

<?php $__env->startSection('title', 'Manage Categories - Lingel DAM'); ?>
<?php $__env->startSection('page_header', 'Manage Categories'); ?>

<?php $__env->startSection('content'); ?>
    <div class="bg-white p-6 rounded-lg shadow-sm mb-8 border border-gray-200">
        <form action="<?php echo e(route('admin.categories.store')); ?>" method="POST" class="flex gap-4">
            <?php echo csrf_field(); ?>
            <input type="text" name="name" placeholder="Category Name (e.g. uPVC Windows)" required class="flex-1 px-4 py-2 border rounded focus:outline-none focus:border-blue-500">
            <button type="submit" class="bg-blue-600 text-white px-6 py-2 rounded font-medium hover:bg-blue-700 transition">
                <i class="fas fa-plus mr-1"></i> Add Category
            </button>
        </form>
    </div>

    <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
        <table class="w-full text-left">
            <thead class="bg-gray-50 border-b">
                <tr>
                    <th class="px-6 py-4 text-gray-600 font-semibold">#</th>
                    <th class="px-6 py-4 text-gray-600 font-semibold">Name</th>
                    <th class="px-6 py-4 text-gray-600 font-semibold">Slug</th>
                    <th class="px-6 py-4 text-gray-600 font-semibold text-right">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr class="border-b hover:bg-gray-50 transition">
                    <td class="px-6 py-4"><?php echo e($loop->iteration); ?></td>
                    <td class="px-6 py-4 font-medium text-gray-800"><?php echo e($cat->name); ?></td>
                    <td class="px-6 py-4 text-gray-500"><?php echo e($cat->slug); ?></td>
                    <td class="px-6 py-4 text-right">
                        
                        <button onclick="openEditModal(<?php echo e($cat->id); ?>, '<?php echo e($cat->name); ?>')" class="text-blue-500 hover:text-blue-700 mr-4 transition">
                            <i class="fas fa-edit"></i> Edit
                        </button>

                        <form action="<?php echo e(route('admin.categories.destroy', $cat->id)); ?>" method="POST" class="inline-block">
                            <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                            <button type="submit" class="text-red-500 hover:text-red-700 transition" onclick="return confirm('Are you sure you want to delete this category? All associated assets will also be deleted.')">
                                <i class="fas fa-trash"></i> Delete
                            </button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>

    <div id="editModal" class="hidden fixed inset-0 bg-gray-900 bg-opacity-50 overflow-y-auto h-full w-full flex items-center justify-center">
        <div class="bg-white p-6 rounded-lg shadow-xl w-full max-w-md">
            <h3 class="text-xl font-bold mb-4 text-gray-800">Edit Category</h3>
            <form id="editForm" method="POST">
                <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                <div class="mb-4">
                    <label class="block text-gray-700 text-sm font-bold mb-2">Category Name</label>
                    <input type="text" id="editName" name="name" class="w-full px-4 py-2 border rounded focus:outline-none focus:border-blue-500" required>
                </div>
                <div class="flex justify-end gap-3">
                    <button type="button" onclick="closeModal()" class="bg-gray-500 hover:bg-gray-600 text-white px-4 py-2 rounded transition">Cancel</button>
                    <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded transition">Save Changes</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        function openEditModal(id, name) {
            document.getElementById('editForm').action = '/admin/categories/' + id;
            document.getElementById('editName').value = name;
            document.getElementById('editModal').classList.remove('hidden');
        }

        function closeModal() {
            document.getElementById('editModal').classList.add('hidden');
        }
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wamp64\www\lingel-portal\system\resources\views/admin/categories/index.blade.php ENDPATH**/ ?>