@saas-support/react 0.7.2 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +29 -20
- package/dist/react.cjs +25 -2
- package/dist/react.d.ts +6 -1
- package/dist/react.js +1215 -1181
- package/package.json +1 -1
package/dist/react.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),r=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),r=require("react"),R=require("./index.cjs"),js=require("react-dom"),Z=r.createContext(null);function B(){const e=r.useContext(Z);if(!e)throw new Error("useSaaSContext must be used within a <SaaSProvider>");return e}function vs({publishableKey:e,apiKey:t,baseUrl:a,appearance:l,children:n}){const[u]=r.useState(()=>new R.SaaSSupport({publishableKey:e,apiKey:t,baseUrl:a})),[c,d]=r.useState(null),[i,o]=r.useState(!1),[x,p]=r.useState(null);return r.useEffect(()=>{let h=!1;u.load().then(async()=>{if(h)return;const f=await u.auth.getUser(),b=await u.auth.getSettings();d(f),p(b),o(!0)});const y=u.auth.onAuthStateChange(f=>{h||d(f)});return()=>{h=!0,y(),u.destroy()}},[u]),s.jsx(Z.Provider,{value:{client:u,user:c,isLoaded:i,appearance:l,settings:x},children:n})}const ws={colorPrimary:"#6366f1",colorPrimaryHover:"#4f46e5",colorBackground:"#ffffff",colorText:"#1a1a2e",colorTextSecondary:"#6b7280",colorInputBackground:"#f9fafb",colorInputBorder:"#d1d5db",colorError:"#ef4444",colorSuccess:"#22c55e",colorWarning:"#f59e0b",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',borderRadius:"8px",authPrimary:"#4648d4",authPrimaryContainer:"#6063ee",authOnPrimary:"#ffffff",authPrimaryFixed:"#e1e0ff",authSurface:"#fcf8ff",authSurfaceContainerLowest:"#ffffff",authSurfaceContainerLow:"#f5f2ff",authSurfaceContainer:"#efecff",authSurfaceContainerHigh:"#e8e5ff",authSurfaceContainerHighest:"#e2e0fc",authOnSurface:"#1a1a2e",authOnSurfaceVariant:"#464554",authOutline:"#767586",authOutlineVariant:"#c7c4d7",authError:"#ba1a1a",authErrorContainer:"#ffdad6",authSuccess:"#22c55e",authFontHeadline:"'Manrope', sans-serif",authFontBody:"'Inter', sans-serif"},Ss={colorPrimary:"#818cf8",colorPrimaryHover:"#6366f1",colorBackground:"#1e1e2e",colorText:"#e2e8f0",colorTextSecondary:"#94a3b8",colorInputBackground:"#2a2a3e",colorInputBorder:"#3f3f5e",colorError:"#f87171",colorSuccess:"#4ade80",colorWarning:"#fbbf24",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',borderRadius:"8px",authPrimary:"#818cf8",authPrimaryContainer:"#6063ee",authOnPrimary:"#ffffff",authPrimaryFixed:"#2a2a3e",authSurface:"#1e1e2e",authSurfaceContainerLowest:"#161623",authSurfaceContainerLow:"#27273a",authSurfaceContainer:"#2d2d44",authSurfaceContainerHigh:"#363654",authSurfaceContainerHighest:"#3f3f61",authOnSurface:"#e2e8f0",authOnSurfaceVariant:"#94a3b8",authOutline:"#464554",authOutlineVariant:"#44445a",authError:"#f87171",authErrorContainer:"#93000a",authSuccess:"#4ade80",authFontHeadline:"'Manrope', sans-serif",authFontBody:"'Inter', sans-serif"};function Q(e){const t=(e==null?void 0:e.baseTheme)==="dark"?Ss:ws,a=e==null?void 0:e.variables,l=(a==null?void 0:a.colorPrimary)??t.authPrimary;return{colorPrimary:(a==null?void 0:a.colorPrimary)??t.colorPrimary,colorPrimaryHover:a!=null&&a.colorPrimary?Ns(a.colorPrimary,10):t.colorPrimaryHover,colorBackground:(a==null?void 0:a.colorBackground)??t.colorBackground,colorText:(a==null?void 0:a.colorText)??t.colorText,colorTextSecondary:t.colorTextSecondary,colorInputBackground:(a==null?void 0:a.colorInputBackground)??t.colorInputBackground,colorInputBorder:(a==null?void 0:a.colorInputBorder)??t.colorInputBorder,colorError:(a==null?void 0:a.colorError)??t.colorError,colorSuccess:(a==null?void 0:a.colorSuccess)??t.colorSuccess,colorWarning:(a==null?void 0:a.colorWarning)??t.colorWarning,fontFamily:(a==null?void 0:a.fontFamily)??t.fontFamily,borderRadius:(a==null?void 0:a.borderRadius)??t.borderRadius,authPrimary:l,authPrimaryContainer:a!=null&&a.colorPrimary?ks(l,15):t.authPrimaryContainer,authOnPrimary:t.authOnPrimary,authPrimaryFixed:t.authPrimaryFixed,authSurface:(a==null?void 0:a.colorBackground)??t.authSurface,authSurfaceContainerLowest:t.authSurfaceContainerLowest,authSurfaceContainerLow:(a==null?void 0:a.colorInputBackground)??t.authSurfaceContainerLow,authSurfaceContainer:t.authSurfaceContainer,authSurfaceContainerHigh:t.authSurfaceContainerHigh,authSurfaceContainerHighest:t.authSurfaceContainerHighest,authOnSurface:(a==null?void 0:a.colorText)??t.authOnSurface,authOnSurfaceVariant:t.authOnSurfaceVariant,authOutline:t.authOutline,authOutlineVariant:(a==null?void 0:a.colorInputBorder)??t.authOutlineVariant,authError:(a==null?void 0:a.colorError)??t.authError,authErrorContainer:t.authErrorContainer,authSuccess:(a==null?void 0:a.colorSuccess)??t.authSuccess,authFontHeadline:(a==null?void 0:a.fontFamily)??t.authFontHeadline,authFontBody:(a==null?void 0:a.fontFamily)??t.authFontBody}}function Ns(e,t){const a=parseInt(e.replace("#",""),16),l=Math.max(0,(a>>16)-Math.round(2.55*t)),n=Math.max(0,(a>>8&255)-Math.round(2.55*t)),u=Math.max(0,(a&255)-Math.round(2.55*t));return`#${(l<<16|n<<8|u).toString(16).padStart(6,"0")}`}function ks(e,t){const a=parseInt(e.replace("#",""),16),l=Math.min(255,(a>>16)+Math.round(2.55*t)),n=Math.min(255,(a>>8&255)+Math.round(2.55*t)),u=Math.min(255,(a&255)+Math.round(2.55*t));return`#${(l<<16|n<<8|u).toString(16).padStart(6,"0")}`}function J(e){return`
|
|
2
2
|
:host {
|
|
3
3
|
all: initial;
|
|
4
4
|
font-family: ${e.fontFamily};
|
|
@@ -1279,6 +1279,7 @@
|
|
|
1279
1279
|
cursor: pointer;
|
|
1280
1280
|
transition: background 0.15s, box-shadow 0.15s;
|
|
1281
1281
|
font-family: ${e.authFontBody};
|
|
1282
|
+
max-width: 200px;
|
|
1282
1283
|
}
|
|
1283
1284
|
|
|
1284
1285
|
.ss-auth-user-trigger:hover {
|
|
@@ -2098,6 +2099,25 @@
|
|
|
2098
2099
|
margin: 0;
|
|
2099
2100
|
}
|
|
2100
2101
|
|
|
2102
|
+
.ss-auth-settings-back {
|
|
2103
|
+
display: flex;
|
|
2104
|
+
align-items: center;
|
|
2105
|
+
justify-content: center;
|
|
2106
|
+
width: 36px;
|
|
2107
|
+
height: 36px;
|
|
2108
|
+
border-radius: 8px;
|
|
2109
|
+
border: none;
|
|
2110
|
+
background: none;
|
|
2111
|
+
cursor: pointer;
|
|
2112
|
+
color: ${e.authOnSurfaceVariant};
|
|
2113
|
+
transition: background 0.15s, color 0.15s;
|
|
2114
|
+
}
|
|
2115
|
+
.ss-auth-settings-back:hover {
|
|
2116
|
+
background: ${e.authSurfaceContainer};
|
|
2117
|
+
color: ${e.authOnSurface};
|
|
2118
|
+
}
|
|
2119
|
+
.ss-auth-settings-back .material-symbols-outlined { font-size: 22px; }
|
|
2120
|
+
|
|
2101
2121
|
.ss-auth-settings-layout {
|
|
2102
2122
|
display: flex;
|
|
2103
2123
|
flex: 1;
|
|
@@ -2156,6 +2176,9 @@
|
|
|
2156
2176
|
flex: 1;
|
|
2157
2177
|
overflow-y: auto;
|
|
2158
2178
|
padding: 32px;
|
|
2179
|
+
max-width: 720px;
|
|
2180
|
+
margin: 0 auto;
|
|
2181
|
+
width: 100%;
|
|
2159
2182
|
}
|
|
2160
2183
|
|
|
2161
2184
|
.ss-auth-settings-content h3 {
|
|
@@ -2331,4 +2354,4 @@
|
|
|
2331
2354
|
.ss-auth-trigger-org-name { display: none; }
|
|
2332
2355
|
.ss-auth-user-trigger { padding: 0; border: none; background: none; }
|
|
2333
2356
|
}
|
|
2334
|
-
`}function M({children:e,appearance:a}){const t=r.useRef(null),[o,n]=r.useState(null);r.useEffect(()=>{var g;if(!t.current||t.current.shadowRoot){n(((g=t.current)==null?void 0:g.shadowRoot)??null);return}const i=t.current.attachShadow({mode:"open"});if((a==null?void 0:a.fontUrl)!==null){const p=(a==null?void 0:a.fontUrl)??"https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Inter:wght@400;500;600&family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&display=swap";if(!document.querySelector(`link[href="${p}"]`)){const m=document.createElement("link");m.rel="stylesheet",m.href=p,document.head.appendChild(m)}const x=document.createElement("link");x.rel="stylesheet",x.href=p,i.appendChild(x)}const c=Q(a),d=document.createElement("style");d.textContent=J(c),i.appendChild(d);const l=document.createElement("div");i.appendChild(l),n(i)},[]),r.useEffect(()=>{if(!o)return;const i=o.querySelector("style");if(i){const c=Q(a);i.textContent=J(c)}},[a,o]);const u=(o==null?void 0:o.querySelector("div"))??null;return s.jsx("div",{ref:t,style:{display:"contents"},children:u&&js.createPortal(e,u)})}function W(){const{client:e,user:a,isLoaded:t}=I();return{isLoaded:t,isSignedIn:!!a,user:a,signOut:r.useCallback(()=>e.auth.signOut(),[e]),getToken:r.useCallback(()=>e.auth.getToken(),[e]),refreshUser:r.useCallback(()=>e.auth.refreshUser(),[e])}}function $s(){const{user:e,isLoaded:a}=I();return{user:e,isLoaded:a}}function K(){const{client:e}=I(),[a,t]=r.useState(!1),[o,n]=r.useState(null),u=r.useCallback(async(d,l)=>{t(!0),n(null);try{return await e.auth.signIn(d,l)}catch(g){return n(g instanceof Error?g.message:"Sign in failed"),null}finally{t(!1)}},[e]),i=r.useCallback(async d=>{t(!0),n(null);try{return await e.auth.signInWithOAuth(d)}catch(l){return n(l instanceof Error?l.message:"OAuth sign in failed"),null}finally{t(!1)}},[e]),c=r.useCallback(async(d,l)=>{t(!0),n(null);try{return await e.auth.submitMfaCode(d,l)}catch(g){return n(g instanceof Error?g.message:"MFA verification failed"),null}finally{t(!1)}},[e]);return{signIn:u,signInWithOAuth:i,submitMfaCode:c,isLoading:a,error:o,setError:n}}function es(){const{client:e}=I(),[a,t]=r.useState(!1),[o,n]=r.useState(null);return{signUp:r.useCallback(async(i,c)=>{t(!0),n(null);try{return await e.auth.signUp(i,c)}catch(d){return n(d instanceof Error?d.message:"Sign up failed"),null}finally{t(!1)}},[e]),isLoading:a,error:o,setError:n}}function H(){const{client:e}=I(),[a,t]=r.useState([]),[o,n]=r.useState(null),[u,i]=r.useState([]),[c,d]=r.useState([]),[l,g]=r.useState(!1),[p,x]=r.useState(null),m=r.useCallback(async()=>{g(!0),x(null);try{const S=await e.auth.listOrgs();if(t(S),!o&&S.length>0){const f=typeof window<"u"?localStorage.getItem("ss_selected_org"):null,z=(f?S.find(B=>B.id===f):null)??(S.length===1?S[0]:null);if(z){n(z),typeof window<"u"&&localStorage.setItem("ss_selected_org",z.id);try{const B=await e.auth.listMembers(z.id);i(B)}catch{}}}}catch(S){x(S instanceof Error?S.message:"Failed to load organizations")}finally{g(!1)}},[e,o]);r.useEffect(()=>{m()},[m]);const j=r.useCallback(async S=>{try{const f=await e.auth.getOrg(S);n(f),typeof window<"u"&&localStorage.setItem("ss_selected_org",S);const w=await e.auth.listMembers(S);i(w)}catch(f){x(f instanceof Error?f.message:"Failed to load organization")}},[e]),b=r.useCallback(async(S,f)=>{try{const w=await e.auth.createOrg(S,f);return t(z=>[...z,w]),w}catch(w){return x(w instanceof Error?w.message:"Failed to create organization"),null}},[e]),C=r.useCallback(async(S,f)=>{try{const w=await e.auth.updateOrg(S,f);return t(z=>z.map(B=>B.id===S?w:B)),(o==null?void 0:o.id)===S&&n(w),w}catch(w){return x(w instanceof Error?w.message:"Failed to update organization"),null}},[e,o]),h=r.useCallback(async S=>{try{return await e.auth.deleteOrg(S),t(f=>f.filter(w=>w.id!==S)),(o==null?void 0:o.id)===S&&(n(null),i([]),d([]),typeof window<"u"&&localStorage.removeItem("ss_selected_org")),!0}catch(f){return x(f instanceof Error?f.message:"Failed to delete organization"),!1}},[e,o]),v=r.useCallback(async(S,f,w)=>{try{return await e.auth.sendInvite(S,f,w)}catch(z){return x(z instanceof Error?z.message:"Failed to send invite"),null}},[e]),N=r.useCallback(async S=>{try{const f=await e.auth.listInvites(S);d(f)}catch(f){x(f instanceof Error?f.message:"Failed to load invites")}},[e]),$=r.useCallback(async(S,f)=>{try{return await e.auth.revokeInvite(S,f),d(w=>w.filter(z=>z.id!==f)),!0}catch(w){return x(w instanceof Error?w.message:"Failed to revoke invite"),!1}},[e]),P=r.useCallback(async(S,f,w)=>{try{return await e.auth.updateMemberRole(S,f,w),i(z=>z.map(B=>B.userId===f?{...B,role:w}:B)),!0}catch(z){return x(z instanceof Error?z.message:"Failed to update member role"),!1}},[e]),O=r.useCallback(async(S,f)=>{try{return await e.auth.removeMember(S,f),i(w=>w.filter(z=>z.userId!==f)),!0}catch(w){return x(w instanceof Error?w.message:"Failed to remove member"),!1}},[e]),E=r.useCallback(async S=>{try{const f=await e.auth.listMembers(S);i(f)}catch(f){x(f instanceof Error?f.message:"Failed to load members")}},[e]);return{orgs:a,selectedOrg:o,members:u,invites:c,isLoading:l,error:p,setError:x,refresh:m,selectOrg:j,createOrg:b,updateOrg:C,deleteOrg:h,sendInvite:v,refreshInvites:N,revokeInvite:$,updateMemberRole:P,removeMember:O,refreshMembers:E}}function as(){const{client:e}=I(),[a,t]=r.useState(!1),[o,n]=r.useState(null);return{deleteAccount:r.useCallback(async()=>{t(!0),n(null);try{return await e.auth.deleteAccount(),!0}catch(i){return n(i instanceof Error?i.message:"Failed to delete account"),!1}finally{t(!1)}},[e]),isLoading:a,error:o,setError:n}}function X(){const{client:e,user:a}=I(),[t,o]=r.useState(!1),[n,u]=r.useState(null),[i,c]=r.useState(null),d=r.useCallback(async p=>{o(!0),u(null),c(null);try{const x=await e.auth.updateProfile(p);return c("Profile updated"),x}catch(x){return u(x instanceof Error?x.message:"Failed to update profile"),null}finally{o(!1)}},[e]),l=r.useCallback(async(p,x)=>{o(!0),u(null),c(null);try{return await e.auth.changePassword(p,x),c("Password changed successfully"),!0}catch(m){return u(m instanceof Error?m.message:"Failed to change password"),!1}finally{o(!1)}},[e]),g=r.useCallback(async p=>{o(!0),u(null),c(null);try{const x=await e.auth.uploadAvatar(p);return c("Avatar updated"),x}catch(x){return u(x instanceof Error?x.message:"Failed to upload avatar"),null}finally{o(!1)}},[e]);return{user:a,updateProfile:d,uploadAvatar:g,changePassword:l,isLoading:t,error:n,success:i,setError:u,setSuccess:c}}const ts='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z" fill="#4285F4"/><path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/><path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05"/><path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/></svg>',rs='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0 0 24 12c0-6.63-5.37-12-12-12z" fill="currentColor"/></svg>',y={close:"close",person:"person",logout:"logout",checkCircle:"check_circle",unfoldMore:"unfold_more",cloudUpload:"cloud_upload",zoomIn:"zoom_in",zoomOut:"zoom_out",lock:"lock",visibility:"visibility",visibilityOff:"visibility_off",add:"add",addCircle:"add_circle",camera:"photo_camera",security:"security",errorOutline:"error_outline",info:"info",arrowForward:"arrow_forward",verified:"verified",token:"token",autoAwesome:"auto_awesome",corporateFare:"corporate_fare",cloudDone:"cloud_done",check:"check",image:"image",settings:"settings",group:"group",creditCard:"credit_card",edit:"edit",send:"send",personRemove:"person_remove"};function Cs({appearance:e,signUpUrl:a,onSignUp:t}){const{appearance:o,settings:n}=I(),{signIn:u,signInWithOAuth:i,submitMfaCode:c,isLoading:d,error:l,setError:g}=K(),p=e??o,[x,m]=r.useState(""),[j,b]=r.useState(""),[C,h]=r.useState(!1),[v,N]=r.useState(!1),[$,P]=r.useState(""),[O,E]=r.useState(["","","","","",""]),S=r.useRef([]),f=r.useCallback(async L=>{if(L.preventDefault(),v){await c($,O.join(""));return}const k=await u(x,j);k&&U.isMfaRequired(k)&&(P(k.mfaToken),N(!0),g(null))},[x,j,v,$,O,u,c,g]),w=r.useCallback(async L=>{await i(L)},[i]),z=r.useCallback((L,k)=>{var V;if(!/^\d*$/.test(k))return;const F=k.slice(-1);E(G=>{const q=[...G];return q[L]=F,q}),F&&L<5&&((V=S.current[L+1])==null||V.focus())},[]),B=r.useCallback((L,k)=>{var F;k.key==="Backspace"&&!O[L]&&L>0&&((F=S.current[L-1])==null||F.focus())},[O]),T=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled);return s.jsx(M,{appearance:p,children:s.jsx("div",{className:"ss-auth-card",children:s.jsxs("div",{className:"ss-auth-card-body",children:[s.jsxs("div",{className:"ss-auth-header",children:[s.jsx("div",{className:"ss-auth-brand-icon",children:s.jsx("span",{className:"material-symbols-outlined",children:y.token})}),s.jsx("h1",{className:"ss-auth-title",children:"Sign in to your account"}),s.jsx("p",{className:"ss-auth-subtitle",children:"Welcome back to your workspace"})]}),!v&&T&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-auth-oauth-grid",children:[(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>w("google"),disabled:d,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:ts}}),"Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>w("github"),disabled:d,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:rs}}),"GitHub"]})]}),s.jsx("div",{className:"ss-auth-divider",children:"or continue with"})]}),l&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:l})]}),s.jsxs("form",{onSubmit:f,children:[v?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ss-auth-mfa-divider",children:s.jsx("span",{children:"Verification Required"})}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"6-Digit Code"}),s.jsx("div",{className:"ss-auth-mfa-group",children:O.map((L,k)=>s.jsx("input",{ref:F=>{S.current[k]=F},className:"ss-auth-mfa-digit",type:"text",inputMode:"numeric",maxLength:1,value:L,onChange:F=>z(k,F.target.value),onKeyDown:F=>B(k,F),autoFocus:k===0},k))}),s.jsx("p",{className:"ss-auth-mfa-hint",children:"We sent a 6-digit code to your registered email."})]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-email",children:"Email Address"}),s.jsx("input",{id:"ss-email",className:"ss-auth-input",type:"email",autoComplete:"email",placeholder:"name@company.com",value:x,onChange:L=>m(L.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsxs("div",{className:"ss-auth-field-row",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-password",style:{marginBottom:0},children:"Password"}),s.jsx("span",{className:"ss-auth-link",style:{fontSize:"12px"},children:"Forgot?"})]}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{id:"ss-password",className:"ss-auth-input",type:C?"text":"password",autoComplete:"current-password",placeholder:"••••••••",value:j,onChange:L=>b(L.target.value),required:!0}),s.jsx("button",{type:"button",className:"ss-auth-visibility-toggle",onClick:()=>h(!C),children:s.jsx("span",{className:"material-symbols-outlined",children:C?y.visibilityOff:y.visibility})})]})]})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:d,children:[d&&s.jsx("span",{className:"ss-auth-spinner"}),v?"Verify":"Sign in",!d&&s.jsx("span",{className:"material-symbols-outlined",children:y.arrowForward})]})]}),v?s.jsx("div",{className:"ss-auth-footer",children:s.jsx("span",{className:"ss-auth-link",onClick:()=>{N(!1),E(["","","","","",""]),g(null)},children:"Back to sign in"})}):s.jsxs("div",{className:"ss-auth-footer",children:["Don't have an account?"," ",t?s.jsx("span",{className:"ss-auth-link",onClick:t,children:"Sign up"}):a?s.jsx("a",{className:"ss-auth-link",href:a,children:"Sign up"}):s.jsx("span",{className:"ss-auth-link",children:"Sign up"})]})]})})})}function zs({appearance:e,signInUrl:a,onSignIn:t}){const{appearance:o,settings:n}=I(),{signUp:u,isLoading:i,error:c,setError:d}=es(),{signInWithOAuth:l}=K(),g=e??o,[p,x]=r.useState(""),[m,j]=r.useState(""),[b,C]=r.useState(""),[h,v]=r.useState(!1),[N,$]=r.useState(null),P=r.useCallback(async f=>{if(f.preventDefault(),$(null),m!==b){$("Passwords do not match");return}const w=(n==null?void 0:n.passwordMinLength)??8;if(m.length<w){$(`Password must be at least ${w} characters`);return}await u(p,m)},[p,m,b,n,u]),O=r.useCallback(async f=>{await l(f)},[l]),E=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled),S=N||c;return s.jsx(M,{appearance:g,children:s.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%",maxWidth:"520px"},children:[s.jsxs("div",{className:"ss-auth-header",children:[s.jsx("div",{className:"ss-auth-brand-icon-gradient",children:s.jsx("span",{className:"material-symbols-outlined",children:y.autoAwesome})}),s.jsx("h1",{className:"ss-auth-title ss-auth-title-lg",children:"Create your account"}),s.jsx("p",{className:"ss-auth-subtitle",children:"Join the ecosystem"})]}),s.jsx("div",{className:"ss-auth-card",children:s.jsxs("div",{className:"ss-auth-card-body",children:[E&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-auth-oauth-grid",children:[(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>O("google"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:ts}}),"Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>O("github"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:rs}}),"GitHub"]})]}),s.jsx("div",{className:"ss-auth-divider",children:"or sign up with email"})]}),S&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:S})]}),s.jsxs("form",{onSubmit:P,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-signup-email",children:"Email"}),s.jsx("input",{id:"ss-signup-email",className:"ss-auth-input",type:"email",autoComplete:"email",placeholder:"name@company.com",value:p,onChange:f=>x(f.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-signup-password",children:"Password"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{id:"ss-signup-password",className:"ss-auth-input",type:h?"text":"password",autoComplete:"new-password",placeholder:"••••••••",value:m,onChange:f=>{j(f.target.value),$(null)},required:!0}),s.jsx("button",{type:"button",className:"ss-auth-visibility-toggle",onClick:()=>v(!h),children:s.jsx("span",{className:"material-symbols-outlined",children:h?y.visibilityOff:y.visibility})})]})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-signup-confirm",children:"Confirm Password"}),s.jsx("input",{id:"ss-signup-confirm",className:"ss-auth-input",type:"password",autoComplete:"new-password",placeholder:"••••••••",value:b,onChange:f=>{C(f.target.value),$(null)},required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:i,children:[i&&s.jsx("span",{className:"ss-auth-spinner"}),"Sign up",!i&&s.jsx("span",{className:"material-symbols-outlined",children:y.arrowForward})]})]}),s.jsxs("div",{className:"ss-auth-footer",children:["Already have an account?"," ",t?s.jsx("span",{className:"ss-auth-link",onClick:t,children:"Sign in"}):a?s.jsx("a",{className:"ss-auth-link",href:a,children:"Sign in"}):s.jsx("span",{className:"ss-auth-link",children:"Sign in"})]})]})})]})})}const D=320,R=128;function Ps({file:e,onCrop:a,onCancel:t}){const o=r.useRef(null),n=r.useRef(null),[u,i]=r.useState(1),[c,d]=r.useState({x:0,y:0}),[l,g]=r.useState(!1),p=r.useRef({x:0,y:0,ox:0,oy:0}),[x,m]=r.useState(!1);r.useEffect(()=>{const h=new Image,v=URL.createObjectURL(e);return h.onload=()=>{n.current=h,m(!0),d({x:0,y:0}),i(1)},h.src=v,()=>URL.revokeObjectURL(v)},[e]),r.useEffect(()=>{if(!x||!n.current||!o.current)return;const h=o.current.getContext("2d");if(!h)return;const v=n.current;h.clearRect(0,0,D,D),h.fillStyle="#111",h.fillRect(0,0,D,D);const N=Math.max(D/v.width,D/v.height)*u,$=v.width*N,P=v.height*N,O=(D-$)/2+c.x,E=(D-P)/2+c.y;h.save(),h.beginPath(),h.arc(D/2,D/2,R,0,Math.PI*2),h.clip(),h.drawImage(v,O,E,$,P),h.restore(),h.save(),h.fillStyle="rgba(0, 0, 0, 0.6)",h.fillRect(0,0,D,D),h.globalCompositeOperation="destination-out",h.beginPath(),h.arc(D/2,D/2,R,0,Math.PI*2),h.fill(),h.restore(),h.save(),h.beginPath(),h.arc(D/2,D/2,R,0,Math.PI*2),h.clip(),h.drawImage(v,O,E,$,P),h.restore(),h.strokeStyle="rgba(255, 255, 255, 0.4)",h.lineWidth=2,h.beginPath(),h.arc(D/2,D/2,R,0,Math.PI*2),h.stroke()},[u,c,x]);const j=r.useCallback(h=>{g(!0),p.current={x:h.clientX,y:h.clientY,ox:c.x,oy:c.y},h.target.setPointerCapture(h.pointerId)},[c]),b=r.useCallback(h=>{l&&d({x:p.current.ox+(h.clientX-p.current.x),y:p.current.oy+(h.clientY-p.current.y)})},[l]),C=r.useCallback(()=>g(!1),[]);return r.useCallback(()=>{if(!n.current)return;const h=document.createElement("canvas"),v=R*2;h.width=v,h.height=v;const N=h.getContext("2d");if(!N)return;const $=n.current,P=Math.max(D/$.width,D/$.height)*u,O=$.width*P,E=$.height*P,S=(D-O)/2+c.x-(D/2-R),f=(D-E)/2+c.y-(D/2-R);N.beginPath(),N.arc(R,R,R,0,Math.PI*2),N.clip(),N.drawImage($,S,f,O,E),h.toBlob(w=>{w&&a(w)},"image/png")},[u,c,a]),s.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"24px"},children:[s.jsxs("div",{className:"ss-auth-crop-area",children:[s.jsx("canvas",{ref:o,width:D,height:D,style:{cursor:l?"grabbing":"grab",width:"100%",height:"100%"},onPointerDown:j,onPointerMove:b,onPointerUp:C}),s.jsx("div",{className:"ss-auth-crop-size-badge",children:"256 x 256 px"})]}),s.jsxs("div",{className:"ss-auth-zoom-control",style:{width:"100%",maxWidth:"280px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.zoomOut}),s.jsx("input",{type:"range",min:"1",max:"3",step:"0.01",value:u,onChange:h=>i(parseFloat(h.target.value)),className:"ss-auth-zoom-slider"}),s.jsx("span",{className:"material-symbols-outlined",children:y.zoomIn})]})]})}function ns({onUpload:e,onClose:a,isLoading:t}){const[o,n]=r.useState(null),[u,i]=r.useState(!1),[c,d]=r.useState(null),l=r.useRef(null),g=r.useCallback(m=>{if(!m.type.startsWith("image/")){d("Please select an image file");return}if(m.size>5*1024*1024){d("Image must be smaller than 5 MB");return}d(null),n(m)},[]),p=r.useCallback(m=>{m.preventDefault(),i(!1);const j=m.dataTransfer.files[0];j&&g(j)},[g]),x=r.useCallback(async m=>{await e(m)},[e]);return s.jsx("div",{className:"ss-auth-modal-overlay",onClick:m=>{m.target===m.currentTarget&&a()},children:s.jsxs("div",{className:"ss-auth-modal ss-auth-card-wide",children:[s.jsxs("div",{className:"ss-auth-modal-header",children:[s.jsx("h2",{children:"Upload avatar"}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:a,children:s.jsx("span",{className:"material-symbols-outlined",children:y.close})})]}),s.jsxs("div",{className:"ss-auth-modal-body",children:[c&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"24px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:c})]}),s.jsxs("div",{className:"ss-auth-upload-grid",children:[s.jsx("div",{children:o?s.jsx(Ps,{file:o,onCrop:x,onCancel:()=>n(null)}):s.jsxs("div",{className:"ss-auth-crop-area",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"8px",width:"100%",aspectRatio:"1"},children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"48px",opacity:.3},children:y.image}),s.jsx("span",{style:{fontSize:"12px",opacity:.4},children:"No image selected"})]})}),s.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[s.jsxs("div",{className:`ss-auth-dropzone${u?" ss-auth-dropzone-active":""}`,onDragOver:m=>{m.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:p,onClick:()=>{var m;return(m=l.current)==null?void 0:m.click()},style:{minHeight:"180px"},children:[s.jsx("div",{className:"ss-auth-dropzone-icon",children:s.jsx("span",{className:"material-symbols-outlined",children:y.cloudUpload})}),s.jsx("span",{className:"ss-auth-dropzone-title",children:"Drag and drop"}),s.jsxs("span",{className:"ss-auth-dropzone-desc",children:["JPG, PNG or WEBP",s.jsx("br",{}),"Max file size 5 MB"]}),s.jsx("button",{type:"button",className:"ss-auth-dropzone-btn",children:"Choose File"}),s.jsx("input",{ref:l,type:"file",accept:"image/*",style:{display:"none"},onChange:m=>{var j;(j=m.target.files)!=null&&j[0]&&g(m.target.files[0])}})]}),s.jsxs("div",{className:"ss-auth-info-box",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.info}),s.jsx("span",{children:"Your profile photo will be visible to all members of your organization."})]})]})]})]}),s.jsxs("div",{className:"ss-auth-modal-footer",children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:a,children:"Cancel"}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",onClick:()=>{},disabled:!o||t,style:{width:"auto"},children:[t&&s.jsx("span",{className:"ss-auth-spinner"}),"Save Profile",!t&&s.jsx("span",{className:"material-symbols-outlined",children:y.check})]})]})]})})}function os({onClose:e,afterDeleteAccountUrl:a,defaultTab:t="profile"}){const[o,n]=r.useState(t),u=[{key:"profile",label:"Profile",icon:y.person},{key:"organization",label:"Organization",icon:y.corporateFare},{key:"people",label:"People",icon:y.group},{key:"billing",label:"Billing",icon:y.creditCard}];return s.jsxs("div",{className:"ss-auth-settings-page",children:[s.jsxs("div",{className:"ss-auth-settings-header",children:[s.jsx("h2",{children:"Settings"}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:e,children:s.jsx("span",{className:"material-symbols-outlined",children:y.close})})]}),s.jsxs("div",{className:"ss-auth-settings-layout",children:[s.jsx("nav",{className:"ss-auth-settings-nav",children:u.map(i=>s.jsxs("button",{type:"button",className:`ss-auth-settings-nav-item${o===i.key?" ss-auth-settings-nav-item-active":""}`,onClick:()=>n(i.key),children:[s.jsx("span",{className:"material-symbols-outlined",children:i.icon}),i.label]},i.key))}),s.jsxs("div",{className:"ss-auth-settings-content",children:[o==="profile"&&s.jsx(Os,{afterDeleteAccountUrl:a}),o==="organization"&&s.jsx(Es,{}),o==="people"&&s.jsx(Is,{}),o==="billing"&&s.jsx(Fs,{})]})]})]})}function Os({afterDeleteAccountUrl:e}){const{user:a,updateProfile:t,uploadAvatar:o,changePassword:n,isLoading:u,error:i,success:c,setError:d,setSuccess:l}=X(),{signOut:g}=W(),{deleteAccount:p,isLoading:x,error:m,setError:j}=as(),[b,C]=r.useState((a==null?void 0:a.name)??""),[h,v]=r.useState((a==null?void 0:a.avatarUrl)??""),[N,$]=r.useState(!1),[P,O]=r.useState(""),[E,S]=r.useState(""),[f,w]=r.useState(""),[z,B]=r.useState(null),[T,L]=r.useState(!1),[k,F]=r.useState(""),V=r.useCallback(async A=>{A.preventDefault(),d(null),l(null),await t({name:b,avatarUrl:h||void 0})},[b,h,t,d,l]),G=r.useCallback(async A=>{const Y=await o(A);Y&&(v(Y.avatarUrl),$(!1))},[o]),q=r.useCallback(async A=>{if(A.preventDefault(),B(null),d(null),l(null),E!==f){B("Passwords do not match");return}if(E.length<8){B("Password must be at least 8 characters");return}await n(P,E)&&(O(""),S(""),w(""))},[P,E,f,n,d,l]),ms=r.useCallback(async()=>{await p()&&(await g(),e&&(window.location.href=e))},[p,g,e]),fs=(a==null?void 0:a.provider)==="email",bs=k===(a==null?void 0:a.email),ys=((a==null?void 0:a.name)||(a==null?void 0:a.email)||"?").charAt(0).toUpperCase();return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Profile"}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("div",{className:"ss-auth-profile-header",style:{border:"none",background:"none",padding:0,marginBottom:16},children:[s.jsxs("div",{className:"ss-auth-avatar-lg",onClick:()=>$(!0),children:[h?s.jsx("img",{src:h,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"48px",fontWeight:800,opacity:.4},children:ys}),s.jsxs("div",{className:"ss-auth-avatar-overlay",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.camera}),s.jsx("span",{children:"Edit"})]})]}),s.jsxs("div",{className:"ss-auth-profile-info",children:[s.jsxs("h2",{className:"ss-auth-profile-name",children:[(a==null?void 0:a.name)||"Unnamed User",(a==null?void 0:a.emailVerified)&&s.jsxs("span",{className:"ss-auth-badge ss-auth-badge-success",children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"12px",fontVariationSettings:"'FILL' 1"},children:y.verified}),"Verified"]})]}),s.jsx("p",{className:"ss-auth-profile-desc",children:a==null?void 0:a.email})]})]}),i&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:i})]}),c&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.check}),s.jsx("span",{children:c})]}),s.jsxs("form",{onSubmit:V,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Full Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"Your name",value:b,onChange:A=>C(A.target.value)})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Email Address"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"email",value:(a==null?void 0:a.email)??"",readOnly:!0}),s.jsx("span",{className:"ss-auth-visibility-toggle",style:{cursor:"default"},children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"18px"},children:y.lock})})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Auth Provider"}),s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"text",value:(a==null?void 0:a.provider)??"",readOnly:!0})]})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:u,style:{width:"auto"},children:[u&&s.jsx("span",{className:"ss-auth-spinner"}),"Save changes"]})})]})]}),fs&&s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:y.security}),"Security Credentials"]}),z&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:z})]}),s.jsxs("form",{onSubmit:q,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Current Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"••••••••••••",value:P,onChange:A=>O(A.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Min. 8 characters",value:E,onChange:A=>S(A.target.value),required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Confirm New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Repeat new password",value:f,onChange:A=>w(A.target.value),required:!0})]})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsx("button",{type:"submit",className:"ss-auth-btn-ghost",disabled:u,children:"Update Security"})})]})]}),s.jsxs("div",{className:"ss-auth-settings-card ss-auth-settings-danger",children:[s.jsx("h4",{children:"Danger Zone"}),s.jsx("p",{className:"ss-auth-section-desc",style:{marginBottom:"16px"},children:"Deleting your account is permanent. All organizations you own will also be deleted."}),m&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:m})]}),T?s.jsxs("div",{children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Type your email to confirm"}),s.jsx("input",{className:"ss-auth-input",type:"email",placeholder:a==null?void 0:a.email,value:k,onChange:A=>F(A.target.value),autoFocus:!0})]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>{L(!1),F(""),j(null)},children:"Cancel"}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto",background:"linear-gradient(135deg, #ef4444, #dc2626)"},disabled:!bs||x,onClick:ms,children:[x&&s.jsx("span",{className:"ss-auth-spinner"}),"Delete account"]})]})]}):s.jsx("button",{type:"button",className:"ss-auth-btn-outline",style:{borderColor:"currentColor",width:"auto"},onClick:()=>L(!0),children:"Delete my account"})]}),N&&s.jsx(ns,{onUpload:G,onClose:()=>$(!1),isLoading:u})]})}function Es(){const{selectedOrg:e,updateOrg:a,deleteOrg:t,isLoading:o,error:n,setError:u}=H(),[i,c]=r.useState((e==null?void 0:e.name)??""),[d,l]=r.useState(!1),[g,p]=r.useState(!1),[x,m]=r.useState(!1),[j,b]=r.useState("");if(r.useEffect(()=>{e&&c(e.name)},[e]),!e)return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Organization"}),s.jsxs("div",{className:"ss-auth-settings-empty",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.corporateFare}),s.jsx("div",{children:"Select an organization from the user menu to manage its settings."})]})]});const C=async v=>{if(v.preventDefault(),!i.trim())return;l(!0),p(!1);const N=await a(e.id,{name:i.trim()});l(!1),N&&p(!0)},h=async()=>{await t(e.id)&&m(!1)};return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Organization"}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:y.corporateFare}),"General"]}),n&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:n})]}),g&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.check}),s.jsx("span",{children:"Organization updated"})]}),s.jsxs("form",{onSubmit:C,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Organization Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",value:i,onChange:v=>{c(v.target.value),p(!1)}})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Slug"}),s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"text",value:e.slug,readOnly:!0})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:d,style:{width:"auto"},children:[d&&s.jsx("span",{className:"ss-auth-spinner"}),"Save"]})})]})]}),s.jsxs("div",{className:"ss-auth-settings-card ss-auth-settings-danger",children:[s.jsx("h4",{children:"Danger Zone"}),s.jsx("p",{className:"ss-auth-section-desc",style:{marginBottom:"16px"},children:"Deleting this organization is permanent and will remove all members."}),x?s.jsxs("div",{children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Type the organization name to confirm"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:e.name,value:j,onChange:v=>b(v.target.value),autoFocus:!0})]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>{m(!1),b("")},children:"Cancel"}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto",background:"linear-gradient(135deg, #ef4444, #dc2626)"},disabled:j!==e.name||o,onClick:h,children:[o&&s.jsx("span",{className:"ss-auth-spinner"}),"Delete organization"]})]})]}):s.jsx("button",{type:"button",className:"ss-auth-btn-outline",style:{borderColor:"currentColor",width:"auto"},onClick:()=>m(!0),children:"Delete this organization"})]})]})}function Is(){const{selectedOrg:e,members:a,invites:t,isLoading:o,error:n,setError:u,sendInvite:i,refreshInvites:c,revokeInvite:d,updateMemberRole:l,removeMember:g,refreshMembers:p}=H(),[x,m]=r.useState(""),[j,b]=r.useState("member"),[C,h]=r.useState(!1),[v,N]=r.useState(!1),[$,P]=r.useState(null),[O,E]=r.useState(""),[S,f]=r.useState(null);if(r.useEffect(()=>{e&&(p(e.id),c(e.id))},[e,p,c]),!e)return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"People"}),s.jsxs("div",{className:"ss-auth-settings-empty",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.group}),s.jsx("div",{children:"Select an organization from the user menu to manage members."})]})]});const w=async k=>{k.preventDefault(),N(!1),await i(e.id,x,j)&&(m(""),b("member"),N(!0),h(!1),c(e.id))},z=async()=>{if(!$)return;await l(e.id,$.userId,O)&&P(null)},B=async()=>{if(!S)return;await g(e.id,S.userId)&&f(null)},T=async k=>{await d(e.id,k)},L=k=>k==="owner"?"ss-auth-role-badge ss-auth-role-badge-owner":k==="admin"?"ss-auth-role-badge ss-auth-role-badge-admin":"ss-auth-role-badge ss-auth-role-badge-member";return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"People"}),n&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:n})]}),v&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.check}),s.jsx("span",{children:"Invitation sent"})]}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"16px"},children:[s.jsxs("h4",{style:{margin:0},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.group}),"Members"]}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto"},onClick:()=>h(!C),children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"16px"},children:y.add}),"Invite"]})]}),C&&s.jsx("form",{onSubmit:w,style:{marginBottom:"16px",padding:"16px",background:"rgba(0,0,0,0.05)",borderRadius:"8px"},children:s.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[s.jsxs("div",{style:{flex:1},children:[s.jsx("label",{className:"ss-auth-label",children:"Email"}),s.jsx("input",{className:"ss-auth-input",type:"email",placeholder:"member@example.com",value:x,onChange:k=>m(k.target.value),required:!0})]}),s.jsxs("div",{style:{width:"120px"},children:[s.jsx("label",{className:"ss-auth-label",children:"Role"}),s.jsxs("select",{className:"ss-auth-input",value:j,onChange:k=>b(k.target.value),style:{cursor:"pointer"},children:[s.jsx("option",{value:"admin",children:"Admin"}),s.jsx("option",{value:"member",children:"Member"})]})]}),s.jsx("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:o,style:{width:"auto",marginBottom:"0"},children:"Send"})]})}),a.length===0?s.jsx("div",{className:"ss-auth-settings-empty",style:{padding:"20px"},children:s.jsx("div",{children:"No members yet."})}):s.jsxs("table",{className:"ss-auth-settings-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Email"}),s.jsx("th",{children:"Role"}),s.jsx("th",{style:{width:"80px"},children:"Actions"})]})}),s.jsx("tbody",{children:a.map(k=>s.jsxs("tr",{children:[s.jsx("td",{children:k.email}),s.jsx("td",{children:s.jsx("span",{className:L(k.role),children:k.role})}),s.jsx("td",{children:k.role==="owner"?s.jsx("span",{style:{fontSize:"12px",opacity:.4},children:"—"}):s.jsxs("div",{className:"ss-auth-settings-actions",children:[s.jsx("button",{type:"button",className:"ss-auth-icon-btn",title:"Edit role",onClick:()=>{P(k),E(k.role)},children:s.jsx("span",{className:"material-symbols-outlined",children:y.edit})}),s.jsx("button",{type:"button",className:"ss-auth-icon-btn ss-auth-icon-btn-danger",title:"Remove member",onClick:()=>f(k),children:s.jsx("span",{className:"material-symbols-outlined",children:y.personRemove})})]})})]},k.userId))})]})]}),t.length>0&&s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:y.send}),"Pending Invites"]}),s.jsxs("table",{className:"ss-auth-settings-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Email"}),s.jsx("th",{children:"Role"}),s.jsx("th",{style:{width:"80px"},children:"Actions"})]})}),s.jsx("tbody",{children:t.map(k=>s.jsxs("tr",{children:[s.jsx("td",{children:k.email}),s.jsx("td",{children:s.jsx("span",{className:L(k.role),children:k.role})}),s.jsx("td",{children:s.jsx("button",{type:"button",className:"ss-auth-icon-btn ss-auth-icon-btn-danger",title:"Revoke invite",onClick:()=>T(k.id),children:s.jsx("span",{className:"material-symbols-outlined",children:y.close})})})]},k.id))})]})]}),$&&s.jsx("div",{className:"ss-auth-modal-overlay",onClick:k=>{k.target===k.currentTarget&&P(null)},children:s.jsxs("div",{className:"ss-auth-modal",style:{maxWidth:"400px"},children:[s.jsxs("div",{className:"ss-auth-modal-header",children:[s.jsx("h2",{children:"Edit Role"}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:()=>P(null),children:s.jsx("span",{className:"material-symbols-outlined",children:y.close})})]}),s.jsxs("div",{className:"ss-auth-modal-body",children:[s.jsxs("p",{style:{fontSize:"14px",marginBottom:"16px",margin:"0 0 16px 0"},children:["Change role for ",s.jsx("strong",{children:$.email})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Role"}),s.jsxs("select",{className:"ss-auth-input",value:O,onChange:k=>E(k.target.value),style:{cursor:"pointer"},children:[s.jsx("option",{value:"admin",children:"Admin"}),s.jsx("option",{value:"member",children:"Member"})]})]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>P(null),children:"Cancel"}),s.jsx("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto"},onClick:z,children:"Save"})]})]})]})}),S&&s.jsx("div",{className:"ss-auth-modal-overlay",onClick:k=>{k.target===k.currentTarget&&f(null)},children:s.jsxs("div",{className:"ss-auth-modal",style:{maxWidth:"400px"},children:[s.jsxs("div",{className:"ss-auth-modal-header",children:[s.jsx("h2",{children:"Remove Member"}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:()=>f(null),children:s.jsx("span",{className:"material-symbols-outlined",children:y.close})})]}),s.jsxs("div",{className:"ss-auth-modal-body",children:[s.jsxs("p",{style:{fontSize:"14px",margin:"0 0 16px 0"},children:["Are you sure you want to remove ",s.jsx("strong",{children:S.email})," from the organization?"]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>f(null),children:"Cancel"}),s.jsx("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto",background:"linear-gradient(135deg, #ef4444, #dc2626)"},onClick:B,children:"Remove"})]})]})]})})]})}function Fs(){const{selectedOrg:e}=H();return e?s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Billing"}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:y.creditCard}),"Plan & Billing"]}),s.jsx("div",{className:"ss-auth-settings-empty",style:{padding:"20px"},children:s.jsx("div",{children:"No billing plan configured for this organization."})})]})]}):s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Billing"}),s.jsxs("div",{className:"ss-auth-settings-empty",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.creditCard}),s.jsx("div",{children:"Select an organization from the user menu to manage billing."})]})]})}function Bs({appearance:e,afterSignOutUrl:a,afterDeleteAccountUrl:t,showOrgSwitcher:o=!0,onOrgChange:n,onOrgSettingsClick:u}){const{appearance:i}=I(),{user:c,signOut:d}=W(),l=e??i,[g,p]=r.useState(!1),[x,m]=r.useState(!1),[j,b]=r.useState(""),[C,h]=r.useState(null),[v,N]=r.useState(!1),$=r.useRef(null),{orgs:P,selectedOrg:O,selectOrg:E,createOrg:S}=H(),f=r.useCallback(z=>{$.current&&!z.composedPath().includes($.current)&&p(!1)},[]);r.useEffect(()=>{if(g){const z=setTimeout(()=>{document.addEventListener("click",f)},0);return()=>{clearTimeout(z),document.removeEventListener("click",f)}}},[g,f]);const w=r.useCallback(async z=>{z.preventDefault(),h(null),N(!0);const B=j.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");try{const T=await S(j,B);T&&(await E(T.id),n==null||n(T),b(""),p(!1))}catch(T){h(T instanceof Error?T.message:"Failed to create organization")}finally{N(!1)}},[j,S,E,n]);return c?s.jsx(M,{appearance:l,children:s.jsxs("div",{style:{position:"relative",display:"inline-block"},ref:$,children:[s.jsxs("button",{type:"button",className:"ss-auth-user-trigger",onClick:()=>p(!g),"aria-label":"User menu",children:[s.jsx("span",{className:"ss-auth-avatar-trigger",children:c.avatarUrl?s.jsx("img",{src:c.avatarUrl,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"16px",fontWeight:700},children:(c.name||c.email).charAt(0).toUpperCase()})}),O&&s.jsx("span",{className:"ss-auth-trigger-org-name",children:O.name})]}),g&&s.jsxs("div",{className:"ss-auth-dropdown ss-auth-glass-panel",style:{minWidth:"320px"},children:[s.jsxs("div",{className:"ss-auth-dropdown-header",children:[s.jsx("div",{className:"ss-auth-dropdown-avatar",children:c.avatarUrl?s.jsx("img",{src:c.avatarUrl,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"20px",fontWeight:800},children:(c.name||c.email).charAt(0).toUpperCase()})}),s.jsxs("div",{children:[c.name&&s.jsx("div",{className:"ss-auth-dropdown-name",children:c.name}),s.jsx("div",{className:"ss-auth-dropdown-email",children:c.email})]})]}),s.jsx("div",{style:{padding:"4px 8px"},children:s.jsxs("button",{type:"button",className:"ss-auth-dropdown-action",onClick:()=>{p(!1),m(!0)},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.settings}),"Settings"]})}),o&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ss-auth-section-label",children:"Organizations"}),s.jsx("div",{style:{padding:"0 8px 4px"},children:P.map(z=>{const B=(O==null?void 0:O.id)===z.id,T=z.name.split(" ").map(L=>L[0]).join("").slice(0,2).toUpperCase();return s.jsxs("button",{type:"button",className:`ss-auth-org-item${B?" ss-auth-org-item-active":""}`,onClick:async()=>{p(!1),await E(z.id),n==null||n(z)},children:[s.jsxs("div",{className:"ss-auth-org-item-inner",children:[s.jsx("div",{className:`ss-auth-org-avatar${B?"":" ss-auth-org-avatar-inactive"}`,children:T}),s.jsx("span",{style:{fontFamily:"'Manrope', sans-serif",letterSpacing:"-0.01em"},children:z.name}),z.planName&&s.jsx("span",{className:"ss-auth-plan-badge",children:z.planName})]}),B&&s.jsx("span",{className:"material-symbols-outlined ss-auth-org-check",style:{fontSize:"18px"},children:y.checkCircle})]},z.id)})}),s.jsxs("div",{className:"ss-auth-inline-create",children:[C&&s.jsx("div",{className:"ss-auth-error",style:{marginBottom:"8px",fontSize:"12px"},children:s.jsx("span",{children:C})}),s.jsx("form",{onSubmit:w,children:s.jsxs("div",{className:"ss-auth-inline-create-input",children:[s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"New organization name",value:j,onChange:z=>b(z.target.value),required:!0,style:{fontSize:"13px",padding:"10px 40px 10px 12px"}}),s.jsx("button",{type:"submit",className:"ss-auth-inline-create-btn",disabled:v||!j.trim(),children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"20px"},children:y.add})})]})})]}),O&&u&&s.jsx("div",{style:{padding:"0 8px 4px"},children:s.jsxs("button",{type:"button",className:"ss-auth-dropdown-action",onClick:()=>{p(!1),u(O)},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.corporateFare}),"Org settings"]})})]}),s.jsx("div",{className:"ss-auth-signout-section",style:{padding:"8px"},children:s.jsxs("button",{type:"button",className:"ss-auth-dropdown-action",onClick:async()=>{p(!1),await d(),a&&(window.location.href=a)},style:{color:"inherit"},children:[s.jsx("span",{className:"material-symbols-outlined",style:{color:"inherit"},children:y.logout}),"Sign out"]})})]}),x&&s.jsx(os,{onClose:()=>m(!1),afterDeleteAccountUrl:t})]})}):null}function Ls({appearance:e}){const{appearance:a}=I(),{user:t,signOut:o}=W(),{updateProfile:n,uploadAvatar:u,changePassword:i,isLoading:c,error:d,success:l,setError:g,setSuccess:p}=X(),x=e??a,[m,j]=r.useState((t==null?void 0:t.name)??""),[b,C]=r.useState((t==null?void 0:t.avatarUrl)??""),[h,v]=r.useState(!1),[N,$]=r.useState(""),[P,O]=r.useState(""),[E,S]=r.useState(""),[f,w]=r.useState(null),z=r.useCallback(async F=>{F.preventDefault(),g(null),p(null),await n({name:m,avatarUrl:b||void 0})},[m,b,n,g,p]),B=r.useCallback(async F=>{const V=await u(F);V&&(C(V.avatarUrl),v(!1))},[u]),T=r.useCallback(async F=>{if(F.preventDefault(),w(null),g(null),p(null),P!==E){w("Passwords do not match");return}if(P.length<8){w("Password must be at least 8 characters");return}await i(N,P)&&($(""),O(""),S(""))},[N,P,E,i,g,p]);if(!t)return null;const L=t.provider==="email",k=(t.name||t.email).charAt(0).toUpperCase();return s.jsx(M,{appearance:x,children:s.jsxs("div",{className:"ss-auth-card",style:{maxWidth:"640px"},children:[s.jsxs("div",{className:"ss-auth-profile-header",children:[s.jsxs("div",{className:"ss-auth-avatar-lg",onClick:()=>v(!0),children:[b?s.jsx("img",{src:b,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"48px",fontWeight:800,opacity:.4},children:k}),s.jsxs("div",{className:"ss-auth-avatar-overlay",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.camera}),s.jsx("span",{children:"Edit"})]})]}),s.jsxs("div",{className:"ss-auth-profile-info",children:[s.jsxs("h2",{className:"ss-auth-profile-name",children:[t.name||"Unnamed User",t.emailVerified&&s.jsxs("span",{className:"ss-auth-badge ss-auth-badge-success",children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"12px",fontVariationSettings:"'FILL' 1"},children:y.verified}),"Verified"]})]}),s.jsx("p",{className:"ss-auth-profile-desc",children:t.email})]})]}),s.jsxs("div",{className:"ss-auth-card-body",children:[d&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:d})]}),l&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.check}),s.jsx("span",{children:l})]}),s.jsxs("form",{onSubmit:z,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Full Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"Your name",value:m,onChange:F=>j(F.target.value)})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Email Address"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"email",value:t.email,readOnly:!0}),s.jsx("span",{className:"ss-auth-visibility-toggle",style:{cursor:"default"},children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"18px"},children:y.lock})})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Auth Provider"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"text",value:t.provider,readOnly:!0}),s.jsx("span",{className:"ss-auth-visibility-toggle",style:{cursor:"default"},children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"18px"},children:y.cloudDone})})]})]})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:c,style:{width:"auto"},children:[c&&s.jsx("span",{className:"ss-auth-spinner"}),"Save changes"]})})]}),L&&s.jsxs("div",{className:"ss-auth-section",children:[s.jsxs("div",{className:"ss-auth-section-title",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.security}),"Security Credentials"]}),s.jsx("p",{className:"ss-auth-section-desc",style:{marginBottom:"24px"},children:"Update your password to keep your account secure."}),f&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.errorOutline}),s.jsx("span",{children:f})]}),s.jsxs("form",{onSubmit:T,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Current Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"••••••••••••",value:N,onChange:F=>$(F.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Min. 8 characters",value:P,onChange:F=>O(F.target.value),required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Confirm New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Repeat new password",value:E,onChange:F=>S(F.target.value),required:!0})]})]}),s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:y.info}),s.jsx("span",{children:"Password must be at least 8 characters long."})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsx("button",{type:"submit",className:"ss-auth-btn-ghost",disabled:c,children:"Update Security"})})]})]}),s.jsx("div",{className:"ss-auth-section",style:{borderTop:"none",paddingTop:0,marginTop:"24px"},children:s.jsx("div",{className:"ss-auth-signout-section",style:{borderRadius:"12px",padding:"16px 20px"},children:s.jsxs("div",{className:"ss-auth-signout-row",children:[s.jsxs("div",{className:"ss-auth-signout-info",children:[s.jsx("div",{className:"ss-auth-signout-icon",children:s.jsx("span",{className:"material-symbols-outlined",children:y.logout})}),s.jsxs("div",{children:[s.jsx("div",{className:"ss-auth-signout-title",children:"End Session"}),s.jsx("div",{className:"ss-auth-signout-desc",children:"Terminate your active session"})]})]}),s.jsx("button",{type:"button",className:"ss-auth-btn-outline",onClick:()=>o(),style:{width:"auto",flexShrink:0},children:"Sign out"})]})})})]}),h&&s.jsx(ns,{onUpload:B,onClose:()=>v(!1),isLoading:c})]})})}function Ds({appearance:e,onOrgChange:a}){const{appearance:t}=I(),{orgs:o,selectedOrg:n,selectOrg:u,createOrg:i,isLoading:c}=H(),d=e??t,[l,g]=r.useState(!1),[p,x]=r.useState(""),[m,j]=r.useState(""),[b,C]=r.useState(null),[h,v]=r.useState(!1),N=r.useRef(null),$=r.useCallback(f=>{N.current&&!f.composedPath().includes(N.current)&&g(!1)},[]);r.useEffect(()=>{if(l){const f=setTimeout(()=>{document.addEventListener("click",$)},0);return()=>{clearTimeout(f),document.removeEventListener("click",$)}}},[l,$]);const P=r.useCallback(f=>{x(f),j(f.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},[]),O=r.useCallback(async f=>{f.preventDefault(),C(null),v(!0);try{const w=await i(p,m);w&&(await u(w.id),a==null||a(w),x(""),j(""),g(!1))}catch(w){C(w instanceof Error?w.message:"Failed to create organization")}finally{v(!1)}},[p,m,i,u,a]);if(c)return null;const E=(n==null?void 0:n.name)??(o.length===0?"No organization":"Select organization"),S=n?n.name.split(" ").map(f=>f[0]).join("").slice(0,2).toUpperCase():"--";return s.jsx(M,{appearance:d,children:s.jsxs("div",{style:{position:"relative",display:"inline-block",width:"100%",maxWidth:"360px"},ref:N,children:[s.jsxs("button",{type:"button",className:"ss-auth-org-trigger",onClick:()=>g(!l),children:[s.jsxs("div",{className:"ss-auth-org-trigger-inner",children:[s.jsx("div",{className:"ss-auth-org-avatar",children:S}),s.jsxs("div",{style:{textAlign:"left"},children:[s.jsx("div",{className:"ss-auth-org-trigger-label",children:"Current Organization"}),s.jsx("div",{className:"ss-auth-org-trigger-name",children:E})]})]}),s.jsx("span",{className:"material-symbols-outlined",children:y.unfoldMore})]}),l&&s.jsxs("div",{className:"ss-auth-dropdown ss-auth-dropdown-left ss-auth-glass-panel",style:{width:"100%"},children:[s.jsx("div",{className:"ss-auth-section-label",children:"Your Organizations"}),s.jsx("div",{style:{padding:"0 8px 4px"},children:o.map(f=>{const w=(n==null?void 0:n.id)===f.id,z=f.name.split(" ").map(B=>B[0]).join("").slice(0,2).toUpperCase();return s.jsxs("button",{type:"button",className:`ss-auth-org-item${w?" ss-auth-org-item-active":""}`,onClick:async()=>{g(!1),await u(f.id),a==null||a(f)},children:[s.jsxs("div",{className:"ss-auth-org-item-inner",children:[s.jsx("div",{className:`ss-auth-org-avatar${w?"":" ss-auth-org-avatar-inactive"}`,children:z}),s.jsx("span",{style:{fontFamily:"'Manrope', sans-serif",letterSpacing:"-0.01em"},children:f.name})]}),w&&s.jsx("span",{className:"material-symbols-outlined ss-auth-org-check",style:{fontSize:"18px"},children:y.checkCircle})]},f.id)})}),s.jsxs("div",{className:"ss-auth-org-create",children:[s.jsxs("div",{className:"ss-auth-org-create-header",children:[s.jsx("span",{className:"material-symbols-outlined",children:y.addCircle}),s.jsx("span",{children:"Create organization"})]}),b&&s.jsx("div",{className:"ss-auth-error",style:{marginBottom:"12px",fontSize:"12px"},children:s.jsx("span",{children:b})}),s.jsxs("form",{onSubmit:O,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",style:{fontSize:"10px"},children:"Org Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"e.g. Nexus Dynamics",value:p,onChange:f=>P(f.target.value),required:!0,style:{fontSize:"13px",padding:"10px 12px"}})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",style:{fontSize:"10px"},children:"Workspace Slug"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("span",{className:"ss-auth-org-slug-prefix",children:"/"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"nexus-dynamics",value:m,onChange:f=>j(f.target.value),required:!0,style:{fontSize:"13px",padding:"10px 12px 10px 22px"}})]})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:h||!p.trim(),style:{marginTop:"8px"},children:[h&&s.jsx("span",{className:"ss-auth-spinner"}),"Initialize Organization"]})]})]})]})]})})}function Ts(e,a="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:a,minimumFractionDigits:e%100===0?0:2}).format(e/100)}function As({plans:e,currentPlanId:a,onSelectPlan:t,interval:o,appearance:n}){const{appearance:u}=I(),i=n??u,c=o?e.filter(d=>d.interval===o||d.isFree):e;return s.jsx(M,{appearance:i,children:s.jsx("div",{className:"ss-pricing-grid",children:c.map(d=>{const l=d.id===a;return s.jsxs("div",{className:`ss-pricing-card ${l?"ss-pricing-card-current":""}`,children:[s.jsxs("div",{className:"ss-pricing-header",children:[s.jsx("h3",{className:"ss-pricing-name",children:d.name}),d.trialDays>0&&s.jsxs("span",{className:"ss-badge ss-badge-trialing",children:[d.trialDays,"-day trial"]}),d.isFree&&s.jsx("span",{className:"ss-badge ss-badge-active",children:"Free"})]}),s.jsx("div",{className:"ss-pricing-price",children:d.isFree?s.jsx("span",{className:"ss-pricing-amount",children:"Free"}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ss-pricing-amount",children:Ts(d.amountCents,d.currency)}),s.jsxs("span",{className:"ss-pricing-interval",children:["/",d.interval]})]})}),d.description&&s.jsx("p",{className:"ss-pricing-desc",children:d.description}),d.features.length>0&&s.jsx("ul",{className:"ss-pricing-features",children:d.features.map((g,p)=>s.jsxs("li",{className:"ss-pricing-feature",children:[s.jsx("span",{className:"ss-check",children:"✓"})," ",g]},p))}),s.jsx("button",{type:"button",className:`ss-btn ${l?"ss-btn-current":"ss-btn-primary"}`,disabled:l,onClick:()=>t(d.id),children:l?"Current plan":"Select plan"})]},d.id)})})})}function Ms(){const{client:e}=I();return{billing:e.billing}}function _(e){const{client:a}=I();return r.useMemo(()=>{if(e){const t=new U.Transport("https://api.saas-support.com/v1",{type:"portalToken",token:e});return new U.BillingClient(t)}return a.billing},[a,e])}function is(e,a){const t=_(a),[o,n]=r.useState(null),[u,i]=r.useState(!0),[c,d]=r.useState(null),l=r.useCallback(async()=>{i(!0),d(null);try{const g=await t.getCustomer(e);n(g)}catch(g){d(g instanceof Error?g.message:"Failed to load subscription")}finally{i(!1)}},[t,e]);return r.useEffect(()=>{l()},[l]),{customer:o,isLoading:u,error:c,refresh:l}}function ls(e,a){const t=_(a),[o,n]=r.useState([]),[u,i]=r.useState(!0),[c,d]=r.useState(null),l=r.useCallback(async()=>{i(!0),d(null);try{const g=await t.getInvoices(e);n(g)}catch(g){d(g instanceof Error?g.message:"Failed to load invoices")}finally{i(!1)}},[t,e]);return r.useEffect(()=>{l()},[l]),{invoices:o,isLoading:u,error:c,refresh:l}}function cs(e,a){const t=_(a),[o,n]=r.useState([]),[u,i]=r.useState(!0),[c,d]=r.useState(null),l=r.useCallback(async()=>{i(!0),d(null);try{const g=await t.getCurrentUsage(e);n(g)}catch(g){d(g instanceof Error?g.message:"Failed to load usage")}finally{i(!1)}},[t,e]);return r.useEffect(()=>{l()},[l]),{usage:o,isLoading:u,error:c,refresh:l}}const Us={active:"ss-badge-active"};function ds({customerId:e,portalToken:a,onChangePlan:t,onCancel:o,appearance:n}){const{appearance:u}=I(),{customer:i,isLoading:c,error:d}=is(e,a),l=n??u;return s.jsx(M,{appearance:l,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Subscription"}),c&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),i&&!c&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Customer"}),s.jsx("input",{className:"ss-input",value:i.name||i.email,disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Status"}),s.jsx("div",{children:s.jsx("span",{className:`ss-badge ${Us.active}`,children:"Active"})})]}),s.jsxs("div",{className:"ss-btn-group",children:[t&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-primary",onClick:t,children:"Change plan"}),o&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:o,children:"Cancel subscription"})]})]})]})})}const Rs={paid:"ss-badge-active",open:"ss-badge-trialing",draft:"ss-badge-paused",void:"ss-badge-canceled",uncollectible:"ss-badge-past-due"};function Vs(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Hs(e){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(e/100)}function us({customerId:e,portalToken:a,appearance:t}){const{appearance:o}=I(),{invoices:n,isLoading:u,error:i}=ls(e,a),c=t??o,d=[...n].sort((l,g)=>new Date(g.createdAt).getTime()-new Date(l.createdAt).getTime());return s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Invoices"}),u&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),i&&s.jsx("div",{className:"ss-global-error",children:i}),!u&&d.length===0&&s.jsx("p",{className:"ss-empty",children:"No invoices yet."}),!u&&d.length>0&&s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{className:"ss-th",children:"Date"}),s.jsx("th",{className:"ss-th",children:"Amount"}),s.jsx("th",{className:"ss-th",children:"Status"}),s.jsx("th",{className:"ss-th",children:"PDF"})]})}),s.jsx("tbody",{children:d.map(l=>s.jsxs("tr",{className:"ss-tr",children:[s.jsx("td",{className:"ss-td",children:Vs(l.createdAt)}),s.jsx("td",{className:"ss-td",children:Hs(l.amountCents)}),s.jsx("td",{className:"ss-td",children:s.jsx("span",{className:`ss-badge ${Rs[l.status]||""}`,children:l.status})}),s.jsx("td",{className:"ss-td",children:l.pdfUrl?s.jsx("a",{className:"ss-link",href:l.pdfUrl,target:"_blank",rel:"noopener noreferrer",children:"Download"}):"—"})]},l.id))})]})]})})}function ps({customerId:e,limits:a,portalToken:t,appearance:o}){const{appearance:n}=I(),{usage:u,isLoading:i,error:c}=cs(e,t),d=o??n;return s.jsx(M,{appearance:d,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Usage"}),i&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),c&&s.jsx("div",{className:"ss-global-error",children:c}),!i&&u.length===0&&s.jsx("p",{className:"ss-empty",children:"No usage data."}),!i&&u.map(l=>{const g=a==null?void 0:a[l.metric],p=g?Math.min(100,l.total/g*100):null;return s.jsxs("div",{className:"ss-usage-item",children:[s.jsxs("div",{className:"ss-usage-header",children:[s.jsx("span",{className:"ss-usage-metric",children:l.metric}),s.jsxs("span",{className:"ss-usage-value",children:[l.total.toLocaleString(),g?` / ${g.toLocaleString()}`:""]})]}),p!==null&&s.jsx("div",{className:"ss-progress-bar",children:s.jsx("div",{className:`ss-progress-fill ${p>90?"ss-progress-danger":""}`,style:{width:`${p}%`}})})]},l.metric)})]})})}function qs({customerId:e,portalToken:a,limits:t,onChangePlan:o,onCancel:n,appearance:u}){const{appearance:i}=I(),c=u??i,[d,l]=r.useState("subscription"),g=[{id:"subscription",label:"Subscription"},{id:"invoices",label:"Invoices"},{id:"usage",label:"Usage"}];return s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Billing"}),s.jsx("div",{className:"ss-tab-group",children:g.map(p=>s.jsx("button",{type:"button",className:`ss-tab ${d===p.id?"ss-tab-active":""}`,onClick:()=>l(p.id),children:p.label},p.id))}),s.jsxs("div",{className:"ss-tab-content",children:[d==="subscription"&&s.jsx(ds,{customerId:e,portalToken:a,onChangePlan:o,onCancel:n}),d==="invoices"&&s.jsx(us,{customerId:e,portalToken:a}),d==="usage"&&s.jsx(ps,{customerId:e,portalToken:a,limits:t})]})]})})}function Ws({customerId:e,portalToken:a,onApplied:t,appearance:o}){const{appearance:n}=I(),u=_(a),i=o??n,[c,d]=r.useState(""),[l,g]=r.useState(!1),[p,x]=r.useState(null),[m,j]=r.useState(null),b=r.useCallback(async C=>{if(C.preventDefault(),!!c.trim()){g(!0),x(null),j(null);try{const h=await u.applyCoupon(e,c.trim());j(`Coupon applied! ${h.discountType==="percent"?`${h.amount}% off`:`$${(h.amount/100).toFixed(2)} off`}`),d(""),t==null||t(h)}catch(h){x(h instanceof Error?h.message:"Invalid coupon code")}finally{g(!1)}}},[u,e,c,t]);return s.jsx(M,{appearance:i,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Apply coupon"}),p&&s.jsx("div",{className:"ss-global-error",children:p}),m&&s.jsx("div",{className:"ss-success-msg",children:m}),s.jsxs("form",{onSubmit:b,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-coupon-code",children:"Coupon code"}),s.jsx("input",{id:"ss-coupon-code",className:"ss-input",type:"text",placeholder:"Enter coupon code",value:c,onChange:C=>d(C.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:l||!c.trim(),children:[l&&s.jsx("span",{className:"ss-spinner"}),"Apply"]})]})]})})}function _s(){const{client:e}=I();return{report:e.report}}function ss(){const{client:e}=I(),[a,t]=r.useState(null),[o,n]=r.useState(!1),[u,i]=r.useState(null),c=r.useCallback(async d=>{n(!0),i(null);try{const l=await e.report.executeQuery(d);return t(l),l}catch(l){return i(l instanceof Error?l.message:"Query failed"),null}finally{n(!1)}},[e]);return{result:a,execute:c,isLoading:o,error:u}}function hs(e){const{client:a}=I(),[t,o]=r.useState(null),[n,u]=r.useState(!0),[i,c]=r.useState(null),d=r.useCallback(async()=>{u(!0),c(null);try{const l=await a.report.listQueries(e);o(l)}catch(l){c(l instanceof Error?l.message:"Failed to load queries")}finally{u(!1)}},[a,e]);return r.useEffect(()=>{d()},[d]),{queries:(t==null?void 0:t.data)??[],meta:t==null?void 0:t.meta,isLoading:n,error:i,refresh:d}}function Gs(e){const{client:a}=I(),[t,o]=r.useState(null),[n,u]=r.useState(!0),[i,c]=r.useState(null),d=r.useCallback(async()=>{u(!0),c(null);try{const l=await a.report.getDashboard(e);o(l)}catch(l){c(l instanceof Error?l.message:"Failed to load dashboard")}finally{u(!1)}},[a,e]);return r.useEffect(()=>{d()},[d]),{dashboard:t,isLoading:n,error:i,refresh:d}}function Ys(e,a,t="https://api.saas-support.com/v1"){const o=r.useMemo(()=>{const p=new U.Transport(t,{type:"embedToken",token:e});return new U.ReportClient(p)},[e,t]),[n,u]=r.useState(null),[i,c]=r.useState(!0),[d,l]=r.useState(null),g=r.useCallback(async()=>{c(!0),l(null);try{const p=await o.getDashboard(a);u(p)}catch(p){l(p instanceof Error?p.message:"Failed to load dashboard")}finally{c(!1)}},[o,a]);return r.useEffect(()=>{g()},[g]),{dashboard:n,reportClient:o,isLoading:i,error:d,refresh:g}}function Qs({onResult:e,mode:a="both",placeholder:t,appearance:o}){const{appearance:n}=I(),{execute:u,isLoading:i,error:c}=ss(),d=o??n,[l,g]=r.useState(""),[p,x]=r.useState(a==="sql"?"sql":"nl"),m=r.useCallback(async j=>{if(j.preventDefault(),!l.trim())return;const C=await u(p==="sql"?{sql:l}:{naturalLanguage:l});C&&(e==null||e(C))},[l,p,u,e]);return s.jsx(M,{appearance:d,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[a==="both"&&s.jsxs("div",{className:"ss-tab-group ss-tab-group-sm",children:[s.jsx("button",{type:"button",className:`ss-tab ${p==="nl"?"ss-tab-active":""}`,onClick:()=>x("nl"),children:"Natural Language"}),s.jsx("button",{type:"button",className:`ss-tab ${p==="sql"?"ss-tab-active":""}`,onClick:()=>x("sql"),children:"SQL"})]}),c&&s.jsx("div",{className:"ss-global-error",children:c}),s.jsxs("form",{onSubmit:m,children:[s.jsx("div",{className:"ss-field",children:s.jsx("textarea",{className:"ss-input ss-query-textarea",placeholder:t??(p==="sql"?"SELECT ...":"Ask a question about your data..."),value:l,onChange:j=>g(j.target.value),rows:3})}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:i||!l.trim(),children:[i&&s.jsx("span",{className:"ss-spinner"}),"Run query"]})]})]})})}function xs({columns:e,rows:a,sortable:t=!0,maxRows:o,appearance:n}){const{appearance:u}=I(),i=n??u,[c,d]=r.useState(null),[l,g]=r.useState("asc"),p=r.useMemo(()=>c?[...a].sort((b,C)=>{const h=b[c],v=C[c];if(h==null&&v==null)return 0;if(h==null)return 1;if(v==null)return-1;if(typeof h=="number"&&typeof v=="number")return l==="asc"?h-v:v-h;const N=String(h),$=String(v);return l==="asc"?N.localeCompare($):$.localeCompare(N)}):a,[a,c,l]),x=o?p.slice(0,o):p,m=b=>{t&&(c===b?g(C=>C==="asc"?"desc":"asc"):(d(b),g("asc")))};function j(b){return b==null?"":typeof b=="object"?JSON.stringify(b):String(b)}return s.jsx(M,{appearance:i,children:s.jsxs("div",{className:"ss-table-container",children:[s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsx("tr",{children:e.map(b=>s.jsxs("th",{className:`ss-th ${t?"ss-th-sortable":""} ${c===b?l==="asc"?"ss-sorted-asc":"ss-sorted-desc":""}`,onClick:()=>m(b),children:[b,c===b&&s.jsx("span",{className:"ss-sort-indicator",children:l==="asc"?" ▲":" ▼"})]},b))})}),s.jsx("tbody",{children:x.map((b,C)=>s.jsx("tr",{className:"ss-tr",children:e.map(h=>s.jsx("td",{className:"ss-td",children:j(b[h])},h))},C))})]}),o&&a.length>o&&s.jsxs("div",{className:"ss-table-footer",children:["Showing ",o," of ",a.length," rows"]})]})})}function Js(e,a="#6366f1"){const t=parseInt(a.replace("#","").slice(0,2),16),o=[];for(let n=0;n<e;n++){const u=(t+n*Math.floor(360/Math.max(e,1)))%360;o.push(`hsl(${u}, 65%, 55%)`)}return o}function Zs({labels:e,values:a,w:t,h:o,colors:n}){const u=Math.max(...a,1),i=40,c=t-i*2,d=o-i*2,l=Math.max(1,c/e.length-4);return s.jsxs("g",{children:[s.jsx("line",{x1:i,y1:o-i,x2:t-i,y2:o-i,stroke:"#ccc",strokeWidth:1}),a.map((g,p)=>{const x=g/u*d,m=i+c/e.length*p+2,j=o-i-x;return s.jsxs("g",{children:[s.jsx("rect",{x:m,y:j,width:l,height:x,fill:n[p%n.length],rx:2}),s.jsx("text",{x:m+l/2,y:o-i+14,textAnchor:"middle",fontSize:10,fill:"#666",children:e[p].length>8?e[p].slice(0,8)+"...":e[p]})]},p)})]})}function Ks({labels:e,values:a,w:t,h:o,colors:n}){const u=Math.max(...a,1),i=40,c=t-i*2,d=o-i*2,l=e.length>1?c/(e.length-1):0,g=a.map((p,x)=>{const m=i+l*x,j=o-i-p/u*d;return`${m},${j}`});return s.jsxs("g",{children:[[.25,.5,.75,1].map(p=>{const x=o-i-p*d;return s.jsx("line",{x1:i,y1:x,x2:t-i,y2:x,stroke:"#eee",strokeWidth:1},p)}),s.jsx("polyline",{points:g.join(" "),fill:"none",stroke:n[0],strokeWidth:2}),a.map((p,x)=>{const m=i+l*x,j=o-i-p/u*d;return s.jsx("circle",{cx:m,cy:j,r:4,fill:n[0]},x)})]})}function Xs({labels:e,values:a,w:t,h:o,colors:n}){const u=a.reduce((x,m)=>x+m,0)||1,i=t/2,c=o/2-20,d=Math.min(t,o)/2-40,l=2*Math.PI*d;let g=0;const p=a.map((x,m)=>{const j=x/u,b=j*l,C={dash:b,offset:g,color:n[m%n.length],label:e[m],pct:j};return g+=b,C});return s.jsxs("g",{children:[p.map((x,m)=>s.jsx("circle",{cx:i,cy:c,r:d,fill:"none",stroke:x.color,strokeWidth:d*.6,strokeDasharray:`${x.dash} ${l-x.dash}`,strokeDashoffset:-x.offset,transform:`rotate(-90 ${i} ${c})`},m)),s.jsx("g",{transform:`translate(${i-e.length*30}, ${o-20})`,children:p.slice(0,6).map((x,m)=>s.jsxs("g",{transform:`translate(${m*60}, 0)`,children:[s.jsx("rect",{width:10,height:10,fill:x.color,rx:2}),s.jsx("text",{x:14,y:9,fontSize:9,fill:"#666",children:x.label.length>6?x.label.slice(0,6)+"..":x.label})]},m))})]})}function gs({type:e,data:a,title:t,width:o=400,height:n=300,appearance:u}){const{appearance:i}=I(),c=u??i,d=r.useMemo(()=>Js(a.labels.length),[a.labels.length]);return s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-chart-container",children:[t&&s.jsx("h3",{className:"ss-chart-title",children:t}),s.jsxs("svg",{viewBox:`0 0 ${o} ${n}`,width:"100%",style:{maxWidth:o},children:[e==="bar"&&s.jsx(Zs,{labels:a.labels,values:a.values,w:o,h:n,colors:d}),e==="line"&&s.jsx(Ks,{labels:a.labels,values:a.values,w:o,h:n,colors:d}),e==="pie"&&s.jsx(Xs,{labels:a.labels,values:a.values,w:o,h:n,colors:d})]})]})})}function se({dashboardId:e,embedToken:a,baseUrl:t,refreshInterval:o,appearance:n}){const u=I(),i=n??(u==null?void 0:u.appearance),c=r.useMemo(()=>{if(a){const h=t??"https://api.saas-support.com/v1",v=new U.Transport(h,{type:"embedToken",token:a});return new U.ReportClient(v)}return u.client.report},[a,t,u]),[d,l]=r.useState([]),[g,p]=r.useState({}),[x,m]=r.useState(!0),[j,b]=r.useState(null),C=r.useCallback(async()=>{m(!0),b(null);try{const h=await c.getDashboard(e),v=JSON.parse(h.layoutJson||"[]");l(v);const N={};for(const $ of v)try{const P=await c.listQueries({search:$.queryId,perPage:1});if(P.data.length>0&&P.data[0].generatedSql){const O=await c.executeQuery({sql:P.data[0].generatedSql});N[$.queryId]=O}}catch{}p(N)}catch(h){b(h instanceof Error?h.message:"Failed to load dashboard")}finally{m(!1)}},[c,e]);return r.useEffect(()=>{C()},[C]),r.useEffect(()=>{if(!o||o<=0)return;const h=setInterval(C,o*1e3);return()=>clearInterval(h)},[o,C]),s.jsx(M,{appearance:i,children:s.jsxs("div",{className:"ss-dashboard-grid",children:[x&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading dashboard..."]}),j&&s.jsx("div",{className:"ss-global-error",children:j}),!x&&d.map((h,v)=>{const N=g[h.queryId];if(!N)return null;const $=N.columns.length>=2?{labels:N.rows.map(P=>String(P[N.columns[0]]??"")),values:N.rows.map(P=>Number(P[N.columns[1]]??0))}:{labels:[],values:[]};return s.jsxs("div",{className:"ss-widget",children:[h.title&&s.jsx("h4",{className:"ss-widget-header",children:h.title}),h.chartType==="table"?s.jsx(xs,{columns:N.columns,rows:N.rows,maxRows:50}):s.jsx(gs,{type:h.chartType||"bar",data:$,width:h.w,height:h.h})]},v)})]})})}function ee(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function ae({onSelectQuery:e,onRunQuery:a,appearance:t}){const{appearance:o}=I(),{queries:n,isLoading:u,error:i}=hs(),{execute:c,isLoading:d}=ss(),l=t??o,g=r.useCallback(async p=>{if(!p.generatedSql)return;const x=await c({sql:p.generatedSql});x&&(a==null||a(x))},[c,a]);return s.jsx(M,{appearance:l,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Saved Queries"}),u&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),i&&s.jsx("div",{className:"ss-global-error",children:i}),!u&&n.length===0&&s.jsx("p",{className:"ss-empty",children:"No saved queries."}),!u&&n.map(p=>s.jsxs("div",{className:"ss-saved-query-card",onClick:()=>e==null?void 0:e(p),children:[s.jsxs("div",{className:"ss-saved-query-header",children:[s.jsx("span",{className:"ss-saved-query-name",children:p.name}),p.chartType&&s.jsx("span",{className:"ss-badge",children:p.chartType})]}),p.naturalLanguage&&s.jsx("p",{className:"ss-saved-query-desc",children:p.naturalLanguage}),s.jsxs("div",{className:"ss-saved-query-footer",children:[s.jsx("span",{className:"ss-saved-query-date",children:ee(p.createdAt)}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:d||!p.generatedSql,onClick:x=>{x.stopPropagation(),g(p)},children:d?s.jsx("span",{className:"ss-spinner"}):"Run"})]})]},p.id))]})})}function te({embedToken:e,dashboardId:a,baseUrl:t="https://api.saas-support.com/v1",refreshInterval:o,appearance:n}){const u=r.useMemo(()=>{const b=new U.Transport(t,{type:"embedToken",token:e});return new U.ReportClient(b)},[e,t]),[i,c]=r.useState([]),[d,l]=r.useState(!0),[g,p]=r.useState(null),x=r.useMemo(()=>Q(n),[n]),m=r.useMemo(()=>J(x),[x]),j=r.useCallback(async()=>{l(!0),p(null);try{const b=await u.getDashboard(a),C=JSON.parse(b.layoutJson||"[]"),h=await Promise.all(C.map(async v=>{try{const N=await u.listQueries({search:v.queryId,perPage:1});if(N.data.length>0&&N.data[0].generatedSql){const $=await u.executeQuery({sql:N.data[0].generatedSql});return{...v,result:$}}}catch{}return v}));c(h)}catch(b){p(b instanceof Error?b.message:"Failed to load dashboard")}finally{l(!1)}},[u,a]);return r.useEffect(()=>{j()},[j]),r.useEffect(()=>{if(!o||o<=0)return;const b=setInterval(j,o*1e3);return()=>clearInterval(b)},[o,j]),s.jsx("div",{ref:b=>{if(!b||b.shadowRoot)return;const C=b.attachShadow({mode:"open"}),h=document.createElement("style");h.textContent=m,C.appendChild(h);const v=document.createElement("div");C.appendChild(v)},style:{display:"contents"},children:s.jsxs("div",{className:"ss-dashboard-grid",children:[d&&s.jsx("div",{className:"ss-loading",children:"Loading dashboard..."}),g&&s.jsx("div",{className:"ss-global-error",children:g}),!d&&i.map((b,C)=>{if(!b.result)return null;const{columns:h,rows:v}=b.result;return s.jsxs("div",{className:"ss-widget",children:[b.title&&s.jsx("h4",{className:"ss-widget-header",children:b.title}),s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsx("tr",{children:h.map(N=>s.jsx("th",{className:"ss-th",children:N},N))})}),s.jsx("tbody",{children:v.slice(0,50).map((N,$)=>s.jsx("tr",{className:"ss-tr",children:h.map(P=>s.jsx("td",{className:"ss-td",children:String(N[P]??"")},P))},$))})]})]},C)})]})})}exports.SaaSError=U.SaaSError;exports.SaaSSupport=U.SaaSSupport;exports.isMfaRequired=U.isMfaRequired;exports.Chart=gs;exports.CouponInput=Ws;exports.DashboardView=se;exports.DataTable=xs;exports.InvoiceHistory=us;exports.OrgSwitcher=Ds;exports.PaymentPortal=qs;exports.PricingTable=As;exports.QueryInput=Qs;exports.ReportEmbed=te;exports.SaaSContext=Z;exports.SaaSProvider=vs;exports.SavedQueryList=ae;exports.SettingsPanel=os;exports.SignIn=Cs;exports.SignUp=zs;exports.SubscriptionStatus=ds;exports.UsageDisplay=ps;exports.UserButton=Bs;exports.UserProfile=Ls;exports.useAuth=W;exports.useBilling=Ms;exports.useDashboard=Gs;exports.useDeleteAccount=as;exports.useEmbedDashboard=Ys;exports.useInvoices=ls;exports.useOrg=H;exports.useProfile=X;exports.useQuery=ss;exports.useReport=_s;exports.useSaaSContext=I;exports.useSavedQueries=hs;exports.useSignIn=K;exports.useSignUp=es;exports.useSubscription=is;exports.useUsage=cs;exports.useUser=$s;
|
|
2357
|
+
`}function M({children:e,appearance:t}){const a=r.useRef(null),[l,n]=r.useState(null);r.useEffect(()=>{var x;if(!a.current||a.current.shadowRoot){n(((x=a.current)==null?void 0:x.shadowRoot)??null);return}const c=a.current.attachShadow({mode:"open"});if((t==null?void 0:t.fontUrl)!==null){const p=(t==null?void 0:t.fontUrl)??"https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Inter:wght@400;500;600&family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&display=swap";if(!document.querySelector(`link[href="${p}"]`)){const y=document.createElement("link");y.rel="stylesheet",y.href=p,document.head.appendChild(y)}const h=document.createElement("link");h.rel="stylesheet",h.href=p,c.appendChild(h)}const d=Q(t),i=document.createElement("style");i.textContent=J(d),c.appendChild(i);const o=document.createElement("div");c.appendChild(o),n(c)},[]),r.useEffect(()=>{if(!l)return;const c=l.querySelector("style");if(c){const d=Q(t);c.textContent=J(d)}},[t,l]);const u=(l==null?void 0:l.querySelector("div"))??null;return s.jsx("div",{ref:a,style:{display:"contents"},children:u&&js.createPortal(e,u)})}function W(){const{client:e,user:t,isLoaded:a}=B();return{isLoaded:a,isSignedIn:!!t,user:t,signOut:r.useCallback(()=>e.auth.signOut(),[e]),getToken:r.useCallback(()=>e.auth.getToken(),[e]),refreshUser:r.useCallback(()=>e.auth.refreshUser(),[e])}}function $s(){const{user:e,isLoaded:t}=B();return{user:e,isLoaded:t}}function K(){const{client:e}=B(),[t,a]=r.useState(!1),[l,n]=r.useState(null),u=r.useCallback(async(i,o)=>{a(!0),n(null);try{return await e.auth.signIn(i,o)}catch(x){return n(x instanceof Error?x.message:"Sign in failed"),null}finally{a(!1)}},[e]),c=r.useCallback(async i=>{a(!0),n(null);try{return await e.auth.signInWithOAuth(i)}catch(o){return n(o instanceof Error?o.message:"OAuth sign in failed"),null}finally{a(!1)}},[e]),d=r.useCallback(async(i,o)=>{a(!0),n(null);try{return await e.auth.submitMfaCode(i,o)}catch(x){return n(x instanceof Error?x.message:"MFA verification failed"),null}finally{a(!1)}},[e]);return{signIn:u,signInWithOAuth:c,submitMfaCode:d,isLoading:t,error:l,setError:n}}function es(){const{client:e}=B(),[t,a]=r.useState(!1),[l,n]=r.useState(null);return{signUp:r.useCallback(async(c,d)=>{a(!0),n(null);try{return await e.auth.signUp(c,d)}catch(i){return n(i instanceof Error?i.message:"Sign up failed"),null}finally{a(!1)}},[e]),isLoading:t,error:l,setError:n}}function H(){const{client:e}=B(),[t,a]=r.useState([]),[l,n]=r.useState(null),[u,c]=r.useState([]),[d,i]=r.useState([]),[o,x]=r.useState(!1),[p,h]=r.useState(null),y=r.useRef(!1),f=r.useCallback(async()=>{x(!0),h(null);try{const m=await e.auth.listOrgs();if(a(m),!y.current&&m.length>0){const j=typeof window<"u"?localStorage.getItem("ss_selected_org"):null,k=(j?m.find(T=>T.id===j):null)??(m.length===1?m[0]:null);if(k){y.current=!0,n(k),typeof window<"u"&&localStorage.setItem("ss_selected_org",k.id);try{const T=await e.auth.listMembers(k.id);c(T)}catch{}}}}catch(m){h(m instanceof Error?m.message:"Failed to load organizations")}finally{x(!1)}},[e]);r.useEffect(()=>{f()},[f]);const b=r.useCallback(async m=>{try{const j=await e.auth.getOrg(m);n(j),typeof window<"u"&&localStorage.setItem("ss_selected_org",m);const O=await e.auth.listMembers(m);c(O)}catch(j){h(j instanceof Error?j.message:"Failed to load organization")}},[e]),$=r.useCallback(async(m,j)=>{try{const O=await e.auth.createOrg(m,j);return a(k=>[...k,O]),O}catch(O){return h(O instanceof Error?O.message:"Failed to create organization"),null}},[e]),v=r.useCallback(async(m,j)=>{try{const O=await e.auth.updateOrg(m,j);return a(k=>k.map(T=>T.id===m?O:T)),(l==null?void 0:l.id)===m&&n(O),O}catch(O){return h(O instanceof Error?O.message:"Failed to update organization"),null}},[e,l]),z=r.useCallback(async m=>{try{return await e.auth.deleteOrg(m),a(j=>j.filter(O=>O.id!==m)),(l==null?void 0:l.id)===m&&(n(null),c([]),i([]),typeof window<"u"&&localStorage.removeItem("ss_selected_org")),!0}catch(j){return h(j instanceof Error?j.message:"Failed to delete organization"),!1}},[e,l]),N=r.useCallback(async(m,j,O)=>{try{return await e.auth.sendInvite(m,j,O)}catch(k){return h(k instanceof Error?k.message:"Failed to send invite"),null}},[e]),g=r.useCallback(async m=>{try{const j=await e.auth.listInvites(m);i(j)}catch(j){h(j instanceof Error?j.message:"Failed to load invites")}},[e]),C=r.useCallback(async(m,j)=>{try{return await e.auth.revokeInvite(m,j),i(O=>O.filter(k=>k.id!==j)),!0}catch(O){return h(O instanceof Error?O.message:"Failed to revoke invite"),!1}},[e]),P=r.useCallback(async(m,j,O)=>{try{return await e.auth.updateMemberRole(m,j,O),c(k=>k.map(T=>T.userId===j?{...T,role:O}:T)),!0}catch(k){return h(k instanceof Error?k.message:"Failed to update member role"),!1}},[e]),E=r.useCallback(async(m,j)=>{try{return await e.auth.removeMember(m,j),c(O=>O.filter(k=>k.userId!==j)),!0}catch(O){return h(O instanceof Error?O.message:"Failed to remove member"),!1}},[e]),F=r.useCallback(async m=>{try{const j=await e.auth.listMembers(m);c(j)}catch(j){h(j instanceof Error?j.message:"Failed to load members")}},[e]);return{orgs:t,selectedOrg:l,members:u,invites:d,isLoading:o,error:p,setError:h,refresh:f,selectOrg:b,createOrg:$,updateOrg:v,deleteOrg:z,sendInvite:N,refreshInvites:g,revokeInvite:C,updateMemberRole:P,removeMember:E,refreshMembers:F}}function as(){const{client:e}=B(),[t,a]=r.useState(!1),[l,n]=r.useState(null);return{deleteAccount:r.useCallback(async()=>{a(!0),n(null);try{return await e.auth.deleteAccount(),!0}catch(c){return n(c instanceof Error?c.message:"Failed to delete account"),!1}finally{a(!1)}},[e]),isLoading:t,error:l,setError:n}}function X(){const{client:e,user:t}=B(),[a,l]=r.useState(!1),[n,u]=r.useState(null),[c,d]=r.useState(null),i=r.useCallback(async p=>{l(!0),u(null),d(null);try{const h=await e.auth.updateProfile(p);return d("Profile updated"),h}catch(h){return u(h instanceof Error?h.message:"Failed to update profile"),null}finally{l(!1)}},[e]),o=r.useCallback(async(p,h)=>{l(!0),u(null),d(null);try{return await e.auth.changePassword(p,h),d("Password changed successfully"),!0}catch(y){return u(y instanceof Error?y.message:"Failed to change password"),!1}finally{l(!1)}},[e]),x=r.useCallback(async p=>{l(!0),u(null),d(null);try{const h=await e.auth.uploadAvatar(p);return d("Avatar updated"),h}catch(h){return u(h instanceof Error?h.message:"Failed to upload avatar"),null}finally{l(!1)}},[e]);return{user:t,updateProfile:i,uploadAvatar:x,changePassword:o,isLoading:a,error:n,success:c,setError:u,setSuccess:d}}const ts='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z" fill="#4285F4"/><path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/><path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05"/><path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/></svg>',rs='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0 0 24 12c0-6.63-5.37-12-12-12z" fill="currentColor"/></svg>',w={close:"close",person:"person",logout:"logout",checkCircle:"check_circle",unfoldMore:"unfold_more",cloudUpload:"cloud_upload",zoomIn:"zoom_in",zoomOut:"zoom_out",lock:"lock",visibility:"visibility",visibilityOff:"visibility_off",add:"add",addCircle:"add_circle",camera:"photo_camera",security:"security",errorOutline:"error_outline",info:"info",arrowBack:"arrow_back",arrowForward:"arrow_forward",verified:"verified",token:"token",autoAwesome:"auto_awesome",corporateFare:"corporate_fare",cloudDone:"cloud_done",check:"check",image:"image",settings:"settings",group:"group",creditCard:"credit_card",edit:"edit",send:"send",personRemove:"person_remove"};function Cs({appearance:e,signUpUrl:t,onSignUp:a}){const{appearance:l,settings:n}=B(),{signIn:u,signInWithOAuth:c,submitMfaCode:d,isLoading:i,error:o,setError:x}=K(),p=e??l,[h,y]=r.useState(""),[f,b]=r.useState(""),[$,v]=r.useState(!1),[z,N]=r.useState(!1),[g,C]=r.useState(""),[P,E]=r.useState(["","","","","",""]),F=r.useRef([]),m=r.useCallback(async I=>{if(I.preventDefault(),z){await d(g,P.join(""));return}const S=await u(h,f);S&&R.isMfaRequired(S)&&(C(S.mfaToken),N(!0),x(null))},[h,f,z,g,P,u,d,x]),j=r.useCallback(async I=>{await c(I)},[c]),O=r.useCallback((I,S)=>{var V;if(!/^\d*$/.test(S))return;const L=S.slice(-1);E(G=>{const q=[...G];return q[I]=L,q}),L&&I<5&&((V=F.current[I+1])==null||V.focus())},[]),k=r.useCallback((I,S)=>{var L;S.key==="Backspace"&&!P[I]&&I>0&&((L=F.current[I-1])==null||L.focus())},[P]),T=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled);return s.jsx(M,{appearance:p,children:s.jsx("div",{className:"ss-auth-card",children:s.jsxs("div",{className:"ss-auth-card-body",children:[s.jsxs("div",{className:"ss-auth-header",children:[s.jsx("div",{className:"ss-auth-brand-icon",children:s.jsx("span",{className:"material-symbols-outlined",children:w.token})}),s.jsx("h1",{className:"ss-auth-title",children:"Sign in to your account"}),s.jsx("p",{className:"ss-auth-subtitle",children:"Welcome back to your workspace"})]}),!z&&T&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-auth-oauth-grid",children:[(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>j("google"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:ts}}),"Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>j("github"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:rs}}),"GitHub"]})]}),s.jsx("div",{className:"ss-auth-divider",children:"or continue with"})]}),o&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:o})]}),s.jsxs("form",{onSubmit:m,children:[z?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ss-auth-mfa-divider",children:s.jsx("span",{children:"Verification Required"})}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"6-Digit Code"}),s.jsx("div",{className:"ss-auth-mfa-group",children:P.map((I,S)=>s.jsx("input",{ref:L=>{F.current[S]=L},className:"ss-auth-mfa-digit",type:"text",inputMode:"numeric",maxLength:1,value:I,onChange:L=>O(S,L.target.value),onKeyDown:L=>k(S,L),autoFocus:S===0},S))}),s.jsx("p",{className:"ss-auth-mfa-hint",children:"We sent a 6-digit code to your registered email."})]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-email",children:"Email Address"}),s.jsx("input",{id:"ss-email",className:"ss-auth-input",type:"email",autoComplete:"email",placeholder:"name@company.com",value:h,onChange:I=>y(I.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsxs("div",{className:"ss-auth-field-row",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-password",style:{marginBottom:0},children:"Password"}),s.jsx("span",{className:"ss-auth-link",style:{fontSize:"12px"},children:"Forgot?"})]}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{id:"ss-password",className:"ss-auth-input",type:$?"text":"password",autoComplete:"current-password",placeholder:"••••••••",value:f,onChange:I=>b(I.target.value),required:!0}),s.jsx("button",{type:"button",className:"ss-auth-visibility-toggle",onClick:()=>v(!$),children:s.jsx("span",{className:"material-symbols-outlined",children:$?w.visibilityOff:w.visibility})})]})]})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:i,children:[i&&s.jsx("span",{className:"ss-auth-spinner"}),z?"Verify":"Sign in",!i&&s.jsx("span",{className:"material-symbols-outlined",children:w.arrowForward})]})]}),z?s.jsx("div",{className:"ss-auth-footer",children:s.jsx("span",{className:"ss-auth-link",onClick:()=>{N(!1),E(["","","","","",""]),x(null)},children:"Back to sign in"})}):s.jsxs("div",{className:"ss-auth-footer",children:["Don't have an account?"," ",a?s.jsx("span",{className:"ss-auth-link",onClick:a,children:"Sign up"}):t?s.jsx("a",{className:"ss-auth-link",href:t,children:"Sign up"}):s.jsx("span",{className:"ss-auth-link",children:"Sign up"})]})]})})})}function zs({appearance:e,signInUrl:t,onSignIn:a}){const{appearance:l,settings:n}=B(),{signUp:u,isLoading:c,error:d,setError:i}=es(),{signInWithOAuth:o}=K(),x=e??l,[p,h]=r.useState(""),[y,f]=r.useState(""),[b,$]=r.useState(""),[v,z]=r.useState(!1),[N,g]=r.useState(null),C=r.useCallback(async m=>{if(m.preventDefault(),g(null),y!==b){g("Passwords do not match");return}const j=(n==null?void 0:n.passwordMinLength)??8;if(y.length<j){g(`Password must be at least ${j} characters`);return}await u(p,y)},[p,y,b,n,u]),P=r.useCallback(async m=>{await o(m)},[o]),E=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled),F=N||d;return s.jsx(M,{appearance:x,children:s.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%",maxWidth:"520px"},children:[s.jsxs("div",{className:"ss-auth-header",children:[s.jsx("div",{className:"ss-auth-brand-icon-gradient",children:s.jsx("span",{className:"material-symbols-outlined",children:w.autoAwesome})}),s.jsx("h1",{className:"ss-auth-title ss-auth-title-lg",children:"Create your account"}),s.jsx("p",{className:"ss-auth-subtitle",children:"Join the ecosystem"})]}),s.jsx("div",{className:"ss-auth-card",children:s.jsxs("div",{className:"ss-auth-card-body",children:[E&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-auth-oauth-grid",children:[(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>P("google"),disabled:c,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:ts}}),"Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>P("github"),disabled:c,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:rs}}),"GitHub"]})]}),s.jsx("div",{className:"ss-auth-divider",children:"or sign up with email"})]}),F&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:F})]}),s.jsxs("form",{onSubmit:C,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-signup-email",children:"Email"}),s.jsx("input",{id:"ss-signup-email",className:"ss-auth-input",type:"email",autoComplete:"email",placeholder:"name@company.com",value:p,onChange:m=>h(m.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-signup-password",children:"Password"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{id:"ss-signup-password",className:"ss-auth-input",type:v?"text":"password",autoComplete:"new-password",placeholder:"••••••••",value:y,onChange:m=>{f(m.target.value),g(null)},required:!0}),s.jsx("button",{type:"button",className:"ss-auth-visibility-toggle",onClick:()=>z(!v),children:s.jsx("span",{className:"material-symbols-outlined",children:v?w.visibilityOff:w.visibility})})]})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",htmlFor:"ss-signup-confirm",children:"Confirm Password"}),s.jsx("input",{id:"ss-signup-confirm",className:"ss-auth-input",type:"password",autoComplete:"new-password",placeholder:"••••••••",value:b,onChange:m=>{$(m.target.value),g(null)},required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:c,children:[c&&s.jsx("span",{className:"ss-auth-spinner"}),"Sign up",!c&&s.jsx("span",{className:"material-symbols-outlined",children:w.arrowForward})]})]}),s.jsxs("div",{className:"ss-auth-footer",children:["Already have an account?"," ",a?s.jsx("span",{className:"ss-auth-link",onClick:a,children:"Sign in"}):t?s.jsx("a",{className:"ss-auth-link",href:t,children:"Sign in"}):s.jsx("span",{className:"ss-auth-link",children:"Sign in"})]})]})})]})})}const A=320,U=128,Ps=r.forwardRef(function({file:t,onCrop:a,onCancel:l},n){const u=r.useRef(null),c=r.useRef(null),[d,i]=r.useState(1),[o,x]=r.useState({x:0,y:0}),[p,h]=r.useState(!1),y=r.useRef({x:0,y:0,ox:0,oy:0}),[f,b]=r.useState(!1);r.useEffect(()=>{const g=new Image,C=URL.createObjectURL(t);return g.onload=()=>{c.current=g,b(!0),x({x:0,y:0}),i(1)},g.src=C,()=>URL.revokeObjectURL(C)},[t]),r.useEffect(()=>{if(!f||!c.current||!u.current)return;const g=u.current.getContext("2d");if(!g)return;const C=c.current;g.clearRect(0,0,A,A),g.fillStyle="#111",g.fillRect(0,0,A,A);const P=Math.max(A/C.width,A/C.height)*d,E=C.width*P,F=C.height*P,m=(A-E)/2+o.x,j=(A-F)/2+o.y;g.save(),g.beginPath(),g.arc(A/2,A/2,U,0,Math.PI*2),g.clip(),g.drawImage(C,m,j,E,F),g.restore(),g.save(),g.fillStyle="rgba(0, 0, 0, 0.6)",g.fillRect(0,0,A,A),g.globalCompositeOperation="destination-out",g.beginPath(),g.arc(A/2,A/2,U,0,Math.PI*2),g.fill(),g.restore(),g.save(),g.beginPath(),g.arc(A/2,A/2,U,0,Math.PI*2),g.clip(),g.drawImage(C,m,j,E,F),g.restore(),g.strokeStyle="rgba(255, 255, 255, 0.4)",g.lineWidth=2,g.beginPath(),g.arc(A/2,A/2,U,0,Math.PI*2),g.stroke()},[d,o,f]);const $=r.useCallback(g=>{h(!0),y.current={x:g.clientX,y:g.clientY,ox:o.x,oy:o.y},g.target.setPointerCapture(g.pointerId)},[o]),v=r.useCallback(g=>{p&&x({x:y.current.ox+(g.clientX-y.current.x),y:y.current.oy+(g.clientY-y.current.y)})},[p]),z=r.useCallback(()=>h(!1),[]),N=r.useCallback(()=>{if(!c.current)return;const g=document.createElement("canvas"),C=U*2;g.width=C,g.height=C;const P=g.getContext("2d");if(!P)return;const E=c.current,F=Math.max(A/E.width,A/E.height)*d,m=E.width*F,j=E.height*F,O=(A-m)/2+o.x-(A/2-U),k=(A-j)/2+o.y-(A/2-U);P.beginPath(),P.arc(U,U,U,0,Math.PI*2),P.clip(),P.drawImage(E,O,k,m,j),g.toBlob(T=>{T&&a(T)},"image/png")},[d,o,a]);return r.useImperativeHandle(n,()=>({triggerCrop:()=>N()}),[N]),s.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"24px"},children:[s.jsxs("div",{className:"ss-auth-crop-area",children:[s.jsx("canvas",{ref:u,width:A,height:A,style:{cursor:p?"grabbing":"grab",width:"100%",height:"100%"},onPointerDown:$,onPointerMove:v,onPointerUp:z}),s.jsx("div",{className:"ss-auth-crop-size-badge",children:"256 x 256 px"})]}),s.jsxs("div",{className:"ss-auth-zoom-control",style:{width:"100%",maxWidth:"280px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.zoomOut}),s.jsx("input",{type:"range",min:"1",max:"3",step:"0.01",value:d,onChange:g=>i(parseFloat(g.target.value)),className:"ss-auth-zoom-slider"}),s.jsx("span",{className:"material-symbols-outlined",children:w.zoomIn})]})]})});function ns({onUpload:e,onClose:t,isLoading:a}){const[l,n]=r.useState(null),[u,c]=r.useState(!1),[d,i]=r.useState(null),o=r.useRef(null),x=r.useRef(null),p=r.useCallback(f=>{if(!f.type.startsWith("image/")){i("Please select an image file");return}if(f.size>5*1024*1024){i("Image must be smaller than 5 MB");return}i(null),n(f)},[]),h=r.useCallback(f=>{f.preventDefault(),c(!1);const b=f.dataTransfer.files[0];b&&p(b)},[p]),y=r.useCallback(async f=>{await e(f)},[e]);return s.jsx("div",{className:"ss-auth-modal-overlay",onClick:f=>{f.target===f.currentTarget&&t()},children:s.jsxs("div",{className:"ss-auth-modal",style:{maxWidth:"480px"},children:[s.jsxs("div",{className:"ss-auth-modal-header",children:[s.jsx("h2",{children:"Upload avatar"}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:t,children:s.jsx("span",{className:"material-symbols-outlined",children:w.close})})]}),s.jsxs("div",{className:"ss-auth-modal-body",children:[d&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:d})]}),l?s.jsxs(s.Fragment,{children:[s.jsx(Ps,{ref:x,file:l,onCrop:y,onCancel:()=>n(null)}),s.jsx("div",{style:{textAlign:"center",marginTop:"8px"},children:s.jsxs("button",{type:"button",className:"ss-auth-btn-ghost",style:{fontSize:"13px"},onClick:()=>{var f;return(f=o.current)==null?void 0:f.click()},children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"16px"},children:w.image}),"Change image"]})})]}):s.jsxs("div",{className:`ss-auth-dropzone${u?" ss-auth-dropzone-active":""}`,onDragOver:f=>{f.preventDefault(),c(!0)},onDragLeave:()=>c(!1),onDrop:h,onClick:()=>{var f;return(f=o.current)==null?void 0:f.click()},style:{minHeight:"240px"},children:[s.jsx("div",{className:"ss-auth-dropzone-icon",children:s.jsx("span",{className:"material-symbols-outlined",children:w.cloudUpload})}),s.jsx("span",{className:"ss-auth-dropzone-title",children:"Drag and drop"}),s.jsxs("span",{className:"ss-auth-dropzone-desc",children:["JPG, PNG or WEBP",s.jsx("br",{}),"Max file size 5 MB"]}),s.jsx("button",{type:"button",className:"ss-auth-dropzone-btn",children:"Choose File"})]}),s.jsx("input",{ref:o,type:"file",accept:"image/*",style:{display:"none"},onChange:f=>{var b;(b=f.target.files)!=null&&b[0]&&p(f.target.files[0])}}),s.jsxs("div",{className:"ss-auth-info-box",style:{marginTop:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.info}),s.jsx("span",{children:"Your profile photo will be visible to all members of your organization."})]})]}),s.jsxs("div",{className:"ss-auth-modal-footer",children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:t,children:"Cancel"}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",onClick:()=>{var f;return(f=x.current)==null?void 0:f.triggerCrop()},disabled:!l||a,style:{width:"auto"},children:[a&&s.jsx("span",{className:"ss-auth-spinner"}),"Save Profile",!a&&s.jsx("span",{className:"material-symbols-outlined",children:w.check})]})]})]})})}function os({onClose:e,afterDeleteAccountUrl:t,defaultTab:a="profile",onOrgDeleted:l,onOrgUpdated:n}){const[u,c]=r.useState(a),d=[{key:"profile",label:"Profile",icon:w.person},{key:"organization",label:"Organization",icon:w.corporateFare},{key:"people",label:"People",icon:w.group},{key:"billing",label:"Billing",icon:w.creditCard}];return s.jsxs("div",{className:"ss-auth-settings-page",children:[s.jsxs("div",{className:"ss-auth-settings-header",children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[s.jsx("button",{type:"button",className:"ss-auth-settings-back",onClick:e,children:s.jsx("span",{className:"material-symbols-outlined",children:w.arrowBack})}),s.jsx("h2",{children:"Settings"})]}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:e,children:s.jsx("span",{className:"material-symbols-outlined",children:w.close})})]}),s.jsxs("div",{className:"ss-auth-settings-layout",children:[s.jsx("nav",{className:"ss-auth-settings-nav",children:d.map(i=>s.jsxs("button",{type:"button",className:`ss-auth-settings-nav-item${u===i.key?" ss-auth-settings-nav-item-active":""}`,onClick:()=>c(i.key),children:[s.jsx("span",{className:"material-symbols-outlined",children:i.icon}),i.label]},i.key))}),s.jsxs("div",{className:"ss-auth-settings-content",children:[u==="profile"&&s.jsx(Os,{afterDeleteAccountUrl:t}),u==="organization"&&s.jsx(Es,{onOrgDeleted:l,onOrgUpdated:n}),u==="people"&&s.jsx(Is,{}),u==="billing"&&s.jsx(Fs,{})]})]})]})}function Os({afterDeleteAccountUrl:e}){const{user:t,updateProfile:a,uploadAvatar:l,changePassword:n,isLoading:u,error:c,success:d,setError:i,setSuccess:o}=X(),{signOut:x}=W(),{deleteAccount:p,isLoading:h,error:y,setError:f}=as(),[b,$]=r.useState((t==null?void 0:t.name)??""),[v,z]=r.useState((t==null?void 0:t.avatarUrl)??""),[N,g]=r.useState(!1),[C,P]=r.useState(""),[E,F]=r.useState(""),[m,j]=r.useState(""),[O,k]=r.useState(null),[T,I]=r.useState(!1),[S,L]=r.useState(""),V=r.useCallback(async D=>{D.preventDefault(),i(null),o(null),await a({name:b,avatarUrl:v||void 0})},[b,v,a,i,o]),G=r.useCallback(async D=>{const Y=await l(D);Y&&(z(Y.avatarUrl),g(!1))},[l]),q=r.useCallback(async D=>{if(D.preventDefault(),k(null),i(null),o(null),E!==m){k("Passwords do not match");return}if(E.length<8){k("Password must be at least 8 characters");return}await n(C,E)&&(P(""),F(""),j(""))},[C,E,m,n,i,o]),ms=r.useCallback(async()=>{await p()&&(await x(),e&&(window.location.href=e))},[p,x,e]),fs=(t==null?void 0:t.provider)==="email",bs=S===(t==null?void 0:t.email),ys=((t==null?void 0:t.name)||(t==null?void 0:t.email)||"?").charAt(0).toUpperCase();return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Profile"}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("div",{className:"ss-auth-profile-header",style:{border:"none",background:"none",padding:0,marginBottom:16},children:[s.jsxs("div",{className:"ss-auth-avatar-lg",onClick:()=>g(!0),children:[v?s.jsx("img",{src:v,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"48px",fontWeight:800,opacity:.4},children:ys}),s.jsxs("div",{className:"ss-auth-avatar-overlay",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.camera}),s.jsx("span",{children:"Edit"})]})]}),s.jsxs("div",{className:"ss-auth-profile-info",children:[s.jsxs("h2",{className:"ss-auth-profile-name",children:[(t==null?void 0:t.name)||"Unnamed User",(t==null?void 0:t.emailVerified)&&s.jsxs("span",{className:"ss-auth-badge ss-auth-badge-success",children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"12px",fontVariationSettings:"'FILL' 1"},children:w.verified}),"Verified"]})]}),s.jsx("p",{className:"ss-auth-profile-desc",children:t==null?void 0:t.email})]})]}),c&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:c})]}),d&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.check}),s.jsx("span",{children:d})]}),s.jsxs("form",{onSubmit:V,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Full Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"Your name",value:b,onChange:D=>$(D.target.value)})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Email Address"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"email",value:(t==null?void 0:t.email)??"",readOnly:!0}),s.jsx("span",{className:"ss-auth-visibility-toggle",style:{cursor:"default"},children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"18px"},children:w.lock})})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Auth Provider"}),s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"text",value:(t==null?void 0:t.provider)??"",readOnly:!0})]})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:u,style:{width:"auto"},children:[u&&s.jsx("span",{className:"ss-auth-spinner"}),"Save changes"]})})]})]}),fs&&s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:w.security}),"Security Credentials"]}),O&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:O})]}),s.jsxs("form",{onSubmit:q,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Current Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"••••••••••••",value:C,onChange:D=>P(D.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Min. 8 characters",value:E,onChange:D=>F(D.target.value),required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Confirm New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Repeat new password",value:m,onChange:D=>j(D.target.value),required:!0})]})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsx("button",{type:"submit",className:"ss-auth-btn-ghost",disabled:u,children:"Update Security"})})]})]}),s.jsxs("div",{className:"ss-auth-settings-card ss-auth-settings-danger",children:[s.jsx("h4",{children:"Danger Zone"}),s.jsx("p",{className:"ss-auth-section-desc",style:{marginBottom:"16px"},children:"Deleting your account is permanent. All organizations you own will also be deleted."}),y&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:y})]}),T?s.jsxs("div",{children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Type your email to confirm"}),s.jsx("input",{className:"ss-auth-input",type:"email",placeholder:t==null?void 0:t.email,value:S,onChange:D=>L(D.target.value),autoFocus:!0})]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>{I(!1),L(""),f(null)},children:"Cancel"}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto",background:"linear-gradient(135deg, #ef4444, #dc2626)"},disabled:!bs||h,onClick:ms,children:[h&&s.jsx("span",{className:"ss-auth-spinner"}),"Delete account"]})]})]}):s.jsx("button",{type:"button",className:"ss-auth-btn-outline",style:{borderColor:"currentColor",width:"auto"},onClick:()=>I(!0),children:"Delete my account"})]}),N&&s.jsx(ns,{onUpload:G,onClose:()=>g(!1),isLoading:u})]})}function Es({onOrgDeleted:e,onOrgUpdated:t}){const{selectedOrg:a,updateOrg:l,deleteOrg:n,isLoading:u,error:c,setError:d}=H(),[i,o]=r.useState((a==null?void 0:a.name)??""),[x,p]=r.useState(!1),[h,y]=r.useState(!1),[f,b]=r.useState(!1),[$,v]=r.useState(!1),[z,N]=r.useState("");if(r.useEffect(()=>{a&&(o(a.name),b(!1))},[a]),f)return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Organization"}),s.jsxs("div",{className:"ss-auth-settings-card",style:{textAlign:"center",padding:"48px 24px"},children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"48px",opacity:.4,marginBottom:"16px",display:"block"},children:w.check}),s.jsx("h4",{style:{margin:"0 0 8px"},children:"Organization deleted"}),s.jsx("p",{className:"ss-auth-section-desc",children:"The organization has been permanently deleted."})]})]});if(!a)return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Organization"}),s.jsxs("div",{className:"ss-auth-settings-empty",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.corporateFare}),s.jsx("div",{children:"Select an organization from the user menu to manage its settings."})]})]});const g=async P=>{if(P.preventDefault(),!i.trim())return;p(!0),y(!1);const E=await l(a.id,{name:i.trim()});p(!1),E&&(y(!0),t==null||t())},C=async()=>{await n(a.id)&&(v(!1),b(!0),e==null||e())};return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Organization"}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:w.corporateFare}),"General"]}),c&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:c})]}),h&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.check}),s.jsx("span",{children:"Organization updated"})]}),s.jsxs("form",{onSubmit:g,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Organization Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",value:i,onChange:P=>{o(P.target.value),y(!1)}})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Slug"}),s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"text",value:a.slug,readOnly:!0})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:x,style:{width:"auto"},children:[x&&s.jsx("span",{className:"ss-auth-spinner"}),"Save"]})})]})]}),s.jsxs("div",{className:"ss-auth-settings-card ss-auth-settings-danger",children:[s.jsx("h4",{children:"Danger Zone"}),s.jsx("p",{className:"ss-auth-section-desc",style:{marginBottom:"16px"},children:"Deleting this organization is permanent and will remove all members."}),$?s.jsxs("div",{children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Type the organization name to confirm"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:a.name,value:z,onChange:P=>N(P.target.value),autoFocus:!0})]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>{v(!1),N("")},children:"Cancel"}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto",background:"linear-gradient(135deg, #ef4444, #dc2626)"},disabled:z!==a.name||u,onClick:C,children:[u&&s.jsx("span",{className:"ss-auth-spinner"}),"Delete organization"]})]})]}):s.jsx("button",{type:"button",className:"ss-auth-btn-outline",style:{borderColor:"currentColor",width:"auto"},onClick:()=>v(!0),children:"Delete this organization"})]})]})}function Is(){const{selectedOrg:e,members:t,invites:a,isLoading:l,error:n,setError:u,sendInvite:c,refreshInvites:d,revokeInvite:i,updateMemberRole:o,removeMember:x,refreshMembers:p}=H(),[h,y]=r.useState(""),[f,b]=r.useState("member"),[$,v]=r.useState(!1),[z,N]=r.useState(!1),[g,C]=r.useState(null),[P,E]=r.useState(""),[F,m]=r.useState(null);if(r.useEffect(()=>{e&&(p(e.id),d(e.id))},[e,p,d]),!e)return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"People"}),s.jsxs("div",{className:"ss-auth-settings-empty",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.group}),s.jsx("div",{children:"Select an organization from the user menu to manage members."})]})]});const j=async S=>{S.preventDefault(),N(!1),await c(e.id,h,f)&&(y(""),b("member"),N(!0),v(!1),d(e.id))},O=async()=>{if(!g)return;await o(e.id,g.userId,P)&&C(null)},k=async()=>{if(!F)return;await x(e.id,F.userId)&&m(null)},T=async S=>{await i(e.id,S)},I=S=>S==="owner"?"ss-auth-role-badge ss-auth-role-badge-owner":S==="admin"?"ss-auth-role-badge ss-auth-role-badge-admin":"ss-auth-role-badge ss-auth-role-badge-member";return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"People"}),n&&s.jsxs("div",{className:"ss-auth-error",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:n})]}),z&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.check}),s.jsx("span",{children:"Invitation sent"})]}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"16px"},children:[s.jsxs("h4",{style:{margin:0},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.group}),"Members"]}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto"},onClick:()=>v(!$),children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"16px"},children:w.add}),"Invite"]})]}),$&&s.jsx("form",{onSubmit:j,style:{marginBottom:"16px",padding:"16px",background:"rgba(0,0,0,0.05)",borderRadius:"8px"},children:s.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[s.jsxs("div",{style:{flex:1},children:[s.jsx("label",{className:"ss-auth-label",children:"Email"}),s.jsx("input",{className:"ss-auth-input",type:"email",placeholder:"member@example.com",value:h,onChange:S=>y(S.target.value),required:!0})]}),s.jsxs("div",{style:{width:"120px"},children:[s.jsx("label",{className:"ss-auth-label",children:"Role"}),s.jsxs("select",{className:"ss-auth-input",value:f,onChange:S=>b(S.target.value),style:{cursor:"pointer"},children:[s.jsx("option",{value:"admin",children:"Admin"}),s.jsx("option",{value:"member",children:"Member"})]})]}),s.jsx("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:l,style:{width:"auto",marginBottom:"0"},children:"Send"})]})}),t.length===0?s.jsx("div",{className:"ss-auth-settings-empty",style:{padding:"20px"},children:s.jsx("div",{children:"No members yet."})}):s.jsxs("table",{className:"ss-auth-settings-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Email"}),s.jsx("th",{children:"Role"}),s.jsx("th",{style:{width:"80px"},children:"Actions"})]})}),s.jsx("tbody",{children:t.map(S=>s.jsxs("tr",{children:[s.jsx("td",{children:S.email}),s.jsx("td",{children:s.jsx("span",{className:I(S.role),children:S.role})}),s.jsx("td",{children:S.role==="owner"?s.jsx("span",{style:{fontSize:"12px",opacity:.4},children:"—"}):s.jsxs("div",{className:"ss-auth-settings-actions",children:[s.jsx("button",{type:"button",className:"ss-auth-icon-btn",title:"Edit role",onClick:()=>{C(S),E(S.role)},children:s.jsx("span",{className:"material-symbols-outlined",children:w.edit})}),s.jsx("button",{type:"button",className:"ss-auth-icon-btn ss-auth-icon-btn-danger",title:"Remove member",onClick:()=>m(S),children:s.jsx("span",{className:"material-symbols-outlined",children:w.personRemove})})]})})]},S.userId))})]})]}),a.length>0&&s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:w.send}),"Pending Invites"]}),s.jsxs("table",{className:"ss-auth-settings-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Email"}),s.jsx("th",{children:"Role"}),s.jsx("th",{style:{width:"80px"},children:"Actions"})]})}),s.jsx("tbody",{children:a.map(S=>s.jsxs("tr",{children:[s.jsx("td",{children:S.email}),s.jsx("td",{children:s.jsx("span",{className:I(S.role),children:S.role})}),s.jsx("td",{children:s.jsx("button",{type:"button",className:"ss-auth-icon-btn ss-auth-icon-btn-danger",title:"Revoke invite",onClick:()=>T(S.id),children:s.jsx("span",{className:"material-symbols-outlined",children:w.close})})})]},S.id))})]})]}),g&&s.jsx("div",{className:"ss-auth-modal-overlay",onClick:S=>{S.target===S.currentTarget&&C(null)},children:s.jsxs("div",{className:"ss-auth-modal",style:{maxWidth:"400px"},children:[s.jsxs("div",{className:"ss-auth-modal-header",children:[s.jsx("h2",{children:"Edit Role"}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:()=>C(null),children:s.jsx("span",{className:"material-symbols-outlined",children:w.close})})]}),s.jsxs("div",{className:"ss-auth-modal-body",children:[s.jsxs("p",{style:{fontSize:"14px",marginBottom:"16px",margin:"0 0 16px 0"},children:["Change role for ",s.jsx("strong",{children:g.email})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Role"}),s.jsxs("select",{className:"ss-auth-input",value:P,onChange:S=>E(S.target.value),style:{cursor:"pointer"},children:[s.jsx("option",{value:"admin",children:"Admin"}),s.jsx("option",{value:"member",children:"Member"})]})]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>C(null),children:"Cancel"}),s.jsx("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto"},onClick:O,children:"Save"})]})]})]})}),F&&s.jsx("div",{className:"ss-auth-modal-overlay",onClick:S=>{S.target===S.currentTarget&&m(null)},children:s.jsxs("div",{className:"ss-auth-modal",style:{maxWidth:"400px"},children:[s.jsxs("div",{className:"ss-auth-modal-header",children:[s.jsx("h2",{children:"Remove Member"}),s.jsx("button",{type:"button",className:"ss-auth-modal-close",onClick:()=>m(null),children:s.jsx("span",{className:"material-symbols-outlined",children:w.close})})]}),s.jsxs("div",{className:"ss-auth-modal-body",children:[s.jsxs("p",{style:{fontSize:"14px",margin:"0 0 16px 0"},children:["Are you sure you want to remove ",s.jsx("strong",{children:F.email})," from the organization?"]}),s.jsxs("div",{style:{display:"flex",gap:"8px",justifyContent:"flex-end"},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",onClick:()=>m(null),children:"Cancel"}),s.jsx("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto",background:"linear-gradient(135deg, #ef4444, #dc2626)"},onClick:k,children:"Remove"})]})]})]})})]})}function Fs(){const{selectedOrg:e}=H();return e?s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Billing"}),s.jsxs("div",{className:"ss-auth-settings-card",children:[s.jsxs("h4",{children:[s.jsx("span",{className:"material-symbols-outlined",children:w.creditCard}),"Plan & Billing"]}),s.jsx("div",{className:"ss-auth-settings-empty",style:{padding:"20px"},children:s.jsx("div",{children:"No billing plan configured for this organization."})})]})]}):s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Billing"}),s.jsxs("div",{className:"ss-auth-settings-empty",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.creditCard}),s.jsx("div",{children:"Select an organization from the user menu to manage billing."})]})]})}function Bs({appearance:e,afterSignOutUrl:t,afterDeleteAccountUrl:a,showOrgSwitcher:l=!0,onOrgChange:n,onOrgSettingsClick:u}){const{appearance:c}=B(),{user:d,signOut:i}=W(),o=e??c,[x,p]=r.useState(!1),[h,y]=r.useState(!1),[f,b]=r.useState(""),[$,v]=r.useState(null),[z,N]=r.useState(!1),g=r.useRef(null),{orgs:C,selectedOrg:P,selectOrg:E,createOrg:F,refresh:m}=H(),j=r.useCallback(k=>{g.current&&!k.composedPath().includes(g.current)&&p(!1)},[]);r.useEffect(()=>{if(x){const k=setTimeout(()=>{document.addEventListener("click",j)},0);return()=>{clearTimeout(k),document.removeEventListener("click",j)}}},[x,j]);const O=r.useCallback(async k=>{k.preventDefault(),v(null),N(!0);const T=f.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");try{const I=await F(f,T);I&&(await E(I.id),n==null||n(I),b(""),p(!1))}catch(I){v(I instanceof Error?I.message:"Failed to create organization")}finally{N(!1)}},[f,F,E,n]);return d?s.jsx(M,{appearance:o,children:s.jsxs("div",{style:{position:"relative",display:"inline-block"},ref:g,children:[s.jsxs("button",{type:"button",className:"ss-auth-user-trigger",onClick:()=>p(!x),"aria-label":"User menu",children:[s.jsx("span",{className:"ss-auth-avatar-trigger",children:d.avatarUrl?s.jsx("img",{src:d.avatarUrl,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"16px",fontWeight:700},children:(d.name||d.email).charAt(0).toUpperCase()})}),P&&s.jsx("span",{className:"ss-auth-trigger-org-name",children:P.name})]}),x&&s.jsxs("div",{className:"ss-auth-dropdown ss-auth-glass-panel",style:{minWidth:"320px"},children:[s.jsxs("div",{className:"ss-auth-dropdown-header",children:[s.jsx("div",{className:"ss-auth-dropdown-avatar",children:d.avatarUrl?s.jsx("img",{src:d.avatarUrl,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"20px",fontWeight:800},children:(d.name||d.email).charAt(0).toUpperCase()})}),s.jsxs("div",{children:[d.name&&s.jsx("div",{className:"ss-auth-dropdown-name",children:d.name}),s.jsx("div",{className:"ss-auth-dropdown-email",children:d.email})]})]}),s.jsx("div",{style:{padding:"4px 8px"},children:s.jsxs("button",{type:"button",className:"ss-auth-dropdown-action",onClick:()=>{p(!1),y(!0)},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.settings}),"Settings"]})}),l&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ss-auth-section-label",children:"Organizations"}),s.jsx("div",{style:{padding:"0 8px 4px"},children:C.map(k=>{const T=(P==null?void 0:P.id)===k.id,I=k.name.split(" ").map(S=>S[0]).join("").slice(0,2).toUpperCase();return s.jsxs("button",{type:"button",className:`ss-auth-org-item${T?" ss-auth-org-item-active":""}`,onClick:async()=>{p(!1),await E(k.id),n==null||n(k)},children:[s.jsxs("div",{className:"ss-auth-org-item-inner",children:[s.jsx("div",{className:`ss-auth-org-avatar${T?"":" ss-auth-org-avatar-inactive"}`,children:I}),s.jsx("span",{style:{fontFamily:"'Manrope', sans-serif",letterSpacing:"-0.01em"},children:k.name}),k.planName&&s.jsx("span",{className:"ss-auth-plan-badge",children:k.planName})]}),T&&s.jsx("span",{className:"material-symbols-outlined ss-auth-org-check",style:{fontSize:"18px"},children:w.checkCircle})]},k.id)})}),s.jsxs("div",{className:"ss-auth-inline-create",children:[$&&s.jsx("div",{className:"ss-auth-error",style:{marginBottom:"8px",fontSize:"12px"},children:s.jsx("span",{children:$})}),s.jsx("form",{onSubmit:O,children:s.jsxs("div",{className:"ss-auth-inline-create-input",children:[s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"New organization name",value:f,onChange:k=>b(k.target.value),required:!0,style:{fontSize:"13px",padding:"10px 40px 10px 12px"}}),s.jsx("button",{type:"submit",className:"ss-auth-inline-create-btn",disabled:z||!f.trim(),children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"20px"},children:w.add})})]})})]}),P&&u&&s.jsx("div",{style:{padding:"0 8px 4px"},children:s.jsxs("button",{type:"button",className:"ss-auth-dropdown-action",onClick:()=>{p(!1),u(P)},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.corporateFare}),"Org settings"]})})]}),s.jsx("div",{className:"ss-auth-signout-section",style:{padding:"8px"},children:s.jsxs("button",{type:"button",className:"ss-auth-dropdown-action",onClick:async()=>{p(!1),await i(),t&&(window.location.href=t)},style:{color:"inherit"},children:[s.jsx("span",{className:"material-symbols-outlined",style:{color:"inherit"},children:w.logout}),"Sign out"]})})]}),h&&s.jsx(os,{onClose:()=>y(!1),afterDeleteAccountUrl:a,onOrgDeleted:m,onOrgUpdated:m})]})}):null}function Ls({appearance:e}){const{appearance:t}=B(),{user:a,signOut:l}=W(),{updateProfile:n,uploadAvatar:u,changePassword:c,isLoading:d,error:i,success:o,setError:x,setSuccess:p}=X(),h=e??t,[y,f]=r.useState((a==null?void 0:a.name)??""),[b,$]=r.useState((a==null?void 0:a.avatarUrl)??""),[v,z]=r.useState(!1),[N,g]=r.useState(""),[C,P]=r.useState(""),[E,F]=r.useState(""),[m,j]=r.useState(null),O=r.useCallback(async L=>{L.preventDefault(),x(null),p(null),await n({name:y,avatarUrl:b||void 0})},[y,b,n,x,p]),k=r.useCallback(async L=>{const V=await u(L);V&&($(V.avatarUrl),z(!1))},[u]),T=r.useCallback(async L=>{if(L.preventDefault(),j(null),x(null),p(null),C!==E){j("Passwords do not match");return}if(C.length<8){j("Password must be at least 8 characters");return}await c(N,C)&&(g(""),P(""),F(""))},[N,C,E,c,x,p]);if(!a)return null;const I=a.provider==="email",S=(a.name||a.email).charAt(0).toUpperCase();return s.jsx(M,{appearance:h,children:s.jsxs("div",{className:"ss-auth-card",style:{maxWidth:"640px"},children:[s.jsxs("div",{className:"ss-auth-profile-header",children:[s.jsxs("div",{className:"ss-auth-avatar-lg",onClick:()=>z(!0),children:[b?s.jsx("img",{src:b,alt:""}):s.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"48px",fontWeight:800,opacity:.4},children:S}),s.jsxs("div",{className:"ss-auth-avatar-overlay",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.camera}),s.jsx("span",{children:"Edit"})]})]}),s.jsxs("div",{className:"ss-auth-profile-info",children:[s.jsxs("h2",{className:"ss-auth-profile-name",children:[a.name||"Unnamed User",a.emailVerified&&s.jsxs("span",{className:"ss-auth-badge ss-auth-badge-success",children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"12px",fontVariationSettings:"'FILL' 1"},children:w.verified}),"Verified"]})]}),s.jsx("p",{className:"ss-auth-profile-desc",children:a.email})]})]}),s.jsxs("div",{className:"ss-auth-card-body",children:[i&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:i})]}),o&&s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.check}),s.jsx("span",{children:o})]}),s.jsxs("form",{onSubmit:O,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Full Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"Your name",value:y,onChange:L=>f(L.target.value)})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Email Address"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"email",value:a.email,readOnly:!0}),s.jsx("span",{className:"ss-auth-visibility-toggle",style:{cursor:"default"},children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"18px"},children:w.lock})})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Auth Provider"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("input",{className:"ss-auth-input ss-auth-input-readonly",type:"text",value:a.provider,readOnly:!0}),s.jsx("span",{className:"ss-auth-visibility-toggle",style:{cursor:"default"},children:s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"18px"},children:w.cloudDone})})]})]})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary ss-auth-btn-sm",disabled:d,style:{width:"auto"},children:[d&&s.jsx("span",{className:"ss-auth-spinner"}),"Save changes"]})})]}),I&&s.jsxs("div",{className:"ss-auth-section",children:[s.jsxs("div",{className:"ss-auth-section-title",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.security}),"Security Credentials"]}),s.jsx("p",{className:"ss-auth-section-desc",style:{marginBottom:"24px"},children:"Update your password to keep your account secure."}),m&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:m})]}),s.jsxs("form",{onSubmit:T,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",children:"Current Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"••••••••••••",value:N,onChange:L=>g(L.target.value),required:!0})]}),s.jsxs("div",{className:"ss-auth-profile-grid",style:{marginBottom:"16px"},children:[s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Min. 8 characters",value:C,onChange:L=>P(L.target.value),required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"ss-auth-label",children:"Confirm New Password"}),s.jsx("input",{className:"ss-auth-input",type:"password",placeholder:"Repeat new password",value:E,onChange:L=>F(L.target.value),required:!0})]})]}),s.jsxs("div",{className:"ss-auth-info-box",style:{marginBottom:"16px"},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.info}),s.jsx("span",{children:"Password must be at least 8 characters long."})]}),s.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:s.jsx("button",{type:"submit",className:"ss-auth-btn-ghost",disabled:d,children:"Update Security"})})]})]}),s.jsx("div",{className:"ss-auth-section",style:{borderTop:"none",paddingTop:0,marginTop:"24px"},children:s.jsx("div",{className:"ss-auth-signout-section",style:{borderRadius:"12px",padding:"16px 20px"},children:s.jsxs("div",{className:"ss-auth-signout-row",children:[s.jsxs("div",{className:"ss-auth-signout-info",children:[s.jsx("div",{className:"ss-auth-signout-icon",children:s.jsx("span",{className:"material-symbols-outlined",children:w.logout})}),s.jsxs("div",{children:[s.jsx("div",{className:"ss-auth-signout-title",children:"End Session"}),s.jsx("div",{className:"ss-auth-signout-desc",children:"Terminate your active session"})]})]}),s.jsx("button",{type:"button",className:"ss-auth-btn-outline",onClick:()=>l(),style:{width:"auto",flexShrink:0},children:"Sign out"})]})})})]}),v&&s.jsx(ns,{onUpload:k,onClose:()=>z(!1),isLoading:d})]})})}function Ts({appearance:e,onOrgChange:t}){const{appearance:a}=B(),{orgs:l,selectedOrg:n,selectOrg:u,createOrg:c,isLoading:d}=H(),i=e??a,[o,x]=r.useState(!1),[p,h]=r.useState(""),[y,f]=r.useState(""),[b,$]=r.useState(null),[v,z]=r.useState(!1),N=r.useRef(null),g=r.useCallback(m=>{N.current&&!m.composedPath().includes(N.current)&&x(!1)},[]);r.useEffect(()=>{if(o){const m=setTimeout(()=>{document.addEventListener("click",g)},0);return()=>{clearTimeout(m),document.removeEventListener("click",g)}}},[o,g]);const C=r.useCallback(m=>{h(m),f(m.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},[]),P=r.useCallback(async m=>{m.preventDefault(),$(null),z(!0);try{const j=await c(p,y);j&&(await u(j.id),t==null||t(j),h(""),f(""),x(!1))}catch(j){$(j instanceof Error?j.message:"Failed to create organization")}finally{z(!1)}},[p,y,c,u,t]);if(d)return null;const E=(n==null?void 0:n.name)??(l.length===0?"No organization":"Select organization"),F=n?n.name.split(" ").map(m=>m[0]).join("").slice(0,2).toUpperCase():"--";return s.jsx(M,{appearance:i,children:s.jsxs("div",{style:{position:"relative",display:"inline-block",width:"100%",maxWidth:"360px"},ref:N,children:[s.jsxs("button",{type:"button",className:"ss-auth-org-trigger",onClick:()=>x(!o),children:[s.jsxs("div",{className:"ss-auth-org-trigger-inner",children:[s.jsx("div",{className:"ss-auth-org-avatar",children:F}),s.jsxs("div",{style:{textAlign:"left"},children:[s.jsx("div",{className:"ss-auth-org-trigger-label",children:"Current Organization"}),s.jsx("div",{className:"ss-auth-org-trigger-name",children:E})]})]}),s.jsx("span",{className:"material-symbols-outlined",children:w.unfoldMore})]}),o&&s.jsxs("div",{className:"ss-auth-dropdown ss-auth-dropdown-left ss-auth-glass-panel",style:{width:"100%"},children:[s.jsx("div",{className:"ss-auth-section-label",children:"Your Organizations"}),s.jsx("div",{style:{padding:"0 8px 4px"},children:l.map(m=>{const j=(n==null?void 0:n.id)===m.id,O=m.name.split(" ").map(k=>k[0]).join("").slice(0,2).toUpperCase();return s.jsxs("button",{type:"button",className:`ss-auth-org-item${j?" ss-auth-org-item-active":""}`,onClick:async()=>{x(!1),await u(m.id),t==null||t(m)},children:[s.jsxs("div",{className:"ss-auth-org-item-inner",children:[s.jsx("div",{className:`ss-auth-org-avatar${j?"":" ss-auth-org-avatar-inactive"}`,children:O}),s.jsx("span",{style:{fontFamily:"'Manrope', sans-serif",letterSpacing:"-0.01em"},children:m.name})]}),j&&s.jsx("span",{className:"material-symbols-outlined ss-auth-org-check",style:{fontSize:"18px"},children:w.checkCircle})]},m.id)})}),s.jsxs("div",{className:"ss-auth-org-create",children:[s.jsxs("div",{className:"ss-auth-org-create-header",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.addCircle}),s.jsx("span",{children:"Create organization"})]}),b&&s.jsx("div",{className:"ss-auth-error",style:{marginBottom:"12px",fontSize:"12px"},children:s.jsx("span",{children:b})}),s.jsxs("form",{onSubmit:P,children:[s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",style:{fontSize:"10px"},children:"Org Name"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"e.g. Nexus Dynamics",value:p,onChange:m=>C(m.target.value),required:!0,style:{fontSize:"13px",padding:"10px 12px"}})]}),s.jsxs("div",{className:"ss-auth-field",children:[s.jsx("label",{className:"ss-auth-label",style:{fontSize:"10px"},children:"Workspace Slug"}),s.jsxs("div",{style:{position:"relative"},children:[s.jsx("span",{className:"ss-auth-org-slug-prefix",children:"/"}),s.jsx("input",{className:"ss-auth-input",type:"text",placeholder:"nexus-dynamics",value:y,onChange:m=>f(m.target.value),required:!0,style:{fontSize:"13px",padding:"10px 12px 10px 22px"}})]})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:v||!p.trim(),style:{marginTop:"8px"},children:[v&&s.jsx("span",{className:"ss-auth-spinner"}),"Initialize Organization"]})]})]})]})]})})}function As(e,t="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:e%100===0?0:2}).format(e/100)}function Ds({plans:e,currentPlanId:t,onSelectPlan:a,interval:l,appearance:n}){const{appearance:u}=B(),c=n??u,d=l?e.filter(i=>i.interval===l||i.isFree):e;return s.jsx(M,{appearance:c,children:s.jsx("div",{className:"ss-pricing-grid",children:d.map(i=>{const o=i.id===t;return s.jsxs("div",{className:`ss-pricing-card ${o?"ss-pricing-card-current":""}`,children:[s.jsxs("div",{className:"ss-pricing-header",children:[s.jsx("h3",{className:"ss-pricing-name",children:i.name}),i.trialDays>0&&s.jsxs("span",{className:"ss-badge ss-badge-trialing",children:[i.trialDays,"-day trial"]}),i.isFree&&s.jsx("span",{className:"ss-badge ss-badge-active",children:"Free"})]}),s.jsx("div",{className:"ss-pricing-price",children:i.isFree?s.jsx("span",{className:"ss-pricing-amount",children:"Free"}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ss-pricing-amount",children:As(i.amountCents,i.currency)}),s.jsxs("span",{className:"ss-pricing-interval",children:["/",i.interval]})]})}),i.description&&s.jsx("p",{className:"ss-pricing-desc",children:i.description}),i.features.length>0&&s.jsx("ul",{className:"ss-pricing-features",children:i.features.map((x,p)=>s.jsxs("li",{className:"ss-pricing-feature",children:[s.jsx("span",{className:"ss-check",children:"✓"})," ",x]},p))}),s.jsx("button",{type:"button",className:`ss-btn ${o?"ss-btn-current":"ss-btn-primary"}`,disabled:o,onClick:()=>a(i.id),children:o?"Current plan":"Select plan"})]},i.id)})})})}function Ms(){const{client:e}=B();return{billing:e.billing}}function _(e){const{client:t}=B();return r.useMemo(()=>{if(e){const a=new R.Transport("https://api.saas-support.com/v1",{type:"portalToken",token:e});return new R.BillingClient(a)}return t.billing},[t,e])}function is(e,t){const a=_(t),[l,n]=r.useState(null),[u,c]=r.useState(!0),[d,i]=r.useState(null),o=r.useCallback(async()=>{c(!0),i(null);try{const x=await a.getCustomer(e);n(x)}catch(x){i(x instanceof Error?x.message:"Failed to load subscription")}finally{c(!1)}},[a,e]);return r.useEffect(()=>{o()},[o]),{customer:l,isLoading:u,error:d,refresh:o}}function ls(e,t){const a=_(t),[l,n]=r.useState([]),[u,c]=r.useState(!0),[d,i]=r.useState(null),o=r.useCallback(async()=>{c(!0),i(null);try{const x=await a.getInvoices(e);n(x)}catch(x){i(x instanceof Error?x.message:"Failed to load invoices")}finally{c(!1)}},[a,e]);return r.useEffect(()=>{o()},[o]),{invoices:l,isLoading:u,error:d,refresh:o}}function cs(e,t){const a=_(t),[l,n]=r.useState([]),[u,c]=r.useState(!0),[d,i]=r.useState(null),o=r.useCallback(async()=>{c(!0),i(null);try{const x=await a.getCurrentUsage(e);n(x)}catch(x){i(x instanceof Error?x.message:"Failed to load usage")}finally{c(!1)}},[a,e]);return r.useEffect(()=>{o()},[o]),{usage:l,isLoading:u,error:d,refresh:o}}const Rs={active:"ss-badge-active"};function ds({customerId:e,portalToken:t,onChangePlan:a,onCancel:l,appearance:n}){const{appearance:u}=B(),{customer:c,isLoading:d,error:i}=is(e,t),o=n??u;return s.jsx(M,{appearance:o,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Subscription"}),d&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),i&&s.jsx("div",{className:"ss-global-error",children:i}),c&&!d&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Customer"}),s.jsx("input",{className:"ss-input",value:c.name||c.email,disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Status"}),s.jsx("div",{children:s.jsx("span",{className:`ss-badge ${Rs.active}`,children:"Active"})})]}),s.jsxs("div",{className:"ss-btn-group",children:[a&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-primary",onClick:a,children:"Change plan"}),l&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:l,children:"Cancel subscription"})]})]})]})})}const Us={paid:"ss-badge-active",open:"ss-badge-trialing",draft:"ss-badge-paused",void:"ss-badge-canceled",uncollectible:"ss-badge-past-due"};function Vs(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Hs(e){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(e/100)}function us({customerId:e,portalToken:t,appearance:a}){const{appearance:l}=B(),{invoices:n,isLoading:u,error:c}=ls(e,t),d=a??l,i=[...n].sort((o,x)=>new Date(x.createdAt).getTime()-new Date(o.createdAt).getTime());return s.jsx(M,{appearance:d,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Invoices"}),u&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),c&&s.jsx("div",{className:"ss-global-error",children:c}),!u&&i.length===0&&s.jsx("p",{className:"ss-empty",children:"No invoices yet."}),!u&&i.length>0&&s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{className:"ss-th",children:"Date"}),s.jsx("th",{className:"ss-th",children:"Amount"}),s.jsx("th",{className:"ss-th",children:"Status"}),s.jsx("th",{className:"ss-th",children:"PDF"})]})}),s.jsx("tbody",{children:i.map(o=>s.jsxs("tr",{className:"ss-tr",children:[s.jsx("td",{className:"ss-td",children:Vs(o.createdAt)}),s.jsx("td",{className:"ss-td",children:Hs(o.amountCents)}),s.jsx("td",{className:"ss-td",children:s.jsx("span",{className:`ss-badge ${Us[o.status]||""}`,children:o.status})}),s.jsx("td",{className:"ss-td",children:o.pdfUrl?s.jsx("a",{className:"ss-link",href:o.pdfUrl,target:"_blank",rel:"noopener noreferrer",children:"Download"}):"—"})]},o.id))})]})]})})}function ps({customerId:e,limits:t,portalToken:a,appearance:l}){const{appearance:n}=B(),{usage:u,isLoading:c,error:d}=cs(e,a),i=l??n;return s.jsx(M,{appearance:i,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Usage"}),c&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),!c&&u.length===0&&s.jsx("p",{className:"ss-empty",children:"No usage data."}),!c&&u.map(o=>{const x=t==null?void 0:t[o.metric],p=x?Math.min(100,o.total/x*100):null;return s.jsxs("div",{className:"ss-usage-item",children:[s.jsxs("div",{className:"ss-usage-header",children:[s.jsx("span",{className:"ss-usage-metric",children:o.metric}),s.jsxs("span",{className:"ss-usage-value",children:[o.total.toLocaleString(),x?` / ${x.toLocaleString()}`:""]})]}),p!==null&&s.jsx("div",{className:"ss-progress-bar",children:s.jsx("div",{className:`ss-progress-fill ${p>90?"ss-progress-danger":""}`,style:{width:`${p}%`}})})]},o.metric)})]})})}function qs({customerId:e,portalToken:t,limits:a,onChangePlan:l,onCancel:n,appearance:u}){const{appearance:c}=B(),d=u??c,[i,o]=r.useState("subscription"),x=[{id:"subscription",label:"Subscription"},{id:"invoices",label:"Invoices"},{id:"usage",label:"Usage"}];return s.jsx(M,{appearance:d,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Billing"}),s.jsx("div",{className:"ss-tab-group",children:x.map(p=>s.jsx("button",{type:"button",className:`ss-tab ${i===p.id?"ss-tab-active":""}`,onClick:()=>o(p.id),children:p.label},p.id))}),s.jsxs("div",{className:"ss-tab-content",children:[i==="subscription"&&s.jsx(ds,{customerId:e,portalToken:t,onChangePlan:l,onCancel:n}),i==="invoices"&&s.jsx(us,{customerId:e,portalToken:t}),i==="usage"&&s.jsx(ps,{customerId:e,portalToken:t,limits:a})]})]})})}function Ws({customerId:e,portalToken:t,onApplied:a,appearance:l}){const{appearance:n}=B(),u=_(t),c=l??n,[d,i]=r.useState(""),[o,x]=r.useState(!1),[p,h]=r.useState(null),[y,f]=r.useState(null),b=r.useCallback(async $=>{if($.preventDefault(),!!d.trim()){x(!0),h(null),f(null);try{const v=await u.applyCoupon(e,d.trim());f(`Coupon applied! ${v.discountType==="percent"?`${v.amount}% off`:`$${(v.amount/100).toFixed(2)} off`}`),i(""),a==null||a(v)}catch(v){h(v instanceof Error?v.message:"Invalid coupon code")}finally{x(!1)}}},[u,e,d,a]);return s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Apply coupon"}),p&&s.jsx("div",{className:"ss-global-error",children:p}),y&&s.jsx("div",{className:"ss-success-msg",children:y}),s.jsxs("form",{onSubmit:b,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-coupon-code",children:"Coupon code"}),s.jsx("input",{id:"ss-coupon-code",className:"ss-input",type:"text",placeholder:"Enter coupon code",value:d,onChange:$=>i($.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:o||!d.trim(),children:[o&&s.jsx("span",{className:"ss-spinner"}),"Apply"]})]})]})})}function _s(){const{client:e}=B();return{report:e.report}}function ss(){const{client:e}=B(),[t,a]=r.useState(null),[l,n]=r.useState(!1),[u,c]=r.useState(null),d=r.useCallback(async i=>{n(!0),c(null);try{const o=await e.report.executeQuery(i);return a(o),o}catch(o){return c(o instanceof Error?o.message:"Query failed"),null}finally{n(!1)}},[e]);return{result:t,execute:d,isLoading:l,error:u}}function hs(e){const{client:t}=B(),[a,l]=r.useState(null),[n,u]=r.useState(!0),[c,d]=r.useState(null),i=r.useCallback(async()=>{u(!0),d(null);try{const o=await t.report.listQueries(e);l(o)}catch(o){d(o instanceof Error?o.message:"Failed to load queries")}finally{u(!1)}},[t,e]);return r.useEffect(()=>{i()},[i]),{queries:(a==null?void 0:a.data)??[],meta:a==null?void 0:a.meta,isLoading:n,error:c,refresh:i}}function Gs(e){const{client:t}=B(),[a,l]=r.useState(null),[n,u]=r.useState(!0),[c,d]=r.useState(null),i=r.useCallback(async()=>{u(!0),d(null);try{const o=await t.report.getDashboard(e);l(o)}catch(o){d(o instanceof Error?o.message:"Failed to load dashboard")}finally{u(!1)}},[t,e]);return r.useEffect(()=>{i()},[i]),{dashboard:a,isLoading:n,error:c,refresh:i}}function Ys(e,t,a="https://api.saas-support.com/v1"){const l=r.useMemo(()=>{const p=new R.Transport(a,{type:"embedToken",token:e});return new R.ReportClient(p)},[e,a]),[n,u]=r.useState(null),[c,d]=r.useState(!0),[i,o]=r.useState(null),x=r.useCallback(async()=>{d(!0),o(null);try{const p=await l.getDashboard(t);u(p)}catch(p){o(p instanceof Error?p.message:"Failed to load dashboard")}finally{d(!1)}},[l,t]);return r.useEffect(()=>{x()},[x]),{dashboard:n,reportClient:l,isLoading:c,error:i,refresh:x}}function Qs({onResult:e,mode:t="both",placeholder:a,appearance:l}){const{appearance:n}=B(),{execute:u,isLoading:c,error:d}=ss(),i=l??n,[o,x]=r.useState(""),[p,h]=r.useState(t==="sql"?"sql":"nl"),y=r.useCallback(async f=>{if(f.preventDefault(),!o.trim())return;const $=await u(p==="sql"?{sql:o}:{naturalLanguage:o});$&&(e==null||e($))},[o,p,u,e]);return s.jsx(M,{appearance:i,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[t==="both"&&s.jsxs("div",{className:"ss-tab-group ss-tab-group-sm",children:[s.jsx("button",{type:"button",className:`ss-tab ${p==="nl"?"ss-tab-active":""}`,onClick:()=>h("nl"),children:"Natural Language"}),s.jsx("button",{type:"button",className:`ss-tab ${p==="sql"?"ss-tab-active":""}`,onClick:()=>h("sql"),children:"SQL"})]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),s.jsxs("form",{onSubmit:y,children:[s.jsx("div",{className:"ss-field",children:s.jsx("textarea",{className:"ss-input ss-query-textarea",placeholder:a??(p==="sql"?"SELECT ...":"Ask a question about your data..."),value:o,onChange:f=>x(f.target.value),rows:3})}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:c||!o.trim(),children:[c&&s.jsx("span",{className:"ss-spinner"}),"Run query"]})]})]})})}function xs({columns:e,rows:t,sortable:a=!0,maxRows:l,appearance:n}){const{appearance:u}=B(),c=n??u,[d,i]=r.useState(null),[o,x]=r.useState("asc"),p=r.useMemo(()=>d?[...t].sort((b,$)=>{const v=b[d],z=$[d];if(v==null&&z==null)return 0;if(v==null)return 1;if(z==null)return-1;if(typeof v=="number"&&typeof z=="number")return o==="asc"?v-z:z-v;const N=String(v),g=String(z);return o==="asc"?N.localeCompare(g):g.localeCompare(N)}):t,[t,d,o]),h=l?p.slice(0,l):p,y=b=>{a&&(d===b?x($=>$==="asc"?"desc":"asc"):(i(b),x("asc")))};function f(b){return b==null?"":typeof b=="object"?JSON.stringify(b):String(b)}return s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-table-container",children:[s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsx("tr",{children:e.map(b=>s.jsxs("th",{className:`ss-th ${a?"ss-th-sortable":""} ${d===b?o==="asc"?"ss-sorted-asc":"ss-sorted-desc":""}`,onClick:()=>y(b),children:[b,d===b&&s.jsx("span",{className:"ss-sort-indicator",children:o==="asc"?" ▲":" ▼"})]},b))})}),s.jsx("tbody",{children:h.map((b,$)=>s.jsx("tr",{className:"ss-tr",children:e.map(v=>s.jsx("td",{className:"ss-td",children:f(b[v])},v))},$))})]}),l&&t.length>l&&s.jsxs("div",{className:"ss-table-footer",children:["Showing ",l," of ",t.length," rows"]})]})})}function Js(e,t="#6366f1"){const a=parseInt(t.replace("#","").slice(0,2),16),l=[];for(let n=0;n<e;n++){const u=(a+n*Math.floor(360/Math.max(e,1)))%360;l.push(`hsl(${u}, 65%, 55%)`)}return l}function Zs({labels:e,values:t,w:a,h:l,colors:n}){const u=Math.max(...t,1),c=40,d=a-c*2,i=l-c*2,o=Math.max(1,d/e.length-4);return s.jsxs("g",{children:[s.jsx("line",{x1:c,y1:l-c,x2:a-c,y2:l-c,stroke:"#ccc",strokeWidth:1}),t.map((x,p)=>{const h=x/u*i,y=c+d/e.length*p+2,f=l-c-h;return s.jsxs("g",{children:[s.jsx("rect",{x:y,y:f,width:o,height:h,fill:n[p%n.length],rx:2}),s.jsx("text",{x:y+o/2,y:l-c+14,textAnchor:"middle",fontSize:10,fill:"#666",children:e[p].length>8?e[p].slice(0,8)+"...":e[p]})]},p)})]})}function Ks({labels:e,values:t,w:a,h:l,colors:n}){const u=Math.max(...t,1),c=40,d=a-c*2,i=l-c*2,o=e.length>1?d/(e.length-1):0,x=t.map((p,h)=>{const y=c+o*h,f=l-c-p/u*i;return`${y},${f}`});return s.jsxs("g",{children:[[.25,.5,.75,1].map(p=>{const h=l-c-p*i;return s.jsx("line",{x1:c,y1:h,x2:a-c,y2:h,stroke:"#eee",strokeWidth:1},p)}),s.jsx("polyline",{points:x.join(" "),fill:"none",stroke:n[0],strokeWidth:2}),t.map((p,h)=>{const y=c+o*h,f=l-c-p/u*i;return s.jsx("circle",{cx:y,cy:f,r:4,fill:n[0]},h)})]})}function Xs({labels:e,values:t,w:a,h:l,colors:n}){const u=t.reduce((h,y)=>h+y,0)||1,c=a/2,d=l/2-20,i=Math.min(a,l)/2-40,o=2*Math.PI*i;let x=0;const p=t.map((h,y)=>{const f=h/u,b=f*o,$={dash:b,offset:x,color:n[y%n.length],label:e[y],pct:f};return x+=b,$});return s.jsxs("g",{children:[p.map((h,y)=>s.jsx("circle",{cx:c,cy:d,r:i,fill:"none",stroke:h.color,strokeWidth:i*.6,strokeDasharray:`${h.dash} ${o-h.dash}`,strokeDashoffset:-h.offset,transform:`rotate(-90 ${c} ${d})`},y)),s.jsx("g",{transform:`translate(${c-e.length*30}, ${l-20})`,children:p.slice(0,6).map((h,y)=>s.jsxs("g",{transform:`translate(${y*60}, 0)`,children:[s.jsx("rect",{width:10,height:10,fill:h.color,rx:2}),s.jsx("text",{x:14,y:9,fontSize:9,fill:"#666",children:h.label.length>6?h.label.slice(0,6)+"..":h.label})]},y))})]})}function gs({type:e,data:t,title:a,width:l=400,height:n=300,appearance:u}){const{appearance:c}=B(),d=u??c,i=r.useMemo(()=>Js(t.labels.length),[t.labels.length]);return s.jsx(M,{appearance:d,children:s.jsxs("div",{className:"ss-chart-container",children:[a&&s.jsx("h3",{className:"ss-chart-title",children:a}),s.jsxs("svg",{viewBox:`0 0 ${l} ${n}`,width:"100%",style:{maxWidth:l},children:[e==="bar"&&s.jsx(Zs,{labels:t.labels,values:t.values,w:l,h:n,colors:i}),e==="line"&&s.jsx(Ks,{labels:t.labels,values:t.values,w:l,h:n,colors:i}),e==="pie"&&s.jsx(Xs,{labels:t.labels,values:t.values,w:l,h:n,colors:i})]})]})})}function se({dashboardId:e,embedToken:t,baseUrl:a,refreshInterval:l,appearance:n}){const u=B(),c=n??(u==null?void 0:u.appearance),d=r.useMemo(()=>{if(t){const v=a??"https://api.saas-support.com/v1",z=new R.Transport(v,{type:"embedToken",token:t});return new R.ReportClient(z)}return u.client.report},[t,a,u]),[i,o]=r.useState([]),[x,p]=r.useState({}),[h,y]=r.useState(!0),[f,b]=r.useState(null),$=r.useCallback(async()=>{y(!0),b(null);try{const v=await d.getDashboard(e),z=JSON.parse(v.layoutJson||"[]");o(z);const N={};for(const g of z)try{const C=await d.listQueries({search:g.queryId,perPage:1});if(C.data.length>0&&C.data[0].generatedSql){const P=await d.executeQuery({sql:C.data[0].generatedSql});N[g.queryId]=P}}catch{}p(N)}catch(v){b(v instanceof Error?v.message:"Failed to load dashboard")}finally{y(!1)}},[d,e]);return r.useEffect(()=>{$()},[$]),r.useEffect(()=>{if(!l||l<=0)return;const v=setInterval($,l*1e3);return()=>clearInterval(v)},[l,$]),s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-dashboard-grid",children:[h&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading dashboard..."]}),f&&s.jsx("div",{className:"ss-global-error",children:f}),!h&&i.map((v,z)=>{const N=x[v.queryId];if(!N)return null;const g=N.columns.length>=2?{labels:N.rows.map(C=>String(C[N.columns[0]]??"")),values:N.rows.map(C=>Number(C[N.columns[1]]??0))}:{labels:[],values:[]};return s.jsxs("div",{className:"ss-widget",children:[v.title&&s.jsx("h4",{className:"ss-widget-header",children:v.title}),v.chartType==="table"?s.jsx(xs,{columns:N.columns,rows:N.rows,maxRows:50}):s.jsx(gs,{type:v.chartType||"bar",data:g,width:v.w,height:v.h})]},z)})]})})}function ee(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function ae({onSelectQuery:e,onRunQuery:t,appearance:a}){const{appearance:l}=B(),{queries:n,isLoading:u,error:c}=hs(),{execute:d,isLoading:i}=ss(),o=a??l,x=r.useCallback(async p=>{if(!p.generatedSql)return;const h=await d({sql:p.generatedSql});h&&(t==null||t(h))},[d,t]);return s.jsx(M,{appearance:o,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Saved Queries"}),u&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),c&&s.jsx("div",{className:"ss-global-error",children:c}),!u&&n.length===0&&s.jsx("p",{className:"ss-empty",children:"No saved queries."}),!u&&n.map(p=>s.jsxs("div",{className:"ss-saved-query-card",onClick:()=>e==null?void 0:e(p),children:[s.jsxs("div",{className:"ss-saved-query-header",children:[s.jsx("span",{className:"ss-saved-query-name",children:p.name}),p.chartType&&s.jsx("span",{className:"ss-badge",children:p.chartType})]}),p.naturalLanguage&&s.jsx("p",{className:"ss-saved-query-desc",children:p.naturalLanguage}),s.jsxs("div",{className:"ss-saved-query-footer",children:[s.jsx("span",{className:"ss-saved-query-date",children:ee(p.createdAt)}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:i||!p.generatedSql,onClick:h=>{h.stopPropagation(),x(p)},children:i?s.jsx("span",{className:"ss-spinner"}):"Run"})]})]},p.id))]})})}function te({embedToken:e,dashboardId:t,baseUrl:a="https://api.saas-support.com/v1",refreshInterval:l,appearance:n}){const u=r.useMemo(()=>{const b=new R.Transport(a,{type:"embedToken",token:e});return new R.ReportClient(b)},[e,a]),[c,d]=r.useState([]),[i,o]=r.useState(!0),[x,p]=r.useState(null),h=r.useMemo(()=>Q(n),[n]),y=r.useMemo(()=>J(h),[h]),f=r.useCallback(async()=>{o(!0),p(null);try{const b=await u.getDashboard(t),$=JSON.parse(b.layoutJson||"[]"),v=await Promise.all($.map(async z=>{try{const N=await u.listQueries({search:z.queryId,perPage:1});if(N.data.length>0&&N.data[0].generatedSql){const g=await u.executeQuery({sql:N.data[0].generatedSql});return{...z,result:g}}}catch{}return z}));d(v)}catch(b){p(b instanceof Error?b.message:"Failed to load dashboard")}finally{o(!1)}},[u,t]);return r.useEffect(()=>{f()},[f]),r.useEffect(()=>{if(!l||l<=0)return;const b=setInterval(f,l*1e3);return()=>clearInterval(b)},[l,f]),s.jsx("div",{ref:b=>{if(!b||b.shadowRoot)return;const $=b.attachShadow({mode:"open"}),v=document.createElement("style");v.textContent=y,$.appendChild(v);const z=document.createElement("div");$.appendChild(z)},style:{display:"contents"},children:s.jsxs("div",{className:"ss-dashboard-grid",children:[i&&s.jsx("div",{className:"ss-loading",children:"Loading dashboard..."}),x&&s.jsx("div",{className:"ss-global-error",children:x}),!i&&c.map((b,$)=>{if(!b.result)return null;const{columns:v,rows:z}=b.result;return s.jsxs("div",{className:"ss-widget",children:[b.title&&s.jsx("h4",{className:"ss-widget-header",children:b.title}),s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsx("tr",{children:v.map(N=>s.jsx("th",{className:"ss-th",children:N},N))})}),s.jsx("tbody",{children:z.slice(0,50).map((N,g)=>s.jsx("tr",{className:"ss-tr",children:v.map(C=>s.jsx("td",{className:"ss-td",children:String(N[C]??"")},C))},g))})]})]},$)})]})})}exports.SaaSError=R.SaaSError;exports.SaaSSupport=R.SaaSSupport;exports.isMfaRequired=R.isMfaRequired;exports.Chart=gs;exports.CouponInput=Ws;exports.DashboardView=se;exports.DataTable=xs;exports.InvoiceHistory=us;exports.OrgSwitcher=Ts;exports.PaymentPortal=qs;exports.PricingTable=Ds;exports.QueryInput=Qs;exports.ReportEmbed=te;exports.SaaSContext=Z;exports.SaaSProvider=vs;exports.SavedQueryList=ae;exports.SettingsPanel=os;exports.SignIn=Cs;exports.SignUp=zs;exports.SubscriptionStatus=ds;exports.UsageDisplay=ps;exports.UserButton=Bs;exports.UserProfile=Ls;exports.useAuth=W;exports.useBilling=Ms;exports.useDashboard=Gs;exports.useDeleteAccount=as;exports.useEmbedDashboard=Ys;exports.useInvoices=ls;exports.useOrg=H;exports.useProfile=X;exports.useQuery=ss;exports.useReport=_s;exports.useSaaSContext=B;exports.useSavedQueries=hs;exports.useSignIn=K;exports.useSignUp=es;exports.useSubscription=is;exports.useUsage=cs;exports.useUser=$s;
|
package/dist/react.d.ts
CHANGED
|
@@ -27,8 +27,10 @@ declare class AuthClient {
|
|
|
27
27
|
private cachedUser;
|
|
28
28
|
private cachedSettings;
|
|
29
29
|
private loaded;
|
|
30
|
+
private loadPromise;
|
|
30
31
|
constructor(transport: Transport, tokenManager: TokenManager | null, emitter: EventEmitter<SaaSEvents>, baseUrl: string);
|
|
31
32
|
load(): Promise<void>;
|
|
33
|
+
private doLoad;
|
|
32
34
|
signIn(email: string, password: string): Promise<AuthResult>;
|
|
33
35
|
signUp(email: string, password: string): Promise<SignUpResult>;
|
|
34
36
|
signOut(): Promise<void>;
|
|
@@ -543,6 +545,7 @@ export declare class SaaSSupport {
|
|
|
543
545
|
private tokenManager;
|
|
544
546
|
private emitter;
|
|
545
547
|
private loaded;
|
|
548
|
+
private loadPromise;
|
|
546
549
|
constructor(options: SaaSOptions);
|
|
547
550
|
load(): Promise<void>;
|
|
548
551
|
isLoaded(): boolean;
|
|
@@ -569,12 +572,14 @@ export declare interface SavedQueryListProps {
|
|
|
569
572
|
appearance?: Appearance;
|
|
570
573
|
}
|
|
571
574
|
|
|
572
|
-
export declare function SettingsPanel({ onClose, afterDeleteAccountUrl, defaultTab }: SettingsPanelProps): JSX_2.Element;
|
|
575
|
+
export declare function SettingsPanel({ onClose, afterDeleteAccountUrl, defaultTab, onOrgDeleted, onOrgUpdated }: SettingsPanelProps): JSX_2.Element;
|
|
573
576
|
|
|
574
577
|
export declare interface SettingsPanelProps {
|
|
575
578
|
onClose: () => void;
|
|
576
579
|
afterDeleteAccountUrl?: string;
|
|
577
580
|
defaultTab?: SettingsTab;
|
|
581
|
+
onOrgDeleted?: () => void;
|
|
582
|
+
onOrgUpdated?: () => void;
|
|
578
583
|
}
|
|
579
584
|
|
|
580
585
|
declare type SettingsTab = 'profile' | 'organization' | 'people' | 'billing';
|