"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js");
const chartEditStore$1 = require("../../../store/modules/chartEditStore/chartEditStore.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");
const plugin = require("../../../utils/plugin.js");
require("../../../components/GoLoading/index.js");
require("../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.js");
require("../../../components/GoSkeleton/index.vue.js");
const icon = require("../../../plugins/icon.js");
const editPageEnum = require("../../../enums/editPageEnum.js");
const cloneDeep = require("../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/cloneDeep.js");
const reactivity_esmBundler = require("../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
const runtimeCore_esmBundler = require("../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js");
const {
  CopyIcon,
  CutIcon,
  ClipboardOutlineIcon,
  TrashIcon,
  ChevronDownIcon,
  ChevronUpIcon,
  LockOpenOutlineIcon,
  LockClosedOutlineIcon,
  EyeOutlineIcon,
  EyeOffOutlineIcon
} = icon.icon.ionicons5;
const { UpToTopIcon, DownToBottomIcon, PaintBrushIcon, Carbon3DSoftwareIcon, Carbon3DCursorIcon } = icon.icon.carbon;
const chartEditStore = chartEditStore$1.useChartEditStore();
const divider = (n = 3) => {
  return {
    type: "divider",
    key: `d${n}`
  };
};
const defaultOptions = [
  {
    label: "锁定",
    key: editPageEnum.MenuEnum.LOCK,
    icon: utils.renderIcon(LockClosedOutlineIcon),
    fnHandle: chartEditStore.setLock
  },
  {
    label: "解锁",
    key: editPageEnum.MenuEnum.UNLOCK,
    icon: utils.renderIcon(LockOpenOutlineIcon),
    fnHandle: chartEditStore.setUnLock
  },
  {
    label: "隐藏",
    key: editPageEnum.MenuEnum.HIDE,
    icon: utils.renderIcon(EyeOffOutlineIcon),
    fnHandle: chartEditStore.setHide
  },
  {
    label: "显示",
    key: editPageEnum.MenuEnum.SHOW,
    icon: utils.renderIcon(EyeOutlineIcon),
    fnHandle: chartEditStore.setShow
  },
  {
    type: "divider",
    key: "d0"
  },
  {
    label: "复制",
    key: editPageEnum.MenuEnum.COPY,
    icon: utils.renderIcon(CopyIcon),
    fnHandle: chartEditStore.setCopy
  },
  {
    label: "剪切",
    key: editPageEnum.MenuEnum.CUT,
    icon: utils.renderIcon(CutIcon),
    fnHandle: chartEditStore.setCut
  },
  {
    label: "粘贴",
    key: editPageEnum.MenuEnum.PARSE,
    icon: utils.renderIcon(ClipboardOutlineIcon),
    fnHandle: chartEditStore.setParse
  },
  {
    type: "divider",
    key: "d1"
  },
  {
    label: "置顶",
    key: editPageEnum.MenuEnum.TOP,
    icon: utils.renderIcon(UpToTopIcon),
    fnHandle: chartEditStore.setTop
  },
  {
    label: "置底",
    key: editPageEnum.MenuEnum.BOTTOM,
    icon: utils.renderIcon(DownToBottomIcon),
    fnHandle: chartEditStore.setBottom
  },
  {
    label: "上移",
    key: editPageEnum.MenuEnum.UP,
    icon: utils.renderIcon(ChevronUpIcon),
    fnHandle: chartEditStore.setUp
  },
  {
    label: "下移",
    key: editPageEnum.MenuEnum.DOWN,
    icon: utils.renderIcon(ChevronDownIcon),
    fnHandle: chartEditStore.setDown
  },
  {
    type: "divider",
    key: "d2"
  },
  {
    label: "清空剪贴板",
    key: editPageEnum.MenuEnum.CLEAR,
    icon: utils.renderIcon(PaintBrushIcon),
    fnHandle: chartEditStore.setRecordChart
  },
  {
    label: "删除",
    key: editPageEnum.MenuEnum.DELETE,
    icon: utils.renderIcon(TrashIcon),
    fnHandle: chartEditStore.removeComponentList
  }
];
const defaultMultiSelectOptions = [
  {
    label: "创建分组",
    key: editPageEnum.MenuEnum.GROUP,
    icon: utils.renderIcon(Carbon3DSoftwareIcon),
    fnHandle: chartEditStore.setGroup
  },
  {
    label: "解除分组",
    key: editPageEnum.MenuEnum.UN_GROUP,
    icon: utils.renderIcon(Carbon3DCursorIcon),
    fnHandle: chartEditStore.setUnGroup
  }
];
const defaultNoItemKeys = [editPageEnum.MenuEnum.PARSE, editPageEnum.MenuEnum.CLEAR];
const pickOption = (options, pickList) => {
  if (!pickList)
    return options;
  const list = [];
  pickList.forEach((e) => {
    list.push(...options.filter((op) => op.key === e));
  });
  return list;
};
const hideOption = (options, hideList) => {
  if (!hideList)
    return options;
  return options.filter((op) => {
    return hideList.findIndex((e) => e !== op.key) !== -1;
  });
};
const menuOptions = reactivity_esmBundler.ref([]);
const handleContextMenu = (e, targetInstance, optionsHandle, hideOptionsList, pickOptionsList) => {
  e.stopPropagation();
  e.preventDefault();
  let target = e.target;
  while (target instanceof SVGElement) {
    target = target.parentNode;
  }
  chartEditStore.setTargetSelectChart(targetInstance && targetInstance.id);
  chartEditStore.setRightMenuShow(false);
  if (chartEditStore.getTargetChart.selectId.length > 1) {
    menuOptions.value = defaultMultiSelectOptions;
  } else {
    menuOptions.value = defaultOptions;
  }
  if (!targetInstance) {
    menuOptions.value = pickOption(reactivity_esmBundler.toRaw(menuOptions.value), defaultNoItemKeys);
  }
  if (hideOptionsList) {
    menuOptions.value = hideOption([...defaultMultiSelectOptions, divider(), ...defaultOptions], hideOptionsList);
  }
  if (pickOptionsList) {
    menuOptions.value = pickOption([...defaultMultiSelectOptions, divider(), ...defaultOptions], pickOptionsList);
  }
  if (optionsHandle) {
    menuOptions.value = optionsHandle(
      cloneDeep.default(reactivity_esmBundler.toRaw(menuOptions.value)),
      [...defaultMultiSelectOptions, ...defaultOptions],
      targetInstance
    );
  }
  runtimeCore_esmBundler.nextTick().then(() => {
    chartEditStore.setMousePosition(e.clientX, e.clientY);
    chartEditStore.setRightMenuShow(true);
  });
};
const useContextMenu = () => {
  menuOptions.value = defaultOptions;
  const onClickOutSide = () => {
    chartEditStore.setRightMenuShow(false);
  };
  const handleMenuSelect = (key) => {
    chartEditStore.setRightMenuShow(false);
    const targetItem = menuOptions.value.filter((e) => e.key === key);
    menuOptions.value.forEach((e) => {
      if (e.key === key) {
        if (e.fnHandle) {
          e.fnHandle();
          return;
        }
        if (!targetItem)
          plugin.loadingError();
      }
    });
  };
  return {
    menuOptions,
    defaultOptions,
    defaultMultiSelectOptions,
    handleContextMenu,
    onClickOutSide,
    handleMenuSelect,
    mousePosition: chartEditStore.getMousePosition
  };
};
exports.defaultMultiSelectOptions = defaultMultiSelectOptions;
exports.defaultOptions = defaultOptions;
exports.divider = divider;
exports.useContextMenu = useContextMenu;
