import Vue from 'vue'
import uniqueId from 'lodash'
import {i18n} from "../main";
import AuthorityFilter from '../commands/AuthorityFilter'
import DeletePerformanceDialog from '@/components/DialogComponents/DataSafeDialog/DeletePerformanceDialog'
import DeleteAlarmDialog from '@/components/DialogComponents/DataSafeDialog/DeleteAlarmDialog'

Vue.component('DeletePerformanceDialog', DeletePerformanceDialog)
Vue.component('DeleteAlarmDialog', DeleteAlarmDialog)

let CommandTypes = {
  DELETE_PERFORMANCE_CMD: {
    type: 'DeletePerformance',
    executeComponent: 'DeletePerformanceDialog',
    registerComponent: DeletePerformanceDialog // import对应的对话框组件
  },
  DELETE_ALARM_CMD: {
    type: 'DeleteAlarm',
    executeComponent: 'DeleteAlarmDialog',
    registerComponent: DeleteAlarmDialog
  }
}

class PerformanceDataSafeCommands {
  static deletePerformanceDataCommand (performanceList, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_PERFORMANCE_CMD.type),
      visible: true,
      disabled: false,
      target: performanceList,
      executeComponent: CommandTypes.DELETE_PERFORMANCE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('PerformanceDataSafeCommands.deletePerformance')
    };
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return AuthorityFilter.performanceAuthorityFilter(command)
  }

  static deleteAlarmDataCommand (alarmList, commandContext){
    let command = {
      id: uniqueId(CommandTypes.DELETE_ALARM_CMD.type),
      visible: true,
      disabled: false,
      target: alarmList,
      executeComponent: CommandTypes.DELETE_ALARM_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('PerformanceDataSafeCommands.deleteAlarm')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.performanceAuthorityFilter(command)
  }

}

PerformanceDataSafeCommands.CommandTypes = CommandTypes;

export default PerformanceDataSafeCommands
