import config from './initCKEditorConfig';

if (typeof window.CKEDITOR !== 'undefined') {
    window.CKEDITOR.config.language = 'vi';
}

export default () => {
    $('.form-control-ckeditor').each(function () {
        let field = $(this);
        let type = field.attr('data-ckeditor-type') || 'default';

        let editor = CKEDITOR.replace(field.get(0), {
            height: field.attr('data-height'),
            ...config[type],
        });

        editor.on('instanceReady', function () {
            this.document.on('input', () => editor.updateElement());
        });

        field.addClass('ckeditor');
    });
};
