@php use Seka\Portal\Modul\Vzdelavanie\Enums\ModelStatusEnum;use Seka\Portal\Modul\Vzdelavanie\Models\Testovanie\HodnotenieOdpovedeEnum; @endphp
<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 = HodnotenieOdpovedeEnum::SPRAVNA;
                    if (isset($odpoved) && $odpoved->hodnotenie) {
                        $checked = $odpoved->hodnotenie;
                    }
                @endphp
                @foreach(HodnotenieOdpovedeEnum::cases() as $case)
                    <div class="form-check form-check-inline">
                        <input type="radio" class="form-check-input" name="hodnotenie"
                               id="hodnotenie-{{ $loop->index }}" value="{{ $case->value }}"
                               @if($checked->equal($case)) checked @endif>
                        <label class="form-check-label"
                               for="hodnotenie-{{ $loop->index }}">{{ $case->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 = ModelStatusEnum::PUBLIKOVANE;
                    if (isset($odpoved) && $odpoved->stav) {
                        $checked = $odpoved->stav;
                    }
                @endphp
                @foreach(ModelStatusEnum::cases() as $case)
                    <div class="form-check form-check-inline">
                        <input type="radio" class="form-check-input" name="stav" id="stav-{{ $loop->index }}"
                               value="{{ $case->value }}" @if($checked->equal($case)) checked @endif>
                        <label class="form-check-label" for="stav-{{ $loop->index }}">{{ $case->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="{{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