import "../../../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import SettingItem from "../../../../../../../components/Pages/ChartItemSetting/SettingItem.vue2.mjs";
import SettingItemBox from "../../../../../../../components/Pages/ChartItemSetting/SettingItemBox.vue.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 "../../../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseClone.mjs";
import { RequestParamsTypeEnum, RequestDataTypeEnum } from "../../../../../../../enums/httpEnum.mjs";
import { COMPONENT_INTERACT_EVENT_KET } from "../../../../../../../enums/eventEnum.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 { goDialog } from "../../../../../../../utils/plugin.mjs";
import "../../../../../../../components/GoLoading/index.mjs";
import "../../../../../../../components/GoSkeleton/index.vue.mjs";
import { icon } from "../../../../../../../plugins/icon.mjs";
import "../../../../../../../store/modules/chartEditStore/chartEditStore.mjs";
import { ChartFrameEnum } from "../../../../../../../packages/index.d.mjs";
import "../../../../../../../components/Pages/ChartItemSetting/StylesSetting.vue.mjs";
import noData from "../../../../../../../assets/images/canvas/noData.png.mjs";
import { useTargetData } from "../../../hooks/useTargetData.hook.mjs";
import { withModifiers, vShow } from "../../../../../../../../node_modules/.pnpm/@vue_runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.mjs";
import { defineComponent, computed, resolveComponent, openBlock, createBlock, withCtx, createVNode, createTextVNode, createElementBlock, createElementVNode as createBaseVNode, createCommentVNode, Fragment, renderList, withDirectives } from "../../../../../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.mjs";
import { unref } 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";
const _hoisted_1 = {
  key: 0,
  class: "no-data go-flex-center"
};
const _hoisted_2 = ["src"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const { CloseIcon, AddIcon, HelpOutlineIcon } = icon.ionicons5;
    const { targetData, chartEditStore } = useTargetData();
    const requestParamsTypeList = [RequestParamsTypeEnum.PARAMS, RequestParamsTypeEnum.HEADER];
    const interactActions = computed(() => {
      const interactActions2 = targetData.value.interactActions;
      if (!interactActions2)
        return [];
      return interactActions2.map((value) => ({
        label: value.interactName,
        value: value.interactType
      }));
    });
    const option = computed(() => {
      return targetData.value.option;
    });
    const fnGetRequest = (id, key) => {
      var _a, _b;
      if (!id)
        return {};
      const globalConfigPindApr = (_a = chartEditStore.requestGlobalConfig.requestDataPond.find((item) => {
        return item.dataPondId === id;
      })) == null ? void 0 : _a.dataPondRequestConfig.requestParams;
      if (globalConfigPindApr)
        return globalConfigPindApr[key];
      return (_b = chartEditStore.componentList[chartEditStore.fetchTargetIndex(id)]) == null ? void 0 : _b.request.requestParams[key];
    };
    const fnDimensionsAndSource = (interactOn) => {
      if (!interactOn || !targetData.value.interactActions)
        return [];
      const tableData = targetData.value.interactActions.find((item) => {
        return item.interactType === interactOn;
      });
      return (tableData == null ? void 0 : tableData.componentEmitEvents[option.value[COMPONENT_INTERACT_EVENT_KET]]) || [];
    };
    const fnEventsOptions = () => {
      var _a;
      const fnFlattern = (data) => {
        return data.reduce(
          (iter, val) => {
            if (!val.groupList && val.request.requestDataType === RequestDataTypeEnum.AJAX && val.request.requestUrl) {
              iter.push(val);
            }
            return val.groupList && val.groupList.length > 0 ? [...iter, ...fnFlattern(val.groupList)] : iter;
          },
          []
        );
      };
      const filterOptionList = fnFlattern(chartEditStore.componentList).filter((item) => {
        const isNotSelf = item.id !== targetData.value.id;
        const isNotStatic = item.chartConfig.chartFrame !== ChartFrameEnum.STATIC;
        const isNotGroup = !item.isGroup;
        return isNotSelf && isNotStatic && isNotGroup;
      });
      const mapOptionList = filterOptionList.map((item) => ({
        id: item.id,
        title: item.chartConfig.title,
        disabled: false,
        type: "componentList"
      }));
      const requestDataPond = chartEditStore.requestGlobalConfig.requestDataPond.map((item) => ({
        id: item.dataPondId,
        title: item.dataPondName,
        disabled: false,
        type: "requestDataPond"
      }));
      const tarArr = requestDataPond.concat(mapOptionList);
      (_a = targetData.value.events.interactEvents) == null ? void 0 : _a.forEach((iaItem) => {
        tarArr.forEach((optionItem) => {
          if (optionItem.id === iaItem.interactComponentId) {
            optionItem.disabled = true;
          }
        });
      });
      return tarArr;
    };
    const evAddEventsFn = () => {
      targetData.value.events.interactEvents.push({
        interactOn: void 0,
        interactComponentId: void 0,
        interactFn: {}
      });
    };
    const evDeleteEventsFn = (index) => {
      goDialog({
        message: "是否删除此关联交互模块?",
        onPositiveCallback: () => {
          targetData.value.events.interactEvents.splice(index, 1);
        }
      });
    };
    return (_ctx, _cache) => {
      const _component_n_icon = resolveComponent("n-icon");
      const _component_n_button = resolveComponent("n-button");
      const _component_n_text = resolveComponent("n-text");
      const _component_n_space = resolveComponent("n-space");
      const _component_n_divider = resolveComponent("n-divider");
      const _component_n_tag = resolveComponent("n-tag");
      const _component_n_select = resolveComponent("n-select");
      const _component_n_input_group = resolveComponent("n-input-group");
      const _component_n_tooltip = resolveComponent("n-tooltip");
      const _component_n_table = resolveComponent("n-table");
      const _component_n_card = resolveComponent("n-card");
      const _component_n_collapse_item = resolveComponent("n-collapse-item");
      return interactActions.value.length ? (openBlock(), createBlock(_component_n_collapse_item, {
        key: 0,
        title: "组件交互",
        name: "1"
      }, {
        "header-extra": withCtx(() => [
          createVNode(_component_n_button, {
            type: "primary",
            tertiary: "",
            size: "small",
            onClick: withModifiers(evAddEventsFn, ["stop"])
          }, {
            icon: withCtx(() => [
              createVNode(_component_n_icon, null, {
                default: withCtx(() => [
                  createVNode(unref(AddIcon))
                ]),
                _: 1
              })
            ]),
            default: withCtx(() => [
              createTextVNode(" 新增 ")
            ]),
            _: 1
          }, 8, ["onClick"])
        ]),
        default: withCtx(() => [
          !unref(targetData).events.interactEvents.length ? (openBlock(), createElementBlock("div", _hoisted_1, [
            createBaseVNode("img", {
              src: unref(noData),
              alt: "暂无数据"
            }, null, 8, _hoisted_2),
            createVNode(_component_n_text, { depth: 3 }, {
              default: withCtx(() => [
                createTextVNode("暂无内容")
              ]),
              _: 1
            })
          ])) : createCommentVNode("", true),
          (openBlock(true), createElementBlock(Fragment, null, renderList(unref(targetData).events.interactEvents, (item, cardIndex) => {
            return openBlock(), createBlock(_component_n_card, {
              key: cardIndex,
              class: "n-card-shallow",
              size: "small"
            }, {
              default: withCtx(() => [
                createVNode(_component_n_space, { justify: "space-between" }, {
                  default: withCtx(() => [
                    createVNode(_component_n_text, null, {
                      default: withCtx(() => [
                        createTextVNode("关联组件 - " + toDisplayString(cardIndex + 1), 1)
                      ]),
                      _: 2
                    }, 1024),
                    createVNode(_component_n_button, {
                      type: "error",
                      text: "",
                      size: "small",
                      onClick: ($event) => evDeleteEventsFn(cardIndex)
                    }, {
                      icon: withCtx(() => [
                        createVNode(_component_n_icon, null, {
                          default: withCtx(() => [
                            createVNode(unref(CloseIcon))
                          ]),
                          _: 1
                        })
                      ]),
                      _: 2
                    }, 1032, ["onClick"])
                  ]),
                  _: 2
                }, 1024),
                createVNode(_component_n_divider, { style: { "margin": "10px 0" } }),
                createVNode(_component_n_tag, {
                  bordered: false,
                  type: "primary"
                }, {
                  default: withCtx(() => [
                    createTextVNode(" 选择目标组件 ")
                  ]),
                  _: 1
                }),
                createVNode(unref(SettingItemBox), {
                  name: "触发事件",
                  alone: true
                }, {
                  default: withCtx(() => [
                    interactActions.value ? (openBlock(), createBlock(_component_n_input_group, { key: 0 }, {
                      default: withCtx(() => [
                        createVNode(_component_n_select, {
                          class: "select-type-options",
                          value: item.interactOn,
                          "onUpdate:value": ($event) => item.interactOn = $event,
                          size: "tiny",
                          options: interactActions.value
                        }, null, 8, ["value", "onUpdate:value", "options"])
                      ]),
                      _: 2
                    }, 1024)) : createCommentVNode("", true)
                  ]),
                  _: 2
                }, 1024),
                createVNode(unref(SettingItemBox), { alone: true }, {
                  name: withCtx(() => [
                    createVNode(_component_n_text, null, {
                      default: withCtx(() => [
                        createTextVNode("绑定")
                      ]),
                      _: 1
                    }),
                    createVNode(_component_n_tooltip, { trigger: "hover" }, {
                      trigger: withCtx(() => [
                        createVNode(_component_n_icon, {
                          size: "21",
                          depth: 3
                        }, {
                          default: withCtx(() => [
                            createVNode(unref(HelpOutlineIcon))
                          ]),
                          _: 1
                        })
                      ]),
                      default: withCtx(() => [
                        createVNode(_component_n_text, null, {
                          default: withCtx(() => [
                            createTextVNode("不支持「静态组件」支持「组件」「公共APi」")
                          ]),
                          _: 1
                        })
                      ]),
                      _: 1
                    })
                  ]),
                  default: withCtx(() => [
                    createVNode(_component_n_select, {
                      class: "select-type-options",
                      "value-field": "id",
                      "label-field": "title",
                      size: "tiny",
                      filterable: "",
                      placeholder: "仅展示符合条件的组件",
                      value: item.interactComponentId,
                      "onUpdate:value": ($event) => item.interactComponentId = $event,
                      options: fnEventsOptions()
                    }, null, 8, ["value", "onUpdate:value", "options"])
                  ]),
                  _: 2
                }, 1024),
                fnDimensionsAndSource(item.interactOn).length ? (openBlock(), createBlock(unref(SettingItemBox), {
                  key: 0,
                  name: "查询结果",
                  alone: true
                }, {
                  default: withCtx(() => [
                    createVNode(_component_n_table, {
                      size: "small",
                      striped: ""
                    }, {
                      default: withCtx(() => [
                        createBaseVNode("thead", null, [
                          createBaseVNode("tr", null, [
                            (openBlock(), createElementBlock(Fragment, null, renderList(["参数", "说明"], (item2) => {
                              return createBaseVNode("th", { key: item2 }, toDisplayString(item2), 1);
                            }), 64))
                          ])
                        ]),
                        createBaseVNode("tbody", null, [
                          (openBlock(true), createElementBlock(Fragment, null, renderList(fnDimensionsAndSource(item.interactOn), (cItem, index) => {
                            return openBlock(), createElementBlock("tr", { key: index }, [
                              createBaseVNode("td", null, toDisplayString(cItem.value), 1),
                              createBaseVNode("td", null, toDisplayString(cItem.label), 1)
                            ]);
                          }), 128))
                        ])
                      ]),
                      _: 2
                    }, 1024)
                  ]),
                  _: 2
                }, 1024)) : createCommentVNode("", true),
                createVNode(_component_n_tag, {
                  bordered: false,
                  type: "primary"
                }, {
                  default: withCtx(() => [
                    createTextVNode(" 关联目标请求参数 ")
                  ]),
                  _: 1
                }),
                (openBlock(), createElementBlock(Fragment, null, renderList(requestParamsTypeList, (requestParamsItem) => {
                  return createVNode(unref(SettingItemBox), {
                    name: requestParamsItem,
                    key: requestParamsItem
                  }, {
                    default: withCtx(() => [
                      (openBlock(true), createElementBlock(Fragment, null, renderList(fnGetRequest(item.interactComponentId, requestParamsItem), (ovlValue, ovlKey, index) => {
                        return openBlock(), createBlock(unref(SettingItem), {
                          key: index,
                          name: `${ovlKey}`
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_n_select, {
                              size: "tiny",
                              value: item.interactFn[ovlKey],
                              "onUpdate:value": ($event) => item.interactFn[ovlKey] = $event,
                              options: fnDimensionsAndSource(item.interactOn),
                              clearable: ""
                            }, null, 8, ["value", "onUpdate:value", "options"])
                          ]),
                          _: 2
                        }, 1032, ["name"]);
                      }), 128)),
                      withDirectives(createVNode(_component_n_text, {
                        class: "go-pt-1",
                        depth: "3"
                      }, {
                        default: withCtx(() => [
                          createTextVNode(" 暂无数据 ")
                        ]),
                        _: 2
                      }, 1536), [
                        [vShow, JSON.stringify(fnGetRequest(item.interactComponentId, requestParamsItem)) === "{}"]
                      ])
                    ]),
                    _: 2
                  }, 1032, ["name"]);
                }), 64))
              ]),
              _: 2
            }, 1024);
          }), 128))
        ]),
        _: 1
      })) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
