"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const chartEditStore$1 = require("../../../store/modules/chartEditStore/chartEditStore.js");
const editPageEnum = require("../../../enums/editPageEnum.js");
const throttle = require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/throttle.js");
const debounce = require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/debounce.js");
const keymaster = require("../../../../node_modules/.pnpm/keymaster@1.6.2/node_modules/keymaster/keymaster.js");
const utils = require("../../../utils/utils.js");
require("../../../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.js");
require("../../../enums/pageEnum.js");
require("../../../router/index.js");
require("../../../store/modules/designStore/designStore.js");
require("../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.js");
require("../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js");
require("../../../components/GoSkeleton/index.vue.js");
require("../../../components/GoLoading/index.js");
require("../../../settings/designSetting.js");
const chartEditStore = chartEditStore$1.useChartEditStore();
const winCtrlMerge = (e) => `${editPageEnum.WinKeyboard.CTRL}+${e}`;
const winShiftMerge = (e) => `${editPageEnum.WinKeyboard.SHIFT}+${e}`;
const winKeyboardValue = {
  [editPageEnum.MenuEnum.ARROW_UP]: winCtrlMerge("up"),
  [editPageEnum.MenuEnum.ARROW_RIGHT]: winCtrlMerge("right"),
  [editPageEnum.MenuEnum.ARROW_DOWN]: winCtrlMerge("down"),
  [editPageEnum.MenuEnum.ARROW_LEFT]: winCtrlMerge("left"),
  [editPageEnum.MenuEnum.COPY]: winCtrlMerge("c"),
  [editPageEnum.MenuEnum.CUT]: winCtrlMerge("x"),
  [editPageEnum.MenuEnum.PARSE]: winCtrlMerge("v"),
  [editPageEnum.MenuEnum.DELETE]: "delete",
  [editPageEnum.MenuEnum.BACK]: winCtrlMerge("z"),
  [editPageEnum.MenuEnum.FORWORD]: winCtrlMerge(winShiftMerge("z")),
  [editPageEnum.MenuEnum.GROUP]: winCtrlMerge("g"),
  [editPageEnum.MenuEnum.UN_GROUP]: winCtrlMerge(winShiftMerge("g")),
  [editPageEnum.MenuEnum.LOCK]: winCtrlMerge("l"),
  [editPageEnum.MenuEnum.UNLOCK]: winCtrlMerge(winShiftMerge("l")),
  [editPageEnum.MenuEnum.HIDE]: winCtrlMerge("h"),
  [editPageEnum.MenuEnum.SHOW]: winCtrlMerge(winShiftMerge("h"))
};
const macCtrlMerge = (e) => `${editPageEnum.MacKeyboard.CTRL}+${e}`;
const macShiftMerge = (e) => `${editPageEnum.MacKeyboard.SHIFT}+${e}`;
const macKeyboardValue = {
  [editPageEnum.MenuEnum.ARROW_UP]: macCtrlMerge("arrowup"),
  [editPageEnum.MenuEnum.ARROW_RIGHT]: macCtrlMerge("arrowright"),
  [editPageEnum.MenuEnum.ARROW_DOWN]: macCtrlMerge("arrowdown"),
  [editPageEnum.MenuEnum.ARROW_LEFT]: macCtrlMerge("arrowleft"),
  [editPageEnum.MenuEnum.COPY]: macCtrlMerge("c"),
  [editPageEnum.MenuEnum.CUT]: macCtrlMerge("x"),
  [editPageEnum.MenuEnum.PARSE]: macCtrlMerge("v"),
  [editPageEnum.MenuEnum.DELETE]: macCtrlMerge("backspace"),
  [editPageEnum.MenuEnum.BACK]: macCtrlMerge("z"),
  [editPageEnum.MenuEnum.FORWORD]: macCtrlMerge(macShiftMerge("z")),
  [editPageEnum.MenuEnum.GROUP]: macCtrlMerge("g"),
  [editPageEnum.MenuEnum.UN_GROUP]: macCtrlMerge(macShiftMerge("g")),
  [editPageEnum.MenuEnum.LOCK]: macCtrlMerge("l"),
  [editPageEnum.MenuEnum.UNLOCK]: macCtrlMerge(macShiftMerge("l")),
  [editPageEnum.MenuEnum.HIDE]: macCtrlMerge("h"),
  [editPageEnum.MenuEnum.SHOW]: macCtrlMerge(macShiftMerge("h"))
};
const winKeyList = [
  winKeyboardValue.up,
  winKeyboardValue.right,
  winKeyboardValue.down,
  winKeyboardValue.left,
  winKeyboardValue.delete,
  winKeyboardValue.copy,
  winKeyboardValue.cut,
  winKeyboardValue.parse,
  winKeyboardValue.back,
  winKeyboardValue.forward,
  winKeyboardValue.group,
  winKeyboardValue.unGroup,
  winKeyboardValue.lock,
  winKeyboardValue.unLock,
  winKeyboardValue.hide,
  winKeyboardValue.show
];
const macKeyList = [
  macKeyboardValue.up,
  macKeyboardValue.right,
  macKeyboardValue.down,
  macKeyboardValue.left,
  macKeyboardValue.delete,
  macKeyboardValue.copy,
  macKeyboardValue.cut,
  macKeyboardValue.parse,
  macKeyboardValue.back,
  macKeyboardValue.forward,
  macKeyboardValue.group,
  macKeyboardValue.unGroup,
  macKeyboardValue.lock,
  macKeyboardValue.unLock,
  macKeyboardValue.hide,
  macKeyboardValue.show
];
const keyRecordHandle = () => {
  window.$KeyboardActive = {
    ctrl: false,
    space: false
  };
  document.onkeydown = (e) => {
    const { keyCode } = e;
    if (keyCode == 32 && e.target == document.body)
      e.preventDefault();
    if ([17, 32].includes(keyCode) && window.$KeyboardActive) {
      utils.setKeyboardDressShow(e.keyCode);
      switch (keyCode) {
        case 17:
          window.$KeyboardActive.ctrl = true;
          break;
        case 32:
          window.$KeyboardActive.space = true;
          break;
      }
    }
  };
  document.onkeyup = (e) => {
    const { keyCode } = e;
    if (keyCode == 32 && e.target == document.body)
      e.preventDefault();
    if ([17, 32].includes(keyCode) && window.$KeyboardActive) {
      utils.setKeyboardDressShow();
      switch (keyCode) {
        case 17:
          window.$KeyboardActive.ctrl = false;
          break;
        case 32:
          window.$KeyboardActive.space = false;
          break;
      }
    }
  };
};
const useAddKeyboard = () => {
  const throttleTime = 50;
  const switchHandle = (keyboardValue, e) => {
    switch (e) {
      case keyboardValue.up:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setMove(editPageEnum.MenuEnum.ARROW_UP);
          return false;
        }, throttleTime));
        break;
      case keyboardValue.right:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setMove(editPageEnum.MenuEnum.ARROW_RIGHT);
          return false;
        }, throttleTime));
        break;
      case keyboardValue.down:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setMove(editPageEnum.MenuEnum.ARROW_DOWN);
          return false;
        }, throttleTime));
        break;
      case keyboardValue.left:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setMove(editPageEnum.MenuEnum.ARROW_LEFT);
          return false;
        }, throttleTime));
        break;
      case keyboardValue.delete:
        keymaster.default(e, debounce.default(() => {
          chartEditStore.removeComponentList();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.copy:
        keymaster.default(e, debounce.default(() => {
          chartEditStore.setCopy();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.cut:
        keymaster.default(e, debounce.default(() => {
          chartEditStore.setCut();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.parse:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setParse();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.back:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setBack();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.forward:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setForward();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.group:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setGroup();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.unGroup:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setUnGroup();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.lock:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setLock();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.unLock:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setUnLock();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.hide:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setHide();
          return false;
        }, throttleTime));
        break;
      case keyboardValue.show:
        keymaster.default(e, throttle.default(() => {
          chartEditStore.setShow();
          return false;
        }, throttleTime));
        break;
    }
  };
  winKeyList.forEach((key) => {
    switchHandle(winKeyboardValue, key);
  });
  macKeyList.forEach((key) => {
    switchHandle(macKeyboardValue, key);
  });
  keyRecordHandle();
};
exports.macKeyboardValue = macKeyboardValue;
exports.useAddKeyboard = useAddKeyboard;
exports.winKeyboardValue = winKeyboardValue;
