@php use Carbon\CarbonInterface;use Illuminate\Support\Str; @endphp
@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">
                    <div class="media align-items-center">
                        <div class="media-body">
                            <h1 class="h2 mb-0">{{ $udalost->nazov }}</h1>
                            <h2 class="lead mb-2">{{ Str::ucfirst($udalost->druh->label()) }}</h2>
                            <div class="d-flex align-items-center">
                                <ul class="list-inline">
                                    <li class="list-inline-item">
                                        <span class="badge badge-secondary">
                                        @if($udalost->skoncila)
                                                Udalosť sa už konala
                                            @elseif($udalost->prebieha)
                                                Udalosť prebieha
                                            @elseif($udalost->nezacala)
                                                Udalosť sa ešte nekonala
                                            @else
                                                ???
                                            @endif
                                        </span>
                                        @if($udalost->povolena_registracia)
                                            <span class="badge badge-success">Povolená registrácia</span>
                                        @else
                                            <span class="badge badge-warning">Nie je povolená registrácia</span>
                                        @endif
                                        @if($udalost->nezacala)
                                            <span class="badge badge-secondary">
                                            Začne {{ $udalost->datum_od->diffForHumans(now(), CarbonInterface::DIFF_RELATIVE_TO_NOW, false, 4) }}
                                        </span>
                                        @endif
                                        @if($udalost->povolena_registracia)
                                            <span class="badge badge-secondary">
                                            Počet voľných miest je {{ $udalost->pocet_volnych_miest }}
                                        </span>
                                    </li>
                                    @endif
                                </ul>
                            </div>
                        </div>
                    </div>
                    @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>
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="card card-sm shadow">
                        <livewire:Terminy.frontend.registracie.components.form
                                :udalost="$udalost"/>
                        <div class="list-group list-group-flush">
                            @forelse($registracie 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 class="col">
                                                    <h4 class="text-truncate mb-1">
                                                        @if($registracia->pouzivatel)
                                                            {{ $registracia->pouzivatel->cele_meno }}
                                                        @else
                                                            {{ $registracia->cele_meno }}
                                                        @endif
                                                    </h4>
                                                    <h5 class="text-muted text-truncate mb-1">{{ $registracia->pracovisko->nazov }}
                                                        [{{ $registracia->pracovisko->kod }}]</h5>
                                                    @if($registracia->poznamka)
                                                        <small class="text-muted">Poznámka: {{ $registracia->poznamka }}</small>
                                                    @endif

                                                    @if($registracia->maVytvoreneMoznosti())
                                                        <h5 class="title-decorative mb-1">Možnosti</h5>
                                                        <dl class="row">
                                                            @forelse($registracia->moznosti as $zoznamMoznosti)
                                                                <dt class="col-sm-3">{{$zoznamMoznosti->getNazov()}}:
                                                                </dt>
                                                                <dd class="col-sm-9">
                                                                    @forelse($zoznamMoznosti->getMoznosti() as $moznost)
                                                                        <p>{{$moznost->getPopis()}}</p>
                                                                    @empty
                                                                        <p>-</p>
                                                                    @endforelse
                                                                </dd>
                                                            @empty
                                                                <dt>-</dt>
                                                            @endforelse
                                                        </dl>
                                                    @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->cele_meno }}
                                                                </li>
                                                            </ul>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div>
                                                    @if($registracia->trashed())
                                                        <span class="badge badge-danger">ZRUŠENÁ</span>
                                                    @endif
                                                </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"
                                                                @if($registracia->trashed()) disabled @endif
                                                                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.frontend.registracie.pracovisko.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
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection
