import { defineComponent, toRefs, ref, watch, resolveComponent, openBlock, createBlock, withCtx, createVNode, createElementVNode, createTextVNode, toDisplayString, unref, useCssVars, computed, watchEffect, onBeforeUnmount, createElementBlock, toRaw } from "vue";
import { ba as RequestContentTypeEnum, _ as _export_sfc, y as useDesignStore, a_ as SettingItemBox, b4 as SettingItem, b0 as SelectHttpTimeNameObj, i as icon, b8 as customizeHttp, bb as newFunctionHandle } from "./index-e2623483.js";
import { R as RequestGlobalConfig, a as RequestTargetConfig } from "./pondIndex.vue_vue_type_style_index_0_scoped_de860d6d_lang-eeb12f97.js";
import { u as useTargetData } from "./useTargetData.hook-2b5299d6.js";
import "./index-dda8e899.js";
import "./EditorWorker-c209331a.js";
import { C as ChartDataMatchingAndShow } from "./index-f740626d.js";
import "./fileTypeEnum-d13b2cef.js";
const _hoisted_1$1 = { class: "go-pr-3" };
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    modelShow: Boolean,
    targetData: Object,
    saveBtnText: String || null
  },
  emits: ["update:modelShow", "sendHandle"],
  setup(__props, { emit }) {
    const props = __props;
    const { chartConfig } = toRefs(props.targetData);
    const { requestContentType } = toRefs(props.targetData.request);
    const modelShowRef = ref(false);
    const requestContentTypeObj = {
      [RequestContentTypeEnum.DEFAULT]: "普通请求",
      [RequestContentTypeEnum.SQL]: "SQL 请求"
    };
    watch(
      () => props.modelShow,
      (newValue) => {
        modelShowRef.value = newValue;
      },
      {
        immediate: true
      }
    );
    const closeAndSendHandle = () => {
      emit("update:modelShow", false);
      emit("sendHandle");
    };
    return (_ctx, _cache) => {
      const _component_n_space = resolveComponent("n-space");
      const _component_n_scrollbar = resolveComponent("n-scrollbar");
      const _component_n_text = resolveComponent("n-text");
      const _component_n_tag = resolveComponent("n-tag");
      const _component_n_button = resolveComponent("n-button");
      const _component_n_card = resolveComponent("n-card");
      const _component_n_modal = resolveComponent("n-modal");
      return openBlock(), createBlock(_component_n_modal, {
        class: "go-chart-data-request",
        show: modelShowRef.value,
        "onUpdate:show": _cache[0] || (_cache[0] = ($event) => modelShowRef.value = $event),
        "mask-closable": false,
        closeOnEsc: false
      }, {
        default: withCtx(() => [
          createVNode(_component_n_card, {
            bordered: false,
            role: "dialog",
            size: "small",
            "aria-modal": "true",
            style: { "width": "1000px", "height": "800px" }
          }, {
            header: withCtx(() => []),
            "header-extra": withCtx(() => []),
            action: withCtx(() => [
              createVNode(_component_n_space, { justify: "space-between" }, {
                default: withCtx(() => [
                  createElementVNode("div", null, [
                    createVNode(_component_n_text, null, {
                      default: withCtx(() => [
                        createTextVNode("「 " + toDisplayString(unref(chartConfig).categoryName) + " 」", 1)
                      ]),
                      _: 1
                    }),
                    createVNode(_component_n_text, null, {
                      default: withCtx(() => [
                        createTextVNode("—— ")
                      ]),
                      _: 1
                    }),
                    createVNode(_component_n_tag, {
                      type: "primary",
                      bordered: false,
                      style: { "border-radius": "5px" }
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(requestContentTypeObj[unref(requestContentType)]), 1)
                      ]),
                      _: 1
                    })
                  ]),
                  createVNode(_component_n_button, {
                    type: "primary",
                    onClick: closeAndSendHandle
                  }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(__props.saveBtnText || "保存 & 发送请求"), 1)
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              })
            ]),
            default: withCtx(() => [
              createVNode(_component_n_scrollbar, { style: { "max-height": "718px" } }, {
                default: withCtx(() => [
                  createElementVNode("div", _hoisted_1$1, [
                    createVNode(_component_n_space, { vertical: "" }, {
                      default: withCtx(() => {
                        var _a;
                        return [
                          createVNode(unref(RequestGlobalConfig)),
                          createVNode(unref(RequestTargetConfig), {
                            "target-data-request": (_a = __props.targetData) == null ? void 0 : _a.request
                          }, null, 8, ["target-data-request"])
                        ];
                      }),
                      _: 1
                    })
                  ])
                ]),
                _: 1
              })
            ]),
            _: 1
          })
        ]),
        _: 1
      }, 8, ["show"]);
    };
  }
});
const ChartDataRequest = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-6ace1718"]]);
const _hoisted_1 = { class: "go-chart-configurations-data-ajax" };
const _hoisted_2 = { class: "go-absolute-center" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    useCssVars((_ctx) => ({
      "272613bc": themeColor.value
    }));
    const { HelpOutlineIcon, FlashIcon, PulseIcon } = icon.ionicons5;
    const { targetData, chartEditStore } = useTargetData();
    const {
      requestOriginUrl,
      requestInterval: GlobalRequestInterval,
      requestIntervalUnit: GlobalRequestIntervalUnit
    } = toRefs(chartEditStore.getRequestGlobalConfig);
    const designStore = useDesignStore();
    const loading = ref(false);
    const requestShow = ref(false);
    const showMatching = ref(false);
    let firstFocus = 0;
    let lastFilter = void 0;
    const requestModelHandle = () => {
      requestShow.value = true;
    };
    const sendHandle = async () => {
      var _a;
      if (!((_a = targetData.value) == null ? void 0 : _a.request))
        return;
      loading.value = true;
      try {
        const res = await customizeHttp(toRaw(targetData.value.request), toRaw(chartEditStore.getRequestGlobalConfig));
        loading.value = false;
        if (res) {
          const { data } = res;
          if (!data && !targetData.value.filter) {
            window["$message"].warning("您的数据不符合默认格式，请配置过滤器！");
            showMatching.value = true;
            return;
          }
          targetData.value.option.dataset = newFunctionHandle(data, res, targetData.value.filter);
          showMatching.value = true;
          return;
        }
        window["$message"].warning("没有拿到返回值，请检查接口！");
      } catch (error) {
        console.error(error);
        loading.value = false;
        window["$message"].warning("数据异常，请检查参数！");
      }
    };
    const themeColor = computed(() => {
      return designStore.getAppTheme;
    });
    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_tag = resolveComponent("n-tag");
      const _component_n_input = resolveComponent("n-input");
      const _component_n_icon = resolveComponent("n-icon");
      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("div", _hoisted_1, [
        createVNode(_component_n_card, { class: "n-card-shallow" }, {
          default: withCtx(() => [
            createVNode(unref(SettingItemBox), { name: "请求配置" }, {
              default: withCtx(() => [
                createVNode(unref(SettingItem), { name: "类型" }, {
                  default: withCtx(() => [
                    createVNode(_component_n_tag, {
                      bordered: false,
                      type: "primary",
                      style: { "border-radius": "5px" }
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(unref(targetData).request.requestContentType === unref(RequestContentTypeEnum).DEFAULT ? "普通请求" : "SQL请求"), 1)
                      ]),
                      _: 1
                    })
                  ]),
                  _: 1
                }),
                createVNode(unref(SettingItem), { name: "方式" }, {
                  default: withCtx(() => [
                    createVNode(_component_n_input, {
                      size: "small",
                      placeholder: unref(targetData).request.requestHttpType || "暂无",
                      disabled: true
                    }, null, 8, ["placeholder"])
                  ]),
                  _: 1
                }),
                createVNode(unref(SettingItem), { name: "组件间隔" }, {
                  default: withCtx(() => [
                    createVNode(_component_n_input, {
                      size: "small",
                      placeholder: `${unref(targetData).request.requestInterval || "暂无"}`,
                      disabled: true
                    }, {
                      suffix: withCtx(() => [
                        createTextVNode(toDisplayString(unref(SelectHttpTimeNameObj)[unref(targetData).request.requestIntervalUnit]), 1)
                      ]),
                      _: 1
                    }, 8, ["placeholder"])
                  ]),
                  _: 1
                }),
                createVNode(unref(SettingItem), { name: "全局间隔（默认）" }, {
                  default: withCtx(() => [
                    createVNode(_component_n_input, {
                      size: "small",
                      placeholder: `${unref(GlobalRequestInterval) || "暂无"} `,
                      disabled: true
                    }, {
                      suffix: withCtx(() => [
                        createTextVNode(toDisplayString(unref(SelectHttpTimeNameObj)[unref(GlobalRequestIntervalUnit)]), 1)
                      ]),
                      _: 1
                    }, 8, ["placeholder"])
                  ]),
                  _: 1
                })
              ]),
              _: 1
            }),
            createVNode(unref(SettingItemBox), {
              name: "源地址",
              alone: true
            }, {
              default: withCtx(() => [
                createVNode(_component_n_input, {
                  size: "small",
                  placeholder: unref(requestOriginUrl) || "暂无",
                  disabled: true
                }, {
                  prefix: withCtx(() => [
                    createVNode(_component_n_icon, { component: unref(PulseIcon) }, null, 8, ["component"])
                  ]),
                  _: 1
                }, 8, ["placeholder"])
              ]),
              _: 1
            }),
            createVNode(unref(SettingItemBox), {
              name: "组件地址",
              alone: true
            }, {
              default: withCtx(() => [
                createVNode(_component_n_input, {
                  size: "small",
                  placeholder: unref(targetData).request.requestUrl || "暂无",
                  disabled: true
                }, {
                  prefix: withCtx(() => [
                    createVNode(_component_n_icon, { component: unref(FlashIcon) }, null, 8, ["component"])
                  ]),
                  _: 1
                }, 8, ["placeholder"])
              ]),
              _: 1
            }),
            createElementVNode("div", {
              class: "edit-text",
              onClick: requestModelHandle
            }, [
              createElementVNode("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(ChartDataRequest), {
          modelShow: requestShow.value,
          "onUpdate:modelShow": _cache[0] || (_cache[0] = ($event) => requestShow.value = $event),
          targetData: unref(targetData),
          onSendHandle: sendHandle
        }, null, 8, ["modelShow", "targetData"])
      ]);
    };
  }
});
const index_vue_vue_type_style_index_0_scoped_688badbe_lang = "";
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-688badbe"]]);
export {
  index as default
};
