"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 http = require("../api/http.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("../components/GoSkeleton/index.vue.js");
require("../components/GoLoading/index.js");
require("../settings/designSetting.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 reactivity_esmBundler = require("../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
const mittDataPondMap = /* @__PURE__ */ new Map();
const newPondItemInterval = (requestGlobalConfig, requestDataPondItem, dataPondMapItem) => {
  if (!dataPondMapItem)
    return;
  let fetchInterval = 0;
  clearInterval(fetchInterval);
  const fetchFn = async () => {
    try {
      const res = await http.customizeHttp(reactivity_esmBundler.toRaw(requestDataPondItem.value.dataPondRequestConfig), reactivity_esmBundler.toRaw(requestGlobalConfig));
      if (res) {
        try {
          dataPondMapItem.forEach((item) => {
            item.updateCallback(utils.newFunctionHandle(res == null ? void 0 : res.data, res, item.filter));
          });
        } catch (error) {
          console.error(error);
          return error;
        }
      }
    } catch (error) {
      return error;
    }
  };
  runtimeCore_esmBundler.watch(
    () => requestDataPondItem.value.dataPondRequestConfig.requestParams.Params,
    () => {
      fetchFn();
    },
    {
      immediate: false,
      deep: true
    }
  );
  fetchFn();
  const targetInterval = requestDataPondItem.value.dataPondRequestConfig.requestInterval;
  const targetUnit = requestDataPondItem.value.dataPondRequestConfig.requestIntervalUnit;
  const globalRequestInterval = requestGlobalConfig.requestInterval;
  const globalUnit = requestGlobalConfig.requestIntervalUnit;
  const time = targetInterval ? targetInterval : globalRequestInterval;
  const unit = targetInterval ? targetUnit : globalUnit;
  if (time)
    fetchInterval = setInterval(fetchFn, utils.intervalUnitHandle(time, unit));
};
const useChartDataPondFetch = () => {
  const addGlobalDataInterface = (targetComponent, useChartEditStore2, updateCallback) => {
    const chartEditStore = useChartEditStore2();
    chartEditStore.getRequestGlobalConfig;
    const requestDataPondId = targetComponent.request.requestDataPondId;
    const mittPondIdArr = mittDataPondMap.get(requestDataPondId) || [];
    mittPondIdArr.push({
      updateCallback,
      filter: targetComponent.filter
    });
    mittDataPondMap.set(requestDataPondId, mittPondIdArr);
  };
  const clearMittDataPondMap = () => {
    mittDataPondMap.clear();
  };
  const initDataPond = (useChartEditStore2) => {
    const { requestGlobalConfig } = useChartEditStore2();
    const chartEditStore = useChartEditStore2();
    for (let pondKey of mittDataPondMap.keys()) {
      const requestDataPondItem = runtimeCore_esmBundler.computed(() => {
        return requestGlobalConfig.requestDataPond.find((item) => item.dataPondId === pondKey);
      });
      if (requestDataPondItem) {
        newPondItemInterval(chartEditStore.requestGlobalConfig, requestDataPondItem, mittDataPondMap.get(pondKey));
      }
    }
  };
  return {
    addGlobalDataInterface,
    clearMittDataPondMap,
    initDataPond
  };
};
exports.useChartDataPondFetch = useChartDataPondFetch;
