"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js");
const chartEditStore = require("../../../../../store/modules/chartEditStore/chartEditStore.js");
require("../../../../../store/modules/designStore/designStore.js");
require("../../../../../settings/designSetting.js");
require("../../../../../../node_modules/.pnpm/screenfull@6.0.2/node_modules/screenfull/index.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js");
require("../../../../../../node_modules/.pnpm/html2canvas@1.4.1/node_modules/html2canvas/dist/html2canvas.esm.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseClone.js");
const eventEnum = require("../../../../../enums/eventEnum.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("../../../../../../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");
require("../../../../../components/GoLoading/index.js");
require("../../../../../api/axios.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/merge.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/pick.js");
require("../../../../../../node_modules/.pnpm/echarts@5.4.3/node_modules/echarts/index.js");
require("../../../../../store/modules/langStore/langStore.js");
const useChartInteract_hook = require("../../../../../hooks/useChartInteract.hook.js");
const interact = require("./interact.js");
const dayjs_min = require("../../../../../../node_modules/.pnpm/dayjs@1.11.9/node_modules/dayjs/dayjs.min.js");
const quarterOfYear = require("../../../../../../node_modules/.pnpm/dayjs@1.11.9/node_modules/dayjs/plugin/quarterOfYear.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 runtimeDom_esmBundler = require("../../../../../../node_modules/.pnpm/@vue_runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js");
const reactivity_esmBundler = require("../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
const shared_esmBundler = require("../../../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js");
const _sfc_main = /* @__PURE__ */ runtimeCore_esmBundler.defineComponent({
  __name: "index",
  props: {
    chartConfig: {
      type: Object,
      required: true
    }
  },
  setup(__props) {
    const props = __props;
    runtimeDom_esmBundler.useCssVars((_ctx) => ({
      "22ea0f84": reactivity_esmBundler.unref(h) + "px"
    }));
    const { w, h } = reactivity_esmBundler.toRefs(props.chartConfig.attr);
    reactivity_esmBundler.ref();
    const option = reactivity_esmBundler.shallowReactive({
      dataset: props.chartConfig.option.dataset
    });
    const isRange = runtimeCore_esmBundler.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_hook.useChartInteract(
          props.chartConfig,
          chartEditStore.useChartEditStore,
          {
            [interact.ComponentInteractParamsEnum.DATE_START]: dateStart,
            [interact.ComponentInteractParamsEnum.DATE_END]: dateEnd,
            [interact.ComponentInteractParamsEnum.DATE_RANGE]: daterange
          },
          eventEnum.InteractEventOn.CHANGE
        );
      } else {
        useChartInteract_hook.useChartInteract(
          props.chartConfig,
          chartEditStore.useChartEditStore,
          { [interact.ComponentInteractParamsEnum.DATE]: v },
          eventEnum.InteractEventOn.CHANGE
        );
      }
    };
    const getDiffDate = (type, date) => {
      dayjs_min.default.extend(quarterOfYear.default);
      switch (type) {
        case interact.ComponentInteractEventEnum.DATE:
        case interact.ComponentInteractEventEnum.DATE_RANGE:
          date = date.startOf("day");
          break;
        case interact.ComponentInteractEventEnum.MONTH:
        case interact.ComponentInteractEventEnum.MONTH_RANGE:
          date = date.startOf("month");
          break;
        case interact.ComponentInteractEventEnum.YEAR:
        case interact.ComponentInteractEventEnum.YEAR_RANGE:
          date = date.startOf("year");
          break;
        case interact.ComponentInteractEventEnum.QUARTER:
        case interact.ComponentInteractEventEnum.QUARTER_RANGE:
          date = date.startOf("quarter");
          break;
      }
      return date;
    };
    runtimeCore_esmBundler.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 === interact.DefaultTypeEnum.NONE) {
            props.chartConfig.option.dataset = null;
          } else if (newData.defaultType === interact.DefaultTypeEnum.DYNAMIC) {
            let date = dayjs_min.default();
            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 = runtimeCore_esmBundler.resolveComponent("n-date-picker");
      return runtimeCore_esmBundler.openBlock(), runtimeCore_esmBundler.createBlock(_component_n_date_picker, {
        value: reactivity_esmBundler.unref(option).dataset,
        "onUpdate:value": [
          _cache[0] || (_cache[0] = ($event) => reactivity_esmBundler.unref(option).dataset = $event),
          onChange
        ],
        clearable: "",
        panel: !!__props.chartConfig.option.isPanel,
        type: __props.chartConfig.option.componentInteractEventKey,
        style: shared_esmBundler.normalizeStyle(`width:${reactivity_esmBundler.unref(w)}px;`)
      }, null, 8, ["value", "panel", "type", "style"]);
    };
  }
});
exports.default = _sfc_main;
