import "../../../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import "../../../../../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.mjs";
import { newFunctionHandle } 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 { useDesignStore } from "../../../../../../../store/modules/designStore/designStore.mjs";
import "../../../../../../../settings/designSetting.mjs";
import "../../../../../../../components/GoLoading/index.mjs";
import "../../../../../../../components/GoSkeleton/index.vue.mjs";
import { icon } from "../../../../../../../plugins/icon.mjs";
import { customizeHttp } from "../../../../../../../api/http.mjs";
import "../../../../../../../components/Pages/ChartItemSetting/SettingItem.vue.mjs";
import SettingItemBox from "../../../../../../../components/Pages/ChartItemSetting/SettingItemBox.vue.mjs";
import "../../../../../../../store/modules/chartEditStore/chartEditStore.mjs";
import "../../../../../../../components/Pages/ChartItemSetting/StylesSetting.vue.mjs";
import ChartDataPondControl from "./components/ChartDataPondControl/index.vue.mjs";
import { useTargetData } from "../../../hooks/useTargetData.hook.mjs";
import ChartDataMatchingAndShow from "../ChartDataMatchingAndShow/index.vue.mjs";
import { defineComponent, computed, watchEffect, onBeforeUnmount, resolveComponent, openBlock, createElementBlock, createElementVNode as createBaseVNode, createVNode, withCtx, createTextVNode, Fragment } 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 { toRefs, ref, unref, toRaw } from "../../../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.mjs";
const _hoisted_1 = { class: "go-chart-data-pond" };
const _hoisted_2 = { class: "go-absolute-center" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    useCssVars((_ctx) => ({
      "5189590e": themeColor.value
    }));
    const designStore = useDesignStore();
    const { HelpOutlineIcon, FlashIcon, PulseIcon, FishIcon } = icon.ionicons5;
    const { targetData, chartEditStore } = useTargetData();
    const {
      requestDataPond,
      requestInterval: GlobalRequestInterval,
      requestIntervalUnit: GlobalRequestIntervalUnit
    } = toRefs(chartEditStore.getRequestGlobalConfig);
    const loading = ref(false);
    const controlModel = ref(false);
    const showMatching = ref(false);
    let firstFocus = 0;
    let lastFilter = void 0;
    const pondData = computed(() => {
      const selectId = targetData.value.request.requestDataPondId;
      if (!selectId)
        return void 0;
      const data = requestDataPond.value.filter((item) => {
        return selectId === item.dataPondId;
      });
      return data[0];
    });
    const themeColor = computed(() => {
      return designStore.getAppTheme;
    });
    const controlModelHandle = () => {
      controlModel.value = true;
    };
    const sendHandle = async () => {
      var _a;
      if (!((_a = targetData.value) == null ? void 0 : _a.request)) {
        window.$message.warning("请选择一个公共接口！");
        return;
      }
      loading.value = true;
      try {
        const res = await customizeHttp(toRaw(targetData.value.request), toRaw(chartEditStore.getRequestGlobalConfig));
        loading.value = false;
        if (res) {
          if (!(res == null ? void 0 : res.data) && !targetData.value.filter) {
            window["$message"].warning("您的数据不符合默认格式，请配置过滤器！");
            showMatching.value = true;
            return;
          }
          targetData.value.option.dataset = newFunctionHandle(res == null ? void 0 : res.data, res, targetData.value.filter);
          showMatching.value = true;
          return;
        }
        window["$message"].warning("没有拿到返回值，请检查接口！");
      } catch (error) {
        console.error(error);
        loading.value = false;
        window["$message"].warning("数据异常，请检查参数！");
      }
    };
    watchEffect(() => {
      var _a;
      const filter = (_a = targetData.value) == null ? void 0 : _a.filter;
      if (lastFilter !== filter && firstFocus) {
        lastFilter = filter;
        sendHandle();
      }
      firstFocus++;
    });
    onBeforeUnmount(() => {
      lastFilter = null;
    });
    return (_ctx, _cache) => {
      const _component_n_icon = resolveComponent("n-icon");
      const _component_n_input = resolveComponent("n-input");
      const _component_n_button = resolveComponent("n-button");
      const _component_n_card = resolveComponent("n-card");
      const _component_n_tooltip = resolveComponent("n-tooltip");
      const _component_go_skeleton = resolveComponent("go-skeleton");
      return openBlock(), createElementBlock(Fragment, null, [
        createBaseVNode("div", _hoisted_1, [
          createVNode(_component_n_card, { class: "n-card-shallow" }, {
            default: withCtx(() => [
              createVNode(unref(SettingItemBox), {
                name: "请求名称",
                alone: true
              }, {
                default: withCtx(() => {
                  var _a;
                  return [
                    createVNode(_component_n_input, {
                      size: "small",
                      placeholder: ((_a = pondData.value) == null ? void 0 : _a.dataPondName) || "暂无",
                      disabled: true
                    }, {
                      prefix: withCtx(() => [
                        createVNode(_component_n_icon, { component: unref(FishIcon) }, null, 8, ["component"])
                      ]),
                      _: 1
                    }, 8, ["placeholder"])
                  ];
                }),
                _: 1
              }),
              createVNode(unref(SettingItemBox), {
                name: "接口地址",
                alone: true
              }, {
                default: withCtx(() => {
                  var _a;
                  return [
                    createVNode(_component_n_input, {
                      size: "small",
                      placeholder: ((_a = pondData.value) == null ? void 0 : _a.dataPondRequestConfig.requestUrl) || "暂无",
                      disabled: true
                    }, {
                      prefix: withCtx(() => [
                        createVNode(_component_n_icon, { component: unref(FlashIcon) }, null, 8, ["component"])
                      ]),
                      _: 1
                    }, 8, ["placeholder"])
                  ];
                }),
                _: 1
              }),
              createBaseVNode("div", {
                class: "edit-text",
                onClick: controlModelHandle
              }, [
                createBaseVNode("div", _hoisted_2, [
                  createVNode(_component_n_button, {
                    type: "primary",
                    secondary: ""
                  }, {
                    default: withCtx(() => [
                      createTextVNode("编辑配置")
                    ]),
                    _: 1
                  })
                ])
              ])
            ]),
            _: 1
          })
        ]),
        createVNode(unref(SettingItemBox), { alone: true }, {
          name: withCtx(() => [
            createTextVNode(" 测试 "),
            createVNode(_component_n_tooltip, { trigger: "hover" }, {
              trigger: withCtx(() => [
                createVNode(_component_n_icon, {
                  size: "21",
                  depth: 3
                }, {
                  default: withCtx(() => [
                    createVNode(unref(HelpOutlineIcon))
                  ]),
                  _: 1
                })
              ]),
              default: withCtx(() => [
                createTextVNode(" 默认赋值给 dataset 字段 ")
              ]),
              _: 1
            })
          ]),
          default: withCtx(() => [
            createVNode(_component_n_button, {
              type: "primary",
              ghost: "",
              onClick: sendHandle
            }, {
              icon: withCtx(() => [
                createVNode(_component_n_icon, null, {
                  default: withCtx(() => [
                    createVNode(unref(FlashIcon))
                  ]),
                  _: 1
                })
              ]),
              default: withCtx(() => [
                createTextVNode(" 发送请求 ")
              ]),
              _: 1
            })
          ]),
          _: 1
        }),
        createVNode(unref(ChartDataMatchingAndShow), {
          show: showMatching.value && !loading.value,
          ajax: true
        }, null, 8, ["show"]),
        createVNode(_component_go_skeleton, {
          load: loading.value,
          repeat: 3
        }, null, 8, ["load"]),
        createVNode(unref(ChartDataPondControl), {
          modelShow: controlModel.value,
          "onUpdate:modelShow": _cache[0] || (_cache[0] = ($event) => controlModel.value = $event),
          onSendHandle: sendHandle
        }, null, 8, ["modelShow"])
      ], 64);
    };
  }
});
export {
  _sfc_main as default
};
