{{-- Admin branch switcher. Selection is persisted in session by BranchContext. --}}
@if (($canSwitchBranch ?? false) && isset($branches) && $branches->count() > 1)
    <form method="GET" class="flex flex-wrap gap-3 rounded-2xl border border-slate-200 bg-white p-4">
        <select name="branch_id" class="rounded-lg border-slate-300 text-sm" @if ($autoSubmit ?? true) onchange="this.form.submit()" @endif>
            @foreach ($branches as $branch)
                <option value="{{ $branch->id }}" @selected((int) $branchId === (int) $branch->id)>{{ $branch->name }}</option>
            @endforeach
        </select>
        @isset($extraFilters)
            {!! $extraFilters !!}
        @endisset
        @unless ($autoSubmit ?? true)
            <button type="submit" class="btn-primary">Filter</button>
        @endunless
        @if ($autoSubmit ?? true)
            {{-- Keep non-JS fallback --}}
            <noscript><button type="submit" class="btn-primary">Filter</button></noscript>
        @endif
    </form>
@elseif (isset($branches) && $branches->isNotEmpty())
    <p class="text-sm text-slate-500">{{ $branches->first()->name }}</p>
@endif
