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