<x-layout.universal pageTitle="Nuova Anagrafica (Soggetto)" showBreadcrumb="true" showSidebar="true">
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h3 class="card-title mb-0">Crea Anagrafica</h3>
                    <a href="{{ route('admin.soggetti.index') }}" class="btn btn-secondary">
                        <i class="fas fa-arrow-left me-1"></i>Torna alla Lista
                    </a>
                </div>
                <div class="card-body">
                    @if ($errors->any())
                        <div class="alert alert-danger">
                            <h6><i class="fas fa-exclamation-triangle"></i> Errori di validazione:</h6>
                            <ul class="mb-0">
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif

                    <form method="POST" action="{{ route('admin.soggetti.store') }}">
                        @csrf

                        <!-- Nome e Cognome -->
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label for="nome" class="form-label">Nome</label>
                                <input type="text" name="nome" id="nome" value="{{ old('nome') }}" class="form-control">
                            </div>
                            <div class="col-md-6">
                                <label for="cognome" class="form-label">Cognome</label>
                                <input type="text" name="cognome" id="cognome" value="{{ old('cognome') }}" class="form-control">
                            </div>
                        </div>

                        <!-- Ragione Sociale (Alternativa a Nome/Cognome) -->
                        <div class="mb-3">
                            <label for="ragione_sociale" class="form-label">Ragione Sociale</label>
                            <input type="text" name="ragione_sociale" id="ragione_sociale" value="{{ old('ragione_sociale') }}" class="form-control">
                            <div class="form-text">Compilare solo se si tratta di una società/ente (alternativo a Nome/Cognome)</div>
                        </div>

                        <!-- Altri campi -->
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label for="codice_fiscale" class="form-label">Codice Fiscale</label>
                                <input type="text" name="codice_fiscale" id="codice_fiscale" value="{{ old('codice_fiscale') }}" class="form-control">
                            </div>
                            <div class="col-md-6">
                                <label for="partita_iva" class="form-label">Partita IVA</label>
                                <input type="text" name="partita_iva" id="partita_iva" value="{{ old('partita_iva') }}" class="form-control">
                            </div>
                        </div>

                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label for="email" class="form-label">Email</label>
                                <input type="email" name="email" id="email" value="{{ old('email') }}" class="form-control">
                            </div>
                            <div class="col-md-6">
                                <label for="telefono" class="form-label">Telefono</label>
                                <input type="text" name="telefono" id="telefono" value="{{ old('telefono') }}" class="form-control">
                            </div>
                        </div>

                        <!-- Tipo Soggetto -->
                        <div class="mb-3">
                            <label for="tipo" class="form-label">Tipo Soggetto <span class="text-danger">*</span></label>
                            <select name="tipo" id="tipo" required class="form-select">
                                <option value="">Seleziona Tipo</option>
                                @foreach($tipi_anagrafica as $tipo)
                                    <option value="{{ $tipo }}" {{ old('tipo') == $tipo ? 'selected' : '' }}>{{ ucfirst($tipo) }}</option>
                                @endforeach
                            </select>
                        </div>

                        <!-- Pulsanti -->
                        <div class="d-flex justify-content-end">
                            <a href="{{ route('admin.soggetti.index') }}" class="btn btn-outline-secondary me-2">
                                <i class="fas fa-times"></i> Annulla
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save"></i> Crea Anagrafica
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</x-layout.universal>