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

@section('content')
    @parent
    <section class="bg-white space-sm">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col">
                    <h1 class="h2 mb-2">História testov</h1>
                    <span>Zoznam mojich spustených testov</span>
                </div>
            </div>
        </div>
    </section>

    <section>
        <div class="container">
            <div class="row">
                <div class="col">
                @if($testy->isEmpty())
                    <div class="alert alert-primary text-small">
                        <i class="icon-info mr-2"></i>
                        Zatiaľ neexistujú žiadne testy...
                    </div>
                @else
                    <div class="card card-sm shadow">
                        <div class="card-header bg-secondary d-flex justify-content-between align-items-center">
                            <div>
                                <span class="text-muted text-small">Výsledky {{ ($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>
                                        @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">
                                        @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>
                    </div>
                @endif
                </div>
            </div>
            @if($testy->count() && $testy->hasPages())
            <div class="row">
                <div class="col-12 d-flex justify-content-center">
                    {{ $testy->onEachSide(5)->links() }}
                </div>
            </div>
            @endif
        </div>
    </section>
@endsection

@push('scripts')
    <script type="text/javascript">
      $(function () {
        $('[data-toggle="tooltip"]').tooltip()
      })
    </script>
@endpush