import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import FlowchartIcon from '../../themes/icons/flowchart.svg';
import FlowchartDialogCommand from './flowchartdialogcommand';

export default class QMSCKEditorFlowchartPlugin extends Plugin {
    init() {
        const editor = this.editor;
        const t = editor.t;
        editor.ui.componentFactory.add('qmsFlowchart', locale => {
            const view = new ButtonView(locale);
            const command = editor.commands.get('flowchartDialog');
            view.set({
                label: t('Flowchart'),
                icon: FlowchartIcon,
                tooltip: true
            });

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

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

            return view;
        });

        editor.commands.add('flowchartDialog', new FlowchartDialogCommand(editor));
    }
}
