@json-to-office/jto 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/client/assets/{HomePage-Dm2fRH6p.js → HomePage-CcmtpSuV.js} +3 -3
  3. package/dist/client/assets/{HomePage-Dm2fRH6p.js.map → HomePage-CcmtpSuV.js.map} +1 -1
  4. package/dist/client/assets/{JsonEditorPage-CeOvPs5I.js → JsonEditorPage-RDa8GWDd.js} +3 -3
  5. package/dist/client/assets/{JsonEditorPage-CeOvPs5I.js.map → JsonEditorPage-RDa8GWDd.js.map} +1 -1
  6. package/dist/client/assets/{MonacoPluginProvider-BDwUsxu4.js → MonacoPluginProvider-DM63WAJx.js} +3 -3
  7. package/dist/client/assets/{MonacoPluginProvider-BDwUsxu4.js.map → MonacoPluginProvider-DM63WAJx.js.map} +1 -1
  8. package/dist/client/assets/{button-DpH0SUBp.js → button-CyTe9rTl.js} +2 -2
  9. package/dist/client/assets/{button-DpH0SUBp.js.map → button-CyTe9rTl.js.map} +1 -1
  10. package/dist/client/assets/{editor-e3ONSdDx.js → editor-DCtGYNz2.js} +2 -2
  11. package/dist/client/assets/{editor-e3ONSdDx.js.map → editor-DCtGYNz2.js.map} +1 -1
  12. package/dist/client/assets/{editor-monaco-json-CFSP94ky.js → editor-monaco-json-CU9ciwPv.js} +2 -2
  13. package/dist/client/assets/{editor-monaco-json-CFSP94ky.js.map → editor-monaco-json-CU9ciwPv.js.map} +1 -1
  14. package/dist/client/assets/{index-D2uJMa4G.js → index-CHAIoQtG.js} +4 -4
  15. package/dist/client/assets/index-CHAIoQtG.js.map +1 -0
  16. package/dist/client/assets/{preview-_aGms4Sr.js → preview-oxnxMi4x.js} +2 -2
  17. package/dist/client/assets/{preview-_aGms4Sr.js.map → preview-oxnxMi4x.js.map} +1 -1
  18. package/dist/client/index.html +1 -1
  19. package/dist/client/templates/data-report-presentation.pptx.json +3160 -0
  20. package/dist/client/templates/management-plan.pptx.json +5923 -0
  21. package/dist/client/templates/media/management-plan/crop_s1.jpg +0 -0
  22. package/dist/client/templates/media/management-plan/crop_s10.jpg +0 -0
  23. package/dist/client/templates/media/management-plan/crop_s11.jpg +0 -0
  24. package/dist/client/templates/media/management-plan/crop_s12.jpg +0 -0
  25. package/dist/client/templates/media/management-plan/crop_s13.jpg +0 -0
  26. package/dist/client/templates/media/management-plan/crop_s14.jpg +0 -0
  27. package/dist/client/templates/media/management-plan/crop_s15.jpg +0 -0
  28. package/dist/client/templates/media/management-plan/crop_s16.jpg +0 -0
  29. package/dist/client/templates/media/management-plan/crop_s18a.jpg +0 -0
  30. package/dist/client/templates/media/management-plan/crop_s18b.jpg +0 -0
  31. package/dist/client/templates/media/management-plan/crop_s19.jpg +0 -0
  32. package/dist/client/templates/media/management-plan/crop_s3.jpg +0 -0
  33. package/dist/client/templates/media/management-plan/crop_s5.jpg +0 -0
  34. package/dist/client/templates/media/management-plan/crop_s9.jpg +0 -0
  35. package/dist/client/templates/media/management-plan/image2.jpg +0 -0
  36. package/dist/client/templates/media/minimalist-pitch-deck/image1.jpg +0 -0
  37. package/dist/client/templates/media/minimalist-pitch-deck/image3.png +0 -0
  38. package/dist/client/templates/media/modern-annual-report-2/hatch-1.86x2.03.png +0 -0
  39. package/dist/client/templates/media/modern-annual-report-2/hatch-1.88x2.13.png +0 -0
  40. package/dist/client/templates/media/modern-annual-report-2/hatch-2.19x2.61.png +0 -0
  41. package/dist/client/templates/media/modern-annual-report-2/hatch-2.22x2.88.png +0 -0
  42. package/dist/client/templates/media/modern-annual-report-2/hatch-2.57x2.91.png +0 -0
  43. package/dist/client/templates/media/modern-annual-report-2/hatch-2.78x3.03.png +0 -0
  44. package/dist/client/templates/media/modern-annual-report-2/hatch-3.53x4.22.png +0 -0
  45. package/dist/client/templates/media/modern-annual-report-2/hatch-3.8x5.41.png +0 -0
  46. package/dist/client/templates/media/modern-annual-report-2/hatch-4.46x6.42.png +0 -0
  47. package/dist/client/templates/media/modern-annual-report-2/image2.png +0 -0
  48. package/dist/client/templates/media/modern-annual-report-2/image4.png +0 -0
  49. package/dist/client/templates/media/modern-annual-report-2/image6.png +0 -0
  50. package/dist/client/templates/media/modern-annual-report-3/image1.gif +0 -0
  51. package/dist/client/templates/media/modern-annual-report-3/pct30-1308x1454-v2.png +0 -0
  52. package/dist/client/templates/media/modern-annual-report-3/pct30-1312x1574-v2.png +0 -0
  53. package/dist/client/templates/media/modern-annual-report-3/pct30-1618x1597-v2.png +0 -0
  54. package/dist/client/templates/media/modern-annual-report-3/pct30-1660x1818-v2.png +0 -0
  55. package/dist/client/templates/media/modern-annual-report-3/pct30-1817x2117-v2.png +0 -0
  56. package/dist/client/templates/media/modern-annual-report-3/pct30-1822x2099-v2.png +0 -0
  57. package/dist/client/templates/media/modern-annual-report-3/pct30-1874x2077-v2.png +0 -0
  58. package/dist/client/templates/media/modern-annual-report-3/pct30-2084x2506-v2.png +0 -0
  59. package/dist/client/templates/media/modern-annual-report-3/pct30-2544x3221-v2.png +0 -0
  60. package/dist/client/templates/media/modern-annual-report-3/pct30-2622x3017-v2.png +0 -0
  61. package/dist/client/templates/media/modern-annual-report-3/pct30-7054x10363-v2.png +0 -0
  62. package/dist/client/templates/media/modern-annual-report-3/pct30-7253x2778-v2.png +0 -0
  63. package/dist/client/templates/media/modern-annual-report-3/pct30-7256x6807-v2.png +0 -0
  64. package/dist/client/templates/media/standard-annual-report/image1.png +0 -0
  65. package/dist/client/templates/media/standard-annual-report/image10.png +0 -0
  66. package/dist/client/templates/media/standard-annual-report/image11.png +0 -0
  67. package/dist/client/templates/media/standard-annual-report/image12.png +0 -0
  68. package/dist/client/templates/media/standard-annual-report/image13.png +0 -0
  69. package/dist/client/templates/media/standard-annual-report/image14.png +0 -0
  70. package/dist/client/templates/media/standard-annual-report/image15.png +0 -0
  71. package/dist/client/templates/media/standard-annual-report/image16.png +0 -0
  72. package/dist/client/templates/media/standard-annual-report/image17.png +0 -0
  73. package/dist/client/templates/media/standard-annual-report/image18.png +0 -0
  74. package/dist/client/templates/media/standard-annual-report/image19.png +0 -0
  75. package/dist/client/templates/media/standard-annual-report/image2.png +0 -0
  76. package/dist/client/templates/media/standard-annual-report/image20.png +0 -0
  77. package/dist/client/templates/media/standard-annual-report/image21.png +0 -0
  78. package/dist/client/templates/media/standard-annual-report/image22.png +0 -0
  79. package/dist/client/templates/media/standard-annual-report/image23.png +0 -0
  80. package/dist/client/templates/media/standard-annual-report/image24.png +0 -0
  81. package/dist/client/templates/media/standard-annual-report/image25.png +0 -0
  82. package/dist/client/templates/media/standard-annual-report/image3.png +0 -0
  83. package/dist/client/templates/media/standard-annual-report/image4.png +0 -0
  84. package/dist/client/templates/media/standard-annual-report/image5.png +0 -0
  85. package/dist/client/templates/media/standard-annual-report/image6.png +0 -0
  86. package/dist/client/templates/media/standard-annual-report/image7.png +0 -0
  87. package/dist/client/templates/media/standard-annual-report/image8.png +0 -0
  88. package/dist/client/templates/media/standard-annual-report/image9.png +0 -0
  89. package/dist/client/templates/media/tech-report/fonts/DMSans-Bold.ttf +0 -0
  90. package/dist/client/templates/media/tech-report/fonts/DMSans-Light.ttf +0 -0
  91. package/dist/client/templates/media/tech-report/fonts/DMSans-Medium.ttf +0 -0
  92. package/dist/client/templates/media/tech-report/fonts/DMSans-Regular.ttf +0 -0
  93. package/dist/client/templates/minimalist-pitch-deck.pptx.json +3837 -0
  94. package/dist/client/templates/modern-annual-report-1.docx.json +10970 -0
  95. package/dist/client/templates/modern-annual-report-2.docx.json +15368 -0
  96. package/dist/client/templates/modern-annual-report-3.docx.json +13277 -0
  97. package/dist/client/templates/standard-annual-report.docx.json +7574 -0
  98. package/dist/client/templates/tech-report.docx.json +6503 -0
  99. package/package.json +3 -3
  100. package/dist/client/assets/index-D2uJMa4G.js.map +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-e3ONSdDx.js","assets/react-vendor-CTFDOf2G.js","assets/editor-monaco-json-CFSP94ky.js","assets/index-D2uJMa4G.js","assets/query-vendor-Df8-oete.js","assets/radix-ui-Bq-7y_Sq.js","assets/ui-vendor-Nd4Lg2re.js","assets/monaco-editor-BcgxPCqT.js","assets/state-vendor-ByFYl9bq.js","assets/index-BdmImuIf.css","assets/MonacoPluginProvider-BDwUsxu4.js","assets/button-DpH0SUBp.js","assets/preview-_aGms4Sr.js"])))=>i.map(i=>d[i]);
2
- var um=Object.defineProperty;var cm=(e,t,n)=>t in e?um(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Po=(e,t,n)=>cm(e,typeof t!="symbol"?t+"":t,n);import{r as b,j as u,c as _e,R as lc,g as Za}from"./react-vendor-CTFDOf2G.js";import{b as uc,c as Ba,d as cc,e as rs,f as is,D as ss,O as as,g as dm,V as fm,h as dc,I as pm,i as hm,j as fc,k as mm,l as pc,m as gm,n as xm,G as ym,S as hc,o as mc,L as gc,p as xc,q as yc,r as dr,s as bm,t as vm,u as wm,v as bc,w as vc,x as wc,y as kc,z as Sc,B as _c,E as jc,F as Cc,H as Nc,J as km,K as Sm,M as _m,N as Ec,Q as Ic,U as Tc,W as zc,X as Ac,Y as Pc,Z as Oc,_ as Dc,$ as Rc,a0 as Mc,a1 as jm,a2 as $c,a3 as Cm,a4 as Nm,a5 as Fc,a6 as Em,a7 as Im,a8 as Tm,a9 as zm,aa as Am,ab as Pm,ac as Om,ad as Lc,ae as Zc,af as Bc}from"./radix-ui-Bq-7y_Sq.js";import{c as H,u as fr,S as en,A as Vc,T as fi,C as Dm,E as Rm,F as yt,a as Mm,b as $m,d as qe,e as Ge,f as Ke,g as Uc,_ as Jc,h as pi,i as Fm,j as Lm,k as Zm,l as xr,s as Es,m as Ci,W as Bm}from"./index-D2uJMa4G.js";import{X as fn,C as ti,a as pn,b as Vm,d as ni,G as Hc,F as Um,e as ri,f as Wc,P as Jm,g as Hm,h as qc,E as Gc,S as Wm,B as Oo,i as qm,j as Gm,k as Km,l as os,m as Ym,M as Xm,I as Kc,n as Xt,o as Qm,p as eg,q as Yc,r as tg,s as ng,t as rg,u as ig,R as sg,v as ag,T as Xc,w as og,x as lg,y as ug,z as Qc,A as Va,D as ed,H as cg,J as td,L as la,K as dg,N as fg,O as Do,Q as ua,U as pg}from"./ui-vendor-Nd4Lg2re.js";import{B as Ee}from"./button-DpH0SUBp.js";import{u as Oe,i as hg,a as ca,b as Qt,g as mg,c as Dt,T as nd,d as hi,S as gg,O as xg,e as yg,M as bg,D as vg}from"./MonacoPluginProvider-BDwUsxu4.js";import{u as rd,a as wg,d as kg,p as Sg,b as _g,e as jg}from"./state-vendor-ByFYl9bq.js";import{b as Cg}from"./query-vendor-Df8-oete.js";const It=uc,Ng=cc,Ro=Ba,id=b.forwardRef(({className:e,...t},n)=>u.jsx(as,{ref:n,className:H("fixed inset-0 z-50 bg-black/50",e),...t}));id.displayName=as.displayName;const St=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ng,{children:[u.jsx(id,{}),u.jsxs(rs,{ref:r,className:H("bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",e),...n,children:[t,u.jsxs(Ba,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 cursor-pointer rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none",children:[u.jsx(fn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));St.displayName=rs.displayName;const Ht=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ht.displayName="DialogHeader";const In=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});In.displayName="DialogFooter";const Wt=b.forwardRef(({className:e,...t},n)=>u.jsx(is,{ref:n,className:H("text-lg leading-none font-semibold tracking-tight",e),...t}));Wt.displayName=is.displayName;const hn=b.forwardRef(({className:e,...t},n)=>u.jsx(ss,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));hn.displayName=ss.displayName;const Fr=dm,Eg=ym,Lr=fm,rr=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(dc,{ref:r,className:H("border-input ring-offset-background placeholder:text-muted-foreground focus:ring-ring flex min-h-9 w-full min-w-0 items-center justify-between gap-2 rounded-sm border bg-background px-3 py-2 text-sm shadow-xs focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:min-w-0 [&>span]:whitespace-normal [&>span]:break-words text-left cursor-pointer",e),...n,children:[t,u.jsx(pm,{asChild:!0,children:u.jsx(ti,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));rr.displayName=dc.displayName;const sd=b.forwardRef(({className:e,...t},n)=>u.jsx(hc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Vm,{className:"h-4 w-4"})}));sd.displayName=hc.displayName;const ad=b.forwardRef(({className:e,...t},n)=>u.jsx(mc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ti,{className:"h-4 w-4"})}));ad.displayName=mc.displayName;const ir=b.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(hm,{children:u.jsxs(fc,{ref:i,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-lg border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(sd,{}),u.jsx(mm,{className:H("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(ad,{})]})}));ir.displayName=fc.displayName;const od=b.forwardRef(({className:e,...t},n)=>u.jsx(gc,{ref:n,className:H("px-2 py-1.5 text-sm font-semibold",e),...t}));od.displayName=gc.displayName;const Tn=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex w-full cursor-pointer items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(gm,{children:u.jsx(pn,{className:"h-4 w-4"})})}),u.jsx(xm,{children:t})]}));Tn.displayName=pc.displayName;const Ig=b.forwardRef(({className:e,...t},n)=>u.jsx(xc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));Ig.displayName=xc.displayName;const ii=b.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:H("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-sm border bg-background px-3 py-1 text-sm shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));ii.displayName="Input";const Tg=ni("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Xn=b.forwardRef(({className:e,...t},n)=>u.jsx(yc,{ref:n,className:H(Tg(),e),...t}));Xn.displayName=yc.displayName;const zg=ni("inline-flex items-center rounded-md border px-2.5 py-1 text-xs font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Jt({className:e,variant:t,...n}){return u.jsx("div",{className:H(zg({variant:t}),e),...n})}const Ag=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Oe(rd(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),{toast:o}=fr(),l=b.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[c,f]=b.useState(""),[d,p]=b.useState(""),[h,g]=b.useState("playground"),[v,S]=b.useState(!1),[x,_]=b.useState(null),[m,I]=b.useState(null),[E,w]=b.useState(null),N=()=>{_(null),I(null),w(null)};b.useEffect(()=>{if(!e)return;_(null),I(null),w(null);const T=l.map(F=>F.name),A=T.includes(i)?i:T[0]??"";p(A),f(T.find(F=>F!==A)??"")},[e]);const O=async()=>{const T=l.find(F=>F.name===c),A=l.find(F=>F.name===d);if(!(!T||!A)){S(!0),_(null),I(null),w(null);try{const F=await fetch(Vc.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:T.text,newDefinition:A.text,options:{author:h||"playground"}})}),R=await F.json();if(!F.ok||!R.success){const L=Array.isArray(R.errors)?`: ${R.errors.slice(0,3).map(P=>P.message||String(P)).join("; ")}`:"";throw new Error((R.error||`Diff failed (${F.status})`)+L)}I(R.data.summary),w(R.data.document)}catch(F){_(F instanceof Error?F.message:"Diff failed")}finally{S(!1)}}},K=()=>{if(!E)return;const T=new Set(n.map(R=>R.name));let A=`${d}-redline`,F=2;for(;T.has(A);)A=`${d}-redline-${F++}`;s(A,JSON.stringify(E,null,2)),a(A),o({title:`Redline created: ${A}`}),t(!1)},C=m?m.tracked.modified+m.tracked.inserted+m.tracked.deleted:0;return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"sm:max-w-[560px]",children:[u.jsxs(Ht,{children:[u.jsxs(Wt,{className:"flex items-center gap-2",children:[u.jsx(Hc,{className:"size-4"}),"Compare documents"]}),u.jsx(hn,{children:"Diff two versions into a redline with native Word tracked changes (accept/reject in Word)."})]}),u.jsxs("div",{className:"grid gap-4 py-2",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Xn,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(Fr,{value:c,onValueChange:T=>{f(T),N()},children:[u.jsx(rr,{id:"diff-base",children:u.jsx(Lr,{placeholder:"Select document"})}),u.jsx(ir,{children:l.map(T=>u.jsx(Tn,{value:T.name,children:T.name},T.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Xn,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(Fr,{value:d,onValueChange:T=>{p(T),N()},children:[u.jsx(rr,{id:"diff-revised",children:u.jsx(Lr,{placeholder:"Select document"})}),u.jsx(ir,{children:l.map(T=>u.jsx(Tn,{value:T.name,children:T.name},T.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Xn,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(ii,{id:"diff-author",value:h,onChange:T=>{g(T.target.value),N()},placeholder:"playground"})]}),x&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:x}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Jt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Jt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Jt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),C===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((T,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},A))]}),m.notes.map((T,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},A))]})]}),u.jsx(In,{children:m&&C+m.untracked.length>0?u.jsxs(Ee,{onClick:K,children:[u.jsx(Um,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Ee,{onClick:O,disabled:v||!c||!d||c===d,children:[v&&u.jsx(en,{className:"size-4 mr-1"}),"Compare"]})})]})})};var si=e=>e.type==="checkbox",jn=e=>e instanceof Date,ct=e=>e==null;const ld=e=>typeof e=="object";var Qe=e=>!ct(e)&&!Array.isArray(e)&&ld(e)&&!jn(e),ud=e=>Qe(e)&&e.target?si(e.target)?e.target.checked:e.target.value:e,Pg=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,cd=(e,t)=>e.has(Pg(t)),Og=e=>{const t=e.constructor&&e.constructor.prototype;return Qe(t)&&t.hasOwnProperty("isPrototypeOf")},Ua=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mt(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(Ua&&(e instanceof Blob||r))&&(n||Qe(e)))if(t=n?[]:{},!n&&!Og(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=mt(e[i]));else return e;return t}var ls=e=>Array.isArray(e)?e.filter(Boolean):[],Xe=e=>e===void 0,oe=(e,t,n)=>{if(!t||!Qe(e))return n;const r=ls(t.split(/[,[\].]+?/)).reduce((i,s)=>ct(i)?i:i[s],e);return Xe(r)||r===e?Xe(e[t])?n:e[t]:r},Nt=e=>typeof e=="boolean",Ja=e=>/^\w*$/.test(e),dd=e=>ls(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Me=(e,t,n)=>{let r=-1;const i=Ja(t)?[t]:dd(t),s=i.length,a=s-1;for(;++r<s;){const o=i[r];let l=n;if(r!==a){const c=e[o];l=Qe(c)||Array.isArray(c)?c:isNaN(+i[r+1])?{}:[]}if(o==="__proto__"||o==="constructor"||o==="prototype")return;e[o]=l,e=e[o]}return e};const Pi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ot={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Yt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},fd=_e.createContext(null),us=()=>_e.useContext(fd),Dg=e=>{const{children:t,...n}=e;return _e.createElement(fd.Provider,{value:n},t)};var pd=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const a=s;return t._proxyFormState[a]!==Ot.all&&(t._proxyFormState[a]=!r||Ot.all),n&&(n[a]=!0),e[a]}});return i},gt=e=>Qe(e)&&!Object.keys(e).length,hd=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return gt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(a=>t[a]===(!r||Ot.all))},Pr=e=>Array.isArray(e)?e:[e],md=(e,t,n)=>!e||!t||e===t||Pr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function Ha(e){const t=_e.useRef(e);t.current=e,_e.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function Rg(e){const t=us(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[a,o]=_e.useState(n._formState),l=_e.useRef(!0),c=_e.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),f=_e.useRef(i);return f.current=i,Ha({disabled:r,next:d=>l.current&&md(f.current,d.name,s)&&hd(d,c.current,n._updateFormState)&&o({...n._formState,...d}),subject:n._subjects.state}),_e.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),_e.useMemo(()=>pd(a,n,c.current,!1),[a,n])}var Ut=e=>typeof e=="string",gd=(e,t,n,r,i)=>Ut(e)?(r&&t.watch.add(e),oe(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),oe(n,s))):(r&&(t.watchAll=!0),n);function Mg(e){const t=us(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=_e.useRef(r);o.current=r,Ha({disabled:s,subject:n._subjects.values,next:f=>{md(o.current,f.name,a)&&c(mt(gd(o.current,n._names,f.values||n._formValues,!1,i)))}});const[l,c]=_e.useState(n._getWatch(r,i));return _e.useEffect(()=>n._removeUnmounted()),l}function $g(e){const t=us(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=cd(i._names.array,n),o=Mg({control:i,name:n,defaultValue:oe(i._formValues,n,oe(i._defaultValues,n,e.defaultValue)),exact:!0}),l=Rg({control:i,name:n,exact:!0}),c=_e.useRef(i.register(n,{...e.rules,value:o,...Nt(e.disabled)?{disabled:e.disabled}:{}})),f=_e.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!oe(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!oe(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!oe(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!oe(l.validatingFields,n)},error:{enumerable:!0,get:()=>oe(l.errors,n)}}),[l,n]),d=_e.useMemo(()=>({name:n,value:o,...Nt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:ud(p),name:n},type:Pi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:oe(i._formValues,n),name:n},type:Pi.BLUR}),ref:p=>{const h=oe(i._fields,n);h&&p&&(h._f.ref={focus:()=>p.focus(),select:()=>p.select(),setCustomValidity:g=>p.setCustomValidity(g),reportValidity:()=>p.reportValidity()})}}),[n,i._formValues,r,l.disabled,o,i._fields]);return _e.useEffect(()=>{const p=i._options.shouldUnregister||s,h=(g,v)=>{const S=oe(i._fields,g);S&&S._f&&(S._f.mount=v)};if(h(n,!0),p){const g=mt(oe(i._options.defaultValues,n));Me(i._defaultValues,n,g),Xe(oe(i._formValues,n))&&Me(i._formValues,n,g)}return!a&&i.register(n),()=>{(a?p&&!i._state.action:p)?i.unregister(n):h(n,!1)}},[n,i,a,s]),_e.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),_e.useMemo(()=>({field:d,formState:l,fieldState:f}),[d,l,f])}const Fg=e=>e.render($g(e));var Lg=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},Mo=e=>({isOnSubmit:!e||e===Ot.onSubmit,isOnBlur:e===Ot.onBlur,isOnChange:e===Ot.onChange,isOnAll:e===Ot.all,isOnTouch:e===Ot.onTouched}),$o=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Or=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=oe(e,i);if(s){const{_f:a,...o}=s;if(a){if(a.refs&&a.refs[0]&&t(a.refs[0],i)&&!r)return!0;if(a.ref&&t(a.ref,a.name)&&!r)return!0;if(Or(o,t))break}else if(Qe(o)&&Or(o,t))break}}};var Zg=(e,t,n)=>{const r=Pr(oe(e,n));return Me(r,"root",t[n]),Me(e,n,r),e},Wa=e=>e.type==="file",Vt=e=>typeof e=="function",Oi=e=>{if(!Ua)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Ni=e=>Ut(e),qa=e=>e.type==="radio",Di=e=>e instanceof RegExp;const Fo={value:!1,isValid:!1},Lo={value:!0,isValid:!0};var xd=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Xe(e[0].attributes.value)?Xe(e[0].value)||e[0].value===""?Lo:{value:e[0].value,isValid:!0}:Lo:Fo}return Fo};const Zo={isValid:!1,value:null};var yd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Zo):Zo;function Bo(e,t,n="validate"){if(Ni(e)||Array.isArray(e)&&e.every(Ni)||Nt(e)&&!e)return{type:n,message:Ni(e)?e:"",ref:t}}var Rn=e=>Qe(e)&&!Di(e)?e:{value:e,message:""},Vo=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:f,min:d,max:p,pattern:h,validate:g,name:v,valueAsNumber:S,mount:x}=e._f,_=oe(n,v);if(!x||t.has(v))return{};const m=o?o[0]:a,I=A=>{i&&m.reportValidity&&(m.setCustomValidity(Nt(A)?"":A||""),m.reportValidity())},E={},w=qa(a),N=si(a),O=w||N,K=(S||Wa(a))&&Xe(a.value)&&Xe(_)||Oi(a)&&a.value===""||_===""||Array.isArray(_)&&!_.length,C=Lg.bind(null,v,r,E),T=(A,F,R,L=Yt.maxLength,P=Yt.minLength)=>{const V=A?F:R;E[v]={type:A?L:P,message:V,ref:a,...C(A?L:P,V)}};if(s?!Array.isArray(_)||!_.length:l&&(!O&&(K||ct(_))||Nt(_)&&!_||N&&!xd(o).isValid||w&&!yd(o).isValid)){const{value:A,message:F}=Ni(l)?{value:!!l,message:l}:Rn(l);if(A&&(E[v]={type:Yt.required,message:F,ref:m,...C(Yt.required,F)},!r))return I(F),E}if(!K&&(!ct(d)||!ct(p))){let A,F;const R=Rn(p),L=Rn(d);if(!ct(_)&&!isNaN(_)){const P=a.valueAsNumber||_&&+_;ct(R.value)||(A=P>R.value),ct(L.value)||(F=P<L.value)}else{const P=a.valueAsDate||new Date(_),V=k=>new Date(new Date().toDateString()+" "+k),U=a.type=="time",se=a.type=="week";Ut(R.value)&&_&&(A=U?V(_)>V(R.value):se?_>R.value:P>new Date(R.value)),Ut(L.value)&&_&&(F=U?V(_)<V(L.value):se?_<L.value:P<new Date(L.value))}if((A||F)&&(T(!!A,R.message,L.message,Yt.max,Yt.min),!r))return I(E[v].message),E}if((c||f)&&!K&&(Ut(_)||s&&Array.isArray(_))){const A=Rn(c),F=Rn(f),R=!ct(A.value)&&_.length>+A.value,L=!ct(F.value)&&_.length<+F.value;if((R||L)&&(T(R,A.message,F.message),!r))return I(E[v].message),E}if(h&&!K&&Ut(_)){const{value:A,message:F}=Rn(h);if(Di(A)&&!_.match(A)&&(E[v]={type:Yt.pattern,message:F,ref:a,...C(Yt.pattern,F)},!r))return I(F),E}if(g){if(Vt(g)){const A=await g(_,n),F=Bo(A,m);if(F&&(E[v]={...F,...C(Yt.validate,F.message)},!r))return I(F.message),E}else if(Qe(g)){let A={};for(const F in g){if(!gt(A)&&!r)break;const R=Bo(await g[F](_,n),m,F);R&&(A={...R,...C(F,R.message)},I(R.message),r&&(E[v]=A))}if(!gt(A)&&(E[v]={ref:m,...A},!r))return E}}return I(!0),E};function Bg(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Xe(e)?r++:e[t[r++]];return e}function Vg(e){for(const t in e)if(e.hasOwnProperty(t)&&!Xe(e[t]))return!1;return!0}function rt(e,t){const n=Array.isArray(t)?t:Ja(t)?[t]:dd(t),r=n.length===1?e:Bg(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(Qe(r)&&gt(r)||Array.isArray(r)&&Vg(r))&&rt(e,n.slice(0,-1)),e}var Is=()=>{let e=[];return{get observers(){return e},next:i=>{for(const s of e)s.next&&s.next(i)},subscribe:i=>(e.push(i),{unsubscribe:()=>{e=e.filter(s=>s!==i)}}),unsubscribe:()=>{e=[]}}},da=e=>ct(e)||!ld(e);function un(e,t){if(da(e)||da(t))return e===t;if(jn(e)&&jn(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const s=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const a=t[i];if(jn(s)&&jn(a)||Qe(s)&&Qe(a)||Array.isArray(s)&&Array.isArray(a)?!un(s,a):s!==a)return!1}}return!0}var bd=e=>e.type==="select-multiple",Ug=e=>qa(e)||si(e),Ts=e=>Oi(e)&&e.isConnected,vd=e=>{for(const t in e)if(Vt(e[t]))return!0;return!1};function Ri(e,t={}){const n=Array.isArray(e);if(Qe(e)||n)for(const r in e)Array.isArray(e[r])||Qe(e[r])&&!vd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Ri(e[r],t[r])):ct(e[r])||(t[r]=!0);return t}function wd(e,t,n){const r=Array.isArray(e);if(Qe(e)||r)for(const i in e)Array.isArray(e[i])||Qe(e[i])&&!vd(e[i])?Xe(t)||da(n[i])?n[i]=Array.isArray(e[i])?Ri(e[i],[]):{...Ri(e[i])}:wd(e[i],ct(t)?{}:t[i],n[i]):n[i]=!un(e[i],t[i]);return n}var yr=(e,t)=>wd(e,t,Ri(t)),kd=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Xe(e)?e:t?e===""?NaN:e&&+e:n&&Ut(e)?new Date(e):r?r(e):e;function zs(e){const t=e.ref;return Wa(t)?t.files:qa(t)?yd(e.refs).value:bd(t)?[...t.selectedOptions].map(({value:n})=>n):si(t)?xd(e.refs).value:kd(Xe(t.value)?e.ref.value:t.value,e)}var Jg=(e,t,n,r)=>{const i={};for(const s of e){const a=oe(t,s);a&&Me(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},br=e=>Xe(e)?e:Di(e)?e.source:Qe(e)?Di(e.value)?e.value.source:e.value:e;const Uo="AsyncFunction";var Hg=e=>!!e&&!!e.validate&&!!(Vt(e.validate)&&e.validate.constructor.name===Uo||Qe(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Uo)),Wg=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Jo(e,t,n){const r=oe(e,n);if(r||Ja(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=oe(t,s),o=oe(e,s);if(a&&!Array.isArray(a)&&n!==s)return{name:n};if(o&&o.type)return{name:s,error:o};i.pop()}return{name:n}}var qg=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,Gg=(e,t)=>!ls(oe(e,t)).length&&rt(e,t);const Kg={mode:Ot.onSubmit,reValidateMode:Ot.onChange,shouldFocusError:!0};function Yg(e={}){let t={...Kg,...e},n={submitCount:0,isDirty:!1,isLoading:Vt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=Qe(t.defaultValues)||Qe(t.values)?mt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:mt(i),a={action:!1,mount:!1,watch:!1},o={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const f={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={values:Is(),array:Is(),state:Is()},p=Mo(t.mode),h=Mo(t.reValidateMode),g=t.criteriaMode===Ot.all,v=j=>z=>{clearTimeout(c),c=setTimeout(j,z)},S=async j=>{if(!t.disabled&&(f.isValid||j)){const z=t.resolver?gt((await O()).errors):await C(r,!0);z!==n.isValid&&d.state.next({isValid:z})}},x=(j,z)=>{!t.disabled&&(f.isValidating||f.validatingFields)&&((j||Array.from(o.mount)).forEach(M=>{M&&(z?Me(n.validatingFields,M,z):rt(n.validatingFields,M))}),d.state.next({validatingFields:n.validatingFields,isValidating:!gt(n.validatingFields)}))},_=(j,z=[],M,re,ee=!0,Q=!0)=>{if(re&&M&&!t.disabled){if(a.action=!0,Q&&Array.isArray(oe(r,j))){const pe=M(oe(r,j),re.argA,re.argB);ee&&Me(r,j,pe)}if(Q&&Array.isArray(oe(n.errors,j))){const pe=M(oe(n.errors,j),re.argA,re.argB);ee&&Me(n.errors,j,pe),Gg(n.errors,j)}if(f.touchedFields&&Q&&Array.isArray(oe(n.touchedFields,j))){const pe=M(oe(n.touchedFields,j),re.argA,re.argB);ee&&Me(n.touchedFields,j,pe)}f.dirtyFields&&(n.dirtyFields=yr(i,s)),d.state.next({name:j,isDirty:A(j,z),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Me(s,j,z)},m=(j,z)=>{Me(n.errors,j,z),d.state.next({errors:n.errors})},I=j=>{n.errors=j,d.state.next({errors:n.errors,isValid:!1})},E=(j,z,M,re)=>{const ee=oe(r,j);if(ee){const Q=oe(s,j,Xe(M)?oe(i,j):M);Xe(Q)||re&&re.defaultChecked||z?Me(s,j,z?Q:zs(ee._f)):L(j,Q),a.mount&&S()}},w=(j,z,M,re,ee)=>{let Q=!1,pe=!1;const we={name:j};if(!t.disabled){const $=!!(oe(r,j)&&oe(r,j)._f&&oe(r,j)._f.disabled);if(!M||re){f.isDirty&&(pe=n.isDirty,n.isDirty=we.isDirty=A(),Q=pe!==we.isDirty);const G=$||un(oe(i,j),z);pe=!!(!$&&oe(n.dirtyFields,j)),G||$?rt(n.dirtyFields,j):Me(n.dirtyFields,j,!0),we.dirtyFields=n.dirtyFields,Q=Q||f.dirtyFields&&pe!==!G}if(M){const G=oe(n.touchedFields,j);G||(Me(n.touchedFields,j,M),we.touchedFields=n.touchedFields,Q=Q||f.touchedFields&&G!==M)}Q&&ee&&d.state.next(we)}return Q?we:{}},N=(j,z,M,re)=>{const ee=oe(n.errors,j),Q=f.isValid&&Nt(z)&&n.isValid!==z;if(t.delayError&&M?(l=v(()=>m(j,M)),l(t.delayError)):(clearTimeout(c),l=null,M?Me(n.errors,j,M):rt(n.errors,j)),(M?!un(ee,M):ee)||!gt(re)||Q){const pe={...re,...Q&&Nt(z)?{isValid:z}:{},errors:n.errors,name:j};n={...n,...pe},d.state.next(pe)}},O=async j=>{x(j,!0);const z=await t.resolver(s,t.context,Jg(j||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return x(j),z},K=async j=>{const{errors:z}=await O(j);if(j)for(const M of j){const re=oe(z,M);re?Me(n.errors,M,re):rt(n.errors,M)}else n.errors=z;return z},C=async(j,z,M={valid:!0})=>{for(const re in j){const ee=j[re];if(ee){const{_f:Q,...pe}=ee;if(Q){const we=o.array.has(Q.name),$=ee._f&&Hg(ee._f);$&&f.validatingFields&&x([re],!0);const G=await Vo(ee,o.disabled,s,g,t.shouldUseNativeValidation&&!z,we);if($&&f.validatingFields&&x([re]),G[Q.name]&&(M.valid=!1,z))break;!z&&(oe(G,Q.name)?we?Zg(n.errors,G,Q.name):Me(n.errors,Q.name,G[Q.name]):rt(n.errors,Q.name))}!gt(pe)&&await C(pe,z,M)}}return M.valid},T=()=>{for(const j of o.unMount){const z=oe(r,j);z&&(z._f.refs?z._f.refs.every(M=>!Ts(M)):!Ts(z._f.ref))&&ie(j)}o.unMount=new Set},A=(j,z)=>!t.disabled&&(j&&z&&Me(s,j,z),!un(le(),i)),F=(j,z,M)=>gd(j,o,{...a.mount?s:Xe(z)?i:Ut(j)?{[j]:z}:z},M,z),R=j=>ls(oe(a.mount?s:i,j,t.shouldUnregister?oe(i,j,[]):[])),L=(j,z,M={})=>{const re=oe(r,j);let ee=z;if(re){const Q=re._f;Q&&(!Q.disabled&&Me(s,j,kd(z,Q)),ee=Oi(Q.ref)&&ct(z)?"":z,bd(Q.ref)?[...Q.ref.options].forEach(pe=>pe.selected=ee.includes(pe.value)):Q.refs?si(Q.ref)?Q.refs.length>1?Q.refs.forEach(pe=>(!pe.defaultChecked||!pe.disabled)&&(pe.checked=Array.isArray(ee)?!!ee.find(we=>we===pe.value):ee===pe.value)):Q.refs[0]&&(Q.refs[0].checked=!!ee):Q.refs.forEach(pe=>pe.checked=pe.value===ee):Wa(Q.ref)?Q.ref.value="":(Q.ref.value=ee,Q.ref.type||d.values.next({name:j,values:{...s}})))}(M.shouldDirty||M.shouldTouch)&&w(j,ee,M.shouldTouch,M.shouldDirty,!0),M.shouldValidate&&k(j)},P=(j,z,M)=>{for(const re in z){const ee=z[re],Q=`${j}.${re}`,pe=oe(r,Q);(o.array.has(j)||Qe(ee)||pe&&!pe._f)&&!jn(ee)?P(Q,ee,M):L(Q,ee,M)}},V=(j,z,M={})=>{const re=oe(r,j),ee=o.array.has(j),Q=mt(z);Me(s,j,Q),ee?(d.array.next({name:j,values:{...s}}),(f.isDirty||f.dirtyFields)&&M.shouldDirty&&d.state.next({name:j,dirtyFields:yr(i,s),isDirty:A(j,Q)})):re&&!re._f&&!ct(Q)?P(j,Q,M):L(j,Q,M),$o(j,o)&&d.state.next({...n}),d.values.next({name:a.mount?j:void 0,values:{...s}})},U=async j=>{a.mount=!0;const z=j.target;let M=z.name,re=!0;const ee=oe(r,M),Q=()=>z.type?zs(ee._f):ud(j),pe=we=>{re=Number.isNaN(we)||jn(we)&&isNaN(we.getTime())||un(we,oe(s,M,we))};if(ee){let we,$;const G=Q(),he=j.type===Pi.BLUR||j.type===Pi.FOCUS_OUT,je=!Wg(ee._f)&&!t.resolver&&!oe(n.errors,M)&&!ee._f.deps||qg(he,oe(n.touchedFields,M),n.isSubmitted,h,p),D=$o(M,o,he);Me(s,M,G),he?(ee._f.onBlur&&ee._f.onBlur(j),l&&l(0)):ee._f.onChange&&ee._f.onChange(j);const ge=w(M,G,he,!1),Te=!gt(ge)||D;if(!he&&d.values.next({name:M,type:j.type,values:{...s}}),je)return f.isValid&&(t.mode==="onBlur"&&he?S():he||S()),Te&&d.state.next({name:M,...D?{}:ge});if(!he&&D&&d.state.next({...n}),t.resolver){const{errors:Le}=await O([M]);if(pe(G),re){const nt=Jo(n.errors,r,M),et=Jo(Le,r,nt.name||M);we=et.error,M=et.name,$=gt(Le)}}else x([M],!0),we=(await Vo(ee,o.disabled,s,g,t.shouldUseNativeValidation))[M],x([M]),pe(G),re&&(we?$=!1:f.isValid&&($=await C(r,!0)));re&&(ee._f.deps&&k(ee._f.deps),N(M,$,we,ge))}},se=(j,z)=>{if(oe(n.errors,z)&&j.focus)return j.focus(),1},k=async(j,z={})=>{let M,re;const ee=Pr(j);if(t.resolver){const Q=await K(Xe(j)?j:ee);M=gt(Q),re=j?!ee.some(pe=>oe(Q,pe)):M}else j?(re=(await Promise.all(ee.map(async Q=>{const pe=oe(r,Q);return await C(pe&&pe._f?{[Q]:pe}:pe)}))).every(Boolean),!(!re&&!n.isValid)&&S()):re=M=await C(r);return d.state.next({...!Ut(j)||f.isValid&&M!==n.isValid?{}:{name:j},...t.resolver||!j?{isValid:M}:{},errors:n.errors}),z.shouldFocus&&!re&&Or(r,se,j?ee:o.mount),re},le=j=>{const z={...a.mount?s:i};return Xe(j)?z:Ut(j)?oe(z,j):j.map(M=>oe(z,M))},q=(j,z)=>({invalid:!!oe((z||n).errors,j),isDirty:!!oe((z||n).dirtyFields,j),error:oe((z||n).errors,j),isValidating:!!oe(n.validatingFields,j),isTouched:!!oe((z||n).touchedFields,j)}),y=j=>{j&&Pr(j).forEach(z=>rt(n.errors,z)),d.state.next({errors:j?n.errors:{}})},W=(j,z,M)=>{const re=(oe(r,j,{_f:{}})._f||{}).ref,ee=oe(n.errors,j)||{},{ref:Q,message:pe,type:we,...$}=ee;Me(n.errors,j,{...$,...z,ref:re}),d.state.next({name:j,errors:n.errors,isValid:!1}),M&&M.shouldFocus&&re&&re.focus&&re.focus()},B=(j,z)=>Vt(j)?d.values.subscribe({next:M=>j(F(void 0,z),M)}):F(j,z,!0),ie=(j,z={})=>{for(const M of j?Pr(j):o.mount)o.mount.delete(M),o.array.delete(M),z.keepValue||(rt(r,M),rt(s,M)),!z.keepError&&rt(n.errors,M),!z.keepDirty&&rt(n.dirtyFields,M),!z.keepTouched&&rt(n.touchedFields,M),!z.keepIsValidating&&rt(n.validatingFields,M),!t.shouldUnregister&&!z.keepDefaultValue&&rt(i,M);d.values.next({values:{...s}}),d.state.next({...n,...z.keepDirty?{isDirty:A()}:{}}),!z.keepIsValid&&S()},te=({disabled:j,name:z,field:M,fields:re})=>{(Nt(j)&&a.mount||j||o.disabled.has(z))&&(j?o.disabled.add(z):o.disabled.delete(z),w(z,zs(M?M._f:oe(re,z)._f),!1,!1,!0))},X=(j,z={})=>{let M=oe(r,j);const re=Nt(z.disabled)||Nt(t.disabled);return Me(r,j,{...M||{},_f:{...M&&M._f?M._f:{ref:{name:j}},name:j,mount:!0,...z}}),o.mount.add(j),M?te({field:M,disabled:Nt(z.disabled)?z.disabled:t.disabled,name:j}):E(j,!0,z.value),{...re?{disabled:z.disabled||t.disabled}:{},...t.progressive?{required:!!z.required,min:br(z.min),max:br(z.max),minLength:br(z.minLength),maxLength:br(z.maxLength),pattern:br(z.pattern)}:{},name:j,onChange:U,onBlur:U,ref:ee=>{if(ee){X(j,z),M=oe(r,j);const Q=Xe(ee.value)&&ee.querySelectorAll&&ee.querySelectorAll("input,select,textarea")[0]||ee,pe=Ug(Q),we=M._f.refs||[];if(pe?we.find($=>$===Q):Q===M._f.ref)return;Me(r,j,{_f:{...M._f,...pe?{refs:[...we.filter(Ts),Q,...Array.isArray(oe(i,j))?[{}]:[]],ref:{type:Q.type,name:j}}:{ref:Q}}}),E(j,!1,void 0,Q)}else M=oe(r,j,{}),M._f&&(M._f.mount=!1),(t.shouldUnregister||z.shouldUnregister)&&!(cd(o.array,j)&&a.action)&&o.unMount.add(j)}}},fe=()=>t.shouldFocusError&&Or(r,se,o.mount),be=j=>{Nt(j)&&(d.state.next({disabled:j}),Or(r,(z,M)=>{const re=oe(r,M);re&&(z.disabled=re._f.disabled||j,Array.isArray(re._f.refs)&&re._f.refs.forEach(ee=>{ee.disabled=re._f.disabled||j}))},0,!1))},ne=(j,z)=>async M=>{let re;M&&(M.preventDefault&&M.preventDefault(),M.persist&&M.persist());let ee=mt(s);if(o.disabled.size)for(const Q of o.disabled)Me(ee,Q,void 0);if(d.state.next({isSubmitting:!0}),t.resolver){const{errors:Q,values:pe}=await O();n.errors=Q,ee=pe}else await C(r);if(rt(n.errors,"root"),gt(n.errors)){d.state.next({errors:{}});try{await j(ee,M)}catch(Q){re=Q}}else z&&await z({...n.errors},M),fe(),setTimeout(fe);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:gt(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},de=(j,z={})=>{oe(r,j)&&(Xe(z.defaultValue)?V(j,mt(oe(i,j))):(V(j,z.defaultValue),Me(i,j,mt(z.defaultValue))),z.keepTouched||rt(n.touchedFields,j),z.keepDirty||(rt(n.dirtyFields,j),n.isDirty=z.defaultValue?A(j,mt(oe(i,j))):A()),z.keepError||(rt(n.errors,j),f.isValid&&S()),d.state.next({...n}))},ue=(j,z={})=>{const M=j?mt(j):i,re=mt(M),ee=gt(j),Q=ee?i:re;if(z.keepDefaultValues||(i=M),!z.keepValues){if(z.keepDirtyValues){const pe=new Set([...o.mount,...Object.keys(yr(i,s))]);for(const we of Array.from(pe))oe(n.dirtyFields,we)?Me(Q,we,oe(s,we)):V(we,oe(Q,we))}else{if(Ua&&Xe(j))for(const pe of o.mount){const we=oe(r,pe);if(we&&we._f){const $=Array.isArray(we._f.refs)?we._f.refs[0]:we._f.ref;if(Oi($)){const G=$.closest("form");if(G){G.reset();break}}}}r={}}s=t.shouldUnregister?z.keepDefaultValues?mt(i):{}:mt(Q),d.array.next({values:{...Q}}),d.values.next({values:{...Q}})}o={mount:z.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!f.isValid||!!z.keepIsValid||!!z.keepDirtyValues,a.watch=!!t.shouldUnregister,d.state.next({submitCount:z.keepSubmitCount?n.submitCount:0,isDirty:ee?!1:z.keepDirty?n.isDirty:!!(z.keepDefaultValues&&!un(j,i)),isSubmitted:z.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ee?{}:z.keepDirtyValues?z.keepDefaultValues&&s?yr(i,s):n.dirtyFields:z.keepDefaultValues&&j?yr(i,j):z.keepDirty?n.dirtyFields:{},touchedFields:z.keepTouched?n.touchedFields:{},errors:z.keepErrors?n.errors:{},isSubmitSuccessful:z.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},Z=(j,z)=>ue(Vt(j)?j(s):j,z);return{control:{register:X,unregister:ie,getFieldState:q,handleSubmit:ne,setError:W,_executeSchema:O,_getWatch:F,_getDirty:A,_updateValid:S,_removeUnmounted:T,_updateFieldArray:_,_updateDisabledField:te,_getFieldArray:R,_reset:ue,_resetDefaultValues:()=>Vt(t.defaultValues)&&t.defaultValues().then(j=>{Z(j,t.resetOptions),d.state.next({isLoading:!1})}),_updateFormState:j=>{n={...n,...j}},_disableForm:be,_subjects:d,_proxyFormState:f,_setErrors:I,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(j){a=j},get _defaultValues(){return i},get _names(){return o},set _names(j){o=j},get _formState(){return n},set _formState(j){n=j},get _options(){return t},set _options(j){t={...t,...j}}},trigger:k,register:X,handleSubmit:ne,watch:B,setValue:V,getValues:le,reset:Z,resetField:de,clearErrors:y,unregister:ie,setError:W,setFocus:(j,z={})=>{const M=oe(r,j),re=M&&M._f;if(re){const ee=re.refs?re.refs[0]:re.ref;ee.focus&&(ee.focus(),z.shouldSelect&&Vt(ee.select)&&ee.select())}},getFieldState:q}}function Xg(e={}){const t=_e.useRef(void 0),n=_e.useRef(void 0),[r,i]=_e.useState({isDirty:!1,isValidating:!1,isLoading:Vt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Vt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Yg(e),formState:r});const s=t.current.control;return s._options=e,Ha({subject:s._subjects.state,next:a=>{hd(a,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),_e.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),_e.useEffect(()=>{if(s._proxyFormState.isDirty){const a=s._getDirty();a!==r.isDirty&&s._subjects.state.next({isDirty:a})}},[s,r.isDirty]),_e.useEffect(()=>{e.values&&!un(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(a=>({...a}))):s._resetDefaultValues()},[e.values,s]),_e.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),_e.useEffect(()=>{s._state.mount||(s._updateValid(),s._state.mount=!0),s._state.watch&&(s._state.watch=!1,s._subjects.state.next({...s._formState})),s._removeUnmounted()}),_e.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=pd(r,s),t.current}function Qg(e){return async t=>{const n=e(t);if(n.success&&n.data)return{values:n.data,errors:{}};const r={};if(n.errors)for(const i of n.errors){const s=i.path||"root";r[s]||(r[s]={type:"validation",message:i.message})}return{values:{},errors:r}}}const ex=Dg,Sd=b.createContext({}),Ho=({...e})=>u.jsx(Sd.Provider,{value:{name:e.name},children:u.jsx(Fg,{...e})}),cs=()=>{const e=b.useContext(Sd),t=b.useContext(_d),{getFieldState:n,formState:r}=us(),i=n(e.name,r);if(!e)throw new Error("useFormField should be used within <FormField>");const{id:s}=t;return{id:s,name:e.name,formItemId:`${s}-form-item`,formDescriptionId:`${s}-form-item-description`,formMessageId:`${s}-form-item-message`,...i}},_d=b.createContext({}),fa=b.forwardRef(({className:e,...t},n)=>{const r=b.useId();return u.jsx(_d.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:H("space-y-2",e),...t})})});fa.displayName="FormItem";const pa=b.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=cs();return u.jsx(Xn,{ref:n,className:H(r&&"text-destructive",e),htmlFor:i,...t})});pa.displayName="FormLabel";const ha=b.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=cs();return u.jsx(dr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});ha.displayName="FormControl";const jd=b.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=cs();return u.jsx("p",{ref:n,id:r,className:H("text-muted-foreground text-[0.8rem]",e),...t})});jd.displayName="FormDescription";const ma=b.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=cs(),a=i?String(i==null?void 0:i.message):t;return a?u.jsx("p",{ref:r,id:s,className:H("text-destructive text-[0.8rem] font-medium",e),...n,children:a}):null});ma.displayName="FormMessage";function Ga(){const e=new Date,t=n=>String(n).padStart(2,"0");return`Chat ${t(e.getMonth()+1)}/${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}const Cd=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),tx=(e=Cd())=>wg()(kg(Sg((t,n)=>({...e,toggleChat:()=>t(r=>({chatOpen:!r.chatOpen})),openChat:()=>t({chatOpen:!0}),closeChat:()=>t({chatOpen:!1}),addContext:r=>t(i=>({contextAttachments:[...i.contextAttachments,r]})),removeContext:r=>t(i=>({contextAttachments:i.contextAttachments.filter((s,a)=>a!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),a={id:i,documentName:r,title:Ga(),messages:[],createdAt:s,updatedAt:s};return t(o=>({threads:{...o.threads,[i]:a},activeThreadId:{...o.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const a=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),o=s.documentName,l={...i.activeThreadId};if(l[o]===r){const c=Object.values(a).filter(f=>f.documentName===o);c.length>0?(c.sort((f,d)=>d.updatedAt-f.updatedAt),l[o]=c[0].id):delete l[o]}t({threads:a,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(a=>({activeThreadId:{...a.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},a={...i.activeThreadId};for(const[o,l]of Object.entries(s))l.documentName===r&&delete s[o];return delete a[r],{threads:s,activeThreadId:a}})},renameThreadsForDocument:(r,i)=>{t(s=>{const a={...s.threads},o={...s.activeThreadId};for(const[l,c]of Object.entries(a))c.documentName===r&&(a[l]={...c,documentName:i});return r in o&&(o[i]=o[r],delete o[r]),{threads:a,activeThreadId:o}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:_g(()=>hg),partialize:t=>({threads:t.threads,activeThreadId:t.activeThreadId,scope:t.scope,model:t.model}),migrate:(t,n)=>{if(n===0&&t){const r=t.chatMessages;if(Array.isArray(r)&&r.length>0){const i=crypto.randomUUID(),s=Date.now();return{threads:{[i]:{id:i,documentName:"__migrated__",title:"Migrated Chat",messages:r,createdAt:s,updatedAt:s}},activeThreadId:{__migrated__:i}}}return{threads:{},activeThreadId:{}}}return t}}))),Nd=b.createContext(void 0),nx=({children:e})=>{const t=b.useRef(null);return t.current||(t.current=tx(Cd())),u.jsx(Nd.Provider,{value:t.current,children:e})},Pe=e=>{const t=b.useContext(Nd);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return jg(t,e)};function rx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function ix(e,t,n){const r={},i=[];e!=="delete"&&(r.name=fi.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),i.push("name")),e==="create"&&(r.template=fi.Optional(fi.String({description:"Template selection"})));const s=fi.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:a=>{const o=[];if(!Dm(s,a))for(const c of Rm(s,a))o.push({path:c.path.replace(/^\//,""),message:c.message});const l=a;if(e!=="delete"&&l.name){const c=l.name.trim();c?(l.name=c,t(c)||o.push({path:"name",message:"Document with this name already exists"})):o.push({path:"name",message:"Name can't be empty"})}return e==="create"&&(n!=null&&n.length)&&l.template&&(n.some(c=>c.name===l.template)||o.push({path:"template",message:"You must select a valid template"})),{success:o.length===0,data:o.length===0?l:void 0,errors:o}}}}function sx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const ax=e=>({create:{title:e?"New Theme":"New Document",description:e?"Create a new theme from scratch or based on discovered themes.":"Create a new document from scratch or based on discovered documents.",button:"Create",buttonVariant:"default"},update:{title:"Rename Document",description:"Give your document a new name.",button:"Save",buttonVariant:"default"},delete:{title:"Are you absolutely sure?",description:"This action cannot be undone. Are you sure you want to permanently delete this document?",button:"Confirm",buttonVariant:"destructive"}}),Mn="__empty__";function ox({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=b.useState(!1),[c,f]=b.useState(null),[d,p]=b.useState("idle"),{toast:h}=fr(),g=ax(a),{documents:v,openTabs:S,createDocument:x,renameDocument:_,deleteDocument:m,openDocument:I,closeDocument:E}=Oe(le=>le),{updateTheme:w,removeTheme:N}=ca(le=>le),O=Pe(le=>le.renameThreadsForDocument),K=Pe(le=>le.deleteThreadsForDocument),C=b.useMemo(()=>a?s||[]:i||[],[a,i,s]),T=b.useMemo(()=>{const le={current:[],downstream:[]};return C.forEach(q=>{le[q.location]&&le[q.location].push(q)}),le},[C]),A=b.useMemo(()=>C.map(le=>({name:le.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[C]),F=b.useMemo(()=>ix(e,le=>rx(le,v,r),A),[e,v,r,A]),R=F.schema,L=b.useMemo(()=>{const le=new Map;return C.forEach(q=>le.set(q.path,q)),le},[C]),P=Mn,V=Xg({resolver:Qg(F.validate),defaultValues:sx(e,void 0,r)}),[U,se]=b.useState(P);b.useEffect(()=>{if(U&&U!==Mn&&e==="create"){const le=L.get(U);if(le){f(null),p("loading");let q=!1;return fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(le.name)}/content`).then(y=>{if(!y.ok)throw new Error(`Failed to fetch content: ${y.statusText}`);return y.text()}).then(y=>{if(q)return;const W=JSON.parse(y);f(JSON.stringify(W,null,2)),p("idle")}).catch(y=>{q||(console.error("Failed to copy template:",y),f(null),p("error"))}),()=>{q=!0}}}p("idle")},[U,e,L,a]),b.useEffect(()=>{t&&(V.reset(),f(null),p("idle"),se(P))},[V,t]);const k=V.handleSubmit(async({name:le,template:q})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=U?L.get(U):C.find(de=>de.name===q);let W,B=le;if(!!U&&U!==Mn&&c===null){h({title:d==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:d==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(a){const de=B.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),ue=yt==="docx"?Mm(de):{name:de,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};W=c||JSON.stringify(ue,null,2);const Z=`.${yt}.theme.json`;B.endsWith(Z)||(B=B.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),B+=Z)}else{const de=y;W=c||JSON.stringify(yt==="docx"?{name:"docx",props:{theme:(de==null?void 0:de.theme)||"default",metadata:{title:(de==null?void 0:de.title)||B.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(de==null?void 0:de.title)||B.replace(/\.(json|js)$/i,""),theme:(de==null?void 0:de.theme)||"default"},children:[{name:"slide",props:{},children:[{name:"text",props:{text:"Start writing your presentation content here...",fontSize:24,y:2,x:1,w:8}}]}]},null,2);const ue=yt==="docx"?".docx.json":".pptx.json";!B.endsWith(ue)&&!B.endsWith(".json")&&(B+=ue)}const te=B.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),X=te?te[0]:"",fe=B.slice(0,B.length-X.length);let be=B,ne=1;for(;v.some(de=>de.name===be);)ne++,be=`${fe} (${ne})${X}`;B=be,x(B,W),I(B),a&&w(B,W)}else if(e==="update"){const y=r,W=le,B=S.includes(y);B&&E(y),_(y,W),O(y,W),B&&I(W)}else if(e==="delete"){const y=r;E(y),m(y),K(y),a&&N(y)}n()}finally{l(!1)}});return u.jsx(ex,{...V,children:u.jsxs("form",{onSubmit:k,children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:g[e].title}),u.jsx(hn,{children:g[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[R.properties&&"name"in R.properties&&u.jsx(Ho,{control:V.control,name:"name",render:({field:le})=>u.jsxs(fa,{children:[u.jsx(pa,{children:"Name"}),u.jsx(ha,{children:u.jsx(ii,{placeholder:"Enter a name or select a template below",autoComplete:"off",...le})}),u.jsx(ma,{})]})}),e==="create"&&u.jsx(Ho,{control:V.control,name:"template",render:({field:le})=>u.jsxs(fa,{children:[u.jsx(pa,{children:a?"Base Theme":"Base Document"}),u.jsxs(Fr,{onValueChange:q=>{if(q===Mn)le.onChange(void 0),V.setValue("name",""),se(Mn),f(null);else{const y=L.get(q);y&&(le.onChange(y.name),V.setValue("name",y.name),se(q))}},defaultValue:P,children:[u.jsx(ha,{children:u.jsx(rr,{children:u.jsx(Lr,{placeholder:`Select a discovered ${a?"theme":"document"}`})})}),u.jsxs(ir,{className:"max-h-[300px]",children:[u.jsxs(Tn,{value:Mn,children:["Empty ",a?"theme":"document"]}),Object.entries(T).map(([q,y])=>y.length===0?null:u.jsxs(Eg,{children:[u.jsx(od,{children:q==="current"?"📁 Current Directory":"📦 Project"}),y.map(W=>{let B;return W.title&&W.title!==W.name?B=W.title:W.description&&(B=W.description.length>40?W.description.substring(0,40)+"...":W.description),u.jsx(Tn,{value:W.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:W.name}),B&&u.jsx("span",{className:"text-muted-foreground text-xs",children:B})]})},W.path)})]},q))]})]}),u.jsxs(jd,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(ma,{})]})})]}),u.jsx(In,{children:u.jsx(Ee,{type:"submit",variant:g[e].buttonVariant,disabled:o,children:o?u.jsxs(u.Fragment,{children:[u.jsx(en,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):g[e].button})})]})})}const Mi=_e.memo(ox);function sn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function Ka({text:e,query:t}){if(!t)return u.jsx(u.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?u.jsx(u.Fragment,{children:e}):u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Wo({children:e,count:t,actions:n,className:r}){return u.jsxs("div",{className:H("flex h-6 shrink-0 items-center gap-1.5 px-1 select-none",r),children:[u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] text-sidebar-foreground/70 uppercase",children:e}),t!==void 0&&u.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t}),n&&u.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:n})]})}const Ft=_e.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:H("flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm","text-sidebar-foreground/55 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","disabled:pointer-events-none disabled:opacity-40","[&>svg]:size-3.5",e),...t}));Ft.displayName="RailIconButton";function qo({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:H("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function Go({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:H("flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(e,{className:"size-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:t})]}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const lx=bm,ux=vm,cx=b.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(kc,{ref:i,className:H("focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none",t&&"pl-8",e),...r,children:[n,u.jsx(ri,{className:"ml-auto h-4 w-4"})]}));cx.displayName=kc.displayName;const dx=b.forwardRef(({className:e,...t},n)=>u.jsx(Sc,{ref:n,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));dx.displayName=Sc.displayName;const Ed=b.forwardRef(({className:e,...t},n)=>u.jsx(wm,{children:u.jsx(bc,{ref:n,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md",e),...t})}));Ed.displayName=bc.displayName;const Id=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(wc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Id.displayName=wc.displayName;const fx=b.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(_c,{ref:i,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(jc,{children:u.jsx(pn,{className:"h-4 w-4"})})}),t]}));fx.displayName=_c.displayName;const px=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Cc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(jc,{children:u.jsx(Wc,{className:"h-4 w-4 fill-current"})})}),t]}));px.displayName=Cc.displayName;const hx=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Nc,{ref:r,className:H("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));hx.displayName=Nc.displayName;const Td=b.forwardRef(({className:e,...t},n)=>u.jsx(vc,{ref:n,className:H("bg-border -mx-1 my-1 h-px",e),...t}));Td.displayName=vc.displayName;const zd=({className:e,...t})=>u.jsx("span",{className:H("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});zd.displayName="ContextMenuShortcut";const ds=km,fs=Sm,mx=b.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(Ac,{ref:i,className:H("focus:bg-accent data-[state=open]:bg-accent flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none select-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",e),...r,children:[n,u.jsx(ri,{className:"ml-auto"})]}));mx.displayName=Ac.displayName;const gx=b.forwardRef(({className:e,...t},n)=>u.jsx(Pc,{ref:n,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));gx.displayName=Pc.displayName;const ai=b.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(_m,{children:u.jsx(Ec,{ref:r,sideOffset:t,className:H("bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));ai.displayName=Ec.displayName;const Bt=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Ic,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",e),...n}));Bt.displayName=Ic.displayName;const xx=b.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Oc,{ref:i,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Dc,{children:u.jsx(pn,{className:"h-4 w-4"})})}),t]}));xx.displayName=Oc.displayName;const yx=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Rc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Dc,{children:u.jsx(Wc,{className:"h-2 w-2 fill-current"})})}),t]}));yx.displayName=Rc.displayName;const Ad=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(zc,{ref:r,className:H("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Ad.displayName=zc.displayName;const sr=b.forwardRef(({className:e,...t},n)=>u.jsx(Tc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));sr.displayName=Tc.displayName;const Pd=({className:e,...t})=>u.jsx("span",{className:H("ml-auto text-xs tracking-widest opacity-60",e),...t});Pd.displayName="DropdownMenuShortcut";const Od=b.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(Mc,{ref:i,decorative:n,orientation:t,className:H("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Od.displayName=Mc.displayName;const Dd=uc,bx=jm,vx=cc,Rd=b.forwardRef(({className:e,...t},n)=>u.jsx(as,{className:H("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t,ref:n}));Rd.displayName=as.displayName;const wx=ni("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Ya=b.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(vx,{children:[u.jsx(Rd,{}),u.jsxs(rs,{ref:i,className:H(wx({side:e}),t),...r,children:[u.jsxs(Ba,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none",children:[u.jsx(fn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));Ya.displayName=rs.displayName;const kx=b.forwardRef(({className:e,...t},n)=>u.jsx(is,{ref:n,className:H("text-foreground text-lg font-semibold",e),...t}));kx.displayName=is.displayName;const Sx=b.forwardRef(({className:e,...t},n)=>u.jsx(ss,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));Sx.displayName=ss.displayName;function Dr({className:e,...t}){return u.jsx("div",{className:H("bg-primary/10 animate-pulse rounded-md",e),...t})}const As=768,Ps=1200;function Md(e){return typeof window<"u"?window.innerWidth<e:!1}function $d(){const[e,t]=b.useState(()=>Md(As));return b.useEffect(()=>{const n=window.matchMedia(`(max-width: ${As-1}px)`),r=()=>{t(window.innerWidth<As)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function _x(){const[e,t]=b.useState(()=>Md(Ps));return b.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ps-1}px)`),r=()=>{t(window.innerWidth<Ps)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const jx="sidebar_state",Cx=60*60*24*7,Nx="16rem",Ex="18rem",Ix="3rem",Tx="b",Fd=b.createContext(null);function ps(){const e=b.useContext(Fd);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const Ld=b.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=$d(),[c,f]=b.useState(!1),[d,p]=b.useState(e),h=t??d,g=b.useCallback(_=>{const m=typeof _=="function"?_(h):_;n?n(m):p(m),document.cookie=`${jx}=${m}; path=/; max-age=${Cx}`},[n,h]),v=b.useCallback(()=>l?f(_=>!_):g(_=>!_),[l,g,f]);b.useEffect(()=>{const _=I=>{var N;const E=I;if(!E)return!1;const w=(N=E.tagName)==null?void 0:N.toLowerCase();return w==="input"||w==="textarea"||w==="select"||E.isContentEditable?!0:!!(E.closest&&E.closest(".monaco-editor"))},m=I=>{const E=I.metaKey||I.ctrlKey,w=I.key.toLowerCase();if(E&&w===Tx){I.preventDefault(),v();return}E&&w==="s"&&!_(I.target)&&(I.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const S=h?"expanded":"collapsed",x=b.useMemo(()=>({state:S,open:h,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:f,toggleSidebar:v}),[S,h,g,l,c,f,v]);return u.jsx(Fd.Provider,{value:x,children:u.jsx($m,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":Nx,"--sidebar-width-icon":Ix,...i},className:H("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});Ld.displayName="SidebarProvider";const Zd=b.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},a)=>{const{isMobile:o,state:l,openMobile:c,setOpenMobile:f}=ps();return n==="none"?u.jsx("div",{className:H("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:a,...s,children:i}):o?u.jsx(Dd,{open:c,onOpenChange:f,...s,children:u.jsx(Ya,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":Ex},side:e,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):u.jsxs("div",{ref:a,className:"group peer text-sidebar-foreground hidden md:block","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":t,"data-side":e,children:[u.jsx("div",{className:H("relative h-svh w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),u.jsx("div",{className:H("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",e==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...s,children:u.jsx("div",{"data-sidebar":"sidebar",className:"bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow",children:i})})]})});Zd.displayName="Sidebar";const zx=b.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=ps();return u.jsxs(Ee,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:H("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(Jm,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});zx.displayName="SidebarTrigger";const Ax=b.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=ps();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:H("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:hover:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",e),...t})});Ax.displayName="SidebarRail";const Px=b.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:H("bg-background relative flex min-h-svh flex-1 flex-col","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2",e),...t}));Px.displayName="SidebarInset";const Ox=b.forwardRef(({className:e,...t},n)=>u.jsx(ii,{ref:n,"data-sidebar":"input",className:H("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));Ox.displayName="SidebarInput";const ga=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:H("flex flex-col gap-2 p-2",e),...t}));ga.displayName="SidebarHeader";const Bd=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:H("flex flex-col gap-2 p-2",e),...t}));Bd.displayName="SidebarFooter";const Dx=b.forwardRef(({className:e,...t},n)=>u.jsx(Od,{ref:n,"data-sidebar":"separator",className:H("bg-sidebar-border mx-2 w-auto",e),...t}));Dx.displayName="SidebarSeparator";const xa=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:H("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));xa.displayName="SidebarContent";const Rx=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:H("relative flex w-full min-w-0 flex-col p-2",e),...t}));Rx.displayName="SidebarGroup";const Mx=b.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?dr:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:H("text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium transition-[margin,opa] duration-200 ease-linear outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",e),...n})});Mx.displayName="SidebarGroupLabel";const $x=b.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?dr:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:H("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",e),...n})});$x.displayName="SidebarGroupAction";const Fx=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:H("w-full text-sm",e),...t}));Fx.displayName="SidebarGroupContent";const Cr=b.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:H("flex w-full min-w-0 flex-col gap-1",e),...t}));Cr.displayName="SidebarMenu";const Vd=b.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:H("group/menu-item relative",e),...t}));Vd.displayName="SidebarMenuItem";const Lx=ni("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),Ud=b.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...a},o)=>{const l=e?dr:"button",{isMobile:c,state:f}=ps(),d=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:H(Lx({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:d}),u.jsx(Ke,{side:"right",align:"center",hidden:f!=="collapsed"||c,...i})]})):d});Ud.displayName="SidebarMenuButton";const Jd=b.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?dr:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:H("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",e),...r})});Jd.displayName="SidebarMenuAction";const Zx=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:H("text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",e),...t}));Zx.displayName="SidebarMenuBadge";const Bx=b.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=b.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:H("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Dr,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Dr,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Bx.displayName="SidebarMenuSkeleton";const Vx=b.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:H("border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",e),...t}));Vx.displayName="SidebarMenuSub";const Ux=b.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Ux.displayName="SidebarMenuSubItem";const Jx=b.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const a=e?dr:"a";return u.jsx(a,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:H("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...i})});Jx.displayName="SidebarMenuSubButton";function Ei(e,t){const n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.style.display="none",r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}const Hx=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Wx({document:e,compact:t=!1,query:n=""}){const r=b.useRef(null),[i,s]=b.useState(!1),[a,o]=b.useState(!1),[l,c]=b.useState(!1),[f,d]=b.useState(!1),p=Oe(q=>q.openDocument),h=Oe(q=>q.documentTypes),g=Oe(q=>q.activeTab),v=Qt(q=>q.name),S=Qt(q=>q.text),x=Qt(q=>q.isGenerating),m=(h[e.name]||"application/json+report")==="application/json+theme",I=g===e.name,[E,w]=b.useState(v),[N,O]=b.useState(S),K=100,C=0;b.useEffect(()=>{const q=setTimeout(()=>{v&&S?(w(v),O(S)):x||(w(""),O(""))},x?K:C);return()=>clearTimeout(q)},[v,S,x]);const T=E===e.name,A=q=>{var W;const y=new Set;try{const B=JSON.parse(q);(W=B.props)!=null&&W.theme&&y.add(B.props.theme),B.children&&Array.isArray(B.children)&&B.children.forEach(ie=>{var te;ie.name==="docx"&&((te=ie.props)!=null&&te.theme)&&y.add(ie.props.theme)})}catch{}return y},F=b.useMemo(()=>{if(!m||!N)return!1;try{const q=JSON.parse(e.text),y=mg(q);if(y)return A(N).has(y)}catch{}return!1},[m,N,e.text]),R=b.useCallback(()=>{c(!1)},[]),L=b.useCallback(()=>{d(!1)},[]),P=I?null:T?"preview":F?"in-use":null,V=I?"Editing":T?"In preview":F?"Used by preview":null,U=b.useMemo(()=>[{key:"open",label:"Open",shortcut:Hx?"⌘⏎":"⌃⏎",run:()=>p(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Ei(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>d(!0)}],[e.name,e.text,e.type,p]),se=m?Hm:qc,k=i||a,le=u.jsxs(Ud,{size:"sm",ref:r,"aria-label":V?`${e.name} — ${V}`:e.name,className:H("relative h-7 rounded-sm text-[13px] font-normal","text-sidebar-foreground/85 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground",t?"size-7 justify-center px-0":"gap-2 pr-7 pl-2",k&&"bg-sidebar-accent/60 text-sidebar-foreground",I&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:V?`${e.name} — ${V}`:e.name,onClick:()=>{p(e.name)},onKeyDown:q=>{var y;(q.ctrlKey||q.metaKey)&&q.key==="Enter"?(p(e.name),q.preventDefault()):q.key==="Enter"?(c(!0),q.preventDefault()):q.key==="Backspace"||q.key==="Delete"?(d(!0),q.preventDefault()):q.key==="Escape"&&((y=r.current)==null||y.blur(),q.preventDefault())},children:[I&&u.jsx("span",{"aria-hidden":!0,className:H("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(se,{className:H("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",I&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(Ka,{text:e.name,query:n})}),t&&P&&u.jsx(qo,{tone:P,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(Vd,{children:[u.jsxs(lx,{onOpenChange:s,children:[u.jsx(ux,{className:"block",children:t?u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:le}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:V??(m?"Theme":"Document")})]})})]}):le}),u.jsx(Ed,{className:"w-44",children:U.map(q=>u.jsxs(_e.Fragment,{children:[q.separatorBefore&&u.jsx(Td,{}),u.jsxs(Id,{onClick:q.run,className:H(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(zd,{children:q.shortcut})]})]},q.key))})]}),!t&&u.jsxs(u.Fragment,{children:[P&&u.jsx(qo,{tone:P,className:H("pointer-events-none absolute top-1/2 right-2.5 -translate-y-1/2 transition-opacity","group-hover/menu-item:opacity-0 group-focus-within/menu-item:opacity-0",a&&"opacity-0")}),u.jsxs(ds,{onOpenChange:o,children:[u.jsx(fs,{asChild:!0,children:u.jsx(Jd,{showOnHover:!0,"aria-label":`Actions for ${e.name}`,className:"top-1 size-5 rounded-sm text-sidebar-foreground/55 hover:text-sidebar-foreground [&>svg]:size-3.5",children:u.jsx(Gc,{})})}),u.jsx(ai,{side:"right",align:"start",className:"w-44",children:U.map(q=>u.jsxs(_e.Fragment,{children:[q.separatorBefore&&u.jsx(sr,{}),u.jsxs(Bt,{onClick:q.run,className:H(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(Pd,{children:q.shortcut})]})]},q.key))})]})]}),u.jsx(It,{open:l,onOpenChange:c,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var y;q.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Mi,{mode:"update",shouldReset:!l,postSubmit:R,selectedName:e.name})})}),u.jsx(It,{open:f,onOpenChange:d,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var y;q.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Mi,{mode:"delete",shouldReset:!f,postSubmit:L,selectedName:e.name})})})]})}const mi=_e.memo(Wx);async function qx(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const Zr=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs($c,{ref:r,className:H("relative overflow-hidden",e),...n,children:[u.jsx(Cm,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Hd,{}),u.jsx(Nm,{})]}));Zr.displayName=$c.displayName;const Hd=b.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Fc,{ref:r,orientation:t,className:H("flex touch-none transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Em,{className:"bg-border relative flex-1 rounded-full"})}));Hd.displayName=Fc.displayName;function Xa({className:e,...t}){return u.jsx(Im,{"data-slot":"switch",className:H("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-switch-off focus-visible:ring-ring inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent transition-colors outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:u.jsx(Tm,{"data-slot":"switch-thumb",className:H("bg-background pointer-events-none block size-4 rounded-full shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const Gx=ni("relative w-full rounded-sm border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-card text-foreground",destructive:"border-transparent bg-destructive-bg text-destructive-bg-foreground [&>svg]:text-destructive-bg-foreground",warning:"border-transparent bg-warning-bg text-warning-bg-foreground [&>svg]:text-warning-bg-foreground",success:"border-transparent bg-success-bg text-success-bg-foreground [&>svg]:text-success-bg-foreground",info:"border-transparent bg-data-blue-bg text-data-blue-bg-foreground [&>svg]:text-data-blue-bg-foreground"}},defaultVariants:{variant:"default"}}),$i=b.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:H(Gx({variant:t}),e),...n}));$i.displayName="Alert";const Kx=b.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:H("mb-1 font-medium leading-none tracking-tight",e),...t}));Kx.displayName="AlertTitle";const Fi=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:H("text-sm [&_p]:leading-relaxed",e),...t}));Fi.displayName="AlertDescription";const Li=b.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=b.useState(n<2),a=t!==null&&typeof t=="object",o=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?u.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-warning",children:['"',t,'"']}):u.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,f=a?Object.keys(t).length:0;return u.jsxs("div",{className:H("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[a&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(ti,{className:"h-3 w-3"}):u.jsx(ri,{className:"h-3 w-3"})}),!a&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),a?u.jsxs("span",{className:"text-muted-foreground",children:[o?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[f," ",o?"items":"properties"]}),!i&&(o?"]":"}")]}):c(),!a&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),a&&i&&u.jsxs("div",{className:"ml-4",children:[o?t.map((d,p)=>u.jsx(Li,{keyName:String(p),value:d,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([d,p],h,g)=>u.jsx(Li,{keyName:d,value:p,depth:n+1,isLast:h===g.length-1},d)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[o?"]":"}",!r&&","]})})]})]})});Li.displayName="JsonNode";const Zi=b.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:H("space-y-4",r),children:[u.jsx(Dr,{className:"h-8 w-64"}),u.jsx(Dr,{className:"h-4 w-full"}),u.jsx(Dr,{className:"h-64 w-full"})]}):n?u.jsx($i,{variant:"destructive",className:r,children:u.jsx(Fi,{children:n})}):e?u.jsx(Zr,{className:H("h-full w-full rounded-md border bg-muted/10 p-4",r),children:u.jsx("div",{className:"font-mono text-xs",children:u.jsx(Li,{value:e})})}):u.jsx($i,{className:r,children:u.jsx(Fi,{children:"No schema available"})}));Zi.displayName="SchemaViewer";function Yx({plugins:e,initialFocusedPlugin:t}){var m,I;const n=Dt(E=>E.togglePlugin),r=Dt(E=>E.isPluginSelected),i=Dt(E=>E.selectedPlugins),s=Dt(E=>E.isApplyingPlugins),[a,o]=b.useState(null),[l,c]=b.useState(null),[f,d]=b.useState("properties");b.useEffect(()=>{if(t){const E=e.find(w=>w.name===t);if(E){o(E);return}}e.length>0&&!a&&o(e[0])},[t,e]);const p=b.useMemo(()=>{const E={current:[],downstream:[],upstream:[]};return e.forEach(w=>{E[w.location]&&E[w.location].push(w)}),E},[e]),h=async(E,w)=>{a&&(await qx(a.name,E.props),c(w),setTimeout(()=>c(null),2e3))},g=E=>{switch(E){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return E}},v=E=>{switch(E){case"current":return u.jsx(Xm,{className:"size-3"});case"downstream":return u.jsx(Ym,{className:"size-3"});case"upstream":return u.jsx(qc,{className:"size-3"});default:return null}},S=((m=a==null?void 0:a.schema)==null?void 0:m.properties)&&Object.keys(a.schema.properties).length>0,x=(I=a==null?void 0:a.schema)==null?void 0:I.jsonSchema,_=(a==null?void 0:a.examples)&&a.examples.length>0;return u.jsxs(u.Fragment,{children:[u.jsxs(Ht,{children:[u.jsxs(Wt,{className:"flex items-center gap-2",children:[u.jsx(Wm,{className:"size-5 text-warning"}),"Plugins",u.jsxs(Jt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(hn,{children:[e.length," plugin",e.length!==1?"s":""," discovered in your project"]})]}),u.jsxs("div",{className:"mt-3 flex gap-0 h-[600px] border rounded-lg overflow-hidden",children:[u.jsx("div",{className:"w-[240px] flex-none border-r bg-muted/30",children:u.jsx(Zr,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(p).map(([E,w])=>w.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[v(E),g(E)]}),u.jsx("div",{className:"space-y-0.5",children:w.map(N=>{const O=r(N.name),K=(a==null?void 0:a.name)===N.name;return u.jsxs("button",{onClick:()=>o(N),className:H("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",K?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:H("size-1.5 rounded-full flex-none transition-colors",O?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:N.name})]},N.name)})})]},E))})})}),a?u.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[u.jsxs("div",{className:"flex-none px-5 py-4 border-b bg-background",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2.5",children:[u.jsx("h3",{className:"text-base font-semibold truncate",children:a.name}),a.version&&u.jsxs(Jt,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",a.version]})]}),a.description&&u.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:a.description})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-none pt-0.5",children:[u.jsx("span",{className:"text-xs text-muted-foreground",children:r(a.name)?"On":"Off"}),u.jsx(Xa,{checked:r(a.name),onCheckedChange:()=>n(a),disabled:s,"aria-label":`Toggle ${a.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[v(a.location),u.jsx("span",{children:g(a.location)}),u.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),u.jsx("span",{className:"font-mono truncate",children:a.relativePath})]})]}),u.jsxs("div",{className:"flex-none px-5 pt-3 pb-0 flex gap-1 border-b bg-background",children:[S&&u.jsx("button",{onClick:()=>d("properties"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Oo,{className:"size-3.5"}),"Properties"]})}),x&&u.jsx("button",{onClick:()=>d("schema"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(qm,{className:"size-3.5"}),"Schema"]})}),_&&u.jsx("button",{onClick:()=>d("examples"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Gm,{className:"size-3.5"}),"Examples",u.jsx(Jt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:a.examples.length})]})})]}),u.jsx(Zr,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[f==="properties"&&S&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([E,w])=>u.jsx(Xx,{name:E,prop:w},E))}),f==="schema"&&x&&u.jsx(Zi,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),f==="examples"&&_&&a.examples.map((E,w)=>u.jsxs("div",{className:H(w>0&&"mt-4 pt-4 border-t"),children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[E.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:E.title}),!E.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),u.jsx(Ee,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>h(E,w),children:l===w?u.jsxs(u.Fragment,{children:[u.jsx(Km,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(os,{className:"size-3 mr-1"}),"Copy"]})})]}),E.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:E.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(E.props,null,2)})]},w)),!S&&!x&&!_&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(Oo,{className:"size-10 mx-auto mb-3 opacity-20"}),u.jsx("p",{className:"text-sm",children:"No schema or examples available for this plugin"})]})]})})]}):u.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:u.jsx("p",{className:"text-sm",children:"Select a plugin to view details"})})]})]})}function Xx({name:e,prop:t}){var a;const[n,r]=b.useState(!1),i=t.description||t.enum||t.default!==void 0||t.items||t.properties,s=t.type||(t.enum?"enum":t.oneOf?"oneOf":"—");return u.jsxs("div",{className:"rounded-md border",children:[u.jsxs("button",{onClick:()=>i&&r(!n),className:H("w-full text-left flex items-center gap-2 px-3 py-2 text-sm",i&&"cursor-pointer hover:bg-muted/50"),children:[i?n?u.jsx(ti,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(ri,{className:"size-3 text-muted-foreground flex-none"}):u.jsx("span",{className:"size-3 flex-none"}),u.jsx("span",{className:"font-mono font-medium text-xs",children:e}),u.jsx(Jt,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&u.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),u.jsx("span",{className:"flex-1"}),t.default!==void 0&&u.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&u.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&u.jsx("p",{children:t.description}),t.enum&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((o,l)=>u.jsxs("span",{children:[l>0&&", ",u.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(o)})]},l))]}),((a=t.items)==null?void 0:a.type)&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const Qx=zm,ey=Am,ty=Pm,ny={current:"Current directory",downstream:"Project"};function Os({id:e,label:t,count:n,open:r,onToggle:i,children:s}){return u.jsxs(Qx,{open:r,children:[u.jsxs(ey,{onClick:()=>i(e),className:H("flex h-7 w-full cursor-pointer items-center gap-1.5 rounded-sm px-1","text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(ri,{className:H("size-3 shrink-0 transition-transform duration-150 ease-out",r&&"rotate-90")}),u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:t}),u.jsx("span",{className:"ml-auto text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:n})]}),u.jsx(ty,{children:u.jsx("div",{className:"border-sidebar-border/70 mt-0.5 ml-[13px] border-l pl-1",children:s})})]})}function Ko({location:e}){return u.jsx("div",{className:"px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:ny[e]??e})}function Yo({name:e,subtitle:t,added:n,query:r,onSelect:i}){return u.jsxs("button",{type:"button",onClick:i,title:t?`${e} — ${t}`:e,"aria-label":n?`Open ${e}`:`Add ${e} to workspace`,className:H("group/row flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","text-sidebar-foreground/70"),children:[u.jsx("span",{className:"truncate",children:u.jsx(Ka,{text:e,query:r})}),n?u.jsx("span",{className:"ml-auto shrink-0 text-[10px] tracking-[0.06em] text-sidebar-foreground/65 uppercase",children:"Open"}):u.jsx(Xt,{"aria-hidden":!0,className:"ml-auto size-3.5 shrink-0 text-sidebar-foreground/45 opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100"})]})}function ry({documents:e,themes:t,plugins:n,openNames:r,query:i,expandedGroups:s,onToggleGroup:a,onQuickAdd:o,onShowPluginDetails:l,isPluginSelected:c,onTogglePlugin:f,isApplyingPlugins:d,selectedPluginCount:p}){const h=x=>i?!0:s.has(x),g=b.useMemo(()=>Xo(e),[e]),v=b.useMemo(()=>Xo(t),[t]);return e.length>0||t.length>0||n.length>0?u.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.length>0&&u.jsx(Os,{id:"library-documents",label:"Project documents",count:e.length,open:h("library-documents"),onToggle:a,children:g.map(([x,_])=>u.jsxs(_e.Fragment,{children:[g.length>1&&u.jsx(Ko,{location:x}),_.map(m=>u.jsx(Yo,{name:m.name,subtitle:m.title,added:r.has(m.name),query:i,onSelect:()=>o(m.name,!1)},m.path||m.name))]},x))}),t.length>0&&u.jsx(Os,{id:"library-themes",label:"Project themes",count:t.length,open:h("library-themes"),onToggle:a,children:v.map(([x,_])=>u.jsxs(_e.Fragment,{children:[v.length>1&&u.jsx(Ko,{location:x}),_.map(m=>u.jsx(Yo,{name:m.name,subtitle:m.description,added:r.has(m.name),query:i,onSelect:()=>o(m.name,!0)},m.path||m.name))]},x))}),n.length>0&&u.jsx(Os,{id:"library-plugins",label:"Plugins",count:`${p}/${n.length}`,open:h("library-plugins"),onToggle:a,children:n.map(x=>{const _=c(x.name),m=`plugin-switch-${x.filePath||x.name}`;return u.jsxs("div",{title:x.description?`${x.name} — ${x.description}`:x.name,className:H("group/row flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2","transition-colors hover:bg-sidebar-accent/60"),children:[u.jsx("label",{htmlFor:m,className:H("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",_?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(Ka,{text:x.name,query:i})})}),u.jsx(Ft,{"aria-label":`Details for ${x.name}`,onClick:I=>{I.stopPropagation(),l(x.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(Kc,{})}),u.jsx(Xa,{id:m,checked:_,onCheckedChange:()=>f(x),disabled:d,className:"shrink-0","aria-label":`Toggle ${x.name} plugin`})]},x.filePath||x.name)})})]}):null}function Xo(e){const t=["current","downstream"],n=new Map;return e.forEach(r=>{const i=n.get(r.location);i?i.push(r):n.set(r.location,[r])}),[...n.entries()].sort(([r],[i])=>t.indexOf(r)-t.indexOf(i))}function Wd({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:H("pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground","[[data-slot=tooltip-content]_&]:bg-primary-foreground/20 [[data-slot=tooltip-content]_&]:text-primary-foreground",t),children:e})}function iy({children:e,className:t}){return u.jsx("span",{className:H("inline-flex items-center gap-0.5",t),children:e})}const gi=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function Br({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return gi?"⌘":"Ctrl";case"shift":return gi?"⇧":"Shift";case"alt":return gi?"⌥":"Alt";case"ctrl":return gi?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(iy,{className:t,children:r.map((i,s)=>u.jsx(Wd,{children:i},s))})}function sy({className:e}={}){const{theme:t,setTheme:n}=Uc(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=b.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(Ee,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Qm,{className:"hidden dark:block"}),u.jsx(eg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:"Toggle theme"})})]})}function ay({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o}=Oe(rd(Z=>({documents:Z.documents,documentTypes:Z.documentTypes,createDocument:Z.createDocument,openDocument:Z.openDocument}))),l=ca(Z=>Z.updateTheme),c=ca(Z=>Z.removeTheme),f=b.useContext(nd),[d,p]=b.useState(!1),[h,g]=b.useState(!1),[v,S]=b.useState(!1),[x,_]=b.useState(null),m=Dt(Z=>Z.togglePlugin),I=Dt(Z=>Z.isPluginSelected),E=Dt(Z=>Z.selectedPlugins),w=Dt(Z=>Z.isApplyingPlugins),[N,O]=b.useState(!1),[K,C]=b.useState(new Set(["library-documents"])),[T,A]=b.useState(""),F=b.useRef(null),{toast:R}=fr(),L=i.filter(Z=>s[Z.name]!=="application/json+theme"),P=i.filter(Z=>s[Z.name]==="application/json+theme"),V=b.useCallback(()=>{p(!1)},[]),U=b.useCallback(()=>{g(!1)},[]),se=b.useRef(new Map);b.useEffect(()=>{const Z=se.current,ke=new Map;P.forEach(me=>{ke.set(me.name,me.text),Z.get(me.name)!==me.text&&l(me.name,me.text)}),Z.forEach((me,De)=>{ke.has(De)||c(De)}),se.current=ke},[P,l,c]);const k=b.useRef(!1);b.useEffect(()=>{if(k.current||!f)return;k.current=!0;const Z=new Set(P.map(me=>me.name));Object.keys(f.getState().customThemes).forEach(me=>{Z.has(me)||c(me)})},[P,c,f]);const le=b.useCallback(Z=>{C(ke=>{const me=new Set(ke);return me.has(Z)?me.delete(Z):me.add(Z),me})},[]),{resolvedTheme:q}=Uc(),y=q==="dark"?"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo-white.svg?updatedAt=1751359555877":"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo.svg?updatedAt=1749817149276",W=b.useCallback(async(Z,ke)=>{if(i.some(me=>me.name===Z)){o(Z);return}try{const me=await fetch(`/api/discovery/${ke?"themes":"documents"}/${encodeURIComponent(Z)}/content`);if(!me.ok)throw new Error(me.statusText);const De=await me.text(),j=JSON.parse(De);a(Z,JSON.stringify(j,null,2)),o(Z),R({title:`Added ${ke?"theme":"document"}: ${Z}`})}catch{R({title:"Failed to load",description:`Could not load ${Z}`,variant:"destructive"})}},[i,a,o,R]);b.useEffect(()=>{if(n)return;const Z=ke=>{var j,z,M,re,ee;if(ke.key!=="/"||ke.metaKey||ke.ctrlKey||ke.altKey)return;const me=ke.target,De=(j=me==null?void 0:me.tagName)==null?void 0:j.toLowerCase();De==="input"||De==="textarea"||De==="select"||me!=null&&me.isContentEditable||(z=me==null?void 0:me.closest)!=null&&z.call(me,".monaco-editor")||(M=F.current)!=null&&M.closest('[aria-hidden="true"], [inert]')||(ke.preventDefault(),(re=F.current)==null||re.focus(),(ee=F.current)==null||ee.select())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[n]);const B=T.trim(),ie=b.useMemo(()=>new Set(i.map(Z=>Z.name)),[i]),te=b.useMemo(()=>L.filter(Z=>sn(Z.name,B)),[L,B]),X=b.useMemo(()=>P.filter(Z=>sn(Z.name,B)),[P,B]),fe=b.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(Z=>sn(Z.name,B)||sn(Z.title??"",B)),[e,B]),be=b.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(Z=>sn(Z.name,B)||sn(Z.description??"",B)),[e,B]),ne=b.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(Z=>sn(Z.name,B)||sn(Z.description??"",B)),[e,B]),de=B.length>0&&te.length===0&&X.length===0&&fe.length===0&&be.length===0&&ne.length===0,ue=H("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(Zd,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(ga,{className:H("gap-0 p-1.5",ue),children:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Yc,{})})}),u.jsxs(Ke,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(Br,{shortcut:"mod+b"})]})]})}),u.jsxs(xa,{className:H("gap-2 px-1 py-1",ue),children:[u.jsxs(Cr,{className:"items-center gap-0.5",children:[L.map(Z=>u.jsx(mi,{document:Z,compact:!0},Z.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"right",children:"New document"})]})]}),u.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),u.jsxs(Cr,{className:"items-center gap-0.5",children:[P.map(Z=>u.jsx(mi,{document:Z,compact:!0},Z.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{className:"size-7","aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(ga,{className:H("gap-0 p-2",ue),children:[u.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[u.jsx("a",{href:"/","aria-label":"JSON to Office home",className:"focus-visible:ring-sidebar-ring flex items-center rounded-sm pl-1 focus-visible:ring-1 focus-visible:outline-none",children:u.jsx("img",{src:y,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(tg,{})})}),u.jsxs(Ke,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(Br,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(ng,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),u.jsx("input",{ref:F,type:"text",value:T,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:Z=>A(Z.target.value),onKeyDown:Z=>{Z.key==="Escape"&&(Z.preventDefault(),A(""),Z.currentTarget.blur())},className:H("border-sidebar-border/70 bg-sidebar-accent/40 h-7 w-full rounded-sm border","pr-7 pl-7 text-[13px] text-sidebar-foreground transition-colors","placeholder:text-sidebar-foreground/60","focus-visible:border-sidebar-ring focus-visible:bg-sidebar-accent/60","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none")}),B?u.jsx(Ft,{"aria-label":"Clear filter",onClick:()=>{var Z;A(""),(Z=F.current)==null||Z.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(fn,{})}):u.jsx(Wd,{className:"absolute top-1/2 right-1.5 h-4 min-w-4 -translate-y-1/2 bg-transparent px-0 text-[10px] text-sidebar-foreground/65",children:"/"})]})]}),u.jsx(xa,{className:H("gap-0 px-2 pb-2",ue),children:de?u.jsxs("div",{className:"px-1 py-6 text-center",children:[u.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",B,"”"]}),u.jsx("button",{type:"button",onClick:()=>{var Z;A(""),(Z=F.current)==null||Z.focus()},className:"text-sidebar-foreground/70 hover:text-sidebar-foreground focus-visible:ring-sidebar-ring mt-1 cursor-pointer rounded-sm text-[12px] underline-offset-2 hover:underline focus-visible:ring-1 focus-visible:outline-none",children:"Clear filter"})]}):u.jsxs(u.Fragment,{children:[(te.length>0||!B)&&u.jsxs("section",{children:[u.jsx(Wo,{count:(B?te.length:L.length)||void 0,actions:u.jsxs(u.Fragment,{children:[yt==="docx"&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"Compare documents",disabled:L.length<2,onClick:()=>O(!0),children:u.jsx(Hc,{})})}),u.jsx(Ke,{side:"bottom",children:L.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),u.jsx(Cr,{className:"gap-0.5",children:te.length>0?te.map(Z=>u.jsx(mi,{document:Z,query:B},Z.name)):u.jsx(Go,{icon:Xt,label:"New document",onClick:()=>p(!0)})})]}),(X.length>0||!B)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Wo,{count:(B?X.length:P.length)||void 0,actions:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"bottom",children:"New theme"})]}),children:"Themes"}),u.jsx(Cr,{className:"gap-0.5",children:X.length>0?X.map(Z=>u.jsx(mi,{document:Z,query:B},Z.name)):u.jsx(Go,{icon:Xt,label:"New theme",onClick:()=>g(!0)})})]}),(fe.length>0||be.length>0||ne.length>0)&&u.jsx("div",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:u.jsx(ry,{documents:fe,themes:be,plugins:ne,openNames:ie,query:B,expandedGroups:K,onToggleGroup:le,onQuickAdd:W,onShowPluginDetails:Z=>{_(Z),S(!0)},isPluginSelected:I,onTogglePlugin:m,isApplyingPlugins:w,selectedPluginCount:E.size})})]})})]}),u.jsx(Bd,{className:H("border-sidebar-border/70 gap-0 border-t p-1.5",ue),children:u.jsx("div",{className:H("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(sy,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),u.jsx(It,{open:d,onOpenChange:p,children:u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Mi,{mode:"create",shouldReset:!d,postSubmit:V,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(It,{open:h,onOpenChange:g,children:u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Mi,{mode:"create",shouldReset:!h,postSubmit:U,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(It,{open:v,onOpenChange:Z=>{S(Z),Z||_(null)},children:u.jsx(St,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(Yx,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:x})})}),u.jsx(Ag,{open:N,onOpenChange:O})]})}const Qo=b.memo(ay),oy=b.lazy(()=>Jc(()=>import("./editor-e3ONSdDx.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function el(){return u.jsx(b.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(en,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(oy,{})})}const ly=b.lazy(()=>Jc(()=>import("./preview-_aGms4Sr.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function tl(){return u.jsx(b.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(en,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(ly,{})})}const{createElement:ar,createContext:uy,forwardRef:qd,useCallback:pt,useContext:Gd,useEffect:Nn,useImperativeHandle:Kd,useLayoutEffect:cy,useMemo:dy,useRef:xt,useState:Qn}=lc,nl=lc[`useId${Math.random()}`.slice(0,5)],fy=cy,hs=uy(null);hs.displayName="PanelGroupContext";const En=fy,py=typeof nl=="function"?nl:()=>null;let hy=0;function Qa(e=null){const t=py(),n=xt(e||t||null);return n.current===null&&(n.current=""+hy++),e??n.current}function Yd({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:f,onResize:d,order:p,style:h,tagName:g="div",...v}){const S=Gd(hs);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:x,expandPanel:_,getPanelSize:m,getPanelStyle:I,groupId:E,isPanelCollapsed:w,reevaluatePanelConstraints:N,registerPanel:O,resizePanel:K,unregisterPanel:C}=S,T=Qa(a),A=xt({callbacks:{onCollapse:c,onExpand:f,onResize:d},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:T,idIsFromProps:a!==void 0,order:p});xt({didLogMissingDefaultSizeWarning:!1}),En(()=>{const{callbacks:R,constraints:L}=A.current,P={...L};A.current.id=T,A.current.idIsFromProps=a!==void 0,A.current.order=p,R.onCollapse=c,R.onExpand=f,R.onResize=d,L.collapsedSize=n,L.collapsible=r,L.defaultSize=i,L.maxSize=o,L.minSize=l,(P.collapsedSize!==L.collapsedSize||P.collapsible!==L.collapsible||P.maxSize!==L.maxSize||P.minSize!==L.minSize)&&N(A.current,P)}),En(()=>{const R=A.current;return O(R),()=>{C(R)}},[p,T,O,C]),Kd(s,()=>({collapse:()=>{x(A.current)},expand:R=>{_(A.current,R)},getId(){return T},getSize(){return m(A.current)},isCollapsed(){return w(A.current)},isExpanded(){return!w(A.current)},resize:R=>{K(A.current,R)}}),[x,_,m,w,T,K]);const F=I(A.current,i);return ar(g,{...v,children:e,className:t,id:a,style:{...F,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":E,"data-panel-id":T,"data-panel-size":parseFloat(""+F.flexGrow).toFixed(1)})}const Xd=qd((e,t)=>ar(Yd,{...e,forwardedRef:t}));Yd.displayName="Panel";Xd.displayName="forwardRef(Panel)";let ya=null,Cn=null;function my(e,t){if(t){const n=(t&rf)!==0,r=(t&sf)!==0,i=(t&af)!==0,s=(t&of)!==0;if(n)return i?"se-resize":s?"ne-resize":"e-resize";if(r)return i?"sw-resize":s?"nw-resize":"w-resize";if(i)return"s-resize";if(s)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function gy(){Cn!==null&&(document.head.removeChild(Cn),ya=null,Cn=null)}function Ds(e,t){const n=my(e,t);ya!==n&&(ya=n,Cn===null&&(Cn=document.createElement("style"),document.head.appendChild(Cn)),Cn.innerHTML=`*{cursor: ${n}!important;}`)}function Qd(e){return e.type==="keydown"}function ef(e){return e.type.startsWith("pointer")}function tf(e){return e.type.startsWith("mouse")}function ms(e){if(ef(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(tf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function xy(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function yy(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function by(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:sl(e),b:sl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ce(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:il(rl(n.a)),b:il(rl(n.b))};if(i.a===i.b){const s=r.childNodes,a={a:n.a.at(-1),b:n.b.at(-1)};let o=s.length;for(;o--;){const l=s[o];if(l===a.a)return 1;if(l===a.b)return-1}}return Math.sign(i.a-i.b)}const vy=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function wy(e){var t;const n=getComputedStyle((t=nf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function ky(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||wy(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||vy.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function rl(e){let t=e.length;for(;t--;){const n=e[t];if(Ce(n,"Missing node"),ky(n))return n}return null}function il(e){return e&&Number(getComputedStyle(e).zIndex)||0}function sl(e){const t=[];for(;e;)t.push(e),e=nf(e);return t}function nf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const rf=1,sf=2,af=4,of=8,Sy=xy()==="coarse";let Rt=[],er=!1,cn=new Map,gs=new Map;const Vr=new Set;function _y(e,t,n,r,i){var s;const{ownerDocument:a}=t,o={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=cn.get(a))!==null&&s!==void 0?s:0;return cn.set(a,l+1),Vr.add(o),Bi(),function(){var f;gs.delete(e),Vr.delete(o);const d=(f=cn.get(a))!==null&&f!==void 0?f:1;if(cn.set(a,d-1),Bi(),d===1&&cn.delete(a),Rt.includes(o)){const p=Rt.indexOf(o);p>=0&&Rt.splice(p,1),to(),i("up",!0,null)}}}function al(e){const{target:t}=e,{x:n,y:r}=ms(e);er=!0,eo({target:t,x:n,y:r}),Bi(),Rt.length>0&&(Vi("down",e),e.preventDefault(),e.stopPropagation())}function vr(e){const{x:t,y:n}=ms(e);if(er&&e.buttons===0&&(er=!1,Vi("up",e)),!er){const{target:r}=e;eo({target:r,x:t,y:n})}Vi("move",e),to(),Rt.length>0&&e.preventDefault()}function $n(e){const{target:t}=e,{x:n,y:r}=ms(e);gs.clear(),er=!1,Rt.length>0&&e.preventDefault(),Vi("up",e),eo({target:t,x:n,y:r}),to(),Bi()}function eo({target:e,x:t,y:n}){Rt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Vr.forEach(i=>{const{element:s,hitAreaMargins:a}=i,o=s.getBoundingClientRect(),{bottom:l,left:c,right:f,top:d}=o,p=Sy?a.coarse:a.fine;if(t>=c-p&&t<=f+p&&n>=d-p&&n<=l+p){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&by(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(yy(g.getBoundingClientRect(),o)){v=!0;break}g=g.parentElement}if(v)return}Rt.push(i)}})}function Rs(e,t){gs.set(e,t)}function to(){let e=!1,t=!1;Rt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;gs.forEach(r=>{n|=r}),e&&t?Ds("intersection",n):e?Ds("horizontal",n):t?Ds("vertical",n):gy()}function Bi(){cn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",$n),n.removeEventListener("pointerdown",al),n.removeEventListener("pointerleave",vr),n.removeEventListener("pointermove",vr)}),window.removeEventListener("pointerup",$n),window.removeEventListener("pointercancel",$n),Vr.size>0&&(er?(Rt.length>0&&cn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",$n),n.addEventListener("pointerleave",vr),n.addEventListener("pointermove",vr))}),window.addEventListener("pointerup",$n),window.addEventListener("pointercancel",$n)):cn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",al,{capture:!0}),n.addEventListener("pointermove",vr))}))}function Vi(e,t){Vr.forEach(n=>{const{setResizeHandlerState:r}=n,i=Rt.includes(n);r(e,i,t)})}function jy(){const[e,t]=Qn(0);return pt(()=>t(n=>n+1),[])}function Ce(e,t){if(!e)throw console.error(t),Error(t)}const no=10;function zn(e,t,n=no){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function tn(e,t,n=no){return zn(e,t,n)===0}function kt(e,t,n){return zn(e,t,n)===0}function Cy(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],s=t[r];if(!kt(i,s,n))return!1}return!0}function Gn({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ce(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:a=100,minSize:o=0}=r;if(zn(n,o)<0)if(s){const l=(i+o)/2;zn(n,l)<0?n=i:n=o}else n=o;return n=Math.min(a,n),n=parseFloat(n.toFixed(no)),n}function Nr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(kt(e,0))return t;const a=[...t],[o,l]=r;Ce(o!=null,"Invalid first pivot index"),Ce(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?l:o,p=n[d];Ce(p,`Panel constraints not found for index ${d}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[d];if(Ce(S!=null,`Previous layout not found for panel index ${d}`),kt(S,h)){const x=v-S;zn(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}{const d=e<0?o:l,p=n[d];Ce(p,`No panel constraints found for index ${d}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[d];if(Ce(S!=null,`Previous layout not found for panel index ${d}`),kt(S,v)){const x=S-h;zn(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}}{const d=e<0?1:-1;let p=e<0?l:o,h=0;for(;;){const v=t[p];Ce(v!=null,`Previous layout not found for panel index ${p}`);const x=Gn({panelConstraints:n,panelIndex:p,size:100})-v;if(h+=x,p+=d,p<0||p>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-g:g}{let p=e<0?o:l;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),g=t[p];Ce(g!=null,`Previous layout not found for panel index ${p}`);const v=g-h,S=Gn({panelConstraints:n,panelIndex:p,size:v});if(!kt(g,S)&&(c+=g-S,a[p]=S,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(Cy(i,a))return i;{const d=e<0?l:o,p=t[d];Ce(p!=null,`Previous layout not found for panel index ${d}`);const h=p+c,g=Gn({panelConstraints:n,panelIndex:d,size:h});if(a[d]=g,!kt(g,h)){let v=h-g,x=e<0?l:o;for(;x>=0&&x<n.length;){const _=a[x];Ce(_!=null,`Previous layout not found for panel index ${x}`);const m=_+v,I=Gn({panelConstraints:n,panelIndex:x,size:m});if(kt(_,I)||(v-=I-_,a[x]=I),kt(v,0))break;e>0?x--:x++}}}const f=a.reduce((d,p)=>p+d,0);return kt(f,100)?a:i}function Ny({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,a=0;const o=n[0];Ce(o!=null,"No pivot index found"),t.forEach((d,p)=>{const{constraints:h}=d,{maxSize:g=100,minSize:v=0}=h;p===o?(r=v,i=g):(s+=v,a+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-a),f=e[o];return{valueMax:l,valueMin:c,valueNow:f}}function Ur(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function lf(e,t,n=document){const i=Ur(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function uf(e,t,n){const r=lf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function cf(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function xs(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function Ey(e,t,n,r=document){var i,s,a,o;const l=xs(t,r),c=Ur(e,r),f=l?c.indexOf(l):-1,d=(i=(s=n[f])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,p=(a=(o=n[f+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[d,p]}function Iy({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:a}){xt({didWarnAboutMissingResizeHandle:!1}),En(()=>{if(!s)return;const o=Ur(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:f,valueNow:d}=Ny({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=o[l];if(p!=null){const h=i[l];Ce(h,`No panel data found for index "${l}"`),p.setAttribute("aria-controls",h.id),p.setAttribute("aria-valuemax",""+Math.round(c)),p.setAttribute("aria-valuemin",""+Math.round(f)),p.setAttribute("aria-valuenow",d!=null?""+Math.round(d):"")}}return()=>{o.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),Nn(()=>{if(!s)return;const o=t.current;Ce(o,"Eager values not found");const{panelDataArray:l}=o,c=cf(n,s);Ce(c!=null,`No group found for id "${n}"`);const f=Ur(n,s);Ce(f,`No resize handles found for group id "${n}"`);const d=f.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");Ce(h,"Resize handle element has no handle id attribute");const[g,v]=Ey(n,h,l,s);if(g==null||v==null)return()=>{};const S=x=>{if(!x.defaultPrevented)switch(x.key){case"Enter":{x.preventDefault();const _=l.findIndex(m=>m.id===g);if(_>=0){const m=l[_];Ce(m,`No panel data found for index ${_}`);const I=r[_],{collapsedSize:E=0,collapsible:w,minSize:N=0}=m.constraints;if(I!=null&&w){const O=Nr({delta:kt(I,E)?N-E:E-I,initialLayout:r,panelConstraints:l.map(K=>K.constraints),pivotIndices:uf(n,h,s),prevLayout:r,trigger:"keyboard"});r!==O&&a(O)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{d.forEach(p=>p())}},[s,e,t,n,r,i,a])}function ol(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function df(e,t){const n=e==="horizontal",{x:r,y:i}=ms(t);return n?r:i}function Ty(e,t,n,r,i){const s=n==="horizontal",a=xs(t,i);Ce(a,`No resize handle element found for id "${t}"`);const o=a.getAttribute("data-panel-group-id");Ce(o,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=df(n,e),f=cf(o,i);Ce(f,`No group element found for id "${o}"`);const d=f.getBoundingClientRect(),p=s?d.width:d.height;return(c-l)/p*100}function zy(e,t,n,r,i,s){if(Qd(e)){const a=n==="horizontal";let o=0;e.shiftKey?o=100:i!=null?o=i:o=10;let l=0;switch(e.key){case"ArrowDown":l=a?0:o;break;case"ArrowLeft":l=a?-o:0;break;case"ArrowRight":l=a?o:0;break;case"ArrowUp":l=a?0:-o;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:Ty(e,t,n,r,s)}function Ay({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,i=100;for(let s=0;s<e.length;s++){const a=n[s];Ce(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;o!=null&&(r++,t[s]=o,i-=o)}for(let s=0;s<e.length;s++){const a=n[s];Ce(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;if(o!=null)continue;const l=e.length-r,c=i/l;r++,t[s]=c,i-=c}return t}function Fn(e,t,n){t.forEach((r,i)=>{const s=e[i];Ce(s,`Panel data not found for index ${i}`);const{callbacks:a,constraints:o,id:l}=s,{collapsedSize:c=0,collapsible:f}=o,d=n[l];if(d==null||r!==d){n[l]=r;const{onCollapse:p,onExpand:h,onResize:g}=a;g&&g(r,d),f&&(p||h)&&(h&&(d==null||tn(d,c))&&!tn(r,c)&&h(),p&&(d==null||!tn(d,c))&&tn(r,c)&&p())}})}function xi(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function Py({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const a=n[i];let o;return a==null?o=e!=null?e.toPrecision(s):"1":r.length===1?o="1":o=a.toPrecision(s),{flexBasis:0,flexGrow:o,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function Oy(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function ll(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function ff(e){return`react-resizable-panels:${e}`}function pf(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:i,order:s}=t;return i?r:s?`${s}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function hf(e,t){try{const n=ff(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Dy(e,t,n){var r,i;const s=(r=hf(e,n))!==null&&r!==void 0?r:{},a=pf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Ry(e,t,n,r,i){var s;const a=ff(e),o=pf(t),l=(s=hf(e,i))!==null&&s!==void 0?s:{};l[o]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(a,JSON.stringify(l))}catch(c){console.error(c)}}function ul({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,a)=>s+a,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!kt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const a=n[s];Ce(a!=null,`No layout data found for index ${s}`);const o=100/r*a;n[s]=o}let i=0;for(let s=0;s<t.length;s++){const a=n[s];Ce(a!=null,`No layout data found for index ${s}`);const o=Gn({panelConstraints:t,panelIndex:s,size:a});a!=o&&(i+=a-o,n[s]=o)}if(!kt(i,0))for(let s=0;s<t.length;s++){const a=n[s];Ce(a!=null,`No layout data found for index ${s}`);const o=a+i,l=Gn({panelConstraints:t,panelIndex:s,size:o});if(a!==l&&(i-=l-a,n[s]=l,kt(i,0)))break}return n}const My=100,Er={getItem:e=>(ll(Er),Er.getItem(e)),setItem:(e,t)=>{ll(Er),Er.setItem(e,t)}},cl={};function mf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:a=null,keyboardResizeBy:o=null,storage:l=Er,style:c,tagName:f="div",...d}){const p=Qa(s),h=xt(null),[g,v]=Qn(null),[S,x]=Qn([]),_=jy(),m=xt({}),I=xt(new Map),E=xt(0),w=xt({autoSaveId:e,direction:r,dragState:g,id:p,keyboardResizeBy:o,onLayout:a,storage:l}),N=xt({layout:S,panelDataArray:[],panelDataArrayChanged:!1});xt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),Kd(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:y}=N.current;return y},setLayout:y=>{const{onLayout:W}=w.current,{layout:B,panelDataArray:ie}=N.current,te=ul({layout:y,panelConstraints:ie.map(X=>X.constraints)});ol(B,te)||(x(te),N.current.layout=te,W&&W(te),Fn(ie,te,m.current))}}),[]),En(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=g,w.current.id=p,w.current.onLayout=a,w.current.storage=l}),Iy({committedValuesRef:w,eagerValuesRef:N,groupId:p,layout:S,panelDataArray:N.current.panelDataArray,setLayout:x,panelGroupElement:h.current}),Nn(()=>{const{panelDataArray:y}=N.current;if(e){if(S.length===0||S.length!==y.length)return;let W=cl[e];W==null&&(W=Oy(Ry,My),cl[e]=W);const B=[...y],ie=new Map(I.current);W(e,B,ie,S,l)}},[e,S,l]),Nn(()=>{});const O=pt(y=>{const{onLayout:W}=w.current,{layout:B,panelDataArray:ie}=N.current;if(y.constraints.collapsible){const te=ie.map(ne=>ne.constraints),{collapsedSize:X=0,panelSize:fe,pivotIndices:be}=vn(ie,y,B);if(Ce(fe!=null,`Panel size not found for panel "${y.id}"`),!tn(fe,X)){I.current.set(y.id,fe);const de=Jn(ie,y)===ie.length-1?fe-X:X-fe,ue=Nr({delta:de,initialLayout:B,panelConstraints:te,pivotIndices:be,prevLayout:B,trigger:"imperative-api"});xi(B,ue)||(x(ue),N.current.layout=ue,W&&W(ue),Fn(ie,ue,m.current))}}},[]),K=pt((y,W)=>{const{onLayout:B}=w.current,{layout:ie,panelDataArray:te}=N.current;if(y.constraints.collapsible){const X=te.map(Z=>Z.constraints),{collapsedSize:fe=0,panelSize:be=0,minSize:ne=0,pivotIndices:de}=vn(te,y,ie),ue=W??ne;if(tn(be,fe)){const Z=I.current.get(y.id),ke=Z!=null&&Z>=ue?Z:ue,De=Jn(te,y)===te.length-1?be-ke:ke-be,j=Nr({delta:De,initialLayout:ie,panelConstraints:X,pivotIndices:de,prevLayout:ie,trigger:"imperative-api"});xi(ie,j)||(x(j),N.current.layout=j,B&&B(j),Fn(te,j,m.current))}}},[]),C=pt(y=>{const{layout:W,panelDataArray:B}=N.current,{panelSize:ie}=vn(B,y,W);return Ce(ie!=null,`Panel size not found for panel "${y.id}"`),ie},[]),T=pt((y,W)=>{const{panelDataArray:B}=N.current,ie=Jn(B,y);return Py({defaultSize:W,dragState:g,layout:S,panelData:B,panelIndex:ie})},[g,S]),A=pt(y=>{const{layout:W,panelDataArray:B}=N.current,{collapsedSize:ie=0,collapsible:te,panelSize:X}=vn(B,y,W);return Ce(X!=null,`Panel size not found for panel "${y.id}"`),te===!0&&tn(X,ie)},[]),F=pt(y=>{const{layout:W,panelDataArray:B}=N.current,{collapsedSize:ie=0,collapsible:te,panelSize:X}=vn(B,y,W);return Ce(X!=null,`Panel size not found for panel "${y.id}"`),!te||zn(X,ie)>0},[]),R=pt(y=>{const{panelDataArray:W}=N.current;W.push(y),W.sort((B,ie)=>{const te=B.order,X=ie.order;return te==null&&X==null?0:te==null?-1:X==null?1:te-X}),N.current.panelDataArrayChanged=!0,_()},[_]);En(()=>{if(N.current.panelDataArrayChanged){N.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:W,storage:B}=w.current,{layout:ie,panelDataArray:te}=N.current;let X=null;if(y){const be=Dy(y,te,B);be&&(I.current=new Map(Object.entries(be.expandToSizes)),X=be.layout)}X==null&&(X=Ay({panelDataArray:te}));const fe=ul({layout:X,panelConstraints:te.map(be=>be.constraints)});ol(ie,fe)||(x(fe),N.current.layout=fe,W&&W(fe),Fn(te,fe,m.current))}}),En(()=>{const y=N.current;return()=>{y.layout=[]}},[]);const L=pt(y=>{let W=!1;const B=h.current;return B&&window.getComputedStyle(B,null).getPropertyValue("direction")==="rtl"&&(W=!0),function(te){te.preventDefault();const X=h.current;if(!X)return()=>null;const{direction:fe,dragState:be,id:ne,keyboardResizeBy:de,onLayout:ue}=w.current,{layout:Z,panelDataArray:ke}=N.current,{initialLayout:me}=be??{},De=uf(ne,y,X);let j=zy(te,y,fe,be,de,X);const z=fe==="horizontal";z&&W&&(j=-j);const M=ke.map(Q=>Q.constraints),re=Nr({delta:j,initialLayout:me??Z,panelConstraints:M,pivotIndices:De,prevLayout:Z,trigger:Qd(te)?"keyboard":"mouse-or-touch"}),ee=!xi(Z,re);(ef(te)||tf(te))&&E.current!=j&&(E.current=j,!ee&&j!==0?z?Rs(y,j<0?rf:sf):Rs(y,j<0?af:of):Rs(y,0)),ee&&(x(re),N.current.layout=re,ue&&ue(re),Fn(ke,re,m.current))}},[]),P=pt((y,W)=>{const{onLayout:B}=w.current,{layout:ie,panelDataArray:te}=N.current,X=te.map(Z=>Z.constraints),{panelSize:fe,pivotIndices:be}=vn(te,y,ie);Ce(fe!=null,`Panel size not found for panel "${y.id}"`);const de=Jn(te,y)===te.length-1?fe-W:W-fe,ue=Nr({delta:de,initialLayout:ie,panelConstraints:X,pivotIndices:be,prevLayout:ie,trigger:"imperative-api"});xi(ie,ue)||(x(ue),N.current.layout=ue,B&&B(ue),Fn(te,ue,m.current))},[]),V=pt((y,W)=>{const{layout:B,panelDataArray:ie}=N.current,{collapsedSize:te=0,collapsible:X}=W,{collapsedSize:fe=0,collapsible:be,maxSize:ne=100,minSize:de=0}=y.constraints,{panelSize:ue}=vn(ie,y,B);ue!=null&&(X&&be&&tn(ue,te)?tn(te,fe)||P(y,fe):ue<de?P(y,de):ue>ne&&P(y,ne))},[P]),U=pt((y,W)=>{const{direction:B}=w.current,{layout:ie}=N.current;if(!h.current)return;const te=xs(y,h.current);Ce(te,`Drag handle element not found for id "${y}"`);const X=df(B,W);v({dragHandleId:y,dragHandleRect:te.getBoundingClientRect(),initialCursorPosition:X,initialLayout:ie})},[]),se=pt(()=>{v(null)},[]),k=pt(y=>{const{panelDataArray:W}=N.current,B=Jn(W,y);B>=0&&(W.splice(B,1),delete m.current[y.id],N.current.panelDataArrayChanged=!0,_())},[_]),le=dy(()=>({collapsePanel:O,direction:r,dragState:g,expandPanel:K,getPanelSize:C,getPanelStyle:T,groupId:p,isPanelCollapsed:A,isPanelExpanded:F,reevaluatePanelConstraints:V,registerPanel:R,registerResizeHandle:L,resizePanel:P,startDragging:U,stopDragging:se,unregisterPanel:k,panelGroupElement:h.current}),[O,g,r,K,C,T,p,A,F,V,R,L,P,U,se,k]),q={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return ar(hs.Provider,{value:le},ar(f,{...d,children:t,className:n,id:s,ref:h,style:{...q,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const gf=qd((e,t)=>ar(mf,{...e,forwardedRef:t}));mf.displayName="PanelGroup";gf.displayName="forwardRef(PanelGroup)";function Jn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function vn(e,t,n){const r=Jn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],a=n[r];return{...t.constraints,panelSize:a,pivotIndices:s}}function $y({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){Nn(()=>{if(e||n==null||r==null)return;const i=xs(t,r);if(i==null)return;const s=a=>{if(!a.defaultPrevented)switch(a.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{a.preventDefault(),n(a);break}case"F6":{a.preventDefault();const o=i.getAttribute("data-panel-group-id");Ce(o,`No group element found for id "${o}"`);const l=Ur(o,r),c=lf(o,t,r);Ce(c!==null,`No resize element found for id "${t}"`);const f=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[f].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function xf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:f="div",...d}){var p,h;const g=xt(null),v=xt({onDragging:a});Nn(()=>{v.current.onDragging=a});const S=Gd(hs);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:x,groupId:_,registerResizeHandle:m,startDragging:I,stopDragging:E,panelGroupElement:w}=S,N=Qa(i),[O,K]=Qn("inactive"),[C,T]=Qn(!1),[A,F]=Qn(null),R=xt({state:O});En(()=>{R.current.state=O}),Nn(()=>{if(n)F(null);else{const U=m(N);F(()=>U)}},[n,N,m]);const L=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,P=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return Nn(()=>{if(n||A==null)return;const U=g.current;return Ce(U,"Element ref not attached"),_y(N,U,x,{coarse:L,fine:P},(k,le,q)=>{if(le)switch(k){case"down":{K("drag"),Ce(q,'Expected event to be defined for "down" action'),I(N,q);const{onDragging:y}=v.current;y&&y(!0);break}case"move":{const{state:y}=R.current;y!=="drag"&&K("hover"),Ce(q,'Expected event to be defined for "move" action'),A(q);break}case"up":{K("hover"),E();const{onDragging:y}=v.current;y&&y(!1);break}}else K("inactive")})},[L,x,n,P,m,N,A,I,E]),$y({disabled:n,handleId:N,resizeHandler:A,panelGroupElement:w}),ar(f,{...d,children:e,className:t,id:i,onBlur:()=>{T(!1),s==null||s()},onFocus:()=>{T(!0),o==null||o()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":x,"data-panel-group-id":_,"data-resize-handle":"","data-resize-handle-active":O==="drag"?"pointer":C?"keyboard":void 0,"data-resize-handle-state":O,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":N})}xf.displayName="PanelResizeHandle";const Fy=({className:e,...t})=>u.jsx(gf,{className:H("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Ms=Xd,dl=({withHandle:e,className:t,...n})=>u.jsx(xf,{className:H("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-none data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&u.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:u.jsx(rg,{className:"h-2.5 w-2.5"})})});class Ly{constructor(t){Po(this,"client");this.client=Cg.create({baseURL:t||void 0||"/api",headers:{"Content-Type":"application/json"}})}get(t,n){return this.client.get(t,n)}post(t,n,r){return this.client.post(t,n,r)}put(t,n,r){return this.client.put(t,n,r)}delete(t,n){return this.client.delete(t,n)}patch(t,n,r){return this.client.patch(t,n,r)}}const Zy=new Ly;function By(){const e=b.useRef(null),t=b.useCallback(async(r,i,s,a,o)=>{e.current&&e.current.abort();const l=new AbortController;e.current=l;try{a==null||a("parsing","Validating JSON structure...");let c;try{c=JSON.parse(i)}catch(w){throw new Error(`Invalid JSON: ${w instanceof Error?w.message:"Unknown parse error"}`)}a==null||a("building",`Building ${pi.toLowerCase()} structure...`);const f={jsonDefinition:c,options:o||{}};f.customThemes=s??{},a==null||a("rendering",`Generating ${yt.toUpperCase()} content...`);const d={"Content-Type":"application/json"};o!=null&&o.bypassCache&&(d["X-Bypass-Cache"]="true");const p=await fetch(Vc.generate,{method:"POST",headers:d,body:JSON.stringify(f),signal:l.signal}),h=await p.json();if(!p.ok||!h.success){const w=h.error||h.message||`API request failed with status: ${p.status}`;throw new Error(w)}const{data:g,cache:v,warnings:S}=h,x=v.status==="HIT"?"HIT":v.status==="MISS"?"MISS":"UNKNOWN",_=x==="HIT"?`Served from cache (Hit rate: ${v.hitRate})`:`Generated fresh ${pi.toLowerCase()}`;a==null||a("finalizing",_);const m=globalThis.atob(g.document),I=new Uint8Array(m.length);for(let w=0;w<m.length;w++)I[w]=m.charCodeAt(w);const E=new Blob([I],{type:g.contentType});if(E.size===0)throw new Error(`Received empty ${pi.toLowerCase()} from API`);return{name:r,text:i,blob:E,filename:g.filename,fileId:g.fileId,cacheStatus:x,cacheHitRate:v.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${pi} generation was cancelled`):c}finally{e.current===l&&(e.current=null)}},[]),n=b.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:t,generateDocument:t,cancelGeneration:n}}function Vy(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const a of i){let o=a.message;if(a.context&&Object.keys(a.context).length>0){const l=Object.entries(a.context).map(([c,f])=>`${c}: ${JSON.stringify(f)}`).join(", ");o+=` (${l})`}s.push(o)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function Uy({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=_e.useState("custom");_e.useEffect(()=>{e&&s("custom")},[e]);const a=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),o=[{value:"custom",title:"Keep custom fonts",desc:"Recipients with the font installed see the authored typeface. Others get a generic fallback."},{value:"substitute",title:"Convert to safe fonts",desc:"Rewrite non-safe families to Calibri / Georgia / Consolas so every recipient sees the same glyphs."}];return u.jsx(It,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(St,{className:"max-w-md",children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:"Non-safe fonts in this document"}),u.jsxs(hn,{children:[a," ",n.length===1?"is":"are"," not in the built-in safe list. Choose how to export."]})]}),u.jsx("div",{className:"grid gap-2 py-2",children:o.map(l=>{const c=i===l.value;return u.jsxs("button",{type:"button",onClick:()=>s(l.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${c?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${c?"border-primary":"border-muted-foreground/50"}`,children:c&&u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),u.jsx("span",{className:"text-sm font-medium",children:l.title})]}),u.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:l.desc})]},l.value)})}),u.jsxs(In,{children:[u.jsx(Ee,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(Ee,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const fl=yt==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],$s={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function Jy({name:e,blob:t,displayReloadButton:n,iframeRef:r,autoReload:i,onToggleAutoReload:s,onManualRender:a,isGenerating:o,isRendering:l,onShowCacheMetrics:c,onShowSchemas:f,onShowFonts:d,documentText:p,warnings:h,renderingLibrary:g,setRenderingLibrary:v,onToggleChat:S,chatOpen:x,onTogglePreview:_,previewOpen:m}){const I=g!=="docxjs",[E,w]=b.useState(!1),[N,O]=b.useState(!1),[K,C]=b.useState(!1),[T,A]=b.useState(!1),[F,R]=b.useState(!1),[L,P]=b.useState(!1),{toast:V}=fr(),{generateDocument:U}=By(),se=b.useContext(nd),k=b.useCallback(()=>{const ne={},{customThemes:de}=se.getState();return Object.values(de).forEach(ue=>{ue.valid&&ue.parsed&&(ne[ue.name]=ue.parsed)}),ne},[se]),le=_e.useMemo(()=>{if(!p)return[];try{const ne=JSON.parse(p);return[...(yt==="pptx"?Fm:Lm)(ne)].filter(ue=>!Zm(ue))}catch{return[]}},[p]),[q,y]=b.useState(!1),W=b.useCallback(async()=>{if(t){w(!0);try{await new Promise(ne=>setTimeout(ne,100)),Ei(`${e}${xr}`,t)}finally{setTimeout(()=>w(!1),500)}}},[t,e]),B=b.useCallback(async()=>{if(t){if(le.length===0){await W();return}y(!0)}},[t,le.length,W]),ie=b.useCallback(async ne=>{var de;if(p){w(!0);try{const ue=await U(e,p,k(),void 0,{bypassCache:!0,fonts:{mode:ne}});if(ue.blob.size===0)V({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Ei(`${e}${xr}`,ue.blob);const Z=(de=ue.warnings)==null?void 0:de.find(ke=>{var me,De;return((me=ke.context)==null?void 0:me.code)==="FONT_MODE_SUBSTITUTED"||((De=ke.context)==null?void 0:De.code)==="FONT_MODE_CUSTOM"});Z&&V({title:ne==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:Z.message})}}catch(ue){V({title:"Export failed",description:ue instanceof Error?ue.message:String(ue),variant:"destructive"})}finally{setTimeout(()=>w(!1),500)}}},[p,e,U,V,k]),te=b.useCallback(async()=>{if(!(!h||h.length===0)){O(!0);try{const ne=Vy(h);if(!ne){V({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const de=await U("warnings",JSON.stringify(ne,null,2),{});de&&typeof de=="object"&&"blob"in de&&de.blob&&(Ei(`${e}-warnings${xr}`,de.blob),V({title:"Warnings downloaded",description:`Downloaded warnings document with ${h.length} warning(s).`}))}catch(ne){console.error("Failed to generate warnings document:",ne),V({title:"Download failed",description:ne instanceof Error?ne.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>O(!1),500)}}},[h,e,U,V]),X=b.useCallback(async()=>{const ne=r==null?void 0:r.current;if(ne!=null&&ne.src){C(!0);try{await new Promise(ue=>{let Z=null,ke=!1;const me=()=>{Z&&(clearTimeout(Z),Z=null),ne.removeEventListener("load",j),ne.removeEventListener("error",z)},De=()=>{ke||(ke=!0,me(),ue())},j=()=>De(),z=()=>De();ne.addEventListener("load",j),ne.addEventListener("error",z),Z=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),De()},5e3);const M=ne.src,re=M.includes("?")?"&":"?",ee=Date.now();ne.src=`${M}${re}_reload=${ee}`})}catch(de){console.error("Iframe reload failed:",de)}finally{C(!1)}}},[r]),fe=b.useCallback(async()=>{A(!0);try{await Zy.delete(`/${yt}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),V({title:"Cache Cleared",description:"All caches (document and component) have been successfully cleared.",variant:"default"})}catch(ne){console.error("Failed to clear cache:",ne),V({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{A(!1)}},[V]),be=b.useCallback(async()=>{if(!p){V({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}P(!0);try{const ne=await fetch(`/api/${yt}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:p})});if(!ne.ok){let Z=`Request failed with status ${ne.status}`;try{const ke=await ne.json();ke.message&&(Z=ke.message)}catch{}V({title:"Failed to get standard components",description:Z,variant:"destructive"});return}const de=await ne.json(),ue=JSON.stringify(de.data,null,2);await navigator.clipboard.writeText(ue),V({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(ne){console.error("Error copying standard components:",ne),V({title:"Error",description:ne instanceof Error?ne.message:"Failed to copy standard components",variant:"destructive"})}finally{P(!1)}},[p,V]);return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"bg-sidebar border-b flex flex-row flex-nowrap items-center justify-between gap-x-2 px-3 py-1.5",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[u.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("button",{type:"button","aria-label":"Preview disclaimer",className:"cursor-help inline-flex items-center justify-center h-6 w-6 rounded-sm hover:bg-muted/60 shrink-0",children:u.jsx(Kc,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Ke,{className:"max-w-sm",children:u.jsxs("p",{className:"text-sm",children:["Preview uses"," ",yt==="docx"?"docx-preview":"LibreOffice PDF conversion",". Download the ",xr," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[(!i||I)&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(Ee,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:a,"aria-label":"Render preview",disabled:o||l||m===!1,children:[l?u.jsx(en,{size:"sm"}):u.jsx(ig,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:m===!1?"Open preview to run":l?"Rendering preview...":"Render preview"})})]}),yt==="docx"&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("div",{className:"flex items-center gap-1.5 cursor-help ml-2 mr-1",children:[u.jsx(Xn,{className:"text-xs text-muted-foreground hidden sm:inline",children:"Auto"}),u.jsx(Xa,{checked:i,onCheckedChange:s,disabled:I})]})}),u.jsx(Ke,{children:u.jsx("p",{children:I?"Auto-reload is not available for Office, Docs, and LibreOffice renderers":`${i?"Disable":"Enable"} automatic preview reload on content changes`})})]}),n&&i&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:X,disabled:K||o||l,children:K?u.jsx(en,{size:"sm"}):u.jsx(sg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsx("p",{children:K?"Reloading...":"Reload"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(Ee,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||E||o,onClick:B,children:[E?u.jsx(en,{size:"sm"}):u.jsx(ag,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download ",xr]})})]}),h&&h.length>0&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:N||o,onClick:te,children:N?u.jsx(en,{size:"sm"}):u.jsx(Xc,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download warnings (",h.length,")"]})})]}),g&&v&&u.jsxs(Fr,{value:g,onValueChange:v,children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(rr,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(Lr,{placeholder:"Renderer"})})}),u.jsx(Ke,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(ir,{className:"text-sidebar-foreground",children:fl.map(ne=>u.jsxs(Tn,{value:ne,children:[u.jsxs(qe,{children:[u.jsx(Ge,{tabIndex:-1,children:$s[ne][0]}),u.jsx(Ke,{children:$s[ne][1]})]})," ",ne]},ne))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(ds,{children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(fs,{asChild:!0,children:u.jsx(Ee,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Gc,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ke,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(ai,{align:"end",className:"w-52",children:[f&&u.jsxs(Bt,{onClick:f,children:[u.jsx(og,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),d&&u.jsxs(Bt,{onClick:d,children:[u.jsx(lg,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Bt,{onClick:c,children:[u.jsx(ug,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),u.jsxs(Bt,{onClick:be,disabled:!p||L,children:[u.jsx(Qc,{className:"h-4 w-4 mr-2"}),L?"Copying...":"Copy standard components"]}),u.jsx(sr,{}),u.jsxs(Bt,{onClick:()=>R(!0),disabled:T,className:"text-destructive focus:text-destructive",children:[u.jsx(Va,{className:"h-4 w-4 mr-2"}),T?"Clearing...":"Clear all caches"]}),g&&v&&u.jsxs(u.Fragment,{children:[u.jsx(sr,{className:"lg:hidden"}),fl.map(ne=>u.jsxs(Bt,{className:"lg:hidden",onClick:()=>v(ne),children:[u.jsx("span",{className:"mr-2",children:g===ne?"●":"○"}),$s[ne][0]," ",ne]},ne))]})]})]}),_&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:m?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:_,children:m?u.jsx(ed,{className:"h-3.5 w-3.5"}):u.jsx(cg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[m?"Hide":"Show"," Preview"," ",u.jsx(Br,{shortcut:"mod+shift+p"})]})})]}),S&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:x?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:S,children:u.jsx(td,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[x?"Close":"Open"," AI Chat"," ",u.jsx(Br,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(Uy,{open:q,onClose:()=>y(!1),nonSafeFonts:le,onChoose:ie}),u.jsx(It,{open:F,onOpenChange:R,children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:"Clear all caches?"}),u.jsx(hn,{children:"This will clear document and component caches. Next generation will be uncached."})]}),u.jsxs(In,{children:[u.jsx(Ee,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),u.jsx(Ee,{variant:"destructive",size:"sm",disabled:T,onClick:async()=>{await fe(),R(!1)},children:T?u.jsx(en,{size:"sm"}):"Clear"})]})]})})]})}const Hy=_e.memo(Jy),yf=Om,ro=b.forwardRef(({className:e,...t},n)=>u.jsx(Lc,{ref:n,className:H("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));ro.displayName=Lc.displayName;const Jr=b.forwardRef(({className:e,...t},n)=>u.jsx(Zc,{ref:n,className:H("ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex cursor-pointer items-center justify-center rounded-sm px-3 py-1 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",e),...t}));Jr.displayName=Zc.displayName;const Hr=b.forwardRef(({className:e,...t},n)=>u.jsx(Bc,{ref:n,className:H("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));Hr.displayName=Bc.displayName;async function Wy(e){if(navigator.clipboard&&navigator.clipboard.writeText)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="2em",t.style.height="2em",t.style.padding="0",t.style.border="none",t.style.outline="none",t.style.boxShadow="none",t.style.background="transparent",document.body.appendChild(t),t.focus(),t.select();const n=document.execCommand("copy");return document.body.removeChild(t),n}catch(t){return console.error("Failed to copy text to clipboard:",t),!1}}function qy(e){try{const t=typeof e=="string"?JSON.parse(e):e;return JSON.stringify(t,null,2)}catch(t){return console.error("Failed to format schema:",t),typeof e=="string"?e:JSON.stringify(e)}}async function Gy(e){const t=qy(e);return Wy(t)}const Ky=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=b.useState(n),[s,a]=b.useState(null),[o,l]=b.useState(null),[c,f]=b.useState(!1),[d,p]=b.useState(!1),[h,g]=b.useState(null),[v,S]=b.useState(null),[x,_]=b.useState(!1),{toast:m}=fr(),I=Dt(F=>F.selectedPlugins),E=Array.from(I);b.useEffect(()=>{n&&i(n)},[n]);const w=b.useCallback(async()=>{f(!0),g(null);try{const F=await Es.fetchDocumentSchema(E);a(F)}catch(F){const R=F instanceof Error?F.message:"Failed to load document schema";g(R),m({variant:"destructive",title:"Error loading schema",description:R})}finally{f(!1)}},[E,m]),N=b.useCallback(async()=>{if(!o){p(!0),S(null);try{const F=await Es.fetchThemeSchema();l(F)}catch(F){const R=F instanceof Error?F.message:"Failed to load theme schema";S(R),m({variant:"destructive",title:"Error loading schema",description:R})}finally{p(!1)}}},[o,m]),[O,K]=b.useState([]);b.useEffect(()=>{e||(a(null),g(null))},[e]),b.useEffect(()=>{if(!e)return;const F=E.length!==O.length||E.some((R,L)=>R!==O[L]);r==="document"?(!s||F)&&(F&&(Es.clearPluginSchemaCache(),K([...E])),c||w()):r==="theme"&&!o&&!d&&N()},[r,e,s,o,c,d,E,O,w,N]);const C=E.length,T=r==="document"?s:o,A=async()=>{if(T)try{await Gy(T)&&(_(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>_(!1),2e3))}catch(F){console.error("Copy failed:",F)}};return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ht,{children:u.jsx(Wt,{children:"Schema Viewer"})}),u.jsxs(yf,{value:r,onValueChange:F=>i(F),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Jr,{value:"document",className:"flex items-center gap-1",children:["Document",C>0&&u.jsxs(Jt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",C]})]}),u.jsx(Jr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(Ee,{variant:"ghost",size:"icon",onClick:A,disabled:x||!T,"aria-label":"Copy schema",children:x?u.jsx(pn,{className:"h-4 w-4"}):u.jsx(os,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(Hr,{value:"document",className:"h-full",children:u.jsx(Zi,{schema:s,loading:c,error:h||void 0})}),u.jsx(Hr,{value:"theme",className:"h-full",children:u.jsx(Zi,{schema:o,loading:d,error:v||void 0})})]})]})]})})};function Yy(e,t,n){if(t.length===0)return n;const r=pl(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const a=t[s],o=t[s+1],l=i[a],c=pl(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function pl(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Xy={safe:[],google:[]};function Qy(e,t){var f;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((f=r==null?void 0:r.dataset.weights)==null?void 0:f.split(",").map(Number).filter(d=>!Number.isNaN(d)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((d,p)=>d-p).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${o}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...a].sort((d,p)=>d-p).join(",")}function eb(){const e=Oe(i=>i.activeTab),t=Oe(i=>i.documents),n=Oe(i=>i.documentTypes),r=Oe(i=>i.saveDocument);return b.useCallback(i=>{if(!e)return{ok:!1,error:"No active file"};if(n[e]!=="application/json+theme")return{ok:!1,error:"Fonts are registered on themes, not documents. Open a .theme.json file and try again."};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active theme not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active theme is not valid JSON: ${l.message}`}}const o=i(a);return r(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n,r])}function tb(){const e=Oe(r=>r.activeTab),t=Oe(r=>r.documents),n=Oe(r=>r.saveDocument);return b.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active document not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active document is not valid JSON: ${l.message}`}}const o=Yy(a,r,i);return n(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n])}function nb(e,t,n){(!e.fonts||typeof e.fonts!="object")&&(e.fonts={});const r=e.fonts[t];r&&typeof r=="object"?e.fonts[t]={...r,family:n}:e.fonts[t]=n}function hl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const rb=({open:e,onOpenChange:t})=>{const n=Ci(P=>P.open),r=Ci(P=>P.contextual),i=Ci(P=>P.close),s=e??n,a=r,o=b.useCallback(P=>{t&&t(P),P||i()},[t,i]),[l,c]=b.useState(Xy),[f,d]=b.useState(!1),[p,h]=b.useState(""),[g,v]=b.useState("safe"),[S,x]=b.useState(null),[_,m]=b.useState(null),{toast:I}=fr(),E=eb(),w=tb(),N=Oe(P=>P.activeTab),O=Oe(P=>P.documentTypes),K=N&&O[N]==="application/json+theme",C=!!a||K;b.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(d(!0),fetch("/api/fonts/catalog").then(P=>P.json()).then(P=>c(P)).catch(P=>{I({variant:"destructive",title:"Font catalog unavailable",description:P.message})}).finally(()=>d(!1))))},[s,l,I]),b.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const P of l.google)Qy(P.family,P.weights)},[g,l]);const T=b.useMemo(()=>l.safe.filter(P=>P.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),A=b.useMemo(()=>l.google.filter(P=>P.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),F=b.useCallback(async P=>{try{await navigator.clipboard.writeText(P),m(P),setTimeout(()=>m(null),1500)}catch{I({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[I]),R=b.useCallback(async(P,V,U)=>{x(P);try{const se=E(k=>(nb(k,U,P),k));if(!se.ok){I({variant:"destructive",title:"Could not insert font",description:se.error});return}I({title:"Font inserted",description:`${P} set as ${U} font in "${se.name}".`})}finally{x(null)}},[E,I]),L=b.useCallback(async P=>{if(a){x(P);try{const V=w(a.jsonPath,P);if(!V.ok){I({variant:"destructive",title:"Could not insert font",description:V.error});return}I({title:"Font inserted",description:`${P} set at ${hl(a.jsonPath)}.`}),o(!1)}finally{x(null)}}},[a,w,I,o]);return u.jsx(It,{open:s,onOpenChange:o,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ht,{children:u.jsx(Wt,{children:a?`Font for ${hl(a.jsonPath)}`:"Fonts"})}),!a&&!K&&u.jsx($i,{children:u.jsxs(Fi,{children:["Fonts are registered on themes. Open a ",u.jsx("code",{children:".theme.json"})," ","file to apply a font — the buttons below are disabled until you do."]})}),u.jsxs(yf,{value:g,onValueChange:P=>v(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Jr,{value:"safe",children:["Safe",u.jsx(Jt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(Jr,{value:"google",children:["Google",u.jsx(Jt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]})]}),u.jsx(ii,{type:"search",placeholder:"Search fonts...",value:p,onChange:P=>h(P.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(Hr,{value:"safe",className:"m-0",children:f&&T.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(la,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:T.map(P=>u.jsx(ml,{family:P,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${P}", sans-serif`},onCopy:()=>F(P),copied:_===P,contextual:!!a,onUseThis:()=>L(P),onInsertHeading:()=>R(P,"safe","heading"),onInsertBody:()=>R(P,"safe","body"),applying:S===P,disabled:!C},P))})}),u.jsx(Hr,{value:"google",className:"m-0",children:f&&A.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(la,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:A.map(P=>u.jsx(ml,{family:P.family,meta:u.jsxs("span",{className:"text-xs",children:[P.category," · ",P.weights.length," weights"]}),previewStyle:{fontFamily:`"${P.family}", sans-serif`},onCopy:()=>F(P.family),copied:_===P.family,contextual:!!a,onUseThis:()=>L(P.family),onInsertHeading:()=>R(P.family,"google","heading"),onInsertBody:()=>R(P.family,"google","body"),applying:S===P.family,disabled:!C,extraAction:u.jsx(sb,{family:P.family,weights:P.weights,hasItalic:P.hasItalic})},P.family))})})]})]})]})})},ib="The quick brown fox jumps over the lazy dog",sb=({family:e,weights:t,hasItalic:n})=>{const r=b.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsx(Ee,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(ai,{align:"end",className:"min-w-[260px]",children:[u.jsxs(Ad,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(sr,{}),r.map(i=>{const s=Bm[i]??String(i);return u.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-1.5",children:[u.jsx("span",{className:"truncate",style:{fontFamily:`"${e}", sans-serif`,fontWeight:i},children:s}),u.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:["fontWeight: ",i]})]},i)})]})]})},ml=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:f,extraAction:d})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:ib}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Ee,{size:"sm",onClick:a,disabled:c||f,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(Ee,{size:"sm",variant:"secondary",onClick:o,disabled:c||f,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Ee,{size:"sm",variant:"secondary",onClick:l,disabled:c||f,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),d,u.jsx(Ee,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(pn,{className:"h-4 w-4"}):u.jsx(os,{className:"h-4 w-4"})})]})]});function gl({previewOpen:e,onTogglePreview:t}){const n=Qt(O=>O.name||""),r=Qt(O=>O.blob),i=Qt(O=>O.isGenerating),s=Qt(O=>O.text),a=Qt(O=>O.warnings),o=Qt(O=>O.isRendering),l=hi(O=>O.autoReload),c=hi(O=>O.renderingLibrary),f=hi(O=>O.setSettings),d=hi(O=>O.useGlobalPreviewHeader??!0),p=Oe(O=>O.activeTab),h=Oe(O=>O.documentTypes),g=p&&h[p]==="application/json+theme"?"theme":"document",v=Pe(O=>O.chatOpen),S=Pe(O=>O.toggleChat),[x,_]=_e.useState(!1),m=Ci(O=>O.openFor);if(!d)return null;const I=b.useCallback(()=>f({saveDocumentDebounceWait:2e3,autoReload:!l}),[l,f]),E=b.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),w=b.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),N=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(Hy,{name:N,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:I,onManualRender:E,isGenerating:i,isRendering:!!o,onShowCacheMetrics:w,onShowSchemas:()=>_(!0),onShowFonts:()=>m(),documentText:s,warnings:a,renderingLibrary:c,setRenderingLibrary:O=>f({renderingLibrary:O}),onToggleChat:S,chatOpen:v,onTogglePreview:t,previewOpen:e}),u.jsx(Ky,{open:x,onOpenChange:_,defaultTab:g==="theme"?"theme":"document"}),u.jsx(rb,{})]})}function ab(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const ob=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,lb=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,ub={};function xl(e,t){return(ub.jsx?lb:ob).test(e)}const cb=/[ \t\n\f\r]/g;function db(e){return typeof e=="object"?e.type==="text"?yl(e.value):!1:yl(e)}function yl(e){return e.replace(cb,"")===""}class oi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}oi.prototype.normal={};oi.prototype.property={};oi.prototype.space=void 0;function bf(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new oi(n,r,t)}function ba(e){return e.toLowerCase()}class bt{constructor(t,n){this.attribute=n,this.property=t}}bt.prototype.attribute="";bt.prototype.booleanish=!1;bt.prototype.boolean=!1;bt.prototype.commaOrSpaceSeparated=!1;bt.prototype.commaSeparated=!1;bt.prototype.defined=!1;bt.prototype.mustUseProperty=!1;bt.prototype.number=!1;bt.prototype.overloadedBoolean=!1;bt.prototype.property="";bt.prototype.spaceSeparated=!1;bt.prototype.space=void 0;let fb=0;const Se=On(),tt=On(),va=On(),Y=On(),Ze=On(),tr=On(),wt=On();function On(){return 2**++fb}const wa=Object.freeze(Object.defineProperty({__proto__:null,boolean:Se,booleanish:tt,commaOrSpaceSeparated:wt,commaSeparated:tr,number:Y,overloadedBoolean:va,spaceSeparated:Ze},Symbol.toStringTag,{value:"Module"})),Fs=Object.keys(wa);class io extends bt{constructor(t,n,r,i){let s=-1;if(super(t,n),bl(this,"space",i),typeof r=="number")for(;++s<Fs.length;){const a=Fs[s];bl(this,Fs[s],(r&wa[a])===wa[a])}}}io.prototype.defined=!0;function bl(e,t,n){n&&(e[t]=n)}function pr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new io(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[ba(r)]=r,n[ba(s.attribute)]=r}return new oi(t,n,e.space)}const vf=pr({properties:{ariaActiveDescendant:null,ariaAtomic:tt,ariaAutoComplete:null,ariaBusy:tt,ariaChecked:tt,ariaColCount:Y,ariaColIndex:Y,ariaColSpan:Y,ariaControls:Ze,ariaCurrent:null,ariaDescribedBy:Ze,ariaDetails:null,ariaDisabled:tt,ariaDropEffect:Ze,ariaErrorMessage:null,ariaExpanded:tt,ariaFlowTo:Ze,ariaGrabbed:tt,ariaHasPopup:null,ariaHidden:tt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Ze,ariaLevel:Y,ariaLive:null,ariaModal:tt,ariaMultiLine:tt,ariaMultiSelectable:tt,ariaOrientation:null,ariaOwns:Ze,ariaPlaceholder:null,ariaPosInSet:Y,ariaPressed:tt,ariaReadOnly:tt,ariaRelevant:null,ariaRequired:tt,ariaRoleDescription:Ze,ariaRowCount:Y,ariaRowIndex:Y,ariaRowSpan:Y,ariaSelected:tt,ariaSetSize:Y,ariaSort:null,ariaValueMax:Y,ariaValueMin:Y,ariaValueNow:Y,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function wf(e,t){return t in e?e[t]:t}function kf(e,t){return wf(e,t.toLowerCase())}const pb=pr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:tr,acceptCharset:Ze,accessKey:Ze,action:null,allow:null,allowFullScreen:Se,allowPaymentRequest:Se,allowUserMedia:Se,alt:null,as:null,async:Se,autoCapitalize:null,autoComplete:Ze,autoFocus:Se,autoPlay:Se,blocking:Ze,capture:null,charSet:null,checked:Se,cite:null,className:Ze,cols:Y,colSpan:null,content:null,contentEditable:tt,controls:Se,controlsList:Ze,coords:Y|tr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Se,defer:Se,dir:null,dirName:null,disabled:Se,download:va,draggable:tt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Se,formTarget:null,headers:Ze,height:Y,hidden:va,high:Y,href:null,hrefLang:null,htmlFor:Ze,httpEquiv:Ze,id:null,imageSizes:null,imageSrcSet:null,inert:Se,inputMode:null,integrity:null,is:null,isMap:Se,itemId:null,itemProp:Ze,itemRef:Ze,itemScope:Se,itemType:Ze,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Se,low:Y,manifest:null,max:null,maxLength:Y,media:null,method:null,min:null,minLength:Y,multiple:Se,muted:Se,name:null,nonce:null,noModule:Se,noValidate:Se,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Se,optimum:Y,pattern:null,ping:Ze,placeholder:null,playsInline:Se,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Se,referrerPolicy:null,rel:Ze,required:Se,reversed:Se,rows:Y,rowSpan:Y,sandbox:Ze,scope:null,scoped:Se,seamless:Se,selected:Se,shadowRootClonable:Se,shadowRootDelegatesFocus:Se,shadowRootMode:null,shape:null,size:Y,sizes:null,slot:null,span:Y,spellCheck:tt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Y,step:null,style:null,tabIndex:Y,target:null,title:null,translate:null,type:null,typeMustMatch:Se,useMap:null,value:tt,width:Y,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ze,axis:null,background:null,bgColor:null,border:Y,borderColor:null,bottomMargin:Y,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Se,declare:Se,event:null,face:null,frame:null,frameBorder:null,hSpace:Y,leftMargin:Y,link:null,longDesc:null,lowSrc:null,marginHeight:Y,marginWidth:Y,noResize:Se,noHref:Se,noShade:Se,noWrap:Se,object:null,profile:null,prompt:null,rev:null,rightMargin:Y,rules:null,scheme:null,scrolling:tt,standby:null,summary:null,text:null,topMargin:Y,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Y,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Se,disableRemotePlayback:Se,prefix:null,property:null,results:Y,security:null,unselectable:null},space:"html",transform:kf}),hb=pr({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:wt,accentHeight:Y,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Y,amplitude:Y,arabicForm:null,ascent:Y,attributeName:null,attributeType:null,azimuth:Y,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Y,by:null,calcMode:null,capHeight:Y,className:Ze,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Y,diffuseConstant:Y,direction:null,display:null,dur:null,divisor:Y,dominantBaseline:null,download:Se,dx:null,dy:null,edgeMode:null,editable:null,elevation:Y,enableBackground:null,end:null,event:null,exponent:Y,externalResourcesRequired:null,fill:null,fillOpacity:Y,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:tr,g2:tr,glyphName:tr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Y,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Y,horizOriginX:Y,horizOriginY:Y,id:null,ideographic:Y,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Y,k:Y,k1:Y,k2:Y,k3:Y,k4:Y,kernelMatrix:wt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Y,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Y,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Y,overlineThickness:Y,paintOrder:null,panose1:null,path:null,pathLength:Y,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ze,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Y,pointsAtY:Y,pointsAtZ:Y,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:wt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:wt,rev:wt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:wt,requiredFeatures:wt,requiredFonts:wt,requiredFormats:wt,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Y,specularExponent:Y,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Y,strikethroughThickness:Y,string:null,stroke:null,strokeDashArray:wt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Y,strokeOpacity:Y,strokeWidth:null,style:null,surfaceScale:Y,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:wt,tabIndex:Y,tableValues:null,target:null,targetX:Y,targetY:Y,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:wt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Y,underlineThickness:Y,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Y,values:null,vAlphabetic:Y,vMathematical:Y,vectorEffect:null,vHanging:Y,vIdeographic:Y,version:null,vertAdvY:Y,vertOriginX:Y,vertOriginY:Y,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Y,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:wf}),Sf=pr({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),_f=pr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:kf}),jf=pr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),mb={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},gb=/[A-Z]/g,vl=/-[a-z]/g,xb=/^data[-\w.:]+$/i;function yb(e,t){const n=ba(t);let r=t,i=bt;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&xb.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(vl,vb);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!vl.test(s)){let a=s.replace(gb,bb);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=io}return new i(r,t)}function bb(e){return"-"+e.toLowerCase()}function vb(e){return e.charAt(1).toUpperCase()}const wb=bf([vf,pb,Sf,_f,jf],"html"),so=bf([vf,hb,Sf,_f,jf],"svg");function kb(e){return e.join(" ").trim()}var Ln={},Ls,wl;function Sb(){if(wl)return Ls;wl=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,a=/^[;\s]*/,o=/^\s+|\s+$/g,l=`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-DCtGYNz2.js","assets/react-vendor-CTFDOf2G.js","assets/editor-monaco-json-CU9ciwPv.js","assets/index-CHAIoQtG.js","assets/query-vendor-Df8-oete.js","assets/radix-ui-Bq-7y_Sq.js","assets/ui-vendor-Nd4Lg2re.js","assets/monaco-editor-BcgxPCqT.js","assets/state-vendor-ByFYl9bq.js","assets/index-BdmImuIf.css","assets/MonacoPluginProvider-DM63WAJx.js","assets/button-CyTe9rTl.js","assets/preview-oxnxMi4x.js"])))=>i.map(i=>d[i]);
2
+ var um=Object.defineProperty;var cm=(e,t,n)=>t in e?um(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Po=(e,t,n)=>cm(e,typeof t!="symbol"?t+"":t,n);import{r as b,j as u,c as _e,R as lc,g as Za}from"./react-vendor-CTFDOf2G.js";import{b as uc,c as Ba,d as cc,e as rs,f as is,D as ss,O as as,g as dm,V as fm,h as dc,I as pm,i as hm,j as fc,k as mm,l as pc,m as gm,n as xm,G as ym,S as hc,o as mc,L as gc,p as xc,q as yc,r as dr,s as bm,t as vm,u as wm,v as bc,w as vc,x as wc,y as kc,z as Sc,B as _c,E as jc,F as Cc,H as Nc,J as km,K as Sm,M as _m,N as Ec,Q as Ic,U as Tc,W as zc,X as Ac,Y as Pc,Z as Oc,_ as Dc,$ as Rc,a0 as Mc,a1 as jm,a2 as $c,a3 as Cm,a4 as Nm,a5 as Fc,a6 as Em,a7 as Im,a8 as Tm,a9 as zm,aa as Am,ab as Pm,ac as Om,ad as Lc,ae as Zc,af as Bc}from"./radix-ui-Bq-7y_Sq.js";import{c as H,u as fr,S as en,A as Vc,T as fi,C as Dm,E as Rm,F as yt,a as Mm,b as $m,d as qe,e as Ge,f as Ke,g as Uc,_ as Jc,h as pi,i as Fm,j as Lm,k as Zm,l as xr,s as Es,m as Ci,W as Bm}from"./index-CHAIoQtG.js";import{X as fn,C as ti,a as pn,b as Vm,d as ni,G as Hc,F as Um,e as ri,f as Wc,P as Jm,g as Hm,h as qc,E as Gc,S as Wm,B as Oo,i as qm,j as Gm,k as Km,l as os,m as Ym,M as Xm,I as Kc,n as Xt,o as Qm,p as eg,q as Yc,r as tg,s as ng,t as rg,u as ig,R as sg,v as ag,T as Xc,w as og,x as lg,y as ug,z as Qc,A as Va,D as ed,H as cg,J as td,L as la,K as dg,N as fg,O as Do,Q as ua,U as pg}from"./ui-vendor-Nd4Lg2re.js";import{B as Ee}from"./button-CyTe9rTl.js";import{u as Oe,i as hg,a as ca,b as Qt,g as mg,c as Dt,T as nd,d as hi,S as gg,O as xg,e as yg,M as bg,D as vg}from"./MonacoPluginProvider-DM63WAJx.js";import{u as rd,a as wg,d as kg,p as Sg,b as _g,e as jg}from"./state-vendor-ByFYl9bq.js";import{b as Cg}from"./query-vendor-Df8-oete.js";const It=uc,Ng=cc,Ro=Ba,id=b.forwardRef(({className:e,...t},n)=>u.jsx(as,{ref:n,className:H("fixed inset-0 z-50 bg-black/50",e),...t}));id.displayName=as.displayName;const St=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ng,{children:[u.jsx(id,{}),u.jsxs(rs,{ref:r,className:H("bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",e),...n,children:[t,u.jsxs(Ba,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 cursor-pointer rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none",children:[u.jsx(fn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));St.displayName=rs.displayName;const Ht=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ht.displayName="DialogHeader";const In=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});In.displayName="DialogFooter";const Wt=b.forwardRef(({className:e,...t},n)=>u.jsx(is,{ref:n,className:H("text-lg leading-none font-semibold tracking-tight",e),...t}));Wt.displayName=is.displayName;const hn=b.forwardRef(({className:e,...t},n)=>u.jsx(ss,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));hn.displayName=ss.displayName;const Fr=dm,Eg=ym,Lr=fm,rr=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(dc,{ref:r,className:H("border-input ring-offset-background placeholder:text-muted-foreground focus:ring-ring flex min-h-9 w-full min-w-0 items-center justify-between gap-2 rounded-sm border bg-background px-3 py-2 text-sm shadow-xs focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:min-w-0 [&>span]:whitespace-normal [&>span]:break-words text-left cursor-pointer",e),...n,children:[t,u.jsx(pm,{asChild:!0,children:u.jsx(ti,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));rr.displayName=dc.displayName;const sd=b.forwardRef(({className:e,...t},n)=>u.jsx(hc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Vm,{className:"h-4 w-4"})}));sd.displayName=hc.displayName;const ad=b.forwardRef(({className:e,...t},n)=>u.jsx(mc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ti,{className:"h-4 w-4"})}));ad.displayName=mc.displayName;const ir=b.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(hm,{children:u.jsxs(fc,{ref:i,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-lg border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(sd,{}),u.jsx(mm,{className:H("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(ad,{})]})}));ir.displayName=fc.displayName;const od=b.forwardRef(({className:e,...t},n)=>u.jsx(gc,{ref:n,className:H("px-2 py-1.5 text-sm font-semibold",e),...t}));od.displayName=gc.displayName;const Tn=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex w-full cursor-pointer items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(gm,{children:u.jsx(pn,{className:"h-4 w-4"})})}),u.jsx(xm,{children:t})]}));Tn.displayName=pc.displayName;const Ig=b.forwardRef(({className:e,...t},n)=>u.jsx(xc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));Ig.displayName=xc.displayName;const ii=b.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:H("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-sm border bg-background px-3 py-1 text-sm shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));ii.displayName="Input";const Tg=ni("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Xn=b.forwardRef(({className:e,...t},n)=>u.jsx(yc,{ref:n,className:H(Tg(),e),...t}));Xn.displayName=yc.displayName;const zg=ni("inline-flex items-center rounded-md border px-2.5 py-1 text-xs font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Jt({className:e,variant:t,...n}){return u.jsx("div",{className:H(zg({variant:t}),e),...n})}const Ag=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Oe(rd(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),{toast:o}=fr(),l=b.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[c,f]=b.useState(""),[d,p]=b.useState(""),[h,g]=b.useState("playground"),[v,S]=b.useState(!1),[x,_]=b.useState(null),[m,I]=b.useState(null),[E,w]=b.useState(null),N=()=>{_(null),I(null),w(null)};b.useEffect(()=>{if(!e)return;_(null),I(null),w(null);const T=l.map(F=>F.name),A=T.includes(i)?i:T[0]??"";p(A),f(T.find(F=>F!==A)??"")},[e]);const O=async()=>{const T=l.find(F=>F.name===c),A=l.find(F=>F.name===d);if(!(!T||!A)){S(!0),_(null),I(null),w(null);try{const F=await fetch(Vc.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:T.text,newDefinition:A.text,options:{author:h||"playground"}})}),R=await F.json();if(!F.ok||!R.success){const L=Array.isArray(R.errors)?`: ${R.errors.slice(0,3).map(P=>P.message||String(P)).join("; ")}`:"";throw new Error((R.error||`Diff failed (${F.status})`)+L)}I(R.data.summary),w(R.data.document)}catch(F){_(F instanceof Error?F.message:"Diff failed")}finally{S(!1)}}},K=()=>{if(!E)return;const T=new Set(n.map(R=>R.name));let A=`${d}-redline`,F=2;for(;T.has(A);)A=`${d}-redline-${F++}`;s(A,JSON.stringify(E,null,2)),a(A),o({title:`Redline created: ${A}`}),t(!1)},C=m?m.tracked.modified+m.tracked.inserted+m.tracked.deleted:0;return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"sm:max-w-[560px]",children:[u.jsxs(Ht,{children:[u.jsxs(Wt,{className:"flex items-center gap-2",children:[u.jsx(Hc,{className:"size-4"}),"Compare documents"]}),u.jsx(hn,{children:"Diff two versions into a redline with native Word tracked changes (accept/reject in Word)."})]}),u.jsxs("div",{className:"grid gap-4 py-2",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Xn,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(Fr,{value:c,onValueChange:T=>{f(T),N()},children:[u.jsx(rr,{id:"diff-base",children:u.jsx(Lr,{placeholder:"Select document"})}),u.jsx(ir,{children:l.map(T=>u.jsx(Tn,{value:T.name,children:T.name},T.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Xn,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(Fr,{value:d,onValueChange:T=>{p(T),N()},children:[u.jsx(rr,{id:"diff-revised",children:u.jsx(Lr,{placeholder:"Select document"})}),u.jsx(ir,{children:l.map(T=>u.jsx(Tn,{value:T.name,children:T.name},T.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Xn,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(ii,{id:"diff-author",value:h,onChange:T=>{g(T.target.value),N()},placeholder:"playground"})]}),x&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:x}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Jt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Jt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Jt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),C===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((T,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},A))]}),m.notes.map((T,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},A))]})]}),u.jsx(In,{children:m&&C+m.untracked.length>0?u.jsxs(Ee,{onClick:K,children:[u.jsx(Um,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Ee,{onClick:O,disabled:v||!c||!d||c===d,children:[v&&u.jsx(en,{className:"size-4 mr-1"}),"Compare"]})})]})})};var si=e=>e.type==="checkbox",jn=e=>e instanceof Date,ct=e=>e==null;const ld=e=>typeof e=="object";var Qe=e=>!ct(e)&&!Array.isArray(e)&&ld(e)&&!jn(e),ud=e=>Qe(e)&&e.target?si(e.target)?e.target.checked:e.target.value:e,Pg=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,cd=(e,t)=>e.has(Pg(t)),Og=e=>{const t=e.constructor&&e.constructor.prototype;return Qe(t)&&t.hasOwnProperty("isPrototypeOf")},Ua=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mt(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(Ua&&(e instanceof Blob||r))&&(n||Qe(e)))if(t=n?[]:{},!n&&!Og(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=mt(e[i]));else return e;return t}var ls=e=>Array.isArray(e)?e.filter(Boolean):[],Xe=e=>e===void 0,oe=(e,t,n)=>{if(!t||!Qe(e))return n;const r=ls(t.split(/[,[\].]+?/)).reduce((i,s)=>ct(i)?i:i[s],e);return Xe(r)||r===e?Xe(e[t])?n:e[t]:r},Nt=e=>typeof e=="boolean",Ja=e=>/^\w*$/.test(e),dd=e=>ls(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Me=(e,t,n)=>{let r=-1;const i=Ja(t)?[t]:dd(t),s=i.length,a=s-1;for(;++r<s;){const o=i[r];let l=n;if(r!==a){const c=e[o];l=Qe(c)||Array.isArray(c)?c:isNaN(+i[r+1])?{}:[]}if(o==="__proto__"||o==="constructor"||o==="prototype")return;e[o]=l,e=e[o]}return e};const Pi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ot={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Yt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},fd=_e.createContext(null),us=()=>_e.useContext(fd),Dg=e=>{const{children:t,...n}=e;return _e.createElement(fd.Provider,{value:n},t)};var pd=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const a=s;return t._proxyFormState[a]!==Ot.all&&(t._proxyFormState[a]=!r||Ot.all),n&&(n[a]=!0),e[a]}});return i},gt=e=>Qe(e)&&!Object.keys(e).length,hd=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return gt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(a=>t[a]===(!r||Ot.all))},Pr=e=>Array.isArray(e)?e:[e],md=(e,t,n)=>!e||!t||e===t||Pr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function Ha(e){const t=_e.useRef(e);t.current=e,_e.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function Rg(e){const t=us(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[a,o]=_e.useState(n._formState),l=_e.useRef(!0),c=_e.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),f=_e.useRef(i);return f.current=i,Ha({disabled:r,next:d=>l.current&&md(f.current,d.name,s)&&hd(d,c.current,n._updateFormState)&&o({...n._formState,...d}),subject:n._subjects.state}),_e.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),_e.useMemo(()=>pd(a,n,c.current,!1),[a,n])}var Ut=e=>typeof e=="string",gd=(e,t,n,r,i)=>Ut(e)?(r&&t.watch.add(e),oe(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),oe(n,s))):(r&&(t.watchAll=!0),n);function Mg(e){const t=us(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=_e.useRef(r);o.current=r,Ha({disabled:s,subject:n._subjects.values,next:f=>{md(o.current,f.name,a)&&c(mt(gd(o.current,n._names,f.values||n._formValues,!1,i)))}});const[l,c]=_e.useState(n._getWatch(r,i));return _e.useEffect(()=>n._removeUnmounted()),l}function $g(e){const t=us(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=cd(i._names.array,n),o=Mg({control:i,name:n,defaultValue:oe(i._formValues,n,oe(i._defaultValues,n,e.defaultValue)),exact:!0}),l=Rg({control:i,name:n,exact:!0}),c=_e.useRef(i.register(n,{...e.rules,value:o,...Nt(e.disabled)?{disabled:e.disabled}:{}})),f=_e.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!oe(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!oe(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!oe(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!oe(l.validatingFields,n)},error:{enumerable:!0,get:()=>oe(l.errors,n)}}),[l,n]),d=_e.useMemo(()=>({name:n,value:o,...Nt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:ud(p),name:n},type:Pi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:oe(i._formValues,n),name:n},type:Pi.BLUR}),ref:p=>{const h=oe(i._fields,n);h&&p&&(h._f.ref={focus:()=>p.focus(),select:()=>p.select(),setCustomValidity:g=>p.setCustomValidity(g),reportValidity:()=>p.reportValidity()})}}),[n,i._formValues,r,l.disabled,o,i._fields]);return _e.useEffect(()=>{const p=i._options.shouldUnregister||s,h=(g,v)=>{const S=oe(i._fields,g);S&&S._f&&(S._f.mount=v)};if(h(n,!0),p){const g=mt(oe(i._options.defaultValues,n));Me(i._defaultValues,n,g),Xe(oe(i._formValues,n))&&Me(i._formValues,n,g)}return!a&&i.register(n),()=>{(a?p&&!i._state.action:p)?i.unregister(n):h(n,!1)}},[n,i,a,s]),_e.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),_e.useMemo(()=>({field:d,formState:l,fieldState:f}),[d,l,f])}const Fg=e=>e.render($g(e));var Lg=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},Mo=e=>({isOnSubmit:!e||e===Ot.onSubmit,isOnBlur:e===Ot.onBlur,isOnChange:e===Ot.onChange,isOnAll:e===Ot.all,isOnTouch:e===Ot.onTouched}),$o=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Or=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=oe(e,i);if(s){const{_f:a,...o}=s;if(a){if(a.refs&&a.refs[0]&&t(a.refs[0],i)&&!r)return!0;if(a.ref&&t(a.ref,a.name)&&!r)return!0;if(Or(o,t))break}else if(Qe(o)&&Or(o,t))break}}};var Zg=(e,t,n)=>{const r=Pr(oe(e,n));return Me(r,"root",t[n]),Me(e,n,r),e},Wa=e=>e.type==="file",Vt=e=>typeof e=="function",Oi=e=>{if(!Ua)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Ni=e=>Ut(e),qa=e=>e.type==="radio",Di=e=>e instanceof RegExp;const Fo={value:!1,isValid:!1},Lo={value:!0,isValid:!0};var xd=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Xe(e[0].attributes.value)?Xe(e[0].value)||e[0].value===""?Lo:{value:e[0].value,isValid:!0}:Lo:Fo}return Fo};const Zo={isValid:!1,value:null};var yd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Zo):Zo;function Bo(e,t,n="validate"){if(Ni(e)||Array.isArray(e)&&e.every(Ni)||Nt(e)&&!e)return{type:n,message:Ni(e)?e:"",ref:t}}var Rn=e=>Qe(e)&&!Di(e)?e:{value:e,message:""},Vo=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:f,min:d,max:p,pattern:h,validate:g,name:v,valueAsNumber:S,mount:x}=e._f,_=oe(n,v);if(!x||t.has(v))return{};const m=o?o[0]:a,I=A=>{i&&m.reportValidity&&(m.setCustomValidity(Nt(A)?"":A||""),m.reportValidity())},E={},w=qa(a),N=si(a),O=w||N,K=(S||Wa(a))&&Xe(a.value)&&Xe(_)||Oi(a)&&a.value===""||_===""||Array.isArray(_)&&!_.length,C=Lg.bind(null,v,r,E),T=(A,F,R,L=Yt.maxLength,P=Yt.minLength)=>{const V=A?F:R;E[v]={type:A?L:P,message:V,ref:a,...C(A?L:P,V)}};if(s?!Array.isArray(_)||!_.length:l&&(!O&&(K||ct(_))||Nt(_)&&!_||N&&!xd(o).isValid||w&&!yd(o).isValid)){const{value:A,message:F}=Ni(l)?{value:!!l,message:l}:Rn(l);if(A&&(E[v]={type:Yt.required,message:F,ref:m,...C(Yt.required,F)},!r))return I(F),E}if(!K&&(!ct(d)||!ct(p))){let A,F;const R=Rn(p),L=Rn(d);if(!ct(_)&&!isNaN(_)){const P=a.valueAsNumber||_&&+_;ct(R.value)||(A=P>R.value),ct(L.value)||(F=P<L.value)}else{const P=a.valueAsDate||new Date(_),V=k=>new Date(new Date().toDateString()+" "+k),U=a.type=="time",se=a.type=="week";Ut(R.value)&&_&&(A=U?V(_)>V(R.value):se?_>R.value:P>new Date(R.value)),Ut(L.value)&&_&&(F=U?V(_)<V(L.value):se?_<L.value:P<new Date(L.value))}if((A||F)&&(T(!!A,R.message,L.message,Yt.max,Yt.min),!r))return I(E[v].message),E}if((c||f)&&!K&&(Ut(_)||s&&Array.isArray(_))){const A=Rn(c),F=Rn(f),R=!ct(A.value)&&_.length>+A.value,L=!ct(F.value)&&_.length<+F.value;if((R||L)&&(T(R,A.message,F.message),!r))return I(E[v].message),E}if(h&&!K&&Ut(_)){const{value:A,message:F}=Rn(h);if(Di(A)&&!_.match(A)&&(E[v]={type:Yt.pattern,message:F,ref:a,...C(Yt.pattern,F)},!r))return I(F),E}if(g){if(Vt(g)){const A=await g(_,n),F=Bo(A,m);if(F&&(E[v]={...F,...C(Yt.validate,F.message)},!r))return I(F.message),E}else if(Qe(g)){let A={};for(const F in g){if(!gt(A)&&!r)break;const R=Bo(await g[F](_,n),m,F);R&&(A={...R,...C(F,R.message)},I(R.message),r&&(E[v]=A))}if(!gt(A)&&(E[v]={ref:m,...A},!r))return E}}return I(!0),E};function Bg(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Xe(e)?r++:e[t[r++]];return e}function Vg(e){for(const t in e)if(e.hasOwnProperty(t)&&!Xe(e[t]))return!1;return!0}function rt(e,t){const n=Array.isArray(t)?t:Ja(t)?[t]:dd(t),r=n.length===1?e:Bg(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(Qe(r)&&gt(r)||Array.isArray(r)&&Vg(r))&&rt(e,n.slice(0,-1)),e}var Is=()=>{let e=[];return{get observers(){return e},next:i=>{for(const s of e)s.next&&s.next(i)},subscribe:i=>(e.push(i),{unsubscribe:()=>{e=e.filter(s=>s!==i)}}),unsubscribe:()=>{e=[]}}},da=e=>ct(e)||!ld(e);function un(e,t){if(da(e)||da(t))return e===t;if(jn(e)&&jn(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const s=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const a=t[i];if(jn(s)&&jn(a)||Qe(s)&&Qe(a)||Array.isArray(s)&&Array.isArray(a)?!un(s,a):s!==a)return!1}}return!0}var bd=e=>e.type==="select-multiple",Ug=e=>qa(e)||si(e),Ts=e=>Oi(e)&&e.isConnected,vd=e=>{for(const t in e)if(Vt(e[t]))return!0;return!1};function Ri(e,t={}){const n=Array.isArray(e);if(Qe(e)||n)for(const r in e)Array.isArray(e[r])||Qe(e[r])&&!vd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Ri(e[r],t[r])):ct(e[r])||(t[r]=!0);return t}function wd(e,t,n){const r=Array.isArray(e);if(Qe(e)||r)for(const i in e)Array.isArray(e[i])||Qe(e[i])&&!vd(e[i])?Xe(t)||da(n[i])?n[i]=Array.isArray(e[i])?Ri(e[i],[]):{...Ri(e[i])}:wd(e[i],ct(t)?{}:t[i],n[i]):n[i]=!un(e[i],t[i]);return n}var yr=(e,t)=>wd(e,t,Ri(t)),kd=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Xe(e)?e:t?e===""?NaN:e&&+e:n&&Ut(e)?new Date(e):r?r(e):e;function zs(e){const t=e.ref;return Wa(t)?t.files:qa(t)?yd(e.refs).value:bd(t)?[...t.selectedOptions].map(({value:n})=>n):si(t)?xd(e.refs).value:kd(Xe(t.value)?e.ref.value:t.value,e)}var Jg=(e,t,n,r)=>{const i={};for(const s of e){const a=oe(t,s);a&&Me(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},br=e=>Xe(e)?e:Di(e)?e.source:Qe(e)?Di(e.value)?e.value.source:e.value:e;const Uo="AsyncFunction";var Hg=e=>!!e&&!!e.validate&&!!(Vt(e.validate)&&e.validate.constructor.name===Uo||Qe(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Uo)),Wg=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Jo(e,t,n){const r=oe(e,n);if(r||Ja(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=oe(t,s),o=oe(e,s);if(a&&!Array.isArray(a)&&n!==s)return{name:n};if(o&&o.type)return{name:s,error:o};i.pop()}return{name:n}}var qg=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,Gg=(e,t)=>!ls(oe(e,t)).length&&rt(e,t);const Kg={mode:Ot.onSubmit,reValidateMode:Ot.onChange,shouldFocusError:!0};function Yg(e={}){let t={...Kg,...e},n={submitCount:0,isDirty:!1,isLoading:Vt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=Qe(t.defaultValues)||Qe(t.values)?mt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:mt(i),a={action:!1,mount:!1,watch:!1},o={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const f={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={values:Is(),array:Is(),state:Is()},p=Mo(t.mode),h=Mo(t.reValidateMode),g=t.criteriaMode===Ot.all,v=j=>z=>{clearTimeout(c),c=setTimeout(j,z)},S=async j=>{if(!t.disabled&&(f.isValid||j)){const z=t.resolver?gt((await O()).errors):await C(r,!0);z!==n.isValid&&d.state.next({isValid:z})}},x=(j,z)=>{!t.disabled&&(f.isValidating||f.validatingFields)&&((j||Array.from(o.mount)).forEach(M=>{M&&(z?Me(n.validatingFields,M,z):rt(n.validatingFields,M))}),d.state.next({validatingFields:n.validatingFields,isValidating:!gt(n.validatingFields)}))},_=(j,z=[],M,re,ee=!0,Q=!0)=>{if(re&&M&&!t.disabled){if(a.action=!0,Q&&Array.isArray(oe(r,j))){const pe=M(oe(r,j),re.argA,re.argB);ee&&Me(r,j,pe)}if(Q&&Array.isArray(oe(n.errors,j))){const pe=M(oe(n.errors,j),re.argA,re.argB);ee&&Me(n.errors,j,pe),Gg(n.errors,j)}if(f.touchedFields&&Q&&Array.isArray(oe(n.touchedFields,j))){const pe=M(oe(n.touchedFields,j),re.argA,re.argB);ee&&Me(n.touchedFields,j,pe)}f.dirtyFields&&(n.dirtyFields=yr(i,s)),d.state.next({name:j,isDirty:A(j,z),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Me(s,j,z)},m=(j,z)=>{Me(n.errors,j,z),d.state.next({errors:n.errors})},I=j=>{n.errors=j,d.state.next({errors:n.errors,isValid:!1})},E=(j,z,M,re)=>{const ee=oe(r,j);if(ee){const Q=oe(s,j,Xe(M)?oe(i,j):M);Xe(Q)||re&&re.defaultChecked||z?Me(s,j,z?Q:zs(ee._f)):L(j,Q),a.mount&&S()}},w=(j,z,M,re,ee)=>{let Q=!1,pe=!1;const we={name:j};if(!t.disabled){const $=!!(oe(r,j)&&oe(r,j)._f&&oe(r,j)._f.disabled);if(!M||re){f.isDirty&&(pe=n.isDirty,n.isDirty=we.isDirty=A(),Q=pe!==we.isDirty);const G=$||un(oe(i,j),z);pe=!!(!$&&oe(n.dirtyFields,j)),G||$?rt(n.dirtyFields,j):Me(n.dirtyFields,j,!0),we.dirtyFields=n.dirtyFields,Q=Q||f.dirtyFields&&pe!==!G}if(M){const G=oe(n.touchedFields,j);G||(Me(n.touchedFields,j,M),we.touchedFields=n.touchedFields,Q=Q||f.touchedFields&&G!==M)}Q&&ee&&d.state.next(we)}return Q?we:{}},N=(j,z,M,re)=>{const ee=oe(n.errors,j),Q=f.isValid&&Nt(z)&&n.isValid!==z;if(t.delayError&&M?(l=v(()=>m(j,M)),l(t.delayError)):(clearTimeout(c),l=null,M?Me(n.errors,j,M):rt(n.errors,j)),(M?!un(ee,M):ee)||!gt(re)||Q){const pe={...re,...Q&&Nt(z)?{isValid:z}:{},errors:n.errors,name:j};n={...n,...pe},d.state.next(pe)}},O=async j=>{x(j,!0);const z=await t.resolver(s,t.context,Jg(j||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return x(j),z},K=async j=>{const{errors:z}=await O(j);if(j)for(const M of j){const re=oe(z,M);re?Me(n.errors,M,re):rt(n.errors,M)}else n.errors=z;return z},C=async(j,z,M={valid:!0})=>{for(const re in j){const ee=j[re];if(ee){const{_f:Q,...pe}=ee;if(Q){const we=o.array.has(Q.name),$=ee._f&&Hg(ee._f);$&&f.validatingFields&&x([re],!0);const G=await Vo(ee,o.disabled,s,g,t.shouldUseNativeValidation&&!z,we);if($&&f.validatingFields&&x([re]),G[Q.name]&&(M.valid=!1,z))break;!z&&(oe(G,Q.name)?we?Zg(n.errors,G,Q.name):Me(n.errors,Q.name,G[Q.name]):rt(n.errors,Q.name))}!gt(pe)&&await C(pe,z,M)}}return M.valid},T=()=>{for(const j of o.unMount){const z=oe(r,j);z&&(z._f.refs?z._f.refs.every(M=>!Ts(M)):!Ts(z._f.ref))&&ie(j)}o.unMount=new Set},A=(j,z)=>!t.disabled&&(j&&z&&Me(s,j,z),!un(le(),i)),F=(j,z,M)=>gd(j,o,{...a.mount?s:Xe(z)?i:Ut(j)?{[j]:z}:z},M,z),R=j=>ls(oe(a.mount?s:i,j,t.shouldUnregister?oe(i,j,[]):[])),L=(j,z,M={})=>{const re=oe(r,j);let ee=z;if(re){const Q=re._f;Q&&(!Q.disabled&&Me(s,j,kd(z,Q)),ee=Oi(Q.ref)&&ct(z)?"":z,bd(Q.ref)?[...Q.ref.options].forEach(pe=>pe.selected=ee.includes(pe.value)):Q.refs?si(Q.ref)?Q.refs.length>1?Q.refs.forEach(pe=>(!pe.defaultChecked||!pe.disabled)&&(pe.checked=Array.isArray(ee)?!!ee.find(we=>we===pe.value):ee===pe.value)):Q.refs[0]&&(Q.refs[0].checked=!!ee):Q.refs.forEach(pe=>pe.checked=pe.value===ee):Wa(Q.ref)?Q.ref.value="":(Q.ref.value=ee,Q.ref.type||d.values.next({name:j,values:{...s}})))}(M.shouldDirty||M.shouldTouch)&&w(j,ee,M.shouldTouch,M.shouldDirty,!0),M.shouldValidate&&k(j)},P=(j,z,M)=>{for(const re in z){const ee=z[re],Q=`${j}.${re}`,pe=oe(r,Q);(o.array.has(j)||Qe(ee)||pe&&!pe._f)&&!jn(ee)?P(Q,ee,M):L(Q,ee,M)}},V=(j,z,M={})=>{const re=oe(r,j),ee=o.array.has(j),Q=mt(z);Me(s,j,Q),ee?(d.array.next({name:j,values:{...s}}),(f.isDirty||f.dirtyFields)&&M.shouldDirty&&d.state.next({name:j,dirtyFields:yr(i,s),isDirty:A(j,Q)})):re&&!re._f&&!ct(Q)?P(j,Q,M):L(j,Q,M),$o(j,o)&&d.state.next({...n}),d.values.next({name:a.mount?j:void 0,values:{...s}})},U=async j=>{a.mount=!0;const z=j.target;let M=z.name,re=!0;const ee=oe(r,M),Q=()=>z.type?zs(ee._f):ud(j),pe=we=>{re=Number.isNaN(we)||jn(we)&&isNaN(we.getTime())||un(we,oe(s,M,we))};if(ee){let we,$;const G=Q(),he=j.type===Pi.BLUR||j.type===Pi.FOCUS_OUT,je=!Wg(ee._f)&&!t.resolver&&!oe(n.errors,M)&&!ee._f.deps||qg(he,oe(n.touchedFields,M),n.isSubmitted,h,p),D=$o(M,o,he);Me(s,M,G),he?(ee._f.onBlur&&ee._f.onBlur(j),l&&l(0)):ee._f.onChange&&ee._f.onChange(j);const ge=w(M,G,he,!1),Te=!gt(ge)||D;if(!he&&d.values.next({name:M,type:j.type,values:{...s}}),je)return f.isValid&&(t.mode==="onBlur"&&he?S():he||S()),Te&&d.state.next({name:M,...D?{}:ge});if(!he&&D&&d.state.next({...n}),t.resolver){const{errors:Le}=await O([M]);if(pe(G),re){const nt=Jo(n.errors,r,M),et=Jo(Le,r,nt.name||M);we=et.error,M=et.name,$=gt(Le)}}else x([M],!0),we=(await Vo(ee,o.disabled,s,g,t.shouldUseNativeValidation))[M],x([M]),pe(G),re&&(we?$=!1:f.isValid&&($=await C(r,!0)));re&&(ee._f.deps&&k(ee._f.deps),N(M,$,we,ge))}},se=(j,z)=>{if(oe(n.errors,z)&&j.focus)return j.focus(),1},k=async(j,z={})=>{let M,re;const ee=Pr(j);if(t.resolver){const Q=await K(Xe(j)?j:ee);M=gt(Q),re=j?!ee.some(pe=>oe(Q,pe)):M}else j?(re=(await Promise.all(ee.map(async Q=>{const pe=oe(r,Q);return await C(pe&&pe._f?{[Q]:pe}:pe)}))).every(Boolean),!(!re&&!n.isValid)&&S()):re=M=await C(r);return d.state.next({...!Ut(j)||f.isValid&&M!==n.isValid?{}:{name:j},...t.resolver||!j?{isValid:M}:{},errors:n.errors}),z.shouldFocus&&!re&&Or(r,se,j?ee:o.mount),re},le=j=>{const z={...a.mount?s:i};return Xe(j)?z:Ut(j)?oe(z,j):j.map(M=>oe(z,M))},q=(j,z)=>({invalid:!!oe((z||n).errors,j),isDirty:!!oe((z||n).dirtyFields,j),error:oe((z||n).errors,j),isValidating:!!oe(n.validatingFields,j),isTouched:!!oe((z||n).touchedFields,j)}),y=j=>{j&&Pr(j).forEach(z=>rt(n.errors,z)),d.state.next({errors:j?n.errors:{}})},W=(j,z,M)=>{const re=(oe(r,j,{_f:{}})._f||{}).ref,ee=oe(n.errors,j)||{},{ref:Q,message:pe,type:we,...$}=ee;Me(n.errors,j,{...$,...z,ref:re}),d.state.next({name:j,errors:n.errors,isValid:!1}),M&&M.shouldFocus&&re&&re.focus&&re.focus()},B=(j,z)=>Vt(j)?d.values.subscribe({next:M=>j(F(void 0,z),M)}):F(j,z,!0),ie=(j,z={})=>{for(const M of j?Pr(j):o.mount)o.mount.delete(M),o.array.delete(M),z.keepValue||(rt(r,M),rt(s,M)),!z.keepError&&rt(n.errors,M),!z.keepDirty&&rt(n.dirtyFields,M),!z.keepTouched&&rt(n.touchedFields,M),!z.keepIsValidating&&rt(n.validatingFields,M),!t.shouldUnregister&&!z.keepDefaultValue&&rt(i,M);d.values.next({values:{...s}}),d.state.next({...n,...z.keepDirty?{isDirty:A()}:{}}),!z.keepIsValid&&S()},te=({disabled:j,name:z,field:M,fields:re})=>{(Nt(j)&&a.mount||j||o.disabled.has(z))&&(j?o.disabled.add(z):o.disabled.delete(z),w(z,zs(M?M._f:oe(re,z)._f),!1,!1,!0))},X=(j,z={})=>{let M=oe(r,j);const re=Nt(z.disabled)||Nt(t.disabled);return Me(r,j,{...M||{},_f:{...M&&M._f?M._f:{ref:{name:j}},name:j,mount:!0,...z}}),o.mount.add(j),M?te({field:M,disabled:Nt(z.disabled)?z.disabled:t.disabled,name:j}):E(j,!0,z.value),{...re?{disabled:z.disabled||t.disabled}:{},...t.progressive?{required:!!z.required,min:br(z.min),max:br(z.max),minLength:br(z.minLength),maxLength:br(z.maxLength),pattern:br(z.pattern)}:{},name:j,onChange:U,onBlur:U,ref:ee=>{if(ee){X(j,z),M=oe(r,j);const Q=Xe(ee.value)&&ee.querySelectorAll&&ee.querySelectorAll("input,select,textarea")[0]||ee,pe=Ug(Q),we=M._f.refs||[];if(pe?we.find($=>$===Q):Q===M._f.ref)return;Me(r,j,{_f:{...M._f,...pe?{refs:[...we.filter(Ts),Q,...Array.isArray(oe(i,j))?[{}]:[]],ref:{type:Q.type,name:j}}:{ref:Q}}}),E(j,!1,void 0,Q)}else M=oe(r,j,{}),M._f&&(M._f.mount=!1),(t.shouldUnregister||z.shouldUnregister)&&!(cd(o.array,j)&&a.action)&&o.unMount.add(j)}}},fe=()=>t.shouldFocusError&&Or(r,se,o.mount),be=j=>{Nt(j)&&(d.state.next({disabled:j}),Or(r,(z,M)=>{const re=oe(r,M);re&&(z.disabled=re._f.disabled||j,Array.isArray(re._f.refs)&&re._f.refs.forEach(ee=>{ee.disabled=re._f.disabled||j}))},0,!1))},ne=(j,z)=>async M=>{let re;M&&(M.preventDefault&&M.preventDefault(),M.persist&&M.persist());let ee=mt(s);if(o.disabled.size)for(const Q of o.disabled)Me(ee,Q,void 0);if(d.state.next({isSubmitting:!0}),t.resolver){const{errors:Q,values:pe}=await O();n.errors=Q,ee=pe}else await C(r);if(rt(n.errors,"root"),gt(n.errors)){d.state.next({errors:{}});try{await j(ee,M)}catch(Q){re=Q}}else z&&await z({...n.errors},M),fe(),setTimeout(fe);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:gt(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},de=(j,z={})=>{oe(r,j)&&(Xe(z.defaultValue)?V(j,mt(oe(i,j))):(V(j,z.defaultValue),Me(i,j,mt(z.defaultValue))),z.keepTouched||rt(n.touchedFields,j),z.keepDirty||(rt(n.dirtyFields,j),n.isDirty=z.defaultValue?A(j,mt(oe(i,j))):A()),z.keepError||(rt(n.errors,j),f.isValid&&S()),d.state.next({...n}))},ue=(j,z={})=>{const M=j?mt(j):i,re=mt(M),ee=gt(j),Q=ee?i:re;if(z.keepDefaultValues||(i=M),!z.keepValues){if(z.keepDirtyValues){const pe=new Set([...o.mount,...Object.keys(yr(i,s))]);for(const we of Array.from(pe))oe(n.dirtyFields,we)?Me(Q,we,oe(s,we)):V(we,oe(Q,we))}else{if(Ua&&Xe(j))for(const pe of o.mount){const we=oe(r,pe);if(we&&we._f){const $=Array.isArray(we._f.refs)?we._f.refs[0]:we._f.ref;if(Oi($)){const G=$.closest("form");if(G){G.reset();break}}}}r={}}s=t.shouldUnregister?z.keepDefaultValues?mt(i):{}:mt(Q),d.array.next({values:{...Q}}),d.values.next({values:{...Q}})}o={mount:z.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!f.isValid||!!z.keepIsValid||!!z.keepDirtyValues,a.watch=!!t.shouldUnregister,d.state.next({submitCount:z.keepSubmitCount?n.submitCount:0,isDirty:ee?!1:z.keepDirty?n.isDirty:!!(z.keepDefaultValues&&!un(j,i)),isSubmitted:z.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ee?{}:z.keepDirtyValues?z.keepDefaultValues&&s?yr(i,s):n.dirtyFields:z.keepDefaultValues&&j?yr(i,j):z.keepDirty?n.dirtyFields:{},touchedFields:z.keepTouched?n.touchedFields:{},errors:z.keepErrors?n.errors:{},isSubmitSuccessful:z.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},Z=(j,z)=>ue(Vt(j)?j(s):j,z);return{control:{register:X,unregister:ie,getFieldState:q,handleSubmit:ne,setError:W,_executeSchema:O,_getWatch:F,_getDirty:A,_updateValid:S,_removeUnmounted:T,_updateFieldArray:_,_updateDisabledField:te,_getFieldArray:R,_reset:ue,_resetDefaultValues:()=>Vt(t.defaultValues)&&t.defaultValues().then(j=>{Z(j,t.resetOptions),d.state.next({isLoading:!1})}),_updateFormState:j=>{n={...n,...j}},_disableForm:be,_subjects:d,_proxyFormState:f,_setErrors:I,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(j){a=j},get _defaultValues(){return i},get _names(){return o},set _names(j){o=j},get _formState(){return n},set _formState(j){n=j},get _options(){return t},set _options(j){t={...t,...j}}},trigger:k,register:X,handleSubmit:ne,watch:B,setValue:V,getValues:le,reset:Z,resetField:de,clearErrors:y,unregister:ie,setError:W,setFocus:(j,z={})=>{const M=oe(r,j),re=M&&M._f;if(re){const ee=re.refs?re.refs[0]:re.ref;ee.focus&&(ee.focus(),z.shouldSelect&&Vt(ee.select)&&ee.select())}},getFieldState:q}}function Xg(e={}){const t=_e.useRef(void 0),n=_e.useRef(void 0),[r,i]=_e.useState({isDirty:!1,isValidating:!1,isLoading:Vt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Vt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Yg(e),formState:r});const s=t.current.control;return s._options=e,Ha({subject:s._subjects.state,next:a=>{hd(a,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),_e.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),_e.useEffect(()=>{if(s._proxyFormState.isDirty){const a=s._getDirty();a!==r.isDirty&&s._subjects.state.next({isDirty:a})}},[s,r.isDirty]),_e.useEffect(()=>{e.values&&!un(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(a=>({...a}))):s._resetDefaultValues()},[e.values,s]),_e.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),_e.useEffect(()=>{s._state.mount||(s._updateValid(),s._state.mount=!0),s._state.watch&&(s._state.watch=!1,s._subjects.state.next({...s._formState})),s._removeUnmounted()}),_e.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=pd(r,s),t.current}function Qg(e){return async t=>{const n=e(t);if(n.success&&n.data)return{values:n.data,errors:{}};const r={};if(n.errors)for(const i of n.errors){const s=i.path||"root";r[s]||(r[s]={type:"validation",message:i.message})}return{values:{},errors:r}}}const ex=Dg,Sd=b.createContext({}),Ho=({...e})=>u.jsx(Sd.Provider,{value:{name:e.name},children:u.jsx(Fg,{...e})}),cs=()=>{const e=b.useContext(Sd),t=b.useContext(_d),{getFieldState:n,formState:r}=us(),i=n(e.name,r);if(!e)throw new Error("useFormField should be used within <FormField>");const{id:s}=t;return{id:s,name:e.name,formItemId:`${s}-form-item`,formDescriptionId:`${s}-form-item-description`,formMessageId:`${s}-form-item-message`,...i}},_d=b.createContext({}),fa=b.forwardRef(({className:e,...t},n)=>{const r=b.useId();return u.jsx(_d.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:H("space-y-2",e),...t})})});fa.displayName="FormItem";const pa=b.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=cs();return u.jsx(Xn,{ref:n,className:H(r&&"text-destructive",e),htmlFor:i,...t})});pa.displayName="FormLabel";const ha=b.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=cs();return u.jsx(dr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});ha.displayName="FormControl";const jd=b.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=cs();return u.jsx("p",{ref:n,id:r,className:H("text-muted-foreground text-[0.8rem]",e),...t})});jd.displayName="FormDescription";const ma=b.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=cs(),a=i?String(i==null?void 0:i.message):t;return a?u.jsx("p",{ref:r,id:s,className:H("text-destructive text-[0.8rem] font-medium",e),...n,children:a}):null});ma.displayName="FormMessage";function Ga(){const e=new Date,t=n=>String(n).padStart(2,"0");return`Chat ${t(e.getMonth()+1)}/${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}const Cd=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),tx=(e=Cd())=>wg()(kg(Sg((t,n)=>({...e,toggleChat:()=>t(r=>({chatOpen:!r.chatOpen})),openChat:()=>t({chatOpen:!0}),closeChat:()=>t({chatOpen:!1}),addContext:r=>t(i=>({contextAttachments:[...i.contextAttachments,r]})),removeContext:r=>t(i=>({contextAttachments:i.contextAttachments.filter((s,a)=>a!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),a={id:i,documentName:r,title:Ga(),messages:[],createdAt:s,updatedAt:s};return t(o=>({threads:{...o.threads,[i]:a},activeThreadId:{...o.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const a=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),o=s.documentName,l={...i.activeThreadId};if(l[o]===r){const c=Object.values(a).filter(f=>f.documentName===o);c.length>0?(c.sort((f,d)=>d.updatedAt-f.updatedAt),l[o]=c[0].id):delete l[o]}t({threads:a,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(a=>({activeThreadId:{...a.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},a={...i.activeThreadId};for(const[o,l]of Object.entries(s))l.documentName===r&&delete s[o];return delete a[r],{threads:s,activeThreadId:a}})},renameThreadsForDocument:(r,i)=>{t(s=>{const a={...s.threads},o={...s.activeThreadId};for(const[l,c]of Object.entries(a))c.documentName===r&&(a[l]={...c,documentName:i});return r in o&&(o[i]=o[r],delete o[r]),{threads:a,activeThreadId:o}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:_g(()=>hg),partialize:t=>({threads:t.threads,activeThreadId:t.activeThreadId,scope:t.scope,model:t.model}),migrate:(t,n)=>{if(n===0&&t){const r=t.chatMessages;if(Array.isArray(r)&&r.length>0){const i=crypto.randomUUID(),s=Date.now();return{threads:{[i]:{id:i,documentName:"__migrated__",title:"Migrated Chat",messages:r,createdAt:s,updatedAt:s}},activeThreadId:{__migrated__:i}}}return{threads:{},activeThreadId:{}}}return t}}))),Nd=b.createContext(void 0),nx=({children:e})=>{const t=b.useRef(null);return t.current||(t.current=tx(Cd())),u.jsx(Nd.Provider,{value:t.current,children:e})},Pe=e=>{const t=b.useContext(Nd);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return jg(t,e)};function rx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function ix(e,t,n){const r={},i=[];e!=="delete"&&(r.name=fi.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),i.push("name")),e==="create"&&(r.template=fi.Optional(fi.String({description:"Template selection"})));const s=fi.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:a=>{const o=[];if(!Dm(s,a))for(const c of Rm(s,a))o.push({path:c.path.replace(/^\//,""),message:c.message});const l=a;if(e!=="delete"&&l.name){const c=l.name.trim();c?(l.name=c,t(c)||o.push({path:"name",message:"Document with this name already exists"})):o.push({path:"name",message:"Name can't be empty"})}return e==="create"&&(n!=null&&n.length)&&l.template&&(n.some(c=>c.name===l.template)||o.push({path:"template",message:"You must select a valid template"})),{success:o.length===0,data:o.length===0?l:void 0,errors:o}}}}function sx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const ax=e=>({create:{title:e?"New Theme":"New Document",description:e?"Create a new theme from scratch or based on discovered themes.":"Create a new document from scratch or based on discovered documents.",button:"Create",buttonVariant:"default"},update:{title:"Rename Document",description:"Give your document a new name.",button:"Save",buttonVariant:"default"},delete:{title:"Are you absolutely sure?",description:"This action cannot be undone. Are you sure you want to permanently delete this document?",button:"Confirm",buttonVariant:"destructive"}}),Mn="__empty__";function ox({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=b.useState(!1),[c,f]=b.useState(null),[d,p]=b.useState("idle"),{toast:h}=fr(),g=ax(a),{documents:v,openTabs:S,createDocument:x,renameDocument:_,deleteDocument:m,openDocument:I,closeDocument:E}=Oe(le=>le),{updateTheme:w,removeTheme:N}=ca(le=>le),O=Pe(le=>le.renameThreadsForDocument),K=Pe(le=>le.deleteThreadsForDocument),C=b.useMemo(()=>a?s||[]:i||[],[a,i,s]),T=b.useMemo(()=>{const le={current:[],downstream:[]};return C.forEach(q=>{le[q.location]&&le[q.location].push(q)}),le},[C]),A=b.useMemo(()=>C.map(le=>({name:le.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[C]),F=b.useMemo(()=>ix(e,le=>rx(le,v,r),A),[e,v,r,A]),R=F.schema,L=b.useMemo(()=>{const le=new Map;return C.forEach(q=>le.set(q.path,q)),le},[C]),P=Mn,V=Xg({resolver:Qg(F.validate),defaultValues:sx(e,void 0,r)}),[U,se]=b.useState(P);b.useEffect(()=>{if(U&&U!==Mn&&e==="create"){const le=L.get(U);if(le){f(null),p("loading");let q=!1;return fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(le.name)}/content`).then(y=>{if(!y.ok)throw new Error(`Failed to fetch content: ${y.statusText}`);return y.text()}).then(y=>{if(q)return;const W=JSON.parse(y);f(JSON.stringify(W,null,2)),p("idle")}).catch(y=>{q||(console.error("Failed to copy template:",y),f(null),p("error"))}),()=>{q=!0}}}p("idle")},[U,e,L,a]),b.useEffect(()=>{t&&(V.reset(),f(null),p("idle"),se(P))},[V,t]);const k=V.handleSubmit(async({name:le,template:q})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=U?L.get(U):C.find(de=>de.name===q);let W,B=le;if(!!U&&U!==Mn&&c===null){h({title:d==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:d==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(a){const de=B.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),ue=yt==="docx"?Mm(de):{name:de,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};W=c||JSON.stringify(ue,null,2);const Z=`.${yt}.theme.json`;B.endsWith(Z)||(B=B.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),B+=Z)}else{const de=y;W=c||JSON.stringify(yt==="docx"?{name:"docx",props:{theme:(de==null?void 0:de.theme)||"default",metadata:{title:(de==null?void 0:de.title)||B.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(de==null?void 0:de.title)||B.replace(/\.(json|js)$/i,""),theme:(de==null?void 0:de.theme)||"default"},children:[{name:"slide",props:{},children:[{name:"text",props:{text:"Start writing your presentation content here...",fontSize:24,y:2,x:1,w:8}}]}]},null,2);const ue=yt==="docx"?".docx.json":".pptx.json";!B.endsWith(ue)&&!B.endsWith(".json")&&(B+=ue)}const te=B.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),X=te?te[0]:"",fe=B.slice(0,B.length-X.length);let be=B,ne=1;for(;v.some(de=>de.name===be);)ne++,be=`${fe} (${ne})${X}`;B=be,x(B,W),I(B),a&&w(B,W)}else if(e==="update"){const y=r,W=le,B=S.includes(y);B&&E(y),_(y,W),O(y,W),B&&I(W)}else if(e==="delete"){const y=r;E(y),m(y),K(y),a&&N(y)}n()}finally{l(!1)}});return u.jsx(ex,{...V,children:u.jsxs("form",{onSubmit:k,children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:g[e].title}),u.jsx(hn,{children:g[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[R.properties&&"name"in R.properties&&u.jsx(Ho,{control:V.control,name:"name",render:({field:le})=>u.jsxs(fa,{children:[u.jsx(pa,{children:"Name"}),u.jsx(ha,{children:u.jsx(ii,{placeholder:"Enter a name or select a template below",autoComplete:"off",...le})}),u.jsx(ma,{})]})}),e==="create"&&u.jsx(Ho,{control:V.control,name:"template",render:({field:le})=>u.jsxs(fa,{children:[u.jsx(pa,{children:a?"Base Theme":"Base Document"}),u.jsxs(Fr,{onValueChange:q=>{if(q===Mn)le.onChange(void 0),V.setValue("name",""),se(Mn),f(null);else{const y=L.get(q);y&&(le.onChange(y.name),V.setValue("name",y.name),se(q))}},defaultValue:P,children:[u.jsx(ha,{children:u.jsx(rr,{children:u.jsx(Lr,{placeholder:`Select a discovered ${a?"theme":"document"}`})})}),u.jsxs(ir,{className:"max-h-[300px]",children:[u.jsxs(Tn,{value:Mn,children:["Empty ",a?"theme":"document"]}),Object.entries(T).map(([q,y])=>y.length===0?null:u.jsxs(Eg,{children:[u.jsx(od,{children:q==="current"?"📁 Current Directory":"📦 Project"}),y.map(W=>{let B;return W.title&&W.title!==W.name?B=W.title:W.description&&(B=W.description.length>40?W.description.substring(0,40)+"...":W.description),u.jsx(Tn,{value:W.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:W.name}),B&&u.jsx("span",{className:"text-muted-foreground text-xs",children:B})]})},W.path)})]},q))]})]}),u.jsxs(jd,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(ma,{})]})})]}),u.jsx(In,{children:u.jsx(Ee,{type:"submit",variant:g[e].buttonVariant,disabled:o,children:o?u.jsxs(u.Fragment,{children:[u.jsx(en,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):g[e].button})})]})})}const Mi=_e.memo(ox);function sn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function Ka({text:e,query:t}){if(!t)return u.jsx(u.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?u.jsx(u.Fragment,{children:e}):u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Wo({children:e,count:t,actions:n,className:r}){return u.jsxs("div",{className:H("flex h-6 shrink-0 items-center gap-1.5 px-1 select-none",r),children:[u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] text-sidebar-foreground/70 uppercase",children:e}),t!==void 0&&u.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t}),n&&u.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:n})]})}const Ft=_e.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:H("flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm","text-sidebar-foreground/55 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","disabled:pointer-events-none disabled:opacity-40","[&>svg]:size-3.5",e),...t}));Ft.displayName="RailIconButton";function qo({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:H("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function Go({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:H("flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(e,{className:"size-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:t})]}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const lx=bm,ux=vm,cx=b.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(kc,{ref:i,className:H("focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none",t&&"pl-8",e),...r,children:[n,u.jsx(ri,{className:"ml-auto h-4 w-4"})]}));cx.displayName=kc.displayName;const dx=b.forwardRef(({className:e,...t},n)=>u.jsx(Sc,{ref:n,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));dx.displayName=Sc.displayName;const Ed=b.forwardRef(({className:e,...t},n)=>u.jsx(wm,{children:u.jsx(bc,{ref:n,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md",e),...t})}));Ed.displayName=bc.displayName;const Id=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(wc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Id.displayName=wc.displayName;const fx=b.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(_c,{ref:i,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(jc,{children:u.jsx(pn,{className:"h-4 w-4"})})}),t]}));fx.displayName=_c.displayName;const px=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Cc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(jc,{children:u.jsx(Wc,{className:"h-4 w-4 fill-current"})})}),t]}));px.displayName=Cc.displayName;const hx=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Nc,{ref:r,className:H("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));hx.displayName=Nc.displayName;const Td=b.forwardRef(({className:e,...t},n)=>u.jsx(vc,{ref:n,className:H("bg-border -mx-1 my-1 h-px",e),...t}));Td.displayName=vc.displayName;const zd=({className:e,...t})=>u.jsx("span",{className:H("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});zd.displayName="ContextMenuShortcut";const ds=km,fs=Sm,mx=b.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(Ac,{ref:i,className:H("focus:bg-accent data-[state=open]:bg-accent flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none select-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",e),...r,children:[n,u.jsx(ri,{className:"ml-auto"})]}));mx.displayName=Ac.displayName;const gx=b.forwardRef(({className:e,...t},n)=>u.jsx(Pc,{ref:n,className:H("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));gx.displayName=Pc.displayName;const ai=b.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(_m,{children:u.jsx(Ec,{ref:r,sideOffset:t,className:H("bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));ai.displayName=Ec.displayName;const Bt=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Ic,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",e),...n}));Bt.displayName=Ic.displayName;const xx=b.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Oc,{ref:i,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Dc,{children:u.jsx(pn,{className:"h-4 w-4"})})}),t]}));xx.displayName=Oc.displayName;const yx=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Rc,{ref:r,className:H("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Dc,{children:u.jsx(Wc,{className:"h-2 w-2 fill-current"})})}),t]}));yx.displayName=Rc.displayName;const Ad=b.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(zc,{ref:r,className:H("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Ad.displayName=zc.displayName;const sr=b.forwardRef(({className:e,...t},n)=>u.jsx(Tc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));sr.displayName=Tc.displayName;const Pd=({className:e,...t})=>u.jsx("span",{className:H("ml-auto text-xs tracking-widest opacity-60",e),...t});Pd.displayName="DropdownMenuShortcut";const Od=b.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(Mc,{ref:i,decorative:n,orientation:t,className:H("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Od.displayName=Mc.displayName;const Dd=uc,bx=jm,vx=cc,Rd=b.forwardRef(({className:e,...t},n)=>u.jsx(as,{className:H("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t,ref:n}));Rd.displayName=as.displayName;const wx=ni("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Ya=b.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(vx,{children:[u.jsx(Rd,{}),u.jsxs(rs,{ref:i,className:H(wx({side:e}),t),...r,children:[u.jsxs(Ba,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none",children:[u.jsx(fn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));Ya.displayName=rs.displayName;const kx=b.forwardRef(({className:e,...t},n)=>u.jsx(is,{ref:n,className:H("text-foreground text-lg font-semibold",e),...t}));kx.displayName=is.displayName;const Sx=b.forwardRef(({className:e,...t},n)=>u.jsx(ss,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));Sx.displayName=ss.displayName;function Dr({className:e,...t}){return u.jsx("div",{className:H("bg-primary/10 animate-pulse rounded-md",e),...t})}const As=768,Ps=1200;function Md(e){return typeof window<"u"?window.innerWidth<e:!1}function $d(){const[e,t]=b.useState(()=>Md(As));return b.useEffect(()=>{const n=window.matchMedia(`(max-width: ${As-1}px)`),r=()=>{t(window.innerWidth<As)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function _x(){const[e,t]=b.useState(()=>Md(Ps));return b.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ps-1}px)`),r=()=>{t(window.innerWidth<Ps)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const jx="sidebar_state",Cx=60*60*24*7,Nx="16rem",Ex="18rem",Ix="3rem",Tx="b",Fd=b.createContext(null);function ps(){const e=b.useContext(Fd);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const Ld=b.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=$d(),[c,f]=b.useState(!1),[d,p]=b.useState(e),h=t??d,g=b.useCallback(_=>{const m=typeof _=="function"?_(h):_;n?n(m):p(m),document.cookie=`${jx}=${m}; path=/; max-age=${Cx}`},[n,h]),v=b.useCallback(()=>l?f(_=>!_):g(_=>!_),[l,g,f]);b.useEffect(()=>{const _=I=>{var N;const E=I;if(!E)return!1;const w=(N=E.tagName)==null?void 0:N.toLowerCase();return w==="input"||w==="textarea"||w==="select"||E.isContentEditable?!0:!!(E.closest&&E.closest(".monaco-editor"))},m=I=>{const E=I.metaKey||I.ctrlKey,w=I.key.toLowerCase();if(E&&w===Tx){I.preventDefault(),v();return}E&&w==="s"&&!_(I.target)&&(I.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const S=h?"expanded":"collapsed",x=b.useMemo(()=>({state:S,open:h,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:f,toggleSidebar:v}),[S,h,g,l,c,f,v]);return u.jsx(Fd.Provider,{value:x,children:u.jsx($m,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":Nx,"--sidebar-width-icon":Ix,...i},className:H("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});Ld.displayName="SidebarProvider";const Zd=b.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},a)=>{const{isMobile:o,state:l,openMobile:c,setOpenMobile:f}=ps();return n==="none"?u.jsx("div",{className:H("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:a,...s,children:i}):o?u.jsx(Dd,{open:c,onOpenChange:f,...s,children:u.jsx(Ya,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":Ex},side:e,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):u.jsxs("div",{ref:a,className:"group peer text-sidebar-foreground hidden md:block","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":t,"data-side":e,children:[u.jsx("div",{className:H("relative h-svh w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),u.jsx("div",{className:H("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",e==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...s,children:u.jsx("div",{"data-sidebar":"sidebar",className:"bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow",children:i})})]})});Zd.displayName="Sidebar";const zx=b.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=ps();return u.jsxs(Ee,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:H("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(Jm,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});zx.displayName="SidebarTrigger";const Ax=b.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=ps();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:H("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:hover:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",e),...t})});Ax.displayName="SidebarRail";const Px=b.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:H("bg-background relative flex min-h-svh flex-1 flex-col","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2",e),...t}));Px.displayName="SidebarInset";const Ox=b.forwardRef(({className:e,...t},n)=>u.jsx(ii,{ref:n,"data-sidebar":"input",className:H("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));Ox.displayName="SidebarInput";const ga=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:H("flex flex-col gap-2 p-2",e),...t}));ga.displayName="SidebarHeader";const Bd=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:H("flex flex-col gap-2 p-2",e),...t}));Bd.displayName="SidebarFooter";const Dx=b.forwardRef(({className:e,...t},n)=>u.jsx(Od,{ref:n,"data-sidebar":"separator",className:H("bg-sidebar-border mx-2 w-auto",e),...t}));Dx.displayName="SidebarSeparator";const xa=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:H("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));xa.displayName="SidebarContent";const Rx=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:H("relative flex w-full min-w-0 flex-col p-2",e),...t}));Rx.displayName="SidebarGroup";const Mx=b.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?dr:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:H("text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium transition-[margin,opa] duration-200 ease-linear outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",e),...n})});Mx.displayName="SidebarGroupLabel";const $x=b.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?dr:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:H("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",e),...n})});$x.displayName="SidebarGroupAction";const Fx=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:H("w-full text-sm",e),...t}));Fx.displayName="SidebarGroupContent";const Cr=b.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:H("flex w-full min-w-0 flex-col gap-1",e),...t}));Cr.displayName="SidebarMenu";const Vd=b.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:H("group/menu-item relative",e),...t}));Vd.displayName="SidebarMenuItem";const Lx=ni("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),Ud=b.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...a},o)=>{const l=e?dr:"button",{isMobile:c,state:f}=ps(),d=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:H(Lx({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:d}),u.jsx(Ke,{side:"right",align:"center",hidden:f!=="collapsed"||c,...i})]})):d});Ud.displayName="SidebarMenuButton";const Jd=b.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?dr:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:H("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",e),...r})});Jd.displayName="SidebarMenuAction";const Zx=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:H("text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",e),...t}));Zx.displayName="SidebarMenuBadge";const Bx=b.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=b.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:H("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Dr,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Dr,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Bx.displayName="SidebarMenuSkeleton";const Vx=b.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:H("border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",e),...t}));Vx.displayName="SidebarMenuSub";const Ux=b.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Ux.displayName="SidebarMenuSubItem";const Jx=b.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const a=e?dr:"a";return u.jsx(a,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:H("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...i})});Jx.displayName="SidebarMenuSubButton";function Ei(e,t){const n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.style.display="none",r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}const Hx=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Wx({document:e,compact:t=!1,query:n=""}){const r=b.useRef(null),[i,s]=b.useState(!1),[a,o]=b.useState(!1),[l,c]=b.useState(!1),[f,d]=b.useState(!1),p=Oe(q=>q.openDocument),h=Oe(q=>q.documentTypes),g=Oe(q=>q.activeTab),v=Qt(q=>q.name),S=Qt(q=>q.text),x=Qt(q=>q.isGenerating),m=(h[e.name]||"application/json+report")==="application/json+theme",I=g===e.name,[E,w]=b.useState(v),[N,O]=b.useState(S),K=100,C=0;b.useEffect(()=>{const q=setTimeout(()=>{v&&S?(w(v),O(S)):x||(w(""),O(""))},x?K:C);return()=>clearTimeout(q)},[v,S,x]);const T=E===e.name,A=q=>{var W;const y=new Set;try{const B=JSON.parse(q);(W=B.props)!=null&&W.theme&&y.add(B.props.theme),B.children&&Array.isArray(B.children)&&B.children.forEach(ie=>{var te;ie.name==="docx"&&((te=ie.props)!=null&&te.theme)&&y.add(ie.props.theme)})}catch{}return y},F=b.useMemo(()=>{if(!m||!N)return!1;try{const q=JSON.parse(e.text),y=mg(q);if(y)return A(N).has(y)}catch{}return!1},[m,N,e.text]),R=b.useCallback(()=>{c(!1)},[]),L=b.useCallback(()=>{d(!1)},[]),P=I?null:T?"preview":F?"in-use":null,V=I?"Editing":T?"In preview":F?"Used by preview":null,U=b.useMemo(()=>[{key:"open",label:"Open",shortcut:Hx?"⌘⏎":"⌃⏎",run:()=>p(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Ei(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>d(!0)}],[e.name,e.text,e.type,p]),se=m?Hm:qc,k=i||a,le=u.jsxs(Ud,{size:"sm",ref:r,"aria-label":V?`${e.name} — ${V}`:e.name,className:H("relative h-7 rounded-sm text-[13px] font-normal","text-sidebar-foreground/85 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground",t?"size-7 justify-center px-0":"gap-2 pr-7 pl-2",k&&"bg-sidebar-accent/60 text-sidebar-foreground",I&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:V?`${e.name} — ${V}`:e.name,onClick:()=>{p(e.name)},onKeyDown:q=>{var y;(q.ctrlKey||q.metaKey)&&q.key==="Enter"?(p(e.name),q.preventDefault()):q.key==="Enter"?(c(!0),q.preventDefault()):q.key==="Backspace"||q.key==="Delete"?(d(!0),q.preventDefault()):q.key==="Escape"&&((y=r.current)==null||y.blur(),q.preventDefault())},children:[I&&u.jsx("span",{"aria-hidden":!0,className:H("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(se,{className:H("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",I&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(Ka,{text:e.name,query:n})}),t&&P&&u.jsx(qo,{tone:P,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(Vd,{children:[u.jsxs(lx,{onOpenChange:s,children:[u.jsx(ux,{className:"block",children:t?u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:le}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:V??(m?"Theme":"Document")})]})})]}):le}),u.jsx(Ed,{className:"w-44",children:U.map(q=>u.jsxs(_e.Fragment,{children:[q.separatorBefore&&u.jsx(Td,{}),u.jsxs(Id,{onClick:q.run,className:H(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(zd,{children:q.shortcut})]})]},q.key))})]}),!t&&u.jsxs(u.Fragment,{children:[P&&u.jsx(qo,{tone:P,className:H("pointer-events-none absolute top-1/2 right-2.5 -translate-y-1/2 transition-opacity","group-hover/menu-item:opacity-0 group-focus-within/menu-item:opacity-0",a&&"opacity-0")}),u.jsxs(ds,{onOpenChange:o,children:[u.jsx(fs,{asChild:!0,children:u.jsx(Jd,{showOnHover:!0,"aria-label":`Actions for ${e.name}`,className:"top-1 size-5 rounded-sm text-sidebar-foreground/55 hover:text-sidebar-foreground [&>svg]:size-3.5",children:u.jsx(Gc,{})})}),u.jsx(ai,{side:"right",align:"start",className:"w-44",children:U.map(q=>u.jsxs(_e.Fragment,{children:[q.separatorBefore&&u.jsx(sr,{}),u.jsxs(Bt,{onClick:q.run,className:H(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(Pd,{children:q.shortcut})]})]},q.key))})]})]}),u.jsx(It,{open:l,onOpenChange:c,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var y;q.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Mi,{mode:"update",shouldReset:!l,postSubmit:R,selectedName:e.name})})}),u.jsx(It,{open:f,onOpenChange:d,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var y;q.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Mi,{mode:"delete",shouldReset:!f,postSubmit:L,selectedName:e.name})})})]})}const mi=_e.memo(Wx);async function qx(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const Zr=b.forwardRef(({className:e,children:t,...n},r)=>u.jsxs($c,{ref:r,className:H("relative overflow-hidden",e),...n,children:[u.jsx(Cm,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Hd,{}),u.jsx(Nm,{})]}));Zr.displayName=$c.displayName;const Hd=b.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Fc,{ref:r,orientation:t,className:H("flex touch-none transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Em,{className:"bg-border relative flex-1 rounded-full"})}));Hd.displayName=Fc.displayName;function Xa({className:e,...t}){return u.jsx(Im,{"data-slot":"switch",className:H("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-switch-off focus-visible:ring-ring inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent transition-colors outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:u.jsx(Tm,{"data-slot":"switch-thumb",className:H("bg-background pointer-events-none block size-4 rounded-full shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const Gx=ni("relative w-full rounded-sm border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-card text-foreground",destructive:"border-transparent bg-destructive-bg text-destructive-bg-foreground [&>svg]:text-destructive-bg-foreground",warning:"border-transparent bg-warning-bg text-warning-bg-foreground [&>svg]:text-warning-bg-foreground",success:"border-transparent bg-success-bg text-success-bg-foreground [&>svg]:text-success-bg-foreground",info:"border-transparent bg-data-blue-bg text-data-blue-bg-foreground [&>svg]:text-data-blue-bg-foreground"}},defaultVariants:{variant:"default"}}),$i=b.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:H(Gx({variant:t}),e),...n}));$i.displayName="Alert";const Kx=b.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:H("mb-1 font-medium leading-none tracking-tight",e),...t}));Kx.displayName="AlertTitle";const Fi=b.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:H("text-sm [&_p]:leading-relaxed",e),...t}));Fi.displayName="AlertDescription";const Li=b.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=b.useState(n<2),a=t!==null&&typeof t=="object",o=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?u.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-warning",children:['"',t,'"']}):u.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,f=a?Object.keys(t).length:0;return u.jsxs("div",{className:H("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[a&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(ti,{className:"h-3 w-3"}):u.jsx(ri,{className:"h-3 w-3"})}),!a&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),a?u.jsxs("span",{className:"text-muted-foreground",children:[o?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[f," ",o?"items":"properties"]}),!i&&(o?"]":"}")]}):c(),!a&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),a&&i&&u.jsxs("div",{className:"ml-4",children:[o?t.map((d,p)=>u.jsx(Li,{keyName:String(p),value:d,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([d,p],h,g)=>u.jsx(Li,{keyName:d,value:p,depth:n+1,isLast:h===g.length-1},d)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[o?"]":"}",!r&&","]})})]})]})});Li.displayName="JsonNode";const Zi=b.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:H("space-y-4",r),children:[u.jsx(Dr,{className:"h-8 w-64"}),u.jsx(Dr,{className:"h-4 w-full"}),u.jsx(Dr,{className:"h-64 w-full"})]}):n?u.jsx($i,{variant:"destructive",className:r,children:u.jsx(Fi,{children:n})}):e?u.jsx(Zr,{className:H("h-full w-full rounded-md border bg-muted/10 p-4",r),children:u.jsx("div",{className:"font-mono text-xs",children:u.jsx(Li,{value:e})})}):u.jsx($i,{className:r,children:u.jsx(Fi,{children:"No schema available"})}));Zi.displayName="SchemaViewer";function Yx({plugins:e,initialFocusedPlugin:t}){var m,I;const n=Dt(E=>E.togglePlugin),r=Dt(E=>E.isPluginSelected),i=Dt(E=>E.selectedPlugins),s=Dt(E=>E.isApplyingPlugins),[a,o]=b.useState(null),[l,c]=b.useState(null),[f,d]=b.useState("properties");b.useEffect(()=>{if(t){const E=e.find(w=>w.name===t);if(E){o(E);return}}e.length>0&&!a&&o(e[0])},[t,e]);const p=b.useMemo(()=>{const E={current:[],downstream:[],upstream:[]};return e.forEach(w=>{E[w.location]&&E[w.location].push(w)}),E},[e]),h=async(E,w)=>{a&&(await qx(a.name,E.props),c(w),setTimeout(()=>c(null),2e3))},g=E=>{switch(E){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return E}},v=E=>{switch(E){case"current":return u.jsx(Xm,{className:"size-3"});case"downstream":return u.jsx(Ym,{className:"size-3"});case"upstream":return u.jsx(qc,{className:"size-3"});default:return null}},S=((m=a==null?void 0:a.schema)==null?void 0:m.properties)&&Object.keys(a.schema.properties).length>0,x=(I=a==null?void 0:a.schema)==null?void 0:I.jsonSchema,_=(a==null?void 0:a.examples)&&a.examples.length>0;return u.jsxs(u.Fragment,{children:[u.jsxs(Ht,{children:[u.jsxs(Wt,{className:"flex items-center gap-2",children:[u.jsx(Wm,{className:"size-5 text-warning"}),"Plugins",u.jsxs(Jt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(hn,{children:[e.length," plugin",e.length!==1?"s":""," discovered in your project"]})]}),u.jsxs("div",{className:"mt-3 flex gap-0 h-[600px] border rounded-lg overflow-hidden",children:[u.jsx("div",{className:"w-[240px] flex-none border-r bg-muted/30",children:u.jsx(Zr,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(p).map(([E,w])=>w.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[v(E),g(E)]}),u.jsx("div",{className:"space-y-0.5",children:w.map(N=>{const O=r(N.name),K=(a==null?void 0:a.name)===N.name;return u.jsxs("button",{onClick:()=>o(N),className:H("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",K?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:H("size-1.5 rounded-full flex-none transition-colors",O?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:N.name})]},N.name)})})]},E))})})}),a?u.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[u.jsxs("div",{className:"flex-none px-5 py-4 border-b bg-background",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2.5",children:[u.jsx("h3",{className:"text-base font-semibold truncate",children:a.name}),a.version&&u.jsxs(Jt,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",a.version]})]}),a.description&&u.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:a.description})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-none pt-0.5",children:[u.jsx("span",{className:"text-xs text-muted-foreground",children:r(a.name)?"On":"Off"}),u.jsx(Xa,{checked:r(a.name),onCheckedChange:()=>n(a),disabled:s,"aria-label":`Toggle ${a.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[v(a.location),u.jsx("span",{children:g(a.location)}),u.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),u.jsx("span",{className:"font-mono truncate",children:a.relativePath})]})]}),u.jsxs("div",{className:"flex-none px-5 pt-3 pb-0 flex gap-1 border-b bg-background",children:[S&&u.jsx("button",{onClick:()=>d("properties"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Oo,{className:"size-3.5"}),"Properties"]})}),x&&u.jsx("button",{onClick:()=>d("schema"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(qm,{className:"size-3.5"}),"Schema"]})}),_&&u.jsx("button",{onClick:()=>d("examples"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Gm,{className:"size-3.5"}),"Examples",u.jsx(Jt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:a.examples.length})]})})]}),u.jsx(Zr,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[f==="properties"&&S&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([E,w])=>u.jsx(Xx,{name:E,prop:w},E))}),f==="schema"&&x&&u.jsx(Zi,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),f==="examples"&&_&&a.examples.map((E,w)=>u.jsxs("div",{className:H(w>0&&"mt-4 pt-4 border-t"),children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[E.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:E.title}),!E.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),u.jsx(Ee,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>h(E,w),children:l===w?u.jsxs(u.Fragment,{children:[u.jsx(Km,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(os,{className:"size-3 mr-1"}),"Copy"]})})]}),E.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:E.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(E.props,null,2)})]},w)),!S&&!x&&!_&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(Oo,{className:"size-10 mx-auto mb-3 opacity-20"}),u.jsx("p",{className:"text-sm",children:"No schema or examples available for this plugin"})]})]})})]}):u.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:u.jsx("p",{className:"text-sm",children:"Select a plugin to view details"})})]})]})}function Xx({name:e,prop:t}){var a;const[n,r]=b.useState(!1),i=t.description||t.enum||t.default!==void 0||t.items||t.properties,s=t.type||(t.enum?"enum":t.oneOf?"oneOf":"—");return u.jsxs("div",{className:"rounded-md border",children:[u.jsxs("button",{onClick:()=>i&&r(!n),className:H("w-full text-left flex items-center gap-2 px-3 py-2 text-sm",i&&"cursor-pointer hover:bg-muted/50"),children:[i?n?u.jsx(ti,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(ri,{className:"size-3 text-muted-foreground flex-none"}):u.jsx("span",{className:"size-3 flex-none"}),u.jsx("span",{className:"font-mono font-medium text-xs",children:e}),u.jsx(Jt,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&u.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),u.jsx("span",{className:"flex-1"}),t.default!==void 0&&u.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&u.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&u.jsx("p",{children:t.description}),t.enum&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((o,l)=>u.jsxs("span",{children:[l>0&&", ",u.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(o)})]},l))]}),((a=t.items)==null?void 0:a.type)&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const Qx=zm,ey=Am,ty=Pm,ny={current:"Current directory",downstream:"Project"};function Os({id:e,label:t,count:n,open:r,onToggle:i,children:s}){return u.jsxs(Qx,{open:r,children:[u.jsxs(ey,{onClick:()=>i(e),className:H("flex h-7 w-full cursor-pointer items-center gap-1.5 rounded-sm px-1","text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(ri,{className:H("size-3 shrink-0 transition-transform duration-150 ease-out",r&&"rotate-90")}),u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:t}),u.jsx("span",{className:"ml-auto text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:n})]}),u.jsx(ty,{children:u.jsx("div",{className:"border-sidebar-border/70 mt-0.5 ml-[13px] border-l pl-1",children:s})})]})}function Ko({location:e}){return u.jsx("div",{className:"px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:ny[e]??e})}function Yo({name:e,subtitle:t,added:n,query:r,onSelect:i}){return u.jsxs("button",{type:"button",onClick:i,title:t?`${e} — ${t}`:e,"aria-label":n?`Open ${e}`:`Add ${e} to workspace`,className:H("group/row flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","text-sidebar-foreground/70"),children:[u.jsx("span",{className:"truncate",children:u.jsx(Ka,{text:e,query:r})}),n?u.jsx("span",{className:"ml-auto shrink-0 text-[10px] tracking-[0.06em] text-sidebar-foreground/65 uppercase",children:"Open"}):u.jsx(Xt,{"aria-hidden":!0,className:"ml-auto size-3.5 shrink-0 text-sidebar-foreground/45 opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100"})]})}function ry({documents:e,themes:t,plugins:n,openNames:r,query:i,expandedGroups:s,onToggleGroup:a,onQuickAdd:o,onShowPluginDetails:l,isPluginSelected:c,onTogglePlugin:f,isApplyingPlugins:d,selectedPluginCount:p}){const h=x=>i?!0:s.has(x),g=b.useMemo(()=>Xo(e),[e]),v=b.useMemo(()=>Xo(t),[t]);return e.length>0||t.length>0||n.length>0?u.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.length>0&&u.jsx(Os,{id:"library-documents",label:"Project documents",count:e.length,open:h("library-documents"),onToggle:a,children:g.map(([x,_])=>u.jsxs(_e.Fragment,{children:[g.length>1&&u.jsx(Ko,{location:x}),_.map(m=>u.jsx(Yo,{name:m.name,subtitle:m.title,added:r.has(m.name),query:i,onSelect:()=>o(m.name,!1)},m.path||m.name))]},x))}),t.length>0&&u.jsx(Os,{id:"library-themes",label:"Project themes",count:t.length,open:h("library-themes"),onToggle:a,children:v.map(([x,_])=>u.jsxs(_e.Fragment,{children:[v.length>1&&u.jsx(Ko,{location:x}),_.map(m=>u.jsx(Yo,{name:m.name,subtitle:m.description,added:r.has(m.name),query:i,onSelect:()=>o(m.name,!0)},m.path||m.name))]},x))}),n.length>0&&u.jsx(Os,{id:"library-plugins",label:"Plugins",count:`${p}/${n.length}`,open:h("library-plugins"),onToggle:a,children:n.map(x=>{const _=c(x.name),m=`plugin-switch-${x.filePath||x.name}`;return u.jsxs("div",{title:x.description?`${x.name} — ${x.description}`:x.name,className:H("group/row flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2","transition-colors hover:bg-sidebar-accent/60"),children:[u.jsx("label",{htmlFor:m,className:H("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",_?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(Ka,{text:x.name,query:i})})}),u.jsx(Ft,{"aria-label":`Details for ${x.name}`,onClick:I=>{I.stopPropagation(),l(x.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(Kc,{})}),u.jsx(Xa,{id:m,checked:_,onCheckedChange:()=>f(x),disabled:d,className:"shrink-0","aria-label":`Toggle ${x.name} plugin`})]},x.filePath||x.name)})})]}):null}function Xo(e){const t=["current","downstream"],n=new Map;return e.forEach(r=>{const i=n.get(r.location);i?i.push(r):n.set(r.location,[r])}),[...n.entries()].sort(([r],[i])=>t.indexOf(r)-t.indexOf(i))}function Wd({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:H("pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground","[[data-slot=tooltip-content]_&]:bg-primary-foreground/20 [[data-slot=tooltip-content]_&]:text-primary-foreground",t),children:e})}function iy({children:e,className:t}){return u.jsx("span",{className:H("inline-flex items-center gap-0.5",t),children:e})}const gi=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function Br({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return gi?"⌘":"Ctrl";case"shift":return gi?"⇧":"Shift";case"alt":return gi?"⌥":"Alt";case"ctrl":return gi?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(iy,{className:t,children:r.map((i,s)=>u.jsx(Wd,{children:i},s))})}function sy({className:e}={}){const{theme:t,setTheme:n}=Uc(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=b.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(Ee,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Qm,{className:"hidden dark:block"}),u.jsx(eg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:"Toggle theme"})})]})}function ay({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o}=Oe(rd(Z=>({documents:Z.documents,documentTypes:Z.documentTypes,createDocument:Z.createDocument,openDocument:Z.openDocument}))),l=ca(Z=>Z.updateTheme),c=ca(Z=>Z.removeTheme),f=b.useContext(nd),[d,p]=b.useState(!1),[h,g]=b.useState(!1),[v,S]=b.useState(!1),[x,_]=b.useState(null),m=Dt(Z=>Z.togglePlugin),I=Dt(Z=>Z.isPluginSelected),E=Dt(Z=>Z.selectedPlugins),w=Dt(Z=>Z.isApplyingPlugins),[N,O]=b.useState(!1),[K,C]=b.useState(new Set(["library-documents"])),[T,A]=b.useState(""),F=b.useRef(null),{toast:R}=fr(),L=i.filter(Z=>s[Z.name]!=="application/json+theme"),P=i.filter(Z=>s[Z.name]==="application/json+theme"),V=b.useCallback(()=>{p(!1)},[]),U=b.useCallback(()=>{g(!1)},[]),se=b.useRef(new Map);b.useEffect(()=>{const Z=se.current,ke=new Map;P.forEach(me=>{ke.set(me.name,me.text),Z.get(me.name)!==me.text&&l(me.name,me.text)}),Z.forEach((me,De)=>{ke.has(De)||c(De)}),se.current=ke},[P,l,c]);const k=b.useRef(!1);b.useEffect(()=>{if(k.current||!f)return;k.current=!0;const Z=new Set(P.map(me=>me.name));Object.keys(f.getState().customThemes).forEach(me=>{Z.has(me)||c(me)})},[P,c,f]);const le=b.useCallback(Z=>{C(ke=>{const me=new Set(ke);return me.has(Z)?me.delete(Z):me.add(Z),me})},[]),{resolvedTheme:q}=Uc(),y=q==="dark"?"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo-white.svg?updatedAt=1751359555877":"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo.svg?updatedAt=1749817149276",W=b.useCallback(async(Z,ke)=>{if(i.some(me=>me.name===Z)){o(Z);return}try{const me=await fetch(`/api/discovery/${ke?"themes":"documents"}/${encodeURIComponent(Z)}/content`);if(!me.ok)throw new Error(me.statusText);const De=await me.text(),j=JSON.parse(De);a(Z,JSON.stringify(j,null,2)),o(Z),R({title:`Added ${ke?"theme":"document"}: ${Z}`})}catch{R({title:"Failed to load",description:`Could not load ${Z}`,variant:"destructive"})}},[i,a,o,R]);b.useEffect(()=>{if(n)return;const Z=ke=>{var j,z,M,re,ee;if(ke.key!=="/"||ke.metaKey||ke.ctrlKey||ke.altKey)return;const me=ke.target,De=(j=me==null?void 0:me.tagName)==null?void 0:j.toLowerCase();De==="input"||De==="textarea"||De==="select"||me!=null&&me.isContentEditable||(z=me==null?void 0:me.closest)!=null&&z.call(me,".monaco-editor")||(M=F.current)!=null&&M.closest('[aria-hidden="true"], [inert]')||(ke.preventDefault(),(re=F.current)==null||re.focus(),(ee=F.current)==null||ee.select())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[n]);const B=T.trim(),ie=b.useMemo(()=>new Set(i.map(Z=>Z.name)),[i]),te=b.useMemo(()=>L.filter(Z=>sn(Z.name,B)),[L,B]),X=b.useMemo(()=>P.filter(Z=>sn(Z.name,B)),[P,B]),fe=b.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(Z=>sn(Z.name,B)||sn(Z.title??"",B)),[e,B]),be=b.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(Z=>sn(Z.name,B)||sn(Z.description??"",B)),[e,B]),ne=b.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(Z=>sn(Z.name,B)||sn(Z.description??"",B)),[e,B]),de=B.length>0&&te.length===0&&X.length===0&&fe.length===0&&be.length===0&&ne.length===0,ue=H("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(Zd,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(ga,{className:H("gap-0 p-1.5",ue),children:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Yc,{})})}),u.jsxs(Ke,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(Br,{shortcut:"mod+b"})]})]})}),u.jsxs(xa,{className:H("gap-2 px-1 py-1",ue),children:[u.jsxs(Cr,{className:"items-center gap-0.5",children:[L.map(Z=>u.jsx(mi,{document:Z,compact:!0},Z.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"right",children:"New document"})]})]}),u.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),u.jsxs(Cr,{className:"items-center gap-0.5",children:[P.map(Z=>u.jsx(mi,{document:Z,compact:!0},Z.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{className:"size-7","aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(ga,{className:H("gap-0 p-2",ue),children:[u.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[u.jsx("a",{href:"/","aria-label":"JSON to Office home",className:"focus-visible:ring-sidebar-ring flex items-center rounded-sm pl-1 focus-visible:ring-1 focus-visible:outline-none",children:u.jsx("img",{src:y,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(tg,{})})}),u.jsxs(Ke,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(Br,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(ng,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),u.jsx("input",{ref:F,type:"text",value:T,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:Z=>A(Z.target.value),onKeyDown:Z=>{Z.key==="Escape"&&(Z.preventDefault(),A(""),Z.currentTarget.blur())},className:H("border-sidebar-border/70 bg-sidebar-accent/40 h-7 w-full rounded-sm border","pr-7 pl-7 text-[13px] text-sidebar-foreground transition-colors","placeholder:text-sidebar-foreground/60","focus-visible:border-sidebar-ring focus-visible:bg-sidebar-accent/60","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none")}),B?u.jsx(Ft,{"aria-label":"Clear filter",onClick:()=>{var Z;A(""),(Z=F.current)==null||Z.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(fn,{})}):u.jsx(Wd,{className:"absolute top-1/2 right-1.5 h-4 min-w-4 -translate-y-1/2 bg-transparent px-0 text-[10px] text-sidebar-foreground/65",children:"/"})]})]}),u.jsx(xa,{className:H("gap-0 px-2 pb-2",ue),children:de?u.jsxs("div",{className:"px-1 py-6 text-center",children:[u.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",B,"”"]}),u.jsx("button",{type:"button",onClick:()=>{var Z;A(""),(Z=F.current)==null||Z.focus()},className:"text-sidebar-foreground/70 hover:text-sidebar-foreground focus-visible:ring-sidebar-ring mt-1 cursor-pointer rounded-sm text-[12px] underline-offset-2 hover:underline focus-visible:ring-1 focus-visible:outline-none",children:"Clear filter"})]}):u.jsxs(u.Fragment,{children:[(te.length>0||!B)&&u.jsxs("section",{children:[u.jsx(Wo,{count:(B?te.length:L.length)||void 0,actions:u.jsxs(u.Fragment,{children:[yt==="docx"&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"Compare documents",disabled:L.length<2,onClick:()=>O(!0),children:u.jsx(Hc,{})})}),u.jsx(Ke,{side:"bottom",children:L.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),u.jsx(Cr,{className:"gap-0.5",children:te.length>0?te.map(Z=>u.jsx(mi,{document:Z,query:B},Z.name)):u.jsx(Go,{icon:Xt,label:"New document",onClick:()=>p(!0)})})]}),(X.length>0||!B)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Wo,{count:(B?X.length:P.length)||void 0,actions:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ft,{"aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(Xt,{})})}),u.jsx(Ke,{side:"bottom",children:"New theme"})]}),children:"Themes"}),u.jsx(Cr,{className:"gap-0.5",children:X.length>0?X.map(Z=>u.jsx(mi,{document:Z,query:B},Z.name)):u.jsx(Go,{icon:Xt,label:"New theme",onClick:()=>g(!0)})})]}),(fe.length>0||be.length>0||ne.length>0)&&u.jsx("div",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:u.jsx(ry,{documents:fe,themes:be,plugins:ne,openNames:ie,query:B,expandedGroups:K,onToggleGroup:le,onQuickAdd:W,onShowPluginDetails:Z=>{_(Z),S(!0)},isPluginSelected:I,onTogglePlugin:m,isApplyingPlugins:w,selectedPluginCount:E.size})})]})})]}),u.jsx(Bd,{className:H("border-sidebar-border/70 gap-0 border-t p-1.5",ue),children:u.jsx("div",{className:H("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(sy,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),u.jsx(It,{open:d,onOpenChange:p,children:u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Mi,{mode:"create",shouldReset:!d,postSubmit:V,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(It,{open:h,onOpenChange:g,children:u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Mi,{mode:"create",shouldReset:!h,postSubmit:U,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(It,{open:v,onOpenChange:Z=>{S(Z),Z||_(null)},children:u.jsx(St,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(Yx,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:x})})}),u.jsx(Ag,{open:N,onOpenChange:O})]})}const Qo=b.memo(ay),oy=b.lazy(()=>Jc(()=>import("./editor-DCtGYNz2.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function el(){return u.jsx(b.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(en,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(oy,{})})}const ly=b.lazy(()=>Jc(()=>import("./preview-oxnxMi4x.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function tl(){return u.jsx(b.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(en,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(ly,{})})}const{createElement:ar,createContext:uy,forwardRef:qd,useCallback:pt,useContext:Gd,useEffect:Nn,useImperativeHandle:Kd,useLayoutEffect:cy,useMemo:dy,useRef:xt,useState:Qn}=lc,nl=lc[`useId${Math.random()}`.slice(0,5)],fy=cy,hs=uy(null);hs.displayName="PanelGroupContext";const En=fy,py=typeof nl=="function"?nl:()=>null;let hy=0;function Qa(e=null){const t=py(),n=xt(e||t||null);return n.current===null&&(n.current=""+hy++),e??n.current}function Yd({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:f,onResize:d,order:p,style:h,tagName:g="div",...v}){const S=Gd(hs);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:x,expandPanel:_,getPanelSize:m,getPanelStyle:I,groupId:E,isPanelCollapsed:w,reevaluatePanelConstraints:N,registerPanel:O,resizePanel:K,unregisterPanel:C}=S,T=Qa(a),A=xt({callbacks:{onCollapse:c,onExpand:f,onResize:d},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:T,idIsFromProps:a!==void 0,order:p});xt({didLogMissingDefaultSizeWarning:!1}),En(()=>{const{callbacks:R,constraints:L}=A.current,P={...L};A.current.id=T,A.current.idIsFromProps=a!==void 0,A.current.order=p,R.onCollapse=c,R.onExpand=f,R.onResize=d,L.collapsedSize=n,L.collapsible=r,L.defaultSize=i,L.maxSize=o,L.minSize=l,(P.collapsedSize!==L.collapsedSize||P.collapsible!==L.collapsible||P.maxSize!==L.maxSize||P.minSize!==L.minSize)&&N(A.current,P)}),En(()=>{const R=A.current;return O(R),()=>{C(R)}},[p,T,O,C]),Kd(s,()=>({collapse:()=>{x(A.current)},expand:R=>{_(A.current,R)},getId(){return T},getSize(){return m(A.current)},isCollapsed(){return w(A.current)},isExpanded(){return!w(A.current)},resize:R=>{K(A.current,R)}}),[x,_,m,w,T,K]);const F=I(A.current,i);return ar(g,{...v,children:e,className:t,id:a,style:{...F,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":E,"data-panel-id":T,"data-panel-size":parseFloat(""+F.flexGrow).toFixed(1)})}const Xd=qd((e,t)=>ar(Yd,{...e,forwardedRef:t}));Yd.displayName="Panel";Xd.displayName="forwardRef(Panel)";let ya=null,Cn=null;function my(e,t){if(t){const n=(t&rf)!==0,r=(t&sf)!==0,i=(t&af)!==0,s=(t&of)!==0;if(n)return i?"se-resize":s?"ne-resize":"e-resize";if(r)return i?"sw-resize":s?"nw-resize":"w-resize";if(i)return"s-resize";if(s)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function gy(){Cn!==null&&(document.head.removeChild(Cn),ya=null,Cn=null)}function Ds(e,t){const n=my(e,t);ya!==n&&(ya=n,Cn===null&&(Cn=document.createElement("style"),document.head.appendChild(Cn)),Cn.innerHTML=`*{cursor: ${n}!important;}`)}function Qd(e){return e.type==="keydown"}function ef(e){return e.type.startsWith("pointer")}function tf(e){return e.type.startsWith("mouse")}function ms(e){if(ef(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(tf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function xy(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function yy(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function by(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:sl(e),b:sl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ce(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:il(rl(n.a)),b:il(rl(n.b))};if(i.a===i.b){const s=r.childNodes,a={a:n.a.at(-1),b:n.b.at(-1)};let o=s.length;for(;o--;){const l=s[o];if(l===a.a)return 1;if(l===a.b)return-1}}return Math.sign(i.a-i.b)}const vy=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function wy(e){var t;const n=getComputedStyle((t=nf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function ky(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||wy(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||vy.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function rl(e){let t=e.length;for(;t--;){const n=e[t];if(Ce(n,"Missing node"),ky(n))return n}return null}function il(e){return e&&Number(getComputedStyle(e).zIndex)||0}function sl(e){const t=[];for(;e;)t.push(e),e=nf(e);return t}function nf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const rf=1,sf=2,af=4,of=8,Sy=xy()==="coarse";let Rt=[],er=!1,cn=new Map,gs=new Map;const Vr=new Set;function _y(e,t,n,r,i){var s;const{ownerDocument:a}=t,o={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=cn.get(a))!==null&&s!==void 0?s:0;return cn.set(a,l+1),Vr.add(o),Bi(),function(){var f;gs.delete(e),Vr.delete(o);const d=(f=cn.get(a))!==null&&f!==void 0?f:1;if(cn.set(a,d-1),Bi(),d===1&&cn.delete(a),Rt.includes(o)){const p=Rt.indexOf(o);p>=0&&Rt.splice(p,1),to(),i("up",!0,null)}}}function al(e){const{target:t}=e,{x:n,y:r}=ms(e);er=!0,eo({target:t,x:n,y:r}),Bi(),Rt.length>0&&(Vi("down",e),e.preventDefault(),e.stopPropagation())}function vr(e){const{x:t,y:n}=ms(e);if(er&&e.buttons===0&&(er=!1,Vi("up",e)),!er){const{target:r}=e;eo({target:r,x:t,y:n})}Vi("move",e),to(),Rt.length>0&&e.preventDefault()}function $n(e){const{target:t}=e,{x:n,y:r}=ms(e);gs.clear(),er=!1,Rt.length>0&&e.preventDefault(),Vi("up",e),eo({target:t,x:n,y:r}),to(),Bi()}function eo({target:e,x:t,y:n}){Rt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Vr.forEach(i=>{const{element:s,hitAreaMargins:a}=i,o=s.getBoundingClientRect(),{bottom:l,left:c,right:f,top:d}=o,p=Sy?a.coarse:a.fine;if(t>=c-p&&t<=f+p&&n>=d-p&&n<=l+p){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&by(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(yy(g.getBoundingClientRect(),o)){v=!0;break}g=g.parentElement}if(v)return}Rt.push(i)}})}function Rs(e,t){gs.set(e,t)}function to(){let e=!1,t=!1;Rt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;gs.forEach(r=>{n|=r}),e&&t?Ds("intersection",n):e?Ds("horizontal",n):t?Ds("vertical",n):gy()}function Bi(){cn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",$n),n.removeEventListener("pointerdown",al),n.removeEventListener("pointerleave",vr),n.removeEventListener("pointermove",vr)}),window.removeEventListener("pointerup",$n),window.removeEventListener("pointercancel",$n),Vr.size>0&&(er?(Rt.length>0&&cn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",$n),n.addEventListener("pointerleave",vr),n.addEventListener("pointermove",vr))}),window.addEventListener("pointerup",$n),window.addEventListener("pointercancel",$n)):cn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",al,{capture:!0}),n.addEventListener("pointermove",vr))}))}function Vi(e,t){Vr.forEach(n=>{const{setResizeHandlerState:r}=n,i=Rt.includes(n);r(e,i,t)})}function jy(){const[e,t]=Qn(0);return pt(()=>t(n=>n+1),[])}function Ce(e,t){if(!e)throw console.error(t),Error(t)}const no=10;function zn(e,t,n=no){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function tn(e,t,n=no){return zn(e,t,n)===0}function kt(e,t,n){return zn(e,t,n)===0}function Cy(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],s=t[r];if(!kt(i,s,n))return!1}return!0}function Gn({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ce(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:a=100,minSize:o=0}=r;if(zn(n,o)<0)if(s){const l=(i+o)/2;zn(n,l)<0?n=i:n=o}else n=o;return n=Math.min(a,n),n=parseFloat(n.toFixed(no)),n}function Nr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(kt(e,0))return t;const a=[...t],[o,l]=r;Ce(o!=null,"Invalid first pivot index"),Ce(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?l:o,p=n[d];Ce(p,`Panel constraints not found for index ${d}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[d];if(Ce(S!=null,`Previous layout not found for panel index ${d}`),kt(S,h)){const x=v-S;zn(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}{const d=e<0?o:l,p=n[d];Ce(p,`No panel constraints found for index ${d}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[d];if(Ce(S!=null,`Previous layout not found for panel index ${d}`),kt(S,v)){const x=S-h;zn(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}}{const d=e<0?1:-1;let p=e<0?l:o,h=0;for(;;){const v=t[p];Ce(v!=null,`Previous layout not found for panel index ${p}`);const x=Gn({panelConstraints:n,panelIndex:p,size:100})-v;if(h+=x,p+=d,p<0||p>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-g:g}{let p=e<0?o:l;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),g=t[p];Ce(g!=null,`Previous layout not found for panel index ${p}`);const v=g-h,S=Gn({panelConstraints:n,panelIndex:p,size:v});if(!kt(g,S)&&(c+=g-S,a[p]=S,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(Cy(i,a))return i;{const d=e<0?l:o,p=t[d];Ce(p!=null,`Previous layout not found for panel index ${d}`);const h=p+c,g=Gn({panelConstraints:n,panelIndex:d,size:h});if(a[d]=g,!kt(g,h)){let v=h-g,x=e<0?l:o;for(;x>=0&&x<n.length;){const _=a[x];Ce(_!=null,`Previous layout not found for panel index ${x}`);const m=_+v,I=Gn({panelConstraints:n,panelIndex:x,size:m});if(kt(_,I)||(v-=I-_,a[x]=I),kt(v,0))break;e>0?x--:x++}}}const f=a.reduce((d,p)=>p+d,0);return kt(f,100)?a:i}function Ny({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,a=0;const o=n[0];Ce(o!=null,"No pivot index found"),t.forEach((d,p)=>{const{constraints:h}=d,{maxSize:g=100,minSize:v=0}=h;p===o?(r=v,i=g):(s+=v,a+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-a),f=e[o];return{valueMax:l,valueMin:c,valueNow:f}}function Ur(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function lf(e,t,n=document){const i=Ur(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function uf(e,t,n){const r=lf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function cf(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function xs(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function Ey(e,t,n,r=document){var i,s,a,o;const l=xs(t,r),c=Ur(e,r),f=l?c.indexOf(l):-1,d=(i=(s=n[f])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,p=(a=(o=n[f+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[d,p]}function Iy({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:a}){xt({didWarnAboutMissingResizeHandle:!1}),En(()=>{if(!s)return;const o=Ur(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:f,valueNow:d}=Ny({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=o[l];if(p!=null){const h=i[l];Ce(h,`No panel data found for index "${l}"`),p.setAttribute("aria-controls",h.id),p.setAttribute("aria-valuemax",""+Math.round(c)),p.setAttribute("aria-valuemin",""+Math.round(f)),p.setAttribute("aria-valuenow",d!=null?""+Math.round(d):"")}}return()=>{o.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),Nn(()=>{if(!s)return;const o=t.current;Ce(o,"Eager values not found");const{panelDataArray:l}=o,c=cf(n,s);Ce(c!=null,`No group found for id "${n}"`);const f=Ur(n,s);Ce(f,`No resize handles found for group id "${n}"`);const d=f.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");Ce(h,"Resize handle element has no handle id attribute");const[g,v]=Ey(n,h,l,s);if(g==null||v==null)return()=>{};const S=x=>{if(!x.defaultPrevented)switch(x.key){case"Enter":{x.preventDefault();const _=l.findIndex(m=>m.id===g);if(_>=0){const m=l[_];Ce(m,`No panel data found for index ${_}`);const I=r[_],{collapsedSize:E=0,collapsible:w,minSize:N=0}=m.constraints;if(I!=null&&w){const O=Nr({delta:kt(I,E)?N-E:E-I,initialLayout:r,panelConstraints:l.map(K=>K.constraints),pivotIndices:uf(n,h,s),prevLayout:r,trigger:"keyboard"});r!==O&&a(O)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{d.forEach(p=>p())}},[s,e,t,n,r,i,a])}function ol(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function df(e,t){const n=e==="horizontal",{x:r,y:i}=ms(t);return n?r:i}function Ty(e,t,n,r,i){const s=n==="horizontal",a=xs(t,i);Ce(a,`No resize handle element found for id "${t}"`);const o=a.getAttribute("data-panel-group-id");Ce(o,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=df(n,e),f=cf(o,i);Ce(f,`No group element found for id "${o}"`);const d=f.getBoundingClientRect(),p=s?d.width:d.height;return(c-l)/p*100}function zy(e,t,n,r,i,s){if(Qd(e)){const a=n==="horizontal";let o=0;e.shiftKey?o=100:i!=null?o=i:o=10;let l=0;switch(e.key){case"ArrowDown":l=a?0:o;break;case"ArrowLeft":l=a?-o:0;break;case"ArrowRight":l=a?o:0;break;case"ArrowUp":l=a?0:-o;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:Ty(e,t,n,r,s)}function Ay({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,i=100;for(let s=0;s<e.length;s++){const a=n[s];Ce(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;o!=null&&(r++,t[s]=o,i-=o)}for(let s=0;s<e.length;s++){const a=n[s];Ce(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;if(o!=null)continue;const l=e.length-r,c=i/l;r++,t[s]=c,i-=c}return t}function Fn(e,t,n){t.forEach((r,i)=>{const s=e[i];Ce(s,`Panel data not found for index ${i}`);const{callbacks:a,constraints:o,id:l}=s,{collapsedSize:c=0,collapsible:f}=o,d=n[l];if(d==null||r!==d){n[l]=r;const{onCollapse:p,onExpand:h,onResize:g}=a;g&&g(r,d),f&&(p||h)&&(h&&(d==null||tn(d,c))&&!tn(r,c)&&h(),p&&(d==null||!tn(d,c))&&tn(r,c)&&p())}})}function xi(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function Py({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const a=n[i];let o;return a==null?o=e!=null?e.toPrecision(s):"1":r.length===1?o="1":o=a.toPrecision(s),{flexBasis:0,flexGrow:o,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function Oy(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function ll(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function ff(e){return`react-resizable-panels:${e}`}function pf(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:i,order:s}=t;return i?r:s?`${s}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function hf(e,t){try{const n=ff(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Dy(e,t,n){var r,i;const s=(r=hf(e,n))!==null&&r!==void 0?r:{},a=pf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Ry(e,t,n,r,i){var s;const a=ff(e),o=pf(t),l=(s=hf(e,i))!==null&&s!==void 0?s:{};l[o]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(a,JSON.stringify(l))}catch(c){console.error(c)}}function ul({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,a)=>s+a,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!kt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const a=n[s];Ce(a!=null,`No layout data found for index ${s}`);const o=100/r*a;n[s]=o}let i=0;for(let s=0;s<t.length;s++){const a=n[s];Ce(a!=null,`No layout data found for index ${s}`);const o=Gn({panelConstraints:t,panelIndex:s,size:a});a!=o&&(i+=a-o,n[s]=o)}if(!kt(i,0))for(let s=0;s<t.length;s++){const a=n[s];Ce(a!=null,`No layout data found for index ${s}`);const o=a+i,l=Gn({panelConstraints:t,panelIndex:s,size:o});if(a!==l&&(i-=l-a,n[s]=l,kt(i,0)))break}return n}const My=100,Er={getItem:e=>(ll(Er),Er.getItem(e)),setItem:(e,t)=>{ll(Er),Er.setItem(e,t)}},cl={};function mf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:a=null,keyboardResizeBy:o=null,storage:l=Er,style:c,tagName:f="div",...d}){const p=Qa(s),h=xt(null),[g,v]=Qn(null),[S,x]=Qn([]),_=jy(),m=xt({}),I=xt(new Map),E=xt(0),w=xt({autoSaveId:e,direction:r,dragState:g,id:p,keyboardResizeBy:o,onLayout:a,storage:l}),N=xt({layout:S,panelDataArray:[],panelDataArrayChanged:!1});xt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),Kd(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:y}=N.current;return y},setLayout:y=>{const{onLayout:W}=w.current,{layout:B,panelDataArray:ie}=N.current,te=ul({layout:y,panelConstraints:ie.map(X=>X.constraints)});ol(B,te)||(x(te),N.current.layout=te,W&&W(te),Fn(ie,te,m.current))}}),[]),En(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=g,w.current.id=p,w.current.onLayout=a,w.current.storage=l}),Iy({committedValuesRef:w,eagerValuesRef:N,groupId:p,layout:S,panelDataArray:N.current.panelDataArray,setLayout:x,panelGroupElement:h.current}),Nn(()=>{const{panelDataArray:y}=N.current;if(e){if(S.length===0||S.length!==y.length)return;let W=cl[e];W==null&&(W=Oy(Ry,My),cl[e]=W);const B=[...y],ie=new Map(I.current);W(e,B,ie,S,l)}},[e,S,l]),Nn(()=>{});const O=pt(y=>{const{onLayout:W}=w.current,{layout:B,panelDataArray:ie}=N.current;if(y.constraints.collapsible){const te=ie.map(ne=>ne.constraints),{collapsedSize:X=0,panelSize:fe,pivotIndices:be}=vn(ie,y,B);if(Ce(fe!=null,`Panel size not found for panel "${y.id}"`),!tn(fe,X)){I.current.set(y.id,fe);const de=Jn(ie,y)===ie.length-1?fe-X:X-fe,ue=Nr({delta:de,initialLayout:B,panelConstraints:te,pivotIndices:be,prevLayout:B,trigger:"imperative-api"});xi(B,ue)||(x(ue),N.current.layout=ue,W&&W(ue),Fn(ie,ue,m.current))}}},[]),K=pt((y,W)=>{const{onLayout:B}=w.current,{layout:ie,panelDataArray:te}=N.current;if(y.constraints.collapsible){const X=te.map(Z=>Z.constraints),{collapsedSize:fe=0,panelSize:be=0,minSize:ne=0,pivotIndices:de}=vn(te,y,ie),ue=W??ne;if(tn(be,fe)){const Z=I.current.get(y.id),ke=Z!=null&&Z>=ue?Z:ue,De=Jn(te,y)===te.length-1?be-ke:ke-be,j=Nr({delta:De,initialLayout:ie,panelConstraints:X,pivotIndices:de,prevLayout:ie,trigger:"imperative-api"});xi(ie,j)||(x(j),N.current.layout=j,B&&B(j),Fn(te,j,m.current))}}},[]),C=pt(y=>{const{layout:W,panelDataArray:B}=N.current,{panelSize:ie}=vn(B,y,W);return Ce(ie!=null,`Panel size not found for panel "${y.id}"`),ie},[]),T=pt((y,W)=>{const{panelDataArray:B}=N.current,ie=Jn(B,y);return Py({defaultSize:W,dragState:g,layout:S,panelData:B,panelIndex:ie})},[g,S]),A=pt(y=>{const{layout:W,panelDataArray:B}=N.current,{collapsedSize:ie=0,collapsible:te,panelSize:X}=vn(B,y,W);return Ce(X!=null,`Panel size not found for panel "${y.id}"`),te===!0&&tn(X,ie)},[]),F=pt(y=>{const{layout:W,panelDataArray:B}=N.current,{collapsedSize:ie=0,collapsible:te,panelSize:X}=vn(B,y,W);return Ce(X!=null,`Panel size not found for panel "${y.id}"`),!te||zn(X,ie)>0},[]),R=pt(y=>{const{panelDataArray:W}=N.current;W.push(y),W.sort((B,ie)=>{const te=B.order,X=ie.order;return te==null&&X==null?0:te==null?-1:X==null?1:te-X}),N.current.panelDataArrayChanged=!0,_()},[_]);En(()=>{if(N.current.panelDataArrayChanged){N.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:W,storage:B}=w.current,{layout:ie,panelDataArray:te}=N.current;let X=null;if(y){const be=Dy(y,te,B);be&&(I.current=new Map(Object.entries(be.expandToSizes)),X=be.layout)}X==null&&(X=Ay({panelDataArray:te}));const fe=ul({layout:X,panelConstraints:te.map(be=>be.constraints)});ol(ie,fe)||(x(fe),N.current.layout=fe,W&&W(fe),Fn(te,fe,m.current))}}),En(()=>{const y=N.current;return()=>{y.layout=[]}},[]);const L=pt(y=>{let W=!1;const B=h.current;return B&&window.getComputedStyle(B,null).getPropertyValue("direction")==="rtl"&&(W=!0),function(te){te.preventDefault();const X=h.current;if(!X)return()=>null;const{direction:fe,dragState:be,id:ne,keyboardResizeBy:de,onLayout:ue}=w.current,{layout:Z,panelDataArray:ke}=N.current,{initialLayout:me}=be??{},De=uf(ne,y,X);let j=zy(te,y,fe,be,de,X);const z=fe==="horizontal";z&&W&&(j=-j);const M=ke.map(Q=>Q.constraints),re=Nr({delta:j,initialLayout:me??Z,panelConstraints:M,pivotIndices:De,prevLayout:Z,trigger:Qd(te)?"keyboard":"mouse-or-touch"}),ee=!xi(Z,re);(ef(te)||tf(te))&&E.current!=j&&(E.current=j,!ee&&j!==0?z?Rs(y,j<0?rf:sf):Rs(y,j<0?af:of):Rs(y,0)),ee&&(x(re),N.current.layout=re,ue&&ue(re),Fn(ke,re,m.current))}},[]),P=pt((y,W)=>{const{onLayout:B}=w.current,{layout:ie,panelDataArray:te}=N.current,X=te.map(Z=>Z.constraints),{panelSize:fe,pivotIndices:be}=vn(te,y,ie);Ce(fe!=null,`Panel size not found for panel "${y.id}"`);const de=Jn(te,y)===te.length-1?fe-W:W-fe,ue=Nr({delta:de,initialLayout:ie,panelConstraints:X,pivotIndices:be,prevLayout:ie,trigger:"imperative-api"});xi(ie,ue)||(x(ue),N.current.layout=ue,B&&B(ue),Fn(te,ue,m.current))},[]),V=pt((y,W)=>{const{layout:B,panelDataArray:ie}=N.current,{collapsedSize:te=0,collapsible:X}=W,{collapsedSize:fe=0,collapsible:be,maxSize:ne=100,minSize:de=0}=y.constraints,{panelSize:ue}=vn(ie,y,B);ue!=null&&(X&&be&&tn(ue,te)?tn(te,fe)||P(y,fe):ue<de?P(y,de):ue>ne&&P(y,ne))},[P]),U=pt((y,W)=>{const{direction:B}=w.current,{layout:ie}=N.current;if(!h.current)return;const te=xs(y,h.current);Ce(te,`Drag handle element not found for id "${y}"`);const X=df(B,W);v({dragHandleId:y,dragHandleRect:te.getBoundingClientRect(),initialCursorPosition:X,initialLayout:ie})},[]),se=pt(()=>{v(null)},[]),k=pt(y=>{const{panelDataArray:W}=N.current,B=Jn(W,y);B>=0&&(W.splice(B,1),delete m.current[y.id],N.current.panelDataArrayChanged=!0,_())},[_]),le=dy(()=>({collapsePanel:O,direction:r,dragState:g,expandPanel:K,getPanelSize:C,getPanelStyle:T,groupId:p,isPanelCollapsed:A,isPanelExpanded:F,reevaluatePanelConstraints:V,registerPanel:R,registerResizeHandle:L,resizePanel:P,startDragging:U,stopDragging:se,unregisterPanel:k,panelGroupElement:h.current}),[O,g,r,K,C,T,p,A,F,V,R,L,P,U,se,k]),q={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return ar(hs.Provider,{value:le},ar(f,{...d,children:t,className:n,id:s,ref:h,style:{...q,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const gf=qd((e,t)=>ar(mf,{...e,forwardedRef:t}));mf.displayName="PanelGroup";gf.displayName="forwardRef(PanelGroup)";function Jn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function vn(e,t,n){const r=Jn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],a=n[r];return{...t.constraints,panelSize:a,pivotIndices:s}}function $y({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){Nn(()=>{if(e||n==null||r==null)return;const i=xs(t,r);if(i==null)return;const s=a=>{if(!a.defaultPrevented)switch(a.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{a.preventDefault(),n(a);break}case"F6":{a.preventDefault();const o=i.getAttribute("data-panel-group-id");Ce(o,`No group element found for id "${o}"`);const l=Ur(o,r),c=lf(o,t,r);Ce(c!==null,`No resize element found for id "${t}"`);const f=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[f].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function xf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:f="div",...d}){var p,h;const g=xt(null),v=xt({onDragging:a});Nn(()=>{v.current.onDragging=a});const S=Gd(hs);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:x,groupId:_,registerResizeHandle:m,startDragging:I,stopDragging:E,panelGroupElement:w}=S,N=Qa(i),[O,K]=Qn("inactive"),[C,T]=Qn(!1),[A,F]=Qn(null),R=xt({state:O});En(()=>{R.current.state=O}),Nn(()=>{if(n)F(null);else{const U=m(N);F(()=>U)}},[n,N,m]);const L=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,P=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return Nn(()=>{if(n||A==null)return;const U=g.current;return Ce(U,"Element ref not attached"),_y(N,U,x,{coarse:L,fine:P},(k,le,q)=>{if(le)switch(k){case"down":{K("drag"),Ce(q,'Expected event to be defined for "down" action'),I(N,q);const{onDragging:y}=v.current;y&&y(!0);break}case"move":{const{state:y}=R.current;y!=="drag"&&K("hover"),Ce(q,'Expected event to be defined for "move" action'),A(q);break}case"up":{K("hover"),E();const{onDragging:y}=v.current;y&&y(!1);break}}else K("inactive")})},[L,x,n,P,m,N,A,I,E]),$y({disabled:n,handleId:N,resizeHandler:A,panelGroupElement:w}),ar(f,{...d,children:e,className:t,id:i,onBlur:()=>{T(!1),s==null||s()},onFocus:()=>{T(!0),o==null||o()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":x,"data-panel-group-id":_,"data-resize-handle":"","data-resize-handle-active":O==="drag"?"pointer":C?"keyboard":void 0,"data-resize-handle-state":O,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":N})}xf.displayName="PanelResizeHandle";const Fy=({className:e,...t})=>u.jsx(gf,{className:H("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Ms=Xd,dl=({withHandle:e,className:t,...n})=>u.jsx(xf,{className:H("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-none data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&u.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:u.jsx(rg,{className:"h-2.5 w-2.5"})})});class Ly{constructor(t){Po(this,"client");this.client=Cg.create({baseURL:t||void 0||"/api",headers:{"Content-Type":"application/json"}})}get(t,n){return this.client.get(t,n)}post(t,n,r){return this.client.post(t,n,r)}put(t,n,r){return this.client.put(t,n,r)}delete(t,n){return this.client.delete(t,n)}patch(t,n,r){return this.client.patch(t,n,r)}}const Zy=new Ly;function By(){const e=b.useRef(null),t=b.useCallback(async(r,i,s,a,o)=>{e.current&&e.current.abort();const l=new AbortController;e.current=l;try{a==null||a("parsing","Validating JSON structure...");let c;try{c=JSON.parse(i)}catch(w){throw new Error(`Invalid JSON: ${w instanceof Error?w.message:"Unknown parse error"}`)}a==null||a("building",`Building ${pi.toLowerCase()} structure...`);const f={jsonDefinition:c,options:o||{}};f.customThemes=s??{},a==null||a("rendering",`Generating ${yt.toUpperCase()} content...`);const d={"Content-Type":"application/json"};o!=null&&o.bypassCache&&(d["X-Bypass-Cache"]="true");const p=await fetch(Vc.generate,{method:"POST",headers:d,body:JSON.stringify(f),signal:l.signal}),h=await p.json();if(!p.ok||!h.success){const w=h.error||h.message||`API request failed with status: ${p.status}`;throw new Error(w)}const{data:g,cache:v,warnings:S}=h,x=v.status==="HIT"?"HIT":v.status==="MISS"?"MISS":"UNKNOWN",_=x==="HIT"?`Served from cache (Hit rate: ${v.hitRate})`:`Generated fresh ${pi.toLowerCase()}`;a==null||a("finalizing",_);const m=globalThis.atob(g.document),I=new Uint8Array(m.length);for(let w=0;w<m.length;w++)I[w]=m.charCodeAt(w);const E=new Blob([I],{type:g.contentType});if(E.size===0)throw new Error(`Received empty ${pi.toLowerCase()} from API`);return{name:r,text:i,blob:E,filename:g.filename,fileId:g.fileId,cacheStatus:x,cacheHitRate:v.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${pi} generation was cancelled`):c}finally{e.current===l&&(e.current=null)}},[]),n=b.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:t,generateDocument:t,cancelGeneration:n}}function Vy(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const a of i){let o=a.message;if(a.context&&Object.keys(a.context).length>0){const l=Object.entries(a.context).map(([c,f])=>`${c}: ${JSON.stringify(f)}`).join(", ");o+=` (${l})`}s.push(o)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function Uy({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=_e.useState("custom");_e.useEffect(()=>{e&&s("custom")},[e]);const a=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),o=[{value:"custom",title:"Keep custom fonts",desc:"Recipients with the font installed see the authored typeface. Others get a generic fallback."},{value:"substitute",title:"Convert to safe fonts",desc:"Rewrite non-safe families to Calibri / Georgia / Consolas so every recipient sees the same glyphs."}];return u.jsx(It,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(St,{className:"max-w-md",children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:"Non-safe fonts in this document"}),u.jsxs(hn,{children:[a," ",n.length===1?"is":"are"," not in the built-in safe list. Choose how to export."]})]}),u.jsx("div",{className:"grid gap-2 py-2",children:o.map(l=>{const c=i===l.value;return u.jsxs("button",{type:"button",onClick:()=>s(l.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${c?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${c?"border-primary":"border-muted-foreground/50"}`,children:c&&u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),u.jsx("span",{className:"text-sm font-medium",children:l.title})]}),u.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:l.desc})]},l.value)})}),u.jsxs(In,{children:[u.jsx(Ee,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(Ee,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const fl=yt==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],$s={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function Jy({name:e,blob:t,displayReloadButton:n,iframeRef:r,autoReload:i,onToggleAutoReload:s,onManualRender:a,isGenerating:o,isRendering:l,onShowCacheMetrics:c,onShowSchemas:f,onShowFonts:d,documentText:p,warnings:h,renderingLibrary:g,setRenderingLibrary:v,onToggleChat:S,chatOpen:x,onTogglePreview:_,previewOpen:m}){const I=g!=="docxjs",[E,w]=b.useState(!1),[N,O]=b.useState(!1),[K,C]=b.useState(!1),[T,A]=b.useState(!1),[F,R]=b.useState(!1),[L,P]=b.useState(!1),{toast:V}=fr(),{generateDocument:U}=By(),se=b.useContext(nd),k=b.useCallback(()=>{const ne={},{customThemes:de}=se.getState();return Object.values(de).forEach(ue=>{ue.valid&&ue.parsed&&(ne[ue.name]=ue.parsed)}),ne},[se]),le=_e.useMemo(()=>{if(!p)return[];try{const ne=JSON.parse(p);return[...(yt==="pptx"?Fm:Lm)(ne)].filter(ue=>!Zm(ue))}catch{return[]}},[p]),[q,y]=b.useState(!1),W=b.useCallback(async()=>{if(t){w(!0);try{await new Promise(ne=>setTimeout(ne,100)),Ei(`${e}${xr}`,t)}finally{setTimeout(()=>w(!1),500)}}},[t,e]),B=b.useCallback(async()=>{if(t){if(le.length===0){await W();return}y(!0)}},[t,le.length,W]),ie=b.useCallback(async ne=>{var de;if(p){w(!0);try{const ue=await U(e,p,k(),void 0,{bypassCache:!0,fonts:{mode:ne}});if(ue.blob.size===0)V({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Ei(`${e}${xr}`,ue.blob);const Z=(de=ue.warnings)==null?void 0:de.find(ke=>{var me,De;return((me=ke.context)==null?void 0:me.code)==="FONT_MODE_SUBSTITUTED"||((De=ke.context)==null?void 0:De.code)==="FONT_MODE_CUSTOM"});Z&&V({title:ne==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:Z.message})}}catch(ue){V({title:"Export failed",description:ue instanceof Error?ue.message:String(ue),variant:"destructive"})}finally{setTimeout(()=>w(!1),500)}}},[p,e,U,V,k]),te=b.useCallback(async()=>{if(!(!h||h.length===0)){O(!0);try{const ne=Vy(h);if(!ne){V({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const de=await U("warnings",JSON.stringify(ne,null,2),{});de&&typeof de=="object"&&"blob"in de&&de.blob&&(Ei(`${e}-warnings${xr}`,de.blob),V({title:"Warnings downloaded",description:`Downloaded warnings document with ${h.length} warning(s).`}))}catch(ne){console.error("Failed to generate warnings document:",ne),V({title:"Download failed",description:ne instanceof Error?ne.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>O(!1),500)}}},[h,e,U,V]),X=b.useCallback(async()=>{const ne=r==null?void 0:r.current;if(ne!=null&&ne.src){C(!0);try{await new Promise(ue=>{let Z=null,ke=!1;const me=()=>{Z&&(clearTimeout(Z),Z=null),ne.removeEventListener("load",j),ne.removeEventListener("error",z)},De=()=>{ke||(ke=!0,me(),ue())},j=()=>De(),z=()=>De();ne.addEventListener("load",j),ne.addEventListener("error",z),Z=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),De()},5e3);const M=ne.src,re=M.includes("?")?"&":"?",ee=Date.now();ne.src=`${M}${re}_reload=${ee}`})}catch(de){console.error("Iframe reload failed:",de)}finally{C(!1)}}},[r]),fe=b.useCallback(async()=>{A(!0);try{await Zy.delete(`/${yt}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),V({title:"Cache Cleared",description:"All caches (document and component) have been successfully cleared.",variant:"default"})}catch(ne){console.error("Failed to clear cache:",ne),V({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{A(!1)}},[V]),be=b.useCallback(async()=>{if(!p){V({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}P(!0);try{const ne=await fetch(`/api/${yt}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:p})});if(!ne.ok){let Z=`Request failed with status ${ne.status}`;try{const ke=await ne.json();ke.message&&(Z=ke.message)}catch{}V({title:"Failed to get standard components",description:Z,variant:"destructive"});return}const de=await ne.json(),ue=JSON.stringify(de.data,null,2);await navigator.clipboard.writeText(ue),V({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(ne){console.error("Error copying standard components:",ne),V({title:"Error",description:ne instanceof Error?ne.message:"Failed to copy standard components",variant:"destructive"})}finally{P(!1)}},[p,V]);return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"bg-sidebar border-b flex flex-row flex-nowrap items-center justify-between gap-x-2 px-3 py-1.5",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[u.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("button",{type:"button","aria-label":"Preview disclaimer",className:"cursor-help inline-flex items-center justify-center h-6 w-6 rounded-sm hover:bg-muted/60 shrink-0",children:u.jsx(Kc,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Ke,{className:"max-w-sm",children:u.jsxs("p",{className:"text-sm",children:["Preview uses"," ",yt==="docx"?"docx-preview":"LibreOffice PDF conversion",". Download the ",xr," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[(!i||I)&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(Ee,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:a,"aria-label":"Render preview",disabled:o||l||m===!1,children:[l?u.jsx(en,{size:"sm"}):u.jsx(ig,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:m===!1?"Open preview to run":l?"Rendering preview...":"Render preview"})})]}),yt==="docx"&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("div",{className:"flex items-center gap-1.5 cursor-help ml-2 mr-1",children:[u.jsx(Xn,{className:"text-xs text-muted-foreground hidden sm:inline",children:"Auto"}),u.jsx(Xa,{checked:i,onCheckedChange:s,disabled:I})]})}),u.jsx(Ke,{children:u.jsx("p",{children:I?"Auto-reload is not available for Office, Docs, and LibreOffice renderers":`${i?"Disable":"Enable"} automatic preview reload on content changes`})})]}),n&&i&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:X,disabled:K||o||l,children:K?u.jsx(en,{size:"sm"}):u.jsx(sg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsx("p",{children:K?"Reloading...":"Reload"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(Ee,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||E||o,onClick:B,children:[E?u.jsx(en,{size:"sm"}):u.jsx(ag,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download ",xr]})})]}),h&&h.length>0&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:N||o,onClick:te,children:N?u.jsx(en,{size:"sm"}):u.jsx(Xc,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download warnings (",h.length,")"]})})]}),g&&v&&u.jsxs(Fr,{value:g,onValueChange:v,children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(rr,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(Lr,{placeholder:"Renderer"})})}),u.jsx(Ke,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(ir,{className:"text-sidebar-foreground",children:fl.map(ne=>u.jsxs(Tn,{value:ne,children:[u.jsxs(qe,{children:[u.jsx(Ge,{tabIndex:-1,children:$s[ne][0]}),u.jsx(Ke,{children:$s[ne][1]})]})," ",ne]},ne))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(ds,{children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(fs,{asChild:!0,children:u.jsx(Ee,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Gc,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ke,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(ai,{align:"end",className:"w-52",children:[f&&u.jsxs(Bt,{onClick:f,children:[u.jsx(og,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),d&&u.jsxs(Bt,{onClick:d,children:[u.jsx(lg,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Bt,{onClick:c,children:[u.jsx(ug,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),u.jsxs(Bt,{onClick:be,disabled:!p||L,children:[u.jsx(Qc,{className:"h-4 w-4 mr-2"}),L?"Copying...":"Copy standard components"]}),u.jsx(sr,{}),u.jsxs(Bt,{onClick:()=>R(!0),disabled:T,className:"text-destructive focus:text-destructive",children:[u.jsx(Va,{className:"h-4 w-4 mr-2"}),T?"Clearing...":"Clear all caches"]}),g&&v&&u.jsxs(u.Fragment,{children:[u.jsx(sr,{className:"lg:hidden"}),fl.map(ne=>u.jsxs(Bt,{className:"lg:hidden",onClick:()=>v(ne),children:[u.jsx("span",{className:"mr-2",children:g===ne?"●":"○"}),$s[ne][0]," ",ne]},ne))]})]})]}),_&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:m?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:_,children:m?u.jsx(ed,{className:"h-3.5 w-3.5"}):u.jsx(cg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[m?"Hide":"Show"," Preview"," ",u.jsx(Br,{shortcut:"mod+shift+p"})]})})]}),S&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ee,{variant:x?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:S,children:u.jsx(td,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[x?"Close":"Open"," AI Chat"," ",u.jsx(Br,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(Uy,{open:q,onClose:()=>y(!1),nonSafeFonts:le,onChoose:ie}),u.jsx(It,{open:F,onOpenChange:R,children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:"Clear all caches?"}),u.jsx(hn,{children:"This will clear document and component caches. Next generation will be uncached."})]}),u.jsxs(In,{children:[u.jsx(Ee,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),u.jsx(Ee,{variant:"destructive",size:"sm",disabled:T,onClick:async()=>{await fe(),R(!1)},children:T?u.jsx(en,{size:"sm"}):"Clear"})]})]})})]})}const Hy=_e.memo(Jy),yf=Om,ro=b.forwardRef(({className:e,...t},n)=>u.jsx(Lc,{ref:n,className:H("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));ro.displayName=Lc.displayName;const Jr=b.forwardRef(({className:e,...t},n)=>u.jsx(Zc,{ref:n,className:H("ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex cursor-pointer items-center justify-center rounded-sm px-3 py-1 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",e),...t}));Jr.displayName=Zc.displayName;const Hr=b.forwardRef(({className:e,...t},n)=>u.jsx(Bc,{ref:n,className:H("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));Hr.displayName=Bc.displayName;async function Wy(e){if(navigator.clipboard&&navigator.clipboard.writeText)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="2em",t.style.height="2em",t.style.padding="0",t.style.border="none",t.style.outline="none",t.style.boxShadow="none",t.style.background="transparent",document.body.appendChild(t),t.focus(),t.select();const n=document.execCommand("copy");return document.body.removeChild(t),n}catch(t){return console.error("Failed to copy text to clipboard:",t),!1}}function qy(e){try{const t=typeof e=="string"?JSON.parse(e):e;return JSON.stringify(t,null,2)}catch(t){return console.error("Failed to format schema:",t),typeof e=="string"?e:JSON.stringify(e)}}async function Gy(e){const t=qy(e);return Wy(t)}const Ky=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=b.useState(n),[s,a]=b.useState(null),[o,l]=b.useState(null),[c,f]=b.useState(!1),[d,p]=b.useState(!1),[h,g]=b.useState(null),[v,S]=b.useState(null),[x,_]=b.useState(!1),{toast:m}=fr(),I=Dt(F=>F.selectedPlugins),E=Array.from(I);b.useEffect(()=>{n&&i(n)},[n]);const w=b.useCallback(async()=>{f(!0),g(null);try{const F=await Es.fetchDocumentSchema(E);a(F)}catch(F){const R=F instanceof Error?F.message:"Failed to load document schema";g(R),m({variant:"destructive",title:"Error loading schema",description:R})}finally{f(!1)}},[E,m]),N=b.useCallback(async()=>{if(!o){p(!0),S(null);try{const F=await Es.fetchThemeSchema();l(F)}catch(F){const R=F instanceof Error?F.message:"Failed to load theme schema";S(R),m({variant:"destructive",title:"Error loading schema",description:R})}finally{p(!1)}}},[o,m]),[O,K]=b.useState([]);b.useEffect(()=>{e||(a(null),g(null))},[e]),b.useEffect(()=>{if(!e)return;const F=E.length!==O.length||E.some((R,L)=>R!==O[L]);r==="document"?(!s||F)&&(F&&(Es.clearPluginSchemaCache(),K([...E])),c||w()):r==="theme"&&!o&&!d&&N()},[r,e,s,o,c,d,E,O,w,N]);const C=E.length,T=r==="document"?s:o,A=async()=>{if(T)try{await Gy(T)&&(_(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>_(!1),2e3))}catch(F){console.error("Copy failed:",F)}};return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ht,{children:u.jsx(Wt,{children:"Schema Viewer"})}),u.jsxs(yf,{value:r,onValueChange:F=>i(F),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Jr,{value:"document",className:"flex items-center gap-1",children:["Document",C>0&&u.jsxs(Jt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",C]})]}),u.jsx(Jr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(Ee,{variant:"ghost",size:"icon",onClick:A,disabled:x||!T,"aria-label":"Copy schema",children:x?u.jsx(pn,{className:"h-4 w-4"}):u.jsx(os,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(Hr,{value:"document",className:"h-full",children:u.jsx(Zi,{schema:s,loading:c,error:h||void 0})}),u.jsx(Hr,{value:"theme",className:"h-full",children:u.jsx(Zi,{schema:o,loading:d,error:v||void 0})})]})]})]})})};function Yy(e,t,n){if(t.length===0)return n;const r=pl(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const a=t[s],o=t[s+1],l=i[a],c=pl(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function pl(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Xy={safe:[],google:[]};function Qy(e,t){var f;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((f=r==null?void 0:r.dataset.weights)==null?void 0:f.split(",").map(Number).filter(d=>!Number.isNaN(d)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((d,p)=>d-p).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${o}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...a].sort((d,p)=>d-p).join(",")}function eb(){const e=Oe(i=>i.activeTab),t=Oe(i=>i.documents),n=Oe(i=>i.documentTypes),r=Oe(i=>i.saveDocument);return b.useCallback(i=>{if(!e)return{ok:!1,error:"No active file"};if(n[e]!=="application/json+theme")return{ok:!1,error:"Fonts are registered on themes, not documents. Open a .theme.json file and try again."};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active theme not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active theme is not valid JSON: ${l.message}`}}const o=i(a);return r(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n,r])}function tb(){const e=Oe(r=>r.activeTab),t=Oe(r=>r.documents),n=Oe(r=>r.saveDocument);return b.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active document not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active document is not valid JSON: ${l.message}`}}const o=Yy(a,r,i);return n(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n])}function nb(e,t,n){(!e.fonts||typeof e.fonts!="object")&&(e.fonts={});const r=e.fonts[t];r&&typeof r=="object"?e.fonts[t]={...r,family:n}:e.fonts[t]=n}function hl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const rb=({open:e,onOpenChange:t})=>{const n=Ci(P=>P.open),r=Ci(P=>P.contextual),i=Ci(P=>P.close),s=e??n,a=r,o=b.useCallback(P=>{t&&t(P),P||i()},[t,i]),[l,c]=b.useState(Xy),[f,d]=b.useState(!1),[p,h]=b.useState(""),[g,v]=b.useState("safe"),[S,x]=b.useState(null),[_,m]=b.useState(null),{toast:I}=fr(),E=eb(),w=tb(),N=Oe(P=>P.activeTab),O=Oe(P=>P.documentTypes),K=N&&O[N]==="application/json+theme",C=!!a||K;b.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(d(!0),fetch("/api/fonts/catalog").then(P=>P.json()).then(P=>c(P)).catch(P=>{I({variant:"destructive",title:"Font catalog unavailable",description:P.message})}).finally(()=>d(!1))))},[s,l,I]),b.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const P of l.google)Qy(P.family,P.weights)},[g,l]);const T=b.useMemo(()=>l.safe.filter(P=>P.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),A=b.useMemo(()=>l.google.filter(P=>P.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),F=b.useCallback(async P=>{try{await navigator.clipboard.writeText(P),m(P),setTimeout(()=>m(null),1500)}catch{I({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[I]),R=b.useCallback(async(P,V,U)=>{x(P);try{const se=E(k=>(nb(k,U,P),k));if(!se.ok){I({variant:"destructive",title:"Could not insert font",description:se.error});return}I({title:"Font inserted",description:`${P} set as ${U} font in "${se.name}".`})}finally{x(null)}},[E,I]),L=b.useCallback(async P=>{if(a){x(P);try{const V=w(a.jsonPath,P);if(!V.ok){I({variant:"destructive",title:"Could not insert font",description:V.error});return}I({title:"Font inserted",description:`${P} set at ${hl(a.jsonPath)}.`}),o(!1)}finally{x(null)}}},[a,w,I,o]);return u.jsx(It,{open:s,onOpenChange:o,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ht,{children:u.jsx(Wt,{children:a?`Font for ${hl(a.jsonPath)}`:"Fonts"})}),!a&&!K&&u.jsx($i,{children:u.jsxs(Fi,{children:["Fonts are registered on themes. Open a ",u.jsx("code",{children:".theme.json"})," ","file to apply a font — the buttons below are disabled until you do."]})}),u.jsxs(yf,{value:g,onValueChange:P=>v(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Jr,{value:"safe",children:["Safe",u.jsx(Jt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(Jr,{value:"google",children:["Google",u.jsx(Jt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]})]}),u.jsx(ii,{type:"search",placeholder:"Search fonts...",value:p,onChange:P=>h(P.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(Hr,{value:"safe",className:"m-0",children:f&&T.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(la,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:T.map(P=>u.jsx(ml,{family:P,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${P}", sans-serif`},onCopy:()=>F(P),copied:_===P,contextual:!!a,onUseThis:()=>L(P),onInsertHeading:()=>R(P,"safe","heading"),onInsertBody:()=>R(P,"safe","body"),applying:S===P,disabled:!C},P))})}),u.jsx(Hr,{value:"google",className:"m-0",children:f&&A.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(la,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:A.map(P=>u.jsx(ml,{family:P.family,meta:u.jsxs("span",{className:"text-xs",children:[P.category," · ",P.weights.length," weights"]}),previewStyle:{fontFamily:`"${P.family}", sans-serif`},onCopy:()=>F(P.family),copied:_===P.family,contextual:!!a,onUseThis:()=>L(P.family),onInsertHeading:()=>R(P.family,"google","heading"),onInsertBody:()=>R(P.family,"google","body"),applying:S===P.family,disabled:!C,extraAction:u.jsx(sb,{family:P.family,weights:P.weights,hasItalic:P.hasItalic})},P.family))})})]})]})]})})},ib="The quick brown fox jumps over the lazy dog",sb=({family:e,weights:t,hasItalic:n})=>{const r=b.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsx(Ee,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(ai,{align:"end",className:"min-w-[260px]",children:[u.jsxs(Ad,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(sr,{}),r.map(i=>{const s=Bm[i]??String(i);return u.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-1.5",children:[u.jsx("span",{className:"truncate",style:{fontFamily:`"${e}", sans-serif`,fontWeight:i},children:s}),u.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:["fontWeight: ",i]})]},i)})]})]})},ml=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:f,extraAction:d})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:ib}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Ee,{size:"sm",onClick:a,disabled:c||f,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(Ee,{size:"sm",variant:"secondary",onClick:o,disabled:c||f,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Ee,{size:"sm",variant:"secondary",onClick:l,disabled:c||f,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),d,u.jsx(Ee,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(pn,{className:"h-4 w-4"}):u.jsx(os,{className:"h-4 w-4"})})]})]});function gl({previewOpen:e,onTogglePreview:t}){const n=Qt(O=>O.name||""),r=Qt(O=>O.blob),i=Qt(O=>O.isGenerating),s=Qt(O=>O.text),a=Qt(O=>O.warnings),o=Qt(O=>O.isRendering),l=hi(O=>O.autoReload),c=hi(O=>O.renderingLibrary),f=hi(O=>O.setSettings),d=hi(O=>O.useGlobalPreviewHeader??!0),p=Oe(O=>O.activeTab),h=Oe(O=>O.documentTypes),g=p&&h[p]==="application/json+theme"?"theme":"document",v=Pe(O=>O.chatOpen),S=Pe(O=>O.toggleChat),[x,_]=_e.useState(!1),m=Ci(O=>O.openFor);if(!d)return null;const I=b.useCallback(()=>f({saveDocumentDebounceWait:2e3,autoReload:!l}),[l,f]),E=b.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),w=b.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),N=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(Hy,{name:N,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:I,onManualRender:E,isGenerating:i,isRendering:!!o,onShowCacheMetrics:w,onShowSchemas:()=>_(!0),onShowFonts:()=>m(),documentText:s,warnings:a,renderingLibrary:c,setRenderingLibrary:O=>f({renderingLibrary:O}),onToggleChat:S,chatOpen:v,onTogglePreview:t,previewOpen:e}),u.jsx(Ky,{open:x,onOpenChange:_,defaultTab:g==="theme"?"theme":"document"}),u.jsx(rb,{})]})}function ab(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const ob=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,lb=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,ub={};function xl(e,t){return(ub.jsx?lb:ob).test(e)}const cb=/[ \t\n\f\r]/g;function db(e){return typeof e=="object"?e.type==="text"?yl(e.value):!1:yl(e)}function yl(e){return e.replace(cb,"")===""}class oi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}oi.prototype.normal={};oi.prototype.property={};oi.prototype.space=void 0;function bf(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new oi(n,r,t)}function ba(e){return e.toLowerCase()}class bt{constructor(t,n){this.attribute=n,this.property=t}}bt.prototype.attribute="";bt.prototype.booleanish=!1;bt.prototype.boolean=!1;bt.prototype.commaOrSpaceSeparated=!1;bt.prototype.commaSeparated=!1;bt.prototype.defined=!1;bt.prototype.mustUseProperty=!1;bt.prototype.number=!1;bt.prototype.overloadedBoolean=!1;bt.prototype.property="";bt.prototype.spaceSeparated=!1;bt.prototype.space=void 0;let fb=0;const Se=On(),tt=On(),va=On(),Y=On(),Ze=On(),tr=On(),wt=On();function On(){return 2**++fb}const wa=Object.freeze(Object.defineProperty({__proto__:null,boolean:Se,booleanish:tt,commaOrSpaceSeparated:wt,commaSeparated:tr,number:Y,overloadedBoolean:va,spaceSeparated:Ze},Symbol.toStringTag,{value:"Module"})),Fs=Object.keys(wa);class io extends bt{constructor(t,n,r,i){let s=-1;if(super(t,n),bl(this,"space",i),typeof r=="number")for(;++s<Fs.length;){const a=Fs[s];bl(this,Fs[s],(r&wa[a])===wa[a])}}}io.prototype.defined=!0;function bl(e,t,n){n&&(e[t]=n)}function pr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new io(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[ba(r)]=r,n[ba(s.attribute)]=r}return new oi(t,n,e.space)}const vf=pr({properties:{ariaActiveDescendant:null,ariaAtomic:tt,ariaAutoComplete:null,ariaBusy:tt,ariaChecked:tt,ariaColCount:Y,ariaColIndex:Y,ariaColSpan:Y,ariaControls:Ze,ariaCurrent:null,ariaDescribedBy:Ze,ariaDetails:null,ariaDisabled:tt,ariaDropEffect:Ze,ariaErrorMessage:null,ariaExpanded:tt,ariaFlowTo:Ze,ariaGrabbed:tt,ariaHasPopup:null,ariaHidden:tt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Ze,ariaLevel:Y,ariaLive:null,ariaModal:tt,ariaMultiLine:tt,ariaMultiSelectable:tt,ariaOrientation:null,ariaOwns:Ze,ariaPlaceholder:null,ariaPosInSet:Y,ariaPressed:tt,ariaReadOnly:tt,ariaRelevant:null,ariaRequired:tt,ariaRoleDescription:Ze,ariaRowCount:Y,ariaRowIndex:Y,ariaRowSpan:Y,ariaSelected:tt,ariaSetSize:Y,ariaSort:null,ariaValueMax:Y,ariaValueMin:Y,ariaValueNow:Y,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function wf(e,t){return t in e?e[t]:t}function kf(e,t){return wf(e,t.toLowerCase())}const pb=pr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:tr,acceptCharset:Ze,accessKey:Ze,action:null,allow:null,allowFullScreen:Se,allowPaymentRequest:Se,allowUserMedia:Se,alt:null,as:null,async:Se,autoCapitalize:null,autoComplete:Ze,autoFocus:Se,autoPlay:Se,blocking:Ze,capture:null,charSet:null,checked:Se,cite:null,className:Ze,cols:Y,colSpan:null,content:null,contentEditable:tt,controls:Se,controlsList:Ze,coords:Y|tr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Se,defer:Se,dir:null,dirName:null,disabled:Se,download:va,draggable:tt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Se,formTarget:null,headers:Ze,height:Y,hidden:va,high:Y,href:null,hrefLang:null,htmlFor:Ze,httpEquiv:Ze,id:null,imageSizes:null,imageSrcSet:null,inert:Se,inputMode:null,integrity:null,is:null,isMap:Se,itemId:null,itemProp:Ze,itemRef:Ze,itemScope:Se,itemType:Ze,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Se,low:Y,manifest:null,max:null,maxLength:Y,media:null,method:null,min:null,minLength:Y,multiple:Se,muted:Se,name:null,nonce:null,noModule:Se,noValidate:Se,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Se,optimum:Y,pattern:null,ping:Ze,placeholder:null,playsInline:Se,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Se,referrerPolicy:null,rel:Ze,required:Se,reversed:Se,rows:Y,rowSpan:Y,sandbox:Ze,scope:null,scoped:Se,seamless:Se,selected:Se,shadowRootClonable:Se,shadowRootDelegatesFocus:Se,shadowRootMode:null,shape:null,size:Y,sizes:null,slot:null,span:Y,spellCheck:tt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Y,step:null,style:null,tabIndex:Y,target:null,title:null,translate:null,type:null,typeMustMatch:Se,useMap:null,value:tt,width:Y,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ze,axis:null,background:null,bgColor:null,border:Y,borderColor:null,bottomMargin:Y,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Se,declare:Se,event:null,face:null,frame:null,frameBorder:null,hSpace:Y,leftMargin:Y,link:null,longDesc:null,lowSrc:null,marginHeight:Y,marginWidth:Y,noResize:Se,noHref:Se,noShade:Se,noWrap:Se,object:null,profile:null,prompt:null,rev:null,rightMargin:Y,rules:null,scheme:null,scrolling:tt,standby:null,summary:null,text:null,topMargin:Y,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Y,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Se,disableRemotePlayback:Se,prefix:null,property:null,results:Y,security:null,unselectable:null},space:"html",transform:kf}),hb=pr({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:wt,accentHeight:Y,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Y,amplitude:Y,arabicForm:null,ascent:Y,attributeName:null,attributeType:null,azimuth:Y,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Y,by:null,calcMode:null,capHeight:Y,className:Ze,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Y,diffuseConstant:Y,direction:null,display:null,dur:null,divisor:Y,dominantBaseline:null,download:Se,dx:null,dy:null,edgeMode:null,editable:null,elevation:Y,enableBackground:null,end:null,event:null,exponent:Y,externalResourcesRequired:null,fill:null,fillOpacity:Y,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:tr,g2:tr,glyphName:tr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Y,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Y,horizOriginX:Y,horizOriginY:Y,id:null,ideographic:Y,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Y,k:Y,k1:Y,k2:Y,k3:Y,k4:Y,kernelMatrix:wt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Y,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Y,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Y,overlineThickness:Y,paintOrder:null,panose1:null,path:null,pathLength:Y,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ze,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Y,pointsAtY:Y,pointsAtZ:Y,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:wt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:wt,rev:wt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:wt,requiredFeatures:wt,requiredFonts:wt,requiredFormats:wt,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Y,specularExponent:Y,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Y,strikethroughThickness:Y,string:null,stroke:null,strokeDashArray:wt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Y,strokeOpacity:Y,strokeWidth:null,style:null,surfaceScale:Y,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:wt,tabIndex:Y,tableValues:null,target:null,targetX:Y,targetY:Y,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:wt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Y,underlineThickness:Y,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Y,values:null,vAlphabetic:Y,vMathematical:Y,vectorEffect:null,vHanging:Y,vIdeographic:Y,version:null,vertAdvY:Y,vertOriginX:Y,vertOriginY:Y,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Y,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:wf}),Sf=pr({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),_f=pr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:kf}),jf=pr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),mb={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},gb=/[A-Z]/g,vl=/-[a-z]/g,xb=/^data[-\w.:]+$/i;function yb(e,t){const n=ba(t);let r=t,i=bt;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&xb.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(vl,vb);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!vl.test(s)){let a=s.replace(gb,bb);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=io}return new i(r,t)}function bb(e){return"-"+e.toLowerCase()}function vb(e){return e.charAt(1).toUpperCase()}const wb=bf([vf,pb,Sf,_f,jf],"html"),so=bf([vf,hb,Sf,_f,jf],"svg");function kb(e){return e.join(" ").trim()}var Ln={},Ls,wl;function Sb(){if(wl)return Ls;wl=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,a=/^[;\s]*/,o=/^\s+|\s+$/g,l=`
3
3
  `,c="/",f="*",d="",p="comment",h="declaration";function g(S,x){if(typeof S!="string")throw new TypeError("First argument must be a string");if(!S)return[];x=x||{};var _=1,m=1;function I(R){var L=R.match(t);L&&(_+=L.length);var P=R.lastIndexOf(l);m=~P?R.length-P:m+R.length}function E(){var R={line:_,column:m};return function(L){return L.position=new w(R),K(),L}}function w(R){this.start=R,this.end={line:_,column:m},this.source=x.source}w.prototype.content=S;function N(R){var L=new Error(x.source+":"+_+":"+m+": "+R);if(L.reason=R,L.filename=x.source,L.line=_,L.column=m,L.source=S,!x.silent)throw L}function O(R){var L=R.exec(S);if(L){var P=L[0];return I(P),S=S.slice(P.length),L}}function K(){O(n)}function C(R){var L;for(R=R||[];L=T();)L!==!1&&R.push(L);return R}function T(){var R=E();if(!(c!=S.charAt(0)||f!=S.charAt(1))){for(var L=2;d!=S.charAt(L)&&(f!=S.charAt(L)||c!=S.charAt(L+1));)++L;if(L+=2,d===S.charAt(L-1))return N("End of comment missing");var P=S.slice(2,L-2);return m+=2,I(P),S=S.slice(L),m+=2,R({type:p,comment:P})}}function A(){var R=E(),L=O(r);if(L){if(T(),!O(i))return N("property missing ':'");var P=O(s),V=R({type:h,property:v(L[0].replace(e,d)),value:P?v(P[0].replace(e,d)):d});return O(a),V}}function F(){var R=[];C(R);for(var L;L=A();)L!==!1&&(R.push(L),C(R));return R}return K(),F()}function v(S){return S?S.replace(o,d):d}return Ls=g,Ls}var kl;function _b(){if(kl)return Ln;kl=1;var e=Ln&&Ln.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ln,"__esModule",{value:!0}),Ln.default=n;const t=e(Sb());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const a=(0,t.default)(r),o=typeof i=="function";return a.forEach(l=>{if(l.type!=="declaration")return;const{property:c,value:f}=l;o?i(c,f,l):f&&(s=s||{},s[c]=f)}),s}return Ln}var wr={},Sl;function jb(){if(Sl)return wr;Sl=1,Object.defineProperty(wr,"__esModule",{value:!0}),wr.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(c){return!c||n.test(c)||e.test(c)},a=function(c,f){return f.toUpperCase()},o=function(c,f){return"".concat(f,"-")},l=function(c,f){return f===void 0&&(f={}),s(c)?c:(c=c.toLowerCase(),f.reactCompat?c=c.replace(i,o):c=c.replace(r,o),c.replace(t,a))};return wr.camelCase=l,wr}var kr,_l;function Cb(){if(_l)return kr;_l=1;var e=kr&&kr.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(_b()),n=jb();function r(i,s){var a={};return!i||typeof i!="string"||(0,t.default)(i,function(o,l){o&&l&&(a[(0,n.camelCase)(o,s)]=l)}),a}return r.default=r,kr=r,kr}var Nb=Cb();const Eb=Za(Nb),Cf=Nf("end"),ao=Nf("start");function Nf(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function Ib(e){const t=ao(e),n=Cf(e);if(t&&n)return{start:t,end:n}}function Rr(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?jl(e.position):"start"in e||"end"in e?jl(e):"line"in e||"column"in e?ka(e):""}function ka(e){return Cl(e&&e.line)+":"+Cl(e&&e.column)}function jl(e){return ka(e&&e.start)+"-"+ka(e&&e.end)}function Cl(e){return e&&typeof e=="number"?e:1}class at extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},a=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(a=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?s.ruleId=r:(s.source=r.slice(0,l),s.ruleId=r.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){const l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}const o=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=o?o.line:void 0,this.name=Rr(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=a&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}at.prototype.file="";at.prototype.name="";at.prototype.reason="";at.prototype.message="";at.prototype.stack="";at.prototype.column=void 0;at.prototype.line=void 0;at.prototype.ancestors=void 0;at.prototype.cause=void 0;at.prototype.fatal=void 0;at.prototype.place=void 0;at.prototype.ruleId=void 0;at.prototype.source=void 0;const oo={}.hasOwnProperty,Tb=new Map,zb=/[A-Z]/g,Ab=new Set(["table","tbody","thead","tfoot","tr"]),Pb=new Set(["td","th"]),Ef="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function Ob(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=Bb(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=Zb(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?so:wb,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=If(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function If(e,t,n){if(t.type==="element")return Db(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return Rb(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return $b(e,t,n);if(t.type==="mdxjsEsm")return Mb(e,t);if(t.type==="root")return Fb(e,t,n);if(t.type==="text")return Lb(e,t)}function Db(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=so,e.schema=i),e.ancestors.push(t);const s=zf(e,t.tagName,!1),a=Vb(e,t);let o=uo(e,t);return Ab.has(t.tagName)&&(o=o.filter(function(l){return typeof l=="string"?!db(l):!0})),Tf(e,a,s,t),lo(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function Rb(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}Wr(e,t.position)}function Mb(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Wr(e,t.position)}function $b(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=so,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:zf(e,t.name,!0),a=Ub(e,t),o=uo(e,t);return Tf(e,a,s,t),lo(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function Fb(e,t,n){const r={};return lo(r,uo(e,t)),e.create(t,e.Fragment,r,n)}function Lb(e,t){return t.value}function Tf(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function lo(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function Zb(e,t,n){return r;function r(i,s,a,o){const c=Array.isArray(a.children)?n:t;return o?c(s,a,o):c(s,a)}}function Bb(e,t){return n;function n(r,i,s,a){const o=Array.isArray(s.children),l=ao(r);return t(i,s,a,o,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function Vb(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&oo.call(t.properties,i)){const s=Jb(e,i,t.properties[i]);if(s){const[a,o]=s;e.tableCellAlignToStyle&&a==="align"&&typeof o=="string"&&Pb.has(t.tagName)?r=o:n[a]=o}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function Ub(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const a=s.expression;a.type;const o=a.properties[0];o.type,Object.assign(n,e.evaluater.evaluateExpression(o.argument))}else Wr(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const o=r.value.data.estree.body[0];o.type,s=e.evaluater.evaluateExpression(o.expression)}else Wr(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function uo(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:Tb;for(;++r<t.children.length;){const s=t.children[r];let a;if(e.passKeys){const l=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(l){const c=i.get(l)||0;a=l+"-"+c,i.set(l,c+1)}}const o=If(e,s,a);o!==void 0&&n.push(o)}return n}function Jb(e,t,n){const r=yb(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?ab(n):kb(n)),r.property==="style"){let i=typeof n=="object"?n:Hb(e,String(n));return e.stylePropertyNameCase==="css"&&(i=Wb(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?mb[r.property]||r.property:r.attribute,n]}}function Hb(e,t){try{return Eb(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new at("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=e.filePath||void 0,i.url=Ef+"#cannot-parse-style-attribute",i}}function zf(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,a;for(;++s<i.length;){const o=xl(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};a=a?{type:"MemberExpression",object:a,property:o,computed:!!(s&&o.type==="Literal"),optional:!1}:o}r=a}else r=xl(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return oo.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);Wr(e)}function Wr(e,t){const n=new at("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=Ef+"#cannot-handle-mdx-estrees-without-createevaluater",n}function Wb(e){const t={};let n;for(n in e)oo.call(e,n)&&(t[qb(n)]=e[n]);return t}function qb(e){let t=e.replace(zb,Gb);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function Gb(e){return"-"+e.toLowerCase()}const Zs={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},Kb={};function co(e,t){const n=Kb,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Af(e,r,i)}function Af(e,t,n){if(Yb(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return Nl(e.children,t,n)}return Array.isArray(e)?Nl(e,t,n):""}function Nl(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=Af(e[i],t,n);return r.join("")}function Yb(e){return!!(e&&typeof e=="object")}const El=document.createElement("i");function fo(e){const t="&"+e+";";El.innerHTML=t;const n=El.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function _t(e,t,n,r){const i=e.length;let s=0,a;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)a=Array.from(r),a.unshift(t,n),e.splice(...a);else for(n&&e.splice(t,n);s<r.length;)a=r.slice(s,s+1e4),a.unshift(t,0),e.splice(...a),s+=1e4,t+=1e4}function Et(e,t){return e.length>0?(_t(e,e.length,0,t),e):t}const Il={}.hasOwnProperty;function Pf(e){const t={};let n=-1;for(;++n<e.length;)Xb(t,e[n]);return t}function Xb(e,t){let n;for(n in t){const i=(Il.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let a;if(s)for(a in s){Il.call(i,a)||(i[a]=[]);const o=s[a];Qb(i[a],Array.isArray(o)?o:o?[o]:[])}}}function Qb(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);_t(e,0,0,r)}function Of(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Mt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const dt=xn(/[A-Za-z]/),st=xn(/[\dA-Za-z]/),ev=xn(/[#-'*+\--9=?A-Z^-~]/);function Ui(e){return e!==null&&(e<32||e===127)}const Sa=xn(/\d/),tv=xn(/[\dA-Fa-f]/),nv=xn(/[!-/:-@[-`{-~]/);function xe(e){return e!==null&&e<-2}function Fe(e){return e!==null&&(e<0||e===32)}function Ie(e){return e===-2||e===-1||e===32}const ys=xn(new RegExp("\\p{P}|\\p{S}","u")),An=xn(/\s/);function xn(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function hr(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let a="";if(s===37&&st(e.charCodeAt(n+1))&&st(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(a=String.fromCharCode(s));else if(s>55295&&s<57344){const o=e.charCodeAt(n+1);s<56320&&o>56319&&o<57344?(a=String.fromCharCode(s,o),i=1):a="�"}else a=String.fromCharCode(s);a&&(t.push(e.slice(r,n),encodeURIComponent(a)),r=n+i+1,a=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function Ae(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return a;function a(l){return Ie(l)?(e.enter(n),o(l)):t(l)}function o(l){return Ie(l)&&s++<i?(e.consume(l),o):(e.exit(n),t(l))}}const rv={tokenize:iv};function iv(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(o){if(o===null){e.consume(o);return}return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),Ae(e,t,"linePrefix")}function i(o){return e.enter("paragraph"),s(o)}function s(o){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,a(o)}function a(o){if(o===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(o);return}return xe(o)?(e.consume(o),e.exit("chunkText"),s):(e.consume(o),a)}}const sv={tokenize:av},Tl={tokenize:ov};function av(e){const t=this,n=[];let r=0,i,s,a;return o;function o(m){if(r<n.length){const I=n[r];return t.containerState=I[1],e.attempt(I[0].continuation,l,c)(m)}return c(m)}function l(m){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&_();const I=t.events.length;let E=I,w;for(;E--;)if(t.events[E][0]==="exit"&&t.events[E][1].type==="chunkFlow"){w=t.events[E][1].end;break}x(r);let N=I;for(;N<t.events.length;)t.events[N][1].end={...w},N++;return _t(t.events,E+1,0,t.events.slice(I)),t.events.length=N,c(m)}return o(m)}function c(m){if(r===n.length){if(!i)return p(m);if(i.currentConstruct&&i.currentConstruct.concrete)return g(m);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Tl,f,d)(m)}function f(m){return i&&_(),x(r),p(m)}function d(m){return t.parser.lazy[t.now().line]=r!==n.length,a=t.now().offset,g(m)}function p(m){return t.containerState={},e.attempt(Tl,h,g)(m)}function h(m){return r++,n.push([t.currentConstruct,t.containerState]),p(m)}function g(m){if(m===null){i&&_(),x(0),e.consume(m);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),v(m)}function v(m){if(m===null){S(e.exit("chunkFlow"),!0),x(0),e.consume(m);return}return xe(m)?(e.consume(m),S(e.exit("chunkFlow")),r=0,t.interrupt=void 0,o):(e.consume(m),v)}function S(m,I){const E=t.sliceStream(m);if(I&&E.push(null),m.previous=s,s&&(s.next=m),s=m,i.defineSkip(m.start),i.write(E),t.parser.lazy[m.start.line]){let w=i.events.length;for(;w--;)if(i.events[w][1].start.offset<a&&(!i.events[w][1].end||i.events[w][1].end.offset>a))return;const N=t.events.length;let O=N,K,C;for(;O--;)if(t.events[O][0]==="exit"&&t.events[O][1].type==="chunkFlow"){if(K){C=t.events[O][1].end;break}K=!0}for(x(r),w=N;w<t.events.length;)t.events[w][1].end={...C},w++;_t(t.events,O+1,0,t.events.slice(N)),t.events.length=w}}function x(m){let I=n.length;for(;I-- >m;){const E=n[I];t.containerState=E[1],E[0].exit.call(t,e)}n.length=m}function _(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function ov(e,t,n){return Ae(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function or(e){if(e===null||Fe(e)||An(e))return 1;if(ys(e))return 2}function bs(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const s=e[i].resolveAll;s&&!r.includes(s)&&(t=s(t,n),r.push(s))}return t}const _a={name:"attention",resolveAll:lv,tokenize:uv};function lv(e,t){let n=-1,r,i,s,a,o,l,c,f;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const d={...e[r][1].end},p={...e[n][1].start};zl(d,-l),zl(p,l),a={type:l>1?"strongSequence":"emphasisSequence",start:d,end:{...e[r][1].end}},o={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:p},s={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...a.start},end:{...o.end}},e[r][1].end={...a.start},e[n][1].start={...o.end},c=[],e[r][1].end.offset-e[r][1].start.offset&&(c=Et(c,[["enter",e[r][1],t],["exit",e[r][1],t]])),c=Et(c,[["enter",i,t],["enter",a,t],["exit",a,t],["enter",s,t]]),c=Et(c,bs(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),c=Et(c,[["exit",s,t],["enter",o,t],["exit",o,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(f=2,c=Et(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):f=0,_t(e,r-1,n-r+3,c),n=r+c.length-f-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function uv(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=or(r);let s;return a;function a(l){return s=l,e.enter("attentionSequence"),o(l)}function o(l){if(l===s)return e.consume(l),o;const c=e.exit("attentionSequence"),f=or(l),d=!f||f===2&&i||n.includes(l),p=!i||i===2&&f||n.includes(r);return c._open=!!(s===42?d:d&&(i||!p)),c._close=!!(s===42?p:p&&(f||!d)),t(l)}}function zl(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const cv={name:"autolink",tokenize:dv};function dv(e,t,n){let r=0;return i;function i(h){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(h){return dt(h)?(e.consume(h),a):h===64?n(h):c(h)}function a(h){return h===43||h===45||h===46||st(h)?(r=1,o(h)):c(h)}function o(h){return h===58?(e.consume(h),r=0,l):(h===43||h===45||h===46||st(h))&&r++<32?(e.consume(h),o):(r=0,c(h))}function l(h){return h===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.exit("autolink"),t):h===null||h===32||h===60||Ui(h)?n(h):(e.consume(h),l)}function c(h){return h===64?(e.consume(h),f):ev(h)?(e.consume(h),c):n(h)}function f(h){return st(h)?d(h):n(h)}function d(h){return h===46?(e.consume(h),r=0,f):h===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.exit("autolink"),t):p(h)}function p(h){if((h===45||st(h))&&r++<63){const g=h===45?p:d;return e.consume(h),g}return n(h)}}const li={partial:!0,tokenize:fv};function fv(e,t,n){return r;function r(s){return Ie(s)?Ae(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||xe(s)?t(s):n(s)}}const Df={continuation:{tokenize:hv},exit:mv,name:"blockQuote",tokenize:pv};function pv(e,t,n){const r=this;return i;function i(a){if(a===62){const o=r.containerState;return o.open||(e.enter("blockQuote",{_container:!0}),o.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(a),e.exit("blockQuoteMarker"),s}return n(a)}function s(a){return Ie(a)?(e.enter("blockQuotePrefixWhitespace"),e.consume(a),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(a))}}function hv(e,t,n){const r=this;return i;function i(a){return Ie(a)?Ae(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a):s(a)}function s(a){return e.attempt(Df,t,n)(a)}}function mv(e){e.exit("blockQuote")}const Rf={name:"characterEscape",tokenize:gv};function gv(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return nv(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const Mf={name:"characterReference",tokenize:xv};function xv(e,t,n){const r=this;let i=0,s,a;return o;function o(d){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),l}function l(d){return d===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(d),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),s=31,a=st,f(d))}function c(d){return d===88||d===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(d),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,a=tv,f):(e.enter("characterReferenceValue"),s=7,a=Sa,f(d))}function f(d){if(d===59&&i){const p=e.exit("characterReferenceValue");return a===st&&!fo(r.sliceSerialize(p))?n(d):(e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return a(d)&&i++<s?(e.consume(d),f):n(d)}}const Al={partial:!0,tokenize:bv},Pl={concrete:!0,name:"codeFenced",tokenize:yv};function yv(e,t,n){const r=this,i={partial:!0,tokenize:E};let s=0,a=0,o;return l;function l(w){return c(w)}function c(w){const N=r.events[r.events.length-1];return s=N&&N[1].type==="linePrefix"?N[2].sliceSerialize(N[1],!0).length:0,o=w,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),f(w)}function f(w){return w===o?(a++,e.consume(w),f):a<3?n(w):(e.exit("codeFencedFenceSequence"),Ie(w)?Ae(e,d,"whitespace")(w):d(w))}function d(w){return w===null||xe(w)?(e.exit("codeFencedFence"),r.interrupt?t(w):e.check(Al,v,I)(w)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(w))}function p(w){return w===null||xe(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),d(w)):Ie(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),Ae(e,h,"whitespace")(w)):w===96&&w===o?n(w):(e.consume(w),p)}function h(w){return w===null||xe(w)?d(w):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(w))}function g(w){return w===null||xe(w)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),d(w)):w===96&&w===o?n(w):(e.consume(w),g)}function v(w){return e.attempt(i,I,S)(w)}function S(w){return e.enter("lineEnding"),e.consume(w),e.exit("lineEnding"),x}function x(w){return s>0&&Ie(w)?Ae(e,_,"linePrefix",s+1)(w):_(w)}function _(w){return w===null||xe(w)?e.check(Al,v,I)(w):(e.enter("codeFlowValue"),m(w))}function m(w){return w===null||xe(w)?(e.exit("codeFlowValue"),_(w)):(e.consume(w),m)}function I(w){return e.exit("codeFenced"),t(w)}function E(w,N,O){let K=0;return C;function C(L){return w.enter("lineEnding"),w.consume(L),w.exit("lineEnding"),T}function T(L){return w.enter("codeFencedFence"),Ie(L)?Ae(w,A,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(L):A(L)}function A(L){return L===o?(w.enter("codeFencedFenceSequence"),F(L)):O(L)}function F(L){return L===o?(K++,w.consume(L),F):K>=a?(w.exit("codeFencedFenceSequence"),Ie(L)?Ae(w,R,"whitespace")(L):R(L)):O(L)}function R(L){return L===null||xe(L)?(w.exit("codeFencedFence"),N(L)):O(L)}}}function bv(e,t,n){const r=this;return i;function i(a){return a===null?n(a):(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),s)}function s(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}const Bs={name:"codeIndented",tokenize:wv},vv={partial:!0,tokenize:kv};function wv(e,t,n){const r=this;return i;function i(c){return e.enter("codeIndented"),Ae(e,s,"linePrefix",5)(c)}function s(c){const f=r.events[r.events.length-1];return f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?a(c):n(c)}function a(c){return c===null?l(c):xe(c)?e.attempt(vv,a,l)(c):(e.enter("codeFlowValue"),o(c))}function o(c){return c===null||xe(c)?(e.exit("codeFlowValue"),a(c)):(e.consume(c),o)}function l(c){return e.exit("codeIndented"),t(c)}}function kv(e,t,n){const r=this;return i;function i(a){return r.parser.lazy[r.now().line]?n(a):xe(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),i):Ae(e,s,"linePrefix",5)(a)}function s(a){const o=r.events[r.events.length-1];return o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(a):xe(a)?i(a):n(a)}}const Sv={name:"codeText",previous:jv,resolve:_v,tokenize:Cv};function _v(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function jv(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Cv(e,t,n){let r=0,i,s;return a;function a(d){return e.enter("codeText"),e.enter("codeTextSequence"),o(d)}function o(d){return d===96?(e.consume(d),r++,o):(e.exit("codeTextSequence"),l(d))}function l(d){return d===null?n(d):d===32?(e.enter("space"),e.consume(d),e.exit("space"),l):d===96?(s=e.enter("codeTextSequence"),i=0,f(d)):xe(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),l):(e.enter("codeTextData"),c(d))}function c(d){return d===null||d===32||d===96||xe(d)?(e.exit("codeTextData"),l(d)):(e.consume(d),c)}function f(d){return d===96?(e.consume(d),i++,f):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(d)):(s.type="codeTextData",c(d))}}class Nv{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Sr(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Sr(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Sr(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Sr(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Sr(this.left,n.reverse())}}}function Sr(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function $f(e){const t={};let n=-1,r,i,s,a,o,l,c;const f=new Nv(e);for(;++n<f.length;){for(;n in t;)n=t[n];if(r=f.get(n),n&&r[1].type==="chunkFlow"&&f.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,Ev(f,n)),n=t[n],c=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(a=f.get(s),a[1].type==="lineEnding"||a[1].type==="lineEndingBlank")a[0]==="enter"&&(i&&(f.get(i)[1].type="lineEndingBlank"),a[1].type="lineEnding",i=s);else if(!(a[1].type==="linePrefix"||a[1].type==="listItemIndent"))break;i&&(r[1].end={...f.get(i)[1].start},o=f.slice(i,n),o.unshift(r),f.splice(i,n-i+1,o))}}return _t(e,0,Number.POSITIVE_INFINITY,f.slice(0)),!c}function Ev(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let a=n._tokenizer;a||(a=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(a._contentTypeTextTrailing=!0));const o=a.events,l=[],c={};let f,d,p=-1,h=n,g=0,v=0;const S=[v];for(;h;){for(;e.get(++i)[1]!==h;);s.push(i),h._tokenizer||(f=r.sliceStream(h),h.next||f.push(null),d&&a.defineSkip(h.start),h._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=!0),a.write(f),h._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=void 0)),d=h,h=h.next}for(h=n;++p<o.length;)o[p][0]==="exit"&&o[p-1][0]==="enter"&&o[p][1].type===o[p-1][1].type&&o[p][1].start.line!==o[p][1].end.line&&(v=p+1,S.push(v),h._tokenizer=void 0,h.previous=void 0,h=h.next);for(a.events=[],h?(h._tokenizer=void 0,h.previous=void 0):S.pop(),p=S.length;p--;){const x=o.slice(S[p],S[p+1]),_=s.pop();l.push([_,_+x.length-1]),e.splice(_,2,x)}for(l.reverse(),p=-1;++p<l.length;)c[g+l[p][0]]=g+l[p][1],g+=l[p][1]-l[p][0]-1;return c}const Iv={resolve:zv,tokenize:Av},Tv={partial:!0,tokenize:Pv};function zv(e){return $f(e),e}function Av(e,t){let n;return r;function r(o){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(o)}function i(o){return o===null?s(o):xe(o)?e.check(Tv,a,s)(o):(e.consume(o),i)}function s(o){return e.exit("chunkContent"),e.exit("content"),t(o)}function a(o){return e.consume(o),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function Pv(e,t,n){const r=this;return i;function i(a){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),Ae(e,s,"linePrefix")}function s(a){if(a===null||xe(a))return n(a);const o=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(a):e.interrupt(r.parser.constructs.flow,n,t)(a)}}function Ff(e,t,n,r,i,s,a,o,l){const c=l||Number.POSITIVE_INFINITY;let f=0;return d;function d(x){return x===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(x),e.exit(s),p):x===null||x===32||x===41||Ui(x)?n(x):(e.enter(r),e.enter(a),e.enter(o),e.enter("chunkString",{contentType:"string"}),v(x))}function p(x){return x===62?(e.enter(s),e.consume(x),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(o),e.enter("chunkString",{contentType:"string"}),h(x))}function h(x){return x===62?(e.exit("chunkString"),e.exit(o),p(x)):x===null||x===60||xe(x)?n(x):(e.consume(x),x===92?g:h)}function g(x){return x===60||x===62||x===92?(e.consume(x),h):h(x)}function v(x){return!f&&(x===null||x===41||Fe(x))?(e.exit("chunkString"),e.exit(o),e.exit(a),e.exit(r),t(x)):f<c&&x===40?(e.consume(x),f++,v):x===41?(e.consume(x),f--,v):x===null||x===32||x===40||Ui(x)?n(x):(e.consume(x),x===92?S:v)}function S(x){return x===40||x===41||x===92?(e.consume(x),v):v(x)}}function Lf(e,t,n,r,i,s){const a=this;let o=0,l;return c;function c(h){return e.enter(r),e.enter(i),e.consume(h),e.exit(i),e.enter(s),f}function f(h){return o>999||h===null||h===91||h===93&&!l||h===94&&!o&&"_hiddenFootnoteSupport"in a.parser.constructs?n(h):h===93?(e.exit(s),e.enter(i),e.consume(h),e.exit(i),e.exit(r),t):xe(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),f):(e.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===null||h===91||h===93||xe(h)||o++>999?(e.exit("chunkString"),f(h)):(e.consume(h),l||(l=!Ie(h)),h===92?p:d)}function p(h){return h===91||h===92||h===93?(e.consume(h),o++,d):d(h)}}function Zf(e,t,n,r,i,s){let a;return o;function o(p){return p===34||p===39||p===40?(e.enter(r),e.enter(i),e.consume(p),e.exit(i),a=p===40?41:p,l):n(p)}function l(p){return p===a?(e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):(e.enter(s),c(p))}function c(p){return p===a?(e.exit(s),l(a)):p===null?n(p):xe(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),Ae(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===a||p===null||xe(p)?(e.exit("chunkString"),c(p)):(e.consume(p),p===92?d:f)}function d(p){return p===a||p===92?(e.consume(p),f):f(p)}}function Mr(e,t){let n;return r;function r(i){return xe(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):Ie(i)?Ae(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const Ov={name:"definition",tokenize:Rv},Dv={partial:!0,tokenize:Mv};function Rv(e,t,n){const r=this;let i;return s;function s(h){return e.enter("definition"),a(h)}function a(h){return Lf.call(r,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return i=Mt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),l):n(h)}function l(h){return Fe(h)?Mr(e,c)(h):c(h)}function c(h){return Ff(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function f(h){return e.attempt(Dv,d,d)(h)}function d(h){return Ie(h)?Ae(e,p,"whitespace")(h):p(h)}function p(h){return h===null||xe(h)?(e.exit("definition"),r.parser.defined.push(i),t(h)):n(h)}}function Mv(e,t,n){return r;function r(o){return Fe(o)?Mr(e,i)(o):n(o)}function i(o){return Zf(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(o)}function s(o){return Ie(o)?Ae(e,a,"whitespace")(o):a(o)}function a(o){return o===null||xe(o)?t(o):n(o)}}const $v={name:"hardBreakEscape",tokenize:Fv};function Fv(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return xe(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const Lv={name:"headingAtx",resolve:Zv,tokenize:Bv};function Zv(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},_t(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function Bv(e,t,n){let r=0;return i;function i(f){return e.enter("atxHeading"),s(f)}function s(f){return e.enter("atxHeadingSequence"),a(f)}function a(f){return f===35&&r++<6?(e.consume(f),a):f===null||Fe(f)?(e.exit("atxHeadingSequence"),o(f)):n(f)}function o(f){return f===35?(e.enter("atxHeadingSequence"),l(f)):f===null||xe(f)?(e.exit("atxHeading"),t(f)):Ie(f)?Ae(e,o,"whitespace")(f):(e.enter("atxHeadingText"),c(f))}function l(f){return f===35?(e.consume(f),l):(e.exit("atxHeadingSequence"),o(f))}function c(f){return f===null||f===35||Fe(f)?(e.exit("atxHeadingText"),o(f)):(e.consume(f),c)}}const Vv=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Ol=["pre","script","style","textarea"],Uv={concrete:!0,name:"htmlFlow",resolveTo:Wv,tokenize:qv},Jv={partial:!0,tokenize:Kv},Hv={partial:!0,tokenize:Gv};function Wv(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function qv(e,t,n){const r=this;let i,s,a,o,l;return c;function c(y){return f(y)}function f(y){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(y),d}function d(y){return y===33?(e.consume(y),p):y===47?(e.consume(y),s=!0,v):y===63?(e.consume(y),i=3,r.interrupt?t:k):dt(y)?(e.consume(y),a=String.fromCharCode(y),S):n(y)}function p(y){return y===45?(e.consume(y),i=2,h):y===91?(e.consume(y),i=5,o=0,g):dt(y)?(e.consume(y),i=4,r.interrupt?t:k):n(y)}function h(y){return y===45?(e.consume(y),r.interrupt?t:k):n(y)}function g(y){const W="CDATA[";return y===W.charCodeAt(o++)?(e.consume(y),o===W.length?r.interrupt?t:A:g):n(y)}function v(y){return dt(y)?(e.consume(y),a=String.fromCharCode(y),S):n(y)}function S(y){if(y===null||y===47||y===62||Fe(y)){const W=y===47,B=a.toLowerCase();return!W&&!s&&Ol.includes(B)?(i=1,r.interrupt?t(y):A(y)):Vv.includes(a.toLowerCase())?(i=6,W?(e.consume(y),x):r.interrupt?t(y):A(y)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(y):s?_(y):m(y))}return y===45||st(y)?(e.consume(y),a+=String.fromCharCode(y),S):n(y)}function x(y){return y===62?(e.consume(y),r.interrupt?t:A):n(y)}function _(y){return Ie(y)?(e.consume(y),_):C(y)}function m(y){return y===47?(e.consume(y),C):y===58||y===95||dt(y)?(e.consume(y),I):Ie(y)?(e.consume(y),m):C(y)}function I(y){return y===45||y===46||y===58||y===95||st(y)?(e.consume(y),I):E(y)}function E(y){return y===61?(e.consume(y),w):Ie(y)?(e.consume(y),E):m(y)}function w(y){return y===null||y===60||y===61||y===62||y===96?n(y):y===34||y===39?(e.consume(y),l=y,N):Ie(y)?(e.consume(y),w):O(y)}function N(y){return y===l?(e.consume(y),l=null,K):y===null||xe(y)?n(y):(e.consume(y),N)}function O(y){return y===null||y===34||y===39||y===47||y===60||y===61||y===62||y===96||Fe(y)?E(y):(e.consume(y),O)}function K(y){return y===47||y===62||Ie(y)?m(y):n(y)}function C(y){return y===62?(e.consume(y),T):n(y)}function T(y){return y===null||xe(y)?A(y):Ie(y)?(e.consume(y),T):n(y)}function A(y){return y===45&&i===2?(e.consume(y),P):y===60&&i===1?(e.consume(y),V):y===62&&i===4?(e.consume(y),le):y===63&&i===3?(e.consume(y),k):y===93&&i===5?(e.consume(y),se):xe(y)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(Jv,q,F)(y)):y===null||xe(y)?(e.exit("htmlFlowData"),F(y)):(e.consume(y),A)}function F(y){return e.check(Hv,R,q)(y)}function R(y){return e.enter("lineEnding"),e.consume(y),e.exit("lineEnding"),L}function L(y){return y===null||xe(y)?F(y):(e.enter("htmlFlowData"),A(y))}function P(y){return y===45?(e.consume(y),k):A(y)}function V(y){return y===47?(e.consume(y),a="",U):A(y)}function U(y){if(y===62){const W=a.toLowerCase();return Ol.includes(W)?(e.consume(y),le):A(y)}return dt(y)&&a.length<8?(e.consume(y),a+=String.fromCharCode(y),U):A(y)}function se(y){return y===93?(e.consume(y),k):A(y)}function k(y){return y===62?(e.consume(y),le):y===45&&i===2?(e.consume(y),k):A(y)}function le(y){return y===null||xe(y)?(e.exit("htmlFlowData"),q(y)):(e.consume(y),le)}function q(y){return e.exit("htmlFlow"),t(y)}}function Gv(e,t,n){const r=this;return i;function i(a){return xe(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),s):n(a)}function s(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}function Kv(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(li,t,n)}}const Yv={name:"htmlText",tokenize:Xv};function Xv(e,t,n){const r=this;let i,s,a;return o;function o(k){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(k),l}function l(k){return k===33?(e.consume(k),c):k===47?(e.consume(k),E):k===63?(e.consume(k),m):dt(k)?(e.consume(k),O):n(k)}function c(k){return k===45?(e.consume(k),f):k===91?(e.consume(k),s=0,g):dt(k)?(e.consume(k),_):n(k)}function f(k){return k===45?(e.consume(k),h):n(k)}function d(k){return k===null?n(k):k===45?(e.consume(k),p):xe(k)?(a=d,V(k)):(e.consume(k),d)}function p(k){return k===45?(e.consume(k),h):d(k)}function h(k){return k===62?P(k):k===45?p(k):d(k)}function g(k){const le="CDATA[";return k===le.charCodeAt(s++)?(e.consume(k),s===le.length?v:g):n(k)}function v(k){return k===null?n(k):k===93?(e.consume(k),S):xe(k)?(a=v,V(k)):(e.consume(k),v)}function S(k){return k===93?(e.consume(k),x):v(k)}function x(k){return k===62?P(k):k===93?(e.consume(k),x):v(k)}function _(k){return k===null||k===62?P(k):xe(k)?(a=_,V(k)):(e.consume(k),_)}function m(k){return k===null?n(k):k===63?(e.consume(k),I):xe(k)?(a=m,V(k)):(e.consume(k),m)}function I(k){return k===62?P(k):m(k)}function E(k){return dt(k)?(e.consume(k),w):n(k)}function w(k){return k===45||st(k)?(e.consume(k),w):N(k)}function N(k){return xe(k)?(a=N,V(k)):Ie(k)?(e.consume(k),N):P(k)}function O(k){return k===45||st(k)?(e.consume(k),O):k===47||k===62||Fe(k)?K(k):n(k)}function K(k){return k===47?(e.consume(k),P):k===58||k===95||dt(k)?(e.consume(k),C):xe(k)?(a=K,V(k)):Ie(k)?(e.consume(k),K):P(k)}function C(k){return k===45||k===46||k===58||k===95||st(k)?(e.consume(k),C):T(k)}function T(k){return k===61?(e.consume(k),A):xe(k)?(a=T,V(k)):Ie(k)?(e.consume(k),T):K(k)}function A(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(e.consume(k),i=k,F):xe(k)?(a=A,V(k)):Ie(k)?(e.consume(k),A):(e.consume(k),R)}function F(k){return k===i?(e.consume(k),i=void 0,L):k===null?n(k):xe(k)?(a=F,V(k)):(e.consume(k),F)}function R(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||Fe(k)?K(k):(e.consume(k),R)}function L(k){return k===47||k===62||Fe(k)?K(k):n(k)}function P(k){return k===62?(e.consume(k),e.exit("htmlTextData"),e.exit("htmlText"),t):n(k)}function V(k){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),U}function U(k){return Ie(k)?Ae(e,se,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):se(k)}function se(k){return e.enter("htmlTextData"),a(k)}}const po={name:"labelEnd",resolveAll:nw,resolveTo:rw,tokenize:iw},Qv={tokenize:sw},ew={tokenize:aw},tw={tokenize:ow};function nw(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&_t(e,0,e.length,n),e}function rw(e,t){let n=e.length,r=0,i,s,a,o;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(a){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(a=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},c={type:"label",start:{...e[s][1].start},end:{...e[a][1].end}},f={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[a-2][1].start}};return o=[["enter",l,t],["enter",c,t]],o=Et(o,e.slice(s+1,s+r+3)),o=Et(o,[["enter",f,t]]),o=Et(o,bs(t.parser.constructs.insideSpan.null,e.slice(s+r+4,a-3),t)),o=Et(o,[["exit",f,t],e[a-2],e[a-1],["exit",c,t]]),o=Et(o,e.slice(a+1)),o=Et(o,[["exit",l,t]]),_t(e,s,e.length,o),e}function iw(e,t,n){const r=this;let i=r.events.length,s,a;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return o;function o(p){return s?s._inactive?d(p):(a=r.parser.defined.includes(Mt(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(p),e.exit("labelMarker"),e.exit("labelEnd"),l):n(p)}function l(p){return p===40?e.attempt(Qv,f,a?f:d)(p):p===91?e.attempt(ew,f,a?c:d)(p):a?f(p):d(p)}function c(p){return e.attempt(tw,f,d)(p)}function f(p){return t(p)}function d(p){return s._balanced=!0,n(p)}}function sw(e,t,n){return r;function r(d){return e.enter("resource"),e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),i}function i(d){return Fe(d)?Mr(e,s)(d):s(d)}function s(d){return d===41?f(d):Ff(e,a,o,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(d)}function a(d){return Fe(d)?Mr(e,l)(d):f(d)}function o(d){return n(d)}function l(d){return d===34||d===39||d===40?Zf(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(d):f(d)}function c(d){return Fe(d)?Mr(e,f)(d):f(d)}function f(d){return d===41?(e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),e.exit("resource"),t):n(d)}}function aw(e,t,n){const r=this;return i;function i(o){return Lf.call(r,e,s,a,"reference","referenceMarker","referenceString")(o)}function s(o){return r.parser.defined.includes(Mt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(o):n(o)}function a(o){return n(o)}}function ow(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const lw={name:"labelStartImage",resolveAll:po.resolveAll,tokenize:uw};function uw(e,t,n){const r=this;return i;function i(o){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(o),e.exit("labelImageMarker"),s}function s(o){return o===91?(e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelImage"),a):n(o)}function a(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const cw={name:"labelStartLink",resolveAll:po.resolveAll,tokenize:dw};function dw(e,t,n){const r=this;return i;function i(a){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelLink"),s}function s(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const Vs={name:"lineEnding",tokenize:fw};function fw(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),Ae(e,t,"linePrefix")}}const Ii={name:"thematicBreak",tokenize:pw};function pw(e,t,n){let r=0,i;return s;function s(c){return e.enter("thematicBreak"),a(c)}function a(c){return i=c,o(c)}function o(c){return c===i?(e.enter("thematicBreakSequence"),l(c)):r>=3&&(c===null||xe(c))?(e.exit("thematicBreak"),t(c)):n(c)}function l(c){return c===i?(e.consume(c),r++,l):(e.exit("thematicBreakSequence"),Ie(c)?Ae(e,o,"whitespace")(c):o(c))}}const ht={continuation:{tokenize:xw},exit:bw,name:"list",tokenize:gw},hw={partial:!0,tokenize:vw},mw={partial:!0,tokenize:yw};function gw(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,a=0;return o;function o(h){const g=r.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||h===r.containerState.marker:Sa(h)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),h===42||h===45?e.check(Ii,n,c)(h):c(h);if(!r.interrupt||h===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(h)}return n(h)}function l(h){return Sa(h)&&++a<10?(e.consume(h),l):(!r.interrupt||a<2)&&(r.containerState.marker?h===r.containerState.marker:h===41||h===46)?(e.exit("listItemValue"),c(h)):n(h)}function c(h){return e.enter("listItemMarker"),e.consume(h),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||h,e.check(li,r.interrupt?n:f,e.attempt(hw,p,d))}function f(h){return r.containerState.initialBlankLine=!0,s++,p(h)}function d(h){return Ie(h)?(e.enter("listItemPrefixWhitespace"),e.consume(h),e.exit("listItemPrefixWhitespace"),p):n(h)}function p(h){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(h)}}function xw(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(li,i,s);function i(o){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Ae(e,t,"listItemIndent",r.containerState.size+1)(o)}function s(o){return r.containerState.furtherBlankLines||!Ie(o)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,a(o)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(mw,t,a)(o))}function a(o){return r.containerState._closeFlow=!0,r.interrupt=void 0,Ae(e,e.attempt(ht,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o)}}function yw(e,t,n){const r=this;return Ae(e,i,"listItemIndent",r.containerState.size+1);function i(s){const a=r.events[r.events.length-1];return a&&a[1].type==="listItemIndent"&&a[2].sliceSerialize(a[1],!0).length===r.containerState.size?t(s):n(s)}}function bw(e){e.exit(this.containerState.type)}function vw(e,t,n){const r=this;return Ae(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const a=r.events[r.events.length-1];return!Ie(s)&&a&&a[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const Dl={name:"setextUnderline",resolveTo:ww,tokenize:kw};function ww(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const a={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",a,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=a,e.push(["exit",a,t]),e}function kw(e,t,n){const r=this;let i;return s;function s(c){let f=r.events.length,d;for(;f--;)if(r.events[f][1].type!=="lineEnding"&&r.events[f][1].type!=="linePrefix"&&r.events[f][1].type!=="content"){d=r.events[f][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||d)?(e.enter("setextHeadingLine"),i=c,a(c)):n(c)}function a(c){return e.enter("setextHeadingLineSequence"),o(c)}function o(c){return c===i?(e.consume(c),o):(e.exit("setextHeadingLineSequence"),Ie(c)?Ae(e,l,"lineSuffix")(c):l(c))}function l(c){return c===null||xe(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const Sw={tokenize:_w};function _w(e){const t=this,n=e.attempt(li,r,e.attempt(this.parser.constructs.flowInitial,i,Ae(e,e.attempt(this.parser.constructs.flow,i,e.attempt(Iv,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const jw={resolveAll:Vf()},Cw=Bf("string"),Nw=Bf("text");function Bf(e){return{resolveAll:Vf(e==="text"?Ew:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,a,o);return a;function a(f){return c(f)?s(f):o(f)}function o(f){if(f===null){n.consume(f);return}return n.enter("data"),n.consume(f),l}function l(f){return c(f)?(n.exit("data"),s(f)):(n.consume(f),l)}function c(f){if(f===null)return!0;const d=i[f];let p=-1;if(d)for(;++p<d.length;){const h=d[p];if(!h.previous||h.previous.call(r,r.previous))return!0}return!1}}}function Vf(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function Ew(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,a=-1,o=0,l;for(;s--;){const c=i[s];if(typeof c=="string"){for(a=c.length;c.charCodeAt(a-1)===32;)o++,a--;if(a)break;a=-1}else if(c===-2)l=!0,o++;else if(c!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(o=0),o){const c={type:n===e.length||l||o<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?a:r.start._bufferIndex+a,_index:r.start._index+s,line:r.end.line,column:r.end.column-o,offset:r.end.offset-o},end:{...r.end}};r.end={...c.start},r.start.offset===r.end.offset?Object.assign(r,c):(e.splice(n,0,["enter",c,t],["exit",c,t]),n+=2)}n++}return e}const Iw={42:ht,43:ht,45:ht,48:ht,49:ht,50:ht,51:ht,52:ht,53:ht,54:ht,55:ht,56:ht,57:ht,62:Df},Tw={91:Ov},zw={[-2]:Bs,[-1]:Bs,32:Bs},Aw={35:Lv,42:Ii,45:[Dl,Ii],60:Uv,61:Dl,95:Ii,96:Pl,126:Pl},Pw={38:Mf,92:Rf},Ow={[-5]:Vs,[-4]:Vs,[-3]:Vs,33:lw,38:Mf,42:_a,60:[cv,Yv],91:cw,92:[$v,Rf],93:po,95:_a,96:Sv},Dw={null:[_a,jw]},Rw={null:[42,95]},Mw={null:[]},$w=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:Rw,contentInitial:Tw,disable:Mw,document:Iw,flow:Aw,flowInitial:zw,insideSpan:Dw,string:Pw,text:Ow},Symbol.toStringTag,{value:"Module"}));function Fw(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let a=[],o=[];const l={attempt:N(E),check:N(w),consume:_,enter:m,exit:I,interrupt:N(w,{interrupt:!0})},c={code:null,containerState:{},defineSkip:v,events:[],now:g,parser:e,previous:null,sliceSerialize:p,sliceStream:h,write:d};let f=t.tokenize.call(c,l);return t.resolveAll&&s.push(t),c;function d(T){return a=Et(a,T),S(),a[a.length-1]!==null?[]:(O(t,0),c.events=bs(s,c.events,c),c.events)}function p(T,A){return Zw(h(T),A)}function h(T){return Lw(a,T)}function g(){const{_bufferIndex:T,_index:A,line:F,column:R,offset:L}=r;return{_bufferIndex:T,_index:A,line:F,column:R,offset:L}}function v(T){i[T.line]=T.column,C()}function S(){let T;for(;r._index<a.length;){const A=a[r._index];if(typeof A=="string")for(T=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===T&&r._bufferIndex<A.length;)x(A.charCodeAt(r._bufferIndex));else x(A)}}function x(T){f=f(T)}function _(T){xe(T)?(r.line++,r.column=1,r.offset+=T===-3?2:1,C()):T!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===a[r._index].length&&(r._bufferIndex=-1,r._index++)),c.previous=T}function m(T,A){const F=A||{};return F.type=T,F.start=g(),c.events.push(["enter",F,c]),o.push(F),F}function I(T){const A=o.pop();return A.end=g(),c.events.push(["exit",A,c]),A}function E(T,A){O(T,A.from)}function w(T,A){A.restore()}function N(T,A){return F;function F(R,L,P){let V,U,se,k;return Array.isArray(R)?q(R):"tokenize"in R?q([R]):le(R);function le(ie){return te;function te(X){const fe=X!==null&&ie[X],be=X!==null&&ie.null,ne=[...Array.isArray(fe)?fe:fe?[fe]:[],...Array.isArray(be)?be:be?[be]:[]];return q(ne)(X)}}function q(ie){return V=ie,U=0,ie.length===0?P:y(ie[U])}function y(ie){return te;function te(X){return k=K(),se=ie,ie.partial||(c.currentConstruct=ie),ie.name&&c.parser.constructs.disable.null.includes(ie.name)?B():ie.tokenize.call(A?Object.assign(Object.create(c),A):c,l,W,B)(X)}}function W(ie){return T(se,k),L}function B(ie){return k.restore(),++U<V.length?y(V[U]):P}}}function O(T,A){T.resolveAll&&!s.includes(T)&&s.push(T),T.resolve&&_t(c.events,A,c.events.length-A,T.resolve(c.events.slice(A),c)),T.resolveTo&&(c.events=T.resolveTo(c.events,c))}function K(){const T=g(),A=c.previous,F=c.currentConstruct,R=c.events.length,L=Array.from(o);return{from:R,restore:P};function P(){r=T,c.previous=A,c.currentConstruct=F,c.events.length=R,o=L,C()}}function C(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function Lw(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let a;if(n===i)a=[e[n].slice(r,s)];else{if(a=e.slice(n,i),r>-1){const o=a[0];typeof o=="string"?a[0]=o.slice(r):a.shift()}s>0&&a.push(e[i].slice(0,s))}return a}function Zw(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let a;if(typeof s=="string")a=s;else switch(s){case-5:{a="\r";break}case-4:{a=`
4
4
  `;break}case-3:{a=`\r
5
5
  `;break}case-2:{a=t?" ":" ";break}case-1:{if(!t&&i)continue;a=" ";break}default:a=String.fromCharCode(s)}i=s===-2,r.push(a)}return r.join("")}function Bw(e){const r={constructs:Pf([$w,...(e||{}).extensions||[]]),content:i(rv),defined:[],document:i(sv),flow:i(Sw),lazy:{},string:i(Cw),text:i(Nw)};return r;function i(s){return a;function a(o){return Fw(r,s,o)}}}function Vw(e){for(;!$f(e););return e}const Rl=/[\0\t\n\r]/g;function Uw(){let e=1,t="",n=!0,r;return i;function i(s,a,o){const l=[];let c,f,d,p,h;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(a||void 0).decode(s)),d=0,t="",n&&(s.charCodeAt(0)===65279&&d++,n=void 0);d<s.length;){if(Rl.lastIndex=d,c=Rl.exec(s),p=c&&c.index!==void 0?c.index:s.length,h=s.charCodeAt(p),!c){t=s.slice(d);break}if(h===10&&d===p&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),d<p&&(l.push(s.slice(d,p)),e+=p-d),h){case 0:{l.push(65533),e++;break}case 9:{for(f=Math.ceil(e/4)*4,l.push(-2);e++<f;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}d=p+1}return o&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const Jw=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function Hw(e){return e.replace(Jw,Ww)}function Ww(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Of(n.slice(s?2:1),s?16:10)}return fo(n)||e}const Uf={}.hasOwnProperty;function qw(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),Gw(n)(Vw(Bw(n).document().write(Uw()(e,t,!0))))}function Gw(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(z),autolinkProtocol:K,autolinkEmail:K,atxHeading:s(ke),blockQuote:s(be),characterEscape:K,characterReference:K,codeFenced:s(ne),codeFencedFenceInfo:a,codeFencedFenceMeta:a,codeIndented:s(ne,a),codeText:s(de,a),codeTextData:K,data:K,codeFlowValue:K,definition:s(ue),definitionDestinationString:a,definitionLabelString:a,definitionTitleString:a,emphasis:s(Z),hardBreakEscape:s(me),hardBreakTrailing:s(me),htmlFlow:s(De,a),htmlFlowData:K,htmlText:s(De,a),htmlTextData:K,image:s(j),label:a,link:s(z),listItem:s(re),listItemValue:p,listOrdered:s(M,d),listUnordered:s(M),paragraph:s(ee),reference:y,referenceString:a,resourceDestinationString:a,resourceTitleString:a,setextHeading:s(ke),strong:s(Q),thematicBreak:s(we)},exit:{atxHeading:l(),atxHeadingSequence:E,autolink:l(),autolinkEmail:fe,autolinkProtocol:X,blockQuote:l(),characterEscapeValue:C,characterReferenceMarkerHexadecimal:B,characterReferenceMarkerNumeric:B,characterReferenceValue:ie,characterReference:te,codeFenced:l(S),codeFencedFence:v,codeFencedFenceInfo:h,codeFencedFenceMeta:g,codeFlowValue:C,codeIndented:l(x),codeText:l(L),codeTextData:C,data:C,definition:l(),definitionDestinationString:I,definitionLabelString:_,definitionTitleString:m,emphasis:l(),hardBreakEscape:l(A),hardBreakTrailing:l(A),htmlFlow:l(F),htmlFlowData:C,htmlText:l(R),htmlTextData:C,image:l(V),label:se,labelText:U,lineEnding:T,link:l(P),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:W,resourceDestinationString:k,resourceTitleString:le,resource:q,setextHeading:l(O),setextHeadingLineSequence:N,setextHeadingText:w,strong:l(),thematicBreak:l()}};Jf(t,(e||{}).mdastExtensions||[]);const n={};return r;function r($){let G={type:"root",children:[]};const he={stack:[G],tokenStack:[],config:t,enter:o,exit:c,buffer:a,resume:f,data:n},je=[];let D=-1;for(;++D<$.length;)if($[D][1].type==="listOrdered"||$[D][1].type==="listUnordered")if($[D][0]==="enter")je.push(D);else{const ge=je.pop();D=i($,ge,D)}for(D=-1;++D<$.length;){const ge=t[$[D][0]];Uf.call(ge,$[D][1].type)&&ge[$[D][1].type].call(Object.assign({sliceSerialize:$[D][2].sliceSerialize},he),$[D][1])}if(he.tokenStack.length>0){const ge=he.tokenStack[he.tokenStack.length-1];(ge[1]||Ml).call(he,void 0,ge[0])}for(G.position={start:an($.length>0?$[0][1].start:{line:1,column:1,offset:0}),end:an($.length>0?$[$.length-2][1].end:{line:1,column:1,offset:0})},D=-1;++D<t.transforms.length;)G=t.transforms[D](G)||G;return G}function i($,G,he){let je=G-1,D=-1,ge=!1,Te,Le,nt,et;for(;++je<=he;){const it=$[je];switch(it[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{it[0]==="enter"?D++:D--,et=void 0;break}case"lineEndingBlank":{it[0]==="enter"&&(Te&&!et&&!D&&!nt&&(nt=je),et=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:et=void 0}if(!D&&it[0]==="enter"&&it[1].type==="listItemPrefix"||D===-1&&it[0]==="exit"&&(it[1].type==="listUnordered"||it[1].type==="listOrdered")){if(Te){let rn=je;for(Le=void 0;rn--;){const Kt=$[rn];if(Kt[1].type==="lineEnding"||Kt[1].type==="lineEndingBlank"){if(Kt[0]==="exit")continue;Le&&($[Le][1].type="lineEndingBlank",ge=!0),Kt[1].type="lineEnding",Le=rn}else if(!(Kt[1].type==="linePrefix"||Kt[1].type==="blockQuotePrefix"||Kt[1].type==="blockQuotePrefixWhitespace"||Kt[1].type==="blockQuoteMarker"||Kt[1].type==="listItemIndent"))break}nt&&(!Le||nt<Le)&&(Te._spread=!0),Te.end=Object.assign({},Le?$[Le][1].start:it[1].end),$.splice(Le||je,0,["exit",Te,it[2]]),je++,he++}if(it[1].type==="listItemPrefix"){const rn={type:"listItem",_spread:!1,start:Object.assign({},it[1].start),end:void 0};Te=rn,$.splice(je,0,["enter",rn,it[2]]),je++,he++,nt=void 0,et=!0}}}return $[G][1]._spread=ge,he}function s($,G){return he;function he(je){o.call(this,$(je),je),G&&G.call(this,je)}}function a(){this.stack.push({type:"fragment",children:[]})}function o($,G,he){this.stack[this.stack.length-1].children.push($),this.stack.push($),this.tokenStack.push([G,he||void 0]),$.position={start:an(G.start),end:void 0}}function l($){return G;function G(he){$&&$.call(this,he),c.call(this,he)}}function c($,G){const he=this.stack.pop(),je=this.tokenStack.pop();if(je)je[0].type!==$.type&&(G?G.call(this,$,je[0]):(je[1]||Ml).call(this,$,je[0]));else throw new Error("Cannot close `"+$.type+"` ("+Rr({start:$.start,end:$.end})+"): it’s not open");he.position.end=an($.end)}function f(){return co(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function p($){if(this.data.expectingFirstListItemValue){const G=this.stack[this.stack.length-2];G.start=Number.parseInt(this.sliceSerialize($),10),this.data.expectingFirstListItemValue=void 0}}function h(){const $=this.resume(),G=this.stack[this.stack.length-1];G.lang=$}function g(){const $=this.resume(),G=this.stack[this.stack.length-1];G.meta=$}function v(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function S(){const $=this.resume(),G=this.stack[this.stack.length-1];G.value=$.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function x(){const $=this.resume(),G=this.stack[this.stack.length-1];G.value=$.replace(/(\r?\n|\r)$/g,"")}function _($){const G=this.resume(),he=this.stack[this.stack.length-1];he.label=G,he.identifier=Mt(this.sliceSerialize($)).toLowerCase()}function m(){const $=this.resume(),G=this.stack[this.stack.length-1];G.title=$}function I(){const $=this.resume(),G=this.stack[this.stack.length-1];G.url=$}function E($){const G=this.stack[this.stack.length-1];if(!G.depth){const he=this.sliceSerialize($).length;G.depth=he}}function w(){this.data.setextHeadingSlurpLineEnding=!0}function N($){const G=this.stack[this.stack.length-1];G.depth=this.sliceSerialize($).codePointAt(0)===61?1:2}function O(){this.data.setextHeadingSlurpLineEnding=void 0}function K($){const he=this.stack[this.stack.length-1].children;let je=he[he.length-1];(!je||je.type!=="text")&&(je=pe(),je.position={start:an($.start),end:void 0},he.push(je)),this.stack.push(je)}function C($){const G=this.stack.pop();G.value+=this.sliceSerialize($),G.position.end=an($.end)}function T($){const G=this.stack[this.stack.length-1];if(this.data.atHardBreak){const he=G.children[G.children.length-1];he.position.end=an($.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(G.type)&&(K.call(this,$),C.call(this,$))}function A(){this.data.atHardBreak=!0}function F(){const $=this.resume(),G=this.stack[this.stack.length-1];G.value=$}function R(){const $=this.resume(),G=this.stack[this.stack.length-1];G.value=$}function L(){const $=this.resume(),G=this.stack[this.stack.length-1];G.value=$}function P(){const $=this.stack[this.stack.length-1];if(this.data.inReference){const G=this.data.referenceType||"shortcut";$.type+="Reference",$.referenceType=G,delete $.url,delete $.title}else delete $.identifier,delete $.label;this.data.referenceType=void 0}function V(){const $=this.stack[this.stack.length-1];if(this.data.inReference){const G=this.data.referenceType||"shortcut";$.type+="Reference",$.referenceType=G,delete $.url,delete $.title}else delete $.identifier,delete $.label;this.data.referenceType=void 0}function U($){const G=this.sliceSerialize($),he=this.stack[this.stack.length-2];he.label=Hw(G),he.identifier=Mt(G).toLowerCase()}function se(){const $=this.stack[this.stack.length-1],G=this.resume(),he=this.stack[this.stack.length-1];if(this.data.inReference=!0,he.type==="link"){const je=$.children;he.children=je}else he.alt=G}function k(){const $=this.resume(),G=this.stack[this.stack.length-1];G.url=$}function le(){const $=this.resume(),G=this.stack[this.stack.length-1];G.title=$}function q(){this.data.inReference=void 0}function y(){this.data.referenceType="collapsed"}function W($){const G=this.resume(),he=this.stack[this.stack.length-1];he.label=G,he.identifier=Mt(this.sliceSerialize($)).toLowerCase(),this.data.referenceType="full"}function B($){this.data.characterReferenceType=$.type}function ie($){const G=this.sliceSerialize($),he=this.data.characterReferenceType;let je;he?(je=Of(G,he==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):je=fo(G);const D=this.stack[this.stack.length-1];D.value+=je}function te($){const G=this.stack.pop();G.position.end=an($.end)}function X($){C.call(this,$);const G=this.stack[this.stack.length-1];G.url=this.sliceSerialize($)}function fe($){C.call(this,$);const G=this.stack[this.stack.length-1];G.url="mailto:"+this.sliceSerialize($)}function be(){return{type:"blockquote",children:[]}}function ne(){return{type:"code",lang:null,meta:null,value:""}}function de(){return{type:"inlineCode",value:""}}function ue(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function Z(){return{type:"emphasis",children:[]}}function ke(){return{type:"heading",depth:0,children:[]}}function me(){return{type:"break"}}function De(){return{type:"html",value:""}}function j(){return{type:"image",title:null,url:"",alt:null}}function z(){return{type:"link",title:null,url:"",children:[]}}function M($){return{type:"list",ordered:$.type==="listOrdered",start:null,spread:$._spread,children:[]}}function re($){return{type:"listItem",spread:$._spread,checked:null,children:[]}}function ee(){return{type:"paragraph",children:[]}}function Q(){return{type:"strong",children:[]}}function pe(){return{type:"text",value:""}}function we(){return{type:"thematicBreak"}}}function an(e){return{line:e.line,column:e.column,offset:e.offset}}function Jf(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Jf(e,r):Kw(e,r)}}function Kw(e,t){let n;for(n in t)if(Uf.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function Ml(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Rr({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Rr({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Rr({start:t.start,end:t.end})+") is still open")}function Yw(e){const t=this;t.parser=n;function n(r){return qw(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function Xw(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function Qw(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
@@ -96,4 +96,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
96
96
  `;)t++;return!0}return!1}function c(U){if(f(U)){if(Gu(e[t]))for(;t<e.length&&Ku(e[t]);)t++;return a(),!0}return!1}function f(U){o(!0);for(const se of U){const k=t+se.length;if(e.slice(t,k)===se)return t=k,!0}return!1}function d(U){return e[t]===U?(n+=e[t],t++,!0):!1}function p(U){return e[t]===U?(t++,!0):!1}function h(){return p("\\")}function g(){return a(),e[t]==="."&&e[t+1]==="."&&e[t+2]==="."?(t+=3,a(),p(","),!0):!1}function v(){if(e[t]==="{"){n+="{",t++,a(),p(",")&&a();let U=!0;for(;t<e.length&&e[t]!=="}";){let se;if(U?(se=!0,U=!1):(se=d(","),se||(n=Pt(n,",")),a()),g(),!(_()||N(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=jr(n,","):L();break}a();const le=d(":"),q=t>=e.length;le||(ec(e[t])||q?n=Pt(n,":"):P()),s()||(le||q?n+="null":P())}return e[t]==="}"?(n+="}",t++):n=Pt(n,"}"),!0}return!1}function S(){if(e[t]==="["){n+="[",t++,a(),p(",")&&a();let U=!0;for(;t<e.length&&e[t]!=="]";)if(U?U=!1:d(",")||(n=Pt(n,",")),g(),!s()){n=jr(n,",");break}return e[t]==="]"?(n+="]",t++):n=Pt(n,"]"),!0}return!1}function x(){let U=!0,se=!0;for(;se;)U?U=!1:d(",")||(n=Pt(n,",")),se=s();se||(n=jr(n,",")),n=`[
97
97
  ${n}
98
98
  ]`}function _(){let U=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1,se=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1,k=e[t]==="\\";if(k&&(t++,k=!0),Ai(e[t])){const le=tc(e[t])?tc:nc(e[t])?nc:La(e[t])?La:am,q=t,y=n.length;let W='"';for(t++;;){if(t>=e.length){const B=K(t-1);return!U&&ji(e.charAt(B))?(t=q,n=n.substring(0,y),_(!0)):(W=Pt(W,'"'),n+=W,!0)}if(t===se)return W=Pt(W,'"'),n+=W,!0;if(le(e[t])){const B=t,ie=W.length;if(W+='"',t++,n+=W,a(!1),U||t>=e.length||ji(e[t])||Ai(e[t])||Sn(e[t]))return m(),!0;const te=K(B-1),X=e.charAt(te);if(X===",")return t=q,n=n.substring(0,y),_(!1,te);if(ji(X))return t=q,n=n.substring(0,y),_(!0);n=n.substring(0,y),t=B+1,W=`${W.substring(0,ie)}\\${W.substring(ie)}`}else if(U&&Qu(e[t])){if(e[t-1]===":"&&Yu.test(e.substring(q+1,t+2)))for(;t<e.length&&Xu.test(e[t]);)W+=e[t],t++;return W=Pt(W,'"'),n+=W,m(),!0}else if(e[t]==="\\"){const B=e.charAt(t+1);if(DT[B]!==void 0)W+=e.slice(t,t+2),t+=2;else if(B==="u"){let te=2;for(;te<6&&CT(e[t+te]);)te++;te===6?(W+=e.slice(t,t+6),t+=6):t+te>=e.length?t=e.length:V()}else W+=B,t+=2}else{const B=e.charAt(t);B==='"'&&e[t-1]!=="\\"?(W+=`\\${B}`,t++):IT(B)?(W+=OT[B],t++):(NT(B)||A(B),W+=B,t++)}k&&h()}}return!1}function m(){let U=!1;for(a();e[t]==="+";){U=!0,t++,a(),n=jr(n,'"',!0);const se=n.length;_()?n=AT(n,se,1):n=Pt(n,'"')}return U}function I(){const U=t;if(e[t]==="-"){if(t++,C())return T(U),!0;if(!Sn(e[t]))return t=U,!1}for(;Sn(e[t]);)t++;if(e[t]==="."){if(t++,C())return T(U),!0;if(!Sn(e[t]))return t=U,!1;for(;Sn(e[t]);)t++}if(e[t]==="e"||e[t]==="E"){if(t++,(e[t]==="-"||e[t]==="+")&&t++,C())return T(U),!0;if(!Sn(e[t]))return t=U,!1;for(;Sn(e[t]);)t++}if(!C())return t=U,!1;if(t>U){const se=e.slice(U,t),k=/^0\d/.test(se);return n+=k?`"${se}"`:se,!0}return!1}function E(){return w("true","true")||w("false","false")||w("null","null")||w("True","true")||w("False","false")||w("None","null")}function w(U,se){return e.slice(t,t+U.length)===U?(n+=se,t+=U.length,!0):!1}function N(U){const se=t;if(Gu(e[t])){for(;t<e.length&&Ku(e[t]);)t++;let k=t;for(;_n(e,k);)k++;if(e[k]==="(")return t=k+1,s(),e[t]===")"&&(t++,e[t]===";"&&t++),!0}for(;t<e.length&&!Qu(e[t])&&!Ai(e[t])&&(!U||e[t]!==":");)t++;if(e[t-1]===":"&&Yu.test(e.substring(se,t+2)))for(;t<e.length&&Xu.test(e[t]);)t++;if(t>se){for(;_n(e,t-1)&&t>0;)t--;const k=e.slice(se,t);return n+=k==="undefined"?"null":JSON.stringify(k),e[t]==='"'&&t++,!0}}function O(){if(e[t]==="/"){const U=t;for(t++;t<e.length&&(e[t]!=="/"||e[t-1]==="\\");)t++;return t++,n+=JSON.stringify(e.substring(U,t)),!0}}function K(U){let se=U;for(;se>0&&_n(e,se);)se--;return se}function C(){return t>=e.length||ji(e[t])||_n(e,t)}function T(U){n+=`${e.slice(U,t)}0`}function A(U){throw new Un(`Invalid character ${JSON.stringify(U)}`,t)}function F(){throw new Un(`Unexpected character ${JSON.stringify(e[t])}`,t)}function R(){throw new Un("Unexpected end of json string",e.length)}function L(){throw new Un("Object key expected",t)}function P(){throw new Un("Colon expected",t)}function V(){const U=e.slice(t,t+6);throw new Un(`Invalid unicode character "${U}"`,t)}}function RT(e,t){return e[t]==="*"&&e[t+1]==="/"}function MT({json:e,context:t,scope:n}){const[r,i]=b.useState(!1),[s,a]=b.useState(null),o=b.useMemo(()=>{try{return JSON.parse(e),e}catch{}try{return rc(e)}catch{}const x=`{${e}}`;try{return JSON.parse(x),x}catch{}try{return rc(x)}catch{return null}},[e]),l=b.useMemo(()=>Qh(o||e),[o,e]),c=Oe(x=>x.activeTab),f=Oe(x=>x.documents),d=Oe(x=>(x.acceptedApplyIds||[]).includes(l)),p=Oe(x=>x.setPendingDiff),h=Oe(x=>x.createDocument),g=Oe(x=>x.openDocument),v=b.useCallback(()=>{if(o){a(null);try{if(c){const x=f.find(w=>w.name===c),_=(x==null?void 0:x.text)||"";if(n==="templates")try{const w=JSON.parse(_),N=JSON.parse(o);if(Array.isArray(N.templates)){w.props||(w.props={}),w.props.templates=Xh(w.props.templates||[],N.templates);const O=JSON.stringify(w,null,2);p(c,_,O,l);return}}catch{}const m=t==null?void 0:t[0],{original:I,modified:E}=em(_,o,m);p(c,I,E,l)}else{const x=`ai-generated-${Date.now()}`;h(x,o),g(x)}}catch(x){a(x instanceof Error?x.message:"Merge failed")}}},[o,c,f,p,h,g,t,n,l]),S=b.useCallback(async()=>{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)},[e]);return u.jsxs("div",{className:"flex flex-col gap-1 px-3 py-2 border-t",children:[u.jsxs("div",{className:"flex gap-1.5",children:[u.jsx(Ee,{variant:"secondary",size:"sm",onClick:v,disabled:d||!o,children:d?"Applied":o?"Apply to Editor":"Invalid JSON"}),u.jsx(Ee,{variant:"ghost",size:"sm",onClick:S,children:r?u.jsx(pn,{className:"h-3.5 w-3.5"}):u.jsx(os,{className:"h-3.5 w-3.5"})})]}),s&&u.jsx("p",{className:"text-xs text-destructive m-0",children:s})]})}function $T({threads:e,activeThread:t,disabled:n,onSwitch:r,onCreate:i,onDelete:s,onRename:a}){const[o,l]=b.useState(null),[c,f]=b.useState(""),[d,p]=b.useState(null),h=b.useRef(null),g=(t==null?void 0:t.title)||"New Chat",v=g.length>24?g.slice(0,24)+"...":g;b.useEffect(()=>{o&&requestAnimationFrame(()=>{var N;return(N=h.current)==null?void 0:N.focus()})},[o]);const S=b.useCallback((N,O)=>{O.stopPropagation(),O.preventDefault(),l(N.id),f(N.title),p(null)},[]),x=b.useCallback(()=>{o&&c.trim()&&a(o,c.trim()),l(null),f("")},[o,c,a]),_=b.useCallback(()=>{l(null),f("")},[]),m=b.useCallback(N=>{N.stopPropagation(),N.key==="Enter"?(N.preventDefault(),x()):N.key==="Escape"&&(N.preventDefault(),_())},[x,_]),I=b.useCallback((N,O)=>{O.stopPropagation(),O.preventDefault(),p(N),l(null)},[]),E=b.useCallback(N=>{N.stopPropagation(),N.preventDefault(),d&&(s(d),p(null))},[d,s]),w=b.useCallback(N=>{N.stopPropagation(),N.preventDefault(),p(null)},[]);return u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsxs(ds,{onOpenChange:N=>{N||(l(null),p(null))},children:[u.jsx(fs,{asChild:!0,disabled:n,children:u.jsxs("button",{className:"flex items-center gap-1 text-sm font-semibold tracking-tight hover:text-foreground/80 transition-colors max-w-[180px] cursor-pointer",children:[u.jsx("div",{className:"h-2 w-2 rounded-full bg-primary/70 shrink-0"}),u.jsx("span",{className:"truncate",children:v}),u.jsx(ti,{className:"h-3 w-3 shrink-0 opacity-60"})]})}),u.jsxs(ai,{align:"start",className:"w-64",children:[e.map(N=>{const O=o===N.id;return d===N.id?u.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-sm",children:[u.jsx("span",{className:"text-destructive text-xs flex-1 truncate",children:"Delete this thread?"}),u.jsx("button",{className:"shrink-0 text-destructive hover:text-destructive/80 transition-colors cursor-pointer",onClick:E,children:u.jsx(pn,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:w,children:u.jsx(fn,{className:"h-3.5 w-3.5"})})]},N.id):O?u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1",onClick:C=>C.stopPropagation(),onPointerDown:C=>C.stopPropagation(),children:[u.jsx("input",{ref:h,type:"text",value:c,onChange:C=>f(C.target.value),onKeyDown:m,onBlur:x,className:"flex-1 min-w-0 text-sm rounded-sm border border-border bg-background px-1.5 py-0.5 outline-none focus:ring-1 focus:ring-primary/40"}),u.jsx("button",{className:"shrink-0 text-primary hover:text-primary/80 transition-colors cursor-pointer",onMouseDown:C=>{C.preventDefault(),x()},children:u.jsx(pn,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onMouseDown:C=>{C.preventDefault(),_()},children:u.jsx(fn,{className:"h-3.5 w-3.5"})})]},N.id):u.jsxs(Bt,{onSelect:()=>r(N.id),className:`group ${N.id===(t==null?void 0:t.id)?"bg-accent":""}`,children:[u.jsx("span",{className:"truncate flex-1",children:N.title.length>30?N.title.slice(0,30)+"...":N.title}),u.jsxs("div",{className:"ml-auto shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[u.jsx("button",{className:"text-muted-foreground hover:text-foreground transition-colors p-0.5 cursor-pointer",onClick:C=>S(N,C),children:u.jsx(fg,{className:"h-3 w-3"})}),e.length>1&&u.jsx("button",{className:"text-muted-foreground hover:text-destructive transition-colors p-0.5 cursor-pointer",onClick:C=>I(N.id,C),children:u.jsx(Va,{className:"h-3 w-3"})})]})]},N.id)}),u.jsx(sr,{}),u.jsxs(Bt,{onSelect:N=>{N.preventDefault();const O=i();O&&(l(O),f(Ga()),p(null))},children:[u.jsx(Xt,{className:"h-3.5 w-3.5 mr-1.5"}),"New Chat"]})]})]}),u.jsx(Ee,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",onClick:()=>i(),disabled:n,title:"New chat thread",children:u.jsx(Xt,{className:"h-3.5 w-3.5"})})]})}const om=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),FT=Array.from(om).join(","),LT=20*1024*1024,ic=10;function ZT(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t({type:"file",mediaType:e.type,filename:e.name,url:r.result}),r.onerror=n,r.readAsDataURL(e)})}function sc(e){return Array.from(e).filter(t=>om.has(t.type)&&t.size<=LT)}function lm(e){return e.startsWith("image/")}function ac(){var G,he,je;const e=Pe(D=>D.contextAttachments),t=Pe(D=>D.addContext),n=Pe(D=>D.removeContext),r=Pe(D=>D.scope),i=Pe(D=>D.setScope),s=Pe(D=>D.model),a=Pe(D=>D.setModel),o=Pe(D=>D.openChat),l=Pe(D=>D.closeChat),c=Pe(D=>D.threads),f=Pe(D=>D.activeThreadId),d=Pe(D=>D.createThread),p=Pe(D=>D.deleteThread),h=Pe(D=>D.switchThread),g=Pe(D=>D.updateThreadMessages),v=Pe(D=>D.updateThreadTitle),S=Pe(D=>D.deleteThreadsForDocument),x=Oe(D=>D.activeTab),_=Oe(D=>D.documents),{messages:m,sendMessage:I,status:E,error:w,setMessages:N,stop:O,getMessageContext:K,getMessageScope:C}=hT(),[T,A]=b.useState(""),[F,R]=b.useState([]),[L,P]=b.useState(!1),[V,U]=b.useState(!1),se=b.useRef(null),k=b.useRef(null),le=b.useRef(null),q=b.useCallback(async D=>{const ge=sc(D);if(ge.length===0)return;const Te=await Promise.all(ge.map(ZT));R(Le=>{const nt=[...Le,...Te];return nt.length>ic?nt.slice(0,ic):nt})},[]),y=b.useCallback(D=>{R(ge=>ge.filter((Te,Le)=>Le!==D))},[]),W=b.useCallback(D=>{var Te;const ge=(Te=D.clipboardData)==null?void 0:Te.files;if(ge&&ge.length>0){const Le=sc(ge);Le.length>0&&(D.preventDefault(),q(Le))}},[q]),B=b.useCallback(D=>{var Te;D.preventDefault(),U(!1);const ge=(Te=D.dataTransfer)==null?void 0:Te.files;ge&&ge.length>0&&q(Array.from(ge))},[q]),ie=b.useCallback(D=>{D.preventDefault(),U(!0)},[]),te=b.useCallback(()=>U(!1),[]),X=x?f[x]:void 0,fe=X?c[X]:void 0,be=b.useMemo(()=>x?Object.values(c).filter(D=>D.documentName===x).sort((D,ge)=>ge.updatedAt-D.updatedAt):[],[c,x]);b.useEffect(()=>{x&&be.length===0&&d(x)},[x,be.length,d]);const ne=b.useRef(c);ne.current=c,b.useEffect(()=>{const D=new Set(_.map(Te=>Te.name)),ge=new Set;for(const Te of Object.values(ne.current))!D.has(Te.documentName)&&Te.documentName!=="__migrated__"&&ge.add(Te.documentName);for(const Te of ge)S(Te)},[_,S]);const de=b.useRef(null);b.useEffect(()=>{de.current!==X&&(de.current=X,N((fe==null?void 0:fe.messages)??[]))},[X,fe,N]),b.useEffect(()=>{var D;(D=se.current)==null||D.scrollIntoView({behavior:"smooth"})},[m,E]),b.useEffect(()=>{const D=ge=>{var nt;const{documentName:Te,selection:Le}=ge.detail;t({...Le,documentName:Te}),o(),(nt=k.current)==null||nt.focus()};return window.addEventListener("monaco-selection-to-ai",D),()=>window.removeEventListener("monaco-selection-to-ai",D)},[t,o]);const ue=E==="streaming",Z=E==="submitted"||ue,ke=b.useCallback(D=>{D.preventDefault(),!(!T.trim()&&F.length===0||Z)&&(I(T,F.length>0?F:void 0),A(""),R([]))},[T,F,Z,I]),me=b.useCallback(D=>{D.key==="Enter"&&!D.shiftKey&&(D.preventDefault(),ke(D))},[ke]),De=b.useCallback(()=>{m.length!==0&&P(!0)},[m.length]),j=b.useCallback(()=>{P(!1),N([]),X&&(g(X,[]),v(X,Ga()))},[N,X,g,v]),[z,M]=b.useState(null),re=b.useCallback(D=>{M(D)},[]),ee=b.useCallback(()=>{var nt,et;if(!z)return;const D=m.findIndex(it=>it.id===z);if(D===-1){M(null);return}const ge=m[D],Te=new Set([D]);ge.role==="user"&&((nt=m[D+1])==null?void 0:nt.role)==="assistant"?Te.add(D+1):ge.role==="assistant"&&D>0&&((et=m[D-1])==null?void 0:et.role)==="user"&&Te.add(D-1);const Le=m.filter((it,rn)=>!Te.has(rn));N(Le),X&&g(X,Le),M(null)},[z,m,N,X,g]),Q=b.useCallback(D=>{if(!Z){if(be.length<=1){De();return}p(D)}},[Z,be.length,De,p]),pe=b.useCallback(()=>{if(!(!x||Z))return d(x)},[x,Z,d]),we=b.useCallback(D=>{Z||D===X||h(D)},[Z,X,h]),$=b.useCallback((D,ge)=>{v(D,ge)},[v]);return u.jsxs("div",{className:"flex flex-col h-full border-l bg-surface-chat",children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-surface-chat",children:[u.jsx($T,{threads:be,activeThread:fe,disabled:Z,onSwitch:we,onCreate:pe,onDelete:Q,onRename:$}),u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(Ee,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:De,disabled:Z||m.length===0,children:"Clear"}),u.jsx(Ee,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:l,title:"Close chat",children:u.jsx(fn,{className:"h-3.5 w-3.5"})})]})]}),u.jsx(Zr,{className:"flex-1 min-h-0 [&_[data-radix-scroll-area-viewport]>div]:!block",children:u.jsxs("div",{className:"p-3 space-y-4 min-w-0",children:[m.length===0&&u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4",children:[u.jsx("div",{className:"rounded-xl bg-primary/10 p-3 mb-4",children:u.jsx(Do,{className:"h-5 w-5 text-primary"})}),u.jsx("p",{className:"text-sm font-medium text-foreground/80 mb-1",children:"JSON Assistant"}),u.jsx("p",{className:"text-xs text-muted-foreground text-center max-w-[200px] mb-4",children:"Generate, edit, and refine your JSON document definitions with AI."}),u.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-muted/50 px-2.5 py-1.5",children:[u.jsx(Br,{shortcut:"mod+k"}),u.jsx("span",{className:"text-xs text-muted-foreground",children:"to send a selection"})]})]}),m.map((D,ge)=>{let Te;if(D.role==="user"){const et=K(D.id);et&&et.length>0&&(Te=et)}else if(D.role==="assistant"){for(let et=ge-1;et>=0;et--)if(m[et].role==="user"){Te=K(m[et].id);break}}const Le=ue&&ge===m.length-1&&D.role==="assistant",nt=D.role==="user"?C(D.id):void 0;return u.jsx(BT,{msg:D,isStreaming:Le,context:Te,scope:nt,onDelete:Z?void 0:re},D.id)}),Z&&((G=m[m.length-1])==null?void 0:G.role)!=="assistant"&&u.jsx("div",{className:"flex justify-start",children:u.jsx("div",{className:"rounded-lg px-3 py-2 bg-muted/60 border border-border/40",children:u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(la,{className:"h-3.5 w-3.5 animate-spin text-primary"}),u.jsx("span",{children:"Thinking..."})]})})}),w&&!Z&&u.jsx("div",{className:"flex justify-start",children:u.jsx("div",{className:"rounded-lg px-3 py-2 bg-destructive/10 border border-destructive/30 text-destructive text-sm max-w-[90%]",children:w.message||"Something went wrong"})}),u.jsx("div",{ref:se})]})}),u.jsxs("div",{className:`border-t border-border/60 p-2.5 space-y-2 bg-surface-chat transition-colors ${V?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:B,onDragOver:ie,onDragLeave:te,children:[e.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((D,ge)=>u.jsx(nm,{context:D,onRemove:()=>n(ge)},ge))}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx(JT,{model:s,setModel:a}),yt==="pptx"&&x&&u.jsx(WT,{scope:r,setScope:i,docSize:((je=(he=_.find(D=>D.name===x))==null?void 0:he.text)==null?void 0:je.length)??0})]}),F.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:F.map((D,ge)=>u.jsxs("div",{className:"relative group",children:[lm(D.mediaType)?u.jsx("img",{src:D.url,alt:D.filename||"attachment",className:"h-14 w-14 rounded-md object-cover border border-border/60"}):u.jsxs("div",{className:"h-14 px-2.5 flex items-center gap-1.5 rounded-md border border-border/60 bg-muted/60 max-w-[140px]",children:[u.jsx(ua,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsx("span",{className:"text-xs truncate text-muted-foreground",children:D.filename||"file"})]}),u.jsx("button",{type:"button",onClick:()=>y(ge),className:"absolute -top-1.5 -right-1.5 rounded-full bg-destructive text-destructive-foreground p-0.5 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:u.jsx(fn,{className:"h-3 w-3"})})]},ge))}),u.jsxs("form",{onSubmit:ke,className:"flex items-end gap-2",children:[u.jsx("input",{ref:le,type:"file",accept:FT,multiple:!0,className:"hidden",onChange:D=>{D.target.files&&q(Array.from(D.target.files)),D.target.value=""}}),u.jsx(Ee,{type:"button",variant:"ghost",size:"icon",className:"shrink-0 h-9 w-9 rounded-lg text-muted-foreground hover:text-foreground",onClick:()=>{var D;return(D=le.current)==null?void 0:D.click()},title:"Attach file",children:u.jsx(ua,{className:"h-4 w-4"})}),u.jsx("textarea",{ref:k,value:T,onChange:D=>{A(D.target.value);const ge=D.target;ge.style.height="auto",ge.style.height=`${Math.min(ge.scrollHeight,128)}px`},onKeyDown:me,onPaste:W,placeholder:e.length>0?"Describe how to edit the selection...":r==="slides"?"Add, edit, or remove slides...":r==="templates"?"Edit template layouts and placeholders...":"Ask AI to generate or edit JSON...",className:"flex-1 min-h-[36px] max-h-32 resize-none overflow-y-auto rounded-lg border border-border/60 bg-background px-3 py-1.5 text-sm placeholder:text-muted-foreground placeholder:whitespace-nowrap placeholder:overflow-hidden placeholder:text-ellipsis focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30 focus-visible:border-primary/50 transition-shadow",rows:1}),Z?u.jsx(Ee,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:O,title:"Stop generating",children:u.jsx(pg,{className:"h-4 w-4"})}):u.jsx(Ee,{type:"submit",size:"icon",disabled:!T.trim()&&F.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:u.jsx(Do,{className:"h-4 w-4"})})]})]}),u.jsx(It,{open:L,onOpenChange:P,children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:"Clear thread"}),u.jsx(hn,{children:"This will delete all messages in this thread. This action cannot be undone."})]}),u.jsxs(In,{children:[u.jsx(Ro,{asChild:!0,children:u.jsx(Ee,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Ee,{variant:"destructive",size:"sm",onClick:j,children:"Clear"})]})]})}),u.jsx(It,{open:z!==null,onOpenChange:D=>{D||M(null)},children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ht,{children:[u.jsx(Wt,{children:"Delete message"}),u.jsx(hn,{children:"This will delete the message and its paired response. This action cannot be undone."})]}),u.jsxs(In,{children:[u.jsx(Ro,{asChild:!0,children:u.jsx(Ee,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Ee,{variant:"destructive",size:"sm",onClick:ee,children:"Delete"})]})]})})]})}const BT=b.memo(function({msg:t,isStreaming:n,context:r,scope:i,onDelete:s}){var l,c;const a=((l=t.parts)==null?void 0:l.filter(f=>f.type==="text").map(f=>f.text).join(""))||"",o=((c=t.parts)==null?void 0:c.filter(f=>f.type==="file"))||[];return u.jsx("div",{className:`group/msg flex ${t.role==="user"?"justify-end":"justify-start"}`,children:u.jsxs("div",{className:`rounded-lg px-3 py-2 max-w-[90%] overflow-hidden min-w-0 ${t.role==="user"?"bg-primary text-primary-foreground":"bg-muted/60 border border-border/40"}`,children:[t.role==="user"?u.jsxs("div",{children:[o.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:o.map((f,d)=>lm(f.mediaType)?u.jsx("img",{src:f.url,alt:f.filename||"image",className:"h-20 max-w-[160px] rounded-sm object-cover"},d):u.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm bg-primary-foreground/20 px-2 py-1",children:[u.jsx(ua,{className:"h-3 w-3 shrink-0"}),u.jsx("span",{className:"text-xs truncate max-w-[120px]",children:f.filename||"file"})]},d))}),r&&r.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:r.map((f,d)=>u.jsx(nm,{context:f,variant:"sent"},d))}),a&&u.jsx("div",{className:"whitespace-pre-wrap text-sm break-words",children:a}),i&&i!=="global"&&u.jsx("span",{className:"text-[10px] text-primary-foreground/60 mt-0.5 block text-right",children:i})]}):u.jsx(VT,{text:a,isStreaming:n,context:r,scope:i}),s&&!n&&u.jsx("div",{className:"opacity-0 transition-opacity group-hover/msg:opacity-100 focus-within:opacity-100 mt-1",children:u.jsx("button",{type:"button","aria-label":"Delete message",onClick:()=>s(t.id),className:`p-0.5 rounded-sm cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring ${t.role==="user"?"text-primary-foreground/50 hover:text-primary-foreground/80":"text-muted-foreground hover:text-destructive"}`,children:u.jsx(Va,{className:"h-3 w-3"})})})]})})},(e,t)=>e.msg.id===t.msg.id&&e.msg===t.msg&&e.isStreaming===t.isStreaming&&e.scope===t.scope&&e.onDelete===t.onDelete&&e.context===t.context);function VT({text:e,isStreaming:t,context:n,scope:r}){return t?u.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1",children:u.jsx("pre",{className:"whitespace-pre-wrap font-sans text-sm m-0 p-0 bg-transparent border-none",children:e})}):u.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5 [&_h1]:text-base [&_h2]:text-sm [&_h3]:text-sm [&_h1]:my-2 [&_h2]:my-1.5 [&_h3]:my-1",children:u.jsx(gk,{remarkPlugins:[I1],components:{pre:({children:i})=>u.jsx(u.Fragment,{children:i}),code:({className:i,children:s})=>{const a=i==null?void 0:i.startsWith("language-"),o=(i==null?void 0:i.replace("language-",""))||"",l=String(s).replace(/\n$/,"");if(!a)return u.jsx("code",{className:"rounded-sm bg-muted px-1 py-0.5 text-xs font-mono",children:s});const c=o==="json"||o==="jsonc";return u.jsxs("div",{className:"my-2 rounded-lg border bg-card",children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-muted/60 border-b text-xs text-muted-foreground",children:[u.jsx("span",{className:"font-mono",children:o||"code"}),!c&&u.jsx(qT,{text:l})]}),u.jsx("pre",{className:"p-3 text-xs font-mono overflow-x-auto max-h-80 overflow-y-auto m-0",children:u.jsx("code",{children:l})}),c&&u.jsx(MT,{json:l,context:n,scope:r})]})}},children:e})})}const UT=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function JT({model:e,setModel:t}){return u.jsxs(Fr,{value:e,onValueChange:n=>t(n),children:[u.jsx(rr,{className:"h-6 w-auto gap-1 border-none bg-muted/40 px-2 py-0 text-[10px] shadow-none focus:ring-0",children:u.jsx(Lr,{})}),u.jsx(ir,{children:UT.map(n=>u.jsx(Tn,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const oc={global:"AI sees and edits the entire document",slides:"AI sees and edits only slides — templates stay unchanged",templates:"AI sees and edits only template layouts — slides stay unchanged"},HT=1e5;function WT({scope:e,setScope:t,docSize:n}){return u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Scope"}),u.jsx("div",{className:"flex items-center bg-muted/40 rounded-md p-0.5 gap-px",children:Object.keys(oc).map(r=>u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("button",{type:"button",onClick:()=>t(r),className:`px-2 py-0.5 rounded-sm text-[10px] cursor-pointer transition-colors ${e===r?"bg-background text-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:r})}),u.jsx(Ke,{side:"top",className:"text-xs max-w-[200px]",children:oc[r]})]},r))})]}),e==="global"&&n>HT&&u.jsxs("div",{className:"text-[10px] text-warning flex items-center gap-1",children:[u.jsx(Xc,{className:"h-3 w-3 shrink-0"}),u.jsxs("span",{children:["Large doc — switch to"," ",u.jsx("button",{type:"button",onClick:()=>t("slides"),className:"underline cursor-pointer hover:text-warning/80",children:"slides"})," ","or"," ",u.jsx("button",{type:"button",onClick:()=>t("templates"),className:"underline cursor-pointer hover:text-warning/80",children:"templates"})]})]})]})}function qT({text:e}){const[t,n]=b.useState(!1),r=b.useCallback(async()=>{await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},[e]);return u.jsx("button",{onClick:r,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:t?"Copied!":"Copy"})}function GT({discoveryData:e}){const t=$d(),n=_x(),r=Pe(C=>C.chatOpen),i=Pe(C=>C.toggleChat),[s,a]=b.useState(()=>{try{const C=localStorage.getItem("dev-env.sidebar-open");return n?!1:C?C==="true":!0}catch{return!n}}),[o,l]=b.useState(()=>{try{const C=localStorage.getItem("dev-env.preview-open");return C?C==="true":!0}catch{return!0}}),[c,f]=b.useState("editor"),[d,p]=b.useState(!1),h=150,[g,v]=b.useState(!s),[S,x]=b.useState(!1);b.useEffect(()=>{try{localStorage.setItem("dev-env.sidebar-open",String(s))}catch{}},[s]),b.useEffect(()=>{try{localStorage.setItem("dev-env.preview-open",String(o))}catch{}},[o]);const _=b.useRef(n);b.useEffect(()=>{n&&!_.current&&s&&(x(!0),a(!1),setTimeout(()=>{v(!0),x(!1)},h)),!n&&_.current&&!s&&(x(!0),a(!0),setTimeout(()=>{v(!1),x(!1)},h)),_.current=n},[n,s]);const m=b.useCallback(()=>{if(t){p(C=>!C);return}x(!0),a(C=>!C),setTimeout(()=>{v(C=>!C),x(!1)},h)},[t]),I=b.useCallback(()=>l(C=>!C),[]),E=b.useRef(i),w=b.useRef(m),N=b.useRef(I);b.useEffect(()=>{E.current=i}),b.useEffect(()=>{w.current=m}),b.useEffect(()=>{N.current=I}),b.useEffect(()=>{const C=T=>{(T.metaKey||T.ctrlKey)&&(T.code==="KeyB"&&!T.shiftKey&&(T.preventDefault(),w.current()),T.code==="KeyJ"&&T.shiftKey&&(T.preventDefault(),T.stopPropagation(),E.current()),T.code==="KeyP"&&T.shiftKey&&(T.preventDefault(),N.current()))};return window.addEventListener("keydown",C,!0),()=>window.removeEventListener("keydown",C,!0)},[]);const O=pT,K=[{key:"editor",icon:Qc,label:"Editor"},{key:"preview",icon:ed,label:"Preview"},{key:"chat",icon:td,label:"Chat"}];return t?u.jsx(O,{children:u.jsxs("div",{className:"flex flex-col h-full w-full overflow-hidden",children:[u.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b bg-sidebar shrink-0",children:[u.jsxs(Dd,{open:d,onOpenChange:p,children:[u.jsx(bx,{asChild:!0,children:u.jsx(Ee,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:u.jsx(Yc,{className:"h-4 w-4"})})}),u.jsx(Ya,{side:"left",className:"p-0 w-72",children:u.jsx(Qo,{discoveryData:e,onToggleSidebar:()=>p(!1),isCollapsed:!1})})]}),u.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:K.map(({key:C,icon:T,label:A})=>u.jsxs(Ee,{variant:c===C?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>f(C),children:[u.jsx(T,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"hidden xs:inline",children:A})]},C))})]}),c!=="chat"&&u.jsx(gl,{previewOpen:o,onTogglePreview:I}),u.jsxs("div",{className:"flex-1 min-h-0",children:[c==="editor"&&u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(el,{})}),c==="preview"&&u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(tl,{})}),c==="chat"&&u.jsx(ac,{})]})]})}):u.jsx(O,{children:u.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[u.jsx("div",{className:H("shrink-0 overflow-hidden border-r bg-sidebar","transition-[width] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]",s?"w-64":"w-12"),children:u.jsx(Qo,{discoveryData:e,onToggleSidebar:m,isCollapsed:g,isAnimating:S})}),u.jsxs("div",{className:"flex-1 min-w-0 flex flex-col h-full",children:[u.jsx(gl,{previewOpen:o,onTogglePreview:I}),u.jsxs(Fy,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[u.jsx(Ms,{defaultSize:o?50:100,minSize:20,id:"editor",order:1,children:u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(el,{})})}),o&&u.jsxs(u.Fragment,{children:[u.jsx(dl,{withHandle:!0}),u.jsx(Ms,{defaultSize:50,minSize:20,id:"preview",order:2,children:u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(tl,{})})})]}),r&&u.jsxs(u.Fragment,{children:[u.jsx(dl,{withHandle:!0}),u.jsx(Ms,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:u.jsx(ac,{})})]})]})]})]})})}function KT(){const[e,t]=b.useState(null),[n,r]=b.useState(!0),[i,s]=b.useState(null),a=b.useCallback(async()=>{r(!0),s(null);try{const o=await fetch("/api/discovery/all");if(!o.ok)throw new Error(`Discovery failed: ${o.statusText}`);const l=await o.json();if(!l.success)throw new Error(l.error||"Discovery failed");t(l.data)}catch(o){console.error("Discovery error:",o),s(o instanceof Error?o.message:"Failed to fetch discovered items"),t({plugins:[],documents:[],themes:[]})}finally{r(!1)}},[]);return b.useEffect(()=>{a()},[a]),{data:e,loading:n,error:i,refetch:a}}function YT(){const[e,t]=b.useState(!1),[n,r]=b.useState(null),[i,s]=b.useState(0);return{loadPlugins:b.useCallback(async()=>{t(!0),r(null);try{const o=await fetch("/api/discovery/load-plugins",{method:"POST"});if(!o.ok)throw new Error(`Failed to load plugins: ${o.statusText}`);const l=await o.json();if(!l.success)throw new Error(l.error||"Failed to load plugins");return s(l.data.loaded),!0}catch(o){return console.error("Plugin loading error:",o),r(o instanceof Error?o.message:"Failed to load plugins"),!1}finally{t(!1)}},[]),loading:e,error:n,loadedCount:i}}function XT(){const{data:e,loading:t,error:n}=KT(),{loadPlugins:r}=YT(),i=Dt(s=>s.applyPluginsWithValidation);return b.useEffect(()=>{e&&e.plugins.length>0&&r().then(s=>{if(s){console.log("Plugins loaded successfully");const a=Dt.getState().selectedPlugins;a.size>0&&(console.log("Auto-applying persisted plugin selections:",Array.from(a)),i())}})},[e,r,i]),t?u.jsx("div",{className:"flex items-center justify-center h-screen",children:u.jsxs("div",{className:"text-center",children:[u.jsx("div",{className:"text-lg font-medium",children:"Discovering project resources..."}),u.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:"Searching for documents, themes, and plugins"})]})}):n?u.jsx("div",{className:"flex items-center justify-center h-screen",children:u.jsxs("div",{className:"text-center",children:[u.jsx("div",{className:"text-lg font-medium text-destructive",children:"Discovery failed"}),u.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:n}),u.jsx("div",{className:"text-xs text-muted-foreground mt-4",children:"The playground will work with limited functionality."})]})}):u.jsx(gg,{children:u.jsx(xg,{children:u.jsx(yg,{children:u.jsx(bg,{children:u.jsx(vg,{children:u.jsx(nx,{children:u.jsx(Ld,{children:u.jsx("section",{className:"flex h-screen w-full flex-col",children:u.jsx("div",{className:"grow overflow-hidden",children:u.jsx(GT,{discoveryData:e})})})})})})})})})})}const lz=Object.freeze(Object.defineProperty({__proto__:null,HomePage:XT},Symbol.toStringTag,{value:"Module"}));export{Jt as B,It as D,lz as H,Hy as P,Dr as S,Hr as T,yf as a,Od as b,St as c,Ht as d,Wt as e,By as u};
99
- //# sourceMappingURL=HomePage-Dm2fRH6p.js.map
99
+ //# sourceMappingURL=HomePage-CcmtpSuV.js.map