@extends('layouts.landing')

@section('title', 'Evaluaciones')

@section('content')
<div class="container-fluid">

    @if(session('info'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('info') }}
            <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
        </div>
    @endif

    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <div class="d-sm-flex align-items-center justify-content-between">
                <h6 class="m-0 font-weight-bold text-primary">
                    <i class="fa-duotone fa-regular fa-clipboard-list"></i> Evaluaciones
                </h6>
                <a href="{{ route('evaluacion.create') }}" class="btn btn-sm btn-primary shadow-sm">
                    <i class="fas fa-plus fa-sm text-white-50"></i> Nueva evaluación
                </a>
            </div>
        </div>

        <div class="card-body">
                <table id="tcont" class="table table-striped table-bordered nowrap table-hover" style="width:100%;">
                    <thead class="thead-light">
                        <tr>
                            <th>Título</th>
                            <th>Dirigida a</th>
                            <th>Estado</th>
                            <th class="text-center">Preguntas</th>
                            <th class="text-center">Respuestas</th>
                            <th>Vigencia</th>
                            <th class="text-center">Acciones</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($evaluaciones as $evaluacion)
                        <tr>
                            <td>
                                <strong>{{ $evaluacion->titulo }}</strong>
                                @if($evaluacion->anonima)
                                    <span class="badge badge-secondary ml-1" title="Anónima">
                                        <i class="fas fa-user-secret"></i>
                                    </span>
                                @endif
                            </td>
                            <td>
                                @php $slug = $evaluacion->tipo?->slug; @endphp
                                @if($slug === 'docente')
                                    <span class="badge badge-info"><i class="fa-duotone fa-solid fa-chalkboard-user"></i>   Docentes</span>
                                @elseif($slug === 'alumno')
                                    <span class="badge badge-success"><i class="fa-duotone fa-solid fa-user-graduate"></i>   Alumnos</span>
                                @elseif($slug === 'administrativo')
                                    <span class="badge badge-warning text-dark"><i class="fa-duotone fa-regular fa-briefcase"></i>   Administrativos</span>
                                @else
                                    <span class="badge badge-light">—</span>
                                @endif
                            </td>
                            <td>
                                @if($evaluacion->status === 'activa')
                                    <span class="badge badge-success">Activa</span>
                                @elseif($evaluacion->status === 'borrador')
                                    <span class="badge badge-secondary">Borrador</span>
                                @else
                                    <span class="badge badge-dark">Cerrada</span>
                                @endif
                            </td>
                            <td class="text-center">{{ $evaluacion->preguntas_count }}</td>
                            <td class="text-center">{{ $evaluacion->submissions_count }}</td>
                            <td>
                                @if($evaluacion->fecha_inicio || $evaluacion->fecha_fin)
                                    <small>
                                        {{ $evaluacion->fecha_inicio?->format('d/m/Y') ?? '—' }}
                                        &rarr;
                                        {{ $evaluacion->fecha_fin?->format('d/m/Y') ?? '—' }}
                                    </small>
                                @else
                                    <small class="text-muted">Sin fecha límite</small>
                                @endif
                            </td>
                            <td class="text-center text-nowrap">
                                <a href="{{ route('evaluacion.show', $evaluacion) }}"
                                   class="btn btn-sm btn-info" title="Ver detalle">
                                    <i class="fa-duotone fa-solid fa-eye"></i>
                                </a>
                                <a href="{{ route('evaluacion.edit', $evaluacion) }}"
                                   class="btn btn-sm btn-primary" title="Editar">
                                    <i class="fa-duotone fa-solid fa-pen-to-square"></i>
                                </a>
                                <form action="{{ route('evaluacion.destroy', $evaluacion) }}"
                                      method="POST" class="d-inline delete-form">
                                    @csrf @method('DELETE')
                                    <button class="btn btn-sm btn-danger" title="Eliminar">
                                        <i class="fa-duotone fa-solid fa-trash-can"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                        @empty
                        @endforelse
                    </tbody>
                </table>
        </div>
    </div>
</div>
@endsection


@section('scripts')
    @include('layouts._partials.tablaScript')
    @include('layouts._partials.delete')
@endsection
