@saas-support/react 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +218 -209
- package/dist/react.cjs +23 -3
- package/dist/react.d.ts +39 -4
- package/dist/react.js +1452 -1145
- 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"),a=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("react"),A=require("./index.cjs"),fs=require("react-dom"),G=a.createContext(null);function I(){const e=a.useContext(G);if(!e)throw new Error("useSaaSContext must be used within a <SaaSProvider>");return e}function ys({publishableKey:e,apiKey:t,baseUrl:r,appearance:l,children:n}){const[u]=a.useState(()=>new A.SaaSSupport({publishableKey:e,apiKey:t,baseUrl:r})),[i,d]=a.useState(null),[c,o]=a.useState(!1),[m,p]=a.useState(null);return a.useEffect(()=>{let g=!1;u.load().then(async()=>{if(g)return;const w=await u.auth.getUser(),f=await u.auth.getSettings();d(w),p(f),o(!0)});const h=u.auth.onAuthStateChange(w=>{g||d(w)});return()=>{g=!0,h(),u.destroy()}},[u]),s.jsx(G.Provider,{value:{client:u,user:i,isLoaded:c,appearance:l,settings:m},children:n})}const vs={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"},js={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"};function V(e){const t=(e==null?void 0:e.baseTheme)==="dark"?js:vs,r=e==null?void 0:e.variables;return{colorPrimary:(r==null?void 0:r.colorPrimary)??t.colorPrimary,colorPrimaryHover:r!=null&&r.colorPrimary?ws(r.colorPrimary,10):t.colorPrimaryHover,colorBackground:(r==null?void 0:r.colorBackground)??t.colorBackground,colorText:(r==null?void 0:r.colorText)??t.colorText,colorTextSecondary:t.colorTextSecondary,colorInputBackground:(r==null?void 0:r.colorInputBackground)??t.colorInputBackground,colorInputBorder:(r==null?void 0:r.colorInputBorder)??t.colorInputBorder,colorError:(r==null?void 0:r.colorError)??t.colorError,colorSuccess:(r==null?void 0:r.colorSuccess)??t.colorSuccess,colorWarning:(r==null?void 0:r.colorWarning)??t.colorWarning,fontFamily:(r==null?void 0:r.fontFamily)??t.fontFamily,borderRadius:(r==null?void 0:r.borderRadius)??t.borderRadius}}function ws(e,t){const r=parseInt(e.replace("#",""),16),l=Math.max(0,(r>>16)-Math.round(2.55*t)),n=Math.max(0,(r>>8&255)-Math.round(2.55*t)),u=Math.max(0,(r&255)-Math.round(2.55*t));return`#${(l<<16|n<<8|u).toString(16).padStart(6,"0")}`}function Q(e){return`
|
|
2
2
|
:host {
|
|
3
3
|
all: initial;
|
|
4
4
|
font-family: ${e.fontFamily};
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
border-radius: ${e.borderRadius};
|
|
15
15
|
padding: 32px;
|
|
16
16
|
width: 100%;
|
|
17
|
-
max-width:
|
|
17
|
+
max-width: 480px;
|
|
18
18
|
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
|
|
19
19
|
border: 1px solid ${e.colorInputBorder};
|
|
20
20
|
}
|
|
@@ -320,6 +320,26 @@
|
|
|
320
320
|
.ss-dropdown-item-danger { color: ${e.colorError}; }
|
|
321
321
|
.ss-dropdown-item-active { font-weight: 600; color: ${e.colorPrimary}; }
|
|
322
322
|
|
|
323
|
+
.ss-dropdown-section-title {
|
|
324
|
+
padding: 8px 16px 4px;
|
|
325
|
+
font-size: 11px;
|
|
326
|
+
font-weight: 600;
|
|
327
|
+
text-transform: uppercase;
|
|
328
|
+
letter-spacing: 0.5px;
|
|
329
|
+
color: ${e.colorTextSecondary};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.ss-org-check {
|
|
333
|
+
margin-right: 6px;
|
|
334
|
+
font-size: 12px;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.ss-danger-zone {
|
|
338
|
+
padding-top: 20px;
|
|
339
|
+
margin-top: 20px;
|
|
340
|
+
border-top: 2px solid ${e.colorError}33;
|
|
341
|
+
}
|
|
342
|
+
|
|
323
343
|
/* Badges */
|
|
324
344
|
|
|
325
345
|
.ss-badge {
|
|
@@ -830,4 +850,4 @@
|
|
|
830
850
|
font-size: 13px;
|
|
831
851
|
padding: 6px 12px;
|
|
832
852
|
}
|
|
833
|
-
`}function z({children:e,appearance:t}){const r=a.useRef(null),[i,n]=a.useState(null);a.useEffect(()=>{var x;if(!r.current||r.current.shadowRoot){n(((x=r.current)==null?void 0:x.shadowRoot)??null);return}const d=r.current.attachShadow({mode:"open"}),u=F(t),l=document.createElement("style");l.textContent=R(u),d.appendChild(l);const o=document.createElement("div");d.appendChild(o),n(d)},[]),a.useEffect(()=>{if(!i)return;const d=i.querySelector("style");if(d){const u=F(t);d.textContent=R(u)}},[t,i]);const c=(i==null?void 0:i.querySelector("div"))??null;return s.jsx("div",{ref:r,style:{display:"contents"},children:c&&cs.createPortal(e,c)})}function W(){const{client:e,user:t,isLoaded:r}=C();return{isLoaded:r,isSignedIn:!!t,user:t,signOut:a.useCallback(()=>e.auth.signOut(),[e]),getToken:a.useCallback(()=>e.auth.getToken(),[e])}}function xs(){const{user:e,isLoaded:t}=C();return{user:e,isLoaded:t}}function H(){const{client:e}=C(),[t,r]=a.useState(!1),[i,n]=a.useState(null),c=a.useCallback(async(l,o)=>{r(!0),n(null);try{return await e.auth.signIn(l,o)}catch(x){return n(x instanceof Error?x.message:"Sign in failed"),null}finally{r(!1)}},[e]),d=a.useCallback(async l=>{r(!0),n(null);try{return await e.auth.signInWithOAuth(l)}catch(o){return n(o instanceof Error?o.message:"OAuth sign in failed"),null}finally{r(!1)}},[e]),u=a.useCallback(async(l,o)=>{r(!0),n(null);try{return await e.auth.submitMfaCode(l,o)}catch(x){return n(x instanceof Error?x.message:"MFA verification failed"),null}finally{r(!1)}},[e]);return{signIn:c,signInWithOAuth:d,submitMfaCode:u,isLoading:t,error:i,setError:n}}function Q(){const{client:e}=C(),[t,r]=a.useState(!1),[i,n]=a.useState(null);return{signUp:a.useCallback(async(d,u)=>{r(!0),n(null);try{return await e.auth.signUp(d,u)}catch(l){return n(l instanceof Error?l.message:"Sign up failed"),null}finally{r(!1)}},[e]),isLoading:t,error:i,setError:n}}function G(){const{client:e}=C(),[t,r]=a.useState([]),[i,n]=a.useState(null),[c,d]=a.useState([]),[u,l]=a.useState(!1),[o,x]=a.useState(null),p=a.useCallback(async()=>{l(!0),x(null);try{const f=await e.auth.listOrgs();r(f)}catch(f){x(f instanceof Error?f.message:"Failed to load organizations")}finally{l(!1)}},[e]);a.useEffect(()=>{p()},[p]);const g=a.useCallback(async f=>{try{const b=await e.auth.getOrg(f);n(b);const v=await e.auth.listMembers(f);d(v)}catch(b){x(b instanceof Error?b.message:"Failed to load organization")}},[e]),h=a.useCallback(async(f,b)=>{try{const v=await e.auth.createOrg(f,b);return r(y=>[...y,v]),v}catch(v){return x(v instanceof Error?v.message:"Failed to create organization"),null}},[e]);return{orgs:t,selectedOrg:i,members:c,isLoading:u,error:o,refresh:p,selectOrg:g,createOrg:h}}function _(){const{client:e,user:t}=C(),[r,i]=a.useState(!1),[n,c]=a.useState(null),[d,u]=a.useState(null),l=a.useCallback(async p=>{i(!0),c(null),u(null);try{const g=await e.auth.updateProfile(p);return u("Profile updated"),g}catch(g){return c(g instanceof Error?g.message:"Failed to update profile"),null}finally{i(!1)}},[e]),o=a.useCallback(async(p,g)=>{i(!0),c(null),u(null);try{return await e.auth.changePassword(p,g),u("Password changed successfully"),!0}catch(h){return c(h instanceof Error?h.message:"Failed to change password"),!1}finally{i(!1)}},[e]),x=a.useCallback(async p=>{i(!0),c(null),u(null);try{const g=await e.auth.uploadAvatar(p);return u("Avatar updated"),g}catch(g){return c(g instanceof Error?g.message:"Failed to upload avatar"),null}finally{i(!1)}},[e]);return{user:t,updateProfile:l,uploadAvatar:x,changePassword:o,isLoading:r,error:n,success:d,setError:c,setSuccess:u}}const J='<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>',Y='<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>';function ms({appearance:e,signUpUrl:t,onSignUp:r}){const{appearance:i,settings:n}=C(),{signIn:c,signInWithOAuth:d,submitMfaCode:u,isLoading:l,error:o,setError:x}=H(),p=e??i,[g,h]=a.useState(""),[f,b]=a.useState(""),[v,y]=a.useState(!1),[m,j]=a.useState(""),[N,w]=a.useState(""),P=a.useCallback(async E=>{if(E.preventDefault(),v){await u(m,N);return}const S=await c(g,f);S&&M.isMfaRequired(S)&&(j(S.mfaToken),y(!0),x(null))},[g,f,v,m,N,c,u,x]),k=a.useCallback(async E=>{await d(E)},[d]),T=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled);return s.jsx(z,{appearance:p,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Sign in"}),!v&&s.jsxs(s.Fragment,{children:[(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>k("google"),disabled:l,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:J}}),"Continue with Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>k("github"),disabled:l,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:Y}}),"Continue with GitHub"]}),T&&s.jsx("div",{className:"ss-divider",children:"or"})]}),o&&s.jsx("div",{className:"ss-global-error",children:o}),s.jsxs("form",{onSubmit:P,children:[v?s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-mfa-code",children:"Authentication code"}),s.jsx("input",{id:"ss-mfa-code",className:"ss-input",type:"text",inputMode:"numeric",autoComplete:"one-time-code",placeholder:"Enter 6-digit code",value:N,onChange:E=>w(E.target.value),autoFocus:!0})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-email",children:"Email"}),s.jsx("input",{id:"ss-email",className:"ss-input",type:"email",autoComplete:"email",placeholder:"you@example.com",value:g,onChange:E=>h(E.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-password",children:"Password"}),s.jsx("input",{id:"ss-password",className:"ss-input",type:"password",autoComplete:"current-password",placeholder:"Enter your password",value:f,onChange:E=>b(E.target.value),required:!0})]})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:l,children:[l&&s.jsx("span",{className:"ss-spinner"}),v?"Verify":"Continue"]})]}),v&&s.jsx("div",{className:"ss-footer",children:s.jsx("span",{className:"ss-link",onClick:()=>{y(!1),w(""),x(null)},children:"Back to sign in"})}),!v&&s.jsxs("div",{className:"ss-footer",children:["Don't have an account?"," ",r?s.jsx("span",{className:"ss-link",onClick:r,children:"Sign up"}):t?s.jsx("a",{className:"ss-link",href:t,children:"Sign up"}):s.jsx("span",{className:"ss-link",children:"Sign up"})]})]})})}function gs({appearance:e,signInUrl:t,onSignIn:r}){const{appearance:i,settings:n}=C(),{signUp:c,isLoading:d,error:u,setError:l}=Q(),{signInWithOAuth:o}=H(),x=e??i,[p,g]=a.useState(""),[h,f]=a.useState(""),[b,v]=a.useState(""),[y,m]=a.useState(null),j=a.useCallback(async k=>{if(k.preventDefault(),m(null),h!==b){m("Passwords do not match");return}const T=(n==null?void 0:n.passwordMinLength)??8;if(h.length<T){m(`Password must be at least ${T} characters`);return}await c(p,h)},[p,h,b,n,c]),N=a.useCallback(async k=>{await o(k)},[o]),w=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled),P=y||u;return s.jsx(z,{appearance:x,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Create account"}),(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>N("google"),disabled:d,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:J}}),"Continue with Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>N("github"),disabled:d,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:Y}}),"Continue with GitHub"]}),w&&s.jsx("div",{className:"ss-divider",children:"or"}),P&&s.jsx("div",{className:"ss-global-error",children:P}),s.jsxs("form",{onSubmit:j,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-signup-email",children:"Email"}),s.jsx("input",{id:"ss-signup-email",className:"ss-input",type:"email",autoComplete:"email",placeholder:"you@example.com",value:p,onChange:k=>g(k.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-signup-password",children:"Password"}),s.jsx("input",{id:"ss-signup-password",className:"ss-input",type:"password",autoComplete:"new-password",placeholder:"Create a password",value:h,onChange:k=>{f(k.target.value),m(null)},required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-signup-confirm",children:"Confirm password"}),s.jsx("input",{id:"ss-signup-confirm",className:"ss-input",type:"password",autoComplete:"new-password",placeholder:"Confirm your password",value:b,onChange:k=>{v(k.target.value),m(null)},required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:d,children:[d&&s.jsx("span",{className:"ss-spinner"}),"Create account"]})]}),s.jsxs("div",{className:"ss-footer",children:["Already have an account?"," ",r?s.jsx("span",{className:"ss-link",onClick:r,children:"Sign in"}):t?s.jsx("a",{className:"ss-link",href:t,children:"Sign in"}):s.jsx("span",{className:"ss-link",children:"Sign in"})]})]})})}const $=256,D=112;function hs({file:e,onCrop:t,onCancel:r}){const i=a.useRef(null),n=a.useRef(null),[c,d]=a.useState(1),[u,l]=a.useState({x:0,y:0}),[o,x]=a.useState(!1),p=a.useRef({x:0,y:0,ox:0,oy:0}),[g,h]=a.useState(!1);a.useEffect(()=>{const m=new Image,j=URL.createObjectURL(e);return m.onload=()=>{n.current=m,h(!0),l({x:0,y:0}),d(1)},m.src=j,()=>URL.revokeObjectURL(j)},[e]),a.useEffect(()=>{if(!g||!n.current||!i.current)return;const m=i.current.getContext("2d");if(!m)return;const j=n.current;m.clearRect(0,0,$,$),m.fillStyle="#111",m.fillRect(0,0,$,$);const N=Math.max($/j.width,$/j.height)*c,w=j.width*N,P=j.height*N,k=($-w)/2+u.x,T=($-P)/2+u.y;m.save(),m.beginPath(),m.arc($/2,$/2,D,0,Math.PI*2),m.clip(),m.drawImage(j,k,T,w,P),m.restore(),m.save(),m.fillStyle="rgba(0, 0, 0, 0.6)",m.fillRect(0,0,$,$),m.globalCompositeOperation="destination-out",m.beginPath(),m.arc($/2,$/2,D,0,Math.PI*2),m.fill(),m.restore(),m.save(),m.beginPath(),m.arc($/2,$/2,D,0,Math.PI*2),m.clip(),m.drawImage(j,k,T,w,P),m.restore(),m.strokeStyle="rgba(255, 255, 255, 0.6)",m.lineWidth=2,m.beginPath(),m.arc($/2,$/2,D,0,Math.PI*2),m.stroke()},[c,u,g]);const f=a.useCallback(m=>{x(!0),p.current={x:m.clientX,y:m.clientY,ox:u.x,oy:u.y},m.target.setPointerCapture(m.pointerId)},[u]),b=a.useCallback(m=>{o&&l({x:p.current.ox+(m.clientX-p.current.x),y:p.current.oy+(m.clientY-p.current.y)})},[o]),v=a.useCallback(()=>x(!1),[]),y=a.useCallback(()=>{if(!n.current)return;const m=document.createElement("canvas"),j=D*2;m.width=j,m.height=j;const N=m.getContext("2d");if(!N)return;const w=n.current,P=Math.max($/w.width,$/w.height)*c,k=w.width*P,T=w.height*P,E=($-k)/2+u.x-($/2-D),S=($-T)/2+u.y-($/2-D);N.beginPath(),N.arc(D,D,D,0,Math.PI*2),N.clip(),N.drawImage(w,E,S,k,T),m.toBlob(L=>{L&&t(L)},"image/png")},[c,u,t]);return s.jsxs("div",{className:"ss-avatar-cropper",children:[s.jsx("canvas",{ref:i,width:$,height:$,className:"ss-avatar-canvas",onPointerDown:f,onPointerMove:b,onPointerUp:v,style:{cursor:o?"grabbing":"grab"}}),s.jsxs("div",{className:"ss-avatar-zoom",children:[s.jsx("span",{className:"ss-avatar-zoom-label",children:"Zoom"}),s.jsx("input",{type:"range",min:"1",max:"3",step:"0.01",value:c,onChange:m=>d(parseFloat(m.target.value)),className:"ss-avatar-zoom-slider"})]}),s.jsxs("div",{className:"ss-btn-group",children:[s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger ss-btn-sm",onClick:r,children:"Cancel"}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-primary ss-btn-sm",onClick:y,children:"Save"})]})]})}function Z({onUpload:e,onClose:t,isLoading:r}){const[i,n]=a.useState(null),[c,d]=a.useState(!1),[u,l]=a.useState(null),o=a.useRef(null),x=a.useCallback(h=>{if(!h.type.startsWith("image/")){l("Please select an image file");return}if(h.size>5*1024*1024){l("Image must be smaller than 5 MB");return}l(null),n(h)},[]),p=a.useCallback(h=>{h.preventDefault(),d(!1);const f=h.dataTransfer.files[0];f&&x(f)},[x]),g=a.useCallback(async h=>{await e(h)},[e]);return s.jsx("div",{className:"ss-modal-overlay",onClick:h=>{h.target===h.currentTarget&&t()},children:s.jsxs("div",{className:"ss-modal",children:[s.jsxs("div",{className:"ss-modal-header",children:[s.jsx("span",{className:"ss-modal-title",children:"Upload Avatar"}),s.jsx("button",{type:"button",className:"ss-modal-close",onClick:t,children:"✕"})]}),u&&s.jsx("div",{className:"ss-global-error",children:u}),i?s.jsx(hs,{file:i,onCrop:g,onCancel:()=>n(null)}):s.jsxs("div",{className:`ss-avatar-dropzone${c?" ss-avatar-dropzone-active":""}`,onDragOver:h=>{h.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:p,onClick:()=>{var h;return(h=o.current)==null?void 0:h.click()},children:[s.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[s.jsx("path",{d:"M12 16a4 4 0 100-8 4 4 0 000 8z"}),s.jsx("path",{d:"M3 16.8V9.2c0-1.12 0-1.68.218-2.108a2 2 0 01.874-.874C4.52 6 5.08 6 6.2 6h.382c.246 0 .37 0 .482-.022a1 1 0 00.513-.29c.08-.082.148-.186.284-.392l.079-.118C8.08 4.968 8.15 4.863 8.234 4.77a2 2 0 01.965-.61C9.346 4.1 9.508 4.1 9.834 4.1h4.332c.326 0 .488 0 .636.06a2 2 0 01.965.61c.083.094.153.198.293.408l.079.118c.136.206.204.31.284.392a1 1 0 00.513.29c.112.022.236.022.482.022h.382c1.12 0 1.68 0 2.108.218a2 2 0 01.874.874C21 7.52 21 8.08 21 9.2v7.6c0 1.12 0 1.68-.218 2.108a2 2 0 01-.874.874C19.48 20 18.92 20 17.8 20H6.2c-1.12 0-1.68 0-2.108-.218a2 2 0 01-.874-.874C3 18.48 3 17.92 3 16.8z"})]}),s.jsx("span",{children:"Drop image here or click to browse"}),s.jsx("input",{ref:o,type:"file",accept:"image/*",style:{display:"none"},onChange:h=>{var f;(f=h.target.files)!=null&&f[0]&&x(h.target.files[0])}})]}),r&&s.jsx("div",{className:"ss-loading",children:"Uploading..."})]})})}function bs({appearance:e}){const{appearance:t}=C(),{user:r,signOut:i}=W(),n=e??t,[c,d]=a.useState(!1),[u,l]=a.useState(!1),o=a.useRef(null),x=a.useCallback(g=>{o.current&&!g.composedPath().includes(o.current)&&d(!1)},[]);if(a.useEffect(()=>{if(c){const g=setTimeout(()=>{document.addEventListener("click",x)},0);return()=>{clearTimeout(g),document.removeEventListener("click",x)}}},[c,x]),!r)return null;const p=(r.name||r.email).charAt(0).toUpperCase();return s.jsx(z,{appearance:n,children:s.jsxs("div",{className:"ss-user-btn",ref:o,children:[s.jsx("button",{type:"button",className:"ss-avatar",onClick:()=>d(!c),"aria-label":"User menu",children:r.avatarUrl?s.jsx("img",{src:r.avatarUrl,alt:"",style:{width:"100%",height:"100%",borderRadius:"50%",objectFit:"cover"}}):p}),c&&s.jsxs("div",{className:"ss-dropdown",children:[s.jsxs("div",{className:"ss-dropdown-header",children:[r.name&&s.jsx("div",{style:{fontWeight:600,fontSize:"14px",color:"inherit"},children:r.name}),s.jsx("div",{className:"ss-dropdown-email",children:r.email})]}),s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>{d(!1),l(!0)},children:"Profile"}),s.jsx("button",{type:"button",className:"ss-dropdown-item ss-dropdown-item-danger",onClick:async()=>{d(!1),await i()},children:"Sign out"})]}),u&&s.jsx(fs,{onClose:()=>l(!1)})]})})}function fs({onClose:e}){const{user:t,updateProfile:r,uploadAvatar:i,changePassword:n,isLoading:c,error:d,success:u,setError:l,setSuccess:o}=_(),[x,p]=a.useState((t==null?void 0:t.name)??""),[g,h]=a.useState((t==null?void 0:t.avatarUrl)??""),[f,b]=a.useState(!1),[v,y]=a.useState(""),[m,j]=a.useState(""),[N,w]=a.useState(""),[P,k]=a.useState(null),T=a.useCallback(async I=>{I.preventDefault(),l(null),o(null),await r({name:x,avatarUrl:g||void 0})},[x,g,r,l,o]),E=a.useCallback(async I=>{const A=await i(I);A&&(h(A.avatarUrl),b(!1))},[i]),S=a.useCallback(async I=>{if(I.preventDefault(),k(null),l(null),o(null),m!==N){k("Passwords do not match");return}if(m.length<8){k("Password must be at least 8 characters");return}await n(v,m)&&(y(""),j(""),w(""))},[v,m,N,n,l,o]),L=(t==null?void 0:t.provider)==="email";return s.jsx("div",{className:"ss-modal-overlay",onClick:I=>{I.target===I.currentTarget&&e()},children:s.jsxs("div",{className:"ss-modal",children:[s.jsxs("div",{className:"ss-modal-header",children:[s.jsx("span",{className:"ss-modal-title",children:"Profile"}),s.jsx("button",{type:"button",className:"ss-modal-close",onClick:e,children:"✕"})]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),u&&s.jsx("div",{className:"ss-success-msg",children:u}),s.jsxs("div",{className:"ss-avatar-preview ss-avatar-hoverable",onClick:()=>b(!0),title:"Click to change avatar",children:[g?s.jsx("img",{src:g,alt:""}):(x||(t==null?void 0:t.email)||"?").charAt(0).toUpperCase(),s.jsx("div",{className:"ss-avatar-overlay",children:s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("path",{d:"M12 16a4 4 0 100-8 4 4 0 000 8z"}),s.jsx("path",{d:"M3 16.8V9.2c0-1.12 0-1.68.218-2.108a2 2 0 01.874-.874C4.52 6 5.08 6 6.2 6h.382c.246 0 .37 0 .482-.022a1 1 0 00.513-.29c.08-.082.148-.186.284-.392l.079-.118C8.08 4.968 8.15 4.863 8.234 4.77a2 2 0 01.965-.61C9.346 4.1 9.508 4.1 9.834 4.1h4.332c.326 0 .488 0 .636.06a2 2 0 01.965.61c.083.094.153.198.293.408l.079.118c.136.206.204.31.284.392a1 1 0 00.513.29c.112.022.236.022.482.022h.382c1.12 0 1.68 0 2.108.218a2 2 0 01.874.874C21 7.52 21 8.08 21 9.2v7.6c0 1.12 0 1.68-.218 2.108a2 2 0 01-.874.874C19.48 20 18.92 20 17.8 20H6.2c-1.12 0-1.68 0-2.108-.218a2 2 0 01-.874-.874C3 18.48 3 17.92 3 16.8z"})]})})]}),s.jsxs("form",{onSubmit:T,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Name"}),s.jsx("input",{className:"ss-input",type:"text",placeholder:"Your name",value:x,onChange:I=>p(I.target.value)})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Email"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"email",value:(t==null?void 0:t.email)??"",disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Provider"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"text",value:(t==null?void 0:t.provider)??"",disabled:!0,readOnly:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:c,children:[c&&s.jsx("span",{className:"ss-spinner"}),"Save changes"]})]}),L&&s.jsxs("div",{className:"ss-modal-section",children:[s.jsx("div",{className:"ss-modal-section-title",children:"Change password"}),P&&s.jsx("div",{className:"ss-global-error",children:P}),s.jsxs("form",{onSubmit:S,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Current password"}),s.jsx("input",{className:"ss-input",type:"password",value:v,onChange:I=>y(I.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"New password"}),s.jsx("input",{className:"ss-input",type:"password",value:m,onChange:I=>j(I.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Confirm new password"}),s.jsx("input",{className:"ss-input",type:"password",value:N,onChange:I=>w(I.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:c,children:[c&&s.jsx("span",{className:"ss-spinner"}),"Update password"]})]})]}),f&&s.jsx(Z,{onUpload:E,onClose:()=>b(!1),isLoading:c})]})})}function ys({appearance:e}){const{appearance:t}=C(),{user:r,signOut:i}=W(),{updateProfile:n,uploadAvatar:c,changePassword:d,isLoading:u,error:l,success:o,setError:x,setSuccess:p}=_(),g=e??t,[h,f]=a.useState((r==null?void 0:r.name)??""),[b,v]=a.useState((r==null?void 0:r.avatarUrl)??""),[y,m]=a.useState(!1),[j,N]=a.useState(""),[w,P]=a.useState(""),[k,T]=a.useState(""),[E,S]=a.useState(null),L=a.useCallback(async B=>{B.preventDefault(),x(null),p(null),await n({name:h,avatarUrl:b||void 0})},[h,b,n,x,p]),I=a.useCallback(async B=>{const q=await c(B);q&&(v(q.avatarUrl),m(!1))},[c]),A=a.useCallback(async B=>{if(B.preventDefault(),S(null),x(null),p(null),w!==k){S("Passwords do not match");return}if(w.length<8){S("Password must be at least 8 characters");return}await d(j,w)&&(N(""),P(""),T(""))},[j,w,k,d,x,p]);if(!r)return null;const ls=r.provider==="email";return s.jsx(z,{appearance:g,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Profile"}),l&&s.jsx("div",{className:"ss-global-error",children:l}),o&&s.jsx("div",{className:"ss-success-msg",children:o}),s.jsxs("div",{className:"ss-avatar-preview ss-avatar-hoverable",style:{margin:"0 auto 16px"},onClick:()=>m(!0),title:"Click to change avatar",children:[b?s.jsx("img",{src:b,alt:""}):(h||r.email).charAt(0).toUpperCase(),s.jsx("div",{className:"ss-avatar-overlay",children:s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("path",{d:"M12 16a4 4 0 100-8 4 4 0 000 8z"}),s.jsx("path",{d:"M3 16.8V9.2c0-1.12 0-1.68.218-2.108a2 2 0 01.874-.874C4.52 6 5.08 6 6.2 6h.382c.246 0 .37 0 .482-.022a1 1 0 00.513-.29c.08-.082.148-.186.284-.392l.079-.118C8.08 4.968 8.15 4.863 8.234 4.77a2 2 0 01.965-.61C9.346 4.1 9.508 4.1 9.834 4.1h4.332c.326 0 .488 0 .636.06a2 2 0 01.965.61c.083.094.153.198.293.408l.079.118c.136.206.204.31.284.392a1 1 0 00.513.29c.112.022.236.022.482.022h.382c1.12 0 1.68 0 2.108.218a2 2 0 01.874.874C21 7.52 21 8.08 21 9.2v7.6c0 1.12 0 1.68-.218 2.108a2 2 0 01-.874.874C19.48 20 18.92 20 17.8 20H6.2c-1.12 0-1.68 0-2.108-.218a2 2 0 01-.874-.874C3 18.48 3 17.92 3 16.8z"})]})})]}),s.jsxs("form",{onSubmit:L,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Name"}),s.jsx("input",{className:"ss-input",type:"text",placeholder:"Your name",value:h,onChange:B=>f(B.target.value)})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Email"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"email",value:r.email,disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Provider"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"text",value:r.provider,disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Email verified"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"text",value:r.emailVerified?"Yes":"No",disabled:!0,readOnly:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:u,children:[u&&s.jsx("span",{className:"ss-spinner"}),"Save changes"]})]}),ls&&s.jsxs("div",{className:"ss-modal-section",children:[s.jsx("div",{className:"ss-modal-section-title",children:"Change password"}),E&&s.jsx("div",{className:"ss-global-error",children:E}),s.jsxs("form",{onSubmit:A,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Current password"}),s.jsx("input",{className:"ss-input",type:"password",value:j,onChange:B=>N(B.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"New password"}),s.jsx("input",{className:"ss-input",type:"password",value:w,onChange:B=>P(B.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Confirm new password"}),s.jsx("input",{className:"ss-input",type:"password",value:k,onChange:B=>T(B.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:u,children:[u&&s.jsx("span",{className:"ss-spinner"}),"Update password"]})]})]}),s.jsx("div",{style:{marginTop:"24px"},children:s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:()=>i(),children:"Sign out"})}),y&&s.jsx(Z,{onUpload:I,onClose:()=>m(!1),isLoading:u})]})})}function vs({appearance:e,onOrgChange:t}){const{appearance:r}=C(),{orgs:i,selectedOrg:n,selectOrg:c,createOrg:d,isLoading:u}=G(),l=e??r,[o,x]=a.useState(!1),[p,g]=a.useState(!1),[h,f]=a.useState(""),[b,v]=a.useState(""),[y,m]=a.useState(null),[j,N]=a.useState(!1),w=a.useRef(null),P=a.useCallback(S=>{w.current&&!S.composedPath().includes(w.current)&&(x(!1),g(!1))},[]);a.useEffect(()=>{if(o){const S=setTimeout(()=>{document.addEventListener("click",P)},0);return()=>{clearTimeout(S),document.removeEventListener("click",P)}}},[o,P]);const k=a.useCallback(S=>{f(S),v(S.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},[]),T=a.useCallback(async S=>{S.preventDefault(),m(null),N(!0);try{const L=await d(h,b);L&&(await c(L.id),t==null||t(L),g(!1),f(""),v(""),x(!1))}catch(L){m(L instanceof Error?L.message:"Failed to create organization")}finally{N(!1)}},[h,b,d,c,t]);if(u)return null;const E=(n==null?void 0:n.name)??(i.length===0?"No organization":"Select organization");return s.jsx(z,{appearance:l,children:s.jsxs("div",{className:"ss-user-btn",ref:w,children:[s.jsxs("button",{type:"button",className:"ss-btn ss-btn-org-switcher",onClick:()=>x(!o),children:[E,s.jsx("span",{className:"ss-chevron",children:o?"▲":"▼"})]}),o&&s.jsxs("div",{className:"ss-dropdown ss-dropdown-org",children:[i.map(S=>s.jsx("button",{type:"button",className:`ss-dropdown-item ${(n==null?void 0:n.id)===S.id?"ss-dropdown-item-active":""}`,onClick:async()=>{x(!1),g(!1),await c(S.id),t==null||t(S)},children:S.name},S.id)),s.jsx("div",{className:"ss-dropdown-divider"}),p?s.jsxs("div",{className:"ss-inline-form",children:[y&&s.jsx("div",{className:"ss-global-error",style:{marginBottom:"8px",fontSize:"12px"},children:y}),s.jsxs("form",{onSubmit:T,children:[s.jsx("div",{className:"ss-field",children:s.jsx("input",{className:"ss-input",type:"text",placeholder:"Organization name",value:h,onChange:S=>k(S.target.value),required:!0,autoFocus:!0})}),s.jsx("div",{className:"ss-field",children:s.jsx("input",{className:"ss-input",type:"text",placeholder:"org-slug",value:b,onChange:S=>v(S.target.value),required:!0})}),s.jsxs("div",{className:"ss-btn-group",style:{marginTop:"8px"},children:[s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-current",onClick:()=>{g(!1),m(null)},children:"Cancel"}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:j,children:[j&&s.jsx("span",{className:"ss-spinner"}),"Create"]})]})]})]}):s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>g(!0),style:{fontWeight:500},children:"+ Create organization"})]})]})})}function js(e,t="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:e%100===0?0:2}).format(e/100)}function ws({plans:e,currentPlanId:t,onSelectPlan:r,interval:i,appearance:n}){const{appearance:c}=C(),d=n??c,u=i?e.filter(l=>l.interval===i||l.isFree):e;return s.jsx(z,{appearance:d,children:s.jsx("div",{className:"ss-pricing-grid",children:u.map(l=>{const o=l.id===t;return s.jsxs("div",{className:`ss-pricing-card ${o?"ss-pricing-card-current":""}`,children:[s.jsxs("div",{className:"ss-pricing-header",children:[s.jsx("h3",{className:"ss-pricing-name",children:l.name}),l.trialDays>0&&s.jsxs("span",{className:"ss-badge ss-badge-trialing",children:[l.trialDays,"-day trial"]}),l.isFree&&s.jsx("span",{className:"ss-badge ss-badge-active",children:"Free"})]}),s.jsx("div",{className:"ss-pricing-price",children:l.isFree?s.jsx("span",{className:"ss-pricing-amount",children:"Free"}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ss-pricing-amount",children:js(l.amountCents,l.currency)}),s.jsxs("span",{className:"ss-pricing-interval",children:["/",l.interval]})]})}),l.description&&s.jsx("p",{className:"ss-pricing-desc",children:l.description}),l.features.length>0&&s.jsx("ul",{className:"ss-pricing-features",children:l.features.map((x,p)=>s.jsxs("li",{className:"ss-pricing-feature",children:[s.jsx("span",{className:"ss-check",children:"✓"})," ",x]},p))}),s.jsx("button",{type:"button",className:`ss-btn ${o?"ss-btn-current":"ss-btn-primary"}`,disabled:o,onClick:()=>r(l.id),children:o?"Current plan":"Select plan"})]},l.id)})})})}function Ns(){const{client:e}=C();return{billing:e.billing}}function U(e){const{client:t}=C();return a.useMemo(()=>{if(e){const r=new M.Transport("https://api.saas-support.com/v1",{type:"portalToken",token:e});return new M.BillingClient(r)}return t.billing},[t,e])}function X(e,t){const r=U(t),[i,n]=a.useState(null),[c,d]=a.useState(!0),[u,l]=a.useState(null),o=a.useCallback(async()=>{d(!0),l(null);try{const x=await r.getCustomer(e);n(x)}catch(x){l(x instanceof Error?x.message:"Failed to load subscription")}finally{d(!1)}},[r,e]);return a.useEffect(()=>{o()},[o]),{customer:i,isLoading:c,error:u,refresh:o}}function K(e,t){const r=U(t),[i,n]=a.useState([]),[c,d]=a.useState(!0),[u,l]=a.useState(null),o=a.useCallback(async()=>{d(!0),l(null);try{const x=await r.getInvoices(e);n(x)}catch(x){l(x instanceof Error?x.message:"Failed to load invoices")}finally{d(!1)}},[r,e]);return a.useEffect(()=>{o()},[o]),{invoices:i,isLoading:c,error:u,refresh:o}}function ss(e,t){const r=U(t),[i,n]=a.useState([]),[c,d]=a.useState(!0),[u,l]=a.useState(null),o=a.useCallback(async()=>{d(!0),l(null);try{const x=await r.getCurrentUsage(e);n(x)}catch(x){l(x instanceof Error?x.message:"Failed to load usage")}finally{d(!1)}},[r,e]);return a.useEffect(()=>{o()},[o]),{usage:i,isLoading:c,error:u,refresh:o}}const Ss={active:"ss-badge-active"};function es({customerId:e,portalToken:t,onChangePlan:r,onCancel:i,appearance:n}){const{appearance:c}=C(),{customer:d,isLoading:u,error:l}=X(e,t),o=n??c;return s.jsx(z,{appearance:o,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Subscription"}),u&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),l&&s.jsx("div",{className:"ss-global-error",children:l}),d&&!u&&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:d.name||d.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 ${Ss.active}`,children:"Active"})})]}),s.jsxs("div",{className:"ss-btn-group",children:[r&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-primary",onClick:r,children:"Change plan"}),i&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:i,children:"Cancel subscription"})]})]})]})})}const Cs={paid:"ss-badge-active",open:"ss-badge-trialing",draft:"ss-badge-paused",void:"ss-badge-canceled",uncollectible:"ss-badge-past-due"};function ks(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function $s(e){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(e/100)}function as({customerId:e,portalToken:t,appearance:r}){const{appearance:i}=C(),{invoices:n,isLoading:c,error:d}=K(e,t),u=r??i,l=[...n].sort((o,x)=>new Date(x.createdAt).getTime()-new Date(o.createdAt).getTime());return s.jsx(z,{appearance:u,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Invoices"}),c&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),!c&&l.length===0&&s.jsx("p",{className:"ss-empty",children:"No invoices yet."}),!c&&l.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:l.map(o=>s.jsxs("tr",{className:"ss-tr",children:[s.jsx("td",{className:"ss-td",children:ks(o.createdAt)}),s.jsx("td",{className:"ss-td",children:$s(o.amountCents)}),s.jsx("td",{className:"ss-td",children:s.jsx("span",{className:`ss-badge ${Cs[o.status]||""}`,children:o.status})}),s.jsx("td",{className:"ss-td",children:o.pdfUrl?s.jsx("a",{className:"ss-link",href:o.pdfUrl,target:"_blank",rel:"noopener noreferrer",children:"Download"}):"—"})]},o.id))})]})]})})}function rs({customerId:e,limits:t,portalToken:r,appearance:i}){const{appearance:n}=C(),{usage:c,isLoading:d,error:u}=ss(e,r),l=i??n;return s.jsx(z,{appearance:l,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Usage"}),d&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),u&&s.jsx("div",{className:"ss-global-error",children:u}),!d&&c.length===0&&s.jsx("p",{className:"ss-empty",children:"No usage data."}),!d&&c.map(o=>{const x=t==null?void 0:t[o.metric],p=x?Math.min(100,o.total/x*100):null;return s.jsxs("div",{className:"ss-usage-item",children:[s.jsxs("div",{className:"ss-usage-header",children:[s.jsx("span",{className:"ss-usage-metric",children:o.metric}),s.jsxs("span",{className:"ss-usage-value",children:[o.total.toLocaleString(),x?` / ${x.toLocaleString()}`:""]})]}),p!==null&&s.jsx("div",{className:"ss-progress-bar",children:s.jsx("div",{className:`ss-progress-fill ${p>90?"ss-progress-danger":""}`,style:{width:`${p}%`}})})]},o.metric)})]})})}function Ps({customerId:e,portalToken:t,limits:r,onChangePlan:i,onCancel:n,appearance:c}){const{appearance:d}=C(),u=c??d,[l,o]=a.useState("subscription"),x=[{id:"subscription",label:"Subscription"},{id:"invoices",label:"Invoices"},{id:"usage",label:"Usage"}];return s.jsx(z,{appearance:u,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Billing"}),s.jsx("div",{className:"ss-tab-group",children:x.map(p=>s.jsx("button",{type:"button",className:`ss-tab ${l===p.id?"ss-tab-active":""}`,onClick:()=>o(p.id),children:p.label},p.id))}),s.jsxs("div",{className:"ss-tab-content",children:[l==="subscription"&&s.jsx(es,{customerId:e,portalToken:t,onChangePlan:i,onCancel:n}),l==="invoices"&&s.jsx(as,{customerId:e,portalToken:t}),l==="usage"&&s.jsx(rs,{customerId:e,portalToken:t,limits:r})]})]})})}function Es({customerId:e,portalToken:t,onApplied:r,appearance:i}){const{appearance:n}=C(),c=U(t),d=i??n,[u,l]=a.useState(""),[o,x]=a.useState(!1),[p,g]=a.useState(null),[h,f]=a.useState(null),b=a.useCallback(async v=>{if(v.preventDefault(),!!u.trim()){x(!0),g(null),f(null);try{const y=await c.applyCoupon(e,u.trim());f(`Coupon applied! ${y.discountType==="percent"?`${y.amount}% off`:`$${(y.amount/100).toFixed(2)} off`}`),l(""),r==null||r(y)}catch(y){g(y instanceof Error?y.message:"Invalid coupon code")}finally{x(!1)}}},[c,e,u,r]);return s.jsx(z,{appearance:d,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}),h&&s.jsx("div",{className:"ss-success-msg",children:h}),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:u,onChange:v=>l(v.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:o||!u.trim(),children:[o&&s.jsx("span",{className:"ss-spinner"}),"Apply"]})]})]})})}function Is(){const{client:e}=C();return{report:e.report}}function V(){const{client:e}=C(),[t,r]=a.useState(null),[i,n]=a.useState(!1),[c,d]=a.useState(null),u=a.useCallback(async l=>{n(!0),d(null);try{const o=await e.report.executeQuery(l);return r(o),o}catch(o){return d(o instanceof Error?o.message:"Query failed"),null}finally{n(!1)}},[e]);return{result:t,execute:u,isLoading:i,error:c}}function ts(e){const{client:t}=C(),[r,i]=a.useState(null),[n,c]=a.useState(!0),[d,u]=a.useState(null),l=a.useCallback(async()=>{c(!0),u(null);try{const o=await t.report.listQueries(e);i(o)}catch(o){u(o instanceof Error?o.message:"Failed to load queries")}finally{c(!1)}},[t,e]);return a.useEffect(()=>{l()},[l]),{queries:(r==null?void 0:r.data)??[],meta:r==null?void 0:r.meta,isLoading:n,error:d,refresh:l}}function Ts(e){const{client:t}=C(),[r,i]=a.useState(null),[n,c]=a.useState(!0),[d,u]=a.useState(null),l=a.useCallback(async()=>{c(!0),u(null);try{const o=await t.report.getDashboard(e);i(o)}catch(o){u(o instanceof Error?o.message:"Failed to load dashboard")}finally{c(!1)}},[t,e]);return a.useEffect(()=>{l()},[l]),{dashboard:r,isLoading:n,error:d,refresh:l}}function zs(e,t,r="https://api.saas-support.com/v1"){const i=a.useMemo(()=>{const p=new M.Transport(r,{type:"embedToken",token:e});return new M.ReportClient(p)},[e,r]),[n,c]=a.useState(null),[d,u]=a.useState(!0),[l,o]=a.useState(null),x=a.useCallback(async()=>{u(!0),o(null);try{const p=await i.getDashboard(t);c(p)}catch(p){o(p instanceof Error?p.message:"Failed to load dashboard")}finally{u(!1)}},[i,t]);return a.useEffect(()=>{x()},[x]),{dashboard:n,reportClient:i,isLoading:d,error:l,refresh:x}}function Ls({onResult:e,mode:t="both",placeholder:r,appearance:i}){const{appearance:n}=C(),{execute:c,isLoading:d,error:u}=V(),l=i??n,[o,x]=a.useState(""),[p,g]=a.useState(t==="sql"?"sql":"nl"),h=a.useCallback(async f=>{if(f.preventDefault(),!o.trim())return;const v=await c(p==="sql"?{sql:o}:{naturalLanguage:o});v&&(e==null||e(v))},[o,p,c,e]);return s.jsx(z,{appearance:l,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[t==="both"&&s.jsxs("div",{className:"ss-tab-group ss-tab-group-sm",children:[s.jsx("button",{type:"button",className:`ss-tab ${p==="nl"?"ss-tab-active":""}`,onClick:()=>g("nl"),children:"Natural Language"}),s.jsx("button",{type:"button",className:`ss-tab ${p==="sql"?"ss-tab-active":""}`,onClick:()=>g("sql"),children:"SQL"})]}),u&&s.jsx("div",{className:"ss-global-error",children:u}),s.jsxs("form",{onSubmit:h,children:[s.jsx("div",{className:"ss-field",children:s.jsx("textarea",{className:"ss-input ss-query-textarea",placeholder:r??(p==="sql"?"SELECT ...":"Ask a question about your data..."),value:o,onChange:f=>x(f.target.value),rows:3})}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:d||!o.trim(),children:[d&&s.jsx("span",{className:"ss-spinner"}),"Run query"]})]})]})})}function ns({columns:e,rows:t,sortable:r=!0,maxRows:i,appearance:n}){const{appearance:c}=C(),d=n??c,[u,l]=a.useState(null),[o,x]=a.useState("asc"),p=a.useMemo(()=>u?[...t].sort((b,v)=>{const y=b[u],m=v[u];if(y==null&&m==null)return 0;if(y==null)return 1;if(m==null)return-1;if(typeof y=="number"&&typeof m=="number")return o==="asc"?y-m:m-y;const j=String(y),N=String(m);return o==="asc"?j.localeCompare(N):N.localeCompare(j)}):t,[t,u,o]),g=i?p.slice(0,i):p,h=b=>{r&&(u===b?x(v=>v==="asc"?"desc":"asc"):(l(b),x("asc")))};function f(b){return b==null?"":typeof b=="object"?JSON.stringify(b):String(b)}return s.jsx(z,{appearance:d,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 ${r?"ss-th-sortable":""} ${u===b?o==="asc"?"ss-sorted-asc":"ss-sorted-desc":""}`,onClick:()=>h(b),children:[b,u===b&&s.jsx("span",{className:"ss-sort-indicator",children:o==="asc"?" ▲":" ▼"})]},b))})}),s.jsx("tbody",{children:g.map((b,v)=>s.jsx("tr",{className:"ss-tr",children:e.map(y=>s.jsx("td",{className:"ss-td",children:f(b[y])},y))},v))})]}),i&&t.length>i&&s.jsxs("div",{className:"ss-table-footer",children:["Showing ",i," of ",t.length," rows"]})]})})}function Bs(e,t="#6366f1"){const r=parseInt(t.replace("#","").slice(0,2),16),i=[];for(let n=0;n<e;n++){const c=(r+n*Math.floor(360/Math.max(e,1)))%360;i.push(`hsl(${c}, 65%, 55%)`)}return i}function Ms({labels:e,values:t,w:r,h:i,colors:n}){const c=Math.max(...t,1),d=40,u=r-d*2,l=i-d*2,o=Math.max(1,u/e.length-4);return s.jsxs("g",{children:[s.jsx("line",{x1:d,y1:i-d,x2:r-d,y2:i-d,stroke:"#ccc",strokeWidth:1}),t.map((x,p)=>{const g=x/c*l,h=d+u/e.length*p+2,f=i-d-g;return s.jsxs("g",{children:[s.jsx("rect",{x:h,y:f,width:o,height:g,fill:n[p%n.length],rx:2}),s.jsx("text",{x:h+o/2,y:i-d+14,textAnchor:"middle",fontSize:10,fill:"#666",children:e[p].length>8?e[p].slice(0,8)+"...":e[p]})]},p)})]})}function Ds({labels:e,values:t,w:r,h:i,colors:n}){const c=Math.max(...t,1),d=40,u=r-d*2,l=i-d*2,o=e.length>1?u/(e.length-1):0,x=t.map((p,g)=>{const h=d+o*g,f=i-d-p/c*l;return`${h},${f}`});return s.jsxs("g",{children:[[.25,.5,.75,1].map(p=>{const g=i-d-p*l;return s.jsx("line",{x1:d,y1:g,x2:r-d,y2:g,stroke:"#eee",strokeWidth:1},p)}),s.jsx("polyline",{points:x.join(" "),fill:"none",stroke:n[0],strokeWidth:2}),t.map((p,g)=>{const h=d+o*g,f=i-d-p/c*l;return s.jsx("circle",{cx:h,cy:f,r:4,fill:n[0]},g)})]})}function As({labels:e,values:t,w:r,h:i,colors:n}){const c=t.reduce((g,h)=>g+h,0)||1,d=r/2,u=i/2-20,l=Math.min(r,i)/2-40,o=2*Math.PI*l;let x=0;const p=t.map((g,h)=>{const f=g/c,b=f*o,v={dash:b,offset:x,color:n[h%n.length],label:e[h],pct:f};return x+=b,v});return s.jsxs("g",{children:[p.map((g,h)=>s.jsx("circle",{cx:d,cy:u,r:l,fill:"none",stroke:g.color,strokeWidth:l*.6,strokeDasharray:`${g.dash} ${o-g.dash}`,strokeDashoffset:-g.offset,transform:`rotate(-90 ${d} ${u})`},h)),s.jsx("g",{transform:`translate(${d-e.length*30}, ${i-20})`,children:p.slice(0,6).map((g,h)=>s.jsxs("g",{transform:`translate(${h*60}, 0)`,children:[s.jsx("rect",{width:10,height:10,fill:g.color,rx:2}),s.jsx("text",{x:14,y:9,fontSize:9,fill:"#666",children:g.label.length>6?g.label.slice(0,6)+"..":g.label})]},h))})]})}function os({type:e,data:t,title:r,width:i=400,height:n=300,appearance:c}){const{appearance:d}=C(),u=c??d,l=a.useMemo(()=>Bs(t.labels.length),[t.labels.length]);return s.jsx(z,{appearance:u,children:s.jsxs("div",{className:"ss-chart-container",children:[r&&s.jsx("h3",{className:"ss-chart-title",children:r}),s.jsxs("svg",{viewBox:`0 0 ${i} ${n}`,width:"100%",style:{maxWidth:i},children:[e==="bar"&&s.jsx(Ms,{labels:t.labels,values:t.values,w:i,h:n,colors:l}),e==="line"&&s.jsx(Ds,{labels:t.labels,values:t.values,w:i,h:n,colors:l}),e==="pie"&&s.jsx(As,{labels:t.labels,values:t.values,w:i,h:n,colors:l})]})]})})}function Us({dashboardId:e,embedToken:t,baseUrl:r,refreshInterval:i,appearance:n}){const c=C(),d=n??(c==null?void 0:c.appearance),u=a.useMemo(()=>{if(t){const y=r??"https://api.saas-support.com/v1",m=new M.Transport(y,{type:"embedToken",token:t});return new M.ReportClient(m)}return c.client.report},[t,r,c]),[l,o]=a.useState([]),[x,p]=a.useState({}),[g,h]=a.useState(!0),[f,b]=a.useState(null),v=a.useCallback(async()=>{h(!0),b(null);try{const y=await u.getDashboard(e),m=JSON.parse(y.layoutJson||"[]");o(m);const j={};for(const N of m)try{const w=await u.listQueries({search:N.queryId,perPage:1});if(w.data.length>0&&w.data[0].generatedSql){const P=await u.executeQuery({sql:w.data[0].generatedSql});j[N.queryId]=P}}catch{}p(j)}catch(y){b(y instanceof Error?y.message:"Failed to load dashboard")}finally{h(!1)}},[u,e]);return a.useEffect(()=>{v()},[v]),a.useEffect(()=>{if(!i||i<=0)return;const y=setInterval(v,i*1e3);return()=>clearInterval(y)},[i,v]),s.jsx(z,{appearance:d,children:s.jsxs("div",{className:"ss-dashboard-grid",children:[g&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading dashboard..."]}),f&&s.jsx("div",{className:"ss-global-error",children:f}),!g&&l.map((y,m)=>{const j=x[y.queryId];if(!j)return null;const N=j.columns.length>=2?{labels:j.rows.map(w=>String(w[j.columns[0]]??"")),values:j.rows.map(w=>Number(w[j.columns[1]]??0))}:{labels:[],values:[]};return s.jsxs("div",{className:"ss-widget",children:[y.title&&s.jsx("h4",{className:"ss-widget-header",children:y.title}),y.chartType==="table"?s.jsx(ns,{columns:j.columns,rows:j.rows,maxRows:50}):s.jsx(os,{type:y.chartType||"bar",data:N,width:y.w,height:y.h})]},m)})]})})}function qs(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Fs({onSelectQuery:e,onRunQuery:t,appearance:r}){const{appearance:i}=C(),{queries:n,isLoading:c,error:d}=ts(),{execute:u,isLoading:l}=V(),o=r??i,x=a.useCallback(async p=>{if(!p.generatedSql)return;const g=await u({sql:p.generatedSql});g&&(t==null||t(g))},[u,t]);return s.jsx(z,{appearance:o,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Saved Queries"}),c&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),!c&&n.length===0&&s.jsx("p",{className:"ss-empty",children:"No saved queries."}),!c&&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:qs(p.createdAt)}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:l||!p.generatedSql,onClick:g=>{g.stopPropagation(),x(p)},children:l?s.jsx("span",{className:"ss-spinner"}):"Run"})]})]},p.id))]})})}function Rs({embedToken:e,dashboardId:t,baseUrl:r="https://api.saas-support.com/v1",refreshInterval:i,appearance:n}){const c=a.useMemo(()=>{const b=new M.Transport(r,{type:"embedToken",token:e});return new M.ReportClient(b)},[e,r]),[d,u]=a.useState([]),[l,o]=a.useState(!0),[x,p]=a.useState(null),g=a.useMemo(()=>F(n),[n]),h=a.useMemo(()=>R(g),[g]),f=a.useCallback(async()=>{o(!0),p(null);try{const b=await c.getDashboard(t),v=JSON.parse(b.layoutJson||"[]"),y=await Promise.all(v.map(async m=>{try{const j=await c.listQueries({search:m.queryId,perPage:1});if(j.data.length>0&&j.data[0].generatedSql){const N=await c.executeQuery({sql:j.data[0].generatedSql});return{...m,result:N}}}catch{}return m}));u(y)}catch(b){p(b instanceof Error?b.message:"Failed to load dashboard")}finally{o(!1)}},[c,t]);return a.useEffect(()=>{f()},[f]),a.useEffect(()=>{if(!i||i<=0)return;const b=setInterval(f,i*1e3);return()=>clearInterval(b)},[i,f]),s.jsx("div",{ref:b=>{if(!b||b.shadowRoot)return;const v=b.attachShadow({mode:"open"}),y=document.createElement("style");y.textContent=h,v.appendChild(y);const m=document.createElement("div");v.appendChild(m)},style:{display:"contents"},children:s.jsxs("div",{className:"ss-dashboard-grid",children:[l&&s.jsx("div",{className:"ss-loading",children:"Loading dashboard..."}),x&&s.jsx("div",{className:"ss-global-error",children:x}),!l&&d.map((b,v)=>{if(!b.result)return null;const{columns:y,rows:m}=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:y.map(j=>s.jsx("th",{className:"ss-th",children:j},j))})}),s.jsx("tbody",{children:m.slice(0,50).map((j,N)=>s.jsx("tr",{className:"ss-tr",children:y.map(w=>s.jsx("td",{className:"ss-td",children:String(j[w]??"")},w))},N))})]})]},v)})]})})}exports.SaaSError=M.SaaSError;exports.SaaSSupport=M.SaaSSupport;exports.isMfaRequired=M.isMfaRequired;exports.Chart=os;exports.CouponInput=Es;exports.DashboardView=Us;exports.DataTable=ns;exports.InvoiceHistory=as;exports.OrgSwitcher=vs;exports.PaymentPortal=Ps;exports.PricingTable=ws;exports.QueryInput=Ls;exports.ReportEmbed=Rs;exports.SaaSContext=O;exports.SaaSProvider=is;exports.SavedQueryList=Fs;exports.SignIn=ms;exports.SignUp=gs;exports.SubscriptionStatus=es;exports.UsageDisplay=rs;exports.UserButton=bs;exports.UserProfile=ys;exports.useAuth=W;exports.useBilling=Ns;exports.useDashboard=Ts;exports.useEmbedDashboard=zs;exports.useInvoices=K;exports.useOrg=G;exports.useProfile=_;exports.useQuery=V;exports.useReport=Is;exports.useSaaSContext=C;exports.useSavedQueries=ts;exports.useSignIn=H;exports.useSignUp=Q;exports.useSubscription=X;exports.useUsage=ss;exports.useUser=xs;
|
|
853
|
+
`}function B({children:e,appearance:t}){const r=a.useRef(null),[l,n]=a.useState(null);a.useEffect(()=>{var m;if(!r.current||r.current.shadowRoot){n(((m=r.current)==null?void 0:m.shadowRoot)??null);return}const i=r.current.attachShadow({mode:"open"}),d=V(t),c=document.createElement("style");c.textContent=Q(d),i.appendChild(c);const o=document.createElement("div");i.appendChild(o),n(i)},[]),a.useEffect(()=>{if(!l)return;const i=l.querySelector("style");if(i){const d=V(t);i.textContent=Q(d)}},[t,l]);const u=(l==null?void 0:l.querySelector("div"))??null;return s.jsx("div",{ref:r,style:{display:"contents"},children:u&&fs.createPortal(e,u)})}function W(){const{client:e,user:t,isLoaded:r}=I();return{isLoaded:r,isSignedIn:!!t,user:t,signOut:a.useCallback(()=>e.auth.signOut(),[e]),getToken:a.useCallback(()=>e.auth.getToken(),[e])}}function Ns(){const{user:e,isLoaded:t}=I();return{user:e,isLoaded:t}}function J(){const{client:e}=I(),[t,r]=a.useState(!1),[l,n]=a.useState(null),u=a.useCallback(async(c,o)=>{r(!0),n(null);try{return await e.auth.signIn(c,o)}catch(m){return n(m instanceof Error?m.message:"Sign in failed"),null}finally{r(!1)}},[e]),i=a.useCallback(async c=>{r(!0),n(null);try{return await e.auth.signInWithOAuth(c)}catch(o){return n(o instanceof Error?o.message:"OAuth sign in failed"),null}finally{r(!1)}},[e]),d=a.useCallback(async(c,o)=>{r(!0),n(null);try{return await e.auth.submitMfaCode(c,o)}catch(m){return n(m instanceof Error?m.message:"MFA verification failed"),null}finally{r(!1)}},[e]);return{signIn:u,signInWithOAuth:i,submitMfaCode:d,isLoading:t,error:l,setError:n}}function K(){const{client:e}=I(),[t,r]=a.useState(!1),[l,n]=a.useState(null);return{signUp:a.useCallback(async(i,d)=>{r(!0),n(null);try{return await e.auth.signUp(i,d)}catch(c){return n(c instanceof Error?c.message:"Sign up failed"),null}finally{r(!1)}},[e]),isLoading:t,error:l,setError:n}}function Y(){const{client:e}=I(),[t,r]=a.useState([]),[l,n]=a.useState(null),[u,i]=a.useState([]),[d,c]=a.useState([]),[o,m]=a.useState(!1),[p,g]=a.useState(null),h=a.useCallback(async()=>{m(!0),g(null);try{const v=await e.auth.listOrgs();r(v);const S=typeof window<"u"?localStorage.getItem("ss_selected_org"):null;if(S&&v.some(b=>b.id===S)&&!l){const b=v.find(C=>C.id===S);n(b);try{const C=await e.auth.listMembers(b.id);i(C)}catch{}}}catch(v){g(v instanceof Error?v.message:"Failed to load organizations")}finally{m(!1)}},[e,l]);a.useEffect(()=>{h()},[h]);const w=a.useCallback(async v=>{try{const S=await e.auth.getOrg(v);n(S),typeof window<"u"&&localStorage.setItem("ss_selected_org",v);const b=await e.auth.listMembers(v);i(b)}catch(S){g(S instanceof Error?S.message:"Failed to load organization")}},[e]),f=a.useCallback(async(v,S)=>{try{const b=await e.auth.createOrg(v,S);return r(C=>[...C,b]),b}catch(b){return g(b instanceof Error?b.message:"Failed to create organization"),null}},[e]),j=a.useCallback(async(v,S)=>{try{const b=await e.auth.updateOrg(v,S);return r(C=>C.map(M=>M.id===v?b:M)),(l==null?void 0:l.id)===v&&n(b),b}catch(b){return g(b instanceof Error?b.message:"Failed to update organization"),null}},[e,l]),y=a.useCallback(async v=>{try{return await e.auth.deleteOrg(v),r(S=>S.filter(b=>b.id!==v)),(l==null?void 0:l.id)===v&&(n(null),i([]),c([]),typeof window<"u"&&localStorage.removeItem("ss_selected_org")),!0}catch(S){return g(S instanceof Error?S.message:"Failed to delete organization"),!1}},[e,l]),x=a.useCallback(async(v,S,b)=>{try{return await e.auth.sendInvite(v,S,b)}catch(C){return g(C instanceof Error?C.message:"Failed to send invite"),null}},[e]),N=a.useCallback(async v=>{try{const S=await e.auth.listInvites(v);c(S)}catch(S){g(S instanceof Error?S.message:"Failed to load invites")}},[e]),$=a.useCallback(async(v,S)=>{try{return await e.auth.revokeInvite(v,S),c(b=>b.filter(C=>C.id!==S)),!0}catch(b){return g(b instanceof Error?b.message:"Failed to revoke invite"),!1}},[e]),k=a.useCallback(async(v,S,b)=>{try{return await e.auth.updateMemberRole(v,S,b),i(C=>C.map(M=>M.userId===S?{...M,role:b}:M)),!0}catch(C){return g(C instanceof Error?C.message:"Failed to update member role"),!1}},[e]),E=a.useCallback(async(v,S)=>{try{return await e.auth.removeMember(v,S),i(b=>b.filter(C=>C.userId!==S)),!0}catch(b){return g(b instanceof Error?b.message:"Failed to remove member"),!1}},[e]),P=a.useCallback(async v=>{try{const S=await e.auth.listMembers(v);i(S)}catch(S){g(S instanceof Error?S.message:"Failed to load members")}},[e]);return{orgs:t,selectedOrg:l,members:u,invites:d,isLoading:o,error:p,setError:g,refresh:h,selectOrg:w,createOrg:f,updateOrg:j,deleteOrg:y,sendInvite:x,refreshInvites:N,revokeInvite:$,updateMemberRole:k,removeMember:E,refreshMembers:P}}function ss(){const{client:e}=I(),[t,r]=a.useState(!1),[l,n]=a.useState(null);return{deleteAccount:a.useCallback(async()=>{r(!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{r(!1)}},[e]),isLoading:t,error:l,setError:n}}function Z(){const{client:e,user:t}=I(),[r,l]=a.useState(!1),[n,u]=a.useState(null),[i,d]=a.useState(null),c=a.useCallback(async p=>{l(!0),u(null),d(null);try{const g=await e.auth.updateProfile(p);return d("Profile updated"),g}catch(g){return u(g instanceof Error?g.message:"Failed to update profile"),null}finally{l(!1)}},[e]),o=a.useCallback(async(p,g)=>{l(!0),u(null),d(null);try{return await e.auth.changePassword(p,g),d("Password changed successfully"),!0}catch(h){return u(h instanceof Error?h.message:"Failed to change password"),!1}finally{l(!1)}},[e]),m=a.useCallback(async p=>{l(!0),u(null),d(null);try{const g=await e.auth.uploadAvatar(p);return d("Avatar updated"),g}catch(g){return u(g instanceof Error?g.message:"Failed to upload avatar"),null}finally{l(!1)}},[e]);return{user:t,updateProfile:c,uploadAvatar:m,changePassword:o,isLoading:r,error:n,success:i,setError:u,setSuccess:d}}const es='<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>',as='<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>',Ss='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4-8 5-8-5V6l8 5 8-5v2z" fill="currentColor"/></svg>';function Cs({appearance:e,signUpUrl:t,onSignUp:r}){const{appearance:l,settings:n}=I(),{signIn:u,signInWithOAuth:i,submitMfaCode:d,isLoading:c,error:o,setError:m}=J(),p=e??l,[g,h]=a.useState(""),[w,f]=a.useState(""),[j,y]=a.useState(!1),[x,N]=a.useState(""),[$,k]=a.useState(""),[E,P]=a.useState(!1),v=a.useCallback(async C=>{if(C.preventDefault(),j){await d(x,$);return}const M=await u(g,w);M&&A.isMfaRequired(M)&&(N(M.mfaToken),y(!0),m(null))},[g,w,j,x,$,u,d,m]),S=a.useCallback(async C=>{await i(C)},[i]),b=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled);return s.jsx(B,{appearance:p,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Sign in"}),!j&&s.jsxs(s.Fragment,{children:[(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>S("google"),disabled:c,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:es}}),"Continue with Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>S("github"),disabled:c,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:as}}),"Continue with GitHub"]}),b&&!E&&s.jsx("div",{className:"ss-divider",children:"or"}),b&&!E&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>P(!0),children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:Ss}}),"Login with email"]}),b&&E&&s.jsx("div",{className:"ss-divider",children:"or"})]}),o&&s.jsx("div",{className:"ss-global-error",children:o}),(E||j||!b)&&s.jsxs("form",{onSubmit:v,children:[j?s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-mfa-code",children:"Authentication code"}),s.jsx("input",{id:"ss-mfa-code",className:"ss-input",type:"text",inputMode:"numeric",autoComplete:"one-time-code",placeholder:"Enter 6-digit code",value:$,onChange:C=>k(C.target.value),autoFocus:!0})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-email",children:"Email"}),s.jsx("input",{id:"ss-email",className:"ss-input",type:"email",autoComplete:"email",placeholder:"you@example.com",value:g,onChange:C=>h(C.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-password",children:"Password"}),s.jsx("input",{id:"ss-password",className:"ss-input",type:"password",autoComplete:"current-password",placeholder:"Enter your password",value:w,onChange:C=>f(C.target.value),required:!0})]})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:c,children:[c&&s.jsx("span",{className:"ss-spinner"}),j?"Verify":"Continue"]})]}),j&&s.jsx("div",{className:"ss-footer",children:s.jsx("span",{className:"ss-link",onClick:()=>{y(!1),k(""),m(null)},children:"Back to sign in"})}),!j&&s.jsxs("div",{className:"ss-footer",children:["Don't have an account?"," ",r?s.jsx("span",{className:"ss-link",onClick:r,children:"Sign up"}):t?s.jsx("a",{className:"ss-link",href:t,children:"Sign up"}):s.jsx("span",{className:"ss-link",children:"Sign up"})]})]})})}function ks({appearance:e,signInUrl:t,onSignIn:r}){const{appearance:l,settings:n}=I(),{signUp:u,isLoading:i,error:d,setError:c}=K(),{signInWithOAuth:o}=J(),m=e??l,[p,g]=a.useState(""),[h,w]=a.useState(""),[f,j]=a.useState(""),[y,x]=a.useState(null),N=a.useCallback(async P=>{if(P.preventDefault(),x(null),h!==f){x("Passwords do not match");return}const v=(n==null?void 0:n.passwordMinLength)??8;if(h.length<v){x(`Password must be at least ${v} characters`);return}await u(p,h)},[p,h,f,n,u]),$=a.useCallback(async P=>{await o(P)},[o]),k=(n==null?void 0:n.googleEnabled)||(n==null?void 0:n.githubEnabled),E=y||d;return s.jsx(B,{appearance:m,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Create account"}),(n==null?void 0:n.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>$("google"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:es}}),"Continue with Google"]}),(n==null?void 0:n.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>$("github"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:as}}),"Continue with GitHub"]}),k&&s.jsx("div",{className:"ss-divider",children:"or"}),E&&s.jsx("div",{className:"ss-global-error",children:E}),s.jsxs("form",{onSubmit:N,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-signup-email",children:"Email"}),s.jsx("input",{id:"ss-signup-email",className:"ss-input",type:"email",autoComplete:"email",placeholder:"you@example.com",value:p,onChange:P=>g(P.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-signup-password",children:"Password"}),s.jsx("input",{id:"ss-signup-password",className:"ss-input",type:"password",autoComplete:"new-password",placeholder:"Create a password",value:h,onChange:P=>{w(P.target.value),x(null)},required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-signup-confirm",children:"Confirm password"}),s.jsx("input",{id:"ss-signup-confirm",className:"ss-input",type:"password",autoComplete:"new-password",placeholder:"Confirm your password",value:f,onChange:P=>{j(P.target.value),x(null)},required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:i,children:[i&&s.jsx("span",{className:"ss-spinner"}),"Create account"]})]}),s.jsxs("div",{className:"ss-footer",children:["Already have an account?"," ",r?s.jsx("span",{className:"ss-link",onClick:r,children:"Sign in"}):t?s.jsx("a",{className:"ss-link",href:t,children:"Sign in"}):s.jsx("span",{className:"ss-link",children:"Sign in"})]})]})})}const z=256,F=112;function $s({file:e,onCrop:t,onCancel:r}){const l=a.useRef(null),n=a.useRef(null),[u,i]=a.useState(1),[d,c]=a.useState({x:0,y:0}),[o,m]=a.useState(!1),p=a.useRef({x:0,y:0,ox:0,oy:0}),[g,h]=a.useState(!1);a.useEffect(()=>{const x=new Image,N=URL.createObjectURL(e);return x.onload=()=>{n.current=x,h(!0),c({x:0,y:0}),i(1)},x.src=N,()=>URL.revokeObjectURL(N)},[e]),a.useEffect(()=>{if(!g||!n.current||!l.current)return;const x=l.current.getContext("2d");if(!x)return;const N=n.current;x.clearRect(0,0,z,z),x.fillStyle="#111",x.fillRect(0,0,z,z);const $=Math.max(z/N.width,z/N.height)*u,k=N.width*$,E=N.height*$,P=(z-k)/2+d.x,v=(z-E)/2+d.y;x.save(),x.beginPath(),x.arc(z/2,z/2,F,0,Math.PI*2),x.clip(),x.drawImage(N,P,v,k,E),x.restore(),x.save(),x.fillStyle="rgba(0, 0, 0, 0.6)",x.fillRect(0,0,z,z),x.globalCompositeOperation="destination-out",x.beginPath(),x.arc(z/2,z/2,F,0,Math.PI*2),x.fill(),x.restore(),x.save(),x.beginPath(),x.arc(z/2,z/2,F,0,Math.PI*2),x.clip(),x.drawImage(N,P,v,k,E),x.restore(),x.strokeStyle="rgba(255, 255, 255, 0.6)",x.lineWidth=2,x.beginPath(),x.arc(z/2,z/2,F,0,Math.PI*2),x.stroke()},[u,d,g]);const w=a.useCallback(x=>{m(!0),p.current={x:x.clientX,y:x.clientY,ox:d.x,oy:d.y},x.target.setPointerCapture(x.pointerId)},[d]),f=a.useCallback(x=>{o&&c({x:p.current.ox+(x.clientX-p.current.x),y:p.current.oy+(x.clientY-p.current.y)})},[o]),j=a.useCallback(()=>m(!1),[]),y=a.useCallback(()=>{if(!n.current)return;const x=document.createElement("canvas"),N=F*2;x.width=N,x.height=N;const $=x.getContext("2d");if(!$)return;const k=n.current,E=Math.max(z/k.width,z/k.height)*u,P=k.width*E,v=k.height*E,S=(z-P)/2+d.x-(z/2-F),b=(z-v)/2+d.y-(z/2-F);$.beginPath(),$.arc(F,F,F,0,Math.PI*2),$.clip(),$.drawImage(k,S,b,P,v),x.toBlob(C=>{C&&t(C)},"image/png")},[u,d,t]);return s.jsxs("div",{className:"ss-avatar-cropper",children:[s.jsx("canvas",{ref:l,width:z,height:z,className:"ss-avatar-canvas",onPointerDown:w,onPointerMove:f,onPointerUp:j,style:{cursor:o?"grabbing":"grab"}}),s.jsxs("div",{className:"ss-avatar-zoom",children:[s.jsx("span",{className:"ss-avatar-zoom-label",children:"Zoom"}),s.jsx("input",{type:"range",min:"1",max:"3",step:"0.01",value:u,onChange:x=>i(parseFloat(x.target.value)),className:"ss-avatar-zoom-slider"})]}),s.jsxs("div",{className:"ss-btn-group",children:[s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger ss-btn-sm",onClick:r,children:"Cancel"}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-primary ss-btn-sm",onClick:y,children:"Save"})]})]})}function rs({onUpload:e,onClose:t,isLoading:r}){const[l,n]=a.useState(null),[u,i]=a.useState(!1),[d,c]=a.useState(null),o=a.useRef(null),m=a.useCallback(h=>{if(!h.type.startsWith("image/")){c("Please select an image file");return}if(h.size>5*1024*1024){c("Image must be smaller than 5 MB");return}c(null),n(h)},[]),p=a.useCallback(h=>{h.preventDefault(),i(!1);const w=h.dataTransfer.files[0];w&&m(w)},[m]),g=a.useCallback(async h=>{await e(h)},[e]);return s.jsx("div",{className:"ss-modal-overlay",onClick:h=>{h.target===h.currentTarget&&t()},children:s.jsxs("div",{className:"ss-modal",children:[s.jsxs("div",{className:"ss-modal-header",children:[s.jsx("span",{className:"ss-modal-title",children:"Upload Avatar"}),s.jsx("button",{type:"button",className:"ss-modal-close",onClick:t,children:"✕"})]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),l?s.jsx($s,{file:l,onCrop:g,onCancel:()=>n(null)}):s.jsxs("div",{className:`ss-avatar-dropzone${u?" ss-avatar-dropzone-active":""}`,onDragOver:h=>{h.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:p,onClick:()=>{var h;return(h=o.current)==null?void 0:h.click()},children:[s.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[s.jsx("path",{d:"M12 16a4 4 0 100-8 4 4 0 000 8z"}),s.jsx("path",{d:"M3 16.8V9.2c0-1.12 0-1.68.218-2.108a2 2 0 01.874-.874C4.52 6 5.08 6 6.2 6h.382c.246 0 .37 0 .482-.022a1 1 0 00.513-.29c.08-.082.148-.186.284-.392l.079-.118C8.08 4.968 8.15 4.863 8.234 4.77a2 2 0 01.965-.61C9.346 4.1 9.508 4.1 9.834 4.1h4.332c.326 0 .488 0 .636.06a2 2 0 01.965.61c.083.094.153.198.293.408l.079.118c.136.206.204.31.284.392a1 1 0 00.513.29c.112.022.236.022.482.022h.382c1.12 0 1.68 0 2.108.218a2 2 0 01.874.874C21 7.52 21 8.08 21 9.2v7.6c0 1.12 0 1.68-.218 2.108a2 2 0 01-.874.874C19.48 20 18.92 20 17.8 20H6.2c-1.12 0-1.68 0-2.108-.218a2 2 0 01-.874-.874C3 18.48 3 17.92 3 16.8z"})]}),s.jsx("span",{children:"Drop image here or click to browse"}),s.jsx("input",{ref:o,type:"file",accept:"image/*",style:{display:"none"},onChange:h=>{var w;(w=h.target.files)!=null&&w[0]&&m(h.target.files[0])}})]}),r&&s.jsx("div",{className:"ss-loading",children:"Uploading..."})]})})}function Es({appearance:e,afterSignOutUrl:t,afterDeleteAccountUrl:r,showOrgSwitcher:l=!0,onOrgChange:n,onOrgSettingsClick:u}){const{appearance:i}=I(),{user:d,signOut:c}=W(),o=e??i,[m,p]=a.useState(!1),[g,h]=a.useState(!1),[w,f]=a.useState(!1),[j,y]=a.useState(""),[x,N]=a.useState(""),[$,k]=a.useState(null),[E,P]=a.useState(!1),v=a.useRef(null),{orgs:S,selectedOrg:b,selectOrg:C,createOrg:M}=Y(),U=a.useCallback(T=>{v.current&&!T.composedPath().includes(v.current)&&(p(!1),f(!1))},[]);a.useEffect(()=>{if(m){const T=setTimeout(()=>{document.addEventListener("click",U)},0);return()=>{clearTimeout(T),document.removeEventListener("click",U)}}},[m,U]);const O=a.useCallback(T=>{y(T),N(T.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},[]),D=a.useCallback(async T=>{T.preventDefault(),k(null),P(!0);try{const R=await M(j,x);R&&(await C(R.id),n==null||n(R),f(!1),y(""),N(""),p(!1))}catch(R){k(R instanceof Error?R.message:"Failed to create organization")}finally{P(!1)}},[j,x,M,C,n]);if(!d)return null;const q=(d.name||d.email).charAt(0).toUpperCase();return s.jsx(B,{appearance:o,children:s.jsxs("div",{className:"ss-user-btn",ref:v,children:[s.jsx("button",{type:"button",className:"ss-avatar",onClick:()=>p(!m),"aria-label":"User menu",children:d.avatarUrl?s.jsx("img",{src:d.avatarUrl,alt:"",style:{width:"100%",height:"100%",borderRadius:"50%",objectFit:"cover"}}):q}),m&&s.jsxs("div",{className:"ss-dropdown",children:[s.jsxs("div",{className:"ss-dropdown-header",children:[d.name&&s.jsx("div",{style:{fontWeight:600,fontSize:"14px",color:"inherit"},children:d.name}),s.jsx("div",{className:"ss-dropdown-email",children:d.email})]}),s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>{p(!1),h(!0)},children:"Profile"}),l&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ss-dropdown-divider"}),s.jsx("div",{className:"ss-dropdown-section-title",children:"Organizations"}),S.map(T=>s.jsxs("button",{type:"button",className:`ss-dropdown-item${(b==null?void 0:b.id)===T.id?" ss-dropdown-item-active":""}`,onClick:async()=>{p(!1),f(!1),await C(T.id),n==null||n(T)},children:[(b==null?void 0:b.id)===T.id&&s.jsx("span",{className:"ss-org-check",children:"✓"}),T.name]},T.id)),w?s.jsxs("div",{className:"ss-inline-form",children:[$&&s.jsx("div",{className:"ss-global-error",style:{marginBottom:"8px",fontSize:"12px"},children:$}),s.jsxs("form",{onSubmit:D,children:[s.jsx("div",{className:"ss-field",children:s.jsx("input",{className:"ss-input",type:"text",placeholder:"Organization name",value:j,onChange:T=>O(T.target.value),required:!0,autoFocus:!0})}),s.jsx("div",{className:"ss-field",children:s.jsx("input",{className:"ss-input",type:"text",placeholder:"org-slug",value:x,onChange:T=>N(T.target.value),required:!0})}),s.jsxs("div",{className:"ss-btn-group",style:{marginTop:"8px"},children:[s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-current",onClick:()=>{f(!1),k(null)},children:"Cancel"}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:E,children:[E&&s.jsx("span",{className:"ss-spinner"}),"Create"]})]})]})]}):s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>f(!0),style:{fontWeight:500},children:"+ Create organization"}),b&&u&&s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>{p(!1),u(b)},children:"Org settings"})]}),s.jsx("div",{className:"ss-dropdown-divider"}),s.jsx("button",{type:"button",className:"ss-dropdown-item ss-dropdown-item-danger",onClick:async()=>{p(!1),await c(),t&&(window.location.href=t)},children:"Sign out"})]}),g&&s.jsx(Ps,{onClose:()=>h(!1),afterDeleteAccountUrl:r})]})})}function Ps({onClose:e,afterDeleteAccountUrl:t}){const{user:r,updateProfile:l,uploadAvatar:n,changePassword:u,isLoading:i,error:d,success:c,setError:o,setSuccess:m}=Z(),{signOut:p}=W(),{deleteAccount:g,isLoading:h,error:w,setError:f}=ss(),[j,y]=a.useState((r==null?void 0:r.name)??""),[x,N]=a.useState((r==null?void 0:r.avatarUrl)??""),[$,k]=a.useState(!1),[E,P]=a.useState(""),[v,S]=a.useState(""),[b,C]=a.useState(""),[M,U]=a.useState(null),[O,D]=a.useState(!1),[q,T]=a.useState(""),R=a.useCallback(async L=>{L.preventDefault(),o(null),m(null),await l({name:j,avatarUrl:x||void 0})},[j,x,l,o,m]),ms=a.useCallback(async L=>{const _=await n(L);_&&(N(_.avatarUrl),k(!1))},[n]),xs=a.useCallback(async L=>{if(L.preventDefault(),U(null),o(null),m(null),v!==b){U("Passwords do not match");return}if(v.length<8){U("Password must be at least 8 characters");return}await u(E,v)&&(P(""),S(""),C(""))},[E,v,b,u,o,m]),gs=a.useCallback(async()=>{await g()&&(await p(),t&&(window.location.href=t))},[g,p,t]),hs=(r==null?void 0:r.provider)==="email",bs=q===(r==null?void 0:r.email);return s.jsx("div",{className:"ss-modal-overlay",onClick:L=>{L.target===L.currentTarget&&e()},children:s.jsxs("div",{className:"ss-modal",children:[s.jsxs("div",{className:"ss-modal-header",children:[s.jsx("span",{className:"ss-modal-title",children:"Profile"}),s.jsx("button",{type:"button",className:"ss-modal-close",onClick:e,children:"✕"})]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),c&&s.jsx("div",{className:"ss-success-msg",children:c}),s.jsxs("div",{className:"ss-avatar-preview ss-avatar-hoverable",onClick:()=>k(!0),title:"Click to change avatar",children:[x?s.jsx("img",{src:x,alt:""}):(j||(r==null?void 0:r.email)||"?").charAt(0).toUpperCase(),s.jsx("div",{className:"ss-avatar-overlay",children:s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("path",{d:"M12 16a4 4 0 100-8 4 4 0 000 8z"}),s.jsx("path",{d:"M3 16.8V9.2c0-1.12 0-1.68.218-2.108a2 2 0 01.874-.874C4.52 6 5.08 6 6.2 6h.382c.246 0 .37 0 .482-.022a1 1 0 00.513-.29c.08-.082.148-.186.284-.392l.079-.118C8.08 4.968 8.15 4.863 8.234 4.77a2 2 0 01.965-.61C9.346 4.1 9.508 4.1 9.834 4.1h4.332c.326 0 .488 0 .636.06a2 2 0 01.965.61c.083.094.153.198.293.408l.079.118c.136.206.204.31.284.392a1 1 0 00.513.29c.112.022.236.022.482.022h.382c1.12 0 1.68 0 2.108.218a2 2 0 01.874.874C21 7.52 21 8.08 21 9.2v7.6c0 1.12 0 1.68-.218 2.108a2 2 0 01-.874.874C19.48 20 18.92 20 17.8 20H6.2c-1.12 0-1.68 0-2.108-.218a2 2 0 01-.874-.874C3 18.48 3 17.92 3 16.8z"})]})})]}),s.jsxs("form",{onSubmit:R,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Name"}),s.jsx("input",{className:"ss-input",type:"text",placeholder:"Your name",value:j,onChange:L=>y(L.target.value)})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Email"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"email",value:(r==null?void 0:r.email)??"",disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Provider"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"text",value:(r==null?void 0:r.provider)??"",disabled:!0,readOnly:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:i,children:[i&&s.jsx("span",{className:"ss-spinner"}),"Save changes"]})]}),hs&&s.jsxs("div",{className:"ss-modal-section",children:[s.jsx("div",{className:"ss-modal-section-title",children:"Change password"}),M&&s.jsx("div",{className:"ss-global-error",children:M}),s.jsxs("form",{onSubmit:xs,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Current password"}),s.jsx("input",{className:"ss-input",type:"password",value:E,onChange:L=>P(L.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"New password"}),s.jsx("input",{className:"ss-input",type:"password",value:v,onChange:L=>S(L.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Confirm new password"}),s.jsx("input",{className:"ss-input",type:"password",value:b,onChange:L=>C(L.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:i,children:[i&&s.jsx("span",{className:"ss-spinner"}),"Update password"]})]})]}),s.jsxs("div",{className:"ss-danger-zone",children:[s.jsx("div",{className:"ss-modal-section-title",children:"Danger zone"}),s.jsx("p",{style:{fontSize:"13px",margin:"0 0 12px 0",opacity:.8},children:"Deleting your account is permanent. All organizations you own will also be deleted."}),w&&s.jsx("div",{className:"ss-global-error",children:w}),O?s.jsxs("div",{children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Type your email to confirm"}),s.jsx("input",{className:"ss-input",type:"email",placeholder:r==null?void 0:r.email,value:q,onChange:L=>T(L.target.value),autoFocus:!0})]}),s.jsxs("div",{className:"ss-btn-group",style:{marginTop:"8px"},children:[s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-current",onClick:()=>{D(!1),T(""),f(null)},children:"Cancel"}),s.jsxs("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-danger",disabled:!bs||h,onClick:gs,children:[h&&s.jsx("span",{className:"ss-spinner"}),"Delete account"]})]})]}):s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:()=>D(!0),children:"Delete my account"})]}),$&&s.jsx(rs,{onUpload:ms,onClose:()=>k(!1),isLoading:i})]})})}function Is({appearance:e}){const{appearance:t}=I(),{user:r,signOut:l}=W(),{updateProfile:n,uploadAvatar:u,changePassword:i,isLoading:d,error:c,success:o,setError:m,setSuccess:p}=Z(),g=e??t,[h,w]=a.useState((r==null?void 0:r.name)??""),[f,j]=a.useState((r==null?void 0:r.avatarUrl)??""),[y,x]=a.useState(!1),[N,$]=a.useState(""),[k,E]=a.useState(""),[P,v]=a.useState(""),[S,b]=a.useState(null),C=a.useCallback(async D=>{D.preventDefault(),m(null),p(null),await n({name:h,avatarUrl:f||void 0})},[h,f,n,m,p]),M=a.useCallback(async D=>{const q=await u(D);q&&(j(q.avatarUrl),x(!1))},[u]),U=a.useCallback(async D=>{if(D.preventDefault(),b(null),m(null),p(null),k!==P){b("Passwords do not match");return}if(k.length<8){b("Password must be at least 8 characters");return}await i(N,k)&&($(""),E(""),v(""))},[N,k,P,i,m,p]);if(!r)return null;const O=r.provider==="email";return s.jsx(B,{appearance:g,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Profile"}),c&&s.jsx("div",{className:"ss-global-error",children:c}),o&&s.jsx("div",{className:"ss-success-msg",children:o}),s.jsxs("div",{className:"ss-avatar-preview ss-avatar-hoverable",style:{margin:"0 auto 16px"},onClick:()=>x(!0),title:"Click to change avatar",children:[f?s.jsx("img",{src:f,alt:""}):(h||r.email).charAt(0).toUpperCase(),s.jsx("div",{className:"ss-avatar-overlay",children:s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("path",{d:"M12 16a4 4 0 100-8 4 4 0 000 8z"}),s.jsx("path",{d:"M3 16.8V9.2c0-1.12 0-1.68.218-2.108a2 2 0 01.874-.874C4.52 6 5.08 6 6.2 6h.382c.246 0 .37 0 .482-.022a1 1 0 00.513-.29c.08-.082.148-.186.284-.392l.079-.118C8.08 4.968 8.15 4.863 8.234 4.77a2 2 0 01.965-.61C9.346 4.1 9.508 4.1 9.834 4.1h4.332c.326 0 .488 0 .636.06a2 2 0 01.965.61c.083.094.153.198.293.408l.079.118c.136.206.204.31.284.392a1 1 0 00.513.29c.112.022.236.022.482.022h.382c1.12 0 1.68 0 2.108.218a2 2 0 01.874.874C21 7.52 21 8.08 21 9.2v7.6c0 1.12 0 1.68-.218 2.108a2 2 0 01-.874.874C19.48 20 18.92 20 17.8 20H6.2c-1.12 0-1.68 0-2.108-.218a2 2 0 01-.874-.874C3 18.48 3 17.92 3 16.8z"})]})})]}),s.jsxs("form",{onSubmit:C,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Name"}),s.jsx("input",{className:"ss-input",type:"text",placeholder:"Your name",value:h,onChange:D=>w(D.target.value)})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Email"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"email",value:r.email,disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Provider"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"text",value:r.provider,disabled:!0,readOnly:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Email verified"}),s.jsx("input",{className:"ss-input ss-input-readonly",type:"text",value:r.emailVerified?"Yes":"No",disabled:!0,readOnly:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:d,children:[d&&s.jsx("span",{className:"ss-spinner"}),"Save changes"]})]}),O&&s.jsxs("div",{className:"ss-modal-section",children:[s.jsx("div",{className:"ss-modal-section-title",children:"Change password"}),S&&s.jsx("div",{className:"ss-global-error",children:S}),s.jsxs("form",{onSubmit:U,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Current password"}),s.jsx("input",{className:"ss-input",type:"password",value:N,onChange:D=>$(D.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"New password"}),s.jsx("input",{className:"ss-input",type:"password",value:k,onChange:D=>E(D.target.value),required:!0})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Confirm new password"}),s.jsx("input",{className:"ss-input",type:"password",value:P,onChange:D=>v(D.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:d,children:[d&&s.jsx("span",{className:"ss-spinner"}),"Update password"]})]})]}),s.jsx("div",{style:{marginTop:"24px"},children:s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:()=>l(),children:"Sign out"})}),y&&s.jsx(rs,{onUpload:M,onClose:()=>x(!1),isLoading:d})]})})}function zs({appearance:e,onOrgChange:t}){const{appearance:r}=I(),{orgs:l,selectedOrg:n,selectOrg:u,createOrg:i,isLoading:d}=Y(),c=e??r,[o,m]=a.useState(!1),[p,g]=a.useState(!1),[h,w]=a.useState(""),[f,j]=a.useState(""),[y,x]=a.useState(null),[N,$]=a.useState(!1),k=a.useRef(null),E=a.useCallback(b=>{k.current&&!b.composedPath().includes(k.current)&&(m(!1),g(!1))},[]);a.useEffect(()=>{if(o){const b=setTimeout(()=>{document.addEventListener("click",E)},0);return()=>{clearTimeout(b),document.removeEventListener("click",E)}}},[o,E]);const P=a.useCallback(b=>{w(b),j(b.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},[]),v=a.useCallback(async b=>{b.preventDefault(),x(null),$(!0);try{const C=await i(h,f);C&&(await u(C.id),t==null||t(C),g(!1),w(""),j(""),m(!1))}catch(C){x(C instanceof Error?C.message:"Failed to create organization")}finally{$(!1)}},[h,f,i,u,t]);if(d)return null;const S=(n==null?void 0:n.name)??(l.length===0?"No organization":"Select organization");return s.jsx(B,{appearance:c,children:s.jsxs("div",{className:"ss-user-btn",ref:k,children:[s.jsxs("button",{type:"button",className:"ss-btn ss-btn-org-switcher",onClick:()=>m(!o),children:[S,s.jsx("span",{className:"ss-chevron",children:o?"▲":"▼"})]}),o&&s.jsxs("div",{className:"ss-dropdown ss-dropdown-org",children:[l.map(b=>s.jsx("button",{type:"button",className:`ss-dropdown-item ${(n==null?void 0:n.id)===b.id?"ss-dropdown-item-active":""}`,onClick:async()=>{m(!1),g(!1),await u(b.id),t==null||t(b)},children:b.name},b.id)),s.jsx("div",{className:"ss-dropdown-divider"}),p?s.jsxs("div",{className:"ss-inline-form",children:[y&&s.jsx("div",{className:"ss-global-error",style:{marginBottom:"8px",fontSize:"12px"},children:y}),s.jsxs("form",{onSubmit:v,children:[s.jsx("div",{className:"ss-field",children:s.jsx("input",{className:"ss-input",type:"text",placeholder:"Organization name",value:h,onChange:b=>P(b.target.value),required:!0,autoFocus:!0})}),s.jsx("div",{className:"ss-field",children:s.jsx("input",{className:"ss-input",type:"text",placeholder:"org-slug",value:f,onChange:b=>j(b.target.value),required:!0})}),s.jsxs("div",{className:"ss-btn-group",style:{marginTop:"8px"},children:[s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-current",onClick:()=>{g(!1),x(null)},children:"Cancel"}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:N,children:[N&&s.jsx("span",{className:"ss-spinner"}),"Create"]})]})]})]}):s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>g(!0),style:{fontWeight:500},children:"+ Create organization"})]})]})})}function Ts(e,t="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:e%100===0?0:2}).format(e/100)}function Ls({plans:e,currentPlanId:t,onSelectPlan:r,interval:l,appearance:n}){const{appearance:u}=I(),i=n??u,d=l?e.filter(c=>c.interval===l||c.isFree):e;return s.jsx(B,{appearance:i,children:s.jsx("div",{className:"ss-pricing-grid",children:d.map(c=>{const o=c.id===t;return s.jsxs("div",{className:`ss-pricing-card ${o?"ss-pricing-card-current":""}`,children:[s.jsxs("div",{className:"ss-pricing-header",children:[s.jsx("h3",{className:"ss-pricing-name",children:c.name}),c.trialDays>0&&s.jsxs("span",{className:"ss-badge ss-badge-trialing",children:[c.trialDays,"-day trial"]}),c.isFree&&s.jsx("span",{className:"ss-badge ss-badge-active",children:"Free"})]}),s.jsx("div",{className:"ss-pricing-price",children:c.isFree?s.jsx("span",{className:"ss-pricing-amount",children:"Free"}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"ss-pricing-amount",children:Ts(c.amountCents,c.currency)}),s.jsxs("span",{className:"ss-pricing-interval",children:["/",c.interval]})]})}),c.description&&s.jsx("p",{className:"ss-pricing-desc",children:c.description}),c.features.length>0&&s.jsx("ul",{className:"ss-pricing-features",children:c.features.map((m,p)=>s.jsxs("li",{className:"ss-pricing-feature",children:[s.jsx("span",{className:"ss-check",children:"✓"})," ",m]},p))}),s.jsx("button",{type:"button",className:`ss-btn ${o?"ss-btn-current":"ss-btn-primary"}`,disabled:o,onClick:()=>r(c.id),children:o?"Current plan":"Select plan"})]},c.id)})})})}function Ms(){const{client:e}=I();return{billing:e.billing}}function H(e){const{client:t}=I();return a.useMemo(()=>{if(e){const r=new A.Transport("https://api.saas-support.com/v1",{type:"portalToken",token:e});return new A.BillingClient(r)}return t.billing},[t,e])}function ts(e,t){const r=H(t),[l,n]=a.useState(null),[u,i]=a.useState(!0),[d,c]=a.useState(null),o=a.useCallback(async()=>{i(!0),c(null);try{const m=await r.getCustomer(e);n(m)}catch(m){c(m instanceof Error?m.message:"Failed to load subscription")}finally{i(!1)}},[r,e]);return a.useEffect(()=>{o()},[o]),{customer:l,isLoading:u,error:d,refresh:o}}function ns(e,t){const r=H(t),[l,n]=a.useState([]),[u,i]=a.useState(!0),[d,c]=a.useState(null),o=a.useCallback(async()=>{i(!0),c(null);try{const m=await r.getInvoices(e);n(m)}catch(m){c(m instanceof Error?m.message:"Failed to load invoices")}finally{i(!1)}},[r,e]);return a.useEffect(()=>{o()},[o]),{invoices:l,isLoading:u,error:d,refresh:o}}function os(e,t){const r=H(t),[l,n]=a.useState([]),[u,i]=a.useState(!0),[d,c]=a.useState(null),o=a.useCallback(async()=>{i(!0),c(null);try{const m=await r.getCurrentUsage(e);n(m)}catch(m){c(m instanceof Error?m.message:"Failed to load usage")}finally{i(!1)}},[r,e]);return a.useEffect(()=>{o()},[o]),{usage:l,isLoading:u,error:d,refresh:o}}const Ds={active:"ss-badge-active"};function ls({customerId:e,portalToken:t,onChangePlan:r,onCancel:l,appearance:n}){const{appearance:u}=I(),{customer:i,isLoading:d,error:c}=ts(e,t),o=n??u;return s.jsx(B,{appearance:o,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Subscription"}),d&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),c&&s.jsx("div",{className:"ss-global-error",children:c}),i&&!d&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Customer"}),s.jsx("input",{className:"ss-input",value: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 ${Ds.active}`,children:"Active"})})]}),s.jsxs("div",{className:"ss-btn-group",children:[r&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-primary",onClick:r,children:"Change plan"}),l&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:l,children:"Cancel subscription"})]})]})]})})}const Bs={paid:"ss-badge-active",open:"ss-badge-trialing",draft:"ss-badge-paused",void:"ss-badge-canceled",uncollectible:"ss-badge-past-due"};function As(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Fs(e){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(e/100)}function is({customerId:e,portalToken:t,appearance:r}){const{appearance:l}=I(),{invoices:n,isLoading:u,error:i}=ns(e,t),d=r??l,c=[...n].sort((o,m)=>new Date(m.createdAt).getTime()-new Date(o.createdAt).getTime());return s.jsx(B,{appearance:d,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Invoices"}),u&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),i&&s.jsx("div",{className:"ss-global-error",children:i}),!u&&c.length===0&&s.jsx("p",{className:"ss-empty",children:"No invoices yet."}),!u&&c.length>0&&s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{className:"ss-th",children:"Date"}),s.jsx("th",{className:"ss-th",children:"Amount"}),s.jsx("th",{className:"ss-th",children:"Status"}),s.jsx("th",{className:"ss-th",children:"PDF"})]})}),s.jsx("tbody",{children:c.map(o=>s.jsxs("tr",{className:"ss-tr",children:[s.jsx("td",{className:"ss-td",children:As(o.createdAt)}),s.jsx("td",{className:"ss-td",children:Fs(o.amountCents)}),s.jsx("td",{className:"ss-td",children:s.jsx("span",{className:`ss-badge ${Bs[o.status]||""}`,children:o.status})}),s.jsx("td",{className:"ss-td",children:o.pdfUrl?s.jsx("a",{className:"ss-link",href:o.pdfUrl,target:"_blank",rel:"noopener noreferrer",children:"Download"}):"—"})]},o.id))})]})]})})}function cs({customerId:e,limits:t,portalToken:r,appearance:l}){const{appearance:n}=I(),{usage:u,isLoading:i,error:d}=os(e,r),c=l??n;return s.jsx(B,{appearance:c,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..."]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),!i&&u.length===0&&s.jsx("p",{className:"ss-empty",children:"No usage data."}),!i&&u.map(o=>{const m=t==null?void 0:t[o.metric],p=m?Math.min(100,o.total/m*100):null;return s.jsxs("div",{className:"ss-usage-item",children:[s.jsxs("div",{className:"ss-usage-header",children:[s.jsx("span",{className:"ss-usage-metric",children:o.metric}),s.jsxs("span",{className:"ss-usage-value",children:[o.total.toLocaleString(),m?` / ${m.toLocaleString()}`:""]})]}),p!==null&&s.jsx("div",{className:"ss-progress-bar",children:s.jsx("div",{className:`ss-progress-fill ${p>90?"ss-progress-danger":""}`,style:{width:`${p}%`}})})]},o.metric)})]})})}function Us({customerId:e,portalToken:t,limits:r,onChangePlan:l,onCancel:n,appearance:u}){const{appearance:i}=I(),d=u??i,[c,o]=a.useState("subscription"),m=[{id:"subscription",label:"Subscription"},{id:"invoices",label:"Invoices"},{id:"usage",label:"Usage"}];return s.jsx(B,{appearance:d,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Billing"}),s.jsx("div",{className:"ss-tab-group",children:m.map(p=>s.jsx("button",{type:"button",className:`ss-tab ${c===p.id?"ss-tab-active":""}`,onClick:()=>o(p.id),children:p.label},p.id))}),s.jsxs("div",{className:"ss-tab-content",children:[c==="subscription"&&s.jsx(ls,{customerId:e,portalToken:t,onChangePlan:l,onCancel:n}),c==="invoices"&&s.jsx(is,{customerId:e,portalToken:t}),c==="usage"&&s.jsx(cs,{customerId:e,portalToken:t,limits:r})]})]})})}function qs({customerId:e,portalToken:t,onApplied:r,appearance:l}){const{appearance:n}=I(),u=H(t),i=l??n,[d,c]=a.useState(""),[o,m]=a.useState(!1),[p,g]=a.useState(null),[h,w]=a.useState(null),f=a.useCallback(async j=>{if(j.preventDefault(),!!d.trim()){m(!0),g(null),w(null);try{const y=await u.applyCoupon(e,d.trim());w(`Coupon applied! ${y.discountType==="percent"?`${y.amount}% off`:`$${(y.amount/100).toFixed(2)} off`}`),c(""),r==null||r(y)}catch(y){g(y instanceof Error?y.message:"Invalid coupon code")}finally{m(!1)}}},[u,e,d,r]);return s.jsx(B,{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}),h&&s.jsx("div",{className:"ss-success-msg",children:h}),s.jsxs("form",{onSubmit:f,children:[s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",htmlFor:"ss-coupon-code",children:"Coupon code"}),s.jsx("input",{id:"ss-coupon-code",className:"ss-input",type:"text",placeholder:"Enter coupon code",value:d,onChange:j=>c(j.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:o||!d.trim(),children:[o&&s.jsx("span",{className:"ss-spinner"}),"Apply"]})]})]})})}function Rs(){const{client:e}=I();return{report:e.report}}function X(){const{client:e}=I(),[t,r]=a.useState(null),[l,n]=a.useState(!1),[u,i]=a.useState(null),d=a.useCallback(async c=>{n(!0),i(null);try{const o=await e.report.executeQuery(c);return r(o),o}catch(o){return i(o instanceof Error?o.message:"Query failed"),null}finally{n(!1)}},[e]);return{result:t,execute:d,isLoading:l,error:u}}function ds(e){const{client:t}=I(),[r,l]=a.useState(null),[n,u]=a.useState(!0),[i,d]=a.useState(null),c=a.useCallback(async()=>{u(!0),d(null);try{const o=await t.report.listQueries(e);l(o)}catch(o){d(o instanceof Error?o.message:"Failed to load queries")}finally{u(!1)}},[t,e]);return a.useEffect(()=>{c()},[c]),{queries:(r==null?void 0:r.data)??[],meta:r==null?void 0:r.meta,isLoading:n,error:i,refresh:c}}function Os(e){const{client:t}=I(),[r,l]=a.useState(null),[n,u]=a.useState(!0),[i,d]=a.useState(null),c=a.useCallback(async()=>{u(!0),d(null);try{const o=await t.report.getDashboard(e);l(o)}catch(o){d(o instanceof Error?o.message:"Failed to load dashboard")}finally{u(!1)}},[t,e]);return a.useEffect(()=>{c()},[c]),{dashboard:r,isLoading:n,error:i,refresh:c}}function Ws(e,t,r="https://api.saas-support.com/v1"){const l=a.useMemo(()=>{const p=new A.Transport(r,{type:"embedToken",token:e});return new A.ReportClient(p)},[e,r]),[n,u]=a.useState(null),[i,d]=a.useState(!0),[c,o]=a.useState(null),m=a.useCallback(async()=>{d(!0),o(null);try{const p=await l.getDashboard(t);u(p)}catch(p){o(p instanceof Error?p.message:"Failed to load dashboard")}finally{d(!1)}},[l,t]);return a.useEffect(()=>{m()},[m]),{dashboard:n,reportClient:l,isLoading:i,error:c,refresh:m}}function Hs({onResult:e,mode:t="both",placeholder:r,appearance:l}){const{appearance:n}=I(),{execute:u,isLoading:i,error:d}=X(),c=l??n,[o,m]=a.useState(""),[p,g]=a.useState(t==="sql"?"sql":"nl"),h=a.useCallback(async w=>{if(w.preventDefault(),!o.trim())return;const j=await u(p==="sql"?{sql:o}:{naturalLanguage:o});j&&(e==null||e(j))},[o,p,u,e]);return s.jsx(B,{appearance:c,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[t==="both"&&s.jsxs("div",{className:"ss-tab-group ss-tab-group-sm",children:[s.jsx("button",{type:"button",className:`ss-tab ${p==="nl"?"ss-tab-active":""}`,onClick:()=>g("nl"),children:"Natural Language"}),s.jsx("button",{type:"button",className:`ss-tab ${p==="sql"?"ss-tab-active":""}`,onClick:()=>g("sql"),children:"SQL"})]}),d&&s.jsx("div",{className:"ss-global-error",children:d}),s.jsxs("form",{onSubmit:h,children:[s.jsx("div",{className:"ss-field",children:s.jsx("textarea",{className:"ss-input ss-query-textarea",placeholder:r??(p==="sql"?"SELECT ...":"Ask a question about your data..."),value:o,onChange:w=>m(w.target.value),rows:3})}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:i||!o.trim(),children:[i&&s.jsx("span",{className:"ss-spinner"}),"Run query"]})]})]})})}function us({columns:e,rows:t,sortable:r=!0,maxRows:l,appearance:n}){const{appearance:u}=I(),i=n??u,[d,c]=a.useState(null),[o,m]=a.useState("asc"),p=a.useMemo(()=>d?[...t].sort((f,j)=>{const y=f[d],x=j[d];if(y==null&&x==null)return 0;if(y==null)return 1;if(x==null)return-1;if(typeof y=="number"&&typeof x=="number")return o==="asc"?y-x:x-y;const N=String(y),$=String(x);return o==="asc"?N.localeCompare($):$.localeCompare(N)}):t,[t,d,o]),g=l?p.slice(0,l):p,h=f=>{r&&(d===f?m(j=>j==="asc"?"desc":"asc"):(c(f),m("asc")))};function w(f){return f==null?"":typeof f=="object"?JSON.stringify(f):String(f)}return s.jsx(B,{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(f=>s.jsxs("th",{className:`ss-th ${r?"ss-th-sortable":""} ${d===f?o==="asc"?"ss-sorted-asc":"ss-sorted-desc":""}`,onClick:()=>h(f),children:[f,d===f&&s.jsx("span",{className:"ss-sort-indicator",children:o==="asc"?" ▲":" ▼"})]},f))})}),s.jsx("tbody",{children:g.map((f,j)=>s.jsx("tr",{className:"ss-tr",children:e.map(y=>s.jsx("td",{className:"ss-td",children:w(f[y])},y))},j))})]}),l&&t.length>l&&s.jsxs("div",{className:"ss-table-footer",children:["Showing ",l," of ",t.length," rows"]})]})})}function _s(e,t="#6366f1"){const r=parseInt(t.replace("#","").slice(0,2),16),l=[];for(let n=0;n<e;n++){const u=(r+n*Math.floor(360/Math.max(e,1)))%360;l.push(`hsl(${u}, 65%, 55%)`)}return l}function Vs({labels:e,values:t,w:r,h:l,colors:n}){const u=Math.max(...t,1),i=40,d=r-i*2,c=l-i*2,o=Math.max(1,d/e.length-4);return s.jsxs("g",{children:[s.jsx("line",{x1:i,y1:l-i,x2:r-i,y2:l-i,stroke:"#ccc",strokeWidth:1}),t.map((m,p)=>{const g=m/u*c,h=i+d/e.length*p+2,w=l-i-g;return s.jsxs("g",{children:[s.jsx("rect",{x:h,y:w,width:o,height:g,fill:n[p%n.length],rx:2}),s.jsx("text",{x:h+o/2,y:l-i+14,textAnchor:"middle",fontSize:10,fill:"#666",children:e[p].length>8?e[p].slice(0,8)+"...":e[p]})]},p)})]})}function Qs({labels:e,values:t,w:r,h:l,colors:n}){const u=Math.max(...t,1),i=40,d=r-i*2,c=l-i*2,o=e.length>1?d/(e.length-1):0,m=t.map((p,g)=>{const h=i+o*g,w=l-i-p/u*c;return`${h},${w}`});return s.jsxs("g",{children:[[.25,.5,.75,1].map(p=>{const g=l-i-p*c;return s.jsx("line",{x1:i,y1:g,x2:r-i,y2:g,stroke:"#eee",strokeWidth:1},p)}),s.jsx("polyline",{points:m.join(" "),fill:"none",stroke:n[0],strokeWidth:2}),t.map((p,g)=>{const h=i+o*g,w=l-i-p/u*c;return s.jsx("circle",{cx:h,cy:w,r:4,fill:n[0]},g)})]})}function Gs({labels:e,values:t,w:r,h:l,colors:n}){const u=t.reduce((g,h)=>g+h,0)||1,i=r/2,d=l/2-20,c=Math.min(r,l)/2-40,o=2*Math.PI*c;let m=0;const p=t.map((g,h)=>{const w=g/u,f=w*o,j={dash:f,offset:m,color:n[h%n.length],label:e[h],pct:w};return m+=f,j});return s.jsxs("g",{children:[p.map((g,h)=>s.jsx("circle",{cx:i,cy:d,r:c,fill:"none",stroke:g.color,strokeWidth:c*.6,strokeDasharray:`${g.dash} ${o-g.dash}`,strokeDashoffset:-g.offset,transform:`rotate(-90 ${i} ${d})`},h)),s.jsx("g",{transform:`translate(${i-e.length*30}, ${l-20})`,children:p.slice(0,6).map((g,h)=>s.jsxs("g",{transform:`translate(${h*60}, 0)`,children:[s.jsx("rect",{width:10,height:10,fill:g.color,rx:2}),s.jsx("text",{x:14,y:9,fontSize:9,fill:"#666",children:g.label.length>6?g.label.slice(0,6)+"..":g.label})]},h))})]})}function ps({type:e,data:t,title:r,width:l=400,height:n=300,appearance:u}){const{appearance:i}=I(),d=u??i,c=a.useMemo(()=>_s(t.labels.length),[t.labels.length]);return s.jsx(B,{appearance:d,children:s.jsxs("div",{className:"ss-chart-container",children:[r&&s.jsx("h3",{className:"ss-chart-title",children:r}),s.jsxs("svg",{viewBox:`0 0 ${l} ${n}`,width:"100%",style:{maxWidth:l},children:[e==="bar"&&s.jsx(Vs,{labels:t.labels,values:t.values,w:l,h:n,colors:c}),e==="line"&&s.jsx(Qs,{labels:t.labels,values:t.values,w:l,h:n,colors:c}),e==="pie"&&s.jsx(Gs,{labels:t.labels,values:t.values,w:l,h:n,colors:c})]})]})})}function Js({dashboardId:e,embedToken:t,baseUrl:r,refreshInterval:l,appearance:n}){const u=I(),i=n??(u==null?void 0:u.appearance),d=a.useMemo(()=>{if(t){const y=r??"https://api.saas-support.com/v1",x=new A.Transport(y,{type:"embedToken",token:t});return new A.ReportClient(x)}return u.client.report},[t,r,u]),[c,o]=a.useState([]),[m,p]=a.useState({}),[g,h]=a.useState(!0),[w,f]=a.useState(null),j=a.useCallback(async()=>{h(!0),f(null);try{const y=await d.getDashboard(e),x=JSON.parse(y.layoutJson||"[]");o(x);const N={};for(const $ of x)try{const k=await d.listQueries({search:$.queryId,perPage:1});if(k.data.length>0&&k.data[0].generatedSql){const E=await d.executeQuery({sql:k.data[0].generatedSql});N[$.queryId]=E}}catch{}p(N)}catch(y){f(y instanceof Error?y.message:"Failed to load dashboard")}finally{h(!1)}},[d,e]);return a.useEffect(()=>{j()},[j]),a.useEffect(()=>{if(!l||l<=0)return;const y=setInterval(j,l*1e3);return()=>clearInterval(y)},[l,j]),s.jsx(B,{appearance:i,children:s.jsxs("div",{className:"ss-dashboard-grid",children:[g&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading dashboard..."]}),w&&s.jsx("div",{className:"ss-global-error",children:w}),!g&&c.map((y,x)=>{const N=m[y.queryId];if(!N)return null;const $=N.columns.length>=2?{labels:N.rows.map(k=>String(k[N.columns[0]]??"")),values:N.rows.map(k=>Number(k[N.columns[1]]??0))}:{labels:[],values:[]};return s.jsxs("div",{className:"ss-widget",children:[y.title&&s.jsx("h4",{className:"ss-widget-header",children:y.title}),y.chartType==="table"?s.jsx(us,{columns:N.columns,rows:N.rows,maxRows:50}):s.jsx(ps,{type:y.chartType||"bar",data:$,width:y.w,height:y.h})]},x)})]})})}function Ys(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Zs({onSelectQuery:e,onRunQuery:t,appearance:r}){const{appearance:l}=I(),{queries:n,isLoading:u,error:i}=ds(),{execute:d,isLoading:c}=X(),o=r??l,m=a.useCallback(async p=>{if(!p.generatedSql)return;const g=await d({sql:p.generatedSql});g&&(t==null||t(g))},[d,t]);return s.jsx(B,{appearance:o,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Saved Queries"}),u&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),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:Ys(p.createdAt)}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:c||!p.generatedSql,onClick:g=>{g.stopPropagation(),m(p)},children:c?s.jsx("span",{className:"ss-spinner"}):"Run"})]})]},p.id))]})})}function Xs({embedToken:e,dashboardId:t,baseUrl:r="https://api.saas-support.com/v1",refreshInterval:l,appearance:n}){const u=a.useMemo(()=>{const f=new A.Transport(r,{type:"embedToken",token:e});return new A.ReportClient(f)},[e,r]),[i,d]=a.useState([]),[c,o]=a.useState(!0),[m,p]=a.useState(null),g=a.useMemo(()=>V(n),[n]),h=a.useMemo(()=>Q(g),[g]),w=a.useCallback(async()=>{o(!0),p(null);try{const f=await u.getDashboard(t),j=JSON.parse(f.layoutJson||"[]"),y=await Promise.all(j.map(async x=>{try{const N=await u.listQueries({search:x.queryId,perPage:1});if(N.data.length>0&&N.data[0].generatedSql){const $=await u.executeQuery({sql:N.data[0].generatedSql});return{...x,result:$}}}catch{}return x}));d(y)}catch(f){p(f instanceof Error?f.message:"Failed to load dashboard")}finally{o(!1)}},[u,t]);return a.useEffect(()=>{w()},[w]),a.useEffect(()=>{if(!l||l<=0)return;const f=setInterval(w,l*1e3);return()=>clearInterval(f)},[l,w]),s.jsx("div",{ref:f=>{if(!f||f.shadowRoot)return;const j=f.attachShadow({mode:"open"}),y=document.createElement("style");y.textContent=h,j.appendChild(y);const x=document.createElement("div");j.appendChild(x)},style:{display:"contents"},children:s.jsxs("div",{className:"ss-dashboard-grid",children:[c&&s.jsx("div",{className:"ss-loading",children:"Loading dashboard..."}),m&&s.jsx("div",{className:"ss-global-error",children:m}),!c&&i.map((f,j)=>{if(!f.result)return null;const{columns:y,rows:x}=f.result;return s.jsxs("div",{className:"ss-widget",children:[f.title&&s.jsx("h4",{className:"ss-widget-header",children:f.title}),s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsx("tr",{children:y.map(N=>s.jsx("th",{className:"ss-th",children:N},N))})}),s.jsx("tbody",{children:x.slice(0,50).map((N,$)=>s.jsx("tr",{className:"ss-tr",children:y.map(k=>s.jsx("td",{className:"ss-td",children:String(N[k]??"")},k))},$))})]})]},j)})]})})}exports.SaaSError=A.SaaSError;exports.SaaSSupport=A.SaaSSupport;exports.isMfaRequired=A.isMfaRequired;exports.Chart=ps;exports.CouponInput=qs;exports.DashboardView=Js;exports.DataTable=us;exports.InvoiceHistory=is;exports.OrgSwitcher=zs;exports.PaymentPortal=Us;exports.PricingTable=Ls;exports.QueryInput=Hs;exports.ReportEmbed=Xs;exports.SaaSContext=G;exports.SaaSProvider=ys;exports.SavedQueryList=Zs;exports.SignIn=Cs;exports.SignUp=ks;exports.SubscriptionStatus=ls;exports.UsageDisplay=cs;exports.UserButton=Es;exports.UserProfile=Is;exports.useAuth=W;exports.useBilling=Ms;exports.useDashboard=Os;exports.useDeleteAccount=ss;exports.useEmbedDashboard=Ws;exports.useInvoices=ns;exports.useOrg=Y;exports.useProfile=Z;exports.useQuery=X;exports.useReport=Rs;exports.useSaaSContext=I;exports.useSavedQueries=ds;exports.useSignIn=J;exports.useSignUp=K;exports.useSubscription=ts;exports.useUsage=os;exports.useUser=Ns;
|
package/dist/react.d.ts
CHANGED
|
@@ -73,6 +73,9 @@ declare class AuthClient {
|
|
|
73
73
|
orgId: string;
|
|
74
74
|
role: string;
|
|
75
75
|
}>;
|
|
76
|
+
listInvites(orgId: string): Promise<PendingInvite[]>;
|
|
77
|
+
revokeInvite(orgId: string, inviteId: string): Promise<void>;
|
|
78
|
+
deleteAccount(): Promise<void>;
|
|
76
79
|
/* Excluded from this release type: handleExternalLogout */
|
|
77
80
|
/* Excluded from this release type: performRefresh */
|
|
78
81
|
private setSession;
|
|
@@ -251,7 +254,7 @@ declare interface FilterRule {
|
|
|
251
254
|
value: string;
|
|
252
255
|
}
|
|
253
256
|
|
|
254
|
-
declare interface Invite {
|
|
257
|
+
export declare interface Invite {
|
|
255
258
|
inviteId: string;
|
|
256
259
|
email: string;
|
|
257
260
|
role: string;
|
|
@@ -293,7 +296,7 @@ declare interface ListParams {
|
|
|
293
296
|
search?: string;
|
|
294
297
|
}
|
|
295
298
|
|
|
296
|
-
declare interface Member {
|
|
299
|
+
export declare interface Member {
|
|
297
300
|
userId: string;
|
|
298
301
|
email: string;
|
|
299
302
|
role: string;
|
|
@@ -325,7 +328,7 @@ declare interface OffsetPage<T> {
|
|
|
325
328
|
};
|
|
326
329
|
}
|
|
327
330
|
|
|
328
|
-
declare interface Org {
|
|
331
|
+
export declare interface Org {
|
|
329
332
|
id: string;
|
|
330
333
|
projectId: string;
|
|
331
334
|
name: string;
|
|
@@ -352,6 +355,14 @@ export declare interface PaymentPortalProps {
|
|
|
352
355
|
appearance?: Appearance;
|
|
353
356
|
}
|
|
354
357
|
|
|
358
|
+
export declare interface PendingInvite {
|
|
359
|
+
id: string;
|
|
360
|
+
email: string;
|
|
361
|
+
role: string;
|
|
362
|
+
expiresAt: string;
|
|
363
|
+
createdAt: string;
|
|
364
|
+
}
|
|
365
|
+
|
|
355
366
|
declare interface Plan {
|
|
356
367
|
id: string;
|
|
357
368
|
name: string;
|
|
@@ -700,6 +711,13 @@ export declare function useDashboard(dashboardId: string): {
|
|
|
700
711
|
refresh: () => Promise<void>;
|
|
701
712
|
};
|
|
702
713
|
|
|
714
|
+
export declare function useDeleteAccount(): {
|
|
715
|
+
deleteAccount: () => Promise<boolean>;
|
|
716
|
+
isLoading: boolean;
|
|
717
|
+
error: string | null;
|
|
718
|
+
setError: Dispatch<SetStateAction<string | null>>;
|
|
719
|
+
};
|
|
720
|
+
|
|
703
721
|
export declare function useEmbedDashboard(embedToken: string, dashboardId: string, baseUrl?: string): {
|
|
704
722
|
dashboard: Dashboard | null;
|
|
705
723
|
reportClient: ReportClient;
|
|
@@ -719,11 +737,24 @@ export declare function useOrg(): {
|
|
|
719
737
|
orgs: Org[];
|
|
720
738
|
selectedOrg: Org | null;
|
|
721
739
|
members: Member[];
|
|
740
|
+
invites: PendingInvite[];
|
|
722
741
|
isLoading: boolean;
|
|
723
742
|
error: string | null;
|
|
743
|
+
setError: Dispatch<SetStateAction<string | null>>;
|
|
724
744
|
refresh: () => Promise<void>;
|
|
725
745
|
selectOrg: (orgId: string) => Promise<void>;
|
|
726
746
|
createOrg: (name: string, slug: string) => Promise<Org | null>;
|
|
747
|
+
updateOrg: (orgId: string, params: {
|
|
748
|
+
name?: string;
|
|
749
|
+
avatarUrl?: string;
|
|
750
|
+
}) => Promise<Org | null>;
|
|
751
|
+
deleteOrg: (orgId: string) => Promise<boolean>;
|
|
752
|
+
sendInvite: (orgId: string, email: string, role: string) => Promise<Invite | null>;
|
|
753
|
+
refreshInvites: (orgId: string) => Promise<void>;
|
|
754
|
+
revokeInvite: (orgId: string, inviteId: string) => Promise<boolean>;
|
|
755
|
+
updateMemberRole: (orgId: string, userId: string, role: string) => Promise<boolean>;
|
|
756
|
+
removeMember: (orgId: string, userId: string) => Promise<boolean>;
|
|
757
|
+
refreshMembers: (orgId: string) => Promise<void>;
|
|
727
758
|
};
|
|
728
759
|
|
|
729
760
|
export declare function useProfile(): {
|
|
@@ -765,11 +796,15 @@ export declare interface User {
|
|
|
765
796
|
avatarUrl?: string;
|
|
766
797
|
}
|
|
767
798
|
|
|
768
|
-
export declare function UserButton({ appearance: localAppearance }: UserButtonProps): JSX_2.Element | null;
|
|
799
|
+
export declare function UserButton({ appearance: localAppearance, afterSignOutUrl, afterDeleteAccountUrl, showOrgSwitcher, onOrgChange, onOrgSettingsClick, }: UserButtonProps): JSX_2.Element | null;
|
|
769
800
|
|
|
770
801
|
export declare interface UserButtonProps {
|
|
771
802
|
appearance?: Appearance;
|
|
772
803
|
afterSignOutUrl?: string;
|
|
804
|
+
afterDeleteAccountUrl?: string;
|
|
805
|
+
showOrgSwitcher?: boolean;
|
|
806
|
+
onOrgChange?: (org: Org) => void;
|
|
807
|
+
onOrgSettingsClick?: (org: Org) => void;
|
|
773
808
|
}
|
|
774
809
|
|
|
775
810
|
export declare function useReport(): {
|