@extends('layouts.app')

@section('content')
    @parent
    <div class="main-container">
        <section class="bg-white space-sm pb-4">
            <div class="container">
                <div class="row justify-content-between align-items-center">
                    <div class="col-auto">
                        @include('flash::message')
                        <h1 class="h2">Nový učebný materiál</h1>
                    </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>
                        <div class="row">
                            @if($errors->any())
                            <div class="col-12 col-md-4 order-md-2">
                                <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>
                            @endif
                            <div class="col-12 col-md-8 order-md-1">
                                <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</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</label>
                                            <span class="text-red">*</span>
                                            <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="3">{{ 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
