import { createVNode as _createVNode, Fragment as _Fragment, mergeProps as _mergeProps } from "vue";
import { arrayType, funcType, stringType, useEffect } from "@antdv/pro-utils";
import { Image, Typography } from "ant-design-vue";
import { computed, defineComponent, ref } from "vue";
import { ProHelpContext } from "./HelpProvide.mjs";
import { SelectKeyContext } from "./ProHelpPanel.mjs";
const HTMLRender = (props) => {
  return _createVNode("div", {
    "class": props.className || "inner-html",
    "innerHTML": props.content
  }, null);
};
HTMLRender.inheritAttrs = false;
const NavigationSwitch = defineComponent({
  name: "NavigationSwitch",
  props: {
    content: stringType().isRequired,
    selectKey: stringType().isRequired
  },
  setup(props, {
    slots
  }) {
    const context = SelectKeyContext.useContext();
    return () => {
      return _createVNode(Typography.Text, null, {
        default: () => [_createVNode("a", {
          "data-testid": "navigation-switch",
          "onClick": () => {
            context.selectedKey = props.selectKey;
          }
        }, [props.content])]
      });
    };
  }
});
const RenderContentPanel = defineComponent({
  name: "RenderContentPanel",
  props: {
    dataSourceChildren: arrayType().isRequired,
    onInit: funcType()
  },
  setup(props) {
    const {
      valueTypeMap
    } = ProHelpContext.useContext();
    const divRef = ref(null);
    useEffect(() => {
      var _a;
      (_a = props.onInit) == null ? void 0 : _a.call(props, divRef.value);
    }, computed(() => [props.dataSourceChildren]));
    return () => {
      var _a;
      const itemRender = (item, index) => {
        var _a2;
        if (valueTypeMap == null ? void 0 : valueTypeMap.has(item.valueType)) {
          return _createVNode(_Fragment, null, [(_a2 = valueTypeMap == null ? void 0 : valueTypeMap.get(item.valueType)) == null ? void 0 : _a2(item, index)]);
        }
        if (item.valueType === "html") {
          return _createVNode(HTMLRender, _mergeProps({
            "key": index
          }, item.valueChildren), null);
        }
        if (item.valueType === "h1") {
          return _createVNode(Typography.Title, {
            "key": index,
            "style": {
              marginTop: 0
            },
            "level": 3
          }, {
            default: () => [item.valueChildren]
          });
        }
        if (item.valueType === "h2") {
          return _createVNode(Typography.Title, {
            "key": index,
            "style": {
              marginTop: `20px`
            },
            "level": 5
          }, {
            default: () => [item.valueChildren]
          });
        }
        if (item.valueType === "image") {
          return _createVNode("div", {
            "key": index,
            "style": {
              marginBlock: `12px`
            }
          }, [_createVNode(Image, item.valueChildren, null)]);
        }
        if (item.valueType === "inlineLink") {
          return _createVNode(Typography.Text, {
            "key": index
          }, {
            default: () => [_createVNode("a", item.valueChildren, null)]
          });
        }
        if (item.valueType === "link") {
          return _createVNode("div", {
            "key": index
          }, [_createVNode(Typography.Text, {
            "key": index
          }, {
            default: () => [_createVNode("a", item.valueChildren, null)]
          })]);
        }
        if (item.valueType === "navigationSwitch") {
          return _createVNode(NavigationSwitch, _mergeProps({
            "key": index
          }, item.valueChildren), null);
        }
        return _createVNode(Typography.Text, {
          "key": index
        }, {
          default: () => [item.valueChildren]
        });
      };
      return _createVNode("div", {
        "ref": divRef
      }, [(_a = props.dataSourceChildren) == null ? void 0 : _a.map(itemRender)]);
    };
  }
});
export {
  RenderContentPanel
};
