import { translate as I } from "@arcblock/ux/lib/Locale/util";
import { LOGIN_PROVIDER as n } from "@arcblock/ux/lib/Util/constant";
import { toBase64 as A } from "@ocap/util";
import { translations as C } from "../libs/locales.js";
function k({ state: p, locale: a, connectApi: c }) {
  const { user: u } = p, s = u?.connectedAccounts || [], f = s.some((e) => e.provider === n.PASSKEY), l = s.some((e) => e.provider === n.EMAIL), d = s.some((e) => e.provider === n.GITHUB), h = s.some((e) => e.provider === n.GOOGLE), y = s.some((e) => e.provider === n.APPLE), g = f ? "only-existing" : "none", o = ["web", "mobile"];
  l && o.push("email"), d && o.push("github"), h && o.push("google"), y && o.push("apple");
  const t = (e, i = {}) => I(C.verify, e, a, "en", i);
  return (e = {}) => {
    const { payload: i, ...r } = e.extraParams || {}, v = {
      payload: A(JSON.stringify({ action: e.operation || "destroy-self", input: r.input || {} })),
      ...r || {}
    };
    return new Promise((P, E) => {
      c.open({
        locale: a,
        action: e.action || "destroy-self",
        // 每次都需要验证的
        forceConnected: !0,
        saveConnect: !1,
        autoConnect: !1,
        className: "connect",
        checkTimeout: 10 * 60 * 1e3,
        passkeyBehavior: g,
        enabledConnectTypes: o,
        messages: e.messages || {
          title: t("title"),
          scan: t("scan"),
          confirm: t("confirm"),
          success: t("success")
        },
        extraParams: v,
        onSuccess: (m, b = (G) => G) => {
          P({ result: m, input: r.input, sessionId: b(m.destroySessionId) });
        },
        onClose: () => {
          E(new Error(t("abort"))), c.close();
        }
      });
    });
  };
}
export {
  k as default
};
