@extends('Terminy::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-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">Možnosti</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link"
                                   href="{{ route('modul.terminy.backend.udalosti.udalost.registracie.index', $udalost) }}"
                                   role="tab">
                                    Registrácie
                                    <span class="badge badge-light">{{ $pocetRegistracii }}</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">

                                @if($moznostiUdalosti->isEmpty())
                                    <div class="list-group-item bg-light d-flex justify-content-center disabled py-4">
                                        <span class="text-muted h5">Žiadne možnosti udalosti sa nenašli...</span>
                                    </div>
                                @else
                                    <div class="accordion" id="moznostiUdalosti">
                                        @foreach($moznostiUdalosti as $moznostUdalosti)
                                            <div class="card my-0">
                                                <div class="card-header d-flex justify-content-between"
                                                     id="header_{{ $moznostUdalosti->kod }}">
                                                    <h2 class="mb-0">
                                                        <button class="btn btn-link btn-block text-left" type="button"
                                                                data-toggle="collapse"
                                                                data-target="#moznost_{{ $moznostUdalosti->kod }}"
                                                                aria-expanded="true"
                                                                aria-controls="moznost_{{ $moznostUdalosti->kod }}">
                                                            {{ $moznostUdalosti->nazov }}
                                                        </button>
                                                    </h2>
                                                    @php
                                                        $f = $udalost->moznosti->filter(fn($a) => $a->getKod() === $moznostUdalosti->kod);
                                                    @endphp
                                                    <div class="badge badge-light align-self-center">
                                                        {{ $f->isNotEmpty() ? count($f->first()->getMoznosti()) : 0 }}
                                                    </div>
                                                </div>

                                                <div id="moznost_{{ $moznostUdalosti->kod }}"
                                                     class="collapse"
                                                     aria-labelledby="header_{{ $moznostUdalosti->kod }}"
                                                     data-parent="#moznostiUdalosti">
                                                    <div class="card-body">
                                                        <livewire:Terminy::backend.udalosti.components.moznosti-udalosti.components.form
                                                                :udalost="$udalost"
                                                                :moznostUdalosti="$moznostUdalosti"/>
                                                    </div>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection
