<?php

namespace Contao;

if ($GLOBALS['TL_CONFIG']['useRTE']) :
    // Use document.write() here in case TinyMCE is loaded in a subpalette (see #1424)
    ?>
    <script>
        window.tinymce || document.write('<script src="<?= $this->asset('js/tinymce.min.js', 'contao-components/tinymce4') ?>">\x3C/script>')
    </script>
    <script>
        window.tinymce && tinymce.init({
            selector: '#<?= $this->selector ?>',
            min_height: 336,
            language: '<?= Backend::getTinyMceLanguage() ?>',
            element_format: 'html',
            document_base_url: '<?= Environment::get('base') ?>',
            entities: '160,nbsp,60,lt,62,gt,173,shy',
            branding: false,
            verify_html: false,
            fontsize_formats: "8px 9px 10px 11px 12px 13px 14px 15px 16px 17px 18px 19px 20px 22px 24px 26px 28px 30px 32px 34px 36px 38px 40px 42px 44px 46px 48px 50px 52px 54px 56px 58px 60px",
            setup: function (editor) {
                editor.getElement().removeAttribute('required');
            },
            init_instance_callback: function (editor) {
                if (document.activeElement && document.activeElement.id && document.activeElement.id == editor.id) {
                    editor.editorManager.get(editor.id).focus();
                }
                editor.on('focus', function () {
                    Backend.getScrollOffset();
                });
            },
            <?php $this->block('picker'); ?>
            file_picker_callback: function (callback, value, meta) {
                Backend.openModalSelector({
                    'id': 'tl_listing',
                    'title': document.getElement('.tox-dialog__title').get('text'),
                    'url': Contao.routes.backend_picker + '?context=' + (meta.filetype == 'file' ? 'link' : 'file') + '&amp;extras[fieldType]=radio&amp;extras[filesOnly]=true&amp;extras[source]=<?= $this->source ?>&amp;value=' + value + '&amp;popup=1',
                    'callback': function (table, val) {
                        callback(val.join(','));
                    }
                });
            },
            file_picker_types: <?= json_encode($this->fileBrowserTypes) ?>,
            <?php $this->endblock(); ?>
            <?php $this->block('content_css'); ?>
            content_css: ['system/themes/<?= Backend::getTheme() ?>/tinymce.min.css', 'files/base/layout/css/style.min.css',],
            importcss_selector_converter: function (selector) {
                return false;
            },
            <?php $this->endblock(); ?>
            <?php $this->block('plugins'); ?>
            plugins: 'autosave charmap code fullscreen image importcss link lists paste searchreplace stripnbsp tabfocus table visualblocks visualchars',
            <?php $this->endblock(); ?>
            <?php $this->block('valid_elements'); ?>
            extended_valid_elements: 'q[cite|class|title],article,section,hgroup,figure,figcaption',
            <?php $this->endblock(); ?>
            <?php $this->block('menubar'); ?>
            menubar: 'edit insert format table',
            <?php $this->endblock(); ?>
            <?php $this->block('toolbar'); ?>
            toolbar: 'link unlink | image | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | code ',
            <?php $this->endblock(); ?>
            <?php $this->block('custom'); ?>
            <?php $this->endblock(); ?>
            browser_spellcheck: true,
            tabfocus_elements: ':prev,:next',
            importcss_append: true,

            style_formats_merge: true,
            style_formats: [{
                title: 'Custom',
                items: [
                    {
                        title: 'Text in Hauptfarbe',
                        inline: 'span',
                        classes: 'text-primary'
                    },
                    {
                        title: 'Text in Grau',
                        inline: 'span',
                        classes: 'text-gray'
                    },
                ]
            }],
            link_class_list: [{
                title: 'None',
                value: ''

            },
                {
                    title: 'Haupt-Button',
                    value: 'btn btn-primary'
                },
                {
                    title: 'Haupt-Button (Outline)',
                    value: 'btn btn-outline-primary'
                },
                {
                    title: 'Sekundärer Button',
                    value: 'btn btn-secondary'
                },
                {
                    title: 'Sekundärer Button (Outline)',
                    value: 'btn btn-outline-secondary'
                },
                {
                    title: 'Weißer Button mit schwarzer Schrift',
                    value: 'btn btn-white'
                },
                {
                    title: 'Transparenter Button mit schwarzer Schrift und Rahmen',
                    value: 'btn btn-outline-black'
                },
                {
                    title: 'Transparenter Button mit weißer Schrift und Rahmen',
                    value: 'btn btn-outline-white'
                },
            ]
        });
    </script>
<?php endif; ?>