@php use Seka\Vzdelavanie\Enums\ModelStatusEnum; @endphp
<form class="row" method="post" action="{{ $actionRoute }}">
    @if(isset($edit) && $edit === true)
        @method('PUT')
    @endif
    @csrf()
    <div class="col-12">
        <div class="form-group">
            <label>
                Názov
                <span class="text-red">*</span>
            </label>
            <input class="form-control @if($errors->has('nazov')) is-invalid @endif" type="text" name="nazov"
                   placeholder="názov učebného materiálu" value="{{ $ucebnica->nazov ?? old('nazov') }}" required
                   autofocus>
            @if($errors->has('nazov'))
                @foreach($errors->get('nazov') as $message)
                    <div class="invalid-feedback">{{ $message }}</div>
                @endforeach
            @endif
        </div>
    </div>
    <div class="col-6">
        <div class="form-group">
            <label>
                Kategória
                <span class="text-red">*</span>
            </label>
            <select class="form-control" name="kategoria" autocomplete="off" @empty($kategorie) readonly @endempty>
                @forelse($kategorie as $_kategoria)
                    <option value="{{ $_kategoria->getKey() }}"
                            @if((isset($ucebnica) && ($ucebnica->kategoria_id == $_kategoria->getKey())) || (isset($kategoria) && ($kategoria->getKey() == $_kategoria->getKey()))) selected="selected" @endif>{{ $_kategoria->nazov }}</option>
                @empty
                    <option value="null">žiadna kategória</option>
                @endforelse
            </select>
        </div>
    </div>
    <div class="col-6">
        <div class="form-group">
            <label>
                Autor
                <span class="text-red">*</span>
            </label>
            <input class="form-control" type="text" name="autor" placeholder="celé meno autora učebného materiálu"
                   value="{{ $ucebnica->autor ?? old('autor') }}">
            @if($errors->has('autor'))
                @foreach($errors->get('autor') as $message)
                    <div class="invalid-feedback">{{ $message }}</div>
                @endforeach
            @endif
        </div>
    </div>
    <div class="col-12">
        <div class="form-group">
            <label>Popis</label>
            <textarea class="form-control" name="popis" placeholder="popis učebného materiálu"
                      rows="5">{{ $ucebnica->popis ?? old('popis') }}</textarea>
            <small>* nepovinný údaj</small>
            @if($errors->has('popis'))
                @foreach($errors->get('popis') as $message)
                    <div class="invalid-feedback">{{ $message }}</div>
                @endforeach
            @endif
        </div>
    </div>
    <div class="col-6">
        <div class="form-group">
            @php
                $checked = ModelStatusEnum::PUBLIKOVANE;
                if (isset($ucebnica) && $ucebnica->stav) {
                    $checked = $ucebnica->stav;
                }
            @endphp
            @foreach(ModelStatusEnum::cases() as $case)
                <div class="form-check form-check-inline">
                    <input type="radio" class="form-check-input" name="stav" id="stav-{{ $loop->index }}"
                           value="{{ $case->value }}" @if($checked->equal($case)) checked @endif>
                    <label class="form-check-label" for="stav-{{ $loop->index }}">{{ $case->label() }}</label>
                </div>
            @endforeach
            @if($errors->has('stav'))
                @foreach($errors->get('stav') as $message)
                    <div class="invalid-feedback">{{ $message }}</div>
                @endforeach
            @endif
        </div>
    </div>
    <div class="col-6">
        <div class="form-group">
            <label>Titulný obrázok</label>
            <div class="input-group">
                <div id="holder">
                    <img src="{{ $ucebnica->obrazok ?? old('obrazok') }}" style="height: 5rem;" alt="">
                </div>
                <input id="thumbnail" hidden type="text" name="obrazok"
                       value="{{ $ucebnica->obrazok ?? old('obrazok') }}">
                <span class="input-group-btn">
                    <a id="lfm" data-input="thumbnail" data-preview="holder" class="btn">
                        <i class="fa fa-picture-o"></i> Zvoliť
                    </a>
                </span>
            </div>
            <small>* nepovinný údaj</small>
            @if($errors->has('obrazok'))
                @foreach($errors->get('obrazok') as $message)
                    <div class="invalid-feedback">{{ $message }}</div>
                @endforeach
            @endif
        </div>
    </div>
    <div class="col-12">
        <div class="form-group">
            <button class="btn btn-primary" type="submit">
                <i class="fa fa-save"></i>
                Uložiť
            </button>
        </div>
    </div>
</form>