@extends('Vzdelavanie::pages.testovanie.historia.layout')

@section('historia_testov_pouzivatela_subtitle')
    @hasrole('spravca_pek')
    <span>Zoznam spustených testov na mojom pracovisku</span>
    @else
    <span>Zoznam mojich spustených testov</span>
    @endhasrole
@endsection

@section('historia_testov_pouzivatela_zoznam')
    @parent

    <div class="card card-sm shadow">
    @if($testy->isNotEmpty())
        <div class="card-header bg-secondary d-flex justify-content-between align-items-center">
            <div>
                <span class="text-muted text-small">Počet položiek {{ ($testy->currentPage() * $testy->perPage()) - $testy->perPage() + 1 }} - @if($testy->total() > ($testy->currentPage() * $testy->perPage())) {{ $testy->currentPage() * $testy->perPage() }} @else {{ $testy->total() }} @endif z {{ $testy->total() }}</span>
            </div>
        </div>

        <div class="table-responsive">
            <table class="table align-items-center mb-0">
                <thead>
                <tr>
                    <th scope="col">#</th>
                    @hasrole('spravca_pek')
                    <th scope="col">Používateľ</th>
                    @endhasrole
                    <th scope="col">Názov testu</th>
                    <th scope="col" class="text-center">Úspešnosť</th>
                    <th scope="col" class="text-center">Spustené</th>
                    <th scope="col" class="text-center">Vyhodnotené</th>
                    <th scope="col" class="text-center">Akcia</th>
                </tr>
                </thead>
                <tbody>
                @foreach($testy as $test)
                    <tr class="text-small">
                        <td>{{ ($testy->currentPage() * $testy->perPage()) - $testy->perPage() + $loop->index + 1 }}.</td>
                        @hasrole('spravca_pek')
                        <td class="w-15">
                            <h5 class="h6">{{ $test->pouzivatel->meno }} <span class="badge badge-light">{{ $test->pouzivatel->login }}</span></h5>
                        </td>
                        @endhasrole
                        <td class="w-auto">
                            <div class="media align-items-center">
                                <div class="media-body">
                                    <span class="h5 mb-0">{{ $test->nazov }}</span>
                                    <span class="text-muted">{{ \Illuminate\Support\Str::limit($test->popis, 60) }}</span>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="progress progress-sm">
                                <div class="progress-bar bg-success" role="progressbar" style="width: {{ $test->spravneZodpovedaneOtazkyPercentualne }}%" aria-valuenow="{{ $test->spravneZodpovedaneOtazkyPercentualne }}" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="Podiel správne zodpovedaných otázok"></div>
                                <div class="progress-bar bg-danger" role="progressbar" style="width: {{ $test->nespravneZodpovedaneOtazkyPercentualne }}%" aria-valuenow="{{ $test->nespravneZodpovedaneOtazkyPercentualne }}" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="Podiel nesprávne zodpovedaných otázok"></div>
                            </div>
                        </td>
                        <td class="text-center">{{ $test->casova_znacka_spustenia ? $test->casova_znacka_spustenia->longRelativeDiffForHumans() : '-' }}</td>
                        <td class="text-center">{{ $test->casova_znacka_vyhodnotenia ? $test->casova_znacka_vyhodnotenia->longRelativeDiffForHumans() : '-' }}</td>
                        <td class="w-auto">
                            @if($test->jeVyhodnoteny())
                                <a class="btn btn-md btn-success btn-block" href="{{ route('vzdelavanie.testy.pouzivatela.test.vyhodnotenie', $test) }}">
                                    Zobraziť
                                    <i class="icon-right-open"></i>
                                </a>
                            @else
                                <a class="btn btn-md btn-primary btn-block" href="{{ route('vzdelavanie.testy.pouzivatela.test.spustenie', $test) }}">
                                    <i class="icon-play"></i>
                                    Dokončiť
                                </a>
                            @endif
                        </td>
                    </tr>
                    @if($loop->remaining)
                        <tr class="table-divider"></tr>
                    @endif
                @endforeach
                </tbody>
            </table>
        </div>
    @else
        <div class="list-group list-group-flush">
            <div class="list-group-item bg-light d-flex justify-content-center disabled py-4">
                <span class="text-muted h5">Zatiaľ neexistujú žiadne testy.</span>
            </div>
        </div>
    @endif
    </div>
@endsection

@section('historia_testov_pouzivatela_zoznam_strankovanie')
    @if($testy->isNotEmpty() && $testy->hasPages())
        <div class="row">
            <div class="col-12 d-flex justify-content-center">
                {{ $testy->onEachSide(5)->links() }}
            </div>
        </div>
    @endif
@endsection