<div>

                    @if($full)
                        <button onclick="Livewire.dispatch('create-prospecto')" class="d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Inscribir</button>
                    @endif

<div wire:key="modal-prospecto-{{ $prospecto?->id ?? '' }}">


                        @if ($prospecto)

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

                            <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>Apellido Paterno</label>
                                    <input class="form-control"
                                           wire:model.defer="papellidoPaterno"
                                           name="prospecto_apellidoPaterno"
                                           autocomplete="off">
                                </div>

                                <div class="col-md-6">
                                    <label>Apellido Materno</label>
                                    <input class="form-control"
                                           wire:model.defer="papellidoMaterno"
                                           name="prospecto_apellidoMaterno"
                                           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>

                            </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 class="row pt-5">
                            <div class="col-md-4">
                                <div class="mt-2">
                                    <label>Plan de pago</label>
                                    <select wire:model.live="selectedplane" class="form-control">
                                        <option value="">Selecciona plan de pago</option>
                                        @foreach ($planesPago as $plan)
                                            <option value="{{ $plan->id }}">
                                                {{ $plan->name }}
                                            </option>
                                        @endforeach
                                    </select>
                                    <button type="button" class="btn btn-success" wire:click="plan">
                                        Asignar plan
                                    </button>
                                </div>
                            </div>
                            <div class="col-md-8">
                                @if(count($conceptos))
                                    <ul class="list-group mt-3">
                                        @foreach ($conceptos as $concepto)
                                            <li class="list-group-item d-flex justify-content-between">

                                                <span>@foreach ($conceptosNombres as $tconcepto)
                                                    @if ($concepto->name == $tconcepto->id)
                                                        {{$tconcepto->name}}
                                                    @endif
                                                @endforeach</span>
                                                <span>{{ $concepto->fecha_pago }}</span>
                                                <span>{{ $concepto->monto }}</span>
                                            </li>
                                        @endforeach
                                    </ul>
                                @endif
                            </div>
                        </div>

                        <div class="row pt-5">

                        <div>
                            <h5>Expediente del alumno</h5>

                            @php
                                $nivel = $prospecto->nivelRel ?? null;

                                $tipos = $nivel
                                    ? $nivel->documentosRequeridos
                                    : collect();

                                $documentos = collect($prospecto?->documentos)->keyBy('tipo');
                            @endphp

                            @foreach($tipos as $tipo)

                            @php
                                $doc = $documentos[$tipo->slug] ?? null;
                            @endphp

                                <div class="mb-3">
                                    <strong>{{ strtoupper($tipo->name) }}</strong> :

                                    @if($doc)

                                        @if($doc->status == 1)
                                            <span class="badge bg-success">✔ Validado</span>

                                        @elseif($doc->status == 2)
                                            <span class="badge bg-danger">❌ Rechazado</span>

                                        @else
                                            <span class="badge bg-warning">Pendiente de revision</span>

                                            <button
                                            onclick="verDocumento('{{ url('documento/ver/'.$doc->id) }}', {{ $doc->id }})"
                                            class="btn btn-sm btn-primary mt-2">
                                            <i class="fa-duotone fa-solid fa-eye"></i> Ver documento
                                        </button>
                                        @endif



                                    @else
                                        <span class="text-danger">❌ Faltante</span>
                                    @endif

                                </div>
                            @endforeach

                        </div>


                        </div>

                        @else

                        @endif

                </div>


                <div class="modal fade"
     id="visorModal"
     tabindex="-1"
     wire:ignore.self>
        <div class="modal-dialog modal-xl">
            <div class="modal-content">
            <div class="modal-header">
            <h5 class="modal-title">Vista previa</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>

            <div class="modal-body">
                    <iframe id="visorFrame" width="100%" height="500px" style="border:none;" wire:ignore></iframe>

                <div class="m-5 text-center">


                    <button wire:click="rechazarDocumento" class="btn btn-danger">
                    <i class="fa-solid fa-trash-can"></i>    Rechazar
                    </button>

                    <button wire:click="aprobarDocumento" class="btn btn-success">
                     <i class="fa-duotone fa-regular fa-circle-check"></i> Aprobar
                    </button>
                </div>
            </div>
        </div>
    </div>

    </div>
</div>


