@extends('layouts.admin')

@section('title', 'Premium Products')

@section('content')
    <div class="flex flex-col md:flex-row md:items-end justify-between gap-6 mb-8 border-b border-gray-100 pb-6">
        <div class="space-y-1">
            <h1 class="text-3xl font-bold text-gray-900 tracking-tight">Premium Products</h1>
            <p class="text-gray-500 text-sm">Only products marked as Premium appear here.</p>
        </div>
        <div class="flex items-center gap-3">
            <a href="{{ route('admin.products.premium.select') }}" class="inline-flex items-center px-5 py-3 bg-white border border-gray-200 hover:bg-gray-50 text-gray-700 text-xs font-bold rounded-xl shadow-sm transition-all">
                <i class="fas fa-plus mr-2 text-[10px] text-brand"></i>
                Add From Products
            </a>
        </div>
    </div>

    <div class="bg-white rounded-3xl shadow-sm border border-gray-100 overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-100 bg-gray-50/60">
            <div class="flex items-center gap-2 text-sm text-gray-600">
                <i class="fas fa-gem text-purple-500"></i>
                Showing premium products
            </div>
        </div>

        <div class="p-6">
            @if($products->count())
                <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-5">
                    @foreach($products as $product)
                    <div class="group border border-gray-100 rounded-2xl overflow-hidden bg-white hover:shadow-md transition-all">
                        <div class="relative aspect-square bg-gray-50 flex items-center justify-center overflow-hidden">
                            @if($product->image)
                                <img class="h-full w-full object-cover group-hover:scale-105 transition-transform duration-500" src="{{ Str::startsWith($product->image, ['http://', 'https://']) ? $product->image : Storage::url($product->image) }}" alt="{{ $product->name }}">
                            @else
                                <i class="fas fa-box text-4xl text-gray-200"></i>
                            @endif
                            <div class="absolute top-3 right-3 h-7 px-2 rounded-lg bg-purple-600 text-white text-[10px] font-bold inline-flex items-center gap-1">
                                <i class="fas fa-gem text-[9px]"></i>
                                Premium
                            </div>
                            @if(!$product->is_active)
                                <div class="absolute bottom-3 left-3 px-2 py-1 text-[10px] font-semibold rounded bg-gray-900 text-white/90">Inactive</div>
                            @endif
                        </div>
                        <div class="p-4">
                            <div class="text-sm font-semibold text-gray-900 line-clamp-2">{{ $product->name }}</div>
                            <div class="mt-1 text-xs text-gray-500">{{ $product->category->name ?? 'Uncategorized' }}</div>
                            <div class="mt-2 flex items-baseline gap-2">
                                @if($product->discount_price)
                                    <span class="text-sm font-semibold text-emerald-600">{{ $currencySymbol }}{{ number_format($product->discount_price, 2) }}</span>
                                    <span class="text-xs text-gray-400 line-through">{{ $currencySymbol }}{{ number_format($product->price, 2) }}</span>
                                @else
                                    <span class="text-sm font-semibold text-gray-900">{{ $currencySymbol }}{{ number_format($product->price, 2) }}</span>
                                @endif
                            </div>
                            <div class="mt-3 flex items-center justify-between">
                                <span class="text-xs text-gray-500">{{ $product->stock }} {{ $product->unit }}</span>
                                <div class="flex items-center gap-2">
                                    <a href="{{ route('admin.products.edit', $product) }}" class="h-9 w-9 flex items-center justify-center text-gray-400 hover:text-brand hover:bg-emerald-50 rounded-xl transition-all" title="Edit">
                                        <i class="fas fa-edit text-sm"></i>
                                    </a>
                                    <form method="POST" action="{{ route('admin.products.premium.detach') }}" class="inline-block">
                                        @csrf
                                        <input type="hidden" name="product_ids[]" value="{{ $product->id }}">
                                        <button type="submit" class="h-9 w-9 flex items-center justify-center text-gray-400 hover:text-amber-600 hover:bg-amber-50 rounded-xl transition-all" title="Remove from Premium">
                                            <i class="fas fa-minus-circle text-sm"></i>
                                        </button>
                                    </form>
                                    <form action="{{ route('admin.products.destroy', $product) }}" method="POST" class="inline-block" onsubmit="return confirm('Are you sure you want to delete this product?');">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="h-9 w-9 flex items-center justify-center text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-all" title="Delete">
                                            <i class="fas fa-trash-alt text-sm"></i>
                                        </button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    @endforeach
                </div>
            @else
                <div class="px-8 py-24 text-center">
                    <div class="flex flex-col items-center justify-center max-w-md mx-auto">
                        <div class="h-20 w-20 bg-gray-50 rounded-2xl flex items-center justify-center mb-6 border border-gray-100">
                            <i class="fas fa-gem text-3xl text-purple-300"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-900 mb-1">No premium products</h3>
                        <p class="text-gray-500 text-sm leading-relaxed mb-8">Add from existing products to build your Premium list.</p>
                        <a href="{{ route('admin.products.premium.select') }}" class="inline-flex items-center gap-2 btn-brand text-white px-6 py-3 rounded-xl text-sm font-semibold transition-all shadow-md shadow-brand/20">
                            <i class="fas fa-plus text-[10px]"></i>
                            Add From Products
                        </a>
                    </div>
                </div>
            @endif
        </div>

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