@extends('layouts.app')

@section('content')
    @parent
    <div class="main-container">
        <section class="bg-white space-sm pb-4">
            <div class="container">
                <div class="row">
                    <div class="col">
                        <h1 class="h2 mb-2">Nový učebný materiál</h1>
                        @include('flash::message')
                    </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">
                                    <p class="nav-link active">Učebný materiál</p>
                                </li>
                                <li class="nav-item">
                                    <p class="nav-link disabled">Sekcie</p>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section class="flush-with-above height-80 d-block">
            <div class="tab-content">
                <div class="tab-pane fade show active">
                    <div class="container">
                        <div class="row mb-4">
                            <div class="col">
                                <h5>Detaily učebného materiálu</h5>
                            </div>
                        </div>
                        @if($errors->any())
                        <div class="row">
                            <div class="col-12">
                                <div class="alert alert-danger text-small" role="alert">
                                    <i class="icon-shield"></i>
                                    <span>Skontrolujte si prosím zadané údaje, niečo nie je v poriadku.</span>
                                </div>
                            </div>
                        </div>
                        @endif
                        <div class="row">
                            <div class="col-12">
                                <form class="row" action="{{ route('vzdelavanie.kniznica.ucebnica.store') }}" method="post">
                                    @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="{{ 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" @empty($kategorie) readonly @endempty>
                                                @forelse($kategorie as $_kategoria)
                                                <option value="{{ $_kategoria->getKey() }}" @if(isset($kategoria) && ($kategoria->getKey() == $_kategoria->getKey())) 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 @if($errors->has('autor')) is-invalid @endif" type="text" name="autor" placeholder="celé meno autora učebného materiálu" value="{{ 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">{{ 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">
                                            <div class="custom-control custom-switch">
                                                <input type="checkbox" class="custom-control-input" name="verejne" id="public" value="1" @if(old('verejne', 0)) checked @endif">
                                                <label class="custom-control-label" for="public">zverejniť pre študentov</label>
                                            </div>
                                            @if($errors->has('verejne'))
                                                @foreach($errors->get('verejne') 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="{{ old('obrazok') }}" style="height: 5rem;" alt="">
                                                </div>
                                                <input id="thumbnail" hidden type="text" name="obrazok" value="{{ 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>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @push('scripts')
    <script type="application/javascript">
        $(window).on('load', function () {
          $('#myTab a').on('click', function (e) {
            e.preventDefault()
            $(this).tab('show')
          })
        })
    </script>

    <script src="/vendor/laravel-filemanager/js/stand-alone-button.js"></script>
    <script type="application/javascript">
      $('#lfm').filemanager('file', {prefix: '/file-manager'});
    </script>
    @endpush
@endsection
