import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';

import Autosave from "@ckeditor/ckeditor5-autosave/src/autosave";
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
import UploadAdapter from '@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter';
import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript';
import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
import Heading from '@ckeditor/ckeditor5-heading/src/heading';
import Image from '@ckeditor/ckeditor5-image/src/image';
import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';
import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
import Indent from '@ckeditor/ckeditor5-indent/src/indent';
import Link from '@ckeditor/ckeditor5-link/src/link';
import List from '@ckeditor/ckeditor5-list/src/list';
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Table from '@ckeditor/ckeditor5-table/src/table';
import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar';
import TextTransformation from '@ckeditor/ckeditor5-typing/src/texttransformation';
import Alignment from "@ckeditor/ckeditor5-alignment/src/alignment";
import Font from "@ckeditor/ckeditor5-font/src/font";
import SourceEditing from "@ckeditor/ckeditor5-source-editing/src/sourceediting";
import CloudServices from "@ckeditor/ckeditor5-cloud-services/src/cloudservices";
import WordCount from "@ckeditor/ckeditor5-word-count/src/wordcount";

import PasteAsPlainText from './plugin/PasteAsPlainText.js';

class ClassicEditor extends ClassicEditorBase {
}

ClassicEditor.builtinPlugins = [
    Autosave,
    Essentials,
    UploadAdapter,
    Autoformat,

    Bold,
    Code,
    Italic,
    Strikethrough,
    Subscript,
    Superscript,
    Underline,

    BlockQuote,
    CKFinder,
    EasyImage,
    Heading,
    Image,
    ImageCaption,
    ImageStyle,
    ImageToolbar,
    ImageUpload,
    Indent,
    Link,
    List,
    MediaEmbed,
    Paragraph,
    // PasteFromOffice,// we don't want intelligent paste from word, only bring back
    Table,
    TableToolbar,
    TextTransformation,
    Alignment,
    Font,
    SourceEditing,
    CloudServices,

    WordCount,

    // custom aa plugins
    PasteAsPlainText,
];

// Editor configuration.
ClassicEditor.defaultConfig = {
    alignment: {
        options: ['left', 'right', 'center', 'justify']
    },
    toolbar: {
        items: [
            'heading',
            '|',
            'bold',
            'italic',
            'link',
            'bulletedList',
            'numberedList',
            '|',
            'indent',
            'outdent',
            '|',
            //'imageUpload',

            'blockQuote',
            'insertTable',
            'mediaEmbed',

            'undo',
            'redo',
        ]
    },
    image: {
        toolbar: [
            'imageStyle:full',
            'imageStyle:side',
            '|',
            'imageTextAlternative'
        ]
    },
    table: {
        contentToolbar: [
            'tableColumn',
            'tableRow',
            'mergeTableCells'
        ]
    },
    heading: {
        options: [
            {model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph'},
            // {model: 'heading1', view: 'h1', title: 'Heading 1 (h1)', class: 'ck-heading_heading1'},
            {model: 'heading2', view: 'h2', title: 'Titre 2 (h2)', class: 'ck-heading_heading2'},
            {model: 'heading3', view: 'h3', title: 'Titre 3 (h3)', class: 'ck-heading_heading3'},
            {model: 'heading4', view: 'h4', title: 'Titre 4 (h4)', class: 'ck-heading_heading4'},
            {model: 'heading5', view: 'h5', title: 'Titre 5 (h5)', class: 'ck-heading_heading5'},
            {model: 'heading6', view: 'h6', title: 'Titre 6 (h6)', class: 'ck-heading_heading6'}
        ]
    },
    // This value must be kept in sync with the language defined in webpack.config.js.
    language: 'fr',

    // custom aa config values
    aaForcePlainTextPaste: true,
    wordCount: {
        displayWords: true,
        displayCharacters: true,
        onUpdate: stats => {
            console.log( `Characters: ${stats.characters}, Words: ${stats.words}` );
        }
    }
};
global.ClassicEditor = ClassicEditor;

export default ClassicEditor
