@extends('layouts.admin')

@section('title', 'Banners')

@section('content')
<div class="max-w-[1600px] mx-auto">
    <!-- Header -->
    <div class="flex flex-col md:flex-row md:items-end justify-between mb-8 gap-6 border-b border-gray-100 pb-8">
        <div class="space-y-1">
            <nav class="flex mb-2" aria-label="Breadcrumb">
                <ol class="inline-flex items-center space-x-2 text-[10px] font-bold uppercase tracking-wider">
                    <li><a href="{{ route('admin.dashboard') }}" class="text-gray-400 hover:text-brand transition-colors">Admin</a></li>
                    <li><i class="fas fa-chevron-right text-gray-300 text-[8px]"></i></li>
                    <li class="text-brand">Banners</li>
                </ol>
            </nav>
            <h1 class="text-3xl font-black text-gray-900 tracking-tight">Banner Management</h1>
            <p class="text-gray-500 text-sm font-medium">Manage promotional banners and marketing assets for your store.</p>
        </div>
        <div class="flex items-center gap-3">
            <a href="{{ route('admin.banners.create') }}" class="flex items-center gap-2 bg-emerald-600 !bg-brand text-white px-6 py-3 rounded-xl font-bold text-xs shadow-lg shadow-brand/20 hover:bg-emerald-700 hover:!bg-brand/90 transition-all">
                <i class="fas fa-plus text-[10px]"></i>
                Add New Banner
            </a>
        </div>
    </div>

    @if(session('success'))
        <div x-data="{ show: true }" x-show="show" x-init="setTimeout(() => show = false, 5000)" 
             class="bg-white border-l-4 border-emerald-500 p-4 mb-8 rounded-xl shadow-sm flex items-center justify-between">
            <div class="flex items-center gap-3">
                <div class="w-8 h-8 bg-emerald-50 rounded-lg flex items-center justify-center text-emerald-500">
                    <i class="fas fa-check text-xs"></i>
                </div>
                <p class="text-sm font-bold text-gray-700">{{ session('success') }}</p>
            </div>
            <button @click="show = false" class="text-gray-400 hover:text-gray-600 transition-colors">
                <i class="fas fa-times text-xs"></i>
            </button>
        </div>
    @endif

    <!-- Filter Bar -->
    <div class="bg-white p-4 mb-6 rounded-2xl border border-gray-100 shadow-sm flex flex-col md:flex-row items-center justify-between gap-4">
        <div class="relative w-full md:w-96">
            <i class="fas fa-search absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 text-xs"></i>
            <input type="text" class="w-full pl-10 pr-4 py-2.5 bg-gray-50 border-none rounded-xl text-xs font-bold focus:ring-2 focus:ring-brand/10 transition-all placeholder:text-gray-400" placeholder="Search banners...">
        </div>
        <div class="flex items-center gap-3 w-full md:w-auto">
            <select class="flex-1 md:flex-none appearance-none px-4 py-2.5 bg-gray-50 border-none rounded-xl text-[10px] font-bold uppercase tracking-wider focus:ring-2 focus:ring-brand/10 cursor-pointer min-w-[140px]">
                <option>All Status</option>
                <option>Active</option>
                <option>Inactive</option>
            </select>
        </div>
    </div>

    <!-- Banners Grid -->
    <div class="bg-white rounded-3xl border border-gray-100 shadow-sm p-6">
        @if($banners->count())
        <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
            @foreach($banners as $banner)
            <div class="rounded-2xl border border-gray-200 hover:border-brand/40 transition-colors bg-white overflow-hidden">
                <div class="aspect-[16/9] w-full bg-gray-50 border-b border-gray-100">
                    @if($banner->image)
                        <img class="w-full h-full object-cover" src="{{ Str::startsWith($banner->image, ['http://', 'https://']) ? $banner->image : Storage::url($banner->image) }}" alt="{{ $banner->title }}">
                    @else
                        <div class="w-full h-full flex items-center justify-center text-gray-300">
                            <i class="fas fa-image text-2xl"></i>
                        </div>
                    @endif
                </div>
                <div class="p-4">
                    <div class="flex items-start justify-between gap-3">
                        <div class="min-w-0">
                            <h4 class="font-semibold text-gray-900 truncate">{{ $banner->title ?? 'Untitled banner' }}</h4>
                            <div class="mt-1 flex items-center gap-2">
                                <span class="px-2 py-0.5 bg-gray-100 text-gray-600 rounded text-xs">Order: {{ $banner->sort_order }}</span>
                                @if($banner->is_active)
                                    <span class="px-2 py-0.5 bg-emerald-50 text-emerald-600 rounded text-xs">Active</span>
                                @else
                                    <span class="px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs">Inactive</span>
                                @endif
                            </div>
                            @if($banner->link)
                                <a href="{{ $banner->link }}" target="_blank" class="mt-2 inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-700 truncate max-w-full">
                                    <i class="fas fa-link text-[10px]"></i>
                                    <span class="truncate">{{ $banner->link }}</span>
                                </a>
                            @endif
                        </div>
                        <div class="flex items-center gap-2">
                            <a href="{{ route('admin.banners.edit', $banner) }}" class="w-9 h-9 flex items-center justify-center bg-gray-50 rounded-lg text-gray-500 hover:bg-brand/10 hover:text-brand transition">
                                <i class="fas fa-edit text-[11px]"></i>
                            </a>
                            <form action="{{ route('admin.banners.destroy', $banner) }}" method="POST" onsubmit="return confirm('Are you sure you want to delete this banner?');">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="w-9 h-9 flex items-center justify-center bg-gray-50 rounded-lg text-gray-500 hover:bg-red-50 hover:text-red-600 transition">
                                    <i class="fas fa-trash-alt text-[11px]"></i>
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            @endforeach
        </div>
        @else
        <div class="px-8 py-20 text-center">
            <div class="flex flex-col items-center justify-center">
                <div class="w-16 h-16 bg-gray-50 rounded-2xl flex items-center justify-center mb-4">
                    <i class="fas fa-images text-gray-200 text-2xl"></i>
                </div>
                <h3 class="text-lg font-semibold text-gray-900 mb-1">No banners found</h3>
                <p class="text-gray-500 text-sm max-w-xs mx-auto">Start by creating your first promotional banner.</p>
                <a href="{{ route('admin.banners.create') }}" class="mt-6 inline-flex items-center gap-2 bg-emerald-600 !bg-brand text-white px-5 py-2.5 rounded-xl text-sm hover:bg-emerald-700 hover:!bg-brand/90 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/40">
                    <i class="fas fa-plus text-xs"></i>
                    Add banner
                </a>
            </div>
        </div>
        @endif
        @if($banners->hasPages())
        <div class="mt-6">
            {{ $banners->links() }}
        </div>
        @endif
    </div>
</div>
@endsection
