import { jsx as i, Fragment as b } from "react/jsx-runtime";
import "iconify-icon";
import a from "prop-types";
import { use as L, createElement as v } from "react";
import { SessionContext as N } from "@arcblock/did-connect-react/lib/Session";
import T from "@arcblock/ux/lib/Config/theme-mode-toggle";
import { useLocaleContext as k } from "@arcblock/ux/lib/Locale/context";
import C from "@arcblock/ux/lib/Locale/selector";
import S from "@arcblock/ux/lib/SessionBlocklet";
import D from "@arcblock/ux/lib/SessionUser";
import { WELLKNOWN_BLOCKLET_ADMIN_PATH as E } from "@abtnode/constant";
import { getLocalizedNavigation as M, filterNavByRole as O } from "../blocklets.js";
import { SessionManagerProps as R } from "../types.js";
import W from "./domain-warning.js";
import P from "./notification-addon.js";
import B from "./org-switch/index.js";
const _ = () => !!(window?.blocklet?.navigation ?? []).find((o) => o.id === "/userCenter/notification"), j = (n) => {
  const { settings: o = {} } = n ?? window?.blocklet ?? {};
  return o?.org?.enabled || !1;
}, x = () => {
  const { pathname: n = "" } = window.location || {};
  return n.startsWith(E);
};
function z({
  formattedBlocklet: n,
  addons: o = null,
  showDomainWarningDialog: m = !0,
  sessionManagerProps: u = { showRole: !0 }
}) {
  const e = L(N), { locale: t, languages: p, defaultLocale: g } = k() || {}, { enableConnect: d = !0, enableLocale: h = !0 } = n, y = !!e?.session?.user;
  let l = M({
    navigation: n?.navigation?.sessionManager,
    locale: t,
    defaultLocale: g
  }) || [];
  l = O(l, e?.session?.user?.role);
  const c = (() => {
    if (o && typeof o != "function")
      return Array.isArray(o) ? o : [o];
    let s = [];
    if (_() && s.push(/* @__PURE__ */ i(P, { session: e.session }, "notification-addon")), h && t && p.length > 1 && s.push(/* @__PURE__ */ i(C, { showText: !1 }, "locale-selector")), s.push(/* @__PURE__ */ i(T, {}, "theme-mode-toggle")), d && e) {
      const f = [];
      y && (l ? l.slice(0, 5) : []).forEach((r) => {
        f.push({
          label: r.title,
          icon: r.icon ? /* @__PURE__ */ i("iconify-icon", { icon: r.icon, height: 24, style: { marginRight: 8 } }) : null,
          component: "a",
          href: r.link,
          key: r.link
        });
      }), s.push(/* @__PURE__ */ i(S, { session: e.session, locale: t }, "session-blocklet")), s.push(
        /* @__PURE__ */ i(
          D,
          {
            session: e.session,
            locale: t,
            menu: f,
            showRole: !0,
            ...u
          },
          "session-user"
        )
      );
    }
    return !x() && j(n) && e?.session?.user && s.unshift(/* @__PURE__ */ i(B, { session: e.session, locale: t }, "orgs-switch")), typeof o == "function" && (s = o(s) || []), s;
  })(), w = Array.isArray(c) ? c : [c], A = [
    m ? /* @__PURE__ */ i(W, { session: e?.session, locale: t }) : null,
    ...w
  ].filter(Boolean);
  return v(b, null, ...A);
}
z.propTypes = {
  formattedBlocklet: a.object.isRequired,
  // 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
  addons: a.oneOfType([a.func, a.node]),
  sessionManagerProps: R,
  showDomainWarningDialog: a.bool
};
export {
  z as default
};
