@extends('layouts.admin')

@section('title', 'Shipping Methods')

@section('content')
<div class="max-w-[1600px] mx-auto">
    <!-- Header -->
    <div class="flex flex-col md:flex-row md:items-center justify-between gap-8 mb-12">
        <div>
            <div class="flex items-center gap-3 mb-2">
                <span class="px-3 py-1 bg-brand/10 text-brand text-[10px] font-bold uppercase tracking-wider rounded-full">Logistics</span>
                <span class="w-1 h-1 rounded-full bg-gray-300"></span>
                <span class="text-[10px] font-bold text-gray-400 uppercase tracking-wider">Shipping Methods</span>
            </div>
            <h1 class="text-3xl font-black text-gray-900 tracking-tight">Shipping Methods</h1>
            <p class="text-gray-500 text-sm font-medium mt-1">Manage delivery options, shipping costs, and estimated times.</p>
        </div>
        <div class="flex items-center gap-4">
            <a href="{{ route('admin.delivery-types.create') }}" class="inline-flex items-center gap-2 btn-brand text-white px-6 py-3 rounded-xl text-xs font-bold shadow-lg shadow-brand/20">
                <i class="fas fa-plus text-[10px]"></i>
                Add New Method
            </a>
        </div>
    </div>

    <!-- Stats -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
        <div class="bg-white p-6 rounded-3xl border border-gray-100 shadow-sm group hover:border-brand/20 transition-all duration-300">
            <div class="w-12 h-12 bg-emerald-50 rounded-2xl flex items-center justify-center text-emerald-500 mb-4 group-hover:bg-brand group-hover:text-white transition-all duration-300">
                <i class="fas fa-truck text-lg"></i>
            </div>
            <h3 class="text-2xl font-black text-gray-900 mb-1 tracking-tight">{{ $types->where('is_active', true)->count() }}</h3>
            <p class="text-[10px] font-bold text-gray-400 uppercase tracking-widest">Active Methods</p>
        </div>

        <div class="bg-white p-6 rounded-3xl border border-gray-100 shadow-sm group hover:border-brand/20 transition-all duration-300">
            <div class="w-12 h-12 bg-blue-50 rounded-2xl flex items-center justify-center text-blue-500 mb-4 group-hover:bg-brand group-hover:text-white transition-all duration-300">
                <i class="fas fa-coins text-lg"></i>
            </div>
            <h3 class="text-2xl font-black text-gray-900 mb-1 tracking-tight">{{ $currencySymbol }}{{ number_format($types->avg('cost'), 2) }}</h3>
            <p class="text-[10px] font-bold text-gray-400 uppercase tracking-widest">Avg. Shipping Cost</p>
        </div>

        <div class="bg-white p-6 rounded-3xl border border-gray-100 shadow-sm group hover:border-brand/20 transition-all duration-300">
            <div class="w-12 h-12 bg-orange-50 rounded-2xl flex items-center justify-center text-orange-500 mb-4 group-hover:bg-brand group-hover:text-white transition-all duration-300">
                <i class="fas fa-globe text-lg"></i>
            </div>
            <h3 class="text-2xl font-black text-gray-900 mb-1 tracking-tight">{{ $types->count() }}</h3>
            <p class="text-[10px] font-bold text-gray-400 uppercase tracking-widest">Total Options</p>
        </div>
    </div>

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

    <!-- Table -->
    <div class="bg-white rounded-3xl border border-gray-100 shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left border-collapse">
                <thead>
                    <tr class="bg-gray-50/50">
                        <th class="px-8 py-5 text-[10px] font-bold text-gray-400 uppercase tracking-widest">Shipping Method</th>
                        <th class="px-8 py-5 text-[10px] font-bold text-gray-400 uppercase tracking-widest">Cost</th>
                        <th class="px-8 py-5 text-[10px] font-bold text-gray-400 uppercase tracking-widest text-center">Delivery Time</th>
                        <th class="px-8 py-5 text-[10px] font-bold text-gray-400 uppercase tracking-widest text-center">Status</th>
                        <th class="px-8 py-5 text-[10px] font-bold text-gray-400 uppercase tracking-widest text-right">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-50">
                    @forelse($types as $type)
                    <tr class="hover:bg-gray-50/50 transition-colors group">
                        <td class="px-8 py-6">
                            <div class="flex items-center gap-4">
                                <div class="w-10 h-10 rounded-xl bg-gray-50 flex items-center justify-center text-gray-400 group-hover:bg-brand/10 group-hover:text-brand transition-all duration-300">
                                    <i class="fas fa-shipping-fast text-xs"></i>
                                </div>
                                <div>
                                    <p class="font-bold text-gray-900 group-hover:text-brand transition-colors duration-300">{{ $type->name }}</p>
                                    <p class="text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-0.5">{{ Str::limit($type->description, 50) }}</p>
                                </div>
                            </div>
                        </td>
                        <td class="px-8 py-6">
                            <span class="text-sm font-black text-gray-900">{{ $currencySymbol }}{{ number_format($type->cost, 2) }}</span>
                        </td>
                        <td class="px-8 py-6 text-center">
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-[9px] font-bold bg-gray-50 text-gray-600 border border-gray-100 uppercase tracking-wider">
                                <i class="far fa-clock mr-1.5 opacity-50"></i>
                                {{ $type->estimated_time ?? 'N/A' }}
                            </span>
                        </td>
                        <td class="px-8 py-6 text-center">
                            @if($type->is_active)
                                <span class="px-3 py-1 bg-emerald-50 text-emerald-600 rounded-full text-[9px] font-bold uppercase tracking-wider inline-flex items-center gap-1.5">
                                    <span class="w-1 h-1 rounded-full bg-emerald-500"></span>
                                    Active
                                </span>
                            @else
                                <span class="px-3 py-1 bg-red-50 text-red-600 rounded-full text-[9px] font-bold uppercase tracking-wider inline-flex items-center gap-1.5">
                                    <span class="w-1 h-1 rounded-full bg-red-500"></span>
                                    Inactive
                                </span>
                            @endif
                        </td>
                        <td class="px-8 py-6 text-right">
                            <div class="flex items-center justify-end gap-2">
                                <a href="{{ route('admin.delivery-types.edit', $type) }}" class="w-9 h-9 flex items-center justify-center bg-gray-50 text-gray-400 rounded-xl hover:bg-brand/10 hover:text-brand transition-all duration-300">
                                    <i class="fas fa-edit text-xs"></i>
                                </a>
                                <form action="{{ route('admin.delivery-types.destroy', $type) }}" method="POST" class="inline-block" onsubmit="return confirm('Delete this shipping method?');">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="w-9 h-9 flex items-center justify-center bg-gray-50 text-gray-400 rounded-xl hover:bg-red-50 hover:text-red-500 transition-all duration-300">
                                        <i class="fas fa-trash-alt text-xs"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="5" 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-truck-loading text-gray-200 text-2xl"></i>
                                </div>
                                <h3 class="text-lg font-bold text-gray-900 mb-1">No Shipping Methods</h3>
                                <p class="text-gray-400 text-xs font-medium max-w-xs mx-auto">Please add a shipping method to enable deliveries.</p>
                            </div>
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
