<?php $__env->startSection('title', 'Product Management'); ?>

<?php $__env->startSection('content'); ?>
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px;">
    <div>
        <h1 class="serif" style="font-size: 26px; margin: 0; color: #0f172a;">Product Catalog Management</h1>
        <p style="color: var(--text-muted); font-size: 14px; margin-top: 4px;">Manage store products, prices, variants, inventory, and visibility.</p>
    </div>
    <a href="<?php echo e(route('admin.products.create')); ?>" class="btn-admin btn-primary">
        <i data-lucide="plus" style="width: 18px;"></i>
        <span>Add Product</span>
    </a>
</div>

<!-- Filters Bar -->
<div class="admin-card" style="margin-bottom: 24px; padding: 16px 20px;">
    <form action="<?php echo e(route('admin.products.index')); ?>" method="GET" style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
        <div style="flex: 1; min-width: 200px;">
            <input type="text" name="search" value="<?php echo e($search); ?>" placeholder="Search by product name or tag..." class="form-control">
        </div>
        <div style="width: 200px;">
            <select name="category_id" class="form-control" onchange="this.form.submit()">
                <option value="">All Categories</option>
                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($cat->id); ?>" <?php echo e($category_id == $cat->id ? 'selected' : ''); ?>><?php echo e($cat->name); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <button type="submit" class="btn-admin btn-secondary">Filter</button>
        <?php if($search || $category_id): ?>
            <a href="<?php echo e(route('admin.products.index')); ?>" class="btn-admin btn-secondary" style="color: #b91c1c;">Clear</a>
        <?php endif; ?>
    </form>
</div>

<!-- Products Table -->
<div class="admin-card">
    <?php if($products->isEmpty()): ?>
        <div style="padding: 40px; text-align: center; color: var(--text-muted);">
            No products found matching your filter criteria.
        </div>
    <?php else: ?>
        <div style="overflow-x: auto;">
            <table class="admin-table">
                <thead>
                    <tr>
                        <th style="width: 70px;">Image</th>
                        <th>Product Name & Tag</th>
                        <th>Category</th>
                        <th>Price (₹)</th>
                        <th>Stock</th>
                        <th>Badge</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $prod): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td>
                                <div style="width: 52px; height: 52px; background: #f1f5f9; border-radius: 10px; overflow: hidden; border: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: center;">
                                    <?php if($prod->image): ?>
                                        <img src="<?php echo e(asset($prod->image)); ?>" alt="<?php echo e($prod->name); ?>" style="width: 100%; height: 100%; object-fit: cover;">
                                    <?php else: ?>
                                        <i data-lucide="package" style="width: 20px; color: var(--primary);"></i>
                                    <?php endif; ?>
                                </div>
                            </td>
                            <td>
                                <strong style="color: #0f172a; font-size: 15px;"><?php echo e($prod->name); ?></strong>
                                <div style="font-size: 12px; color: var(--text-muted); margin-top: 2px;"><?php echo e($prod->tag ?? 'No tagline'); ?></div>
                            </td>
                            <td>
                                <span class="badge" style="background: #f1f5f9; color: #334155;"><?php echo e($prod->category->name ?? 'Unassigned'); ?></span>
                            </td>
                            <td>
                                <strong>₹<?php echo e(number_format($prod->price, 2)); ?></strong>
                                <?php if($prod->compare_at): ?>
                                    <div style="font-size: 11px; color: var(--text-muted); text-decoration: line-through;">₹<?php echo e(number_format($prod->compare_at, 2)); ?></div>
                                <?php endif; ?>
                            </td>
                            <td>
                                <span class="badge <?php echo e($prod->stock <= 10 ? 'badge-pending' : 'badge-delivered'); ?>">
                                    <?php echo e($prod->stock); ?> units
                                </span>
                            </td>
                            <td>
                                <?php if($prod->badge): ?>
                                    <span class="badge" style="background: #fef3c7; color: #b45309;"><?php echo e($prod->badge); ?></span>
                                <?php else: ?>
                                    <span style="color: var(--text-muted); font-size: 12px;">—</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <form action="<?php echo e(route('admin.products.toggle', $prod)); ?>" method="POST" style="margin:0;">
                                    <?php echo csrf_field(); ?>
                                    <button type="submit" class="badge <?php echo e($prod->is_active ? 'badge-active' : 'badge-inactive'); ?>" style="cursor: pointer; border: none;">
                                        <?php echo e($prod->is_active ? 'Active' : 'Disabled'); ?>

                                    </button>
                                </form>
                            </td>
                            <td>
                                <div style="display: flex; gap: 8px;">
                                    <a href="<?php echo e(route('admin.products.show', $prod)); ?>" class="btn-admin btn-secondary" style="padding: 6px 10px; font-size: 12px; background: #e0eff9; color: #186297; border-color: #b9dff3;">
                                        <i data-lucide="eye" style="width: 14px;"></i> View
                                    </a>
                                    <a href="<?php echo e(route('admin.products.edit', $prod)); ?>" class="btn-admin btn-secondary" style="padding: 6px 10px; font-size: 12px;">
                                        <i data-lucide="edit-3" style="width: 14px;"></i> Edit
                                    </a>
                                    <form action="<?php echo e(route('admin.products.destroy', $prod)); ?>" method="POST" onsubmit="return confirm('Are you sure you want to delete this product?')" style="margin: 0;">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="btn-admin btn-danger" style="padding: 6px 10px; font-size: 12px;">
                                            <i data-lucide="trash-2" style="width: 14px;"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>

        <div style="margin-top: 20px;">
            <?php echo e($products->links()); ?>

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

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/koushikkona/Documents/Projects/divne/resources/views/admin/products/index.blade.php ENDPATH**/ ?>