@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Select Branch') }}</div>

                <div class="card-body">
                    @if (session('error'))
                        <div class="alert alert-danger" role="alert">
                            {{ session('error') }}
                        </div>
                    @endif

                    <p class="mb-4">You have access to multiple branches. Please select the branch you want to work with:</p>

                    <form method="POST" action="{{ route('branch.select.post') }}">
                        @csrf

                        <div class="list-group mb-3">
                            @foreach($branches as $branch)
                                <label class="list-group-item list-group-item-action">
                                    <div class="d-flex align-items-center">
                                        <input class="form-check-input me-3" type="radio" name="branch_id" 
                                               value="{{ $branch->id }}" 
                                               id="branch_{{ $branch->id }}"
                                               required>
                                        <div class="flex-grow-1">
                                            <h6 class="mb-1">{{ $branch->name }}</h6>
                                            <small class="text-muted">
                                                {{ $branch->branch_code }} 
                                                @if($branch->company)
                                                    - {{ $branch->company->display_name }}
                                                @endif
                                            </small>
                                        </div>
                                    </div>
                                </label>
                            @endforeach
                        </div>

                        <div class="d-grid">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Continue') }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
