@extends('Vzdelavanie::layout.integrated')

@section('content')
    @parent
    <section class="bg-white space-sm pb-4">
        <div class="container">
            <div class="row justify-content-between">
                <div class="col-auto">
                    <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>@yield('titulok')</span>
                            </div>
                        </div>
                    </div>
                    @include('flash::message')
                </div>
                @yield('zobrazit')
            </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.sprava.kniznica.kategoria.ucebnice.edit', [$kategoria, $ucebnica]) }}" 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.sprava.kniznica.kategoria.ucebnice.sekcia.create', [$kategoria, $ucebnica]) }}" class="btn btn-block btn-outline-primary">
                                        <i class="fa fa-plus"></i>
                                        Vytvoriť sekciu
                                    </a>
                                </div>
                            </div>
                        </div>

                        <div class="col-12 col-md-8">
                            @yield('form')
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

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

@push('scripts')
    <script src="{{mix('/js/tinymce/tinymce.min.js', '/vendor/seka/vzdelavanie')}}"></script>
    <script>
      const editor_config = {
        path_absolute: '{{ URL::secure('/') }}',
        selector: "textarea.my-editor",
        language_url: '{{asset('/vendor/seka/vzdelavanie/js/tinymce/langs/sk.js')}}',
        language: 'sk',
        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 code | fullscreen",
        relative_urls: false,
        convert_urls: false,
        file_picker_callback : function(callback, value, meta) {
          const x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth
          const y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight
          const cmsURL = editor_config.path_absolute + '/file-manager?editor=tinymce5&type=Files'

          tinyMCE.activeEditor.windowManager.openUrl({
            url : cmsURL,
            title : 'Správca súborov',
            width : x * 0.8,
            height : y * 0.8,
            resizable : 'yes',
            close_previous : 'no',
            onMessage: (api, message) => {
              callback(message.content)
            }
          })
        }
      }

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

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