@wacht/jsx 0.0.1-alpha.48 → 0.0.1-alpha.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +33 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +262 -259
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*
|
|
16
16
|
* This source code is licensed under the MIT license found in the
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*/var la;function Bd(){return la||(la=1,process.env.NODE_ENV!=="production"&&function(){function t(m,v){return m===v&&(m!==0||1/m===1/v)||m!==m&&v!==v}function r(m,v){d||s.startTransition===void 0||(d=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var b=v();if(!p){var _=v();a(b,_)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),p=!0)}_=h({inst:{value:b,getSnapshot:v}});var k=_[0].inst,C=_[1];return c(function(){k.value=b,k.getSnapshot=v,o(k)&&C({inst:k})},[m,b,v]),g(function(){return o(k)&&C({inst:k}),m(function(){o(k)&&C({inst:k})})},[m]),u(b),b}function o(m){var v=m.getSnapshot;m=m.value;try{var b=v();return!a(m,b)}catch{return!0}}function n(m,v){return v()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var s=i,a=typeof Object.is=="function"?Object.is:t,h=s.useState,g=s.useEffect,c=s.useLayoutEffect,u=s.useDebugValue,d=!1,p=!1,x=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?n:r;vn.useSyncExternalStore=s.useSyncExternalStore!==void 0?s.useSyncExternalStore:x,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),vn}var da;function Ud(){return da||(da=1,process.env.NODE_ENV==="production"?ro.exports=Fd():ro.exports=Bd()),ro.exports}var Wd=Ud();const Sc=0,zc=1,$c=2,ua=3;var pa=Object.prototype.hasOwnProperty;function ss(t,r){var o,n;if(t===r)return!0;if(t&&r&&(o=t.constructor)===r.constructor){if(o===Date)return t.getTime()===r.getTime();if(o===RegExp)return t.toString()===r.toString();if(o===Array){if((n=t.length)===r.length)for(;n--&&ss(t[n],r[n]););return n===-1}if(!o||typeof t=="object"){n=0;for(o in t)if(pa.call(t,o)&&++n&&!pa.call(r,o)||!(o in r)||!ss(t[o],r[o]))return!1;return Object.keys(r).length===n}}return t!==t&&r!==r}const Rt=new WeakMap,Lt=()=>{},rt=Lt(),as=Object,Ee=t=>t===rt,vt=t=>typeof t=="function",Nt=(t,r)=>({...t,...r}),Ec=t=>vt(t.then),bn={},oo={},Is="undefined",Jr=typeof window!=Is,is=typeof document!=Is,Vd=Jr&&"Deno"in window,Gd=()=>Jr&&typeof window.requestAnimationFrame!=Is,Ic=(t,r)=>{const o=Rt.get(t);return[()=>!Ee(r)&&t.get(r)||bn,n=>{if(!Ee(r)){const s=t.get(r);r in oo||(oo[r]=s),o[5](r,Nt(s,n),s||bn)}},o[6],()=>!Ee(r)&&r in oo?oo[r]:!Ee(r)&&t.get(r)||bn]};let cs=!0;const Hd=()=>cs,[ls,ds]=Jr&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[Lt,Lt],qd=()=>{const t=is&&document.visibilityState;return Ee(t)||t!=="hidden"},Yd=t=>(is&&document.addEventListener("visibilitychange",t),ls("focus",t),()=>{is&&document.removeEventListener("visibilitychange",t),ds("focus",t)}),Zd=t=>{const r=()=>{cs=!0,t()},o=()=>{cs=!1};return ls("online",r),ls("offline",o),()=>{ds("online",r),ds("offline",o)}},Kd={isOnline:Hd,isVisible:qd},Qd={initFocus:Yd,initReconnect:Zd},ha=!i.useId,Zr=!Jr||Vd,Jd=t=>Gd()?window.requestAnimationFrame(t):setTimeout(t,1),yn=Zr?i.useEffect:i.useLayoutEffect,wn=typeof navigator<"u"&&navigator.connection,fa=!Zr&&wn&&(["slow-2g","2g"].includes(wn.effectiveType)||wn.saveData),no=new WeakMap,Xd=t=>as.prototype.toString.call(t),jn=(t,r)=>t===`[object ${r}]`;let eu=0;const us=t=>{const r=typeof t,o=Xd(t),n=jn(o,"Date"),s=jn(o,"RegExp"),a=jn(o,"Object");let h,g;if(as(t)===t&&!n&&!s){if(h=no.get(t),h)return h;if(h=++eu+"~",no.set(t,h),Array.isArray(t)){for(h="@",g=0;g<t.length;g++)h+=us(t[g])+",";no.set(t,h)}if(a){h="#";const c=as.keys(t).sort();for(;!Ee(g=c.pop());)Ee(t[g])||(h+=g+":"+us(t[g])+",");no.set(t,h)}}else h=n?t.toJSON():r=="symbol"?t.toString():r=="string"?JSON.stringify(t):""+t;return h},Ps=t=>{if(vt(t))try{t=t()}catch{t=""}const r=t;return t=typeof t=="string"?t:(Array.isArray(t)?t.length:t)?us(t):"",[t,r]};let tu=0;const ps=()=>++tu;async function Pc(...t){const[r,o,n,s]=t,a=Nt({populateCache:!0,throwOnError:!0},typeof s=="boolean"?{revalidate:s}:s||{});let h=a.populateCache;const g=a.rollbackOnError;let c=a.optimisticData;const u=x=>typeof g=="function"?g(x):g!==!1,d=a.throwOnError;if(vt(o)){const x=o,m=[],v=r.keys();for(const b of v)!/^\$(inf|sub)\$/.test(b)&&x(r.get(b)._k)&&m.push(b);return Promise.all(m.map(p))}return p(o);async function p(x){const[m]=Ps(x);if(!m)return;const[v,b]=Ic(r,m),[_,k,C,z]=Rt.get(r),E=()=>{const P=_[m];return(vt(a.revalidate)?a.revalidate(v().data,x):a.revalidate!==!1)&&(delete C[m],delete z[m],P&&P[0])?P[0]($c).then(()=>v().data):v().data};if(t.length<3)return E();let w=n,y,f=!1;const $=ps();k[m]=[$,0];const S=!Ee(c),j=v(),T=j.data,R=j._c,O=Ee(R)?T:R;if(S&&(c=vt(c)?c(O,T):c,b({data:c,_c:O})),vt(w))try{w=w(O)}catch(P){y=P,f=!0}if(w&&Ec(w))if(w=await w.catch(P=>{y=P,f=!0}),$!==k[m][0]){if(f)throw y;return w}else f&&S&&u(y)&&(h=!0,b({data:O,_c:rt}));if(h&&!f)if(vt(h)){const P=h(w,O);b({data:P,error:rt,_c:rt})}else b({data:w,error:rt,_c:rt});if(k[m][1]=ps(),Promise.resolve(E()).then(()=>{b({_c:rt})}),f){if(d)throw y;return}return w}}const ga=(t,r)=>{for(const o in t)t[o][0]&&t[o][0](r)},ru=(t,r)=>{if(!Rt.has(t)){const o=Nt(Qd,r),n=Object.create(null),s=Pc.bind(rt,t);let a=Lt;const h=Object.create(null),g=(d,p)=>{const x=h[d]||[];return h[d]=x,x.push(p),()=>x.splice(x.indexOf(p),1)},c=(d,p,x)=>{t.set(d,p);const m=h[d];if(m)for(const v of m)v(p,x)},u=()=>{if(!Rt.has(t)&&(Rt.set(t,[n,Object.create(null),Object.create(null),Object.create(null),s,c,g]),!Zr)){const d=o.initFocus(setTimeout.bind(rt,ga.bind(rt,n,Sc))),p=o.initReconnect(setTimeout.bind(rt,ga.bind(rt,n,zc)));a=()=>{d&&d(),p&&p(),Rt.delete(t)}}};return u(),[t,s,u,a]}return[t,Rt.get(t)[4]]},ou=(t,r,o,n,s)=>{const a=o.errorRetryCount,h=s.retryCount,g=~~((Math.random()+.5)*(1<<(h<8?h:8)))*o.errorRetryInterval;!Ee(a)&&h>a||setTimeout(n,g,s)},nu=ss,[Rc,Wr]=ru(new Map),su=Nt({onLoadingSlow:Lt,onSuccess:Lt,onError:Lt,onErrorRetry:ou,onDiscarded:Lt,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:fa?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:fa?5e3:3e3,compare:nu,isPaused:()=>!1,cache:Rc,mutate:Wr,fallback:{}},Kd),au=(t,r)=>{const o=Nt(t,r);if(r){const{use:n,fallback:s}=t,{use:a,fallback:h}=r;n&&a&&(o.use=n.concat(a)),s&&h&&(o.fallback=Nt(s,h))}return o},iu=i.createContext({}),cu="$inf$",Tc=Jr&&window.__SWR_DEVTOOLS_USE__,lu=Tc?window.__SWR_DEVTOOLS_USE__:[],du=()=>{Tc&&(window.__SWR_DEVTOOLS_REACT__=i)},uu=t=>vt(t[1])?[t[0],t[1],t[2]||{}]:[t[0],null,(t[1]===null?t[2]:t[1])||{}],Mc=()=>Nt(su,i.useContext(iu)),pu=t=>(r,o,n)=>t(r,o&&((...a)=>{const[h]=Ps(r),[,,,g]=Rt.get(Rc);if(h.startsWith(cu))return o(...a);const c=g[h];return Ee(c)?o(...a):(delete g[h],c)}),n),hu=lu.concat(pu),fu=t=>function(...o){const n=Mc(),[s,a,h]=uu(o),g=au(n,h);let c=t;const{use:u}=g,d=(u||[]).concat(hu);for(let p=d.length;p--;)c=d[p](c);return c(s,a||g.fetcher||null,g)},gu=(t,r,o)=>{const n=r[t]||(r[t]=[]);return n.push(o),()=>{const s=n.indexOf(o);s>=0&&(n[s]=n[n.length-1],n.pop())}};du();const _n=i.use||(t=>{switch(t.status){case"pending":throw t;case"fulfilled":return t.value;case"rejected":throw t.reason;default:throw t.status="pending",t.then(r=>{t.status="fulfilled",t.value=r},r=>{t.status="rejected",t.reason=r}),t}}),kn={dedupe:!0},mu=(t,r,o)=>{const{cache:n,compare:s,suspense:a,fallbackData:h,revalidateOnMount:g,revalidateIfStale:c,refreshInterval:u,refreshWhenHidden:d,refreshWhenOffline:p,keepPreviousData:x}=o,[m,v,b,_]=Rt.get(n),[k,C]=Ps(t),z=i.useRef(!1),E=i.useRef(!1),w=i.useRef(k),y=i.useRef(r),f=i.useRef(o),$=()=>f.current,S=()=>$().isVisible()&&$().isOnline(),[j,T,R,O]=Ic(n,k),P=i.useRef({}).current,M=Ee(h)?Ee(o.fallback)?rt:o.fallback[k]:h,N=(pe,U)=>{for(const ce in P){const Q=ce;if(Q==="data"){if(!s(pe[Q],U[Q])&&(!Ee(pe[Q])||!s(V,U[Q])))return!1}else if(U[Q]!==pe[Q])return!1}return!0},D=i.useMemo(()=>{const pe=!k||!r?!1:Ee(g)?$().isPaused()||a?!1:c!==!1:g,U=le=>{const ee=Nt(le);return delete ee._k,pe?{isValidating:!0,isLoading:!0,...ee}:ee},ce=j(),Q=O(),Z=U(ce),ne=ce===Q?Z:U(Q);let me=Z;return[()=>{const le=U(j());return N(le,me)?(me.data=le.data,me.isLoading=le.isLoading,me.isValidating=le.isValidating,me.error=le.error,me):(me=le,le)},()=>ne]},[n,k]),L=Wd.useSyncExternalStore(i.useCallback(pe=>R(k,(U,ce)=>{N(ce,U)||pe()}),[n,k]),D[0],D[1]),I=!z.current,A=m[k]&&m[k].length>0,q=L.data,Y=Ee(q)?M&&Ec(M)?_n(M):M:q,B=L.error,H=i.useRef(Y),V=x?Ee(q)?Ee(H.current)?Y:H.current:q:Y,J=A&&!Ee(B)?!1:I&&!Ee(g)?g:$().isPaused()?!1:a?Ee(Y)?!1:c:Ee(Y)||c,oe=!!(k&&r&&I&&J),re=Ee(L.isValidating)?oe:L.isValidating,fe=Ee(L.isLoading)?oe:L.isLoading,X=i.useCallback(async pe=>{const U=y.current;if(!k||!U||E.current||$().isPaused())return!1;let ce,Q,Z=!0;const ne=pe||{},me=!b[k]||!ne.dedupe,le=()=>ha?!E.current&&k===w.current&&z.current:k===w.current,ee={isValidating:!1,isLoading:!1},W=()=>{T(ee)},F=()=>{const be=b[k];be&&be[1]===Q&&delete b[k]},se={isValidating:!0};Ee(j().data)&&(se.isLoading=!0);try{if(me&&(T(se),o.loadingTimeout&&Ee(j().data)&&setTimeout(()=>{Z&&le()&&$().onLoadingSlow(k,o)},o.loadingTimeout),b[k]=[U(C),ps()]),[ce,Q]=b[k],ce=await ce,me&&setTimeout(F,o.dedupingInterval),!b[k]||b[k][1]!==Q)return me&&le()&&$().onDiscarded(k),!1;ee.error=rt;const be=v[k];if(!Ee(be)&&(Q<=be[0]||Q<=be[1]||be[1]===0))return W(),me&&le()&&$().onDiscarded(k),!1;const Oe=j().data;ee.data=s(Oe,ce)?Oe:ce,me&&le()&&$().onSuccess(ce,k,o)}catch(be){F();const Oe=$(),{shouldRetryOnError:Fe}=Oe;Oe.isPaused()||(ee.error=be,me&&le()&&(Oe.onError(be,k,Oe),(Fe===!0||vt(Fe)&&Fe(be))&&(!$().revalidateOnFocus||!$().revalidateOnReconnect||S())&&Oe.onErrorRetry(be,k,Oe,Se=>{const Ve=m[k];Ve&&Ve[0]&&Ve[0](ua,Se)},{retryCount:(ne.retryCount||0)+1,dedupe:!0})))}return Z=!1,W(),!0},[k,n]),ue=i.useCallback((...pe)=>Pc(n,w.current,...pe),[]);if(yn(()=>{y.current=r,f.current=o,Ee(q)||(H.current=q)}),yn(()=>{if(!k)return;const pe=X.bind(rt,kn);let U=0;$().revalidateOnFocus&&(U=Date.now()+$().focusThrottleInterval);const Q=gu(k,m,(Z,ne={})=>{if(Z==Sc){const me=Date.now();$().revalidateOnFocus&&me>U&&S()&&(U=me+$().focusThrottleInterval,pe())}else if(Z==zc)$().revalidateOnReconnect&&S()&&pe();else{if(Z==$c)return X();if(Z==ua)return X(ne)}});return E.current=!1,w.current=k,z.current=!0,T({_k:C}),J&&(b[k]||(Ee(Y)||Zr?pe():Jd(pe))),()=>{E.current=!0,Q()}},[k]),yn(()=>{let pe;function U(){const Q=vt(u)?u(j().data):u;Q&&pe!==-1&&(pe=setTimeout(ce,Q))}function ce(){!j().error&&(d||$().isVisible())&&(p||$().isOnline())?X(kn).then(U):U()}return U(),()=>{pe&&(clearTimeout(pe),pe=-1)}},[u,d,p,k]),i.useDebugValue(V),a&&Ee(Y)&&k){if(!ha&&Zr)throw new Error("Fallback data is required when using Suspense in SSR.");y.current=r,f.current=o,E.current=!1;const pe=_[k];if(!Ee(pe)){const U=ue(pe);_n(U)}if(Ee(B)){const U=X(kn);Ee(V)||(U.status="fulfilled",U.value=!0),_n(U)}else throw B}return{mutate:ue,get data(){return P.data=!0,V},get error(){return P.error=!0,B},get isValidating(){return P.isValidating=!0,re},get isLoading(){return P.isLoading=!0,fe}}},Ye=fu(mu);async function G(t){if(!t.ok){let o=`HTTP ${t.status}: ${t.statusText}`;try{const n=await t.json();n.message?o=n.message:n.errors&&n.errors.length>0&&(o=n.errors[0].message||o)}catch{}throw new Error(o)}return{data:(await t.json()).data}}function Oc(t){const{client:r}=Ze(),o=i.useCallback(async()=>{const c=await r(`/api/agent/contexts?token=${encodeURIComponent(t)}`,{method:"GET"});return(await G(c)).data},[r,t]),{data:n,error:s,mutate:a}=Ye(t?`wacht-agent-sessions:${t}`:null,o,{revalidateOnFocus:!1}),h=i.useCallback(async c=>{const u=new FormData;u.append("title",c.title),c.system_instructions&&u.append("system_instructions",c.system_instructions);const d=await r(`/api/agent/contexts?token=${encodeURIComponent(t)}`,{method:"POST",body:u}),p=await G(d);return await a(x=>x&&{...x,data:[p.data,...x.data]}),p.data},[r,t,a]),g=i.useCallback(async c=>{await r(`/api/agent/contexts/${c}/delete?token=${encodeURIComponent(t)}`,{method:"POST"}),await a(u=>u&&{...u,data:u.data.filter(d=>d.id!==c)})},[r,t,a]);return{sessions:(n==null?void 0:n.data)||[],loading:!n&&!s,error:s,createSession:h,deleteSession:g,refetch:async()=>{await a()}}}const Ac=i.createContext(void 0);function Xo(){const t=i.useContext(Ac);if(!t)throw new Error("useAgentConversationContext must be used within AgentConversationProvider");return t}function xu({children:t,agentName:r,token:o,platformAdapter:n,defaultSessionId:s,onSessionCreated:a,onSessionDeleted:h,onError:g}){const[c,u]=i.useState(s?{id:s,title:"Conversation",status:"idle",last_activity_at:new Date().toISOString(),created_at:new Date().toISOString()}:null),[d,p]=i.useState(!1),{sessions:x,loading:m,error:v,createSession:b,deleteSession:_,refetch:k}=Oc(o);i.useEffect(()=>{if(s&&x.length>0){const y=x.find(f=>f.id===s);y&&u(y)}},[s,x]);const C=i.useCallback(y=>{u(y),p(!1)},[]),z=i.useCallback(async y=>{try{const f=y||`Chat ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`,$=await b({title:f});return u($),a==null||a($),$}catch(f){const $=f instanceof Error?f.message:"Failed to create session";throw g==null||g($),f}},[b,a,g]),E=i.useCallback(async y=>{try{await _(y),(c==null?void 0:c.id)===y&&u(null),h==null||h(y)}catch(f){const $=f instanceof Error?f.message:"Failed to delete session";throw g==null||g($),f}},[_,c,h,g]),w={agentName:r,token:o,platformAdapter:n,sessions:x,selectedSession:c,loadingSessions:m,sessionError:v,selectSession:C,createSession:z,deleteSession:E,refreshSessions:k,showHistory:d,setShowHistory:p,onSessionCreated:a,onSessionDeleted:h,onError:g};return e.jsx(Ac.Provider,{value:w,children:t})}var Lc=(t=>(t.XOauth="x_oauth",t.GithubOauth="github_oauth",t.GitlabOauth="gitlab_oauth",t.GoogleOauth="google_oauth",t.FacebookOauth="facebook_oauth",t.MicrosoftOauth="microsoft_oauth",t.LinkedinOauth="linkedin_oauth",t.DiscordOauth="discord_oauth",t.AppleOauth="apple_oauth",t))(Lc||{});function vu(t,r){const o={username:bu(t,r),email:yu(t,r),phone:wu(t,r),email_otp:ju(t,r),magic_link:_u(t,r),oauth:ku(t),passkey:Cu(t),generic:Su(t,r)};return function(s){return o[s]}}function bu(t,r){return async({username:o,password:n})=>{var g,c;const s=new FormData;s.append("strategy","plain_username"),s.append("username",o),s.append("password",n);const a=await t("/auth/signin",{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signin_attempts)!=null&&c.length)&&r(h.data.signin_attempts.at(-1)||null),h}}function yu(t,r){return async({email:o,password:n})=>{var g,c;const s=new FormData;s.append("strategy","plain_email"),s.append("email",o),s.append("password",n);const a=await t("/auth/signin",{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signin_attempts)!=null&&c.length)&&r(h.data.signin_attempts.at(-1)||null),h}}function wu(t,r){return async({phone:o})=>{var h,g;const n=new FormData;n.append("strategy","phone_otp"),n.append("phone",o);const s=await t("/auth/signin",{method:"POST",body:n}),a=await G(s);return"data"in a&&((g=(h=a.data)==null?void 0:h.signin_attempts)!=null&&g.length)&&r(a.data.signin_attempts.at(-1)||null),a}}function ju(t,r){return async({email:o})=>{var h,g;const n=new FormData;n.append("strategy","email_otp"),n.append("email",o);const s=await t("/auth/signin",{method:"POST",body:n}),a=await G(s);return"data"in a&&((g=(h=a.data)==null?void 0:h.signin_attempts)!=null&&g.length)&&r(a.data.signin_attempts.at(-1)||null),a}}function _u(t,r){return async({email:o})=>{var h,g;const n=new FormData;n.append("strategy","magic_link"),n.append("email",o);const s=await t("/auth/signin",{method:"POST",body:n}),a=await G(s);return"data"in a&&((g=(h=a.data)==null?void 0:h.signin_attempts)!=null&&g.length)&&r(a.data.signin_attempts.at(-1)||null),a}}function ku(t){return async({provider:r,redirectUri:o})=>{const n=new URLSearchParams({provider:r});o&&n.append("redirect_uri",o);const s=await t(`/auth/oauth2/init?${n.toString()}`,{method:"POST"}),a=await G(s);return"data"in a&&a.data.oauth_url&&(window.location.href=a.data.oauth_url),a}}function Ar(t){const r=new Uint8Array(t);let o="";for(let n=0;n<r.length;n++)o+=String.fromCharCode(r[n]);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function ma(t){const r=t.replace(/-/g,"+").replace(/_/g,"/"),o=r.padEnd(r.length+(4-r.length%4)%4,"="),n=atob(o),s=new Uint8Array(n.length);for(let a=0;a<n.length;a++)s[a]=n.charCodeAt(a);return s.buffer}function Cu(t){return async()=>{var u;const r=await t("/auth/passkey/login/begin",{method:"POST"}),o=await G(r);if(!("data"in o))return o;const n=o.data.options.publicKey,s={challenge:ma(n.challenge),timeout:n.timeout,rpId:n.rpId,userVerification:n.userVerification,allowCredentials:(u=n.allowCredentials)==null?void 0:u.map(d=>({type:d.type,id:ma(d.id),transports:d.transports}))},a=await navigator.credentials.get({publicKey:s});if(!a)throw new Error("Failed to get credential");const h=a.response,g={id:a.id,rawId:Ar(a.rawId),type:a.type,response:{clientDataJSON:Ar(h.clientDataJSON),authenticatorData:Ar(h.authenticatorData),signature:Ar(h.signature),userHandle:h.userHandle?Ar(h.userHandle):null}},c=await t("/auth/passkey/login/finish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});return G(c)}}function Su(t,r){return async({email:o,username:n,password:s,phone:a,strategy:h,token:g})=>{var p,x;const c=new FormData;h&&c.append("strategy",h),o&&c.append("email",o),n&&c.append("username",n),s&&c.append("password",s),a&&c.append("phone",a),g&&c.append("token",g);const u=await t("/auth/signin",{method:"POST",body:c}),d=await G(u);return"data"in d&&((x=(p=d.data)==null?void 0:p.signin_attempts)!=null&&x.length)&&r(d.data.signin_attempts.at(-1)||null),d}}function Dc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(null);return r?{loading:!0,signIn:null,signinAttempt:null,discardSignInAttempt:()=>{n(null)},setSignInAttempt:n}:{loading:!1,signinAttempt:o,signIn:{createStrategy:vu(t,n),completeVerification:async s=>{var c,u;const a=new FormData;a.append("verification_code",s);const h=await t(`/auth/attempt-verification?attempt_identifier=${o==null?void 0:o.id}&identifier_type=signin`,{method:"POST",body:a}),g=await G(h);if("data"in g&&((u=(c=g.data)==null?void 0:c.signin_attempts)!=null&&u.length)){const d=g.data.signin_attempts.at(-1);return n(d||null),g.data}else throw new Error("Verification failed")},prepareVerification:async s=>{var g;const a=new URL("/auth/prepare-verification",window.location.origin);a.searchParams.set("attempt_identifier",((g=o==null?void 0:o.id)==null?void 0:g.toString())||""),a.searchParams.set("strategy",s.strategy),a.searchParams.set("identifier_type","signin"),s.strategy==="phone_otp"&&s.lastDigits?a.searchParams.set("last_digits",s.lastDigits):(s.strategy==="email_otp"&&s.redirectUri||s.strategy==="magic_link"&&s.redirectUri)&&a.searchParams.set("redirect_uri",s.redirectUri);const h=await t(a.pathname+a.search,{method:"POST"});return G(h)},completeProfile:async s=>{var c;if(!o)throw new Error("No signin attempt found");const a=new FormData;for(const[u,d]of Object.entries(s))d&&a.append(u,d);const h=await t(`/auth/complete-profile?attempt_id=${o.id}`,{method:"POST",body:a}),g=await G(h);if("data"in g&&g.data){const u=(c=g.data.signin_attempts)==null?void 0:c.find(d=>d.id===o.id);return u&&n(u),g.data}else throw new Error("Profile completion failed")},identify:async s=>{const a=new FormData;a.append("identifier",s);const h=await t("/auth/identify",{method:"POST",body:a});return(await G(h)).data},initEnterpriseSso:async(s,a)=>{const h=new URLSearchParams({connection_id:s});a&&h.append("redirect_uri",a);const g=await t(`/auth/sso/login?${h.toString()}`,{method:"POST"});return(await G(g)).data}},discardSignInAttempt:()=>{n(null)},setSignInAttempt:n}}function Sr(t){const{loading:r,signIn:o,signinAttempt:n,discardSignInAttempt:s,setSignInAttempt:a}=Dc();if(r)return{loading:!0,signIn:null,signinAttempt:null,discardSignInAttempt:s,setSignInAttempt:a};const h=(()=>{switch(t){case"username":return o.createStrategy("username");case"email":return o.createStrategy("email");case"phone":return o.createStrategy("phone");case"email_otp":return o.createStrategy("email_otp");case"magic_link":return o.createStrategy("magic_link");case"oauth":return o.createStrategy("oauth");case"passkey":return o.createStrategy("passkey");case"generic":return o.createStrategy("generic");default:throw new Error("Invalid sign-in strategy")}})();return{loading:!1,signinAttempt:n,signIn:{create:h,completeVerification:o.completeVerification,prepareVerification:o.prepareVerification,completeProfile:o.completeProfile,identify:o.identify,initEnterpriseSso:o.initEnterpriseSso},discardSignInAttempt:s,setSignInAttempt:a}}function zu(t,r,o){return{create:async n=>{var g,c,u;const s=new FormData;for(const[d,p]of Object.entries(n))s.append(d,p);const a=await t("/auth/signup",{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signup_attempts)!=null&&c.length)&&o(((u=h.data.signup_attempts)==null?void 0:u.at(-1))||null),h},prepareVerification:async n=>{var h;const s=new URL("/auth/prepare-verification",window.location.origin);s.searchParams.set("attempt_identifier",((h=r==null?void 0:r.id)==null?void 0:h.toString())||""),s.searchParams.set("strategy",n.strategy),s.searchParams.set("identifier_type","signup"),n.strategy==="phone_otp"&&n.lastDigits?s.searchParams.set("last_digits",n.lastDigits):n.strategy==="email_otp"&&n.redirectUri&&s.searchParams.set("redirect_uri",n.redirectUri);const a=await t(s.pathname+s.search,{method:"POST"});return G(a)},completeVerification:async n=>{var g,c;const s=new FormData;s.append("verification_code",n);const a=await t(`/auth/attempt-verification?attempt_identifier=${r==null?void 0:r.id}&identifier_type=signup`,{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signup_attempts)!=null&&c.length)&&o(h.data.signup_attempts.at(-1)||null),h},validateDeploymentInvitation:async n=>{try{const s=await t(`/deployment/invitations/validate?token=${encodeURIComponent(n)}`,{method:"GET"}),a=await G(s);return"data"in a&&a.data?a.data:{valid:!1,message:"Failed to validate invitation",error_code:"VALIDATION_ERROR"}}catch(s){return{valid:!1,message:s.message||"Failed to validate invitation",error_code:"NETWORK_ERROR"}}}}}function Nc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(null);return r?{loading:!0,signUp:null,signupAttempt:null,discardSignupAttempt:()=>{n(null)}}:{loading:!1,signupAttempt:o,discardSignupAttempt:()=>{n(null)},signUp:zu(t,o,n)}}const tt=()=>{const{adapter:t,deployment:r}=ye(),o=t.useNavigate(),n=(c,u)=>{o?o(c,u):window.location.href=c},s=c=>{if(c)return c;const d=new URLSearchParams(window.location.search).get("redirect_uri");return d||window.location.href};return{navigate:n,navigateToSignIn:c=>{if(!r)return;const u=s(c),d=new URLSearchParams;d.set("redirect_uri",u),(r==null?void 0:r.mode)==="staging"&&d.set("__dev_session__",localStorage.getItem("__dev_session__")??""),n(`${r.ui_settings.sign_in_page_url}?${d.toString()}`,{replace:!0})},navigateToAccountSelection:c=>{if(!r)return;const u=s(c),d=new URLSearchParams;d.set("redirect_uri",u),(r==null?void 0:r.mode)==="staging"&&d.set("__dev_session__",localStorage.getItem("__dev_session__")??""),n(`https://${r.frontend_host}?${d.toString()}`,{replace:!0})},navigateToSignUp:c=>{if(!r)return;const u=s(c),d=new URLSearchParams;d.set("redirect_uri",u),(r==null?void 0:r.mode)==="staging"&&d.set("__dev_session__",localStorage.getItem("__dev_session__")??""),n(`${r.ui_settings.sign_up_page_url}?${d.toString()}`,{replace:!0})}}};async function $u(t){const r=await t("/session",{method:"GET"});return(await G(r)).data}async function Eu(t,r){const o=await t(`/session/switch-sign-in?sign_in_id=${r}`,{method:"POST"});return G(o)}async function Iu(t,r){const o=r?`/session/sign-out?sign_in_id=${r}`:"/session/sign-out",n=await t(o,{method:"POST"});return G(n)}async function Pu(t,r){const o=await t(`/session/switch-organization${r?`?organization_id=${r}`:""}`,{method:"POST"});return G(o)}async function Ru(t,r){const o=await t(`/session/switch-workspace?workspace_id=${r}`,{method:"POST"});return G(o)}const hs=new Map,Vr=new Map;function Tt(){hs.clear(),Vr.clear()}async function Tu(t,r){const o=await t(`/session/token${r?`?template=${r}`:""}`);return G(o)}function Ke(){const{client:t,loading:r}=Ze(),{deployment:o}=ye(),{navigate:n}=tt(),{cache:s}=Mc(),{data:a,error:h,mutate:g,isLoading:c}=Ye(r?null:"/session",()=>$u(t),{refreshInterval:3e4,revalidateOnFocus:!1,revalidateOnReconnect:!1,revalidateIfStale:!1,dedupingInterval:5e3}),u=i.useCallback(async()=>{await g(void 0,{revalidate:!0})},[g]),d=i.useCallback(async(p="default")=>{if(!a)throw new Error("no session");const x=hs.get(p);if(x&&x.expires>Date.now())return(x==null?void 0:x.token)||"";Vr.get(p)||Vr.set(p,Tu(t,p));const m=await Vr.get(p);return Vr.delete(p),hs.set(p,m.data),m.data.token},[t,a==null?void 0:a.active_signin]);return r||!a||c?{loading:!0,error:h,session:null,switchSignIn:null,switchOrganization:null,switchWorkspace:null,signOut:null,getToken:null,refetch:u}:{loading:c,error:h,session:a,switchSignIn:async p=>{await Eu(t,p),Tt(),await Wr("/me/organization-memberships",void 0,{revalidate:!1}),await Wr("/me/workspace-memberships",void 0,{revalidate:!1}),await g(void 0,{revalidate:!0}),await Wr("/me/organization-memberships"),await Wr("/me/workspace-memberships")},signOut:async p=>{await Iu(t,p);const x=["/session","/user","/me/signins","/me/organization-memberships","/me/workspace-memberships","wacht-notifications:channel-counts"],m=["wacht-notifications:","wacht-agent-sessions:","wacht-agent-contexts:","wacht-org-domains:","wacht-api-workspaces:","wacht-api-organizations:"];if(s instanceof Map){const v=Array.from(s.keys());for(const b of v){let _=!1;(x.includes(b)||typeof b=="string"&&m.some(k=>b.startsWith(k)))&&(_=!0),_&&s.delete(b)}}Tt(),await g(void 0,{revalidate:!0}),o!=null&&o.ui_settings&&(p&&o.ui_settings.after_sign_out_one_page_url?n(o.ui_settings.after_sign_out_one_page_url):!p&&o.ui_settings.after_sign_out_all_page_url&&n(o.ui_settings.after_sign_out_all_page_url))},switchOrganization:async p=>{await Pu(t,p),Tt(),await g(void 0,{revalidate:!0})},switchWorkspace:async p=>{await Ru(t,p),Tt(),await g(void 0,{revalidate:!0})},getToken:d,refetch:u}}const en=()=>{const{organizationMemberships:t,refetch:r,loading:o}=Mt(),{client:n}=Ze(),{refetch:s}=Ke(),a=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/roles`,{method:"GET"}))).data,[n]),h=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/members`,{method:"GET"}))).data,[n]),g=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/invitations`,{method:"GET"}))).data,[n]),c=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/domains`,{method:"GET"}))).data,[n]),u=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/members/${I.id}/remove`,{method:"POST"})},[n]),d=i.useCallback(async L=>{const I=new FormData;I.append("name",L.name),L.image&&I.append("image",L.image),L.description&&I.append("description",L.description);const A=await G(await n("/organizations",{method:"POST",body:I}));return Tt(),await r(),await s(),A},[s,r,n]),p=i.useCallback(async(L,I)=>{const A=Object.entries(I).reduce((Y,[B,H])=>(H&&Y.append(B,H),Y),new FormData),q=await G(await n(`/organizations/${L.id}/update`,{method:"POST",body:A}));return await r(),q},[r,n]),x=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/roles/${I.id}/remove`,{method:"POST"})},[n]),m=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("domain",I.fqdn),await G(await n(`/organizations/${L.id}/domains`,{method:"POST",body:A}))},[n]),v=i.useCallback(async(L,I)=>await G(await n(`/organizations/${L.id}/domains/${I.id}/verify`,{method:"POST"})),[n]),b=i.useCallback(async(L,I)=>await G(await n(`/organizations/${L.id}/domains/${I.id}/delete`,{method:"POST"})),[n]),_=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/enterprise-connections`,{method:"GET"}))).data,[n]),k=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("protocol",I.protocol),I.domain_id&&A.append("domain_id",I.domain_id),I.idp_entity_id&&A.append("idp_entity_id",I.idp_entity_id),I.idp_sso_url&&A.append("idp_sso_url",I.idp_sso_url),I.idp_certificate&&A.append("idp_certificate",I.idp_certificate),I.oidc_client_id&&A.append("oidc_client_id",I.oidc_client_id),I.oidc_client_secret&&A.append("oidc_client_secret",I.oidc_client_secret),I.oidc_issuer_url&&A.append("oidc_issuer_url",I.oidc_issuer_url),I.oidc_scopes&&A.append("oidc_scopes",I.oidc_scopes),I.jit_enabled!==void 0&&A.append("jit_enabled",String(I.jit_enabled)),I.attribute_mapping&&A.append("attribute_mapping",JSON.stringify(I.attribute_mapping)),(await G(await n(`/organizations/${L.id}/enterprise-connections`,{method:"POST",body:A}))).data},[n]),C=i.useCallback(async(L,I,A)=>{const q=new FormData;return A.domain_id&&q.append("domain_id",A.domain_id),A.idp_entity_id&&q.append("idp_entity_id",A.idp_entity_id),A.idp_sso_url&&q.append("idp_sso_url",A.idp_sso_url),A.idp_certificate&&q.append("idp_certificate",A.idp_certificate),A.oidc_client_id&&q.append("oidc_client_id",A.oidc_client_id),A.oidc_client_secret&&q.append("oidc_client_secret",A.oidc_client_secret),A.oidc_issuer_url&&q.append("oidc_issuer_url",A.oidc_issuer_url),A.oidc_scopes&&q.append("oidc_scopes",A.oidc_scopes),A.attribute_mapping&&q.append("attribute_mapping",JSON.stringify(A.attribute_mapping)),(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/update`,{method:"POST",body:q}))).data},[n]),z=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/enterprise-connections/${I}/delete`,{method:"POST"})},[n]),E=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("protocol",I.protocol),I.idp_entity_id&&A.append("idp_entity_id",I.idp_entity_id),I.idp_sso_url&&A.append("idp_sso_url",I.idp_sso_url),I.idp_certificate&&A.append("idp_certificate",I.idp_certificate),I.oidc_issuer_url&&A.append("oidc_issuer_url",I.oidc_issuer_url),I.oidc_client_id&&A.append("oidc_client_id",I.oidc_client_id),I.oidc_client_secret&&A.append("oidc_client_secret",I.oidc_client_secret),(await G(await n(`/organizations/${L.id}/enterprise-connections/test`,{method:"POST",body:A}))).data},[n]),w=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/test`,{method:"POST"}))).data,[n]),y=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/scim/token`,{method:"POST"}))).data,[n]),f=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/scim/token`,{method:"GET"}))).data,[n]),$=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/enterprise-connections/${I}/scim/token/revoke`,{method:"POST"})},[n]),S=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("name",I.name),I.permissions&&I.permissions.forEach((Y,B)=>{A.append(`permissions[${B}]`,Y)}),await G(await n(`/organizations/${L.id}/roles`,{method:"POST",body:A}))},[n]),j=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/leave`,{method:"POST"}))).data,[n]),T=i.useCallback(async L=>{const I=await G(await n(`/organizations/${L.id}/delete`,{method:"POST"}));return Tt(),await r(),await s(),I.data},[n,r,s]),R=i.useCallback(async(L,I,A)=>(await G(await n(`/organizations/${L.id}/members/${I.id}/roles/${A.id}/add`,{method:"POST"}))).data,[n]),O=i.useCallback(async(L,I,A)=>(await G(await n(`/organizations/${L.id}/members/${I.id}/roles/${A.id}/remove`,{method:"POST"}))).data,[n]),P=i.useCallback(async(L,I)=>{var Y,B;const A=new FormData;return A.append("email",I.email),A.append("role_id",I.organizationRole.id),(Y=I.workspace)!=null&&Y.id&&A.append("workspace_id",I.workspace.id),(B=I.workspaceRole)!=null&&B.id&&A.append("workspace_role_id",I.workspaceRole.id),(await G(await n(`/organizations/${L.id}/invitations`,{method:"POST",body:A}))).data},[n]),M=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/invitations/${I.id}/discard`,{method:"POST"}))).data,[n]),N=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/invitations/${I.id}/resend`,{method:"POST"}))).data,[n]);return{organizations:i.useMemo(()=>t==null?void 0:t.map(L=>L.organization),[t]),loading:o,error:null,refetch:r,leaveOrganization:j,getOrganizationRoles:a,getOrganizationMembers:h,removeOrganizationMember:u,createOrganization:d,getOrganizationInvitations:g,getOrganizationDomains:c,addOrganizationDomain:m,verifyOrganizationDomain:v,removeOrganizationDomain:b,addRoleToOrganizationMember:R,removeRoleFromOrganizationMember:O,inviteOrganizationMember:P,discardOrganizationInvitation:M,resendOrganizationInvitation:N,updateOrganization:p,addRole:S,removeOrganizationRoles:x,deleteOrganization:T,getEnterpriseConnections:_,createEnterpriseConnection:k,updateEnterpriseConnection:C,deleteEnterpriseConnection:z,testEnterpriseConnectionConfig:E,testEnterpriseConnection:w,generateSCIMToken:y,getSCIMToken:f,revokeSCIMToken:$}},nt=()=>{const{loading:t,error:r,refetch:o,getOrganizationMembers:n,getOrganizationRoles:s,leaveOrganization:a,removeOrganizationMember:h,getOrganizationInvitations:g,getOrganizationDomains:c,removeOrganizationDomain:u,addOrganizationDomain:d,verifyOrganizationDomain:p,addRoleToOrganizationMember:x,removeRoleFromOrganizationMember:m,inviteOrganizationMember:v,discardOrganizationInvitation:b,resendOrganizationInvitation:_,updateOrganization:k,removeOrganizationRoles:C,getEnterpriseConnections:z,createEnterpriseConnection:E,updateEnterpriseConnection:w,deleteEnterpriseConnection:y,testEnterpriseConnectionConfig:f,testEnterpriseConnection:$,generateSCIMToken:S,getSCIMToken:j,revokeSCIMToken:T}=en(),{session:R,error:O,loading:P}=Ke(),{organizationMemberships:M}=Mt(),N=i.useMemo(()=>(M==null?void 0:M.find(F=>{var se;return F.id===((se=R==null?void 0:R.active_signin)==null?void 0:se.active_organization_membership_id)}))||null,[M,R]),D=i.useMemo(()=>(N==null?void 0:N.organization)||null,[N]),L=i.useCallback(async F=>D?await k(D,F):[],[D,k]),I=i.useCallback(async()=>D?await n(D):[],[D,n]),A=i.useCallback(async()=>D?await s(D):[],[D,s]),q=i.useCallback(async F=>D?await h(D,F):[],[D,h]),Y=i.useCallback(async F=>D?await C(D,F):void 0,[D,C]),B=i.useCallback(async()=>D?await c(D):[],[D,c]),H=i.useCallback(async F=>D?await d(D,F):void 0,[D,d]),V=i.useCallback(async F=>D?await p(D,F):void 0,[D,p]),J=i.useCallback(async F=>D?await u(D,F):void 0,[D,u]),oe=i.useCallback(async(F,se)=>D?await x(D,F,se):void 0,[D,x]),re=i.useCallback(async(F,se)=>D?await m(D,F,se):void 0,[D,m]),fe=i.useCallback(async F=>D?await v(D,F):void 0,[D,v]),X=i.useCallback(async F=>D?await b(D,F):void 0,[D,b]),ue=i.useCallback(async F=>D?await _(D,F):void 0,[D,_]),ve=i.useCallback(async()=>{D&&await a(D)},[D,a]),pe=i.useCallback(async()=>D?await g(D):[],[D,g]),U=i.useCallback(async()=>D?await z(D):[],[D,z]),ce=i.useCallback(async F=>{if(D)return await E(D,F)},[D,E]),Q=i.useCallback(async(F,se)=>{if(D)return await w(D,F,se)},[D,w]),Z=i.useCallback(async F=>{D&&await y(D,F)},[D,y]),ne=i.useCallback(async F=>D?await f(D,F):null,[D,f]),me=i.useCallback(async F=>D?await $(D,F):null,[D,$]),le=i.useCallback(async F=>{if(D)return await S(D,F)},[D,S]),ee=i.useCallback(async F=>{if(D)return await j(D,F)},[D,j]),W=i.useCallback(async F=>{D&&await T(D,F)},[D,T]);return P||t?{activeOrganization:null,activeMembership:null,loading:!0,error:O||r,updateOrganization:null,getRoles:null,getMembers:null,getDomains:null,addDomain:null,verifyDomain:null,removeDomain:null,removeRole:null,getInvitations:null,removeMember:null,addMemberRole:null,removeMemberRole:null,inviteMember:null,discardInvitation:null,resendInvitation:null,leave:null,getEnterpriseConnections:null,createEnterpriseConnection:null,updateEnterpriseConnection:null,deleteEnterpriseConnection:null,generateSCIMToken:null,getSCIMToken:null,revokeSCIMToken:null}:{activeOrganization:D,activeMembership:N,loading:!1,refetch:o,getRoles:A,updateOrganization:L,getMembers:I,getDomains:B,addDomain:H,verifyDomain:V,removeDomain:J,getInvitations:pe,removeMember:q,leave:ve,removeRole:Y,addMemberRole:oe,removeMemberRole:re,inviteMember:fe,discardInvitation:X,resendInvitation:ue,getEnterpriseConnections:U,createEnterpriseConnection:ce,updateEnterpriseConnection:Q,deleteEnterpriseConnection:Z,testEnterpriseConnectionConfig:ne,testEnterpriseConnection:me,generateSCIMToken:le,getSCIMToken:ee,revokeSCIMToken:W,error:null}};async function Mu(t){return(await G(await t("/me/organization-memberships"))).data}const Mt=()=>{const{client:t,loading:r}=Ze(),{data:o,isLoading:n,error:s,mutate:a}=Ye(r?null:"/me/organization-memberships",()=>Mu(t),{refreshInterval:3e4,revalidateOnFocus:!1,revalidateOnReconnect:!1,revalidateIfStale:!1,dedupingInterval:5e3}),h=i.useCallback(async()=>{await a(void 0,{revalidate:!0})},[a]);return{organizationMemberships:o,loading:r||n,error:s,refetch:h}};async function Ou(t){return(await G(await t("/me/workspace-memberships"))).data}async function Au(t,r,o){return(await G(await t(`/workspaces/${r}/members/${o}/remove`,{method:"POST"}))).data}const tn=()=>{const{client:t,loading:r}=Ze(),{deployment:o}=ye(),{data:n,isLoading:s,error:a,mutate:h}=Ye(!r&&(o!=null&&o.b2b_settings.workspaces_enabled)?"/me/workspace-memberships":null,()=>Ou(t),{refreshInterval:3e4,revalidateOnFocus:!1,revalidateOnReconnect:!1,revalidateIfStale:!1,dedupingInterval:5e3}),g=i.useCallback(async()=>{await h(void 0,{revalidate:!0})},[h]);return{workspaceMemberships:n,loading:r||s,error:a,refetch:g}},Bt=()=>{const{workspaceMemberships:t,refetch:r,loading:o,error:n}=tn(),{client:s}=Ze(),a=i.useMemo(()=>t==null?void 0:t.map(w=>({...w.workspace,organization:w.organization,eligibility_restriction:w.eligibility_restriction})),[t]),h=i.useCallback(async(w,y,f,$)=>{const S=new FormData;S.append("name",y),f&&S.append("image",f),$&&S.append("description",$),S.append("organization_id",w);const j=await G(await s("/workspaces",{method:"POST",body:S}));return Tt(),await r(),j.data},[s,r]),g=i.useCallback(async(w,y)=>{const f=await Au(s,w,y);return await r(),f},[s,r]),c=i.useCallback(async(w,y)=>{const f=new FormData;y.name&&f.append("name",y.name),y.description&&f.append("description",y.description),y.image&&f.append("image",y.image),y.enforce_2fa!==void 0&&f.append("enforce_2fa",String(y.enforce_2fa)),y.enable_ip_restriction!==void 0&&f.append("enable_ip_restriction",String(y.enable_ip_restriction)),y.whitelisted_ips&&y.whitelisted_ips.forEach(S=>f.append("whitelisted_ips",S));const $=await G(await s(`/workspaces/${w.id}/update`,{method:"POST",body:f}));return await r(),$.data},[s,r]),u=i.useCallback(async w=>{const y=await G(await s(`/workspaces/${w.id}/delete`,{method:"POST"}));return Tt(),await r(),y.data},[s,r]),d=i.useCallback(async w=>(await G(await s(`/workspaces/${w.id}/members`,{method:"GET"}))).data,[s]),p=i.useCallback(async w=>(await G(await s(`/workspaces/${w.id}/roles`,{method:"GET"}))).data,[s]),x=i.useCallback(async(w,y,f)=>{const $=new FormData;return $.append("name",y),f.forEach(j=>$.append("permissions",j)),(await G(await s(`/workspaces/${w.id}/roles`,{method:"POST",body:$}))).data},[s]),m=i.useCallback(async(w,y)=>(await G(await s(`/workspaces/${w.id}/roles/${y.id}/delete`,{method:"POST"}))).data,[s]),v=i.useCallback(async(w,y)=>{const f=await G(await s(`/workspaces/${w.id}/members/${y}/remove`,{method:"POST"}));return await r(),f.data},[s,r]),b=i.useCallback(async(w,y,f)=>(await G(await s(`/workspaces/${w.id}/members/${y}/roles/${f}/add`,{method:"POST"}))).data,[s]),_=i.useCallback(async(w,y,f)=>(await G(await s(`/workspaces/${w.id}/members/${y}/roles/${f}/remove`,{method:"POST"}))).data,[s]),k=i.useCallback(async w=>(await G(await s(`/organizations/${w.organization.id}/invitations`,{method:"GET"}))).data.filter(f=>String(f.workspace_id)===String(w.id)),[s]),C=i.useCallback(async(w,y,f)=>{const $=new FormData;return $.append("email",y),$.append("workspace_id",w.id),f&&$.append("workspace_role_id",f),(await G(await s(`/organizations/${w.organization.id}/invitations`,{method:"POST",body:$}))).data},[s]),z=i.useCallback(async(w,y)=>(await G(await s(`/organizations/${w.organization.id}/invitations/${y}/discard`,{method:"POST"}))).data,[s]),E=i.useCallback(async(w,y)=>(await G(await s(`/organizations/${w.organization.id}/invitations/${y}/resend`,{method:"POST"}))).data,[s]);return{workspaces:a||[],loading:o,error:n,refetch:r,leaveWorkspace:g,createWorkspace:h,updateWorkspace:c,deleteWorkspace:u,getWorkspaceMembers:d,getWorkspaceRoles:p,createWorkspaceRole:x,deleteWorkspaceRole:m,removeWorkspaceMember:v,addWorkspaceMemberRole:b,removeWorkspaceMemberRole:_,getWorkspaceInvitations:k,createWorkspaceInvitation:C,discardWorkspaceInvitation:z,resendWorkspaceInvitation:E}},Ut=()=>{const{refetch:t,loading:r,error:o,workspaces:n,leaveWorkspace:s,updateWorkspace:a,deleteWorkspace:h,getWorkspaceMembers:g,getWorkspaceRoles:c,createWorkspaceRole:u,deleteWorkspaceRole:d,removeWorkspaceMember:p,addWorkspaceMemberRole:x,removeWorkspaceMemberRole:m,getWorkspaceInvitations:v,createWorkspaceInvitation:b,discardWorkspaceInvitation:_,resendWorkspaceInvitation:k}=Bt(),{workspaceMemberships:C}=tn(),{session:z,loading:E,error:w}=Ke(),y=i.useMemo(()=>(C==null?void 0:C.find(V=>{var J;return V.id===((J=z==null?void 0:z.active_signin)==null?void 0:J.active_workspace_membership_id)}))||null,[C,z]),f=i.useMemo(()=>(y==null?void 0:y.workspace)||null,[y]),$=i.useCallback(async()=>{var V;if(!(!f||!((V=z==null?void 0:z.active_signin)!=null&&V.user_id)))return await s(f.id,z.active_signin.user_id)},[f,s,z]),S=i.useCallback(async V=>{if(f)return await a(f,V)},[f,a]),j=i.useCallback(async()=>{if(f)return await h(f)},[f,h]),T=i.useCallback(async()=>f?await g(f):[],[f,g]),R=i.useCallback(async()=>f?await c(f):[],[f,c]),O=i.useCallback(async(V,J)=>{if(f)return await u(f,V,J)},[f,u]),P=i.useCallback(async V=>{if(f)return await d(f,V)},[f,d]),M=i.useCallback(async V=>{if(f)return await p(f,V)},[f,p]),N=i.useCallback(async(V,J)=>{if(f)return await x(f,V,J)},[f,x]),D=i.useCallback(async(V,J)=>{if(f)return await m(f,V,J)},[f,m]),L=i.useMemo(()=>(n==null?void 0:n.find(V=>V.id===(f==null?void 0:f.id)))||null,[n,f]),I=i.useCallback(async()=>L?await v(L):[],[L,v]),A=i.useCallback(async(V,J)=>{if(L)return await b(L,V,J)},[L,b]),q=i.useCallback(async V=>{if(L)return await _(L,V)},[L,_]),Y=i.useCallback(async V=>{if(L)return await k(L,V)},[L,k]),B=r||E,H=o||w;return B?{activeWorkspace:null,activeMembership:null,loading:!0,error:H,refetch:t,leave:null,updateWorkspace:null,deleteWorkspace:null,getMembers:null,getRoles:null,createRole:null,deleteRole:null,inviteMember:null,removeMember:null,addMemberRole:null,removeMemberRole:null,getInvitations:null,discardInvitation:null,resendInvitation:null}:{activeWorkspace:f,activeMembership:y,loading:!1,error:H,refetch:t,leave:$,updateWorkspace:S,deleteWorkspace:j,getMembers:T,getRoles:R,createRole:O,deleteRole:P,inviteMember:A,removeMember:M,addMemberRole:N,removeMemberRole:D,getInvitations:I,discardInvitation:q,resendInvitation:Y}};function Cn(t){const r=new Uint8Array(t);let o="";for(let n=0;n<r.length;n++)o+=String.fromCharCode(r[n]);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Sn(t){const r=t.replace(/-/g,"+").replace(/_/g,"/"),o=r.padEnd(r.length+(4-r.length%4)%4,"="),n=atob(o),s=new Uint8Array(n.length);for(let a=0;a<n.length;a++)s[a]=n.charCodeAt(a);return s.buffer}const Lu=async t=>(await G(await t("/me"))).data,Du=async t=>(await G(await t("/me/signins"))).data;function Wt(){const{client:t,loading:r}=Ze(),{data:o,error:n,isLoading:s,mutate:a}=Ye(r?null:"/user",()=>Lu(t)),h=async L=>{const I=new FormData;for(const[q,Y]of Object.entries(L))Y!=null&&Y!==""&&I.append(q,String(Y));const A=await G(await t("/me",{method:"POST",body:I}));return a(),A},g=async()=>await G(await t("/me/email-addresses",{method:"GET"})),c=async L=>await G(await t(`/me/email-addresses/${L}`,{method:"GET"})),u=async L=>{const I=new FormData;return I.append("email",L),await G(await t("/me/email-addresses",{method:"POST",body:I}))},d=async L=>await G(await t(`/me/email-addresses/${L}/delete`,{method:"POST"})),p=async L=>await G(await t(`/me/email-addresses/${L}/prepare-verification`,{method:"POST"})),x=async(L,I)=>await G(await t(`/me/email-addresses/${L}/attempt-verification?code=${I}`,{method:"POST"})),m=async(L,I)=>{const A=new FormData;return A.append("phone_number",L),A.append("country_code",I),await G(await t("/me/phone-numbers",{method:"POST",body:A}))},v=async L=>await G(await t(`/me/phone-numbers/${L}/delete`,{method:"POST"})),b=async L=>await G(await t(`/me/phone-numbers/${L}/prepare-verification`,{method:"POST"})),_=async(L,I)=>{const A=new FormData;return A.append("code",I),await G(await t(`/me/phone-numbers/${L}/attempt-verification`,{method:"POST",body:A}))},k=async L=>{const I=await G(await t(`/me/phone-numbers/${L}/make-primary`,{method:"POST"}));return a(),I},C=async L=>await G(await t(`/me/email-addresses/${L}/make-primary`,{method:"POST"})),z=async()=>(await G(await t("/me/authenticator",{method:"POST"}))).data,E=async(L,I)=>{const A=new FormData;return A.append("authenticator_id",L),I.forEach(Y=>{A.append("codes",Y)}),await G(await t("/me/authenticator/attempt-verification",{method:"POST",body:A}))},w=async L=>await G(await t(`/me/authenticator/${L}/delete`,{method:"POST"})),y=async()=>(await G(await t("/me/backup-codes",{method:"POST"}))).data,f=async L=>{const I=new FormData;return I.append("file",L),await G(await t("/me/profile-picture",{method:"POST",body:I}))},$=async()=>(await G(await t("/me/backup-codes/regenerate",{method:"POST"}))).data,S=async(L,I)=>{const A=new FormData;return A.append("current_password",L),A.append("new_password",I),await G(await t("/me/update-password",{method:"POST",body:A}))},j=async L=>{const I=new FormData;I.append("current_password",L);const A=await G(await t("/me/remove-password",{method:"POST",body:I}));return a(),A},T=async L=>{const I=new FormData;return I.append("password",L),await G(await t("/me/account/delete",{method:"POST",body:I}))},R=async L=>await G(await t(`/me/social-connections/${L}/disconnect`,{method:"POST"})),O=async({provider:L,redirectUri:I})=>{var Y;const A=new URLSearchParams({provider:L});I&&A.append("redirect_uri",I);const q=await G(await t(`/me/init-sso-connection?${A.toString()}`,{method:"POST"}));return"data"in q&&((Y=q.data)!=null&&Y.oauth_url)&&window.open(q.data.oauth_url,"_blank"),q},P=async()=>await G(await t("/me/passkeys",{method:"GET"})),M=async L=>{var J,oe;const I=await G(await t("/me/passkeys/register/begin",{method:"POST"}));if(!("data"in I))return I;const A=I.data.options.publicKey,q={challenge:Sn(A.challenge),rp:A.rp,user:{id:Sn(A.user.id),name:A.user.name,displayName:A.user.displayName},pubKeyCredParams:A.pubKeyCredParams,timeout:A.timeout,attestation:A.attestation,authenticatorSelection:A.authenticatorSelection,excludeCredentials:(J=A.excludeCredentials)==null?void 0:J.map(re=>({type:re.type,id:Sn(re.id),transports:re.transports}))},Y=await navigator.credentials.create({publicKey:q});if(!Y)throw new Error("Failed to create credential");const B=Y.response,H={id:Y.id,rawId:Cn(Y.rawId),type:Y.type,response:{clientDataJSON:Cn(B.clientDataJSON),attestationObject:Cn(B.attestationObject),transports:((oe=B.getTransports)==null?void 0:oe.call(B))||[]}};return await G(await t(`/me/passkeys/register/finish?name=${encodeURIComponent(L||"")}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(H)}))},N=async L=>await G(await t(`/me/passkeys/${L}/delete`,{method:"POST"})),D=async(L,I)=>await G(await t(`/me/passkeys/${L}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:I})}));return{user:{...o,refetch:a},loading:r||s,error:n||null,updateProfile:h,getEmailAddresses:g,getEmailAddress:c,createEmailAddress:u,deleteEmailAddress:d,prepareEmailVerification:p,attemptEmailVerification:x,makeEmailPrimary:C,createPhoneNumber:m,deletePhoneNumber:v,preparePhoneVerification:b,attemptPhoneVerification:_,makePhonePrimary:k,setupAuthenticator:z,verifyAuthenticator:E,deleteAuthenticator:w,generateBackupCodes:y,regenerateBackupCodes:$,updateProfilePicture:f,disconnectSocialConnection:R,connectSocialAccount:O,updatePassword:S,removePassword:j,deleteAccount:T,getPasskeys:P,registerPasskey:M,deletePasskey:N,renamePasskey:D}}function Fc(){const{client:t,loading:r}=Ze(),{data:o,error:n,isLoading:s,mutate:a}=Ye(r?null:"/me/signins",()=>Du(t));return{signins:o,error:n||null,removeSignin:async g=>await G(await t(`/me/signins/${g}/signout`,{method:"POST"})),refetch:a,loading:s||r}}function Nu(){const{session:t,loading:r}=Ke(),{loading:o,organizationMemberships:n}=Mt(),{loading:s,workspaceMemberships:a}=tn();if(r||o||s)return{loading:!0,orgMembership:null,workspaceMembership:null};const h=i.useMemo(()=>!t||!t.signins||t.signins.length===0?null:n==null?void 0:n.find(c=>{var u;return c.id===((u=t.active_signin)==null?void 0:u.active_organization_membership_id)}),[t]),g=i.useMemo(()=>!t||!t.signins||t.signins.length===0?null:a==null?void 0:a.find(c=>{var u;return c.id===((u=t.active_signin)==null?void 0:u.active_workspace_membership_id)}),[t]);return{loading:!1,orgMembership:h,workspaceMembership:g}}function Bc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(!1),s=async a=>{n(!0);try{const h=new FormData;for(const[u,d]of Object.entries(a))d&&h.append(u,d);const g=await t("/waitlist/join",{method:"POST",body:h});return await G(g)}finally{n(!1)}};return r?{loading:!0,joinWaitlist:null}:{loading:o,joinWaitlist:s}}function Uc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(!1),[s,a]=i.useState(null),[h,g]=i.useState(null),[c,u]=i.useState(null),[d,p]=i.useState(!1),[x,m]=i.useState(null);i.useEffect(()=>{if(d||r)return;const b=new URLSearchParams(window.location.search),_=b.get("code"),k=b.get("state"),C=b.get("error"),z=b.get("error_description");if(!_&&!C){p(!0);const E=new Error("No OAuth callback data found.");a(E);return}if(p(!0),n(!0),C){const E=z||C,w=new Error(`OAuth Error: ${E}`);a(w),n(!1);return}if(_&&k)v(_,k);else{const E=new Error("Missing required OAuth parameters");a(E),n(!1)}},[d,r]);const v=async(b,_)=>{try{let k,C;try{const w=_.split(".");if(w.length!==2)throw new Error("Invalid OAuth state format - missing signature");const y=w[0].replace(/-/g,"+").replace(/_/g,"/"),f=y.length%4?"=".repeat(4-y.length%4):"",S=atob(y+f).split("|")[0];if(S==="sign_in")k="/auth/oauth2/callback",C="GET";else if(S==="connect_social")k="/me/sso-connection-callback",C="POST";else throw new Error(`Unknown OAuth action: ${S}`)}catch(w){const y=w instanceof Error?w:new Error("Failed to parse OAuth state");a(new Error(`Invalid OAuth callback: ${y.message}. The authorization link may be expired or malformed. Please try signing in again.`)),n(!1);return}const z=await t(`${k}?code=${encodeURIComponent(b)}&state=${encodeURIComponent(_)}`,{method:C}),E=await G(z);if("data"in E){const w=E.data.session,y=E.data.redirect_uri||null;if(g(w),u(y),w.signin_attempts&&w.signin_attempts.length>0){const f=w.signin_attempts.at(-1);f&&m(f)}}else{const w=new Error("SSO callback failed");a(w)}}catch(k){const C=k instanceof Error?k:new Error("Unknown error occurred");a(C)}finally{n(!1)}};return{loading:o,error:s,session:h,redirectUri:c,processed:d,signinAttempt:x}}function Wc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(!1),[s,a]=i.useState(null);return{loading:r||o,verifyMagicLink:async g=>{if(!g.token||!g.attempt)throw new Error("Invalid magic link parameters");n(!0),a(null);try{const c=new URL("/auth/verify-magic-link",window.location.origin);c.searchParams.set("token",g.token),c.searchParams.set("attempt",g.attempt),g.redirectUri&&c.searchParams.set("redirect_uri",g.redirectUri);const u=await t(c.pathname+c.search,{method:"GET"}),d=await G(u);return n(!1),a(!0),d}catch(c){throw n(!1),a(!1),c}},success:s}}function Vc(){const[t,r]=i.useState({});return i.useEffect(()=>{const o=new URLSearchParams(window.location.search);r({token:o.get("token")||void 0,attempt:o.get("attempt")||void 0,redirectUri:o.get("redirect_uri")||void 0})},[]),t}function Gc(){const{client:t,loading:r}=Ze();return{loading:r,forgotPassword:async a=>{const h=new FormData;h.append("email",a);const g=await t("/auth/forgot-password",{method:"POST",body:h});return await G(g)},verifyOtp:async(a,h)=>{const g=new FormData;g.append("email",a),g.append("otp",h);const c=await t("/auth/forgot-password",{method:"POST",body:g});return await G(c)},resetPassword:async(a,h)=>{const g=new FormData;g.append("token",a),g.append("password",h);const c=await t("/auth/reset-password",{method:"POST",body:g});return await G(c)}}}function Hc({enabled:t=!0,channels:r,organizationIds:o,workspaceIds:n,onNotification:s,onError:a,reconnectDelay:h=1e3,maxReconnectAttempts:g=5}={}){const{session:c,loading:u}=Ke(),{deployment:d,loading:p}=ye(),[x,m]=i.useState(!1),[v,b]=i.useState(null),_=i.useRef(null),k=i.useRef(null),C=i.useRef(0),z=i.useRef(null),E=i.useRef(s),w=i.useRef(a),y=i.useRef(r),f=i.useRef(o),$=i.useRef(n),S=i.useRef(h),j=i.useRef(g);E.current=s,w.current=a,y.current=r,f.current=o,$.current=n,S.current=h,j.current=g;const T=i.useCallback(()=>{k.current&&(clearTimeout(k.current),k.current=null),z.current&&(clearInterval(z.current),z.current=null),_.current&&(_.current.close(),_.current=null)},[]),R=i.useCallback(async()=>{var L;if(!t||u||p||!c||!d)return;T();const M=new URL(d.backend_host),N=M.protocol==="https:"?"wss:":"ws:",D=new URL("/realtime/notifications",`${N}//${M.host}`);if(d.mode==="staging"){const I=localStorage.getItem("__dev_session__");I&&D.searchParams.set("__dev_session__",I)}y.current&&y.current.length>0&&y.current.forEach(I=>D.searchParams.append("channels",I)),f.current&&f.current.length>0&&f.current.forEach(I=>D.searchParams.append("organization_ids",I.toString())),$.current&&$.current.length>0&&$.current.forEach(I=>D.searchParams.append("workspace_ids",I.toString()));try{const I=new WebSocket(D.toString());_.current=I,I.onopen=()=>{m(!0),b(null),C.current=0,z.current=setInterval(()=>{I.readyState===WebSocket.OPEN&&I.send("ping")},3e4)},I.onmessage=A=>{var q,Y;try{const B=JSON.parse(A.data);if(B.type==="notification"&&B.data)(q=E.current)==null||q.call(E,B.data);else if(B.type==="error"){const H=B.error||"Unknown error occurred";b(H),(Y=w.current)==null||Y.call(w,H)}else B.type}catch{}},I.onerror=()=>{var A;b("Connection error occurred"),(A=w.current)==null||A.call(w,"Connection error occurred")},I.onclose=A=>{var q;if(m(!1),z.current&&(clearInterval(z.current),z.current=null),t&&A.code!==1e3&&C.current<j.current){C.current++;const Y=S.current*Math.pow(2,C.current-1);k.current=setTimeout(()=>{R()},Y)}else C.current>=j.current&&(b("Max reconnection attempts reached"),(q=w.current)==null||q.call(w,"Max reconnection attempts reached"))}}catch{b("Failed to connect"),(L=w.current)==null||L.call(w,"Failed to connect")}},[t,u,p,c,d,T]);i.useEffect(()=>(R(),()=>{T()}),[R,T]),i.useEffect(()=>{_.current&&_.current.readyState===WebSocket.OPEN&&R()},[r,o,n,R]);const O=i.useCallback(()=>{T(),m(!1)},[T]),P=i.useCallback(()=>{C.current=0,R()},[R]);return{isConnected:x,connectionError:v,disconnect:O,reconnect:P}}async function Fu(t,r){const o=new URLSearchParams;r&&(r.limit&&o.append("limit",r.limit.toString()),r.offset&&o.append("offset",r.offset.toString()),r.channels&&r.channels.forEach(h=>o.append("channels",h)),r.organization_ids&&r.organization_ids.forEach(h=>o.append("organization_ids",h.toString())),r.workspace_ids&&r.workspace_ids.forEach(h=>o.append("workspace_ids",h.toString())),r.is_read!==void 0&&o.append("is_read",r.is_read.toString()),r.is_archived!==void 0&&o.append("is_archived",r.is_archived.toString()),r.severity&&o.append("severity",r.severity));const n=`/notifications${o.toString()?"?"+o.toString():""}`,s=await t(n,{method:"GET"});return(await G(s)).data}async function Bu(t){const r=await t("/notifications/channel-counts",{method:"GET"});return(await G(r)).data}async function Uu(t,r){const o=await t(`/notifications/${r}/read`,{method:"POST"});return G(o)}async function Wu(t){const r=await t("/notifications/mark-all-read",{method:"POST"});return G(r)}async function Vu(t,r){const o=await t(`/notifications/${r}/delete`,{method:"POST"});return G(o)}function qc(t){const{client:r,loading:o}=Ze(),{data:n,error:s,mutate:a,isLoading:h}=Ye(o?null:`wacht-notifications:${JSON.stringify(t)}`,()=>Fu(r,t),{refreshInterval:6e4,revalidateOnFocus:!0});Hc({enabled:!o&&!!n,onNotification:i.useCallback(p=>{a(async x=>!x||x.notifications.some(v=>v.id===p.id.toString())?x:{...x,notifications:[{id:p.id.toString(),user_id:p.user_id.toString(),deployment_id:p.deployment_id.toString(),title:p.title,body:p.body,severity:p.severity,action_url:p.action_url,action_label:p.action_label,is_read:!1,is_archived:!1,created_at:p.created_at,updated_at:p.created_at},...x.notifications],unread_count:x.unread_count+1,total:x.total+1},!1)},[a]),onError:i.useCallback(()=>{},[])});const g=i.useCallback(async p=>{o||(await a(async x=>x&&{...x,notifications:x.notifications.map(m=>m.id===p?{...m,is_read:!0}:m),unread_count:Math.max(0,x.unread_count-1)},!1),await Uu(r,p),await a())},[r,o,a]),c=i.useCallback(async()=>{o||(await a(async p=>p&&{...p,notifications:p.notifications.map(x=>({...x,is_read:!0})),unread_count:0},!1),await Wu(r),await a())},[r,a]),u=i.useCallback(async p=>{o||(await a(async x=>{if(!x)return x;const m=x.notifications.find(v=>v.id===p);return{...x,notifications:x.notifications.filter(v=>v.id!==p),unread_count:m&&!m.is_read?Math.max(0,x.unread_count-1):x.unread_count,total:Math.max(0,x.total-1)}},!1),await Vu(r,p),await a())},[r,o,a]),d=i.useCallback(async()=>{await a()},[a]);return!n||o||h?{loading:!0,notifications:void 0,unreadCount:void 0,unreadCounts:void 0,channels:void 0,hasMore:void 0,markAsRead:void 0,markAllAsRead:void 0,deleteNotification:void 0,error:s,refetch:d}:{loading:!1,error:s,notifications:n.notifications,unreadCount:n.unread_count,unreadCounts:n.unread_counts,channels:n.channels,hasMore:n.has_more,markAsRead:g,markAllAsRead:c,deleteNotification:u,refetch:d}}async function Gu(t){const r=await t("/notifications/channel-counts",{method:"GET"});return(await G(r)).data}function Hu(){const{client:t,loading:r}=Ze(),{data:o,error:n,mutate:s}=Ye(r?null:"wacht-notifications:channel-counts",()=>Gu(t),{refreshInterval:3e4,revalidateOnFocus:!0}),a=async()=>{await s()};return!o||r?{loading:!0,counts:void 0,error:n,refetch:a}:{loading:!1,counts:o,error:n,refetch:a}}const sr=class sr{constructor(){lt(this,"ws",null);lt(this,"messageHandlers",new Set);lt(this,"connectionStateHandlers",new Set);lt(this,"reconnectTimer",null);lt(this,"reconnectAttempts",0);lt(this,"url",null);lt(this,"isIntentionalDisconnect",!1);lt(this,"sessionMessages",{});lt(this,"currentSessionKey",null)}static getInstance(){return sr.instance||(sr.instance=new sr),sr.instance}connect(r){var o,n;if(this.url=r,this.isIntentionalDisconnect=!1,((o=this.ws)==null?void 0:o.readyState)===WebSocket.OPEN&&this.url===r){this.notifyConnectionState({isConnected:!0});return}((n=this.ws)==null?void 0:n.readyState)!==WebSocket.CONNECTING&&this.createConnection()}createConnection(){if(this.url)try{this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.reconnectAttempts=0,this.notifyConnectionState({isConnected:!0})},this.ws.onmessage=r=>{try{const o=JSON.parse(r.data);this.notifyMessageHandlers(o)}catch{}},this.ws.onerror=()=>{this.notifyConnectionState({isConnected:!1,error:"Connection error"})},this.ws.onclose=()=>{this.ws=null,this.notifyConnectionState({isConnected:!1}),this.isIntentionalDisconnect||this.scheduleReconnect()}}catch(r){this.notifyConnectionState({isConnected:!1,error:r instanceof Error?r.message:"Failed to connect"})}}scheduleReconnect(){this.reconnectAttempts++;const r=Math.min(1e3*Math.pow(2,this.reconnectAttempts-1),3e4),o=Math.random()*.3*r,n=Math.floor(r+o);this.reconnectTimer=setTimeout(()=>{this.createConnection()},n)}disconnect(){this.isIntentionalDisconnect=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws&&(this.ws.close(),this.ws=null)}send(r){var o;if(((o=this.ws)==null?void 0:o.readyState)===WebSocket.OPEN){const n=JSON.stringify(r);this.ws.send(n)}}onMessage(r){return this.messageHandlers.add(r),()=>{this.messageHandlers.delete(r)}}onConnectionStateChange(r){var o;return this.connectionStateHandlers.add(r),r({isConnected:((o=this.ws)==null?void 0:o.readyState)===WebSocket.OPEN}),()=>{this.connectionStateHandlers.delete(r)}}notifyMessageHandlers(r){this.messageHandlers.forEach(o=>{try{o(r)}catch{}})}notifyConnectionState(r){this.connectionStateHandlers.forEach(o=>{try{o(r)}catch{}})}isConnected(){var r;return((r=this.ws)==null?void 0:r.readyState)===WebSocket.OPEN}setCurrentSession(r){this.currentSessionKey=r,this.sessionMessages[r]||(this.sessionMessages[r]=[])}addMessage(r){this.currentSessionKey&&(this.sessionMessages[this.currentSessionKey]||(this.sessionMessages[this.currentSessionKey]=[]),this.sessionMessages[this.currentSessionKey].push(r))}getSessionMessages(r){return this.sessionMessages[r]||[]}clearSessionMessages(r){this.sessionMessages[r]&&(this.sessionMessages[r]=[])}};lt(sr,"instance");let fs=sr;const st=fs.getInstance(),Pt={DISCONNECTED:"disconnected",CONNECTING:"connecting",CONNECTED:"connected",ERROR:"error"},Ge={IDLE:"idle",STARTING:"starting",RUNNING:"running",WAITING_FOR_INPUT:"waiting_for_input",COMPLETED:"completed",FAILED:"failed"},qt={IDLE:"Idle",STARTING:"Starting",RUNNING:"Running",WAITING_FOR_INPUT:"WaitingForInput",COMPLETED:"Completed",FAILED:"Failed",CANCELLED:"Cancelled"};function xa(t){switch(t){case qt.IDLE:return Ge.IDLE;case qt.STARTING:return Ge.STARTING;case qt.RUNNING:return Ge.RUNNING;case qt.WAITING_FOR_INPUT:return Ge.WAITING_FOR_INPUT;case qt.COMPLETED:return Ge.COMPLETED;case qt.FAILED:case qt.CANCELLED:return Ge.FAILED;default:return Ge.IDLE}}function va(t){return t===Ge.STARTING||t===Ge.RUNNING||t===Ge.WAITING_FOR_INPUT}function Yc({contextId:t,agentName:r,token:o,platformAdapter:n,autoConnect:s=!0}){const{deployment:a}=ye(),{client:h}=Ze(),[g,c]=i.useState([]),[u,d]=i.useState(null),[p,x]=i.useState(null),[m,v]=i.useState(!1),[b,_]=i.useState(!1),[k,C]=i.useState(Ge.IDLE),[z,E]=i.useState({status:Pt.DISCONNECTED}),[w,y]=i.useState(!0),[f,$]=i.useState(!1),S=i.useRef(null),j=i.useRef(null),T=i.useCallback(B=>{var H,V;switch(B.message_type){case"session_connected":if(v(!0),E({status:Pt.CONNECTED}),(H=B.data)!=null&&H.execution_status){const oe=B.data.execution_status,re=xa(oe);C(re),_(va(re))}break;case"conversation_message":R(B.data);break;case"user_input_request":O(B.data);break;case"platform_event":P(B.data);break;case"platform_function":M(B.data);break;case"execution_complete":_(!1),C(Ge.IDLE),j.current=null;break;case"execution_error":_(!1),C(Ge.FAILED),j.current=null;break;case"execution_cancelled":_(!1),C(Ge.IDLE),j.current=null;break;case"execution_status":const J=(V=B.data)==null?void 0:V.status;if(J){const oe=xa(J);C(oe),_(va(oe))}break}},[u]),R=i.useCallback(B=>{var re,fe,X,ue,ve,pe,U,ce;const{id:H,message_type:V,content:J}=B,oe=Q=>g.some(Z=>Z.id===Q);if(V==="system_decision"||V==="action_execution_result"||V==="assistant_task_breakdown"||V==="assistant_validation"||V==="assistant_action_planning"||V==="context_results"){d(null),x(null);let Q="";if(V==="system_decision"){const Z=J==null?void 0:J.step,ne=J==null?void 0:J.reasoning;if(Z==="gathercontext")ne&&ne.length>0?Q=ne.length>60?`${ne.substring(0,60)}...`:ne:Q="Gathering context...";else if(Z==="executeaction")Q="Executing action";else if(Z==="deliverresponse")Q="Preparing response";else if(Z==="taskplanning")Q="Planning approach";else if(Z==="validateprogress")Q="Validating progress";else if(Z==="acknowledge")Q="Processing request";else if(Z==="finishplanning")Q="Finalizing plan";else if(Z==="executetasks")Q="Executing tasks";else if(Z==="requestuserinput")Q="Waiting for input";else if(Z==="complete")Q="Completed";else if(Z==="examinetool")Q="Examining tool";else if(Z==="examineworkflow")Q="Examining workflow";else{const me=(J==null?void 0:J.confidence)||.5;me>.8?Q="Analyzing":me>.6?Q="Thinking":Q="Reasoning"}}else if(V==="action_execution_result")((re=J.task_execution)==null?void 0:re.status)==="completed"?Q="Task execution completed":(fe=J.task_execution)!=null&&fe.approach?Q=J.task_execution.approach:Q="Executing task";else if(V==="assistant_task_breakdown")(X=J.task_breakdown)!=null&&X.total_tasks?Q=`Identified ${J.task_breakdown.total_tasks} tasks`:Q="Planning tasks";else if(V==="assistant_validation")Q="Validated results";else if(V==="assistant_action_planning")(ue=J.task_execution)!=null&&ue.total_tasks?Q=`Planned ${J.task_execution.total_tasks} tasks`:(pe=(ve=J.task_execution)==null?void 0:ve.tasks)!=null&&pe.length?Q=`Planned ${J.task_execution.tasks.length} tasks`:Q="Planning actions";else if(V==="context_results"){const Z=J.query,ne=J.result_count||0;Z&&Z!=="General context gathering"?Q=`${Z}: Found ${ne} results`:Q=`Found ${ne} results`}Q&&!oe(H)&&c(Z=>[...Z,{id:H,role:"system",content:Q,timestamp:new Date,metadata:{type:"log",messageType:V}}]);return}if(V==="user_message")oe(H)||(d(null),x(null),c(Q=>[...Q,{id:H,role:"user",content:J.message,images:J.images,timestamp:new Date}]));else if(V==="agent_response")oe(H)||(d(null),x(null),_(!1),C(Ge.IDLE),j.current=null,c(Q=>[...Q,{id:H,role:"assistant",content:J.response,timestamp:new Date,isStreaming:!1}]));else if(V==="assistant_acknowledgment")oe(H)||(d(null),x(null),c(Q=>[...Q,{id:H,role:"assistant",content:J.acknowledgment_message,timestamp:new Date}]));else if(V==="assistant_ideation"||V==="assistant_action_planning"||V==="action_execution_result"||V==="assistant_validation"||V==="assistant_context_gathering"||V==="assistant_task_breakdown"){let Q="";if(J.reasoning_summary)Q=J.reasoning_summary;else if((U=J.task_execution)!=null&&U.approach)Q=J.task_execution.approach;else if(J.strategic_synthesis)Q=J.strategic_synthesis;else if((ce=J.task_breakdown)!=null&&ce.total_tasks)Q=`Breaking down into ${J.task_breakdown.total_tasks} tasks...`;else if(J.acknowledgment_message)Q=J.acknowledgment_message;else return;c(Z=>[...Z,{id:H,role:"assistant",content:Q,timestamp:new Date}])}else if(V==="user_input_request"){const Q={question:J.question,context:J.context,input_type:J.input_type,options:J.options||J.suggestions,default_value:J.default_value,placeholder:J.placeholder};C("waiting_for_input"),c(Z=>[...Z,{id:H,role:"system",content:Q.question,timestamp:new Date,metadata:{type:"user_input_request",userInputRequest:Q}}])}},[]),O=i.useCallback(async B=>{C("waiting_for_input");const H=`input-request-${Date.now()}`;c(V=>[...V,{id:H,role:"system",content:B.question,timestamp:new Date,metadata:{type:"user_input_request",userInputRequest:B}}])},[]),P=i.useCallback(B=>{const{event_label:H,event_data:V}=B;n!=null&&n.onPlatformEvent&&n.onPlatformEvent(H,V)},[n]),M=i.useCallback(async B=>{const{function_name:H,function_data:V}=B,{parameters:J,execution_id:oe}=V;if(!(n!=null&&n.onPlatformFunction)){st.send({message_type:{platform_function_result:[oe,{error:"No platform function handler registered"}]},data:{}});return}try{const re=await n.onPlatformFunction(H,J,oe),fe={message_type:{platform_function_result:[oe,re]},data:{}};st.send(fe)}catch(re){st.send({message_type:{platform_function_result:[oe,{error:re instanceof Error?re.message:"Function execution failed",stack:re instanceof Error?re.stack:void 0}]},data:{}})}},[n]);i.useEffect(()=>{if(!a)return;const H=`wss://${a==null?void 0:a.backend_host.replace(/https?:\/\//,"")}/realtime/agent?token=${encodeURIComponent(o)}`;E({status:Pt.CONNECTING}),st.connect(H)},[a,o]),i.useEffect(()=>st.onConnectionStateChange(H=>{E({status:H.isConnected?Pt.CONNECTED:H.error?Pt.ERROR:Pt.DISCONNECTED}),v(H.isConnected)}),[]),i.useEffect(()=>st.onMessage(T),[T]),i.useEffect(()=>{m&&t&&r&&s&&st.send({message_type:{session_connect:[t,r]},data:{}})},[m,t,r,s]);const N=i.useCallback(async()=>(m&&t&&r&&st.send({message_type:{session_connect:[t,r]},data:{}}),()=>{}),[m,t,r]),D=i.useCallback((B,H)=>{m&&(d(B),x(H||null),_(!0),C(Ge.STARTING),st.send({message_type:{message_input:B},data:H?{images:H}:{}}))},[m]),L=i.useCallback(()=>{c([]),j.current=null},[]),I=i.useCallback(B=>{!m||k!==Ge.WAITING_FOR_INPUT||(st.send({message_type:{user_input_response:B},data:{}}),C(Ge.RUNNING))},[m,k]),A=i.useCallback(async B=>{var H;if(!(!o||!t))try{const V=new URLSearchParams({token:o,limit:"50"});B&&(V.append("before_id",B),$(!0));const oe=await(await h(`/api/agent/contexts/${t}/messages?${V}`,{method:"GET"})).json();if(oe.status===200&&oe.data){const re=oe.data;if(Array.isArray(re.data)){const fe=re.data.filter(X=>{var pe;let ue=X.content;if(typeof X.content=="string")try{ue=JSON.parse(X.content)}catch{ue={message:X.content}}const ve=((pe=X.metadata)==null?void 0:pe.message_type)||(ue==null?void 0:ue.message_type);return ve==="user_message"||ve==="agent_response"||ve==="assistant_acknowledgment"||ve==="user_input_request"||ve==="system_decision"||ve==="action_execution_result"||ve==="assistant_task_breakdown"||ve==="assistant_validation"||ve==="assistant_action_planning"||ve==="context_results"}).map(X=>{var Q,Z,ne,me,le,ee,W;let ue="",ve,pe,U=X.content;if(typeof X.content=="string")try{U=JSON.parse(X.content)}catch{U=X.content}const ce=((Q=X.metadata)==null?void 0:Q.message_type)||(U==null?void 0:U.message_type);if(ce==="user_message"?(ue=(U==null?void 0:U.message)||"",ve=(U==null?void 0:U.images)||void 0):ce==="agent_response"?ue=(U==null?void 0:U.response)||"":ce==="assistant_acknowledgment"?ue=(U==null?void 0:U.acknowledgment_message)||"":ce==="user_input_request"&&(ue=(U==null?void 0:U.question)||"",pe={type:"user_input_request",userInputRequest:{question:(U==null?void 0:U.question)||"",context:(U==null?void 0:U.context)||"",input_type:(U==null?void 0:U.input_type)||"text",options:(U==null?void 0:U.options)||(U==null?void 0:U.suggestions)||[],default_value:(U==null?void 0:U.default_value)||"",placeholder:(U==null?void 0:U.placeholder)||""}}),ce==="system_decision"||ce==="action_execution_result"||ce==="assistant_task_breakdown"||ce==="assistant_validation"||ce==="assistant_action_planning"||ce==="context_results"){let F="";if(ce==="system_decision"){const se=U==null?void 0:U.step,be=U==null?void 0:U.reasoning;if(se==="gathercontext")be&&be.length>0?F=be.length>60?`${be.substring(0,60)}...`:be:F="Gathering context...";else if(se==="executeaction")F="Executing action";else if(se==="deliverresponse")F="Preparing response";else if(se==="taskplanning")F="Planning approach";else if(se==="validateprogress")F="Validating progress";else if(se==="acknowledge")F="Processing request";else if(se==="finishplanning")F="Finalizing plan";else if(se==="executetasks")F="Executing tasks";else if(se==="requestuserinput")F="Waiting for input";else if(se==="complete")F="Completed";else if(se==="examinetool")F="Examining tool";else if(se==="examineworkflow")F="Examining workflow";else{const Oe=(U==null?void 0:U.confidence)||.5;Oe>.8?F="Analyzing":Oe>.6?F="Thinking":F="Reasoning"}}else if(ce==="action_execution_result")((Z=U==null?void 0:U.task_execution)==null?void 0:Z.status)==="completed"?F="Task execution completed":(ne=U==null?void 0:U.task_execution)!=null&&ne.approach?F=U.task_execution.approach:F="Executing task";else if(ce==="assistant_task_breakdown")(me=U==null?void 0:U.task_breakdown)!=null&&me.total_tasks?F=`Identified ${U.task_breakdown.total_tasks} tasks`:F="Planning tasks";else if(ce==="assistant_validation")F="Validated results";else if(ce==="assistant_action_planning")(le=U==null?void 0:U.task_execution)!=null&&le.total_tasks?F=`Planned ${U.task_execution.total_tasks} tasks`:(W=(ee=U==null?void 0:U.task_execution)==null?void 0:ee.tasks)!=null&&W.length?F=`Planned ${U.task_execution.tasks.length} tasks`:F="Planning actions";else if(ce==="context_results"){const se=U==null?void 0:U.query,be=(U==null?void 0:U.result_count)||0;se&&se!=="General context gathering"?F=`${se}: Found ${be} results`:F=`Found ${be} results`}ue=F,pe={type:"log",messageType:ce}}return{id:X.id,role:ce==="user_message"?"user":ce==="user_input_request"?"system":"assistant",content:ue,images:ve,timestamp:new Date(X.timestamp||X.created_at||Date.now()),metadata:pe}}).filter(X=>X.content||X.metadata||X.images).sort((X,ue)=>{const ve=BigInt(X.id),pe=BigInt(ue.id);return ve<pe?-1:ve>pe?1:0});fe.length>0&&(S.current=fe[0].id),B?(c(X=>[...fe,...X]),y(fe.length>=50)):(c(fe),fe.length>0&&((H=fe[fe.length-1].metadata)==null?void 0:H.type)==="user_input_request"&&C(Ge.WAITING_FOR_INPUT)),$(!1)}}}catch(V){console.error("Failed to fetch messages:",V),$(!1)}},[o,t,h]);i.useEffect(()=>{t&&o&&A()},[t,o]);const q=i.useCallback(async()=>{if(!(f||!w||!S.current)){$(!0);try{await A(S.current)}finally{$(!1)}}},[f,w,A]),Y=i.useCallback(()=>{!m||!b||(st.send({message_type:{cancel_execution:null},data:{}}),_(!1),C("idle"))},[m,b]);return{messages:g,pendingMessage:u,pendingImages:p,connectionState:z,isConnected:m,isExecuting:b,executionStatus:k,isWaitingForInput:k==="waiting_for_input",hasMoreMessages:w,isLoadingMore:f,sendMessage:D,submitUserInput:I,clearMessages:L,loadMoreMessages:q,cancelExecution:Y,connect:N,disconnect:()=>st.disconnect()}}const Zc=()=>{const{client:t}=Ze(),[r,o]=i.useState(!1),[n,s]=i.useState(null),[a,h]=i.useState(null),g=i.useCallback(async u=>{o(!0),s(null),h(null);try{const d=new FormData;d.append("token",u);const p=await t("/organizations/invitations/accept",{method:"POST",body:d}),m=(await G(p)).data;return h(m),m.error_code&&s(m.message||"Failed to accept invitation"),m}catch(d){const p=d.message||"Failed to accept invitation";s(p);const x={error_code:"NETWORK_ERROR",message:p};return h(x),x}finally{o(!1)}},[t]),c=i.useCallback(()=>{s(null),h(null)},[]);return{acceptInvitation:g,invitationData:a,loading:r,error:n,reset:c}},qu=({children:t})=>{const{loading:r}=ye();return r?null:e.jsx(e.Fragment,{children:t})},Yu=({children:t})=>{const{loading:r}=ye();return r?e.jsx(e.Fragment,{children:t}):null};var ot=function(){return ot=Object.assign||function(r){for(var o,n=1,s=arguments.length;n<s;n++){o=arguments[n];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(r[a]=o[a])}return r},ot.apply(this,arguments)};function pr(t,r,o){if(o||arguments.length===2)for(var n=0,s=r.length,a;n<s;n++)(a||!(n in r))&&(a||(a=Array.prototype.slice.call(r,0,n)),a[n]=r[n]);return t.concat(a||Array.prototype.slice.call(r))}function Zu(t){var r=Object.create(null);return function(o){return r[o]===void 0&&(r[o]=t(o)),r[o]}}var Ku=/^((children|dangerouslySetInnerHTML|key|ref|autoFocus|defaultValue|defaultChecked|innerHTML|suppressContentEditableWarning|suppressHydrationWarning|valueLink|abbr|accept|acceptCharset|accessKey|action|allow|allowUserMedia|allowPaymentRequest|allowFullScreen|allowTransparency|alt|async|autoComplete|autoPlay|capture|cellPadding|cellSpacing|challenge|charSet|checked|cite|classID|className|cols|colSpan|content|contentEditable|contextMenu|controls|controlsList|coords|crossOrigin|data|dateTime|decoding|default|defer|dir|disabled|disablePictureInPicture|disableRemotePlayback|download|draggable|encType|enterKeyHint|form|formAction|formEncType|formMethod|formNoValidate|formTarget|frameBorder|headers|height|hidden|high|href|hrefLang|htmlFor|httpEquiv|id|inputMode|integrity|is|keyParams|keyType|kind|label|lang|list|loading|loop|low|marginHeight|marginWidth|max|maxLength|media|mediaGroup|method|min|minLength|multiple|muted|name|nonce|noValidate|open|optimum|pattern|placeholder|playsInline|poster|preload|profile|radioGroup|readOnly|referrerPolicy|rel|required|reversed|role|rows|rowSpan|sandbox|scope|scoped|scrolling|seamless|selected|shape|size|sizes|slot|span|spellCheck|src|srcDoc|srcLang|srcSet|start|step|style|summary|tabIndex|target|title|translate|type|useMap|value|width|wmode|wrap|about|datatype|inlist|prefix|property|resource|typeof|vocab|autoCapitalize|autoCorrect|autoSave|color|incremental|fallback|inert|itemProp|itemScope|itemType|itemID|itemRef|on|option|results|security|unselectable|accentHeight|accumulate|additive|alignmentBaseline|allowReorder|alphabetic|amplitude|arabicForm|ascent|attributeName|attributeType|autoReverse|azimuth|baseFrequency|baselineShift|baseProfile|bbox|begin|bias|by|calcMode|capHeight|clip|clipPathUnits|clipPath|clipRule|colorInterpolation|colorInterpolationFilters|colorProfile|colorRendering|contentScriptType|contentStyleType|cursor|cx|cy|d|decelerate|descent|diffuseConstant|direction|display|divisor|dominantBaseline|dur|dx|dy|edgeMode|elevation|enableBackground|end|exponent|externalResourcesRequired|fill|fillOpacity|fillRule|filter|filterRes|filterUnits|floodColor|floodOpacity|focusable|fontFamily|fontSize|fontSizeAdjust|fontStretch|fontStyle|fontVariant|fontWeight|format|from|fr|fx|fy|g1|g2|glyphName|glyphOrientationHorizontal|glyphOrientationVertical|glyphRef|gradientTransform|gradientUnits|hanging|horizAdvX|horizOriginX|ideographic|imageRendering|in|in2|intercept|k|k1|k2|k3|k4|kernelMatrix|kernelUnitLength|kerning|keyPoints|keySplines|keyTimes|lengthAdjust|letterSpacing|lightingColor|limitingConeAngle|local|markerEnd|markerMid|markerStart|markerHeight|markerUnits|markerWidth|mask|maskContentUnits|maskUnits|mathematical|mode|numOctaves|offset|opacity|operator|order|orient|orientation|origin|overflow|overlinePosition|overlineThickness|panose1|paintOrder|pathLength|patternContentUnits|patternTransform|patternUnits|pointerEvents|points|pointsAtX|pointsAtY|pointsAtZ|preserveAlpha|preserveAspectRatio|primitiveUnits|r|radius|refX|refY|renderingIntent|repeatCount|repeatDur|requiredExtensions|requiredFeatures|restart|result|rotate|rx|ry|scale|seed|shapeRendering|slope|spacing|specularConstant|specularExponent|speed|spreadMethod|startOffset|stdDeviation|stemh|stemv|stitchTiles|stopColor|stopOpacity|strikethroughPosition|strikethroughThickness|string|stroke|strokeDasharray|strokeDashoffset|strokeLinecap|strokeLinejoin|strokeMiterlimit|strokeOpacity|strokeWidth|surfaceScale|systemLanguage|tableValues|targetX|targetY|textAnchor|textDecoration|textRendering|textLength|to|transform|u1|u2|underlinePosition|underlineThickness|unicode|unicodeBidi|unicodeRange|unitsPerEm|vAlphabetic|vHanging|vIdeographic|vMathematical|values|vectorEffect|version|vertAdvY|vertOriginX|vertOriginY|viewBox|viewTarget|visibility|widths|wordSpacing|writingMode|x|xHeight|x1|x2|xChannelSelector|xlinkActuate|xlinkArcrole|xlinkHref|xlinkRole|xlinkShow|xlinkTitle|xlinkType|xmlBase|xmlns|xmlnsXlink|xmlLang|xmlSpace|y|y1|y2|yChannelSelector|z|zoomAndPan|for|class|autofocus)|(([Dd][Aa][Tt][Aa]|[Aa][Rr][Ii][Aa]|x)-.*))$/,Qu=Zu(function(t){return Ku.test(t)||t.charCodeAt(0)===111&&t.charCodeAt(1)===110&&t.charCodeAt(2)<91}),Le="-ms-",qr="-moz-",Re="-webkit-",Kc="comm",rn="rule",Rs="decl",Ju="@import",Qc="@keyframes",Xu="@layer",Jc=Math.abs,Ts=String.fromCharCode,gs=Object.assign;function ep(t,r){return Qe(t,0)^45?(((r<<2^Qe(t,0))<<2^Qe(t,1))<<2^Qe(t,2))<<2^Qe(t,3):0}function Xc(t){return t.trim()}function It(t,r){return(t=r.exec(t))?t[0]:t}function je(t,r,o){return t.replace(r,o)}function Ao(t,r,o){return t.indexOf(r,o)}function Qe(t,r){return t.charCodeAt(r)|0}function zr(t,r,o){return t.slice(r,o)}function xt(t){return t.length}function el(t){return t.length}function Gr(t,r){return r.push(t),t}function tp(t,r){return t.map(r).join("")}function ba(t,r){return t.filter(function(o){return!It(o,r)})}var on=1,$r=1,tl=0,it=0,He=0,Rr="";function nn(t,r,o,n,s,a,h,g){return{value:t,root:r,parent:o,type:n,props:s,children:a,line:on,column:$r,length:h,return:"",siblings:g}}function At(t,r){return gs(nn("",null,null,"",null,null,0,t.siblings),t,{length:-t.length},r)}function mr(t){for(;t.root;)t=At(t.root,{children:[t]});Gr(t,t.siblings)}function rp(){return He}function op(){return He=it>0?Qe(Rr,--it):0,$r--,He===10&&($r=1,on--),He}function dt(){return He=it<tl?Qe(Rr,it++):0,$r++,He===10&&($r=1,on++),He}function ir(){return Qe(Rr,it)}function Lo(){return it}function sn(t,r){return zr(Rr,t,r)}function ms(t){switch(t){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function np(t){return on=$r=1,tl=xt(Rr=t),it=0,[]}function sp(t){return Rr="",t}function zn(t){return Xc(sn(it-1,xs(t===91?t+2:t===40?t+1:t)))}function ap(t){for(;(He=ir())&&He<33;)dt();return ms(t)>2||ms(He)>3?"":" "}function ip(t,r){for(;--r&&dt()&&!(He<48||He>102||He>57&&He<65||He>70&&He<97););return sn(t,Lo()+(r<6&&ir()==32&&dt()==32))}function xs(t){for(;dt();)switch(He){case t:return it;case 34:case 39:t!==34&&t!==39&&xs(He);break;case 40:t===41&&xs(t);break;case 92:dt();break}return it}function cp(t,r){for(;dt()&&t+He!==57;)if(t+He===84&&ir()===47)break;return"/*"+sn(r,it-1)+"*"+Ts(t===47?t:dt())}function lp(t){for(;!ms(ir());)dt();return sn(t,it)}function dp(t){return sp(Do("",null,null,null,[""],t=np(t),0,[0],t))}function Do(t,r,o,n,s,a,h,g,c){for(var u=0,d=0,p=h,x=0,m=0,v=0,b=1,_=1,k=1,C=0,z="",E=s,w=a,y=n,f=z;_;)switch(v=C,C=dt()){case 40:if(v!=108&&Qe(f,p-1)==58){Ao(f+=je(zn(C),"&","&\f"),"&\f",Jc(u?g[u-1]:0))!=-1&&(k=-1);break}case 34:case 39:case 91:f+=zn(C);break;case 9:case 10:case 13:case 32:f+=ap(v);break;case 92:f+=ip(Lo()-1,7);continue;case 47:switch(ir()){case 42:case 47:Gr(up(cp(dt(),Lo()),r,o,c),c);break;default:f+="/"}break;case 123*b:g[u++]=xt(f)*k;case 125*b:case 59:case 0:switch(C){case 0:case 125:_=0;case 59+d:k==-1&&(f=je(f,/\f/g,"")),m>0&&xt(f)-p&&Gr(m>32?wa(f+";",n,o,p-1,c):wa(je(f," ","")+";",n,o,p-2,c),c);break;case 59:f+=";";default:if(Gr(y=ya(f,r,o,u,d,s,g,z,E=[],w=[],p,a),a),C===123)if(d===0)Do(f,r,y,y,E,a,p,g,w);else switch(x===99&&Qe(f,3)===110?100:x){case 100:case 108:case 109:case 115:Do(t,y,y,n&&Gr(ya(t,y,y,0,0,s,g,z,s,E=[],p,w),w),s,w,p,g,n?E:w);break;default:Do(f,y,y,y,[""],w,0,g,w)}}u=d=m=0,b=k=1,z=f="",p=h;break;case 58:p=1+xt(f),m=v;default:if(b<1){if(C==123)--b;else if(C==125&&b++==0&&op()==125)continue}switch(f+=Ts(C),C*b){case 38:k=d>0?1:(f+="\f",-1);break;case 44:g[u++]=(xt(f)-1)*k,k=1;break;case 64:ir()===45&&(f+=zn(dt())),x=ir(),d=p=xt(z=f+=lp(Lo())),C++;break;case 45:v===45&&xt(f)==2&&(b=0)}}return a}function ya(t,r,o,n,s,a,h,g,c,u,d,p){for(var x=s-1,m=s===0?a:[""],v=el(m),b=0,_=0,k=0;b<n;++b)for(var C=0,z=zr(t,x+1,x=Jc(_=h[b])),E=t;C<v;++C)(E=Xc(_>0?m[C]+" "+z:je(z,/&\f/g,m[C])))&&(c[k++]=E);return nn(t,r,o,s===0?rn:g,c,u,d,p)}function up(t,r,o,n){return nn(t,r,o,Kc,Ts(rp()),zr(t,2,-2),0,n)}function wa(t,r,o,n,s){return nn(t,r,o,Rs,zr(t,0,n),zr(t,n+1,-1),n,s)}function rl(t,r,o){switch(ep(t,r)){case 5103:return Re+"print-"+t+t;case 5737:case 4201:case 3177:case 3433:case 1641:case 4457:case 2921:case 5572:case 6356:case 5844:case 3191:case 6645:case 3005:case 6391:case 5879:case 5623:case 6135:case 4599:case 4855:case 4215:case 6389:case 5109:case 5365:case 5621:case 3829:return Re+t+t;case 4789:return qr+t+t;case 5349:case 4246:case 4810:case 6968:case 2756:return Re+t+qr+t+Le+t+t;case 5936:switch(Qe(t,r+11)){case 114:return Re+t+Le+je(t,/[svh]\w+-[tblr]{2}/,"tb")+t;case 108:return Re+t+Le+je(t,/[svh]\w+-[tblr]{2}/,"tb-rl")+t;case 45:return Re+t+Le+je(t,/[svh]\w+-[tblr]{2}/,"lr")+t}case 6828:case 4268:case 2903:return Re+t+Le+t+t;case 6165:return Re+t+Le+"flex-"+t+t;case 5187:return Re+t+je(t,/(\w+).+(:[^]+)/,Re+"box-$1$2"+Le+"flex-$1$2")+t;case 5443:return Re+t+Le+"flex-item-"+je(t,/flex-|-self/g,"")+(It(t,/flex-|baseline/)?"":Le+"grid-row-"+je(t,/flex-|-self/g,""))+t;case 4675:return Re+t+Le+"flex-line-pack"+je(t,/align-content|flex-|-self/g,"")+t;case 5548:return Re+t+Le+je(t,"shrink","negative")+t;case 5292:return Re+t+Le+je(t,"basis","preferred-size")+t;case 6060:return Re+"box-"+je(t,"-grow","")+Re+t+Le+je(t,"grow","positive")+t;case 4554:return Re+je(t,/([^-])(transform)/g,"$1"+Re+"$2")+t;case 6187:return je(je(je(t,/(zoom-|grab)/,Re+"$1"),/(image-set)/,Re+"$1"),t,"")+t;case 5495:case 3959:return je(t,/(image-set\([^]*)/,Re+"$1$`$1");case 4968:return je(je(t,/(.+:)(flex-)?(.*)/,Re+"box-pack:$3"+Le+"flex-pack:$3"),/s.+-b[^;]+/,"justify")+Re+t+t;case 4200:if(!It(t,/flex-|baseline/))return Le+"grid-column-align"+zr(t,r)+t;break;case 2592:case 3360:return Le+je(t,"template-","")+t;case 4384:case 3616:return o&&o.some(function(n,s){return r=s,It(n.props,/grid-\w+-end/)})?~Ao(t+(o=o[r].value),"span",0)?t:Le+je(t,"-start","")+t+Le+"grid-row-span:"+(~Ao(o,"span",0)?It(o,/\d+/):+It(o,/\d+/)-+It(t,/\d+/))+";":Le+je(t,"-start","")+t;case 4896:case 4128:return o&&o.some(function(n){return It(n.props,/grid-\w+-start/)})?t:Le+je(je(t,"-end","-span"),"span ","")+t;case 4095:case 3583:case 4068:case 2532:return je(t,/(.+)-inline(.+)/,Re+"$1$2")+t;case 8116:case 7059:case 5753:case 5535:case 5445:case 5701:case 4933:case 4677:case 5533:case 5789:case 5021:case 4765:if(xt(t)-1-r>6)switch(Qe(t,r+1)){case 109:if(Qe(t,r+4)!==45)break;case 102:return je(t,/(.+:)(.+)-([^]+)/,"$1"+Re+"$2-$3$1"+qr+(Qe(t,r+3)==108?"$3":"$2-$3"))+t;case 115:return~Ao(t,"stretch",0)?rl(je(t,"stretch","fill-available"),r,o)+t:t}break;case 5152:case 5920:return je(t,/(.+?):(\d+)(\s*\/\s*(span)?\s*(\d+))?(.*)/,function(n,s,a,h,g,c,u){return Le+s+":"+a+u+(h?Le+s+"-span:"+(g?c:+c-+a)+u:"")+t});case 4949:if(Qe(t,r+6)===121)return je(t,":",":"+Re)+t;break;case 6444:switch(Qe(t,Qe(t,14)===45?18:11)){case 120:return je(t,/(.+:)([^;\s!]+)(;|(\s+)?!.+)?/,"$1"+Re+(Qe(t,14)===45?"inline-":"")+"box$3$1"+Re+"$2$3$1"+Le+"$2box$3")+t;case 100:return je(t,":",":"+Le)+t}break;case 5719:case 2647:case 2135:case 3927:case 2391:return je(t,"scroll-","scroll-snap-")+t}return t}function Vo(t,r){for(var o="",n=0;n<t.length;n++)o+=r(t[n],n,t,r)||"";return o}function pp(t,r,o,n){switch(t.type){case Xu:if(t.children.length)break;case Ju:case Rs:return t.return=t.return||t.value;case Kc:return"";case Qc:return t.return=t.value+"{"+Vo(t.children,n)+"}";case rn:if(!xt(t.value=t.props.join(",")))return""}return xt(o=Vo(t.children,n))?t.return=t.value+"{"+o+"}":""}function hp(t){var r=el(t);return function(o,n,s,a){for(var h="",g=0;g<r;g++)h+=t[g](o,n,s,a)||"";return h}}function fp(t){return function(r){r.root||(r=r.return)&&t(r)}}function gp(t,r,o,n){if(t.length>-1&&!t.return)switch(t.type){case Rs:t.return=rl(t.value,t.length,o);return;case Qc:return Vo([At(t,{value:je(t.value,"@","@"+Re)})],n);case rn:if(t.length)return tp(o=t.props,function(s){switch(It(s,n=/(::plac\w+|:read-\w+)/)){case":read-only":case":read-write":mr(At(t,{props:[je(s,/:(read-\w+)/,":"+qr+"$1")]})),mr(At(t,{props:[s]})),gs(t,{props:ba(o,n)});break;case"::placeholder":mr(At(t,{props:[je(s,/:(plac\w+)/,":"+Re+"input-$1")]})),mr(At(t,{props:[je(s,/:(plac\w+)/,":"+qr+"$1")]})),mr(At(t,{props:[je(s,/:(plac\w+)/,Le+"input-$1")]})),mr(At(t,{props:[s]})),gs(t,{props:ba(o,n)});break}return""})}}var mp={animationIterationCount:1,aspectRatio:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1},hr=typeof process<"u"&&process.env!==void 0&&(process.env.REACT_APP_SC_ATTR||process.env.SC_ATTR)||"data-styled",ol="active",nl="data-styled-version",an="6.1.19",Ms=`/*!sc*/
|
|
18
|
+
*/var la;function Bd(){return la||(la=1,process.env.NODE_ENV!=="production"&&function(){function t(m,v){return m===v&&(m!==0||1/m===1/v)||m!==m&&v!==v}function r(m,v){d||s.startTransition===void 0||(d=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var b=v();if(!p){var _=v();a(b,_)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),p=!0)}_=h({inst:{value:b,getSnapshot:v}});var k=_[0].inst,C=_[1];return c(function(){k.value=b,k.getSnapshot=v,o(k)&&C({inst:k})},[m,b,v]),g(function(){return o(k)&&C({inst:k}),m(function(){o(k)&&C({inst:k})})},[m]),u(b),b}function o(m){var v=m.getSnapshot;m=m.value;try{var b=v();return!a(m,b)}catch{return!0}}function n(m,v){return v()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var s=i,a=typeof Object.is=="function"?Object.is:t,h=s.useState,g=s.useEffect,c=s.useLayoutEffect,u=s.useDebugValue,d=!1,p=!1,x=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?n:r;vn.useSyncExternalStore=s.useSyncExternalStore!==void 0?s.useSyncExternalStore:x,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),vn}var da;function Ud(){return da||(da=1,process.env.NODE_ENV==="production"?ro.exports=Fd():ro.exports=Bd()),ro.exports}var Wd=Ud();const Sc=0,zc=1,$c=2,ua=3;var pa=Object.prototype.hasOwnProperty;function ss(t,r){var o,n;if(t===r)return!0;if(t&&r&&(o=t.constructor)===r.constructor){if(o===Date)return t.getTime()===r.getTime();if(o===RegExp)return t.toString()===r.toString();if(o===Array){if((n=t.length)===r.length)for(;n--&&ss(t[n],r[n]););return n===-1}if(!o||typeof t=="object"){n=0;for(o in t)if(pa.call(t,o)&&++n&&!pa.call(r,o)||!(o in r)||!ss(t[o],r[o]))return!1;return Object.keys(r).length===n}}return t!==t&&r!==r}const Rt=new WeakMap,Lt=()=>{},rt=Lt(),as=Object,Ee=t=>t===rt,vt=t=>typeof t=="function",Nt=(t,r)=>({...t,...r}),Ec=t=>vt(t.then),bn={},oo={},Is="undefined",Jr=typeof window!=Is,is=typeof document!=Is,Vd=Jr&&"Deno"in window,Gd=()=>Jr&&typeof window.requestAnimationFrame!=Is,Ic=(t,r)=>{const o=Rt.get(t);return[()=>!Ee(r)&&t.get(r)||bn,n=>{if(!Ee(r)){const s=t.get(r);r in oo||(oo[r]=s),o[5](r,Nt(s,n),s||bn)}},o[6],()=>!Ee(r)&&r in oo?oo[r]:!Ee(r)&&t.get(r)||bn]};let cs=!0;const Hd=()=>cs,[ls,ds]=Jr&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[Lt,Lt],qd=()=>{const t=is&&document.visibilityState;return Ee(t)||t!=="hidden"},Yd=t=>(is&&document.addEventListener("visibilitychange",t),ls("focus",t),()=>{is&&document.removeEventListener("visibilitychange",t),ds("focus",t)}),Zd=t=>{const r=()=>{cs=!0,t()},o=()=>{cs=!1};return ls("online",r),ls("offline",o),()=>{ds("online",r),ds("offline",o)}},Kd={isOnline:Hd,isVisible:qd},Qd={initFocus:Yd,initReconnect:Zd},ha=!i.useId,Zr=!Jr||Vd,Jd=t=>Gd()?window.requestAnimationFrame(t):setTimeout(t,1),yn=Zr?i.useEffect:i.useLayoutEffect,wn=typeof navigator<"u"&&navigator.connection,fa=!Zr&&wn&&(["slow-2g","2g"].includes(wn.effectiveType)||wn.saveData),no=new WeakMap,Xd=t=>as.prototype.toString.call(t),jn=(t,r)=>t===`[object ${r}]`;let eu=0;const us=t=>{const r=typeof t,o=Xd(t),n=jn(o,"Date"),s=jn(o,"RegExp"),a=jn(o,"Object");let h,g;if(as(t)===t&&!n&&!s){if(h=no.get(t),h)return h;if(h=++eu+"~",no.set(t,h),Array.isArray(t)){for(h="@",g=0;g<t.length;g++)h+=us(t[g])+",";no.set(t,h)}if(a){h="#";const c=as.keys(t).sort();for(;!Ee(g=c.pop());)Ee(t[g])||(h+=g+":"+us(t[g])+",");no.set(t,h)}}else h=n?t.toJSON():r=="symbol"?t.toString():r=="string"?JSON.stringify(t):""+t;return h},Ps=t=>{if(vt(t))try{t=t()}catch{t=""}const r=t;return t=typeof t=="string"?t:(Array.isArray(t)?t.length:t)?us(t):"",[t,r]};let tu=0;const ps=()=>++tu;async function Pc(...t){const[r,o,n,s]=t,a=Nt({populateCache:!0,throwOnError:!0},typeof s=="boolean"?{revalidate:s}:s||{});let h=a.populateCache;const g=a.rollbackOnError;let c=a.optimisticData;const u=x=>typeof g=="function"?g(x):g!==!1,d=a.throwOnError;if(vt(o)){const x=o,m=[],v=r.keys();for(const b of v)!/^\$(inf|sub)\$/.test(b)&&x(r.get(b)._k)&&m.push(b);return Promise.all(m.map(p))}return p(o);async function p(x){const[m]=Ps(x);if(!m)return;const[v,b]=Ic(r,m),[_,k,C,z]=Rt.get(r),E=()=>{const P=_[m];return(vt(a.revalidate)?a.revalidate(v().data,x):a.revalidate!==!1)&&(delete C[m],delete z[m],P&&P[0])?P[0]($c).then(()=>v().data):v().data};if(t.length<3)return E();let w=n,y,f=!1;const $=ps();k[m]=[$,0];const S=!Ee(c),j=v(),T=j.data,R=j._c,O=Ee(R)?T:R;if(S&&(c=vt(c)?c(O,T):c,b({data:c,_c:O})),vt(w))try{w=w(O)}catch(P){y=P,f=!0}if(w&&Ec(w))if(w=await w.catch(P=>{y=P,f=!0}),$!==k[m][0]){if(f)throw y;return w}else f&&S&&u(y)&&(h=!0,b({data:O,_c:rt}));if(h&&!f)if(vt(h)){const P=h(w,O);b({data:P,error:rt,_c:rt})}else b({data:w,error:rt,_c:rt});if(k[m][1]=ps(),Promise.resolve(E()).then(()=>{b({_c:rt})}),f){if(d)throw y;return}return w}}const ga=(t,r)=>{for(const o in t)t[o][0]&&t[o][0](r)},ru=(t,r)=>{if(!Rt.has(t)){const o=Nt(Qd,r),n=Object.create(null),s=Pc.bind(rt,t);let a=Lt;const h=Object.create(null),g=(d,p)=>{const x=h[d]||[];return h[d]=x,x.push(p),()=>x.splice(x.indexOf(p),1)},c=(d,p,x)=>{t.set(d,p);const m=h[d];if(m)for(const v of m)v(p,x)},u=()=>{if(!Rt.has(t)&&(Rt.set(t,[n,Object.create(null),Object.create(null),Object.create(null),s,c,g]),!Zr)){const d=o.initFocus(setTimeout.bind(rt,ga.bind(rt,n,Sc))),p=o.initReconnect(setTimeout.bind(rt,ga.bind(rt,n,zc)));a=()=>{d&&d(),p&&p(),Rt.delete(t)}}};return u(),[t,s,u,a]}return[t,Rt.get(t)[4]]},ou=(t,r,o,n,s)=>{const a=o.errorRetryCount,h=s.retryCount,g=~~((Math.random()+.5)*(1<<(h<8?h:8)))*o.errorRetryInterval;!Ee(a)&&h>a||setTimeout(n,g,s)},nu=ss,[Rc,Wr]=ru(new Map),su=Nt({onLoadingSlow:Lt,onSuccess:Lt,onError:Lt,onErrorRetry:ou,onDiscarded:Lt,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:fa?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:fa?5e3:3e3,compare:nu,isPaused:()=>!1,cache:Rc,mutate:Wr,fallback:{}},Kd),au=(t,r)=>{const o=Nt(t,r);if(r){const{use:n,fallback:s}=t,{use:a,fallback:h}=r;n&&a&&(o.use=n.concat(a)),s&&h&&(o.fallback=Nt(s,h))}return o},iu=i.createContext({}),cu="$inf$",Tc=Jr&&window.__SWR_DEVTOOLS_USE__,lu=Tc?window.__SWR_DEVTOOLS_USE__:[],du=()=>{Tc&&(window.__SWR_DEVTOOLS_REACT__=i)},uu=t=>vt(t[1])?[t[0],t[1],t[2]||{}]:[t[0],null,(t[1]===null?t[2]:t[1])||{}],Mc=()=>Nt(su,i.useContext(iu)),pu=t=>(r,o,n)=>t(r,o&&((...a)=>{const[h]=Ps(r),[,,,g]=Rt.get(Rc);if(h.startsWith(cu))return o(...a);const c=g[h];return Ee(c)?o(...a):(delete g[h],c)}),n),hu=lu.concat(pu),fu=t=>function(...o){const n=Mc(),[s,a,h]=uu(o),g=au(n,h);let c=t;const{use:u}=g,d=(u||[]).concat(hu);for(let p=d.length;p--;)c=d[p](c);return c(s,a||g.fetcher||null,g)},gu=(t,r,o)=>{const n=r[t]||(r[t]=[]);return n.push(o),()=>{const s=n.indexOf(o);s>=0&&(n[s]=n[n.length-1],n.pop())}};du();const _n=i.use||(t=>{switch(t.status){case"pending":throw t;case"fulfilled":return t.value;case"rejected":throw t.reason;default:throw t.status="pending",t.then(r=>{t.status="fulfilled",t.value=r},r=>{t.status="rejected",t.reason=r}),t}}),kn={dedupe:!0},mu=(t,r,o)=>{const{cache:n,compare:s,suspense:a,fallbackData:h,revalidateOnMount:g,revalidateIfStale:c,refreshInterval:u,refreshWhenHidden:d,refreshWhenOffline:p,keepPreviousData:x}=o,[m,v,b,_]=Rt.get(n),[k,C]=Ps(t),z=i.useRef(!1),E=i.useRef(!1),w=i.useRef(k),y=i.useRef(r),f=i.useRef(o),$=()=>f.current,S=()=>$().isVisible()&&$().isOnline(),[j,T,R,O]=Ic(n,k),P=i.useRef({}).current,M=Ee(h)?Ee(o.fallback)?rt:o.fallback[k]:h,N=(pe,U)=>{for(const le in P){const Q=le;if(Q==="data"){if(!s(pe[Q],U[Q])&&(!Ee(pe[Q])||!s(V,U[Q])))return!1}else if(U[Q]!==pe[Q])return!1}return!0},D=i.useMemo(()=>{const pe=!k||!r?!1:Ee(g)?$().isPaused()||a?!1:c!==!1:g,U=de=>{const ee=Nt(de);return delete ee._k,pe?{isValidating:!0,isLoading:!0,...ee}:ee},le=j(),Q=O(),Z=U(le),ne=le===Q?Z:U(Q);let me=Z;return[()=>{const de=U(j());return N(de,me)?(me.data=de.data,me.isLoading=de.isLoading,me.isValidating=de.isValidating,me.error=de.error,me):(me=de,de)},()=>ne]},[n,k]),L=Wd.useSyncExternalStore(i.useCallback(pe=>R(k,(U,le)=>{N(le,U)||pe()}),[n,k]),D[0],D[1]),I=!z.current,A=m[k]&&m[k].length>0,q=L.data,Y=Ee(q)?M&&Ec(M)?_n(M):M:q,B=L.error,H=i.useRef(Y),V=x?Ee(q)?Ee(H.current)?Y:H.current:q:Y,J=A&&!Ee(B)?!1:I&&!Ee(g)?g:$().isPaused()?!1:a?Ee(Y)?!1:c:Ee(Y)||c,oe=!!(k&&r&&I&&J),re=Ee(L.isValidating)?oe:L.isValidating,fe=Ee(L.isLoading)?oe:L.isLoading,X=i.useCallback(async pe=>{const U=y.current;if(!k||!U||E.current||$().isPaused())return!1;let le,Q,Z=!0;const ne=pe||{},me=!b[k]||!ne.dedupe,de=()=>ha?!E.current&&k===w.current&&z.current:k===w.current,ee={isValidating:!1,isLoading:!1},W=()=>{T(ee)},F=()=>{const be=b[k];be&&be[1]===Q&&delete b[k]},se={isValidating:!0};Ee(j().data)&&(se.isLoading=!0);try{if(me&&(T(se),o.loadingTimeout&&Ee(j().data)&&setTimeout(()=>{Z&&de()&&$().onLoadingSlow(k,o)},o.loadingTimeout),b[k]=[U(C),ps()]),[le,Q]=b[k],le=await le,me&&setTimeout(F,o.dedupingInterval),!b[k]||b[k][1]!==Q)return me&&de()&&$().onDiscarded(k),!1;ee.error=rt;const be=v[k];if(!Ee(be)&&(Q<=be[0]||Q<=be[1]||be[1]===0))return W(),me&&de()&&$().onDiscarded(k),!1;const Oe=j().data;ee.data=s(Oe,le)?Oe:le,me&&de()&&$().onSuccess(le,k,o)}catch(be){F();const Oe=$(),{shouldRetryOnError:Fe}=Oe;Oe.isPaused()||(ee.error=be,me&&de()&&(Oe.onError(be,k,Oe),(Fe===!0||vt(Fe)&&Fe(be))&&(!$().revalidateOnFocus||!$().revalidateOnReconnect||S())&&Oe.onErrorRetry(be,k,Oe,Se=>{const Ve=m[k];Ve&&Ve[0]&&Ve[0](ua,Se)},{retryCount:(ne.retryCount||0)+1,dedupe:!0})))}return Z=!1,W(),!0},[k,n]),ue=i.useCallback((...pe)=>Pc(n,w.current,...pe),[]);if(yn(()=>{y.current=r,f.current=o,Ee(q)||(H.current=q)}),yn(()=>{if(!k)return;const pe=X.bind(rt,kn);let U=0;$().revalidateOnFocus&&(U=Date.now()+$().focusThrottleInterval);const Q=gu(k,m,(Z,ne={})=>{if(Z==Sc){const me=Date.now();$().revalidateOnFocus&&me>U&&S()&&(U=me+$().focusThrottleInterval,pe())}else if(Z==zc)$().revalidateOnReconnect&&S()&&pe();else{if(Z==$c)return X();if(Z==ua)return X(ne)}});return E.current=!1,w.current=k,z.current=!0,T({_k:C}),J&&(b[k]||(Ee(Y)||Zr?pe():Jd(pe))),()=>{E.current=!0,Q()}},[k]),yn(()=>{let pe;function U(){const Q=vt(u)?u(j().data):u;Q&&pe!==-1&&(pe=setTimeout(le,Q))}function le(){!j().error&&(d||$().isVisible())&&(p||$().isOnline())?X(kn).then(U):U()}return U(),()=>{pe&&(clearTimeout(pe),pe=-1)}},[u,d,p,k]),i.useDebugValue(V),a&&Ee(Y)&&k){if(!ha&&Zr)throw new Error("Fallback data is required when using Suspense in SSR.");y.current=r,f.current=o,E.current=!1;const pe=_[k];if(!Ee(pe)){const U=ue(pe);_n(U)}if(Ee(B)){const U=X(kn);Ee(V)||(U.status="fulfilled",U.value=!0),_n(U)}else throw B}return{mutate:ue,get data(){return P.data=!0,V},get error(){return P.error=!0,B},get isValidating(){return P.isValidating=!0,re},get isLoading(){return P.isLoading=!0,fe}}},Ye=fu(mu);async function G(t){if(!t.ok){let o=`HTTP ${t.status}: ${t.statusText}`;try{const n=await t.json();n.message?o=n.message:n.errors&&n.errors.length>0&&(o=n.errors[0].message||o)}catch{}throw new Error(o)}return{data:(await t.json()).data}}function Oc(t){const{client:r}=Ze(),o=i.useCallback(async()=>{const c=await r(`/api/agent/contexts?token=${encodeURIComponent(t)}`,{method:"GET"});return(await G(c)).data},[r,t]),{data:n,error:s,mutate:a}=Ye(t?`wacht-agent-sessions:${t}`:null,o,{revalidateOnFocus:!1}),h=i.useCallback(async c=>{const u=new FormData;u.append("title",c.title),c.system_instructions&&u.append("system_instructions",c.system_instructions);const d=await r(`/api/agent/contexts?token=${encodeURIComponent(t)}`,{method:"POST",body:u}),p=await G(d);return await a(x=>x&&{...x,data:[p.data,...x.data]}),p.data},[r,t,a]),g=i.useCallback(async c=>{await r(`/api/agent/contexts/${c}/delete?token=${encodeURIComponent(t)}`,{method:"POST"}),await a(u=>u&&{...u,data:u.data.filter(d=>d.id!==c)})},[r,t,a]);return{sessions:(n==null?void 0:n.data)||[],loading:!n&&!s,error:s,createSession:h,deleteSession:g,refetch:async()=>{await a()}}}const Ac=i.createContext(void 0);function Xo(){const t=i.useContext(Ac);if(!t)throw new Error("useAgentConversationContext must be used within AgentConversationProvider");return t}function xu({children:t,agentName:r,token:o,platformAdapter:n,defaultSessionId:s,onSessionCreated:a,onSessionDeleted:h,onError:g}){const[c,u]=i.useState(s?{id:s,title:"Conversation",status:"idle",last_activity_at:new Date().toISOString(),created_at:new Date().toISOString()}:null),[d,p]=i.useState(!1),{sessions:x,loading:m,error:v,createSession:b,deleteSession:_,refetch:k}=Oc(o);i.useEffect(()=>{if(s&&x.length>0){const y=x.find(f=>f.id===s);y&&u(y)}},[s,x]);const C=i.useCallback(y=>{u(y),p(!1)},[]),z=i.useCallback(async y=>{try{const f=y||`Chat ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`,$=await b({title:f});return u($),a==null||a($),$}catch(f){const $=f instanceof Error?f.message:"Failed to create session";throw g==null||g($),f}},[b,a,g]),E=i.useCallback(async y=>{try{await _(y),(c==null?void 0:c.id)===y&&u(null),h==null||h(y)}catch(f){const $=f instanceof Error?f.message:"Failed to delete session";throw g==null||g($),f}},[_,c,h,g]),w={agentName:r,token:o,platformAdapter:n,sessions:x,selectedSession:c,loadingSessions:m,sessionError:v,selectSession:C,createSession:z,deleteSession:E,refreshSessions:k,showHistory:d,setShowHistory:p,onSessionCreated:a,onSessionDeleted:h,onError:g};return e.jsx(Ac.Provider,{value:w,children:t})}var Lc=(t=>(t.XOauth="x_oauth",t.GithubOauth="github_oauth",t.GitlabOauth="gitlab_oauth",t.GoogleOauth="google_oauth",t.FacebookOauth="facebook_oauth",t.MicrosoftOauth="microsoft_oauth",t.LinkedinOauth="linkedin_oauth",t.DiscordOauth="discord_oauth",t.AppleOauth="apple_oauth",t))(Lc||{});function vu(t,r){const o={username:bu(t,r),email:yu(t,r),phone:wu(t,r),email_otp:ju(t,r),magic_link:_u(t,r),oauth:ku(t),passkey:Cu(t),generic:Su(t,r)};return function(s){return o[s]}}function bu(t,r){return async({username:o,password:n})=>{var g,c;const s=new FormData;s.append("strategy","plain_username"),s.append("username",o),s.append("password",n);const a=await t("/auth/signin",{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signin_attempts)!=null&&c.length)&&r(h.data.signin_attempts.at(-1)||null),h}}function yu(t,r){return async({email:o,password:n})=>{var g,c;const s=new FormData;s.append("strategy","plain_email"),s.append("email",o),s.append("password",n);const a=await t("/auth/signin",{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signin_attempts)!=null&&c.length)&&r(h.data.signin_attempts.at(-1)||null),h}}function wu(t,r){return async({phone:o})=>{var h,g;const n=new FormData;n.append("strategy","phone_otp"),n.append("phone",o);const s=await t("/auth/signin",{method:"POST",body:n}),a=await G(s);return"data"in a&&((g=(h=a.data)==null?void 0:h.signin_attempts)!=null&&g.length)&&r(a.data.signin_attempts.at(-1)||null),a}}function ju(t,r){return async({email:o})=>{var h,g;const n=new FormData;n.append("strategy","email_otp"),n.append("email",o);const s=await t("/auth/signin",{method:"POST",body:n}),a=await G(s);return"data"in a&&((g=(h=a.data)==null?void 0:h.signin_attempts)!=null&&g.length)&&r(a.data.signin_attempts.at(-1)||null),a}}function _u(t,r){return async({email:o})=>{var h,g;const n=new FormData;n.append("strategy","magic_link"),n.append("email",o);const s=await t("/auth/signin",{method:"POST",body:n}),a=await G(s);return"data"in a&&((g=(h=a.data)==null?void 0:h.signin_attempts)!=null&&g.length)&&r(a.data.signin_attempts.at(-1)||null),a}}function ku(t){return async({provider:r,redirectUri:o})=>{const n=new URLSearchParams({provider:r});o&&n.append("redirect_uri",o);const s=await t(`/auth/oauth2/init?${n.toString()}`,{method:"POST"}),a=await G(s);return"data"in a&&a.data.oauth_url&&(window.location.href=a.data.oauth_url),a}}function Ar(t){const r=new Uint8Array(t);let o="";for(let n=0;n<r.length;n++)o+=String.fromCharCode(r[n]);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function ma(t){const r=t.replace(/-/g,"+").replace(/_/g,"/"),o=r.padEnd(r.length+(4-r.length%4)%4,"="),n=atob(o),s=new Uint8Array(n.length);for(let a=0;a<n.length;a++)s[a]=n.charCodeAt(a);return s.buffer}function Cu(t){return async()=>{var u;const r=await t("/auth/passkey/login/begin",{method:"POST"}),o=await G(r);if(!("data"in o))return o;const n=o.data.options.publicKey,s={challenge:ma(n.challenge),timeout:n.timeout,rpId:n.rpId,userVerification:n.userVerification,allowCredentials:(u=n.allowCredentials)==null?void 0:u.map(d=>({type:d.type,id:ma(d.id),transports:d.transports}))},a=await navigator.credentials.get({publicKey:s});if(!a)throw new Error("Failed to get credential");const h=a.response,g={id:a.id,rawId:Ar(a.rawId),type:a.type,response:{clientDataJSON:Ar(h.clientDataJSON),authenticatorData:Ar(h.authenticatorData),signature:Ar(h.signature),userHandle:h.userHandle?Ar(h.userHandle):null}},c=await t("/auth/passkey/login/finish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});return G(c)}}function Su(t,r){return async({email:o,username:n,password:s,phone:a,strategy:h,token:g})=>{var p,x;const c=new FormData;h&&c.append("strategy",h),o&&c.append("email",o),n&&c.append("username",n),s&&c.append("password",s),a&&c.append("phone",a),g&&c.append("token",g);const u=await t("/auth/signin",{method:"POST",body:c}),d=await G(u);return"data"in d&&((x=(p=d.data)==null?void 0:p.signin_attempts)!=null&&x.length)&&r(d.data.signin_attempts.at(-1)||null),d}}function Dc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(null);return r?{loading:!0,signIn:null,signinAttempt:null,discardSignInAttempt:()=>{n(null)},setSignInAttempt:n}:{loading:!1,signinAttempt:o,signIn:{createStrategy:vu(t,n),completeVerification:async s=>{var c,u;const a=new FormData;a.append("verification_code",s);const h=await t(`/auth/attempt-verification?attempt_identifier=${o==null?void 0:o.id}&identifier_type=signin`,{method:"POST",body:a}),g=await G(h);if("data"in g&&((u=(c=g.data)==null?void 0:c.signin_attempts)!=null&&u.length)){const d=g.data.signin_attempts.at(-1);return n(d||null),g.data}else throw new Error("Verification failed")},prepareVerification:async s=>{var g;const a=new URL("/auth/prepare-verification",window.location.origin);a.searchParams.set("attempt_identifier",((g=o==null?void 0:o.id)==null?void 0:g.toString())||""),a.searchParams.set("strategy",s.strategy),a.searchParams.set("identifier_type","signin"),s.strategy==="phone_otp"&&s.lastDigits?a.searchParams.set("last_digits",s.lastDigits):(s.strategy==="email_otp"&&s.redirectUri||s.strategy==="magic_link"&&s.redirectUri)&&a.searchParams.set("redirect_uri",s.redirectUri);const h=await t(a.pathname+a.search,{method:"POST"});return G(h)},completeProfile:async s=>{var c;if(!o)throw new Error("No signin attempt found");const a=new FormData;for(const[u,d]of Object.entries(s))d&&a.append(u,d);const h=await t(`/auth/complete-profile?attempt_id=${o.id}`,{method:"POST",body:a}),g=await G(h);if("data"in g&&g.data){const u=(c=g.data.signin_attempts)==null?void 0:c.find(d=>d.id===o.id);return u&&n(u),g.data}else throw new Error("Profile completion failed")},identify:async s=>{const a=new FormData;a.append("identifier",s);const h=await t("/auth/identify",{method:"POST",body:a});return(await G(h)).data},initEnterpriseSso:async(s,a)=>{const h=new URLSearchParams({connection_id:s});a&&h.append("redirect_uri",a);const g=await t(`/auth/sso/login?${h.toString()}`,{method:"POST"});return(await G(g)).data}},discardSignInAttempt:()=>{n(null)},setSignInAttempt:n}}function Sr(t){const{loading:r,signIn:o,signinAttempt:n,discardSignInAttempt:s,setSignInAttempt:a}=Dc();if(r)return{loading:!0,signIn:null,signinAttempt:null,discardSignInAttempt:s,setSignInAttempt:a};const h=(()=>{switch(t){case"username":return o.createStrategy("username");case"email":return o.createStrategy("email");case"phone":return o.createStrategy("phone");case"email_otp":return o.createStrategy("email_otp");case"magic_link":return o.createStrategy("magic_link");case"oauth":return o.createStrategy("oauth");case"passkey":return o.createStrategy("passkey");case"generic":return o.createStrategy("generic");default:throw new Error("Invalid sign-in strategy")}})();return{loading:!1,signinAttempt:n,signIn:{create:h,completeVerification:o.completeVerification,prepareVerification:o.prepareVerification,completeProfile:o.completeProfile,identify:o.identify,initEnterpriseSso:o.initEnterpriseSso},discardSignInAttempt:s,setSignInAttempt:a}}function zu(t,r,o){return{create:async n=>{var g,c,u;const s=new FormData;for(const[d,p]of Object.entries(n))s.append(d,p);const a=await t("/auth/signup",{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signup_attempts)!=null&&c.length)&&o(((u=h.data.signup_attempts)==null?void 0:u.at(-1))||null),h},prepareVerification:async n=>{var h;const s=new URL("/auth/prepare-verification",window.location.origin);s.searchParams.set("attempt_identifier",((h=r==null?void 0:r.id)==null?void 0:h.toString())||""),s.searchParams.set("strategy",n.strategy),s.searchParams.set("identifier_type","signup"),n.strategy==="phone_otp"&&n.lastDigits?s.searchParams.set("last_digits",n.lastDigits):n.strategy==="email_otp"&&n.redirectUri&&s.searchParams.set("redirect_uri",n.redirectUri);const a=await t(s.pathname+s.search,{method:"POST"});return G(a)},completeVerification:async n=>{var g,c;const s=new FormData;s.append("verification_code",n);const a=await t(`/auth/attempt-verification?attempt_identifier=${r==null?void 0:r.id}&identifier_type=signup`,{method:"POST",body:s}),h=await G(a);return"data"in h&&((c=(g=h.data)==null?void 0:g.signup_attempts)!=null&&c.length)&&o(h.data.signup_attempts.at(-1)||null),h},validateDeploymentInvitation:async n=>{try{const s=await t(`/deployment/invitations/validate?token=${encodeURIComponent(n)}`,{method:"GET"}),a=await G(s);return"data"in a&&a.data?a.data:{valid:!1,message:"Failed to validate invitation",error_code:"VALIDATION_ERROR"}}catch(s){return{valid:!1,message:s.message||"Failed to validate invitation",error_code:"NETWORK_ERROR"}}}}}function Nc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(null);return r?{loading:!0,signUp:null,signupAttempt:null,discardSignupAttempt:()=>{n(null)}}:{loading:!1,signupAttempt:o,discardSignupAttempt:()=>{n(null)},signUp:zu(t,o,n)}}const tt=()=>{const{adapter:t,deployment:r}=ye(),o=t.useNavigate(),n=(c,u)=>{o?o(c,u):window.location.href=c},s=c=>{if(c)return c;const d=new URLSearchParams(window.location.search).get("redirect_uri");return d||window.location.href};return{navigate:n,navigateToSignIn:c=>{if(!r)return;const u=s(c),d=new URLSearchParams;d.set("redirect_uri",u),(r==null?void 0:r.mode)==="staging"&&d.set("__dev_session__",localStorage.getItem("__dev_session__")??""),n(`${r.ui_settings.sign_in_page_url}?${d.toString()}`,{replace:!0})},navigateToAccountSelection:c=>{if(!r)return;const u=s(c),d=new URLSearchParams;d.set("redirect_uri",u),(r==null?void 0:r.mode)==="staging"&&d.set("__dev_session__",localStorage.getItem("__dev_session__")??""),n(`https://${r.frontend_host}?${d.toString()}`,{replace:!0})},navigateToSignUp:c=>{if(!r)return;const u=s(c),d=new URLSearchParams;d.set("redirect_uri",u),(r==null?void 0:r.mode)==="staging"&&d.set("__dev_session__",localStorage.getItem("__dev_session__")??""),n(`${r.ui_settings.sign_up_page_url}?${d.toString()}`,{replace:!0})}}};async function $u(t){const r=await t("/session",{method:"GET"});return(await G(r)).data}async function Eu(t,r){const o=await t(`/session/switch-sign-in?sign_in_id=${r}`,{method:"POST"});return G(o)}async function Iu(t,r){const o=r?`/session/sign-out?sign_in_id=${r}`:"/session/sign-out",n=await t(o,{method:"POST"});return G(n)}async function Pu(t,r){const o=await t(`/session/switch-organization${r?`?organization_id=${r}`:""}`,{method:"POST"});return G(o)}async function Ru(t,r){const o=await t(`/session/switch-workspace?workspace_id=${r}`,{method:"POST"});return G(o)}const hs=new Map,Vr=new Map;function Tt(){hs.clear(),Vr.clear()}async function Tu(t,r){const o=await t(`/session/token${r?`?template=${r}`:""}`);return G(o)}function Ke(){const{client:t,loading:r}=Ze(),{deployment:o}=ye(),{navigate:n}=tt(),{cache:s}=Mc(),{data:a,error:h,mutate:g,isLoading:c}=Ye(r?null:"/session",()=>$u(t),{refreshInterval:3e4,revalidateOnFocus:!1,revalidateOnReconnect:!1,revalidateIfStale:!1,dedupingInterval:5e3}),u=i.useCallback(async()=>{await g(void 0,{revalidate:!0})},[g]),d=i.useCallback(async(p="default")=>{if(!a)throw new Error("no session");const x=hs.get(p);if(x&&x.expires>Date.now())return(x==null?void 0:x.token)||"";Vr.get(p)||Vr.set(p,Tu(t,p));const m=await Vr.get(p);return Vr.delete(p),hs.set(p,m.data),m.data.token},[t,a==null?void 0:a.active_signin]);return r||!a||c?{loading:!0,error:h,session:null,switchSignIn:null,switchOrganization:null,switchWorkspace:null,signOut:null,getToken:null,refetch:u}:{loading:c,error:h,session:a,switchSignIn:async p=>{await Eu(t,p),Tt(),await Wr("/me/organization-memberships",void 0,{revalidate:!1}),await Wr("/me/workspace-memberships",void 0,{revalidate:!1}),await g(void 0,{revalidate:!0}),await Wr("/me/organization-memberships"),await Wr("/me/workspace-memberships")},signOut:async p=>{await Iu(t,p);const x=["/session","/user","/me/signins","/me/organization-memberships","/me/workspace-memberships","wacht-notifications:channel-counts"],m=["wacht-notifications:","wacht-agent-sessions:","wacht-agent-contexts:","wacht-org-domains:","wacht-api-workspaces:","wacht-api-organizations:"];if(s instanceof Map){const v=Array.from(s.keys());for(const b of v){let _=!1;(x.includes(b)||typeof b=="string"&&m.some(k=>b.startsWith(k)))&&(_=!0),_&&s.delete(b)}}Tt(),await g(void 0,{revalidate:!0}),o!=null&&o.ui_settings&&(p&&o.ui_settings.after_sign_out_one_page_url?n(o.ui_settings.after_sign_out_one_page_url):!p&&o.ui_settings.after_sign_out_all_page_url&&n(o.ui_settings.after_sign_out_all_page_url))},switchOrganization:async p=>{await Pu(t,p),Tt(),await g(void 0,{revalidate:!0})},switchWorkspace:async p=>{await Ru(t,p),Tt(),await g(void 0,{revalidate:!0})},getToken:d,refetch:u}}const en=()=>{const{organizationMemberships:t,refetch:r,loading:o}=Mt(),{client:n}=Ze(),{refetch:s}=Ke(),a=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/roles`,{method:"GET"}))).data,[n]),h=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/members`,{method:"GET"}))).data,[n]),g=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/invitations`,{method:"GET"}))).data,[n]),c=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/domains`,{method:"GET"}))).data,[n]),u=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/members/${I.id}/remove`,{method:"POST"})},[n]),d=i.useCallback(async L=>{const I=new FormData;I.append("name",L.name),L.image&&I.append("image",L.image),L.description&&I.append("description",L.description);const A=await G(await n("/organizations",{method:"POST",body:I}));return Tt(),await r(),await s(),A},[s,r,n]),p=i.useCallback(async(L,I)=>{const A=Object.entries(I).reduce((Y,[B,H])=>(H&&Y.append(B,H),Y),new FormData),q=await G(await n(`/organizations/${L.id}/update`,{method:"POST",body:A}));return await r(),q},[r,n]),x=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/roles/${I.id}/remove`,{method:"POST"})},[n]),m=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("domain",I.fqdn),await G(await n(`/organizations/${L.id}/domains`,{method:"POST",body:A}))},[n]),v=i.useCallback(async(L,I)=>await G(await n(`/organizations/${L.id}/domains/${I.id}/verify`,{method:"POST"})),[n]),b=i.useCallback(async(L,I)=>await G(await n(`/organizations/${L.id}/domains/${I.id}/delete`,{method:"POST"})),[n]),_=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/enterprise-connections`,{method:"GET"}))).data,[n]),k=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("protocol",I.protocol),I.domain_id&&A.append("domain_id",I.domain_id),I.idp_entity_id&&A.append("idp_entity_id",I.idp_entity_id),I.idp_sso_url&&A.append("idp_sso_url",I.idp_sso_url),I.idp_certificate&&A.append("idp_certificate",I.idp_certificate),I.oidc_client_id&&A.append("oidc_client_id",I.oidc_client_id),I.oidc_client_secret&&A.append("oidc_client_secret",I.oidc_client_secret),I.oidc_issuer_url&&A.append("oidc_issuer_url",I.oidc_issuer_url),I.oidc_scopes&&A.append("oidc_scopes",I.oidc_scopes),I.jit_enabled!==void 0&&A.append("jit_enabled",String(I.jit_enabled)),I.attribute_mapping&&A.append("attribute_mapping",JSON.stringify(I.attribute_mapping)),(await G(await n(`/organizations/${L.id}/enterprise-connections`,{method:"POST",body:A}))).data},[n]),C=i.useCallback(async(L,I,A)=>{const q=new FormData;return A.domain_id&&q.append("domain_id",A.domain_id),A.idp_entity_id&&q.append("idp_entity_id",A.idp_entity_id),A.idp_sso_url&&q.append("idp_sso_url",A.idp_sso_url),A.idp_certificate&&q.append("idp_certificate",A.idp_certificate),A.oidc_client_id&&q.append("oidc_client_id",A.oidc_client_id),A.oidc_client_secret&&q.append("oidc_client_secret",A.oidc_client_secret),A.oidc_issuer_url&&q.append("oidc_issuer_url",A.oidc_issuer_url),A.oidc_scopes&&q.append("oidc_scopes",A.oidc_scopes),A.attribute_mapping&&q.append("attribute_mapping",JSON.stringify(A.attribute_mapping)),(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/update`,{method:"POST",body:q}))).data},[n]),z=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/enterprise-connections/${I}/delete`,{method:"POST"})},[n]),E=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("protocol",I.protocol),I.idp_entity_id&&A.append("idp_entity_id",I.idp_entity_id),I.idp_sso_url&&A.append("idp_sso_url",I.idp_sso_url),I.idp_certificate&&A.append("idp_certificate",I.idp_certificate),I.oidc_issuer_url&&A.append("oidc_issuer_url",I.oidc_issuer_url),I.oidc_client_id&&A.append("oidc_client_id",I.oidc_client_id),I.oidc_client_secret&&A.append("oidc_client_secret",I.oidc_client_secret),(await G(await n(`/organizations/${L.id}/enterprise-connections/test`,{method:"POST",body:A}))).data},[n]),w=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/test`,{method:"POST"}))).data,[n]),y=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/scim/token`,{method:"POST"}))).data,[n]),f=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/enterprise-connections/${I}/scim/token`,{method:"GET"}))).data,[n]),$=i.useCallback(async(L,I)=>{await n(`/organizations/${L.id}/enterprise-connections/${I}/scim/token/revoke`,{method:"POST"})},[n]),S=i.useCallback(async(L,I)=>{const A=new FormData;return A.append("name",I.name),I.permissions&&I.permissions.forEach((Y,B)=>{A.append(`permissions[${B}]`,Y)}),await G(await n(`/organizations/${L.id}/roles`,{method:"POST",body:A}))},[n]),j=i.useCallback(async L=>(await G(await n(`/organizations/${L.id}/leave`,{method:"POST"}))).data,[n]),T=i.useCallback(async L=>{const I=await G(await n(`/organizations/${L.id}/delete`,{method:"POST"}));return Tt(),await r(),await s(),I.data},[n,r,s]),R=i.useCallback(async(L,I,A)=>(await G(await n(`/organizations/${L.id}/members/${I.id}/roles/${A.id}/add`,{method:"POST"}))).data,[n]),O=i.useCallback(async(L,I,A)=>(await G(await n(`/organizations/${L.id}/members/${I.id}/roles/${A.id}/remove`,{method:"POST"}))).data,[n]),P=i.useCallback(async(L,I)=>{var Y,B;const A=new FormData;return A.append("email",I.email),A.append("role_id",I.organizationRole.id),(Y=I.workspace)!=null&&Y.id&&A.append("workspace_id",I.workspace.id),(B=I.workspaceRole)!=null&&B.id&&A.append("workspace_role_id",I.workspaceRole.id),(await G(await n(`/organizations/${L.id}/invitations`,{method:"POST",body:A}))).data},[n]),M=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/invitations/${I.id}/discard`,{method:"POST"}))).data,[n]),N=i.useCallback(async(L,I)=>(await G(await n(`/organizations/${L.id}/invitations/${I.id}/resend`,{method:"POST"}))).data,[n]);return{organizations:i.useMemo(()=>t==null?void 0:t.map(L=>L.organization),[t]),loading:o,error:null,refetch:r,leaveOrganization:j,getOrganizationRoles:a,getOrganizationMembers:h,removeOrganizationMember:u,createOrganization:d,getOrganizationInvitations:g,getOrganizationDomains:c,addOrganizationDomain:m,verifyOrganizationDomain:v,removeOrganizationDomain:b,addRoleToOrganizationMember:R,removeRoleFromOrganizationMember:O,inviteOrganizationMember:P,discardOrganizationInvitation:M,resendOrganizationInvitation:N,updateOrganization:p,addRole:S,removeOrganizationRoles:x,deleteOrganization:T,getEnterpriseConnections:_,createEnterpriseConnection:k,updateEnterpriseConnection:C,deleteEnterpriseConnection:z,testEnterpriseConnectionConfig:E,testEnterpriseConnection:w,generateSCIMToken:y,getSCIMToken:f,revokeSCIMToken:$}},nt=()=>{const{loading:t,error:r,refetch:o,getOrganizationMembers:n,getOrganizationRoles:s,leaveOrganization:a,removeOrganizationMember:h,getOrganizationInvitations:g,getOrganizationDomains:c,removeOrganizationDomain:u,addOrganizationDomain:d,verifyOrganizationDomain:p,addRoleToOrganizationMember:x,removeRoleFromOrganizationMember:m,inviteOrganizationMember:v,discardOrganizationInvitation:b,resendOrganizationInvitation:_,updateOrganization:k,removeOrganizationRoles:C,getEnterpriseConnections:z,createEnterpriseConnection:E,updateEnterpriseConnection:w,deleteEnterpriseConnection:y,testEnterpriseConnectionConfig:f,testEnterpriseConnection:$,generateSCIMToken:S,getSCIMToken:j,revokeSCIMToken:T}=en(),{session:R,error:O,loading:P}=Ke(),{organizationMemberships:M}=Mt(),N=i.useMemo(()=>(M==null?void 0:M.find(F=>{var se;return F.id===((se=R==null?void 0:R.active_signin)==null?void 0:se.active_organization_membership_id)}))||null,[M,R]),D=i.useMemo(()=>(N==null?void 0:N.organization)||null,[N]),L=i.useCallback(async F=>D?await k(D,F):[],[D,k]),I=i.useCallback(async()=>D?await n(D):[],[D,n]),A=i.useCallback(async()=>D?await s(D):[],[D,s]),q=i.useCallback(async F=>D?await h(D,F):[],[D,h]),Y=i.useCallback(async F=>D?await C(D,F):void 0,[D,C]),B=i.useCallback(async()=>D?await c(D):[],[D,c]),H=i.useCallback(async F=>D?await d(D,F):void 0,[D,d]),V=i.useCallback(async F=>D?await p(D,F):void 0,[D,p]),J=i.useCallback(async F=>D?await u(D,F):void 0,[D,u]),oe=i.useCallback(async(F,se)=>D?await x(D,F,se):void 0,[D,x]),re=i.useCallback(async(F,se)=>D?await m(D,F,se):void 0,[D,m]),fe=i.useCallback(async F=>D?await v(D,F):void 0,[D,v]),X=i.useCallback(async F=>D?await b(D,F):void 0,[D,b]),ue=i.useCallback(async F=>D?await _(D,F):void 0,[D,_]),ve=i.useCallback(async()=>{D&&await a(D)},[D,a]),pe=i.useCallback(async()=>D?await g(D):[],[D,g]),U=i.useCallback(async()=>D?await z(D):[],[D,z]),le=i.useCallback(async F=>{if(D)return await E(D,F)},[D,E]),Q=i.useCallback(async(F,se)=>{if(D)return await w(D,F,se)},[D,w]),Z=i.useCallback(async F=>{D&&await y(D,F)},[D,y]),ne=i.useCallback(async F=>D?await f(D,F):null,[D,f]),me=i.useCallback(async F=>D?await $(D,F):null,[D,$]),de=i.useCallback(async F=>{if(D)return await S(D,F)},[D,S]),ee=i.useCallback(async F=>{if(D)return await j(D,F)},[D,j]),W=i.useCallback(async F=>{D&&await T(D,F)},[D,T]);return P||t?{activeOrganization:null,activeMembership:null,loading:!0,error:O||r,updateOrganization:null,getRoles:null,getMembers:null,getDomains:null,addDomain:null,verifyDomain:null,removeDomain:null,removeRole:null,getInvitations:null,removeMember:null,addMemberRole:null,removeMemberRole:null,inviteMember:null,discardInvitation:null,resendInvitation:null,leave:null,getEnterpriseConnections:null,createEnterpriseConnection:null,updateEnterpriseConnection:null,deleteEnterpriseConnection:null,generateSCIMToken:null,getSCIMToken:null,revokeSCIMToken:null}:{activeOrganization:D,activeMembership:N,loading:!1,refetch:o,getRoles:A,updateOrganization:L,getMembers:I,getDomains:B,addDomain:H,verifyDomain:V,removeDomain:J,getInvitations:pe,removeMember:q,leave:ve,removeRole:Y,addMemberRole:oe,removeMemberRole:re,inviteMember:fe,discardInvitation:X,resendInvitation:ue,getEnterpriseConnections:U,createEnterpriseConnection:le,updateEnterpriseConnection:Q,deleteEnterpriseConnection:Z,testEnterpriseConnectionConfig:ne,testEnterpriseConnection:me,generateSCIMToken:de,getSCIMToken:ee,revokeSCIMToken:W,error:null}};async function Mu(t){return(await G(await t("/me/organization-memberships"))).data}const Mt=()=>{const{client:t,loading:r}=Ze(),{data:o,isLoading:n,error:s,mutate:a}=Ye(r?null:"/me/organization-memberships",()=>Mu(t),{refreshInterval:3e4,revalidateOnFocus:!1,revalidateOnReconnect:!1,revalidateIfStale:!1,dedupingInterval:5e3}),h=i.useCallback(async()=>{await a(void 0,{revalidate:!0})},[a]);return{organizationMemberships:o,loading:r||n,error:s,refetch:h}};async function Ou(t){return(await G(await t("/me/workspace-memberships"))).data}async function Au(t,r,o){return(await G(await t(`/workspaces/${r}/members/${o}/remove`,{method:"POST"}))).data}const tn=()=>{const{client:t,loading:r}=Ze(),{deployment:o}=ye(),{data:n,isLoading:s,error:a,mutate:h}=Ye(!r&&(o!=null&&o.b2b_settings.workspaces_enabled)?"/me/workspace-memberships":null,()=>Ou(t),{refreshInterval:3e4,revalidateOnFocus:!1,revalidateOnReconnect:!1,revalidateIfStale:!1,dedupingInterval:5e3}),g=i.useCallback(async()=>{await h(void 0,{revalidate:!0})},[h]);return{workspaceMemberships:n,loading:r||s,error:a,refetch:g}},Bt=()=>{const{workspaceMemberships:t,refetch:r,loading:o,error:n}=tn(),{client:s}=Ze(),a=i.useMemo(()=>t==null?void 0:t.map(w=>({...w.workspace,organization:w.organization,eligibility_restriction:w.eligibility_restriction})),[t]),h=i.useCallback(async(w,y,f,$)=>{const S=new FormData;S.append("name",y),f&&S.append("image",f),$&&S.append("description",$),S.append("organization_id",w);const j=await G(await s("/workspaces",{method:"POST",body:S}));return Tt(),await r(),j.data},[s,r]),g=i.useCallback(async(w,y)=>{const f=await Au(s,w,y);return await r(),f},[s,r]),c=i.useCallback(async(w,y)=>{const f=new FormData;y.name&&f.append("name",y.name),y.description&&f.append("description",y.description),y.image&&f.append("image",y.image),y.enforce_2fa!==void 0&&f.append("enforce_2fa",String(y.enforce_2fa)),y.enable_ip_restriction!==void 0&&f.append("enable_ip_restriction",String(y.enable_ip_restriction)),y.whitelisted_ips&&y.whitelisted_ips.forEach(S=>f.append("whitelisted_ips",S));const $=await G(await s(`/workspaces/${w.id}/update`,{method:"POST",body:f}));return await r(),$.data},[s,r]),u=i.useCallback(async w=>{const y=await G(await s(`/workspaces/${w.id}/delete`,{method:"POST"}));return Tt(),await r(),y.data},[s,r]),d=i.useCallback(async w=>(await G(await s(`/workspaces/${w.id}/members`,{method:"GET"}))).data,[s]),p=i.useCallback(async w=>(await G(await s(`/workspaces/${w.id}/roles`,{method:"GET"}))).data,[s]),x=i.useCallback(async(w,y,f)=>{const $=new FormData;return $.append("name",y),f.forEach(j=>$.append("permissions",j)),(await G(await s(`/workspaces/${w.id}/roles`,{method:"POST",body:$}))).data},[s]),m=i.useCallback(async(w,y)=>(await G(await s(`/workspaces/${w.id}/roles/${y.id}/delete`,{method:"POST"}))).data,[s]),v=i.useCallback(async(w,y)=>{const f=await G(await s(`/workspaces/${w.id}/members/${y}/remove`,{method:"POST"}));return await r(),f.data},[s,r]),b=i.useCallback(async(w,y,f)=>(await G(await s(`/workspaces/${w.id}/members/${y}/roles/${f}/add`,{method:"POST"}))).data,[s]),_=i.useCallback(async(w,y,f)=>(await G(await s(`/workspaces/${w.id}/members/${y}/roles/${f}/remove`,{method:"POST"}))).data,[s]),k=i.useCallback(async w=>(await G(await s(`/organizations/${w.organization.id}/invitations`,{method:"GET"}))).data.filter(f=>String(f.workspace_id)===String(w.id)),[s]),C=i.useCallback(async(w,y,f)=>{const $=new FormData;return $.append("email",y),$.append("workspace_id",w.id),f&&$.append("workspace_role_id",f),(await G(await s(`/organizations/${w.organization.id}/invitations`,{method:"POST",body:$}))).data},[s]),z=i.useCallback(async(w,y)=>(await G(await s(`/organizations/${w.organization.id}/invitations/${y}/discard`,{method:"POST"}))).data,[s]),E=i.useCallback(async(w,y)=>(await G(await s(`/organizations/${w.organization.id}/invitations/${y}/resend`,{method:"POST"}))).data,[s]);return{workspaces:a||[],loading:o,error:n,refetch:r,leaveWorkspace:g,createWorkspace:h,updateWorkspace:c,deleteWorkspace:u,getWorkspaceMembers:d,getWorkspaceRoles:p,createWorkspaceRole:x,deleteWorkspaceRole:m,removeWorkspaceMember:v,addWorkspaceMemberRole:b,removeWorkspaceMemberRole:_,getWorkspaceInvitations:k,createWorkspaceInvitation:C,discardWorkspaceInvitation:z,resendWorkspaceInvitation:E}},Ut=()=>{const{refetch:t,loading:r,error:o,workspaces:n,leaveWorkspace:s,updateWorkspace:a,deleteWorkspace:h,getWorkspaceMembers:g,getWorkspaceRoles:c,createWorkspaceRole:u,deleteWorkspaceRole:d,removeWorkspaceMember:p,addWorkspaceMemberRole:x,removeWorkspaceMemberRole:m,getWorkspaceInvitations:v,createWorkspaceInvitation:b,discardWorkspaceInvitation:_,resendWorkspaceInvitation:k}=Bt(),{workspaceMemberships:C}=tn(),{session:z,loading:E,error:w}=Ke(),y=i.useMemo(()=>(C==null?void 0:C.find(V=>{var J;return V.id===((J=z==null?void 0:z.active_signin)==null?void 0:J.active_workspace_membership_id)}))||null,[C,z]),f=i.useMemo(()=>(y==null?void 0:y.workspace)||null,[y]),$=i.useCallback(async()=>{var V;if(!(!f||!((V=z==null?void 0:z.active_signin)!=null&&V.user_id)))return await s(f.id,z.active_signin.user_id)},[f,s,z]),S=i.useCallback(async V=>{if(f)return await a(f,V)},[f,a]),j=i.useCallback(async()=>{if(f)return await h(f)},[f,h]),T=i.useCallback(async()=>f?await g(f):[],[f,g]),R=i.useCallback(async()=>f?await c(f):[],[f,c]),O=i.useCallback(async(V,J)=>{if(f)return await u(f,V,J)},[f,u]),P=i.useCallback(async V=>{if(f)return await d(f,V)},[f,d]),M=i.useCallback(async V=>{if(f)return await p(f,V)},[f,p]),N=i.useCallback(async(V,J)=>{if(f)return await x(f,V,J)},[f,x]),D=i.useCallback(async(V,J)=>{if(f)return await m(f,V,J)},[f,m]),L=i.useMemo(()=>(n==null?void 0:n.find(V=>V.id===(f==null?void 0:f.id)))||null,[n,f]),I=i.useCallback(async()=>L?await v(L):[],[L,v]),A=i.useCallback(async(V,J)=>{if(L)return await b(L,V,J)},[L,b]),q=i.useCallback(async V=>{if(L)return await _(L,V)},[L,_]),Y=i.useCallback(async V=>{if(L)return await k(L,V)},[L,k]),B=r||E,H=o||w;return B?{activeWorkspace:null,activeMembership:null,loading:!0,error:H,refetch:t,leave:null,updateWorkspace:null,deleteWorkspace:null,getMembers:null,getRoles:null,createRole:null,deleteRole:null,inviteMember:null,removeMember:null,addMemberRole:null,removeMemberRole:null,getInvitations:null,discardInvitation:null,resendInvitation:null}:{activeWorkspace:f,activeMembership:y,loading:!1,error:H,refetch:t,leave:$,updateWorkspace:S,deleteWorkspace:j,getMembers:T,getRoles:R,createRole:O,deleteRole:P,inviteMember:A,removeMember:M,addMemberRole:N,removeMemberRole:D,getInvitations:I,discardInvitation:q,resendInvitation:Y}};function Cn(t){const r=new Uint8Array(t);let o="";for(let n=0;n<r.length;n++)o+=String.fromCharCode(r[n]);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Sn(t){const r=t.replace(/-/g,"+").replace(/_/g,"/"),o=r.padEnd(r.length+(4-r.length%4)%4,"="),n=atob(o),s=new Uint8Array(n.length);for(let a=0;a<n.length;a++)s[a]=n.charCodeAt(a);return s.buffer}const Lu=async t=>(await G(await t("/me"))).data,Du=async t=>(await G(await t("/me/signins"))).data;function Wt(){const{client:t,loading:r}=Ze(),{data:o,error:n,isLoading:s,mutate:a}=Ye(r?null:"/user",()=>Lu(t)),h=async L=>{const I=new FormData;for(const[q,Y]of Object.entries(L))Y!=null&&Y!==""&&I.append(q,String(Y));const A=await G(await t("/me",{method:"POST",body:I}));return a(),A},g=async()=>await G(await t("/me/email-addresses",{method:"GET"})),c=async L=>await G(await t(`/me/email-addresses/${L}`,{method:"GET"})),u=async L=>{const I=new FormData;return I.append("email",L),await G(await t("/me/email-addresses",{method:"POST",body:I}))},d=async L=>await G(await t(`/me/email-addresses/${L}/delete`,{method:"POST"})),p=async L=>await G(await t(`/me/email-addresses/${L}/prepare-verification`,{method:"POST"})),x=async(L,I)=>await G(await t(`/me/email-addresses/${L}/attempt-verification?code=${I}`,{method:"POST"})),m=async(L,I)=>{const A=new FormData;return A.append("phone_number",L),A.append("country_code",I),await G(await t("/me/phone-numbers",{method:"POST",body:A}))},v=async L=>await G(await t(`/me/phone-numbers/${L}/delete`,{method:"POST"})),b=async L=>await G(await t(`/me/phone-numbers/${L}/prepare-verification`,{method:"POST"})),_=async(L,I)=>{const A=new FormData;return A.append("code",I),await G(await t(`/me/phone-numbers/${L}/attempt-verification`,{method:"POST",body:A}))},k=async L=>{const I=await G(await t(`/me/phone-numbers/${L}/make-primary`,{method:"POST"}));return a(),I},C=async L=>await G(await t(`/me/email-addresses/${L}/make-primary`,{method:"POST"})),z=async()=>(await G(await t("/me/authenticator",{method:"POST"}))).data,E=async(L,I)=>{const A=new FormData;return A.append("authenticator_id",L),I.forEach(Y=>{A.append("codes",Y)}),await G(await t("/me/authenticator/attempt-verification",{method:"POST",body:A}))},w=async L=>await G(await t(`/me/authenticator/${L}/delete`,{method:"POST"})),y=async()=>(await G(await t("/me/backup-codes",{method:"POST"}))).data,f=async L=>{const I=new FormData;return I.append("file",L),await G(await t("/me/profile-picture",{method:"POST",body:I}))},$=async()=>(await G(await t("/me/backup-codes/regenerate",{method:"POST"}))).data,S=async(L,I)=>{const A=new FormData;return A.append("current_password",L),A.append("new_password",I),await G(await t("/me/update-password",{method:"POST",body:A}))},j=async L=>{const I=new FormData;I.append("current_password",L);const A=await G(await t("/me/remove-password",{method:"POST",body:I}));return a(),A},T=async L=>{const I=new FormData;return I.append("password",L),await G(await t("/me/account/delete",{method:"POST",body:I}))},R=async L=>await G(await t(`/me/social-connections/${L}/disconnect`,{method:"POST"})),O=async({provider:L,redirectUri:I})=>{var Y;const A=new URLSearchParams({provider:L});I&&A.append("redirect_uri",I);const q=await G(await t(`/me/init-sso-connection?${A.toString()}`,{method:"POST"}));return"data"in q&&((Y=q.data)!=null&&Y.oauth_url)&&window.open(q.data.oauth_url,"_blank"),q},P=async()=>await G(await t("/me/passkeys",{method:"GET"})),M=async L=>{var J,oe;const I=await G(await t("/me/passkeys/register/begin",{method:"POST"}));if(!("data"in I))return I;const A=I.data.options.publicKey,q={challenge:Sn(A.challenge),rp:A.rp,user:{id:Sn(A.user.id),name:A.user.name,displayName:A.user.displayName},pubKeyCredParams:A.pubKeyCredParams,timeout:A.timeout,attestation:A.attestation,authenticatorSelection:A.authenticatorSelection,excludeCredentials:(J=A.excludeCredentials)==null?void 0:J.map(re=>({type:re.type,id:Sn(re.id),transports:re.transports}))},Y=await navigator.credentials.create({publicKey:q});if(!Y)throw new Error("Failed to create credential");const B=Y.response,H={id:Y.id,rawId:Cn(Y.rawId),type:Y.type,response:{clientDataJSON:Cn(B.clientDataJSON),attestationObject:Cn(B.attestationObject),transports:((oe=B.getTransports)==null?void 0:oe.call(B))||[]}};return await G(await t(`/me/passkeys/register/finish?name=${encodeURIComponent(L||"")}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(H)}))},N=async L=>await G(await t(`/me/passkeys/${L}/delete`,{method:"POST"})),D=async(L,I)=>await G(await t(`/me/passkeys/${L}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:I})}));return{user:{...o,refetch:a},loading:r||s,error:n||null,updateProfile:h,getEmailAddresses:g,getEmailAddress:c,createEmailAddress:u,deleteEmailAddress:d,prepareEmailVerification:p,attemptEmailVerification:x,makeEmailPrimary:C,createPhoneNumber:m,deletePhoneNumber:v,preparePhoneVerification:b,attemptPhoneVerification:_,makePhonePrimary:k,setupAuthenticator:z,verifyAuthenticator:E,deleteAuthenticator:w,generateBackupCodes:y,regenerateBackupCodes:$,updateProfilePicture:f,disconnectSocialConnection:R,connectSocialAccount:O,updatePassword:S,removePassword:j,deleteAccount:T,getPasskeys:P,registerPasskey:M,deletePasskey:N,renamePasskey:D}}function Fc(){const{client:t,loading:r}=Ze(),{data:o,error:n,isLoading:s,mutate:a}=Ye(r?null:"/me/signins",()=>Du(t));return{signins:o,error:n||null,removeSignin:async g=>await G(await t(`/me/signins/${g}/signout`,{method:"POST"})),refetch:a,loading:s||r}}function Nu(){const{session:t,loading:r}=Ke(),{loading:o,organizationMemberships:n}=Mt(),{loading:s,workspaceMemberships:a}=tn();if(r||o||s)return{loading:!0,orgMembership:null,workspaceMembership:null};const h=i.useMemo(()=>!t||!t.signins||t.signins.length===0?null:n==null?void 0:n.find(c=>{var u;return c.id===((u=t.active_signin)==null?void 0:u.active_organization_membership_id)}),[t]),g=i.useMemo(()=>!t||!t.signins||t.signins.length===0?null:a==null?void 0:a.find(c=>{var u;return c.id===((u=t.active_signin)==null?void 0:u.active_workspace_membership_id)}),[t]);return{loading:!1,orgMembership:h,workspaceMembership:g}}function Bc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(!1),s=async a=>{n(!0);try{const h=new FormData;for(const[u,d]of Object.entries(a))d&&h.append(u,d);const g=await t("/waitlist/join",{method:"POST",body:h});return await G(g)}finally{n(!1)}};return r?{loading:!0,joinWaitlist:null}:{loading:o,joinWaitlist:s}}function Uc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(!1),[s,a]=i.useState(null),[h,g]=i.useState(null),[c,u]=i.useState(null),[d,p]=i.useState(!1),[x,m]=i.useState(null);i.useEffect(()=>{if(d||r)return;const b=new URLSearchParams(window.location.search),_=b.get("code"),k=b.get("state"),C=b.get("error"),z=b.get("error_description");if(!_&&!C){p(!0);const E=new Error("No OAuth callback data found.");a(E);return}if(p(!0),n(!0),C){const E=z||C,w=new Error(`OAuth Error: ${E}`);a(w),n(!1);return}if(_&&k)v(_,k);else{const E=new Error("Missing required OAuth parameters");a(E),n(!1)}},[d,r]);const v=async(b,_)=>{try{let k,C;try{const w=_.split(".");if(w.length!==2)throw new Error("Invalid OAuth state format - missing signature");const y=w[0].replace(/-/g,"+").replace(/_/g,"/"),f=y.length%4?"=".repeat(4-y.length%4):"",S=atob(y+f).split("|")[0];if(S==="sign_in")k="/auth/oauth2/callback",C="GET";else if(S==="connect_social")k="/me/sso-connection-callback",C="POST";else throw new Error(`Unknown OAuth action: ${S}`)}catch(w){const y=w instanceof Error?w:new Error("Failed to parse OAuth state");a(new Error(`Invalid OAuth callback: ${y.message}. The authorization link may be expired or malformed. Please try signing in again.`)),n(!1);return}const z=await t(`${k}?code=${encodeURIComponent(b)}&state=${encodeURIComponent(_)}`,{method:C}),E=await G(z);if("data"in E){const w=E.data.session,y=E.data.redirect_uri||null;if(g(w),u(y),w.signin_attempts&&w.signin_attempts.length>0){const f=w.signin_attempts.at(-1);f&&m(f)}}else{const w=new Error("SSO callback failed");a(w)}}catch(k){const C=k instanceof Error?k:new Error("Unknown error occurred");a(C)}finally{n(!1)}};return{loading:o,error:s,session:h,redirectUri:c,processed:d,signinAttempt:x}}function Wc(){const{client:t,loading:r}=Ze(),[o,n]=i.useState(!1),[s,a]=i.useState(null);return{loading:r||o,verifyMagicLink:async g=>{if(!g.token||!g.attempt)throw new Error("Invalid magic link parameters");n(!0),a(null);try{const c=new URL("/auth/verify-magic-link",window.location.origin);c.searchParams.set("token",g.token),c.searchParams.set("attempt",g.attempt),g.redirectUri&&c.searchParams.set("redirect_uri",g.redirectUri);const u=await t(c.pathname+c.search,{method:"GET"}),d=await G(u);return n(!1),a(!0),d}catch(c){throw n(!1),a(!1),c}},success:s}}function Vc(){const[t,r]=i.useState({});return i.useEffect(()=>{const o=new URLSearchParams(window.location.search);r({token:o.get("token")||void 0,attempt:o.get("attempt")||void 0,redirectUri:o.get("redirect_uri")||void 0})},[]),t}function Gc(){const{client:t,loading:r}=Ze();return{loading:r,forgotPassword:async a=>{const h=new FormData;h.append("email",a);const g=await t("/auth/forgot-password",{method:"POST",body:h});return await G(g)},verifyOtp:async(a,h)=>{const g=new FormData;g.append("email",a),g.append("otp",h);const c=await t("/auth/forgot-password",{method:"POST",body:g});return await G(c)},resetPassword:async(a,h)=>{const g=new FormData;g.append("token",a),g.append("password",h);const c=await t("/auth/reset-password",{method:"POST",body:g});return await G(c)}}}function Hc({enabled:t=!0,channels:r,organizationIds:o,workspaceIds:n,onNotification:s,onError:a,reconnectDelay:h=1e3,maxReconnectAttempts:g=5}={}){const{session:c,loading:u}=Ke(),{deployment:d,loading:p}=ye(),[x,m]=i.useState(!1),[v,b]=i.useState(null),_=i.useRef(null),k=i.useRef(null),C=i.useRef(0),z=i.useRef(null),E=i.useRef(s),w=i.useRef(a),y=i.useRef(r),f=i.useRef(o),$=i.useRef(n),S=i.useRef(h),j=i.useRef(g);E.current=s,w.current=a,y.current=r,f.current=o,$.current=n,S.current=h,j.current=g;const T=i.useCallback(()=>{k.current&&(clearTimeout(k.current),k.current=null),z.current&&(clearInterval(z.current),z.current=null),_.current&&(_.current.close(),_.current=null)},[]),R=i.useCallback(async()=>{var L;if(!t||u||p||!c||!d)return;T();const M=new URL(d.backend_host),N=M.protocol==="https:"?"wss:":"ws:",D=new URL("/realtime/notifications",`${N}//${M.host}`);if(d.mode==="staging"){const I=localStorage.getItem("__dev_session__");I&&D.searchParams.set("__dev_session__",I)}y.current&&y.current.length>0&&y.current.forEach(I=>D.searchParams.append("channels",I)),f.current&&f.current.length>0&&f.current.forEach(I=>D.searchParams.append("organization_ids",I.toString())),$.current&&$.current.length>0&&$.current.forEach(I=>D.searchParams.append("workspace_ids",I.toString()));try{const I=new WebSocket(D.toString());_.current=I,I.onopen=()=>{m(!0),b(null),C.current=0,z.current=setInterval(()=>{I.readyState===WebSocket.OPEN&&I.send("ping")},3e4)},I.onmessage=A=>{var q,Y;try{const B=JSON.parse(A.data);if(B.type==="notification"&&B.data)(q=E.current)==null||q.call(E,B.data);else if(B.type==="error"){const H=B.error||"Unknown error occurred";b(H),(Y=w.current)==null||Y.call(w,H)}else B.type}catch{}},I.onerror=()=>{var A;b("Connection error occurred"),(A=w.current)==null||A.call(w,"Connection error occurred")},I.onclose=A=>{var q;if(m(!1),z.current&&(clearInterval(z.current),z.current=null),t&&A.code!==1e3&&C.current<j.current){C.current++;const Y=S.current*Math.pow(2,C.current-1);k.current=setTimeout(()=>{R()},Y)}else C.current>=j.current&&(b("Max reconnection attempts reached"),(q=w.current)==null||q.call(w,"Max reconnection attempts reached"))}}catch{b("Failed to connect"),(L=w.current)==null||L.call(w,"Failed to connect")}},[t,u,p,c,d,T]);i.useEffect(()=>(R(),()=>{T()}),[R,T]),i.useEffect(()=>{_.current&&_.current.readyState===WebSocket.OPEN&&R()},[r,o,n,R]);const O=i.useCallback(()=>{T(),m(!1)},[T]),P=i.useCallback(()=>{C.current=0,R()},[R]);return{isConnected:x,connectionError:v,disconnect:O,reconnect:P}}async function Fu(t,r){const o=new URLSearchParams;r&&(r.limit&&o.append("limit",r.limit.toString()),r.offset&&o.append("offset",r.offset.toString()),r.channels&&r.channels.forEach(h=>o.append("channels",h)),r.organization_ids&&r.organization_ids.forEach(h=>o.append("organization_ids",h.toString())),r.workspace_ids&&r.workspace_ids.forEach(h=>o.append("workspace_ids",h.toString())),r.is_read!==void 0&&o.append("is_read",r.is_read.toString()),r.is_archived!==void 0&&o.append("is_archived",r.is_archived.toString()),r.severity&&o.append("severity",r.severity));const n=`/notifications${o.toString()?"?"+o.toString():""}`,s=await t(n,{method:"GET"});return(await G(s)).data}async function Bu(t){const r=await t("/notifications/channel-counts",{method:"GET"});return(await G(r)).data}async function Uu(t,r){const o=await t(`/notifications/${r}/read`,{method:"POST"});return G(o)}async function Wu(t){const r=await t("/notifications/mark-all-read",{method:"POST"});return G(r)}async function Vu(t,r){const o=await t(`/notifications/${r}/delete`,{method:"POST"});return G(o)}function qc(t){const{client:r,loading:o}=Ze(),{data:n,error:s,mutate:a,isLoading:h}=Ye(o?null:`wacht-notifications:${JSON.stringify(t)}`,()=>Fu(r,t),{refreshInterval:6e4,revalidateOnFocus:!0});Hc({enabled:!o&&!!n,onNotification:i.useCallback(p=>{a(async x=>!x||x.notifications.some(v=>v.id===p.id.toString())?x:{...x,notifications:[{id:p.id.toString(),user_id:p.user_id.toString(),deployment_id:p.deployment_id.toString(),title:p.title,body:p.body,severity:p.severity,action_url:p.action_url,action_label:p.action_label,is_read:!1,is_archived:!1,created_at:p.created_at,updated_at:p.created_at},...x.notifications],unread_count:x.unread_count+1,total:x.total+1},!1)},[a]),onError:i.useCallback(()=>{},[])});const g=i.useCallback(async p=>{o||(await a(async x=>x&&{...x,notifications:x.notifications.map(m=>m.id===p?{...m,is_read:!0}:m),unread_count:Math.max(0,x.unread_count-1)},!1),await Uu(r,p),await a())},[r,o,a]),c=i.useCallback(async()=>{o||(await a(async p=>p&&{...p,notifications:p.notifications.map(x=>({...x,is_read:!0})),unread_count:0},!1),await Wu(r),await a())},[r,a]),u=i.useCallback(async p=>{o||(await a(async x=>{if(!x)return x;const m=x.notifications.find(v=>v.id===p);return{...x,notifications:x.notifications.filter(v=>v.id!==p),unread_count:m&&!m.is_read?Math.max(0,x.unread_count-1):x.unread_count,total:Math.max(0,x.total-1)}},!1),await Vu(r,p),await a())},[r,o,a]),d=i.useCallback(async()=>{await a()},[a]);return!n||o||h?{loading:!0,notifications:void 0,unreadCount:void 0,unreadCounts:void 0,channels:void 0,hasMore:void 0,markAsRead:void 0,markAllAsRead:void 0,deleteNotification:void 0,error:s,refetch:d}:{loading:!1,error:s,notifications:n.notifications,unreadCount:n.unread_count,unreadCounts:n.unread_counts,channels:n.channels,hasMore:n.has_more,markAsRead:g,markAllAsRead:c,deleteNotification:u,refetch:d}}async function Gu(t){const r=await t("/notifications/channel-counts",{method:"GET"});return(await G(r)).data}function Hu(){const{client:t,loading:r}=Ze(),{data:o,error:n,mutate:s}=Ye(r?null:"wacht-notifications:channel-counts",()=>Gu(t),{refreshInterval:3e4,revalidateOnFocus:!0}),a=async()=>{await s()};return!o||r?{loading:!0,counts:void 0,error:n,refetch:a}:{loading:!1,counts:o,error:n,refetch:a}}const sr=class sr{constructor(){lt(this,"ws",null);lt(this,"messageHandlers",new Set);lt(this,"connectionStateHandlers",new Set);lt(this,"reconnectTimer",null);lt(this,"reconnectAttempts",0);lt(this,"url",null);lt(this,"isIntentionalDisconnect",!1);lt(this,"sessionMessages",{});lt(this,"currentSessionKey",null)}static getInstance(){return sr.instance||(sr.instance=new sr),sr.instance}connect(r){var o,n;if(this.url=r,this.isIntentionalDisconnect=!1,((o=this.ws)==null?void 0:o.readyState)===WebSocket.OPEN&&this.url===r){this.notifyConnectionState({isConnected:!0});return}((n=this.ws)==null?void 0:n.readyState)!==WebSocket.CONNECTING&&this.createConnection()}createConnection(){if(this.url)try{this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.reconnectAttempts=0,this.notifyConnectionState({isConnected:!0})},this.ws.onmessage=r=>{try{const o=JSON.parse(r.data);this.notifyMessageHandlers(o)}catch{}},this.ws.onerror=()=>{this.notifyConnectionState({isConnected:!1,error:"Connection error"})},this.ws.onclose=()=>{this.ws=null,this.notifyConnectionState({isConnected:!1}),this.isIntentionalDisconnect||this.scheduleReconnect()}}catch(r){this.notifyConnectionState({isConnected:!1,error:r instanceof Error?r.message:"Failed to connect"})}}scheduleReconnect(){this.reconnectAttempts++;const r=Math.min(1e3*Math.pow(2,this.reconnectAttempts-1),3e4),o=Math.random()*.3*r,n=Math.floor(r+o);this.reconnectTimer=setTimeout(()=>{this.createConnection()},n)}disconnect(){this.isIntentionalDisconnect=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws&&(this.ws.close(),this.ws=null)}send(r){var o;if(((o=this.ws)==null?void 0:o.readyState)===WebSocket.OPEN){const n=JSON.stringify(r);this.ws.send(n)}}onMessage(r){return this.messageHandlers.add(r),()=>{this.messageHandlers.delete(r)}}onConnectionStateChange(r){var o;return this.connectionStateHandlers.add(r),r({isConnected:((o=this.ws)==null?void 0:o.readyState)===WebSocket.OPEN}),()=>{this.connectionStateHandlers.delete(r)}}notifyMessageHandlers(r){this.messageHandlers.forEach(o=>{try{o(r)}catch{}})}notifyConnectionState(r){this.connectionStateHandlers.forEach(o=>{try{o(r)}catch{}})}isConnected(){var r;return((r=this.ws)==null?void 0:r.readyState)===WebSocket.OPEN}setCurrentSession(r){this.currentSessionKey=r,this.sessionMessages[r]||(this.sessionMessages[r]=[])}addMessage(r){this.currentSessionKey&&(this.sessionMessages[this.currentSessionKey]||(this.sessionMessages[this.currentSessionKey]=[]),this.sessionMessages[this.currentSessionKey].push(r))}getSessionMessages(r){return this.sessionMessages[r]||[]}clearSessionMessages(r){this.sessionMessages[r]&&(this.sessionMessages[r]=[])}};lt(sr,"instance");let fs=sr;const st=fs.getInstance(),Pt={DISCONNECTED:"disconnected",CONNECTING:"connecting",CONNECTED:"connected",ERROR:"error"},Ge={IDLE:"idle",STARTING:"starting",RUNNING:"running",WAITING_FOR_INPUT:"waiting_for_input",COMPLETED:"completed",FAILED:"failed"},qt={IDLE:"Idle",STARTING:"Starting",RUNNING:"Running",WAITING_FOR_INPUT:"WaitingForInput",COMPLETED:"Completed",FAILED:"Failed",CANCELLED:"Cancelled"};function xa(t){switch(t){case qt.IDLE:return Ge.IDLE;case qt.STARTING:return Ge.STARTING;case qt.RUNNING:return Ge.RUNNING;case qt.WAITING_FOR_INPUT:return Ge.WAITING_FOR_INPUT;case qt.COMPLETED:return Ge.COMPLETED;case qt.FAILED:case qt.CANCELLED:return Ge.FAILED;default:return Ge.IDLE}}function va(t){return t===Ge.STARTING||t===Ge.RUNNING||t===Ge.WAITING_FOR_INPUT}function Yc({contextId:t,agentName:r,token:o,platformAdapter:n,autoConnect:s=!0}){const{deployment:a}=ye(),{client:h}=Ze(),[g,c]=i.useState([]),[u,d]=i.useState(null),[p,x]=i.useState(null),[m,v]=i.useState(!1),[b,_]=i.useState(!1),[k,C]=i.useState(Ge.IDLE),[z,E]=i.useState({status:Pt.DISCONNECTED}),[w,y]=i.useState(!0),[f,$]=i.useState(!1),S=i.useRef(null),j=i.useRef(null),T=i.useCallback(B=>{var H,V;switch(B.message_type){case"session_connected":if(v(!0),E({status:Pt.CONNECTED}),(H=B.data)!=null&&H.execution_status){const oe=B.data.execution_status,re=xa(oe);C(re),_(va(re))}break;case"conversation_message":R(B.data);break;case"user_input_request":O(B.data);break;case"platform_event":P(B.data);break;case"platform_function":M(B.data);break;case"execution_complete":_(!1),C(Ge.IDLE),j.current=null;break;case"execution_error":_(!1),C(Ge.FAILED),j.current=null;break;case"execution_cancelled":_(!1),C(Ge.IDLE),j.current=null;break;case"execution_status":const J=(V=B.data)==null?void 0:V.status;if(J){const oe=xa(J);C(oe),_(va(oe))}break}},[u]),R=i.useCallback(B=>{var re,fe,X,ue,ve,pe,U,le;const{id:H,message_type:V,content:J}=B,oe=Q=>g.some(Z=>Z.id===Q);if(V==="system_decision"||V==="action_execution_result"||V==="assistant_task_breakdown"||V==="assistant_validation"||V==="assistant_action_planning"||V==="context_results"){d(null),x(null);let Q="";if(V==="system_decision"){const Z=J==null?void 0:J.step,ne=J==null?void 0:J.reasoning;if(Z==="gathercontext")ne&&ne.length>0?Q=ne.length>60?`${ne.substring(0,60)}...`:ne:Q="Gathering context...";else if(Z==="executeaction")Q="Executing action";else if(Z==="deliverresponse")Q="Preparing response";else if(Z==="taskplanning")Q="Planning approach";else if(Z==="validateprogress")Q="Validating progress";else if(Z==="acknowledge")Q="Processing request";else if(Z==="finishplanning")Q="Finalizing plan";else if(Z==="executetasks")Q="Executing tasks";else if(Z==="requestuserinput")Q="Waiting for input";else if(Z==="complete")Q="Completed";else if(Z==="examinetool")Q="Examining tool";else if(Z==="examineworkflow")Q="Examining workflow";else{const me=(J==null?void 0:J.confidence)||.5;me>.8?Q="Analyzing":me>.6?Q="Thinking":Q="Reasoning"}}else if(V==="action_execution_result")((re=J.task_execution)==null?void 0:re.status)==="completed"?Q="Task execution completed":(fe=J.task_execution)!=null&&fe.approach?Q=J.task_execution.approach:Q="Executing task";else if(V==="assistant_task_breakdown")(X=J.task_breakdown)!=null&&X.total_tasks?Q=`Identified ${J.task_breakdown.total_tasks} tasks`:Q="Planning tasks";else if(V==="assistant_validation")Q="Validated results";else if(V==="assistant_action_planning")(ue=J.task_execution)!=null&&ue.total_tasks?Q=`Planned ${J.task_execution.total_tasks} tasks`:(pe=(ve=J.task_execution)==null?void 0:ve.tasks)!=null&&pe.length?Q=`Planned ${J.task_execution.tasks.length} tasks`:Q="Planning actions";else if(V==="context_results"){const Z=J.query,ne=J.result_count||0;Z&&Z!=="General context gathering"?Q=`${Z}: Found ${ne} results`:Q=`Found ${ne} results`}Q&&!oe(H)&&c(Z=>[...Z,{id:H,role:"system",content:Q,timestamp:new Date,metadata:{type:"log",messageType:V}}]);return}if(V==="user_message")oe(H)||(d(null),x(null),c(Q=>[...Q,{id:H,role:"user",content:J.message,images:J.images,timestamp:new Date}]));else if(V==="agent_response")oe(H)||(d(null),x(null),_(!1),C(Ge.IDLE),j.current=null,c(Q=>[...Q,{id:H,role:"assistant",content:J.response,timestamp:new Date,isStreaming:!1}]));else if(V==="assistant_acknowledgment")oe(H)||(d(null),x(null),c(Q=>[...Q,{id:H,role:"assistant",content:J.acknowledgment_message,timestamp:new Date}]));else if(V==="assistant_ideation"||V==="assistant_action_planning"||V==="action_execution_result"||V==="assistant_validation"||V==="assistant_context_gathering"||V==="assistant_task_breakdown"){let Q="";if(J.reasoning_summary)Q=J.reasoning_summary;else if((U=J.task_execution)!=null&&U.approach)Q=J.task_execution.approach;else if(J.strategic_synthesis)Q=J.strategic_synthesis;else if((le=J.task_breakdown)!=null&&le.total_tasks)Q=`Breaking down into ${J.task_breakdown.total_tasks} tasks...`;else if(J.acknowledgment_message)Q=J.acknowledgment_message;else return;c(Z=>[...Z,{id:H,role:"assistant",content:Q,timestamp:new Date}])}else if(V==="user_input_request"){const Q={question:J.question,context:J.context,input_type:J.input_type,options:J.options||J.suggestions,default_value:J.default_value,placeholder:J.placeholder};C("waiting_for_input"),c(Z=>[...Z,{id:H,role:"system",content:Q.question,timestamp:new Date,metadata:{type:"user_input_request",userInputRequest:Q}}])}},[]),O=i.useCallback(async B=>{C("waiting_for_input");const H=`input-request-${Date.now()}`;c(V=>[...V,{id:H,role:"system",content:B.question,timestamp:new Date,metadata:{type:"user_input_request",userInputRequest:B}}])},[]),P=i.useCallback(B=>{const{event_label:H,event_data:V}=B;n!=null&&n.onPlatformEvent&&n.onPlatformEvent(H,V)},[n]),M=i.useCallback(async B=>{const{function_name:H,function_data:V}=B,{parameters:J,execution_id:oe}=V;if(!(n!=null&&n.onPlatformFunction)){st.send({message_type:{platform_function_result:[oe,{error:"No platform function handler registered"}]},data:{}});return}try{const re=await n.onPlatformFunction(H,J,oe),fe={message_type:{platform_function_result:[oe,re]},data:{}};st.send(fe)}catch(re){st.send({message_type:{platform_function_result:[oe,{error:re instanceof Error?re.message:"Function execution failed",stack:re instanceof Error?re.stack:void 0}]},data:{}})}},[n]);i.useEffect(()=>{if(!a)return;const H=`wss://${a==null?void 0:a.backend_host.replace(/https?:\/\//,"")}/realtime/agent?token=${encodeURIComponent(o)}`;E({status:Pt.CONNECTING}),st.connect(H)},[a,o]),i.useEffect(()=>st.onConnectionStateChange(H=>{E({status:H.isConnected?Pt.CONNECTED:H.error?Pt.ERROR:Pt.DISCONNECTED}),v(H.isConnected)}),[]),i.useEffect(()=>st.onMessage(T),[T]),i.useEffect(()=>{m&&t&&r&&s&&st.send({message_type:{session_connect:[t,r]},data:{}})},[m,t,r,s]);const N=i.useCallback(async()=>(m&&t&&r&&st.send({message_type:{session_connect:[t,r]},data:{}}),()=>{}),[m,t,r]),D=i.useCallback((B,H)=>{m&&(d(B),x(H||null),_(!0),C(Ge.STARTING),st.send({message_type:{message_input:B},data:H?{images:H}:{}}))},[m]),L=i.useCallback(()=>{c([]),j.current=null},[]),I=i.useCallback(B=>{!m||k!==Ge.WAITING_FOR_INPUT||(st.send({message_type:{user_input_response:B},data:{}}),C(Ge.RUNNING))},[m,k]),A=i.useCallback(async B=>{var H;if(!(!o||!t))try{const V=new URLSearchParams({token:o,limit:"50"});B&&(V.append("before_id",B),$(!0));const oe=await(await h(`/api/agent/contexts/${t}/messages?${V}`,{method:"GET"})).json();if(oe.status===200&&oe.data){const re=oe.data;if(Array.isArray(re.data)){const fe=re.data.filter(X=>{var pe;let ue=X.content;if(typeof X.content=="string")try{ue=JSON.parse(X.content)}catch{ue={message:X.content}}const ve=((pe=X.metadata)==null?void 0:pe.message_type)||(ue==null?void 0:ue.message_type);return ve==="user_message"||ve==="agent_response"||ve==="assistant_acknowledgment"||ve==="user_input_request"||ve==="system_decision"||ve==="action_execution_result"||ve==="assistant_task_breakdown"||ve==="assistant_validation"||ve==="assistant_action_planning"||ve==="context_results"}).map(X=>{var Q,Z,ne,me,de,ee,W;let ue="",ve,pe,U=X.content;if(typeof X.content=="string")try{U=JSON.parse(X.content)}catch{U=X.content}const le=((Q=X.metadata)==null?void 0:Q.message_type)||(U==null?void 0:U.message_type);if(le==="user_message"?(ue=(U==null?void 0:U.message)||"",ve=(U==null?void 0:U.images)||void 0):le==="agent_response"?ue=(U==null?void 0:U.response)||"":le==="assistant_acknowledgment"?ue=(U==null?void 0:U.acknowledgment_message)||"":le==="user_input_request"&&(ue=(U==null?void 0:U.question)||"",pe={type:"user_input_request",userInputRequest:{question:(U==null?void 0:U.question)||"",context:(U==null?void 0:U.context)||"",input_type:(U==null?void 0:U.input_type)||"text",options:(U==null?void 0:U.options)||(U==null?void 0:U.suggestions)||[],default_value:(U==null?void 0:U.default_value)||"",placeholder:(U==null?void 0:U.placeholder)||""}}),le==="system_decision"||le==="action_execution_result"||le==="assistant_task_breakdown"||le==="assistant_validation"||le==="assistant_action_planning"||le==="context_results"){let F="";if(le==="system_decision"){const se=U==null?void 0:U.step,be=U==null?void 0:U.reasoning;if(se==="gathercontext")be&&be.length>0?F=be.length>60?`${be.substring(0,60)}...`:be:F="Gathering context...";else if(se==="executeaction")F="Executing action";else if(se==="deliverresponse")F="Preparing response";else if(se==="taskplanning")F="Planning approach";else if(se==="validateprogress")F="Validating progress";else if(se==="acknowledge")F="Processing request";else if(se==="finishplanning")F="Finalizing plan";else if(se==="executetasks")F="Executing tasks";else if(se==="requestuserinput")F="Waiting for input";else if(se==="complete")F="Completed";else if(se==="examinetool")F="Examining tool";else if(se==="examineworkflow")F="Examining workflow";else{const Oe=(U==null?void 0:U.confidence)||.5;Oe>.8?F="Analyzing":Oe>.6?F="Thinking":F="Reasoning"}}else if(le==="action_execution_result")((Z=U==null?void 0:U.task_execution)==null?void 0:Z.status)==="completed"?F="Task execution completed":(ne=U==null?void 0:U.task_execution)!=null&&ne.approach?F=U.task_execution.approach:F="Executing task";else if(le==="assistant_task_breakdown")(me=U==null?void 0:U.task_breakdown)!=null&&me.total_tasks?F=`Identified ${U.task_breakdown.total_tasks} tasks`:F="Planning tasks";else if(le==="assistant_validation")F="Validated results";else if(le==="assistant_action_planning")(de=U==null?void 0:U.task_execution)!=null&&de.total_tasks?F=`Planned ${U.task_execution.total_tasks} tasks`:(W=(ee=U==null?void 0:U.task_execution)==null?void 0:ee.tasks)!=null&&W.length?F=`Planned ${U.task_execution.tasks.length} tasks`:F="Planning actions";else if(le==="context_results"){const se=U==null?void 0:U.query,be=(U==null?void 0:U.result_count)||0;se&&se!=="General context gathering"?F=`${se}: Found ${be} results`:F=`Found ${be} results`}ue=F,pe={type:"log",messageType:le}}return{id:X.id,role:le==="user_message"?"user":le==="user_input_request"?"system":"assistant",content:ue,images:ve,timestamp:new Date(X.timestamp||X.created_at||Date.now()),metadata:pe}}).filter(X=>X.content||X.metadata||X.images).sort((X,ue)=>{const ve=BigInt(X.id),pe=BigInt(ue.id);return ve<pe?-1:ve>pe?1:0});fe.length>0&&(S.current=fe[0].id),B?(c(X=>[...fe,...X]),y(fe.length>=50)):(c(fe),fe.length>0&&((H=fe[fe.length-1].metadata)==null?void 0:H.type)==="user_input_request"&&C(Ge.WAITING_FOR_INPUT)),$(!1)}}}catch(V){console.error("Failed to fetch messages:",V),$(!1)}},[o,t,h]);i.useEffect(()=>{t&&o&&A()},[t,o]);const q=i.useCallback(async()=>{if(!(f||!w||!S.current)){$(!0);try{await A(S.current)}finally{$(!1)}}},[f,w,A]),Y=i.useCallback(()=>{!m||!b||(st.send({message_type:{cancel_execution:null},data:{}}),_(!1),C("idle"))},[m,b]);return{messages:g,pendingMessage:u,pendingImages:p,connectionState:z,isConnected:m,isExecuting:b,executionStatus:k,isWaitingForInput:k==="waiting_for_input",hasMoreMessages:w,isLoadingMore:f,sendMessage:D,submitUserInput:I,clearMessages:L,loadMoreMessages:q,cancelExecution:Y,connect:N,disconnect:()=>st.disconnect()}}const Zc=()=>{const{client:t}=Ze(),[r,o]=i.useState(!1),[n,s]=i.useState(null),[a,h]=i.useState(null),g=i.useCallback(async u=>{o(!0),s(null),h(null);try{const d=new FormData;d.append("token",u);const p=await t("/organizations/invitations/accept",{method:"POST",body:d}),m=(await G(p)).data;return h(m),m.error_code&&s(m.message||"Failed to accept invitation"),m}catch(d){const p=d.message||"Failed to accept invitation";s(p);const x={error_code:"NETWORK_ERROR",message:p};return h(x),x}finally{o(!1)}},[t]),c=i.useCallback(()=>{s(null),h(null)},[]);return{acceptInvitation:g,invitationData:a,loading:r,error:n,reset:c}},qu=({children:t})=>{const{loading:r}=ye();return r?null:e.jsx(e.Fragment,{children:t})},Yu=({children:t})=>{const{loading:r}=ye();return r?e.jsx(e.Fragment,{children:t}):null};var ot=function(){return ot=Object.assign||function(r){for(var o,n=1,s=arguments.length;n<s;n++){o=arguments[n];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(r[a]=o[a])}return r},ot.apply(this,arguments)};function pr(t,r,o){if(o||arguments.length===2)for(var n=0,s=r.length,a;n<s;n++)(a||!(n in r))&&(a||(a=Array.prototype.slice.call(r,0,n)),a[n]=r[n]);return t.concat(a||Array.prototype.slice.call(r))}function Zu(t){var r=Object.create(null);return function(o){return r[o]===void 0&&(r[o]=t(o)),r[o]}}var Ku=/^((children|dangerouslySetInnerHTML|key|ref|autoFocus|defaultValue|defaultChecked|innerHTML|suppressContentEditableWarning|suppressHydrationWarning|valueLink|abbr|accept|acceptCharset|accessKey|action|allow|allowUserMedia|allowPaymentRequest|allowFullScreen|allowTransparency|alt|async|autoComplete|autoPlay|capture|cellPadding|cellSpacing|challenge|charSet|checked|cite|classID|className|cols|colSpan|content|contentEditable|contextMenu|controls|controlsList|coords|crossOrigin|data|dateTime|decoding|default|defer|dir|disabled|disablePictureInPicture|disableRemotePlayback|download|draggable|encType|enterKeyHint|form|formAction|formEncType|formMethod|formNoValidate|formTarget|frameBorder|headers|height|hidden|high|href|hrefLang|htmlFor|httpEquiv|id|inputMode|integrity|is|keyParams|keyType|kind|label|lang|list|loading|loop|low|marginHeight|marginWidth|max|maxLength|media|mediaGroup|method|min|minLength|multiple|muted|name|nonce|noValidate|open|optimum|pattern|placeholder|playsInline|poster|preload|profile|radioGroup|readOnly|referrerPolicy|rel|required|reversed|role|rows|rowSpan|sandbox|scope|scoped|scrolling|seamless|selected|shape|size|sizes|slot|span|spellCheck|src|srcDoc|srcLang|srcSet|start|step|style|summary|tabIndex|target|title|translate|type|useMap|value|width|wmode|wrap|about|datatype|inlist|prefix|property|resource|typeof|vocab|autoCapitalize|autoCorrect|autoSave|color|incremental|fallback|inert|itemProp|itemScope|itemType|itemID|itemRef|on|option|results|security|unselectable|accentHeight|accumulate|additive|alignmentBaseline|allowReorder|alphabetic|amplitude|arabicForm|ascent|attributeName|attributeType|autoReverse|azimuth|baseFrequency|baselineShift|baseProfile|bbox|begin|bias|by|calcMode|capHeight|clip|clipPathUnits|clipPath|clipRule|colorInterpolation|colorInterpolationFilters|colorProfile|colorRendering|contentScriptType|contentStyleType|cursor|cx|cy|d|decelerate|descent|diffuseConstant|direction|display|divisor|dominantBaseline|dur|dx|dy|edgeMode|elevation|enableBackground|end|exponent|externalResourcesRequired|fill|fillOpacity|fillRule|filter|filterRes|filterUnits|floodColor|floodOpacity|focusable|fontFamily|fontSize|fontSizeAdjust|fontStretch|fontStyle|fontVariant|fontWeight|format|from|fr|fx|fy|g1|g2|glyphName|glyphOrientationHorizontal|glyphOrientationVertical|glyphRef|gradientTransform|gradientUnits|hanging|horizAdvX|horizOriginX|ideographic|imageRendering|in|in2|intercept|k|k1|k2|k3|k4|kernelMatrix|kernelUnitLength|kerning|keyPoints|keySplines|keyTimes|lengthAdjust|letterSpacing|lightingColor|limitingConeAngle|local|markerEnd|markerMid|markerStart|markerHeight|markerUnits|markerWidth|mask|maskContentUnits|maskUnits|mathematical|mode|numOctaves|offset|opacity|operator|order|orient|orientation|origin|overflow|overlinePosition|overlineThickness|panose1|paintOrder|pathLength|patternContentUnits|patternTransform|patternUnits|pointerEvents|points|pointsAtX|pointsAtY|pointsAtZ|preserveAlpha|preserveAspectRatio|primitiveUnits|r|radius|refX|refY|renderingIntent|repeatCount|repeatDur|requiredExtensions|requiredFeatures|restart|result|rotate|rx|ry|scale|seed|shapeRendering|slope|spacing|specularConstant|specularExponent|speed|spreadMethod|startOffset|stdDeviation|stemh|stemv|stitchTiles|stopColor|stopOpacity|strikethroughPosition|strikethroughThickness|string|stroke|strokeDasharray|strokeDashoffset|strokeLinecap|strokeLinejoin|strokeMiterlimit|strokeOpacity|strokeWidth|surfaceScale|systemLanguage|tableValues|targetX|targetY|textAnchor|textDecoration|textRendering|textLength|to|transform|u1|u2|underlinePosition|underlineThickness|unicode|unicodeBidi|unicodeRange|unitsPerEm|vAlphabetic|vHanging|vIdeographic|vMathematical|values|vectorEffect|version|vertAdvY|vertOriginX|vertOriginY|viewBox|viewTarget|visibility|widths|wordSpacing|writingMode|x|xHeight|x1|x2|xChannelSelector|xlinkActuate|xlinkArcrole|xlinkHref|xlinkRole|xlinkShow|xlinkTitle|xlinkType|xmlBase|xmlns|xmlnsXlink|xmlLang|xmlSpace|y|y1|y2|yChannelSelector|z|zoomAndPan|for|class|autofocus)|(([Dd][Aa][Tt][Aa]|[Aa][Rr][Ii][Aa]|x)-.*))$/,Qu=Zu(function(t){return Ku.test(t)||t.charCodeAt(0)===111&&t.charCodeAt(1)===110&&t.charCodeAt(2)<91}),Le="-ms-",qr="-moz-",Re="-webkit-",Kc="comm",rn="rule",Rs="decl",Ju="@import",Qc="@keyframes",Xu="@layer",Jc=Math.abs,Ts=String.fromCharCode,gs=Object.assign;function ep(t,r){return Qe(t,0)^45?(((r<<2^Qe(t,0))<<2^Qe(t,1))<<2^Qe(t,2))<<2^Qe(t,3):0}function Xc(t){return t.trim()}function It(t,r){return(t=r.exec(t))?t[0]:t}function je(t,r,o){return t.replace(r,o)}function Ao(t,r,o){return t.indexOf(r,o)}function Qe(t,r){return t.charCodeAt(r)|0}function zr(t,r,o){return t.slice(r,o)}function xt(t){return t.length}function el(t){return t.length}function Gr(t,r){return r.push(t),t}function tp(t,r){return t.map(r).join("")}function ba(t,r){return t.filter(function(o){return!It(o,r)})}var on=1,$r=1,tl=0,it=0,He=0,Rr="";function nn(t,r,o,n,s,a,h,g){return{value:t,root:r,parent:o,type:n,props:s,children:a,line:on,column:$r,length:h,return:"",siblings:g}}function At(t,r){return gs(nn("",null,null,"",null,null,0,t.siblings),t,{length:-t.length},r)}function mr(t){for(;t.root;)t=At(t.root,{children:[t]});Gr(t,t.siblings)}function rp(){return He}function op(){return He=it>0?Qe(Rr,--it):0,$r--,He===10&&($r=1,on--),He}function dt(){return He=it<tl?Qe(Rr,it++):0,$r++,He===10&&($r=1,on++),He}function ir(){return Qe(Rr,it)}function Lo(){return it}function sn(t,r){return zr(Rr,t,r)}function ms(t){switch(t){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function np(t){return on=$r=1,tl=xt(Rr=t),it=0,[]}function sp(t){return Rr="",t}function zn(t){return Xc(sn(it-1,xs(t===91?t+2:t===40?t+1:t)))}function ap(t){for(;(He=ir())&&He<33;)dt();return ms(t)>2||ms(He)>3?"":" "}function ip(t,r){for(;--r&&dt()&&!(He<48||He>102||He>57&&He<65||He>70&&He<97););return sn(t,Lo()+(r<6&&ir()==32&&dt()==32))}function xs(t){for(;dt();)switch(He){case t:return it;case 34:case 39:t!==34&&t!==39&&xs(He);break;case 40:t===41&&xs(t);break;case 92:dt();break}return it}function cp(t,r){for(;dt()&&t+He!==57;)if(t+He===84&&ir()===47)break;return"/*"+sn(r,it-1)+"*"+Ts(t===47?t:dt())}function lp(t){for(;!ms(ir());)dt();return sn(t,it)}function dp(t){return sp(Do("",null,null,null,[""],t=np(t),0,[0],t))}function Do(t,r,o,n,s,a,h,g,c){for(var u=0,d=0,p=h,x=0,m=0,v=0,b=1,_=1,k=1,C=0,z="",E=s,w=a,y=n,f=z;_;)switch(v=C,C=dt()){case 40:if(v!=108&&Qe(f,p-1)==58){Ao(f+=je(zn(C),"&","&\f"),"&\f",Jc(u?g[u-1]:0))!=-1&&(k=-1);break}case 34:case 39:case 91:f+=zn(C);break;case 9:case 10:case 13:case 32:f+=ap(v);break;case 92:f+=ip(Lo()-1,7);continue;case 47:switch(ir()){case 42:case 47:Gr(up(cp(dt(),Lo()),r,o,c),c);break;default:f+="/"}break;case 123*b:g[u++]=xt(f)*k;case 125*b:case 59:case 0:switch(C){case 0:case 125:_=0;case 59+d:k==-1&&(f=je(f,/\f/g,"")),m>0&&xt(f)-p&&Gr(m>32?wa(f+";",n,o,p-1,c):wa(je(f," ","")+";",n,o,p-2,c),c);break;case 59:f+=";";default:if(Gr(y=ya(f,r,o,u,d,s,g,z,E=[],w=[],p,a),a),C===123)if(d===0)Do(f,r,y,y,E,a,p,g,w);else switch(x===99&&Qe(f,3)===110?100:x){case 100:case 108:case 109:case 115:Do(t,y,y,n&&Gr(ya(t,y,y,0,0,s,g,z,s,E=[],p,w),w),s,w,p,g,n?E:w);break;default:Do(f,y,y,y,[""],w,0,g,w)}}u=d=m=0,b=k=1,z=f="",p=h;break;case 58:p=1+xt(f),m=v;default:if(b<1){if(C==123)--b;else if(C==125&&b++==0&&op()==125)continue}switch(f+=Ts(C),C*b){case 38:k=d>0?1:(f+="\f",-1);break;case 44:g[u++]=(xt(f)-1)*k,k=1;break;case 64:ir()===45&&(f+=zn(dt())),x=ir(),d=p=xt(z=f+=lp(Lo())),C++;break;case 45:v===45&&xt(f)==2&&(b=0)}}return a}function ya(t,r,o,n,s,a,h,g,c,u,d,p){for(var x=s-1,m=s===0?a:[""],v=el(m),b=0,_=0,k=0;b<n;++b)for(var C=0,z=zr(t,x+1,x=Jc(_=h[b])),E=t;C<v;++C)(E=Xc(_>0?m[C]+" "+z:je(z,/&\f/g,m[C])))&&(c[k++]=E);return nn(t,r,o,s===0?rn:g,c,u,d,p)}function up(t,r,o,n){return nn(t,r,o,Kc,Ts(rp()),zr(t,2,-2),0,n)}function wa(t,r,o,n,s){return nn(t,r,o,Rs,zr(t,0,n),zr(t,n+1,-1),n,s)}function rl(t,r,o){switch(ep(t,r)){case 5103:return Re+"print-"+t+t;case 5737:case 4201:case 3177:case 3433:case 1641:case 4457:case 2921:case 5572:case 6356:case 5844:case 3191:case 6645:case 3005:case 6391:case 5879:case 5623:case 6135:case 4599:case 4855:case 4215:case 6389:case 5109:case 5365:case 5621:case 3829:return Re+t+t;case 4789:return qr+t+t;case 5349:case 4246:case 4810:case 6968:case 2756:return Re+t+qr+t+Le+t+t;case 5936:switch(Qe(t,r+11)){case 114:return Re+t+Le+je(t,/[svh]\w+-[tblr]{2}/,"tb")+t;case 108:return Re+t+Le+je(t,/[svh]\w+-[tblr]{2}/,"tb-rl")+t;case 45:return Re+t+Le+je(t,/[svh]\w+-[tblr]{2}/,"lr")+t}case 6828:case 4268:case 2903:return Re+t+Le+t+t;case 6165:return Re+t+Le+"flex-"+t+t;case 5187:return Re+t+je(t,/(\w+).+(:[^]+)/,Re+"box-$1$2"+Le+"flex-$1$2")+t;case 5443:return Re+t+Le+"flex-item-"+je(t,/flex-|-self/g,"")+(It(t,/flex-|baseline/)?"":Le+"grid-row-"+je(t,/flex-|-self/g,""))+t;case 4675:return Re+t+Le+"flex-line-pack"+je(t,/align-content|flex-|-self/g,"")+t;case 5548:return Re+t+Le+je(t,"shrink","negative")+t;case 5292:return Re+t+Le+je(t,"basis","preferred-size")+t;case 6060:return Re+"box-"+je(t,"-grow","")+Re+t+Le+je(t,"grow","positive")+t;case 4554:return Re+je(t,/([^-])(transform)/g,"$1"+Re+"$2")+t;case 6187:return je(je(je(t,/(zoom-|grab)/,Re+"$1"),/(image-set)/,Re+"$1"),t,"")+t;case 5495:case 3959:return je(t,/(image-set\([^]*)/,Re+"$1$`$1");case 4968:return je(je(t,/(.+:)(flex-)?(.*)/,Re+"box-pack:$3"+Le+"flex-pack:$3"),/s.+-b[^;]+/,"justify")+Re+t+t;case 4200:if(!It(t,/flex-|baseline/))return Le+"grid-column-align"+zr(t,r)+t;break;case 2592:case 3360:return Le+je(t,"template-","")+t;case 4384:case 3616:return o&&o.some(function(n,s){return r=s,It(n.props,/grid-\w+-end/)})?~Ao(t+(o=o[r].value),"span",0)?t:Le+je(t,"-start","")+t+Le+"grid-row-span:"+(~Ao(o,"span",0)?It(o,/\d+/):+It(o,/\d+/)-+It(t,/\d+/))+";":Le+je(t,"-start","")+t;case 4896:case 4128:return o&&o.some(function(n){return It(n.props,/grid-\w+-start/)})?t:Le+je(je(t,"-end","-span"),"span ","")+t;case 4095:case 3583:case 4068:case 2532:return je(t,/(.+)-inline(.+)/,Re+"$1$2")+t;case 8116:case 7059:case 5753:case 5535:case 5445:case 5701:case 4933:case 4677:case 5533:case 5789:case 5021:case 4765:if(xt(t)-1-r>6)switch(Qe(t,r+1)){case 109:if(Qe(t,r+4)!==45)break;case 102:return je(t,/(.+:)(.+)-([^]+)/,"$1"+Re+"$2-$3$1"+qr+(Qe(t,r+3)==108?"$3":"$2-$3"))+t;case 115:return~Ao(t,"stretch",0)?rl(je(t,"stretch","fill-available"),r,o)+t:t}break;case 5152:case 5920:return je(t,/(.+?):(\d+)(\s*\/\s*(span)?\s*(\d+))?(.*)/,function(n,s,a,h,g,c,u){return Le+s+":"+a+u+(h?Le+s+"-span:"+(g?c:+c-+a)+u:"")+t});case 4949:if(Qe(t,r+6)===121)return je(t,":",":"+Re)+t;break;case 6444:switch(Qe(t,Qe(t,14)===45?18:11)){case 120:return je(t,/(.+:)([^;\s!]+)(;|(\s+)?!.+)?/,"$1"+Re+(Qe(t,14)===45?"inline-":"")+"box$3$1"+Re+"$2$3$1"+Le+"$2box$3")+t;case 100:return je(t,":",":"+Le)+t}break;case 5719:case 2647:case 2135:case 3927:case 2391:return je(t,"scroll-","scroll-snap-")+t}return t}function Vo(t,r){for(var o="",n=0;n<t.length;n++)o+=r(t[n],n,t,r)||"";return o}function pp(t,r,o,n){switch(t.type){case Xu:if(t.children.length)break;case Ju:case Rs:return t.return=t.return||t.value;case Kc:return"";case Qc:return t.return=t.value+"{"+Vo(t.children,n)+"}";case rn:if(!xt(t.value=t.props.join(",")))return""}return xt(o=Vo(t.children,n))?t.return=t.value+"{"+o+"}":""}function hp(t){var r=el(t);return function(o,n,s,a){for(var h="",g=0;g<r;g++)h+=t[g](o,n,s,a)||"";return h}}function fp(t){return function(r){r.root||(r=r.return)&&t(r)}}function gp(t,r,o,n){if(t.length>-1&&!t.return)switch(t.type){case Rs:t.return=rl(t.value,t.length,o);return;case Qc:return Vo([At(t,{value:je(t.value,"@","@"+Re)})],n);case rn:if(t.length)return tp(o=t.props,function(s){switch(It(s,n=/(::plac\w+|:read-\w+)/)){case":read-only":case":read-write":mr(At(t,{props:[je(s,/:(read-\w+)/,":"+qr+"$1")]})),mr(At(t,{props:[s]})),gs(t,{props:ba(o,n)});break;case"::placeholder":mr(At(t,{props:[je(s,/:(plac\w+)/,":"+Re+"input-$1")]})),mr(At(t,{props:[je(s,/:(plac\w+)/,":"+qr+"$1")]})),mr(At(t,{props:[je(s,/:(plac\w+)/,Le+"input-$1")]})),mr(At(t,{props:[s]})),gs(t,{props:ba(o,n)});break}return""})}}var mp={animationIterationCount:1,aspectRatio:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1},hr=typeof process<"u"&&process.env!==void 0&&(process.env.REACT_APP_SC_ATTR||process.env.SC_ATTR)||"data-styled",ol="active",nl="data-styled-version",an="6.1.19",Ms=`/*!sc*/
|
|
19
19
|
`,Go=typeof window<"u"&&typeof document<"u",xp=!!(typeof SC_DISABLE_SPEEDY=="boolean"?SC_DISABLE_SPEEDY:typeof process<"u"&&process.env!==void 0&&process.env.REACT_APP_SC_DISABLE_SPEEDY!==void 0&&process.env.REACT_APP_SC_DISABLE_SPEEDY!==""?process.env.REACT_APP_SC_DISABLE_SPEEDY!=="false"&&process.env.REACT_APP_SC_DISABLE_SPEEDY:typeof process<"u"&&process.env!==void 0&&process.env.SC_DISABLE_SPEEDY!==void 0&&process.env.SC_DISABLE_SPEEDY!==""?process.env.SC_DISABLE_SPEEDY!=="false"&&process.env.SC_DISABLE_SPEEDY:process.env.NODE_ENV!=="production"),ja=/invalid hook call/i,so=new Set,vp=function(t,r){if(process.env.NODE_ENV!=="production"){var o=r?' with the id of "'.concat(r,'"'):"",n="The component ".concat(t).concat(o,` has been created dynamically.
|
|
20
20
|
`)+`You may see this warning because you've called styled inside another component.
|
|
21
21
|
To resolve this only create new StyledComponents outside of any render method and function component.
|
|
@@ -556,7 +556,7 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
556
556
|
height: 16px;
|
|
557
557
|
flex-shrink: 0;
|
|
558
558
|
}
|
|
559
|
-
`,Ns=({connections:t,callback:r})=>{const o=()=>t.length<=6?[t]:t.length<=12?[t.slice(0,4),t.slice(4)]:[t.slice(0,4),t.slice(4,8),t.slice(8)],n=t.length,s=o();return e.jsx(hf,{children:s.map((a,h)=>e.jsx(ff,{children:a.map((g,c)=>{const u=g.provider;return e.jsxs(gf,{onClick:()=>r(g),type:"button",$isWide:s.length>1&&h<s.length-1,$totalProviders:n,children:[Mn[u].icon,n<3&&e.jsx("span",{children:n===1?Mn[u].fullLabel:Mn[u].shortLabel})]},`${g.provider}-${c}`)})},`row-${h}`))})},pt=({to:t,replace:r,children:o,...n})=>{const{navigate:s}=tt(),a=i.useCallback(h=>{h.preventDefault(),s(t,{replace:r})},[t,r,s]);return e.jsx("a",{href:t,onClick:a,...n,children:o})},mf={sm:"36rem"},
|
|
559
|
+
`,Ns=({connections:t,callback:r})=>{const o=()=>t.length<=6?[t]:t.length<=12?[t.slice(0,4),t.slice(4)]:[t.slice(0,4),t.slice(4,8),t.slice(8)],n=t.length,s=o();return e.jsx(hf,{children:s.map((a,h)=>e.jsx(ff,{children:a.map((g,c)=>{const u=g.provider;return e.jsxs(gf,{onClick:()=>r(g),type:"button",$isWide:s.length>1&&h<s.length-1,$totalProviders:n,children:[Mn[u].icon,n<3&&e.jsx("span",{children:n===1?Mn[u].fullLabel:Mn[u].shortLabel})]},`${g.provider}-${c}`)})},`row-${h}`))})},pt=({to:t,replace:r,children:o,...n})=>{const{navigate:s}=tt(),a=i.useCallback(h=>{h.preventDefault(),s(t,{replace:r})},[t,r,s]);return e.jsx("a",{href:t,onClick:a,...n,children:o})},mf={sm:"36rem"},ce=l.input`
|
|
560
560
|
padding: var(--space-sm) var(--space-md);
|
|
561
561
|
width: 100%;
|
|
562
562
|
height: 36px;
|
|
@@ -716,7 +716,7 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
716
716
|
font-size: 0.8125rem;
|
|
717
717
|
gap: 0.375rem;
|
|
718
718
|
}
|
|
719
|
-
`,kf=l(
|
|
719
|
+
`,kf=l(ce)`
|
|
720
720
|
flex: 1;
|
|
721
721
|
`,eo=({value:t,onChange:r,error:o,countryCode:n,setCountryCode:s})=>{const[a,h]=i.useState(!1),[g,c]=i.useState(Bo.find(v=>v.code===n)||Bo[0]),u=i.useRef(null),[d,p]=i.useState(""),x=i.useRef(null);i.useEffect(()=>{function v(b){u.current&&!u.current.contains(b.target)&&h(!1)}return document.addEventListener("mousedown",v),()=>{document.removeEventListener("mousedown",v)}},[]);const m=Bo.filter(v=>v.name.toLowerCase().includes(d.toLowerCase())||v.dialCode.includes(d));return i.useEffect(()=>{s(g.dialCode)},[g,s]),e.jsxs(xf,{children:[e.jsxs(vf,{ref:u,children:[e.jsxs(bf,{type:"button",onClick:()=>h(v=>!v),children:[e.jsx("span",{children:g.flag}),e.jsx("span",{children:g.dialCode})]}),e.jsxs(yf,{$isOpen:a,children:[e.jsx(wf,{type:"text",placeholder:"Search country...",value:d,onChange:v=>p(v.target.value),onClick:v=>v.stopPropagation()}),e.jsx(jf,{children:m.map(v=>e.jsxs(_f,{onClick:b=>{var _;b.stopPropagation(),b.preventDefault(),c(v),h(!1),(_=x.current)==null||_.focus()},children:[e.jsx("span",{children:v.flag}),e.jsx("span",{children:v.name}),e.jsx("span",{className:"country-code",children:v.dialCode})]},v.code))})]})]}),e.jsx(kf,{style:{height:"100%"},type:"tel",id:"phone",name:"phone",required:!0,minLength:7,maxLength:15,ref:x,value:t,onChange:r,placeholder:"Phone number","aria-invalid":!!o,pattern:"^\\d{7,15}$"})]})},Cf=l.div`
|
|
722
722
|
display: flex;
|
|
@@ -926,7 +926,7 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
926
926
|
`,br=l.span`
|
|
927
927
|
color: var(--color-danger);
|
|
928
928
|
margin-left: 2px;
|
|
929
|
-
`;function Df(){var B,H,V,J,oe,re,fe,X,ue,ve,pe,U,ce,Q,Z,ne,me;const{loading:t,signUp:r,signupAttempt:o,discardSignupAttempt:n}=Nc(),{signIn:s}=Sr("oauth"),{deployment:a}=ye(),{navigate:h}=tt(),{session:g,refetch:c,loading:u}=Ke(),[d,p]=i.useState({first_name:"",last_name:"",email:"",password:"",username:"",phone_number:""}),[x,m]=i.useState({}),[v,b]=i.useState(!1),[_,k]=i.useState(void 0),[C,z]=i.useState(null),[E,w]=i.useState(null),[y,f]=i.useState(!1),$=((B=a==null?void 0:a.restrictions)==null?void 0:B.sign_up_mode)==="restricted",S=((H=a==null?void 0:a.restrictions)==null?void 0:H.sign_up_mode)==="waitlist",j=((J=(V=a==null?void 0:a.auth_settings)==null?void 0:V.multi_session_support)==null?void 0:J.enabled)??!1;i.useEffect(()=>{var le;if(!u&&(g!=null&&g.active_signin)&&!j&&!y){f(!0);let ee=new URLSearchParams(window.location.search).get("redirect_uri");ee||(ee=((le=a==null?void 0:a.ui_settings)==null?void 0:le.after_signin_redirect_url)||null),!ee&&(a!=null&&a.frontend_host)&&(ee=`https://${a.frontend_host}`),!ee&&(a!=null&&a.frontend_host)&&(ee=`https://${a.frontend_host}`),ee&&h(ee)}},[g,u,j,a,h,y]),i.useEffect(()=>{var W;if(!a)return;const ee=new URLSearchParams(window.location.search).get("invite_token");if(S&&!ee){f(!0);const F=((W=a.ui_settings)==null?void 0:W.waitlist_page_url)||`https://${a.frontend_host}/waitlist`;h(F);return}ee&&!C&&r&&(w(ee),r.validateDeploymentInvitation(ee).then(F=>{z(F),F.valid&&p(se=>({...se,first_name:F.first_name||se.first_name,last_name:F.last_name||se.last_name,email:F.email||se.email}))}).catch(F=>{console.error("Failed to validate invitation:",F)}))},[a,S,h,C,r]);const[T,R]=i.useState(!1),[O,P]=i.useState(""),M=le=>{let{name:ee,value:W}=le.target;ee==="phone_number"?W=W.replace(/[^0-9-]/g,""):ee==="email"&&(W=W.toLowerCase()),p(F=>({...F,[ee]:W})),m(F=>({...F,[ee]:""}))},N=()=>{p({first_name:"",last_name:"",email:"",password:"",username:"",phone_number:""}),m({}),R(!1),P(""),n()},D=async le=>{if(le.preventDefault(),console.log("Signup form - handleSubmit called"),console.log("Auth settings:",A),console.log("Form data:",d),t||v)return;const ee={},W=/^[a-zA-Z]{3,30}$/,F=/^[a-zA-Z][a-zA-Z0-9_.]{2,29}$/,se=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,be=/^\d{7,15}$/,Oe=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,125}$/;if(A!=null&&A.first_name.enabled&&(A!=null&&A.first_name.required&&!d.first_name?ee.first_name="First name is required":d.first_name&&!W.test(d.first_name)&&(ee.first_name="Invalid name")),A!=null&&A.last_name.enabled&&(A!=null&&A.last_name.required&&!d.last_name?ee.last_name="Last name is required":d.last_name&&!W.test(d.last_name)&&(ee.last_name="Invalid last name")),A!=null&&A.username.enabled&&(A!=null&&A.username.required&&!d.username?ee.username="Username is required":d.username&&!F.test(d.username)&&(ee.username="Username must be 3-20 characters")),A!=null&&A.email_address.enabled&&(A!=null&&A.email_address.required&&!d.email?ee.email="Email address is required":d.email&&!se.test(d.email)&&(ee.email="Invalid email address")),A!=null&&A.phone_number.enabled&&(A!=null&&A.phone_number.required&&!d.phone_number?ee.phone_number="Phone number is required":d.phone_number&&!be.test(d.phone_number)&&(ee.phone_number="Phone number must contain 7-15 digits")),A!=null&&A.password.enabled&&(d.password?Oe.test(d.password)||(ee.password="Password must be 8-125 characters and include uppercase, lowercase, number, and special character"):ee.password="Password is required"),m(ee),Object.keys(ee).length>0){console.log("Signup validation failed. Errors:",ee);return}console.log("Signup validation passed"),b(!0);try{const Fe={...d};d.phone_number&&_&&(Fe.phone_country_code=_),E&&(Fe.invite_token=E),console.log("Submitting signup data:",Fe),console.log("Phone number:",Fe.phone_number),console.log("Phone country code:",Fe.phone_country_code),await r.create(Fe)}catch(Fe){m({submit:Fe.message})}finally{b(!1)}},L=async le=>{if(!(t||v)){b(!0);try{const W=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,{data:F}=await s.create({provider:le.provider,redirectUri:W});F&&typeof F=="object"&&"oauth_url"in F&&(window.location.href=F.oauth_url)}catch(ee){m({submit:ee.message})}finally{b(!1)}}},I=(a==null?void 0:a.social_connections.filter(le=>le.enabled))||[],A=a==null?void 0:a.auth_settings,q=!!((oe=A==null?void 0:A.first_name)!=null&&oe.enabled&&((re=A==null?void 0:A.last_name)!=null&&re.enabled)),Y=async le=>{var W;if(le.preventDefault(),t||v)return;b(!0);const ee={};if(!O){ee.otp="OTP code is required",m(ee),b(!1);return}m(ee);try{const F=await r.completeVerification(O);"data"in F&&((W=F.data)!=null&&W.active_signin)&&await c()}catch(F){console.error("Verification failed:",F)}finally{b(!1)}};return i.useEffect(()=>{var le;if(o){if(o.completed){let ee=new URLSearchParams(window.location.search).get("redirect_uri");if(ee||(ee=((le=a==null?void 0:a.ui_settings)==null?void 0:le.after_signup_redirect_url)||null),!ee&&(a!=null&&a.frontend_host)&&(ee=`https://${a.frontend_host}`),ee){let W;try{W=new URL(ee)}catch{W=new URL(ee,window.location.origin)}(a==null?void 0:a.mode)==="staging"&&W.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),h(W.toString())}return}if(!T){switch(o.current_step){case"verify_email":r.prepareVerification({strategy:"email_otp"});break;case"verify_phone":r.prepareVerification({strategy:"phone_otp"});break}R(!0)}}},[o,r,T,a,g,h]),u?e.jsx(ge,{children:e.jsxs(lo,{children:[e.jsx(Me,{}),e.jsx(Aa,{children:e.jsx(bt,{size:32})})]})}):y?e.jsx(ge,{children:e.jsxs(lo,{children:[e.jsx(Me,{}),e.jsx(Aa,{children:e.jsx(bt,{size:32})})]})}):$?e.jsx(ge,{children:e.jsxs(lo,{children:[e.jsx(Me,{}),e.jsx(On,{children:e.jsx(An,{children:"Sign up Restricted!"})}),e.jsx(Tf,{children:e.jsx(Mf,{children:"New account registration is currently restricted. Please check back later."})}),e.jsx(Of,{children:e.jsxs(Af,{children:["Need assistance?"," ",e.jsx(Lf,{href:(fe=a==null?void 0:a.ui_settings)!=null&&fe.sign_in_page_url?`${a.ui_settings.sign_in_page_url}?help=true`:"/contact",children:"Get help"})]})})]})}):e.jsx(ge,{children:e.jsx(lo,{children:T?e.jsxs(e.Fragment,{children:[e.jsxs(On,{children:[e.jsxs(An,{children:["Check your"," ",(o==null?void 0:o.current_step)==="verify_email"?"email":"phone"]}),e.jsx(La,{children:(o==null?void 0:o.current_step)==="verify_email"?`${d.email} to continue to ${(X=a==null?void 0:a.ui_settings)==null?void 0:X.app_name}`:`${d.phone_number} to continue to ${(ue=a==null?void 0:a.ui_settings)==null?void 0:ue.app_name}`})]}),e.jsxs(Da,{style:{gap:"15px"},onSubmit:Y,noValidate:!0,children:[e.jsx(Gt,{onComplete:async le=>{P(le)},onResend:async()=>{const le=(o==null?void 0:o.current_step)==="verify_email"?"email_otp":"phone_otp";await r.prepareVerification({strategy:le})},error:x.otp,isSubmitting:v}),e.jsx(Na,{type:"submit",disabled:v||t||!O,children:v?"Verifying...":`Continue to ${(ve=a==null?void 0:a.ui_settings)==null?void 0:ve.app_name}`})]}),e.jsxs(Fa,{children:["Having trouble?"," ",e.jsx(Ln,{children:e.jsx(pt,{to:a.ui_settings.support_page_url,children:"Contact support"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Ln,{onClick:()=>{N()},style:{cursor:"pointer"},children:"Use other method"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(On,{children:[e.jsx(An,{children:"Create your account"}),e.jsx(La,{children:C!=null&&C.valid?"You've been invited! Complete your registration below.":"Welcome! Please fill in the details to get started."})]}),I.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ns,{connections:I,callback:L}),e.jsx(Ef,{children:e.jsx(If,{children:"or"})})]}),e.jsxs(Da,{onSubmit:D,noValidate:!0,children:[(((pe=A==null?void 0:A.first_name)==null?void 0:pe.enabled)||((U=A==null?void 0:A.last_name)==null?void 0:U.enabled))&&e.jsxs(Pf,{$isBothEnabled:q,children:[((ce=A==null?void 0:A.first_name)==null?void 0:ce.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"first_name",children:["First name",((Q=A==null?void 0:A.first_name)==null?void 0:Q.required)&&e.jsx(br,{children:"*"})]}),e.jsx(ie,{type:"text",id:"first_name",name:"first_name",required:!0,minLength:3,maxLength:30,value:d.first_name,onChange:M,placeholder:"First name","aria-invalid":!!x.first_name,pattern:"^[a-zA-Z]{3,30}$"}),x.first_name&&e.jsx(Yt,{children:x.first_name})]}),((Z=A==null?void 0:A.last_name)==null?void 0:Z.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"last_name",children:["Last name",((ne=A==null?void 0:A.last_name)==null?void 0:ne.required)&&e.jsx(br,{children:"*"})]}),e.jsx(ie,{type:"text",id:"last_name",name:"last_name",required:!0,minLength:3,maxLength:30,value:d.last_name,onChange:M,placeholder:"Last name","aria-invalid":!!x.last_name,pattern:"^[a-zA-Z]{3,30}$"}),x.last_name&&e.jsx(Yt,{children:x.last_name})]})]}),(A==null?void 0:A.username.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"username",children:["Username",A.username.required&&e.jsx(br,{children:"*"})]}),e.jsx(ie,{type:"text",id:"username",name:"username",minLength:3,maxLength:20,value:d.username,onChange:M,placeholder:"Choose a username","aria-invalid":!!x.username,required:!0,pattern:"^[a-zA-Z][a-zA-Z0-9_.]{2,29}$"}),x.username&&e.jsx(Yt,{children:x.username})]}),(A==null?void 0:A.email_address.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"email",children:["Email address",A.email_address.required&&e.jsx(br,{children:"*"})]}),e.jsx(ie,{type:"email",id:"email",name:"email",maxLength:320,value:d.email,onChange:M,placeholder:"Enter your email address","aria-invalid":!!x.email,required:!0,readOnly:(C==null?void 0:C.valid)&&!!(C!=null&&C.email),pattern:"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"}),x.email&&e.jsx(Yt,{children:x.email})]}),(A==null?void 0:A.phone_number.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"phone_number",children:["Phone number",A.phone_number.required&&e.jsx(br,{children:"*"})]}),e.jsx(eo,{value:d.phone_number,onChange:M,error:x.phone_number,countryCode:_,setCountryCode:k}),x.phone_number&&e.jsx(Yt,{children:x.phone_number})]}),(A==null?void 0:A.password.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"password",children:["Password",A.password.required&&e.jsx(br,{children:"*"})]}),e.jsx(Rf,{children:e.jsx(ie,{type:"password",id:"password",name:"password",value:d.password,onChange:M,placeholder:"Enter your password","aria-invalid":!!x.password,required:!0,minLength:8,maxLength:128,pattern:"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,125}$"})}),x.password&&e.jsx(Yt,{children:x.password})]}),x.submit&&e.jsx(Yt,{children:x.submit}),e.jsx(Na,{type:"submit",disabled:v||t,children:v?"Creating account...":"Continue"})]}),e.jsxs(Fa,{children:["Already have an account?"," ",e.jsx(Ln,{children:e.jsx(pt,{to:`${(me=a.ui_settings)==null?void 0:me.sign_in_page_url}${window.location.search}`,children:"Sign in"})})]})]})})})}const El=i.createContext(void 0),Il=()=>{const t=i.useContext(El);if(!t)throw new Error("Dialog components must be used within a Dialog");return t},Nf=l.div`
|
|
929
|
+
`;function Df(){var B,H,V,J,oe,re,fe,X,ue,ve,pe,U,le,Q,Z,ne,me;const{loading:t,signUp:r,signupAttempt:o,discardSignupAttempt:n}=Nc(),{signIn:s}=Sr("oauth"),{deployment:a}=ye(),{navigate:h}=tt(),{session:g,refetch:c,loading:u}=Ke(),[d,p]=i.useState({first_name:"",last_name:"",email:"",password:"",username:"",phone_number:""}),[x,m]=i.useState({}),[v,b]=i.useState(!1),[_,k]=i.useState(void 0),[C,z]=i.useState(null),[E,w]=i.useState(null),[y,f]=i.useState(!1),$=((B=a==null?void 0:a.restrictions)==null?void 0:B.sign_up_mode)==="restricted",S=((H=a==null?void 0:a.restrictions)==null?void 0:H.sign_up_mode)==="waitlist",j=((J=(V=a==null?void 0:a.auth_settings)==null?void 0:V.multi_session_support)==null?void 0:J.enabled)??!1;i.useEffect(()=>{var de;if(!u&&(g!=null&&g.active_signin)&&!j&&!y){f(!0);let ee=new URLSearchParams(window.location.search).get("redirect_uri");ee||(ee=((de=a==null?void 0:a.ui_settings)==null?void 0:de.after_signin_redirect_url)||null),!ee&&(a!=null&&a.frontend_host)&&(ee=`https://${a.frontend_host}`),!ee&&(a!=null&&a.frontend_host)&&(ee=`https://${a.frontend_host}`),ee&&h(ee)}},[g,u,j,a,h,y]),i.useEffect(()=>{var W;if(!a)return;const ee=new URLSearchParams(window.location.search).get("invite_token");if(S&&!ee){f(!0);const F=((W=a.ui_settings)==null?void 0:W.waitlist_page_url)||`https://${a.frontend_host}/waitlist`;h(F);return}ee&&!C&&r&&(w(ee),r.validateDeploymentInvitation(ee).then(F=>{z(F),F.valid&&p(se=>({...se,first_name:F.first_name||se.first_name,last_name:F.last_name||se.last_name,email:F.email||se.email}))}).catch(F=>{console.error("Failed to validate invitation:",F)}))},[a,S,h,C,r]);const[T,R]=i.useState(!1),[O,P]=i.useState(""),M=de=>{let{name:ee,value:W}=de.target;ee==="phone_number"?W=W.replace(/[^0-9-]/g,""):ee==="email"&&(W=W.toLowerCase()),p(F=>({...F,[ee]:W})),m(F=>({...F,[ee]:""}))},N=()=>{p({first_name:"",last_name:"",email:"",password:"",username:"",phone_number:""}),m({}),R(!1),P(""),n()},D=async de=>{if(de.preventDefault(),console.log("Signup form - handleSubmit called"),console.log("Auth settings:",A),console.log("Form data:",d),t||v)return;const ee={},W=/^[a-zA-Z]{3,30}$/,F=/^[a-zA-Z][a-zA-Z0-9_.]{2,29}$/,se=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,be=/^\d{7,15}$/,Oe=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,125}$/;if(A!=null&&A.first_name.enabled&&(A!=null&&A.first_name.required&&!d.first_name?ee.first_name="First name is required":d.first_name&&!W.test(d.first_name)&&(ee.first_name="Invalid name")),A!=null&&A.last_name.enabled&&(A!=null&&A.last_name.required&&!d.last_name?ee.last_name="Last name is required":d.last_name&&!W.test(d.last_name)&&(ee.last_name="Invalid last name")),A!=null&&A.username.enabled&&(A!=null&&A.username.required&&!d.username?ee.username="Username is required":d.username&&!F.test(d.username)&&(ee.username="Username must be 3-20 characters")),A!=null&&A.email_address.enabled&&(A!=null&&A.email_address.required&&!d.email?ee.email="Email address is required":d.email&&!se.test(d.email)&&(ee.email="Invalid email address")),A!=null&&A.phone_number.enabled&&(A!=null&&A.phone_number.required&&!d.phone_number?ee.phone_number="Phone number is required":d.phone_number&&!be.test(d.phone_number)&&(ee.phone_number="Phone number must contain 7-15 digits")),A!=null&&A.password.enabled&&(d.password?Oe.test(d.password)||(ee.password="Password must be 8-125 characters and include uppercase, lowercase, number, and special character"):ee.password="Password is required"),m(ee),Object.keys(ee).length>0){console.log("Signup validation failed. Errors:",ee);return}console.log("Signup validation passed"),b(!0);try{const Fe={...d};d.phone_number&&_&&(Fe.phone_country_code=_),E&&(Fe.invite_token=E),console.log("Submitting signup data:",Fe),console.log("Phone number:",Fe.phone_number),console.log("Phone country code:",Fe.phone_country_code),await r.create(Fe)}catch(Fe){m({submit:Fe.message})}finally{b(!1)}},L=async de=>{if(!(t||v)){b(!0);try{const W=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,{data:F}=await s.create({provider:de.provider,redirectUri:W});F&&typeof F=="object"&&"oauth_url"in F&&(window.location.href=F.oauth_url)}catch(ee){m({submit:ee.message})}finally{b(!1)}}},I=(a==null?void 0:a.social_connections.filter(de=>de.enabled))||[],A=a==null?void 0:a.auth_settings,q=!!((oe=A==null?void 0:A.first_name)!=null&&oe.enabled&&((re=A==null?void 0:A.last_name)!=null&&re.enabled)),Y=async de=>{var W;if(de.preventDefault(),t||v)return;b(!0);const ee={};if(!O){ee.otp="OTP code is required",m(ee),b(!1);return}m(ee);try{const F=await r.completeVerification(O);"data"in F&&((W=F.data)!=null&&W.active_signin)&&await c()}catch(F){console.error("Verification failed:",F)}finally{b(!1)}};return i.useEffect(()=>{var de;if(o){if(o.completed){let ee=new URLSearchParams(window.location.search).get("redirect_uri");if(ee||(ee=((de=a==null?void 0:a.ui_settings)==null?void 0:de.after_signup_redirect_url)||null),!ee&&(a!=null&&a.frontend_host)&&(ee=`https://${a.frontend_host}`),ee){let W;try{W=new URL(ee)}catch{W=new URL(ee,window.location.origin)}(a==null?void 0:a.mode)==="staging"&&W.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),h(W.toString())}return}if(!T){switch(o.current_step){case"verify_email":r.prepareVerification({strategy:"email_otp"});break;case"verify_phone":r.prepareVerification({strategy:"phone_otp"});break}R(!0)}}},[o,r,T,a,g,h]),u?e.jsx(ge,{children:e.jsxs(lo,{children:[e.jsx(Me,{}),e.jsx(Aa,{children:e.jsx(bt,{size:32})})]})}):y?e.jsx(ge,{children:e.jsxs(lo,{children:[e.jsx(Me,{}),e.jsx(Aa,{children:e.jsx(bt,{size:32})})]})}):$?e.jsx(ge,{children:e.jsxs(lo,{children:[e.jsx(Me,{}),e.jsx(On,{children:e.jsx(An,{children:"Sign up Restricted!"})}),e.jsx(Tf,{children:e.jsx(Mf,{children:"New account registration is currently restricted. Please check back later."})}),e.jsx(Of,{children:e.jsxs(Af,{children:["Need assistance?"," ",e.jsx(Lf,{href:(fe=a==null?void 0:a.ui_settings)!=null&&fe.sign_in_page_url?`${a.ui_settings.sign_in_page_url}?help=true`:"/contact",children:"Get help"})]})})]})}):e.jsx(ge,{children:e.jsx(lo,{children:T?e.jsxs(e.Fragment,{children:[e.jsxs(On,{children:[e.jsxs(An,{children:["Check your"," ",(o==null?void 0:o.current_step)==="verify_email"?"email":"phone"]}),e.jsx(La,{children:(o==null?void 0:o.current_step)==="verify_email"?`${d.email} to continue to ${(X=a==null?void 0:a.ui_settings)==null?void 0:X.app_name}`:`${d.phone_number} to continue to ${(ue=a==null?void 0:a.ui_settings)==null?void 0:ue.app_name}`})]}),e.jsxs(Da,{style:{gap:"15px"},onSubmit:Y,noValidate:!0,children:[e.jsx(Gt,{onComplete:async de=>{P(de)},onResend:async()=>{const de=(o==null?void 0:o.current_step)==="verify_email"?"email_otp":"phone_otp";await r.prepareVerification({strategy:de})},error:x.otp,isSubmitting:v}),e.jsx(Na,{type:"submit",disabled:v||t||!O,children:v?"Verifying...":`Continue to ${(ve=a==null?void 0:a.ui_settings)==null?void 0:ve.app_name}`})]}),e.jsxs(Fa,{children:["Having trouble?"," ",e.jsx(Ln,{children:e.jsx(pt,{to:a.ui_settings.support_page_url,children:"Contact support"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Ln,{onClick:()=>{N()},style:{cursor:"pointer"},children:"Use other method"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(On,{children:[e.jsx(An,{children:"Create your account"}),e.jsx(La,{children:C!=null&&C.valid?"You've been invited! Complete your registration below.":"Welcome! Please fill in the details to get started."})]}),I.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ns,{connections:I,callback:L}),e.jsx(Ef,{children:e.jsx(If,{children:"or"})})]}),e.jsxs(Da,{onSubmit:D,noValidate:!0,children:[(((pe=A==null?void 0:A.first_name)==null?void 0:pe.enabled)||((U=A==null?void 0:A.last_name)==null?void 0:U.enabled))&&e.jsxs(Pf,{$isBothEnabled:q,children:[((le=A==null?void 0:A.first_name)==null?void 0:le.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"first_name",children:["First name",((Q=A==null?void 0:A.first_name)==null?void 0:Q.required)&&e.jsx(br,{children:"*"})]}),e.jsx(ce,{type:"text",id:"first_name",name:"first_name",required:!0,minLength:3,maxLength:30,value:d.first_name,onChange:M,placeholder:"First name","aria-invalid":!!x.first_name,pattern:"^[a-zA-Z]{3,30}$"}),x.first_name&&e.jsx(Yt,{children:x.first_name})]}),((Z=A==null?void 0:A.last_name)==null?void 0:Z.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"last_name",children:["Last name",((ne=A==null?void 0:A.last_name)==null?void 0:ne.required)&&e.jsx(br,{children:"*"})]}),e.jsx(ce,{type:"text",id:"last_name",name:"last_name",required:!0,minLength:3,maxLength:30,value:d.last_name,onChange:M,placeholder:"Last name","aria-invalid":!!x.last_name,pattern:"^[a-zA-Z]{3,30}$"}),x.last_name&&e.jsx(Yt,{children:x.last_name})]})]}),(A==null?void 0:A.username.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"username",children:["Username",A.username.required&&e.jsx(br,{children:"*"})]}),e.jsx(ce,{type:"text",id:"username",name:"username",minLength:3,maxLength:20,value:d.username,onChange:M,placeholder:"Choose a username","aria-invalid":!!x.username,required:!0,pattern:"^[a-zA-Z][a-zA-Z0-9_.]{2,29}$"}),x.username&&e.jsx(Yt,{children:x.username})]}),(A==null?void 0:A.email_address.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"email",children:["Email address",A.email_address.required&&e.jsx(br,{children:"*"})]}),e.jsx(ce,{type:"email",id:"email",name:"email",maxLength:320,value:d.email,onChange:M,placeholder:"Enter your email address","aria-invalid":!!x.email,required:!0,readOnly:(C==null?void 0:C.valid)&&!!(C!=null&&C.email),pattern:"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"}),x.email&&e.jsx(Yt,{children:x.email})]}),(A==null?void 0:A.phone_number.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"phone_number",children:["Phone number",A.phone_number.required&&e.jsx(br,{children:"*"})]}),e.jsx(eo,{value:d.phone_number,onChange:M,error:x.phone_number,countryCode:_,setCountryCode:k}),x.phone_number&&e.jsx(Yt,{children:x.phone_number})]}),(A==null?void 0:A.password.enabled)&&e.jsxs(xr,{children:[e.jsxs(vr,{htmlFor:"password",children:["Password",A.password.required&&e.jsx(br,{children:"*"})]}),e.jsx(Rf,{children:e.jsx(ce,{type:"password",id:"password",name:"password",value:d.password,onChange:M,placeholder:"Enter your password","aria-invalid":!!x.password,required:!0,minLength:8,maxLength:128,pattern:"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,125}$"})}),x.password&&e.jsx(Yt,{children:x.password})]}),x.submit&&e.jsx(Yt,{children:x.submit}),e.jsx(Na,{type:"submit",disabled:v||t,children:v?"Creating account...":"Continue"})]}),e.jsxs(Fa,{children:["Already have an account?"," ",e.jsx(Ln,{children:e.jsx(pt,{to:`${(me=a.ui_settings)==null?void 0:me.sign_in_page_url}${window.location.search}`,children:"Sign in"})})]})]})})})}const El=i.createContext(void 0),Il=()=>{const t=i.useContext(El);if(!t)throw new Error("Dialog components must be used within a Dialog");return t},Nf=l.div`
|
|
930
930
|
position: fixed;
|
|
931
931
|
inset: 0;
|
|
932
932
|
background-color: var(--color-dialog-backdrop, rgba(0, 0, 0, 0.5));
|
|
@@ -1014,7 +1014,7 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
1014
1014
|
display: flex;
|
|
1015
1015
|
flex-direction: column;
|
|
1016
1016
|
gap: var(--space-xs);
|
|
1017
|
-
`,
|
|
1017
|
+
`,ie=l.label`
|
|
1018
1018
|
font-size: var(--font-xs);
|
|
1019
1019
|
text-align: left;
|
|
1020
1020
|
font-weight: 400;
|
|
@@ -1299,7 +1299,7 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
1299
1299
|
&:hover {
|
|
1300
1300
|
text-decoration: underline;
|
|
1301
1301
|
}
|
|
1302
|
-
`;function hg({onBack:t}){const{deployment:r}=ye(),{navigate:o}=tt(),[n,s]=i.useState("start"),[a,h]=i.useState(""),[g,c]=i.useState(""),[u,d]=i.useState(""),[p,x]=i.useState(""),[m,v]=i.useState(""),{forgotPassword:b,verifyOtp:_,resetPassword:k}=Gc(),[C,z]=i.useState(!1),[E,w]=i.useState(null),y=async j=>{if(j.preventDefault(),!!a){z(!0),w(null);try{await b(a),s("otp")}catch(T){w(T)}finally{z(!1)}}},f=async j=>{if(j.preventDefault(),g.length===6){z(!0),w(null);try{const T=await _(a,g);T.data&&(d(T.data.token),s("reset"))}catch(T){w(T)}finally{z(!1)}}},$=async j=>{var T,R;if(j.preventDefault(),p===m&&!(p.length<8)){z(!0),w(null);try{const O=await k(u,p);if(O.data){const P=O.data,M=P.signin_attempts&&P.signin_attempts.length>0?P.signin_attempts[P.signin_attempts.length-1]:null;if(M&&!M.completed){const N=(T=r==null?void 0:r.ui_settings)==null?void 0:T.sign_in_page_url;if(N){const D=new URL(N,window.location.origin);D.searchParams.set("signin_attempt_id",M.id),o(D.toString())}else t()}else{const N=((R=r==null?void 0:r.ui_settings)==null?void 0:R.after_signin_redirect_url)||"/";o(N)}}}catch(O){w(O)}finally{z(!1)}}},S=()=>e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsx(uo,{children:e.jsx(po,{children:"Forgot Password"})}),e.jsx(dg,{onClick:()=>s("email"),disabled:C,children:"Reset your password"}),e.jsx(ug,{children:e.jsx(pg,{children:"Or, sign in with another method"})}),e.jsx(Ul,{}),e.jsxs(ho,{children:[e.jsxs(Dr,{children:["Unable to reset password? ",e.jsx(Nr,{href:"/contact",children:"Get help"})]}),e.jsx(Dr,{style:{marginTop:"var(--space-sm)"},children:e.jsx(Nr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})})]})]});return e.jsx(ge,{children:e.jsxs(lg,{children:[n==="start"&&S(),n==="email"&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(uo,{children:[e.jsx(po,{children:"Forgot Password"}),e.jsx(Dn,{children:"Enter your email address and we'll send you a code to reset your password."})]}),e.jsxs(yt,{onSubmit:y,noValidate:!0,children:[e.jsxs(he,{children:[e.jsx(
|
|
1302
|
+
`;function hg({onBack:t}){const{deployment:r}=ye(),{navigate:o}=tt(),[n,s]=i.useState("start"),[a,h]=i.useState(""),[g,c]=i.useState(""),[u,d]=i.useState(""),[p,x]=i.useState(""),[m,v]=i.useState(""),{forgotPassword:b,verifyOtp:_,resetPassword:k}=Gc(),[C,z]=i.useState(!1),[E,w]=i.useState(null),y=async j=>{if(j.preventDefault(),!!a){z(!0),w(null);try{await b(a),s("otp")}catch(T){w(T)}finally{z(!1)}}},f=async j=>{if(j.preventDefault(),g.length===6){z(!0),w(null);try{const T=await _(a,g);T.data&&(d(T.data.token),s("reset"))}catch(T){w(T)}finally{z(!1)}}},$=async j=>{var T,R;if(j.preventDefault(),p===m&&!(p.length<8)){z(!0),w(null);try{const O=await k(u,p);if(O.data){const P=O.data,M=P.signin_attempts&&P.signin_attempts.length>0?P.signin_attempts[P.signin_attempts.length-1]:null;if(M&&!M.completed){const N=(T=r==null?void 0:r.ui_settings)==null?void 0:T.sign_in_page_url;if(N){const D=new URL(N,window.location.origin);D.searchParams.set("signin_attempt_id",M.id),o(D.toString())}else t()}else{const N=((R=r==null?void 0:r.ui_settings)==null?void 0:R.after_signin_redirect_url)||"/";o(N)}}}catch(O){w(O)}finally{z(!1)}}},S=()=>e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsx(uo,{children:e.jsx(po,{children:"Forgot Password"})}),e.jsx(dg,{onClick:()=>s("email"),disabled:C,children:"Reset your password"}),e.jsx(ug,{children:e.jsx(pg,{children:"Or, sign in with another method"})}),e.jsx(Ul,{}),e.jsxs(ho,{children:[e.jsxs(Dr,{children:["Unable to reset password? ",e.jsx(Nr,{href:"/contact",children:"Get help"})]}),e.jsx(Dr,{style:{marginTop:"var(--space-sm)"},children:e.jsx(Nr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})})]})]});return e.jsx(ge,{children:e.jsxs(lg,{children:[n==="start"&&S(),n==="email"&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(uo,{children:[e.jsx(po,{children:"Forgot Password"}),e.jsx(Dn,{children:"Enter your email address and we'll send you a code to reset your password."})]}),e.jsxs(yt,{onSubmit:y,noValidate:!0,children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"email",children:"Email Address"}),e.jsx(ce,{type:"email",id:"email",value:a,onChange:j=>h(j.target.value),placeholder:"Enter your email",required:!0})]}),E&&e.jsx(Nn,{children:E.message}),e.jsx(K,{type:"submit",disabled:C,style:{width:"100%",marginTop:"var(--space-md)"},children:C?"Sending...":"Send Code"})]}),e.jsx(ho,{children:e.jsx(Dr,{style:{marginTop:"var(--space-sm)"},children:e.jsx(Nr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})})})]}),n==="otp"&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(uo,{children:[e.jsx(po,{children:"Enter Verification Code"}),e.jsxs(Dn,{children:["We've sent a 6-digit code to ",a,". Please enter it below."]})]}),e.jsxs(yt,{onSubmit:f,noValidate:!0,children:[e.jsx(Gt,{onComplete:j=>c(j),isSubmitting:C,error:E==null?void 0:E.message,onResend:async()=>{await b(a)}}),E&&e.jsx(Nn,{children:E.message}),e.jsx(K,{type:"submit",disabled:C||g.length!==6,style:{width:"100%",marginTop:"var(--space-md)"},children:C?"Verifying...":"Verify"})]}),e.jsx(ho,{children:e.jsx(Dr,{style:{marginTop:"var(--space-sm)"},children:e.jsx(Nr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})})})]}),n==="reset"&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{}),e.jsxs(uo,{children:[e.jsx(po,{children:"Reset Password"}),e.jsx(Dn,{children:"Create a new password for your account."})]}),e.jsxs(yt,{onSubmit:$,noValidate:!0,children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"password",children:"New Password"}),e.jsx(ce,{type:"password",id:"password",value:p,onChange:j=>x(j.target.value),placeholder:"Enter new password",required:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"confirmPassword",children:"Confirm New Password"}),e.jsx(ce,{type:"password",id:"confirmPassword",value:m,onChange:j=>v(j.target.value),placeholder:"Confirm new password",required:!0})]}),E&&e.jsx(Nn,{children:E.message}),e.jsx(K,{type:"submit",disabled:C,style:{width:"100%",marginTop:"var(--space-md)"},children:C?"Resetting...":"Reset Password"})]}),e.jsx(ho,{children:e.jsx(Dr,{style:{marginTop:"var(--space-sm)"},children:e.jsx(Nr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})})})]})]})})}const fg=l.div`
|
|
1303
1303
|
max-width: 360px;
|
|
1304
1304
|
width: 360px;
|
|
1305
1305
|
padding: var(--space-2xl);
|
|
@@ -1459,9 +1459,9 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
1459
1459
|
&:hover {
|
|
1460
1460
|
color: var(--color-primary-hover);
|
|
1461
1461
|
}
|
|
1462
|
-
`,Ng=l(
|
|
1462
|
+
`,Ng=l(ce)`
|
|
1463
1463
|
padding: var(--space-sm) var(--space-md);
|
|
1464
|
-
`;function Vl({onVerify:t,onBack:r,loading:o}){const[n,s]=i.useState(""),[a,h]=i.useState(""),g=u=>{if(u.preventDefault(),n.length!==4){h("Please enter the last 4 digits of your phone number");return}t(n)},c=u=>{const d=u.target.value.replace(/\D/g,"").slice(0,4);s(d),h("")};return e.jsx(ge,{children:e.jsxs(Pg,{children:[e.jsx(Me,{}),e.jsxs(Rg,{children:[e.jsx(Tg,{children:"Verify your phone number"}),e.jsx(Mg,{children:"To send a verification code, please confirm the last 4 digits of your primary phone number"})]}),e.jsxs(yt,{onSubmit:g,noValidate:!0,children:[e.jsxs(he,{children:[e.jsx(
|
|
1464
|
+
`;function Vl({onVerify:t,onBack:r,loading:o}){const[n,s]=i.useState(""),[a,h]=i.useState(""),g=u=>{if(u.preventDefault(),n.length!==4){h("Please enter the last 4 digits of your phone number");return}t(n)},c=u=>{const d=u.target.value.replace(/\D/g,"").slice(0,4);s(d),h("")};return e.jsx(ge,{children:e.jsxs(Pg,{children:[e.jsx(Me,{}),e.jsxs(Rg,{children:[e.jsx(Tg,{children:"Verify your phone number"}),e.jsx(Mg,{children:"To send a verification code, please confirm the last 4 digits of your primary phone number"})]}),e.jsxs(yt,{onSubmit:g,noValidate:!0,children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"lastDigits",children:"Last 4 digits"}),e.jsx(Ng,{type:"text",id:"lastDigits",name:"lastDigits",value:n,onChange:c,placeholder:"0000",maxLength:4,autoComplete:"off","aria-invalid":!!a,autoFocus:!0}),a&&e.jsx(Og,{children:a})]}),e.jsx(Ag,{type:"submit",disabled:o||n.length!==4,children:o?"Verifying...":"Send code"})]}),e.jsx(Lg,{children:e.jsx(Dg,{onClick:r,style:{cursor:"pointer"},children:"Choose a different method"})})]})})}const Fg=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),Bg=()=>e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2",ry:"2"}),e.jsx("path",{d:"M12 18h.01"})]}),Ug=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m21 2-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0 3 3L22 7l-3-3m-3.5 3.5L19 4"})}),Fn=l.div`
|
|
1465
1465
|
max-width: 380px;
|
|
1466
1466
|
width: 380px;
|
|
1467
1467
|
padding: var(--space-3xl);
|
|
@@ -1520,9 +1520,9 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
1520
1520
|
&:hover {
|
|
1521
1521
|
color: var(--color-primary-hover);
|
|
1522
1522
|
}
|
|
1523
|
-
`,Hg=l(
|
|
1523
|
+
`,Hg=l(ce)`
|
|
1524
1524
|
padding: var(--space-sm) var(--space-md);
|
|
1525
|
-
`;function Gl({onBack:t,attempt:r,completeVerification:o,prepareVerification:n}){const{deployment:s}=ye(),[a,h]=i.useState(""),[g,c]=i.useState({}),[u,d]=i.useState(!1),[p,x]=i.useState(null),[m,v]=i.useState(!0),[b,_]=i.useState(!1),[k,C]=i.useState(""),[z,E]=i.useState(!1),{navigate:w}=tt(),y=(r==null?void 0:r.available_2fa_methods)||[],f=[{id:"authenticator",name:"Authenticator app",description:"Use your authenticator app",icon:e.jsx(Fg,{}),available:y.includes("authenticator")},{id:"phone_otp",name:"Text message",description:"Get a code via SMS",icon:e.jsx(Bg,{}),available:y.includes("phone_otp"),phoneNumber:k},{id:"backup_code",name:"Backup code",description:"Use one of your backup codes",icon:e.jsx(Ug,{}),available:y.includes("backup_code")}].filter(R=>R.available),$=async R=>{x(R),v(!1),R==="phone_otp"&&_(!0)},S=async R=>{var O,P;if(r){d(!0);try{const M=await n({strategy:"phone_otp",lastDigits:R});M&&"data"in M&&((O=M.data)!=null&&O.otp_sent)?((P=M.data)!=null&&P.masked_phone&&C(M.data.masked_phone),_(!1)):c({phone:"Phone number verification failed"})}catch(M){c({phone:M.message})}finally{d(!1)}}},j=async(R,O)=>{if(R.preventDefault(),u)return;const P=O||a,M={};if(P?p==="authenticator"&&P.length!==6?M.code="Authentication code must be 6 digits":p==="phone_otp"&&P.length!==6&&(M.code="SMS code must be 6 digits"):M.code="Verification code is required",c(M),!(Object.keys(M).length>0)){d(!0);try{await o(P)}catch(N){c({submit:N.message})}finally{d(!1)}}},T=R=>{let O=R.target.value;p!=="backup_code"&&(O=O.replace(/\D/g,"").slice(0,6)),h(O),c(P=>({...P,code:""}))};return i.useEffect(()=>{var R;if(r.completed){E(!0);let O=new URLSearchParams(window.location.search).get("redirect_uri");if(O||(O=((R=s==null?void 0:s.ui_settings)==null?void 0:R.after_signin_redirect_url)||null),!O&&(s!=null&&s.frontend_host)&&(O=`https://${s.frontend_host}`),O){let P;try{P=new URL(O)}catch{P=new URL(O,window.location.origin)}(s==null?void 0:s.mode)==="staging"&&P.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),w(P.toString())}return}},[r,s]),z?e.jsx(ge,{children:e.jsxs(Fn,{children:[e.jsx(Me,{}),e.jsx(Vg,{children:e.jsx(bt,{size:32})})]})}):m?f.length===0?e.jsx(ge,{children:e.jsxs(Fn,{children:[e.jsx(Me,{}),e.jsxs(Wa,{children:[e.jsx(Va,{children:"Set Up Two-Factor Authentication"}),e.jsx(Ga,{children:"Your account requires two-factor authentication, but you haven't set up any methods yet. Please contact your administrator to set up 2FA."})]}),e.jsxs(qa,{children:[t&&e.jsx("div",{children:e.jsx(Fr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})}),e.jsxs("div",{style:{marginTop:"var(--space-sm)"},children:["Having trouble?"," ",e.jsx(Fr,{children:e.jsx(pt,{to:(s==null?void 0:s.ui_settings.support_page_url)||"#",children:"Get help"})})]})]})]})}):e.jsx(Wl,{methods:f,onSelectMethod:$,onBack:t}):b&&p==="phone_otp"?e.jsx(Vl,{onVerify:S,onBack:()=>{_(!1),v(!0),x(null)},loading:u}):e.jsx(ge,{children:e.jsxs(Fn,{children:[e.jsx(Me,{}),e.jsxs(Wa,{children:[e.jsx(Va,{children:"Two-factor authentication"}),e.jsxs(Ga,{children:[p==="authenticator"&&"Enter the 6-digit code from your authenticator app",p==="phone_otp"&&`Enter the 6-digit code sent to your phone ${k}`,p==="backup_code"&&"Enter one of your backup codes"]})]}),e.jsxs(yt,{onSubmit:j,noValidate:!0,children:[p==="backup_code"?e.jsxs(he,{children:[e.jsx(
|
|
1525
|
+
`;function Gl({onBack:t,attempt:r,completeVerification:o,prepareVerification:n}){const{deployment:s}=ye(),[a,h]=i.useState(""),[g,c]=i.useState({}),[u,d]=i.useState(!1),[p,x]=i.useState(null),[m,v]=i.useState(!0),[b,_]=i.useState(!1),[k,C]=i.useState(""),[z,E]=i.useState(!1),{navigate:w}=tt(),y=(r==null?void 0:r.available_2fa_methods)||[],f=[{id:"authenticator",name:"Authenticator app",description:"Use your authenticator app",icon:e.jsx(Fg,{}),available:y.includes("authenticator")},{id:"phone_otp",name:"Text message",description:"Get a code via SMS",icon:e.jsx(Bg,{}),available:y.includes("phone_otp"),phoneNumber:k},{id:"backup_code",name:"Backup code",description:"Use one of your backup codes",icon:e.jsx(Ug,{}),available:y.includes("backup_code")}].filter(R=>R.available),$=async R=>{x(R),v(!1),R==="phone_otp"&&_(!0)},S=async R=>{var O,P;if(r){d(!0);try{const M=await n({strategy:"phone_otp",lastDigits:R});M&&"data"in M&&((O=M.data)!=null&&O.otp_sent)?((P=M.data)!=null&&P.masked_phone&&C(M.data.masked_phone),_(!1)):c({phone:"Phone number verification failed"})}catch(M){c({phone:M.message})}finally{d(!1)}}},j=async(R,O)=>{if(R.preventDefault(),u)return;const P=O||a,M={};if(P?p==="authenticator"&&P.length!==6?M.code="Authentication code must be 6 digits":p==="phone_otp"&&P.length!==6&&(M.code="SMS code must be 6 digits"):M.code="Verification code is required",c(M),!(Object.keys(M).length>0)){d(!0);try{await o(P)}catch(N){c({submit:N.message})}finally{d(!1)}}},T=R=>{let O=R.target.value;p!=="backup_code"&&(O=O.replace(/\D/g,"").slice(0,6)),h(O),c(P=>({...P,code:""}))};return i.useEffect(()=>{var R;if(r.completed){E(!0);let O=new URLSearchParams(window.location.search).get("redirect_uri");if(O||(O=((R=s==null?void 0:s.ui_settings)==null?void 0:R.after_signin_redirect_url)||null),!O&&(s!=null&&s.frontend_host)&&(O=`https://${s.frontend_host}`),O){let P;try{P=new URL(O)}catch{P=new URL(O,window.location.origin)}(s==null?void 0:s.mode)==="staging"&&P.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),w(P.toString())}return}},[r,s]),z?e.jsx(ge,{children:e.jsxs(Fn,{children:[e.jsx(Me,{}),e.jsx(Vg,{children:e.jsx(bt,{size:32})})]})}):m?f.length===0?e.jsx(ge,{children:e.jsxs(Fn,{children:[e.jsx(Me,{}),e.jsxs(Wa,{children:[e.jsx(Va,{children:"Set Up Two-Factor Authentication"}),e.jsx(Ga,{children:"Your account requires two-factor authentication, but you haven't set up any methods yet. Please contact your administrator to set up 2FA."})]}),e.jsxs(qa,{children:[t&&e.jsx("div",{children:e.jsx(Fr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})}),e.jsxs("div",{style:{marginTop:"var(--space-sm)"},children:["Having trouble?"," ",e.jsx(Fr,{children:e.jsx(pt,{to:(s==null?void 0:s.ui_settings.support_page_url)||"#",children:"Get help"})})]})]})]})}):e.jsx(Wl,{methods:f,onSelectMethod:$,onBack:t}):b&&p==="phone_otp"?e.jsx(Vl,{onVerify:S,onBack:()=>{_(!1),v(!0),x(null)},loading:u}):e.jsx(ge,{children:e.jsxs(Fn,{children:[e.jsx(Me,{}),e.jsxs(Wa,{children:[e.jsx(Va,{children:"Two-factor authentication"}),e.jsxs(Ga,{children:[p==="authenticator"&&"Enter the 6-digit code from your authenticator app",p==="phone_otp"&&`Enter the 6-digit code sent to your phone ${k}`,p==="backup_code"&&"Enter one of your backup codes"]})]}),e.jsxs(yt,{onSubmit:j,noValidate:!0,children:[p==="backup_code"?e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"code",children:"Backup code"}),e.jsx(Hg,{type:"text",id:"code",name:"code",value:a,onChange:T,placeholder:"Enter backup code",maxLength:20,autoComplete:"one-time-code","aria-invalid":!!g.code,autoFocus:!0}),g.code&&e.jsx(Ha,{children:g.code})]}):e.jsx(Gt,{onComplete:async R=>{if(h(R),p!=="backup_code"){const O=new Event("submit",{bubbles:!0,cancelable:!0});await j(O,R)}},onResend:p==="phone_otp"?async()=>{try{await n({strategy:"phone_otp",lastDigits:k.slice(-4)})}catch(R){c({submit:R.message})}}:void 0,error:g.code,isSubmitting:u}),e.jsxs("div",{children:[g.submit&&e.jsx(Ha,{children:g.submit}),e.jsx(Gg,{type:"submit",disabled:u||!a,children:u?"Verifying...":"Verify"})]})]}),e.jsxs(qa,{children:[e.jsx(Fr,{onClick:()=>{v(!0),x(null),h(""),c({})},style:{cursor:"pointer"},children:"Try another method"}),e.jsxs("div",{style:{marginTop:"var(--space-sm)"},children:["Having trouble?"," ",e.jsx(Fr,{children:e.jsx(pt,{to:(s==null?void 0:s.ui_settings.support_page_url)||"#",children:"Get help"})})]}),t&&e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Fr,{onClick:t,style:{cursor:"pointer"},children:"Back to login"})})]})]})})}const Bn=l.div`
|
|
1526
1526
|
max-width: 380px;
|
|
1527
1527
|
width: 380px;
|
|
1528
1528
|
padding: var(--space-3xl);
|
|
@@ -1587,7 +1587,7 @@ See https://s-c.sh/2BAXzed for more info.`),window[co]+=1);/**
|
|
|
1587
1587
|
transform: rotate(360deg);
|
|
1588
1588
|
}
|
|
1589
1589
|
}
|
|
1590
|
-
`;function Hl({attempt:t,onBack:r,completeProfile:o,completeVerification:n,prepareVerification:s}){var L,I,A,q,Y,B,H,V,J;const{deployment:a}=ye(),{navigate:h}=tt(),[g,c]=i.useState({}),[u,d]=i.useState({}),[p,x]=i.useState("US"),[m,v]=i.useState(!1),[b,_]=i.useState(!1),[k,C]=i.useState(null),[z,E]=i.useState(!1),w=k,y=b,f=async oe=>{var re;_(!0),C(null);try{if(await o(oe)){E(!0);let X=new URLSearchParams(window.location.search).get("redirect_uri");if(X||(X=((re=a==null?void 0:a.ui_settings)==null?void 0:re.after_signin_redirect_url)||null),!X&&(a!=null&&a.frontend_host)&&(X=`https://${a.frontend_host}`),X){let ue;try{ue=new URL(X)}catch{ue=new URL(X,window.location.origin)}(a==null?void 0:a.mode)==="staging"&&ue.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),h(ue.toString())}}}catch(fe){const X=fe;throw C(X),X}finally{_(!1)}},$=async oe=>{var re;_(!0),C(null);try{if(await n(oe)){E(!0);let X=new URLSearchParams(window.location.search).get("redirect_uri");if(X||(X=((re=a==null?void 0:a.ui_settings)==null?void 0:re.after_signin_redirect_url)||null),!X&&(a!=null&&a.frontend_host)&&(X=`https://${a.frontend_host}`),X){let ue;try{ue=new URL(X)}catch{ue=new URL(X,window.location.origin)}(a==null?void 0:a.mode)==="staging"&&ue.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),h(ue.toString())}}return!0}catch(fe){return C(fe),!1}finally{_(!1)}};if(z||!t)return e.jsx(ge,{children:e.jsxs(Bn,{children:[e.jsx(Me,{}),e.jsx(Zg,{children:e.jsx(bt,{size:32})})]})});const S=t.missing_fields||[],j="Complete Your Profile",T="Please provide the following information to continue",R=a==null?void 0:a.auth_settings,O=(t==null?void 0:t.current_step)==="verify_phone_otp"||(t==null?void 0:t.current_step)==="verify_email_otp"||m,P=oe=>{const{name:re,value:fe}=oe.target;c(X=>({...X,[re]:fe})),u[re]&&d(X=>({...X,[re]:""}))},M=()=>{const oe={};return S.forEach(re=>{var ue,ve,pe,U,
|
|
1590
|
+
`;function Hl({attempt:t,onBack:r,completeProfile:o,completeVerification:n,prepareVerification:s}){var L,I,A,q,Y,B,H,V,J;const{deployment:a}=ye(),{navigate:h}=tt(),[g,c]=i.useState({}),[u,d]=i.useState({}),[p,x]=i.useState("US"),[m,v]=i.useState(!1),[b,_]=i.useState(!1),[k,C]=i.useState(null),[z,E]=i.useState(!1),w=k,y=b,f=async oe=>{var re;_(!0),C(null);try{if(await o(oe)){E(!0);let X=new URLSearchParams(window.location.search).get("redirect_uri");if(X||(X=((re=a==null?void 0:a.ui_settings)==null?void 0:re.after_signin_redirect_url)||null),!X&&(a!=null&&a.frontend_host)&&(X=`https://${a.frontend_host}`),X){let ue;try{ue=new URL(X)}catch{ue=new URL(X,window.location.origin)}(a==null?void 0:a.mode)==="staging"&&ue.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),h(ue.toString())}}}catch(fe){const X=fe;throw C(X),X}finally{_(!1)}},$=async oe=>{var re;_(!0),C(null);try{if(await n(oe)){E(!0);let X=new URLSearchParams(window.location.search).get("redirect_uri");if(X||(X=((re=a==null?void 0:a.ui_settings)==null?void 0:re.after_signin_redirect_url)||null),!X&&(a!=null&&a.frontend_host)&&(X=`https://${a.frontend_host}`),X){let ue;try{ue=new URL(X)}catch{ue=new URL(X,window.location.origin)}(a==null?void 0:a.mode)==="staging"&&ue.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),h(ue.toString())}}return!0}catch(fe){return C(fe),!1}finally{_(!1)}};if(z||!t)return e.jsx(ge,{children:e.jsxs(Bn,{children:[e.jsx(Me,{}),e.jsx(Zg,{children:e.jsx(bt,{size:32})})]})});const S=t.missing_fields||[],j="Complete Your Profile",T="Please provide the following information to continue",R=a==null?void 0:a.auth_settings,O=(t==null?void 0:t.current_step)==="verify_phone_otp"||(t==null?void 0:t.current_step)==="verify_email_otp"||m,P=oe=>{const{name:re,value:fe}=oe.target;c(X=>({...X,[re]:fe})),u[re]&&d(X=>({...X,[re]:""}))},M=()=>{const oe={};return S.forEach(re=>{var ue,ve,pe,U,le;const fe=g[re];let X=!1;switch(re){case"first_name":X=((ue=R==null?void 0:R.first_name)==null?void 0:ue.enabled)||!1;break;case"last_name":X=((ve=R==null?void 0:R.last_name)==null?void 0:ve.enabled)||!1;break;case"username":X=((pe=R==null?void 0:R.username)==null?void 0:pe.enabled)||!1;break;case"phone_number":X=((U=R==null?void 0:R.phone_number)==null?void 0:U.enabled)||!1;break;case"email_address":X=((le=R==null?void 0:R.email_address)==null?void 0:le.enabled)||!1;break;default:X=!0}if(X&&(!fe||fe.trim()==="")){const Q=re.replace("_"," ").replace(/\b\w/g,Z=>Z.toUpperCase());oe[re]=`${Q} is required`}}),g.username&&S.includes("username")&&(/^[a-zA-Z0-9_-]{3,30}$/.test(g.username)||(oe.username="Username must be 3-30 characters and contain only letters, numbers, underscores, and hyphens")),g.phone_number&&S.includes("phone_number")&&(/^\d{7,15}$/.test(g.phone_number)||(oe.phone_number="Phone number must contain 7-15 digits")),g.email&&S.includes("email_address")&&(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(g.email)||(oe.email_address="Please enter a valid email address")),d(oe),Object.keys(oe).length===0},N=async oe=>{if(oe.preventDefault(),!M())return;const re={...g};g.phone_number&&p&&(re.phone_country_code=p),await f(re)},D=oe=>{const re=oe.target.value;c(fe=>({...fe,phone_number:re})),u.phone_number&&d(fe=>({...fe,phone_number:""}))};if(O){const oe=t.current_step==="verify_phone_otp"?"Verify Your Phone Number":"Verify Your Email",re=t.current_step==="verify_phone_otp"?"Enter the 6-digit code sent to your phone":"Enter the 6-digit code sent to your email",fe=t.current_step==="verify_phone_otp"?"phone_otp":"email_otp";return e.jsx(ge,{children:e.jsxs(Bn,{children:[e.jsx(Me,{}),e.jsxs(Ya,{children:[e.jsx(Za,{children:oe}),e.jsx(Ka,{children:re})]}),e.jsxs(yt,{onSubmit:X=>X.preventDefault(),noValidate:!0,children:[e.jsx(Gt,{onComplete:$,onResend:async()=>{await s({strategy:fe})},error:w==null?void 0:w.message,isSubmitting:y}),w&&e.jsx(Zt,{style:{marginBottom:"var(--space-md)"},children:w.message})]}),e.jsxs(Qa,{children:[e.jsx("div",{children:e.jsx(fo,{onClick:()=>v(!1),style:{cursor:"pointer"},children:"Back to profile completion"})}),e.jsxs("div",{style:{marginTop:"var(--space-sm)"},children:["Having trouble?"," ",e.jsx(fo,{children:e.jsx(pt,{to:(a==null?void 0:a.ui_settings.support_page_url)||"#",children:"Get help"})})]})]})]})})}return e.jsx(ge,{children:e.jsxs(Bn,{children:[e.jsx(Me,{}),e.jsxs(Ya,{children:[e.jsx(Za,{children:j}),e.jsx(Ka,{children:T})]}),e.jsxs(yt,{onSubmit:N,noValidate:!0,children:[(S.includes("first_name")||S.includes("last_name"))&&(((L=R==null?void 0:R.first_name)==null?void 0:L.enabled)||((I=R==null?void 0:R.last_name)==null?void 0:I.enabled))&&e.jsxs(qg,{$isBothEnabled:!!((A=R==null?void 0:R.first_name)!=null&&A.enabled&&((q=R==null?void 0:R.last_name)!=null&&q.enabled)&&S.includes("first_name")&&S.includes("last_name")),children:[S.includes("first_name")&&((Y=R==null?void 0:R.first_name)==null?void 0:Y.enabled)&&e.jsxs(he,{children:[e.jsxs(ie,{htmlFor:"first_name",children:["First name ",R.first_name.required&&"*"]}),e.jsx(ce,{type:"text",id:"first_name",name:"first_name",value:g.first_name||"",onChange:P,placeholder:"Enter your first name","aria-invalid":!!u.first_name,disabled:y,autoComplete:"given-name"}),u.first_name&&e.jsx(Zt,{children:u.first_name})]}),S.includes("last_name")&&((B=R==null?void 0:R.last_name)==null?void 0:B.enabled)&&e.jsxs(he,{children:[e.jsxs(ie,{htmlFor:"last_name",children:["Last name ",R.last_name.required&&"*"]}),e.jsx(ce,{type:"text",id:"last_name",name:"last_name",value:g.last_name||"",onChange:P,placeholder:"Enter your last name","aria-invalid":!!u.last_name,disabled:y,autoComplete:"family-name"}),u.last_name&&e.jsx(Zt,{children:u.last_name})]})]}),S.includes("username")&&((H=R==null?void 0:R.username)==null?void 0:H.enabled)&&e.jsxs(he,{children:[e.jsxs(ie,{htmlFor:"username",children:["Username ",R.username.required&&"*"]}),e.jsx(ce,{type:"text",id:"username",name:"username",value:g.username||"",onChange:P,placeholder:"Choose a username","aria-invalid":!!u.username,disabled:y,autoComplete:"username"}),u.username&&e.jsx(Zt,{children:u.username})]}),S.includes("phone_number")&&((V=R==null?void 0:R.phone_number)==null?void 0:V.enabled)&&e.jsxs(he,{children:[e.jsxs(ie,{htmlFor:"phone_number",children:["Phone number ",R.phone_number.required&&"*"]}),e.jsx(eo,{value:g.phone_number||"",onChange:D,error:u.phone_number,countryCode:p,setCountryCode:x}),u.phone_number&&e.jsx(Zt,{children:u.phone_number})]}),S.includes("email_address")&&((J=R==null?void 0:R.email_address)==null?void 0:J.enabled)&&e.jsxs(he,{children:[e.jsxs(ie,{htmlFor:"email",children:["Email address ",R.email_address.required&&"*"]}),e.jsx(ce,{type:"email",id:"email",name:"email",value:g.email||"",onChange:P,placeholder:"Enter your email address","aria-invalid":!!u.email_address,disabled:y,autoComplete:"email"}),u.email_address&&e.jsx(Zt,{children:u.email_address})]}),w&&e.jsx(Zt,{style:{marginBottom:"var(--space-md)"},children:w.message}),e.jsx(Yg,{type:"submit",disabled:y,children:y?"Completing...":"Continue"})]}),e.jsxs(Qa,{children:[r&&e.jsx("div",{children:e.jsx(fo,{onClick:r,style:{cursor:"pointer"},children:"Back to login"})}),e.jsxs("div",{style:{marginTop:"var(--space-sm)"},children:["Having trouble?"," ",e.jsx(fo,{children:e.jsx(pt,{to:(a==null?void 0:a.ui_settings.support_page_url)||"#",children:"Get help"})})]})]})]})})}const Kg=l.div`
|
|
1591
1591
|
text-align: center;
|
|
1592
1592
|
margin-bottom: var(--space-2xl);
|
|
1593
1593
|
`,Qg=l.div`
|
|
@@ -1809,7 +1809,7 @@ cursor: pointer;
|
|
|
1809
1809
|
&:hover {
|
|
1810
1810
|
color: var(--color-primary-hover);
|
|
1811
1811
|
}
|
|
1812
|
-
`;function gm(){return e.jsx(cg,{children:e.jsx(mm,{})})}function mm(){var ce,Q,Z,ne,me,le,ee,W,F,se,be,Oe,Fe,Se,Ve,Ae;const{deployment:t}=ye(),{navigate:r}=tt(),{session:o,loading:n}=Ke(),s=((Q=(ce=t==null?void 0:t.auth_settings)==null?void 0:ce.multi_session_support)==null?void 0:Q.enabled)??!1,{setEmail:a,otpSent:h,setOtpSent:g,showForgotPassword:c,setShowForgotPassword:u,showOtherOptions:d,setShowOtherOptions:p,enabledSocialsProviders:x,firstFactor:m,signInStep:v,setSignInStep:b}=Bl(),{loading:_,signIn:k,signinAttempt:C,discardSignInAttempt:z,setSignInAttempt:E}=Sr("generic"),{signIn:w}=Sr("oauth"),{signIn:y}=Sr("passkey"),[f,$]=i.useState({email:"",username:"",password:"",phone:""}),[S,j]=i.useState({}),[T,R]=i.useState(!1),[O,P]=i.useState(""),[M,N]=i.useState("US"),[D,L]=i.useState(!1),[I,A]=i.useState(null),[q,Y]=i.useState(!1),[B,H]=i.useState(null);i.useEffect(()=>{const te=new URLSearchParams(window.location.search),xe=te.get("error"),_e=te.get("error_description");if(xe==="access_denied"&&_e){A(_e),te.delete("error"),te.delete("error_description");const Ce=te.toString()?`${window.location.pathname}?${te.toString()}`:window.location.pathname;window.history.replaceState({},"",Ce)}},[]),i.useEffect(()=>{var te,xe,_e,Ce;if(!n&&(o!=null&&o.active_signin)&&!s&&!D&&!q){let Pe=new URLSearchParams(window.location.search).get("redirect_uri");Pe||(Pe=((te=t==null?void 0:t.ui_settings)==null?void 0:te.after_signin_redirect_url)||null),!Pe&&(t!=null&&t.frontend_host)&&(Pe=`https://${t.frontend_host}`);const Te=(xe=t==null?void 0:t.auth_settings)==null?void 0:xe.passkey;(Te==null?void 0:Te.enabled)&&(Te==null?void 0:Te.prompt_registration_on_auth)&&!((Ce=(_e=o.active_signin)==null?void 0:_e.user)!=null&&Ce.has_passkeys)?(H(Pe),Y(!0)):Pe&&(L(!0),r(Pe))}},[o,n,s,t,r,D]);const V=te=>{let{name:xe,value:_e}=te.target;xe==="phone"?_e=_e.replace(/[^0-9]/g,""):xe==="email"&&(a(_e),_e=_e.toLowerCase()),$(Ce=>({...Ce,[xe]:_e})),j(Ce=>({...Ce,[xe]:""}))},J=()=>{$({email:"",username:"",password:"",phone:""}),j({}),N("US"),b("identifier")},oe=async te=>{if(!te){j({email:"Email address is required"});return}R(!0),j({});try{const xe=await k.identify(te);if(xe.strategy==="sso"&&xe.connection_id){const Ce=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,Pe=await k.initEnterpriseSso(xe.connection_id,Ce);if(Pe&&Pe.sso_url){L(!0),window.location.href=Pe.sso_url;return}}else if(xe.strategy==="social"&&xe.provider){const _e=x.find(Ce=>Ce.provider===xe.provider);if(_e){const Pe=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,{data:Te}=await w.create({provider:_e.provider,redirectUri:Pe});if(Te&&typeof Te=="object"&&"oauth_url"in Te){L(!0),window.location.href=Te.oauth_url;return}}else b("password")}else b("password")}catch(xe){j({submit:xe.message})}finally{D||R(!1)}},re=async te=>{if(te.preventDefault(),_||T)return;z();const xe={};if(v==="identifier"&&m==="email_password"){if(!f.email){j({email:"Email address is required"});return}await oe(f.email);return}if(m==="email_password"?(f.email||(xe.email="Email address is required"),f.password||(xe.password="Password is required")):m==="username_password"?(f.username||(xe.username="Username is required"),f.password||(xe.password="Password is required")):m==="email_otp"||m==="email_magic_link"?f.email||(xe.email="Email address is required"):m==="phone_otp"&&(f.phone?/^\d{7,15}$/.test(f.phone)||(xe.phone="Phone number must contain 7-15 digits"):xe.phone="Phone number is required"),j(xe),Object.keys(xe).length>0)return;let _e="";switch(m){case"email_password":_e="plain_email";break;case"username_password":_e="plain_username";break;case"email_otp":_e="email_otp";break;case"email_magic_link":_e="magic_link";break;case"phone_otp":_e="phone_otp";break}R(!0);try{const Ce={...f,strategy:_e};m==="phone_otp"&&M&&(Ce.phone_country_code=M),await k.create(Ce)}catch(Ce){j({submit:Ce.message}),R(!1)}},fe=async te=>{if(te.preventDefault(),_||T)return;const xe={};if(!O){xe.otp="OTP code is required",j(xe);return}R(!0),j({});try{await k.completeVerification(O),g(!1),P("")}catch(_e){j({otp:_e.message||"Verification failed"})}finally{R(!1)}},X=async te=>{if(!(_||T)){R(!0);try{const _e=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,{data:Ce}=await w.create({provider:te.provider,redirectUri:_e});Ce&&typeof Ce=="object"&&"oauth_url"in Ce&&(window.location.href=Ce.oauth_url)}catch(xe){j({submit:xe.message})}finally{R(!1)}}},ue=async()=>{if(!(_||T)){R(!0),j({});try{const te=await y.create();"data"in te&&te.data&&L(!0)}catch(te){j({submit:te.message||"Passkey sign-in failed"})}finally{R(!1)}}},ve=i.useRef(!1);if(i.useEffect(()=>{if(n)return;const te=new URLSearchParams(window.location.search),xe=te.get("impersonation_token");if(xe&&!C&&!_&&!ve.current){ve.current=!0,te.delete("impersonation_token");const Ce=te.toString()?`${window.location.pathname}?${te.toString()} `:window.location.pathname;window.history.replaceState({},"",Ce),(async()=>{try{R(!0),await k.create({strategy:"impersonation",token:xe})}catch(Te){j({submit:Te.message}),R(!1),ve.current=!1}})();return}const _e=te.get("signin_attempt_id");if(_e&&(o!=null&&o.signin_attempts)&&!C){const Ce=o.signin_attempts.find(Pe=>Pe.id===_e);if(Ce){E(Ce),te.delete("signin_attempt_id");const Pe=te.toString()?`${window.location.pathname}?${te.toString()} `:window.location.pathname;window.history.replaceState({},"",Pe)}}},[o,n,C,E,_]),i.useEffect(()=>{var Ce;if(!C)return;if(C.completed){L(!0);let Pe=new URLSearchParams(window.location.search).get("redirect_uri");if(Pe||(Pe=((Ce=t==null?void 0:t.ui_settings)==null?void 0:Ce.after_signin_redirect_url)||null),!Pe&&(t!=null&&t.frontend_host)&&(Pe=`https://${t.frontend_host}`),Pe){let Te;try{Te=new URL(Pe)}catch{Te=new URL(Pe,window.location.origin)}(t==null?void 0:t.mode)==="staging"&&Te.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),r(Te.toString())}return}if(!k||h)return;const xe={verify_email:"email_otp",verify_email_otp:"email_otp",verify_email_link:"magic_link",verify_phone:"phone_otp",verify_phone_otp:"phone_otp"}[C.current_step];if(!xe)return;(async()=>{try{await k.prepareVerification({strategy:xe}),g(!0)}catch(Pe){console.error("Failed to prepare verification:",Pe),j({submit:"Failed to send verification. Please try again."})}finally{R(!1)}})()},[C,k,h,g,r,t]),i.useEffect(()=>{},[]),d)return e.jsx(bg,{onBack:()=>p(!1)});if(c)return e.jsx(hg,{onBack:()=>u(!1)});if((C==null?void 0:C.current_step)==="verify_second_factor")return e.jsx(Gl,{attempt:C,completeVerification:k.completeVerification,prepareVerification:k.prepareVerification,onBack:()=>{z(),J(),g(!1)}});if((C==null?void 0:C.current_step)==="complete_profile")return e.jsx(Hl,{attempt:C,completeProfile:k.completeProfile,completeVerification:k.completeVerification,prepareVerification:k.prepareVerification,onBack:()=>{z(),J(),g(!1)}});if(q){const te=()=>{Y(!1),B&&(L(!0),r(B))},xe=()=>{Y(!1),B&&(L(!0),r(B))};return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),e.jsx(ql,{onComplete:te,onSkip:xe})]})})}if(n)return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),e.jsx(Ja,{children:e.jsx(bt,{size:32})})]})});if(D)return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),e.jsx(Ja,{children:e.jsx(bt,{size:32})})]})});const U=(C==null?void 0:C.current_step)&&["verify_email","verify_email_otp","verify_email_link","verify_phone","verify_phone_otp"].includes(C.current_step)&&h;return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),U?e.jsx(e.Fragment,{children:e.jsxs(Xa,{children:[e.jsx(ei,{children:m==="phone_otp"?"Check your phone":"Check your email"}),e.jsx(ti,{children:m==="email_magic_link"?`If ${f.email} exists in our records, you will receive a magic link. Click the link to sign in.`:m==="phone_otp"?`If ${f.phone} exists in our records, you will receive a verification code via SMS. Enter it below to continue.`:`If ${f.email} exists in our records, you will receive a verification code. Enter it below to continue.`})]})}):e.jsxs(Xa,{children:[e.jsx(ei,{children:"Sign in to your account"}),e.jsxs(ti,{children:["Please enter your details to continue to"," ",(t==null?void 0:t.ui_settings.app_name)||"App","!"]})]}),I&&e.jsxs(um,{children:[e.jsx(pm,{children:"Access Denied"}),e.jsx(hm,{children:I}),e.jsx(fm,{onClick:()=>A(null),children:"Try again"})]}),U?m==="email_magic_link"?e.jsxs(Un,{children:["Having trouble?"," ",e.jsx(Kt,{children:e.jsx(pt,{to:t.ui_settings.support_page_url,children:"Get help"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Kt,{onClick:()=>{g(!1),z(),J()},style:{cursor:"pointer"},children:"Back to login"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(yt,{style:{gap:"15px"},onSubmit:fe,noValidate:!0,children:[e.jsx(Gt,{onComplete:async te=>{if(P(te),te&&te.length===6){R(!0),j({});try{await k.completeVerification(te),g(!1)}catch(xe){j({otp:xe.message||"Verification failed"})}finally{R(!1)}}},onResend:async()=>{const te=m==="email_otp"?"email_otp":"phone_otp";await k.prepareVerification({strategy:te})},error:S.otp,isSubmitting:T}),e.jsx(ri,{type:"submit",disabled:T||_||!O,style:{margin:0},children:T?"Verifying...":`Continue to ${(Ae=t==null?void 0:t.ui_settings)==null?void 0:Ae.app_name}`})]}),e.jsxs(Un,{children:["Having trouble?"," ",e.jsx(Kt,{children:e.jsx(pt,{to:t.ui_settings.support_page_url,children:"Get help"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Kt,{onClick:()=>{g(!1),z(),J()},style:{cursor:"pointer"},children:"Back to login"})})]})]}):e.jsxs(e.Fragment,{children:[x.length>0&&e.jsx(e.Fragment,{children:e.jsx(Ns,{connections:x,callback:X})}),((ne=(Z=t==null?void 0:t.auth_settings)==null?void 0:Z.passkey)==null?void 0:ne.enabled)&&e.jsxs(dm,{type:"button",onClick:ue,disabled:T,children:[e.jsx(Ss,{size:18}),"Sign in with Passkey"]}),(x.length>0||((le=(me=t==null?void 0:t.auth_settings)==null?void 0:me.passkey)==null?void 0:le.enabled))&&e.jsx(im,{children:e.jsx(cm,{children:"or"})}),e.jsxs(yt,{onSubmit:re,noValidate:!0,children:[(m==="email_password"||m==="email_otp"||m==="email_magic_link")&&((W=(ee=t==null?void 0:t.auth_settings)==null?void 0:ee.email_address)==null?void 0:W.enabled)&&e.jsxs(he,{children:[e.jsx(ae,{htmlFor:"email",children:"Email address"}),e.jsx(ie,{type:"email",id:"email",name:"email",value:f.email,onChange:V,placeholder:"Enter your email address","aria-invalid":!!S.email}),S.email&&e.jsx(Br,{children:S.email})]}),m==="username_password"&&((se=(F=t==null?void 0:t.auth_settings)==null?void 0:F.username)==null?void 0:se.enabled)&&e.jsxs(he,{children:[e.jsx(ae,{htmlFor:"username",children:"Username"}),e.jsx(ie,{type:"text",id:"username",name:"username",value:f.username,onChange:V,placeholder:"Enter your username","aria-invalid":!!S.username}),S.username&&e.jsx(Br,{children:S.username})]}),m==="phone_otp"&&((Oe=(be=t==null?void 0:t.auth_settings)==null?void 0:be.phone_number)==null?void 0:Oe.enabled)&&e.jsxs(he,{children:[e.jsx(ae,{htmlFor:"phone",children:"Phone number"}),e.jsx(eo,{value:f.phone,onChange:V,error:S.phone,countryCode:M,setCountryCode:N}),S.phone&&e.jsx(Br,{children:S.phone})]}),v==="password"&&(m==="email_password"||m==="username_password")&&((Se=(Fe=t==null?void 0:t.auth_settings)==null?void 0:Fe.password)==null?void 0:Se.enabled)&&e.jsxs(he,{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[e.jsx(ae,{htmlFor:"password",children:"Password"}),e.jsx(Kt,{style:{fontSize:"12px"},onClick:()=>u(!0),children:"Forgot password?"})]}),e.jsx(lm,{children:e.jsx(ie,{type:"password",id:"password",name:"password",value:f.password,onChange:V,placeholder:"Enter your password","aria-invalid":!!S.password})}),S.password&&e.jsx(Br,{children:S.password})]}),e.jsxs("div",{children:[S.submit&&e.jsx(Br,{children:S.submit}),e.jsx(ri,{type:"submit",disabled:T||_,children:T?e.jsxs(e.Fragment,{children:[e.jsx(bt,{size:16,style:{animation:"spin 1s linear infinite",marginRight:"8px"}}),v==="identifier"?"Checking...":"Signing in..."]}):v==="identifier"?"Continue":"Sign in"})]}),e.jsx(Kt,{style:{fontSize:"12px",textAlign:"center"},onClick:()=>p(!0),children:"Use other methods"})]}),e.jsxs(Un,{children:["Don't have an account?"," ",e.jsx(Kt,{children:e.jsx(pt,{to:`${(Ve=t.ui_settings)==null?void 0:Ve.sign_up_page_url}${window.location.search}`,children:"Sign up"})})]})]})]})})}const oi=l.div`
|
|
1812
|
+
`;function gm(){return e.jsx(cg,{children:e.jsx(mm,{})})}function mm(){var le,Q,Z,ne,me,de,ee,W,F,se,be,Oe,Fe,Se,Ve,Ae;const{deployment:t}=ye(),{navigate:r}=tt(),{session:o,loading:n}=Ke(),s=((Q=(le=t==null?void 0:t.auth_settings)==null?void 0:le.multi_session_support)==null?void 0:Q.enabled)??!1,{setEmail:a,otpSent:h,setOtpSent:g,showForgotPassword:c,setShowForgotPassword:u,showOtherOptions:d,setShowOtherOptions:p,enabledSocialsProviders:x,firstFactor:m,signInStep:v,setSignInStep:b}=Bl(),{loading:_,signIn:k,signinAttempt:C,discardSignInAttempt:z,setSignInAttempt:E}=Sr("generic"),{signIn:w}=Sr("oauth"),{signIn:y}=Sr("passkey"),[f,$]=i.useState({email:"",username:"",password:"",phone:""}),[S,j]=i.useState({}),[T,R]=i.useState(!1),[O,P]=i.useState(""),[M,N]=i.useState("US"),[D,L]=i.useState(!1),[I,A]=i.useState(null),[q,Y]=i.useState(!1),[B,H]=i.useState(null);i.useEffect(()=>{const te=new URLSearchParams(window.location.search),xe=te.get("error"),_e=te.get("error_description");if(xe==="access_denied"&&_e){A(_e),te.delete("error"),te.delete("error_description");const Ce=te.toString()?`${window.location.pathname}?${te.toString()}`:window.location.pathname;window.history.replaceState({},"",Ce)}},[]),i.useEffect(()=>{var te,xe,_e,Ce;if(!n&&(o!=null&&o.active_signin)&&!s&&!D&&!q){let Pe=new URLSearchParams(window.location.search).get("redirect_uri");Pe||(Pe=((te=t==null?void 0:t.ui_settings)==null?void 0:te.after_signin_redirect_url)||null),!Pe&&(t!=null&&t.frontend_host)&&(Pe=`https://${t.frontend_host}`);const Te=(xe=t==null?void 0:t.auth_settings)==null?void 0:xe.passkey;(Te==null?void 0:Te.enabled)&&(Te==null?void 0:Te.prompt_registration_on_auth)&&!((Ce=(_e=o.active_signin)==null?void 0:_e.user)!=null&&Ce.has_passkeys)?(H(Pe),Y(!0)):Pe&&(L(!0),r(Pe))}},[o,n,s,t,r,D]);const V=te=>{let{name:xe,value:_e}=te.target;xe==="phone"?_e=_e.replace(/[^0-9]/g,""):xe==="email"&&(a(_e),_e=_e.toLowerCase()),$(Ce=>({...Ce,[xe]:_e})),j(Ce=>({...Ce,[xe]:""}))},J=()=>{$({email:"",username:"",password:"",phone:""}),j({}),N("US"),b("identifier")},oe=async te=>{if(!te){j({email:"Email address is required"});return}R(!0),j({});try{const xe=await k.identify(te);if(xe.strategy==="sso"&&xe.connection_id){const Ce=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,Pe=await k.initEnterpriseSso(xe.connection_id,Ce);if(Pe&&Pe.sso_url){L(!0),window.location.href=Pe.sso_url;return}}else if(xe.strategy==="social"&&xe.provider){const _e=x.find(Ce=>Ce.provider===xe.provider);if(_e){const Pe=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,{data:Te}=await w.create({provider:_e.provider,redirectUri:Pe});if(Te&&typeof Te=="object"&&"oauth_url"in Te){L(!0),window.location.href=Te.oauth_url;return}}else b("password")}else b("password")}catch(xe){j({submit:xe.message})}finally{D||R(!1)}},re=async te=>{if(te.preventDefault(),_||T)return;z();const xe={};if(v==="identifier"&&m==="email_password"){if(!f.email){j({email:"Email address is required"});return}await oe(f.email);return}if(m==="email_password"?(f.email||(xe.email="Email address is required"),f.password||(xe.password="Password is required")):m==="username_password"?(f.username||(xe.username="Username is required"),f.password||(xe.password="Password is required")):m==="email_otp"||m==="email_magic_link"?f.email||(xe.email="Email address is required"):m==="phone_otp"&&(f.phone?/^\d{7,15}$/.test(f.phone)||(xe.phone="Phone number must contain 7-15 digits"):xe.phone="Phone number is required"),j(xe),Object.keys(xe).length>0)return;let _e="";switch(m){case"email_password":_e="plain_email";break;case"username_password":_e="plain_username";break;case"email_otp":_e="email_otp";break;case"email_magic_link":_e="magic_link";break;case"phone_otp":_e="phone_otp";break}R(!0);try{const Ce={...f,strategy:_e};m==="phone_otp"&&M&&(Ce.phone_country_code=M),await k.create(Ce)}catch(Ce){j({submit:Ce.message}),R(!1)}},fe=async te=>{if(te.preventDefault(),_||T)return;const xe={};if(!O){xe.otp="OTP code is required",j(xe);return}R(!0),j({});try{await k.completeVerification(O),g(!1),P("")}catch(_e){j({otp:_e.message||"Verification failed"})}finally{R(!1)}},X=async te=>{if(!(_||T)){R(!0);try{const _e=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,{data:Ce}=await w.create({provider:te.provider,redirectUri:_e});Ce&&typeof Ce=="object"&&"oauth_url"in Ce&&(window.location.href=Ce.oauth_url)}catch(xe){j({submit:xe.message})}finally{R(!1)}}},ue=async()=>{if(!(_||T)){R(!0),j({});try{const te=await y.create();"data"in te&&te.data&&L(!0)}catch(te){j({submit:te.message||"Passkey sign-in failed"})}finally{R(!1)}}},ve=i.useRef(!1);if(i.useEffect(()=>{if(n)return;const te=new URLSearchParams(window.location.search),xe=te.get("impersonation_token");if(xe&&!C&&!_&&!ve.current){ve.current=!0,te.delete("impersonation_token");const Ce=te.toString()?`${window.location.pathname}?${te.toString()} `:window.location.pathname;window.history.replaceState({},"",Ce),(async()=>{try{R(!0),await k.create({strategy:"impersonation",token:xe})}catch(Te){j({submit:Te.message}),R(!1),ve.current=!1}})();return}const _e=te.get("signin_attempt_id");if(_e&&(o!=null&&o.signin_attempts)&&!C){const Ce=o.signin_attempts.find(Pe=>Pe.id===_e);if(Ce){E(Ce),te.delete("signin_attempt_id");const Pe=te.toString()?`${window.location.pathname}?${te.toString()} `:window.location.pathname;window.history.replaceState({},"",Pe)}}},[o,n,C,E,_]),i.useEffect(()=>{var Ce;if(!C)return;if(C.completed){L(!0);let Pe=new URLSearchParams(window.location.search).get("redirect_uri");if(Pe||(Pe=((Ce=t==null?void 0:t.ui_settings)==null?void 0:Ce.after_signin_redirect_url)||null),!Pe&&(t!=null&&t.frontend_host)&&(Pe=`https://${t.frontend_host}`),Pe){let Te;try{Te=new URL(Pe)}catch{Te=new URL(Pe,window.location.origin)}(t==null?void 0:t.mode)==="staging"&&Te.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),r(Te.toString())}return}if(!k||h)return;const xe={verify_email:"email_otp",verify_email_otp:"email_otp",verify_email_link:"magic_link",verify_phone:"phone_otp",verify_phone_otp:"phone_otp"}[C.current_step];if(!xe)return;(async()=>{try{await k.prepareVerification({strategy:xe}),g(!0)}catch(Pe){console.error("Failed to prepare verification:",Pe),j({submit:"Failed to send verification. Please try again."})}finally{R(!1)}})()},[C,k,h,g,r,t]),i.useEffect(()=>{},[]),d)return e.jsx(bg,{onBack:()=>p(!1)});if(c)return e.jsx(hg,{onBack:()=>u(!1)});if((C==null?void 0:C.current_step)==="verify_second_factor")return e.jsx(Gl,{attempt:C,completeVerification:k.completeVerification,prepareVerification:k.prepareVerification,onBack:()=>{z(),J(),g(!1)}});if((C==null?void 0:C.current_step)==="complete_profile")return e.jsx(Hl,{attempt:C,completeProfile:k.completeProfile,completeVerification:k.completeVerification,prepareVerification:k.prepareVerification,onBack:()=>{z(),J(),g(!1)}});if(q){const te=()=>{Y(!1),B&&(L(!0),r(B))},xe=()=>{Y(!1),B&&(L(!0),r(B))};return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),e.jsx(ql,{onComplete:te,onSkip:xe})]})})}if(n)return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),e.jsx(Ja,{children:e.jsx(bt,{size:32})})]})});if(D)return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),e.jsx(Ja,{children:e.jsx(bt,{size:32})})]})});const U=(C==null?void 0:C.current_step)&&["verify_email","verify_email_otp","verify_email_link","verify_phone","verify_phone_otp"].includes(C.current_step)&&h;return e.jsx(ge,{children:e.jsxs(go,{children:[e.jsx(Me,{}),U?e.jsx(e.Fragment,{children:e.jsxs(Xa,{children:[e.jsx(ei,{children:m==="phone_otp"?"Check your phone":"Check your email"}),e.jsx(ti,{children:m==="email_magic_link"?`If ${f.email} exists in our records, you will receive a magic link. Click the link to sign in.`:m==="phone_otp"?`If ${f.phone} exists in our records, you will receive a verification code via SMS. Enter it below to continue.`:`If ${f.email} exists in our records, you will receive a verification code. Enter it below to continue.`})]})}):e.jsxs(Xa,{children:[e.jsx(ei,{children:"Sign in to your account"}),e.jsxs(ti,{children:["Please enter your details to continue to"," ",(t==null?void 0:t.ui_settings.app_name)||"App","!"]})]}),I&&e.jsxs(um,{children:[e.jsx(pm,{children:"Access Denied"}),e.jsx(hm,{children:I}),e.jsx(fm,{onClick:()=>A(null),children:"Try again"})]}),U?m==="email_magic_link"?e.jsxs(Un,{children:["Having trouble?"," ",e.jsx(Kt,{children:e.jsx(pt,{to:t.ui_settings.support_page_url,children:"Get help"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Kt,{onClick:()=>{g(!1),z(),J()},style:{cursor:"pointer"},children:"Back to login"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(yt,{style:{gap:"15px"},onSubmit:fe,noValidate:!0,children:[e.jsx(Gt,{onComplete:async te=>{if(P(te),te&&te.length===6){R(!0),j({});try{await k.completeVerification(te),g(!1)}catch(xe){j({otp:xe.message||"Verification failed"})}finally{R(!1)}}},onResend:async()=>{const te=m==="email_otp"?"email_otp":"phone_otp";await k.prepareVerification({strategy:te})},error:S.otp,isSubmitting:T}),e.jsx(ri,{type:"submit",disabled:T||_||!O,style:{margin:0},children:T?"Verifying...":`Continue to ${(Ae=t==null?void 0:t.ui_settings)==null?void 0:Ae.app_name}`})]}),e.jsxs(Un,{children:["Having trouble?"," ",e.jsx(Kt,{children:e.jsx(pt,{to:t.ui_settings.support_page_url,children:"Get help"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Kt,{onClick:()=>{g(!1),z(),J()},style:{cursor:"pointer"},children:"Back to login"})})]})]}):e.jsxs(e.Fragment,{children:[x.length>0&&e.jsx(e.Fragment,{children:e.jsx(Ns,{connections:x,callback:X})}),((ne=(Z=t==null?void 0:t.auth_settings)==null?void 0:Z.passkey)==null?void 0:ne.enabled)&&e.jsxs(dm,{type:"button",onClick:ue,disabled:T,children:[e.jsx(Ss,{size:18}),"Sign in with Passkey"]}),(x.length>0||((de=(me=t==null?void 0:t.auth_settings)==null?void 0:me.passkey)==null?void 0:de.enabled))&&e.jsx(im,{children:e.jsx(cm,{children:"or"})}),e.jsxs(yt,{onSubmit:re,noValidate:!0,children:[(m==="email_password"||m==="email_otp"||m==="email_magic_link")&&((W=(ee=t==null?void 0:t.auth_settings)==null?void 0:ee.email_address)==null?void 0:W.enabled)&&e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"email",children:"Email address"}),e.jsx(ce,{type:"email",id:"email",name:"email",value:f.email,onChange:V,placeholder:"Enter your email address","aria-invalid":!!S.email}),S.email&&e.jsx(Br,{children:S.email})]}),m==="username_password"&&((se=(F=t==null?void 0:t.auth_settings)==null?void 0:F.username)==null?void 0:se.enabled)&&e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"username",children:"Username"}),e.jsx(ce,{type:"text",id:"username",name:"username",value:f.username,onChange:V,placeholder:"Enter your username","aria-invalid":!!S.username}),S.username&&e.jsx(Br,{children:S.username})]}),m==="phone_otp"&&((Oe=(be=t==null?void 0:t.auth_settings)==null?void 0:be.phone_number)==null?void 0:Oe.enabled)&&e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"phone",children:"Phone number"}),e.jsx(eo,{value:f.phone,onChange:V,error:S.phone,countryCode:M,setCountryCode:N}),S.phone&&e.jsx(Br,{children:S.phone})]}),v==="password"&&(m==="email_password"||m==="username_password")&&((Se=(Fe=t==null?void 0:t.auth_settings)==null?void 0:Fe.password)==null?void 0:Se.enabled)&&e.jsxs(he,{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[e.jsx(ie,{htmlFor:"password",children:"Password"}),e.jsx(Kt,{style:{fontSize:"12px"},onClick:()=>u(!0),children:"Forgot password?"})]}),e.jsx(lm,{children:e.jsx(ce,{type:"password",id:"password",name:"password",value:f.password,onChange:V,placeholder:"Enter your password","aria-invalid":!!S.password})}),S.password&&e.jsx(Br,{children:S.password})]}),e.jsxs("div",{children:[S.submit&&e.jsx(Br,{children:S.submit}),e.jsx(ri,{type:"submit",disabled:T||_,children:T?e.jsxs(e.Fragment,{children:[e.jsx(bt,{size:16,style:{animation:"spin 1s linear infinite",marginRight:"8px"}}),v==="identifier"?"Checking...":"Signing in..."]}):v==="identifier"?"Continue":"Sign in"})]}),e.jsx(Kt,{style:{fontSize:"12px",textAlign:"center"},onClick:()=>p(!0),children:"Use other methods"})]}),e.jsxs(Un,{children:["Don't have an account?"," ",e.jsx(Kt,{children:e.jsx(pt,{to:`${(Ve=t.ui_settings)==null?void 0:Ve.sign_up_page_url}${window.location.search}`,children:"Sign up"})})]})]})]})})}const oi=l.div`
|
|
1813
1813
|
max-width: 380px;
|
|
1814
1814
|
width: 380px;
|
|
1815
1815
|
padding: var(--space-3xl);
|
|
@@ -1910,7 +1910,7 @@ cursor: pointer;
|
|
|
1910
1910
|
color: var(--color-primary);
|
|
1911
1911
|
text-decoration: none;
|
|
1912
1912
|
cursor: pointer;
|
|
1913
|
-
`;function Im(){var _,k,C,z,E,w,y,f,$,S,j,T;const{deployment:t}=ye(),{loading:r,joinWaitlist:o}=Bc(),[n,s]=i.useState({first_name:"",last_name:"",email:""}),[a,h]=i.useState(!1),[g,c]=i.useState(!1),[u,d]=i.useState(null),p=R=>{if(u)return u.message},x=t==null?void 0:t.auth_settings,m=!!((_=x==null?void 0:x.first_name)!=null&&_.enabled&&((k=x==null?void 0:x.last_name)!=null&&k.enabled)),v=R=>{const{name:O,value:P}=R.target;s(M=>({...M,[O]:P}))},b=async R=>{if(R.preventDefault(),!!x){c(!0),d(null);try{(await o(n)).data&&h(!0)}catch(O){d(O)}finally{c(!1)}}};return a?e.jsx(ge,{children:e.jsx(oi,{children:e.jsxs(_m,{children:[e.jsx(km,{children:e.jsx(et,{size:32})}),e.jsx(Cm,{children:"You're on the waitlist!"}),e.jsxs(Sm,{children:["Thanks for your interest! We'll notify you at ",n.email," ","when we're ready for you to join."]})]})})}):e.jsx(ge,{children:e.jsxs(oi,{children:[e.jsx(Me,{}),e.jsxs(xm,{children:[e.jsx(vm,{children:"Join the waitlist"}),e.jsx(bm,{children:"Be the first to know when we launch!"})]}),e.jsxs(ym,{onSubmit:b,noValidate:!0,children:[(((C=x==null?void 0:x.first_name)==null?void 0:C.enabled)||((z=x==null?void 0:x.last_name)==null?void 0:z.enabled))&&e.jsxs(wm,{$isBothEnabled:m,children:[((E=x==null?void 0:x.first_name)==null?void 0:E.enabled)&&e.jsxs(Wn,{children:[e.jsxs(Vn,{htmlFor:"first_name",children:["First name",((w=x==null?void 0:x.first_name)==null?void 0:w.required)&&e.jsx(Gn,{children:"*"})]}),e.jsx(
|
|
1913
|
+
`;function Im(){var _,k,C,z,E,w,y,f,$,S,j,T;const{deployment:t}=ye(),{loading:r,joinWaitlist:o}=Bc(),[n,s]=i.useState({first_name:"",last_name:"",email:""}),[a,h]=i.useState(!1),[g,c]=i.useState(!1),[u,d]=i.useState(null),p=R=>{if(u)return u.message},x=t==null?void 0:t.auth_settings,m=!!((_=x==null?void 0:x.first_name)!=null&&_.enabled&&((k=x==null?void 0:x.last_name)!=null&&k.enabled)),v=R=>{const{name:O,value:P}=R.target;s(M=>({...M,[O]:P}))},b=async R=>{if(R.preventDefault(),!!x){c(!0),d(null);try{(await o(n)).data&&h(!0)}catch(O){d(O)}finally{c(!1)}}};return a?e.jsx(ge,{children:e.jsx(oi,{children:e.jsxs(_m,{children:[e.jsx(km,{children:e.jsx(et,{size:32})}),e.jsx(Cm,{children:"You're on the waitlist!"}),e.jsxs(Sm,{children:["Thanks for your interest! We'll notify you at ",n.email," ","when we're ready for you to join."]})]})})}):e.jsx(ge,{children:e.jsxs(oi,{children:[e.jsx(Me,{}),e.jsxs(xm,{children:[e.jsx(vm,{children:"Join the waitlist"}),e.jsx(bm,{children:"Be the first to know when we launch!"})]}),e.jsxs(ym,{onSubmit:b,noValidate:!0,children:[(((C=x==null?void 0:x.first_name)==null?void 0:C.enabled)||((z=x==null?void 0:x.last_name)==null?void 0:z.enabled))&&e.jsxs(wm,{$isBothEnabled:m,children:[((E=x==null?void 0:x.first_name)==null?void 0:E.enabled)&&e.jsxs(Wn,{children:[e.jsxs(Vn,{htmlFor:"first_name",children:["First name",((w=x==null?void 0:x.first_name)==null?void 0:w.required)&&e.jsx(Gn,{children:"*"})]}),e.jsx(ce,{type:"text",id:"first_name",name:"first_name",required:(y=x==null?void 0:x.first_name)==null?void 0:y.required,minLength:2,maxLength:50,value:n.first_name,onChange:v,placeholder:"First name","aria-invalid":!!p()}),p()&&e.jsx(mo,{children:p()})]}),((f=x==null?void 0:x.last_name)==null?void 0:f.enabled)&&e.jsxs(Wn,{children:[e.jsxs(Vn,{htmlFor:"last_name",children:["Last name",(($=x==null?void 0:x.last_name)==null?void 0:$.required)&&e.jsx(Gn,{children:"*"})]}),e.jsx(ce,{type:"text",id:"last_name",name:"last_name",required:(S=x==null?void 0:x.last_name)==null?void 0:S.required,minLength:2,maxLength:50,value:n.last_name,onChange:v,placeholder:"Last name","aria-invalid":!!p()}),p()&&e.jsx(mo,{children:p()})]})]}),e.jsxs(Wn,{children:[e.jsxs(Vn,{htmlFor:"email",children:["Email address",((j=x==null?void 0:x.email_address)==null?void 0:j.required)&&e.jsx(Gn,{children:"*"})]}),e.jsx(ce,{type:"email",id:"email",name:"email",required:(T=x==null?void 0:x.email_address)==null?void 0:T.required,value:n.email,onChange:v,placeholder:"Enter your email address","aria-invalid":!!p()}),p()&&e.jsx(mo,{children:p()})]}),p()&&e.jsx(mo,{children:p()}),e.jsx(jm,{type:"submit",$primary:!0,disabled:g||r,children:g||r?"Joining waitlist...":"Join waitlist"})]}),e.jsx(zm,{children:e.jsxs($m,{children:["Need assistance? ",e.jsx(Em,{href:"/contact",children:"Get help"})]})})]})})}const Ur=l.div`
|
|
1914
1914
|
max-width: 380px;
|
|
1915
1915
|
width: 380px;
|
|
1916
1916
|
padding: var(--space-3xl);
|
|
@@ -2400,7 +2400,7 @@ cursor: pointer;
|
|
|
2400
2400
|
color: var(--color-foreground);
|
|
2401
2401
|
background: var(--color-input-background);
|
|
2402
2402
|
}
|
|
2403
|
-
`,fi=({onClose:t,domain:r,triggerRef:o})=>{const n=i.useRef(null),[s,a]=i.useState(),[h,g]=i.useState(""),[c,u]=i.useState(!1),[d,p]=i.useState(!1),[x,m]=i.useState({top:0,left:0}),{addDomain:v,verifyDomain:b}=nt(),{toast:_}=Je(),k=w=>/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(w),C=w=>w.trim().toLowerCase().replace(/^https?:\/\//,""),z=async()=>{const w=C(h);if(!w){_("Please enter a domain name","error");return}if(!k(w)){_("Please enter a valid domain name (e.g., example.com)","error");return}if(w.length>253){_("Domain name is too long","error");return}try{const y=await v({fqdn:w});_("Domain added successfully","info"),a(y.data)}catch(y){const f=y.message||"Failed to add domain. Please try again.";_(f,"error")}},E=async()=>{if(!(!s||c)){u(!0);try{await b(s),t==null||t(),_("Domain verified successfully","info")}catch(w){const y=w.message||"Failed to verify domain. Please check DNS records and try again.";_(y,"error")}finally{u(!1)}}};return i.useEffect(()=>{p(!0);const w=setTimeout(()=>{if(!n.current)return;const $=o==null?void 0:o.current,S=360,j=250,T=8;let R=0,O=0;if(!$){const D=n.current.getBoundingClientRect(),L=D.width||S,I=D.height||j;R=Math.max(T,(window.innerHeight-I)/2),O=Math.max(T,(window.innerWidth-L)/2),m({top:R,left:O});return}const P=$.getBoundingClientRect(),M=window.innerHeight-P.bottom,N=P.top;M>=j+T?(R=P.bottom+T,O=P.right-S,O<T&&(O=P.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):N>=j+T?(R=P.top-j-T,O=P.right-S,O<T&&(O=P.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):(R=P.bottom+T,O=P.right-S,O<T&&(O=P.left)),m({top:R,left:O})},10),y=$=>{n.current&&!n.current.contains($.target)&&(t==null||t())},f=$=>{$.key==="Escape"&&(t==null||t())};return document.addEventListener("mousedown",y),document.addEventListener("keydown",f),()=>{clearTimeout(w),document.removeEventListener("mousedown",y),document.removeEventListener("keydown",f)}},[t,o]),i.useEffect(()=>{r&&a(r)},[r]),d?e.jsx(vx,{ref:n,style:{top:`${x.top}px`,left:`${x.left}px`,visibility:x.top>0?"visible":"hidden"},onClick:w=>w.stopPropagation(),role:"dialog","aria-labelledby":"add-domain-title","aria-modal":"true",children:s?e.jsxs(e.Fragment,{children:[e.jsxs(li,{children:[e.jsx(di,{id:"verify-domain-title",children:"Verify Domain"}),e.jsx(hi,{onClick:t,"aria-label":"Close domain verification dialog",children:e.jsx(ct,{size:16})})]}),e.jsxs(ui,{children:[e.jsx("div",{style:{marginBottom:"var(--space-md)"},children:e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-muted)",margin:0,textAlign:"left"},children:"Add the following DNS record to your domain"})}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(
|
|
2403
|
+
`,fi=({onClose:t,domain:r,triggerRef:o})=>{const n=i.useRef(null),[s,a]=i.useState(),[h,g]=i.useState(""),[c,u]=i.useState(!1),[d,p]=i.useState(!1),[x,m]=i.useState({top:0,left:0}),{addDomain:v,verifyDomain:b}=nt(),{toast:_}=Je(),k=w=>/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(w),C=w=>w.trim().toLowerCase().replace(/^https?:\/\//,""),z=async()=>{const w=C(h);if(!w){_("Please enter a domain name","error");return}if(!k(w)){_("Please enter a valid domain name (e.g., example.com)","error");return}if(w.length>253){_("Domain name is too long","error");return}try{const y=await v({fqdn:w});_("Domain added successfully","info"),a(y.data)}catch(y){const f=y.message||"Failed to add domain. Please try again.";_(f,"error")}},E=async()=>{if(!(!s||c)){u(!0);try{await b(s),t==null||t(),_("Domain verified successfully","info")}catch(w){const y=w.message||"Failed to verify domain. Please check DNS records and try again.";_(y,"error")}finally{u(!1)}}};return i.useEffect(()=>{p(!0);const w=setTimeout(()=>{if(!n.current)return;const $=o==null?void 0:o.current,S=360,j=250,T=8;let R=0,O=0;if(!$){const D=n.current.getBoundingClientRect(),L=D.width||S,I=D.height||j;R=Math.max(T,(window.innerHeight-I)/2),O=Math.max(T,(window.innerWidth-L)/2),m({top:R,left:O});return}const P=$.getBoundingClientRect(),M=window.innerHeight-P.bottom,N=P.top;M>=j+T?(R=P.bottom+T,O=P.right-S,O<T&&(O=P.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):N>=j+T?(R=P.top-j-T,O=P.right-S,O<T&&(O=P.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):(R=P.bottom+T,O=P.right-S,O<T&&(O=P.left)),m({top:R,left:O})},10),y=$=>{n.current&&!n.current.contains($.target)&&(t==null||t())},f=$=>{$.key==="Escape"&&(t==null||t())};return document.addEventListener("mousedown",y),document.addEventListener("keydown",f),()=>{clearTimeout(w),document.removeEventListener("mousedown",y),document.removeEventListener("keydown",f)}},[t,o]),i.useEffect(()=>{r&&a(r)},[r]),d?e.jsx(vx,{ref:n,style:{top:`${x.top}px`,left:`${x.left}px`,visibility:x.top>0?"visible":"hidden"},onClick:w=>w.stopPropagation(),role:"dialog","aria-labelledby":"add-domain-title","aria-modal":"true",children:s?e.jsxs(e.Fragment,{children:[e.jsxs(li,{children:[e.jsx(di,{id:"verify-domain-title",children:"Verify Domain"}),e.jsx(hi,{onClick:t,"aria-label":"Close domain verification dialog",children:e.jsx(ct,{size:16})})]}),e.jsxs(ui,{children:[e.jsx("div",{style:{marginBottom:"var(--space-md)"},children:e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-muted)",margin:0,textAlign:"left"},children:"Add the following DNS record to your domain"})}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(ie,{children:"Record Type"}),e.jsx(ce,{value:s==null?void 0:s.verification_dns_record_type,disabled:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Record Name"}),e.jsx(ce,{value:s==null?void 0:s.verification_dns_record_name,disabled:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Record Data"}),e.jsx(ce,{type:"text",value:s==null?void 0:s.verification_dns_record_data,disabled:!0})]})]})]}),e.jsxs(pi,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto"},children:"Cancel"}),e.jsx(K,{onClick:E,disabled:c,style:{width:"auto"},children:c?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:14})," Verifying..."]}):"Verify Domain"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(li,{children:[e.jsx(di,{id:"add-domain-title",children:"Add Domain"}),e.jsx(hi,{onClick:t,"aria-label":"Close add domain dialog",children:e.jsx(ct,{size:16})})]}),e.jsx(ui,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:e.jsxs(he,{children:[e.jsx(ie,{children:"Enter FQDN"}),e.jsx(ce,{type:"text",placeholder:"Enter your domain",value:h,onChange:w=>g(w.target.value),autoFocus:!0,"aria-label":"Domain name (FQDN)","aria-describedby":"domain-help"})]})})}),e.jsxs(pi,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto"},children:"Cancel"}),e.jsx(K,{onClick:z,disabled:!h||c,style:{width:"auto"},children:c?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:14})," Adding..."]}):"Continue"})]})]})}):null},bx=l.div`
|
|
2404
2404
|
position: fixed;
|
|
2405
2405
|
width: 360px;
|
|
2406
2406
|
max-width: calc(100vw - 48px);
|
|
@@ -2449,7 +2449,7 @@ cursor: pointer;
|
|
|
2449
2449
|
color: var(--color-foreground);
|
|
2450
2450
|
background: var(--color-input-background);
|
|
2451
2451
|
}
|
|
2452
|
-
`,Zl=({onClose:t,onSuccess:r,roles:o,triggerRef:n})=>{const s=i.useRef(null),[a,h]=i.useState(""),[g,c]=i.useState(null),[u,d]=i.useState(!1),[p,x]=i.useState(!1),[m,v]=i.useState({top:0,left:0}),{inviteMember:b}=nt(),{toast:_}=Je(),k=o.map(E=>({value:E.id,label:E.name})),C=E=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E),z=async()=>{const E=a.trim().toLowerCase();if(!(!E||!g)){if(!C(E)){_("Please enter a valid email address","error");return}if(E.length>320){_("Email address is too long","error");return}d(!0);try{await b({email:E,organizationRole:g}),r==null||r()}catch(w){const y=w.message||"Failed to send invitation. Please try again.";_(y,"error")}finally{d(!1)}}};return i.useEffect(()=>{x(!0);const E=setTimeout(()=>{if(!s.current||!(n!=null&&n.current))return;const f=n.current;if(f){const $=f.getBoundingClientRect(),S=360,j=250,T=8;let R=0,O=0;const P=window.innerHeight-$.bottom,M=$.top;P>=j+T?(R=$.bottom+T,O=$.right-S,O<T&&(O=$.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):M>=j+T?(R=$.top-j-T,O=$.right-S,O<T&&(O=$.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):(R=$.bottom+T,O=$.right-S,O<T&&(O=$.left)),v({top:R,left:O})}},10),w=f=>{s.current&&!s.current.contains(f.target)&&(t==null||t())},y=f=>{f.key==="Escape"&&(t==null||t())};return document.addEventListener("mousedown",w),document.addEventListener("keydown",y),()=>{clearTimeout(E),document.removeEventListener("mousedown",w),document.removeEventListener("keydown",y)}},[t,n]),p?e.jsxs(bx,{ref:s,style:{top:`${m.top}px`,left:`${m.left}px`,visibility:m.top>0?"visible":"hidden"},onClick:E=>E.stopPropagation(),role:"dialog","aria-labelledby":"invite-member-title","aria-modal":"true",children:[e.jsxs(yx,{children:[e.jsx(wx,{id:"invite-member-title",children:"Invite Member"}),e.jsx(kx,{onClick:t,"aria-label":"Close invite member dialog",children:e.jsx(ct,{size:16})})]}),e.jsx(jx,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(
|
|
2452
|
+
`,Zl=({onClose:t,onSuccess:r,roles:o,triggerRef:n})=>{const s=i.useRef(null),[a,h]=i.useState(""),[g,c]=i.useState(null),[u,d]=i.useState(!1),[p,x]=i.useState(!1),[m,v]=i.useState({top:0,left:0}),{inviteMember:b}=nt(),{toast:_}=Je(),k=o.map(E=>({value:E.id,label:E.name})),C=E=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E),z=async()=>{const E=a.trim().toLowerCase();if(!(!E||!g)){if(!C(E)){_("Please enter a valid email address","error");return}if(E.length>320){_("Email address is too long","error");return}d(!0);try{await b({email:E,organizationRole:g}),r==null||r()}catch(w){const y=w.message||"Failed to send invitation. Please try again.";_(y,"error")}finally{d(!1)}}};return i.useEffect(()=>{x(!0);const E=setTimeout(()=>{if(!s.current||!(n!=null&&n.current))return;const f=n.current;if(f){const $=f.getBoundingClientRect(),S=360,j=250,T=8;let R=0,O=0;const P=window.innerHeight-$.bottom,M=$.top;P>=j+T?(R=$.bottom+T,O=$.right-S,O<T&&(O=$.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):M>=j+T?(R=$.top-j-T,O=$.right-S,O<T&&(O=$.left,O+S>window.innerWidth-T&&(O=(window.innerWidth-S)/2))):(R=$.bottom+T,O=$.right-S,O<T&&(O=$.left)),v({top:R,left:O})}},10),w=f=>{s.current&&!s.current.contains(f.target)&&(t==null||t())},y=f=>{f.key==="Escape"&&(t==null||t())};return document.addEventListener("mousedown",w),document.addEventListener("keydown",y),()=>{clearTimeout(E),document.removeEventListener("mousedown",w),document.removeEventListener("keydown",y)}},[t,n]),p?e.jsxs(bx,{ref:s,style:{top:`${m.top}px`,left:`${m.left}px`,visibility:m.top>0?"visible":"hidden"},onClick:E=>E.stopPropagation(),role:"dialog","aria-labelledby":"invite-member-title","aria-modal":"true",children:[e.jsxs(yx,{children:[e.jsx(wx,{id:"invite-member-title",children:"Invite Member"}),e.jsx(kx,{onClick:t,"aria-label":"Close invite member dialog",children:e.jsx(ct,{size:16})})]}),e.jsx(jx,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(ie,{children:"Email Address"}),e.jsx(ce,{type:"email",placeholder:"colleague@company.com",value:a,onChange:E=>h(E.target.value),autoFocus:!0,"aria-label":"Email address for invitation","aria-describedby":"email-help"})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Role"}),e.jsx(Fs,{options:k,value:g==null?void 0:g.id,onChange:E=>c(o.find(w=>w.id===E)),placeholder:"Select a role","aria-label":"Select role for invited member"})]})]})}),e.jsxs(_x,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto"},children:"Cancel"}),e.jsx(K,{onClick:z,disabled:!a||!g||u,style:{width:"auto"},children:u?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:14})," Sending..."]}):"Send Invitation"})]})]}):null},Cx=l.div`
|
|
2453
2453
|
position: fixed;
|
|
2454
2454
|
width: 400px;
|
|
2455
2455
|
max-width: calc(100vw - 48px);
|
|
@@ -2500,7 +2500,7 @@ cursor: pointer;
|
|
|
2500
2500
|
color: var(--color-foreground);
|
|
2501
2501
|
background: var(--color-input-background);
|
|
2502
2502
|
}
|
|
2503
|
-
`,gi=({onClose:t,onSuccess:r,role:o,triggerRef:n})=>{var y;const s=i.useRef(null),[a,h]=i.useState((o==null?void 0:o.name)||""),[g,c]=i.useState((o==null?void 0:o.permissions)||[]);nt();const[u,d]=i.useState(!1),[p,x]=i.useState(!1),[m,v]=i.useState({top:0,left:0}),{deployment:b}=ye(),{toast:_}=Je(),k=!!o,C=Array.isArray((y=b==null?void 0:b.b2b_settings)==null?void 0:y.organization_permissions)?b.b2b_settings.organization_permissions.map(f=>({value:f,label:f})):[];i.useEffect(()=>{x(!0);const f=setTimeout(()=>{if(!s.current)return;let T=null;if(n!=null&&n.current)T=n.current;else if(k){const R=document.querySelectorAll("[data-role-dropdown-trigger]");for(let O=0;O<R.length;O++){const P=R[O];if(P.offsetParent!==null){T=P;break}}}else{const R=document.querySelectorAll("button");for(let O=0;O<R.length;O++){const P=R[O];if(P.textContent==="Add role"&&P.offsetParent!==null){T=P;break}}}if(T){const R=T.getBoundingClientRect(),O=400;let P=R.bottom+8,M=R.right-O;M<10&&(M=R.left),P+300>window.innerHeight&&(P=R.top-300-8),v({top:P,left:M})}},10),$=T=>{s.current&&!s.current.contains(T.target)&&(t==null||t())},S=T=>{T.key==="Escape"&&(t==null||t())},j=setTimeout(()=>{document.addEventListener("mousedown",$),document.addEventListener("keydown",S)},100);return()=>{clearTimeout(f),clearTimeout(j),document.removeEventListener("mousedown",$),document.removeEventListener("keydown",S)}},[t,k,n]);const z=f=>f.trim().replace(/[<>\"'&]/g,""),E=f=>f.length>=2&&f.length<=50&&/^[a-zA-Z0-9\s_-]+$/.test(f),w=async()=>{const f=z(a);if(!f){_("Please enter a role name","error");return}if(!E(f)){_("Role name must be 2-50 characters and contain only letters, numbers, spaces, underscores, and hyphens","error");return}if(g.length===0){_("Please select at least one permission","error");return}d(!0);try{const $={id:o==null?void 0:o.id,name:f,permissions:g||[]};r==null||r($)}catch($){const S=$.message||`Failed to ${k?"update":"create"} role. Please try again.`;_(S,"error")}finally{d(!1)}};return p?e.jsxs(Cx,{ref:s,$isInTable:k,style:{top:`${m.top}px`,left:`${m.left}px`,visibility:m.top>0?"visible":"hidden"},onClick:f=>f.stopPropagation(),role:"dialog","aria-labelledby":"role-dialog-title","aria-modal":"true",children:[e.jsxs(Sx,{children:[e.jsx(zx,{id:"role-dialog-title",children:k?"Edit Role":"Create New Role"}),e.jsx(Ix,{onClick:t,"aria-label":`Close ${k?"edit":"create"} role dialog`,children:e.jsx(ct,{size:16})})]}),e.jsx($x,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(
|
|
2503
|
+
`,gi=({onClose:t,onSuccess:r,role:o,triggerRef:n})=>{var y;const s=i.useRef(null),[a,h]=i.useState((o==null?void 0:o.name)||""),[g,c]=i.useState((o==null?void 0:o.permissions)||[]);nt();const[u,d]=i.useState(!1),[p,x]=i.useState(!1),[m,v]=i.useState({top:0,left:0}),{deployment:b}=ye(),{toast:_}=Je(),k=!!o,C=Array.isArray((y=b==null?void 0:b.b2b_settings)==null?void 0:y.organization_permissions)?b.b2b_settings.organization_permissions.map(f=>({value:f,label:f})):[];i.useEffect(()=>{x(!0);const f=setTimeout(()=>{if(!s.current)return;let T=null;if(n!=null&&n.current)T=n.current;else if(k){const R=document.querySelectorAll("[data-role-dropdown-trigger]");for(let O=0;O<R.length;O++){const P=R[O];if(P.offsetParent!==null){T=P;break}}}else{const R=document.querySelectorAll("button");for(let O=0;O<R.length;O++){const P=R[O];if(P.textContent==="Add role"&&P.offsetParent!==null){T=P;break}}}if(T){const R=T.getBoundingClientRect(),O=400;let P=R.bottom+8,M=R.right-O;M<10&&(M=R.left),P+300>window.innerHeight&&(P=R.top-300-8),v({top:P,left:M})}},10),$=T=>{s.current&&!s.current.contains(T.target)&&(t==null||t())},S=T=>{T.key==="Escape"&&(t==null||t())},j=setTimeout(()=>{document.addEventListener("mousedown",$),document.addEventListener("keydown",S)},100);return()=>{clearTimeout(f),clearTimeout(j),document.removeEventListener("mousedown",$),document.removeEventListener("keydown",S)}},[t,k,n]);const z=f=>f.trim().replace(/[<>\"'&]/g,""),E=f=>f.length>=2&&f.length<=50&&/^[a-zA-Z0-9\s_-]+$/.test(f),w=async()=>{const f=z(a);if(!f){_("Please enter a role name","error");return}if(!E(f)){_("Role name must be 2-50 characters and contain only letters, numbers, spaces, underscores, and hyphens","error");return}if(g.length===0){_("Please select at least one permission","error");return}d(!0);try{const $={id:o==null?void 0:o.id,name:f,permissions:g||[]};r==null||r($)}catch($){const S=$.message||`Failed to ${k?"update":"create"} role. Please try again.`;_(S,"error")}finally{d(!1)}};return p?e.jsxs(Cx,{ref:s,$isInTable:k,style:{top:`${m.top}px`,left:`${m.left}px`,visibility:m.top>0?"visible":"hidden"},onClick:f=>f.stopPropagation(),role:"dialog","aria-labelledby":"role-dialog-title","aria-modal":"true",children:[e.jsxs(Sx,{children:[e.jsx(zx,{id:"role-dialog-title",children:k?"Edit Role":"Create New Role"}),e.jsx(Ix,{onClick:t,"aria-label":`Close ${k?"edit":"create"} role dialog`,children:e.jsx(ct,{size:16})})]}),e.jsx($x,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(ie,{children:"Role Name"}),e.jsx(ce,{type:"text",placeholder:"e.g. Admin, Editor, Viewer",value:a,onChange:f=>h(f.target.value),autoFocus:!0,"aria-label":"Role name","aria-describedby":"role-name-help"})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Permissions"}),e.jsx(Nl,{options:C,value:g,onChange:c,placeholder:"Select permissions","aria-label":"Select permissions for role"})]})]})}),e.jsxs(Ex,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto"},children:"Cancel"}),e.jsx(K,{onClick:w,disabled:!a||u,style:{width:"auto"},children:u?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:14})," ",k?"Updating...":"Creating..."]}):k?"Update Role":"Create Role"})]})]}):null},_t=l.table`
|
|
2504
2504
|
width: 100%;
|
|
2505
2505
|
border-collapse: separate;
|
|
2506
2506
|
border-spacing: 0;
|
|
@@ -2749,7 +2749,7 @@ cursor: pointer;
|
|
|
2749
2749
|
color: var(--color-foreground);
|
|
2750
2750
|
text-transform: uppercase;
|
|
2751
2751
|
letter-spacing: 0.5px;
|
|
2752
|
-
`,Yx=({onCreate:t})=>{const{getDomains:r,testEnterpriseConnectionConfig:o}=nt(),{deployment:n}=ye(),{toast:s}=Je(),[a,h]=i.useState(!1),[g,c]=i.useState(null),[u,d]=i.useState("saml"),[p,x]=i.useState(null),[m,v]=i.useState(!1),[b,_]=i.useState({domain_id:"",idp_entity_id:"",idp_sso_url:"",idp_certificate:"",oidc_issuer_url:"",oidc_client_id:"",oidc_client_secret:"",oidc_scopes:"openid profile email",jit_enabled:!0,attr_first_name:"",attr_last_name:"",attr_email:""}),[k,C]=i.useState(!1),[z,E]=i.useState(null),{data:w=[],isLoading:y}=Ye("wacht-org-verified-domains-for-sso-screen",async()=>(await(r==null?void 0:r())||[]).filter(M=>M.verified),{revalidateOnFocus:!1}),f=P=>{c(P),d(P.protocol),P.protocol==="saml"?_(M=>{var N,D,L;return{...M,idp_entity_id:P.placeholders.entityId||"",idp_sso_url:P.placeholders.ssoUrl||"",attr_first_name:((N=P.attributeMapping)==null?void 0:N.first_name)||"",attr_last_name:((D=P.attributeMapping)==null?void 0:D.last_name)||"",attr_email:((L=P.attributeMapping)==null?void 0:L.email)||""}}):_(M=>{var N,D,L;return{...M,oidc_issuer_url:P.placeholders.issuerUrl||"",oidc_scopes:P.placeholders.scopes||"openid profile email",attr_first_name:((N=P.attributeMapping)==null?void 0:N.first_name)||"",attr_last_name:((D=P.attributeMapping)==null?void 0:D.last_name)||"",attr_email:((L=P.attributeMapping)==null?void 0:L.email)||""}})},$=n!=null&&n.backend_host?`${n.backend_host.startsWith("https://")?"":"https://"}${n.backend_host}/auth/sso/oidc/callback`:"",S=n!=null&&n.backend_host?`https://${n.backend_host}/auth/sso/metadata`:"",j=n!=null&&n.backend_host?`https://${n.backend_host}/auth/sso/callback`:"",T=(P,M)=>{navigator.clipboard.writeText(P),x(M),setTimeout(()=>x(null),2e3)},R=async P=>{P.preventDefault();const M=N=>N.includes("{")||N.includes("}");if(u==="saml"){if(!b.idp_entity_id||M(b.idp_entity_id)){s("Please enter a valid IdP Entity ID (no placeholders)","error");return}if(!b.idp_sso_url||M(b.idp_sso_url)){s("Please enter a valid IdP SSO URL (no placeholders)","error");return}if(!b.idp_certificate){s("Please provide the X.509 Certificate","error");return}}else{if(!b.oidc_issuer_url||M(b.oidc_issuer_url)){s("Please enter a valid Issuer URL (no placeholders)","error");return}if(!b.oidc_client_id||M(b.oidc_client_id)){s("Please enter a valid Client ID (no placeholders)","error");return}if(!b.oidc_client_secret){s("Please enter the Client Secret","error");return}}h(!0);try{const N={};b.attr_first_name&&(N.first_name=b.attr_first_name),b.attr_last_name&&(N.last_name=b.attr_last_name),b.attr_email&&(N.email=b.attr_email);const D=Object.keys(N).length>0;u==="saml"?await t({protocol:"saml",domain_id:b.domain_id||void 0,idp_entity_id:b.idp_entity_id,idp_sso_url:b.idp_sso_url,idp_certificate:b.idp_certificate,jit_enabled:b.jit_enabled,...D&&{attribute_mapping:N}}):await t({protocol:"oidc",domain_id:b.domain_id||void 0,oidc_issuer_url:b.oidc_issuer_url,oidc_client_id:b.oidc_client_id,oidc_client_secret:b.oidc_client_secret,oidc_scopes:b.oidc_scopes,jit_enabled:b.jit_enabled,...D&&{attribute_mapping:N}})}finally{h(!1)}},O=async()=>{C(!0),E(null);const P=D=>D.includes("{")||D.includes("}"),M={},N={};if(u==="saml"?(b.idp_entity_id?P(b.idp_entity_id)?(N.entity_id_valid=!1,M.entity_id_valid="IdP Entity ID contains placeholder values - please replace with actual values"):N.entity_id_valid=!0:(N.entity_id_valid=!1,M.entity_id_valid="IdP Entity ID is required"),b.idp_sso_url?P(b.idp_sso_url)?(N.sso_url_valid=!1,M.sso_url_valid="IdP SSO URL contains placeholder values - please replace with actual values"):N.sso_url_valid=!0:(N.sso_url_valid=!1,M.sso_url_valid="IdP SSO URL is required"),b.idp_certificate?N.certificate_provided=!0:(N.certificate_provided=!1,M.certificate_provided="X.509 Certificate is required")):(b.oidc_issuer_url?P(b.oidc_issuer_url)?(N.issuer_url_valid=!1,M.issuer_url_valid="Issuer URL contains placeholder values - please replace with actual values"):N.issuer_url_valid=!0:(N.issuer_url_valid=!1,M.issuer_url_valid="Issuer URL is required"),b.oidc_client_id?P(b.oidc_client_id)?(N.client_id_valid=!1,M.client_id_valid="Client ID contains placeholder values - please replace with actual values"):N.client_id_valid=!0:(N.client_id_valid=!1,M.client_id_valid="Client ID is required")),Object.keys(M).length>0){E({success:!1,checks:N,errors:M}),C(!1);return}try{const D=u==="saml"?{protocol:"saml",idp_entity_id:b.idp_entity_id,idp_sso_url:b.idp_sso_url,idp_certificate:b.idp_certificate}:{protocol:"oidc",oidc_issuer_url:b.oidc_issuer_url,oidc_client_id:b.oidc_client_id,oidc_client_secret:b.oidc_client_secret},L=await(o==null?void 0:o(D));L&&E(L)}catch(D){E({success:!1,checks:{},errors:{general:"Test failed: "+D.message}})}finally{C(!1)}};return e.jsxs("form",{onSubmit:R,autoComplete:"off",children:[g?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px",background:"var(--color-primary-background)",borderRadius:"8px",border:"1px solid var(--color-primary)",marginBottom:"16px"},children:[g.logo?e.jsx(Yn,{src:g.logo,alt:g.name}):e.jsx("div",{style:{height:"24px",width:"24px",display:"flex",alignItems:"center",justifyContent:"center",background:"white",borderRadius:"4px",padding:"3px"},children:e.jsx(ut,{size:18,color:"#666"})}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,fontSize:"14px",color:"var(--color-foreground)"},children:g.name}),e.jsx("div",{style:{fontSize:"11px",color:"var(--color-muted)",textTransform:"uppercase"},children:g.protocol})]}),e.jsx("button",{type:"button",onClick:()=>c(null),style:{background:"none",border:"none",color:"var(--color-primary)",cursor:"pointer",fontSize:"12px",padding:"4px 8px"},children:"Change"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Zn,{children:"SAML Providers"}),e.jsx(vi,{children:xi.filter(P=>P.protocol==="saml").map(P=>e.jsxs(bi,{type:"button",$selected:!1,onClick:()=>f(P),children:[P.logo?e.jsx(Yn,{src:P.logo,alt:P.name}):e.jsx("div",{style:{height:"24px",width:"24px",display:"flex",alignItems:"center",justifyContent:"center",background:"white",borderRadius:"4px",padding:"3px"},children:e.jsx(ut,{size:18,color:"#666"})}),e.jsx(yi,{children:P.name})]},P.id))}),e.jsx(Zn,{style:{marginTop:"20px"},children:"OIDC Providers"}),e.jsx(vi,{children:xi.filter(P=>P.protocol==="oidc").map(P=>e.jsxs(bi,{type:"button",$selected:!1,onClick:()=>f(P),children:[P.logo?e.jsx(Yn,{src:P.logo,alt:P.name}):e.jsx("div",{style:{height:"24px",width:"24px",display:"flex",alignItems:"center",justifyContent:"center",background:"white",borderRadius:"4px",padding:"3px"},children:e.jsx(ut,{size:18,color:"#666"})}),e.jsx(yi,{children:P.name})]},P.id))})]}),g&&e.jsxs(e.Fragment,{children:[e.jsxs(mi,{style:{marginTop:"16px"},children:[e.jsx("div",{style:{marginBottom:"12px",fontWeight:500},children:"Service Provider Details"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:u==="saml"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{minWidth:"80px",fontSize:"12px"},children:"ACS URL:"}),e.jsx("code",{style:{flex:1,fontSize:"11px"},children:j}),e.jsx(Yr,{onClick:()=>T(j,"acs"),children:p==="acs"?e.jsx(et,{size:12}):e.jsx(dr,{size:12})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{minWidth:"80px",fontSize:"12px"},children:"Metadata:"}),e.jsx("code",{style:{flex:1,fontSize:"11px"},children:S}),e.jsx(Yr,{onClick:()=>T(S,"metadata"),children:p==="metadata"?e.jsx(et,{size:12}):e.jsx(dr,{size:12})})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{minWidth:"80px",fontSize:"12px"},children:"Callback:"}),e.jsx("code",{style:{flex:1,fontSize:"11px"},children:$}),e.jsx(Yr,{onClick:()=>T($,"callback"),children:p==="callback"?e.jsx(et,{size:12}):e.jsx(dr,{size:12})})]})})]}),e.jsxs("div",{style:{marginTop:"24px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[e.jsx(Zn,{style:{margin:0},children:g?`${g.name} Configuration`:"Configuration"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[g&&g.docUrl&&e.jsxs("a",{href:g.docUrl,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--color-primary)",textDecoration:"none",display:"flex",gap:"2px",alignItems:"center"},children:[e.jsx(Ls,{size:12})," Docs"]}),e.jsx(K,{type:"button",onClick:O,disabled:k||!g,style:{width:"auto",padding:"8px 16px",background:"transparent",border:"1px solid var(--color-border)"},children:k?e.jsx(Ie,{size:16}):"Test Connection"}),e.jsx(K,{type:"submit",disabled:a||w.length===0||!g,style:{width:"auto",padding:"8px 16px"},children:a?e.jsx(Ie,{size:16}):"Create Connection"})]})]}),z&&(()=>{const P={entity_id_valid:"IdP Entity ID",sso_url_valid:"IdP SSO URL",certificate_provided:"X.509 Certificate",issuer_url_valid:"Issuer URL",client_id_valid:"Client ID",certificate_valid:"Certificate Valid",sso_url_reachable:"SSO URL Reachable",discovery_reachable:"Discovery Endpoint",discovery_valid:"Discovery Valid",authorization_endpoint:"Authorization Endpoint",token_endpoint:"Token Endpoint",issuer_valid:"Issuer URL Valid"};return e.jsxs("div",{style:{padding:"16px",marginBottom:"16px",borderRadius:"8px",background:z.success?"rgba(16, 185, 129, 0.1)":"rgba(239, 68, 68, 0.1)",border:`1px solid ${z.success?"#10b981":"#ef4444"}`},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:"12px",fontSize:"14px",color:z.success?"#10b981":"#ef4444"},children:z.success?"✓ All checks passed":"✗ Some checks failed"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:Object.entries(z.checks).map(([M,N])=>{var D;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px",padding:"8px 12px",background:"var(--color-background)",borderRadius:"6px",border:"1px solid var(--color-border)"},children:[e.jsx("span",{style:{color:N?"#10b981":"#ef4444",fontWeight:600,fontSize:"14px",minWidth:"16px"},children:N?"✓":"✗"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,color:"var(--color-foreground)",fontSize:"13px"},children:P[M]||M.replace(/_/g," ").replace(/\b\w/g,L=>L.toUpperCase())}),((D=z.errors)==null?void 0:D[M])&&e.jsx("div",{style:{color:"#ef4444",fontSize:"12px",marginTop:"4px"},children:z.errors[M]})]})]},M)})})]})})(),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"16px"},children:[!g&&e.jsxs(he,{children:[e.jsx(ae,{children:"Protocol *"}),e.jsxs(wi,{value:u,onChange:P=>d(P.target.value),children:[e.jsx("option",{value:"saml",children:"SAML"}),e.jsx("option",{value:"oidc",children:"OpenID Connect (OIDC)"})]})]}),e.jsxs(he,{style:{gridColumn:"1 / -1"},children:[e.jsx(ae,{children:"Domain *"}),y?e.jsx("div",{style:{padding:"10px",color:"var(--color-muted)"},children:"Loading domains..."}):w.length===0?e.jsx(mi,{style:{marginBottom:0},children:"No verified domains found. Please add and verify a domain first."}):e.jsxs(wi,{value:b.domain_id,onChange:P=>_({...b,domain_id:P.target.value}),required:!0,children:[e.jsx("option",{value:"",children:"Select a verified domain"}),w.map(P=>e.jsx("option",{value:P.id,children:P.fqdn},P.id))]})]}),u==="saml"?e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(ae,{children:"IdP Entity ID *"}),e.jsx(ie,{type:"text",value:b.idp_entity_id,onChange:P=>_({...b,idp_entity_id:P.target.value}),placeholder:"https://idp.example.com/entity",required:!0})]}),e.jsxs(he,{children:[e.jsx(ae,{children:"IdP SSO URL *"}),e.jsx(ie,{type:"url",value:b.idp_sso_url,onChange:P=>_({...b,idp_sso_url:P.target.value}),placeholder:"https://idp.example.com/sso",required:!0})]}),e.jsxs(he,{style:{gridColumn:"1 / -1"},children:[e.jsx(ae,{children:"X.509 Certificate *"}),e.jsx(Ux,{value:b.idp_certificate,onChange:P=>_({...b,idp_certificate:P.target.value}),placeholder:"-----BEGIN CERTIFICATE-----...",required:!0})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(ae,{children:"Issuer URL *"}),e.jsx(ie,{type:"url",value:b.oidc_issuer_url,onChange:P=>_({...b,oidc_issuer_url:P.target.value}),placeholder:"https://login.example.com",required:!0})]}),e.jsxs(he,{children:[e.jsx(ae,{children:"Client ID *"}),e.jsx(ie,{type:"text",value:b.oidc_client_id,onChange:P=>_({...b,oidc_client_id:P.target.value}),placeholder:"your-client-id",required:!0,autoComplete:"off","data-lpignore":"true","data-form-type":"other"})]}),e.jsxs(he,{children:[e.jsx(ae,{children:"Client Secret *"}),e.jsx(ie,{type:"password",value:b.oidc_client_secret,onChange:P=>_({...b,oidc_client_secret:P.target.value}),placeholder:"your-client-secret",required:!0,autoComplete:"new-password","data-lpignore":"true","data-form-type":"other"})]}),e.jsxs(he,{children:[e.jsx(ae,{children:"Scopes"}),e.jsx(ie,{type:"text",value:b.oidc_scopes,onChange:P=>_({...b,oidc_scopes:P.target.value}),placeholder:"openid profile email"})]})]}),e.jsx(he,{style:{gridColumn:"1 / -1"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:400,color:"var(--color-foreground)",display:"block"},children:"Enable JIT Provisioning"}),e.jsx("div",{style:{fontSize:"12px",color:"var(--color-muted)",marginTop:"4px"},children:"When enabled, new users are automatically created on their first SSO login. When disabled, only pre-existing users can sign in via SSO."})]}),e.jsx(fr,{checked:b.jit_enabled,onChange:()=>_({...b,jit_enabled:!b.jit_enabled})})]})}),e.jsxs("div",{style:{gridColumn:"1 / -1",marginTop:"8px",marginBottom:"24px"},children:[e.jsxs("div",{onClick:()=>v(!m),style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",color:"var(--color-primary)",fontSize:"13px",fontWeight:500,marginBottom:m?"16px":"0"},children:[e.jsx("span",{style:{fontSize:"10px"},children:m?"▼":"▶"}),"Advanced Options (Attribute Mapping)"]}),m&&e.jsxs("div",{style:{padding:"16px",background:"var(--color-background-alt)",borderRadius:"8px",border:"1px solid var(--color-border)"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--color-muted)",marginBottom:"12px"},children:"Map IdP attribute names to Wacht user fields. Leave empty to use default attribute names."}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"12px"},children:[e.jsxs(he,{children:[e.jsx(ae,{children:"First Name Attribute"}),e.jsx(ie,{type:"text",value:b.attr_first_name,onChange:P=>_({...b,attr_first_name:P.target.value}),placeholder:u==="saml"?"givenName":"given_name"})]}),e.jsxs(he,{children:[e.jsx(ae,{children:"Last Name Attribute"}),e.jsx(ie,{type:"text",value:b.attr_last_name,onChange:P=>_({...b,attr_last_name:P.target.value}),placeholder:u==="saml"?"surname":"family_name"})]}),e.jsxs(he,{children:[e.jsx(ae,{children:"Email Attribute"}),e.jsx(ie,{type:"text",value:b.attr_email,onChange:P=>_({...b,attr_email:P.target.value}),placeholder:"email"})]})]})]})]})]})]})]})]})},ji=l.div`
|
|
2752
|
+
`,Yx=({onCreate:t})=>{const{getDomains:r,testEnterpriseConnectionConfig:o}=nt(),{deployment:n}=ye(),{toast:s}=Je(),[a,h]=i.useState(!1),[g,c]=i.useState(null),[u,d]=i.useState("saml"),[p,x]=i.useState(null),[m,v]=i.useState(!1),[b,_]=i.useState({domain_id:"",idp_entity_id:"",idp_sso_url:"",idp_certificate:"",oidc_issuer_url:"",oidc_client_id:"",oidc_client_secret:"",oidc_scopes:"openid profile email",jit_enabled:!0,attr_first_name:"",attr_last_name:"",attr_email:""}),[k,C]=i.useState(!1),[z,E]=i.useState(null),{data:w=[],isLoading:y}=Ye("wacht-org-verified-domains-for-sso-screen",async()=>(await(r==null?void 0:r())||[]).filter(M=>M.verified),{revalidateOnFocus:!1}),f=P=>{c(P),d(P.protocol),P.protocol==="saml"?_(M=>{var N,D,L;return{...M,idp_entity_id:P.placeholders.entityId||"",idp_sso_url:P.placeholders.ssoUrl||"",attr_first_name:((N=P.attributeMapping)==null?void 0:N.first_name)||"",attr_last_name:((D=P.attributeMapping)==null?void 0:D.last_name)||"",attr_email:((L=P.attributeMapping)==null?void 0:L.email)||""}}):_(M=>{var N,D,L;return{...M,oidc_issuer_url:P.placeholders.issuerUrl||"",oidc_scopes:P.placeholders.scopes||"openid profile email",attr_first_name:((N=P.attributeMapping)==null?void 0:N.first_name)||"",attr_last_name:((D=P.attributeMapping)==null?void 0:D.last_name)||"",attr_email:((L=P.attributeMapping)==null?void 0:L.email)||""}})},$=n!=null&&n.backend_host?`${n.backend_host.startsWith("https://")?"":"https://"}${n.backend_host}/auth/sso/oidc/callback`:"",S=n!=null&&n.backend_host?`https://${n.backend_host}/auth/sso/metadata`:"",j=n!=null&&n.backend_host?`https://${n.backend_host}/auth/sso/callback`:"",T=(P,M)=>{navigator.clipboard.writeText(P),x(M),setTimeout(()=>x(null),2e3)},R=async P=>{P.preventDefault();const M=N=>N.includes("{")||N.includes("}");if(u==="saml"){if(!b.idp_entity_id||M(b.idp_entity_id)){s("Please enter a valid IdP Entity ID (no placeholders)","error");return}if(!b.idp_sso_url||M(b.idp_sso_url)){s("Please enter a valid IdP SSO URL (no placeholders)","error");return}if(!b.idp_certificate){s("Please provide the X.509 Certificate","error");return}}else{if(!b.oidc_issuer_url||M(b.oidc_issuer_url)){s("Please enter a valid Issuer URL (no placeholders)","error");return}if(!b.oidc_client_id||M(b.oidc_client_id)){s("Please enter a valid Client ID (no placeholders)","error");return}if(!b.oidc_client_secret){s("Please enter the Client Secret","error");return}}h(!0);try{const N={};b.attr_first_name&&(N.first_name=b.attr_first_name),b.attr_last_name&&(N.last_name=b.attr_last_name),b.attr_email&&(N.email=b.attr_email);const D=Object.keys(N).length>0;u==="saml"?await t({protocol:"saml",domain_id:b.domain_id||void 0,idp_entity_id:b.idp_entity_id,idp_sso_url:b.idp_sso_url,idp_certificate:b.idp_certificate,jit_enabled:b.jit_enabled,...D&&{attribute_mapping:N}}):await t({protocol:"oidc",domain_id:b.domain_id||void 0,oidc_issuer_url:b.oidc_issuer_url,oidc_client_id:b.oidc_client_id,oidc_client_secret:b.oidc_client_secret,oidc_scopes:b.oidc_scopes,jit_enabled:b.jit_enabled,...D&&{attribute_mapping:N}})}finally{h(!1)}},O=async()=>{C(!0),E(null);const P=D=>D.includes("{")||D.includes("}"),M={},N={};if(u==="saml"?(b.idp_entity_id?P(b.idp_entity_id)?(N.entity_id_valid=!1,M.entity_id_valid="IdP Entity ID contains placeholder values - please replace with actual values"):N.entity_id_valid=!0:(N.entity_id_valid=!1,M.entity_id_valid="IdP Entity ID is required"),b.idp_sso_url?P(b.idp_sso_url)?(N.sso_url_valid=!1,M.sso_url_valid="IdP SSO URL contains placeholder values - please replace with actual values"):N.sso_url_valid=!0:(N.sso_url_valid=!1,M.sso_url_valid="IdP SSO URL is required"),b.idp_certificate?N.certificate_provided=!0:(N.certificate_provided=!1,M.certificate_provided="X.509 Certificate is required")):(b.oidc_issuer_url?P(b.oidc_issuer_url)?(N.issuer_url_valid=!1,M.issuer_url_valid="Issuer URL contains placeholder values - please replace with actual values"):N.issuer_url_valid=!0:(N.issuer_url_valid=!1,M.issuer_url_valid="Issuer URL is required"),b.oidc_client_id?P(b.oidc_client_id)?(N.client_id_valid=!1,M.client_id_valid="Client ID contains placeholder values - please replace with actual values"):N.client_id_valid=!0:(N.client_id_valid=!1,M.client_id_valid="Client ID is required")),Object.keys(M).length>0){E({success:!1,checks:N,errors:M}),C(!1);return}try{const D=u==="saml"?{protocol:"saml",idp_entity_id:b.idp_entity_id,idp_sso_url:b.idp_sso_url,idp_certificate:b.idp_certificate}:{protocol:"oidc",oidc_issuer_url:b.oidc_issuer_url,oidc_client_id:b.oidc_client_id,oidc_client_secret:b.oidc_client_secret},L=await(o==null?void 0:o(D));L&&E(L)}catch(D){E({success:!1,checks:{},errors:{general:"Test failed: "+D.message}})}finally{C(!1)}};return e.jsxs("form",{onSubmit:R,autoComplete:"off",children:[g?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px",background:"var(--color-primary-background)",borderRadius:"8px",border:"1px solid var(--color-primary)",marginBottom:"16px"},children:[g.logo?e.jsx(Yn,{src:g.logo,alt:g.name}):e.jsx("div",{style:{height:"24px",width:"24px",display:"flex",alignItems:"center",justifyContent:"center",background:"white",borderRadius:"4px",padding:"3px"},children:e.jsx(ut,{size:18,color:"#666"})}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,fontSize:"14px",color:"var(--color-foreground)"},children:g.name}),e.jsx("div",{style:{fontSize:"11px",color:"var(--color-muted)",textTransform:"uppercase"},children:g.protocol})]}),e.jsx("button",{type:"button",onClick:()=>c(null),style:{background:"none",border:"none",color:"var(--color-primary)",cursor:"pointer",fontSize:"12px",padding:"4px 8px"},children:"Change"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Zn,{children:"SAML Providers"}),e.jsx(vi,{children:xi.filter(P=>P.protocol==="saml").map(P=>e.jsxs(bi,{type:"button",$selected:!1,onClick:()=>f(P),children:[P.logo?e.jsx(Yn,{src:P.logo,alt:P.name}):e.jsx("div",{style:{height:"24px",width:"24px",display:"flex",alignItems:"center",justifyContent:"center",background:"white",borderRadius:"4px",padding:"3px"},children:e.jsx(ut,{size:18,color:"#666"})}),e.jsx(yi,{children:P.name})]},P.id))}),e.jsx(Zn,{style:{marginTop:"20px"},children:"OIDC Providers"}),e.jsx(vi,{children:xi.filter(P=>P.protocol==="oidc").map(P=>e.jsxs(bi,{type:"button",$selected:!1,onClick:()=>f(P),children:[P.logo?e.jsx(Yn,{src:P.logo,alt:P.name}):e.jsx("div",{style:{height:"24px",width:"24px",display:"flex",alignItems:"center",justifyContent:"center",background:"white",borderRadius:"4px",padding:"3px"},children:e.jsx(ut,{size:18,color:"#666"})}),e.jsx(yi,{children:P.name})]},P.id))})]}),g&&e.jsxs(e.Fragment,{children:[e.jsxs(mi,{style:{marginTop:"16px"},children:[e.jsx("div",{style:{marginBottom:"12px",fontWeight:500},children:"Service Provider Details"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:u==="saml"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{minWidth:"80px",fontSize:"12px"},children:"ACS URL:"}),e.jsx("code",{style:{flex:1,fontSize:"11px"},children:j}),e.jsx(Yr,{onClick:()=>T(j,"acs"),children:p==="acs"?e.jsx(et,{size:12}):e.jsx(dr,{size:12})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{minWidth:"80px",fontSize:"12px"},children:"Metadata:"}),e.jsx("code",{style:{flex:1,fontSize:"11px"},children:S}),e.jsx(Yr,{onClick:()=>T(S,"metadata"),children:p==="metadata"?e.jsx(et,{size:12}):e.jsx(dr,{size:12})})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{minWidth:"80px",fontSize:"12px"},children:"Callback:"}),e.jsx("code",{style:{flex:1,fontSize:"11px"},children:$}),e.jsx(Yr,{onClick:()=>T($,"callback"),children:p==="callback"?e.jsx(et,{size:12}):e.jsx(dr,{size:12})})]})})]}),e.jsxs("div",{style:{marginTop:"24px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[e.jsx(Zn,{style:{margin:0},children:g?`${g.name} Configuration`:"Configuration"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[g&&g.docUrl&&e.jsxs("a",{href:g.docUrl,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--color-primary)",textDecoration:"none",display:"flex",gap:"2px",alignItems:"center"},children:[e.jsx(Ls,{size:12})," Docs"]}),e.jsx(K,{type:"button",onClick:O,disabled:k||!g,style:{width:"auto",padding:"8px 16px",background:"transparent",border:"1px solid var(--color-border)"},children:k?e.jsx(Ie,{size:16}):"Test Connection"}),e.jsx(K,{type:"submit",disabled:a||w.length===0||!g,style:{width:"auto",padding:"8px 16px"},children:a?e.jsx(Ie,{size:16}):"Create Connection"})]})]}),z&&(()=>{const P={entity_id_valid:"IdP Entity ID",sso_url_valid:"IdP SSO URL",certificate_provided:"X.509 Certificate",issuer_url_valid:"Issuer URL",client_id_valid:"Client ID",certificate_valid:"Certificate Valid",sso_url_reachable:"SSO URL Reachable",discovery_reachable:"Discovery Endpoint",discovery_valid:"Discovery Valid",authorization_endpoint:"Authorization Endpoint",token_endpoint:"Token Endpoint",issuer_valid:"Issuer URL Valid"};return e.jsxs("div",{style:{padding:"16px",marginBottom:"16px",borderRadius:"8px",background:z.success?"rgba(16, 185, 129, 0.1)":"rgba(239, 68, 68, 0.1)",border:`1px solid ${z.success?"#10b981":"#ef4444"}`},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:"12px",fontSize:"14px",color:z.success?"#10b981":"#ef4444"},children:z.success?"✓ All checks passed":"✗ Some checks failed"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:Object.entries(z.checks).map(([M,N])=>{var D;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px",padding:"8px 12px",background:"var(--color-background)",borderRadius:"6px",border:"1px solid var(--color-border)"},children:[e.jsx("span",{style:{color:N?"#10b981":"#ef4444",fontWeight:600,fontSize:"14px",minWidth:"16px"},children:N?"✓":"✗"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,color:"var(--color-foreground)",fontSize:"13px"},children:P[M]||M.replace(/_/g," ").replace(/\b\w/g,L=>L.toUpperCase())}),((D=z.errors)==null?void 0:D[M])&&e.jsx("div",{style:{color:"#ef4444",fontSize:"12px",marginTop:"4px"},children:z.errors[M]})]})]},M)})})]})})(),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"16px"},children:[!g&&e.jsxs(he,{children:[e.jsx(ie,{children:"Protocol *"}),e.jsxs(wi,{value:u,onChange:P=>d(P.target.value),children:[e.jsx("option",{value:"saml",children:"SAML"}),e.jsx("option",{value:"oidc",children:"OpenID Connect (OIDC)"})]})]}),e.jsxs(he,{style:{gridColumn:"1 / -1"},children:[e.jsx(ie,{children:"Domain *"}),y?e.jsx("div",{style:{padding:"10px",color:"var(--color-muted)"},children:"Loading domains..."}):w.length===0?e.jsx(mi,{style:{marginBottom:0},children:"No verified domains found. Please add and verify a domain first."}):e.jsxs(wi,{value:b.domain_id,onChange:P=>_({...b,domain_id:P.target.value}),required:!0,children:[e.jsx("option",{value:"",children:"Select a verified domain"}),w.map(P=>e.jsx("option",{value:P.id,children:P.fqdn},P.id))]})]}),u==="saml"?e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(ie,{children:"IdP Entity ID *"}),e.jsx(ce,{type:"text",value:b.idp_entity_id,onChange:P=>_({...b,idp_entity_id:P.target.value}),placeholder:"https://idp.example.com/entity",required:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"IdP SSO URL *"}),e.jsx(ce,{type:"url",value:b.idp_sso_url,onChange:P=>_({...b,idp_sso_url:P.target.value}),placeholder:"https://idp.example.com/sso",required:!0})]}),e.jsxs(he,{style:{gridColumn:"1 / -1"},children:[e.jsx(ie,{children:"X.509 Certificate *"}),e.jsx(Ux,{value:b.idp_certificate,onChange:P=>_({...b,idp_certificate:P.target.value}),placeholder:"-----BEGIN CERTIFICATE-----...",required:!0})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(ie,{children:"Issuer URL *"}),e.jsx(ce,{type:"url",value:b.oidc_issuer_url,onChange:P=>_({...b,oidc_issuer_url:P.target.value}),placeholder:"https://login.example.com",required:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Client ID *"}),e.jsx(ce,{type:"text",value:b.oidc_client_id,onChange:P=>_({...b,oidc_client_id:P.target.value}),placeholder:"your-client-id",required:!0,autoComplete:"off","data-lpignore":"true","data-form-type":"other"})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Client Secret *"}),e.jsx(ce,{type:"password",value:b.oidc_client_secret,onChange:P=>_({...b,oidc_client_secret:P.target.value}),placeholder:"your-client-secret",required:!0,autoComplete:"new-password","data-lpignore":"true","data-form-type":"other"})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Scopes"}),e.jsx(ce,{type:"text",value:b.oidc_scopes,onChange:P=>_({...b,oidc_scopes:P.target.value}),placeholder:"openid profile email"})]})]}),e.jsx(he,{style:{gridColumn:"1 / -1"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:400,color:"var(--color-foreground)",display:"block"},children:"Enable JIT Provisioning"}),e.jsx("div",{style:{fontSize:"12px",color:"var(--color-muted)",marginTop:"4px"},children:"When enabled, new users are automatically created on their first SSO login. When disabled, only pre-existing users can sign in via SSO."})]}),e.jsx(fr,{checked:b.jit_enabled,onChange:()=>_({...b,jit_enabled:!b.jit_enabled})})]})}),e.jsxs("div",{style:{gridColumn:"1 / -1",marginTop:"8px",marginBottom:"24px"},children:[e.jsxs("div",{onClick:()=>v(!m),style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",color:"var(--color-primary)",fontSize:"13px",fontWeight:500,marginBottom:m?"16px":"0"},children:[e.jsx("span",{style:{fontSize:"10px"},children:m?"▼":"▶"}),"Advanced Options (Attribute Mapping)"]}),m&&e.jsxs("div",{style:{padding:"16px",background:"var(--color-background-alt)",borderRadius:"8px",border:"1px solid var(--color-border)"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--color-muted)",marginBottom:"12px"},children:"Map IdP attribute names to Wacht user fields. Leave empty to use default attribute names."}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"12px"},children:[e.jsxs(he,{children:[e.jsx(ie,{children:"First Name Attribute"}),e.jsx(ce,{type:"text",value:b.attr_first_name,onChange:P=>_({...b,attr_first_name:P.target.value}),placeholder:u==="saml"?"givenName":"given_name"})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Last Name Attribute"}),e.jsx(ce,{type:"text",value:b.attr_last_name,onChange:P=>_({...b,attr_last_name:P.target.value}),placeholder:u==="saml"?"surname":"family_name"})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Email Attribute"}),e.jsx(ce,{type:"text",value:b.attr_email,onChange:P=>_({...b,attr_email:P.target.value}),placeholder:"email"})]})]})]})]})]})]})]})]})},ji=l.div`
|
|
2753
2753
|
* {
|
|
2754
2754
|
box-sizing: border-box;
|
|
2755
2755
|
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
@@ -2852,8 +2852,8 @@ cursor: pointer;
|
|
|
2852
2852
|
gap: 12px;
|
|
2853
2853
|
margin-bottom: 24px;
|
|
2854
2854
|
`,Jx=()=>{var M,N,D,L;const{activeOrganization:t,loading:r}=nt(),{switchOrganization:o,refetch:n}=Ke(),{workspaces:s}=Bt(),{deployment:a}=ye(),{deleteOrganization:h,updateOrganization:g}=en(),{toast:c}=Je(),[u,d]=i.useState((t==null?void 0:t.name)||""),[p,x]=i.useState((t==null?void 0:t.description)||""),[m,v]=i.useState((t==null?void 0:t.image_url)||null),b=i.useRef(null),[_,k]=i.useState(!1),[C,z]=i.useState({mfa_required:!1,ip_restrictions:!1,allowed_ips:"",default_workspace_id:""}),[E,w]=i.useState(""),[y,f]=i.useState(!1),[$,S]=i.useState(!1),j=i.useCallback(async()=>{if(!(!t||_))try{k(!0),await g(t,{name:u,description:p}),c("Changes saved","info")}catch(I){const A=I.message||"Failed to save changes. Please try again.";c(A,"error")}finally{k(!1)}},[t,u,p,m,C,g,c]);i.useEffect(()=>{var I;t&&(d(t.name||""),x(t.description||""),v(t.image_url||null),z({allowed_ips:((I=t.whitelisted_ips)==null?void 0:I.join(`
|
|
2855
|
-
`))||"",ip_restrictions:t.enable_ip_restriction||!1,mfa_required:t.enforce_mfa||!1,default_workspace_id:t.auto_assigned_workspace_id||""}))},[t]);const T=i.useMemo(()=>s.filter(A=>A.organization.id===(t==null?void 0:t.id)),[s,t==null?void 0:t.id]),R=async()=>{if(!(!t||E!==t.name))try{f(!0),await o(""),await h(t),await n(),c("Organization deleted successfully","info")}catch{c("Failed to delete organization","error")}finally{f(!1),w("")}};if(i.useEffect(()=>()=>{m&&URL.revokeObjectURL(m)},[m]),r)return e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Ie,{})});const O=I=>{var A;if((A=I.target.files)!=null&&A[0]){const q=I.target.files[0];if(q.size>2*1024*1024){c("File size cannot exceed 2MB","error");return}if(!q.type.startsWith("image/")){c("Please select a valid image file","error");return}m&&URL.revokeObjectURL(m),v(URL.createObjectURL(q)),setTimeout(()=>j(),100)}},P=()=>{b.current&&b.current.click()};return e.jsx(e.Fragment,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2xl)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-2xl)",alignItems:"center"},children:[e.jsx("div",{style:{flexShrink:0},children:e.jsxs("div",{style:{width:"120px",height:"120px",borderRadius:"50%",border:"2px dashed var(--color-border)",background:m?"transparent":"var(--color-input-background)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",transition:"all 0.2s ease"},onClick:P,onMouseEnter:I=>{I.currentTarget.style.borderColor="var(--color-primary)",I.currentTarget.style.transform="scale(1.02)"},onMouseLeave:I=>{I.currentTarget.style.borderColor="var(--color-border)",I.currentTarget.style.transform="scale(1)"},children:[m?e.jsx("img",{src:m,alt:"Organization Logo",style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"50%"}}):e.jsx(Kr,{size:32,color:"var(--color-muted)"}),e.jsx("input",{type:"file",ref:b,style:{display:"none"},accept:"image/*",onChange:O,"aria-label":"Upload organization logo"})]})}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{marginBottom:"var(--space-lg)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Organization Logo"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Upload an image to represent your organization"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-sm)",marginBottom:"var(--space-sm)"},children:[e.jsxs(K,{onClick:()=>{var I;return(I=b.current)==null?void 0:I.click()},style:{padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(Kr,{size:14}),m?"Change":"Upload"]}),e.jsxs(K,{onClick:()=>{v(null),b.current&&(b.current.value="")},style:{background:"transparent",color:"var(--color-muted)",border:"1px solid var(--color-border)",padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(pn,{size:14}),"Remove"]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"var(--space-md)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Organization Details"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Basic information about your organization"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-lg)"},children:[e.jsxs(he,{children:[e.jsx(
|
|
2856
|
-
10.0.0.0/24`,style:{minHeight:"80px",resize:"vertical",fontFamily:"monospace"}}),e.jsx("p",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)",margin:"var(--space-2xs) 0 0 0"},children:"Enter one IP address or CIDR block per line"})]})]}),((D=a==null?void 0:a.b2b_settings)==null?void 0:D.workspaces_enabled)&&T.length>0&&e.jsxs(he,{children:[e.jsx(
|
|
2855
|
+
`))||"",ip_restrictions:t.enable_ip_restriction||!1,mfa_required:t.enforce_mfa||!1,default_workspace_id:t.auto_assigned_workspace_id||""}))},[t]);const T=i.useMemo(()=>s.filter(A=>A.organization.id===(t==null?void 0:t.id)),[s,t==null?void 0:t.id]),R=async()=>{if(!(!t||E!==t.name))try{f(!0),await o(""),await h(t),await n(),c("Organization deleted successfully","info")}catch{c("Failed to delete organization","error")}finally{f(!1),w("")}};if(i.useEffect(()=>()=>{m&&URL.revokeObjectURL(m)},[m]),r)return e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Ie,{})});const O=I=>{var A;if((A=I.target.files)!=null&&A[0]){const q=I.target.files[0];if(q.size>2*1024*1024){c("File size cannot exceed 2MB","error");return}if(!q.type.startsWith("image/")){c("Please select a valid image file","error");return}m&&URL.revokeObjectURL(m),v(URL.createObjectURL(q)),setTimeout(()=>j(),100)}},P=()=>{b.current&&b.current.click()};return e.jsx(e.Fragment,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2xl)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-2xl)",alignItems:"center"},children:[e.jsx("div",{style:{flexShrink:0},children:e.jsxs("div",{style:{width:"120px",height:"120px",borderRadius:"50%",border:"2px dashed var(--color-border)",background:m?"transparent":"var(--color-input-background)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",transition:"all 0.2s ease"},onClick:P,onMouseEnter:I=>{I.currentTarget.style.borderColor="var(--color-primary)",I.currentTarget.style.transform="scale(1.02)"},onMouseLeave:I=>{I.currentTarget.style.borderColor="var(--color-border)",I.currentTarget.style.transform="scale(1)"},children:[m?e.jsx("img",{src:m,alt:"Organization Logo",style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"50%"}}):e.jsx(Kr,{size:32,color:"var(--color-muted)"}),e.jsx("input",{type:"file",ref:b,style:{display:"none"},accept:"image/*",onChange:O,"aria-label":"Upload organization logo"})]})}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{marginBottom:"var(--space-lg)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Organization Logo"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Upload an image to represent your organization"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-sm)",marginBottom:"var(--space-sm)"},children:[e.jsxs(K,{onClick:()=>{var I;return(I=b.current)==null?void 0:I.click()},style:{padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(Kr,{size:14}),m?"Change":"Upload"]}),e.jsxs(K,{onClick:()=>{v(null),b.current&&(b.current.value="")},style:{background:"transparent",color:"var(--color-muted)",border:"1px solid var(--color-border)",padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(pn,{size:14}),"Remove"]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"var(--space-md)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Organization Details"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Basic information about your organization"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-lg)"},children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"name",children:"Organization Name"}),e.jsx(ce,{id:"name",type:"text",value:u,onChange:I=>d(I.target.value),onBlur:j,placeholder:"Enter organization name",required:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"description",children:"Description"}),e.jsx(ce,{id:"description",as:"textarea",value:p,onChange:I=>x(I.target.value),onBlur:j,placeholder:"Enter organization description",style:{minHeight:"80px",resize:"vertical",fontFamily:"inherit"}}),e.jsx("p",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)",margin:"var(--space-2xs) 0 0 0"},children:"Brief description of your organization"})]}),((M=a==null?void 0:a.b2b_settings)==null?void 0:M.enforce_mfa_per_org_enabled)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx(ie,{style:{fontSize:"var(--font-xs)",color:"var(--color-foreground)",display:"block",marginBottom:"var(--space-2xs)"},children:"Multi-Factor Authentication"}),e.jsx("div",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)"},id:"mfa-description",children:"Require all members to set up MFA for added security"})]}),e.jsx(fr,{checked:C.mfa_required,onChange:()=>{z(I=>({...I,mfa_required:!I.mfa_required})),setTimeout(()=>j(),100)}})]}),((N=a==null?void 0:a.b2b_settings)==null?void 0:N.ip_allowlist_per_org_enabled)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx(ie,{style:{fontSize:"var(--font-xs)",color:"var(--color-foreground)",display:"block",marginBottom:"var(--space-2xs)"},children:"IP Restrictions"}),e.jsx("div",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)"},id:"ip-restrictions-description",children:"Only allow access from specific IP addresses"})]}),e.jsx(fr,{checked:C.ip_restrictions,onChange:()=>{z(I=>({...I,ip_restrictions:!I.ip_restrictions})),setTimeout(()=>j(),100)},"aria-label":"Enable IP address restrictions","aria-describedby":"ip-restrictions-description"})]}),C.ip_restrictions&&e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"allowed_ips",children:"Allowed IP Addresses"}),e.jsx(ce,{id:"allowed_ips",as:"textarea",value:C.allowed_ips,onChange:I=>z(A=>({...A,allowed_ips:I.target.value})),onBlur:j,placeholder:`192.168.1.1
|
|
2856
|
+
10.0.0.0/24`,style:{minHeight:"80px",resize:"vertical",fontFamily:"monospace"}}),e.jsx("p",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)",margin:"var(--space-2xs) 0 0 0"},children:"Enter one IP address or CIDR block per line"})]})]}),((D=a==null?void 0:a.b2b_settings)==null?void 0:D.workspaces_enabled)&&T.length>0&&e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"default_workspace",children:"Default Workspace"}),e.jsx(Fs,{options:T.map(I=>({value:I.id,label:I.name})),value:C.default_workspace_id,onChange:I=>{z(A=>({...A,default_workspace_id:I})),setTimeout(()=>j(),100)},placeholder:"Select default workspace"}),e.jsx("p",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)",margin:"var(--space-2xs) 0 0 0"},children:"Workspace that new members will be added to automatically"})]})]})]}),((L=a==null?void 0:a.b2b_settings)==null?void 0:L.allow_org_deletion)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h3",{style:{fontSize:"16px",color:"var(--color-foreground)",margin:"0 0 4px 0"},children:"Danger Zone"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-muted)",margin:0},children:"Irreversible and destructive actions"})]}),e.jsxs("div",{style:{padding:"20px",border:"1px solid var(--color-error)",borderRadius:"8px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:$?"20px":"0"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",color:"var(--color-foreground)",marginBottom:"4px",fontWeight:"500"},children:"Delete Organization"}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-muted)"},children:"Once you delete this organization, there is no going back. Please be certain."})]}),e.jsx(K,{onClick:()=>{$?(S(!1),w("")):S(!0)},style:{background:"var(--color-error)",color:"white",border:"none",padding:"6px 12px",fontSize:"13px",height:"32px",width:"auto"},children:$?"Cancel":"Delete"})]}),$&&e.jsxs("div",{children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"confirm_name",children:"Confirm by typing the organization name"}),e.jsx(ce,{id:"confirm_name",type:"text",value:E,onChange:I=>w(I.target.value),placeholder:`Type "${t==null?void 0:t.name}" to confirm`})]}),e.jsx(K,{onClick:R,disabled:E!==(t==null?void 0:t.name)||y,style:{background:E===(t==null?void 0:t.name)?"var(--color-error)":"transparent",color:E===(t==null?void 0:t.name)?"white":"var(--color-muted)",border:"1px solid var(--color-border)",padding:"8px 16px",fontSize:"14px",height:"36px",cursor:E===(t==null?void 0:t.name)?"pointer":"not-allowed",opacity:E===(t==null?void 0:t.name)?1:.6,marginTop:"12px"},children:y?e.jsx(Ie,{size:12}):"Delete Forever"})]})]})]})]})]})})},_i=l.span`
|
|
2857
2857
|
background: var(--color-primary-background);
|
|
2858
2858
|
color: var(--color-primary);
|
|
2859
2859
|
padding: 4px 8px;
|
|
@@ -3242,7 +3242,7 @@ cursor: pointer;
|
|
|
3242
3242
|
color: var(--color-foreground);
|
|
3243
3243
|
background: var(--color-input-background);
|
|
3244
3244
|
}
|
|
3245
|
-
`,O0=({onClose:t,onSuccess:r,roles:o,createInvitation:n,triggerRef:s})=>{const a=i.useRef(null),[h,g]=i.useState(""),[c,u]=i.useState(null),[d,p]=i.useState(!1),[x,m]=i.useState(!1),[v,b]=i.useState({top:0,left:0}),{toast:_}=Je(),k=o.map(E=>({value:E.id,label:E.name}));i.useEffect(()=>{m(!0);const E=setTimeout(()=>{if(!a.current||!(s!=null&&s.current))return;const $=s.current;if($){const S=$.getBoundingClientRect(),j=360,T=250,R=8;let O=0,P=0;const M=window.innerHeight-S.bottom,N=S.top;M>=T+R?(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):N>=T+R?(O=S.top-T-R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left)),b({top:O,left:P})}},10),w=$=>{a.current&&!a.current.contains($.target)&&(t==null||t())},y=$=>{$.key==="Escape"&&(t==null||t())},f=setTimeout(()=>{document.addEventListener("mousedown",w),document.addEventListener("keydown",y)},100);return()=>{clearTimeout(E),clearTimeout(f),document.removeEventListener("mousedown",w),document.removeEventListener("keydown",y)}},[t,s]);const C=E=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E),z=async()=>{const E=h.trim().toLowerCase();if(!(!E||!c)){if(!C(E)){_("Please enter a valid email address","error");return}if(E.length>320){_("Email address is too long","error");return}p(!0);try{await n(E,c.id),r==null||r()}catch(w){const y=w.message||"Failed to send invitation. Please try again.";_(y,"error")}finally{p(!1)}}};return x?e.jsxs(E0,{ref:a,style:{top:`${v.top}px`,left:`${v.left}px`,visibility:v.top>0?"visible":"hidden"},onClick:E=>E.stopPropagation(),role:"dialog","aria-labelledby":"invite-workspace-member-title","aria-modal":"true",children:[e.jsxs(I0,{children:[e.jsx(P0,{id:"invite-workspace-member-title",children:"Invite Member"}),e.jsx(M0,{onClick:t,"aria-label":"Close invite member dialog",children:e.jsx(ct,{size:16})})]}),e.jsx(R0,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(
|
|
3245
|
+
`,O0=({onClose:t,onSuccess:r,roles:o,createInvitation:n,triggerRef:s})=>{const a=i.useRef(null),[h,g]=i.useState(""),[c,u]=i.useState(null),[d,p]=i.useState(!1),[x,m]=i.useState(!1),[v,b]=i.useState({top:0,left:0}),{toast:_}=Je(),k=o.map(E=>({value:E.id,label:E.name}));i.useEffect(()=>{m(!0);const E=setTimeout(()=>{if(!a.current||!(s!=null&&s.current))return;const $=s.current;if($){const S=$.getBoundingClientRect(),j=360,T=250,R=8;let O=0,P=0;const M=window.innerHeight-S.bottom,N=S.top;M>=T+R?(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):N>=T+R?(O=S.top-T-R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left)),b({top:O,left:P})}},10),w=$=>{a.current&&!a.current.contains($.target)&&(t==null||t())},y=$=>{$.key==="Escape"&&(t==null||t())},f=setTimeout(()=>{document.addEventListener("mousedown",w),document.addEventListener("keydown",y)},100);return()=>{clearTimeout(E),clearTimeout(f),document.removeEventListener("mousedown",w),document.removeEventListener("keydown",y)}},[t,s]);const C=E=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E),z=async()=>{const E=h.trim().toLowerCase();if(!(!E||!c)){if(!C(E)){_("Please enter a valid email address","error");return}if(E.length>320){_("Email address is too long","error");return}p(!0);try{await n(E,c.id),r==null||r()}catch(w){const y=w.message||"Failed to send invitation. Please try again.";_(y,"error")}finally{p(!1)}}};return x?e.jsxs(E0,{ref:a,style:{top:`${v.top}px`,left:`${v.left}px`,visibility:v.top>0?"visible":"hidden"},onClick:E=>E.stopPropagation(),role:"dialog","aria-labelledby":"invite-workspace-member-title","aria-modal":"true",children:[e.jsxs(I0,{children:[e.jsx(P0,{id:"invite-workspace-member-title",children:"Invite Member"}),e.jsx(M0,{onClick:t,"aria-label":"Close invite member dialog",children:e.jsx(ct,{size:16})})]}),e.jsx(R0,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(ie,{children:"Email Address"}),e.jsx(ce,{type:"email",placeholder:"colleague@company.com",value:h,onChange:E=>g(E.target.value),autoFocus:!0,"aria-label":"Email address for workspace invitation","aria-describedby":"workspace-email-help"})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Role"}),e.jsx(Fs,{options:k,value:c==null?void 0:c.id,onChange:E=>u(o.find(w=>w.id===E)),placeholder:"Select a role","aria-label":"Select role for invited workspace member"})]})]})}),e.jsxs(T0,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto"},children:"Cancel"}),e.jsx(K,{onClick:z,disabled:!h||!c||d,style:{width:"auto"},children:d?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:14})," Sending..."]}):"Send Invitation"})]})]}):null},A0=l.div`
|
|
3246
3246
|
position: fixed;
|
|
3247
3247
|
width: 360px;
|
|
3248
3248
|
max-width: calc(100vw - 48px);
|
|
@@ -3291,7 +3291,7 @@ cursor: pointer;
|
|
|
3291
3291
|
color: var(--color-foreground);
|
|
3292
3292
|
background: var(--color-input-background);
|
|
3293
3293
|
}
|
|
3294
|
-
`,Si=({onClose:t,onSuccess:r,role:o,triggerRef:n})=>{var E;const s=i.useRef(null),[a,h]=i.useState((o==null?void 0:o.name)||""),[g,c]=i.useState((o==null?void 0:o.permissions)||[]),[u,d]=i.useState(!1),{deployment:p}=ye(),[x,m]=i.useState(!1),[v,b]=i.useState({top:0,left:0}),{toast:_}=Je(),k=!!o,C=(((E=p==null?void 0:p.b2b_settings)==null?void 0:E.workspace_permissions)||[]).map(w=>({value:w,label:w}));i.useEffect(()=>{m(!0);const w=setTimeout(()=>{if(!s.current||!(n!=null&&n.current))return;const S=n.current;if(S){const j=S.getBoundingClientRect(),T=360,R=250,O=8;let P=0,M=0;const N=window.innerHeight-j.bottom,D=j.top;N>=R+O?(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):D>=R+O?(P=j.top-R-O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left)),b({top:P,left:M})}},10),y=S=>{s.current&&!s.current.contains(S.target)&&(t==null||t())},f=S=>{S.key==="Escape"&&(t==null||t())},$=setTimeout(()=>{document.addEventListener("mousedown",y),document.addEventListener("keydown",f)},100);return()=>{clearTimeout(w),clearTimeout($),document.removeEventListener("mousedown",y),document.removeEventListener("keydown",f)}},[t,n]);const z=async()=>{if(a.trim()){d(!0);try{const w={id:o==null?void 0:o.id,name:a.trim(),permissions:g};r==null||r(w)}catch(w){const y=w.message||"Failed to save role. Please try again.";_(y,"error")}finally{d(!1)}}};return x?e.jsxs(A0,{ref:s,style:{top:`${v.top}px`,left:`${v.left}px`,visibility:v.top>0?"visible":"hidden"},onClick:w=>w.stopPropagation(),children:[e.jsxs(L0,{children:[e.jsx(D0,{children:k?"Edit Role":"Add Role"}),e.jsx(B0,{onClick:t,children:e.jsx(ct,{size:16})})]}),e.jsx(N0,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(
|
|
3294
|
+
`,Si=({onClose:t,onSuccess:r,role:o,triggerRef:n})=>{var E;const s=i.useRef(null),[a,h]=i.useState((o==null?void 0:o.name)||""),[g,c]=i.useState((o==null?void 0:o.permissions)||[]),[u,d]=i.useState(!1),{deployment:p}=ye(),[x,m]=i.useState(!1),[v,b]=i.useState({top:0,left:0}),{toast:_}=Je(),k=!!o,C=(((E=p==null?void 0:p.b2b_settings)==null?void 0:E.workspace_permissions)||[]).map(w=>({value:w,label:w}));i.useEffect(()=>{m(!0);const w=setTimeout(()=>{if(!s.current||!(n!=null&&n.current))return;const S=n.current;if(S){const j=S.getBoundingClientRect(),T=360,R=250,O=8;let P=0,M=0;const N=window.innerHeight-j.bottom,D=j.top;N>=R+O?(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):D>=R+O?(P=j.top-R-O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left)),b({top:P,left:M})}},10),y=S=>{s.current&&!s.current.contains(S.target)&&(t==null||t())},f=S=>{S.key==="Escape"&&(t==null||t())},$=setTimeout(()=>{document.addEventListener("mousedown",y),document.addEventListener("keydown",f)},100);return()=>{clearTimeout(w),clearTimeout($),document.removeEventListener("mousedown",y),document.removeEventListener("keydown",f)}},[t,n]);const z=async()=>{if(a.trim()){d(!0);try{const w={id:o==null?void 0:o.id,name:a.trim(),permissions:g};r==null||r(w)}catch(w){const y=w.message||"Failed to save role. Please try again.";_(y,"error")}finally{d(!1)}}};return x?e.jsxs(A0,{ref:s,style:{top:`${v.top}px`,left:`${v.left}px`,visibility:v.top>0?"visible":"hidden"},onClick:w=>w.stopPropagation(),children:[e.jsxs(L0,{children:[e.jsx(D0,{children:k?"Edit Role":"Add Role"}),e.jsx(B0,{onClick:t,children:e.jsx(ct,{size:16})})]}),e.jsx(N0,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-sm)"},children:[e.jsxs(he,{children:[e.jsx(ie,{children:"Role Name"}),e.jsx(ce,{type:"text",value:a,onChange:w=>h(w.target.value),placeholder:"Enter role name",autoFocus:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{children:"Permissions"}),e.jsx(Nl,{options:C,value:g,onChange:c,placeholder:"Select permissions"})]})]})}),e.jsxs(F0,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto"},children:"Cancel"}),e.jsx(K,{onClick:z,disabled:!a.trim()||u,style:{width:"auto"},children:u?"Saving...":k?"Update":"Create"})]})]}):null},U0=l.div`
|
|
3295
3295
|
* {
|
|
3296
3296
|
box-sizing: border-box;
|
|
3297
3297
|
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
@@ -3430,8 +3430,8 @@ cursor: pointer;
|
|
|
3430
3430
|
`,q0=()=>{const{activeWorkspace:t,loading:r,getRoles:o,getInvitations:n,inviteMember:s,discardInvitation:a,resendInvitation:h}=Ut(),{toast:g}=Je(),[c,u]=i.useState(!0),[d,p]=i.useState(!0),[x,m]=i.useState(""),[v,b]=i.useState([]),[_,k]=i.useState([]),[C,z]=i.useState(!1),E=i.useRef(null);i.useEffect(()=>{if(!t)return;(async()=>{u(!0),p(!0);try{const[j,T]=await Promise.all([o(),n()]);k(j),b(T)}catch{}finally{u(!1),p(!1)}})()},[t==null?void 0:t.id]);const w=async S=>{try{await a(S.id);const j=await n();b(j)}catch{}},y=async S=>{try{await h(S.id);const j=await n();b(j),g("Invitation resent successfully","info")}catch{}},f=async()=>{z(!1);const S=await n();b(S),g("Invitation sent successfully","info")},$=i.useMemo(()=>x?v.filter(S=>(S.email||"").toLowerCase().includes(x.toLowerCase())):v,[v,x]);return r||c||d?e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Ie,{})}):e.jsxs(e.Fragment,{children:[e.jsxs(Vs,{children:[e.jsx(Ot,{value:x,onChange:m,placeholder:"Search Invitation"}),e.jsxs("div",{children:[e.jsx(K,{ref:E,onClick:()=>z(!C),style:{padding:"8px 16px",borderRadius:"6px",fontSize:"14px",fontWeight:500,height:"36px"},children:"Invite Members"}),C&&e.jsx(O0,{onClose:()=>z(!1),onSuccess:f,roles:_,createInvitation:s,triggerRef:E})]})]}),e.jsx("div",{children:$.length===0?e.jsx(mt,{title:x?"No invitations match your search":"No pending invitations",description:"Invite new members to your workspace."}):e.jsxs(_t,{children:[e.jsx(kt,{children:e.jsxs(qe,{children:[e.jsx($e,{children:"Email"}),e.jsx($e,{children:"Role"}),e.jsx($e,{children:"Invited"}),e.jsx($e,{})]})}),e.jsx(Ct,{children:$.map(S=>{var j,T;return e.jsxs(qe,{children:[e.jsx(Ne,{children:S.email}),e.jsx(Ne,{children:((j=S.initial_workspace_role)==null?void 0:j.name)||((T=S.initial_organization_role)==null?void 0:T.name)||"No role"}),e.jsx(Ne,{children:new Date(S.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}),e.jsx(St,{children:e.jsx("div",{style:{position:"relative"},children:e.jsxs(ht,{children:[e.jsx(gt,{children:e.jsx(rd,{children:"•••"})}),e.jsxs(ft,{children:[e.jsx(De,{onClick:()=>y(S),children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(Ds,{size:16,color:"var(--color-muted)"}),e.jsx("span",{children:"Resend Invitation"})]})}),e.jsx(De,{$destructive:!0,onClick:()=>w(S),children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(un,{size:16,color:"var(--color-error)"}),e.jsx("span",{children:"Cancel Invitation"})]})})]})]})})})]},S.id)})})]})})]})},Y0=()=>{const{activeWorkspace:t,loading:r,getMembers:o,getRoles:n,removeMember:s,addMemberRole:a,removeMemberRole:h}=Ut(),{session:g}=Ke(),{toast:c}=Je(),[u,d]=i.useState(""),{data:p=[],isLoading:x,mutate:m}=Ye(t?`wacht-api-workspaces:${t.id}:members`:null,()=>o()||[]),{data:v=[],isLoading:b}=Ye(t?`wacht-api-workspaces:${t.id}:roles`:null,()=>n()||[]),_=v,k=i.useMemo(()=>u?p.filter(y=>{var R;const f=y.public_user_data;if(!f)return!1;const $=f.first_name||"",S=f.last_name||"",j=((R=f.primary_email_address)==null?void 0:R.email)||"";return`${$} ${S}`.trim().toLowerCase().includes(u.toLowerCase())||j.toLowerCase().includes(u.toLowerCase())}):p,[p,u]),C=async y=>{try{await s(y),c("Member removed successfully","info"),m()}catch{c("Failed to remove member","error")}},z=async(y,f,$)=>{try{$?(await h(y,f),c("Role removed successfully","info")):(await a(y,f),c("Role added successfully","info")),m()}catch{c("Failed to toggle role","error"),c("Failed to update role","error")}},E=(y="",f="")=>`${y[0]||""}${f[0]||""}`.toUpperCase(),w=(y,f)=>{var $;return(($=y.roles)==null?void 0:$.some(S=>S.id===f))||!1};return r||x||b?e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Ie,{})}):e.jsxs(e.Fragment,{children:[e.jsx(Vs,{children:e.jsx(Ot,{value:u,onChange:d,placeholder:"Search members..."})}),k.length===0?e.jsx(mt,{title:u?"No members match your search":"No members yet",description:"Invite members to your workspace to get started."}):e.jsxs(_t,{children:[e.jsx(kt,{children:e.jsxs(qe,{children:[e.jsx($e,{children:"Member"}),e.jsx($e,{children:"Joined"}),e.jsx($e,{children:"Role"})]})}),e.jsx(Ct,{children:k.map(y=>{var j,T;const f=y.public_user_data,$=y.roles||[],S=(f==null?void 0:f.id)===((j=g==null?void 0:g.active_signin)==null?void 0:j.user_id);return e.jsxs(qe,{children:[e.jsx(Kl,{children:e.jsxs("div",{children:[e.jsx(H0,{children:f&&f.profile_picture_url?e.jsx("img",{src:f.profile_picture_url,alt:`${f.first_name||""} ${f.last_name||""}`,style:{width:"100%",height:"100%",objectFit:"cover"}}):E(f==null?void 0:f.first_name,f==null?void 0:f.last_name)||"?"}),e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--color-foreground)"},children:(()=>{var O;if(!f)return"Unknown User";const R=`${f.first_name||""} ${f.last_name||""}`.trim();return R||((O=f.primary_email_address)==null?void 0:O.email)||"Unknown User"})()}),S&&e.jsx("span",{style:{fontSize:"12px",padding:"2px 8px",background:"var(--color-background-alt)",borderRadius:"4px",color:"var(--color-secondary-text)"},children:"You"})]}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-secondary-text)"},children:(T=f==null?void 0:f.primary_email_address)==null?void 0:T.email})]})]})}),e.jsx(Ne,{children:new Date(y.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}),e.jsx(St,{children:e.jsxs(ht,{children:[e.jsx(gt,{children:e.jsxs(K,{style:{background:"var(--color-background)",border:"1px solid var(--color-border)",borderRadius:"6px",padding:"8px 12px",fontSize:"14px",color:"var(--color-foreground)",display:"flex",alignItems:"center",gap:"4px",minWidth:"120px",justifyContent:"space-between"},children:[e.jsx("span",{children:$.length>0?$[0].name:"No role"}),e.jsx(Ft,{size:14})]})}),e.jsxs(ft,{children:[_.map(R=>{const O=w(y,R.id);return e.jsx(De,{onClick:()=>z(y.id,R.id,O),children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",width:"100%"},children:[e.jsx("span",{children:R.name}),O&&e.jsx(et,{size:16,color:"var(--color-success)"})]})},R.id)}),e.jsx(hn,{}),e.jsx(De,{$destructive:!0,onClick:()=>C(y.id),children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(un,{size:16,color:"var(--color-error)"}),e.jsx("span",{children:"Remove Member"})]})})]})]})})]},y.id)})})]})]})},Z0=()=>{var q,Y;const{activeWorkspace:t,loading:r,updateWorkspace:o}=Ut(),{deleteWorkspace:n}=Bt(),{deployment:s}=ye(),{toast:a}=Je(),[h,g]=i.useState((t==null?void 0:t.name)||""),[c,u]=i.useState((t==null?void 0:t.description)||""),[d,p]=i.useState({mfa_required:!1,ip_restrictions:!1,allowed_ips:""}),[x,m]=i.useState(null),[v,b]=i.useState((t==null?void 0:t.image_url)||null),[_,k]=i.useState(!1),[C,z]=i.useState(!1),[E,w]=i.useState(""),[y,f]=i.useState(!1),[$,S]=i.useState(!1),j=i.useRef(null),T=i.useRef(null);if(i.useEffect(()=>{var B;t&&(g(t.name||""),u(t.description||""),b(t.image_url||null),p({mfa_required:t.enforce_2fa||!1,ip_restrictions:t.enable_ip_restriction||!1,allowed_ips:((B=t.whitelisted_ips)==null?void 0:B.join(`
|
|
3431
3431
|
`))||""}))},[t]),r||!t)return e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Ie,{})});const R=B=>{var H;if((H=B.target.files)!=null&&H[0]){const V=B.target.files[0];m(V),b(URL.createObjectURL(V)),setTimeout(()=>P(),100)}},O=()=>{j.current&&j.current.click()},P=i.useCallback(async()=>{if(!(!t||C))try{z(!0);const B={};x&&(B.image=x,m(null)),h!==t.name&&(B.name=h),c!==t.description&&(B.description=c),d.mfa_required!==t.enforce_2fa&&(B.enforce_2fa=d.mfa_required),d.ip_restrictions!==t.enable_ip_restriction&&(B.enable_ip_restriction=d.ip_restrictions);const H=(t.whitelisted_ips||[]).join(`
|
|
3432
3432
|
`);d.allowed_ips!==H&&(B.whitelisted_ips=d.allowed_ips.split(`
|
|
3433
|
-
`).map(V=>V.trim()).filter(V=>V!=="")),Object.keys(B).length>0&&(await o(B),k(!0),setTimeout(()=>k(!1),3e3))}catch{a("Failed to auto-save workspace","error")}finally{z(!1)}},[t,o,h,c,x,d,C]),M=i.useCallback(()=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{P()},1e3)},[P]),N=B=>{g(B.target.value),M()},D=B=>{u(B.target.value),M()},L=()=>{T.current&&clearTimeout(T.current),P()},I=()=>{T.current&&clearTimeout(T.current),P()},A=async()=>{if(!(!t||E!==t.name))try{f(!0),await n(t),a("Workspace deleted successfully","info")}catch(B){a(B.message||"Failed to delete workspace","error")}finally{f(!1),w(""),S(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2xl)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-2xl)",alignItems:"center"},children:[e.jsx("div",{style:{flexShrink:0},children:e.jsxs("div",{style:{width:"120px",height:"120px",borderRadius:"50%",border:"2px dashed var(--color-border)",background:v?"transparent":"var(--color-input-background)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",transition:"all 0.2s ease"},onClick:O,onMouseEnter:B=>{B.currentTarget.style.borderColor="var(--color-primary)",B.currentTarget.style.transform="scale(1.02)"},onMouseLeave:B=>{B.currentTarget.style.borderColor="var(--color-border)",B.currentTarget.style.transform="scale(1)"},children:[v?e.jsx("img",{src:v,alt:"Workspace Logo",style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"50%"}}):e.jsx(Kr,{size:32,color:"var(--color-muted)"}),e.jsx("input",{type:"file",ref:j,style:{display:"none"},accept:"image/*",onChange:R})]})}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{marginBottom:"var(--space-lg)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Workspace Logo"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Upload an image to represent your workspace"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-sm)",marginBottom:"var(--space-sm)"},children:[e.jsxs(K,{onClick:()=>{var B;return(B=j.current)==null?void 0:B.click()},style:{padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(Kr,{size:14}),v?"Change":"Upload"]}),e.jsxs(K,{onClick:()=>{b(null),m(null),j.current&&(j.current.value=""),setTimeout(()=>P(),100)},style:{background:"transparent",color:"var(--color-muted)",border:"1px solid var(--color-border)",padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(un,{size:14}),"Remove"]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"var(--space-md)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Workspace Details"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Basic information about your workspace"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-lg)"},children:[e.jsxs(he,{children:[e.jsx(
|
|
3434
|
-
10.0.0.0/24`,style:{minHeight:"80px",resize:"vertical",fontFamily:"monospace"}}),e.jsx("p",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)",margin:"var(--space-2xs) 0 0 0"},children:"Enter one IP address or CIDR block per line"})]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h3",{style:{fontSize:"16px",color:"var(--color-foreground)",margin:"0 0 4px 0"},children:"Danger Zone"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-muted)",margin:0},children:"Irreversible and destructive actions"})]}),e.jsxs("div",{style:{padding:"20px",border:"1px solid var(--color-error)",borderRadius:"8px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:$?"20px":"0"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",color:"var(--color-foreground)",marginBottom:"4px",fontWeight:"500"},children:"Delete Workspace"}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-muted)"},children:"Once you delete this workspace, there is no going back. Please be certain."})]}),e.jsx(K,{onClick:()=>{$?(S(!1),w("")):S(!0)},style:{background:"var(--color-error)",color:"white",border:"none",padding:"6px 12px",fontSize:"13px",height:"32px",width:"auto"},children:$?"Cancel":"Delete"})]}),$&&e.jsxs("div",{children:[e.jsxs(he,{children:[e.jsx(
|
|
3433
|
+
`).map(V=>V.trim()).filter(V=>V!=="")),Object.keys(B).length>0&&(await o(B),k(!0),setTimeout(()=>k(!1),3e3))}catch{a("Failed to auto-save workspace","error")}finally{z(!1)}},[t,o,h,c,x,d,C]),M=i.useCallback(()=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{P()},1e3)},[P]),N=B=>{g(B.target.value),M()},D=B=>{u(B.target.value),M()},L=()=>{T.current&&clearTimeout(T.current),P()},I=()=>{T.current&&clearTimeout(T.current),P()},A=async()=>{if(!(!t||E!==t.name))try{f(!0),await n(t),a("Workspace deleted successfully","info")}catch(B){a(B.message||"Failed to delete workspace","error")}finally{f(!1),w(""),S(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2xl)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-2xl)",alignItems:"center"},children:[e.jsx("div",{style:{flexShrink:0},children:e.jsxs("div",{style:{width:"120px",height:"120px",borderRadius:"50%",border:"2px dashed var(--color-border)",background:v?"transparent":"var(--color-input-background)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",transition:"all 0.2s ease"},onClick:O,onMouseEnter:B=>{B.currentTarget.style.borderColor="var(--color-primary)",B.currentTarget.style.transform="scale(1.02)"},onMouseLeave:B=>{B.currentTarget.style.borderColor="var(--color-border)",B.currentTarget.style.transform="scale(1)"},children:[v?e.jsx("img",{src:v,alt:"Workspace Logo",style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"50%"}}):e.jsx(Kr,{size:32,color:"var(--color-muted)"}),e.jsx("input",{type:"file",ref:j,style:{display:"none"},accept:"image/*",onChange:R})]})}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{marginBottom:"var(--space-lg)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Workspace Logo"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Upload an image to represent your workspace"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-sm)",marginBottom:"var(--space-sm)"},children:[e.jsxs(K,{onClick:()=>{var B;return(B=j.current)==null?void 0:B.click()},style:{padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(Kr,{size:14}),v?"Change":"Upload"]}),e.jsxs(K,{onClick:()=>{b(null),m(null),j.current&&(j.current.value=""),setTimeout(()=>P(),100)},style:{background:"transparent",color:"var(--color-muted)",border:"1px solid var(--color-border)",padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(un,{size:14}),"Remove"]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"var(--space-md)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Workspace Details"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Basic information about your workspace"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-lg)"},children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"name",children:"Workspace Name"}),e.jsx(ce,{id:"name",type:"text",value:h,onChange:N,onBlur:L,placeholder:"Enter workspace name",required:!0})]}),e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"description",children:"Description"}),e.jsx(ce,{id:"description",as:"textarea",value:c,onChange:D,onBlur:I,placeholder:"Tell us about your workspace",style:{minHeight:"80px",resize:"vertical",fontFamily:"inherit"}}),e.jsx("p",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)",margin:"var(--space-2xs) 0 0 0"},children:"Brief description of your workspace and its purpose"})]}),((q=s==null?void 0:s.b2b_settings)==null?void 0:q.enforce_mfa_per_workspace_enabled)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx(ie,{style:{fontSize:"var(--font-xs)",color:"var(--color-foreground)",display:"block",marginBottom:"var(--space-2xs)"},children:"Multi-Factor Authentication"}),e.jsx("div",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)"},id:"mfa-description",children:"Require all members to set up MFA for added security"})]}),e.jsx(fr,{checked:d.mfa_required,onChange:()=>{p(B=>({...B,mfa_required:!B.mfa_required})),setTimeout(()=>P(),100)}})]}),((Y=s==null?void 0:s.b2b_settings)==null?void 0:Y.ip_allowlist_per_workspace_enabled)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx(ie,{style:{fontSize:"var(--font-xs)",color:"var(--color-foreground)",display:"block",marginBottom:"var(--space-2xs)"},children:"IP Restrictions"}),e.jsx("div",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)"},id:"ip-restrictions-description",children:"Only allow access from specific IP addresses"})]}),e.jsx(fr,{checked:d.ip_restrictions,onChange:()=>{p(B=>({...B,ip_restrictions:!B.ip_restrictions})),setTimeout(()=>P(),100)},"aria-label":"Enable IP address restrictions","aria-describedby":"ip-restrictions-description"})]}),d.ip_restrictions&&e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"allowed_ips",children:"Allowed IP Addresses"}),e.jsx(ce,{id:"allowed_ips",as:"textarea",value:d.allowed_ips,onChange:B=>p(H=>({...H,allowed_ips:B.target.value})),onBlur:P,placeholder:`192.168.1.1
|
|
3434
|
+
10.0.0.0/24`,style:{minHeight:"80px",resize:"vertical",fontFamily:"monospace"}}),e.jsx("p",{style:{fontSize:"var(--font-2xs)",color:"var(--color-muted)",margin:"var(--space-2xs) 0 0 0"},children:"Enter one IP address or CIDR block per line"})]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h3",{style:{fontSize:"16px",color:"var(--color-foreground)",margin:"0 0 4px 0"},children:"Danger Zone"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-muted)",margin:0},children:"Irreversible and destructive actions"})]}),e.jsxs("div",{style:{padding:"20px",border:"1px solid var(--color-error)",borderRadius:"8px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:$?"20px":"0"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",color:"var(--color-foreground)",marginBottom:"4px",fontWeight:"500"},children:"Delete Workspace"}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-muted)"},children:"Once you delete this workspace, there is no going back. Please be certain."})]}),e.jsx(K,{onClick:()=>{$?(S(!1),w("")):S(!0)},style:{background:"var(--color-error)",color:"white",border:"none",padding:"6px 12px",fontSize:"13px",height:"32px",width:"auto"},children:$?"Cancel":"Delete"})]}),$&&e.jsxs("div",{children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"confirm_workspace_name",children:"Confirm by typing the workspace name"}),e.jsx(ce,{id:"confirm_workspace_name",type:"text",value:E,onChange:B=>w(B.target.value),placeholder:`Type "${t==null?void 0:t.name}" to confirm`})]}),e.jsx(K,{onClick:A,disabled:E!==(t==null?void 0:t.name)||y,style:{background:E===(t==null?void 0:t.name)?"var(--color-error)":"transparent",color:E===(t==null?void 0:t.name)?"white":"var(--color-muted)",border:"1px solid var(--color-border)",padding:"8px 16px",fontSize:"14px",height:"36px",cursor:E===(t==null?void 0:t.name)?"pointer":"not-allowed",opacity:E===(t==null?void 0:t.name)?1:.6,marginTop:"12px"},children:y?e.jsx(Ie,{size:12}):"Delete Forever"})]})]})]})]}),_&&e.jsx("div",{style:{position:"fixed",bottom:"24px",left:"50%",transform:"translateX(-50%)",background:"var(--color-success-background)",color:"var(--color-success)",padding:"var(--space-sm) var(--space-lg)",borderRadius:"var(--radius-lg)",boxShadow:"0 4px 12px var(--color-shadow)",display:"flex",alignItems:"center",gap:"var(--space-xs)",fontSize:"var(--font-xs)",fontWeight:500,zIndex:1e3,animation:"slideUp 0.3s ease-out"},children:"✓ Changes saved automatically"}),e.jsx("style",{children:`
|
|
3435
3435
|
@keyframes slideUp {
|
|
3436
3436
|
from {
|
|
3437
3437
|
opacity: 0;
|
|
@@ -3793,7 +3793,7 @@ cursor: pointer;
|
|
|
3793
3793
|
height: 16px;
|
|
3794
3794
|
background: var(--color-border);
|
|
3795
3795
|
border-radius: 2px;
|
|
3796
|
-
`,ud=({showPersonal:t=!0})=>{var pe,U,
|
|
3796
|
+
`,ud=({showPersonal:t=!0})=>{var pe,U,le,Q;const[r,o]=i.useState(!1),[n,s]=i.useState(!1),[a,h]=i.useState(new Set),g=i.useRef(null),c=i.useRef(null),u=sd({triggerRef:g,isOpen:r,minWidth:300}),d=Hr(!1),p=Hr(!1),x=Hr(!1),m=Hr(!1),[v,b]=i.useState(null),[_,k]=i.useState(!1),[C,z]=i.useState(null),{organizationMemberships:E,loading:w,refetch:y}=Mt(),{activeOrganization:f,activeMembership:$,leave:S}=nt(),{activeWorkspace:j,activeMembership:T,leave:R}=Ut(),{workspaces:O,loading:P}=Bt(),{session:M,loading:N,switchOrganization:D,switchWorkspace:L}=Ke(),{deployment:I}=ye(),{toast:A}=Je(),q=I==null?void 0:I.b2b_settings.organizations_enabled,Y=I==null?void 0:I.b2b_settings.workspaces_enabled,B=I==null?void 0:I.b2b_settings.allow_users_to_create_orgs,H=!((pe=M==null?void 0:M.active_signin)!=null&&pe.active_organization_membership_id),V=i.useMemo(()=>{var ne,me;if(H)return{name:"Personal account",image_url:(me=(ne=M==null?void 0:M.active_signin)==null?void 0:ne.user)==null?void 0:me.profile_picture_url,isPersonal:!0};let Z=(f==null?void 0:f.name)||"";return Y&&j&&(Z=`${f==null?void 0:f.name} / ${j.name}`),{name:Z,image_url:f==null?void 0:f.image_url,isPersonal:!1}},[H,f,j,M,Y]);i.useEffect(()=>{if(!r)return;let Z=null;const ne=setTimeout(()=>{const me=de=>{var W,F;const ee=de.target;(W=g.current)!=null&&W.contains(ee)||(F=c.current)!=null&&F.contains(ee)||(o(!1),z(null))};document.addEventListener("mousedown",me),Z=()=>{document.removeEventListener("mousedown",me)}},50);return()=>{clearTimeout(ne),Z==null||Z()}},[r]),i.useEffect(()=>{if(C){const Z=setTimeout(()=>{z(null)},5e3);return()=>clearTimeout(Z)}},[C]);const J=()=>{y()};if(!q)return null;const oe=Z=>{s(!0),D(Z).finally(()=>{s(!1)})},re=Z=>{s(!0),L(Z).finally(()=>{s(!1)})},fe=Z=>{const ne=new Set(a);ne.has(Z)?ne.delete(Z):ne.add(Z),h(ne)},X=Z=>Z.split(" ").map(ne=>ne[0]).join("").toUpperCase().slice(0,2),ue=!!((U=M==null?void 0:M.active_signin)!=null&&U.active_organization_membership_id);return w||N||!E&&ue?e.jsx(ge,{children:e.jsx($i,{children:e.jsxs(cv,{children:[e.jsxs(Ei,{children:[e.jsx(lv,{}),e.jsx(dv,{})]}),e.jsx(uv,{})]})})}):e.jsx(ge,{children:e.jsxs($i,{children:[e.jsxs(X0,{ref:g,onClick:()=>{o(!r),r||z(null)},disabled:n,children:[e.jsxs(Ei,{children:[e.jsx(ev,{children:V.image_url?e.jsx(tv,{src:V.image_url,alt:V.name}):V.isPersonal?e.jsx(qo,{size:12}):X(V.name)}),e.jsx(rv,{children:V.name})]}),e.jsx(bh,{size:16})]}),typeof window<"u"&&Qr.createPortal(e.jsx(ge,{children:e.jsx(ov,{ref:c,$isOpen:r,$position:u,children:w||P?e.jsxs(iv,{children:[e.jsxs(Eo,{children:[e.jsx(Io,{}),e.jsxs(Po,{children:[e.jsx(Ro,{width:"120px"}),e.jsx(Oi,{width:"80px"})]})]}),e.jsx(jr,{}),e.jsxs(Eo,{children:[e.jsx(Io,{}),e.jsx(Po,{children:e.jsx(Ro,{width:"100px"})})]}),e.jsx(jr,{}),e.jsxs(Eo,{children:[e.jsx(Io,{}),e.jsxs(Po,{children:[e.jsx(Ro,{width:"140px"}),e.jsx(Oi,{width:"60px"})]})]}),e.jsx(jr,{}),e.jsxs(Eo,{children:[e.jsx(Io,{}),e.jsx(Po,{children:e.jsx(Ro,{width:"110px"})})]})]}):e.jsxs("div",{children:[t&&e.jsxs(e.Fragment,{children:[e.jsxs(Uo,{as:"button",$isActive:H,onClick:Z=>{Z.stopPropagation(),H||oe()},disabled:n||H,children:[H&&e.jsx(zo,{}),e.jsxs(zt,{children:[e.jsx(nv,{children:(Q=(le=M==null?void 0:M.active_signin)==null?void 0:le.user)!=null&&Q.profile_picture_url?e.jsx(sv,{src:M.active_signin.user.profile_picture_url,alt:"Personal account"}):e.jsx(qo,{size:12})}),e.jsx($t,{children:e.jsx(Et,{children:"Personal account"})})]}),!H&&e.jsx(Co,{className:"hover-arrow",size:14})]}),!H&&f&&e.jsx(jr,{})]}),!H&&f&&e.jsxs(Uo,{$isActive:!0,onClick:()=>{Y&&fe(f.id)},style:n?{pointerEvents:"none",opacity:.7}:void 0,children:[e.jsx(zo,{}),e.jsxs(zt,{children:[Y&&e.jsx(Ft,{size:12,style:{marginRight:"4px",transform:a.has(f.id)?"rotate(0deg)":"rotate(-90deg)",transition:"transform 0.2s ease",color:"var(--color-secondary-text)"}}),e.jsx(Ii,{children:f.image_url?e.jsx(Pi,{src:f.image_url,alt:f.name}):X(f.name)}),e.jsx($t,{children:e.jsx(Et,{children:f.name})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[dd($)&&e.jsx(Wo,{onClick:Z=>{Z.stopPropagation(),p.open()},title:"Manage organization",children:e.jsx(ur,{size:12})}),e.jsx(Xn,{onClick:async Z=>{Z.stopPropagation(),k(!0),z(null);try{await S(),await y(),setTimeout(()=>{k(!1)},500)}catch(ne){z(ne instanceof Error?ne.message:"Failed to leave organization"),k(!1)}},disabled:_,title:"Leave organization",children:e.jsx(Dt,{size:12})})]})]}),f&&Y&&a.has(f.id)&&e.jsxs(e.Fragment,{children:[O==null?void 0:O.filter(Z=>Z.organization.id===f.id).map(Z=>{const ne=(j==null?void 0:j.id)===Z.id;return e.jsxs($o,{as:ne?void 0:"button",$isActive:ne,onClick:ne?void 0:()=>re(Z.id),...ne?{style:n?{pointerEvents:"none",opacity:.7}:void 0}:{disabled:n},children:[ne&&e.jsx(zo,{}),e.jsxs(zt,{children:[e.jsx(Ti,{children:Z.image_url?e.jsx("img",{src:Z.image_url,alt:Z.name,style:{width:"100%",height:"100%",objectFit:"cover"}}):X(Z.name).charAt(0)}),e.jsx($t,{children:e.jsx(Et,{children:Z.name})})]}),ne?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[zs(T)&&e.jsx(Wo,{onClick:me=>{me.stopPropagation(),m.open()},title:"Manage workspace",children:e.jsx(ur,{size:12})}),e.jsx(Xn,{onClick:async me=>{me.stopPropagation();try{R&&await R()}catch(de){const ee=de.message||"Failed to leave workspace. Please try again.";A(ee,"error")}},title:"Leave workspace",children:e.jsx(Dt,{size:12})})]}):e.jsx(Co,{className:"hover-arrow",size:14})]},Z.id)}),e.jsx($o,{as:"button",onClick:()=>{b(f.id),x.open()},disabled:n,children:e.jsxs(zt,{children:[e.jsx(So,{style:{width:"14px",height:"14px"},children:e.jsx(at,{size:12})}),e.jsx($t,{children:e.jsx(Et,{children:"Create workspace"})})]})})]}),(_||C)&&e.jsxs(e.Fragment,{children:[_&&e.jsxs(Mi,{children:[e.jsx(av,{}),"Leaving organization..."]}),C&&e.jsxs(Mi,{$isError:!0,children:[e.jsx("span",{children:"⚠️"}),C]})]}),e.jsx(jr,{}),E&&E.length>0&&e.jsx(e.Fragment,{children:E.filter(Z=>Z.organization.id!==(f==null?void 0:f.id)).map(Z=>{const ne=Z.organization,me=(O==null?void 0:O.filter(ee=>ee.organization.id===ne.id))||[],de=a.has(ne.id);return e.jsxs(i.Fragment,{children:[e.jsxs(Uo,{as:"button",$isActive:!1,onClick:()=>{Y?fe(ne.id):oe(ne.id)},disabled:n,children:[e.jsxs(zt,{children:[Y&&e.jsx(Ft,{size:12,style:{marginRight:"4px",transform:de?"rotate(0deg)":"rotate(-90deg)",transition:"transform 0.2s ease",color:"var(--color-secondary-text)"}}),e.jsx(Ii,{children:ne.image_url?e.jsx(Pi,{src:ne.image_url,alt:ne.name}):X(ne.name)}),e.jsx($t,{children:e.jsx(Et,{children:ne.name})})]}),e.jsx(Co,{className:"hover-arrow",size:14})]}),Y&&de&&e.jsxs(e.Fragment,{children:[me.map(ee=>{const W=(j==null?void 0:j.id)===ee.id;return e.jsxs($o,{as:W?void 0:"button",$isActive:W,onClick:W?void 0:()=>re(ee.id),...W?{style:n?{pointerEvents:"none",opacity:.7}:void 0}:{disabled:n},children:[W&&e.jsx(zo,{}),e.jsxs(zt,{children:[e.jsx(Ti,{children:ee.image_url?e.jsx("img",{src:ee.image_url,alt:ee.name,style:{width:"100%",height:"100%",objectFit:"cover"}}):X(ee.name).charAt(0)}),e.jsx($t,{children:e.jsx(Et,{children:ee.name})})]}),W?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[zs(T)&&e.jsx(Wo,{onClick:F=>{F.stopPropagation(),m.open()},title:"Manage workspace",children:e.jsx(ur,{size:12})}),e.jsx(Xn,{onClick:async F=>{F.stopPropagation();try{R&&await R()}catch(se){const be=se.message||"Failed to leave workspace. Please try again.";A(be,"error")}},title:"Leave workspace",children:e.jsx(Dt,{size:12})})]}):e.jsx(Co,{className:"hover-arrow",size:16})]},ee.id)}),e.jsx($o,{as:"button",onClick:()=>{b(ne.id),x.open()},disabled:n,children:e.jsxs(zt,{children:[e.jsx(So,{style:{width:"14px",height:"14px"},children:e.jsx(at,{size:10})}),e.jsx($t,{children:e.jsx(Et,{children:"Create workspace"})})]})})]}),e.jsx(jr,{})]},ne.id)})}),Y?f&&e.jsx(Ri,{onClick:()=>{b(f.id),x.open()},disabled:n,children:e.jsxs(zt,{children:[e.jsx(So,{children:e.jsx(at,{size:12})}),e.jsx($t,{children:e.jsx(Et,{children:"Create workspace"})})]})}):B&&e.jsx(Ri,{onClick:()=>{d.open()},disabled:n,children:e.jsxs(zt,{children:[e.jsx(So,{children:e.jsx(at,{size:12})}),e.jsx($t,{children:e.jsx(Et,{children:"Create organization"})})]})})]})})}),document.body),q&&B&&e.jsx(xx,{isOpen:d.isOpen,onClose:d.close,onCreated:J}),e.jsx(n0,{isOpen:p.isOpen,onClose:p.close}),e.jsx(nd,{isOpen:m.isOpen,onClose:m.close}),v&&e.jsx(td,{isOpen:x.isOpen,onClose:()=>{x.close(),b(null)},organizationId:v})]})})};var pv=Object.defineProperty,Qo=Object.getOwnPropertySymbols,pd=Object.prototype.hasOwnProperty,hd=Object.prototype.propertyIsEnumerable,Ai=(t,r,o)=>r in t?pv(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,$s=(t,r)=>{for(var o in r||(r={}))pd.call(r,o)&&Ai(t,o,r[o]);if(Qo)for(var o of Qo(r))hd.call(r,o)&&Ai(t,o,r[o]);return t},Es=(t,r)=>{var o={};for(var n in t)pd.call(t,n)&&r.indexOf(n)<0&&(o[n]=t[n]);if(t!=null&&Qo)for(var n of Qo(t))r.indexOf(n)<0&&hd.call(t,n)&&(o[n]=t[n]);return o};/**
|
|
3797
3797
|
* @license QR Code generator library (TypeScript)
|
|
3798
3798
|
* Copyright (c) Project Nayuki.
|
|
3799
3799
|
* SPDX-License-Identifier: MIT
|
|
@@ -3840,7 +3840,7 @@ cursor: pointer;
|
|
|
3840
3840
|
justify-content: center;
|
|
3841
3841
|
color: var(--color-muted);
|
|
3842
3842
|
flex-shrink: 0;
|
|
3843
|
-
`,Ni=({onClose:t,onAddEmail:r,onAttemptVerification:o,onPrepareVerification:n,existingEmail:s,triggerRef:a})=>{const h=i.useRef(null),[g,c]=i.useState(!1),[u,d]=i.useState({top:0,left:0}),{toast:p}=Ht();i.useEffect(()=>{c(!0);const y=setTimeout(()=>{if(!h.current||!(a!=null&&a.current))return;const S=a.current;if(S){const j=S.getBoundingClientRect(),T=380,R=300,O=8;let P=0,M=0;const N=window.innerHeight-j.bottom,D=j.top;N>=R+O?(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):D>=R+O?(P=j.top-R-O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left)),d({top:P,left:M})}},10),f=S=>{h.current&&!h.current.contains(S.target)&&t()},$=S=>{S.key==="Escape"&&t()};return document.addEventListener("mousedown",f),document.addEventListener("keydown",$),()=>{clearTimeout(y),document.removeEventListener("mousedown",f),document.removeEventListener("keydown",$)}},[t,a]);const[x,m]=i.useState(s?"otp":"email"),[v,b]=i.useState(s||""),[_,k]=i.useState(""),[C,z]=i.useState(!1),E=async()=>{if(!(!v||C)){z(!0);try{await r(v),m("otp")}catch(y){const f=y.message||"Failed to add email address. Please try again.";p(f,"error")}finally{z(!1)}}},w=async()=>{z(!0);try{await o(_),t()}catch(y){const f=y.message||"Failed to verify email. Please check the code and try again.";p(f,"error")}finally{z(!1)}};return g?e.jsx(wv,{ref:h,style:{top:`${u.top}px`,left:`${u.left}px`,visibility:u.top>0?"visible":"hidden"},onClick:y=>y.stopPropagation(),children:x==="email"?e.jsxs(e.Fragment,{children:[e.jsx(Di,{children:"Add email address"}),e.jsx(he,{children:e.jsxs(jv,{children:[e.jsx(_v,{children:e.jsx(dn,{size:16})}),e.jsx(
|
|
3843
|
+
`,Ni=({onClose:t,onAddEmail:r,onAttemptVerification:o,onPrepareVerification:n,existingEmail:s,triggerRef:a})=>{const h=i.useRef(null),[g,c]=i.useState(!1),[u,d]=i.useState({top:0,left:0}),{toast:p}=Ht();i.useEffect(()=>{c(!0);const y=setTimeout(()=>{if(!h.current||!(a!=null&&a.current))return;const S=a.current;if(S){const j=S.getBoundingClientRect(),T=380,R=300,O=8;let P=0,M=0;const N=window.innerHeight-j.bottom,D=j.top;N>=R+O?(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):D>=R+O?(P=j.top-R-O,M=j.right-T,M<O&&(M=j.left,M+T>window.innerWidth-O&&(M=(window.innerWidth-T)/2))):(P=j.bottom+O,M=j.right-T,M<O&&(M=j.left)),d({top:P,left:M})}},10),f=S=>{h.current&&!h.current.contains(S.target)&&t()},$=S=>{S.key==="Escape"&&t()};return document.addEventListener("mousedown",f),document.addEventListener("keydown",$),()=>{clearTimeout(y),document.removeEventListener("mousedown",f),document.removeEventListener("keydown",$)}},[t,a]);const[x,m]=i.useState(s?"otp":"email"),[v,b]=i.useState(s||""),[_,k]=i.useState(""),[C,z]=i.useState(!1),E=async()=>{if(!(!v||C)){z(!0);try{await r(v),m("otp")}catch(y){const f=y.message||"Failed to add email address. Please try again.";p(f,"error")}finally{z(!1)}}},w=async()=>{z(!0);try{await o(_),t()}catch(y){const f=y.message||"Failed to verify email. Please check the code and try again.";p(f,"error")}finally{z(!1)}};return g?e.jsx(wv,{ref:h,style:{top:`${u.top}px`,left:`${u.left}px`,visibility:u.top>0?"visible":"hidden"},onClick:y=>y.stopPropagation(),children:x==="email"?e.jsxs(e.Fragment,{children:[e.jsx(Di,{children:"Add email address"}),e.jsx(he,{children:e.jsxs(jv,{children:[e.jsx(_v,{children:e.jsx(dn,{size:16})}),e.jsx(ce,{id:"email-input",type:"email",placeholder:"Email address",value:v,onChange:y=>b(y.target.value),style:{flex:1}})]})}),e.jsxs(Li,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto",padding:"0 var(--space-md)"},children:"Cancel"}),e.jsx(K,{onClick:E,disabled:!v||C,style:{width:"auto",padding:"0 var(--space-md)"},children:C?"Adding...":"Continue"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Di,{children:"Verify your email"}),e.jsxs("div",{style:{fontSize:"14px",color:"var(--color-muted)",marginBottom:"16px"},children:["Enter the 6-digit code sent to ",v]}),e.jsx(Gt,{onComplete:async y=>k(y),onResend:n,isSubmitting:C}),e.jsxs(Li,{children:[e.jsx(K,{$outline:!0,onClick:()=>m("email"),style:{width:"auto",padding:"0 var(--space-md)"},children:"Back"}),e.jsx(K,{onClick:w,disabled:_.length<6||C,style:{width:"auto",padding:"0 var(--space-md)"},children:C?"Verifying...":"Verify"})]})]})}):null},kv=l.div`
|
|
3844
3844
|
position: fixed;
|
|
3845
3845
|
background: var(--color-background);
|
|
3846
3846
|
border-radius: var(--radius-md);
|
|
@@ -3907,7 +3907,7 @@ cursor: pointer;
|
|
|
3907
3907
|
font-weight: 400;
|
|
3908
3908
|
color: var(--color-foreground);
|
|
3909
3909
|
margin-bottom: 8px;
|
|
3910
|
-
`,Sv=({onClose:t,onSetupTOTP:r,onVerifyTOTP:o,triggerRef:n})=>{const s=i.useRef(null),[a,h]=i.useState("qr"),[g,c]=i.useState(""),[u,d]=i.useState(""),[p,x]=i.useState(["",""]),[m,v]=i.useState(!1),[b,_]=i.useState(!1),[k,C]=i.useState({top:0,left:0}),{toast:z}=Ht();i.useEffect(()=>{_(!0);const w=setTimeout(()=>{if(!s.current||!(n!=null&&n.current))return;const $=n.current;if($){const S=$.getBoundingClientRect(),j=380,T=400,R=8;let O=0,P=0;const M=window.innerHeight-S.bottom,N=S.top;M>=T+R?(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):N>=T+R?(O=S.top-T-R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left)),C({top:O,left:P})}},10),y=$=>{s.current&&!s.current.contains($.target)&&t()},f=$=>{$.key==="Escape"&&t()};return document.addEventListener("mousedown",y),document.addEventListener("keydown",f),()=>{clearTimeout(w),document.removeEventListener("mousedown",y),document.removeEventListener("keydown",f)}},[t,n]),i.useEffect(()=>{(async()=>{v(!0);try{const y=await r();c(y.otp_url||""),d(y.totp_secret||"")}catch(y){const f=y.message||"Failed to setup two-factor authentication. Please try again.";z(f,"error")}finally{v(!1)}})()},[]);const E=async()=>{if(!p.some(w=>w.length!==6)){v(!0);try{await o(p),t()}catch(w){const y=w.message||"Failed to verify codes. Please check your authenticator app and try again.";z(y,"error")}finally{v(!1)}}};return b?e.jsx(Cv,{ref:s,style:{top:`${k.top}px`,left:`${k.left}px`,visibility:k.top>0?"visible":"hidden"},onClick:w=>w.stopPropagation(),children:a==="qr"?e.jsxs(e.Fragment,{children:[e.jsx(Vi,{children:"Setup Two-Factor Authentication"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-muted)",marginBottom:"16px"},children:"Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.)"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"16px"},children:m?e.jsx("div",{style:{width:"150px",height:"150px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:"var(--color-input-background)"},children:"Loading..."}):g?e.jsx("div",{style:{border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"8px",background:"white"},children:e.jsx(qs,{value:g,size:150,title:"QR Code for Two-Factor Authentication Setup","aria-label":"Scan this QR code with your authenticator app to set up two-factor authentication"})}):e.jsx("div",{style:{width:"150px",height:"150px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:"var(--color-input-background)",color:"var(--color-error)"},children:"QR Code Not Available"})}),u&&e.jsxs("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"8px",marginBottom:"16px",fontSize:"12px"},children:[e.jsx("div",{style:{color:"var(--color-secondary-text)",marginBottom:"4px"},children:"Or enter manually:"}),e.jsx("code",{style:{fontFamily:"monospace",wordBreak:"break-all",color:"var(--color-secondary-text)"},children:u})]}),e.jsx(Wi,{children:e.jsx(es,{$primary:!0,onClick:()=>h("verify"),disabled:m||!g,children:"I've Scanned the Code"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Vi,{children:"Verify Your Authenticator"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-muted)",marginBottom:"16px"},children:"Enter two consecutive codes from your authenticator app"}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:[e.jsx(
|
|
3910
|
+
`,Sv=({onClose:t,onSetupTOTP:r,onVerifyTOTP:o,triggerRef:n})=>{const s=i.useRef(null),[a,h]=i.useState("qr"),[g,c]=i.useState(""),[u,d]=i.useState(""),[p,x]=i.useState(["",""]),[m,v]=i.useState(!1),[b,_]=i.useState(!1),[k,C]=i.useState({top:0,left:0}),{toast:z}=Ht();i.useEffect(()=>{_(!0);const w=setTimeout(()=>{if(!s.current||!(n!=null&&n.current))return;const $=n.current;if($){const S=$.getBoundingClientRect(),j=380,T=400,R=8;let O=0,P=0;const M=window.innerHeight-S.bottom,N=S.top;M>=T+R?(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):N>=T+R?(O=S.top-T-R,P=S.right-j,P<R&&(P=S.left,P+j>window.innerWidth-R&&(P=(window.innerWidth-j)/2))):(O=S.bottom+R,P=S.right-j,P<R&&(P=S.left)),C({top:O,left:P})}},10),y=$=>{s.current&&!s.current.contains($.target)&&t()},f=$=>{$.key==="Escape"&&t()};return document.addEventListener("mousedown",y),document.addEventListener("keydown",f),()=>{clearTimeout(w),document.removeEventListener("mousedown",y),document.removeEventListener("keydown",f)}},[t,n]),i.useEffect(()=>{(async()=>{v(!0);try{const y=await r();c(y.otp_url||""),d(y.totp_secret||"")}catch(y){const f=y.message||"Failed to setup two-factor authentication. Please try again.";z(f,"error")}finally{v(!1)}})()},[]);const E=async()=>{if(!p.some(w=>w.length!==6)){v(!0);try{await o(p),t()}catch(w){const y=w.message||"Failed to verify codes. Please check your authenticator app and try again.";z(y,"error")}finally{v(!1)}}};return b?e.jsx(Cv,{ref:s,style:{top:`${k.top}px`,left:`${k.left}px`,visibility:k.top>0?"visible":"hidden"},onClick:w=>w.stopPropagation(),children:a==="qr"?e.jsxs(e.Fragment,{children:[e.jsx(Vi,{children:"Setup Two-Factor Authentication"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-muted)",marginBottom:"16px"},children:"Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.)"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"16px"},children:m?e.jsx("div",{style:{width:"150px",height:"150px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:"var(--color-input-background)"},children:"Loading..."}):g?e.jsx("div",{style:{border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"8px",background:"white"},children:e.jsx(qs,{value:g,size:150,title:"QR Code for Two-Factor Authentication Setup","aria-label":"Scan this QR code with your authenticator app to set up two-factor authentication"})}):e.jsx("div",{style:{width:"150px",height:"150px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:"var(--color-input-background)",color:"var(--color-error)"},children:"QR Code Not Available"})}),u&&e.jsxs("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"8px",marginBottom:"16px",fontSize:"12px"},children:[e.jsx("div",{style:{color:"var(--color-secondary-text)",marginBottom:"4px"},children:"Or enter manually:"}),e.jsx("code",{style:{fontFamily:"monospace",wordBreak:"break-all",color:"var(--color-secondary-text)"},children:u})]}),e.jsx(Wi,{children:e.jsx(es,{$primary:!0,onClick:()=>h("verify"),disabled:m||!g,children:"I've Scanned the Code"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Vi,{children:"Verify Your Authenticator"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-muted)",marginBottom:"16px"},children:"Enter two consecutive codes from your authenticator app"}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:[e.jsx(ce,{id:"totp-code-1",type:"text",placeholder:"000000",value:p[0],onChange:w=>{const y=w.target.value.replace(/[^0-9]/g,"").substring(0,6);x([y,p[1]])},maxLength:6,style:{textAlign:"center",fontFamily:"monospace"},"aria-label":"First verification code from authenticator app"}),e.jsx(ce,{id:"totp-code-2",type:"text",placeholder:"000000",value:p[1],onChange:w=>{const y=w.target.value.replace(/[^0-9]/g,"").substring(0,6);x([p[0],y])},maxLength:6,style:{textAlign:"center",fontFamily:"monospace"},"aria-label":"Second verification code from authenticator app"})]}),e.jsxs(Wi,{children:[e.jsx(es,{onClick:()=>h("qr"),children:"Back"}),e.jsx(es,{$primary:!0,onClick:E,disabled:m||p.some(w=>w.length!==6),children:m?"Verifying...":"Verify"})]})]})}):null},zv=l.div`
|
|
3911
3911
|
position: fixed;
|
|
3912
3912
|
background: var(--color-background);
|
|
3913
3913
|
border-radius: var(--radius-md);
|
|
@@ -3977,7 +3977,7 @@ cursor: pointer;
|
|
|
3977
3977
|
color: var(--color-error);
|
|
3978
3978
|
font-size: 12px;
|
|
3979
3979
|
margin-top: 4px;
|
|
3980
|
-
`,Hi=({onClose:t,onChangePassword:r,triggerRef:o,isSetup:n=!1})=>{const s=i.useRef(null),[a,h]=i.useState(!1),[g,c]=i.useState({top:0,left:0}),[u,d]=i.useState(""),[p,x]=i.useState(""),[m,v]=i.useState(""),[b,_]=i.useState(!1),[k,C]=i.useState(!1),[z,E]=i.useState(!1),[w,y]=i.useState(!1),[f,$]=i.useState({});i.useEffect(()=>{h(!0);const j=setTimeout(()=>{if(!s.current||!(o!=null&&o.current))return;const O=o.current;if(O){const P=O.getBoundingClientRect(),M=380,N=350,D=8;let L=0,I=0;const A=window.innerHeight-P.bottom,q=P.top;A>=N+D?(L=P.bottom+D,I=P.right-M,I<D&&(I=P.left,I+M>window.innerWidth-D&&(I=(window.innerWidth-M)/2))):q>=N+D?(L=P.top-N-D,I=P.right-M,I<D&&(I=P.left,I+M>window.innerWidth-D&&(I=(window.innerWidth-M)/2))):(L=P.bottom+D,I=P.right-M,I<D&&(I=P.left)),c({top:L,left:I})}},10),T=O=>{s.current&&!s.current.contains(O.target)&&t()},R=O=>{O.key==="Escape"&&t()};return document.addEventListener("mousedown",T),document.addEventListener("keydown",R),()=>{clearTimeout(j),document.removeEventListener("mousedown",T),document.removeEventListener("keydown",R)}},[t,o]);const S=async()=>{if(w)return;const j={};if(!n&&!u&&(j.currentPassword="Current password is required"),p?p.length<8&&(j.newPassword="Password must be at least 8 characters"):j.newPassword="New password is required",p!==m&&(j.confirmPassword="Passwords do not match"),Object.keys(j).length>0){$(j);return}y(!0);try{await r(n?"":u,p),t()}catch(T){$({form:T.message||"Failed to update password"})}finally{y(!1)}};return a?e.jsxs(zv,{ref:s,style:{top:`${g.top}px`,left:`${g.left}px`,visibility:g.top>0?"visible":"hidden"},onClick:j=>j.stopPropagation(),children:[e.jsx(Ev,{children:n?"Set Password":"Change Password"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-muted)",marginBottom:"16px"},children:n?"Set a password for your account to enable password authentication.":"Update your account password to keep it secure."}),!n&&e.jsxs(ts,{children:[e.jsx(
|
|
3980
|
+
`,Hi=({onClose:t,onChangePassword:r,triggerRef:o,isSetup:n=!1})=>{const s=i.useRef(null),[a,h]=i.useState(!1),[g,c]=i.useState({top:0,left:0}),[u,d]=i.useState(""),[p,x]=i.useState(""),[m,v]=i.useState(""),[b,_]=i.useState(!1),[k,C]=i.useState(!1),[z,E]=i.useState(!1),[w,y]=i.useState(!1),[f,$]=i.useState({});i.useEffect(()=>{h(!0);const j=setTimeout(()=>{if(!s.current||!(o!=null&&o.current))return;const O=o.current;if(O){const P=O.getBoundingClientRect(),M=380,N=350,D=8;let L=0,I=0;const A=window.innerHeight-P.bottom,q=P.top;A>=N+D?(L=P.bottom+D,I=P.right-M,I<D&&(I=P.left,I+M>window.innerWidth-D&&(I=(window.innerWidth-M)/2))):q>=N+D?(L=P.top-N-D,I=P.right-M,I<D&&(I=P.left,I+M>window.innerWidth-D&&(I=(window.innerWidth-M)/2))):(L=P.bottom+D,I=P.right-M,I<D&&(I=P.left)),c({top:L,left:I})}},10),T=O=>{s.current&&!s.current.contains(O.target)&&t()},R=O=>{O.key==="Escape"&&t()};return document.addEventListener("mousedown",T),document.addEventListener("keydown",R),()=>{clearTimeout(j),document.removeEventListener("mousedown",T),document.removeEventListener("keydown",R)}},[t,o]);const S=async()=>{if(w)return;const j={};if(!n&&!u&&(j.currentPassword="Current password is required"),p?p.length<8&&(j.newPassword="Password must be at least 8 characters"):j.newPassword="New password is required",p!==m&&(j.confirmPassword="Passwords do not match"),Object.keys(j).length>0){$(j);return}y(!0);try{await r(n?"":u,p),t()}catch(T){$({form:T.message||"Failed to update password"})}finally{y(!1)}};return a?e.jsxs(zv,{ref:s,style:{top:`${g.top}px`,left:`${g.left}px`,visibility:g.top>0?"visible":"hidden"},onClick:j=>j.stopPropagation(),children:[e.jsx(Ev,{children:n?"Set Password":"Change Password"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-muted)",marginBottom:"16px"},children:n?"Set a password for your account to enable password authentication.":"Update your account password to keep it secure."}),!n&&e.jsxs(ts,{children:[e.jsx(ie,{children:"Current Password"}),e.jsxs(rs,{children:[e.jsx(ce,{type:b?"text":"password",placeholder:"Enter your current password",value:u,onChange:j=>d(j.target.value),style:{paddingRight:"40px"}}),e.jsx("button",{type:"button",onClick:()=>_(!b),"aria-label":b?"Hide current password":"Show current password",children:b?e.jsx(Rn,{size:16}):e.jsx(Tn,{size:16})})]}),f.currentPassword&&e.jsx(To,{children:f.currentPassword})]}),e.jsxs(ts,{children:[e.jsx(ie,{children:n?"Password":"New Password"}),e.jsxs(rs,{children:[e.jsx(ce,{type:k?"text":"password",placeholder:n?"Enter your password":"Enter your new password",value:p,onChange:j=>x(j.target.value),style:{paddingRight:"40px"}}),e.jsx("button",{type:"button",onClick:()=>C(!k),"aria-label":k?"Hide new password":"Show new password",children:k?e.jsx(Rn,{size:16}):e.jsx(Tn,{size:16})})]}),f.newPassword&&e.jsx(To,{children:f.newPassword})]}),e.jsxs(ts,{children:[e.jsx(ie,{children:"Confirm New Password"}),e.jsxs(rs,{children:[e.jsx(ce,{type:z?"text":"password",placeholder:"Confirm your new password",value:m,onChange:j=>v(j.target.value),style:{paddingRight:"40px"}}),e.jsx("button",{type:"button",onClick:()=>E(!z),"aria-label":z?"Hide confirm password":"Show confirm password",children:z?e.jsx(Rn,{size:16}):e.jsx(Tn,{size:16})})]}),f.confirmPassword&&e.jsx(To,{children:f.confirmPassword})]}),f.form&&e.jsx(To,{children:f.form}),e.jsxs($v,{children:[e.jsx(Gi,{onClick:t,children:"Cancel"}),e.jsx(Gi,{$primary:!0,onClick:S,disabled:w,children:w?n?"Setting...":"Updating...":n?"Set Password":"Update Password"})]})]}):null},Iv=l.div`
|
|
3981
3981
|
position: fixed;
|
|
3982
3982
|
background: var(--color-background);
|
|
3983
3983
|
border-radius: var(--radius-md);
|
|
@@ -4015,7 +4015,7 @@ cursor: pointer;
|
|
|
4015
4015
|
color: var(--color-warning-text, var(--color-foreground));
|
|
4016
4016
|
margin: 0;
|
|
4017
4017
|
line-height: 1.5;
|
|
4018
|
-
`,Ov=({onClose:t,onRemovePassword:r,triggerRef:o})=>{const n=i.useRef(null),[s,a]=i.useState(!1),[h,g]=i.useState({top:0,left:0}),[c,u]=i.useState(""),[d,p]=i.useState(!1),{toast:x}=Ht();i.useEffect(()=>{a(!0);const v=setTimeout(()=>{if(!n.current||!(o!=null&&o.current))return;const k=o.current;if(k){const C=k.getBoundingClientRect(),z=400,E=300,w=8;let y=0,f=0;const $=window.innerHeight-C.bottom,S=C.top;$>=E+w?(y=C.bottom+w,f=C.right-z,f<w&&(f=C.left,f+z>window.innerWidth-w&&(f=(window.innerWidth-z)/2))):S>=E+w?(y=C.top-E-w,f=C.right-z,f<w&&(f=C.left,f+z>window.innerWidth-w&&(f=(window.innerWidth-z)/2))):(y=C.bottom+w,f=C.right-z,f<w&&(f=C.left)),g({top:y,left:f})}},10),b=k=>{n.current&&!n.current.contains(k.target)&&t()},_=k=>{k.key==="Escape"&&t()};return document.addEventListener("mousedown",b),document.addEventListener("keydown",_),()=>{clearTimeout(v),document.removeEventListener("mousedown",b),document.removeEventListener("keydown",_)}},[t,o]);const m=async()=>{if(!(!c||d)){p(!0);try{await r(c),t()}catch(v){const b=v.message||"Failed to remove password. Please try again.";x(b,"error")}finally{p(!1)}}};return s?e.jsxs(Iv,{ref:n,style:{top:`${h.top}px`,left:`${h.left}px`,visibility:h.top>0?"visible":"hidden"},onClick:v=>v.stopPropagation(),children:[e.jsxs(Rv,{children:[e.jsx(wt,{size:18,color:"var(--color-warning, #fbbf24)"}),"Remove Password"]}),e.jsx(Tv,{children:e.jsx(Mv,{children:"You're about to remove password authentication from your account. Make sure you have another way to sign in (email, phone, social login, or passkey) before continuing."})}),e.jsxs(he,{children:[e.jsx(
|
|
4018
|
+
`,Ov=({onClose:t,onRemovePassword:r,triggerRef:o})=>{const n=i.useRef(null),[s,a]=i.useState(!1),[h,g]=i.useState({top:0,left:0}),[c,u]=i.useState(""),[d,p]=i.useState(!1),{toast:x}=Ht();i.useEffect(()=>{a(!0);const v=setTimeout(()=>{if(!n.current||!(o!=null&&o.current))return;const k=o.current;if(k){const C=k.getBoundingClientRect(),z=400,E=300,w=8;let y=0,f=0;const $=window.innerHeight-C.bottom,S=C.top;$>=E+w?(y=C.bottom+w,f=C.right-z,f<w&&(f=C.left,f+z>window.innerWidth-w&&(f=(window.innerWidth-z)/2))):S>=E+w?(y=C.top-E-w,f=C.right-z,f<w&&(f=C.left,f+z>window.innerWidth-w&&(f=(window.innerWidth-z)/2))):(y=C.bottom+w,f=C.right-z,f<w&&(f=C.left)),g({top:y,left:f})}},10),b=k=>{n.current&&!n.current.contains(k.target)&&t()},_=k=>{k.key==="Escape"&&t()};return document.addEventListener("mousedown",b),document.addEventListener("keydown",_),()=>{clearTimeout(v),document.removeEventListener("mousedown",b),document.removeEventListener("keydown",_)}},[t,o]);const m=async()=>{if(!(!c||d)){p(!0);try{await r(c),t()}catch(v){const b=v.message||"Failed to remove password. Please try again.";x(b,"error")}finally{p(!1)}}};return s?e.jsxs(Iv,{ref:n,style:{top:`${h.top}px`,left:`${h.left}px`,visibility:h.top>0?"visible":"hidden"},onClick:v=>v.stopPropagation(),children:[e.jsxs(Rv,{children:[e.jsx(wt,{size:18,color:"var(--color-warning, #fbbf24)"}),"Remove Password"]}),e.jsx(Tv,{children:e.jsx(Mv,{children:"You're about to remove password authentication from your account. Make sure you have another way to sign in (email, phone, social login, or passkey) before continuing."})}),e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"current-password",children:"Confirm your current password"}),e.jsx(ce,{id:"current-password",type:"password",placeholder:"Enter current password",value:c,onChange:v=>u(v.target.value),autoFocus:!0})]}),e.jsxs(Pv,{children:[e.jsx(K,{$outline:!0,onClick:t,style:{width:"auto",padding:"0 var(--space-md)"},children:"Cancel"}),e.jsx(K,{onClick:m,disabled:!c||d,style:{width:"auto",padding:"0 var(--space-md)",background:"var(--color-error)",borderColor:"var(--color-error)"},children:d?"Removing...":"Remove Password"})]})]}):null},Av=l.div`
|
|
4019
4019
|
position: fixed;
|
|
4020
4020
|
background: var(--color-background);
|
|
4021
4021
|
border-radius: var(--radius-md);
|
|
@@ -4231,9 +4231,9 @@ cursor: pointer;
|
|
|
4231
4231
|
flex-shrink: 0;
|
|
4232
4232
|
display: block;
|
|
4233
4233
|
}
|
|
4234
|
-
`,a1=()=>{const{user:t,disconnectSocialConnection:r,connectSocialAccount:o}=Wt(),{deployment:n}=ye(),s={google_oauth:{icon:e.jsx(kl,{}),label:"Google"},microsoft_oauth:{icon:e.jsx(Wv,{}),label:"Microsoft"},github_oauth:{icon:e.jsx(_l,{}),label:"GitHub"},gitlab_oauth:{icon:e.jsx(zl,{}),label:"GitLab"},linkedin_oauth:{icon:e.jsx(Sl,{}),label:"LinkedIn"},discord_oauth:{icon:e.jsx($l,{}),label:"Discord"},x_oauth:{icon:e.jsx(Cl,{}),label:"X"}},a=(n==null?void 0:n.social_connections.filter(h=>h.enabled))||[];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h3",{style:{fontSize:"16px",margin:"0 0 6px 0",letterSpacing:"-0.01em",color:"var(--color-foreground)"},children:"Connected Accounts"}),e.jsx("p",{style:{fontSize:"13px",margin:0,lineHeight:"1.5",color:"var(--color-muted)"},children:"Connect social accounts for easy sign-in and profile sync"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:a.map((h,g)=>{var d;const c=((d=t==null?void 0:t.social_connections)==null?void 0:d.filter(p=>p.provider===h.provider))||[],u=s[h.provider];return u?e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0",minHeight:"58px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:"var(--color-foreground)"},children:[e.jsx(kd,{children:u.icon}),e.jsx("div",{style:{fontSize:"14px",fontWeight:500},children:u.label})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-end",gap:"8px"},children:[c.map(p=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"6px",padding:"4px 8px",fontSize:"13px",color:"var(--color-muted)"},children:[e.jsx("span",{children:p.email_address}),e.jsx(gn,{onClick:async()=>{await r(p.id.toString()),t.refetch()},style:{padding:"2px"},children:e.jsx(ct,{size:14})})]},p.id)),c.length>0?e.jsx(K,{onClick:()=>{o({provider:h.provider,redirectUri:window.location.href})},style:{padding:"6px 24px",fontSize:"13px"},children:"Add"}):e.jsx(K,{onClick:()=>{o({provider:h.provider,redirectUri:window.location.href})},style:{padding:"6px 14px",fontSize:"13px"},children:"Connect"})]})]}),g<a.length-1&&e.jsx("div",{style:{height:"1px",background:"var(--color-border)"}})]},h.provider):null})})]})},Cd=()=>{var v,b,_,k,C,z,E;const{loading:t}=Wt(),{deployment:r}=ye(),[o,n]=i.useState("profile"),[s,a]=i.useState(null),[h,g]=i.useState("info"),c=i.useCallback((w,y="info")=>{a(w),g(y),setTimeout(()=>a(null),3e3)},[a]);if(t)return e.jsx(ge,{children:e.jsx(Yi,{style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(Ie,{})})});const u=r==null?void 0:r.auth_settings,d=(v=u==null?void 0:u.email_address)==null?void 0:v.enabled,p=(b=u==null?void 0:u.phone_number)==null?void 0:b.enabled,x=((_=r==null?void 0:r.social_connections)==null?void 0:_.some(w=>w.enabled))||!1,m=((k=u==null?void 0:u.password)==null?void 0:k.enabled)||((C=u==null?void 0:u.auth_factors_enabled)==null?void 0:C.authenticator)||((z=u==null?void 0:u.auth_factors_enabled)==null?void 0:z.phone_otp)||((E=u==null?void 0:u.auth_factors_enabled)==null?void 0:E.backup_code);return e.jsx(ge,{children:e.jsx(Qv,{children:e.jsx(_d.Provider,{value:{screen:null,setScreen:()=>{},toast:c},children:e.jsxs(Yi,{children:[e.jsx(Jv,{children:e.jsxs(Xv,{children:[e.jsx(_r,{$isActive:o==="profile",onClick:()=>n("profile"),children:e.jsxs(kr,{children:[e.jsx(qo,{size:16}),"Profile"]})}),d&&e.jsx(_r,{$isActive:o==="email",onClick:()=>n("email"),children:e.jsxs(kr,{children:[e.jsx(dn,{size:16}),"Email"]})}),p&&e.jsx(_r,{$isActive:o==="phone",onClick:()=>n("phone"),children:e.jsxs(kr,{children:[e.jsx(Bh,{size:16}),"Phone"]})}),x&&e.jsx(_r,{$isActive:o==="social",onClick:()=>n("social"),children:e.jsxs(kr,{children:[e.jsx(Ph,{size:16}),"Connections"]})}),m&&e.jsx(_r,{$isActive:o==="security",onClick:()=>n("security"),children:e.jsxs(kr,{children:[e.jsx(ut,{size:16}),"Security"]})}),e.jsx(_r,{$isActive:o==="sessions",onClick:()=>n("sessions"),children:e.jsxs(kr,{children:[e.jsx(nh,{size:16}),"Sessions"]})})]})}),e.jsxs(e1,{children:[o==="profile"&&e.jsx(c1,{}),o==="email"&&d&&e.jsx(n1,{}),o==="phone"&&p&&e.jsx(s1,{}),o==="social"&&x&&e.jsx(a1,{}),o==="security"&&m&&e.jsx(i1,{}),o==="sessions"&&e.jsx(o1,{})]}),s&&e.jsx("div",{style:{position:"absolute",bottom:"20px",right:"20px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"8px",padding:"12px 16px",boxShadow:"0 4px 12px var(--color-shadow)",animation:"slideUp 0.3s ease-out"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h==="error"?e.jsx(wt,{size:16,color:"var(--color-error)"}):e.jsx(et,{size:16,color:"var(--color-success)"}),e.jsx("span",{style:{fontSize:"14px",color:"var(--color-foreground)"},children:s})]})})]})})})})},i1=()=>{var mn,Zs,Ks,Qs,Js,Xs,ea;const{deployment:t}=ye(),{user:r,updatePassword:o,removePassword:n,setupAuthenticator:s,verifyAuthenticator:a,deleteAuthenticator:h,generateBackupCodes:g,regenerateBackupCodes:c,updateProfile:u,getPasskeys:d,registerPasskey:p,deletePasskey:x}=Wt(),{toast:m}=Ht(),[v,b]=i.useState((r==null?void 0:r.second_factor_policy)||"none"),[_,k]=i.useState(!1),C=async
|
|
4235
|
-
`);navigator.clipboard.writeText(
|
|
4236
|
-
`),Ue=new Blob([de],{type:"text/plain"}),Be=URL.createObjectURL(Ue),Xe=document.createElement("a");Xe.href=Be,Xe.download="wacht-backup-codes.txt",Xe.click(),URL.revokeObjectURL(Be),m("Backup codes downloaded","info")},_e=async()=>{var de,Ue;if((Ue=(de=t==null?void 0:t.auth_settings)==null?void 0:de.passkey)!=null&&Ue.enabled)try{L(!0);const Be=await d();N(Be.data||[])}catch(Be){console.error("Failed to load passkeys:",Be)}finally{L(!1)}},Ce=async()=>{try{A(!0),await p(),await _e(),m("Passkey registered successfully!","info")}catch(de){m(de.message||"Failed to register passkey","error")}finally{A(!1)}},Pe=async de=>{try{await x(de),await _e(),m("Passkey removed","info")}catch(Ue){m(Ue.message||"Failed to remove passkey","error")}};i.useEffect(()=>{_e()},[(Js=(Qs=t==null?void 0:t.auth_settings)==null?void 0:Qs.passkey)==null?void 0:Js.enabled]);const Te=[];return F&&Te.push({id:"password",name:"Password",description:"Secure your account with a strong password",status:r!=null&&r.has_password?"Enabled":"Disabled",actions:r!=null&&r.has_password?["change"]:["setup"]}),(ea=(Xs=t==null?void 0:t.auth_settings)==null?void 0:Xs.passkey)!=null&&ea.enabled&&Te.push({id:"passkey",name:"Passkeys",description:"Sign in faster with fingerprint, face, or screen lock",status:M.length>0?`${M.length} registered`:"None",actions:M.length>0?["manage","add"]:["add"]}),W!=null&&W.authenticator&&Te.push({id:"authenticator",name:"Authenticator App",description:"Use an authenticator app for extra security",status:r!=null&&r.user_authenticator?"Enabled":"Disabled",actions:r!=null&&r.user_authenticator?["remove"]:["setup"]}),r!=null&&r.user_authenticator&&Te.push({id:"backup_codes",name:"Backup Codes",description:"Recovery codes if you lose your authenticator",status:r!=null&&r.backup_codes_generated?"Generated":"Not Generated",actions:["generate"]}),r!=null&&r.user_authenticator&&Te.push({id:"second_factor_policy",name:"Require 2FA",description:"Require a second factor for all sign-ins",status:v==="enforced"?"Enforced":"Optional",actions:["toggle"]}),B!=="table"?e.jsxs(e.Fragment,{children:[e.jsxs(Jo,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(ut,{size:16}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--color-foreground)"},children:[B==="qr"&&"Setup Two-Factor Authentication",B==="verify"&&"Verify Your Authenticator",B==="backup"&&"Save Your Backup Codes",B==="success"&&"Setup Complete!"]})]}),e.jsx(K,{onClick:()=>H("table"),style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",color:"var(--color-foreground)",fontWeight:"500",cursor:"pointer",transition:"all 0.2s ease"},children:"← Back"})]}),e.jsxs("div",{style:{maxWidth:"500px",margin:"0 auto",textAlign:"center",padding:"24px"},children:[B==="qr"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{color:"var(--color-secondary-text)",marginBottom:"24px"},children:"Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.)"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"24px"},children:me?e.jsx("div",{style:{width:"200px",height:"200px",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-input-background)"},children:e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{width:"24px",height:"24px",border:"2px solid var(--color-border)",borderTop:"2px solid var(--color-primary)",borderRadius:"50%",animation:`${Kv} 1s linear infinite`,margin:"0 auto 8px"}}),e.jsx("div",{style:{fontSize:"12px",color:"var(--color-secondary-text)"},children:"Loading QR Code..."})]})}):V?e.jsx("div",{style:{border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"16px",background:"white"},children:e.jsx(qs,{value:V,size:200,level:"M",marginSize:0})}):e.jsx("div",{style:{width:"200px",height:"200px",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-input-background)",color:"var(--color-error)",fontSize:"14px",textAlign:"center"},children:"QR Code Not Available"})}),e.jsxs("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"12px",marginBottom:"24px"},children:[e.jsx("p",{style:{fontSize:"14px",color:"var(--color-secondary-text)",margin:"0 0 8px 0"},children:"Or enter this code manually:"}),e.jsx("code",{style:{fontFamily:"monospace",fontSize:"14px",wordBreak:"break-all"},children:oe||"Loading..."})]}),e.jsx(K,{onClick:()=>H("verify"),disabled:!V||!oe,style:{padding:"10px 20px",background:!V||!oe?"var(--color-border)":"var(--color-primary)",color:!V||!oe?"var(--color-secondary-text)":"white",border:`1px solid ${!V||!oe?"var(--color-border)":"var(--color-primary)"}`,cursor:!V||!oe?"not-allowed":"pointer"},children:"I've Scanned the Code"})]}),B==="verify"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{color:"var(--color-secondary-text)",marginBottom:"24px"},children:"Enter two consecutive codes from your authenticator app to verify setup"}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center",marginBottom:"24px"},children:[e.jsx(ie,{type:"text",placeholder:"000000",value:ue[0],onChange:de=>{const Ue=de.target.value.replace(/[^0-9]/g,"").substring(0,6);ve([Ue,ue[1]])},maxLength:6,style:{width:"100px",textAlign:"center",fontFamily:"monospace"}}),e.jsx(ie,{type:"text",placeholder:"000000",value:ue[1],onChange:de=>{const Ue=de.target.value.replace(/[^0-9]/g,"").substring(0,6);ve([ue[0],Ue])},maxLength:6,style:{width:"100px",textAlign:"center",fontFamily:"monospace"}})]}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center"},children:[e.jsx(K,{onClick:()=>H("qr"),style:{padding:"8px 16px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:"Back"}),e.jsx(K,{onClick:Fe,disabled:Z||ue.some(de=>de.length!==6),style:{padding:"8px 16px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:Z?"Verifying...":"Verify & Continue"})]})]}),B==="backup"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{background:"var(--color-warning-background)",border:"1px solid var(--color-warning-border)",borderRadius:"var(--radius-md)",padding:"16px",marginBottom:"24px",display:"flex",alignItems:"flex-start",gap:"12px",textAlign:"left"},children:[e.jsx(wt,{size:16,style:{color:"var(--color-warning)",marginTop:"2px"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:"Important!"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-secondary-text)"},children:"Store these codes safely. Each code can only be used once if you lose access to your authenticator device."})]})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"8px",marginBottom:"24px",maxWidth:"300px",margin:"0 auto 24px auto"},children:pe.map((de,Ue)=>e.jsx("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"8px",fontFamily:"monospace",fontSize:"12px",textAlign:"center",cursor:"pointer"},onClick:()=>navigator.clipboard.writeText(de),children:de},Ue))}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center",marginBottom:"24px"},children:[e.jsx(K,{onClick:te,style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:"Copy All"}),e.jsxs(K,{onClick:xe,style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:[e.jsx(ln,{size:16,style:{marginRight:"4px"}}),"Download"]})]}),e.jsx(K,{onClick:Se,style:{padding:"10px 20px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:"Complete Setup"})]}),B==="success"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx(et,{size:48,style:{color:"var(--color-success)",marginBottom:"16px"}}),e.jsx("h3",{style:{fontSize:"18px",fontWeight:600,margin:"0 0 8px 0"},children:"All Set!"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-secondary-text)",margin:0},children:"Your account is now protected with two-factor authentication."})]}),e.jsx(K,{onClick:Se,style:{padding:"10px 20px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:"Continue to Security"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Jo,{children:e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--color-foreground)"},children:"Security Settings"})})}),Te.length?e.jsx("div",{children:Te.map((de,Ue)=>e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 0"},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:400,color:"var(--color-foreground)"},children:de.name}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-secondary-text)"},children:de.description})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[e.jsx("span",{style:{padding:"4px 12px",borderRadius:"16px",fontSize:"12px",fontWeight:400,background:de.status==="Enabled"||de.status==="Generated"?"var(--color-success-background)":"var(--color-background-hover)",color:de.status==="Enabled"||de.status==="Generated"?"var(--color-success)":"var(--color-secondary-text)"},children:de.status}),e.jsxs("div",{style:{position:"relative"},children:[de.id==="password"&&e.jsx(e.Fragment,{children:r!=null&&r.has_password?e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:R,onClick:()=>y(!0),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Change"}),w&&e.jsx(Hi,{triggerRef:R,onClose:()=>y(!1),onChangePassword:se})]}),Oe()&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:O,onClick:()=>$(!0),style:{padding:"6px 12px",fontSize:"12px",background:"transparent",color:"var(--color-error)",border:"1px solid var(--color-error)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Remove"}),f&&e.jsx(Ov,{triggerRef:O,onClose:()=>$(!1),onRemovePassword:be})]})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:R,onClick:()=>y(!0),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Setup"}),w&&e.jsx(Hi,{triggerRef:R,onClose:()=>y(!1),onChangePassword:se,isSetup:!0})]})}),de.id==="authenticator"&&!(r!=null&&r.user_authenticator)&&e.jsx(e.Fragment,{children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:T,onClick:()=>E(!0),disabled:me,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:me?"Setting up...":"Setup"}),z&&e.jsx(Sv,{triggerRef:T,onClose:()=>E(!1),onSetupTOTP:async()=>{const Be=await s();return X(Be.id),Be},onVerifyTOTP:async Be=>{await a(fe,Be),await r.refetch(),m("Two-factor authentication enabled successfully!","info")}})]})}),de.id==="authenticator"&&(r==null?void 0:r.user_authenticator)&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{onClick:()=>k(!0),disabled:le,style:{padding:"6px 16px",fontSize:"13px",background:"var(--color-error)",border:"1px solid var(--color-error)",color:"white",cursor:le?"not-allowed":"pointer",opacity:le?.6:1},children:le?"Removing...":"Remove"}),_&&e.jsx(to,{title:"Remove MFA and reset policy to default?",onConfirm:Ve,onCancel:()=>k(!1)})]}),de.id==="backup_codes"&&e.jsx(e.Fragment,{children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:P,onClick:Ae,disabled:ce,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:ce?"Generating...":r!=null&&r.backup_codes_generated?"Regenerate":"Generate"}),S&&e.jsx(Uv,{triggerRef:P,codes:pe,onClose:()=>j(!1),onCopy:te,onDownload:xe})]})}),de.id==="second_factor_policy"&&e.jsx(fr,{checked:v==="enforced",onChange:Be=>{C(Be?"enforced":"none")}}),de.id==="passkey"&&e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsxs(K,{onClick:()=>Y(!q),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",fontWeight:"400",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px"},children:[q?"Hide":"Manage"," (",M.length,")",e.jsx(Ft,{size:14,style:{transform:q?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s ease"}})]}),e.jsx(K,{onClick:Ce,disabled:I,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400",cursor:I?"not-allowed":"pointer",opacity:I?.7:1},children:I?"Registering...":"Add"})]})]})]})]}),de.id==="passkey"&&q&&e.jsx("div",{style:{padding:"12px 0",borderTop:"1px solid var(--color-border)",marginTop:"8px"},children:D?e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"16px"},children:e.jsx(Ie,{})}):M.length===0?e.jsx("div",{style:{textAlign:"center",padding:"16px",color:"var(--color-secondary-text)",fontSize:"13px"},children:"No passkeys registered yet"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:M.map(Be=>e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 12px",background:"var(--color-input-background)",borderRadius:"var(--radius-md)",border:"1px solid var(--color-border)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--color-foreground)"},children:Be.name||"Unnamed Passkey"}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--color-secondary-text)"},children:[Be.device_type==="platform"?"This device":"Security key",Be.last_used_at&&` • Last used ${new Date(Be.last_used_at).toLocaleDateString()}`]})]}),e.jsx(K,{onClick:()=>{confirm(`Remove "${Be.name||"Unnamed Passkey"}"?`)&&Pe(Be.id)},style:{padding:"4px 10px",fontSize:"12px",background:"transparent",border:"1px solid var(--color-error)",borderRadius:"var(--radius-md)",color:"var(--color-error)",cursor:"pointer"},children:"Remove"})]},Be.id))})}),Ue<Te.length-1&&e.jsx("div",{style:{height:"1px",background:"var(--color-border)",margin:"0"}})]},de.id))}):e.jsx(mt,{title:"No security features available",description:"Contact your administrator to enable security features."})]})},c1=()=>{var D,L;const{deployment:t}=ye(),{user:r,updateProfile:o,updateProfilePicture:n,deleteAccount:s}=Wt(),{toast:a}=Ht(),[h,g]=i.useState(""),[c,u]=i.useState(""),[d,p]=i.useState(""),[x,m]=i.useState(!1),[v,b]=i.useState(!1),[_,k]=i.useState(!1),[C,z]=i.useState(""),[E,w]=i.useState((r==null?void 0:r.profile_picture_url)||null),y=i.useRef(null);i.useEffect(()=>{r&&!x&&(g(r.first_name||""),u(r.last_name||""),p(r.username||""),w(r.profile_picture_url||null),m(!0))},[r,x]);const f=i.useCallback(async()=>{if(r)try{const I={};h!==r.first_name&&(I.first_name=h),c!==r.last_name&&(I.last_name=c),d!==r.username&&(I.username=d),Object.keys(I).length>0&&await o(I)}catch(I){a(I.message||"Failed to save profile changes","error")}},[r,o,h,c,d,a]),$=I=>{g(I.target.value)},S=I=>{u(I.target.value)},j=I=>{p(I.target.value)},T=()=>{f()},R=()=>{f()},O=()=>{f()},P=I=>{var A;if((A=I.target.files)!=null&&A[0]){const q=I.target.files[0];w(URL.createObjectURL(q)),setTimeout(async()=>{try{await n(q),r.refetch(),a("Profile picture updated successfully","info")}catch(Y){a(Y.message||"Failed to update profile picture","error"),w((r==null?void 0:r.profile_picture_url)||null)}},100)}},M=()=>{y.current&&y.current.click()};if(!r)return e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Ie,{})});const N=async()=>{if(!(!r||C!==r.username)){k(!0);try{await s(""),a("Account deleted successfully","info")}catch(I){a(I.message||"Failed to delete account","error")}finally{k(!1),z(""),b(!1)}}};return e.jsx(e.Fragment,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2xl)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-2xl)",alignItems:"center"},children:[e.jsx("div",{style:{flexShrink:0},children:e.jsxs("div",{style:{width:"120px",height:"120px",borderRadius:"50%",border:"2px dashed var(--color-border)",background:E?"transparent":"var(--color-input-background)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",transition:"all 0.2s ease"},onClick:M,onMouseEnter:I=>{I.currentTarget.style.borderColor="var(--color-primary)",I.currentTarget.style.transform="scale(1.02)"},onMouseLeave:I=>{I.currentTarget.style.borderColor="var(--color-border)",I.currentTarget.style.transform="scale(1)"},children:[E?e.jsx("img",{src:E,alt:"Profile Picture",style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"50%"}}):e.jsx(qo,{size:32,color:"var(--color-muted)"}),e.jsx("input",{type:"file",ref:y,style:{display:"none"},accept:"image/*",onChange:P})]})}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{marginBottom:"var(--space-lg)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Profile Picture"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Upload an image to represent your profile"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-sm)",marginBottom:"var(--space-sm)"},children:[e.jsxs(K,{onClick:()=>{var I;return(I=y.current)==null?void 0:I.click()},style:{padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(ln,{size:14}),E?"Change":"Upload"]}),e.jsxs(K,{onClick:async()=>{w(null),y.current&&(y.current.value="");try{await o({remove_profile_picture:!0}),await r.refetch(),a("Profile picture removed successfully","info")}catch(I){a(I.message||"Failed to remove profile picture","error"),w((r==null?void 0:r.profile_picture_url)||null)}},style:{background:"transparent",color:"var(--color-muted)",border:"1px solid var(--color-border)",padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(wt,{size:14}),"Remove"]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"var(--space-md)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Profile Details"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Basic information about your profile"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-lg)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-md)"},children:[e.jsxs(he,{style:{flex:1},children:[e.jsx(ae,{htmlFor:"firstName",children:"First Name"}),e.jsx(ie,{id:"firstName",type:"text",value:h,onChange:$,onBlur:T,placeholder:"Enter your first name",required:!0})]}),e.jsxs(he,{style:{flex:1},children:[e.jsx(ae,{htmlFor:"lastName",children:"Last Name"}),e.jsx(ie,{id:"lastName",type:"text",value:c,onChange:S,onBlur:R,placeholder:"Enter your last name",required:!0})]})]}),((L=(D=t==null?void 0:t.auth_settings)==null?void 0:D.username)==null?void 0:L.enabled)&&e.jsxs(he,{children:[e.jsx(ae,{htmlFor:"username",children:"Username"}),e.jsx(ie,{id:"username",type:"text",value:d,onChange:j,onBlur:O,placeholder:"Enter your username",required:!0})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h3",{style:{fontSize:"16px",color:"var(--color-foreground)",margin:"0 0 4px 0"},children:"Danger Zone"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-muted)",margin:0},children:"Irreversible and destructive actions"})]}),e.jsxs("div",{style:{padding:"20px",border:"1px solid var(--color-error)",borderRadius:"8px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:v?"20px":"0"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",color:"var(--color-foreground)",marginBottom:"4px",fontWeight:"500"},children:"Delete Account"}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-muted)"},children:"Once you delete your account, there is no going back. Please be certain."})]}),e.jsx(K,{onClick:()=>{v?(b(!1),z("")):b(!0)},style:{background:"var(--color-error)",color:"white",border:"none",padding:"6px 12px",fontSize:"13px",height:"32px",width:"auto"},children:v?"Cancel":"Delete"})]}),v&&e.jsxs("div",{style:{maxWidth:"400px"},children:[e.jsxs(he,{children:[e.jsx(ae,{htmlFor:"confirm_username",children:"Confirm by typing your username"}),e.jsx(ie,{id:"confirm_username",type:"text",value:C,onChange:I=>z(I.target.value),placeholder:`Type "${r==null?void 0:r.username}" to confirm`})]}),e.jsx(K,{onClick:N,disabled:C!==(r==null?void 0:r.username)||_,style:{background:C===(r==null?void 0:r.username)?"var(--color-error)":"transparent",color:C===(r==null?void 0:r.username)?"white":"var(--color-muted)",border:"1px solid var(--color-border)",padding:"8px 16px",fontSize:"14px",height:"36px",cursor:C===(r==null?void 0:r.username)?"pointer":"not-allowed",opacity:C===(r==null?void 0:r.username)?1:.6,marginTop:"12px"},children:_?e.jsx(Ie,{size:12}):"Delete Forever"})]})]})]})]})})},Sd=({isOpen:t,onClose:r,title:o,showHeader:n,headerContent:s,footerContent:a,customContent:h,children:g,showCloseButton:c})=>e.jsx(ze,{isOpen:t,onClose:r,children:e.jsx(ze.Overlay,{children:e.jsxs(ze.Content,{style:{width:"900px",maxWidth:"100%"},children:[n&&e.jsx(ze.Header,{showCloseButton:c,children:s||o}),h||g||e.jsx(Cd,{}),a&&e.jsx(ze.Footer,{children:a})]})})}),l1=l.div`
|
|
4234
|
+
`,a1=()=>{const{user:t,disconnectSocialConnection:r,connectSocialAccount:o}=Wt(),{deployment:n}=ye(),s={google_oauth:{icon:e.jsx(kl,{}),label:"Google"},microsoft_oauth:{icon:e.jsx(Wv,{}),label:"Microsoft"},github_oauth:{icon:e.jsx(_l,{}),label:"GitHub"},gitlab_oauth:{icon:e.jsx(zl,{}),label:"GitLab"},linkedin_oauth:{icon:e.jsx(Sl,{}),label:"LinkedIn"},discord_oauth:{icon:e.jsx($l,{}),label:"Discord"},x_oauth:{icon:e.jsx(Cl,{}),label:"X"}},a=(n==null?void 0:n.social_connections.filter(h=>h.enabled))||[];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h3",{style:{fontSize:"16px",margin:"0 0 6px 0",letterSpacing:"-0.01em",color:"var(--color-foreground)"},children:"Connected Accounts"}),e.jsx("p",{style:{fontSize:"13px",margin:0,lineHeight:"1.5",color:"var(--color-muted)"},children:"Connect social accounts for easy sign-in and profile sync"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:a.map((h,g)=>{var d;const c=((d=t==null?void 0:t.social_connections)==null?void 0:d.filter(p=>p.provider===h.provider))||[],u=s[h.provider];return u?e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0",minHeight:"58px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:"var(--color-foreground)"},children:[e.jsx(kd,{children:u.icon}),e.jsx("div",{style:{fontSize:"14px",fontWeight:500},children:u.label})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-end",gap:"8px"},children:[c.map(p=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"6px",padding:"4px 8px",fontSize:"13px",color:"var(--color-muted)"},children:[e.jsx("span",{children:p.email_address}),e.jsx(gn,{onClick:async()=>{await r(p.id.toString()),t.refetch()},style:{padding:"2px"},children:e.jsx(ct,{size:14})})]},p.id)),c.length>0?e.jsx(K,{onClick:()=>{o({provider:h.provider,redirectUri:window.location.href})},style:{padding:"6px 24px",fontSize:"13px"},children:"Add"}):e.jsx(K,{onClick:()=>{o({provider:h.provider,redirectUri:window.location.href})},style:{padding:"6px 14px",fontSize:"13px"},children:"Connect"})]})]}),g<a.length-1&&e.jsx("div",{style:{height:"1px",background:"var(--color-border)"}})]},h.provider):null})})]})},Cd=()=>{var v,b,_,k,C,z,E;const{loading:t}=Wt(),{deployment:r}=ye(),[o,n]=i.useState("profile"),[s,a]=i.useState(null),[h,g]=i.useState("info"),c=i.useCallback((w,y="info")=>{a(w),g(y),setTimeout(()=>a(null),3e3)},[a]);if(t)return e.jsx(ge,{children:e.jsx(Yi,{style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(Ie,{})})});const u=r==null?void 0:r.auth_settings,d=(v=u==null?void 0:u.email_address)==null?void 0:v.enabled,p=(b=u==null?void 0:u.phone_number)==null?void 0:b.enabled,x=((_=r==null?void 0:r.social_connections)==null?void 0:_.some(w=>w.enabled))||!1,m=((k=u==null?void 0:u.password)==null?void 0:k.enabled)||((C=u==null?void 0:u.auth_factors_enabled)==null?void 0:C.authenticator)||((z=u==null?void 0:u.auth_factors_enabled)==null?void 0:z.phone_otp)||((E=u==null?void 0:u.auth_factors_enabled)==null?void 0:E.backup_code);return e.jsx(ge,{children:e.jsx(Qv,{children:e.jsx(_d.Provider,{value:{screen:null,setScreen:()=>{},toast:c},children:e.jsxs(Yi,{children:[e.jsx(Jv,{children:e.jsxs(Xv,{children:[e.jsx(_r,{$isActive:o==="profile",onClick:()=>n("profile"),children:e.jsxs(kr,{children:[e.jsx(qo,{size:16}),"Profile"]})}),d&&e.jsx(_r,{$isActive:o==="email",onClick:()=>n("email"),children:e.jsxs(kr,{children:[e.jsx(dn,{size:16}),"Email"]})}),p&&e.jsx(_r,{$isActive:o==="phone",onClick:()=>n("phone"),children:e.jsxs(kr,{children:[e.jsx(Bh,{size:16}),"Phone"]})}),x&&e.jsx(_r,{$isActive:o==="social",onClick:()=>n("social"),children:e.jsxs(kr,{children:[e.jsx(Ph,{size:16}),"Connections"]})}),m&&e.jsx(_r,{$isActive:o==="security",onClick:()=>n("security"),children:e.jsxs(kr,{children:[e.jsx(ut,{size:16}),"Security"]})}),e.jsx(_r,{$isActive:o==="sessions",onClick:()=>n("sessions"),children:e.jsxs(kr,{children:[e.jsx(nh,{size:16}),"Sessions"]})})]})}),e.jsxs(e1,{children:[o==="profile"&&e.jsx(c1,{}),o==="email"&&d&&e.jsx(n1,{}),o==="phone"&&p&&e.jsx(s1,{}),o==="social"&&x&&e.jsx(a1,{}),o==="security"&&m&&e.jsx(i1,{}),o==="sessions"&&e.jsx(o1,{})]}),s&&e.jsx("div",{style:{position:"absolute",bottom:"20px",right:"20px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"8px",padding:"12px 16px",boxShadow:"0 4px 12px var(--color-shadow)",animation:"slideUp 0.3s ease-out"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h==="error"?e.jsx(wt,{size:16,color:"var(--color-error)"}):e.jsx(et,{size:16,color:"var(--color-success)"}),e.jsx("span",{style:{fontSize:"14px",color:"var(--color-foreground)"},children:s})]})})]})})})})},i1=()=>{var mn,Zs,Ks,Qs,Js,Xs,ea;const{deployment:t}=ye(),{user:r,updatePassword:o,removePassword:n,setupAuthenticator:s,verifyAuthenticator:a,deleteAuthenticator:h,generateBackupCodes:g,regenerateBackupCodes:c,updateProfile:u,getPasskeys:d,registerPasskey:p,deletePasskey:x}=Wt(),{toast:m}=Ht(),[v,b]=i.useState((r==null?void 0:r.second_factor_policy)||"none"),[_,k]=i.useState(!1),C=async ae=>{try{await u({second_factor_policy:ae}),b(ae),m("2FA requirement updated successfully","info")}catch(Ue){m(Ue.message||"Failed to update 2FA requirement","error")}},[z,E]=i.useState(!1),[w,y]=i.useState(!1),[f,$]=i.useState(!1),[S,j]=i.useState(!1),T=i.useRef(null),R=i.useRef(null),O=i.useRef(null),P=i.useRef(null),[M,N]=i.useState([]),[D,L]=i.useState(!1),[I,A]=i.useState(!1),[q,Y]=i.useState(!1),[B,H]=i.useState("table"),[V,J]=i.useState(""),[oe,re]=i.useState(""),[fe,X]=i.useState(""),[ue,ve]=i.useState(["",""]),[pe,U]=i.useState([]),[le,Q]=i.useState(!1),[Z,ne]=i.useState(!1),[me]=i.useState(!1),[de,ee]=i.useState(!1),W=(mn=t==null?void 0:t.auth_settings)==null?void 0:mn.auth_factors_enabled,F=(Ks=(Zs=t==null?void 0:t.auth_settings)==null?void 0:Zs.password)==null?void 0:Ks.enabled;if(!(W!=null&&W.authenticator)&&!(W!=null&&W.backup_code)&&!F)return null;const se=async(ae,Ue)=>{await o(ae,Ue),await r.refetch(),m("Password updated successfully","info")},be=async ae=>{await n(ae),await r.refetch(),m("Password removed successfully","info")},Oe=()=>{var ta,ra,oa,na,sa,aa;if(!r)return!1;const ae=(ta=r.user_email_addresses)==null?void 0:ta.some(Or=>Or.verified),Ue=(ra=r.user_phone_numbers)==null?void 0:ra.some(Or=>Or.verified),Be=r.social_connections&&r.social_connections.length>0,Xe=t==null?void 0:t.auth_settings;return(Xe==null?void 0:Xe.first_factor)==="email_otp"&&ae||((oa=Xe==null?void 0:Xe.magic_link)==null?void 0:oa.enabled)&&ae||((na=Xe==null?void 0:Xe.passkey)==null?void 0:na.enabled)||((sa=Xe==null?void 0:Xe.auth_factors_enabled)==null?void 0:sa.phone_otp)&&Ue||Be&&((aa=t==null?void 0:t.social_connections)==null?void 0:aa.some(Or=>Or.enabled))},Fe=async()=>{if(ue.some(ae=>ae.length!==6)){m("Please enter both 6-digit verification codes","error");return}try{if(ne(!0),await a(fe,ue),await r.refetch(),W!=null&&W.backup_code){const ae=await g();U(ae),await r.refetch(),H("backup")}else H("success")}catch(ae){m(ae.message||"Invalid verification codes","error")}finally{ne(!1)}},Se=()=>{H("table"),J(""),re(""),X(""),ve(["",""]),U([]),m("Two-factor authentication setup completed successfully!","info")},Ve=async()=>{var ae;if((ae=r==null?void 0:r.user_authenticator)!=null&&ae.id)try{ee(!0),await h(r.user_authenticator.id),await r.refetch(),k(!1),m("Two-factor authentication removed successfully","info")}catch(Ue){m(Ue.message||"Failed to remove authenticator","error")}finally{ee(!1)}},Ae=async()=>{if(!le)try{Q(!0);const ae=await c();U(ae),await r.refetch(),j(!0),m("New backup codes generated","info")}catch(ae){m(ae.message||"Failed to generate backup codes","error")}finally{Q(!1)}},te=()=>{const ae=pe.join(`
|
|
4235
|
+
`);navigator.clipboard.writeText(ae).then(()=>{m("Backup codes copied to clipboard","info")}).catch(()=>{m("Failed to copy backup codes","error")})},xe=()=>{const ae=pe.join(`
|
|
4236
|
+
`),Ue=new Blob([ae],{type:"text/plain"}),Be=URL.createObjectURL(Ue),Xe=document.createElement("a");Xe.href=Be,Xe.download="wacht-backup-codes.txt",Xe.click(),URL.revokeObjectURL(Be),m("Backup codes downloaded","info")},_e=async()=>{var ae,Ue;if((Ue=(ae=t==null?void 0:t.auth_settings)==null?void 0:ae.passkey)!=null&&Ue.enabled)try{L(!0);const Be=await d();N(Be.data||[])}catch(Be){console.error("Failed to load passkeys:",Be)}finally{L(!1)}},Ce=async()=>{try{A(!0),await p(),await _e(),m("Passkey registered successfully!","info")}catch(ae){m(ae.message||"Failed to register passkey","error")}finally{A(!1)}},Pe=async ae=>{try{await x(ae),await _e(),m("Passkey removed","info")}catch(Ue){m(Ue.message||"Failed to remove passkey","error")}};i.useEffect(()=>{_e()},[(Js=(Qs=t==null?void 0:t.auth_settings)==null?void 0:Qs.passkey)==null?void 0:Js.enabled]);const Te=[];return F&&Te.push({id:"password",name:"Password",description:"Secure your account with a strong password",status:r!=null&&r.has_password?"Enabled":"Disabled",actions:r!=null&&r.has_password?["change"]:["setup"]}),(ea=(Xs=t==null?void 0:t.auth_settings)==null?void 0:Xs.passkey)!=null&&ea.enabled&&Te.push({id:"passkey",name:"Passkeys",description:"Sign in faster with fingerprint, face, or screen lock",status:M.length>0?`${M.length} registered`:"",actions:M.length>0?["manage","add"]:["add"]}),W!=null&&W.authenticator&&Te.push({id:"authenticator",name:"Authenticator App",description:"Use an authenticator app for extra security",status:r!=null&&r.user_authenticator?"Enabled":"Disabled",actions:r!=null&&r.user_authenticator?["remove"]:["setup"]}),r!=null&&r.user_authenticator&&Te.push({id:"backup_codes",name:"Backup Codes",description:"Recovery codes if you lose your authenticator",status:r!=null&&r.backup_codes_generated?"Generated":"Not Generated",actions:["generate"]}),r!=null&&r.user_authenticator&&Te.push({id:"second_factor_policy",name:"Require 2FA",description:"Require a second factor for all sign-ins",status:v==="enforced"?"Enforced":"Optional",actions:["toggle"]}),B!=="table"?e.jsxs(e.Fragment,{children:[e.jsxs(Jo,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(ut,{size:16}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--color-foreground)"},children:[B==="qr"&&"Setup Two-Factor Authentication",B==="verify"&&"Verify Your Authenticator",B==="backup"&&"Save Your Backup Codes",B==="success"&&"Setup Complete!"]})]}),e.jsx(K,{onClick:()=>H("table"),style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",color:"var(--color-foreground)",fontWeight:"500",cursor:"pointer",transition:"all 0.2s ease"},children:"← Back"})]}),e.jsxs("div",{style:{maxWidth:"500px",margin:"0 auto",textAlign:"center",padding:"24px"},children:[B==="qr"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{color:"var(--color-secondary-text)",marginBottom:"24px"},children:"Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.)"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"24px"},children:me?e.jsx("div",{style:{width:"200px",height:"200px",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-input-background)"},children:e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{width:"24px",height:"24px",border:"2px solid var(--color-border)",borderTop:"2px solid var(--color-primary)",borderRadius:"50%",animation:`${Kv} 1s linear infinite`,margin:"0 auto 8px"}}),e.jsx("div",{style:{fontSize:"12px",color:"var(--color-secondary-text)"},children:"Loading QR Code..."})]})}):V?e.jsx("div",{style:{border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"16px",background:"white"},children:e.jsx(qs,{value:V,size:200,level:"M",marginSize:0})}):e.jsx("div",{style:{width:"200px",height:"200px",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-input-background)",color:"var(--color-error)",fontSize:"14px",textAlign:"center"},children:"QR Code Not Available"})}),e.jsxs("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"12px",marginBottom:"24px"},children:[e.jsx("p",{style:{fontSize:"14px",color:"var(--color-secondary-text)",margin:"0 0 8px 0"},children:"Or enter this code manually:"}),e.jsx("code",{style:{fontFamily:"monospace",fontSize:"14px",wordBreak:"break-all"},children:oe||"Loading..."})]}),e.jsx(K,{onClick:()=>H("verify"),disabled:!V||!oe,style:{padding:"10px 20px",background:!V||!oe?"var(--color-border)":"var(--color-primary)",color:!V||!oe?"var(--color-secondary-text)":"white",border:`1px solid ${!V||!oe?"var(--color-border)":"var(--color-primary)"}`,cursor:!V||!oe?"not-allowed":"pointer"},children:"I've Scanned the Code"})]}),B==="verify"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{color:"var(--color-secondary-text)",marginBottom:"24px"},children:"Enter two consecutive codes from your authenticator app to verify setup"}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center",marginBottom:"24px"},children:[e.jsx(ce,{type:"text",placeholder:"000000",value:ue[0],onChange:ae=>{const Ue=ae.target.value.replace(/[^0-9]/g,"").substring(0,6);ve([Ue,ue[1]])},maxLength:6,style:{width:"100px",textAlign:"center",fontFamily:"monospace"}}),e.jsx(ce,{type:"text",placeholder:"000000",value:ue[1],onChange:ae=>{const Ue=ae.target.value.replace(/[^0-9]/g,"").substring(0,6);ve([ue[0],Ue])},maxLength:6,style:{width:"100px",textAlign:"center",fontFamily:"monospace"}})]}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center"},children:[e.jsx(K,{onClick:()=>H("qr"),style:{padding:"8px 16px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:"Back"}),e.jsx(K,{onClick:Fe,disabled:Z||ue.some(ae=>ae.length!==6),style:{padding:"8px 16px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:Z?"Verifying...":"Verify & Continue"})]})]}),B==="backup"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{background:"var(--color-warning-background)",border:"1px solid var(--color-warning-border)",borderRadius:"var(--radius-md)",padding:"16px",marginBottom:"24px",display:"flex",alignItems:"flex-start",gap:"12px",textAlign:"left"},children:[e.jsx(wt,{size:16,style:{color:"var(--color-warning)",marginTop:"2px"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:"Important!"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-secondary-text)"},children:"Store these codes safely. Each code can only be used once if you lose access to your authenticator device."})]})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"8px",marginBottom:"24px",maxWidth:"300px",margin:"0 auto 24px auto"},children:pe.map((ae,Ue)=>e.jsx("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"8px",fontFamily:"monospace",fontSize:"12px",textAlign:"center",cursor:"pointer"},onClick:()=>navigator.clipboard.writeText(ae),children:ae},Ue))}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center",marginBottom:"24px"},children:[e.jsx(K,{onClick:te,style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:"Copy All"}),e.jsxs(K,{onClick:xe,style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:[e.jsx(ln,{size:16,style:{marginRight:"4px"}}),"Download"]})]}),e.jsx(K,{onClick:Se,style:{padding:"10px 20px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:"Complete Setup"})]}),B==="success"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx(et,{size:48,style:{color:"var(--color-success)",marginBottom:"16px"}}),e.jsx("h3",{style:{fontSize:"18px",fontWeight:600,margin:"0 0 8px 0"},children:"All Set!"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-secondary-text)",margin:0},children:"Your account is now protected with two-factor authentication."})]}),e.jsx(K,{onClick:Se,style:{padding:"10px 20px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:"Continue to Security"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Jo,{children:e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--color-foreground)"},children:"Security Settings"})})}),Te.length?e.jsx("div",{children:Te.map((ae,Ue)=>e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 0"},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:400,color:"var(--color-foreground)"},children:ae.name}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-secondary-text)"},children:ae.description})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[ae.status&&ae.id!=="passkey"&&e.jsx("span",{style:{padding:"4px 12px",borderRadius:"16px",fontSize:"12px",fontWeight:400,background:ae.status==="Enabled"||ae.status==="Generated"?"var(--color-success-background)":"var(--color-background-hover)",color:ae.status==="Enabled"||ae.status==="Generated"?"var(--color-success)":"var(--color-secondary-text)"},children:ae.status}),e.jsxs("div",{style:{position:"relative"},children:[ae.id==="password"&&e.jsx(e.Fragment,{children:r!=null&&r.has_password?e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:R,onClick:()=>y(!0),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Change"}),w&&e.jsx(Hi,{triggerRef:R,onClose:()=>y(!1),onChangePassword:se})]}),Oe()&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:O,onClick:()=>$(!0),style:{padding:"6px 12px",fontSize:"12px",background:"transparent",color:"var(--color-error)",border:"1px solid var(--color-error)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Remove"}),f&&e.jsx(Ov,{triggerRef:O,onClose:()=>$(!1),onRemovePassword:be})]})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:R,onClick:()=>y(!0),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Setup"}),w&&e.jsx(Hi,{triggerRef:R,onClose:()=>y(!1),onChangePassword:se,isSetup:!0})]})}),ae.id==="authenticator"&&!(r!=null&&r.user_authenticator)&&e.jsx(e.Fragment,{children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:T,onClick:()=>E(!0),disabled:me,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:me?"Setting up...":"Setup"}),z&&e.jsx(Sv,{triggerRef:T,onClose:()=>E(!1),onSetupTOTP:async()=>{const Be=await s();return X(Be.id),Be},onVerifyTOTP:async Be=>{await a(fe,Be),await r.refetch(),m("Two-factor authentication enabled successfully!","info")}})]})}),ae.id==="authenticator"&&(r==null?void 0:r.user_authenticator)&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{onClick:()=>k(!0),disabled:de,style:{padding:"6px 16px",fontSize:"13px",background:"var(--color-error)",border:"1px solid var(--color-error)",color:"white",cursor:de?"not-allowed":"pointer",opacity:de?.6:1},children:de?"Removing...":"Remove"}),_&&e.jsx(to,{title:"Remove MFA and reset policy to default?",onConfirm:Ve,onCancel:()=>k(!1)})]}),ae.id==="backup_codes"&&e.jsx(e.Fragment,{children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:P,onClick:Ae,disabled:le,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:le?"Generating...":r!=null&&r.backup_codes_generated?"Regenerate":"Generate"}),S&&e.jsx(Uv,{triggerRef:P,codes:pe,onClose:()=>j(!1),onCopy:te,onDownload:xe})]})}),ae.id==="second_factor_policy"&&e.jsx(fr,{checked:v==="enforced",onChange:Be=>{C(Be?"enforced":"none")}}),ae.id==="passkey"&&e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsxs(K,{onClick:()=>Y(!q),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",fontWeight:"400",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",whiteSpace:"nowrap",flexShrink:0},children:[q?"Hide":"Manage"," (",M.length,")",e.jsx(Ft,{size:14,style:{transform:q?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s ease"}})]}),e.jsx(K,{onClick:Ce,disabled:I,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400",cursor:I?"not-allowed":"pointer",opacity:I?.7:1,whiteSpace:"nowrap"},children:I?"Registering...":"Add"})]})]})]})]}),ae.id==="passkey"&&q&&e.jsx("div",{style:{padding:"12px 0",borderTop:"1px solid var(--color-border)",marginTop:"8px"},children:D?e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"16px"},children:e.jsx(Ie,{})}):M.length===0?e.jsx("div",{style:{textAlign:"center",padding:"16px",color:"var(--color-secondary-text)",fontSize:"13px"},children:"No passkeys registered yet"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:M.map(Be=>e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 12px",background:"var(--color-input-background)",borderRadius:"var(--radius-md)",border:"1px solid var(--color-border)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--color-foreground)"},children:Be.name||"Unnamed Passkey"}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--color-secondary-text)"},children:[Be.device_type==="platform"?"This device":"Security key",Be.last_used_at&&` • Last used ${new Date(Be.last_used_at).toLocaleDateString()}`]})]}),e.jsx(K,{onClick:()=>{confirm(`Remove "${Be.name||"Unnamed Passkey"}"?`)&&Pe(Be.id)},style:{padding:"4px 10px",fontSize:"12px",background:"transparent",border:"1px solid var(--color-error)",borderRadius:"var(--radius-md)",color:"var(--color-error)",cursor:"pointer"},children:"Remove"})]},Be.id))})}),Ue<Te.length-1&&e.jsx("div",{style:{height:"1px",background:"var(--color-border)",margin:"0"}})]},ae.id))}):e.jsx(mt,{title:"No security features available",description:"Contact your administrator to enable security features."})]})},c1=()=>{var D,L;const{deployment:t}=ye(),{user:r,updateProfile:o,updateProfilePicture:n,deleteAccount:s}=Wt(),{toast:a}=Ht(),[h,g]=i.useState(""),[c,u]=i.useState(""),[d,p]=i.useState(""),[x,m]=i.useState(!1),[v,b]=i.useState(!1),[_,k]=i.useState(!1),[C,z]=i.useState(""),[E,w]=i.useState((r==null?void 0:r.profile_picture_url)||null),y=i.useRef(null);i.useEffect(()=>{r&&!x&&(g(r.first_name||""),u(r.last_name||""),p(r.username||""),w(r.profile_picture_url||null),m(!0))},[r,x]);const f=i.useCallback(async()=>{if(r)try{const I={};h!==r.first_name&&(I.first_name=h),c!==r.last_name&&(I.last_name=c),d!==r.username&&(I.username=d),Object.keys(I).length>0&&await o(I)}catch(I){a(I.message||"Failed to save profile changes","error")}},[r,o,h,c,d,a]),$=I=>{g(I.target.value)},S=I=>{u(I.target.value)},j=I=>{p(I.target.value)},T=()=>{f()},R=()=>{f()},O=()=>{f()},P=I=>{var A;if((A=I.target.files)!=null&&A[0]){const q=I.target.files[0];w(URL.createObjectURL(q)),setTimeout(async()=>{try{await n(q),r.refetch(),a("Profile picture updated successfully","info")}catch(Y){a(Y.message||"Failed to update profile picture","error"),w((r==null?void 0:r.profile_picture_url)||null)}},100)}},M=()=>{y.current&&y.current.click()};if(!r)return e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Ie,{})});const N=async()=>{if(!(!r||C!==r.username)){k(!0);try{await s(""),a("Account deleted successfully","info")}catch(I){a(I.message||"Failed to delete account","error")}finally{k(!1),z(""),b(!1)}}};return e.jsx(e.Fragment,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2xl)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-2xl)",alignItems:"center"},children:[e.jsx("div",{style:{flexShrink:0},children:e.jsxs("div",{style:{width:"120px",height:"120px",borderRadius:"50%",border:"2px dashed var(--color-border)",background:E?"transparent":"var(--color-input-background)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",transition:"all 0.2s ease"},onClick:M,onMouseEnter:I=>{I.currentTarget.style.borderColor="var(--color-primary)",I.currentTarget.style.transform="scale(1.02)"},onMouseLeave:I=>{I.currentTarget.style.borderColor="var(--color-border)",I.currentTarget.style.transform="scale(1)"},children:[E?e.jsx("img",{src:E,alt:"Profile Picture",style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"50%"}}):e.jsx(qo,{size:32,color:"var(--color-muted)"}),e.jsx("input",{type:"file",ref:y,style:{display:"none"},accept:"image/*",onChange:P})]})}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{marginBottom:"var(--space-lg)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Profile Picture"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Upload an image to represent your profile"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-sm)",marginBottom:"var(--space-sm)"},children:[e.jsxs(K,{onClick:()=>{var I;return(I=y.current)==null?void 0:I.click()},style:{padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(ln,{size:14}),E?"Change":"Upload"]}),e.jsxs(K,{onClick:async()=>{w(null),y.current&&(y.current.value="");try{await o({remove_profile_picture:!0}),await r.refetch(),a("Profile picture removed successfully","info")}catch(I){a(I.message||"Failed to remove profile picture","error"),w((r==null?void 0:r.profile_picture_url)||null)}},style:{background:"transparent",color:"var(--color-muted)",border:"1px solid var(--color-border)",padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(wt,{size:14}),"Remove"]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"var(--space-md)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Profile Details"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Basic information about your profile"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-lg)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-md)"},children:[e.jsxs(he,{style:{flex:1},children:[e.jsx(ie,{htmlFor:"firstName",children:"First Name"}),e.jsx(ce,{id:"firstName",type:"text",value:h,onChange:$,onBlur:T,placeholder:"Enter your first name",required:!0})]}),e.jsxs(he,{style:{flex:1},children:[e.jsx(ie,{htmlFor:"lastName",children:"Last Name"}),e.jsx(ce,{id:"lastName",type:"text",value:c,onChange:S,onBlur:R,placeholder:"Enter your last name",required:!0})]})]}),((L=(D=t==null?void 0:t.auth_settings)==null?void 0:D.username)==null?void 0:L.enabled)&&e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"username",children:"Username"}),e.jsx(ce,{id:"username",type:"text",value:d,onChange:j,onBlur:O,placeholder:"Enter your username",required:!0})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h3",{style:{fontSize:"16px",color:"var(--color-foreground)",margin:"0 0 4px 0"},children:"Danger Zone"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-muted)",margin:0},children:"Irreversible and destructive actions"})]}),e.jsxs("div",{style:{padding:"20px",border:"1px solid var(--color-error)",borderRadius:"8px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:v?"20px":"0"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",color:"var(--color-foreground)",marginBottom:"4px",fontWeight:"500"},children:"Delete Account"}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-muted)"},children:"Once you delete your account, there is no going back. Please be certain."})]}),e.jsx(K,{onClick:()=>{v?(b(!1),z("")):b(!0)},style:{background:"var(--color-error)",color:"white",border:"none",padding:"6px 12px",fontSize:"13px",height:"32px",width:"auto"},children:v?"Cancel":"Delete"})]}),v&&e.jsxs("div",{style:{maxWidth:"400px"},children:[e.jsxs(he,{children:[e.jsx(ie,{htmlFor:"confirm_username",children:"Confirm by typing your username"}),e.jsx(ce,{id:"confirm_username",type:"text",value:C,onChange:I=>z(I.target.value),placeholder:`Type "${r==null?void 0:r.username}" to confirm`})]}),e.jsx(K,{onClick:N,disabled:C!==(r==null?void 0:r.username)||_,style:{background:C===(r==null?void 0:r.username)?"var(--color-error)":"transparent",color:C===(r==null?void 0:r.username)?"white":"var(--color-muted)",border:"1px solid var(--color-border)",padding:"8px 16px",fontSize:"14px",height:"36px",cursor:C===(r==null?void 0:r.username)?"pointer":"not-allowed",opacity:C===(r==null?void 0:r.username)?1:.6,marginTop:"12px"},children:_?e.jsx(Ie,{size:12}):"Delete Forever"})]})]})]})]})})},Sd=({isOpen:t,onClose:r,title:o,showHeader:n,headerContent:s,footerContent:a,customContent:h,children:g,showCloseButton:c})=>e.jsx(ze,{isOpen:t,onClose:r,children:e.jsx(ze.Overlay,{children:e.jsxs(ze.Content,{style:{width:"900px",maxWidth:"100%"},children:[n&&e.jsx(ze.Header,{showCloseButton:c,children:s||o}),h||g||e.jsx(Cd,{}),a&&e.jsx(ze.Footer,{children:a})]})})}),l1=l.div`
|
|
4237
4237
|
position: relative;
|
|
4238
4238
|
`,d1=l.button`
|
|
4239
4239
|
display: flex;
|
|
@@ -5781,7 +5781,7 @@ cursor: pointer;
|
|
|
5781
5781
|
&:hover .expand-icon {
|
|
5782
5782
|
opacity: 1;
|
|
5783
5783
|
}
|
|
5784
|
-
`,ny=({isOpen:t,imageUrl:r,zoomLevel:o,dragPosition:n,isDragging:s,onClose:a,onDownload:h,onZoom:g,onReset:c,onWheel:u,onMouseDown:d,onMouseMove:p,onMouseUp:x})=>{const[m,v]=i.useState(!1),b=i.useRef(null);return i.useEffect(()=>(v(!0),()=>v(!1)),[]),i.useEffect(()=>{if(t){const _=document.body.style.overflow;document.body.style.overflow="hidden";const k=E=>{(E.ctrlKey||E.metaKey)&&E.preventDefault()},C=E=>{E.preventDefault()},z=E=>{E.preventDefault()};return document.addEventListener("wheel",k,{passive:!1}),document.addEventListener("gesturestart",C,{passive:!1}),document.addEventListener("gesturechange",z,{passive:!1}),()=>{document.body.style.overflow=_,document.removeEventListener("wheel",k),document.removeEventListener("gesturestart",C),document.removeEventListener("gesturechange",z)}}},[t]),!m||!t||!r?null:Qr.createPortal(e.jsx(ge,{children:e.jsx(Qb,{ref:b,$isOpen:!0,onClick:_=>{_.target===_.currentTarget&&a()},children:e.jsxs(Jb,{onClick:_=>_.stopPropagation(),onWheel:_=>{_.preventDefault(),_.stopPropagation(),u(_)},onMouseMove:p,onMouseUp:x,onMouseLeave:x,children:[e.jsx(Xb,{src:r,alt:"Preview",$zoom:o,$x:n.x,$y:n.y,$isDragging:s,onMouseDown:d,draggable:!1}),e.jsx(Oo,{$variant:"ghost",onClick:a,title:"Close",style:{position:"absolute",top:"16px",right:"16px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:e.jsx(ct,{size:14})}),e.jsxs(ey,{children:[e.jsxs(ty,{children:[e.jsx(Oo,{$variant:"ghost",onClick:()=>g(-.25),title:"Zoom out",disabled:o<=.5,children:e.jsx(of,{size:14})}),e.jsxs(ry,{children:[Math.round(o*100),"%"]}),e.jsx(Oo,{$variant:"ghost",onClick:()=>g(.25),title:"Zoom in",disabled:o>=3,children:e.jsx(tf,{size:14})}),e.jsx(Oo,{$variant:"ghost",onClick:c,title:"Reset zoom",children:e.jsx(Ah,{size:14})})]}),e.jsxs(Td,{$variant:"primary",onClick:h,title:"Download image",children:[e.jsx(ln,{size:14}),"Download"]})]})]})})}),document.body)};function Md({showBackButton:t=!1,onBack:r}){const{agentName:o,token:n,platformAdapter:s,selectedSession:a,selectSession:h}=Xo(),g=a==null?void 0:a.id;if(!g)return e.jsx(ge,{style:{height:"100%",width:"100%"},children:e.jsx(_c,{children:e.jsxs(kc,{children:[e.jsx(Pn,{size:48,strokeWidth:1.5}),e.jsx("p",{children:"No conversation selected"})]})})});const c=!0,u=!0,d="Start a conversation by typing a message below",[p,x]=i.useState(""),[m,v]=i.useState(!1),[b,_]=i.useState(null),[k,C]=i.useState([]),[z,E]=i.useState([]),[w,y]=i.useState(null),[f,$]=i.useState(1),[S,j]=i.useState(!1),[T,R]=i.useState({x:0,y:0}),[O,P]=i.useState({x:0,y:0}),M=i.useRef(null),N=i.useRef(null),{messages:D,pendingMessage:L,pendingImages:I,connectionState:A,isConnected:q,isExecuting:Y,executionStatus:B,isWaitingForInput:H,sendMessage:V,submitUserInput:J,cancelExecution:oe}=Yc({contextId:g,agentName:o,token:n,platformAdapter:s,autoConnect:c});i.useEffect(()=>{var W;(W=M.current)==null||W.scrollIntoView({behavior:"smooth"})},[D]),i.useEffect(()=>{var W;if(H){const F=D.slice().reverse().find(se=>{var be;return((be=se.metadata)==null?void 0:be.type)==="user_input_request"});(W=F==null?void 0:F.metadata)!=null&&W.userInputRequest&&_(F.metadata.userInputRequest)}else _(null),C([])},[H,D]);const re=W=>{if(W.preventDefault(),!!q)if(H&&b){let F=p.trim();b.input_type==="multiselect"&&(F=k.join(",")),F&&(J(F),x(""),C([]))}else!Y&&p.trim()&&(V(p,z.length>0?z:void 0),x(""),E([]))},fe=W=>{const F=W.target.files;F&&(Array.from(F).forEach(se=>{if(se.type.startsWith("image/")){const be=new FileReader;be.onload=Oe=>{var Fe;if((Fe=Oe.target)!=null&&Fe.result){const Ve=Oe.target.result.split(",")[1];E(Ae=>[...Ae,{mime_type:se.type,data:Ve}])}},be.readAsDataURL(se)}}),N.current&&(N.current.value=""))},X=W=>{E(F=>F.filter((se,be)=>be!==W))},ue=W=>{y(W),$(1),R({x:0,y:0})},ve=()=>{y(null),$(1),R({x:0,y:0}),j(!1)},pe=W=>{const F=document.createElement("a");F.href=W,F.download=`image-${Date.now()}.png`,document.body.appendChild(F),F.click(),document.body.removeChild(F)},U=W=>{$(F=>{const se=F+W;return Math.min(Math.max(se,.5),3)})},ce=W=>{W.preventDefault(),W.stopPropagation();const F=W.deltaY>0?-.1:.1;U(F)},Q=W=>{f>1&&(j(!0),P({x:W.clientX-T.x,y:W.clientY-T.y}))},Z=W=>{S&&f>1&&R({x:W.clientX-O.x,y:W.clientY-O.y})},ne=()=>{j(!1)},me=()=>A.status===Pt.CONNECTING?"Connecting...":A.status===Pt.ERROR?"Connection error":A.status===Pt.DISCONNECTED||!q?"Disconnected":H?"Waiting for your input...":Y?"Working...":"Ready",le=()=>{if(!H||!b)return"Ask anything";switch(b.input_type){case"select":case"boolean":case"date":return"Use controls above to make selection";case"multiselect":return"Select options above";default:return"Enter your response..."}},ee=()=>!H||!b?!1:["select","multiselect","boolean","date"].includes(b.input_type||"");return e.jsxs(ge,{style:{height:"100%",width:"100%"},children:[e.jsxs(_c,{children:[e.jsxs(Cb,{children:[e.jsxs(Sb,{children:[t&&e.jsx(zb,{onClick:()=>{r?r():h(null)},children:e.jsx(Xr,{size:20})}),e.jsxs($b,{children:[e.jsx(Eb,{children:e.jsx(Pn,{size:20})}),e.jsxs(Ib,{children:[e.jsx(Rb,{children:o}),e.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[e.jsx(Pb,{$status:me()}),e.jsx(Tb,{$status:me(),children:me()})]})]})]})]}),B!==Ge.IDLE&&e.jsx(Mb,{$status:B,children:B.replace("_"," ")})]}),e.jsx(Ob,{children:D.length===0&&u?e.jsxs(kc,{children:[e.jsx(Pn,{size:48,strokeWidth:1.5}),e.jsx("p",{children:d})]}):e.jsxs(e.Fragment,{children:[D.map((W,F)=>{var se,be,Oe,Fe;if(((se=W.metadata)==null?void 0:se.type)==="user_input_request"&&W.metadata.userInputRequest){const Se=W.metadata.userInputRequest,Ve=!Se.input_type||Se.input_type==="text"||Se.input_type==="number",Ae=H&&(b==null?void 0:b.input_type)===Se.input_type;return e.jsx(ns,{$isUser:!1,children:e.jsxs(Nb,{children:[e.jsx("div",{className:"question",children:Se.question}),Se.context&&Se.context.trim()&&e.jsx("div",{className:"context",children:Se.context}),!Ve&&e.jsxs("div",{className:"controls",children:[Se.input_type==="select"&&Se.options&&e.jsxs("select",{value:Ae?p:"",onChange:te=>x(te.target.value),disabled:!Ae,children:[e.jsx("option",{value:"",children:"Choose an option..."}),Se.options.map(te=>e.jsx("option",{value:te,children:te},te))]}),Se.input_type==="multiselect"&&Se.options&&e.jsx("div",{className:"checkbox-group",children:Se.options.map(te=>e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:Ae&&k.includes(te),onChange:xe=>{xe.target.checked?C([...k,te]):C(k.filter(_e=>_e!==te))},disabled:!Ae}),e.jsx("span",{children:te})]},te))}),Se.input_type==="boolean"&&e.jsxs("div",{className:"radio-group",children:[e.jsxs("label",{className:"radio-label",children:[e.jsx("input",{type:"radio",name:"boolean",value:"true",checked:Ae&&p==="true",onChange:te=>x(te.target.value),disabled:!Ae}),e.jsx("span",{children:"Yes"})]}),e.jsxs("label",{className:"radio-label",children:[e.jsx("input",{type:"radio",name:"boolean",value:"false",checked:Ae&&p==="false",onChange:te=>x(te.target.value),disabled:!Ae}),e.jsx("span",{children:"No"})]})]}),Se.input_type==="date"&&e.jsx("input",{type:"date",value:Ae?p:"",onChange:te=>x(te.target.value),disabled:!Ae})]}),e.jsx("div",{className:"instruction",children:Ae?Ve?"Type your response below":Se.input_type==="multiselect"?"Select options above and click send":"Make your selection above and click send":""})]})},W.id)}if(((be=W.metadata)==null?void 0:be.type)==="log"){const Se=D[F-1],Ve=D[F+1],Ae=((Oe=Se==null?void 0:Se.metadata)==null?void 0:Oe.type)==="log",te=((Fe=Ve==null?void 0:Ve.metadata)==null?void 0:Fe.type)==="log",xe=Ae||te,_e=!Ae&&te,Ce=Ae&&!te;return e.jsx(Db,{$isGrouped:xe,$isFirstInGroup:_e,$isLastInGroup:Ce,children:e.jsx("div",{className:"log-content",children:W.content})},W.id)}return!W.content&&(!W.images||W.images.length===0)?null:e.jsx(ns,{$isUser:W.role==="user",children:e.jsxs(Rd,{$isUser:W.role==="user",children:[e.jsx("div",{children:W.content}),W.images&&W.images.length>0&&e.jsx("div",{style:{display:"flex",gap:"8px",marginTop:"8px",flexWrap:"wrap"},children:W.images.map((Se,Ve)=>{const Ae=Se.url||`data:${Se.mime_type};base64,${Se.data}`;return e.jsxs(oy,{onClick:()=>ue(Ae),title:"Click to preview",children:[e.jsx("img",{src:Ae,alt:`Image ${Ve+1}`,loading:"lazy"}),e.jsx("div",{className:"expand-icon",children:e.jsx(_h,{size:14})})]},Ve)})}),W.isStreaming&&e.jsx(Ab,{})]})},W.id)}),L&&e.jsx(ns,{$isUser:!0,children:e.jsxs(Lb,{$isUser:!0,children:[e.jsx("div",{children:L}),I&&I.length>0&&e.jsx("div",{style:{display:"flex",gap:"8px",marginTop:"8px",flexWrap:"wrap"},children:I.map((W,F)=>e.jsx("div",{style:{width:"200px",height:"200px",borderRadius:"8px",border:"1px solid var(--color-border)",overflow:"hidden",backgroundColor:"var(--color-background-subtle)",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("img",{src:W.data?`data:${W.mime_type};base64,${W.data}`:"#",alt:`Image ${F+1}`,style:{maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",objectFit:"contain"},loading:"lazy"})},F))})]})}),e.jsx("div",{ref:M})]})}),z.length>0&&e.jsx(Gb,{children:z.map((W,F)=>e.jsxs(Hb,{children:[e.jsx("img",{src:W.data?`data:${W.mime_type};base64,${W.data}`:"#",alt:`Upload ${F+1}`}),e.jsx(qb,{type:"button",onClick:()=>X(F),children:e.jsx(ct,{size:12})})]},F))}),e.jsx(Fb,{onSubmit:re,children:e.jsxs(Bb,{children:[e.jsxs(Ub,{children:[e.jsx(Wb,{value:p,onChange:W=>x(W.target.value),onKeyDown:W=>{W.key==="Enter"&&!W.shiftKey&&(W.preventDefault(),re(W))},placeholder:le(),disabled:!q||Y&&!H||ee(),rows:1}),e.jsx(Vb,{children:e.jsxs(Zb,{type:"button",disabled:!q||Y,onClick:()=>{var W;return(W=N.current)==null?void 0:W.click()},children:[e.jsx(Nh,{size:16}),"Attach"]})}),e.jsx(Yb,{ref:N,type:"file",accept:"image/*",multiple:!0,onChange:fe})]}),e.jsx(Kb,{type:Y?"button":"submit",disabled:!q||!H&&!Y&&!p.trim(),onClick:Y?oe:void 0,onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),style:{background:Y&&m?"var(--color-error)":void 0},children:Y?m?e.jsx(ct,{size:14}):e.jsx(bt,{size:14,className:"animate-spin"}):e.jsx(Ds,{size:14})})]})})]}),e.jsx(ny,{isOpen:!!w,imageUrl:w,zoomLevel:f,dragPosition:T,isDragging:S,onClose:ve,onDownload:()=>w&&pe(w),onZoom:U,onReset:()=>{$(1),R({x:0,y:0})},onWheel:ce,onMouseDown:Q,onMouseMove:Z,onMouseUp:ne})]})}const sy=l.div`
|
|
5784
|
+
`,ny=({isOpen:t,imageUrl:r,zoomLevel:o,dragPosition:n,isDragging:s,onClose:a,onDownload:h,onZoom:g,onReset:c,onWheel:u,onMouseDown:d,onMouseMove:p,onMouseUp:x})=>{const[m,v]=i.useState(!1),b=i.useRef(null);return i.useEffect(()=>(v(!0),()=>v(!1)),[]),i.useEffect(()=>{if(t){const _=document.body.style.overflow;document.body.style.overflow="hidden";const k=E=>{(E.ctrlKey||E.metaKey)&&E.preventDefault()},C=E=>{E.preventDefault()},z=E=>{E.preventDefault()};return document.addEventListener("wheel",k,{passive:!1}),document.addEventListener("gesturestart",C,{passive:!1}),document.addEventListener("gesturechange",z,{passive:!1}),()=>{document.body.style.overflow=_,document.removeEventListener("wheel",k),document.removeEventListener("gesturestart",C),document.removeEventListener("gesturechange",z)}}},[t]),!m||!t||!r?null:Qr.createPortal(e.jsx(ge,{children:e.jsx(Qb,{ref:b,$isOpen:!0,onClick:_=>{_.target===_.currentTarget&&a()},children:e.jsxs(Jb,{onClick:_=>_.stopPropagation(),onWheel:_=>{_.preventDefault(),_.stopPropagation(),u(_)},onMouseMove:p,onMouseUp:x,onMouseLeave:x,children:[e.jsx(Xb,{src:r,alt:"Preview",$zoom:o,$x:n.x,$y:n.y,$isDragging:s,onMouseDown:d,draggable:!1}),e.jsx(Oo,{$variant:"ghost",onClick:a,title:"Close",style:{position:"absolute",top:"16px",right:"16px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:e.jsx(ct,{size:14})}),e.jsxs(ey,{children:[e.jsxs(ty,{children:[e.jsx(Oo,{$variant:"ghost",onClick:()=>g(-.25),title:"Zoom out",disabled:o<=.5,children:e.jsx(of,{size:14})}),e.jsxs(ry,{children:[Math.round(o*100),"%"]}),e.jsx(Oo,{$variant:"ghost",onClick:()=>g(.25),title:"Zoom in",disabled:o>=3,children:e.jsx(tf,{size:14})}),e.jsx(Oo,{$variant:"ghost",onClick:c,title:"Reset zoom",children:e.jsx(Ah,{size:14})})]}),e.jsxs(Td,{$variant:"primary",onClick:h,title:"Download image",children:[e.jsx(ln,{size:14}),"Download"]})]})]})})}),document.body)};function Md({showBackButton:t=!1,onBack:r}){const{agentName:o,token:n,platformAdapter:s,selectedSession:a,selectSession:h}=Xo(),g=a==null?void 0:a.id;if(!g)return e.jsx(ge,{style:{height:"100%",width:"100%"},children:e.jsx(_c,{children:e.jsxs(kc,{children:[e.jsx(Pn,{size:48,strokeWidth:1.5}),e.jsx("p",{children:"No conversation selected"})]})})});const c=!0,u=!0,d="Start a conversation by typing a message below",[p,x]=i.useState(""),[m,v]=i.useState(!1),[b,_]=i.useState(null),[k,C]=i.useState([]),[z,E]=i.useState([]),[w,y]=i.useState(null),[f,$]=i.useState(1),[S,j]=i.useState(!1),[T,R]=i.useState({x:0,y:0}),[O,P]=i.useState({x:0,y:0}),M=i.useRef(null),N=i.useRef(null),{messages:D,pendingMessage:L,pendingImages:I,connectionState:A,isConnected:q,isExecuting:Y,executionStatus:B,isWaitingForInput:H,sendMessage:V,submitUserInput:J,cancelExecution:oe}=Yc({contextId:g,agentName:o,token:n,platformAdapter:s,autoConnect:c});i.useEffect(()=>{var W;(W=M.current)==null||W.scrollIntoView({behavior:"smooth"})},[D]),i.useEffect(()=>{var W;if(H){const F=D.slice().reverse().find(se=>{var be;return((be=se.metadata)==null?void 0:be.type)==="user_input_request"});(W=F==null?void 0:F.metadata)!=null&&W.userInputRequest&&_(F.metadata.userInputRequest)}else _(null),C([])},[H,D]);const re=W=>{if(W.preventDefault(),!!q)if(H&&b){let F=p.trim();b.input_type==="multiselect"&&(F=k.join(",")),F&&(J(F),x(""),C([]))}else!Y&&p.trim()&&(V(p,z.length>0?z:void 0),x(""),E([]))},fe=W=>{const F=W.target.files;F&&(Array.from(F).forEach(se=>{if(se.type.startsWith("image/")){const be=new FileReader;be.onload=Oe=>{var Fe;if((Fe=Oe.target)!=null&&Fe.result){const Ve=Oe.target.result.split(",")[1];E(Ae=>[...Ae,{mime_type:se.type,data:Ve}])}},be.readAsDataURL(se)}}),N.current&&(N.current.value=""))},X=W=>{E(F=>F.filter((se,be)=>be!==W))},ue=W=>{y(W),$(1),R({x:0,y:0})},ve=()=>{y(null),$(1),R({x:0,y:0}),j(!1)},pe=W=>{const F=document.createElement("a");F.href=W,F.download=`image-${Date.now()}.png`,document.body.appendChild(F),F.click(),document.body.removeChild(F)},U=W=>{$(F=>{const se=F+W;return Math.min(Math.max(se,.5),3)})},le=W=>{W.preventDefault(),W.stopPropagation();const F=W.deltaY>0?-.1:.1;U(F)},Q=W=>{f>1&&(j(!0),P({x:W.clientX-T.x,y:W.clientY-T.y}))},Z=W=>{S&&f>1&&R({x:W.clientX-O.x,y:W.clientY-O.y})},ne=()=>{j(!1)},me=()=>A.status===Pt.CONNECTING?"Connecting...":A.status===Pt.ERROR?"Connection error":A.status===Pt.DISCONNECTED||!q?"Disconnected":H?"Waiting for your input...":Y?"Working...":"Ready",de=()=>{if(!H||!b)return"Ask anything";switch(b.input_type){case"select":case"boolean":case"date":return"Use controls above to make selection";case"multiselect":return"Select options above";default:return"Enter your response..."}},ee=()=>!H||!b?!1:["select","multiselect","boolean","date"].includes(b.input_type||"");return e.jsxs(ge,{style:{height:"100%",width:"100%"},children:[e.jsxs(_c,{children:[e.jsxs(Cb,{children:[e.jsxs(Sb,{children:[t&&e.jsx(zb,{onClick:()=>{r?r():h(null)},children:e.jsx(Xr,{size:20})}),e.jsxs($b,{children:[e.jsx(Eb,{children:e.jsx(Pn,{size:20})}),e.jsxs(Ib,{children:[e.jsx(Rb,{children:o}),e.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[e.jsx(Pb,{$status:me()}),e.jsx(Tb,{$status:me(),children:me()})]})]})]})]}),B!==Ge.IDLE&&e.jsx(Mb,{$status:B,children:B.replace("_"," ")})]}),e.jsx(Ob,{children:D.length===0&&u?e.jsxs(kc,{children:[e.jsx(Pn,{size:48,strokeWidth:1.5}),e.jsx("p",{children:d})]}):e.jsxs(e.Fragment,{children:[D.map((W,F)=>{var se,be,Oe,Fe;if(((se=W.metadata)==null?void 0:se.type)==="user_input_request"&&W.metadata.userInputRequest){const Se=W.metadata.userInputRequest,Ve=!Se.input_type||Se.input_type==="text"||Se.input_type==="number",Ae=H&&(b==null?void 0:b.input_type)===Se.input_type;return e.jsx(ns,{$isUser:!1,children:e.jsxs(Nb,{children:[e.jsx("div",{className:"question",children:Se.question}),Se.context&&Se.context.trim()&&e.jsx("div",{className:"context",children:Se.context}),!Ve&&e.jsxs("div",{className:"controls",children:[Se.input_type==="select"&&Se.options&&e.jsxs("select",{value:Ae?p:"",onChange:te=>x(te.target.value),disabled:!Ae,children:[e.jsx("option",{value:"",children:"Choose an option..."}),Se.options.map(te=>e.jsx("option",{value:te,children:te},te))]}),Se.input_type==="multiselect"&&Se.options&&e.jsx("div",{className:"checkbox-group",children:Se.options.map(te=>e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:Ae&&k.includes(te),onChange:xe=>{xe.target.checked?C([...k,te]):C(k.filter(_e=>_e!==te))},disabled:!Ae}),e.jsx("span",{children:te})]},te))}),Se.input_type==="boolean"&&e.jsxs("div",{className:"radio-group",children:[e.jsxs("label",{className:"radio-label",children:[e.jsx("input",{type:"radio",name:"boolean",value:"true",checked:Ae&&p==="true",onChange:te=>x(te.target.value),disabled:!Ae}),e.jsx("span",{children:"Yes"})]}),e.jsxs("label",{className:"radio-label",children:[e.jsx("input",{type:"radio",name:"boolean",value:"false",checked:Ae&&p==="false",onChange:te=>x(te.target.value),disabled:!Ae}),e.jsx("span",{children:"No"})]})]}),Se.input_type==="date"&&e.jsx("input",{type:"date",value:Ae?p:"",onChange:te=>x(te.target.value),disabled:!Ae})]}),e.jsx("div",{className:"instruction",children:Ae?Ve?"Type your response below":Se.input_type==="multiselect"?"Select options above and click send":"Make your selection above and click send":""})]})},W.id)}if(((be=W.metadata)==null?void 0:be.type)==="log"){const Se=D[F-1],Ve=D[F+1],Ae=((Oe=Se==null?void 0:Se.metadata)==null?void 0:Oe.type)==="log",te=((Fe=Ve==null?void 0:Ve.metadata)==null?void 0:Fe.type)==="log",xe=Ae||te,_e=!Ae&&te,Ce=Ae&&!te;return e.jsx(Db,{$isGrouped:xe,$isFirstInGroup:_e,$isLastInGroup:Ce,children:e.jsx("div",{className:"log-content",children:W.content})},W.id)}return!W.content&&(!W.images||W.images.length===0)?null:e.jsx(ns,{$isUser:W.role==="user",children:e.jsxs(Rd,{$isUser:W.role==="user",children:[e.jsx("div",{children:W.content}),W.images&&W.images.length>0&&e.jsx("div",{style:{display:"flex",gap:"8px",marginTop:"8px",flexWrap:"wrap"},children:W.images.map((Se,Ve)=>{const Ae=Se.url||`data:${Se.mime_type};base64,${Se.data}`;return e.jsxs(oy,{onClick:()=>ue(Ae),title:"Click to preview",children:[e.jsx("img",{src:Ae,alt:`Image ${Ve+1}`,loading:"lazy"}),e.jsx("div",{className:"expand-icon",children:e.jsx(_h,{size:14})})]},Ve)})}),W.isStreaming&&e.jsx(Ab,{})]})},W.id)}),L&&e.jsx(ns,{$isUser:!0,children:e.jsxs(Lb,{$isUser:!0,children:[e.jsx("div",{children:L}),I&&I.length>0&&e.jsx("div",{style:{display:"flex",gap:"8px",marginTop:"8px",flexWrap:"wrap"},children:I.map((W,F)=>e.jsx("div",{style:{width:"200px",height:"200px",borderRadius:"8px",border:"1px solid var(--color-border)",overflow:"hidden",backgroundColor:"var(--color-background-subtle)",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("img",{src:W.data?`data:${W.mime_type};base64,${W.data}`:"#",alt:`Image ${F+1}`,style:{maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",objectFit:"contain"},loading:"lazy"})},F))})]})}),e.jsx("div",{ref:M})]})}),z.length>0&&e.jsx(Gb,{children:z.map((W,F)=>e.jsxs(Hb,{children:[e.jsx("img",{src:W.data?`data:${W.mime_type};base64,${W.data}`:"#",alt:`Upload ${F+1}`}),e.jsx(qb,{type:"button",onClick:()=>X(F),children:e.jsx(ct,{size:12})})]},F))}),e.jsx(Fb,{onSubmit:re,children:e.jsxs(Bb,{children:[e.jsxs(Ub,{children:[e.jsx(Wb,{value:p,onChange:W=>x(W.target.value),onKeyDown:W=>{W.key==="Enter"&&!W.shiftKey&&(W.preventDefault(),re(W))},placeholder:de(),disabled:!q||Y&&!H||ee(),rows:1}),e.jsx(Vb,{children:e.jsxs(Zb,{type:"button",disabled:!q||Y,onClick:()=>{var W;return(W=N.current)==null?void 0:W.click()},children:[e.jsx(Nh,{size:16}),"Attach"]})}),e.jsx(Yb,{ref:N,type:"file",accept:"image/*",multiple:!0,onChange:fe})]}),e.jsx(Kb,{type:Y?"button":"submit",disabled:!q||!H&&!Y&&!p.trim(),onClick:Y?oe:void 0,onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),style:{background:Y&&m?"var(--color-error)":void 0},children:Y?m?e.jsx(ct,{size:14}):e.jsx(bt,{size:14,className:"animate-spin"}):e.jsx(Ds,{size:14})})]})})]}),e.jsx(ny,{isOpen:!!w,imageUrl:w,zoomLevel:f,dragPosition:T,isDragging:S,onClose:ve,onDownload:()=>w&&pe(w),onZoom:U,onReset:()=>{$(1),R({x:0,y:0})},onWheel:le,onMouseDown:Q,onMouseMove:Z,onMouseUp:ne})]})}const sy=l.div`
|
|
5785
5785
|
height: 100%;
|
|
5786
5786
|
display: flex;
|
|
5787
5787
|
flex-direction: column;
|
|
@@ -6134,5 +6134,5 @@ cursor: pointer;
|
|
|
6134
6134
|
display: flex;
|
|
6135
6135
|
flex-direction: column;
|
|
6136
6136
|
gap: var(--space-xs);
|
|
6137
|
-
`;function Vy(){const[t,r]=i.useState(!1),{sessions:o,selectedSession:n,showHistory:s,selectSession:a,createSession:h,setShowHistory:g}=Xo(),c=async()=>{try{r(!0),await h()}finally{r(!1)}},u=d=>{try{const p=new Date(d),m=new Date().getTime()-p.getTime(),v=Math.floor(m/6e4),b=Math.floor(v/60),_=Math.floor(b/24);return _>0?`${_}d ago`:b>0?`${b}h ago`:v>0?`${v}m ago`:"Just now"}catch{return""}};return s?e.jsx(Od,{showBackButton:!0}):n?e.jsx(Md,{showBackButton:!0}):e.jsx(ge,{style:{height:"100%",width:"100%"},children:e.jsx($y,{children:e.jsxs(Ey,{children:[e.jsx(Iy,{children:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),e.jsx(Py,{children:"Hi there! 👋"}),e.jsx(Ry,{children:"How can I help you today?"}),e.jsx(Ty,{onClick:c,disabled:t,children:t?e.jsxs(e.Fragment,{children:["Starting",e.jsx(My,{})]}):"Start a conversation"}),o.length>0&&e.jsxs(Ny,{children:[e.jsxs(Fy,{children:[e.jsx(By,{children:"Recent Chats"}),e.jsx(Uy,{onClick:()=>g(!0),children:"View All →"})]}),e.jsx(Wy,{children:o.slice(0,2).map(d=>e.jsx(Oy,{onClick:()=>a(d),children:e.jsxs(Dy,{children:[e.jsx(Ay,{children:d.title}),e.jsxs(Ly,{children:[e.jsx("span",{children:u(d.last_activity_at)}),d.status==="running"&&e.jsx("span",{children:"• Active"})]})]})},d.id))})]})]})})})}const Gy=t=>{const r=t.toLowerCase().trim();return["javascript:","data:","vbscript:"].some(s=>r.startsWith(s))?!0:["http://","https://","//","ftp://","ftps://","mailto:","tel:","sms:","file:","blob:"].some(s=>r.startsWith(s))},Hy=t=>{const r=t.toLowerCase().trim();return!["javascript:","data:","vbscript:"].some(n=>r.startsWith(n))};exports.AcceptInvite=Qm;exports.AgentConversation=Md;exports.AgentConversationHistory=Od;exports.AgentConversationHub=Vy;exports.AgentConversationProvider=xu;exports.AuthFormImage=Me;exports.ChannelSelector=kb;exports.CreateOrganizationForm=fn;exports.CreateWorkspaceDialog=td;exports.CreateWorkspaceForm=Ws;exports.DeploymentInitialized=qu;exports.DeploymentInitializing=Yu;exports.DeploymentProvider=Dd;exports.Dialog=ze;exports.DialogTrigger=Xf;exports.Dropdown=ht;exports.DropdownDivider=hn;exports.DropdownItem=De;exports.DropdownItems=ft;exports.DropdownTrigger=gt;exports.Form=yt;exports.FormGroup=he;exports.Input=
|
|
6137
|
+
`;function Vy(){const[t,r]=i.useState(!1),{sessions:o,selectedSession:n,showHistory:s,selectSession:a,createSession:h,setShowHistory:g}=Xo(),c=async()=>{try{r(!0),await h()}finally{r(!1)}},u=d=>{try{const p=new Date(d),m=new Date().getTime()-p.getTime(),v=Math.floor(m/6e4),b=Math.floor(v/60),_=Math.floor(b/24);return _>0?`${_}d ago`:b>0?`${b}h ago`:v>0?`${v}m ago`:"Just now"}catch{return""}};return s?e.jsx(Od,{showBackButton:!0}):n?e.jsx(Md,{showBackButton:!0}):e.jsx(ge,{style:{height:"100%",width:"100%"},children:e.jsx($y,{children:e.jsxs(Ey,{children:[e.jsx(Iy,{children:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),e.jsx(Py,{children:"Hi there! 👋"}),e.jsx(Ry,{children:"How can I help you today?"}),e.jsx(Ty,{onClick:c,disabled:t,children:t?e.jsxs(e.Fragment,{children:["Starting",e.jsx(My,{})]}):"Start a conversation"}),o.length>0&&e.jsxs(Ny,{children:[e.jsxs(Fy,{children:[e.jsx(By,{children:"Recent Chats"}),e.jsx(Uy,{onClick:()=>g(!0),children:"View All →"})]}),e.jsx(Wy,{children:o.slice(0,2).map(d=>e.jsx(Oy,{onClick:()=>a(d),children:e.jsxs(Dy,{children:[e.jsx(Ay,{children:d.title}),e.jsxs(Ly,{children:[e.jsx("span",{children:u(d.last_activity_at)}),d.status==="running"&&e.jsx("span",{children:"• Active"})]})]})},d.id))})]})]})})})}const Gy=t=>{const r=t.toLowerCase().trim();return["javascript:","data:","vbscript:"].some(s=>r.startsWith(s))?!0:["http://","https://","//","ftp://","ftps://","mailto:","tel:","sms:","file:","blob:"].some(s=>r.startsWith(s))},Hy=t=>{const r=t.toLowerCase().trim();return!["javascript:","data:","vbscript:"].some(n=>r.startsWith(n))};exports.AcceptInvite=Qm;exports.AgentConversation=Md;exports.AgentConversationHistory=Od;exports.AgentConversationHub=Vy;exports.AgentConversationProvider=xu;exports.AuthFormImage=Me;exports.ChannelSelector=kb;exports.CreateOrganizationForm=fn;exports.CreateWorkspaceDialog=td;exports.CreateWorkspaceForm=Ws;exports.DeploymentInitialized=qu;exports.DeploymentInitializing=Yu;exports.DeploymentProvider=Dd;exports.Dialog=ze;exports.DialogTrigger=Xf;exports.Dropdown=ht;exports.DropdownDivider=hn;exports.DropdownItem=De;exports.DropdownItems=ft;exports.DropdownTrigger=gt;exports.Form=yt;exports.FormGroup=he;exports.Input=ce;exports.Label=ie;exports.MagicLinkVerification=Vm;exports.ManageAccount=Cd;exports.ManageAccountDialog=Sd;exports.ManageOrganization=Jl;exports.ManageWorkspace=od;exports.ManageWorkspaceDialog=nd;exports.NavigateToSignIn=nb;exports.NavigateToSignUp=sb;exports.NavigationLink=pt;exports.NotificationBell=Id;exports.NotificationItem=$d;exports.NotificationPopover=Ed;exports.OAuthProvider=Lc;exports.ORG_ADMIN_PERMISSIONS=ad;exports.ORG_MANAGEMENT_PERMISSIONS=id;exports.OTPInput=Gt;exports.OrganizationSwitcher=ud;exports.PhoneNumberInput=eo;exports.PhoneVerification=Vl;exports.ProfileCompletion=Hl;exports.RequireActiveTenancy=bb;exports.SSOCallback=Om;exports.SignInForm=gm;exports.SignUpForm=Df;exports.SignedIn=U1;exports.SignedInAccounts=ob;exports.SignedOut=W1;exports.SimpleDialog=Jf;exports.Spinner=Ie;exports.Switch=fr;exports.TwoFactorMethodSelector=Wl;exports.TwoFactorVerification=Gl;exports.UserButton=Ys;exports.UserControls=B1;exports.WORKSPACE_ADMIN_PERMISSIONS=cd;exports.WORKSPACE_MANAGEMENT_PERMISSIONS=ld;exports.WaitlistForm=Im;exports.canManageOrganization=dd;exports.canManageWorkspace=zs;exports.clearTokenCache=Tt;exports.fetchChannelCounts=Bu;exports.hasIncompleteProfile=Gm;exports.hasOrgPermission=Gs;exports.hasWorkspacePermission=Hs;exports.isExternalUrl=Gy;exports.isOrgAdmin=Q0;exports.isSafeUrl=Hy;exports.isWorkspaceAdmin=J0;exports.redirectToProfileCompletion=Hm;exports.useActiveOrganization=nt;exports.useActiveTenancy=Nu;exports.useActiveWorkspace=Ut;exports.useAgentConversation=Yc;exports.useAgentConversationContext=Xo;exports.useChannelCounts=Hu;exports.useClient=Ze;exports.useConversationSessions=Oc;exports.useDeployment=ye;exports.useForgotPassword=Gc;exports.useInvitation=Zc;exports.useMagicLinkParams=Vc;exports.useMagicLinkVerification=Wc;exports.useNavigation=tt;exports.useNotificationStream=Hc;exports.useNotifications=qc;exports.useOrganizationList=en;exports.useOrganizationMemberships=Mt;exports.useSSOCallback=Uc;exports.useSession=Ke;exports.useSignIn=Dc;exports.useSignInWithStrategy=Sr;exports.useSignUp=Nc;exports.useUser=Wt;exports.useUserSignins=Fc;exports.useWaitlist=Bc;exports.useWorkspaceList=Bt;exports.useWorkspaceMemberships=tn;Object.keys(ia).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>ia[t]})});
|
|
6138
6138
|
//# sourceMappingURL=index.cjs.js.map
|