<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 odpovede
                <span class="text-red">*</span>
            </label>
            <textarea name="znenie" class="form-control my-editor" rows="10">{{ $odpoved->znenie ?? old('znenie') }}</textarea>
        </div>
    </div>

    <div class="col-6">
        <div class="form-group">
            <label>
                Hodnotenie odpovede
                <span class="text-red">*</span>
            </label>
            <div class="form-group">
                @php
                    $checked = \Seka\Vzdelavanie\Models\Testovanie\HodnotenieOdpovedeEnum::SPRAVNA();
                    if (isset($odpoved) && $odpoved->hodnotenie) {
                        $checked = $odpoved->hodnotenie;
                    }
                @endphp
                @foreach(\Seka\Vzdelavanie\Models\Testovanie\HodnotenieOdpovedeEnum::toArray() as $value => $label)
                    <div class="form-check form-check-inline">
                        <input type="radio" class="form-check-input" name="hodnotenie" id="hodnotenie-{{ $loop->index }}" value="{{ $value }}" @if($checked->equals(\Seka\Vzdelavanie\Models\Testovanie\HodnotenieOdpovedeEnum::make($value))) checked @endif>
                        <label class="form-check-label" for="hodnotenie-{{ $loop->index }}">{{ $label }}</label>
                    </div>
                @endforeach
                @if($errors->has('stav'))
                    @foreach($errors->get('hodnotenie') as $message)
                        <div class="invalid-feedback">{{ $message }}</div>
                    @endforeach
                @endif
            </div>
        </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($odpoved) && $odpoved->stav) {
                        $checked = $odpoved->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="stav-{{ $loop->index }}" value="{{ $value }}" @if($checked->equals(\Seka\Vzdelavanie\Enums\ModelStatusEnum::make($value))) checked @endif>
                        <label class="form-check-label" for="stav-{{ $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