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