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