@extends('admin.layouts.app')

@section('page-title', 'Shop Products')

@section('content')
<div class="space-y-6">
    <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <div>
            <h1 class="text-2xl font-bold tracking-tight text-gray-950 dark:text-white">Products</h1>
            <p class="text-sm text-gray-500 dark:text-gray-400">Inventory and catalog management.</p>
        </div>
        <a href="{{ route('admin.products.create') }}" class="inline-flex items-center gap-2 rounded-lg bg-primary-600 px-4 py-2 text-sm font-semibold text-white shadow-sm ring-1 ring-inset ring-primary-600 transition hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600">
            <i data-lucide="plus" class="h-4 w-4"></i>
            <span>Add Product</span>
        </a>
    </div>

    <div class="flex flex-col rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10">
        <!-- Table Header/Search -->
        <div class="flex flex-col gap-4 p-4 border-b border-gray-100 dark:border-white/5 sm:flex-row sm:items-center">
            <div class="relative flex-1">
                <i data-lucide="search" class="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"></i>
                <input type="text" placeholder="Search catalog..." class="block w-full rounded-lg border-0 py-2 pl-10 pr-3 text-sm text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary-600 dark:bg-white/5 dark:text-white dark:ring-white/10 dark:placeholder:text-gray-500">
            </div>
            <button class="inline-flex items-center gap-2 rounded-lg bg-white px-3 py-2 text-sm font-semibold text-gray-700 shadow-sm ring-1 ring-gray-950/10 transition hover:bg-gray-50 dark:bg-white/5 dark:text-gray-200 dark:ring-white/10 dark:hover:bg-white/10">
                <i data-lucide="filter" class="h-4 w-4"></i>
                <span>Categories</span>
            </button>
        </div>

        <!-- Table -->
        <div class="overflow-x-auto">
            <table class="w-full text-left text-sm leading-6">
                <thead>
                    <tr class="bg-gray-50 font-semibold text-gray-500 dark:bg-white/5 dark:text-gray-400">
                        <th class="px-6 py-3">Product</th>
                        <th class="px-6 py-3">Brand</th>
                        <th class="px-6 py-3">Price</th>
                        <th class="px-6 py-3">Inventory</th>
                        <th class="px-6 py-3 text-center">Visibility</th>
                        <th class="px-6 py-3 text-right text-[10px] uppercase tracking-widest text-gray-400">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100 dark:divide-white/5">
                    @forelse($products as $product)
                    <tr class="hover:bg-gray-50 transition dark:hover:bg-white/5">
                        <td class="px-6 py-4">
                            <div class="flex items-center gap-3">
                                <div class="h-10 w-10 shrink-0 rounded-lg bg-gray-100 dark:bg-white/5 flex items-center justify-center text-gray-400">
                                    <i data-lucide="package" class="h-5 w-5"></i>
                                </div>
                                <div class="overflow-hidden">
                                    <p class="font-semibold truncate text-gray-900 dark:text-white">{{ $product->name }}</p>
                                    <p class="text-[10px] font-mono text-gray-400 dark:text-gray-500 truncate mt-0.5">{{ $product->slug }}</p>
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4 font-medium text-gray-600 dark:text-gray-400">
                            {{ $product->brand?->name ?? '-' }}
                        </td>
                        <td class="px-6 py-4 font-bold text-gray-900 dark:text-white">
                            ${{ number_format($product->price, 2) }}
                        </td>
                        <td class="px-6 py-4">
                            <div class="flex flex-col gap-1.5">
                                <span class="text-xs font-medium {{ $product->qty > 10 ? 'text-gray-600 dark:text-gray-400' : 'text-danger-600 font-bold' }}">
                                    {{ $product->qty }} in stock
                                </span>
                                <div class="w-20 h-1 bg-gray-100 rounded-full overflow-hidden dark:bg-white/5">
                                    <div class="h-full bg-primary-500 rounded-full" style="width: {{ min(100, ($product->qty / 50) * 100) }}%"></div>
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4 text-center">
                            @if($product->is_visible)
                                <span class="inline-flex items-center rounded-full bg-success-50 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider text-success-700 ring-1 ring-inset ring-success-600/20 dark:bg-success-400/10 dark:text-success-400 dark:ring-success-400/30">Visible</span>
                            @else
                                <span class="inline-flex items-center rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider text-gray-500 ring-1 ring-inset ring-gray-950/10 dark:bg-white/5 dark:text-gray-400 dark:ring-white/10">Hidden</span>
                            @endif
                        </td>
                        <td class="px-6 py-4 text-right">
                            <div class="flex items-center justify-end gap-3">
                                <a href="{{ route('admin.products.edit', $product) }}" class="text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 transition-colors">
                                    <i data-lucide="edit-3" class="h-4 w-4"></i>
                                </a>
                                <button class="text-gray-400 hover:text-danger-600 dark:hover:text-danger-500 transition-colors">
                                    <i data-lucide="trash-2" class="h-4 w-4"></i>
                                </button>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="6" class="px-6 py-12 text-center text-gray-400 dark:text-gray-500 italic">No products found.</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($products->hasPages())
        <div class="px-6 py-4 border-t border-gray-100 dark:border-white/5">
            {{ $products->links() }}
        </div>
        @endif
    </div>
</div>
@endsection
