'use client';
import { jsx as s, jsxs as G, Fragment as H } from "react/jsx-runtime";
import { useCallback as N } from "react";
import { Button as j } from "@heroui/react";
import { UserIcon as J, UserPlusIcon as D } from "@heroicons/react/24/outline";
import { useSignUpModal as K, SignUpModal as Q } from "./sign-up-modal.js";
import { useAuth as V } from "../../../hooks/use-auth.js";
import { useConfig as W } from "../../../hooks/use-config.js";
function ts({
  children: d,
  variant: w = "solid",
  color: U = "primary",
  size: m = "md",
  fullWidth: g = !1,
  startContent: x,
  endContent: C,
  className: l = "",
  modalMode: e = !1,
  modalProps: b = {},
  href: r = "/auth/sign-up",
  onClick: o,
  onSuccess: p,
  onError: B,
  disabled: u = !1,
  loading: i = !1,
  showAuthenticatedState: I = !0,
  iconOnly: t = !1,
  redirectAfterSignUp: n,
  autoRedirect: a = !0
}) {
  const { isSignedIn: L, user: c, isLoading: f } = V(), { components: $, features: y } = W(), { isOpen: F, open: S, close: P } = K(), T = $.SignUpButton;
  if (T)
    return /* @__PURE__ */ s(T, { children: d, variant: w, color: U, size: m, fullWidth: g, startContent: x, endContent: C, className: l, modalMode: e, modalProps: b, href: r, onClick: o, onSuccess: p, onError: B, disabled: u, loading: i, showAuthenticatedState: I, iconOnly: t, redirectAfterSignUp: n, autoRedirect: a });
  if (!y.signUp)
    return null;
  const _ = N((h) => {
    if (p?.(h), a && n)
      setTimeout(() => {
        window.location.href = n;
      }, 1e3);
    else if (a && h.user) {
      const v = h.user.userType || "external", E = {
        internal: "/admin/dashboard",
        external: "/dashboard",
        end_user: "/app"
      }[v] || "/dashboard";
      setTimeout(() => {
        window.location.href = E;
      }, 1e3);
    }
  }, [p, a, n]), q = N(() => {
    if (!(u || i || f)) {
      if (o) {
        o();
        return;
      }
      if (e) {
        S();
        return;
      }
      r && (window.location.href = r);
    }
  }, [u, i, f, o, e, S, r]);
  return I && L && c ? /* @__PURE__ */ s(
    j,
    {
      variant: "light",
      size: m,
      className: `${l} text-success-600`,
      startContent: /* @__PURE__ */ s(J, { className: "w-4 h-4" }),
      isDisabled: !0,
      children: t ? null : `Welcome, ${c.firstName || c.primaryEmailAddress || "User"}`
    }
  ) : /* @__PURE__ */ G(H, { children: [
    /* @__PURE__ */ s(
      j,
      {
        variant: w,
        color: U,
        size: m,
        fullWidth: g,
        startContent: x || (t ? /* @__PURE__ */ s(D, { className: "w-4 h-4" }) : /* @__PURE__ */ s(D, { className: "w-4 h-4" })),
        endContent: C,
        className: l,
        onPress: q,
        isDisabled: u || f,
        isLoading: i || f,
        isIconOnly: t,
        children: d || (t ? null : "Sign Up")
      }
    ),
    e && /* @__PURE__ */ s(
      Q,
      {
        isOpen: F,
        onClose: P,
        onSuccess: _,
        onError: B,
        redirectUrl: n,
        ...b
      }
    )
  ] });
}
export {
  ts as SignUpButton
};
//# sourceMappingURL=sign-up-button.js.map
