@augmentd-labs/canvas-web 2.14.17 → 2.14.18
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-Ciz5_WNq.js","assets/preload-helper-Czpn1I53.js","assets/markdown-html-bKd2bDZi.js","assets/rolldown-runtime-C0FnF6B9.js","assets/react-DQazvoR7.js","assets/sanitize-DrVcFY1Q.js","assets/punycode.es6-ZbLrB_Dn.js","assets/markdown-html-T86c6cqD.css","assets/SketchEditor-BbXQRr1e.js","assets/ui-BX_B5WCf.js","assets/utils-BxVxyehK.js","assets/workspace-CBQfK-Dr.js","assets/utils-2pl1SbIp.js","assets/blobs-Cn7cVptE.js","assets/sha256-OKSsHPWr.js","assets/chunk-K2UTITRG-D0fgw4vC.js","assets/chunk-SRAX5OIU-Dhm3gOdh.js","assets/chunk-6U3AYISY-C6-Mtja1.js","assets/chunk-Z3N5DIM6-D9TMVU7m.js","assets/EditorOverlay-y6SK-pjT.js","assets/SketchEditor-DtRVLazd.css","assets/TextDocumentEditor-BU0qu4aP.js","assets/text-documents-De1PQIC0.js","assets/LocationTab-ARqmeXmv.js","assets/map-BxCwdK0d.js","assets/map-BcsP_QXj.css","assets/NextShell-DDBrRX1x.js","assets/NextShell-B4NeoNB5.css"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{a as e,n as t,o as n,r,t as i}from"./rolldown-runtime-C0FnF6B9.js";import{Ct as a,St as o,_t as s,bt as c,st as l,vt as u,wt as d,xt as f,yt as p}from"./react-DQazvoR7.js";import{t as m}from"./preload-helper-Czpn1I53.js";import{$ as h,$n as g,$r as _,$t as v,An as y,Ar as b,At as x,B as S,Bn as C,Br as w,Bt as T,C as E,Cn as D,Cr as O,Ct as k,Dn as A,Dr as j,Dt as M,En as N,Er as P,Et as F,F as I,Fn as ee,Fr as te,Ft as ne,G as re,Gn as ie,Gr as L,Gt as R,H as ae,Hn as oe,Hr as se,Ht as ce,I as z,Ir as le,It as ue,J as de,Jn as fe,Jr as pe,Jt as me,K as he,Kn as ge,Kr as _e,Kt as ve,L as ye,Lr as B,Lt as be,Mn as V,Mr as xe,Mt as H,Nn as Se,Nr as Ce,Nt as U,On as W,Or as we,Ot as Te,Pn as Ee,Pr as De,Pt as Oe,Q as ke,Qn as Ae,Qr as je,Qt as Me,R as G,Rn as Ne,Rr as Pe,Rt as Fe,S as Ie,Sn as Le,Sr as Re,St as ze,T as Be,Tr as Ve,Tt as He,U as Ue,Un as We,Ur as Ge,Ut as Ke,V as qe,Vn as Je,Vr as Ye,Vt as Xe,W as Ze,Wn as Qe,Wr as $e,Wt as et,X as tt,Xn as nt,Xr as rt,Xt as it,Y as at,Yn as ot,Yr as st,Yt as ct,Z as lt,Zn as ut,Zr as dt,Zt as ft,_ as pt,_i as mt,_n as ht,_r as gt,_t,ai as vt,an as yt,ar as bt,at as xt,b as St,bn as Ct,br as wt,bt as Tt,ci as Et,cn as Dt,cr as Ot,ct as kt,d as At,di as jt,dn as Mt,dr as Nt,dt as Pt,ei as Ft,en as It,er as Lt,et as Rt,f as zt,fi as Bt,fr as Vt,ft as Ht,g as Ut,gi as Wt,gn as Gt,gr as Kt,gt as qt,h as Jt,hi as Yt,hn as Xt,hr as Zt,ht as Qt,ii as $t,in as en,ir as tn,it as nn,jn as rn,jr as an,jt as on,kn as sn,kr as cn,kt as ln,li as un,ln as dn,lr as fn,lt as pn,m as mn,mi as hn,mr as gn,mt as _n,ni as vn,nn as yn,nr as bn,nt as xn,oi as Sn,on as Cn,or as wn,ot as Tn,p as En,pi as Dn,pn as On,pr as kn,pt as An,q as jn,qn as Mn,qr as Nn,qt as Pn,rn as Fn,rr as In,rt as Ln,si as Rn,sn as zn,sr as Bn,st as Vn,ti as Hn,tn as Un,tr as Wn,tt as Gn,u as Kn,ui as qn,un as Jn,ur as Yn,ut as Xn,v as Zn,vi as Qn,vn as $n,vr as er,vt as tr,w as nr,wn as rr,wr as ir,wt as ar,x as or,xn as sr,xr as cr,xt as lr,y as ur,yn as dr,yr as fr,yt as pr,z as mr,zn as hr,zr as gr,zt as _r}from"./ui-BX_B5WCf.js";import{i as vr,n as yr,r as br}from"./utils-BxVxyehK.js";import{n as xr,t as K}from"./utils-2pl1SbIp.js";import{$ as Sr,$t as Cr,A as wr,An as Tr,At as Er,B as Dr,Bt as Or,C as kr,Cn as Ar,Ct as jr,D as Mr,Dn as Nr,Dt as Pr,E as Fr,En as Ir,Et as Lr,F as Rr,Fn as q,Ft as zr,G as Br,H as Vr,Ht as Hr,I as Ur,In as J,It as Wr,J as Gr,Jt as Kr,K as qr,Kt as Jr,L as Yr,Lt as Xr,M as Zr,Mn as Qr,Mt as $r,N as ei,Nn as ti,Nt as ni,O as ri,On as ii,Ot as ai,P as oi,Pn as si,Pt as ci,Q as li,Qt as ui,R as di,Rt as fi,S as pi,Sn as mi,St as hi,T as gi,Tn as Y,Tt as _i,U as vi,Ut as yi,V as bi,Vt as xi,W as Si,Wt as Ci,X as wi,Xt as Ti,Y as Ei,Yt as Di,Z as Oi,Zt as ki,_ as Ai,_n as ji,_t as Mi,a as Ni,an as Pi,at as Fi,b as Ii,bn as Li,bt as Ri,c as zi,cn as Bi,ct as Vi,d as Hi,dn as Ui,dt as Wi,en as Gi,et as Ki,f as qi,fn as Ji,ft as Yi,g as Xi,gn as Zi,gt as Qi,h as $i,hn as ea,ht as ta,i as na,in as ra,it as ia,jn as aa,jt as oa,k as sa,kn as ca,kt as la,l as ua,ln as da,lt as fa,m as pa,mn as ma,mt as ha,n as ga,nn as _a,nt as va,o as ya,on as ba,ot as xa,p as Sa,pn as Ca,pt as wa,q as Ta,qt as Ea,r as Da,rn as Oa,rt as ka,s as Aa,sn as ja,st as Ma,t as Na,tn as Pa,tt as Fa,u as Ia,un as La,ut as Ra,v as za,vn as Ba,vt as Va,w as Ha,wn as Ua,wt as Wa,x as Ga,xn as Ka,xt as qa,y as Ja,yn as Ya,yt as Xa,z as Za,zt as Qa}from"./workspace-CBQfK-Dr.js";import{t as $a}from"./socket-hM4c-ZSl.js";import{_ as eo,a as to,d as no,g as ro,h as io,i as ao,l as oo,m as so,n as co,o as lo,p as uo,t as fo,v as po}from"./blobs-Cn7cVptE.js";import{_ as mo,a as ho,c as go,d as _o,f as vo,g as yo,h as bo,i as xo,l as So,m as Co,n as wo,o as To,p as Eo,r as Do,s as Oo,t as ko,u as Ao,v as jo}from"./text-documents-De1PQIC0.js";import{n as Mo,t as No}from"./map-BxCwdK0d.js";import{t as Po}from"./search-COMZIxA7.js";import{A as Fo,B as Io,C as Lo,D as Ro,E as zo,F as Bo,H as Vo,I as Ho,L as Uo,M as Wo,N as Go,O as Ko,P as qo,R as Jo,S as Yo,T as Xo,V as Zo,_ as Qo,a as $o,b as es,c as ts,d as ns,f as rs,g as is,h as as,i as os,j as ss,k as cs,l as ls,m as us,o as ds,p as fs,r as ps,s as ms,t as hs,u as gs,v as _s,w as vs,x as ys,y as bs,z as xs}from"./sha256-OKSsHPWr.js";import{t as Ss}from"./sanitize-DrVcFY1Q.js";import{n as Cs,t as ws}from"./use-theme-pnVLU4Kg.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var X=n(d(),1),Ts=o(),Es=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,Ds=/^[\\/]{2}/;function Os(e,t){return t+e.replace(/\\/g,`/`)}var ks=(e=>(e.Pop=`POP`,e.Push=`PUSH`,e.Replace=`REPLACE`,e))(ks||{}),As=`popstate`;function js(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function Ms(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return Ls(``,{pathname:r,search:i,hash:a},t.state&&t.state.usr||null,t.state&&t.state.key||`default`,n?{pathname:e.location.pathname,search:e.location.search,hash:e.location.hash}:void 0)}function n(e,t){return typeof t==`string`?t:Rs(t)}return Bs(t,n,null,e)}function Ns(e,t){if(e===!1||e==null)throw Error(t)}function Ps(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function Fs(){return Math.random().toString(36).substring(2,10)}function Is(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function Ls(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?zs(t):t,state:n,key:t&&t.key||r||Fs(),mask:i}}function Rs({pathname:e=`/`,search:t=``,hash:n=``}){return t&&t!==`?`&&(e+=t.charAt(0)===`?`?t:`?`+t),n&&n!==`#`&&(e+=n.charAt(0)===`#`?n:`#`+n),e}function zs(e){let t={};if(e){let n=e.indexOf(`#`);n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf(`?`);r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function Bs(e,t,n,r={}){let{window:i=document.defaultView,v5Compat:a=!1}=r,o=i.history,s=`POP`,c=null,l=u();l??(l=0,o.replaceState({...o.state,idx:l},``));function u(){return(o.state||{idx:null}).idx}function d(){s=`POP`;let e=u(),t=e==null?null:e-l;l=e,c&&c({action:s,location:h.location,delta:t})}function f(e,t){s=`PUSH`;let r=js(e)?e:Ls(h.location,e,t);n&&n(r,e),l=u()+1;let d=Is(r,l),f=h.createHref(r.mask||r);try{o.pushState(d,``,f)}catch(e){if(e instanceof DOMException&&e.name===`DataCloneError`)throw e;i.location.assign(f)}a&&c&&c({action:s,location:h.location,delta:1})}function p(e,t){s=`REPLACE`;let r=js(e)?e:Ls(h.location,e,t);n&&n(r,e),l=u();let i=Is(r,l),d=h.createHref(r.mask||r);o.replaceState(i,``,d),a&&c&&c({action:s,location:h.location,delta:0})}function m(e){return Vs(i,e)}let h={get action(){return s},get location(){return e(i,o)},listen(e){if(c)throw Error(`A history only accepts one active listener`);return i.addEventListener(As,d),c=e,()=>{i.removeEventListener(As,d),c=null}},createHref(e){return t(i,e)},createURL:m,encodeLocation(e){let t=m(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:f,replace:p,go(e){return o.go(e)}};return h}function Vs(e,t,n=!1){let r=`http://localhost`;e&&(r=e.location.origin===`null`?e.location.href:e.location.origin),Ns(r,`No window.location.(origin|href) available to create URL`);let i=typeof t==`string`?t:Rs(t);return i=i.replace(/ $/,`%20`),!n&&Ds.test(i)&&(i=r+i),new URL(i,r)}function Hs(e,t,n=`/`){return Us(e,t,n,!1)}function Us(e,t,n,r,i){let a=cc((typeof t==`string`?zs(t):t).pathname||`/`,n);if(a==null)return null;let o=i??Ws(e),s=null,c=sc(a);for(let e=0;s==null&&e<o.length;++e)s=rc(o[e],c,r);return s}function Ws(e){let t=Gs(e);return qs(t),t}function Gs(e,t=[],n=[],r=``,i=!1){let a=(e,a,o=i,s)=>{let c={relativePath:s===void 0?e.path||``:s,caseSensitive:e.caseSensitive===!0,childrenIndex:a,route:e};if(c.relativePath.startsWith(`/`)){if(!c.relativePath.startsWith(r)&&o)return;Ns(c.relativePath.startsWith(r),`Absolute route path "${c.relativePath}" nested under path "${r}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),c.relativePath=c.relativePath.slice(r.length)}let l=gc([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(Ns(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),Gs(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:tc(l,e.index),routesMeta:u.map((e,t)=>{let[n,r]=oc(e.relativePath,e.caseSensitive,t===u.length-1);return{...e,matcher:n,compiledParams:r}})})};return e.forEach((e,t)=>{if(e.path===``||!e.path?.includes(`?`))a(e,t);else for(let n of Ks(e.path))a(e,t,!0,n)}),t}function Ks(e){let t=e.split(`/`);if(t.length===0)return[];let[n,...r]=t,i=n.endsWith(`?`),a=n.replace(/\?$/,``);if(r.length===0)return i?[a,``]:[a];let o=Ks(r.join(`/`)),s=[];return s.push(...o.map(e=>e===``?a:[a,e].join(`/`))),i&&s.push(...o),s.map(t=>e.startsWith(`/`)&&t===``?`/`:t)}function qs(e){e.sort((e,t)=>e.score===t.score?nc(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var Js=/^:[\w-]+$/,Ys=3,Xs=2,Zs=1,Qs=10,$s=-2,ec=e=>e===`*`;function tc(e,t){let n=e.split(`/`),r=n.length;return n.some(ec)&&(r+=$s),t&&(r+=Xs),n.filter(e=>!ec(e)).reduce((e,t)=>e+(Js.test(t)?Ys:t===``?Zs:Qs),r)}function nc(e,t){return e.length===t.length&&e.slice(0,-1).every((e,n)=>e===t[n])?e[e.length-1]-t[t.length-1]:0}function rc(e,t,n=!1){let{routesMeta:r}=e,i={},a=`/`,o=[];for(let e=0;e<r.length;++e){let s=r[e],c=e===r.length-1,l=a===`/`?t:t.slice(a.length)||`/`,u={path:s.relativePath,caseSensitive:s.caseSensitive,end:c},d=s.matcher&&s.compiledParams?ac(u,l,s.matcher,s.compiledParams):ic(u,l),f=s.route;if(!d&&c&&n&&!r[r.length-1].route.index&&(d=ic({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!d)return null;Object.assign(i,d.params),o.push({params:i,pathname:gc([a,d.pathname]),pathnameBase:vc(gc([a,d.pathnameBase])),route:f}),d.pathnameBase!==`/`&&(a=gc([a,d.pathnameBase]))}return o}function ic(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=oc(e.path,e.caseSensitive,e.end);return ac(e,t,n,r)}function ac(e,t,n,r){let i=t.match(n);if(!i)return null;let a=i[0],o=a.replace(/(.)\/+$/,`$1`),s=i.slice(1);return{params:r.reduce((e,{paramName:t,isOptional:n},r)=>{if(t===`*`){let e=s[r]||``;o=a.slice(0,a.length-e.length).replace(/(.)\/+$/,`$1`)}let i=s[r];return e[t]=n&&!i?void 0:(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function oc(e,t=!1,n=!0){Ps(e===`*`||!e.endsWith(`*`)||e.endsWith(`/*`),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,`/*`)}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,`/*`)}".`);let r=[],i=`^`+e.replace(/\/*\*?$/,``).replace(/^\/*/,`/`).replace(/[\\.*+^${}|()[\]]/g,`\\$&`).replace(/\/:([\w-]+)(\?)?/g,(e,t,n,i,a)=>{if(r.push({paramName:t,isOptional:n!=null}),n){let t=a.charAt(i+e.length);return t&&t!==`/`?`/([^\\/]*)`:`(?:/([^\\/]*))?`}return`/([^\\/]+)`}).replace(/\/([\w-]+)\?(\/|$)/g,`(/$1)?$2`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function sc(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return Ps(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function cc(e,t){if(t===`/`)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith(`/`)?t.length-1:t.length,r=e.charAt(n);return r&&r!==`/`?null:e.slice(n)||`/`}function lc(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?zs(e):e,a;return n?(n=hc(n),a=n.startsWith(`/`)?uc(n.substring(1),`/`):uc(n,t)):a=t,{pathname:a,search:yc(r),hash:bc(i)}}function uc(e,t){let n=_c(t).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function dc(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function fc(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function pc(e){let t=fc(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function mc(e,t,n,r=!1){let i;typeof e==`string`?i=zs(e):(i={...e},Ns(!i.pathname||!i.pathname.includes(`?`),dc(`?`,`pathname`,`search`,i)),Ns(!i.pathname||!i.pathname.includes(`#`),dc(`#`,`pathname`,`hash`,i)),Ns(!i.search||!i.search.includes(`#`),dc(`#`,`search`,`hash`,i)));let a=e===``||i.pathname===``,o=a?`/`:i.pathname,s;if(o==null)s=n;else{let e=t.length-1;if(!r&&o.startsWith(`..`)){let t=o.split(`/`);for(;t[0]===`..`;)t.shift(),--e;i.pathname=t.join(`/`)}s=e>=0?t[e]:`/`}let c=lc(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var hc=e=>e.replace(/[\\/]{2,}/g,`/`),gc=e=>hc(e.join(`/`)),_c=e=>e.replace(/\/+$/,``),vc=e=>_c(e).replace(/^\/*/,`/`),yc=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,bc=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,xc=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||``,this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function Sc(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function Cc(e){return gc(e.map(e=>e.route.path).filter(Boolean))||`/`}var wc=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function Tc(e,t){let n=e;if(typeof n!=`string`||!Es.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(wc)try{let e=new URL(window.location.href),r=Ds.test(n)?new URL(Os(n,e.protocol)):new URL(n),a=cc(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{Ps(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:i,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var Ec=[`POST`,`PUT`,`PATCH`,`DELETE`];new Set(Ec);var Dc=[`GET`,...Ec];new Set(Dc);var Oc=[`about:`,`blob:`,`chrome:`,`chrome-untrusted:`,`content:`,`data:`,`devtools:`,`file:`,`filesystem:`,`javascript:`];function kc(e){try{return Oc.includes(new URL(e).protocol)}catch{return!1}}var Ac=X.createContext(null);Ac.displayName=`DataRouter`;var jc=X.createContext(null);jc.displayName=`DataRouterState`;var Mc=X.createContext(!1);function Nc(){return X.useContext(Mc)}var Pc=X.createContext({isTransitioning:!1});Pc.displayName=`ViewTransition`;var Fc=X.createContext(new Map);Fc.displayName=`Fetchers`;var Ic=X.createContext(null);Ic.displayName=`Await`;var Lc=X.createContext(null);Lc.displayName=`Navigation`;var Rc=X.createContext(null);Rc.displayName=`Location`;var zc=X.createContext({outlet:null,matches:[],isDataRoute:!1});zc.displayName=`Route`;var Bc=X.createContext(null);Bc.displayName=`RouteError`;var Vc=`REACT_ROUTER_ERROR`,Hc=`REDIRECT`,Uc=`ROUTE_ERROR_RESPONSE`;function Wc(e){if(e.startsWith(`${Vc}:${Hc}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`&&typeof t.location==`string`&&typeof t.reloadDocument==`boolean`&&typeof t.replace==`boolean`)return t}catch{}}function Gc(e){if(e.startsWith(`${Vc}:${Uc}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new xc(t.status,t.statusText,t.data)}catch{}}function Kc(e,{relative:t}={}){Ns(qc(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=X.useContext(Lc),{hash:i,pathname:a,search:o}=nl(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:gc([n,a])),r.createHref({pathname:s,search:o,hash:i})}function qc(){return X.useContext(Rc)!=null}function Jc(){return Ns(qc(),`useLocation() may be used only in the context of a <Router> component.`),X.useContext(Rc).location}var Yc=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function Xc(e){X.useContext(Lc).static||X.useLayoutEffect(e)}function Zc(){let{isDataRoute:e}=X.useContext(zc);return e?yl():Qc()}function Qc(){Ns(qc(),`useNavigate() may be used only in the context of a <Router> component.`);let e=X.useContext(Ac),{basename:t,navigator:n}=X.useContext(Lc),{matches:r}=X.useContext(zc),{pathname:i}=Jc(),a=JSON.stringify(pc(r)),o=X.useRef(!1);return Xc(()=>{o.current=!0}),X.useCallback((r,s={})=>{if(Ps(o.current,Yc),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=mc(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:gc([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}var $c=X.createContext(null);function el(e){let t=X.useContext(zc).outlet;return X.useMemo(()=>t&&X.createElement($c.Provider,{value:e},t),[t,e])}function tl(){let{matches:e}=X.useContext(zc);return e[e.length-1]?.params??{}}function nl(e,{relative:t}={}){let{matches:n}=X.useContext(zc),{pathname:r}=Jc(),i=JSON.stringify(pc(n));return X.useMemo(()=>mc(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function rl(e,t){return il(e,t)}function il(e,t,n){Ns(qc(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=X.useContext(Lc),{matches:i}=X.useContext(zc),a=i[i.length-1],o=a?a.params:{},s=a?a.pathname:`/`,c=a?a.pathnameBase:`/`,l=a&&a.route;{let e=l&&l.path||``;xl(s,!l||e.endsWith(`*`)||e.endsWith(`*?`),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${s}" (under <Route path="${e}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
3
3
|
|
|
4
|
-
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let u=Jc(),d;if(t){let e=typeof t==`string`?zs(t):t;Ns(c===`/`||e.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${e.pathname}" was given in the \`location\` prop.`),d=e}else d=u;let f=d.pathname||`/`,p=f;if(c!==`/`){let e=c.replace(/^\//,``).split(`/`);p=`/`+f.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let m=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):Hs(e,{pathname:p});Ps(l||m!=null,`No routes matched location "${d.pathname}${d.search}${d.hash}" `),Ps(m==null||m[m.length-1].route.element!==void 0||m[m.length-1].route.Component!==void 0||m[m.length-1].route.lazy!==void 0,`Matched leaf route at location "${d.pathname}${d.search}${d.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let h=dl(m&&m.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:gc([c,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?c:gc([c,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&h?X.createElement(Rc.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...d},navigationType:`POP`}},h):h}function al(){let e=vl(),t=Sc(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},o=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),o=X.createElement(X.Fragment,null,X.createElement(`p`,null,`💿 Hey developer 👋`),X.createElement(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,X.createElement(`code`,{style:a},`ErrorBoundary`),` or`,` `,X.createElement(`code`,{style:a},`errorElement`),` prop on your route.`)),X.createElement(X.Fragment,null,X.createElement(`h2`,null,`Unexpected Application Error!`),X.createElement(`h3`,{style:{fontStyle:`italic`}},t),n?X.createElement(`pre`,{style:i},n):null,o)}var ol=X.createElement(al,null),sl=class extends X.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=Gc(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:X.createElement(zc.Provider,{value:this.props.routeContext},X.createElement(Bc.Provider,{value:e,children:this.props.component}));return this.context?X.createElement(ll,{error:e},t):t}};sl.contextType=Mc;var cl=new WeakMap;function ll({children:e,error:t}){let{basename:n}=X.useContext(Lc);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=Wc(t.digest);if(e){let r=cl.get(t);if(r)throw r;let i=Tc(e.location,n),a=i.absoluteURL||i.to;if(kc(a))throw Error(`Invalid redirect location`);if(wc&&!cl.get(t)){if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw cl.set(t,n),n}}return X.createElement(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function ul({routeContext:e,match:t,children:n}){let r=X.useContext(Ac);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),X.createElement(zc.Provider,{value:e},n)}function dl(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);Ns(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:Cc(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,d=!1,f=null,p=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,f=n.route.errorElement||ol,o&&(s<0&&c===0?(xl(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),d=!0,p=null):s===c&&(d=!0,p=n.route.hydrateFallbackElement||null)));let m=t.concat(i.slice(0,c+1)),h=()=>{let t;return t=u?f:d?p:n.route.Component?X.createElement(n.route.Component,null):n.route.element?n.route.element:e,X.createElement(ul,{match:n,routeContext:{outlet:e,matches:m,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?X.createElement(sl,{location:r.location,revalidation:r.revalidation,component:f,error:u,children:h(),routeContext:{outlet:null,matches:m,isDataRoute:!0},onError:l}):h()},null)}function fl(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function pl(e){let t=X.useContext(Ac);return Ns(t,fl(e)),t}function ml(e){let t=X.useContext(jc);return Ns(t,fl(e)),t}function hl(e){let t=X.useContext(zc);return Ns(t,fl(e)),t}function gl(e){let t=hl(e),n=t.matches[t.matches.length-1];return Ns(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function _l(){return gl(`useRouteId`)}function vl(){let e=X.useContext(Bc),t=ml(`useRouteError`),n=gl(`useRouteError`);return e===void 0?t.errors?.[n]:e}function yl(){let{router:e}=pl(`useNavigate`),t=gl(`useNavigate`),n=X.useRef(!1);return Xc(()=>{n.current=!0}),X.useCallback(async(r,i={})=>{Ps(n.current,Yc),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var bl={};function xl(e,t,n){!t&&!bl[e]&&(bl[e]=!0,Ps(!1,n))}X.memo(Sl);function Sl({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return il(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function Cl({to:e,replace:t,state:n,relative:r}){Ns(qc(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=X.useContext(Lc);Ps(!i,`<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`);let{matches:a}=X.useContext(zc),{pathname:o}=Jc(),s=Zc(),c=mc(e,pc(a),o,r===`path`),l=JSON.stringify(c);return X.useEffect(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function wl(e){return el(e.context)}function Tl(e){Ns(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function El({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:o}){Ns(!qc(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=X.useMemo(()=>({basename:s,navigator:i,static:a,useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=zs(n));let{pathname:l=`/`,search:u=``,hash:d=``,state:f=null,key:p=`default`,mask:m}=n,h=X.useMemo(()=>{let e=cc(l,s);return e==null?null:{location:{pathname:e,search:u,hash:d,state:f,key:p,mask:m},navigationType:r}},[s,l,u,d,f,p,r,m]);return Ps(h!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${d}" because it does not start with the basename, so the <Router> won't render anything.`),h==null?null:X.createElement(Lc.Provider,{value:c},X.createElement(Rc.Provider,{children:t,value:h}))}function Dl({children:e,location:t}){return rl(Ol(e),t)}X.Component;function Ol(e,t=[]){let n=[];return X.Children.forEach(e,(e,r)=>{if(!X.isValidElement(e))return;let i=[...t,r];if(e.type===X.Fragment){n.push.apply(n,Ol(e.props.children,i));return}Ns(e.type===Tl,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),Ns(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=Ol(e.props.children,i)),n.push(a)}),n}var kl=`get`,Al=`application/x-www-form-urlencoded`;function jl(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function Ml(e){return jl(e)&&e.tagName.toLowerCase()===`button`}function Nl(e){return jl(e)&&e.tagName.toLowerCase()===`form`}function Pl(e){return jl(e)&&e.tagName.toLowerCase()===`input`}function Fl(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Il(e,t){return e.button===0&&(!t||t===`_self`)&&!Fl(e)}function Ll(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function Rl(e,t){let n=Ll(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var zl=null;function Bl(){if(zl===null)try{new FormData(document.createElement(`form`),0),zl=!1}catch{zl=!0}return zl}var Vl=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function Hl(e){return e!=null&&!Vl.has(e)?(Ps(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Al}"`),null):e}function Ul(e,t){let n,r,i,a,o;if(Nl(e)){let o=e.getAttribute(`action`);r=o?cc(o,t):null,n=e.getAttribute(`method`)||kl,i=Hl(e.getAttribute(`enctype`))||Al,a=new FormData(e)}else if(Ml(e)||Pl(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?cc(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||kl,i=Hl(e.getAttribute(`formenctype`))||Hl(o.getAttribute(`enctype`))||Al,a=new FormData(o,e),!Bl()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(jl(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=kl,r=null,i=Al,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);function Wl(e,t){if(e===!1||e==null)throw Error(t)}function Gl(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return i.pathname=n?i.pathname.endsWith(`/`)?`${i.pathname}_.${r}`:`${i.pathname}.${r}`:i.pathname===`/`?`_root.${r}`:t&&cc(i.pathname,t)===`/`?`${_c(t)}/_root.${r}`:`${_c(i.pathname)}.${r}`,i}async function Kl(e,t){if(e.id in t)return t[e.id];try{let n=await m(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function ql(e){return e!=null&&typeof e.page==`string`}function Jl(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function Yl(e,t,n){return eu((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await Kl(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(Jl).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function Xl(e,t,n,r,i,a){let o=(e,t)=>!n[t]||e.route.id!==n[t].route.id,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function Zl(e,t,{includeHydrateFallback:n}={}){return Ql(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function Ql(e){return[...new Set(e)]}function $l(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function eu(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!ql(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify($l(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function tu(){let e=X.useContext(Ac);return Wl(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function nu(){let e=X.useContext(jc);return Wl(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var ru=X.createContext(void 0);ru.displayName=`FrameworkContext`;function iu(){let e=X.useContext(ru);return Wl(e,`You must render this element inside a <HydratedRouter> element`),e}function au(e,t){let n=X.useContext(ru),[r,i]=X.useState(!1),[a,o]=X.useState(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=X.useRef(null);X.useEffect(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),X.useEffect(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let p=()=>{i(!0)},m=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:ou(s,p),onBlur:ou(c,m),onMouseEnter:ou(l,p),onMouseLeave:ou(u,m),onTouchStart:ou(d,p)}]:[a,f,{}]:[!1,f,{}]}function ou(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function su({page:e,...t}){let n=Nc(),{nonce:r}=iu(),{router:i}=tu(),a=X.useMemo(()=>Hs(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),n?X.createElement(lu,{page:e,matches:a,...t}):X.createElement(uu,{page:e,matches:a,...t})):null}function cu(e){let{manifest:t,routeModules:n}=iu(),[r,i]=X.useState([]);return X.useEffect(()=>{let r=!1;return Yl(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function lu({page:e,matches:t,...n}){let r=Jc(),{future:i}=iu(),{basename:a}=tu(),o=X.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=Gl(e,a,i.v8_trailingSlashAwareDataRequests,`rsc`),o=!1,s=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?o=!0:s.push(e.route.id);return o&&s.length>0&&n.searchParams.set(`_routes`,s.join(`,`)),[n.pathname+n.search]},[a,i.v8_trailingSlashAwareDataRequests,e,r,t]);return X.createElement(X.Fragment,null,o.map(e=>X.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function uu({page:e,matches:t,...n}){let r=Jc(),{future:i,manifest:a,routeModules:o}=iu(),{basename:s}=tu(),{loaderData:c,matches:l}=nu(),u=X.useMemo(()=>Xl(e,t,l,a,r,`data`),[e,t,l,a,r]),d=X.useMemo(()=>Xl(e,t,l,a,r,`assets`),[e,t,l,a,r]),f=X.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,l=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!u.some(t=>t.route.id===e.route.id)&&e.route.id in c&&o[e.route.id]?.shouldRevalidate||t.hasClientLoader?l=!0:n.add(e.route.id))}),n.size===0)return[];let d=Gl(e,s,i.v8_trailingSlashAwareDataRequests,`data`);return l&&n.size>0&&d.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[d.pathname+d.search]},[s,i.v8_trailingSlashAwareDataRequests,c,r,a,u,t,e,o]),p=X.useMemo(()=>Zl(d,a),[d,a]),m=cu(d);return X.createElement(X.Fragment,null,f.map(e=>X.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),p.map(e=>X.createElement(`link`,{key:e,rel:`modulepreload`,href:e,...n})),m.map(({key:e,link:t})=>X.createElement(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function du(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}X.Component;var fu=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{fu&&(window.__reactRouterVersion=`7.18.2`)}catch{}function pu({basename:e,children:t,useTransitions:n,window:r}){let i=X.useRef();i.current??=Ms({window:r,v5Compat:!0});let a=i.current,[o,s]=X.useState({action:a.action,location:a.location}),c=X.useCallback(e=>{n===!1?s(e):X.startTransition(()=>s(e))},[n]);return X.useLayoutEffect(()=>a.listen(c),[a,c]),X.createElement(El,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:a,useTransitions:n})}var mu=X.forwardRef(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m){let{basename:h,navigator:g,useTransitions:_}=X.useContext(Lc),v=typeof l==`string`&&Es.test(l),y=Tc(l,h);l=y.to;let b=Kc(l,{relative:r}),x=Jc(),S=null;if(o){let e=mc(o,[],x.mask?x.mask.pathname:`/`,!0);h!==`/`&&(e.pathname=e.pathname===`/`?h:gc([h,e.pathname])),S=g.createHref(e)}let[C,w,T]=au(n,p),E=yu(l,{replace:a,mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:d,defaultShouldRevalidate:f,useTransitions:_});function D(t){e&&e(t),t.defaultPrevented||E(t)}let O=!(y.isExternal||i),k=X.createElement(`a`,{...p,...T,href:(O?S:void 0)||y.absoluteURL||b,onClick:O?D:e,ref:du(m,w),target:c,"data-discover":!v&&t===`render`?`true`:void 0});return C&&!v?X.createElement(X.Fragment,null,k,X.createElement(su,{page:b})):k});mu.displayName=`Link`;var hu=X.forwardRef(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=nl(a,{relative:c.relative}),d=Jc(),f=X.useContext(jc),{navigator:p,basename:m}=X.useContext(Lc),h=f!=null&&Tu(u)&&o===!0,g=p.encodeLocation?p.encodeLocation(u).pathname:u.pathname,_=d.pathname,v=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;t||(_=_.toLowerCase(),v=v?v.toLowerCase():null,g=g.toLowerCase()),v&&m&&(v=cc(v,m)||v);let y=g!==`/`&&g.endsWith(`/`)?g.length-1:g.length,b=_===g||!r&&_.startsWith(g)&&_.charAt(y)===`/`,x=v!=null&&(v===g||!r&&v.startsWith(g)&&v.charAt(g.length)===`/`),S={isActive:b,isPending:x,isTransitioning:h},C=b?e:void 0,w;w=typeof n==`function`?n(S):[n,b?`active`:null,x?`pending`:null,h?`transitioning`:null].filter(Boolean).join(` `);let T=typeof i==`function`?i(S):i;return X.createElement(mu,{...c,"aria-current":C,className:w,ref:l,style:T,to:a,viewTransition:o},typeof s==`function`?s(S):s)});hu.displayName=`NavLink`;var gu=X.forwardRef(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=kl,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m)=>{let{useTransitions:h}=X.useContext(Lc),g=Cu(),_=wu(s,{relative:l}),v=o.toLowerCase()===`get`?`get`:`post`,y=typeof s==`string`&&Es.test(s);return X.createElement(`form`,{ref:m,method:v,action:_,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,p=()=>g(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f});h&&n!==!1?X.startTransition(()=>p()):p()},...p,"data-discover":!y&&e===`render`?`true`:void 0})});gu.displayName=`Form`;function _u(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function vu(e){let t=X.useContext(Ac);return Ns(t,_u(e)),t}function yu(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=Zc(),d=Jc(),f=nl(e,{relative:o});return X.useCallback(p=>{if(Il(p,t)){p.preventDefault();let t=n===void 0?Rs(d)===Rs(f):n,m=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?X.startTransition(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function bu(e){Ps(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=X.useRef(Ll(e)),n=X.useRef(!1),r=Jc(),i=X.useMemo(()=>Rl(r.search,n.current?null:t.current),[r.search]),a=Zc();return[i,X.useCallback((e,t)=>{let r=Ll(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var xu=0,Su=()=>`__${String(++xu)}__`;function Cu(){let{router:e}=vu(`useSubmit`),{basename:t}=X.useContext(Lc),n=_l(),r=e.fetch,i=e.navigate;return X.useCallback(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=Ul(e,t);if(a.navigate===!1){let e=a.fetcherKey||Su();await r(e,n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync})}else await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function wu(e,{relative:t}={}){let{basename:n}=X.useContext(Lc),r=X.useContext(zc);Ns(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...nl(e||`.`,{relative:t})},o=Jc();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:gc([n,a.pathname])),Rs(a)}function Tu(e,{relative:t}={}){let n=X.useContext(Pc);Ns(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=vu(`useViewTransitionState`),i=nl(e,{relative:t});if(!n.isTransitioning)return!1;let a=cc(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=cc(n.nextLocation.pathname,r)||n.nextLocation.pathname;return ic(i.pathname,o)!=null||ic(i.pathname,a)!=null}var Z=f(),Eu=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Qn,{ref:n,className:K(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,e),...t}));Eu.displayName=Qn.displayName;var Du=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`rounded-lg border bg-card text-card-foreground shadow-elevation-1`,e),...t}));Du.displayName=`Card`;var Ou=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`flex flex-col space-y-1.5 p-6`,e),...t}));Ou.displayName=`CardHeader`;var ku=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`h3`,{ref:n,className:K(`text-2xl font-semibold leading-none tracking-tight`,e),...t}));ku.displayName=`CardTitle`;var Au=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`p`,{ref:n,className:K(`text-sm text-muted-foreground`,e),...t}));Au.displayName=`CardDescription`;var ju=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`p-6 pt-0`,e),...t}));ju.displayName=`CardContent`;var Mu=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`flex items-center p-6 pt-0`,e),...t}));Mu.displayName=`CardFooter`;var Nu=`2.14.17`,Pu=e=>{window.particlesJS.load(e,`/js/particles.config.json`,()=>{console.log(`particles.js config loaded for`,e)})};function Fu(e){(0,X.useEffect)(()=>{if(window.particlesJS!==void 0)Pu(e);else{if(document.getElementById(`particles-js-script`))return;let t=document.createElement(`script`);t.id=`particles-js-script`,t.src=`/js/particles.min.js`,t.onload=()=>{console.log(`particles.js loaded`),Pu(e)},document.head.appendChild(t)}return()=>{window.pJS&&window.pJS[e]?.destroy&&window.pJS[e].destroy()}},[e])}var Iu=`session.open`,Lu=`session.set`,Ru=`session.ids`,zu=`session.materialize`,Bu=`session.close`,Vu=`session.delta`;function Hu(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)(!0),[i,a]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!0;async function n(){try{r(!0),a(null);let n=await Y.get(`/ping`,{skipAuth:!0});e&&(n?.version?t(n.version):a(`Invalid server response`))}catch(t){e&&(console.error(`Failed to fetch server version:`,t),a(`Unable to connect to server`))}finally{e&&r(!1)}}n();let i=setInterval(n,3e4);return()=>{e=!1,clearInterval(i)}},[]),{serverVersion:e,isLoading:n,error:i}}var Uu=`https://github.com/canvas-ui/canvas-server`,Wu=null;function Gu(){return Wu||=Y.get(`/ping`,{skipAuth:!0}).then(e=>{let t=e??{};return{sourceUrl:t.sourceUrl||Uu,version:t.version??null,commit:t.commit??null,license:t.license??null}}).catch(e=>(console.error(`Failed to fetch server source info:`,e),Wu=null,{sourceUrl:Uu,version:null,commit:null,license:null})),Wu}function Ku(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!0;return Gu().then(n=>{e&&t(n)}),()=>{e=!1}},[]),e}function qu({className:e=``}){let t=Ku();if(!t)return null;let n=[t.version?`v${t.version}`:null,t.commit?.slice(0,7)].filter(Boolean).join(` `);return(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground ${e}`,children:[`Powered by`,` `,(0,Z.jsx)(`a`,{href:t.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Canvas`}),n?` ${n}`:``,t.license?`, ${t.license}`:``,`.`,` `,(0,Z.jsx)(`a`,{href:t.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})}function Ju({children:e}){Fu(`particle-js`);let{serverVersion:t,isLoading:n,error:r}=Hu();return(0,Z.jsx)(`div`,{className:`flex min-h-viewport w-full items-center justify-center p-4 flex-col`,children:(0,Z.jsxs)(Du,{className:`flex w-[95vw] h-viewport-modal overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`hidden md:block w-1/2 relative bg-background`,"data-scheme":`dark`,id:`particle-js`,children:[(0,Z.jsxs)(mu,{className:`absolute top-8 left-8 font-bold text-foreground flex items-center z-raised`,to:`/`,children:[(0,Z.jsx)(`img`,{src:`/images/logo-wr_128x128.png`,alt:`Canvas Logo`,className:`mr-2 h-6 w-6 touch-target`}),(0,Z.jsx)(`span`,{className:`text-2xl font-bold text-foreground`,children:`Canvas`})]}),(0,Z.jsxs)(`div`,{className:`absolute bottom-8 left-8 text-sm text-foreground max-w-[80%] z-raised`,children:[`Web UI: v`,Nu,`, Server: `,n?`Loading...`:r?`Unavailable`:t?`v${t}`:`Unknown`]})]}),(0,Z.jsx)(`div`,{className:`flex w-full md:w-1/2 flex-col justify-center px-4 py-12 sm:px-6 lg:px-8`,children:(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-sm`,children:[e,(0,Z.jsxs)(`div`,{className:`mt-8 border-t pt-6`,children:[(0,Z.jsxs)(`a`,{href:`https://github.com/canvas-ui`,target:`_blank`,className:`text-muted-foreground hover:text-foreground justify-center flex items-center space-x-2`,rel:`noopener noreferrer`,children:[(0,Z.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`24`,height:`24`,stroke:`currentColor`,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-6 h-6`,children:(0,Z.jsx)(`path`,{d:`M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22`})}),(0,Z.jsx)(`span`,{children:`View on GitHub`})]}),(0,Z.jsx)(qu,{className:`mt-4 text-center`})]})]})})]})})}function Yu(){let e=localStorage.getItem(`authToken`);return!e||e===`canvas-server-token`?null:e}var Xu=new class{socket=null;connected=!1;authToken=null;handlers=new Map;socketWrappers=new Map;desiredSubscriptions=new Set;baseUrl;connectionId=``;constructor(){this.baseUrl=si,this.connectionId=`socket-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}connect(e){let t=e||Yu();!t||t===`canvas-server-token`||this.socket&&this.authToken===t||(this.cleanupSocket(),this.authToken=t,this.socket=$a(this.baseUrl,{transports:[`websocket`],autoConnect:!1,reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:1e3,reconnectionDelayMax:3e4,randomizationFactor:.5,timeout:1e4,forceNew:!0,extraHeaders:{Authorization:`Bearer ${t}`,"X-Connection-ID":this.connectionId},auth:{token:t}}),this.setupDefaultHandlers(),this.registerHandlers(),this.socket.connect())}cleanupSocket(){this.socket?.removeAllListeners(),this.socket?.disconnect(),this.socket=null,this.connected=!1,this.socketWrappers.clear()}setupDefaultHandlers(){this.socket&&(this.socket.on(`connect`,()=>{this.connected=!0;for(let e of this.desiredSubscriptions)this.socket?.emit(`subscribe`,{channel:e})}),this.socket.on(`disconnect`,()=>{this.connected=!1}),this.socket.on(`connect_error`,()=>{this.connected=!1}))}registerHandlers(){this.socket&&this.handlers.forEach((e,t)=>{e.forEach(e=>{this.attach(t,e)})})}attach(e,t){if(!this.socket)return;let n=this.socketWrappers.get(e);if(n||(n=new Map,this.socketWrappers.set(e,n)),n.has(t))return;let r=(...e)=>t(...e);n.set(t,r),this.socket.on(e,r)}detach(e,t){if(!this.socket)return;let n=this.socketWrappers.get(e),r=n?.get(t);r&&(this.socket.off(e,r),n?.delete(t),n&&n.size===0&&this.socketWrappers.delete(e))}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set);let n=this.handlers.get(e);return n.has(t)?()=>this.off(e,t):(n.add(t),this.socket&&this.attach(e,t),()=>this.off(e,t))}off(e,t){let n=this.handlers.get(e);n&&n.has(t)&&(n.delete(t),n.size===0&&this.handlers.delete(e),this.detach(e,t))}request(e,t,n=1e4){return new Promise((r,i)=>{if(!this.socket||!this.connected){i(Error(`Socket not connected`));return}let a=!1,o=setTimeout(()=>{a||(a=!0,i(Error(`Socket request timed out: ${e}`)))},n);try{this.socket.emit(e,t??{},t=>{a||(a=!0,clearTimeout(o),t?.status===`error`?i(Error(t.message||`${e} failed`)):r(t?.payload??t))})}catch(e){a=!0,clearTimeout(o),i(e instanceof Error?e:Error(String(e)))}})}emit(e,...t){if(e===`subscribe`){let e=t?.[0]?.channel;typeof e==`string`&&e&&this.desiredSubscriptions.add(e)}else if(e===`unsubscribe`){let e=t?.[0]?.channel;typeof e==`string`&&e&&this.desiredSubscriptions.delete(e)}if(this.socket&&this.connected)try{this.socket.emit(e,...t)}catch(t){console.error(`Error emitting event ${e}:`,t),this.reconnect()}else this.connect()}disconnect(){this.cleanupSocket(),this.authToken=null,this.desiredSubscriptions.clear()}isConnected(){return this.connected}retryNow(){this.connected||(this.cleanupSocket(),this.connect())}reconnect(){this.connect()}};async function Zu(e,t,n=`auto`){try{let r=await Y.post(Qr.login,{email:e,password:t,strategy:n},{skipAuth:!0});console.log(`Login response:`,r);let i=r;if(`token`in i)return console.log(`Setting auth token (direct):`,i.token.substring(0,10)+`...`),Y.setAuthToken(i.token),Xu.connect(i.token),r;if(i&&`payload`in i&&i.payload&&i.payload.token)return console.log(`Setting auth token (nested):`,i.payload.token.substring(0,10)+`...`),Y.setAuthToken(i.payload.token),Xu.connect(i.payload.token),r;throw console.error(`Invalid login response structure:`,r),Error(`Invalid login response: missing token`)}catch(e){throw console.error(`Login error:`,e),Y.clearAuthToken(),e}}async function Qu(e,t,n){try{return await Y.post(Qr.register,{name:e,email:t,password:n},{skipAuth:!0})}catch(e){throw console.error(`Registration failed:`,e),e}}function $u(e){return e instanceof Error&&/^Network error/i.test(e.message)}function ed(){let e=localStorage.getItem(`authToken`);if(!e)return!1;if(e.startsWith(`canvas-`))return!0;try{return br(e).exp*1e3>Date.now()}catch{return!1}}function td(){let e=localStorage.getItem(`authToken`);if(!e||e.startsWith(`canvas-`))return null;try{let t=br(e);return t.exp*1e3<Date.now()?(Y.clearAuthToken(),null):{id:t.sub,email:t.email,userType:t.userType||`user`}}catch(e){return console.error(`Failed to decode token:`,e),Y.clearAuthToken(),null}}async function nd(){try{if(!Y.isAuthenticated())return console.log(`Not authenticated, skipping getCurrentUser request`),null;let e=await Y.get(Qr.me);return console.log(`Current user response:`,e),e&&e?(Xu.isConnected()||Xu.reconnect(),e):(console.warn(`Invalid user profile response structure:`,e),null)}catch(e){if(console.error(`Failed to get current user:`,e),$u(e))throw e;return e instanceof Error&&(e.message.includes(`USER_NOT_FOUND_IN_DATABASE`)||e.message.includes(`Your session is invalid`)||e.message.includes(`Authentication required`)||e.message.includes(`user account no longer exists`))?(console.warn(`Authentication error detected, clearing token:`,e.message),Y.clearAuthToken(),Xu.disconnect(),null):null}}function rd(){return Y.isAuthenticated()}async function id(){try{let e=await Y.get(Qr.authConfig,{skipAuth:!0});return e||e}catch(e){return console.error(`Failed to get auth config:`,e),{strategies:{local:{enabled:!0},imap:{enabled:!1,domains:[]}}}}}async function ad(e){try{await Y.post(Qr.verifyEmailRequest,{email:e},{skipAuth:!0})}catch(e){throw console.error(`Failed to request email verification:`,e),e}}var od=e=>e?.strategies?.local?.enabled!==!1,sd=e=>e?.allowUserRegistrations!==!1;function cd(){let e=Zc(),[t,n]=X.useState(!1),[r,i]=X.useState({}),[a,o]=X.useState(null),[s,c]=X.useState({email:``,password:``,strategy:`auto`});X.useEffect(()=>{rd()&&e(`/workspaces`),id().then(e=>{o(e)}).catch(e=>{console.error(`Failed to load auth config:`,e)})},[e]);let l=()=>{let e={};return s.email?/\S+@\S+\.\S+/.test(s.email)||(e.email=`Email is invalid`):e.email=`Email is required`,s.password||(e.password=`Password is required`),i(e),Object.keys(e).length===0},u=e=>{let{name:t,value:n}=e.target;c(e=>({...e,[t]:n}))};async function d(t){if(t.preventDefault(),l()){n(!0);try{console.log(`Attempting login with:`,s.email,`strategy:`,s.strategy);let t=await Zu(s.email,s.password,s.strategy);console.log(`Login successful, received token:`,`token`in t?!!t.token:!!t.payload?.token),i({}),e(`/home`)}catch(e){console.error(`Login error:`,e);let t=`Login failed`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;n.message?t=n.message:n.error?t=n.error:n.payload?.message&&(t=n.payload.message)}i({password:t})}finally{n(!1)}}}return(0,Z.jsx)(Ju,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-2 text-center`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Welcome back`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Enter your credentials to access your account`})]}),(0,Z.jsx)(`form`,{onSubmit:d,children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[a?.strategies?.imap?.enabled&&a.strategies.imap.domains.length>0&&(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`strategy`,children:`Authentication Method`}),(0,Z.jsxs)(`select`,{id:`strategy`,name:`strategy`,value:s.strategy,onChange:u,disabled:t,className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Z.jsx)(`option`,{value:`auto`,children:`Auto-detect`}),(0,Z.jsx)(`option`,{value:`local`,children:`Local Account`}),(0,Z.jsx)(`option`,{value:`imap`,children:`Email Server (IMAP)`})]})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`email`,children:`Email`}),(0,Z.jsx)(q,{id:`email`,name:`email`,placeholder:`name@example.com`,type:`email`,autoCapitalize:`none`,autoComplete:`email`,autoCorrect:`off`,disabled:t,value:s.email,onChange:u}),r.email&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:r.email})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`password`,children:`Password`}),(0,Z.jsx)(q,{id:`password`,name:`password`,type:`password`,disabled:t,value:s.password,onChange:u}),r.password&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:r.password})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-4`,children:[(0,Z.jsx)(J,{type:`submit`,disabled:t,children:t?`Signing in...`:`Sign In`}),od(a)&&sd(a)&&(0,Z.jsx)(J,{variant:`outline`,type:`button`,disabled:t,onClick:()=>e(`/register`),children:`Don't have an account? Sign up`})]})]})})]})})}function ld(){let e=Zc(),{showToast:t}=po(),[n,r]=X.useState(!1),[i,a]=X.useState({}),[o,s]=X.useState({name:``,email:``,password:``}),[c,l]=X.useState(!1),[u,d]=X.useState(!1),[f,p]=X.useState(null);X.useEffect(()=>{(async()=>{let t=await id(),n=t?.strategies?.local;if(t?.allowUserRegistrations===!1||n?.enabled===!1){e(`/login`,{replace:!0});return}n?.passwordPolicy&&p(n.passwordPolicy),d(!!n?.requireEmailVerification)})()},[e]);let m=X.useMemo(()=>{if(!f)return null;let e=o.password||``;return{minLength:!f.minLength||e.length>=f.minLength,maxLength:!f.maxLength||e.length<=f.maxLength,uppercase:!f.requireUppercase||/[A-Z]/.test(e),lowercase:!f.requireLowercase||/[a-z]/.test(e),number:!f.requireNumbers||/[0-9]/.test(e),special:!f.requireSpecialChars||/[^A-Za-z0-9]/.test(e)}},[f,o.password]),h=()=>{let e={};if(!o.name)e.name=`Username is required`;else if(o.name.trim().length===0)e.name=`Username cannot be empty`;else{let t=o.name.toLowerCase().trim();t.length<3?e.name=`Username must be at least 3 characters long`:t.length>39?e.name=`Username cannot be longer than 39 characters`:/^[a-z0-9_-]+$/.test(t)?[`admin`,`administrator`,`root`,`system`,`support`,`help`,`api`,`www`,`mail`,`ftp`,`localhost`,`test`,`demo`,`canvas`,`universe`,`workspace`,`context`,`user`,`users`].includes(t)&&(e.name=`Username '${t}' is reserved and cannot be used`):e.name=`Username can only contain lowercase letters, numbers, underscores, and hyphens`}if(o.email?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o.email)||(e.email=`Please enter a valid email address`):e.email=`Email is required`,!o.password)e.password=`Password is required`;else if(f){let t=o.password,n=[];f.minLength&&t.length<f.minLength&&n.push(`at least ${f.minLength} characters`),f.maxLength&&t.length>f.maxLength&&n.push(`no more than ${f.maxLength} characters`),f.requireUppercase&&!/[A-Z]/.test(t)&&n.push(`an uppercase letter`),f.requireLowercase&&!/[a-z]/.test(t)&&n.push(`a lowercase letter`),f.requireNumbers&&!/[0-9]/.test(t)&&n.push(`a number`),f.requireSpecialChars&&!/[^A-Za-z0-9]/.test(t)&&n.push(`a special character`),n.length&&(e.password=`Password must contain ${n.join(`, `).replace(/, ([^,]*)$/,` and $1`)}.`)}else o.password.length<8&&(e.password=`Password must be at least 8 characters long`);return a(e),Object.keys(e).length===0},g=e=>{let t={...o,[e.target.id]:e.target.value};s(t),(e.target.id===`name`||e.target.id===`email`||e.target.id===`password`)&&h()};return c?(0,Z.jsxs)(Ju,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-2 text-center`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Registration Successful!`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:u?`Check your email for a verification link to activate your account.`:`Your account has been created.`})]}),(0,Z.jsx)(`div`,{className:`space-y-6 text-center pt-6`,children:!u&&(0,Z.jsx)(J,{asChild:!0,className:`w-full`,children:(0,Z.jsx)(mu,{to:`/login`,children:`Go to Login`})})})]}):(0,Z.jsxs)(Ju,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-2 text-center`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Create an account`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Enter your email below to create your account`})]}),(0,Z.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),h()){r(!0);try{let e=await Qu(o.name,o.email,o.password);console.log(`Registration successful:`,e),t({title:`Registration Successful`,description:u?`Check your email for a verification link before logging in.`:`You can now log in with your credentials.`,variant:`default`}),l(!0),s({name:``,email:``,password:``}),a({})}catch(e){console.error(`Registration failed:`,e);let n=e?.message||`Registration failed`;n.toLowerCase().includes(`password`)?a({...i,password:n}):a({...i,email:n}),t({title:`Registration Failed`,description:n,variant:`destructive`})}finally{r(!1)}}},className:`space-y-4 pt-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`name`,children:`Username`}),(0,Z.jsx)(q,{id:`name`,type:`text`,placeholder:`Enter your username (e.g., john_doe)`,value:o.name,onChange:g,disabled:n,className:i.name?`border-destructive`:``}),i.name&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:i.name}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`3-39 characters, lowercase letters, numbers, underscores, and hyphens only`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`email`,children:`Email`}),(0,Z.jsx)(q,{id:`email`,type:`email`,placeholder:`name@example.com`,value:o.email,onChange:g,disabled:n,className:i.email?`border-destructive`:``}),i.email&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:i.email})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`password`,children:`Password`}),(0,Z.jsx)(q,{id:`password`,type:`password`,placeholder:`Enter your password`,value:o.password,onChange:g,disabled:n,className:i.password?`border-destructive`:``}),i.password&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:i.password}),f&&m&&(0,Z.jsxs)(`ul`,{className:`text-xs list-disc pl-4 space-y-1`,children:[(0,Z.jsxs)(`li`,{className:m.minLength?`text-success`:`text-muted-foreground`,children:[`At least `,f.minLength,` characters`]}),f.requireUppercase&&(0,Z.jsx)(`li`,{className:m.uppercase?`text-success`:`text-muted-foreground`,children:`At least one uppercase letter`}),f.requireLowercase&&(0,Z.jsx)(`li`,{className:m.lowercase?`text-success`:`text-muted-foreground`,children:`At least one lowercase letter`}),f.requireNumbers&&(0,Z.jsx)(`li`,{className:m.number?`text-success`:`text-muted-foreground`,children:`At least one number`}),f.requireSpecialChars&&(0,Z.jsx)(`li`,{className:m.special?`text-success`:`text-muted-foreground`,children:`At least one special character`}),f.maxLength&&(0,Z.jsxs)(`li`,{className:m.maxLength?`text-success`:`text-muted-foreground`,children:[`No more than `,f.maxLength,` characters`]})]})]}),(0,Z.jsx)(J,{type:`submit`,className:`w-full`,disabled:n,children:n?`Creating Account...`:`Create Account`})]}),(0,Z.jsxs)(`div`,{className:`mt-4 text-center text-sm`,children:[`Already have an account?`,` `,(0,Z.jsx)(mu,{to:`/login`,className:`underline`,children:`Sign in`})]}),(0,Z.jsxs)(`div`,{className:`px-8 py-4 text-center text-sm text-muted-foreground border-t mt-6`,children:[`By clicking continue, you agree to our`,` `,(0,Z.jsx)(mu,{to:`/terms`,className:`underline underline-offset-4 hover:text-primary`,children:`Terms of Service`}),` `,`and`,` `,(0,Z.jsx)(mu,{to:`/privacy`,className:`underline underline-offset-4 hover:text-primary`,children:`Privacy Policy`}),`.`]})]})}function ud({className:e=`h-5 w-5`,...t}){return(0,Z.jsxs)(`svg`,{className:`animate-spin ${e}`,xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...t,children:[(0,Z.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,Z.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]})}function dd({children:e}){let[t,n]=(0,X.useState)(`loading`);return(0,X.useEffect)(()=>{(async()=>{try{if(!rd()){console.log(`No authentication token found, redirecting to login`),n(`unauthenticated`);return}let e=await nd();e?(console.log(`User authenticated:`,e.email),n(`authenticated`)):(console.log(`User not authenticated or token expired`),n(`unauthenticated`))}catch(e){if(console.error(`Authentication check failed:`,e),$u(e)){n(ed()?`authenticated`:`unauthenticated`);return}e instanceof Error&&e.message.includes(`Authentication required`)&&(console.log(`Clearing invalid token from ProtectedRoute`),Y.clearAuthToken()),n(`unauthenticated`)}})()},[]),t===`loading`?(0,Z.jsx)(`div`,{className:`flex h-screen items-center justify-center`,children:(0,Z.jsx)(ud,{className:`h-8 w-8`})}):t===`unauthenticated`?(0,Z.jsx)(Cl,{to:`/login`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}function fd({children:e}){let[t,n]=(0,X.useState)(null);return(0,X.useEffect)(()=>{(async()=>{try{await Y.get(`/auth/me`),n(!0)}catch(e){e instanceof Error&&e.message.includes(`Authentication required`)&&(console.log(`Clearing invalid token from PublicRoute`),Y.clearAuthToken()),n(!1)}})()},[]),t===null?null:t?(0,Z.jsx)(Cl,{to:`/workspaces`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}var pd=i(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?r(e):typeof define==`function`&&define.amd?define([`exports`],r):(n=typeof globalThis<`u`?globalThis:n||self,r(n[`fast-equals`]={}))})(e,(function(e){function t(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function n(e){return function(t,n,r,i){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r,i);var a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);var s=e(t,n,r,i);return i.delete(t),i.delete(n),s}}function r(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n}function i(e){return e.constructor===Object||e.constructor==null}function a(e){return typeof e.then==`function`}function o(e,t){return e===t||e!==e&&t!==t}var s=Object.prototype.toString;function c(e){var t=e.areArraysEqual,n=e.areDatesEqual,r=e.areMapsEqual,c=e.areObjectsEqual,l=e.areRegExpsEqual,u=e.areSetsEqual,d=e.createIsNestedEqual,f=d(p);function p(e,d,p){if(e===d)return!0;if(!e||!d||typeof e!=`object`||typeof d!=`object`)return e!==e&&d!==d;if(i(e)&&i(d))return c(e,d,f,p);var m=Array.isArray(e),h=Array.isArray(d);if(m||h)return m===h&&t(e,d,f,p);var g=s.call(e);return g===s.call(d)?g===`[object Date]`?n(e,d,f,p):g===`[object RegExp]`?l(e,d,f,p):g===`[object Map]`?r(e,d,f,p):g===`[object Set]`?u(e,d,f,p):g===`[object Object]`||g===`[object Arguments]`?a(e)||a(d)?!1:c(e,d,f,p):g===`[object Boolean]`||g===`[object Number]`||g===`[object String]`?o(e.valueOf(),d.valueOf()):!1:!1}return p}function l(e,t,n,r){var i=e.length;if(t.length!==i)return!1;for(;i-->0;)if(!n(e[i],t[i],i,i,e,t,r))return!1;return!0}var u=n(l);function d(e,t){return o(e.valueOf(),t.valueOf())}function f(e,t,n,r){var i=e.size===t.size;if(!i)return!1;if(!e.size)return!0;var a={},o=0;return e.forEach(function(s,c){if(i){var l=!1,u=0;t.forEach(function(i,d){!l&&!a[u]&&(l=n(c,d,o,u,e,t,r)&&n(s,i,c,d,e,t,r))&&(a[u]=!0),u++}),o++,i=l}}),i}var p=n(f),m=`_owner`,h=Object.prototype.hasOwnProperty;function g(e,t,n,r){var i=Object.keys(e),a=i.length;if(Object.keys(t).length!==a)return!1;for(var o;a-->0;){if(o=i[a],o===m){var s=!!e.$$typeof,c=!!t.$$typeof;if((s||c)&&s!==c)return!1}if(!h.call(t,o)||!n(e[o],t[o],o,o,e,t,r))return!1}return!0}var _=n(g);function v(e,t){return e.source===t.source&&e.flags===t.flags}function y(e,t,n,r){var i=e.size===t.size;if(!i)return!1;if(!e.size)return!0;var a={};return e.forEach(function(o,s){if(i){var c=!1,l=0;t.forEach(function(i,u){!c&&!a[l]&&(c=n(o,i,s,u,e,t,r))&&(a[l]=!0),l++}),i=c}}),i}var b=n(y),x=Object.freeze({areArraysEqual:l,areDatesEqual:d,areMapsEqual:f,areObjectsEqual:g,areRegExpsEqual:v,areSetsEqual:y,createIsNestedEqual:t}),S=Object.freeze({areArraysEqual:u,areDatesEqual:d,areMapsEqual:p,areObjectsEqual:_,areRegExpsEqual:v,areSetsEqual:b,createIsNestedEqual:t}),C=c(x);function w(e,t){return C(e,t,void 0)}var T=c(r(x,{createIsNestedEqual:function(){return o}}));function E(e,t){return T(e,t,void 0)}var D=c(S);function O(e,t){return D(e,t,new WeakMap)}var k=c(r(S,{createIsNestedEqual:function(){return o}}));function A(e,t){return k(e,t,new WeakMap)}function j(e){return c(r(x,e(x)))}function M(e){var t=c(r(S,e(S)));return(function(e,n,r){return r===void 0&&(r=new WeakMap),t(e,n,r)})}e.circularDeepEqual=O,e.circularShallowEqual=A,e.createCustomCircularEqual=M,e.createCustomEqual=j,e.deepEqual=w,e.sameValueZeroEqual=o,e.shallowEqual=E,Object.defineProperty(e,"__esModule",{value:!0})}))})),md=i(((e,t)=>{t.exports=function(e,t,n){return e===t||e.className===t.className&&n(e.style,t.style)&&e.width===t.width&&e.autoSize===t.autoSize&&e.cols===t.cols&&e.draggableCancel===t.draggableCancel&&e.draggableHandle===t.draggableHandle&&n(e.verticalCompact,t.verticalCompact)&&n(e.compactType,t.compactType)&&n(e.layout,t.layout)&&n(e.margin,t.margin)&&n(e.containerPadding,t.containerPadding)&&e.rowHeight===t.rowHeight&&e.maxRows===t.maxRows&&e.isBounded===t.isBounded&&e.isDraggable===t.isDraggable&&e.isResizable===t.isResizable&&e.allowOverlap===t.allowOverlap&&e.preventCollision===t.preventCollision&&e.useCSSTransforms===t.useCSSTransforms&&e.transformScale===t.transformScale&&e.isDroppable===t.isDroppable&&n(e.resizeHandles,t.resizeHandles)&&n(e.resizeHandle,t.resizeHandle)&&e.onLayoutChange===t.onLayoutChange&&e.onDragStart===t.onDragStart&&e.onDrag===t.onDrag&&e.onDragStop===t.onDragStop&&e.onResizeStart===t.onResizeStart&&e.onResize===t.onResize&&e.onResizeStop===t.onResizeStop&&e.onDrop===t.onDrop&&n(e.droppingItem,t.droppingItem)&&n(e.innerRef,t.innerRef)}})),hd=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.bottom=l,e.childrenEqual=h,e.cloneLayout=u,e.cloneLayoutItem=m,e.collides=_,e.compact=v,e.compactItem=x,e.compactType=ce,e.correctBounds=S,e.fastPositionEqual=g,e.fastRGLPropsEqual=void 0,e.getAllCollisions=T,e.getFirstCollision=w,e.getLayoutItem=C,e.getStatics=E,e.modifyLayout=f,e.moveElement=D,e.moveElementAwayFromCollision=O,e.noop=void 0,e.perc=k,e.resizeItemInDirection=ne,e.setTopLeft=ie,e.setTransform=re,e.sortLayoutItems=L,e.sortLayoutItemsByColRow=ae,e.sortLayoutItemsByRowCol=R,e.synchronizeLayoutWithChildren=oe,e.validateLayout=se,e.withLayoutItem=p;var t=pd(),n=r(d());function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?i(Object(n),!0).forEach(function(t){o(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function o(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e){var t=c(e,`string`);return typeof t==`symbol`?t:t+``}function c(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){let t=0,n;for(let r=0,i=e.length;r<i;r++)n=e[r].y+e[r].h,n>t&&(t=n);return t}function u(e){let t=Array(e.length);for(let n=0,r=e.length;n<r;n++)t[n]=m(e[n]);return t}function f(e,t){let n=Array(e.length);for(let r=0,i=e.length;r<i;r++)t.i===e[r].i?n[r]=t:n[r]=e[r];return n}function p(e,t,n){let r=C(e,t);return r?(r=n(m(r)),e=f(e,r),[e,r]):[e,null]}function m(e){return{w:e.w,h:e.h,x:e.x,y:e.y,i:e.i,minW:e.minW,maxW:e.maxW,minH:e.minH,maxH:e.maxH,moved:!!e.moved,static:!!e.static,isDraggable:e.isDraggable,isResizable:e.isResizable,resizeHandles:e.resizeHandles,isBounded:e.isBounded}}function h(e,r){return(0,t.deepEqual)(n.default.Children.map(e,e=>e?.key),n.default.Children.map(r,e=>e?.key))&&(0,t.deepEqual)(n.default.Children.map(e,e=>e?.props[`data-grid`]),n.default.Children.map(r,e=>e?.props[`data-grid`]))}e.fastRGLPropsEqual=md();function g(e,t){return e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height}function _(e,t){return!(e.i===t.i||e.x+e.w<=t.x||e.x>=t.x+t.w||e.y+e.h<=t.y||e.y>=t.y+t.h)}function v(e,t,n,r){let i=E(e),a=l(i),o=L(e,t),s=Array(e.length);for(let c=0,l=o.length;c<l;c++){let l=m(o[c]);l.static||(l=x(i,l,t,n,o,r,a),a=Math.max(a,l.y+l.h),i.push(l)),s[e.indexOf(o[c])]=l,l.moved=!1}return s}var y={x:`w`,y:`h`};function b(e,t,n,r){let i=y[r];t[r]+=1;let a=e.map(e=>e.i).indexOf(t.i);for(let o=a+1;o<e.length;o++){let a=e[o];if(!a.static){if(a.y>t.y+t.h)break;_(t,a)&&b(e,a,n+t[i],r)}}t[r]=n}function x(e,t,n,r,i,a,o){let s=n===`vertical`,c=n===`horizontal`;if(s)for(t.y=Math.min(typeof o==`number`?o:l(e),t.y);t.y>0&&!w(e,t);)t.y--;else if(c)for(;t.x>0&&!w(e,t);)t.x--;let u;for(;(u=w(e,t))&&!(n===null&&a);)if(c?b(i,t,u.x+u.w,`x`):b(i,t,u.y+u.h,`y`),c&&t.x+t.w>r)for(t.x=r-t.w,t.y++;t.x>0&&!w(e,t);)t.x--;return t.y=Math.max(t.y,0),t.x=Math.max(t.x,0),t}function S(e,t){let n=E(e);for(let r=0,i=e.length;r<i;r++){let i=e[r];if(i.x+i.w>t.cols&&(i.x=t.cols-i.w),i.x<0&&(i.x=0,i.w=t.cols),!i.static)n.push(i);else for(;w(n,i);)i.y++}return e}function C(e,t){for(let n=0,r=e.length;n<r;n++)if(e[n].i===t)return e[n]}function w(e,t){for(let n=0,r=e.length;n<r;n++)if(_(e[n],t))return e[n]}function T(e,t){return e.filter(e=>_(e,t))}function E(e){return e.filter(e=>e.static)}function D(e,t,n,r,i,a,o,s,c){if(t.static&&t.isDraggable!==!0||t.y===r&&t.x===n)return e;`${t.i}${String(n)}${String(r)}${t.x}${t.y}`;let l=t.x,d=t.y;typeof n==`number`&&(t.x=n),typeof r==`number`&&(t.y=r),t.moved=!0;let f=L(e,o);(o===`vertical`&&typeof r==`number`?d>=r:o===`horizontal`&&typeof n==`number`&&l>=n)&&(f=f.reverse());let p=T(f,t),m=p.length>0;if(m&&c)return u(e);if(m&&a)return`${t.i}`,t.x=l,t.y=d,t.moved=!1,e;for(let n=0,r=p.length;n<r;n++){let r=p[n];`${t.i}${t.x}${t.y}${r.i}${r.x}${r.y}`,!r.moved&&(e=r.static?O(e,r,t,i,o,s):O(e,t,r,i,o,s))}return e}function O(e,t,n,r,i,a){let o=i===`horizontal`,s=i===`vertical`,c=t.static;if(r){r=!1;let l={x:o?Math.max(t.x-n.w,0):n.x,y:s?Math.max(t.y-n.h,0):n.y,w:n.w,h:n.h,i:`-1`},u=w(e,l),d=u&&u.y+u.h>t.y,f=u&&t.x+t.w>u.x;if(!u)return`${n.i}${l.x}${l.y}`,D(e,n,o?l.x:void 0,s?l.y:void 0,r,c,i,a);if(d&&s)return D(e,n,void 0,n.y+1,r,c,i,a);if(d&&i==null)return t.y=n.y,n.y+=n.h,e;if(f&&o)return D(e,t,n.x,void 0,r,c,i,a)}let l=o?n.x+1:void 0,u=s?n.y+1:void 0;return l==null&&u==null?e:D(e,n,o?n.x+1:void 0,s?n.y+1:void 0,r,c,i,a)}function k(e){return e*100+`%`}var A=(e,t,n,r)=>e+n>r?t:n,j=(e,t,n)=>e<0?t:n,M=e=>Math.max(0,e),N=e=>Math.max(0,e),P=(e,t,n)=>{let{left:r,height:i,width:a}=t,o=e.top-(i-e.height);return{left:r,width:a,height:j(o,e.height,i),top:N(o)}},F=(e,t,n)=>{let{top:r,left:i,height:a,width:o}=t;return{top:r,height:a,width:A(e.left,e.width,o,n),left:M(i)}},I=(e,t,n)=>{let{top:r,height:i,width:a}=t,o=e.left-(a-e.width);return{height:i,width:o<0?e.width:A(e.left,e.width,a,n),top:N(r),left:M(o)}},ee=(e,t,n)=>{let{top:r,left:i,height:a,width:o}=t;return{width:o,left:i,height:j(r,e.height,a),top:N(r)}},te={n:P,ne:function(){return P(arguments.length<=0?void 0:arguments[0],F(...arguments),arguments.length<=2?void 0:arguments[2])},e:F,se:function(){return ee(arguments.length<=0?void 0:arguments[0],F(...arguments),arguments.length<=2?void 0:arguments[2])},s:ee,sw:function(){return ee(arguments.length<=0?void 0:arguments[0],I(...arguments),arguments.length<=2?void 0:arguments[2])},w:I,nw:function(){return P(arguments.length<=0?void 0:arguments[0],I(...arguments),arguments.length<=2?void 0:arguments[2])}};function ne(e,t,n,r){let i=te[e];return i?i(t,a(a({},t),n),r):n}function re(e){let{top:t,left:n,width:r,height:i}=e,a=`translate(${n}px,${t}px)`;return{transform:a,WebkitTransform:a,MozTransform:a,msTransform:a,OTransform:a,width:`${r}px`,height:`${i}px`,position:`absolute`}}function ie(e){let{top:t,left:n,width:r,height:i}=e;return{top:`${t}px`,left:`${n}px`,width:`${r}px`,height:`${i}px`,position:`absolute`}}function L(e,t){return t===`horizontal`?ae(e):t===`vertical`?R(e):e}function R(e){return e.slice(0).sort(function(e,t){return e.y>t.y||e.y===t.y&&e.x>t.x?1:e.y===t.y&&e.x===t.x?0:-1})}function ae(e){return e.slice(0).sort(function(e,t){return e.x>t.x||e.x===t.x&&e.y>t.y?1:-1})}function oe(e,t,r,i,o){e||=[];let s=[];n.default.Children.forEach(t,t=>{if(t?.key==null)return;let n=C(e,String(t.key)),r=t.props[`data-grid`];n&&r==null?s.push(m(n)):r?s.push(m(a(a({},r),{},{i:t.key}))):s.push(m({w:1,h:1,x:0,y:l(s),i:String(t.key)}))});let c=S(s,{cols:r});return o?c:v(c,i,r)}function se(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`Layout`,n=[`x`,`y`,`w`,`h`];if(!Array.isArray(e))throw Error(t+` must be an array!`);for(let r=0,i=e.length;r<i;r++){let i=e[r];for(let e=0;e<n.length;e++){let a=n[e],o=i[a];if(typeof o!=`number`||Number.isNaN(o))throw Error(`ReactGridLayout: ${t}[${r}].${a} must be a number! Received: ${o} (${typeof o})`)}if(i.i!==void 0&&typeof i.i!=`string`)throw Error(`ReactGridLayout: ${t}[${r}].i must be a string! Received: ${i.i} (${typeof i.i})`)}}function ce(e){let{verticalCompact:t,compactType:n}=e||{};return t===!1?null:n}e.noop=()=>{}})),gd=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.calcGridColWidth=t,e.calcGridItemPosition=r,e.calcGridItemWHPx=n,e.calcWH=a,e.calcXY=i,e.clamp=o;function t(e){let{margin:t,containerPadding:n,containerWidth:r,cols:i}=e;return(r-t[0]*(i-1)-n[0]*2)/i}function n(e,t,n){return Number.isFinite(e)?Math.round(t*e+Math.max(0,e-1)*n):e}function r(e,r,i,a,o,s){let{margin:c,containerPadding:l,rowHeight:u}=e,d=t(e),f={};return s&&s.resizing?(f.width=Math.round(s.resizing.width),f.height=Math.round(s.resizing.height)):(f.width=n(a,d,c[0]),f.height=n(o,u,c[1])),s&&s.dragging?(f.top=Math.round(s.dragging.top),f.left=Math.round(s.dragging.left)):s&&s.resizing&&typeof s.resizing.top==`number`&&typeof s.resizing.left==`number`?(f.top=Math.round(s.resizing.top),f.left=Math.round(s.resizing.left)):(f.top=Math.round((u+c[1])*i+l[1]),f.left=Math.round((d+c[0])*r+l[0])),f}function i(e,n,r,i,a){let{margin:s,containerPadding:c,cols:l,rowHeight:u,maxRows:d}=e,f=t(e),p=Math.round((r-c[0])/(f+s[0])),m=Math.round((n-c[1])/(u+s[1]));return p=o(p,0,l-i),m=o(m,0,d-a),{x:p,y:m}}function a(e,n,r,i,a,s){let{margin:c,maxRows:l,cols:u,rowHeight:d}=e,f=t(e),p=Math.round((n+c[0])/(f+c[0])),m=Math.round((r+c[1])/(d+c[1])),h=o(p,0,u-i),g=o(m,0,l-a);return[`sw`,`w`,`nw`].indexOf(s)!==-1&&(h=o(p,0,u)),[`nw`,`n`,`ne`].indexOf(s)!==-1&&(g=o(m,0,l)),{w:h,h:g}}function o(e,t,n){return Math.max(Math.min(e,n),t)}})),_d=i(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),vd=i(((e,t)=>{var n=_d();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),yd=i(((e,t)=>{t.exports=vd()()})),bd=i(((e,t)=>{var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})},u=(e,t,n,a)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let s of o(t))!c.call(e,s)&&s!==n&&r(e,s,{get:()=>t[s],enumerable:!(a=i(t,s))||a.enumerable});return e},f=(e,t,i)=>(i=e==null?{}:n(s(e)),u(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),p=e=>u(r({},`__esModule`,{value:!0}),e),m={};l(m,{DraggableCore:()=>Se,default:()=>Ce}),t.exports=p(m);var h=f(d()),g=f(yd()),_=f(a()),v=yr();function y(e,t){for(let n=0,r=e.length;n<r;n++)if(t.apply(t,[e[n],n,e]))return e[n]}function b(e){return typeof e==`function`||Object.prototype.toString.call(e)===`[object Function]`}function x(e){return typeof e==`number`&&!isNaN(e)}function S(e){return parseInt(e,10)}function C(e,t,n){if(e[t])return Error(`Invalid prop ${t} passed to ${n} - do not set this, set it on the child.`)}var w=[`Moz`,`Webkit`,`O`,`ms`];function T(e=`transform`){if(typeof window>`u`)return``;let t=window.document?.documentElement?.style;if(!t||e in t)return``;for(let n=0;n<w.length;n++)if(E(e,w[n])in t)return w[n];return``}function E(e,t){return t?`${t}${D(e)}`:e}function D(e){let t=``,n=!0;for(let r=0;r<e.length;r++)n?(t+=e[r].toUpperCase(),n=!1):e[r]===`-`?n=!0:t+=e[r];return t}var O=T(),k=``;function A(e,t){k||=y([`matches`,`webkitMatchesSelector`,`mozMatchesSelector`,`msMatchesSelector`,`oMatchesSelector`],function(t){return b(e[t])})??``;let n=e[k];return b(n)?!!n.call(e,t):!1}function j(e,t,n){let r=e;do{if(A(r,t))return!0;if(r===n)return!1;r=r.parentNode}while(r);return!1}function M(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.addEventListener?e.addEventListener(t,a,i):e.attachEvent?e.attachEvent(`on`+t,a):e[`on`+t]=a}function N(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.removeEventListener?e.removeEventListener(t,a,i):e.detachEvent?e.detachEvent(`on`+t,a):e[`on`+t]=null}function P(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=S(n.borderTopWidth),t+=S(n.borderBottomWidth),t}function F(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=S(n.borderLeftWidth),t+=S(n.borderRightWidth),t}function I(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=S(n.paddingTop),t-=S(n.paddingBottom),t}function ee(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=S(n.paddingLeft),t-=S(n.paddingRight),t}function te(e,t,n){let r=t===t.ownerDocument.body?{left:0,top:0}:t.getBoundingClientRect();return{x:(e.clientX+t.scrollLeft-r.left)/n,y:(e.clientY+t.scrollTop-r.top)/n}}function ne(e,t){let n=ie(e,t,`px`);return{[E(`transform`,O)]:n}}function re(e,t){return ie(e,t,``)}function ie({x:e,y:t},n,r){let i=`translate(${e}${r},${t}${r})`;return n&&(i=`translate(${`${typeof n.x==`string`?n.x:n.x+r}`}, ${`${typeof n.y==`string`?n.y:n.y+r}`})`+i),i}function L(e,t){return e.targetTouches&&y(e.targetTouches,e=>t===e.identifier)||e.changedTouches&&y(e.changedTouches,e=>t===e.identifier)}function R(e){if(e.targetTouches&&e.targetTouches[0])return e.targetTouches[0].identifier;if(e.changedTouches&&e.changedTouches[0])return e.changedTouches[0].identifier}function ae(){return typeof __webpack_nonce__<`u`?__webpack_nonce__:void 0}function oe(e,t){if(!e)return;let n=e.getElementById(`react-draggable-style-el`);if(!n){n=e.createElement(`style`),n.type=`text/css`,n.id=`react-draggable-style-el`;let r=t??ae();r&&n.setAttribute(`nonce`,r),n.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;}
|
|
4
|
+
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let u=Jc(),d;if(t){let e=typeof t==`string`?zs(t):t;Ns(c===`/`||e.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${e.pathname}" was given in the \`location\` prop.`),d=e}else d=u;let f=d.pathname||`/`,p=f;if(c!==`/`){let e=c.replace(/^\//,``).split(`/`);p=`/`+f.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let m=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):Hs(e,{pathname:p});Ps(l||m!=null,`No routes matched location "${d.pathname}${d.search}${d.hash}" `),Ps(m==null||m[m.length-1].route.element!==void 0||m[m.length-1].route.Component!==void 0||m[m.length-1].route.lazy!==void 0,`Matched leaf route at location "${d.pathname}${d.search}${d.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let h=dl(m&&m.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:gc([c,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?c:gc([c,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&h?X.createElement(Rc.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...d},navigationType:`POP`}},h):h}function al(){let e=vl(),t=Sc(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},o=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),o=X.createElement(X.Fragment,null,X.createElement(`p`,null,`💿 Hey developer 👋`),X.createElement(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,X.createElement(`code`,{style:a},`ErrorBoundary`),` or`,` `,X.createElement(`code`,{style:a},`errorElement`),` prop on your route.`)),X.createElement(X.Fragment,null,X.createElement(`h2`,null,`Unexpected Application Error!`),X.createElement(`h3`,{style:{fontStyle:`italic`}},t),n?X.createElement(`pre`,{style:i},n):null,o)}var ol=X.createElement(al,null),sl=class extends X.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=Gc(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:X.createElement(zc.Provider,{value:this.props.routeContext},X.createElement(Bc.Provider,{value:e,children:this.props.component}));return this.context?X.createElement(ll,{error:e},t):t}};sl.contextType=Mc;var cl=new WeakMap;function ll({children:e,error:t}){let{basename:n}=X.useContext(Lc);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=Wc(t.digest);if(e){let r=cl.get(t);if(r)throw r;let i=Tc(e.location,n),a=i.absoluteURL||i.to;if(kc(a))throw Error(`Invalid redirect location`);if(wc&&!cl.get(t)){if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw cl.set(t,n),n}}return X.createElement(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function ul({routeContext:e,match:t,children:n}){let r=X.useContext(Ac);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),X.createElement(zc.Provider,{value:e},n)}function dl(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);Ns(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:Cc(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,d=!1,f=null,p=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,f=n.route.errorElement||ol,o&&(s<0&&c===0?(xl(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),d=!0,p=null):s===c&&(d=!0,p=n.route.hydrateFallbackElement||null)));let m=t.concat(i.slice(0,c+1)),h=()=>{let t;return t=u?f:d?p:n.route.Component?X.createElement(n.route.Component,null):n.route.element?n.route.element:e,X.createElement(ul,{match:n,routeContext:{outlet:e,matches:m,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?X.createElement(sl,{location:r.location,revalidation:r.revalidation,component:f,error:u,children:h(),routeContext:{outlet:null,matches:m,isDataRoute:!0},onError:l}):h()},null)}function fl(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function pl(e){let t=X.useContext(Ac);return Ns(t,fl(e)),t}function ml(e){let t=X.useContext(jc);return Ns(t,fl(e)),t}function hl(e){let t=X.useContext(zc);return Ns(t,fl(e)),t}function gl(e){let t=hl(e),n=t.matches[t.matches.length-1];return Ns(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function _l(){return gl(`useRouteId`)}function vl(){let e=X.useContext(Bc),t=ml(`useRouteError`),n=gl(`useRouteError`);return e===void 0?t.errors?.[n]:e}function yl(){let{router:e}=pl(`useNavigate`),t=gl(`useNavigate`),n=X.useRef(!1);return Xc(()=>{n.current=!0}),X.useCallback(async(r,i={})=>{Ps(n.current,Yc),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var bl={};function xl(e,t,n){!t&&!bl[e]&&(bl[e]=!0,Ps(!1,n))}X.memo(Sl);function Sl({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return il(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function Cl({to:e,replace:t,state:n,relative:r}){Ns(qc(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=X.useContext(Lc);Ps(!i,`<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`);let{matches:a}=X.useContext(zc),{pathname:o}=Jc(),s=Zc(),c=mc(e,pc(a),o,r===`path`),l=JSON.stringify(c);return X.useEffect(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function wl(e){return el(e.context)}function Tl(e){Ns(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function El({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:o}){Ns(!qc(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=X.useMemo(()=>({basename:s,navigator:i,static:a,useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=zs(n));let{pathname:l=`/`,search:u=``,hash:d=``,state:f=null,key:p=`default`,mask:m}=n,h=X.useMemo(()=>{let e=cc(l,s);return e==null?null:{location:{pathname:e,search:u,hash:d,state:f,key:p,mask:m},navigationType:r}},[s,l,u,d,f,p,r,m]);return Ps(h!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${d}" because it does not start with the basename, so the <Router> won't render anything.`),h==null?null:X.createElement(Lc.Provider,{value:c},X.createElement(Rc.Provider,{children:t,value:h}))}function Dl({children:e,location:t}){return rl(Ol(e),t)}X.Component;function Ol(e,t=[]){let n=[];return X.Children.forEach(e,(e,r)=>{if(!X.isValidElement(e))return;let i=[...t,r];if(e.type===X.Fragment){n.push.apply(n,Ol(e.props.children,i));return}Ns(e.type===Tl,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),Ns(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=Ol(e.props.children,i)),n.push(a)}),n}var kl=`get`,Al=`application/x-www-form-urlencoded`;function jl(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function Ml(e){return jl(e)&&e.tagName.toLowerCase()===`button`}function Nl(e){return jl(e)&&e.tagName.toLowerCase()===`form`}function Pl(e){return jl(e)&&e.tagName.toLowerCase()===`input`}function Fl(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Il(e,t){return e.button===0&&(!t||t===`_self`)&&!Fl(e)}function Ll(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function Rl(e,t){let n=Ll(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var zl=null;function Bl(){if(zl===null)try{new FormData(document.createElement(`form`),0),zl=!1}catch{zl=!0}return zl}var Vl=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function Hl(e){return e!=null&&!Vl.has(e)?(Ps(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Al}"`),null):e}function Ul(e,t){let n,r,i,a,o;if(Nl(e)){let o=e.getAttribute(`action`);r=o?cc(o,t):null,n=e.getAttribute(`method`)||kl,i=Hl(e.getAttribute(`enctype`))||Al,a=new FormData(e)}else if(Ml(e)||Pl(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?cc(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||kl,i=Hl(e.getAttribute(`formenctype`))||Hl(o.getAttribute(`enctype`))||Al,a=new FormData(o,e),!Bl()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(jl(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=kl,r=null,i=Al,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);function Wl(e,t){if(e===!1||e==null)throw Error(t)}function Gl(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return i.pathname=n?i.pathname.endsWith(`/`)?`${i.pathname}_.${r}`:`${i.pathname}.${r}`:i.pathname===`/`?`_root.${r}`:t&&cc(i.pathname,t)===`/`?`${_c(t)}/_root.${r}`:`${_c(i.pathname)}.${r}`,i}async function Kl(e,t){if(e.id in t)return t[e.id];try{let n=await m(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function ql(e){return e!=null&&typeof e.page==`string`}function Jl(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function Yl(e,t,n){return eu((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await Kl(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(Jl).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function Xl(e,t,n,r,i,a){let o=(e,t)=>!n[t]||e.route.id!==n[t].route.id,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function Zl(e,t,{includeHydrateFallback:n}={}){return Ql(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function Ql(e){return[...new Set(e)]}function $l(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function eu(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!ql(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify($l(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function tu(){let e=X.useContext(Ac);return Wl(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function nu(){let e=X.useContext(jc);return Wl(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var ru=X.createContext(void 0);ru.displayName=`FrameworkContext`;function iu(){let e=X.useContext(ru);return Wl(e,`You must render this element inside a <HydratedRouter> element`),e}function au(e,t){let n=X.useContext(ru),[r,i]=X.useState(!1),[a,o]=X.useState(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=X.useRef(null);X.useEffect(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),X.useEffect(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let p=()=>{i(!0)},m=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:ou(s,p),onBlur:ou(c,m),onMouseEnter:ou(l,p),onMouseLeave:ou(u,m),onTouchStart:ou(d,p)}]:[a,f,{}]:[!1,f,{}]}function ou(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function su({page:e,...t}){let n=Nc(),{nonce:r}=iu(),{router:i}=tu(),a=X.useMemo(()=>Hs(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),n?X.createElement(lu,{page:e,matches:a,...t}):X.createElement(uu,{page:e,matches:a,...t})):null}function cu(e){let{manifest:t,routeModules:n}=iu(),[r,i]=X.useState([]);return X.useEffect(()=>{let r=!1;return Yl(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function lu({page:e,matches:t,...n}){let r=Jc(),{future:i}=iu(),{basename:a}=tu(),o=X.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=Gl(e,a,i.v8_trailingSlashAwareDataRequests,`rsc`),o=!1,s=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?o=!0:s.push(e.route.id);return o&&s.length>0&&n.searchParams.set(`_routes`,s.join(`,`)),[n.pathname+n.search]},[a,i.v8_trailingSlashAwareDataRequests,e,r,t]);return X.createElement(X.Fragment,null,o.map(e=>X.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function uu({page:e,matches:t,...n}){let r=Jc(),{future:i,manifest:a,routeModules:o}=iu(),{basename:s}=tu(),{loaderData:c,matches:l}=nu(),u=X.useMemo(()=>Xl(e,t,l,a,r,`data`),[e,t,l,a,r]),d=X.useMemo(()=>Xl(e,t,l,a,r,`assets`),[e,t,l,a,r]),f=X.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,l=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!u.some(t=>t.route.id===e.route.id)&&e.route.id in c&&o[e.route.id]?.shouldRevalidate||t.hasClientLoader?l=!0:n.add(e.route.id))}),n.size===0)return[];let d=Gl(e,s,i.v8_trailingSlashAwareDataRequests,`data`);return l&&n.size>0&&d.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[d.pathname+d.search]},[s,i.v8_trailingSlashAwareDataRequests,c,r,a,u,t,e,o]),p=X.useMemo(()=>Zl(d,a),[d,a]),m=cu(d);return X.createElement(X.Fragment,null,f.map(e=>X.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),p.map(e=>X.createElement(`link`,{key:e,rel:`modulepreload`,href:e,...n})),m.map(({key:e,link:t})=>X.createElement(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function du(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}X.Component;var fu=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{fu&&(window.__reactRouterVersion=`7.18.2`)}catch{}function pu({basename:e,children:t,useTransitions:n,window:r}){let i=X.useRef();i.current??=Ms({window:r,v5Compat:!0});let a=i.current,[o,s]=X.useState({action:a.action,location:a.location}),c=X.useCallback(e=>{n===!1?s(e):X.startTransition(()=>s(e))},[n]);return X.useLayoutEffect(()=>a.listen(c),[a,c]),X.createElement(El,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:a,useTransitions:n})}var mu=X.forwardRef(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m){let{basename:h,navigator:g,useTransitions:_}=X.useContext(Lc),v=typeof l==`string`&&Es.test(l),y=Tc(l,h);l=y.to;let b=Kc(l,{relative:r}),x=Jc(),S=null;if(o){let e=mc(o,[],x.mask?x.mask.pathname:`/`,!0);h!==`/`&&(e.pathname=e.pathname===`/`?h:gc([h,e.pathname])),S=g.createHref(e)}let[C,w,T]=au(n,p),E=yu(l,{replace:a,mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:d,defaultShouldRevalidate:f,useTransitions:_});function D(t){e&&e(t),t.defaultPrevented||E(t)}let O=!(y.isExternal||i),k=X.createElement(`a`,{...p,...T,href:(O?S:void 0)||y.absoluteURL||b,onClick:O?D:e,ref:du(m,w),target:c,"data-discover":!v&&t===`render`?`true`:void 0});return C&&!v?X.createElement(X.Fragment,null,k,X.createElement(su,{page:b})):k});mu.displayName=`Link`;var hu=X.forwardRef(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=nl(a,{relative:c.relative}),d=Jc(),f=X.useContext(jc),{navigator:p,basename:m}=X.useContext(Lc),h=f!=null&&Tu(u)&&o===!0,g=p.encodeLocation?p.encodeLocation(u).pathname:u.pathname,_=d.pathname,v=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;t||(_=_.toLowerCase(),v=v?v.toLowerCase():null,g=g.toLowerCase()),v&&m&&(v=cc(v,m)||v);let y=g!==`/`&&g.endsWith(`/`)?g.length-1:g.length,b=_===g||!r&&_.startsWith(g)&&_.charAt(y)===`/`,x=v!=null&&(v===g||!r&&v.startsWith(g)&&v.charAt(g.length)===`/`),S={isActive:b,isPending:x,isTransitioning:h},C=b?e:void 0,w;w=typeof n==`function`?n(S):[n,b?`active`:null,x?`pending`:null,h?`transitioning`:null].filter(Boolean).join(` `);let T=typeof i==`function`?i(S):i;return X.createElement(mu,{...c,"aria-current":C,className:w,ref:l,style:T,to:a,viewTransition:o},typeof s==`function`?s(S):s)});hu.displayName=`NavLink`;var gu=X.forwardRef(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=kl,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f,...p},m)=>{let{useTransitions:h}=X.useContext(Lc),g=Cu(),_=wu(s,{relative:l}),v=o.toLowerCase()===`get`?`get`:`post`,y=typeof s==`string`&&Es.test(s);return X.createElement(`form`,{ref:m,method:v,action:_,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,p=()=>g(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:d,defaultShouldRevalidate:f});h&&n!==!1?X.startTransition(()=>p()):p()},...p,"data-discover":!y&&e===`render`?`true`:void 0})});gu.displayName=`Form`;function _u(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function vu(e){let t=X.useContext(Ac);return Ns(t,_u(e)),t}function yu(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=Zc(),d=Jc(),f=nl(e,{relative:o});return X.useCallback(p=>{if(Il(p,t)){p.preventDefault();let t=n===void 0?Rs(d)===Rs(f):n,m=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?X.startTransition(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function bu(e){Ps(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=X.useRef(Ll(e)),n=X.useRef(!1),r=Jc(),i=X.useMemo(()=>Rl(r.search,n.current?null:t.current),[r.search]),a=Zc();return[i,X.useCallback((e,t)=>{let r=Ll(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var xu=0,Su=()=>`__${String(++xu)}__`;function Cu(){let{router:e}=vu(`useSubmit`),{basename:t}=X.useContext(Lc),n=_l(),r=e.fetch,i=e.navigate;return X.useCallback(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=Ul(e,t);if(a.navigate===!1){let e=a.fetcherKey||Su();await r(e,n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync})}else await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function wu(e,{relative:t}={}){let{basename:n}=X.useContext(Lc),r=X.useContext(zc);Ns(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...nl(e||`.`,{relative:t})},o=Jc();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:gc([n,a.pathname])),Rs(a)}function Tu(e,{relative:t}={}){let n=X.useContext(Pc);Ns(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=vu(`useViewTransitionState`),i=nl(e,{relative:t});if(!n.isTransitioning)return!1;let a=cc(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=cc(n.nextLocation.pathname,r)||n.nextLocation.pathname;return ic(i.pathname,o)!=null||ic(i.pathname,a)!=null}var Z=f(),Eu=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Qn,{ref:n,className:K(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,e),...t}));Eu.displayName=Qn.displayName;var Du=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`rounded-lg border bg-card text-card-foreground shadow-elevation-1`,e),...t}));Du.displayName=`Card`;var Ou=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`flex flex-col space-y-1.5 p-6`,e),...t}));Ou.displayName=`CardHeader`;var ku=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`h3`,{ref:n,className:K(`text-2xl font-semibold leading-none tracking-tight`,e),...t}));ku.displayName=`CardTitle`;var Au=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`p`,{ref:n,className:K(`text-sm text-muted-foreground`,e),...t}));Au.displayName=`CardDescription`;var ju=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`p-6 pt-0`,e),...t}));ju.displayName=`CardContent`;var Mu=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{ref:n,className:K(`flex items-center p-6 pt-0`,e),...t}));Mu.displayName=`CardFooter`;var Nu=`2.14.18`,Pu=e=>{window.particlesJS.load(e,`/js/particles.config.json`,()=>{console.log(`particles.js config loaded for`,e)})};function Fu(e){(0,X.useEffect)(()=>{if(window.particlesJS!==void 0)Pu(e);else{if(document.getElementById(`particles-js-script`))return;let t=document.createElement(`script`);t.id=`particles-js-script`,t.src=`/js/particles.min.js`,t.onload=()=>{console.log(`particles.js loaded`),Pu(e)},document.head.appendChild(t)}return()=>{window.pJS&&window.pJS[e]?.destroy&&window.pJS[e].destroy()}},[e])}var Iu=`session.open`,Lu=`session.set`,Ru=`session.ids`,zu=`session.materialize`,Bu=`session.close`,Vu=`session.delta`;function Hu(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)(!0),[i,a]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!0;async function n(){try{r(!0),a(null);let n=await Y.get(`/ping`,{skipAuth:!0});e&&(n?.version?t(n.version):a(`Invalid server response`))}catch(t){e&&(console.error(`Failed to fetch server version:`,t),a(`Unable to connect to server`))}finally{e&&r(!1)}}n();let i=setInterval(n,3e4);return()=>{e=!1,clearInterval(i)}},[]),{serverVersion:e,isLoading:n,error:i}}var Uu=`https://github.com/canvas-ui/canvas-server`,Wu=null;function Gu(){return Wu||=Y.get(`/ping`,{skipAuth:!0}).then(e=>{let t=e??{};return{sourceUrl:t.sourceUrl||Uu,version:t.version??null,commit:t.commit??null,license:t.license??null}}).catch(e=>(console.error(`Failed to fetch server source info:`,e),Wu=null,{sourceUrl:Uu,version:null,commit:null,license:null})),Wu}function Ku(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!0;return Gu().then(n=>{e&&t(n)}),()=>{e=!1}},[]),e}function qu({className:e=``}){let t=Ku();if(!t)return null;let n=[t.version?`v${t.version}`:null,t.commit?.slice(0,7)].filter(Boolean).join(` `);return(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground ${e}`,children:[`Powered by`,` `,(0,Z.jsx)(`a`,{href:t.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Canvas`}),n?` ${n}`:``,t.license?`, ${t.license}`:``,`.`,` `,(0,Z.jsx)(`a`,{href:t.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})}function Ju({children:e}){Fu(`particle-js`);let{serverVersion:t,isLoading:n,error:r}=Hu();return(0,Z.jsx)(`div`,{className:`flex min-h-viewport w-full items-center justify-center p-4 flex-col`,children:(0,Z.jsxs)(Du,{className:`flex w-[95vw] h-viewport-modal overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`hidden md:block w-1/2 relative bg-background`,"data-scheme":`dark`,id:`particle-js`,children:[(0,Z.jsxs)(mu,{className:`absolute top-8 left-8 font-bold text-foreground flex items-center z-raised`,to:`/`,children:[(0,Z.jsx)(`img`,{src:`/images/logo-wr_128x128.png`,alt:`Canvas Logo`,className:`mr-2 h-6 w-6 touch-target`}),(0,Z.jsx)(`span`,{className:`text-2xl font-bold text-foreground`,children:`Canvas`})]}),(0,Z.jsxs)(`div`,{className:`absolute bottom-8 left-8 text-sm text-foreground max-w-[80%] z-raised`,children:[`Web UI: v`,Nu,`, Server: `,n?`Loading...`:r?`Unavailable`:t?`v${t}`:`Unknown`]})]}),(0,Z.jsx)(`div`,{className:`flex w-full md:w-1/2 flex-col justify-center px-4 py-12 sm:px-6 lg:px-8`,children:(0,Z.jsxs)(`div`,{className:`mx-auto w-full max-w-sm`,children:[e,(0,Z.jsxs)(`div`,{className:`mt-8 border-t pt-6`,children:[(0,Z.jsxs)(`a`,{href:`https://github.com/canvas-ui`,target:`_blank`,className:`text-muted-foreground hover:text-foreground justify-center flex items-center space-x-2`,rel:`noopener noreferrer`,children:[(0,Z.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`24`,height:`24`,stroke:`currentColor`,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-6 h-6`,children:(0,Z.jsx)(`path`,{d:`M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22`})}),(0,Z.jsx)(`span`,{children:`View on GitHub`})]}),(0,Z.jsx)(qu,{className:`mt-4 text-center`})]})]})})]})})}function Yu(){let e=localStorage.getItem(`authToken`);return!e||e===`canvas-server-token`?null:e}var Xu=new class{socket=null;connected=!1;authToken=null;handlers=new Map;socketWrappers=new Map;desiredSubscriptions=new Set;baseUrl;connectionId=``;constructor(){this.baseUrl=si,this.connectionId=`socket-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}connect(e){let t=e||Yu();!t||t===`canvas-server-token`||this.socket&&this.authToken===t||(this.cleanupSocket(),this.authToken=t,this.socket=$a(this.baseUrl,{transports:[`websocket`],autoConnect:!1,reconnection:!0,reconnectionAttempts:1/0,reconnectionDelay:1e3,reconnectionDelayMax:3e4,randomizationFactor:.5,timeout:1e4,forceNew:!0,extraHeaders:{Authorization:`Bearer ${t}`,"X-Connection-ID":this.connectionId},auth:{token:t}}),this.setupDefaultHandlers(),this.registerHandlers(),this.socket.connect())}cleanupSocket(){this.socket?.removeAllListeners(),this.socket?.disconnect(),this.socket=null,this.connected=!1,this.socketWrappers.clear()}setupDefaultHandlers(){this.socket&&(this.socket.on(`connect`,()=>{this.connected=!0;for(let e of this.desiredSubscriptions)this.socket?.emit(`subscribe`,{channel:e})}),this.socket.on(`disconnect`,()=>{this.connected=!1}),this.socket.on(`connect_error`,()=>{this.connected=!1}))}registerHandlers(){this.socket&&this.handlers.forEach((e,t)=>{e.forEach(e=>{this.attach(t,e)})})}attach(e,t){if(!this.socket)return;let n=this.socketWrappers.get(e);if(n||(n=new Map,this.socketWrappers.set(e,n)),n.has(t))return;let r=(...e)=>t(...e);n.set(t,r),this.socket.on(e,r)}detach(e,t){if(!this.socket)return;let n=this.socketWrappers.get(e),r=n?.get(t);r&&(this.socket.off(e,r),n?.delete(t),n&&n.size===0&&this.socketWrappers.delete(e))}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set);let n=this.handlers.get(e);return n.has(t)?()=>this.off(e,t):(n.add(t),this.socket&&this.attach(e,t),()=>this.off(e,t))}off(e,t){let n=this.handlers.get(e);n&&n.has(t)&&(n.delete(t),n.size===0&&this.handlers.delete(e),this.detach(e,t))}request(e,t,n=1e4){return new Promise((r,i)=>{if(!this.socket||!this.connected){i(Error(`Socket not connected`));return}let a=!1,o=setTimeout(()=>{a||(a=!0,i(Error(`Socket request timed out: ${e}`)))},n);try{this.socket.emit(e,t??{},t=>{a||(a=!0,clearTimeout(o),t?.status===`error`?i(Error(t.message||`${e} failed`)):r(t?.payload??t))})}catch(e){a=!0,clearTimeout(o),i(e instanceof Error?e:Error(String(e)))}})}emit(e,...t){if(e===`subscribe`){let e=t?.[0]?.channel;typeof e==`string`&&e&&this.desiredSubscriptions.add(e)}else if(e===`unsubscribe`){let e=t?.[0]?.channel;typeof e==`string`&&e&&this.desiredSubscriptions.delete(e)}if(this.socket&&this.connected)try{this.socket.emit(e,...t)}catch(t){console.error(`Error emitting event ${e}:`,t),this.reconnect()}else this.connect()}disconnect(){this.cleanupSocket(),this.authToken=null,this.desiredSubscriptions.clear()}isConnected(){return this.connected}retryNow(){this.connected||(this.cleanupSocket(),this.connect())}reconnect(){this.connect()}};async function Zu(e,t,n=`auto`){try{let r=await Y.post(Qr.login,{email:e,password:t,strategy:n},{skipAuth:!0});console.log(`Login response:`,r);let i=r;if(`token`in i)return console.log(`Setting auth token (direct):`,i.token.substring(0,10)+`...`),Y.setAuthToken(i.token),Xu.connect(i.token),r;if(i&&`payload`in i&&i.payload&&i.payload.token)return console.log(`Setting auth token (nested):`,i.payload.token.substring(0,10)+`...`),Y.setAuthToken(i.payload.token),Xu.connect(i.payload.token),r;throw console.error(`Invalid login response structure:`,r),Error(`Invalid login response: missing token`)}catch(e){throw console.error(`Login error:`,e),Y.clearAuthToken(),e}}async function Qu(e,t,n){try{return await Y.post(Qr.register,{name:e,email:t,password:n},{skipAuth:!0})}catch(e){throw console.error(`Registration failed:`,e),e}}function $u(e){return e instanceof Error&&/^Network error/i.test(e.message)}function ed(){let e=localStorage.getItem(`authToken`);if(!e)return!1;if(e.startsWith(`canvas-`))return!0;try{return br(e).exp*1e3>Date.now()}catch{return!1}}function td(){let e=localStorage.getItem(`authToken`);if(!e||e.startsWith(`canvas-`))return null;try{let t=br(e);return t.exp*1e3<Date.now()?(Y.clearAuthToken(),null):{id:t.sub,email:t.email,userType:t.userType||`user`}}catch(e){return console.error(`Failed to decode token:`,e),Y.clearAuthToken(),null}}async function nd(){try{if(!Y.isAuthenticated())return console.log(`Not authenticated, skipping getCurrentUser request`),null;let e=await Y.get(Qr.me);return console.log(`Current user response:`,e),e&&e?(Xu.isConnected()||Xu.reconnect(),e):(console.warn(`Invalid user profile response structure:`,e),null)}catch(e){if(console.error(`Failed to get current user:`,e),$u(e))throw e;return e instanceof Error&&(e.message.includes(`USER_NOT_FOUND_IN_DATABASE`)||e.message.includes(`Your session is invalid`)||e.message.includes(`Authentication required`)||e.message.includes(`user account no longer exists`))?(console.warn(`Authentication error detected, clearing token:`,e.message),Y.clearAuthToken(),Xu.disconnect(),null):null}}function rd(){return Y.isAuthenticated()}async function id(){try{let e=await Y.get(Qr.authConfig,{skipAuth:!0});return e||e}catch(e){return console.error(`Failed to get auth config:`,e),{strategies:{local:{enabled:!0},imap:{enabled:!1,domains:[]}}}}}async function ad(e){try{await Y.post(Qr.verifyEmailRequest,{email:e},{skipAuth:!0})}catch(e){throw console.error(`Failed to request email verification:`,e),e}}var od=e=>e?.strategies?.local?.enabled!==!1,sd=e=>e?.allowUserRegistrations!==!1;function cd(){let e=Zc(),[t,n]=X.useState(!1),[r,i]=X.useState({}),[a,o]=X.useState(null),[s,c]=X.useState({email:``,password:``,strategy:`auto`});X.useEffect(()=>{rd()&&e(`/workspaces`),id().then(e=>{o(e)}).catch(e=>{console.error(`Failed to load auth config:`,e)})},[e]);let l=()=>{let e={};return s.email?/\S+@\S+\.\S+/.test(s.email)||(e.email=`Email is invalid`):e.email=`Email is required`,s.password||(e.password=`Password is required`),i(e),Object.keys(e).length===0},u=e=>{let{name:t,value:n}=e.target;c(e=>({...e,[t]:n}))};async function d(t){if(t.preventDefault(),l()){n(!0);try{console.log(`Attempting login with:`,s.email,`strategy:`,s.strategy);let t=await Zu(s.email,s.password,s.strategy);console.log(`Login successful, received token:`,`token`in t?!!t.token:!!t.payload?.token),i({}),e(`/home`)}catch(e){console.error(`Login error:`,e);let t=`Login failed`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;n.message?t=n.message:n.error?t=n.error:n.payload?.message&&(t=n.payload.message)}i({password:t})}finally{n(!1)}}}return(0,Z.jsx)(Ju,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-2 text-center`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Welcome back`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Enter your credentials to access your account`})]}),(0,Z.jsx)(`form`,{onSubmit:d,children:(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[a?.strategies?.imap?.enabled&&a.strategies.imap.domains.length>0&&(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`strategy`,children:`Authentication Method`}),(0,Z.jsxs)(`select`,{id:`strategy`,name:`strategy`,value:s.strategy,onChange:u,disabled:t,className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Z.jsx)(`option`,{value:`auto`,children:`Auto-detect`}),(0,Z.jsx)(`option`,{value:`local`,children:`Local Account`}),(0,Z.jsx)(`option`,{value:`imap`,children:`Email Server (IMAP)`})]})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`email`,children:`Email`}),(0,Z.jsx)(q,{id:`email`,name:`email`,placeholder:`name@example.com`,type:`email`,autoCapitalize:`none`,autoComplete:`email`,autoCorrect:`off`,disabled:t,value:s.email,onChange:u}),r.email&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:r.email})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`password`,children:`Password`}),(0,Z.jsx)(q,{id:`password`,name:`password`,type:`password`,disabled:t,value:s.password,onChange:u}),r.password&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:r.password})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-4`,children:[(0,Z.jsx)(J,{type:`submit`,disabled:t,children:t?`Signing in...`:`Sign In`}),od(a)&&sd(a)&&(0,Z.jsx)(J,{variant:`outline`,type:`button`,disabled:t,onClick:()=>e(`/register`),children:`Don't have an account? Sign up`})]})]})})]})})}function ld(){let e=Zc(),{showToast:t}=po(),[n,r]=X.useState(!1),[i,a]=X.useState({}),[o,s]=X.useState({name:``,email:``,password:``}),[c,l]=X.useState(!1),[u,d]=X.useState(!1),[f,p]=X.useState(null);X.useEffect(()=>{(async()=>{let t=await id(),n=t?.strategies?.local;if(t?.allowUserRegistrations===!1||n?.enabled===!1){e(`/login`,{replace:!0});return}n?.passwordPolicy&&p(n.passwordPolicy),d(!!n?.requireEmailVerification)})()},[e]);let m=X.useMemo(()=>{if(!f)return null;let e=o.password||``;return{minLength:!f.minLength||e.length>=f.minLength,maxLength:!f.maxLength||e.length<=f.maxLength,uppercase:!f.requireUppercase||/[A-Z]/.test(e),lowercase:!f.requireLowercase||/[a-z]/.test(e),number:!f.requireNumbers||/[0-9]/.test(e),special:!f.requireSpecialChars||/[^A-Za-z0-9]/.test(e)}},[f,o.password]),h=()=>{let e={};if(!o.name)e.name=`Username is required`;else if(o.name.trim().length===0)e.name=`Username cannot be empty`;else{let t=o.name.toLowerCase().trim();t.length<3?e.name=`Username must be at least 3 characters long`:t.length>39?e.name=`Username cannot be longer than 39 characters`:/^[a-z0-9_-]+$/.test(t)?[`admin`,`administrator`,`root`,`system`,`support`,`help`,`api`,`www`,`mail`,`ftp`,`localhost`,`test`,`demo`,`canvas`,`universe`,`workspace`,`context`,`user`,`users`].includes(t)&&(e.name=`Username '${t}' is reserved and cannot be used`):e.name=`Username can only contain lowercase letters, numbers, underscores, and hyphens`}if(o.email?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o.email)||(e.email=`Please enter a valid email address`):e.email=`Email is required`,!o.password)e.password=`Password is required`;else if(f){let t=o.password,n=[];f.minLength&&t.length<f.minLength&&n.push(`at least ${f.minLength} characters`),f.maxLength&&t.length>f.maxLength&&n.push(`no more than ${f.maxLength} characters`),f.requireUppercase&&!/[A-Z]/.test(t)&&n.push(`an uppercase letter`),f.requireLowercase&&!/[a-z]/.test(t)&&n.push(`a lowercase letter`),f.requireNumbers&&!/[0-9]/.test(t)&&n.push(`a number`),f.requireSpecialChars&&!/[^A-Za-z0-9]/.test(t)&&n.push(`a special character`),n.length&&(e.password=`Password must contain ${n.join(`, `).replace(/, ([^,]*)$/,` and $1`)}.`)}else o.password.length<8&&(e.password=`Password must be at least 8 characters long`);return a(e),Object.keys(e).length===0},g=e=>{let t={...o,[e.target.id]:e.target.value};s(t),(e.target.id===`name`||e.target.id===`email`||e.target.id===`password`)&&h()};return c?(0,Z.jsxs)(Ju,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-2 text-center`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Registration Successful!`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:u?`Check your email for a verification link to activate your account.`:`Your account has been created.`})]}),(0,Z.jsx)(`div`,{className:`space-y-6 text-center pt-6`,children:!u&&(0,Z.jsx)(J,{asChild:!0,className:`w-full`,children:(0,Z.jsx)(mu,{to:`/login`,children:`Go to Login`})})})]}):(0,Z.jsxs)(Ju,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-2 text-center`,children:[(0,Z.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Create an account`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Enter your email below to create your account`})]}),(0,Z.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),h()){r(!0);try{let e=await Qu(o.name,o.email,o.password);console.log(`Registration successful:`,e),t({title:`Registration Successful`,description:u?`Check your email for a verification link before logging in.`:`You can now log in with your credentials.`,variant:`default`}),l(!0),s({name:``,email:``,password:``}),a({})}catch(e){console.error(`Registration failed:`,e);let n=e?.message||`Registration failed`;n.toLowerCase().includes(`password`)?a({...i,password:n}):a({...i,email:n}),t({title:`Registration Failed`,description:n,variant:`destructive`})}finally{r(!1)}}},className:`space-y-4 pt-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`name`,children:`Username`}),(0,Z.jsx)(q,{id:`name`,type:`text`,placeholder:`Enter your username (e.g., john_doe)`,value:o.name,onChange:g,disabled:n,className:i.name?`border-destructive`:``}),i.name&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:i.name}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`3-39 characters, lowercase letters, numbers, underscores, and hyphens only`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`email`,children:`Email`}),(0,Z.jsx)(q,{id:`email`,type:`email`,placeholder:`name@example.com`,value:o.email,onChange:g,disabled:n,className:i.email?`border-destructive`:``}),i.email&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:i.email})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`password`,children:`Password`}),(0,Z.jsx)(q,{id:`password`,type:`password`,placeholder:`Enter your password`,value:o.password,onChange:g,disabled:n,className:i.password?`border-destructive`:``}),i.password&&(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:i.password}),f&&m&&(0,Z.jsxs)(`ul`,{className:`text-xs list-disc pl-4 space-y-1`,children:[(0,Z.jsxs)(`li`,{className:m.minLength?`text-success`:`text-muted-foreground`,children:[`At least `,f.minLength,` characters`]}),f.requireUppercase&&(0,Z.jsx)(`li`,{className:m.uppercase?`text-success`:`text-muted-foreground`,children:`At least one uppercase letter`}),f.requireLowercase&&(0,Z.jsx)(`li`,{className:m.lowercase?`text-success`:`text-muted-foreground`,children:`At least one lowercase letter`}),f.requireNumbers&&(0,Z.jsx)(`li`,{className:m.number?`text-success`:`text-muted-foreground`,children:`At least one number`}),f.requireSpecialChars&&(0,Z.jsx)(`li`,{className:m.special?`text-success`:`text-muted-foreground`,children:`At least one special character`}),f.maxLength&&(0,Z.jsxs)(`li`,{className:m.maxLength?`text-success`:`text-muted-foreground`,children:[`No more than `,f.maxLength,` characters`]})]})]}),(0,Z.jsx)(J,{type:`submit`,className:`w-full`,disabled:n,children:n?`Creating Account...`:`Create Account`})]}),(0,Z.jsxs)(`div`,{className:`mt-4 text-center text-sm`,children:[`Already have an account?`,` `,(0,Z.jsx)(mu,{to:`/login`,className:`underline`,children:`Sign in`})]}),(0,Z.jsxs)(`div`,{className:`px-8 py-4 text-center text-sm text-muted-foreground border-t mt-6`,children:[`By clicking continue, you agree to our`,` `,(0,Z.jsx)(mu,{to:`/terms`,className:`underline underline-offset-4 hover:text-primary`,children:`Terms of Service`}),` `,`and`,` `,(0,Z.jsx)(mu,{to:`/privacy`,className:`underline underline-offset-4 hover:text-primary`,children:`Privacy Policy`}),`.`]})]})}function ud({className:e=`h-5 w-5`,...t}){return(0,Z.jsxs)(`svg`,{className:`animate-spin ${e}`,xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,...t,children:[(0,Z.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,Z.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]})}function dd({children:e}){let[t,n]=(0,X.useState)(`loading`);return(0,X.useEffect)(()=>{(async()=>{try{if(!rd()){console.log(`No authentication token found, redirecting to login`),n(`unauthenticated`);return}let e=await nd();e?(console.log(`User authenticated:`,e.email),n(`authenticated`)):(console.log(`User not authenticated or token expired`),n(`unauthenticated`))}catch(e){if(console.error(`Authentication check failed:`,e),$u(e)){n(ed()?`authenticated`:`unauthenticated`);return}e instanceof Error&&e.message.includes(`Authentication required`)&&(console.log(`Clearing invalid token from ProtectedRoute`),Y.clearAuthToken()),n(`unauthenticated`)}})()},[]),t===`loading`?(0,Z.jsx)(`div`,{className:`flex h-screen items-center justify-center`,children:(0,Z.jsx)(ud,{className:`h-8 w-8`})}):t===`unauthenticated`?(0,Z.jsx)(Cl,{to:`/login`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}function fd({children:e}){let[t,n]=(0,X.useState)(null);return(0,X.useEffect)(()=>{(async()=>{try{await Y.get(`/auth/me`),n(!0)}catch(e){e instanceof Error&&e.message.includes(`Authentication required`)&&(console.log(`Clearing invalid token from PublicRoute`),Y.clearAuthToken()),n(!1)}})()},[]),t===null?null:t?(0,Z.jsx)(Cl,{to:`/workspaces`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}var pd=i(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?r(e):typeof define==`function`&&define.amd?define([`exports`],r):(n=typeof globalThis<`u`?globalThis:n||self,r(n[`fast-equals`]={}))})(e,(function(e){function t(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function n(e){return function(t,n,r,i){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r,i);var a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);var s=e(t,n,r,i);return i.delete(t),i.delete(n),s}}function r(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n}function i(e){return e.constructor===Object||e.constructor==null}function a(e){return typeof e.then==`function`}function o(e,t){return e===t||e!==e&&t!==t}var s=Object.prototype.toString;function c(e){var t=e.areArraysEqual,n=e.areDatesEqual,r=e.areMapsEqual,c=e.areObjectsEqual,l=e.areRegExpsEqual,u=e.areSetsEqual,d=e.createIsNestedEqual,f=d(p);function p(e,d,p){if(e===d)return!0;if(!e||!d||typeof e!=`object`||typeof d!=`object`)return e!==e&&d!==d;if(i(e)&&i(d))return c(e,d,f,p);var m=Array.isArray(e),h=Array.isArray(d);if(m||h)return m===h&&t(e,d,f,p);var g=s.call(e);return g===s.call(d)?g===`[object Date]`?n(e,d,f,p):g===`[object RegExp]`?l(e,d,f,p):g===`[object Map]`?r(e,d,f,p):g===`[object Set]`?u(e,d,f,p):g===`[object Object]`||g===`[object Arguments]`?a(e)||a(d)?!1:c(e,d,f,p):g===`[object Boolean]`||g===`[object Number]`||g===`[object String]`?o(e.valueOf(),d.valueOf()):!1:!1}return p}function l(e,t,n,r){var i=e.length;if(t.length!==i)return!1;for(;i-->0;)if(!n(e[i],t[i],i,i,e,t,r))return!1;return!0}var u=n(l);function d(e,t){return o(e.valueOf(),t.valueOf())}function f(e,t,n,r){var i=e.size===t.size;if(!i)return!1;if(!e.size)return!0;var a={},o=0;return e.forEach(function(s,c){if(i){var l=!1,u=0;t.forEach(function(i,d){!l&&!a[u]&&(l=n(c,d,o,u,e,t,r)&&n(s,i,c,d,e,t,r))&&(a[u]=!0),u++}),o++,i=l}}),i}var p=n(f),m=`_owner`,h=Object.prototype.hasOwnProperty;function g(e,t,n,r){var i=Object.keys(e),a=i.length;if(Object.keys(t).length!==a)return!1;for(var o;a-->0;){if(o=i[a],o===m){var s=!!e.$$typeof,c=!!t.$$typeof;if((s||c)&&s!==c)return!1}if(!h.call(t,o)||!n(e[o],t[o],o,o,e,t,r))return!1}return!0}var _=n(g);function v(e,t){return e.source===t.source&&e.flags===t.flags}function y(e,t,n,r){var i=e.size===t.size;if(!i)return!1;if(!e.size)return!0;var a={};return e.forEach(function(o,s){if(i){var c=!1,l=0;t.forEach(function(i,u){!c&&!a[l]&&(c=n(o,i,s,u,e,t,r))&&(a[l]=!0),l++}),i=c}}),i}var b=n(y),x=Object.freeze({areArraysEqual:l,areDatesEqual:d,areMapsEqual:f,areObjectsEqual:g,areRegExpsEqual:v,areSetsEqual:y,createIsNestedEqual:t}),S=Object.freeze({areArraysEqual:u,areDatesEqual:d,areMapsEqual:p,areObjectsEqual:_,areRegExpsEqual:v,areSetsEqual:b,createIsNestedEqual:t}),C=c(x);function w(e,t){return C(e,t,void 0)}var T=c(r(x,{createIsNestedEqual:function(){return o}}));function E(e,t){return T(e,t,void 0)}var D=c(S);function O(e,t){return D(e,t,new WeakMap)}var k=c(r(S,{createIsNestedEqual:function(){return o}}));function A(e,t){return k(e,t,new WeakMap)}function j(e){return c(r(x,e(x)))}function M(e){var t=c(r(S,e(S)));return(function(e,n,r){return r===void 0&&(r=new WeakMap),t(e,n,r)})}e.circularDeepEqual=O,e.circularShallowEqual=A,e.createCustomCircularEqual=M,e.createCustomEqual=j,e.deepEqual=w,e.sameValueZeroEqual=o,e.shallowEqual=E,Object.defineProperty(e,"__esModule",{value:!0})}))})),md=i(((e,t)=>{t.exports=function(e,t,n){return e===t||e.className===t.className&&n(e.style,t.style)&&e.width===t.width&&e.autoSize===t.autoSize&&e.cols===t.cols&&e.draggableCancel===t.draggableCancel&&e.draggableHandle===t.draggableHandle&&n(e.verticalCompact,t.verticalCompact)&&n(e.compactType,t.compactType)&&n(e.layout,t.layout)&&n(e.margin,t.margin)&&n(e.containerPadding,t.containerPadding)&&e.rowHeight===t.rowHeight&&e.maxRows===t.maxRows&&e.isBounded===t.isBounded&&e.isDraggable===t.isDraggable&&e.isResizable===t.isResizable&&e.allowOverlap===t.allowOverlap&&e.preventCollision===t.preventCollision&&e.useCSSTransforms===t.useCSSTransforms&&e.transformScale===t.transformScale&&e.isDroppable===t.isDroppable&&n(e.resizeHandles,t.resizeHandles)&&n(e.resizeHandle,t.resizeHandle)&&e.onLayoutChange===t.onLayoutChange&&e.onDragStart===t.onDragStart&&e.onDrag===t.onDrag&&e.onDragStop===t.onDragStop&&e.onResizeStart===t.onResizeStart&&e.onResize===t.onResize&&e.onResizeStop===t.onResizeStop&&e.onDrop===t.onDrop&&n(e.droppingItem,t.droppingItem)&&n(e.innerRef,t.innerRef)}})),hd=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.bottom=l,e.childrenEqual=h,e.cloneLayout=u,e.cloneLayoutItem=m,e.collides=_,e.compact=v,e.compactItem=x,e.compactType=ce,e.correctBounds=S,e.fastPositionEqual=g,e.fastRGLPropsEqual=void 0,e.getAllCollisions=T,e.getFirstCollision=w,e.getLayoutItem=C,e.getStatics=E,e.modifyLayout=f,e.moveElement=D,e.moveElementAwayFromCollision=O,e.noop=void 0,e.perc=k,e.resizeItemInDirection=ne,e.setTopLeft=ie,e.setTransform=re,e.sortLayoutItems=L,e.sortLayoutItemsByColRow=ae,e.sortLayoutItemsByRowCol=R,e.synchronizeLayoutWithChildren=oe,e.validateLayout=se,e.withLayoutItem=p;var t=pd(),n=r(d());function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?i(Object(n),!0).forEach(function(t){o(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function o(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e){var t=c(e,`string`);return typeof t==`symbol`?t:t+``}function c(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){let t=0,n;for(let r=0,i=e.length;r<i;r++)n=e[r].y+e[r].h,n>t&&(t=n);return t}function u(e){let t=Array(e.length);for(let n=0,r=e.length;n<r;n++)t[n]=m(e[n]);return t}function f(e,t){let n=Array(e.length);for(let r=0,i=e.length;r<i;r++)t.i===e[r].i?n[r]=t:n[r]=e[r];return n}function p(e,t,n){let r=C(e,t);return r?(r=n(m(r)),e=f(e,r),[e,r]):[e,null]}function m(e){return{w:e.w,h:e.h,x:e.x,y:e.y,i:e.i,minW:e.minW,maxW:e.maxW,minH:e.minH,maxH:e.maxH,moved:!!e.moved,static:!!e.static,isDraggable:e.isDraggable,isResizable:e.isResizable,resizeHandles:e.resizeHandles,isBounded:e.isBounded}}function h(e,r){return(0,t.deepEqual)(n.default.Children.map(e,e=>e?.key),n.default.Children.map(r,e=>e?.key))&&(0,t.deepEqual)(n.default.Children.map(e,e=>e?.props[`data-grid`]),n.default.Children.map(r,e=>e?.props[`data-grid`]))}e.fastRGLPropsEqual=md();function g(e,t){return e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height}function _(e,t){return!(e.i===t.i||e.x+e.w<=t.x||e.x>=t.x+t.w||e.y+e.h<=t.y||e.y>=t.y+t.h)}function v(e,t,n,r){let i=E(e),a=l(i),o=L(e,t),s=Array(e.length);for(let c=0,l=o.length;c<l;c++){let l=m(o[c]);l.static||(l=x(i,l,t,n,o,r,a),a=Math.max(a,l.y+l.h),i.push(l)),s[e.indexOf(o[c])]=l,l.moved=!1}return s}var y={x:`w`,y:`h`};function b(e,t,n,r){let i=y[r];t[r]+=1;let a=e.map(e=>e.i).indexOf(t.i);for(let o=a+1;o<e.length;o++){let a=e[o];if(!a.static){if(a.y>t.y+t.h)break;_(t,a)&&b(e,a,n+t[i],r)}}t[r]=n}function x(e,t,n,r,i,a,o){let s=n===`vertical`,c=n===`horizontal`;if(s)for(t.y=Math.min(typeof o==`number`?o:l(e),t.y);t.y>0&&!w(e,t);)t.y--;else if(c)for(;t.x>0&&!w(e,t);)t.x--;let u;for(;(u=w(e,t))&&!(n===null&&a);)if(c?b(i,t,u.x+u.w,`x`):b(i,t,u.y+u.h,`y`),c&&t.x+t.w>r)for(t.x=r-t.w,t.y++;t.x>0&&!w(e,t);)t.x--;return t.y=Math.max(t.y,0),t.x=Math.max(t.x,0),t}function S(e,t){let n=E(e);for(let r=0,i=e.length;r<i;r++){let i=e[r];if(i.x+i.w>t.cols&&(i.x=t.cols-i.w),i.x<0&&(i.x=0,i.w=t.cols),!i.static)n.push(i);else for(;w(n,i);)i.y++}return e}function C(e,t){for(let n=0,r=e.length;n<r;n++)if(e[n].i===t)return e[n]}function w(e,t){for(let n=0,r=e.length;n<r;n++)if(_(e[n],t))return e[n]}function T(e,t){return e.filter(e=>_(e,t))}function E(e){return e.filter(e=>e.static)}function D(e,t,n,r,i,a,o,s,c){if(t.static&&t.isDraggable!==!0||t.y===r&&t.x===n)return e;`${t.i}${String(n)}${String(r)}${t.x}${t.y}`;let l=t.x,d=t.y;typeof n==`number`&&(t.x=n),typeof r==`number`&&(t.y=r),t.moved=!0;let f=L(e,o);(o===`vertical`&&typeof r==`number`?d>=r:o===`horizontal`&&typeof n==`number`&&l>=n)&&(f=f.reverse());let p=T(f,t),m=p.length>0;if(m&&c)return u(e);if(m&&a)return`${t.i}`,t.x=l,t.y=d,t.moved=!1,e;for(let n=0,r=p.length;n<r;n++){let r=p[n];`${t.i}${t.x}${t.y}${r.i}${r.x}${r.y}`,!r.moved&&(e=r.static?O(e,r,t,i,o,s):O(e,t,r,i,o,s))}return e}function O(e,t,n,r,i,a){let o=i===`horizontal`,s=i===`vertical`,c=t.static;if(r){r=!1;let l={x:o?Math.max(t.x-n.w,0):n.x,y:s?Math.max(t.y-n.h,0):n.y,w:n.w,h:n.h,i:`-1`},u=w(e,l),d=u&&u.y+u.h>t.y,f=u&&t.x+t.w>u.x;if(!u)return`${n.i}${l.x}${l.y}`,D(e,n,o?l.x:void 0,s?l.y:void 0,r,c,i,a);if(d&&s)return D(e,n,void 0,n.y+1,r,c,i,a);if(d&&i==null)return t.y=n.y,n.y+=n.h,e;if(f&&o)return D(e,t,n.x,void 0,r,c,i,a)}let l=o?n.x+1:void 0,u=s?n.y+1:void 0;return l==null&&u==null?e:D(e,n,o?n.x+1:void 0,s?n.y+1:void 0,r,c,i,a)}function k(e){return e*100+`%`}var A=(e,t,n,r)=>e+n>r?t:n,j=(e,t,n)=>e<0?t:n,M=e=>Math.max(0,e),N=e=>Math.max(0,e),P=(e,t,n)=>{let{left:r,height:i,width:a}=t,o=e.top-(i-e.height);return{left:r,width:a,height:j(o,e.height,i),top:N(o)}},F=(e,t,n)=>{let{top:r,left:i,height:a,width:o}=t;return{top:r,height:a,width:A(e.left,e.width,o,n),left:M(i)}},I=(e,t,n)=>{let{top:r,height:i,width:a}=t,o=e.left-(a-e.width);return{height:i,width:o<0?e.width:A(e.left,e.width,a,n),top:N(r),left:M(o)}},ee=(e,t,n)=>{let{top:r,left:i,height:a,width:o}=t;return{width:o,left:i,height:j(r,e.height,a),top:N(r)}},te={n:P,ne:function(){return P(arguments.length<=0?void 0:arguments[0],F(...arguments),arguments.length<=2?void 0:arguments[2])},e:F,se:function(){return ee(arguments.length<=0?void 0:arguments[0],F(...arguments),arguments.length<=2?void 0:arguments[2])},s:ee,sw:function(){return ee(arguments.length<=0?void 0:arguments[0],I(...arguments),arguments.length<=2?void 0:arguments[2])},w:I,nw:function(){return P(arguments.length<=0?void 0:arguments[0],I(...arguments),arguments.length<=2?void 0:arguments[2])}};function ne(e,t,n,r){let i=te[e];return i?i(t,a(a({},t),n),r):n}function re(e){let{top:t,left:n,width:r,height:i}=e,a=`translate(${n}px,${t}px)`;return{transform:a,WebkitTransform:a,MozTransform:a,msTransform:a,OTransform:a,width:`${r}px`,height:`${i}px`,position:`absolute`}}function ie(e){let{top:t,left:n,width:r,height:i}=e;return{top:`${t}px`,left:`${n}px`,width:`${r}px`,height:`${i}px`,position:`absolute`}}function L(e,t){return t===`horizontal`?ae(e):t===`vertical`?R(e):e}function R(e){return e.slice(0).sort(function(e,t){return e.y>t.y||e.y===t.y&&e.x>t.x?1:e.y===t.y&&e.x===t.x?0:-1})}function ae(e){return e.slice(0).sort(function(e,t){return e.x>t.x||e.x===t.x&&e.y>t.y?1:-1})}function oe(e,t,r,i,o){e||=[];let s=[];n.default.Children.forEach(t,t=>{if(t?.key==null)return;let n=C(e,String(t.key)),r=t.props[`data-grid`];n&&r==null?s.push(m(n)):r?s.push(m(a(a({},r),{},{i:t.key}))):s.push(m({w:1,h:1,x:0,y:l(s),i:String(t.key)}))});let c=S(s,{cols:r});return o?c:v(c,i,r)}function se(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:`Layout`,n=[`x`,`y`,`w`,`h`];if(!Array.isArray(e))throw Error(t+` must be an array!`);for(let r=0,i=e.length;r<i;r++){let i=e[r];for(let e=0;e<n.length;e++){let a=n[e],o=i[a];if(typeof o!=`number`||Number.isNaN(o))throw Error(`ReactGridLayout: ${t}[${r}].${a} must be a number! Received: ${o} (${typeof o})`)}if(i.i!==void 0&&typeof i.i!=`string`)throw Error(`ReactGridLayout: ${t}[${r}].i must be a string! Received: ${i.i} (${typeof i.i})`)}}function ce(e){let{verticalCompact:t,compactType:n}=e||{};return t===!1?null:n}e.noop=()=>{}})),gd=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.calcGridColWidth=t,e.calcGridItemPosition=r,e.calcGridItemWHPx=n,e.calcWH=a,e.calcXY=i,e.clamp=o;function t(e){let{margin:t,containerPadding:n,containerWidth:r,cols:i}=e;return(r-t[0]*(i-1)-n[0]*2)/i}function n(e,t,n){return Number.isFinite(e)?Math.round(t*e+Math.max(0,e-1)*n):e}function r(e,r,i,a,o,s){let{margin:c,containerPadding:l,rowHeight:u}=e,d=t(e),f={};return s&&s.resizing?(f.width=Math.round(s.resizing.width),f.height=Math.round(s.resizing.height)):(f.width=n(a,d,c[0]),f.height=n(o,u,c[1])),s&&s.dragging?(f.top=Math.round(s.dragging.top),f.left=Math.round(s.dragging.left)):s&&s.resizing&&typeof s.resizing.top==`number`&&typeof s.resizing.left==`number`?(f.top=Math.round(s.resizing.top),f.left=Math.round(s.resizing.left)):(f.top=Math.round((u+c[1])*i+l[1]),f.left=Math.round((d+c[0])*r+l[0])),f}function i(e,n,r,i,a){let{margin:s,containerPadding:c,cols:l,rowHeight:u,maxRows:d}=e,f=t(e),p=Math.round((r-c[0])/(f+s[0])),m=Math.round((n-c[1])/(u+s[1]));return p=o(p,0,l-i),m=o(m,0,d-a),{x:p,y:m}}function a(e,n,r,i,a,s){let{margin:c,maxRows:l,cols:u,rowHeight:d}=e,f=t(e),p=Math.round((n+c[0])/(f+c[0])),m=Math.round((r+c[1])/(d+c[1])),h=o(p,0,u-i),g=o(m,0,l-a);return[`sw`,`w`,`nw`].indexOf(s)!==-1&&(h=o(p,0,u)),[`nw`,`n`,`ne`].indexOf(s)!==-1&&(g=o(m,0,l)),{w:h,h:g}}function o(e,t,n){return Math.max(Math.min(e,n),t)}})),_d=i(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),vd=i(((e,t)=>{var n=_d();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),yd=i(((e,t)=>{t.exports=vd()()})),bd=i(((e,t)=>{var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})},u=(e,t,n,a)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let s of o(t))!c.call(e,s)&&s!==n&&r(e,s,{get:()=>t[s],enumerable:!(a=i(t,s))||a.enumerable});return e},f=(e,t,i)=>(i=e==null?{}:n(s(e)),u(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),p=e=>u(r({},`__esModule`,{value:!0}),e),m={};l(m,{DraggableCore:()=>Se,default:()=>Ce}),t.exports=p(m);var h=f(d()),g=f(yd()),_=f(a()),v=yr();function y(e,t){for(let n=0,r=e.length;n<r;n++)if(t.apply(t,[e[n],n,e]))return e[n]}function b(e){return typeof e==`function`||Object.prototype.toString.call(e)===`[object Function]`}function x(e){return typeof e==`number`&&!isNaN(e)}function S(e){return parseInt(e,10)}function C(e,t,n){if(e[t])return Error(`Invalid prop ${t} passed to ${n} - do not set this, set it on the child.`)}var w=[`Moz`,`Webkit`,`O`,`ms`];function T(e=`transform`){if(typeof window>`u`)return``;let t=window.document?.documentElement?.style;if(!t||e in t)return``;for(let n=0;n<w.length;n++)if(E(e,w[n])in t)return w[n];return``}function E(e,t){return t?`${t}${D(e)}`:e}function D(e){let t=``,n=!0;for(let r=0;r<e.length;r++)n?(t+=e[r].toUpperCase(),n=!1):e[r]===`-`?n=!0:t+=e[r];return t}var O=T(),k=``;function A(e,t){k||=y([`matches`,`webkitMatchesSelector`,`mozMatchesSelector`,`msMatchesSelector`,`oMatchesSelector`],function(t){return b(e[t])})??``;let n=e[k];return b(n)?!!n.call(e,t):!1}function j(e,t,n){let r=e;do{if(A(r,t))return!0;if(r===n)return!1;r=r.parentNode}while(r);return!1}function M(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.addEventListener?e.addEventListener(t,a,i):e.attachEvent?e.attachEvent(`on`+t,a):e[`on`+t]=a}function N(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.removeEventListener?e.removeEventListener(t,a,i):e.detachEvent?e.detachEvent(`on`+t,a):e[`on`+t]=null}function P(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=S(n.borderTopWidth),t+=S(n.borderBottomWidth),t}function F(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=S(n.borderLeftWidth),t+=S(n.borderRightWidth),t}function I(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=S(n.paddingTop),t-=S(n.paddingBottom),t}function ee(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=S(n.paddingLeft),t-=S(n.paddingRight),t}function te(e,t,n){let r=t===t.ownerDocument.body?{left:0,top:0}:t.getBoundingClientRect();return{x:(e.clientX+t.scrollLeft-r.left)/n,y:(e.clientY+t.scrollTop-r.top)/n}}function ne(e,t){let n=ie(e,t,`px`);return{[E(`transform`,O)]:n}}function re(e,t){return ie(e,t,``)}function ie({x:e,y:t},n,r){let i=`translate(${e}${r},${t}${r})`;return n&&(i=`translate(${`${typeof n.x==`string`?n.x:n.x+r}`}, ${`${typeof n.y==`string`?n.y:n.y+r}`})`+i),i}function L(e,t){return e.targetTouches&&y(e.targetTouches,e=>t===e.identifier)||e.changedTouches&&y(e.changedTouches,e=>t===e.identifier)}function R(e){if(e.targetTouches&&e.targetTouches[0])return e.targetTouches[0].identifier;if(e.changedTouches&&e.changedTouches[0])return e.changedTouches[0].identifier}function ae(){return typeof __webpack_nonce__<`u`?__webpack_nonce__:void 0}function oe(e,t){if(!e)return;let n=e.getElementById(`react-draggable-style-el`);if(!n){n=e.createElement(`style`),n.type=`text/css`,n.id=`react-draggable-style-el`;let r=t??ae();r&&n.setAttribute(`nonce`,r),n.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;}
|
|
5
5
|
`,n.innerHTML+=`.react-draggable-transparent-selection *::selection {all: inherit;}
|
|
6
6
|
`,e.getElementsByTagName(`head`)[0].appendChild(n)}e.body&&z(e.body,`react-draggable-transparent-selection`)}function se(e){window.requestAnimationFrame?window.requestAnimationFrame(()=>{ce(e)}):ce(e)}function ce(e){if(e)try{e.body&&le(e.body,`react-draggable-transparent-selection`);let t=e.selection;if(t)t.empty();else{let t=(e.defaultView||window).getSelection();t&&t.type!==`Caret`&&t.removeAllRanges()}}catch{}}function z(e,t){e.classList?e.classList.add(t):e.className.match(RegExp(`(?:^|\\s)${t}(?!\\S)`))||(e.className+=` ${t}`)}function le(e,t){e.classList?e.classList.remove(t):e.className=e.className.replace(RegExp(`(?:^|\\s)${t}(?!\\S)`,`g`),``)}function ue(e,t,n){if(!e.props.bounds)return[t,n];let{bounds:r}=e.props;r=typeof r==`string`?r:_e(r);let i=ve(e);if(typeof r==`string`){let{ownerDocument:e}=i,t=e.defaultView;if(!t)throw Error(`Cannot resolve the owner window of the draggable node.`);let n;if(n=r===`parent`?i.parentNode:i.getRootNode().querySelector(r),!(n instanceof t.HTMLElement))throw Error(`Bounds selector "`+r+`" could not find an element.`);let a=n,o=t.getComputedStyle(i),s=t.getComputedStyle(a);r={left:-i.offsetLeft+S(s.paddingLeft)+S(o.marginLeft),top:-i.offsetTop+S(s.paddingTop)+S(o.marginTop),right:ee(a)-F(i)-i.offsetLeft+S(s.paddingRight)-S(o.marginRight),bottom:I(a)-P(i)-i.offsetTop+S(s.paddingBottom)-S(o.marginBottom)}}return x(r.right)&&(t=Math.min(t,r.right)),x(r.bottom)&&(n=Math.min(n,r.bottom)),x(r.left)&&(t=Math.max(t,r.left)),x(r.top)&&(n=Math.max(n,r.top)),[t,n]}function de(e,t,n){return[Math.round(t/e[0])*e[0],Math.round(n/e[1])*e[1]]}function fe(e){return e.props.axis===`both`||e.props.axis===`x`}function pe(e){return e.props.axis===`both`||e.props.axis===`y`}function me(e,t,n){let r=typeof t==`number`?L(e,t):null;if(typeof t==`number`&&!r)return null;let i=ve(n),a=n.props.offsetParent||i.offsetParent||i.ownerDocument.body;return te(r||e,a,n.props.scale)}function he(e,t,n){let r=!x(e.lastX),i=ve(e);return r?{node:i,deltaX:0,deltaY:0,lastX:t,lastY:n,x:t,y:n}:{node:i,deltaX:t-e.lastX,deltaY:n-e.lastY,lastX:e.lastX,lastY:e.lastY,x:t,y:n}}function ge(e,t){let n=e.props.scale;return{node:t.node,x:e.state.x+t.deltaX/n,y:e.state.y+t.deltaY/n,deltaX:t.deltaX/n,deltaY:t.deltaY/n,lastX:e.state.x,lastY:e.state.y}}function _e(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom}}function ve(e){let t=e.findDOMNode();if(!t)throw Error(`<DraggableCore>: Unmounted during event!`);return t}var ye=f(d()),B=f(yd()),be=f(a()),V=typeof process<`u`&&{}.DRAGGABLE_DEBUG?console.log.bind(console):function(){},xe={touch:{start:`touchstart`,move:`touchmove`,stop:`touchend`},mouse:{start:`mousedown`,move:`mousemove`,stop:`mouseup`}},H=xe.mouse,Se=class extends ye.Component{constructor(){super(...arguments),this.dragging=!1,this.lastX=NaN,this.lastY=NaN,this.touchIdentifier=null,this.mounted=!1,this.handleDragStart=e=>{if(this.props.onMouseDown(e),!this.props.allowAnyClick&&(typeof e.button==`number`&&e.button!==0||e.ctrlKey))return!1;let t=this.findDOMNode();if(!t||!t.ownerDocument||!t.ownerDocument.body)throw Error(`<DraggableCore> not mounted on DragStart!`);let{ownerDocument:n}=t;if(this.props.disabled||!(e.target instanceof n.defaultView.Node)||this.props.handle&&!j(e.target,this.props.handle,t)||this.props.cancel&&j(e.target,this.props.cancel,t))return;e.type===`touchstart`&&!this.props.allowMobileScroll&&e.preventDefault();let r=R(e);this.touchIdentifier=r;let i=me(e,r,this);if(i==null)return;let{x:a,y:o}=i,s=he(this,a,o);V(`DraggableCore: handleDragStart: %j`,s),V(`calling`,this.props.onStart),this.props.onStart(e,s)!==!1&&this.mounted!==!1&&(this.props.enableUserSelectHack&&oe(n,this.props.nonce),this.dragging=!0,this.lastX=a,this.lastY=o,M(n,H.move,this.handleDrag),M(n,H.stop,this.handleDragStop))},this.handleDrag=e=>{let t=me(e,this.touchIdentifier,this);if(t==null)return;let{x:n,y:r}=t;if(Array.isArray(this.props.grid)){let e=n-this.lastX,t=r-this.lastY;if([e,t]=de(this.props.grid,e,t),!e&&!t)return;n=this.lastX+e,r=this.lastY+t}let i=he(this,n,r);if(V(`DraggableCore: handleDrag: %j`,i),this.props.onDrag(e,i)===!1||this.mounted===!1){try{this.handleDragStop(new MouseEvent(`mouseup`))}catch{let e=document.createEvent(`MouseEvents`);e.initMouseEvent(`mouseup`,!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),this.handleDragStop(e)}return}this.lastX=n,this.lastY=r},this.handleDragStop=e=>{if(!this.dragging)return;let t=me(e,this.touchIdentifier,this);if(t==null)return;let{x:n,y:r}=t;if(Array.isArray(this.props.grid)){let e=n-this.lastX||0,t=r-this.lastY||0;[e,t]=de(this.props.grid,e,t),n=this.lastX+e,r=this.lastY+t}let i=he(this,n,r);if(this.props.onStop(e,i)===!1||this.mounted===!1)return!1;let a=this.findDOMNode();a&&this.props.enableUserSelectHack&&se(a.ownerDocument),V(`DraggableCore: handleDragStop: %j`,i),this.dragging=!1,this.lastX=NaN,this.lastY=NaN,a&&(V(`DraggableCore: Removing handlers`),N(a.ownerDocument,H.move,this.handleDrag),N(a.ownerDocument,H.stop,this.handleDragStop))},this.onMouseDown=e=>(H=xe.mouse,this.handleDragStart(e)),this.onMouseUp=e=>(H=xe.mouse,this.handleDragStop(e)),this.onTouchStart=e=>(H=xe.touch,this.handleDragStart(e)),this.onTouchEnd=e=>(H=xe.touch,this.handleDragStop(e))}componentDidMount(){this.mounted=!0;let e=this.findDOMNode();e&&M(e,xe.touch.start,this.onTouchStart,{passive:!1})}componentWillUnmount(){this.mounted=!1;let e=this.findDOMNode();if(e){let{ownerDocument:t}=e;N(t,xe.mouse.move,this.handleDrag),N(t,xe.touch.move,this.handleDrag),N(t,xe.mouse.stop,this.handleDragStop),N(t,xe.touch.stop,this.handleDragStop),N(e,xe.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&se(t)}}findDOMNode(){if(this.props?.nodeRef)return this.props.nodeRef.current;let e=be.default;return typeof e.findDOMNode==`function`?e.findDOMNode(this):(V(`react-draggable: ReactDOM.findDOMNode is not available in React 19+. You must provide a nodeRef prop. See: https://github.com/react-grid-layout/react-draggable#noderef`),null)}render(){return ye.cloneElement(ye.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}};Se.displayName=`DraggableCore`,Se.propTypes={allowAnyClick:B.default.bool,allowMobileScroll:B.default.bool,children:B.default.node.isRequired,disabled:B.default.bool,enableUserSelectHack:B.default.bool,offsetParent:function(e,t){if(e[t]&&e[t].nodeType!==1)throw Error(`Draggable's offsetParent must be a DOM Node.`)},grid:B.default.arrayOf(B.default.number),handle:B.default.string,cancel:B.default.string,nodeRef:B.default.object,nonce:B.default.string,onStart:B.default.func,onDrag:B.default.func,onStop:B.default.func,onMouseDown:B.default.func,scale:B.default.number,className:C,style:C,transform:C},Se.defaultProps={allowAnyClick:!1,allowMobileScroll:!1,disabled:!1,enableUserSelectHack:!0,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){},scale:1};var Ce=class extends h.Component{constructor(e){super(e),this.onDragStart=(e,t)=>{if(V(`Draggable: onDragStart: %j`,t),this.props.onStart(e,ge(this,t))===!1)return!1;this.setState({dragging:!0,dragged:!0})},this.onDrag=(e,t)=>{if(!this.state.dragging)return!1;V(`Draggable: onDrag: %j`,t);let n=ge(this,t),r={x:n.x,y:n.y,slackX:0,slackY:0};if(this.props.bounds){let{x:e,y:t}=r;r.x+=this.state.slackX,r.y+=this.state.slackY;let[i,a]=ue(this,r.x,r.y);r.x=i,r.y=a,r.slackX=this.state.slackX+(e-r.x),r.slackY=this.state.slackY+(t-r.y),n.x=r.x,n.y=r.y,n.deltaX=r.x-this.state.x,n.deltaY=r.y-this.state.y}if(this.props.onDrag(e,n)===!1)return!1;this.setState(r)},this.onDragStop=(e,t)=>{if(!this.state.dragging||this.props.onStop(e,ge(this,t))===!1)return!1;V(`Draggable: onDragStop: %j`,t);let n={dragging:!1,slackX:0,slackY:0};if(this.props.position){let{x:e,y:t}=this.props.position;n.x=e,n.y=t}this.setState(n)},this.state={dragging:!1,dragged:!1,x:e.position?e.position.x:e.defaultPosition.x,y:e.position?e.position.y:e.defaultPosition.y,prevPropsPosition:{...e.position},slackX:0,slackY:0,isElementSVG:!1},e.position&&!(e.onDrag||e.onStop)&&console.warn("A `position` was applied to this <Draggable>, without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element.")}static getDerivedStateFromProps({position:e},{prevPropsPosition:t}){return e&&(!t||e.x!==t.x||e.y!==t.y)?(V(`Draggable: getDerivedStateFromProps %j`,{position:e,prevPropsPosition:t}),{x:e.x,y:e.y,prevPropsPosition:{...e}}):null}componentDidMount(){window.SVGElement!==void 0&&this.findDOMNode()instanceof window.SVGElement&&this.setState({isElementSVG:!0})}componentWillUnmount(){this.state.dragging&&this.setState({dragging:!1})}findDOMNode(){if(this.props?.nodeRef)return this.props.nodeRef.current;let e=_.default;return typeof e.findDOMNode==`function`?e.findDOMNode(this):null}render(){let{axis:e,bounds:t,children:n,defaultPosition:r,defaultClassName:i,defaultClassNameDragging:a,defaultClassNameDragged:o,position:s,positionOffset:c,scale:l,...u}=this.props,d={},f=null,p=!s||this.state.dragging,m=s||r,g={x:fe(this)&&p?this.state.x:m.x,y:pe(this)&&p?this.state.y:m.y};this.state.isElementSVG?f=re(g,c):d=ne(g,c);let _=h.Children.only(n),y=(0,v.clsx)(_.props.className||``,i,{[a]:this.state.dragging,[o]:this.state.dragged});return h.createElement(Se,{...u,onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop},h.cloneElement(_,{className:y,style:{..._.props.style,...d},transform:f}))}};Ce.displayName=`Draggable`,Ce.propTypes={...Se.propTypes,axis:g.default.oneOf([`both`,`x`,`y`,`none`]),bounds:g.default.oneOfType([g.default.shape({left:g.default.number,right:g.default.number,top:g.default.number,bottom:g.default.number}),g.default.string,g.default.oneOf([!1])]),defaultClassName:g.default.string,defaultClassNameDragging:g.default.string,defaultClassNameDragged:g.default.string,defaultPosition:g.default.shape({x:g.default.number,y:g.default.number}),positionOffset:g.default.shape({x:g.default.oneOfType([g.default.number,g.default.string]),y:g.default.oneOfType([g.default.number,g.default.string])}),position:g.default.shape({x:g.default.number,y:g.default.number}),className:C,style:C,transform:C},Ce.defaultProps={...Se.defaultProps,axis:`both`,bounds:!1,defaultClassName:`react-draggable`,defaultClassNameDragging:`react-draggable-dragging`,defaultClassNameDragged:`react-draggable-dragged`,defaultPosition:{x:0,y:0},scale:1},0&&(t.exports={DraggableCore:Se})})),xd=i(((e,t)=>{var n=bd(),r=n.DraggableCore,i=n.default||n;t.exports=i,t.exports.default=i,t.exports.DraggableCore=r})),Sd=i((e=>{e.__esModule=!0,e.cloneElement=c;var t=n(d());function n(e){return e&&e.__esModule?e:{default:e}}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?r(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function a(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e){var t=s(e,`string`);return typeof t==`symbol`?t:t+``}function s(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e,n){return n.style&&e.props.style&&(n.style=i(i({},e.props.style),n.style)),n.className&&e.props.className&&(n.className=e.props.className+` `+n.className),t.default.cloneElement(e,n)}})),Cd=i((e=>{e.__esModule=!0,e.resizableProps=void 0;var t=n(yd());xd();function n(e){return e&&e.__esModule?e:{default:e}}e.resizableProps={axis:t.default.oneOf([`both`,`x`,`y`,`none`]),className:t.default.string,children:t.default.element.isRequired,draggableOpts:t.default.shape({allowAnyClick:t.default.bool,cancel:t.default.string,children:t.default.node,disabled:t.default.bool,enableUserSelectHack:t.default.bool,offsetParent:typeof Element<`u`?t.default.instanceOf(Element):t.default.any,grid:t.default.arrayOf(t.default.number),handle:t.default.string,nodeRef:t.default.object,onStart:t.default.func,onDrag:t.default.func,onStop:t.default.func,onMouseDown:t.default.func,scale:t.default.number}),height:function(){var e=[...arguments];let n=e[0];return n.axis===`both`||n.axis===`y`?t.default.number.isRequired(...e):t.default.number(...e)},handle:t.default.oneOfType([t.default.node,t.default.func]),handleSize:t.default.arrayOf(t.default.number),lockAspectRatio:t.default.bool,maxConstraints:t.default.arrayOf(t.default.number),minConstraints:t.default.arrayOf(t.default.number),onResizeStop:t.default.func,onResizeStart:t.default.func,onResize:t.default.func,resizeHandles:t.default.arrayOf(t.default.oneOf([`s`,`w`,`e`,`n`,`sw`,`nw`,`se`,`ne`])),transformScale:t.default.number,width:function(){var e=[...arguments];let n=e[0];return n.axis===`both`||n.axis===`x`?t.default.number.isRequired(...e):t.default.number(...e)}}})),wd=i((e=>{e.__esModule=!0,e.default=void 0;var t=o(d()),n=xd(),r=Sd(),i=Cd(),a=[`children`,`className`,`draggableOpts`,`width`,`height`,`handle`,`handleSize`,`lockAspectRatio`,`axis`,`minConstraints`,`maxConstraints`,`onResize`,`onResizeStop`,`onResizeStart`,`resizeHandles`,`transformScale`];function o(e,t){if(typeof WeakMap==`function`)var n=new WeakMap,r=new WeakMap;return(o=function(e,t){if(!t&&e&&e.__esModule)return e;var i,a,o={__proto__:null,default:e};if(e===null||typeof e!=`object`&&typeof e!=`function`)return o;if(i=t?r:n){if(i.has(e))return i.get(e);i.set(e,o)}for(let t in e)t!=="default"&&{}.hasOwnProperty.call(e,t)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(a.get||a.set)?i(o,t,a):o[t]=e[t]);return o})(e,t)}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s.apply(null,arguments)}function c(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?l(Object(n),!0).forEach(function(t){f(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function f(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e){var t=m(e,`string`);return typeof t==`symbol`?t:t+``}function m(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var h=class extends t.Component{constructor(){super(...arguments),this.handleRefs={},this.lastHandleRect=null,this.slack=null,this.lastSize=null}componentWillUnmount(){this.resetData()}resetData(){this.lastHandleRect=this.slack=this.lastSize=null}runConstraints(e,t){let n=this.props,r=n.minConstraints,i=n.maxConstraints,a=n.lockAspectRatio;if(!r&&!i&&!a)return[e,t];if(a){let n=this.props.width/this.props.height,r=e-this.props.width,i=t-this.props.height;Math.abs(r)>Math.abs(i*n)?t=e/n:e=t*n}let o=e,s=t,c=this.slack||[0,0],l=c[0],u=c[1];return e+=l,t+=u,r&&(e=Math.max(r[0],e),t=Math.max(r[1],t)),i&&(e=Math.min(i[0],e),t=Math.min(i[1],t)),this.slack=[l+(o-e),u+(s-t)],[e,t]}resizeHandler(e,t){return(n,r)=>{let i=r.node,a=r.deltaX,o=r.deltaY;e===`onResizeStart`&&this.resetData();let s=(this.props.axis===`both`||this.props.axis===`x`)&&t!==`n`&&t!==`s`,c=(this.props.axis===`both`||this.props.axis===`y`)&&t!==`e`&&t!==`w`;if(!s&&!c)return;let l=t[0],u=t[t.length-1],d=i.getBoundingClientRect();if(this.lastHandleRect!=null){if(u===`w`){let e=d.left-this.lastHandleRect.left;a+=e}if(l===`n`){let e=d.top-this.lastHandleRect.top;o+=e}}this.lastHandleRect=d,u===`w`&&(a=-a),l===`n`&&(o=-o);let f=this.lastSize?.width??this.props.width,p=this.lastSize?.height??this.props.height,m=f+(s?a/this.props.transformScale:0),h=p+(c?o/this.props.transformScale:0);var g=this.runConstraints(m,h);if(m=g[0],h=g[1],e===`onResizeStop`&&this.lastSize){var _=this.lastSize;m=_.width,h=_.height}let v=m!==f||h!==p;e!==`onResizeStop`&&(this.lastSize={width:m,height:h});let y=typeof this.props[e]==`function`?this.props[e]:null;y&&!(e===`onResize`&&!v)&&(n.persist==null||n.persist(),y(n,{node:i,size:{width:m,height:h},handle:t})),e===`onResizeStop`&&this.resetData()}}renderResizeHandle(e,n){let r=this.props.handle;if(!r)return t.createElement(`span`,{className:`react-resizable-handle react-resizable-handle-`+e,ref:n});if(typeof r==`function`)return r(e,n);let i=typeof r.type==`string`,a=u({ref:n},i?{}:{handleAxis:e});return t.cloneElement(r,a)}render(){let e=this.props,i=e.children,o=e.className,l=e.draggableOpts;e.width,e.height,e.handle,e.handleSize,e.lockAspectRatio,e.axis,e.minConstraints,e.maxConstraints,e.onResize,e.onResizeStop,e.onResizeStart;let d=e.resizeHandles;e.transformScale;let f=c(e,a);return(0,r.cloneElement)(i,u(u({},f),{},{className:(o?o+` `:``)+`react-resizable`,children:[...t.Children.toArray(i.props.children),...d.map(e=>{let r=this.handleRefs[e]??(this.handleRefs[e]=t.createRef());return t.createElement(n.DraggableCore,s({},l,{nodeRef:r,key:`resizableHandle-`+e,onStop:this.resizeHandler(`onResizeStop`,e),onStart:this.resizeHandler(`onResizeStart`,e),onDrag:this.resizeHandler(`onResize`,e)}),this.renderResizeHandle(e,r))})]}))}};e.default=h,h.propTypes=i.resizableProps,h.defaultProps={axis:`both`,handleSize:[20,20],lockAspectRatio:!1,minConstraints:[20,20],maxConstraints:[1/0,1/0],resizeHandles:[`se`],transformScale:1}})),Td=i((e=>{e.__esModule=!0,e.default=void 0;var t=s(d()),n=o(yd()),r=o(wd()),i=Cd(),a=[`handle`,`handleSize`,`onResize`,`onResizeStart`,`onResizeStop`,`draggableOpts`,`minConstraints`,`maxConstraints`,`lockAspectRatio`,`axis`,`width`,`height`,`resizeHandles`,`style`,`transformScale`];function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(typeof WeakMap==`function`)var n=new WeakMap,r=new WeakMap;return(s=function(e,t){if(!t&&e&&e.__esModule)return e;var i,a,o={__proto__:null,default:e};if(e===null||typeof e!=`object`&&typeof e!=`function`)return o;if(i=t?r:n){if(i.has(e))return i.get(e);i.set(e,o)}for(let t in e)t!=="default"&&{}.hasOwnProperty.call(e,t)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(a.get||a.set)?i(o,t,a):o[t]=e[t]);return o})(e,t)}function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c.apply(null,arguments)}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?l(Object(n),!0).forEach(function(t){f(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function f(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e){var t=m(e,`string`);return typeof t==`symbol`?t:t+``}function m(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function h(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var g=class extends t.Component{constructor(){super(...arguments),this.state={width:this.props.width,height:this.props.height,propsWidth:this.props.width,propsHeight:this.props.height},this.onResize=(e,t)=>{let n=t.size;this.props.onResize?(e.persist==null||e.persist(),this.setState(n,()=>this.props.onResize&&this.props.onResize(e,t))):this.setState(n)}}static getDerivedStateFromProps(e,t){return t.propsWidth!==e.width||t.propsHeight!==e.height?{width:e.width,height:e.height,propsWidth:e.width,propsHeight:e.height}:null}render(){let e=this.props,n=e.handle,i=e.handleSize;e.onResize;let o=e.onResizeStart,s=e.onResizeStop,l=e.draggableOpts,d=e.minConstraints,f=e.maxConstraints,p=e.lockAspectRatio,m=e.axis;e.width,e.height;let g=e.resizeHandles,_=e.style,v=e.transformScale,y=h(e,a);return t.createElement(r.default,{axis:m,draggableOpts:l,handle:n,handleSize:i,height:this.state.height,lockAspectRatio:p,maxConstraints:f,minConstraints:d,onResizeStart:o,onResize:this.onResize,onResizeStop:s,resizeHandles:g,transformScale:v,width:this.state.width},t.createElement(`div`,c({},y,{style:u(u({},_),{},{width:this.state.width+`px`,height:this.state.height+`px`})})))}};e.default=g,g.propTypes=u(u({},i.resizableProps),{},{children:n.default.element})})),Ed=i(((e,t)=>{t.exports=function(){throw Error(`Don't instantiate Resizable directly! Use require('react-resizable').Resizable`)},t.exports.Resizable=wd().default,t.exports.ResizableBox=Td().default})),Dd=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.resizeHandleType=e.resizeHandleAxesType=e.default=void 0;var t=r(yd()),n=r(d());function r(e){return e&&e.__esModule?e:{default:e}}var i=e.resizeHandleAxesType=t.default.arrayOf(t.default.oneOf([`s`,`w`,`e`,`n`,`sw`,`nw`,`se`,`ne`])),a=e.resizeHandleType=t.default.oneOfType([t.default.node,t.default.func]);e.default={className:t.default.string,style:t.default.object,width:t.default.number,autoSize:t.default.bool,cols:t.default.number,draggableCancel:t.default.string,draggableHandle:t.default.string,verticalCompact:function(e){e.verticalCompact},compactType:t.default.oneOf([`vertical`,`horizontal`]),layout:function(e){var t=e.layout;t!==void 0&&hd().validateLayout(t,`layout`)},margin:t.default.arrayOf(t.default.number),containerPadding:t.default.arrayOf(t.default.number),rowHeight:t.default.number,maxRows:t.default.number,isBounded:t.default.bool,isDraggable:t.default.bool,isResizable:t.default.bool,allowOverlap:t.default.bool,preventCollision:t.default.bool,useCSSTransforms:t.default.bool,transformScale:t.default.number,isDroppable:t.default.bool,resizeHandles:i,resizeHandle:a,onLayoutChange:t.default.func,onDragStart:t.default.func,onDrag:t.default.func,onDragStop:t.default.func,onResizeStart:t.default.func,onResize:t.default.func,onResizeStop:t.default.func,onDrop:t.default.func,droppingItem:t.default.shape({i:t.default.string.isRequired,w:t.default.number.isRequired,h:t.default.number.isRequired}),children:function(e,t){let r=e[t],i={};n.default.Children.forEach(r,function(e){if(e?.key!=null){if(i[e.key])throw Error(`Duplicate child key "`+e.key+`" found! This will cause problems in ReactGridLayout.`);i[e.key]=!0}})},innerRef:t.default.any}})),Od=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var t=f(d()),n=a(),r=f(yd()),i=xd(),o=Ed(),s=hd(),c=gd(),l=Dd(),u=f(yr());function f(e){return e&&e.__esModule?e:{default:e}}function p(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function m(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?p(Object(n),!0).forEach(function(t){h(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function h(e,t,n){return(t=g(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e){var t=_(e,`string`);return typeof t==`symbol`?t:t+``}function _(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var v=class extends t.default.Component{constructor(){super(...arguments),h(this,`state`,{resizing:null,dragging:null,className:``}),h(this,`elementRef`,t.default.createRef()),h(this,`onDragStart`,(e,t)=>{let{node:n}=t,{onDragStart:r,transformScale:i}=this.props;if(!r)return;let a={top:0,left:0},{offsetParent:o}=n;if(!o)return;let s=o.getBoundingClientRect(),l=n.getBoundingClientRect(),u=l.left/i,d=s.left/i,f=l.top/i,p=s.top/i;a.left=u-d+o.scrollLeft,a.top=f-p+o.scrollTop,this.setState({dragging:a});let{x:m,y:h}=(0,c.calcXY)(this.getPositionParams(),a.top,a.left,this.props.w,this.props.h);return r.call(this,this.props.i,m,h,{e,node:n,newPosition:a})}),h(this,`onDrag`,(e,t,r)=>{let{node:i,deltaX:a,deltaY:o}=t,{onDrag:s}=this.props;if(!s)return;if(!this.state.dragging)throw Error(`onDrag called before onDragStart.`);let l=this.state.dragging.top+o,u=this.state.dragging.left+a,{isBounded:d,i:f,w:p,h:m,containerWidth:h}=this.props,g=this.getPositionParams();if(d){let{offsetParent:e}=i;if(e){let{margin:t,rowHeight:n}=this.props,r=e.clientHeight-(0,c.calcGridItemWHPx)(m,n,t[1]);l=(0,c.clamp)(l,0,r);let i=(0,c.calcGridColWidth)(g),a=h-(0,c.calcGridItemWHPx)(p,i,t[0]);u=(0,c.clamp)(u,0,a)}}let _={top:l,left:u};r?this.setState({dragging:_}):(0,n.flushSync)(()=>{this.setState({dragging:_})});let{x:v,y}=(0,c.calcXY)(g,l,u,p,m);return s.call(this,f,v,y,{e,node:i,newPosition:_})}),h(this,`onDragStop`,(e,t)=>{let{node:n}=t,{onDragStop:r}=this.props;if(!r)return;if(!this.state.dragging)throw Error(`onDragEnd called before onDragStart.`);let{w:i,h:a,i:o}=this.props,{left:s,top:l}=this.state.dragging,u={top:l,left:s};this.setState({dragging:null});let{x:d,y:f}=(0,c.calcXY)(this.getPositionParams(),l,s,i,a);return r.call(this,o,d,f,{e,node:n,newPosition:u})}),h(this,`onResizeStop`,(e,t,n)=>this.onResizeHandler(e,t,n,`onResizeStop`)),h(this,`onResizeStart`,(e,t,n)=>this.onResizeHandler(e,t,n,`onResizeStart`)),h(this,`onResize`,(e,t,n)=>this.onResizeHandler(e,t,n,`onResize`))}shouldComponentUpdate(e,t){if(this.props.children!==e.children||this.props.droppingPosition!==e.droppingPosition)return!0;let n=(0,c.calcGridItemPosition)(this.getPositionParams(this.props),this.props.x,this.props.y,this.props.w,this.props.h,this.state),r=(0,c.calcGridItemPosition)(this.getPositionParams(e),e.x,e.y,e.w,e.h,t);return!(0,s.fastPositionEqual)(n,r)||this.props.useCSSTransforms!==e.useCSSTransforms}componentDidMount(){this.moveDroppingItem({})}componentDidUpdate(e){this.moveDroppingItem(e)}moveDroppingItem(e){let{droppingPosition:t}=this.props;if(!t)return;let n=this.elementRef.current;if(!n)return;let r=e.droppingPosition||{left:0,top:0},{dragging:i}=this.state,a=i&&t.left!==r.left||t.top!==r.top;if(!i)this.onDragStart(t.e,{node:n,deltaX:t.left,deltaY:t.top});else if(a){let e=t.left-i.left,r=t.top-i.top;this.onDrag(t.e,{node:n,deltaX:e,deltaY:r},!0)}}getPositionParams(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.props;return{cols:e.cols,containerPadding:e.containerPadding,containerWidth:e.containerWidth,margin:e.margin,maxRows:e.maxRows,rowHeight:e.rowHeight}}createStyle(e){let{usePercentages:t,containerWidth:n,useCSSTransforms:r}=this.props,i;return r?i=(0,s.setTransform)(e):(i=(0,s.setTopLeft)(e),t&&(i.left=(0,s.perc)(e.left/n),i.width=(0,s.perc)(e.width/n))),i}mixinDraggable(e,n){return t.default.createElement(i.DraggableCore,{disabled:!n,onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop,handle:this.props.handle,cancel:`.react-resizable-handle`+(this.props.cancel?`,`+this.props.cancel:``),scale:this.props.transformScale,nodeRef:this.elementRef},e)}curryResizeHandler(e,t){return(n,r)=>t(n,r,e)}mixinResizable(e,n,r){let{cols:i,minW:a,minH:s,maxW:l,maxH:u,transformScale:d,resizeHandles:f,resizeHandle:p}=this.props,m=this.getPositionParams(),h=(0,c.calcGridItemPosition)(m,0,0,i,0).width,g=(0,c.calcGridItemPosition)(m,0,0,a,s),_=(0,c.calcGridItemPosition)(m,0,0,l,u),v=[g.width,g.height],y=[Math.min(_.width,h),Math.min(_.height,1/0)];return t.default.createElement(o.Resizable,{draggableOpts:{disabled:!r},className:r?void 0:`react-resizable-hide`,width:n.width,height:n.height,minConstraints:v,maxConstraints:y,onResizeStop:this.curryResizeHandler(n,this.onResizeStop),onResizeStart:this.curryResizeHandler(n,this.onResizeStart),onResize:this.curryResizeHandler(n,this.onResize),transformScale:d,resizeHandles:f,handle:p},e)}onResizeHandler(e,t,r,i){let{node:a,size:o,handle:l}=t,u=this.props[i];if(!u)return;let{x:d,y:f,i:p,maxH:m,minH:h,containerWidth:g}=this.props,{minW:_,maxW:v}=this.props,y=o;a&&(y=(0,s.resizeItemInDirection)(l,r,o,g),(0,n.flushSync)(()=>{this.setState({resizing:i===`onResizeStop`?null:y})}));let{w:b,h:x}=(0,c.calcWH)(this.getPositionParams(),y.width,y.height,d,f,l);b=(0,c.clamp)(b,Math.max(_,1),v),x=(0,c.clamp)(x,h,m),u.call(this,p,b,x,{e,node:a,size:y,handle:l})}render(){let{x:e,y:n,w:r,h:i,isDraggable:a,isResizable:o,droppingPosition:s,useCSSTransforms:l}=this.props,d=(0,c.calcGridItemPosition)(this.getPositionParams(),e,n,r,i,this.state),f=t.default.Children.only(this.props.children),p=t.default.cloneElement(f,{ref:this.elementRef,className:(0,u.default)(`react-grid-item`,f.props.className,this.props.className,{static:this.props.static,resizing:!!this.state.resizing,"react-draggable":a,"react-draggable-dragging":!!this.state.dragging,dropping:!!s,cssTransforms:l}),style:m(m(m({},this.props.style),f.props.style),this.createStyle(d))});return p=this.mixinResizable(p,d,o),p=this.mixinDraggable(p,a),p}};e.default=v,h(v,`propTypes`,{children:r.default.element,cols:r.default.number.isRequired,containerWidth:r.default.number.isRequired,rowHeight:r.default.number.isRequired,margin:r.default.array.isRequired,maxRows:r.default.number.isRequired,containerPadding:r.default.array.isRequired,x:r.default.number.isRequired,y:r.default.number.isRequired,w:r.default.number.isRequired,h:r.default.number.isRequired,minW:function(e,t){let n=e[t];if(typeof n!=`number`)return Error(`minWidth not Number`);if(n>e.w||n>e.maxW)return Error(`minWidth larger than item width/maxWidth`)},maxW:function(e,t){let n=e[t];if(typeof n!=`number`)return Error(`maxWidth not Number`);if(n<e.w||n<e.minW)return Error(`maxWidth smaller than item width/minWidth`)},minH:function(e,t){let n=e[t];if(typeof n!=`number`)return Error(`minHeight not Number`);if(n>e.h||n>e.maxH)return Error(`minHeight larger than item height/maxHeight`)},maxH:function(e,t){let n=e[t];if(typeof n!=`number`)return Error(`maxHeight not Number`);if(n<e.h||n<e.minH)return Error(`maxHeight smaller than item height/minHeight`)},i:r.default.string.isRequired,resizeHandles:l.resizeHandleAxesType,resizeHandle:l.resizeHandleType,onDragStop:r.default.func,onDragStart:r.default.func,onDrag:r.default.func,onResizeStop:r.default.func,onResizeStart:r.default.func,onResize:r.default.func,isDraggable:r.default.bool.isRequired,isResizable:r.default.bool.isRequired,isBounded:r.default.bool.isRequired,static:r.default.bool,useCSSTransforms:r.default.bool.isRequired,transformScale:r.default.number,className:r.default.string,handle:r.default.string,cancel:r.default.string,droppingPosition:r.default.shape({e:r.default.object.isRequired,left:r.default.number.isRequired,top:r.default.number.isRequired})}),h(v,`defaultProps`,{className:``,cancel:``,handle:``,minH:1,minW:1,maxH:1/0,maxW:1/0,transformScale:1})})),kd=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var t=l(d()),n=pd(),r=c(yr()),i=hd(),a=gd(),o=c(Od()),s=c(Dd());function c(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(typeof WeakMap==`function`)var n=new WeakMap,r=new WeakMap;return(l=function(e,t){if(!t&&e&&e.__esModule)return e;var i,a,o={__proto__:null,default:e};if(e===null||typeof e!=`object`&&typeof e!=`function`)return o;if(i=t?r:n){if(i.has(e))return i.get(e);i.set(e,o)}for(let t in e)t!=="default"&&{}.hasOwnProperty.call(e,t)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(a.get||a.set)?i(o,t,a):o[t]=e[t]);return o})(e,t)}function u(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function f(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?u(Object(n),!0).forEach(function(t){p(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function p(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(e){var t=h(e,`string`);return typeof t==`symbol`?t:t+``}function h(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var g=`react-grid-layout`,_=!1;try{_=/firefox/i.test(navigator.userAgent)}catch{}var v=class extends t.Component{constructor(){super(...arguments),p(this,`state`,{activeDrag:null,layout:(0,i.synchronizeLayoutWithChildren)(this.props.layout,this.props.children,this.props.cols,(0,i.compactType)(this.props),this.props.allowOverlap),mounted:!1,oldDragItem:null,oldLayout:null,oldResizeItem:null,resizing:!1,droppingDOMNode:null,children:[]}),p(this,`dragEnterCounter`,0),p(this,`onDragStart`,(e,t,n,r)=>{let{e:a,node:o}=r,{layout:s}=this.state,c=(0,i.getLayoutItem)(s,e);if(!c)return;let l={w:c.w,h:c.h,x:c.x,y:c.y,placeholder:!0,i:e};return this.setState({oldDragItem:(0,i.cloneLayoutItem)(c),oldLayout:s,activeDrag:l}),this.props.onDragStart(s,c,c,null,a,o)}),p(this,`onDrag`,(e,t,n,r)=>{let{e:a,node:o}=r,{oldDragItem:s}=this.state,{layout:c}=this.state,{cols:l,allowOverlap:u,preventCollision:d}=this.props,f=(0,i.getLayoutItem)(c,e);if(!f)return;let p={w:f.w,h:f.h,x:f.x,y:f.y,placeholder:!0,i:e};c=(0,i.moveElement)(c,f,t,n,!0,d,(0,i.compactType)(this.props),l,u),this.props.onDrag(c,s,f,p,a,o),this.setState({layout:u?c:(0,i.compact)(c,(0,i.compactType)(this.props),l),activeDrag:p})}),p(this,`onDragStop`,(e,t,n,r)=>{let{e:a,node:o}=r;if(!this.state.activeDrag)return;let{oldDragItem:s}=this.state,{layout:c}=this.state,{cols:l,preventCollision:u,allowOverlap:d}=this.props,f=(0,i.getLayoutItem)(c,e);if(!f)return;c=(0,i.moveElement)(c,f,t,n,!0,u,(0,i.compactType)(this.props),l,d);let p=d?c:(0,i.compact)(c,(0,i.compactType)(this.props),l);this.props.onDragStop(p,s,f,null,a,o);let{oldLayout:m}=this.state;this.setState({activeDrag:null,layout:p,oldDragItem:null,oldLayout:null}),this.onLayoutMaybeChanged(p,m)}),p(this,`onResizeStart`,(e,t,n,r)=>{let{e:a,node:o}=r,{layout:s}=this.state,c=(0,i.getLayoutItem)(s,e);c&&(this.setState({oldResizeItem:(0,i.cloneLayoutItem)(c),oldLayout:this.state.layout,resizing:!0}),this.props.onResizeStart(s,c,c,null,a,o))}),p(this,`onResize`,(e,t,n,r)=>{let{e:a,node:o,size:s,handle:c}=r,{oldResizeItem:l}=this.state,{layout:u}=this.state,{cols:d,preventCollision:p,allowOverlap:m}=this.props,h=!1,g,_,v,[y,b]=(0,i.withLayoutItem)(u,e,e=>{let r;return _=e.x,v=e.y,[`sw`,`w`,`nw`,`n`,`ne`].indexOf(c)!==-1&&([`sw`,`nw`,`w`].indexOf(c)!==-1&&(_=e.x+(e.w-t),t=e.x!==_&&_<0?e.w:t,_=_<0?0:_),[`ne`,`n`,`nw`].indexOf(c)!==-1&&(v=e.y+(e.h-n),n=e.y!==v&&v<0?e.h:n,v=v<0?0:v),h=!0),p&&!m&&(r=(0,i.getAllCollisions)(u,f(f({},e),{},{w:t,h:n,x:_,y:v})).filter(t=>t.i!==e.i).length>0,r&&(v=e.y,n=e.h,_=e.x,t=e.w,h=!1)),e.w=t,e.h=n,e});if(!b)return;g=y,h&&(g=(0,i.moveElement)(y,b,_,v,!0,this.props.preventCollision,(0,i.compactType)(this.props),d,m));let x={w:b.w,h:b.h,x:b.x,y:b.y,static:!0,i:e};this.props.onResize(g,l,b,x,a,o),this.setState({layout:m?g:(0,i.compact)(g,(0,i.compactType)(this.props),d),activeDrag:x})}),p(this,`onResizeStop`,(e,t,n,r)=>{let{e:a,node:o}=r,{layout:s,oldResizeItem:c}=this.state,{cols:l,allowOverlap:u}=this.props,d=(0,i.getLayoutItem)(s,e),f=u?s:(0,i.compact)(s,(0,i.compactType)(this.props),l);this.props.onResizeStop(f,c,d,null,a,o);let{oldLayout:p}=this.state;this.setState({activeDrag:null,layout:f,oldResizeItem:null,oldLayout:null,resizing:!1}),this.onLayoutMaybeChanged(f,p)}),p(this,`onDragOver`,e=>{var n;if(e.preventDefault(),e.stopPropagation(),_&&!((n=e.nativeEvent.target)!=null&&n.classList.contains(g)))return!1;let{droppingItem:r,onDropDragOver:i,margin:o,cols:s,rowHeight:c,maxRows:l,width:u,containerPadding:d,transformScale:p}=this.props,m=i?.(e);if(m===!1)return this.state.droppingDOMNode&&this.removeDroppingPlaceholder(),!1;let h=f(f({},r),m),{layout:v}=this.state,y=e.currentTarget.getBoundingClientRect(),b=e.clientX-y.left,x=e.clientY-y.top,S={left:b/p,top:x/p,e};if(!this.state.droppingDOMNode){let e={cols:s,margin:o,maxRows:l,rowHeight:c,containerWidth:u,containerPadding:d||o},n=(0,a.calcXY)(e,x,b,h.w,h.h);this.setState({droppingDOMNode:t.createElement(`div`,{key:h.i}),droppingPosition:S,layout:[...v,f(f({},h),{},{x:n.x,y:n.y,static:!1,isDraggable:!0})]})}else if(this.state.droppingPosition){let{left:e,top:t}=this.state.droppingPosition;(e!=b||t!=x)&&this.setState({droppingPosition:S})}}),p(this,`removeDroppingPlaceholder`,()=>{let{droppingItem:e,cols:t}=this.props,{layout:n}=this.state,r=(0,i.compact)(n.filter(t=>t.i!==e.i),(0,i.compactType)(this.props),t,this.props.allowOverlap);this.setState({layout:r,droppingDOMNode:null,activeDrag:null,droppingPosition:void 0})}),p(this,`onDragLeave`,e=>{e.preventDefault(),e.stopPropagation(),this.dragEnterCounter--,this.dragEnterCounter===0&&this.removeDroppingPlaceholder()}),p(this,`onDragEnter`,e=>{e.preventDefault(),e.stopPropagation(),this.dragEnterCounter++}),p(this,`onDrop`,e=>{e.preventDefault(),e.stopPropagation();let{droppingItem:t}=this.props,{layout:n}=this.state,r=n.find(e=>e.i===t.i);this.dragEnterCounter=0,this.removeDroppingPlaceholder(),this.props.onDrop(n,r,e)})}componentDidMount(){this.setState({mounted:!0}),this.onLayoutMaybeChanged(this.state.layout,this.props.layout)}static getDerivedStateFromProps(e,t){let r;return t.activeDrag?null:(!(0,n.deepEqual)(e.layout,t.propsLayout)||e.compactType!==t.compactType?r=e.layout:(0,i.childrenEqual)(e.children,t.children)||(r=t.layout),r?{layout:(0,i.synchronizeLayoutWithChildren)(r,e.children,e.cols,(0,i.compactType)(e),e.allowOverlap),compactType:e.compactType,children:e.children,propsLayout:e.layout}:null)}shouldComponentUpdate(e,t){return this.props.children!==e.children||!(0,i.fastRGLPropsEqual)(this.props,e,n.deepEqual)||this.state.activeDrag!==t.activeDrag||this.state.mounted!==t.mounted||this.state.droppingPosition!==t.droppingPosition}componentDidUpdate(e,t){if(!this.state.activeDrag){let e=this.state.layout,n=t.layout;this.onLayoutMaybeChanged(e,n)}}containerHeight(){if(!this.props.autoSize)return;let e=(0,i.bottom)(this.state.layout),t=this.props.containerPadding?this.props.containerPadding[1]:this.props.margin[1];return e*this.props.rowHeight+(e-1)*this.props.margin[1]+t*2+`px`}onLayoutMaybeChanged(e,t){t||=this.state.layout,(0,n.deepEqual)(t,e)||this.props.onLayoutChange(e)}placeholder(){let{activeDrag:e}=this.state;if(!e)return null;let{width:n,cols:r,margin:i,containerPadding:a,rowHeight:s,maxRows:c,useCSSTransforms:l,transformScale:u}=this.props;return t.createElement(o.default,{w:e.w,h:e.h,x:e.x,y:e.y,i:e.i,className:`react-grid-placeholder ${this.state.resizing?`placeholder-resizing`:``}`,containerWidth:n,cols:r,margin:i,containerPadding:a||i,maxRows:c,rowHeight:s,isDraggable:!1,isResizable:!1,isBounded:!1,useCSSTransforms:l,transformScale:u},t.createElement(`div`,null))}processGridItem(e,n){if(!e||!e.key)return;let r=(0,i.getLayoutItem)(this.state.layout,String(e.key));if(!r)return null;let{width:a,cols:s,margin:c,containerPadding:l,rowHeight:u,maxRows:d,isDraggable:f,isResizable:p,isBounded:m,useCSSTransforms:h,transformScale:g,draggableCancel:_,draggableHandle:v,resizeHandles:y,resizeHandle:b}=this.props,{mounted:x,droppingPosition:S}=this.state,C=typeof r.isDraggable==`boolean`?r.isDraggable:!r.static&&f,w=typeof r.isResizable==`boolean`?r.isResizable:!r.static&&p,T=r.resizeHandles||y,E=C&&m&&r.isBounded!==!1;return t.createElement(o.default,{containerWidth:a,cols:s,margin:c,containerPadding:l||c,maxRows:d,rowHeight:u,cancel:_,handle:v,onDragStop:this.onDragStop,onDragStart:this.onDragStart,onDrag:this.onDrag,onResizeStart:this.onResizeStart,onResize:this.onResize,onResizeStop:this.onResizeStop,isDraggable:C,isResizable:w,isBounded:E,useCSSTransforms:h&&x,usePercentages:!x,transformScale:g,w:r.w,h:r.h,x:r.x,y:r.y,i:r.i,minH:r.minH,minW:r.minW,maxH:r.maxH,maxW:r.maxW,static:r.static,droppingPosition:n?S:void 0,resizeHandles:T,resizeHandle:b},e)}render(){let{className:e,style:n,isDroppable:a,innerRef:o}=this.props,s=(0,r.default)(g,e),c=f({height:this.containerHeight()},n);return t.createElement(`div`,{ref:o,className:s,style:c,onDrop:a?this.onDrop:i.noop,onDragLeave:a?this.onDragLeave:i.noop,onDragEnter:a?this.onDragEnter:i.noop,onDragOver:a?this.onDragOver:i.noop},t.Children.map(this.props.children,e=>this.processGridItem(e)),a&&this.state.droppingDOMNode&&this.processGridItem(this.state.droppingDOMNode,!0),this.placeholder())}};e.default=v,p(v,`displayName`,`ReactGridLayout`),p(v,`propTypes`,s.default),p(v,`defaultProps`,{autoSize:!0,cols:12,className:``,style:{},draggableHandle:``,draggableCancel:``,containerPadding:null,rowHeight:150,maxRows:1/0,layout:[],margin:[10,10],isBounded:!1,isDraggable:!0,isResizable:!0,allowOverlap:!1,isDroppable:!1,useCSSTransforms:!0,transformScale:1,verticalCompact:!0,compactType:`vertical`,preventCollision:!1,droppingItem:{i:`__dropping-elem__`,h:1,w:1},resizeHandles:[`se`],onLayoutChange:i.noop,onDragStart:i.noop,onDrag:i.noop,onDragStop:i.noop,onResizeStart:i.noop,onResize:i.noop,onResizeStop:i.noop,onDrop:i.noop,onDropDragOver:i.noop})})),Ad=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.findOrGenerateResponsiveLayout=i,e.getBreakpointFromWidth=n,e.getColsFromBreakpoint=r,e.sortBreakpoints=a;var t=hd();function n(e,t){let n=a(e),r=n[0];for(let i=1,a=n.length;i<a;i++){let a=n[i];t>e[a]&&(r=a)}return r}function r(e,t){if(!t[e])throw Error("ResponsiveReactGridLayout: `cols` entry for breakpoint "+e+` is missing!`);return t[e]}function i(e,n,r,i,o,s){if(e[r])return(0,t.cloneLayout)(e[r]);let c=e[i],l=a(n),u=l.slice(l.indexOf(r));for(let t=0,n=u.length;t<n;t++){let n=u[t];if(e[n]){c=e[n];break}}return c=(0,t.cloneLayout)(c||[]),(0,t.compact)((0,t.correctBounds)(c,{cols:o}),s,o)}function a(e){return Object.keys(e).sort(function(t,n){return e[t]-e[n]})}})),jd=i((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var t=l(d()),n=c(yd()),r=pd(),i=hd(),a=Ad(),o=c(kd()),s=[`breakpoint`,`breakpoints`,`cols`,`layouts`,`margin`,`containerPadding`,`onBreakpointChange`,`onLayoutChange`,`onWidthChange`];function c(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(typeof WeakMap==`function`)var n=new WeakMap,r=new WeakMap;return(l=function(e,t){if(!t&&e&&e.__esModule)return e;var i,a,o={__proto__:null,default:e};if(e===null||typeof e!=`object`&&typeof e!=`function`)return o;if(i=t?r:n){if(i.has(e))return i.get(e);i.set(e,o)}for(let t in e)t!=="default"&&{}.hasOwnProperty.call(e,t)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(a.get||a.set)?i(o,t,a):o[t]=e[t]);return o})(e,t)}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(null,arguments)}function f(e,t){if(e==null)return{};var n,r,i=p(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function p(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function m(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function h(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?m(Object(n),!0).forEach(function(t){g(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function g(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _(e){var t=v(e,`string`);return typeof t==`symbol`?t:t+``}function v(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var y=e=>Object.prototype.toString.call(e);function b(e,t){return e==null?null:Array.isArray(e)?e:e[t]}var x=class extends t.Component{constructor(){super(...arguments),g(this,`state`,this.generateInitialState()),g(this,`onLayoutChange`,e=>{this.props.onLayoutChange(e,h(h({},this.props.layouts),{},{[this.state.breakpoint]:e}))})}generateInitialState(){let{width:e,breakpoints:t,layouts:n,cols:r}=this.props,i=(0,a.getBreakpointFromWidth)(t,e),o=(0,a.getColsFromBreakpoint)(i,r),s=this.props.verticalCompact===!1?null:this.props.compactType;return{layout:(0,a.findOrGenerateResponsiveLayout)(n,t,i,i,o,s),breakpoint:i,cols:o}}static getDerivedStateFromProps(e,t){if(!(0,r.deepEqual)(e.layouts,t.layouts)){let{breakpoint:n,cols:r}=t;return{layout:(0,a.findOrGenerateResponsiveLayout)(e.layouts,e.breakpoints,n,n,r,e.compactType),layouts:e.layouts}}return null}componentDidUpdate(e){(this.props.width!=e.width||this.props.breakpoint!==e.breakpoint||!(0,r.deepEqual)(this.props.breakpoints,e.breakpoints)||!(0,r.deepEqual)(this.props.cols,e.cols))&&this.onWidthChange(e)}onWidthChange(e){let{breakpoints:t,cols:n,layouts:r,compactType:o}=this.props,s=this.props.breakpoint||(0,a.getBreakpointFromWidth)(this.props.breakpoints,this.props.width),c=this.state.breakpoint,l=(0,a.getColsFromBreakpoint)(s,n),u=h({},r);if(c!==s||e.breakpoints!==t||e.cols!==n){c in u||(u[c]=(0,i.cloneLayout)(this.state.layout));let e=(0,a.findOrGenerateResponsiveLayout)(u,t,s,c,l,o);e=(0,i.synchronizeLayoutWithChildren)(e,this.props.children,l,o,this.props.allowOverlap),u[s]=e,this.props.onBreakpointChange(s,l),this.props.onLayoutChange(e,u),this.setState({breakpoint:s,layout:e,cols:l})}let d=b(this.props.margin,s),f=b(this.props.containerPadding,s);this.props.onWidthChange(this.props.width,d,l,f)}render(){let e=this.props,{breakpoint:n,breakpoints:r,cols:i,layouts:a,margin:c,containerPadding:l,onBreakpointChange:d,onLayoutChange:p,onWidthChange:m}=e,h=f(e,s);return t.createElement(o.default,u({},h,{margin:b(c,this.state.breakpoint),containerPadding:b(l,this.state.breakpoint),onLayoutChange:this.onLayoutChange,layout:this.state.layout,cols:this.state.cols}))}};e.default=x,g(x,`propTypes`,{breakpoint:n.default.string,breakpoints:n.default.object,allowOverlap:n.default.bool,cols:n.default.object,margin:n.default.oneOfType([n.default.array,n.default.object]),containerPadding:n.default.oneOfType([n.default.array,n.default.object]),layouts(e,t){if(y(e[t])!==`[object Object]`)throw Error(`Layout property must be an object. Received: `+y(e[t]));Object.keys(e[t]).forEach(t=>{if(!(t in e.breakpoints))throw Error(`Each key in layouts must align with a key in breakpoints.`);(0,i.validateLayout)(e.layouts[t],`layouts.`+t)})},width:n.default.number.isRequired,onBreakpointChange:n.default.func,onLayoutChange:n.default.func,onWidthChange:n.default.func}),g(x,`defaultProps`,{breakpoints:{lg:1200,md:996,sm:768,xs:480,xxs:0},cols:{lg:12,md:10,sm:6,xs:4,xxs:2},containerPadding:{lg:null,md:null,sm:null,xs:null,xxs:null},layouts:{},margin:[10,10],allowOverlap:!1,onBreakpointChange:i.noop,onLayoutChange:i.noop,onWidthChange:i.noop})})),Md=r({default:()=>cf});function Nd(e,t){var n=!1,r=!1,i=0;function a(){n&&(n=!1,e()),r&&s()}function o(){Kd(a)}function s(){var e=Date.now();if(n){if(e-i<qd)return;r=!0}else n=!0,r=!1,setTimeout(o,t);i=e}return s}function Pd(e){return parseFloat(e)||0}function Fd(e){return[...arguments].slice(1).reduce(function(t,n){var r=e[`border-`+n+`-width`];return t+Pd(r)},0)}function Id(e){for(var t=[`top`,`right`,`bottom`,`left`],n={},r=0,i=t;r<i.length;r++){var a=i[r],o=e[`padding-`+a];n[a]=Pd(o)}return n}function Ld(e){var t=e.getBBox();return Hd(0,0,t.width,t.height)}function Rd(e){var t=e.clientWidth,n=e.clientHeight;if(!t&&!n)return ef;var r=$d(e).getComputedStyle(e),i=Id(r),a=i.left+i.right,o=i.top+i.bottom,s=Pd(r.width),c=Pd(r.height);if(r.boxSizing===`border-box`&&(Math.round(s+a)!==t&&(s-=Fd(r,`left`,`right`)+a),Math.round(c+o)!==n&&(c-=Fd(r,`top`,`bottom`)+o)),!zd(e)){var l=Math.round(s+a)-t,u=Math.round(c+o)-n;Math.abs(l)!==1&&(s-=l),Math.abs(u)!==1&&(c-=u)}return Hd(i.left,i.top,s,c)}function zd(e){return e===$d(e).document.documentElement}function Bd(e){return Wd?tf(e)?Ld(e):Rd(e):ef}function Vd(e){var t=e.x,n=e.y,r=e.width,i=e.height,a=Object.create((typeof DOMRectReadOnly<`u`?DOMRectReadOnly:Object).prototype);return Qd(a,{x:t,y:n,width:r,height:i,top:n,right:t+r,bottom:i+n,left:t}),a}function Hd(e,t,n,r){return{x:e,y:t,width:n,height:r}}var Ud,Wd,Gd,Kd,qd,Jd,Yd,Xd,Zd,Qd,$d,ef,tf,nf,rf,af,of,sf,cf,lf=t((()=>{Ud=(function(){if(typeof Map<`u`)return Map;function e(e,t){var n=-1;return e.some(function(e,r){return e[0]===t&&(n=r,!0)}),n}return function(){function t(){this.__entries__=[]}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),t.prototype.get=function(t){var n=e(this.__entries__,t),r=this.__entries__[n];return r&&r[1]},t.prototype.set=function(t,n){var r=e(this.__entries__,t);~r?this.__entries__[r][1]=n:this.__entries__.push([t,n])},t.prototype.delete=function(t){var n=this.__entries__,r=e(n,t);~r&&n.splice(r,1)},t.prototype.has=function(t){return!!~e(this.__entries__,t)},t.prototype.clear=function(){this.__entries__.splice(0)},t.prototype.forEach=function(e,t){t===void 0&&(t=null);for(var n=0,r=this.__entries__;n<r.length;n++){var i=r[n];e.call(t,i[1],i[0])}},t}()})(),Wd=typeof window<`u`&&typeof document<`u`&&window.document===document,Gd=(function(){return typeof global<`u`&&global.Math===Math?global:typeof self<`u`&&self.Math===Math?self:typeof window<`u`&&window.Math===Math?window:Function(`return this`)()})(),Kd=(function(){return typeof requestAnimationFrame==`function`?requestAnimationFrame.bind(Gd):function(e){return setTimeout(function(){return e(Date.now())},1e3/60)}})(),qd=2,Jd=20,Yd=[`top`,`right`,`bottom`,`left`,`width`,`height`,`size`,`weight`],Xd=typeof MutationObserver<`u`,Zd=function(){function e(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=Nd(this.refresh.bind(this),Jd)}return e.prototype.addObserver=function(e){~this.observers_.indexOf(e)||this.observers_.push(e),this.connected_||this.connect_()},e.prototype.removeObserver=function(e){var t=this.observers_,n=t.indexOf(e);~n&&t.splice(n,1),!t.length&&this.connected_&&this.disconnect_()},e.prototype.refresh=function(){this.updateObservers_()&&this.refresh()},e.prototype.updateObservers_=function(){var e=this.observers_.filter(function(e){return e.gatherActive(),e.hasActive()});return e.forEach(function(e){return e.broadcastActive()}),e.length>0},e.prototype.connect_=function(){!Wd||this.connected_||(document.addEventListener(`transitionend`,this.onTransitionEnd_),window.addEventListener(`resize`,this.refresh),Xd?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener(`DOMSubtreeModified`,this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},e.prototype.disconnect_=function(){!Wd||!this.connected_||(document.removeEventListener(`transitionend`,this.onTransitionEnd_),window.removeEventListener(`resize`,this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener(`DOMSubtreeModified`,this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},e.prototype.onTransitionEnd_=function(e){var t=e.propertyName,n=t===void 0?``:t;Yd.some(function(e){return!!~n.indexOf(e)})&&this.refresh()},e.getInstance=function(){return this.instance_||=new e,this.instance_},e.instance_=null,e}(),Qd=(function(e,t){for(var n=0,r=Object.keys(t);n<r.length;n++){var i=r[n];Object.defineProperty(e,i,{value:t[i],enumerable:!1,writable:!1,configurable:!0})}return e}),$d=(function(e){return e&&e.ownerDocument&&e.ownerDocument.defaultView||Gd}),ef=Hd(0,0,0,0),tf=(function(){return typeof SVGGraphicsElement<`u`?function(e){return e instanceof $d(e).SVGGraphicsElement}:function(e){return e instanceof $d(e).SVGElement&&typeof e.getBBox==`function`}})(),nf=function(){function e(e){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=Hd(0,0,0,0),this.target=e}return e.prototype.isActive=function(){var e=Bd(this.target);return this.contentRect_=e,e.width!==this.broadcastWidth||e.height!==this.broadcastHeight},e.prototype.broadcastRect=function(){var e=this.contentRect_;return this.broadcastWidth=e.width,this.broadcastHeight=e.height,e},e}(),rf=function(){function e(e,t){var n=Vd(t);Qd(this,{target:e,contentRect:n})}return e}(),af=function(){function e(e,t,n){if(this.activeObservations_=[],this.observations_=new Ud,typeof e!=`function`)throw TypeError(`The callback provided as parameter 1 is not a function.`);this.callback_=e,this.controller_=t,this.callbackCtx_=n}return e.prototype.observe=function(e){if(!arguments.length)throw TypeError(`1 argument required, but only 0 present.`);if(!(typeof Element>`u`||!(Element instanceof Object))){if(!(e instanceof $d(e).Element))throw TypeError(`parameter 1 is not of type "Element".`);var t=this.observations_;t.has(e)||(t.set(e,new nf(e)),this.controller_.addObserver(this),this.controller_.refresh())}},e.prototype.unobserve=function(e){if(!arguments.length)throw TypeError(`1 argument required, but only 0 present.`);if(!(typeof Element>`u`||!(Element instanceof Object))){if(!(e instanceof $d(e).Element))throw TypeError(`parameter 1 is not of type "Element".`);var t=this.observations_;t.has(e)&&(t.delete(e),t.size||this.controller_.removeObserver(this))}},e.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},e.prototype.gatherActive=function(){var e=this;this.clearActive(),this.observations_.forEach(function(t){t.isActive()&&e.activeObservations_.push(t)})},e.prototype.broadcastActive=function(){if(this.hasActive()){var e=this.callbackCtx_,t=this.activeObservations_.map(function(e){return new rf(e.target,e.broadcastRect())});this.callback_.call(e,t,e),this.clearActive()}},e.prototype.clearActive=function(){this.activeObservations_.splice(0)},e.prototype.hasActive=function(){return this.activeObservations_.length>0},e}(),of=typeof WeakMap<`u`?new WeakMap:new Ud,sf=function(){function e(t){if(!(this instanceof e))throw TypeError(`Cannot call a class as a function.`);if(!arguments.length)throw TypeError(`1 argument required, but only 0 present.`);var n=new af(t,Zd.getInstance(),this);of.set(this,n)}return e}(),[`observe`,`unobserve`,`disconnect`].forEach(function(e){sf.prototype[e]=function(){var t;return(t=of.get(this))[e].apply(t,arguments)}}),cf=(function(){return Gd.ResizeObserver===void 0?sf:Gd.ResizeObserver})()})),uf=i((t=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=_;var n=c(d()),r=s(yd()),i=s((lf(),e(Md))),a=s(yr()),o=[`measureBeforeMount`];function s(e){return e&&e.__esModule?e:{default:e}}function c(e,t){if(typeof WeakMap==`function`)var n=new WeakMap,r=new WeakMap;return(c=function(e,t){if(!t&&e&&e.__esModule)return e;var i,a,o={__proto__:null,default:e};if(e===null||typeof e!=`object`&&typeof e!=`function`)return o;if(i=t?r:n){if(i.has(e))return i.get(e);i.set(e,o)}for(let t in e)t!=="default"&&{}.hasOwnProperty.call(e,t)&&((a=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(a.get||a.set)?i(o,t,a):o[t]=e[t]);return o})(e,t)}function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l.apply(null,arguments)}function u(e,t){if(e==null)return{};var n,r,i=f(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function f(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function p(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(e){var t=h(e,`string`);return typeof t==`symbol`?t:t+``}function h(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var g=`react-grid-layout`;function _(e){var t;return t=class extends n.Component{constructor(){super(...arguments),p(this,`state`,{width:1280}),p(this,`elementRef`,n.createRef()),p(this,`mounted`,!1),p(this,`resizeObserver`,void 0)}componentDidMount(){this.mounted=!0,this.resizeObserver=new i.default(e=>{if(this.elementRef.current instanceof HTMLElement){let t=e[0].contentRect.width;this.setState({width:t})}});let e=this.elementRef.current;e instanceof HTMLElement&&this.resizeObserver.observe(e)}componentWillUnmount(){this.mounted=!1;let e=this.elementRef.current;e instanceof HTMLElement&&this.resizeObserver.unobserve(e),this.resizeObserver.disconnect()}render(){let t=this.props,{measureBeforeMount:r}=t,i=u(t,o);return r&&!this.mounted?n.createElement(`div`,{className:(0,a.default)(this.props.className,g),style:this.props.style,ref:this.elementRef}):n.createElement(e,l({innerRef:this.elementRef},i,this.state))}},p(t,`defaultProps`,{measureBeforeMount:!1}),p(t,`propTypes`,{measureBeforeMount:r.default.bool}),t}})),df=n(i(((e,t)=>{t.exports=kd().default,t.exports.utils=hd(),t.exports.calculateUtils=gd(),t.exports.Responsive=jd().default,t.exports.Responsive.utils=Ad(),t.exports.WidthProvider=uf().default}))(),1),ff=new Map;function pf(e){ff.set(e.type,e)}function mf(e){return ff.get(e)}function hf(){return[...ff.values()]}function gf(){let e,t,n=!1,r=()=>{clearTimeout(e),e=void 0,t=void 0};return{cancel:r,start(i,a,o){r(),n=!1,t={x:i,y:a},e=setTimeout(()=>{e=void 0,n=!0,o()},500)},move(e,n){t&&Math.hypot(e-t.x,n-t.y)>10&&r()},consumeClick(){let e=n;return n=!1,e},contextMenu(){let e=n;return t&&(n=!0),r(),e},reset(){r(),n=!1}}}function _f(){let[e]=(0,X.useState)(gf);return(0,X.useEffect)(()=>e.cancel,[e]),{onPointerDown:t=>{if(e.reset(),t.pointerType!==`touch`||!t.isPrimary)return;let n=t.target;if(!t.currentTarget.contains(n)||n.closest(`button, input, textarea, select, a, [contenteditable="true"], [role="dialog"]`))return;let{clientX:r,clientY:i}=t;e.start(r,i,()=>{n.dispatchEvent(new window.MouseEvent(`contextmenu`,{bubbles:!0,cancelable:!0,clientX:r,clientY:i}))})},onPointerMove:t=>e.move(t.clientX,t.clientY),onPointerUp:e.cancel,onPointerCancel:e.cancel,onPointerLeave:e.cancel,onDragStartCapture:t=>{e.cancel(),e.consumeClick()&&t.preventDefault()},onContextMenuCapture:t=>{t.isTrusted&&e.contextMenu()&&(t.preventDefault(),t.stopPropagation())},onClickCapture:t=>{e.consumeClick()&&(t.preventDefault(),t.stopPropagation())}}}function vf(e,t,n,r,i=!1){let a=e.indexOf(n);if(a<0)return new Set(r);let o=t===null?-1:e.indexOf(t),s=o<0?a:o,c=i?new Set(r):new Set;for(let t of e.slice(Math.min(s,a),Math.max(s,a)+1))c.add(t);return c}var yf=n(a(),1),bf=[];function xf(e){if(e.key!==`Escape`||e.isComposing||e.defaultPrevented)return;let t=bf[bf.length-1];t&&(e.preventDefault(),t())}function Sf(e,t=!0){let n=(0,X.useRef)(e);(0,X.useEffect)(()=>{n.current=e});let r=t&&!!e;(0,X.useEffect)(()=>{if(!r)return;let e=()=>n.current?.();return bf.push(e),bf.length===1&&window.addEventListener(`keydown`,xf),()=>{let t=bf.indexOf(e);t>=0&&bf.splice(t,1),bf.length===0&&window.removeEventListener(`keydown`,xf)}},[r])}function Cf({x:e,y:t,onClose:n,className:r,children:i}){let a=(0,X.useRef)(null),[o,s]=(0,X.useState)({x:e,y:t});return Sf(n),(0,X.useLayoutEffect)(()=>{let n=a.current;if(!n)return;let{width:r,height:i}=n.getBoundingClientRect();s({x:Math.max(8,Math.min(e,window.innerWidth-r-8)),y:Math.max(8,Math.min(t,window.innerHeight-i-8))})},[e,t]),(0,yf.createPortal)((0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-menu-scrim`,onClick:n,onContextMenu:e=>{e.preventDefault(),n()}}),(0,Z.jsx)(`div`,{ref:a,style:{left:o.x,top:o.y},className:K(`fixed z-menu max-h-viewport-modal overflow-y-auto`,r),children:i})]}),document.body)}var wf=null;function Tf(){return wf||=fetch(`https://api.iconify.design/collection?prefix=ph`).then(e=>e.json()).then(e=>[...e.uncategorized??[],...Object.values(e.categories??{}).flat()].filter(e=>e.endsWith(`-fill`)).map(e=>`ph:${e}`)).catch(()=>(wf=null,[])),wf}async function Ef(e,t=120){let n=e.trim();if(!n)return[];try{let e=await(await fetch(`https://api.iconify.design/search?query=${encodeURIComponent(n)}&limit=${t}`)).json();return Array.isArray(e.icons)?e.icons:[]}catch{return[]}}var Df=[`#ef4444`,`#f97316`,`#f59e0b`,`#eab308`,`#84cc16`,`#22c55e`,`#14b8a6`,`#06b6d4`,`#3b82f6`,`#6366f1`,`#8b5cf6`,`#a855f7`,`#ec4899`,`#f43f5e`,`#64748b`,`#78716c`],Of={home:{icon:`ph:house-fill`,color:`#3b82f6`},travel:{icon:`ph:airplane-tilt-fill`,color:`#06b6d4`},work:{icon:`ph:briefcase-fill`,color:`#64748b`},books:{icon:`ph:books-fill`,color:`#a855f7`},workouts:{icon:`ph:barbell-fill`,color:`#22c55e`},sport:{icon:`ph:barbell-fill`,color:`#22c55e`},sports:{icon:`ph:barbell-fill`,color:`#22c55e`},fitness:{icon:`ph:barbell-fill`,color:`#22c55e`},beauty:{icon:`ph:flower-lotus-fill`,color:`#ec4899`},recipes:{icon:`ph:cooking-pot-fill`,color:`#f97316`},"to watch":{icon:`ph:monitor-play-fill`,color:`#f43f5e`},"to read":{icon:`ph:book-open-text-fill`,color:`#8b5cf6`},learning:{icon:`ph:graduation-cap-fill`,color:`#6366f1`},tech:{icon:`ph:cpu-fill`,color:`#14b8a6`},music:{icon:`ph:music-notes-fill`,color:`#eab308`},finance:{icon:`ph:piggy-bank-fill`,color:`#84cc16`},shopping:{icon:`ph:shopping-cart-fill`,color:`#f59e0b`},ideas:{icon:`ph:lightbulb-filament-fill`,color:`#facc15`},data:{icon:`ph:database-fill`,color:`#14b8a6`}},kf={"workspace:home":{icon:`ph:house-fill`,color:`#3b82f6`},"workspace:data":{icon:`ph:database-fill`,color:`#14b8a6`}},Af={file:{icon:`ph:folder-fill`,color:`#64748b`},cacache:{icon:`ph:database-fill`,color:`#14b8a6`},s3:{icon:`ph:cloud-fill`,color:`#0ea5e9`},gdrive:{icon:`mdi:google-drive`,color:`#fbbc04`},http:{icon:`ph:globe-fill`,color:`#0ea5e9`},imap:{icon:`ph:envelope-fill`,color:`#a855f7`}},jf={icon:`ph:hard-drive-fill`,color:`#64748b`};function Mf(e){let t=e.config?.ui??{},n=e.address&&kf[e.address]||e.driver&&Af[e.driver]||jf;return{icon:typeof t.icon==`string`?t.icon:n.icon??jf.icon,color:typeof t.color==`string`?t.color:n.color??jf.color}}function Nf(e){let t=e.metadata?.ui??{},n=Of[String(e.label??e.name??``).trim().toLowerCase()];return{icon:typeof t.icon==`string`?t.icon:n?.icon,color:typeof t.color==`string`?t.color:e.color??n?.color}}function Pf(e){let t=Of[(e.split(`/`).filter(Boolean).pop()??``).trim().toLowerCase()];return t?{metadata:Ff(void 0,t)}:null}function Ff(e,t){let n={...e??{}},r={...n.ui??{}};return`icon`in t&&(t.icon?r.icon=t.icon:delete r.icon),`color`in t&&(t.color?r.color=t.color:delete r.color),n.ui=r,n}var If=(e,t)=>Math.floor(Math.random()*(t-e+1))+e,Lf=()=>({h:If(0,360),s:If(42,98),l:If(40,90)}),Rf=(e,t,n)=>{t/=100,n/=100;let r=(1-Math.abs(2*n-1))*t,i=r*(1-Math.abs(e/60%2-1)),a=n-r/2,o=0,s=0,c=0;0<=e&&e<60?(o=r,s=i):60<=e&&e<120?(o=i,s=r):120<=e&&e<180?(s=r,c=i):180<=e&&e<240?(s=i,c=r):240<=e&&e<300?(o=i,c=r):300<=e&&e<360&&(o=r,c=i),o=Math.round((o+a)*255),s=Math.round((s+a)*255),c=Math.round((c+a)*255);let l=e=>e.toString(16).padStart(2,`0`);return`#${l(o)}${l(s)}${l(c)}`},zf=()=>{let{h:e,s:t,l:n}=Lf();return Rf(e,t,n)},Bf=e=>{let t=e.trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(!t)return null;let n=t[1];n.length===3&&(n=n.split(``).map(e=>e+e).join(``));let r=e=>{let t=parseInt(n.slice(e*2,e*2+2),16)/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(0)+.7152*r(1)+.0722*r(2)},Vf=(e,t=.82)=>{let n=Bf(e);return n===null||n>t},Hf=e=>e&&!Vf(e)?e:void 0,Uf=e=>{if(!e)return`text-muted-foreground/70`;let t=Bf(e);return t!==null&&t>.5?`text-black/45`:`text-white/80`},Wf=e=>{let t=Bf(e);return t!==null&&t>.45?`text-black`:`text-white`},Gf=[{color:`text-data-1`,chip:`bg-data-1/15`},{color:`text-data-2`,chip:`bg-data-2/15`},{color:`text-data-3`,chip:`bg-data-3/15`},{color:`text-data-4`,chip:`bg-data-4/15`},{color:`text-data-5`,chip:`bg-data-5/15`},{color:`text-data-6`,chip:`bg-data-6/15`},{color:`text-data-7`,chip:`bg-data-7/15`},{color:`text-data-8`,chip:`bg-data-8/15`},{color:`text-data-9`,chip:`bg-data-9/15`},{color:`text-data-10`,chip:`bg-data-10/15`},{color:`text-data-11`,chip:`bg-data-11/15`},{color:`text-data-12`,chip:`bg-data-12/15`}];function Kf(e,t){return{Icon:e,...Gf[t-1]}}var qf={tab:Kf(oe,7),link:Kf(oe,7),email:Kf(Cn,3),note:Kf(xn,3),task:Kf(Tn,5),message:Kf(Me,6),identity:Kf(Ze,2),contact:Kf(Ze,2),device:Kf(me,10),application:Kf(et,11),dotfile:Kf(qt,4),document:Kf(wn,9)},Jf=[{test:/^image\//,spec:Kf(y,5)},{test:/^video\//,spec:Kf(tn,11)},{test:/^audio\//,spec:Kf(R,10)},{test:/pdf$/,spec:Kf(wn,1)},{test:/zip|tar|gzip|7z|rar|compressed/,spec:Kf(Nt,12)},{test:/json|javascript|typescript|xml|html|css|x-sh|python/,spec:Kf(Yn,6)},{test:/^text\//,spec:Kf(wn,12)}],Yf=Kf(bt,6),Xf=Kf(bt,9);function Zf(e){let t=(e.schema||``).split(`/`).pop()||``;if(t===`file`){let t=String(e.metadata?.contentType||``).toLowerCase();return Jf.find(({test:e})=>e.test(t))?.spec||Yf}return qf[t]||Xf}var Qf={3.5:`h-3.5 w-3.5`,4:`h-4 w-4`,5:`h-5 w-5`,10:`h-10 w-10`};function $f(e){let t=[],n=typeof e?.favIconUrl==`string`?e.favIconUrl:``;/^https?:\/\//i.test(n)&&t.push(n);let r=typeof e?.url==`string`?e.url:``;try{let e=new URL(r).origin;if(/^https?:/i.test(e)){let n=`${e}/favicon.ico`;t.includes(n)||t.push(n)}}catch{}return t}function ep({document:e,size:t=4,chip:n=!1,className:r}){let i=Zf(e),a=e.schema===`data/schema/tab`?$f(e.data):[],[o,s]=(0,X.useState)(0),c=a[o]??null,l=c?(0,Z.jsx)(`img`,{src:c,alt:``,loading:`lazy`,onError:()=>s(e=>e+1),className:K(Qf[t],`rounded-xs object-contain`,!n&&`shrink-0`,!n&&r)}):(0,Z.jsx)(i.Icon,{className:K(Qf[t],i.color,!n&&`shrink-0`,!n&&r)});return n?(0,Z.jsx)(`span`,{className:K(`inline-flex shrink-0 items-center justify-center rounded-md`,t>=10?`p-3`:`p-1`,i.chip,r),children:l}):l}var tp={context:(0,Z.jsx)(We,{className:`h-3.5 w-3.5`}),directory:(0,Z.jsx)(Mn,{className:`h-3.5 w-3.5`}),backends:(0,Z.jsx)(hr,{className:`h-3.5 w-3.5`}),relations:(0,Z.jsx)(_n,{className:`h-3.5 w-3.5`})},np={context:`Context tree`,directory:`Directory tree`,backends:`Backends tree`,relations:`Relations`};function rp(e,t){return e===`/`?`/${t}`:`${e}/${t}`}function ip(e,t){let n=(0,X.useRef)(null),r=(0,X.useRef)(!1),i=()=>{n.current&&=(clearTimeout(n.current),null)},a=e=>()=>{if(r.current){r.current=!1;return}e()};return t?{guardClick:a,handlers:{onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),t({clientX:n.clientX,clientY:n.clientY,path:e})},onPointerDown:a=>{if(a.pointerType!==`touch`)return;let{clientX:o,clientY:s}=a;i(),n.current=setTimeout(()=>{r.current=!0,t({clientX:o,clientY:s,path:e})},500)},onPointerUp:i,onPointerLeave:i,onPointerMove:i}}:{handlers:{},guardClick:a}}function ap(e,t,n){let r=rp(t,e.name);return r.toLowerCase().includes(n)||(e.label||``).toLowerCase().includes(n)?!0:e.children?.some(e=>ap(e,r,n))??!1}var op=200;function sp({onConfirm:e,onCancel:t,busy:n}){let[r,i]=(0,X.useState)(``);return(0,Z.jsxs)(`div`,{className:`flex min-h-11 items-center gap-2 rounded-md bg-card px-3 py-2.5 text-sm shadow-elevation-1`,children:[(0,Z.jsx)(ir,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Z.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),onKeyDown:n=>{n.key===`Enter`&&r.trim()&&e(r.trim()),n.key===`Escape`&&t()},onBlur:()=>{n||t()},placeholder:`New folder name…`,autoFocus:!0,disabled:n,className:`w-full flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground`}),n&&(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:`Creating…`})]})}function cp({node:e,parentPath:t,query:n,selected:r,onToggle:i,onActivate:a,onRowMenu:o,createParent:s,onCreateConfirm:l,onCreateCancel:u,creating:d}){let f=rp(t,e.name),p=!!e.children?.length,[m,h]=(0,X.useState)(!1),{handlers:g,guardClick:_}=ip(f,o);if(n&&!ap(e,t,n))return null;let v=s===f,y=m||n.length>0||v,b=r.has(f),x=e.type===`canvas`,S=Nf(e);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:K(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,b?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:_(()=>i(f)),onDoubleClick:a?()=>a(f):void 0,title:f,...g,children:[(0,Z.jsx)(`button`,{type:`button`,className:K(`shrink-0 text-muted-foreground hover:text-foreground`,!p&&`invisible`),onClick:e=>{e.stopPropagation(),h(e=>!e)},children:y?(0,Z.jsx)(Ge,{className:`w-4 h-4`}):(0,Z.jsx)(Ye,{className:`w-4 h-4`})}),(0,Z.jsx)(c,{icon:S.icon||(x?`ph:squares-four-fill`:`ph:folder-fill`),width:16,height:16,color:Hf(S.color),className:K(`shrink-0`,!Hf(S.color)&&(x?`text-primary`:`text-muted-foreground`))}),(0,Z.jsx)(`span`,{className:`flex-1 truncate font-medium`,title:e.description||void 0,children:e.label||e.name})]}),y&&p||v?(0,Z.jsxs)(`div`,{className:`ml-[22px] mt-1.5 space-y-1.5`,children:[v&&l&&u&&(0,Z.jsx)(sp,{busy:d,onConfirm:e=>{h(!0),l(f,e)},onCancel:u}),y&&e.children?.map(e=>(0,Z.jsx)(cp,{node:e,parentPath:f,query:n,selected:r,onToggle:i,onActivate:a,onRowMenu:o,createParent:s,onCreateConfirm:l,onCreateCancel:u,creating:d},e.id||e.name))]}):null]})}function lp({workspaces:e,loading:t,onPick:n}){return t&&e.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):e.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`No workspaces found`}):(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.map(e=>{let t=Hf(e.color);return(0,Z.jsxs)(`div`,{onClick:()=>n(e.name),className:`group relative flex cursor-pointer items-center gap-2 rounded-md bg-card px-3 py-2.5 shadow-elevation-1 transition-all hover:bg-accent/50 hover:shadow`,style:{borderRight:`6px solid ${t||`transparent`}`,borderRadius:t?`6px 0 0 6px`:void 0},children:[(0,Z.jsx)(c,{icon:e.icon||`ph:stack-fill`,width:18,height:18,color:t,className:K(`shrink-0`,!t&&`text-muted-foreground`)}),(0,Z.jsx)(`span`,{className:`flex-1 truncate text-sm font-medium`,children:e.label||e.name}),(0,Z.jsx)(Ye,{className:`h-4 w-4 shrink-0 text-muted-foreground`})]},e.id||e.name)})})}function up({workspaceName:e,treeTab:t,onTreeTabChange:n,selectedDocIds:r,onToggleDoc:i,onNavigate:a,excludeDocumentIds:o}){let[s,c]=(0,X.useState)(`folder`),[l,u]=(0,X.useState)(``),d=l.trim().toLowerCase(),[f,p]=(0,X.useState)(`/`),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)([]),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(``),[E,D]=(0,X.useState)(t),O=n?t:E,k=e=>{p(`/`),c(`folder`),C(``),T(``),a?.(`/`),n?n(e):D(e)},[A,j]=(0,X.useState)(O);O!==A&&(j(O),p(`/`),c(`folder`)),(0,X.useEffect)(()=>{let e=setTimeout(()=>T(S.trim()),300);return()=>clearTimeout(e)},[S]),(0,X.useEffect)(()=>{let t=!1;async function n(){_(!0);try{let n=await vi(e,O);t||h(n)}catch{t||h(null)}finally{t||_(!1)}}return n(),()=>{t=!0}},[e,O]),(0,X.useEffect)(()=>{if(s!==`documents`)return;let t=!1,n=O===`directory`?`directory`:Na,r=O===`context`?`context`:`directory`;async function i(){x(!0);try{let i=w?await Ki(e,f,[],{treeName:n,treeType:r,q:w,limit:op}):await Si(e,f,n,{limit:op});t||y(i.payload||[])}catch{t||y([])}finally{t||x(!1)}}return i(),()=>{t=!0}},[e,O,f,s,w]);let M=e=>`${O===`directory`?`dir`:`ctx`}://${e.replace(/^\/+/,``)}`,N=e=>{p(e),a?.(e)},P=o?.size?v.filter(e=>!o.has(e.id)):v;return s===`folder`?(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[!n&&(0,Z.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border border-input p-0.5`,children:[`context`,`directory`].map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>k(e),className:K(`flex flex-1 items-center justify-center gap-1.5 rounded px-2 py-1 text-xs transition-colors`,O===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:bg-muted hover:text-foreground`),title:`Browse the ${np[e].toLowerCase()}`,children:[tp[e],(0,Z.jsx)(`span`,{className:`font-mono`,children:e===`directory`?`dir://`:`ctx://`})]},e))}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Step 1 of 2 · Pick a folder`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>c(`documents`),className:`inline-flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground transition-opacity hover:opacity-90`,children:[`Next `,(0,Z.jsx)(Ye,{className:`h-3.5 w-3.5`})]})]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(pr,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(`input`,{type:`text`,placeholder:`Filter folders…`,value:l,onChange:e=>u(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-3 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:g?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:K(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,f===`/`?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:()=>N(`/`),onDoubleClick:()=>{N(`/`),c(`documents`)},title:`/`,children:[(0,Z.jsx)(Ge,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,Z.jsx)(`div`,{className:`ml-[22px] space-y-1.5`,children:m?.children?.length?m.children.map(e=>(0,Z.jsx)(cp,{node:e,parentPath:`/`,query:d,selected:new Set([f]),onToggle:N,onActivate:e=>{N(e),c(`documents`)}},e.id||e.name)):(0,Z.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})})]})})]}):(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-muted/30 px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>c(`folder`),className:`inline-flex min-w-0 items-center gap-1 rounded-md px-1.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:`Back to folders`,children:[(0,Z.jsx)(Ye,{className:`h-3.5 w-3.5 shrink-0 rotate-180`}),(0,Z.jsx)(`span`,{className:`truncate font-mono`,children:M(f)})]}),(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-muted-foreground`,children:`Step 2 of 2 · Pick a document`})]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(pr,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(`input`,{type:`text`,placeholder:`Search documents in this folder…`,value:S,onChange:e=>C(e.target.value),className:`w-full rounded-md border border-input bg-background py-1.5 pl-8 pr-7 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`}),S&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>C(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":`Clear document search`,children:(0,Z.jsx)(G,{className:`h-3.5 w-3.5`})})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-3`,children:b?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading documents…`}):P.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:w?`No documents match “${w}” here.`:`No documents in this folder.`}):P.map(e=>{let t=bo(e),n=r.has(e.id);return(0,Z.jsxs)(`div`,{onClick:()=>i(e.id),className:K(`flex min-h-9 items-center gap-2 rounded-md px-3 py-1.5 cursor-pointer transition-all select-none text-sm`,n?`bg-primary/[0.08] hover:bg-primary/[0.12]`:`hover:bg-primary/[0.04]`),children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>i(e.id),className:`shrink-0`,onClick:e=>e.stopPropagation()}),(0,Z.jsx)(ep,{document:e,size:3.5}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:t.title})]},e.id)})})]})}function dp({onClose:e,onConfirm:t,documentCount:n,fixedWorkspaceName:r,excludeWorkspace:i,multiple:a=!0,saving:o=!1,savingContent:s,sizeClassName:c,tabs:l=[`context`,`directory`],title:u,confirmLabel:d,onConfirmRelation:f,relationWorkspaceName:p,relationPredicates:m,relationExcludeIds:h}){let[g,_]=(0,X.useState)(r?`tree`:`workspace`);Sf(e,!o);let[v,y]=(0,X.useState)([]),[b,x]=(0,X.useState)(!r),[S,C]=(0,X.useState)(r??null),[w,T]=(0,X.useState)(l.includes(`context`)||l.includes(`directory`)?`pins`:l[0]??`context`),E=m?.length?m:[...Da],[D,O]=(0,X.useState)(E[0]??`references`),[k,A]=(0,X.useState)(`out`),[j,M]=(0,X.useState)(new Set),[N,P]=(0,X.useState)(null),[F,I]=(0,X.useState)(`context`),[ee,te]=(0,X.useState)(!1),re=w===`pins`?F:w;(0,X.useEffect)(()=>{if(!S)return;let e=!1;return qa(S).then(t=>{e||P(t)}).catch(()=>{e||te(!0)}),()=>{e=!0}},[S]);let ie=w===`relations`,[L,R]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(!1),[se,ce]=(0,X.useState)(new Set),[z,le]=(0,X.useState)(``),ue=z.trim().toLowerCase(),{showErrorToast:de}=to(),[fe,pe]=(0,X.useState)(null),[me,he]=(0,X.useState)(null),[ge,_e]=(0,X.useState)(!1),ve=ip(`/`,e=>pe(e)),ye=w!==`pins`&&w!==`backends`&&w!==`relations`,B=async(e,t)=>{let n=t.trim().replace(/^\/+|\/+$/g,``);if(!(!n||!S||ge||!ye)){_e(!0);try{let t=`${e===`/`?``:e}/${n}`;await Vi(S,t,!0,w===`directory`?`directory`:Na),fa(S);let r=await vi(S,w);R(r),ce(e=>a?new Set([...e,t]):new Set([t])),he(null)}catch(e){de(e instanceof Error?e.message:`Failed to create folder`)}finally{_e(!1)}}},[be,V]=(0,X.useState)(r);r!==be&&(V(r),r||x(!0)),(0,X.useEffect)(()=>{r||Pr().then(e=>y(e.filter(e=>e.id!==i&&e.name!==i))).catch(()=>y([])).finally(()=>x(!1))},[r,i]),(0,X.useEffect)(()=>{if(!S||w===`relations`||w===`pins`)return;let e=!1;async function t(){oe(!0);try{let t=await vi(S,w);e||R(t)}catch{e||R(null)}finally{e||oe(!1)}}return t(),()=>{e=!0}},[S,w]);let xe=e=>{e!==S&&(P(null),te(!1)),T(l.includes(`context`)||l.includes(`directory`)?`pins`:l[0]??`context`),C(e),ce(new Set),M(new Set),_(`tree`)},H=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Se=e=>{if(!a){ce(new Set([e]));return}ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ce=ie?j.size>0&&!!f:se.size>0,U=async()=>{if(!(!S||o||!Ce)){if(ie){await f?.({predicate:D,direction:k,targetIds:Array.from(j)},{workspaceName:p??S});return}await t(Array.from(se),{workspaceName:S,treeName:re===`context`?Na:re,treeType:re===`context`?`context`:`directory`})}},W=n??1;return o&&s?(0,Z.jsx)(`div`,{className:K(`flex flex-col overflow-hidden rounded-2xl border bg-card shadow-elevation-4`,c||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:s}):(0,Z.jsxs)(`div`,{className:K(`flex flex-col overflow-hidden rounded-2xl border bg-card shadow-elevation-4`,c||`h-viewport-card max-h-full w-[min(380px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,Z.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Z.jsx)(Gt,{className:`h-4 w-4`}),u??(g===`workspace`?`Link to…`:ie?`Relate ${W} document${W===1?``:`s`} to…`:`Link ${W} document${W===1?``:`s`} to…`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:e,disabled:o,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Z.jsx)(G,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,Z.jsxs)(`div`,{className:`grid h-full w-[200%] grid-cols-2 transition-transform duration-200`,style:{transform:g===`workspace`?`translateX(0)`:`translateX(-50%)`},children:[(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-col overflow-y-auto p-2`,children:(0,Z.jsx)(lp,{workspaces:v,loading:b,onPick:xe})}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 overflow-x-auto border-b px-2 pt-2`,children:[!r&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>_(`workspace`),className:`mr-1 rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground touch-target`,"aria-label":`Back to workspaces`,children:(0,Z.jsx)(Ye,{className:`h-4 w-4 rotate-180`})}),(l.includes(`context`)||l.includes(`directory`))&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{T(`pins`),ce(new Set),he(null)},className:K(`flex shrink-0 items-center gap-1.5 border-b-2 px-3 py-2 text-xs`,w===`pins`?`border-primary`:`border-transparent text-muted-foreground`),children:[(0,Z.jsx)(ne,{className:`h-3.5 w-3.5`}),`Pins`]}),l.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{T(e),ce(new Set),he(null)},className:K(`flex shrink-0 items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors`,w===e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[tp[e],np[e]]},e))]}),!ie&&(0,Z.jsx)(`div`,{className:`shrink-0 border-b p-2`,children:(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(pr,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(`input`,{type:`text`,placeholder:`Search paths…`,value:z,onChange:e=>le(e.target.value),className:`w-full rounded-md border border-input bg-background py-2 pl-9 pr-3 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring`})]})}),ie&&(0,Z.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b bg-primary/[0.04] px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{htmlFor:`relation-predicate`,className:`shrink-0 text-xs text-muted-foreground`,children:`Predicate`}),(0,Z.jsx)(`select`,{id:`relation-predicate`,value:D,onChange:e=>O(e.target.value),className:`min-w-0 flex-1 rounded-md border border-input bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-2 focus:ring-ring`,children:E.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:[{dir:`out`,label:`This → picked`,hint:`the ${W===1?`document`:`documents`} you started from ${D} the picked one(s)`},{dir:`in`,label:`Picked → this`,hint:`the picked document(s) ${D} the ${W===1?`one`:`ones`} you started from`}].map(({dir:e,label:t,hint:n})=>(0,Z.jsx)(`button`,{type:`button`,title:n,onClick:()=>A(e),className:K(`flex-1 rounded-md border px-2 py-1.5 text-xs transition-colors`,k===e?`border-primary bg-primary text-primary-foreground`:`border-input hover:bg-accent`),children:t},e))})]}),!ie&&a&&se.size>0&&(0,Z.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1.5 border-b bg-primary/[0.04] px-3 py-2`,children:Array.from(se).map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1 rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground`,children:[(0,Z.jsx)(`span`,{className:`truncate`,title:e,children:e}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Se(e),className:`shrink-0 rounded-full hover:bg-primary-foreground/20`,"aria-label":`Remove ${e}`,children:(0,Z.jsx)(G,{className:`h-3 w-3`})})]},e))}),ie&&(p??S)&&(0,Z.jsx)(up,{workspaceName:p??S,treeTab:`context`,selectedDocIds:j,onToggleDoc:H,excludeDocumentIds:h}),w===`pins`&&(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3 space-y-2`,children:[!N&&!ee&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading pins…`}),ee&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:`Could not load pins. You can still browse the trees.`}),!ee&&N?.length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No pinned paths yet. Choose a path from a tree.`}),N?.filter(e=>e.resolvable!==!1&&l.includes(e.tree===`context`?`context`:e.tree)&&`${e.label??e.name??``} ${e.path}`.toLowerCase().includes(ue)).map(e=>{let t=e.tree===`context`?`context`:e.tree;return(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":F===t&&se.has(e.path),className:K(`w-full rounded-md border p-3 text-left text-sm hover:bg-muted`,F===t&&se.has(e.path)&&`border-primary bg-primary/10`),onClick:()=>{F===t?Se(e.path):(I(t),ce(new Set([e.path])))},children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ne,{className:`h-3.5 w-3.5`}),e.label||e.name||e.path]}),(0,Z.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[t,` · `,e.path]})]},e.id)})]}),(0,Z.jsx)(`div`,{className:K(`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,(ie||w===`pins`)&&`hidden`),children:ae?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading…`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:K(`group relative flex min-h-11 items-center gap-2 rounded-md px-3 py-2.5 cursor-pointer transition-all select-none text-sm shadow-elevation-1 hover:shadow`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,se.has(`/`)?`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),onClick:ve.guardClick(()=>Se(`/`)),title:`/`,...ye?ve.handlers:{},children:[(0,Z.jsx)(Ge,{className:`w-4 h-4 shrink-0 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`flex-1 truncate font-medium`,children:`/`})]}),(0,Z.jsxs)(`div`,{className:`ml-[22px] space-y-1.5`,children:[me===`/`&&(0,Z.jsx)(sp,{busy:ge,onConfirm:e=>B(`/`,e),onCancel:()=>he(null)}),L?.children?.length?L.children.map(e=>(0,Z.jsx)(cp,{node:e,parentPath:`/`,query:ue,selected:se,onToggle:Se,onRowMenu:ye?pe:void 0,createParent:me,onCreateConfirm:B,onCreateCancel:()=>he(null),creating:ge},e.id||e.name)):me===`/`?null:(0,Z.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`Empty tree`})]})]})})]})]})}),g===`tree`&&(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-t px-4 py-3`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ie?`${j.size} document${j.size===1?``:`s`} selected`:`${se.size} path${se.size===1?``:`s`} selected`}),(0,Z.jsx)(J,{size:`sm`,onClick:U,disabled:!Ce||o,children:o?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ud,{className:`mr-1.5 h-3.5 w-3.5`}),ie?`Relating…`:`Linking…`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Gt,{className:`mr-1 h-3.5 w-3.5`}),ie?`Relate`:d??`Link`]})})]}),fe&&(0,Z.jsx)(Cf,{x:fe.clientX,y:fe.clientY,onClose:()=>pe(null),className:`min-w-[11rem] rounded-md border bg-popover p-1 shadow-elevation-3`,children:(0,Z.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-3 py-1.5 text-left text-xs hover:bg-accent`,onClick:()=>{he(fe.path),pe(null)},children:[(0,Z.jsx)(ut,{className:`h-3 w-3`}),`New folder in `,fe.path]})})]})}var fp=`h-full w-[380px] max-w-[90vw] max-md:w-full`;function pp({onClose:e,children:t}){return(0,yf.createPortal)((0,Z.jsx)(`div`,{className:`fixed inset-0 z-picker flex items-stretch justify-end bg-scrim animate-fade-in`,onClick:e,children:(0,Z.jsx)(`div`,{className:`h-full p-2 max-md:w-full max-md:p-1`,onClick:e=>e.stopPropagation(),children:t})}),window.document.body)}function mp(e){let t=2166136261;for(let e of localStorage.getItem(`authToken`)||``)t=Math.imul(t^e.charCodeAt(0),16777619);return`canvas:workspace-copy:${t>>>0}:${e}`}function hp({workspaceId:e,ids:t,onClose:n}){let[r]=(0,X.useState)(()=>{try{return mp(e)}catch{return``}}),[i,a]=(0,X.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(r)||`null`);return e&&Array.isArray(e.ids)&&e.target&&e.index<e.ids.length?e:null}catch{return null}}),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(``),u=(0,X.useRef)(!1),d=(0,X.useRef)(!1);(0,X.useEffect)(()=>(u.current=!1,()=>{u.current=!0}),[]);let f=e=>{try{e.index>=e.ids.length?localStorage.removeItem(r):localStorage.setItem(r,JSON.stringify(e))}catch{}u.current||a(e)},p=async t=>{if(d.current)return;d.current=!0,s(!0),l(``);let n=t;f(n);try{for(;n.index<n.ids.length&&!u.current;){if(!navigator.onLine)throw Error(`Offline. Your copy is saved; resume when connected.`);await Sa(e,n.ids[n.index],{destination:n.target.workspaceName,context:n.paths,treeType:n.target.treeType,treeNameOrTreeId:n.target.treeName,operationId:`${n.id}:${n.index}`}),n={...n,index:n.index+1},f(n)}window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`))}catch(e){u.current||l(`Document ${n.ids[n.index]}: ${e instanceof Error?e.message:`Copy failed`}. Resume to retry.`)}finally{d.current=!1,u.current||s(!1)}},m=()=>{u.current=!0,n()},h=i!=null&&i.index>=i.ids.length;return(0,Z.jsx)(pp,{onClose:m,children:i?(0,Z.jsxs)(`section`,{role:`dialog`,"aria-label":`Copy to workspace`,className:`${fp} flex flex-col rounded-2xl border bg-card p-4 shadow-elevation-4`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Copy to workspace`}),(0,Z.jsxs)(`p`,{className:`mt-3 break-words text-sm`,children:[i.target.workspaceName,`: `,i.paths.join(`, `)]}),(0,Z.jsxs)(`p`,{role:`status`,className:`mt-3 text-sm`,children:[i.index,` of `,i.ids.length,` copied`,h?`.`:o?`…`:` — paused.`]}),c&&(0,Z.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-destructive`,children:c}),(0,Z.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Files go to workspace:data. Destination rules handle storage placement. Relationships and sharing permissions are not copied. Source documents stay unchanged.`}),!h&&(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Closing lets the current item finish and pauses the rest. Reopen Copy to workspace to resume, including after reconnecting.`}),(0,Z.jsxs)(`div`,{className:`mt-auto flex flex-wrap justify-end gap-2 pt-4`,children:[!h&&!o&&(0,Z.jsx)(J,{variant:`ghost`,onClick:()=>{try{localStorage.removeItem(r)}catch{}a(null),l(``)},children:`Discard remaining`}),!h&&!o&&(0,Z.jsx)(J,{onClick:()=>void p(i),children:`Resume copy`}),(0,Z.jsx)(J,{variant:h?`default`:`outline`,onClick:m,children:h?`Done`:o?`Pause & close`:`Close`})]})]}):(0,Z.jsx)(dp,{title:`Copy to workspace…`,confirmLabel:`Copy documents`,excludeWorkspace:e,documentCount:t.length,sizeClassName:fp,onClose:m,onConfirm:(e,n)=>p({ids:t,target:n,paths:e,index:0,id:crypto.randomUUID()})})})}function gp({tags:e,onChange:t,placeholder:n=`Add tag, press Enter`,suggestions:r=[]}){let[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(!1),c=i.trim().toLowerCase(),l=(c?r.filter(t=>t.toLowerCase().includes(c)&&!e.includes(t)):o?r.filter(t=>!e.includes(t)):[]).slice(0,8),u=()=>{let n=i.trim();n&&!e.includes(n)&&t([...e,n]),a(``)};return(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 rounded-md border border-input bg-transparent px-2 py-1.5 focus-within:ring-1 focus-within:ring-ring`,children:[e.map(n=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5 text-xs`,children:[n,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>t(e.filter(e=>e!==n)),className:`text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${n}`,children:(0,Z.jsx)(G,{className:`h-3 w-3`})})]},n)),(0,Z.jsxs)(`div`,{className:`relative flex-1 min-w-[8ch]`,children:[(0,Z.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),onKeyDown:n=>{n.key===`Enter`||n.key===`,`?(n.preventDefault(),u()):n.key===`Backspace`&&!i&&e.length&&t(e.slice(0,-1))},onFocus:()=>s(!0),onBlur:()=>{setTimeout(u,150),s(!1)},placeholder:e.length?``:n,className:`w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground`}),l.length>0&&(0,Z.jsx)(`div`,{className:`absolute left-0 top-full z-50 mt-1 max-h-48 w-56 overflow-auto rounded-md border bg-popover p-1 text-sm shadow-elevation-2`,children:l.map(n=>(0,Z.jsx)(`button`,{type:`button`,onMouseDown:r=>{r.preventDefault(),e.includes(n)||t([...e,n]),a(``)},className:`block w-full rounded px-2 py-1 text-left hover:bg-accent`,children:n},n))})]})]})}function _p(e){let t=new Set;for(let n of e){let e=n.trim();e&&t.add(`tag/${e}`)}return Array.from(t)}function vp(e){return(e||[]).filter(e=>e.startsWith(`tag/`)).map(e=>e.slice(4))}function yp(e,t,n){return{...t.length?{features:[...new Set([...e.features??e.metadata?.features??[],..._p(e.data?.tags??[]),..._p(t)])]}:{},...n?{geo:n}:{}}}function bp(e,t,n,r){return{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,metadata:yp(e,t,n),...r===void 0?{}:{comment:r.trim()}}}var xp=n(Mo(),1),Sp=`#8b5cf6`,Cp=`https://nominatim.openstreetmap.org`,wp=700,Tp=e=>Math.round(e*1e6)/1e6;function Ep(){let e=`<div style="display:flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:9999px 9999px 9999px 2px;transform:rotate(-45deg);background:${Sp};border:2px solid #fff;box-shadow:0 1px 4px rgba(0,0,0,.45)"><div style="width:8px;height:8px;border-radius:9999px;background:#fff"></div></div>`;return xp.default.divIcon({html:e,className:`canvas-map-pick`,iconSize:[28,28],iconAnchor:[14,28]})}function Dp({initial:e,onPick:t,onClose:n}){let r=(0,X.useRef)(null),i=(0,X.useRef)(null),a=(0,X.useRef)(null),o=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>o.current?.abort(),[]);let[s,c]=(0,X.useState)(e?{lat:e.lat,lon:e.lon}:null),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)([]),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=requestAnimationFrame(()=>S(!0));return()=>cancelAnimationFrame(e)},[]),Sf(n);let C=(0,X.useCallback)((e,t,n)=>{let r=i.current;if(!r)return;let o=xp.default.latLng(e,t);a.current?a.current.setLatLng(o):(a.current=xp.default.marker(o,{icon:Ep(),draggable:!0,autoPan:!0}).addTo(r),a.current.on(`dragend`,()=>{let e=a.current.getLatLng();c({lat:Tp(e.lat),lon:Tp(e.lng)})})),c({lat:Tp(e),lon:Tp(t),...n?{label:n}:{}})},[]);(0,X.useEffect)(()=>{let t=r.current;if(!t||i.current)return;let n=xp.default.map(t,{center:e?[e.lat,e.lon]:[20,0],zoom:e?13:2,worldCopyJump:!0,zoomControl:!0});xp.default.tileLayer(`https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png`,{attribution:`© OpenStreetMap contributors`,maxZoom:19}).addTo(n),i.current=n,e&&C(e.lat,e.lon),n.on(`click`,e=>C(e.latlng.lat,e.latlng.lng));let o=new ResizeObserver(()=>n.invalidateSize());o.observe(t);let s=setTimeout(()=>n.invalidateSize(),260);return()=>{clearTimeout(s),o.disconnect(),n.remove(),i.current=null,a.current=null}},[]),(0,X.useEffect)(()=>{if(!s||s.label)return;let{lat:e,lon:t}=s,n=new AbortController,r=setTimeout(()=>{v(!0),fetch(`${Cp}/reverse?format=jsonv2&zoom=16&lat=${e}&lon=${t}`,{signal:n.signal,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(n=>{let r=n?.display_name;typeof r==`string`&&r&&c(n=>n&&n.lat===e&&n.lon===t?{...n,label:r}:n)}).catch(()=>{}).finally(()=>v(!1))},wp);return()=>{clearTimeout(r),n.abort()}},[s]);let w=(0,X.useCallback)(async()=>{let e=l.trim();if(e.length<2)return;o.current?.abort();let t=new AbortController;o.current=t;let n=!1,r=window.setTimeout(()=>{n=!0,t.abort()},12e3);m(!0),f([]),g(null);try{let n=await fetch(`${Cp}/search?format=jsonv2&limit=6&q=${encodeURIComponent(e)}`,{signal:t.signal,headers:{Accept:`application/json`}});if(n.status===429)throw Error(`Place search is busy. Wait a moment and try again, or click the map`);if(!n.ok)throw Error(`Place search is unavailable (${n.status}). Try again, or click the map`);let r=await n.json();if(!Array.isArray(r))throw Error(`Place search returned an invalid response. Try again, or click the map`);if(t.signal.aborted||o.current!==t)return;f(r),r.length||g(`No match. Try a different spelling, or just click the map`)}catch(e){if(o.current!==t||t.signal.aborted&&!n)return;g(n?`Place search timed out. Try again, or click the map`:e instanceof TypeError?`Could not reach place search. Check your connection, or click the map`:e instanceof Error?e.message:`Search is unavailable right now. Click the map to place a pin`)}finally{window.clearTimeout(r),o.current===t&&(!t.signal.aborted||n)&&m(!1)}},[l]),T=(0,X.useCallback)(()=>{if(!navigator.geolocation){g(`This browser has no geolocation`);return}b(!0),g(null),navigator.geolocation.getCurrentPosition(e=>{b(!1),i.current?.setView([e.coords.latitude,e.coords.longitude],16),C(e.coords.latitude,e.coords.longitude)},()=>{b(!1),g(`Could not read your location. Search or click the map instead`)},{enableHighAccuracy:!0,timeout:1e4,maximumAge:6e4})},[C]),E=(0,X.useCallback)(e=>{let t=i.current,n=Number(e.lat),r=Number(e.lon);if(!t||!Number.isFinite(n)||!Number.isFinite(r))return;let a=e.boundingbox?.map(Number);a&&a.length===4&&a.every(Number.isFinite)?t.fitBounds(xp.default.latLngBounds([a[0],a[2]],[a[1],a[3]]),{maxZoom:16}):t.setView([n,r],15),C(n,r,e.display_name),f([])},[C]);return(0,yf.createPortal)((0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:K(`fixed inset-0 z-[60] bg-black/40 transition-opacity duration-200`,x?`opacity-100`:`opacity-0`),onClick:n}),(0,Z.jsxs)(`div`,{role:`dialog`,"aria-label":`Pick a location on the map`,className:K(`fixed inset-y-0 right-0 z-[61] flex w-[min(560px,100vw)] flex-col bg-background shadow-elevation-4 transition-transform duration-200 ease-out`,x?`translate-x-0`:`translate-x-full`),children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Z.jsx)(yt,{className:`h-4 w-4 text-info`}),`Custom geotag`]}),(0,Z.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close map`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Z.jsx)(G,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`relative z-10 shrink-0 border-b px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(pr,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(`input`,{value:l,autoFocus:!0,onChange:e=>{o.current?.abort(),o.current=null,m(!1),f([]),u(e.target.value),g(null)},"aria-label":`Search for a place or address`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),w())},placeholder:`Search a place, e.g. Slavkovský štít`,spellCheck:!1,className:`h-8 w-full rounded-md border border-input bg-transparent pl-7 pr-2 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring`})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:T,disabled:y,title:`Use my current location`,"aria-label":`Use my current location`,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50`,children:y?(0,Z.jsx)(Mt,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Jn,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(`button`,{type:`button`,onClick:w,disabled:p||l.trim().length<2,className:`inline-flex h-8 items-center gap-1.5 rounded-md bg-primary px-3 text-xs text-primary-foreground disabled:opacity-50`,children:[p?(0,Z.jsx)(Mt,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(pr,{className:`h-3.5 w-3.5`}),`Search`]})]}),h&&(0,Z.jsx)(`p`,{role:`status`,className:`mt-1 text-xs text-warning`,children:h}),d.length>0&&(0,Z.jsx)(`div`,{className:`absolute inset-x-3 top-full z-10 mt-1 max-h-64 overflow-y-auto rounded-md border bg-popover shadow-elevation-4`,children:d.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>E(e),className:`block w-full border-b border-border/60 px-3 py-2 text-left text-xs last:border-0 hover:bg-muted`,children:e.display_name},`${e.lat},${e.lon},${e.display_name}`))})]}),(0,Z.jsxs)(`div`,{className:`relative isolate z-0 min-h-0 flex-1`,children:[(0,Z.jsx)(`div`,{ref:r,className:`h-full w-full`}),!s&&(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-3 z-[1000] flex justify-center`,children:(0,Z.jsx)(`span`,{className:`rounded-full bg-background/90 px-3 py-1 text-xs text-muted-foreground shadow-elevation-2`,children:`Click the map to drop a pin, or drag it to fine-tune`})})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t px-3 py-2`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 text-xs`,children:s?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 tabular-nums text-foreground`,children:[(0,Z.jsx)(cr,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),s.lat.toFixed(5),`, `,s.lon.toFixed(5),_&&(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin text-muted-foreground`})]}),s.label&&(0,Z.jsx)(`div`,{className:`truncate text-muted-foreground`,children:s.label})]}):(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`No point selected`})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-border px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Cancel`}),(0,Z.jsxs)(`button`,{type:`button`,disabled:!s,onClick:()=>{s&&(t(s),n())},className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`,children:[(0,Z.jsx)($e,{className:`h-3.5 w-3.5`}),`Use this point`]})]})]})]})]}),document.body)}var Op={exif:`from the photo's EXIF`,device:`from the device at capture`,manual:`placed by hand`};function kp(e){let t=`${e.lat.toFixed(5)}, ${e.lon.toFixed(5)}`,n=e.source?Op[e.source]:null;return[t,e.accuracy==null?null:`±${e.accuracy} m`,n].filter(Boolean).join(` · `)}function Ap({value:e,onChange:t,idPrefix:n=`edit-geo`}){let[r,i]=(0,X.useState)(!1);return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(Eu,{htmlFor:`${n}-action`,children:`Location`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,Z.jsx)(yt,{className:e?`h-4 w-4 shrink-0 text-info`:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:e?`truncate tabular-nums`:`truncate text-muted-foreground`,children:e?kp(e):`No location on this document`})]}),(0,Z.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Z.jsxs)(`button`,{id:`${n}-action`,type:`button`,onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,Z.jsx)(en,{className:`h-3.5 w-3.5`}),e?`Move pin`:`Set on map`]}),e&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>t(null),"aria-label":`Remove location`,title:`Remove location`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]})]}),r&&(0,Z.jsx)(Dp,{initial:e,onPick:e=>t({lat:e.lat,lon:e.lon,source:`manual`}),onClose:()=>i(!1)})]})}function jp({workspaceId:e,documentIds:t,onClose:n}){let[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(`keep`),[l,u]=(0,X.useState)(``),d=(r.length>0||!!a||s!==`keep`)&&(s!==`replace`||l.trim().length>0),[f,p]=(0,X.useState)(t),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(``);return Sf(n,!m),(0,yf.createPortal)((0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4`,children:(0,Z.jsxs)(`section`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`bulk-edit-title`,className:`max-h-viewport-modal overflow-y-auto w-full max-w-md space-y-4 rounded-xl border bg-background p-5 shadow-elevation-4`,children:[(0,Z.jsxs)(`h2`,{id:`bulk-edit-title`,className:`font-semibold`,children:[`Bulk Edit · `,f.length,` documents`]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Add tags to all selected documents. Choosing a location replaces their existing geotags; leaving it unset keeps them.`}),(0,Z.jsxs)(`fieldset`,{disabled:m,className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:`Add tags`}),(0,Z.jsx)(gp,{tags:r,onChange:i,suggestions:[]})]}),(0,Z.jsx)(Ap,{value:a,onChange:o,idPrefix:`bulk-geo`}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`label`,{htmlFor:`bulk-comment-mode`,className:`text-sm font-medium`,children:`Comment`}),(0,Z.jsxs)(`select`,{id:`bulk-comment-mode`,value:s,onChange:e=>c(e.target.value),className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,children:[(0,Z.jsx)(`option`,{value:`keep`,children:`Keep existing comments`}),(0,Z.jsx)(`option`,{value:`replace`,children:`Replace comments`}),(0,Z.jsx)(`option`,{value:`clear`,children:`Clear comments`})]}),s===`replace`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`label`,{htmlFor:`bulk-comment`,className:`sr-only`,children:`New comment for all selected documents`}),(0,Z.jsx)(`textarea`,{id:`bulk-comment`,rows:3,value:l,onChange:e=>u(e.target.value),placeholder:`Comment for all selected documents…`,className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This replaces the comment on every selected document.`})]}),s===`clear`&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This removes the comment from every selected document.`})]})]}),g&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:g}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(J,{variant:`outline`,onClick:n,disabled:m,children:`Cancel`}),(0,Z.jsx)(J,{onClick:async()=>{if(m||!d)return;h(!0),_(``);let t=[];for(let n of f)try{let t=await Sr(e,n);await Ui(e,bp(t,r,a,s===`keep`?void 0:s===`clear`?``:l))}catch{t.push(n)}window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),h(!1),t.length?(p(t),_(`${f.length-t.length} saved; ${t.length} could not be updated. Retry applies only to those documents.`)):n()},disabled:m||!d,children:m?`Saving…`:g?`Retry failed`:`Apply to all`})]})]})}),window.document.body)}var Mp=[{mode:`copy`,label:`Copy to`,icon:(0,Z.jsx)(Ve,{className:`h-3.5 w-3.5`})},{mode:`move`,label:`Move to`,icon:(0,Z.jsx)(qn,{className:`h-3.5 w-3.5`})},{mode:`delete`,label:`Delete from`,icon:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})}],Np=[{value:`rename`,label:`Rename mine (file-1.ext)`},{value:`overwrite`,label:`Overwrite the existing file`},{value:`error`,label:`Skip the document`}],Pp=`h-9 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function Fp(e){return e.driver===`cacache`?wt:e.config?.remote===!0?we:hr}function Ip({workspaceId:e,documentCount:t,initialMode:n=`copy`,defaultFilename:r=``,onConfirm:i,onClose:a,saving:o=!1,sizeClassName:s}){let{showErrorToast:c}=to(),[l,u]=(0,X.useState)(!1);Sf(a,!o&&!l);let[d,f]=(0,X.useState)(n),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(new Set),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(``),[C,w]=(0,X.useState)(r),[T,E]=(0,X.useState)(`rename`);(0,X.useEffect)(()=>{let t=!1;return wa(e).then(e=>{t||m(e.filter(e=>e.kind===`storage`))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let D=d===`move`,O=e=>d===`delete`?null:e.enabled===!1?`disabled`:e.config?.readOnly===!0?`read-only`:e.config?.supported===!1?`unsupported`:null,k=(0,X.useMemo)(()=>(p||[]).filter(e=>!O(e)).map(e=>e.address),[p,d]),A=e=>{f(e),v(t=>{let n=(p||[]).filter(t=>e===`delete`||t.enabled!==!1&&t.config?.readOnly!==!0&&t.config?.supported!==!1).map(e=>e.address),r=[...t].filter(e=>n.includes(e));return new Set(e===`move`?r.slice(0,1):r)})},j=e=>{v(t=>{if(D)return t.has(e)?new Set:new Set([e]);let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=(0,X.useMemo)(()=>(p||[]).filter(e=>_.has(e.address)&&ua(e)),[p,_]),N=d!==`delete`&&M.length>0,P=e=>{u(!1);let t=Ia(e[0]||``,p||[]),n=t?(p||[]).find(e=>e.address===t.address):null;if(!t||!n){c(`Pick a folder inside a storage backend`);return}if(O(n)){c(`${n.address} is ${O(n)}`);return}if(!ua(n)){c(`${n.address} does not keep folders — objects are stored by content`);return}S(t.key),v(e=>D?new Set([t.address]):new Set([...e,t.address]))},F=async()=>{_.size===0||o||await i([..._],d,{keepDocument:y,folder:N?x.trim():``,filename:N&&t===1?C.trim():``,onConflict:T})},I=t,ee=I===1?``:`s`,te=d===`delete`?`Delete ${I} document${ee} from…`:`${d===`move`?`Move`:`Copy`} ${I} document${ee} to…`,ne=d===`delete`?`Delete from`:d===`move`?`Move to`:`Copy to`,re=_.size===0?ne.split(` `)[0]:`${ne} ${_.size} backend${_.size===1?``:`s`}`;return(0,Z.jsxs)(`div`,{className:K(`flex flex-col overflow-hidden rounded-2xl border bg-card shadow-elevation-4`,s||`max-h-viewport-card w-[min(420px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,Z.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Z.jsx)(hr,{className:`h-4 w-4`}),te]}),(0,Z.jsx)(`button`,{type:`button`,onClick:a,disabled:o,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Z.jsx)(G,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:Mp.map(({mode:e,label:t,icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(e),disabled:o,className:K(`flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors disabled:opacity-50`,d===e?e===`delete`?`border-destructive text-destructive`:`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[n,t]},e))}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto p-3`,children:[h&&(0,Z.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-destructive`,children:h}),!p&&!h&&(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground`,children:`Loading backends…`}),p?.length===0&&(0,Z.jsx)(`p`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No storage backends configured.`}),p?.map(e=>{let t=Fp(e),n=O(e),r=_.has(e.address),i=e.config?.remote===!0;return(0,Z.jsxs)(`div`,{onClick:()=>!n&&!o&&j(e.address),className:K(`group relative flex min-h-10 items-center gap-2 rounded-md px-3 py-2 text-sm shadow-elevation-1 transition-all select-none`,`before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1.5 before:transition-colors`,n?`cursor-not-allowed bg-muted/40 opacity-60 before:bg-transparent`:`cursor-pointer hover:shadow`,!n&&r?d===`delete`?`bg-destructive/[0.08] hover:bg-destructive/[0.12] before:bg-destructive`:`bg-primary/[0.08] hover:bg-primary/[0.12] before:bg-primary`:n?``:`bg-card hover:bg-primary/[0.04] before:bg-transparent`),title:e.address,children:[(0,Z.jsx)(`input`,{type:D?`radio`:`checkbox`,checked:r,disabled:!!n||o,onChange:()=>j(e.address),onClick:e=>e.stopPropagation(),className:`h-4 w-4 shrink-0 accent-primary`,"aria-label":e.address}),(0,Z.jsx)(t,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate font-medium`,children:e.config?.label||e.address}),(0,Z.jsxs)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:[e.driver,` · `,e.address]})]}),i&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-info-subtle px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,title:`Network mount${e.config?.transport?` (${e.config.transport})`:``} — transfers cross the network`,children:e.config?.transport||`remote`}),n&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:n})]},`${e.driver}/${e.address}`)}),d===`delete`&&(0,Z.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:y,onChange:e=>b(e.target.checked),className:`mt-0.5 h-3.5 w-3.5 accent-destructive`}),(0,Z.jsxs)(`span`,{children:[`Keep the index entry when its `,(0,Z.jsx)(`strong`,{children:`last`}),` copy is deleted.`,(0,Z.jsx)(`span`,{className:`block text-muted-foreground`,children:`Otherwise the document is removed from the index once no locations remain.`})]})]}),N&&(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-md border px-3 py-2`,children:[(0,Z.jsxs)(`p`,{className:`text-xs font-medium`,children:[`Destination on `,M.map(e=>e.config?.label||e.address).join(`, `)]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`backend-transfer-folder`,className:`text-[11px] text-muted-foreground`,children:`Folder (relative to the backend root)`}),(0,Z.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Z.jsx)(q,{id:`backend-transfer-folder`,value:x,onChange:e=>S(e.target.value),placeholder:`/`,disabled:o,className:`h-9 font-mono text-xs`}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`icon`,className:`h-9 w-9 shrink-0`,onClick:()=>u(!0),disabled:o,"aria-label":`Browse backend folders`,title:`Browse…`,children:(0,Z.jsx)(Mn,{className:`h-4 w-4`})})]})]}),t===1?(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`backend-transfer-filename`,className:`text-[11px] text-muted-foreground`,children:`File name`}),(0,Z.jsx)(q,{id:`backend-transfer-filename`,value:C,onChange:e=>w(e.target.value),placeholder:r||`keeps the document's own name`,disabled:o,className:`h-9 font-mono text-xs`})]}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Each document keeps its own file name and extension.`}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{htmlFor:`backend-transfer-conflict`,className:`text-[11px] text-muted-foreground`,children:`If a different file already has that name`}),(0,Z.jsx)(`select`,{id:`backend-transfer-conflict`,className:Pp,value:T,onChange:e=>E(e.target.value),disabled:o,children:Np.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),d===`move`&&k.length>0&&(0,Z.jsx)(`p`,{className:`px-1 pt-2 text-[11px] text-muted-foreground`,children:`The source copy is released only once the destination write is durable.`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-t px-4 py-3`,children:[(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[_.size,` backend`,_.size===1?``:`s`,` selected`]}),(0,Z.jsx)(J,{size:`sm`,variant:d===`delete`?`destructive`:`default`,onClick:F,disabled:_.size===0||o,children:o?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ud,{className:`mr-1.5 h-3.5 w-3.5`}),`Working…`]}):(0,Z.jsxs)(Z.Fragment,{children:[d===`delete`?(0,Z.jsx)(lt,{className:`mr-1 h-3.5 w-3.5`}):d===`move`?(0,Z.jsx)(qn,{className:`mr-1 h-3.5 w-3.5`}):(0,Z.jsx)(Ve,{className:`mr-1 h-3.5 w-3.5`}),re]})})]}),d===`delete`&&(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 border-t bg-destructive/5 px-4 py-2 text-[11px] text-muted-foreground`,children:[(0,Z.jsx)(at,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,Z.jsx)(`span`,{children:`Deletes the file data from the selected backends. Copies on other backends are untouched.`})]}),l&&(0,Z.jsx)(pp,{onClose:()=>u(!1),children:(0,Z.jsx)(dp,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`backends`],fixedWorkspaceName:e,title:`Pick a destination folder…`,confirmLabel:`Use folder`,onConfirm:P,onClose:()=>u(!1)})})]})}function Lp({onClose:e,onConfirm:t,fixedWorkspaceName:n,saving:r=!1,sizeClassName:i}){let[a,o]=(0,X.useState)(n?`browse`:`workspace`),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!n),[d,f]=(0,X.useState)(n??null),[p,m]=(0,X.useState)(`context`),[h,g]=(0,X.useState)(new Set),[_,v]=(0,X.useState)(n);return n!==_&&(v(n),n||u(!0)),(0,X.useEffect)(()=>{n||Pr().then(c).catch(()=>c([])).finally(()=>u(!1))},[n]),(0,Z.jsxs)(`div`,{className:K(`flex flex-col overflow-hidden rounded-2xl border bg-card shadow-elevation-4`,i||`h-viewport-card max-h-full w-[min(420px,90vw)] max-md:h-full max-md:w-full max-md:shadow-elevation-5`),children:[(0,Z.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center justify-between border-b px-4`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Z.jsx)(Ot,{className:`h-4 w-4`}),a===`workspace`?`Add existing documents…`:`Pick documents…`]}),(0,Z.jsx)(`button`,{type:`button`,onClick:e,disabled:r,className:`text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40`,"aria-label":`Close`,children:(0,Z.jsx)(G,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,Z.jsxs)(`div`,{className:`grid h-full w-[200%] grid-cols-2 transition-transform duration-200`,style:{transform:a===`workspace`?`translateX(0)`:`translateX(-50%)`},children:[(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-col overflow-y-auto p-2`,children:(0,Z.jsx)(lp,{workspaces:s,loading:l,onPick:e=>{f(e),g(new Set),o(`browse`)}})}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b px-2 pt-2`,children:[!n&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>o(`workspace`),className:`mr-1 rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground touch-target`,"aria-label":`Back to workspaces`,children:(0,Z.jsx)(Ye,{className:`h-4 w-4 rotate-180`})}),[`context`,`directory`].map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{m(e),g(new Set)},className:K(`flex items-center gap-1.5 rounded-t-md border-b-2 px-3 py-2 text-xs font-medium transition-colors`,p===e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:[tp[e],np[e]]},e))]}),d&&(0,Z.jsx)(up,{workspaceName:d,treeTab:p,onTreeTabChange:m,selectedDocIds:h,onToggleDoc:e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onNavigate:()=>g(new Set)})]})]})}),a===`browse`&&(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-t px-4 py-3`,children:[(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[h.size,` document`,h.size===1?``:`s`,` selected`]}),(0,Z.jsx)(J,{size:`sm`,onClick:async()=>{!d||h.size===0||r||await t(Array.from(h),{workspaceName:d,treeName:p===`directory`?`directory`:Na,treeType:p})},disabled:h.size===0||r,children:r?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ud,{className:`mr-1.5 h-3.5 w-3.5`}),`Adding…`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ot,{className:`mr-1 h-3.5 w-3.5`}),`Add`]})})]})]})}var Rp=(0,X.createContext)(null),zp={entry:null,open:()=>{},close:()=>{}};function Bp(){return(0,X.useContext)(Rp)??zp}var Vp=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`div`,{className:`relative w-full overflow-auto`,children:(0,Z.jsx)(`table`,{ref:n,className:K(`w-full caption-bottom text-sm`,e),...t})}));Vp.displayName=`Table`;var Hp=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`thead`,{ref:n,className:K(`[&_tr]:border-b`,e),...t}));Hp.displayName=`TableHeader`;var Up=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`tbody`,{ref:n,className:K(`[&_tr:last-child]:border-0`,e),...t}));Up.displayName=`TableBody`;var Wp=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`tfoot`,{ref:n,className:K(`border-t bg-muted/50 font-medium [&>tr]:last:border-b-0`,e),...t}));Wp.displayName=`TableFooter`;var Gp=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`tr`,{ref:n,className:K(`border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted`,e),...t}));Gp.displayName=`TableRow`;var Kp=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`th`,{ref:n,className:K(`h-12 px-2 md:px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0`,e),...t}));Kp.displayName=`TableHead`;var qp=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`td`,{ref:n,className:K(`p-2 md:p-4 align-middle [&:has([role=checkbox])]:pr-0`,e),...t}));qp.displayName=`TableCell`;var Jp=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(`caption`,{ref:n,className:K(`mt-4 text-sm text-muted-foreground`,e),...t}));Jp.displayName=`TableCaption`;var Yp=({label:e,sortKey:t,sort:n,onSort:r,className:i})=>{let a=n.key===t;return(0,Z.jsx)(Kp,{"aria-sort":a?n.dir===`asc`?`ascending`:`descending`:`none`,className:K(`cursor-pointer select-none hover:text-foreground transition-colors`,i),onClick:()=>r(t),children:(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e,a?n.dir===`asc`?(0,Z.jsx)(Sn,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Dn,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Pe,{className:`h-3.5 w-3.5 opacity-40`})]})})};Yp.displayName=`SortableTableHead`;function Xp(e,t,n={key:null,dir:`asc`}){let[r,i]=X.useState(n);return{sorted:X.useMemo(()=>{let n=r.key?t[r.key]:null;if(!n)return e;let i=r.dir===`asc`?1:-1;return[...e].sort((e,t)=>{let r=n(e)??``,a=n(t)??``;return typeof r==`number`&&typeof a==`number`?(r-a)*i:String(r).localeCompare(String(a),void 0,{numeric:!0})*i})},[e,r,t]),sort:r,toggleSort:X.useCallback(e=>{i(t=>t.key===e?{key:e,dir:t.dir===`asc`?`desc`:`asc`}:{key:e,dir:`asc`})},[])}}var Zp=`workspace:relations:refresh`;function Qp(){window.dispatchEvent(new CustomEvent(Zp))}var $p=(0,X.createContext)(null),em=`canvas:documentOpenMode`;function tm(){try{return localStorage.getItem(em)===`modal`?`modal`:`side`}catch{return`side`}}var nm=tm(),rm=new Set;function im(){return nm}function am(e){try{localStorage.setItem(em,e)}catch{}nm=e;for(let e of rm)e()}function om(e){rm.add(e);let t=t=>{(t.key===em||t.key===null)&&(nm=tm(),e())};return window.addEventListener(`storage`,t),()=>{rm.delete(e),window.removeEventListener(`storage`,t)}}function sm(){return(0,X.useSyncExternalStore)(om,im,()=>`side`)}function cm({tabs:e,active:t,onChange:n,className:r=``,iconOnly:i=!1}){return(0,Z.jsx)(`div`,{className:`flex gap-1 border-b overflow-x-auto ${r}`,children:e.map(e=>{let r=e.icon;return(0,Z.jsxs)(`button`,{onClick:()=>n(e.id),title:e.label,className:`${i&&r?`px-3`:`px-4`} py-2 text-sm font-medium border-b-2 transition-colors whitespace-nowrap inline-flex items-center gap-1.5 ${t===e.id?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[r&&(0,Z.jsx)(r,{className:`h-3.5 w-3.5`}),(!i||!r)&&e.label]},e.id)})})}var lm=e=>`${Qr.workspaces}/${encodeURIComponent(e)}/messages`,um=e=>Y.get(`${lm(e)}/accounts`),dm=(e,t)=>Y.get(`${lm(e)}/reply-target/${t}`),fm=(e,t)=>Y.post(`${lm(e)}/send`,t),pm=(e,t)=>Y.get(`${lm(e)}/whatsapp/${encodeURIComponent(t)}/connection`),mm=(e,t)=>Y.get(`${lm(e)}/outbox/${encodeURIComponent(t)}`),hm=(e,t)=>Y.delete(`${lm(e)}/whatsapp/${encodeURIComponent(t)}/connection`);function gm(e,t,n=!1){let r=2166136261;try{for(let e of localStorage.getItem(`authToken`)||``)r=Math.imul(r^e.charCodeAt(0),16777619)}catch{}return`canvas:message-draft:${r>>>0}:${e}:${t||`new`}${n?`:fwd`:``}`}var _m={reply:`Reply`,replyAll:`Reply all`,forward:`Forward`};function vm({workspaceId:e,replyToDocumentId:t,mode:n=`reply`,originalSubject:r,initialAccount:i,testEmail:a=!1,onClose:o}){let s=!!t&&n===`forward`,c=a?`${gm(e)}:smtp-test:${i?.address}`:gm(e,t,s),l=()=>({requestId:crypto.randomUUID(),text:a?`This is a test email sent from Canvas to check the SMTP configuration.`:``,replyToDocumentId:t,...i,...a?{subject:`Canvas SMTP test`}:{},...s?{forward:!0}:t?{replyAll:n===`replyAll`,quote:!0}:{}}),[u,d]=(0,X.useState)(()=>{try{let e=localStorage.getItem(c);if(e){let r=JSON.parse(e),i=r.draft||r;if(s||!t||r.attempted)return i;let a=n===`replyAll`;return{...i,replyAll:a,...!!i.replyAll===a?{}:{to:void 0,cc:void 0}}}}catch{}return l()}),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)([]),[g,_]=(0,X.useState)(navigator.onLine);(0,X.useEffect)(()=>{let e=()=>_(navigator.onLine);return window.addEventListener(`online`,e),window.addEventListener(`offline`,e),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,e)}},[]);let[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(()=>{try{return JSON.parse(localStorage.getItem(c)||`{}`).attempted===!0}catch{return!1}}),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(null);(0,X.useEffect)(()=>{let n=!0;return Promise.all([um(e),t?dm(e,t):Promise.resolve(null)]).then(([e,r])=>{n&&(p(r),h(e.filter(e=>e.canSend&&(!r||e.driver===r.driver&&e.address===r.address))),t&&!r&&C(`This message has no supported reply account.`),r&&d(e=>{let t=e.replyAll?r.allRecipients:r.recipients;return{...e,driver:r.driver,address:r.address,...!s&&t&&!b?{to:e.to?.some(e=>e.trim())?e.to:t.to,cc:e.cc?.some(e=>e.trim())?e.cc:t.cc}:{}}}))}).catch(e=>{n&&C(e.message)}),()=>{n=!1}},[e,t,s,b]),(0,X.useEffect)(()=>{try{w?.status===`accepted`?localStorage.removeItem(c):localStorage.setItem(c,JSON.stringify({draft:u,attempted:b}))}catch{}},[c,u,b,w]);let E=m.find(e=>e.driver===u.driver&&e.address===u.address),D=E?.driver===`imap`,O=!!u.text.trim(),k=e=>d(t=>({...t,...e})),A=async()=>{y(!0),C(``),x(!0);let t=D?O?u:{...u,html:void 0}:{...u,html:void 0,quote:void 0,forward:void 0};try{let n=b?await mm(e,u.requestId).catch(n=>{if(n.statusCode===404)return fm(e,t);throw n}):await fm(e,t);if(T(n),n.status===`accepted`){try{localStorage.removeItem(c)}catch{}window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e}}))}}catch(e){let t=e;C(t.message),!b&&t.statusCode&&t.statusCode>=400&&t.statusCode<500&&t.statusCode!==409&&x(!1)}finally{y(!1)}},j=u.replyAll?f?.allRecipients:f?.recipients,M=v||b,N=a?`Send test email`:t?s?_m.forward:_m[u.replyAll?`replyAll`:`reply`]:`New message`,P=t&&r?`${s?`Fwd`:`Re`}: ${r.replace(s?/^(fwd?|fw):\s*/i:/^re:\s*/i,``)}`:``;return(0,Z.jsxs)(`section`,{className:`max-h-[70dvh] overflow-y-auto rounded-md border bg-card p-3 space-y-3`,"aria-label":t?`${N} to message`:`New message`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Z.jsx)(`strong`,{className:`text-sm`,children:N}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,onClick:o,children:`Close`})]}),(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[`Send from`,(0,Z.jsxs)(`select`,{"aria-label":`Sending account`,className:`w-full rounded border bg-background p-2`,value:E?`${E.driver}:${E.address}`:``,disabled:M||!!t||!!i,onChange:e=>{let t=m.find(t=>`${t.driver}:${t.address}`===e.target.value);t&&k({driver:t.driver,address:t.address,to:[],cc:[],bcc:[],subject:void 0,target:void 0,replyAll:!1})},children:[(0,Z.jsx)(`option`,{value:``,children:`Select an enabled sending account`}),m.map(e=>(0,Z.jsxs)(`option`,{value:`${e.driver}:${e.address}`,children:[e.driver,` · `,e.from||e.address]},`${e.driver}:${e.address}`))]})]}),a&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Uses the saved SMTP settings. Enter a recipient you control, then click Send. This sends a real email; provider acceptance does not guarantee inbox delivery.`}),!m.length&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Enable sending in the account’s workspace settings. Your draft stays on this device.`}),D?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[`To `,t&&!s?`(leave blank to reply to the sender)`:``,(0,Z.jsx)(q,{"aria-label":`To`,disabled:M,value:u.to?.join(`, `)||``,onChange:e=>k({to:[e.target.value]})})]}),t&&!s&&!u.to?.some(e=>e.trim())&&j&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Reply to: `,j.to.join(`, `),j.cc.length?` · Cc: ${j.cc.join(`, `)}`:``]}),[`cc`,`bcc`].map(e=>(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[e===`cc`?`Cc`:`Bcc`,(0,Z.jsx)(q,{"aria-label":e===`cc`?`Cc`:`Bcc`,disabled:M,value:u[e]?.join(`, `)||``,onChange:t=>k({[e]:[t.target.value]})})]},e)),(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[`Subject`,(0,Z.jsx)(q,{"aria-label":`Subject`,disabled:M,value:u.subject||``,placeholder:P,onChange:e=>k({subject:e.target.value||void 0})})]}),t&&!s&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-xs`,children:[(0,Z.jsxs)(`label`,{className:`flex gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:M,checked:u.replyAll||!1,onChange:e=>{let t=e.target.checked?f?.allRecipients:f?.recipients;k({replyAll:e.target.checked,...t?{to:t.to,cc:t.cc}:{}})}}),`Reply all`]}),(0,Z.jsxs)(`label`,{className:`flex gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:M,checked:u.quote||!1,onChange:e=>k({quote:e.target.checked})}),`Quote original message`]})]}),s&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The original message and its attachments are included below your note.`}),(0,Z.jsx)(So,{format:`html`,editable:!M,value:u.html||``,placeholder:s?`Add a note (optional)…`:`Write a message…`,onChange:(e,t)=>k({html:e,text:t.slice(0,32e3)})})]}):(0,Z.jsxs)(Z.Fragment,{children:[!t&&(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[`Conversation (configured channel name or ID)`,(0,Z.jsx)(q,{"aria-label":`Conversation`,disabled:M,value:u.target||``,onChange:e=>k({target:e.target.value})})]}),(0,Z.jsx)(`textarea`,{"aria-label":`Message text`,className:`w-full rounded border bg-background p-2 text-sm`,rows:5,maxLength:32e3,disabled:M,value:u.text,onChange:e=>k({text:e.target.value}),placeholder:`Write a message…`})]}),S&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:S}),w&&(0,Z.jsxs)(`p`,{role:`status`,className:`text-sm`,children:[w.status===`accepted`?`Accepted by the provider.`:w.message,` `,w.warnings?.join(` `),` `,w.rejected?.length?`Not accepted for: ${w.rejected.join(`, `)}`:``]}),w?.status!==`accepted`&&(0,Z.jsx)(J,{size:`sm`,disabled:v||!b&&(!E||!O&&!(D&&s)||s&&!u.to?.some(e=>e.trim()))||!g,onClick:()=>void A(),children:v?`Sending…`:b?`Check send status`:`Send`}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,disabled:v,onClick:()=>{window.confirm(b?`This message may already have been sent. Discard this draft only after checking the conversation.`:`Discard this draft?`)&&(d({...l(),driver:u.driver,address:u.address}),x(!1),T(null),C(``))},children:`Discard draft`}),b&&w?.status!==`accepted`&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Do not start another send until you have checked the conversation. The same request will not be delivered twice by Canvas.`})]})}function ym(e){let t=(0,X.useRef)(null),n=(0,X.useRef)(e.onClose);return(0,X.useEffect)(()=>{n.current=e.onClose}),(0,X.useEffect)(()=>{let e=t.current;if(!e)return;let n=document.activeElement;return e.showModal(),()=>{e.close(),n?.focus()}},[]),(0,Z.jsx)(`dialog`,{ref:t,"aria-label":e.replyToDocumentId?`${e.mode===`forward`?`Forward`:e.mode===`replyAll`?`Reply all`:`Reply`} message`:`Send test email`,className:`m-auto w-[calc(100%-2rem)] max-w-3xl max-h-[90dvh] overflow-y-auto rounded-lg border bg-card p-0 text-foreground shadow-elevation-4 backdrop:bg-black/40`,onKeyDown:e=>e.stopPropagation(),onCancel:e=>{e.preventDefault(),e.stopPropagation(),n.current()},children:(0,Z.jsx)(vm,{...e})})}var bm=1,xm=8,Sm=320,Cm=28,wm=2.5,Tm={scale:1,x:0,y:0};function Em({src:e,alt:t,className:n=``,onZoomChange:r}){let i=(0,X.useRef)(null),a=(0,X.useRef)(null),[o,s]=(0,X.useState)(Tm),c=(0,X.useRef)(new Map),l=(0,X.useRef)(null),u=(0,X.useRef)(null),d=(0,X.useRef)(!1),f=(0,X.useRef)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(e);h!==e&&(g(e),s(Tm)),(0,X.useEffect)(()=>{r?.(o.scale>1.001)},[o.scale,r]);let _=(0,X.useCallback)(e=>{let t=i.current,n=a.current;if(!t||!n)return e;let r=Math.min(xm,Math.max(bm,e.scale)),o=Math.max(0,(n.offsetWidth*r-t.clientWidth)/2),s=Math.max(0,(n.offsetHeight*r-t.clientHeight)/2);return{scale:r,x:Math.min(o,Math.max(-o,e.x)),y:Math.min(s,Math.max(-s,e.y))}},[]),v=(0,X.useCallback)((e,t,n)=>{let r=i.current;if(!r)return;let a=r.getBoundingClientRect(),o=t-a.left-a.width/2,c=n-a.top-a.height/2;s(t=>{let n=e/t.scale;return _({scale:e,x:o-(o-t.x)*n,y:c-(c-t.y)*n})})},[_]),y=(0,X.useCallback)(()=>{let e=i.current,t=a.current;if(!e||!t||!t.offsetWidth||!t.offsetHeight)return wm;let n=Math.max(e.clientWidth/t.offsetWidth,e.clientHeight/t.offsetHeight),r=Math.max(t.naturalWidth/t.offsetWidth,t.naturalHeight/t.offsetHeight)||xm;return Math.min(xm,Math.max(wm,Math.min(Math.max(n,wm),r)))},[]),b=(0,X.useCallback)((e,t)=>{o.scale>1.001?s(Tm):v(y(),e,t)},[o.scale,v,y]),x=e=>{if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),d.current=!1,c.current.size===2){let[e,t]=[...c.current.values()];l.current={dist:Math.hypot(e.x-t.x,e.y-t.y),scale:o.scale,cx:(e.x+t.x)/2,cy:(e.y+t.y)/2}}e.currentTarget.setPointerCapture(e.pointerId)},S=e=>{let t=c.current.get(e.pointerId);if(!t)return;if(c.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),c.current.size>=2&&l.current){let[e,t]=[...c.current.values()],n=Math.hypot(e.x-t.x,e.y-t.y);l.current.dist>0&&(d.current=!0,m(!0),v(l.current.scale*(n/l.current.dist),l.current.cx,l.current.cy));return}if(o.scale<=1.001)return;let n=e.clientX-t.x,r=e.clientY-t.y;(Math.abs(n)>1||Math.abs(r)>1)&&(d.current=!0,m(!0)),s(e=>_({...e,x:e.x+n,y:e.y+r}))},C=e=>{if(c.current.delete(e.pointerId),c.current.size<2&&(l.current=null),c.current.size===0&&m(!1),d.current){u.current=null;return}let t=e.timeStamp,n=u.current;if(n&&t-n.t<Sm&&Math.hypot(e.clientX-n.x,e.clientY-n.y)<Cm){u.current=null,f.current=t,b(e.clientX,e.clientY);return}u.current={t,x:e.clientX,y:e.clientY}},w=e=>{e.preventDefault();let t=o.scale*(e.deltaY<0?1.15:1/1.15);t<=bm?s(Tm):v(Math.min(xm,t),e.clientX,e.clientY)},T=o.scale>1.001;return(0,Z.jsx)(`div`,{ref:i,className:`relative flex h-full w-full items-center justify-center overflow-hidden`,style:{touchAction:`none`,cursor:T?`grab`:`zoom-in`},onPointerDown:x,onPointerMove:S,onPointerUp:C,onPointerCancel:e=>{c.current.delete(e.pointerId),l.current=null,u.current=null,d.current=!0,c.current.size===0&&m(!1)},onWheel:w,onDoubleClick:e=>{e.preventDefault(),e.stopPropagation(),!(f.current!==null&&e.timeStamp-f.current<Sm)&&b(e.clientX,e.clientY)},children:(0,Z.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,className:n,style:{transform:`translate3d(${o.x}px, ${o.y}px, 0) scale(${o.scale})`,transformOrigin:`center center`,transition:p?`none`:`transform 160ms ease-out`,willChange:`transform`}})})}var Dm=`(max-width: 767px)`,Om=new Map;function km(e){let t=Om.get(e);if(!t){let n=()=>typeof window<`u`&&typeof window.matchMedia==`function`;t={subscribe:t=>{if(!n())return()=>{};let r=window.matchMedia(e);return r.addEventListener(`change`,t),()=>r.removeEventListener(`change`,t)},getSnapshot:()=>n()?window.matchMedia(e).matches:!1},Om.set(e,t)}return t}function Am(){let e=km(Dm);return(0,X.useSyncExternalStore)(e.subscribe,e.getSnapshot,()=>!1)}function jm(){return Mm(`(max-width: 1023px)`)}function Mm(e){let t=km(e);return(0,X.useSyncExternalStore)(t.subscribe,t.getSnapshot,()=>!1)}function Nm(){return!/android|iphone|ipad|mobile/i.test(navigator.userAgent)&&navigator.pdfViewerEnabled!==!1}var Pm=40,Fm=1600;function Im({blob:e,filename:t}){let n=(0,X.useRef)(null),[r,i]=(0,X.useState)({error:null,pages:0,truncated:!1});return(0,X.useEffect)(()=>{let r=n.current;if(!r)return;let a=!1,o=null;return(async()=>{let n=await m(()=>import(`./pdf-Ciz5_WNq.js`),__vite__mapDeps([0,1])),s=(await m(async()=>{let{default:e}=await import(`./pdf.worker.min-C8Ts8bNu.js`);return{default:e}},[])).default;n.GlobalWorkerOptions.workerSrc=s;let c=await e.arrayBuffer();if(a)return;let l=n.getDocument({data:c});o=()=>{l.destroy()};let u=await l.promise;if(a)return;let d=Math.min(u.numPages,Pm),f=r.clientWidth||600,p=window.devicePixelRatio||1;for(let e=1;e<=d;e++){if(a)return;let n=await u.getPage(e),o=n.getViewport({scale:1}),s=Math.min(f*p,Fm*p)/o.width,c=n.getViewport({scale:s}),l=document.createElement(`canvas`);if(l.width=c.width,l.height=c.height,l.style.width=`100%`,l.style.height=`auto`,l.className=`rounded border bg-white`,l.setAttribute(`aria-label`,`${t}, page ${e}`),await n.render({canvas:l,viewport:c}).promise,n.cleanup(),a)return;r.appendChild(l),i({error:null,pages:e,truncated:u.numPages>Pm})}})().catch(e=>{a||i(t=>({...t,error:e instanceof Error?e.message:String(e)}))}),()=>{a=!0,o?.(),r.replaceChildren()}},[e,t]),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[r.error&&(0,Z.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not render PDF: `,r.error]}),!r.error&&r.pages===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rendering PDF…`}),(0,Z.jsx)(`div`,{ref:n,className:`space-y-2`}),r.truncated&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Showing the first `,Pm,` pages. Download the file for the full document.`]})]})}function Lm({blob:e,blobUrl:t,filename:n,className:r=``}){let i=(0,X.useMemo)(()=>e&&e.type!==`application/pdf`?URL.createObjectURL(e.slice(0,e.size,`application/pdf`)):null,[e]);return(0,X.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),Nm()||!e?(0,Z.jsx)(`div`,{className:`min-h-[300px] ${r}`,children:(0,Z.jsx)(`iframe`,{src:i??t,className:`h-full min-h-[300px] w-full rounded border`,title:n})}):(0,Z.jsx)(`div`,{className:`max-h-viewport-pane overflow-y-auto ${r}`,children:(0,Z.jsx)(Im,{blob:e,filename:n})})}function Rm(e,t,n=256,{enabled:r=!0,blobFallback:i=!0,version:a=null}={}){let{isPublic:o,fetchBlob:s,fetchThumbnail:c}=vo(e),l=`${o?`pub`:`ws`}:${e}:${t}:${n}:${r}:${a??``}`,[u,d]=(0,X.useState)({blobUrl:null,error:null,loading:r}),[f,p]=(0,X.useState)(l);return l!==f&&(p(l),d({blobUrl:null,error:null,loading:r})),(0,X.useEffect)(()=>{if(!r)return;let e=!1,o=null;return c(t,n,a).catch(e=>{if(!i)throw e;return s(t)}).then(({blob:t})=>{e||(o=URL.createObjectURL(t),d({blobUrl:o,error:null,loading:!1}))}).catch(t=>{e||d({blobUrl:null,error:String(t instanceof Error?t.message:t),loading:!1})}),()=>{e=!0,o&&URL.revokeObjectURL(o)}},[l]),u}function zm({workspaceId:e,document:t}){let{download:n}=vo(e),[r,i]=(0,X.useState)(!1),a=mo(t)||`document-${t.id}`;return(0,Z.jsxs)(`button`,{type:`button`,onClick:async()=>{i(!0);try{await n(t.id,a)}finally{i(!1)}},disabled:r,className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Z.jsx)(er,{className:`h-3.5 w-3.5`}),r?`Preparing…`:`Download`]})}var Bm=1600;function Vm({error:e,loading:t,children:n}){return e?(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:e}):t?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading preview...`}):(0,Z.jsx)(Z.Fragment,{children:n})}function Hm({workspaceId:e,document:t,className:n=``}){let r=(0,X.useContext)($p),i=Am(),a=Mm(`(pointer: coarse)`),{blobUrl:o,error:s,loading:c}=Rm(e,t.id,Bm,{version:t.checksumArray?.[0]??null}),{fetchBlob:l}=vo(e),u=mo(t)||`document-${t.id}`,[d,f]=(0,X.useState)(!1);return(0,Z.jsx)(Vm,{error:s,loading:c,children:o&&(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[i||a?(0,Z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Z.jsx)(Em,{src:o,alt:u,className:`max-h-full max-w-full object-contain`})}):(0,Z.jsx)(`img`,{src:o,alt:u,draggable:!1,onDoubleClick:r?e=>{e.preventDefault(),e.stopPropagation(),r()}:void 0,title:r?`Double-click to maximize or restore`:void 0,className:`min-h-0 w-full flex-1 object-contain ${r?`cursor-zoom-in`:``}`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{let{blob:e}=await l(t.id),n=URL.createObjectURL(e),r=window.document.createElement(`a`);r.href=n,r.download=u,window.document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),3e4)}finally{f(!1)}},disabled:d,className:`inline-flex shrink-0 self-start items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50`,children:[(0,Z.jsx)(er,{className:`h-3.5 w-3.5`}),d?`Preparing…`:`Download original`]})]})})}function Um({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=go(e,t.id);return(0,Z.jsx)(Vm,{error:i,loading:a,children:r&&(0,Z.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Z.jsx)(`audio`,{src:r,controls:!0,preload:`metadata`,className:`w-full`}),(0,Z.jsx)(zm,{workspaceId:e,document:t})]})})}function Wm({workspaceId:e,document:t,className:n=``}){let{src:r,error:i,loading:a}=go(e,t.id),[o,s]=(0,X.useState)(!1);return(0,Z.jsx)(Vm,{error:i,loading:a,children:r&&(0,Z.jsxs)(`div`,{className:`space-y-2 ${n}`,children:[(0,Z.jsx)(`video`,{src:r,controls:!0,playsInline:!0,preload:`metadata`,onError:()=>s(!0),className:`max-h-viewport-pane w-full rounded border`}),o&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This video can’t be played inline in your browser. Download it to view.`}),(0,Z.jsx)(zm,{workspaceId:e,document:t})]})})}function Gm({workspaceId:e,document:t,className:n=``}){let{blobUrl:r,blob:i,error:a,loading:o}=Oo(e,t.id,{typeHint:`application/pdf`}),s=mo(t)||`document-${t.id}`;return(0,Z.jsx)(Vm,{error:a,loading:o,children:r&&(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${n}`,children:[(0,Z.jsx)(Lm,{blob:i,blobUrl:r,filename:s,className:`min-h-0 flex-1`}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(zm,{workspaceId:e,document:t})})]})})}var Km=(0,X.lazy)(()=>m(()=>import(`./markdown-html-bKd2bDZi.js`),__vite__mapDeps([2,3,4,5,6,7])));function qm({content:e,className:t=``,preview:n=!1}){return(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`whitespace-pre-wrap break-words ${t}`,children:e}),children:(0,Z.jsx)(Km,{content:e,className:t,preview:n})})}function Jm({workspaceId:e,document:t,className:n=``}){let{text:r,error:i,loading:a}=Oo(e,t.id,{mode:`text`});return i?(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:i}):a||r==null?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Z.jsx)(`pre`,{className:`bg-muted p-3 rounded text-xs overflow-auto max-h-viewport-pane whitespace-pre-wrap ${n}`,children:r})}function Ym({workspaceId:e,document:t,className:n=``}){let r=t.schema===no,{text:i,error:a,loading:o}=Oo(e,t.id,{mode:`text`,enabled:!r});return r?(0,Z.jsxs)(`div`,{className:`space-y-3 ${n}`,children:[t.data?.title?(0,Z.jsx)(`h3`,{className:`text-lg font-semibold`,children:String(t.data.title)}):null,(0,Z.jsx)(`div`,{className:`rounded-md border border-input bg-transparent`,children:(0,Z.jsx)(qm,{content:String(t.data?.content??``),className:`markdown-doc px-4 py-3`})})]}):a?(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:a}):o||i==null?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading...`}):(0,Z.jsx)(`div`,{className:`rounded-md border border-input bg-transparent overflow-auto max-h-viewport-pane ${n}`,children:(0,Z.jsx)(qm,{content:i,className:`markdown-doc px-4 py-3`})})}function Xm({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),r=ro(n);return r?(0,Z.jsx)(`div`,{className:`aspect-video w-full ${t}`,children:(0,Z.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${encodeURIComponent(r)}`,title:String(e.data?.title??e.data?.label??`YouTube video`),className:`h-full w-full rounded border`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})}):null}function Zm({document:e,className:t=``}){let n=String(e.data?.url??e.data?.uri??``),[r,i]=(0,X.useState)({blobUrl:null,blob:null,failed:!1,loading:!0}),[a,o]=(0,X.useState)(n);n!==a&&(o(n),i({blobUrl:null,blob:null,failed:!1,loading:!0})),(0,X.useEffect)(()=>{let e=!1,t=null,r=async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.blob();return new Blob([t],{type:`application/pdf`})},a=()=>{let e=localStorage.getItem(`authToken`);return fetch(`${ti}/proxy/pdf?url=${encodeURIComponent(n)}`,{headers:e?{Authorization:`Bearer ${e}`}:{}})};return fetch(n).then(r).catch(()=>a().then(r)).then(n=>{e||(t=URL.createObjectURL(n),i({blobUrl:t,blob:n,failed:!1,loading:!1}))}).catch(()=>{e||i({blobUrl:null,blob:null,failed:!0,loading:!1})}),()=>{e=!0,t&&URL.revokeObjectURL(t)}},[n]);let{blobUrl:s,blob:c,failed:l,loading:u}=r,d=(()=>{try{let e=decodeURIComponent(new URL(n).pathname.split(`/`).filter(Boolean).pop()??``)||`document`;return/\.pdf$/i.test(e)?e:`${e}.pdf`}catch{return`document.pdf`}})();return(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-2 ${t}`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3`,children:[(0,Z.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[(0,Z.jsx)(gn,{className:`h-3 w-3`}),` `,n]}),c&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{if(!c)return;let e=URL.createObjectURL(c),t=window.document.createElement(`a`);t.href=e,t.download=d,window.document.body.appendChild(t),t.click(),t.remove(),setTimeout(()=>URL.revokeObjectURL(e),3e4)},className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:[(0,Z.jsx)(er,{className:`h-3.5 w-3.5`}),` Download`]})]}),u&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading PDF…`}),l&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Inline preview unavailable (direct fetch and server proxy both failed). Use the link above.`}),s&&(0,Z.jsx)(Lm,{blob:c,blobUrl:s,filename:d,className:`min-h-[300px] flex-1`})]})}function Qm(e){if(!e)return!1;try{let t=new URL(e);return!!(/\.pdf$/i.test(t.pathname)||t.hostname.endsWith(`arxiv.org`)&&t.pathname.startsWith(`/pdf/`))}catch{return!1}}function $m(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function eh({document:e,className:t=``}){let n=e.data||{},r=String(n.url??n.uri??``),i=String(n.title??n.label??``)||$m(r),a=typeof n.favIconUrl==`string`?n.favIconUrl:``,o=n.pinned===!0,s=typeof n.timestamp==`string`?n.timestamp:null,[c,l]=(0,X.useState)(!1);return(0,Z.jsxs)(`div`,{className:`space-y-3 ${t}`,children:[(0,Z.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors hover:bg-accent/40`,children:[(0,Z.jsx)(`div`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded bg-muted`,children:a&&!c?(0,Z.jsx)(`img`,{src:a,alt:``,className:`h-5 w-5`,onError:()=>l(!0)}):(0,Z.jsx)(oe,{className:`h-4 w-4 text-muted-foreground`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium leading-tight`,children:i}),o&&(0,Z.jsx)(ne,{className:`h-3 w-3 shrink-0 fill-warning text-warning`})]}),(0,Z.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:$m(r)}),(0,Z.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground/70`,children:r})]}),(0,Z.jsx)(gn,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground reveal-on-hover`})]}),s&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Saved `,new Date(s).toLocaleString()]})]})}var th={enableHighAccuracy:!0,timeout:1e4,maximumAge:6e4};function nh(e){let t=e.coords,n={lat:t.latitude,lon:t.longitude,source:`device`};return t.altitude!=null&&Number.isFinite(t.altitude)&&(n.alt=t.altitude),Number.isFinite(t.accuracy)&&(n.accuracy=Math.round(t.accuracy)),n}function rh(){return new Promise((e,t)=>navigator.geolocation.getCurrentPosition(e,t,th))}function ih(e){let t=e?.code;return t===1?`Location permission denied`:t===2?`Location unavailable; no fix right now`:t===3?`Timed out waiting for a location fix`:`Could not read your location`}function ah(){let e=typeof navigator<`u`&&`geolocation`in navigator&&typeof window<`u`&&window.isSecureContext,[t,n]=(0,X.useState)(e?`prompt`:`unsupported`),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(null),h=(0,X.useRef)(!1),g=(0,X.useRef)(null),_=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!e||!navigator.permissions?.query)return;let t=!1,r=null;return navigator.permissions.query({name:`geolocation`}).then(e=>{t||(r=e,n(e.state),e.onchange=()=>n(e.state))}).catch(()=>{}),()=>{t=!0,r&&(r.onchange=null)}},[e]);let v=(0,X.useCallback)(e=>{if(c(null),!e){_.current=null,f(null),m(null),h.current||i(!1);return}let t={lat:e.lat,lon:e.lon,source:`manual`};_.current=t,f(t),m(e.label??null),i(!0)},[]);return{supported:e,permission:t,enabled:r,busy:a,error:s,fix:l,setEnabled:(0,X.useCallback)(t=>{if(c(null),!t){h.current=!1,_.current=null,f(null),m(null),i(!1);return}_.current||e&&(h.current=!0,i(!0),o(!0),rh().then(e=>{let t=nh(e);g.current=t,u(t),n(`granted`)}).catch(e=>{c(ih(e)),e?.code===1&&(n(`denied`),h.current=!1,i(!1))}).finally(()=>o(!1)))},[e]),manual:d,manualLabel:p,setManual:v,capture:(0,X.useCallback)(async()=>{if(_.current)return _.current;if(!h.current||!e)return null;try{return nh(await rh())}catch{return g.current}},[e])}}var oh=`2.1`,sh=[`pending`,`in-progress`,`completed`,`cancelled`],ch={pending:`Pending`,"in-progress":`In progress`,completed:`Completed`,cancelled:`Cancelled`};function lh(e){return String(e).padStart(2,`0`)}function uh(e){return`${e.getFullYear()}-${lh(e.getMonth()+1)}-${lh(e.getDate())}T${lh(e.getHours())}:${lh(e.getMinutes())}`}function dh(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:uh(t)}function fh(e){if(!e)return;let t=new Date(e);return Number.isNaN(t.getTime())?void 0:t.toISOString()}function ph(){let e=new Date;return e.setHours(23,59,0,0),uh(e)}function mh(e){let t=fh(e.due);return{title:e.title.trim(),...e.description.trim()?{description:e.description.trim()}:{},status:e.status,completed:e.status===`completed`,...t?{dueDate:t}:{},...e.priority===``?{}:{priority:Number(e.priority)}}}function hh(){let[e,t]=(0,X.useState)(``),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(`pending`),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(ph()),[u,d]=(0,X.useState)([]),[f,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(!1),g=ah(),_=e.trim().length>0&&!m;async function v(t){h(!0);try{let r=await g.capture(),a=f.trim(),s={schema:uo,schemaVersion:oh,data:mh({title:e,description:n,status:i,priority:o,due:c}),...a?{comment:a}:{},metadata:{features:_p(u),...r?{geo:r}:{}}};return await ts(t,[s])}finally{h(!1)}}return{title:e,setTitle:t,description:n,setDescription:r,status:i,setStatus:a,priority:o,setPriority:s,due:c,setDue:l,tags:u,setTags:d,comment:f,setComment:p,saving:m,canSave:_,save:v,geotag:g}}function gh(e){return e.data||{}}var _h={pending:`bg-muted text-muted-foreground`,"in-progress":`bg-info/15 text-info dark:text-info`,completed:`bg-success/15 text-success dark:text-success`,cancelled:`bg-muted text-muted-foreground line-through`};function vh(e){if(!e.dueDate||e.status===`completed`||e.status===`cancelled`)return!1;let t=new Date(e.dueDate).getTime();return Number.isFinite(t)&&t<Date.now()}function yh(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}async function bh(e,t,n){let r=n===`completed`,i={...t.data||{},status:n,completed:r};r?i.completedAt=new Date().toISOString():delete i.completedAt,await Ui(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:i}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}function xh({document:e,workspaceId:t,className:n=``}){let r=gh(e),i=Eo()!=null,[a,o]=(0,X.useState)(!1),{replicating:s,label:c}=ea(e),l=r.status===`completed`,u=r.status??`pending`,d=vh(r);return(0,Z.jsx)(`div`,{className:`space-y-3 ${n}`,children:(0,Z.jsxs)(`div`,{className:`relative flex items-start gap-3 rounded-lg border bg-card p-3 transition-opacity ${s?`opacity-60`:``}`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(i||a)){o(!0);try{await bh(t,e,l?`pending`:`completed`)}catch{}finally{o(!1)}}},disabled:i||a||s,"aria-pressed":l,title:l?`Mark not done`:`Mark done`,className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors ${l?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${i?`cursor-default opacity-70`:``}`,children:a?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):l&&(0,Z.jsx)($e,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`font-medium leading-tight ${l?`text-muted-foreground line-through`:``}`,children:r.title||`Todo ${e.id}`}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[(0,Z.jsx)(`span`,{className:`rounded-full px-2 py-0.5 ${_h[u]}`,children:ch[u]}),r.dueDate&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 ${d?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,Z.jsx)(pe,{className:`h-3 w-3`}),yh(r.dueDate),d?` · overdue`:``]}),typeof r.priority==`number`&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Z.jsx)(bn,{className:`h-3 w-3`}),`P`,r.priority]})]}),r.description&&(0,Z.jsx)(qm,{content:String(r.description),className:`mt-2 text-sm text-muted-foreground`}),s&&(0,Z.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-1.5 text-xs text-muted-foreground`,role:`status`,children:[(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}),c]})]})]})})}function Sh(e){return e?typeof e==`string`?e:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||``:``}function Ch(e){return e?(Array.isArray(e)?e:[e]).map(e=>Sh(e)).filter(Boolean).join(`, `):``}function wh(e){if(!Number.isFinite(e))return``;let t=Number(e);return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function Th(e,t,n){let r=0;Ss.addHook(`afterSanitizeAttributes`,e=>{if(e.tagName===`IMG`){let i=e.getAttribute(`src`)||``,a=i.toLowerCase();if(a.startsWith(`cid:`)){let n=i.slice(4).replace(/^<|>$/g,``),r=t.get(n)||t.get(`<${n}>`);r?e.setAttribute(`src`,r):e.removeAttribute(`src`)}else(a.startsWith(`http:`)||a.startsWith(`https:`)||a.startsWith(`//`))&&(r++,n?e.setAttribute(`src`,i.replace(/^http:/i,`https:`).replace(/^\/\//,`https://`)):e.removeAttribute(`src`))}e.tagName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});try{let t=Ss.sanitize(e,{FORBID_TAGS:[`script`,`iframe`,`object`,`embed`,`form`,`base`,`link`,`meta`],FORBID_ATTR:[`srcset`]}),i=`<!doctype html><html><head>
|
|
7
7
|
<meta charset="utf-8">
|
|
@@ -15,7 +15,7 @@ Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}
|
|
|
15
15
|
`).trim():``:``}function rw(e){if(!e)return;let t=nw(e),n={...e.api?{api:e.api}:{},...e.provider?{provider:e.provider}:{},...e.model?{model:e.model}:{},...e.stopReason?{stopReason:e.stopReason}:{},...e.timestamp===void 0?{}:{timestamp:e.timestamp},...e.responseId?{responseId:e.responseId}:{},...e.usage?{usage:e.usage}:{},...e.metadata?.toolCalls?{toolCalls:e.metadata.toolCalls}:{},...t?{reasoning:t}:{}};return Object.keys(n).length>0?n:void 0}function iw(e){if(typeof e==`number`)return new Date(e).toISOString();if(typeof e==`string`){let t=new Date(e);if(!Number.isNaN(t.getTime()))return t.toISOString()}return new Date().toISOString()}function aw(e=[]){return e.filter(e=>e?.role===`user`||e?.role===`assistant`).map(e=>({role:e.role,content:tw(e),timestamp:iw(e.timestamp),...e.role===`assistant`?{metadata:rw(e)}:{}})).filter(e=>e.content||e.metadata?.reasoning)}function ow(e){return{mode:e?.mode,sessionId:e?.sessionId,sessionFile:e?.sessionFile,thinkingLevel:e?.thinkingLevel,model:e?.model,messages:aw(e?.messages||[])}}function sw(e){return{current:ow(e?.current),sessions:e?.sessions}}new class{connectors=new Map;wsService=null;messageCallbacks=new Map;constructor(){this.initializeWebSocketFallback()}async initializeWebSocketFallback(){try{let e=`${window.location.protocol===`https:`?`wss:`:`ws:`}//${window.location.host}/ws`;this.wsService=new ew(e)}catch(e){console.warn(`WebSocket fallback not available:`,e)}}registerAgent(e){if(e.type===`anthropic`){let t=new $C(e.apiKey||``,e.endpoint||`${ti}/agents/${e.id}`);this.connectors.set(e.id,t)}}async sendMessage(e,t,n={}){let{onMessage:r,onError:i,onComplete:a,useWebSocketFallback:o=!1}=n,s=`msg_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;r&&this.messageCallbacks.set(s,r);try{if(o&&this.wsService){await this.sendMessageViaWebSocket(e,s,t,r,i),a&&a();return}let n=this.connectors.get(e);n?await n.chatStream(t,{agentId:e,messageId:s,onMessage:e=>{let t={id:e.messageId,agentId:e.agentId,content:e.content||``,timestamp:new Date,type:`agent`,streaming:!e.done,error:e.error};r&&r(t)},onError:n=>{if(console.error(`Agent connector error:`,n),n.message.includes(`getReader is not a function`)&&this.wsService){console.log(`Falling back to WebSocket streaming...`),this.sendMessageViaWebSocket(e,s,t,r,i);return}i&&i(n)},onComplete:a}):await this.sendMessageViaAPI(e,s,t,r,i,a)}catch(e){console.error(`Agent communication error:`,e),i&&i(e instanceof Error?e:Error(String(e)))}finally{this.messageCallbacks.delete(s)}}async sendMessageViaAPI(e,t,n,r,i,a){try{await Y.stream(`${ti}/agents/${e}/chat/stream`,{message:n,messageId:t},{onChunk:n=>{try{let i=JSON.parse(n),a={id:t,agentId:e,content:i.content||n,timestamp:new Date,type:`agent`,streaming:!i.done,error:i.error};r&&r(a)}catch{r&&r({id:t,agentId:e,content:n,timestamp:new Date,type:`agent`,streaming:!0})}},onError:e=>{console.error(`API streaming error:`,e),i&&i(e)},onComplete:a})}catch(e){i&&i(e instanceof Error?e:Error(String(e)))}}async sendMessageViaWebSocket(e,t,n,r,i){if(!this.wsService){i&&i(Error(`WebSocket service not available`));return}try{this.wsService.socket?.readyState!==WebSocket.OPEN&&await this.wsService.connect(),this.wsService.startChatStream(e,t,n,e=>{let t={id:e.messageId,agentId:e.agentId,content:e.content||``,timestamp:new Date,type:`agent`,streaming:!e.done,error:e.error};r&&r(t)},i)}catch(e){i&&i(e instanceof Error?e:Error(String(e)))}}async getAvailableAgents(){try{return(await Y.get(`${ti}/agents`)).agents||[]}catch(e){return console.error(`Failed to fetch available agents:`,e),[]}}async createAgent(e){let t=await Y.post(`${ti}/agents`,e);return this.registerAgent(t),t}dispose(){this.connectors.clear(),this.messageCallbacks.clear(),this.wsService&&this.wsService.disconnect()}};async function cw(e){return await Y.get(`${ti}/agents/${e}/access`)||null}async function lw(e,t){return await Y.put(`${ti}/agents/${e}/access`,t)}async function uw(e){return await Y.post(`${ti}/agents/${e}/access/token`)}async function dw(e){await Y.delete(`${ti}/agents/${e}/access`)}async function fw(e){return await Y.get(`${ti}/agents/${e}/tools`)||{tools:[],config:{}}}async function pw(){try{return await Y.get(`${ti}/agents`)||[]}catch(e){return console.error(`Failed to list agents:`,e),[]}}async function mw(e){return await Y.get(`${ti}/agents/${e}`)}async function hw(e){return ow(await Y.get(`${ti}/agents/${e}/session`))}async function gw(e){return await Y.get(`${ti}/agents/${e}/sessions`)}async function _w(e,t){return sw(await Y.post(`${ti}/agents/${e}/sessions`,t))}async function vw(e,t){return sw(await Y.put(`${ti}/agents/${e}/session`,t))}async function yw(e,t,n){return sw(await Y.patch(`${ti}/agents/${e}/sessions/${t}`,n))}async function bw(e,t){return sw(await Y.delete(`${ti}/agents/${e}/sessions/${t}`))}async function xw(e){return await Y.get(`${ti}/agents/${e}/skills`)||[]}async function Sw(e,t){return await Y.post(`${ti}/agents/${e}/skills`,t)||[]}async function Cw(e,t){return await Y.delete(`${ti}/agents/${e}/skills/${encodeURIComponent(t)}`)||[]}async function ww(e){return await Y.post(`${ti}/agents`,e)}async function Tw(e,t){return await Y.put(`${ti}/agents/${e}`,t)}async function Ew(e){await Y.delete(`${ti}/agents/${e}`)}async function Dw(e){return await Y.post(`${ti}/agents/${e}/start`)}async function Ow(e){return await Y.post(`${ti}/agents/${e}/stop`)}async function kw(e){return await Y.get(`${ti}/agents/${e}/status`)}async function Aw(e,t,n={}){let{onStart:r,onMessage:i,onError:a,onComplete:o,context:s,mcpContext:c,maxTokens:l,temperature:u,images:d}=n,f=``;await Y.stream(`${ti}/agents/${e}/prompt/stream`,{message:t,images:d,context:s,mcpContext:c,maxTokens:l,temperature:u},{onOpen:()=>{r?.()},onChunk:e=>{f+=e;let t=f.split(`
|
|
16
16
|
|
|
17
17
|
`);f=t.pop()||``;for(let e of t){let t=e.split(`
|
|
18
|
-
`).map(e=>e.trim()).filter(Boolean);for(let e of t){if(!e.startsWith(`data: `))continue;let t=e.slice(6).trim();if(t!==`[DONE]`)try{let e=JSON.parse(t);if(!i)continue;if(e.type===`chunk`)i(e.delta||``,!1,e.metadata||{});else if(e.type===`thinking`)i(``,!1,{...e.metadata||{},reasoningDelta:e.delta||``});else if(e.type===`complete`){let t=Array.isArray(e.messages)?[...e.messages].reverse().find(e=>e?.role===`assistant`):null;i(``,!0,{...e.metadata||{},...rw(t)||{}})}else e.type===`error`&&a&&a(Error(e.error||`Prompt stream failed`))}catch{}}}},onError:a,onComplete:o})}async function jw(e,t){let{message:n,onMessage:r,onError:i,onComplete:a,context:o,mcpContext:s,maxTokens:c,temperature:l,images:u}=t;try{let t=await Y.post(`${ti}/agents/${e}/prompt`,{message:n,images:u,context:o,mcpContext:s,maxTokens:c,temperature:l}),i=Array.isArray(t.messages)?[...t.messages].reverse().find(e=>e?.role===`assistant`):null,d={content:tw(i),metadata:rw(i)};return r&&r(d.content,!0,d.metadata),a&&a(),d}catch(e){throw i&&i(e),e}}function Mw(e){return e.map(e=>({...e,timestamp:typeof e.timestamp==`string`?e.timestamp:new Date().toISOString()}))}async function Nw(){return await Y.get(`${ti}/voice/status`)}async function Pw(e,t,n={}){let r=new FormData,i=(t.type.split(`/`)[1]||`webm`).split(`;`)[0];r.append(`file`,t,`voice.${i}`);let a=new URLSearchParams;n.tts===!1&&a.set(`tts`,`false`),n.voice&&a.set(`voice`,n.voice);let o=a.toString()?`?${a.toString()}`:``;return await Y.post(`${ti}/agents/${e}/voice${o}`,r)}var Fw=[{id:`workspace`,label:`Workspace`,path:`workspaces`,description:`Files, search, devices and sharing for one workspace. These settings override account defaults.`,sections:GC,load:async()=>(await Pr()).map(e=>({id:e.name,label:e.label||e.name}))},{id:`context`,label:`Context`,path:`contexts`,description:`Choose the tree and path a context opens, and who can access that view. File storage belongs to its workspace.`,sections:JC,load:async()=>(await Yo()).map(e=>({id:e.id,label:e.name||e.id}))},{id:`agent`,label:`Agent`,path:`agents`,description:`Configure one assistant: its instructions, chat model, tools and access to Canvas.`,sections:XC,load:async()=>(await pw()).map(e=>({id:e.id,label:e.label||e.name}))}];function Iw({to:e,label:t,description:n,icon:r}){return(0,Z.jsxs)(mu,{to:e,className:`group flex items-start gap-3 rounded-lg border bg-card p-4 transition-colors hover:border-primary/50 hover:bg-accent/30 focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary`,children:[(0,Z.jsx)(r,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm font-semibold`,children:t}),(0,Z.jsx)(`span`,{className:`mt-1 block text-sm leading-relaxed text-muted-foreground`,children:n})]}),(0,Z.jsx)(qn,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground group-hover:text-primary`})]})}function Lw({group:e,query:t}){let[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(`loading`),[c,l]=(0,X.useState)(0);(0,X.useEffect)(()=>{let t=!1;return e.load().then(e=>{t||(r(e),s(`ready`))}).catch(()=>{t||s(`error`)}),()=>{t=!0}},[e,c]);let u=e.sections.filter(n=>jb(t,e.label,n.label,n.description));return u.length?(0,Z.jsxs)(`section`,{id:e.id,className:`scroll-mt-6 space-y-3`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,Z.jsxs)(`label`,{className:`block max-w-md text-sm font-medium`,children:[`Choose a `,e.label.toLowerCase(),(0,Z.jsxs)(`select`,{className:`mt-2 h-10 w-full rounded-md border bg-background px-3 text-sm`,value:i,disabled:o!==`ready`||!n.length,onChange:e=>a(e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:o===`loading`?`Loading…`:o===`error`?`Unable to load list`:n.length?`Select ${e.label.toLowerCase()}…`:`No ${e.path} available`}),n.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),o===`error`&&(0,Z.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[`The list could not be loaded. `,(0,Z.jsx)(`button`,{type:`button`,className:`underline`,onClick:()=>{s(`loading`),l(e=>e+1)},children:`Retry`})]}),(0,Z.jsxs)(`details`,{open:!!(i||t.trim()),children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer py-2 text-sm text-muted-foreground`,children:i?`Settings for ${n.find(e=>e.id===i)?.label||i}`:`What you can configure (${u.length})`}),(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:u.map(t=>i?(0,Z.jsx)(Iw,{to:`/${e.path}/${encodeURIComponent(i)}/settings/${t.id}`,...t},t.id):(0,Z.jsxs)(`div`,{className:`rounded-lg border border-dashed p-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:t.label}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:t.description})]},t.id))})]})]}):null}function Rw(){let{state:e}=$b(),[t,n]=(0,X.useState)(``),r=kb.filter(t=>t.id!==`server`||e.user?.userType===`admin`).map(e=>({...e,items:e.items.filter(n=>jb(t,e.label,n.label,n.description))})).filter(e=>e.items.length),i=Fw.some(e=>e.sections.some(n=>jb(t,e.label,n.label,n.description)));return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-6xl space-y-8 pb-8 max-md:pb-rail-stack`,children:[(0,Z.jsx)(pb,{title:`Settings`,description:`Start with what you want to change. Each section explains where your changes apply.`}),(0,Z.jsx)(q,{type:`search`,className:`max-w-xl`,"aria-label":`Search all settings`,placeholder:`Find a setting: offline, folders, models, sharing…`,value:t,onChange:e=>n(e.target.value)}),r.filter(e=>e.id===`device`||e.id===`account`).map(e=>(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:e.items.map(e=>(0,Z.jsx)(Iw,{to:e.path,...e},e.path))})]},e.id)),Fw.map(e=>(0,Z.jsx)(Lw,{group:e,query:t},e.id)),r.filter(e=>e.id===`server`||e.id===`information`).map(e=>(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:e.items.map(e=>(0,Z.jsx)(Iw,{to:e.path,...e},e.path))})]},e.id)),!r.length&&!i&&(0,Z.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[`No settings match “`,t,`”. Try a shorter phrase or clear the search.`]})]})}var zw=[{id:`canvas_1`,title:`Canvas Deep`,scheme:`dark`,background:`#032940`,accent:`#f2f2f2`,sources:[{type:`image/svg+xml`,src:`files/canvas_1.svg`},{type:`image/avif`,src:`files/canvas_1.avif`},{type:`image/webp`,src:`files/canvas_1.webp`}],thumb:`thumbs/canvas_1.webp`,author:`Canvas`,license:`LicenseRef-Canvas-Brand`},{id:`canvas_3`,title:`Canvas Mono Dark`,scheme:`dark`,background:`#000000`,accent:`#ffffff`,sources:[{type:`image/svg+xml`,src:`files/canvas_3.svg`},{type:`image/avif`,src:`files/canvas_3.avif`},{type:`image/webp`,src:`files/canvas_3.webp`}],thumb:`thumbs/canvas_3.webp`,author:`Canvas`,license:`LicenseRef-Canvas-Brand`},{id:`w1`,title:`Frost`,scheme:`dark`,background:`#164a6f`,accent:`#9ad9f0`,sources:[{type:`image/avif`,src:`files/w1.avif`},{type:`image/webp`,src:`files/w1.webp`},{type:`image/jpeg`,src:`files/w1.jpg`}],thumb:`thumbs/w1.webp`,author:`Peter Cui Bide`,source:`https://petercui.deviantart.com`,license:`LicenseRef-Attribution-Only`}],Bw=`/wallpapers`;function Vw(e){return zw.find(t=>t.id===e)}function Hw(e,t={}){let n=typeof e==`string`?Vw(e):e;if(!n)return null;let{base:r=Bw,types:i}=t,a=(i?n.sources.find(e=>i.includes(e.type)):n.sources[0])??n.sources[n.sources.length-1];return`${r.replace(/\/$/,``)}/${a.src}`}function Uw(e,t=Bw){let n=typeof e==`string`?Vw(e):e;return n?`${t.replace(/\/$/,``)}/${n.thumb}`:null}var Ww=[{id:`cover`,label:`Scale and Crop`,description:`Fills the screen, cropping edges as needed`},{id:`fill`,label:`Fill`,description:`Stretches to the exact screen size`},{id:`center`,label:`Centered`,description:`Original size, centered on the desk`}],Gw=`canvas:wallpaper`,Kw=`builtin:`,qw=zw;function Jw(e){return Uw(e)??``}function Yw(e){return`${Kw}${e}`}function Xw(e){return e?.startsWith(Kw)?e.slice(8):null}function Zw(){try{let e=localStorage.getItem(Gw);if(e){let t=JSON.parse(e);if(typeof t.image==`string`||t.image===null){let e=t.fit===`fill`||t.fit===`center`?t.fit:`cover`;return{image:t.image??null,fit:e}}}}catch{}return{image:null,fit:`cover`}}function Qw(e){localStorage.setItem(Gw,JSON.stringify(e)),nT(e)}var $w=typeof CSS<`u`&&CSS.supports(`background-image`,`image-set(url("a.avif") type("image/avif"))`);function eT(e){if(!e)return null;let t=Xw(e);if(t===null)return`url("${e}")`;let n=Vw(t);if(!n)return null;let r=`url("${Hw(n,{types:[n.sources[n.sources.length-1].type]})}")`;return!$w||n.sources.length===1?r:`image-set(${n.sources.map(e=>`url("${Hw(n,{types:[e.type]})}") type("${e.type}")`).join(`, `)})`}function tT(e){return e===`fill`?`100% 100%`:e===`center`?`auto`:`cover`}function nT(e=Zw()){let t=document.documentElement.style,n=eT(e.image);if(!n){t.removeProperty(`--wallpaper-image`),t.removeProperty(`--wallpaper-size`);return}t.setProperty(`--wallpaper-image`,n),t.setProperty(`--wallpaper-size`,tT(e.fit))}var rT=[{id:`cards`,name:`Cards`,description:`Nested cards with connector lines. Each level indents.`},{id:`accordion-mobile`,name:`Accordion on phones (beta)`,description:`Experimental. Full-width accordion rows on a phone, cards on wider screens.`},{id:`accordion`,name:`Accordion (beta)`,description:`Experimental. Full-width rows at every depth; a depth rail, tint and colour swatch replace the indent, and open parents stick to the top while you scroll.`}],iT=`canvas:treeStyle`;function aT(){try{let e=localStorage.getItem(iT);return e===`accordion`||e===`accordion-mobile`?e:`cards`}catch{return`cards`}}var oT=aT(),sT=new Set;function cT(){return oT}function lT(e){try{e===`cards`?localStorage.removeItem(iT):localStorage.setItem(iT,e)}catch{}oT=e;for(let e of sT)e()}function uT(e){sT.add(e);let t=t=>{(t.key===iT||t.key===null)&&(oT=aT(),e())};return window.addEventListener(`storage`,t),()=>{sT.delete(e),window.removeEventListener(`storage`,t)}}function dT(){return(0,X.useSyncExternalStore)(uT,cT,()=>`cards`)}function fT(){let e=dT(),t=Am();return e===`accordion`||e===`accordion-mobile`&&t}var pT=[{id:`canvas`,name:`Canvas`,description:`Black and white with a teal accent. Sheets of paper on a grey desk.`,swatches:[`oklch(1 0 0)`,`oklch(0 0 0)`,`oklch(0.704 0.135 183)`]},{id:`nord`,name:`Nord`,description:`Cool arctic blues, lower contrast, softer corners.`,swatches:[`oklch(0.976 0.006 251)`,`oklch(0.588 0.056 244)`,`oklch(0.686 0.062 213)`]},{id:`contrast`,name:`High Contrast`,description:`WCAG AAA text contrast, square corners, hard borders, no shadows.`,swatches:[`oklch(1 0 0)`,`oklch(0 0 0)`,`oklch(0.32 0.16 258)`]},{id:`frost`,name:`Frosted Glass`,description:`Translucent, blurred surfaces over a soft backdrop. Best with a wallpaper.`,swatches:[`oklch(0.92 0.008 250)`,`oklch(0.31 0.025 255)`,`oklch(0.55 0.05 250)`]},{id:`terminal`,name:`Terminal`,description:`Monospaced and dense. Tighter rows and chrome for large displays.`,swatches:[`oklch(0.17 0.006 152)`,`oklch(0.8 0.19 148)`,`oklch(0.75 0.12 220)`]},{id:`halflife`,name:`Half-Life`,description:`Lambda orange on black steel. Square corners; the left rail is orange.`,swatches:[`oklch(0.724 0.181 52)`,`oklch(0 0 0)`,`oklch(1 0 0)`]}],mT=pT.map(e=>e.id),hT=[{id:`system`,name:`System`},{id:`light`,name:`Light`},{id:`dark`,name:`Dark`}],gT=[{id:`auto`,name:`Auto`,description:`Match the pointer: touch on phones, mouse on desktop`},{id:`compact`,name:`Compact`,description:`Maximum rows per screen`},{id:`comfortable`,name:`Comfortable`,description:`Balanced for mouse use`},{id:`touch`,name:`Touch`,description:`Large targets for finger input`}],_T={theme:`canvas`,scheme:`light`,density:`auto`},vT=`canvas.ui.theme`;function yT(e){return typeof e==`string`&&mT.includes(e)}function bT(e){return e===`light`||e===`dark`||e===`system`}function xT(e){return e===`auto`||e===`compact`||e===`comfortable`||e===`touch`}function ST(e){let t=typeof e==`object`&&e?e:{};return{theme:yT(t.theme)?t.theme:_T.theme,scheme:bT(t.scheme)?t.scheme:_T.scheme,density:xT(t.density)?t.density:_T.density}}var CT=`(prefers-color-scheme: dark)`;function wT(){return typeof document<`u`}function TT(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(CT).matches}function ET(e){return e===`system`?TT()?`dark`:`light`:e}function DT(e){if(typeof window>`u`||typeof window.matchMedia!=`function`)return()=>{};let t=window.matchMedia(CT),n=t=>e(t.matches?`dark`:`light`);return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)}function OT(e){return DT(e)}function kT(){return TT()?`dark`:`light`}function AT(){return`light`}function jT(e){let t=getComputedStyle(e).getPropertyValue(`--background`).trim();if(!t)return;let n=document.querySelector(`meta[name="theme-color"]`);n||(n=document.createElement(`meta`),n.name=`theme-color`,document.head.appendChild(n)),n.content=t}function MT(e,t=wT()?document.documentElement:void 0){let n=ET(e.scheme);return t?(t.dataset.theme=e.theme,t.dataset.scheme=n,t.dataset.density=e.density,jT(t),n):n}function NT(e,t=wT()?document.documentElement:void 0){if(!t||typeof window>`u`)return MT(e,t);let n=document.createElement(`style`);n.appendChild(document.createTextNode(`*,*::before,*::after{transition:none!important;animation:none!important}`)),document.head.appendChild(n);let r=MT(e,t);return window.getComputedStyle(n).opacity,document.head.removeChild(n),r}function PT(e){let t=e??LT();if(!t)return _T;try{let e=t.getItem(vT);return e?ST(JSON.parse(e)):_T}catch{return _T}}function FT(e,t){let n=t??LT();if(n)try{n.setItem(vT,JSON.stringify(e))}catch{}}function IT(e){let t=e??LT();if(t)try{t.removeItem(vT)}catch{}}function LT(){try{return typeof localStorage<`u`?localStorage:void 0}catch{return}}function RT({children:e,initial:t,storage:n,persist:r=!0}){let[i,a]=(0,X.useState)(()=>({...PT(n),...t})),o=(0,X.useSyncExternalStore)(OT,kT,AT),s=i.scheme===`system`?o:i.scheme;(0,X.useEffect)(()=>{NT({...i,scheme:s})},[i,s]),(0,X.useEffect)(()=>{r&&FT(i,n)},[i,r,n]);let c=(0,X.useCallback)(e=>{a(t=>t.theme===e?t:{...t,theme:e})},[]),l=(0,X.useCallback)(e=>{a(t=>t.scheme===e?t:{...t,scheme:e})},[]),u=(0,X.useCallback)(e=>{a(t=>t.density===e?t:{...t,density:e})},[]),d=(0,X.useCallback)(()=>{a(e=>({...e,scheme:(e.scheme===`system`?kT():e.scheme)===`dark`?`light`:`dark`}))},[]),f=(0,X.useCallback)(()=>{IT(n),a(_T)},[n]),p=(0,X.useMemo)(()=>({...i,resolvedScheme:s,setTheme:c,setScheme:l,setDensity:u,toggleScheme:d,reset:f}),[i,s,c,l,u,d,f]);return(0,Z.jsx)(Cs.Provider,{value:p,children:e})}var zT={system:me,light:Gn,dark:Pn};function BT(){let{theme:e,scheme:t,density:n,resolvedScheme:r,setTheme:i,setScheme:a,setDensity:o,reset:s}=ws(),c=sm(),l=Vb(),u=dT(),d=Xb();return(0,Z.jsxs)(`div`,{className:`space-y-8`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Theme`,description:`Palette, shape and typography. Each theme defines its own light and dark variants.`}),(0,Z.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:pT.map(t=>{let n=t.id===e;return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>i(t.id),"aria-pressed":n,className:K(`focus-ring group flex flex-col gap-3 rounded-lg border p-4 text-left transition-colors`,n?`border-primary bg-accent`:`border-border hover:border-muted-foreground/40 hover:bg-accent/50`),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t.name}),n&&(0,Z.jsx)($e,{className:`size-4 shrink-0 text-primary`})]}),(0,Z.jsx)(`div`,{className:`flex gap-1.5`,"aria-hidden":!0,children:t.swatches.map(e=>(0,Z.jsx)(`span`,{className:`size-6 rounded-full border border-border`,style:{backgroundColor:e}},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]},t.id)})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Colour scheme`,description:t===`system`?`Following your system setting, currently ${r}.`:`Overrides your system setting.`}),(0,Z.jsx)(GT,{options:hT.map(e=>{let t=zT[e.id];return{id:e.id,label:e.name,icon:(0,Z.jsx)(t,{className:`size-4 shrink-0`})}}),value:t,onChange:a})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Density`,description:`Controls row height, hit-target size and shell spacing across the whole app.`}),(0,Z.jsx)(GT,{options:gT.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:o}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:gT.find(e=>e.id===n)?.description})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Layout`,description:`How menus and content share the screen. Device-local, like the wallpaper.`}),(0,Z.jsx)(GT,{options:Mb.map(e=>({id:e.id,label:e.name,title:e.description})),value:l,onChange:zb}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:Mb.find(e=>e.id===l)?.description}),l===`strip`&&(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Navigation keys`}),(0,Z.jsx)(GT,{options:Hb.map(e=>({id:e.id,label:e.name,title:e.description})),value:d,onChange:Jb}),(0,Z.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[Hb.find(e=>e.id===d)?.description,` `,`Left and right walk the columns, up and down switch pin rows.`]})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Tree style`,description:`How workspace and context trees are drawn in the menu. Device-local.`}),(0,Z.jsx)(GT,{options:rT.map(e=>({id:e.id,label:e.name,title:e.description})),value:u,onChange:lT}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:rT.find(e=>e.id===u)?.description})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Open documents`,description:`Choose how documents open from lists, tiles and boards. Saved on this device.`}),(0,Z.jsx)(GT,{options:[{id:`modal`,label:`Modal`},{id:`side`,label:`Side reading pane`}],value:c,onChange:am}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`The reading pane opens beside the content and updates as you select another document. On small screens it opens as a drawer.`})]}),(0,Z.jsx)(VT,{}),(0,Z.jsx)(`section`,{children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{s(),am(`modal`)},className:`focus-ring rounded-md text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline`,children:`Reset to defaults`})})]})}function VT(){let[e,t]=(0,X.useState)(Zw),[n,r]=(0,X.useState)(null),i=e=>{try{Qw(e),t(e),r(null)}catch{r(`Could not store the wallpaper (browser storage full?). Try a smaller image.`)}},a=t=>{if(!t)return;if(!t.type.startsWith(`image/`)){r(`Pick an image file.`);return}let n=new FileReader;n.onload=()=>{let t=String(n.result||``);if(t.length>3670016){r(`Image too large for browser storage. Use one under ~2.5 MB.`);return}i({...e,image:t})},n.readAsDataURL(t)},o=e.image!==null&&Xw(e.image)===null,s=eT(e.image);return(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Wallpaper`,description:`Background image for the desk behind all panels. Without one, the theme's desk color shows (the default).`}),(0,Z.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Wallpaper`,className:`grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6`,children:[(0,Z.jsx)(UT,{label:`None`,isActive:e.image===null,onSelect:()=>i({...e,image:null}),children:(0,Z.jsx)(`span`,{className:`flex size-full items-center justify-center surface-desk text-xs text-muted-foreground`,style:{backgroundImage:`none`},children:`None`})}),qw.map(t=>(0,Z.jsx)(UT,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:Xw(e.image)===t.id,onSelect:()=>i({...e,image:Yw(t.id)}),children:(0,Z.jsx)(`img`,{src:Jw(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),o&&(0,Z.jsx)(UT,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,Z.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,Z.jsx)(HT,{}),(0,Z.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:s?{backgroundImage:s,backgroundSize:tT(e.fit),backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,"aria-hidden":!0}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(`label`,{className:`focus-ring inline-flex cursor-pointer items-center rounded-md border px-3 py-1.5 text-sm hover:bg-accent/50`,children:[o?`Change image…`:`Use your own image…`,(0,Z.jsx)(`input`,{type:`file`,accept:`image/*`,className:`hidden`,onChange:e=>{a(e.target.files?.[0]),e.target.value=``}})]}),e.image&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>i({...e,image:null}),className:`focus-ring rounded-md border px-3 py-1.5 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:`Remove`})]}),(0,Z.jsx)(GT,{options:Ww.map(e=>({id:e.id,label:e.label,title:e.description})),value:e.fit,onChange:t=>i({...e,fit:t})}),n&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:n})]})]})]})}function HT(){let e=qw.filter(e=>e.author!==`Canvas`);return e.length===0?null:(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.map((e,t)=>(0,Z.jsxs)(`span`,{children:[t>0&&` · `,e.title,` © `,e.author,e.source&&(0,Z.jsxs)(Z.Fragment,{children:[` `,(0,Z.jsx)(`a`,{href:e.source,target:`_blank`,rel:`noreferrer noopener`,className:`focus-ring underline underline-offset-2 hover:text-foreground`,children:new URL(e.source).hostname})]})]},e.id))})}function UT({label:e,title:t,isActive:n,onSelect:r,children:i}){return(0,Z.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e,title:t??e,onClick:r,className:K(`focus-ring group relative aspect-video overflow-hidden rounded-md border transition-colors`,n?`border-primary ring-1 ring-primary`:`border-border hover:border-muted-foreground/40`),children:[i,n&&(0,Z.jsx)(`span`,{className:`absolute right-1 top-1 rounded-full bg-primary p-0.5 text-primary-foreground`,children:(0,Z.jsx)($e,{className:`size-3`})})]})}function WT({title:e,description:t}){return(0,Z.jsxs)(`div`,{className:`mb-3`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function GT({options:e,value:t,onChange:n}){return(0,Z.jsx)(`div`,{role:`radiogroup`,className:`inline-flex flex-wrap gap-1 rounded-lg bg-muted p-1`,children:e.map(e=>{let r=e.id===t;return(0,Z.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:e.title,onClick:()=>n(e.id),className:K(`focus-ring flex h-control items-center gap-2 rounded-md px-3 text-sm transition-colors`,r?`bg-card text-foreground shadow-elevation-1`:`text-muted-foreground hover:text-foreground`),children:[e.icon,e.label]},e.id)})})}function KT(){return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`Appearance`,onBack:FC(),description:`Theme, colour scheme and density. Changes apply immediately and are remembered on this device.`}),(0,Z.jsx)(BT,{})]})}var qT={previousTree:`Alt+Q`,nextTree:`Alt+W`},JT=`canvas:key-bindings`,YT=/^(Alt|Alt\+Shift|Ctrl\+Shift|Meta\+Shift)\+[A-Z]$/;function XT(){try{let e=JSON.parse(localStorage.getItem(JT)||`{}`),t={...qT};for(let n of Object.keys(t))(e[n]===``||YT.test(e[n]))&&(t[n]=e[n]);return t.previousTree&&t.previousTree===t.nextTree?{...qT}:t}catch{return{...qT}}}function ZT(e){localStorage.setItem(JT,JSON.stringify(e))}function QT(e){return/^Key[A-Z]$/.test(e.code)?[e.ctrlKey&&`Ctrl`,e.altKey&&`Alt`,e.metaKey&&`Meta`,e.shiftKey&&`Shift`,e.code.slice(3)].filter(Boolean).join(`+`):``}function $T(e,t,n){return e[(Math.max(0,e.indexOf(t))+n+e.length)%e.length]}function eE(e,t){return Math.abs(e)>=48&&Math.abs(e)>Math.abs(t)*1.5?e<0?1:-1:0}function tE(){let[e,t]=(0,X.useState)(XT),[n,r]=(0,X.useState)(``),i=e=>{if(e.previousTree&&e.previousTree===e.nextTree){r(`Choose a different shortcut: that combination is already assigned.`);return}try{ZT(e),t(e),r(`Saved on this device.`)}catch{r(`Could not save shortcuts in this browser.`)}};return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`Key bindings`,onBack:FC(),description:`Web UI shortcuts, saved on this device and available offline.`}),(0,Z.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,Z.jsx)(`h2`,{className:`font-medium`,children:`Tree navigation`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Cycle the open workspace menu’s tabs in their displayed order, including Pins and Layers. Swipe left for next or right for previous over the tab bar. Shortcuts pause while typing or using a dialog.`}),[`previousTree`,`nextTree`].map(t=>(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`label`,{htmlFor:t,className:`min-w-32 text-sm`,children:t===`previousTree`?`Previous tree`:`Next tree`}),(0,Z.jsxs)(`select`,{id:t,className:`rounded-md border bg-background p-2 text-sm`,value:e[t].split(`+`).slice(0,-1).join(`+`),onChange:n=>i({...e,[t]:n.target.value?`${n.target.value}+${e[t].slice(-1)||qT[t].slice(-1)}`:``}),children:[(0,Z.jsx)(`option`,{value:``,children:`Disabled`}),[`Alt`,`Alt+Shift`,`Ctrl+Shift`,`Meta+Shift`].map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]}),(0,Z.jsx)(`select`,{"aria-label":`${t===`previousTree`?`Previous`:`Next`} tree key`,disabled:!e[t],className:`rounded-md border bg-background p-2 text-sm disabled:opacity-50`,value:e[t].slice(-1)||qT[t].slice(-1),onChange:n=>i({...e,[t]:`${e[t].split(`+`).slice(0,-1).join(`+`)}+${n.target.value}`}),children:`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``).map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})]},t)),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Browsers and operating systems may reserve combinations. Choose another if a shortcut does not reach Canvas. Letters refer to physical keyboard positions (Q/W on a US keyboard); Meta is Command on Mac.`}),(0,Z.jsx)(`button`,{type:`button`,className:`rounded-md border px-3 py-2 text-sm hover:bg-accent`,onClick:()=>i({...qT}),children:`Restore defaults`}),(0,Z.jsx)(`p`,{role:`status`,className:`text-sm`,children:n})]})]})}var nE=`offline-content-v1`,rE=`offline-api-v1`,iE=1073741824,aE={enabled:!1,budgetBytes:4*iE,excludedWorkspaces:[]},oE=1e3;function sE(e){return(e.startsWith(`/`)?e:`/${e}`).replace(/\/+$/,``)||`/`}function cE(e,t,n){return`${e}:${t}:${sE(n)}`}var lE=`canvas-offline`,uE=2,dE=null;function fE(){return dE||(dE=new Promise((e,t)=>{let n=indexedDB.open(lE,uE);n.onupgradeneeded=e=>{let t=n.result;if(t.objectStoreNames.contains(`config`)||t.createObjectStore(`config`),t.objectStoreNames.contains(`entries`)||t.createObjectStore(`entries`,{keyPath:`url`}),e.oldVersion>=1&&t.objectStoreNames.contains(`pins`)){t.deleteObjectStore(`pins`);let e=n.transaction.objectStore(`entries`).openCursor();e.onsuccess=()=>{let t=e.result;if(!t)return;let n=t.value;n.pinned&&t.update({...n,pinned:!1}),t.continue()}}t.objectStoreNames.contains(`scopes`)||t.createObjectStore(`scopes`,{keyPath:`id`})},n.onsuccess=()=>{n.result.onversionchange=()=>{n.result.close(),dE=null},e(n.result)},n.onerror=()=>{dE=null,t(n.error)}}),dE)}function pE(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}function mE(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}async function hE(e,t){return mE((await fE()).transaction(e).objectStore(e).get(t))}async function gE(e){return mE((await fE()).transaction(e).objectStore(e).getAll())}async function _E(e,t,n){let r=(await fE()).transaction(e,`readwrite`);return r.objectStore(e).put(t,n),pE(r)}async function vE(e,t){let n=(await fE()).transaction(e,`readwrite`);return n.objectStore(e).delete(t),pE(n)}async function yE(e){let t=(await fE()).transaction(e,`readwrite`);return t.objectStore(e).clear(),pE(t)}async function bE(){try{let e=await hE(`config`,`settings`);return e?{...aE,...e}:aE}catch{return aE}}async function xE(e){await _E(`config`,e,`settings`)}async function SE(e,t){let n=(await fE()).transaction(`entries`,`readwrite`),r=n.objectStore(`entries`);for(let n of e){let e=r.get(n);e.onsuccess=()=>{let i=e.result;i?r.put({...i,pinned:t}):t&&r.put({url:n,kind:`content`,size:0,lastAccess:Date.now(),pinned:t})}}return pE(n)}async function CE(e){let t=await gE(`entries`),n=t.filter(e=>e.kind===`api`).sort((e,t)=>e.lastAccess-t.lastAccess),r=n.slice(0,Math.max(0,n.length-oE)),i=t.filter(e=>e.kind===`content`),a=i.reduce((e,t)=>e+t.size,0),o=i.filter(e=>!e.pinned).sort((e,t)=>e.lastAccess-t.lastAccess),s=[];for(let t of o){if(a<=e)break;s.push(t),a-=t.size}if(!r.length&&!s.length)return;let[c,l]=await Promise.all([caches.open(rE),caches.open(nE)]);await Promise.all([...r.map(async e=>{await c.delete(e.url),await vE(`entries`,e.url)}),...s.map(async e=>{await l.delete(e.url),await vE(`entries`,e.url)})])}async function wE(){let e=await gE(`entries`),t=e.filter(e=>e.kind===`content`);return{contentBytes:t.reduce((e,t)=>e+t.size,0),contentCount:t.length,pinnedBytes:t.filter(e=>e.pinned).reduce((e,t)=>e+t.size,0),apiCount:e.length-t.length}}async function TE(){await Promise.all([caches.delete(nE),caches.delete(rE)]),await yE(`entries`),await yE(`scopes`)}async function EE(){return gE(`scopes`)}async function DE(e){return hE(`scopes`,e)}async function OE(e){await _E(`scopes`,e)}async function kE(e){let t=await hE(`scopes`,e);await vE(`scopes`,e),t?.urls.length&&await AE(t.urls)}async function AE(e){let t=await gE(`scopes`),n=new Set(t.flatMap(e=>e.urls)),r=e.filter(e=>!n.has(e));r.length&&await SE(r,!1)}var jE=3,ME=`data/schema/file`,NE=128;async function PE({workspaceRef:e,path:t,treeName:n,treeType:r},i){let a=await bE();if(!a.enabled)throw Error(`Enable the offline cache first`);if(a.excludedWorkspaces.includes(e))throw Error(`Workspace "${e}" is excluded from offline caching`);let o=cE(e,n,t),s=sE(t),c=await DE(o),l=((await Ki(e,s,[],{limit:1e4,treeName:n,treeType:r})).payload??[]).filter(e=>e.schema===ME),u=[],d=0,f=0,p=!1,m=l.length;i?.({done:f,total:m,bytes:d});let h=0;await Promise.all(Array.from({length:Math.min(jE,l.length)},async()=>{for(;h<l.length;){let t=l[h++];if(d>=a.budgetBytes*.9){p=!0;return}try{let{blob:n}=await Yr(e,t.id);d+=n.size,u.push(`${Qr.workspaces}/${e}/documents/${t.id}/content`);try{await di(e,t.id,NE),u.push(`${Qr.workspaces}/${e}/documents/${t.id}/thumbnail?size=${NE}`)}catch{}}catch{}f+=1,i?.({done:f,total:m,bytes:d})}})),await SE(u,!0);let g={id:o,workspaceRef:e,treeName:n,treeType:r,path:s,urls:u,bytes:d,warmedAt:Date.now(),...p?{truncated:!0}:{}};if(await OE(g),c){let e=new Set(u),t=c.urls.filter(t=>!e.has(t));t.length&&await AE(t)}return g}var FE=[{label:`1 GB`,bytes:1*iE},{label:`2 GB`,bytes:2*iE},{label:`4 GB`,bytes:4*iE},{label:`8 GB`,bytes:8*iE}];function IE(e){return e<1048576?`${(e/1024).toFixed(0)} KB`:e<1073741824?`${(e/1048576).toFixed(1)} MB`:`${(e/iE).toFixed(2)} GB`}function LE(){navigator.serviceWorker?.controller?.postMessage({type:`OFFLINE_SETTINGS_CHANGED`})}function RE(){let{showSuccessToast:e,showErrorToast:t}=to(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)([]),[u,d]=(0,X.useState)([]),[f,p]=(0,X.useState)({}),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),v=(0,X.useCallback)(()=>{bE().then(r).catch(()=>{}),wE().then(a).catch(()=>{}),EE().then(e=>d(e.sort((e,t)=>e.id.localeCompare(t.id)))).catch(()=>{}),navigator.storage?.persisted?.().then(s).catch(()=>{})},[]);(0,X.useEffect)(()=>{v(),Pr().then(e=>l(e.map(e=>e.name).filter(Boolean).sort())).catch(()=>{})},[v]);let y=async e=>{r(e),await xE(e),LE(),e.enabled&&navigator.storage?.persist?.().then(s).catch(()=>{}),CE(e.budgetBytes).then(v).catch(()=>{})},b=e=>{if(!n)return;let t=n.excludedWorkspaces.includes(e)?n.excludedWorkspaces.filter(t=>t!==e):[...n.excludedWorkspaces,e];y({...n,excludedWorkspaces:t})},x=async()=>{h(!0);try{await TE(),e(`Offline cache cleared`),v()}catch(e){t(e instanceof Error?e.message:`Failed to clear cache`)}finally{h(!1)}},S=async n=>{let r=cE(n.workspaceRef,n.treeName,n.path);p(e=>({...e,[r]:{done:0,total:0,bytes:0}}));try{let t=await PE(n,e=>p(t=>({...t,[r]:e})));e(t.truncated?`Pinned ${IE(t.bytes)} — stopped at the size budget`:`Pinned ${t.workspaceRef}:/${t.path} (${IE(t.bytes)})`)}catch(e){t(e instanceof Error?e.message:`Failed to pin`)}finally{p(e=>{let{[r]:t,...n}=e;return n}),v()}},w=(e,t)=>{_(!1);for(let n of e)S({workspaceRef:t.workspaceName,path:n,treeName:t.treeName,treeType:t.treeType})},T=e=>({workspaceRef:e.workspaceRef,path:e.path,treeName:e.treeName||`context`,treeType:e.treeType||`context`}),E=async e=>{await kE(e),v()};return n?(0,Z.jsxs)(`div`,{className:`space-y-8`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(zE,{title:`Offline cache`,description:`Keep documents you open (and scopes you pin) readable without a connection. Cached on this device only; least-recently-used files are evicted when the size budget fills. Video streaming is not cached.`}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>y({...n,enabled:!n.enabled}),"aria-pressed":n.enabled,className:K(`focus-ring flex items-center gap-3 rounded-lg border p-4 text-left transition-colors`,n.enabled?`border-primary bg-accent`:`border-input hover:bg-muted/40`),children:[(0,Z.jsx)(C,{className:`h-5 w-5 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm font-medium`,children:n.enabled?`Enabled`:`Disabled`}),(0,Z.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.enabled?o===!1?`Storage is not persistent — the browser may still evict the cache under disk pressure`:`Documents are cached as you browse`:`Nothing is cached for offline use`})]}),n.enabled&&(0,Z.jsx)($e,{className:`h-4 w-4 shrink-0 text-primary`})]}),n.enabled&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Size budget`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:FE.map(e=>(0,Z.jsx)(J,{variant:n.budgetBytes===e.bytes?`default`:`outline`,size:`sm`,onClick:()=>y({...n,budgetBytes:e.bytes}),children:e.label},e.bytes))})]}),i&&(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between text-sm`,children:[(0,Z.jsxs)(`span`,{children:[IE(i.contentBytes),` of `,IE(n.budgetBytes),` used`]}),(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[i.contentCount,` file(s)`,i.pinnedBytes>0?`, ${IE(i.pinnedBytes)} pinned`:``]})]}),(0,Z.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${Math.min(100,i.contentBytes/n.budgetBytes*100)}%`}})})]}),(0,Z.jsx)(`div`,{children:(0,Z.jsxs)(J,{variant:`outline`,size:`sm`,onClick:x,disabled:m,children:[m?(0,Z.jsx)(Mt,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(lt,{className:`mr-1.5 h-3.5 w-3.5`}),`Clear offline cache`]})})]})]})]}),n.enabled&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(zE,{title:`Pinned scopes`,description:`A pinned scope — a workspace, or one of its tree paths — is downloaded up front and never evicted. Scopes resolve fresh on every re-warm, so moved contexts and reorganized trees are picked up; documents that left a scope return to normal eviction.`}),(0,Z.jsx)(`div`,{className:`mb-3`,children:(0,Z.jsxs)(J,{size:`sm`,onClick:()=>_(!0),disabled:!!Object.keys(f).length,children:[(0,Z.jsx)(ne,{className:`mr-1.5 h-3.5 w-3.5`}),`Pin a path…`]})}),(0,Z.jsxs)(`ul`,{className:`space-y-1`,children:[u.map(e=>{let t=f[e.id];return(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,Z.jsxs)(`span`,{className:`flex-1 truncate font-mono text-xs sm:text-sm`,children:[e.workspaceRef,`://`,e.path.replace(/^\//,``),e.treeName&&e.treeName!==`context`&&(0,Z.jsx)(`span`,{className:`ml-1.5 rounded bg-muted px-1 py-0.5 font-sans text-[10px] text-muted-foreground`,children:e.treeName})]}),t?(0,Z.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(Mt,{className:`h-3.5 w-3.5 animate-spin`}),t.total>0?`${t.done}/${t.total} · ${IE(t.bytes)}`:`listing…`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[IE(e.bytes),e.truncated?` (partial)`:``]}),(0,Z.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>S(T(e)),"aria-label":`Re-warm ${e.id}`,title:`Re-warm: re-resolve the scope and download anything new`,children:(0,Z.jsx)(Te,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>E(e.id),"aria-label":`Unpin ${e.id}`,children:(0,Z.jsx)(G,{className:`h-3.5 w-3.5`})})]})]},e.id)}),u.length===0&&(0,Z.jsx)(`li`,{className:`rounded-md border border-dashed border-input px-3 py-4 text-center text-sm text-muted-foreground`,children:`Nothing pinned — everything relies on browse-caching and LRU`})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(zE,{title:`Workspace caching`,description:`Excluded workspaces are never cached — not even as you browse — and are not served from cache.`}),(0,Z.jsx)(`ul`,{className:`space-y-1`,children:c.map(e=>{let t=n.excludedWorkspaces.includes(e);return(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,Z.jsx)(`span`,{className:K(`flex-1 truncate`,t&&`text-muted-foreground line-through`),children:e}),t&&(0,Z.jsx)(vt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(J,{variant:t?`outline`:`ghost`,size:`sm`,onClick:()=>b(e),children:t?`Include`:`Exclude`})]},e)})})]})]}),g&&(0,Z.jsx)(pp,{onClose:()=>_(!1),children:(0,Z.jsx)(dp,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`context`,`directory`],title:`Pin for offline…`,confirmLabel:`Pin path`,onConfirm:w,onClose:()=>_(!1)})})]}):null}function zE({title:e,description:t}){return(0,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function BE(){return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`Offline`,onBack:FC(),description:`Per-device offline cache: browse notes, files, photos and saved websites without a connection.`}),(0,Z.jsx)(RE,{})]})}function VE(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function HE({name:e,version:t,detail:n}){return(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 px-4 py-2.5`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e}),n&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n})]}),(0,Z.jsx)(`code`,{className:`text-xs text-muted-foreground shrink-0`,children:t})]})}function UE(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=!0;return Y.get(`/ping`,{skipAuth:!0}).then(n=>{e&&t(n??{})}).catch(t=>{e&&r(t instanceof Error?t.message:`Failed to reach the server`)}),()=>{e=!1}},[]);let i=[e?.commit?`commit ${e.commit.slice(0,7)}`:null,typeof e?.uptime==`number`?`up ${VE(e.uptime)}`:null].filter(Boolean).join(` · `),a=Object.entries(e?.components??{}).sort(([e],[t])=>e.localeCompare(t));return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`About`,onBack:FC(),description:`Versions of every Canvas component this installation is running.`}),(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`section`,{className:`rounded-md border border-border divide-y divide-border`,children:[(0,Z.jsx)(HE,{name:`Canvas Web`,detail:`this interface`,version:`v2.14.17`}),e?.version&&(0,Z.jsx)(HE,{name:e.productName||e.appName||`Canvas Server`,detail:i||void 0,version:`v${e.version}`})]}),a.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Server components`}),(0,Z.jsx)(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:a.map(([e,t])=>(0,Z.jsx)(HE,{name:e,version:`v${t}`},e))})]}),n&&(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Server details unavailable: `,n]}),e?.sourceUrl&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.license?`Licensed ${e.license}. `:``,(0,Z.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})]})]})}var WE=[`onnx`,`clip`,`blip`,`openai`],GE=[`onnx`,`clip`,`blip`,`ollama`,`vllm`],KE=[{id:`openai`,baseUrl:`https://api.openai.com/v1`,label:`OpenAI`},{id:`vllm`,baseUrl:`http://127.0.0.1:8000/v1`,label:`vLLM`},{id:`ollama`,baseUrl:`http://127.0.0.1:11434/v1`,label:`Ollama`}],qE=e=>`${Qr.workspaces}/${encodeURIComponent(e)}/inferd`;function JE(e,t){let n={};for(let[r,i]of Object.entries(e.providers||{})){let e={...i};delete e.apiKeySet,delete e.headerNames,t.has(r)&&i.apiKey?e.apiKey=i.apiKey:delete e.apiKey,n[r]=e}return{...e,providers:n}}async function YE(e){return await Y.get(`${qE(e)}/status`)}async function XE(e,t={}){let n={};return t.force!==void 0&&(n.force=t.force),await Y.post(`${qE(e)}/summarize/images`,n)}async function ZE(e){return await Y.post(`${qE(e)}/summarize/images/stop`,{})}async function QE(e){return await Y.get(`${qE(e)}/config`)}async function $E(e,t){return await Y.put(`${qE(e)}/config`,t)}async function eD(e,t={}){let n={};return t.space&&(n.space=t.space),t.reindex!==void 0&&(n.reindex=t.reindex),t.scope&&(n.scope=t.scope),await Y.post(`${qE(e)}/reindex`,n)}async function tD(e){return await Y.get(`${qE(e)}/vector-tables`)}async function nD(e,t){return await Y.delete(`${qE(e)}/vector-tables/${encodeURIComponent(t)}`)}async function rD(){return await Y.get(`${Qr.inferd}/config`)}async function iD(e){return await Y.put(`${Qr.inferd}/config`,e)}async function aD(){return await Y.get(`${Qr.inferd}/defaults`)}async function oD(e){return await Y.put(`${Qr.inferd}/defaults`,e)}async function sD(e,t){let n={...e};return delete n.apiKeySet,delete n.headerNames,(await Y.post(`${Qr.inferd}/test`,{provider:n,...t?{model:t}:{},probe:!0})).cached??null}async function cD(e,t,n=`text`){let r={...e};return delete r.apiKeySet,delete r.headerNames,await Y.post(`${Qr.inferd}/test`,{provider:r,...t?{model:t}:{},modality:n})}var lD=`h-8 w-full rounded-md border bg-background px-2 text-sm outline-none focus:ring-2 focus:ring-ring`,uD=`font-semibold uppercase tracking-[0.08em]`,dD={openai:{url:{key:`baseUrl`,label:`Base URL`,placeholder:`http://gpu.local:8000/v1`,hint:`OpenAI-compatible embeddings endpoint — Ollama, vLLM, TEI, infinity, LM Studio and OpenAI itself all speak this. A trailing /v1 is optional; both http://host:8000 and http://host:8000/v1 work.`},apiKey:"Sent as `Authorization: Bearer …`. Leave empty for servers that do not check it.",imageInput:!0,timeoutMs:!0,headers:!0,where:e=>e.baseUrl||`no endpoint set`},ollama:{url:{key:`host`,label:`Host (legacy)`,placeholder:`http://127.0.0.1:11434`,hint:`Written by an older version. Switch the type to openai — the host becomes the base URL and the /v1 suffix is added for you.`},apiKey:"Sent as `Authorization: Bearer …`.",where:e=>e.host||`http://127.0.0.1:11434`},onnx:{cacheDir:`Where downloaded weights are cached on the server. Empty uses the server default.`,note:`Runs in-process on the server. No endpoint and no credentials.`,where:()=>`in-process`},clip:{cacheDir:`Where downloaded weights are cached on the server. Empty uses the server default.`,note:`Runs in-process on the server. No endpoint and no credentials.`,where:()=>`in-process`}},fD=[`baseUrl`,`host`,`apiKey`,`cacheDir`,`imageInput`,`timeoutMs`],pD=[{value:`data-uri`,label:`data-uri (default)`,hint:"Images ride in the ordinary `input` array as data URIs (infinity, TEI-style servers)."},{value:`messages`,label:`messages`,hint:`vLLM's multimodal shape: one request per image, wrapped in a chat message.`}],mD=12e4;function hD(e){if(typeof e!=`string`||e.trim()===``)return null;let t;try{t=new URL(e.trim())}catch{return`Must be an absolute URL including the scheme, e.g. http://127.0.0.1:11434`}return t.protocol!==`http:`&&t.protocol!==`https:`?`Unsupported scheme '${t.protocol.replace(`:`,``)}'. Use http or https.`:null}function gD({title:e,hint:t}){return(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(`h3`,{className:K(`text-[11px] text-muted-foreground`,uD),children:e}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:t})]})}function _D({overridden:e,source:t}){return e?(0,Z.jsx)(`span`,{className:`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,title:`Set on this layer; it wins over anything inherited`,children:`overridden`}):(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground`,title:t?`Inherited: ${t}`:`Inherited from a lower config layer`,children:`inherited`})}function vD({label:e,value:t,inheritedValue:n,onChange:r,type:i=`text`,placeholder:a,disabled:o,hint:s,error:c,mono:l}){let u=t!==void 0&&t!==``;return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:e}),(0,Z.jsx)(_D,{overridden:u,source:n===void 0?void 0:String(n)}),u&&!o&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>r(``),className:`text-[10px] text-muted-foreground underline hover:text-foreground`,title:`Clear the override and fall back to the inherited value`,children:`reset`})]}),(0,Z.jsx)(q,{type:i,value:t??``,disabled:o,onChange:e=>r(e.target.value),placeholder:a??(n===void 0?`—`:String(n)),className:K(`h-8 text-sm`,l&&`font-mono`,c&&`border-destructive focus-visible:ring-destructive`)}),c&&(0,Z.jsx)(`p`,{className:`text-[11px] font-medium text-destructive`,children:c}),s&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:s})]})}function yD({label:e,checked:t,overridden:n,disabled:r,onChange:i}){return(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:r,checked:t,onChange:e=>i(e.target.checked)}),e,(0,Z.jsx)(_D,{overridden:n})]})}function bD({storedNames:e,value:t,disabled:n,onChange:r}){let i=t!==void 0,[a,o]=(0,X.useState)([]),s=e=>{o(e),r(Object.fromEntries(e.filter(([e])=>e.trim()!==``)))};return(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Custom headers`}),i?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`rounded bg-warning-subtle px-1.5 py-0.5 text-[10px] font-medium text-warning`,children:`will replace stored`}),!n&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{o([]),r(void 0)},className:`text-[10px] text-muted-foreground underline hover:text-foreground`,children:`cancel`})]}):(0,Z.jsx)(_D,{overridden:!1,source:e?.join(`, `)})]}),!i&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e?.length?(0,Z.jsxs)(Z.Fragment,{children:[`Stored: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.join(`, `)}),` (values are never sent back)`]}):`None set.`}),!n&&(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{o([[``,``]]),r({})},children:e?.length?`Replace headers`:`Add headers`})]}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Saving replaces every stored header, so re-enter the ones you want to keep.`}),a.map(([e,t],r)=>(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(q,{value:e,disabled:n,placeholder:`X-Tenant`,className:`h-8 font-mono text-sm`,onChange:e=>s(a.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,Z.jsx)(q,{value:t,disabled:n,placeholder:`value`,className:`h-8 font-mono text-sm`,onChange:e=>s(a.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,disabled:n,"aria-label":`Remove header ${e||r+1}`,onClick:()=>s(a.filter((e,t)=>t!==r)),children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]},r)),!n&&(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>s([...a,[``,``]]),children:[(0,Z.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),`Add header`]})]})]})}function xD({open:e,onClick:t,label:n}){return(0,Z.jsx)(`button`,{type:`button`,onClick:t,"aria-expanded":e,title:n,"aria-label":n,className:`flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:(0,Z.jsx)(Ge,{className:K(`h-4 w-4 transition-transform motion-reduce:transition-none`,e&&`rotate-180`)})})}var SD={configured:`bg-success`,"needs-fill":`bg-warning`,unresolved:`bg-destructive`,unset:`bg-muted-foreground/30`};function CD({value:e,effective:t,inherited:n,resolvedSpaces:r,invalid:i,attention:a,onFill:o,saving:s=!1,disabled:c=!1,saveLabel:l=`Save`,onSave:u}){let{showToast:d}=po(),[f,p]=(0,X.useState)(()=>structuredClone(e)),[m,h]=(0,X.useState)(new Set),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(null),E=(0,X.useMemo)(()=>[...new Set([...Object.keys(t.spaces||{}),...Object.keys(f.spaces||{})])].sort(),[t.spaces,f.spaces]),D=(0,X.useMemo)(()=>[...new Set([...Object.keys(t.providers||{}),...Object.keys(f.providers||{})])].sort(),[t.providers,f.providers]),O=(e,t,n)=>{p(r=>{let i={...r.spaces||{}},a={...i[e]||{}};if(n===``)delete a[t];else if(t===`dim`||t===`maxLength`||t===`dimensions`){let e=Number(n);if(Number.isNaN(e))return r;a[t]=e}else a[t]=n;return Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,spaces:i}})},k=(e,t,n)=>{p(r=>{let i={...r.spaces||{}},a={...i[e]||{}};return n===void 0?delete a[t]:a[t]=n,Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,spaces:i}})},A=(e,t,n)=>{t===`apiKey`&&h(t=>{let r=new Set(t);return n===``?r.delete(e):r.add(e),r}),p(r=>{let i={...r.providers||{}},a={...i[e]||{}};if(n===``)delete a[t];else if(t===`timeoutMs`){let e=Number(n);if(Number.isNaN(e))return r;a[t]=e}else a[t]=n;return Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,providers:i}})},j=(e,t,n)=>{p(r=>{let i={...r.providers||{}},a={...i[e]||{}};return n===void 0?delete a[t]:a[t]=n,Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,providers:i}})},M=e=>{p(t=>{let n={...t.providers||{}};return delete n[e],{...t,providers:n}}),h(t=>{let n=new Set(t);return n.delete(e),n})},N=()=>{let e=S.trim();if(e){if(E.includes(e)){d({title:`Space exists`,description:`'${e}' already has a row below.`,variant:`destructive`});return}p(t=>({...t,spaces:{...t.spaces||{},[e]:{}}})),C(``),T(`space:${e}`)}},P=(e,t)=>{if(e){if(D.includes(e)){d({title:`Backend exists`,description:`'${e}' is already declared. Open it below to edit.`,variant:`destructive`});return}p(n=>({...n,providers:{...n.providers||{},[e]:{type:`openai`,...t?{baseUrl:t}:{}}}})),x(``),T(`provider:${e}`)}},F=e=>({...t.providers?.[e]||{},...f.providers?.[e]||{}}),I=async e=>{let n=f.spaces?.[e]?.provider??t.spaces?.[e]?.provider,r=f.spaces?.[e]?.model??t.spaces?.[e]?.model;if(!n){d({title:`No backend`,description:`Space '${e}' has no backend to test.`,variant:`destructive`});return}let i=F(n),a=i.type?dD[i.type]?.url?.key:void 0,o=a?hD(i[a]):null;if(o){d({title:`Backend '${n}'`,description:o,variant:`destructive`});return}_(e);try{try{await sD(i,r)===!1&&(y(!0),d({title:`Downloading model`,description:`'${r??`the configured model`}' is not in the server's cache yet; downloading now. A first test can take a few minutes; the model is then cached for good.`}))}catch{}let n=await cD(i,r,e),a=f.spaces?.[e]?.dim??t.spaces?.[e]?.dim,o=n.dim>0&&a!==void 0&&n.dim!==a;(o||n.dim>0&&a===void 0)&&O(e,`dim`,String(n.dim)),d({title:o?`Backend answered; dimensions corrected`:`Backend answered`,description:o?`Returned ${n.dim}-d but '${e}' was set to ${a}-d. Dimensions updated to ${n.dim}; save to apply. (${n.latencyMs} ms)`:`${n.dim}-d in ${n.latencyMs} ms`})}catch(e){d({title:`Test failed`,description:e instanceof Error?e.message:`Backend unreachable`,variant:`destructive`})}finally{_(null),y(!1)}},ee=(0,X.useMemo)(()=>{let e=[];for(let[n,r]of Object.entries(f.providers||{})){let i=r.type??t.providers?.[n]?.type,a=i?dD[i]?.url?.key:void 0;if(!a)continue;let o=hD(r[a]);o&&e.push(`${n}: ${o}`)}return e},[f.providers,t.providers]),te=(0,X.useMemo)(()=>JSON.stringify(f)!==JSON.stringify(e)||m.size>0,[f,e,m]),ne=async()=>{if(ee.length>0){d({title:`Fix the endpoint first`,description:ee.join(` · `),variant:`destructive`});return}await u(JE(f,m)),h(new Set)},re=e=>T(t=>t===e?null:e);return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[i&&(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive-subtle p-3 text-xs`,children:[(0,Z.jsx)(at,{className:`mt-0.5 h-4 w-4 shrink-0 text-destructive`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`font-medium text-destructive`,children:`Stored config does not resolve; defaults are standing in`}),(0,Z.jsx)(`p`,{className:`mt-0.5 font-mono text-[11px] text-muted-foreground`,children:i})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(gD,{title:`Search models`,hint:`Choose a provider and model for each kind of content. After switching models, fill the new index to make existing documents searchable. Previous model indexes are preserved.`}),E.length===0?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-dashed p-6 text-center`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:`No spaces on this layer`}),(0,Z.jsx)(`p`,{className:`mx-auto mt-1 max-w-sm text-xs text-muted-foreground`,children:`A space needs a backend, a model and a dimension count. Add one below to start embedding.`})]}):(0,Z.jsx)(`div`,{className:`divide-y overflow-hidden rounded-lg border`,children:E.map(e=>{let s=f.spaces?.[e]||{},l=t.spaces?.[e]||{},u=n.spaces?.[e]||{},d=r?.[e],p=`space:${e}`,m=w===p,h=s.model??l.model,_=s.provider??l.provider,y=s.dim??l.dim,b=s.chunk??l.chunk??!1,x=a?.includes(e)??!1;return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`span`,{className:K(`absolute inset-y-0 left-0 w-[3px]`,SD[i?`unresolved`:x?`needs-fill`:h?`configured`:`unset`]),"aria-hidden":!0}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 py-3 pl-4 pr-3 sm:flex-row sm:items-start sm:gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,Z.jsx)(`span`,{className:K(`text-[11px]`,uD),children:e}),(0,Z.jsx)(`span`,{className:`truncate font-mono text-sm`,children:h||`no model set`}),_&&(0,Z.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:[`via `,_]}),y!==void 0&&(0,Z.jsxs)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:[y,`-d`]}),b&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`chunked`})]}),r&&h&&(0,Z.jsxs)(`p`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground`,title:`Vector table backing this space`,children:[`└─ `,d?.table??(0,Z.jsx)(`span`,{className:`not-italic`,children:`not created yet`})]}),x&&(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-warning`,children:`New table, nothing embedded in it yet; dense search stays thin for this space until it is filled. Reverting the model is still instant.`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 max-sm:justify-end`,children:[x&&o&&(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>o(e),children:`Fill`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,disabled:c||g!==null,onClick:()=>I(e),title:`Round-trip a real embedding call against this backend and report the dimensions it returns`,children:[(0,Z.jsx)(ye,{className:`mr-1.5 h-3.5 w-3.5`}),g===e?v?`Downloading…`:`Testing…`:`Test`]}),(0,Z.jsx)(xD,{open:m,onClick:()=>re(p),label:`Edit ${e}`})]})]}),m&&(0,Z.jsxs)(`div`,{className:`border-t bg-muted/40 py-4 pl-4 pr-3`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Backend`}),(0,Z.jsx)(_D,{overridden:s.provider!==void 0,source:u.provider})]}),(0,Z.jsxs)(`select`,{className:lD,disabled:c,value:s.provider??``,onChange:t=>O(e,`provider`,t.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:l.provider?`inherited: ${l.provider}`:`inherited`}),D.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Z.jsx)(vD,{label:`Model`,mono:!0,value:s.model,inheritedValue:l.model,onChange:t=>O(e,`model`,t),disabled:c}),(0,Z.jsx)(vD,{label:`Dimensions`,type:`number`,value:s.dim,inheritedValue:l.dim,onChange:t=>O(e,`dim`,t),disabled:c,hint:`Sizes the vector table. Test asks the backend and fills in what it really returns.`}),(0,Z.jsx)(vD,{label:`Max length`,type:`number`,value:s.maxLength,inheritedValue:l.maxLength,onChange:t=>O(e,`maxLength`,t),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-4`,children:[(0,Z.jsx)(yD,{label:`Chunk long inputs`,checked:b,overridden:s.chunk!==void 0,disabled:c,onChange:t=>k(e,`chunk`,t)}),(0,Z.jsx)(yD,{label:`Build ANN index`,checked:s.annIndex??l.annIndex??!0,overridden:s.annIndex!==void 0,disabled:c,onChange:t=>k(e,`annIndex`,t)})]})]})]},e)})}),!c&&(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(q,{value:S,onChange:e=>C(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),N())},placeholder:`new space name (e.g. audio)`,className:`h-8 w-full max-w-xs text-sm sm:w-auto`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:N,children:[(0,Z.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),`Add space`]})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(gD,{title:`Model providers`,hint:`Connect a service here, then select it under Search models above. Built-in providers work without an extra connection. Provider changes take effect when you save.`}),(0,Z.jsx)(`div`,{className:`divide-y overflow-hidden rounded-lg border`,children:D.map(e=>{let n=f.providers?.[e]||{},r=t.providers?.[e]||{},i=GE.includes(e),a=f.providers?.[e]!==void 0,o=`provider:${e}`,s=w===o,l=n.type??r.type,u=l?dD[l]:void 0,d=u?.url?hD(n[u.url.key]):null,p={...r,...n},h=fD.filter(e=>!(n[e]===void 0||e===u?.url?.key||e===`apiKey`&&u?.apiKey||e===`cacheDir`&&u?.cacheDir)),g=E.filter(n=>(f.spaces?.[n]?.provider??t.spaces?.[n]?.provider)===e);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3 sm:flex-row sm:items-start sm:gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-sm font-semibold`,children:e}),(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:l??`no type`}),i&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`built-in`}),p.apiKeySet&&!m.has(e)&&(0,Z.jsx)(`span`,{className:`text-[10px] font-medium text-success`,children:`key set`}),d&&(0,Z.jsx)(`span`,{className:`text-[10px] font-medium text-destructive`,children:`check endpoint`})]}),(0,Z.jsx)(`p`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground`,children:u?u.where(p):`—`}),g.length>0&&(0,Z.jsxs)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:[`used by `,g.join(`, `)]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 max-sm:justify-end`,children:[a&&!i&&!c&&(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>M(e),title:`Remove this override`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(xD,{open:s,onClick:()=>re(o),label:`Edit ${e}`})]})]}),s&&(0,Z.jsxs)(`div`,{className:`border-t bg-muted/40 px-4 py-4`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Type`}),(0,Z.jsx)(_D,{overridden:n.type!==void 0,source:r.type})]}),(0,Z.jsxs)(`select`,{className:lD,disabled:c,value:n.type??``,onChange:t=>A(e,`type`,t.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:r.type?`inherited: ${r.type}`:`inherited`}),WE.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e)),l&&!WE.includes(l)&&(0,Z.jsxs)(`option`,{value:l,children:[l,` (legacy)`]})]}),u?.note&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:u.note})]}),u?.url&&(0,Z.jsx)(vD,{label:u.url.label,mono:!0,value:n[u.url.key],inheritedValue:r[u.url.key],onChange:t=>A(e,u.url.key,t),disabled:c,placeholder:r[u.url.key]??u.url.placeholder,hint:u.url.hint,error:d??void 0}),u?.cacheDir&&(0,Z.jsx)(vD,{label:`Cache directory`,mono:!0,value:n.cacheDir,inheritedValue:r.cacheDir,onChange:t=>A(e,`cacheDir`,t),disabled:c,placeholder:r.cacheDir??`server default`,hint:u.cacheDir}),u?.imageInput&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Image input shape`}),(0,Z.jsx)(_D,{overridden:n.imageInput!==void 0,source:r.imageInput})]}),(0,Z.jsxs)(`select`,{className:lD,disabled:c,value:n.imageInput??``,onChange:t=>A(e,`imageInput`,t.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:r.imageInput?`inherited: ${r.imageInput}`:`inherited: data-uri`}),pD.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:pD.find(e=>e.value===(n.imageInput??r.imageInput??`data-uri`))?.hint})]}),u?.timeoutMs&&(0,Z.jsx)(vD,{label:`Request timeout (ms)`,type:`number`,value:n.timeoutMs,inheritedValue:r.timeoutMs??mD,onChange:t=>A(e,`timeoutMs`,t),disabled:c,hint:`How long to wait for a batch before giving up. Raise it for a slow or cold GPU host.`}),u?.apiKey&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`API key`}),m.has(e)&&(0,Z.jsx)(`span`,{className:`rounded bg-warning-subtle px-1.5 py-0.5 text-[10px] font-medium text-warning`,children:`will be written`})]}),(0,Z.jsx)(q,{type:`password`,autoComplete:`new-password`,disabled:c,value:n.apiKey??``,onChange:t=>A(e,`apiKey`,t.target.value),placeholder:r.apiKeySet?`•••••••• (stored; leave empty to keep)`:`unset`,className:`h-8 text-sm`}),(0,Z.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[u.apiKey,` Write-only: the stored key is never sent back, and leaving this empty keeps whatever is stored.`]})]})]}),u?.headers&&(0,Z.jsx)(bD,{disabled:c,storedNames:r.headerNames,value:n.headers,onChange:t=>j(e,`headers`,t)}),h.length>0&&!c&&(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2 rounded-md border border-dashed p-2 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{children:[`Not used by type `,(0,Z.jsx)(`span`,{className:`font-mono`,children:l}),`:`,` `,(0,Z.jsx)(`span`,{className:`font-mono`,children:h.join(`, `)})]}),(0,Z.jsx)(`button`,{type:`button`,className:`underline hover:text-foreground`,onClick:()=>h.forEach(t=>A(e,t,``)),children:`clear`})]}),r.headerNames&&r.headerNames.length>0&&(0,Z.jsxs)(`p`,{className:`mt-3 text-[11px] text-muted-foreground`,children:[`Stored custom headers: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:r.headerNames.join(`, `)}),` (values not shown)`]})]})]},e)})}),!c&&(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(q,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),P(b.trim()))},placeholder:`new backend name (e.g. gpu)`,className:`h-8 w-full max-w-xs text-sm sm:w-auto`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>P(b.trim()),children:[(0,Z.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),`Add backend`]}),KE.filter(e=>!D.includes(e.id)).map(e=>(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>P(e.id,e.baseUrl),title:`Add an openai-type backend '${e.id}' pointed at ${e.baseUrl}`,children:e.label},e.id))]})]}),!c&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-t pt-4`,children:[(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:te?`default`:`outline`,onClick:ne,disabled:s||!te||ee.length>0,children:s?`Saving…`:l}),(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,disabled:s||!te,onClick:()=>{p(structuredClone(e)),h(new Set)},children:`Discard changes`}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ee.length>0?(0,Z.jsxs)(`span`,{className:`font-medium text-destructive`,children:[ee.length,` endpoint `,ee.length===1?`needs`:`need`,` fixing`]}):te?`Unsaved changes`:`Everything saved`})]})]})}function wD(){let{showToast:e}=po(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(!0),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),l=(0,X.useCallback)(()=>rD().then(e=>{n(e),c(null)}).catch(e=>c(e instanceof Error?e.message:`Failed to load embedding defaults`)).finally(()=>i(!1)),[]);(0,X.useEffect)(()=>{l()},[l]);let u=()=>{i(!0),l()};return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,Z.jsx)(pb,{compact:!0,className:`mb-6`,title:`Search & AI defaults`,onBack:FC(),description:`Your account · Choose the embedding models used for text and image search. Workspace settings override these defaults. Running workspaces adopt new defaults when restarted.`,actions:(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:u,disabled:r,children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})}),r?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(Te,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):s||!t?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-destructive`,children:`Embedding defaults unavailable`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s||`No config returned.`})]}),(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:u,children:`Retry`})]}):(0,Z.jsx)(CD,{value:t.user||{},effective:t.effective||{},inherited:t.serverDefaults||{},invalid:t.invalid,saving:a,saveLabel:`Save defaults`,onSave:async t=>{o(!0);try{let n=await iD(t);e({title:`Defaults saved`,description:n.restartRequired?`${n.workspaces.length} running workspace(s) keep their current tables until restarted. Set the config on a workspace directly to change it live.`:`New workspaces will inherit this.`}),await l()}catch(t){e({title:`Save failed`,description:t instanceof Error?t.message:`Failed to save`,variant:`destructive`})}finally{o(!1)}}},JSON.stringify(t.user))]})}function TD(){let e=Jc(),{showToast:t}=po(),n=new URLSearchParams(e.search),r=e=>{try{let t=new URL(e);return t.pathname.includes(`/rest/v2/workspaces/`)&&!t.pathname.includes(`/rest/v2/pub/`)?t.pathname=t.pathname.replace(`/rest/v2/workspaces/`,`/rest/v2/pub/workspaces/`):t.pathname.includes(`/rest/v2/contexts/`)&&!t.pathname.includes(`/rest/v2/pub/`)&&(t.pathname=t.pathname.replace(`/rest/v2/contexts/`,`/rest/v2/pub/contexts/`)),t.toString()}catch{return e}},i=r(n.get(`url`)||``),a=sessionStorage.getItem(`sharedToken:last`)||``,[o,s]=(0,X.useState)(i),[c,l]=(0,X.useState)(a),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)([]),[m,h]=(0,X.useState)(!1),g=(0,X.useMemo)(()=>{try{let e=new URL(o);return e.pathname.includes(`/pub/workspaces/`)?`workspace`:e.pathname.includes(`/pub/contexts/`)?`context`:`unknown`}catch{return`unknown`}},[o]),_=()=>({Authorization:`Bearer ${c.trim()}`}),v=async()=>{if(!(!o||!c)){h(!0);try{let e=r(o),t=await Y.get(e,{skipAuth:!0,headers:_()});d(t);let n=await Y.get(`${e}/documents`,{skipAuth:!0,headers:_()}),i=Array.isArray(n)?n:Array.isArray(n?.data)?n.data:[];p(Array.isArray(i)?i:[])}catch(e){let n=o.includes(`/rest/v2/workspaces/`)?`Ensure the URL uses /rest/v2/pub/workspaces/<workspace-id> and the token matches that workspace.`:o.includes(`/rest/v2/contexts/`)?`Ensure the URL uses /rest/v2/pub/contexts/<context-id>.`:void 0;t({title:`Error`,description:`${e instanceof Error?e.message:`Failed to load shared resource`}${n?`: ${n}`:``}`,variant:`destructive`}),d(null),p([])}finally{h(!1)}}},y=(0,X.useRef)(v);return(0,X.useEffect)(()=>{y.current()},[]),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(pb,{onBack:FC(),title:`Shared Resource Viewer`,description:`Open a resource someone shared with you.`}),(0,Z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-3`,children:[(0,Z.jsx)(q,{value:o,onChange:e=>s(e.target.value),placeholder:`Full pub URL`}),(0,Z.jsx)(q,{value:c,onChange:e=>l(e.target.value),placeholder:`Access token (canvas-...)`}),(0,Z.jsx)(J,{onClick:v,disabled:m||!o||!c,children:`Load`})]}),(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`Type: `,g]}),m?(0,Z.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`Loading...`}):(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`border rounded p-3`,children:[(0,Z.jsx)(`h2`,{className:`font-semibold mb-2`,children:`Metadata`}),(0,Z.jsx)(`pre`,{className:`text-xs overflow-auto max-h-80`,children:JSON.stringify(u,null,2)})]}),(0,Z.jsxs)(`div`,{className:`border rounded p-3`,children:[(0,Z.jsxs)(`h2`,{className:`font-semibold mb-2`,children:[`Documents (`,f.length,`)`]}),f.length===0?(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No documents`}):(0,Z.jsx)(`ul`,{className:`space-y-2 text-sm`,children:f.slice(0,100).map((e,t)=>(0,Z.jsxs)(`li`,{className:`border rounded p-2`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-xs`,children:e.id}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.schema})]},t))})]})]}),(0,Z.jsx)(qu,{className:`mt-8`})]})}function ED(e={}){let t=new URLSearchParams;e.tail&&t.set(`tail`,String(e.tail)),e.level&&t.set(`level`,e.level),e.module&&t.set(`module`,e.module);let n=t.toString();return n?`?${n}`:``}function DD(){let e=localStorage.getItem(`authToken`);if(!e)throw Error(`Authentication required`);let t=localStorage.getItem(`appName`)||window.location.hostname;return{Authorization:`Bearer ${e}`,"X-App-Name":t,Accept:`text/event-stream`}}var OD={async listUsers(e){let t=new URLSearchParams;e?.status&&t.append(`status`,e.status),e?.userType&&t.append(`userType`,e.userType);let n=t.toString(),r=n?`${Qr.admin.users}?${n}`:Qr.admin.users;return await Y.get(r)},async getUser(e){return await Y.get(`${Qr.admin.users}/${e}`)},async createUser(e){return await Y.post(Qr.admin.users,e)},async updateUser(e,t){return await Y.put(`${Qr.admin.users}/${e}`,t)},async deleteUser(e){await Y.delete(`${Qr.admin.users}/${e}`)}},kD={async listAllWorkspaces(){return await Y.get(Qr.admin.workspaces)},async createWorkspace(e){return await Y.post(Qr.admin.workspaces,e)},async deleteWorkspace(e){await Y.delete(`${Qr.admin.workspaces}/${e}`)}},AD={async getLogs(e={}){return(await Y.get(`${Qr.admin.logs}${ED(e)}`)).logs||[]},async streamLogs(e={},t={}){let{signal:n,onEntry:r,onError:i}=t;try{let t=await fetch(`${Qr.admin.logsStream}${ED(e)}`,{method:`GET`,headers:DD(),credentials:`include`,signal:n});if(!t.ok)throw Error(`Failed to open log stream (${t.status})`);if(!t.body)throw Error(`Streaming is not supported by this browser`);let i=t.body.getReader(),a=new TextDecoder,o=``,s=e=>{let t=e.split(`
|
|
18
|
+
`).map(e=>e.trim()).filter(Boolean);for(let e of t){if(!e.startsWith(`data: `))continue;let t=e.slice(6).trim();if(t!==`[DONE]`)try{let e=JSON.parse(t);if(!i)continue;if(e.type===`chunk`)i(e.delta||``,!1,e.metadata||{});else if(e.type===`thinking`)i(``,!1,{...e.metadata||{},reasoningDelta:e.delta||``});else if(e.type===`complete`){let t=Array.isArray(e.messages)?[...e.messages].reverse().find(e=>e?.role===`assistant`):null;i(``,!0,{...e.metadata||{},...rw(t)||{}})}else e.type===`error`&&a&&a(Error(e.error||`Prompt stream failed`))}catch{}}}},onError:a,onComplete:o})}async function jw(e,t){let{message:n,onMessage:r,onError:i,onComplete:a,context:o,mcpContext:s,maxTokens:c,temperature:l,images:u}=t;try{let t=await Y.post(`${ti}/agents/${e}/prompt`,{message:n,images:u,context:o,mcpContext:s,maxTokens:c,temperature:l}),i=Array.isArray(t.messages)?[...t.messages].reverse().find(e=>e?.role===`assistant`):null,d={content:tw(i),metadata:rw(i)};return r&&r(d.content,!0,d.metadata),a&&a(),d}catch(e){throw i&&i(e),e}}function Mw(e){return e.map(e=>({...e,timestamp:typeof e.timestamp==`string`?e.timestamp:new Date().toISOString()}))}async function Nw(){return await Y.get(`${ti}/voice/status`)}async function Pw(e,t,n={}){let r=new FormData,i=(t.type.split(`/`)[1]||`webm`).split(`;`)[0];r.append(`file`,t,`voice.${i}`);let a=new URLSearchParams;n.tts===!1&&a.set(`tts`,`false`),n.voice&&a.set(`voice`,n.voice);let o=a.toString()?`?${a.toString()}`:``;return await Y.post(`${ti}/agents/${e}/voice${o}`,r)}var Fw=[{id:`workspace`,label:`Workspace`,path:`workspaces`,description:`Files, search, devices and sharing for one workspace. These settings override account defaults.`,sections:GC,load:async()=>(await Pr()).map(e=>({id:e.name,label:e.label||e.name}))},{id:`context`,label:`Context`,path:`contexts`,description:`Choose the tree and path a context opens, and who can access that view. File storage belongs to its workspace.`,sections:JC,load:async()=>(await Yo()).map(e=>({id:e.id,label:e.name||e.id}))},{id:`agent`,label:`Agent`,path:`agents`,description:`Configure one assistant: its instructions, chat model, tools and access to Canvas.`,sections:XC,load:async()=>(await pw()).map(e=>({id:e.id,label:e.label||e.name}))}];function Iw({to:e,label:t,description:n,icon:r}){return(0,Z.jsxs)(mu,{to:e,className:`group flex items-start gap-3 rounded-lg border bg-card p-4 transition-colors hover:border-primary/50 hover:bg-accent/30 focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary`,children:[(0,Z.jsx)(r,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm font-semibold`,children:t}),(0,Z.jsx)(`span`,{className:`mt-1 block text-sm leading-relaxed text-muted-foreground`,children:n})]}),(0,Z.jsx)(qn,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground group-hover:text-primary`})]})}function Lw({group:e,query:t}){let[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(`loading`),[c,l]=(0,X.useState)(0);(0,X.useEffect)(()=>{let t=!1;return e.load().then(e=>{t||(r(e),s(`ready`))}).catch(()=>{t||s(`error`)}),()=>{t=!0}},[e,c]);let u=e.sections.filter(n=>jb(t,e.label,n.label,n.description));return u.length?(0,Z.jsxs)(`section`,{id:e.id,className:`scroll-mt-6 space-y-3`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,Z.jsxs)(`label`,{className:`block max-w-md text-sm font-medium`,children:[`Choose a `,e.label.toLowerCase(),(0,Z.jsxs)(`select`,{className:`mt-2 h-10 w-full rounded-md border bg-background px-3 text-sm`,value:i,disabled:o!==`ready`||!n.length,onChange:e=>a(e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:o===`loading`?`Loading…`:o===`error`?`Unable to load list`:n.length?`Select ${e.label.toLowerCase()}…`:`No ${e.path} available`}),n.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),o===`error`&&(0,Z.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[`The list could not be loaded. `,(0,Z.jsx)(`button`,{type:`button`,className:`underline`,onClick:()=>{s(`loading`),l(e=>e+1)},children:`Retry`})]}),(0,Z.jsxs)(`details`,{open:!!(i||t.trim()),children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer py-2 text-sm text-muted-foreground`,children:i?`Settings for ${n.find(e=>e.id===i)?.label||i}`:`What you can configure (${u.length})`}),(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:u.map(t=>i?(0,Z.jsx)(Iw,{to:`/${e.path}/${encodeURIComponent(i)}/settings/${t.id}`,...t},t.id):(0,Z.jsxs)(`div`,{className:`rounded-lg border border-dashed p-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:t.label}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:t.description})]},t.id))})]})]}):null}function Rw(){let{state:e}=$b(),[t,n]=(0,X.useState)(``),r=kb.filter(t=>t.id!==`server`||e.user?.userType===`admin`).map(e=>({...e,items:e.items.filter(n=>jb(t,e.label,n.label,n.description))})).filter(e=>e.items.length),i=Fw.some(e=>e.sections.some(n=>jb(t,e.label,n.label,n.description)));return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-6xl space-y-8 pb-8 max-md:pb-rail-stack`,children:[(0,Z.jsx)(pb,{title:`Settings`,description:`Start with what you want to change. Each section explains where your changes apply.`}),(0,Z.jsx)(q,{type:`search`,className:`max-w-xl`,"aria-label":`Search all settings`,placeholder:`Find a setting: offline, folders, models, sharing…`,value:t,onChange:e=>n(e.target.value)}),r.filter(e=>e.id===`device`||e.id===`account`).map(e=>(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:e.items.map(e=>(0,Z.jsx)(Iw,{to:e.path,...e},e.path))})]},e.id)),Fw.map(e=>(0,Z.jsx)(Lw,{group:e,query:t},e.id)),r.filter(e=>e.id===`server`||e.id===`information`).map(e=>(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:e.items.map(e=>(0,Z.jsx)(Iw,{to:e.path,...e},e.path))})]},e.id)),!r.length&&!i&&(0,Z.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[`No settings match “`,t,`”. Try a shorter phrase or clear the search.`]})]})}var zw=[{id:`canvas_1`,title:`Canvas Deep`,scheme:`dark`,background:`#032940`,accent:`#f2f2f2`,sources:[{type:`image/svg+xml`,src:`files/canvas_1.svg`},{type:`image/avif`,src:`files/canvas_1.avif`},{type:`image/webp`,src:`files/canvas_1.webp`}],thumb:`thumbs/canvas_1.webp`,author:`Canvas`,license:`LicenseRef-Canvas-Brand`},{id:`canvas_3`,title:`Canvas Mono Dark`,scheme:`dark`,background:`#000000`,accent:`#ffffff`,sources:[{type:`image/svg+xml`,src:`files/canvas_3.svg`},{type:`image/avif`,src:`files/canvas_3.avif`},{type:`image/webp`,src:`files/canvas_3.webp`}],thumb:`thumbs/canvas_3.webp`,author:`Canvas`,license:`LicenseRef-Canvas-Brand`},{id:`w1`,title:`Frost`,scheme:`dark`,background:`#164a6f`,accent:`#9ad9f0`,sources:[{type:`image/avif`,src:`files/w1.avif`},{type:`image/webp`,src:`files/w1.webp`},{type:`image/jpeg`,src:`files/w1.jpg`}],thumb:`thumbs/w1.webp`,author:`Peter Cui Bide`,source:`https://petercui.deviantart.com`,license:`LicenseRef-Attribution-Only`}],Bw=`/wallpapers`;function Vw(e){return zw.find(t=>t.id===e)}function Hw(e,t={}){let n=typeof e==`string`?Vw(e):e;if(!n)return null;let{base:r=Bw,types:i}=t,a=(i?n.sources.find(e=>i.includes(e.type)):n.sources[0])??n.sources[n.sources.length-1];return`${r.replace(/\/$/,``)}/${a.src}`}function Uw(e,t=Bw){let n=typeof e==`string`?Vw(e):e;return n?`${t.replace(/\/$/,``)}/${n.thumb}`:null}var Ww=[{id:`cover`,label:`Scale and Crop`,description:`Fills the screen, cropping edges as needed`},{id:`fill`,label:`Fill`,description:`Stretches to the exact screen size`},{id:`center`,label:`Centered`,description:`Original size, centered on the desk`}],Gw=`canvas:wallpaper`,Kw=`builtin:`,qw=zw;function Jw(e){return Uw(e)??``}function Yw(e){return`${Kw}${e}`}function Xw(e){return e?.startsWith(Kw)?e.slice(8):null}function Zw(){try{let e=localStorage.getItem(Gw);if(e){let t=JSON.parse(e);if(typeof t.image==`string`||t.image===null){let e=t.fit===`fill`||t.fit===`center`?t.fit:`cover`;return{image:t.image??null,fit:e}}}}catch{}return{image:null,fit:`cover`}}function Qw(e){localStorage.setItem(Gw,JSON.stringify(e)),nT(e)}var $w=typeof CSS<`u`&&CSS.supports(`background-image`,`image-set(url("a.avif") type("image/avif"))`);function eT(e){if(!e)return null;let t=Xw(e);if(t===null)return`url("${e}")`;let n=Vw(t);if(!n)return null;let r=`url("${Hw(n,{types:[n.sources[n.sources.length-1].type]})}")`;return!$w||n.sources.length===1?r:`image-set(${n.sources.map(e=>`url("${Hw(n,{types:[e.type]})}") type("${e.type}")`).join(`, `)})`}function tT(e){return e===`fill`?`100% 100%`:e===`center`?`auto`:`cover`}function nT(e=Zw()){let t=document.documentElement.style,n=eT(e.image);if(!n){t.removeProperty(`--wallpaper-image`),t.removeProperty(`--wallpaper-size`);return}t.setProperty(`--wallpaper-image`,n),t.setProperty(`--wallpaper-size`,tT(e.fit))}var rT=[{id:`cards`,name:`Cards`,description:`Nested cards with connector lines. Each level indents.`},{id:`accordion-mobile`,name:`Accordion on phones (beta)`,description:`Experimental. Full-width accordion rows on a phone, cards on wider screens.`},{id:`accordion`,name:`Accordion (beta)`,description:`Experimental. Full-width rows at every depth; a depth rail, tint and colour swatch replace the indent, and open parents stick to the top while you scroll.`}],iT=`canvas:treeStyle`;function aT(){try{let e=localStorage.getItem(iT);return e===`accordion`||e===`accordion-mobile`?e:`cards`}catch{return`cards`}}var oT=aT(),sT=new Set;function cT(){return oT}function lT(e){try{e===`cards`?localStorage.removeItem(iT):localStorage.setItem(iT,e)}catch{}oT=e;for(let e of sT)e()}function uT(e){sT.add(e);let t=t=>{(t.key===iT||t.key===null)&&(oT=aT(),e())};return window.addEventListener(`storage`,t),()=>{sT.delete(e),window.removeEventListener(`storage`,t)}}function dT(){return(0,X.useSyncExternalStore)(uT,cT,()=>`cards`)}function fT(){let e=dT(),t=Am();return e===`accordion`||e===`accordion-mobile`&&t}var pT=[{id:`canvas`,name:`Canvas`,description:`Black and white with a teal accent. Sheets of paper on a grey desk.`,swatches:[`oklch(1 0 0)`,`oklch(0 0 0)`,`oklch(0.704 0.135 183)`]},{id:`nord`,name:`Nord`,description:`Cool arctic blues, lower contrast, softer corners.`,swatches:[`oklch(0.976 0.006 251)`,`oklch(0.588 0.056 244)`,`oklch(0.686 0.062 213)`]},{id:`contrast`,name:`High Contrast`,description:`WCAG AAA text contrast, square corners, hard borders, no shadows.`,swatches:[`oklch(1 0 0)`,`oklch(0 0 0)`,`oklch(0.32 0.16 258)`]},{id:`frost`,name:`Frosted Glass`,description:`Translucent, blurred surfaces over a soft backdrop. Best with a wallpaper.`,swatches:[`oklch(0.92 0.008 250)`,`oklch(0.31 0.025 255)`,`oklch(0.55 0.05 250)`]},{id:`terminal`,name:`Terminal`,description:`Monospaced and dense. Tighter rows and chrome for large displays.`,swatches:[`oklch(0.17 0.006 152)`,`oklch(0.8 0.19 148)`,`oklch(0.75 0.12 220)`]},{id:`halflife`,name:`Half-Life`,description:`Lambda orange on black steel. Square corners; the left rail is orange.`,swatches:[`oklch(0.724 0.181 52)`,`oklch(0 0 0)`,`oklch(1 0 0)`]}],mT=pT.map(e=>e.id),hT=[{id:`system`,name:`System`},{id:`light`,name:`Light`},{id:`dark`,name:`Dark`}],gT=[{id:`auto`,name:`Auto`,description:`Match the pointer: touch on phones, mouse on desktop`},{id:`compact`,name:`Compact`,description:`Maximum rows per screen`},{id:`comfortable`,name:`Comfortable`,description:`Balanced for mouse use`},{id:`touch`,name:`Touch`,description:`Large targets for finger input`}],_T={theme:`canvas`,scheme:`light`,density:`auto`},vT=`canvas.ui.theme`;function yT(e){return typeof e==`string`&&mT.includes(e)}function bT(e){return e===`light`||e===`dark`||e===`system`}function xT(e){return e===`auto`||e===`compact`||e===`comfortable`||e===`touch`}function ST(e){let t=typeof e==`object`&&e?e:{};return{theme:yT(t.theme)?t.theme:_T.theme,scheme:bT(t.scheme)?t.scheme:_T.scheme,density:xT(t.density)?t.density:_T.density}}var CT=`(prefers-color-scheme: dark)`;function wT(){return typeof document<`u`}function TT(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(CT).matches}function ET(e){return e===`system`?TT()?`dark`:`light`:e}function DT(e){if(typeof window>`u`||typeof window.matchMedia!=`function`)return()=>{};let t=window.matchMedia(CT),n=t=>e(t.matches?`dark`:`light`);return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)}function OT(e){return DT(e)}function kT(){return TT()?`dark`:`light`}function AT(){return`light`}function jT(e){let t=getComputedStyle(e).getPropertyValue(`--background`).trim();if(!t)return;let n=document.querySelector(`meta[name="theme-color"]`);n||(n=document.createElement(`meta`),n.name=`theme-color`,document.head.appendChild(n)),n.content=t}function MT(e,t=wT()?document.documentElement:void 0){let n=ET(e.scheme);return t?(t.dataset.theme=e.theme,t.dataset.scheme=n,t.dataset.density=e.density,jT(t),n):n}function NT(e,t=wT()?document.documentElement:void 0){if(!t||typeof window>`u`)return MT(e,t);let n=document.createElement(`style`);n.appendChild(document.createTextNode(`*,*::before,*::after{transition:none!important;animation:none!important}`)),document.head.appendChild(n);let r=MT(e,t);return window.getComputedStyle(n).opacity,document.head.removeChild(n),r}function PT(e){let t=e??LT();if(!t)return _T;try{let e=t.getItem(vT);return e?ST(JSON.parse(e)):_T}catch{return _T}}function FT(e,t){let n=t??LT();if(n)try{n.setItem(vT,JSON.stringify(e))}catch{}}function IT(e){let t=e??LT();if(t)try{t.removeItem(vT)}catch{}}function LT(){try{return typeof localStorage<`u`?localStorage:void 0}catch{return}}function RT({children:e,initial:t,storage:n,persist:r=!0}){let[i,a]=(0,X.useState)(()=>({...PT(n),...t})),o=(0,X.useSyncExternalStore)(OT,kT,AT),s=i.scheme===`system`?o:i.scheme;(0,X.useEffect)(()=>{NT({...i,scheme:s})},[i,s]),(0,X.useEffect)(()=>{r&&FT(i,n)},[i,r,n]);let c=(0,X.useCallback)(e=>{a(t=>t.theme===e?t:{...t,theme:e})},[]),l=(0,X.useCallback)(e=>{a(t=>t.scheme===e?t:{...t,scheme:e})},[]),u=(0,X.useCallback)(e=>{a(t=>t.density===e?t:{...t,density:e})},[]),d=(0,X.useCallback)(()=>{a(e=>({...e,scheme:(e.scheme===`system`?kT():e.scheme)===`dark`?`light`:`dark`}))},[]),f=(0,X.useCallback)(()=>{IT(n),a(_T)},[n]),p=(0,X.useMemo)(()=>({...i,resolvedScheme:s,setTheme:c,setScheme:l,setDensity:u,toggleScheme:d,reset:f}),[i,s,c,l,u,d,f]);return(0,Z.jsx)(Cs.Provider,{value:p,children:e})}var zT={system:me,light:Gn,dark:Pn};function BT(){let{theme:e,scheme:t,density:n,resolvedScheme:r,setTheme:i,setScheme:a,setDensity:o,reset:s}=ws(),c=sm(),l=Vb(),u=dT(),d=Xb();return(0,Z.jsxs)(`div`,{className:`space-y-8`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Theme`,description:`Palette, shape and typography. Each theme defines its own light and dark variants.`}),(0,Z.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:pT.map(t=>{let n=t.id===e;return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>i(t.id),"aria-pressed":n,className:K(`focus-ring group flex flex-col gap-3 rounded-lg border p-4 text-left transition-colors`,n?`border-primary bg-accent`:`border-border hover:border-muted-foreground/40 hover:bg-accent/50`),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t.name}),n&&(0,Z.jsx)($e,{className:`size-4 shrink-0 text-primary`})]}),(0,Z.jsx)(`div`,{className:`flex gap-1.5`,"aria-hidden":!0,children:t.swatches.map(e=>(0,Z.jsx)(`span`,{className:`size-6 rounded-full border border-border`,style:{backgroundColor:e}},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]},t.id)})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Colour scheme`,description:t===`system`?`Following your system setting, currently ${r}.`:`Overrides your system setting.`}),(0,Z.jsx)(GT,{options:hT.map(e=>{let t=zT[e.id];return{id:e.id,label:e.name,icon:(0,Z.jsx)(t,{className:`size-4 shrink-0`})}}),value:t,onChange:a})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Density`,description:`Controls row height, hit-target size and shell spacing across the whole app.`}),(0,Z.jsx)(GT,{options:gT.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:o}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:gT.find(e=>e.id===n)?.description})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Layout`,description:`How menus and content share the screen. Device-local, like the wallpaper.`}),(0,Z.jsx)(GT,{options:Mb.map(e=>({id:e.id,label:e.name,title:e.description})),value:l,onChange:zb}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:Mb.find(e=>e.id===l)?.description}),l===`strip`&&(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Navigation keys`}),(0,Z.jsx)(GT,{options:Hb.map(e=>({id:e.id,label:e.name,title:e.description})),value:d,onChange:Jb}),(0,Z.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[Hb.find(e=>e.id===d)?.description,` `,`Left and right walk the columns, up and down switch pin rows.`]})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Tree style`,description:`How workspace and context trees are drawn in the menu. Device-local.`}),(0,Z.jsx)(GT,{options:rT.map(e=>({id:e.id,label:e.name,title:e.description})),value:u,onChange:lT}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:rT.find(e=>e.id===u)?.description})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Open documents`,description:`Choose how documents open from lists, tiles and boards. Saved on this device.`}),(0,Z.jsx)(GT,{options:[{id:`modal`,label:`Modal`},{id:`side`,label:`Side reading pane`}],value:c,onChange:am}),(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`The reading pane opens beside the content and updates as you select another document. On small screens it opens as a drawer.`})]}),(0,Z.jsx)(VT,{}),(0,Z.jsx)(`section`,{children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{s(),am(`modal`)},className:`focus-ring rounded-md text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline`,children:`Reset to defaults`})})]})}function VT(){let[e,t]=(0,X.useState)(Zw),[n,r]=(0,X.useState)(null),i=e=>{try{Qw(e),t(e),r(null)}catch{r(`Could not store the wallpaper (browser storage full?). Try a smaller image.`)}},a=t=>{if(!t)return;if(!t.type.startsWith(`image/`)){r(`Pick an image file.`);return}let n=new FileReader;n.onload=()=>{let t=String(n.result||``);if(t.length>3670016){r(`Image too large for browser storage. Use one under ~2.5 MB.`);return}i({...e,image:t})},n.readAsDataURL(t)},o=e.image!==null&&Xw(e.image)===null,s=eT(e.image);return(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(WT,{title:`Wallpaper`,description:`Background image for the desk behind all panels. Without one, the theme's desk color shows (the default).`}),(0,Z.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Wallpaper`,className:`grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6`,children:[(0,Z.jsx)(UT,{label:`None`,isActive:e.image===null,onSelect:()=>i({...e,image:null}),children:(0,Z.jsx)(`span`,{className:`flex size-full items-center justify-center surface-desk text-xs text-muted-foreground`,style:{backgroundImage:`none`},children:`None`})}),qw.map(t=>(0,Z.jsx)(UT,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:Xw(e.image)===t.id,onSelect:()=>i({...e,image:Yw(t.id)}),children:(0,Z.jsx)(`img`,{src:Jw(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),o&&(0,Z.jsx)(UT,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,Z.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,Z.jsx)(HT,{}),(0,Z.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:s?{backgroundImage:s,backgroundSize:tT(e.fit),backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,"aria-hidden":!0}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(`label`,{className:`focus-ring inline-flex cursor-pointer items-center rounded-md border px-3 py-1.5 text-sm hover:bg-accent/50`,children:[o?`Change image…`:`Use your own image…`,(0,Z.jsx)(`input`,{type:`file`,accept:`image/*`,className:`hidden`,onChange:e=>{a(e.target.files?.[0]),e.target.value=``}})]}),e.image&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>i({...e,image:null}),className:`focus-ring rounded-md border px-3 py-1.5 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:`Remove`})]}),(0,Z.jsx)(GT,{options:Ww.map(e=>({id:e.id,label:e.label,title:e.description})),value:e.fit,onChange:t=>i({...e,fit:t})}),n&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:n})]})]})]})}function HT(){let e=qw.filter(e=>e.author!==`Canvas`);return e.length===0?null:(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.map((e,t)=>(0,Z.jsxs)(`span`,{children:[t>0&&` · `,e.title,` © `,e.author,e.source&&(0,Z.jsxs)(Z.Fragment,{children:[` `,(0,Z.jsx)(`a`,{href:e.source,target:`_blank`,rel:`noreferrer noopener`,className:`focus-ring underline underline-offset-2 hover:text-foreground`,children:new URL(e.source).hostname})]})]},e.id))})}function UT({label:e,title:t,isActive:n,onSelect:r,children:i}){return(0,Z.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e,title:t??e,onClick:r,className:K(`focus-ring group relative aspect-video overflow-hidden rounded-md border transition-colors`,n?`border-primary ring-1 ring-primary`:`border-border hover:border-muted-foreground/40`),children:[i,n&&(0,Z.jsx)(`span`,{className:`absolute right-1 top-1 rounded-full bg-primary p-0.5 text-primary-foreground`,children:(0,Z.jsx)($e,{className:`size-3`})})]})}function WT({title:e,description:t}){return(0,Z.jsxs)(`div`,{className:`mb-3`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function GT({options:e,value:t,onChange:n}){return(0,Z.jsx)(`div`,{role:`radiogroup`,className:`inline-flex flex-wrap gap-1 rounded-lg bg-muted p-1`,children:e.map(e=>{let r=e.id===t;return(0,Z.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:e.title,onClick:()=>n(e.id),className:K(`focus-ring flex h-control items-center gap-2 rounded-md px-3 text-sm transition-colors`,r?`bg-card text-foreground shadow-elevation-1`:`text-muted-foreground hover:text-foreground`),children:[e.icon,e.label]},e.id)})})}function KT(){return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`Appearance`,onBack:FC(),description:`Theme, colour scheme and density. Changes apply immediately and are remembered on this device.`}),(0,Z.jsx)(BT,{})]})}var qT={previousTree:`Alt+Q`,nextTree:`Alt+W`},JT=`canvas:key-bindings`,YT=/^(Alt|Alt\+Shift|Ctrl\+Shift|Meta\+Shift)\+[A-Z]$/;function XT(){try{let e=JSON.parse(localStorage.getItem(JT)||`{}`),t={...qT};for(let n of Object.keys(t))(e[n]===``||YT.test(e[n]))&&(t[n]=e[n]);return t.previousTree&&t.previousTree===t.nextTree?{...qT}:t}catch{return{...qT}}}function ZT(e){localStorage.setItem(JT,JSON.stringify(e))}function QT(e){return/^Key[A-Z]$/.test(e.code)?[e.ctrlKey&&`Ctrl`,e.altKey&&`Alt`,e.metaKey&&`Meta`,e.shiftKey&&`Shift`,e.code.slice(3)].filter(Boolean).join(`+`):``}function $T(e,t,n){return e[(Math.max(0,e.indexOf(t))+n+e.length)%e.length]}function eE(e,t){return Math.abs(e)>=48&&Math.abs(e)>Math.abs(t)*1.5?e<0?1:-1:0}function tE(){let[e,t]=(0,X.useState)(XT),[n,r]=(0,X.useState)(``),i=e=>{if(e.previousTree&&e.previousTree===e.nextTree){r(`Choose a different shortcut: that combination is already assigned.`);return}try{ZT(e),t(e),r(`Saved on this device.`)}catch{r(`Could not save shortcuts in this browser.`)}};return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`Key bindings`,onBack:FC(),description:`Web UI shortcuts, saved on this device and available offline.`}),(0,Z.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,Z.jsx)(`h2`,{className:`font-medium`,children:`Tree navigation`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Cycle the open workspace menu’s tabs in their displayed order, including Pins and Layers. Swipe left for next or right for previous over the tab bar. Shortcuts pause while typing or using a dialog.`}),[`previousTree`,`nextTree`].map(t=>(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`label`,{htmlFor:t,className:`min-w-32 text-sm`,children:t===`previousTree`?`Previous tree`:`Next tree`}),(0,Z.jsxs)(`select`,{id:t,className:`rounded-md border bg-background p-2 text-sm`,value:e[t].split(`+`).slice(0,-1).join(`+`),onChange:n=>i({...e,[t]:n.target.value?`${n.target.value}+${e[t].slice(-1)||qT[t].slice(-1)}`:``}),children:[(0,Z.jsx)(`option`,{value:``,children:`Disabled`}),[`Alt`,`Alt+Shift`,`Ctrl+Shift`,`Meta+Shift`].map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]}),(0,Z.jsx)(`select`,{"aria-label":`${t===`previousTree`?`Previous`:`Next`} tree key`,disabled:!e[t],className:`rounded-md border bg-background p-2 text-sm disabled:opacity-50`,value:e[t].slice(-1)||qT[t].slice(-1),onChange:n=>i({...e,[t]:`${e[t].split(`+`).slice(0,-1).join(`+`)}+${n.target.value}`}),children:`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``).map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})]},t)),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Browsers and operating systems may reserve combinations. Choose another if a shortcut does not reach Canvas. Letters refer to physical keyboard positions (Q/W on a US keyboard); Meta is Command on Mac.`}),(0,Z.jsx)(`button`,{type:`button`,className:`rounded-md border px-3 py-2 text-sm hover:bg-accent`,onClick:()=>i({...qT}),children:`Restore defaults`}),(0,Z.jsx)(`p`,{role:`status`,className:`text-sm`,children:n})]})]})}var nE=`offline-content-v1`,rE=`offline-api-v1`,iE=1073741824,aE={enabled:!1,budgetBytes:4*iE,excludedWorkspaces:[]},oE=1e3;function sE(e){return(e.startsWith(`/`)?e:`/${e}`).replace(/\/+$/,``)||`/`}function cE(e,t,n){return`${e}:${t}:${sE(n)}`}var lE=`canvas-offline`,uE=2,dE=null;function fE(){return dE||(dE=new Promise((e,t)=>{let n=indexedDB.open(lE,uE);n.onupgradeneeded=e=>{let t=n.result;if(t.objectStoreNames.contains(`config`)||t.createObjectStore(`config`),t.objectStoreNames.contains(`entries`)||t.createObjectStore(`entries`,{keyPath:`url`}),e.oldVersion>=1&&t.objectStoreNames.contains(`pins`)){t.deleteObjectStore(`pins`);let e=n.transaction.objectStore(`entries`).openCursor();e.onsuccess=()=>{let t=e.result;if(!t)return;let n=t.value;n.pinned&&t.update({...n,pinned:!1}),t.continue()}}t.objectStoreNames.contains(`scopes`)||t.createObjectStore(`scopes`,{keyPath:`id`})},n.onsuccess=()=>{n.result.onversionchange=()=>{n.result.close(),dE=null},e(n.result)},n.onerror=()=>{dE=null,t(n.error)}}),dE)}function pE(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}function mE(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}async function hE(e,t){return mE((await fE()).transaction(e).objectStore(e).get(t))}async function gE(e){return mE((await fE()).transaction(e).objectStore(e).getAll())}async function _E(e,t,n){let r=(await fE()).transaction(e,`readwrite`);return r.objectStore(e).put(t,n),pE(r)}async function vE(e,t){let n=(await fE()).transaction(e,`readwrite`);return n.objectStore(e).delete(t),pE(n)}async function yE(e){let t=(await fE()).transaction(e,`readwrite`);return t.objectStore(e).clear(),pE(t)}async function bE(){try{let e=await hE(`config`,`settings`);return e?{...aE,...e}:aE}catch{return aE}}async function xE(e){await _E(`config`,e,`settings`)}async function SE(e,t){let n=(await fE()).transaction(`entries`,`readwrite`),r=n.objectStore(`entries`);for(let n of e){let e=r.get(n);e.onsuccess=()=>{let i=e.result;i?r.put({...i,pinned:t}):t&&r.put({url:n,kind:`content`,size:0,lastAccess:Date.now(),pinned:t})}}return pE(n)}async function CE(e){let t=await gE(`entries`),n=t.filter(e=>e.kind===`api`).sort((e,t)=>e.lastAccess-t.lastAccess),r=n.slice(0,Math.max(0,n.length-oE)),i=t.filter(e=>e.kind===`content`),a=i.reduce((e,t)=>e+t.size,0),o=i.filter(e=>!e.pinned).sort((e,t)=>e.lastAccess-t.lastAccess),s=[];for(let t of o){if(a<=e)break;s.push(t),a-=t.size}if(!r.length&&!s.length)return;let[c,l]=await Promise.all([caches.open(rE),caches.open(nE)]);await Promise.all([...r.map(async e=>{await c.delete(e.url),await vE(`entries`,e.url)}),...s.map(async e=>{await l.delete(e.url),await vE(`entries`,e.url)})])}async function wE(){let e=await gE(`entries`),t=e.filter(e=>e.kind===`content`);return{contentBytes:t.reduce((e,t)=>e+t.size,0),contentCount:t.length,pinnedBytes:t.filter(e=>e.pinned).reduce((e,t)=>e+t.size,0),apiCount:e.length-t.length}}async function TE(){await Promise.all([caches.delete(nE),caches.delete(rE)]),await yE(`entries`),await yE(`scopes`)}async function EE(){return gE(`scopes`)}async function DE(e){return hE(`scopes`,e)}async function OE(e){await _E(`scopes`,e)}async function kE(e){let t=await hE(`scopes`,e);await vE(`scopes`,e),t?.urls.length&&await AE(t.urls)}async function AE(e){let t=await gE(`scopes`),n=new Set(t.flatMap(e=>e.urls)),r=e.filter(e=>!n.has(e));r.length&&await SE(r,!1)}var jE=3,ME=`data/schema/file`,NE=128;async function PE({workspaceRef:e,path:t,treeName:n,treeType:r},i){let a=await bE();if(!a.enabled)throw Error(`Enable the offline cache first`);if(a.excludedWorkspaces.includes(e))throw Error(`Workspace "${e}" is excluded from offline caching`);let o=cE(e,n,t),s=sE(t),c=await DE(o),l=((await Ki(e,s,[],{limit:1e4,treeName:n,treeType:r})).payload??[]).filter(e=>e.schema===ME),u=[],d=0,f=0,p=!1,m=l.length;i?.({done:f,total:m,bytes:d});let h=0;await Promise.all(Array.from({length:Math.min(jE,l.length)},async()=>{for(;h<l.length;){let t=l[h++];if(d>=a.budgetBytes*.9){p=!0;return}try{let{blob:n}=await Yr(e,t.id);d+=n.size,u.push(`${Qr.workspaces}/${e}/documents/${t.id}/content`);try{await di(e,t.id,NE),u.push(`${Qr.workspaces}/${e}/documents/${t.id}/thumbnail?size=${NE}`)}catch{}}catch{}f+=1,i?.({done:f,total:m,bytes:d})}})),await SE(u,!0);let g={id:o,workspaceRef:e,treeName:n,treeType:r,path:s,urls:u,bytes:d,warmedAt:Date.now(),...p?{truncated:!0}:{}};if(await OE(g),c){let e=new Set(u),t=c.urls.filter(t=>!e.has(t));t.length&&await AE(t)}return g}var FE=[{label:`1 GB`,bytes:1*iE},{label:`2 GB`,bytes:2*iE},{label:`4 GB`,bytes:4*iE},{label:`8 GB`,bytes:8*iE}];function IE(e){return e<1048576?`${(e/1024).toFixed(0)} KB`:e<1073741824?`${(e/1048576).toFixed(1)} MB`:`${(e/iE).toFixed(2)} GB`}function LE(){navigator.serviceWorker?.controller?.postMessage({type:`OFFLINE_SETTINGS_CHANGED`})}function RE(){let{showSuccessToast:e,showErrorToast:t}=to(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)([]),[u,d]=(0,X.useState)([]),[f,p]=(0,X.useState)({}),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),v=(0,X.useCallback)(()=>{bE().then(r).catch(()=>{}),wE().then(a).catch(()=>{}),EE().then(e=>d(e.sort((e,t)=>e.id.localeCompare(t.id)))).catch(()=>{}),navigator.storage?.persisted?.().then(s).catch(()=>{})},[]);(0,X.useEffect)(()=>{v(),Pr().then(e=>l(e.map(e=>e.name).filter(Boolean).sort())).catch(()=>{})},[v]);let y=async e=>{r(e),await xE(e),LE(),e.enabled&&navigator.storage?.persist?.().then(s).catch(()=>{}),CE(e.budgetBytes).then(v).catch(()=>{})},b=e=>{if(!n)return;let t=n.excludedWorkspaces.includes(e)?n.excludedWorkspaces.filter(t=>t!==e):[...n.excludedWorkspaces,e];y({...n,excludedWorkspaces:t})},x=async()=>{h(!0);try{await TE(),e(`Offline cache cleared`),v()}catch(e){t(e instanceof Error?e.message:`Failed to clear cache`)}finally{h(!1)}},S=async n=>{let r=cE(n.workspaceRef,n.treeName,n.path);p(e=>({...e,[r]:{done:0,total:0,bytes:0}}));try{let t=await PE(n,e=>p(t=>({...t,[r]:e})));e(t.truncated?`Pinned ${IE(t.bytes)} — stopped at the size budget`:`Pinned ${t.workspaceRef}:/${t.path} (${IE(t.bytes)})`)}catch(e){t(e instanceof Error?e.message:`Failed to pin`)}finally{p(e=>{let{[r]:t,...n}=e;return n}),v()}},w=(e,t)=>{_(!1);for(let n of e)S({workspaceRef:t.workspaceName,path:n,treeName:t.treeName,treeType:t.treeType})},T=e=>({workspaceRef:e.workspaceRef,path:e.path,treeName:e.treeName||`context`,treeType:e.treeType||`context`}),E=async e=>{await kE(e),v()};return n?(0,Z.jsxs)(`div`,{className:`space-y-8`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(zE,{title:`Offline cache`,description:`Keep documents you open (and scopes you pin) readable without a connection. Cached on this device only; least-recently-used files are evicted when the size budget fills. Video streaming is not cached.`}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>y({...n,enabled:!n.enabled}),"aria-pressed":n.enabled,className:K(`focus-ring flex items-center gap-3 rounded-lg border p-4 text-left transition-colors`,n.enabled?`border-primary bg-accent`:`border-input hover:bg-muted/40`),children:[(0,Z.jsx)(C,{className:`h-5 w-5 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm font-medium`,children:n.enabled?`Enabled`:`Disabled`}),(0,Z.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.enabled?o===!1?`Storage is not persistent — the browser may still evict the cache under disk pressure`:`Documents are cached as you browse`:`Nothing is cached for offline use`})]}),n.enabled&&(0,Z.jsx)($e,{className:`h-4 w-4 shrink-0 text-primary`})]}),n.enabled&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Size budget`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:FE.map(e=>(0,Z.jsx)(J,{variant:n.budgetBytes===e.bytes?`default`:`outline`,size:`sm`,onClick:()=>y({...n,budgetBytes:e.bytes}),children:e.label},e.bytes))})]}),i&&(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between text-sm`,children:[(0,Z.jsxs)(`span`,{children:[IE(i.contentBytes),` of `,IE(n.budgetBytes),` used`]}),(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[i.contentCount,` file(s)`,i.pinnedBytes>0?`, ${IE(i.pinnedBytes)} pinned`:``]})]}),(0,Z.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${Math.min(100,i.contentBytes/n.budgetBytes*100)}%`}})})]}),(0,Z.jsx)(`div`,{children:(0,Z.jsxs)(J,{variant:`outline`,size:`sm`,onClick:x,disabled:m,children:[m?(0,Z.jsx)(Mt,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(lt,{className:`mr-1.5 h-3.5 w-3.5`}),`Clear offline cache`]})})]})]})]}),n.enabled&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(zE,{title:`Pinned scopes`,description:`A pinned scope — a workspace, or one of its tree paths — is downloaded up front and never evicted. Scopes resolve fresh on every re-warm, so moved contexts and reorganized trees are picked up; documents that left a scope return to normal eviction.`}),(0,Z.jsx)(`div`,{className:`mb-3`,children:(0,Z.jsxs)(J,{size:`sm`,onClick:()=>_(!0),disabled:!!Object.keys(f).length,children:[(0,Z.jsx)(ne,{className:`mr-1.5 h-3.5 w-3.5`}),`Pin a path…`]})}),(0,Z.jsxs)(`ul`,{className:`space-y-1`,children:[u.map(e=>{let t=f[e.id];return(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,Z.jsxs)(`span`,{className:`flex-1 truncate font-mono text-xs sm:text-sm`,children:[e.workspaceRef,`://`,e.path.replace(/^\//,``),e.treeName&&e.treeName!==`context`&&(0,Z.jsx)(`span`,{className:`ml-1.5 rounded bg-muted px-1 py-0.5 font-sans text-[10px] text-muted-foreground`,children:e.treeName})]}),t?(0,Z.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(Mt,{className:`h-3.5 w-3.5 animate-spin`}),t.total>0?`${t.done}/${t.total} · ${IE(t.bytes)}`:`listing…`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[IE(e.bytes),e.truncated?` (partial)`:``]}),(0,Z.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>S(T(e)),"aria-label":`Re-warm ${e.id}`,title:`Re-warm: re-resolve the scope and download anything new`,children:(0,Z.jsx)(Te,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>E(e.id),"aria-label":`Unpin ${e.id}`,children:(0,Z.jsx)(G,{className:`h-3.5 w-3.5`})})]})]},e.id)}),u.length===0&&(0,Z.jsx)(`li`,{className:`rounded-md border border-dashed border-input px-3 py-4 text-center text-sm text-muted-foreground`,children:`Nothing pinned — everything relies on browse-caching and LRU`})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(zE,{title:`Workspace caching`,description:`Excluded workspaces are never cached — not even as you browse — and are not served from cache.`}),(0,Z.jsx)(`ul`,{className:`space-y-1`,children:c.map(e=>{let t=n.excludedWorkspaces.includes(e);return(0,Z.jsxs)(`li`,{className:`flex items-center gap-3 rounded-md border border-input px-3 py-2 text-sm`,children:[(0,Z.jsx)(`span`,{className:K(`flex-1 truncate`,t&&`text-muted-foreground line-through`),children:e}),t&&(0,Z.jsx)(vt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(J,{variant:t?`outline`:`ghost`,size:`sm`,onClick:()=>b(e),children:t?`Include`:`Exclude`})]},e)})})]})]}),g&&(0,Z.jsx)(pp,{onClose:()=>_(!1),children:(0,Z.jsx)(dp,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,multiple:!1,tabs:[`context`,`directory`],title:`Pin for offline…`,confirmLabel:`Pin path`,onConfirm:w,onClose:()=>_(!1)})})]}):null}function zE({title:e,description:t}){return(0,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function BE(){return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`Offline`,onBack:FC(),description:`Per-device offline cache: browse notes, files, photos and saved websites without a connection.`}),(0,Z.jsx)(RE,{})]})}function VE(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function HE({name:e,version:t,detail:n}){return(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 px-4 py-2.5`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e}),n&&(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n})]}),(0,Z.jsx)(`code`,{className:`text-xs text-muted-foreground shrink-0`,children:t})]})}function UE(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=!0;return Y.get(`/ping`,{skipAuth:!0}).then(n=>{e&&t(n??{})}).catch(t=>{e&&r(t instanceof Error?t.message:`Failed to reach the server`)}),()=>{e=!1}},[]);let i=[e?.commit?`commit ${e.commit.slice(0,7)}`:null,typeof e?.uptime==`number`?`up ${VE(e.uptime)}`:null].filter(Boolean).join(` · `),a=Object.entries(e?.components??{}).sort(([e],[t])=>e.localeCompare(t));return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,Z.jsx)(pb,{className:`mb-6`,title:`About`,onBack:FC(),description:`Versions of every Canvas component this installation is running.`}),(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`section`,{className:`rounded-md border border-border divide-y divide-border`,children:[(0,Z.jsx)(HE,{name:`Canvas Web`,detail:`this interface`,version:`v2.14.18`}),e?.version&&(0,Z.jsx)(HE,{name:e.productName||e.appName||`Canvas Server`,detail:i||void 0,version:`v${e.version}`})]}),a.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Server components`}),(0,Z.jsx)(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:a.map(([e,t])=>(0,Z.jsx)(HE,{name:e,version:`v${t}`},e))})]}),n&&(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Server details unavailable: `,n]}),e?.sourceUrl&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.license?`Licensed ${e.license}. `:``,(0,Z.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})]})]})}var WE=[`onnx`,`clip`,`blip`,`openai`],GE=[`onnx`,`clip`,`blip`,`ollama`,`vllm`],KE=[{id:`openai`,baseUrl:`https://api.openai.com/v1`,label:`OpenAI`},{id:`vllm`,baseUrl:`http://127.0.0.1:8000/v1`,label:`vLLM`},{id:`ollama`,baseUrl:`http://127.0.0.1:11434/v1`,label:`Ollama`}],qE=e=>`${Qr.workspaces}/${encodeURIComponent(e)}/inferd`;function JE(e,t){let n={};for(let[r,i]of Object.entries(e.providers||{})){let e={...i};delete e.apiKeySet,delete e.headerNames,t.has(r)&&i.apiKey?e.apiKey=i.apiKey:delete e.apiKey,n[r]=e}return{...e,providers:n}}async function YE(e){return await Y.get(`${qE(e)}/status`)}async function XE(e,t={}){let n={};return t.force!==void 0&&(n.force=t.force),await Y.post(`${qE(e)}/summarize/images`,n)}async function ZE(e){return await Y.post(`${qE(e)}/summarize/images/stop`,{})}async function QE(e){return await Y.get(`${qE(e)}/config`)}async function $E(e,t){return await Y.put(`${qE(e)}/config`,t)}async function eD(e,t={}){let n={};return t.space&&(n.space=t.space),t.reindex!==void 0&&(n.reindex=t.reindex),t.scope&&(n.scope=t.scope),await Y.post(`${qE(e)}/reindex`,n)}async function tD(e){return await Y.get(`${qE(e)}/vector-tables`)}async function nD(e,t){return await Y.delete(`${qE(e)}/vector-tables/${encodeURIComponent(t)}`)}async function rD(){return await Y.get(`${Qr.inferd}/config`)}async function iD(e){return await Y.put(`${Qr.inferd}/config`,e)}async function aD(){return await Y.get(`${Qr.inferd}/defaults`)}async function oD(e){return await Y.put(`${Qr.inferd}/defaults`,e)}async function sD(e,t){let n={...e};return delete n.apiKeySet,delete n.headerNames,(await Y.post(`${Qr.inferd}/test`,{provider:n,...t?{model:t}:{},probe:!0})).cached??null}async function cD(e,t,n=`text`){let r={...e};return delete r.apiKeySet,delete r.headerNames,await Y.post(`${Qr.inferd}/test`,{provider:r,...t?{model:t}:{},modality:n})}var lD=`h-8 w-full rounded-md border bg-background px-2 text-sm outline-none focus:ring-2 focus:ring-ring`,uD=`font-semibold uppercase tracking-[0.08em]`,dD={openai:{url:{key:`baseUrl`,label:`Base URL`,placeholder:`http://gpu.local:8000/v1`,hint:`OpenAI-compatible embeddings endpoint — Ollama, vLLM, TEI, infinity, LM Studio and OpenAI itself all speak this. A trailing /v1 is optional; both http://host:8000 and http://host:8000/v1 work.`},apiKey:"Sent as `Authorization: Bearer …`. Leave empty for servers that do not check it.",imageInput:!0,timeoutMs:!0,headers:!0,where:e=>e.baseUrl||`no endpoint set`},ollama:{url:{key:`host`,label:`Host (legacy)`,placeholder:`http://127.0.0.1:11434`,hint:`Written by an older version. Switch the type to openai — the host becomes the base URL and the /v1 suffix is added for you.`},apiKey:"Sent as `Authorization: Bearer …`.",where:e=>e.host||`http://127.0.0.1:11434`},onnx:{cacheDir:`Where downloaded weights are cached on the server. Empty uses the server default.`,note:`Runs in-process on the server. No endpoint and no credentials.`,where:()=>`in-process`},clip:{cacheDir:`Where downloaded weights are cached on the server. Empty uses the server default.`,note:`Runs in-process on the server. No endpoint and no credentials.`,where:()=>`in-process`}},fD=[`baseUrl`,`host`,`apiKey`,`cacheDir`,`imageInput`,`timeoutMs`],pD=[{value:`data-uri`,label:`data-uri (default)`,hint:"Images ride in the ordinary `input` array as data URIs (infinity, TEI-style servers)."},{value:`messages`,label:`messages`,hint:`vLLM's multimodal shape: one request per image, wrapped in a chat message.`}],mD=12e4;function hD(e){if(typeof e!=`string`||e.trim()===``)return null;let t;try{t=new URL(e.trim())}catch{return`Must be an absolute URL including the scheme, e.g. http://127.0.0.1:11434`}return t.protocol!==`http:`&&t.protocol!==`https:`?`Unsupported scheme '${t.protocol.replace(`:`,``)}'. Use http or https.`:null}function gD({title:e,hint:t}){return(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(`h3`,{className:K(`text-[11px] text-muted-foreground`,uD),children:e}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:t})]})}function _D({overridden:e,source:t}){return e?(0,Z.jsx)(`span`,{className:`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,title:`Set on this layer; it wins over anything inherited`,children:`overridden`}):(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground`,title:t?`Inherited: ${t}`:`Inherited from a lower config layer`,children:`inherited`})}function vD({label:e,value:t,inheritedValue:n,onChange:r,type:i=`text`,placeholder:a,disabled:o,hint:s,error:c,mono:l}){let u=t!==void 0&&t!==``;return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:e}),(0,Z.jsx)(_D,{overridden:u,source:n===void 0?void 0:String(n)}),u&&!o&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>r(``),className:`text-[10px] text-muted-foreground underline hover:text-foreground`,title:`Clear the override and fall back to the inherited value`,children:`reset`})]}),(0,Z.jsx)(q,{type:i,value:t??``,disabled:o,onChange:e=>r(e.target.value),placeholder:a??(n===void 0?`—`:String(n)),className:K(`h-8 text-sm`,l&&`font-mono`,c&&`border-destructive focus-visible:ring-destructive`)}),c&&(0,Z.jsx)(`p`,{className:`text-[11px] font-medium text-destructive`,children:c}),s&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:s})]})}function yD({label:e,checked:t,overridden:n,disabled:r,onChange:i}){return(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:r,checked:t,onChange:e=>i(e.target.checked)}),e,(0,Z.jsx)(_D,{overridden:n})]})}function bD({storedNames:e,value:t,disabled:n,onChange:r}){let i=t!==void 0,[a,o]=(0,X.useState)([]),s=e=>{o(e),r(Object.fromEntries(e.filter(([e])=>e.trim()!==``)))};return(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Custom headers`}),i?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`rounded bg-warning-subtle px-1.5 py-0.5 text-[10px] font-medium text-warning`,children:`will replace stored`}),!n&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{o([]),r(void 0)},className:`text-[10px] text-muted-foreground underline hover:text-foreground`,children:`cancel`})]}):(0,Z.jsx)(_D,{overridden:!1,source:e?.join(`, `)})]}),!i&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e?.length?(0,Z.jsxs)(Z.Fragment,{children:[`Stored: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.join(`, `)}),` (values are never sent back)`]}):`None set.`}),!n&&(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{o([[``,``]]),r({})},children:e?.length?`Replace headers`:`Add headers`})]}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Saving replaces every stored header, so re-enter the ones you want to keep.`}),a.map(([e,t],r)=>(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(q,{value:e,disabled:n,placeholder:`X-Tenant`,className:`h-8 font-mono text-sm`,onChange:e=>s(a.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,Z.jsx)(q,{value:t,disabled:n,placeholder:`value`,className:`h-8 font-mono text-sm`,onChange:e=>s(a.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,disabled:n,"aria-label":`Remove header ${e||r+1}`,onClick:()=>s(a.filter((e,t)=>t!==r)),children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]},r)),!n&&(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>s([...a,[``,``]]),children:[(0,Z.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),`Add header`]})]})]})}function xD({open:e,onClick:t,label:n}){return(0,Z.jsx)(`button`,{type:`button`,onClick:t,"aria-expanded":e,title:n,"aria-label":n,className:`flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:(0,Z.jsx)(Ge,{className:K(`h-4 w-4 transition-transform motion-reduce:transition-none`,e&&`rotate-180`)})})}var SD={configured:`bg-success`,"needs-fill":`bg-warning`,unresolved:`bg-destructive`,unset:`bg-muted-foreground/30`};function CD({value:e,effective:t,inherited:n,resolvedSpaces:r,invalid:i,attention:a,onFill:o,saving:s=!1,disabled:c=!1,saveLabel:l=`Save`,onSave:u}){let{showToast:d}=po(),[f,p]=(0,X.useState)(()=>structuredClone(e)),[m,h]=(0,X.useState)(new Set),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(null),E=(0,X.useMemo)(()=>[...new Set([...Object.keys(t.spaces||{}),...Object.keys(f.spaces||{})])].sort(),[t.spaces,f.spaces]),D=(0,X.useMemo)(()=>[...new Set([...Object.keys(t.providers||{}),...Object.keys(f.providers||{})])].sort(),[t.providers,f.providers]),O=(e,t,n)=>{p(r=>{let i={...r.spaces||{}},a={...i[e]||{}};if(n===``)delete a[t];else if(t===`dim`||t===`maxLength`||t===`dimensions`){let e=Number(n);if(Number.isNaN(e))return r;a[t]=e}else a[t]=n;return Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,spaces:i}})},k=(e,t,n)=>{p(r=>{let i={...r.spaces||{}},a={...i[e]||{}};return n===void 0?delete a[t]:a[t]=n,Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,spaces:i}})},A=(e,t,n)=>{t===`apiKey`&&h(t=>{let r=new Set(t);return n===``?r.delete(e):r.add(e),r}),p(r=>{let i={...r.providers||{}},a={...i[e]||{}};if(n===``)delete a[t];else if(t===`timeoutMs`){let e=Number(n);if(Number.isNaN(e))return r;a[t]=e}else a[t]=n;return Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,providers:i}})},j=(e,t,n)=>{p(r=>{let i={...r.providers||{}},a={...i[e]||{}};return n===void 0?delete a[t]:a[t]=n,Object.keys(a).length===0?delete i[e]:i[e]=a,{...r,providers:i}})},M=e=>{p(t=>{let n={...t.providers||{}};return delete n[e],{...t,providers:n}}),h(t=>{let n=new Set(t);return n.delete(e),n})},N=()=>{let e=S.trim();if(e){if(E.includes(e)){d({title:`Space exists`,description:`'${e}' already has a row below.`,variant:`destructive`});return}p(t=>({...t,spaces:{...t.spaces||{},[e]:{}}})),C(``),T(`space:${e}`)}},P=(e,t)=>{if(e){if(D.includes(e)){d({title:`Backend exists`,description:`'${e}' is already declared. Open it below to edit.`,variant:`destructive`});return}p(n=>({...n,providers:{...n.providers||{},[e]:{type:`openai`,...t?{baseUrl:t}:{}}}})),x(``),T(`provider:${e}`)}},F=e=>({...t.providers?.[e]||{},...f.providers?.[e]||{}}),I=async e=>{let n=f.spaces?.[e]?.provider??t.spaces?.[e]?.provider,r=f.spaces?.[e]?.model??t.spaces?.[e]?.model;if(!n){d({title:`No backend`,description:`Space '${e}' has no backend to test.`,variant:`destructive`});return}let i=F(n),a=i.type?dD[i.type]?.url?.key:void 0,o=a?hD(i[a]):null;if(o){d({title:`Backend '${n}'`,description:o,variant:`destructive`});return}_(e);try{try{await sD(i,r)===!1&&(y(!0),d({title:`Downloading model`,description:`'${r??`the configured model`}' is not in the server's cache yet; downloading now. A first test can take a few minutes; the model is then cached for good.`}))}catch{}let n=await cD(i,r,e),a=f.spaces?.[e]?.dim??t.spaces?.[e]?.dim,o=n.dim>0&&a!==void 0&&n.dim!==a;(o||n.dim>0&&a===void 0)&&O(e,`dim`,String(n.dim)),d({title:o?`Backend answered; dimensions corrected`:`Backend answered`,description:o?`Returned ${n.dim}-d but '${e}' was set to ${a}-d. Dimensions updated to ${n.dim}; save to apply. (${n.latencyMs} ms)`:`${n.dim}-d in ${n.latencyMs} ms`})}catch(e){d({title:`Test failed`,description:e instanceof Error?e.message:`Backend unreachable`,variant:`destructive`})}finally{_(null),y(!1)}},ee=(0,X.useMemo)(()=>{let e=[];for(let[n,r]of Object.entries(f.providers||{})){let i=r.type??t.providers?.[n]?.type,a=i?dD[i]?.url?.key:void 0;if(!a)continue;let o=hD(r[a]);o&&e.push(`${n}: ${o}`)}return e},[f.providers,t.providers]),te=(0,X.useMemo)(()=>JSON.stringify(f)!==JSON.stringify(e)||m.size>0,[f,e,m]),ne=async()=>{if(ee.length>0){d({title:`Fix the endpoint first`,description:ee.join(` · `),variant:`destructive`});return}await u(JE(f,m)),h(new Set)},re=e=>T(t=>t===e?null:e);return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[i&&(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive-subtle p-3 text-xs`,children:[(0,Z.jsx)(at,{className:`mt-0.5 h-4 w-4 shrink-0 text-destructive`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`font-medium text-destructive`,children:`Stored config does not resolve; defaults are standing in`}),(0,Z.jsx)(`p`,{className:`mt-0.5 font-mono text-[11px] text-muted-foreground`,children:i})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(gD,{title:`Search models`,hint:`Choose a provider and model for each kind of content. After switching models, fill the new index to make existing documents searchable. Previous model indexes are preserved.`}),E.length===0?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-dashed p-6 text-center`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:`No spaces on this layer`}),(0,Z.jsx)(`p`,{className:`mx-auto mt-1 max-w-sm text-xs text-muted-foreground`,children:`A space needs a backend, a model and a dimension count. Add one below to start embedding.`})]}):(0,Z.jsx)(`div`,{className:`divide-y overflow-hidden rounded-lg border`,children:E.map(e=>{let s=f.spaces?.[e]||{},l=t.spaces?.[e]||{},u=n.spaces?.[e]||{},d=r?.[e],p=`space:${e}`,m=w===p,h=s.model??l.model,_=s.provider??l.provider,y=s.dim??l.dim,b=s.chunk??l.chunk??!1,x=a?.includes(e)??!1;return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`span`,{className:K(`absolute inset-y-0 left-0 w-[3px]`,SD[i?`unresolved`:x?`needs-fill`:h?`configured`:`unset`]),"aria-hidden":!0}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 py-3 pl-4 pr-3 sm:flex-row sm:items-start sm:gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,Z.jsx)(`span`,{className:K(`text-[11px]`,uD),children:e}),(0,Z.jsx)(`span`,{className:`truncate font-mono text-sm`,children:h||`no model set`}),_&&(0,Z.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:[`via `,_]}),y!==void 0&&(0,Z.jsxs)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:[y,`-d`]}),b&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`chunked`})]}),r&&h&&(0,Z.jsxs)(`p`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground`,title:`Vector table backing this space`,children:[`└─ `,d?.table??(0,Z.jsx)(`span`,{className:`not-italic`,children:`not created yet`})]}),x&&(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-warning`,children:`New table, nothing embedded in it yet; dense search stays thin for this space until it is filled. Reverting the model is still instant.`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 max-sm:justify-end`,children:[x&&o&&(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>o(e),children:`Fill`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,disabled:c||g!==null,onClick:()=>I(e),title:`Round-trip a real embedding call against this backend and report the dimensions it returns`,children:[(0,Z.jsx)(ye,{className:`mr-1.5 h-3.5 w-3.5`}),g===e?v?`Downloading…`:`Testing…`:`Test`]}),(0,Z.jsx)(xD,{open:m,onClick:()=>re(p),label:`Edit ${e}`})]})]}),m&&(0,Z.jsxs)(`div`,{className:`border-t bg-muted/40 py-4 pl-4 pr-3`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Backend`}),(0,Z.jsx)(_D,{overridden:s.provider!==void 0,source:u.provider})]}),(0,Z.jsxs)(`select`,{className:lD,disabled:c,value:s.provider??``,onChange:t=>O(e,`provider`,t.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:l.provider?`inherited: ${l.provider}`:`inherited`}),D.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Z.jsx)(vD,{label:`Model`,mono:!0,value:s.model,inheritedValue:l.model,onChange:t=>O(e,`model`,t),disabled:c}),(0,Z.jsx)(vD,{label:`Dimensions`,type:`number`,value:s.dim,inheritedValue:l.dim,onChange:t=>O(e,`dim`,t),disabled:c,hint:`Sizes the vector table. Test asks the backend and fills in what it really returns.`}),(0,Z.jsx)(vD,{label:`Max length`,type:`number`,value:s.maxLength,inheritedValue:l.maxLength,onChange:t=>O(e,`maxLength`,t),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-4`,children:[(0,Z.jsx)(yD,{label:`Chunk long inputs`,checked:b,overridden:s.chunk!==void 0,disabled:c,onChange:t=>k(e,`chunk`,t)}),(0,Z.jsx)(yD,{label:`Build ANN index`,checked:s.annIndex??l.annIndex??!0,overridden:s.annIndex!==void 0,disabled:c,onChange:t=>k(e,`annIndex`,t)})]})]})]},e)})}),!c&&(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(q,{value:S,onChange:e=>C(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),N())},placeholder:`new space name (e.g. audio)`,className:`h-8 w-full max-w-xs text-sm sm:w-auto`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:N,children:[(0,Z.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),`Add space`]})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(gD,{title:`Model providers`,hint:`Connect a service here, then select it under Search models above. Built-in providers work without an extra connection. Provider changes take effect when you save.`}),(0,Z.jsx)(`div`,{className:`divide-y overflow-hidden rounded-lg border`,children:D.map(e=>{let n=f.providers?.[e]||{},r=t.providers?.[e]||{},i=GE.includes(e),a=f.providers?.[e]!==void 0,o=`provider:${e}`,s=w===o,l=n.type??r.type,u=l?dD[l]:void 0,d=u?.url?hD(n[u.url.key]):null,p={...r,...n},h=fD.filter(e=>!(n[e]===void 0||e===u?.url?.key||e===`apiKey`&&u?.apiKey||e===`cacheDir`&&u?.cacheDir)),g=E.filter(n=>(f.spaces?.[n]?.provider??t.spaces?.[n]?.provider)===e);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3 sm:flex-row sm:items-start sm:gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-sm font-semibold`,children:e}),(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:l??`no type`}),i&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`built-in`}),p.apiKeySet&&!m.has(e)&&(0,Z.jsx)(`span`,{className:`text-[10px] font-medium text-success`,children:`key set`}),d&&(0,Z.jsx)(`span`,{className:`text-[10px] font-medium text-destructive`,children:`check endpoint`})]}),(0,Z.jsx)(`p`,{className:`mt-1 truncate font-mono text-[11px] text-muted-foreground`,children:u?u.where(p):`—`}),g.length>0&&(0,Z.jsxs)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:[`used by `,g.join(`, `)]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 max-sm:justify-end`,children:[a&&!i&&!c&&(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>M(e),title:`Remove this override`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(xD,{open:s,onClick:()=>re(o),label:`Edit ${e}`})]})]}),s&&(0,Z.jsxs)(`div`,{className:`border-t bg-muted/40 px-4 py-4`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Type`}),(0,Z.jsx)(_D,{overridden:n.type!==void 0,source:r.type})]}),(0,Z.jsxs)(`select`,{className:lD,disabled:c,value:n.type??``,onChange:t=>A(e,`type`,t.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:r.type?`inherited: ${r.type}`:`inherited`}),WE.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e)),l&&!WE.includes(l)&&(0,Z.jsxs)(`option`,{value:l,children:[l,` (legacy)`]})]}),u?.note&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:u.note})]}),u?.url&&(0,Z.jsx)(vD,{label:u.url.label,mono:!0,value:n[u.url.key],inheritedValue:r[u.url.key],onChange:t=>A(e,u.url.key,t),disabled:c,placeholder:r[u.url.key]??u.url.placeholder,hint:u.url.hint,error:d??void 0}),u?.cacheDir&&(0,Z.jsx)(vD,{label:`Cache directory`,mono:!0,value:n.cacheDir,inheritedValue:r.cacheDir,onChange:t=>A(e,`cacheDir`,t),disabled:c,placeholder:r.cacheDir??`server default`,hint:u.cacheDir}),u?.imageInput&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Image input shape`}),(0,Z.jsx)(_D,{overridden:n.imageInput!==void 0,source:r.imageInput})]}),(0,Z.jsxs)(`select`,{className:lD,disabled:c,value:n.imageInput??``,onChange:t=>A(e,`imageInput`,t.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:r.imageInput?`inherited: ${r.imageInput}`:`inherited: data-uri`}),pD.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:pD.find(e=>e.value===(n.imageInput??r.imageInput??`data-uri`))?.hint})]}),u?.timeoutMs&&(0,Z.jsx)(vD,{label:`Request timeout (ms)`,type:`number`,value:n.timeoutMs,inheritedValue:r.timeoutMs??mD,onChange:t=>A(e,`timeoutMs`,t),disabled:c,hint:`How long to wait for a batch before giving up. Raise it for a slow or cold GPU host.`}),u?.apiKey&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`API key`}),m.has(e)&&(0,Z.jsx)(`span`,{className:`rounded bg-warning-subtle px-1.5 py-0.5 text-[10px] font-medium text-warning`,children:`will be written`})]}),(0,Z.jsx)(q,{type:`password`,autoComplete:`new-password`,disabled:c,value:n.apiKey??``,onChange:t=>A(e,`apiKey`,t.target.value),placeholder:r.apiKeySet?`•••••••• (stored; leave empty to keep)`:`unset`,className:`h-8 text-sm`}),(0,Z.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[u.apiKey,` Write-only: the stored key is never sent back, and leaving this empty keeps whatever is stored.`]})]})]}),u?.headers&&(0,Z.jsx)(bD,{disabled:c,storedNames:r.headerNames,value:n.headers,onChange:t=>j(e,`headers`,t)}),h.length>0&&!c&&(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2 rounded-md border border-dashed p-2 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{children:[`Not used by type `,(0,Z.jsx)(`span`,{className:`font-mono`,children:l}),`:`,` `,(0,Z.jsx)(`span`,{className:`font-mono`,children:h.join(`, `)})]}),(0,Z.jsx)(`button`,{type:`button`,className:`underline hover:text-foreground`,onClick:()=>h.forEach(t=>A(e,t,``)),children:`clear`})]}),r.headerNames&&r.headerNames.length>0&&(0,Z.jsxs)(`p`,{className:`mt-3 text-[11px] text-muted-foreground`,children:[`Stored custom headers: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:r.headerNames.join(`, `)}),` (values not shown)`]})]})]},e)})}),!c&&(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(q,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),P(b.trim()))},placeholder:`new backend name (e.g. gpu)`,className:`h-8 w-full max-w-xs text-sm sm:w-auto`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>P(b.trim()),children:[(0,Z.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),`Add backend`]}),KE.filter(e=>!D.includes(e.id)).map(e=>(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>P(e.id,e.baseUrl),title:`Add an openai-type backend '${e.id}' pointed at ${e.baseUrl}`,children:e.label},e.id))]})]}),!c&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-t pt-4`,children:[(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:te?`default`:`outline`,onClick:ne,disabled:s||!te||ee.length>0,children:s?`Saving…`:l}),(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,disabled:s||!te,onClick:()=>{p(structuredClone(e)),h(new Set)},children:`Discard changes`}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ee.length>0?(0,Z.jsxs)(`span`,{className:`font-medium text-destructive`,children:[ee.length,` endpoint `,ee.length===1?`needs`:`need`,` fixing`]}):te?`Unsaved changes`:`Everything saved`})]})]})}function wD(){let{showToast:e}=po(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(!0),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),l=(0,X.useCallback)(()=>rD().then(e=>{n(e),c(null)}).catch(e=>c(e instanceof Error?e.message:`Failed to load embedding defaults`)).finally(()=>i(!1)),[]);(0,X.useEffect)(()=>{l()},[l]);let u=()=>{i(!0),l()};return(0,Z.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,Z.jsx)(pb,{compact:!0,className:`mb-6`,title:`Search & AI defaults`,onBack:FC(),description:`Your account · Choose the embedding models used for text and image search. Workspace settings override these defaults. Running workspaces adopt new defaults when restarted.`,actions:(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:u,disabled:r,children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5`}),`Refresh`]})}),r?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(Te,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):s||!t?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-destructive`,children:`Embedding defaults unavailable`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:s||`No config returned.`})]}),(0,Z.jsx)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:u,children:`Retry`})]}):(0,Z.jsx)(CD,{value:t.user||{},effective:t.effective||{},inherited:t.serverDefaults||{},invalid:t.invalid,saving:a,saveLabel:`Save defaults`,onSave:async t=>{o(!0);try{let n=await iD(t);e({title:`Defaults saved`,description:n.restartRequired?`${n.workspaces.length} running workspace(s) keep their current tables until restarted. Set the config on a workspace directly to change it live.`:`New workspaces will inherit this.`}),await l()}catch(t){e({title:`Save failed`,description:t instanceof Error?t.message:`Failed to save`,variant:`destructive`})}finally{o(!1)}}},JSON.stringify(t.user))]})}function TD(){let e=Jc(),{showToast:t}=po(),n=new URLSearchParams(e.search),r=e=>{try{let t=new URL(e);return t.pathname.includes(`/rest/v2/workspaces/`)&&!t.pathname.includes(`/rest/v2/pub/`)?t.pathname=t.pathname.replace(`/rest/v2/workspaces/`,`/rest/v2/pub/workspaces/`):t.pathname.includes(`/rest/v2/contexts/`)&&!t.pathname.includes(`/rest/v2/pub/`)&&(t.pathname=t.pathname.replace(`/rest/v2/contexts/`,`/rest/v2/pub/contexts/`)),t.toString()}catch{return e}},i=r(n.get(`url`)||``),a=sessionStorage.getItem(`sharedToken:last`)||``,[o,s]=(0,X.useState)(i),[c,l]=(0,X.useState)(a),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)([]),[m,h]=(0,X.useState)(!1),g=(0,X.useMemo)(()=>{try{let e=new URL(o);return e.pathname.includes(`/pub/workspaces/`)?`workspace`:e.pathname.includes(`/pub/contexts/`)?`context`:`unknown`}catch{return`unknown`}},[o]),_=()=>({Authorization:`Bearer ${c.trim()}`}),v=async()=>{if(!(!o||!c)){h(!0);try{let e=r(o),t=await Y.get(e,{skipAuth:!0,headers:_()});d(t);let n=await Y.get(`${e}/documents`,{skipAuth:!0,headers:_()}),i=Array.isArray(n)?n:Array.isArray(n?.data)?n.data:[];p(Array.isArray(i)?i:[])}catch(e){let n=o.includes(`/rest/v2/workspaces/`)?`Ensure the URL uses /rest/v2/pub/workspaces/<workspace-id> and the token matches that workspace.`:o.includes(`/rest/v2/contexts/`)?`Ensure the URL uses /rest/v2/pub/contexts/<context-id>.`:void 0;t({title:`Error`,description:`${e instanceof Error?e.message:`Failed to load shared resource`}${n?`: ${n}`:``}`,variant:`destructive`}),d(null),p([])}finally{h(!1)}}},y=(0,X.useRef)(v);return(0,X.useEffect)(()=>{y.current()},[]),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(pb,{onBack:FC(),title:`Shared Resource Viewer`,description:`Open a resource someone shared with you.`}),(0,Z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-3`,children:[(0,Z.jsx)(q,{value:o,onChange:e=>s(e.target.value),placeholder:`Full pub URL`}),(0,Z.jsx)(q,{value:c,onChange:e=>l(e.target.value),placeholder:`Access token (canvas-...)`}),(0,Z.jsx)(J,{onClick:v,disabled:m||!o||!c,children:`Load`})]}),(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`Type: `,g]}),m?(0,Z.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`Loading...`}):(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`border rounded p-3`,children:[(0,Z.jsx)(`h2`,{className:`font-semibold mb-2`,children:`Metadata`}),(0,Z.jsx)(`pre`,{className:`text-xs overflow-auto max-h-80`,children:JSON.stringify(u,null,2)})]}),(0,Z.jsxs)(`div`,{className:`border rounded p-3`,children:[(0,Z.jsxs)(`h2`,{className:`font-semibold mb-2`,children:[`Documents (`,f.length,`)`]}),f.length===0?(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No documents`}):(0,Z.jsx)(`ul`,{className:`space-y-2 text-sm`,children:f.slice(0,100).map((e,t)=>(0,Z.jsxs)(`li`,{className:`border rounded p-2`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-xs`,children:e.id}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.schema})]},t))})]})]}),(0,Z.jsx)(qu,{className:`mt-8`})]})}function ED(e={}){let t=new URLSearchParams;e.tail&&t.set(`tail`,String(e.tail)),e.level&&t.set(`level`,e.level),e.module&&t.set(`module`,e.module);let n=t.toString();return n?`?${n}`:``}function DD(){let e=localStorage.getItem(`authToken`);if(!e)throw Error(`Authentication required`);let t=localStorage.getItem(`appName`)||window.location.hostname;return{Authorization:`Bearer ${e}`,"X-App-Name":t,Accept:`text/event-stream`}}var OD={async listUsers(e){let t=new URLSearchParams;e?.status&&t.append(`status`,e.status),e?.userType&&t.append(`userType`,e.userType);let n=t.toString(),r=n?`${Qr.admin.users}?${n}`:Qr.admin.users;return await Y.get(r)},async getUser(e){return await Y.get(`${Qr.admin.users}/${e}`)},async createUser(e){return await Y.post(Qr.admin.users,e)},async updateUser(e,t){return await Y.put(`${Qr.admin.users}/${e}`,t)},async deleteUser(e){await Y.delete(`${Qr.admin.users}/${e}`)}},kD={async listAllWorkspaces(){return await Y.get(Qr.admin.workspaces)},async createWorkspace(e){return await Y.post(Qr.admin.workspaces,e)},async deleteWorkspace(e){await Y.delete(`${Qr.admin.workspaces}/${e}`)}},AD={async getLogs(e={}){return(await Y.get(`${Qr.admin.logs}${ED(e)}`)).logs||[]},async streamLogs(e={},t={}){let{signal:n,onEntry:r,onError:i}=t;try{let t=await fetch(`${Qr.admin.logsStream}${ED(e)}`,{method:`GET`,headers:DD(),credentials:`include`,signal:n});if(!t.ok)throw Error(`Failed to open log stream (${t.status})`);if(!t.body)throw Error(`Streaming is not supported by this browser`);let i=t.body.getReader(),a=new TextDecoder,o=``,s=e=>{let t=e.split(`
|
|
19
19
|
`),n=`message`,i=[];for(let e of t)if(!(!e||e.startsWith(`:`))){if(e.startsWith(`event:`)){n=e.slice(6).trim();continue}e.startsWith(`data:`)&&i.push(e.slice(5).trim())}if(n!==`log`||i.length===0)return;let a=JSON.parse(i.join(`
|
|
20
20
|
`));r?.(a)};try{for(;;){let{done:e,value:t}=await i.read();if(e)break;o+=a.decode(t,{stream:!0});let n=o.split(`
|
|
21
21
|
|
|
@@ -74,8 +74,8 @@ Body: {{doc.data.body}}`,value:t.b,onChange:e=>r({b:e.target.value})})}),a(`repl
|
|
|
74
74
|
# Called from a hook via: spawn('bash', [script, ...args])
|
|
75
75
|
set -euo pipefail
|
|
76
76
|
`;function Q$({workspaceId:e,prefillRule:t,onPrefillConsumed:n,initialSection:r,initialRunsHandler:i,initialRunId:a}){let{showToast:o}=po(),[s,c]=(0,X.useState)(r??`rules`),[l,u]=(0,X.useState)(t);t!==l&&(u(t),t&&c(`rules`));let[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)([]),[h,g]=(0,X.useState)(!0),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(``),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(`document.inserted`),[N,P]=(0,X.useState)(``),[F,I]=(0,X.useState)([]),[ee,te]=(0,X.useState)(!1),[ne,re]=(0,X.useState)([]),[ie,L]=(0,X.useState)(!1),[R,ae]=(0,X.useState)(i||null),[oe,se]=(0,X.useState)(a?{runId:a,run:null}:null),ce=e=>{se(t=>t?.runId===e?null:{runId:e,run:null})};(0,X.useEffect)(()=>{if(!oe||oe.run||oe.error)return;let t=!1;return HQ(e,oe.runId).then(e=>{t||se(t=>t?.runId===e.runId?{runId:e.runId,run:e}:t)}).catch(e=>{t||se(t=>t?.runId===oe.runId?{...t,error:e instanceof Error?e.message:`Failed to load run`}:t)}),()=>{t=!0}},[e,oe]);let[z,le]=(0,X.useState)(null),[ue,de]=(0,X.useState)(!1),[fe,pe]=(0,X.useState)(0),[me,he]=(0,X.useState)(null),[ge,_e]=(0,X.useState)(()=>qQ()),[ve,ye]=(0,X.useState)(()=>String(qQ())),B=()=>{let e=JQ(KQ(ve));_e(e),ye(String(e))};(0,X.useEffect)(()=>{let t=!1;return BQ(e,{status:`pending`,limit:500}).then(e=>{t||pe(e.length)}).catch(()=>{}),()=>{t=!0}},[e]),Sf(()=>de(!1),ue);let be=async t=>{if(confirm(`Replay ${t.handlerType} "${t.handler}" for ${t.event} (docs ${(t.docIds||[]).join(`, `)})?`)){le(t.runId);try{let n=await QQ(e,t.runId);o({title:`Replayed`,description:`${t.handler} → ${n.status}`}),await Se()}catch(e){o({title:`Replay failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{le(null)}}},V=s===`scripts`?{list:r$,get:i$,save:a$,del:o$}:{list:vQ,get:yQ,save:bQ,del:xQ},xe=s===`hooks`||s===`scripts`,Se=async()=>{if(s!==`rules`&&s!==`pending`){if(s===`runs`){try{g(!0),re(await UQ(e,{limit:100,failed:ie||void 0,handler:R||void 0}))}catch{o({title:`Error`,description:`Failed to load hook runs`,variant:`destructive`})}finally{g(!1)}return}try{g(!0),m(await V.list(e))}catch{o({title:`Error`,description:`Failed to load ${s}`,variant:`destructive`})}finally{g(!1)}}};(0,X.useEffect)(()=>{Se()},[e,s,ie,R]);let Ce=e=>{e!==s&&(S&&!confirm(`Discard unsaved changes?`)||(c(e),v(null),b(``),C(!1),D(!1)))},U=async t=>{if(!(S&&!confirm(`Discard unsaved changes?`)))try{v(t),b(await V.get(e,t)),C(!1)}catch{o({title:`Error`,description:`Failed to open ${t}`,variant:`destructive`})}},we=async()=>{if(_)try{T(!0),await V.save(e,_,y),C(!1),o({title:`Saved`,description:`${_} saved`}),await Se()}catch{o({title:`Error`,description:`Failed to save ${_}`,variant:`destructive`})}finally{T(!1)}},De=async t=>{let n=TQ(t);try{let r=await OQ(e,t,!n);_===t&&v(r),await Se(),o({title:n?`Disabled`:`Enabled`,description:r})}catch{o({title:`Error`,description:`Failed to toggle ${t}`,variant:`destructive`})}},Ae=async t=>{let n=YQ(t);if(!n||!TQ(t)&&!confirm(`${t} is disabled. Run it anyway?`))return;let r=n.startsWith(`document.`);if(!(r&&!confirm(`Run ${t} against up to ${ge} existing documents (event ${n})?`))){he(t);try{if(r){let r=await XQ(e,{hookFile:t,event:n,limit:ge});o({title:`Run finished`,description:`${r.processed} documents processed, ${r.failed} failed. Details in the Runs tab`,...r.failed?{variant:`destructive`}:{}})}else{let r=await ZQ(e,{hookFile:t,event:n});o({title:r.status===`error`?`Run failed`:`Run finished`,description:r.status===`error`?`${t}: ${r.error||`see the Runs tab`}`:`${t} → ${r.status}${r.durationMs==null?``:` in ${r.durationMs}ms`}`,...r.status===`error`?{variant:`destructive`}:{}})}}catch(e){o({title:`Run failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{he(null)}}},je=async t=>{if(confirm(`Delete ${s===`hooks`?`hook`:`script`} ${t}?`))try{await V.del(e,t),_===t&&(v(null),b(``),C(!1)),await Se(),o({title:`Deleted`,description:`${t} deleted`})}catch{o({title:`Error`,description:`Failed to delete ${t}`,variant:`destructive`})}},Me=async()=>{if(!O)try{A(await $Q(e))}catch{o({title:`Error`,description:`Failed to load hook metadata`,variant:`destructive`})}},Ne=async()=>{D(!E),s===`hooks`&&await Me()},Pe=async()=>{f(!d),await Me()},Fe=async()=>{let t=N.trim().replace(/^\/+/,``);if(!t){o({title:`Error`,description:`Give the script a name (e.g. on-image.sh)`,variant:`destructive`});return}try{te(!0),await a$(e,t,Z$),D(!1),P(``),await Se(),await U(t)}catch{o({title:`Error`,description:`Failed to create script`,variant:`destructive`})}finally{te(!1)}},Ie=e=>{I(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},Le=async()=>{if(!N.trim()){o({title:`Error`,description:`Give the hook a name`,variant:`destructive`});return}try{te(!0);let{path:t}=await e$(e,{event:j,name:N.trim(),actions:F});D(!1),P(``),I([]),await Se(),await U(t),o({title:`Created`,description:`${t}. Edit the TODOs, then enable it`})}catch{o({title:`Error`,description:`Failed to create hook`,variant:`destructive`})}finally{te(!1)}},Re=s===`hooks`?kQ(p):{scripts:p},ze=`${ti}/workspaces/${e}/git`;return(0,Z.jsxs)(`div`,{className:`@container space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 @3xl:flex-row @3xl:items-start @3xl:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 @3xl:min-w-[18rem] @3xl:flex-1`,children:[(0,Z.jsx)(`h3`,{className:`text-lg font-medium`,children:`Automation`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rules are simple click-to-build automations (Outlook-style). Hooks are their programmable big brother; scripts are the shell helpers hooks spawn. Everything commits to the workspace git repo.`})]}),(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2 @3xl:max-w-[60%] @3xl:flex-row @3xl:items-center`,children:(0,Z.jsx)(`div`,{className:`w-full min-w-0 @3xl:w-auto`,children:(0,Z.jsx)(cm,{className:`border-b-0`,active:s,onChange:Ce,tabs:[{id:`pending`,label:fe>0?`Pending (${fe})`:`Pending`,icon:W},{id:`rules`,label:`Rules`,icon:Vn},{id:`hooks`,label:`Hooks`,icon:We},{id:`scripts`,label:`Scripts`,icon:ke},{id:`runs`,label:`Runs`,icon:Ee}]})})})]}),(s===`runs`||xe)&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[s===`runs`&&(0,Z.jsxs)(Z.Fragment,{children:[R&&(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-full border bg-muted/50 px-2.5 py-1 font-mono text-xs hover:bg-muted`,title:`Showing runs of this rule / hook only — click to clear`,onClick:()=>ae(null),children:[R,` `,(0,Z.jsx)(G,{className:`h-3 w-3`})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:ie,onChange:e=>L(e.target.checked)}),`failed only`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`ghost`,onClick:Se,title:`Reload`,children:[(0,Z.jsx)(Te,{className:`mr-1.5 h-4 w-4`}),` Reload`]})]}),xe&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(J,{size:`sm`,variant:`ghost`,onClick:Se,title:`Reload`,children:[(0,Z.jsx)(Te,{className:`mr-1.5 h-4 w-4`}),` Reload`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`ghost`,onClick:Pe,title:`Hook context API & classifier reference`,children:[(0,Z.jsx)(Hn,{className:`mr-1.5 h-4 w-4`}),` Reference`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,onClick:Ne,children:[(0,Z.jsx)(H,{className:`mr-2 h-4 w-4`}),` `,s===`hooks`?`New Hook`:`New Script`]})]})]}),s===`pending`&&(0,Z.jsx)(X$,{workspaceId:e,onPendingCount:pe}),s===`rules`&&(0,Z.jsx)(H$,{workspaceId:e,backfillLimit:ge,onShowRuns:e=>{ae(e),Ce(`runs`)},prefill:t,onPrefillConsumed:n,onOpenJson:async()=>{try{await yQ(e,`rules.json`)}catch{await bQ(e,`rules.json`,JSON.stringify({$schema:`canvas.hook-rules/v1`,rules:[]},null,2)+`
|
|
77
|
-
`).catch(()=>{})}c(`hooks`),U(`rules.json`)}}),s===`runs`&&(0,Z.jsx)(`div`,{className:`border rounded-lg overflow-auto max-h-[560px]`,children:h?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:`Loading...`}):ne.length===0?(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground p-3`,children:[`No runs recorded yet`,ie?` (failed only)`:``,`. Runs appear here every time a rule or hook executes.`]}):(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{className:`text-xs text-muted-foreground border-b sticky top-0 bg-background`,children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Time`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Handler`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Event`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Docs`}),(0,Z.jsx)(`th`,{className:`text-right font-medium px-3 py-2`,children:`ms`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Status`}),(0,Z.jsx)(`th`,{className:`px-2 py-2`})]})}),(0,Z.jsx)(`tbody`,{children:ne.map(e=>(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsxs)(`tr`,{className:`border-b last:border-0 align-top hover:bg-muted/40`,children:[(0,Z.jsx)(`td`,{className:`px-3 py-1.5 whitespace-nowrap text-xs text-muted-foreground`,title:e.ts,children:new Date(e.ts).toLocaleString()}),(0,Z.jsxs)(`td`,{className:`px-3 py-1.5 font-mono text-xs`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.handlerType,`:`]}),e.handler,e.origin!==`user`&&(0,Z.jsxs)(`span`,{className:`ml-1.5 text-[10px] uppercase tracking-wide rounded bg-muted-foreground/15 px-1 py-0.5 text-muted-foreground`,children:[e.origin,e.depth?` d${e.depth}`:``]})]}),(0,Z.jsxs)(`td`,{className:`px-3 py-1.5 font-mono text-xs`,children:[e.event,e.batch?` (batch)`:``]}),(0,Z.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs`,children:(e.docIds||[]).join(`, `)}),(0,Z.jsx)(`td`,{className:`px-3 py-1.5 text-right font-mono text-xs`,children:e.durationMs}),(0,Z.jsxs)(`td`,{className:`px-3 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:e.status===`error`?`text-destructive font-medium`:e.status===`skipped`?`text-muted-foreground`:`text-success dark:text-success`,children:e.status}),e.error&&(0,Z.jsx)(`span`,{className:`block text-destructive/80 font-mono break-all`,children:e.error}),e.skipReason&&(0,Z.jsx)(`span`,{className:`block text-muted-foreground`,children:e.skipReason}),e.actions&&e.actions.length>0&&(0,Z.jsx)(`span`,{className:`block text-muted-foreground font-mono`,children:e.actions.map(e=>`${e.action}:${e.status}`).join(` `)}),e.actions?.filter(e=>e.error).map((e,t)=>(0,Z.jsxs)(`span`,{className:`block break-all font-mono ${e.status===`error`?`text-destructive/80`:`text-muted-foreground`}`,children:[e.action,`: `,e.error]},t))]}),(0,Z.jsxs)(`td`,{className:`px-2 py-1.5 whitespace-nowrap`,children:[(0,Z.jsxs)(J,{size:`sm`,variant:`ghost`,className:`h-6 px-1.5 touch-target`,title:e.traceLines?`Execution log (${e.traceLines} lines)`:`Execution log`,onClick:()=>ce(e.runId),children:[(0,Z.jsx)(Tt,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(Ge,{className:`ml-0.5 h-3 w-3 transition-transform ${oe?.runId===e.runId?`rotate-180`:``}`})]}),e.handlerType!==`dispatch`&&(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 touch-target`,title:`Replay this run (reloads the document, re-runs the handler)`,disabled:z!==null,onClick:()=>be(e),children:(0,Z.jsx)(He,{className:`h-3 w-3 ${z===e.runId?`animate-spin`:``}`})})]})]}),oe?.runId===e.runId&&(0,Z.jsx)(`tr`,{className:`border-b last:border-0 bg-muted/30`,children:(0,Z.jsx)(`td`,{colSpan:7,className:`px-3 py-2`,children:(0,Z.jsx)($$,{state:oe})})})]},e.runId))})]})}),xe&&d&&O&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 bg-muted/30 text-sm`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h4`,{className:`font-medium mb-2`,children:[`Hook context (`,(0,Z.jsx)(`span`,{className:`font-mono`,children:`ctx`}),`)`]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:O.contextApi?.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:e.signature}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e.description})]},e.name))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h4`,{className:`font-medium mb-2`,children:[`Classifier (`,(0,Z.jsx)(`span`,{className:`font-mono`,children:`const c = ctx.classify()`}),`)`]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:O.classifier.predicates.map(e=>(0,Z.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:e},e))}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:[`Fields: `,O.classifier.fields.map(e=>(0,Z.jsxs)(`code`,{className:`font-mono`,children:[e,` `]},e)),`(never throws; all predicates are false for a null/unknown document).`]})]}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Full reference: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`docs/hooks.md`}),` in the server repo.`]})]}),E&&s===`scripts`&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-3 flex gap-2 items-center bg-muted/50`,children:[(0,Z.jsx)(q,{placeholder:`on-image.sh`,value:N,onChange:e=>P(e.target.value),className:`font-mono text-sm`}),(0,Z.jsx)(J,{size:`sm`,onClick:Fe,disabled:ee,children:`Create`}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>D(!1),children:`Cancel`})]}),E&&s===`hooks`&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3 bg-muted/50`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground block mb-1`,children:`1. When (event)`}),(0,Z.jsx)(`select`,{className:`w-full h-9 rounded-md border bg-background px-2 font-mono text-sm outline-none focus:ring-2 focus:ring-ring`,value:j,onChange:e=>M(e.target.value),children:(O?.events??[]).map(e=>(0,Z.jsxs)(`option`,{value:e.name,children:[e.name,`: `,e.description]},e.name))}),O&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1 font-mono`,children:[`payload: `,O.events.find(e=>e.name===j)?.payload]}),(0,Z.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground block mt-3 mb-1`,children:`2. Name`}),(0,Z.jsx)(q,{placeholder:`my-hook`,value:N,onChange:e=>P(e.target.value),className:`font-mono text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground block mb-1`,children:`3. Then (actions; pick any)`}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-52 overflow-auto pr-1`,children:(O?.actions??[]).map(e=>(0,Z.jsxs)(`label`,{className:`flex items-start gap-2 text-sm rounded px-2 py-1 hover:bg-muted cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`mt-1`,checked:F.includes(e.id),onChange:()=>Ie(e.id)}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,Z.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.description})]})]},e.id))})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(J,{size:`sm`,onClick:Le,disabled:ee||!O,children:ee?`Creating…`:`Create skeleton`}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>D(!1),children:`Cancel`}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Creates a disabled skeleton. Edit the TODOs, then enable it. Simple match→action automations can also go into `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`rules.json`}),` (no code).`]})]})]}),xe&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,Z.jsx)(`div`,{className:`md:col-span-1 border rounded-lg p-2 max-h-[480px] overflow-auto`,children:h?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground p-2`,children:`Loading...`}):p.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground p-2`,children:`No hooks yet.`}):Object.entries(Re).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground px-2 py-1`,children:e}),t.map(e=>{let t=TQ(e.path);return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded px-2 py-1 cursor-pointer text-sm ${_===e.path?`bg-muted`:`hover:bg-muted/50`} ${t?``:`opacity-50`}`,onClick:()=>U(e.path),children:[(0,Z.jsxs)(`span`,{className:`font-mono truncate flex items-center gap-1.5`,children:[e.path,s===`hooks`&&EQ(e.path)&&(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide rounded bg-muted-foreground/15 px-1 py-0.5 text-muted-foreground shrink-0`,children:`example`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center`,children:[s===`hooks`&&YQ(e.path)&&(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 touch-target`,title:YQ(e.path)?.startsWith(`document.`)?`Run against up to ${ge} existing documents`:`Run now`,disabled:me!==null,onClick:t=>{t.stopPropagation(),Ae(e.path)},children:(0,Z.jsx)(Oe,{className:`h-3 w-3 ${me===e.path?`animate-pulse`:``}`})}),s===`hooks`&&(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 touch-target`,title:t?`Disable`:`Enable`,onClick:t=>{t.stopPropagation(),De(e.path)},children:t?(0,Z.jsx)(x,{className:`h-3 w-3`}):(0,Z.jsx)(on,{className:`h-3 w-3 text-muted-foreground`})}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 text-destructive hover:text-destructive touch-target`,onClick:t=>{t.stopPropagation(),je(e.path)},children:(0,Z.jsx)(lt,{className:`h-3 w-3`})})]})]},e.path)})]},e))}),(0,Z.jsx)(`div`,{className:ue?`fixed inset-0 z-50 bg-background p-4 flex flex-col`:`md:col-span-2 border rounded-lg p-2 flex flex-col`,children:_?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`span`,{className:`font-mono text-sm truncate`,children:[_,S?` •`:``]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[s===`hooks`&&YQ(_)&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(J,{size:`sm`,variant:`outline`,className:`h-8`,title:TQ(_)?`Disable this hook (renames it with a disabled- prefix)`:`Enable this hook (strips the prefix)`,onClick:()=>De(_),children:TQ(_)?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(x,{className:`mr-1.5 h-3.5 w-3.5`}),` Enabled`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(on,{className:`mr-1.5 h-3.5 w-3.5 text-muted-foreground`}),` Disabled`]})}),(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,className:`h-8`,title:`Run this hook now`,disabled:me!==null||S,onClick:()=>Ae(_),children:[(0,Z.jsx)(Oe,{className:`mr-1.5 h-3.5 w-3.5 ${me===_?`animate-pulse`:``}`}),` Run`]})]}),(0,Z.jsxs)(J,{size:`sm`,onClick:we,disabled:w||!S,children:[(0,Z.jsx)(k,{className:`mr-2 h-4 w-4`}),` Save`]}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-8 w-8 p-0`,title:ue?`Exit full screen (Esc)`:`Edit full screen`,onClick:()=>de(!ue),children:ue?(0,Z.jsx)(it,{className:`h-4 w-4`}):(0,Z.jsx)(Fn,{className:`h-4 w-4`})})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto rounded border text-sm ${ue?``:`min-h-[400px] max-h-viewport-pane`}`,children:(0,Z.jsx)(gQ,{value:y,path:_,onChange:e=>{b(e),C(!0)}})})]}):(0,Z.jsxs)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-muted-foreground min-h-[400px]`,children:[`Select a `,s===`hooks`?`hook`:`script`,` to edit, or create a new one.`]})})]}),(s===`rules`||s===`hooks`)&&(0,Z.jsxs)(`label`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground`,title:`1–10000. Raise it when "Apply to existing items" reports fewer matches than you expect.`,children:[(0,Z.jsx)(kt,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{children:`Apply / run in batches of`}),(0,Z.jsx)(q,{type:`number`,min:1,max:1e4,step:100,value:ve,onChange:e=>ye(e.target.value),onBlur:B,onKeyDown:e=>{e.key===`Enter`&&(B(),e.target.blur())},className:`h-7 w-20 px-2 text-xs`}),(0,Z.jsx)(`span`,{children:`documents per pass — the rule "Apply" button and manual hook runs stop after that many.`})]}),(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(We,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsxs)(`span`,{children:[`Everything here lives in the workspace git repo. Clone it with`,` `,(0,Z.jsxs)(`code`,{className:`break-all rounded bg-muted px-1 py-0.5 font-mono select-all`,children:[`git clone `,ze.replace(`://`,`://canvas@`)]}),` `,`(password: a canvas API token; the `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`canvas@`}),` username is arbitrary but git needs one). Pushes hot-reload hooks.`]})]})]})}function $$({state:e}){if(e.error)return(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:e.error});if(!e.run)return(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading…`});let t=e.run,n={error:`text-destructive`,warn:`text-warning`,info:`text-foreground`,debug:`text-muted-foreground`};return(0,Z.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{children:[`run `,(0,Z.jsx)(`span`,{className:`font-mono`,children:t.runId})]}),(0,Z.jsxs)(`span`,{children:[`trigger `,(0,Z.jsx)(`span`,{className:`font-mono`,children:t.trigger})]}),t.eventId&&(0,Z.jsxs)(`span`,{children:[`event `,(0,Z.jsx)(`span`,{className:`font-mono`,children:t.eventId})]}),(0,Z.jsxs)(`span`,{children:[t.durationMs,` ms`]})]}),t.actions&&t.actions.length>0&&(0,Z.jsx)(`ol`,{className:`space-y-0.5 font-mono`,children:t.actions.map((e,t)=>(0,Z.jsxs)(`li`,{className:e.status===`error`?`text-destructive`:e.status===`skipped`?`text-muted-foreground`:``,children:[t+1,`. `,e.action,` → `,e.status,e.error?` — ${e.error}`:``]},t))}),t.trace&&t.trace.length>0?(0,Z.jsx)(`pre`,{className:`max-h-96 overflow-auto rounded-md border bg-background p-2 font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-all`,children:t.trace.map((e,t)=>(0,Z.jsxs)(`span`,{className:`block ${n[e.level]||``}`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[`+`,String(e.t).padStart(5,` `),`ms `]}),(0,Z.jsxs)(`span`,{className:`uppercase text-muted-foreground`,children:[e.level.padEnd(5,` `),` `]}),e.msg]},t))}):(0,Z.jsxs)(`p`,{className:`text-muted-foreground`,children:[`No execution log recorded for this run`,t.error?``:` (older runs predate tracing)`,`.`]})]})}function e1({workspaceName:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),u=(0,X.useCallback)(async()=>{a(!0);try{r(await ta(e))}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to load the trash`,variant:`destructive`})}finally{a(!1)}},[e]);(0,X.useEffect)(()=>{u()},[u]);let d=(0,X.useCallback)(e=>o.includes(e),[o]),f=async(e,t)=>{s(t=>[...t,...e]);try{await t()}finally{s(t=>t.filter(t=>!e.includes(t)))}},p=n=>f([n.id],async()=>{try{let i=await Jr(e,[n.id]);i.failed?.length?t({title:`Not restored`,description:i.failed[0]?.error||`No restore target recorded`,variant:`destructive`}):(t({title:`Restored`,description:`Document put back where it was.`}),r(e=>e.filter(e=>e.id!==n.id)))}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to restore`,variant:`destructive`})}}),m=n=>f([n.id],async()=>{try{await oi(e,[n.id]),t({title:`Deleted`,description:`Document permanently deleted.`}),r(e=>e.filter(e=>e.id!==n.id))}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to delete`,variant:`destructive`})}}),h=async()=>{if(!c){l(!0);return}l(!1);try{let n=await oi(e);t({title:`Trash emptied`,description:`${n.destroyed?.length??0} document(s) permanently deleted.`}),r([])}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to empty the trash`,variant:`destructive`})}},g=(0,X.useMemo)(()=>n.map(e=>{let t=bo(e),n=(e.trashed?.placements??[]).flatMap(e=>e.paths.map(t=>`${e.tree}:${t}`));return{document:e,title:t.title,origin:n,trashedAt:e.trashed?.trashedAt||null}}),[n]);return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-medium`,children:`Trash`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 max-w-2xl`,children:`Removing a document from a path detaches it; when that was its last place, it lands here so nothing goes missing. Restoring puts it back everywhere it was. Emptying deletes for real: from the index and from canvas-owned storage, never from external backends.`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 max-sm:flex-wrap`,children:[(0,Z.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>u(),disabled:i,children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${i?`animate-spin`:``}`}),`Refresh`]}),(0,Z.jsxs)(J,{variant:c?`destructive`:`outline`,size:`sm`,onClick:h,onBlur:()=>l(!1),disabled:n.length===0,children:[(0,Z.jsx)(lt,{className:`mr-2 h-3.5 w-3.5`}),c?`Click again to delete everything`:`Empty trash`]})]})]}),i&&n.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}),!i&&n.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The trash is empty.`}),g.length>0&&(0,Z.jsx)(`div`,{className:`border rounded-md divide-y`,children:g.map(({document:e,title:t,origin:n,trashedAt:r})=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm`,children:t}),(0,Z.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[n.length>0?`from ${n.join(`, `)}`:`no recorded origin`,r?` · ${new Date(r).toLocaleString()}`:``]})]}),(0,Z.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>p(e),disabled:d(e.id)||n.length===0,title:n.length===0?`Nothing recorded to restore to`:`Put it back where it was`,children:[(0,Z.jsx)(He,{className:`mr-2 h-3.5 w-3.5`}),`Restore`]}),(0,Z.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>m(e),disabled:d(e.id),title:`Delete permanently`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]},e.id))})]})}var t1=e=>`${Qr.workspaces}/${encodeURIComponent(e)}`;async function n1(e){return await Y.get(`${t1(e)}/mirrors`)||[]}async function r1(e,t){await Y.delete(`${t1(e)}/mirrors/${encodeURIComponent(t)}`)}async function i1(e,t=10){return Y.get(`${t1(e)}/mirrors/protection?sample=${t}`)}async function a1(e,t,n){return(await Y.patch(`${t1(e)}/mirrors/${encodeURIComponent(t)}`,n)).replica}async function o1(e){return await Y.get(`${t1(e)}/sync/conflicts`)||[]}async function s1(e,t,n){return Y.post(`${t1(e)}/sync/conflicts/${t}/resolve`,{keep:n})}var c1=e=>{if(e==null||e===``)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})},l1=e=>e==null?`—`:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<1073741824?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(2)} GB`,u1=e=>e?e.slice(0,12):`—`;function d1({mirror:e,now:t,busy:n,onForget:r,onRequired:i}){let a=e.mirror,o=!e.lastSeen||t-new Date(e.lastSeen).getTime()>6e5,s=e.replica?.role===`cache`||a.client===`fuse`,c=e.replica?.required===!0,l=a.direction||(a.client===`fuse`?`bi`:void 0);return(0,Z.jsx)(`div`,{className:`rounded-lg border p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(0,Z.jsx)(sr,{className:`h-4 w-4 text-muted-foreground mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e.name||e.deviceId}),a.client&&(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono uppercase`,children:a.client}),l&&(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,title:l===`pull`?`Backup target: the hub is the only writer`:l===`push`?`One-shot import: local is the only writer`:`Both ways`,children:l===`pull`?`⇣ pull`:l===`push`?`⇡ push`:`⇅ bi`}),c&&(0,Z.jsx)(`span`,{className:`rounded bg-emerald-500/15 px-1.5 py-0.5 text-[10px] font-mono text-emerald-700 dark:text-emerald-300`,title:`Counts toward protection`,children:`required`}),(0,Z.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] font-mono ${o?`bg-muted text-muted-foreground`:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}`,children:a.state||(o?`offline`:`online`)})]}),a.path&&(0,Z.jsx)(`p`,{className:`mt-0.5 text-[11px] font-mono text-muted-foreground truncate`,children:a.path}),(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-x-4 gap-y-0.5 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{title:`Change-log entries the device has not applied yet`,children:[`lag `,e.lag??`—`]}),(0,Z.jsxs)(`span`,{title:`Local changes waiting to be pushed`,children:[`pending `,a.pending??0]}),(a.failed??0)>0&&(0,Z.jsxs)(`span`,{className:`text-destructive`,children:[`failed `,a.failed]}),(a.conflicts??0)>0&&(0,Z.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`conflicts `,a.conflicts]}),(a.skipped??0)>0&&(0,Z.jsxs)(`span`,{children:[`skipped `,a.skipped]}),(a.reverted??0)>0&&(0,Z.jsxs)(`span`,{title:`Local edits parked in .workspace/conflicts and replaced by the hub version`,children:[`reverted `,a.reverted]}),e.behind!=null&&(0,Z.jsxs)(`span`,{title:`Documents whose current version this device does not hold yet`,className:e.behind>0&&c?`text-amber-600 dark:text-amber-400`:``,children:[`behind `,e.behind]}),(0,Z.jsxs)(`span`,{children:[`last sync `,c1(a.lastSync)]}),(0,Z.jsxs)(`span`,{children:[`seen `,c1(e.lastSeen)]}),a.prefixes&&a.prefixes.length>0&&(0,Z.jsx)(`span`,{className:`font-mono`,children:a.prefixes.join(`, `)})]}),a.lastError&&(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-destructive`,children:a.lastError}),(0,Z.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-[11px] ${s?`text-muted-foreground`:``}`,title:s?`A cache never counts toward protection`:`A document is protected once every required replica holds its current version`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`h-3 w-3`,checked:c,disabled:n||s,onChange:e=>i(e.target.checked)}),`required for protection`]})]})]}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:n,title:`Forget this mirror record (the device is not revoked)`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]})})}function f1({p:e}){let t=e.required.length===0,n=e.unprotected??0,r=t||n>0?An:Ht,i=t?`text-muted-foreground`:n>0?`text-amber-600 dark:text-amber-400`:`text-emerald-700 dark:text-emerald-300`;return(0,Z.jsx)(`div`,{className:`rounded-lg border p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Z.jsx)(r,{className:`h-4 w-4 mt-0.5 shrink-0 ${i}`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 text-[11px]`,children:[t?(0,Z.jsxs)(`p`,{className:`text-sm`,children:[`No replica is marked `,(0,Z.jsx)(`span`,{className:`font-medium`,children:`required`}),` yet — nothing is counted as protected. Tick it on the device that must hold every document (the backup).`]}):(0,Z.jsxs)(`p`,{className:`text-sm`,children:[(0,Z.jsxs)(`span`,{className:`font-medium ${i}`,children:[e.protected??0,` of `,e.total-e.unversioned]}),` documents are held at their current version by every required replica`,n>0&&(0,Z.jsxs)(`span`,{className:i,children:[` · `,n,` not yet`]}),e.partial&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (first `,e.total,` checked)`]})]}),e.oldestUnprotected.length>0&&(0,Z.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-muted-foreground`,children:[e.oldestUnprotected.slice(0,5).map(e=>(0,Z.jsxs)(`li`,{className:`truncate`,title:`document ${e.docId} v${e.version}`,children:[e.key,` `,(0,Z.jsxs)(`span`,{className:`opacity-70`,children:[`· `,c1(e.mtime)]})]},`${e.docId}:${e.key}`)),e.oldestUnprotected.length>5&&(0,Z.jsxs)(`li`,{children:[`… and `,e.oldestUnprotected.length-5,` more`]})]})]})]})})}function p1({conflict:e,busy:t,onResolve:n}){let r=!e.hub;return(0,Z.jsxs)(`div`,{className:`rounded-lg border p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Z.jsx)(at,{className:`h-4 w-4 text-amber-500 mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium font-mono break-all`,children:e.key}),(0,Z.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`from `,(0,Z.jsx)(`span`,{className:`font-medium`,children:e.deviceName||e.device||`unknown device`}),` · `,c1(e.ts),e.mode===`rename`&&e.conflictKey&&(0,Z.jsxs)(Z.Fragment,{children:[` · already on disk as `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.conflictKey})]})]})]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 text-[11px] sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`rounded border border-dashed p-2`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:`Hub version (keeps the name)`}),e.hub?(0,Z.jsxs)(`div`,{className:`font-mono`,children:[u1(e.hub.sha256),` · `,l1(e.hub.size),` · `,c1(e.hub.mtime)]}):(0,Z.jsx)(`div`,{className:`italic text-muted-foreground`,children:`no file at this key any more`})]}),(0,Z.jsxs)(`div`,{className:`rounded border border-dashed p-2`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:`Incoming version (the device’s)`}),(0,Z.jsxs)(`div`,{className:`font-mono`,children:[u1(e.incoming.sha256),` · `,l1(e.incoming.size),` · `,c1(e.incoming.mtime)]})]})]}),e.resolvable?(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t||r,onClick:()=>n(`hub`),title:`Discard the device's version`,children:`Keep hub`}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t,onClick:()=>n(`incoming`),title:`The device's bytes replace the hub's; tags, relations and placements move over`,children:`Keep incoming`}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t,onClick:()=>n(`both`),title:`Keep the hub file and add the device's version under a conflict name`,children:`Keep both`})]}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Dropbox-style conflict copy: both files are on disk, delete the one you do not need.`})]})}function m1({workspaceId:e,workspaceUuid:t}){let{showToast:n}=po(),[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(0),h=(0,X.useRef)(null),g=(0,X.useCallback)(async(t=!1)=>{if(e){t||u(!0);try{let[t,n,r]=await Promise.all([n1(e),o1(e),i1(e).catch(()=>null)]);i(t),o(n),c(r),m(Date.now())}catch(e){t||n({title:`Error`,description:e instanceof Error?e.message:`Failed to load sync state`,variant:`destructive`})}finally{t||u(!1)}}},[e]);(0,X.useEffect)(()=>{g()},[g]),(0,X.useEffect)(()=>{if(!t)return;let e=`workspace:${t}`,n=()=>Xu.emit(`subscribe`,{channel:e}),r=Xu.on(`connect`,n);n();let i=e=>{let n=e;n?.workspaceId&&n.workspaceId!==t||(h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{h.current=null,g(!0)},800))},a=[`backend.changed`,`sync.conflict.created`,`sync.conflict.resolved`].map(e=>Xu.on(e,i));return()=>{r(),a.forEach(e=>e()),Xu.emit(`unsubscribe`,{channel:e}),h.current&&=(clearTimeout(h.current),null)}},[t,g]);let _=async t=>{f(`mirror:${t}`);try{await r1(e,t),i(e=>e.filter(e=>e.deviceId!==t)),n({title:`Forgotten`,description:`Mirror record removed. The device keeps running and will report again if it still syncs this workspace.`})}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to forget mirror`,variant:`destructive`})}finally{f(null)}},v=async(t,r)=>{f(`mirror:${t}`);try{let n=await a1(e,t,{required:r});i(e=>e.map(e=>e.deviceId===t?{...e,replica:{role:n.role,required:n.required}}:e)),c(await i1(e).catch(()=>null))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to update replica policy`,variant:`destructive`})}finally{f(null)}},y=async(t,r)=>{f(`conflict:${t.docId}`);try{let i=await s1(e,t.docId,r);o(e=>e.filter(e=>e.docId!==t.docId));let a=r===`hub`?`kept the hub version`:r===`incoming`?`the device version now holds the name`:`kept both (${i.resultKey||`conflict copy`})`;n({title:`Resolved`,description:`${t.key}: ${a}`})}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to resolve conflict`,variant:`destructive`})}finally{f(null)}};return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Device mirrors`}),(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Devices keeping this workspace’s files in sync (canvas-fuse `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`--mirror`}),`, canvas-edge). Lag counts change-log entries the device has not applied yet.`]})]}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>g(),disabled:l,children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${l?`animate-spin`:``}`}),`Refresh`]})]}),l&&r.length===0&&a.length===0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(Te,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):r.length===0?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-dashed p-4 text-xs text-muted-foreground`,children:[`No device mirrors this workspace yet. Mount it with `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`canvas-fuse mount -w <workspace> ~/Workspaces --mirror`}),` on a device and it shows up here.`]}):(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[s&&(0,Z.jsx)(f1,{p:s}),r.map(e=>(0,Z.jsx)(d1,{mirror:e,now:p,busy:d===`mirror:${e.deviceId}`,onForget:()=>_(e.deviceId),onRequired:t=>v(e.deviceId,t)},e.deviceId))]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Conflicts`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`A device and the hub both changed the same file. The hub’s version keeps the filename; decide what happens to the device’s. Tags, relations and placements follow whichever version survives.`})]}),a.length===0?(0,Z.jsx)(`div`,{className:`rounded-lg border border-dashed p-4 text-xs text-muted-foreground`,children:`Nothing to resolve.`}):(0,Z.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>(0,Z.jsx)(p1,{conflict:e,busy:d===`conflict:${e.docId}`,onResolve:t=>y(e,t)},e.docId))})]})}function h1({workspaceId:e,address:t}){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(``);return(0,X.useEffect)(()=>{if(!n)return;let r=!1,i,o=async()=>{try{let n=await pm(e,t);r||(a(n),s(``))}catch(e){r||s(e instanceof Error?e.message:`Connection unavailable`)}r||(i=setTimeout(()=>void o(),3e3))};return o(),()=>{r=!0,clearTimeout(i)}},[e,t,n]),(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>r(!n),children:n?`Close connection panel`:`Pair / connection status`}),n&&(0,Z.jsxs)(`div`,{className:`space-y-2 p-2 text-xs`,children:[(0,Z.jsx)(`p`,{children:o||i?.state||`Connecting…`}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>{window.confirm(`Forget the current session and pair this account again?`)&&hm(e,t).catch(e=>s(e.message))},children:`Pair again`}),i?.qr&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{children:`WhatsApp → Settings → Linked devices → Link a device.`}),(0,Z.jsx)(`img`,{className:`max-w-full`,src:i.qr,width:256,height:256,alt:`WhatsApp device pairing QR code`})]}),i?.chats.length?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{children:`Copy the conversations you want into this account’s Conversation IDs setting.`}),(0,Z.jsx)(`div`,{className:`max-h-48 overflow-auto`,children:i.chats.map(e=>(0,Z.jsxs)(`p`,{children:[e.name,` · `,(0,Z.jsx)(`code`,{className:`select-all`,children:e.id})]},e.id))})]}):null]})]})}var g1={github:{label:`GitHub Issues`,icon:`mdi:github`,blurb:`Issues from the listed repos sync as todos. Token optional for public repos.`,fields:[{key:`address`,label:`Account label`,placeholder:`e.g. canvas-ui`,required:!0},{key:`token`,label:`Personal access token`,hint:`Optional for public repos; required for write-back.`,secret:!0},{key:`repos`,label:`Repositories`,placeholder:`owner/repo, one per line`,hint:`Issues from each repo sync as todos.`,list:!0,required:!0},{key:`writeBack`,label:`Manage issues from Canvas`,hint:`Create, edit and close issues. Needs a PAT with repo scope.`,bool:!0},{key:`pruneRemoved`,label:`Remove items deleted at the source`,hint:`After each sync, issues that no longer exist in the repo are dropped from the mirror (kept as location-less orphans until database retention GC; skipped whenever the repo can’t be fully listed).`,bool:!0}]},slack:{label:`Slack`,icon:`mdi:slack`,blurb:`Channel messages sync as message documents. Bot/user token with channels:read + channels:history.`,fields:[{key:`address`,label:`Workspace label`,placeholder:`e.g. acme`,required:!0},{key:`token`,label:`Token (xoxb-… / xoxp-…)`,secret:!0,required:!0},{key:`channels`,label:`Conversations (channel names or IDs; DM IDs need im:read + im:history)`,list:!0},{key:`directMessages`,label:`Include direct messages`,hint:`Requires im:read, im:history, mpim:read and mpim:history.`,bool:!0},{key:`writeBack`,label:`Allow sending from Canvas`,hint:`Token also needs chat:write.`,bool:!0},{key:`allowAgentSend`,label:`Allow agents with workspace write access to send`,bool:!0}]},whatsapp:{label:`WhatsApp (linked device)`,icon:`mdi:whatsapp`,blurb:`Pair your phone with Canvas, then choose conversations. Uses Baileys; separate from WhatsApp Business.`,fields:[{key:`address`,label:`Account label`,placeholder:`personal`,required:!0},{key:`chats`,label:`Conversation IDs to sync (one per line; available after pairing)`,list:!0},{key:`writeBack`,label:`Allow sending from Canvas`,bool:!0},{key:`allowAgentSend`,label:`Allow agents with workspace write access to send`,bool:!0}]},gcal:{label:`Google Calendar`,icon:`mdi:calendar-month`,blurb:`Events sync as calendar entries (recurring series kept as series). Offline-access OAuth credentials.`,fields:[{key:`address`,label:`Account label`,placeholder:`e.g. me-gmail`,required:!0},{key:`clientId`,label:`OAuth client id`,required:!0},{key:`clientSecret`,label:`OAuth client secret`,secret:!0,required:!0},{key:`refreshToken`,label:`Refresh token`,secret:!0,required:!0},{key:`calendars`,label:`Calendar ids (empty = primary)`,list:!0}]},caldav:{label:`CalDAV`,icon:`mdi:calendar-sync`,blurb:`Any CalDAV endpoint (GroupOffice, Nextcloud, Radicale, SOGo…). Read-only by default; enable write-back to create events from Canvas.`,fields:[{key:`address`,label:`Account label`,placeholder:`e.g. groupoffice`,required:!0},{key:`url`,label:`CalDAV URL (calendar home or one calendar)`,placeholder:`https://host/caldav/user`,required:!0},{key:`username`,label:`Username`},{key:`password`,label:`Password`,secret:!0},{key:`calendars`,label:`Calendars (names, empty = all)`,list:!0},{key:`writeBack`,label:`Create events from Canvas`,hint:`Write-back into the CalDAV calendar.`,bool:!0}]},teams:{label:`MS Teams`,icon:`mdi:microsoft-teams`,blurb:`Channel messages via Microsoft Graph (app-only credentials, admin-consented ChannelMessage.Read.All).`,fields:[{key:`address`,label:`Tenant label`,placeholder:`e.g. corp`,required:!0},{key:`tenantId`,label:`Tenant id`,required:!0},{key:`clientId`,label:`Client id`,required:!0},{key:`clientSecret`,label:`Client secret`,secret:!0,required:!0},{key:`teams`,label:`Team ids (one per line)`,list:!0,required:!0}]}};function _1(e){return e.split(/[\n,]/).map(e=>e.trim()).filter(Boolean)}function v1({workspaceId:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[l,u]=(0,X.useState)({}),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),h=(0,X.useCallback)(async()=>{let t=await wa(e).catch(()=>[]);r(t.filter(e=>e.kind===`connector`))},[e]),g=async()=>{m(!0);try{await h()}finally{m(!1)}};(0,X.useEffect)(()=>{let t=!1;return wa(e).then(e=>{t||r(e.filter(e=>e.kind===`connector`))}).catch(()=>{}),()=>{t=!0}},[e]);let _=n.some(e=>e.status===`syncing`);(0,X.useEffect)(()=>{if(!_)return;let e=setInterval(()=>{h()},4e3);return()=>clearInterval(e)},[_,h]);let v=e=>{let t=g1[e.driver];if(!t)return;let n=e.config||{},r={};for(let i of t.fields){if(i.key===`address`){r.address=e.address;continue}if(i.secret)continue;if(i.key===`writeBack`){r.writeBack=n.readOnly===!1&&(![`slack`,`whatsapp`].includes(e.driver)||n.sendEnabled===!0)?`true`:``;continue}let t=n[i.key];if(i.list){r[i.key]=Array.isArray(t)?t.join(`
|
|
78
|
-
`):``;continue}t!=null&&(r[i.key]=String(t))}u(r),a(e.driver),s(e)},y=()=>{a(null),s(null),u({})},b=async()=>{if(!i)return;let n=g1[i],r={};for(let e of n.fields){let n=(l[e.key]||``).trim();if(!n){if(e.required&&!(o&&e.secret)){t({title:`${e.label} is required`,variant:`destructive`});return}o&&!e.secret&&(r[e.key]=e.list?[]:!e.bool&&``);continue}r[e.key]=e.list?_1(n):e.bool?n===`true`:n}n.fields.some(e=>e.key===`writeBack`)&&([`slack`,`whatsapp`].includes(i)&&(r.sendEnabled=r.writeBack===!0),r.readOnly=r.writeBack!==!0,delete r.writeBack),f(!0);try{o?await da(e,o.driver,o.address,r):await na(e,i,r),y(),await h(),t({title:o?`Connector updated; sync restarted`:`Connector saved; first sync started`})}catch(e){t({title:`Failed to save connector`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{f(!1)}},x=async n=>{try{await _a(e,n.driver,n.address),t({title:`Syncing ${n.driver}/${n.address}`}),setTimeout(()=>{h()},1500)}catch(e){t({title:`Sync failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},S=async n=>{if(window.confirm(`Remove ${n.driver}/${n.address}? Synced documents stay in the backends tree until purged.`))try{await zr(e,n.driver,n.address),await h()}catch(e){t({title:`Remove failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}};return(0,Z.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Connectors`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`GitHub issues, Slack, Google Calendar, CalDAV and MS Teams, polled into the backends tree (read-only unless write-back is enabled).`})]}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:p,onClick:()=>{g()},title:`Refresh`,children:(0,Z.jsx)(Te,{className:`h-3.5 w-3.5 ${p?`animate-spin`:``}`})})]}),n.length>0&&(0,Z.jsx)(`div`,{className:`mt-3 space-y-2`,children:n.map(t=>{let n=g1[t.driver];return(0,Z.jsxs)(`div`,{className:`rounded-md border p-3`,children:[t.driver===`whatsapp`&&(0,Z.jsx)(h1,{workspaceId:e,address:t.address}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(c,{icon:n?.icon||`mdi:cloud-sync`,width:16,height:16,className:`shrink-0`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:n?.label||t.driver}),(0,Z.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:t.address}),(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t.status===`syncing`,onClick:()=>{x(t)},children:[(0,Z.jsx)(Te,{className:`mr-1 h-3 w-3 ${t.status===`syncing`?`animate-spin`:``}`}),t.status===`syncing`?`Syncing`:`Sync now`]}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>v(t),title:`Edit connector`,children:(0,Z.jsx)(Fe,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{S(t)},title:`Remove connector`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5 text-destructive`})})]}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{children:[`status: `,t.status]}),t.lastSyncAt&&(0,Z.jsxs)(`span`,{children:[`last sync: `,new Date(t.lastSyncAt).toLocaleString()]}),t.treePath&&(0,Z.jsx)(`span`,{className:`font-mono`,children:t.treePath})]}),t.lastError&&(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-destructive`,children:t.lastError})]},`${t.driver}:${t.address}`)})}),i?(0,Z.jsxs)(`div`,{className:`mt-3 rounded-md border p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(c,{icon:g1[i].icon,width:16,height:16}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:o?`Edit ${g1[i].label}`:g1[i].label}),o&&(0,Z.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:o.address}),(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsx)(`button`,{type:`button`,onClick:y,className:`p-1 text-muted-foreground hover:text-foreground`,"aria-label":`Cancel`,children:(0,Z.jsx)(G,{className:`h-3.5 w-3.5`})})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:g1[i].blurb}),(0,Z.jsx)(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2`,children:g1[i].fields.map(e=>(0,Z.jsxs)(`label`,{className:`text-xs ${e.list||e.bool?`sm:col-span-2`:``}`,children:[!e.bool&&(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),e.bool?(0,Z.jsxs)(`span`,{className:`mt-1 flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:l[e.key]===`true`,onChange:t=>u(n=>({...n,[e.key]:t.target.checked?`true`:``})),className:`h-4 w-4 accent-primary`}),(0,Z.jsx)(`span`,{children:e.label})]}):e.list?(0,Z.jsx)(`textarea`,{value:l[e.key]||``,onChange:t=>u(n=>({...n,[e.key]:t.target.value})),placeholder:e.placeholder,rows:2,className:`mt-1 w-full rounded-md border border-input bg-background px-2 py-1.5 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`}):(0,Z.jsx)(q,{type:e.secret?`password`:`text`,value:l[e.key]||``,disabled:!!o&&e.key===`address`,onChange:t=>u(n=>({...n,[e.key]:t.target.value})),placeholder:o&&e.secret?`Leave blank to keep current`:e.placeholder,autoComplete:`off`,className:`mt-1 h-8 text-xs`}),e.hint&&(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-muted-foreground/80`,children:e.hint})]},e.key))}),(0,Z.jsx)(J,{type:`button`,size:`sm`,className:`mt-3`,disabled:d,onClick:()=>{b()},children:d?`Saving…`:o?`Save changes & sync`:`Save & sync`})]}):(0,Z.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:Object.entries(g1).map(([e,t])=>(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{a(e),u({})},children:[(0,Z.jsx)(H,{className:`mr-1 h-3 w-3`}),(0,Z.jsx)(c,{icon:t.icon,width:14,height:14,className:`mr-1`}),t.label]},e))})]})}var y1={host:``,port:993,tls:!0,allowSelfSigned:!0,user:``,password:``,pollInterval:6e4,initialSyncDays:180,smtp:{enabled:!1,host:``,port:587,secure:!1,user:``,password:``,from:``,sentFolder:`Sent`,appendSent:!1,allowAgentSend:!1}};function b1(e){let t=e.config||{};return{host:String(t.host||``),port:Number(t.port??993),tls:t.tls!==!1,allowSelfSigned:t.allowSelfSigned!==!1,user:String(t.user||e.address),password:``,pollInterval:Number(t.pollInterval??6e4),initialSyncDays:Number(t.initialSyncDays??180),smtp:{...y1.smtp,...t.smtp||{},password:``}}}function x1({workspaceId:e,enabled:t}){let[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(y1),[f,p]=(0,X.useState)([]),[m,h]=(0,X.useState)([`INBOX`]),[g,_]=(0,X.useState)(!0),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(null),{showToast:w}=po(),T=(0,X.useMemo)(()=>[...n].sort((e,t)=>e.address.localeCompare(t.address)),[n]),E=(0,X.useMemo)(()=>n.find(e=>e.address===o)||null,[n,o]),D=(0,X.useCallback)(()=>wa(e,`imap`).then(e=>r(e)).catch(e=>{w({title:`Error`,description:e instanceof Error?e.message:`Failed to load IMAP accounts`,variant:`destructive`})}).finally(()=>_(!1)),[e,w]),O=(0,X.useCallback)(async()=>{_(!0),await D()},[D]),[A,j]=(0,X.useState)(e);e!==A&&(j(e),_(!0)),(0,X.useEffect)(()=>{D()},[D]);let M=(0,X.useCallback)(async(t,n)=>{y(!0);try{let r=t?await Yi(e,`imap`,t.address):await wr(e,`imap`,{host:(n?.host||``).trim(),port:Number(n?.port)||993,tls:n?.tls!==!1,allowSelfSigned:n?.allowSelfSigned!==!1,user:(n?.user||``).trim(),password:n?.password||``,folder:`INBOX`});p(r.filter(e=>e.selectable))}catch(e){w({title:`IMAP Error`,description:e instanceof Error?e.message:`Failed to discover folders`,variant:`destructive`})}finally{y(!1)}},[e,w]),N=()=>{l(!1),s(null),d(y1),p([]),h([`INBOX`])},P=e=>{if(o===e.address){N();return}l(!1),s(e.address),d(b1(e)),p([]),h((e.containers||[]).map(e=>e.name)),M(e)},F=()=>{N(),l(!0)},I=(e,t)=>d(n=>({...n,[e]:t})),ee=e=>h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),te=(0,X.useMemo)(()=>{let e=new Map(f.map(e=>[e.path,e]));for(let t of m)e.has(t)||e.set(t,{name:t,path:t,delimiter:`/`,selectable:!0,attributes:[]});return[...e.values()].sort((e,t)=>e.path.localeCompare(t.path))},[f,m]),ne=async()=>{x(!0);try{let t=m.length?m:[`INBOX`],n={host:u.host.trim(),user:u.user.trim(),port:Number(u.port)||993,tls:u.tls,allowSelfSigned:u.allowSelfSigned,pollInterval:Number(u.pollInterval)||6e4,initialSyncDays:Math.max(0,Number(u.initialSyncDays)||0),smtp:u.smtp,...u.password?{password:u.password}:{}};if(E){await da(e,`imap`,E.address,n);let r=new Set((E.containers||[]).map(e=>e.name)),i=t.filter(e=>!r.has(e)),a=[...r].filter(e=>!t.includes(e));i.length&&await Ni(e,`imap`,E.address,i);for(let t of a)await Wr(e,`imap`,E.address,t)}else{await na(e,`imap`,{...n,password:u.password,folder:t[0]});let r=u.user.trim();t.length>1&&await Ni(e,`imap`,r,t.slice(1))}await O(),l(!1),s(u.user.trim()),w({title:`Saved`,description:`IMAP account ${u.user.trim()} saved; sync runs in the background`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to save IMAP account`,variant:`destructive`})}finally{x(!1)}},re=async()=>{if(!(!E||!window.confirm(`Delete IMAP account ${E.address} and all its folders?`))){C(`delete:${E.address}`);try{await zr(e,`imap`,E.address),await O(),N(),w({title:`Deleted`,description:`IMAP account ${E.address} deleted`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to delete account`,variant:`destructive`})}finally{C(null)}}},ie=async(t,n)=>{C(`${t}:${n}`);try{t===`test`?await ra(e,`imap`,n):await _a(e,`imap`,n),await O(),w({title:`Success`,description:t===`sync`?`${n} sync started (runs in the background)`:`${n} test completed`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to ${t}`,variant:`destructive`})}finally{C(null)}},L=async(t,n)=>{C(`folder-sync:${t}:${n}`);try{await Oa(e,`imap`,t,n),await O(),w({title:`Synced`,description:`${t} · ${n}`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to sync folder`,variant:`destructive`})}finally{C(null)}},R=(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-host`,children:`Host`}),(0,Z.jsx)(q,{id:`imap-host`,value:u.host,disabled:!!E,onChange:e=>I(`host`,e.target.value),placeholder:`imap.example.com`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-user`,children:`User (account)`}),(0,Z.jsx)(q,{id:`imap-user`,value:u.user,disabled:!!E,onChange:e=>I(`user`,e.target.value),placeholder:`me@example.com`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-password`,children:`Password`}),(0,Z.jsx)(q,{id:`imap-password`,type:`password`,value:u.password,onChange:e=>I(`password`,e.target.value),placeholder:E?`Leave blank to keep current password`:`Password`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-port`,children:`Port`}),(0,Z.jsx)(q,{id:`imap-port`,type:`number`,value:String(u.port),onChange:e=>I(`port`,Number(e.target.value||993))})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(Eu,{children:`Folders to sync`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void M(E,u),disabled:v||!E&&(!u.host.trim()||!u.user.trim()||!u.password),children:[v?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(ut,{className:`h-3 w-3`}),` Discover folders`]})]}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto rounded-md border p-2`,children:te.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:v?`Discovering folders…`:E?`No folders found on the server.`:`Fill in host, user and password, then discover the account’s folders. INBOX is synced by default.`}):(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:te.map(e=>{let t=e.path.split(e.delimiter||`/`).length-1,n=f.some(t=>t.path===e.path);return(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 rounded px-2 py-1 text-xs hover:bg-accent/50`,style:{paddingLeft:`${8+t*14}px`},children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:m.includes(e.path),onChange:()=>ee(e.path)}),(0,Z.jsx)(`span`,{className:`font-mono truncate`,children:e.path}),!n&&f.length>0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`(subscribed, not on server)`})]},e.path)})})}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[m.length,` folder`,m.length===1?``:`s`,` selected; each synced as its own container. Unchecking a synced folder removes it on Save.`]})]}),(0,Z.jsxs)(`fieldset`,{className:`rounded border p-3 space-y-3 sm:col-span-2`,children:[(0,Z.jsx)(`legend`,{className:`px-1 text-sm font-medium`,children:`Outgoing email (SMTP)`}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:!E||!u.smtp.enabled||b,onClick:()=>a(E.address),children:`Send test email`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Save your SMTP settings before testing. The test uses the saved account.`}),i&&(0,Z.jsx)(ym,{workspaceId:e,initialAccount:{driver:`imap`,address:i},testEmail:!0,onClose:()=>a(null)}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.enabled,onChange:e=>I(`smtp`,{...u.smtp,enabled:e.target.checked})}),`Allow sending from Canvas`]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[[`host`,`user`,`password`,`from`,`sentFolder`].map(e=>(0,Z.jsxs)(`label`,{className:`text-xs`,children:[{host:`SMTP host`,user:`SMTP username`,password:`SMTP password (blank keeps current)`,from:`From address`,sentFolder:`Sent folder`}[e],(0,Z.jsx)(q,{type:e===`password`?`password`:`text`,value:u.smtp[e],autoComplete:`off`,onChange:t=>I(`smtp`,{...u.smtp,[e]:t.target.value})})]},e)),(0,Z.jsxs)(`label`,{className:`text-xs`,children:[`Port`,(0,Z.jsx)(q,{type:`number`,min:1,max:65535,value:u.smtp.port,onChange:e=>I(`smtp`,{...u.smtp,port:Number(e.target.value)})})]})]}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.secure,onChange:e=>I(`smtp`,{...u.smtp,secure:e.target.checked})}),`Implicit TLS (usually port 465; otherwise STARTTLS is required)`]}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.appendSent,onChange:e=>I(`smtp`,{...u.smtp,appendSent:e.target.checked})}),`Save a copy in the IMAP Sent folder (leave off if your provider does this automatically)`]}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.allowAgentSend,onChange:e=>I(`smtp`,{...u.smtp,allowAgentSend:e.target.checked})}),`Allow agents with workspace write access to send`]})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-lookback`,children:`Initial sync lookback (days)`}),(0,Z.jsx)(q,{id:`imap-lookback`,type:`number`,min:`0`,value:String(u.initialSyncDays),onChange:e=>I(`initialSyncDays`,Number(e.target.value||0))}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`First sync only (lastUid 0). Set 0 to import the whole mailbox.`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-poll`,children:`Poll interval (ms)`}),(0,Z.jsx)(q,{id:`imap-poll`,type:`number`,value:String(u.pollInterval),onChange:e=>I(`pollInterval`,Number(e.target.value||6e4))})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-xs`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.tls,onChange:e=>I(`tls`,e.target.checked)}),` TLS`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.allowSelfSigned,onChange:e=>I(`allowSelfSigned`,e.target.checked)}),` Allow self-signed`]})]})]});return(0,Z.jsxs)(`div`,{className:`space-y-3 border-t pt-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium`,children:`IMAP Accounts`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Each account mirrors under /imap/<account> in the backends tree; its folders are synced as containers. Click an account to edit its settings.`})]}),!t&&(0,Z.jsx)(`p`,{className:`rounded-md border bg-muted/40 p-2 text-xs text-muted-foreground`,children:`Enable the IMAP service before polling starts. Accounts can still be configured while it is off.`}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,onClick:c?N:F,children:[(0,Z.jsx)(Cn,{className:`h-3 w-3`}),` `,c?`Cancel`:`New Account`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`ghost`,onClick:O,disabled:g,children:[g?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Te,{className:`h-3 w-3`}),` Refresh`]})]}),(0,Z.jsx)(`div`,{className:`rounded-md border`,children:(0,Z.jsx)(`div`,{className:`max-h-[32rem] overflow-y-auto p-2 space-y-1`,children:T.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No IMAP accounts configured.`}):T.map(t=>{let n=o===t.address;return(0,Z.jsxs)(`div`,{className:`rounded px-2 py-2 text-xs transition-colors ${n?`bg-accent/40`:`hover:bg-accent/50`}`,children:[(0,Z.jsxs)(`button`,{onClick:()=>P(t),className:`w-full text-left`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 font-medium`,children:[n?(0,Z.jsx)(Ge,{className:`h-3 w-3 shrink-0`}):(0,Z.jsx)(Ye,{className:`h-3 w-3 shrink-0`}),t.address]}),(0,Z.jsx)(`span`,{className:`shrink-0 ${t.status===`error`?`text-destructive`:`text-muted-foreground`}`,children:t.status})]}),(0,Z.jsxs)(`div`,{className:`pl-[18px] text-muted-foreground`,children:[String(t.config?.host||``),` · `,(t.containers||[]).length,` folder(s)`]}),t.lastError&&(0,Z.jsxs)(`div`,{className:`pl-[18px] text-destructive`,children:[`error: `,t.lastError]})]}),n&&(0,Z.jsxs)(`div`,{className:`mt-2 space-y-3 border-t pt-2`,children:[(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:(t.containers||[]).map(n=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono truncate`,children:n.name}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Z.jsx)(`button`,{title:`Sync folder`,className:`p-1 hover:bg-accent rounded`,onClick:()=>L(t.address,n.name),disabled:!!S,children:S===`folder-sync:${t.address}:${n.name}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Te,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{title:`Remove folder`,className:`p-1 hover:bg-destructive/10 text-destructive rounded`,onClick:()=>Wr(e,`imap`,t.address,n.name).then(O).catch(e=>w({title:`Error`,description:e instanceof Error?e.message:`Failed to remove folder`,variant:`destructive`})),disabled:!!S,children:(0,Z.jsx)(lt,{className:`h-3 w-3`})})]})]},n.name))}),R,(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(J,{size:`sm`,onClick:ne,disabled:b,children:[b?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(k,{className:`h-3 w-3`}),` Save`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,disabled:!!S,onClick:()=>ie(`test`,t.address),children:[S===`test:${t.address}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Cn,{className:`h-3 w-3`}),` Test`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,disabled:!!S,onClick:()=>ie(`sync`,t.address),children:[S===`sync:${t.address}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Te,{className:`h-3 w-3`}),` Sync all`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`destructive`,disabled:!!S,onClick:re,children:[S===`delete:${t.address}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(lt,{className:`h-3 w-3`}),` Delete`]})]})]})]},t.address)})})}),c&&(0,Z.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,Z.jsx)(`h5`,{className:`text-xs font-medium`,children:`New IMAP account`}),R,(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(J,{size:`sm`,onClick:ne,disabled:b,children:[b?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(k,{className:`h-3 w-3`}),` Save`]}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,onClick:N,children:`Cancel`})]})]})]})}function S1({workspaceId:e}){let[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(!0),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)([`read`]),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(!0),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(new Set),[y,b]=(0,X.useState)(``),[x,S]=(0,X.useState)(!1),{showToast:C}=po(),[w,T]=(0,X.useState)(e);e!==w&&(T(e),i(!0));let E=(0,X.useCallback)(()=>Y.get(`/workspaces/${e}/tokens`).then(e=>{n((e||[]).map(e=>({...e,hash:e.hash||e.tokenHash||``})).filter(e=>e.hash))}).catch(()=>{C({title:`Error`,description:`Failed to load workspace tokens`,variant:`destructive`})}).finally(()=>{i(!1)}),[e,C]);(0,X.useEffect)(()=>{E()},[E]);let D=async()=>{if(!s.trim()){C({title:`Error`,description:`Token description is required`,variant:`destructive`});return}try{o(!0);let t=null;if(!p&&d){let e=new Date(d);e.setHours(23,59,59,999),t=e.toISOString()}let n={description:s,permissions:l,expiresAt:t},r=await Y.post(`/workspaces/${e}/tokens`,n);r&&r.token&&b(r.token),c(``),u([`read`]),f(``),m(!0),g(!1),i(!0),await E(),C({title:`Success`,description:`Workspace sharing token created successfully`,variant:`default`})}catch{C({title:`Error`,description:`Failed to create token`,variant:`destructive`})}finally{o(!1)}},O=async t=>{try{await Y.delete(`/workspaces/${e}/tokens/${t}`),C({title:`Success`,description:`Token revoked successfully`}),i(!0),await E()}catch{C({title:`Error`,description:`Failed to revoke token`,variant:`destructive`})}},k=e=>{let t=new Set(_);t.has(e)?t.delete(e):t.add(e),v(t)},A=e=>_.has(e)?e:`${e.substring(0,8)}...${e.substring(e.length-8)}`,j=async e=>{try{await navigator.clipboard.writeText(e),C({title:`Copied`,description:`Token hash copied to clipboard`})}catch{C({title:`Error`,description:`Failed to copy to clipboard`,variant:`destructive`})}};return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-lg font-medium`,children:`Workspace Sharing Tokens`}),(0,Z.jsxs)(J,{onClick:()=>g(!h),size:`sm`,variant:`outline`,children:[(0,Z.jsx)(H,{className:`mr-2 h-4 w-4`}),`Create Token`]})]}),h&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 bg-muted/50`,children:[(0,Z.jsx)(q,{placeholder:`Token description (e.g., 'John's laptop')`,value:s,onChange:e=>c(e.target.value)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-sm font-medium mb-2 block`,children:`Permissions`}),(0,Z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:[`read`,`write`,`admin`].map(e=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:l.includes(e),onChange:t=>{t.target.checked?u([...l,e]):u(l.filter(t=>t!==e))}}),(0,Z.jsx)(`span`,{className:`text-sm`,children:e})]},e))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-sm font-medium mb-2 block`,children:`Token Expiry`}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>{m(e.target.checked),e.target.checked&&f(``)}}),(0,Z.jsx)(`span`,{className:`text-sm`,children:`Never expires`})]}),!p&&(0,Z.jsx)(q,{type:`date`,placeholder:`Expiry date`,value:d,onChange:e=>f(e.target.value),min:new Date().toISOString().split(`T`)[0]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(J,{onClick:D,disabled:a,children:`Create Token`}),(0,Z.jsx)(J,{variant:`outline`,onClick:()=>g(!1),children:`Cancel`})]})]}),y&&(0,Z.jsxs)(`div`,{className:`p-4 border rounded-md bg-muted/50`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-center mb-2`,children:[(0,Z.jsx)(`h3`,{className:`font-semibold`,children:`Your New Workspace Sharing Token`}),(0,Z.jsx)(J,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(y),S(!0),C({title:`Success`,description:`Token copied to clipboard`}),setTimeout(()=>S(!1),2e3)}catch{C({title:`Error`,description:`Failed to copy token to clipboard`,variant:`destructive`})}},children:x?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($e,{className:`mr-2 h-4 w-4`}),`Copied`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ve,{className:`mr-2 h-4 w-4`}),`Copy`]})})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mb-2`,children:`Make sure to copy your workspace sharing token now. You won't be able to see it again!`}),(0,Z.jsx)(`div`,{className:`p-2 bg-background border rounded font-mono text-sm break-all outline-none focus:ring-2 focus:ring-ring`,children:y}),(0,Z.jsx)(J,{variant:`outline`,size:`sm`,className:`mt-2`,onClick:()=>b(``),children:`Dismiss`})]}),(0,Z.jsx)(C1,{workspaceId:e}),r?(0,Z.jsxs)(`div`,{className:`text-center py-4`,children:[(0,Z.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-b-2 border-primary mx-auto touch-target`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2`,children:`Loading tokens...`})]}):t.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(`p`,{children:`No sharing tokens created yet.`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Create a token to share this workspace with others.`})]}):(0,Z.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,Z.jsxs)(`div`,{className:`border rounded-lg p-3 flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:e.description}),(0,Z.jsx)(`span`,{className:`text-xs bg-muted px-2 py-1 rounded`,children:e.permissions.join(`, `)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:A(e.hash)}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>k(e.hash),children:_.has(e.hash)?(0,Z.jsx)(kn,{className:`h-3 w-3`}):(0,Z.jsx)(Vt,{className:`h-3 w-3`})}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>j(e.hash),children:(0,Z.jsx)(Ve,{className:`h-3 w-3`})})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Created: `,new Date(e.createdAt).toLocaleDateString(),e.expiresAt?(0,Z.jsxs)(`span`,{children:[` • Expires: `,new Date(e.expiresAt).toLocaleDateString()]}):(0,Z.jsx)(`span`,{children:` • Never expires`})]})]}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>O(e.hash),className:`text-destructive hover:text-destructive`,children:(0,Z.jsx)(lt,{className:`h-4 w-4`})})]},e.hash))})]})}function C1({workspaceId:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)([`read`]),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)([]),u=(0,X.useCallback)(()=>Y.get(`/workspaces/${e}/shares`).then(e=>l(Array.isArray(e)?e:e?.emailShares||[])).catch(()=>{}),[e]);(0,X.useEffect)(()=>{u()},[u]);let d=async()=>{if(n.trim())try{s(!0),await Y.post(`/workspaces/${e}/shares`,{userEmail:n.trim(),permissions:i}),r(``),a([`read`]),await u(),t({title:`Success`,description:`Access granted`})}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to grant access`,variant:`destructive`})}finally{s(!1)}},f=async n=>{try{await Y.delete(`/workspaces/${e}/shares/${encodeURIComponent(n)}`),await u(),t({title:`Success`,description:`Access revoked`})}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to revoke`,variant:`destructive`})}};return(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`h4`,{className:`font-medium`,children:`Email-based Shares`}),(0,Z.jsxs)(`div`,{className:`flex gap-2 flex-wrap items-center`,children:[(0,Z.jsx)(q,{placeholder:`user@local.server`,value:n,onChange:e=>r(e.target.value),className:`max-w-xs`}),(0,Z.jsx)(`div`,{className:`flex gap-2`,children:[`read`,`write`,`admin`].map(e=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:i.includes(e),onChange:t=>{t.target.checked?a([...i,e]):a(i.filter(t=>t!==e))}}),e]},e))}),(0,Z.jsx)(J,{size:`sm`,onClick:d,disabled:o,children:`Add`})]}),c.length>0&&(0,Z.jsx)(`div`,{className:`space-y-2`,children:c.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border rounded p-2`,children:[(0,Z.jsxs)(`div`,{className:`text-sm`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:e.userEmail}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e.permissions.join(`, `),e.grantedAt?` • ${new Date(e.grantedAt).toLocaleDateString()}`:``]})]}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>f(e.userEmail),className:`text-destructive hover:text-destructive`,children:`Revoke`})]},e.userEmail))})]})}var w1=[{value:`read`,label:`Read`,hint:`Browse and search`},{value:`write`,label:`Read & write`,hint:`Add, edit and organise documents`},{value:`admin`,label:`Admin`,hint:`Everything except sharing and deleting`}],T1=e=>e.includes(`admin`)?`admin`:e.includes(`write`)?`write`:`read`;function E1({workspaceId:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(!0),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(`user`),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(`read`),[m,h]=(0,X.useState)(e);e!==m&&(h(e),a(!0));let g=(0,X.useCallback)(()=>Ri(e).then(r).catch(()=>r(null)).finally(()=>a(!1)),[e]);(0,X.useEffect)(()=>{g()},[g]);let _=n?.isOwner===!0,v=n?.members??[],y=async n=>{n.preventDefault();let r=u.trim();if(r){s(`grant`);try{let n=await ia(e,c===`user`?{email:r}:{group:r},[f]);d(``),await g();let i=c===`user`?r:`group ${r}`;t({title:`Shared`,description:n.type===`user`&&n.userExists===!1?`${i} has no account here yet — the share applies as soon as they sign in.`:`Access granted to ${i}.`})}catch(e){t({title:`Could not share`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{s(null)}}},b=async(n,r)=>{let i=`${n.type}:${n.principal}`;s(i);try{await Ji(e,n.type,n.principal,[r]),await g()}catch(e){t({title:`Could not update`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{s(null)}},x=async n=>{let r=`${n.type}:${n.principal}`;s(r);try{await Ea(e,n.type,n.principal),await g(),t({title:`Access revoked`,description:`${n.principal} no longer has access.`})}catch(e){t({title:`Could not revoke`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{s(null)}};return n&&n.shareable===!1?(0,Z.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Your universe workspace is private and cannot be shared.`}):(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_?`People and groups who can open this workspace.`:`You are a member of this workspace; only its owner can change the list.`}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{a(!0),g()},disabled:i,children:[(0,Z.jsx)(Te,{className:K(`mr-2 h-3.5 w-3.5`,i&&`animate-spin`)}),`Refresh`]})]}),i?(0,Z.jsx)(`div`,{className:`rounded-md border p-4 text-sm text-muted-foreground`,children:`Loading members…`}):v.length===0?(0,Z.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Not shared with anyone.`}):v.map(e=>{let t=`${e.type}:${e.principal}`,n=T1(e.permissions);return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[e.type===`group`?(0,Z.jsx)(Ue,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}):(0,Z.jsx)(Ze,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-medium`,title:e.principal,children:e.principal}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e.type===`group`?`Group`:`User`,e.description?` · ${e.description}`:``,e.grantedAt?` · since ${new Date(e.grantedAt).toLocaleDateString()}`:``]}),e.type===`user`&&e.userExists===!1&&(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-[11px] text-warning`,children:[(0,Z.jsx)(B,{className:`h-3 w-3`}),` No account yet — applies at first sign-in`]})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[_?(0,Z.jsx)(`select`,{value:n,disabled:o===t,onChange:t=>b(e,t.target.value),className:`rounded-md border border-input bg-background px-2 py-1 text-xs focus:outline-none focus:ring-2 focus:ring-ring`,title:`Access level`,children:w1.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))}):(0,Z.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs`,children:w1.find(e=>e.value===n)?.label}),_&&(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,className:`text-destructive hover:text-destructive`,disabled:o===t,onClick:()=>x(e),title:`Revoke access`,children:(0,Z.jsx)(he,{className:`h-3.5 w-3.5`})})]})]},t)})]}),_&&(0,Z.jsxs)(`form`,{onSubmit:y,className:`space-y-3 rounded-md border p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium`,children:[`Share with`,(0,Z.jsx)(`div`,{className:`inline-flex overflow-hidden rounded-md border`,children:[`user`,`group`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>l(e),className:K(`px-3 py-1 text-xs`,c===e?`bg-primary text-primary-foreground`:`bg-background text-muted-foreground hover:bg-muted`),children:e===`user`?`a person`:`a group`},e))})]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[1fr_auto]`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(q,{type:c===`user`?`email`:`text`,value:u,onChange:e=>d(e.target.value),placeholder:c===`user`?`colleague@corp.tld`:`team-a or cn=team-a,ou=groups,dc=corp,dc=tld`,autoComplete:`off`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:c===`user`?`The share is keyed by e-mail: it works even before the person signs in for the first time.`:`Directory group (LDAP/AD memberOf — full DN or just the CN) or a group an admin assigned to local accounts.`})]}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`,title:w1.find(e=>e.value===f)?.hint,children:w1.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})})]}),(0,Z.jsx)(J,{type:`submit`,size:`sm`,disabled:o===`grant`||!u.trim(),children:o===`grant`?`Sharing…`:`Share workspace`})]})]})}function D1({workspaceId:e,workspaceName:t,isActive:n,onChanged:r}){let{showToast:i}=po(),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(!0),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(``),C=(0,X.useRef)(null),w=(0,X.useCallback)(async()=>{try{o(n?await Mi(e):[])}catch{o([])}finally{c(!1)}},[e,n]);(0,X.useEffect)(()=>{w()},[w]);let T=async()=>{if(!(n&&!window.confirm(`'${t}' is running. It has to be stopped to be exported — its index is only consistent on disk once it has flushed.\n\nStop it and export now?`))){u(!0);try{let t=await Ur(e,{stop:!0});f(t.stoppedWorkspace),i({title:`Workspace exported`,description:`${t.name} — ${bi(t.size)}`}),await w(),t.stoppedWorkspace&&r?.()}catch(e){i({title:`Export failed`,description:e instanceof Error?e.message:`Failed to export workspace`,variant:`destructive`})}finally{u(!1)}}},E=async()=>{m(!0);try{await ui(e),f(!1),i({title:`Workspace started`,description:`'${t}' is running again.`}),r?.()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to start workspace`,variant:`destructive`})}finally{m(!1)}},D=async e=>{g(e.name);try{await ei(e.name)}catch(e){i({title:`Download failed`,description:e instanceof Error?e.message:`Failed to download archive`,variant:`destructive`})}finally{g(null)}},O=async e=>{if(window.confirm(`Delete ${e.name}? The archive is removed from the server; any copy you already downloaded is untouched.`)){g(e.name);try{await gi(e.name),await w()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to delete archive`,variant:`destructive`})}finally{g(null)}}},k=async e=>{b(`uploading`),v(0),S(``);try{let t=await xa(e,e=>{v(Math.round(e*100)),e>=1&&b(`server`)},e=>S(ga[e.phase]||e.phase));i({title:`Workspace imported`,description:`'${t.label||t.name}' was extracted, validated and loaded.`}),r?.(),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){i({title:`Import failed`,description:e instanceof Error?e.message:`Failed to import workspace`,variant:`destructive`})}finally{b(null),v(null),S(``),C.current&&(C.current.value=``)}},A=y!==null;return(0,Z.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(et,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Export & Import`})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Export packs this workspace into a single compressed archive you can download and move elsewhere. The workspace is stopped first — an export of a running workspace would capture a half-written index.`}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:l||A,onClick:T,children:[(0,Z.jsx)(et,{className:`mr-2 h-3.5 w-3.5 ${l?`animate-pulse`:``}`}),l?`Exporting…`:`Export Workspace`]}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:s||l,onClick:()=>void w(),children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${s?`animate-spin`:``}`}),`Refresh`]}),d&&(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:p,onClick:E,children:p?`Starting…`:`Start workspace again`})]}),(0,Z.jsxs)(`div`,{className:`mt-4 border-t pt-3`,children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Archives`}),s?(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`No exports yet.`}):(0,Z.jsx)(`ul`,{className:`mt-2 space-y-2`,children:a.map(e=>(0,Z.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-md border p-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs`,children:e.name}),(0,Z.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[bi(e.size),` · `,new Date(e.createdAt).toLocaleString()]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:h===e.name,onClick:()=>D(e),title:`Download (${bi(e.size)})`,children:(0,Z.jsx)(er,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:h===e.name,onClick:()=>O(e),className:`text-destructive hover:text-destructive`,title:`Delete archive`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]})]},e.name))})]}),(0,Z.jsxs)(`div`,{className:`mt-4 border-t pt-3`,children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Import`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Pick a workspace archive from your local drive. It is uploaded into your home, extracted into your Workspaces folder, validated and loaded as a new workspace.`}),(0,Z.jsx)(`input`,{ref:C,type:`file`,accept:`.tar.gz,.tgz,.tar.bz2,.tbz2,.tbz,application/gzip,application/x-bzip2`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&k(t)}}),(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3`,children:[(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:A||l,onClick:()=>C.current?.click(),children:[(0,Z.jsx)(re,{className:`mr-2 h-3.5 w-3.5`}),`Import from local drive…`]}),y===`uploading`&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Uploading… `,_,`%`]}),y===`server`&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:x||`Extracting, validating and loading…`})]})]})]})}var O1={"workspace:home":{title:`Workspace Home`,description:`User-managed roaming home folder, exported through WebDAV and watched for changes. Mirrored into the backends tree.`},"workspace:data":{title:`Workspace Data`,description:`Managed content-addressable blob store (deduped, checksum-keyed). Opaque by design: the tree is the navigation; not meant for direct edits or export.`},s3:{title:`S3`,description:`Remote object storage. Placeholder until Stored gets a real S3 driver.`},imap:{title:`IMAP`,description:`Mailbox data source; ingested mail lands in the backends tree.`}},k1=[{id:`git`,title:`Git`,description:`Git-backed dotfile access.`},{id:`webdav`,title:`WebDAV`,description:`Mountable access to the workspace home backend.`},{id:`imapSync`,title:`IMAP Sync Worker`,description:`Background mailbox polling and ingestion.`}];function A1({checked:e,disabled:t,onClick:n}){return(0,Z.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:t,onClick:n,className:`relative inline-flex h-5 w-9 shrink-0 rounded-full border-2 border-transparent transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${e?`bg-primary`:`bg-muted-foreground/30`}`,children:(0,Z.jsx)(`span`,{className:`pointer-events-none inline-block h-4 w-4 rounded-full bg-background shadow transition-transform ${e?`translate-x-4`:`translate-x-0`}`})})}function j1({workspaceId:e,onAdded:t}){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),{showToast:m}=po(),h=()=>{a(``),s(``),l(!1),d(!1)};return n?(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),!(!i.trim()||!o.trim())){p(!0);try{await na(e,`file`,{name:i.trim(),path:o.trim(),watch:c,readOnly:u}),m({title:`Added`,description:`${i.trim()} mounted; initial scan running in the background`}),h(),r(!1),await t()}catch(e){m({title:`Error`,description:e instanceof Error?e.message:`Failed to add folder backend`,variant:`destructive`})}finally{p(!1)}}},className:`w-full space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ut,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Add local folder`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Index a folder on the server host as a data source. Files stay in place; the index records them as device-scoped locations, so they remain addressable if the workspace moves to another server.`}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Name`}),(0,Z.jsx)(q,{value:i,onChange:e=>a(e.target.value),placeholder:`Financial Reports`,required:!0})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Absolute path on server`}),(0,Z.jsx)(q,{value:o,onChange:e=>s(e.target.value),placeholder:`/mnt/data/reports`,required:!0,className:`font-mono`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-6 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[`watch`,(0,Z.jsx)(A1,{checked:c,onClick:()=>l(e=>!e)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,title:`Never delete bytes in this folder. Destroy degrades to a reference drop. Recommended for folders managed outside Canvas.`,children:[`read-only`,(0,Z.jsx)(A1,{checked:u,onClick:()=>d(e=>!e)})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(J,{type:`submit`,size:`sm`,disabled:f||!i.trim()||!o.trim(),children:f?`Adding…`:`Add folder`}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,disabled:f,onClick:()=>{h(),r(!1)},children:`Cancel`})]})]}):(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(!0),children:[(0,Z.jsx)(ut,{className:`mr-2 h-3.5 w-3.5`}),`Add local folder`]})}function M1({workspaceId:e,onAdded:t}){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)({name:``,clientId:``,clientSecret:``,refreshToken:``,folderId:``}),[o,s]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),{showToast:p}=po(),m=e=>t=>a(n=>({...n,[e]:t.target.value})),h=()=>{a({name:``,clientId:``,clientSecret:``,refreshToken:``,folderId:``}),s(!1),u(!1)},g=i.name.trim()&&i.clientId.trim()&&i.clientSecret.trim()&&i.refreshToken.trim();return n?(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),g){f(!0);try{await na(e,`gdrive`,{name:i.name.trim(),clientId:i.clientId.trim(),clientSecret:i.clientSecret.trim(),refreshToken:i.refreshToken.trim(),folderId:i.folderId.trim()||`root`,watch:o,readOnly:l}),p({title:`Added`,description:`${i.name.trim()} connected; initial scan running in the background`}),h(),r(!1),await t()}catch(e){p({title:`Error`,description:e instanceof Error?e.message:`Failed to add Google Drive backend`,variant:`destructive`})}finally{f(!1)}}},className:`w-full space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(c,{icon:`mdi:google-drive`,width:16,height:16,className:`text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Add Google Drive`})]}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Index a Drive folder (or the whole My Drive) as a remote data source. Files are hashed from Drive metadata, uploads are queued through the workspace cache. Needs an OAuth client with the `,(0,Z.jsx)(`code`,{children:`drive`}),` scope and an offline-access refresh token — the same kind of credentials as the Google Calendar connector.`]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Name`}),(0,Z.jsx)(q,{value:i.name,onChange:m(`name`),placeholder:`Work Drive`,required:!0})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Folder id (empty = My Drive root)`}),(0,Z.jsx)(q,{value:i.folderId,onChange:m(`folderId`),placeholder:`1AbC…`,className:`font-mono`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`OAuth client id`}),(0,Z.jsx)(q,{value:i.clientId,onChange:m(`clientId`),required:!0,className:`font-mono`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`OAuth client secret`}),(0,Z.jsx)(q,{type:`password`,value:i.clientSecret,onChange:m(`clientSecret`),required:!0,className:`font-mono`,autoComplete:`off`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 sm:col-span-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Refresh token`}),(0,Z.jsx)(q,{type:`password`,value:i.refreshToken,onChange:m(`refreshToken`),required:!0,className:`font-mono`,autoComplete:`off`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-6 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,title:`Poll the Drive changes feed (every 60s) so edits made in Drive show up without a manual re-sync.`,children:[`watch`,(0,Z.jsx)(A1,{checked:o,onClick:()=>s(e=>!e)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,title:`Never delete files in this Drive. Destroy degrades to a reference drop.`,children:[`read-only`,(0,Z.jsx)(A1,{checked:l,onClick:()=>u(e=>!e)})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(J,{type:`submit`,size:`sm`,disabled:d||!g,children:d?`Checking…`:`Add Drive`}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,disabled:d,onClick:()=>{h(),r(!1)},children:`Cancel`})]})]}):(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(!0),children:[(0,Z.jsx)(c,{icon:`mdi:google-drive`,width:14,height:14,className:`mr-2`}),`Add Google Drive`]})}function N1({workspaceId:e,backend:t}){let[n,r]=(0,X.useState)(t.usage??null),[i,a]=(0,X.useState)(!1),{showToast:o}=po();return(0,Z.jsxs)(`button`,{type:`button`,onClick:async()=>{a(!0);try{r(await Vr(e,t.driver,t.address))}catch(e){o({title:`Error`,description:e instanceof Error?e.message:`Failed to compute size`,variant:`destructive`})}finally{a(!1)}},disabled:i,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-[11px] text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50`,title:n?`Computed ${new Date(n.computedAt).toLocaleString()}; click to refresh`:`Compute on-disk size (walks the backend folder; may take a while)`,children:[(0,Z.jsx)(hr,{className:`h-3 w-3 ${i?`animate-pulse`:``}`}),i?`Calculating…`:n?bi(n.bytes):`Size`]})}function P1({workspaceId:e}){let[t,n]=(0,X.useState)(!1),{showToast:r}=po();return(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t,onClick:async()=>{n(!0);try{let{removed:t}=await qi(e);r({title:`Thumbnail cache cleared`,description:`${t} cached thumbnail(s) removed`})}catch(e){r({title:`Error`,description:e instanceof Error?e.message:`Failed to clear thumbnail cache`,variant:`destructive`})}finally{n(!1)}},title:`Remove all cached thumbnails; they regenerate on demand`,children:[(0,Z.jsx)(lt,{className:`mr-2 h-3.5 w-3.5 ${t?`animate-pulse`:``}`}),t?`Clearing…`:`Clear thumbnails`]})}function F1({workspaceId:e}){let[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(!1),{showToast:a}=po();return(0,Z.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(hr,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Disk usage`})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Total on-disk size of this workspace (index, blobs, home, cache): what an export or sync would move. Computed on demand; may take a while on large workspaces.`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3`,children:[t&&(0,Z.jsx)(`span`,{className:`text-sm font-semibold`,children:bi(t.bytes)}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:r,onClick:async()=>{i(!0);try{n(await li(e))}catch(e){a({title:`Error`,description:e instanceof Error?e.message:`Failed to compute workspace size`,variant:`destructive`})}finally{i(!1)}},children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${r?`animate-spin`:``}`}),r?`Calculating…`:t?`Recalculate`:`Calculate size`]})]})]}),t&&(0,Z.jsx)(`div`,{className:`mt-3 grid grid-cols-2 gap-x-6 gap-y-1 border-t pt-3 sm:grid-cols-3`,children:Object.entries(t.breakdown).sort(([,e],[,t])=>t-e).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-xs`,children:[(0,Z.jsx)(`span`,{className:`truncate font-mono text-muted-foreground`,children:e}),(0,Z.jsx)(`span`,{children:bi(t)})]},e))})]})}function I1({backend:e,busy:t,onSave:n}){let r=e.config||{},i=Array.isArray(r.exclude)?r.exclude:[],a=Array.isArray(r.effectiveExclusions)?r.effectiveExclusions:[],o=Math.max(a.length-i.length,0),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(i.join(`
|
|
77
|
+
`).catch(()=>{})}c(`hooks`),U(`rules.json`)}}),s===`runs`&&(0,Z.jsx)(`div`,{className:`border rounded-lg overflow-auto max-h-[560px]`,children:h?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:`Loading...`}):ne.length===0?(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground p-3`,children:[`No runs recorded yet`,ie?` (failed only)`:``,`. Runs appear here every time a rule or hook executes.`]}):(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{className:`text-xs text-muted-foreground border-b sticky top-0 bg-background`,children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Time`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Handler`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Event`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Docs`}),(0,Z.jsx)(`th`,{className:`text-right font-medium px-3 py-2`,children:`ms`}),(0,Z.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Status`}),(0,Z.jsx)(`th`,{className:`px-2 py-2`})]})}),(0,Z.jsx)(`tbody`,{children:ne.map(e=>(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsxs)(`tr`,{className:`border-b last:border-0 align-top hover:bg-muted/40`,children:[(0,Z.jsx)(`td`,{className:`px-3 py-1.5 whitespace-nowrap text-xs text-muted-foreground`,title:e.ts,children:new Date(e.ts).toLocaleString()}),(0,Z.jsxs)(`td`,{className:`px-3 py-1.5 font-mono text-xs`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.handlerType,`:`]}),e.handler,e.origin!==`user`&&(0,Z.jsxs)(`span`,{className:`ml-1.5 text-[10px] uppercase tracking-wide rounded bg-muted-foreground/15 px-1 py-0.5 text-muted-foreground`,children:[e.origin,e.depth?` d${e.depth}`:``]})]}),(0,Z.jsxs)(`td`,{className:`px-3 py-1.5 font-mono text-xs`,children:[e.event,e.batch?` (batch)`:``]}),(0,Z.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs`,children:(e.docIds||[]).join(`, `)}),(0,Z.jsx)(`td`,{className:`px-3 py-1.5 text-right font-mono text-xs`,children:e.durationMs}),(0,Z.jsxs)(`td`,{className:`px-3 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:e.status===`error`?`text-destructive font-medium`:e.status===`skipped`?`text-muted-foreground`:`text-success dark:text-success`,children:e.status}),e.error&&(0,Z.jsx)(`span`,{className:`block text-destructive/80 font-mono break-all`,children:e.error}),e.skipReason&&(0,Z.jsx)(`span`,{className:`block text-muted-foreground`,children:e.skipReason}),e.actions&&e.actions.length>0&&(0,Z.jsx)(`span`,{className:`block text-muted-foreground font-mono`,children:e.actions.map(e=>`${e.action}:${e.status}`).join(` `)}),e.actions?.filter(e=>e.error).map((e,t)=>(0,Z.jsxs)(`span`,{className:`block break-all font-mono ${e.status===`error`?`text-destructive/80`:`text-muted-foreground`}`,children:[e.action,`: `,e.error]},t))]}),(0,Z.jsxs)(`td`,{className:`px-2 py-1.5 whitespace-nowrap`,children:[(0,Z.jsxs)(J,{size:`sm`,variant:`ghost`,className:`h-6 px-1.5 touch-target`,title:e.traceLines?`Execution log (${e.traceLines} lines)`:`Execution log`,onClick:()=>ce(e.runId),children:[(0,Z.jsx)(Tt,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(Ge,{className:`ml-0.5 h-3 w-3 transition-transform ${oe?.runId===e.runId?`rotate-180`:``}`})]}),e.handlerType!==`dispatch`&&(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 touch-target`,title:`Replay this run (reloads the document, re-runs the handler)`,disabled:z!==null,onClick:()=>be(e),children:(0,Z.jsx)(He,{className:`h-3 w-3 ${z===e.runId?`animate-spin`:``}`})})]})]}),oe?.runId===e.runId&&(0,Z.jsx)(`tr`,{className:`border-b last:border-0 bg-muted/30`,children:(0,Z.jsx)(`td`,{colSpan:7,className:`px-3 py-2`,children:(0,Z.jsx)($$,{state:oe})})})]},e.runId))})]})}),xe&&d&&O&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 bg-muted/30 text-sm`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h4`,{className:`font-medium mb-2`,children:[`Hook context (`,(0,Z.jsx)(`span`,{className:`font-mono`,children:`ctx`}),`)`]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:O.contextApi?.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:e.signature}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e.description})]},e.name))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`h4`,{className:`font-medium mb-2`,children:[`Classifier (`,(0,Z.jsx)(`span`,{className:`font-mono`,children:`const c = ctx.classify()`}),`)`]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:O.classifier.predicates.map(e=>(0,Z.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:e},e))}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:[`Fields: `,O.classifier.fields.map(e=>(0,Z.jsxs)(`code`,{className:`font-mono`,children:[e,` `]},e)),`(never throws; all predicates are false for a null/unknown document).`]})]}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Full reference: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`docs/hooks.md`}),` in the server repo.`]})]}),E&&s===`scripts`&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-3 flex gap-2 items-center bg-muted/50`,children:[(0,Z.jsx)(q,{placeholder:`on-image.sh`,value:N,onChange:e=>P(e.target.value),className:`font-mono text-sm`}),(0,Z.jsx)(J,{size:`sm`,onClick:Fe,disabled:ee,children:`Create`}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>D(!1),children:`Cancel`})]}),E&&s===`hooks`&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3 bg-muted/50`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground block mb-1`,children:`1. When (event)`}),(0,Z.jsx)(`select`,{className:`w-full h-9 rounded-md border bg-background px-2 font-mono text-sm outline-none focus:ring-2 focus:ring-ring`,value:j,onChange:e=>M(e.target.value),children:(O?.events??[]).map(e=>(0,Z.jsxs)(`option`,{value:e.name,children:[e.name,`: `,e.description]},e.name))}),O&&(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1 font-mono`,children:[`payload: `,O.events.find(e=>e.name===j)?.payload]}),(0,Z.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground block mt-3 mb-1`,children:`2. Name`}),(0,Z.jsx)(q,{placeholder:`my-hook`,value:N,onChange:e=>P(e.target.value),className:`font-mono text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground block mb-1`,children:`3. Then (actions; pick any)`}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-52 overflow-auto pr-1`,children:(O?.actions??[]).map(e=>(0,Z.jsxs)(`label`,{className:`flex items-start gap-2 text-sm rounded px-2 py-1 hover:bg-muted cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`mt-1`,checked:F.includes(e.id),onChange:()=>Ie(e.id)}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,Z.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.description})]})]},e.id))})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(J,{size:`sm`,onClick:Le,disabled:ee||!O,children:ee?`Creating…`:`Create skeleton`}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>D(!1),children:`Cancel`}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Creates a disabled skeleton. Edit the TODOs, then enable it. Simple match→action automations can also go into `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`rules.json`}),` (no code).`]})]})]}),xe&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,Z.jsx)(`div`,{className:`md:col-span-1 border rounded-lg p-2 max-h-[480px] overflow-auto`,children:h?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground p-2`,children:`Loading...`}):p.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground p-2`,children:`No hooks yet.`}):Object.entries(Re).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground px-2 py-1`,children:e}),t.map(e=>{let t=TQ(e.path);return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded px-2 py-1 cursor-pointer text-sm ${_===e.path?`bg-muted`:`hover:bg-muted/50`} ${t?``:`opacity-50`}`,onClick:()=>U(e.path),children:[(0,Z.jsxs)(`span`,{className:`font-mono truncate flex items-center gap-1.5`,children:[e.path,s===`hooks`&&EQ(e.path)&&(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide rounded bg-muted-foreground/15 px-1 py-0.5 text-muted-foreground shrink-0`,children:`example`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center`,children:[s===`hooks`&&YQ(e.path)&&(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 touch-target`,title:YQ(e.path)?.startsWith(`document.`)?`Run against up to ${ge} existing documents`:`Run now`,disabled:me!==null,onClick:t=>{t.stopPropagation(),Ae(e.path)},children:(0,Z.jsx)(Oe,{className:`h-3 w-3 ${me===e.path?`animate-pulse`:``}`})}),s===`hooks`&&(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 touch-target`,title:t?`Disable`:`Enable`,onClick:t=>{t.stopPropagation(),De(e.path)},children:t?(0,Z.jsx)(x,{className:`h-3 w-3`}):(0,Z.jsx)(on,{className:`h-3 w-3 text-muted-foreground`})}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 text-destructive hover:text-destructive touch-target`,onClick:t=>{t.stopPropagation(),je(e.path)},children:(0,Z.jsx)(lt,{className:`h-3 w-3`})})]})]},e.path)})]},e))}),(0,Z.jsx)(`div`,{className:ue?`fixed inset-0 z-50 bg-background p-4 flex flex-col`:`md:col-span-2 border rounded-lg p-2 flex flex-col`,children:_?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`span`,{className:`font-mono text-sm truncate`,children:[_,S?` •`:``]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[s===`hooks`&&YQ(_)&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(J,{size:`sm`,variant:`outline`,className:`h-8`,title:TQ(_)?`Disable this hook (renames it with a disabled- prefix)`:`Enable this hook (strips the prefix)`,onClick:()=>De(_),children:TQ(_)?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(x,{className:`mr-1.5 h-3.5 w-3.5`}),` Enabled`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(on,{className:`mr-1.5 h-3.5 w-3.5 text-muted-foreground`}),` Disabled`]})}),(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,className:`h-8`,title:`Run this hook now`,disabled:me!==null||S,onClick:()=>Ae(_),children:[(0,Z.jsx)(Oe,{className:`mr-1.5 h-3.5 w-3.5 ${me===_?`animate-pulse`:``}`}),` Run`]})]}),(0,Z.jsxs)(J,{size:`sm`,onClick:we,disabled:w||!S,children:[(0,Z.jsx)(k,{className:`mr-2 h-4 w-4`}),` Save`]}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-8 w-8 p-0`,title:ue?`Exit full screen (Esc)`:`Edit full screen`,onClick:()=>de(!ue),children:ue?(0,Z.jsx)(it,{className:`h-4 w-4`}):(0,Z.jsx)(Fn,{className:`h-4 w-4`})})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto rounded border text-sm ${ue?``:`min-h-[400px] max-h-viewport-pane`}`,children:(0,Z.jsx)(gQ,{value:y,path:_,onChange:e=>{b(e),C(!0)}})})]}):(0,Z.jsxs)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-muted-foreground min-h-[400px]`,children:[`Select a `,s===`hooks`?`hook`:`script`,` to edit, or create a new one.`]})})]}),(s===`rules`||s===`hooks`)&&(0,Z.jsxs)(`label`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground`,title:`1–10000. Raise it when "Apply to existing items" reports fewer matches than you expect.`,children:[(0,Z.jsx)(kt,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{children:`Apply / run in batches of`}),(0,Z.jsx)(q,{type:`number`,min:1,max:1e4,step:100,value:ve,onChange:e=>ye(e.target.value),onBlur:B,onKeyDown:e=>{e.key===`Enter`&&(B(),e.target.blur())},className:`h-7 w-20 px-2 text-xs`}),(0,Z.jsx)(`span`,{children:`documents per pass — the rule "Apply" button and manual hook runs stop after that many.`})]}),(0,Z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(We,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsxs)(`span`,{children:[`Everything here lives in the workspace git repo. Clone it with`,` `,(0,Z.jsxs)(`code`,{className:`break-all rounded bg-muted px-1 py-0.5 font-mono select-all`,children:[`git clone `,ze.replace(`://`,`://canvas@`)]}),` `,`(password: a canvas API token; the `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`canvas@`}),` username is arbitrary but git needs one). Pushes hot-reload hooks.`]})]})]})}function $$({state:e}){if(e.error)return(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:e.error});if(!e.run)return(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading…`});let t=e.run,n={error:`text-destructive`,warn:`text-warning`,info:`text-foreground`,debug:`text-muted-foreground`};return(0,Z.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{children:[`run `,(0,Z.jsx)(`span`,{className:`font-mono`,children:t.runId})]}),(0,Z.jsxs)(`span`,{children:[`trigger `,(0,Z.jsx)(`span`,{className:`font-mono`,children:t.trigger})]}),t.eventId&&(0,Z.jsxs)(`span`,{children:[`event `,(0,Z.jsx)(`span`,{className:`font-mono`,children:t.eventId})]}),(0,Z.jsxs)(`span`,{children:[t.durationMs,` ms`]})]}),t.actions&&t.actions.length>0&&(0,Z.jsx)(`ol`,{className:`space-y-0.5 font-mono`,children:t.actions.map((e,t)=>(0,Z.jsxs)(`li`,{className:e.status===`error`?`text-destructive`:e.status===`skipped`?`text-muted-foreground`:``,children:[t+1,`. `,e.action,` → `,e.status,e.error?` — ${e.error}`:``]},t))}),t.trace&&t.trace.length>0?(0,Z.jsx)(`pre`,{className:`max-h-96 overflow-auto rounded-md border bg-background p-2 font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-all`,children:t.trace.map((e,t)=>(0,Z.jsxs)(`span`,{className:`block ${n[e.level]||``}`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[`+`,String(e.t).padStart(5,` `),`ms `]}),(0,Z.jsxs)(`span`,{className:`uppercase text-muted-foreground`,children:[e.level.padEnd(5,` `),` `]}),e.msg]},t))}):(0,Z.jsxs)(`p`,{className:`text-muted-foreground`,children:[`No execution log recorded for this run`,t.error?``:` (older runs predate tracing)`,`.`]})]})}function e1({workspaceName:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),u=(0,X.useCallback)(async()=>{a(!0);try{r(await ta(e))}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to load the trash`,variant:`destructive`})}finally{a(!1)}},[e]);(0,X.useEffect)(()=>{u()},[u]);let d=(0,X.useCallback)(e=>o.includes(e),[o]),f=async(e,t)=>{s(t=>[...t,...e]);try{await t()}finally{s(t=>t.filter(t=>!e.includes(t)))}},p=n=>f([n.id],async()=>{try{let i=await Jr(e,[n.id]);i.failed?.length?t({title:`Not restored`,description:i.failed[0]?.error||`No restore target recorded`,variant:`destructive`}):(t({title:`Restored`,description:`Document put back where it was.`}),r(e=>e.filter(e=>e.id!==n.id)))}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to restore`,variant:`destructive`})}}),m=n=>f([n.id],async()=>{try{await oi(e,[n.id]),t({title:`Deleted`,description:`Document permanently deleted.`}),r(e=>e.filter(e=>e.id!==n.id))}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to delete`,variant:`destructive`})}}),h=async()=>{if(!c){l(!0);return}l(!1);try{let n=await oi(e);t({title:`Trash emptied`,description:`${n.destroyed?.length??0} document(s) permanently deleted.`}),r([])}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to empty the trash`,variant:`destructive`})}},g=(0,X.useMemo)(()=>n.map(e=>{let t=bo(e),n=(e.trashed?.placements??[]).flatMap(e=>e.paths.map(t=>`${e.tree}:${t}`));return{document:e,title:t.title,origin:n,trashedAt:e.trashed?.trashedAt||null}}),[n]);return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-medium`,children:`Trash`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 max-w-2xl`,children:`Removing a document from a path detaches it; when that was its last place, it lands here so nothing goes missing. Restoring puts it back everywhere it was. Emptying deletes for real: from the index and from canvas-owned storage, never from external backends.`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 max-sm:flex-wrap`,children:[(0,Z.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>u(),disabled:i,children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${i?`animate-spin`:``}`}),`Refresh`]}),(0,Z.jsxs)(J,{variant:c?`destructive`:`outline`,size:`sm`,onClick:h,onBlur:()=>l(!1),disabled:n.length===0,children:[(0,Z.jsx)(lt,{className:`mr-2 h-3.5 w-3.5`}),c?`Click again to delete everything`:`Empty trash`]})]})]}),i&&n.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading…`}),!i&&n.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The trash is empty.`}),g.length>0&&(0,Z.jsx)(`div`,{className:`border rounded-md divide-y`,children:g.map(({document:e,title:t,origin:n,trashedAt:r})=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm`,children:t}),(0,Z.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[n.length>0?`from ${n.join(`, `)}`:`no recorded origin`,r?` · ${new Date(r).toLocaleString()}`:``]})]}),(0,Z.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>p(e),disabled:d(e.id)||n.length===0,title:n.length===0?`Nothing recorded to restore to`:`Put it back where it was`,children:[(0,Z.jsx)(He,{className:`mr-2 h-3.5 w-3.5`}),`Restore`]}),(0,Z.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>m(e),disabled:d(e.id),title:`Delete permanently`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]},e.id))})]})}var t1=e=>`${Qr.workspaces}/${encodeURIComponent(e)}`;async function n1(e){return await Y.get(`${t1(e)}/mirrors`)||[]}async function r1(e,t){await Y.delete(`${t1(e)}/mirrors/${encodeURIComponent(t)}`)}async function i1(e,t=10){return Y.get(`${t1(e)}/mirrors/protection?sample=${t}`)}async function a1(e,t,n){return(await Y.patch(`${t1(e)}/mirrors/${encodeURIComponent(t)}`,n)).replica}async function o1(e){return await Y.get(`${t1(e)}/sync/conflicts`)||[]}async function s1(e,t,n){return Y.post(`${t1(e)}/sync/conflicts/${t}/resolve`,{keep:n})}var c1=e=>{if(e==null||e===``)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})},l1=e=>e==null?`—`:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<1073741824?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(2)} GB`,u1=e=>e?e.slice(0,12):`—`;function d1({mirror:e,now:t,busy:n,onForget:r,onRequired:i}){let a=e.mirror,o=!e.lastSeen||t-new Date(e.lastSeen).getTime()>6e5,s=e.replica?.role===`cache`||a.client===`fuse`,c=e.replica?.required===!0,l=a.direction||(a.client===`fuse`?`bi`:void 0);return(0,Z.jsx)(`div`,{className:`rounded-lg border p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(0,Z.jsx)(sr,{className:`h-4 w-4 text-muted-foreground mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e.name||e.deviceId}),a.client&&(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono uppercase`,children:a.client}),l&&(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,title:l===`pull`?`Backup target: the hub is the only writer`:l===`push`?`One-shot import: local is the only writer`:`Both ways`,children:l===`pull`?`⇣ pull`:l===`push`?`⇡ push`:`⇅ bi`}),c&&(0,Z.jsx)(`span`,{className:`rounded bg-emerald-500/15 px-1.5 py-0.5 text-[10px] font-mono text-emerald-700 dark:text-emerald-300`,title:`Counts toward protection`,children:`required`}),(0,Z.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] font-mono ${o?`bg-muted text-muted-foreground`:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}`,children:a.state||(o?`offline`:`online`)})]}),a.path&&(0,Z.jsx)(`p`,{className:`mt-0.5 text-[11px] font-mono text-muted-foreground truncate`,children:a.path}),(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-x-4 gap-y-0.5 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{title:`Change-log entries the device has not applied yet`,children:[`lag `,e.lag??`—`]}),(0,Z.jsxs)(`span`,{title:`Local changes waiting to be pushed`,children:[`pending `,a.pending??0]}),(a.failed??0)>0&&(0,Z.jsxs)(`span`,{className:`text-destructive`,children:[`failed `,a.failed]}),(a.conflicts??0)>0&&(0,Z.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`conflicts `,a.conflicts]}),(a.skipped??0)>0&&(0,Z.jsxs)(`span`,{children:[`skipped `,a.skipped]}),(a.reverted??0)>0&&(0,Z.jsxs)(`span`,{title:`Local edits parked in .workspace/conflicts and replaced by the hub version`,children:[`reverted `,a.reverted]}),e.behind!=null&&(0,Z.jsxs)(`span`,{title:`Documents whose current version this device does not hold yet`,className:e.behind>0&&c?`text-amber-600 dark:text-amber-400`:``,children:[`behind `,e.behind]}),(0,Z.jsxs)(`span`,{children:[`last sync `,c1(a.lastSync)]}),(0,Z.jsxs)(`span`,{children:[`seen `,c1(e.lastSeen)]}),a.prefixes&&a.prefixes.length>0&&(0,Z.jsx)(`span`,{className:`font-mono`,children:a.prefixes.join(`, `)})]}),a.lastError&&(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-destructive`,children:a.lastError}),(0,Z.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-[11px] ${s?`text-muted-foreground`:``}`,title:s?`A cache never counts toward protection`:`A document is protected once every required replica holds its current version`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`h-3 w-3`,checked:c,disabled:n||s,onChange:e=>i(e.target.checked)}),`required for protection`]})]})]}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:n,title:`Forget this mirror record (the device is not revoked)`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]})})}function f1({p:e}){let t=e.required.length===0,n=e.unprotected??0,r=t||n>0?An:Ht,i=t?`text-muted-foreground`:n>0?`text-amber-600 dark:text-amber-400`:`text-emerald-700 dark:text-emerald-300`;return(0,Z.jsx)(`div`,{className:`rounded-lg border p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Z.jsx)(r,{className:`h-4 w-4 mt-0.5 shrink-0 ${i}`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 text-[11px]`,children:[t?(0,Z.jsxs)(`p`,{className:`text-sm`,children:[`No replica is marked `,(0,Z.jsx)(`span`,{className:`font-medium`,children:`required`}),` yet — nothing is counted as protected. Tick it on the device that must hold every document (the backup).`]}):(0,Z.jsxs)(`p`,{className:`text-sm`,children:[(0,Z.jsxs)(`span`,{className:`font-medium ${i}`,children:[e.protected??0,` of `,e.total-e.unversioned]}),` documents are held at their current version by every required replica`,n>0&&(0,Z.jsxs)(`span`,{className:i,children:[` · `,n,` not yet`]}),e.partial&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (first `,e.total,` checked)`]})]}),e.oldestUnprotected.length>0&&(0,Z.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-muted-foreground`,children:[e.oldestUnprotected.slice(0,5).map(e=>(0,Z.jsxs)(`li`,{className:`truncate`,title:`document ${e.docId} v${e.version}`,children:[e.key,` `,(0,Z.jsxs)(`span`,{className:`opacity-70`,children:[`· `,c1(e.mtime)]})]},`${e.docId}:${e.key}`)),e.oldestUnprotected.length>5&&(0,Z.jsxs)(`li`,{children:[`… and `,e.oldestUnprotected.length-5,` more`]})]})]})]})})}function p1({conflict:e,busy:t,onResolve:n}){let r=!e.hub;return(0,Z.jsxs)(`div`,{className:`rounded-lg border p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Z.jsx)(at,{className:`h-4 w-4 text-amber-500 mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium font-mono break-all`,children:e.key}),(0,Z.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`from `,(0,Z.jsx)(`span`,{className:`font-medium`,children:e.deviceName||e.device||`unknown device`}),` · `,c1(e.ts),e.mode===`rename`&&e.conflictKey&&(0,Z.jsxs)(Z.Fragment,{children:[` · already on disk as `,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.conflictKey})]})]})]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 text-[11px] sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`rounded border border-dashed p-2`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:`Hub version (keeps the name)`}),e.hub?(0,Z.jsxs)(`div`,{className:`font-mono`,children:[u1(e.hub.sha256),` · `,l1(e.hub.size),` · `,c1(e.hub.mtime)]}):(0,Z.jsx)(`div`,{className:`italic text-muted-foreground`,children:`no file at this key any more`})]}),(0,Z.jsxs)(`div`,{className:`rounded border border-dashed p-2`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:`Incoming version (the device’s)`}),(0,Z.jsxs)(`div`,{className:`font-mono`,children:[u1(e.incoming.sha256),` · `,l1(e.incoming.size),` · `,c1(e.incoming.mtime)]})]})]}),e.resolvable?(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t||r,onClick:()=>n(`hub`),title:`Discard the device's version`,children:`Keep hub`}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t,onClick:()=>n(`incoming`),title:`The device's bytes replace the hub's; tags, relations and placements move over`,children:`Keep incoming`}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t,onClick:()=>n(`both`),title:`Keep the hub file and add the device's version under a conflict name`,children:`Keep both`})]}):(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Dropbox-style conflict copy: both files are on disk, delete the one you do not need.`})]})}function m1({workspaceId:e,workspaceUuid:t}){let{showToast:n}=po(),[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(0),h=(0,X.useRef)(null),g=(0,X.useCallback)(async(t=!1)=>{if(e){t||u(!0);try{let[t,n,r]=await Promise.all([n1(e),o1(e),i1(e).catch(()=>null)]);i(t),o(n),c(r),m(Date.now())}catch(e){t||n({title:`Error`,description:e instanceof Error?e.message:`Failed to load sync state`,variant:`destructive`})}finally{t||u(!1)}}},[e]);(0,X.useEffect)(()=>{g()},[g]),(0,X.useEffect)(()=>{if(!t)return;let e=`workspace:${t}`,n=()=>Xu.emit(`subscribe`,{channel:e}),r=Xu.on(`connect`,n);n();let i=e=>{let n=e;n?.workspaceId&&n.workspaceId!==t||(h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{h.current=null,g(!0)},800))},a=[`backend.changed`,`sync.conflict.created`,`sync.conflict.resolved`].map(e=>Xu.on(e,i));return()=>{r(),a.forEach(e=>e()),Xu.emit(`unsubscribe`,{channel:e}),h.current&&=(clearTimeout(h.current),null)}},[t,g]);let _=async t=>{f(`mirror:${t}`);try{await r1(e,t),i(e=>e.filter(e=>e.deviceId!==t)),n({title:`Forgotten`,description:`Mirror record removed. The device keeps running and will report again if it still syncs this workspace.`})}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to forget mirror`,variant:`destructive`})}finally{f(null)}},v=async(t,r)=>{f(`mirror:${t}`);try{let n=await a1(e,t,{required:r});i(e=>e.map(e=>e.deviceId===t?{...e,replica:{role:n.role,required:n.required}}:e)),c(await i1(e).catch(()=>null))}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to update replica policy`,variant:`destructive`})}finally{f(null)}},y=async(t,r)=>{f(`conflict:${t.docId}`);try{let i=await s1(e,t.docId,r);o(e=>e.filter(e=>e.docId!==t.docId));let a=r===`hub`?`kept the hub version`:r===`incoming`?`the device version now holds the name`:`kept both (${i.resultKey||`conflict copy`})`;n({title:`Resolved`,description:`${t.key}: ${a}`})}catch(e){n({title:`Error`,description:e instanceof Error?e.message:`Failed to resolve conflict`,variant:`destructive`})}finally{f(null)}};return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Device mirrors`}),(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Devices keeping this workspace’s files in sync (canvas-fuse `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`--mirror`}),`, canvas-edge). Lag counts change-log entries the device has not applied yet.`]})]}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>g(),disabled:l,children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${l?`animate-spin`:``}`}),`Refresh`]})]}),l&&r.length===0&&a.length===0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(Te,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):r.length===0?(0,Z.jsxs)(`div`,{className:`rounded-lg border border-dashed p-4 text-xs text-muted-foreground`,children:[`No device mirrors this workspace yet. Mount it with `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`canvas-fuse mount -w <workspace> ~/Workspaces --mirror`}),` on a device and it shows up here.`]}):(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[s&&(0,Z.jsx)(f1,{p:s}),r.map(e=>(0,Z.jsx)(d1,{mirror:e,now:p,busy:d===`mirror:${e.deviceId}`,onForget:()=>_(e.deviceId),onRequired:t=>v(e.deviceId,t)},e.deviceId))]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Conflicts`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`A device and the hub both changed the same file. The hub’s version keeps the filename; decide what happens to the device’s. Tags, relations and placements follow whichever version survives.`})]}),a.length===0?(0,Z.jsx)(`div`,{className:`rounded-lg border border-dashed p-4 text-xs text-muted-foreground`,children:`Nothing to resolve.`}):(0,Z.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>(0,Z.jsx)(p1,{conflict:e,busy:d===`conflict:${e.docId}`,onResolve:t=>y(e,t)},e.docId))})]})}function h1({workspaceId:e,address:t,selectedChats:n=[],onSaved:r}){let[i,a]=(0,X.useState)(n),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(``);return(0,X.useEffect)(()=>{if(!c)return;let n=!1,r,i=async()=>{try{let r=await pm(e,t);n||(d(r),p(``))}catch(e){n||p(e instanceof Error?e.message:`Connection unavailable`)}n||(r=setTimeout(()=>void i(),3e3))};return i(),()=>{n=!0,clearTimeout(r)}},[e,t,c]),(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>{c||a(n),l(!c)},children:c?`Close connection panel`:`Pair / connection status`}),c&&(0,Z.jsxs)(`div`,{className:`space-y-2 p-2 text-xs`,children:[(0,Z.jsx)(`p`,{children:f||u?.state||`Connecting…`}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>{window.confirm(`Forget the current session and pair this account again?`)&&hm(e,t).catch(e=>p(e.message))},children:`Pair again`}),u?.qr&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{children:`WhatsApp → Settings → Linked devices → Link a device.`}),(0,Z.jsx)(`img`,{className:`max-w-full`,src:u.qr,width:256,height:256,alt:`WhatsApp device pairing QR code`})]}),u?.chats.length?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{children:`Select conversations to synchronize into this workspace.`}),(0,Z.jsx)(`div`,{className:`max-h-48 overflow-auto`,children:u.chats.map(e=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,disabled:o,checked:i.includes(e.id),onChange:t=>a(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),e.name,` · `,(0,Z.jsx)(`code`,{children:e.id})]},e.id))}),(0,Z.jsx)(J,{size:`sm`,disabled:o,onClick:async()=>{s(!0),p(``);try{await da(e,`whatsapp`,t,{chats:i}),await r?.()}catch(e){p(e instanceof Error?e.message:`Could not save conversations`)}finally{s(!1)}},children:o?`Saving…`:`Save conversations and sync`}),!i.length&&(0,Z.jsx)(`p`,{children:`No conversations selected; messages will not be synchronized.`})]}):null]})]})}var g1={github:{label:`GitHub Issues`,icon:`mdi:github`,blurb:`Issues from the listed repos sync as todos. Token optional for public repos.`,fields:[{key:`address`,label:`Account label`,placeholder:`e.g. canvas-ui`,required:!0},{key:`token`,label:`Personal access token`,hint:`Optional for public repos; required for write-back.`,secret:!0},{key:`repos`,label:`Repositories`,placeholder:`owner/repo, one per line`,hint:`Issues from each repo sync as todos.`,list:!0,required:!0},{key:`writeBack`,label:`Manage issues from Canvas`,hint:`Create, edit and close issues. Needs a PAT with repo scope.`,bool:!0},{key:`pruneRemoved`,label:`Remove items deleted at the source`,hint:`After each sync, issues that no longer exist in the repo are dropped from the mirror (kept as location-less orphans until database retention GC; skipped whenever the repo can’t be fully listed).`,bool:!0}]},slack:{label:`Slack`,icon:`mdi:slack`,blurb:`Channel messages sync as message documents. Bot/user token with channels:read + channels:history.`,fields:[{key:`address`,label:`Workspace label`,placeholder:`e.g. acme`,required:!0},{key:`token`,label:`Token (xoxb-… / xoxp-…)`,secret:!0,required:!0},{key:`channels`,label:`Conversations (channel names or IDs; DM IDs need im:read + im:history)`,list:!0},{key:`directMessages`,label:`Include direct messages`,hint:`Requires im:read, im:history, mpim:read and mpim:history.`,bool:!0},{key:`writeBack`,label:`Allow sending from Canvas`,hint:`Token also needs chat:write.`,bool:!0},{key:`allowAgentSend`,label:`Allow agents with workspace write access to send`,bool:!0}]},whatsapp:{label:`WhatsApp (linked device)`,icon:`mdi:whatsapp`,blurb:`Pair your phone with Canvas, then choose conversations. Uses Baileys; separate from WhatsApp Business.`,fields:[{key:`address`,label:`Account label`,placeholder:`personal`,hint:`Any unique label; no phone number required. Keep it unchanged after pairing.`,required:!0},{key:`chats`,label:`Conversation IDs to sync (one per line; available after pairing)`,list:!0},{key:`writeBack`,label:`Allow sending from Canvas`,bool:!0},{key:`allowAgentSend`,label:`Allow agents with workspace write access to send`,bool:!0}]},gcal:{label:`Google Calendar`,icon:`mdi:calendar-month`,blurb:`Events sync as calendar entries (recurring series kept as series). Offline-access OAuth credentials.`,fields:[{key:`address`,label:`Account label`,placeholder:`e.g. me-gmail`,required:!0},{key:`clientId`,label:`OAuth client id`,required:!0},{key:`clientSecret`,label:`OAuth client secret`,secret:!0,required:!0},{key:`refreshToken`,label:`Refresh token`,secret:!0,required:!0},{key:`calendars`,label:`Calendar ids (empty = primary)`,list:!0}]},caldav:{label:`CalDAV`,icon:`mdi:calendar-sync`,blurb:`Any CalDAV endpoint (GroupOffice, Nextcloud, Radicale, SOGo…). Read-only by default; enable write-back to create events from Canvas.`,fields:[{key:`address`,label:`Account label`,placeholder:`e.g. groupoffice`,required:!0},{key:`url`,label:`CalDAV URL (calendar home or one calendar)`,placeholder:`https://host/caldav/user`,required:!0},{key:`username`,label:`Username`},{key:`password`,label:`Password`,secret:!0},{key:`calendars`,label:`Calendars (names, empty = all)`,list:!0},{key:`writeBack`,label:`Create events from Canvas`,hint:`Write-back into the CalDAV calendar.`,bool:!0}]},teams:{label:`MS Teams`,icon:`mdi:microsoft-teams`,blurb:`Channel messages via Microsoft Graph (app-only credentials, admin-consented ChannelMessage.Read.All).`,fields:[{key:`address`,label:`Tenant label`,placeholder:`e.g. corp`,required:!0},{key:`tenantId`,label:`Tenant id`,required:!0},{key:`clientId`,label:`Client id`,required:!0},{key:`clientSecret`,label:`Client secret`,secret:!0,required:!0},{key:`teams`,label:`Team ids (one per line)`,list:!0,required:!0}]}};function _1(e){return e.split(/[\n,]/).map(e=>e.trim()).filter(Boolean)}function v1({workspaceId:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[l,u]=(0,X.useState)({}),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),h=(0,X.useCallback)(async()=>{let t=await wa(e).catch(()=>[]);r(t.filter(e=>e.kind===`connector`))},[e]),g=async()=>{m(!0);try{await h()}finally{m(!1)}};(0,X.useEffect)(()=>{let t=!1;return wa(e).then(e=>{t||r(e.filter(e=>e.kind===`connector`))}).catch(()=>{}),()=>{t=!0}},[e]);let _=n.some(e=>e.status===`syncing`);(0,X.useEffect)(()=>{if(!_)return;let e=setInterval(()=>{h()},4e3);return()=>clearInterval(e)},[_,h]);let v=e=>{let t=g1[e.driver];if(!t)return;let n=e.config||{},r={};for(let i of t.fields){if(i.key===`address`){r.address=e.address;continue}if(i.secret)continue;if(i.key===`writeBack`){r.writeBack=n.readOnly===!1&&(![`slack`,`whatsapp`].includes(e.driver)||n.sendEnabled===!0)?`true`:``;continue}let t=n[i.key];if(i.list){r[i.key]=Array.isArray(t)?t.join(`
|
|
78
|
+
`):``;continue}t!=null&&(r[i.key]=String(t))}u(r),a(e.driver),s(e)},y=()=>{a(null),s(null),u({})},b=async()=>{if(!i)return;let n=g1[i],r={};for(let e of n.fields){let n=(l[e.key]||``).trim();if(!n){if(e.required&&!(o&&e.secret)){t({title:`${e.label} is required`,variant:`destructive`});return}o&&!e.secret&&(r[e.key]=e.list?[]:!e.bool&&``);continue}r[e.key]=e.list?_1(n):e.bool?n===`true`:n}n.fields.some(e=>e.key===`writeBack`)&&([`slack`,`whatsapp`].includes(i)&&(r.sendEnabled=r.writeBack===!0),r.readOnly=r.writeBack!==!0,delete r.writeBack),f(!0);try{o?await da(e,o.driver,o.address,r):await na(e,i,r),y(),await h(),t({title:o?`Connector updated; sync restarted`:`Connector saved; first sync started`})}catch(e){t({title:`Failed to save connector`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{f(!1)}},x=async n=>{try{await _a(e,n.driver,n.address),t({title:`Syncing ${n.driver}/${n.address}`}),setTimeout(()=>{h()},1500)}catch(e){t({title:`Sync failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},S=async n=>{if(window.confirm(`Remove ${n.driver}/${n.address}? Synced documents stay in the backends tree until purged.`))try{await zr(e,n.driver,n.address),await h()}catch(e){t({title:`Remove failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}};return(0,Z.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Connectors`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`GitHub issues, Slack, Google Calendar, CalDAV and MS Teams, polled into the backends tree (read-only unless write-back is enabled).`})]}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:p,onClick:()=>{g()},title:`Refresh`,children:(0,Z.jsx)(Te,{className:`h-3.5 w-3.5 ${p?`animate-spin`:``}`})})]}),n.length>0&&(0,Z.jsx)(`div`,{className:`mt-3 space-y-2`,children:n.map(t=>{let n=g1[t.driver];return(0,Z.jsxs)(`div`,{className:`rounded-md border p-3`,children:[t.driver===`whatsapp`&&(0,Z.jsx)(h1,{workspaceId:e,address:t.address,selectedChats:Array.isArray(t.config?.chats)?t.config.chats:[],onSaved:h}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(c,{icon:n?.icon||`mdi:cloud-sync`,width:16,height:16,className:`shrink-0`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:n?.label||t.driver}),(0,Z.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:t.address}),(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t.status===`syncing`,onClick:()=>{x(t)},children:[(0,Z.jsx)(Te,{className:`mr-1 h-3 w-3 ${t.status===`syncing`?`animate-spin`:``}`}),t.status===`syncing`?`Syncing`:`Sync now`]}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>v(t),title:`Edit connector`,children:(0,Z.jsx)(Fe,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{S(t)},title:`Remove connector`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5 text-destructive`})})]}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{children:[`status: `,t.status]}),t.lastSyncAt&&(0,Z.jsxs)(`span`,{children:[`last sync: `,new Date(t.lastSyncAt).toLocaleString()]}),t.treePath&&(0,Z.jsx)(`span`,{className:`font-mono`,children:t.treePath})]}),t.lastError&&(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-destructive`,children:t.lastError})]},`${t.driver}:${t.address}`)})}),i?(0,Z.jsxs)(`div`,{className:`mt-3 rounded-md border p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(c,{icon:g1[i].icon,width:16,height:16}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:o?`Edit ${g1[i].label}`:g1[i].label}),o&&(0,Z.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:o.address}),(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsx)(`button`,{type:`button`,onClick:y,className:`p-1 text-muted-foreground hover:text-foreground`,"aria-label":`Cancel`,children:(0,Z.jsx)(G,{className:`h-3.5 w-3.5`})})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:g1[i].blurb}),(0,Z.jsx)(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2`,children:g1[i].fields.map(e=>(0,Z.jsxs)(`label`,{className:`text-xs ${e.list||e.bool?`sm:col-span-2`:``}`,children:[!e.bool&&(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),e.bool?(0,Z.jsxs)(`span`,{className:`mt-1 flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:l[e.key]===`true`,onChange:t=>u(n=>({...n,[e.key]:t.target.checked?`true`:``})),className:`h-4 w-4 accent-primary`}),(0,Z.jsx)(`span`,{children:e.label})]}):e.list?(0,Z.jsx)(`textarea`,{value:l[e.key]||``,onChange:t=>u(n=>({...n,[e.key]:t.target.value})),placeholder:e.placeholder,rows:2,className:`mt-1 w-full rounded-md border border-input bg-background px-2 py-1.5 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`}):(0,Z.jsx)(q,{type:e.secret?`password`:`text`,value:l[e.key]||``,disabled:!!o&&e.key===`address`,onChange:t=>u(n=>({...n,[e.key]:t.target.value})),placeholder:o&&e.secret?`Leave blank to keep current`:e.placeholder,autoComplete:`off`,className:`mt-1 h-8 text-xs`}),e.hint&&(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-muted-foreground/80`,children:e.hint})]},e.key))}),(0,Z.jsx)(J,{type:`button`,size:`sm`,className:`mt-3`,disabled:d,onClick:()=>{b()},children:d?`Saving…`:o?`Save changes & sync`:`Save & sync`})]}):(0,Z.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:Object.entries(g1).map(([e,t])=>(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{a(e),u({})},children:[(0,Z.jsx)(H,{className:`mr-1 h-3 w-3`}),(0,Z.jsx)(c,{icon:t.icon,width:14,height:14,className:`mr-1`}),t.label]},e))})]})}var y1={host:``,port:993,tls:!0,allowSelfSigned:!0,user:``,password:``,pollInterval:6e4,initialSyncDays:180,smtp:{enabled:!1,host:``,port:587,secure:!1,user:``,password:``,from:``,sentFolder:`Sent`,appendSent:!1,allowAgentSend:!1}};function b1(e){let t=e.config||{};return{host:String(t.host||``),port:Number(t.port??993),tls:t.tls!==!1,allowSelfSigned:t.allowSelfSigned!==!1,user:String(t.user||e.address),password:``,pollInterval:Number(t.pollInterval??6e4),initialSyncDays:Number(t.initialSyncDays??180),smtp:{...y1.smtp,...t.smtp||{},password:``}}}function x1({workspaceId:e,enabled:t}){let[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(y1),[f,p]=(0,X.useState)([]),[m,h]=(0,X.useState)([`INBOX`]),[g,_]=(0,X.useState)(!0),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(null),{showToast:w}=po(),T=(0,X.useMemo)(()=>[...n].sort((e,t)=>e.address.localeCompare(t.address)),[n]),E=(0,X.useMemo)(()=>n.find(e=>e.address===o)||null,[n,o]),D=(0,X.useCallback)(()=>wa(e,`imap`).then(e=>r(e)).catch(e=>{w({title:`Error`,description:e instanceof Error?e.message:`Failed to load IMAP accounts`,variant:`destructive`})}).finally(()=>_(!1)),[e,w]),O=(0,X.useCallback)(async()=>{_(!0),await D()},[D]),[A,j]=(0,X.useState)(e);e!==A&&(j(e),_(!0)),(0,X.useEffect)(()=>{D()},[D]);let M=(0,X.useCallback)(async(t,n)=>{y(!0);try{let r=t?await Yi(e,`imap`,t.address):await wr(e,`imap`,{host:(n?.host||``).trim(),port:Number(n?.port)||993,tls:n?.tls!==!1,allowSelfSigned:n?.allowSelfSigned!==!1,user:(n?.user||``).trim(),password:n?.password||``,folder:`INBOX`});p(r.filter(e=>e.selectable))}catch(e){w({title:`IMAP Error`,description:e instanceof Error?e.message:`Failed to discover folders`,variant:`destructive`})}finally{y(!1)}},[e,w]),N=()=>{l(!1),s(null),d(y1),p([]),h([`INBOX`])},P=e=>{if(o===e.address){N();return}l(!1),s(e.address),d(b1(e)),p([]),h((e.containers||[]).map(e=>e.name)),M(e)},F=()=>{N(),l(!0)},I=(e,t)=>d(n=>({...n,[e]:t})),ee=e=>h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),te=(0,X.useMemo)(()=>{let e=new Map(f.map(e=>[e.path,e]));for(let t of m)e.has(t)||e.set(t,{name:t,path:t,delimiter:`/`,selectable:!0,attributes:[]});return[...e.values()].sort((e,t)=>e.path.localeCompare(t.path))},[f,m]),ne=async()=>{x(!0);try{let t=m.length?m:[`INBOX`],n={host:u.host.trim(),user:u.user.trim(),port:Number(u.port)||993,tls:u.tls,allowSelfSigned:u.allowSelfSigned,pollInterval:Number(u.pollInterval)||6e4,initialSyncDays:Math.max(0,Number(u.initialSyncDays)||0),smtp:u.smtp,...u.password?{password:u.password}:{}};if(E){await da(e,`imap`,E.address,n);let r=new Set((E.containers||[]).map(e=>e.name)),i=t.filter(e=>!r.has(e)),a=[...r].filter(e=>!t.includes(e));i.length&&await Ni(e,`imap`,E.address,i);for(let t of a)await Wr(e,`imap`,E.address,t)}else{await na(e,`imap`,{...n,password:u.password,folder:t[0]});let r=u.user.trim();t.length>1&&await Ni(e,`imap`,r,t.slice(1))}await O(),l(!1),s(u.user.trim()),w({title:`Saved`,description:`IMAP account ${u.user.trim()} saved; sync runs in the background`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to save IMAP account`,variant:`destructive`})}finally{x(!1)}},re=async()=>{if(!(!E||!window.confirm(`Delete IMAP account ${E.address} and all its folders?`))){C(`delete:${E.address}`);try{await zr(e,`imap`,E.address),await O(),N(),w({title:`Deleted`,description:`IMAP account ${E.address} deleted`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to delete account`,variant:`destructive`})}finally{C(null)}}},ie=async(t,n)=>{C(`${t}:${n}`);try{t===`test`?await ra(e,`imap`,n):await _a(e,`imap`,n),await O(),w({title:`Success`,description:t===`sync`?`${n} sync started (runs in the background)`:`${n} test completed`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to ${t}`,variant:`destructive`})}finally{C(null)}},L=async(t,n)=>{C(`folder-sync:${t}:${n}`);try{await Oa(e,`imap`,t,n),await O(),w({title:`Synced`,description:`${t} · ${n}`})}catch(e){w({title:`Error`,description:e instanceof Error?e.message:`Failed to sync folder`,variant:`destructive`})}finally{C(null)}},R=(0,Z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-host`,children:`Host`}),(0,Z.jsx)(q,{id:`imap-host`,value:u.host,disabled:!!E,onChange:e=>I(`host`,e.target.value),placeholder:`imap.example.com`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-user`,children:`User (account)`}),(0,Z.jsx)(q,{id:`imap-user`,value:u.user,disabled:!!E,onChange:e=>I(`user`,e.target.value),placeholder:`me@example.com`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-password`,children:`Password`}),(0,Z.jsx)(q,{id:`imap-password`,type:`password`,value:u.password,onChange:e=>I(`password`,e.target.value),placeholder:E?`Leave blank to keep current password`:`Password`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-port`,children:`Port`}),(0,Z.jsx)(q,{id:`imap-port`,type:`number`,value:String(u.port),onChange:e=>I(`port`,Number(e.target.value||993))})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(Eu,{children:`Folders to sync`}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>void M(E,u),disabled:v||!E&&(!u.host.trim()||!u.user.trim()||!u.password),children:[v?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(ut,{className:`h-3 w-3`}),` Discover folders`]})]}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto rounded-md border p-2`,children:te.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:v?`Discovering folders…`:E?`No folders found on the server.`:`Fill in host, user and password, then discover the account’s folders. INBOX is synced by default.`}):(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:te.map(e=>{let t=e.path.split(e.delimiter||`/`).length-1,n=f.some(t=>t.path===e.path);return(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 rounded px-2 py-1 text-xs hover:bg-accent/50`,style:{paddingLeft:`${8+t*14}px`},children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:m.includes(e.path),onChange:()=>ee(e.path)}),(0,Z.jsx)(`span`,{className:`font-mono truncate`,children:e.path}),!n&&f.length>0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`(subscribed, not on server)`})]},e.path)})})}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[m.length,` folder`,m.length===1?``:`s`,` selected; each synced as its own container. Unchecking a synced folder removes it on Save.`]})]}),(0,Z.jsxs)(`fieldset`,{className:`rounded border p-3 space-y-3 sm:col-span-2`,children:[(0,Z.jsx)(`legend`,{className:`px-1 text-sm font-medium`,children:`Outgoing email (SMTP)`}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:!E||!u.smtp.enabled||b,onClick:()=>a(E.address),children:`Send test email`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Save your SMTP settings before testing. The test uses the saved account.`}),i&&(0,Z.jsx)(ym,{workspaceId:e,initialAccount:{driver:`imap`,address:i},testEmail:!0,onClose:()=>a(null)}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.enabled,onChange:e=>I(`smtp`,{...u.smtp,enabled:e.target.checked})}),`Allow sending from Canvas`]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[[`host`,`user`,`password`,`from`,`sentFolder`].map(e=>(0,Z.jsxs)(`label`,{className:`text-xs`,children:[{host:`SMTP host`,user:`SMTP username`,password:`SMTP password (blank keeps current)`,from:`From address`,sentFolder:`Sent folder`}[e],(0,Z.jsx)(q,{type:e===`password`?`password`:`text`,value:u.smtp[e],autoComplete:`off`,onChange:t=>I(`smtp`,{...u.smtp,[e]:t.target.value})})]},e)),(0,Z.jsxs)(`label`,{className:`text-xs`,children:[`Port`,(0,Z.jsx)(q,{type:`number`,min:1,max:65535,value:u.smtp.port,onChange:e=>I(`smtp`,{...u.smtp,port:Number(e.target.value)})})]})]}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.secure,onChange:e=>I(`smtp`,{...u.smtp,secure:e.target.checked})}),`Implicit TLS (usually port 465; otherwise STARTTLS is required)`]}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.appendSent,onChange:e=>I(`smtp`,{...u.smtp,appendSent:e.target.checked})}),`Save a copy in the IMAP Sent folder (leave off if your provider does this automatically)`]}),(0,Z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.smtp.allowAgentSend,onChange:e=>I(`smtp`,{...u.smtp,allowAgentSend:e.target.checked})}),`Allow agents with workspace write access to send`]})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-lookback`,children:`Initial sync lookback (days)`}),(0,Z.jsx)(q,{id:`imap-lookback`,type:`number`,min:`0`,value:String(u.initialSyncDays),onChange:e=>I(`initialSyncDays`,Number(e.target.value||0))}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`First sync only (lastUid 0). Set 0 to import the whole mailbox.`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Z.jsx)(Eu,{htmlFor:`imap-poll`,children:`Poll interval (ms)`}),(0,Z.jsx)(q,{id:`imap-poll`,type:`number`,value:String(u.pollInterval),onChange:e=>I(`pollInterval`,Number(e.target.value||6e4))})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-xs`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.tls,onChange:e=>I(`tls`,e.target.checked)}),` TLS`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u.allowSelfSigned,onChange:e=>I(`allowSelfSigned`,e.target.checked)}),` Allow self-signed`]})]})]});return(0,Z.jsxs)(`div`,{className:`space-y-3 border-t pt-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium`,children:`IMAP Accounts`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Each account mirrors under /imap/<account> in the backends tree; its folders are synced as containers. Click an account to edit its settings.`})]}),!t&&(0,Z.jsx)(`p`,{className:`rounded-md border bg-muted/40 p-2 text-xs text-muted-foreground`,children:`Enable the IMAP service before polling starts. Accounts can still be configured while it is off.`}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,onClick:c?N:F,children:[(0,Z.jsx)(Cn,{className:`h-3 w-3`}),` `,c?`Cancel`:`New Account`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`ghost`,onClick:O,disabled:g,children:[g?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Te,{className:`h-3 w-3`}),` Refresh`]})]}),(0,Z.jsx)(`div`,{className:`rounded-md border`,children:(0,Z.jsx)(`div`,{className:`max-h-[32rem] overflow-y-auto p-2 space-y-1`,children:T.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No IMAP accounts configured.`}):T.map(t=>{let n=o===t.address;return(0,Z.jsxs)(`div`,{className:`rounded px-2 py-2 text-xs transition-colors ${n?`bg-accent/40`:`hover:bg-accent/50`}`,children:[(0,Z.jsxs)(`button`,{onClick:()=>P(t),className:`w-full text-left`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 font-medium`,children:[n?(0,Z.jsx)(Ge,{className:`h-3 w-3 shrink-0`}):(0,Z.jsx)(Ye,{className:`h-3 w-3 shrink-0`}),t.address]}),(0,Z.jsx)(`span`,{className:`shrink-0 ${t.status===`error`?`text-destructive`:`text-muted-foreground`}`,children:t.status})]}),(0,Z.jsxs)(`div`,{className:`pl-[18px] text-muted-foreground`,children:[String(t.config?.host||``),` · `,(t.containers||[]).length,` folder(s)`]}),t.lastError&&(0,Z.jsxs)(`div`,{className:`pl-[18px] text-destructive`,children:[`error: `,t.lastError]})]}),n&&(0,Z.jsxs)(`div`,{className:`mt-2 space-y-3 border-t pt-2`,children:[(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:(t.containers||[]).map(n=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono truncate`,children:n.name}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Z.jsx)(`button`,{title:`Sync folder`,className:`p-1 hover:bg-accent rounded`,onClick:()=>L(t.address,n.name),disabled:!!S,children:S===`folder-sync:${t.address}:${n.name}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Te,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{title:`Remove folder`,className:`p-1 hover:bg-destructive/10 text-destructive rounded`,onClick:()=>Wr(e,`imap`,t.address,n.name).then(O).catch(e=>w({title:`Error`,description:e instanceof Error?e.message:`Failed to remove folder`,variant:`destructive`})),disabled:!!S,children:(0,Z.jsx)(lt,{className:`h-3 w-3`})})]})]},n.name))}),R,(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(J,{size:`sm`,onClick:ne,disabled:b,children:[b?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(k,{className:`h-3 w-3`}),` Save`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,disabled:!!S,onClick:()=>ie(`test`,t.address),children:[S===`test:${t.address}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Cn,{className:`h-3 w-3`}),` Test`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`outline`,disabled:!!S,onClick:()=>ie(`sync`,t.address),children:[S===`sync:${t.address}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Te,{className:`h-3 w-3`}),` Sync all`]}),(0,Z.jsxs)(J,{size:`sm`,variant:`destructive`,disabled:!!S,onClick:re,children:[S===`delete:${t.address}`?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(lt,{className:`h-3 w-3`}),` Delete`]})]})]})]},t.address)})})}),c&&(0,Z.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,Z.jsx)(`h5`,{className:`text-xs font-medium`,children:`New IMAP account`}),R,(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(J,{size:`sm`,onClick:ne,disabled:b,children:[b?(0,Z.jsx)(Mt,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(k,{className:`h-3 w-3`}),` Save`]}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,onClick:N,children:`Cancel`})]})]})]})}function S1({workspaceId:e}){let[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(!0),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)([`read`]),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(!0),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(new Set),[y,b]=(0,X.useState)(``),[x,S]=(0,X.useState)(!1),{showToast:C}=po(),[w,T]=(0,X.useState)(e);e!==w&&(T(e),i(!0));let E=(0,X.useCallback)(()=>Y.get(`/workspaces/${e}/tokens`).then(e=>{n((e||[]).map(e=>({...e,hash:e.hash||e.tokenHash||``})).filter(e=>e.hash))}).catch(()=>{C({title:`Error`,description:`Failed to load workspace tokens`,variant:`destructive`})}).finally(()=>{i(!1)}),[e,C]);(0,X.useEffect)(()=>{E()},[E]);let D=async()=>{if(!s.trim()){C({title:`Error`,description:`Token description is required`,variant:`destructive`});return}try{o(!0);let t=null;if(!p&&d){let e=new Date(d);e.setHours(23,59,59,999),t=e.toISOString()}let n={description:s,permissions:l,expiresAt:t},r=await Y.post(`/workspaces/${e}/tokens`,n);r&&r.token&&b(r.token),c(``),u([`read`]),f(``),m(!0),g(!1),i(!0),await E(),C({title:`Success`,description:`Workspace sharing token created successfully`,variant:`default`})}catch{C({title:`Error`,description:`Failed to create token`,variant:`destructive`})}finally{o(!1)}},O=async t=>{try{await Y.delete(`/workspaces/${e}/tokens/${t}`),C({title:`Success`,description:`Token revoked successfully`}),i(!0),await E()}catch{C({title:`Error`,description:`Failed to revoke token`,variant:`destructive`})}},k=e=>{let t=new Set(_);t.has(e)?t.delete(e):t.add(e),v(t)},A=e=>_.has(e)?e:`${e.substring(0,8)}...${e.substring(e.length-8)}`,j=async e=>{try{await navigator.clipboard.writeText(e),C({title:`Copied`,description:`Token hash copied to clipboard`})}catch{C({title:`Error`,description:`Failed to copy to clipboard`,variant:`destructive`})}};return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-lg font-medium`,children:`Workspace Sharing Tokens`}),(0,Z.jsxs)(J,{onClick:()=>g(!h),size:`sm`,variant:`outline`,children:[(0,Z.jsx)(H,{className:`mr-2 h-4 w-4`}),`Create Token`]})]}),h&&(0,Z.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 bg-muted/50`,children:[(0,Z.jsx)(q,{placeholder:`Token description (e.g., 'John's laptop')`,value:s,onChange:e=>c(e.target.value)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-sm font-medium mb-2 block`,children:`Permissions`}),(0,Z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:[`read`,`write`,`admin`].map(e=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:l.includes(e),onChange:t=>{t.target.checked?u([...l,e]):u(l.filter(t=>t!==e))}}),(0,Z.jsx)(`span`,{className:`text-sm`,children:e})]},e))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-sm font-medium mb-2 block`,children:`Token Expiry`}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>{m(e.target.checked),e.target.checked&&f(``)}}),(0,Z.jsx)(`span`,{className:`text-sm`,children:`Never expires`})]}),!p&&(0,Z.jsx)(q,{type:`date`,placeholder:`Expiry date`,value:d,onChange:e=>f(e.target.value),min:new Date().toISOString().split(`T`)[0]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(J,{onClick:D,disabled:a,children:`Create Token`}),(0,Z.jsx)(J,{variant:`outline`,onClick:()=>g(!1),children:`Cancel`})]})]}),y&&(0,Z.jsxs)(`div`,{className:`p-4 border rounded-md bg-muted/50`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-center mb-2`,children:[(0,Z.jsx)(`h3`,{className:`font-semibold`,children:`Your New Workspace Sharing Token`}),(0,Z.jsx)(J,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(y),S(!0),C({title:`Success`,description:`Token copied to clipboard`}),setTimeout(()=>S(!1),2e3)}catch{C({title:`Error`,description:`Failed to copy token to clipboard`,variant:`destructive`})}},children:x?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($e,{className:`mr-2 h-4 w-4`}),`Copied`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ve,{className:`mr-2 h-4 w-4`}),`Copy`]})})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mb-2`,children:`Make sure to copy your workspace sharing token now. You won't be able to see it again!`}),(0,Z.jsx)(`div`,{className:`p-2 bg-background border rounded font-mono text-sm break-all outline-none focus:ring-2 focus:ring-ring`,children:y}),(0,Z.jsx)(J,{variant:`outline`,size:`sm`,className:`mt-2`,onClick:()=>b(``),children:`Dismiss`})]}),(0,Z.jsx)(C1,{workspaceId:e}),r?(0,Z.jsxs)(`div`,{className:`text-center py-4`,children:[(0,Z.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-b-2 border-primary mx-auto touch-target`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2`,children:`Loading tokens...`})]}):t.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(`p`,{children:`No sharing tokens created yet.`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Create a token to share this workspace with others.`})]}):(0,Z.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,Z.jsxs)(`div`,{className:`border rounded-lg p-3 flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:e.description}),(0,Z.jsx)(`span`,{className:`text-xs bg-muted px-2 py-1 rounded`,children:e.permissions.join(`, `)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:A(e.hash)}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>k(e.hash),children:_.has(e.hash)?(0,Z.jsx)(kn,{className:`h-3 w-3`}):(0,Z.jsx)(Vt,{className:`h-3 w-3`})}),(0,Z.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>j(e.hash),children:(0,Z.jsx)(Ve,{className:`h-3 w-3`})})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Created: `,new Date(e.createdAt).toLocaleDateString(),e.expiresAt?(0,Z.jsxs)(`span`,{children:[` • Expires: `,new Date(e.expiresAt).toLocaleDateString()]}):(0,Z.jsx)(`span`,{children:` • Never expires`})]})]}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>O(e.hash),className:`text-destructive hover:text-destructive`,children:(0,Z.jsx)(lt,{className:`h-4 w-4`})})]},e.hash))})]})}function C1({workspaceId:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)([`read`]),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)([]),u=(0,X.useCallback)(()=>Y.get(`/workspaces/${e}/shares`).then(e=>l(Array.isArray(e)?e:e?.emailShares||[])).catch(()=>{}),[e]);(0,X.useEffect)(()=>{u()},[u]);let d=async()=>{if(n.trim())try{s(!0),await Y.post(`/workspaces/${e}/shares`,{userEmail:n.trim(),permissions:i}),r(``),a([`read`]),await u(),t({title:`Success`,description:`Access granted`})}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to grant access`,variant:`destructive`})}finally{s(!1)}},f=async n=>{try{await Y.delete(`/workspaces/${e}/shares/${encodeURIComponent(n)}`),await u(),t({title:`Success`,description:`Access revoked`})}catch(e){t({title:`Error`,description:e instanceof Error?e.message:`Failed to revoke`,variant:`destructive`})}};return(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`h4`,{className:`font-medium`,children:`Email-based Shares`}),(0,Z.jsxs)(`div`,{className:`flex gap-2 flex-wrap items-center`,children:[(0,Z.jsx)(q,{placeholder:`user@local.server`,value:n,onChange:e=>r(e.target.value),className:`max-w-xs`}),(0,Z.jsx)(`div`,{className:`flex gap-2`,children:[`read`,`write`,`admin`].map(e=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:i.includes(e),onChange:t=>{t.target.checked?a([...i,e]):a(i.filter(t=>t!==e))}}),e]},e))}),(0,Z.jsx)(J,{size:`sm`,onClick:d,disabled:o,children:`Add`})]}),c.length>0&&(0,Z.jsx)(`div`,{className:`space-y-2`,children:c.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border rounded p-2`,children:[(0,Z.jsxs)(`div`,{className:`text-sm`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:e.userEmail}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e.permissions.join(`, `),e.grantedAt?` • ${new Date(e.grantedAt).toLocaleDateString()}`:``]})]}),(0,Z.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>f(e.userEmail),className:`text-destructive hover:text-destructive`,children:`Revoke`})]},e.userEmail))})]})}var w1=[{value:`read`,label:`Read`,hint:`Browse and search`},{value:`write`,label:`Read & write`,hint:`Add, edit and organise documents`},{value:`admin`,label:`Admin`,hint:`Everything except sharing and deleting`}],T1=e=>e.includes(`admin`)?`admin`:e.includes(`write`)?`write`:`read`;function E1({workspaceId:e}){let{showToast:t}=po(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(!0),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(`user`),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(`read`),[m,h]=(0,X.useState)(e);e!==m&&(h(e),a(!0));let g=(0,X.useCallback)(()=>Ri(e).then(r).catch(()=>r(null)).finally(()=>a(!1)),[e]);(0,X.useEffect)(()=>{g()},[g]);let _=n?.isOwner===!0,v=n?.members??[],y=async n=>{n.preventDefault();let r=u.trim();if(r){s(`grant`);try{let n=await ia(e,c===`user`?{email:r}:{group:r},[f]);d(``),await g();let i=c===`user`?r:`group ${r}`;t({title:`Shared`,description:n.type===`user`&&n.userExists===!1?`${i} has no account here yet — the share applies as soon as they sign in.`:`Access granted to ${i}.`})}catch(e){t({title:`Could not share`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{s(null)}}},b=async(n,r)=>{let i=`${n.type}:${n.principal}`;s(i);try{await Ji(e,n.type,n.principal,[r]),await g()}catch(e){t({title:`Could not update`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{s(null)}},x=async n=>{let r=`${n.type}:${n.principal}`;s(r);try{await Ea(e,n.type,n.principal),await g(),t({title:`Access revoked`,description:`${n.principal} no longer has access.`})}catch(e){t({title:`Could not revoke`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{s(null)}};return n&&n.shareable===!1?(0,Z.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Your universe workspace is private and cannot be shared.`}):(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_?`People and groups who can open this workspace.`:`You are a member of this workspace; only its owner can change the list.`}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{a(!0),g()},disabled:i,children:[(0,Z.jsx)(Te,{className:K(`mr-2 h-3.5 w-3.5`,i&&`animate-spin`)}),`Refresh`]})]}),i?(0,Z.jsx)(`div`,{className:`rounded-md border p-4 text-sm text-muted-foreground`,children:`Loading members…`}):v.length===0?(0,Z.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Not shared with anyone.`}):v.map(e=>{let t=`${e.type}:${e.principal}`,n=T1(e.permissions);return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[e.type===`group`?(0,Z.jsx)(Ue,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}):(0,Z.jsx)(Ze,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-medium`,title:e.principal,children:e.principal}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e.type===`group`?`Group`:`User`,e.description?` · ${e.description}`:``,e.grantedAt?` · since ${new Date(e.grantedAt).toLocaleDateString()}`:``]}),e.type===`user`&&e.userExists===!1&&(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-[11px] text-warning`,children:[(0,Z.jsx)(B,{className:`h-3 w-3`}),` No account yet — applies at first sign-in`]})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[_?(0,Z.jsx)(`select`,{value:n,disabled:o===t,onChange:t=>b(e,t.target.value),className:`rounded-md border border-input bg-background px-2 py-1 text-xs focus:outline-none focus:ring-2 focus:ring-ring`,title:`Access level`,children:w1.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))}):(0,Z.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs`,children:w1.find(e=>e.value===n)?.label}),_&&(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,className:`text-destructive hover:text-destructive`,disabled:o===t,onClick:()=>x(e),title:`Revoke access`,children:(0,Z.jsx)(he,{className:`h-3.5 w-3.5`})})]})]},t)})]}),_&&(0,Z.jsxs)(`form`,{onSubmit:y,className:`space-y-3 rounded-md border p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium`,children:[`Share with`,(0,Z.jsx)(`div`,{className:`inline-flex overflow-hidden rounded-md border`,children:[`user`,`group`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>l(e),className:K(`px-3 py-1 text-xs`,c===e?`bg-primary text-primary-foreground`:`bg-background text-muted-foreground hover:bg-muted`),children:e===`user`?`a person`:`a group`},e))})]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[1fr_auto]`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(q,{type:c===`user`?`email`:`text`,value:u,onChange:e=>d(e.target.value),placeholder:c===`user`?`colleague@corp.tld`:`team-a or cn=team-a,ou=groups,dc=corp,dc=tld`,autoComplete:`off`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:c===`user`?`The share is keyed by e-mail: it works even before the person signs in for the first time.`:`Directory group (LDAP/AD memberOf — full DN or just the CN) or a group an admin assigned to local accounts.`})]}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`,title:w1.find(e=>e.value===f)?.hint,children:w1.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})})]}),(0,Z.jsx)(J,{type:`submit`,size:`sm`,disabled:o===`grant`||!u.trim(),children:o===`grant`?`Sharing…`:`Share workspace`})]})]})}function D1({workspaceId:e,workspaceName:t,isActive:n,onChanged:r}){let{showToast:i}=po(),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(!0),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(``),C=(0,X.useRef)(null),w=(0,X.useCallback)(async()=>{try{o(n?await Mi(e):[])}catch{o([])}finally{c(!1)}},[e,n]);(0,X.useEffect)(()=>{w()},[w]);let T=async()=>{if(!(n&&!window.confirm(`'${t}' is running. It has to be stopped to be exported — its index is only consistent on disk once it has flushed.\n\nStop it and export now?`))){u(!0);try{let t=await Ur(e,{stop:!0});f(t.stoppedWorkspace),i({title:`Workspace exported`,description:`${t.name} — ${bi(t.size)}`}),await w(),t.stoppedWorkspace&&r?.()}catch(e){i({title:`Export failed`,description:e instanceof Error?e.message:`Failed to export workspace`,variant:`destructive`})}finally{u(!1)}}},E=async()=>{m(!0);try{await ui(e),f(!1),i({title:`Workspace started`,description:`'${t}' is running again.`}),r?.()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to start workspace`,variant:`destructive`})}finally{m(!1)}},D=async e=>{g(e.name);try{await ei(e.name)}catch(e){i({title:`Download failed`,description:e instanceof Error?e.message:`Failed to download archive`,variant:`destructive`})}finally{g(null)}},O=async e=>{if(window.confirm(`Delete ${e.name}? The archive is removed from the server; any copy you already downloaded is untouched.`)){g(e.name);try{await gi(e.name),await w()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to delete archive`,variant:`destructive`})}finally{g(null)}}},k=async e=>{b(`uploading`),v(0),S(``);try{let t=await xa(e,e=>{v(Math.round(e*100)),e>=1&&b(`server`)},e=>S(ga[e.phase]||e.phase));i({title:`Workspace imported`,description:`'${t.label||t.name}' was extracted, validated and loaded.`}),r?.(),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){i({title:`Import failed`,description:e instanceof Error?e.message:`Failed to import workspace`,variant:`destructive`})}finally{b(null),v(null),S(``),C.current&&(C.current.value=``)}},A=y!==null;return(0,Z.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(et,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Export & Import`})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Export packs this workspace into a single compressed archive you can download and move elsewhere. The workspace is stopped first — an export of a running workspace would capture a half-written index.`}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:l||A,onClick:T,children:[(0,Z.jsx)(et,{className:`mr-2 h-3.5 w-3.5 ${l?`animate-pulse`:``}`}),l?`Exporting…`:`Export Workspace`]}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:s||l,onClick:()=>void w(),children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${s?`animate-spin`:``}`}),`Refresh`]}),d&&(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:p,onClick:E,children:p?`Starting…`:`Start workspace again`})]}),(0,Z.jsxs)(`div`,{className:`mt-4 border-t pt-3`,children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Archives`}),s?(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,Z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`No exports yet.`}):(0,Z.jsx)(`ul`,{className:`mt-2 space-y-2`,children:a.map(e=>(0,Z.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-md border p-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs`,children:e.name}),(0,Z.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[bi(e.size),` · `,new Date(e.createdAt).toLocaleString()]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:h===e.name,onClick:()=>D(e),title:`Download (${bi(e.size)})`,children:(0,Z.jsx)(er,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:h===e.name,onClick:()=>O(e),className:`text-destructive hover:text-destructive`,title:`Delete archive`,children:(0,Z.jsx)(lt,{className:`h-3.5 w-3.5`})})]})]},e.name))})]}),(0,Z.jsxs)(`div`,{className:`mt-4 border-t pt-3`,children:[(0,Z.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Import`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Pick a workspace archive from your local drive. It is uploaded into your home, extracted into your Workspaces folder, validated and loaded as a new workspace.`}),(0,Z.jsx)(`input`,{ref:C,type:`file`,accept:`.tar.gz,.tgz,.tar.bz2,.tbz2,.tbz,application/gzip,application/x-bzip2`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&k(t)}}),(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3`,children:[(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:A||l,onClick:()=>C.current?.click(),children:[(0,Z.jsx)(re,{className:`mr-2 h-3.5 w-3.5`}),`Import from local drive…`]}),y===`uploading`&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Uploading… `,_,`%`]}),y===`server`&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:x||`Extracting, validating and loading…`})]})]})]})}var O1={"workspace:home":{title:`Workspace Home`,description:`User-managed roaming home folder, exported through WebDAV and watched for changes. Mirrored into the backends tree.`},"workspace:data":{title:`Workspace Data`,description:`Managed content-addressable blob store (deduped, checksum-keyed). Opaque by design: the tree is the navigation; not meant for direct edits or export.`},s3:{title:`S3`,description:`Remote object storage. Placeholder until Stored gets a real S3 driver.`},imap:{title:`IMAP`,description:`Mailbox data source; ingested mail lands in the backends tree.`}},k1=[{id:`git`,title:`Git`,description:`Git-backed dotfile access.`},{id:`webdav`,title:`WebDAV`,description:`Mountable access to the workspace home backend.`},{id:`imapSync`,title:`IMAP Sync Worker`,description:`Background mailbox polling and ingestion.`}];function A1({checked:e,disabled:t,onClick:n}){return(0,Z.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:t,onClick:n,className:`relative inline-flex h-5 w-9 shrink-0 rounded-full border-2 border-transparent transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${e?`bg-primary`:`bg-muted-foreground/30`}`,children:(0,Z.jsx)(`span`,{className:`pointer-events-none inline-block h-4 w-4 rounded-full bg-background shadow transition-transform ${e?`translate-x-4`:`translate-x-0`}`})})}function j1({workspaceId:e,onAdded:t}){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),{showToast:m}=po(),h=()=>{a(``),s(``),l(!1),d(!1)};return n?(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),!(!i.trim()||!o.trim())){p(!0);try{await na(e,`file`,{name:i.trim(),path:o.trim(),watch:c,readOnly:u}),m({title:`Added`,description:`${i.trim()} mounted; initial scan running in the background`}),h(),r(!1),await t()}catch(e){m({title:`Error`,description:e instanceof Error?e.message:`Failed to add folder backend`,variant:`destructive`})}finally{p(!1)}}},className:`w-full space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ut,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Add local folder`})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Index a folder on the server host as a data source. Files stay in place; the index records them as device-scoped locations, so they remain addressable if the workspace moves to another server.`}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Name`}),(0,Z.jsx)(q,{value:i,onChange:e=>a(e.target.value),placeholder:`Financial Reports`,required:!0})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Absolute path on server`}),(0,Z.jsx)(q,{value:o,onChange:e=>s(e.target.value),placeholder:`/mnt/data/reports`,required:!0,className:`font-mono`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-6 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[`watch`,(0,Z.jsx)(A1,{checked:c,onClick:()=>l(e=>!e)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,title:`Never delete bytes in this folder. Destroy degrades to a reference drop. Recommended for folders managed outside Canvas.`,children:[`read-only`,(0,Z.jsx)(A1,{checked:u,onClick:()=>d(e=>!e)})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(J,{type:`submit`,size:`sm`,disabled:f||!i.trim()||!o.trim(),children:f?`Adding…`:`Add folder`}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,disabled:f,onClick:()=>{h(),r(!1)},children:`Cancel`})]})]}):(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(!0),children:[(0,Z.jsx)(ut,{className:`mr-2 h-3.5 w-3.5`}),`Add local folder`]})}function M1({workspaceId:e,onAdded:t}){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)({name:``,clientId:``,clientSecret:``,refreshToken:``,folderId:``}),[o,s]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),{showToast:p}=po(),m=e=>t=>a(n=>({...n,[e]:t.target.value})),h=()=>{a({name:``,clientId:``,clientSecret:``,refreshToken:``,folderId:``}),s(!1),u(!1)},g=i.name.trim()&&i.clientId.trim()&&i.clientSecret.trim()&&i.refreshToken.trim();return n?(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),g){f(!0);try{await na(e,`gdrive`,{name:i.name.trim(),clientId:i.clientId.trim(),clientSecret:i.clientSecret.trim(),refreshToken:i.refreshToken.trim(),folderId:i.folderId.trim()||`root`,watch:o,readOnly:l}),p({title:`Added`,description:`${i.name.trim()} connected; initial scan running in the background`}),h(),r(!1),await t()}catch(e){p({title:`Error`,description:e instanceof Error?e.message:`Failed to add Google Drive backend`,variant:`destructive`})}finally{f(!1)}}},className:`w-full space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(c,{icon:`mdi:google-drive`,width:16,height:16,className:`text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Add Google Drive`})]}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Index a Drive folder (or the whole My Drive) as a remote data source. Files are hashed from Drive metadata, uploads are queued through the workspace cache. Needs an OAuth client with the `,(0,Z.jsx)(`code`,{children:`drive`}),` scope and an offline-access refresh token — the same kind of credentials as the Google Calendar connector.`]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Name`}),(0,Z.jsx)(q,{value:i.name,onChange:m(`name`),placeholder:`Work Drive`,required:!0})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Folder id (empty = My Drive root)`}),(0,Z.jsx)(q,{value:i.folderId,onChange:m(`folderId`),placeholder:`1AbC…`,className:`font-mono`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`OAuth client id`}),(0,Z.jsx)(q,{value:i.clientId,onChange:m(`clientId`),required:!0,className:`font-mono`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`OAuth client secret`}),(0,Z.jsx)(q,{type:`password`,value:i.clientSecret,onChange:m(`clientSecret`),required:!0,className:`font-mono`,autoComplete:`off`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 sm:col-span-2`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium`,children:`Refresh token`}),(0,Z.jsx)(q,{type:`password`,value:i.refreshToken,onChange:m(`refreshToken`),required:!0,className:`font-mono`,autoComplete:`off`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-6 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,title:`Poll the Drive changes feed (every 60s) so edits made in Drive show up without a manual re-sync.`,children:[`watch`,(0,Z.jsx)(A1,{checked:o,onClick:()=>s(e=>!e)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1.5`,title:`Never delete files in this Drive. Destroy degrades to a reference drop.`,children:[`read-only`,(0,Z.jsx)(A1,{checked:l,onClick:()=>u(e=>!e)})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(J,{type:`submit`,size:`sm`,disabled:d||!g,children:d?`Checking…`:`Add Drive`}),(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,disabled:d,onClick:()=>{h(),r(!1)},children:`Cancel`})]})]}):(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(!0),children:[(0,Z.jsx)(c,{icon:`mdi:google-drive`,width:14,height:14,className:`mr-2`}),`Add Google Drive`]})}function N1({workspaceId:e,backend:t}){let[n,r]=(0,X.useState)(t.usage??null),[i,a]=(0,X.useState)(!1),{showToast:o}=po();return(0,Z.jsxs)(`button`,{type:`button`,onClick:async()=>{a(!0);try{r(await Vr(e,t.driver,t.address))}catch(e){o({title:`Error`,description:e instanceof Error?e.message:`Failed to compute size`,variant:`destructive`})}finally{a(!1)}},disabled:i,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-[11px] text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50`,title:n?`Computed ${new Date(n.computedAt).toLocaleString()}; click to refresh`:`Compute on-disk size (walks the backend folder; may take a while)`,children:[(0,Z.jsx)(hr,{className:`h-3 w-3 ${i?`animate-pulse`:``}`}),i?`Calculating…`:n?bi(n.bytes):`Size`]})}function P1({workspaceId:e}){let[t,n]=(0,X.useState)(!1),{showToast:r}=po();return(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:t,onClick:async()=>{n(!0);try{let{removed:t}=await qi(e);r({title:`Thumbnail cache cleared`,description:`${t} cached thumbnail(s) removed`})}catch(e){r({title:`Error`,description:e instanceof Error?e.message:`Failed to clear thumbnail cache`,variant:`destructive`})}finally{n(!1)}},title:`Remove all cached thumbnails; they regenerate on demand`,children:[(0,Z.jsx)(lt,{className:`mr-2 h-3.5 w-3.5 ${t?`animate-pulse`:``}`}),t?`Clearing…`:`Clear thumbnails`]})}function F1({workspaceId:e}){let[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(!1),{showToast:a}=po();return(0,Z.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(hr,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Disk usage`})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Total on-disk size of this workspace (index, blobs, home, cache): what an export or sync would move. Computed on demand; may take a while on large workspaces.`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3`,children:[t&&(0,Z.jsx)(`span`,{className:`text-sm font-semibold`,children:bi(t.bytes)}),(0,Z.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:r,onClick:async()=>{i(!0);try{n(await li(e))}catch(e){a({title:`Error`,description:e instanceof Error?e.message:`Failed to compute workspace size`,variant:`destructive`})}finally{i(!1)}},children:[(0,Z.jsx)(Te,{className:`mr-2 h-3.5 w-3.5 ${r?`animate-spin`:``}`}),r?`Calculating…`:t?`Recalculate`:`Calculate size`]})]})]}),t&&(0,Z.jsx)(`div`,{className:`mt-3 grid grid-cols-2 gap-x-6 gap-y-1 border-t pt-3 sm:grid-cols-3`,children:Object.entries(t.breakdown).sort(([,e],[,t])=>t-e).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-xs`,children:[(0,Z.jsx)(`span`,{className:`truncate font-mono text-muted-foreground`,children:e}),(0,Z.jsx)(`span`,{children:bi(t)})]},e))})]})}function I1({backend:e,busy:t,onSave:n}){let r=e.config||{},i=Array.isArray(r.exclude)?r.exclude:[],a=Array.isArray(r.effectiveExclusions)?r.effectiveExclusions:[],o=Math.max(a.length-i.length,0),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(i.join(`
|
|
79
79
|
`)),[d,f]=(0,X.useState)(!1),p=i.join(`
|
|
80
80
|
`),[m,h]=(0,X.useState)(p);return m!==p&&(h(p),u(p)),(0,Z.jsxs)(`div`,{className:`mt-3 border-t pt-3`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`text-[11px] font-medium text-muted-foreground hover:text-foreground`,onClick:()=>c(!s),children:[`Sync exclusions `,i.length>0?`(${i.length} custom`:`(defaults only`,o>0?`, ${o} default)`:`)`,` `,s?`▾`:`▸`]}),s&&(0,Z.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,Z.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`One glob pattern per line, e.g. `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`**/node_modules/**`}),` or `,(0,Z.jsx)(`code`,{className:`font-mono`,children:`**/target/**`}),`. Defaults (dotfiles, node_modules, __pycache__, caches, …) always apply. Changes take effect immediately for the watcher; run Re-sync to also unlink already-mirrored entries.`]}),(0,Z.jsx)(`textarea`,{className:`w-full min-h-[80px] rounded-md border bg-background p-2 font-mono text-xs`,value:l,onChange:e=>u(e.target.value),placeholder:`**/node_modules/**
|
|
81
81
|
**/dist/**`,spellCheck:!1}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(J,{type:`button`,size:`sm`,disabled:t||l.split(`
|