import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import TemplateIcon from '../../themes/icons/load_template.svg';
import LoadTemplateDialogCommand from './loadtemplatedialogcommand';
export default class QMSCKEditorLoadTemplatePlugin extends Plugin {
    init() {
        const editor = this.editor;
        const t = editor.t;

        editor.ui.componentFactory.add('qmsLoadTemplate', locale => {
            const view = new ButtonView(locale);
            const command = editor.commands.get('loadtemplateDialog');
            view.set({
                label: t('Templates'),
                icon: TemplateIcon,
                tooltip: true
            });

            view.bind('isEnabled').to(command);

            view.on('execute', () => {
              command.execute();
            });

            return view;
        });

        editor.commands.add('loadtemplateDialog', new LoadTemplateDialogCommand(editor));
    }
}
