var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  ProHelpPanel: () => ProHelpPanel,
  SelectKeyContext: () => SelectKeyContext,
  propHelpPanelProps: () => propHelpPanelProps
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_icons_vue = require("@ant-design/icons-vue");
var import_pro_provider = require("@antdv/pro-provider");
var import_pro_utils = require("@antdv/pro-utils");
var import_ant_design_vue = require("ant-design-vue");
var import_context = require("ant-design-vue/lib/config-provider/context");
var import_vue2 = require("vue");
var import_HelpProvide = require("./HelpProvide");
var import_ProHelpContentPanel = require("./ProHelpContentPanel");
var import_Search = require("./Search");
var import_style = require("./style");
const SelectKeyContext = (0, import_pro_provider.createContext)((0, import_vue2.reactive)({
  selectedKey: void 0
}));
const propHelpPanelProps = {
  /**
   * 帮助面板的标题
   */
  title: (0, import_pro_utils.stringType)(),
  /**
   * 帮助面板首次打开时的默认选中文档的键名
   */
  defaultSelectedKey: (0, import_pro_utils.stringType)(),
  /**
   * 当前选中的帮助文档的键名。如果提供了这个 prop，那么该组件将是一个受控组件，其状态将由父组件管理。如果未提供，那么该组件将是一个非受控组件，其状态将在组件内部管理。
   */
  selectedKey: (0, import_pro_utils.stringType)(),
  /**
   * 当选中的文档键名发生变化时调用的回调函数。新的键名将作为参数传递给该函数。
   */
  onSelectedKeyChange: (0, import_pro_utils.funcType)(),
  /**
   *控制左侧面板是否能够打开
   */
  showLeftPanel: (0, import_pro_utils.boolType)().def(void 0),
  /**
   * 当左侧面板打开状态发生变化时调用的回调函数。新的打开状态将作为参数传递给该函数。
   */
  onShowLeftPanelChange: (0, import_pro_utils.funcType)(),
  /**
   * 是否显示边框
   */
  bordered: (0, import_pro_utils.boolType)(),
  /**
   * 当帮助面板关闭时调用的回调函数。
   */
  onClose: (0, import_pro_utils.funcType)(),
  /**
   * 帮助面板的高度，可以是数字或字符串类型。
   */
  height: (0, import_pro_utils.oneOfType)([Number, String]),
  /**
   * 帮助面板的页脚
   */
  footer: (0, import_pro_utils.vNodeType)(),
  /**
   * 在一页内加载所有的 children 内容
   */
  infiniteScrollFull: (0, import_pro_utils.boolType)(),
  /**
   * 自定义渲染 extra 部分的内容
   *
   * @param {VueNode} collapsePannelAction - 折叠收起的左侧按钮
   * @param {VueNode} helpSelectAction - 默认的帮助筛选按钮
   * @param {VueNode} closeAction - 关闭操作按钮
   * @returns {VueNode} - 返回自定义渲染的 extra 操作按钮
   *
   */
  extraRender: (0, import_pro_utils.funcType)()
};
const ProHelpPanel = (0, import_vue2.defineComponent)({
  name: "ProHelpPanel",
  inheritAttrs: false,
  props: propHelpPanelProps,
  slots: Object,
  emits: {
    "update:selectedKey": (val) => true,
    "update:showLeftPanel": (val) => true
  },
  setup(props, {
    emit,
    slots
  }) {
    const {
      getPrefixCls
    } = (0, import_context.useConfigContextInject)();
    const className = (0, import_vue2.computed)(() => getPrefixCls("pro-help"));
    const {
      wrapSSR,
      hashId
    } = (0, import_style.useStyle)(className);
    const {
      dataSource
    } = import_HelpProvide.ProHelpContext.useContext();
    const {
      token
    } = import_pro_provider.ProProvider.useContext();
    const selectedKey = (0, import_vue2.ref)(props.selectedKey !== void 0 ? props.selectedKey : props.defaultSelectedKey);
    const showLeftPanel = (0, import_vue2.ref)(props.showLeftPanel !== void 0 ? props.showLeftPanel : true);
    (0, import_vue2.watch)(() => props.selectedKey, () => {
      selectedKey.value = props.selectedKey;
    });
    (0, import_vue2.watch)(() => selectedKey.value, (val) => {
      var _a;
      (_a = props.onSelectedKeyChange) == null ? void 0 : _a.call(props, val);
      emit("update:selectedKey", val);
    });
    const [openKey, setOpenKey] = (0, import_pro_utils.useState)("");
    const dataSourceKeyMap = (0, import_vue2.computed)(() => {
      const map = /* @__PURE__ */ new Map();
      dataSource == null ? void 0 : dataSource.forEach((page) => {
        var _a;
        map.set(page.key, page);
        (_a = page.children) == null ? void 0 : _a.forEach((item) => {
          map.set(item.key || item.title, __spreadValues({
            parentKey: page.key
          }, item));
        });
      });
      return map;
    });
    const parentKey = (0, import_vue2.computed)(() => {
      var _a;
      return (_a = dataSourceKeyMap.value.get(selectedKey.value)) == null ? void 0 : _a.parentKey;
    });
    return () => {
      var _a;
      const {
        title = "\u5E2E\u52A9\u4E2D\u5FC3",
        bordered = true,
        onClose,
        footer = (_a = slots.footer) == null ? void 0 : _a.call(slots),
        height,
        extraRender
      } = props;
      const defaultExtraActions = {
        collapsePanelAction: (0, import_vue.createVNode)("div", {
          "class": `${className.value}-actions-item ${hashId.value}`.trim()
        }, [(0, import_vue.createVNode)(import_icons_vue.ProfileOutlined, {
          "title": "collapse panel",
          "onClick": () => {
            var _a2;
            const newVal = !showLeftPanel.value;
            showLeftPanel.value = newVal;
            emit("update:showLeftPanel", newVal);
            (_a2 = props.onShowLeftPanelChange) == null ? void 0 : _a2.call(props, newVal);
          }
        }, null)]),
        helpSelectAction: (0, import_vue.createVNode)(import_Search.ProHelpSelect, {
          "iconClassName": `${className.value}-actions-item`,
          "className": `${hashId.value} ${className.value}-actions-input`,
          "value": selectedKey.value,
          "onChange": (value, item) => {
            selectedKey.value = value;
            setOpenKey(item == null ? void 0 : item.dataItemKey);
          }
        }, null),
        closeAction: (0, import_vue.createVNode)("div", {
          "class": `${className.value}-actions-item ${hashId.value}`.trim()
        }, [(0, import_vue.createVNode)(import_icons_vue.CloseOutlined, {
          "title": "close panel",
          "onClick": () => {
            onClose == null ? void 0 : onClose();
          }
        }, null)])
      };
      const extraDomList = () => {
        return (0, import_vue.createVNode)("div", {
          "class": `${className.value}-actions ${hashId.value}`.trim()
        }, [extraRender ? extraRender(defaultExtraActions.collapsePanelAction, defaultExtraActions.helpSelectAction, defaultExtraActions.closeAction) : (0, import_vue.createVNode)(import_vue.Fragment, null, [defaultExtraActions.collapsePanelAction, defaultExtraActions.helpSelectAction, onClose ? defaultExtraActions.closeAction : null])]);
      };
      return wrapSSR((0, import_vue.createVNode)(SelectKeyContext.Provider, {
        "value": {
          selectedKey: selectedKey.value
        }
      }, {
        default: () => [(0, import_vue.createVNode)(import_ant_design_vue.Card, {
          "bordered": bordered,
          "title": title,
          "bodyStyle": {
            display: "flex",
            padding: 0,
            margin: 0,
            height: "100%",
            width: "100%"
          },
          "size": "small",
          "extra": extraDomList()
        }, {
          default: () => {
            var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
            return [showLeftPanel.value ? (0, import_vue.createVNode)("div", {
              "class": `${hashId.value} ${className.value}-left-panel `,
              "style": {
                height: (0, import_pro_utils.isNumeric)(height) ? `${height}px` : height
              }
            }, [(0, import_vue.createVNode)(import_ant_design_vue.ConfigProvider, {
              "theme": {
                hashed: (0, import_pro_provider.isNeedOpenHash)(),
                token: {
                  lineHeight: 1.2,
                  fontSize: 12,
                  controlHeightLG: 26
                },
                components: {
                  Menu: {
                    radiusItem: token == null ? void 0 : token.borderRadius,
                    colorActiveBarWidth: 0,
                    colorActiveBarBorderSize: 0,
                    colorItemBgSelected: ((_b = (_a2 = token == null ? void 0 : token.layout) == null ? void 0 : _a2.sider) == null ? void 0 : _b.colorBgMenuItemSelected) || "rgba(0, 0, 0, 0.04)",
                    colorItemBgActive: ((_d = (_c = token == null ? void 0 : token.layout) == null ? void 0 : _c.sider) == null ? void 0 : _d.colorBgMenuItemHover) || "rgba(0, 0, 0, 0.04)",
                    colorItemText: ((_f = (_e = token == null ? void 0 : token.layout) == null ? void 0 : _e.sider) == null ? void 0 : _f.colorTextMenu) || "rgba(0, 0, 0, 0.65)",
                    colorItemTextHover: ((_h = (_g = token == null ? void 0 : token.layout) == null ? void 0 : _g.sider) == null ? void 0 : _h.colorTextMenuActive) || "rgba(0, 0, 0, 0.85)",
                    colorItemTextSelected: ((_j = (_i = token == null ? void 0 : token.layout) == null ? void 0 : _i.sider) == null ? void 0 : _j.colorTextMenuSelected) || "rgba(0, 0, 0, 1)",
                    colorItemBg: "transparent",
                    colorSubItemBg: "transparent",
                    // @ts-expect-error
                    popupBg: token == null ? void 0 : token.colorBgElevated,
                    darkPopupBg: token == null ? void 0 : token.colorBgElevated
                  }
                }
              }
            }, {
              default: () => [(0, import_vue.createVNode)(import_ant_design_vue.Menu, {
                "class": `${hashId.value} ${className.value}-left-panel-menu`,
                "openKeys": [parentKey.value, openKey.value],
                "onOpenChange": (keys) => {
                  setOpenKey(keys.at(-1) || "");
                },
                "selectedKeys": selectedKey.value ? [selectedKey.value] : [],
                "onSelect": ({
                  selectedKeys
                }) => {
                  selectedKey.value = selectedKeys.at(-1) || "";
                },
                "mode": "inline",
                "items": dataSource == null ? void 0 : dataSource.map((item) => {
                  return {
                    key: item.key,
                    label: item.title,
                    children: item.children.map((child) => {
                      return {
                        key: child.key,
                        label: child.title
                      };
                    })
                  };
                })
              }, null)]
            })]) : null, (0, import_vue.createVNode)("div", {
              "class": `${hashId.value} ${className.value}-content-panel`,
              "style": {
                height: (0, import_pro_utils.isNumeric)(height) ? `${height}px` : height
              }
            }, [selectedKey.value ? (0, import_vue.createVNode)(import_ProHelpContentPanel.ProHelpContentPanel, {
              "parentItem": dataSourceKeyMap.value.get(parentKey.value),
              "class": `${className.value}-content-render`,
              "selectedKey": selectedKey.value,
              "onScroll": (key) => {
                selectedKey.value = key;
              }
            }, null) : null, footer ? (0, import_vue.createVNode)("div", {
              "class": `${hashId.value} ${className.value}-footer`
            }, [footer]) : null])];
          }
        })]
      }));
    };
  }
});
