@extends('layouts.admin')

@section('title', 'Select Store')

@section('content')
<div class="admin-page-header mt-2"><h1>Select Store Context</h1></div>
<div class="admin-card"><div class="card-body">
@if($locations->isEmpty())
    <p class="text-muted mb-0">No stores are assigned to your account. Contact an admin.</p>
@else
<form method="post" action="{{ route('admin.locations.set-current') }}">
    @csrf
    <div class="mb-3">
        <label class="form-label" for="location_id">Store / Warehouse</label>
        <select name="location_id" id="location_id" class="form-select" required>
            @foreach($locations as $location)
                <option value="{{ $location->id }}" @selected((int) ($currentLocationId ?? 0) === (int) $location->id)>
                    {{ $location->name }} ({{ $location->type }})
                </option>
            @endforeach
        </select>
        @if(!empty($currentLocationId))
            <div class="form-text">Current: {{ $locations->firstWhere('id', $currentLocationId)?->name ?? ('#'.$currentLocationId) }}</div>
        @endif
    </div>
    <button type="submit" class="btn btn-primary">Continue</button>
</form>
@endif
</div></div>
@endsection
