<x-layouts.tenant pageTitle="Sedes">
    <x-page-header title="Múltiples sedes" subtitle="Administra puntos de atención, datos de contacto y estado de cada sede." />

    <div class="grid grid-cols-1 xl:grid-cols-3 gap-6">
        <x-card title="Nueva sede">
            <form method="POST" action="{{ route('tenant.branches.store') }}" class="space-y-4">
                @csrf
                @include('tenant.modules.partials.branch-fields')
                <x-btn type="submit" class="w-full">Crear sede</x-btn>
            </form>
        </x-card>

        <div class="xl:col-span-2 space-y-4">
            @forelse ($branches as $branch)
                <x-card :title="$branch->name" :subtitle="$branch->address">
                    <form method="POST" action="{{ route('tenant.branches.update', $branch) }}" class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        @csrf
                        @method('PUT')
                        @include('tenant.modules.partials.branch-fields', ['branch' => $branch])
                        <div class="md:col-span-2 flex justify-between gap-2">
                            <div class="flex items-center gap-2">
                                @if ($branch->is_main)
                                    <x-badge color="indigo">Principal</x-badge>
                                @endif
                                <x-badge :color="$branch->is_active ? 'emerald' : 'gray'">{{ $branch->is_active ? 'Activa' : 'Inactiva' }}</x-badge>
                            </div>
                            <div class="flex gap-2">
                                <x-btn type="submit" size="sm">Guardar</x-btn>
                            </div>
                        </div>
                    </form>
                    @unless ($branch->is_main)
                        <form method="POST" action="{{ route('tenant.branches.destroy', $branch) }}" class="mt-3">
                            @csrf
                            @method('DELETE')
                            <x-btn type="submit" variant="danger" size="sm">Eliminar sede</x-btn>
                        </form>
                    @endunless
                </x-card>
            @empty
                <x-card>
                    <x-empty-state title="Sin sedes" />
                </x-card>
            @endforelse
            {{ $branches->links() }}
        </div>
    </div>
</x-layouts.tenant>
