export default function PaletteProvider(bpmnFactory, create, elementFactory, palette, translate) {
  this.bpmnFactory = bpmnFactory
  this.create = create
  this.elementFactory = elementFactory
  this.translate = translate

  palette.registerProvider(this)
}

PaletteProvider.$inject = [
  'bpmnFactory',
  'create',
  'elementFactory',
  'palette',
  'translate',
]

PaletteProvider.prototype.getPaletteEntries = function () {
  const {
    bpmnFactory,
    create,
    elementFactory,
    translate,
  } = this

  function createApprovementUserTask(event) {
    const extensionElements = bpmnFactory.create('bpmn:ExtensionElements', {
      values: [
        bpmnFactory.create('camunda:Properties', {
          values: [
            bpmnFactory.create('camunda:Property', {
              name: 'tags',
              value: 'approvement',
            }),
            bpmnFactory.create('camunda:Property', {
              name: 'serviceKey',
              value: 'sd-adapter',
            }),
          ],
        }),
      ],
    })

    const businessObject = bpmnFactory.create('bpmn:UserTask', {
      name: translate('Approvement'),
      extensionElements,
    })

    const shape = elementFactory.createShape({
      type: 'bpmn:UserTask',
      businessObject,
    })

    create.start(event, shape)
  }

  return {
    'sd-separator-top': {
      group: 'sd',
      separator: true,
    },
    'create.approvement': {
      group: 'sd',
      className: 'bpmn-icon-user sd-badge',
      title: translate('Approvement'),
      action: {
        dragstart: createApprovementUserTask,
        click: createApprovementUserTask,
      },
    },
    'sd-separator-bottom': {
      group: 'sd',
      separator: true,
    },
  }
}
