import { useCreation as u } from "ahooks";
import { getFederatedEnabled as m, getMaster as c, getApps as A } from "@arcblock/ux/lib/Util/federated";
import p from "lodash/isUndefined";
import { use as P } from "react";
import { SessionContext as g } from "../../Session/context.js";
function F({ blocklet: t, action: f, sourceAppPid: r, connectState: i, enableSwitchApp: d }) {
  const s = P(g), n = u(() => d === !0 ? !0 : !(d === !1 || s?.session?.user && !["login", "invite", "connect-to-did-space", "connect-to-did-domain"].includes(f)), [f, s?.session?.user]), o = u(() => {
    if (p(r)) {
      const a = m(t), e = c(t);
      if (a && e?.appPid)
        return e.appPid;
    }
    return r;
  }, [r, t]);
  return { appInfoList: u(() => A(t).filter((e) => n ? !0 : p(r) ? p(i.sourceAppPid) ? s?.session?.user ? e.sourceAppPid === s.session.user.sourceAppPid : e.sourceAppPid === o : e.sourceAppPid === i.sourceAppPid : e.sourceAppPid === r), [n, r, i.sourceAppPid, o, s?.session?.user]), autoGenerateSourceAppPid: o, canSwitchApp: n };
}
export {
  F as default
};
