@saas-support/react 0.3.2 → 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/react.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),t=require("react"),L=require("./index.cjs"),ss=require("react-dom"),D=t.createContext(null);function w(){const e=t.useContext(D);if(!e)throw new Error("useSaaSContext must be used within a <SaaSProvider>");return e}function es({publishableKey:e,apiKey:r,baseUrl:a,appearance:c,children:o}){const[d]=t.useState(()=>new L.SaaSSupport({publishableKey:e,apiKey:r,baseUrl:a})),[i,u]=t.useState(null),[l,n]=t.useState(!1),[m,p]=t.useState(null);return t.useEffect(()=>{let x=!1;d.load().then(async()=>{if(x)return;const h=await d.auth.getUser(),g=await d.auth.getSettings();u(h),p(g),n(!0)});const y=d.auth.onAuthStateChange(h=>{x||u(h)});return()=>{x=!0,y(),d.destroy()}},[d]),s.jsx(D.Provider,{value:{client:d,user:i,isLoaded:l,appearance:c,settings:m},children:o})}const as={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"},rs={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 z(e){const r=(e==null?void 0:e.baseTheme)==="dark"?rs:as,a=e==null?void 0:e.variables;return{colorPrimary:(a==null?void 0:a.colorPrimary)??r.colorPrimary,colorPrimaryHover:a!=null&&a.colorPrimary?ts(a.colorPrimary,10):r.colorPrimaryHover,colorBackground:(a==null?void 0:a.colorBackground)??r.colorBackground,colorText:(a==null?void 0:a.colorText)??r.colorText,colorTextSecondary:r.colorTextSecondary,colorInputBackground:(a==null?void 0:a.colorInputBackground)??r.colorInputBackground,colorInputBorder:(a==null?void 0:a.colorInputBorder)??r.colorInputBorder,colorError:(a==null?void 0:a.colorError)??r.colorError,colorSuccess:(a==null?void 0:a.colorSuccess)??r.colorSuccess,colorWarning:(a==null?void 0:a.colorWarning)??r.colorWarning,fontFamily:(a==null?void 0:a.fontFamily)??r.fontFamily,borderRadius:(a==null?void 0:a.borderRadius)??r.borderRadius}}function ts(e,r){const a=parseInt(e.replace("#",""),16),c=Math.max(0,(a>>16)-Math.round(2.55*r)),o=Math.max(0,(a>>8&255)-Math.round(2.55*r)),d=Math.max(0,(a&255)-Math.round(2.55*r));return`#${(c<<16|o<<8|d).toString(16).padStart(6,"0")}`}function q(e){return`
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: 400px;
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 {
@@ -695,6 +715,111 @@
695
715
  object-fit: cover;
696
716
  }
697
717
 
718
+ /* Avatar hover overlay */
719
+ .ss-avatar-hoverable {
720
+ position: relative;
721
+ cursor: pointer;
722
+ transition: filter 0.15s;
723
+ }
724
+
725
+ .ss-avatar-overlay {
726
+ position: absolute;
727
+ inset: 0;
728
+ border-radius: 50%;
729
+ background: rgba(0, 0, 0, 0.5);
730
+ display: flex;
731
+ align-items: center;
732
+ justify-content: center;
733
+ opacity: 0;
734
+ transition: opacity 0.15s;
735
+ color: #fff;
736
+ }
737
+
738
+ .ss-avatar-hoverable:hover .ss-avatar-overlay {
739
+ opacity: 1;
740
+ }
741
+
742
+ /* Avatar cropper */
743
+ .ss-avatar-cropper {
744
+ display: flex;
745
+ flex-direction: column;
746
+ align-items: center;
747
+ gap: 16px;
748
+ }
749
+
750
+ .ss-avatar-canvas {
751
+ border-radius: ${e.borderRadius};
752
+ background: #111;
753
+ touch-action: none;
754
+ max-width: 100%;
755
+ }
756
+
757
+ .ss-avatar-zoom {
758
+ display: flex;
759
+ align-items: center;
760
+ gap: 12px;
761
+ width: 100%;
762
+ }
763
+
764
+ .ss-avatar-zoom-label {
765
+ font-size: 13px;
766
+ color: ${e.colorTextSecondary};
767
+ flex-shrink: 0;
768
+ }
769
+
770
+ .ss-avatar-zoom-slider {
771
+ flex: 1;
772
+ height: 4px;
773
+ -webkit-appearance: none;
774
+ appearance: none;
775
+ background: ${e.colorInputBorder};
776
+ border-radius: 2px;
777
+ outline: none;
778
+ }
779
+
780
+ .ss-avatar-zoom-slider::-webkit-slider-thumb {
781
+ -webkit-appearance: none;
782
+ width: 16px;
783
+ height: 16px;
784
+ border-radius: 50%;
785
+ background: ${e.colorPrimary};
786
+ cursor: pointer;
787
+ }
788
+
789
+ .ss-avatar-zoom-slider::-moz-range-thumb {
790
+ width: 16px;
791
+ height: 16px;
792
+ border-radius: 50%;
793
+ background: ${e.colorPrimary};
794
+ cursor: pointer;
795
+ border: none;
796
+ }
797
+
798
+ /* Dropzone */
799
+ .ss-avatar-dropzone {
800
+ border: 2px dashed ${e.colorInputBorder};
801
+ border-radius: ${e.borderRadius};
802
+ padding: 40px 24px;
803
+ text-align: center;
804
+ cursor: pointer;
805
+ transition: border-color 0.15s, background 0.15s;
806
+ color: ${e.colorTextSecondary};
807
+ display: flex;
808
+ flex-direction: column;
809
+ align-items: center;
810
+ gap: 12px;
811
+ }
812
+
813
+ .ss-avatar-dropzone:hover,
814
+ .ss-avatar-dropzone-active {
815
+ border-color: ${e.colorPrimary};
816
+ background: ${e.colorPrimary}08;
817
+ }
818
+
819
+ .ss-avatar-dropzone svg {
820
+ opacity: 0.5;
821
+ }
822
+
698
823
  .ss-input-readonly {
699
824
  opacity: 0.6;
700
825
  cursor: not-allowed;
@@ -725,4 +850,4 @@
725
850
  font-size: 13px;
726
851
  padding: 6px 12px;
727
852
  }
728
- `}function P({children:e,appearance:r}){const a=t.useRef(null),[c,o]=t.useState(null);t.useEffect(()=>{var m;if(!a.current||a.current.shadowRoot){o(((m=a.current)==null?void 0:m.shadowRoot)??null);return}const i=a.current.attachShadow({mode:"open"}),u=z(r),l=document.createElement("style");l.textContent=q(u),i.appendChild(l);const n=document.createElement("div");i.appendChild(n),o(i)},[]),t.useEffect(()=>{if(!c)return;const i=c.querySelector("style");if(i){const u=z(r);i.textContent=q(u)}},[r,c]);const d=(c==null?void 0:c.querySelector("div"))??null;return s.jsx("div",{ref:a,style:{display:"contents"},children:d&&ss.createPortal(e,d)})}function M(){const{client:e,user:r,isLoaded:a}=w();return{isLoaded:a,isSignedIn:!!r,user:r,signOut:t.useCallback(()=>e.auth.signOut(),[e]),getToken:t.useCallback(()=>e.auth.getToken(),[e])}}function ns(){const{user:e,isLoaded:r}=w();return{user:e,isLoaded:r}}function F(){const{client:e}=w(),[r,a]=t.useState(!1),[c,o]=t.useState(null),d=t.useCallback(async(l,n)=>{a(!0),o(null);try{return await e.auth.signIn(l,n)}catch(m){return o(m instanceof Error?m.message:"Sign in failed"),null}finally{a(!1)}},[e]),i=t.useCallback(async l=>{a(!0),o(null);try{return await e.auth.signInWithOAuth(l)}catch(n){return o(n instanceof Error?n.message:"OAuth sign in failed"),null}finally{a(!1)}},[e]),u=t.useCallback(async(l,n)=>{a(!0),o(null);try{return await e.auth.submitMfaCode(l,n)}catch(m){return o(m instanceof Error?m.message:"MFA verification failed"),null}finally{a(!1)}},[e]);return{signIn:d,signInWithOAuth:i,submitMfaCode:u,isLoading:r,error:c,setError:o}}function R(){const{client:e}=w(),[r,a]=t.useState(!1),[c,o]=t.useState(null);return{signUp:t.useCallback(async(i,u)=>{a(!0),o(null);try{return await e.auth.signUp(i,u)}catch(l){return o(l instanceof Error?l.message:"Sign up failed"),null}finally{a(!1)}},[e]),isLoading:r,error:c,setError:o}}function O(){const{client:e}=w(),[r,a]=t.useState([]),[c,o]=t.useState(null),[d,i]=t.useState([]),[u,l]=t.useState(!1),[n,m]=t.useState(null),p=t.useCallback(async()=>{l(!0),m(null);try{const h=await e.auth.listOrgs();a(h)}catch(h){m(h instanceof Error?h.message:"Failed to load organizations")}finally{l(!1)}},[e]);t.useEffect(()=>{p()},[p]);const x=t.useCallback(async h=>{try{const g=await e.auth.getOrg(h);o(g);const f=await e.auth.listMembers(h);i(f)}catch(g){m(g instanceof Error?g.message:"Failed to load organization")}},[e]),y=t.useCallback(async(h,g)=>{try{const f=await e.auth.createOrg(h,g);return a(b=>[...b,f]),f}catch(f){return m(f instanceof Error?f.message:"Failed to create organization"),null}},[e]);return{orgs:r,selectedOrg:c,members:d,isLoading:u,error:n,refresh:p,selectOrg:x,createOrg:y}}function A(){const{client:e,user:r}=w(),[a,c]=t.useState(!1),[o,d]=t.useState(null),[i,u]=t.useState(null),l=t.useCallback(async m=>{c(!0),d(null),u(null);try{const p=await e.auth.updateProfile(m);return u("Profile updated"),p}catch(p){return d(p instanceof Error?p.message:"Failed to update profile"),null}finally{c(!1)}},[e]),n=t.useCallback(async(m,p)=>{c(!0),d(null),u(null);try{return await e.auth.changePassword(m,p),u("Password changed successfully"),!0}catch(x){return d(x instanceof Error?x.message:"Failed to change password"),!1}finally{c(!1)}},[e]);return{user:r,updateProfile:l,changePassword:n,isLoading:a,error:o,success:i,setError:d,setSuccess:u}}const W='<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>',H='<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 os({appearance:e,signUpUrl:r,onSignUp:a}){const{appearance:c,settings:o}=w(),{signIn:d,signInWithOAuth:i,submitMfaCode:u,isLoading:l,error:n,setError:m}=F(),p=e??c,[x,y]=t.useState(""),[h,g]=t.useState(""),[f,b]=t.useState(!1),[j,v]=t.useState(""),[N,k]=t.useState(""),T=t.useCallback(async I=>{if(I.preventDefault(),f){await u(j,N);return}const C=await d(x,h);C&&L.isMfaRequired(C)&&(v(C.mfaToken),b(!0),m(null))},[x,h,f,j,N,d,u,m]),$=t.useCallback(async I=>{await i(I)},[i]),S=(o==null?void 0:o.googleEnabled)||(o==null?void 0:o.githubEnabled);return s.jsx(P,{appearance:p,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Sign in"}),!f&&s.jsxs(s.Fragment,{children:[(o==null?void 0:o.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>$("google"),disabled:l,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:W}}),"Continue with Google"]}),(o==null?void 0:o.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>$("github"),disabled:l,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:H}}),"Continue with GitHub"]}),S&&s.jsx("div",{className:"ss-divider",children:"or"})]}),n&&s.jsx("div",{className:"ss-global-error",children:n}),s.jsxs("form",{onSubmit:T,children:[f?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:I=>k(I.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:x,onChange:I=>y(I.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:h,onChange:I=>g(I.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"}),f?"Verify":"Continue"]})]}),f&&s.jsx("div",{className:"ss-footer",children:s.jsx("span",{className:"ss-link",onClick:()=>{b(!1),k(""),m(null)},children:"Back to sign in"})}),!f&&s.jsxs("div",{className:"ss-footer",children:["Don't have an account?"," ",a?s.jsx("span",{className:"ss-link",onClick:a,children:"Sign up"}):r?s.jsx("a",{className:"ss-link",href:r,children:"Sign up"}):s.jsx("span",{className:"ss-link",children:"Sign up"})]})]})})}function ls({appearance:e,signInUrl:r,onSignIn:a}){const{appearance:c,settings:o}=w(),{signUp:d,isLoading:i,error:u,setError:l}=R(),{signInWithOAuth:n}=F(),m=e??c,[p,x]=t.useState(""),[y,h]=t.useState(""),[g,f]=t.useState(""),[b,j]=t.useState(null),v=t.useCallback(async $=>{if($.preventDefault(),j(null),y!==g){j("Passwords do not match");return}const S=(o==null?void 0:o.passwordMinLength)??8;if(y.length<S){j(`Password must be at least ${S} characters`);return}await d(p,y)},[p,y,g,o,d]),N=t.useCallback(async $=>{await n($)},[n]),k=(o==null?void 0:o.googleEnabled)||(o==null?void 0:o.githubEnabled),T=b||u;return s.jsx(P,{appearance:m,children:s.jsxs("div",{className:"ss-card",children:[s.jsx("h2",{className:"ss-title",children:"Create account"}),(o==null?void 0:o.googleEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>N("google"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:W}}),"Continue with Google"]}),(o==null?void 0:o.githubEnabled)&&s.jsxs("button",{type:"button",className:"ss-btn-social",onClick:()=>N("github"),disabled:i,children:[s.jsx("span",{dangerouslySetInnerHTML:{__html:H}}),"Continue with GitHub"]}),k&&s.jsx("div",{className:"ss-divider",children:"or"}),T&&s.jsx("div",{className:"ss-global-error",children:T}),s.jsxs("form",{onSubmit:v,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:$=>x($.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:y,onChange:$=>{h($.target.value),j(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:g,onChange:$=>{f($.target.value),j(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?"," ",a?s.jsx("span",{className:"ss-link",onClick:a,children:"Sign in"}):r?s.jsx("a",{className:"ss-link",href:r,children:"Sign in"}):s.jsx("span",{className:"ss-link",children:"Sign in"})]})]})})}function is({appearance:e}){const{appearance:r}=w(),{user:a,signOut:c}=M(),o=e??r,[d,i]=t.useState(!1),[u,l]=t.useState(!1),n=t.useRef(null),m=t.useCallback(x=>{n.current&&!x.composedPath().includes(n.current)&&i(!1)},[]);if(t.useEffect(()=>{if(d){const x=setTimeout(()=>{document.addEventListener("click",m)},0);return()=>{clearTimeout(x),document.removeEventListener("click",m)}}},[d,m]),!a)return null;const p=(a.name||a.email).charAt(0).toUpperCase();return s.jsx(P,{appearance:o,children:s.jsxs("div",{className:"ss-user-btn",ref:n,children:[s.jsx("button",{type:"button",className:"ss-avatar",onClick:()=>i(!d),"aria-label":"User menu",children:a.avatarUrl?s.jsx("img",{src:a.avatarUrl,alt:"",style:{width:"100%",height:"100%",borderRadius:"50%",objectFit:"cover"}}):p}),d&&s.jsxs("div",{className:"ss-dropdown",children:[s.jsxs("div",{className:"ss-dropdown-header",children:[a.name&&s.jsx("div",{style:{fontWeight:600,fontSize:"14px",color:"inherit"},children:a.name}),s.jsx("div",{className:"ss-dropdown-email",children:a.email})]}),s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>{i(!1),l(!0)},children:"Profile"}),s.jsx("button",{type:"button",className:"ss-dropdown-item ss-dropdown-item-danger",onClick:async()=>{i(!1),await c()},children:"Sign out"})]}),u&&s.jsx(cs,{onClose:()=>l(!1)})]})})}function cs({onClose:e}){const{user:r,updateProfile:a,changePassword:c,isLoading:o,error:d,success:i,setError:u,setSuccess:l}=A(),[n,m]=t.useState((r==null?void 0:r.name)??""),[p,x]=t.useState((r==null?void 0:r.avatarUrl)??""),[y,h]=t.useState(""),[g,f]=t.useState(""),[b,j]=t.useState(""),[v,N]=t.useState(null),k=t.useCallback(async S=>{S.preventDefault(),u(null),l(null),await a({name:n,avatarUrl:p})},[n,p,a,u,l]),T=t.useCallback(async S=>{if(S.preventDefault(),N(null),u(null),l(null),g!==b){N("Passwords do not match");return}if(g.length<8){N("Password must be at least 8 characters");return}await c(y,g)&&(h(""),f(""),j(""))},[y,g,b,c,u,l]),$=(r==null?void 0:r.provider)==="email";return s.jsx("div",{className:"ss-modal-overlay",onClick:S=>{S.target===S.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}),i&&s.jsx("div",{className:"ss-success-msg",children:i}),s.jsx("div",{className:"ss-avatar-preview",children:p?s.jsx("img",{src:p,alt:""}):(n||(r==null?void 0:r.email)||"?").charAt(0).toUpperCase()}),s.jsxs("form",{onSubmit:k,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:n,onChange:S=>m(S.target.value)})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Avatar URL"}),s.jsx("input",{className:"ss-input",type:"url",placeholder:"https://example.com/avatar.jpg",value:p,onChange:S=>x(S.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:o,children:[o&&s.jsx("span",{className:"ss-spinner"}),"Save changes"]})]}),$&&s.jsxs("div",{className:"ss-modal-section",children:[s.jsx("div",{className:"ss-modal-section-title",children:"Change password"}),v&&s.jsx("div",{className:"ss-global-error",children:v}),s.jsxs("form",{onSubmit:T,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:y,onChange:S=>h(S.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:g,onChange:S=>f(S.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:S=>j(S.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:o,children:[o&&s.jsx("span",{className:"ss-spinner"}),"Update password"]})]})]})]})})}function ds({appearance:e}){const{appearance:r}=w(),{user:a,signOut:c}=M(),{updateProfile:o,changePassword:d,isLoading:i,error:u,success:l,setError:n,setSuccess:m}=A(),p=e??r,[x,y]=t.useState((a==null?void 0:a.name)??""),[h,g]=t.useState((a==null?void 0:a.avatarUrl)??""),[f,b]=t.useState(""),[j,v]=t.useState(""),[N,k]=t.useState(""),[T,$]=t.useState(null),S=t.useCallback(async E=>{E.preventDefault(),n(null),m(null),await o({name:x,avatarUrl:h})},[x,h,o,n,m]),I=t.useCallback(async E=>{if(E.preventDefault(),$(null),n(null),m(null),j!==N){$("Passwords do not match");return}if(j.length<8){$("Password must be at least 8 characters");return}await d(f,j)&&(b(""),v(""),k(""))},[f,j,N,d,n,m]);if(!a)return null;const C=a.provider==="email";return s.jsx(P,{appearance:p,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Profile"}),u&&s.jsx("div",{className:"ss-global-error",children:u}),l&&s.jsx("div",{className:"ss-success-msg",children:l}),s.jsx("div",{className:"ss-avatar-preview",style:{margin:"0 auto 16px"},children:h?s.jsx("img",{src:h,alt:""}):(x||a.email).charAt(0).toUpperCase()}),s.jsxs("form",{onSubmit:S,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:E=>y(E.target.value)})]}),s.jsxs("div",{className:"ss-field",children:[s.jsx("label",{className:"ss-label",children:"Avatar URL"}),s.jsx("input",{className:"ss-input",type:"url",placeholder:"https://example.com/avatar.jpg",value:h,onChange:E=>g(E.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:a.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:a.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:a.emailVerified?"Yes":"No",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"]})]}),C&&s.jsxs("div",{className:"ss-modal-section",children:[s.jsx("div",{className:"ss-modal-section-title",children:"Change password"}),T&&s.jsx("div",{className:"ss-global-error",children:T}),s.jsxs("form",{onSubmit:I,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:f,onChange:E=>b(E.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:j,onChange:E=>v(E.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:E=>k(E.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.jsx("div",{style:{marginTop:"24px"},children:s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:()=>c(),children:"Sign out"})})]})})}function us({appearance:e,onOrgChange:r}){const{appearance:a}=w(),{orgs:c,selectedOrg:o,selectOrg:d,createOrg:i,isLoading:u}=O(),l=e??a,[n,m]=t.useState(!1),[p,x]=t.useState(!1),[y,h]=t.useState(""),[g,f]=t.useState(""),[b,j]=t.useState(null),[v,N]=t.useState(!1),k=t.useRef(null),T=t.useCallback(C=>{k.current&&!C.composedPath().includes(k.current)&&(m(!1),x(!1))},[]);t.useEffect(()=>{if(n){const C=setTimeout(()=>{document.addEventListener("click",T)},0);return()=>{clearTimeout(C),document.removeEventListener("click",T)}}},[n,T]);const $=t.useCallback(C=>{h(C),f(C.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},[]),S=t.useCallback(async C=>{C.preventDefault(),j(null),N(!0);try{const E=await i(y,g);E&&(await d(E.id),r==null||r(E),x(!1),h(""),f(""),m(!1))}catch(E){j(E instanceof Error?E.message:"Failed to create organization")}finally{N(!1)}},[y,g,i,d,r]);if(u)return null;const I=(o==null?void 0:o.name)??(c.length===0?"No organization":"Select organization");return s.jsx(P,{appearance:l,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(!n),children:[I,s.jsx("span",{className:"ss-chevron",children:n?"▲":"▼"})]}),n&&s.jsxs("div",{className:"ss-dropdown ss-dropdown-org",children:[c.map(C=>s.jsx("button",{type:"button",className:`ss-dropdown-item ${(o==null?void 0:o.id)===C.id?"ss-dropdown-item-active":""}`,onClick:async()=>{m(!1),x(!1),await d(C.id),r==null||r(C)},children:C.name},C.id)),s.jsx("div",{className:"ss-dropdown-divider"}),p?s.jsxs("div",{className:"ss-inline-form",children:[b&&s.jsx("div",{className:"ss-global-error",style:{marginBottom:"8px",fontSize:"12px"},children:b}),s.jsxs("form",{onSubmit:S,children:[s.jsx("div",{className:"ss-field",children:s.jsx("input",{className:"ss-input",type:"text",placeholder:"Organization name",value:y,onChange:C=>$(C.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:g,onChange:C=>f(C.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:()=>{x(!1),j(null)},children:"Cancel"}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:v,children:[v&&s.jsx("span",{className:"ss-spinner"}),"Create"]})]})]})]}):s.jsx("button",{type:"button",className:"ss-dropdown-item",onClick:()=>x(!0),style:{fontWeight:500},children:"+ Create organization"})]})]})})}function ps(e,r="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:r,minimumFractionDigits:e%100===0?0:2}).format(e/100)}function ms({plans:e,currentPlanId:r,onSelectPlan:a,interval:c,appearance:o}){const{appearance:d}=w(),i=o??d,u=c?e.filter(l=>l.interval===c||l.isFree):e;return s.jsx(P,{appearance:i,children:s.jsx("div",{className:"ss-pricing-grid",children:u.map(l=>{const n=l.id===r;return s.jsxs("div",{className:`ss-pricing-card ${n?"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:ps(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((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 ${n?"ss-btn-current":"ss-btn-primary"}`,disabled:n,onClick:()=>a(l.id),children:n?"Current plan":"Select plan"})]},l.id)})})})}function xs(){const{client:e}=w();return{billing:e.billing}}function B(e){const{client:r}=w();return t.useMemo(()=>{if(e){const a=new L.Transport("https://api.saas-support.com/v1",{type:"portalToken",token:e});return new L.BillingClient(a)}return r.billing},[r,e])}function _(e,r){const a=B(r),[c,o]=t.useState(null),[d,i]=t.useState(!0),[u,l]=t.useState(null),n=t.useCallback(async()=>{i(!0),l(null);try{const m=await a.getCustomer(e);o(m)}catch(m){l(m instanceof Error?m.message:"Failed to load subscription")}finally{i(!1)}},[a,e]);return t.useEffect(()=>{n()},[n]),{customer:c,isLoading:d,error:u,refresh:n}}function Q(e,r){const a=B(r),[c,o]=t.useState([]),[d,i]=t.useState(!0),[u,l]=t.useState(null),n=t.useCallback(async()=>{i(!0),l(null);try{const m=await a.getInvoices(e);o(m)}catch(m){l(m instanceof Error?m.message:"Failed to load invoices")}finally{i(!1)}},[a,e]);return t.useEffect(()=>{n()},[n]),{invoices:c,isLoading:d,error:u,refresh:n}}function G(e,r){const a=B(r),[c,o]=t.useState([]),[d,i]=t.useState(!0),[u,l]=t.useState(null),n=t.useCallback(async()=>{i(!0),l(null);try{const m=await a.getCurrentUsage(e);o(m)}catch(m){l(m instanceof Error?m.message:"Failed to load usage")}finally{i(!1)}},[a,e]);return t.useEffect(()=>{n()},[n]),{usage:c,isLoading:d,error:u,refresh:n}}const gs={active:"ss-badge-active"};function V({customerId:e,portalToken:r,onChangePlan:a,onCancel:c,appearance:o}){const{appearance:d}=w(),{customer:i,isLoading:u,error:l}=_(e,r),n=o??d;return s.jsx(P,{appearance:n,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}),i&&!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: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 ${gs.active}`,children:"Active"})})]}),s.jsxs("div",{className:"ss-btn-group",children:[a&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-primary",onClick:a,children:"Change plan"}),c&&s.jsx("button",{type:"button",className:"ss-btn ss-btn-danger",onClick:c,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 hs(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 J({customerId:e,portalToken:r,appearance:a}){const{appearance:c}=w(),{invoices:o,isLoading:d,error:i}=Q(e,r),u=a??c,l=[...o].sort((n,m)=>new Date(m.createdAt).getTime()-new Date(n.createdAt).getTime());return s.jsx(P,{appearance:u,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Invoices"}),d&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),i&&s.jsx("div",{className:"ss-global-error",children:i}),!d&&l.length===0&&s.jsx("p",{className:"ss-empty",children:"No invoices yet."}),!d&&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(n=>s.jsxs("tr",{className:"ss-tr",children:[s.jsx("td",{className:"ss-td",children:hs(n.createdAt)}),s.jsx("td",{className:"ss-td",children:fs(n.amountCents)}),s.jsx("td",{className:"ss-td",children:s.jsx("span",{className:`ss-badge ${bs[n.status]||""}`,children:n.status})}),s.jsx("td",{className:"ss-td",children:n.pdfUrl?s.jsx("a",{className:"ss-link",href:n.pdfUrl,target:"_blank",rel:"noopener noreferrer",children:"Download"}):"—"})]},n.id))})]})]})})}function Y({customerId:e,limits:r,portalToken:a,appearance:c}){const{appearance:o}=w(),{usage:d,isLoading:i,error:u}=G(e,a),l=c??o;return s.jsx(P,{appearance:l,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..."]}),u&&s.jsx("div",{className:"ss-global-error",children:u}),!i&&d.length===0&&s.jsx("p",{className:"ss-empty",children:"No usage data."}),!i&&d.map(n=>{const m=r==null?void 0:r[n.metric],p=m?Math.min(100,n.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:n.metric}),s.jsxs("span",{className:"ss-usage-value",children:[n.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}%`}})})]},n.metric)})]})})}function ys({customerId:e,portalToken:r,limits:a,onChangePlan:c,onCancel:o,appearance:d}){const{appearance:i}=w(),u=d??i,[l,n]=t.useState("subscription"),m=[{id:"subscription",label:"Subscription"},{id:"invoices",label:"Invoices"},{id:"usage",label:"Usage"}];return s.jsx(P,{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:m.map(p=>s.jsx("button",{type:"button",className:`ss-tab ${l===p.id?"ss-tab-active":""}`,onClick:()=>n(p.id),children:p.label},p.id))}),s.jsxs("div",{className:"ss-tab-content",children:[l==="subscription"&&s.jsx(V,{customerId:e,portalToken:r,onChangePlan:c,onCancel:o}),l==="invoices"&&s.jsx(J,{customerId:e,portalToken:r}),l==="usage"&&s.jsx(Y,{customerId:e,portalToken:r,limits:a})]})]})})}function js({customerId:e,portalToken:r,onApplied:a,appearance:c}){const{appearance:o}=w(),d=B(r),i=c??o,[u,l]=t.useState(""),[n,m]=t.useState(!1),[p,x]=t.useState(null),[y,h]=t.useState(null),g=t.useCallback(async f=>{if(f.preventDefault(),!!u.trim()){m(!0),x(null),h(null);try{const b=await d.applyCoupon(e,u.trim());h(`Coupon applied! ${b.discountType==="percent"?`${b.amount}% off`:`$${(b.amount/100).toFixed(2)} off`}`),l(""),a==null||a(b)}catch(b){x(b instanceof Error?b.message:"Invalid coupon code")}finally{m(!1)}}},[d,e,u,a]);return s.jsx(P,{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}),y&&s.jsx("div",{className:"ss-success-msg",children:y}),s.jsxs("form",{onSubmit:g,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:f=>l(f.target.value),required:!0})]}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:n||!u.trim(),children:[n&&s.jsx("span",{className:"ss-spinner"}),"Apply"]})]})]})})}function vs(){const{client:e}=w();return{report:e.report}}function U(){const{client:e}=w(),[r,a]=t.useState(null),[c,o]=t.useState(!1),[d,i]=t.useState(null),u=t.useCallback(async l=>{o(!0),i(null);try{const n=await e.report.executeQuery(l);return a(n),n}catch(n){return i(n instanceof Error?n.message:"Query failed"),null}finally{o(!1)}},[e]);return{result:r,execute:u,isLoading:c,error:d}}function K(e){const{client:r}=w(),[a,c]=t.useState(null),[o,d]=t.useState(!0),[i,u]=t.useState(null),l=t.useCallback(async()=>{d(!0),u(null);try{const n=await r.report.listQueries(e);c(n)}catch(n){u(n instanceof Error?n.message:"Failed to load queries")}finally{d(!1)}},[r,e]);return t.useEffect(()=>{l()},[l]),{queries:(a==null?void 0:a.data)??[],meta:a==null?void 0:a.meta,isLoading:o,error:i,refresh:l}}function Ns(e){const{client:r}=w(),[a,c]=t.useState(null),[o,d]=t.useState(!0),[i,u]=t.useState(null),l=t.useCallback(async()=>{d(!0),u(null);try{const n=await r.report.getDashboard(e);c(n)}catch(n){u(n instanceof Error?n.message:"Failed to load dashboard")}finally{d(!1)}},[r,e]);return t.useEffect(()=>{l()},[l]),{dashboard:a,isLoading:o,error:i,refresh:l}}function ws(e,r,a="https://api.saas-support.com/v1"){const c=t.useMemo(()=>{const p=new L.Transport(a,{type:"embedToken",token:e});return new L.ReportClient(p)},[e,a]),[o,d]=t.useState(null),[i,u]=t.useState(!0),[l,n]=t.useState(null),m=t.useCallback(async()=>{u(!0),n(null);try{const p=await c.getDashboard(r);d(p)}catch(p){n(p instanceof Error?p.message:"Failed to load dashboard")}finally{u(!1)}},[c,r]);return t.useEffect(()=>{m()},[m]),{dashboard:o,reportClient:c,isLoading:i,error:l,refresh:m}}function Ss({onResult:e,mode:r="both",placeholder:a,appearance:c}){const{appearance:o}=w(),{execute:d,isLoading:i,error:u}=U(),l=c??o,[n,m]=t.useState(""),[p,x]=t.useState(r==="sql"?"sql":"nl"),y=t.useCallback(async h=>{if(h.preventDefault(),!n.trim())return;const f=await d(p==="sql"?{sql:n}:{naturalLanguage:n});f&&(e==null||e(f))},[n,p,d,e]);return s.jsx(P,{appearance:l,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[r==="both"&&s.jsxs("div",{className:"ss-tab-group ss-tab-group-sm",children:[s.jsx("button",{type:"button",className:`ss-tab ${p==="nl"?"ss-tab-active":""}`,onClick:()=>x("nl"),children:"Natural Language"}),s.jsx("button",{type:"button",className:`ss-tab ${p==="sql"?"ss-tab-active":""}`,onClick:()=>x("sql"),children:"SQL"})]}),u&&s.jsx("div",{className:"ss-global-error",children:u}),s.jsxs("form",{onSubmit:y,children:[s.jsx("div",{className:"ss-field",children:s.jsx("textarea",{className:"ss-input ss-query-textarea",placeholder:a??(p==="sql"?"SELECT ...":"Ask a question about your data..."),value:n,onChange:h=>m(h.target.value),rows:3})}),s.jsxs("button",{type:"submit",className:"ss-btn ss-btn-primary",disabled:i||!n.trim(),children:[i&&s.jsx("span",{className:"ss-spinner"}),"Run query"]})]})]})})}function X({columns:e,rows:r,sortable:a=!0,maxRows:c,appearance:o}){const{appearance:d}=w(),i=o??d,[u,l]=t.useState(null),[n,m]=t.useState("asc"),p=t.useMemo(()=>u?[...r].sort((g,f)=>{const b=g[u],j=f[u];if(b==null&&j==null)return 0;if(b==null)return 1;if(j==null)return-1;if(typeof b=="number"&&typeof j=="number")return n==="asc"?b-j:j-b;const v=String(b),N=String(j);return n==="asc"?v.localeCompare(N):N.localeCompare(v)}):r,[r,u,n]),x=c?p.slice(0,c):p,y=g=>{a&&(u===g?m(f=>f==="asc"?"desc":"asc"):(l(g),m("asc")))};function h(g){return g==null?"":typeof g=="object"?JSON.stringify(g):String(g)}return s.jsx(P,{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(g=>s.jsxs("th",{className:`ss-th ${a?"ss-th-sortable":""} ${u===g?n==="asc"?"ss-sorted-asc":"ss-sorted-desc":""}`,onClick:()=>y(g),children:[g,u===g&&s.jsx("span",{className:"ss-sort-indicator",children:n==="asc"?" ▲":" ▼"})]},g))})}),s.jsx("tbody",{children:x.map((g,f)=>s.jsx("tr",{className:"ss-tr",children:e.map(b=>s.jsx("td",{className:"ss-td",children:h(g[b])},b))},f))})]}),c&&r.length>c&&s.jsxs("div",{className:"ss-table-footer",children:["Showing ",c," of ",r.length," rows"]})]})})}function ks(e,r="#6366f1"){const a=parseInt(r.replace("#","").slice(0,2),16),c=[];for(let o=0;o<e;o++){const d=(a+o*Math.floor(360/Math.max(e,1)))%360;c.push(`hsl(${d}, 65%, 55%)`)}return c}function Cs({labels:e,values:r,w:a,h:c,colors:o}){const d=Math.max(...r,1),i=40,u=a-i*2,l=c-i*2,n=Math.max(1,u/e.length-4);return s.jsxs("g",{children:[s.jsx("line",{x1:i,y1:c-i,x2:a-i,y2:c-i,stroke:"#ccc",strokeWidth:1}),r.map((m,p)=>{const x=m/d*l,y=i+u/e.length*p+2,h=c-i-x;return s.jsxs("g",{children:[s.jsx("rect",{x:y,y:h,width:n,height:x,fill:o[p%o.length],rx:2}),s.jsx("text",{x:y+n/2,y:c-i+14,textAnchor:"middle",fontSize:10,fill:"#666",children:e[p].length>8?e[p].slice(0,8)+"...":e[p]})]},p)})]})}function $s({labels:e,values:r,w:a,h:c,colors:o}){const d=Math.max(...r,1),i=40,u=a-i*2,l=c-i*2,n=e.length>1?u/(e.length-1):0,m=r.map((p,x)=>{const y=i+n*x,h=c-i-p/d*l;return`${y},${h}`});return s.jsxs("g",{children:[[.25,.5,.75,1].map(p=>{const x=c-i-p*l;return s.jsx("line",{x1:i,y1:x,x2:a-i,y2:x,stroke:"#eee",strokeWidth:1},p)}),s.jsx("polyline",{points:m.join(" "),fill:"none",stroke:o[0],strokeWidth:2}),r.map((p,x)=>{const y=i+n*x,h=c-i-p/d*l;return s.jsx("circle",{cx:y,cy:h,r:4,fill:o[0]},x)})]})}function Es({labels:e,values:r,w:a,h:c,colors:o}){const d=r.reduce((x,y)=>x+y,0)||1,i=a/2,u=c/2-20,l=Math.min(a,c)/2-40,n=2*Math.PI*l;let m=0;const p=r.map((x,y)=>{const h=x/d,g=h*n,f={dash:g,offset:m,color:o[y%o.length],label:e[y],pct:h};return m+=g,f});return s.jsxs("g",{children:[p.map((x,y)=>s.jsx("circle",{cx:i,cy:u,r:l,fill:"none",stroke:x.color,strokeWidth:l*.6,strokeDasharray:`${x.dash} ${n-x.dash}`,strokeDashoffset:-x.offset,transform:`rotate(-90 ${i} ${u})`},y)),s.jsx("g",{transform:`translate(${i-e.length*30}, ${c-20})`,children:p.slice(0,6).map((x,y)=>s.jsxs("g",{transform:`translate(${y*60}, 0)`,children:[s.jsx("rect",{width:10,height:10,fill:x.color,rx:2}),s.jsx("text",{x:14,y:9,fontSize:9,fill:"#666",children:x.label.length>6?x.label.slice(0,6)+"..":x.label})]},y))})]})}function Z({type:e,data:r,title:a,width:c=400,height:o=300,appearance:d}){const{appearance:i}=w(),u=d??i,l=t.useMemo(()=>ks(r.labels.length),[r.labels.length]);return s.jsx(P,{appearance:u,children:s.jsxs("div",{className:"ss-chart-container",children:[a&&s.jsx("h3",{className:"ss-chart-title",children:a}),s.jsxs("svg",{viewBox:`0 0 ${c} ${o}`,width:"100%",style:{maxWidth:c},children:[e==="bar"&&s.jsx(Cs,{labels:r.labels,values:r.values,w:c,h:o,colors:l}),e==="line"&&s.jsx($s,{labels:r.labels,values:r.values,w:c,h:o,colors:l}),e==="pie"&&s.jsx(Es,{labels:r.labels,values:r.values,w:c,h:o,colors:l})]})]})})}function Ps({dashboardId:e,embedToken:r,baseUrl:a,refreshInterval:c,appearance:o}){const d=w(),i=o??(d==null?void 0:d.appearance),u=t.useMemo(()=>{if(r){const b=a??"https://api.saas-support.com/v1",j=new L.Transport(b,{type:"embedToken",token:r});return new L.ReportClient(j)}return d.client.report},[r,a,d]),[l,n]=t.useState([]),[m,p]=t.useState({}),[x,y]=t.useState(!0),[h,g]=t.useState(null),f=t.useCallback(async()=>{y(!0),g(null);try{const b=await u.getDashboard(e),j=JSON.parse(b.layoutJson||"[]");n(j);const v={};for(const N of j)try{const k=await u.listQueries({search:N.queryId,perPage:1});if(k.data.length>0&&k.data[0].generatedSql){const T=await u.executeQuery({sql:k.data[0].generatedSql});v[N.queryId]=T}}catch{}p(v)}catch(b){g(b instanceof Error?b.message:"Failed to load dashboard")}finally{y(!1)}},[u,e]);return t.useEffect(()=>{f()},[f]),t.useEffect(()=>{if(!c||c<=0)return;const b=setInterval(f,c*1e3);return()=>clearInterval(b)},[c,f]),s.jsx(P,{appearance:i,children:s.jsxs("div",{className:"ss-dashboard-grid",children:[x&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading dashboard..."]}),h&&s.jsx("div",{className:"ss-global-error",children:h}),!x&&l.map((b,j)=>{const v=m[b.queryId];if(!v)return null;const N=v.columns.length>=2?{labels:v.rows.map(k=>String(k[v.columns[0]]??"")),values:v.rows.map(k=>Number(k[v.columns[1]]??0))}:{labels:[],values:[]};return s.jsxs("div",{className:"ss-widget",children:[b.title&&s.jsx("h4",{className:"ss-widget-header",children:b.title}),b.chartType==="table"?s.jsx(X,{columns:v.columns,rows:v.rows,maxRows:50}):s.jsx(Z,{type:b.chartType||"bar",data:N,width:b.w,height:b.h})]},j)})]})})}function Ts(e){return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Is({onSelectQuery:e,onRunQuery:r,appearance:a}){const{appearance:c}=w(),{queries:o,isLoading:d,error:i}=K(),{execute:u,isLoading:l}=U(),n=a??c,m=t.useCallback(async p=>{if(!p.generatedSql)return;const x=await u({sql:p.generatedSql});x&&(r==null||r(x))},[u,r]);return s.jsx(P,{appearance:n,children:s.jsxs("div",{className:"ss-card ss-card-wide",children:[s.jsx("h2",{className:"ss-title",children:"Saved Queries"}),d&&s.jsxs("div",{className:"ss-loading",children:[s.jsx("span",{className:"ss-spinner"})," Loading..."]}),i&&s.jsx("div",{className:"ss-global-error",children:i}),!d&&o.length===0&&s.jsx("p",{className:"ss-empty",children:"No saved queries."}),!d&&o.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:Ts(p.createdAt)}),s.jsx("button",{type:"button",className:"ss-btn ss-btn-sm ss-btn-primary",disabled:l||!p.generatedSql,onClick:x=>{x.stopPropagation(),m(p)},children:l?s.jsx("span",{className:"ss-spinner"}):"Run"})]})]},p.id))]})})}function Ls({embedToken:e,dashboardId:r,baseUrl:a="https://api.saas-support.com/v1",refreshInterval:c,appearance:o}){const d=t.useMemo(()=>{const g=new L.Transport(a,{type:"embedToken",token:e});return new L.ReportClient(g)},[e,a]),[i,u]=t.useState([]),[l,n]=t.useState(!0),[m,p]=t.useState(null),x=t.useMemo(()=>z(o),[o]),y=t.useMemo(()=>q(x),[x]),h=t.useCallback(async()=>{n(!0),p(null);try{const g=await d.getDashboard(r),f=JSON.parse(g.layoutJson||"[]"),b=await Promise.all(f.map(async j=>{try{const v=await d.listQueries({search:j.queryId,perPage:1});if(v.data.length>0&&v.data[0].generatedSql){const N=await d.executeQuery({sql:v.data[0].generatedSql});return{...j,result:N}}}catch{}return j}));u(b)}catch(g){p(g instanceof Error?g.message:"Failed to load dashboard")}finally{n(!1)}},[d,r]);return t.useEffect(()=>{h()},[h]),t.useEffect(()=>{if(!c||c<=0)return;const g=setInterval(h,c*1e3);return()=>clearInterval(g)},[c,h]),s.jsx("div",{ref:g=>{if(!g||g.shadowRoot)return;const f=g.attachShadow({mode:"open"}),b=document.createElement("style");b.textContent=y,f.appendChild(b);const j=document.createElement("div");f.appendChild(j)},style:{display:"contents"},children:s.jsxs("div",{className:"ss-dashboard-grid",children:[l&&s.jsx("div",{className:"ss-loading",children:"Loading dashboard..."}),m&&s.jsx("div",{className:"ss-global-error",children:m}),!l&&i.map((g,f)=>{if(!g.result)return null;const{columns:b,rows:j}=g.result;return s.jsxs("div",{className:"ss-widget",children:[g.title&&s.jsx("h4",{className:"ss-widget-header",children:g.title}),s.jsxs("table",{className:"ss-table",children:[s.jsx("thead",{children:s.jsx("tr",{children:b.map(v=>s.jsx("th",{className:"ss-th",children:v},v))})}),s.jsx("tbody",{children:j.slice(0,50).map((v,N)=>s.jsx("tr",{className:"ss-tr",children:b.map(k=>s.jsx("td",{className:"ss-td",children:String(v[k]??"")},k))},N))})]})]},f)})]})})}exports.SaaSError=L.SaaSError;exports.SaaSSupport=L.SaaSSupport;exports.isMfaRequired=L.isMfaRequired;exports.Chart=Z;exports.CouponInput=js;exports.DashboardView=Ps;exports.DataTable=X;exports.InvoiceHistory=J;exports.OrgSwitcher=us;exports.PaymentPortal=ys;exports.PricingTable=ms;exports.QueryInput=Ss;exports.ReportEmbed=Ls;exports.SaaSContext=D;exports.SaaSProvider=es;exports.SavedQueryList=Is;exports.SignIn=os;exports.SignUp=ls;exports.SubscriptionStatus=V;exports.UsageDisplay=Y;exports.UserButton=is;exports.UserProfile=ds;exports.useAuth=M;exports.useBilling=xs;exports.useDashboard=Ns;exports.useEmbedDashboard=ws;exports.useInvoices=Q;exports.useOrg=O;exports.useProfile=A;exports.useQuery=U;exports.useReport=vs;exports.useSaaSContext=w;exports.useSavedQueries=K;exports.useSignIn=F;exports.useSignUp=R;exports.useSubscription=_;exports.useUsage=G;exports.useUser=ns;
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
@@ -50,6 +50,12 @@ declare class AuthClient {
50
50
  avatarUrl?: string;
51
51
  metadata?: Record<string, unknown>;
52
52
  }): Promise<User>;
53
+ uploadAvatar(imageBlob: Blob): Promise<{
54
+ avatarUrl: string;
55
+ small: string;
56
+ medium: string;
57
+ original: string;
58
+ }>;
53
59
  changePassword(currentPassword: string, newPassword: string): Promise<void>;
54
60
  listOrgs(): Promise<Org[]>;
55
61
  createOrg(name: string, slug: string): Promise<Org>;
@@ -67,6 +73,9 @@ declare class AuthClient {
67
73
  orgId: string;
68
74
  role: string;
69
75
  }>;
76
+ listInvites(orgId: string): Promise<PendingInvite[]>;
77
+ revokeInvite(orgId: string, inviteId: string): Promise<void>;
78
+ deleteAccount(): Promise<void>;
70
79
  /* Excluded from this release type: handleExternalLogout */
71
80
  /* Excluded from this release type: performRefresh */
72
81
  private setSession;
@@ -245,7 +254,7 @@ declare interface FilterRule {
245
254
  value: string;
246
255
  }
247
256
 
248
- declare interface Invite {
257
+ export declare interface Invite {
249
258
  inviteId: string;
250
259
  email: string;
251
260
  role: string;
@@ -287,7 +296,7 @@ declare interface ListParams {
287
296
  search?: string;
288
297
  }
289
298
 
290
- declare interface Member {
299
+ export declare interface Member {
291
300
  userId: string;
292
301
  email: string;
293
302
  role: string;
@@ -319,7 +328,7 @@ declare interface OffsetPage<T> {
319
328
  };
320
329
  }
321
330
 
322
- declare interface Org {
331
+ export declare interface Org {
323
332
  id: string;
324
333
  projectId: string;
325
334
  name: string;
@@ -346,6 +355,14 @@ export declare interface PaymentPortalProps {
346
355
  appearance?: Appearance;
347
356
  }
348
357
 
358
+ export declare interface PendingInvite {
359
+ id: string;
360
+ email: string;
361
+ role: string;
362
+ expiresAt: string;
363
+ createdAt: string;
364
+ }
365
+
349
366
  declare interface Plan {
350
367
  id: string;
351
368
  name: string;
@@ -654,6 +671,8 @@ declare class Transport {
654
671
  post<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
655
672
  patch<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
656
673
  del<T>(path: string, headers?: Record<string, string>): Promise<T>;
674
+ uploadBinary<T>(path: string, data: Blob, headers?: Record<string, string>): Promise<T>;
675
+ private doUploadBinary;
657
676
  private doRequest;
658
677
  private getAuthHeaders;
659
678
  private inferDomain;
@@ -692,6 +711,13 @@ export declare function useDashboard(dashboardId: string): {
692
711
  refresh: () => Promise<void>;
693
712
  };
694
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
+
695
721
  export declare function useEmbedDashboard(embedToken: string, dashboardId: string, baseUrl?: string): {
696
722
  dashboard: Dashboard | null;
697
723
  reportClient: ReportClient;
@@ -711,11 +737,24 @@ export declare function useOrg(): {
711
737
  orgs: Org[];
712
738
  selectedOrg: Org | null;
713
739
  members: Member[];
740
+ invites: PendingInvite[];
714
741
  isLoading: boolean;
715
742
  error: string | null;
743
+ setError: Dispatch<SetStateAction<string | null>>;
716
744
  refresh: () => Promise<void>;
717
745
  selectOrg: (orgId: string) => Promise<void>;
718
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>;
719
758
  };
720
759
 
721
760
  export declare function useProfile(): {
@@ -725,6 +764,12 @@ export declare function useProfile(): {
725
764
  avatarUrl?: string;
726
765
  metadata?: Record<string, unknown>;
727
766
  }) => Promise<User | null>;
767
+ uploadAvatar: (imageBlob: Blob) => Promise<{
768
+ avatarUrl: string;
769
+ small: string;
770
+ medium: string;
771
+ original: string;
772
+ } | null>;
728
773
  changePassword: (currentPassword: string, newPassword: string) => Promise<boolean>;
729
774
  isLoading: boolean;
730
775
  error: string | null;
@@ -751,11 +796,15 @@ export declare interface User {
751
796
  avatarUrl?: string;
752
797
  }
753
798
 
754
- 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;
755
800
 
756
801
  export declare interface UserButtonProps {
757
802
  appearance?: Appearance;
758
803
  afterSignOutUrl?: string;
804
+ afterDeleteAccountUrl?: string;
805
+ showOrgSwitcher?: boolean;
806
+ onOrgChange?: (org: Org) => void;
807
+ onOrgSettingsClick?: (org: Org) => void;
759
808
  }
760
809
 
761
810
  export declare function useReport(): {