@extends('Statistiky::layouts.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">
                    <h1 class="h2 mb-2">História spustených importov</h1>
                    <span>Údaje pre štatistiky sa importujú automaticky v pravidelných intervaloch. Na tomto mieste je možné skontrolovať informácie o procese importu.</span>
                    @include('flash::message')
                </div>
                <div class="col-auto text-right">
                    <a class="btn btn-primary" href="#" onclick="event.preventDefault();(confirm('Prajete si spustiť import údajov?')) ? document.getElementById('form-run-import').submit() : null;">
                        <i class="icon-play"></i>
                        Spustiť import
                    </a>
                    <form hidden id="form-run-import" method="POST" action="{{ route('modul.statistiky.backend.importy.spustit') }}">
                        @method('PUT')
                        @csrf
                    </form>
                </div>
            </div>
        </div>
    </section>

    <section>
        <div class="container">
            <div class="row">
                <div class="col">
                    <div class="card card-sm shadow">
                        @if($importy->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 {{ $importy->count() }}</span>
                                </div>
                            </div>
                            <div class="table-responsive">
                                <table class="table align-items-center mb-0">
                                    <thead>
                                    <tr>
                                        <th scope="col">#</th>
                                        <th scope="col">Súbor</th>
                                        <th scope="col">Stav</th>
                                        <th scope="col">Správa</th>
                                        <th scope="col">Čas akcie</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($importy as $import)
                                        <tr class="text-small">
                                            <td>{{ ($importy->currentPage() * $importy->perPage()) - $importy->perPage() + $loop->index + 1 }}.</td>
                                            <td class="w-auto">
                                                <div class="media align-items-center">
                                                    <div class="media-body">
                                                        <span class="h5 mb-0">{{ $import->subor->nazov() }}</span>
                                                        <span class="badge badge-light">{{ round($import->subor->velkost() / 1024, 2) }} kB</span>
                                                        <span class="badge badge-light text-muted">{{ \Illuminate\Support\Str::limit($import->subor->povodneUmiestnenie(), 80) }}</span>
                                                        <span class="badge badge-light text-muted">{{ \Illuminate\Support\Str::limit($import->subor->presunutyDo(), 80) }}</span>
                                                    </div>
                                                </div>
                                            </td>
                                            <td>
                                                <h6>
                                                    <span class="badge" style="background-color: {{ $import->stav->color() }}">
                                                        {{ \Illuminate\Support\Str::upper($import->stav->label) }}
                                                    </span>
                                                </h6>
                                            </td>
                                            <td>
                                                <p title="{{ $import->sprava }}">{{ \Illuminate\Support\Str::limit($import->sprava ?? '-', 10) }}</p>
                                            </td>
                                            <td>{{ $import->datum_cas_akcie ? $import->datum_cas_akcie->format('d.m.Y H:i:s') : '-' }}</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 importy...</span>
                                </div>
                            </div>
                        @endif
                    </div>
                </div>
            </div>

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