import { useBrowser as R } from "@arcblock/react-hooks";
import { detectWalletExtension as v } from "@arcblock/ux/lib/Util";
import { useRequest as D, useCreation as r } from "ahooks";
import W from "lodash/intersection";
import { OAUTH_PROVIDER as x } from "@arcblock/ux/lib/Util/constant";
import { useOAuth as C } from "../../OAuth/context.js";
import "../../utils.js";
import { checkSameProtocol as I, getWebWalletUrl as M } from "@arcblock/ux/lib/Util/wallet";
function F({
  enabledConnectTypes: o = [],
  allowWallet: n = !0,
  passkeyBehavior: g = "none",
  webWalletUrl: L = M(),
  action: e,
  sourceAppPid: f,
  mode: c = "dialog",
  blocklet: u = globalThis.blocklet,
  isSmallView: d = !1
}) {
  const s = ["login", "invite", "connect-to-did-space", "connect-to-did-domain", "destroy-self"], { getOAuthConfigList: w } = C(), i = R(), a = v(), { data: m = [] } = D(
    async () => await w({ sourceAppPid: f }),
    { refreshDeps: [f] }
  ), l = r(() => {
    const t = W(Object.keys(x), o);
    return m.filter((P) => t.includes(P.provider));
  }, [m, o]), O = r(() => s.includes(e) ? l.length > 0 : !1, [l, e]), h = r(() => {
    let t = n;
    return s.includes(e) || (t = !0), t && o.includes("mobile");
  }, [n, o, e]), b = I(L), p = r(() => {
    let t = n;
    return s.includes(e) || (t = !0), t && o.includes("web") && (b || a) && (!i.mobile.any || a);
  }, [n, o, i?.mobile?.any, e]), _ = r(() => g !== "none" && !i.wallet && !i.arcSphere, [e]), A = r(() => !s.includes(e) || !["true", void 0, null].includes(u?.DID_CONNECT_ALLOW_EMAIL) ? !1 : u?.settings?.notification?.email?.enabled ?? !1, [e, u]), E = r(() => !1);
  return {
    hideQRCode: r(() => !!(c === "drawer" || d && i.mobile.any || s.includes(e) && !h), [c, d]),
    hideChooseList: E,
    showOAuthLogin: O,
    showMobileLogin: h,
    showWebLogin: p,
    showPasskeyLogin: _,
    showEmailLogin: A,
    oauthProviderList: l
  };
}
export {
  F as default
};
