import Vue from 'vue'
import uniqueId from 'lodash'
import {i18n} from '../main'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyReportTemplateDialog from '@/components/DialogComponents/ReportTemplateDialog/CreateAndCopyReportTemplateDialog.vue'
import CopyReportTemplateDialog from '@/components/DialogComponents/ReportTemplateDialog/CopyReportTemplateDialog.vue'
import UpdateReportTemplateDialog from '@/components/DialogComponents/ReportTemplateDialog/UpdateReportTemplateDialog.vue'
import DeleteReportTemplateDialog from '@/components/DialogComponents/ReportTemplateDialog/DeleteReportTemplateDialog.vue'

Vue.component('CreateAndCopyReportTemplateDialog', CreateAndCopyReportTemplateDialog)
Vue.component('CopyReportTemplateDialog', CopyReportTemplateDialog)
Vue.component('DeleteReportTemplateDialog', DeleteReportTemplateDialog)
Vue.component('UpdateReportTemplateDialog', UpdateReportTemplateDialog)

let CommandTypes = {
  CREATE_COPY_REPORT_TEMPLATE_CMD: {
    type: 'CreateAndCopyReportTemplateDialog',
    executeComponent: 'CreateAndCopyReportTemplateDialog',
    registerComponent: CreateAndCopyReportTemplateDialog
  },
  COPY_REPORT_TEMPLATE_CMD: {
    type: 'CopyReportTemplateDialog',
    executeComponent: 'CopyReportTemplateDialog',
    registerComponent: CopyReportTemplateDialog
  },
  DELETE_REPORT_TEMPLATE_CMD: {
    type: 'DeleteReportTemplate',
    executeComponent: 'DeleteReportTemplateDialog',
    registerComponent: DeleteReportTemplateDialog
  },
  UPDATE_REPORT_TEMPLATE_CMD: {
    type: 'UpdateReportTemplateDialog',
    executeComponent: 'UpdateReportTemplateDialog',
    registerComponent: UpdateReportTemplateDialog
  }
}

class ReportTemplateCommands {
  static createAndCopyReportTemplateCommand (title, templatePa, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_REPORT_TEMPLATE_CMD.type),
      visible: true,
      disabled: false,
      target: templatePa,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_REPORT_TEMPLATE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTemplateManagement.createReportTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTemplateAuthorityFilter(command)
  }
  static copyReportTemplateCommand (templatePa, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.COPY_REPORT_TEMPLATE_CMD.type),
      visible: true,
      disabled: false,
      target: templatePa,
      executeComponent: CommandTypes.COPY_REPORT_TEMPLATE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTemplateManagement.copyReportTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTemplateAuthorityFilter(command)
  }
  static updateReportTemplateCommand (templatePa, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_REPORT_TEMPLATE_CMD.type),
      visible: true,
      disabled: false,
      target: templatePa,
      executeComponent: CommandTypes.UPDATE_REPORT_TEMPLATE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTemplateManagement.updateReportTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTemplateAuthorityFilter(command)
  }

  static deleteReportTemplateCommand (template1, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_REPORT_TEMPLATE_CMD.type),
      visible: true,
      disabled: false,
      target: template1,
      executeComponent: CommandTypes.DELETE_REPORT_TEMPLATE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTemplateManagement.deleteReportTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTemplateAuthorityFilter(command)
  }
}

ReportTemplateCommands.CommandTypes = CommandTypes

export default ReportTemplateCommands
