import hideButKeepRequireBehavior from "../util/hide_but_required_behavior";

AAForm.addTypeHandler('aa-ft-text-rich', (el, defaultOptions, libs)=>{
    var aaFormComponent = (async () => {
        return await libs.getLib('ckeditor')
            .create(el, defaultOptions)
            .then(editor => {
                let textarea = editor.sourceElement;
                hideButKeepRequireBehavior(textarea);

                const wcPlugin = editor.plugins.get('WordCount');
                if (wcPlugin) {
                    const wcContainer = wcPlugin.wordCountContainer;
                    editor.ui.view.element.appendChild(wcContainer);
                }

                return editor;
            })
            .catch(error => {
                console.error(error);
            });
    })();

    return aaFormComponent;
});
AAForm.setTypeDefaultOptions('aa-ft-text-rich', AAFormConfig.config['aa-ft-text-rich']);
