export default class CustomContextPad {
  constructor(config, contextPad, create, elementFactory, injector, translate) {
    this.create = create;
    this.elementFactory = elementFactory;
    this.translate = translate;

    if (config.autoPlace !== false) {
      this.autoPlace = injector.get('autoPlace', false);
    }

    contextPad.registerProvider(this);
  }

  getContextPadEntries(element) {
    const {
      autoPlace,
      create,
      elementFactory,
      translate
    } = this;

    function appendServiceTask(event, element) {
      if (autoPlace) {
        const shape = elementFactory.createShape({ type: 'bpmn:ServiceTask' });

        autoPlace.append(element, shape);
      } else {
        appendServiceTaskStart(event, element);
      }
    }

    function appendServiceTaskStart(event) {
      const shape = elementFactory.createShape({ type: 'bpmn:ServiceTask' });

      create.start(event, shape, element);
    }
    function appendUserTaskStart(event) {
      const shape = elementFactory.createShape({ type: 'bpmn:UserTask' });

      create.start(event, shape, element);
    }

    return {
      // 'append.service-task': {
      //   group: 'model',
      //   className: 'bpmn-icon-service-task',
      //   title: translate('Append ServiceTask'),
      //   action: {
      //     click: appendServiceTask,
      //     dragstart: appendServiceTaskStart
      //   }
      // },
      'create.user-task': {
        group: 'model',
        className: 'bpmn-icon-user-task',
        title: translate('Create {type}', { type: 'User Task' }),
        action: {
          dragstart: appendUserTaskStart,
          click: appendUserTaskStart
        }
      }
    };
  }
}

CustomContextPad.$inject = [
  'config',
  'contextPad',
  'create',
  'elementFactory',
  'injector',
  'translate'
];
