import { createVNode as _createVNode, Fragment as _Fragment } from "vue";
import { arrayType, classNames, funcType } from "@antdv/pro-utils";
import { Popover } from "ant-design-vue";
import { computed, defineComponent, ref } from "vue";
import { AppsLogo } from "./AppsLogo.mjs";
import { DefaultContent } from "./DefaultContent.mjs";
import { SimpleContent } from "./SimpleContent.mjs";
import { useStyle } from "./style/index.mjs";
function defaultRenderLogo(logo) {
  if (typeof logo === "string") {
    return _createVNode("img", {
      "width": "auto",
      "height": 22,
      "src": logo,
      "alt": "logo"
    }, null);
  }
  if (typeof logo === "function") {
    return logo();
  }
  return logo;
}
const appsLogoComponentProps = {
  appList: arrayType(),
  appListRender: funcType(),
  onItemClick: funcType(),
  prefixCls: String
};
const AppsLogoComponents = defineComponent({
  name: "AppsLogoComponents",
  props: appsLogoComponentProps,
  inheritAttrs: false,
  setup(props) {
    const divRef = ref(null);
    const popoverRef = ref(null);
    const baseClassName = computed(() => `${props.prefixCls || "ant-pro"}-layout-apps`);
    const {
      wrapSSR,
      hashId
    } = useStyle(baseClassName);
    const open = 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 _createVNode(SimpleContent, {
            "hashId": hashId.value,
            "appList": appList,
            "itemClick": itemClick ? cloneItemClick : void 0,
            "baseClassName": `${baseClassName.value}-simple`
          }, null);
        }
        return _createVNode(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(_createVNode(_Fragment, null, [_createVNode("div", {
        "ref": divRef,
        "onClick": (e) => {
          e.stopPropagation();
          e.preventDefault();
        }
      }, null), _createVNode(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: () => [_createVNode("span", {
          "ref": popoverRef,
          "onClick": (e) => {
            e.stopPropagation();
          },
          "class": classNames(`${baseClassName.value}-icon`, hashId.value, {
            [`${baseClassName.value}-icon-active`]: open.value
          })
        }, [_createVNode(AppsLogo, null, null)])]
      })]));
    };
  }
});
export {
  AppsLogoComponents,
  appsLogoComponentProps,
  defaultRenderLogo
};
