
const style = templateCustomizer.settings.style;
const isDarkMode = style === "dark";

var editor_config = {
    path_absolute : "/",
    language: "ar",
    language_url: "/admin/ar.js",
    selector: '.content',
    directionality : document.documentElement.dir,
    skin: isDarkMode ? 'oxide-dark' : 'oxide',
    content_css:  isDarkMode ? 'dark' : 'default',
    menubar: false,
    statusbar: false,
    toolbar: false,
    relative_urls : false,
  // remove_script_host : false,
  // document_base_url : window.location.href,
    plugins: 'print preview powerpaste casechange importcss tinydrive searchreplace autolink autosave save directionality advcode visualblocks visualchars fullscreen image link media mediaembed template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists checklist wordcount tinymcespellchecker a11ychecker imagetools textpattern noneditable help formatpainter permanentpen pageembed charmap tinycomments mentions linkchecker emoticons advtable',
      mobile: {
        plugins: 'print preview powerpaste casechange importcss tinydrive searchreplace autolink autosave save directionality advcode visualblocks visualchars fullscreen image link media mediaembed template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists checklist wordcount tinymcespellchecker a11ychecker textpattern noneditable help formatpainter pageembed charmap mentions linkchecker emoticons advtable'
      },
      menu: {
        tc: {
          title: 'TinyComments',
          items: 'addcomment showcomments deleteallconversations'
        }
      },
      menubar: 'file edit view insert format tools table tc help',

      toolbar1: "undo redo | revisionhistory | aidialog aishortcuts | blocks fontsizeinput fontfamily | underline bold italic | align numlist bullist | link image | table math media pageembed | lineheight  outdent indent",
      toolbar2: "strikethrough forecolor backcolor formatpainter removeformat | charmap emoticons checklist | code fullscreen preview | save print | pagebreak anchor codesample footnotes mergetags | addtemplate inserttemplate | addcomment showcomments | ltr rtl casechange | spellcheckdialog a11ycheck",
      font_family_formats: 'Andale Mono=andale mono,times; Arial=arial,helvetica,sans-serif; Arial Black=arial black,avant garde; Book Antiqua=book antiqua,palatino; Comic Sans MS=comic sans ms,sans-serif; Courier New=courier new,courier; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,chicago; Oswald=oswald; Symbol=symbol; Tahoma=tahoma,arial,helvetica,sans-serif; Terminal=terminal,monaco; Times New Roman=times new roman,times; Trebuchet MS=trebuchet ms,geneva; Verdana=verdana,geneva; Webdings=webdings; Wingdings=wingdings,zapf dingbats',
      autosave_ask_before_unload: true,
      autosave_interval: '30s',
      autosave_prefix: '{path}{query}-{id}-',
      autosave_restore_when_empty: false,
      autosave_retention: '2m',
      image_advtab: true,
      importcss_append: true,
      template_cdate_format: '[Date Created (CDATE): %m/%d/%Y : %H:%M:%S]',
      template_mdate_format: '[Date Modified (MDATE): %m/%d/%Y : %H:%M:%S]',
      height: 550,
      image_caption: true,
      quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quicktable',
      noneditable_noneditable_class: 'mceNonEditable',
      toolbar_mode: 'sliding',
      spellchecker_whitelist: ['Ephox', 'Moxiecode'],
      tinycomments_mode: 'embedded',
      content_style: '.mymention{ color: gray; }',
      contextmenu: false,
      a11y_advanced_options: true,


    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 + 'filemanager?editor=' + meta.fieldname+'&type=files';

      tinyMCE.activeEditor.windowManager.openUrl({
        url : cmsURL,
        title : 'مدير الملفات',
        width : x * 0.8,
        height : y * 0.8,
        resizable : "yes",
        close_previous : "no",
        onMessage: (api, message) => {
          callback(message.content);
        }
      });
    },
    init_instance_callback : function(editor) {
      document.querySelector('.tox-notifications-container').style.display = 'none';
    }
};

tinymce.init(editor_config);
