import { jsx as e, jsxs as o, Fragment as p } from "react/jsx-runtime";
import { CircularProgress as u, Box as d, Stack as G, Button as h, Typography as J, Link as K } from "@mui/material";
import { useReactive as O, useMemoizedFn as r } from "ahooks";
import c from "lodash/noop";
import { useImperativeHandle as Q } from "react";
import V from "../did-connect-container.js";
import X from "./auth-apps-info.js";
import Y from "../../Center/index.js";
import Z from "../landing-page.js";
import { translate as _ } from "../../Locale/util.js";
import { useLocaleContext as $ } from "../../Locale/context.js";
import ee from "../../UserCard/index.js";
import { InfoType as ne, CardType as oe } from "../../UserCard/types.js";
import { mergeSx as f } from "../../Util/style.js";
import re from "./switch-role.js";
const ie = {
  en: {
    notThis: "Not you?",
    useAnother: "Use another account",
    authorize: "Authorize",
    connect: "Connect",
    cancel: "Cancel"
  },
  zh: {
    notThis: "不是这个？",
    useAnother: "使用其他账户",
    authorize: "授权",
    connect: "Connect",
    cancel: "取消"
  }
};
function ye({
  session: s,
  requestAppInfo: g,
  currentAppInfo: x,
  children: C = null,
  userInfo: v = void 0,
  hideSwitchConnect: y = !1,
  hideAuthorize: z = !1,
  hideCancel: w = !1,
  hideButton: A = !1,
  notThisText: T = void 0,
  authorizeText: b = void 0,
  connectText: k = void 0,
  cancelText: S = void 0,
  useAnotherText: D = void 0,
  slotProps: i = void 0,
  onConnect: I = c,
  onAuthorize: L = c,
  onSwitchConnect: R = c,
  onSwitchPassport: W = c,
  onCancel: j = c,
  ref: B,
  disableAuthorizeButton: m = !1
}) {
  const n = O({
    loading: !1
  }), { locale: F = "en" } = $() || {}, t = r((q, E = {}) => _(ie, q, F, "en", E)), l = r(() => {
    n.loading = !1;
  }), M = r(() => {
    n.loading = !0, I?.(l);
  }), U = r(() => {
    n.loading = !0, R?.(l);
  }), H = r(() => {
    n.loading = !0, L?.(l);
  }), N = r(() => {
    n.loading = !0, W?.(l);
  }), P = r(() => {
    j?.();
  });
  if (Q(B, () => ({
    closeLoading: l
  })), s.loading || !s.initialized)
    return /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ e(u, {}) });
  const a = v ?? s?.user;
  return /* @__PURE__ */ e(Z, { did: window.blocklet?.appPid, standalone: !0, children: /* @__PURE__ */ e(
    d,
    {
      ...i?.root,
      sx: f(
        {
          width: 420,
          maxWidth: "100%"
        },
        i?.root?.sx
      ),
      children: /* @__PURE__ */ e(V, { hideCloseButton: !0, ...i?.didConnectContainer, children: /* @__PURE__ */ o(
        d,
        {
          ...i?.contentContainer,
          sx: f(
            {
              display: "flex",
              flexDirection: "column",
              gap: 1.5,
              p: {
                xs: 2,
                lg: 3,
                xl: 4
              },
              pt: {
                xs: 3,
                xl: 4
              },
              bgcolor: "background.paper"
            },
            i?.contentContainer?.sx
          ),
          children: [
            /* @__PURE__ */ e(X, { requestAppInfo: g, currentAppInfo: x }),
            a ? /* @__PURE__ */ o(p, { children: [
              /* @__PURE__ */ e(
                ee,
                {
                  user: a,
                  showDid: !0,
                  cardType: oe.Detailed,
                  infoType: ne.Minimal,
                  renderTopRightContent: () => /* @__PURE__ */ e(re, { user: a, switchPassport: N })
                }
              ),
              /* @__PURE__ */ e(d, {})
            ] }) : null,
            C,
            A ? null : /* @__PURE__ */ o(p, { children: [
              /* @__PURE__ */ e(
                d,
                {
                  sx: {
                    border: "1px solid",
                    borderColor: "divider",
                    borderRadius: 2,
                    overflow: "hidden",
                    my: 1
                  }
                }
              ),
              /* @__PURE__ */ o(G, { direction: "row", spacing: 2, children: [
                w ? null : /* @__PURE__ */ e(
                  h,
                  {
                    color: "inherit",
                    variant: "outlined",
                    size: "large",
                    fullWidth: !0,
                    onClick: P,
                    sx: {
                      color: "grey.500"
                    },
                    children: S || t("cancel")
                  }
                ),
                a && !z ? /* @__PURE__ */ o(
                  h,
                  {
                    variant: "contained",
                    size: "large",
                    fullWidth: !0,
                    onClick: H,
                    disabled: n.loading || m,
                    children: [
                      n.loading ? /* @__PURE__ */ e(u, { size: 20, sx: { mr: 1 } }) : null,
                      b || t("authorize")
                    ]
                  }
                ) : /* @__PURE__ */ o(
                  h,
                  {
                    variant: "contained",
                    size: "large",
                    fullWidth: !0,
                    disabled: n.loading || m,
                    onClick: M,
                    children: [
                      n.loading ? /* @__PURE__ */ e(u, { size: 20, sx: { mr: 1 } }) : null,
                      k || t("connect")
                    ]
                  }
                )
              ] })
            ] }),
            y || !a ? null : /* @__PURE__ */ e(d, { sx: { textAlign: "center" }, children: /* @__PURE__ */ o(
              J,
              {
                variant: "body2",
                sx: {
                  display: "flex",
                  alignItems: "center",
                  justifyContent: "center",
                  gap: 1
                },
                children: [
                  T || t("notThis"),
                  " ",
                  /* @__PURE__ */ e(
                    K,
                    {
                      underline: "hover",
                      onClick: U,
                      sx: {
                        cursor: "pointer"
                      },
                      children: D || t("useAnother")
                    }
                  )
                ]
              }
            ) })
          ]
        }
      ) })
    }
  ) });
}
export {
  ye as default
};
