<div class="m-0 p-0">
    <div class="card-header bg-secondary d-flex justify-content-between align-items-center">
        <button class="btn btn-primary" type="button" data-target="#new-registration" data-toggle="collapse">
            <i class="icon-plus"></i>
            Vytvoriť registráciu
        </button>
        <span wire:loading class="spinner-grow spinner-grow-sm" role="status"></span>
        <a href="{{ route('modul.terminy.backend.udalosti.udalost.registracie.export', $udalost) }}" class="btn btn-secondary" type="button">
            <i class="icon-floppy"></i>
            Exportovať
        </a>
    </div>
    <div class="collapse" id="new-registration" wire:ignore.self>
        <div class="card-body">
            <div class="row justify-content-center text-center my-4">
                <div class="col">
                    <h5>Zvoľte existujúceho používateľa</h5>
                </div>
            </div>

            <div class="form-group">
                <select wire:model="pouzivatel.hash_id"
                        class="custom-select form-control"
                        id="pouzivatel"
                        name="pouzivatel"
                        autocomplete="off"
                >
                    @if($pouzivatelia->isNotEmpty())
                    <option value="">Zvoľte používateľa...</option>
                    @else
                    <option value="">neexistuje žiadny používateľ</option>
                    @endif
                    @foreach($pouzivatelia as $_pouzivatel)
                    <option value="{{ $_pouzivatel->hash_id }}">{{ $_pouzivatel->pracovisko->kod }}, {{ $_pouzivatel->cele_meno }}</option>
                    @endforeach
                </select>
                @error('pouzivatel.hash_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>

            <div class="row justify-content-center text-center my-4">
                <div class="col">
                    <h5>alebo zadajte celé meno a priezvisko</h5>
                </div>
            </div>

            <div class="form-row">
                <div class="col">
                    <div class="form-group">
                        <label for="meno">Meno</label>
                        <input wire:model="registracia.meno"
                               type="text"
                               id="meno"
                               class="form-control from-control-lg"
                               name="meno"
                               placeholder="Meno používateľa"
                               autocomplete="off"
                        >
                        @error('registracia.meno')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <label for="priezvisko">Priezvisko</label>
                        <input wire:model="registracia.priezvisko"
                               type="text"
                               id="priezvisko"
                               class="form-control from-control-lg"
                               name="priezvisko"
                               placeholder="Priezvisko používateľa"
                               autocomplete="off"
                        >
                        @error('registracia.priezvisko')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <label for="pracovisko">Pracovisko</label>
                        <select wire:model="registracia.pracovisko_id"
                                id="pracovisko"
                                class="custom-select form-control"
                                name="pracovisko"
                                placeholder="Zvoliť používateľa..."
                                autocomplete="off"
                        >
                            <option selected value="">Zvoľte pracovisko...</option>
                            @foreach($pracoviska as $pracovisko)
                                <option value="{{ $pracovisko->hash_id }}">{{ $pracovisko->kod }}, {{ $pracovisko->nazov }}</option>
                            @endforeach
                        </select>
                        @error('registracia.pracovisko_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="poznamka">Poznámka</label>
                <textarea wire:model.defer="registracia.poznamka"
                          id="poznamka"
                          name="poznamka"
                          rows="2"
                          class="form-control form-control-lg"
                          autocomplete="off"
                          maxlength="500"
                ></textarea>
                @error('registracia.poznamka')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>

        @if($udalost->maVytvoreneMoznosti())
            <div class="row justify-content-center text-center my-4">
                <div class="col">
                    <h5>Zvoľte si z dostupných možností registrácie</h5>
                </div>
            </div>

            <div class="m-0 p-0">
                @forelse($udalost->moznosti as $zoznamMoznosti)
                    <h5>
                        {{$zoznamMoznosti->getNazov()}}
                    </h5>
                    <form class="d-flex flex-column">
                        @forelse($zoznamMoznosti->getMoznosti() as $moznost)
                            <div class="custom-control custom-radio">
                                <input class="custom-control-input" type="radio" name="radio" id="moznost_{{$moznost->getId()}}" value="{{$moznost->getId()}}" wire:model="moznosti.{{$zoznamMoznosti->getKod()}}">
                                <label class="custom-control-label" for="moznost_{{$moznost->getId()}}">{{$moznost->getPopis()}}</label>
                            </div>
                        @empty
                            <span>Nie sú žiadne možnosti na výber...</span>
                        @endforelse
                    </form>

                    <hr>
                @empty
                    <span>Nie sú žiadne možnosti na výber...</span>
                @endforelse

                <div class="row">
                    <div class="col text-center">
                        <div class="custom-control custom-checkbox mb-2">
                            <input type="checkbox" class="custom-control-input" id="accept-options-choices" wire:model="acceptChoices">
                            <label class="custom-control-label" for="accept-options-choices">potvrdzujem mnou zvolené možnosti registrácie na udalosť</label>
                        </div>
                    </div>
                </div>
            </div>
        @endif

            <div class="d-flex align-items-center">
                <button type="submit" class="btn btn-success mr-3" wire:click="create()" @if(($udalost->maVytvoreneMoznosti() && (!$this->acceptChoices || !$this->choosedAllOptions)) || !$this->pouzivatelIsSet) disabled="disabled" @endif>
                    <span wire:loading.remove wire:target="create" class="icon-floppy"></span>
                    <span wire:loading wire:target="create" class="spinner-grow spinner-grow-sm" role="status"></span>
                    Vytvoriť registráciu
                </button>
                <a href="#new-registration" class="text-small text-muted" data-toggle="collapse">Zrušiť</a>
            </div>
        </div>
    </div>
</div>