<x-admin-layout>

    <x-page-heading title="Modifier une commune" :breadcrumbs="['Communes', 'Modification']" />

    <section class="section">
        <div class="row">
            <div class="col-lg-12">
        
                <x-card>
                    <form action="{{ route('communes.update', $commune) }}" method="POST" novalidate>
                        @csrf
                        @method('PUT')

                        <div class="row g-3 mb-3">
                            <div class="col-md-6">
                                <x-input type="text" id="name" wire:model="name" :label="__('Nom de la commune')" :value="$commune->name" />
                            </div>
                            
                            <div class="col-md-6">
                                <x-label for="department" :label="__('Département')" />
                                <select class="form-select" id="department" name="department_id">
                                    <option value="">{{ __('Sélectionner une département') }}</option>
                                    @foreach ($departments as $value => $label)
                                        <option value="{{ $value }}" @if($value==$commune->department_id) selected @endif>{{ $label }}</option>
                                    @endforeach
                                </select>
                                <x-error name="department_id" />
                            </div>
                        </div>

                        <div class="row g-3 mb-3">
                            <div class="col-md-6">
                                <x-input type="text" id="pf_name" name="pf_name" :label="__('Nom du point focal')" :value="$commune->pf_name" />
                            </div>
                            <div class="col-md-6">
                                <x-input type="text" id="pf_poste" name="pf_poste" :label="__('Poste du point focal')" :value="$commune->pf_poste" />
                            </div>
                        </div>

                        <div class="row g-3 mb-3">
                            <div class="col-md-6">
                                <x-input type="text" id="pf_phone" name="pf_phone" :label="__('Téléphone du point focal')" :value="$commune->pf_phone" />
                            </div>
                            <div class="col-md-6">
                                <x-input type="text" id="pf_email" name="pf_email" :label="__('Email du point focal')" :value="$commune->pf_email" />
                            </div>
                        </div>

                        <div class="row">
                            <label class="form-label">
                                Cibles spatialisées
                            </label>
                            <div class="ms-1">
                                @foreach ($targets as $target)
                                    <div class="form-check form-switch">
                                        <input class="form-check-input" type="checkbox" role="switch" name="targets[]" value="{{ $target->id }}" @checked($commune->check_target_exist($target->id))>
                                        <label class="form-check-label" for="flexSwitchCheckDefault">{{ $target->code }} {{ $target->name }}</label>
                                    </div>
                                @endforeach
                            </div>
                        </div>

                        <x-button type="submit" :label="__('Mise à jour')" primary />
                        <x-button :href="route('communes.index')" :label="__('Annuler')" secondary outline />

                    </form>
                </x-card>

            </div>
        </div>
    </section>

</x-admin-layout>