@extends('layouts.default')

@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">Zoznam používateľov</h1>
                    <span>Zoznam a správa používateľov prihlásených do Portálu</span>
                </div>
            </div>
        </div>
    </section>

    <section>
        <div class="container">
            <div class="row">
                <div class="col-12">
                @if($pouzivatelia->isEmpty())
                    <div class="alert alert-primary text-small">
                        <i class="icon-info mr-2"></i>
                        Zatiaľ neexistujú žiadni používatelia...
                    </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">Počet položiek {{ ($pouzivatelia->currentPage() * $pouzivatelia->perPage()) - $pouzivatelia->perPage() + 1 }} - @if($pouzivatelia->total() > ($pouzivatelia->currentPage() * $pouzivatelia->perPage())) {{ $pouzivatelia->currentPage() * $pouzivatelia->perPage() }} @else {{ $pouzivatelia->total() }} @endif z {{ $pouzivatelia->total() }}</span>
                            </div>
                        </div>

                        <div class="table-responsive">
                            <table class="table align-items-center mb-0">
                                <thead>
                                    <tr>
                                        <th scope="col">#</th>
                                        <th scope="col">Meno</th>
                                        <th scope="col">Stav</th>
                                        <th scope="col" class="text-center">Posledné prihlásenie</th>
                                        <th scope="col" class="text-center">Prvé prihlásenie</th>
                                    </tr>
                                </thead>
                                <tbody>
                                @foreach($pouzivatelia as $pouzivatel)
                                    <tr class="bg-white">
                                        <td>{{ ($pouzivatelia->currentPage() * $pouzivatelia->perPage()) - $pouzivatelia->perPage() + $loop->index + 1 }}.</td>
                                        <th scope="row">
                                            <a href="{{ route('portal.sprava.pouzivatelia.edit', $pouzivatel) }}">
                                                <div class="media align-items-center">
                                                    <i class="icon-user text-gray fa-2x mr-2"></i>
                                                    <div class="media-body">
                                                        <span class="h6 font-weight-bolder mb-0">{{ $pouzivatel->meno }}</span>
                                                        <div class="text-uppercase text-small text-muted">{{ $pouzivatel->pracovisko->nazov }}, kód {{ $pouzivatel->pracovisko->kod }}</div>
                                                    </div>
                                                </div>
                                            </a>
                                        </th>
                                        <td class="text-left">
                                            <span class="badge @if($pouzivatel->jeBlokovany()) badge-warning @else badge-success @endif">
                                                {{ ucfirst($pouzivatel->stav->label) }}
                                            </span>
                                        </td>
                                        <td class="text-center">
                                            <span @isset($pouzivatel->datum_posledneho_prihlasenia) data-toggle="tooltip" title="{{ $pouzivatel->datum_posledneho_prihlasenia->format('d.m.Y H:i:s') }}" @endisset>
                                                {{ isset($pouzivatel->datum_posledneho_prihlasenia) ? $pouzivatel->datum_posledneho_prihlasenia->longRelativeDiffForHumans() : '-' }}
                                            </span>
                                        </td>
                                        <td class="text-center">
                                            <span @isset($pouzivatel->created_at) data-toggle="tooltip" title="{{ $pouzivatel->created_at->format('d.m.Y H:i:s') }}" @endisset>
                                                {{ isset($pouzivatel->created_at) ? $pouzivatel->created_at->longRelativeDiffForHumans() : '-' }}
                                            </span>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                @endif
                </div>
            </div>
            @if(!$pouzivatelia->isEmpty() && $pouzivatelia->hasPages())
            <div class="row">
                <div class="col-12 d-flex justify-content-center">
                    {{ $pouzivatelia->onEachSide(5)->links() }}
                </div>
            </div>
            @endif
        </div>
    </section>
@endsection