<div>

    <div wire:ignore.self class="modal fade" id="exampleModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">

                {{-- CLAVE TOTAL: evita que Livewire recicle inputs --}}
                <div wire:key="modal-prospecto-{{ $prospecto?->id ?? 'create' }}">

                    <div class="modal-header">
                        <h5 class="modal-title">
                            {{ $prospecto ? 'Modificar prospecto' : 'Nuevo prospecto' }}
                        </h5>
                        <button type="button" class="close" data-dismiss="modal">
                            <span>&times;</span>
                        </button>
                    </div>

                    <div class="modal-body">

                        {{-- FORM UNICO --}}
                        <form
                            wire:submit.prevent="{{ $prospecto ? 'actualizarProspecto' : 'guardarProspecto' }}"
                            autocomplete="off"
                        >

                            {{-- ================= USUARIO ================= --}}
                            <div class="row">

                                <div class="col-md-6">
                                    <label>Nombre</label>
                                    <input class="form-control"
                                           wire:model.defer="pname"
                                           name="prospecto_name"
                                           autocomplete="off">
                                </div>

                                <div class="col-md-6">
                                    <label>Correo</label>
                                    <input class="form-control"
                                           wire:model.defer="pemail"
                                           name="prospecto_email"
                                           autocomplete="off">
                                </div>

                                <div class="col-md-6 mt-2">
                                    <label>Teléfono</label>
                                    <input class="form-control"
                                           wire:model.defer="ptelefono"
                                           name="prospecto_phone"
                                           autocomplete="off">
                                </div>

                                <div class="col-md-6 mt-2">
                                    <label>Dirección</label>
                                    <input class="form-control"
                                           wire:model.defer="pdireccion"
                                           name="prospecto_address"
                                           autocomplete="off">
                                </div>

                                @if(!$prospecto)
                                    <div class="col-md-6 mt-2">
                                        <label>Password</label>
                                        <input type="password"
                                               class="form-control"
                                               wire:model.defer="ppassword"
                                               name="prospecto_password"
                                               autocomplete="new-password">
                                    </div>
                                @endif

                            </div>

                            <hr>

                            {{-- ================= PLANTEL ================= --}}
                            <div class="mt-2">
                                <label>Campus</label>
                                <select class="form-control" wire:model.live="pplantels" name="prospecto_plantel">
                                    <option value="">Seleccione</option>
                                    @foreach($plantels as $p)
                                        @if($user->existe($p->id))
                                            <option value="{{ $p->id }}">{{ $p->name }}</option>
                                        @endif
                                    @endforeach
                                </select>
                            </div>

                            {{-- ================= ROL ================= --}}
                            <div class="mt-2">
                                <label>Rol</label>
                                <select class="form-control" wire:model="proles" name="prospecto_rol">
                                    <option value="">Seleccione</option>
                                    @foreach($roles as $r)
                                        <option value="{{ $r->id }}">{{ $r->name }}</option>
                                    @endforeach
                                </select>
                            </div>

                            <hr>

                            {{-- ================= NIVEL ================= --}}
                            <div class="mt-2">
                                <label>Nivel</label>
                                <select class="form-control" wire:model.live="selectedNivel" name="prospecto_nivel">
                                    <option value="">Seleccione</option>
                                    @foreach($niveles as $n)
                                        <option value="{{ $n->id }}">{{ $n->name }}</option>
                                    @endforeach
                                </select>
                            </div>

                            {{-- ================= PLAN ================= --}}
                            <div class="mt-2">
                                <label>Plan</label>
                                <select class="form-control" wire:model.live="selectedplan" name="prospecto_plan" {{ $active }}>
                                    <option value="">Seleccione</option>
                                    @foreach($plans as $pl)
                                        <option value="{{ $pl->id }}">
                                            {{ $pl->name }} - {{ $pl->rvoe }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>

                            {{-- ================= CAMPAÑA ================= --}}
                            <div class="mt-2">
                                <label>Campaña</label>
                                <select class="form-control" wire:model="pciclo" name="prospecto_ciclo">
                                    <option value="">Seleccione</option>
                                    @foreach($campans as $c)
                                        <option value="{{ $c->id }}">{{ $c->name }}</option>
                                    @endforeach
                                </select>
                            </div>

                            {{-- ================= TURNO ================= --}}
                            <div class="mt-2">
                                <label>Turno</label>
                                <select class="form-control" wire:model="pturno" name="prospecto_turno">
                                    <option value="">Seleccione</option>
                                    @foreach($turnos as $t)
                                        <option value="{{ $t->id }}">{{ $t->name }}</option>
                                    @endforeach
                                </select>
                            </div>

                            {{-- ================= MEDIO ================= --}}
                            <div class="mt-2">
                                <label>Medio</label>
                                <select class="form-control" wire:model="pmedio" name="prospecto_medio">
                                    <option value="">Seleccione</option>
                                    @foreach($medios as $m)
                                        <option value="{{ $m->id }}">{{ $m->name }}</option>
                                    @endforeach
                                </select>
                            </div>

                            <div class="text-end mt-4">
                                <button class="btn btn-primary">
                                    {{ $prospecto ? 'Actualizar' : 'Guardar' }}
                                </button>
                            </div>

                        </form>

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