import Vue from 'vue'
import uniqueId from 'lodash'
import {i18n} from '../main'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyCollTaskDialog from '@/components/DialogComponents/CollectTaskDialog/CreateAndCopyCollTaskDialog.vue'
import DeleteCollTaskDialog from '@/components/DialogComponents/CollectTaskDialog/DeleteCollTaskDialog.vue'
import UpdateCollTaskDialog from '@/components/DialogComponents/CollectTaskDialog/UpdateCollTaskDialog.vue'
import DetailCollTaskDialog from '@/components/DialogComponents/CollectTaskDialog/DetailCollTaskDialog.vue'
import CopyCollTaskDialog from '@/components/DialogComponents/CollectTaskDialog/CopyCollTaskDialog.vue'

Vue.component('CreateAndCopyCollTaskDialog', CreateAndCopyCollTaskDialog)
Vue.component('CopyCollTaskDialog', CopyCollTaskDialog)
Vue.component('DeleteCollTaskDialog', DeleteCollTaskDialog)
Vue.component('UpdateCollTaskDialog', UpdateCollTaskDialog)
Vue.component('DetailCollTaskDialog', DetailCollTaskDialog)

let CommandTypes = {
  CREATE_COPY_COLL_TASK_CMD: {
    type: 'CreateAndCopyCollTaskDialog',
    executeComponent: 'CreateAndCopyCollTaskDialog',
    registerComponent: CreateAndCopyCollTaskDialog
  },
  COPY_COLL_TASK_CMD: {
    type: 'CopyCollTaskDialog',
    executeComponent: 'CopyCollTaskDialog',
    registerComponent: CopyCollTaskDialog
  },
  DELETE_COLL_TASK_CMD: {
    type: 'DeleteCollTaskDialog',
    executeComponent: 'DeleteCollTaskDialog',
    registerComponent: DeleteCollTaskDialog
  },
  UPDATE_COLL_TASK_CMD: {
    type: 'UpdateCollTaskDialog',
    executeComponent: 'UpdateCollTaskDialog',
    registerComponent: UpdateCollTaskDialog
  },
  SHOW_COLL_TASK_CMD: {
    type: 'DetailCollTaskDialog',
    executeComponent: 'DetailCollTaskDialog',
    registerComponent: DetailCollTaskDialog
  },
}

class CollectTaskCommands {
  static createAndCopyCommand (title, colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_COLL_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_COLL_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('CollecTaskCommands.createCollectTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.collectTaskAuthorityFilter(command)
  }

  static copyCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.COPY_COLL_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.COPY_COLL_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('CollecTaskCommands.copyCollectTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.collectTaskAuthorityFilter(command)
  }

  static deleteCollecTaskCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_COLL_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.DELETE_COLL_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('CollecTaskCommands.deleteCollectTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.collectTaskAuthorityFilter(command)
  }

  static updateCollectTaskCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_COLL_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.UPDATE_COLL_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('CollecTaskCommands.updateCollectTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.collectTaskAuthorityFilter(command)
  }
  static showCollectTaskDetailCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.SHOW_COLL_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.SHOW_COLL_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('CollecTaskCommands.viewCollectTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return command
  }
}

CollectTaskCommands.CommandTypes = CommandTypes

export default CollectTaskCommands
