import "../../../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import { ChartFrameEnum } from "../../../../../../../packages/index.d.mjs";
import { RequestDataTypeEnum } from "../../../../../../../enums/httpEnum.mjs";
import "../../../../../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.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 { isArray, toString } from "../../../../../../../utils/type.mjs";
import "../../../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseClone.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 "../../../../../../../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 { TimelineTitleEnum, DataResultEnum } from "../../index.d.mjs";
import ChartDataMonacoEditor from "../ChartDataMonacoEditor/index.vue.mjs";
import { useFile } from "../../hooks/useFile.hooks.mjs";
import { useTargetData } from "../../../hooks/useTargetData.hook.mjs";
import { defineComponent, computed, watch, resolveComponent, openBlock, createBlock, withCtx, withDirectives, createVNode, createElementVNode as createBaseVNode, createElementBlock, Fragment, renderList, createTextVNode, createCommentVNode } from "../../../../../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.mjs";
import { ref, unref, isRef } from "../../../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.mjs";
import { toDisplayString } from "../../../../../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.mjs";
import { vShow } from "../../../../../../../../node_modules/.pnpm/@vue_runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    show: {
      type: Boolean,
      required: false
    },
    ajax: {
      type: Boolean,
      required: true
    }
  },
  setup(__props) {
    const { targetData } = useTargetData();
    const tableTitle = ["字段", "映射", "状态"];
    const { HelpOutlineIcon } = icon.ionicons5;
    const { DocumentAddIcon, DocumentDownloadIcon } = icon.carbon;
    const source = ref();
    const dimensions = ref();
    const dimensionsAndSource = ref();
    const noData = ref(false);
    const { uploadFileListRef, customRequest, beforeUpload, download } = useFile(targetData);
    const filterShow = computed(() => {
      return targetData.value.request.requestDataType !== RequestDataTypeEnum.STATIC;
    });
    const isCharts = computed(() => {
      return targetData.value.chartConfig.chartFrame === ChartFrameEnum.ECHARTS;
    });
    const matchingHandle = (mapping) => {
      let res = DataResultEnum.SUCCESS;
      for (let i = 0; i < source.value.length; i++) {
        if (source.value[i][mapping] === void 0) {
          res = DataResultEnum.FAILURE;
          return res;
        }
      }
      return DataResultEnum.SUCCESS;
    };
    const dimensionsAndSourceHandle = () => {
      try {
        return dimensions.value.map((dimensionsItem, index) => {
          return index === 0 ? {
            // 字段
            field: "通用标识",
            // 映射
            mapping: dimensionsItem,
            // 结果
            result: DataResultEnum.NULL
          } : {
            field: `数据项-${index}`,
            mapping: dimensionsItem,
            result: matchingHandle(dimensionsItem)
          };
        });
      } catch (error) {
        return [];
      }
    };
    watch(
      () => {
        var _a, _b;
        return (_b = (_a = targetData.value) == null ? void 0 : _a.option) == null ? void 0 : _b.dataset;
      },
      (newData) => {
        var _a, _b;
        if (newData && ((_b = (_a = targetData == null ? void 0 : targetData.value) == null ? void 0 : _a.chartConfig) == null ? void 0 : _b.chartFrame) === ChartFrameEnum.ECHARTS) {
          source.value = newData;
          if (isCharts.value) {
            dimensions.value = newData.dimensions;
            dimensionsAndSource.value = dimensionsAndSourceHandle();
          }
        } else if (newData !== void 0 && newData !== null) {
          dimensionsAndSource.value = null;
          source.value = newData;
        } else {
          noData.value = true;
          source.value = "此组件无数据源";
        }
        if (isArray(newData)) {
          dimensionsAndSource.value = null;
        }
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _component_n_badge = resolveComponent("n-badge");
      const _component_n_text = resolveComponent("n-text");
      const _component_n_space = resolveComponent("n-space");
      const _component_n_table = resolveComponent("n-table");
      const _component_n_timeline_item = resolveComponent("n-timeline-item");
      const _component_n_icon = resolveComponent("n-icon");
      const _component_n_button = resolveComponent("n-button");
      const _component_n_upload = resolveComponent("n-upload");
      const _component_n_tooltip = resolveComponent("n-tooltip");
      const _component_n_code = resolveComponent("n-code");
      const _component_n_card = resolveComponent("n-card");
      const _component_n_timeline = resolveComponent("n-timeline");
      return openBlock(), createBlock(_component_n_timeline, { class: "go-chart-configurations-timeline" }, {
        default: withCtx(() => [
          withDirectives(createVNode(_component_n_timeline_item, {
            type: "info",
            title: unref(TimelineTitleEnum).MAPPING
          }, {
            default: withCtx(() => [
              createVNode(_component_n_table, { striped: "" }, {
                default: withCtx(() => [
                  createBaseVNode("thead", null, [
                    createBaseVNode("tr", null, [
                      (openBlock(), createElementBlock(Fragment, null, renderList(tableTitle, (item) => {
                        return createBaseVNode("th", { key: item }, toDisplayString(item), 1);
                      }), 64))
                    ])
                  ]),
                  createBaseVNode("tbody", null, [
                    (openBlock(true), createElementBlock(Fragment, null, renderList(dimensionsAndSource.value, (item, index) => {
                      return openBlock(), createElementBlock("tr", { key: index }, [
                        createBaseVNode("td", null, toDisplayString(item.field), 1),
                        createBaseVNode("td", null, toDisplayString(item.mapping), 1),
                        createBaseVNode("td", null, [
                          item.result === 0 ? (openBlock(), createBlock(_component_n_space, { key: 0 }, {
                            default: withCtx(() => [
                              createVNode(_component_n_badge, {
                                dot: "",
                                type: "success"
                              }),
                              createVNode(_component_n_text, null, {
                                default: withCtx(() => [
                                  createTextVNode("无")
                                ]),
                                _: 1
                              })
                            ]),
                            _: 1
                          })) : (openBlock(), createBlock(_component_n_space, { key: 1 }, {
                            default: withCtx(() => [
                              createVNode(_component_n_badge, {
                                dot: "",
                                type: item.result === 1 ? "success" : "error"
                              }, null, 8, ["type"]),
                              createVNode(_component_n_text, null, {
                                default: withCtx(() => [
                                  createTextVNode("匹配" + toDisplayString(item.result === 1 ? "成功" : "失败"), 1)
                                ]),
                                _: 2
                              }, 1024)
                            ]),
                            _: 2
                          }, 1024))
                        ])
                      ]);
                    }), 128))
                  ])
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["title"]), [
            [vShow, isCharts.value && dimensionsAndSource.value]
          ]),
          withDirectives(createVNode(_component_n_timeline_item, {
            color: "#97846c",
            title: unref(TimelineTitleEnum).FILTER
          }, {
            default: withCtx(() => [
              createVNode(_component_n_space, {
                size: 18,
                vertical: ""
              }, {
                default: withCtx(() => [
                  createVNode(_component_n_text, { depth: "3" }, {
                    default: withCtx(() => [
                      createTextVNode("过滤器默认处理接口返回值的「data」字段")
                    ]),
                    _: 1
                  }),
                  createVNode(unref(ChartDataMonacoEditor))
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["title"]), [
            [vShow, filterShow.value]
          ]),
          createVNode(_component_n_timeline_item, {
            type: "success",
            title: unref(TimelineTitleEnum).CONTENT
          }, {
            default: withCtx(() => [
              createVNode(_component_n_space, { vertical: "" }, {
                default: withCtx(() => [
                  createVNode(_component_n_space, { class: "source-btn-box" }, {
                    default: withCtx(() => [
                      createVNode(_component_n_upload, {
                        "file-list": unref(uploadFileListRef),
                        "onUpdate:fileList": _cache[0] || (_cache[0] = ($event) => isRef(uploadFileListRef) ? uploadFileListRef.value = $event : null),
                        "show-file-list": false,
                        customRequest: unref(customRequest),
                        onBeforeUpload: unref(beforeUpload)
                      }, {
                        default: withCtx(() => [
                          createVNode(_component_n_space, null, {
                            default: withCtx(() => [
                              !__props.ajax ? (openBlock(), createBlock(_component_n_button, {
                                key: 0,
                                class: "sourceBtn-item",
                                disabled: noData.value
                              }, {
                                icon: withCtx(() => [
                                  createVNode(_component_n_icon, null, {
                                    default: withCtx(() => [
                                      createVNode(unref(DocumentAddIcon))
                                    ]),
                                    _: 1
                                  })
                                ]),
                                default: withCtx(() => [
                                  createTextVNode(" 导入（json / txt） ")
                                ]),
                                _: 1
                              }, 8, ["disabled"])) : createCommentVNode("", true)
                            ]),
                            _: 1
                          })
                        ]),
                        _: 1
                      }, 8, ["file-list", "customRequest", "onBeforeUpload"]),
                      createBaseVNode("div", null, [
                        createVNode(_component_n_button, {
                          class: "sourceBtn-item",
                          disabled: noData.value,
                          onClick: unref(download)
                        }, {
                          icon: withCtx(() => [
                            createVNode(_component_n_icon, null, {
                              default: withCtx(() => [
                                createVNode(unref(DocumentDownloadIcon))
                              ]),
                              _: 1
                            })
                          ]),
                          default: withCtx(() => [
                            createTextVNode(" 下载 ")
                          ]),
                          _: 1
                        }, 8, ["disabled", "onClick"]),
                        createVNode(_component_n_tooltip, { trigger: "hover" }, {
                          trigger: withCtx(() => [
                            createVNode(_component_n_icon, {
                              class: "go-ml-1",
                              size: "21",
                              depth: 3
                            }, {
                              default: withCtx(() => [
                                createVNode(unref(HelpOutlineIcon))
                              ]),
                              _: 1
                            })
                          ]),
                          default: withCtx(() => [
                            createVNode(_component_n_text, { depth: "3" }, {
                              default: withCtx(() => [
                                createTextVNode("点击【下载】查看完整数据")
                              ]),
                              _: 1
                            })
                          ]),
                          _: 1
                        })
                      ])
                    ]),
                    _: 1
                  }),
                  createVNode(_component_n_card, { size: "small" }, {
                    default: withCtx(() => [
                      createVNode(_component_n_code, {
                        code: unref(toString)(source.value),
                        language: "json"
                      }, null, 8, ["code"])
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["title"])
        ]),
        _: 1
      });
    };
  }
});
export {
  _sfc_main as default
};
