@php use Illuminate\Support\Str;use Seka\Vzdelavanie\Enums\ModelStatusEnum;use Seka\Vzdelavanie\Models\Testovanie\HodnotenieOdpovedeEnum; @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 odpovedí na otázku</h1>
                    <span>"{!! $otazka->znenie  !!}"</span>
                </div>
                <div class="col-auto text-right">
                    <a href="{{ route('vzdelavanie.sprava.testovanie.testy.otazky.odpovede.create', [$test, $otazka]) }}"
                       class="btn btn-primary">
                        <i class="fa fa-plus"></i>
                        &nbsp;Vytvoriť odpoveď
                    </a>
                </div>
            </div>
        </div>
    </section>

    <section>
        <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 {{ $odpovede->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">
                    @if(!$otazka->odpovede->count())
                        <div class="card card-lg text-center">
                            <div class="card-body">
                                <i class="icon-add-to-list display-4 opacity-20"></i>
                                <h1 class="h5">Na otázku ešte neexistujú žiadne odpovede...</h1>
                                <a href="{{ route('vzdelavanie.sprava.testovanie.testy.otazky.odpovede.create', [$test, $otazka]) }}"
                                   class="btn btn-lg btn-outline-primary">
                                    <i class="fa fa-plus"></i>
                                    &nbsp;Vytvoriť novú odpoveď
                                </a>
                            </div>
                        </div>
                    @else
                        <div class="table-responsive">
                            <table class="table table-borderless align-items-center">
                                <thead>
                                <tr>
                                    <th scope="col">#</th>
                                    <th scope="col">Znenie odpovede</th>
                                    <th scope="col">Hodnotenie</th>
                                    <th scope="col">Stav</th>
                                    <th scope="col"></th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($odpovede as $odpoved)
                                    <tr class="bg-white">
                                        <th scope="col" class="text-monospace">{{ ++$loop->index }}.</th>
                                        <td scope="row">{!! $odpoved->znenie !!}</td>
                                        <td>
                                            <span class="badge @if($odpoved->hodnotenie->equal(HodnotenieOdpovedeEnum::SPRAVNA)) badge-success @else badge-danger @endif">{{ Str::upper($odpoved->hodnotenie->label()) }}</span>
                                        </td>
                                        <td>
                                            <span class="badge @if($odpoved->stav->equal(ModelStatusEnum::PUBLIKOVANE)) badge-success @else badge-warning @endif">{{ Str::upper($odpoved->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.odpovede.edit', [$test, $otazka, $odpoved]) }}">
                                                        <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ť odpoveď, prajete si pokračovať?')) ? document.getElementById('delete-odpoved-{{ $odpoved->hashId() }}-form').submit() : null;">
                                                        <i class="fa fa-trash"></i>
                                                        &nbsp;Odstrániť
                                                    </a>

                                                    <form id="delete-odpoved-{{ $odpoved->hashId() }}-form"
                                                          action="{{ route('vzdelavanie.sprava.testovanie.testy.otazky.odpovede.destroy', [$test, $otazka, $odpoved]) }}"
                                                          method="POST" style="display: none;">
                                                        @csrf
                                                        @method('DELETE')
                                                    </form>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr class="table-divider">
                                        <th></th>
                                        <td></td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </section>
@endsection