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