import "../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import { useDesignStore } from "../../../../../store/modules/designStore/designStore.mjs";
import { useChartEditStore } from "../../../../../store/modules/chartEditStore/chartEditStore.mjs";
import { EditCanvasTypeEnum } from "../../../../../store/modules/chartEditStore/chartEditStore.d.mjs";
import { useSettingStore } from "../../../../../store/modules/settingStore/settingStore.mjs";
import { setComponentPosition } from "../../../../../utils/utils.mjs";
import "../../../../../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.mjs";
import "../../../../../enums/pageEnum.mjs";
import "../../../../../router/index.mjs";
import "../../../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.mjs";
import "../../../../../components/GoSkeleton/index.vue.mjs";
import "../../../../../components/GoLoading/index.mjs";
import "../../../../../settings/designSetting.mjs";
import throttle from "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/throttle.mjs";
import cloneDeep from "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/cloneDeep.mjs";
import { defineComponent, computed, watch, openBlock, createElementBlock, Fragment, renderList } from "../../../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.mjs";
import { useCssVars } from "../../../../../../node_modules/.pnpm/@vue_runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.mjs";
import { reactive } from "../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.mjs";
import { normalizeClass, normalizeStyle } from "../../../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.mjs";
const _hoisted_1 = { class: "go-edit-align-line" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    useCssVars((_ctx) => ({
      "2a25621e": themeColor.value
    }));
    const designStore = useDesignStore();
    const chartEditStore = useChartEditStore();
    const settingStore = useSettingStore();
    const line = reactive({
      // 行横向row（上中下），列竖线col（左中右）
      lineArr: ["rowt", "rowc", "rowb", "coll", "colc", "colr"],
      // 展示线
      select: /* @__PURE__ */ new Map(),
      // 已经吸附
      sorptioned: {
        x: false,
        y: false
      }
    });
    const useComponentStyle = (attr) => {
      if (!attr)
        return {};
      const componentStyle = {
        left: `${attr.x ? attr.x : 0}px`,
        top: `${attr.y ? attr.y : 0}px`
      };
      return componentStyle;
    };
    const themeColor = computed(() => {
      return designStore.getAppTheme;
    });
    const minDistance = computed(() => {
      return settingStore.getChartAlignRange;
    });
    const isComputedLine = computed(() => {
      const isDrag = chartEditStore.getEditCanvas[EditCanvasTypeEnum.IS_DRAG];
      return isDrag;
    });
    const isSorption = (selectValue, componentValue) => {
      const isSorption2 = Math.abs(selectValue - componentValue) <= minDistance.value;
      return isSorption2;
    };
    const selectId = computed(() => chartEditStore.getTargetChart.selectId);
    const selectTarget = computed(() => chartEditStore.getComponentList[chartEditStore.fetchTargetIndex()]);
    const selectAttr = computed(() => {
      var _a;
      return ((_a = selectTarget.value) == null ? void 0 : _a.attr) || {};
    });
    const canvasPositionList = computed(() => {
      return {
        id: "0",
        attr: {
          w: cloneDeep(chartEditStore.getEditCanvasConfig.width),
          h: cloneDeep(chartEditStore.getEditCanvasConfig.height),
          x: 0,
          y: 0,
          offsetX: 0,
          offsetY: 0,
          zIndex: 0
        }
      };
    });
    watch(
      () => chartEditStore.getMousePosition,
      throttle(() => {
        try {
          if (!isComputedLine.value || selectId.value.length !== 1)
            return;
          const selectW = selectAttr.value.w;
          const selectH = selectAttr.value.h;
          const selectLeftX = selectAttr.value.x;
          const selectHalfX = selectLeftX + selectW / 2;
          const selectRightX = selectLeftX + selectW;
          const seletX = [selectLeftX, selectHalfX, selectRightX];
          const selectTopY = selectAttr.value.y;
          const selectHalfY = selectTopY + selectH / 2;
          const selectBottomY = selectTopY + selectH;
          const selectY = [selectTopY, selectHalfY, selectBottomY];
          line.select.clear();
          line.sorptioned.y = false;
          const componentList = chartEditStore.getComponentList.map((e) => {
            return {
              id: e.id,
              attr: e.attr
            };
          });
          componentList.push(canvasPositionList.value);
          line.lineArr.forEach((lineItem) => {
            componentList.forEach((component) => {
              if (selectId.value[0] === component.id)
                return;
              const componentW = component.attr.w;
              const componentH = component.attr.h;
              const componentLeftX = component.attr.x;
              const componentHalfX = componentLeftX + componentW / 2;
              const componentRightX = componentLeftX + componentW;
              const componentX = [componentLeftX, componentHalfX, componentRightX];
              const componentTopY = component.attr.y;
              const componentHalfY = componentTopY + componentH / 2;
              const componentBottomY = componentTopY + componentH;
              const componentY = [componentTopY, componentHalfY, componentBottomY];
              if (lineItem.includes("rowt")) {
                if (isSorption(selectTopY, componentTopY)) {
                  line.select.set(lineItem, { y: componentTopY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentTopY);
                }
                if (isSorption(selectTopY, componentHalfY)) {
                  line.select.set(lineItem, { y: componentHalfY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentHalfY);
                }
                if (isSorption(selectTopY, componentBottomY)) {
                  line.select.set(lineItem, { y: componentBottomY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentBottomY);
                }
              }
              if (lineItem.includes("rowc")) {
                if (isSorption(selectHalfY, componentTopY)) {
                  line.select.set(lineItem, { y: componentTopY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentTopY - selectH / 2);
                }
                if (isSorption(selectHalfY, componentHalfY)) {
                  line.select.set(lineItem, { y: componentHalfY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentHalfY - selectH / 2);
                }
                if (isSorption(selectHalfY, componentBottomY)) {
                  line.select.set(lineItem, { y: componentBottomY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentBottomY - selectH / 2);
                }
              }
              if (lineItem.includes("rowb")) {
                if (isSorption(selectBottomY, componentTopY)) {
                  line.select.set(lineItem, { y: componentTopY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentTopY - selectH);
                }
                if (isSorption(selectBottomY, componentHalfY)) {
                  line.select.set(lineItem, { y: componentHalfY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentHalfY - selectH);
                }
                if (isSorption(selectBottomY, componentBottomY)) {
                  line.select.set(lineItem, { y: componentBottomY });
                  setComponentPosition(selectTarget.value, selectLeftX, componentBottomY - selectH);
                }
              }
              if (lineItem.includes("coll")) {
                if (isSorption(selectLeftX, componentLeftX)) {
                  line.select.set(lineItem, { x: componentLeftX });
                  setComponentPosition(selectTarget.value, componentLeftX, selectTopY);
                }
                if (isSorption(selectLeftX, componentHalfX)) {
                  line.select.set(lineItem, { x: componentHalfX });
                  setComponentPosition(selectTarget.value, componentHalfX, selectTopY);
                }
                if (isSorption(selectLeftX, componentRightX)) {
                  line.select.set(lineItem, { x: componentRightX });
                  setComponentPosition(selectTarget.value, componentRightX, selectTopY);
                }
              }
              if (lineItem.includes("colc")) {
                if (isSorption(selectHalfX, componentLeftX)) {
                  line.select.set(lineItem, { x: componentLeftX });
                  setComponentPosition(selectTarget.value, componentLeftX - selectW / 2, selectTopY);
                }
                if (isSorption(selectHalfX, componentHalfX)) {
                  line.select.set(lineItem, { x: componentHalfX });
                  setComponentPosition(selectTarget.value, componentHalfX - selectW / 2, selectTopY);
                }
                if (isSorption(selectHalfX, componentRightX)) {
                  line.select.set(lineItem, { x: componentRightX });
                  setComponentPosition(selectTarget.value, componentRightX - selectW / 2, selectTopY);
                }
              }
              if (lineItem.includes("colr")) {
                if (isSorption(selectRightX, componentLeftX)) {
                  line.select.set(lineItem, { x: componentLeftX });
                  setComponentPosition(selectTarget.value, componentLeftX - selectW, selectTopY);
                }
                if (isSorption(selectRightX, componentHalfX)) {
                  line.select.set(lineItem, { x: componentHalfX });
                  setComponentPosition(selectTarget.value, componentHalfX - selectW, selectTopY);
                }
                if (isSorption(selectRightX, componentRightX)) {
                  line.select.set(lineItem, { x: componentRightX });
                  setComponentPosition(selectTarget.value, componentRightX - selectW, selectTopY);
                }
              }
            });
          });
        } catch (err) {
          console.log(err);
        }
      }, 200),
      {
        deep: true
      }
    );
    watch(
      () => isComputedLine.value,
      (val) => {
        if (!val) {
          line.select.clear();
          line.sorptioned.y = false;
        }
      }
    );
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        (openBlock(true), createElementBlock(Fragment, null, renderList(line.lineArr, (item) => {
          return openBlock(), createElementBlock("div", {
            class: normalizeClass(["line", [item.includes("row") ? "row" : "col", line["select"].has(item) && "visible"]]),
            key: item,
            style: normalizeStyle(useComponentStyle(line["select"].get(item)))
          }, null, 6);
        }), 128))
      ]);
    };
  }
});
export {
  _sfc_main as default
};
