'use client';
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");require("@emotion/styled");const T=require("../../ui/button/button.cjs"),x=require("@heroicons/react/24/outline"),U=require("react"),k=require("../../../hooks/use-auth.cjs"),A=require("../../../hooks/use-config.cjs"),y=require("./sign-in-modal.cjs");function E({children:j,variant:w="primary",color:d,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:s=!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 e.jsx(R,{children:j,variant:w,color:d,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:s,redirectAfterSignIn:n,autoRedirect:a});const v=U.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=U.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 e.jsx(T.Button,{variant:"light",size:l,className:`${f} text-success-600`,startContent:e.jsx(x.UserIcon,{className:"w-4 h-4"}),isDisabled:!0,children:s?null:`Welcome, ${h.firstName||h.primaryEmailAddress||"User"}`});const M=I||(s?e.jsx(x.ArrowRightOnRectangleIcon,{className:"w-4 h-4"}):e.jsx(x.ArrowRightOnRectangleIcon,{className:"w-4 h-4"})),O=j||(s?null:"Sign In");return e.jsxs(e.Fragment,{children:[e.jsx(T.Button,{variant:w,color:d,size:l,fullWidth:p,startContent:M,endContent:b,className:f,onPress:F,isDisabled:o||c,isLoading:i||c,isIconOnly:s,children:O}),t&&e.jsx(y.SignInModal,{isOpen:L,onClose:$,onSuccess:v,onError:B,redirectUrl:n,...q})]})}exports.SignInButton=E;
//# sourceMappingURL=sign-in-button.cjs.map
