heyio 4.1.4 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -446,7 +446,7 @@ ${k}`}class Zt extends Error{constructor({message:e,code:r,cause:n,name:i}){var
446
446
  `);const O=await C.signMessage(new TextEncoder().encode(b),"utf8");if(!O||!(O instanceof Uint8Array))throw new Error("@supabase/auth-js: Wallet signMessage() API returned an recognized value");w=O}}try{const{data:x,error:k}=await Ne(this.fetch,"POST",`${this.url}/token?grant_type=web3`,{headers:this.headers,body:Object.assign({chain:"solana",message:b,signature:ko(w)},!((m=e.options)===null||m===void 0)&&m.captchaToken?{gotrue_meta_security:{captcha_token:(v=e.options)===null||v===void 0?void 0:v.captchaToken}}:null),xform:En});if(k)throw k;if(!x||!x.session||!x.user){const S=new ws;return this._returnResult({data:{user:null,session:null},error:S})}return x.session&&(await this._saveSession(x.session),await this._notifyAllSubscribers("SIGNED_IN",x.session)),this._returnResult({data:Object.assign({},x),error:k})}catch(x){if(be(x))return this._returnResult({data:{user:null,session:null},error:x});throw x}}async _exchangeCodeForSession(e){const r=await Di(this.storage,`${this.storageKey}-code-verifier`),[n,i]=(r??"").split("/");try{if(!n&&this.flowType==="pkce")throw new b6;const{data:a,error:o}=await Ne(this.fetch,"POST",`${this.url}/token?grant_type=pkce`,{headers:this.headers,body:{auth_code:e,code_verifier:n},xform:En});if(await nr(this.storage,`${this.storageKey}-code-verifier`),o)throw o;if(!a||!a.session||!a.user){const c=new ws;return this._returnResult({data:{user:null,session:null,redirectType:null},error:c})}return a.session&&(await this._saveSession(a.session),await this._notifyAllSubscribers(i==="recovery"?"PASSWORD_RECOVERY":"SIGNED_IN",a.session)),this._returnResult({data:Object.assign(Object.assign({},a),{redirectType:i??null}),error:o})}catch(a){if(await nr(this.storage,`${this.storageKey}-code-verifier`),be(a))return this._returnResult({data:{user:null,session:null,redirectType:null},error:a});throw a}}async signInWithIdToken(e){try{const{options:r,provider:n,token:i,access_token:a,nonce:o}=e,c=await Ne(this.fetch,"POST",`${this.url}/token?grant_type=id_token`,{headers:this.headers,body:{provider:n,id_token:i,access_token:a,nonce:o,gotrue_meta_security:{captcha_token:r==null?void 0:r.captchaToken}},xform:En}),{data:u,error:d}=c;if(d)return this._returnResult({data:{user:null,session:null},error:d});if(!u||!u.session||!u.user){const p=new ws;return this._returnResult({data:{user:null,session:null},error:p})}return u.session&&(await this._saveSession(u.session),await this._notifyAllSubscribers("SIGNED_IN",u.session)),this._returnResult({data:u,error:d})}catch(r){if(be(r))return this._returnResult({data:{user:null,session:null},error:r});throw r}}async signInWithOtp(e){var r,n,i,a,o;try{if("email"in e){const{email:c,options:u}=e;let d=null,p=null;this.flowType==="pkce"&&([d,p]=await _s(this.storage,this.storageKey));const{error:f}=await Ne(this.fetch,"POST",`${this.url}/otp`,{headers:this.headers,body:{email:c,data:(r=u==null?void 0:u.data)!==null&&r!==void 0?r:{},create_user:(n=u==null?void 0:u.shouldCreateUser)!==null&&n!==void 0?n:!0,gotrue_meta_security:{captcha_token:u==null?void 0:u.captchaToken},code_challenge:d,code_challenge_method:p},redirectTo:u==null?void 0:u.emailRedirectTo});return this._returnResult({data:{user:null,session:null},error:f})}if("phone"in e){const{phone:c,options:u}=e,{data:d,error:p}=await Ne(this.fetch,"POST",`${this.url}/otp`,{headers:this.headers,body:{phone:c,data:(i=u==null?void 0:u.data)!==null&&i!==void 0?i:{},create_user:(a=u==null?void 0:u.shouldCreateUser)!==null&&a!==void 0?a:!0,gotrue_meta_security:{captcha_token:u==null?void 0:u.captchaToken},channel:(o=u==null?void 0:u.channel)!==null&&o!==void 0?o:"sms"}});return this._returnResult({data:{user:null,session:null,messageId:d==null?void 0:d.message_id},error:p})}throw new ff("You must provide either an email or phone number.")}catch(c){if(await nr(this.storage,`${this.storageKey}-code-verifier`),be(c))return this._returnResult({data:{user:null,session:null},error:c});throw c}}async verifyOtp(e){var r,n;try{let i,a;"options"in e&&(i=(r=e.options)===null||r===void 0?void 0:r.redirectTo,a=(n=e.options)===null||n===void 0?void 0:n.captchaToken);const{data:o,error:c}=await Ne(this.fetch,"POST",`${this.url}/verify`,{headers:this.headers,body:Object.assign(Object.assign({},e),{gotrue_meta_security:{captcha_token:a}}),redirectTo:i,xform:En});if(c)throw c;if(!o)throw new Error("An error occurred on token verification.");const u=o.session,d=o.user;return u!=null&&u.access_token&&(await this._saveSession(u),await this._notifyAllSubscribers(e.type=="recovery"?"PASSWORD_RECOVERY":"SIGNED_IN",u)),this._returnResult({data:{user:d,session:u},error:null})}catch(i){if(be(i))return this._returnResult({data:{user:null,session:null},error:i});throw i}}async signInWithSSO(e){var r,n,i,a,o;try{let c=null,u=null;this.flowType==="pkce"&&([c,u]=await _s(this.storage,this.storageKey));const d=await Ne(this.fetch,"POST",`${this.url}/sso`,{body:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},"providerId"in e?{provider_id:e.providerId}:null),"domain"in e?{domain:e.domain}:null),{redirect_to:(n=(r=e.options)===null||r===void 0?void 0:r.redirectTo)!==null&&n!==void 0?n:void 0}),!((i=e==null?void 0:e.options)===null||i===void 0)&&i.captchaToken?{gotrue_meta_security:{captcha_token:e.options.captchaToken}}:null),{skip_http_redirect:!0,code_challenge:c,code_challenge_method:u}),headers:this.headers,xform:W6});return!((a=d.data)===null||a===void 0)&&a.url&&Tr()&&!(!((o=e.options)===null||o===void 0)&&o.skipBrowserRedirect)&&window.location.assign(d.data.url),this._returnResult(d)}catch(c){if(await nr(this.storage,`${this.storageKey}-code-verifier`),be(c))return this._returnResult({data:null,error:c});throw c}}async reauthenticate(){return await this.initializePromise,this.lock!=null?await this._acquireLock(this.lockAcquireTimeout,async()=>await this._reauthenticate()):await this._reauthenticate()}async _reauthenticate(){try{return await this._useSession(async e=>{const{data:{session:r},error:n}=e;if(n)throw n;if(!r)throw new mr;const{error:i}=await Ne(this.fetch,"GET",`${this.url}/reauthenticate`,{headers:this.headers,jwt:r.access_token});return this._returnResult({data:{user:null,session:null},error:i})})}catch(e){if(be(e))return this._returnResult({data:{user:null,session:null},error:e});throw e}}async resend(e){try{const r=`${this.url}/resend`;if("email"in e){const{email:n,type:i,options:a}=e,{error:o}=await Ne(this.fetch,"POST",r,{headers:this.headers,body:{email:n,type:i,gotrue_meta_security:{captcha_token:a==null?void 0:a.captchaToken}},redirectTo:a==null?void 0:a.emailRedirectTo});return this._returnResult({data:{user:null,session:null},error:o})}else if("phone"in e){const{phone:n,type:i,options:a}=e,{data:o,error:c}=await Ne(this.fetch,"POST",r,{headers:this.headers,body:{phone:n,type:i,gotrue_meta_security:{captcha_token:a==null?void 0:a.captchaToken}}});return this._returnResult({data:{user:null,session:null,messageId:o==null?void 0:o.message_id},error:c})}throw new ff("You must provide either an email or phone number and a type")}catch(r){if(be(r))return this._returnResult({data:{user:null,session:null},error:r});throw r}}async getSession(){return await this.initializePromise,this.lock!=null?await this._acquireLock(this.lockAcquireTimeout,async()=>this._useSession(async e=>e)):await this._useSession(async e=>e)}async _acquireLock(e,r){this._debug("#_acquireLock","begin",e);try{if(this.lockAcquired){const n=this.pendingInLock.length?this.pendingInLock[this.pendingInLock.length-1]:Promise.resolve(),i=(async()=>(await n,await r()))();return this.pendingInLock.push((async()=>{try{await i}catch{}})()),i}return await this.lock(`lock:${this.storageKey}`,e,async()=>{this._debug("#_acquireLock","lock acquired for storage key",this.storageKey);try{this.lockAcquired=!0;const n=r();for(this.pendingInLock.push((async()=>{try{await n}catch{}})()),await n;this.pendingInLock.length;){const i=[...this.pendingInLock];await Promise.all(i),this.pendingInLock.splice(0,i.length)}return await n}finally{this._debug("#_acquireLock","lock released for storage key",this.storageKey),this.lockAcquired=!1}})}finally{this._debug("#_acquireLock","end")}}async _useSession(e){this._debug("#_useSession","begin");try{const r=await this.__loadSession();return await e(r)}finally{this._debug("#_useSession","end")}}async __loadSession(){this._debug("#__loadSession()","begin"),this.lock!=null&&!this.lockAcquired&&this._debug("#__loadSession()","used outside of an acquired lock!",new Error().stack);try{let e=null;const r=await Di(this.storage,this.storageKey);if(this._debug("#getSession()","session from storage",r),r!==null&&(this._isValidSession(r)?e=r:(this._debug("#getSession()","session from storage is not valid"),await this._removeSession())),!e)return{data:{session:null},error:null};const n=e.expires_at?e.expires_at*1e3-Date.now()<Lg:!1;if(this._debug("#__loadSession()",`session has${n?"":" not"} expired`,"expires_at",e.expires_at),!n){if(this.userStorage){const o=await Di(this.userStorage,this.storageKey+"-user");o!=null&&o.user?e.user=o.user:e.user=Bg()}if(this.storage.isServer&&e.user&&!e.user.__isUserNotAvailableProxy){const o={value:this.suppressGetSessionWarning};e.user=U6(e.user,o),o.value&&(this.suppressGetSessionWarning=!0)}return{data:{session:e},error:null}}const{data:i,error:a}=await this._callRefreshToken(e.refresh_token);return a?this._returnResult({data:{session:null},error:a}):this._returnResult({data:{session:i},error:null})}finally{this._debug("#__loadSession()","end")}}async getUser(e){if(e)return await this._getUser(e);await this.initializePromise;let r;return this.lock!=null?r=await this._acquireLock(this.lockAcquireTimeout,async()=>await this._getUser()):r=await this._getUser(),r.data.user&&(this.suppressGetSessionWarning=!0),r}async _getUser(e){try{return e?await Ne(this.fetch,"GET",`${this.url}/user`,{headers:this.headers,jwt:e,xform:Pa}):await this._useSession(async r=>{var n,i,a;const{data:o,error:c}=r;if(c)throw c;return!(!((n=o.session)===null||n===void 0)&&n.access_token)&&!this.hasCustomAuthorizationHeader?{data:{user:null},error:new mr}:await Ne(this.fetch,"GET",`${this.url}/user`,{headers:this.headers,jwt:(a=(i=o.session)===null||i===void 0?void 0:i.access_token)!==null&&a!==void 0?a:void 0,xform:Pa})})}catch(r){if(be(r))return df(r)&&(await this._removeSession(),await nr(this.storage,`${this.storageKey}-code-verifier`)),this._returnResult({data:{user:null},error:r});throw r}}async updateUser(e,r={}){return await this.initializePromise,this.lock!=null?await this._acquireLock(this.lockAcquireTimeout,async()=>await this._updateUser(e,r)):await this._updateUser(e,r)}async _updateUser(e,r={}){try{return await this._useSession(async n=>{const{data:i,error:a}=n;if(a)throw a;if(!i.session)throw new mr;const o=i.session;let c=null,u=null;this.flowType==="pkce"&&e.email!=null&&([c,u]=await _s(this.storage,this.storageKey));const{data:d,error:p}=await Ne(this.fetch,"PUT",`${this.url}/user`,{headers:this.headers,redirectTo:r==null?void 0:r.emailRedirectTo,body:Object.assign(Object.assign({},e),{code_challenge:c,code_challenge_method:u}),jwt:o.access_token,xform:Pa});if(p)throw p;return o.user=d.user,await this._saveSession(o),await this._notifyAllSubscribers("USER_UPDATED",o),this._returnResult({data:{user:o.user},error:null})})}catch(n){if(await nr(this.storage,`${this.storageKey}-code-verifier`),be(n))return this._returnResult({data:{user:null},error:n});throw n}}async setSession(e){return await this.initializePromise,this.lock!=null?await this._acquireLock(this.lockAcquireTimeout,async()=>await this._setSession(e)):await this._setSession(e)}async _setSession(e){try{if(!e.access_token||!e.refresh_token)throw new mr;const r=Date.now()/1e3;let n=r,i=!0,a=null;const{payload:o}=pf(e.access_token);if(o.exp&&(n=o.exp,i=n<=r),i){const{data:c,error:u}=await this._callRefreshToken(e.refresh_token);if(u)return this._returnResult({data:{user:null,session:null},error:u});if(!c)return{data:{user:null,session:null},error:null};a=c}else{const{data:c,error:u}=await this._getUser(e.access_token);if(u)return this._returnResult({data:{user:null,session:null},error:u});a={access_token:e.access_token,refresh_token:e.refresh_token,user:c.user,token_type:"bearer",expires_in:n-r,expires_at:n},await this._saveSession(a),await this._notifyAllSubscribers("SIGNED_IN",a)}return this._returnResult({data:{user:a.user,session:a},error:null})}catch(r){if(be(r))return this._returnResult({data:{session:null,user:null},error:r});throw r}}async refreshSession(e){return await this.initializePromise,this.lock!=null?await this._acquireLock(this.lockAcquireTimeout,async()=>await this._refreshSession(e)):await this._refreshSession(e)}async _refreshSession(e){try{return await this._useSession(async r=>{var n;if(!e){const{data:o,error:c}=r;if(c)throw c;e=(n=o.session)!==null&&n!==void 0?n:void 0}if(!(e!=null&&e.refresh_token))throw new mr;const{data:i,error:a}=await this._callRefreshToken(e.refresh_token);return a?this._returnResult({data:{user:null,session:null},error:a}):i?this._returnResult({data:{user:i.user,session:i},error:null}):this._returnResult({data:{user:null,session:null},error:null})})}catch(r){if(be(r))return this._returnResult({data:{user:null,session:null},error:r});throw r}}async _getSessionFromURL(e,r){var n;try{if(!Tr())throw new hf("No browser detected.");if(e.error||e.error_description||e.error_code)throw new hf(e.error_description||"Error in URL with unspecified error_description",{error:e.error||"unspecified_error",code:e.error_code||"unspecified_code"});switch(r){case"implicit":if(this.flowType==="pkce")throw new _E("Not a valid PKCE flow url.");break;case"pkce":if(this.flowType==="implicit")throw new hf("Not a valid implicit grant flow url.");break;default:}if(r==="pkce"){if(this._debug("#_initialize()","begin","is PKCE flow",!0),!e.code)throw new _E("No code detected.");const{data:A,error:C}=await this._exchangeCodeForSession(e.code);if(C)throw C;const T=new URL(window.location.href);return T.searchParams.delete("code"),window.history.replaceState(window.history.state,"",T.toString()),{data:{session:A.session,redirectType:(n=A.redirectType)!==null&&n!==void 0?n:null},error:null}}const{provider_token:i,provider_refresh_token:a,access_token:o,refresh_token:c,expires_in:u,expires_at:d,token_type:p}=e;if(!o||!u||!c||!p)throw new hf("No session defined in URL");const f=Math.round(Date.now()/1e3),m=parseInt(u);let v=f+m;d&&(v=parseInt(d));const b=v-f;b*1e3<=Ca&&console.warn(`@supabase/gotrue-js: Session as retrieved from URL expires in ${b}s, should have been closer to ${m}s`);const w=v-m;f-w>=120?console.warn("@supabase/gotrue-js: Session as retrieved from URL was issued over 120s ago, URL could be stale",w,v,f):f-w<0&&console.warn("@supabase/gotrue-js: Session as retrieved from URL was issued in the future? Check the device clock for skew",w,v,f);const{data:x,error:k}=await this._getUser(o);if(k)throw k;const S={provider_token:i,provider_refresh_token:a,access_token:o,expires_in:m,expires_at:v,refresh_token:c,token_type:p,user:x.user};return window.location.hash="",this._debug("#_getSessionFromURL()","clearing window.location.hash"),this._returnResult({data:{session:S,redirectType:e.type},error:null})}catch(i){if(be(i))return this._returnResult({data:{session:null,redirectType:null},error:i});throw i}}_isImplicitGrantCallback(e){return typeof this.detectSessionInUrl=="function"?this.detectSessionInUrl(new URL(window.location.href),e):!!(e.access_token||e.error||e.error_description||e.error_code)}async _isPKCECallback(e){const r=await Di(this.storage,`${this.storageKey}-code-verifier`);return!!(e.code&&r)}async signOut(e={scope:"global"}){return await this.initializePromise,this.lock!=null?await this._acquireLock(this.lockAcquireTimeout,async()=>await this._signOut(e)):await this._signOut(e)}async _signOut({scope:e}={scope:"global"}){return await this._useSession(async r=>{var n;const{data:i,error:a}=r;if(a&&!df(a))return this._returnResult({error:a});const o=(n=i.session)===null||n===void 0?void 0:n.access_token;if(o){const{error:c}=await this.admin.signOut(o,e);if(c&&!(y6(c)&&(c.status===404||c.status===401||c.status===403)||df(c)))return this._returnResult({error:c})}return e!=="others"&&(await this._removeSession(),await nr(this.storage,`${this.storageKey}-code-verifier`)),this._returnResult({error:null})})}onAuthStateChange(e){const r=O6(),n={id:r,callback:e,unsubscribe:()=>{this._debug("#unsubscribe()","state change callback with id removed",r),this.stateChangeEmitters.delete(r)}};return this._debug("#onAuthStateChange()","registered callback with id",r),this.stateChangeEmitters.set(r,n),(async()=>(await this.initializePromise,this.lock!=null?await this._acquireLock(this.lockAcquireTimeout,async()=>{this._emitInitialSession(r)}):await this._emitInitialSession(r)))(),{data:{subscription:n}}}async _emitInitialSession(e){return await this._useSession(async r=>{var n,i;try{const{data:{session:a},error:o}=r;if(o)throw o;await((n=this.stateChangeEmitters.get(e))===null||n===void 0?void 0:n.callback("INITIAL_SESSION",a)),this._debug("INITIAL_SESSION","callback id",e,"session",a)}catch(a){await((i=this.stateChangeEmitters.get(e))===null||i===void 0?void 0:i.callback("INITIAL_SESSION",null)),this._debug("INITIAL_SESSION","callback id",e,"error",a),df(a)?console.warn(a):console.error(a)}})}async resetPasswordForEmail(e,r={}){let n=null,i=null;this.flowType==="pkce"&&([n,i]=await _s(this.storage,this.storageKey,!0));try{return await Ne(this.fetch,"POST",`${this.url}/recover`,{body:{email:e,code_challenge:n,code_challenge_method:i,gotrue_meta_security:{captcha_token:r.captchaToken}},headers:this.headers,redirectTo:r.redirectTo})}catch(a){if(await nr(this.storage,`${this.storageKey}-code-verifier`),be(a))return this._returnResult({data:null,error:a});throw a}}async getUserIdentities(){var e;try{const{data:r,error:n}=await this.getUser();if(n)throw n;return this._returnResult({data:{identities:(e=r.user.identities)!==null&&e!==void 0?e:[]},error:null})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async linkIdentity(e){return"token"in e?this.linkIdentityIdToken(e):this.linkIdentityOAuth(e)}async linkIdentityOAuth(e){var r;try{const{data:n,error:i}=await this._useSession(async a=>{var o,c,u,d,p;const{data:f,error:m}=a;if(m)throw m;const v=await this._getUrlForProvider(`${this.url}/user/identities/authorize`,e.provider,{redirectTo:(o=e.options)===null||o===void 0?void 0:o.redirectTo,scopes:(c=e.options)===null||c===void 0?void 0:c.scopes,queryParams:(u=e.options)===null||u===void 0?void 0:u.queryParams,skipBrowserRedirect:!0});return await Ne(this.fetch,"GET",v,{headers:this.headers,jwt:(p=(d=f.session)===null||d===void 0?void 0:d.access_token)!==null&&p!==void 0?p:void 0})});if(i)throw i;return Tr()&&!(!((r=e.options)===null||r===void 0)&&r.skipBrowserRedirect)&&window.location.assign(n==null?void 0:n.url),this._returnResult({data:{provider:e.provider,url:n==null?void 0:n.url},error:null})}catch(n){if(be(n))return this._returnResult({data:{provider:e.provider,url:null},error:n});throw n}}async linkIdentityIdToken(e){return await this._useSession(async r=>{var n;try{const{error:i,data:{session:a}}=r;if(i)throw i;const{options:o,provider:c,token:u,access_token:d,nonce:p}=e,f=await Ne(this.fetch,"POST",`${this.url}/token?grant_type=id_token`,{headers:this.headers,jwt:(n=a==null?void 0:a.access_token)!==null&&n!==void 0?n:void 0,body:{provider:c,id_token:u,access_token:d,nonce:p,link_identity:!0,gotrue_meta_security:{captcha_token:o==null?void 0:o.captchaToken}},xform:En}),{data:m,error:v}=f;return v?this._returnResult({data:{user:null,session:null},error:v}):!m||!m.session||!m.user?this._returnResult({data:{user:null,session:null},error:new ws}):(m.session&&(await this._saveSession(m.session),await this._notifyAllSubscribers("USER_UPDATED",m.session)),this._returnResult({data:m,error:v}))}catch(i){if(await nr(this.storage,`${this.storageKey}-code-verifier`),be(i))return this._returnResult({data:{user:null,session:null},error:i});throw i}})}async unlinkIdentity(e){try{return await this._useSession(async r=>{var n,i;const{data:a,error:o}=r;if(o)throw o;return await Ne(this.fetch,"DELETE",`${this.url}/user/identities/${e.identity_id}`,{headers:this.headers,jwt:(i=(n=a.session)===null||n===void 0?void 0:n.access_token)!==null&&i!==void 0?i:void 0})})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async _refreshAccessToken(e){const r="#_refreshAccessToken()";this._debug(r,"begin");try{const n=Date.now();return await N6(async i=>(i>0&&await j6(200*Math.pow(2,i-1)),this._debug(r,"refreshing attempt",i),await Ne(this.fetch,"POST",`${this.url}/token?grant_type=refresh_token`,{body:{refresh_token:e},headers:this.headers,xform:En})),(i,a)=>{const o=200*Math.pow(2,i);return a&&zg(a)&&Date.now()+o-n<Ca})}catch(n){if(this._debug(r,"error",n),be(n))return this._returnResult({data:{session:null,user:null},error:n});throw n}finally{this._debug(r,"end")}}_isValidSession(e){return typeof e=="object"&&e!==null&&"access_token"in e&&"refresh_token"in e&&"expires_at"in e}async _handleProviderSignIn(e,r){const n=await this._getUrlForProvider(`${this.url}/authorize`,e,{redirectTo:r.redirectTo,scopes:r.scopes,queryParams:r.queryParams});return this._debug("#_handleProviderSignIn()","provider",e,"options",r,"url",n),Tr()&&!r.skipBrowserRedirect&&window.location.assign(n),{data:{provider:e,url:n},error:null}}async _recoverAndRefresh(){var e,r;const n="#_recoverAndRefresh()";this._debug(n,"begin");try{const i=await Di(this.storage,this.storageKey);if(i&&this.userStorage){let o=await Di(this.userStorage,this.storageKey+"-user");!this.storage.isServer&&Object.is(this.storage,this.userStorage)&&!o&&(o={user:i.user},await Ns(this.userStorage,this.storageKey+"-user",o)),i.user=(e=o==null?void 0:o.user)!==null&&e!==void 0?e:Bg()}else if(i&&!i.user&&!i.user){const o=await Di(this.storage,this.storageKey+"-user");o&&(o!=null&&o.user)?(i.user=o.user,await nr(this.storage,this.storageKey+"-user"),await Ns(this.storage,this.storageKey,i)):i.user=Bg()}if(this._debug(n,"session from storage",i),!this._isValidSession(i)){this._debug(n,"session is not valid"),i!==null&&await this._removeSession();return}const a=((r=i.expires_at)!==null&&r!==void 0?r:1/0)*1e3-Date.now()<Lg;if(this._debug(n,`session has${a?"":" not"} expired with margin of ${Lg}s`),a){if(this.autoRefreshToken&&i.refresh_token){const{error:o}=await this._callRefreshToken(i.refresh_token);o&&(x6(o)?this._debug(n,"refresh discarded by commit guard",o):(console.error(o),zg(o)||(this._debug(n,"refresh failed with a non-retryable error, removing the session",o),await this._removeSession())))}}else if(i.user&&i.user.__isUserNotAvailableProxy===!0)try{const{data:o,error:c}=await this._getUser(i.access_token);!c&&(o!=null&&o.user)?(i.user=o.user,await this._saveSession(i),await this._notifyAllSubscribers("SIGNED_IN",i)):this._debug(n,"could not get user data, skipping SIGNED_IN notification")}catch(o){console.error("Error getting user data:",o),this._debug(n,"error getting user data, skipping SIGNED_IN notification",o)}else await this._notifyAllSubscribers("SIGNED_IN",i)}catch(i){this._debug(n,"error",i),console.error(i);return}finally{this._debug(n,"end")}}async _callRefreshToken(e){var r,n;if(!e)throw new mr;if(this.refreshingDeferred)return this.refreshingDeferred.promise;const i="#_callRefreshToken()";this._debug(i,"begin");try{this.refreshingDeferred=new mp;const a=await Di(this.storage,this.storageKey),{data:o,error:c}=await this._refreshAccessToken(e);if(c)throw c;if(!o.session)throw new mr;const u=await Di(this.storage,this.storageKey);if(a!==null&&(u===null||u.refresh_token!==a.refresh_token)){this._debug(i,"commit guard: storage changed since refresh started, discarding rotated tokens",{startedWith:"present",nowHolds:u?"replaced":"cleared"});const m={data:null,error:new SE};return this.refreshingDeferred.resolve(m),m}const p=this._sessionRemovalEpoch;if(await this._saveSession(o.session),this._sessionRemovalEpoch!==p){this._debug(i,"commit guard (post-save): _removeSession ran during _saveSession, undoing write"),await nr(this.storage,this.storageKey),this.userStorage&&await nr(this.userStorage,this.storageKey+"-user");const m={data:null,error:new SE};return this.refreshingDeferred.resolve(m),m}await this._notifyAllSubscribers("TOKEN_REFRESHED",o.session);const f={data:o.session,error:null};return this.refreshingDeferred.resolve(f),f}catch(a){if(this._debug(i,"error",a),be(a)){const o={data:null,error:a};return zg(a)||await this._removeSession(),(r=this.refreshingDeferred)===null||r===void 0||r.resolve(o),o}throw(n=this.refreshingDeferred)===null||n===void 0||n.reject(a),a}finally{this.refreshingDeferred=null,this._debug(i,"end")}}async _notifyAllSubscribers(e,r,n=!0){const i=`#_notifyAllSubscribers(${e})`;this._debug(i,"begin",r,`broadcast = ${n}`);try{this.broadcastChannel&&n&&this.broadcastChannel.postMessage({event:e,session:r});const a=[],o=Array.from(this.stateChangeEmitters.values()).map(async c=>{try{await c.callback(e,r)}catch(u){a.push(u)}});if(await Promise.all(o),a.length>0){for(let c=0;c<a.length;c+=1)console.error(a[c]);throw a[0]}}finally{this._debug(i,"end")}}async _saveSession(e){this._debug("#_saveSession()",e),this.suppressGetSessionWarning=!0,await nr(this.storage,`${this.storageKey}-code-verifier`);const r=Object.assign({},e),n=r.user&&r.user.__isUserNotAvailableProxy===!0;if(this.userStorage){!n&&r.user&&await Ns(this.userStorage,this.storageKey+"-user",{user:r.user});const i=Object.assign({},r);delete i.user;const a=TE(i);await Ns(this.storage,this.storageKey,a)}else{const i=TE(r);await Ns(this.storage,this.storageKey,i)}}async _removeSession(){this._sessionRemovalEpoch+=1,this._debug("#_removeSession()"),this.suppressGetSessionWarning=!1,await nr(this.storage,this.storageKey),await nr(this.storage,this.storageKey+"-code-verifier"),await nr(this.storage,this.storageKey+"-user"),this.userStorage&&await nr(this.userStorage,this.storageKey+"-user"),await this._notifyAllSubscribers("SIGNED_OUT",null)}_removeVisibilityChangedCallback(){this._debug("#_removeVisibilityChangedCallback()");const e=this.visibilityChangedCallback;this.visibilityChangedCallback=null;try{e&&Tr()&&(window!=null&&window.removeEventListener)&&window.removeEventListener("visibilitychange",e)}catch(r){console.error("removing visibilitychange callback failed",r)}}async _startAutoRefresh(){await this._stopAutoRefresh(),this._debug("#_startAutoRefresh()");const e=setInterval(()=>this._autoRefreshTokenTick(),Ca);this.autoRefreshTicker=e,e&&typeof e=="object"&&typeof e.unref=="function"?e.unref():typeof Deno<"u"&&typeof Deno.unrefTimer=="function"&&Deno.unrefTimer(e);const r=setTimeout(async()=>{await this.initializePromise,await this._autoRefreshTokenTick()},0);this.autoRefreshTickTimeout=r,r&&typeof r=="object"&&typeof r.unref=="function"?r.unref():typeof Deno<"u"&&typeof Deno.unrefTimer=="function"&&Deno.unrefTimer(r)}async _stopAutoRefresh(){this._debug("#_stopAutoRefresh()");const e=this.autoRefreshTicker;this.autoRefreshTicker=null,e&&clearInterval(e);const r=this.autoRefreshTickTimeout;this.autoRefreshTickTimeout=null,r&&clearTimeout(r)}async startAutoRefresh(){this._removeVisibilityChangedCallback(),await this._startAutoRefresh()}async stopAutoRefresh(){this._removeVisibilityChangedCallback(),await this._stopAutoRefresh()}async dispose(){var e;this._removeVisibilityChangedCallback(),await this._stopAutoRefresh(),(e=this.broadcastChannel)===null||e===void 0||e.close(),this.broadcastChannel=null,this.stateChangeEmitters.clear()}async _autoRefreshTokenTick(){if(this._debug("#_autoRefreshTokenTick()","begin"),this.lock!=null){try{await this._acquireLock(0,async()=>{try{const e=Date.now();try{return await this._useSession(async r=>{const{data:{session:n}}=r;if(!n||!n.refresh_token||!n.expires_at){this._debug("#_autoRefreshTokenTick()","no session");return}const i=Math.floor((n.expires_at*1e3-e)/Ca);this._debug("#_autoRefreshTokenTick()",`access token expires in ${i} ticks, a tick lasts ${Ca}ms, refresh threshold is ${Oc} ticks`),i<=Oc&&await this._callRefreshToken(n.refresh_token)})}catch(r){console.error("Auto refresh tick failed with error. This is likely a transient error.",r)}}finally{this._debug("#_autoRefreshTokenTick()","end")}})}catch(e){if(e instanceof X6)this._debug("auto refresh token tick lock not available");else throw e}return}if(this.refreshingDeferred!==null){this._debug("#_autoRefreshTokenTick()","refresh already in flight, skipping");return}try{const e=Date.now();try{await this._useSession(async r=>{const{data:{session:n}}=r;if(!n||!n.refresh_token||!n.expires_at){this._debug("#_autoRefreshTokenTick()","no session");return}const i=Math.floor((n.expires_at*1e3-e)/Ca);this._debug("#_autoRefreshTokenTick()",`access token expires in ${i} ticks, a tick lasts ${Ca}ms, refresh threshold is ${Oc} ticks`),i<=Oc&&await this._callRefreshToken(n.refresh_token)})}catch(r){console.error("Auto refresh tick failed with error. This is likely a transient error.",r)}}finally{this._debug("#_autoRefreshTokenTick()","end")}}async _handleVisibilityChange(){if(this._debug("#_handleVisibilityChange()"),!Tr()||!(window!=null&&window.addEventListener))return this.autoRefreshToken&&this.startAutoRefresh(),!1;try{this.visibilityChangedCallback=async()=>{try{await this._onVisibilityChanged(!1)}catch(e){this._debug("#visibilityChangedCallback","error",e)}},window==null||window.addEventListener("visibilitychange",this.visibilityChangedCallback),await this._onVisibilityChanged(!0)}catch(e){console.error("_handleVisibilityChange",e)}}async _onVisibilityChanged(e){const r=`#_onVisibilityChanged(${e})`;if(this._debug(r,"visibilityState",document.visibilityState),document.visibilityState==="visible"){if(this.autoRefreshToken&&this._startAutoRefresh(),!e)if(await this.initializePromise,this.lock!=null)await this._acquireLock(this.lockAcquireTimeout,async()=>{if(document.visibilityState!=="visible"){this._debug(r,"acquired the lock to recover the session, but the browser visibilityState is no longer visible, aborting");return}await this._recoverAndRefresh()});else{if(document.visibilityState!=="visible"){this._debug(r,"visibilityState is no longer visible, skipping recovery");return}await this._recoverAndRefresh()}}else document.visibilityState==="hidden"&&this.autoRefreshToken&&this._stopAutoRefresh()}async _getUrlForProvider(e,r,n){const i=[`provider=${encodeURIComponent(r)}`];if(n!=null&&n.redirectTo&&i.push(`redirect_to=${encodeURIComponent(n.redirectTo)}`),n!=null&&n.scopes&&i.push(`scopes=${encodeURIComponent(n.scopes)}`),this.flowType==="pkce"){const[a,o]=await _s(this.storage,this.storageKey),c=new URLSearchParams({code_challenge:`${encodeURIComponent(a)}`,code_challenge_method:`${encodeURIComponent(o)}`});i.push(c.toString())}if(n!=null&&n.queryParams){const a=new URLSearchParams(n.queryParams);i.push(a.toString())}return n!=null&&n.skipBrowserRedirect&&i.push(`skip_http_redirect=${n.skipBrowserRedirect}`),`${e}?${i.join("&")}`}async _unenroll(e){try{return await this._useSession(async r=>{var n;const{data:i,error:a}=r;return a?this._returnResult({data:null,error:a}):await Ne(this.fetch,"DELETE",`${this.url}/factors/${e.factorId}`,{headers:this.headers,jwt:(n=i==null?void 0:i.session)===null||n===void 0?void 0:n.access_token})})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async _enroll(e){try{return await this._useSession(async r=>{var n,i;const{data:a,error:o}=r;if(o)return this._returnResult({data:null,error:o});const c=Object.assign({friendly_name:e.friendlyName,factor_type:e.factorType},e.factorType==="phone"?{phone:e.phone}:e.factorType==="totp"?{issuer:e.issuer}:{}),{data:u,error:d}=await Ne(this.fetch,"POST",`${this.url}/factors`,{body:c,headers:this.headers,jwt:(n=a==null?void 0:a.session)===null||n===void 0?void 0:n.access_token});return d?this._returnResult({data:null,error:d}):(e.factorType==="totp"&&u.type==="totp"&&(!((i=u==null?void 0:u.totp)===null||i===void 0)&&i.qr_code)&&(u.totp.qr_code=`data:image/svg+xml;utf-8,${u.totp.qr_code}`),this._returnResult({data:u,error:null}))})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async _verify(e){const r=async()=>{try{return await this._useSession(async n=>{var i;const{data:a,error:o}=n;if(o)return this._returnResult({data:null,error:o});const c=Object.assign({challenge_id:e.challengeId},"webauthn"in e?{webauthn:Object.assign(Object.assign({},e.webauthn),{credential_response:e.webauthn.type==="create"?$E(e.webauthn.credential_response):ME(e.webauthn.credential_response)})}:{code:e.code}),{data:u,error:d}=await Ne(this.fetch,"POST",`${this.url}/factors/${e.factorId}/verify`,{body:c,headers:this.headers,jwt:(i=a==null?void 0:a.session)===null||i===void 0?void 0:i.access_token});return d?this._returnResult({data:null,error:d}):(await this._saveSession(Object.assign({expires_at:Math.round(Date.now()/1e3)+u.expires_in},u)),await this._notifyAllSubscribers("MFA_CHALLENGE_VERIFIED",u),this._returnResult({data:u,error:d}))})}catch(n){if(be(n))return this._returnResult({data:null,error:n});throw n}};return this.lock!=null?this._acquireLock(this.lockAcquireTimeout,r):r()}async _challenge(e){const r=async()=>{try{return await this._useSession(async n=>{var i;const{data:a,error:o}=n;if(o)return this._returnResult({data:null,error:o});const c=await Ne(this.fetch,"POST",`${this.url}/factors/${e.factorId}/challenge`,{body:e,headers:this.headers,jwt:(i=a==null?void 0:a.session)===null||i===void 0?void 0:i.access_token});if(c.error)return c;const{data:u}=c;if(u.type!=="webauthn")return{data:u,error:null};switch(u.webauthn.type){case"create":return{data:Object.assign(Object.assign({},u),{webauthn:Object.assign(Object.assign({},u.webauthn),{credential_options:Object.assign(Object.assign({},u.webauthn.credential_options),{publicKey:RE(u.webauthn.credential_options.publicKey)})})}),error:null};case"request":return{data:Object.assign(Object.assign({},u),{webauthn:Object.assign(Object.assign({},u.webauthn),{credential_options:Object.assign(Object.assign({},u.webauthn.credential_options),{publicKey:IE(u.webauthn.credential_options.publicKey)})})}),error:null}}})}catch(n){if(be(n))return this._returnResult({data:null,error:n});throw n}};return this.lock!=null?this._acquireLock(this.lockAcquireTimeout,r):r()}async _challengeAndVerify(e){const{data:r,error:n}=await this._challenge({factorId:e.factorId});return n?this._returnResult({data:null,error:n}):await this._verify({factorId:e.factorId,challengeId:r.id,code:e.code})}async _listFactors(){var e;const{data:{user:r},error:n}=await this.getUser();if(n)return{data:null,error:n};const i={all:[],phone:[],totp:[],webauthn:[]};for(const a of(e=r==null?void 0:r.factors)!==null&&e!==void 0?e:[])i.all.push(a),a.status==="verified"&&i[a.factor_type].push(a);return{data:i,error:null}}async _getAuthenticatorAssuranceLevel(e){var r,n,i,a;if(e)try{const{payload:v}=pf(e);let b=null;v.aal&&(b=v.aal);let w=b;const{data:{user:x},error:k}=await this.getUser(e);if(k)return this._returnResult({data:null,error:k});((n=(r=x==null?void 0:x.factors)===null||r===void 0?void 0:r.filter(C=>C.status==="verified"))!==null&&n!==void 0?n:[]).length>0&&(w="aal2");const A=v.amr||[];return{data:{currentLevel:b,nextLevel:w,currentAuthenticationMethods:A},error:null}}catch(v){if(be(v))return this._returnResult({data:null,error:v});throw v}const{data:{session:o},error:c}=await this.getSession();if(c)return this._returnResult({data:null,error:c});if(!o)return{data:{currentLevel:null,nextLevel:null,currentAuthenticationMethods:[]},error:null};const{payload:u}=pf(o.access_token);let d=null;u.aal&&(d=u.aal);let p=d;((a=(i=o.user.factors)===null||i===void 0?void 0:i.filter(v=>v.status==="verified"))!==null&&a!==void 0?a:[]).length>0&&(p="aal2");const m=u.amr||[];return{data:{currentLevel:d,nextLevel:p,currentAuthenticationMethods:m},error:null}}async _getAuthorizationDetails(e){try{return await this._useSession(async r=>{const{data:{session:n},error:i}=r;return i?this._returnResult({data:null,error:i}):n?await Ne(this.fetch,"GET",`${this.url}/oauth/authorizations/${e}`,{headers:this.headers,jwt:n.access_token,xform:a=>({data:a,error:null})}):this._returnResult({data:null,error:new mr})})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async _approveAuthorization(e,r){try{return await this._useSession(async n=>{const{data:{session:i},error:a}=n;if(a)return this._returnResult({data:null,error:a});if(!i)return this._returnResult({data:null,error:new mr});const o=await Ne(this.fetch,"POST",`${this.url}/oauth/authorizations/${e}/consent`,{headers:this.headers,jwt:i.access_token,body:{action:"approve"},xform:c=>({data:c,error:null})});return o.data&&o.data.redirect_url&&Tr()&&!(r!=null&&r.skipBrowserRedirect)&&window.location.assign(o.data.redirect_url),o})}catch(n){if(be(n))return this._returnResult({data:null,error:n});throw n}}async _denyAuthorization(e,r){try{return await this._useSession(async n=>{const{data:{session:i},error:a}=n;if(a)return this._returnResult({data:null,error:a});if(!i)return this._returnResult({data:null,error:new mr});const o=await Ne(this.fetch,"POST",`${this.url}/oauth/authorizations/${e}/consent`,{headers:this.headers,jwt:i.access_token,body:{action:"deny"},xform:c=>({data:c,error:null})});return o.data&&o.data.redirect_url&&Tr()&&!(r!=null&&r.skipBrowserRedirect)&&window.location.assign(o.data.redirect_url),o})}catch(n){if(be(n))return this._returnResult({data:null,error:n});throw n}}async _listOAuthGrants(){try{return await this._useSession(async e=>{const{data:{session:r},error:n}=e;return n?this._returnResult({data:null,error:n}):r?await Ne(this.fetch,"GET",`${this.url}/user/oauth/grants`,{headers:this.headers,jwt:r.access_token,xform:i=>({data:i,error:null})}):this._returnResult({data:null,error:new mr})})}catch(e){if(be(e))return this._returnResult({data:null,error:e});throw e}}async _revokeOAuthGrant(e){try{return await this._useSession(async r=>{const{data:{session:n},error:i}=r;return i?this._returnResult({data:null,error:i}):n?(await Ne(this.fetch,"DELETE",`${this.url}/user/oauth/grants`,{headers:this.headers,jwt:n.access_token,query:{client_id:e.clientId},noResolveJson:!0}),{data:{},error:null}):this._returnResult({data:null,error:new mr})})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async fetchJwk(e,r={keys:[]}){let n=r.keys.find(c=>c.kid===e);if(n)return n;const i=Date.now();if(n=this.jwks.keys.find(c=>c.kid===e),n&&this.jwks_cached_at+m6>i)return n;const{data:a,error:o}=await Ne(this.fetch,"GET",`${this.url}/.well-known/jwks.json`,{headers:this.headers});if(o)throw o;return!a.keys||a.keys.length===0||(this.jwks=a,this.jwks_cached_at=i,n=a.keys.find(c=>c.kid===e),!n)?null:n}async getClaims(e,r={}){try{let n=e;if(!n){const{data:v,error:b}=await this.getSession();if(b||!v.session)return this._returnResult({data:null,error:b});n=v.session.access_token}const{header:i,payload:a,signature:o,raw:{header:c,payload:u}}=pf(n);if(!(r!=null&&r.allowExpired))try{L6(a.exp)}catch(v){throw new Jf(v instanceof Error?v.message:"JWT validation failed")}const d=!i.alg||i.alg.startsWith("HS")||!i.kid||!("crypto"in globalThis&&"subtle"in globalThis.crypto)?null:await this.fetchJwk(i.kid,r!=null&&r.keys?{keys:r.keys}:r==null?void 0:r.jwks);if(!d){const{error:v}=await this.getUser(n);if(v)throw v;return{data:{claims:a,header:i,signature:o},error:null}}const p=z6(i.alg),f=await crypto.subtle.importKey("jwk",d,p,!0,["verify"]);if(!await crypto.subtle.verify(p,f,o,E6(`${c}.${u}`)))throw new Jf("Invalid JWT signature");return{data:{claims:a,header:i,signature:o},error:null}}catch(n){if(be(n))return this._returnResult({data:null,error:n});throw n}}async signInWithPasskey(e){var r,n,i;qn(this.experimental);try{if(!eh())return this._returnResult({data:null,error:new Xn("Browser does not support WebAuthn",null)});const{data:a,error:o}=await this._startPasskeyAuthentication({options:{captchaToken:(r=e==null?void 0:e.options)===null||r===void 0?void 0:r.captchaToken}});if(o||!a)return this._returnResult({data:null,error:o});const c=IE(a.options),u=(i=(n=e==null?void 0:e.options)===null||n===void 0?void 0:n.signal)!==null&&i!==void 0?i:fx.createNewAbortSignal(),{data:d,error:p}=await fR({publicKey:c,signal:u});if(p||!d)return this._returnResult({data:null,error:p??new Xn("WebAuthn ceremony failed",null)});const f=ME(d);return this._verifyPasskeyAuthentication({challengeId:a.challenge_id,credential:f})}catch(a){if(be(a))return this._returnResult({data:null,error:a});throw a}}async registerPasskey(e){var r,n;qn(this.experimental);try{if(!eh())return this._returnResult({data:null,error:new Xn("Browser does not support WebAuthn",null)});const{data:i,error:a}=await this._startPasskeyRegistration();if(a||!i)return this._returnResult({data:null,error:a});const o=RE(i.options),c=(n=(r=e==null?void 0:e.options)===null||r===void 0?void 0:r.signal)!==null&&n!==void 0?n:fx.createNewAbortSignal(),{data:u,error:d}=await dR({publicKey:o,signal:c});if(d||!u)return this._returnResult({data:null,error:d??new Xn("WebAuthn ceremony failed",null)});const p=$E(u);return this._verifyPasskeyRegistration({challengeId:i.challenge_id,credential:p})}catch(i){if(be(i))return this._returnResult({data:null,error:i});throw i}}async _startPasskeyRegistration(){qn(this.experimental);try{return await this._useSession(async e=>{const{data:{session:r},error:n}=e;if(n)return this._returnResult({data:null,error:n});if(!r)return this._returnResult({data:null,error:new mr});const{data:i,error:a}=await Ne(this.fetch,"POST",`${this.url}/passkeys/registration/options`,{headers:this.headers,jwt:r.access_token,body:{}});return a?this._returnResult({data:null,error:a}):this._returnResult({data:i,error:null})})}catch(e){if(be(e))return this._returnResult({data:null,error:e});throw e}}async _verifyPasskeyRegistration(e){qn(this.experimental);try{return await this._useSession(async r=>{const{data:{session:n},error:i}=r;if(i)return this._returnResult({data:null,error:i});if(!n)return this._returnResult({data:null,error:new mr});const{data:a,error:o}=await Ne(this.fetch,"POST",`${this.url}/passkeys/registration/verify`,{headers:this.headers,jwt:n.access_token,body:{challenge_id:e.challengeId,credential:e.credential}});return o?this._returnResult({data:null,error:o}):this._returnResult({data:a,error:null})})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async _startPasskeyAuthentication(e){var r;qn(this.experimental);try{const{data:n,error:i}=await Ne(this.fetch,"POST",`${this.url}/passkeys/authentication/options`,{headers:this.headers,body:{gotrue_meta_security:{captcha_token:(r=e==null?void 0:e.options)===null||r===void 0?void 0:r.captchaToken}}});return i?this._returnResult({data:null,error:i}):this._returnResult({data:n,error:null})}catch(n){if(be(n))return this._returnResult({data:null,error:n});throw n}}async _verifyPasskeyAuthentication(e){qn(this.experimental);try{const{data:r,error:n}=await Ne(this.fetch,"POST",`${this.url}/passkeys/authentication/verify`,{headers:this.headers,body:{challenge_id:e.challengeId,credential:e.credential},xform:En});return n?this._returnResult({data:null,error:n}):(r.session&&(await this._saveSession(r.session),await this._notifyAllSubscribers("SIGNED_IN",r.session)),this._returnResult({data:r,error:null}))}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async _listPasskeys(){qn(this.experimental);try{return await this._useSession(async e=>{const{data:{session:r},error:n}=e;if(n)return this._returnResult({data:null,error:n});if(!r)return this._returnResult({data:null,error:new mr});const{data:i,error:a}=await Ne(this.fetch,"GET",`${this.url}/passkeys`,{headers:this.headers,jwt:r.access_token,xform:o=>({data:o,error:null})});return a?this._returnResult({data:null,error:a}):this._returnResult({data:i,error:null})})}catch(e){if(be(e))return this._returnResult({data:null,error:e});throw e}}async _updatePasskey(e){qn(this.experimental);try{return await this._useSession(async r=>{const{data:{session:n},error:i}=r;if(i)return this._returnResult({data:null,error:i});if(!n)return this._returnResult({data:null,error:new mr});const{data:a,error:o}=await Ne(this.fetch,"PATCH",`${this.url}/passkeys/${e.passkeyId}`,{headers:this.headers,jwt:n.access_token,body:{friendly_name:e.friendlyName}});return o?this._returnResult({data:null,error:o}):this._returnResult({data:a,error:null})})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}async _deletePasskey(e){qn(this.experimental);try{return await this._useSession(async r=>{const{data:{session:n},error:i}=r;if(i)return this._returnResult({data:null,error:i});if(!n)return this._returnResult({data:null,error:new mr});const{error:a}=await Ne(this.fetch,"DELETE",`${this.url}/passkeys/${e.passkeyId}`,{headers:this.headers,jwt:n.access_token,noResolveJson:!0});return a?this._returnResult({data:null,error:a}):this._returnResult({data:null,error:null})})}catch(r){if(be(r))return this._returnResult({data:null,error:r});throw r}}}Xc.nextInstanceID={};const cU=Xc,uU="2.107.0";let Tc="",rh;if(typeof Deno<"u"){var qg;Tc="deno",rh=(qg=Deno.version)===null||qg===void 0?void 0:qg.deno}else if(typeof document<"u")Tc="web";else if(typeof navigator<"u"&&navigator.product==="ReactNative")Tc="react-native";else{var Fg;Tc="node",rh=typeof process<"u"?(Fg=process.version)===null||Fg===void 0?void 0:Fg.replace(/^v/,""):void 0}const hR=[`runtime=${Tc}`];rh&&hR.push(`runtime-version=${rh}`);const dU={"X-Client-Info":`supabase-js/${uU}; ${hR.join("; ")}`},fU={headers:dU},hU={schema:"public"},pU={autoRefreshToken:!0,persistSession:!0,detectSessionInUrl:!0,flowType:"implicit"},mU={},gU={enabled:!1,respectSamplingDecision:!0};function yU(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(p){try{d(n.next(p))}catch(f){o(f)}}function u(p){try{d(n.throw(p))}catch(f){o(f)}}function d(p){p.done?a(p.value):i(p.value).then(c,u)}d((n=n.apply(t,[])).next())})}let Hg=null;const vU="@opentelemetry/api";function bU(){return Hg===null&&(Hg=import(vU).catch(()=>null)),Hg}function xU(){return yU(this,void 0,void 0,function*(){try{const t=yield bU();if(!t||!t.propagation||!t.context)return null;const e={};t.propagation.inject(t.context.active(),e);const r=e.traceparent;return r?{traceparent:r,tracestate:e.tracestate,baggage:e.baggage}:null}catch{return null}})}function wU(t){if(!t||typeof t!="string")return null;const e=t.split("-");if(e.length!==4)return null;const[r,n,i,a]=e;if(r.length!==2||n.length!==32||i.length!==16||a.length!==2)return null;const o=/^[0-9a-f]+$/i;return!o.test(r)||!o.test(n)||!o.test(i)||!o.test(a)||n==="00000000000000000000000000000000"||i==="0000000000000000"?null:{version:r,traceId:n,parentId:i,traceFlags:a,isSampled:(parseInt(a,16)&1)===1}}function _U(t,e){if(!t||!e||e.length===0)return!1;let r;if(t instanceof URL)r=t;else try{r=new URL(t)}catch{return!1}for(const n of e)try{if(typeof n=="string"){if(SU(r.hostname,n))return!0}else if(n instanceof RegExp){if(n.test(r.hostname))return!0}else if(typeof n=="function"&&n(r))return!0}catch{continue}return!1}function SU(t,e){if(e===t)return!0;if(e.startsWith("*.")){const r=e.slice(2);if(t.endsWith(r)&&(t===r||t.endsWith("."+r)))return!0}return!1}function kU(t){const e=[];try{const r=new URL(t);e.push(r.hostname)}catch{}return e.push("*.supabase.co","*.supabase.in"),e.push("localhost","127.0.0.1","[::1]"),e}function Yc(t){"@babel/helpers - typeof";return Yc=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Yc(t)}function EU(t,e){if(Yc(t)!="object"||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var n=r.call(t,e);if(Yc(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function AU(t){var e=EU(t,"string");return Yc(e)=="symbol"?e:e+""}function OU(t,e,r){return(e=AU(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function DE(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),r.push.apply(r,n)}return r}function Ht(t){for(var e=1;e<arguments.length;e++){var r=arguments[e]!=null?arguments[e]:{};e%2?DE(Object(r),!0).forEach(function(n){OU(t,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):DE(Object(r)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(r,n))})}return t}const TU=t=>t?(...e)=>t(...e):(...e)=>fetch(...e),CU=()=>Headers,jU=(t,e,r,n,i)=>{const a=TU(n),o=CU(),c=(i==null?void 0:i.enabled)===!0,u=(i==null?void 0:i.respectSamplingDecision)!==!1,d=c?kU(e):null;return async(p,f)=>{var m;const v=(m=await r())!==null&&m!==void 0?m:t;let b=new o(f==null?void 0:f.headers);if(b.has("apikey")||b.set("apikey",t),b.has("Authorization")||b.set("Authorization",`Bearer ${v}`),d){const w=await NU(p,d,u);w&&(w.traceparent&&!b.has("traceparent")&&b.set("traceparent",w.traceparent),w.tracestate&&!b.has("tracestate")&&b.set("tracestate",w.tracestate),w.baggage&&!b.has("baggage")&&b.set("baggage",w.baggage))}return a(p,Ht(Ht({},f),{},{headers:b}))}};async function NU(t,e,r){if(!_U(typeof t=="string"||t instanceof URL?t:t.url,e))return null;const n=await xU();if(!n||!n.traceparent)return null;if(r){const i=wU(n.traceparent);if(i&&!i.isSampled)return null}return n}function LE(t){return typeof t=="boolean"?{enabled:t}:t}function PU(t){return t.endsWith("/")?t:t+"/"}function RU(t,e){var r,n,i,a,o,c;const{db:u,auth:d,realtime:p,global:f}=t,{db:m,auth:v,realtime:b,global:w}=e,x=LE(t.tracePropagation),k=LE(e.tracePropagation),S={db:Ht(Ht({},m),u),auth:Ht(Ht({},v),d),realtime:Ht(Ht({},b),p),storage:{},global:Ht(Ht(Ht({},w),f),{},{headers:Ht(Ht({},(r=w==null?void 0:w.headers)!==null&&r!==void 0?r:{}),(n=f==null?void 0:f.headers)!==null&&n!==void 0?n:{})}),tracePropagation:{enabled:(i=(a=x==null?void 0:x.enabled)!==null&&a!==void 0?a:k==null?void 0:k.enabled)!==null&&i!==void 0?i:!1,respectSamplingDecision:(o=(c=x==null?void 0:x.respectSamplingDecision)!==null&&c!==void 0?c:k==null?void 0:k.respectSamplingDecision)!==null&&o!==void 0?o:!0},accessToken:async()=>""};return t.accessToken?S.accessToken=t.accessToken:delete S.accessToken,S}function IU(t){const e=t==null?void 0:t.trim();if(!e)throw new Error("supabaseUrl is required.");if(!e.match(/^https?:\/\//i))throw new Error("Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL.");try{return new URL(PU(e))}catch{throw Error("Invalid supabaseUrl: Provided URL is malformed.")}}var $U=class extends cU{constructor(t){super(t)}},MU=class{constructor(t,e,r){var n,i;this.supabaseUrl=t,this.supabaseKey=e;const a=IU(t);if(!e)throw new Error("supabaseKey is required.");this.realtimeUrl=new URL("realtime/v1",a),this.realtimeUrl.protocol=this.realtimeUrl.protocol.replace("http","ws"),this.authUrl=new URL("auth/v1",a),this.storageUrl=new URL("storage/v1",a),this.functionsUrl=new URL("functions/v1",a);const o=`sb-${a.hostname.split(".")[0]}-auth-token`,c={db:hU,realtime:mU,auth:Ht(Ht({},pU),{},{storageKey:o}),global:fU,tracePropagation:gU},u=RU(r??{},c);if(this.settings=u,this.storageKey=(n=u.auth.storageKey)!==null&&n!==void 0?n:"",this.headers=(i=u.global.headers)!==null&&i!==void 0?i:{},u.accessToken)this.accessToken=u.accessToken,this.auth=new Proxy({},{get:(p,f)=>{throw new Error(`@supabase/supabase-js: Supabase Client is configured with the accessToken option, accessing supabase.auth.${String(f)} is not possible`)}});else{var d;this.auth=this._initSupabaseAuthClient((d=u.auth)!==null&&d!==void 0?d:{},this.headers,u.global.fetch)}this.fetch=jU(e,t,this._getAccessToken.bind(this),u.global.fetch,u.tracePropagation),this.realtime=this._initRealtimeClient(Ht({headers:this.headers,accessToken:this._getAccessToken.bind(this),fetch:this.fetch},u.realtime)),this.accessToken&&Promise.resolve(this.accessToken()).then(p=>this.realtime.setAuth(p)).catch(p=>console.warn("Failed to set initial Realtime auth token:",p)),this.rest=new JB(new URL("rest/v1",a).href,{headers:this.headers,schema:u.db.schema,fetch:this.fetch,timeout:u.db.timeout,urlLengthLimit:u.db.urlLengthLimit}),this.storage=new u6(this.storageUrl.href,this.headers,this.fetch,r==null?void 0:r.storage),u.accessToken||this._listenForAuthEvents()}get functions(){return new qB(this.functionsUrl.href,{headers:this.headers,customFetch:this.fetch})}from(t){return this.rest.from(t)}schema(t){return this.rest.schema(t)}rpc(t,e={},r={head:!1,get:!1,count:void 0}){return this.rest.rpc(t,e,r)}channel(t,e={config:{}}){return this.realtime.channel(t,e)}getChannels(){return this.realtime.getChannels()}removeChannel(t){return this.realtime.removeChannel(t)}removeAllChannels(){return this.realtime.removeAllChannels()}async _getAccessToken(){var t=this,e,r;if(t.accessToken)return await t.accessToken();const{data:n}=await t.auth.getSession();return(e=(r=n.session)===null||r===void 0?void 0:r.access_token)!==null&&e!==void 0?e:t.supabaseKey}_initSupabaseAuthClient({autoRefreshToken:t,persistSession:e,detectSessionInUrl:r,storage:n,userStorage:i,storageKey:a,flowType:o,lock:c,debug:u,throwOnError:d,experimental:p,lockAcquireTimeout:f,skipAutoInitialize:m},v,b){const w={Authorization:`Bearer ${this.supabaseKey}`,apikey:`${this.supabaseKey}`};return new $U({url:this.authUrl.href,headers:Ht(Ht({},w),v),storageKey:a,autoRefreshToken:t,persistSession:e,detectSessionInUrl:r,storage:n,userStorage:i,flowType:o,lock:c,debug:u,throwOnError:d,experimental:p,fetch:b,lockAcquireTimeout:f,skipAutoInitialize:m,hasCustomAuthorizationHeader:Object.keys(this.headers).some(x=>x.toLowerCase()==="authorization")})}_initRealtimeClient(t){return new R8(this.realtimeUrl.href,Ht(Ht({},t),{},{params:Ht(Ht({},{apikey:this.supabaseKey}),t==null?void 0:t.params)}))}_listenForAuthEvents(){return this.auth.onAuthStateChange((t,e)=>{this._handleTokenChanged(t,"CLIENT",e==null?void 0:e.access_token)})}_handleTokenChanged(t,e,r){(t==="TOKEN_REFRESHED"||t==="SIGNED_IN")&&this.changedAccessToken!==r?(this.changedAccessToken=r,this.realtime.setAuth(r)):t==="SIGNED_OUT"&&(this.realtime.setAuth(),e=="STORAGE"&&this.auth.signOut(),this.changedAccessToken=void 0)}};const DU=(t,e,r)=>new MU(t,e,r);function LU(){if(typeof window<"u")return!1;const t=globalThis.process;if(!t)return!1;const e=t.version;if(e==null)return!1;const r=e.match(/^v(\d+)\./);return r?parseInt(r[1],10)<=18:!1}LU()&&console.warn("⚠️ Node.js 18 and below are deprecated and will no longer be supported in future versions of @supabase/supabase-js. Please upgrade to Node.js 20 or later. For more information, visit: https://github.com/orgs/supabase/discussions/37217");const pR=j.createContext({session:null,supabase:null,loading:!0,signIn:async()=>({error:"Not initialized"}),signOut:async()=>{}});function gp(){return j.useContext(pR)}function zU({children:t}){const[e,r]=j.useState(null),[n,i]=j.useState(null),[a,o]=j.useState(!0),c=j.useRef(null);j.useEffect(()=>{W4(()=>{var f;return((f=c.current)==null?void 0:f.access_token)??null})},[]);const u=j.useRef(null);j.useEffect(()=>{K4(async()=>{const f=u.current;if(!f)return null;const{data:m,error:v}=await f.auth.refreshSession();return v||!m.session?null:(c.current=m.session,i(m.session),m.session.access_token)})},[]),j.useEffect(()=>{fetch("/api/auth/config").then(f=>f.json()).then(f=>{if(f.supabaseUrl&&f.supabaseAnonKey){const m=DU(f.supabaseUrl,f.supabaseAnonKey);r(m),u.current=m,m.auth.getSession().then(({data:b})=>{c.current=b.session,i(b.session),o(!1)});const{data:{subscription:v}}=m.auth.onAuthStateChange((b,w)=>{c.current=w,i(w)});return()=>v.unsubscribe()}o(!1)}).catch(()=>{o(!1)})},[]);async function d(f,m){if(!e)return{error:"Supabase not configured"};const{error:v}=await e.auth.signInWithPassword({email:f,password:m});return{error:(v==null?void 0:v.message)??null}}async function p(){e&&(await e.auth.signOut(),c.current=null,i(null))}return y.jsx(pR.Provider,{value:{session:n,supabase:e,loading:a,signIn:d,signOut:p},children:t})}function mR(t){var e,r,n="";if(typeof t=="string"||typeof t=="number")n+=t;else if(typeof t=="object")if(Array.isArray(t)){var i=t.length;for(e=0;e<i;e++)t[e]&&(r=mR(t[e]))&&(n&&(n+=" "),n+=r)}else for(r in t)t[r]&&(n&&(n+=" "),n+=r);return n}function ot(){for(var t,e,r=0,n="",i=arguments.length;r<i;r++)(t=arguments[r])&&(e=mR(t))&&(n&&(n+=" "),n+=e);return n}const BU=(t,e)=>{const r=new Array(t.length+e.length);for(let n=0;n<t.length;n++)r[n]=t[n];for(let n=0;n<e.length;n++)r[t.length+n]=e[n];return r},UU=(t,e)=>({classGroupId:t,validator:e}),gR=(t=new Map,e=null,r)=>({nextPart:t,validators:e,classGroupId:r}),nh="-",zE=[],qU="arbitrary..",FU=t=>{const e=WU(t),{conflictingClassGroups:r,conflictingClassGroupModifiers:n}=t;return{getClassGroupId:o=>{if(o.startsWith("[")&&o.endsWith("]"))return HU(o);const c=o.split(nh),u=c[0]===""&&c.length>1?1:0;return yR(c,u,e)},getConflictingClassGroupIds:(o,c)=>{if(c){const u=n[o],d=r[o];return u?d?BU(d,u):u:d||zE}return r[o]||zE}}},yR=(t,e,r)=>{if(t.length-e===0)return r.classGroupId;const i=t[e],a=r.nextPart.get(i);if(a){const d=yR(t,e+1,a);if(d)return d}const o=r.validators;if(o===null)return;const c=e===0?t.join(nh):t.slice(e).join(nh),u=o.length;for(let d=0;d<u;d++){const p=o[d];if(p.validator(c))return p.classGroupId}},HU=t=>t.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const e=t.slice(1,-1),r=e.indexOf(":"),n=e.slice(0,r);return n?qU+n:void 0})(),WU=t=>{const{theme:e,classGroups:r}=t;return KU(r,e)},KU=(t,e)=>{const r=gR();for(const n in t){const i=t[n];c1(i,r,n,e)}return r},c1=(t,e,r,n)=>{const i=t.length;for(let a=0;a<i;a++){const o=t[a];GU(o,e,r,n)}},GU=(t,e,r,n)=>{if(typeof t=="string"){VU(t,e,r);return}if(typeof t=="function"){XU(t,e,r,n);return}YU(t,e,r,n)},VU=(t,e,r)=>{const n=t===""?e:vR(e,t);n.classGroupId=r},XU=(t,e,r,n)=>{if(JU(t)){c1(t(n),e,r,n);return}e.validators===null&&(e.validators=[]),e.validators.push(UU(r,t))},YU=(t,e,r,n)=>{const i=Object.entries(t),a=i.length;for(let o=0;o<a;o++){const[c,u]=i[o];c1(u,vR(e,c),r,n)}},vR=(t,e)=>{let r=t;const n=e.split(nh),i=n.length;for(let a=0;a<i;a++){const o=n[a];let c=r.nextPart.get(o);c||(c=gR(),r.nextPart.set(o,c)),r=c}return r},JU=t=>"isThemeGetter"in t&&t.isThemeGetter===!0,ZU=t=>{if(t<1)return{get:()=>{},set:()=>{}};let e=0,r=Object.create(null),n=Object.create(null);const i=(a,o)=>{r[a]=o,e++,e>t&&(e=0,n=r,r=Object.create(null))};return{get(a){let o=r[a];if(o!==void 0)return o;if((o=n[a])!==void 0)return i(a,o),o},set(a,o){a in r?r[a]=o:i(a,o)}}},hx="!",BE=":",QU=[],UE=(t,e,r,n,i)=>({modifiers:t,hasImportantModifier:e,baseClassName:r,maybePostfixModifierPosition:n,isExternal:i}),eq=t=>{const{prefix:e,experimentalParseClassName:r}=t;let n=i=>{const a=[];let o=0,c=0,u=0,d;const p=i.length;for(let w=0;w<p;w++){const x=i[w];if(o===0&&c===0){if(x===BE){a.push(i.slice(u,w)),u=w+1;continue}if(x==="/"){d=w;continue}}x==="["?o++:x==="]"?o--:x==="("?c++:x===")"&&c--}const f=a.length===0?i:i.slice(u);let m=f,v=!1;f.endsWith(hx)?(m=f.slice(0,-1),v=!0):f.startsWith(hx)&&(m=f.slice(1),v=!0);const b=d&&d>u?d-u:void 0;return UE(a,v,m,b)};if(e){const i=e+BE,a=n;n=o=>o.startsWith(i)?a(o.slice(i.length)):UE(QU,!1,o,void 0,!0)}if(r){const i=n;n=a=>r({className:a,parseClassName:i})}return n},tq=t=>{const e=new Map;return t.orderSensitiveModifiers.forEach((r,n)=>{e.set(r,1e6+n)}),r=>{const n=[];let i=[];for(let a=0;a<r.length;a++){const o=r[a],c=o[0]==="[",u=e.has(o);c||u?(i.length>0&&(i.sort(),n.push(...i),i=[]),n.push(o)):i.push(o)}return i.length>0&&(i.sort(),n.push(...i)),n}},rq=t=>({cache:ZU(t.cacheSize),parseClassName:eq(t),sortModifiers:tq(t),postfixLookupClassGroupIds:nq(t),...FU(t)}),nq=t=>{const e=Object.create(null),r=t.postfixLookupClassGroups;if(r)for(let n=0;n<r.length;n++)e[r[n]]=!0;return e},iq=/\s+/,aq=(t,e)=>{const{parseClassName:r,getClassGroupId:n,getConflictingClassGroupIds:i,sortModifiers:a,postfixLookupClassGroupIds:o}=e,c=[],u=t.trim().split(iq);let d="";for(let p=u.length-1;p>=0;p-=1){const f=u[p],{isExternal:m,modifiers:v,hasImportantModifier:b,baseClassName:w,maybePostfixModifierPosition:x}=r(f);if(m){d=f+(d.length>0?" "+d:d);continue}let k=!!x,S;if(k){const N=w.substring(0,x);S=n(N);const R=S&&o[S]?n(w):void 0;R&&R!==S&&(S=R,k=!1)}else S=n(w);if(!S){if(!k){d=f+(d.length>0?" "+d:d);continue}if(S=n(w),!S){d=f+(d.length>0?" "+d:d);continue}k=!1}const A=v.length===0?"":v.length===1?v[0]:a(v).join(":"),C=b?A+hx:A,T=C+S;if(c.indexOf(T)>-1)continue;c.push(T);const O=i(S,k);for(let N=0;N<O.length;++N){const R=O[N];c.push(C+R)}d=f+(d.length>0?" "+d:d)}return d},oq=(...t)=>{let e=0,r,n,i="";for(;e<t.length;)(r=t[e++])&&(n=bR(r))&&(i&&(i+=" "),i+=n);return i},bR=t=>{if(typeof t=="string")return t;let e,r="";for(let n=0;n<t.length;n++)t[n]&&(e=bR(t[n]))&&(r&&(r+=" "),r+=e);return r},sq=(t,...e)=>{let r,n,i,a;const o=u=>{const d=e.reduce((p,f)=>f(p),t());return r=rq(d),n=r.cache.get,i=r.cache.set,a=c,c(u)},c=u=>{const d=n(u);if(d)return d;const p=aq(u,r);return i(u,p),p};return a=o,(...u)=>a(oq(...u))},lq=[],ir=t=>{const e=r=>r[t]||lq;return e.isThemeGetter=!0,e},xR=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,wR=/^\((?:(\w[\w-]*):)?(.+)\)$/i,cq=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,uq=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,dq=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,fq=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,hq=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,pq=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Ta=t=>cq.test(t),Ye=t=>!!t&&!Number.isNaN(Number(t)),gi=t=>!!t&&Number.isInteger(Number(t)),Wg=t=>t.endsWith("%")&&Ye(t.slice(0,-1)),zi=t=>uq.test(t),_R=()=>!0,mq=t=>dq.test(t)&&!fq.test(t),u1=()=>!1,gq=t=>hq.test(t),yq=t=>pq.test(t),vq=t=>!ke(t)&&!Oe(t),bq=t=>t.startsWith("@container")&&(t[10]==="/"&&t[11]!==void 0||t[11]==="s"&&t[16]!==void 0&&t.startsWith("-size/",10)||t[11]==="n"&&t[18]!==void 0&&t.startsWith("-normal/",10)),xq=t=>Ha(t,ER,u1),ke=t=>xR.test(t),vo=t=>Ha(t,AR,mq),qE=t=>Ha(t,Tq,Ye),wq=t=>Ha(t,TR,_R),_q=t=>Ha(t,OR,u1),FE=t=>Ha(t,SR,u1),Sq=t=>Ha(t,kR,yq),mf=t=>Ha(t,CR,gq),Oe=t=>wR.test(t),pc=t=>zo(t,AR),kq=t=>zo(t,OR),HE=t=>zo(t,SR),Eq=t=>zo(t,ER),Aq=t=>zo(t,kR),gf=t=>zo(t,CR,!0),Oq=t=>zo(t,TR,!0),Ha=(t,e,r)=>{const n=xR.exec(t);return n?n[1]?e(n[1]):r(n[2]):!1},zo=(t,e,r=!1)=>{const n=wR.exec(t);return n?n[1]?e(n[1]):r:!1},SR=t=>t==="position"||t==="percentage",kR=t=>t==="image"||t==="url",ER=t=>t==="length"||t==="size"||t==="bg-size",AR=t=>t==="length",Tq=t=>t==="number",OR=t=>t==="family-name",TR=t=>t==="number"||t==="weight",CR=t=>t==="shadow",Cq=()=>{const t=ir("color"),e=ir("font"),r=ir("text"),n=ir("font-weight"),i=ir("tracking"),a=ir("leading"),o=ir("breakpoint"),c=ir("container"),u=ir("spacing"),d=ir("radius"),p=ir("shadow"),f=ir("inset-shadow"),m=ir("text-shadow"),v=ir("drop-shadow"),b=ir("blur"),w=ir("perspective"),x=ir("aspect"),k=ir("ease"),S=ir("animate"),A=()=>["auto","avoid","all","avoid-page","page","left","right","column"],C=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],T=()=>[...C(),Oe,ke],O=()=>["auto","hidden","clip","visible","scroll"],N=()=>["auto","contain","none"],R=()=>[Oe,ke,u],$=()=>[Ta,"full","auto",...R()],W=()=>[gi,"none","subgrid",Oe,ke],z=()=>["auto",{span:["full",gi,Oe,ke]},gi,Oe,ke],U=()=>[gi,"auto",Oe,ke],F=()=>["auto","min","max","fr",Oe,ke],X=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],Y=()=>["start","end","center","stretch","center-safe","end-safe"],G=()=>["auto",...R()],Z=()=>[Ta,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...R()],K=()=>[Ta,"screen","full","dvw","lvw","svw","min","max","fit",...R()],ee=()=>[Ta,"screen","full","lh","dvh","lvh","svh","min","max","fit",...R()],L=()=>[t,Oe,ke],I=()=>[...C(),HE,FE,{position:[Oe,ke]}],q=()=>["no-repeat",{repeat:["","x","y","space","round"]}],Q=()=>["auto","cover","contain",Eq,xq,{size:[Oe,ke]}],le=()=>[Wg,pc,vo],fe=()=>["","none","full",d,Oe,ke],ve=()=>["",Ye,pc,vo],qe=()=>["solid","dashed","dotted","double"],xe=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],ae=()=>[Ye,Wg,HE,FE],Se=()=>["","none",b,Oe,ke],Me=()=>["none",Ye,Oe,ke],oe=()=>["none",Ye,Oe,ke],rt=()=>[Ye,Oe,ke],Fe=()=>[Ta,"full",...R()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[zi],breakpoint:[zi],color:[_R],container:[zi],"drop-shadow":[zi],ease:["in","out","in-out"],font:[vq],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[zi],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[zi],shadow:[zi],spacing:["px",Ye],text:[zi],"text-shadow":[zi],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",Ta,ke,Oe,x]}],container:["container"],"container-type":[{"@container":["","normal","size",Oe,ke]}],"container-named":[bq],columns:[{columns:[Ye,ke,Oe,c]}],"break-after":[{"break-after":A()}],"break-before":[{"break-before":A()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:T()}],overflow:[{overflow:O()}],"overflow-x":[{"overflow-x":O()}],"overflow-y":[{"overflow-y":O()}],overscroll:[{overscroll:N()}],"overscroll-x":[{"overscroll-x":N()}],"overscroll-y":[{"overscroll-y":N()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:$()}],"inset-x":[{"inset-x":$()}],"inset-y":[{"inset-y":$()}],start:[{"inset-s":$(),start:$()}],end:[{"inset-e":$(),end:$()}],"inset-bs":[{"inset-bs":$()}],"inset-be":[{"inset-be":$()}],top:[{top:$()}],right:[{right:$()}],bottom:[{bottom:$()}],left:[{left:$()}],visibility:["visible","invisible","collapse"],z:[{z:[gi,"auto",Oe,ke]}],basis:[{basis:[Ta,"full","auto",c,...R()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[Ye,Ta,"auto","initial","none",ke]}],grow:[{grow:["",Ye,Oe,ke]}],shrink:[{shrink:["",Ye,Oe,ke]}],order:[{order:[gi,"first","last","none",Oe,ke]}],"grid-cols":[{"grid-cols":W()}],"col-start-end":[{col:z()}],"col-start":[{"col-start":U()}],"col-end":[{"col-end":U()}],"grid-rows":[{"grid-rows":W()}],"row-start-end":[{row:z()}],"row-start":[{"row-start":U()}],"row-end":[{"row-end":U()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":F()}],"auto-rows":[{"auto-rows":F()}],gap:[{gap:R()}],"gap-x":[{"gap-x":R()}],"gap-y":[{"gap-y":R()}],"justify-content":[{justify:[...X(),"normal"]}],"justify-items":[{"justify-items":[...Y(),"normal"]}],"justify-self":[{"justify-self":["auto",...Y()]}],"align-content":[{content:["normal",...X()]}],"align-items":[{items:[...Y(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...Y(),{baseline:["","last"]}]}],"place-content":[{"place-content":X()}],"place-items":[{"place-items":[...Y(),"baseline"]}],"place-self":[{"place-self":["auto",...Y()]}],p:[{p:R()}],px:[{px:R()}],py:[{py:R()}],ps:[{ps:R()}],pe:[{pe:R()}],pbs:[{pbs:R()}],pbe:[{pbe:R()}],pt:[{pt:R()}],pr:[{pr:R()}],pb:[{pb:R()}],pl:[{pl:R()}],m:[{m:G()}],mx:[{mx:G()}],my:[{my:G()}],ms:[{ms:G()}],me:[{me:G()}],mbs:[{mbs:G()}],mbe:[{mbe:G()}],mt:[{mt:G()}],mr:[{mr:G()}],mb:[{mb:G()}],ml:[{ml:G()}],"space-x":[{"space-x":R()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":R()}],"space-y-reverse":["space-y-reverse"],size:[{size:Z()}],"inline-size":[{inline:["auto",...K()]}],"min-inline-size":[{"min-inline":["auto",...K()]}],"max-inline-size":[{"max-inline":["none",...K()]}],"block-size":[{block:["auto",...ee()]}],"min-block-size":[{"min-block":["auto",...ee()]}],"max-block-size":[{"max-block":["none",...ee()]}],w:[{w:[c,"screen",...Z()]}],"min-w":[{"min-w":[c,"screen","none",...Z()]}],"max-w":[{"max-w":[c,"screen","none","prose",{screen:[o]},...Z()]}],h:[{h:["screen","lh",...Z()]}],"min-h":[{"min-h":["screen","lh","none",...Z()]}],"max-h":[{"max-h":["screen","lh",...Z()]}],"font-size":[{text:["base",r,pc,vo]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[n,Oq,wq]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",Wg,ke]}],"font-family":[{font:[kq,_q,e]}],"font-features":[{"font-features":[ke]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[i,Oe,ke]}],"line-clamp":[{"line-clamp":[Ye,"none",Oe,qE]}],leading:[{leading:[a,...R()]}],"list-image":[{"list-image":["none",Oe,ke]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",Oe,ke]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:L()}],"text-color":[{text:L()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...qe(),"wavy"]}],"text-decoration-thickness":[{decoration:[Ye,"from-font","auto",Oe,vo]}],"text-decoration-color":[{decoration:L()}],"underline-offset":[{"underline-offset":[Ye,"auto",Oe,ke]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:R()}],"tab-size":[{tab:[gi,Oe,ke]}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",Oe,ke]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",Oe,ke]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:I()}],"bg-repeat":[{bg:q()}],"bg-size":[{bg:Q()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},gi,Oe,ke],radial:["",Oe,ke],conic:[gi,Oe,ke]},Aq,Sq]}],"bg-color":[{bg:L()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:L()}],"gradient-via":[{via:L()}],"gradient-to":[{to:L()}],rounded:[{rounded:fe()}],"rounded-s":[{"rounded-s":fe()}],"rounded-e":[{"rounded-e":fe()}],"rounded-t":[{"rounded-t":fe()}],"rounded-r":[{"rounded-r":fe()}],"rounded-b":[{"rounded-b":fe()}],"rounded-l":[{"rounded-l":fe()}],"rounded-ss":[{"rounded-ss":fe()}],"rounded-se":[{"rounded-se":fe()}],"rounded-ee":[{"rounded-ee":fe()}],"rounded-es":[{"rounded-es":fe()}],"rounded-tl":[{"rounded-tl":fe()}],"rounded-tr":[{"rounded-tr":fe()}],"rounded-br":[{"rounded-br":fe()}],"rounded-bl":[{"rounded-bl":fe()}],"border-w":[{border:ve()}],"border-w-x":[{"border-x":ve()}],"border-w-y":[{"border-y":ve()}],"border-w-s":[{"border-s":ve()}],"border-w-e":[{"border-e":ve()}],"border-w-bs":[{"border-bs":ve()}],"border-w-be":[{"border-be":ve()}],"border-w-t":[{"border-t":ve()}],"border-w-r":[{"border-r":ve()}],"border-w-b":[{"border-b":ve()}],"border-w-l":[{"border-l":ve()}],"divide-x":[{"divide-x":ve()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":ve()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...qe(),"hidden","none"]}],"divide-style":[{divide:[...qe(),"hidden","none"]}],"border-color":[{border:L()}],"border-color-x":[{"border-x":L()}],"border-color-y":[{"border-y":L()}],"border-color-s":[{"border-s":L()}],"border-color-e":[{"border-e":L()}],"border-color-bs":[{"border-bs":L()}],"border-color-be":[{"border-be":L()}],"border-color-t":[{"border-t":L()}],"border-color-r":[{"border-r":L()}],"border-color-b":[{"border-b":L()}],"border-color-l":[{"border-l":L()}],"divide-color":[{divide:L()}],"outline-style":[{outline:[...qe(),"none","hidden"]}],"outline-offset":[{"outline-offset":[Ye,Oe,ke]}],"outline-w":[{outline:["",Ye,pc,vo]}],"outline-color":[{outline:L()}],shadow:[{shadow:["","none",p,gf,mf]}],"shadow-color":[{shadow:L()}],"inset-shadow":[{"inset-shadow":["none",f,gf,mf]}],"inset-shadow-color":[{"inset-shadow":L()}],"ring-w":[{ring:ve()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:L()}],"ring-offset-w":[{"ring-offset":[Ye,vo]}],"ring-offset-color":[{"ring-offset":L()}],"inset-ring-w":[{"inset-ring":ve()}],"inset-ring-color":[{"inset-ring":L()}],"text-shadow":[{"text-shadow":["none",m,gf,mf]}],"text-shadow-color":[{"text-shadow":L()}],opacity:[{opacity:[Ye,Oe,ke]}],"mix-blend":[{"mix-blend":[...xe(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":xe()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[Ye]}],"mask-image-linear-from-pos":[{"mask-linear-from":ae()}],"mask-image-linear-to-pos":[{"mask-linear-to":ae()}],"mask-image-linear-from-color":[{"mask-linear-from":L()}],"mask-image-linear-to-color":[{"mask-linear-to":L()}],"mask-image-t-from-pos":[{"mask-t-from":ae()}],"mask-image-t-to-pos":[{"mask-t-to":ae()}],"mask-image-t-from-color":[{"mask-t-from":L()}],"mask-image-t-to-color":[{"mask-t-to":L()}],"mask-image-r-from-pos":[{"mask-r-from":ae()}],"mask-image-r-to-pos":[{"mask-r-to":ae()}],"mask-image-r-from-color":[{"mask-r-from":L()}],"mask-image-r-to-color":[{"mask-r-to":L()}],"mask-image-b-from-pos":[{"mask-b-from":ae()}],"mask-image-b-to-pos":[{"mask-b-to":ae()}],"mask-image-b-from-color":[{"mask-b-from":L()}],"mask-image-b-to-color":[{"mask-b-to":L()}],"mask-image-l-from-pos":[{"mask-l-from":ae()}],"mask-image-l-to-pos":[{"mask-l-to":ae()}],"mask-image-l-from-color":[{"mask-l-from":L()}],"mask-image-l-to-color":[{"mask-l-to":L()}],"mask-image-x-from-pos":[{"mask-x-from":ae()}],"mask-image-x-to-pos":[{"mask-x-to":ae()}],"mask-image-x-from-color":[{"mask-x-from":L()}],"mask-image-x-to-color":[{"mask-x-to":L()}],"mask-image-y-from-pos":[{"mask-y-from":ae()}],"mask-image-y-to-pos":[{"mask-y-to":ae()}],"mask-image-y-from-color":[{"mask-y-from":L()}],"mask-image-y-to-color":[{"mask-y-to":L()}],"mask-image-radial":[{"mask-radial":[Oe,ke]}],"mask-image-radial-from-pos":[{"mask-radial-from":ae()}],"mask-image-radial-to-pos":[{"mask-radial-to":ae()}],"mask-image-radial-from-color":[{"mask-radial-from":L()}],"mask-image-radial-to-color":[{"mask-radial-to":L()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":C()}],"mask-image-conic-pos":[{"mask-conic":[Ye]}],"mask-image-conic-from-pos":[{"mask-conic-from":ae()}],"mask-image-conic-to-pos":[{"mask-conic-to":ae()}],"mask-image-conic-from-color":[{"mask-conic-from":L()}],"mask-image-conic-to-color":[{"mask-conic-to":L()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:I()}],"mask-repeat":[{mask:q()}],"mask-size":[{mask:Q()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",Oe,ke]}],filter:[{filter:["","none",Oe,ke]}],blur:[{blur:Se()}],brightness:[{brightness:[Ye,Oe,ke]}],contrast:[{contrast:[Ye,Oe,ke]}],"drop-shadow":[{"drop-shadow":["","none",v,gf,mf]}],"drop-shadow-color":[{"drop-shadow":L()}],grayscale:[{grayscale:["",Ye,Oe,ke]}],"hue-rotate":[{"hue-rotate":[Ye,Oe,ke]}],invert:[{invert:["",Ye,Oe,ke]}],saturate:[{saturate:[Ye,Oe,ke]}],sepia:[{sepia:["",Ye,Oe,ke]}],"backdrop-filter":[{"backdrop-filter":["","none",Oe,ke]}],"backdrop-blur":[{"backdrop-blur":Se()}],"backdrop-brightness":[{"backdrop-brightness":[Ye,Oe,ke]}],"backdrop-contrast":[{"backdrop-contrast":[Ye,Oe,ke]}],"backdrop-grayscale":[{"backdrop-grayscale":["",Ye,Oe,ke]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[Ye,Oe,ke]}],"backdrop-invert":[{"backdrop-invert":["",Ye,Oe,ke]}],"backdrop-opacity":[{"backdrop-opacity":[Ye,Oe,ke]}],"backdrop-saturate":[{"backdrop-saturate":[Ye,Oe,ke]}],"backdrop-sepia":[{"backdrop-sepia":["",Ye,Oe,ke]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":R()}],"border-spacing-x":[{"border-spacing-x":R()}],"border-spacing-y":[{"border-spacing-y":R()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",Oe,ke]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[Ye,"initial",Oe,ke]}],ease:[{ease:["linear","initial",k,Oe,ke]}],delay:[{delay:[Ye,Oe,ke]}],animate:[{animate:["none",S,Oe,ke]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[w,Oe,ke]}],"perspective-origin":[{"perspective-origin":T()}],rotate:[{rotate:Me()}],"rotate-x":[{"rotate-x":Me()}],"rotate-y":[{"rotate-y":Me()}],"rotate-z":[{"rotate-z":Me()}],scale:[{scale:oe()}],"scale-x":[{"scale-x":oe()}],"scale-y":[{"scale-y":oe()}],"scale-z":[{"scale-z":oe()}],"scale-3d":["scale-3d"],skew:[{skew:rt()}],"skew-x":[{"skew-x":rt()}],"skew-y":[{"skew-y":rt()}],transform:[{transform:[Oe,ke,"","none","gpu","cpu"]}],"transform-origin":[{origin:T()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:Fe()}],"translate-x":[{"translate-x":Fe()}],"translate-y":[{"translate-y":Fe()}],"translate-z":[{"translate-z":Fe()}],"translate-none":["translate-none"],zoom:[{zoom:[gi,Oe,ke]}],accent:[{accent:L()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:L()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",Oe,ke]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scrollbar-thumb-color":[{"scrollbar-thumb":L()}],"scrollbar-track-color":[{"scrollbar-track":L()}],"scrollbar-gutter":[{"scrollbar-gutter":["auto","stable","both"]}],"scrollbar-w":[{scrollbar:["auto","thin","none"]}],"scroll-m":[{"scroll-m":R()}],"scroll-mx":[{"scroll-mx":R()}],"scroll-my":[{"scroll-my":R()}],"scroll-ms":[{"scroll-ms":R()}],"scroll-me":[{"scroll-me":R()}],"scroll-mbs":[{"scroll-mbs":R()}],"scroll-mbe":[{"scroll-mbe":R()}],"scroll-mt":[{"scroll-mt":R()}],"scroll-mr":[{"scroll-mr":R()}],"scroll-mb":[{"scroll-mb":R()}],"scroll-ml":[{"scroll-ml":R()}],"scroll-p":[{"scroll-p":R()}],"scroll-px":[{"scroll-px":R()}],"scroll-py":[{"scroll-py":R()}],"scroll-ps":[{"scroll-ps":R()}],"scroll-pe":[{"scroll-pe":R()}],"scroll-pbs":[{"scroll-pbs":R()}],"scroll-pbe":[{"scroll-pbe":R()}],"scroll-pt":[{"scroll-pt":R()}],"scroll-pr":[{"scroll-pr":R()}],"scroll-pb":[{"scroll-pb":R()}],"scroll-pl":[{"scroll-pl":R()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",Oe,ke]}],fill:[{fill:["none",...L()]}],"stroke-w":[{stroke:[Ye,pc,vo,qE]}],stroke:[{stroke:["none",...L()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{"container-named":["container-type"],overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},postfixLookupClassGroups:["container-type"],orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},jq=sq(Cq);function Cc(...t){return jq(ot(t))}const Nq=[{to:"/squads",icon:a1,label:"Squads"},{to:"/skills",icon:tx,label:"Skills"},{to:"/schedules",icon:yz,label:"Schedules"},{to:"/wiki",icon:RP,label:"Wiki"},{to:"/usage",icon:bz,label:"Usage"}],Pq=[{to:"/",icon:n1,label:"Chat"},{to:"/feed",icon:ex,label:"Inbox"},{to:"/settings",icon:pB,label:"Settings"}];function WE({to:t,icon:e,label:r,collapsed:n,badge:i}){return y.jsxs(rP,{to:t,end:t==="/",title:n?r:void 0,className:({isActive:a})=>Cc("w-full flex items-center gap-2.5 px-2 py-2 rounded-xl text-[11px] font-mono transition-colors cursor-pointer relative",n?"justify-center":"",a?"text-[#E43A9C]":"text-zinc-600 hover:text-zinc-300 hover:bg-white/[0.04]"),style:({isActive:a})=>a?{background:"rgba(228,58,156,0.1)"}:void 0,children:[y.jsx(e,{className:"w-3.5 h-3.5 flex-shrink-0"}),!n&&r,i!=null&&i>0&&y.jsx("span",{className:"absolute top-1 right-1 min-w-[14px] h-[14px] flex items-center justify-center rounded-full bg-[#E43A9C] text-[9px] text-white font-mono px-1",children:i>99?"99+":i})]})}function Rq(){const[t,e]=j.useState(!1),[r,n]=j.useState(""),[i,a]=j.useState(0),{supabase:o}=gp();return j.useEffect(()=>{Ge.get("/version").then(c=>n(c.version)).catch(()=>n("unknown"))},[]),j.useEffect(()=>{let c=!0;const u=()=>{Ge.get("/inbox?limit=200").then(p=>{if(!c)return;const f=p.entries??[];a(f.filter(m=>m.status==="pending").length)}).catch(()=>{})};u();const d=setInterval(u,3e4);return()=>{c=!1,clearInterval(d)}},[]),y.jsxs("div",{className:"flex h-screen overflow-hidden bg-background relative",children:[y.jsxs("div",{className:Cc("flex-shrink-0 flex flex-col border-r border-white/[0.06] bg-[#181818] transition-all duration-200",t?"w-[52px]":"w-[210px]"),children:[y.jsx("div",{className:Cc("h-[52px] flex items-center border-b border-white/[0.06] flex-shrink-0",t?"justify-center px-3":"justify-between pl-4 pr-3"),children:t?y.jsx(Ia,{height:26}):y.jsxs("div",{className:"flex items-center gap-2.5",children:[y.jsx(Ia,{height:26}),y.jsx("span",{className:"text-2xl text-white tracking-wider leading-none",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"IO"})]})}),y.jsx("nav",{className:"flex-1 py-2 px-1.5 space-y-0.5 overflow-y-auto",children:Nq.map(c=>y.jsx(WE,{collapsed:t,...c},c.to))}),y.jsxs("div",{className:"flex-shrink-0 border-t border-white/[0.06]",children:[y.jsx("div",{className:"py-1.5 px-1.5 space-y-0.5",children:Pq.map(c=>y.jsx(WE,{collapsed:t,badge:c.to==="/feed"?i:void 0,...c},c.to))}),y.jsxs("div",{className:"border-t border-white/[0.05] py-1.5 px-1.5 space-y-0.5",children:[y.jsxs("a",{href:`https://github.com/michaeljolley/io/releases/tag/v${r}`,target:"_blank",rel:"noreferrer",title:"GitHub",className:Cc("flex items-center gap-2.5 px-2 py-2 rounded-xl text-[11px] font-mono text-zinc-600 hover:text-zinc-300 hover:bg-white/[0.04] transition-colors cursor-pointer",t&&"justify-center"),children:[y.jsx(r1,{className:"w-3.5 h-3.5 flex-shrink-0"}),!t&&y.jsxs("span",{className:"text-zinc-700",children:["v",r]})]}),y.jsx("button",{type:"button",onClick:()=>e(!t),title:t?"Expand sidebar":"Collapse sidebar",className:Cc("w-full flex items-center gap-2.5 px-2 py-2 rounded-xl text-[11px] font-mono text-zinc-600 hover:text-zinc-300 hover:bg-white/[0.04] transition-colors cursor-pointer",t&&"justify-center"),children:t?y.jsx(Qw,{className:"w-3.5 h-3.5 flex-shrink-0"}):y.jsx(vl,{className:"w-3.5 h-3.5 flex-shrink-0"})})]})]})]}),y.jsxs("div",{className:"flex flex-col flex-1 min-w-0 overflow-hidden",children:[y.jsxs("div",{className:"h-[52px] flex-shrink-0 flex items-center justify-between px-4 border-b border-white/[0.06] bg-[#181818]",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(MB,{status:"connected"}),y.jsx("span",{className:"text-[11px] font-mono text-green-400",children:"connected"})]}),y.jsxs("div",{className:"flex items-center gap-1.5",children:[y.jsx(TB,{}),o&&y.jsx("button",{type:"button",onClick:()=>o.auth.signOut(),className:"p-2 rounded-xl hover:bg-white/[0.05] text-zinc-600 hover:text-zinc-300 transition-colors cursor-pointer",title:"Sign out",children:y.jsx(Xz,{className:"w-3.5 h-3.5"})})]})]}),y.jsxs("main",{className:"flex-1 overflow-hidden flex flex-col min-h-0 relative",children:[y.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",style:{zIndex:0},children:[y.jsx("div",{className:"orb orb-pink"}),y.jsx("div",{className:"orb orb-gray"})]}),y.jsx(TL,{})]})]})]})}function Iq(){const{session:t}=gp(),e=Fa(),{messages:r,streaming:n,isStreaming:i,isThinking:a,sendChatMessage:o,stopStreaming:c,addUserMessage:u,uploadAttachment:d}=WP(),[p,f]=j.useState(""),[m,v]=j.useState(null),[b,w]=j.useState(null),x=j.useRef(null),k=j.useRef(null),S=j.useRef(null);j.useLayoutEffect(()=>{const O=x.current;O&&(O.scrollTop=O.scrollHeight)});async function A(){const O=p.trim();if(!O&&!m||i||a)return;const N=crypto.randomUUID(),R=m==null?void 0:m.name,$=[O,R?`Attachment: ${R}`:""].filter(Boolean).join(`
447
447
 
448
448
  `);u({id:N,role:"user",content:O,timestamp:new Date().toISOString(),attachmentName:R}),f(""),v(null),S.current&&(S.current.value=""),k.current&&(k.current.style.height="auto");try{m&&await d(m,N),await o($)}catch{}}function C(O){O.key==="Enter"&&!O.shiftKey&&(O.preventDefault(),A())}function T(O){f(O.target.value),k.current&&(k.current.style.height="auto",k.current.style.height=`${Math.min(k.current.scrollHeight,160)}px`)}return y.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[y.jsxs("div",{ref:x,className:"flex-1 overflow-y-auto px-5 py-5 space-y-5",children:[r.map(O=>{var N,R;return y.jsxs("div",{className:`flex gap-3 ${O.role==="user"?"flex-row-reverse":""}`,children:[y.jsx("div",{className:`flex-shrink-0 w-6 h-6 rounded-lg flex items-center justify-center text-[10px] font-mono mt-0.5 ${O.role==="user"?"border border-[#E43A9C]/30 text-[#E43A9C]":"bg-[#282828] border border-white/[0.07] text-zinc-500"}`,style:O.role==="user"?{background:"rgba(228,58,156,0.12)"}:void 0,children:O.role==="user"?((R=(N=t==null?void 0:t.user)==null?void 0:N.email)==null?void 0:R.charAt(0).toUpperCase())??"U":y.jsx(Ia,{height:12})}),y.jsxs("div",{className:`flex flex-col gap-1.5 max-w-[72%] ${O.role==="user"?"items-end":"items-start"}`,children:[O.toolCall&&y.jsxs("button",{type:"button",onClick:()=>w(b===O.id?null:O.id),className:"w-full text-left border border-white/[0.07] bg-[#1e1e1e] rounded-xl px-3 py-2 flex items-center gap-2 hover:border-[#E43A9C]/25 transition-colors",children:[y.jsx(Hf,{className:"w-3 h-3 text-[#E43A9C] flex-shrink-0"}),y.jsx("span",{className:"text-[11px] font-mono text-zinc-400 flex-1",children:O.toolCall.name}),y.jsx(Rt,{variant:O.toolCall.status==="done"?"success":O.toolCall.status==="error"?"error":"warning",children:O.toolCall.status}),y.jsx(wz,{className:`w-3 h-3 text-zinc-600 transition-transform flex-shrink-0 ${b===O.id?"rotate-180":""}`})]}),O.toolCall&&b===O.id&&y.jsx("div",{className:"w-full bg-[#181818] border border-white/[0.06] rounded-xl px-3 py-2",children:y.jsx("p",{className:"text-[11px] font-mono text-zinc-500",children:O.toolCall.result})}),O.attachmentName&&y.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-[#1e1e1e] px-3 py-2 text-[11px] font-mono text-zinc-400",children:O.attachmentName}),O.content&&y.jsx("div",{className:`rounded-2xl px-4 py-2.5 text-sm leading-relaxed ${O.role==="user"?"text-white rounded-tr-sm":"bg-[#222222] border border-white/[0.07] text-zinc-200 rounded-tl-sm"}`,style:O.role==="user"?{background:"linear-gradient(135deg, #D83333 0%, #C0285E 100%)"}:void 0,children:O.role==="user"?y.jsx("p",{className:"whitespace-pre-wrap",children:O.content}):y.jsx("div",{className:"prose-io",dangerouslySetInnerHTML:{__html:it.parse(O.content)}})}),y.jsx("span",{className:"text-[11px] text-zinc-700 font-mono px-0.5",children:cp(O.timestamp,e)})]})]},O.id)}),a&&y.jsxs("div",{className:"flex gap-3",children:[y.jsx("div",{className:"flex-shrink-0 w-6 h-6 rounded-lg flex items-center justify-center bg-[#282828] border border-white/[0.07] mt-0.5",children:y.jsx(Ia,{height:12})}),y.jsx("div",{className:"bg-[#222222] border border-white/[0.07] rounded-2xl rounded-tl-sm px-4 py-3 flex items-center gap-1.5",children:[0,120,240].map(O=>y.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#E43A9C] animate-bounce",style:{animationDelay:`${O}ms`}},O))})]}),i&&n&&y.jsxs("div",{className:"flex gap-3",children:[y.jsx("div",{className:"flex-shrink-0 w-6 h-6 rounded-lg flex items-center justify-center bg-[#282828] border border-white/[0.07] mt-0.5",children:y.jsx(Ia,{height:12})}),y.jsx("div",{className:"bg-[#222222] border border-white/[0.07] rounded-2xl rounded-tl-sm px-4 py-2.5 max-w-[72%]",children:y.jsx("div",{className:"prose-io text-sm",dangerouslySetInnerHTML:{__html:it.parse(n)}})})]}),i&&!n&&y.jsxs("div",{className:"flex gap-3",children:[y.jsx("div",{className:"flex-shrink-0 w-6 h-6 rounded-lg flex items-center justify-center bg-[#282828] border border-white/[0.07] mt-0.5",children:y.jsx(Ia,{height:12})}),y.jsx("div",{className:"bg-[#222222] border border-white/[0.07] rounded-2xl rounded-tl-sm px-4 py-3 flex items-center gap-1.5",children:[0,120,240].map(O=>y.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#E43A9C] animate-bounce",style:{animationDelay:`${O}ms`}},O))})]})]}),y.jsxs("div",{className:"border-t border-white/[0.06] p-4 flex-shrink-0",children:[y.jsxs("div",{className:"bg-[#1e1e1e] border border-white/[0.08] rounded-2xl overflow-hidden transition-colors focus-within:border-[#E43A9C]/30",children:[y.jsx("input",{ref:S,type:"file",className:"hidden",onChange:O=>{var N;return v(((N=O.target.files)==null?void 0:N[0])??null)}}),m&&y.jsxs("div",{className:"px-4 pt-3 text-[11px] font-mono text-zinc-400",children:["Attached: ",m.name]}),y.jsx("textarea",{ref:k,value:p,onChange:T,onKeyDown:C,placeholder:"Message IO…",rows:1,className:"w-full bg-transparent px-4 pt-3 pb-1 text-sm text-zinc-200 placeholder:text-zinc-700 resize-none focus:outline-none",style:{minHeight:"42px",maxHeight:"160px",fontFamily:"Inter, sans-serif"}}),y.jsxs("div",{className:"flex items-center justify-between px-3 pb-2.5",children:[y.jsx("button",{type:"button",onClick:()=>{var O;return(O=S.current)==null?void 0:O.click()},className:"p-1.5 rounded-lg hover:bg-white/[0.05] text-zinc-700 hover:text-zinc-400 transition-colors",children:y.jsx(LP,{className:"w-4 h-4"})}),y.jsx("div",{className:"flex items-center gap-2",children:i?y.jsxs("button",{type:"button",onClick:()=>c(),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-zinc-800 hover:bg-zinc-700 text-[11px] font-mono text-zinc-300 transition-colors",children:[y.jsx(dp,{className:"w-3 h-3"})," Stop"]}):y.jsx("button",{type:"button",onClick:A,disabled:!p.trim()&&!m||a,className:"p-2 rounded-xl text-white disabled:opacity-30 disabled:cursor-not-allowed transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #D83333, #E43A9C)"},children:y.jsx(BP,{className:"w-3.5 h-3.5"})})})]})]}),y.jsx("p",{className:"text-center text-[11px] text-zinc-800 font-mono mt-2",children:"IO may make mistakes. Verify important outputs."})]})]})}const KE=["#38bdf8","#a78bfa","#34d399","#f59e0b","#f87171","#E43A9C"];function $q(t){let e=0;for(let r=0;r<t.length;r++)e=t.charCodeAt(r)+((e<<5)-e);return KE[Math.abs(e)%KE.length]}function GE({name:t,color:e}){const r=t.toLowerCase(),n=e??(r==="orchestrator"||r==="io"?"#71717a":$q(t));return y.jsx("span",{className:"inline-flex items-center px-1.5 py-px rounded text-[10px] font-mono border",style:{background:`${n}15`,color:n,borderColor:`${n}30`},children:t})}function mc(t){return t.status==="pending"}function Mq(){const[t,e]=j.useState([]),[r,n]=j.useState(null),[i,a]=j.useState(new Set),[o,c]=j.useState("all"),u=Fa();j.useEffect(()=>{Ge.get("/inbox").then(A=>e(A.entries??[])).catch(()=>{})},[]);const d=t.filter(mc).length,p=o==="unread"?t.filter(mc):t,f=p.length>0&&p.every(A=>i.has(A.id)),m=i.size>0;function v(A){m||(n(A),mc(A)&&(Ge.put(`/inbox/${A.id}/read`,{}).catch(()=>{}),e(C=>C.map(T=>T.id===A.id?{...T,status:"read"}:T))))}function b(A,C){A.stopPropagation(),a(T=>{const O=new Set(T);return O.has(C)?O.delete(C):O.add(C),O})}function w(){a(f?new Set:new Set(p.map(A=>A.id)))}function x(){const A=Array.from(i);Promise.allSettled(A.map(C=>Ge.put(`/inbox/${C}/read`,{}))),e(C=>C.map(T=>i.has(T.id)?{...T,status:"read"}:T)),a(new Set)}function k(){const A=Array.from(i);Promise.allSettled(A.map(C=>Ge.delete(`/inbox/${C}`))),e(C=>C.filter(T=>!i.has(T.id))),r&&i.has(r.id)&&n(null),a(new Set)}function S(A){Ge.delete(`/inbox/${A}`).catch(()=>{}),e(C=>C.filter(T=>T.id!==A)),(r==null?void 0:r.id)===A&&n(null)}return y.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[y.jsxs("div",{className:"w-72 flex-shrink-0 border-r border-white/[0.06] flex flex-col overflow-hidden",children:[y.jsxs("div",{className:"px-4 py-3 border-b border-white/[0.06] flex-shrink-0 space-y-2",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx("span",{className:"text-lg tracking-wide text-zinc-200",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Inbox"}),d>0&&y.jsxs(Rt,{variant:"default",children:[d," unread"]})]}),y.jsx("div",{className:"flex gap-1",children:["all","unread"].map(A=>y.jsx("button",{type:"button",onClick:()=>{c(A),a(new Set)},className:`flex-1 py-1 text-[11px] font-mono rounded-lg transition-colors cursor-pointer ${o===A?"text-[#E43A9C]":"text-zinc-600 hover:text-zinc-300"}`,style:o===A?{background:"rgba(228,58,156,0.12)"}:void 0,children:A},A))})]}),m&&y.jsxs("div",{className:"px-3 py-2 border-b border-white/[0.06] flex items-center gap-1.5 flex-shrink-0",style:{background:"rgba(228,58,156,0.06)"},children:[y.jsxs("span",{className:"text-[10px] font-mono text-zinc-500 flex-1",children:[i.size," selected"]}),y.jsxs("button",{type:"button",onClick:x,className:"flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-mono text-zinc-400 hover:text-zinc-200 hover:bg-white/[0.06] transition-colors cursor-pointer",children:[y.jsx(Qb,{className:"w-3 h-3"}),"Mark read"]}),y.jsxs("button",{type:"button",onClick:k,className:"flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-mono text-red-400 hover:text-red-300 hover:bg-red-500/10 transition-colors cursor-pointer",children:[y.jsx(Da,{className:"w-3 h-3"}),"Delete"]})]}),p.length>0&&y.jsxs("div",{className:"px-4 py-1.5 border-b border-white/[0.04] flex items-center gap-2 flex-shrink-0",children:[y.jsx("button",{type:"button",onClick:w,className:`w-3.5 h-3.5 rounded border flex items-center justify-center flex-shrink-0 transition-colors cursor-pointer ${f?"border-[#E43A9C] bg-[#E43A9C]":"border-white/20 hover:border-white/40"}`,children:f&&y.jsx("svg",{className:"w-2 h-2 text-white",fill:"none",viewBox:"0 0 8 8","aria-hidden":"true",children:y.jsx("path",{d:"M1 4l2 2 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),y.jsx("span",{className:"text-[10px] font-mono text-zinc-700",children:"Select all"})]}),y.jsxs("div",{className:"flex-1 overflow-y-auto",children:[p.map(A=>{const C=i.has(A.id),T=(r==null?void 0:r.id)===A.id&&!m;return y.jsxs("div",{onClick:()=>v(A),onKeyDown:O=>O.key==="Enter"&&v(A),className:`flex items-start gap-2.5 px-3 py-3 border-b border-white/[0.04] cursor-pointer transition-colors ${T?"border-l-2 border-l-[#E43A9C] pl-2.5":"hover:bg-white/[0.025]"} ${C?"bg-[#E43A9C]/5":""}`,style:T?{background:"rgba(228,58,156,0.05)"}:void 0,children:[y.jsx("button",{type:"button",onClick:O=>b(O,A.id),className:`mt-0.5 w-3.5 h-3.5 rounded border flex items-center justify-center flex-shrink-0 transition-colors cursor-pointer ${C?"border-[#E43A9C] bg-[#E43A9C]":"border-white/20 hover:border-white/50"}`,children:C&&y.jsx("svg",{className:"w-2 h-2 text-white",fill:"none",viewBox:"0 0 8 8","aria-hidden":"true",children:y.jsx("path",{d:"M1 4l2 2 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),y.jsxs("div",{className:"flex-1 min-w-0",children:[y.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[mc(A)&&y.jsx("div",{className:"w-1 h-1 rounded-full bg-[#E43A9C] flex-shrink-0"}),y.jsx(GE,{name:A.squadName??(A.squadId?A.squadId.slice(0,8):"Orchestrator"),color:A.squadColor})]}),y.jsx("p",{className:`text-[11px] truncate ${mc(A)?"text-zinc-200":"text-zinc-500"}`,children:A.title}),y.jsx("p",{className:"text-[10px] text-zinc-700 font-mono mt-1",children:Fs(A.createdAt,u)})]})]},A.id)}),p.length===0&&y.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[y.jsx(ex,{size:32,className:"text-zinc-800 mb-2"}),y.jsx("p",{className:"text-[11px] font-mono text-zinc-700",children:o==="unread"?"All caught up":"No items yet"})]})]})]}),y.jsx("div",{className:"flex-1 flex flex-col overflow-hidden",children:r&&!m?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"px-6 py-4 border-b border-white/[0.06] flex items-start justify-between flex-shrink-0",children:[y.jsxs("div",{className:"flex-1 min-w-0 mr-4",children:[y.jsx(GE,{name:r.squadName??(r.squadId?r.squadId.slice(0,8):"Orchestrator"),color:r.squadColor}),y.jsx("h3",{className:"text-sm font-mono text-zinc-100 mt-1.5",children:r.title}),y.jsx("p",{className:"text-[11px] text-zinc-700 font-mono mt-0.5",children:Fs(r.createdAt,u)})]}),y.jsxs("button",{type:"button",onClick:()=>S(r.id),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg font-mono text-[11px] text-zinc-400 bg-[#252525] hover:bg-red-500/10 hover:text-red-400 transition-colors cursor-pointer",children:[y.jsx(Da,{className:"w-3 h-3"}),"Delete"]})]}),y.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:y.jsx(Mu,{content:r.content})})]}):m?y.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 text-center px-8",children:[y.jsx("div",{className:"w-10 h-10 rounded-2xl flex items-center justify-center border border-[#E43A9C]/20",style:{background:"rgba(228,58,156,0.08)"},children:y.jsx(ex,{className:"w-4 h-4 text-[#E43A9C]"})}),y.jsxs("div",{children:[y.jsxs("p",{className:"text-sm font-mono text-zinc-300",children:[i.size," message",i.size!==1?"s":""," selected"]}),y.jsx("p",{className:"text-[11px] text-zinc-600 mt-1",children:"Use the actions above to mark as read or delete"})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("button",{type:"button",onClick:x,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[11px] font-mono text-zinc-300 border border-white/[0.1] hover:bg-white/[0.05] transition-colors cursor-pointer",children:[y.jsx(Qb,{className:"w-3 h-3"}),"Mark read"]}),y.jsxs("button",{type:"button",onClick:k,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[11px] font-mono text-red-400 border border-red-500/20 hover:bg-red-500/10 transition-colors cursor-pointer",children:[y.jsx(Da,{className:"w-3 h-3"}),"Delete selected"]})]})]}):y.jsx("div",{className:"flex-1 flex items-center justify-center text-zinc-700 font-mono text-xs",children:"Select an item to read"})})]})}function Dq(){const{signIn:t}=gp(),[e,r]=j.useState(""),[n,i]=j.useState(""),[a,o]=j.useState(null),[c,u]=j.useState(!1);async function d(p){p.preventDefault(),o(null),u(!0);const{error:f}=await t(e,n);f&&o(f),u(!1)}return y.jsxs("div",{className:"min-h-screen bg-[#161616] flex items-center justify-center relative overflow-hidden",children:[y.jsx("div",{className:"absolute inset-0 opacity-[0.04]",style:{backgroundImage:"radial-gradient(circle, #E43A9C 1px, transparent 1px)",backgroundSize:"32px 32px"}}),y.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-[60%] w-[400px] h-[300px] rounded-full blur-3xl pointer-events-none",style:{background:"radial-gradient(ellipse, rgba(228,58,156,0.12) 0%, transparent 70%)"}}),y.jsxs("div",{className:"relative z-10 w-full max-w-[360px] mx-4",children:[y.jsxs("div",{className:"flex flex-col items-center mb-8 gap-3",children:[y.jsx(Ia,{height:52}),y.jsx("div",{className:"text-center",children:y.jsx("p",{className:"text-[11px] font-mono text-zinc-600 tracking-widest uppercase mt-1",children:"personal ai orchestrator"})})]}),y.jsxs("form",{onSubmit:d,className:"glass-card border border-white/[0.07] rounded-2xl p-6 space-y-4",children:[y.jsxs("div",{className:"space-y-1",children:[y.jsx("label",{htmlFor:"login-email",className:"text-[11px] font-mono text-zinc-500 block",children:"Email"}),y.jsx("input",{id:"login-email",type:"email",value:e,onChange:p=>r(p.target.value),required:!0,className:"w-full bg-[#161616] border border-white/[0.08] rounded-xl px-3 py-2.5 text-sm text-zinc-200 font-mono placeholder:text-zinc-700 focus:outline-none focus:border-[#E43A9C]/40 focus:ring-1 focus:ring-[#E43A9C]/15 transition-colors"})]}),y.jsxs("div",{className:"space-y-1",children:[y.jsx("label",{htmlFor:"login-password",className:"text-[11px] font-mono text-zinc-500 block",children:"Password"}),y.jsx("input",{id:"login-password",type:"password",value:n,onChange:p=>i(p.target.value),required:!0,placeholder:"••••••••",className:"w-full bg-[#161616] border border-white/[0.08] rounded-xl px-3 py-2.5 text-sm text-zinc-200 font-mono placeholder:text-zinc-700 focus:outline-none focus:border-[#E43A9C]/40 focus:ring-1 focus:ring-[#E43A9C]/15 transition-colors"})]}),a&&y.jsx("p",{className:"text-[11px] font-mono text-red-400",children:a}),y.jsx("button",{type:"submit",disabled:c,className:"w-full text-white font-mono text-sm rounded-xl py-3 mt-1 transition-opacity hover:opacity-90 disabled:opacity-50 flex items-center justify-center gap-2",style:{background:"linear-gradient(135deg, #D83333 0%, #E43A9C 55%, #F041FF 100%)"},children:c?y.jsxs(y.Fragment,{children:[y.jsx("span",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Authenticating…"]}):"Sign In"})]}),y.jsx("p",{className:"text-center text-[11px] text-zinc-700 font-mono mt-4",children:"Secured by Supabase Auth"})]})]})}const jR="w-full bg-[#161616] border border-white/[0.08] rounded-xl px-3 py-2 text-[11px] text-zinc-300 font-mono placeholder:text-zinc-700 focus:outline-none focus:border-[#E43A9C]/40 focus:ring-1 focus:ring-[#E43A9C]/10 transition-colors",Ls="bg-[#161616] border border-white/[0.08] rounded-xl px-3 py-2 text-[11px] text-zinc-300 font-mono placeholder:text-zinc-700 focus:outline-none focus:border-[#E43A9C]/40 focus:ring-1 focus:ring-[#E43A9C]/10 transition-colors";function Fi({label:t,hint:e,align:r="center",children:n}){const i=r==="start"?"flex-1 min-w-0":"flex-1 flex justify-end items-center";return y.jsxs("div",{className:`glass-card border border-white/[0.07] rounded-2xl px-4 py-3.5 flex gap-4 ${r==="start"?"items-start":"items-center"}`,children:[y.jsxs("div",{className:"w-[140px] shrink-0",children:[y.jsx("span",{className:"text-[11px] font-mono text-zinc-400",children:t}),e&&y.jsxs("span",{className:"text-[10px] font-mono text-zinc-700 ml-1.5",children:["(",e,")"]})]}),y.jsx("div",{className:i,children:n})]})}function Lq({onSave:t,onCancel:e,squads:r}){var b;const[n,i]=j.useState("io"),[a,o]=j.useState(((b=r[0])==null?void 0:b.id)??""),[c,u]=j.useState(""),[d,p]=j.useState(""),[f,m]=j.useState(""),v=()=>{!d.trim()||!f.trim()||!c.trim()||t({name:c.trim(),targetType:n==="io"?"orchestrator":"squad",targetId:n==="squad"?a:void 0,cron:d.trim(),prompt:f.trim()})};return y.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center p-6",style:{background:"rgba(0,0,0,0.55)",backdropFilter:"blur(4px)"},children:y.jsxs("div",{className:"glass-card border border-white/[0.09] rounded-2xl w-full max-w-lg shadow-2xl flex flex-col",style:{maxHeight:"90vh"},children:[y.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/[0.06] flex-shrink-0",children:[y.jsx("h3",{className:"text-lg tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"New Schedule"}),y.jsx("button",{type:"button",onClick:e,className:"p-1.5 rounded-lg text-zinc-600 hover:text-zinc-300 hover:bg-white/[0.06] transition-colors cursor-pointer",children:y.jsx(qP,{className:"w-4 h-4"})})]}),y.jsxs("div",{className:"overflow-y-auto flex-1 px-5 py-4 space-y-2",children:[y.jsx(Fi,{label:"Name",children:y.jsx("input",{value:c,onChange:w=>u(w.target.value),placeholder:"Daily triage",className:`${Ls} w-48`})}),y.jsx(Fi,{label:"Type",children:y.jsx("div",{className:"flex gap-2",children:["io","squad"].map(w=>y.jsx("button",{type:"button",onClick:()=>i(w),className:`px-4 py-1.5 rounded-xl text-[11px] font-mono capitalize transition-colors border cursor-pointer ${n===w?"text-[#E43A9C] border-[#E43A9C]/30":"text-zinc-500 border-white/[0.08] hover:text-zinc-300 hover:bg-white/[0.04]"}`,style:n===w?{background:"rgba(228,58,156,0.08)"}:void 0,children:w==="io"?"IO":"Squad"},w))})}),n==="squad"&&y.jsx(Fi,{label:"Squad",children:y.jsx("select",{value:a,onChange:w=>o(w.target.value),className:`${Ls} w-48`,children:r.map(w=>y.jsx("option",{value:w.id,style:{background:"#1a1a1a",color:"#d4d4d8"},children:w.name},w.id))})}),y.jsx(Fi,{label:"Cron Expression",children:y.jsx("input",{value:d,onChange:w=>p(w.target.value),placeholder:"0 9 * * 1-5",className:`${Ls} w-40`})}),y.jsx(Fi,{label:"Prompt",hint:"supports Markdown",align:"start",children:y.jsx("textarea",{value:f,onChange:w=>m(w.target.value),placeholder:"Describe what IO or the squad should do when this schedule fires.",rows:8,className:`${jR} resize-none leading-relaxed`})})]}),y.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3.5 border-t border-white/[0.06] flex-shrink-0",children:[y.jsx(wi,{onClick:e,children:"Cancel"}),y.jsxs(Ba,{onClick:v,className:"px-4 py-1.5",children:[y.jsx(up,{className:"w-3 h-3"}),"Create Schedule"]})]})]})})}function zq({sched:t,squads:e,onSave:r,onBack:n}){var b,w;const[i,a]=j.useState(t.name),[o,c]=j.useState(t.cron),[u,d]=j.useState(t.prompt),[p,f]=j.useState(t.targetId??((b=e[0])==null?void 0:b.id)??""),m=()=>{!o.trim()||!u.trim()||!i.trim()||r({name:i.trim(),cron:o.trim(),prompt:u.trim(),targetId:t.targetType==="squad"?p:void 0})},v=t.targetType==="orchestrator"?"IO Schedule":`Squad — ${((w=e.find(x=>x.id===t.targetId))==null?void 0:w.name)??"Unknown"}`;return y.jsxs("div",{className:"flex-1 overflow-y-auto p-6 max-w-3xl",children:[y.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[y.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-1.5 text-[11px] font-mono text-zinc-600 hover:text-zinc-300 transition-colors cursor-pointer",children:[y.jsx(vl,{className:"w-3.5 h-3.5"}),"Schedules"]}),y.jsx("span",{className:"text-zinc-700 text-[11px]",children:"/"}),y.jsx("span",{className:"text-[11px] font-mono text-zinc-400",children:"Edit"})]}),y.jsxs("div",{className:"flex items-start justify-between mb-6",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Edit Schedule"}),y.jsx("p",{className:"text-[11px] font-mono text-zinc-600 mt-0.5",children:v})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(wi,{onClick:n,children:"Cancel"}),y.jsxs(Ba,{onClick:m,className:"px-4 py-1.5",children:[y.jsx(up,{className:"w-3 h-3"}),"Save Changes"]})]})]}),y.jsxs("div",{className:"space-y-3",children:[y.jsx(Fi,{label:"Name",children:y.jsx("input",{value:i,onChange:x=>a(x.target.value),placeholder:"Schedule name",className:`${Ls} w-48`})}),t.targetType==="squad"&&y.jsx(Fi,{label:"Squad",children:y.jsx("select",{value:p,onChange:x=>f(x.target.value),className:`${Ls} w-48`,children:e.map(x=>y.jsx("option",{value:x.id,style:{background:"#1a1a1a",color:"#d4d4d8"},children:x.name},x.id))})}),y.jsx(Fi,{label:"Cron Expression",children:y.jsx("input",{value:o,onChange:x=>c(x.target.value),placeholder:"0 9 * * 1-5",className:`${Ls} w-40`})}),y.jsx(Fi,{label:"Prompt",hint:"supports Markdown",align:"start",children:y.jsxs("div",{className:"space-y-1.5",children:[y.jsx("textarea",{value:u,onChange:x=>d(x.target.value),placeholder:"Describe what IO or the squad should do when this schedule fires.",className:`${jR} leading-relaxed resize-y`,style:{minHeight:"360px"}}),y.jsx("p",{className:"text-[10px] font-mono text-zinc-700",children:"Tip: use # headings and - lists to structure multi-step instructions."})]})})]})]})}function Bq(){const[t,e]=j.useState("squad"),[r,n]=j.useState([]),[i,a]=j.useState([]),[o,c]=j.useState(!1),[u,d]=j.useState(null),p=Fa();j.useEffect(()=>{f(),m()},[]);function f(){Ge.get("/schedules").then(R=>n(R.schedules)).catch(()=>{})}function m(){Ge.get("/squads").then(R=>a(R.squads)).catch(()=>{})}const v=r.filter(R=>R.targetType==="squad"),b=r.filter(R=>R.targetType==="orchestrator"),w=t==="squad"?v:b;async function x(R){try{await Ge.post("/schedules",R),Qe.success("Schedule created"),c(!1),f()}catch($){Qe.error($ instanceof Error?$.message:"Failed to create")}}async function k(R){if(u)try{await Ge.patch(`/schedules/${u.id}`,R),Qe.success("Schedule saved"),d(null),f()}catch{Qe.error("Failed to save schedule")}}const[S,A]=j.useState(null);async function C(R,$){A(R);try{await Ge.patch(`/schedules/${R}`,{enabled:!$}),Qe.success($?"Schedule paused":"Schedule resumed"),f()}catch{Qe.error("Failed to toggle schedule")}finally{A(null)}}async function T(R){A(R);try{await Ge.post(`/schedules/${R}/run`,{}),Qe.success("Schedule triggered")}catch{Qe.error("Failed to trigger schedule")}finally{A(null)}}async function O(R){A(R);try{await Ge.delete(`/schedules/${R}`),Qe.success("Schedule deleted"),f()}catch{Qe.error("Failed to delete")}finally{A(null)}}if(u)return y.jsx(zq,{sched:u,squads:i,onSave:k,onBack:()=>d(null)});const N=t==="squad"?["Squad","Name","Cron","Next Run","Status",""]:["Name","Cron","Next Run","Status",""];return y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[o&&y.jsx(Lq,{onSave:x,onCancel:()=>c(!1),squads:i}),y.jsxs("div",{className:"flex items-center justify-between mb-5",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Schedules"}),y.jsxs("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:[r.filter(R=>R.enabled).length," active ·"," ",r.filter(R=>!R.enabled).length," paused"]})]}),y.jsxs(Ba,{onClick:()=>c(!0),className:"px-3 py-1.5",children:[y.jsx(i1,{className:"w-3.5 h-3.5"}),"Add Schedule"]})]}),y.jsx("div",{className:"flex gap-1 mb-4",children:[["squad","Squad Schedules"],["io","IO Schedules"]].map(([R,$])=>y.jsx("button",{type:"button",onClick:()=>e(R),className:`px-4 py-2 text-[11px] font-mono rounded-xl transition-colors cursor-pointer ${t===R?"text-[#E43A9C]":"text-zinc-600 hover:text-zinc-300 hover:bg-white/[0.04]"}`,style:t===R?{background:"rgba(228,58,156,0.12)"}:void 0,children:$},R))}),y.jsx("div",{className:"overflow-x-auto rounded-2xl border border-white/[0.07] glass-card",children:w.length===0?y.jsx("div",{className:"px-4 py-12 text-center text-zinc-600 font-mono text-sm",children:"No schedules for this category"}):y.jsxs("table",{className:"w-full text-[11px] font-mono min-w-[640px]",children:[y.jsx("thead",{children:y.jsx("tr",{className:"border-b border-white/[0.06]",style:{background:"rgba(20,20,20,0.6)"},children:N.map(R=>y.jsx("th",{className:"text-left px-4 py-2.5 text-zinc-600 font-medium",children:R},R))})}),y.jsx("tbody",{children:w.map(R=>{var $,W;return y.jsxs("tr",{className:`border-b border-white/[0.04] hover:bg-white/[0.015] transition-colors ${R.enabled?"":"opacity-50"}`,children:[t==="squad"?y.jsx("td",{className:"px-4 py-3",children:y.jsx(DB,{name:(($=i.find(z=>z.id===R.targetId))==null?void 0:$.name)??"Unknown",color:(W=i.find(z=>z.id===R.targetId))==null?void 0:W.color})}):null,y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:R.name}),y.jsx("td",{className:"px-4 py-3 text-zinc-600 text-[10px]",children:R.cron}),y.jsx("td",{className:"px-4 py-3 text-zinc-600",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(e1,{className:"w-3 h-3"}),R.enabled&&R.nextRun?Fs(R.nextRun,p):"—"]})}),y.jsx("td",{className:"px-4 py-3",children:y.jsx(Rt,{variant:R.enabled?"success":"muted",children:R.enabled?"active":"paused"})}),y.jsx("td",{className:"px-4 py-3",children:y.jsxs("div",{className:`flex items-center gap-1 ${S===R.id?"opacity-50 pointer-events-none":""}`,children:[y.jsxs(wi,{onClick:()=>T(R.id),children:[y.jsx(oB,{className:"w-3 h-3"}),"Run now"]}),y.jsx(LB,{onClick:()=>C(R.id,R.enabled),children:R.enabled?y.jsxs(y.Fragment,{children:[y.jsx(tB,{className:"w-3 h-3"}),"Pause"]}):y.jsxs(y.Fragment,{children:[y.jsx(Hf,{className:"w-3 h-3"}),"Resume"]})}),y.jsxs(wi,{onClick:()=>d(R),children:[y.jsx(nB,{className:"w-3 h-3"}),"Edit"]}),y.jsxs(Vf,{onClick:()=>O(R.id),children:[y.jsx(Da,{className:"w-3 h-3"}),"Delete"]})]})})]},R.id)})})]})})]})}const Uq=[{id:"general",label:"General"},{id:"telegram",label:"Telegram"},{id:"auth",label:"Auth"}],Bo="rounded-xl border border-white/[0.07] bg-white/[0.04] px-3 py-2 text-sm font-mono text-zinc-300 outline-none focus:border-[#E43A9C]/50",VE=`${Bo} w-[72px]`,qq=`${Bo} w-[100px]`,XE=`${Bo} w-[200px]`,YE=`${Bo} w-[320px]`,Fq=`${Bo} w-[140px] appearance-none bg-[url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2212%22%20height%3D%2212%22%20viewBox%3D%220%200%2012%2012%22%3E%3Cpath%20fill%3D%22%2371717a%22%20d%3D%22M3%204.5L6%208l3-3.5H3z%22%2F%3E%3C%2Fsvg%3E')] bg-[position:right_10px_center] bg-no-repeat pr-8`;function Hq(){const[t,e]=j.useState(null),[r,n]=j.useState("general");j.useEffect(()=>{Ge.get("/config").then(o=>e(o.config)).catch(()=>{})},[]);function i(o){t&&e({...t,...o})}async function a(){if(t)try{const{dataDir:o,...c}=t;await Ge.patch("/config",c),Qe.success("Settings saved")}catch{Qe.error("Failed to save settings")}}return t?y.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:y.jsxs("div",{className:"max-w-3xl",children:[y.jsx("h2",{className:"mb-6 text-2xl tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Settings"}),y.jsx("div",{className:"mb-6 flex gap-6 border-b border-white/[0.07]",children:Uq.map(o=>y.jsx("button",{type:"button",onClick:()=>n(o.id),className:`-mb-px border-b-2 px-1 pb-3 text-[11px] font-mono transition-colors ${r===o.id?"border-[#E43A9C] text-[#E43A9C]":"border-transparent text-zinc-500 hover:text-zinc-300"}`,children:o.label},o.id))}),y.jsxs("div",{className:"glass-card rounded-2xl border border-white/[0.07] p-5",children:[r==="general"&&y.jsxs(y.Fragment,{children:[y.jsx(Bn,{label:"Log Level",children:y.jsx("select",{value:t.logLevel,onChange:o=>i({logLevel:o.target.value}),className:Fq,children:["trace","debug","info","warn","error","fatal"].map(o=>y.jsx("option",{value:o,children:o},o))})}),y.jsx(Bn,{label:"Default Model",children:y.jsx("input",{type:"text",value:t.defaultModel,onChange:o=>i({defaultModel:o.target.value}),className:XE})}),y.jsx(Bn,{label:"Timezone",children:y.jsx("select",{value:t.timezone,onChange:o=>i({timezone:o.target.value}),className:`${Bo} w-[200px] appearance-none bg-[url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2212%22%20height%3D%2212%22%20viewBox%3D%220%200%2012%2012%22%3E%3Cpath%20fill%3D%22%2371717a%22%20d%3D%22M3%204.5L6%208l3-3.5H3z%22%2F%3E%3C%2Fsvg%3E')] bg-[position:right_10px_center] bg-no-repeat pr-8`,children:Q4.map(o=>y.jsx("option",{value:o.value,children:o.label},o.value))})}),y.jsx(Bn,{label:"Max Instances",children:y.jsx("input",{type:"number",value:t.maxInstancesPerSquad,onChange:o=>i({maxInstancesPerSquad:Number(o.target.value)}),className:VE,min:1,max:10})}),y.jsx(Bn,{label:"API Port",children:y.jsx("input",{type:"number",value:t.apiPort,onChange:o=>i({apiPort:Number(o.target.value)}),className:VE})}),y.jsx(Bn,{label:"Pricing Refresh (hrs)",children:y.jsx("input",{type:"number",value:t.pricing.refreshIntervalHours,onChange:o=>i({pricing:{refreshIntervalHours:Number(o.target.value)}}),className:qq,min:1})}),y.jsx(Bn,{label:"Data Dir",children:y.jsx("input",{type:"text",value:t.dataDir,readOnly:!0,className:`${YE} cursor-default text-zinc-500`})})]}),r==="telegram"&&y.jsxs(y.Fragment,{children:[y.jsx(Bn,{label:"Bot Token",children:y.jsx(JE,{value:t.telegram.botToken??"",onChange:o=>i({telegram:{...t.telegram,botToken:o||null}}),size:"lg"})}),y.jsx(Bn,{label:"Allowed Chat IDs",children:y.jsx("input",{type:"text",value:t.telegram.allowedChatIds.join(", "),onChange:o=>i({telegram:{...t.telegram,allowedChatIds:o.target.value.split(",").map(c=>Number(c.trim())).filter(c=>!Number.isNaN(c))}}),className:XE})})]}),r==="auth"&&y.jsxs(y.Fragment,{children:[y.jsx(Bn,{label:"Project URL",children:y.jsx("input",{type:"text",value:t.supabase.projectUrl??"",onChange:o=>i({supabase:{...t.supabase,projectUrl:o.target.value||null}}),className:YE})}),y.jsx(Bn,{label:"Anon Key",children:y.jsx(JE,{value:t.supabase.anonKey??"",onChange:o=>i({supabase:{...t.supabase,anonKey:o||null}}),size:"lg"})})]}),y.jsx("div",{className:"flex justify-end pt-6",children:y.jsx(Ba,{onClick:a,className:"px-4 py-2.5",children:"Save Settings"})})]})]})}):y.jsx("div",{className:"flex h-full items-center justify-center text-zinc-600",children:"Loading..."})}function Bn({label:t,children:e}){return y.jsxs("div",{className:"flex items-center justify-between gap-6 border-b border-white/[0.07] py-3",children:[y.jsx("span",{className:"text-[11px] font-mono text-zinc-400 shrink-0",children:t}),y.jsx("div",{className:"flex justify-end",children:e})]})}function JE({value:t,onChange:e,size:r="lg"}){const[n,i]=j.useState(!1),a=r==="lg"?"w-[320px]":"w-[200px]";return y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:n?"text":"password",value:t,onChange:o=>e(o.target.value),className:`${Bo} ${a} pr-9`}),y.jsx("button",{type:"button",onClick:()=>i(o=>!o),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-zinc-600 transition-colors hover:text-zinc-400","aria-label":n?"Hide value":"Show value",children:n?y.jsx(Iz,{size:14}):y.jsx(Qb,{size:14})})]})}function yf(t){return"url"in t&&t.url?t.url:t.name}const Wq=[{id:"installed",label:"Installed"},{id:"awesome-copilot",label:"Awesome Copilot"},{id:"skillssh",label:"skills.sh"}];function ZE(t){return t==="awesome-copilot"?"Awesome Copilot":"skills.sh"}function QE(t){return t?t>=1e6?`${(t/1e6).toFixed(1).replace(/\.0$/,"")}M installs`:t>=1e3?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K installs`:`${t} installs`:null}function Kq(t){return t.slice(1,-1).split(",").map(e=>e.trim().replace(/^["']|["']$/g,""))}function Gq(t){const e={};let r="",n=null;for(const i of t.split(`
449
- `)){const a=i.match(/^(\w[\w-]*)\s*:\s*(.*)$/);if(a){r&&n&&(e[r]=n,n=null),r=a[1]??"";const o=(a[2]??"").trim();o===""||o==="[]"?n=[]:o.startsWith("[")&&o.endsWith("]")?e[r]=Kq(o):e[r]=o.replace(/^["']|["']$/g,"")}else i.match(/^\s+-\s+(.+)/)&&r&&(n||(n=[]),n.push(i.replace(/^\s+-\s+/,"").trim()))}return r&&n&&(e[r]=n),e}function Mf(t){const e=t.match(/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/);return e?{frontMatter:Gq(e[1]??""),body:e[2]??""}:{frontMatter:{},body:t}}function Vq({content:t}){const{body:e}=Mf(t);return e.trim()?y.jsx(Mu,{content:e}):y.jsx("p",{className:"font-mono text-[11px] text-zinc-500",children:"No content body in this skill."})}function Xq(){const[t,e]=j.useState("installed"),[r,n]=j.useState([]),[i,a]=j.useState([]),[o,c]=j.useState(null),[u,d]=j.useState(null),[p,f]=j.useState(""),[m,v]=j.useState(!1),[b,w]=j.useState(!1),[x,k]=j.useState(!1),[S,A]=j.useState(""),[C,T]=j.useState(null),[O,N]=j.useState(null),R=j.useCallback(async()=>{try{const I=await Ge.get("/skills"),q=new Set(I.skills.map(Q=>(Q.name||"").toLowerCase()));n(I.skills),a(Q=>Q.map(le=>({...le,installed:q.has((le.name||"").toLowerCase())})))}catch(I){Qe.error(I instanceof Error?I.message:"Failed to load skills")}},[]),$=j.useCallback(async I=>{w(!0);try{const q=await Ge.get(`/skills/${encodeURIComponent(I)}`);d(q);const{body:Q}=Mf(q.content);A(Q)}catch(q){Qe.error(q instanceof Error?q.message:"Failed to load skill"),d(null)}finally{w(!1)}},[]);j.useEffect(()=>{R()},[R]),j.useEffect(()=>{if(t==="installed"){N(null);return}const I=p.trim();if(t==="skillssh"&&!I){a([]),N(null),v(!1);return}let q=!1;v(!0);const Q=window.setTimeout(async()=>{try{const le=await Ge.get(`/skills/discover?source=${t}&q=${encodeURIComponent(I)}`);if(q)return;a(le.skills),N(null)}catch(le){if(q)return;a([]),N(le instanceof Error?le.message:"Discovery failed")}finally{q||v(!1)}},250);return()=>{q=!0,window.clearTimeout(Q)}},[p,t]);const W=j.useMemo(()=>{const I=p.trim().toLowerCase();return I?r.filter(q=>[q.name,q.description,q.preview].some(Q=>Q==null?void 0:Q.toLowerCase().includes(I))):r},[r,p]),z=t==="installed"?W:i,U=W.find(I=>I.name===o)??null,F=i.find(I=>yf(I)===o)??null,X=(U==null?void 0:U.name)??(F==null?void 0:F.name)??null;j.useEffect(()=>{if(k(!1),!z.length){c(null),t!=="installed"&&d(null);return}if(!o||!z.some(I=>yf(I)===o)){const I=z[0];I&&c(yf(I))}},[o,t,z]),j.useEffect(()=>{if(t!=="installed"||!X){d(null);return}$(X)},[$,X,t]);async function Y(I){if(!I.url&&!I.registrySource){Qe.error("Install source is not available for this skill yet");return}T(I.name);try{await Ge.post("/skills/install",{name:I.name,source:I.source,url:I.url,registrySource:I.registrySource,skillId:I.skillId}),Qe.success(`Installed ${I.title||I.name}`),await R(),a(q=>q.map(Q=>Q.name===I.name?{...Q,installed:!0}:Q))}catch(q){Qe.error(q instanceof Error?q.message:"Install failed")}finally{T(null)}}async function G(I){T(I);try{await Ge.delete(`/skills/${encodeURIComponent(I)}`),Qe.success(`Removed ${I}`),await R(),a(q=>q.map(Q=>Q.name===I?{...Q,installed:!1}:Q))}catch(q){Qe.error(q instanceof Error?q.message:"Failed to remove skill")}finally{T(null)}}async function Z(){if(u){T(u.name);try{const I=u.content.match(/^(---\s*\n[\s\S]*?\n---\s*\n)/),q=I?`${I[1]}${S}`:S;await Ge.put(`/skills/${encodeURIComponent(u.name)}`,{content:q}),Qe.success(`Updated ${u.name}`),k(!1),await Promise.all([R(),$(u.name)])}catch(I){Qe.error(I instanceof Error?I.message:"Failed to save skill")}finally{T(null)}}}const K=!!(U!=null&&U.activatedForOrchestrator),ee=C===(u==null?void 0:u.name),L=C===(F==null?void 0:F.name);return y.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[y.jsxs("div",{className:"w-64 flex-shrink-0 border-r border-white/[0.06] flex flex-col overflow-hidden",children:[y.jsxs("div",{className:"px-2.5 pt-2.5 pb-2 flex-shrink-0 border-b border-white/[0.06] space-y-2",children:[y.jsxs("div",{className:"relative",children:[y.jsx(zP,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-zinc-700"}),y.jsx("input",{type:"text",value:p,onChange:I=>f(I.target.value),placeholder:"Search skills…",className:"w-full bg-[#181818] border border-white/[0.06] rounded-xl pl-7 pr-2 py-1.5 text-[11px] text-zinc-300 font-mono placeholder:text-zinc-700 focus:outline-none focus:border-[#E43A9C]/30 transition-colors"})]}),y.jsx("div",{className:"flex flex-col gap-0.5",children:Wq.map(I=>y.jsxs("button",{type:"button",onClick:()=>e(I.id),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] font-mono transition-colors flex items-center justify-between cursor-pointer ${t===I.id?"text-[#E43A9C]":"text-zinc-500 hover:text-zinc-300 hover:bg-white/[0.04]"}`,style:t===I.id?{background:"rgba(228,58,156,0.10)"}:void 0,children:[y.jsx("span",{children:I.label}),I.id==="installed"&&y.jsx("span",{className:"text-[10px] text-zinc-600",children:r.length})]},I.id))})]}),y.jsxs("div",{className:"flex-1 overflow-y-auto py-1.5",children:[m&&t!=="installed"?y.jsxs("div",{className:"flex items-center gap-2 rounded-2xl border border-white/[0.08] bg-white/[0.03] px-3 py-3 font-mono text-[11px] text-zinc-500",children:[y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"})," Searching registry..."]}):null,z.map(I=>{const q=yf(I),Q=o===q,le=I.description||("preview"in I?I.preview:"No description available.");return y.jsxs("button",{type:"button",onClick:()=>{k(!1),c(q)},className:`w-full text-left px-3 py-2.5 border-b border-white/[0.03] transition-colors cursor-pointer ${Q?"border-l-2 border-l-[#E43A9C] bg-[#E43A9C]/5":"hover:bg-white/[0.03]"}`,children:[y.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[y.jsx("span",{className:"truncate font-mono text-[11px] text-zinc-200",children:I.name}),"installed"in I&&I.installed?y.jsx(Rt,{variant:"success",children:"installed"}):null]}),y.jsx("p",{className:"line-clamp-2 font-mono text-[10px] leading-relaxed text-zinc-600",children:le})]},`${t}:${q}`)}),!m&&z.length===0?y.jsx("div",{className:"px-4 py-8",children:y.jsx("p",{className:"font-mono text-[11px] leading-relaxed text-zinc-500",children:O||(t==="skillssh"&&!p.trim()?"Start typing to search the skills.sh registry.":p.trim()?"No skills match your search.":"No skills available in this source.")})}):null]})]}),y.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto p-5",children:t==="installed"&&U?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mb-5 flex items-start justify-between gap-4 border-b border-white/[0.06] pb-5",children:[y.jsxs("div",{className:"flex min-w-0 gap-4",children:[y.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-[#E43A9C]/12 text-[#E43A9C]",children:y.jsx(tx,{className:"h-6 w-6"})}),y.jsxs("div",{className:"min-w-0",children:[y.jsx("h3",{className:"truncate text-[34px] uppercase tracking-[0.08em] text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:U.name}),y.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[y.jsx(Rt,{variant:"success",children:"installed"}),K?y.jsx(Rt,{variant:"warning",children:"active"}):y.jsx(Rt,{variant:"muted",children:"inactive"}),y.jsx(Rt,{variant:"muted",children:"local skill"})]}),y.jsxs("div",{className:"mt-3 space-y-1 font-mono text-[11px] text-zinc-500",children:[y.jsxs("p",{children:["path: ",U.filePath]}),y.jsxs("p",{children:["orchestrator: ",K?"enabled":"disabled"]})]})]})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[x?y.jsxs(Ba,{onClick:Z,disabled:ee||S===Mf((u==null?void 0:u.content)??"").body,className:"px-3 py-2",children:[ee?y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"}):y.jsx(Wf,{className:"h-3.5 w-3.5"}),"Save"]}):y.jsxs(wi,{onClick:()=>k(!0),className:"px-3 py-2",children:[y.jsx(Wf,{className:"h-3.5 w-3.5"})," Edit"]}),y.jsxs(Vf,{onClick:()=>G(U.name),className:"px-3 py-2",children:[ee?y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"}):y.jsx(Da,{className:"h-3.5 w-3.5"}),"Remove"]})]})]}),y.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:b&&!u?y.jsxs("div",{className:"flex items-center gap-2 font-mono text-[11px] text-zinc-500",children:[y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"})," Loading skill..."]}):x?y.jsxs("div",{className:"space-y-3",children:[y.jsx("textarea",{value:S,onChange:I=>A(I.target.value),className:"min-h-[440px] w-full rounded-2xl border border-white/[0.08] bg-black/30 p-4 font-mono text-[12px] leading-6 text-zinc-200 outline-none transition-colors focus:border-[#E43A9C]/50"}),y.jsxs("div",{className:"flex items-center justify-between font-mono text-[11px] text-zinc-500",children:[y.jsx("span",{children:"Editing skill markdown"}),y.jsx(wi,{onClick:()=>{k(!1);const{body:I}=Mf((u==null?void 0:u.content)??"");A(I)},className:"px-3 py-2",children:"Cancel"})]})]}):u?y.jsx(Vq,{content:u.content}):y.jsx("p",{className:"font-mono text-[11px] text-zinc-500",children:"Select an installed skill to inspect it."})})]}):t!=="installed"&&F?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mb-5 flex items-start justify-between gap-4 border-b border-white/[0.06] pb-5",children:[y.jsxs("div",{className:"flex min-w-0 gap-4",children:[y.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-[#E43A9C]/12 text-[#E43A9C]",children:y.jsx(gB,{className:"h-6 w-6"})}),y.jsxs("div",{className:"min-w-0",children:[y.jsx("h3",{className:"truncate text-[34px] uppercase tracking-[0.08em] text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:F.title||F.name}),y.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[y.jsx(Rt,{variant:F.installed?"success":"default",children:F.installed?"installed":"available"}),y.jsx(Rt,{variant:"muted",children:ZE(F.source)}),QE(F.installs)?y.jsx(Rt,{variant:"info",children:QE(F.installs)}):null]}),y.jsxs("div",{className:"mt-3 space-y-1 font-mono text-[11px] text-zinc-500",children:[y.jsxs("p",{children:["registry: ",ZE(F.source)]}),F.registrySource?y.jsxs("p",{children:["source: ",F.registrySource]}):null,F.url?y.jsxs("p",{children:["url: ",F.url]}):null]})]})]}),y.jsx("div",{className:"flex items-center gap-2",children:F.installed?y.jsx(wi,{onClick:()=>{e("installed"),c(F.name)},className:"px-3 py-2",children:"Open installed"}):y.jsxs(Ba,{onClick:()=>Y(F),disabled:L||!F.url&&!F.registrySource,className:"px-3 py-2",children:[L?y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"}):y.jsx(Nz,{className:"h-3.5 w-3.5"}),"Install"]})})]}),y.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:[y.jsx("div",{className:"rounded-2xl border border-white/[0.06] bg-white/[0.02] p-5",children:y.jsx("p",{className:"font-mono text-[12px] leading-7 text-zinc-300",children:F.description||"No registry description is available for this skill yet."})}),y.jsx("div",{className:"mt-4 rounded-2xl border border-dashed border-white/[0.08] bg-black/20 p-4 font-mono text-[11px] leading-6 text-zinc-500",children:"Install will fetch the skill definition from the selected registry source and add it to your local skills library."})]})]}):y.jsx("div",{className:"flex h-full items-center justify-center rounded-2xl border border-dashed border-white/[0.08] bg-white/[0.02] p-8 text-center",children:y.jsxs("div",{children:[y.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-[#E43A9C]/12 text-[#E43A9C]",children:y.jsx(tx,{className:"h-6 w-6"})}),y.jsx("h3",{className:"text-[28px] uppercase tracking-[0.08em] text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Select a Skill"}),y.jsx("p",{className:"mt-2 font-mono text-[11px] leading-relaxed text-zinc-500",children:"Choose a skill from the left panel to inspect details, install registry entries, or edit local definitions."})]})})})]})}function Df(t){let e=0;for(let n=0;n<t.length;n++)e=t.charCodeAt(n)+((e<<5)-e);return`hsl(${(e%360+360)%360}, 70%, 65%)`}function vf(){const{name:t,instanceId:e,role:r}=hL();return t&&r?y.jsx(n9,{squadName:t,role:r}):t&&e?y.jsx(r9,{squadName:t,instanceId:e}):t?y.jsx(Zq,{name:t}):y.jsx(Yq,{})}function Yq(){const[t,e]=j.useState([]),[r,n]=j.useState(null),i=gl();return j.useEffect(()=>{Promise.all([Ge.get("/squads"),Ge.get("/config")]).then(([a,o])=>{e(a.squads),n(o.config.maxInstancesPerSquad)}).catch(()=>{})},[]),y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[y.jsx("div",{className:"mb-6",children:y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Squads"}),y.jsxs("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:[t.length," squads · ",t.reduce((a,o)=>a+(o.activeInstances||0),0)," ","active instances"]})]})}),y.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3",children:[t.map(a=>{var c;const o=a.color||"#38bdf8";return y.jsxs("button",{type:"button",onClick:()=>i(`/squads/${a.name}`),className:"text-left rounded-2xl p-5 transition-all group cursor-pointer",style:{border:`1px solid ${o}30`,background:`${o}08`,backdropFilter:"blur(20px)"},onMouseEnter:u=>{u.currentTarget.style.borderColor=`${o}70`,u.currentTarget.style.background=`${o}12`},onMouseLeave:u=>{u.currentTarget.style.borderColor=`${o}30`,u.currentTarget.style.background=`${o}08`},children:[y.jsxs("div",{className:"flex items-start justify-between mb-1",children:[y.jsx("h3",{className:"text-sm font-mono transition-colors",style:{color:o},children:a.name}),y.jsx(Rt,{variant:Ms(a.status),children:a.status})]}),y.jsxs("div",{className:"flex items-center justify-between mb-3",children:[y.jsx("p",{className:"text-[11px] text-zinc-600 font-mono",children:((c=a.config)==null?void 0:c.prMode)??"draft-pr"}),y.jsxs("span",{className:"text-[11px] text-zinc-600 font-mono flex items-center gap-1",children:[y.jsx(Tz,{className:"w-3 h-3"}),a.activeInstances,"/",r??(a.totalInstances||a.memberCount)]})]}),a.repoUrl&&y.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-zinc-700 font-mono mb-4",children:[y.jsx(r1,{className:"w-3 h-3 flex-shrink-0"}),y.jsx("span",{className:"truncate",children:a.repoUrl.replace("https://github.com/","")})]}),a.recentActivity&&a.recentActivity.length>0&&y.jsxs("div",{className:"border-t pt-3",style:{borderColor:`${o}15`},children:[y.jsx("p",{className:"text-[10px] font-mono uppercase tracking-wider mb-2",style:{color:`${o}80`},children:"Recent Work"}),y.jsx("ul",{className:"space-y-1.5",children:a.recentActivity.map(u=>{const d={className:"w-3.5 h-3.5 flex-shrink-0 mt-px"},p=Jq(u.status,d),f=u.objective?u.objective.length>60?`${u.objective.slice(0,60)}…`:u.objective:u.issueRef||"Instance";return y.jsxs("li",{className:"flex items-start gap-1.5 text-[11px] font-mono text-zinc-600",children:[p,y.jsx("span",{className:"truncate",children:f})]},u.id)})})]})]},a.id)}),t.length===0&&y.jsxs("div",{className:"col-span-full text-center py-12 text-zinc-600",children:[y.jsx(a1,{size:48,className:"mx-auto mb-3 opacity-30"}),y.jsx("p",{className:"text-[11px] font-mono",children:"No squads hired yet. Ask IO to hire a squad for a project."})]})]})]})}function Jq(t,e){const r=t.toLowerCase();return r.includes("complete")||r.includes("success")||r.includes("done")?y.jsx(IP,{...e,style:{color:"#34d399"}}):r.includes("warning")||r.includes("review")?y.jsx(wB,{...e,style:{color:"#fbbf24"}}):r.includes("error")||r.includes("fail")?y.jsx($P,{...e,style:{color:"#f87171"}}):r.includes("working")||r.includes("progress")||r.includes("running")?y.jsx(DP,{...e,style:{color:"#E43A9C"}}):y.jsx(Wz,{...e,style:{color:"#60a5fa"}})}function Hs(t,e){const r="w-4 h-4",n={color:e},i=t.toLowerCase();return i.includes("lead")||i.includes("pm")||i.includes("technical")?y.jsx(t1,{className:r,style:n}):i.includes("qa")||i.includes("test")?y.jsx(mz,{className:r,style:n}):i.includes("scribe")?y.jsx(uB,{className:r,style:n}):y.jsx(qc,{className:r,style:n})}function Zq({name:t}){var k;const[e,r]=j.useState(null),[n,i]=j.useState("agents"),[a,o]=j.useState([]),[c,u]=j.useState(0),[d,p]=j.useState(null),[f,m]=j.useState([]),v=gl(),b=Fa();j.useEffect(()=>{Ge.get(`/squads/${t}`).then(r).catch(()=>{})},[t]),j.useEffect(()=>{n==="history"&&Ge.get(`/squads/${t}/history`).then(S=>{o(S.items),u(S.total)}).catch(()=>{}),n==="schedules"&&e&&Ge.get(`/schedules?targetId=${e.squad.id}`).then(S=>m(S.schedules)).catch(()=>{})},[n,t,e]);const w=S=>{Ge.get(`/squads/${t}/history/${S.id}`).then(p).catch(()=>Qe.error("Failed to load activity detail"))};if(!e)return y.jsx("div",{className:"h-full flex items-center justify-center text-zinc-600",children:"Loading..."});const x=e.squad.color||"#38bdf8";return d?y.jsx(Qq,{activity:d,squadColor:x,squadName:e.squad.name,onBack:()=>p(null)}):y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",style:{background:`${x}06`},children:[y.jsxs("button",{type:"button",onClick:()=>v("/squads"),className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," All Squads"]}),y.jsxs("div",{className:"flex items-start justify-between mb-5",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-3xl tracking-wide",style:{fontFamily:"'Bebas Neue', sans-serif",color:x},children:e.squad.name}),y.jsxs("p",{className:"text-[11px] text-zinc-600 font-mono",children:[((k=e.squad.config)==null?void 0:k.prMode)??"draft-pr"," · ",e.squad.autonomyTier||"standard"," ","autonomy"]}),e.squad.repoUrl&&y.jsxs("a",{href:e.squad.repoUrl,target:"_blank",rel:"noreferrer",className:"text-[11px] font-mono text-[#E43A9C] hover:text-[#F041FF] flex items-center gap-1 mt-1 transition-colors",children:[y.jsx(r1,{className:"w-3 h-3"}),e.squad.repoUrl.replace("https://github.com/","")]})]}),y.jsx(Rt,{variant:Ms(e.squad.status),children:e.squad.status})]}),y.jsx("div",{className:"flex gap-0 mb-5 border-b border-white/[0.06]",children:["agents","instances","schedules","history"].map(S=>y.jsx("button",{type:"button",onClick:()=>i(S),className:`px-4 py-2 text-[11px] font-mono capitalize transition-colors border-b-2 -mb-px ${n===S?"text-[#E43A9C] border-[#E43A9C]":"text-zinc-600 hover:text-zinc-300 border-transparent"}`,children:S},S))}),n==="agents"&&y.jsx("div",{className:"space-y-2",children:e.members.map(S=>y.jsxs("button",{type:"button",onClick:()=>v(`/squads/${t}/agents/${S.roleName||S.role}`),className:"w-full glass-card border border-white/[0.07] rounded-2xl p-4 flex items-center gap-3 hover:bg-white/[0.03] transition-colors cursor-pointer text-left",children:[y.jsx("div",{className:"w-8 h-8 rounded-xl flex items-center justify-center flex-shrink-0",style:{border:`1px solid ${x}30`,background:`${x}12`},children:Hs(S.roleName||S.role,x)}),y.jsxs("div",{className:"flex-1 min-w-0",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-sm font-mono text-zinc-200",children:S.displayName}),y.jsx(Rt,{variant:Ms(S.status),children:S.status})]}),y.jsx("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:S.role}),S.currentTask&&y.jsx("p",{className:"text-xs text-zinc-500 mt-1 truncate",children:S.currentTask})]})]},S.id))}),n==="instances"&&y.jsx("div",{className:"space-y-2",children:e.instances.length===0?y.jsx("div",{className:"text-center py-16 text-zinc-700 font-mono text-sm",children:"No active instances"}):e.instances.map(S=>y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-4 flex items-center gap-4",children:[y.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2 text-[11px] font-mono",children:[y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"ID"}),y.jsx("p",{className:"text-zinc-300 mt-0.5 truncate",children:S.id.slice(0,8)})]}),y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"Branch"}),y.jsx("p",{className:"text-zinc-300 mt-0.5 truncate",children:S.branch||"—"})]}),y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"Status"}),y.jsx("p",{className:"text-zinc-300 mt-0.5",children:y.jsx(Rt,{variant:Ms(S.status),children:S.status})})]}),y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"Tasks"}),y.jsxs("p",{className:"text-zinc-300 mt-0.5",children:[S.tasksComplete,"/",S.taskCount]})]})]}),y.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[y.jsx("button",{type:"button",onClick:()=>v(`/squads/${t}/instances/${S.id}`),title:"View instance agents",className:"p-2 rounded-xl hover:bg-white/[0.06] transition-colors cursor-pointer",style:{color:x},children:y.jsx(Hf,{className:"w-4 h-4"})}),y.jsx("button",{type:"button",onClick:async()=>{try{await Ge.post(`/squads/${t}/instances/${S.id}/cancel`),Qe.success("Instance cancelled")}catch{Qe.error("Failed to cancel instance")}},title:"Stop instance",className:"p-2 rounded-xl hover:bg-red-500/10 text-zinc-600 hover:text-red-400 transition-colors cursor-pointer",children:y.jsx(dp,{className:"w-4 h-4"})})]})]},S.id))}),n==="schedules"&&y.jsx("div",{className:"overflow-auto rounded-2xl border border-white/[0.07] glass-card",children:f.length===0?y.jsx("div",{className:"text-center py-16 text-zinc-700 font-mono text-sm",children:"No schedules for this squad"}):y.jsxs("table",{className:"w-full text-[11px] font-mono",children:[y.jsx("thead",{children:y.jsx("tr",{className:"border-b border-white/[0.06]",style:{background:"rgba(20,20,20,0.6)"},children:["Schedule","Next Run","Status"].map(S=>y.jsx("th",{className:"text-left px-4 py-2.5 text-zinc-600 font-medium",children:S},S))})}),y.jsx("tbody",{children:f.map(S=>y.jsxs("tr",{className:`border-b border-white/[0.04] hover:bg-white/[0.015] transition-colors ${S.enabled?"":"opacity-50"}`,children:[y.jsxs("td",{className:"px-4 py-3",children:[y.jsx("div",{className:"text-zinc-300",children:S.name||S.prompt}),y.jsx("div",{className:"text-zinc-700 text-[10px] mt-0.5",children:S.cron})]}),y.jsx("td",{className:"px-4 py-3 text-zinc-600",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(e1,{className:"w-3 h-3"}),S.enabled&&S.nextRun?Fs(S.nextRun,b):"—"]})}),y.jsx("td",{className:"px-4 py-3",children:y.jsx(Rt,{variant:S.enabled?"success":"muted",children:S.enabled?"active":"paused"})})]},S.id))})]})}),n==="history"&&y.jsxs("div",{className:"space-y-2",children:[a.length===0?y.jsx("div",{className:"text-center py-16 text-zinc-700 font-mono text-sm",children:"No history yet"}):a.map(S=>y.jsxs("button",{type:"button",onClick:()=>w(S),className:"w-full glass-card border border-white/[0.07] rounded-2xl px-4 py-3.5 flex items-center gap-3 hover:bg-white/[0.03] transition-colors cursor-pointer text-left",children:[y.jsx("div",{className:"flex-shrink-0",children:S.status==="completed"?y.jsx(IP,{className:"w-4 h-4",style:{color:"#34d399"}}):y.jsx($P,{className:"w-4 h-4",style:{color:"#f87171"}})}),y.jsxs("div",{className:"flex-1 min-w-0",children:[y.jsx("p",{className:"text-[12px] text-zinc-300 font-mono truncate",children:S.title}),y.jsxs("div",{className:"flex items-center gap-3 mt-0.5",children:[y.jsx("span",{className:"text-[10px] text-zinc-700 font-mono",children:Fs(S.completedAt||S.createdAt,b)}),y.jsxs("span",{className:"text-[10px] text-zinc-700 font-mono flex items-center gap-1",children:[y.jsx(Hf,{className:"w-2.5 h-2.5"}),S.duration||"—"]}),y.jsxs("span",{className:"text-[10px] text-zinc-700 font-mono flex items-center gap-1",children:[y.jsx(qc,{className:"w-2.5 h-2.5"}),S.agentCount," agent",S.agentCount!==1?"s":""]})]})]}),y.jsx(Rt,{variant:S.status==="completed"?"success":"error",children:S.status})]},S.id)),a.length<c&&y.jsx("button",{type:"button",onClick:()=>{Ge.get(`/squads/${t}/history?offset=${a.length}`).then(S=>{o(A=>[...A,...S.items])}).catch(()=>{})},className:"w-full text-center py-3 text-[11px] font-mono text-zinc-600 hover:text-zinc-300 transition-colors cursor-pointer",children:"Load more"})]})]})}function Qq({activity:t,squadColor:e,squadName:r,onBack:n}){const i=Fa(),[a,o]=j.useState(new Set),c=j.useMemo(()=>{const v={};for(const b of t.agentEntries)v[b.agentId]=Df(b.agentName);return v},[t]),u={thought:{label:"Thinking",icon:n1},tool_call:{label:"Tool Call",icon:UP},tool_result:{label:"Tool Result",icon:MP},message:{label:"Message",icon:qc},decision:{label:"Decision",icon:t1}},d={label:"Message",icon:qc},p=v=>u[v]??d,f=v=>{o(b=>{const w=new Set(b);return w.has(v)?w.delete(v):w.add(v),w})},m=j.useMemo(()=>{const v=t.agentEntries.flatMap(b=>b.events.map(w=>({ev:w,entry:b})));return v.sort((b,w)=>b.ev.timestamp.localeCompare(w.ev.timestamp)),a.size>0?v.filter(({entry:b})=>a.has(b.agentId)):v},[t,a]);return y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",style:{background:`${e}06`},children:[y.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors cursor-pointer",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," Back to ",r]}),y.jsxs("div",{className:"flex items-start justify-between mb-5",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide",style:{fontFamily:"'Bebas Neue', sans-serif",color:e},children:t.title}),y.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[y.jsx("span",{className:"text-[11px] text-zinc-600 font-mono",children:Fs(t.completedAt||t.createdAt,i)}),y.jsxs("span",{className:"text-[11px] text-zinc-700 font-mono flex items-center gap-1",children:[y.jsx(e1,{className:"w-3 h-3"}),t.duration||"—"]})]})]}),y.jsx(Rt,{variant:t.status==="completed"?"success":"error",children:t.status})]}),y.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[t.agentEntries.map(v=>{const b=c[v.agentId],w=a.has(v.agentId),k=!(a.size>0)||w;return y.jsxs("button",{type:"button",onClick:()=>f(v.agentId),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-xl border transition-all cursor-pointer",style:{borderColor:k?`${b}30`:"rgba(255,255,255,0.05)",background:k?`${b}10`:"transparent",opacity:k?1:.4},children:[Hs(v.roleType||v.role,b),y.jsx("span",{className:"text-[11px] font-mono",style:{color:k?b:"#71717a"},children:v.agentName}),y.jsxs("span",{className:"text-[10px] font-mono text-zinc-500",children:["— ",v.role]})]},v.agentId)}),a.size>0&&y.jsx("button",{type:"button",onClick:()=>o(new Set),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-xl border border-white/[0.1] text-[11px] font-mono text-zinc-400 hover:text-zinc-200 transition-colors cursor-pointer",children:"Show all"})]}),y.jsxs("div",{className:"relative pl-10",children:[y.jsx("div",{className:"absolute left-[15px] top-0 bottom-0 w-px bg-white/[0.06]"}),y.jsx("div",{className:"space-y-3",children:m.map(({ev:v,entry:b})=>{const w=c[b.agentId],{label:x,icon:k}=p(v.kind),S=v.kind==="tool_call"||v.kind==="tool_result";return y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:"absolute -left-10 top-3 w-[30px] h-[30px] rounded-full flex items-center justify-center",style:{background:`${w}15`,border:`1px solid ${w}35`},children:y.jsx(k,{className:"w-3.5 h-3.5",style:{color:w}})}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[y.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[y.jsxs("div",{className:"flex items-center gap-1",children:[Hs(b.roleType||b.role,w),y.jsx("span",{className:"text-[10px] font-mono",style:{color:w},children:b.agentName})]}),y.jsx("span",{className:"text-zinc-700 text-[10px]",children:"·"}),y.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wider text-zinc-500",children:x}),v.label&&y.jsx("span",{className:"text-[10px] font-mono text-zinc-600 border border-white/[0.08] rounded px-1.5 py-px bg-white/[0.03]",children:v.label}),v.status==="error"&&y.jsx(Rt,{variant:"error",children:"failed"}),v.status==="ok"&&v.kind==="tool_result"&&y.jsx(Rt,{variant:"success",children:"ok"})]}),y.jsx("span",{className:"text-[10px] font-mono text-zinc-700 flex-shrink-0 ml-2",children:cp(v.timestamp,i)})]}),S?y.jsx("pre",{className:"text-[11px] font-mono text-zinc-400 whitespace-pre-wrap leading-relaxed overflow-x-auto rounded-lg p-2 mt-1 bg-black/20",children:v.content}):y.jsx(Mu,{content:v.content,className:"text-[12px] [&_pre]:text-[10px]"})]})]},v.id)})})]})]})}const e9={thought:{label:"Thinking",icon:n1,color:"#a78bfa",bg:"rgba(167,139,250,0.1)"},tool_call:{label:"Tool Call",icon:UP,color:"#38bdf8",bg:"rgba(56,189,248,0.1)"},tool_result:{label:"Tool Result",icon:MP,color:"#34d399",bg:"rgba(52,211,153,0.1)"},message:{label:"Message",icon:qc,color:"#E43A9C",bg:"rgba(228,58,156,0.15)"},decision:{label:"Decision",icon:t1,color:"#fbbf24",bg:"rgba(251,191,36,0.1)"},meeting:{label:"Meeting",icon:a1,color:"#818cf8",bg:"rgba(129,140,248,0.1)"}};function t9(t){const e=t.toLowerCase();return e.includes("meeting")?"meeting":e.includes("tool_call")||e.includes("tool-call")?"tool_call":e.includes("tool_result")||e.includes("tool-result")?"tool_result":e.includes("thought")||e.includes("thinking")||e.includes("reason")?"thought":e.includes("decision")?"decision":"message"}function r9({squadName:t,instanceId:e}){const[r,n]=j.useState(null),[i,a]=j.useState([]),[o,c]=j.useState(null),[u,d]=j.useState("running"),[p,f]=j.useState(0),m=gl(),v=Fa(),b=j.useRef(null),w=j.useRef(null),x=j.useRef(!0),k=j.useCallback(()=>{const $=b.current;if(!$)return;const W=100;x.current=$.scrollHeight-$.scrollTop-$.clientHeight<W,x.current&&f(0)},[]);if(j.useEffect(()=>{Ge.get(`/squads/${t}/instances/${e}`).then($=>{n($),d($.instance.status)}).catch(()=>{Qe.error("Failed to load instance")})},[t,e]),o1({onEvent:$=>{if(!$.event)return;const W=$.event;if((W.type==="instance:completed"||W.type==="instance:failed"||W.type==="instance.completed"||W.type==="instance.failed")&&W.instanceId===e){d(W.type==="instance:completed"||W.type==="instance.completed"?"completed":"failed");return}if((W.type.startsWith("agent:")||W.type.startsWith("agent."))&&W.instanceId===e){const z=W.data,U=(z==null?void 0:z.tool)||null,F=typeof(z==null?void 0:z.success)=="boolean"?z.success:null;let X="";if(U&&(z!=null&&z.arguments)){const G=z.arguments;if(typeof G=="string")X=G;else if(typeof G=="object"&&G!==null){const Z=G;Z.command?X=String(Z.command):X=JSON.stringify(G,null,2)}}else z!=null&&z.result?X=String(z.result):z!=null&&z.error?X=String(z.error):X=(z==null?void 0:z.content)||"";try{const G=JSON.parse(X);typeof G=="object"&&G!==null&&(X=G.message??G.content??G.response??G.decision??JSON.stringify(G,null,2))}catch{}const Y={id:W.id,agent:W.agentRole||(z==null?void 0:z.agentRole)||"unknown",type:W.type.replace(/^agent[:.]/,""),content:X,toolName:U,success:F,model:W.model||(z==null?void 0:z.model)||null,tokensUsed:null,timestamp:W.timestamp};a(G=>[...G,Y]),x.current?setTimeout(()=>{var G;return(G=w.current)==null?void 0:G.scrollIntoView({behavior:"smooth"})},50):f(G=>G+1)}}}),!r)return y.jsx("div",{className:"h-full flex items-center justify-center text-zinc-600",children:"Loading..."});const S=r.squadColor||"#38bdf8",A=[...r.activity,...i],C=Array.from(new Map(A.map($=>[$.id,$])).values());C.sort(($,W)=>$.timestamp.localeCompare(W.timestamp));const T=o?C.filter($=>$.agent===o):C,O=[...new Set(C.map($=>$.agent))],N={};for(const $ of O)N[$]=Df($);const R=u==="running"||u==="working"||u==="meeting"||u==="planning";return y.jsxs("div",{ref:b,onScroll:k,className:"flex-1 overflow-y-auto p-6",style:{background:`${S}06`},children:[y.jsxs("button",{type:"button",onClick:()=>m(`/squads/${t}`),className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," Back to ",t]}),y.jsxs("div",{className:"flex items-start justify-between mb-5",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide",style:{fontFamily:"'Bebas Neue', sans-serif",color:S},children:"Instance"}),y.jsx("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:r.instance.id.slice(0,8)}),r.instance.branch&&y.jsx("p",{className:"text-[11px] text-zinc-700 font-mono mt-0.5",children:r.instance.branch})]}),y.jsx(Rt,{variant:Ms(u),children:u})]}),y.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[r.members.map($=>{const W=$.roleName||$.role,z=N[W]||Df(W),U=o===W;return y.jsxs("button",{type:"button",onClick:()=>c(U?null:W),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-xl border transition-all cursor-pointer",style:{borderColor:U?z:`${z}30`,background:U?`${z}25`:`${z}10`,opacity:o&&!U?.5:1},children:[Hs(W,z),y.jsx("span",{className:"text-[11px] font-mono",style:{color:z},children:$.displayName}),y.jsx(Rt,{variant:Ms($.status),children:$.status}),$.status==="working"&&y.jsx("button",{type:"button",onClick:async F=>{F.stopPropagation();try{await Ge.post(`/squads/${t}/instances/${e}/cancel`),Qe.success("Instance cancelled")}catch{Qe.error("Failed to cancel instance")}},title:"Cancel instance",className:"ml-1 p-1 rounded-lg hover:bg-red-500/10 text-zinc-600 hover:text-red-400 transition-colors cursor-pointer",children:y.jsx(dp,{className:"w-3 h-3"})})]},$.id)}),o&&y.jsx("button",{type:"button",onClick:()=>c(null),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-xl border border-white/[0.1] text-[11px] font-mono text-zinc-400 hover:text-zinc-200 transition-colors cursor-pointer",children:"Show all"})]}),y.jsxs("div",{className:"relative pl-10",children:[y.jsx("div",{className:"absolute left-[15px] top-0 bottom-0 w-px bg-white/[0.06]"}),y.jsxs("div",{className:"space-y-3",children:[T.length===0&&y.jsx("div",{className:"text-center py-12 text-zinc-700 font-mono text-sm",children:"No activity recorded yet"}),T.map($=>{const W=t9($.type),z=e9[W],U=z.icon,F=N[$.agent]||Df($.agent),X=W==="tool_call"||W==="tool_result",Y=$.type.toLowerCase().includes("error")||$.type.toLowerCase().includes("fail");return y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:"absolute -left-10 top-3 w-[30px] h-[30px] rounded-full flex items-center justify-center",style:{background:`${F}15`,border:`1px solid ${F}35`},children:y.jsx(U,{className:"w-3.5 h-3.5",style:{color:F}})}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[y.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[y.jsxs("div",{className:"flex items-center gap-1",children:[Hs($.agent,F),y.jsx("span",{className:"text-[10px] font-mono",style:{color:F},children:$.agent})]}),y.jsx("span",{className:"text-zinc-700 text-[10px]",children:"·"}),y.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wider text-zinc-500",children:z.label}),$.toolName&&y.jsx("span",{className:"text-[10px] font-mono text-sky-400 border border-sky-400/20 rounded px-1.5 py-px bg-sky-400/[0.06]",children:$.toolName}),$.model&&y.jsx("span",{className:"text-[10px] font-mono text-zinc-600 border border-white/[0.08] rounded px-1.5 py-px bg-white/[0.03]",children:$.model}),$.success===!0&&y.jsx("span",{className:"text-[10px] font-mono text-emerald-400 border border-emerald-400/20 rounded px-1.5 py-px bg-emerald-400/[0.08]",children:"success"}),$.success===!1&&y.jsx("span",{className:"text-[10px] font-mono text-red-400 border border-red-400/20 rounded px-1.5 py-px bg-red-400/[0.08]",children:"failed"}),Y&&$.success===null&&y.jsx(Rt,{variant:"error",children:"failed"})]}),y.jsx("span",{className:"text-[10px] font-mono text-zinc-700 flex-shrink-0 ml-2",children:cp($.timestamp,v)})]}),X?y.jsx("pre",{className:"text-[11px] font-mono text-zinc-400 whitespace-pre-wrap leading-relaxed overflow-x-auto rounded-lg p-2 mt-1 bg-black/20",children:$.content}):y.jsx(Mu,{content:$.content,className:"text-[12px] [&_pre]:text-[10px]"})]})]},$.id)}),R&&y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:"absolute -left-10 top-3 w-[30px] h-[30px] rounded-full flex items-center justify-center",style:{background:`${S}15`,border:`1px solid ${S}40`},children:y.jsx(DP,{className:"w-3.5 h-3.5 animate-spin",style:{color:S}})}),y.jsx("div",{className:"glass-card border rounded-2xl px-4 py-3",style:{borderColor:`${S}20`},children:y.jsx("span",{className:"text-[11px] font-mono",style:{color:S},children:"Working…"})})]})]})]}),y.jsx("div",{ref:w}),p>0&&y.jsxs("button",{type:"button",onClick:()=>{var $;($=w.current)==null||$.scrollIntoView({behavior:"smooth"}),f(0)},className:"fixed bottom-6 left-1/2 -translate-x-1/2 flex items-center gap-1.5 px-4 py-2 rounded-full border border-white/[0.1] bg-zinc-900/90 backdrop-blur-sm text-[11px] font-mono text-zinc-300 hover:text-white shadow-lg transition-all cursor-pointer z-50",children:[y.jsx(cz,{className:"w-3.5 h-3.5"}),p," new event",p!==1?"s":""]})]})}function n9({squadName:t,role:e}){const r=gl(),[n,i]=j.useState(null),[a,o]=j.useState(""),[c,u]=j.useState(!1),[d,p]=j.useState(""),[f,m]=j.useState(!1),[v,b]=j.useState("#38bdf8");j.useEffect(()=>{Ge.get(`/squads/${t}`).then(x=>{b(x.squad.color||"#38bdf8");const k=x.members.find(S=>S.roleName===e||S.role===e);k&&i(k)}).catch(()=>{}),Ge.get(`/squads/${t}/members/${e}/skill`).then(x=>{o(x.content)}).catch(()=>{})},[t,e]);const w=async()=>{m(!0);try{await Ge.put(`/squads/${t}/members/${e}/skill`,{content:d}),o(d),u(!1),Qe.success("Skill file saved")}catch{Qe.error("Failed to save skill file")}finally{m(!1)}};return n?y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",style:{background:`${v}06`},children:[y.jsxs("button",{type:"button",onClick:()=>r(`/squads/${t}`),className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors cursor-pointer",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," Back to ",t]}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-5 mb-5",children:[y.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[y.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center",style:{border:`1px solid ${v}30`,background:`${v}12`},children:Hs(n.roleName,v)}),y.jsxs("div",{children:[y.jsx("h2",{className:"text-xl tracking-wide",style:{fontFamily:"'Bebas Neue', sans-serif",color:v},children:n.displayName}),y.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[y.jsx("span",{className:"text-[11px] font-mono text-zinc-500",children:n.roleName}),n.veto&&y.jsx("span",{className:"text-[10px] font-mono text-amber-400 border border-amber-400/20 rounded px-1.5 py-px bg-amber-400/[0.06]",children:"veto"})]})]})]}),n.tools.length>0&&y.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:n.tools.map(x=>y.jsx("span",{className:"text-[10px] font-mono text-zinc-500 border border-white/[0.08] rounded px-1.5 py-px bg-white/[0.03]",children:x},x))})]}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-5",children:[y.jsxs("div",{className:"flex items-center justify-between mb-4",children:[y.jsx("h3",{className:"text-sm font-mono text-zinc-300",children:"Skill File"}),c?y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("button",{type:"button",onClick:()=>u(!1),className:"px-3 py-1.5 rounded-lg text-[11px] font-mono text-zinc-500 hover:text-zinc-300 border border-white/[0.1] transition-colors cursor-pointer",children:"Cancel"}),y.jsxs("button",{type:"button",onClick:w,disabled:f,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[11px] font-mono text-emerald-400 border border-emerald-400/30 hover:bg-emerald-400/10 transition-colors cursor-pointer disabled:opacity-50",children:[y.jsx(up,{className:"w-3 h-3"})," ",f?"Saving...":"Save"]})]}):y.jsxs("button",{type:"button",onClick:()=>{p(a),u(!0)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[11px] font-mono text-zinc-400 hover:text-zinc-200 border border-white/[0.1] hover:border-white/[0.2] transition-colors cursor-pointer",children:[y.jsx(Wf,{className:"w-3 h-3"})," Edit"]})]}),c?y.jsx("textarea",{value:d,onChange:x=>p(x.target.value),className:"w-full h-[500px] bg-black/30 border border-white/[0.08] rounded-xl p-4 text-[12px] font-mono text-zinc-300 resize-y focus:outline-none focus:border-white/[0.2] leading-relaxed",spellCheck:!1}):a?y.jsx(Mu,{content:a,className:"text-[12px] [&_pre]:text-[11px]"}):y.jsx("p",{className:"text-zinc-700 text-[12px] font-mono py-8 text-center",children:"No skill file configured for this agent"})]})]}):y.jsx("div",{className:"h-full flex items-center justify-center text-zinc-600",children:"Loading..."})}var Kg,eA;function Qr(){if(eA)return Kg;eA=1;var t=Array.isArray;return Kg=t,Kg}var Gg,tA;function NR(){if(tA)return Gg;tA=1;var t=typeof tf=="object"&&tf&&tf.Object===Object&&tf;return Gg=t,Gg}var Vg,rA;function Ai(){if(rA)return Vg;rA=1;var t=NR(),e=typeof self=="object"&&self&&self.Object===Object&&self,r=t||e||Function("return this")();return Vg=r,Vg}var Xg,nA;function Lu(){if(nA)return Xg;nA=1;var t=Ai(),e=t.Symbol;return Xg=e,Xg}var Yg,iA;function i9(){if(iA)return Yg;iA=1;var t=Lu(),e=Object.prototype,r=e.hasOwnProperty,n=e.toString,i=t?t.toStringTag:void 0;function a(o){var c=r.call(o,i),u=o[i];try{o[i]=void 0;var d=!0}catch{}var p=n.call(o);return d&&(c?o[i]=u:delete o[i]),p}return Yg=a,Yg}var Jg,aA;function a9(){if(aA)return Jg;aA=1;var t=Object.prototype,e=t.toString;function r(n){return e.call(n)}return Jg=r,Jg}var Zg,oA;function ra(){if(oA)return Zg;oA=1;var t=Lu(),e=i9(),r=a9(),n="[object Null]",i="[object Undefined]",a=t?t.toStringTag:void 0;function o(c){return c==null?c===void 0?i:n:a&&a in Object(c)?e(c):r(c)}return Zg=o,Zg}var Qg,sA;function na(){if(sA)return Qg;sA=1;function t(e){return e!=null&&typeof e=="object"}return Qg=t,Qg}var ey,lA;function xl(){if(lA)return ey;lA=1;var t=ra(),e=na(),r="[object Symbol]";function n(i){return typeof i=="symbol"||e(i)&&t(i)==r}return ey=n,ey}var ty,cA;function d1(){if(cA)return ty;cA=1;var t=Qr(),e=xl(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function i(a,o){if(t(a))return!1;var c=typeof a;return c=="number"||c=="symbol"||c=="boolean"||a==null||e(a)?!0:n.test(a)||!r.test(a)||o!=null&&a in Object(o)}return ty=i,ty}var ry,uA;function Wa(){if(uA)return ry;uA=1;function t(e){var r=typeof e;return e!=null&&(r=="object"||r=="function")}return ry=t,ry}var ny,dA;function f1(){if(dA)return ny;dA=1;var t=ra(),e=Wa(),r="[object AsyncFunction]",n="[object Function]",i="[object GeneratorFunction]",a="[object Proxy]";function o(c){if(!e(c))return!1;var u=t(c);return u==n||u==i||u==r||u==a}return ny=o,ny}var iy,fA;function o9(){if(fA)return iy;fA=1;var t=Ai(),e=t["__core-js_shared__"];return iy=e,iy}var ay,hA;function s9(){if(hA)return ay;hA=1;var t=o9(),e=(function(){var n=/[^.]+$/.exec(t&&t.keys&&t.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function r(n){return!!e&&e in n}return ay=r,ay}var oy,pA;function PR(){if(pA)return oy;pA=1;var t=Function.prototype,e=t.toString;function r(n){if(n!=null){try{return e.call(n)}catch{}try{return n+""}catch{}}return""}return oy=r,oy}var sy,mA;function l9(){if(mA)return sy;mA=1;var t=f1(),e=s9(),r=Wa(),n=PR(),i=/[\\^$.*+?()[\]{}|]/g,a=/^\[object .+?Constructor\]$/,o=Function.prototype,c=Object.prototype,u=o.toString,d=c.hasOwnProperty,p=RegExp("^"+u.call(d).replace(i,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function f(m){if(!r(m)||e(m))return!1;var v=t(m)?p:a;return v.test(n(m))}return sy=f,sy}var ly,gA;function c9(){if(gA)return ly;gA=1;function t(e,r){return e==null?void 0:e[r]}return ly=t,ly}var cy,yA;function Uo(){if(yA)return cy;yA=1;var t=l9(),e=c9();function r(n,i){var a=e(n,i);return t(a)?a:void 0}return cy=r,cy}var uy,vA;function yp(){if(vA)return uy;vA=1;var t=Uo(),e=t(Object,"create");return uy=e,uy}var dy,bA;function u9(){if(bA)return dy;bA=1;var t=yp();function e(){this.__data__=t?t(null):{},this.size=0}return dy=e,dy}var fy,xA;function d9(){if(xA)return fy;xA=1;function t(e){var r=this.has(e)&&delete this.__data__[e];return this.size-=r?1:0,r}return fy=t,fy}var hy,wA;function f9(){if(wA)return hy;wA=1;var t=yp(),e="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function i(a){var o=this.__data__;if(t){var c=o[a];return c===e?void 0:c}return n.call(o,a)?o[a]:void 0}return hy=i,hy}var py,_A;function h9(){if(_A)return py;_A=1;var t=yp(),e=Object.prototype,r=e.hasOwnProperty;function n(i){var a=this.__data__;return t?a[i]!==void 0:r.call(a,i)}return py=n,py}var my,SA;function p9(){if(SA)return my;SA=1;var t=yp(),e="__lodash_hash_undefined__";function r(n,i){var a=this.__data__;return this.size+=this.has(n)?0:1,a[n]=t&&i===void 0?e:i,this}return my=r,my}var gy,kA;function m9(){if(kA)return gy;kA=1;var t=u9(),e=d9(),r=f9(),n=h9(),i=p9();function a(o){var c=-1,u=o==null?0:o.length;for(this.clear();++c<u;){var d=o[c];this.set(d[0],d[1])}}return a.prototype.clear=t,a.prototype.delete=e,a.prototype.get=r,a.prototype.has=n,a.prototype.set=i,gy=a,gy}var yy,EA;function g9(){if(EA)return yy;EA=1;function t(){this.__data__=[],this.size=0}return yy=t,yy}var vy,AA;function h1(){if(AA)return vy;AA=1;function t(e,r){return e===r||e!==e&&r!==r}return vy=t,vy}var by,OA;function vp(){if(OA)return by;OA=1;var t=h1();function e(r,n){for(var i=r.length;i--;)if(t(r[i][0],n))return i;return-1}return by=e,by}var xy,TA;function y9(){if(TA)return xy;TA=1;var t=vp(),e=Array.prototype,r=e.splice;function n(i){var a=this.__data__,o=t(a,i);if(o<0)return!1;var c=a.length-1;return o==c?a.pop():r.call(a,o,1),--this.size,!0}return xy=n,xy}var wy,CA;function v9(){if(CA)return wy;CA=1;var t=vp();function e(r){var n=this.__data__,i=t(n,r);return i<0?void 0:n[i][1]}return wy=e,wy}var _y,jA;function b9(){if(jA)return _y;jA=1;var t=vp();function e(r){return t(this.__data__,r)>-1}return _y=e,_y}var Sy,NA;function x9(){if(NA)return Sy;NA=1;var t=vp();function e(r,n){var i=this.__data__,a=t(i,r);return a<0?(++this.size,i.push([r,n])):i[a][1]=n,this}return Sy=e,Sy}var ky,PA;function bp(){if(PA)return ky;PA=1;var t=g9(),e=y9(),r=v9(),n=b9(),i=x9();function a(o){var c=-1,u=o==null?0:o.length;for(this.clear();++c<u;){var d=o[c];this.set(d[0],d[1])}}return a.prototype.clear=t,a.prototype.delete=e,a.prototype.get=r,a.prototype.has=n,a.prototype.set=i,ky=a,ky}var Ey,RA;function p1(){if(RA)return Ey;RA=1;var t=Uo(),e=Ai(),r=t(e,"Map");return Ey=r,Ey}var Ay,IA;function w9(){if(IA)return Ay;IA=1;var t=m9(),e=bp(),r=p1();function n(){this.size=0,this.__data__={hash:new t,map:new(r||e),string:new t}}return Ay=n,Ay}var Oy,$A;function _9(){if($A)return Oy;$A=1;function t(e){var r=typeof e;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?e!=="__proto__":e===null}return Oy=t,Oy}var Ty,MA;function xp(){if(MA)return Ty;MA=1;var t=_9();function e(r,n){var i=r.__data__;return t(n)?i[typeof n=="string"?"string":"hash"]:i.map}return Ty=e,Ty}var Cy,DA;function S9(){if(DA)return Cy;DA=1;var t=xp();function e(r){var n=t(this,r).delete(r);return this.size-=n?1:0,n}return Cy=e,Cy}var jy,LA;function k9(){if(LA)return jy;LA=1;var t=xp();function e(r){return t(this,r).get(r)}return jy=e,jy}var Ny,zA;function E9(){if(zA)return Ny;zA=1;var t=xp();function e(r){return t(this,r).has(r)}return Ny=e,Ny}var Py,BA;function A9(){if(BA)return Py;BA=1;var t=xp();function e(r,n){var i=t(this,r),a=i.size;return i.set(r,n),this.size+=i.size==a?0:1,this}return Py=e,Py}var Ry,UA;function m1(){if(UA)return Ry;UA=1;var t=w9(),e=S9(),r=k9(),n=E9(),i=A9();function a(o){var c=-1,u=o==null?0:o.length;for(this.clear();++c<u;){var d=o[c];this.set(d[0],d[1])}}return a.prototype.clear=t,a.prototype.delete=e,a.prototype.get=r,a.prototype.has=n,a.prototype.set=i,Ry=a,Ry}var Iy,qA;function RR(){if(qA)return Iy;qA=1;var t=m1(),e="Expected a function";function r(n,i){if(typeof n!="function"||i!=null&&typeof i!="function")throw new TypeError(e);var a=function(){var o=arguments,c=i?i.apply(this,o):o[0],u=a.cache;if(u.has(c))return u.get(c);var d=n.apply(this,o);return a.cache=u.set(c,d)||u,d};return a.cache=new(r.Cache||t),a}return r.Cache=t,Iy=r,Iy}var $y,FA;function O9(){if(FA)return $y;FA=1;var t=RR(),e=500;function r(n){var i=t(n,function(o){return a.size===e&&a.clear(),o}),a=i.cache;return i}return $y=r,$y}var My,HA;function T9(){if(HA)return My;HA=1;var t=O9(),e=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=t(function(i){var a=[];return i.charCodeAt(0)===46&&a.push(""),i.replace(e,function(o,c,u,d){a.push(u?d.replace(r,"$1"):c||o)}),a});return My=n,My}var Dy,WA;function g1(){if(WA)return Dy;WA=1;function t(e,r){for(var n=-1,i=e==null?0:e.length,a=Array(i);++n<i;)a[n]=r(e[n],n,e);return a}return Dy=t,Dy}var Ly,KA;function C9(){if(KA)return Ly;KA=1;var t=Lu(),e=g1(),r=Qr(),n=xl(),i=t?t.prototype:void 0,a=i?i.toString:void 0;function o(c){if(typeof c=="string")return c;if(r(c))return e(c,o)+"";if(n(c))return a?a.call(c):"";var u=c+"";return u=="0"&&1/c==-1/0?"-0":u}return Ly=o,Ly}var zy,GA;function IR(){if(GA)return zy;GA=1;var t=C9();function e(r){return r==null?"":t(r)}return zy=e,zy}var By,VA;function $R(){if(VA)return By;VA=1;var t=Qr(),e=d1(),r=T9(),n=IR();function i(a,o){return t(a)?a:e(a,o)?[a]:r(n(a))}return By=i,By}var Uy,XA;function wp(){if(XA)return Uy;XA=1;var t=xl();function e(r){if(typeof r=="string"||t(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return Uy=e,Uy}var qy,YA;function y1(){if(YA)return qy;YA=1;var t=$R(),e=wp();function r(n,i){i=t(i,n);for(var a=0,o=i.length;n!=null&&a<o;)n=n[e(i[a++])];return a&&a==o?n:void 0}return qy=r,qy}var Fy,JA;function MR(){if(JA)return Fy;JA=1;var t=y1();function e(r,n,i){var a=r==null?void 0:t(r,n);return a===void 0?i:a}return Fy=e,Fy}var j9=MR();const On=vt(j9);var Hy,ZA;function N9(){if(ZA)return Hy;ZA=1;function t(e){return e==null}return Hy=t,Hy}var P9=N9();const tt=vt(P9);var Wy,QA;function R9(){if(QA)return Wy;QA=1;var t=ra(),e=Qr(),r=na(),n="[object String]";function i(a){return typeof a=="string"||!e(a)&&r(a)&&t(a)==n}return Wy=i,Wy}var I9=R9();const Ro=vt(I9);var $9=f1();const Je=vt($9);var M9=Wa();const wl=vt(M9);var Ky={exports:{}},pt={};/**
449
+ `)){const a=i.match(/^(\w[\w-]*)\s*:\s*(.*)$/);if(a){r&&n&&(e[r]=n,n=null),r=a[1]??"";const o=(a[2]??"").trim();o===""||o==="[]"?n=[]:o.startsWith("[")&&o.endsWith("]")?e[r]=Kq(o):e[r]=o.replace(/^["']|["']$/g,"")}else i.match(/^\s+-\s+(.+)/)&&r&&(n||(n=[]),n.push(i.replace(/^\s+-\s+/,"").trim()))}return r&&n&&(e[r]=n),e}function Mf(t){const e=t.match(/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/);return e?{frontMatter:Gq(e[1]??""),body:e[2]??""}:{frontMatter:{},body:t}}function Vq({content:t}){const{body:e}=Mf(t);return e.trim()?y.jsx(Mu,{content:e}):y.jsx("p",{className:"font-mono text-[11px] text-zinc-500",children:"No content body in this skill."})}function Xq(){const[t,e]=j.useState("installed"),[r,n]=j.useState([]),[i,a]=j.useState([]),[o,c]=j.useState(null),[u,d]=j.useState(null),[p,f]=j.useState(""),[m,v]=j.useState(!1),[b,w]=j.useState(!1),[x,k]=j.useState(!1),[S,A]=j.useState(""),[C,T]=j.useState(null),[O,N]=j.useState(null),R=j.useCallback(async()=>{try{const I=await Ge.get("/skills"),q=new Set(I.skills.map(Q=>(Q.name||"").toLowerCase()));n(I.skills),a(Q=>Q.map(le=>({...le,installed:q.has((le.name||"").toLowerCase())})))}catch(I){Qe.error(I instanceof Error?I.message:"Failed to load skills")}},[]),$=j.useCallback(async I=>{w(!0);try{const q=await Ge.get(`/skills/${encodeURIComponent(I)}`);d(q);const{body:Q}=Mf(q.content);A(Q)}catch(q){Qe.error(q instanceof Error?q.message:"Failed to load skill"),d(null)}finally{w(!1)}},[]);j.useEffect(()=>{R()},[R]),j.useEffect(()=>{if(t==="installed"){N(null);return}const I=p.trim();if(t==="skillssh"&&!I){a([]),N(null),v(!1);return}let q=!1;v(!0);const Q=window.setTimeout(async()=>{try{const le=await Ge.get(`/skills/discover?source=${t}&q=${encodeURIComponent(I)}`);if(q)return;a(le.skills),N(null)}catch(le){if(q)return;a([]),N(le instanceof Error?le.message:"Discovery failed")}finally{q||v(!1)}},250);return()=>{q=!0,window.clearTimeout(Q)}},[p,t]);const W=j.useMemo(()=>{const I=p.trim().toLowerCase();return I?r.filter(q=>[q.name,q.description,q.preview].some(Q=>Q==null?void 0:Q.toLowerCase().includes(I))):r},[r,p]),z=t==="installed"?W:i,U=W.find(I=>I.name===o)??null,F=i.find(I=>yf(I)===o)??null,X=(U==null?void 0:U.name)??(F==null?void 0:F.name)??null;j.useEffect(()=>{if(k(!1),!z.length){c(null),t!=="installed"&&d(null);return}if(!o||!z.some(I=>yf(I)===o)){const I=z[0];I&&c(yf(I))}},[o,t,z]),j.useEffect(()=>{if(t!=="installed"||!X){d(null);return}$(X)},[$,X,t]);async function Y(I){if(!I.url&&!I.registrySource){Qe.error("Install source is not available for this skill yet");return}T(I.name);try{await Ge.post("/skills/install",{name:I.name,source:I.source,url:I.url,registrySource:I.registrySource,skillId:I.skillId}),Qe.success(`Installed ${I.title||I.name}`),await R(),a(q=>q.map(Q=>Q.name===I.name?{...Q,installed:!0}:Q))}catch(q){Qe.error(q instanceof Error?q.message:"Install failed")}finally{T(null)}}async function G(I){T(I);try{await Ge.delete(`/skills/${encodeURIComponent(I)}`),Qe.success(`Removed ${I}`),await R(),a(q=>q.map(Q=>Q.name===I?{...Q,installed:!1}:Q))}catch(q){Qe.error(q instanceof Error?q.message:"Failed to remove skill")}finally{T(null)}}async function Z(){if(u){T(u.name);try{const I=u.content.match(/^(---\s*\n[\s\S]*?\n---\s*\n)/),q=I?`${I[1]}${S}`:S;await Ge.put(`/skills/${encodeURIComponent(u.name)}`,{content:q}),Qe.success(`Updated ${u.name}`),k(!1),await Promise.all([R(),$(u.name)])}catch(I){Qe.error(I instanceof Error?I.message:"Failed to save skill")}finally{T(null)}}}const K=!!(U!=null&&U.activatedForOrchestrator),ee=C===(u==null?void 0:u.name),L=C===(F==null?void 0:F.name);return y.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[y.jsxs("div",{className:"w-64 flex-shrink-0 border-r border-white/[0.06] flex flex-col overflow-hidden",children:[y.jsxs("div",{className:"px-2.5 pt-2.5 pb-2 flex-shrink-0 border-b border-white/[0.06] space-y-2",children:[y.jsxs("div",{className:"relative",children:[y.jsx(zP,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-zinc-700"}),y.jsx("input",{type:"text",value:p,onChange:I=>f(I.target.value),placeholder:"Search skills…",className:"w-full bg-[#181818] border border-white/[0.06] rounded-xl pl-7 pr-2 py-1.5 text-[11px] text-zinc-300 font-mono placeholder:text-zinc-700 focus:outline-none focus:border-[#E43A9C]/30 transition-colors"})]}),y.jsx("div",{className:"flex flex-col gap-0.5",children:Wq.map(I=>y.jsxs("button",{type:"button",onClick:()=>e(I.id),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] font-mono transition-colors flex items-center justify-between cursor-pointer ${t===I.id?"text-[#E43A9C]":"text-zinc-500 hover:text-zinc-300 hover:bg-white/[0.04]"}`,style:t===I.id?{background:"rgba(228,58,156,0.10)"}:void 0,children:[y.jsx("span",{children:I.label}),I.id==="installed"&&y.jsx("span",{className:"text-[10px] text-zinc-600",children:r.length})]},I.id))})]}),y.jsxs("div",{className:"flex-1 overflow-y-auto py-1.5",children:[m&&t!=="installed"?y.jsxs("div",{className:"flex items-center gap-2 rounded-2xl border border-white/[0.08] bg-white/[0.03] px-3 py-3 font-mono text-[11px] text-zinc-500",children:[y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"})," Searching registry..."]}):null,z.map(I=>{const q=yf(I),Q=o===q,le=I.description||("preview"in I?I.preview:"No description available.");return y.jsxs("button",{type:"button",onClick:()=>{k(!1),c(q)},className:`w-full text-left px-3 py-2.5 border-b border-white/[0.03] transition-colors cursor-pointer ${Q?"border-l-2 border-l-[#E43A9C] bg-[#E43A9C]/5":"hover:bg-white/[0.03]"}`,children:[y.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[y.jsx("span",{className:"truncate font-mono text-[11px] text-zinc-200",children:I.name}),"installed"in I&&I.installed?y.jsx(Rt,{variant:"success",children:"installed"}):null]}),y.jsx("p",{className:"line-clamp-2 font-mono text-[10px] leading-relaxed text-zinc-600",children:le})]},`${t}:${q}`)}),!m&&z.length===0?y.jsx("div",{className:"px-4 py-8",children:y.jsx("p",{className:"font-mono text-[11px] leading-relaxed text-zinc-500",children:O||(t==="skillssh"&&!p.trim()?"Start typing to search the skills.sh registry.":p.trim()?"No skills match your search.":"No skills available in this source.")})}):null]})]}),y.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto p-5",children:t==="installed"&&U?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mb-5 flex items-start justify-between gap-4 border-b border-white/[0.06] pb-5",children:[y.jsxs("div",{className:"flex min-w-0 gap-4",children:[y.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-[#E43A9C]/12 text-[#E43A9C]",children:y.jsx(tx,{className:"h-6 w-6"})}),y.jsxs("div",{className:"min-w-0",children:[y.jsx("h3",{className:"truncate text-[34px] uppercase tracking-[0.08em] text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:U.name}),y.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[y.jsx(Rt,{variant:"success",children:"installed"}),K?y.jsx(Rt,{variant:"warning",children:"active"}):y.jsx(Rt,{variant:"muted",children:"inactive"}),y.jsx(Rt,{variant:"muted",children:"local skill"})]}),y.jsxs("div",{className:"mt-3 space-y-1 font-mono text-[11px] text-zinc-500",children:[y.jsxs("p",{children:["path: ",U.filePath]}),y.jsxs("p",{children:["orchestrator: ",K?"enabled":"disabled"]})]})]})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[x?y.jsxs(Ba,{onClick:Z,disabled:ee||S===Mf((u==null?void 0:u.content)??"").body,className:"px-3 py-2",children:[ee?y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"}):y.jsx(Wf,{className:"h-3.5 w-3.5"}),"Save"]}):y.jsxs(wi,{onClick:()=>k(!0),className:"px-3 py-2",children:[y.jsx(Wf,{className:"h-3.5 w-3.5"})," Edit"]}),y.jsxs(Vf,{onClick:()=>G(U.name),className:"px-3 py-2",children:[ee?y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"}):y.jsx(Da,{className:"h-3.5 w-3.5"}),"Remove"]})]})]}),y.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:b&&!u?y.jsxs("div",{className:"flex items-center gap-2 font-mono text-[11px] text-zinc-500",children:[y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"})," Loading skill..."]}):x?y.jsxs("div",{className:"space-y-3",children:[y.jsx("textarea",{value:S,onChange:I=>A(I.target.value),className:"min-h-[440px] w-full rounded-2xl border border-white/[0.08] bg-black/30 p-4 font-mono text-[12px] leading-6 text-zinc-200 outline-none transition-colors focus:border-[#E43A9C]/50"}),y.jsxs("div",{className:"flex items-center justify-between font-mono text-[11px] text-zinc-500",children:[y.jsx("span",{children:"Editing skill markdown"}),y.jsx(wi,{onClick:()=>{k(!1);const{body:I}=Mf((u==null?void 0:u.content)??"");A(I)},className:"px-3 py-2",children:"Cancel"})]})]}):u?y.jsx(Vq,{content:u.content}):y.jsx("p",{className:"font-mono text-[11px] text-zinc-500",children:"Select an installed skill to inspect it."})})]}):t!=="installed"&&F?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mb-5 flex items-start justify-between gap-4 border-b border-white/[0.06] pb-5",children:[y.jsxs("div",{className:"flex min-w-0 gap-4",children:[y.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-[#E43A9C]/12 text-[#E43A9C]",children:y.jsx(gB,{className:"h-6 w-6"})}),y.jsxs("div",{className:"min-w-0",children:[y.jsx("h3",{className:"truncate text-[34px] uppercase tracking-[0.08em] text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:F.title||F.name}),y.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[y.jsx(Rt,{variant:F.installed?"success":"default",children:F.installed?"installed":"available"}),y.jsx(Rt,{variant:"muted",children:ZE(F.source)}),QE(F.installs)?y.jsx(Rt,{variant:"info",children:QE(F.installs)}):null]}),y.jsxs("div",{className:"mt-3 space-y-1 font-mono text-[11px] text-zinc-500",children:[y.jsxs("p",{children:["registry: ",ZE(F.source)]}),F.registrySource?y.jsxs("p",{children:["source: ",F.registrySource]}):null,F.url?y.jsxs("p",{children:["url: ",F.url]}):null]})]})]}),y.jsx("div",{className:"flex items-center gap-2",children:F.installed?y.jsx(wi,{onClick:()=>{e("installed"),c(F.name)},className:"px-3 py-2",children:"Open installed"}):y.jsxs(Ba,{onClick:()=>Y(F),disabled:L||!F.url&&!F.registrySource,className:"px-3 py-2",children:[L?y.jsx(Ts,{className:"h-3.5 w-3.5 animate-spin"}):y.jsx(Nz,{className:"h-3.5 w-3.5"}),"Install"]})})]}),y.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:[y.jsx("div",{className:"rounded-2xl border border-white/[0.06] bg-white/[0.02] p-5",children:y.jsx("p",{className:"font-mono text-[12px] leading-7 text-zinc-300",children:F.description||"No registry description is available for this skill yet."})}),y.jsx("div",{className:"mt-4 rounded-2xl border border-dashed border-white/[0.08] bg-black/20 p-4 font-mono text-[11px] leading-6 text-zinc-500",children:"Install will fetch the skill definition from the selected registry source and add it to your local skills library."})]})]}):y.jsx("div",{className:"flex h-full items-center justify-center rounded-2xl border border-dashed border-white/[0.08] bg-white/[0.02] p-8 text-center",children:y.jsxs("div",{children:[y.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-[#E43A9C]/12 text-[#E43A9C]",children:y.jsx(tx,{className:"h-6 w-6"})}),y.jsx("h3",{className:"text-[28px] uppercase tracking-[0.08em] text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Select a Skill"}),y.jsx("p",{className:"mt-2 font-mono text-[11px] leading-relaxed text-zinc-500",children:"Choose a skill from the left panel to inspect details, install registry entries, or edit local definitions."})]})})})]})}function Df(t){let e=0;for(let n=0;n<t.length;n++)e=t.charCodeAt(n)+((e<<5)-e);return`hsl(${(e%360+360)%360}, 70%, 65%)`}function vf(){const{name:t,instanceId:e,role:r}=hL();return t&&r?y.jsx(n9,{squadName:t,role:r}):t&&e?y.jsx(r9,{squadName:t,instanceId:e}):t?y.jsx(Zq,{name:t}):y.jsx(Yq,{})}function Yq(){const[t,e]=j.useState([]),[r,n]=j.useState(null),i=gl();return j.useEffect(()=>{Promise.all([Ge.get("/squads"),Ge.get("/config")]).then(([a,o])=>{e(a.squads),n(o.config.maxInstancesPerSquad)}).catch(()=>{})},[]),y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[y.jsx("div",{className:"mb-6",children:y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Squads"}),y.jsxs("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:[t.length," squads · ",t.reduce((a,o)=>a+(o.activeInstances||0),0)," ","active instances"]})]})}),y.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3",children:[t.map(a=>{var c;const o=a.color||"#38bdf8";return y.jsxs("button",{type:"button",onClick:()=>i(`/squads/${a.name}`),className:"text-left rounded-2xl p-5 transition-all group cursor-pointer",style:{border:`1px solid ${o}30`,background:`${o}08`,backdropFilter:"blur(20px)"},onMouseEnter:u=>{u.currentTarget.style.borderColor=`${o}70`,u.currentTarget.style.background=`${o}12`},onMouseLeave:u=>{u.currentTarget.style.borderColor=`${o}30`,u.currentTarget.style.background=`${o}08`},children:[y.jsxs("div",{className:"flex items-start justify-between mb-1",children:[y.jsx("h3",{className:"text-sm font-mono transition-colors",style:{color:o},children:a.name}),y.jsx(Rt,{variant:Ms(a.status),children:a.status})]}),y.jsxs("div",{className:"flex items-center justify-between mb-3",children:[y.jsx("p",{className:"text-[11px] text-zinc-600 font-mono",children:((c=a.config)==null?void 0:c.prMode)??"draft-pr"}),y.jsxs("span",{className:"text-[11px] text-zinc-600 font-mono flex items-center gap-1",children:[y.jsx(Tz,{className:"w-3 h-3"}),a.activeInstances,"/",r??(a.totalInstances||a.memberCount)]})]}),a.repoUrl&&y.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-zinc-700 font-mono mb-4",children:[y.jsx(r1,{className:"w-3 h-3 flex-shrink-0"}),y.jsx("span",{className:"truncate",children:a.repoUrl.replace("https://github.com/","")})]}),a.recentActivity&&a.recentActivity.length>0&&y.jsxs("div",{className:"border-t pt-3",style:{borderColor:`${o}15`},children:[y.jsx("p",{className:"text-[10px] font-mono uppercase tracking-wider mb-2",style:{color:`${o}80`},children:"Recent Work"}),y.jsx("ul",{className:"space-y-1.5",children:a.recentActivity.map(u=>{const d={className:"w-3.5 h-3.5 flex-shrink-0 mt-px"},p=Jq(u.status,d),f=u.objective?u.objective.length>60?`${u.objective.slice(0,60)}…`:u.objective:u.issueRef||"Instance";return y.jsxs("li",{className:"flex items-start gap-1.5 text-[11px] font-mono text-zinc-600",children:[p,y.jsx("span",{className:"truncate",children:f})]},u.id)})})]})]},a.id)}),t.length===0&&y.jsxs("div",{className:"col-span-full text-center py-12 text-zinc-600",children:[y.jsx(a1,{size:48,className:"mx-auto mb-3 opacity-30"}),y.jsx("p",{className:"text-[11px] font-mono",children:"No squads hired yet. Ask IO to hire a squad for a project."})]})]})]})}function Jq(t,e){const r=t.toLowerCase();return r.includes("complete")||r.includes("success")||r.includes("done")?y.jsx(IP,{...e,style:{color:"#34d399"}}):r.includes("warning")||r.includes("review")?y.jsx(wB,{...e,style:{color:"#fbbf24"}}):r.includes("error")||r.includes("fail")?y.jsx($P,{...e,style:{color:"#f87171"}}):r.includes("working")||r.includes("progress")||r.includes("running")?y.jsx(DP,{...e,style:{color:"#E43A9C"}}):y.jsx(Wz,{...e,style:{color:"#60a5fa"}})}function Hs(t,e){const r="w-4 h-4",n={color:e},i=t.toLowerCase();return i.includes("lead")||i.includes("pm")||i.includes("technical")?y.jsx(t1,{className:r,style:n}):i.includes("qa")||i.includes("test")?y.jsx(mz,{className:r,style:n}):i.includes("scribe")?y.jsx(uB,{className:r,style:n}):y.jsx(qc,{className:r,style:n})}function Zq({name:t}){var k;const[e,r]=j.useState(null),[n,i]=j.useState("agents"),[a,o]=j.useState([]),[c,u]=j.useState(0),[d,p]=j.useState(null),[f,m]=j.useState([]),v=gl(),b=Fa();j.useEffect(()=>{Ge.get(`/squads/${t}`).then(r).catch(()=>{})},[t]),j.useEffect(()=>{n==="history"&&Ge.get(`/squads/${t}/history`).then(S=>{o(S.items),u(S.total)}).catch(()=>{}),n==="schedules"&&e&&Ge.get(`/schedules?targetId=${e.squad.id}`).then(S=>m(S.schedules)).catch(()=>{})},[n,t,e]);const w=S=>{Ge.get(`/squads/${t}/history/${S.id}`).then(p).catch(()=>Qe.error("Failed to load activity detail"))};if(!e)return y.jsx("div",{className:"h-full flex items-center justify-center text-zinc-600",children:"Loading..."});const x=e.squad.color||"#38bdf8";return d?y.jsx(Qq,{activity:d,squadColor:x,squadName:e.squad.name,onBack:()=>p(null)}):y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",style:{background:`${x}06`},children:[y.jsxs("button",{type:"button",onClick:()=>v("/squads"),className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," All Squads"]}),y.jsxs("div",{className:"flex items-start justify-between mb-5",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-3xl tracking-wide",style:{fontFamily:"'Bebas Neue', sans-serif",color:x},children:e.squad.name}),y.jsxs("p",{className:"text-[11px] text-zinc-600 font-mono",children:[((k=e.squad.config)==null?void 0:k.prMode)??"draft-pr"," · ",e.squad.autonomyTier||"standard"," ","autonomy"]}),e.squad.repoUrl&&y.jsxs("a",{href:e.squad.repoUrl,target:"_blank",rel:"noreferrer",className:"text-[11px] font-mono text-[#E43A9C] hover:text-[#F041FF] flex items-center gap-1 mt-1 transition-colors",children:[y.jsx(r1,{className:"w-3 h-3"}),e.squad.repoUrl.replace("https://github.com/","")]})]}),y.jsx(Rt,{variant:Ms(e.squad.status),children:e.squad.status})]}),y.jsx("div",{className:"flex gap-0 mb-5 border-b border-white/[0.06]",children:["agents","instances","schedules","history"].map(S=>y.jsx("button",{type:"button",onClick:()=>i(S),className:`px-4 py-2 text-[11px] font-mono capitalize transition-colors border-b-2 -mb-px ${n===S?"text-[#E43A9C] border-[#E43A9C]":"text-zinc-600 hover:text-zinc-300 border-transparent"}`,children:S},S))}),n==="agents"&&y.jsx("div",{className:"space-y-2",children:e.members.map(S=>y.jsxs("button",{type:"button",onClick:()=>v(`/squads/${t}/agents/${S.roleName||S.role}`),className:"w-full glass-card border border-white/[0.07] rounded-2xl p-4 flex items-center gap-3 hover:bg-white/[0.03] transition-colors cursor-pointer text-left",children:[y.jsx("div",{className:"w-8 h-8 rounded-xl flex items-center justify-center flex-shrink-0",style:{border:`1px solid ${x}30`,background:`${x}12`},children:Hs(S.roleName||S.role,x)}),y.jsxs("div",{className:"flex-1 min-w-0",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-sm font-mono text-zinc-200",children:S.displayName}),y.jsx(Rt,{variant:Ms(S.status),children:S.status})]}),y.jsx("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:S.role}),S.currentTask&&y.jsx("p",{className:"text-xs text-zinc-500 mt-1 truncate",children:S.currentTask})]})]},S.id))}),n==="instances"&&y.jsx("div",{className:"space-y-2",children:e.instances.length===0?y.jsx("div",{className:"text-center py-16 text-zinc-700 font-mono text-sm",children:"No active instances"}):e.instances.map(S=>y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-4 flex items-center gap-4",children:[y.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2 text-[11px] font-mono",children:[y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"ID"}),y.jsx("p",{className:"text-zinc-300 mt-0.5 truncate",children:S.id.slice(0,8)})]}),y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"Branch"}),y.jsx("p",{className:"text-zinc-300 mt-0.5 truncate",children:S.branch||"—"})]}),y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"Status"}),y.jsx("p",{className:"text-zinc-300 mt-0.5",children:y.jsx(Rt,{variant:Ms(S.status),children:S.status})})]}),y.jsxs("div",{children:[y.jsx("span",{className:"text-zinc-700",children:"Tasks"}),y.jsxs("p",{className:"text-zinc-300 mt-0.5",children:[S.tasksComplete,"/",S.taskCount]})]})]}),y.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[y.jsx("button",{type:"button",onClick:()=>v(`/squads/${t}/instances/${S.id}`),title:"View instance agents",className:"p-2 rounded-xl hover:bg-white/[0.06] transition-colors cursor-pointer",style:{color:x},children:y.jsx(Hf,{className:"w-4 h-4"})}),y.jsx("button",{type:"button",onClick:async()=>{try{await Ge.post(`/squads/${t}/instances/${S.id}/cancel`),Qe.success("Instance cancelled")}catch{Qe.error("Failed to cancel instance")}},title:"Stop instance",className:"p-2 rounded-xl hover:bg-red-500/10 text-zinc-600 hover:text-red-400 transition-colors cursor-pointer",children:y.jsx(dp,{className:"w-4 h-4"})})]})]},S.id))}),n==="schedules"&&y.jsx("div",{className:"overflow-auto rounded-2xl border border-white/[0.07] glass-card",children:f.length===0?y.jsx("div",{className:"text-center py-16 text-zinc-700 font-mono text-sm",children:"No schedules for this squad"}):y.jsxs("table",{className:"w-full text-[11px] font-mono",children:[y.jsx("thead",{children:y.jsx("tr",{className:"border-b border-white/[0.06]",style:{background:"rgba(20,20,20,0.6)"},children:["Schedule","Next Run","Status"].map(S=>y.jsx("th",{className:"text-left px-4 py-2.5 text-zinc-600 font-medium",children:S},S))})}),y.jsx("tbody",{children:f.map(S=>y.jsxs("tr",{className:`border-b border-white/[0.04] hover:bg-white/[0.015] transition-colors ${S.enabled?"":"opacity-50"}`,children:[y.jsxs("td",{className:"px-4 py-3",children:[y.jsx("div",{className:"text-zinc-300",children:S.name||S.prompt}),y.jsx("div",{className:"text-zinc-700 text-[10px] mt-0.5",children:S.cron})]}),y.jsx("td",{className:"px-4 py-3 text-zinc-600",children:y.jsxs("span",{className:"flex items-center gap-1",children:[y.jsx(e1,{className:"w-3 h-3"}),S.enabled&&S.nextRun?Fs(S.nextRun,b):"—"]})}),y.jsx("td",{className:"px-4 py-3",children:y.jsx(Rt,{variant:S.enabled?"success":"muted",children:S.enabled?"active":"paused"})})]},S.id))})]})}),n==="history"&&y.jsxs("div",{className:"space-y-2",children:[a.length===0?y.jsx("div",{className:"text-center py-16 text-zinc-700 font-mono text-sm",children:"No history yet"}):a.map(S=>y.jsxs("button",{type:"button",onClick:()=>w(S),className:"w-full glass-card border border-white/[0.07] rounded-2xl px-4 py-3.5 flex items-center gap-3 hover:bg-white/[0.03] transition-colors cursor-pointer text-left",children:[y.jsx("div",{className:"flex-shrink-0",children:S.status==="completed"?y.jsx(IP,{className:"w-4 h-4",style:{color:"#34d399"}}):y.jsx($P,{className:"w-4 h-4",style:{color:"#f87171"}})}),y.jsxs("div",{className:"flex-1 min-w-0",children:[y.jsx("p",{className:"text-[12px] text-zinc-300 font-mono truncate",children:S.title}),y.jsxs("div",{className:"flex items-center gap-3 mt-0.5",children:[y.jsx("span",{className:"text-[10px] text-zinc-700 font-mono",children:Fs(S.completedAt||S.createdAt,b)}),y.jsxs("span",{className:"text-[10px] text-zinc-700 font-mono flex items-center gap-1",children:[y.jsx(Hf,{className:"w-2.5 h-2.5"}),S.duration||"—"]}),y.jsxs("span",{className:"text-[10px] text-zinc-700 font-mono flex items-center gap-1",children:[y.jsx(qc,{className:"w-2.5 h-2.5"}),S.agentCount," agent",S.agentCount!==1?"s":""]})]})]}),y.jsx(Rt,{variant:S.status==="completed"?"success":"error",children:S.status})]},S.id)),a.length<c&&y.jsx("button",{type:"button",onClick:()=>{Ge.get(`/squads/${t}/history?offset=${a.length}`).then(S=>{o(A=>[...A,...S.items])}).catch(()=>{})},className:"w-full text-center py-3 text-[11px] font-mono text-zinc-600 hover:text-zinc-300 transition-colors cursor-pointer",children:"Load more"})]})]})}function Qq({activity:t,squadColor:e,squadName:r,onBack:n}){const i=Fa(),[a,o]=j.useState(new Set),c=j.useMemo(()=>{const v={};for(const b of t.agentEntries)v[b.agentId]=Df(b.agentName);return v},[t]),u={thought:{label:"Thinking",icon:n1},tool_call:{label:"Tool Call",icon:UP},tool_result:{label:"Tool Result",icon:MP},message:{label:"Message",icon:qc},decision:{label:"Decision",icon:t1}},d={label:"Message",icon:qc},p=v=>u[v]??d,f=v=>{o(b=>{const w=new Set(b);return w.has(v)?w.delete(v):w.add(v),w})},m=j.useMemo(()=>{const v=t.agentEntries.flatMap(b=>b.events.map(w=>({ev:w,entry:b})));return v.sort((b,w)=>b.ev.timestamp.localeCompare(w.ev.timestamp)),a.size>0?v.filter(({entry:b})=>a.has(b.agentId)):v},[t,a]);return y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",style:{background:`${e}06`},children:[y.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors cursor-pointer",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," Back to ",r]}),y.jsxs("div",{className:"flex items-start justify-between mb-5",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide",style:{fontFamily:"'Bebas Neue', sans-serif",color:e},children:t.title}),y.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[y.jsx("span",{className:"text-[11px] text-zinc-600 font-mono",children:Fs(t.completedAt||t.createdAt,i)}),y.jsxs("span",{className:"text-[11px] text-zinc-700 font-mono flex items-center gap-1",children:[y.jsx(e1,{className:"w-3 h-3"}),t.duration||"—"]})]})]}),y.jsx(Rt,{variant:t.status==="completed"?"success":"error",children:t.status})]}),y.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[t.agentEntries.map(v=>{const b=c[v.agentId],w=a.has(v.agentId),k=!(a.size>0)||w;return y.jsxs("button",{type:"button",onClick:()=>f(v.agentId),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-xl border transition-all cursor-pointer",style:{borderColor:k?`${b}30`:"rgba(255,255,255,0.05)",background:k?`${b}10`:"transparent",opacity:k?1:.4},children:[Hs(v.roleType||v.role,b),y.jsx("span",{className:"text-[11px] font-mono",style:{color:k?b:"#71717a"},children:v.agentName}),y.jsxs("span",{className:"text-[10px] font-mono text-zinc-500",children:["— ",v.role]})]},v.agentId)}),a.size>0&&y.jsx("button",{type:"button",onClick:()=>o(new Set),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-xl border border-white/[0.1] text-[11px] font-mono text-zinc-400 hover:text-zinc-200 transition-colors cursor-pointer",children:"Show all"})]}),y.jsxs("div",{className:"relative pl-10",children:[y.jsx("div",{className:"absolute left-[15px] top-0 bottom-0 w-px bg-white/[0.06]"}),y.jsx("div",{className:"space-y-3",children:m.map(({ev:v,entry:b})=>{const w=c[b.agentId],{label:x,icon:k}=p(v.kind),S=v.kind==="tool_call"||v.kind==="tool_result";return y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:"absolute -left-10 top-3 w-[30px] h-[30px] rounded-full flex items-center justify-center",style:{background:`${w}15`,border:`1px solid ${w}35`},children:y.jsx(k,{className:"w-3.5 h-3.5",style:{color:w}})}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[y.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[y.jsxs("div",{className:"flex items-center gap-1",children:[Hs(b.roleType||b.role,w),y.jsx("span",{className:"text-[10px] font-mono",style:{color:w},children:b.agentName})]}),y.jsx("span",{className:"text-zinc-700 text-[10px]",children:"·"}),y.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wider text-zinc-500",children:x}),v.label&&y.jsx("span",{className:"text-[10px] font-mono text-zinc-600 border border-white/[0.08] rounded px-1.5 py-px bg-white/[0.03]",children:v.label}),v.status==="error"&&y.jsx(Rt,{variant:"error",children:"failed"}),v.status==="ok"&&v.kind==="tool_result"&&y.jsx(Rt,{variant:"success",children:"ok"})]}),y.jsx("span",{className:"text-[10px] font-mono text-zinc-700 flex-shrink-0 ml-2",children:cp(v.timestamp,i)})]}),S?y.jsx("pre",{className:"text-[11px] font-mono text-zinc-400 whitespace-pre-wrap leading-relaxed overflow-x-auto rounded-lg p-2 mt-1 bg-black/20",children:v.content}):y.jsx(Mu,{content:v.content,className:"text-[12px] [&_pre]:text-[10px]"})]})]},v.id)})})]})]})}const e9={thought:{label:"Thinking",icon:n1,color:"#a78bfa",bg:"rgba(167,139,250,0.1)"},tool_call:{label:"Tool Call",icon:UP,color:"#38bdf8",bg:"rgba(56,189,248,0.1)"},tool_result:{label:"Tool Result",icon:MP,color:"#34d399",bg:"rgba(52,211,153,0.1)"},message:{label:"Message",icon:qc,color:"#E43A9C",bg:"rgba(228,58,156,0.15)"},decision:{label:"Decision",icon:t1,color:"#fbbf24",bg:"rgba(251,191,36,0.1)"},meeting:{label:"Meeting",icon:a1,color:"#818cf8",bg:"rgba(129,140,248,0.1)"}};function t9(t){const e=t.toLowerCase();return e.includes("meeting")?"meeting":e.includes("tool_call")||e.includes("tool-call")?"tool_call":e.includes("tool_result")||e.includes("tool-result")?"tool_result":e.includes("thought")||e.includes("thinking")||e.includes("reason")?"thought":e.includes("decision")?"decision":"message"}function r9({squadName:t,instanceId:e}){const[r,n]=j.useState(null),[i,a]=j.useState([]),[o,c]=j.useState(null),[u,d]=j.useState("running"),[p,f]=j.useState(0),m=gl(),v=Fa(),b=j.useRef(null),w=j.useRef(null),x=j.useRef(!0),k=j.useCallback(()=>{const $=b.current;if(!$)return;const W=100;x.current=$.scrollHeight-$.scrollTop-$.clientHeight<W,x.current&&f(0)},[]);if(j.useEffect(()=>{Ge.get(`/squads/${t}/instances/${e}`).then($=>{n($),d($.instance.status)}).catch(()=>{Qe.error("Failed to load instance")})},[t,e]),o1({onEvent:$=>{if(!$.event)return;const W=$.event;if((W.type==="instance:completed"||W.type==="instance:failed"||W.type==="instance.completed"||W.type==="instance.failed")&&W.instanceId===e){d(W.type==="instance:completed"||W.type==="instance.completed"?"completed":"failed");return}if((W.type.startsWith("agent:")||W.type.startsWith("agent."))&&W.instanceId===e){const z=W.data,U=(z==null?void 0:z.tool)||null,F=typeof(z==null?void 0:z.success)=="boolean"?z.success:null;let X="";if(U&&(z!=null&&z.arguments)){const G=z.arguments;if(typeof G=="string")X=G;else if(typeof G=="object"&&G!==null){const Z=G;Z.command?X=String(Z.command):X=JSON.stringify(G,null,2)}}else z!=null&&z.result?X=String(z.result):z!=null&&z.error?X=String(z.error):X=(z==null?void 0:z.content)||"";try{const G=JSON.parse(X);typeof G=="object"&&G!==null&&(X=G.message??G.content??G.response??G.decision??JSON.stringify(G,null,2))}catch{}const Y={id:W.id,agent:W.agentRole||(z==null?void 0:z.agentRole)||"unknown",type:W.type.replace(/^agent[:.]/,""),content:X,toolName:U,success:F,model:W.model||(z==null?void 0:z.model)||null,tokensUsed:null,timestamp:W.timestamp};a(G=>[...G,Y]),x.current?setTimeout(()=>{var G;return(G=w.current)==null?void 0:G.scrollIntoView({behavior:"smooth"})},50):f(G=>G+1)}}}),!r)return y.jsx("div",{className:"h-full flex items-center justify-center text-zinc-600",children:"Loading..."});const S=r.squadColor||"#38bdf8",A=[...r.activity,...i],C=Array.from(new Map(A.map($=>[$.id,$])).values());C.sort(($,W)=>$.timestamp.localeCompare(W.timestamp));const T=o?C.filter($=>$.agent===o):C,O=[...new Set(C.map($=>$.agent))],N={};for(const $ of O)N[$]=Df($);const R=u==="running"||u==="working"||u==="meeting"||u==="planning";return y.jsxs("div",{ref:b,onScroll:k,className:"flex-1 overflow-y-auto p-6",style:{background:`${S}06`},children:[y.jsxs("button",{type:"button",onClick:()=>m(`/squads/${t}`),className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," Back to ",t]}),y.jsxs("div",{className:"flex items-start justify-between mb-5",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide",style:{fontFamily:"'Bebas Neue', sans-serif",color:S},children:"Instance"}),y.jsx("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:r.instance.id.slice(0,8)}),r.instance.branch&&y.jsx("p",{className:"text-[11px] text-zinc-700 font-mono mt-0.5",children:r.instance.branch})]}),y.jsx(Rt,{variant:Ms(u),children:u})]}),y.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[r.members.map($=>{const W=$.roleName||$.role,z=N[W]||Df(W),U=o===W;return y.jsxs("button",{type:"button",onClick:()=>c(U?null:W),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-xl border transition-all cursor-pointer",style:{borderColor:U?z:`${z}30`,background:U?`${z}25`:`${z}10`,opacity:o&&!U?.5:1},children:[Hs(W,z),y.jsx("span",{className:"text-[11px] font-mono",style:{color:z},children:$.displayName}),y.jsx(Rt,{variant:Ms($.status),children:$.status}),$.status==="working"&&y.jsx("button",{type:"button",onClick:async F=>{F.stopPropagation();try{await Ge.post(`/squads/${t}/instances/${e}/cancel`),Qe.success("Instance cancelled")}catch{Qe.error("Failed to cancel instance")}},title:"Cancel instance",className:"ml-1 p-1 rounded-lg hover:bg-red-500/10 text-zinc-600 hover:text-red-400 transition-colors cursor-pointer",children:y.jsx(dp,{className:"w-3 h-3"})})]},$.id)}),o&&y.jsx("button",{type:"button",onClick:()=>c(null),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-xl border border-white/[0.1] text-[11px] font-mono text-zinc-400 hover:text-zinc-200 transition-colors cursor-pointer",children:"Show all"})]}),y.jsxs("div",{className:"relative pl-10",children:[y.jsx("div",{className:"absolute left-[15px] top-0 bottom-0 w-px bg-white/[0.06]"}),y.jsxs("div",{className:"space-y-3",children:[T.length===0&&y.jsx("div",{className:"text-center py-12 text-zinc-700 font-mono text-sm",children:"No activity recorded yet"}),T.map($=>{const W=t9($.type),z=e9[W],U=z.icon,F=N[$.agent]||Df($.agent),X=W==="tool_call"||W==="tool_result",Y=$.type.toLowerCase().includes("error")||$.type.toLowerCase().includes("fail");return y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:"absolute -left-10 top-3 w-[30px] h-[30px] rounded-full flex items-center justify-center",style:{background:`${F}15`,border:`1px solid ${F}35`},children:y.jsx(U,{className:"w-3.5 h-3.5",style:{color:F}})}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[y.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[y.jsxs("div",{className:"flex items-center gap-1",children:[Hs($.agent,F),y.jsx("span",{className:"text-[10px] font-mono",style:{color:F},children:$.agent})]}),y.jsx("span",{className:"text-zinc-700 text-[10px]",children:"·"}),y.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wider text-zinc-500",children:z.label}),$.toolName&&y.jsx("span",{className:"text-[10px] font-mono text-sky-400 border border-sky-400/20 rounded px-1.5 py-px bg-sky-400/[0.06]",children:$.toolName}),$.model&&y.jsx("span",{className:"text-[10px] font-mono text-zinc-600 border border-white/[0.08] rounded px-1.5 py-px bg-white/[0.03]",children:$.model}),$.success===!0&&y.jsx("span",{className:"text-[10px] font-mono text-emerald-400 border border-emerald-400/20 rounded px-1.5 py-px bg-emerald-400/[0.08]",children:"success"}),$.success===!1&&y.jsx("span",{className:"text-[10px] font-mono text-red-400 border border-red-400/20 rounded px-1.5 py-px bg-red-400/[0.08]",children:"failed"}),Y&&$.success===null&&y.jsx(Rt,{variant:"error",children:"failed"})]}),y.jsx("span",{className:"text-[10px] font-mono text-zinc-700 flex-shrink-0 ml-2",children:cp($.timestamp,v)})]}),X?y.jsx("pre",{className:"text-[11px] font-mono text-zinc-400 whitespace-pre-wrap leading-relaxed overflow-x-auto rounded-lg p-2 mt-1 bg-black/20",children:$.content}):y.jsx(Mu,{content:$.content,className:"text-[12px] [&_pre]:text-[10px]"})]})]},$.id)}),R&&y.jsxs("div",{className:"relative",children:[y.jsx("div",{className:"absolute -left-10 top-3 w-[30px] h-[30px] rounded-full flex items-center justify-center",style:{background:`${S}15`,border:`1px solid ${S}40`},children:y.jsx(DP,{className:"w-3.5 h-3.5 animate-spin",style:{color:S}})}),y.jsx("div",{className:"glass-card border rounded-2xl px-4 py-3",style:{borderColor:`${S}20`},children:y.jsx("span",{className:"text-[11px] font-mono",style:{color:S},children:"Working…"})})]})]})]}),y.jsx("div",{ref:w}),p>0&&y.jsxs("button",{type:"button",onClick:()=>{var $;($=w.current)==null||$.scrollIntoView({behavior:"smooth"}),f(0)},className:"fixed bottom-6 left-1/2 -translate-x-1/2 flex items-center gap-1.5 px-4 py-2 rounded-full border border-white/[0.1] bg-zinc-900/90 backdrop-blur-sm text-[11px] font-mono text-zinc-300 hover:text-white shadow-lg transition-all cursor-pointer z-50",children:[y.jsx(cz,{className:"w-3.5 h-3.5"}),p," new event",p!==1?"s":""]})]})}function n9({squadName:t,role:e}){const r=gl(),[n,i]=j.useState(null),[a,o]=j.useState(!1),[c,u]=j.useState(""),[d,p]=j.useState(""),[f,m]=j.useState(!1);j.useEffect(()=>{Ge.get(`/squads/${t}`).then(b=>{const w=b.members.find(x=>x.role===e);w&&i(w)}).catch(()=>{})},[t,e]);const v=async()=>{if(n){m(!0);try{const b=await Ge.put(`/squads/${n.squadId}/members/${n.id}`,{systemPrompt:c,model:d});i(b),o(!1),Qe.success("Agent updated")}catch{Qe.error("Failed to save agent")}finally{m(!1)}}};return n?y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[y.jsxs("button",{type:"button",onClick:()=>r(`/squads/${t}`),className:"flex items-center gap-1.5 text-[11px] text-zinc-600 hover:text-zinc-300 font-mono mb-5 transition-colors cursor-pointer",children:[y.jsx(vl,{className:"w-3.5 h-3.5"})," Back to ",t]}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-5 mb-5",children:[y.jsxs("div",{className:"flex items-center gap-3",children:[y.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center border border-white/[0.1] bg-white/[0.04]",children:Hs(n.role,"#38bdf8")}),y.jsxs("div",{className:"flex-1",children:[y.jsx("h2",{className:"text-xl tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:n.name}),y.jsx("span",{className:"text-[11px] font-mono text-zinc-500",children:n.role})]})]}),!a&&y.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[y.jsx("span",{className:"text-[10px] font-mono text-zinc-600",children:"MODEL:"}),y.jsx("span",{className:"text-[11px] font-mono text-zinc-400",children:n.model||"default"})]})]}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-5",children:[y.jsxs("div",{className:"flex items-center justify-between mb-4",children:[y.jsx("h3",{className:"text-sm font-mono text-zinc-300",children:"System Prompt"}),a?y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("button",{type:"button",onClick:()=>o(!1),className:"px-3 py-1.5 rounded-lg text-[11px] font-mono text-zinc-500 hover:text-zinc-300 border border-white/[0.1] transition-colors cursor-pointer",children:"Cancel"}),y.jsxs("button",{type:"button",onClick:v,disabled:f,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[11px] font-mono text-emerald-400 border border-emerald-400/30 hover:bg-emerald-400/10 transition-colors cursor-pointer disabled:opacity-50",children:[y.jsx(up,{className:"w-3 h-3"})," ",f?"Saving...":"Save"]})]}):y.jsxs("button",{type:"button",onClick:()=>{u(n.systemPrompt),p(n.model||""),o(!0)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[11px] font-mono text-zinc-400 hover:text-zinc-200 border border-white/[0.1] hover:border-white/[0.2] transition-colors cursor-pointer",children:[y.jsx(Wf,{className:"w-3 h-3"})," Edit"]})]}),a?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mb-4",children:[y.jsx("label",{className:"block text-[10px] font-mono text-zinc-600 mb-1.5",children:"MODEL OVERRIDE (leave empty for default)"}),y.jsx("input",{type:"text",value:d,onChange:b=>p(b.target.value),placeholder:"e.g. claude-sonnet-4.5",className:"w-full bg-black/30 border border-white/[0.08] rounded-lg px-3 py-2 text-[12px] font-mono text-zinc-300 focus:outline-none focus:border-white/[0.2] placeholder:text-zinc-700"})]}),y.jsx("textarea",{value:c,onChange:b=>u(b.target.value),className:"w-full h-[500px] bg-black/30 border border-white/[0.08] rounded-xl p-4 text-[12px] font-mono text-zinc-300 resize-y focus:outline-none focus:border-white/[0.2] leading-relaxed",spellCheck:!1})]}):n.systemPrompt?y.jsx(Mu,{content:n.systemPrompt,className:"text-[12px] [&_pre]:text-[11px]"}):y.jsx("p",{className:"text-zinc-700 text-[12px] font-mono py-8 text-center",children:"No system prompt configured for this agent"})]})]}):y.jsx("div",{className:"h-full flex items-center justify-center text-zinc-600",children:"Loading..."})}var Kg,eA;function Qr(){if(eA)return Kg;eA=1;var t=Array.isArray;return Kg=t,Kg}var Gg,tA;function NR(){if(tA)return Gg;tA=1;var t=typeof tf=="object"&&tf&&tf.Object===Object&&tf;return Gg=t,Gg}var Vg,rA;function Ai(){if(rA)return Vg;rA=1;var t=NR(),e=typeof self=="object"&&self&&self.Object===Object&&self,r=t||e||Function("return this")();return Vg=r,Vg}var Xg,nA;function Lu(){if(nA)return Xg;nA=1;var t=Ai(),e=t.Symbol;return Xg=e,Xg}var Yg,iA;function i9(){if(iA)return Yg;iA=1;var t=Lu(),e=Object.prototype,r=e.hasOwnProperty,n=e.toString,i=t?t.toStringTag:void 0;function a(o){var c=r.call(o,i),u=o[i];try{o[i]=void 0;var d=!0}catch{}var p=n.call(o);return d&&(c?o[i]=u:delete o[i]),p}return Yg=a,Yg}var Jg,aA;function a9(){if(aA)return Jg;aA=1;var t=Object.prototype,e=t.toString;function r(n){return e.call(n)}return Jg=r,Jg}var Zg,oA;function ra(){if(oA)return Zg;oA=1;var t=Lu(),e=i9(),r=a9(),n="[object Null]",i="[object Undefined]",a=t?t.toStringTag:void 0;function o(c){return c==null?c===void 0?i:n:a&&a in Object(c)?e(c):r(c)}return Zg=o,Zg}var Qg,sA;function na(){if(sA)return Qg;sA=1;function t(e){return e!=null&&typeof e=="object"}return Qg=t,Qg}var ey,lA;function xl(){if(lA)return ey;lA=1;var t=ra(),e=na(),r="[object Symbol]";function n(i){return typeof i=="symbol"||e(i)&&t(i)==r}return ey=n,ey}var ty,cA;function d1(){if(cA)return ty;cA=1;var t=Qr(),e=xl(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function i(a,o){if(t(a))return!1;var c=typeof a;return c=="number"||c=="symbol"||c=="boolean"||a==null||e(a)?!0:n.test(a)||!r.test(a)||o!=null&&a in Object(o)}return ty=i,ty}var ry,uA;function Wa(){if(uA)return ry;uA=1;function t(e){var r=typeof e;return e!=null&&(r=="object"||r=="function")}return ry=t,ry}var ny,dA;function f1(){if(dA)return ny;dA=1;var t=ra(),e=Wa(),r="[object AsyncFunction]",n="[object Function]",i="[object GeneratorFunction]",a="[object Proxy]";function o(c){if(!e(c))return!1;var u=t(c);return u==n||u==i||u==r||u==a}return ny=o,ny}var iy,fA;function o9(){if(fA)return iy;fA=1;var t=Ai(),e=t["__core-js_shared__"];return iy=e,iy}var ay,hA;function s9(){if(hA)return ay;hA=1;var t=o9(),e=(function(){var n=/[^.]+$/.exec(t&&t.keys&&t.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})();function r(n){return!!e&&e in n}return ay=r,ay}var oy,pA;function PR(){if(pA)return oy;pA=1;var t=Function.prototype,e=t.toString;function r(n){if(n!=null){try{return e.call(n)}catch{}try{return n+""}catch{}}return""}return oy=r,oy}var sy,mA;function l9(){if(mA)return sy;mA=1;var t=f1(),e=s9(),r=Wa(),n=PR(),i=/[\\^$.*+?()[\]{}|]/g,a=/^\[object .+?Constructor\]$/,o=Function.prototype,c=Object.prototype,u=o.toString,d=c.hasOwnProperty,p=RegExp("^"+u.call(d).replace(i,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function f(m){if(!r(m)||e(m))return!1;var v=t(m)?p:a;return v.test(n(m))}return sy=f,sy}var ly,gA;function c9(){if(gA)return ly;gA=1;function t(e,r){return e==null?void 0:e[r]}return ly=t,ly}var cy,yA;function Uo(){if(yA)return cy;yA=1;var t=l9(),e=c9();function r(n,i){var a=e(n,i);return t(a)?a:void 0}return cy=r,cy}var uy,vA;function yp(){if(vA)return uy;vA=1;var t=Uo(),e=t(Object,"create");return uy=e,uy}var dy,bA;function u9(){if(bA)return dy;bA=1;var t=yp();function e(){this.__data__=t?t(null):{},this.size=0}return dy=e,dy}var fy,xA;function d9(){if(xA)return fy;xA=1;function t(e){var r=this.has(e)&&delete this.__data__[e];return this.size-=r?1:0,r}return fy=t,fy}var hy,wA;function f9(){if(wA)return hy;wA=1;var t=yp(),e="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function i(a){var o=this.__data__;if(t){var c=o[a];return c===e?void 0:c}return n.call(o,a)?o[a]:void 0}return hy=i,hy}var py,_A;function h9(){if(_A)return py;_A=1;var t=yp(),e=Object.prototype,r=e.hasOwnProperty;function n(i){var a=this.__data__;return t?a[i]!==void 0:r.call(a,i)}return py=n,py}var my,SA;function p9(){if(SA)return my;SA=1;var t=yp(),e="__lodash_hash_undefined__";function r(n,i){var a=this.__data__;return this.size+=this.has(n)?0:1,a[n]=t&&i===void 0?e:i,this}return my=r,my}var gy,kA;function m9(){if(kA)return gy;kA=1;var t=u9(),e=d9(),r=f9(),n=h9(),i=p9();function a(o){var c=-1,u=o==null?0:o.length;for(this.clear();++c<u;){var d=o[c];this.set(d[0],d[1])}}return a.prototype.clear=t,a.prototype.delete=e,a.prototype.get=r,a.prototype.has=n,a.prototype.set=i,gy=a,gy}var yy,EA;function g9(){if(EA)return yy;EA=1;function t(){this.__data__=[],this.size=0}return yy=t,yy}var vy,AA;function h1(){if(AA)return vy;AA=1;function t(e,r){return e===r||e!==e&&r!==r}return vy=t,vy}var by,OA;function vp(){if(OA)return by;OA=1;var t=h1();function e(r,n){for(var i=r.length;i--;)if(t(r[i][0],n))return i;return-1}return by=e,by}var xy,TA;function y9(){if(TA)return xy;TA=1;var t=vp(),e=Array.prototype,r=e.splice;function n(i){var a=this.__data__,o=t(a,i);if(o<0)return!1;var c=a.length-1;return o==c?a.pop():r.call(a,o,1),--this.size,!0}return xy=n,xy}var wy,CA;function v9(){if(CA)return wy;CA=1;var t=vp();function e(r){var n=this.__data__,i=t(n,r);return i<0?void 0:n[i][1]}return wy=e,wy}var _y,jA;function b9(){if(jA)return _y;jA=1;var t=vp();function e(r){return t(this.__data__,r)>-1}return _y=e,_y}var Sy,NA;function x9(){if(NA)return Sy;NA=1;var t=vp();function e(r,n){var i=this.__data__,a=t(i,r);return a<0?(++this.size,i.push([r,n])):i[a][1]=n,this}return Sy=e,Sy}var ky,PA;function bp(){if(PA)return ky;PA=1;var t=g9(),e=y9(),r=v9(),n=b9(),i=x9();function a(o){var c=-1,u=o==null?0:o.length;for(this.clear();++c<u;){var d=o[c];this.set(d[0],d[1])}}return a.prototype.clear=t,a.prototype.delete=e,a.prototype.get=r,a.prototype.has=n,a.prototype.set=i,ky=a,ky}var Ey,RA;function p1(){if(RA)return Ey;RA=1;var t=Uo(),e=Ai(),r=t(e,"Map");return Ey=r,Ey}var Ay,IA;function w9(){if(IA)return Ay;IA=1;var t=m9(),e=bp(),r=p1();function n(){this.size=0,this.__data__={hash:new t,map:new(r||e),string:new t}}return Ay=n,Ay}var Oy,$A;function _9(){if($A)return Oy;$A=1;function t(e){var r=typeof e;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?e!=="__proto__":e===null}return Oy=t,Oy}var Ty,MA;function xp(){if(MA)return Ty;MA=1;var t=_9();function e(r,n){var i=r.__data__;return t(n)?i[typeof n=="string"?"string":"hash"]:i.map}return Ty=e,Ty}var Cy,DA;function S9(){if(DA)return Cy;DA=1;var t=xp();function e(r){var n=t(this,r).delete(r);return this.size-=n?1:0,n}return Cy=e,Cy}var jy,LA;function k9(){if(LA)return jy;LA=1;var t=xp();function e(r){return t(this,r).get(r)}return jy=e,jy}var Ny,zA;function E9(){if(zA)return Ny;zA=1;var t=xp();function e(r){return t(this,r).has(r)}return Ny=e,Ny}var Py,BA;function A9(){if(BA)return Py;BA=1;var t=xp();function e(r,n){var i=t(this,r),a=i.size;return i.set(r,n),this.size+=i.size==a?0:1,this}return Py=e,Py}var Ry,UA;function m1(){if(UA)return Ry;UA=1;var t=w9(),e=S9(),r=k9(),n=E9(),i=A9();function a(o){var c=-1,u=o==null?0:o.length;for(this.clear();++c<u;){var d=o[c];this.set(d[0],d[1])}}return a.prototype.clear=t,a.prototype.delete=e,a.prototype.get=r,a.prototype.has=n,a.prototype.set=i,Ry=a,Ry}var Iy,qA;function RR(){if(qA)return Iy;qA=1;var t=m1(),e="Expected a function";function r(n,i){if(typeof n!="function"||i!=null&&typeof i!="function")throw new TypeError(e);var a=function(){var o=arguments,c=i?i.apply(this,o):o[0],u=a.cache;if(u.has(c))return u.get(c);var d=n.apply(this,o);return a.cache=u.set(c,d)||u,d};return a.cache=new(r.Cache||t),a}return r.Cache=t,Iy=r,Iy}var $y,FA;function O9(){if(FA)return $y;FA=1;var t=RR(),e=500;function r(n){var i=t(n,function(o){return a.size===e&&a.clear(),o}),a=i.cache;return i}return $y=r,$y}var My,HA;function T9(){if(HA)return My;HA=1;var t=O9(),e=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=t(function(i){var a=[];return i.charCodeAt(0)===46&&a.push(""),i.replace(e,function(o,c,u,d){a.push(u?d.replace(r,"$1"):c||o)}),a});return My=n,My}var Dy,WA;function g1(){if(WA)return Dy;WA=1;function t(e,r){for(var n=-1,i=e==null?0:e.length,a=Array(i);++n<i;)a[n]=r(e[n],n,e);return a}return Dy=t,Dy}var Ly,KA;function C9(){if(KA)return Ly;KA=1;var t=Lu(),e=g1(),r=Qr(),n=xl(),i=t?t.prototype:void 0,a=i?i.toString:void 0;function o(c){if(typeof c=="string")return c;if(r(c))return e(c,o)+"";if(n(c))return a?a.call(c):"";var u=c+"";return u=="0"&&1/c==-1/0?"-0":u}return Ly=o,Ly}var zy,GA;function IR(){if(GA)return zy;GA=1;var t=C9();function e(r){return r==null?"":t(r)}return zy=e,zy}var By,VA;function $R(){if(VA)return By;VA=1;var t=Qr(),e=d1(),r=T9(),n=IR();function i(a,o){return t(a)?a:e(a,o)?[a]:r(n(a))}return By=i,By}var Uy,XA;function wp(){if(XA)return Uy;XA=1;var t=xl();function e(r){if(typeof r=="string"||t(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return Uy=e,Uy}var qy,YA;function y1(){if(YA)return qy;YA=1;var t=$R(),e=wp();function r(n,i){i=t(i,n);for(var a=0,o=i.length;n!=null&&a<o;)n=n[e(i[a++])];return a&&a==o?n:void 0}return qy=r,qy}var Fy,JA;function MR(){if(JA)return Fy;JA=1;var t=y1();function e(r,n,i){var a=r==null?void 0:t(r,n);return a===void 0?i:a}return Fy=e,Fy}var j9=MR();const On=vt(j9);var Hy,ZA;function N9(){if(ZA)return Hy;ZA=1;function t(e){return e==null}return Hy=t,Hy}var P9=N9();const tt=vt(P9);var Wy,QA;function R9(){if(QA)return Wy;QA=1;var t=ra(),e=Qr(),r=na(),n="[object String]";function i(a){return typeof a=="string"||!e(a)&&r(a)&&t(a)==n}return Wy=i,Wy}var I9=R9();const Ro=vt(I9);var $9=f1();const Je=vt($9);var M9=Wa();const wl=vt(M9);var Ky={exports:{}},pt={};/**
450
450
  * @license React
451
451
  * react-is.production.min.js
452
452
  *
@@ -517,4 +517,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
517
517
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function RM(t,e){if(t){if(typeof t=="string")return jw(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);if(r==="Object"&&t.constructor&&(r=t.constructor.name),r==="Map"||r==="Set")return Array.from(t);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return jw(t,e)}}function zne(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Bne(t){if(Array.isArray(t))return jw(t)}function jw(t,e){(e==null||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function RN(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),r.push.apply(r,n)}return r}function ie(t){for(var e=1;e<arguments.length;e++){var r=arguments[e]!=null?arguments[e]:{};e%2?RN(Object(r),!0).forEach(function(n){ze(t,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):RN(Object(r)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(r,n))})}return t}function ze(t,e,r){return e=IM(e),e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function IM(t){var e=Une(t,"string");return dl(e)=="symbol"?e:e+""}function Une(t,e){if(dl(t)!="object"||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var n=r.call(t,e);if(dl(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var qne={xAxis:["bottom","top"],yAxis:["left","right"]},Fne={width:"100%",height:"100%"},$M={x:0,y:0};function Nf(t){return t}var Hne=function(e,r){return r==="horizontal"?e.x:r==="vertical"?e.y:r==="centric"?e.angle:e.radius},Wne=function(e,r,n,i){var a=r.find(function(p){return p&&p.index===n});if(a){if(e==="horizontal")return{x:a.coordinate,y:i.y};if(e==="vertical")return{x:i.x,y:a.coordinate};if(e==="centric"){var o=a.coordinate,c=i.radius;return ie(ie(ie({},i),wr(i.cx,i.cy,c,o)),{},{angle:o,radius:c})}var u=a.coordinate,d=i.angle;return ie(ie(ie({},i),wr(i.cx,i.cy,u,d)),{},{angle:d,radius:u})}return $M},Gp=function(e,r){var n=r.graphicalItems,i=r.dataStartIndex,a=r.dataEndIndex,o=(n??[]).reduce(function(c,u){var d=u.props.data;return d&&d.length?[].concat(fl(c),fl(d)):c},[]);return o.length>0?o:e&&e.length&&ge(i)&&ge(a)?e.slice(i,a+1):[]};function MM(t){return t==="number"?[0,"auto"]:void 0}var Nw=function(e,r,n,i){var a=e.graphicalItems,o=e.tooltipAxis,c=Gp(r,e);return n<0||!a||!a.length||n>=c.length?null:a.reduce(function(u,d){var p,f=(p=d.props.data)!==null&&p!==void 0?p:r;f&&e.dataStartIndex+e.dataEndIndex!==0&&e.dataEndIndex-e.dataStartIndex>=n&&(f=f.slice(e.dataStartIndex,e.dataEndIndex+1));var m;if(o.dataKey&&!o.allowDuplicatedCategory){var v=f===void 0?c:f;m=ih(v,o.dataKey,i)}else m=f&&f[n]||c[n];return m?[].concat(fl(u),[M$(d,m)]):u},[])},IN=function(e,r,n,i){var a=i||{x:e.chartX,y:e.chartY},o=Hne(a,n),c=e.orderedTooltipTicks,u=e.tooltipAxis,d=e.tooltipTicks,p=tY(o,c,d,u);if(p>=0&&d){var f=d[p]&&d[p].value,m=Nw(e,r,p,f),v=Wne(n,c,p,a);return{activeTooltipIndex:p,activeLabel:f,activePayload:m,activeCoordinate:v}}return null},Kne=function(e,r){var n=r.axes,i=r.graphicalItems,a=r.axisType,o=r.axisIdKey,c=r.stackGroups,u=r.dataStartIndex,d=r.dataEndIndex,p=e.layout,f=e.children,m=e.stackOffset,v=R$(p,a);return n.reduce(function(b,w){var x,k=w.type.defaultProps!==void 0?ie(ie({},w.type.defaultProps),w.props):w.props,S=k.type,A=k.dataKey,C=k.allowDataOverflow,T=k.allowDuplicatedCategory,O=k.scale,N=k.ticks,R=k.includeHidden,$=k[o];if(b[$])return b;var W=Gp(e.data,{graphicalItems:i.filter(function(q){var Q,le=o in q.props?q.props[o]:(Q=q.type.defaultProps)===null||Q===void 0?void 0:Q[o];return le===$}),dataStartIndex:u,dataEndIndex:d}),z=W.length,U,F,X;vne(k.domain,C,S)&&(U=Vx(k.domain,null,C),v&&(S==="number"||O!=="auto")&&(X=Lc(W,A,"category")));var Y=MM(S);if(!U||U.length===0){var G,Z=(G=k.domain)!==null&&G!==void 0?G:Y;if(A){if(U=Lc(W,A,S),S==="category"&&v){var K=K9(U);T&&K?(F=U,U=Fh(0,z)):T||(U=Vj(Z,U,w).reduce(function(q,Q){return q.indexOf(Q)>=0?q:[].concat(fl(q),[Q])},[]))}else if(S==="category")T?U=U.filter(function(q){return q!==""&&!tt(q)}):U=Vj(Z,U,w).reduce(function(q,Q){return q.indexOf(Q)>=0||Q===""||tt(Q)?q:[].concat(fl(q),[Q])},[]);else if(S==="number"){var ee=oY(W,i.filter(function(q){var Q,le,fe=o in q.props?q.props[o]:(Q=q.type.defaultProps)===null||Q===void 0?void 0:Q[o],ve="hide"in q.props?q.props.hide:(le=q.type.defaultProps)===null||le===void 0?void 0:le.hide;return fe===$&&(R||!ve)}),A,a,p);ee&&(U=ee)}v&&(S==="number"||O!=="auto")&&(X=Lc(W,A,"category"))}else v?U=Fh(0,z):c&&c[$]&&c[$].hasStack&&S==="number"?U=m==="expand"?[0,1]:$$(c[$].stackGroups,u,d):U=P$(W,i.filter(function(q){var Q=o in q.props?q.props[o]:q.type.defaultProps[o],le="hide"in q.props?q.props.hide:q.type.defaultProps.hide;return Q===$&&(R||!le)}),S,p,!0);if(S==="number")U=Tw(f,U,$,a,N),Z&&(U=Vx(Z,U,C));else if(S==="category"&&Z){var L=Z,I=U.every(function(q){return L.indexOf(q)>=0});I&&(U=L)}}return ie(ie({},b),{},ze({},$,ie(ie({},k),{},{axisType:a,domain:U,categoricalDomain:X,duplicateDomain:F,originalDomain:(x=k.domain)!==null&&x!==void 0?x:Y,isCategorical:v,layout:p})))},{})},Gne=function(e,r){var n=r.graphicalItems,i=r.Axis,a=r.axisType,o=r.axisIdKey,c=r.stackGroups,u=r.dataStartIndex,d=r.dataEndIndex,p=e.layout,f=e.children,m=Gp(e.data,{graphicalItems:n,dataStartIndex:u,dataEndIndex:d}),v=m.length,b=R$(p,a),w=-1;return n.reduce(function(x,k){var S=k.type.defaultProps!==void 0?ie(ie({},k.type.defaultProps),k.props):k.props,A=S[o],C=MM("number");if(!x[A]){w++;var T;return b?T=Fh(0,v):c&&c[A]&&c[A].hasStack?(T=$$(c[A].stackGroups,u,d),T=Tw(f,T,A,a)):(T=Vx(C,P$(m,n.filter(function(O){var N,R,$=o in O.props?O.props[o]:(N=O.type.defaultProps)===null||N===void 0?void 0:N[o],W="hide"in O.props?O.props.hide:(R=O.type.defaultProps)===null||R===void 0?void 0:R.hide;return $===A&&!W}),"number",p),i.defaultProps.allowDataOverflow),T=Tw(f,T,A,a)),ie(ie({},x),{},ze({},A,ie(ie({axisType:a},i.defaultProps),{},{hide:!0,orientation:On(qne,"".concat(a,".").concat(w%2),null),domain:T,originalDomain:C,isCategorical:b,layout:p})))}return x},{})},Vne=function(e,r){var n=r.axisType,i=n===void 0?"xAxis":n,a=r.AxisComp,o=r.graphicalItems,c=r.stackGroups,u=r.dataStartIndex,d=r.dataEndIndex,p=e.children,f="".concat(i,"Id"),m=Tn(p,a),v={};return m&&m.length?v=Kne(e,{axes:m,graphicalItems:o,axisType:i,axisIdKey:f,stackGroups:c,dataStartIndex:u,dataEndIndex:d}):o&&o.length&&(v=Gne(e,{Axis:a,graphicalItems:o,axisType:i,axisIdKey:f,stackGroups:c,dataStartIndex:u,dataEndIndex:d})),v},Xne=function(e){var r=Ra(e),n=Ki(r,!1,!0);return{tooltipTicks:n,orderedTooltipTicks:N1(n,function(i){return i.coordinate}),tooltipAxis:r,tooltipAxisBandSize:Rh(r,n)}},$N=function(e){var r=e.children,n=e.defaultShowTooltip,i=sn(r,rl),a=0,o=0;return e.data&&e.data.length!==0&&(o=e.data.length-1),i&&i.props&&(i.props.startIndex>=0&&(a=i.props.startIndex),i.props.endIndex>=0&&(o=i.props.endIndex)),{chartX:0,chartY:0,dataStartIndex:a,dataEndIndex:o,activeTooltipIndex:-1,isTooltipActive:!!n}},Yne=function(e){return!e||!e.length?!1:e.some(function(r){var n=Gi(r&&r.type);return n&&n.indexOf("Bar")>=0})},MN=function(e){return e==="horizontal"?{numericAxisName:"yAxis",cateAxisName:"xAxis"}:e==="vertical"?{numericAxisName:"xAxis",cateAxisName:"yAxis"}:e==="centric"?{numericAxisName:"radiusAxis",cateAxisName:"angleAxis"}:{numericAxisName:"angleAxis",cateAxisName:"radiusAxis"}},Jne=function(e,r){var n=e.props,i=e.graphicalItems,a=e.xAxisMap,o=a===void 0?{}:a,c=e.yAxisMap,u=c===void 0?{}:c,d=n.width,p=n.height,f=n.children,m=n.margin||{},v=sn(f,rl),b=sn(f,Bs),w=Object.keys(u).reduce(function(T,O){var N=u[O],R=N.orientation;return!N.mirror&&!N.hide?ie(ie({},T),{},ze({},R,T[R]+N.width)):T},{left:m.left||0,right:m.right||0}),x=Object.keys(o).reduce(function(T,O){var N=o[O],R=N.orientation;return!N.mirror&&!N.hide?ie(ie({},T),{},ze({},R,On(T,"".concat(R))+N.height)):T},{top:m.top||0,bottom:m.bottom||0}),k=ie(ie({},x),w),S=k.bottom;v&&(k.bottom+=v.props.height||rl.defaultProps.height),b&&r&&(k=iY(k,i,n,r));var A=d-k.left-k.right,C=p-k.top-k.bottom;return ie(ie({brushBottom:S},k),{},{width:Math.max(A,0),height:Math.max(C,0)})},Zne=function(e,r){if(r==="xAxis")return e[r].width;if(r==="yAxis")return e[r].height},DM=function(e){var r=e.chartName,n=e.GraphicalChild,i=e.defaultTooltipEventType,a=i===void 0?"axis":i,o=e.validateTooltipEventTypes,c=o===void 0?["axis"]:o,u=e.axisComponents,d=e.legendContent,p=e.formatAxisMap,f=e.defaultProps,m=function(k,S){var A=S.graphicalItems,C=S.stackGroups,T=S.offset,O=S.updateId,N=S.dataStartIndex,R=S.dataEndIndex,$=k.barSize,W=k.layout,z=k.barGap,U=k.barCategoryGap,F=k.maxBarSize,X=MN(W),Y=X.numericAxisName,G=X.cateAxisName,Z=Yne(A),K=[];return A.forEach(function(ee,L){var I=Gp(k.data,{graphicalItems:[ee],dataStartIndex:N,dataEndIndex:R}),q=ee.type.defaultProps!==void 0?ie(ie({},ee.type.defaultProps),ee.props):ee.props,Q=q.dataKey,le=q.maxBarSize,fe=q["".concat(Y,"Id")],ve=q["".concat(G,"Id")],qe={},xe=u.reduce(function(cr,_t){var Sr=S["".concat(_t.axisType,"Map")],Ir=q["".concat(_t.axisType,"Id")];Sr&&Sr[Ir]||_t.axisType==="zAxis"||Mo();var ni=Sr[Ir];return ie(ie({},cr),{},ze(ze({},_t.axisType,ni),"".concat(_t.axisType,"Ticks"),Ki(ni)))},qe),ae=xe[G],Se=xe["".concat(G,"Ticks")],Me=C&&C[fe]&&C[fe].hasStack&&vY(ee,C[fe].stackGroups),oe=Gi(ee.type).indexOf("Bar")>=0,rt=Rh(ae,Se),Fe=[],kt=Z&&rY({barSize:$,stackGroups:C,totalSize:Zne(xe,G)});if(oe){var wt,Et,_r=tt(le)?F:le,Ut=(wt=(Et=Rh(ae,Se,!0))!==null&&Et!==void 0?Et:_r)!==null&&wt!==void 0?wt:0;Fe=nY({barGap:z,barCategoryGap:U,bandSize:Ut!==rt?Ut:rt,sizeList:kt[ve],maxBarSize:_r}),Ut!==rt&&(Fe=Fe.map(function(cr){return ie(ie({},cr),{},{position:ie(ie({},cr.position),{},{offset:cr.position.offset-Ut/2})})}))}var Rr=ee&&ee.type&&ee.type.getComposedData;Rr&&K.push({props:ie(ie({},Rr(ie(ie({},xe),{},{displayedData:I,props:k,dataKey:Q,item:ee,bandSize:rt,barPosition:Fe,offset:T,stackedData:Me,layout:W,dataStartIndex:N,dataEndIndex:R}))),{},ze(ze(ze({key:ee.key||"item-".concat(L)},Y,xe[Y]),G,xe[G]),"animationId",O)),childIndex:aF(ee,k.children),item:ee})}),K},v=function(k,S){var A=k.props,C=k.dataStartIndex,T=k.dataEndIndex,O=k.updateId;if(!lO({props:A}))return null;var N=A.children,R=A.layout,$=A.stackOffset,W=A.data,z=A.reverseStackOrder,U=MN(R),F=U.numericAxisName,X=U.cateAxisName,Y=Tn(N,n),G=mY(W,Y,"".concat(F,"Id"),"".concat(X,"Id"),$,z),Z=u.reduce(function(q,Q){var le="".concat(Q.axisType,"Map");return ie(ie({},q),{},ze({},le,Vne(A,ie(ie({},Q),{},{graphicalItems:Y,stackGroups:Q.axisType===F&&G,dataStartIndex:C,dataEndIndex:T}))))},{}),K=Jne(ie(ie({},Z),{},{props:A,graphicalItems:Y}),S==null?void 0:S.legendBBox);Object.keys(Z).forEach(function(q){Z[q]=p(A,Z[q],K,q.replace("Map",""),r)});var ee=Z["".concat(X,"Map")],L=Xne(ee),I=m(A,ie(ie({},Z),{},{dataStartIndex:C,dataEndIndex:T,updateId:O,graphicalItems:Y,stackGroups:G,offset:K}));return ie(ie({formattedGraphicalItems:I,graphicalItems:Y,offset:K,stackGroups:G},L),Z)},b=(function(x){function k(S){var A,C,T;return Nne(this,k),T=Ine(this,k,[S]),ze(T,"eventEmitterSymbol",Symbol("rechartsEventEmitter")),ze(T,"accessibilityManager",new yne),ze(T,"handleLegendBBoxUpdate",function(O){if(O){var N=T.state,R=N.dataStartIndex,$=N.dataEndIndex,W=N.updateId;T.setState(ie({legendBBox:O},v({props:T.props,dataStartIndex:R,dataEndIndex:$,updateId:W},ie(ie({},T.state),{},{legendBBox:O}))))}}),ze(T,"handleReceiveSyncEvent",function(O,N,R){if(T.props.syncId===O){if(R===T.eventEmitterSymbol&&typeof T.props.syncMethod!="function")return;T.applySyncEvent(N)}}),ze(T,"handleBrushChange",function(O){var N=O.startIndex,R=O.endIndex;if(N!==T.state.dataStartIndex||R!==T.state.dataEndIndex){var $=T.state.updateId;T.setState(function(){return ie({dataStartIndex:N,dataEndIndex:R},v({props:T.props,dataStartIndex:N,dataEndIndex:R,updateId:$},T.state))}),T.triggerSyncEvent({dataStartIndex:N,dataEndIndex:R})}}),ze(T,"handleMouseEnter",function(O){var N=T.getMouseInfo(O);if(N){var R=ie(ie({},N),{},{isTooltipActive:!0});T.setState(R),T.triggerSyncEvent(R);var $=T.props.onMouseEnter;Je($)&&$(R,O)}}),ze(T,"triggeredAfterMouseMove",function(O){var N=T.getMouseInfo(O),R=N?ie(ie({},N),{},{isTooltipActive:!0}):{isTooltipActive:!1};T.setState(R),T.triggerSyncEvent(R);var $=T.props.onMouseMove;Je($)&&$(R,O)}),ze(T,"handleItemMouseEnter",function(O){T.setState(function(){return{isTooltipActive:!0,activeItem:O,activePayload:O.tooltipPayload,activeCoordinate:O.tooltipPosition||{x:O.cx,y:O.cy}}})}),ze(T,"handleItemMouseLeave",function(){T.setState(function(){return{isTooltipActive:!1}})}),ze(T,"handleMouseMove",function(O){O.persist(),T.throttleTriggeredAfterMouseMove(O)}),ze(T,"handleMouseLeave",function(O){T.throttleTriggeredAfterMouseMove.cancel();var N={isTooltipActive:!1};T.setState(N),T.triggerSyncEvent(N);var R=T.props.onMouseLeave;Je(R)&&R(N,O)}),ze(T,"handleOuterEvent",function(O){var N=iF(O),R=On(T.props,"".concat(N));if(N&&Je(R)){var $,W;/.*touch.*/i.test(N)?W=T.getMouseInfo(O.changedTouches[0]):W=T.getMouseInfo(O),R(($=W)!==null&&$!==void 0?$:{},O)}}),ze(T,"handleClick",function(O){var N=T.getMouseInfo(O);if(N){var R=ie(ie({},N),{},{isTooltipActive:!0});T.setState(R),T.triggerSyncEvent(R);var $=T.props.onClick;Je($)&&$(R,O)}}),ze(T,"handleMouseDown",function(O){var N=T.props.onMouseDown;if(Je(N)){var R=T.getMouseInfo(O);N(R,O)}}),ze(T,"handleMouseUp",function(O){var N=T.props.onMouseUp;if(Je(N)){var R=T.getMouseInfo(O);N(R,O)}}),ze(T,"handleTouchMove",function(O){O.changedTouches!=null&&O.changedTouches.length>0&&T.throttleTriggeredAfterMouseMove(O.changedTouches[0])}),ze(T,"handleTouchStart",function(O){O.changedTouches!=null&&O.changedTouches.length>0&&T.handleMouseDown(O.changedTouches[0])}),ze(T,"handleTouchEnd",function(O){O.changedTouches!=null&&O.changedTouches.length>0&&T.handleMouseUp(O.changedTouches[0])}),ze(T,"handleDoubleClick",function(O){var N=T.props.onDoubleClick;if(Je(N)){var R=T.getMouseInfo(O);N(R,O)}}),ze(T,"handleContextMenu",function(O){var N=T.props.onContextMenu;if(Je(N)){var R=T.getMouseInfo(O);N(R,O)}}),ze(T,"triggerSyncEvent",function(O){T.props.syncId!==void 0&&Fb.emit(Hb,T.props.syncId,O,T.eventEmitterSymbol)}),ze(T,"applySyncEvent",function(O){var N=T.props,R=N.layout,$=N.syncMethod,W=T.state.updateId,z=O.dataStartIndex,U=O.dataEndIndex;if(O.dataStartIndex!==void 0||O.dataEndIndex!==void 0)T.setState(ie({dataStartIndex:z,dataEndIndex:U},v({props:T.props,dataStartIndex:z,dataEndIndex:U,updateId:W},T.state)));else if(O.activeTooltipIndex!==void 0){var F=O.chartX,X=O.chartY,Y=O.activeTooltipIndex,G=T.state,Z=G.offset,K=G.tooltipTicks;if(!Z)return;if(typeof $=="function")Y=$(K,O);else if($==="value"){Y=-1;for(var ee=0;ee<K.length;ee++)if(K[ee].value===O.activeLabel){Y=ee;break}}var L=ie(ie({},Z),{},{x:Z.left,y:Z.top}),I=Math.min(F,L.x+L.width),q=Math.min(X,L.y+L.height),Q=K[Y]&&K[Y].value,le=Nw(T.state,T.props.data,Y),fe=K[Y]?{x:R==="horizontal"?K[Y].coordinate:I,y:R==="horizontal"?q:K[Y].coordinate}:$M;T.setState(ie(ie({},O),{},{activeLabel:Q,activeCoordinate:fe,activePayload:le,activeTooltipIndex:Y}))}else T.setState(O)}),ze(T,"renderCursor",function(O){var N,R=T.state,$=R.isTooltipActive,W=R.activeCoordinate,z=R.activePayload,U=R.offset,F=R.activeTooltipIndex,X=R.tooltipAxisBandSize,Y=T.getTooltipEventType(),G=(N=O.props.active)!==null&&N!==void 0?N:$,Z=T.props.layout,K=O.key||"_recharts-cursor";return M.createElement(kne,{key:K,activeCoordinate:W,activePayload:z,activeTooltipIndex:F,chartName:r,element:O,isActive:G,layout:Z,offset:U,tooltipAxisBandSize:X,tooltipEventType:Y})}),ze(T,"renderPolarAxis",function(O,N,R){var $=On(O,"type.axisType"),W=On(T.state,"".concat($,"Map")),z=O.type.defaultProps,U=z!==void 0?ie(ie({},z),O.props):O.props,F=W&&W[U["".concat($,"Id")]];return j.cloneElement(O,ie(ie({},F),{},{className:ot($,F.className),key:O.key||"".concat(N,"-").concat(R),ticks:Ki(F,!0)}))}),ze(T,"renderPolarGrid",function(O){var N=O.props,R=N.radialLines,$=N.polarAngles,W=N.polarRadius,z=T.state,U=z.radiusAxisMap,F=z.angleAxisMap,X=Ra(U),Y=Ra(F),G=Y.cx,Z=Y.cy,K=Y.innerRadius,ee=Y.outerRadius;return j.cloneElement(O,{polarAngles:Array.isArray($)?$:Ki(Y,!0).map(function(L){return L.coordinate}),polarRadius:Array.isArray(W)?W:Ki(X,!0).map(function(L){return L.coordinate}),cx:G,cy:Z,innerRadius:K,outerRadius:ee,key:O.key||"polar-grid",radialLines:R})}),ze(T,"renderLegend",function(){var O=T.state.formattedGraphicalItems,N=T.props,R=N.children,$=N.width,W=N.height,z=T.props.margin||{},U=$-(z.left||0)-(z.right||0),F=j$({children:R,formattedGraphicalItems:O,legendWidth:U,legendContent:d});if(!F)return null;var X=F.item,Y=PN(F,Ene);return j.cloneElement(X,ie(ie({},Y),{},{chartWidth:$,chartHeight:W,margin:z,onBBoxUpdate:T.handleLegendBBoxUpdate}))}),ze(T,"renderTooltip",function(){var O,N=T.props,R=N.children,$=N.accessibilityLayer,W=sn(R,ln);if(!W)return null;var z=T.state,U=z.isTooltipActive,F=z.activeCoordinate,X=z.activePayload,Y=z.activeLabel,G=z.offset,Z=(O=W.props.active)!==null&&O!==void 0?O:U;return j.cloneElement(W,{viewBox:ie(ie({},G),{},{x:G.left,y:G.top}),active:Z,label:Y,payload:Z?X:[],coordinate:F,accessibilityLayer:$})}),ze(T,"renderBrush",function(O){var N=T.props,R=N.margin,$=N.data,W=T.state,z=W.offset,U=W.dataStartIndex,F=W.dataEndIndex,X=W.updateId;return j.cloneElement(O,{key:O.key||"_recharts-brush",onChange:Af(T.handleBrushChange,O.props.onChange),data:$,x:ge(O.props.x)?O.props.x:z.left,y:ge(O.props.y)?O.props.y:z.top+z.height+z.brushBottom-(R.bottom||0),width:ge(O.props.width)?O.props.width:z.width,startIndex:U,endIndex:F,updateId:"brush-".concat(X)})}),ze(T,"renderReferenceElement",function(O,N,R){if(!O)return null;var $=T,W=$.clipPathId,z=T.state,U=z.xAxisMap,F=z.yAxisMap,X=z.offset,Y=O.type.defaultProps||{},G=O.props,Z=G.xAxisId,K=Z===void 0?Y.xAxisId:Z,ee=G.yAxisId,L=ee===void 0?Y.yAxisId:ee;return j.cloneElement(O,{key:O.key||"".concat(N,"-").concat(R),xAxis:U[K],yAxis:F[L],viewBox:{x:X.left,y:X.top,width:X.width,height:X.height},clipPathId:W})}),ze(T,"renderActivePoints",function(O){var N=O.item,R=O.activePoint,$=O.basePoint,W=O.childIndex,z=O.isRange,U=[],F=N.props.key,X=N.item.type.defaultProps!==void 0?ie(ie({},N.item.type.defaultProps),N.item.props):N.item.props,Y=X.activeDot,G=X.dataKey,Z=ie(ie({index:W,dataKey:G,cx:R.x,cy:R.y,r:4,fill:n_(N.item),strokeWidth:2,stroke:"#fff",payload:R.payload,value:R.value},at(Y,!1)),ah(Y));return U.push(k.renderActiveDot(Y,Z,"".concat(F,"-activePoint-").concat(W))),$?U.push(k.renderActiveDot(Y,ie(ie({},Z),{},{cx:$.x,cy:$.y}),"".concat(F,"-basePoint-").concat(W))):z&&U.push(null),U}),ze(T,"renderGraphicChild",function(O,N,R){var $=T.filterFormatItem(O,N,R);if(!$)return null;var W=T.getTooltipEventType(),z=T.state,U=z.isTooltipActive,F=z.tooltipAxis,X=z.activeTooltipIndex,Y=z.activeLabel,G=T.props.children,Z=sn(G,ln),K=$.props,ee=K.points,L=K.isRange,I=K.baseLine,q=$.item.type.defaultProps!==void 0?ie(ie({},$.item.type.defaultProps),$.item.props):$.item.props,Q=q.activeDot,le=q.hide,fe=q.activeBar,ve=q.activeShape,qe=!!(!le&&U&&Z&&(Q||fe||ve)),xe={};W!=="axis"&&Z&&Z.props.trigger==="click"?xe={onClick:Af(T.handleItemMouseEnter,O.props.onClick)}:W!=="axis"&&(xe={onMouseLeave:Af(T.handleItemMouseLeave,O.props.onMouseLeave),onMouseEnter:Af(T.handleItemMouseEnter,O.props.onMouseEnter)});var ae=j.cloneElement(O,ie(ie({},$.props),xe));function Se(_t){return typeof F.dataKey=="function"?F.dataKey(_t.payload):null}if(qe)if(X>=0){var Me,oe;if(F.dataKey&&!F.allowDuplicatedCategory){var rt=typeof F.dataKey=="function"?Se:"payload.".concat(F.dataKey.toString());Me=ih(ee,rt,Y),oe=L&&I&&ih(I,rt,Y)}else Me=ee==null?void 0:ee[X],oe=L&&I&&I[X];if(ve||fe){var Fe=O.props.activeIndex!==void 0?O.props.activeIndex:X;return[j.cloneElement(O,ie(ie(ie({},$.props),xe),{},{activeIndex:Fe})),null,null]}if(!tt(Me))return[ae].concat(fl(T.renderActivePoints({item:$,activePoint:Me,basePoint:oe,childIndex:X,isRange:L})))}else{var kt,wt=(kt=T.getItemByXY(T.state.activeCoordinate))!==null&&kt!==void 0?kt:{graphicalItem:ae},Et=wt.graphicalItem,_r=Et.item,Ut=_r===void 0?O:_r,Rr=Et.childIndex,cr=ie(ie(ie({},$.props),xe),{},{activeIndex:Rr});return[j.cloneElement(Ut,cr),null,null]}return L?[ae,null,null]:[ae,null]}),ze(T,"renderCustomized",function(O,N,R){return j.cloneElement(O,ie(ie({key:"recharts-customized-".concat(R)},T.props),T.state))}),ze(T,"renderMap",{CartesianGrid:{handler:Nf,once:!0},ReferenceArea:{handler:T.renderReferenceElement},ReferenceLine:{handler:Nf},ReferenceDot:{handler:T.renderReferenceElement},XAxis:{handler:Nf},YAxis:{handler:Nf},Brush:{handler:T.renderBrush,once:!0},Bar:{handler:T.renderGraphicChild},Line:{handler:T.renderGraphicChild},Area:{handler:T.renderGraphicChild},Radar:{handler:T.renderGraphicChild},RadialBar:{handler:T.renderGraphicChild},Scatter:{handler:T.renderGraphicChild},Pie:{handler:T.renderGraphicChild},Funnel:{handler:T.renderGraphicChild},Tooltip:{handler:T.renderCursor,once:!0},PolarGrid:{handler:T.renderPolarGrid,once:!0},PolarAngleAxis:{handler:T.renderPolarAxis},PolarRadiusAxis:{handler:T.renderPolarAxis},Customized:{handler:T.renderCustomized}}),T.clipPathId="".concat((A=S.id)!==null&&A!==void 0?A:Bu("recharts"),"-clip"),T.throttleTriggeredAfterMouseMove=jI(T.triggeredAfterMouseMove,(C=S.throttleDelay)!==null&&C!==void 0?C:1e3/60),T.state={},T}return Dne(k,x),Rne(k,[{key:"componentDidMount",value:function(){var A,C;this.addListener(),this.accessibilityManager.setDetails({container:this.container,offset:{left:(A=this.props.margin.left)!==null&&A!==void 0?A:0,top:(C=this.props.margin.top)!==null&&C!==void 0?C:0},coordinateList:this.state.tooltipTicks,mouseHandlerCallback:this.triggeredAfterMouseMove,layout:this.props.layout}),this.displayDefaultTooltip()}},{key:"displayDefaultTooltip",value:function(){var A=this.props,C=A.children,T=A.data,O=A.height,N=A.layout,R=sn(C,ln);if(R){var $=R.props.defaultIndex;if(!(typeof $!="number"||$<0||$>this.state.tooltipTicks.length-1)){var W=this.state.tooltipTicks[$]&&this.state.tooltipTicks[$].value,z=Nw(this.state,T,$,W),U=this.state.tooltipTicks[$].coordinate,F=(this.state.offset.top+O)/2,X=N==="horizontal",Y=X?{x:U,y:F}:{y:U,x:F},G=this.state.formattedGraphicalItems.find(function(K){var ee=K.item;return ee.type.name==="Scatter"});G&&(Y=ie(ie({},Y),G.props.points[$].tooltipPosition),z=G.props.points[$].tooltipPayload);var Z={activeTooltipIndex:$,isTooltipActive:!0,activeLabel:W,activePayload:z,activeCoordinate:Y};this.setState(Z),this.renderCursor(R),this.accessibilityManager.setIndex($)}}}},{key:"getSnapshotBeforeUpdate",value:function(A,C){if(!this.props.accessibilityLayer)return null;if(this.state.tooltipTicks!==C.tooltipTicks&&this.accessibilityManager.setDetails({coordinateList:this.state.tooltipTicks}),this.props.layout!==A.layout&&this.accessibilityManager.setDetails({layout:this.props.layout}),this.props.margin!==A.margin){var T,O;this.accessibilityManager.setDetails({offset:{left:(T=this.props.margin.left)!==null&&T!==void 0?T:0,top:(O=this.props.margin.top)!==null&&O!==void 0?O:0}})}return null}},{key:"componentDidUpdate",value:function(A){gx([sn(A.children,ln)],[sn(this.props.children,ln)])||this.displayDefaultTooltip()}},{key:"componentWillUnmount",value:function(){this.removeListener(),this.throttleTriggeredAfterMouseMove.cancel()}},{key:"getTooltipEventType",value:function(){var A=sn(this.props.children,ln);if(A&&typeof A.props.shared=="boolean"){var C=A.props.shared?"axis":"item";return c.indexOf(C)>=0?C:a}return a}},{key:"getMouseInfo",value:function(A){if(!this.container)return null;var C=this.container,T=C.getBoundingClientRect(),O=WW(T),N={chartX:Math.round(A.pageX-O.left),chartY:Math.round(A.pageY-O.top)},R=T.width/C.offsetWidth||1,$=this.inRange(N.chartX,N.chartY,R);if(!$)return null;var W=this.state,z=W.xAxisMap,U=W.yAxisMap,F=this.getTooltipEventType(),X=IN(this.state,this.props.data,this.props.layout,$);if(F!=="axis"&&z&&U){var Y=Ra(z).scale,G=Ra(U).scale,Z=Y&&Y.invert?Y.invert(N.chartX):null,K=G&&G.invert?G.invert(N.chartY):null;return ie(ie({},N),{},{xValue:Z,yValue:K},X)}return X?ie(ie({},N),X):null}},{key:"inRange",value:function(A,C){var T=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1,O=this.props.layout,N=A/T,R=C/T;if(O==="horizontal"||O==="vertical"){var $=this.state.offset,W=N>=$.left&&N<=$.left+$.width&&R>=$.top&&R<=$.top+$.height;return W?{x:N,y:R}:null}var z=this.state,U=z.angleAxisMap,F=z.radiusAxisMap;if(U&&F){var X=Ra(U);return Jj({x:N,y:R},X)}return null}},{key:"parseEventsOfWrapper",value:function(){var A=this.props.children,C=this.getTooltipEventType(),T=sn(A,ln),O={};T&&C==="axis"&&(T.props.trigger==="click"?O={onClick:this.handleClick}:O={onMouseEnter:this.handleMouseEnter,onDoubleClick:this.handleDoubleClick,onMouseMove:this.handleMouseMove,onMouseLeave:this.handleMouseLeave,onTouchMove:this.handleTouchMove,onTouchStart:this.handleTouchStart,onTouchEnd:this.handleTouchEnd,onContextMenu:this.handleContextMenu});var N=ah(this.props,this.handleOuterEvent);return ie(ie({},N),O)}},{key:"addListener",value:function(){Fb.on(Hb,this.handleReceiveSyncEvent)}},{key:"removeListener",value:function(){Fb.removeListener(Hb,this.handleReceiveSyncEvent)}},{key:"filterFormatItem",value:function(A,C,T){for(var O=this.state.formattedGraphicalItems,N=0,R=O.length;N<R;N++){var $=O[N];if($.item===A||$.props.key===A.key||C===Gi($.item.type)&&T===$.childIndex)return $}return null}},{key:"renderClipPath",value:function(){var A=this.clipPathId,C=this.state.offset,T=C.left,O=C.top,N=C.height,R=C.width;return M.createElement("defs",null,M.createElement("clipPath",{id:A},M.createElement("rect",{x:T,y:O,height:N,width:R})))}},{key:"getXScales",value:function(){var A=this.state.xAxisMap;return A?Object.entries(A).reduce(function(C,T){var O=NN(T,2),N=O[0],R=O[1];return ie(ie({},C),{},ze({},N,R.scale))},{}):null}},{key:"getYScales",value:function(){var A=this.state.yAxisMap;return A?Object.entries(A).reduce(function(C,T){var O=NN(T,2),N=O[0],R=O[1];return ie(ie({},C),{},ze({},N,R.scale))},{}):null}},{key:"getXScaleByAxisId",value:function(A){var C;return(C=this.state.xAxisMap)===null||C===void 0||(C=C[A])===null||C===void 0?void 0:C.scale}},{key:"getYScaleByAxisId",value:function(A){var C;return(C=this.state.yAxisMap)===null||C===void 0||(C=C[A])===null||C===void 0?void 0:C.scale}},{key:"getItemByXY",value:function(A){var C=this.state,T=C.formattedGraphicalItems,O=C.activeItem;if(T&&T.length)for(var N=0,R=T.length;N<R;N++){var $=T[N],W=$.props,z=$.item,U=z.type.defaultProps!==void 0?ie(ie({},z.type.defaultProps),z.props):z.props,F=Gi(z.type);if(F==="Bar"){var X=(W.data||[]).find(function(K){return fQ(A,K)});if(X)return{graphicalItem:$,payload:X}}else if(F==="RadialBar"){var Y=(W.data||[]).find(function(K){return Jj(A,K)});if(Y)return{graphicalItem:$,payload:Y}}else if(Bp($,O)||Up($,O)||Eu($,O)){var G=ree({graphicalItem:$,activeTooltipItem:O,itemData:U.data}),Z=U.activeIndex===void 0?G:U.activeIndex;return{graphicalItem:ie(ie({},$),{},{childIndex:Z}),payload:Eu($,O)?U.data[G]:$.props.data[G]}}}return null}},{key:"render",value:function(){var A=this;if(!lO(this))return null;var C=this.props,T=C.children,O=C.className,N=C.width,R=C.height,$=C.style,W=C.compact,z=C.title,U=C.desc,F=PN(C,Ane),X=at(F,!1);if(W)return M.createElement(fN,{state:this.state,width:this.props.width,height:this.props.height,clipPathId:this.clipPathId},M.createElement(vx,$s({},X,{width:N,height:R,title:z,desc:U}),this.renderClipPath(),uO(T,this.renderMap)));if(this.props.accessibilityLayer){var Y,G;X.tabIndex=(Y=this.props.tabIndex)!==null&&Y!==void 0?Y:0,X.role=(G=this.props.role)!==null&&G!==void 0?G:"application",X.onKeyDown=function(K){A.accessibilityManager.keyboardEvent(K)},X.onFocus=function(){A.accessibilityManager.focus()}}var Z=this.parseEventsOfWrapper();return M.createElement(fN,{state:this.state,width:this.props.width,height:this.props.height,clipPathId:this.clipPathId},M.createElement("div",$s({className:ot("recharts-wrapper",O),style:ie({position:"relative",cursor:"default",width:N,height:R},$)},Z,{ref:function(ee){A.container=ee}}),M.createElement(vx,$s({},X,{width:N,height:R,title:z,desc:U,style:Fne}),this.renderClipPath(),uO(T,this.renderMap)),this.renderLegend(),this.renderTooltip()))}}])})(j.Component);ze(b,"displayName",r),ze(b,"defaultProps",ie({layout:"horizontal",stackOffset:"none",barCategoryGap:"10%",barGap:4,margin:{top:5,right:5,bottom:5,left:5},reverseStackOrder:!1,syncMethod:"index"},f)),ze(b,"getDerivedStateFromProps",function(x,k){var S=x.dataKey,A=x.data,C=x.children,T=x.width,O=x.height,N=x.layout,R=x.stackOffset,$=x.margin,W=k.dataStartIndex,z=k.dataEndIndex;if(k.updateId===void 0){var U=$N(x);return ie(ie(ie({},U),{},{updateId:0},v(ie(ie({props:x},U),{},{updateId:0}),k)),{},{prevDataKey:S,prevData:A,prevWidth:T,prevHeight:O,prevLayout:N,prevStackOffset:R,prevMargin:$,prevChildren:C})}if(S!==k.prevDataKey||A!==k.prevData||T!==k.prevWidth||O!==k.prevHeight||N!==k.prevLayout||R!==k.prevStackOffset||!zs($,k.prevMargin)){var F=$N(x),X={chartX:k.chartX,chartY:k.chartY,isTooltipActive:k.isTooltipActive},Y=ie(ie({},IN(k,A,N)),{},{updateId:k.updateId+1}),G=ie(ie(ie({},F),X),Y);return ie(ie(ie({},G),v(ie({props:x},G),k)),{},{prevDataKey:S,prevData:A,prevWidth:T,prevHeight:O,prevLayout:N,prevStackOffset:R,prevMargin:$,prevChildren:C})}if(!gx(C,k.prevChildren)){var Z,K,ee,L,I=sn(C,rl),q=I&&(Z=(K=I.props)===null||K===void 0?void 0:K.startIndex)!==null&&Z!==void 0?Z:W,Q=I&&(ee=(L=I.props)===null||L===void 0?void 0:L.endIndex)!==null&&ee!==void 0?ee:z,le=q!==W||Q!==z,fe=!tt(A),ve=fe&&!le?k.updateId:k.updateId+1;return ie(ie({updateId:ve},v(ie(ie({props:x},k),{},{updateId:ve,dataStartIndex:q,dataEndIndex:Q}),k)),{},{prevChildren:C,dataStartIndex:q,dataEndIndex:Q})}return null}),ze(b,"renderActiveDot",function(x,k,S){var A;return j.isValidElement(x)?A=j.cloneElement(x,k):Je(x)?A=x(k):A=M.createElement(a_,k),M.createElement(Xt,{className:"recharts-active-dot",key:S},A)});var w=j.forwardRef(function(k,S){return M.createElement(b,$s({},k,{ref:S}))});return w.displayName=b.displayName,w},Qne=DM({chartName:"LineChart",GraphicalChild:Gu,axisComponents:[{axisType:"xAxis",AxisComp:Ua},{axisType:"yAxis",AxisComp:qa}],formatAxisMap:rM}),Pw=DM({chartName:"BarChart",GraphicalChild:ta,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:Ua},{axisType:"yAxis",AxisComp:qa}],formatAxisMap:rM});const np={backgroundColor:"#1e1e1e",border:"1px solid rgba(255,255,255,0.08)",borderRadius:"12px",color:"#e4e0dc",fontSize:"11px",fontFamily:"JetBrains Mono, monospace"};function It(t){return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(Math.round(t))}function Zn(t){return`$${t.toFixed(2)}`}function Ma({label:t,value:e,sub:r,accent:n}){return y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl px-5 py-4",children:[y.jsx("p",{className:"text-[11px] font-mono text-zinc-600 mb-1",children:t}),y.jsx("p",{className:`text-xl font-mono font-medium ${n?"text-[#E43A9C]":"text-zinc-100"}`,children:e}),r&&y.jsx("p",{className:"text-[10px] font-mono text-zinc-600 mt-0.5",children:r})]})}const eie={summary:"Summary","by squad":"By Squad","by agent":"By Agent",io:"IO",timeline:"Timeline"};function tie({tabs:t,active:e,onChange:r}){return y.jsx("div",{className:"flex gap-0 border-b border-white/[0.06] mb-5",children:t.map(n=>y.jsx("button",{type:"button",onClick:()=>r(n),className:`px-4 py-2 text-[11px] font-mono transition-colors border-b-2 -mb-px cursor-pointer ${e===n?"text-[#E43A9C] border-[#E43A9C]":"text-zinc-600 hover:text-zinc-300 border-transparent"}`,children:eie[n]??n},n))})}function rie({records:t,totals:e}){const r=e.totalInputTokens+e.totalOutputTokens,n=new Map;for(const o of t){const c=o.squadId??"__io__",u=o.squadName??(o.squadId?`${o.squadId.slice(0,8)} (deleted)`:"IO Orchestrator"),d=n.get(c)??{name:u,inputTokens:0,outputTokens:0,calls:0,cost:0};d.inputTokens+=o.inputTokens,d.outputTokens+=o.outputTokens,d.calls+=1,d.cost+=o.estimatedCostUsd??0,n.set(c,d)}const i=Array.from(n.values()).sort((o,c)=>c.cost-o.cost),a=i.map(o=>({name:o.name.length>12?`${o.name.slice(0,12)}…`:o.name,cost:Number.parseFloat(o.cost.toFixed(2)),tokens:Math.round((o.inputTokens+o.outputTokens)/1e3)}));return y.jsxs("div",{className:"space-y-5",children:[y.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[y.jsx(Ma,{label:"Total Tokens",value:It(r),sub:`${It(e.totalInputTokens)} in · ${It(e.totalOutputTokens)} out`}),y.jsx(Ma,{label:"Total Cost",value:Zn(e.totalCostUsd),accent:!0}),y.jsx(Ma,{label:"API Calls",value:It(e.callCount),sub:"across all entities"}),y.jsx(Ma,{label:"Avg Cost / Call",value:e.callCount>0?Zn(e.totalCostUsd/e.callCount):"$0.00",sub:`over ${e.callCount} calls`})]}),y.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:[y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-4",children:[y.jsx("p",{className:"text-[11px] font-mono text-zinc-500 mb-3",children:"Cost by entity"}),a.length>0?y.jsx(gh,{width:"100%",height:180,children:y.jsxs(Pw,{data:a,barCategoryGap:"35%",children:[y.jsx(ju,{vertical:!1,stroke:"rgba(255,255,255,0.04)"}),y.jsx(Ua,{dataKey:"name",tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1}),y.jsx(qa,{tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1,tickFormatter:o=>`$${o}`,width:40}),y.jsx(ln,{contentStyle:np,cursor:{fill:"rgba(255,255,255,0.03)"},formatter:o=>[`$${o.toFixed(2)}`,"Cost"]}),y.jsx(ta,{dataKey:"cost",fill:"url(#costGrad)",radius:[6,6,0,0]}),y.jsx("defs",{children:y.jsxs("linearGradient",{id:"costGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[y.jsx("stop",{offset:"0%",stopColor:"#E43A9C"}),y.jsx("stop",{offset:"100%",stopColor:"#D83333",stopOpacity:.7})]})})]})}):y.jsx("div",{className:"h-[180px] flex items-center justify-center text-zinc-700 text-[11px] font-mono",children:"No data"})]}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-4",children:[y.jsx("p",{className:"text-[11px] font-mono text-zinc-500 mb-3",children:"Tokens by entity (k)"}),a.length>0?y.jsx(gh,{width:"100%",height:180,children:y.jsxs(Pw,{data:a,barCategoryGap:"35%",children:[y.jsx(ju,{vertical:!1,stroke:"rgba(255,255,255,0.04)"}),y.jsx(Ua,{dataKey:"name",tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1}),y.jsx(qa,{tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1,tickFormatter:o=>`${o}k`,width:40}),y.jsx(ln,{contentStyle:np,cursor:{fill:"rgba(255,255,255,0.03)"},formatter:o=>[`${o}k`,"Tokens"]}),y.jsx(ta,{dataKey:"tokens",fill:"url(#tokenGrad)",radius:[6,6,0,0]}),y.jsx("defs",{children:y.jsxs("linearGradient",{id:"tokenGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[y.jsx("stop",{offset:"0%",stopColor:"#818cf8"}),y.jsx("stop",{offset:"100%",stopColor:"#6366f1",stopOpacity:.7})]})})]})}):y.jsx("div",{className:"h-[180px] flex items-center justify-center text-zinc-700 text-[11px] font-mono",children:"No data"})]})]}),y.jsx("div",{className:"overflow-auto rounded-2xl border border-white/[0.07] glass-card",children:y.jsxs("table",{className:"w-full text-[11px] font-mono",children:[y.jsx("thead",{children:y.jsx("tr",{className:"border-b border-white/[0.06] bg-[#1a1a1a]",children:["Entity","Input","Output","Calls","Cost"].map(o=>y.jsx("th",{className:`text-left px-4 py-2.5 text-zinc-600 font-medium ${o==="Cost"?"text-right":""}`,children:o},o))})}),y.jsxs("tbody",{children:[i.map(o=>y.jsxs("tr",{className:"border-b border-white/[0.04] hover:bg-white/[0.015] transition-colors",children:[y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:o.name}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(o.inputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(o.outputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:o.calls}),y.jsx("td",{className:"px-4 py-3 text-right text-[#E43A9C]",children:Zn(o.cost)})]},o.name)),y.jsxs("tr",{className:"bg-[#1a1a1a]",children:[y.jsx("td",{className:"px-4 py-3 text-zinc-200 font-medium",children:"Total"}),y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:It(e.totalInputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:It(e.totalOutputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:e.callCount}),y.jsx("td",{className:"px-4 py-3 text-right text-[#E43A9C] font-medium",children:Zn(e.totalCostUsd)})]})]})]})})]})}function nie({records:t}){const[e,r]=j.useState([]),[n,i]=j.useState("cost"),[a,o]=j.useState("desc");function c(f){f===n?o(m=>m==="asc"?"desc":"asc"):(i(f),o("desc"))}const u=j.useMemo(()=>{const f=new Map;for(const v of t){if(!v.squadId)continue;const b=f.get(v.squadId)??{id:v.squadId,name:v.squadName??`${v.squadId.slice(0,8)} (deleted)`,agents:new Map,inputTokens:0,outputTokens:0,calls:0,cost:0};b.inputTokens+=v.inputTokens,b.outputTokens+=v.outputTokens,b.calls+=1,b.cost+=v.estimatedCostUsd??0;const w=`${v.agentRole??"unknown"}:${v.model}`,x=b.agents.get(w)??{role:v.agentRole??"unknown",model:v.model,inputTokens:0,outputTokens:0,calls:0,cost:0};x.inputTokens+=v.inputTokens,x.outputTokens+=v.outputTokens,x.calls+=1,x.cost+=v.estimatedCostUsd??0,b.agents.set(w,x),f.set(v.squadId,b)}return[...Array.from(f.values())].sort((v,b)=>{const w=v[n],x=b[n],k=typeof w=="string"?w.localeCompare(x):w-x;return a==="desc"?-k:k})},[t,n,a]),d=f=>r(m=>m.includes(f)?m.filter(v=>v!==f):[...m,f]),p=[{key:"name",label:"Squad"},{key:"inputTokens",label:"In"},{key:"outputTokens",label:"Out"},{key:"calls",label:"Calls"},{key:"cost",label:"Cost"}];return u.length===0?y.jsx("div",{className:"text-center py-12 text-zinc-700 text-[11px] font-mono",children:"No squad usage data"}):y.jsxs("div",{className:"space-y-2",children:[y.jsxs("div",{className:"flex items-center gap-1 px-1 mb-1",children:[y.jsx("span",{className:"text-[10px] font-mono text-zinc-700 mr-1",children:"sort by"}),p.map(f=>y.jsxs("button",{type:"button",onClick:()=>c(f.key),className:`flex items-center gap-0.5 px-2 py-1 rounded-lg text-[10px] font-mono transition-colors ${n===f.key?"text-[#E43A9C]":"text-zinc-600 hover:text-zinc-400 hover:bg-white/[0.04]"}`,style:n===f.key?{background:"rgba(228,58,156,0.1)"}:void 0,children:[f.label,n===f.key&&y.jsx("span",{className:"text-[9px]",children:a==="desc"?"↓":"↑"})]},f.key))]}),u.map(f=>{const m=e.includes(f.id),v=Array.from(f.agents.values());return y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl overflow-hidden",children:[y.jsxs("button",{type:"button",onClick:()=>d(f.id),className:"w-full flex items-center gap-3 px-4 py-3.5 hover:bg-white/[0.02] transition-colors text-left cursor-pointer",children:[y.jsx("div",{className:`transition-transform ${m?"rotate-90":""}`,children:y.jsx(Qw,{className:"w-3.5 h-3.5 text-zinc-600"})}),y.jsx("span",{className:"text-sm font-mono text-zinc-100 flex-1",children:f.name}),y.jsxs("div",{className:"flex items-center gap-6 text-[11px] font-mono",children:[y.jsxs("span",{className:"text-zinc-500 hidden sm:block",children:[y.jsx("span",{className:"text-zinc-700 mr-1",children:"in"}),It(f.inputTokens)]}),y.jsxs("span",{className:"text-zinc-500 hidden sm:block",children:[y.jsx("span",{className:"text-zinc-700 mr-1",children:"out"}),It(f.outputTokens)]}),y.jsxs("span",{className:"text-zinc-500",children:[y.jsx("span",{className:"text-zinc-700 mr-1",children:"calls"}),f.calls]}),y.jsx("span",{className:"text-[#E43A9C] font-medium w-16 text-right",children:Zn(f.cost)})]})]}),m&&y.jsx("div",{className:"border-t border-white/[0.05]",children:y.jsxs("table",{className:"w-full text-[11px] font-mono",children:[y.jsx("thead",{children:y.jsx("tr",{className:"bg-[#191919]",children:["Agent","Model","Input","Output","Calls","Cost"].map(b=>y.jsx("th",{className:`text-left px-4 py-2 text-zinc-700 font-medium ${b==="Cost"?"text-right":""}`,children:b},b))})}),y.jsx("tbody",{children:v.map(b=>y.jsxs("tr",{className:"border-t border-white/[0.04] hover:bg-white/[0.015] transition-colors",children:[y.jsx("td",{className:"px-4 py-2.5 text-zinc-300",children:b.role}),y.jsx("td",{className:"px-4 py-2.5 text-zinc-600",children:b.model}),y.jsx("td",{className:"px-4 py-2.5 text-zinc-500",children:It(b.inputTokens)}),y.jsx("td",{className:"px-4 py-2.5 text-zinc-500",children:It(b.outputTokens)}),y.jsx("td",{className:"px-4 py-2.5 text-zinc-500",children:b.calls}),y.jsx("td",{className:"px-4 py-2.5 text-right text-[#E43A9C]",children:Zn(b.cost)})]},b.role))})]})})]},f.id)})]})}function iie({records:t}){const e=j.useMemo(()=>{const n=new Map;for(const i of t){const a=`${i.squadId??"io"}:${i.agentRole??"orchestrator"}:${i.model}`,o=n.get(a)??{name:i.agentRole??"orchestrator",squad:i.squadName??(i.squadId?i.squadId.slice(0,8):"IO"),model:i.model,inputTokens:0,outputTokens:0,calls:0,cost:0};o.inputTokens+=i.inputTokens,o.outputTokens+=i.outputTokens,o.calls+=1,o.cost+=i.estimatedCostUsd??0,n.set(a,o)}return Array.from(n.values()).sort((i,a)=>a.cost-i.cost)},[t]),r=e.reduce((n,i)=>n+i.cost,0);return y.jsx("div",{className:"overflow-auto rounded-2xl border border-white/[0.07] glass-card",children:y.jsxs("table",{className:"w-full text-[11px] font-mono",children:[y.jsx("thead",{children:y.jsx("tr",{className:"border-b border-white/[0.06] bg-[#1a1a1a]",children:["Agent","Squad","Model","Input","Output","Calls","Cost","% of total"].map(n=>y.jsx("th",{className:`text-left px-4 py-2.5 text-zinc-600 font-medium ${n==="Cost"?"text-right":""}`,children:n},n))})}),y.jsx("tbody",{children:e.map(n=>y.jsxs("tr",{className:"border-b border-white/[0.04] hover:bg-white/[0.015] transition-colors",children:[y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:n.name}),y.jsx("td",{className:"px-4 py-3 text-zinc-600",children:n.squad}),y.jsx("td",{className:"px-4 py-3 text-zinc-600",children:n.model}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(n.inputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(n.outputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:n.calls}),y.jsx("td",{className:"px-4 py-3 text-right text-[#E43A9C]",children:Zn(n.cost)}),y.jsx("td",{className:"px-4 py-3",children:y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("div",{className:"w-16 h-1.5 rounded-full bg-[#252525] overflow-hidden",children:y.jsx("div",{className:"h-full bg-[#E43A9C] rounded-full",style:{width:`${r>0?n.cost/r*100:0}%`}})}),y.jsx("span",{className:"text-zinc-600 text-[10px]",children:r>0?`${(n.cost/r*100).toFixed(1)}%`:"0%"})]})})]},`${n.squad}:${n.name}`))})]})})}function aie({records:t}){const e=j.useMemo(()=>t.filter(o=>!o.squadId),[t]),r=j.useMemo(()=>{const o=new Map;for(const c of e){const u=`${c.agentRole??"orchestrator"}:${c.model}`,d=o.get(u)??{name:c.agentRole??"orchestrator",model:c.model,inputTokens:0,outputTokens:0,calls:0,cost:0};d.inputTokens+=c.inputTokens,d.outputTokens+=c.outputTokens,d.calls+=1,d.cost+=c.estimatedCostUsd??0,o.set(u,d)}return Array.from(o.values()).sort((c,u)=>u.cost-c.cost)},[e]),n=e.reduce((o,c)=>o+c.inputTokens,0),i=e.reduce((o,c)=>o+c.outputTokens,0),a=e.reduce((o,c)=>o+(c.estimatedCostUsd??0),0);return y.jsxs("div",{className:"space-y-5",children:[y.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[y.jsx(Ma,{label:"IO Tokens",value:It(n+i),sub:`${It(n)} in · ${It(i)} out`}),y.jsx(Ma,{label:"IO Cost",value:Zn(a),accent:!0}),y.jsx(Ma,{label:"IO Calls",value:It(e.length)}),y.jsx(Ma,{label:"IO Roles",value:String(r.length)})]}),y.jsx("div",{className:"overflow-auto rounded-2xl border border-white/[0.07] glass-card",children:y.jsxs("table",{className:"w-full text-[11px] font-mono",children:[y.jsx("thead",{children:y.jsx("tr",{className:"border-b border-white/[0.06] bg-[#1a1a1a]",children:["Role","Model","Input","Output","Calls","Cost"].map(o=>y.jsx("th",{className:`text-left px-4 py-2.5 text-zinc-600 font-medium ${o==="Cost"?"text-right":""}`,children:o},o))})}),y.jsx("tbody",{children:r.map(o=>y.jsxs("tr",{className:"border-b border-white/[0.04] hover:bg-white/[0.015] transition-colors",children:[y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:o.name}),y.jsx("td",{className:"px-4 py-3 text-zinc-600",children:o.model}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(o.inputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(o.outputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:o.calls}),y.jsx("td",{className:"px-4 py-3 text-right text-[#E43A9C]",children:Zn(o.cost)})]},o.name))})]})})]})}function oie({records:t}){const e=Fa(),r=j.useMemo(()=>{const i=new Map;for(const a of t){const o=a.timestamp.slice(0,10),c=i.get(o)??{date:o,inputTokens:0,outputTokens:0,cost:0,calls:0};c.inputTokens+=a.inputTokens,c.outputTokens+=a.outputTokens,c.cost+=a.estimatedCostUsd??0,c.calls+=1,i.set(o,c)}return Array.from(i.values()).sort((a,o)=>a.date.localeCompare(o.date))},[t]),n=r.map(i=>({...i,label:ez(i.date,e),tokens:i.inputTokens+i.outputTokens}));return y.jsxs("div",{className:"space-y-5",children:[y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-5",children:[y.jsx("p",{className:"text-[11px] font-mono text-zinc-500 mb-3",children:"Tokens per day"}),n.length>0?y.jsx(gh,{width:"100%",height:220,children:y.jsxs(Qne,{data:n,children:[y.jsx(ju,{vertical:!1,stroke:"rgba(255,255,255,0.04)"}),y.jsx(Ua,{dataKey:"label",tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1}),y.jsx(qa,{tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1,tickFormatter:It,width:44}),y.jsx(ln,{contentStyle:np,cursor:{fill:"rgba(255,255,255,0.03)"},formatter:i=>[It(i),"Tokens"]}),y.jsx(Gu,{type:"monotone",dataKey:"tokens",stroke:"#E43A9C",strokeWidth:2,dot:!1})]})}):y.jsx("div",{className:"h-[220px] flex items-center justify-center text-zinc-700 text-[11px] font-mono",children:"No data"})]}),y.jsxs("div",{className:"glass-card border border-white/[0.07] rounded-2xl p-5",children:[y.jsx("p",{className:"text-[11px] font-mono text-zinc-500 mb-3",children:"Cost per day"}),n.length>0?y.jsx(gh,{width:"100%",height:180,children:y.jsxs(Pw,{data:n,barCategoryGap:"20%",children:[y.jsx(ju,{vertical:!1,stroke:"rgba(255,255,255,0.04)"}),y.jsx(Ua,{dataKey:"label",tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1}),y.jsx(qa,{tick:{fill:"#52525b",fontSize:10,fontFamily:"JetBrains Mono, monospace"},axisLine:!1,tickLine:!1,tickFormatter:i=>`$${i.toFixed(2)}`,width:44}),y.jsx(ln,{contentStyle:np,cursor:{fill:"rgba(255,255,255,0.03)"},formatter:i=>[Zn(i),"Cost"]}),y.jsx(ta,{dataKey:"cost",fill:"url(#costGradTl)",radius:[4,4,0,0]}),y.jsx("defs",{children:y.jsxs("linearGradient",{id:"costGradTl",x1:"0",y1:"0",x2:"0",y2:"1",children:[y.jsx("stop",{offset:"0%",stopColor:"#E43A9C"}),y.jsx("stop",{offset:"100%",stopColor:"#D83333",stopOpacity:.7})]})})]})}):y.jsx("div",{className:"h-[180px] flex items-center justify-center text-zinc-700 text-[11px] font-mono",children:"No data"})]}),y.jsx("div",{className:"overflow-auto rounded-2xl border border-white/[0.07] glass-card",children:y.jsxs("table",{className:"w-full text-[11px] font-mono",children:[y.jsx("thead",{children:y.jsx("tr",{className:"border-b border-white/[0.06] bg-[#1a1a1a]",children:["Date","Input","Output","Calls","Cost"].map(i=>y.jsx("th",{className:`text-left px-4 py-2.5 text-zinc-600 font-medium ${i==="Cost"?"text-right":""}`,children:i},i))})}),y.jsx("tbody",{children:r.map(i=>y.jsxs("tr",{className:"border-b border-white/[0.04] hover:bg-white/[0.015] transition-colors",children:[y.jsx("td",{className:"px-4 py-3 text-zinc-300",children:i.date}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(i.inputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:It(i.outputTokens)}),y.jsx("td",{className:"px-4 py-3 text-zinc-500",children:i.calls}),y.jsx("td",{className:"px-4 py-3 text-right text-[#E43A9C]",children:Zn(i.cost)})]},i.date))})]})})]})}function sie(){const[t,e]=j.useState("summary"),[r,n]=j.useState(null),[i,a]=j.useState("14d"),o=["summary","by squad","by agent","io","timeline"];if(j.useEffect(()=>{const u=new Date;i==="7d"?u.setDate(u.getDate()-7):i==="14d"?u.setDate(u.getDate()-14):i==="30d"?u.setDate(u.getDate()-30):u.setDate(u.getDate()-1),Ge.get(`/usage?since=${u.toISOString()}`).then(n).catch(()=>{})},[i]),!r)return y.jsx("div",{className:"h-full flex items-center justify-center text-zinc-600 font-mono text-[11px]",children:"Loading..."});const c=i==="1d"?"Today":`Last ${i}`;return y.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[y.jsxs("div",{className:"flex items-start justify-between mb-5 gap-4 flex-wrap",children:[y.jsxs("div",{children:[y.jsx("h2",{className:"text-2xl tracking-wide text-zinc-100",style:{fontFamily:"'Bebas Neue', sans-serif"},children:"Usage"}),y.jsx("p",{className:"text-[11px] text-zinc-600 font-mono mt-0.5",children:c})]}),y.jsx("div",{className:"flex gap-1 p-1 rounded-xl bg-white/[0.03] border border-white/[0.07]",children:["1d","7d","14d","30d"].map(u=>y.jsx("button",{type:"button",onClick:()=>a(u),className:`px-3 py-1.5 rounded-lg text-[11px] font-mono transition-colors cursor-pointer ${i===u?"text-[#E43A9C]":"text-zinc-600 hover:text-zinc-400"}`,style:i===u?{background:"rgba(228,58,156,0.12)"}:void 0,children:u},u))})]}),y.jsx(tie,{tabs:o,active:t,onChange:u=>e(u)}),t==="summary"&&y.jsx(rie,{records:r.records,totals:r.totals}),t==="by squad"&&y.jsx(nie,{records:r.records}),t==="by agent"&&y.jsx(iie,{records:r.records}),t==="io"&&y.jsx(aie,{records:r.records}),t==="timeline"&&y.jsx(oie,{records:r.records})]})}function LM(t){return[...t].sort((e,r)=>e.isDir!==r.isDir?e.isDir?-1:1:e.name.localeCompare(r.name)).map(e=>({...e,children:LM(e.children)}))}function lie(t){const e=[];for(const r of t){const n=r.path.split("/").filter(Boolean);let i=e,a="";if(r.isDir){for(const o of n){a=a?`${a}/${o}`:o;let c=i.find(u=>u.path===a);c||(c={name:o,path:a,isDir:!0,children:[]},i.push(c)),i=c.children}continue}for(const[o,c]of n.entries()){const u=o===n.length-1;a=a?`${a}/${c}`:c;let d=i.find(p=>p.path===a);d||(d={name:u&&r.name||c,path:a,isDir:!u,children:[]},i.push(d)),i=d.children}}return LM(e)}function zM(t,e){return e?t.flatMap(r=>{const n=r.name.toLowerCase().includes(e)||r.path.toLowerCase().includes(e);if(!r.isDir)return n?[r]:[];if(n)return[r];const i=zM(r.children,e);return i.length?[{...r,children:i}]:[]}):t}function Rw(t){const e=new Set;for(const r of t)if(r.isDir){e.add(r.path);for(const n of Rw(r.children))e.add(n)}return e}function cie(t){const e=t.split("/").filter(Boolean),r=[];let n="";for(const i of e.slice(0,-1))n=n?`${n}/${i}`:i,r.push(n);return r}function BM({node:t,depth:e,selectedPage:r,expandedPaths:n,autoExpandedPaths:i,onToggle:a,onSelect:o,onAddToFolder:c,onDeleteFolder:u}){const d=r===t.path,p=t.isDir&&(n.has(t.path)||i.has(t.path)),f=12+e*16,m=t.isDir&&["io","shared","squads","templates"].includes(t.path);return t.isDir?y.jsxs("div",{children:[y.jsxs("div",{className:"flex w-full items-center group rounded-lg py-2 pr-3 text-left text-[11px] font-mono text-zinc-400 transition-colors hover:bg-white/[0.04] hover:text-zinc-200",style:{paddingLeft:f},children:[y.jsxs("button",{type:"button",onClick:()=>a(t.path),className:"flex items-center gap-2 flex-1 min-w-0",children:[y.jsx(Qw,{size:14,className:`shrink-0 transition-transform ${p?"rotate-90":""}`}),p?y.jsx(zz,{size:14,className:"shrink-0 text-zinc-500"}):y.jsx(Uz,{size:14,className:"shrink-0 text-zinc-500"}),y.jsx("span",{className:"truncate",children:t.name})]}),y.jsxs("div",{className:"flex items-center gap-0.5",children:[!m&&y.jsx("button",{type:"button",onClick:v=>{v.stopPropagation(),u(t.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-red-500/20 transition-opacity text-zinc-600 hover:text-red-400",title:`Delete ${t.name}`,children:y.jsx(Da,{size:12})}),y.jsx("button",{type:"button",onClick:v=>{v.stopPropagation(),c(t.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/[0.08] transition-opacity text-zinc-600 hover:text-zinc-300",title:`Add page to ${t.name}`,children:y.jsx(i1,{size:12})})]})]}),p&&y.jsx("div",{children:t.children.map(v=>y.jsx(BM,{node:v,depth:e+1,selectedPage:r,expandedPaths:n,autoExpandedPaths:i,onToggle:a,onSelect:o,onAddToFolder:c,onDeleteFolder:u},v.path))})]}):y.jsxs("button",{type:"button",onClick:()=>o(t.path),className:`flex w-full items-center gap-2 rounded-lg py-2 pr-3 text-left text-[11px] font-mono transition-colors ${d?"border-l-2 border-[#E43A9C] bg-[#E43A9C]/10 text-[#E43A9C]":"text-zinc-500 hover:bg-white/[0.04] hover:text-zinc-300"}`,style:{paddingLeft:f},children:[y.jsx(Dz,{size:14,className:"shrink-0"}),y.jsx("span",{className:"truncate",children:t.name})]})}function uie(){const[t,e]=j.useState([]),[r,n]=j.useState(null),[i,a]=j.useState(""),[o,c]=j.useState(!1),[u,d]=j.useState(""),[p,f]=j.useState(""),[m,v]=j.useState(""),[b,w]=j.useState(new Set),[x,k]=j.useState(!1),[S,A]=j.useState(null),C=j.useRef(null),T=j.useCallback(async()=>{try{const L=await Ge.get("/wiki/pages");e(L.map(I=>({name:I.title||I.path.split("/").pop()||I.path,path:I.path,title:I.title,isDir:I.isDir})))}catch{e([])}},[]);j.useEffect(()=>{T()},[T]);const O=j.useMemo(()=>lie(t),[t]),N=m.trim().toLowerCase(),R=j.useMemo(()=>zM(O,N),[O,N]),$=j.useMemo(()=>{const L=N?Rw(R):new Set;if(r)for(const I of cie(r))L.add(I);return L},[R,N,r]),W=r?(function L(I){for(const q of I){if(q.path===r)return q;const Q=L(q.children);if(Q)return Q}return null})(R):null,z=(W==null?void 0:W.name)??(r?r.split("/").pop()??"":"");j.useEffect(()=>{const L=Rw(O);w(I=>new Set([...I,...L]))},[O]);async function U(L){try{const I=await Ge.get(`/wiki/pages/${L}`);a(I.content),d(I.content),n(I.path||L),c(!1)}catch{Qe.error("Failed to load page")}}o1({onEvent:L=>{(L.type==="connected"||L.type===Fc.WIKI_UPDATED)&&T()}});async function F(){if(r)try{await Ge.put(`/wiki/pages/${r}`,{content:u}),a(u),c(!1),Qe.success("Page saved")}catch{Qe.error("Failed to save page")}}async function X(){if(r)try{await Ge.delete(`/wiki/pages/${r}`),Qe.success("Page deleted"),n(null),a(""),d(""),c(!1),await T()}catch{Qe.error("Failed to delete page")}}function Y(L){f(`${L}/`),setTimeout(()=>{const I=C.current;I&&(I.focus(),I.setSelectionRange(I.value.length,I.value.length))},0)}function G(L){A(L)}async function Z(){if(S)try{await Ge.delete(`/wiki/directories/${S}`),Qe.success(`Deleted ${S}`),(r!=null&&r.startsWith(`${S}/`)||r===S)&&(n(null),a(""),d(""),c(!1)),await T()}catch{Qe.error("Failed to delete directory")}finally{A(null)}}async function K(){let L=p.trim().replace(/^\/+|\/+$/g,"");if(!L)return;L=L.replace(/\.md$/i,"");const I=L.startsWith("io/")||L.startsWith("shared/")||L.startsWith("squads/")?L:`shared/${L}`,q=I.split("/").pop()??I;k(!0);try{await Ge.post("/wiki/pages",{path:I,title:q,content:`# ${q}
518
518
 
519
519
  `,tags:[]}),Qe.success("Page created"),f(""),await T(),await U(I)}catch{Qe.error("Failed to create page")}finally{k(!1)}}function ee(L){w(I=>{const q=new Set(I);return q.has(L)?q.delete(L):q.add(L),q})}return y.jsxs("div",{className:"flex h-full",children:[y.jsxs("div",{className:"flex h-full w-64 flex-col border-r border-white/[0.07] bg-[#181818]",children:[y.jsx("div",{className:"border-b border-white/[0.07] p-3",children:y.jsxs("div",{className:"relative",children:[y.jsx(zP,{className:"absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-zinc-600"}),y.jsx("input",{type:"text",value:m,onChange:L=>v(L.target.value),placeholder:"Search pages...",className:"w-full rounded-lg border border-white/[0.07] bg-white/[0.04] py-2 pl-8 pr-3 text-[11px] font-mono text-zinc-300 outline-none placeholder:text-zinc-700 focus:border-[#E43A9C]/50"})]})}),y.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-3",children:R.length>0?R.map(L=>y.jsx(BM,{node:L,depth:0,selectedPage:r,expandedPaths:b,autoExpandedPaths:$,onToggle:ee,onSelect:U,onAddToFolder:Y,onDeleteFolder:G},L.path)):y.jsx("p",{className:"py-4 text-center font-mono text-[11px] text-zinc-700",children:"No pages found"})}),y.jsx("div",{className:"border-t border-white/[0.07] p-3",children:y.jsxs("div",{className:"space-y-2",children:[y.jsx("input",{ref:C,type:"text",value:p,onChange:L=>f(L.target.value),onKeyDown:L=>{L.key==="Enter"&&K(),L.key==="Escape"&&f("")},placeholder:"folder/new-page",className:"w-full rounded-lg border border-white/[0.07] bg-white/[0.04] px-3 py-2 text-[11px] font-mono text-zinc-300 outline-none placeholder:text-zinc-700 focus:border-[#E43A9C]/50"}),y.jsx(Ba,{onClick:K,disabled:!p.trim()||x,className:"w-full justify-center px-3 py-2",children:x?y.jsxs(y.Fragment,{children:[y.jsx(Ts,{size:13,className:"animate-spin"})," Creating..."]}):y.jsxs(y.Fragment,{children:[y.jsx(i1,{size:13})," Add Page"]})})]})})]}),y.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:r?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex h-14 shrink-0 items-center justify-between border-b border-white/[0.07] px-6",children:[y.jsxs("div",{className:"min-w-0",children:[y.jsx("h3",{className:"truncate font-mono text-sm text-zinc-100",children:z}),y.jsx("p",{className:"truncate font-mono text-[11px] text-zinc-500",children:r})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[o?y.jsxs(y.Fragment,{children:[y.jsxs(Ba,{onClick:F,className:"px-3 py-1.5",children:[y.jsx(up,{size:12})," Save"]}),y.jsx(wi,{onClick:()=>{c(!1),d(i)},className:"px-3 py-1.5",children:"Cancel"})]}):y.jsxs(wi,{onClick:()=>{c(!0),d(i)},className:"px-3 py-1.5",children:[y.jsx(Wf,{size:12})," Edit"]}),y.jsxs(Vf,{onClick:X,className:"px-3 py-1.5",children:[y.jsx(Da,{size:12})," Delete"]})]})]}),y.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:o?y.jsx("textarea",{value:u,onChange:L=>d(L.target.value),className:"h-full min-h-[320px] w-full resize-none rounded-xl border border-white/[0.07] bg-[#181818] p-4 font-mono text-sm text-zinc-300 outline-none focus:border-[#E43A9C]/50"}):y.jsx("div",{className:"mx-auto max-w-4xl",children:y.jsx("div",{className:"prose-io text-sm text-zinc-300",dangerouslySetInnerHTML:{__html:it.parse(i)}})})})]}):y.jsx("div",{className:"flex h-full items-center justify-center",children:y.jsxs("div",{className:"text-center",children:[y.jsx(RP,{size:48,className:"mx-auto mb-3 text-zinc-800"}),y.jsx("p",{className:"font-mono text-[11px] text-zinc-700",children:"Select a page to view"})]})})}),S&&y.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:y.jsxs("div",{className:"w-full max-w-sm rounded-2xl border border-white/[0.07] bg-[#1a1a1a] p-6 shadow-2xl",children:[y.jsx("h3",{className:"mb-2 text-sm font-medium text-zinc-100",children:"Delete directory?"}),y.jsxs("p",{className:"mb-4 text-xs text-zinc-400",children:["This will permanently delete"," ",y.jsx("span",{className:"font-mono text-zinc-200",children:S})," and all its contents."]}),y.jsxs("div",{className:"flex justify-end gap-2",children:[y.jsx(wi,{onClick:()=>A(null),className:"px-3 py-1.5",children:"Cancel"}),y.jsxs(Vf,{onClick:Z,className:"px-3 py-1.5",children:[y.jsx(Da,{size:12})," Delete"]})]})]})})]})}function die({children:t}){const{session:e,supabase:r,loading:n}=gp();return n?y.jsx("div",{className:"min-h-screen flex items-center justify-center text-[var(--color-muted-foreground)]",children:"Loading..."}):r?e?y.jsx(y.Fragment,{children:t}):y.jsx(Dq,{}):y.jsx(y.Fragment,{children:t})}function fie(){const{pathname:t}=ti(),e=t==="/"||t==="/chat"||t.startsWith("/chat/");return y.jsxs(y.Fragment,{children:[y.jsx(jL,{children:y.jsxs(Yr,{element:y.jsx(Rq,{}),children:[y.jsx(Yr,{index:!0,element:y.jsx(Iq,{})}),y.jsx(Yr,{path:"squads",element:y.jsx(vf,{})}),y.jsx(Yr,{path:"squads/:name",element:y.jsx(vf,{})}),y.jsx(Yr,{path:"squads/:name/instances/:instanceId",element:y.jsx(vf,{})}),y.jsx(Yr,{path:"squads/:name/agents/:role",element:y.jsx(vf,{})}),y.jsx(Yr,{path:"feed",element:y.jsx(Mq,{})}),y.jsx(Yr,{path:"skills",element:y.jsx(Xq,{})}),y.jsx(Yr,{path:"schedules",element:y.jsx(Bq,{})}),y.jsx(Yr,{path:"wiki",element:y.jsx(uie,{})}),y.jsx(Yr,{path:"settings",element:y.jsx(Hq,{})}),y.jsx(Yr,{path:"usage",element:y.jsx(sie,{})}),y.jsx(Yr,{path:"*",element:y.jsx(OL,{to:"/",replace:!0})})]})}),!e&&y.jsx($B,{})]})}function hie(){return y.jsx(zU,{children:y.jsx(die,{children:y.jsx(Z4,{children:y.jsx(IB,{children:y.jsx(fie,{})})})})})}OD.createRoot(document.getElementById("root")).render(y.jsx(j.StrictMode,{children:y.jsxs(e5,{children:[y.jsx(hie,{}),y.jsx(D5,{theme:"dark",position:"bottom-right"})]})}));
520
- //# sourceMappingURL=index-CZ5uBH6R.js.map
520
+ //# sourceMappingURL=index-3rp2-GCY.js.map