

<?php $__env->startSection('content'); ?>
    <section class="py-4">
        <div class="container-fluid">

            <h4 class="fw-bold mb-3">Halaman Photo Kegiatan</h4>

            <!-- Button Upload -->
            <button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#uploadModal">
                Upload Photo
            </button>

            
            <?php if(session()->has('success')): ?>
                <div class="alert alert-success alert-dismissible fade show">
                    <strong>Informasi :</strong> <?php echo e(session('success')); ?>

                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>

            <!-- TABLE -->
            <div class="table-responsive">
                <table class="table table-bordered align-middle">
                    <thead class="table-light">
                        <tr>
                            <th width="50">#</th>
                            <th width="180">Image</th>
                            <th>Nama Kegiatan</th>
                            <th width="150">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $photos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $no => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($no + 1); ?></td>

                                <td>
                                    <img src="<?php echo e(asset('storage/photo/' . $item->image)); ?>" class="img-fluid rounded"
                                        style="max-height:120px; object-fit:cover;">
                                </td>

                                <td><?php echo e($item->judul); ?></td>

                                <td>
                                    <button class="btn btn-warning btn-sm w-100 mb-1" data-bs-toggle="modal"
                                        data-bs-target="#editModal<?php echo e($item->id); ?>">
                                        Edit
                                    </button>

                                    <form action="<?php echo e(route('photo.destroy', $item->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <button onclick="return confirm('Yakin dihapus?')"
                                            class="btn btn-danger btn-sm w-100">
                                            Hapus
                                        </button>
                                    </form>
                                </td>
                            </tr>

                            <!-- MODAL EDIT -->
                            <div class="modal fade" id="editModal<?php echo e($item->id); ?>" tabindex="-1">
                                <div class="modal-dialog modal-lg modal-dialog-centered">
                                    <div class="modal-content">

                                        <div class="modal-header">
                                            <h5 class="modal-title">Edit Photo</h5>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                        </div>

                                        <div class="modal-body">
                                            <form action="<?php echo e(route('photo.update', $item->id)); ?>" method="POST"
                                                enctype="multipart/form-data">
                                                <?php echo csrf_field(); ?>

                                                <div class="row">
                                                    <div class="col-md-5 text-center mb-3">
                                                        <img src="<?php echo e(asset('storage/photo/' . $item->image)); ?>"
                                                            class="img-fluid rounded mb-2"
                                                            style="max-height:200px; object-fit:cover;">

                                                        <input type="hidden" name="old_image" value="<?php echo e($item->image); ?>">
                                                        <input type="file" name="image" class="form-control">
                                                    </div>

                                                    <div class="col-md-7">
                                                        <div class="mb-3">
                                                            <label class="form-label">Nama Kegiatan</label>
                                                            <input type="text" name="judul" class="form-control"
                                                                value="<?php echo e($item->judul); ?>" required>
                                                        </div>

                                                        <button type="submit" class="btn btn-primary w-100">
                                                            Update
                                                        </button>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>

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

        </div>
    </section>

    <!-- MODAL UPLOAD -->
    <div class="modal fade" id="uploadModal" tabindex="-1">
        <div class="modal-dialog modal-md modal-dialog-centered">
            <div class="modal-content">

                <div class="modal-header">
                    <h5 class="modal-title">Upload Photo</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>

                <div class="modal-body">
                    <form action="<?php echo e(route('photo.store')); ?>" method="POST" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>

                        <div class="mb-3">
                            <label class="form-label">Pilih Photo</label>
                            <input type="file" name="image" class="form-control" required>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Nama Kegiatan</label>
                            <input type="text" name="judul" class="form-control" required>
                        </div>

                        <button type="submit" class="btn btn-primary w-100">
                            Simpan
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\laragon\www\websekolah\resources\views/admin/photo/index.blade.php ENDPATH**/ ?>