import Vue from 'vue'
import uniqueId from 'lodash'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyLocationDialog from "@/components/DialogComponents/LocationConfigurationDialog/CreateAndCopyLocatonCofig.vue"
import DeleteLocationDialog from "@/components/DialogComponents/LocationConfigurationDialog/DeleteLocationConfigDialog.vue";
import UpdateLocationDialog from '@/components/DialogComponents/LocationConfigurationDialog/UpdateLocationConfig.vue'
import ImportLocationDialog from '@/components/DialogComponents/LocationConfigurationDialog/ImportLocationConfigDialog.vue'

Vue.component('CreateAndCopyLocationDialog',CreateAndCopyLocationDialog);
Vue.component('DeleteLocationDialog',DeleteLocationDialog);
Vue.component('UpdateLocationDialog',UpdateLocationDialog);
Vue.component('ImportLocationDialog',ImportLocationDialog);

let CommandTypes = {
  CREATE_COPY_LOCATION_CMD: {
    type: 'CreateAndCopyLocation',
    executeComponent: 'CreateAndCopyLocationDialog',
    registerComponent: CreateAndCopyLocationDialog
  },
  DELETE_LOCATION_CMD: {
    type: 'DeleteLocation',
    executeComponent: 'DeleteLocationDialog',
    registerComponent: DeleteLocationDialog // import对应的对话框组件
  },
  UPDATE_LOCATION_CMD: {
    type: 'UpdateLocation',
    executeComponent: 'UpdateLocationDialog',
    registerComponent: UpdateLocationDialog // import对应的对话框组件
  },
  IMPORT_LOCATION_CMD: {
    type: 'ImportLocationToExcel',
    executeComponent: 'ImportLocationDialog',
    registerComponent: ImportLocationDialog // import对应的对话框组件
  },
};

class LocationCommands {
  static createAndCopyLocationCommand (title, location, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_LOCATION_CMD.type),
      visible: true,
      disabled: false,
      target: location,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_LOCATION_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.locationsAuthorityFilter(command)
  }

  static deleteLocationCommand (location, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_LOCATION_CMD.type),
      visible: true,
      disabled: false,
      target: location,
      executeComponent: CommandTypes.DELETE_LOCATION_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.locationsAuthorityFilter(command)
  }

  static updateLocationCommand (location, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_LOCATION_CMD.type),
      visible: true,
      disabled: false,
      target: location,
      executeComponent: CommandTypes.UPDATE_LOCATION_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.locationsAuthorityFilter(command)
  }

  static importLocationCommand (commandContext) {
    let command = {
      id: uniqueId(CommandTypes.IMPORT_LOCATION_CMD.type),
      visible: true,
      disabled: false,
      target: null,
      executeComponent: CommandTypes.IMPORT_LOCATION_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.locationsAuthorityFilter(command)
  }
}

LocationCommands.CommandTypes = CommandTypes;

export default LocationCommands
