<div wire:ignore class="modal fade " id="anagraficaParte" tabindex="-1" aria-labelledby="anagraficaParteLabel"
            aria-hidden="true" data-keyboard="false" style="z-index: 9999">
            <div class="modal-dialog modal-xl">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="anagraficaParteLabel">Inserimento/modifica anagrafica</h5>
                    </div>
                    <div class="modal-body">
                        <div class="row mt-3">
                            <div class="col-md-4">
                                <label for="anag_type" class="form-label">Tipologia</label>
                            </div>
                            <div class="col-md-8">
                                <input type="radio" value="0" {{ $anag_type == 0 ? 'checked' : '' }}
                                    name="anag_type">&nbsp;Persona fisica&nbsp;&nbsp;&nbsp;
                                <input type="radio" value="1" {{ $anag_type == 1 ? 'checked' : '' }}
                                    name="anag_type">&nbsp;Persona giuridica
                            </div>
                        </div>
                        <div id="boxPersonaFisica">
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_firstname" class="form-label">Nome</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control @error('anag_firstname') is-invalid @enderror" type="text"
                                        id="anag_firstname" wire:model="anag_firstname">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_lastname" class="form-label">Cognome</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control @error('anag_lastname') is-invalid @enderror" type="text"
                                        id="anag_lastname" wire:model="anag_lastname">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_gender" class="form-label">Sesso</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_gender">
                                        <option value="">
                                        <option value="M">Uomo
                                        <option value="F">Donna
                                    </select>
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_birth_date" class="form-label">Data di nascita</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="date" id="anag_birth_date"
                                        wire:model="anag_birth_date">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_nazionalita" class="form-label">Nazionalità</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_nazionalita" onchange="toggleNationalityFields()">
                                        <option value="">
                                        <option value="0">Italiana
                                        <option value="1">Straniera
                                    </select>
                                </div>
                            </div>

                            <!-- Campi sempre visibili per nascita -->
                            <div class="row mt-3" id="pippo">
                                <div class="col-md-4">
                                    <label for="anag_birth_town_id" class="form-label">Comune di nascita</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control anag_birth_town_id" wire:model="anag_birth_town_id"
                                        style="width:100%">
                                        <option value="{{ $anag_birth_town_id }}">
                                            {{ $this->getLocalita($anag_birth_town_id) }}
                                    </select>
                                </div>
                            </div>

                            <div class="row mt-3" id="foreignBirthCountry" style="display: none;">
                                <div class="col-md-4">
                                    <label for="anag_foreign_birth_country" class="form-label">Paese di nascita</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_foreign_birth_country">
                                        <option value="">Seleziona paese</option>
                                        @foreach (\App\Models\LocationCountry::all() as $country)
                                            <option value="{{ $country->id }}">{{ $country->name }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="row mt-3" id="foreignBirthCity" style="display: none;">
                                <div class="col-md-4">
                                    <label for="anag_foreign_birth_city" class="form-label">Città di nascita</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_foreign_birth_city"
                                        wire:model="anag_foreign_birth_city">
                                </div>
                            </div>

                            <!-- Selector per tipo di residenza -->
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_residenza_tipo" class="form-label">Tipo residenza</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_residenza_tipo" onchange="toggleResidenceFields()">
                                        <option value="">Seleziona tipo</option>
                                        <option value="0">Italiana</option>
                                        <option value="1">Straniera</option>
                                    </select>
                                </div>
                            </div>

                            <!-- Campi residenza italiana -->
                            <div class="row mt-3" id="italianResidenceFields" style="display: none;">
                                <div class="col-md-4">
                                    <label for="anag_residenza_town_id" class="form-label">Comune di residenza</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control select2 anag_residenza_town_id"
                                        wire:model="anag_residenza_town_id" style="width:100%">
                                        <option value="{{ $anag_residenza_town_id }}">
                                            {{ $this->getLocalita($anag_residenza_town_id) }}
                                    </select>
                                </div>
                            </div>

                            <!-- Campi residenza straniera -->
                            <div class="row mt-3" id="foreignResidenceCountry" style="display: none;">
                                <div class="col-md-4">
                                    <label for="anag_foreign_residence_country" class="form-label">Paese di residenza</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%"
                                        wire:model="anag_foreign_residence_country">
                                        <option value="">Seleziona paese</option>
                                        @foreach (\App\Models\LocationCountry::all() as $country)
                                            <option value="{{ $country->id }}">{{ $country->name }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="row mt-3" id="foreignResidenceCity" style="display: none;">
                                <div class="col-md-4">
                                    <label for="anag_foreign_residence_city" class="form-label">Città di residenza</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_foreign_residence_city"
                                        wire:model="anag_foreign_residence_city">
                                </div>
                            </div>

                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_residenza_address" class="form-label">Indirizzo di residenza</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_residenza_address"
                                        wire:model="anag_residenza_address">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_residenza_cap" class="form-label">CAP</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_residenza_cap"
                                        wire:model="anag_residenza_cap">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_mobile" class="form-label">Telefono</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_mobile" wire:model="anag_mobile">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_sedicente" class="form-label">Sedicente</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_sedicente">
                                        <option value="">
                                        <option value="1">SI
                                        <option value="0">NO
                                    </select>
                                </div>
                            </div>

                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_tipo" class="form-label">Tipo di documento</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_documento_tipo">
                                        <option value=""></option>
                                        <option value="1">Carta d'Identità</option>
                                        <option value="2">Patente</option>
                                        <option value="3">Passaporto</option>
                                        <option value="4">Altro</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_patente_cat" class="form-label">Categoria patente</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_documento_patente_cat">
                                        <option value=""></option>
                                        <option value="AM">AM</option>
                                        <option value="A1">A1</option>
                                        <option value="A1B">A1B</option>
                                        <option value="A2">A2</option>
                                        <option value="A">A</option>
                                        <option value="AB">AB</option>
                                        <option value="B1">B1</option>
                                        <option value="B">B</option>
                                        <option value="BE">BE</option>
                                        <option value="C1">C1</option>
                                        <option value="C1E">C1E</option>
                                        <option value="C">C</option>
                                        <option value="CE">CE</option>
                                        <option value="D1">D1</option>
                                        <option value="D1E">D1E</option>
                                        <option value="DE">DE</option>
                                        <option value="E">E</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_tipo_altro" class="form-label">Altro documento</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_documento_tipo_altro"
                                        wire:model="anag_documento_tipo_altro">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_numero" class="form-label">Numero documento</label>
                                </div>
                                <div class="col-md-6">
                                    <input class="form-control" type="text" id="anag_documento_numero"
                                        wire:model="anag_documento_numero">
                                </div>
                                <div class="col-md-2">
                                    <button wire:click="getByPatente()" type="button"
                                        class="btn btn-block btn-success float-right btPatente" style="max-width:150px">Dati
                                        MCTC</button>
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_rilasciato_da" class="form-label">Rilasciato da</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%"
                                        wire:model="anag_documento_rilasciato_da">
                                        <option value=""></option>
                                        <option value="1">Comune</option>
                                        <option value="2">Motorizzazione</option>
                                        <option value="4">MCTC</option>
                                        <option value="5">MIT</option>
                                        <option value="6">UCO</option>
                                        <option value="7">Prefettura</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_rilasciato_da_altro" class="form-label">Rilasciato da altro</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_documento_rilasciato_da_altro"
                                        wire:model="anag_documento_rilasciato_da_altro">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_rilasciato_da_di_foreign_localita" class="form-label">Comune di rilascio</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control  anag_documento_rilasciato_da_di_foreign_localita"
                                        wire:model="anag_documento_rilasciato_da_di_foreign_localita" style="width:100%">
                                        <option value="">
                                    </select>
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_foreign_country" class="form-label">Nazionalità documento</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="anag_foreign_country">
                                        <option value="">
                                        <option value="0">Italiana
                                        <option value="1">Altro paese
                                    </select>
                                </div>
                            </div>

                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_rilasciato_il" class="form-label">Rilasciato il</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="date" id="anag_documento_rilasciato_il"
                                        wire:model="anag_documento_rilasciato_il">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_documento_scadenza_il" class="form-label">Data scadenza</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="date" id="anag_documento_scadenza_il"
                                        wire:model="anag_documento_scadenza_il">
                                </div>
                            </div>
                        </div>

                        <!-- SEZIONE PERSONA GIURIDICA -->
                        <div id="boxPersonaGiuridica">
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_rag_soc" class="form-label">Ragione sociale</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control @error('anag_rag_soc') is-invalid @enderror" type="text"
                                        id="anag_rag_soc" wire:model="anag_rag_soc">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_vat" class="form-label">Partita IVA</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control @error('anag_vat') is-invalid @enderror" type="text"
                                        id="anag_vat" wire:model="anag_vat">
                                </div>
                            </div>
                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="nazionalita" class="form-label">Paese Sede Legale</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%" wire:model="nazionalita" onchange="toggleCompanyFields()">
                                        <option value="">
                                        <option value="0">Italia
                                        <option value="1">Estero
                                    </select>
                                </div>
                            </div>

                            <div class="row mt-3" id="foreignPGResidenceCountry" style="display: none;">
                                <div class="col-md-4">
                                    <label for="anag_foreign_residence_country" class="form-label">Paese straniero sede legale</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" style="width:100%"
                                        wire:model="anag_foreign_residence_country">
                                        <option value="">Seleziona paese</option>
                                        @foreach (\App\Models\LocationCountry::all() as $country)
                                            <option value="{{ $country->id }}">{{ $country->name }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="row mt-3" id="foreignPGResidenceCity" style="display: none;">
                                <div class="col-md-4">
                                    <label for="anag_foreign_residence_city_legal" class="form-label">Città straniera sede legale</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_foreign_residence_city_legal"
                                        wire:model="anag_foreign_residence_city">
                                </div>
                            </div>

                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_sede_legale_address" class="form-label">Indirizzo sede legale</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_sede_legale_address"
                                        wire:model="anag_sede_legale_address">
                                </div>
                            </div>

                            <div id="italianAddressFields">
                                <div class="row mt-3">
                                    <div class="col-md-4">
                                        <label for="anag_sede_legale_town_id" class="form-label">Comune sede legale</label>
                                    </div>
                                    <div class="col-md-8">
                                        <select class="form-control select2 anag_sede_legale_town_id"
                                            wire:model="anag_sede_legale_town_id" style="width:100%">
                                            <option value="">
                                        </select>
                                    </div>
                                </div>
                                <div class="row mt-3">
                                    <div class="col-md-4">
                                        <label for="anag_sede_legale_cap" class="form-label">CAP sede legale</label>
                                    </div>
                                    <div class="col-md-8">
                                        <input class="form-control" type="text" id="anag_sede_legale_cap"
                                            wire:model="anag_sede_legale_cap">
                                    </div>
                                </div>
                                <div class="row mt-3">
                                    <div class="col-md-4">
                                        <label for="anag_sede_legale_prov_id" class="form-label">Provincia sede legale</label>
                                    </div>
                                    <div class="col-md-8">
                                        <select class="form-control select2 anag_sede_legale_prov_id"
                                            wire:model="anag_sede_legale_prov_id" style="width:100%">
                                            @foreach ($provinces as $p)
                                                <option value="{{ $p->id }}">{{ $p->title }}
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="row mt-3">
                                <div class="col-md-4">
                                    <label for="anag_phone" class="form-label">Telefono</label>
                                </div>
                                <div class="col-md-8">
                                    <input class="form-control" type="text" id="anag_phone" wire:model="anag_phone">
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Annulla</button>
                        @if (!$this->validated)
                            <button type="button" class="btn btn-primary" wire:click.prevent="anagraficaSave()">Salva</button>
                        @endif
                    </div>
                </div>
            </div>
        </div>
