@extends('Terminy::layouts.integrated')

@push('styles')
    @livewireStyles
@endpush

@push('scripts')
    @livewireScripts
@endpush

@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">Upraviť udalosť</h1>
                    <span>Zoznam všetkých registrácií používateľov na udalosť</span>
                    @include('flash::message')
                </div>
                <div class="col-auto text-right">
                    <a href="{{ route('modul.terminy.frontend.udalosti.udalost.show', $udalost) }}" class="btn btn-primary">Zobraziť udalosť ›</a>
                </div>
            </div>
        </div>
    </section>

    <section class="flush-with-above space-0">
        <div class="bg-white">
            <div class="container">
                <div class="row">
                    <div class="col">
                        <ul class="nav nav-tabs" id="myTab" role="tablist">
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('modul.terminy.backend.udalosti.udalost.edit', $udalost) }}" role="tab">Udalosť</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link active" href="" role="tab">
                                    Registrácie
                                    <span class="badge badge-light">{{ $udalost->registracie()->count() }}</span>
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="flush-with-above">
        <div class="tab-content">
            <div class="tab-pane fade show active" role="tabpanel">
                <div class="container">
                    <div class="row">
                        <div class="col-12">
                            <div class="card card-sm shadow">
                                @livewire('Terminy::pages.udalosti.registracie.backend.livewire.components.form', ['udalost' => $udalost])
                                <div class="list-group list-group-flush">
                                    @forelse($registracieAktivne as $registracia)
                                        <div class="list-group-item">
                                            <div class="media item-align-center">
                                                <div class="media-body">
                                                    <div class="d-flex justify-content-between">
                                                        <div>
                                                            <h3 class="h4 text-truncate">
                                                                @if($registracia->pouzivatel)
                                                                    {{ $registracia->pouzivatel->meno }}
                                                                @else
                                                                    {{ $registracia->cele_meno }}
                                                                @endif
                                                                <small class="text-muted lead text-truncate">{{ $registracia->pracovisko->nazov }} [{{ $registracia->pracovisko->kod }}]</small>
                                                                @if($registracia->poznamka)<small class="text-muted">Poznámka: {{ $registracia->poznamka }}</small>@endif
                                                                <div class="d-flex justify-content-between">
                                                                    <div class="text-small">
                                                                        <ul class="list-inline text-muted">
                                                                            <li class="list-inline-item">
                                                                                <span class="icon-calendar"></span>
                                                                                Vytvorená: {{ $registracia->created_at->diffForHumans() }}
                                                                            </li>
                                                                            <li class="list-inline-item">
                                                                                <span class="icon-calendar"></span>
                                                                                Upravená: {{ $registracia->updated_at->diffForHumans() }}
                                                                            </li>
                                                                            <li class="list-inline-item">
                                                                                <span class="icon-user"></span>
                                                                                Vytvoril: {{ $registracia->vytvoril->meno }}
                                                                            </li>
                                                                        </ul>
                                                                    </div>
                                                                </div>
                                                            </h3>
                                                        </div>
                                                        <div class="d-flex align-items-center">
                                                            <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="#" onclick="event.preventDefault();(confirm('Chystáte sa odstrániť registráciu, prajete si pokračovať?')) ? document.getElementById('delete-registracia-{{ $registracia->hashId() }}-form').submit() : null;">
                                                                        <i class="fa fa-trash mr-1"></i>
                                                                        Zrušiť registráciu
                                                                    </a>

                                                                    <form id="delete-registracia-{{ $registracia->hashId() }}-form" action="{{ route('modul.terminy.backend.udalosti.udalost.registracie.delete', [$udalost, $registracia]) }}" method="POST" style="display: none;">
                                                                        @csrf
                                                                        @method('DELETE')
                                                                    </form>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    @empty
                                        <div class="list-group-item bg-light d-flex justify-content-center disabled py-4">
                                            <span class="text-muted h5">Žiadne registrácie na udalosti sa nenašli...</span>
                                        </div>
                                    @endforelse


                                    @if($registracieZrusene->isnotEmpty())
                                        <div class="card-header bg-secondary">
                                            <h6>Zrušené registrácie</h6>
                                        </div>

                                        @foreach($registracieZrusene as $registracia)
                                            <a class="list-group-item list-group-item-action disabled">
                                                <div class="media item-align-center">
                                                    <div class="media-body">
                                                        <div class="d-flex justify-content-between">
                                                            <div>
                                                                <h3 class="h4 text-truncate">
                                                                    @if($registracia->pouzivatel)
                                                                        {{ $registracia->pouzivatel->meno }}
                                                                    @else
                                                                        {{ $registracia->cele_meno }}
                                                                    @endif
                                                                    <small class="text-muted lead text-truncate">{{ $registracia->pracovisko->nazov }} [{{ $registracia->pracovisko->kod }}]</small>
                                                                    <div class="d-flex justify-content-between">
                                                                        <div class="text-small">
                                                                            <ul class="list-inline text-muted">
                                                                                <li class="list-inline-item">
                                                                                    <span class="icon-calendar"></span>
                                                                                    Vytvorená: {{ $registracia->created_at->diffForHumans() }}
                                                                                </li>
                                                                                <li class="list-inline-item">
                                                                                    <span class="icon-calendar"></span>
                                                                                    Upravená: {{ $registracia->updated_at->diffForHumans() }}
                                                                                </li>
                                                                                <li class="list-inline-item">
                                                                                    <span class="icon-user"></span>
                                                                                    Vytvoril: {{ $registracia->vytvoril->meno }}
                                                                                </li>
                                                                            </ul>
                                                                        </div>
                                                                    </div>
                                                                </h3>
                                                            </div>
                                                            <div>
                                                                @if($registracia->trashed())
                                                                    <span class="badge badge-danger">ZRUŠENÁ</span>
                                                                @endif
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </a>
                                        @endforeach
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection
