@saas-support/react 0.7.5 → 0.7.6

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/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"),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`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),t=require("react"),R=require("./index.cjs"),vs=require("react-dom"),K=t.createContext(null);function A(){const e=t.useContext(K);if(!e)throw new Error("useSaaSContext must be used within a <SaaSProvider>");return e}function ws({publishableKey:e,apiKey:r,baseUrl:a,appearance:i,children:n}){const[u]=t.useState(()=>new R.SaaSSupport({publishableKey:e,apiKey:r,baseUrl:a})),[l,d]=t.useState(null),[c,o]=t.useState(!1),[x,p]=t.useState(null);return t.useEffect(()=>{let h=!1;u.load().then(async()=>{if(h)return;const f=await u.auth.getUser(),y=await u.auth.getSettings();d(f),p(y),o(!0)});const b=u.auth.onAuthStateChange(f=>{h||d(f)});return()=>{h=!0,b(),u.destroy()}},[u]),s.jsx(K.Provider,{value:{client:u,user:l,isLoaded:c,appearance:i,settings:x},children:n})}const Ss={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"},Ns={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 J(e){const r=(e==null?void 0:e.baseTheme)==="dark"?Ns:Ss,a=e==null?void 0:e.variables,i=(a==null?void 0:a.colorPrimary)??r.authPrimary;return{colorPrimary:(a==null?void 0:a.colorPrimary)??r.colorPrimary,colorPrimaryHover:a!=null&&a.colorPrimary?ks(a.colorPrimary,10):r.colorPrimaryHover,colorBackground:(a==null?void 0:a.colorBackground)??r.colorBackground,colorText:(a==null?void 0:a.colorText)??r.colorText,colorTextSecondary:r.colorTextSecondary,colorInputBackground:(a==null?void 0:a.colorInputBackground)??r.colorInputBackground,colorInputBorder:(a==null?void 0:a.colorInputBorder)??r.colorInputBorder,colorError:(a==null?void 0:a.colorError)??r.colorError,colorSuccess:(a==null?void 0:a.colorSuccess)??r.colorSuccess,colorWarning:(a==null?void 0:a.colorWarning)??r.colorWarning,fontFamily:(a==null?void 0:a.fontFamily)??r.fontFamily,borderRadius:(a==null?void 0:a.borderRadius)??r.borderRadius,authPrimary:i,authPrimaryContainer:a!=null&&a.colorPrimary?$s(i,15):r.authPrimaryContainer,authOnPrimary:r.authOnPrimary,authPrimaryFixed:r.authPrimaryFixed,authSurface:(a==null?void 0:a.colorBackground)??r.authSurface,authSurfaceContainerLowest:r.authSurfaceContainerLowest,authSurfaceContainerLow:(a==null?void 0:a.colorInputBackground)??r.authSurfaceContainerLow,authSurfaceContainer:r.authSurfaceContainer,authSurfaceContainerHigh:r.authSurfaceContainerHigh,authSurfaceContainerHighest:r.authSurfaceContainerHighest,authOnSurface:(a==null?void 0:a.colorText)??r.authOnSurface,authOnSurfaceVariant:r.authOnSurfaceVariant,authOutline:r.authOutline,authOutlineVariant:(a==null?void 0:a.colorInputBorder)??r.authOutlineVariant,authError:(a==null?void 0:a.colorError)??r.authError,authErrorContainer:r.authErrorContainer,authSuccess:(a==null?void 0:a.colorSuccess)??r.authSuccess,authFontHeadline:(a==null?void 0:a.fontFamily)??r.authFontHeadline,authFontBody:(a==null?void 0:a.fontFamily)??r.authFontBody}}function ks(e,r){const a=parseInt(e.replace("#",""),16),i=Math.max(0,(a>>16)-Math.round(2.55*r)),n=Math.max(0,(a>>8&255)-Math.round(2.55*r)),u=Math.max(0,(a&255)-Math.round(2.55*r));return`#${(i<<16|n<<8|u).toString(16).padStart(6,"0")}`}function $s(e,r){const a=parseInt(e.replace("#",""),16),i=Math.min(255,(a>>16)+Math.round(2.55*r)),n=Math.min(255,(a>>8&255)+Math.round(2.55*r)),u=Math.min(255,(a&255)+Math.round(2.55*r));return`#${(i<<16|n<<8|u).toString(16).padStart(6,"0")}`}function Z(e){return`
2
2
  :host {
3
3
  all: initial;
4
4
  font-family: ${e.fontFamily};
@@ -1306,11 +1306,31 @@
1306
1306
  height: 40px;
1307
1307
  border-radius: 50%;
1308
1308
  border: 2px solid ${e.authPrimary};
1309
- overflow: hidden;
1309
+ overflow: visible;
1310
1310
  transition: transform 0.15s, box-shadow 0.15s;
1311
1311
  padding: 0;
1312
1312
  background: none;
1313
1313
  flex-shrink: 0;
1314
+ position: relative;
1315
+ }
1316
+
1317
+ .ss-auth-invite-badge {
1318
+ position: absolute;
1319
+ top: -4px;
1320
+ right: -4px;
1321
+ min-width: 18px;
1322
+ height: 18px;
1323
+ border-radius: 9px;
1324
+ font-size: 10px;
1325
+ font-weight: 700;
1326
+ display: flex;
1327
+ align-items: center;
1328
+ justify-content: center;
1329
+ background: ${e.authError||"#ef4444"};
1330
+ color: #fff;
1331
+ padding: 0 4px;
1332
+ line-height: 1;
1333
+ pointer-events: none;
1314
1334
  }
1315
1335
 
1316
1336
  .ss-auth-avatar-trigger img {
@@ -2354,4 +2374,4 @@
2354
2374
  .ss-auth-trigger-org-name { display: none; }
2355
2375
  .ss-auth-user-trigger { padding: 0; border: none; background: none; }
2356
2376
  }
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;
2377
+ `}function M({children:e,appearance:r}){const a=t.useRef(null),[i,n]=t.useState(null);t.useEffect(()=>{var x;if(!a.current||a.current.shadowRoot){n(((x=a.current)==null?void 0:x.shadowRoot)??null);return}const l=a.current.attachShadow({mode:"open"});if((r==null?void 0:r.fontUrl)!==null){const p=(r==null?void 0:r.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 b=document.createElement("link");b.rel="stylesheet",b.href=p,document.head.appendChild(b)}const h=document.createElement("link");h.rel="stylesheet",h.href=p,l.appendChild(h)}const d=J(r),c=document.createElement("style");c.textContent=Z(d),l.appendChild(c);const o=document.createElement("div");l.appendChild(o),n(l)},[]),t.useEffect(()=>{if(!i)return;const l=i.querySelector("style");if(l){const d=J(r);l.textContent=Z(d)}},[r,i]);const u=(i==null?void 0:i.querySelector("div"))??null;return s.jsx("div",{ref:a,style:{display:"contents"},children:u&&vs.createPortal(e,u)})}function W(){const{client:e,user:r,isLoaded:a}=A();return{isLoaded:a,isSignedIn:!!r,user:r,signOut:t.useCallback(()=>e.auth.signOut(),[e]),getToken:t.useCallback(()=>e.auth.getToken(),[e]),refreshUser:t.useCallback(()=>e.auth.refreshUser(),[e])}}function Cs(){const{user:e,isLoaded:r}=A();return{user:e,isLoaded:r}}function X(){const{client:e}=A(),[r,a]=t.useState(!1),[i,n]=t.useState(null),u=t.useCallback(async(c,o)=>{a(!0),n(null);try{return await e.auth.signIn(c,o)}catch(x){return n(x instanceof Error?x.message:"Sign in failed"),null}finally{a(!1)}},[e]),l=t.useCallback(async c=>{a(!0),n(null);try{return await e.auth.signInWithOAuth(c)}catch(o){return n(o instanceof Error?o.message:"OAuth sign in failed"),null}finally{a(!1)}},[e]),d=t.useCallback(async(c,o)=>{a(!0),n(null);try{return await e.auth.submitMfaCode(c,o)}catch(x){return n(x instanceof Error?x.message:"MFA verification failed"),null}finally{a(!1)}},[e]);return{signIn:u,signInWithOAuth:l,submitMfaCode:d,isLoading:r,error:i,setError:n}}function as(){const{client:e}=A(),[r,a]=t.useState(!1),[i,n]=t.useState(null);return{signUp:t.useCallback(async(l,d)=>{a(!0),n(null);try{return await e.auth.signUp(l,d)}catch(c){return n(c instanceof Error?c.message:"Sign up failed"),null}finally{a(!1)}},[e]),isLoading:r,error:i,setError:n}}function H(){const{client:e}=A(),[r,a]=t.useState([]),[i,n]=t.useState(null),[u,l]=t.useState([]),[d,c]=t.useState([]),[o,x]=t.useState(!1),[p,h]=t.useState(null),b=t.useRef(!1),f=t.useCallback(async()=>{x(!0),h(null);try{const m=await e.auth.listOrgs();if(a(m),n(j=>j&&(m.find(O=>O.id===j.id)??null)),!b.current&&m.length>0){const j=typeof window<"u"?localStorage.getItem("ss_selected_org"):null,O=(j?m.find(E=>E.id===j):null)??(m.length===1?m[0]:null);if(O){b.current=!0,n(O),typeof window<"u"&&localStorage.setItem("ss_selected_org",O.id);try{const E=await e.auth.listMembers(O.id);l(E)}catch{}}}}catch(m){h(m instanceof Error?m.message:"Failed to load organizations")}finally{x(!1)}},[e]);t.useEffect(()=>{f()},[f]);const y=t.useCallback(async m=>{try{const j=await e.auth.getOrg(m);n(j),typeof window<"u"&&localStorage.setItem("ss_selected_org",m);const z=await e.auth.listMembers(m);l(z)}catch(j){h(j instanceof Error?j.message:"Failed to load organization")}},[e]),k=t.useCallback(async(m,j)=>{try{const z=await e.auth.createOrg(m,j);return a(O=>[...O,z]),z}catch(z){return h(z instanceof Error?z.message:"Failed to create organization"),null}},[e]),v=t.useCallback(async(m,j)=>{try{const z=await e.auth.updateOrg(m,j);return a(O=>O.map(E=>E.id===m?z:E)),(i==null?void 0:i.id)===m&&n(z),z}catch(z){return h(z instanceof Error?z.message:"Failed to update organization"),null}},[e,i]),C=t.useCallback(async m=>{try{return await e.auth.deleteOrg(m),a(j=>j.filter(z=>z.id!==m)),(i==null?void 0:i.id)===m&&(n(null),l([]),c([]),typeof window<"u"&&localStorage.removeItem("ss_selected_org")),!0}catch(j){return h(j instanceof Error?j.message:"Failed to delete organization"),!1}},[e,i]),N=t.useCallback(async(m,j,z)=>{try{return await e.auth.sendInvite(m,j,z)}catch(O){return h(O instanceof Error?O.message:"Failed to send invite"),null}},[e]),g=t.useCallback(async m=>{try{const j=await e.auth.listInvites(m);c(j)}catch(j){h(j instanceof Error?j.message:"Failed to load invites")}},[e]),$=t.useCallback(async(m,j)=>{try{return await e.auth.revokeInvite(m,j),c(z=>z.filter(O=>O.id!==j)),!0}catch(z){return h(z instanceof Error?z.message:"Failed to revoke invite"),!1}},[e]),P=t.useCallback(async(m,j,z)=>{try{return await e.auth.updateMemberRole(m,j,z),l(O=>O.map(E=>E.userId===j?{...E,role:z}:E)),!0}catch(O){return h(O instanceof Error?O.message:"Failed to update member role"),!1}},[e]),I=t.useCallback(async(m,j)=>{try{return await e.auth.removeMember(m,j),l(z=>z.filter(O=>O.userId!==j)),!0}catch(z){return h(z instanceof Error?z.message:"Failed to remove member"),!1}},[e]),F=t.useCallback(async m=>{try{const j=await e.auth.listMembers(m);l(j)}catch(j){h(j instanceof Error?j.message:"Failed to load members")}},[e]);return{orgs:r,selectedOrg:i,members:u,invites:d,isLoading:o,error:p,setError:h,refresh:f,selectOrg:y,createOrg:k,updateOrg:v,deleteOrg:C,sendInvite:N,refreshInvites:g,revokeInvite:$,updateMemberRole:P,removeMember:I,refreshMembers:F}}function ts(){const{client:e}=A(),[r,a]=t.useState(!1),[i,n]=t.useState(null);return{deleteAccount:t.useCallback(async()=>{a(!0),n(null);try{return await e.auth.deleteAccount(),!0}catch(l){return n(l instanceof Error?l.message:"Failed to delete account"),!1}finally{a(!1)}},[e]),isLoading:r,error:i,setError:n}}function ss(){const{client:e,user:r}=A(),[a,i]=t.useState(!1),[n,u]=t.useState(null),[l,d]=t.useState(null),c=t.useCallback(async p=>{i(!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{i(!1)}},[e]),o=t.useCallback(async(p,h)=>{i(!0),u(null),d(null);try{return await e.auth.changePassword(p,h),d("Password changed successfully"),!0}catch(b){return u(b instanceof Error?b.message:"Failed to change password"),!1}finally{i(!1)}},[e]),x=t.useCallback(async p=>{i(!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{i(!1)}},[e]);return{user:r,updateProfile:c,uploadAvatar:x,changePassword:o,isLoading:a,error:n,success:l,setError:u,setSuccess:d}}function _(){const{client:e}=A(),[r,a]=t.useState([]),[i,n]=t.useState(!1),[u,l]=t.useState(null),d=t.useCallback(async()=>{n(!0),l(null);try{const x=await e.auth.listMyInvites();a(x)}catch(x){l(x instanceof Error?x.message:"Failed to load invites")}finally{n(!1)}},[e]);t.useEffect(()=>{d()},[d]);const c=t.useCallback(async x=>{try{const p=await e.auth.acceptInviteById(x);return a(h=>h.filter(b=>b.id!==x)),p}catch(p){return l(p instanceof Error?p.message:"Failed to accept invite"),null}},[e]),o=t.useCallback(async x=>{try{return await e.auth.declineInvite(x),a(p=>p.filter(h=>h.id!==x)),!0}catch(p){return l(p instanceof Error?p.message:"Failed to decline invite"),!1}},[e]);return{invites:r,isLoading:i,error:u,setError:l,refresh:d,accept:c,decline:o}}const rs='<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>',ns='<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",mail:"mail",cloudDone:"cloud_done",check:"check",image:"image",settings:"settings",group:"group",creditCard:"credit_card",edit:"edit",send:"send",personRemove:"person_remove"};function zs({appearance:e,signUpUrl:r,onSignUp:a}){const{appearance:i,settings:n}=A(),{signIn:u,signInWithOAuth:l,submitMfaCode:d,isLoading:c,error:o,setError:x}=X(),p=e??i,[h,b]=t.useState(""),[f,y]=t.useState(""),[k,v]=t.useState(!1),[C,N]=t.useState(!1),[g,$]=t.useState(""),[P,I]=t.useState(["","","","","",""]),F=t.useRef([]),m=t.useCallback(async B=>{if(B.preventDefault(),C){await d(g,P.join(""));return}const S=await u(h,f);S&&R.isMfaRequired(S)&&($(S.mfaToken),N(!0),x(null))},[h,f,C,g,P,u,d,x]),j=t.useCallback(async B=>{await l(B)},[l]),z=t.useCallback((B,S)=>{var V;if(!/^\d*$/.test(S))return;const L=S.slice(-1);I(Y=>{const q=[...Y];return q[B]=L,q}),L&&B<5&&((V=F.current[B+1])==null||V.focus())},[]),O=t.useCallback((B,S)=>{var L;S.key==="Backspace"&&!P[B]&&B>0&&((L=F.current[B-1])==null||L.focus())},[P]),E=(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"})]}),!C&&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:()=>j("google"),disabled:c,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:rs}}),"Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>j("github"),disabled:c,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:ns}}),"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:[C?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((B,S)=>s.jsx("input",{ref:L=>{F.current[S]=L},className:"ss-auth-mfa-digit",type:"text",inputMode:"numeric",maxLength:1,value:B,onChange:L=>z(S,L.target.value),onKeyDown:L=>O(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:B=>b(B.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:k?"text":"password",autoComplete:"current-password",placeholder:"••••••••",value:f,onChange:B=>y(B.target.value),required:!0}),s.jsx("button",{type:"button",className:"ss-auth-visibility-toggle",onClick:()=>v(!k),children:s.jsx("span",{className:"material-symbols-outlined",children:k?w.visibilityOff:w.visibility})})]})]})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:c,children:[c&&s.jsx("span",{className:"ss-auth-spinner"}),C?"Verify":"Sign in",!c&&s.jsx("span",{className:"material-symbols-outlined",children:w.arrowForward})]})]}),C?s.jsx("div",{className:"ss-auth-footer",children:s.jsx("span",{className:"ss-auth-link",onClick:()=>{N(!1),I(["","","","","",""]),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"}):r?s.jsx("a",{className:"ss-auth-link",href:r,children:"Sign up"}):s.jsx("span",{className:"ss-auth-link",children:"Sign up"})]})]})})})}function Ps({appearance:e,signInUrl:r,onSignIn:a}){const{appearance:i,settings:n}=A(),{signUp:u,isLoading:l,error:d,setError:c}=as(),{signInWithOAuth:o}=X(),x=e??i,[p,h]=t.useState(""),[b,f]=t.useState(""),[y,k]=t.useState(""),[v,C]=t.useState(!1),[N,g]=t.useState(null),$=t.useCallback(async m=>{if(m.preventDefault(),g(null),b!==y){g("Passwords do not match");return}const j=(n==null?void 0:n.passwordMinLength)??8;if(b.length<j){g(`Password must be at least ${j} characters`);return}await u(p,b)},[p,b,y,n,u]),P=t.useCallback(async m=>{await o(m)},[o]),I=(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:[I&&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:l,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:rs}}),"Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-auth-btn-social",onClick:()=>P("github"),disabled:l,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:ns}}),"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:$,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:b,onChange:m=>{f(m.target.value),g(null)},required:!0}),s.jsx("button",{type:"button",className:"ss-auth-visibility-toggle",onClick:()=>C(!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:y,onChange:m=>{k(m.target.value),g(null)},required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-auth-btn-primary",disabled:l,children:[l&&s.jsx("span",{className:"ss-auth-spinner"}),"Sign up",!l&&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"}):r?s.jsx("a",{className:"ss-auth-link",href:r,children:"Sign in"}):s.jsx("span",{className:"ss-auth-link",children:"Sign in"})]})]})})]})})}const D=320,U=128,Os=t.forwardRef(function({file:r,onCrop:a,onCancel:i},n){const u=t.useRef(null),l=t.useRef(null),[d,c]=t.useState(1),[o,x]=t.useState({x:0,y:0}),[p,h]=t.useState(!1),b=t.useRef({x:0,y:0,ox:0,oy:0}),[f,y]=t.useState(!1);t.useEffect(()=>{const g=new Image,$=URL.createObjectURL(r);return g.onload=()=>{l.current=g,y(!0),x({x:0,y:0}),c(1)},g.src=$,()=>URL.revokeObjectURL($)},[r]),t.useEffect(()=>{if(!f||!l.current||!u.current)return;const g=u.current.getContext("2d");if(!g)return;const $=l.current;g.clearRect(0,0,D,D),g.fillStyle="#111",g.fillRect(0,0,D,D);const P=Math.max(D/$.width,D/$.height)*d,I=$.width*P,F=$.height*P,m=(D-I)/2+o.x,j=(D-F)/2+o.y;g.save(),g.beginPath(),g.arc(D/2,D/2,U,0,Math.PI*2),g.clip(),g.drawImage($,m,j,I,F),g.restore(),g.save(),g.fillStyle="rgba(0, 0, 0, 0.6)",g.fillRect(0,0,D,D),g.globalCompositeOperation="destination-out",g.beginPath(),g.arc(D/2,D/2,U,0,Math.PI*2),g.fill(),g.restore(),g.save(),g.beginPath(),g.arc(D/2,D/2,U,0,Math.PI*2),g.clip(),g.drawImage($,m,j,I,F),g.restore(),g.strokeStyle="rgba(255, 255, 255, 0.4)",g.lineWidth=2,g.beginPath(),g.arc(D/2,D/2,U,0,Math.PI*2),g.stroke()},[d,o,f]);const k=t.useCallback(g=>{h(!0),b.current={x:g.clientX,y:g.clientY,ox:o.x,oy:o.y},g.target.setPointerCapture(g.pointerId)},[o]),v=t.useCallback(g=>{p&&x({x:b.current.ox+(g.clientX-b.current.x),y:b.current.oy+(g.clientY-b.current.y)})},[p]),C=t.useCallback(()=>h(!1),[]),N=t.useCallback(()=>{if(!l.current)return;const g=document.createElement("canvas"),$=U*2;g.width=$,g.height=$;const P=g.getContext("2d");if(!P)return;const I=l.current,F=Math.max(D/I.width,D/I.height)*d,m=I.width*F,j=I.height*F,z=(D-m)/2+o.x-(D/2-U),O=(D-j)/2+o.y-(D/2-U);P.beginPath(),P.arc(U,U,U,0,Math.PI*2),P.clip(),P.drawImage(I,z,O,m,j),g.toBlob(E=>{E&&a(E)},"image/png")},[d,o,a]);return t.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:D,height:D,style:{cursor:p?"grabbing":"grab",width:"100%",height:"100%"},onPointerDown:k,onPointerMove:v,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:w.zoomOut}),s.jsx("input",{type:"range",min:"1",max:"3",step:"0.01",value:d,onChange:g=>c(parseFloat(g.target.value)),className:"ss-auth-zoom-slider"}),s.jsx("span",{className:"material-symbols-outlined",children:w.zoomIn})]})]})});function os({onUpload:e,onClose:r,isLoading:a}){const[i,n]=t.useState(null),[u,l]=t.useState(!1),[d,c]=t.useState(null),o=t.useRef(null),x=t.useRef(null),p=t.useCallback(f=>{if(!f.type.startsWith("image/")){c("Please select an image file");return}if(f.size>5*1024*1024){c("Image must be smaller than 5 MB");return}c(null),n(f)},[]),h=t.useCallback(f=>{f.preventDefault(),l(!1);const y=f.dataTransfer.files[0];y&&p(y)},[p]),b=t.useCallback(async f=>{await e(f)},[e]);return s.jsx("div",{className:"ss-auth-modal-overlay",onClick:f=>{f.target===f.currentTarget&&r()},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:r,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})]}),i?s.jsxs(s.Fragment,{children:[s.jsx(Os,{ref:x,file:i,onCrop:b,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(),l(!0)},onDragLeave:()=>l(!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 y;(y=f.target.files)!=null&&y[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:r,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:!i||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 is({onClose:e,afterDeleteAccountUrl:r,defaultTab:a="profile",onOrgDeleted:i,onOrgUpdated:n}){const[u,l]=t.useState(a),{invites:d}=_(),c=[{key:"profile",label:"Profile",icon:w.person},{key:"organization",label:"Organization",icon:w.corporateFare},{key:"people",label:"People",icon:w.group},{key:"invites",label:"Invites",icon:w.mail,badge:d.length||void 0},{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:c.map(o=>s.jsxs("button",{type:"button",className:`ss-auth-settings-nav-item${u===o.key?" ss-auth-settings-nav-item-active":""}`,onClick:()=>l(o.key),children:[s.jsx("span",{className:"material-symbols-outlined",children:o.icon}),o.label,o.badge!=null&&o.badge>0&&s.jsx("span",{className:"ss-auth-invite-badge",style:{position:"static",marginLeft:"6px"},children:o.badge})]},o.key))}),s.jsxs("div",{className:"ss-auth-settings-content",children:[u==="profile"&&s.jsx(Es,{afterDeleteAccountUrl:r}),u==="organization"&&s.jsx(Is,{onOrgDeleted:i,onOrgUpdated:n}),u==="people"&&s.jsx(Fs,{}),u==="invites"&&s.jsx(Bs,{}),u==="billing"&&s.jsx(Ls,{})]})]})]})}function Es({afterDeleteAccountUrl:e}){const{user:r,updateProfile:a,uploadAvatar:i,changePassword:n,isLoading:u,error:l,success:d,setError:c,setSuccess:o}=ss(),{signOut:x}=W(),{deleteAccount:p,isLoading:h,error:b,setError:f}=ts(),[y,k]=t.useState((r==null?void 0:r.name)??""),[v,C]=t.useState((r==null?void 0:r.avatarUrl)??""),[N,g]=t.useState(!1),[$,P]=t.useState(""),[I,F]=t.useState(""),[m,j]=t.useState(""),[z,O]=t.useState(null),[E,B]=t.useState(!1),[S,L]=t.useState(""),V=t.useCallback(async T=>{T.preventDefault(),c(null),o(null),await a({name:y,avatarUrl:v||void 0})},[y,v,a,c,o]),Y=t.useCallback(async T=>{const Q=await i(T);Q&&(C(Q.avatarUrl),g(!1))},[i]),q=t.useCallback(async T=>{if(T.preventDefault(),O(null),c(null),o(null),I!==m){O("Passwords do not match");return}if(I.length<8){O("Password must be at least 8 characters");return}await n($,I)&&(P(""),F(""),j(""))},[$,I,m,n,c,o]),fs=t.useCallback(async()=>{await p()&&(await x(),e&&(window.location.href=e))},[p,x,e]),bs=(r==null?void 0:r.provider)==="email",ys=S===(r==null?void 0:r.email),js=((r==null?void 0:r.name)||(r==null?void 0:r.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:js}),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:[(r==null?void 0:r.name)||"Unnamed User",(r==null?void 0:r.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:r==null?void 0:r.email})]})]}),l&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:l})]}),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:y,onChange:T=>k(T.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:(r==null?void 0:r.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:(r==null?void 0:r.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"]})})]})]}),bs&&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"]}),z&&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: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:$,onChange:T=>P(T.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:I,onChange:T=>F(T.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:T=>j(T.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."}),b&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:b})]}),E?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:r==null?void 0:r.email,value:S,onChange:T=>L(T.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:()=>{B(!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:!ys||h,onClick:fs,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:()=>B(!0),children:"Delete my account"})]}),N&&s.jsx(os,{onUpload:Y,onClose:()=>g(!1),isLoading:u})]})}function Is({onOrgDeleted:e,onOrgUpdated:r}){const{selectedOrg:a,updateOrg:i,deleteOrg:n,isLoading:u,error:l,setError:d}=H(),[c,o]=t.useState((a==null?void 0:a.name)??""),[x,p]=t.useState(!1),[h,b]=t.useState(!1),[f,y]=t.useState(!1),[k,v]=t.useState(!1),[C,N]=t.useState("");if(t.useEffect(()=>{a&&(o(a.name),y(!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(),!c.trim())return;p(!0),b(!1);const I=await i(a.id,{name:c.trim()});p(!1),I&&(b(!0),r==null||r())},$=async()=>{await n(a.id)&&(v(!1),y(!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"]}),l&&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:l})]}),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:c,onChange:P=>{o(P.target.value),b(!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."}),k?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:C,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:C!==a.name||u,onClick:$,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 Fs(){const{selectedOrg:e,members:r,invites:a,isLoading:i,error:n,setError:u,sendInvite:l,refreshInvites:d,revokeInvite:c,updateMemberRole:o,removeMember:x,refreshMembers:p}=H(),[h,b]=t.useState(""),[f,y]=t.useState("member"),[k,v]=t.useState(!1),[C,N]=t.useState(!1),[g,$]=t.useState(null),[P,I]=t.useState(""),[F,m]=t.useState(null);if(t.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 l(e.id,h,f)&&(b(""),y("member"),N(!0),v(!1),d(e.id))},z=async()=>{if(!g)return;await o(e.id,g.userId,P)&&$(null)},O=async()=>{if(!F)return;await x(e.id,F.userId)&&m(null)},E=async S=>{await c(e.id,S)},B=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})]}),C&&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(!k),children:[s.jsx("span",{className:"material-symbols-outlined",style:{fontSize:"16px"},children:w.add}),"Invite"]})]}),k&&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=>b(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=>y(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:i,style:{width:"auto",marginBottom:"0"},children:"Send"})]})}),r.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:r.map(S=>s.jsxs("tr",{children:[s.jsx("td",{children:S.email}),s.jsx("td",{children:s.jsx("span",{className:B(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:()=>{$(S),I(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:B(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:()=>E(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&&$(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:()=>$(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=>I(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:()=>$(null),children:"Cancel"}),s.jsx("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto"},onClick:z,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:O,children:"Remove"})]})]})]})})]})}function Bs(){const{invites:e,isLoading:r,error:a,setError:i,accept:n,decline:u,refresh:l}=_(),{refresh:d}=H(),[c,o]=t.useState(null),x=async h=>{o(h),i(null);const b=await n(h);o(null),b&&d()},p=async h=>{o(h),i(null),await u(h),o(null)};return s.jsxs(s.Fragment,{children:[s.jsx("h3",{children:"Invites"}),a&&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:a})]}),r?s.jsx("div",{className:"ss-auth-settings-empty",style:{padding:"40px"},children:s.jsx("span",{className:"ss-auth-spinner"})}):e.length===0?s.jsxs("div",{className:"ss-auth-settings-empty",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.mail}),s.jsx("div",{children:"No pending invitations"})]}):s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(h=>s.jsx("div",{className:"ss-auth-settings-card",style:{marginBottom:0},children:s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"16px",flexWrap:"wrap"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",flex:1,minWidth:0},children:[s.jsx("div",{className:"ss-auth-org-avatar",style:{width:"40px",height:"40px",fontSize:"14px",flexShrink:0},children:h.orgName.split(" ").map(b=>b[0]).join("").slice(0,2).toUpperCase()}),s.jsxs("div",{style:{minWidth:0},children:[s.jsx("div",{style:{fontWeight:600,fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.orgName}),s.jsxs("div",{style:{fontSize:"12px",opacity:.6,display:"flex",gap:"8px",alignItems:"center"},children:[s.jsx("span",{className:"ss-auth-role-badge ss-auth-role-badge-member",children:h.role}),s.jsxs("span",{children:["Expires ",new Date(h.expiresAt).toLocaleDateString()]})]})]})]}),s.jsxs("div",{style:{display:"flex",gap:"8px",flexShrink:0},children:[s.jsx("button",{type:"button",className:"ss-auth-btn-ghost",style:{padding:"6px 12px",fontSize:"13px"},onClick:()=>p(h.id),disabled:c===h.id,children:"Decline"}),s.jsxs("button",{type:"button",className:"ss-auth-btn-primary ss-auth-btn-sm",style:{width:"auto",padding:"6px 16px",fontSize:"13px"},onClick:()=>x(h.id),disabled:c===h.id,children:[c===h.id&&s.jsx("span",{className:"ss-auth-spinner"}),"Accept"]})]})]})},h.id))})]})}function Ls(){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 As({appearance:e,afterSignOutUrl:r,afterDeleteAccountUrl:a,showOrgSwitcher:i=!0,onOrgChange:n,onOrgSettingsClick:u}){const{appearance:l}=A(),{user:d,signOut:c}=W(),o=e??l,[x,p]=t.useState(!1),[h,b]=t.useState(!1),[f,y]=t.useState(""),[k,v]=t.useState(null),[C,N]=t.useState(!1),g=t.useRef(null),{orgs:$,selectedOrg:P,selectOrg:I,createOrg:F,refresh:m}=H(),{invites:j}=_(),z=t.useCallback(E=>{g.current&&!E.composedPath().includes(g.current)&&p(!1)},[]);t.useEffect(()=>{if(x){const E=setTimeout(()=>{document.addEventListener("click",z)},0);return()=>{clearTimeout(E),document.removeEventListener("click",z)}}},[x,z]);const O=t.useCallback(async E=>{E.preventDefault(),v(null),N(!0);const B=f.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");try{const S=await F(f,B);S&&(await I(S.id),n==null||n(S),y(""),p(!1))}catch(S){v(S instanceof Error?S.message:"Failed to create organization")}finally{N(!1)}},[f,F,I,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.jsxs("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()}),j.length>0&&s.jsx("span",{className:"ss-auth-invite-badge",children:j.length})]}),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),b(!0)},children:[s.jsx("span",{className:"material-symbols-outlined",children:w.settings}),"Settings"]})}),i&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ss-auth-section-label",children:"Organizations"}),s.jsx("div",{style:{padding:"0 8px 4px"},children:$.map(E=>{const B=(P==null?void 0:P.id)===E.id,S=E.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 I(E.id),n==null||n(E)},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:S}),s.jsx("span",{style:{fontFamily:"'Manrope', sans-serif",letterSpacing:"-0.01em"},children:E.name}),E.planName&&s.jsx("span",{className:"ss-auth-plan-badge",children:E.planName})]}),B&&s.jsx("span",{className:"material-symbols-outlined ss-auth-org-check",style:{fontSize:"18px"},children:w.checkCircle})]},E.id)})}),s.jsxs("div",{className:"ss-auth-inline-create",children:[k&&s.jsx("div",{className:"ss-auth-error",style:{marginBottom:"8px",fontSize:"12px"},children:s.jsx("span",{children:k})}),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:E=>y(E.target.value),required:!0,style:{fontSize:"13px",padding:"10px 40px 10px 12px"}}),s.jsx("button",{type:"submit",className:"ss-auth-inline-create-btn",disabled:C||!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 c(),r&&(window.location.href=r)},style:{color:"inherit"},children:[s.jsx("span",{className:"material-symbols-outlined",style:{color:"inherit"},children:w.logout}),"Sign out"]})})]}),h&&s.jsx(is,{onClose:()=>b(!1),afterDeleteAccountUrl:a,onOrgDeleted:m,onOrgUpdated:m})]})}):null}function Ds({appearance:e}){const{appearance:r}=A(),{user:a,signOut:i}=W(),{updateProfile:n,uploadAvatar:u,changePassword:l,isLoading:d,error:c,success:o,setError:x,setSuccess:p}=ss(),h=e??r,[b,f]=t.useState((a==null?void 0:a.name)??""),[y,k]=t.useState((a==null?void 0:a.avatarUrl)??""),[v,C]=t.useState(!1),[N,g]=t.useState(""),[$,P]=t.useState(""),[I,F]=t.useState(""),[m,j]=t.useState(null),z=t.useCallback(async L=>{L.preventDefault(),x(null),p(null),await n({name:b,avatarUrl:y||void 0})},[b,y,n,x,p]),O=t.useCallback(async L=>{const V=await u(L);V&&(k(V.avatarUrl),C(!1))},[u]),E=t.useCallback(async L=>{if(L.preventDefault(),j(null),x(null),p(null),$!==I){j("Passwords do not match");return}if($.length<8){j("Password must be at least 8 characters");return}await l(N,$)&&(g(""),P(""),F(""))},[N,$,I,l,x,p]);if(!a)return null;const B=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:()=>C(!0),children:[y?s.jsx("img",{src:y,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:[c&&s.jsxs("div",{className:"ss-auth-error",children:[s.jsx("span",{className:"material-symbols-outlined",children:w.errorOutline}),s.jsx("span",{children:c})]}),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: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:b,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"]})})]}),B&&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:E,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:$,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:I,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:()=>i(),style:{width:"auto",flexShrink:0},children:"Sign out"})]})})})]}),v&&s.jsx(os,{onUpload:O,onClose:()=>C(!1),isLoading:d})]})})}function Ts({appearance:e,onOrgChange:r}){const{appearance:a}=A(),{orgs:i,selectedOrg:n,selectOrg:u,createOrg:l,isLoading:d}=H(),c=e??a,[o,x]=t.useState(!1),[p,h]=t.useState(""),[b,f]=t.useState(""),[y,k]=t.useState(null),[v,C]=t.useState(!1),N=t.useRef(null),g=t.useCallback(m=>{N.current&&!m.composedPath().includes(N.current)&&x(!1)},[]);t.useEffect(()=>{if(o){const m=setTimeout(()=>{document.addEventListener("click",g)},0);return()=>{clearTimeout(m),document.removeEventListener("click",g)}}},[o,g]);const $=t.useCallback(m=>{h(m),f(m.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},[]),P=t.useCallback(async m=>{m.preventDefault(),k(null),C(!0);try{const j=await l(p,b);j&&(await u(j.id),r==null||r(j),h(""),f(""),x(!1))}catch(j){k(j instanceof Error?j.message:"Failed to create organization")}finally{C(!1)}},[p,b,l,u,r]);if(d)return null;const I=(n==null?void 0:n.name)??(i.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:c,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:I})]})]}),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:i.map(m=>{const j=(n==null?void 0:n.id)===m.id,z=m.name.split(" ").map(O=>O[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),r==null||r(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:z}),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"})]}),y&&s.jsx("div",{className:"ss-auth-error",style:{marginBottom:"12px",fontSize:"12px"},children:s.jsx("span",{children:y})}),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=>$(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:b,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 Ms(e,r="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:r,minimumFractionDigits:e%100===0?0:2}).format(e/100)}function Rs({plans:e,currentPlanId:r,onSelectPlan:a,interval:i,appearance:n}){const{appearance:u}=A(),l=n??u,d=i?e.filter(c=>c.interval===i||c.isFree):e;return s.jsx(M,{appearance:l,children:s.jsx("div",{className:"ss-pricing-grid",children:d.map(c=>{const o=c.id===r;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:c.name}),c.trialDays>0&&s.jsxs("span",{className:"ss-badge ss-badge-trialing",children:[c.trialDays,"-day trial"]}),c.isFree&&s.jsx("span",{className:"ss-badge ss-badge-active",children:"Free"})]}),s.jsx("div",{className:"ss-pricing-price",children:c.isFree?s.jsx("span",{className:"ss-pricing-amount",children:"Free"}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ss-pricing-amount",children:Ms(c.amountCents,c.currency)}),s.jsxs("span",{className:"ss-pricing-interval",children:["/",c.interval]})]})}),c.description&&s.jsx("p",{className:"ss-pricing-desc",children:c.description}),c.features.length>0&&s.jsx("ul",{className:"ss-pricing-features",children:c.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(c.id),children:o?"Current plan":"Select plan"})]},c.id)})})})}function Us(){const{client:e}=A();return{billing:e.billing}}function G(e){const{client:r}=A();return t.useMemo(()=>{if(e){const a=new R.Transport("https://api.saas-support.com/v1",{type:"portalToken",token:e});return new R.BillingClient(a)}return r.billing},[r,e])}function ls(e,r){const a=G(r),[i,n]=t.useState(null),[u,l]=t.useState(!0),[d,c]=t.useState(null),o=t.useCallback(async()=>{l(!0),c(null);try{const x=await a.getCustomer(e);n(x)}catch(x){c(x instanceof Error?x.message:"Failed to load subscription")}finally{l(!1)}},[a,e]);return t.useEffect(()=>{o()},[o]),{customer:i,isLoading:u,error:d,refresh:o}}function cs(e,r){const a=G(r),[i,n]=t.useState([]),[u,l]=t.useState(!0),[d,c]=t.useState(null),o=t.useCallback(async()=>{l(!0),c(null);try{const x=await a.getInvoices(e);n(x)}catch(x){c(x instanceof Error?x.message:"Failed to load invoices")}finally{l(!1)}},[a,e]);return t.useEffect(()=>{o()},[o]),{invoices:i,isLoading:u,error:d,refresh:o}}function ds(e,r){const a=G(r),[i,n]=t.useState([]),[u,l]=t.useState(!0),[d,c]=t.useState(null),o=t.useCallback(async()=>{l(!0),c(null);try{const x=await a.getCurrentUsage(e);n(x)}catch(x){c(x instanceof Error?x.message:"Failed to load usage")}finally{l(!1)}},[a,e]);return t.useEffect(()=>{o()},[o]),{usage:i,isLoading:u,error:d,refresh:o}}const Vs={active:"ss-badge-active"};function us({customerId:e,portalToken:r,onChangePlan:a,onCancel:i,appearance:n}){const{appearance:u}=A(),{customer:l,isLoading:d,error:c}=ls(e,r),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..."]}),c&&s.jsx("div",{className:"ss-global-error",children:c}),l&&!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:l.name||l.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 ${Vs.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"}),i&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:i,children:"Cancel subscription"})]})]})]})})}const Hs={paid:"ss-badge-active",open:"ss-badge-trialing",draft:"ss-badge-paused",void:"ss-badge-canceled",uncollectible:"ss-badge-past-due"};function qs(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Ws(e){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(e/100)}function ps({customerId:e,portalToken:r,appearance:a}){const{appearance:i}=A(),{invoices:n,isLoading:u,error:l}=cs(e,r),d=a??i,c=[...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..."]}),l&&s.jsx("div",{className:"ss-global-error",children:l}),!u&&c.length===0&&s.jsx("p",{className:"ss-empty",children:"No invoices yet."}),!u&&c.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:c.map(o=>s.jsxs("tr",{className:"ss-tr",children:[s.jsx("td",{className:"ss-td",children:qs(o.createdAt)}),s.jsx("td",{className:"ss-td",children:Ws(o.amountCents)}),s.jsx("td",{className:"ss-td",children:s.jsx("span",{className:`ss-badge ${Hs[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 hs({customerId:e,limits:r,portalToken:a,appearance:i}){const{appearance:n}=A(),{usage:u,isLoading:l,error:d}=ds(e,a),c=i??n;return s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Usage"}),l&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),!l&&u.length===0&&s.jsx("p",{className:"ss-empty",children:"No usage data."}),!l&&u.map(o=>{const x=r==null?void 0:r[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 _s({customerId:e,portalToken:r,limits:a,onChangePlan:i,onCancel:n,appearance:u}){const{appearance:l}=A(),d=u??l,[c,o]=t.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 ${c===p.id?"ss-tab-active":""}`,onClick:()=>o(p.id),children:p.label},p.id))}),s.jsxs("div",{className:"ss-tab-content",children:[c==="subscription"&&s.jsx(us,{customerId:e,portalToken:r,onChangePlan:i,onCancel:n}),c==="invoices"&&s.jsx(ps,{customerId:e,portalToken:r}),c==="usage"&&s.jsx(hs,{customerId:e,portalToken:r,limits:a})]})]})})}function Gs({customerId:e,portalToken:r,onApplied:a,appearance:i}){const{appearance:n}=A(),u=G(r),l=i??n,[d,c]=t.useState(""),[o,x]=t.useState(!1),[p,h]=t.useState(null),[b,f]=t.useState(null),y=t.useCallback(async k=>{if(k.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`}`),c(""),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:l,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}),b&&s.jsx("div",{className:"ss-success-msg",children:b}),s.jsxs("form",{onSubmit:y,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:k=>c(k.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 Ys(){const{client:e}=A();return{report:e.report}}function es(){const{client:e}=A(),[r,a]=t.useState(null),[i,n]=t.useState(!1),[u,l]=t.useState(null),d=t.useCallback(async c=>{n(!0),l(null);try{const o=await e.report.executeQuery(c);return a(o),o}catch(o){return l(o instanceof Error?o.message:"Query failed"),null}finally{n(!1)}},[e]);return{result:r,execute:d,isLoading:i,error:u}}function xs(e){const{client:r}=A(),[a,i]=t.useState(null),[n,u]=t.useState(!0),[l,d]=t.useState(null),c=t.useCallback(async()=>{u(!0),d(null);try{const o=await r.report.listQueries(e);i(o)}catch(o){d(o instanceof Error?o.message:"Failed to load queries")}finally{u(!1)}},[r,e]);return t.useEffect(()=>{c()},[c]),{queries:(a==null?void 0:a.data)??[],meta:a==null?void 0:a.meta,isLoading:n,error:l,refresh:c}}function Qs(e){const{client:r}=A(),[a,i]=t.useState(null),[n,u]=t.useState(!0),[l,d]=t.useState(null),c=t.useCallback(async()=>{u(!0),d(null);try{const o=await r.report.getDashboard(e);i(o)}catch(o){d(o instanceof Error?o.message:"Failed to load dashboard")}finally{u(!1)}},[r,e]);return t.useEffect(()=>{c()},[c]),{dashboard:a,isLoading:n,error:l,refresh:c}}function Js(e,r,a="https://api.saas-support.com/v1"){const i=t.useMemo(()=>{const p=new R.Transport(a,{type:"embedToken",token:e});return new R.ReportClient(p)},[e,a]),[n,u]=t.useState(null),[l,d]=t.useState(!0),[c,o]=t.useState(null),x=t.useCallback(async()=>{d(!0),o(null);try{const p=await i.getDashboard(r);u(p)}catch(p){o(p instanceof Error?p.message:"Failed to load dashboard")}finally{d(!1)}},[i,r]);return t.useEffect(()=>{x()},[x]),{dashboard:n,reportClient:i,isLoading:l,error:c,refresh:x}}function Zs({onResult:e,mode:r="both",placeholder:a,appearance:i}){const{appearance:n}=A(),{execute:u,isLoading:l,error:d}=es(),c=i??n,[o,x]=t.useState(""),[p,h]=t.useState(r==="sql"?"sql":"nl"),b=t.useCallback(async f=>{if(f.preventDefault(),!o.trim())return;const k=await u(p==="sql"?{sql:o}:{naturalLanguage:o});k&&(e==null||e(k))},[o,p,u,e]);return s.jsx(M,{appearance:c,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[r==="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:b,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:l||!o.trim(),children:[l&&s.jsx("span",{className:"ss-spinner"}),"Run query"]})]})]})})}function gs({columns:e,rows:r,sortable:a=!0,maxRows:i,appearance:n}){const{appearance:u}=A(),l=n??u,[d,c]=t.useState(null),[o,x]=t.useState("asc"),p=t.useMemo(()=>d?[...r].sort((y,k)=>{const v=y[d],C=k[d];if(v==null&&C==null)return 0;if(v==null)return 1;if(C==null)return-1;if(typeof v=="number"&&typeof C=="number")return o==="asc"?v-C:C-v;const N=String(v),g=String(C);return o==="asc"?N.localeCompare(g):g.localeCompare(N)}):r,[r,d,o]),h=i?p.slice(0,i):p,b=y=>{a&&(d===y?x(k=>k==="asc"?"desc":"asc"):(c(y),x("asc")))};function f(y){return y==null?"":typeof y=="object"?JSON.stringify(y):String(y)}return s.jsx(M,{appearance:l,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(y=>s.jsxs("th",{className:`ss-th ${a?"ss-th-sortable":""} ${d===y?o==="asc"?"ss-sorted-asc":"ss-sorted-desc":""}`,onClick:()=>b(y),children:[y,d===y&&s.jsx("span",{className:"ss-sort-indicator",children:o==="asc"?" ▲":" ▼"})]},y))})}),s.jsx("tbody",{children:h.map((y,k)=>s.jsx("tr",{className:"ss-tr",children:e.map(v=>s.jsx("td",{className:"ss-td",children:f(y[v])},v))},k))})]}),i&&r.length>i&&s.jsxs("div",{className:"ss-table-footer",children:["Showing ",i," of ",r.length," rows"]})]})})}function Ks(e,r="#6366f1"){const a=parseInt(r.replace("#","").slice(0,2),16),i=[];for(let n=0;n<e;n++){const u=(a+n*Math.floor(360/Math.max(e,1)))%360;i.push(`hsl(${u}, 65%, 55%)`)}return i}function Xs({labels:e,values:r,w:a,h:i,colors:n}){const u=Math.max(...r,1),l=40,d=a-l*2,c=i-l*2,o=Math.max(1,d/e.length-4);return s.jsxs("g",{children:[s.jsx("line",{x1:l,y1:i-l,x2:a-l,y2:i-l,stroke:"#ccc",strokeWidth:1}),r.map((x,p)=>{const h=x/u*c,b=l+d/e.length*p+2,f=i-l-h;return s.jsxs("g",{children:[s.jsx("rect",{x:b,y:f,width:o,height:h,fill:n[p%n.length],rx:2}),s.jsx("text",{x:b+o/2,y:i-l+14,textAnchor:"middle",fontSize:10,fill:"#666",children:e[p].length>8?e[p].slice(0,8)+"...":e[p]})]},p)})]})}function se({labels:e,values:r,w:a,h:i,colors:n}){const u=Math.max(...r,1),l=40,d=a-l*2,c=i-l*2,o=e.length>1?d/(e.length-1):0,x=r.map((p,h)=>{const b=l+o*h,f=i-l-p/u*c;return`${b},${f}`});return s.jsxs("g",{children:[[.25,.5,.75,1].map(p=>{const h=i-l-p*c;return s.jsx("line",{x1:l,y1:h,x2:a-l,y2:h,stroke:"#eee",strokeWidth:1},p)}),s.jsx("polyline",{points:x.join(" "),fill:"none",stroke:n[0],strokeWidth:2}),r.map((p,h)=>{const b=l+o*h,f=i-l-p/u*c;return s.jsx("circle",{cx:b,cy:f,r:4,fill:n[0]},h)})]})}function ee({labels:e,values:r,w:a,h:i,colors:n}){const u=r.reduce((h,b)=>h+b,0)||1,l=a/2,d=i/2-20,c=Math.min(a,i)/2-40,o=2*Math.PI*c;let x=0;const p=r.map((h,b)=>{const f=h/u,y=f*o,k={dash:y,offset:x,color:n[b%n.length],label:e[b],pct:f};return x+=y,k});return s.jsxs("g",{children:[p.map((h,b)=>s.jsx("circle",{cx:l,cy:d,r:c,fill:"none",stroke:h.color,strokeWidth:c*.6,strokeDasharray:`${h.dash} ${o-h.dash}`,strokeDashoffset:-h.offset,transform:`rotate(-90 ${l} ${d})`},b)),s.jsx("g",{transform:`translate(${l-e.length*30}, ${i-20})`,children:p.slice(0,6).map((h,b)=>s.jsxs("g",{transform:`translate(${b*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})]},b))})]})}function ms({type:e,data:r,title:a,width:i=400,height:n=300,appearance:u}){const{appearance:l}=A(),d=u??l,c=t.useMemo(()=>Ks(r.labels.length),[r.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 ${i} ${n}`,width:"100%",style:{maxWidth:i},children:[e==="bar"&&s.jsx(Xs,{labels:r.labels,values:r.values,w:i,h:n,colors:c}),e==="line"&&s.jsx(se,{labels:r.labels,values:r.values,w:i,h:n,colors:c}),e==="pie"&&s.jsx(ee,{labels:r.labels,values:r.values,w:i,h:n,colors:c})]})]})})}function ae({dashboardId:e,embedToken:r,baseUrl:a,refreshInterval:i,appearance:n}){const u=A(),l=n??(u==null?void 0:u.appearance),d=t.useMemo(()=>{if(r){const v=a??"https://api.saas-support.com/v1",C=new R.Transport(v,{type:"embedToken",token:r});return new R.ReportClient(C)}return u.client.report},[r,a,u]),[c,o]=t.useState([]),[x,p]=t.useState({}),[h,b]=t.useState(!0),[f,y]=t.useState(null),k=t.useCallback(async()=>{b(!0),y(null);try{const v=await d.getDashboard(e),C=JSON.parse(v.layoutJson||"[]");o(C);const N={};for(const g of C)try{const $=await d.listQueries({search:g.queryId,perPage:1});if($.data.length>0&&$.data[0].generatedSql){const P=await d.executeQuery({sql:$.data[0].generatedSql});N[g.queryId]=P}}catch{}p(N)}catch(v){y(v instanceof Error?v.message:"Failed to load dashboard")}finally{b(!1)}},[d,e]);return t.useEffect(()=>{k()},[k]),t.useEffect(()=>{if(!i||i<=0)return;const v=setInterval(k,i*1e3);return()=>clearInterval(v)},[i,k]),s.jsx(M,{appearance:l,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&&c.map((v,C)=>{const N=x[v.queryId];if(!N)return null;const g=N.columns.length>=2?{labels:N.rows.map($=>String($[N.columns[0]]??"")),values:N.rows.map($=>Number($[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(gs,{columns:N.columns,rows:N.rows,maxRows:50}):s.jsx(ms,{type:v.chartType||"bar",data:g,width:v.w,height:v.h})]},C)})]})})}function te(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function re({onSelectQuery:e,onRunQuery:r,appearance:a}){const{appearance:i}=A(),{queries:n,isLoading:u,error:l}=xs(),{execute:d,isLoading:c}=es(),o=a??i,x=t.useCallback(async p=>{if(!p.generatedSql)return;const h=await d({sql:p.generatedSql});h&&(r==null||r(h))},[d,r]);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..."]}),l&&s.jsx("div",{className:"ss-global-error",children:l}),!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:te(p.createdAt)}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:c||!p.generatedSql,onClick:h=>{h.stopPropagation(),x(p)},children:c?s.jsx("span",{className:"ss-spinner"}):"Run"})]})]},p.id))]})})}function ne({embedToken:e,dashboardId:r,baseUrl:a="https://api.saas-support.com/v1",refreshInterval:i,appearance:n}){const u=t.useMemo(()=>{const y=new R.Transport(a,{type:"embedToken",token:e});return new R.ReportClient(y)},[e,a]),[l,d]=t.useState([]),[c,o]=t.useState(!0),[x,p]=t.useState(null),h=t.useMemo(()=>J(n),[n]),b=t.useMemo(()=>Z(h),[h]),f=t.useCallback(async()=>{o(!0),p(null);try{const y=await u.getDashboard(r),k=JSON.parse(y.layoutJson||"[]"),v=await Promise.all(k.map(async C=>{try{const N=await u.listQueries({search:C.queryId,perPage:1});if(N.data.length>0&&N.data[0].generatedSql){const g=await u.executeQuery({sql:N.data[0].generatedSql});return{...C,result:g}}}catch{}return C}));d(v)}catch(y){p(y instanceof Error?y.message:"Failed to load dashboard")}finally{o(!1)}},[u,r]);return t.useEffect(()=>{f()},[f]),t.useEffect(()=>{if(!i||i<=0)return;const y=setInterval(f,i*1e3);return()=>clearInterval(y)},[i,f]),s.jsx("div",{ref:y=>{if(!y||y.shadowRoot)return;const k=y.attachShadow({mode:"open"}),v=document.createElement("style");v.textContent=b,k.appendChild(v);const C=document.createElement("div");k.appendChild(C)},style:{display:"contents"},children:s.jsxs("div",{className:"ss-dashboard-grid",children:[c&&s.jsx("div",{className:"ss-loading",children:"Loading dashboard..."}),x&&s.jsx("div",{className:"ss-global-error",children:x}),!c&&l.map((y,k)=>{if(!y.result)return null;const{columns:v,rows:C}=y.result;return s.jsxs("div",{className:"ss-widget",children:[y.title&&s.jsx("h4",{className:"ss-widget-header",children:y.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:C.slice(0,50).map((N,g)=>s.jsx("tr",{className:"ss-tr",children:v.map($=>s.jsx("td",{className:"ss-td",children:String(N[$]??"")},$))},g))})]})]},k)})]})})}exports.SaaSError=R.SaaSError;exports.SaaSSupport=R.SaaSSupport;exports.isMfaRequired=R.isMfaRequired;exports.Chart=ms;exports.CouponInput=Gs;exports.DashboardView=ae;exports.DataTable=gs;exports.InvoiceHistory=ps;exports.OrgSwitcher=Ts;exports.PaymentPortal=_s;exports.PricingTable=Rs;exports.QueryInput=Zs;exports.ReportEmbed=ne;exports.SaaSContext=K;exports.SaaSProvider=ws;exports.SavedQueryList=re;exports.SettingsPanel=is;exports.SignIn=zs;exports.SignUp=Ps;exports.SubscriptionStatus=us;exports.UsageDisplay=hs;exports.UserButton=As;exports.UserProfile=Ds;exports.useAuth=W;exports.useBilling=Us;exports.useDashboard=Qs;exports.useDeleteAccount=ts;exports.useEmbedDashboard=Js;exports.useInvites=_;exports.useInvoices=cs;exports.useOrg=H;exports.useProfile=ss;exports.useQuery=es;exports.useReport=Ys;exports.useSaaSContext=A;exports.useSavedQueries=xs;exports.useSignIn=X;exports.useSignUp=as;exports.useSubscription=ls;exports.useUsage=ds;exports.useUser=Cs;
package/dist/react.d.ts CHANGED
@@ -80,6 +80,12 @@ declare class AuthClient {
80
80
  }>;
81
81
  listInvites(orgId: string): Promise<PendingInvite[]>;
82
82
  revokeInvite(orgId: string, inviteId: string): Promise<void>;
83
+ listMyInvites(): Promise<MyPendingInvite[]>;
84
+ acceptInviteById(inviteId: string): Promise<{
85
+ orgId: string;
86
+ role: string;
87
+ }>;
88
+ declineInvite(inviteId: string): Promise<void>;
83
89
  deleteAccount(): Promise<void>;
84
90
  /* Excluded from this release type: handleExternalLogout */
85
91
  /* Excluded from this release type: performRefresh */
@@ -327,6 +333,15 @@ declare interface MfaVerifyResult {
327
333
  backupCodes: string[];
328
334
  }
329
335
 
336
+ export declare interface MyPendingInvite {
337
+ id: string;
338
+ orgId: string;
339
+ orgName: string;
340
+ role: string;
341
+ expiresAt: string;
342
+ createdAt: string;
343
+ }
344
+
330
345
  export declare type OAuthProvider = 'google' | 'github';
331
346
 
332
347
  declare interface OffsetPage<T> {
@@ -582,7 +597,7 @@ export declare interface SettingsPanelProps {
582
597
  onOrgUpdated?: () => void;
583
598
  }
584
599
 
585
- declare type SettingsTab = 'profile' | 'organization' | 'people' | 'billing';
600
+ declare type SettingsTab = 'profile' | 'organization' | 'people' | 'invites' | 'billing';
586
601
 
587
602
  export declare function SignIn({ appearance: localAppearance, signUpUrl, onSignUp }: SignInProps): JSX_2.Element;
588
603
 
@@ -758,6 +773,19 @@ export declare function useEmbedDashboard(embedToken: string, dashboardId: strin
758
773
  refresh: () => Promise<void>;
759
774
  };
760
775
 
776
+ export declare function useInvites(): {
777
+ invites: MyPendingInvite[];
778
+ isLoading: boolean;
779
+ error: string | null;
780
+ setError: Dispatch<SetStateAction<string | null>>;
781
+ refresh: () => Promise<void>;
782
+ accept: (inviteId: string) => Promise<{
783
+ orgId: string;
784
+ role: string;
785
+ } | null>;
786
+ decline: (inviteId: string) => Promise<boolean>;
787
+ };
788
+
761
789
  export declare function useInvoices(customerId: string, portalToken?: string): {
762
790
  invoices: Invoice[];
763
791
  isLoading: boolean;