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