var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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, {
  AppsLogoComponents: () => AppsLogoComponents,
  appsLogoComponentProps: () => appsLogoComponentProps,
  defaultRenderLogo: () => defaultRenderLogo
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_pro_utils = require("@antdv/pro-utils");
var import_ant_design_vue = require("ant-design-vue");
var import_vue2 = require("vue");
var import_AppsLogo = require("./AppsLogo");
var import_DefaultContent = require("./DefaultContent");
var import_SimpleContent = require("./SimpleContent");
var import_style = require("./style/index");
function defaultRenderLogo(logo) {
  if (typeof logo === "string") {
    return (0, import_vue.createVNode)("img", {
      "width": "auto",
      "height": 22,
      "src": logo,
      "alt": "logo"
    }, null);
  }
  if (typeof logo === "function") {
    return logo();
  }
  return logo;
}
const appsLogoComponentProps = {
  appList: (0, import_pro_utils.arrayType)(),
  appListRender: (0, import_pro_utils.funcType)(),
  onItemClick: (0, import_pro_utils.funcType)(),
  prefixCls: String
};
const AppsLogoComponents = (0, import_vue2.defineComponent)({
  name: "AppsLogoComponents",
  props: appsLogoComponentProps,
  inheritAttrs: false,
  setup(props) {
    const divRef = (0, import_vue2.ref)(null);
    const popoverRef = (0, import_vue2.ref)(null);
    const baseClassName = (0, import_vue2.computed)(() => `${props.prefixCls || "ant-pro"}-layout-apps`);
    const {
      wrapSSR,
      hashId
    } = (0, import_style.useStyle)(baseClassName);
    const open = (0, import_vue2.ref)(false);
    return () => {
      var _a;
      const {
        appList,
        appListRender,
        onItemClick: itemClick
      } = props;
      const cloneItemClick = (app) => {
        itemClick == null ? void 0 : itemClick(app, popoverRef);
      };
      const defaultDomContent = () => {
        const isSimple = appList == null ? void 0 : appList.some((app) => {
          return !(app == null ? void 0 : app.desc);
        });
        if (isSimple) {
          return (0, import_vue.createVNode)(import_SimpleContent.SimpleContent, {
            "hashId": hashId.value,
            "appList": appList,
            "itemClick": itemClick ? cloneItemClick : void 0,
            "baseClassName": `${baseClassName.value}-simple`
          }, null);
        }
        return (0, import_vue.createVNode)(import_DefaultContent.DefaultContent, {
          "hashId": hashId.value,
          "appList": appList,
          "itemClick": itemClick ? cloneItemClick : void 0,
          "baseClassName": `${baseClassName.value}-default`
        }, null);
      };
      if (!((_a = props == null ? void 0 : props.appList) == null ? void 0 : _a.length)) return null;
      const popoverContent = appListRender ? appListRender(props == null ? void 0 : props.appList, defaultDomContent()) : defaultDomContent();
      return wrapSSR((0, import_vue.createVNode)(import_vue.Fragment, null, [(0, import_vue.createVNode)("div", {
        "ref": divRef,
        "onClick": (e) => {
          e.stopPropagation();
          e.preventDefault();
        }
      }, null), (0, import_vue.createVNode)(import_ant_design_vue.Popover, {
        "placement": "bottomRight",
        "trigger": ["click"],
        "style": {
          zIndex: 9999
        },
        "arrow": false,
        "onOpenChange": (openChange) => {
          open.value = openChange;
        },
        "overlayClassName": `${baseClassName.value}-popover ${hashId.value}`.trim(),
        "content": popoverContent,
        "getPopupContainer": () => divRef.value || document.body
      }, {
        default: () => [(0, import_vue.createVNode)("span", {
          "ref": popoverRef,
          "onClick": (e) => {
            e.stopPropagation();
          },
          "class": (0, import_pro_utils.classNames)(`${baseClassName.value}-icon`, hashId.value, {
            [`${baseClassName.value}-icon-active`]: open.value
          })
        }, [(0, import_vue.createVNode)(import_AppsLogo.AppsLogo, null, null)])]
      })]));
    };
  }
});
