@extends('layout.app')
@section('content')
<div class="pagetitle">

    <h1>Tambah Data makanan</h1>
    <nav>
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ route('admindash') }}">Home</a></li>
            <li class="breadcrumb-item active"><a href="{{ route('makanan') }}">Makanan</a></li>
            <li class="breadcrumb-item active"><a href="{{ route('tambahmakanan') }}">Tambah Makanan</a></li>
        </ol>
    </nav>

</div><!-- End Page Title -->

<div class="card">
  <div class="card-body">
      <h5 class="card-title">Tambah Makanan</h5>

      <!-- General Form Elements -->
    <form id="AddUserForm" method="POST" action="{{ url('/makanan/storemakanan') }}">
        @csrf <!-- Add this to include CSRF token --> 
      
          <div class="row mb-3">
              <label for="inputText" class="col-sm-2 col-form-label">Name</label>
              <div class="col-sm-10">
                  <input type="text" class="form-control" placeholder="nama" aria-label="Your Name"
                      aria-describedby="basic-addon1" name="nama">
              </div>
          </div>
          <div class="row mb-3">
            <label class="col-sm-2 col-form-label">Kategori</label>
            <div class="col-sm-10">
              <select class="form-select" name="kategori_id" aria-label="Select Kategori" required>
                <option selected disabled>Select a Kategori</option>
                @foreach($kategoris as $kategori)
                  <option value="{{ $kategori->id }}">{{ $kategori->kategori }}</option>
                @endforeach
              </select>
            </div>
          </div>
          <div class="row mb-3">
            <label class="col-sm-2 col-form-label">Jenis Makanan</label>
            <div class="col-sm-10">
              <select class="form-select" name="jenis_id" aria-label="Select Jenis Makanan" required>
                <option selected disabled>Select a Jenis Makanan</option>
                @foreach($jenis_makanans as $jenis)
                  <option value="{{ $jenis->id }}">{{ $jenis->name }}</option>
                @endforeach
              </select>
            </div>
          </div>
            <div class="row mb-3">
                <label for="inputText" class="col-sm-2 col-form-label">Lemak</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" placeholder="lemak" aria-label="Your Name"
                        aria-describedby="basic-addon1" name="lemak">
                </div>
            </div>
            <div class="row mb-3">
              <label for="inputText" class="col-sm-2 col-form-label">Natrium</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" placeholder="natrium" aria-label="Your Name"
                aria-describedby="basic-addon1" name="natrium">
              </div>
            </div>
            <div class="row mb-3">
              <label for="inputText" class="col-sm-2 col-form-label">Energi</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" placeholder="energi" aria-label="Your Name"
                aria-describedby="basic-addon1" name="energi">
              </div>
            </div>
            <div class="row mb-3">
              <label for="inputText" class="col-sm-2 col-form-label">Karbohidrat</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" placeholder="karbohidrat" aria-label="Your Name"
                aria-describedby="basic-addon1" name="karbohidrat">
              </div>
            </div>
        </div>          
          <div class="row mb-3">
              <div class="col-sm-12 text-center">
                  <a href="{{ route('makanan') }}" class="btn btn-secondary mx-3">Back</a>
                  <button type="button" class="btn btn-primary mx-3" onclick="confirmSave()">Save</button>

              </div>
          </div>
    </form><!-- End General Form Elements -->

  </div>
</div>

</div>

<!-- SweetAlert2 -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<!-- Confirmation Dialog Script -->
<script>
    function confirmSave() {
    Swal.fire({
        title: 'Are you sure?',
        text: "Do you want to save the changes?",
        icon: 'question',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, save it!'
    }).then((result) => {
        if (result.isConfirmed) {
            console.log("Form submitted"); // Tambahkan ini di dalam `if (result.isConfirmed)` sebelum submit form
            document.getElementById('AddUserForm').submit();
        }
    });
    }
</script>
@endsection
