import Vue from 'vue'
import uniqueId from 'lodash'
import {i18n} from '../main'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/CreateAndCopyReportTaskDialog.vue'
import DeleteReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/DeleteReportTaskDialog.vue'
import UpdateReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/UpdateReportTaskDialog.vue'
import CopyReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/CopyReportTaskDialog.vue'
import DetailCollTaskDialog from '@/components/DialogComponents/CollectTaskDialog/DetailCollTaskDialog.vue'

Vue.component('CreateAndCopyReportTaskDialog', CreateAndCopyReportTaskDialog)
Vue.component('CopyReportTaskDialog', CopyReportTaskDialog)
Vue.component('DeleteReportTaskDialog', DeleteReportTaskDialog)
Vue.component('UpdateReportTaskDialog', UpdateReportTaskDialog)
Vue.component('DetailCollTaskDialog', DetailCollTaskDialog)

let CommandTypes = {
  CREATE_COPY_REPORT_TASK_CMD: {
    type: 'CreateAndCopyReportTaskDialog',
    executeComponent: 'CreateAndCopyReportTaskDialog',
    registerComponent: CreateAndCopyReportTaskDialog
  },
  COPY_REPORT_TASK_CMD: {
    type: 'CopyReportTaskDialog',
    executeComponent: 'CopyReportTaskDialog',
    registerComponent: CopyReportTaskDialog
  },
  DELETE_REPORT_TASK_CMD: {
    type: 'DeleteReportTaskDialog',
    executeComponent: 'DeleteReportTaskDialog',
    registerComponent: DeleteReportTaskDialog
  },
  UPDATE_REPORT_TASK_CMD: {
    type: 'UpdateReportTaskDialog',
    executeComponent: 'UpdateReportTaskDialog',
    registerComponent: UpdateReportTaskDialog
  },
  SHOW_COLL_TASK_CMD: {
    type: 'DetailCollTaskDialog',
    executeComponent: 'DetailCollTaskDialog',
    registerComponent: DetailCollTaskDialog
  }
}

class ReportTaskCommands {
  static createAndCopyCommand (title, colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_REPORT_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_REPORT_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTask.createReportTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTaskAuthorityFilter(command)
  }

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

  static deleteReportTaskCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_REPORT_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.DELETE_REPORT_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTask.createReportTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTaskAuthorityFilter(command)
  }

  static updateReportTaskCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_REPORT_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.UPDATE_REPORT_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTask.createReportTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTaskAuthorityFilter(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
  }
}

ReportTaskCommands.CommandTypes = CommandTypes

export default ReportTaskCommands
