<div class="m-0 p-0">
    <div class="card-header bg-secondary d-flex justify-content-between align-items-center">
        <div class="d-flex justify-content-between">
            <button class="btn btn-primary" type="button" data-target="#new-registration" data-toggle="collapse">
                <i class="icon-plus"></i>
                Vytvoriť registráciu
            </button>
            <div class="mx-1"></div>
            <a href="{{ route('modul.terminy.backend.udalosti.udalost.registracie.export', $udalost) }}"
               class="btn btn-secondary"
               type="button">
                <i class="icon-floppy"></i>
                Exportovať registrácie
            </a>
        </div>
        <span wire:loading class="spinner-grow spinner-grow-sm" role="status"></span>
        <form class="d-flex align-items-center">
            <span class="mr-2 text-muted text-small text-nowrap">Zoradiť:</span>
            <select class="custom-select" wire:model.change="sort">
                <option value="1">od najstarších</option>
                <option value="0">od najnovších</option>
            </select>
        </form>
    </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.change="pouzivatelId"
                        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 wire:key="wk-pouzivatel-{{ $_pouzivatel->id }}"
                                value="{{ $_pouzivatel->id }}">{{ $_pouzivatel->pracovisko->kod }}
                            , {{ $_pouzivatel->cele_meno }}</option>
                    @endforeach
                </select>
                @error('pouzivatelId')
                <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.change="registraciaMeno"
                               type="text"
                               id="meno"
                               class="form-control from-control-lg"
                               name="meno"
                               placeholder="Meno používateľa"
                               autocomplete="off"
                        >
                        @error('registraciaMeno')
                        <div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <label for="priezvisko">Priezvisko</label>
                        <input wire:model.change="registraciaPriezvisko"
                               type="text"
                               id="priezvisko"
                               class="form-control from-control-lg"
                               name="priezvisko"
                               placeholder="Priezvisko používateľa"
                               autocomplete="off"
                        >
                        @error('registraciaPriezvisko')
                        <div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <label for="pracovisko">Pracovisko</label>
                        <select wire:model.change="registraciaPracoviskoId"
                                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 wire:key="wk-pracovisko-{{ $pracovisko->id }}"
                                        value="{{ $pracovisko->id }}"
                                >{{ $pracovisko->kod }}, {{ $pracovisko->nazov }}</option>
                            @endforeach
                        </select>
                        @error('registraciaPracoviskoId')
                        <div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="poznamka">Poznámka</label>
                <textarea wire:model.change="registraciaPoznamka"
                          id="poznamka"
                          name="poznamka"
                          rows="2"
                          class="form-control form-control-lg"
                          autocomplete="off"
                          maxlength="500"
                ></textarea>
                @error('registraciaPoznamka')
                <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.change="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.change="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>