

<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="container-header">
        <h1><?php echo e($title); ?></h1>
    </div>

    <div class="card mb-25">
        <div class="card-body">
            <form action="<?php echo e(route('backend.product-categories.store')); ?>" method="post">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">Category name<span class="required">*</span></label>
                        <input type="text" class="form-control" name="name" placeholder="e.g. Instagram Accounts" required>
                    </div>
                    <div class="form-group width-50">
                        <label class="form-label">Sort order</label>
                        <input type="number" class="form-control" name="sort" value="0" min="0" placeholder="0">
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-label">Status</label>
                    <select class="form-control" name="status">
                        <option value="1">On</option>
                        <option value="0">Off</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">Add category</button>
            </form>
        </div>
    </div>

    <div class="card table-card">
        <div class="table-header">
            <form method="GET" action="<?php echo e(route('backend.product-categories.index')); ?>" class="table-search-form">
                <div class="table-search">
                    <input type="text" name="search" class="search-input" placeholder="Search categories..." value="<?php echo e($search ?? ''); ?>">
                    <i class="las la-search"></i>
                </div>
                <button type="submit" class="btn btn-secondary search-btn">Search</button>
                <?php if(!empty($search)): ?>
                    <a href="<?php echo e(route('backend.product-categories.index')); ?>" class="btn btn-outline">Clear</a>
                <?php endif; ?>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Sort</th>
                        <th>Products</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($categories->firstItem() + $loop->index); ?></td>
                        <td><?php echo e($c->name); ?></td>
                        <td><?php echo e($c->sort); ?></td>
                        <td><?php echo e($c->products_count ?? 0); ?></td>
                        <td>
                            <div class="table-actions">
                                <button type="button" class="table-btn edit-product-category" data-id="<?php echo e($c->id); ?>" data-name="<?php echo e($c->name); ?>" data-sort="<?php echo e($c->sort); ?>" data-status="<?php echo e($c->status ? '1' : '0'); ?>" title="Edit"><i class="las la-pen"></i></button>
                                <form action="<?php echo e(route('backend.product-categories.destroy', $c->id)); ?>" method="post" class="d-inline" onsubmit="return confirm('Delete this category?');">
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('DELETE'); ?>
                                    <button type="submit" class="table-btn" title="Delete"><i class="las la-trash"></i></button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr><td colspan="5" class="text-center">No categories yet.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?php echo e($categories->links('vendor.pagination.default')); ?>

    </div>
</div>

<div class="modal" id="edit-product-category-modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title">Edit category</h3>
            <button class="close-modal"><i class="las la-times"></i></button>
        </div>
        <form action="<?php echo e(route('backend.product-categories.update', ['id' => '__ID__'])); ?>" method="post" id="edit-product-category-form">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>
            <div class="modal-body">
                <div class="form-group mb-25">
                    <label class="form-label">Category name<span class="required">*</span></label>
                    <input type="text" class="form-control" name="name" id="edit-category-name" required>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Sort order</label>
                    <input type="number" class="form-control" name="sort" id="edit-category-sort" value="0" min="0">
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Status</label>
                    <select class="form-control" name="status" id="edit-category-status">
                        <option value="1">On</option>
                        <option value="0">Off</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" type="submit">Update category</button>
            </div>
        </form>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
document.querySelectorAll('.edit-product-category').forEach(function(btn) {
    btn.addEventListener('click', function() {
        var id = this.getAttribute('data-id');
        var modal = document.getElementById('edit-product-category-modal');
        var form = document.getElementById('edit-product-category-form');
        form.action = '<?php echo e(route("backend.product-categories.update", ["id" => "__ID__"])); ?>'.replace('__ID__', id);
        document.getElementById('edit-category-name').value = this.getAttribute('data-name') || '';
        document.getElementById('edit-category-sort').value = this.getAttribute('data-sort') || '0';
        document.getElementById('edit-category-status').value = this.getAttribute('data-status') ?? '1';
        modal.classList.add('active');
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.layout.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\jjd\socialnum\sstack\mine\core\resources\views/backend/products/categories/index.blade.php ENDPATH**/ ?>