@extends('layouts.app')

@push('scripts')
    <script src="/vendor/seka/vzdelavanie/js/tinymce/tinymce.min.js"></script>
    <script>
      var editor_config = {
        path_absolute : "/",
        selector: "textarea.my-editor",
        language_url: '/vendor/seka/vzdelavanie/js/tinymce/langs/sk.js',
        plugins: [
          "advlist autolink lists link image charmap print preview hr anchor pagebreak",
          "searchreplace wordcount visualblocks visualchars code fullscreen",
          "insertdatetime media nonbreaking save table directionality",
          "emoticons template paste textpattern"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media | fullscreen",
        relative_urls: false,
        file_picker_callback : function(callback, value, meta) {
          var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
          var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;

          var cmsURL = editor_config.path_absolute + 'file-manager?field_name=' + field_name;
          // if (type == 'image') {
          //   cmsURL = cmsURL + "&type=Images";
          // } else {
            cmsURL = cmsURL + "&type=Files";
          // }

          tinyMCE.activeEditor.windowManager.open({
            file : cmsURL,
            title : 'Správca súborov',
            width : x * 0.8,
            height : y * 0.8,
            resizable : "yes",
            close_previous : "no"
          });
        }
      };

      tinymce.init(editor_config);
    </script>
@endpush

@push('styles')
    <style type="text/css">
        div.mce-fullscreen {
            position: fixed;
            top: 80px !important;
            left: 0;
        }
    </style>
@endpush

@section('content')
    @parent
    <div class="main-container">
        <section class="bg-white space-sm pb-4">
            <div class="container">
                <div class="row">
                    <div class="col">
                        <div class="media align-items-center">
                            <img src="{{$ucebnica->obrazok}}" alt="" class="avatar avatar-lg">
                            <div class="media-body">
                                <div class="mb-3">
                                    <h1 class="h2 mb-2">{{$ucebnica->nazov}}</h1>
                                    <span>Nová sekcia učebného materiálu</span>
                                </div>
                            </div>
                        </div>
                        @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">
                                    <a href="{{ route('vzdelavanie.kniznica.ucebnica.edit', ['id' => $ucebnica->getKey()]) }}" class="nav-link">Učebný materiál</a>
                                </li>
                                <li class="nav-item">
                                    <p class="nav-link active">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 justify-content-between">
                            <div class="col-12 col-md-4 mb-5">
                                <div class="card card-sm shadow">
                                    <div class="card-header">
                                        <span class="h6 title-decorative">Sekcie</span>
                                    </div>
                                    <div class="card-body">
                                        <div id="adminZoznamSekciiApp">
                                            <zoznam-component
                                                    :sekcie="{{ json_encode($sekcie) }}"
                                            ></zoznam-component>
                                        </div>
                                    </div>
                                    <div class="card-footer">
                                        <a href="{{ route('vzdelavanie.kniznica.ucebnica.sekcia.create', ['id' => $ucebnica->getKey()]) }}" class="btn btn-block btn-outline-primary">
                                            Vytvoriť sekciu
                                        </a>
                                    </div>
                                </div>
                            </div>

                            <div class="col-12 col-md-8">
                                @if($errors->any())
                                    <div class="row mb-3">
                                        <div class="col-12">
                                            <div class="alert alert-danger text-small mb-0" 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
                                <form id="editorSekcie" class="row" action="{{ route('vzdelavanie.kniznica.ucebnica.sekcia.store', ['id' => $ucebnica->getKey(),]) }}" 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 sekcie 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-12">
                                        <div class="form-group">
                                            <label>Obsah</label>
                                            <textarea name="obsah" class="form-control my-editor" rows="20">{!! old('obsah') !!}</textarea>
                                        </div>
                                    </div>
                                    @isset($sekciaId)
                                        <input name="sekciaId" type="number" hidden value="{{$sekciaId}}">
                                    @endisset
                                    <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>
@endsection

@push('scripts')
    <script type="application/javascript" src="{{mix('/vendor/seka/vzdelavanie/js/adminZoznamSekciiApp.js')}}"></script>
@endpush
