@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 otázok testu</h1>
                    <span>"{{ $test->nazov }}"</span>
                </div>
                <div class="col-auto text-right">
                    <a href="{{ route('vzdelavanie.sprava.testovanie.testy.otazky.create', $test) }}"
                       class="btn btn-primary">
                        <i class="fa fa-plus"></i>
                        &nbsp;Vytvoriť novú otázku
                    </a>
                </div>
            </div>
        </div>
    </section>

    <section>
        <div class="container">
            <div class="card card-sm shadow">
                @if(!$test->otazky->count())
                    <div class="card-body text-center">
                        <h2 class="h3">Zatiaľ neexistujú žiadne otázky...</h2>
                        <a href="{{ route('vzdelavanie.sprava.testovanie.testy.otazky.create', $test) }}"
                           class="btn btn-lg btn-outline-primary">
                            <i class="fa fa-plus"></i>
                            &nbsp;Vytvoriť novú otázku
                        </a>
                    </div>
                @else
                    <div class="table-responsive">
                        <table class="table align-items-center">
                            <thead>
                            <tr>
                                <th scope="col">Znenie otázky</th>
                                <th scope="col" class="text-center">Odpovedí</th>
                                <th scope="col" class="text-center">Druh odpovede</th>
                                <th scope="col" class="text-center">Stav</th>
                                <th scope="col"></th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($test->otazky as $otazka)
                                <tr class="bg-white">
                                    <th scope="col" class="w-75">{!! $otazka->znenie !!}</th>
                                    <td class="text-center">{{ $otazka->odpovede()->count() }}</td>
                                    <td class="text-center">
                                        <span class="badge badge-info">{{ Str::upper($otazka->druh_spravnej_odpovede->label()) }}</span>
                                    </td>
                                    <td class="text-center">
                                        <span class="badge @if($otazka->stav->equal(ModelStatusEnum::PUBLIKOVANE)) badge-success @else badge-warning @endif">{{ Str::upper($otazka->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.otazky.edit', [$test, $otazka]) }}">
                                                    <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ť otázku, prajete si pokračovať?')) ? document.getElementById('delete-otazka-{{ $otazka->hashId() }}-form').submit() : null;">
                                                    <i class="fa fa-trash"></i>
                                                    &nbsp;Odstrániť
                                                </a>

                                                <form id="delete-otazka-{{ $otazka->hashId() }}-form"
                                                      action="{{ route('vzdelavanie.sprava.testovanie.testy.otazky.destroy', [$test, $otazka]) }}"
                                                      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">
                        <span class="text-muted text-small">Počet položiek {{ $test->otazky->count() }}</span>
                    </div>
                @endif
            </div>
        </div>
    </section>
@endsection