<x-app-layout>
    <x-slot name="header">
        <div class="flex items-center justify-between gap-4 rounded-2xl border border-sky-200/70 bg-gradient-to-r from-sky-50 to-green-50 px-5 py-4">
            <h2 class="text-xl font-semibold leading-tight text-sky-900">
                {{ __('Packages') }}
            </h2>
            <a href="{{ route('admin.packages.create') }}"
                class="inline-flex items-center rounded-lg bg-sky-600 px-4 py-2 font-semibold text-white transition hover:bg-sky-700">
                + {{ __('New Package') }}
            </a>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            @if ($message = Session::get('success'))
                <div class="mb-4 rounded-lg border border-green-200 bg-green-50 p-4 text-green-700">
                    {{ $message }}
                </div>
            @endif

            @if ($errors->any())
                <div class="mb-4 rounded-lg border border-red-200 bg-red-50 p-4 text-red-700">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <div class="overflow-hidden rounded-2xl border border-sky-200/70 bg-white shadow-sm">
                <div class="overflow-x-auto">
                    <table class="w-full">
                        <thead class="border-b border-sky-100 bg-sky-50/80">
                            <tr>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Name') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Drivers') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Trucks') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Base Price') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Per Driver') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Legacy Price') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Billing') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Status') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Actions') }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse ($packages as $package)
                                <tr class="border-b border-sky-100 hover:bg-sky-50/40">
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        <a href="{{ route('admin.packages.show', $package) }}"
                                            class="font-semibold text-sky-700 hover:text-sky-900">
                                            {{ $package->name }}
                                        </a>
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                                        {{ $package->driver_limit }}
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                                        {{ $package->truck_limit }}
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-semibold text-gray-900">
                                        ${{ number_format($package->base_price ?? 0, 2) }}
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-semibold text-gray-900">
                                        ${{ number_format($package->price_per_driver ?? 0, 2) }}
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-semibold">
                                        ${{ number_format($package->price, 2) }}
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                                        <span class="rounded-full bg-sky-100 px-3 py-1 text-xs font-semibold text-sky-800">
                                            {{ $package->billing_cycle }}
                                        </span>
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                                        @if ($package->is_active)
                                            <span class="px-3 py-1 bg-green-100 text-green-800 rounded-full text-xs font-semibold">
                                                {{ __('Active') }}
                                            </span>
                                        @else
                                            <span class="px-3 py-1 bg-gray-100 text-gray-800 rounded-full text-xs font-semibold">
                                                {{ __('Inactive') }}
                                            </span>
                                        @endif
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                                        <a href="{{ route('admin.packages.edit', $package) }}"
                                            class="mr-2 inline-block rounded bg-yellow-600 px-3 py-1 text-white hover:bg-yellow-700">
                                            {{ __('Edit') }}
                                        </a>
                                        <form action="{{ route('admin.packages.destroy', $package) }}" method="POST" class="inline"
                                            onsubmit="return confirm('{{ __('Are you sure?') }}');">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit"
                                                class="px-3 py-1 bg-red-600 text-white rounded hover:bg-red-700">
                                                {{ __('Delete') }}
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="9" class="px-6 py-4 text-center text-sky-700/80">
                                        {{ __('No packages found') }}
                                    </td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>

                @if ($packages->hasPages())
                    <div class="border-t border-sky-100 bg-sky-50/50 px-6 py-4">
                        {{ $packages->links() }}
                    </div>
                @endif
            </div>
        </div>
    </div>
</x-app-layout>
