import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyCabinetDialog from "@/components/DialogComponents/CabinetDialog/CreateAndCopyCabinetDialog.vue"
import DeleteCabinetDialog from "@/components/DialogComponents/CabinetDialog/DeleteCabinetDialog.vue";
import UpdateCabinetDialog from '@/components/DialogComponents/CabinetDialog/UpdateCabinetDialog.vue'
import ImportCabinetDialog from '@/components/DialogComponents/CabinetDialog/ImportCabinetDialog.vue'

Vue.component('CreateAndCopyCabinetDialog',CreateAndCopyCabinetDialog);
Vue.component('DeleteCabinetDialog',DeleteCabinetDialog);
Vue.component('UpdateCabinetDialog',UpdateCabinetDialog);
Vue.component('ImportCabinetDialog',ImportCabinetDialog);

let CommandTypes = {
  CREATE_COPY_CABINET_CMD: {
    type: 'CreateAndCopyCabinet',
    executeComponent: 'CreateAndCopyCabinetDialog',
    registerComponent: CreateAndCopyCabinetDialog
  },
  DELETE_CABINET_CMD: {
    type: 'DeleteCabinet',
    executeComponent: 'DeleteCabinetDialog',
    registerComponent: DeleteCabinetDialog // import对应的对话框组件
  },
  UPDATE_CABINET_CMD: {
    type: 'UpdateCabinet',
    executeComponent: 'UpdateCabinetDialog',
    registerComponent: UpdateCabinetDialog // import对应的对话框组件
  },
  IMPORT_CABINET_CMD: {
    type: 'ImportCabinetToExcel',
    executeComponent: 'ImportCabinetDialog',
    registerComponent: ImportCabinetDialog // import对应的对话框组件
  },
};

class CabinetCommands {
  static createAndCopyCabinetCommand (title, cabinet, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_CABINET_CMD.type),
      visible: true,
      disabled: false,
      target: cabinet,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_CABINET_CMD.executeComponent,
      execute: undefined,
      done: undefined,
    };
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return AuthorityFilter.cabinetAuthorityFilter(command)
  }

  static deleteCabinetCommand (cabinet, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_CABINET_CMD.type),
      visible: true,
      disabled: false,
      target: cabinet,
      executeComponent: CommandTypes.DELETE_CABINET_CMD.executeComponent,
      execute: undefined,
      done: undefined,
    };
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return AuthorityFilter.cabinetAuthorityFilter(command)
  }

  static updateCabinetCommand (cabinet, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_CABINET_CMD.type),
      visible: true,
      disabled: false,
      target: cabinet,
      executeComponent: CommandTypes.UPDATE_CABINET_CMD.executeComponent,
      execute: undefined,
      done: undefined,
    };
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return AuthorityFilter.cabinetAuthorityFilter(command)
  }

  static importCabinetCommand (commandContext) {
    let command = {
      id: uniqueId(CommandTypes.IMPORT_CABINET_CMD.type),
      visible: true,
      disabled: false,
      target: null,
      executeComponent: CommandTypes.IMPORT_CABINET_CMD.executeComponent,
      execute: undefined,
      done: undefined,
    };
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return AuthorityFilter.cabinetAuthorityFilter(command)
  }
}

CabinetCommands.CommandTypes = CommandTypes;

export default CabinetCommands
