import { Command } from '@ckeditor/ckeditor5-core';
import { formatDate } from '../common/qmsCKEditorUtil';
import { toMap } from '@ckeditor/ckeditor5-utils';

export default class TimestampCommand extends Command {

	execute(options) {
		const editor = this.editor;
		const model = editor.model;
    model.change( writer => {
      const attributes = toMap(editor.model.document.selection.getAttributes());
      const timestamp = writer.createText(formatDate(new Date(), options.datetimeformat), attributes);
      model.insertContent(timestamp, editor.model.document.selection );
    });
	}
}

