@extends('Vzdelavanie::layout.integrated')

@section('content')
@parent
<section>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col">
                <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>
    </div>
</section>

<section class="flush-with-above">
    <div class="container">
        <div class="row">
            <div class="col">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <div>
                        <span class="text-muted text-small">Počet položiek {{ $testy->count() }}</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col">
                @if(!$testy->count())
                <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="table-responsive">
                    <table class="table table-borderless table-hover align-items-center">
                        <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">{{ \Illuminate\Support\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->equals(\Seka\Vzdelavanie\Enums\ModelStatusEnum::PUBLIKOVANE())) badge-success @else badge-warning @endif">{{ \Illuminate\Support\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-dots-three-horizontal"></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>
        </div>

        @if($testy->count())
        <div class="row">
            <div class="col text-center">
                <a href="{{ route('vzdelavanie.sprava.testovanie.testy.create') }}" class="btn btn-primary">
                    <i class="fa fa-plus"></i>
                    &nbsp;Vytvoriť nový test
                </a>
            </div>
        </div>
        @endif
    </div>
</section>
@endsection