<form id="editor" class="row" method="post" action="{{ $actionRoute }}">
    @if(isset($edit) && $edit === true)
        @method('PUT')
    @endif
    @csrf()
    <div class="col-12">
        <div class="form-group">
            <label>
                Znenie otázky
                <span class="text-red">*</span>
            </label>
            <textarea name="znenie" class="form-control my-editor" rows="10">{{ $otazka->znenie ?? old('znenie') }}</textarea>
        </div>
    </div>

    <div class="col-6">
        <div class="form-group">
            <label>
                Druh odpovede
                <span class="text-red">*</span>
            </label>
            <select class="custom-select mb-2" name="druh_spravnej_odpovede" autocomplete="off">
                @php
                    $selected = \Seka\Vzdelavanie\Models\Testovanie\DruhSpravnejOdpovedeEnum::JEDNA();

                    if (isset($otazka) && $otazka->druh_spravnej_odpovede) {
                        $selected = $otazka->druh_spravnej_odpovede;
                    }
                @endphp
                @foreach(\Seka\Vzdelavanie\Models\Testovanie\DruhSpravnejOdpovedeEnum::toArray() as $value => $label)
                <option value="{{ $value }}" @if($selected->equals(\Seka\Vzdelavanie\Models\Testovanie\DruhSpravnejOdpovedeEnum::make($value))) selected @endif>{{ $label }}</option>
                @endforeach
            </select>
        </div>
    </div>
    <div class="col-6">
        <div class="form-group">
            <label>
                Stav
                <span class="text-red">*</span>
            </label>
            <div class="form-group">
                @php
                    $checked = \Seka\Vzdelavanie\Enums\ModelStatusEnum::PUBLIKOVANE();
                    if (isset($otazka) && $otazka->stav) {
                        $checked = $otazka->stav;
                    }
                @endphp
                @foreach(\Seka\Vzdelavanie\Enums\ModelStatusEnum::toArray() as $value => $label)
                    <div class="form-check form-check-inline">
                        <input type="radio" class="form-check-input" name="stav" id="public-{{ $loop->index }}" value="{{ $value }}" @if($checked->equals(\Seka\Vzdelavanie\Enums\ModelStatusEnum::make($value))) checked @endif>
                        <label class="form-check-label" for="public-{{ $loop->index }}">{{ $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>
    <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>

@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?editor=tinymce5';
          // if (type == 'image') {
          //   cmsURL = cmsURL + "&type=Images";
          // } else {
          cmsURL = cmsURL + "&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 type="text/css">
        div.mce-fullscreen {
            position: fixed;
            top: 80px !important;
            left: 0;
        }
    </style>
@endpush