@php
    /** @var \App\Models\Mission|null $mission */
    $isEdit = isset($mission) && $mission instanceof \App\Models\Mission;
@endphp

<div class="row g-4">
    <div class="col-lg-8">
        <div class="block block-rounded mb-0">
            <div class="block-header block-header-default">
                <h3 class="block-title">{{ $isEdit ? 'Modifier mission' : 'Nouvelle mission' }}</h3>
            </div>
            <div class="block-content">
                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label" for="client_id">Client</label>
                        <select id="client_id" name="client_id" class="form-select" required>
                            <option value="">Selectionner un client</option>
                            @foreach($clients as $client)
                                <option value="{{ $client->id }}" @selected((int) old('client_id', $mission->client_id ?? 0) === $client->id)>
                                    #{{ $client->id }} · {{ $client->name }} ({{ $client->email }})
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="liner_id">Liner</label>
                        <select id="liner_id" name="liner_id" class="form-select">
                            <option value="">Non assigne</option>
                            @foreach($liners as $liner)
                                <option value="{{ $liner->id }}" @selected((int) old('liner_id', $mission->liner_id ?? 0) === $liner->id)>
                                    #{{ $liner->id }} · {{ $liner->name }} ({{ $liner->email }})
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-12">
                        <label class="form-label" for="title">Titre</label>
                        <input id="title" type="text" name="title" class="form-control form-control-alt" value="{{ old('title', $mission->title ?? '') }}" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="event_name">Evenement</label>
                        <input id="event_name" type="text" name="event_name" class="form-control form-control-alt" value="{{ old('event_name', $mission->event_name ?? '') }}">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="location">Lieu</label>
                        <input id="location" type="text" name="location" class="form-control form-control-alt" value="{{ old('location', $mission->location ?? '') }}" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="expected_start_at">Date debut</label>
                        <input id="expected_start_at" type="datetime-local" name="expected_start_at" class="form-control form-control-alt" value="{{ old('expected_start_at', isset($mission->expected_start_at) ? $mission->expected_start_at->format('Y-m-d\\TH:i') : '') }}" required>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label" for="budget_amount">Budget</label>
                        <input id="budget_amount" type="number" step="0.01" min="0" name="budget_amount" class="form-control form-control-alt" value="{{ old('budget_amount', isset($mission->budget_amount) ? (float) $mission->budget_amount : '') }}" required>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label" for="currency">Devise</label>
                        <input id="currency" type="text" name="currency" maxlength="3" class="form-control form-control-alt" value="{{ old('currency', $mission->currency ?? 'EUR') }}" required>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label" for="status">Statut</label>
                        <select id="status" name="status" class="form-select" required>
                            @foreach($statuses as $statusOption)
                                <option value="{{ $statusOption }}" @selected(old('status', $mission->status ?? 'published') === $statusOption)>
                                    {{ strtoupper($statusOption) }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-12">
                        <label class="form-label" for="description">Description</label>
                        <textarea id="description" name="description" rows="5" class="form-control form-control-alt">{{ old('description', $mission->description ?? '') }}</textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-4">
        <div class="block block-rounded mb-0">
            <div class="block-header block-header-default">
                <h3 class="block-title">Actions</h3>
            </div>
            <div class="block-content">
                <button type="submit" class="btn btn-alt-primary w-100 mb-2">
                    <i class="fa fa-save opacity-50 me-1"></i> {{ $isEdit ? 'Mettre a jour' : 'Creer la mission' }}
                </button>
                <a href="{{ route('bo.missions.index') }}" class="btn btn-alt-secondary w-100">Retour a la liste</a>
            </div>
        </div>
    </div>
</div>
