import "../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import { useChartEditStore } from "../../../../../store/modules/chartEditStore/chartEditStore.mjs";
import "../../../../../store/modules/designStore/designStore.mjs";
import "../../../../../settings/designSetting.mjs";
import "../../../../../../node_modules/.pnpm/screenfull@6.0.2/node_modules/screenfull/index.mjs";
import "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.mjs";
import "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.mjs";
import "../../../../../../node_modules/.pnpm/html2canvas@1.4.1/node_modules/html2canvas/dist/html2canvas.esm.mjs";
import "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseClone.mjs";
import { InteractEventOn } from "../../../../../enums/eventEnum.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 "../../../../../api/axios.mjs";
import "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/merge.mjs";
import "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/pick.mjs";
import "../../../../../../node_modules/.pnpm/echarts@5.4.3/node_modules/echarts/index.mjs";
import "../../../../../store/modules/langStore/langStore.mjs";
import { useChartInteract } from "../../../../../hooks/useChartInteract.hook.mjs";
import { DefaultTypeEnum, ComponentInteractParamsEnum, ComponentInteractEventEnum } from "./interact.mjs";
import dayjs from "../../../../../../node_modules/.pnpm/dayjs@1.11.9/node_modules/dayjs/dayjs.min.mjs";
import quarterOfYear from "../../../../../../node_modules/.pnpm/dayjs@1.11.9/node_modules/dayjs/plugin/quarterOfYear.mjs";
import { defineComponent, computed, watch, resolveComponent, openBlock, createBlock } 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 { unref, toRefs, ref, shallowReactive } from "../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.mjs";
import { normalizeStyle } from "../../../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    chartConfig: {
      type: Object,
      required: true
    }
  },
  setup(__props) {
    const props = __props;
    useCssVars((_ctx) => ({
      "22ea0f84": unref(h) + "px"
    }));
    const { w, h } = toRefs(props.chartConfig.attr);
    ref();
    const option = shallowReactive({
      dataset: props.chartConfig.option.dataset
    });
    const isRange = computed(() => {
      return props.chartConfig.option.componentInteractEventKey.endsWith("range");
    });
    const onChange = (v) => {
      if (isRange.value) {
        let dateStart = null;
        let dateEnd = null;
        let daterange = null;
        if (v instanceof Array) {
          dateStart = v[0];
          dateEnd = v[1];
          daterange = `${v[0]}-${v[1]}`;
        }
        useChartInteract(
          props.chartConfig,
          useChartEditStore,
          {
            [ComponentInteractParamsEnum.DATE_START]: dateStart,
            [ComponentInteractParamsEnum.DATE_END]: dateEnd,
            [ComponentInteractParamsEnum.DATE_RANGE]: daterange
          },
          InteractEventOn.CHANGE
        );
      } else {
        useChartInteract(
          props.chartConfig,
          useChartEditStore,
          { [ComponentInteractParamsEnum.DATE]: v },
          InteractEventOn.CHANGE
        );
      }
    };
    const getDiffDate = (type, date) => {
      dayjs.extend(quarterOfYear);
      switch (type) {
        case ComponentInteractEventEnum.DATE:
        case ComponentInteractEventEnum.DATE_RANGE:
          date = date.startOf("day");
          break;
        case ComponentInteractEventEnum.MONTH:
        case ComponentInteractEventEnum.MONTH_RANGE:
          date = date.startOf("month");
          break;
        case ComponentInteractEventEnum.YEAR:
        case ComponentInteractEventEnum.YEAR_RANGE:
          date = date.startOf("year");
          break;
        case ComponentInteractEventEnum.QUARTER:
        case ComponentInteractEventEnum.QUARTER_RANGE:
          date = date.startOf("quarter");
          break;
      }
      return date;
    };
    watch(
      () => {
        return {
          type: props.chartConfig.option.componentInteractEventKey,
          defaultType: props.chartConfig.option.defaultType,
          differValue: props.chartConfig.option.differValue,
          differUnit: props.chartConfig.option.differUnit,
          dataset: props.chartConfig.option.dataset
        };
      },
      (newData, oldData) => {
        const hasTypeChanged = newData.type !== (oldData == null ? void 0 : oldData.type);
        const hasDefaultTypeChanged = newData.defaultType !== (oldData == null ? void 0 : oldData.defaultType);
        const hasDifferValueChanged = newData.differValue !== (oldData == null ? void 0 : oldData.differValue);
        const hasDifferUnitChanged = newData.differUnit !== (oldData == null ? void 0 : oldData.differUnit);
        if (hasTypeChanged || hasDefaultTypeChanged || hasDifferValueChanged || hasDifferUnitChanged) {
          if (newData.defaultType === DefaultTypeEnum.NONE) {
            props.chartConfig.option.dataset = null;
          } else if (newData.defaultType === DefaultTypeEnum.DYNAMIC) {
            let date = dayjs();
            if (isRange.value) {
              props.chartConfig.option.dataset = [
                getDiffDate(newData.type, date.add(newData.differValue[0], newData.differUnit[0])).valueOf(),
                getDiffDate(newData.type, date.add(newData.differValue[1], newData.differUnit[1])).valueOf()
              ];
            } else {
              props.chartConfig.option.dataset = getDiffDate(newData.type, date.add(newData.differValue[0], newData.differUnit[0])).valueOf();
            }
          }
        }
        option.dataset = props.chartConfig.option.dataset;
        onChange(option.dataset);
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _component_n_date_picker = resolveComponent("n-date-picker");
      return openBlock(), createBlock(_component_n_date_picker, {
        value: unref(option).dataset,
        "onUpdate:value": [
          _cache[0] || (_cache[0] = ($event) => unref(option).dataset = $event),
          onChange
        ],
        clearable: "",
        panel: !!__props.chartConfig.option.isPanel,
        type: __props.chartConfig.option.componentInteractEventKey,
        style: normalizeStyle(`width:${unref(w)}px;`)
      }, null, 8, ["value", "panel", "type", "style"]);
    };
  }
});
export {
  _sfc_main as default
};
