import { Command } from 'ckeditor5/src/core';
import { toArray } from 'ckeditor5/src/utils';
import { insertVideo, isVideoAllowed } from "../video/utils";

export default class UploadVideoCommand extends Command {
    refresh() {
        const videoElement = this.editor.model.document.selection.getSelectedElement();
        const isVideo = videoElement && videoElement.name === 'video' || false;

        this.isEnabled = isVideoAllowed( this.editor.model ) || isVideo;
    }

    execute( options ) {
        const editor = this.editor;
        const model = editor.model;

        for ( const url of toArray( options.urls ) ) {
          insertVideo(model, { src: url , controls: true } );
      }
    }
}
