

<?php $__env->startSection('title', 'Daftar Resep'); ?>

<?php $__env->startSection('content'); ?>
<div class="content-body">
  <div class="container-fluid">
    <div class="row page-titles">
      <ol class="breadcrumb">
        <li class="breadcrumb-item active"><a href="javascript:void(0)">Beranda</a></li>
        <li class="breadcrumb-item"><a href="javascript:void(0)">Daftar Resep</a></li>
      </ol>
    </div>

    <!-- row -->
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-header">
            <h4 class="card-title">Daftar Resep</h4>
            <button type="button" class="btn btn-primary float-right" data-bs-toggle="modal" data-bs-target="#addRecipeModal">
              <i class="fa fa-plus"></i> Tambah Resep
            </button>
          </div>
          <div class="card-body">
            <div class="table-responsive">
              <table id="example2" class="display" style="min-width: 845px">
                <thead>
                  <tr>
                    <th>No</th>
                    <th>Judul</th>
                    <th>Kategori</th>
                    <th>Aksi</th>
                  </tr>
                </thead>
                <tbody>
                  <?php $__currentLoopData = $recipes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $recipe): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                      <td><?php echo e($loop->iteration); ?></td>
                      <td><?php echo e($recipe->title); ?></td>
                      <td><?php echo e($recipe->category); ?></td>
                      <td>
                        <button type="button" class="btn btn-warning" data-bs-toggle="modal" data-bs-target="#editRecipeModalCenter<?php echo e($recipe->id); ?>">
                          <i class="fa fa-edit"></i> Edit
                        </button>
                        <button type="button" class="btn btn-danger" onclick="confirmDelete(<?php echo e($recipe->id); ?>)">
                          <i class="fa fa-trash"></i> Hapus
                        </button>
                        <form id="delete-form-<?php echo e($recipe->id); ?>" action="<?php echo e(route('resep.destroy', $recipe->id)); ?>" method="POST" style="display: none;">
                          <?php echo csrf_field(); ?>
                          <?php echo method_field('DELETE'); ?>
                        </form>
                      </td>
                    </tr>

<!-- Modal Edit Resep -->
<div class="modal fade" id="editRecipeModalCenter<?php echo e($recipe->id); ?>" tabindex="-1" role="dialog" aria-labelledby="editRecipeModalCenterLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editRecipeModalCenterLabel">Edit Resep</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form action="<?php echo e(route('resep.update', $recipe->id)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="title">Judul:</label>
                        <input type="text" name="title" class="form-control" value="<?php echo e($recipe->title); ?>" required>
                    </div>
                    <div class="form-group">
                        <label for="description">Deskripsi:</label>
                        <textarea name="description" class="form-control"><?php echo e($recipe->description); ?></textarea>
                    </div>
                    <div class="form-group">
                        <label for="category">Kategori:</label>
                        <input type="text" name="category" class="form-control" value="<?php echo e($recipe->category); ?>" required>
                    </div>
                    <div class="form-group">
                        <label for="ingredients">Bahan:</label>
                        <textarea name="ingredients" class="form-control" required><?php echo e($recipe->ingredients); ?></textarea>
                    </div>
                    <div class="form-group">
                        <label for="instructions">Instruksi:</label>
                        <textarea name="instructions" class="form-control" required><?php echo e($recipe->instructions); ?></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
                    <button type="submit" class="btn btn-success" onclick="setLoading(this)">Update</button>
                </div>
            </form>
        </div>
    </div>
</div>

                  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- Modal Tambah Resep -->
<div class="modal fade" id="addRecipeModal" tabindex="-1" role="dialog" aria-labelledby="addRecipeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="addRecipeModalLabel">Tambah Resep</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>
      <form action="<?php echo e(route('resep.store')); ?>" method="POST">
        <?php echo csrf_field(); ?>
        <div class="modal-body">
          <div class="form-group">
            <label for="title">Judul:</label>
            <input type="text" name="title" class="form-control" required>
          </div>
          <div class="form-group">
            <label for="description">Deskripsi:</label>
            <textarea name="description" class="form-control"></textarea>
          </div>
          <div class="form-group">
            <label for="category">Kategori:</label>
            <input type="text" name="category" class="form-control" required>
          </div>
          <div class="form-group">
            <label for="ingredients">Bahan:</label>
            <textarea name="ingredients" class="form-control" required></textarea>
          </div>
          <div class="form-group">
            <label for="instructions">Instruksi:</label>
            <textarea name="instructions" class="form-control" required></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
          <button type="submit" class="btn btn-success" onclick="setLoading(this)">Simpan</button>
        </div>
      </form>
    </div>
  </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
function confirmDelete(recipeId) {
    Swal.fire({
        title: 'Apakah kamu yakin?',
        text: "Data ini akan dihapus secara permanen!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Ya, hapus!'
    }).then((result) => {
        if (result.isConfirmed) {
            document.getElementById('delete-form-' + recipeId).submit();
        }
    });
}

function setLoading(button) {
    button.disabled = true;
    button.innerHTML = 'Loading...';
    button.form.submit();
}
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\my-life-hub\resources\views/resep/resep.blade.php ENDPATH**/ ?>