rivet-design 0.10.9 → 0.11.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 (91) hide show
  1. package/dist/mcp/agent-variants/SessionStore.d.ts +6 -4
  2. package/dist/mcp/agent-variants/SessionStore.d.ts.map +1 -1
  3. package/dist/mcp/agent-variants/SessionStore.js +314 -123
  4. package/dist/mcp/agent-variants/SessionStore.js.map +1 -1
  5. package/dist/mcp/agent-variants/WorktreeOrchestrator.d.ts +9 -2
  6. package/dist/mcp/agent-variants/WorktreeOrchestrator.d.ts.map +1 -1
  7. package/dist/mcp/agent-variants/WorktreeOrchestrator.js +60 -42
  8. package/dist/mcp/agent-variants/WorktreeOrchestrator.js.map +1 -1
  9. package/dist/mcp/agent-variants/WorktreeOrchestrator.testHelpers.d.ts +1 -1
  10. package/dist/mcp/agent-variants/WorktreeOrchestrator.testHelpers.d.ts.map +1 -1
  11. package/dist/mcp/agent-variants/WorktreeOrchestrator.testHelpers.js +1 -1
  12. package/dist/mcp/agent-variants/WorktreeOrchestrator.testHelpers.js.map +1 -1
  13. package/dist/mcp/agent-variants/contracts.d.ts +7712 -2283
  14. package/dist/mcp/agent-variants/contracts.d.ts.map +1 -1
  15. package/dist/mcp/agent-variants/contracts.js +302 -152
  16. package/dist/mcp/agent-variants/contracts.js.map +1 -1
  17. package/dist/mcp/agent-variants/createZeroToOneTool.d.ts +2 -3
  18. package/dist/mcp/agent-variants/createZeroToOneTool.d.ts.map +1 -1
  19. package/dist/mcp/agent-variants/createZeroToOneTool.js +49 -39
  20. package/dist/mcp/agent-variants/createZeroToOneTool.js.map +1 -1
  21. package/dist/mcp/agent-variants/designCritique.d.ts +7 -3
  22. package/dist/mcp/agent-variants/designCritique.d.ts.map +1 -1
  23. package/dist/mcp/agent-variants/designCritique.js +12 -5
  24. package/dist/mcp/agent-variants/designCritique.js.map +1 -1
  25. package/dist/mcp/agent-variants/index.d.ts +1 -1
  26. package/dist/mcp/agent-variants/index.d.ts.map +1 -1
  27. package/dist/mcp/agent-variants/pinterestSourceContext.d.ts +4 -2
  28. package/dist/mcp/agent-variants/pinterestSourceContext.d.ts.map +1 -1
  29. package/dist/mcp/agent-variants/pinterestSourceContext.js +7 -6
  30. package/dist/mcp/agent-variants/pinterestSourceContext.js.map +1 -1
  31. package/dist/mcp/agent-variants/previewQa.d.ts +6 -4
  32. package/dist/mcp/agent-variants/previewQa.d.ts.map +1 -1
  33. package/dist/mcp/agent-variants/previewQa.js +133 -13
  34. package/dist/mcp/agent-variants/previewQa.js.map +1 -1
  35. package/dist/mcp/agent-variants/sourceContext.d.ts +20 -5
  36. package/dist/mcp/agent-variants/sourceContext.d.ts.map +1 -1
  37. package/dist/mcp/agent-variants/sourceContext.js +99 -115
  38. package/dist/mcp/agent-variants/sourceContext.js.map +1 -1
  39. package/dist/mcp/agent-variants/tools.d.ts +7 -0
  40. package/dist/mcp/agent-variants/tools.d.ts.map +1 -1
  41. package/dist/mcp/agent-variants/tools.js +209 -16
  42. package/dist/mcp/agent-variants/tools.js.map +1 -1
  43. package/dist/mcp/agent-variants/variantContext.d.ts +19 -0
  44. package/dist/mcp/agent-variants/variantContext.d.ts.map +1 -0
  45. package/dist/mcp/agent-variants/variantContext.js +355 -0
  46. package/dist/mcp/agent-variants/variantContext.js.map +1 -0
  47. package/dist/mcp/server.d.ts.map +1 -1
  48. package/dist/mcp/server.js +4 -2
  49. package/dist/mcp/server.js.map +1 -1
  50. package/dist/routes/agentVariants.js +4 -3
  51. package/dist/routes/agentVariants.js.map +1 -1
  52. package/dist/services/BrowserAgentClient.d.ts +54 -0
  53. package/dist/services/BrowserAgentClient.d.ts.map +1 -0
  54. package/dist/services/BrowserAgentClient.js +126 -0
  55. package/dist/services/BrowserAgentClient.js.map +1 -0
  56. package/dist/services/InlineVariantGenerationService.d.ts +2 -0
  57. package/dist/services/InlineVariantGenerationService.d.ts.map +1 -1
  58. package/dist/services/InlineVariantGenerationService.js +70 -3
  59. package/dist/services/InlineVariantGenerationService.js.map +1 -1
  60. package/dist/services/VariantRunService.d.ts +1 -0
  61. package/dist/services/VariantRunService.d.ts.map +1 -1
  62. package/dist/services/VariantRunService.js +1 -0
  63. package/dist/services/VariantRunService.js.map +1 -1
  64. package/dist/services/VariantsRuntime.d.ts.map +1 -1
  65. package/dist/services/VariantsRuntime.js +1 -0
  66. package/dist/services/VariantsRuntime.js.map +1 -1
  67. package/dist/services/WorktreeManager.d.ts +1 -8
  68. package/dist/services/WorktreeManager.d.ts.map +1 -1
  69. package/dist/services/WorktreeManager.js +1 -28
  70. package/dist/services/WorktreeManager.js.map +1 -1
  71. package/dist/utils/skills/describe-motion-protocol.d.ts +2 -3
  72. package/dist/utils/skills/describe-motion-protocol.d.ts.map +1 -1
  73. package/dist/utils/skills/describe-motion-protocol.js +50 -35
  74. package/dist/utils/skills/describe-motion-protocol.js.map +1 -1
  75. package/dist/utils/skills/shared-variants-protocol.d.ts +1 -1
  76. package/dist/utils/skills/shared-variants-protocol.d.ts.map +1 -1
  77. package/dist/utils/skills/shared-variants-protocol.js +16 -13
  78. package/dist/utils/skills/shared-variants-protocol.js.map +1 -1
  79. package/package.json +2 -1
  80. package/src/ui/dist/assets/{main-Cwwhwfjq.js → main-Cw6Pd8ye.js} +56 -56
  81. package/src/ui/dist/assets/main-DkCj7b2K.css +1 -0
  82. package/src/ui/dist/index.html +2 -2
  83. package/dist/mcp/agent-variants/designContextStore.d.ts +0 -160
  84. package/dist/mcp/agent-variants/designContextStore.d.ts.map +0 -1
  85. package/dist/mcp/agent-variants/designContextStore.js +0 -295
  86. package/dist/mcp/agent-variants/designContextStore.js.map +0 -1
  87. package/dist/mcp/agent-variants/inspirationDesignContext.d.ts +0 -440
  88. package/dist/mcp/agent-variants/inspirationDesignContext.d.ts.map +0 -1
  89. package/dist/mcp/agent-variants/inspirationDesignContext.js +0 -2467
  90. package/dist/mcp/agent-variants/inspirationDesignContext.js.map +0 -1
  91. package/src/ui/dist/assets/main-Do6whVIm.css +0 -1
@@ -237,267 +237,267 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
237
237
  .block-interactivity-`.concat(e,` {pointer-events: none;}
238
238
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
239
239
  `)},c0e=0,hu=[];function u0e(e){var t=h.useRef([]),n=h.useRef([0,0]),r=h.useRef(),i=h.useState(c0e++)[0],s=h.useState(NL)[0],o=h.useRef(e);h.useEffect(function(){o.current=e},[e]),h.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var x=Mpe([e.lockRef.current],(e.shards||[]).map(lP),!0).filter(Boolean);return x.forEach(function(C){return C.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),x.forEach(function(C){return C.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var a=h.useCallback(function(x,C){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!o.current.allowPinchZoom;var w=Im(x),E=n.current,A="deltaX"in x?x.deltaX:E[0]-w[0],T="deltaY"in x?x.deltaY:E[1]-w[1],M,I=x.target,P=Math.abs(A)>Math.abs(T)?"h":"v";if("touches"in x&&P==="h"&&I.type==="range")return!1;var S=window.getSelection(),D=S&&S.anchorNode,R=D?D===I||D.contains(I):!1;if(R)return!1;var L=oP(P,I);if(!L)return!0;if(L?M=P:(M=P==="v"?"h":"v",L=oP(P,I)),!L)return!1;if(!r.current&&"changedTouches"in x&&(A||T)&&(r.current=M),!M)return!0;var j=r.current||M;return o0e(j,C,x,j==="h"?A:T)},[]),c=h.useCallback(function(x){var C=x;if(!(!hu.length||hu[hu.length-1]!==s)){var w="deltaY"in C?aP(C):Im(C),E=t.current.filter(function(M){return M.name===C.type&&(M.target===C.target||C.target===M.shadowParent)&&a0e(M.delta,w)})[0];if(E&&E.should){C.cancelable&&C.preventDefault();return}if(!E){var A=(o.current.shards||[]).map(lP).filter(Boolean).filter(function(M){return M.contains(C.target)}),T=A.length>0?a(C,A[0]):!o.current.noIsolation;T&&C.cancelable&&C.preventDefault()}}},[]),u=h.useCallback(function(x,C,w,E){var A={name:x,delta:C,target:w,should:E,shadowParent:d0e(w)};t.current.push(A),setTimeout(function(){t.current=t.current.filter(function(T){return T!==A})},1)},[]),f=h.useCallback(function(x){n.current=Im(x),r.current=void 0},[]),p=h.useCallback(function(x){u(x.type,aP(x),x.target,a(x,e.lockRef.current))},[]),m=h.useCallback(function(x){u(x.type,Im(x),x.target,a(x,e.lockRef.current))},[]);h.useEffect(function(){return hu.push(s),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",c,fu),document.addEventListener("touchmove",c,fu),document.addEventListener("touchstart",f,fu),function(){hu=hu.filter(function(x){return x!==s}),document.removeEventListener("wheel",c,fu),document.removeEventListener("touchmove",c,fu),document.removeEventListener("touchstart",f,fu)}},[]);var g=e.removeScrollBar,b=e.inert;return h.createElement(h.Fragment,null,b?h.createElement(s,{styles:l0e(i)}):null,g?h.createElement(Jpe,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function d0e(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const f0e=Vpe(DL,u0e);var hv=h.forwardRef(function(e,t){return h.createElement(fv,zs({},e,{ref:t,sideCar:f0e}))});hv.classNames=fv.classNames;var pv="Popover",[OL]=xs(pv,[Fd]),Pp=Fd(),[h0e,ol]=OL(pv),VL=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=Pp(t),c=h.useRef(null),[u,f]=h.useState(!1),[p,m]=vs({prop:r,defaultProp:i??!1,onChange:s,caller:pv});return y.jsx(O3,{...a,children:y.jsx(h0e,{scope:t,contentId:Bi(),triggerRef:c,open:p,onOpenChange:m,onOpenToggle:h.useCallback(()=>m(g=>!g),[m]),hasCustomAnchor:u,onCustomAnchorAdd:h.useCallback(()=>f(!0),[]),onCustomAnchorRemove:h.useCallback(()=>f(!1),[]),modal:o,children:n})})};VL.displayName=pv;var HL="PopoverAnchor",BL=h.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=ol(HL,n),s=Pp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return h.useEffect(()=>(o(),()=>a()),[o,a]),y.jsx(dv,{...s,...r,ref:t})});BL.displayName=HL;var zL="PopoverTrigger",UL=h.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=ol(zL,n),s=Pp(n),o=Jt(t,i.triggerRef),a=y.jsx(Et.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":XL(i.open),...r,ref:o,onClick:ft(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:y.jsx(dv,{asChild:!0,...s,children:a})});UL.displayName=zL;var z3="PopoverPortal",[p0e,m0e]=OL(z3,{forceMount:void 0}),ZL=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=ol(z3,t);return y.jsx(p0e,{scope:t,forceMount:n,children:y.jsx(ws,{present:n||s.open,children:y.jsx(Tp,{asChild:!0,container:i,children:r})})})};ZL.displayName=z3;var bd="PopoverContent",WL=h.forwardRef((e,t)=>{const n=m0e(bd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=ol(bd,e.__scopePopover);return y.jsx(ws,{present:r||s.open,children:s.modal?y.jsx(v0e,{...i,ref:t}):y.jsx(y0e,{...i,ref:t})})});WL.displayName=bd;var g0e=vd("PopoverContent.RemoveScroll"),v0e=h.forwardRef((e,t)=>{const n=ol(bd,e.__scopePopover),r=h.useRef(null),i=Jt(t,r),s=h.useRef(!1);return h.useEffect(()=>{const o=r.current;if(o)return B3(o)},[]),y.jsx(hv,{as:g0e,allowPinchZoom:!0,children:y.jsx(GL,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ft(e.onCloseAutoFocus,o=>{var a;o.preventDefault(),s.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:ft(e.onPointerDownOutside,o=>{const a=o.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,u=a.button===2||c;s.current=u},{checkForDefaultPrevented:!1}),onFocusOutside:ft(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),y0e=h.forwardRef((e,t)=>{const n=ol(bd,e.__scopePopover),r=h.useRef(!1),i=h.useRef(!1);return y.jsx(GL,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,a;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,u;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),GL=h.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:u,onInteractOutside:f,...p}=e,m=ol(bd,n),g=Pp(n);return P3(),y.jsx(ov,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:y.jsx(_p,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:u,onDismiss:()=>m.onOpenChange(!1),children:y.jsx(V3,{"data-state":XL(m.open),role:"dialog",id:m.contentId,...g,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),qL="PopoverClose",KL=h.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=ol(qL,n);return y.jsx(Et.button,{type:"button",...r,ref:t,onClick:ft(e.onClick,()=>i.onOpenChange(!1))})});KL.displayName=qL;var b0e="PopoverArrow",YL=h.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Pp(n);return y.jsx(H3,{...i,...r,ref:t})});YL.displayName=b0e;function XL(e){return e?"open":"closed"}var Fo=VL,x0e=BL,al=UL,Oo=ZL,Vo=WL,w0e=KL,k0e=YL;const C0e="data:image/svg+xml,%3csvg%20fill='currentColor'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eClaude%3c/title%3e%3cpath%20d='M4.709%2015.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0%2011.784l.055-.352.48-.321.686.06%201.52.103%202.278.158%201.652.097%202.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686%201.908%201.476%202.491%201.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97%202.97%200%2001-.104-.729L6.283.134%206.696%200l.996.134.42.364.62%201.414%201.002%202.229%201.555%203.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286%201.851-.559%202.903-.364%201.942h.212l.243-.242.985-1.306%201.652-2.064.73-.82.85-.904.547-.431h1.033l.76%201.129-.34%201.166-1.064%201.347-.881%201.142-1.264%201.7-.79%201.36.073.11.188-.02%202.856-.606%201.543-.28%201.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061%201.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093%201.068%202.006%201.81%202.509%202.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649%202.345%203.521.122%201.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674%207.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434%201.967-2.18%202.945-1.726%201.845-.414.164-.717-.37.067-.662.401-.589%202.388-3.036%201.44-1.882.93-1.086-.006-.158h-.055L4.132%2018.56l-1.13.146-.487-.456.061-.746.231-.243%201.908-1.312-.006.006z'%3e%3c/path%3e%3c/svg%3e",E0e=({disabled:e=!1})=>{const[t,n]=Vn(v$),[r,i]=h.useState(!1),s=W_.find(c=>c.id===t),o=(s==null?void 0:s.name)??"Select model",a=c=>{n(c),i(!1)};return y.jsxs(Fo,{open:r,onOpenChange:i,children:[y.jsx(al,{asChild:!0,children:y.jsxs("button",{type:"button",disabled:e,className:`flex items-center gap-1.5 text-[11px] text-content-subtle transition-colors ${e?"cursor-not-allowed opacity-50":"cursor-pointer hover:text-content"}`,children:[y.jsx("img",{src:C0e,alt:"Claude",className:"h-3 w-3 opacity-60 invert"}),o,y.jsx(Ba,{className:"h-3 w-3 opacity-60",weight:"bold"})]})}),y.jsx(Oo,{children:y.jsx(Vo,{className:"z-[60] w-48 rounded-lg border border-divider bg-main p-2 shadow-lg",sideOffset:5,align:"start",children:y.jsx("div",{className:"space-y-1",role:"listbox",children:W_.map(c=>{const u=c.id===t;return y.jsxs("button",{type:"button",role:"option","aria-selected":u,onClick:()=>a(c.id),className:`flex w-full items-center justify-between rounded px-3 py-2 text-left text-xs text-content transition-colors ${u?"bg-main-light":"hover:bg-main-hover"}`,children:[y.jsxs("div",{children:[y.jsx("div",{className:"font-medium",children:c.name}),y.jsx("div",{className:"text-[10px] text-content-subtle",children:c.description})]}),u?y.jsx(za,{size:14,className:"flex-shrink-0",weight:"bold"}):null]},c.id)})})})})]})},S0e=e=>({pill:"bg-white/8",icon:"text-content",label:{comment:"Comment",text:"Text",style:"Style",interface:"Control"}[e]}),_0e=e=>e==="comment"?LI:e==="text"?_G:e==="interface"?bG:a8,t6=({tags:e,onRemoveTag:t,onClearAll:n,canClear:r=!0})=>{const[i,s]=h.useState(!1),[o,a]=h.useState(e.length);return e.length!==o&&(a(e.length),o===0&&e.length>0&&s(!1)),e.length===0?null:y.jsxs("div",{className:"w-full rounded-lg bg-main-input/80 px-3 py-2",children:[y.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y.jsxs("button",{type:"button",onClick:()=>s(c=>!c),className:"inline-flex min-w-0 items-center gap-1.5 text-xs font-medium text-content transition-colors hover:text-content","aria-expanded":i,"aria-controls":"pending-tags-list",children:[y.jsx(fG,{className:`h-3 w-3 shrink-0 transition-transform ${i?"rotate-90":""}`,weight:"bold","aria-hidden":"true"}),y.jsxs("span",{className:"truncate tracking-wide",children:["Pending changes (",e.length,")"]})]}),n?y.jsx("button",{type:"button",onClick:()=>void n(),disabled:!r,className:"rounded px-1 text-[11px] font-medium text-content-subtle transition-colors hover:text-content disabled:cursor-not-allowed disabled:opacity-40",title:r?"Clear all pending changes":"Disabled while processing","aria-label":"Clear all pending changes",children:"Clear all"}):null]}),i?y.jsx("div",{id:"pending-tags-list",className:"mt-2 max-h-36 space-y-1.5 overflow-y-auto",children:e.map(c=>{const u=S0e(c.kind),f=_0e(c.kind);return y.jsxs("div",{className:`text-content ${u.pill} flex w-full items-center gap-2 rounded-md px-2 py-2 text-xs`,title:c.detail,children:[y.jsx(f,{className:`h-3.5 w-3.5 shrink-0 ${u.icon}`,weight:"bold","aria-hidden":"true"}),y.jsx("div",{className:`min-w-0 flex-1 leading-4 ${c.kind==="comment"?"max-h-28 overflow-y-auto whitespace-pre-wrap break-words":"truncate"}`,children:c.detail}),t?y.jsx("button",{type:"button",onClick:()=>void t(c),className:"rounded p-1 text-content-subtle transition-colors hover:bg-main","aria-label":`Remove ${u.label.toLowerCase()} attachment`,title:"Remove",children:y.jsx(Ho,{className:"h-3 w-3",weight:"bold"})}):null]},c.id)})}):null]})};function g1(e,[t,n]){return Math.min(n,Math.max(t,e))}function mv(e){const t=e+"CollectionProvider",[n,r]=xs(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=x=>{const{scope:C,children:w}=x,E=h.useRef(null),A=h.useRef(new Map).current;return y.jsx(i,{scope:C,itemMap:A,collectionRef:E,children:w})};o.displayName=t;const a=e+"CollectionSlot",c=vd(a),u=h.forwardRef((x,C)=>{const{scope:w,children:E}=x,A=s(a,w),T=Jt(C,A.collectionRef);return y.jsx(c,{ref:T,children:E})});u.displayName=a;const f=e+"CollectionItemSlot",p="data-radix-collection-item",m=vd(f),g=h.forwardRef((x,C)=>{const{scope:w,children:E,...A}=x,T=h.useRef(null),M=Jt(C,T),I=s(f,w);return h.useEffect(()=>(I.itemMap.set(T,{ref:T,...A}),()=>void I.itemMap.delete(T))),y.jsx(m,{[p]:"",ref:M,children:E})});g.displayName=f;function b(x){const C=s(e+"CollectionConsumer",x);return h.useCallback(()=>{const E=C.collectionRef.current;if(!E)return[];const A=Array.from(E.querySelectorAll(`[${p}]`));return Array.from(C.itemMap.values()).sort((I,P)=>A.indexOf(I.ref.current)-A.indexOf(P.ref.current))},[C.collectionRef,C.itemMap])}return[{Provider:o,Slot:u,ItemSlot:g},b,r]}var A0e=h.createContext(void 0);function Ip(e){const t=h.useContext(A0e);return e||t||"ltr"}function QL(e){const t=h.useRef({value:e,previous:e});return h.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var JL=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),T0e="VisuallyHidden",ej=h.forwardRef((e,t)=>y.jsx(Et.span,{...e,ref:t,style:{...JL,...e.style}}));ej.displayName=T0e;var P0e=ej,I0e=[" ","Enter","ArrowUp","ArrowDown"],M0e=[" ","Enter"],mc="Select",[gv,vv,R0e]=mv(mc),[Ec]=xs(mc,[R0e,Fd]),yv=Fd(),[$0e,ll]=Ec(mc),[D0e,N0e]=Ec(mc),L0e="SelectProvider";function tj(e){const{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:s,value:o,defaultValue:a,onValueChange:c,dir:u,name:f,autoComplete:p,disabled:m,required:g,form:b,internal_do_not_use_render:x}=e,C=yv(t),[w,E]=h.useState(null),[A,T]=h.useState(null),[M,I]=h.useState(!1),P=Ip(u),[S,D]=vs({prop:r,defaultProp:i??!1,onChange:s,caller:mc}),[R,L]=vs({prop:o,defaultProp:a,onChange:c,caller:mc}),j=h.useRef(null),O=w?!!b||!!w.closest("form"):!0,[H,B]=h.useState(new Set),Z=Bi(),K=Array.from(H).map(V=>V.props.value).join(";"),q=h.useCallback(V=>{B(W=>new Set(W).add(V))},[]),Q=h.useCallback(V=>{B(W=>{const N=new Set(W);return N.delete(V),N})},[]),F={required:g,trigger:w,onTriggerChange:E,valueNode:A,onValueNodeChange:T,valueNodeHasChildren:M,onValueNodeHasChildrenChange:I,contentId:Z,value:R,onValueChange:L,open:S,onOpenChange:D,dir:P,triggerPointerDownPosRef:j,disabled:m,name:f,autoComplete:p,form:b,nativeOptions:H,nativeSelectKey:K,isFormControl:O};return y.jsx(O3,{...C,children:y.jsx($0e,{scope:t,...F,children:y.jsx(gv.Provider,{scope:t,children:y.jsx(D0e,{scope:t,onNativeOptionAdd:q,onNativeOptionRemove:Q,children:Y0e(x)?x(F):n})})})})}tj.displayName=L0e;var bv=e=>{const{__scopeSelect:t,children:n,...r}=e;return y.jsx(tj,{__scopeSelect:t,...r,internal_do_not_use_render:({isFormControl:i})=>y.jsxs(y.Fragment,{children:[n,i?y.jsx(Cj,{__scopeSelect:t}):null]})})};bv.displayName=mc;var nj="SelectTrigger",xv=h.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=yv(n),o=ll(nj,n),a=o.disabled||r,c=Jt(t,o.onTriggerChange),u=vv(n),f=h.useRef("touch"),[p,m,g]=Ej(x=>{const C=u().filter(A=>!A.disabled),w=C.find(A=>A.value===o.value),E=Sj(C,x,w);E!==void 0&&o.onValueChange(E.value)}),b=x=>{a||(o.onOpenChange(!0),g()),x&&(o.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return y.jsx(dv,{asChild:!0,...s,children:y.jsx(Et.button,{type:"button",role:"combobox","aria-controls":o.open?o.contentId:void 0,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":"none",dir:o.dir,"data-state":o.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":q3(o.value)?"":void 0,...i,ref:c,onClick:ft(i.onClick,x=>{x.currentTarget.focus(),f.current!=="mouse"&&b(x)}),onPointerDown:ft(i.onPointerDown,x=>{f.current=x.pointerType;const C=x.target;C.hasPointerCapture(x.pointerId)&&C.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(b(x),x.preventDefault())}),onKeyDown:ft(i.onKeyDown,x=>{const C=p.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&m(x.key),!(C&&x.key===" ")&&I0e.includes(x.key)&&(b(),x.preventDefault())})})})});xv.displayName=nj;var rj="SelectValue",ij=h.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...a}=e,c=ll(rj,n),{onValueNodeHasChildrenChange:u}=c,f=s!==void 0,p=Jt(t,c.onValueNodeChange);hr(()=>{u(f)},[u,f]);const m=q3(c.value);return y.jsx(Et.span,{...a,asChild:m?!1:a.asChild,ref:p,style:{pointerEvents:"none"},children:y.jsx(h.Fragment,{children:m?o:s},m?"placeholder":"value")})});ij.displayName=rj;var j0e="SelectIcon",sj=h.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return y.jsx(Et.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});sj.displayName=j0e;var oj="SelectPortal",[F0e,O0e]=Ec(oj,{forceMount:void 0}),U3=e=>{const{__scopeSelect:t,forceMount:n,...r}=e;return y.jsx(F0e,{scope:e.__scopeSelect,forceMount:n,children:y.jsx(Tp,{asChild:!0,...r})})};U3.displayName=oj;var Qa="SelectContent",Z3=h.forwardRef((e,t)=>{const n=O0e(Qa,e.__scopeSelect),{forceMount:r=n.forceMount,...i}=e,s=ll(Qa,e.__scopeSelect),[o,a]=h.useState();return hr(()=>{a(new DocumentFragment)},[]),y.jsx(ws,{present:r||s.open,children:({present:c})=>c?y.jsx(cj,{...i,ref:t}):y.jsx(aj,{...i,fragment:o})})});Z3.displayName=Qa;var aj=h.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,fragment:i}=e;return i?xc.createPortal(y.jsx(lj,{scope:n,children:y.jsx(gv.Slot,{scope:n,children:y.jsx("div",{ref:t,children:r})})}),i):null});aj.displayName="SelectContentFragment";var is=10,[lj,cl]=Ec(Qa),V0e="SelectContentImpl",H0e=vd("SelectContent.RemoveScroll"),cj=h.forwardRef((e,t)=>{const{__scopeSelect:n}=e,{position:r="item-aligned",onCloseAutoFocus:i,onEscapeKeyDown:s,onPointerDownOutside:o,side:a,sideOffset:c,align:u,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:g,sticky:b,hideWhenDetached:x,avoidCollisions:C,...w}=e,E=ll(Qa,n),[A,T]=h.useState(null),[M,I]=h.useState(null),P=Jt(t,re=>T(re)),[S,D]=h.useState(null),[R,L]=h.useState(null),j=vv(n),[O,H]=h.useState(!1),B=h.useRef(!1);h.useEffect(()=>{if(A)return B3(A)},[A]),P3();const Z=h.useCallback(re=>{const[G,...X]=j().map(we=>we.ref.current),[de]=X.slice(-1),ve=document.activeElement;for(const we of re)if(we===ve||(we==null||we.scrollIntoView({block:"nearest"}),we===G&&M&&(M.scrollTop=0),we===de&&M&&(M.scrollTop=M.scrollHeight),we==null||we.focus(),document.activeElement!==ve))return},[j,M]),K=h.useCallback(()=>Z([S,A]),[Z,S,A]);h.useEffect(()=>{O&&K()},[O,K]);const{onOpenChange:q,triggerPointerDownPosRef:Q}=E;h.useEffect(()=>{if(A){let re={x:0,y:0};const G=de=>{var ve,we;re={x:Math.abs(Math.round(de.pageX)-(((ve=Q.current)==null?void 0:ve.x)??0)),y:Math.abs(Math.round(de.pageY)-(((we=Q.current)==null?void 0:we.y)??0))}},X=de=>{re.x<=10&&re.y<=10?de.preventDefault():de.composedPath().includes(A)||q(!1),document.removeEventListener("pointermove",G),Q.current=null};return Q.current!==null&&(document.addEventListener("pointermove",G),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",G),document.removeEventListener("pointerup",X,{capture:!0})}}},[A,q,Q]),h.useEffect(()=>{const re=()=>q(!1);return window.addEventListener("blur",re),window.addEventListener("resize",re),()=>{window.removeEventListener("blur",re),window.removeEventListener("resize",re)}},[q]);const[F,V]=Ej(re=>{const G=j().filter(ve=>!ve.disabled),X=G.find(ve=>ve.ref.current===document.activeElement),de=Sj(G,re,X);de&&setTimeout(()=>de.ref.current.focus())}),W=h.useCallback((re,G,X)=>{const de=!B.current&&!X;(E.value!==void 0&&E.value===G||de)&&(D(re),de&&(B.current=!0))},[E.value]),N=h.useCallback(()=>A==null?void 0:A.focus(),[A]),z=h.useCallback((re,G,X)=>{const de=!B.current&&!X;(E.value!==void 0&&E.value===G||de)&&L(re)},[E.value]),ee=r==="popper"?n6:uj,te=ee===n6?{side:a,sideOffset:c,align:u,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:g,sticky:b,hideWhenDetached:x,avoidCollisions:C}:{};return y.jsx(lj,{scope:n,content:A,viewport:M,onViewportChange:I,itemRefCallback:W,selectedItem:S,onItemLeave:N,itemTextRefCallback:z,focusSelectedItem:K,selectedItemText:R,position:r,isPositioned:O,searchRef:F,children:y.jsx(hv,{as:H0e,allowPinchZoom:!0,children:y.jsx(ov,{asChild:!0,trapped:E.open,onMountAutoFocus:re=>{re.preventDefault()},onUnmountAutoFocus:ft(i,re=>{var G;(G=E.trigger)==null||G.focus({preventScroll:!0}),re.preventDefault()}),children:y.jsx(_p,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:re=>re.preventDefault(),onDismiss:()=>E.onOpenChange(!1),children:y.jsx(ee,{role:"listbox",id:E.contentId,"data-state":E.open?"open":"closed",dir:E.dir,onContextMenu:re=>re.preventDefault(),...w,...te,onPlaced:()=>H(!0),ref:P,style:{display:"flex",flexDirection:"column",outline:"none",...w.style},onKeyDown:ft(w.onKeyDown,re=>{const G=re.ctrlKey||re.altKey||re.metaKey;if(re.key==="Tab"&&re.preventDefault(),!G&&re.key.length===1&&V(re.key),["ArrowUp","ArrowDown","Home","End"].includes(re.key)){let de=j().filter(ve=>!ve.disabled).map(ve=>ve.ref.current);if(["ArrowUp","End"].includes(re.key)&&(de=de.slice().reverse()),["ArrowUp","ArrowDown"].includes(re.key)){const ve=re.target,we=de.indexOf(ve);de=de.slice(we+1)}setTimeout(()=>Z(de)),re.preventDefault()}})})})})})})});cj.displayName=V0e;var B0e="SelectItemAlignedPosition",uj=h.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=ll(Qa,n),o=cl(Qa,n),[a,c]=h.useState(null),[u,f]=h.useState(null),p=Jt(t,P=>f(P)),m=vv(n),g=h.useRef(!1),b=h.useRef(!0),{viewport:x,selectedItem:C,selectedItemText:w,focusSelectedItem:E}=o,A=h.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&C&&w){const P=s.trigger.getBoundingClientRect(),S=u.getBoundingClientRect(),D=s.valueNode.getBoundingClientRect(),R=w.getBoundingClientRect();if(s.dir!=="rtl"){const ve=R.left-S.left,we=D.left-ve,Fe=P.left-we,Te=P.width+Fe,je=Math.max(Te,S.width),nt=window.innerWidth-is,yt=g1(we,[is,Math.max(is,nt-je)]);a.style.minWidth=Te+"px",a.style.left=yt+"px"}else{const ve=S.right-R.right,we=window.innerWidth-D.right-ve,Fe=window.innerWidth-P.right-we,Te=P.width+Fe,je=Math.max(Te,S.width),nt=window.innerWidth-is,yt=g1(we,[is,Math.max(is,nt-je)]);a.style.minWidth=Te+"px",a.style.right=yt+"px"}const L=m(),j=window.innerHeight-is*2,O=x.scrollHeight,H=window.getComputedStyle(u),B=parseInt(H.borderTopWidth,10),Z=parseInt(H.paddingTop,10),K=parseInt(H.borderBottomWidth,10),q=parseInt(H.paddingBottom,10),Q=B+Z+O+q+K,F=Math.min(C.offsetHeight*5,Q),V=window.getComputedStyle(x),W=parseInt(V.paddingTop,10),N=parseInt(V.paddingBottom,10),z=P.top+P.height/2-is,ee=j-z,te=C.offsetHeight/2,re=C.offsetTop+te,G=B+Z+re,X=Q-G;if(G<=z){const ve=L.length>0&&C===L[L.length-1].ref.current;a.style.bottom="0px";const we=u.clientHeight-x.offsetTop-x.offsetHeight,Fe=Math.max(ee,te+(ve?N:0)+we+K),Te=G+Fe;a.style.height=Te+"px"}else{const ve=L.length>0&&C===L[0].ref.current;a.style.top="0px";const Fe=Math.max(z,B+x.offsetTop+(ve?W:0)+te)+X;a.style.height=Fe+"px",x.scrollTop=G-z+x.offsetTop}a.style.margin=`${is}px 0`,a.style.minHeight=F+"px",a.style.maxHeight=j+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[m,s.trigger,s.valueNode,a,u,x,C,w,s.dir,r]);hr(()=>A(),[A]);const[T,M]=h.useState();hr(()=>{u&&M(window.getComputedStyle(u).zIndex)},[u]);const I=h.useCallback(P=>{P&&b.current===!0&&(A(),E==null||E(),b.current=!1)},[A,E]);return y.jsx(U0e,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:g,onScrollButtonChange:I,children:y.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:T},children:y.jsx(Et.div,{...i,ref:p,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});uj.displayName=B0e;var z0e="SelectPopperPosition",n6=h.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=is,...s}=e,o=yv(n);return y.jsx(V3,{...o,...s,ref:t,align:r,collisionPadding:i,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});n6.displayName=z0e;var[U0e,W3]=Ec(Qa,{}),r6="SelectViewport",G3=h.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=cl(r6,n),o=W3(r6,n),a=Jt(t,s.onViewportChange),c=h.useRef(0);return y.jsxs(y.Fragment,{children:[y.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),y.jsx(gv.Slot,{scope:n,children:y.jsx(Et.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:ft(i.onScroll,u=>{const f=u.currentTarget,{contentWrapper:p,shouldExpandOnScrollRef:m}=o;if(m!=null&&m.current&&p){const g=Math.abs(c.current-f.scrollTop);if(g>0){const b=window.innerHeight-is*2,x=parseFloat(p.style.minHeight),C=parseFloat(p.style.height),w=Math.max(x,C);if(w<b){const E=w+g,A=Math.min(b,E),T=E-A;p.style.height=A+"px",p.style.bottom==="0px"&&(f.scrollTop=T>0?T:0,p.style.justifyContent="flex-end")}}}c.current=f.scrollTop})})})]})});G3.displayName=r6;var dj="SelectGroup",[Z0e,W0e]=Ec(dj),fj=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Bi();return y.jsx(Z0e,{scope:n,id:i,children:y.jsx(Et.div,{role:"group","aria-labelledby":i,...r,ref:t})})});fj.displayName=dj;var hj="SelectLabel",pj=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=W0e(hj,n);return y.jsx(Et.div,{id:i.id,...r,ref:t})});pj.displayName=hj;var v1="SelectItem",[G0e,mj]=Ec(v1),ja=h.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,a=ll(v1,n),c=cl(v1,n),u=a.value===r,[f,p]=h.useState(s??""),[m,g]=h.useState(!1),b=Jt(t,E=>{var A;return(A=c.itemRefCallback)==null?void 0:A.call(c,E,r,i)}),x=Bi(),C=h.useRef("touch"),w=()=>{i||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return y.jsx(G0e,{scope:n,value:r,disabled:i,textId:x,isSelected:u,onItemTextChange:h.useCallback(E=>{p(A=>A||((E==null?void 0:E.textContent)??"").trim())},[]),children:y.jsx(gv.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:y.jsx(Et.div,{role:"option","aria-labelledby":x,"data-highlighted":m?"":void 0,"aria-selected":u&&m,"data-state":u?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:b,onFocus:ft(o.onFocus,()=>g(!0)),onBlur:ft(o.onBlur,()=>g(!1)),onClick:ft(o.onClick,()=>{C.current!=="mouse"&&w()}),onPointerUp:ft(o.onPointerUp,()=>{C.current==="mouse"&&w()}),onPointerDown:ft(o.onPointerDown,E=>{C.current=E.pointerType}),onPointerMove:ft(o.onPointerMove,E=>{var A;C.current=E.pointerType,i?(A=c.onItemLeave)==null||A.call(c):C.current==="mouse"&&E.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ft(o.onPointerLeave,E=>{var A;E.currentTarget===document.activeElement&&((A=c.onItemLeave)==null||A.call(c))}),onKeyDown:ft(o.onKeyDown,E=>{var T;((T=c.searchRef)==null?void 0:T.current)!==""&&E.key===" "||(M0e.includes(E.key)&&w(),E.key===" "&&E.preventDefault())})})})})});ja.displayName=v1;var lh="SelectItemText",xd=h.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=ll(lh,n),a=cl(lh,n),c=mj(lh,n),u=N0e(lh,n),[f,p]=h.useState(null),m=Jt(t,w=>p(w),c.onItemTextChange,w=>{var E;return(E=a.itemTextRefCallback)==null?void 0:E.call(a,w,c.value,c.disabled)}),g=f==null?void 0:f.textContent,b=h.useMemo(()=>y.jsx("option",{value:c.value,disabled:c.disabled,children:g},c.value),[c.disabled,c.value,g]),{onNativeOptionAdd:x,onNativeOptionRemove:C}=u;return hr(()=>(x(b),()=>C(b)),[x,C,b]),y.jsxs(y.Fragment,{children:[y.jsx(Et.span,{id:c.textId,...s,ref:m}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?xc.createPortal(s.children,o.valueNode):null]})});xd.displayName=lh;var gj="SelectItemIndicator",tp=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return mj(gj,n).isSelected?y.jsx(Et.span,{"aria-hidden":!0,...r,ref:t}):null});tp.displayName=gj;var i6="SelectScrollUpButton",vj=h.forwardRef((e,t)=>{const n=cl(i6,e.__scopeSelect),r=W3(i6,e.__scopeSelect),[i,s]=h.useState(!1),o=Jt(t,r.onScrollButtonChange);return hr(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=c.scrollTop>0;s(u)};const c=n.viewport;return a(),c.addEventListener("scroll",a),()=>c.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),i?y.jsx(bj,{...e,ref:o,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop-c.offsetHeight)}}):null});vj.displayName=i6;var s6="SelectScrollDownButton",yj=h.forwardRef((e,t)=>{const n=cl(s6,e.__scopeSelect),r=W3(s6,e.__scopeSelect),[i,s]=h.useState(!1),o=Jt(t,r.onScrollButtonChange);return hr(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=c.scrollHeight-c.clientHeight,f=Math.ceil(c.scrollTop)<u;s(f)};const c=n.viewport;return a(),c.addEventListener("scroll",a),()=>c.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),i?y.jsx(bj,{...e,ref:o,onAutoScroll:()=>{const{viewport:a,selectedItem:c}=n;a&&c&&(a.scrollTop=a.scrollTop+c.offsetHeight)}}):null});yj.displayName=s6;var bj=h.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=cl("SelectScrollButton",n),o=h.useRef(null),a=vv(n),c=h.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return h.useEffect(()=>()=>c(),[c]),hr(()=>{var f;const u=a().find(p=>p.ref.current===document.activeElement);(f=u==null?void 0:u.ref.current)==null||f.scrollIntoView({block:"nearest"})},[a]),y.jsx(Et.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:ft(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:ft(i.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:ft(i.onPointerLeave,()=>{c()})})}),q0e="SelectSeparator",xj=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return y.jsx(Et.div,{"aria-hidden":!0,...r,ref:t})});xj.displayName=q0e;var wj="SelectArrow",K0e=h.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=yv(n);return cl(wj,n).position==="popper"?y.jsx(H3,{...i,...r,ref:t}):null});K0e.displayName=wj;var kj="SelectBubbleInput",Cj=h.forwardRef(({__scopeSelect:e,...t},n)=>{const r=ll(kj,e),{value:i,onValueChange:s,required:o,disabled:a,name:c,autoComplete:u,form:f}=r,{nativeOptions:p,nativeSelectKey:m}=r,g=h.useRef(null),b=Jt(n,g),x=i??"",C=QL(x);return h.useEffect(()=>{const w=g.current;if(!w)return;const E=window.HTMLSelectElement.prototype,T=Object.getOwnPropertyDescriptor(E,"value").set;if(C!==x&&T){const M=new Event("change",{bubbles:!0});T.call(w,x),w.dispatchEvent(M)}},[C,x]),y.jsxs(Et.select,{"aria-hidden":!0,required:o,tabIndex:-1,name:c,autoComplete:u,disabled:a,form:f,onChange:w=>s(w.target.value),...t,style:{...JL,...t.style},ref:b,defaultValue:x,children:[q3(i)?y.jsx("option",{value:""}):null,Array.from(p)]},m)});Cj.displayName=kj;function Y0e(e){return typeof e=="function"}function q3(e){return e===""||e===void 0}function Ej(e){const t=Ka(e),n=h.useRef(""),r=h.useRef(0),i=h.useCallback(o=>{const a=n.current+o;t(a),(function c(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>c(""),1e3))})(a)},[t]),s=h.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return h.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,s]}function Sj(e,t,n){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=X0e(e,Math.max(s,0));i.length===1&&(o=o.filter(u=>u!==n));const c=o.find(u=>u.textValue.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function X0e(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Ja(...e){return V$(U8(e))}const _j=({header:e,children:t,className:n,viewportClassName:r,showScrollButtons:i=!0,position:s="popper",sideOffset:o=5,align:a="end",onCloseAutoFocus:c,onKeyDown:u,dataCy:f})=>y.jsx(U3,{children:y.jsxs(Z3,{className:Ja("z-50 w-64 overflow-hidden rounded-lg border-[1px] border-divider bg-main shadow-lg",n),"data-cy":f,position:s,sideOffset:o,align:a,onCloseAutoFocus:c,onKeyDown:u,children:[e,i?y.jsx(vj,{className:"flex h-6 cursor-default items-center justify-center bg-main",children:y.jsx(Ba,{className:"rotate-180 text-gray-600",size:14,weight:"bold"})}):null,y.jsx(G3,{className:Ja("max-h-96 scroll-smooth p-1",r),children:t}),i?y.jsx(yj,{className:"flex h-6 cursor-default items-center justify-center bg-main",children:y.jsx(Ba,{className:"text-gray-600",size:14,weight:"bold"})}):null]})}),ug=({property:e,onSelectToken:t,colorPickerElement:n,onColorPickerCancel:r,isOpen:i,onOpenChange:s,children:o,currentValue:a,dataCy:c})=>{const u=ke(Td),p=ke(Qs).designSystemEditor.isEnabled,[m,g]=h.useState({selectedValue:"",searchTerm:"",isOpen:!1,view:"tokens",viewMode:"circles"}),b=h.useRef(null),x=i??m.isOpen,C=L=>{g(j=>({...j,isOpen:L})),s==null||s(L)},w=L=>{var j;return((j=L==null?void 0:L.includes)==null?void 0:j.call(L,"var(--"))??!1},E=L=>{if(!w(L))return L;try{const j=document.createElement("div");j.style.display="none",j.style.color=L,document.body.appendChild(j);const H=window.getComputedStyle(j).color;return document.body.removeChild(j),H||L}catch(j){return console.log("Failed to resolve CSS variable",j),L}},A=()=>{if(!a)return null;const L=a.match(/var\(--(?:color-)?(.+?)\)/);if(L)return L[1];if(!M)return null;const j=sc(a,!0);for(const[O,H]of Object.entries(M))if(typeof H=="string"){const B=E(H);if(sc(B,!0)===j)return O}else for(const[B,Z]of Object.entries(H)){const K=E(Z);if(sc(K,!0)===j)return B==="DEFAULT"?O:`${O}-${B}`}return null},T=()=>{const L=A(),j=L?`#tokens?highlight=${encodeURIComponent(L)}`:"#tokens";C(!1),window.location.hash=j},M=h.useMemo(()=>{if(!u)return null;const L=Iu[e];if(!L)return null;const j=u.registry[L];return!j||Object.keys(j).length===0?null:j},[u,e]),I=h.useMemo(()=>{if(!M)return null;if(!m.searchTerm.trim())return M;const L=m.searchTerm.toLowerCase(),j={};return Object.entries(M).forEach(([O,H])=>{if(typeof H=="string")(O.toLowerCase().includes(L)||H.toLowerCase().includes(L))&&(j[O]=H);else{const B={};Object.entries(H).forEach(([Z,K])=>{(O.toLowerCase().includes(L)||Z.toLowerCase().includes(L)||K.toLowerCase().includes(L))&&(B[Z]=K)}),Object.keys(B).length>0&&(j[O]=B)}}),j},[M,m.searchTerm]);if(h.useEffect(()=>{x?m.view==="tokens"&&b.current&&setTimeout(()=>{var L;(L=b.current)==null||L.focus()},10):g(L=>({...L,searchTerm:"",view:"tokens"}))},[x,m.view]),h.useEffect(()=>{!M&&i&&(s==null||s(!1))},[M,i,s]),!M)return null;const P=L=>{const j=L.split("::"),O=j[0],H=j[1],B=M[O];let Z,K;if(typeof B=="string")Z=O,K=B;else if(H)Z=H==="DEFAULT"?O:`${O}-${H}`,K=B[H];else return;t(Z,K),g(q=>({...q,selectedValue:""})),C(!1)},S=Iu[e]==="colors",D=()=>y.jsx("div",{className:"space-y-3 p-2",children:Object.entries(I||{}).map(([L,j])=>{if(typeof j=="string"){const O=E(j);return y.jsxs("div",{className:"space-y-1.5",children:[y.jsx("div",{className:"text-[10px] font-medium text-content-subtle",children:L}),y.jsx(ja,{value:L,className:"relative inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-full outline-none transition-colors data-[highlighted]:bg-main-input data-[highlighted]:ring-1 data-[highlighted]:ring-primary-border",children:y.jsx("div",{className:"h-7 w-7 rounded-full",style:{backgroundColor:O},title:L})})]},L)}else return y.jsxs("div",{className:"space-y-1.5",children:[y.jsx("div",{className:"text-[10px] font-medium text-content-subtle",children:L}),y.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(j).map(([O,H])=>{const B=E(H);return y.jsx(ja,{value:`${L}::${O}`,className:"relative inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-full outline-none transition-colors data-[highlighted]:bg-main-input data-[highlighted]:ring-1 data-[highlighted]:ring-primary-border",children:y.jsx("div",{className:"h-7 w-7 rounded-full",style:{backgroundColor:B},title:O==="DEFAULT"?L:`${L}-${O}`})},`${L}::${O}`)})})]},L)})}),R=()=>Object.entries(I||{}).map(([L,j])=>{if(typeof j=="string"){const O=S?E(j):j;return y.jsxs(ja,{value:L,className:"relative flex cursor-pointer items-center gap-2 rounded border-[1px] border-transparent px-2 py-2 text-xs text-content outline-none transition-colors data-[disabled]:pointer-events-none data-[highlighted]:border-primary-border data-[highlighted]:bg-main-input data-[disabled]:opacity-50",children:[S&&y.jsx("div",{className:"flex-shrink-0 rounded border-[1px] border-gray-300",style:{width:"16px",height:"16px",backgroundColor:O}}),y.jsx("div",{className:"min-w-0 flex-1",children:y.jsxs(xd,{children:[y.jsx("div",{className:"font-medium",children:L}),y.jsx("div",{className:"truncate font-mono text-[10px] text-content-subtle",children:j})]})}),y.jsx(tp,{className:"ml-auto",children:y.jsx(za,{size:14,weight:"bold"})})]},L)}else return y.jsxs(fj,{children:[y.jsx(pj,{className:"px-2 py-1.5 text-xs font-medium text-content-subtle",children:L}),Object.entries(j).map(([O,H])=>{const B=S?E(H):H;return y.jsxs(ja,{value:`${L}::${O}`,className:"relative flex cursor-pointer items-center gap-2 rounded border-[1px] border-transparent px-2 py-2 pl-4 text-xs text-content outline-none transition-colors data-[disabled]:pointer-events-none data-[highlighted]:border-primary-border data-[highlighted]:bg-main-input data-[disabled]:opacity-50",children:[S&&y.jsx("div",{className:"flex-shrink-0 rounded border-[1px] border-gray-300",style:{width:"14px",height:"14px",backgroundColor:B}}),y.jsx("div",{className:"min-w-0 flex-1",children:y.jsxs(xd,{children:[y.jsx("div",{className:"font-medium",children:O==="DEFAULT"?"default":O}),y.jsx("div",{className:"truncate font-mono text-[10px] text-content-subtle",children:H})]})}),y.jsx(tp,{className:"ml-auto",children:y.jsx(za,{size:14,weight:"bold"})})]},`${L}::${O}`)})]},L)});return y.jsxs(bv,{value:m.selectedValue,onValueChange:P,open:x,onOpenChange:C,children:[y.jsx(xv,{asChild:!0,children:o}),y.jsx(_j,{showScrollButtons:m.view==="tokens",onCloseAutoFocus:L=>L.preventDefault(),className:m.view==="colorPicker"?"w-72":void 0,dataCy:c,onKeyDown:L=>{var j;(L.key.length===1||L.key==="Backspace"||L.key==="Delete")&&document.activeElement!==b.current&&((j=b.current)==null||j.focus())},header:y.jsx("div",{className:"sticky top-0 border-b-[1px] border-divider bg-main p-2",children:m.view==="tokens"?y.jsxs("div",{className:"space-y-2",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("div",{className:"relative flex-1",children:[y.jsx(o8,{className:"pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-content-subtle",size:14,weight:"bold"}),y.jsx("input",{ref:b,type:"text",value:m.searchTerm,onChange:L=>g(j=>({...j,searchTerm:L.target.value})),placeholder:"Search tokens...",className:"w-full rounded bg-main-input py-1.5 pl-8 pr-2 text-xs text-content placeholder-content-subtle outline-none focus:outline-none"})]}),n&&y.jsx("button",{type:"button",onClick:L=>{L.preventDefault(),L.stopPropagation(),g(j=>({...j,view:"colorPicker"}))},className:"flex-shrink-0 rounded px-2 py-1.5 text-content-subtle transition-colors hover:bg-main-hover",title:"Open color picker",children:y.jsx(a8,{size:16,weight:"bold"})}),S&&p&&y.jsx("button",{type:"button",onClick:L=>{L.preventDefault(),L.stopPropagation(),T()},className:"flex-shrink-0 rounded px-2 py-1.5 text-content-subtle transition-colors hover:bg-main-hover",title:"Edit design token",children:y.jsx(QI,{size:16,weight:"bold"})})]}),S&&y.jsx("div",{className:"flex items-center justify-end",children:y.jsx("button",{type:"button",onClick:L=>{L.preventDefault(),L.stopPropagation(),g(j=>({...j,viewMode:j.viewMode==="list"?"circles":"list"}))},className:"rounded px-2 py-1 text-content-subtle transition-colors hover:bg-main-hover",title:m.viewMode==="list"?"Switch to circle view":"Switch to list view",children:m.viewMode==="list"?y.jsx(pG,{size:14,weight:"bold"}):y.jsx(mG,{size:14,weight:"bold"})})})]}):y.jsxs("button",{type:"button",onClick:L=>{L.preventDefault(),L.stopPropagation(),r&&r(),g(j=>({...j,view:"tokens"}))},className:"flex items-center gap-2 rounded px-2 py-1 text-content-subtle transition-colors hover:bg-main-hover",title:"Back to tokens",children:[y.jsx(Og,{size:16,weight:"bold"}),y.jsx("span",{className:"text-xs",children:"Back to tokens"})]})}),children:m.view==="colorPicker"?n:Object.keys(I||{}).length===0&&m.searchTerm?y.jsxs("div",{className:"px-4 py-8 text-center text-xs text-content-subtle",children:['No tokens found matching "',m.searchTerm,'"']}):S&&m.viewMode==="circles"?D():R()})]})},Q0e=({onSend:e,onStop:t,disabled:n=!1,isStreaming:r=!1,placeholder:i="What design changes would you like to make?",autoFocus:s=!1,hasPendingChanges:o=!1,pendingTags:a=[],onRemovePendingTag:c,onClearPendingTags:u,canClearPendingTags:f=!0,contextChips:p,showModelPicker:m=!0})=>{const[g,b]=Vn(KJ),[x,C]=Vn(YJ),w=ke(E$),E=h.useRef(null),A=h.useRef(null),T=h.useRef(null),[M,I]=h.useState(!1),P=o||((p==null?void 0:p.length)??0)>0,S=()=>{var W;(g.trim()||P)&&!n&&!r&&(e(g.trim(),x.length>0?x:void 0),b(""),C([]),(W=E.current)==null||W.blur())},D=h.useCallback(W=>{T3(W).then(N=>{C(z=>[...z,N])}).catch(()=>{console.warn("[ChatInput] Failed to process image:",W.name)})},[C]),R=h.useCallback(W=>C(N=>[...N,W]),[C]),{isDragOver:L,dropHandlers:j}=sL(R),O=W=>{const N=W.target.files;if(N){for(const z of Array.from(N))z.type.startsWith("image/")&&D(z);A.current&&(A.current.value="")}},H=W=>{C(N=>N.filter((z,ee)=>ee!==W))};h.useEffect(()=>{E.current&&(E.current.style.height="auto",E.current.style.height=`${E.current.scrollHeight}px`)},[g]),h.useEffect(()=>{s&&E.current&&E.current.focus()},[s]);const B=h.useRef(w);h.useEffect(()=>{var W;w!==B.current&&((W=E.current)==null||W.focus())},[w]);const Z=W=>{var z;const N=(z=W.clipboardData)==null?void 0:z.items;if(N){for(const ee of Array.from(N))if(ee.type.startsWith("image/")){W.preventDefault();const te=ee.getAsFile();if(!te)continue;D(te)}}},K=W=>{const N=W.target.value,z=W.target.selectionStart;N.length===g.length+1&&z>0&&N[z-1]==="@"&&(T.current=z-1,I(!0)),b(N)},q=W=>{W.key==="Enter"&&(W.metaKey||W.ctrlKey)&&(W.preventDefault(),W.nativeEvent.stopImmediatePropagation(),S())},Q=h.useCallback(W=>{const N=E.current,z=(N==null?void 0:N.selectionStart)??g.length,ee=g.slice(0,z),te=g.slice(z),re=ee+W+te;b(re);const G=z+W.length;queueMicrotask(()=>{N==null||N.setSelectionRange(G,G),N==null||N.focus()})},[g,b]),F=(W,N)=>{const z=`${W} (${N})`;if(T.current!==null){const ee=T.current,te=g.slice(0,ee),re=g.slice(ee+1);b(te+z+re);const G=ee+z.length;queueMicrotask(()=>{var X,de;(X=E.current)==null||X.setSelectionRange(G,G),(de=E.current)==null||de.focus()}),T.current=null}else Q(z)},V=W=>{I(W),W||(T.current=null)};return y.jsxs("div",{className:"relative",...j,children:[L?y.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-primary/10",children:y.jsx("span",{className:"text-sm font-medium text-content",children:"Drop image here"})}):null,x.length>0?y.jsx("div",{className:"mb-2 max-h-40 overflow-y-auto rounded",children:y.jsx("div",{className:`grid gap-2 ${x.length===1?"grid-cols-1":"grid-cols-3"}`,children:x.map((W,N)=>y.jsxs("div",{className:"relative",children:[y.jsx("img",{src:W,alt:`Reference ${N+1}`,className:`w-full rounded border border-divider object-cover ${x.length===1?"max-h-24":"aspect-[4/3]"}`}),y.jsx("button",{onClick:()=>H(N),className:"absolute right-1 top-1 rounded-full bg-red-500/80 p-0.5 text-white backdrop-blur-sm hover:bg-red-600",children:y.jsx(Ho,{className:"h-3 w-3",weight:"bold"})})]},N))})}):null,p&&p.length>0?y.jsx("div",{className:"mb-2 flex flex-wrap items-center gap-2",children:p}):null,a.length>0?y.jsx("div",{className:"mb-2",children:y.jsx(t6,{tags:a,onRemoveTag:c,onClearAll:u,canClear:f})}):null,y.jsxs("div",{className:"rounded-lg bg-main-input outline outline-1 outline-transparent transition-[outline-color] focus-within:outline-white/20",children:[y.jsx("textarea",{ref:E,value:g,onChange:K,onPaste:Z,onKeyDown:q,placeholder:i,disabled:n,className:"max-h-32 min-h-[2.5rem] w-full resize-none overflow-y-auto bg-transparent pb-1 pl-3 pr-3 pt-3 text-sm text-content placeholder-content-subtle focus:outline-none disabled:opacity-50",rows:3,"data-cy":"chat-input"}),y.jsx("input",{ref:A,type:"file",accept:"image/*",multiple:!0,onChange:O,className:"hidden"}),y.jsxs("div",{className:"flex items-center justify-between px-3 pb-3 pt-1",children:[y.jsxs("div",{className:"flex gap-1",children:[y.jsx(ug,{property:"backgroundColor",onSelectToken:F,isOpen:M,onOpenChange:V,children:y.jsx("button",{disabled:n,className:"flex items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-hover hover:text-content disabled:cursor-not-allowed disabled:opacity-50",children:y.jsx(a8,{className:"h-5 w-5",weight:"bold"})})}),y.jsx("button",{onClick:()=>{var W;return(W=A.current)==null?void 0:W.click()},disabled:n,className:"flex items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-divider hover:text-content disabled:cursor-not-allowed disabled:opacity-50",children:y.jsx(WI,{className:"h-5 w-5",weight:"bold"})})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[m?y.jsx(E0e,{disabled:n||r}):null,r&&t?y.jsx("button",{onClick:t,className:"flex items-center justify-center rounded bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:"Stop generation",children:y.jsx(wG,{className:"h-4 w-4",weight:"fill"})}):y.jsx("button",{onClick:S,disabled:!g.trim()&&!P||n,className:"flex items-center justify-center rounded bg-primary p-1 text-content transition-colors hover:bg-primary-hover disabled:cursor-not-allowed disabled:opacity-80",children:y.jsx(i8,{className:"h-5 w-5",weight:"bold"})})]})]})]})]})},J0e=({chatMessages:e,statusHint:t,handleChatSend:n,handleStop:r,isProcessing:i,pendingChangeRows:s=[],onRemovePendingChange:o=()=>{},onApplyPendingChanges:a,onClearPendingChanges:c,disableInputWhileProcessing:u=!0,showModelPicker:f=!0})=>{const m=s.length>0,g=async(b,x)=>{if(b.trim().length===0&&m){await(a==null?void 0:a());return}await n(b,x)};return y.jsxs("div",{className:"flex min-h-0 flex-1 flex-col pb-4",children:[y.jsx("div",{className:"flex-1 overflow-y-auto p-4 pb-0",children:y.jsx(_fe,{messages:e})}),y.jsxs("div",{className:"relative flex-shrink-0 bg-main px-4 py-4",children:[t?y.jsx("p",{className:"mb-2 text-center text-xs text-content-subtle","data-cy":"mcp-agent-working-hint",children:t}):null,y.jsx(Q0e,{onSend:g,onStop:r,disabled:u&&i,isStreaming:i,autoFocus:!0,hasPendingChanges:m,pendingTags:s,onRemovePendingTag:o,onClearPendingTags:c,canClearPendingTags:!i,showModelPicker:f}),y.jsx("p",{className:"mt-2 text-center text-xs text-content-subtle",children:"The agent will read, edit, and execute files without asking."})]})]})};var wv="Collapsible",[eme,Aj]=xs(wv),[tme,K3]=eme(wv),Tj=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:i,disabled:s,onOpenChange:o,...a}=e,[c,u]=vs({prop:r,defaultProp:i??!1,onChange:o,caller:wv});return y.jsx(tme,{scope:n,disabled:s,contentId:Bi(),open:c,onOpenToggle:h.useCallback(()=>u(f=>!f),[u]),children:y.jsx(Et.div,{"data-state":X3(c),"data-disabled":s?"":void 0,...a,ref:t})})});Tj.displayName=wv;var Pj="CollapsibleTrigger",Ij=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,i=K3(Pj,n);return y.jsx(Et.button,{type:"button","aria-controls":i.open?i.contentId:void 0,"aria-expanded":i.open||!1,"data-state":X3(i.open),"data-disabled":i.disabled?"":void 0,disabled:i.disabled,...r,ref:t,onClick:ft(e.onClick,i.onOpenToggle)})});Ij.displayName=Pj;var Y3="CollapsibleContent",Mj=h.forwardRef((e,t)=>{const{forceMount:n,...r}=e,i=K3(Y3,e.__scopeCollapsible);return y.jsx(ws,{present:n||i.open,children:({present:s})=>y.jsx(nme,{...r,ref:t,present:s})})});Mj.displayName=Y3;var nme=h.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:i,...s}=e,o=K3(Y3,n),[a,c]=h.useState(r),u=h.useRef(null),f=Jt(t,u),p=h.useRef(0),m=p.current,g=h.useRef(0),b=g.current,x=o.open||a,C=h.useRef(x),w=h.useRef(void 0);return h.useEffect(()=>{const E=requestAnimationFrame(()=>C.current=!1);return()=>cancelAnimationFrame(E)},[]),hr(()=>{const E=u.current;if(E){w.current=w.current||{transitionDuration:E.style.transitionDuration,animationName:E.style.animationName},E.style.transitionDuration="0s",E.style.animationName="none";const A=E.getBoundingClientRect();p.current=A.height,g.current=A.width,C.current||(E.style.transitionDuration=w.current.transitionDuration,E.style.animationName=w.current.animationName),c(r)}},[o.open,r]),y.jsx(Et.div,{"data-state":X3(o.open),"data-disabled":o.disabled?"":void 0,id:o.contentId,hidden:!x,...s,ref:f,style:{"--radix-collapsible-content-height":m?`${m}px`:void 0,"--radix-collapsible-content-width":b?`${b}px`:void 0,...e.style},children:x&&i})});function X3(e){return e?"open":"closed"}var rme=Tj,ime=Ij,sme=Mj,ks="Accordion",ome=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Q3,ame,lme]=mv(ks),[kv]=xs(ks,[lme,Aj]),J3=Aj(),Rj=h.forwardRef((e,t)=>{const{type:n,...r}=e,i=r,s=r;return y.jsx(Q3.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?y.jsx(fme,{...s,ref:t}):y.jsx(dme,{...i,ref:t})})});Rj.displayName=ks;var[$j,cme]=kv(ks),[Dj,ume]=kv(ks,{collapsible:!1}),dme=h.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:i=()=>{},collapsible:s=!1,...o}=e,[a,c]=vs({prop:n,defaultProp:r??"",onChange:i,caller:ks});return y.jsx($j,{scope:e.__scopeAccordion,value:h.useMemo(()=>a?[a]:[],[a]),onItemOpen:c,onItemClose:h.useCallback(()=>s&&c(""),[s,c]),children:y.jsx(Dj,{scope:e.__scopeAccordion,collapsible:s,children:y.jsx(Nj,{...o,ref:t})})})}),fme=h.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:i=()=>{},...s}=e,[o,a]=vs({prop:n,defaultProp:r??[],onChange:i,caller:ks}),c=h.useCallback(f=>a((p=[])=>[...p,f]),[a]),u=h.useCallback(f=>a((p=[])=>p.filter(m=>m!==f)),[a]);return y.jsx($j,{scope:e.__scopeAccordion,value:o,onItemOpen:c,onItemClose:u,children:y.jsx(Dj,{scope:e.__scopeAccordion,collapsible:!0,children:y.jsx(Nj,{...s,ref:t})})})}),[hme,Cv]=kv(ks),Nj=h.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:i,orientation:s="vertical",...o}=e,a=h.useRef(null),c=Jt(a,t),u=ame(n),p=Ip(i)==="ltr",m=ft(e.onKeyDown,g=>{var S;if(!ome.includes(g.key))return;const b=g.target,x=u().filter(D=>{var R;return!((R=D.ref.current)!=null&&R.disabled)}),C=x.findIndex(D=>D.ref.current===b),w=x.length;if(C===-1)return;g.preventDefault();let E=C;const A=0,T=w-1,M=()=>{E=C+1,E>T&&(E=A)},I=()=>{E=C-1,E<A&&(E=T)};switch(g.key){case"Home":E=A;break;case"End":E=T;break;case"ArrowRight":s==="horizontal"&&(p?M():I());break;case"ArrowDown":s==="vertical"&&M();break;case"ArrowLeft":s==="horizontal"&&(p?I():M());break;case"ArrowUp":s==="vertical"&&I();break}const P=E%w;(S=x[P].ref.current)==null||S.focus()});return y.jsx(hme,{scope:n,disabled:r,direction:i,orientation:s,children:y.jsx(Q3.Slot,{scope:n,children:y.jsx(Et.div,{...o,"data-orientation":s,ref:c,onKeyDown:r?void 0:m})})})}),y1="AccordionItem",[pme,ek]=kv(y1),Lj=h.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...i}=e,s=Cv(y1,n),o=cme(y1,n),a=J3(n),c=Bi(),u=r&&o.value.includes(r)||!1,f=s.disabled||e.disabled;return y.jsx(pme,{scope:n,open:u,disabled:f,triggerId:c,children:y.jsx(rme,{"data-orientation":s.orientation,"data-state":Bj(u),...a,...i,ref:t,disabled:f,open:u,onOpenChange:p=>{p?o.onItemOpen(r):o.onItemClose(r)}})})});Lj.displayName=y1;var jj="AccordionHeader",Fj=h.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=Cv(ks,n),s=ek(jj,n);return y.jsx(Et.h3,{"data-orientation":i.orientation,"data-state":Bj(s.open),"data-disabled":s.disabled?"":void 0,...r,ref:t})});Fj.displayName=jj;var o6="AccordionTrigger",Oj=h.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=Cv(ks,n),s=ek(o6,n),o=ume(o6,n),a=J3(n);return y.jsx(Q3.ItemSlot,{scope:n,children:y.jsx(ime,{"aria-disabled":s.open&&!o.collapsible||void 0,"data-orientation":i.orientation,id:s.triggerId,...a,...r,ref:t})})});Oj.displayName=o6;var Vj="AccordionContent",Hj=h.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,i=Cv(ks,n),s=ek(Vj,n),o=J3(n);return y.jsx(sme,{role:"region","aria-labelledby":s.triggerId,"data-orientation":i.orientation,...o,...r,ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}})});Hj.displayName=Vj;function Bj(e){return e?"open":"closed"}var zj=Rj,mme=Lj,gme=Fj,vme=Oj,yme=Hj;/**
240
- * @license lucide-react v1.17.0 - ISC
240
+ * @license lucide-react v1.18.0 - ISC
241
241
  *
242
242
  * This source code is licensed under the ISC license.
243
243
  * See the LICENSE file in the root directory of this source tree.
244
244
  */const Uj=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim();/**
245
- * @license lucide-react v1.17.0 - ISC
245
+ * @license lucide-react v1.18.0 - ISC
246
246
  *
247
247
  * This source code is licensed under the ISC license.
248
248
  * See the LICENSE file in the root directory of this source tree.
249
249
  */const bme=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
250
- * @license lucide-react v1.17.0 - ISC
250
+ * @license lucide-react v1.18.0 - ISC
251
251
  *
252
252
  * This source code is licensed under the ISC license.
253
253
  * See the LICENSE file in the root directory of this source tree.
254
254
  */const xme=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase());/**
255
- * @license lucide-react v1.17.0 - ISC
255
+ * @license lucide-react v1.18.0 - ISC
256
256
  *
257
257
  * This source code is licensed under the ISC license.
258
258
  * See the LICENSE file in the root directory of this source tree.
259
259
  */const cP=e=>{const t=xme(e);return t.charAt(0).toUpperCase()+t.slice(1)};/**
260
- * @license lucide-react v1.17.0 - ISC
260
+ * @license lucide-react v1.18.0 - ISC
261
261
  *
262
262
  * This source code is licensed under the ISC license.
263
263
  * See the LICENSE file in the root directory of this source tree.
264
264
  */var cx={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
265
- * @license lucide-react v1.17.0 - ISC
265
+ * @license lucide-react v1.18.0 - ISC
266
266
  *
267
267
  * This source code is licensed under the ISC license.
268
268
  * See the LICENSE file in the root directory of this source tree.
269
269
  */const wme=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1},kme=h.createContext({}),Cme=()=>h.useContext(kme),Eme=h.forwardRef(({color:e,size:t,strokeWidth:n,absoluteStrokeWidth:r,className:i="",children:s,iconNode:o,...a},c)=>{const{size:u=24,strokeWidth:f=2,absoluteStrokeWidth:p=!1,color:m="currentColor",className:g=""}=Cme()??{},b=r??p?Number(n??f)*24/Number(t??u):n??f;return h.createElement("svg",{ref:c,...cx,width:t??u??cx.width,height:t??u??cx.height,stroke:e??m,strokeWidth:b,className:Uj("lucide",g,i),...!s&&!wme(a)&&{"aria-hidden":"true"},...a},[...o.map(([x,C])=>h.createElement(x,C)),...Array.isArray(s)?s:[s]])});/**
270
- * @license lucide-react v1.17.0 - ISC
270
+ * @license lucide-react v1.18.0 - ISC
271
271
  *
272
272
  * This source code is licensed under the ISC license.
273
273
  * See the LICENSE file in the root directory of this source tree.
274
274
  */const kt=(e,t)=>{const n=h.forwardRef(({className:r,...i},s)=>h.createElement(Eme,{ref:s,iconNode:t,className:Uj(`lucide-${bme(cP(e))}`,`lucide-${e}`,r),...i}));return n.displayName=cP(e),n};/**
275
- * @license lucide-react v1.17.0 - ISC
275
+ * @license lucide-react v1.18.0 - ISC
276
276
  *
277
277
  * This source code is licensed under the ISC license.
278
278
  * See the LICENSE file in the root directory of this source tree.
279
279
  */const Sme=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],_me=kt("arrow-left",Sme);/**
280
- * @license lucide-react v1.17.0 - ISC
280
+ * @license lucide-react v1.18.0 - ISC
281
281
  *
282
282
  * This source code is licensed under the ISC license.
283
283
  * See the LICENSE file in the root directory of this source tree.
284
284
  */const Ame=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Tme=kt("arrow-right",Ame);/**
285
- * @license lucide-react v1.17.0 - ISC
285
+ * @license lucide-react v1.18.0 - ISC
286
286
  *
287
287
  * This source code is licensed under the ISC license.
288
288
  * See the LICENSE file in the root directory of this source tree.
289
289
  */const Pme=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Ime=kt("arrow-up",Pme);/**
290
- * @license lucide-react v1.17.0 - ISC
290
+ * @license lucide-react v1.18.0 - ISC
291
291
  *
292
292
  * This source code is licensed under the ISC license.
293
293
  * See the LICENSE file in the root directory of this source tree.
294
294
  */const Mme=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],Rme=kt("bell",Mme);/**
295
- * @license lucide-react v1.17.0 - ISC
295
+ * @license lucide-react v1.18.0 - ISC
296
296
  *
297
297
  * This source code is licensed under the ISC license.
298
298
  * See the LICENSE file in the root directory of this source tree.
299
299
  */const $me=[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]],Dme=kt("brain",$me);/**
300
- * @license lucide-react v1.17.0 - ISC
300
+ * @license lucide-react v1.18.0 - ISC
301
301
  *
302
302
  * This source code is licensed under the ISC license.
303
303
  * See the LICENSE file in the root directory of this source tree.
304
304
  */const Nme=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Lme=kt("check",Nme);/**
305
- * @license lucide-react v1.17.0 - ISC
305
+ * @license lucide-react v1.18.0 - ISC
306
306
  *
307
307
  * This source code is licensed under the ISC license.
308
308
  * See the LICENSE file in the root directory of this source tree.
309
309
  */const jme=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Fme=kt("chevron-down",jme);/**
310
- * @license lucide-react v1.17.0 - ISC
310
+ * @license lucide-react v1.18.0 - ISC
311
311
  *
312
312
  * This source code is licensed under the ISC license.
313
313
  * See the LICENSE file in the root directory of this source tree.
314
314
  */const Ome=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Vme=kt("chevron-right",Ome);/**
315
- * @license lucide-react v1.17.0 - ISC
315
+ * @license lucide-react v1.18.0 - ISC
316
316
  *
317
317
  * This source code is licensed under the ISC license.
318
318
  * See the LICENSE file in the root directory of this source tree.
319
319
  */const Hme=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Bme=kt("circle",Hme);/**
320
- * @license lucide-react v1.17.0 - ISC
320
+ * @license lucide-react v1.18.0 - ISC
321
321
  *
322
322
  * This source code is licensed under the ISC license.
323
323
  * See the LICENSE file in the root directory of this source tree.
324
324
  */const zme=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],Ume=kt("clock",zme);/**
325
- * @license lucide-react v1.17.0 - ISC
325
+ * @license lucide-react v1.18.0 - ISC
326
326
  *
327
327
  * This source code is licensed under the ISC license.
328
328
  * See the LICENSE file in the root directory of this source tree.
329
329
  */const Zme=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Wme=kt("copy",Zme);/**
330
- * @license lucide-react v1.17.0 - ISC
330
+ * @license lucide-react v1.18.0 - ISC
331
331
  *
332
332
  * This source code is licensed under the ISC license.
333
333
  * See the LICENSE file in the root directory of this source tree.
334
334
  */const Gme=[["circle",{cx:"12.1",cy:"12.1",r:"1",key:"18d7e5"}]],qme=kt("dot",Gme);/**
335
- * @license lucide-react v1.17.0 - ISC
335
+ * @license lucide-react v1.18.0 - ISC
336
336
  *
337
337
  * This source code is licensed under the ISC license.
338
338
  * See the LICENSE file in the root directory of this source tree.
339
339
  */const Kme=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],Yme=kt("globe",Kme);/**
340
- * @license lucide-react v1.17.0 - ISC
340
+ * @license lucide-react v1.18.0 - ISC
341
341
  *
342
342
  * This source code is licensed under the ISC license.
343
343
  * See the LICENSE file in the root directory of this source tree.
344
344
  */const Xme=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],Qme=kt("heart",Xme);/**
345
- * @license lucide-react v1.17.0 - ISC
345
+ * @license lucide-react v1.18.0 - ISC
346
346
  *
347
347
  * This source code is licensed under the ISC license.
348
348
  * See the LICENSE file in the root directory of this source tree.
349
349
  */const Jme=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],ege=kt("house",Jme);/**
350
- * @license lucide-react v1.17.0 - ISC
350
+ * @license lucide-react v1.18.0 - ISC
351
351
  *
352
352
  * This source code is licensed under the ISC license.
353
353
  * See the LICENSE file in the root directory of this source tree.
354
354
  */const tge=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],nge=kt("image",tge);/**
355
- * @license lucide-react v1.17.0 - ISC
355
+ * @license lucide-react v1.18.0 - ISC
356
356
  *
357
357
  * This source code is licensed under the ISC license.
358
358
  * See the LICENSE file in the root directory of this source tree.
359
359
  */const rge=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],ige=kt("inbox",rge);/**
360
- * @license lucide-react v1.17.0 - ISC
360
+ * @license lucide-react v1.18.0 - ISC
361
361
  *
362
362
  * This source code is licensed under the ISC license.
363
363
  * See the LICENSE file in the root directory of this source tree.
364
364
  */const sge=[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]],oge=kt("lightbulb",sge);/**
365
- * @license lucide-react v1.17.0 - ISC
365
+ * @license lucide-react v1.18.0 - ISC
366
366
  *
367
367
  * This source code is licensed under the ISC license.
368
368
  * See the LICENSE file in the root directory of this source tree.
369
369
  */const age=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]],lge=kt("link",age);/**
370
- * @license lucide-react v1.17.0 - ISC
370
+ * @license lucide-react v1.18.0 - ISC
371
371
  *
372
372
  * This source code is licensed under the ISC license.
373
373
  * See the LICENSE file in the root directory of this source tree.
374
374
  */const cge=[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]],uge=kt("loader",cge);/**
375
- * @license lucide-react v1.17.0 - ISC
375
+ * @license lucide-react v1.18.0 - ISC
376
376
  *
377
377
  * This source code is licensed under the ISC license.
378
378
  * See the LICENSE file in the root directory of this source tree.
379
379
  */const dge=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]],fge=kt("lock",dge);/**
380
- * @license lucide-react v1.17.0 - ISC
380
+ * @license lucide-react v1.18.0 - ISC
381
381
  *
382
382
  * This source code is licensed under the ISC license.
383
383
  * See the LICENSE file in the root directory of this source tree.
384
384
  */const hge=[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]],pge=kt("mail",hge);/**
385
- * @license lucide-react v1.17.0 - ISC
385
+ * @license lucide-react v1.18.0 - ISC
386
386
  *
387
387
  * This source code is licensed under the ISC license.
388
388
  * See the LICENSE file in the root directory of this source tree.
389
389
  */const mge=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],gge=kt("menu",mge);/**
390
- * @license lucide-react v1.17.0 - ISC
390
+ * @license lucide-react v1.18.0 - ISC
391
391
  *
392
392
  * This source code is licensed under the ISC license.
393
393
  * See the LICENSE file in the root directory of this source tree.
394
394
  */const vge=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],yge=kt("message-circle",vge);/**
395
- * @license lucide-react v1.17.0 - ISC
395
+ * @license lucide-react v1.18.0 - ISC
396
396
  *
397
397
  * This source code is licensed under the ISC license.
398
398
  * See the LICENSE file in the root directory of this source tree.
399
399
  */const bge=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],xge=kt("monitor",bge);/**
400
- * @license lucide-react v1.17.0 - ISC
400
+ * @license lucide-react v1.18.0 - ISC
401
401
  *
402
402
  * This source code is licensed under the ISC license.
403
403
  * See the LICENSE file in the root directory of this source tree.
404
404
  */const wge=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]],kge=kt("moon",wge);/**
405
- * @license lucide-react v1.17.0 - ISC
405
+ * @license lucide-react v1.18.0 - ISC
406
406
  *
407
407
  * This source code is licensed under the ISC license.
408
408
  * See the LICENSE file in the root directory of this source tree.
409
409
  */const Cge=[["path",{d:"m14.622 17.897-10.68-2.913",key:"vj2p1u"}],["path",{d:"M18.376 2.622a1 1 0 1 1 3.002 3.002L17.36 9.643a.5.5 0 0 0 0 .707l.944.944a2.41 2.41 0 0 1 0 3.408l-.944.944a.5.5 0 0 1-.707 0L8.354 7.348a.5.5 0 0 1 0-.707l.944-.944a2.41 2.41 0 0 1 3.408 0l.944.944a.5.5 0 0 0 .707 0z",key:"18tc5c"}],["path",{d:"M9 8c-1.804 2.71-3.97 3.46-6.583 3.948a.507.507 0 0 0-.302.819l7.32 8.883a1 1 0 0 0 1.185.204C12.735 20.405 16 16.792 16 15",key:"ytzfxy"}]],Ege=kt("paintbrush",Cge);/**
410
- * @license lucide-react v1.17.0 - ISC
410
+ * @license lucide-react v1.18.0 - ISC
411
411
  *
412
412
  * This source code is licensed under the ISC license.
413
413
  * See the LICENSE file in the root directory of this source tree.
414
414
  */const Sge=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],_ge=kt("palette",Sge);/**
415
- * @license lucide-react v1.17.0 - ISC
415
+ * @license lucide-react v1.18.0 - ISC
416
416
  *
417
417
  * This source code is licensed under the ISC license.
418
418
  * See the LICENSE file in the root directory of this source tree.
419
419
  */const Age=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],Tge=kt("pause",Age);/**
420
- * @license lucide-react v1.17.0 - ISC
420
+ * @license lucide-react v1.18.0 - ISC
421
421
  *
422
422
  * This source code is licensed under the ISC license.
423
423
  * See the LICENSE file in the root directory of this source tree.
424
424
  */const Pge=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Ige=kt("pencil",Pge);/**
425
- * @license lucide-react v1.17.0 - ISC
425
+ * @license lucide-react v1.18.0 - ISC
426
426
  *
427
427
  * This source code is licensed under the ISC license.
428
428
  * See the LICENSE file in the root directory of this source tree.
429
429
  */const Mge=[["path",{d:"m12 9-8.414 8.414A2 2 0 0 0 3 18.828v1.344a2 2 0 0 1-.586 1.414A2 2 0 0 1 3.828 21h1.344a2 2 0 0 0 1.414-.586L15 12",key:"1y3wsu"}],["path",{d:"m18 9 .4.4a1 1 0 1 1-3 3l-3.8-3.8a1 1 0 1 1 3-3l.4.4 3.4-3.4a1 1 0 1 1 3 3z",key:"110lr1"}],["path",{d:"m2 22 .414-.414",key:"jhxm08"}]],Rge=kt("pipette",Mge);/**
430
- * @license lucide-react v1.17.0 - ISC
430
+ * @license lucide-react v1.18.0 - ISC
431
431
  *
432
432
  * This source code is licensed under the ISC license.
433
433
  * See the LICENSE file in the root directory of this source tree.
434
434
  */const $ge=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],Dge=kt("play",$ge);/**
435
- * @license lucide-react v1.17.0 - ISC
435
+ * @license lucide-react v1.18.0 - ISC
436
436
  *
437
437
  * This source code is licensed under the ISC license.
438
438
  * See the LICENSE file in the root directory of this source tree.
439
439
  */const Nge=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Lge=kt("plus",Nge);/**
440
- * @license lucide-react v1.17.0 - ISC
440
+ * @license lucide-react v1.18.0 - ISC
441
441
  *
442
442
  * This source code is licensed under the ISC license.
443
443
  * See the LICENSE file in the root directory of this source tree.
444
444
  */const jge=[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}]],Fge=kt("rectangle-horizontal",jge);/**
445
- * @license lucide-react v1.17.0 - ISC
445
+ * @license lucide-react v1.18.0 - ISC
446
446
  *
447
447
  * This source code is licensed under the ISC license.
448
448
  * See the LICENSE file in the root directory of this source tree.
449
449
  */const Oge=[["path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5",key:"qeys4"}],["path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09",key:"u4xsad"}],["path",{d:"M9 12a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.4 22.4 0 0 1-4 2z",key:"676m9"}],["path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 .05 5 .05",key:"92ym6u"}]],Vge=kt("rocket",Oge);/**
450
- * @license lucide-react v1.17.0 - ISC
450
+ * @license lucide-react v1.18.0 - ISC
451
451
  *
452
452
  * This source code is licensed under the ISC license.
453
453
  * See the LICENSE file in the root directory of this source tree.
454
454
  */const Hge=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],Bge=kt("rotate-ccw",Hge);/**
455
- * @license lucide-react v1.17.0 - ISC
455
+ * @license lucide-react v1.18.0 - ISC
456
456
  *
457
457
  * This source code is licensed under the ISC license.
458
458
  * See the LICENSE file in the root directory of this source tree.
459
459
  */const zge=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Uge=kt("search",zge);/**
460
- * @license lucide-react v1.17.0 - ISC
460
+ * @license lucide-react v1.18.0 - ISC
461
461
  *
462
462
  * This source code is licensed under the ISC license.
463
463
  * See the LICENSE file in the root directory of this source tree.
464
464
  */const Zge=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Wge=kt("settings",Zge);/**
465
- * @license lucide-react v1.17.0 - ISC
465
+ * @license lucide-react v1.18.0 - ISC
466
466
  *
467
467
  * This source code is licensed under the ISC license.
468
468
  * See the LICENSE file in the root directory of this source tree.
469
469
  */const Gge=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],qge=kt("shield",Gge);/**
470
- * @license lucide-react v1.17.0 - ISC
470
+ * @license lucide-react v1.18.0 - ISC
471
471
  *
472
472
  * This source code is licensed under the ISC license.
473
473
  * See the LICENSE file in the root directory of this source tree.
474
474
  */const Kge=[["path",{d:"M21 4v16",key:"7j8fe9"}],["path",{d:"M6.029 4.285A2 2 0 0 0 3 6v12a2 2 0 0 0 3.029 1.715l9.997-5.998a2 2 0 0 0 .003-3.432z",key:"zs4d6"}]],Yge=kt("skip-forward",Kge);/**
475
- * @license lucide-react v1.17.0 - ISC
475
+ * @license lucide-react v1.18.0 - ISC
476
476
  *
477
477
  * This source code is licensed under the ISC license.
478
478
  * See the LICENSE file in the root directory of this source tree.
479
479
  */const Xge=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 7v10",key:"d5nglc"}],["path",{d:"M11 7v10",key:"pptsnr"}],["path",{d:"m15 7 2 10",key:"1m7qm5"}]],Qge=kt("square-library",Xge);/**
480
- * @license lucide-react v1.17.0 - ISC
480
+ * @license lucide-react v1.18.0 - ISC
481
481
  *
482
482
  * This source code is licensed under the ISC license.
483
483
  * See the LICENSE file in the root directory of this source tree.
484
484
  */const Jge=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],e1e=kt("star",Jge);/**
485
- * @license lucide-react v1.17.0 - ISC
485
+ * @license lucide-react v1.18.0 - ISC
486
486
  *
487
487
  * This source code is licensed under the ISC license.
488
488
  * See the LICENSE file in the root directory of this source tree.
489
489
  */const t1e=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],n1e=kt("sun",t1e);/**
490
- * @license lucide-react v1.17.0 - ISC
490
+ * @license lucide-react v1.18.0 - ISC
491
491
  *
492
492
  * This source code is licensed under the ISC license.
493
493
  * See the LICENSE file in the root directory of this source tree.
494
494
  */const r1e=[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]],i1e=kt("user",r1e);/**
495
- * @license lucide-react v1.17.0 - ISC
495
+ * @license lucide-react v1.18.0 - ISC
496
496
  *
497
497
  * This source code is licensed under the ISC license.
498
498
  * See the LICENSE file in the root directory of this source tree.
499
499
  */const s1e=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],o1e=kt("users",s1e);/**
500
- * @license lucide-react v1.17.0 - ISC
500
+ * @license lucide-react v1.18.0 - ISC
501
501
  *
502
502
  * This source code is licensed under the ISC license.
503
503
  * See the LICENSE file in the root directory of this source tree.
@@ -507,7 +507,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
507
507
 
508
508
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
509
509
 
510
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return h.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},_2e="DialogDescriptionWarning",A2e=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${DV(_2e).contentName}}.`;return h.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Dv=kV,Nv=SV,Lv=_V,jv=AV,lp=PV,Ak=RV;const Nm=Mt("useCommit"),T2e=()=>{const[e,t]=h.useState(!1),[n,r]=h.useState(!1),i=h.useCallback(async()=>{r(!0);try{const o=await fetch("/api/git/generate-commit-message");if(!o.ok){const c=await o.json();throw new Error(c.error||`HTTP ${o.status}`)}return(await o.json()).message}catch(o){return Nm.warn("Failed to generate commit message:",o),null}finally{r(!1)}},[]);return{commit:h.useCallback(async(o,a=!1)=>{t(!0);try{const c=await fetch("/api/git/commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:o,push:a})}),u=await c.json();if(!c.ok&&u.sha)return Nm.warn("Commit succeeded but push failed:",u.details),{sha:u.sha,pushed:!1,pushError:u.details||u.error};if(!c.ok)throw new Error(u.details||u.error||`HTTP ${c.status}`);return Nm.info("Committed successfully:",u.sha),{sha:u.sha,pushed:!!u.pushed}}catch(c){throw Nm.warn("Failed to commit:",c),c}finally{t(!1)}},[]),generateMessage:i,isCommitting:e,isGenerating:n}},P2e=Mt("CommitModal"),I2e=({isOpen:e,onClose:t,onCommitted:n})=>{const r=bs(),{commit:i,generateMessage:s,isCommitting:o,isGenerating:a}=T2e(),[c,u]=h.useState(""),[f,p]=h.useState(null);h.useEffect(()=>{e&&(u(""),s().then(b=>{b&&u(b)}))},[e,s]);const m=h.useCallback(async(b=!1)=>{if(c.trim()){p(b?"push":"commit");try{const x=await i(c.trim(),b);r==null||r.capture("git_commit",{has_push:b,is_pushed:x.pushed,has_push_error:!!x.pushError,message_length:c.trim().length}),n(),t(),x.pushError&&ct.error("Commit succeeded but push failed",{description:x.pushError})}catch(x){r==null||r.capture("git_commit_failed",{has_push:b,error:x instanceof Error?x.message:"unknown"}),P2e.error("Commit failed:",x),ct.error("Commit failed",{description:x instanceof Error?x.message:"Failed to commit"})}finally{p(null)}}},[i,c,n,t,r]),g=h.useCallback(b=>{b.key==="Enter"&&b.metaKey&&(b.preventDefault(),m(!b.shiftKey))},[m]);return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Commit Changes"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("textarea",{value:c,onChange:b=>u(b.target.value),onKeyDown:g,placeholder:a?"Generating message...":"Enter commit message",disabled:a,rows:3,className:"w-full resize-none rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),a?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:()=>m(!1),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md border border-divider px-3 py-2 text-xs text-white transition-colors hover:bg-main-hover disabled:opacity-50",children:f==="commit"?"Committing...":"Commit"}),y.jsx("button",{onClick:()=>m(!0),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:f==="push"?"Committing...":"Commit & Push"})]})]})})]})})},LP=Mt("CreateBranchModal"),M2e=({isOpen:e,onClose:t,onCreated:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),[c,u]=h.useState(!1);h.useEffect(()=>{e&&(s(""),a(!0),fetch("/api/git/generate-branch-name").then(m=>{if(!m.ok)throw new Error(`HTTP ${m.status}`);return m.json()}).then(m=>{s(m.branchName)}).catch(m=>{LP.error("Failed to generate branch name:",m),s("rivet/")}).finally(()=>{a(!1)}))},[e]);const f=h.useCallback(async()=>{if(!i.trim()||c||o)return;u(!0);const m=i.trim();try{const g=await fetch("/api/git/create-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branchName:m})});if(!g.ok){const b=await g.json();throw new Error(b.details||b.error||`HTTP ${g.status}`)}n(m),t()}catch(g){const b=g instanceof Error?g.message:"Failed to create branch";r==null||r.capture("git_branch_create_failed",{branch:m,error:b}),ct.error("Failed to create branch",{description:b}),LP.error("Failed to create branch:",g)}finally{u(!1)}},[i,c,o,n,t,r]),p=h.useCallback(m=>{m.key==="Enter"&&(m.preventDefault(),f())},[f]);return y.jsx(Dv,{open:e,onOpenChange:m=>!m&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Create Branch"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:i,onChange:m=>s(m.target.value),onKeyDown:p,placeholder:o?"Generating name...":"Enter branch name",disabled:o,className:"w-full rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),o?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsx("button",{onClick:f,disabled:c||o||!i.trim(),className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:c?"Creating...":"Create"})]})})]})})},R2e=({prUrl:e,branchName:t,isOpen:n,isLoading:r=!1,onClose:i})=>{const s=bs(),o=h.useCallback(a=>{a.key!=="Enter"||a.repeat||r||(a.preventDefault(),e&&(s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"keyboard"}),window.open(e,"_blank","noopener,noreferrer")))},[r,e,s,t]);return h.useEffect(()=>{if(n)return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n,o]),y.jsx(Dv,{open:n,onOpenChange:a=>!a&&i(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsxs(jv,{className:"fixed left-1/2 top-1/2 z-max w-[380px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:[r?y.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[y.jsx(Ua,{className:"h-6 w-6 animate-spin text-primary",weight:"bold"}),y.jsx(lp,{className:"text-sm font-medium text-content",children:"Creating pull request..."})]}):null,r?null:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between gap-3",children:[y.jsx(lp,{className:"whitespace-nowrap text-sm font-semibold text-content",children:"Created Pull Request"}),t?y.jsxs("span",{className:"inline-flex max-w-[180px] shrink-0 items-center gap-1 rounded-md bg-main-input px-2 py-0.5 text-xs text-content-muted",children:[y.jsx(vh,{className:"h-3 w-3 shrink-0",weight:"bold"}),y.jsx("span",{className:"truncate",children:t})]}):null]}),y.jsxs("a",{href:e??"#",target:"_blank",rel:"noopener noreferrer",onClick:()=>{s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"button"})},className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover",children:["View PR",y.jsx(r8,{className:"h-3 w-3",weight:"bold"})]})]})]})]})})},NV=({primaryLabel:e,primaryIcon:t,primaryAction:n,isDisabled:r=!1,isLoading:i=!1,loadingLabel:s,dropdownItems:o})=>{const[a,c]=h.useState(!1),u=i?s??e:e;return y.jsxs("div",{className:"flex items-stretch",children:[y.jsxs("button",{onClick:n,disabled:r||i,className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-l-md bg-main-hover px-3 text-xs font-medium text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[t?y.jsx(t,{className:"h-3.5 w-3.5",weight:"bold"}):null,u]}),y.jsxs(Fo,{open:a,onOpenChange:c,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{disabled:i,className:"h-7 flex-shrink-0 rounded-r-md border-l border-white/20 bg-main-hover px-1.5 text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:y.jsx(Ba,{className:"h-3.5 w-3.5",weight:"bold"})})}),y.jsx(Oo,{children:y.jsx(Vo,{className:"z-[60] min-w-[140px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:5,align:"end",children:o.map(f=>{const p=f.icon;return y.jsxs("button",{onClick:()=>{f.isDisabled||(f.onClick(),c(!1))},disabled:f.isDisabled,className:"flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[p?y.jsx(p,{className:"h-3.5 w-3.5",weight:"bold"}):null,f.label]},f.label)})})})]})]})},$2e=h.createContext(null);function D2e(e){switch(e){case"top":return{y:4};case"bottom":return{y:-4};case"left":return{x:4};case"right":return{x:-4}}}function Tk({content:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=200,className:s,forceOpen:o,onOpenChange:a}){const[c,u]=h.useState(!1),f=o!==void 0?o:c,[p,m]=h.useState(!1),g=Mp(),b=h.useContext($2e);h.useEffect(()=>{f&&m(!0)},[f]);const x=()=>{f||m(!1)},C=D2e(n);return y.jsx(bV,{delayDuration:i,children:y.jsxs(xk,{open:f,onOpenChange:w=>{u(w),a==null||a(w)},children:[y.jsx(wk,{asChild:!0,children:t}),p&&y.jsx(kk,{forceMount:!0,container:b??void 0,children:y.jsx(Ck,{side:n,sideOffset:r,forceMount:!0,className:"z-tooltip",children:y.jsx(mn.div,{className:fr("bg-neutral-900 text-white text-[12px] px-2 py-1 border border-white/10 shadow-lg",g.bg,s),style:{fontVariationSettings:_h.medium},initial:{opacity:0,scale:.8,...C},animate:{opacity:f?1:0,scale:f?1:.9,x:0,y:0},transition:f?{type:"spring",duration:.34,bounce:.55}:{duration:.1},onAnimationComplete:x,children:e})})})]})})}const Fi=({label:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=300,disabled:s=!1})=>s?y.jsx(y.Fragment,{children:t}):y.jsx(Tk,{content:e,side:n,sideOffset:r,delayDuration:i,children:t}),vx=Mt("GitHome"),N2e=({onClose:e})=>e?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx(Fi,{label:"Close chat",side:"bottom",children:y.jsx("button",{onClick:e,className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})}):null,L2e=({onUndo:e,isUndoing:t=!1,onClose:n})=>{const r=bs(),s=ke(Qs).branchDiff.isEnabled,{status:o,fetchStatus:a}=q1(),{stats:c}=cV(),{publishChanges:u,isPublishing:f}=Kye(),{pushCommits:p,isPushing:m}=Yye(),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(!1),[A,T]=h.useState(null),[M,I]=h.useState(null),P=(o==null?void 0:o.branchName)??null,S=(o==null?void 0:o.hasUncommittedChanges)??!1,D=c.totalInsertions>0||c.totalDeletions>0,R=(o==null?void 0:o.canUndo)??!1,L=(o==null?void 0:o.prUrl)??null,j=h.useCallback((Fe,Te,je,nt)=>{Fe==="success"?ct.success(Te,{description:je,action:nt?{label:nt.label,onClick:nt.onClick}:void 0}):Fe==="info"?ct.info(Te,{description:je}):(je&&vx.error(`${Te}:`,je),ct.error(Te))},[]),O=h.useCallback(async()=>{r==null||r.capture("git_pr_create_started",{branch:P}),E(!0),T(null);let Fe=!1;const je=await u((nt,yt,et)=>{nt==="error"&&(Fe=!0,r==null||r.capture("git_pr_create_failed",{branch:P,error:et??yt}),vx.error("Failed to create PR:",et??yt),E(!1),ct.error("Failed to create PR",{description:et??yt}))});je!=null&&je.prUrl?(r==null||r.capture("git_pr_created",{branch:je.branchName,pr_url:je.prUrl}),T(je.prUrl),I(je.branchName),a()):Fe||(r==null||r.capture("git_pr_create_failed",{branch:P,error:"unknown"}),vx.error("Failed to create PR: unknown error"),E(!1),ct.error("Failed to create PR",{description:"Something went wrong creating the pull request."}))},[u,a,r,P]),H=h.useCallback(async()=>{r==null||r.capture("git_push_started",{branch:P});const{success:Fe,error:Te}=await p();Fe?(r==null||r.capture("git_push_succeeded",{branch:P}),j("success","Changes pushed to GitHub")):(r==null||r.capture("git_push_failed",{branch:P,error:Te}),j("error","Failed to push",Te??void 0))},[p,j,r,P]),B=h.useCallback(()=>{L&&(r==null||r.capture("git_pr_opened",{branch:P,pr_url:L}),window.open(L,"_blank","noopener,noreferrer"))},[L,r,P]),Z=h.useCallback(()=>{a(),ct.success("Changes committed")},[a]),K=h.useCallback(Fe=>{r==null||r.capture("git_branch_created",{branch:Fe,from_branch:P}),a(),ct.success("Branch created")},[a,r,P]),q=h.useCallback(()=>{r==null||r.capture("git_commit_modal_opened",{branch:P}),b(!0)},[r,P]),Q=h.useCallback(()=>{r==null||r.capture("git_create_branch_modal_opened",{branch:P}),C(!0)},[r,P]),F=h.useCallback(()=>{r==null||r.capture("git_undo_commit",{branch:P}),e==null||e(j)},[r,P,e,j]),V=S,W=!!L,N=P==="main"&&!V&&!W,z=W?"Go to PR":"Create PR",ee=W?r8:C5,te=W?B:O,re=!W&&!D;let G=V?"Commit":z,X=V?k5:ee,de=V?q:te,ve=V?!1:re;N&&(G="New Branch",X=vh,de=Q,ve=!1);const we=V?[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},{label:z,icon:ee,onClick:te,isDisabled:f||re},{label:"Create New Branch",icon:vh,onClick:Q}]:[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},...N?[{label:"Create PR",icon:C5,onClick:O,isDisabled:!0}]:[{label:"Commit",icon:k5,onClick:q,isDisabled:!S},{label:"Create Branch",icon:vh,onClick:Q}]];return P?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"z-10 flex h-10 flex-shrink-0 items-center justify-between border-b border-main-border bg-main-light px-3",children:[n&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})}),y.jsx("div",{className:"mx-1 h-4 w-[1px] flex-shrink-0 bg-divider/20"})]}),y.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-2",children:[y.jsx(g2e,{currentBranch:P,onSwitch:()=>{a()}}),s&&D&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"h-4 w-[1px] flex-shrink-0 bg-divider/20"}),y.jsx(Qye,{})]})]}),y.jsx(NV,{primaryLabel:G,primaryIcon:X,primaryAction:de,isDisabled:ve,isLoading:!1,loadingLabel:"Creating PR...",dropdownItems:we})]}),y.jsx(I2e,{isOpen:g,onClose:()=>b(!1),onCommitted:Z}),y.jsx(M2e,{isOpen:x,onClose:()=>C(!1),onCreated:K}),y.jsx(R2e,{prUrl:A,branchName:M??void 0,isOpen:w,isLoading:f,onClose:()=>E(!1)})]}):n?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})}):null},j2e=e=>{const t=ke(x$),r=ke(Qs).gitUi.isEnabled;return!t||!r?y.jsx(N2e,{onClose:e.onClose}):y.jsx(L2e,{...e})},F2e=Mt("SupportTicketModal"),jP=5e3,yx="feedback",O2e=e=>{var r;if(!e)return null;const t=(r=e.formErrors)==null?void 0:r[0];if(t)return t;const n=e.fieldErrors??{};for(const i of Object.values(n)){const s=i==null?void 0:i[0];if(s)return s}return null},V2e=async e=>{let t;try{t=await e.json()}catch{t=void 0}if(e.status===400){if(typeof(t==null?void 0:t.details)=="string"&&t.details.trim())return t.details;if(typeof(t==null?void 0:t.details)=="object"&&t.details!==null){const n=O2e(t.details);if(n)return n}return"Please check your feedback and try again."}return e.status>=500?typeof(t==null?void 0:t.details)=="string"&&t.details.trim()?t.details:"Could not send feedback right now. Please try again later.":typeof(t==null?void 0:t.error)=="string"&&t.error.trim()?t.error:`HTTP ${e.status}`},H2e=({isOpen:e,onClose:t,contactEmail:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),c=h.useCallback(()=>{s("")},[]),u=h.useCallback(()=>{o||(c(),t())},[o,t,c]),f=h.useCallback(async()=>{const b=i.trim();if(!(!b||o)){a(!0);try{const x=typeof(r==null?void 0:r.get_session_id)=="function"?r.get_session_id():void 0,C=typeof(r==null?void 0:r.get_distinct_id)=="function"?r.get_distinct_id():void 0,w=n==null?void 0:n.trim(),E=await fetch("/api/support/tickets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:yx,message:b,contactEmail:w||void 0,metadata:{posthogSessionId:x??void 0,posthogDistinctId:C??void 0,appVersion:"0.10.9",appEnvironment:"production",pageUrl:window.location.href,userAgent:navigator.userAgent,submittedAt:new Date().toISOString()}})});if(!E.ok){const A=await V2e(E);throw new Error(A)}r==null||r.capture("support_ticket_submitted",{ticket_type:yx,has_posthog_session_id:!!x}),ct.success("Feedback sent",{description:"Thanks for sharing this."}),c(),t()}catch(x){const C=x instanceof Error?x.message:"Failed to send message";r==null||r.capture("support_ticket_submit_failed",{ticket_type:yx,error:C}),F2e.error("Failed to submit support ticket:",C),ct.error("Could not send feedback",{description:C})}finally{a(!1)}}},[n,o,i,t,r,c]),p=h.useCallback(b=>{b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),f())},[f]),m=jP-i.length,g=o||i.trim().length===0;return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&u(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[480px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Send feedback"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",disabled:o,children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsx("p",{className:"text-sm text-content-subtle",children:"Tell us what happened or what we can improve."}),y.jsxs("div",{className:"space-y-2",children:[y.jsx("label",{htmlFor:"support-ticket-message",className:"text-xs font-medium text-content-muted",children:"Your feedback"}),y.jsx("textarea",{id:"support-ticket-message",value:i,onChange:b=>s(b.target.value),onKeyDown:p,maxLength:jP,rows:7,disabled:o,placeholder:"What happened?",className:"w-full resize-none rounded-md border border-divider bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),y.jsxs("div",{className:"flex justify-between text-xs text-content-subtle",children:[y.jsx("span",{children:"Context details are included automatically."}),y.jsx("span",{children:m})]})]}),y.jsx("button",{onClick:f,disabled:g,className:"flex w-full items-center justify-center gap-2 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:o?y.jsxs(y.Fragment,{children:[y.jsx(Ua,{className:"h-4 w-4 animate-spin",weight:"bold"}),y.jsx("span",{children:"Sending..."})]}):y.jsx("span",{children:"Send feedback"})})]})})]})})},B2e=Mt("ProfileAvatar"),z2e=(e,t)=>{const n=(e??"").trim();if(n){const i=n.split(/\s+/).filter(Boolean);return i.length>=2?(i[0][0]+i[i.length-1][0]).toUpperCase():i[0].slice(0,2).toUpperCase()}const r=(t??"").split("@")[0]??"";if(r){const i=r.split(/[._\-+]/).filter(Boolean);return i.length>=2?(i[0][0]+i[1][0]).toUpperCase():r.slice(0,2).toUpperCase()}return""},U2e=({className:e=""})=>{const{name:t,email:n}=ke(p$),[r,i]=h.useState(!1),[s,o]=h.useState(!1),[a,c]=h.useState(!1),u=z2e(t,n);if(!u)return null;const f=(t==null?void 0:t.trim())||null,p=(n==null?void 0:n.trim())||null,m=async()=>{c(!0);try{const g=await fetch("/api/auth/logout",{method:"POST",credentials:"same-origin"});if(!g.ok)throw new Error(`Logout failed: ${g.status}`)}catch(g){B2e.warn("Logout request failed",g),ct.error("Could not log out. Please try again."),c(!1);return}window.location.reload()};return y.jsxs(y.Fragment,{children:[y.jsxs(Fo,{open:r,onOpenChange:i,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{type:"button","aria-label":"Account",className:`flex h-6 w-6 shrink-0 select-none items-center justify-center rounded-full border border-main-border bg-main-input text-[10px] font-semibold leading-none text-content-muted transition-colors hover:text-content ${e}`,children:u})}),y.jsx(Oo,{children:y.jsxs(Vo,{className:"z-[60] min-w-[180px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:6,align:"end",children:[f||p?y.jsxs("div",{className:"border-b border-main-border px-3 py-2",children:[f?y.jsx("div",{className:"truncate text-xs font-medium text-content",children:f}):null,p?y.jsx("div",{className:"truncate text-[11px] text-content-muted",children:p}):null]}):null,y.jsxs("button",{type:"button",onClick:()=>{i(!1),o(!0)},className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input",children:[y.jsx(LI,{className:"h-3.5 w-3.5",weight:"bold"}),"Support & feedback"]}),y.jsxs("button",{type:"button",onClick:m,disabled:a,className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[y.jsx(yG,{className:"h-3.5 w-3.5",weight:"bold"}),a?"Logging out…":"Log out"]})]})})]}),y.jsx(H2e,{isOpen:s,onClose:()=>o(!1),contactEmail:n??void 0})]})},Ut=Mt("ElementInspector"),Z2e=({chatMessages:e,setChatMessages:t,onClose:n})=>{const[r,i]=Vn(Ui),s=ke(Ad),[o]=Vn(U1),{undoLastChange:a,isUndoing:c}=Qie(),{status:u,fetchStatus:f}=q1(),m=ke(Qs).gitUi.isEnabled,g=m?(u==null?void 0:u.canUndo)??!1:!1,b=h.useCallback(async()=>{if(!s||!r)return;await new Promise(E=>requestAnimationFrame(E)),Ut.debug("Refreshing element styles for:",r.tagName);const w=await s.reSelectElement(ND(r));if(w){s.setCurrentElement(w);const E=s.getComputedStyles();s.showSelectionOverlay(w),VD("style_refresh"),i({...r,computedStyles:E})}else Ut.warn("Could not find element for refresh:",r.xpath)},[s,r,i]),x=h.useCallback(async()=>{if(!(o!=null&&o.canUndo()))return!1;const w=await o.undo();return w.ok?(await b(),!0):(Ut.error("Failed to undo:",w.error.message),!1)},[o,b]),C=h.useCallback(async w=>{var A;if(!m||!g||!await a((T,M,I)=>{w?w(T,M,I):T==="success"?ct.success(M,{description:I}):T==="info"?ct.message(M,{description:I}):(I&&Ut.error(`${M}:`,I),ct.error(M))}))return!1;if(await f(),(s==null?void 0:s.type)==="iframe"&&"forceReload"in s){Ut.info("Force reloading iframe after git undo");try{await((A=s.forceReload)==null?void 0:A.call(s))}catch(T){return Ut.error("Iframe reload failed, but git undo succeeded:",T),w==null||w("info","Changes reverted successfully","Please refresh the page to see the updated preview"),!0}}return await b(),!0},[b,g,m,a,f,s]);return y.jsxs("div",{className:"relative flex h-full w-96 cursor-auto flex-col overflow-hidden bg-main font-main shadow-2xl scrollbar-hide","data-cy":"element-inspector",children:[y.jsx(U2e,{className:"absolute right-3 top-2 z-20"}),y.jsx(j2e,{onUndo:C,isUndoing:c,onClose:n}),y.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:y.jsx(W2e,{chatMessages:e,setChatMessages:t,handleUndo:x,refreshElementStyles:b,fetchStatus:f})})]})},W2e=({chatMessages:e,setChatMessages:t,handleUndo:n,refreshElementStyles:r,fetchStatus:i})=>{const s=bs(),[o,a]=Vn(Ui),c=ke(Ad),[u,f]=Vn(ji),p=bc(),m=ke(xp),g=ke(hs),b=ke(wc),x=ke(eo),C=h.useRef(x);C.current=x;const w=h.useMemo(()=>Fie(u,g),[u,g]),E=h.useMemo(()=>{if(!rh(g))return null;const{sessionId:Se,variantId:He}=g;for(const dt of[b==null?void 0:b.left,b==null?void 0:b.right])if(dt&&dt.sessionId===Se&&dt.variantId===He)return dt.label;if(x.active){const dt=x.variants.find(Ze=>Ze.workItemId===He);if(dt)return dt.label}return"Direction"},[g,b,x]),A=ke(F8),[T,M]=Vn(U1);h.useEffect(()=>{if(!c)return;T&&T.destroy();const Se=new zJ(c,A);return M(Se),window.manipulationService=Se,()=>{Se.destroy(),M(null),delete window.manipulationService}},[c,A,M]);const[I,P]=h.useState(null),[S,D]=h.useState(0),R=Be(m$),L=Array.from(u.values()).filter(Se=>Se.status==="pending").length,[j,O]=Vn(ree),[H,B]=h.useState({}),[Z,K]=h.useState(0),q=h.useRef(null),Q=h.useRef(null),F=h.useRef(null),[V,W]=h.useState(0),N=h.useRef({}),z=h.useRef(!1),ee=h.useCallback(Se=>{const He=C.current;He.active&&He.sessionId===Se.sessionId&&$A(Se,He.variants,N.current),z.current=!1,F.current=Se,W(dt=>dt+1)},[]),te=h.useCallback(()=>{F.current!==null&&(F.current=null,W(Se=>Se+1))},[]),re=h.useCallback(Se=>{Q.current=Se,K(He=>He+1)},[]),G=h.useCallback(()=>{const Se=Q.current;Q.current=null,te(),K(He=>He+1),Se&&(Se.changeIds.length>0&&T&&Se.changeIds.forEach(He=>{T.removeTrackedChangeById(He)}),Se.commentIds.length>0&&f(He=>{if(He.size===0)return He;const dt=(m==null?void 0:m.current)??null;if(dt){const Kt=Se.commentIds.map(St=>He.get(St)).filter(St=>St!=null);Vu(dt,Kt)}const Ze=new Map(He);return Se.commentIds.forEach(Kt=>{Ze.delete(Kt)}),Ze}))},[T,f,m,te]),X=h.useCallback(()=>{Q.current=null,te(),K(Se=>Se+1)},[te]),{modifyWithAgent:de,cancelModification:ve,isModifying:we}=pte(),Fe=ke(w$),Te=ke(wp),je=ke(W1),nt=ke(z8),{sendChanges:yt,sendChatMessage:et}=Q$(),{status:ye,resetStatus:Ye}=Gie(),$t=h.useMemo(()=>Tie(ye),[ye]),Tt=ke(B8),{onRoundStarted:Nt,onProgressSteps:yn,onAssistantChunk:nn,onRoundCompleted:he,onRoundFailed:be,onRoundCanceled:We,getActiveAssistantMessageId:ot,getCancellationMessage:lt,setPhase:Vt}=Xie({setChatMessages:t,isMCPSession:Te}),Gt=ke(Js),J=Gt==="comment",Y=ke(Qs).generativeControls.isEnabled,se=ke(Iv),ce=ke(sV),le=Be(lV),ge=Be(aV),Ce=h.useMemo(()=>wie(se,ce),[se,ce]),$e=Be(j8),ut=ke(uc),it=ke(hd),{startRound:Zt,resetPhase:De}=Zie({mcpStatus:ye,isPublishing:j,isMCPSession:Te,setIsPublishing:O,fetchStatus:i,refreshElementStyles:r,getActiveAssistantMessageId:ot,onProgressSteps:yn,onRoundCompleted:he,setSessionUxPhase:Vt,clearQueuedPendingSnapshot:G});h.useEffect(()=>{if(!Te||!j)return;const Se=F.current;if(!Se)return;if(x.active&&x.sessionId===Se.sessionId)z.current=!0;else{if(!z.current)return;X(),O(!1),De(),Vt("idle");const rn=ot();rn&&be({assistantMessageId:rn,error:"Static preview variant refinement was interrupted."});return}const dt=N.current,Ze=Oie(Se,x.variants,dt);if(Ze.status==="pending")return;$A(Se,x.variants,dt);const Kt=Se.variantIds.length>1,St=ot();if(Ze.status==="succeeded"){G(),O(!1),De(),Vt("idle"),St&&he({assistantMessageId:St,finalMessage:Kt?"Static preview variants refined.":"Static preview variant refined."});return}if(X(),O(!1),De(),Vt("idle"),St){let rn;Ze.status==="cancelled"?rn="Static preview variant refinement was cancelled.":Ze.errorCode?rn=`Static preview variant refinement failed (${Ze.errorCode}).`:rn="Static preview variant refinement failed.",be({assistantMessageId:St,error:rn})}},[G,X,ot,Te,j,he,be,De,O,Vt,V,x]),h.useEffect(()=>{o&&(Te||(q.current=null))},[o==null?void 0:o.xpath,Te]);const at=we||j,Ne=Fe,Rt=$ie((o==null?void 0:o.computedStyles)||{});h.useEffect(()=>{var Kt,St;if(!o||!c||c.type!=="iframe")return;let Se=!1;const He=ND(o),dt=((St=(Kt=o.filePaths)==null?void 0:Kt[0])==null?void 0:St.filePath)||void 0;return(async()=>{const rn=await c.reSelectElement(He);if(Se||!rn)return;const wn=Ga();c.injectRivetId(rn,wn);const Un=c.createElementIdentifier(rn);Un.rivetId=wn,Un.filePath=dt,P(Un)})(),()=>{Se=!0}},[o,c]);const bn=ke(z1);h.useEffect(()=>{if(!T)return;const Se=A.getChangeCount();return D(Se),R(Se),A.onChange(()=>{const dt=A.getChangeCount();D(dt),R(dt)})},[A,T,R]);const en=!!o&&!J;h.useEffect(()=>{var dt;const Se=Ze=>{if(!((Ze.metaKey||Ze.ctrlKey)&&Ze.key.toLowerCase()==="z"&&!Ze.shiftKey)||bn.isEditing)return;const St=document.activeElement;St&&(St.tagName==="INPUT"||St.tagName==="TEXTAREA"||St.tagName==="SELECT"||St.getAttribute("contenteditable")==="true")&&!en||(Ze.preventDefault(),Ut.debug("Undo shortcut triggered"),s==null||s.capture("undo"),n())},He=(dt=m==null?void 0:m.current)==null?void 0:dt.contentDocument;return window.addEventListener("keydown",Se),He==null||He.addEventListener("keydown",Se),()=>{window.removeEventListener("keydown",Se),He==null||He.removeEventListener("keydown",Se)}},[en,n,bn.isEditing,m]);const qt=Se=>{Se!==Gt&&(s==null||s.capture("inspector_tab_changed",{from_tab:Gt,to_tab:Se})),$e(Se)};X8({shortcuts:[{key:"1",handler:()=>{Ut.debug("Switching to Styles tab (1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",handler:()=>{Ut.debug("Switching to Chat tab (2)"),qt("comment")},description:"Switch to Chat tab"},{key:"1",metaKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Cmd+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"1",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Ctrl+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",metaKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Cmd+2)"),qt("comment")},description:"Switch to Chat tab"},{key:"2",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Ctrl+2)"),qt("comment")},description:"Switch to Chat tab"}]});const pr=h.useCallback(async()=>{var He;if(at)return;zte(),Vu((m==null?void 0:m.current)??null,u.values());const Se=p.get(qa);Se&&(await a1(Se.diff),p.set(qa,null));for(const dt of u.values()){const Ze=(He=dt.finalizedVariant)==null?void 0:He.codeDiff;Ze&&await a1(Ze)}T==null||T.clear(),f(new Map),le()},[at,T,f,m,u,p,le]),Mn=h.useCallback(async()=>{const He=Hie(Te?u:w,T,Ce);if(!He)return;X();const{pendingComments:dt,styleChanges:Ze,textChanges:Kt,pendingSnapshot:St,applyPointers:rn,hasComments:wn,hasDesignChanges:Un,hasInterfaceChanges:bt}=He;if(s==null||s.capture("apply",{comment_count:dt.length,design_edit_count:Ze.length+Kt.length,interface_change_count:He.interfaceChanges.length,has_comments:wn,has_design_changes:Un,has_interface_changes:bt}),Te){$e("comment"),Ye(),O(!0),Zt();const Yt=$b(rn),{assistantMessageId:on}=Nt({userMessage:Yt,startPhase:"starting"});if(Ut.debug("[MCP] new apply round — asstMsgId:",on),re(St),!wn&&!Un&&bt){const Si=await et(Iw(Ce));if(Si.cancelled)return;Si.success||(X(),ct.error(Si.error||"Failed to send changes"),be({assistantMessageId:on,error:Si.error||"Failed to send changes"}),O(!1),De());return}const Bn=await yt();if(Bn.cancelled)return;if(!Bn.success){X(),ct.error(Bn.error||"Failed to send changes"),be({assistantMessageId:on,error:Bn.error||"Failed to send changes"}),O(!1),De();return}bt&&await et(Iw(Ce)),(Bn.changeIdsToClear||Bn.commentIdsToClear)&&re({...St,commentIds:Bn.commentIdsToClear??St.commentIds,changeIds:Bn.changeIdsToClear??St.changeIds}),Bn.staticPreviewVariantIds&&Bn.staticPreviewVariantIds.length>0&&Bn.staticPreviewSessionId&&ee({sessionId:Bn.staticPreviewSessionId,variantIds:Bn.staticPreviewVariantIds});return}$e("comment"),O(!0);const Rn=Bie(He),Lt=zie(He),sr=$b(rn),{assistantMessageId:Xn}=Nt({userMessage:sr,startPhase:"applying"});re(St);const Tc=dt.flatMap(Yt=>Yt.images??[]),Gi=Uie();Ut.debug("Calling modifyWithAgent");let _s=!1;try{await de({instruction:Rn,elements:Array.from(Lt.values()),images:Tc.length>0?Tc:void 0,sessionId:q.current??void 0},{onProgress:Yt=>{if(Gi.recordActivity(),!Yt.startsWith("Agent:")){const on=Yt.match(/^\[([^\]]+)\]/);on&&Gi.recordToolStart(on[1])}},onChunk:Yt=>{Gi.recordActivity(),Gi.recordReasoningChunk(),nn({content:Yt,assistantMessageId:Xn})},onComplete:async Yt=>{var Fp;_s=!0;const on=Gi.finalize();Ut.debug(`modifyWithAgent completed in ${on.agentExecutionDuration}ms`);const Bn=DA(Yt.changes,Yt.filesModified);if(he({assistantMessageId:Xn,finalMessage:Bn}),Yt.sessionId&&(q.current=Yt.sessionId),G(),Un){Ut.debug("Refreshing styles and status");try{await r(),await i()}catch(io){Ut.warn("Style/status refresh failed:",io)}}wn&&Ut.debug("Sent pending comments were cleared after completion."),bt&&le();const Si=Date.now();if((c==null?void 0:c.type)==="iframe"&&"forceReload"in c){Ut.debug("Force reloading iframe");try{await((Fp=c.forceReload)==null?void 0:Fp.call(c))}catch(io){Ut.warn("Iframe reload failed:",io)}}const Wv=Date.now();s==null||s.capture("code_modification",{success:!0,source:"apply",instruction_length:Rn.length,element_count:Lt.size,modification_time_ms:on.agentExecutionDuration}),s==null||s.capture("agent_apply_session",{success:!0,env:"production",total_duration_ms:Gi.elapsed(),agent_execution_duration_ms:on.agentExecutionDuration,tool_execution_duration_ms:on.totalToolDuration,model_reasoning_duration_ms:on.agentExecutionDuration-on.totalToolDuration,time_to_first_message_ms:on.timeToFirstMessage,post_processing_duration_ms:Si-on.agentEndTime,iframe_reload_duration_ms:Wv-Si,model:Yt.model,tool_counts:on.toolCounts,total_tool_calls:Object.values(on.toolCounts).reduce((io,Op)=>io+Op,0),reasoning_chunk_count:on.reasoningChunkCount,element_count:Lt.size,comment_count:dt.length,design_edit_count:S,instruction_length:Rn.length,session_id:Yt.sessionId,server_ttfm_ms:Yt.ttfmMs}),O(!1),De()},onError:async Yt=>{if(_s=!0,Ut.error("Error in modifyWithAgent:",Yt),be({assistantMessageId:Xn,error:Yt}),X(),s==null||s.capture("code_modification",{success:!1,source:"apply",instruction_length:Rn.length,element_count:Lt.size,error_message:Yt}),s==null||s.capture("agent_apply_session",{success:!1,env:"production",total_duration_ms:Gi.elapsed(),error_message:Yt,element_count:Lt.size,instruction_length:Rn.length}),Un)try{await(T==null?void 0:T.clearInlineChanges())}catch(on){Ut.warn("Failed to clear inline changes:",on)}gm(Yt)?vm(Yt):ct.error("Failed to apply changes"),O(!1),De()},onCanceled:()=>{_s=!0,O(!1),De(),X()}})}catch(Yt){_s=!0,Ut.error("Unexpected error in handleApplyAll:",Yt),X();const on=Yt instanceof Error?Yt.message:"An unexpected error occurred";be({assistantMessageId:Xn,error:on}),gm(on)?vm(on):ct.error("Failed to apply changes"),O(!1),De()}finally{_s||(Ut.warn("modifyWithAgent returned without triggering onComplete or onError"),X(),be({assistantMessageId:Xn,error:"Agent request failed to initialize or timed out without feedback."}),ct.error("Failed to apply changes"),O(!1),De())}},[w,u,T,c,de,r,i,S,s,Te,yt,et,Ye,Nt,nn,he,be,$e,Zt,De,O,re,G,X,Ce,le,ee]);h.useEffect(()=>{const Se=He=>{(He.metaKey||He.ctrlKey)&&He.key==="Enter"&&(ut||(L>0||S>0||Ce.length>0)&&!j&&!at&&(He.preventDefault(),Ut.debug("Apply all shortcut triggered (Cmd/Ctrl+Enter)"),Mn()))};return window.addEventListener("keydown",Se),()=>window.removeEventListener("keydown",Se)},[L,S,Ce,j,at,ut,Mn]);const ir=h.useCallback(async(Se,He)=>{var Kt;if(!T||!I||!c||c.type!=="iframe")return;const Ze=((Kt=Rt[Se])==null?void 0:Kt.type)==="range"?(parseFloat(He)/100).toString():He;await T.previewStyleChange(I,Se,Ze)},[T,I,c,Rt]),cn=h.useCallback(async(Se,He,dt)=>{var wn;const Ze=He;if(!Ze||!T||!I||!o||!c||c.type!=="iframe")return;const St=((wn=Rt[Se])==null?void 0:wn.type)==="range"?(parseFloat(Ze)/100).toString():Ze,rn=await T.applyStyleChange(I,o,Se,St,dt);if(rn.ok){const Un=await c.getComputedStylesForElement(I);Un.ok&&a({...o,computedStyles:Un.value}),B(Rn=>{const Lt={...Rn};return delete Lt[Se],Lt});const bt=Mw.find(Rn=>Rn.properties.some(Lt=>Lt.key===Se));s==null||s.capture("design_property_changed",{property:Se,category:bt==null?void 0:bt.value})}else Ut.error("Failed to apply style:",rn.error.message),ct.error("Failed to apply style")},[T,I,o,c,Rt,B,a,s]),Hn=h.useCallback(async Se=>{T&&await T.transaction(Se)},[T]),Ss=(Se,He)=>{B(dt=>({...dt,[Se]:He}))},Hd=(Se,He)=>{const dt=He.replace("%","").trim();if(dt===""){B(St=>({...St,[Se]:""}));return}const Ze=parseFloat(dt);if(Number.isNaN(Ze))return;const Kt=Math.max(0,Math.min(100,Ze));B(St=>({...St,[Se]:Kt.toString()}))},Bv=Se=>{B(He=>{const dt={...He};return delete dt[Se],dt})},zv=h.useCallback(async()=>{if(!T)return;const Se=await T.redo();Se.ok?await r():Ut.error("Failed to redo:",Se.error.message)},[T,r]),Uv=h.useCallback(()=>{const Se=lt();Te&&je==="embedded"&&fetch("/api/agent/stop",{method:"POST",headers:nt?{"x-rivet-queue-token":nt}:void 0}).catch(He=>{Ut.warn("Failed to stop embedded agent run:",He)}),ve(),O(!1),De(),X(),We({cancellationMessage:Se})},[ve,O,De,X,We,lt,Te,je,nt]),ro=h.useCallback(async(Se,He)=>{Ye();const dt=Date.now();X();const Ze=Array.from(u.values()).filter(Lt=>Lt.status==="pending"),Kt=Ze.length>0,St=Ze.map(Lt=>({id:Lt.id,instruction:Lt.instruction})),rn=jD({pendingComments:St,styleChanges:[],textChanges:[],includeComments:Kt,includeChanges:!1});s==null||s.capture("chat",{message_length:Se.length,has_images:!!(He!=null&&He.length),image_count:(He==null?void 0:He.length)??0,has_pending_comments:Kt,pending_comment_count:Ze.length,has_selected_element:!!o});const wn=Kt?FD(Ze):Se,Un=Kt?LD(Ze,[],[]):[],bt=Kt&&Un.length>0?$b(Un):Se,{assistantMessageId:Rn}=Nt({userMessage:bt,images:He,startPhase:Te?"starting":"applying"});rn.commentIds.length>0&&re(rn);try{if(Te){Ye(),O(!0),Zt();const Lt=await et(wn,He);if(Lt.cancelled)return;Lt.success||(X(),be({assistantMessageId:Rn,error:Lt.error||"Failed to send to Claude Code"}),O(!1),De())}else if(Ne){const Lt=o?[o]:[];await de({instruction:wn,elements:Lt,images:He,sessionId:q.current??void 0},{onProgress:()=>{},onChunk:sr=>{nn({content:sr,assistantMessageId:Rn})},onComplete:async({sessionId:sr,changes:Xn,filesModified:Tc})=>{var _s;const Gi=DA(Xn,Tc);if(he({assistantMessageId:Rn,finalMessage:Gi}),G(),s==null||s.capture("code_modification",{success:!0,source:"chat",instruction_length:wn.length,element_count:Lt.length,modification_time_ms:Date.now()-dt}),sr&&(q.current=sr),Kt&&Ut.debug("Sent pending comments were cleared after completion."),(c==null?void 0:c.type)==="iframe"&&"forceReload"in c)try{await((_s=c.forceReload)==null?void 0:_s.call(c))}catch(Yt){Ut.warn("Iframe reload after agent modification failed:",Yt)}r()},onError:sr=>{X(),be({assistantMessageId:Rn,error:sr}),s==null||s.capture("code_modification",{success:!1,source:"chat",instruction_length:wn.length,element_count:Lt.length,error_message:sr,modification_time_ms:Date.now()-dt}),Ut.error("Code modification error details:",sr),gm(sr)?vm(sr):ct.error("Code Modification Error")},onCanceled:()=>{O(!1),De(),X()}})}else Ut.error("Chat mode not supported"),ct.error("Chat mode not supported")}catch(Lt){Ut.error("Error with streaming request:",Lt);const sr=Lt instanceof Error?Lt.message:"An unexpected error occurred.";X(),O(!1),De(),be({assistantMessageId:Rn,error:sr}),gm(sr)?vm(sr):ct.error("Failed to generate AI response")}},[Ye,u,T,s,o,Te,et,Ne,de,c,r,Nt,nn,he,be,Zt,De,O,re,G,X]),Wi=h.useMemo(()=>{const Se=Array.from(w.values()).filter(bt=>bt.status==="pending"),He=(T==null?void 0:T.getStyleChanges())??[],dt=(T==null?void 0:T.getTextChanges())??[],Ze=He.map(bt=>({id:bt.id,key:rc(bt),property:String(bt.property),newValue:bt.newValue,timestamp:bt.timestamp})),Kt=dt.map(bt=>({id:bt.id,key:rc(bt),oldText:bt.oldText,newText:bt.newText,timestamp:bt.timestamp})),St=jie(Se.map(bt=>({id:bt.id,instruction:bt.instruction,finalizedVariant:bt.finalizedVariant,styleVariants:bt.styleVariants,selectedVariantIndex:bt.selectedVariantIndex,variantGenerationStatus:bt.variantGenerationStatus,requestedVariantCount:bt.requestedVariantCount})),Ze,Kt);for(const bt of Ce)St.push({id:bt.id,kind:"interface",detail:DD(bt)});const rn=Q.current;if(!at||!rn)return St;const wn=new Set(rn.commentIds),Un=new Map;return Ze.forEach(bt=>{Un.set(bt.id,bt.key)}),Kt.forEach(bt=>{Un.set(bt.id,bt.key)}),rn.changeIds.forEach(bt=>{const Rn=Un.get(bt);Rn&&wn.add(Rn)}),St.filter(bt=>!wn.has(bt.id))},[w,S,T,at,Z,Ce]),Ac=h.useCallback(async Se=>{if(Se.kind==="interface"){ge({controlId:Se.id,value:void 0});return}if(Se.kind==="comment"){f(Kt=>{const St=Kt.get(Se.id),rn=(m==null?void 0:m.current)??null;rn&&(St==null?void 0:St.previewBaselineStyle)!==void 0&&Vu(rn,[St]);const wn=new Map(Kt);return wn.delete(Se.id),wn});return}if(!T)return;const dt=T.getChanges().find(Kt=>rc(Kt)===Se.id);if(!dt){Ut.warn("No tracked change for pending row",Se.id);return}const Ze=await T.revertSpecificChange(dt);if(!Ze.ok){Ut.error("revertSpecificChange failed:",Ze.error.message),ct.error("Could not revert change");return}await r()},[T,f,r,m,ge]),Uo=Te?$t||(j&&(ye==null?void 0:ye.status)!=="APPLYING"?Eie:j?Cie:null):null,Lp=y.jsx(J0e,{chatMessages:e,statusHint:Uo,handleChatSend:ro,handleStop:Uv,isProcessing:at,pendingChangeRows:Wi,onRemovePendingChange:Ac,onApplyPendingChanges:Mn,onClearPendingChanges:pr,disableInputWhileProcessing:je!=="embedded",showModelPicker:je!=="embedded"}),jp=y.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center",children:[y.jsx("p",{className:"text-sm text-content-subtle",children:"Select an element to edit, or leave a comment on the page."}),Uo&&y.jsx("p",{className:"mt-2 text-xs text-content-subtle",children:Uo})]});return(()=>{const Se=_ie({isMCPSession:Te,isChatOpen:J,hasSelectedElement:!!o,isVariantsPanelOpen:it,hasPendingChanges:Wi.length>0,changeCount:S,isPublishing:j,isProcessing:at,hasStatusHint:!!Uo,shouldUseAgentChat:je==="embedded"}),He=o?y.jsx(fye,{propertyCategories:Mw,formattedComputedStyles:Rt,pendingChanges:H,handlePendingCssChange:Ss,handlePendingPercentageChange:Hd,applyPropertyChange:cn,previewPropertyChange:ir,performTransaction:Hn,handleBlur:Bv},o.xpath):null,dt=Y&&Gt==="edit"?y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[y.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto scrollbar-hide",children:[y.jsx(Vye,{}),Se.showDesignPanel?He:null]}),Wi.length>0?y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-3 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}):null,y.jsx(Wye,{})]}):Gt==="edit"&&Se.showDesignPanel&&He?He:it?y.jsx(Qee,{}):Se.showChatPanel?Lp:Se.showDesignPanel?He:Se.showMCPEmptyState?jp:null,Ze=Wi.length;return y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[E&&!it?y.jsx("div",{className:"flex flex-shrink-0 items-center border-b border-main-border bg-main-light px-4 py-1.5 text-xs text-content-subtle",children:y.jsxs("span",{className:"truncate",children:["Editing"," ",y.jsx("span",{className:"font-medium text-content",children:E})]})}):null,dt,Se.showExternalPendingChanges&&y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-4 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}),Se.showExternalStatusHint&&Uo&&y.jsx("div",{className:`flex-shrink-0 px-4 py-2 ${Wi.length===0?"border-t border-main-border":""}`,children:y.jsx("p",{className:"text-center text-xs text-content-subtle",children:Uo})}),(Se.showActionBar||Y&&Gt==="edit"&&Wi.length>0)&&y.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-main-border bg-main-light px-4 py-3",children:[y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:n,disabled:!(T!=null&&T.canUndo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Undo (Cmd+Z)",children:y.jsx(Fh,{className:"h-4 w-4"})}),y.jsx("button",{onClick:zv,disabled:!(T!=null&&T.canRedo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Redo (Cmd+Shift+Z)",children:y.jsx(uG,{className:"h-4 w-4"})})]}),y.jsx("button",{onClick:Mn,disabled:j||at,className:"rounded border border-primary px-3 py-1 text-xs font-medium text-gray-300 hover:bg-primary-hover disabled:cursor-not-allowed disabled:opacity-30",title:Te?`Send ${Ze||"pending"} changes to ${Tt||"Claude Code"}`:"Apply all pending changes (⌘↵)","data-cy":"inspector-apply-button",children:Aie({isMCPSession:Te,isApplying:j||at,pendingChangeCount:Ze})})]})]})})()},G2e=Mt("useServerConfig"),q2e=()=>{const[e,t]=h.useState(null),[n,r]=h.useState(!0),[i,s]=h.useState(null),o=h.useCallback(async()=>{var a;try{r(!0),s(null);const c=await fetch("/api/health");if(!c.ok)throw new Error(`Failed to fetch config: ${c.status}`);const u=await c.json();if(!u.framework)throw new Error("Server did not return framework information");const f={userPort:((a=u.ports)==null?void 0:a.userDevServer)||3e3,framework:u.framework};return t(f),f}catch(c){const u=c instanceof Error?c.message:"Failed to fetch server config";throw s(u),G2e.warn("Error fetching server config:",c),c}finally{r(!1)}},[]);return{config:e,fetchConfig:o,isLoading:n,error:i}},K2e="data:image/svg+xml,%3csvg%20width='453'%20height='416'%20viewBox='0%200%20453%20416'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23clip0_1326_108)'%3e%3cpath%20d='M186.07%2025.5539C186.07%2011.4409%20197.511%200%20211.624%200H335.5C400.393%200%20453%2052.6065%20453%20117.5C453%20182.393%20400.393%20235%20335.5%20235H216.639C199.756%20235%20186.07%20221.314%20186.07%20204.431C186.07%20186.743%20198.071%20169.863%20215.299%20165.853C225.291%20163.528%20238.671%20160.53%20256.58%20156.667C258.587%20156.234%20260.54%20155.796%20262.442%20155.354C307.627%20144.861%20299.146%20103.217%20256.58%2084.7815C234.082%2075.0381%20218.731%2068.1115%20208.265%2063.1881C194.851%2056.8779%20186.07%2040.378%20186.07%2025.5539Z'%20fill='white'/%3e%3cpath%20d='M381.709%20415.715C329.789%20415.715%20287.699%20373.625%20287.699%20321.705V314.306C287.699%20288.346%20308.744%20267.301%20334.704%20267.301C386.624%20267.301%20428.714%20309.391%20428.714%20361.311V368.71C428.714%20394.67%20407.669%20415.715%20381.709%20415.715Z'%20fill='white'/%3e%3cpath%20d='M0%2073.5927C0%2033.1632%2032.7745%200.388672%2073.2039%200.388672C113.633%200.388672%20146.408%2033.1632%20146.408%2073.5926V338.795C146.408%20379.225%20113.633%20411.999%2073.2039%20411.999C32.7745%20411.999%200%20379.225%200%20338.795V73.5927Z'%20fill='white'/%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='clip0_1326_108'%3e%3crect%20width='453'%20height='416'%20fill='white'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",Lm=(e,t)=>y.jsxs("div",{className:"flex flex-row items-center gap-2",children:[y.jsx("span",{children:e}),t?y.jsx("span",{className:"rounded bg-white/15 px-1.5 py-0.5 text-[10px] leading-none font-bold",children:t}):null]}),Y2e={type:"spring",duration:.3,bounce:0},X2e=({mode:e,onModeChange:t,isLoading:n=!1,disabled:r=!1})=>{const[i,s]=h.useState(!1),o=ke(ji),a=ke(m$),[c,u]=Vn(bp);ke(Ui);const f=Be(Ui),p=Be(Js),m=Be(E$),g=ke(hd),b=Be(hd),x=ke(eo),C=e!=="view"||i||g,E=Array.from(o.values()).filter(P=>P.status==="pending").length+a,A=()=>{c?u(!1):(u(!0),g||(f(null),p("comment"),m(P=>P+1)))},T=()=>{g||(b(!0),u(!0),p("comment"),vt.capture("variants_panel.opened",{source:"control_bar",hasActiveSession:x.active}))},M=c?"Close panel":"Open panel",I=(P,S,D,R,L)=>{const j=r?"Disconnected":S,O=e===P&&!g;return y.jsx(Fi,{label:Lm(j,r?void 0:D),disabled:!C,children:y.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),b(!1),u(!0),t(P)},disabled:r,className:`rounded-md p-2 transition-colors ${O?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":L,children:R})})};return y.jsxs(mn.div,{className:"z-ui-primary absolute right-6 bottom-6",initial:{y:100,opacity:0},animate:{y:n?100:0,opacity:n?0:1},transition:{duration:.6,ease:"easeOut",delay:n?0:.3},children:[E>0&&!C&&!g&&y.jsx(mn.span,{className:"bg-primary pointer-events-none absolute -top-1 -right-1 z-10 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[9px] leading-none font-bold text-white",animate:{opacity:1},transition:{duration:.15,delay:.2},children:E>9?"9+":E}),y.jsxs(mn.div,{layout:!0,className:`border-primary/30 bg-main overflow-hidden border shadow-lg ${C?"":"cursor-pointer"}`,style:{borderRadius:C?10:9999},transition:Y2e,onClick:C?void 0:()=>t("comment"),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[y.jsx(mn.div,{className:"absolute flex items-center justify-center",style:{width:40,height:40,top:0,left:0},animate:{opacity:C?0:1},transition:C?{duration:0}:{duration:0,delay:.2},"aria-hidden":C,children:y.jsx("img",{src:K2e,alt:"Rivet",style:{width:16,height:16}})}),!C&&y.jsx("div",{style:{width:40,height:40}}),y.jsxs(mn.div,{className:"flex items-center gap-1 p-2",style:{position:C?"relative":"absolute",inset:0,pointerEvents:C?"auto":"none"},animate:{opacity:C?1:0},transition:C?{duration:0,delay:.22}:{duration:0},children:[y.jsx(Fi,{label:Lm(r?"Disconnected":"Explore",r?void 0:"E"),disabled:!C,children:y.jsxs("button",{type:"button",onClick:P=>{P.stopPropagation(),T()},disabled:r,className:`relative rounded-md p-2 transition-colors ${g?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-variants",children:[y.jsx(s8,{className:"h-5 w-5",weight:"bold"}),x.active&&!g&&y.jsx("span",{className:"bg-primary absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full","aria-label":"Active explore session"})]})}),I("edit","Refine","R",y.jsx(xG,{className:"h-5 w-5"}),"mode-design"),y.jsx("div",{className:"bg-primary/20 mx-1 h-4 w-px"}),y.jsx(Fi,{label:Lm(r?"Disconnected":M,r?void 0:"P"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),A()},disabled:r,className:`text-content hover:bg-main-input relative rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-panel",children:y.jsx(Oh,{className:"h-5 w-5",weight:"bold",style:c?{transform:"scaleX(-1)"}:void 0})})}),y.jsx(Fi,{label:Lm(r?"Disconnected":"Collapse",r?void 0:"X"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),t("view"),b(!1),u(!1),s(!1)},disabled:r,"aria-label":"Collapse",className:`text-content hover:bg-main-input rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"mode-view",children:y.jsx(Ho,{className:"h-5 w-5",weight:"bold"})})})]})]})]})},Q2e=async()=>{let e;try{e=await fetch("/api/mcp/status")}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}if(e.status===404||!(e.headers.get("content-type")??"").toLowerCase().includes("application/json"))return jm();if(!e.ok)return{isOk:!1,unavailableReason:"rivet_unreachable"};let n;try{n=await e.json()}catch{return jm()}const r=n.devServerHealth;return r?r.ownership==="none"?{isOk:!1,unavailableReason:"upstream_unreachable"}:r.isReachable===!0?{isOk:!0,unavailableReason:"upstream_unreachable"}:{isOk:!1,unavailableReason:r.reason==="rivet_unreachable"?"rivet_unreachable":"upstream_unreachable"}:jm()},jm=async()=>{try{const e=await fetch("/");return{isOk:e.status!==502&&e.status!==503,unavailableReason:"upstream_unreachable"}}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}},FP=Mt("usePreviewUpstreamHealth"),J2e=500,ebe=4e3,tbe=15e3,nbe=(e,t={})=>{const n=h.useRef(null),r=h.useRef(null),i=t.probeMsWhileDown??J2e,s=t.probeMsWhileUp??ebe,o=t.firstUnreachableCaptureAfterMs??tbe,a=t.rerunProbeImmediatelyOnVersion,c=t.skip??!1,[u,f]=h.useState(e==="static"),[p,m]=h.useState(0),[g,b]=h.useState(null),[x,C]=h.useState(0),[w,E]=h.useState(!1),[A,T]=h.useState(!1),[M,I]=h.useState(e==="static"?null:"upstream_unreachable");return h.useEffect(()=>{if(e==="static"){f(!0),b(null),C(0),E(!1),T(!0),I(null);return}if(c){f(!1),b(null),C(0),E(!1),T(!0),I("upstream_unreachable"),n.current=null;return}let P=!0;const S=Date.now();b(S),C(0),E(!1),f(!1),T(!1),I("upstream_unreachable");const D={current:!1},R={current:!1},L={current:!1},j={current:null},O={current:!1};let H=null;const B=()=>{L.current||(L.current=!0,P&&T(!0))},Z=()=>{H!==null&&(clearTimeout(H),H=null)},K=(Q,F)=>{Z(),H=setTimeout(F,Q)},q=async()=>{if(!P)return;C(N=>N+1);const{isOk:Q,unavailableReason:F}=await Q2e();if(!P)return;if(B(),Q){const N=!O.current;O.current=!0,f(!0),I(null),j.current=null,R.current=!1,E(!1),D.current?N&&(vt==null||vt.capture("preview_upstream_restored",{framework:e})):(D.current=!0,vt==null||vt.capture("preview_dev_server_ready",{framework:e,ready_after_ms:Date.now()-S})),K(s,q);return}const V=O.current;O.current=!1,f(!1),I(F),j.current===null&&(j.current=Date.now(),R.current=!1,E(!1)),V&&(vt==null||vt.capture("preview_upstream_lost",{framework:e}),m(N=>N+1),FP.warn("Preview upstream became unavailable after it was ready"));const W=Date.now()-j.current;W>=o&&!R.current&&(R.current=!0,E(!0),vt==null||vt.capture("preview_dev_server_unreachable",{framework:e,elapsed_ms:W}),FP.warn("Dev server did not become ready within timeout window")),K(i,q)};return n.current=()=>K(0,q),K(0,q),()=>{P=!1,n.current=null,Z()}},[e,i,s,o,c]),h.useEffect(()=>{var S;if(e==="static"||a===void 0)return;const P=r.current;r.current=a,P!==null&&P!==a&&((S=n.current)==null||S.call(n))},[e,a]),{isUpstreamReady:u,iframeRemountKey:p,probeStartedAt:g,probeAttemptCount:x,isFirstUnreachableWindowExceeded:w,initialProbeComplete:A,unavailableReason:M}};function rbe(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),r=n.createElement("base"),i=n.createElement("a");return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}const ibe=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function Va(e){const t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}let mu=null;function LV(e={}){return mu||(e.includeStyleProperties?(mu=e.includeStyleProperties,mu):(mu=Va(window.getComputedStyle(document.documentElement)),mu))}function T1(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function sbe(e){const t=T1(e,"border-left-width"),n=T1(e,"border-right-width");return e.clientWidth+t+n}function obe(e){const t=T1(e,"border-top-width"),n=T1(e,"border-bottom-width");return e.clientHeight+t+n}function jV(e,t={}){const n=t.width||sbe(e),r=t.height||obe(e);return{width:n,height:r}}function abe(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const hi=16384;function lbe(e){(e.width>hi||e.height>hi)&&(e.width>hi&&e.height>hi?e.width>e.height?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi):e.width>hi?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi))}function P1(e){return new Promise((t,n)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function cbe(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function ube(e,t,n){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${n}`),i.setAttribute("viewBox",`0 0 ${t} ${n}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),i.appendChild(s),s.appendChild(e),cbe(i)}const si=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||si(n,t)};function dbe(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function fbe(e,t){return LV(t).map(n=>{const r=e.getPropertyValue(n),i=e.getPropertyPriority(n);return`${n}: ${r}${i?" !important":""};`}).join(" ")}function hbe(e,t,n,r){const i=`.${e}:${t}`,s=n.cssText?dbe(n):fbe(n,r);return document.createTextNode(`${i}{${s}}`)}function OP(e,t,n,r){const i=window.getComputedStyle(e,n),s=i.getPropertyValue("content");if(s===""||s==="none")return;const o=ibe();try{t.className=`${t.className} ${o}`}catch{return}const a=document.createElement("style");a.appendChild(hbe(o,n,i,r)),t.appendChild(a)}function pbe(e,t,n){OP(e,t,":before",n),OP(e,t,":after",n)}const VP="application/font-woff",HP="image/jpeg",mbe={woff:VP,woff2:VP,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:HP,jpeg:HP,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function gbe(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function Pk(e){const t=gbe(e).toLowerCase();return mbe[t]||""}function vbe(e){return e.split(/,/)[1]}function E6(e){return e.search(/^(data:)/)!==-1}function ybe(e,t){return`data:${t};base64,${e}`}async function FV(e,t,n){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise((s,o)=>{const a=new FileReader;a.onerror=o,a.onloadend=()=>{try{s(n({res:r,result:a.result}))}catch(c){o(c)}},a.readAsDataURL(i)})}const bx={};function bbe(e,t,n){let r=e.replace(/\?.*/,"");return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function Ik(e,t,n){const r=bbe(e,t,n.includeQueryParams);if(bx[r]!=null)return bx[r];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let i;try{const s=await FV(e,n.fetchRequestInit,({res:o,result:a})=>(t||(t=o.headers.get("Content-Type")||""),vbe(a)));i=ybe(s,t)}catch(s){i=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;s&&(o=typeof s=="string"?s:s.message),o&&console.warn(o)}return bx[r]=i,i}async function xbe(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):P1(t)}async function wbe(e,t){if(e.currentSrc){const s=document.createElement("canvas"),o=s.getContext("2d");s.width=e.clientWidth,s.height=e.clientHeight,o==null||o.drawImage(e,0,0,s.width,s.height);const a=s.toDataURL();return P1(a)}const n=e.poster,r=Pk(n),i=await Ik(n,r,t);return P1(i)}async function kbe(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await Fv(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function Cbe(e,t){return si(e,HTMLCanvasElement)?xbe(e):si(e,HTMLVideoElement)?wbe(e,t):si(e,HTMLIFrameElement)?kbe(e,t):e.cloneNode(OV(e))}const Ebe=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",OV=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function Sbe(e,t,n){var r,i;if(OV(t))return t;let s=[];return Ebe(e)&&e.assignedNodes?s=Va(e.assignedNodes()):si(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?s=Va(e.contentDocument.body.childNodes):s=Va(((i=e.shadowRoot)!==null&&i!==void 0?i:e).childNodes),s.length===0||si(e,HTMLVideoElement)||await s.reduce((o,a)=>o.then(()=>Fv(a,n)).then(c=>{c&&t.appendChild(c)}),Promise.resolve()),t}function _be(e,t,n){const r=t.style;if(!r)return;const i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):LV(n).forEach(s=>{let o=i.getPropertyValue(s);s==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),si(e,HTMLIFrameElement)&&s==="display"&&o==="inline"&&(o="block"),s==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),r.setProperty(s,o,i.getPropertyPriority(s))})}function Abe(e,t){si(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),si(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function Tbe(e,t){if(si(e,HTMLSelectElement)){const r=Array.from(t.children).find(i=>e.value===i.getAttribute("value"));r&&r.setAttribute("selected","")}}function Pbe(e,t,n){return si(t,Element)&&(_be(e,t,n),pbe(e,t,n),Abe(e,t),Tbe(e,t)),t}async function Ibe(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const r={};for(let s=0;s<n.length;s++){const a=n[s].getAttribute("xlink:href");if(a){const c=e.querySelector(a),u=document.querySelector(a);!c&&u&&!r[a]&&(r[a]=await Fv(u,t,!0))}}const i=Object.values(r);if(i.length){const s="http://www.w3.org/1999/xhtml",o=document.createElementNS(s,"svg");o.setAttribute("xmlns",s),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const a=document.createElementNS(s,"defs");o.appendChild(a);for(let c=0;c<i.length;c++)a.appendChild(i[c]);e.appendChild(o)}return e}async function Fv(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>Cbe(r,t)).then(r=>Sbe(e,r,t)).then(r=>Pbe(e,r,t)).then(r=>Ibe(r,t))}const VV=/url\((['"]?)([^'"]+?)\1\)/g,Mbe=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Rbe=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function $be(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function Dbe(e){const t=[];return e.replace(VV,(n,r,i)=>(t.push(i),n)),t.filter(n=>!E6(n))}async function Nbe(e,t,n,r,i){try{const s=n?rbe(t,n):t,o=Pk(t);let a;return i||(a=await Ik(s,o,r)),e.replace($be(t),`$1${a}$3`)}catch{}return e}function Lbe(e,{preferredFontFormat:t}){return t?e.replace(Rbe,n=>{for(;;){const[r,,i]=Mbe.exec(n)||[];if(!i)return"";if(i===t)return`src: ${r};`}}):e}function HV(e){return e.search(VV)!==-1}async function BV(e,t,n){if(!HV(e))return e;const r=Lbe(e,n);return Dbe(r).reduce((s,o)=>s.then(a=>Nbe(a,o,t,n)),Promise.resolve(r))}async function gu(e,t,n){var r;const i=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(i){const s=await BV(i,null,n);return t.style.setProperty(e,s,t.style.getPropertyPriority(e)),!0}return!1}async function jbe(e,t){await gu("background",e,t)||await gu("background-image",e,t),await gu("mask",e,t)||await gu("-webkit-mask",e,t)||await gu("mask-image",e,t)||await gu("-webkit-mask-image",e,t)}async function Fbe(e,t){const n=si(e,HTMLImageElement);if(!(n&&!E6(e.src))&&!(si(e,SVGImageElement)&&!E6(e.href.baseVal)))return;const r=n?e.src:e.href.baseVal,i=await Ik(r,Pk(r),t);await new Promise((s,o)=>{e.onload=s,e.onerror=t.onImageErrorHandler?(...c)=>{try{s(t.onImageErrorHandler(...c))}catch(u){o(u)}}:o;const a=e;a.decode&&(a.decode=s),a.loading==="lazy"&&(a.loading="eager"),n?(e.srcset="",e.src=i):e.href.baseVal=i})}async function Obe(e,t){const r=Va(e.childNodes).map(i=>zV(i,t));await Promise.all(r).then(()=>e)}async function zV(e,t){si(e,Element)&&(await jbe(e,t),await Fbe(e,t),await Obe(e,t))}function Vbe(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(i=>{n[i]=r[i]}),e}const BP={};async function zP(e){let t=BP[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},BP[e]=t,t}async function UP(e,t){let n=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,s=(n.match(/url\([^)]+\)/g)||[]).map(async o=>{let a=o.replace(r,"$1");return a.startsWith("https://")||(a=new URL(a,e.url).href),FV(a,t.fetchRequestInit,({result:c})=>(n=n.replace(o,`url(${c})`),[o,c]))});return Promise.all(s).then(()=>n)}function ZP(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(n,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const c=i.exec(r);if(c===null)break;t.push(c[0])}r=r.replace(i,"");const s=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,o="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",a=new RegExp(o,"gi");for(;;){let c=s.exec(r);if(c===null){if(c=a.exec(r),c===null)break;s.lastIndex=a.lastIndex}else a.lastIndex=s.lastIndex;t.push(c[0])}return t}async function Hbe(e,t){const n=[],r=[];return e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach((s,o)=>{if(s.type===CSSRule.IMPORT_RULE){let a=o+1;const c=s.href,u=zP(c).then(f=>UP(f,t)).then(f=>ZP(f).forEach(p=>{try{i.insertRule(p,p.startsWith("@import")?a+=1:i.cssRules.length)}catch(m){console.error("Error inserting rule from remote css",{rule:p,error:m})}})).catch(f=>{console.error("Error loading remote css",f.toString())});r.push(u)}})}catch(s){const o=e.find(a=>a.href==null)||document.styleSheets[0];i.href!=null&&r.push(zP(i.href).then(a=>UP(a,t)).then(a=>ZP(a).forEach(c=>{o.insertRule(c,o.cssRules.length)})).catch(a=>{console.error("Error loading remote stylesheet",a)})),console.error("Error inlining remote css file",s)}}),Promise.all(r).then(()=>(e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach(s=>{n.push(s)})}catch(s){console.error(`Error while reading CSS rules from ${i.href}`,s)}}),n))}function Bbe(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>HV(t.style.getPropertyValue("src")))}async function zbe(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=Va(e.ownerDocument.styleSheets),r=await Hbe(n,t);return Bbe(r)}function UV(e){return e.trim().replace(/["']/g,"")}function Ube(e){const t=new Set;function n(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(s=>{t.add(UV(s))}),Array.from(r.children).forEach(s=>{s instanceof HTMLElement&&n(s)})}return n(e),t}async function Zbe(e,t){const n=await zbe(e,t),r=Ube(e);return(await Promise.all(n.filter(s=>r.has(UV(s.style.fontFamily))).map(s=>{const o=s.parentStyleSheet?s.parentStyleSheet.href:null;return BV(s.cssText,o,t)}))).join(`
510
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return h.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},_2e="DialogDescriptionWarning",A2e=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${DV(_2e).contentName}}.`;return h.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Dv=kV,Nv=SV,Lv=_V,jv=AV,lp=PV,Ak=RV;const Nm=Mt("useCommit"),T2e=()=>{const[e,t]=h.useState(!1),[n,r]=h.useState(!1),i=h.useCallback(async()=>{r(!0);try{const o=await fetch("/api/git/generate-commit-message");if(!o.ok){const c=await o.json();throw new Error(c.error||`HTTP ${o.status}`)}return(await o.json()).message}catch(o){return Nm.warn("Failed to generate commit message:",o),null}finally{r(!1)}},[]);return{commit:h.useCallback(async(o,a=!1)=>{t(!0);try{const c=await fetch("/api/git/commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:o,push:a})}),u=await c.json();if(!c.ok&&u.sha)return Nm.warn("Commit succeeded but push failed:",u.details),{sha:u.sha,pushed:!1,pushError:u.details||u.error};if(!c.ok)throw new Error(u.details||u.error||`HTTP ${c.status}`);return Nm.info("Committed successfully:",u.sha),{sha:u.sha,pushed:!!u.pushed}}catch(c){throw Nm.warn("Failed to commit:",c),c}finally{t(!1)}},[]),generateMessage:i,isCommitting:e,isGenerating:n}},P2e=Mt("CommitModal"),I2e=({isOpen:e,onClose:t,onCommitted:n})=>{const r=bs(),{commit:i,generateMessage:s,isCommitting:o,isGenerating:a}=T2e(),[c,u]=h.useState(""),[f,p]=h.useState(null);h.useEffect(()=>{e&&(u(""),s().then(b=>{b&&u(b)}))},[e,s]);const m=h.useCallback(async(b=!1)=>{if(c.trim()){p(b?"push":"commit");try{const x=await i(c.trim(),b);r==null||r.capture("git_commit",{has_push:b,is_pushed:x.pushed,has_push_error:!!x.pushError,message_length:c.trim().length}),n(),t(),x.pushError&&ct.error("Commit succeeded but push failed",{description:x.pushError})}catch(x){r==null||r.capture("git_commit_failed",{has_push:b,error:x instanceof Error?x.message:"unknown"}),P2e.error("Commit failed:",x),ct.error("Commit failed",{description:x instanceof Error?x.message:"Failed to commit"})}finally{p(null)}}},[i,c,n,t,r]),g=h.useCallback(b=>{b.key==="Enter"&&b.metaKey&&(b.preventDefault(),m(!b.shiftKey))},[m]);return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Commit Changes"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("textarea",{value:c,onChange:b=>u(b.target.value),onKeyDown:g,placeholder:a?"Generating message...":"Enter commit message",disabled:a,rows:3,className:"w-full resize-none rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),a?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:()=>m(!1),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md border border-divider px-3 py-2 text-xs text-white transition-colors hover:bg-main-hover disabled:opacity-50",children:f==="commit"?"Committing...":"Commit"}),y.jsx("button",{onClick:()=>m(!0),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:f==="push"?"Committing...":"Commit & Push"})]})]})})]})})},LP=Mt("CreateBranchModal"),M2e=({isOpen:e,onClose:t,onCreated:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),[c,u]=h.useState(!1);h.useEffect(()=>{e&&(s(""),a(!0),fetch("/api/git/generate-branch-name").then(m=>{if(!m.ok)throw new Error(`HTTP ${m.status}`);return m.json()}).then(m=>{s(m.branchName)}).catch(m=>{LP.error("Failed to generate branch name:",m),s("rivet/")}).finally(()=>{a(!1)}))},[e]);const f=h.useCallback(async()=>{if(!i.trim()||c||o)return;u(!0);const m=i.trim();try{const g=await fetch("/api/git/create-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branchName:m})});if(!g.ok){const b=await g.json();throw new Error(b.details||b.error||`HTTP ${g.status}`)}n(m),t()}catch(g){const b=g instanceof Error?g.message:"Failed to create branch";r==null||r.capture("git_branch_create_failed",{branch:m,error:b}),ct.error("Failed to create branch",{description:b}),LP.error("Failed to create branch:",g)}finally{u(!1)}},[i,c,o,n,t,r]),p=h.useCallback(m=>{m.key==="Enter"&&(m.preventDefault(),f())},[f]);return y.jsx(Dv,{open:e,onOpenChange:m=>!m&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Create Branch"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:i,onChange:m=>s(m.target.value),onKeyDown:p,placeholder:o?"Generating name...":"Enter branch name",disabled:o,className:"w-full rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),o?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsx("button",{onClick:f,disabled:c||o||!i.trim(),className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:c?"Creating...":"Create"})]})})]})})},R2e=({prUrl:e,branchName:t,isOpen:n,isLoading:r=!1,onClose:i})=>{const s=bs(),o=h.useCallback(a=>{a.key!=="Enter"||a.repeat||r||(a.preventDefault(),e&&(s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"keyboard"}),window.open(e,"_blank","noopener,noreferrer")))},[r,e,s,t]);return h.useEffect(()=>{if(n)return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n,o]),y.jsx(Dv,{open:n,onOpenChange:a=>!a&&i(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsxs(jv,{className:"fixed left-1/2 top-1/2 z-max w-[380px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:[r?y.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[y.jsx(Ua,{className:"h-6 w-6 animate-spin text-primary",weight:"bold"}),y.jsx(lp,{className:"text-sm font-medium text-content",children:"Creating pull request..."})]}):null,r?null:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between gap-3",children:[y.jsx(lp,{className:"whitespace-nowrap text-sm font-semibold text-content",children:"Created Pull Request"}),t?y.jsxs("span",{className:"inline-flex max-w-[180px] shrink-0 items-center gap-1 rounded-md bg-main-input px-2 py-0.5 text-xs text-content-muted",children:[y.jsx(vh,{className:"h-3 w-3 shrink-0",weight:"bold"}),y.jsx("span",{className:"truncate",children:t})]}):null]}),y.jsxs("a",{href:e??"#",target:"_blank",rel:"noopener noreferrer",onClick:()=>{s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"button"})},className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover",children:["View PR",y.jsx(r8,{className:"h-3 w-3",weight:"bold"})]})]})]})]})})},NV=({primaryLabel:e,primaryIcon:t,primaryAction:n,isDisabled:r=!1,isLoading:i=!1,loadingLabel:s,dropdownItems:o})=>{const[a,c]=h.useState(!1),u=i?s??e:e;return y.jsxs("div",{className:"flex items-stretch",children:[y.jsxs("button",{onClick:n,disabled:r||i,className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-l-md bg-main-hover px-3 text-xs font-medium text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[t?y.jsx(t,{className:"h-3.5 w-3.5",weight:"bold"}):null,u]}),y.jsxs(Fo,{open:a,onOpenChange:c,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{disabled:i,className:"h-7 flex-shrink-0 rounded-r-md border-l border-white/20 bg-main-hover px-1.5 text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:y.jsx(Ba,{className:"h-3.5 w-3.5",weight:"bold"})})}),y.jsx(Oo,{children:y.jsx(Vo,{className:"z-[60] min-w-[140px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:5,align:"end",children:o.map(f=>{const p=f.icon;return y.jsxs("button",{onClick:()=>{f.isDisabled||(f.onClick(),c(!1))},disabled:f.isDisabled,className:"flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[p?y.jsx(p,{className:"h-3.5 w-3.5",weight:"bold"}):null,f.label]},f.label)})})})]})]})},$2e=h.createContext(null);function D2e(e){switch(e){case"top":return{y:4};case"bottom":return{y:-4};case"left":return{x:4};case"right":return{x:-4}}}function Tk({content:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=200,className:s,forceOpen:o,onOpenChange:a}){const[c,u]=h.useState(!1),f=o!==void 0?o:c,[p,m]=h.useState(!1),g=Mp(),b=h.useContext($2e);h.useEffect(()=>{f&&m(!0)},[f]);const x=()=>{f||m(!1)},C=D2e(n);return y.jsx(bV,{delayDuration:i,children:y.jsxs(xk,{open:f,onOpenChange:w=>{u(w),a==null||a(w)},children:[y.jsx(wk,{asChild:!0,children:t}),p&&y.jsx(kk,{forceMount:!0,container:b??void 0,children:y.jsx(Ck,{side:n,sideOffset:r,forceMount:!0,className:"z-tooltip",children:y.jsx(mn.div,{className:fr("bg-neutral-900 text-white text-[12px] px-2 py-1 border border-white/10 shadow-lg",g.bg,s),style:{fontVariationSettings:_h.medium},initial:{opacity:0,scale:.8,...C},animate:{opacity:f?1:0,scale:f?1:.9,x:0,y:0},transition:f?{type:"spring",duration:.34,bounce:.55}:{duration:.1},onAnimationComplete:x,children:e})})})]})})}const Fi=({label:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=300,disabled:s=!1})=>s?y.jsx(y.Fragment,{children:t}):y.jsx(Tk,{content:e,side:n,sideOffset:r,delayDuration:i,children:t}),vx=Mt("GitHome"),N2e=({onClose:e})=>e?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx(Fi,{label:"Close chat",side:"bottom",children:y.jsx("button",{onClick:e,className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})}):null,L2e=({onUndo:e,isUndoing:t=!1,onClose:n})=>{const r=bs(),s=ke(Qs).branchDiff.isEnabled,{status:o,fetchStatus:a}=q1(),{stats:c}=cV(),{publishChanges:u,isPublishing:f}=Kye(),{pushCommits:p,isPushing:m}=Yye(),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(!1),[A,T]=h.useState(null),[M,I]=h.useState(null),P=(o==null?void 0:o.branchName)??null,S=(o==null?void 0:o.hasUncommittedChanges)??!1,D=c.totalInsertions>0||c.totalDeletions>0,R=(o==null?void 0:o.canUndo)??!1,L=(o==null?void 0:o.prUrl)??null,j=h.useCallback((Fe,Te,je,nt)=>{Fe==="success"?ct.success(Te,{description:je,action:nt?{label:nt.label,onClick:nt.onClick}:void 0}):Fe==="info"?ct.info(Te,{description:je}):(je&&vx.error(`${Te}:`,je),ct.error(Te))},[]),O=h.useCallback(async()=>{r==null||r.capture("git_pr_create_started",{branch:P}),E(!0),T(null);let Fe=!1;const je=await u((nt,yt,et)=>{nt==="error"&&(Fe=!0,r==null||r.capture("git_pr_create_failed",{branch:P,error:et??yt}),vx.error("Failed to create PR:",et??yt),E(!1),ct.error("Failed to create PR",{description:et??yt}))});je!=null&&je.prUrl?(r==null||r.capture("git_pr_created",{branch:je.branchName,pr_url:je.prUrl}),T(je.prUrl),I(je.branchName),a()):Fe||(r==null||r.capture("git_pr_create_failed",{branch:P,error:"unknown"}),vx.error("Failed to create PR: unknown error"),E(!1),ct.error("Failed to create PR",{description:"Something went wrong creating the pull request."}))},[u,a,r,P]),H=h.useCallback(async()=>{r==null||r.capture("git_push_started",{branch:P});const{success:Fe,error:Te}=await p();Fe?(r==null||r.capture("git_push_succeeded",{branch:P}),j("success","Changes pushed to GitHub")):(r==null||r.capture("git_push_failed",{branch:P,error:Te}),j("error","Failed to push",Te??void 0))},[p,j,r,P]),B=h.useCallback(()=>{L&&(r==null||r.capture("git_pr_opened",{branch:P,pr_url:L}),window.open(L,"_blank","noopener,noreferrer"))},[L,r,P]),Z=h.useCallback(()=>{a(),ct.success("Changes committed")},[a]),K=h.useCallback(Fe=>{r==null||r.capture("git_branch_created",{branch:Fe,from_branch:P}),a(),ct.success("Branch created")},[a,r,P]),q=h.useCallback(()=>{r==null||r.capture("git_commit_modal_opened",{branch:P}),b(!0)},[r,P]),Q=h.useCallback(()=>{r==null||r.capture("git_create_branch_modal_opened",{branch:P}),C(!0)},[r,P]),F=h.useCallback(()=>{r==null||r.capture("git_undo_commit",{branch:P}),e==null||e(j)},[r,P,e,j]),V=S,W=!!L,N=P==="main"&&!V&&!W,z=W?"Go to PR":"Create PR",ee=W?r8:C5,te=W?B:O,re=!W&&!D;let G=V?"Commit":z,X=V?k5:ee,de=V?q:te,ve=V?!1:re;N&&(G="New Branch",X=vh,de=Q,ve=!1);const we=V?[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},{label:z,icon:ee,onClick:te,isDisabled:f||re},{label:"Create New Branch",icon:vh,onClick:Q}]:[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},...N?[{label:"Create PR",icon:C5,onClick:O,isDisabled:!0}]:[{label:"Commit",icon:k5,onClick:q,isDisabled:!S},{label:"Create Branch",icon:vh,onClick:Q}]];return P?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"z-10 flex h-10 flex-shrink-0 items-center justify-between border-b border-main-border bg-main-light px-3",children:[n&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})}),y.jsx("div",{className:"mx-1 h-4 w-[1px] flex-shrink-0 bg-divider/20"})]}),y.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-2",children:[y.jsx(g2e,{currentBranch:P,onSwitch:()=>{a()}}),s&&D&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"h-4 w-[1px] flex-shrink-0 bg-divider/20"}),y.jsx(Qye,{})]})]}),y.jsx(NV,{primaryLabel:G,primaryIcon:X,primaryAction:de,isDisabled:ve,isLoading:!1,loadingLabel:"Creating PR...",dropdownItems:we})]}),y.jsx(I2e,{isOpen:g,onClose:()=>b(!1),onCommitted:Z}),y.jsx(M2e,{isOpen:x,onClose:()=>C(!1),onCreated:K}),y.jsx(R2e,{prUrl:A,branchName:M??void 0,isOpen:w,isLoading:f,onClose:()=>E(!1)})]}):n?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})}):null},j2e=e=>{const t=ke(x$),r=ke(Qs).gitUi.isEnabled;return!t||!r?y.jsx(N2e,{onClose:e.onClose}):y.jsx(L2e,{...e})},F2e=Mt("SupportTicketModal"),jP=5e3,yx="feedback",O2e=e=>{var r;if(!e)return null;const t=(r=e.formErrors)==null?void 0:r[0];if(t)return t;const n=e.fieldErrors??{};for(const i of Object.values(n)){const s=i==null?void 0:i[0];if(s)return s}return null},V2e=async e=>{let t;try{t=await e.json()}catch{t=void 0}if(e.status===400){if(typeof(t==null?void 0:t.details)=="string"&&t.details.trim())return t.details;if(typeof(t==null?void 0:t.details)=="object"&&t.details!==null){const n=O2e(t.details);if(n)return n}return"Please check your feedback and try again."}return e.status>=500?typeof(t==null?void 0:t.details)=="string"&&t.details.trim()?t.details:"Could not send feedback right now. Please try again later.":typeof(t==null?void 0:t.error)=="string"&&t.error.trim()?t.error:`HTTP ${e.status}`},H2e=({isOpen:e,onClose:t,contactEmail:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),c=h.useCallback(()=>{s("")},[]),u=h.useCallback(()=>{o||(c(),t())},[o,t,c]),f=h.useCallback(async()=>{const b=i.trim();if(!(!b||o)){a(!0);try{const x=typeof(r==null?void 0:r.get_session_id)=="function"?r.get_session_id():void 0,C=typeof(r==null?void 0:r.get_distinct_id)=="function"?r.get_distinct_id():void 0,w=n==null?void 0:n.trim(),E=await fetch("/api/support/tickets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:yx,message:b,contactEmail:w||void 0,metadata:{posthogSessionId:x??void 0,posthogDistinctId:C??void 0,appVersion:"0.11.0",appEnvironment:"production",pageUrl:window.location.href,userAgent:navigator.userAgent,submittedAt:new Date().toISOString()}})});if(!E.ok){const A=await V2e(E);throw new Error(A)}r==null||r.capture("support_ticket_submitted",{ticket_type:yx,has_posthog_session_id:!!x}),ct.success("Feedback sent",{description:"Thanks for sharing this."}),c(),t()}catch(x){const C=x instanceof Error?x.message:"Failed to send message";r==null||r.capture("support_ticket_submit_failed",{ticket_type:yx,error:C}),F2e.error("Failed to submit support ticket:",C),ct.error("Could not send feedback",{description:C})}finally{a(!1)}}},[n,o,i,t,r,c]),p=h.useCallback(b=>{b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),f())},[f]),m=jP-i.length,g=o||i.trim().length===0;return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&u(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[480px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Send feedback"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",disabled:o,children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsx("p",{className:"text-sm text-content-subtle",children:"Tell us what happened or what we can improve."}),y.jsxs("div",{className:"space-y-2",children:[y.jsx("label",{htmlFor:"support-ticket-message",className:"text-xs font-medium text-content-muted",children:"Your feedback"}),y.jsx("textarea",{id:"support-ticket-message",value:i,onChange:b=>s(b.target.value),onKeyDown:p,maxLength:jP,rows:7,disabled:o,placeholder:"What happened?",className:"w-full resize-none rounded-md border border-divider bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),y.jsxs("div",{className:"flex justify-between text-xs text-content-subtle",children:[y.jsx("span",{children:"Context details are included automatically."}),y.jsx("span",{children:m})]})]}),y.jsx("button",{onClick:f,disabled:g,className:"flex w-full items-center justify-center gap-2 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:o?y.jsxs(y.Fragment,{children:[y.jsx(Ua,{className:"h-4 w-4 animate-spin",weight:"bold"}),y.jsx("span",{children:"Sending..."})]}):y.jsx("span",{children:"Send feedback"})})]})})]})})},B2e=Mt("ProfileAvatar"),z2e=(e,t)=>{const n=(e??"").trim();if(n){const i=n.split(/\s+/).filter(Boolean);return i.length>=2?(i[0][0]+i[i.length-1][0]).toUpperCase():i[0].slice(0,2).toUpperCase()}const r=(t??"").split("@")[0]??"";if(r){const i=r.split(/[._\-+]/).filter(Boolean);return i.length>=2?(i[0][0]+i[1][0]).toUpperCase():r.slice(0,2).toUpperCase()}return""},U2e=({className:e=""})=>{const{name:t,email:n}=ke(p$),[r,i]=h.useState(!1),[s,o]=h.useState(!1),[a,c]=h.useState(!1),u=z2e(t,n);if(!u)return null;const f=(t==null?void 0:t.trim())||null,p=(n==null?void 0:n.trim())||null,m=async()=>{c(!0);try{const g=await fetch("/api/auth/logout",{method:"POST",credentials:"same-origin"});if(!g.ok)throw new Error(`Logout failed: ${g.status}`)}catch(g){B2e.warn("Logout request failed",g),ct.error("Could not log out. Please try again."),c(!1);return}window.location.reload()};return y.jsxs(y.Fragment,{children:[y.jsxs(Fo,{open:r,onOpenChange:i,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{type:"button","aria-label":"Account",className:`flex h-6 w-6 shrink-0 select-none items-center justify-center rounded-full border border-main-border bg-main-input text-[10px] font-semibold leading-none text-content-muted transition-colors hover:text-content ${e}`,children:u})}),y.jsx(Oo,{children:y.jsxs(Vo,{className:"z-[60] min-w-[180px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:6,align:"end",children:[f||p?y.jsxs("div",{className:"border-b border-main-border px-3 py-2",children:[f?y.jsx("div",{className:"truncate text-xs font-medium text-content",children:f}):null,p?y.jsx("div",{className:"truncate text-[11px] text-content-muted",children:p}):null]}):null,y.jsxs("button",{type:"button",onClick:()=>{i(!1),o(!0)},className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input",children:[y.jsx(LI,{className:"h-3.5 w-3.5",weight:"bold"}),"Support & feedback"]}),y.jsxs("button",{type:"button",onClick:m,disabled:a,className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[y.jsx(yG,{className:"h-3.5 w-3.5",weight:"bold"}),a?"Logging out…":"Log out"]})]})})]}),y.jsx(H2e,{isOpen:s,onClose:()=>o(!1),contactEmail:n??void 0})]})},Ut=Mt("ElementInspector"),Z2e=({chatMessages:e,setChatMessages:t,onClose:n})=>{const[r,i]=Vn(Ui),s=ke(Ad),[o]=Vn(U1),{undoLastChange:a,isUndoing:c}=Qie(),{status:u,fetchStatus:f}=q1(),m=ke(Qs).gitUi.isEnabled,g=m?(u==null?void 0:u.canUndo)??!1:!1,b=h.useCallback(async()=>{if(!s||!r)return;await new Promise(E=>requestAnimationFrame(E)),Ut.debug("Refreshing element styles for:",r.tagName);const w=await s.reSelectElement(ND(r));if(w){s.setCurrentElement(w);const E=s.getComputedStyles();s.showSelectionOverlay(w),VD("style_refresh"),i({...r,computedStyles:E})}else Ut.warn("Could not find element for refresh:",r.xpath)},[s,r,i]),x=h.useCallback(async()=>{if(!(o!=null&&o.canUndo()))return!1;const w=await o.undo();return w.ok?(await b(),!0):(Ut.error("Failed to undo:",w.error.message),!1)},[o,b]),C=h.useCallback(async w=>{var A;if(!m||!g||!await a((T,M,I)=>{w?w(T,M,I):T==="success"?ct.success(M,{description:I}):T==="info"?ct.message(M,{description:I}):(I&&Ut.error(`${M}:`,I),ct.error(M))}))return!1;if(await f(),(s==null?void 0:s.type)==="iframe"&&"forceReload"in s){Ut.info("Force reloading iframe after git undo");try{await((A=s.forceReload)==null?void 0:A.call(s))}catch(T){return Ut.error("Iframe reload failed, but git undo succeeded:",T),w==null||w("info","Changes reverted successfully","Please refresh the page to see the updated preview"),!0}}return await b(),!0},[b,g,m,a,f,s]);return y.jsxs("div",{className:"relative flex h-full w-96 cursor-auto flex-col overflow-hidden bg-main font-main shadow-2xl scrollbar-hide","data-cy":"element-inspector",children:[y.jsx(U2e,{className:"absolute right-3 top-2 z-20"}),y.jsx(j2e,{onUndo:C,isUndoing:c,onClose:n}),y.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:y.jsx(W2e,{chatMessages:e,setChatMessages:t,handleUndo:x,refreshElementStyles:b,fetchStatus:f})})]})},W2e=({chatMessages:e,setChatMessages:t,handleUndo:n,refreshElementStyles:r,fetchStatus:i})=>{const s=bs(),[o,a]=Vn(Ui),c=ke(Ad),[u,f]=Vn(ji),p=bc(),m=ke(xp),g=ke(hs),b=ke(wc),x=ke(eo),C=h.useRef(x);C.current=x;const w=h.useMemo(()=>Fie(u,g),[u,g]),E=h.useMemo(()=>{if(!rh(g))return null;const{sessionId:Se,variantId:He}=g;for(const dt of[b==null?void 0:b.left,b==null?void 0:b.right])if(dt&&dt.sessionId===Se&&dt.variantId===He)return dt.label;if(x.active){const dt=x.variants.find(Ze=>Ze.workItemId===He);if(dt)return dt.label}return"Direction"},[g,b,x]),A=ke(F8),[T,M]=Vn(U1);h.useEffect(()=>{if(!c)return;T&&T.destroy();const Se=new zJ(c,A);return M(Se),window.manipulationService=Se,()=>{Se.destroy(),M(null),delete window.manipulationService}},[c,A,M]);const[I,P]=h.useState(null),[S,D]=h.useState(0),R=Be(m$),L=Array.from(u.values()).filter(Se=>Se.status==="pending").length,[j,O]=Vn(ree),[H,B]=h.useState({}),[Z,K]=h.useState(0),q=h.useRef(null),Q=h.useRef(null),F=h.useRef(null),[V,W]=h.useState(0),N=h.useRef({}),z=h.useRef(!1),ee=h.useCallback(Se=>{const He=C.current;He.active&&He.sessionId===Se.sessionId&&$A(Se,He.variants,N.current),z.current=!1,F.current=Se,W(dt=>dt+1)},[]),te=h.useCallback(()=>{F.current!==null&&(F.current=null,W(Se=>Se+1))},[]),re=h.useCallback(Se=>{Q.current=Se,K(He=>He+1)},[]),G=h.useCallback(()=>{const Se=Q.current;Q.current=null,te(),K(He=>He+1),Se&&(Se.changeIds.length>0&&T&&Se.changeIds.forEach(He=>{T.removeTrackedChangeById(He)}),Se.commentIds.length>0&&f(He=>{if(He.size===0)return He;const dt=(m==null?void 0:m.current)??null;if(dt){const Kt=Se.commentIds.map(St=>He.get(St)).filter(St=>St!=null);Vu(dt,Kt)}const Ze=new Map(He);return Se.commentIds.forEach(Kt=>{Ze.delete(Kt)}),Ze}))},[T,f,m,te]),X=h.useCallback(()=>{Q.current=null,te(),K(Se=>Se+1)},[te]),{modifyWithAgent:de,cancelModification:ve,isModifying:we}=pte(),Fe=ke(w$),Te=ke(wp),je=ke(W1),nt=ke(z8),{sendChanges:yt,sendChatMessage:et}=Q$(),{status:ye,resetStatus:Ye}=Gie(),$t=h.useMemo(()=>Tie(ye),[ye]),Tt=ke(B8),{onRoundStarted:Nt,onProgressSteps:yn,onAssistantChunk:nn,onRoundCompleted:he,onRoundFailed:be,onRoundCanceled:We,getActiveAssistantMessageId:ot,getCancellationMessage:lt,setPhase:Vt}=Xie({setChatMessages:t,isMCPSession:Te}),Gt=ke(Js),J=Gt==="comment",Y=ke(Qs).generativeControls.isEnabled,se=ke(Iv),ce=ke(sV),le=Be(lV),ge=Be(aV),Ce=h.useMemo(()=>wie(se,ce),[se,ce]),$e=Be(j8),ut=ke(uc),it=ke(hd),{startRound:Zt,resetPhase:De}=Zie({mcpStatus:ye,isPublishing:j,isMCPSession:Te,setIsPublishing:O,fetchStatus:i,refreshElementStyles:r,getActiveAssistantMessageId:ot,onProgressSteps:yn,onRoundCompleted:he,setSessionUxPhase:Vt,clearQueuedPendingSnapshot:G});h.useEffect(()=>{if(!Te||!j)return;const Se=F.current;if(!Se)return;if(x.active&&x.sessionId===Se.sessionId)z.current=!0;else{if(!z.current)return;X(),O(!1),De(),Vt("idle");const rn=ot();rn&&be({assistantMessageId:rn,error:"Static preview variant refinement was interrupted."});return}const dt=N.current,Ze=Oie(Se,x.variants,dt);if(Ze.status==="pending")return;$A(Se,x.variants,dt);const Kt=Se.variantIds.length>1,St=ot();if(Ze.status==="succeeded"){G(),O(!1),De(),Vt("idle"),St&&he({assistantMessageId:St,finalMessage:Kt?"Static preview variants refined.":"Static preview variant refined."});return}if(X(),O(!1),De(),Vt("idle"),St){let rn;Ze.status==="cancelled"?rn="Static preview variant refinement was cancelled.":Ze.errorCode?rn=`Static preview variant refinement failed (${Ze.errorCode}).`:rn="Static preview variant refinement failed.",be({assistantMessageId:St,error:rn})}},[G,X,ot,Te,j,he,be,De,O,Vt,V,x]),h.useEffect(()=>{o&&(Te||(q.current=null))},[o==null?void 0:o.xpath,Te]);const at=we||j,Ne=Fe,Rt=$ie((o==null?void 0:o.computedStyles)||{});h.useEffect(()=>{var Kt,St;if(!o||!c||c.type!=="iframe")return;let Se=!1;const He=ND(o),dt=((St=(Kt=o.filePaths)==null?void 0:Kt[0])==null?void 0:St.filePath)||void 0;return(async()=>{const rn=await c.reSelectElement(He);if(Se||!rn)return;const wn=Ga();c.injectRivetId(rn,wn);const Un=c.createElementIdentifier(rn);Un.rivetId=wn,Un.filePath=dt,P(Un)})(),()=>{Se=!0}},[o,c]);const bn=ke(z1);h.useEffect(()=>{if(!T)return;const Se=A.getChangeCount();return D(Se),R(Se),A.onChange(()=>{const dt=A.getChangeCount();D(dt),R(dt)})},[A,T,R]);const en=!!o&&!J;h.useEffect(()=>{var dt;const Se=Ze=>{if(!((Ze.metaKey||Ze.ctrlKey)&&Ze.key.toLowerCase()==="z"&&!Ze.shiftKey)||bn.isEditing)return;const St=document.activeElement;St&&(St.tagName==="INPUT"||St.tagName==="TEXTAREA"||St.tagName==="SELECT"||St.getAttribute("contenteditable")==="true")&&!en||(Ze.preventDefault(),Ut.debug("Undo shortcut triggered"),s==null||s.capture("undo"),n())},He=(dt=m==null?void 0:m.current)==null?void 0:dt.contentDocument;return window.addEventListener("keydown",Se),He==null||He.addEventListener("keydown",Se),()=>{window.removeEventListener("keydown",Se),He==null||He.removeEventListener("keydown",Se)}},[en,n,bn.isEditing,m]);const qt=Se=>{Se!==Gt&&(s==null||s.capture("inspector_tab_changed",{from_tab:Gt,to_tab:Se})),$e(Se)};X8({shortcuts:[{key:"1",handler:()=>{Ut.debug("Switching to Styles tab (1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",handler:()=>{Ut.debug("Switching to Chat tab (2)"),qt("comment")},description:"Switch to Chat tab"},{key:"1",metaKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Cmd+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"1",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Ctrl+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",metaKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Cmd+2)"),qt("comment")},description:"Switch to Chat tab"},{key:"2",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Ctrl+2)"),qt("comment")},description:"Switch to Chat tab"}]});const pr=h.useCallback(async()=>{var He;if(at)return;zte(),Vu((m==null?void 0:m.current)??null,u.values());const Se=p.get(qa);Se&&(await a1(Se.diff),p.set(qa,null));for(const dt of u.values()){const Ze=(He=dt.finalizedVariant)==null?void 0:He.codeDiff;Ze&&await a1(Ze)}T==null||T.clear(),f(new Map),le()},[at,T,f,m,u,p,le]),Mn=h.useCallback(async()=>{const He=Hie(Te?u:w,T,Ce);if(!He)return;X();const{pendingComments:dt,styleChanges:Ze,textChanges:Kt,pendingSnapshot:St,applyPointers:rn,hasComments:wn,hasDesignChanges:Un,hasInterfaceChanges:bt}=He;if(s==null||s.capture("apply",{comment_count:dt.length,design_edit_count:Ze.length+Kt.length,interface_change_count:He.interfaceChanges.length,has_comments:wn,has_design_changes:Un,has_interface_changes:bt}),Te){$e("comment"),Ye(),O(!0),Zt();const Yt=$b(rn),{assistantMessageId:on}=Nt({userMessage:Yt,startPhase:"starting"});if(Ut.debug("[MCP] new apply round — asstMsgId:",on),re(St),!wn&&!Un&&bt){const Si=await et(Iw(Ce));if(Si.cancelled)return;Si.success||(X(),ct.error(Si.error||"Failed to send changes"),be({assistantMessageId:on,error:Si.error||"Failed to send changes"}),O(!1),De());return}const Bn=await yt();if(Bn.cancelled)return;if(!Bn.success){X(),ct.error(Bn.error||"Failed to send changes"),be({assistantMessageId:on,error:Bn.error||"Failed to send changes"}),O(!1),De();return}bt&&await et(Iw(Ce)),(Bn.changeIdsToClear||Bn.commentIdsToClear)&&re({...St,commentIds:Bn.commentIdsToClear??St.commentIds,changeIds:Bn.changeIdsToClear??St.changeIds}),Bn.staticPreviewVariantIds&&Bn.staticPreviewVariantIds.length>0&&Bn.staticPreviewSessionId&&ee({sessionId:Bn.staticPreviewSessionId,variantIds:Bn.staticPreviewVariantIds});return}$e("comment"),O(!0);const Rn=Bie(He),Lt=zie(He),sr=$b(rn),{assistantMessageId:Xn}=Nt({userMessage:sr,startPhase:"applying"});re(St);const Tc=dt.flatMap(Yt=>Yt.images??[]),Gi=Uie();Ut.debug("Calling modifyWithAgent");let _s=!1;try{await de({instruction:Rn,elements:Array.from(Lt.values()),images:Tc.length>0?Tc:void 0,sessionId:q.current??void 0},{onProgress:Yt=>{if(Gi.recordActivity(),!Yt.startsWith("Agent:")){const on=Yt.match(/^\[([^\]]+)\]/);on&&Gi.recordToolStart(on[1])}},onChunk:Yt=>{Gi.recordActivity(),Gi.recordReasoningChunk(),nn({content:Yt,assistantMessageId:Xn})},onComplete:async Yt=>{var Fp;_s=!0;const on=Gi.finalize();Ut.debug(`modifyWithAgent completed in ${on.agentExecutionDuration}ms`);const Bn=DA(Yt.changes,Yt.filesModified);if(he({assistantMessageId:Xn,finalMessage:Bn}),Yt.sessionId&&(q.current=Yt.sessionId),G(),Un){Ut.debug("Refreshing styles and status");try{await r(),await i()}catch(io){Ut.warn("Style/status refresh failed:",io)}}wn&&Ut.debug("Sent pending comments were cleared after completion."),bt&&le();const Si=Date.now();if((c==null?void 0:c.type)==="iframe"&&"forceReload"in c){Ut.debug("Force reloading iframe");try{await((Fp=c.forceReload)==null?void 0:Fp.call(c))}catch(io){Ut.warn("Iframe reload failed:",io)}}const Wv=Date.now();s==null||s.capture("code_modification",{success:!0,source:"apply",instruction_length:Rn.length,element_count:Lt.size,modification_time_ms:on.agentExecutionDuration}),s==null||s.capture("agent_apply_session",{success:!0,env:"production",total_duration_ms:Gi.elapsed(),agent_execution_duration_ms:on.agentExecutionDuration,tool_execution_duration_ms:on.totalToolDuration,model_reasoning_duration_ms:on.agentExecutionDuration-on.totalToolDuration,time_to_first_message_ms:on.timeToFirstMessage,post_processing_duration_ms:Si-on.agentEndTime,iframe_reload_duration_ms:Wv-Si,model:Yt.model,tool_counts:on.toolCounts,total_tool_calls:Object.values(on.toolCounts).reduce((io,Op)=>io+Op,0),reasoning_chunk_count:on.reasoningChunkCount,element_count:Lt.size,comment_count:dt.length,design_edit_count:S,instruction_length:Rn.length,session_id:Yt.sessionId,server_ttfm_ms:Yt.ttfmMs}),O(!1),De()},onError:async Yt=>{if(_s=!0,Ut.error("Error in modifyWithAgent:",Yt),be({assistantMessageId:Xn,error:Yt}),X(),s==null||s.capture("code_modification",{success:!1,source:"apply",instruction_length:Rn.length,element_count:Lt.size,error_message:Yt}),s==null||s.capture("agent_apply_session",{success:!1,env:"production",total_duration_ms:Gi.elapsed(),error_message:Yt,element_count:Lt.size,instruction_length:Rn.length}),Un)try{await(T==null?void 0:T.clearInlineChanges())}catch(on){Ut.warn("Failed to clear inline changes:",on)}gm(Yt)?vm(Yt):ct.error("Failed to apply changes"),O(!1),De()},onCanceled:()=>{_s=!0,O(!1),De(),X()}})}catch(Yt){_s=!0,Ut.error("Unexpected error in handleApplyAll:",Yt),X();const on=Yt instanceof Error?Yt.message:"An unexpected error occurred";be({assistantMessageId:Xn,error:on}),gm(on)?vm(on):ct.error("Failed to apply changes"),O(!1),De()}finally{_s||(Ut.warn("modifyWithAgent returned without triggering onComplete or onError"),X(),be({assistantMessageId:Xn,error:"Agent request failed to initialize or timed out without feedback."}),ct.error("Failed to apply changes"),O(!1),De())}},[w,u,T,c,de,r,i,S,s,Te,yt,et,Ye,Nt,nn,he,be,$e,Zt,De,O,re,G,X,Ce,le,ee]);h.useEffect(()=>{const Se=He=>{(He.metaKey||He.ctrlKey)&&He.key==="Enter"&&(ut||(L>0||S>0||Ce.length>0)&&!j&&!at&&(He.preventDefault(),Ut.debug("Apply all shortcut triggered (Cmd/Ctrl+Enter)"),Mn()))};return window.addEventListener("keydown",Se),()=>window.removeEventListener("keydown",Se)},[L,S,Ce,j,at,ut,Mn]);const ir=h.useCallback(async(Se,He)=>{var Kt;if(!T||!I||!c||c.type!=="iframe")return;const Ze=((Kt=Rt[Se])==null?void 0:Kt.type)==="range"?(parseFloat(He)/100).toString():He;await T.previewStyleChange(I,Se,Ze)},[T,I,c,Rt]),cn=h.useCallback(async(Se,He,dt)=>{var wn;const Ze=He;if(!Ze||!T||!I||!o||!c||c.type!=="iframe")return;const St=((wn=Rt[Se])==null?void 0:wn.type)==="range"?(parseFloat(Ze)/100).toString():Ze,rn=await T.applyStyleChange(I,o,Se,St,dt);if(rn.ok){const Un=await c.getComputedStylesForElement(I);Un.ok&&a({...o,computedStyles:Un.value}),B(Rn=>{const Lt={...Rn};return delete Lt[Se],Lt});const bt=Mw.find(Rn=>Rn.properties.some(Lt=>Lt.key===Se));s==null||s.capture("design_property_changed",{property:Se,category:bt==null?void 0:bt.value})}else Ut.error("Failed to apply style:",rn.error.message),ct.error("Failed to apply style")},[T,I,o,c,Rt,B,a,s]),Hn=h.useCallback(async Se=>{T&&await T.transaction(Se)},[T]),Ss=(Se,He)=>{B(dt=>({...dt,[Se]:He}))},Hd=(Se,He)=>{const dt=He.replace("%","").trim();if(dt===""){B(St=>({...St,[Se]:""}));return}const Ze=parseFloat(dt);if(Number.isNaN(Ze))return;const Kt=Math.max(0,Math.min(100,Ze));B(St=>({...St,[Se]:Kt.toString()}))},Bv=Se=>{B(He=>{const dt={...He};return delete dt[Se],dt})},zv=h.useCallback(async()=>{if(!T)return;const Se=await T.redo();Se.ok?await r():Ut.error("Failed to redo:",Se.error.message)},[T,r]),Uv=h.useCallback(()=>{const Se=lt();Te&&je==="embedded"&&fetch("/api/agent/stop",{method:"POST",headers:nt?{"x-rivet-queue-token":nt}:void 0}).catch(He=>{Ut.warn("Failed to stop embedded agent run:",He)}),ve(),O(!1),De(),X(),We({cancellationMessage:Se})},[ve,O,De,X,We,lt,Te,je,nt]),ro=h.useCallback(async(Se,He)=>{Ye();const dt=Date.now();X();const Ze=Array.from(u.values()).filter(Lt=>Lt.status==="pending"),Kt=Ze.length>0,St=Ze.map(Lt=>({id:Lt.id,instruction:Lt.instruction})),rn=jD({pendingComments:St,styleChanges:[],textChanges:[],includeComments:Kt,includeChanges:!1});s==null||s.capture("chat",{message_length:Se.length,has_images:!!(He!=null&&He.length),image_count:(He==null?void 0:He.length)??0,has_pending_comments:Kt,pending_comment_count:Ze.length,has_selected_element:!!o});const wn=Kt?FD(Ze):Se,Un=Kt?LD(Ze,[],[]):[],bt=Kt&&Un.length>0?$b(Un):Se,{assistantMessageId:Rn}=Nt({userMessage:bt,images:He,startPhase:Te?"starting":"applying"});rn.commentIds.length>0&&re(rn);try{if(Te){Ye(),O(!0),Zt();const Lt=await et(wn,He);if(Lt.cancelled)return;Lt.success||(X(),be({assistantMessageId:Rn,error:Lt.error||"Failed to send to Claude Code"}),O(!1),De())}else if(Ne){const Lt=o?[o]:[];await de({instruction:wn,elements:Lt,images:He,sessionId:q.current??void 0},{onProgress:()=>{},onChunk:sr=>{nn({content:sr,assistantMessageId:Rn})},onComplete:async({sessionId:sr,changes:Xn,filesModified:Tc})=>{var _s;const Gi=DA(Xn,Tc);if(he({assistantMessageId:Rn,finalMessage:Gi}),G(),s==null||s.capture("code_modification",{success:!0,source:"chat",instruction_length:wn.length,element_count:Lt.length,modification_time_ms:Date.now()-dt}),sr&&(q.current=sr),Kt&&Ut.debug("Sent pending comments were cleared after completion."),(c==null?void 0:c.type)==="iframe"&&"forceReload"in c)try{await((_s=c.forceReload)==null?void 0:_s.call(c))}catch(Yt){Ut.warn("Iframe reload after agent modification failed:",Yt)}r()},onError:sr=>{X(),be({assistantMessageId:Rn,error:sr}),s==null||s.capture("code_modification",{success:!1,source:"chat",instruction_length:wn.length,element_count:Lt.length,error_message:sr,modification_time_ms:Date.now()-dt}),Ut.error("Code modification error details:",sr),gm(sr)?vm(sr):ct.error("Code Modification Error")},onCanceled:()=>{O(!1),De(),X()}})}else Ut.error("Chat mode not supported"),ct.error("Chat mode not supported")}catch(Lt){Ut.error("Error with streaming request:",Lt);const sr=Lt instanceof Error?Lt.message:"An unexpected error occurred.";X(),O(!1),De(),be({assistantMessageId:Rn,error:sr}),gm(sr)?vm(sr):ct.error("Failed to generate AI response")}},[Ye,u,T,s,o,Te,et,Ne,de,c,r,Nt,nn,he,be,Zt,De,O,re,G,X]),Wi=h.useMemo(()=>{const Se=Array.from(w.values()).filter(bt=>bt.status==="pending"),He=(T==null?void 0:T.getStyleChanges())??[],dt=(T==null?void 0:T.getTextChanges())??[],Ze=He.map(bt=>({id:bt.id,key:rc(bt),property:String(bt.property),newValue:bt.newValue,timestamp:bt.timestamp})),Kt=dt.map(bt=>({id:bt.id,key:rc(bt),oldText:bt.oldText,newText:bt.newText,timestamp:bt.timestamp})),St=jie(Se.map(bt=>({id:bt.id,instruction:bt.instruction,finalizedVariant:bt.finalizedVariant,styleVariants:bt.styleVariants,selectedVariantIndex:bt.selectedVariantIndex,variantGenerationStatus:bt.variantGenerationStatus,requestedVariantCount:bt.requestedVariantCount})),Ze,Kt);for(const bt of Ce)St.push({id:bt.id,kind:"interface",detail:DD(bt)});const rn=Q.current;if(!at||!rn)return St;const wn=new Set(rn.commentIds),Un=new Map;return Ze.forEach(bt=>{Un.set(bt.id,bt.key)}),Kt.forEach(bt=>{Un.set(bt.id,bt.key)}),rn.changeIds.forEach(bt=>{const Rn=Un.get(bt);Rn&&wn.add(Rn)}),St.filter(bt=>!wn.has(bt.id))},[w,S,T,at,Z,Ce]),Ac=h.useCallback(async Se=>{if(Se.kind==="interface"){ge({controlId:Se.id,value:void 0});return}if(Se.kind==="comment"){f(Kt=>{const St=Kt.get(Se.id),rn=(m==null?void 0:m.current)??null;rn&&(St==null?void 0:St.previewBaselineStyle)!==void 0&&Vu(rn,[St]);const wn=new Map(Kt);return wn.delete(Se.id),wn});return}if(!T)return;const dt=T.getChanges().find(Kt=>rc(Kt)===Se.id);if(!dt){Ut.warn("No tracked change for pending row",Se.id);return}const Ze=await T.revertSpecificChange(dt);if(!Ze.ok){Ut.error("revertSpecificChange failed:",Ze.error.message),ct.error("Could not revert change");return}await r()},[T,f,r,m,ge]),Uo=Te?$t||(j&&(ye==null?void 0:ye.status)!=="APPLYING"?Eie:j?Cie:null):null,Lp=y.jsx(J0e,{chatMessages:e,statusHint:Uo,handleChatSend:ro,handleStop:Uv,isProcessing:at,pendingChangeRows:Wi,onRemovePendingChange:Ac,onApplyPendingChanges:Mn,onClearPendingChanges:pr,disableInputWhileProcessing:je!=="embedded",showModelPicker:je!=="embedded"}),jp=y.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center",children:[y.jsx("p",{className:"text-sm text-content-subtle",children:"Select an element to edit, or leave a comment on the page."}),Uo&&y.jsx("p",{className:"mt-2 text-xs text-content-subtle",children:Uo})]});return(()=>{const Se=_ie({isMCPSession:Te,isChatOpen:J,hasSelectedElement:!!o,isVariantsPanelOpen:it,hasPendingChanges:Wi.length>0,changeCount:S,isPublishing:j,isProcessing:at,hasStatusHint:!!Uo,shouldUseAgentChat:je==="embedded"}),He=o?y.jsx(fye,{propertyCategories:Mw,formattedComputedStyles:Rt,pendingChanges:H,handlePendingCssChange:Ss,handlePendingPercentageChange:Hd,applyPropertyChange:cn,previewPropertyChange:ir,performTransaction:Hn,handleBlur:Bv},o.xpath):null,dt=Y&&Gt==="edit"?y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[y.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto scrollbar-hide",children:[y.jsx(Vye,{}),Se.showDesignPanel?He:null]}),Wi.length>0?y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-3 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}):null,y.jsx(Wye,{})]}):Gt==="edit"&&Se.showDesignPanel&&He?He:it?y.jsx(Qee,{}):Se.showChatPanel?Lp:Se.showDesignPanel?He:Se.showMCPEmptyState?jp:null,Ze=Wi.length;return y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[E&&!it?y.jsx("div",{className:"flex flex-shrink-0 items-center border-b border-main-border bg-main-light px-4 py-1.5 text-xs text-content-subtle",children:y.jsxs("span",{className:"truncate",children:["Editing"," ",y.jsx("span",{className:"font-medium text-content",children:E})]})}):null,dt,Se.showExternalPendingChanges&&y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-4 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}),Se.showExternalStatusHint&&Uo&&y.jsx("div",{className:`flex-shrink-0 px-4 py-2 ${Wi.length===0?"border-t border-main-border":""}`,children:y.jsx("p",{className:"text-center text-xs text-content-subtle",children:Uo})}),(Se.showActionBar||Y&&Gt==="edit"&&Wi.length>0)&&y.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-main-border bg-main-light px-4 py-3",children:[y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:n,disabled:!(T!=null&&T.canUndo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Undo (Cmd+Z)",children:y.jsx(Fh,{className:"h-4 w-4"})}),y.jsx("button",{onClick:zv,disabled:!(T!=null&&T.canRedo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Redo (Cmd+Shift+Z)",children:y.jsx(uG,{className:"h-4 w-4"})})]}),y.jsx("button",{onClick:Mn,disabled:j||at,className:"rounded border border-primary px-3 py-1 text-xs font-medium text-gray-300 hover:bg-primary-hover disabled:cursor-not-allowed disabled:opacity-30",title:Te?`Send ${Ze||"pending"} changes to ${Tt||"Claude Code"}`:"Apply all pending changes (⌘↵)","data-cy":"inspector-apply-button",children:Aie({isMCPSession:Te,isApplying:j||at,pendingChangeCount:Ze})})]})]})})()},G2e=Mt("useServerConfig"),q2e=()=>{const[e,t]=h.useState(null),[n,r]=h.useState(!0),[i,s]=h.useState(null),o=h.useCallback(async()=>{var a;try{r(!0),s(null);const c=await fetch("/api/health");if(!c.ok)throw new Error(`Failed to fetch config: ${c.status}`);const u=await c.json();if(!u.framework)throw new Error("Server did not return framework information");const f={userPort:((a=u.ports)==null?void 0:a.userDevServer)||3e3,framework:u.framework};return t(f),f}catch(c){const u=c instanceof Error?c.message:"Failed to fetch server config";throw s(u),G2e.warn("Error fetching server config:",c),c}finally{r(!1)}},[]);return{config:e,fetchConfig:o,isLoading:n,error:i}},K2e="data:image/svg+xml,%3csvg%20width='453'%20height='416'%20viewBox='0%200%20453%20416'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23clip0_1326_108)'%3e%3cpath%20d='M186.07%2025.5539C186.07%2011.4409%20197.511%200%20211.624%200H335.5C400.393%200%20453%2052.6065%20453%20117.5C453%20182.393%20400.393%20235%20335.5%20235H216.639C199.756%20235%20186.07%20221.314%20186.07%20204.431C186.07%20186.743%20198.071%20169.863%20215.299%20165.853C225.291%20163.528%20238.671%20160.53%20256.58%20156.667C258.587%20156.234%20260.54%20155.796%20262.442%20155.354C307.627%20144.861%20299.146%20103.217%20256.58%2084.7815C234.082%2075.0381%20218.731%2068.1115%20208.265%2063.1881C194.851%2056.8779%20186.07%2040.378%20186.07%2025.5539Z'%20fill='white'/%3e%3cpath%20d='M381.709%20415.715C329.789%20415.715%20287.699%20373.625%20287.699%20321.705V314.306C287.699%20288.346%20308.744%20267.301%20334.704%20267.301C386.624%20267.301%20428.714%20309.391%20428.714%20361.311V368.71C428.714%20394.67%20407.669%20415.715%20381.709%20415.715Z'%20fill='white'/%3e%3cpath%20d='M0%2073.5927C0%2033.1632%2032.7745%200.388672%2073.2039%200.388672C113.633%200.388672%20146.408%2033.1632%20146.408%2073.5926V338.795C146.408%20379.225%20113.633%20411.999%2073.2039%20411.999C32.7745%20411.999%200%20379.225%200%20338.795V73.5927Z'%20fill='white'/%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='clip0_1326_108'%3e%3crect%20width='453'%20height='416'%20fill='white'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",Lm=(e,t)=>y.jsxs("div",{className:"flex flex-row items-center gap-2",children:[y.jsx("span",{children:e}),t?y.jsx("span",{className:"rounded bg-white/15 px-1.5 py-0.5 text-[10px] leading-none font-bold",children:t}):null]}),Y2e={type:"spring",duration:.3,bounce:0},X2e=({mode:e,onModeChange:t,isLoading:n=!1,disabled:r=!1})=>{const[i,s]=h.useState(!1),o=ke(ji),a=ke(m$),[c,u]=Vn(bp);ke(Ui);const f=Be(Ui),p=Be(Js),m=Be(E$),g=ke(hd),b=Be(hd),x=ke(eo),C=e!=="view"||i||g,E=Array.from(o.values()).filter(P=>P.status==="pending").length+a,A=()=>{c?u(!1):(u(!0),g||(f(null),p("comment"),m(P=>P+1)))},T=()=>{g||(b(!0),u(!0),p("comment"),vt.capture("variants_panel.opened",{source:"control_bar",hasActiveSession:x.active}))},M=c?"Close panel":"Open panel",I=(P,S,D,R,L)=>{const j=r?"Disconnected":S,O=e===P&&!g;return y.jsx(Fi,{label:Lm(j,r?void 0:D),disabled:!C,children:y.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),b(!1),u(!0),t(P)},disabled:r,className:`rounded-md p-2 transition-colors ${O?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":L,children:R})})};return y.jsxs(mn.div,{className:"z-ui-primary absolute right-6 bottom-6",initial:{y:100,opacity:0},animate:{y:n?100:0,opacity:n?0:1},transition:{duration:.6,ease:"easeOut",delay:n?0:.3},children:[E>0&&!C&&!g&&y.jsx(mn.span,{className:"bg-primary pointer-events-none absolute -top-1 -right-1 z-10 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[9px] leading-none font-bold text-white",animate:{opacity:1},transition:{duration:.15,delay:.2},children:E>9?"9+":E}),y.jsxs(mn.div,{layout:!0,className:`border-primary/30 bg-main overflow-hidden border shadow-lg ${C?"":"cursor-pointer"}`,style:{borderRadius:C?10:9999},transition:Y2e,onClick:C?void 0:()=>t("comment"),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[y.jsx(mn.div,{className:"absolute flex items-center justify-center",style:{width:40,height:40,top:0,left:0},animate:{opacity:C?0:1},transition:C?{duration:0}:{duration:0,delay:.2},"aria-hidden":C,children:y.jsx("img",{src:K2e,alt:"Rivet",style:{width:16,height:16}})}),!C&&y.jsx("div",{style:{width:40,height:40}}),y.jsxs(mn.div,{className:"flex items-center gap-1 p-2",style:{position:C?"relative":"absolute",inset:0,pointerEvents:C?"auto":"none"},animate:{opacity:C?1:0},transition:C?{duration:0,delay:.22}:{duration:0},children:[y.jsx(Fi,{label:Lm(r?"Disconnected":"Explore",r?void 0:"E"),disabled:!C,children:y.jsxs("button",{type:"button",onClick:P=>{P.stopPropagation(),T()},disabled:r,className:`relative rounded-md p-2 transition-colors ${g?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-variants",children:[y.jsx(s8,{className:"h-5 w-5",weight:"bold"}),x.active&&!g&&y.jsx("span",{className:"bg-primary absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full","aria-label":"Active explore session"})]})}),I("edit","Refine","R",y.jsx(xG,{className:"h-5 w-5"}),"mode-design"),y.jsx("div",{className:"bg-primary/20 mx-1 h-4 w-px"}),y.jsx(Fi,{label:Lm(r?"Disconnected":M,r?void 0:"P"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),A()},disabled:r,className:`text-content hover:bg-main-input relative rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-panel",children:y.jsx(Oh,{className:"h-5 w-5",weight:"bold",style:c?{transform:"scaleX(-1)"}:void 0})})}),y.jsx(Fi,{label:Lm(r?"Disconnected":"Collapse",r?void 0:"X"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),t("view"),b(!1),u(!1),s(!1)},disabled:r,"aria-label":"Collapse",className:`text-content hover:bg-main-input rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"mode-view",children:y.jsx(Ho,{className:"h-5 w-5",weight:"bold"})})})]})]})]})},Q2e=async()=>{let e;try{e=await fetch("/api/mcp/status")}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}if(e.status===404||!(e.headers.get("content-type")??"").toLowerCase().includes("application/json"))return jm();if(!e.ok)return{isOk:!1,unavailableReason:"rivet_unreachable"};let n;try{n=await e.json()}catch{return jm()}const r=n.devServerHealth;return r?r.ownership==="none"?{isOk:!1,unavailableReason:"upstream_unreachable"}:r.isReachable===!0?{isOk:!0,unavailableReason:"upstream_unreachable"}:{isOk:!1,unavailableReason:r.reason==="rivet_unreachable"?"rivet_unreachable":"upstream_unreachable"}:jm()},jm=async()=>{try{const e=await fetch("/");return{isOk:e.status!==502&&e.status!==503,unavailableReason:"upstream_unreachable"}}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}},FP=Mt("usePreviewUpstreamHealth"),J2e=500,ebe=4e3,tbe=15e3,nbe=(e,t={})=>{const n=h.useRef(null),r=h.useRef(null),i=t.probeMsWhileDown??J2e,s=t.probeMsWhileUp??ebe,o=t.firstUnreachableCaptureAfterMs??tbe,a=t.rerunProbeImmediatelyOnVersion,c=t.skip??!1,[u,f]=h.useState(e==="static"),[p,m]=h.useState(0),[g,b]=h.useState(null),[x,C]=h.useState(0),[w,E]=h.useState(!1),[A,T]=h.useState(!1),[M,I]=h.useState(e==="static"?null:"upstream_unreachable");return h.useEffect(()=>{if(e==="static"){f(!0),b(null),C(0),E(!1),T(!0),I(null);return}if(c){f(!1),b(null),C(0),E(!1),T(!0),I("upstream_unreachable"),n.current=null;return}let P=!0;const S=Date.now();b(S),C(0),E(!1),f(!1),T(!1),I("upstream_unreachable");const D={current:!1},R={current:!1},L={current:!1},j={current:null},O={current:!1};let H=null;const B=()=>{L.current||(L.current=!0,P&&T(!0))},Z=()=>{H!==null&&(clearTimeout(H),H=null)},K=(Q,F)=>{Z(),H=setTimeout(F,Q)},q=async()=>{if(!P)return;C(N=>N+1);const{isOk:Q,unavailableReason:F}=await Q2e();if(!P)return;if(B(),Q){const N=!O.current;O.current=!0,f(!0),I(null),j.current=null,R.current=!1,E(!1),D.current?N&&(vt==null||vt.capture("preview_upstream_restored",{framework:e})):(D.current=!0,vt==null||vt.capture("preview_dev_server_ready",{framework:e,ready_after_ms:Date.now()-S})),K(s,q);return}const V=O.current;O.current=!1,f(!1),I(F),j.current===null&&(j.current=Date.now(),R.current=!1,E(!1)),V&&(vt==null||vt.capture("preview_upstream_lost",{framework:e}),m(N=>N+1),FP.warn("Preview upstream became unavailable after it was ready"));const W=Date.now()-j.current;W>=o&&!R.current&&(R.current=!0,E(!0),vt==null||vt.capture("preview_dev_server_unreachable",{framework:e,elapsed_ms:W}),FP.warn("Dev server did not become ready within timeout window")),K(i,q)};return n.current=()=>K(0,q),K(0,q),()=>{P=!1,n.current=null,Z()}},[e,i,s,o,c]),h.useEffect(()=>{var S;if(e==="static"||a===void 0)return;const P=r.current;r.current=a,P!==null&&P!==a&&((S=n.current)==null||S.call(n))},[e,a]),{isUpstreamReady:u,iframeRemountKey:p,probeStartedAt:g,probeAttemptCount:x,isFirstUnreachableWindowExceeded:w,initialProbeComplete:A,unavailableReason:M}};function rbe(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),r=n.createElement("base"),i=n.createElement("a");return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}const ibe=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function Va(e){const t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}let mu=null;function LV(e={}){return mu||(e.includeStyleProperties?(mu=e.includeStyleProperties,mu):(mu=Va(window.getComputedStyle(document.documentElement)),mu))}function T1(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function sbe(e){const t=T1(e,"border-left-width"),n=T1(e,"border-right-width");return e.clientWidth+t+n}function obe(e){const t=T1(e,"border-top-width"),n=T1(e,"border-bottom-width");return e.clientHeight+t+n}function jV(e,t={}){const n=t.width||sbe(e),r=t.height||obe(e);return{width:n,height:r}}function abe(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const hi=16384;function lbe(e){(e.width>hi||e.height>hi)&&(e.width>hi&&e.height>hi?e.width>e.height?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi):e.width>hi?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi))}function P1(e){return new Promise((t,n)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function cbe(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function ube(e,t,n){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${n}`),i.setAttribute("viewBox",`0 0 ${t} ${n}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),i.appendChild(s),s.appendChild(e),cbe(i)}const si=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||si(n,t)};function dbe(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function fbe(e,t){return LV(t).map(n=>{const r=e.getPropertyValue(n),i=e.getPropertyPriority(n);return`${n}: ${r}${i?" !important":""};`}).join(" ")}function hbe(e,t,n,r){const i=`.${e}:${t}`,s=n.cssText?dbe(n):fbe(n,r);return document.createTextNode(`${i}{${s}}`)}function OP(e,t,n,r){const i=window.getComputedStyle(e,n),s=i.getPropertyValue("content");if(s===""||s==="none")return;const o=ibe();try{t.className=`${t.className} ${o}`}catch{return}const a=document.createElement("style");a.appendChild(hbe(o,n,i,r)),t.appendChild(a)}function pbe(e,t,n){OP(e,t,":before",n),OP(e,t,":after",n)}const VP="application/font-woff",HP="image/jpeg",mbe={woff:VP,woff2:VP,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:HP,jpeg:HP,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function gbe(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function Pk(e){const t=gbe(e).toLowerCase();return mbe[t]||""}function vbe(e){return e.split(/,/)[1]}function E6(e){return e.search(/^(data:)/)!==-1}function ybe(e,t){return`data:${t};base64,${e}`}async function FV(e,t,n){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise((s,o)=>{const a=new FileReader;a.onerror=o,a.onloadend=()=>{try{s(n({res:r,result:a.result}))}catch(c){o(c)}},a.readAsDataURL(i)})}const bx={};function bbe(e,t,n){let r=e.replace(/\?.*/,"");return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function Ik(e,t,n){const r=bbe(e,t,n.includeQueryParams);if(bx[r]!=null)return bx[r];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let i;try{const s=await FV(e,n.fetchRequestInit,({res:o,result:a})=>(t||(t=o.headers.get("Content-Type")||""),vbe(a)));i=ybe(s,t)}catch(s){i=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;s&&(o=typeof s=="string"?s:s.message),o&&console.warn(o)}return bx[r]=i,i}async function xbe(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):P1(t)}async function wbe(e,t){if(e.currentSrc){const s=document.createElement("canvas"),o=s.getContext("2d");s.width=e.clientWidth,s.height=e.clientHeight,o==null||o.drawImage(e,0,0,s.width,s.height);const a=s.toDataURL();return P1(a)}const n=e.poster,r=Pk(n),i=await Ik(n,r,t);return P1(i)}async function kbe(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await Fv(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function Cbe(e,t){return si(e,HTMLCanvasElement)?xbe(e):si(e,HTMLVideoElement)?wbe(e,t):si(e,HTMLIFrameElement)?kbe(e,t):e.cloneNode(OV(e))}const Ebe=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",OV=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function Sbe(e,t,n){var r,i;if(OV(t))return t;let s=[];return Ebe(e)&&e.assignedNodes?s=Va(e.assignedNodes()):si(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?s=Va(e.contentDocument.body.childNodes):s=Va(((i=e.shadowRoot)!==null&&i!==void 0?i:e).childNodes),s.length===0||si(e,HTMLVideoElement)||await s.reduce((o,a)=>o.then(()=>Fv(a,n)).then(c=>{c&&t.appendChild(c)}),Promise.resolve()),t}function _be(e,t,n){const r=t.style;if(!r)return;const i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):LV(n).forEach(s=>{let o=i.getPropertyValue(s);s==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),si(e,HTMLIFrameElement)&&s==="display"&&o==="inline"&&(o="block"),s==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),r.setProperty(s,o,i.getPropertyPriority(s))})}function Abe(e,t){si(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),si(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function Tbe(e,t){if(si(e,HTMLSelectElement)){const r=Array.from(t.children).find(i=>e.value===i.getAttribute("value"));r&&r.setAttribute("selected","")}}function Pbe(e,t,n){return si(t,Element)&&(_be(e,t,n),pbe(e,t,n),Abe(e,t),Tbe(e,t)),t}async function Ibe(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const r={};for(let s=0;s<n.length;s++){const a=n[s].getAttribute("xlink:href");if(a){const c=e.querySelector(a),u=document.querySelector(a);!c&&u&&!r[a]&&(r[a]=await Fv(u,t,!0))}}const i=Object.values(r);if(i.length){const s="http://www.w3.org/1999/xhtml",o=document.createElementNS(s,"svg");o.setAttribute("xmlns",s),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const a=document.createElementNS(s,"defs");o.appendChild(a);for(let c=0;c<i.length;c++)a.appendChild(i[c]);e.appendChild(o)}return e}async function Fv(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>Cbe(r,t)).then(r=>Sbe(e,r,t)).then(r=>Pbe(e,r,t)).then(r=>Ibe(r,t))}const VV=/url\((['"]?)([^'"]+?)\1\)/g,Mbe=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Rbe=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function $be(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function Dbe(e){const t=[];return e.replace(VV,(n,r,i)=>(t.push(i),n)),t.filter(n=>!E6(n))}async function Nbe(e,t,n,r,i){try{const s=n?rbe(t,n):t,o=Pk(t);let a;return i||(a=await Ik(s,o,r)),e.replace($be(t),`$1${a}$3`)}catch{}return e}function Lbe(e,{preferredFontFormat:t}){return t?e.replace(Rbe,n=>{for(;;){const[r,,i]=Mbe.exec(n)||[];if(!i)return"";if(i===t)return`src: ${r};`}}):e}function HV(e){return e.search(VV)!==-1}async function BV(e,t,n){if(!HV(e))return e;const r=Lbe(e,n);return Dbe(r).reduce((s,o)=>s.then(a=>Nbe(a,o,t,n)),Promise.resolve(r))}async function gu(e,t,n){var r;const i=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(i){const s=await BV(i,null,n);return t.style.setProperty(e,s,t.style.getPropertyPriority(e)),!0}return!1}async function jbe(e,t){await gu("background",e,t)||await gu("background-image",e,t),await gu("mask",e,t)||await gu("-webkit-mask",e,t)||await gu("mask-image",e,t)||await gu("-webkit-mask-image",e,t)}async function Fbe(e,t){const n=si(e,HTMLImageElement);if(!(n&&!E6(e.src))&&!(si(e,SVGImageElement)&&!E6(e.href.baseVal)))return;const r=n?e.src:e.href.baseVal,i=await Ik(r,Pk(r),t);await new Promise((s,o)=>{e.onload=s,e.onerror=t.onImageErrorHandler?(...c)=>{try{s(t.onImageErrorHandler(...c))}catch(u){o(u)}}:o;const a=e;a.decode&&(a.decode=s),a.loading==="lazy"&&(a.loading="eager"),n?(e.srcset="",e.src=i):e.href.baseVal=i})}async function Obe(e,t){const r=Va(e.childNodes).map(i=>zV(i,t));await Promise.all(r).then(()=>e)}async function zV(e,t){si(e,Element)&&(await jbe(e,t),await Fbe(e,t),await Obe(e,t))}function Vbe(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(i=>{n[i]=r[i]}),e}const BP={};async function zP(e){let t=BP[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},BP[e]=t,t}async function UP(e,t){let n=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,s=(n.match(/url\([^)]+\)/g)||[]).map(async o=>{let a=o.replace(r,"$1");return a.startsWith("https://")||(a=new URL(a,e.url).href),FV(a,t.fetchRequestInit,({result:c})=>(n=n.replace(o,`url(${c})`),[o,c]))});return Promise.all(s).then(()=>n)}function ZP(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(n,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const c=i.exec(r);if(c===null)break;t.push(c[0])}r=r.replace(i,"");const s=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,o="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",a=new RegExp(o,"gi");for(;;){let c=s.exec(r);if(c===null){if(c=a.exec(r),c===null)break;s.lastIndex=a.lastIndex}else a.lastIndex=s.lastIndex;t.push(c[0])}return t}async function Hbe(e,t){const n=[],r=[];return e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach((s,o)=>{if(s.type===CSSRule.IMPORT_RULE){let a=o+1;const c=s.href,u=zP(c).then(f=>UP(f,t)).then(f=>ZP(f).forEach(p=>{try{i.insertRule(p,p.startsWith("@import")?a+=1:i.cssRules.length)}catch(m){console.error("Error inserting rule from remote css",{rule:p,error:m})}})).catch(f=>{console.error("Error loading remote css",f.toString())});r.push(u)}})}catch(s){const o=e.find(a=>a.href==null)||document.styleSheets[0];i.href!=null&&r.push(zP(i.href).then(a=>UP(a,t)).then(a=>ZP(a).forEach(c=>{o.insertRule(c,o.cssRules.length)})).catch(a=>{console.error("Error loading remote stylesheet",a)})),console.error("Error inlining remote css file",s)}}),Promise.all(r).then(()=>(e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach(s=>{n.push(s)})}catch(s){console.error(`Error while reading CSS rules from ${i.href}`,s)}}),n))}function Bbe(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>HV(t.style.getPropertyValue("src")))}async function zbe(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=Va(e.ownerDocument.styleSheets),r=await Hbe(n,t);return Bbe(r)}function UV(e){return e.trim().replace(/["']/g,"")}function Ube(e){const t=new Set;function n(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(s=>{t.add(UV(s))}),Array.from(r.children).forEach(s=>{s instanceof HTMLElement&&n(s)})}return n(e),t}async function Zbe(e,t){const n=await zbe(e,t),r=Ube(e);return(await Promise.all(n.filter(s=>r.has(UV(s.style.fontFamily))).map(s=>{const o=s.parentStyleSheet?s.parentStyleSheet.href:null;return BV(s.cssText,o,t)}))).join(`
511
511
  `)}async function Wbe(e,t){const n=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await Zbe(e,t);if(n){const r=document.createElement("style"),i=document.createTextNode(n);r.appendChild(i),e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r)}}async function Gbe(e,t={}){const{width:n,height:r}=jV(e,t),i=await Fv(e,t,!0);return await Wbe(i,t),await zV(i,t),Vbe(i,t),await ube(i,n,r)}async function qbe(e,t={}){const{width:n,height:r}=jV(e,t),i=await Gbe(e,t),s=await P1(i),o=document.createElement("canvas"),a=o.getContext("2d"),c=t.pixelRatio||abe(),u=t.canvasWidth||n,f=t.canvasHeight||r;return o.width=u*c,o.height=f*c,t.skipAutoScale||lbe(o),o.style.width=`${u}`,o.style.height=`${f}`,t.backgroundColor&&(a.fillStyle=t.backgroundColor,a.fillRect(0,0,o.width,o.height)),a.drawImage(s,0,0,o.width,o.height),o}async function Kbe(e,t={}){return(await qbe(e,t)).toDataURL()}const Ybe=e=>{var n;const t=(n=e.ownerDocument)==null?void 0:n.defaultView;return t?e instanceof t.HTMLElement:e instanceof HTMLElement},zf=async e=>{if(!Ybe(e))return null;try{return await Kbe(e,{cacheBust:!0,filter:n=>!(n.id??"").startsWith("rivet-")})}catch{return null}},Fm=Mt("component-search-api"),Xbe=e=>e instanceof Error&&e.name==="AbortError",Qbe=async(e,{signal:t}={})=>{var n;Fm.debug("Searching component for element:",e.tagName);try{const r=await fetch("/api/search-components",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e]),signal:t});if(!r.ok)return Fm.error(`Component search failed: HTTP ${r.status}`),e;const s=(n=(await r.json()).elements)==null?void 0:n[0];return s||(Fm.debug(`No component file found for <${e.tagName}>${e.className?` class="${e.className}"`:""}${e.id?` id="${e.id}"`:""}`),e)}catch(r){if(Xbe(r))throw r;return Fm.error("Component search error:",r),e}},Om=.8,Jbe=.5,I1=()=>{let e=null,t=null,n=null,r=null;const i=o=>{r&&(r.style.left=`${o.left}px`,r.style.top=`${o.top}px`,r.style.width=`${o.width}px`,r.style.height=`${o.height}px`)},s=()=>{if(!e||!t||!r)return;e.left+=(t.left-e.left)*Om,e.top+=(t.top-e.top)*Om,e.width+=(t.width-e.width)*Om,e.height+=(t.height-e.height)*Om,i(e),Math.max(Math.abs(t.left-e.left),Math.abs(t.top-e.top),Math.abs(t.width-e.width),Math.abs(t.height-e.height))>Jbe?n=requestAnimationFrame(s):(e={...t},i(t),n=null)};return{animateTo:(o,a,c=!1)=>{if(r=o,t={...a},c||!e){e={...a},i(a),n&&(cancelAnimationFrame(n),n=null);return}n||(n=requestAnimationFrame(s))},stop:()=>{n&&(cancelAnimationFrame(n),n=null)},reset:()=>{e=null,t=null,n&&(cancelAnimationFrame(n),n=null)}}},exe=32,txe=24,WP=(e,t)=>{const n=t-e;if(n<=0)return[];const r=Math.min(txe,Math.max(2,Math.ceil(n/exe)+1));return Array.from({length:r},(i,s)=>{const o=s/(r-1);return e+n*o})},nxe=(e,t,n)=>{if(typeof e.elementsFromPoint=="function")return e.elementsFromPoint(t,n);if(typeof e.elementFromPoint!="function")return[];const r=e.elementFromPoint(t,n);return r?[r]:[]},rxe=(e,t)=>{const n=new Set,r=WP(t.left,t.right),i=WP(t.top,t.bottom);return r.forEach(s=>{i.forEach(o=>{nxe(e,s,o).forEach(a=>{let c=a;for(;c;)n.add(c),c=c.parentElement})})}),Array.from(n).sort((s,o)=>{var u;if(s===o)return 0;const a=((u=e.defaultView)==null?void 0:u.Node)??Node;return s.compareDocumentPosition(o)&a.DOCUMENT_POSITION_PRECEDING?1:-1})},ZV=(e,t)=>rxe(e,t).filter(r=>{const i=r.getBoundingClientRect();return i.left<t.right&&i.right>t.left&&i.top<t.bottom&&i.bottom>t.top&&i.width>0&&i.height>0}),xx=new WeakMap,ixe=e=>{let t=null;return{schedule:()=>{t===null&&(t=window.requestAnimationFrame(()=>{t=null,e()}))},cancel:()=>{t!==null&&(window.cancelAnimationFrame(t),t=null)}}},sxe=e=>{var u;const t=xx.get(e);if(t)return t;const n=new Set,r=()=>{n.forEach(f=>f.handleChange())},i=()=>{n.forEach(f=>f.handleScroll())},s=new MutationObserver(r),o=e.body,a=((u=e.defaultView)==null?void 0:u.Node)??Node;if(o instanceof a)try{s.observe(o,{childList:!0,subtree:!0,attributes:!0})}catch{}e.addEventListener("scroll",i,!0);const c={subscribers:n,disconnect:()=>{s.disconnect(),e.removeEventListener("scroll",i,!0),xx.delete(e)}};return xx.set(e,c),c},oxe=(e,t)=>{const n=sxe(e);return n.subscribers.add(t),()=>{n.subscribers.delete(t),n.subscribers.size===0&&n.disconnect()}},WV=({iframe:e,onChange:t,onScroll:n})=>{const r=ixe(t);let i=null,s=null;const o=()=>{r.schedule()},a=()=>{n==null||n(),r.schedule()},c=()=>{s==null||s(),s=null},u=p=>{c(),s=oxe(p,{handleChange:o,handleScroll:a}),r.schedule()},f=()=>{const p=e==null?void 0:e.contentDocument;p&&u(p)};return e&&(i=new ResizeObserver(o),i.observe(e),e.contentDocument&&u(e.contentDocument),e.addEventListener("load",f)),()=>{e==null||e.removeEventListener("load",f),i==null||i.disconnect(),c(),r.cancel()}},dl={theme:{extend:{fontFamily:{main:["Satoshi","Inter","system-ui","-apple-system","Segoe UI","sans-serif"]},zIndex:{"resize-handle":"36","capture-overlay":"35","selection-overlay":"34","hover-overlay":"30","element-overlay":"25"},colors:{primary:{DEFAULT:"#FF3300",border:"#ff6b35"}}}}},Ov=dl.theme.extend.zIndex,Vv=dl.theme.extend.colors,axe=e=>Array.from(e.childNodes).filter(n=>n.nodeType===Node.TEXT_NODE).map(n=>{var r;return((r=n.textContent)==null?void 0:r.trim())||""}).join("").length>0,lxe=e=>{const t=e.tagName.toLowerCase();return!!(["path","g","circle","rect","line","polygon"].includes(t)||t==="i"&&e.className&&/\b(fa|icon|material)\b/.test(e.className))},cxe=(e,t,n=6)=>{const i=e.map(o=>{const a=o.getBoundingClientRect(),u=a.width*a.height/t,f=o.tagName.toLowerCase();let p=u>=.2&&u<=3?100:20;return["button","a","input","select","textarea"].includes(f)&&(p+=50),(u<.05||u>10)&&(p-=50),{element:o,score:p,ratio:u}}).filter(o=>o.score>30).filter(o=>!lxe(o.element)).sort((o,a)=>a.score-o.score),s=[];for(const o of i)s.some(c=>c.element.contains(o.element))||s.push(o);return s.slice(0,n).map(o=>o.element)},uxe=(e,t,n=6)=>e.map(i=>{const s=i.boundingRect,a=s.width*s.height/t,c=i.tagName.toLowerCase();let u=a>=.2&&a<=3?100:20;return["button","a","input","select","textarea"].includes(c)&&(u+=50),(a<.05||a>10)&&(u-=50),{element:i,score:u,ratio:a}}).filter(({element:i,score:s})=>{const o=i.tagName.toLowerCase();return s>30&&!["path","g","circle","rect","line","polygon"].includes(o)}).sort((i,s)=>s.score-i.score).slice(0,n).map(({element:i})=>i),wx=!1,dxe=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H8.5L4 20V6a2 2 0 0 1 2-2z' fill='%23FF3300' stroke='white' stroke-width='1.5'/%3E%3Cpath d='M9 9h6M9 12h4' stroke='white' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") 4 20, auto`,GV="opacity 0.15s ease-out",kx=8,Mk=e=>`rivet-hover-overlay--${e}`,Rk=e=>`rivet-selection-overlay--${e}`,qV=e=>`rivet-box-selection-overlay--${e}`,KV=e=>`rivet-mouse-capture--${e}`,S6="rivet-selection-overlay--",fxe="rivet-hover-overlay--",YV='[data-rivet-variant-root="true"]',hxe=`${YV} button[data-action]`,Vm=e=>e.closest(YV)!=null,pxe=(e,t,n)=>{const r=Br(e);if(!r)return null;const i=e.getBoundingClientRect(),s=t-i.left,o=n-i.top,a=Array.from(r.querySelectorAll(hxe));for(const c of a){const u=c.getBoundingClientRect();if(s>=u.left&&s<=u.right&&o>=u.top&&o<=u.bottom)return c}return null},mxe=e=>{const t=Mk(e);let n=document.getElementById(t);return n||(n=document.createElement("div"),n.id=t,n.style.cssText=`
512
512
  position: fixed;
513
513
  pointer-events: none;
@@ -608,7 +608,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
608
608
  background: transparent;
609
609
  pointer-events: none;
610
610
  display: none;
611
- `,this.iframeRef.parentElement.appendChild(t)),t}removeMouseCaptureOverlay(){var n;if(!((n=this.iframeRef)!=null&&n.parentElement))return;const t=this.iframeRef.parentElement.querySelector("#rivet-mouse-capture");t&&t.remove()}isOverlayInSidebar(t,n,r,i){const s=document.querySelector('[data-cy="element-inspector"]');if(!s)return!1;const o=s.getBoundingClientRect(),a=t+r,c=n+i;return!(a<=o.left||t>=o.right||c<=o.top||n>=o.bottom)}getComputedStyles(){if(!this.currentElement||!this.iframeRef)return Zf.warn("Attempt to get computed styles failed: currentElement ",this.currentElement,"iFrameRef:",this.iframeRef),{};const t=this.iframeRef.contentWindow;if(!t)return Zf.warn("Attempt to get computed styles failed: iFrameWindow not defined"),{};const n=t.getComputedStyle(this.currentElement),r={};for(let i=0;i<n.length;i++){const s=n[i];r[s]=n.getPropertyValue(s)}return r.background=AA(r),r}onStylesChanged(t){return this.onStylesChangedCallback=t,()=>{this.onStylesChangedCallback=null}}refreshStyles(){const t=this.getComputedStyles();this.notifyStylesChanged(t)}setCurrentElement(t){this.currentElement=t,t&&this.refreshStyles()}notifyStylesChanged(t){this.onStylesChangedCallback&&this.onStylesChangedCallback(t)}async applyStyle(t,n,r){const i=await this.findElement(t);if(!i.ok)return ei(i.error);const s=i.value;t.rivetId&&this.injectRivetId(s,t.rivetId);try{return s.style[n]=r,as(void 0)}catch(o){return ei(new MJ(n,r,o instanceof Error?o.message:String(o)))}}async getComputedStylesForElement(t){const n=await this.findElement(t);if(!n.ok)return ei(n.error);const r=n.value;if(!this.iframeRef)return ei(new ru(t,"Iframe ref is null"));const i=this.iframeRef.contentWindow;if(!i)return ei(new ru(t,"Iframe window is null"));try{const s=i.getComputedStyle(r),o={};for(let a=0;a<s.length;a++){const c=s[a];o[c]=s.getPropertyValue(c)}return o.background=AA(o),as(o)}catch(s){return ei(new ru(t,s instanceof Error?s.message:String(s)))}}async findElement(t){if(!this.iframeRef)return ei(new ru(t,"Iframe ref is null"));const n=Br(this.iframeRef);if(!n)return ei(new ru(t,"Cannot access iframe document"));if(t.rivetId){const r=n.querySelector(`[data-rivet-id="${t.rivetId}"]`);if(r)return as(r)}if(t.xpath){const r=Fu(n,t.xpath);if(r)return as(r)}if(t.cssSelector)try{const r=n.querySelector(t.cssSelector);if(r)return as(r)}catch(r){Zf.warn("Invalid CSS selector:",t.cssSelector,r)}return ei(new ru(t,"Element not found using any identifier strategy"))}injectRivetId(t,n){t.setAttribute("data-rivet-id",n)}createElementIdentifier(t){const n=t.getAttribute("data-rivet-id"),r=G1(t);let i;if(t.id)i=`#${t.id}`;else if(t.className&&typeof t.className=="string"){const s=t.className.trim().split(/\s+/).join(".");s&&(i=`${t.tagName.toLowerCase()}.${s}`)}return{rivetId:n||"",xpath:r,cssSelector:i}}onHMR(t){var o;this.hmrCallbacks.push(t);let n=null,r=null;const i=()=>{r&&clearTimeout(r),r=setTimeout(()=>{this.handleIframeLoad()},1e3)};this.iframeRef&&this.hmrCallbacks.length===1&&this.iframeRef.addEventListener("load",this.handleIframeLoad);const s=this.iframeRef?Br(this.iframeRef):null;if(s){n=new MutationObserver(u=>{u.some(p=>{var g;const m=p.target;return!((g=m.closest)!=null&&g.call(m,'[id^="rivet-"]'))})&&i()});const a=s.body??s.documentElement??s,c=((o=s.defaultView)==null?void 0:o.Node)??Node;if(a instanceof c)try{n.observe(a,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","src","href"],characterData:!0})}catch{}}return()=>{const a=this.hmrCallbacks.indexOf(t);a!==-1&&this.hmrCallbacks.splice(a,1),n==null||n.disconnect(),r&&clearTimeout(r),this.hmrCallbacks.length===0&&this.iframeRef&&this.iframeRef.removeEventListener("load",this.handleIframeLoad)}}forceReload(){return new Promise((t,n)=>{var a;if(!((a=this.iframeRef)!=null&&a.contentWindow)){t();return}let r,i=!1;const s=()=>{var c;i||(i=!0,clearTimeout(r),(c=this.iframeRef)==null||c.removeEventListener("load",o))},o=()=>{s(),t()};r=setTimeout(()=>{s(),n(new Error("Iframe reload timeout after 10s"))},1e4),this.iframeRef.addEventListener("load",o);try{this.iframeRef.contentWindow.location.reload()}catch(c){s(),n(c)}})}}class $xe extends JV{}const Dxe={pending:"bg-primary",complete:"bg-accent-success",error:"bg-accent-error"},A6=36,T6=28,gg=10,P6=gg/2,s9=A6/2,o9=T6+P6,a9=8,Nxe=.65,l9=200,c9=8,Lxe=(e,t)=>{const n=e-t/2,r=window.innerWidth-t-c9;return Math.max(c9,Math.min(n,r))},eH=({comment:e,index:t,position:n,stale:r=!1,onEdit:i,onHover:s,onHoverEnd:o})=>{var b;const[a,c]=h.useState(!1),u=h.useCallback(x=>{x.stopPropagation(),i(e.id)},[e.id,i]),f=n.y/window.innerHeight>Nxe,p=e.instruction,g=Lxe(n.x,l9)-(n.x-s9);return y.jsxs("div",{className:"fixed",style:{top:f?n.y:n.y-o9,left:n.x-s9,zIndex:a?55:36,opacity:r?.5:1},onMouseEnter:()=>{c(!0),s==null||s()},onMouseLeave:()=>{c(!1),o==null||o()},children:[y.jsxs("div",{className:"relative cursor-pointer",style:{filter:"drop-shadow(0 1px 3px rgba(0,0,0,0.2))"},onClick:u,children:[y.jsx("div",{className:"absolute bg-main",style:{width:gg,height:gg,left:(A6-gg)/2,top:f?-P6:T6-P6,transform:"rotate(45deg)",borderRadius:3}}),y.jsxs("div",{className:"relative flex items-center justify-center rounded-lg bg-main",style:{width:A6,height:T6},children:[y.jsx("div",{className:`flex h-5 w-5 items-center justify-center rounded-full ${Dxe[e.status]}`,children:y.jsx("span",{className:"text-[10px] font-bold leading-none text-white",children:t+1})}),e.variantRequest?y.jsx("div",{"aria-label":"Direction request","data-testid":"comment-marker-variant-glyph",className:"absolute -right-1 -top-1 flex h-3.5 w-3.5 items-center justify-center rounded-full bg-primary text-white",children:y.jsx(s8,{className:"h-2.5 w-2.5",weight:"bold"})}):null]})]}),y.jsx(us,{children:a&&(p||((b=e.images)==null?void 0:b.length))&&y.jsxs(mn.div,{className:"absolute rounded-lg bg-main px-3 py-2 shadow-lg",style:{left:g,top:f?-a9:o9+a9,transformOrigin:f?"bottom center":"top center",width:l9},initial:{scale:.96,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.96,opacity:0,transition:{duration:.06,ease:[.55,0,1,.45]}},transition:{duration:.08,ease:[.165,.84,.44,1]},children:[p?y.jsx("p",{className:"line-clamp-2 text-left text-xs leading-snug text-content",children:p}):null,e.images&&e.images.length>0?y.jsx("div",{className:`flex flex-wrap justify-center gap-1 ${p?"mt-1.5":""}`,children:e.images.map((x,C)=>y.jsx("img",{src:x,alt:`Reference ${C+1}`,className:"max-h-10 rounded border border-divider"},C))}):null]})})]})},jxe=({onEditComment:e,target:t,iframeRef:n})=>{const[r,i]=Vn(ji),[s,o]=h.useState(null),[,a]=h.useState(0),c=h.useRef(null),u=h.useRef(new Map),f=h.useRef(new Set),p=h.useRef(null),m=h.useCallback(()=>{p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null,a(S=>S+1)}))},[]);h.useEffect(()=>{const S=n==null?void 0:n.current;if(!S)return;let D=null;const R=()=>{const O=Br(S);!O||O===D||(D&&D.removeEventListener("scroll",m,!0),D=O,O.addEventListener("scroll",m,!0))},L=()=>{R(),m()};R(),S.addEventListener("load",L),window.addEventListener("resize",m);const j=new ResizeObserver(m);return j.observe(S),c.current=()=>{S.removeEventListener("load",L),window.removeEventListener("resize",m),j.disconnect(),D&&D.removeEventListener("scroll",m,!0),p.current!==null&&(cancelAnimationFrame(p.current),p.current=null)},()=>{var O;return(O=c.current)==null?void 0:O.call(c)}},[n,m]);const g=h.useCallback(S=>{const D=n==null?void 0:n.current;D&&Vu(D,r.values()),i(R=>{const L=new Map(R);return L.delete(S),L})},[i,n,r]),b=Array.from(r.values()).filter(S=>Uh(S.target??Xs,t));if(b.length===0)return null;const x=(n==null?void 0:n.current)??null,C=x?Br(x):null,w=(x==null?void 0:x.getBoundingClientRect())??null,E=(S,D,R,L)=>{const j=u.current.get(S);if(!w)return j?{position:j,stale:!0}:null;if(!C){const Z=D.boundingRect,K={x:w.left+Z.left+R*Z.width,y:w.top+Z.top+L*Z.height};return u.current.set(S,K),{position:K,stale:!0}}const O=Ou(C,D);if(!O){if(!f.current.has(S)){const Z=X$(C,D);console.warn("[CommentMarkerLayer] anchor unresolved",{commentId:S,xpath:D.xpath,rivetId:D.rivetId,byRivetHit:!!Z.byRivet,byXPathHit:!!Z.byXPath,fallback:j?"cached-position":"none"}),f.current.add(S)}return j?{position:j,stale:!0}:null}f.current.delete(S);const H=O.getBoundingClientRect();if(H.bottom<0||H.top>w.height)return null;const B={x:w.left+H.left+R*H.width,y:w.top+H.top+L*H.height};return u.current.set(S,B),{position:B,stale:!1}},A=S=>{if(!S.dragBox||!w)return null;const D=C?Ou(C,S.elementContext):null,R=(D==null?void 0:D.getBoundingClientRect())??S.elementContext.boundingRect,{leftPct:L,topPct:j,widthPct:O,heightPct:H}=S.dragBox;return{left:w.left+R.left+L*R.width,top:w.top+R.top+j*R.height,width:O*R.width,height:H*R.height}},T=S=>{if(!w)return null;const D=!S.finalizedVariant&&(S.selectedVariantIndex??0)===0;if(S.dragBox&&D)return A(S);const R=C?Ou(C,S.elementContext):null,L=(R==null?void 0:R.getBoundingClientRect())??S.elementContext.boundingRect;return{left:w.left+L.left,top:w.top+L.top,width:L.width,height:L.height}},M=s!=null?r.get(s):void 0,I=M?T(M):null,P=!!(M!=null&&M.dragBox&&!M.finalizedVariant&&(M.selectedVariantIndex??0)===0);for(const S of u.current.keys())r.has(S)||u.current.delete(S);return y.jsxs(y.Fragment,{children:[b.map((S,D)=>{const R=E(S.id,S.elementContext,S.pin.elementXPct,S.pin.elementYPct);return R?y.jsx(eH,{comment:S,index:D,position:R.position,stale:R.stale,onDismiss:g,onEdit:e,onHover:()=>o(S.id),onHoverEnd:()=>o(null)},S.id):null}),I&&y.jsx("div",{"data-comment-hover-overlay":"true",style:{position:"fixed",pointerEvents:"none",zIndex:30,border:P?"1px dashed var(--color-primary, #FF3300)":"1px solid var(--color-primary-border, #ff6b35)",background:P?"rgba(255, 51, 0, 0.08)":"transparent",borderRadius:2,boxSizing:"border-box",left:I.left,top:I.top,width:I.width,height:I.height}})]})};function Fxe({reference:e,onRemove:t}){return y.jsxs("span",{className:"inline-flex max-w-[180px] items-center gap-1 rounded-full border border-divider bg-main-light px-2 py-0.5 text-[11px] text-content",children:[y.jsx(MI,{className:"h-3 w-3 shrink-0 text-content-muted",weight:"bold"}),y.jsx("span",{className:"truncate",title:e.label,children:e.label}),y.jsx("button",{type:"button",onClick:t,"aria-label":`Remove reference to ${e.label}`,className:"-mr-0.5 rounded-full p-0.5 text-content-muted transition-colors hover:bg-divider hover:text-content",children:y.jsx(Ho,{className:"h-2.5 w-2.5",weight:"bold"})})]})}const Oxe=Mt("CommentReferencePicker"),Bm=(e,t)=>`${e}:${t}`,tH=e=>`direction-reference-option-${e}`,u9=(e,t,n)=>e.kind==="variant"&&e.sessionId===t&&e.variantId===n;function Vxe({attached:e,commentTarget:t,onChange:n,onClose:r}){const i=ke(eo),s=ke(Z1),o=i.active&&i.projectContext.kind==="fresh"&&i.projectContext.workspaceRoot?i.projectContext.workspaceRoot:s,a=h.useRef(null),c=h.useRef([]),u=h.useRef(!1),f=h.useRef(0),p=h.useRef(void 0),m=h.useRef(null),g=h.useRef(r);g.current=r;const[b,x]=h.useState([]),[C,w]=h.useState(0),E=h.useCallback(async()=>{const B=f.current+1;f.current=B;const Z=o?`?projectPath=${encodeURIComponent(o)}`:"";try{const K=await fetch(`/api/variants/history${Z}`,{credentials:"same-origin"});if(!K.ok)return;const q=await K.json();if(B!==f.current)return;const Q=(q.variants??[]).filter(F=>{var V;return((V=F.preview)==null?void 0:V.kind)==="static"});x(Q)}catch(K){Oxe.warn("failed to load past directions for picker",K)}},[o]),A=h.useCallback(B=>{var q;if((q=m.current)==null||q.call(m),m.current=null,a.current=B,!B){f.current+=1,p.current=void 0;return}u.current||(u.current=!0,B.focus()),p.current!==o&&(p.current=o,E());const Z=Q=>{const F=a.current;F&&(F.contains(Q.target)||g.current())},K=Q=>{Q.key==="Escape"&&g.current()};window.addEventListener("pointerdown",Z),window.addEventListener("keydown",K),m.current=()=>{window.removeEventListener("pointerdown",Z),window.removeEventListener("keydown",K)}},[o,E]),T=h.useMemo(()=>new Set(e.map(B=>Bm(B.sessionId,B.variantId))),[e]),M=h.useMemo(()=>i.active?i.variants.filter(B=>B.status==="succeeded").filter(B=>!u9(t,i.sessionId,B.workItemId)).map(B=>({key:Bm(i.sessionId,B.workItemId),reference:{sessionId:i.sessionId,variantId:B.workItemId,label:B.label||"Direction",origin:"live"}})):[],[i,t]),I=h.useMemo(()=>b.filter(B=>!u9(t,B.sessionId,B.variantId)).map(B=>({key:Bm(B.sessionId,B.variantId),reference:{sessionId:B.sessionId,variantId:B.variantId,label:B.label||"Direction",origin:"history"},brief:B.brief})),[b,t]),P=h.useMemo(()=>{const B=new Set(M.map(Z=>Z.key));return I.filter(Z=>!B.has(Z.key))},[M,I]),S=h.useMemo(()=>{const B=[];return M.length>0&&B.push({heading:"This session",rows:M}),P.length>0&&B.push({heading:"Directions",rows:P}),B},[M,P]),D=h.useMemo(()=>S.flatMap(B=>B.rows),[S]),R=h.useMemo(()=>{const B=new Map;return D.forEach((Z,K)=>B.set(Z.key,K)),B},[D]),L=h.useCallback(B=>{const Z=B.key;T.has(Z)?n(e.filter(K=>Bm(K.sessionId,K.variantId)!==Z)):n([...e,B.reference])},[e,T,n]),j=C<D.length?C:0,O=B=>{var Z;w(B),(Z=c.current[B])==null||Z.scrollIntoView({block:"nearest"})},H=B=>{if(B.key==="Escape"){B.preventDefault(),r();return}const Z=D.length;if(Z!==0)switch(B.key){case"ArrowDown":{B.preventDefault(),O((j+1)%Z);break}case"ArrowUp":{B.preventDefault(),O((j-1+Z)%Z);break}case"Enter":case" ":{B.preventDefault();const K=D[j];K&&L(K);break}}};return y.jsx("div",{ref:A,tabIndex:-1,onKeyDown:H,className:"max-h-72 w-72 overflow-y-auto rounded-lg border border-divider bg-main shadow-2xl focus:outline-none",role:"listbox","aria-label":"Reference a direction","aria-activedescendant":D.length>0?tH(j):void 0,children:S.length===0?y.jsx("div",{className:"px-3 py-4 text-xs text-content-muted",children:"No directions available to reference yet."}):S.map(B=>y.jsx(Hxe,{section:B,attachedKeys:T,highlightedIndex:j,indexOf:Z=>R.get(Z)??-1,itemRefs:c,onToggle:L,onHover:w},B.heading))})}function Hxe({section:e,attachedKeys:t,highlightedIndex:n,indexOf:r,itemRefs:i,onToggle:s,onHover:o}){return y.jsxs("div",{children:[y.jsx("div",{className:"sticky top-0 z-10 border-b border-divider bg-main px-3 py-1.5 text-[10px] font-medium uppercase tracking-wider text-content-muted",children:e.heading}),y.jsx("ul",{className:"py-1",children:e.rows.map(a=>{const c=t.has(a.key),u=r(a.key),f=u===n;return y.jsx("li",{children:y.jsxs("button",{type:"button",id:tH(u),ref:p=>{i.current[u]=p},role:"option",onClick:()=>s(a),onMouseEnter:()=>o(u),"aria-selected":c,className:`group flex w-full items-start gap-2 px-3 py-2 text-left transition-colors ${f?"bg-main-hover":"hover:bg-main-input"}`,children:[y.jsx("span",{className:`mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded border ${c?"border-primary bg-primary text-white":"border-divider text-transparent group-hover:border-content-muted"}`,children:y.jsx(za,{className:"h-2.5 w-2.5",weight:"bold"})}),y.jsxs("span",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:"block truncate text-sm text-content",children:a.reference.label}),a.brief?y.jsx("span",{className:"block truncate text-[11px] leading-snug text-content-muted",children:a.brief}):null]})]})},a.key)})})]})}const d9=3,f9=2,h9=8,Bxe=[/\bvariants?\s*[:=]\s*(\d+)(?!\.\d)\b/i,/\b(\d+)(?!\.\d)\s*variants?\b/i,/\bvariants?\s+(\d+)(?!\.\d)\b/i],zxe=e=>e<f9?f9:e>h9?h9:e,p9=e=>{if(!e)return d9;for(const t of Bxe){const n=t.exec(e);if(!n)continue;const r=n[1];if(!/^\d+$/.test(r))continue;const i=Number.parseInt(r,10);if(!(!Number.isInteger(i)||i<=0))return zxe(i)}return d9},m9=8,g9=320,v9=8,y9=3,Uxe=15e3,Zxe=1,Wxe="7.5rem",Gxe=.65,qxe=({elementContext:e,target:t=Xs,pin:n,dragBox:r,position:i,onClose:s,existingCommentId:o,isMCPSession:a=!1,onInputChange:c,shake:u})=>{var Vt,Gt;const f=bs(),p=rJ(),[m,g]=Vn(ji),b=ke(xp),C=ke(Qs).variants.isEnabled,w=Be(Js),E=Be(bp),A=Be(hd),T=Be(b$),M=bc(),{sendVariantRequestComment:I}=Q$(),P=ke(F8),S=o?m.get(o):void 0,D=(S==null?void 0:S.instruction)??"",[R,L]=h.useState(D),[j,O]=h.useState((S==null?void 0:S.images)??[]),[H,B]=h.useState((S==null?void 0:S.references)??[]),[Z,K]=h.useState(!1),q=h.useRef(null),Q=h.useRef(null),F=h.useRef(null);h.useEffect(()=>{const J=setTimeout(()=>{const Y=q.current;Y&&(Y.focus(),Y.selectionStart=Y.selectionEnd=Y.value.length)},150);return()=>clearTimeout(J)},[]);const V=h.useCallback(()=>{F.current&&(clearTimeout(F.current),F.current=null)},[]);h.useEffect(()=>()=>{V()},[V]);const W=h.useRef(u);h.useEffect(()=>{u!==W.current&&p.start({x:[0,-5,5,-4,4,-2,2,0],y:[0,1.5,-1.5,1,-1,.5,-.5,0],transition:{duration:.45,ease:"easeInOut"}})},[u,p]);const N=R.trim()!==D.trim()&&R.trim()!==""||j.length!==(((Vt=S==null?void 0:S.images)==null?void 0:Vt.length)??0)||H.length!==(((Gt=S==null?void 0:S.references)==null?void 0:Gt.length)??0),z=o?N:R.trim()!=="",ee=h.useCallback(J=>{B(J),c==null||c(R.trim()!==""||j.length>0||J.length>0)},[R,j.length,c]),te=h.useCallback(J=>{ee(H.filter(Y=>!(Y.sessionId===J.sessionId&&Y.variantId===J.variantId)))},[H,ee]),re=h.useCallback(J=>{s(J)},[s]),G=h.useCallback(J=>{J.style.height="auto",J.style.height=`${J.scrollHeight}px`},[]),X=h.useCallback(J=>{T3(J).then(Y=>{O(se=>[...se,Y])}).catch(()=>{console.warn("[CommentPopover] Failed to process image:",J.name)})},[]),de=h.useCallback(J=>{O(Y=>[...Y,J]),c==null||c(!0)},[c]),{isDragOver:ve,dropHandlers:we}=sL(de),Fe=J=>{const Y=J.target.files;if(!Y)return;let se=!1;for(const ce of Array.from(Y))ce.type.startsWith("image/")&&(X(ce),se=!0);Q.current&&(Q.current.value=""),se&&(c==null||c(!0))},Te=J=>{var se;const Y=(se=J.clipboardData)==null?void 0:se.items;if(Y){for(const ce of Array.from(Y))if(ce.type.startsWith("image/")){J.preventDefault();const le=ce.getAsFile();le&&(X(le),c==null||c(!0))}}},je=J=>{const Y=j.filter((se,ce)=>ce!==J);O(Y),c==null||c(R.trim()!==""||Y.length>0)},nt=h.useCallback(async()=>{const J=R.trim();if(J){if(o)g(Y=>{const se=Y.get(o);if(!se)return Y;const ce=new Map(Y);return ce.set(o,{...se,instruction:J,images:j.length>0?j:void 0,references:H.length>0?H:void 0,variantRequest:void 0}),ce}),f==null||f.capture("comment_edited",{instruction_length:J.length,image_count:j.length,reference_count:H.length,has_variants:!1});else{const Y=crypto.randomUUID(),se={id:Y,target:t,elementContext:e,pin:n,dragBox:r,instruction:J,images:j.length>0?j:void 0,references:H.length>0?H:void 0,status:"pending"};g(ce=>{const le=new Map(ce);return le.set(Y,se),le}),f==null||f.capture("comment_added",{instruction_length:J.length,image_count:j.length,reference_count:H.length,has_variants:!1})}re({preserveSelection:!0})}},[R,j,H,o,e,t,n,r,g,f,re]),yt=h.useCallback(async J=>{const Y=R.trim();if(!Y)return;const se=J==="mcp"?p9(R):y9,ce=o??crypto.randomUUID();if(o)g(ge=>{const Ce=ge.get(o);if(!Ce)return ge;const $e=new Map(ge);return $e.set(o,{...Ce,instruction:Y,images:void 0,references:H.length>0?H:void 0,variantRequest:{count:se}}),$e}),f==null||f.capture("comment_edited",{instruction_length:Y.length,image_count:0,reference_count:H.length,has_variants:!1});else{const ge={id:ce,target:t,elementContext:e,pin:n,dragBox:r,instruction:Y,references:H.length>0?H:void 0,variantRequest:{count:se},status:"pending"};g(Ce=>{const $e=new Map(Ce);return $e.set(ce,ge),$e}),f==null||f.capture("comment_added",{instruction_length:Y.length,image_count:0,reference_count:H.length,has_variants:!1})}f==null||f.capture("comment_variant_trigger_started",{source:J,requestedCount:se}),V(),T(!0),F.current=setTimeout(()=>{F.current=null,T(!1)},Uxe),A(!0),E(!0),w("comment"),re({preserveSelection:!0});const le=await I(ce,{transport:J==="desktop"?"desktop":"mcp"});le.cancelled||le.success||(V(),T(!1),ct.error(le.error||"Failed to queue direction request"))},[R,H,o,e,t,n,r,g,f,re,w,E,A,T,I,V]),et=nt,ye=h.useCallback(async()=>{var J;if(o){Bte(o);const Y=(b==null?void 0:b.current)??null;Y&&Vu(Y,m.values());const se=M.get(qa);se&&se.commentId===o&&(await a1(se.diff),M.set(qa,null));const ce=m.get(o),le=(J=ce==null?void 0:ce.finalizedVariant)==null?void 0:J.codeDiff;le&&await a1(le),g(ge=>{const Ce=new Map(ge);return Ce.delete(o),Ce}),f==null||f.capture("comment_deleted")}re()},[o,m,b,g,re,f,M]),Ye=h.useCallback(J=>{if(J.key==="Enter"&&(J.metaKey||J.ctrlKey)){J.preventDefault(),J.nativeEvent.stopImmediatePropagation(),et();return}if(J.key==="Enter"&&!J.shiftKey){J.preventDefault(),J.nativeEvent.stopImmediatePropagation(),et();return}J.key==="Escape"&&(J.preventDefault(),J.nativeEvent.stopImmediatePropagation(),re({preserveSelection:!0}))},[et,re]),$t=window.innerHeight,Tt=i.y/$t>Gxe,Nt=o?"Save":"Add",yn=!o&&(a||C),nn=a?"mcp":"desktop",he=a?"mcp-variant-trigger":"desktop-variant-trigger",be=a?"Generate directions":"Generate 3 directions",We=(()=>{if(R.trim()==="")return"empty_instruction";if(j.length>0)return"images_attached";if(P.getStyleChanges().length>0||P.getTextChanges().length>0)return"mixed_batch";const Y=Array.from(m.values()).filter(le=>le.status==="pending"&&le.id!==o);return Y.some(le=>!!le.variantRequest)?"duplicate_variant_request":Y.some(le=>!le.variantRequest)?"mixed_batch":null})(),ot=a?p9(R):y9,lt=(()=>{switch(We){case"empty_instruction":return"Add an instruction";case"images_attached":return"Remove images";case"mixed_batch":return"Clear pending changes";case"duplicate_variant_request":return"Request already pending";default:return`Explore ${ot} directions`}})();return y.jsx("div",{className:"z-comment-preview fixed cursor-auto","data-testid":"comment-popover",style:{top:Tt?i.y-m9:i.y+m9,left:Math.max(v9,Math.min(i.x-g9/2,window.innerWidth-g9-v9)),transform:Tt?"translateY(-100%)":void 0},onClick:J=>J.stopPropagation(),onDoubleClick:J=>{J.stopPropagation(),re({preserveSelection:!0})},children:y.jsx(mn.div,{animate:p,children:y.jsxs(mn.div,{className:"bg-main relative flex w-80 flex-col gap-2 rounded-xl p-4 shadow-2xl",style:{transformOrigin:"center 24px"},initial:{scale:.82,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.82,opacity:0,transition:{duration:.1,ease:[.55,0,1,.45]}},transition:{type:"spring",stiffness:500,damping:28,mass:.8},...we,children:[ve?y.jsx("div",{className:"border-primary bg-primary/10 pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-xl border-2 border-dashed",children:y.jsx("span",{className:"text-content text-sm font-medium",children:"Drop image here"})}):null,H.length>0?y.jsx("div",{className:"flex flex-wrap gap-1.5",children:H.map(J=>y.jsx(Fxe,{reference:J,onRemove:()=>te(J)},`${J.sessionId}:${J.variantId}`))}):null,y.jsx("textarea",{ref:J=>{q.current=J,J&&G(J)},value:R,onChange:J=>{const Y=J.target.value;L(J.target.value),G(J.target),c==null||c(Y.trim()!==""||j.length>0)},onKeyDown:Ye,onPaste:Te,placeholder:"What should change?",rows:Zxe,style:{maxHeight:Wxe,overflowY:"auto"},className:"bg-main-light text-content placeholder:text-content-subtle w-full resize-none rounded-lg p-3 text-sm outline-none"}),j.length>0?y.jsx("div",{className:"max-h-40 overflow-y-auto rounded",children:y.jsx("div",{className:`grid gap-1.5 ${j.length===1?"grid-cols-1":"grid-cols-2"}`,children:j.map((J,Y)=>y.jsxs("div",{className:"relative",children:[y.jsx("img",{src:J,alt:`Reference ${Y+1}`,className:`border-divider w-full rounded border object-cover ${j.length===1?"max-h-32":"aspect-[4/3]"}`}),y.jsx("button",{onClick:()=>je(Y),className:"absolute top-1 right-1 rounded-full bg-red-500/80 p-0.5 text-white backdrop-blur-sm hover:bg-red-600",children:y.jsx(Ho,{className:"h-2.5 w-2.5",weight:"bold"})})]},Y))})}):null,y.jsx("input",{ref:Q,type:"file",accept:"image/*",multiple:!0,onChange:Fe,className:"hidden"}),y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsxs("div",{className:"flex items-center gap-1",children:[o?y.jsx("button",{type:"button",onClick:ye,className:"text-content-subtle hover:text-accent-error p-1 transition-colors",title:"Delete comment",children:y.jsx(fM,{className:"h-4 w-4",weight:"bold"})}):null,y.jsx(Fi,{label:"Attach images",children:y.jsx("button",{type:"button","aria-label":"Attach images",onClick:()=>{var J;return(J=Q.current)==null?void 0:J.click()},className:"text-content-subtle hover:text-content p-1 transition-colors",children:y.jsx(WI,{className:"h-4 w-4",weight:"bold"})})}),y.jsx(Fi,{label:"Reference a direction",children:y.jsxs("div",{className:"relative",children:[y.jsx("button",{type:"button","aria-label":"Reference a direction","aria-haspopup":"listbox","aria-expanded":Z,onClick:()=>K(J=>!J),className:`p-1 transition-colors ${Z||H.length>0?"text-content":"text-content-subtle hover:text-content"}`,children:y.jsx(MI,{className:"h-4 w-4",weight:"bold"})}),Z?y.jsx("div",{className:"absolute bottom-full left-0 z-20 mb-2",children:y.jsx(Vxe,{attached:H,commentTarget:t,onChange:ee,onClose:()=>K(!1)})}):null]})})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[yn?y.jsx(Fi,{label:lt,children:y.jsxs("button",{type:"button","aria-label":be,"data-testid":he,onClick:()=>void yt(nn),disabled:We!==null,className:"border-main-border text-content hover:bg-main-input flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50",children:[y.jsx(s8,{className:"h-4 w-4",weight:"bold"}),y.jsx("span",{children:"Vary"})]})}):null,y.jsx("button",{onClick:()=>et(),disabled:!z,className:"bg-primary hover:bg-primary-hover rounded-full px-5 py-1.5 text-sm font-medium text-white transition-colors disabled:opacity-50",children:Nt})]})]})]})})})},Kxe="allow-scripts allow-same-origin allow-forms allow-popups allow-modals",Yxe="allow-scripts allow-forms allow-popups allow-modals",Xxe=e=>e==="embedded"?Yxe:Kxe,b9=Mt("PreviewSurface"),nH=({target:e,src:t,framework:n,mode:r,isUpstreamReady:i,remountKey:s})=>{const o=No(e),a=Be(XJ),c=Be(QJ),u=Be(hs),f=ke(ji),p=Be(V8),m=ke(wp),g=ke(W1),b=g==="embedded",x=Be(uc),[C,w]=Vn(C$),[E,A]=h.useState(null),T=h.useRef(null),M=bc(),[I,P]=Vn(Qg),S=h.useCallback(()=>M.get(uc),[M]),D=I&&Uh(I.target,e)?I:null,R=h.useRef(null),{enterEditMode:L}=Mxe({iframeRef:R}),j=ke(Qs);Rxe({iframeRef:R,enabled:j.resize.isEnabled&&!b,surfaceId:o});const O=h.useCallback(G=>x(G),[x]),H=h.useCallback((G,X,de)=>{if(S()){w(ve=>ve+1);return}O(!1),p(null),u(e),P({key:crypto.randomUUID(),target:e,elementContext:G,pin:X,dragBox:de})},[S,w,O,p,u,P,e]),B=h.useCallback(()=>{if(S()){w(G=>G+1);return}P(null),p(null),O(!1)},[S,w,P,O,p]),Z=h.useCallback((G,X,de)=>{L(G,X,de)},[L]),{setupIframe:K,clearSelectionState:q,iframeRef:Q}=Ixe({surfaceId:o,target:e,mode:r,isBoxModelVisible:!0,onTextEdit:Z,onCommentClick:H,onCommentSelectionClear:B,isPreviewBridgeEnabled:b}),F=h.useCallback(G=>{P(null),p(null),O(!1),G!=null&&G.preserveSelection||q()},[q,P,O,p]),V=h.useCallback(G=>{const X=f.get(G);X&&(O(!1),p(G),u(e),P({key:crypto.randomUUID(),target:e,elementContext:X.elementContext,pin:X.pin,dragBox:X.dragBox,existingCommentId:G}))},[f,O,p,u,P,e]),W=h.useCallback((G,X)=>{const de=Q.current;if(!de)return null;const ve=de.getBoundingClientRect(),we=b?null:Br(de),Fe=we?Ou(we,G):null,Te=(Fe==null?void 0:Fe.getBoundingClientRect())??G.boundingRect;return{x:ve.left+Te.left+X.elementXPct*Te.width,y:ve.top+Te.top+X.elementYPct*Te.height}},[b,Q]),[,N]=h.useState(0),z=h.useCallback(()=>N(G=>G+1),[]);h.useEffect(()=>{const G=Q.current;if(!D||!G)return;const X=b?null:Br(G);X&&X.addEventListener("scroll",z,!0);const de=new ResizeObserver(z);return de.observe(G),G.addEventListener("load",z),()=>{X&&X.removeEventListener("scroll",z,!0),de.disconnect(),G.removeEventListener("load",z)}},[D,Q,z,b]);const ee=D?W(D.elementContext,D.pin):null,te=i&&!b;h.useEffect(()=>{if(b){E&&(T.current=null,A(null),c({surfaceId:o,adapter:null}));return}if(n!=="static"&&!i){E&&(T.current=null,A(null),c({surfaceId:o,adapter:null}));return}const G=Q.current;if(E&&T.current!==G){T.current=null,A(null),c({surfaceId:o,adapter:null});return}if(G&&!E){const X=n==="static";b9.debug(`Creating ${X?"Static":""}IframeDisplayAdapter`);const de=r==="edit"?"edit":"view",ve=X?new $xe(G,{mode:de,isBoxModelVisible:!0}):new JV(G,{mode:de,isBoxModelVisible:!0});ve.initialize(),T.current=G,A(ve),c({surfaceId:o,adapter:ve})}},[E,n,i,b,r,Q,c,o]);const re=h.useCallback(G=>{G?(K(G),R.current=G):R.current=null},[K]);return h.useEffect(()=>(a({surfaceId:o,ref:Q}),()=>{a({surfaceId:o,ref:null}),c({surfaceId:o,adapter:null})}),[a,c,o,Q]),h.useEffect(()=>{r==="comment"||r==="edit"||S()||(P(null),p(null),r==="view"&&q())},[r,S,q,P,p]),y.jsxs("div",{className:"relative h-full w-full",children:[y.jsx("iframe",{ref:re,src:t,className:"h-full w-full border-none",title:"Project Preview",sandbox:Xxe(g),onLoad:()=>{vt==null||vt.capture("preview_iframe_loaded",{framework:n,src:t})},onError:()=>{vt==null||vt.capture("preview_iframe_load_failed",{framework:n,src:t}),b9.warn("Preview iframe failed to load",{framework:n,src:t})}},s),te?y.jsx(jxe,{onEditComment:V,target:e,iframeRef:Q}):null,(D==null?void 0:D.dragBox)&&!D.existingCommentId&&Q.current&&(()=>{const G=Q.current,X=G.getBoundingClientRect(),de=b?null:Br(G),ve=de?Ou(de,D.elementContext):null,we=(ve==null?void 0:ve.getBoundingClientRect())??D.elementContext.boundingRect,{leftPct:Fe,topPct:Te,widthPct:je,heightPct:nt}=D.dragBox;return y.jsx("div",{"data-comment-drag-box":"true",style:{position:"fixed",pointerEvents:"none",zIndex:45,border:"1px dashed var(--color-primary, #FF3300)",background:"rgba(255, 51, 0, 0.08)",borderRadius:2,boxSizing:"border-box",left:X.left+we.left+Fe*we.width,top:X.top+we.top+Te*we.height,width:je*we.width,height:nt*we.height}})})(),D&&ee&&!D.existingCommentId&&y.jsx(eH,{comment:{id:"draft",elementContext:D.elementContext,pin:D.pin,instruction:"",status:"pending"},index:f.size,position:ee,onDismiss:()=>{},onEdit:()=>{}}),xc.createPortal(y.jsx(us,{children:D&&ee?y.jsx(qxe,{elementContext:D.elementContext,target:e,pin:D.pin,dragBox:D.dragBox,position:ee,onClose:F,existingCommentId:D.existingCommentId,isMCPSession:m,onInputChange:G=>{O(G)},shake:C},D.key):null}),document.body)]})},Qxe=({isInteractionDisabled:e=!1,framework:t,userPort:n,activeDemoSessionId:r=null,holdPreviewNavigation:i=!1})=>{var N;const s=ke(Js),o=ke(mw),a=Be(mw),c=ke(Jg),u=Be(Jg),f=ke(eo),p=ke(W1),m=ke(gw),g=ke(y$),b=ke(wc),x=Be(gw),C=f.active&&f.projectContext.kind==="fresh",w=ke(vw),E=f.active?f.variants.find(z=>z.workItemId===w&&(z.status==="pending"||z.status==="running"))??null:null,A=f.active&&f.variants.some(z=>z.status==="pending"||z.status==="running"),T=C||A,M=f.active?f.variants.find(z=>z.workItemId===w&&z.status==="succeeded"&&!!z.previewUnavailable)??null:null;h.useEffect(()=>{f.active||x(!1)},[f.active,x]);const I=h.useMemo(()=>{var X;if(m||c||!f.active)return null;const{stage:z,variants:ee}=f,te=z==="ready"||z==="degraded",re=ee.some(de=>{var ve,we;return((ve=de.refinement)==null?void 0:ve.status)==="pending"||((we=de.refinement)==null?void 0:we.status)==="running"});if(!te&&!re)return null;const G=ee.find(de=>{var ve;return de.status==="succeeded"&&((ve=de.preview)==null?void 0:ve.kind)==="static_artifact"});return((X=G==null?void 0:G.preview)==null?void 0:X.kind)==="static_artifact"?G.preview.url:null},[c,m,f]),P=c??I,S=h.useMemo(()=>!f.active||!P?null:f.variants.find(z=>{var ee;return((ee=z.preview)==null?void 0:ee.kind)==="static_artifact"&&P.startsWith(z.preview.url)})??null,[P,f]),D=h.useMemo(()=>f.active?S?{kind:"variant",sessionId:f.sessionId,variantId:S.workItemId}:(!!!(b!=null&&b.left||b!=null&&b.right)||C)&&!P&&m&&g&&f.variants.some(ee=>ee.workItemId===g)?{kind:"variant",sessionId:f.sessionId,variantId:g}:Xs:Xs,[S,f,m,g,P,b,C]),R=h.useRef(null);h.useEffect(()=>{var re,G;if(!S||((re=S.preview)==null?void 0:re.kind)!=="static_artifact"||((G=S.refinement)==null?void 0:G.status)!=="succeeded")return;const z=`${S.workItemId}:${S.refinement.workItemId}`;if(R.current===z)return;R.current=z;const ee=S.preview.url.includes("?")?"&":"?",te=`${S.preview.url}${ee}refinement=${encodeURIComponent(S.refinement.workItemId)}`;P!==te&&(u(te),a(X=>X+1))},[P,S,a,u,f]);const L=P!==null||C&&!m,{isUpstreamReady:j,iframeRemountKey:O,initialProbeComplete:H}=nbe(t,{rerunProbeImmediatelyOnVersion:o,skip:L}),B=!!P||j,Z=`${O}:${o}`,K=r?`/try/${encodeURIComponent(r)}`:"",q=t==="static"?`${K}/static/`:`${K}/`,Q=p==="embedded"&&typeof window<"u"?`${window.location.protocol}//localhost:${window.location.port}`:"",F=E?"about:blank":P??(i||!B?"about:blank":`${Q}${q}`),V=!!E||!!M||!B&&H;let W=null;if(E)W=y.jsxs(y.Fragment,{children:[y.jsx("div",{"aria-hidden":!0,className:"h-8 w-8 animate-spin rounded-full border-2 border-content-muted/30 border-t-content"}),y.jsxs("h2",{className:"text-3xl font-semibold text-content",children:["Building “",E.label||"this direction","”…"]}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:"This direction is still generating. It’ll load here the moment it’s ready."})]});else if(M){const z=((N=M.previewUnavailable)==null?void 0:N.portInUse)??!1;W=y.jsxs(y.Fragment,{children:[y.jsx("h2",{className:"text-3xl font-semibold text-content",children:"This direction’s preview couldn’t start"}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:z?"Rivet tried to start it on a free port, but this project’s dev server insists on a port that’s already taken (its dev script likely hardcodes the port). You can still pick this direction by reading its code, or reload to try again.":"Its preview server didn’t come up, so there’s nothing to show live. You can still pick this direction by reading its code, or reload to try again."}),y.jsx("button",{onClick:()=>window.location.reload(),className:"rounded-md bg-primary px-10 py-2.5 text-sm font-medium text-white transition-colors hover:bg-primary-hover",children:"Reload"})]})}else T?W=y.jsxs(y.Fragment,{children:[y.jsx("h2",{className:"text-3xl font-semibold text-content",children:"Directions will appear here"}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:"Select one from the panel to preview it."})]}):W=y.jsxs(y.Fragment,{children:[y.jsx("h2",{className:"text-3xl font-semibold text-content",children:"Preview isn't connected"}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:"The connection between Rivet and your project is offline. Try restarting Rivet, then click reload below."}),y.jsx("button",{onClick:()=>window.location.reload(),className:"rounded-md bg-primary px-10 py-2.5 text-sm font-medium text-white transition-colors hover:bg-primary-hover",children:"Reload"})]});return y.jsxs("div",{className:"relative h-full w-full",children:[V?y.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-main/90 px-6",children:y.jsx("div",{role:"alert","aria-live":"polite",className:"flex max-w-sm flex-col items-center gap-5 text-center",children:W})}):null,y.jsx(nH,{target:D,src:F,framework:t,mode:e?"view":s,isUpstreamReady:B,remountKey:Z})]})},Wf=10,Jxe=2,e4e=.18,t4e=.013,x9=.6,w9=.0016,n4e=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]],r4e=e=>e*e*e,i4e=e=>Math.min(1,Math.max(0,e)),rH=({collapsing:e=!1,onCollapsed:t})=>{const n=h.useRef(null),r=h.useRef(null),i=h.useRef(e),s=h.useRef(t);i.current=e,s.current=t;const o=Be(h$);return h.useEffect(()=>{var L;const a=n.current,c=r.current;if(!a||!c)return;o(j=>j+1);const u=a.getContext("2d"),f=Math.min(window.devicePixelRatio||1,2),p=((L=window.matchMedia)==null?void 0:L.call(window,"(prefers-reduced-motion: reduce)").matches)??!1;let m=0,g=0,b=0,x=0,C=0,w=1,E=null,A=!1;const T=()=>{b=c.clientWidth,x=c.clientHeight,a.width=Math.floor(b*f),a.height=Math.floor(x*f),u==null||u.setTransform(f,0,0,f,0,0),m=Math.ceil(b/Wf)+1,g=Math.ceil(x/Wf)+1,w=m+g||1},M=(j,O)=>{if(!u)return;u.clearRect(0,0,b,x);const H=Wf-Jxe;for(let B=0;B<g;B++)for(let Z=0;Z<m;Z++){const K=Z*Wf,q=B*Wf,Q=.5+.5*Math.sin((K+q)*t4e-j*e4e),F=(n4e[B&3][Z&3]+.5)/16;if(Q<=F)continue;let V=1;if(O>0&&(V=1-r4e(i4e((O-(Z+B)*w9)/x9))),V<=.001)continue;const W=H*V,N=(H-W)/2;u.fillStyle=Q>.8?"#ff5a1e":"#ff3300",u.fillRect(K+N,q+N,W,W)}},I=()=>{var j;A||(A=!0,u==null||u.clearRect(0,0,b,x),(j=s.current)==null||j.call(s))},P=j=>{const O=p?0:j/1e3;if(i.current){if(p){I();return}E===null&&(E=j);const H=(j-E)/1e3;if(H-w*w9>=x9){I();return}M(O,H)}else M(O,0);C=requestAnimationFrame(P)};T(),p&&!i.current&&M(0,0),C=requestAnimationFrame(P);const S=()=>{const j=performance.now(),O=p?0:j/1e3,H=!p&&i.current&&E!==null?(j-E)/1e3:0;M(O,H)},D=()=>{A||(T(),S())};let R;return typeof ResizeObserver<"u"?(R=new ResizeObserver(D),R.observe(c)):window.addEventListener("resize",D),()=>{o(j=>j-1),cancelAnimationFrame(C),R==null||R.disconnect(),window.removeEventListener("resize",D)}},[o]),y.jsx("div",{className:"relative flex h-full w-full items-center justify-center overflow-hidden bg-[#f3ede3]",children:y.jsx("div",{ref:r,"data-testid":"ascii-dither-stage",className:"aspect-square max-h-[90%] max-w-[90%] overflow-hidden rounded-[64px]",style:{width:"min(90%, 90vh)"},children:y.jsx("canvas",{ref:n,className:"block h-full w-full"})})})};function k9({side:e,sessionId:t,variantId:n,url:r,label:i,isFallback:s=!1}){var b;const o=Be(wc),a=ke(Js),c=ke(eo),u=h.useCallback(()=>{if(s){o(null);return}o(x=>{if(!x)return null;const C={...x};return delete C[e],C.left||C.right?C:null})},[o,e,s]),f=h.useMemo(()=>({kind:"variant",sessionId:t,variantId:n}),[t,n]),p=h.useMemo(()=>!c.active||c.sessionId!==t?null:c.variants.find(x=>x.workItemId===n)??null,[t,n,c]),m=h.useMemo(()=>{var C,w;if(((C=p==null?void 0:p.preview)==null?void 0:C.kind)!=="static_artifact"||((w=p.refinement)==null?void 0:w.status)!=="succeeded")return r;const x=p.preview.url.includes("?")?"&":"?";return`${p.preview.url}${x}refinement=${encodeURIComponent(p.refinement.workItemId)}`},[p,r]),g=((b=p==null?void 0:p.refinement)==null?void 0:b.status)==="succeeded"?`${n}:${p.refinement.workItemId}`:n;return y.jsxs("div",{className:"variant-split-secondary","data-cy":"variant-split-pane","data-variant-id":n,children:[y.jsxs("div",{className:"variant-split-secondary-toolbar",children:[y.jsx("span",{className:"variant-split-secondary-label",title:i,children:i}),y.jsx(Fi,{label:"Collapse",children:y.jsx("button",{type:"button",className:"variant-split-secondary-close",onClick:u,"aria-label":"Collapse split view",children:y.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",focusable:"false",children:y.jsx("path",{d:"M2.5 2.5 L9.5 9.5 M9.5 2.5 L2.5 9.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})})]}),y.jsx("div",{className:"variant-split-secondary-body relative min-h-0 flex-1",children:y.jsx(nH,{target:f,src:m,framework:"static",mode:a,isUpstreamReady:!0,remountKey:g})})]})}const C9=240;function s4e(){const e=ke(Wh),t=ke(H8),n=h.useRef(null);return h.useEffect(()=>{if(!e||!t||!n.current)return;const r=t.x-C9/2,i=t.y-22;n.current.style.transform=`translate3d(${r}px, ${i}px, 0)`},[e,t]),!e||!t?null:y.jsx("div",{ref:n,"aria-hidden":"true",className:"variant-drag-ghost",style:{width:C9},children:y.jsxs("div",{className:"variant-drag-ghost-body",children:[y.jsxs("div",{className:"variant-drag-ghost-row",children:[y.jsx("div",{className:"variant-drag-ghost-title",children:e.label}),e.runLabel?y.jsx("div",{className:"variant-drag-ghost-tag",style:H$(e.runLabel),children:e.runLabel}):null]}),e.description?y.jsx("div",{className:"variant-drag-ghost-desc",children:e.description}):null]})})}function o4e(){const e=ke(Wh),t=ke(H8),n=Be(Wh),r=Be(wc),i=h.useRef(null),[s,o]=h.useState(null),[a,c]=h.useState("hidden");h.useEffect(()=>{if(!e){c("hidden"),o(null);return}const p=requestAnimationFrame(()=>c("visible"));return()=>cancelAnimationFrame(p)},[e]);const u=h.useCallback((p,m)=>{const g=i.current;if(!g)return null;const b=g.getBoundingClientRect();return p<b.left||p>b.right||m<b.top||m>b.bottom?null:p<(b.left+b.right)/2?"left":"right"},[]);if(h.useEffect(()=>{if(!e||!t)return;const p=u(t.x,t.y);o(m=>m===p?m:p)},[e,t,u]),h.useEffect(()=>{if(!e)return;const p=m=>{const g=u(m.clientX,m.clientY);if(g&&e.url){const b={sessionId:e.sessionId,variantId:e.variantId,label:e.label,url:e.url};r(x=>({...x??{},[g]:b})),c("exiting"),window.setTimeout(()=>n(null),220)}else c("exiting"),window.setTimeout(()=>n(null),220)};return window.addEventListener("pointerup",p),window.addEventListener("pointercancel",p),()=>{window.removeEventListener("pointerup",p),window.removeEventListener("pointercancel",p)}},[e,u,n,r]),!e)return null;const f=["variant-drop-zones",a==="visible"&&"is-visible",a==="exiting"&&"is-exiting"].filter(Boolean).join(" ");return y.jsxs("div",{ref:i,className:f,"aria-hidden":"true",children:[y.jsx(E9,{side:"left",hovered:s==="left",canDrop:!!e.url,label:e.label}),y.jsx(E9,{side:"right",hovered:s==="right",canDrop:!!e.url,label:e.label})]})}function E9({side:e,hovered:t,canDrop:n,label:r}){return y.jsxs("div",{className:["variant-drop-zone",`is-${e}`,t&&"is-hover",!n&&"is-disabled"].filter(Boolean).join(" "),children:[y.jsxs("div",{className:"variant-drop-zone-inner",children:[y.jsx("div",{className:`variant-drop-zone-icon is-${e}`}),y.jsx("div",{className:"variant-drop-zone-caption",children:n?`Add ${e} split`:"Split unavailable for this direction"})]}),y.jsx("div",{className:"variant-drop-zone-preview","aria-hidden":"true",children:y.jsx("div",{className:"variant-drop-zone-preview-label",children:r})}),y.jsx("div",{className:"variant-drop-zone-border"})]})}const iH=(e,t,n)=>{var s,o;if(!e.active||e.sessionId!==t)return null;const r=e.variants.find(a=>a.workItemId===n);if(((s=r==null?void 0:r.preview)==null?void 0:s.kind)!=="static_artifact")return null;if(((o=r.refinement)==null?void 0:o.status)!=="succeeded")return r.preview.url;const i=r.preview.url.includes("?")?"&":"?";return`${r.preview.url}${i}refinement=${encodeURIComponent(r.refinement.workItemId)}`},S9=(e,t)=>{if(!e)return;const n=iH(t,e.sessionId,e.variantId);return!n||n===e.url?e:{...e,url:n}},a4e=({isLoading:e=!1,isInteractionDisabled:t=!1,activeDemoSessionId:n=null,holdHostedTryoutPreviewNavigation:r=!1})=>{const{config:i,fetchConfig:s,isLoading:o,error:a}=q2e(),[c,u]=h.useState(!1),f=h.useRef(!1);o&&(f.current=!0);const m=!o&&!a&&!!i&&f.current;return h.useEffect(()=>{s().catch(g=>{vt==null||vt.capture("preview_config_load_failed",{message:g instanceof Error?g.message:"unknown_error"})})},[s]),o||m&&!c?o&&r?y.jsx("div",{className:"flex h-full min-h-0 w-full flex-1 bg-main","aria-busy":"true"}):y.jsx(rH,{collapsing:m,onCollapsed:()=>u(!0)}):a||!i?y.jsx("div",{className:"flex h-full w-full items-center justify-center bg-main px-6",children:y.jsxs("div",{className:"max-w-md rounded-lg border border-divider bg-main-light p-4 text-center shadow-lg",children:[y.jsx("p",{className:"text-sm font-medium text-content",children:"We couldn't load your app preview."}),y.jsx("p",{className:"mt-2 text-sm text-content-subtle",children:a||"Missing preview configuration from the server."}),y.jsx("p",{className:"mt-2 text-sm text-content-subtle",children:"If this keeps happening, restart your Rivet session and try again."}),y.jsx("button",{type:"button",className:"mt-4 rounded-md border border-divider px-3 py-1.5 text-xs text-content hover:bg-main/80",onClick:()=>{vt==null||vt.capture("preview_config_retry_clicked"),s().catch(g=>{vt==null||vt.capture("preview_config_load_failed",{message:g instanceof Error?g.message:"unknown_error"})})},children:"Retry preview"})]})}):y.jsx(l4e,{isLoading:e,isInteractionDisabled:t,framework:i.framework,userPort:i.userPort,activeDemoSessionId:n,holdHostedTryoutPreviewNavigation:r})};function l4e(e){const t=ke(wc),n=ke(Wh),r=ke(Js),i=Be(j8),s=ke(eo),o=ke(Jg),a=t==null?void 0:t.left,c=t==null?void 0:t.right,u=h.useMemo(()=>{var P,S;if(!s.active||s.projectContext.kind!=="fresh"||!(!!a!=!!c))return;const w=(P=a??c)==null?void 0:P.variantId,E=s.variants.filter(D=>{var R;return D.status==="succeeded"&&((R=D.preview)==null?void 0:R.kind)==="static_artifact"&&D.workItemId!==w}),A=o==null?void 0:o.replace(/[?&]refinement=[^&]*$/,""),M=E.find(D=>{var R;return((R=D.preview)==null?void 0:R.kind)==="static_artifact"&&D.preview.url===A})??E[0];if(((S=M==null?void 0:M.preview)==null?void 0:S.kind)!=="static_artifact")return;const I=iH(s,s.sessionId,M.workItemId);if(I)return{sessionId:s.sessionId,variantId:M.workItemId,label:M.label,url:I}},[s,a,c,o]),f=S9(a,s)??(c?u:void 0),p=S9(c,s)??(a?u:void 0),m=!a&&!!f,g=!c&&!!p,b=!!(f||p),x=y.jsx(Qxe,{isInteractionDisabled:e.isInteractionDisabled,framework:e.framework,userPort:e.userPort,activeDemoSessionId:e.activeDemoSessionId,holdPreviewNavigation:e.holdHostedTryoutPreviewNavigation});return y.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-1 flex-col",children:[y.jsxs("div",{className:`variant-preview-region relative flex h-full min-h-0 w-full flex-1 flex-col ${n?"is-dragging":""} ${b?"is-split":""}`,children:[y.jsxs("div",{className:"variant-preview-row flex h-full min-h-0 w-full flex-1",children:[f&&y.jsx(k9,{side:"left",sessionId:f.sessionId,variantId:f.variantId,url:f.url,label:f.label,isFallback:m},`left-${f.sessionId}:${f.variantId}:${f.url}`),!(f&&p)&&y.jsx("div",{className:"variant-preview-primary flex h-full min-h-0 flex-1 flex-col",children:x}),p&&y.jsx(k9,{side:"right",sessionId:p.sessionId,variantId:p.variantId,url:p.url,label:p.label,isFallback:g},`right-${p.sessionId}:${p.variantId}:${p.url}`)]}),y.jsx("div",{className:"variant-preview-atmosphere","aria-hidden":"true"}),y.jsx(o4e,{}),y.jsx(s4e,{})]}),e.isInteractionDisabled?null:y.jsx(X2e,{mode:r,onModeChange:i,isLoading:e.isLoading})]})}const sH=({message:e,isLoading:t=!0})=>y.jsxs("div",{className:"flex items-center gap-2 text-sm text-content",children:[t?y.jsx(Ua,{className:"h-4 w-4 shrink-0 animate-spin text-primary",weight:"bold"}):null,y.jsx("span",{className:"whitespace-pre-wrap font-sans",children:e})]}),oH="data:image/svg+xml,%3csvg%20width='94'%20height='24'%20viewBox='0%200%2094%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M-0.000156164%2023.832V7.704H5.11184L6.47984%208.424C7.58384%207.704%209.04784%207.344%2010.8718%207.344C12.0718%207.344%2013.1278%207.476%2014.0398%207.74C14.9518%207.98%2015.6838%208.244%2016.2358%208.532C16.8118%208.82%2017.1718%209.024%2017.3158%209.144L15.5158%2013.824C15.2758%2013.656%2014.8198%2013.428%2014.1478%2013.14C13.4998%2012.852%2012.7318%2012.588%2011.8438%2012.348C10.9558%2012.084%2010.0198%2011.952%209.03584%2011.952H8.63984C7.96784%2011.952%207.45184%2012.072%207.09184%2012.312C6.73184%2012.528%206.55184%2013.02%206.55184%2013.788V23.832H-0.000156164ZM23.464%206.156C21.04%206.156%2019.828%205.124%2019.828%203.06C19.828%201.908%2020.128%201.116%2020.728%200.684C21.352%200.227999%2022.264%20-1.43051e-06%2023.464%20-1.43051e-06C24.736%20-1.43051e-06%2025.66%200.227999%2026.236%200.684C26.836%201.116%2027.136%201.908%2027.136%203.06C27.136%205.124%2025.912%206.156%2023.464%206.156ZM20.152%2023.832V7.704H26.704V23.832H20.152ZM37.4767%2023.832L29.6647%207.704H36.9007L40.3207%2016.524L41.2567%2019.116H41.6167L42.5527%2016.524L46.0087%207.704H53.1727L52.5967%209.9L45.4327%2023.832H37.4767ZM61.1953%2023.832C59.6113%2023.832%2058.3873%2023.604%2057.5233%2023.148C56.6833%2022.692%2056.1073%2022.068%2055.7953%2021.276C55.4833%2020.46%2055.3273%2019.524%2055.3273%2018.468V13.032C55.3273%2012.072%2055.4833%2011.196%2055.7953%2010.404C56.1313%209.588%2056.7193%208.94%2057.5593%208.46C58.3993%207.956%2059.6113%207.704%2061.1953%207.704H68.6473C70.5193%207.704%2071.9473%207.932%2072.9313%208.388C73.9393%208.82%2074.6233%209.444%2074.9833%2010.26C75.3673%2011.052%2075.5593%2011.976%2075.5593%2013.032V17.64H69.2593C67.0993%2017.64%2065.4553%2017.592%2064.3273%2017.496C63.2233%2017.4%2062.4433%2017.34%2061.9873%2017.316V17.856C61.9633%2018.816%2062.5393%2019.296%2063.7153%2019.296H64.8313C66.7513%2019.296%2068.5273%2019.26%2070.1593%2019.188C71.7913%2019.092%2073.0033%2019.008%2073.7953%2018.936L75.9553%2022.356C75.9553%2022.596%2075.7513%2022.824%2075.3433%2023.04C74.9353%2023.256%2074.2153%2023.448%2073.1833%2023.616C72.1753%2023.76%2070.7353%2023.832%2068.8633%2023.832H61.1953ZM61.9873%2014.184H68.8993V13.68C68.8993%2013.2%2068.8513%2012.864%2068.7553%2012.672C68.6833%2012.48%2068.4313%2012.36%2067.9993%2012.312C67.5673%2012.264%2066.8353%2012.24%2065.8033%2012.24H63.7153C62.5633%2012.24%2061.9873%2012.72%2061.9873%2013.68V14.184ZM85.8224%2023.832C83.9984%2023.832%2082.7504%2023.448%2082.0784%2022.68C81.4064%2021.912%2081.0704%2020.76%2081.0704%2019.224V12.24H78.1184V7.704H79.6304C80.0384%207.704%2080.3624%207.632%2080.6024%207.488C80.8664%207.32%2081.0344%207.032%2081.1064%206.624L81.7904%202.772H87.6944V7.704H93.7064V12.24H87.6944V17.82C87.6944%2018.42%2087.8384%2018.816%2088.1264%2019.008C88.4144%2019.2%2088.8464%2019.296%2089.4224%2019.296H93.0224L93.7424%2023.472C93.2384%2023.544%2092.4704%2023.628%2091.4384%2023.724C90.4064%2023.796%2089.2784%2023.832%2088.0544%2023.832H85.8224Z'%20fill='%23FF3300'/%3e%3c/svg%3e",aH=({isSigningIn:e,onStartSignIn:t,errorMessage:n=null,isDesktopShell:r=!1,displayMode:i="full"})=>{const s=i==="modal";return y.jsxs("div",{className:s?"glass-panel relative w-full max-w-sm rounded-2xl border border-white/10 px-8 py-14 font-main text-white shadow-2xl":"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-[#1c1c20] font-main text-white",children:[r&&!s?y.jsx("div",{className:"fixed left-0 right-0 top-0 z-10 h-8",style:{WebkitAppRegion:"drag"}}):null,y.jsxs("div",{className:"flex flex-col items-center gap-10",children:[y.jsx("img",{src:oH,alt:"Rivet",className:"h-8 w-auto object-contain"}),y.jsxs("div",{className:"text-center",children:[y.jsx("h1",{className:"mb-2 text-xl font-medium text-content",children:"Welcome to Rivet"}),y.jsx("p",{className:"text-sm text-content-muted",children:"Sign in to get started"})]}),y.jsx("button",{onClick:t,disabled:e,className:"glass-panel active-push flex items-center gap-3 rounded-xl px-8 py-3.5 text-sm font-medium transition-all hover:bg-white/10 disabled:opacity-50",children:e?y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-primary border-t-transparent"}),y.jsx("span",{children:"Signing in..."})]}):y.jsxs(y.Fragment,{children:[y.jsx("img",{src:"https://www.gstatic.com/firebasejs/ui/2.0.0/images/auth/google.svg",alt:"Google",className:"h-5 w-5 brightness-110"}),y.jsx("span",{children:"Sign in with Google"})]})}),n?y.jsx("p",{className:"text-center text-xs text-red-200",children:n}):null]})]})},c4e=({message:e})=>y.jsx("div",{className:"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-[#1c1c20] font-main text-white",children:y.jsxs("div",{className:"flex flex-col items-center gap-10",children:[y.jsx("img",{src:oH,alt:"Rivet",className:"h-8 w-auto object-contain"}),y.jsxs("div",{className:"glass-panel flex items-center gap-3 rounded-xl px-8 py-3.5 text-sm font-medium",children:[y.jsx(Ua,{className:"h-5 w-5 shrink-0 animate-spin text-primary",weight:"bold"}),y.jsx("span",{children:e})]})]})}),_9=Mt("useConfig"),u4e=()=>{var e;return typeof window>"u"?null:((e=window.__RIVET_BOOTSTRAP__)==null?void 0:e.queueAccessToken)??null},d4e=()=>{var e;return typeof window>"u"?null:((e=window.__RIVET_BOOTSTRAP__)==null?void 0:e.agentApplyMode)??null},f4e=e=>({...f$,...e??{}}),h4e=()=>{const e=ke(Qs),t=Be(Qs),n=Be(wp),r=Be(B8),i=Be(W1),s=Be(z8),o=Be(w$),a=Be(x$),c=Be(p$),u=Jz({queryKey:["rivet-config"],queryFn:async()=>{const g=await fetch("/api/config");if(!g.ok)throw new Error(`Failed to fetch config: ${g.statusText}`);return await g.json()},staleTime:3e4}),{refetch:f}=u;h.useEffect(()=>{const g=u.data;g&&(o(g.agentModeAvailable),c({name:g.name??null,email:g.email??null}),t(f4e(g.featureFlags)),a(!0),g.isMCPSession&&n(!0),g.mcpEditor&&r(g.mcpEditor),i(g.agentApplyMode??d4e()??null),s(g.queueAccessToken??u4e()),_9.info("Config loaded:",g))},[u.data,i,o,t,a,n,r,s,c]),h.useEffect(()=>{u.error&&(a(!0),_9.warn("Failed to load config:",u.error instanceof Error?u.error.message:"Failed to load config"))},[u.error,a]);const p=h.useCallback(async()=>{const g=await f();return g.data?g.data:(a(!0),null)},[f,a]);let m=null;return u.error instanceof Error?m=u.error.message:u.error&&(m="Failed to load config"),{config:u.data??null,featureFlags:e,loading:u.isPending,error:m,refetchConfig:p}},vu=Mt("useOAuthCallback"),p4e="https://rivet-proxy.onrender.com",m4e=()=>{const[e,t]=h.useState({isProcessing:!1,isComplete:!1,error:null});return h.useEffect(()=>{const n=new AbortController;let r=!1;return(async()=>{var a,c,u;const s=window.location.hash,o=window.location.search;if(!(!s||!s.includes("access_token"))&&!r){t({isProcessing:!0,isComplete:!1,error:null});try{vu.info("Processing OAuth callback...");const f=new URLSearchParams(s.substring(1)),p=f.get("access_token"),m=f.get("refresh_token"),b=new URLSearchParams(o).get("session");if(!p)throw new Error("No access token found in URL");if(!b)throw new Error("No session ID found in URL");vu.info(`Completing OAuth with session: ${b}`);const x=await fetch(`${p4e}/api/auth/google/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:b,accessToken:p,refreshToken:m}),signal:n.signal}),C=await x.json();if(!x.ok||!C.success)throw new Error(C.error||C.message||"Failed to complete authentication");if(vu.info("OAuth authentication completed successfully"),r)return;if((a=C.user)!=null&&a.id?(vt.identify(C.user.id,{...C.user.email?{email:C.user.email}:{}}),C.user.email&&vt.alias(C.user.email,C.user.id)):(c=C.user)!=null&&c.email&&vt.identify(C.user.email,{email:C.user.email}),(u=C.user)!=null&&u.email&&p)try{const E=await fetch("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:C.user.email,token:p,refreshToken:m,userId:C.user.id}),signal:n.signal});E.ok||vu.warn(`Local auth store returned ${E.status}`)}catch(E){if(r)return;vu.warn("Failed to store auth locally:",E)}if(r)return;const w=window.location.pathname;window.history.replaceState({},document.title,w),t({isProcessing:!1,isComplete:!0,error:null})}catch(f){if(r)return;const p=f instanceof Error?f.message:"Unknown error occurred";vu.warn("OAuth callback error:",f),t({isProcessing:!1,isComplete:!1,error:p})}}})(),()=>{r=!0,n.abort()}},[]),e},Px=Mt("useAgentVariantsSession"),g4e=()=>{const e=Be(eo),t=Be(hd),n=Be(bp),r=Be(Js),i=Be(b$),s=Be(tee),o=bc(),a=h.useRef(null);h.useEffect(()=>{const c=new EventSource("/api/variants/events");return c.onmessage=u=>{try{const f=JSON.parse(u.data),p=a.current;f.active?(i(!1),f.sessionId!==a.current&&(a.current=f.sessionId,t(!0),n(!0),r("comment"))):(a.current!==null&&t(!1),a.current=null,i(!1)),e(f);const m=!f.active&&p!==null,g=f.active&&f.sessionId!==p;if(g&&fetch(`/api/variants/${f.sessionId}/preview-port`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({variantId:null})}).catch(b=>Px.warn("failed to reset preview-port on session switch",b)),m||g){const b=new Set;if(f.active)for(const C of f.variants)b.add(No({kind:"variant",sessionId:f.sessionId,variantId:C.workItemId}));const x=o.get(wc);for(const C of[x==null?void 0:x.left,x==null?void 0:x.right])C&&b.add(No({kind:"variant",sessionId:C.sessionId,variantId:C.variantId}));s(b)}}catch(f){Px.warn("failed to parse SSE event payload",f)}},c.onerror=u=>{Px.warn("SSE error (auto-reconnects)",u),i(!1)},()=>{c.close()}},[e,t,n,r,i,s,o])},yu=Mt("useTokenEditor"),v4e=()=>{const[e,t]=h.useState(null),[n,r]=h.useState(null),[i,s]=h.useState(new Map),[o,a]=h.useState(!0),[c,u]=h.useState(!1),[f,p]=h.useState(null),m=h.useCallback(async()=>{a(!0),p(null);try{const C=await fetch("/api/tokens");if(!C.ok)throw new Error(`Failed to fetch tokens: ${C.statusText}`);const w=await C.json();t(w.registry),r(w.framework),yu.info(`Loaded ${w.framework} tokens`)}catch(C){const w=C instanceof Error?C.message:"Unknown error";p(w),yu.warn("Failed to fetch tokens:",C)}finally{a(!1)}},[]);h.useEffect(()=>{m()},[m]);const g=h.useCallback((C,w,E,A)=>{const T=`${C}.${w}`;s(M=>{const I=new Map(M);return A===E?I.delete(T):I.set(T,{category:C,path:w,originalValue:E,newValue:A}),I})},[]),b=h.useCallback(async()=>{if(i.size===0)return!0;u(!0),p(null);const C=Array.from(i.values());let w=!0;for(const E of C)try{yu.info(`Saving ${E.category}.${E.path} = "${E.newValue}"`);const T=await(await fetch("/api/tokens/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({category:E.category,path:E.path,value:E.newValue})})).json();if(!T.success)throw new Error(T.error||"Update failed");yu.info(`Successfully saved ${E.category}.${E.path}`)}catch(A){const T=A instanceof Error?A.message:"Unknown error";p(`Failed to update ${E.category}.${E.path}: ${T}`),yu.warn(`Failed to save ${E.category}.${E.path}:`,A),w=!1;break}return w&&(s(new Map),await m()),u(!1),w},[i,m]),x=h.useCallback(()=>{s(new Map),yu.info("Reverted all pending changes")},[]);return{tokens:e,framework:n,pendingChanges:i,isLoading:o,isSaving:c,error:f,updateToken:g,saveChanges:b,revertChanges:x,refetch:m}};var Ix="rovingFocusGroup.onEntryFocus",y4e={bubbles:!1,cancelable:!0},Np="RovingFocusGroup",[I6,lH,b4e]=mv(Np),[x4e,cH]=xs(Np,[b4e]),[w4e,k4e]=x4e(Np),uH=h.forwardRef((e,t)=>y.jsx(I6.Provider,{scope:e.__scopeRovingFocusGroup,children:y.jsx(I6.Slot,{scope:e.__scopeRovingFocusGroup,children:y.jsx(C4e,{...e,ref:t})})}));uH.displayName=Np;var C4e=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:f=!1,...p}=e,m=h.useRef(null),g=Jt(t,m),b=Ip(s),[x,C]=vs({prop:o,defaultProp:a??null,onChange:c,caller:Np}),[w,E]=h.useState(!1),A=Ka(u),T=lH(n),M=h.useRef(!1),[I,P]=h.useState(0);return h.useEffect(()=>{const S=m.current;if(S)return S.addEventListener(Ix,A),()=>S.removeEventListener(Ix,A)},[A]),y.jsx(w4e,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:x,onItemFocus:h.useCallback(S=>C(S),[C]),onItemShiftTab:h.useCallback(()=>E(!0),[]),onFocusableItemAdd:h.useCallback(()=>P(S=>S+1),[]),onFocusableItemRemove:h.useCallback(()=>P(S=>S-1),[]),children:y.jsx(Et.div,{tabIndex:w||I===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:ft(e.onMouseDown,()=>{M.current=!0}),onFocus:ft(e.onFocus,S=>{const D=!M.current;if(S.target===S.currentTarget&&D&&!w){const R=new CustomEvent(Ix,y4e);if(S.currentTarget.dispatchEvent(R),!R.defaultPrevented){const L=T().filter(Z=>Z.focusable),j=L.find(Z=>Z.active),O=L.find(Z=>Z.id===x),B=[j,O,...L].filter(Boolean).map(Z=>Z.ref.current);hH(B,f)}}M.current=!1}),onBlur:ft(e.onBlur,()=>E(!1))})})}),dH="RovingFocusGroupItem",fH=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=Bi(),u=s||c,f=k4e(dH,n),p=f.currentTabStopId===u,m=lH(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:x}=f;return h.useEffect(()=>{if(r)return g(),()=>b()},[r,g,b]),y.jsx(I6.ItemSlot,{scope:n,id:u,focusable:r,active:i,children:y.jsx(Et.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...a,ref:t,onMouseDown:ft(e.onMouseDown,C=>{r?f.onItemFocus(u):C.preventDefault()}),onFocus:ft(e.onFocus,()=>f.onItemFocus(u)),onKeyDown:ft(e.onKeyDown,C=>{if(C.key==="Tab"&&C.shiftKey){f.onItemShiftTab();return}if(C.target!==C.currentTarget)return;const w=_4e(C,f.orientation,f.dir);if(w!==void 0){if(C.metaKey||C.ctrlKey||C.altKey||C.shiftKey)return;C.preventDefault();let A=m().filter(T=>T.focusable).map(T=>T.ref.current);if(w==="last")A.reverse();else if(w==="prev"||w==="next"){w==="prev"&&A.reverse();const T=A.indexOf(C.currentTarget);A=f.loop?A4e(A,T+1):A.slice(T+1)}setTimeout(()=>hH(A))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:x!=null}):o})})});fH.displayName=dH;var E4e={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function S4e(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function _4e(e,t,n){const r=S4e(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return E4e[r]}function hH(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function A4e(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var T4e=uH,P4e=fH,Hv="Tabs",[I4e]=xs(Hv,[cH]),pH=cH(),[M4e,$k]=I4e(Hv),mH=h.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:i,defaultValue:s,orientation:o="horizontal",dir:a,activationMode:c="automatic",...u}=e,f=Ip(a),[p,m]=vs({prop:r,onChange:i,defaultProp:s??"",caller:Hv});return y.jsx(M4e,{scope:n,baseId:Bi(),value:p,onValueChange:m,orientation:o,dir:f,activationMode:c,children:y.jsx(Et.div,{dir:f,"data-orientation":o,...u,ref:t})})});mH.displayName=Hv;var gH="TabsList",vH=h.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...i}=e,s=$k(gH,n),o=pH(n);return y.jsx(T4e,{asChild:!0,...o,orientation:s.orientation,dir:s.dir,loop:r,children:y.jsx(Et.div,{role:"tablist","aria-orientation":s.orientation,...i,ref:t})})});vH.displayName=gH;var yH="TabsTrigger",bH=h.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:i=!1,...s}=e,o=$k(yH,n),a=pH(n),c=kH(o.baseId,r),u=CH(o.baseId,r),f=r===o.value;return y.jsx(P4e,{asChild:!0,...a,focusable:!i,active:f,children:y.jsx(Et.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":u,"data-state":f?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:c,...s,ref:t,onMouseDown:ft(e.onMouseDown,p=>{!i&&p.button===0&&p.ctrlKey===!1?o.onValueChange(r):p.preventDefault()}),onKeyDown:ft(e.onKeyDown,p=>{[" ","Enter"].includes(p.key)&&o.onValueChange(r)}),onFocus:ft(e.onFocus,()=>{const p=o.activationMode!=="manual";!f&&!i&&p&&o.onValueChange(r)})})})});bH.displayName=yH;var xH="TabsContent",wH=h.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:i,children:s,...o}=e,a=$k(xH,n),c=kH(a.baseId,r),u=CH(a.baseId,r),f=r===a.value,p=h.useRef(f);return h.useEffect(()=>{const m=requestAnimationFrame(()=>p.current=!1);return()=>cancelAnimationFrame(m)},[]),y.jsx(ws,{present:i||f,children:({present:m})=>y.jsx(Et.div,{"data-state":f?"active":"inactive","data-orientation":a.orientation,role:"tabpanel","aria-labelledby":c,hidden:!m,id:u,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:p.current?"0s":void 0},children:m&&s})})});wH.displayName=xH;function kH(e,t){return`${e}-trigger-${t}`}function CH(e,t){return`${e}-content-${t}`}var R4e=mH,$4e=vH,D4e=bH,N4e=wH;const L4e=({tokens:e,pendingChanges:t,category:n,onUpdateToken:r,highlightToken:i})=>{const[s,o]=h.useState(null),[a,c]=h.useState(""),u=h.useRef(null);if(h.useEffect(()=>{i&&u.current&&setTimeout(()=>{var x;(x=u.current)==null||x.scrollIntoView({behavior:"smooth",block:"center"})},100)},[i]),!e||Object.keys(e).length===0)return y.jsx("div",{className:"flex items-center justify-center py-12 text-sm text-gray-500",children:"No tokens defined for this category"});const f=(x,C)=>{const w=`${n}.${x}`,E=t.get(w);return E?E.newValue:C},p=x=>{if(x.includes("var(")||x.includes("--"))return{textClass:"text-white",mutedClass:"text-white/70"};let C=0,w=0,E=0,A=!1;if(x.startsWith("#")){const P=x.slice(1);P.length===3?(C=parseInt(P[0]+P[0],16),w=parseInt(P[1]+P[1],16),E=parseInt(P[2]+P[2],16),A=!0):P.length>=6&&(C=parseInt(P.slice(0,2),16),w=parseInt(P.slice(2,4),16),E=parseInt(P.slice(4,6),16),A=!0)}const T=x.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);if(T&&(C=parseInt(T[1],10),w=parseInt(T[2],10),E=parseInt(T[3],10),A=!0),!A){const P=x.match(/rgba?\(\s*(\d+)\s+(\d+)\s+(\d+)/);P&&(C=parseInt(P[1],10),w=parseInt(P[2],10),E=parseInt(P[3],10),A=!0)}if(!A){const P=x.match(/hsla?\(\s*(\d+)\s*,\s*(\d+)%?\s*,\s*(\d+)%?/);if(P){const S=_A(parseInt(P[1],10),parseInt(P[2],10),parseInt(P[3],10));C=S.r,w=S.g,E=S.b,A=!0}}if(!A){const P=x.match(/hsla?\(\s*(\d+)\s+(\d+)%?\s+(\d+)%?/);if(P){const S=_A(parseInt(P[1],10),parseInt(P[2],10),parseInt(P[3],10));C=S.r,w=S.g,E=S.b,A=!0}}if(!A){const P=x.match(/oklch\(\s*([\d.]+)(%?)/);if(P){const S=parseFloat(P[1]),R=(P[2]==="%"?S/100:S)>.5;return{textClass:R?"text-gray-900":"text-white",mutedClass:R?"text-gray-600":"text-white/70"}}}if(!A)return{textClass:"text-white",mutedClass:"text-white/70"};const I=sie(C,w,E)>.5;return{textClass:I?"text-gray-900":"text-white",mutedClass:I?"text-gray-600":"text-white/70"}},m=(x,C,w,E)=>{const A=f(C,w),T=s===C,M=T&&a?a:A,I=C.replace(/\./g,"-"),P=i===I||i===x,S=M.includes("rgba")||M.startsWith("#")&&M.length===9||/oklch\(/.test(M)&&M.includes("/"),{textClass:D}=p(M),R=H=>{c(H)},L=H=>{r(n,C,w,H),o(null),c("")},j=H=>{H?(o(C),c(A)):(a&&a!==A&&r(n,C,w,a),o(null),c(""))},O=E?"h-44":"h-52";return y.jsxs(Fo,{open:T,onOpenChange:j,children:[y.jsx(al,{asChild:!0,children:y.jsxs("div",{ref:P?u:null,className:`group relative flex ${O} cursor-pointer flex-col justify-between overflow-hidden rounded-lg border border-white/10 p-4 transition-all ${P?"animate-token-highlight":""}`,children:[y.jsxs("div",{className:"absolute inset-0",children:[S&&y.jsx("div",{className:"absolute inset-0",style:{backgroundImage:`
611
+ `,this.iframeRef.parentElement.appendChild(t)),t}removeMouseCaptureOverlay(){var n;if(!((n=this.iframeRef)!=null&&n.parentElement))return;const t=this.iframeRef.parentElement.querySelector("#rivet-mouse-capture");t&&t.remove()}isOverlayInSidebar(t,n,r,i){const s=document.querySelector('[data-cy="element-inspector"]');if(!s)return!1;const o=s.getBoundingClientRect(),a=t+r,c=n+i;return!(a<=o.left||t>=o.right||c<=o.top||n>=o.bottom)}getComputedStyles(){if(!this.currentElement||!this.iframeRef)return Zf.warn("Attempt to get computed styles failed: currentElement ",this.currentElement,"iFrameRef:",this.iframeRef),{};const t=this.iframeRef.contentWindow;if(!t)return Zf.warn("Attempt to get computed styles failed: iFrameWindow not defined"),{};const n=t.getComputedStyle(this.currentElement),r={};for(let i=0;i<n.length;i++){const s=n[i];r[s]=n.getPropertyValue(s)}return r.background=AA(r),r}onStylesChanged(t){return this.onStylesChangedCallback=t,()=>{this.onStylesChangedCallback=null}}refreshStyles(){const t=this.getComputedStyles();this.notifyStylesChanged(t)}setCurrentElement(t){this.currentElement=t,t&&this.refreshStyles()}notifyStylesChanged(t){this.onStylesChangedCallback&&this.onStylesChangedCallback(t)}async applyStyle(t,n,r){const i=await this.findElement(t);if(!i.ok)return ei(i.error);const s=i.value;t.rivetId&&this.injectRivetId(s,t.rivetId);try{return s.style[n]=r,as(void 0)}catch(o){return ei(new MJ(n,r,o instanceof Error?o.message:String(o)))}}async getComputedStylesForElement(t){const n=await this.findElement(t);if(!n.ok)return ei(n.error);const r=n.value;if(!this.iframeRef)return ei(new ru(t,"Iframe ref is null"));const i=this.iframeRef.contentWindow;if(!i)return ei(new ru(t,"Iframe window is null"));try{const s=i.getComputedStyle(r),o={};for(let a=0;a<s.length;a++){const c=s[a];o[c]=s.getPropertyValue(c)}return o.background=AA(o),as(o)}catch(s){return ei(new ru(t,s instanceof Error?s.message:String(s)))}}async findElement(t){if(!this.iframeRef)return ei(new ru(t,"Iframe ref is null"));const n=Br(this.iframeRef);if(!n)return ei(new ru(t,"Cannot access iframe document"));if(t.rivetId){const r=n.querySelector(`[data-rivet-id="${t.rivetId}"]`);if(r)return as(r)}if(t.xpath){const r=Fu(n,t.xpath);if(r)return as(r)}if(t.cssSelector)try{const r=n.querySelector(t.cssSelector);if(r)return as(r)}catch(r){Zf.warn("Invalid CSS selector:",t.cssSelector,r)}return ei(new ru(t,"Element not found using any identifier strategy"))}injectRivetId(t,n){t.setAttribute("data-rivet-id",n)}createElementIdentifier(t){const n=t.getAttribute("data-rivet-id"),r=G1(t);let i;if(t.id)i=`#${t.id}`;else if(t.className&&typeof t.className=="string"){const s=t.className.trim().split(/\s+/).join(".");s&&(i=`${t.tagName.toLowerCase()}.${s}`)}return{rivetId:n||"",xpath:r,cssSelector:i}}onHMR(t){var o;this.hmrCallbacks.push(t);let n=null,r=null;const i=()=>{r&&clearTimeout(r),r=setTimeout(()=>{this.handleIframeLoad()},1e3)};this.iframeRef&&this.hmrCallbacks.length===1&&this.iframeRef.addEventListener("load",this.handleIframeLoad);const s=this.iframeRef?Br(this.iframeRef):null;if(s){n=new MutationObserver(u=>{u.some(p=>{var g;const m=p.target;return!((g=m.closest)!=null&&g.call(m,'[id^="rivet-"]'))})&&i()});const a=s.body??s.documentElement??s,c=((o=s.defaultView)==null?void 0:o.Node)??Node;if(a instanceof c)try{n.observe(a,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","src","href"],characterData:!0})}catch{}}return()=>{const a=this.hmrCallbacks.indexOf(t);a!==-1&&this.hmrCallbacks.splice(a,1),n==null||n.disconnect(),r&&clearTimeout(r),this.hmrCallbacks.length===0&&this.iframeRef&&this.iframeRef.removeEventListener("load",this.handleIframeLoad)}}forceReload(){return new Promise((t,n)=>{var a;if(!((a=this.iframeRef)!=null&&a.contentWindow)){t();return}let r,i=!1;const s=()=>{var c;i||(i=!0,clearTimeout(r),(c=this.iframeRef)==null||c.removeEventListener("load",o))},o=()=>{s(),t()};r=setTimeout(()=>{s(),n(new Error("Iframe reload timeout after 10s"))},1e4),this.iframeRef.addEventListener("load",o);try{this.iframeRef.contentWindow.location.reload()}catch(c){s(),n(c)}})}}class $xe extends JV{}const Dxe={pending:"bg-primary",complete:"bg-accent-success",error:"bg-accent-error"},A6=36,T6=28,gg=10,P6=gg/2,s9=A6/2,o9=T6+P6,a9=8,Nxe=.65,l9=200,c9=8,Lxe=(e,t)=>{const n=e-t/2,r=window.innerWidth-t-c9;return Math.max(c9,Math.min(n,r))},eH=({comment:e,index:t,position:n,stale:r=!1,onEdit:i,onHover:s,onHoverEnd:o})=>{var b;const[a,c]=h.useState(!1),u=h.useCallback(x=>{x.stopPropagation(),i(e.id)},[e.id,i]),f=n.y/window.innerHeight>Nxe,p=e.instruction,g=Lxe(n.x,l9)-(n.x-s9);return y.jsxs("div",{className:"fixed",style:{top:f?n.y:n.y-o9,left:n.x-s9,zIndex:a?55:36,opacity:r?.5:1},onMouseEnter:()=>{c(!0),s==null||s()},onMouseLeave:()=>{c(!1),o==null||o()},children:[y.jsxs("div",{className:"relative cursor-pointer",style:{filter:"drop-shadow(0 1px 3px rgba(0,0,0,0.2))"},onClick:u,children:[y.jsx("div",{className:"absolute bg-main",style:{width:gg,height:gg,left:(A6-gg)/2,top:f?-P6:T6-P6,transform:"rotate(45deg)",borderRadius:3}}),y.jsxs("div",{className:"relative flex items-center justify-center rounded-lg bg-main",style:{width:A6,height:T6},children:[y.jsx("div",{className:`flex h-5 w-5 items-center justify-center rounded-full ${Dxe[e.status]}`,children:y.jsx("span",{className:"text-[10px] font-bold leading-none text-white",children:t+1})}),e.variantRequest?y.jsx("div",{"aria-label":"Direction request","data-testid":"comment-marker-variant-glyph",className:"absolute -right-1 -top-1 flex h-3.5 w-3.5 items-center justify-center rounded-full bg-primary text-white",children:y.jsx(s8,{className:"h-2.5 w-2.5",weight:"bold"})}):null]})]}),y.jsx(us,{children:a&&(p||((b=e.images)==null?void 0:b.length))&&y.jsxs(mn.div,{className:"absolute rounded-lg bg-main px-3 py-2 shadow-lg",style:{left:g,top:f?-a9:o9+a9,transformOrigin:f?"bottom center":"top center",width:l9},initial:{scale:.96,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.96,opacity:0,transition:{duration:.06,ease:[.55,0,1,.45]}},transition:{duration:.08,ease:[.165,.84,.44,1]},children:[p?y.jsx("p",{className:"line-clamp-2 text-left text-xs leading-snug text-content",children:p}):null,e.images&&e.images.length>0?y.jsx("div",{className:`flex flex-wrap justify-center gap-1 ${p?"mt-1.5":""}`,children:e.images.map((x,C)=>y.jsx("img",{src:x,alt:`Reference ${C+1}`,className:"max-h-10 rounded border border-divider"},C))}):null]})})]})},jxe=({onEditComment:e,target:t,iframeRef:n})=>{const[r,i]=Vn(ji),[s,o]=h.useState(null),[,a]=h.useState(0),c=h.useRef(null),u=h.useRef(new Map),f=h.useRef(new Set),p=h.useRef(null),m=h.useCallback(()=>{p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null,a(S=>S+1)}))},[]);h.useEffect(()=>{const S=n==null?void 0:n.current;if(!S)return;let D=null;const R=()=>{const O=Br(S);!O||O===D||(D&&D.removeEventListener("scroll",m,!0),D=O,O.addEventListener("scroll",m,!0))},L=()=>{R(),m()};R(),S.addEventListener("load",L),window.addEventListener("resize",m);const j=new ResizeObserver(m);return j.observe(S),c.current=()=>{S.removeEventListener("load",L),window.removeEventListener("resize",m),j.disconnect(),D&&D.removeEventListener("scroll",m,!0),p.current!==null&&(cancelAnimationFrame(p.current),p.current=null)},()=>{var O;return(O=c.current)==null?void 0:O.call(c)}},[n,m]);const g=h.useCallback(S=>{const D=n==null?void 0:n.current;D&&Vu(D,r.values()),i(R=>{const L=new Map(R);return L.delete(S),L})},[i,n,r]),b=Array.from(r.values()).filter(S=>Uh(S.target??Xs,t));if(b.length===0)return null;const x=(n==null?void 0:n.current)??null,C=x?Br(x):null,w=(x==null?void 0:x.getBoundingClientRect())??null,E=(S,D,R,L)=>{const j=u.current.get(S);if(!w)return j?{position:j,stale:!0}:null;if(!C){const Z=D.boundingRect,K={x:w.left+Z.left+R*Z.width,y:w.top+Z.top+L*Z.height};return u.current.set(S,K),{position:K,stale:!0}}const O=Ou(C,D);if(!O){if(!f.current.has(S)){const Z=X$(C,D);console.warn("[CommentMarkerLayer] anchor unresolved",{commentId:S,xpath:D.xpath,rivetId:D.rivetId,byRivetHit:!!Z.byRivet,byXPathHit:!!Z.byXPath,fallback:j?"cached-position":"none"}),f.current.add(S)}return j?{position:j,stale:!0}:null}f.current.delete(S);const H=O.getBoundingClientRect();if(H.bottom<0||H.top>w.height)return null;const B={x:w.left+H.left+R*H.width,y:w.top+H.top+L*H.height};return u.current.set(S,B),{position:B,stale:!1}},A=S=>{if(!S.dragBox||!w)return null;const D=C?Ou(C,S.elementContext):null,R=(D==null?void 0:D.getBoundingClientRect())??S.elementContext.boundingRect,{leftPct:L,topPct:j,widthPct:O,heightPct:H}=S.dragBox;return{left:w.left+R.left+L*R.width,top:w.top+R.top+j*R.height,width:O*R.width,height:H*R.height}},T=S=>{if(!w)return null;const D=!S.finalizedVariant&&(S.selectedVariantIndex??0)===0;if(S.dragBox&&D)return A(S);const R=C?Ou(C,S.elementContext):null,L=(R==null?void 0:R.getBoundingClientRect())??S.elementContext.boundingRect;return{left:w.left+L.left,top:w.top+L.top,width:L.width,height:L.height}},M=s!=null?r.get(s):void 0,I=M?T(M):null,P=!!(M!=null&&M.dragBox&&!M.finalizedVariant&&(M.selectedVariantIndex??0)===0);for(const S of u.current.keys())r.has(S)||u.current.delete(S);return y.jsxs(y.Fragment,{children:[b.map((S,D)=>{const R=E(S.id,S.elementContext,S.pin.elementXPct,S.pin.elementYPct);return R?y.jsx(eH,{comment:S,index:D,position:R.position,stale:R.stale,onDismiss:g,onEdit:e,onHover:()=>o(S.id),onHoverEnd:()=>o(null)},S.id):null}),I&&y.jsx("div",{"data-comment-hover-overlay":"true",style:{position:"fixed",pointerEvents:"none",zIndex:30,border:P?"1px dashed var(--color-primary, #FF3300)":"1px solid var(--color-primary-border, #ff6b35)",background:P?"rgba(255, 51, 0, 0.08)":"transparent",borderRadius:2,boxSizing:"border-box",left:I.left,top:I.top,width:I.width,height:I.height}})]})};function Fxe({reference:e,onRemove:t}){return y.jsxs("span",{className:"inline-flex max-w-[180px] items-center gap-1 rounded-full border border-divider bg-main-light px-2 py-0.5 text-[11px] text-content",children:[y.jsx(MI,{className:"h-3 w-3 shrink-0 text-content-muted",weight:"bold"}),y.jsx("span",{className:"truncate",title:e.label,children:e.label}),y.jsx("button",{type:"button",onClick:t,"aria-label":`Remove reference to ${e.label}`,className:"-mr-0.5 rounded-full p-0.5 text-content-muted transition-colors hover:bg-divider hover:text-content",children:y.jsx(Ho,{className:"h-2.5 w-2.5",weight:"bold"})})]})}const Oxe=Mt("CommentReferencePicker"),Bm=(e,t)=>`${e}:${t}`,tH=e=>`direction-reference-option-${e}`,u9=(e,t,n)=>e.kind==="variant"&&e.sessionId===t&&e.variantId===n;function Vxe({attached:e,commentTarget:t,onChange:n,onClose:r}){const i=ke(eo),s=ke(Z1),o=i.active&&i.projectContext.kind==="fresh"&&i.projectContext.workspaceRoot?i.projectContext.workspaceRoot:s,a=h.useRef(null),c=h.useRef([]),u=h.useRef(!1),f=h.useRef(0),p=h.useRef(void 0),m=h.useRef(null),g=h.useRef(r);g.current=r;const[b,x]=h.useState([]),[C,w]=h.useState(0),E=h.useCallback(async()=>{const B=f.current+1;f.current=B;const Z=o?`?projectPath=${encodeURIComponent(o)}`:"";try{const K=await fetch(`/api/variants/history${Z}`,{credentials:"same-origin"});if(!K.ok)return;const q=await K.json();if(B!==f.current)return;const Q=(q.variants??[]).filter(F=>{var V;return((V=F.preview)==null?void 0:V.kind)==="static"});x(Q)}catch(K){Oxe.warn("failed to load past directions for picker",K)}},[o]),A=h.useCallback(B=>{var q;if((q=m.current)==null||q.call(m),m.current=null,a.current=B,!B){f.current+=1,p.current=void 0;return}u.current||(u.current=!0,B.focus()),p.current!==o&&(p.current=o,E());const Z=Q=>{const F=a.current;F&&(F.contains(Q.target)||g.current())},K=Q=>{Q.key==="Escape"&&g.current()};window.addEventListener("pointerdown",Z),window.addEventListener("keydown",K),m.current=()=>{window.removeEventListener("pointerdown",Z),window.removeEventListener("keydown",K)}},[o,E]),T=h.useMemo(()=>new Set(e.map(B=>Bm(B.sessionId,B.variantId))),[e]),M=h.useMemo(()=>i.active?i.variants.filter(B=>B.status==="succeeded").filter(B=>!u9(t,i.sessionId,B.workItemId)).map(B=>({key:Bm(i.sessionId,B.workItemId),reference:{sessionId:i.sessionId,variantId:B.workItemId,label:B.label||"Direction",origin:"live"}})):[],[i,t]),I=h.useMemo(()=>b.filter(B=>!u9(t,B.sessionId,B.variantId)).map(B=>({key:Bm(B.sessionId,B.variantId),reference:{sessionId:B.sessionId,variantId:B.variantId,label:B.label||"Direction",origin:"history"},brief:B.brief})),[b,t]),P=h.useMemo(()=>{const B=new Set(M.map(Z=>Z.key));return I.filter(Z=>!B.has(Z.key))},[M,I]),S=h.useMemo(()=>{const B=[];return M.length>0&&B.push({heading:"This session",rows:M}),P.length>0&&B.push({heading:"Directions",rows:P}),B},[M,P]),D=h.useMemo(()=>S.flatMap(B=>B.rows),[S]),R=h.useMemo(()=>{const B=new Map;return D.forEach((Z,K)=>B.set(Z.key,K)),B},[D]),L=h.useCallback(B=>{const Z=B.key;T.has(Z)?n(e.filter(K=>Bm(K.sessionId,K.variantId)!==Z)):n([...e,B.reference])},[e,T,n]),j=C<D.length?C:0,O=B=>{var Z;w(B),(Z=c.current[B])==null||Z.scrollIntoView({block:"nearest"})},H=B=>{if(B.key==="Escape"){B.preventDefault(),r();return}const Z=D.length;if(Z!==0)switch(B.key){case"ArrowDown":{B.preventDefault(),O((j+1)%Z);break}case"ArrowUp":{B.preventDefault(),O((j-1+Z)%Z);break}case"Enter":case" ":{B.preventDefault();const K=D[j];K&&L(K);break}}};return y.jsx("div",{ref:A,tabIndex:-1,onKeyDown:H,className:"max-h-72 w-72 overflow-y-auto rounded-lg border border-divider bg-main shadow-2xl focus:outline-none",role:"listbox","aria-label":"Reference a direction","aria-activedescendant":D.length>0?tH(j):void 0,children:S.length===0?y.jsx("div",{className:"px-3 py-4 text-xs text-content-muted",children:"No directions available to reference yet."}):S.map(B=>y.jsx(Hxe,{section:B,attachedKeys:T,highlightedIndex:j,indexOf:Z=>R.get(Z)??-1,itemRefs:c,onToggle:L,onHover:w},B.heading))})}function Hxe({section:e,attachedKeys:t,highlightedIndex:n,indexOf:r,itemRefs:i,onToggle:s,onHover:o}){return y.jsxs("div",{children:[y.jsx("div",{className:"sticky top-0 z-10 border-b border-divider bg-main px-3 py-1.5 text-[10px] font-medium uppercase tracking-wider text-content-muted",children:e.heading}),y.jsx("ul",{className:"py-1",children:e.rows.map(a=>{const c=t.has(a.key),u=r(a.key),f=u===n;return y.jsx("li",{children:y.jsxs("button",{type:"button",id:tH(u),ref:p=>{i.current[u]=p},role:"option",onClick:()=>s(a),onMouseEnter:()=>o(u),"aria-selected":c,className:`group flex w-full items-start gap-2 px-3 py-2 text-left transition-colors ${f?"bg-main-hover":"hover:bg-main-input"}`,children:[y.jsx("span",{className:`mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded border ${c?"border-primary bg-primary text-white":"border-divider text-transparent group-hover:border-content-muted"}`,children:y.jsx(za,{className:"h-2.5 w-2.5",weight:"bold"})}),y.jsxs("span",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:"block truncate text-sm text-content",children:a.reference.label}),a.brief?y.jsx("span",{className:"block truncate text-[11px] leading-snug text-content-muted",children:a.brief}):null]})]})},a.key)})})]})}const d9=3,f9=2,h9=8,Bxe=[/\bvariants?\s*[:=]\s*(\d+)(?!\.\d)\b/i,/\b(\d+)(?!\.\d)\s*variants?\b/i,/\bvariants?\s+(\d+)(?!\.\d)\b/i],zxe=e=>e<f9?f9:e>h9?h9:e,p9=e=>{if(!e)return d9;for(const t of Bxe){const n=t.exec(e);if(!n)continue;const r=n[1];if(!/^\d+$/.test(r))continue;const i=Number.parseInt(r,10);if(!(!Number.isInteger(i)||i<=0))return zxe(i)}return d9},m9=8,g9=320,v9=8,y9=3,Uxe=15e3,Zxe=1,Wxe="7.5rem",Gxe=.65,qxe=({elementContext:e,target:t=Xs,pin:n,dragBox:r,position:i,onClose:s,existingCommentId:o,isMCPSession:a=!1,onInputChange:c,shake:u})=>{var Vt,Gt;const f=bs(),p=rJ(),[m,g]=Vn(ji),b=ke(xp),C=ke(Qs).variants.isEnabled,w=Be(Js),E=Be(bp),A=Be(hd),T=Be(b$),M=bc(),{sendVariantRequestComment:I}=Q$(),P=ke(F8),S=o?m.get(o):void 0,D=(S==null?void 0:S.instruction)??"",[R,L]=h.useState(D),[j,O]=h.useState((S==null?void 0:S.images)??[]),[H,B]=h.useState((S==null?void 0:S.references)??[]),[Z,K]=h.useState(!1),q=h.useRef(null),Q=h.useRef(null),F=h.useRef(null);h.useEffect(()=>{const J=setTimeout(()=>{const Y=q.current;Y&&(Y.focus(),Y.selectionStart=Y.selectionEnd=Y.value.length)},150);return()=>clearTimeout(J)},[]);const V=h.useCallback(()=>{F.current&&(clearTimeout(F.current),F.current=null)},[]);h.useEffect(()=>()=>{V()},[V]);const W=h.useRef(u);h.useEffect(()=>{u!==W.current&&p.start({x:[0,-5,5,-4,4,-2,2,0],y:[0,1.5,-1.5,1,-1,.5,-.5,0],transition:{duration:.45,ease:"easeInOut"}})},[u,p]);const N=R.trim()!==D.trim()&&R.trim()!==""||j.length!==(((Vt=S==null?void 0:S.images)==null?void 0:Vt.length)??0)||H.length!==(((Gt=S==null?void 0:S.references)==null?void 0:Gt.length)??0),z=o?N:R.trim()!=="",ee=h.useCallback(J=>{B(J),c==null||c(R.trim()!==""||j.length>0||J.length>0)},[R,j.length,c]),te=h.useCallback(J=>{ee(H.filter(Y=>!(Y.sessionId===J.sessionId&&Y.variantId===J.variantId)))},[H,ee]),re=h.useCallback(J=>{s(J)},[s]),G=h.useCallback(J=>{J.style.height="auto",J.style.height=`${J.scrollHeight}px`},[]),X=h.useCallback(J=>{T3(J).then(Y=>{O(se=>[...se,Y])}).catch(()=>{console.warn("[CommentPopover] Failed to process image:",J.name)})},[]),de=h.useCallback(J=>{O(Y=>[...Y,J]),c==null||c(!0)},[c]),{isDragOver:ve,dropHandlers:we}=sL(de),Fe=J=>{const Y=J.target.files;if(!Y)return;let se=!1;for(const ce of Array.from(Y))ce.type.startsWith("image/")&&(X(ce),se=!0);Q.current&&(Q.current.value=""),se&&(c==null||c(!0))},Te=J=>{var se;const Y=(se=J.clipboardData)==null?void 0:se.items;if(Y){for(const ce of Array.from(Y))if(ce.type.startsWith("image/")){J.preventDefault();const le=ce.getAsFile();le&&(X(le),c==null||c(!0))}}},je=J=>{const Y=j.filter((se,ce)=>ce!==J);O(Y),c==null||c(R.trim()!==""||Y.length>0)},nt=h.useCallback(async()=>{const J=R.trim();if(J){if(o)g(Y=>{const se=Y.get(o);if(!se)return Y;const ce=new Map(Y);return ce.set(o,{...se,instruction:J,images:j.length>0?j:void 0,references:H.length>0?H:void 0,variantRequest:void 0}),ce}),f==null||f.capture("comment_edited",{instruction_length:J.length,image_count:j.length,reference_count:H.length,has_variants:!1});else{const Y=crypto.randomUUID(),se={id:Y,target:t,elementContext:e,pin:n,dragBox:r,instruction:J,images:j.length>0?j:void 0,references:H.length>0?H:void 0,status:"pending"};g(ce=>{const le=new Map(ce);return le.set(Y,se),le}),f==null||f.capture("comment_added",{instruction_length:J.length,image_count:j.length,reference_count:H.length,has_variants:!1})}re({preserveSelection:!0})}},[R,j,H,o,e,t,n,r,g,f,re]),yt=h.useCallback(async J=>{const Y=R.trim();if(!Y)return;const se=J==="mcp"?p9(R):y9,ce=o??crypto.randomUUID();if(o)g(ge=>{const Ce=ge.get(o);if(!Ce)return ge;const $e=new Map(ge);return $e.set(o,{...Ce,instruction:Y,images:void 0,references:H.length>0?H:void 0,variantRequest:{count:se}}),$e}),f==null||f.capture("comment_edited",{instruction_length:Y.length,image_count:0,reference_count:H.length,has_variants:!1});else{const ge={id:ce,target:t,elementContext:e,pin:n,dragBox:r,instruction:Y,references:H.length>0?H:void 0,variantRequest:{count:se},status:"pending"};g(Ce=>{const $e=new Map(Ce);return $e.set(ce,ge),$e}),f==null||f.capture("comment_added",{instruction_length:Y.length,image_count:0,reference_count:H.length,has_variants:!1})}f==null||f.capture("comment_variant_trigger_started",{source:J,requestedCount:se}),V(),T(!0),F.current=setTimeout(()=>{F.current=null,T(!1)},Uxe),A(!0),E(!0),w("comment"),re({preserveSelection:!0});const le=await I(ce,{transport:J==="desktop"?"desktop":"mcp"});le.cancelled||le.success||(V(),T(!1),ct.error(le.error||"Failed to queue direction request"))},[R,H,o,e,t,n,r,g,f,re,w,E,A,T,I,V]),et=nt,ye=h.useCallback(async()=>{var J;if(o){Bte(o);const Y=(b==null?void 0:b.current)??null;Y&&Vu(Y,m.values());const se=M.get(qa);se&&se.commentId===o&&(await a1(se.diff),M.set(qa,null));const ce=m.get(o),le=(J=ce==null?void 0:ce.finalizedVariant)==null?void 0:J.codeDiff;le&&await a1(le),g(ge=>{const Ce=new Map(ge);return Ce.delete(o),Ce}),f==null||f.capture("comment_deleted")}re()},[o,m,b,g,re,f,M]),Ye=h.useCallback(J=>{if(J.key==="Enter"&&(J.metaKey||J.ctrlKey)){J.preventDefault(),J.nativeEvent.stopImmediatePropagation(),et();return}if(J.key==="Enter"&&!J.shiftKey){J.preventDefault(),J.nativeEvent.stopImmediatePropagation(),et();return}J.key==="Escape"&&(J.preventDefault(),J.nativeEvent.stopImmediatePropagation(),re({preserveSelection:!0}))},[et,re]),$t=window.innerHeight,Tt=i.y/$t>Gxe,Nt=o?"Save":"Add",yn=!o&&(a||C),nn=a?"mcp":"desktop",he=a?"mcp-variant-trigger":"desktop-variant-trigger",be=a?"Generate directions":"Generate 3 directions",We=(()=>{if(R.trim()==="")return"empty_instruction";if(P.getStyleChanges().length>0||P.getTextChanges().length>0)return"mixed_batch";const Y=Array.from(m.values()).filter(le=>le.status==="pending"&&le.id!==o);return Y.some(le=>!!le.variantRequest)?"duplicate_variant_request":Y.some(le=>!le.variantRequest)?"mixed_batch":null})(),ot=a?p9(R):y9,lt=(()=>{switch(We){case"empty_instruction":return"Add an instruction";case"mixed_batch":return"Clear pending changes";case"duplicate_variant_request":return"Request already pending";default:return`Explore ${ot} directions`}})();return y.jsx("div",{className:"z-comment-preview fixed cursor-auto","data-testid":"comment-popover",style:{top:Tt?i.y-m9:i.y+m9,left:Math.max(v9,Math.min(i.x-g9/2,window.innerWidth-g9-v9)),transform:Tt?"translateY(-100%)":void 0},onClick:J=>J.stopPropagation(),onDoubleClick:J=>{J.stopPropagation(),re({preserveSelection:!0})},children:y.jsx(mn.div,{animate:p,children:y.jsxs(mn.div,{className:"bg-main relative flex w-80 flex-col gap-2 rounded-xl p-4 shadow-2xl",style:{transformOrigin:"center 24px"},initial:{scale:.82,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.82,opacity:0,transition:{duration:.1,ease:[.55,0,1,.45]}},transition:{type:"spring",stiffness:500,damping:28,mass:.8},...we,children:[ve?y.jsx("div",{className:"border-primary bg-primary/10 pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-xl border-2 border-dashed",children:y.jsx("span",{className:"text-content text-sm font-medium",children:"Drop image here"})}):null,H.length>0?y.jsx("div",{className:"flex flex-wrap gap-1.5",children:H.map(J=>y.jsx(Fxe,{reference:J,onRemove:()=>te(J)},`${J.sessionId}:${J.variantId}`))}):null,y.jsx("textarea",{ref:J=>{q.current=J,J&&G(J)},value:R,onChange:J=>{const Y=J.target.value;L(J.target.value),G(J.target),c==null||c(Y.trim()!==""||j.length>0)},onKeyDown:Ye,onPaste:Te,placeholder:"What should change?",rows:Zxe,style:{maxHeight:Wxe,overflowY:"auto"},className:"bg-main-light text-content placeholder:text-content-subtle w-full resize-none rounded-lg p-3 text-sm outline-none"}),j.length>0?y.jsx("div",{className:"max-h-40 overflow-y-auto rounded",children:y.jsx("div",{className:`grid gap-1.5 ${j.length===1?"grid-cols-1":"grid-cols-2"}`,children:j.map((J,Y)=>y.jsxs("div",{className:"relative",children:[y.jsx("img",{src:J,alt:`Reference ${Y+1}`,className:`border-divider w-full rounded border object-cover ${j.length===1?"max-h-32":"aspect-[4/3]"}`}),y.jsx("button",{onClick:()=>je(Y),className:"absolute top-1 right-1 rounded-full bg-red-500/80 p-0.5 text-white backdrop-blur-sm hover:bg-red-600",children:y.jsx(Ho,{className:"h-2.5 w-2.5",weight:"bold"})})]},Y))})}):null,y.jsx("input",{ref:Q,type:"file",accept:"image/*",multiple:!0,onChange:Fe,className:"hidden"}),y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsxs("div",{className:"flex items-center gap-1",children:[o?y.jsx("button",{type:"button",onClick:ye,className:"text-content-subtle hover:text-accent-error p-1 transition-colors",title:"Delete comment",children:y.jsx(fM,{className:"h-4 w-4",weight:"bold"})}):null,y.jsx(Fi,{label:"Attach images",children:y.jsx("button",{type:"button","aria-label":"Attach images",onClick:()=>{var J;return(J=Q.current)==null?void 0:J.click()},className:"text-content-subtle hover:text-content p-1 transition-colors",children:y.jsx(WI,{className:"h-4 w-4",weight:"bold"})})}),y.jsx(Fi,{label:"Reference a direction",children:y.jsxs("div",{className:"relative",children:[y.jsx("button",{type:"button","aria-label":"Reference a direction","aria-haspopup":"listbox","aria-expanded":Z,onClick:()=>K(J=>!J),className:`p-1 transition-colors ${Z||H.length>0?"text-content":"text-content-subtle hover:text-content"}`,children:y.jsx(MI,{className:"h-4 w-4",weight:"bold"})}),Z?y.jsx("div",{className:"absolute bottom-full left-0 z-20 mb-2",children:y.jsx(Vxe,{attached:H,commentTarget:t,onChange:ee,onClose:()=>K(!1)})}):null]})})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[yn?y.jsx(Fi,{label:lt,children:y.jsxs("button",{type:"button","aria-label":be,"data-testid":he,onClick:()=>void yt(nn),disabled:We!==null,className:"border-main-border text-content hover:bg-main-input flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50",children:[y.jsx(s8,{className:"h-4 w-4",weight:"bold"}),y.jsx("span",{children:"Vary"})]})}):null,y.jsx("button",{onClick:()=>et(),disabled:!z,className:"bg-primary hover:bg-primary-hover rounded-full px-5 py-1.5 text-sm font-medium text-white transition-colors disabled:opacity-50",children:Nt})]})]})]})})})},Kxe="allow-scripts allow-same-origin allow-forms allow-popups allow-modals",Yxe="allow-scripts allow-forms allow-popups allow-modals",Xxe=e=>e==="embedded"?Yxe:Kxe,b9=Mt("PreviewSurface"),nH=({target:e,src:t,framework:n,mode:r,isUpstreamReady:i,remountKey:s})=>{const o=No(e),a=Be(XJ),c=Be(QJ),u=Be(hs),f=ke(ji),p=Be(V8),m=ke(wp),g=ke(W1),b=g==="embedded",x=Be(uc),[C,w]=Vn(C$),[E,A]=h.useState(null),T=h.useRef(null),M=bc(),[I,P]=Vn(Qg),S=h.useCallback(()=>M.get(uc),[M]),D=I&&Uh(I.target,e)?I:null,R=h.useRef(null),{enterEditMode:L}=Mxe({iframeRef:R}),j=ke(Qs);Rxe({iframeRef:R,enabled:j.resize.isEnabled&&!b,surfaceId:o});const O=h.useCallback(G=>x(G),[x]),H=h.useCallback((G,X,de)=>{if(S()){w(ve=>ve+1);return}O(!1),p(null),u(e),P({key:crypto.randomUUID(),target:e,elementContext:G,pin:X,dragBox:de})},[S,w,O,p,u,P,e]),B=h.useCallback(()=>{if(S()){w(G=>G+1);return}P(null),p(null),O(!1)},[S,w,P,O,p]),Z=h.useCallback((G,X,de)=>{L(G,X,de)},[L]),{setupIframe:K,clearSelectionState:q,iframeRef:Q}=Ixe({surfaceId:o,target:e,mode:r,isBoxModelVisible:!0,onTextEdit:Z,onCommentClick:H,onCommentSelectionClear:B,isPreviewBridgeEnabled:b}),F=h.useCallback(G=>{P(null),p(null),O(!1),G!=null&&G.preserveSelection||q()},[q,P,O,p]),V=h.useCallback(G=>{const X=f.get(G);X&&(O(!1),p(G),u(e),P({key:crypto.randomUUID(),target:e,elementContext:X.elementContext,pin:X.pin,dragBox:X.dragBox,existingCommentId:G}))},[f,O,p,u,P,e]),W=h.useCallback((G,X)=>{const de=Q.current;if(!de)return null;const ve=de.getBoundingClientRect(),we=b?null:Br(de),Fe=we?Ou(we,G):null,Te=(Fe==null?void 0:Fe.getBoundingClientRect())??G.boundingRect;return{x:ve.left+Te.left+X.elementXPct*Te.width,y:ve.top+Te.top+X.elementYPct*Te.height}},[b,Q]),[,N]=h.useState(0),z=h.useCallback(()=>N(G=>G+1),[]);h.useEffect(()=>{const G=Q.current;if(!D||!G)return;const X=b?null:Br(G);X&&X.addEventListener("scroll",z,!0);const de=new ResizeObserver(z);return de.observe(G),G.addEventListener("load",z),()=>{X&&X.removeEventListener("scroll",z,!0),de.disconnect(),G.removeEventListener("load",z)}},[D,Q,z,b]);const ee=D?W(D.elementContext,D.pin):null,te=i&&!b;h.useEffect(()=>{if(b){E&&(T.current=null,A(null),c({surfaceId:o,adapter:null}));return}if(n!=="static"&&!i){E&&(T.current=null,A(null),c({surfaceId:o,adapter:null}));return}const G=Q.current;if(E&&T.current!==G){T.current=null,A(null),c({surfaceId:o,adapter:null});return}if(G&&!E){const X=n==="static";b9.debug(`Creating ${X?"Static":""}IframeDisplayAdapter`);const de=r==="edit"?"edit":"view",ve=X?new $xe(G,{mode:de,isBoxModelVisible:!0}):new JV(G,{mode:de,isBoxModelVisible:!0});ve.initialize(),T.current=G,A(ve),c({surfaceId:o,adapter:ve})}},[E,n,i,b,r,Q,c,o]);const re=h.useCallback(G=>{G?(K(G),R.current=G):R.current=null},[K]);return h.useEffect(()=>(a({surfaceId:o,ref:Q}),()=>{a({surfaceId:o,ref:null}),c({surfaceId:o,adapter:null})}),[a,c,o,Q]),h.useEffect(()=>{r==="comment"||r==="edit"||S()||(P(null),p(null),r==="view"&&q())},[r,S,q,P,p]),y.jsxs("div",{className:"relative h-full w-full",children:[y.jsx("iframe",{ref:re,src:t,className:"h-full w-full border-none",title:"Project Preview",sandbox:Xxe(g),onLoad:()=>{vt==null||vt.capture("preview_iframe_loaded",{framework:n,src:t})},onError:()=>{vt==null||vt.capture("preview_iframe_load_failed",{framework:n,src:t}),b9.warn("Preview iframe failed to load",{framework:n,src:t})}},s),te?y.jsx(jxe,{onEditComment:V,target:e,iframeRef:Q}):null,(D==null?void 0:D.dragBox)&&!D.existingCommentId&&Q.current&&(()=>{const G=Q.current,X=G.getBoundingClientRect(),de=b?null:Br(G),ve=de?Ou(de,D.elementContext):null,we=(ve==null?void 0:ve.getBoundingClientRect())??D.elementContext.boundingRect,{leftPct:Fe,topPct:Te,widthPct:je,heightPct:nt}=D.dragBox;return y.jsx("div",{"data-comment-drag-box":"true",style:{position:"fixed",pointerEvents:"none",zIndex:45,border:"1px dashed var(--color-primary, #FF3300)",background:"rgba(255, 51, 0, 0.08)",borderRadius:2,boxSizing:"border-box",left:X.left+we.left+Fe*we.width,top:X.top+we.top+Te*we.height,width:je*we.width,height:nt*we.height}})})(),D&&ee&&!D.existingCommentId&&y.jsx(eH,{comment:{id:"draft",elementContext:D.elementContext,pin:D.pin,instruction:"",status:"pending"},index:f.size,position:ee,onDismiss:()=>{},onEdit:()=>{}}),xc.createPortal(y.jsx(us,{children:D&&ee?y.jsx(qxe,{elementContext:D.elementContext,target:e,pin:D.pin,dragBox:D.dragBox,position:ee,onClose:F,existingCommentId:D.existingCommentId,isMCPSession:m,onInputChange:G=>{O(G)},shake:C},D.key):null}),document.body)]})},Qxe=({isInteractionDisabled:e=!1,framework:t,userPort:n,activeDemoSessionId:r=null,holdPreviewNavigation:i=!1})=>{var N;const s=ke(Js),o=ke(mw),a=Be(mw),c=ke(Jg),u=Be(Jg),f=ke(eo),p=ke(W1),m=ke(gw),g=ke(y$),b=ke(wc),x=Be(gw),C=f.active&&f.projectContext.kind==="fresh",w=ke(vw),E=f.active?f.variants.find(z=>z.workItemId===w&&(z.status==="pending"||z.status==="running"))??null:null,A=f.active&&f.variants.some(z=>z.status==="pending"||z.status==="running"),T=C||A,M=f.active?f.variants.find(z=>z.workItemId===w&&z.status==="succeeded"&&!!z.previewUnavailable)??null:null;h.useEffect(()=>{f.active||x(!1)},[f.active,x]);const I=h.useMemo(()=>{var X;if(m||c||!f.active)return null;const{stage:z,variants:ee}=f,te=z==="ready"||z==="degraded",re=ee.some(de=>{var ve,we;return((ve=de.refinement)==null?void 0:ve.status)==="pending"||((we=de.refinement)==null?void 0:we.status)==="running"});if(!te&&!re)return null;const G=ee.find(de=>{var ve;return de.status==="succeeded"&&((ve=de.preview)==null?void 0:ve.kind)==="static_artifact"});return((X=G==null?void 0:G.preview)==null?void 0:X.kind)==="static_artifact"?G.preview.url:null},[c,m,f]),P=c??I,S=h.useMemo(()=>!f.active||!P?null:f.variants.find(z=>{var ee;return((ee=z.preview)==null?void 0:ee.kind)==="static_artifact"&&P.startsWith(z.preview.url)})??null,[P,f]),D=h.useMemo(()=>f.active?S?{kind:"variant",sessionId:f.sessionId,variantId:S.workItemId}:(!!!(b!=null&&b.left||b!=null&&b.right)||C)&&!P&&m&&g&&f.variants.some(ee=>ee.workItemId===g)?{kind:"variant",sessionId:f.sessionId,variantId:g}:Xs:Xs,[S,f,m,g,P,b,C]),R=h.useRef(null);h.useEffect(()=>{var re,G;if(!S||((re=S.preview)==null?void 0:re.kind)!=="static_artifact"||((G=S.refinement)==null?void 0:G.status)!=="succeeded")return;const z=`${S.workItemId}:${S.refinement.workItemId}`;if(R.current===z)return;R.current=z;const ee=S.preview.url.includes("?")?"&":"?",te=`${S.preview.url}${ee}refinement=${encodeURIComponent(S.refinement.workItemId)}`;P!==te&&(u(te),a(X=>X+1))},[P,S,a,u,f]);const L=P!==null||C&&!m,{isUpstreamReady:j,iframeRemountKey:O,initialProbeComplete:H}=nbe(t,{rerunProbeImmediatelyOnVersion:o,skip:L}),B=!!P||j,Z=`${O}:${o}`,K=r?`/try/${encodeURIComponent(r)}`:"",q=t==="static"?`${K}/static/`:`${K}/`,Q=p==="embedded"&&typeof window<"u"?`${window.location.protocol}//localhost:${window.location.port}`:"",F=E?"about:blank":P??(i||!B?"about:blank":`${Q}${q}`),V=!!E||!!M||!B&&H;let W=null;if(E)W=y.jsxs(y.Fragment,{children:[y.jsx("div",{"aria-hidden":!0,className:"h-8 w-8 animate-spin rounded-full border-2 border-content-muted/30 border-t-content"}),y.jsxs("h2",{className:"text-3xl font-semibold text-content",children:["Building “",E.label||"this direction","”…"]}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:"This direction is still generating. It’ll load here the moment it’s ready."})]});else if(M){const z=((N=M.previewUnavailable)==null?void 0:N.portInUse)??!1;W=y.jsxs(y.Fragment,{children:[y.jsx("h2",{className:"text-3xl font-semibold text-content",children:"This direction’s preview couldn’t start"}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:z?"Rivet tried to start it on a free port, but this project’s dev server insists on a port that’s already taken (its dev script likely hardcodes the port). You can still pick this direction by reading its code, or reload to try again.":"Its preview server didn’t come up, so there’s nothing to show live. You can still pick this direction by reading its code, or reload to try again."}),y.jsx("button",{onClick:()=>window.location.reload(),className:"rounded-md bg-primary px-10 py-2.5 text-sm font-medium text-white transition-colors hover:bg-primary-hover",children:"Reload"})]})}else T?W=y.jsxs(y.Fragment,{children:[y.jsx("h2",{className:"text-3xl font-semibold text-content",children:"Directions will appear here"}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:"Select one from the panel to preview it."})]}):W=y.jsxs(y.Fragment,{children:[y.jsx("h2",{className:"text-3xl font-semibold text-content",children:"Preview isn't connected"}),y.jsx("p",{className:"text-base leading-relaxed text-content-muted",children:"The connection between Rivet and your project is offline. Try restarting Rivet, then click reload below."}),y.jsx("button",{onClick:()=>window.location.reload(),className:"rounded-md bg-primary px-10 py-2.5 text-sm font-medium text-white transition-colors hover:bg-primary-hover",children:"Reload"})]});return y.jsxs("div",{className:"relative h-full w-full",children:[V?y.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-main/90 px-6",children:y.jsx("div",{role:"alert","aria-live":"polite",className:"flex max-w-sm flex-col items-center gap-5 text-center",children:W})}):null,y.jsx(nH,{target:D,src:F,framework:t,mode:e?"view":s,isUpstreamReady:B,remountKey:Z})]})},Wf=10,Jxe=2,e4e=.18,t4e=.013,x9=.6,w9=.0016,n4e=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]],r4e=e=>e*e*e,i4e=e=>Math.min(1,Math.max(0,e)),rH=({collapsing:e=!1,onCollapsed:t})=>{const n=h.useRef(null),r=h.useRef(null),i=h.useRef(e),s=h.useRef(t);i.current=e,s.current=t;const o=Be(h$);return h.useEffect(()=>{var L;const a=n.current,c=r.current;if(!a||!c)return;o(j=>j+1);const u=a.getContext("2d"),f=Math.min(window.devicePixelRatio||1,2),p=((L=window.matchMedia)==null?void 0:L.call(window,"(prefers-reduced-motion: reduce)").matches)??!1;let m=0,g=0,b=0,x=0,C=0,w=1,E=null,A=!1;const T=()=>{b=c.clientWidth,x=c.clientHeight,a.width=Math.floor(b*f),a.height=Math.floor(x*f),u==null||u.setTransform(f,0,0,f,0,0),m=Math.ceil(b/Wf)+1,g=Math.ceil(x/Wf)+1,w=m+g||1},M=(j,O)=>{if(!u)return;u.clearRect(0,0,b,x);const H=Wf-Jxe;for(let B=0;B<g;B++)for(let Z=0;Z<m;Z++){const K=Z*Wf,q=B*Wf,Q=.5+.5*Math.sin((K+q)*t4e-j*e4e),F=(n4e[B&3][Z&3]+.5)/16;if(Q<=F)continue;let V=1;if(O>0&&(V=1-r4e(i4e((O-(Z+B)*w9)/x9))),V<=.001)continue;const W=H*V,N=(H-W)/2;u.fillStyle=Q>.8?"#ff5a1e":"#ff3300",u.fillRect(K+N,q+N,W,W)}},I=()=>{var j;A||(A=!0,u==null||u.clearRect(0,0,b,x),(j=s.current)==null||j.call(s))},P=j=>{const O=p?0:j/1e3;if(i.current){if(p){I();return}E===null&&(E=j);const H=(j-E)/1e3;if(H-w*w9>=x9){I();return}M(O,H)}else M(O,0);C=requestAnimationFrame(P)};T(),p&&!i.current&&M(0,0),C=requestAnimationFrame(P);const S=()=>{const j=performance.now(),O=p?0:j/1e3,H=!p&&i.current&&E!==null?(j-E)/1e3:0;M(O,H)},D=()=>{A||(T(),S())};let R;return typeof ResizeObserver<"u"?(R=new ResizeObserver(D),R.observe(c)):window.addEventListener("resize",D),()=>{o(j=>j-1),cancelAnimationFrame(C),R==null||R.disconnect(),window.removeEventListener("resize",D)}},[o]),y.jsx("div",{className:"relative flex h-full w-full items-center justify-center overflow-hidden bg-[#f3ede3]",children:y.jsx("div",{ref:r,"data-testid":"ascii-dither-stage",className:"aspect-square max-h-[90%] max-w-[90%] overflow-hidden rounded-[64px]",style:{width:"min(90%, 90vh)"},children:y.jsx("canvas",{ref:n,className:"block h-full w-full"})})})};function k9({side:e,sessionId:t,variantId:n,url:r,label:i,isFallback:s=!1}){var b;const o=Be(wc),a=ke(Js),c=ke(eo),u=h.useCallback(()=>{if(s){o(null);return}o(x=>{if(!x)return null;const C={...x};return delete C[e],C.left||C.right?C:null})},[o,e,s]),f=h.useMemo(()=>({kind:"variant",sessionId:t,variantId:n}),[t,n]),p=h.useMemo(()=>!c.active||c.sessionId!==t?null:c.variants.find(x=>x.workItemId===n)??null,[t,n,c]),m=h.useMemo(()=>{var C,w;if(((C=p==null?void 0:p.preview)==null?void 0:C.kind)!=="static_artifact"||((w=p.refinement)==null?void 0:w.status)!=="succeeded")return r;const x=p.preview.url.includes("?")?"&":"?";return`${p.preview.url}${x}refinement=${encodeURIComponent(p.refinement.workItemId)}`},[p,r]),g=((b=p==null?void 0:p.refinement)==null?void 0:b.status)==="succeeded"?`${n}:${p.refinement.workItemId}`:n;return y.jsxs("div",{className:"variant-split-secondary","data-cy":"variant-split-pane","data-variant-id":n,children:[y.jsxs("div",{className:"variant-split-secondary-toolbar",children:[y.jsx("span",{className:"variant-split-secondary-label",title:i,children:i}),y.jsx(Fi,{label:"Collapse",children:y.jsx("button",{type:"button",className:"variant-split-secondary-close",onClick:u,"aria-label":"Collapse split view",children:y.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",focusable:"false",children:y.jsx("path",{d:"M2.5 2.5 L9.5 9.5 M9.5 2.5 L2.5 9.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})})]}),y.jsx("div",{className:"variant-split-secondary-body relative min-h-0 flex-1",children:y.jsx(nH,{target:f,src:m,framework:"static",mode:a,isUpstreamReady:!0,remountKey:g})})]})}const C9=240;function s4e(){const e=ke(Wh),t=ke(H8),n=h.useRef(null);return h.useEffect(()=>{if(!e||!t||!n.current)return;const r=t.x-C9/2,i=t.y-22;n.current.style.transform=`translate3d(${r}px, ${i}px, 0)`},[e,t]),!e||!t?null:y.jsx("div",{ref:n,"aria-hidden":"true",className:"variant-drag-ghost",style:{width:C9},children:y.jsxs("div",{className:"variant-drag-ghost-body",children:[y.jsxs("div",{className:"variant-drag-ghost-row",children:[y.jsx("div",{className:"variant-drag-ghost-title",children:e.label}),e.runLabel?y.jsx("div",{className:"variant-drag-ghost-tag",style:H$(e.runLabel),children:e.runLabel}):null]}),e.description?y.jsx("div",{className:"variant-drag-ghost-desc",children:e.description}):null]})})}function o4e(){const e=ke(Wh),t=ke(H8),n=Be(Wh),r=Be(wc),i=h.useRef(null),[s,o]=h.useState(null),[a,c]=h.useState("hidden");h.useEffect(()=>{if(!e){c("hidden"),o(null);return}const p=requestAnimationFrame(()=>c("visible"));return()=>cancelAnimationFrame(p)},[e]);const u=h.useCallback((p,m)=>{const g=i.current;if(!g)return null;const b=g.getBoundingClientRect();return p<b.left||p>b.right||m<b.top||m>b.bottom?null:p<(b.left+b.right)/2?"left":"right"},[]);if(h.useEffect(()=>{if(!e||!t)return;const p=u(t.x,t.y);o(m=>m===p?m:p)},[e,t,u]),h.useEffect(()=>{if(!e)return;const p=m=>{const g=u(m.clientX,m.clientY);if(g&&e.url){const b={sessionId:e.sessionId,variantId:e.variantId,label:e.label,url:e.url};r(x=>({...x??{},[g]:b})),c("exiting"),window.setTimeout(()=>n(null),220)}else c("exiting"),window.setTimeout(()=>n(null),220)};return window.addEventListener("pointerup",p),window.addEventListener("pointercancel",p),()=>{window.removeEventListener("pointerup",p),window.removeEventListener("pointercancel",p)}},[e,u,n,r]),!e)return null;const f=["variant-drop-zones",a==="visible"&&"is-visible",a==="exiting"&&"is-exiting"].filter(Boolean).join(" ");return y.jsxs("div",{ref:i,className:f,"aria-hidden":"true",children:[y.jsx(E9,{side:"left",hovered:s==="left",canDrop:!!e.url,label:e.label}),y.jsx(E9,{side:"right",hovered:s==="right",canDrop:!!e.url,label:e.label})]})}function E9({side:e,hovered:t,canDrop:n,label:r}){return y.jsxs("div",{className:["variant-drop-zone",`is-${e}`,t&&"is-hover",!n&&"is-disabled"].filter(Boolean).join(" "),children:[y.jsxs("div",{className:"variant-drop-zone-inner",children:[y.jsx("div",{className:`variant-drop-zone-icon is-${e}`}),y.jsx("div",{className:"variant-drop-zone-caption",children:n?`Add ${e} split`:"Split unavailable for this direction"})]}),y.jsx("div",{className:"variant-drop-zone-preview","aria-hidden":"true",children:y.jsx("div",{className:"variant-drop-zone-preview-label",children:r})}),y.jsx("div",{className:"variant-drop-zone-border"})]})}const iH=(e,t,n)=>{var s,o;if(!e.active||e.sessionId!==t)return null;const r=e.variants.find(a=>a.workItemId===n);if(((s=r==null?void 0:r.preview)==null?void 0:s.kind)!=="static_artifact")return null;if(((o=r.refinement)==null?void 0:o.status)!=="succeeded")return r.preview.url;const i=r.preview.url.includes("?")?"&":"?";return`${r.preview.url}${i}refinement=${encodeURIComponent(r.refinement.workItemId)}`},S9=(e,t)=>{if(!e)return;const n=iH(t,e.sessionId,e.variantId);return!n||n===e.url?e:{...e,url:n}},a4e=({isLoading:e=!1,isInteractionDisabled:t=!1,activeDemoSessionId:n=null,holdHostedTryoutPreviewNavigation:r=!1})=>{const{config:i,fetchConfig:s,isLoading:o,error:a}=q2e(),[c,u]=h.useState(!1),f=h.useRef(!1);o&&(f.current=!0);const m=!o&&!a&&!!i&&f.current;return h.useEffect(()=>{s().catch(g=>{vt==null||vt.capture("preview_config_load_failed",{message:g instanceof Error?g.message:"unknown_error"})})},[s]),o||m&&!c?o&&r?y.jsx("div",{className:"flex h-full min-h-0 w-full flex-1 bg-main","aria-busy":"true"}):y.jsx(rH,{collapsing:m,onCollapsed:()=>u(!0)}):a||!i?y.jsx("div",{className:"flex h-full w-full items-center justify-center bg-main px-6",children:y.jsxs("div",{className:"max-w-md rounded-lg border border-divider bg-main-light p-4 text-center shadow-lg",children:[y.jsx("p",{className:"text-sm font-medium text-content",children:"We couldn't load your app preview."}),y.jsx("p",{className:"mt-2 text-sm text-content-subtle",children:a||"Missing preview configuration from the server."}),y.jsx("p",{className:"mt-2 text-sm text-content-subtle",children:"If this keeps happening, restart your Rivet session and try again."}),y.jsx("button",{type:"button",className:"mt-4 rounded-md border border-divider px-3 py-1.5 text-xs text-content hover:bg-main/80",onClick:()=>{vt==null||vt.capture("preview_config_retry_clicked"),s().catch(g=>{vt==null||vt.capture("preview_config_load_failed",{message:g instanceof Error?g.message:"unknown_error"})})},children:"Retry preview"})]})}):y.jsx(l4e,{isLoading:e,isInteractionDisabled:t,framework:i.framework,userPort:i.userPort,activeDemoSessionId:n,holdHostedTryoutPreviewNavigation:r})};function l4e(e){const t=ke(wc),n=ke(Wh),r=ke(Js),i=Be(j8),s=ke(eo),o=ke(Jg),a=t==null?void 0:t.left,c=t==null?void 0:t.right,u=h.useMemo(()=>{var P,S;if(!s.active||s.projectContext.kind!=="fresh"||!(!!a!=!!c))return;const w=(P=a??c)==null?void 0:P.variantId,E=s.variants.filter(D=>{var R;return D.status==="succeeded"&&((R=D.preview)==null?void 0:R.kind)==="static_artifact"&&D.workItemId!==w}),A=o==null?void 0:o.replace(/[?&]refinement=[^&]*$/,""),M=E.find(D=>{var R;return((R=D.preview)==null?void 0:R.kind)==="static_artifact"&&D.preview.url===A})??E[0];if(((S=M==null?void 0:M.preview)==null?void 0:S.kind)!=="static_artifact")return;const I=iH(s,s.sessionId,M.workItemId);if(I)return{sessionId:s.sessionId,variantId:M.workItemId,label:M.label,url:I}},[s,a,c,o]),f=S9(a,s)??(c?u:void 0),p=S9(c,s)??(a?u:void 0),m=!a&&!!f,g=!c&&!!p,b=!!(f||p),x=y.jsx(Qxe,{isInteractionDisabled:e.isInteractionDisabled,framework:e.framework,userPort:e.userPort,activeDemoSessionId:e.activeDemoSessionId,holdPreviewNavigation:e.holdHostedTryoutPreviewNavigation});return y.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-1 flex-col",children:[y.jsxs("div",{className:`variant-preview-region relative flex h-full min-h-0 w-full flex-1 flex-col ${n?"is-dragging":""} ${b?"is-split":""}`,children:[y.jsxs("div",{className:"variant-preview-row flex h-full min-h-0 w-full flex-1",children:[f&&y.jsx(k9,{side:"left",sessionId:f.sessionId,variantId:f.variantId,url:f.url,label:f.label,isFallback:m},`left-${f.sessionId}:${f.variantId}:${f.url}`),!(f&&p)&&y.jsx("div",{className:"variant-preview-primary flex h-full min-h-0 flex-1 flex-col",children:x}),p&&y.jsx(k9,{side:"right",sessionId:p.sessionId,variantId:p.variantId,url:p.url,label:p.label,isFallback:g},`right-${p.sessionId}:${p.variantId}:${p.url}`)]}),y.jsx("div",{className:"variant-preview-atmosphere","aria-hidden":"true"}),y.jsx(o4e,{}),y.jsx(s4e,{})]}),e.isInteractionDisabled?null:y.jsx(X2e,{mode:r,onModeChange:i,isLoading:e.isLoading})]})}const sH=({message:e,isLoading:t=!0})=>y.jsxs("div",{className:"flex items-center gap-2 text-sm text-content",children:[t?y.jsx(Ua,{className:"h-4 w-4 shrink-0 animate-spin text-primary",weight:"bold"}):null,y.jsx("span",{className:"whitespace-pre-wrap font-sans",children:e})]}),oH="data:image/svg+xml,%3csvg%20width='94'%20height='24'%20viewBox='0%200%2094%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M-0.000156164%2023.832V7.704H5.11184L6.47984%208.424C7.58384%207.704%209.04784%207.344%2010.8718%207.344C12.0718%207.344%2013.1278%207.476%2014.0398%207.74C14.9518%207.98%2015.6838%208.244%2016.2358%208.532C16.8118%208.82%2017.1718%209.024%2017.3158%209.144L15.5158%2013.824C15.2758%2013.656%2014.8198%2013.428%2014.1478%2013.14C13.4998%2012.852%2012.7318%2012.588%2011.8438%2012.348C10.9558%2012.084%2010.0198%2011.952%209.03584%2011.952H8.63984C7.96784%2011.952%207.45184%2012.072%207.09184%2012.312C6.73184%2012.528%206.55184%2013.02%206.55184%2013.788V23.832H-0.000156164ZM23.464%206.156C21.04%206.156%2019.828%205.124%2019.828%203.06C19.828%201.908%2020.128%201.116%2020.728%200.684C21.352%200.227999%2022.264%20-1.43051e-06%2023.464%20-1.43051e-06C24.736%20-1.43051e-06%2025.66%200.227999%2026.236%200.684C26.836%201.116%2027.136%201.908%2027.136%203.06C27.136%205.124%2025.912%206.156%2023.464%206.156ZM20.152%2023.832V7.704H26.704V23.832H20.152ZM37.4767%2023.832L29.6647%207.704H36.9007L40.3207%2016.524L41.2567%2019.116H41.6167L42.5527%2016.524L46.0087%207.704H53.1727L52.5967%209.9L45.4327%2023.832H37.4767ZM61.1953%2023.832C59.6113%2023.832%2058.3873%2023.604%2057.5233%2023.148C56.6833%2022.692%2056.1073%2022.068%2055.7953%2021.276C55.4833%2020.46%2055.3273%2019.524%2055.3273%2018.468V13.032C55.3273%2012.072%2055.4833%2011.196%2055.7953%2010.404C56.1313%209.588%2056.7193%208.94%2057.5593%208.46C58.3993%207.956%2059.6113%207.704%2061.1953%207.704H68.6473C70.5193%207.704%2071.9473%207.932%2072.9313%208.388C73.9393%208.82%2074.6233%209.444%2074.9833%2010.26C75.3673%2011.052%2075.5593%2011.976%2075.5593%2013.032V17.64H69.2593C67.0993%2017.64%2065.4553%2017.592%2064.3273%2017.496C63.2233%2017.4%2062.4433%2017.34%2061.9873%2017.316V17.856C61.9633%2018.816%2062.5393%2019.296%2063.7153%2019.296H64.8313C66.7513%2019.296%2068.5273%2019.26%2070.1593%2019.188C71.7913%2019.092%2073.0033%2019.008%2073.7953%2018.936L75.9553%2022.356C75.9553%2022.596%2075.7513%2022.824%2075.3433%2023.04C74.9353%2023.256%2074.2153%2023.448%2073.1833%2023.616C72.1753%2023.76%2070.7353%2023.832%2068.8633%2023.832H61.1953ZM61.9873%2014.184H68.8993V13.68C68.8993%2013.2%2068.8513%2012.864%2068.7553%2012.672C68.6833%2012.48%2068.4313%2012.36%2067.9993%2012.312C67.5673%2012.264%2066.8353%2012.24%2065.8033%2012.24H63.7153C62.5633%2012.24%2061.9873%2012.72%2061.9873%2013.68V14.184ZM85.8224%2023.832C83.9984%2023.832%2082.7504%2023.448%2082.0784%2022.68C81.4064%2021.912%2081.0704%2020.76%2081.0704%2019.224V12.24H78.1184V7.704H79.6304C80.0384%207.704%2080.3624%207.632%2080.6024%207.488C80.8664%207.32%2081.0344%207.032%2081.1064%206.624L81.7904%202.772H87.6944V7.704H93.7064V12.24H87.6944V17.82C87.6944%2018.42%2087.8384%2018.816%2088.1264%2019.008C88.4144%2019.2%2088.8464%2019.296%2089.4224%2019.296H93.0224L93.7424%2023.472C93.2384%2023.544%2092.4704%2023.628%2091.4384%2023.724C90.4064%2023.796%2089.2784%2023.832%2088.0544%2023.832H85.8224Z'%20fill='%23FF3300'/%3e%3c/svg%3e",aH=({isSigningIn:e,onStartSignIn:t,errorMessage:n=null,isDesktopShell:r=!1,displayMode:i="full"})=>{const s=i==="modal";return y.jsxs("div",{className:s?"glass-panel relative w-full max-w-sm rounded-2xl border border-white/10 px-8 py-14 font-main text-white shadow-2xl":"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-[#1c1c20] font-main text-white",children:[r&&!s?y.jsx("div",{className:"fixed left-0 right-0 top-0 z-10 h-8",style:{WebkitAppRegion:"drag"}}):null,y.jsxs("div",{className:"flex flex-col items-center gap-10",children:[y.jsx("img",{src:oH,alt:"Rivet",className:"h-8 w-auto object-contain"}),y.jsxs("div",{className:"text-center",children:[y.jsx("h1",{className:"mb-2 text-xl font-medium text-content",children:"Welcome to Rivet"}),y.jsx("p",{className:"text-sm text-content-muted",children:"Sign in to get started"})]}),y.jsx("button",{onClick:t,disabled:e,className:"glass-panel active-push flex items-center gap-3 rounded-xl px-8 py-3.5 text-sm font-medium transition-all hover:bg-white/10 disabled:opacity-50",children:e?y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-primary border-t-transparent"}),y.jsx("span",{children:"Signing in..."})]}):y.jsxs(y.Fragment,{children:[y.jsx("img",{src:"https://www.gstatic.com/firebasejs/ui/2.0.0/images/auth/google.svg",alt:"Google",className:"h-5 w-5 brightness-110"}),y.jsx("span",{children:"Sign in with Google"})]})}),n?y.jsx("p",{className:"text-center text-xs text-red-200",children:n}):null]})]})},c4e=({message:e})=>y.jsx("div",{className:"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-[#1c1c20] font-main text-white",children:y.jsxs("div",{className:"flex flex-col items-center gap-10",children:[y.jsx("img",{src:oH,alt:"Rivet",className:"h-8 w-auto object-contain"}),y.jsxs("div",{className:"glass-panel flex items-center gap-3 rounded-xl px-8 py-3.5 text-sm font-medium",children:[y.jsx(Ua,{className:"h-5 w-5 shrink-0 animate-spin text-primary",weight:"bold"}),y.jsx("span",{children:e})]})]})}),_9=Mt("useConfig"),u4e=()=>{var e;return typeof window>"u"?null:((e=window.__RIVET_BOOTSTRAP__)==null?void 0:e.queueAccessToken)??null},d4e=()=>{var e;return typeof window>"u"?null:((e=window.__RIVET_BOOTSTRAP__)==null?void 0:e.agentApplyMode)??null},f4e=e=>({...f$,...e??{}}),h4e=()=>{const e=ke(Qs),t=Be(Qs),n=Be(wp),r=Be(B8),i=Be(W1),s=Be(z8),o=Be(w$),a=Be(x$),c=Be(p$),u=Jz({queryKey:["rivet-config"],queryFn:async()=>{const g=await fetch("/api/config");if(!g.ok)throw new Error(`Failed to fetch config: ${g.statusText}`);return await g.json()},staleTime:3e4}),{refetch:f}=u;h.useEffect(()=>{const g=u.data;g&&(o(g.agentModeAvailable),c({name:g.name??null,email:g.email??null}),t(f4e(g.featureFlags)),a(!0),g.isMCPSession&&n(!0),g.mcpEditor&&r(g.mcpEditor),i(g.agentApplyMode??d4e()??null),s(g.queueAccessToken??u4e()),_9.info("Config loaded:",g))},[u.data,i,o,t,a,n,r,s,c]),h.useEffect(()=>{u.error&&(a(!0),_9.warn("Failed to load config:",u.error instanceof Error?u.error.message:"Failed to load config"))},[u.error,a]);const p=h.useCallback(async()=>{const g=await f();return g.data?g.data:(a(!0),null)},[f,a]);let m=null;return u.error instanceof Error?m=u.error.message:u.error&&(m="Failed to load config"),{config:u.data??null,featureFlags:e,loading:u.isPending,error:m,refetchConfig:p}},vu=Mt("useOAuthCallback"),p4e="https://rivet-proxy.onrender.com",m4e=()=>{const[e,t]=h.useState({isProcessing:!1,isComplete:!1,error:null});return h.useEffect(()=>{const n=new AbortController;let r=!1;return(async()=>{var a,c,u;const s=window.location.hash,o=window.location.search;if(!(!s||!s.includes("access_token"))&&!r){t({isProcessing:!0,isComplete:!1,error:null});try{vu.info("Processing OAuth callback...");const f=new URLSearchParams(s.substring(1)),p=f.get("access_token"),m=f.get("refresh_token"),b=new URLSearchParams(o).get("session");if(!p)throw new Error("No access token found in URL");if(!b)throw new Error("No session ID found in URL");vu.info(`Completing OAuth with session: ${b}`);const x=await fetch(`${p4e}/api/auth/google/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:b,accessToken:p,refreshToken:m}),signal:n.signal}),C=await x.json();if(!x.ok||!C.success)throw new Error(C.error||C.message||"Failed to complete authentication");if(vu.info("OAuth authentication completed successfully"),r)return;if((a=C.user)!=null&&a.id?(vt.identify(C.user.id,{...C.user.email?{email:C.user.email}:{}}),C.user.email&&vt.alias(C.user.email,C.user.id)):(c=C.user)!=null&&c.email&&vt.identify(C.user.email,{email:C.user.email}),(u=C.user)!=null&&u.email&&p)try{const E=await fetch("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:C.user.email,token:p,refreshToken:m,userId:C.user.id}),signal:n.signal});E.ok||vu.warn(`Local auth store returned ${E.status}`)}catch(E){if(r)return;vu.warn("Failed to store auth locally:",E)}if(r)return;const w=window.location.pathname;window.history.replaceState({},document.title,w),t({isProcessing:!1,isComplete:!0,error:null})}catch(f){if(r)return;const p=f instanceof Error?f.message:"Unknown error occurred";vu.warn("OAuth callback error:",f),t({isProcessing:!1,isComplete:!1,error:p})}}})(),()=>{r=!0,n.abort()}},[]),e},Px=Mt("useAgentVariantsSession"),g4e=()=>{const e=Be(eo),t=Be(hd),n=Be(bp),r=Be(Js),i=Be(b$),s=Be(tee),o=bc(),a=h.useRef(null);h.useEffect(()=>{const c=new EventSource("/api/variants/events");return c.onmessage=u=>{try{const f=JSON.parse(u.data),p=a.current;f.active?(i(!1),f.sessionId!==a.current&&(a.current=f.sessionId,t(!0),n(!0),r("comment"))):(a.current!==null&&t(!1),a.current=null,i(!1)),e(f);const m=!f.active&&p!==null,g=f.active&&f.sessionId!==p;if(g&&fetch(`/api/variants/${f.sessionId}/preview-port`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({variantId:null})}).catch(b=>Px.warn("failed to reset preview-port on session switch",b)),m||g){const b=new Set;if(f.active)for(const C of f.variants)b.add(No({kind:"variant",sessionId:f.sessionId,variantId:C.workItemId}));const x=o.get(wc);for(const C of[x==null?void 0:x.left,x==null?void 0:x.right])C&&b.add(No({kind:"variant",sessionId:C.sessionId,variantId:C.variantId}));s(b)}}catch(f){Px.warn("failed to parse SSE event payload",f)}},c.onerror=u=>{Px.warn("SSE error (auto-reconnects)",u),i(!1)},()=>{c.close()}},[e,t,n,r,i,s,o])},yu=Mt("useTokenEditor"),v4e=()=>{const[e,t]=h.useState(null),[n,r]=h.useState(null),[i,s]=h.useState(new Map),[o,a]=h.useState(!0),[c,u]=h.useState(!1),[f,p]=h.useState(null),m=h.useCallback(async()=>{a(!0),p(null);try{const C=await fetch("/api/tokens");if(!C.ok)throw new Error(`Failed to fetch tokens: ${C.statusText}`);const w=await C.json();t(w.registry),r(w.framework),yu.info(`Loaded ${w.framework} tokens`)}catch(C){const w=C instanceof Error?C.message:"Unknown error";p(w),yu.warn("Failed to fetch tokens:",C)}finally{a(!1)}},[]);h.useEffect(()=>{m()},[m]);const g=h.useCallback((C,w,E,A)=>{const T=`${C}.${w}`;s(M=>{const I=new Map(M);return A===E?I.delete(T):I.set(T,{category:C,path:w,originalValue:E,newValue:A}),I})},[]),b=h.useCallback(async()=>{if(i.size===0)return!0;u(!0),p(null);const C=Array.from(i.values());let w=!0;for(const E of C)try{yu.info(`Saving ${E.category}.${E.path} = "${E.newValue}"`);const T=await(await fetch("/api/tokens/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({category:E.category,path:E.path,value:E.newValue})})).json();if(!T.success)throw new Error(T.error||"Update failed");yu.info(`Successfully saved ${E.category}.${E.path}`)}catch(A){const T=A instanceof Error?A.message:"Unknown error";p(`Failed to update ${E.category}.${E.path}: ${T}`),yu.warn(`Failed to save ${E.category}.${E.path}:`,A),w=!1;break}return w&&(s(new Map),await m()),u(!1),w},[i,m]),x=h.useCallback(()=>{s(new Map),yu.info("Reverted all pending changes")},[]);return{tokens:e,framework:n,pendingChanges:i,isLoading:o,isSaving:c,error:f,updateToken:g,saveChanges:b,revertChanges:x,refetch:m}};var Ix="rovingFocusGroup.onEntryFocus",y4e={bubbles:!1,cancelable:!0},Np="RovingFocusGroup",[I6,lH,b4e]=mv(Np),[x4e,cH]=xs(Np,[b4e]),[w4e,k4e]=x4e(Np),uH=h.forwardRef((e,t)=>y.jsx(I6.Provider,{scope:e.__scopeRovingFocusGroup,children:y.jsx(I6.Slot,{scope:e.__scopeRovingFocusGroup,children:y.jsx(C4e,{...e,ref:t})})}));uH.displayName=Np;var C4e=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:f=!1,...p}=e,m=h.useRef(null),g=Jt(t,m),b=Ip(s),[x,C]=vs({prop:o,defaultProp:a??null,onChange:c,caller:Np}),[w,E]=h.useState(!1),A=Ka(u),T=lH(n),M=h.useRef(!1),[I,P]=h.useState(0);return h.useEffect(()=>{const S=m.current;if(S)return S.addEventListener(Ix,A),()=>S.removeEventListener(Ix,A)},[A]),y.jsx(w4e,{scope:n,orientation:r,dir:b,loop:i,currentTabStopId:x,onItemFocus:h.useCallback(S=>C(S),[C]),onItemShiftTab:h.useCallback(()=>E(!0),[]),onFocusableItemAdd:h.useCallback(()=>P(S=>S+1),[]),onFocusableItemRemove:h.useCallback(()=>P(S=>S-1),[]),children:y.jsx(Et.div,{tabIndex:w||I===0?-1:0,"data-orientation":r,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:ft(e.onMouseDown,()=>{M.current=!0}),onFocus:ft(e.onFocus,S=>{const D=!M.current;if(S.target===S.currentTarget&&D&&!w){const R=new CustomEvent(Ix,y4e);if(S.currentTarget.dispatchEvent(R),!R.defaultPrevented){const L=T().filter(Z=>Z.focusable),j=L.find(Z=>Z.active),O=L.find(Z=>Z.id===x),B=[j,O,...L].filter(Boolean).map(Z=>Z.ref.current);hH(B,f)}}M.current=!1}),onBlur:ft(e.onBlur,()=>E(!1))})})}),dH="RovingFocusGroupItem",fH=h.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=Bi(),u=s||c,f=k4e(dH,n),p=f.currentTabStopId===u,m=lH(n),{onFocusableItemAdd:g,onFocusableItemRemove:b,currentTabStopId:x}=f;return h.useEffect(()=>{if(r)return g(),()=>b()},[r,g,b]),y.jsx(I6.ItemSlot,{scope:n,id:u,focusable:r,active:i,children:y.jsx(Et.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...a,ref:t,onMouseDown:ft(e.onMouseDown,C=>{r?f.onItemFocus(u):C.preventDefault()}),onFocus:ft(e.onFocus,()=>f.onItemFocus(u)),onKeyDown:ft(e.onKeyDown,C=>{if(C.key==="Tab"&&C.shiftKey){f.onItemShiftTab();return}if(C.target!==C.currentTarget)return;const w=_4e(C,f.orientation,f.dir);if(w!==void 0){if(C.metaKey||C.ctrlKey||C.altKey||C.shiftKey)return;C.preventDefault();let A=m().filter(T=>T.focusable).map(T=>T.ref.current);if(w==="last")A.reverse();else if(w==="prev"||w==="next"){w==="prev"&&A.reverse();const T=A.indexOf(C.currentTarget);A=f.loop?A4e(A,T+1):A.slice(T+1)}setTimeout(()=>hH(A))}}),children:typeof o=="function"?o({isCurrentTabStop:p,hasTabStop:x!=null}):o})})});fH.displayName=dH;var E4e={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function S4e(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function _4e(e,t,n){const r=S4e(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return E4e[r]}function hH(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function A4e(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var T4e=uH,P4e=fH,Hv="Tabs",[I4e]=xs(Hv,[cH]),pH=cH(),[M4e,$k]=I4e(Hv),mH=h.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:i,defaultValue:s,orientation:o="horizontal",dir:a,activationMode:c="automatic",...u}=e,f=Ip(a),[p,m]=vs({prop:r,onChange:i,defaultProp:s??"",caller:Hv});return y.jsx(M4e,{scope:n,baseId:Bi(),value:p,onValueChange:m,orientation:o,dir:f,activationMode:c,children:y.jsx(Et.div,{dir:f,"data-orientation":o,...u,ref:t})})});mH.displayName=Hv;var gH="TabsList",vH=h.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...i}=e,s=$k(gH,n),o=pH(n);return y.jsx(T4e,{asChild:!0,...o,orientation:s.orientation,dir:s.dir,loop:r,children:y.jsx(Et.div,{role:"tablist","aria-orientation":s.orientation,...i,ref:t})})});vH.displayName=gH;var yH="TabsTrigger",bH=h.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:i=!1,...s}=e,o=$k(yH,n),a=pH(n),c=kH(o.baseId,r),u=CH(o.baseId,r),f=r===o.value;return y.jsx(P4e,{asChild:!0,...a,focusable:!i,active:f,children:y.jsx(Et.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":u,"data-state":f?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:c,...s,ref:t,onMouseDown:ft(e.onMouseDown,p=>{!i&&p.button===0&&p.ctrlKey===!1?o.onValueChange(r):p.preventDefault()}),onKeyDown:ft(e.onKeyDown,p=>{[" ","Enter"].includes(p.key)&&o.onValueChange(r)}),onFocus:ft(e.onFocus,()=>{const p=o.activationMode!=="manual";!f&&!i&&p&&o.onValueChange(r)})})})});bH.displayName=yH;var xH="TabsContent",wH=h.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:i,children:s,...o}=e,a=$k(xH,n),c=kH(a.baseId,r),u=CH(a.baseId,r),f=r===a.value,p=h.useRef(f);return h.useEffect(()=>{const m=requestAnimationFrame(()=>p.current=!1);return()=>cancelAnimationFrame(m)},[]),y.jsx(ws,{present:i||f,children:({present:m})=>y.jsx(Et.div,{"data-state":f?"active":"inactive","data-orientation":a.orientation,role:"tabpanel","aria-labelledby":c,hidden:!m,id:u,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:p.current?"0s":void 0},children:m&&s})})});wH.displayName=xH;function kH(e,t){return`${e}-trigger-${t}`}function CH(e,t){return`${e}-content-${t}`}var R4e=mH,$4e=vH,D4e=bH,N4e=wH;const L4e=({tokens:e,pendingChanges:t,category:n,onUpdateToken:r,highlightToken:i})=>{const[s,o]=h.useState(null),[a,c]=h.useState(""),u=h.useRef(null);if(h.useEffect(()=>{i&&u.current&&setTimeout(()=>{var x;(x=u.current)==null||x.scrollIntoView({behavior:"smooth",block:"center"})},100)},[i]),!e||Object.keys(e).length===0)return y.jsx("div",{className:"flex items-center justify-center py-12 text-sm text-gray-500",children:"No tokens defined for this category"});const f=(x,C)=>{const w=`${n}.${x}`,E=t.get(w);return E?E.newValue:C},p=x=>{if(x.includes("var(")||x.includes("--"))return{textClass:"text-white",mutedClass:"text-white/70"};let C=0,w=0,E=0,A=!1;if(x.startsWith("#")){const P=x.slice(1);P.length===3?(C=parseInt(P[0]+P[0],16),w=parseInt(P[1]+P[1],16),E=parseInt(P[2]+P[2],16),A=!0):P.length>=6&&(C=parseInt(P.slice(0,2),16),w=parseInt(P.slice(2,4),16),E=parseInt(P.slice(4,6),16),A=!0)}const T=x.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);if(T&&(C=parseInt(T[1],10),w=parseInt(T[2],10),E=parseInt(T[3],10),A=!0),!A){const P=x.match(/rgba?\(\s*(\d+)\s+(\d+)\s+(\d+)/);P&&(C=parseInt(P[1],10),w=parseInt(P[2],10),E=parseInt(P[3],10),A=!0)}if(!A){const P=x.match(/hsla?\(\s*(\d+)\s*,\s*(\d+)%?\s*,\s*(\d+)%?/);if(P){const S=_A(parseInt(P[1],10),parseInt(P[2],10),parseInt(P[3],10));C=S.r,w=S.g,E=S.b,A=!0}}if(!A){const P=x.match(/hsla?\(\s*(\d+)\s+(\d+)%?\s+(\d+)%?/);if(P){const S=_A(parseInt(P[1],10),parseInt(P[2],10),parseInt(P[3],10));C=S.r,w=S.g,E=S.b,A=!0}}if(!A){const P=x.match(/oklch\(\s*([\d.]+)(%?)/);if(P){const S=parseFloat(P[1]),R=(P[2]==="%"?S/100:S)>.5;return{textClass:R?"text-gray-900":"text-white",mutedClass:R?"text-gray-600":"text-white/70"}}}if(!A)return{textClass:"text-white",mutedClass:"text-white/70"};const I=sie(C,w,E)>.5;return{textClass:I?"text-gray-900":"text-white",mutedClass:I?"text-gray-600":"text-white/70"}},m=(x,C,w,E)=>{const A=f(C,w),T=s===C,M=T&&a?a:A,I=C.replace(/\./g,"-"),P=i===I||i===x,S=M.includes("rgba")||M.startsWith("#")&&M.length===9||/oklch\(/.test(M)&&M.includes("/"),{textClass:D}=p(M),R=H=>{c(H)},L=H=>{r(n,C,w,H),o(null),c("")},j=H=>{H?(o(C),c(A)):(a&&a!==A&&r(n,C,w,a),o(null),c(""))},O=E?"h-44":"h-52";return y.jsxs(Fo,{open:T,onOpenChange:j,children:[y.jsx(al,{asChild:!0,children:y.jsxs("div",{ref:P?u:null,className:`group relative flex ${O} cursor-pointer flex-col justify-between overflow-hidden rounded-lg border border-white/10 p-4 transition-all ${P?"animate-token-highlight":""}`,children:[y.jsxs("div",{className:"absolute inset-0",children:[S&&y.jsx("div",{className:"absolute inset-0",style:{backgroundImage:`
612
612
  linear-gradient(45deg, #e5e5e5 25%, transparent 25%),
613
613
  linear-gradient(-45deg, #e5e5e5 25%, transparent 25%),
614
614
  linear-gradient(45deg, transparent 75%, #e5e5e5 75%),
@@ -642,4 +642,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
642
642
  <body>
643
643
  <div class="panel">${I9}</div>
644
644
  </body>
645
- </html>`,mwe="Too many people are trying Rivet right now. Please try again in a few minutes.",TH="Failed to start an isolated demo session.",gwe=async e=>{if(e.status===429)return mwe;try{const t=await e.json();if(t.error)return t.error;if(t.message)return t.message}catch{}return TH},vwe=({projectPath:e,activeDemoSessionId:t=null,showLoginGate:n=!1,onStartLogin:r,isStartingLogin:i=!1,loginError:s=null,fullPageHostedLoginProgressMessage:o=null,holdHostedTryoutPreviewNavigation:a=!1,hostedTryoutPreviewHoldMessage:c=null,deferInspectorUntilPreviewReady:u=!1})=>{const[f,p]=Vn(Ui),m=Be(Td),g=Be(O8),b=Be(j8),[x,C]=Vn(qJ),w=ke(Js),E=ke(h$)>0,[A,T]=Vn(bp),[M,I]=Vn(hd),P=ke(eo),[S,D]=Vn(ji),R=ke(uc),L=Be(C$),j=Be(Qg),O=Be(V8),H=Be(uc),B=m4e();g4e();const Z=B.isProcessing?"Completing authentication...":o,K=Z!==null,q=h.useRef((f==null?void 0:f.xpath)??null),Q=h.useRef(!1),F=h.useRef(!1),V=Be(Z1),W=q4e();h.useEffect(()=>{V(e??null)},[e,V]),h.useEffect(()=>{if(!e||Q.current)return;Q.current=!0;const re=Y4e(e);re.size>0&&(F.current=!0,D(re));const G=G4e(e);G&&W(G)},[e,D,W]),h.useEffect(()=>{if(!(!e||!Q.current)){if(F.current){F.current=!1;return}K4e(S,e)}},[S,e]),h.useEffect(()=>{(async()=>{try{const G=await fetch("/api/tokens");if(G.ok){const X=await G.json();m(X),X.framework&&br.info(`Loaded ${X.framework} design tokens`)}}catch(G){br.error("Failed to fetch design tokens:",G)}})()},[m]);const N=()=>{w==="edit"||R||(j(null),O(null),H(!1),Mx())},z=h.useCallback(()=>{I(!1),T(!1),b("view"),Mx(),p(null),g(null)},[b,g,T,I,p]);h.useEffect(()=>{n&&(b("view"),Mx(),p(null),g(null),document.body.style.cursor="auto")},[n,b,g,p]);const ee=h.useMemo(()=>[{key:"Escape",allowInTextField:!0,handler:re=>{const G=re.target,X=G.tagName.toLowerCase();if(!((X==="input"||X==="textarea"||X==="select"||G.getAttribute("contenteditable")==="true")&&w!=="comment")){if(G.closest("[data-radix-popper-content-wrapper]")){br.debug("Escape key pressed inside popover - letting Radix handle it");return}if(R){br.debug("Escape key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}if(M){br.debug("Escape key pressed in variants mode - hiding panel"),I(!1),T(!1);return}br.debug("Escape key pressed - switching to view mode"),z()}},description:"Close inspector"},{key:"x",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("X key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}br.debug("X key pressed - collapsing editor chrome"),z()},description:"Collapse editor chrome"},{key:"n",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("N key pressed with dirty draft comment - blocking mode switch"),L(re=>re+1);return}br.debug("N key pressed - switching to navigate mode"),z()},description:"Switch to navigate mode"},{key:"c",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("C key pressed - switching to comment mode"),b("comment")},description:"Switch to comment mode"},{key:"r",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("R key pressed - switching to refine mode"),I(!1),T(!0),b("edit")},description:"Switch to refine mode"},{key:"e",metaKey:!1,ctrlKey:!1,handler:()=>{M||(br.debug("E key pressed - opening variants panel"),I(!0),T(!0),b("comment"),vt.capture("variants_panel.opened",{source:"keyboard_shortcut",hasActiveSession:P.active}))},description:"Open explore panel"},{key:"p",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("P key pressed - toggling panel"),A?T(!1):(T(!0),w==="view"&&!M&&b("comment"))},description:"Toggle panel"}],[w,R,b,L,j,O,H,M,I,A,T,z,P]);X8({shortcuts:ee}),h.useEffect(()=>{const re=()=>{VD("window_resize")};return window.addEventListener("resize",re),()=>window.removeEventListener("resize",re)},[]),h.useEffect(()=>{const re=(f==null?void 0:f.xpath)??null,G=q.current;re&&re!==G&&(q.current=re)},[f==null?void 0:f.xpath]);const te=Array.from(S.values()).some(re=>re.status==="pending");return h.useEffect(()=>{const re=dwe(w,M,te);re!==null&&T(re)},[w,T,M,te]),y.jsxs(mn.div,{className:"relative flex h-screen overflow-hidden",initial:!1,animate:{opacity:1},transition:{duration:.5,ease:"easeOut"},"data-cy":"rivet-app",children:[Z!==null?y.jsx("div",{className:"absolute inset-0 z-50",children:y.jsx(c4e,{message:Z})}):null,n&&!K?y.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/45 backdrop-blur-[2px]",children:y.jsx(aH,{isSigningIn:i,onStartSignIn:()=>{r==null||r()},errorMessage:s,displayMode:"modal"})}):null,y.jsxs("div",{className:`relative flex min-w-0 flex-1 flex-col ${n?"pointer-events-none select-none":""}`,children:[y.jsx(a4e,{holdHostedTryoutPreviewNavigation:a,isInteractionDisabled:n,activeDemoSessionId:t}),a&&c?y.jsx("div",{className:"bg-main absolute inset-0 z-30 flex items-center justify-center",children:y.jsx("div",{className:"border-divider bg-main-light rounded-lg border p-6 shadow-lg",children:y.jsx(sH,{message:c})})}):null]}),n?null:y.jsx(y.Fragment,{children:!u&&!E?y.jsxs(y.Fragment,{children:[y.jsx(mn.div,{className:"h-full flex-shrink-0",initial:!1,animate:{width:A?"auto":0,opacity:A?1:0},transition:{ease:[.19,1,.22,1],duration:.45},style:{overflow:"hidden",willChange:"width"},onClickCapture:N,children:y.jsx(Z2e,{chatMessages:x,setChatMessages:C,onClose:()=>T(!1)})}),y.jsx(us,{children:!A&&y.jsx(Fi,{label:"Open chat",side:"left",children:y.jsx(mn.button,{initial:{opacity:0,x:8},animate:{opacity:1,x:0},exit:{opacity:0,x:8},transition:{duration:.15},onClick:()=>T(!0),className:"border-primary/30 bg-main text-content absolute top-4 right-0 z-50 rounded-l-lg border border-r-0 p-2 shadow-lg transition-colors","data-cy":"reopen-panel",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})})]}):null}),y.jsx(i$,{duration:5e3,richColors:!0,toastOptions:{style:{maxHeight:"150px",overflow:"hidden"}}})]})},ywe=()=>{const[e,t]=h.useState(window.location.hash),[n,r]=h.useState(0),{config:i,refetchConfig:s,loading:o,error:a}=h4e(),c=Be(uc),[u,f]=h.useState(!1),[p,m]=h.useState(null),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(null),[A,T]=h.useState(!1),M=h.useRef(!1),I=h.useRef(!1),P=cwe(window.location.pathname),S=(i==null?void 0:i.activeDemoSessionId)??null,D=P??w??S,R=h.useMemo(()=>swe(i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D),[i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D]),L=h.useMemo(()=>iwe({configLoading:o,hasConfig:i!==null,demoMode:i==null?void 0:i.demoMode,agentModeAvailable:i==null?void 0:i.agentModeAvailable,pathnameDemoSessionId:P,activeDemoSessionId:w,configuredDemoSessionId:S}),[i,o,P,w,S]);h.useLayoutEffect(()=>{if(!L){T(!1);return}T(!0)},[L]);const j=A,O=h.useMemo(()=>owe(j),[j]),H=(i==null?void 0:i.demoMode)===!0&&j,B=h.useRef(null);B.current=D;const Z=h.useCallback(async()=>{if(!M.current)return;E(null);const te=await s();if((te==null?void 0:te.demoMode)===!0&&te.agentModeAvailable!==!0){C(!1);return}(te==null?void 0:te.demoMode)===!0&&C(!0)},[s]);h.useEffect(()=>{if((i==null?void 0:i.demoMode)===!0)return ewe(()=>{Z()})},[i==null?void 0:i.demoMode,Z]),h.useEffect(()=>{if(M.current=(i==null?void 0:i.demoMode)===!0,(i==null?void 0:i.demoMode)!==!0)return;const te=window.fetch.bind(window);return rwe({nativeFetch:te,pageOrigin:window.location.origin,getShouldIntercept:()=>M.current})},[i==null?void 0:i.demoMode]),h.useEffect(()=>{(i==null?void 0:i.agentModeAvailable)===!0&&C(!1)},[i==null?void 0:i.agentModeAvailable]);const K=h.useCallback(async te=>{const re=B.current;if(!(te!=null&&te.forceRefresh)&&re)return re;if(I.current)return"";I.current=!0;try{const G=await fetch("/api/demo/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(!G.ok){const de=await gwe(G);throw new Error(de)}const X=await G.json();if(!X.sessionId)throw new Error("Demo session response missing session id.");return E(X.sessionId),X.sessionId}finally{I.current=!1}},[]);h.useEffect(()=>{S&&E(S)},[S]),h.useEffect(()=>{i!=null&&i.userId?(vt.identify(i.userId,{...i.email?{email:i.email}:{}}),i.email&&vt.alias(i.email,i.userId)):i!=null&&i.email&&vt.identify(i.email,{email:i.email})},[i==null?void 0:i.userId,i==null?void 0:i.email]),h.useEffect(()=>{if(!i)return;const te=!!i.demoMode,re=te?D:null;vt.register({source:te?"tryout":"core",demo_mode:te,...re?{demo_session_id:re}:{}})},[i,D]);const q=h.useCallback(async()=>{var re;f(!0),m(null);let te=null;try{if(te=window.open("","_blank"),!te)throw new Error("Pop-up blocked. Please allow pop-ups and try again.");try{te.document.open(),te.document.write(pwe),te.document.close()}catch(de){br.warn("Failed to render loading state in auth popup:",de)}const G=await fetch(`${M9}/api/auth/google/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"desktop"})}),X=await G.json();if(!G.ok||!X.success||!X.authUrl||!X.sessionId||!X.pollSecret)throw new Error(X.error||X.message||"Failed to start Google login");if(te.closed)throw new Error("Sign-in window was closed before Google login started.");te.location.href=X.authUrl;for(let de=0;de<hwe;de+=1){if(te.closed)throw new Error("Sign-in window was closed before authentication completed.");const we=await(await fetch(`${M9}/api/auth/google/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:X.sessionId,pollSecret:X.pollSecret})})).json();if(we.success&&we.token&&((re=we.user)!=null&&re.email)){if(!(await fetch("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:we.user.email,token:we.token,refreshToken:we.refreshToken,userId:we.user.id})})).ok)throw new Error("Signed in, but failed to store session locally.");if(te.close(),(i==null?void 0:i.demoMode)===!0){await K({forceRefresh:!0}),window.location.reload();return}window.location.reload();return}if(we.error&&we.error!=="Pending")throw new Error(we.error||"Google login failed");await new Promise(Fe=>setTimeout(Fe,fwe))}throw new Error("Authentication timed out. Please try again.")}catch(G){te&&!te.closed&&te.close();const X=G instanceof Error?G.message:"Failed to start login flow";br.warn("Hosted login failed:",X),m(X),f(!1)}},[i==null?void 0:i.demoMode,K]),Q=(i==null?void 0:i.demoMode)===!0&&((i==null?void 0:i.agentModeAvailable)!==!0||x||u),F=i!=null&&i.demoMode!==!0&&i.agentModeAvailable!==!0,V=M6(e),W=h.useCallback(async()=>{b(!0);try{await s()}finally{b(!1)}},[s]);if(h.useEffect(()=>{if(!L)return;let te=!1;return K({forceRefresh:!0}).catch(re=>{const G=re instanceof Error?re.message:TH;br.warn("Hosted session bootstrap failed:",G),m(G),ct.error(G)}).finally(()=>{te||T(!1)}),()=>{te=!0}},[L,K]),h.useEffect(()=>{const te=()=>{const re=window.location.hash;c(!1),t(G=>(uwe(G,re)&&r(X=>X+1),re))};return window.addEventListener("hashchange",te),()=>window.removeEventListener("hashchange",te)},[c]),V==="tokens")return y.jsx(O4e,{});if(V==="design-system")return y.jsx(Z4e,{});const N={pathname:window.location.pathname,configLoading:o,hasConfig:i!==null,isRetryingConfig:g},z=awe(N),ee=lwe(N);if(z)return y.jsx("div",{className:"h-screen w-full",children:y.jsx(rH,{})});if(ee){const te=a||"Could not load Rivet configuration.";return y.jsx("div",{className:"bg-main flex h-screen items-center justify-center px-6",children:y.jsxs("div",{className:"border-divider bg-main w-full max-w-md rounded-lg border p-6 text-center shadow-lg",children:[y.jsx("p",{className:"text-content text-sm font-medium",children:"We could not start Rivet yet."}),y.jsx("p",{className:"text-content-dim mt-2 text-xs",children:te}),y.jsx("button",{type:"button",className:"border-divider text-content hover:bg-main/80 mt-4 rounded-md border px-3 py-1.5 text-xs",onClick:()=>{W()},children:"Retry"})]})})}return F?y.jsx(aH,{isSigningIn:u,onStartSignIn:()=>{q()},errorMessage:p,displayMode:"full"}):y.jsx(vwe,{projectPath:i==null?void 0:i.projectPath,activeDemoSessionId:R,showLoginGate:Q,onStartLogin:q,isStartingLogin:u,loginError:p,fullPageHostedLoginProgressMessage:(i==null?void 0:i.demoMode)===!0&&u?"Completing sign-in...":null,holdHostedTryoutPreviewNavigation:j,hostedTryoutPreviewHoldMessage:O,deferInspectorUntilPreviewReady:H},n)},bwe="phc_Ntj9tXHbS64XgYxlTfhglRmFivFsfm0AERph4ZlnNH",xwe=new Oz,wwe=()=>y.jsx("div",{style:{display:"flex",height:"100vh",alignItems:"center",justifyContent:"center"},children:y.jsx("p",{style:{fontSize:"14px",color:"#6b7280"},children:"Something went wrong. Please reload the page."})});kW.createRoot(document.getElementById("root")).render(y.jsx(xe.StrictMode,{children:y.jsx(fW,{apiKey:bwe,options:{api_host:"https://us.i.posthog.com",ui_host:"https://us.posthog.com",person_profiles:"always",capture_exceptions:!0,autocapture:!0,capture_pageview:!0,capture_performance:!0,persistence:"localStorage",session_recording:{maskAllInputs:!1,maskInputOptions:{password:!0},maskTextSelector:null},mask_all_text:!1,mask_all_element_attributes:!1,loaded:e=>{e.register({source:"core",rivet_version:"0.10.9",env:"production"})}},children:y.jsx(gW,{fallback:y.jsx(wwe,{}),children:y.jsx(Hz,{client:xwe,children:y.jsx(f1e,{defaultShape:"rounded",children:y.jsx(u1e,{defaultLibrary:"lucide",children:y.jsx(ywe,{})})})})})})}));
645
+ </html>`,mwe="Too many people are trying Rivet right now. Please try again in a few minutes.",TH="Failed to start an isolated demo session.",gwe=async e=>{if(e.status===429)return mwe;try{const t=await e.json();if(t.error)return t.error;if(t.message)return t.message}catch{}return TH},vwe=({projectPath:e,activeDemoSessionId:t=null,showLoginGate:n=!1,onStartLogin:r,isStartingLogin:i=!1,loginError:s=null,fullPageHostedLoginProgressMessage:o=null,holdHostedTryoutPreviewNavigation:a=!1,hostedTryoutPreviewHoldMessage:c=null,deferInspectorUntilPreviewReady:u=!1})=>{const[f,p]=Vn(Ui),m=Be(Td),g=Be(O8),b=Be(j8),[x,C]=Vn(qJ),w=ke(Js),E=ke(h$)>0,[A,T]=Vn(bp),[M,I]=Vn(hd),P=ke(eo),[S,D]=Vn(ji),R=ke(uc),L=Be(C$),j=Be(Qg),O=Be(V8),H=Be(uc),B=m4e();g4e();const Z=B.isProcessing?"Completing authentication...":o,K=Z!==null,q=h.useRef((f==null?void 0:f.xpath)??null),Q=h.useRef(!1),F=h.useRef(!1),V=Be(Z1),W=q4e();h.useEffect(()=>{V(e??null)},[e,V]),h.useEffect(()=>{if(!e||Q.current)return;Q.current=!0;const re=Y4e(e);re.size>0&&(F.current=!0,D(re));const G=G4e(e);G&&W(G)},[e,D,W]),h.useEffect(()=>{if(!(!e||!Q.current)){if(F.current){F.current=!1;return}K4e(S,e)}},[S,e]),h.useEffect(()=>{(async()=>{try{const G=await fetch("/api/tokens");if(G.ok){const X=await G.json();m(X),X.framework&&br.info(`Loaded ${X.framework} design tokens`)}}catch(G){br.error("Failed to fetch design tokens:",G)}})()},[m]);const N=()=>{w==="edit"||R||(j(null),O(null),H(!1),Mx())},z=h.useCallback(()=>{I(!1),T(!1),b("view"),Mx(),p(null),g(null)},[b,g,T,I,p]);h.useEffect(()=>{n&&(b("view"),Mx(),p(null),g(null),document.body.style.cursor="auto")},[n,b,g,p]);const ee=h.useMemo(()=>[{key:"Escape",allowInTextField:!0,handler:re=>{const G=re.target,X=G.tagName.toLowerCase();if(!((X==="input"||X==="textarea"||X==="select"||G.getAttribute("contenteditable")==="true")&&w!=="comment")){if(G.closest("[data-radix-popper-content-wrapper]")){br.debug("Escape key pressed inside popover - letting Radix handle it");return}if(R){br.debug("Escape key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}if(M){br.debug("Escape key pressed in variants mode - hiding panel"),I(!1),T(!1);return}br.debug("Escape key pressed - switching to view mode"),z()}},description:"Close inspector"},{key:"x",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("X key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}br.debug("X key pressed - collapsing editor chrome"),z()},description:"Collapse editor chrome"},{key:"n",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("N key pressed with dirty draft comment - blocking mode switch"),L(re=>re+1);return}br.debug("N key pressed - switching to navigate mode"),z()},description:"Switch to navigate mode"},{key:"c",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("C key pressed - switching to comment mode"),b("comment")},description:"Switch to comment mode"},{key:"r",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("R key pressed - switching to refine mode"),I(!1),T(!0),b("edit")},description:"Switch to refine mode"},{key:"e",metaKey:!1,ctrlKey:!1,handler:()=>{M||(br.debug("E key pressed - opening variants panel"),I(!0),T(!0),b("comment"),vt.capture("variants_panel.opened",{source:"keyboard_shortcut",hasActiveSession:P.active}))},description:"Open explore panel"},{key:"p",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("P key pressed - toggling panel"),A?T(!1):(T(!0),w==="view"&&!M&&b("comment"))},description:"Toggle panel"}],[w,R,b,L,j,O,H,M,I,A,T,z,P]);X8({shortcuts:ee}),h.useEffect(()=>{const re=()=>{VD("window_resize")};return window.addEventListener("resize",re),()=>window.removeEventListener("resize",re)},[]),h.useEffect(()=>{const re=(f==null?void 0:f.xpath)??null,G=q.current;re&&re!==G&&(q.current=re)},[f==null?void 0:f.xpath]);const te=Array.from(S.values()).some(re=>re.status==="pending");return h.useEffect(()=>{const re=dwe(w,M,te);re!==null&&T(re)},[w,T,M,te]),y.jsxs(mn.div,{className:"relative flex h-screen overflow-hidden",initial:!1,animate:{opacity:1},transition:{duration:.5,ease:"easeOut"},"data-cy":"rivet-app",children:[Z!==null?y.jsx("div",{className:"absolute inset-0 z-50",children:y.jsx(c4e,{message:Z})}):null,n&&!K?y.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/45 backdrop-blur-[2px]",children:y.jsx(aH,{isSigningIn:i,onStartSignIn:()=>{r==null||r()},errorMessage:s,displayMode:"modal"})}):null,y.jsxs("div",{className:`relative flex min-w-0 flex-1 flex-col ${n?"pointer-events-none select-none":""}`,children:[y.jsx(a4e,{holdHostedTryoutPreviewNavigation:a,isInteractionDisabled:n,activeDemoSessionId:t}),a&&c?y.jsx("div",{className:"bg-main absolute inset-0 z-30 flex items-center justify-center",children:y.jsx("div",{className:"border-divider bg-main-light rounded-lg border p-6 shadow-lg",children:y.jsx(sH,{message:c})})}):null]}),n?null:y.jsx(y.Fragment,{children:!u&&!E?y.jsxs(y.Fragment,{children:[y.jsx(mn.div,{className:"h-full flex-shrink-0",initial:!1,animate:{width:A?"auto":0,opacity:A?1:0},transition:{ease:[.19,1,.22,1],duration:.45},style:{overflow:"hidden",willChange:"width"},onClickCapture:N,children:y.jsx(Z2e,{chatMessages:x,setChatMessages:C,onClose:()=>T(!1)})}),y.jsx(us,{children:!A&&y.jsx(Fi,{label:"Open chat",side:"left",children:y.jsx(mn.button,{initial:{opacity:0,x:8},animate:{opacity:1,x:0},exit:{opacity:0,x:8},transition:{duration:.15},onClick:()=>T(!0),className:"border-primary/30 bg-main text-content absolute top-4 right-0 z-50 rounded-l-lg border border-r-0 p-2 shadow-lg transition-colors","data-cy":"reopen-panel",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})})]}):null}),y.jsx(i$,{duration:5e3,richColors:!0,toastOptions:{style:{maxHeight:"150px",overflow:"hidden"}}})]})},ywe=()=>{const[e,t]=h.useState(window.location.hash),[n,r]=h.useState(0),{config:i,refetchConfig:s,loading:o,error:a}=h4e(),c=Be(uc),[u,f]=h.useState(!1),[p,m]=h.useState(null),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(null),[A,T]=h.useState(!1),M=h.useRef(!1),I=h.useRef(!1),P=cwe(window.location.pathname),S=(i==null?void 0:i.activeDemoSessionId)??null,D=P??w??S,R=h.useMemo(()=>swe(i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D),[i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D]),L=h.useMemo(()=>iwe({configLoading:o,hasConfig:i!==null,demoMode:i==null?void 0:i.demoMode,agentModeAvailable:i==null?void 0:i.agentModeAvailable,pathnameDemoSessionId:P,activeDemoSessionId:w,configuredDemoSessionId:S}),[i,o,P,w,S]);h.useLayoutEffect(()=>{if(!L){T(!1);return}T(!0)},[L]);const j=A,O=h.useMemo(()=>owe(j),[j]),H=(i==null?void 0:i.demoMode)===!0&&j,B=h.useRef(null);B.current=D;const Z=h.useCallback(async()=>{if(!M.current)return;E(null);const te=await s();if((te==null?void 0:te.demoMode)===!0&&te.agentModeAvailable!==!0){C(!1);return}(te==null?void 0:te.demoMode)===!0&&C(!0)},[s]);h.useEffect(()=>{if((i==null?void 0:i.demoMode)===!0)return ewe(()=>{Z()})},[i==null?void 0:i.demoMode,Z]),h.useEffect(()=>{if(M.current=(i==null?void 0:i.demoMode)===!0,(i==null?void 0:i.demoMode)!==!0)return;const te=window.fetch.bind(window);return rwe({nativeFetch:te,pageOrigin:window.location.origin,getShouldIntercept:()=>M.current})},[i==null?void 0:i.demoMode]),h.useEffect(()=>{(i==null?void 0:i.agentModeAvailable)===!0&&C(!1)},[i==null?void 0:i.agentModeAvailable]);const K=h.useCallback(async te=>{const re=B.current;if(!(te!=null&&te.forceRefresh)&&re)return re;if(I.current)return"";I.current=!0;try{const G=await fetch("/api/demo/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(!G.ok){const de=await gwe(G);throw new Error(de)}const X=await G.json();if(!X.sessionId)throw new Error("Demo session response missing session id.");return E(X.sessionId),X.sessionId}finally{I.current=!1}},[]);h.useEffect(()=>{S&&E(S)},[S]),h.useEffect(()=>{i!=null&&i.userId?(vt.identify(i.userId,{...i.email?{email:i.email}:{}}),i.email&&vt.alias(i.email,i.userId)):i!=null&&i.email&&vt.identify(i.email,{email:i.email})},[i==null?void 0:i.userId,i==null?void 0:i.email]),h.useEffect(()=>{if(!i)return;const te=!!i.demoMode,re=te?D:null;vt.register({source:te?"tryout":"core",demo_mode:te,...re?{demo_session_id:re}:{}})},[i,D]);const q=h.useCallback(async()=>{var re;f(!0),m(null);let te=null;try{if(te=window.open("","_blank"),!te)throw new Error("Pop-up blocked. Please allow pop-ups and try again.");try{te.document.open(),te.document.write(pwe),te.document.close()}catch(de){br.warn("Failed to render loading state in auth popup:",de)}const G=await fetch(`${M9}/api/auth/google/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"desktop"})}),X=await G.json();if(!G.ok||!X.success||!X.authUrl||!X.sessionId||!X.pollSecret)throw new Error(X.error||X.message||"Failed to start Google login");if(te.closed)throw new Error("Sign-in window was closed before Google login started.");te.location.href=X.authUrl;for(let de=0;de<hwe;de+=1){if(te.closed)throw new Error("Sign-in window was closed before authentication completed.");const we=await(await fetch(`${M9}/api/auth/google/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:X.sessionId,pollSecret:X.pollSecret})})).json();if(we.success&&we.token&&((re=we.user)!=null&&re.email)){if(!(await fetch("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:we.user.email,token:we.token,refreshToken:we.refreshToken,userId:we.user.id})})).ok)throw new Error("Signed in, but failed to store session locally.");if(te.close(),(i==null?void 0:i.demoMode)===!0){await K({forceRefresh:!0}),window.location.reload();return}window.location.reload();return}if(we.error&&we.error!=="Pending")throw new Error(we.error||"Google login failed");await new Promise(Fe=>setTimeout(Fe,fwe))}throw new Error("Authentication timed out. Please try again.")}catch(G){te&&!te.closed&&te.close();const X=G instanceof Error?G.message:"Failed to start login flow";br.warn("Hosted login failed:",X),m(X),f(!1)}},[i==null?void 0:i.demoMode,K]),Q=(i==null?void 0:i.demoMode)===!0&&((i==null?void 0:i.agentModeAvailable)!==!0||x||u),F=i!=null&&i.demoMode!==!0&&i.agentModeAvailable!==!0,V=M6(e),W=h.useCallback(async()=>{b(!0);try{await s()}finally{b(!1)}},[s]);if(h.useEffect(()=>{if(!L)return;let te=!1;return K({forceRefresh:!0}).catch(re=>{const G=re instanceof Error?re.message:TH;br.warn("Hosted session bootstrap failed:",G),m(G),ct.error(G)}).finally(()=>{te||T(!1)}),()=>{te=!0}},[L,K]),h.useEffect(()=>{const te=()=>{const re=window.location.hash;c(!1),t(G=>(uwe(G,re)&&r(X=>X+1),re))};return window.addEventListener("hashchange",te),()=>window.removeEventListener("hashchange",te)},[c]),V==="tokens")return y.jsx(O4e,{});if(V==="design-system")return y.jsx(Z4e,{});const N={pathname:window.location.pathname,configLoading:o,hasConfig:i!==null,isRetryingConfig:g},z=awe(N),ee=lwe(N);if(z)return y.jsx("div",{className:"h-screen w-full",children:y.jsx(rH,{})});if(ee){const te=a||"Could not load Rivet configuration.";return y.jsx("div",{className:"bg-main flex h-screen items-center justify-center px-6",children:y.jsxs("div",{className:"border-divider bg-main w-full max-w-md rounded-lg border p-6 text-center shadow-lg",children:[y.jsx("p",{className:"text-content text-sm font-medium",children:"We could not start Rivet yet."}),y.jsx("p",{className:"text-content-dim mt-2 text-xs",children:te}),y.jsx("button",{type:"button",className:"border-divider text-content hover:bg-main/80 mt-4 rounded-md border px-3 py-1.5 text-xs",onClick:()=>{W()},children:"Retry"})]})})}return F?y.jsx(aH,{isSigningIn:u,onStartSignIn:()=>{q()},errorMessage:p,displayMode:"full"}):y.jsx(vwe,{projectPath:i==null?void 0:i.projectPath,activeDemoSessionId:R,showLoginGate:Q,onStartLogin:q,isStartingLogin:u,loginError:p,fullPageHostedLoginProgressMessage:(i==null?void 0:i.demoMode)===!0&&u?"Completing sign-in...":null,holdHostedTryoutPreviewNavigation:j,hostedTryoutPreviewHoldMessage:O,deferInspectorUntilPreviewReady:H},n)},bwe="phc_Ntj9tXHbS64XgYxlTfhglRmFivFsfm0AERph4ZlnNH",xwe=new Oz,wwe=()=>y.jsx("div",{style:{display:"flex",height:"100vh",alignItems:"center",justifyContent:"center"},children:y.jsx("p",{style:{fontSize:"14px",color:"#6b7280"},children:"Something went wrong. Please reload the page."})});kW.createRoot(document.getElementById("root")).render(y.jsx(xe.StrictMode,{children:y.jsx(fW,{apiKey:bwe,options:{api_host:"https://us.i.posthog.com",ui_host:"https://us.posthog.com",person_profiles:"always",capture_exceptions:!0,autocapture:!0,capture_pageview:!0,capture_performance:!0,persistence:"localStorage",session_recording:{maskAllInputs:!1,maskInputOptions:{password:!0},maskTextSelector:null},mask_all_text:!1,mask_all_element_attributes:!1,loaded:e=>{e.register({source:"core",rivet_version:"0.11.0",env:"production"})}},children:y.jsx(gW,{fallback:y.jsx(wwe,{}),children:y.jsx(Hz,{client:xwe,children:y.jsx(f1e,{defaultShape:"rounded",children:y.jsx(u1e,{defaultLibrary:"lucide",children:y.jsx(ywe,{})})})})})})}));