@extends('layouts.landing')

@section('head')
    @include('layouts._partials.tablaStyle')
@endsection
@section('title',"Inicio")

@section('content')

<div class="container-fluid">
    <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">docente</h6>
                        @can('docente.create')
                        <a href="{{route('docente.create')}}" class="d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Crear docente</a>
                        @endcan
            </div>
        </div>

        <div class="card-body">
            <div class="container-fluid">

                    <table id="tcont" class="table table-striped table-bordered nowrap table-hover" style="width:100%;">
                        <thead>
                            <tr>
                                <th>Id</th>
                                <th>Nombre</th>
                                <th>Campus</th>
                                <th>Rol</th>
                                <th>Correo</th>
                                <th>Opciones</th>
                            </tr>
                        </thead>
                        <tbody>
                              @forelse ($docentes as $docente)
                                    @php $usr = $docente->docentes->first() @endphp
                                    <tr>
                                        <td>{{ $docente->id }}</td>
                                        <td>{{ $usr?->name }} {{ $usr?->apellidoPaterno }}</td>
                                        <td>
                                            @foreach($usr?->plantelUsuarios ?? [] as $plantel)
                                                <span class="badge bg-primary text-white">{{ $plantel->name }}</span>
                                            @endforeach
                                        </td>
                                        <td>
                                            @foreach($usr?->roles ?? [] as $rol)
                                                <span class="badge bg-primary text-white">{{ $rol->name }}</span>
                                            @endforeach
                                        </td>
                                        <td>{{ $usr?->email }}</td>
                                        <td class="row mx-auto">
                                            @can('docente.destroy')
                                            <div class="col-sm-6 col-md-6">
                                                <a href="{{ route('docente.edit', $docente->id) }}" class="btn btn-primary">Edit</a>
                                            </div>
                                            @endcan

                                            @can('docente.destroy')
                                        <div class="col-sm-6 col-md-6">
                                            <form class="delete-form" action="{{route('docente.destroy',$docente->id)}}" method="POST">
                                            @csrf
                                            @method('DELETE')
                                            <input type="submit" value="DELETE" class="btn btn-danger">
                                            </form>
                                        </div>
                                        @endcan
                                        </td>
                                    </tr>
                                @empty
                                    <p>Sin docentes.</p>
                                @endforelse

                        </tbody>
                    </table>


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

@endsection

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