import { Plugin } from 'ckeditor5/src/core';
import videoUploadIcon from '../theme/icons/video.svg';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';

export default class VideoUploadUI extends Plugin {
    init() {
        const editor = this.editor;
        const t = editor.t;

        const componentCreator = locale => {
            const command = editor.commands.get('browseVideoDialog');

            const allowMultipleFiles=  editor.config.get('video.upload.allowMultipleFiles');
            const videoTypes = editor.config.get('video.upload.types');

            const buttonView = new ButtonView( locale );
            buttonView.bind('isEnabled').to(command);
            buttonView.set( {
                label: t('Browse Video'),
                icon: videoUploadIcon,
                tooltip: true
            } );

            buttonView.on('execute', () => {
              editor.execute('browseVideoDialog', { allowMultipleFiles, videoTypes });
            });

            return buttonView;
        };

        editor.ui.componentFactory.add( 'uploadVideo', componentCreator );
        editor.ui.componentFactory.add( 'videoUpload', componentCreator );
    }
}
