import { jsx as a } from "react/jsx-runtime";
import e from "prop-types";
import { useRef as l, useImperativeHandle as d } from "react";
import { useMemoizedFn as y } from "ahooks";
import { LOGIN_PROVIDER as P } from "@arcblock/ux/lib/Util/constant";
import A from "../../../Passkey/actions.js";
import { getAppId as I } from "../../../utils.js";
import { useStateContext as R } from "../../contexts/state.js";
function x({ ref: p = null, onSuccess: i, tokenState: o, behavior: n = "none", ...c }) {
  const { extraParams: r, lastLoginMethod: t } = R(), s = l(null), m = y(
    (f) => i(
      {
        ...f,
        encrypted: !1
      },
      (u) => u,
      {
        sourceAppPid: r?.sourceAppPid,
        connected_app: I(o.appInfo, o.memberAppInfo)
      }
    )
  );
  return d(p, () => ({
    connect: s.current.click
  })), n === "none" ? null : /* @__PURE__ */ a(
    A,
    {
      ...c,
      ref: s,
      isLatest: t && t === P.PASSKEY,
      action: o.action,
      behavior: n,
      onSuccess: m,
      extraParams: r
    }
  );
}
x.propTypes = {
  onSuccess: e.func.isRequired,
  tokenState: e.object.isRequired,
  behavior: e.oneOf(["none", "both", "only-existing", "only-new"]),
  ref: e.any
};
export {
  x as default
};
