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

@section('content')
    @parent
    <section class="bg-white pb-4">
        <div class="container">
            <div class="row">
                <div class="col">
                    <h1 class="h2 mb-2">Zoznam otázok testu</h1>
                    <span>"{{ $test->nazov }}"</span>
                </div>
            </div>
        </div>
    </section>

    <section class="flush-with-above space-0">
        <div class="bg-white">
            <div class="container">
                <div class="row">
                    <div class="col">
                        <ul class="nav nav-tabs" id="myTab" role="tablist">
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('vzdelavanie.sprava.testovanie.testy.edit', $test) }}">Test</a>
                            </li>
                            <li class="nav-item">
                                <p class="nav-link active">
                                    Otázky
                                    <span class="badge badge-light">{{ $test->otazky->count() }}</span>
                                </p>
                            </li>
                            <li class="nav-item">
                                <p class="nav-link">Odpovede</p>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="flush-with-above height-80 d-block">
        <div class="tab-content">
            <div class="tab-pane fade show active">
                <div class="container">
                    <div class="row mb-4">
                        <div class="col">
                            <h5>Zoznam otázok testu</h5>
                        </div>
                    </div>
                    <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 {{ $test->otazky->count() }}</span>
                                </div>
                                <form class="d-flex align-items-center">
                                    <span class="mr-2 text-muted text-small text-nowrap">Zoradiť podľa:</span>
                                    <select class="custom-select">
                                        <option value="new-old" selected>Od najnovších</option>
                                        <option value="old-new">Od najstarších</option>
                                        <option value="status">Podľa stavu</option>
                                    </select>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                        @if(!$test->otazky->count())
                            <div class="card card-lg text-center">
                                <div class="card-body">
                                    <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>
                            </div>
                        @else
                            <div class="table-responsive">
                                <table class="table table-borderless table-hover align-items-center">
                                    <thead>
                                        <tr>
                                            <th scope="col">Znenie otázky</th>
                                            <th scope="col" class="text-center">Druh odpovede</th>
                                            <th scope="col" class="text-center">Stav</th>
                                            <th scope="col" class="text-center">Odpovedí</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">
                                                <span class="badge badge-info">{{ \Illuminate\Support\Str::upper($otazka->druh_spravnej_odpovede->label) }}</span>
                                            </td>
                                            <td class="text-center">
                                                <span class="badge @if($otazka->stav->equals(\Seka\Vzdelavanie\Enums\ModelStatusEnum::PUBLIKOVANE())) badge-success @else badge-warning @endif">{{ \Illuminate\Support\Str::upper($otazka->stav->label) }}</span>
                                            </td>
                                            <td scope="row" class="text-center">{{ $otazka->odpovede()->count() }}</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.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>
                        @endif
                        </div>
                    </div>

                    @if($test->otazky->count())
                    <div class="row">
                        <div class="col text-center">
                            <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>
                    @endif
                </div>
            </div>
        </div>
    </section>
@endsection