import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
import {toWidget, toWidgetEditable, viewToModelPositionOutsideModelElement} from "@ckeditor/ckeditor5-widget/src/utils";
import CKEditorError from "@ckeditor/ckeditor5-utils/src/ckeditorerror";

export default class WidgetHelper extends Plugin
{
  static get requires()
  {
    return [Widget];
  }

  init()
  {
    this.editor.model.schema.register(this._schemaName(), this._schemaDefinition());
  }

  //noinspection JSMethodCanBeStatic
  _schemaName()
  {
    throw new CKEditorError('No schema name defined');
  }

  //noinspection JSMethodCanBeStatic
  _schemaDefinition()
  {
    throw new CKEditorError('No schema definition');
  }

  //noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols
  _toWidget(element, writer, options = {})
  {
    return toWidget(element, writer, options);
  }

  //noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols
  _toWidgetEditable(editable, writer)
  {
    return toWidgetEditable(editable, writer);
  }

  //noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols
  _viewToModelPositionOutsideModelElement(model, viewElementMatcher)
  {
    return viewToModelPositionOutsideModelElement(model, viewElementMatcher);
  }
}
