@php use Illuminate\Support\Str;use Seka\Portal\Modul\Vzdelavanie\Enums\ModelStatusEnum; @endphp
@extends('Vzdelavanie::layout.integrated')

@section('content')
    @parent
    <section class="bg-white space-sm">
        <div class="container">
            <div class="row justify-content-between align-items-center">
                <div class="col-auto">
                    <h1 class="h2 mb-2">Zoznam definovaných testov</h1>
                    <span>Zoznam testov pozostávajúcich z otázok a odpovedí používaných pri písomných skúškach technikov emisných kontrol</span>
                </div>
                <div class="col-auto text-right"></div>
            </div>
        </div>
    </section>

    <section>
        <div class="container">
            <div class="row">
                <div class="col">
                    @if($testy->isEmpty())
                        <div class="card text-center">
                            <div class="card-body">
                                <h2 class="h3">Zatiaľ neexistujú žiadne testy...</h2>
                                <a href="{{ route('vzdelavanie.sprava.testovanie.testy.create') }}"
                                   class="btn btn-lg btn-outline-primary">
                                    <i class="fa fa-plus"></i>
                                    &nbsp;Vytvoriť nový test
                                </a>
                            </div>
                        </div>
                    @endif

                    <div class="card card-sm shadow">
                        <div class="card-header bg-secondary d-flex justify-content-between align-items-center">
                            <div class="text-left">
                                <a href="{{ route('vzdelavanie.sprava.testovanie.testy.create') }}"
                                   class="btn btn-primary">
                                    <i class="fa fa-plus"></i>
                                    &nbsp;Vytvoriť test
                                </a>
                            </div>
                        </div>
                        <div class="table-responsive">
                            <table class="table align-items-center mb-0">
                                <thead>
                                <tr>
                                    <th scope="col">Názov testu</th>
                                    <th scope="col" class="text-center">Vytvorených otázok</th>
                                    <th scope="col" class="text-center">Požadovaných otázok</th>
                                    <th scope="col" class="text-center">Stav</th>
                                    <th scope="col" class="text-center">Akcie</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($testy as $test)
                                    <tr class="bg-white">
                                        <th scope="row">
                                            <div class="media align-items-center">
                                                <div class="media-body">
                                                    <span class="h6 mb-0">{{ $test->nazov }}</span>
                                                    <span class="text-muted">{{ Str::limit($test->popis, 60) }}</span>
                                                </div>
                                            </div>
                                        </th>
                                        <td class="text-center">{{ $test->otazky->count() }}</td>
                                        <td class="text-center">{{ $test->pocet_otazok }}</td>
                                        <td class="text-center">
                                            <span class="badge @if($test->stav->equal(ModelStatusEnum::PUBLIKOVANE)) badge-success @else badge-warning @endif">{{ Str::upper($test->stav->label()) }}</span>
                                        </td>
                                        <td>
                                            <div class="dropdown">
                                                <button class="btn btn-sm btn-outline-primary dropdown-toggle dropdown-toggle-no-arrow"
                                                        type="button" id="dropdownMenuButton-1" data-toggle="dropdown"
                                                        aria-haspopup="true" aria-expanded="false">
                                                    <i class="icon-dot-3"></i>
                                                </button>
                                                <div class="dropdown-menu dropdown-menu-sm">
                                                    <a class="dropdown-item"
                                                       href="{{ route('vzdelavanie.sprava.testovanie.testy.edit', $test) }}">
                                                        <i class="fa fa-edit"></i>
                                                        &nbsp;Upraviť
                                                    </a>
                                                    <div class="dropdown-divider"></div>
                                                    <a class="dropdown-item" href="#"
                                                       onclick="event.preventDefault();(confirm('Chystáte sa odstrániť test, prajete si pokračovať?')) ? document.getElementById('delete-test-{{ $test->hashId() }}-form').submit() : null;">
                                                        <i class="fa fa-trash"></i>
                                                        &nbsp;Odstrániť
                                                    </a>

                                                    <form id="delete-test-{{ $test->hashId() }}-form"
                                                          action="{{ route('vzdelavanie.sprava.testovanie.testy.destroy', $test) }}"
                                                          method="POST" style="display: none;">
                                                        @csrf
                                                        @method('DELETE')
                                                    </form>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                        <div class="card-footer bg-secondary d-flex justify-content-between align-items-center">
                            {{ $testy->onEachSide(5)->links() }}
                            {{ $testy->links('partials.pagination.pagination-summary') }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection