parasor 0.1.1 → 0.1.2

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.
@@ -25,10 +25,10 @@ Details…`,className:`cm-mono flex-1 resize-none rounded-control border border-
25
25
  Press space again to drop the item in its new position, or press escape to cancel.
26
26
  `},Bn={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function Vn(e){let{announcements:t=Bn,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=zn}=e,{announce:a,announcement:o}=Fn(),s=xn(`DndLiveRegion`),[c,l]=(0,B.useState)(!1);if((0,B.useEffect)(()=>{l(!0)},[]),Ln((0,B.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=B.createElement(B.Fragment,null,B.createElement(Nn,{id:r,value:i.draggable}),B.createElement(Pn,{id:s,announcement:o}));return n?(0,nn.createPortal)(u,n):u}var Hn;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(Hn||={});function Un(){}function Wn(e,t){return(0,B.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function Gn(){var e=[...arguments];return(0,B.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var Kn=Object.freeze({x:0,y:0});function qn(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function Jn(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function Yn(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function Xn(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function Zn(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function Qn(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var $n=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=Qn(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=qn(Qn(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(Jn)},er=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=Xn(t),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=Xn(r),o=i.reduce((e,t,r)=>e+qn(n[r],t),0),s=Number((o/4).toFixed(4));a.push({id:t,data:{droppableContainer:e,value:s}})}}return a.sort(Jn)};function tr(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r<i&&n<a){let n=t.width*t.height,r=e.width*e.height,i=o*s,a=i/(n+r-i);return Number(a.toFixed(4))}return 0}var nr=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=tr(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(Yn)};function rr(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function ir(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Kn}function ar(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var or=ar(1);function sr(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function cr(e,t,n){let r=sr(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var lr={ignoreTransform:!1};function ur(e,t){t===void 0&&(t=lr);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=cn(e).getComputedStyle(e);t&&(n=cr(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function dr(e){return ur(e,{ignoreTransform:!0})}function fr(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function pr(e,t){return t===void 0&&(t=cn(e).getComputedStyle(e)),t.position===`fixed`}function mr(e,t){t===void 0&&(t=cn(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`?n.test(r):!1})}function hr(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(ln(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!un(i)||dn(i)||n.includes(i))return n;let a=cn(e).getComputedStyle(i);return i!==e&&mr(i,a)&&n.push(i),pr(i,a)?n:r(i.parentNode)}return e?r(e):n}function gr(e){let[t]=hr(e,1);return t??null}function _r(e){return!an||!e?null:on(e)?e:sn(e)?ln(e)||e===fn(e).scrollingElement?window:un(e)?e:null:null}function vr(e){return on(e)?e.scrollX:e.scrollLeft}function yr(e){return on(e)?e.scrollY:e.scrollTop}function br(e){return{x:vr(e),y:yr(e)}}var xr;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(xr||={});function Sr(e){return!an||!e?!1:e===document.scrollingElement}function Cr(e){let t={x:0,y:0},n=Sr(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var wr={x:.2,y:.2};function Tr(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=wr);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=Cr(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=xr.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=xr.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=xr.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=xr.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function Er(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Dr(e){return e.reduce((e,t)=>Cn(e,br(t)),Kn)}function Or(e){return e.reduce((e,t)=>e+vr(t),0)}function kr(e){return e.reduce((e,t)=>e+yr(t),0)}function Ar(e,t){if(t===void 0&&(t=ur),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);gr(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var jr=[[`x`,[`left`,`right`],Or],[`y`,[`top`,`bottom`],kr]],Mr=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=hr(t),r=Dr(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of jr)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,`rect`,{enumerable:!1})}},Nr=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function Pr(e){let{EventTarget:t}=cn(e);return e instanceof t?e:fn(e)}function Fr(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t?r>t.y:!1}var Ir;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(Ir||={});function Lr(e){e.preventDefault()}function Rr(e){e.stopPropagation()}var H;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})(H||={});var zr={start:[H.Space,H.Enter],cancel:[H.Esc],end:[H.Space,H.Enter,H.Tab]},Br=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case H.Right:return{...n,x:n.x+25};case H.Left:return{...n,x:n.x-25};case H.Down:return{...n,y:n.y+25};case H.Up:return{...n,y:n.y-25}}},Vr=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new Nr(fn(t)),this.windowListeners=new Nr(cn(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ir.Resize,this.handleCancel),this.windowListeners.add(Ir.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ir.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&Ar(n),t(Kn)}handleKeyDown(e){if(En(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=zr,coordinateGetter:a=Br,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:Kn;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=wn(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=Cr(n),p=Er(n),m={x:Math.min(i===H.Right?p.right-p.width/2:p.right,Math.max(i===H.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===H.Down?p.bottom-p.height/2:p.bottom,Math.max(i===H.Down?p.top:p.top+p.height/2,u.y))},h=i===H.Right&&!s||i===H.Left&&!c,g=i===H.Down&&!l||i===H.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===H.Right&&e<=d.x||i===H.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===H.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===H.Down&&e<=d.y||i===H.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===H.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,Cn(wn(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};Vr.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=zr,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function Hr(e){return!!(e&&`distance`in e)}function Ur(e){return!!(e&&`delay`in e)}var Wr=class{constructor(e,t,n){n===void 0&&(n=Pr(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=fn(i),this.documentListeners=new Nr(this.document),this.listeners=new Nr(n),this.windowListeners=new Nr(cn(i)),this.initialCoordinates=On(r)??Kn,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Ir.Resize,this.handleCancel),this.windowListeners.add(Ir.DragStart,Lr),this.windowListeners.add(Ir.VisibilityChange,this.handleCancel),this.windowListeners.add(Ir.ContextMenu,Lr),this.documentListeners.add(Ir.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(Ur(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(Hr(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(Ir.Click,Rr,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ir.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=On(e)??Kn,s=wn(n,o);if(!t&&a){if(Hr(a)){if(a.tolerance!=null&&Fr(s,a.tolerance))return this.handleCancel();if(Fr(s,a.distance))return this.handleStart()}if(Ur(a)&&Fr(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===H.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},Gr={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},Kr=class extends Wr{constructor(e){let{event:t}=e,n=fn(t.target);super(e,Gr,n)}};Kr.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var qr={move:{name:`mousemove`},end:{name:`mouseup`}},Jr;(function(e){e[e.RightClick=2]=`RightClick`})(Jr||={});var Yr=class extends Wr{constructor(e){super(e,qr,fn(e.event.target))}};Yr.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===Jr.RightClick?!1:(r?.({event:n}),!0)}}];var Xr={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},Zr=class extends Wr{constructor(e){super(e,Xr)}static setup(){return window.addEventListener(Xr.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(Xr.move.name,e)};function e(){}}};Zr.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var Qr;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(Qr||={});var $r;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})($r||={});function ei(e){let{acceleration:t,activator:n=Qr.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=$r.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=ni({delta:d,disabled:!a}),[m,h]=hn(),g=(0,B.useRef)({x:0,y:0}),_=(0,B.useRef)({x:0,y:0}),v=(0,B.useMemo)(()=>{switch(n){case Qr.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case Qr.DraggableRect:return i}},[n,i,c]),y=(0,B.useRef)(null),b=(0,B.useCallback)(()=>{let e=y.current;if(!e)return;let t=g.current.x*_.current.x,n=g.current.y*_.current.y;e.scrollBy(t,n)},[]),x=(0,B.useMemo)(()=>s===$r.TreeOrder?[...l].reverse():l,[s,l]);(0,B.useEffect)(()=>{if(!a||!l.length||!v){h();return}for(let e of x){if(r?.(e)===!1)continue;let n=u[l.indexOf(e)];if(!n)continue;let{direction:i,speed:a}=Tr(e,n,v,t,f);for(let e of[`x`,`y`])p[e][i[e]]||(a[e]=0,i[e]=0);if(a.x>0||a.y>0){h(),y.current=e,m(b,o),g.current=a,_.current=i;return}}g.current={x:0,y:0},_.current={x:0,y:0},h()},[t,b,r,h,a,o,JSON.stringify(v),JSON.stringify(p),m,l,x,u,JSON.stringify(f)])}var ti={x:{[xr.Backward]:!1,[xr.Forward]:!1},y:{[xr.Backward]:!1,[xr.Forward]:!1}};function ni(e){let{delta:t,disabled:n}=e,r=yn(t);return _n(e=>{if(n||!r||!e)return ti;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[xr.Backward]:e.x[xr.Backward]||i.x===-1,[xr.Forward]:e.x[xr.Forward]||i.x===1},y:{[xr.Backward]:e.y[xr.Backward]||i.y===-1,[xr.Forward]:e.y[xr.Forward]||i.y===1}}},[n,t,r])}function ri(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return _n(e=>t==null?null:r??e??null,[r,t])}function ii(e,t){return(0,B.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var ai;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(ai||={});var oi;(function(e){e.Optimized=`optimized`})(oi||={});var si=new Map;function ci(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,B.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,B.useRef)(e),d=g(),f=gn(d),p=(0,B.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,B.useRef)(null),h=_n(t=>{if(d&&!n)return si;if(!t||t===si||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new Mr(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,B.useEffect)(()=>{u.current=e},[e]),(0,B.useEffect)(()=>{d||p()},[n,d]),(0,B.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,B.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case ai.Always:return!1;case ai.BeforeDragging:return n;default:return!n}}}function li(e,t){return _n(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function ui(e,t){return li(e,t)}function di(e){let{callback:t,disabled:n}=e,r=mn(t),i=(0,B.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,B.useEffect)(()=>()=>i?.disconnect(),[i]),i}function fi(e){let{callback:t,disabled:n}=e,r=mn(t),i=(0,B.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,B.useEffect)(()=>()=>i?.disconnect(),[i]),i}function pi(e){return new Mr(ur(e),e)}function mi(e,t,n){t===void 0&&(t=pi);let[r,i]=(0,B.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=di({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=fi({callback:a});return pn(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function hi(e){return ir(e,li(e))}var gi=[];function _i(e){let t=(0,B.useRef)(e),n=_n(n=>e?n&&n!==gi&&e&&t.current&&e.parentNode===t.current.parentNode?n:hr(e):gi,[e]);return(0,B.useEffect)(()=>{t.current=e},[e]),n}function vi(e){let[t,n]=(0,B.useState)(null),r=(0,B.useRef)(e),i=(0,B.useCallback)(e=>{let t=_r(e.target);t&&n(e=>e?(e.set(t,br(t)),new Map(e)):null)},[]);return(0,B.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=_r(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,br(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{_r(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,B.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>Cn(e,t),Kn):Dr(e):Kn,[e,t])}function yi(e,t){t===void 0&&(t=[]);let n=(0,B.useRef)(null);return(0,B.useEffect)(()=>{n.current=null},t),(0,B.useEffect)(()=>{let t=e!==Kn;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?wn(e,n.current):Kn}function bi(e){(0,B.useEffect)(()=>{if(!an)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function xi(e,t){return(0,B.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function Si(e){return(0,B.useMemo)(()=>e?fr(e):null,[e])}var Ci=[];function wi(e,t){t===void 0&&(t=ur);let[n]=e,r=Si(n?cn(n):null),[i,a]=(0,B.useState)(Ci);function o(){a(()=>e.length?e.map(e=>Sr(e)?r:new Mr(t(e),e)):Ci)}let s=fi({callback:o});return pn(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function Ti(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return un(t)?t:e}function Ei(e){let{measure:t}=e,[n,r]=(0,B.useState)(null),i=fi({callback:(0,B.useCallback)(e=>{for(let{target:n}of e)if(un(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=vn((0,B.useCallback)(e=>{let n=Ti(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,B.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var Di=[{sensor:Kr,options:{}},{sensor:Vr,options:{}}],Oi={current:{}},ki={draggable:{measure:dr},droppable:{measure:dr,strategy:ai.WhileDragging,frequency:oi.Optimized},dragOverlay:{measure:ur}},U=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},W={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new U,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Un},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:ki,measureDroppableContainers:Un,windowRect:null,measuringScheduled:!1},Ai={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:Un,draggableNodes:new Map,over:null,measureDroppableContainers:Un},ji=(0,B.createContext)(Ai),Mi=(0,B.createContext)(W);function Ni(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new U}}}function Pi(e,t){switch(t.type){case Hn.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Hn.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Hn.DragEnd:case Hn.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Hn.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new U(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case Hn.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new U(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case Hn.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new U(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function Fi(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,B.useContext)(ji),a=yn(r),o=yn(n?.id);return(0,B.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!En(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=jn(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function Ii(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function Li(e){return(0,B.useMemo)(()=>({draggable:{...ki.draggable,...e?.draggable},droppable:{...ki.droppable,...e?.droppable},dragOverlay:{...ki.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function Ri(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,B.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;pn(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=ir(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=gr(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var zi=(0,B.createContext)({...Kn,scaleX:1,scaleY:1}),Bi;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(Bi||={});var Vi=(0,B.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=Di,collisionDetection:o=nr,measuring:s,modifiers:c,...l}=e,[u,d]=(0,B.useReducer)(Pi,void 0,Ni),[f,p]=Rn(),[m,h]=(0,B.useState)(Bi.Uninitialized),g=m===Bi.Initialized,{draggable:{active:_,nodes:v,translate:y},droppable:{containers:b}}=u,x=_==null?null:v.get(_),S=(0,B.useRef)({initial:null,translated:null}),C=(0,B.useMemo)(()=>_==null?null:{id:_,data:x?.data??Oi,rect:S},[_,x]),w=(0,B.useRef)(null),[T,E]=(0,B.useState)(null),[D,O]=(0,B.useState)(null),k=gn(l,Object.values(l)),ee=xn(`DndDescribedBy`,t),A=(0,B.useMemo)(()=>b.getEnabled(),[b]),j=Li(s),{droppableRects:te,measureDroppableContainers:ne,measuringScheduled:M}=ci(A,{dragging:g,dependencies:[y.x,y.y],config:j.droppable}),N=ri(v,_),re=(0,B.useMemo)(()=>D?On(D):null,[D]),ie=ke(),ae=ui(N,j.draggable.measure);Ri({activeNode:_==null?null:v.get(_),config:ie.layoutShiftCompensation,initialRect:ae,measure:j.draggable.measure});let P=mi(N,j.draggable.measure,ae),F=mi(N?N.parentElement:null),I=(0,B.useRef)({activatorEvent:null,active:null,activeNode:N,collisionRect:null,collisions:null,droppableRects:te,draggableNodes:v,draggingNode:null,draggingNodeRect:null,droppableContainers:b,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),L=b.getNodeFor(I.current.over?.id),R=Ei({measure:j.dragOverlay.measure}),oe=R.nodeRef.current??N,se=g?R.rect??P:null,ce=!!(R.nodeRef.current&&R.rect),le=hi(ce?null:P),ue=Si(oe?cn(oe):null),de=_i(g?L??N:null),fe=wi(de),pe=Ii(c,{transform:{x:y.x-le.x,y:y.y-le.y,scaleX:1,scaleY:1},activatorEvent:D,active:C,activeNodeRect:P,containerNodeRect:F,draggingNodeRect:se,over:I.current.over,overlayNodeRect:R.rect,scrollableAncestors:de,scrollableAncestorRects:fe,windowRect:ue}),me=re?Cn(re,y):null,he=vi(de),z=yi(he),ge=yi(he,[P]),_e=Cn(pe,z),ve=se?or(se,pe):null,ye=C&&ve?o({active:C,collisionRect:ve,droppableRects:te,droppableContainers:A,pointerCoordinates:me}):null,be=Zn(ye,`id`),[xe,Se]=(0,B.useState)(null),Ce=rr(ce?pe:Cn(pe,ge),xe?.rect??null,P),we=(0,B.useRef)(null),Te=(0,B.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(w.current==null)return;let i=v.get(w.current);if(!i)return;let a=e.nativeEvent;we.current=new n({active:w.current,activeNode:i,event:a,options:r,context:I,onAbort(e){if(!v.get(e))return;let{onDragAbort:t}=k.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!v.get(e))return;let{onDragPending:i}=k.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=w.current;if(t==null)return;let n=v.get(t);if(!n)return;let{onDragStart:r}=k.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:S}};(0,nn.unstable_batchedUpdates)(()=>{r?.(i),h(Bi.Initializing),d({type:Hn.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),E(we.current),O(a)})},onMove(e){d({type:Hn.DragMove,coordinates:e})},onEnd:o(Hn.DragEnd),onCancel:o(Hn.DragCancel)});function o(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=I.current,o=null;if(t&&i){let{cancelDrop:s}=k.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===Hn.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=Hn.DragCancel)}w.current=null,(0,nn.unstable_batchedUpdates)(()=>{d({type:e}),h(Bi.Uninitialized),Se(null),E(null),O(null),we.current=null;let t=e===Hn.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=k.current[t];e?.(o),f({type:t,event:o})}})}}},[v]),Ee=ii(a,(0,B.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=v.get(r);if(w.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},w.current=r,Te(n,t))},[v,Te]));bi(a),pn(()=>{P&&m===Bi.Initializing&&h(Bi.Initialized)},[P,m]),(0,B.useEffect)(()=>{let{onDragMove:e}=k.current,{active:t,activatorEvent:n,collisions:r,over:i}=I.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:_e.x,y:_e.y},over:i};(0,nn.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[_e.x,_e.y]),(0,B.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=I.current;if(!e||w.current==null||!t||!i)return;let{onDragOver:a}=k.current,o=r.get(be),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,nn.unstable_batchedUpdates)(()=>{Se(s),a?.(c),f({type:`onDragOver`,event:c})})},[be]),pn(()=>{I.current={activatorEvent:D,active:C,activeNode:N,collisionRect:ve,collisions:ye,droppableRects:te,draggableNodes:v,draggingNode:oe,draggingNodeRect:se,droppableContainers:b,over:xe,scrollableAncestors:de,scrollAdjustedTranslate:_e},S.current={initial:se,translated:ve}},[C,N,ye,ve,v,oe,se,te,b,xe,de,_e]),ei({...ie,delta:y,draggingRect:ve,pointerCoordinates:me,scrollableAncestors:de,scrollableAncestorRects:fe});let De=(0,B.useMemo)(()=>({active:C,activeNode:N,activeNodeRect:P,activatorEvent:D,collisions:ye,containerNodeRect:F,dragOverlay:R,draggableNodes:v,droppableContainers:b,droppableRects:te,over:xe,measureDroppableContainers:ne,scrollableAncestors:de,scrollableAncestorRects:fe,measuringConfiguration:j,measuringScheduled:M,windowRect:ue}),[C,N,P,D,ye,F,R,v,b,te,xe,ne,de,fe,j,M,ue]),Oe=(0,B.useMemo)(()=>({activatorEvent:D,activators:Ee,active:C,activeNodeRect:P,ariaDescribedById:{draggable:ee},dispatch:d,draggableNodes:v,over:xe,measureDroppableContainers:ne}),[D,Ee,C,P,d,ee,v,xe,ne]);return B.createElement(In.Provider,{value:p},B.createElement(ji.Provider,{value:Oe},B.createElement(Mi.Provider,{value:De},B.createElement(zi.Provider,{value:Ce},i)),B.createElement(Fi,{disabled:n?.restoreFocus===!1})),B.createElement(Vn,{...n,hiddenTextDescribedById:ee}));function ke(){let e=T?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),Hi=(0,B.createContext)(null),Ui=`button`,Wi=`Draggable`;function Gi(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=xn(Wi),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,B.useContext)(ji),{role:p=Ui,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,_=(0,B.useContext)(g?zi:Hi),[v,y]=vn(),[b,x]=vn(),S=xi(o,t),C=gn(n);return pn(()=>(d.set(t,{id:t,key:a,node:v,activatorNode:b,data:C}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,B.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===Ui?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:S,node:v,over:f,setNodeRef:y,setActivatorNodeRef:x,transform:_}}function Ki(){return(0,B.useContext)(Mi)}var qi=`Droppable`,Ji={timeout:25};function Yi(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=xn(qi),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,B.useContext)(ji),u=(0,B.useRef)({disabled:n}),d=(0,B.useRef)(!1),f=(0,B.useRef)(null),p=(0,B.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...Ji,...i},_=gn(h??r),v=fi({callback:(0,B.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(_.current)?_.current:[_.current]),p.current=null},g)},[g]),disabled:m||!o}),[y,b]=vn((0,B.useCallback)((e,t)=>{v&&(t&&(v.unobserve(t),d.current=!1),e&&v.observe(e))},[v])),x=gn(t);return(0,B.useEffect)(()=>{!v||!y.current||(v.disconnect(),d.current=!1,v.observe(y.current))},[y,v]),(0,B.useEffect)(()=>(s({type:Hn.RegisterDroppable,element:{id:r,key:a,disabled:n,node:y,rect:f,data:x}}),()=>s({type:Hn.UnregisterDroppable,key:a,id:r})),[r]),(0,B.useEffect)(()=>{n!==u.current.disabled&&(s({type:Hn.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:y,over:c,setNodeRef:b}}function Xi(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function Zi(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function Qi(e){return e!==null&&e>=0}function $i(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function ea(e){return typeof e==`boolean`?{draggable:e,droppable:e}:e}var ta=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=Xi(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},na={scaleX:1,scaleY:1},ra=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:t<a?e.top+e.height-(o.top+o.height):e.top-o.top,...na}:null}let s=ia(i,r,t);return r>t&&r<=a?{x:0,y:-o.height-s,...na}:r<t&&r>=a?{x:0,y:o.height+s,...na}:{x:0,y:0,...na}};function ia(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?n<t?i?r.top-(i.top+i.height):a?a.top-(r.top+r.height):0:a?a.top-(r.top+r.height):i?r.top-(i.top+i.height):0:0}var aa=`Sortable`,oa=B.createContext({activeIndex:-1,containerId:aa,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:ta,disabled:{draggable:!1,droppable:!1}});function sa(e){let{children:t,id:n,items:r,strategy:i=ta,disabled:a=!1}=e,{active:o,dragOverlay:s,droppableRects:c,over:l,measureDroppableContainers:u}=Ki(),d=xn(aa,n),f=s.rect!==null,p=(0,B.useMemo)(()=>r.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),m=o!=null,h=o?p.indexOf(o.id):-1,g=l?p.indexOf(l.id):-1,_=(0,B.useRef)(p),v=!$i(p,_.current),y=g!==-1&&h===-1||v,b=ea(a);pn(()=>{v&&m&&u(p)},[v,p,m,u]),(0,B.useEffect)(()=>{_.current=p},[p]);let x=(0,B.useMemo)(()=>({activeIndex:h,containerId:d,disabled:b,disableTransforms:y,items:p,overIndex:g,useDragOverlay:f,sortedRects:Zi(p,c),strategy:i}),[h,d,b.draggable,b.droppable,y,p,g,c,f,i]);return B.createElement(oa.Provider,{value:x},t)}var ca=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return Xi(n,r,i).indexOf(t)},la=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},ua={duration:200,easing:`ease`},da=`transform`,fa=kn.Transition.toString({property:da,duration:0,easing:`linear`}),pa={roleDescription:`sortable`};function ma(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,o]=(0,B.useState)(null),s=(0,B.useRef)(n);return pn(()=>{if(!t&&n!==s.current&&r.current){let e=i.current;if(e){let t=ur(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&o(n)}}n!==s.current&&(s.current=n)},[t,n,r,i]),(0,B.useEffect)(()=>{a&&o(null)},[a]),a}function ha(e){let{animateLayoutChanges:t=la,attributes:n,disabled:r,data:i,getNewIndex:a=ca,id:o,strategy:s,resizeObserverConfig:c,transition:l=ua}=e,{items:u,containerId:d,activeIndex:f,disabled:p,disableTransforms:m,sortedRects:h,overIndex:g,useDragOverlay:_,strategy:v}=(0,B.useContext)(oa),y=ga(r,p),b=u.indexOf(o),x=(0,B.useMemo)(()=>({sortable:{containerId:d,index:b,items:u},...i}),[d,i,b,u]),S=(0,B.useMemo)(()=>u.slice(u.indexOf(o)),[u,o]),{rect:C,node:w,isOver:T,setNodeRef:E}=Yi({id:o,data:x,disabled:y.droppable,resizeObserverConfig:{updateMeasurementsFor:S,...c}}),{active:D,activatorEvent:O,activeNodeRect:k,attributes:ee,setNodeRef:A,listeners:j,isDragging:te,over:ne,setActivatorNodeRef:M,transform:N}=Gi({id:o,data:x,attributes:{...pa,...n},disabled:y.draggable}),re=rn(E,A),ie=!!D,ae=ie&&!m&&Qi(f)&&Qi(g),P=!_&&te,F=ae?(P&&ae?N:null)??(s??v)({rects:h,activeNodeRect:k,activeIndex:f,overIndex:g,index:b}):null,I=Qi(f)&&Qi(g)?a({id:o,items:u,activeIndex:f,overIndex:g}):b,L=D?.id,R=(0,B.useRef)({activeId:L,items:u,newIndex:I,containerId:d}),oe=u!==R.current.items,se=t({active:D,containerId:d,isDragging:te,isSorting:ie,id:o,index:b,items:u,newIndex:R.current.newIndex,previousItems:R.current.items,previousContainerId:R.current.containerId,transition:l,wasDragging:R.current.activeId!=null}),ce=ma({disabled:!se,index:b,node:w,rect:C});return(0,B.useEffect)(()=>{ie&&R.current.newIndex!==I&&(R.current.newIndex=I),d!==R.current.containerId&&(R.current.containerId=d),u!==R.current.items&&(R.current.items=u)},[ie,I,d,u]),(0,B.useEffect)(()=>{if(L===R.current.activeId)return;if(L!=null&&R.current.activeId==null){R.current.activeId=L;return}let e=setTimeout(()=>{R.current.activeId=L},50);return()=>clearTimeout(e)},[L]),{active:D,activeIndex:f,attributes:ee,data:x,rect:C,index:b,newIndex:I,items:u,isOver:T,isSorting:ie,isDragging:te,listeners:j,node:w,overIndex:g,over:ne,setNodeRef:re,setActivatorNodeRef:M,setDroppableNodeRef:E,setDraggableNodeRef:A,transform:ce??F,transition:le()};function le(){if(ce||oe&&R.current.newIndex===b)return fa;if(!(P&&!En(O)||!l)&&(ie||se))return kn.Transition.toString({...l,property:da})}}function ga(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}function _a(e){if(!e)return!1;let t=e.data.current;return!!(t&&`sortable`in t&&typeof t.sortable==`object`&&`containerId`in t.sortable&&`items`in t.sortable&&`index`in t.sortable)}var va=[H.Down,H.Right,H.Up,H.Left],ya=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:a,over:o,scrollableAncestors:s}}=t;if(va.includes(e.code)){if(e.preventDefault(),!n||!r)return;let t=[];a.getEnabled().forEach(n=>{if(!n||n!=null&&n.disabled)return;let a=i.get(n.id);if(a)switch(e.code){case H.Down:r.top<a.top&&t.push(n);break;case H.Up:r.top>a.top&&t.push(n);break;case H.Left:r.left>a.left&&t.push(n);break;case H.Right:r.left<a.left&&t.push(n);break}});let c=er({active:n,collisionRect:r,droppableRects:i,droppableContainers:t,pointerCoordinates:null}),l=Zn(c,`id`);if(l===o?.id&&c.length>1&&(l=c[1].id),l!=null){let e=a.get(n.id),t=a.get(l),o=t?i.get(t.id):null,c=t?.node.current;if(c&&o&&e&&t){let n=hr(c).some((e,t)=>s[t]!==e),i=ba(e,t),a=xa(e,t),l=n||!i?{x:0,y:0}:{x:a?r.width-o.width:0,y:a?r.height-o.height:0},u={x:o.left,y:o.top};return l.x&&l.y?u:wn(u,l)}}}};function ba(e,t){return!_a(e)||!_a(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function xa(e,t){return!_a(e)||!_a(t)||!ba(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}function Sa({project:e,worktree:t,selection:n,onSelectChild:r,onToggleChildPin:i,onReorderPanes:a}){return t.children.length===0?null:a?(0,V.jsx)(Ca,{project:e,worktree:t,selection:n,onSelectChild:r,onToggleChildPin:i,onReorderPanes:a}):(0,V.jsx)(`div`,{children:t.children.map(a=>(0,V.jsx)(en,{child:a,selected:n.selectedWorktreeId===t.id&&n.selectedChildId===a.id,onTogglePin:a.kind===`terminal`&&i?()=>i(a.id):void 0,onClick:()=>r?.(e.id,t.id,a.id)},a.id))})}function Ca({project:e,worktree:t,selection:n,onSelectChild:r,onToggleChildPin:i,onReorderPanes:a}){let o=(0,B.useMemo)(()=>t.children.map(e=>e.id),[t.children]),[s,c]=(0,B.useState)(o);(0,B.useEffect)(()=>{c(e=>{let t=new Set(o),n=new Set(e);return t.size===n.size&&[...t].every(e=>n.has(e))?e:o})},[o]);let l=new Map(t.children.map(e=>[e.id,e])),u=s.map(e=>l.get(e)).filter(e=>!!e),d=Gn(Wn(Yr,{activationConstraint:{distance:8}}),Wn(Zr,{activationConstraint:{delay:250,tolerance:6}}),Wn(Vr,{coordinateGetter:ya}));function f(n){let{active:r,over:i}=n;if(!i||r.id===i.id)return;let o=s.indexOf(String(r.id)),l=s.indexOf(String(i.id));if(o===-1||l===-1)return;let u=Xi(s,o,l);c(u),a(e.id,t.path,u)}return(0,V.jsx)(Vi,{sensors:d,collisionDetection:$n,onDragEnd:f,children:(0,V.jsx)(sa,{items:s,strategy:ra,children:(0,V.jsx)(`div`,{children:u.map(a=>(0,V.jsx)(wa,{child:a,selected:n.selectedWorktreeId===t.id&&n.selectedChildId===a.id,onTogglePin:a.kind===`terminal`&&i?()=>i(a.id):void 0,onClick:()=>r?.(e.id,t.id,a.id)},a.id))})})})}function wa({child:e,selected:t,onClick:n,onTogglePin:r}){let{attributes:i,listeners:a,setNodeRef:o,transform:s,transition:c,isDragging:l}=ha({id:e.id}),u={transform:kn.Transform.toString(s),transition:c,opacity:l?.6:1,zIndex:l?5:void 0,WebkitTouchCallout:`none`},d=Ea(a);return(0,V.jsx)(`div`,{ref:o,style:u,...i,...d,className:`select-none`,children:(0,V.jsx)(en,{child:e,selected:t,onTogglePin:r,onClick:n})})}var Ta=new Set([`onPointerDown`,`onMouseDown`,`onTouchStart`]);function Ea(e){if(!e)return e;let t={};for(let[n,r]of Object.entries(e))Ta.has(n)?t[n]=e=>{r(e),e.stopPropagation()}:t[n]=r;return t}function Da({label:e,onOpenContainer:t}){return t?(0,V.jsx)(Kt,{"aria-label":`New session in ${e}`,tone:`accentHover`,onClick:e=>{e.stopPropagation(),t()},children:(0,V.jsx)(h.add,{})}):null}var Oa=`parasor:sidebar:worktree-open`;function ka(e){return`${Oa}:${e}`}function Aa(e,t){try{let n=window.localStorage.getItem(ka(e));if(!n)return!0;let r=JSON.parse(n);if(!r||typeof r!=`object`||Array.isArray(r))return!0;let i=r[t];return typeof i==`boolean`?i:!0}catch{return!0}}function ja(e,t,n){try{let r=ka(e),i=window.localStorage.getItem(r),a=i?JSON.parse(i):null,o=a&&typeof a==`object`&&!Array.isArray(a)?{...a}:{};o[t]=n,window.localStorage.setItem(r,JSON.stringify(o))}catch{}}function Ma(e,t,n){let[r,i]=(0,B.useState)(()=>Aa(e,t));return(0,B.useEffect)(()=>{i(Aa(e,t))},[e,t]),{open:n?!0:r,toggle:()=>{n||i(n=>{let r=!n;return ja(e,t,r),r})}}}function Na({project:e,worktree:t,selection:n,displayName:r,forceOpen:i=!1,isProjectRoot:a=!1,dragHandleProps:o,onSelectWorktree:s,onSelectChild:c,onOpenContainer:l,onToggleChildPin:u,onReorderPanes:d}){let{open:f,toggle:p}=Ma(e.id,t.path,i),m=n.selectedWorktreeId===t.id&&n.selectedChildId===null,g=e.isRepo===!1,_=r??t.name,v=t.dirty>0?`${t.dirty} uncommitted change${t.dirty===1?``:`s`}`:void 0,y=t.dirty>0?`bg-[var(--theme-git-modified)]`:``;return(0,V.jsxs)(`div`,{className:`border-t border-border`,children:[(0,V.jsxs)(Wt,{selected:m,rootProps:o,className:`group select-none`,children:[(0,V.jsx)(Kt,{onClick:p,onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&e.stopPropagation()},"aria-expanded":f,"aria-label":`${f?`Collapse`:`Expand`} ${_}`,children:(0,V.jsx)(`span`,{"aria-hidden":!0,className:`transition-transform duration-[120ms] ${f?`rotate-90`:`rotate-0`}`,children:(0,V.jsx)(h.disclosure,{})})}),!a&&(0,V.jsx)(Jt,{tone:m?`accent`:`secondary`,className:`relative`,children:g?(0,V.jsx)(h.folder,{}):t.active?(0,V.jsx)(h.worktreeActive,{}):(0,V.jsx)(h.worktreeInactive,{})}),(0,V.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-1 text-left`,"aria-label":v?`${_}, ${v}`:void 0,onClick:()=>s?.(e.id,t.id),children:[(0,V.jsx)(Xt,{title:v,selected:m,weight:m?`semibold`:`medium`,className:a?`text-text-primary`:`text-text-secondary`,children:_}),a&&e.readOnly&&(0,V.jsx)(`span`,{title:`read-only`,className:`shrink-0 text-text-secondary`,children:(0,V.jsx)(h.readOnlyProject,{})}),t.origin===`agent`&&(0,V.jsx)(`span`,{role:`img`,"aria-label":`Agent worktree`,title:`Created by an agent (Agent Team isolated checkout)`,className:`shrink-0 rounded-tag border border-accent/40 bg-accent/10 px-1 text-[10px] font-medium leading-tight text-accent`,children:`agent`}),t.orphan&&(0,V.jsx)(`span`,{role:`img`,"aria-label":`Orphan worktree`,title:`Path is missing on disk -- use force remove to prune`,className:`shrink-0 rounded-tag border border-danger/40 bg-danger/10 px-1 text-[10px] font-medium leading-tight text-danger`,children:`orphan`})]}),y&&(0,V.jsx)(`span`,{"aria-hidden":!0,title:v,className:`h-1.5 w-1.5 shrink-0 rounded-tag ${y}`}),(0,V.jsx)(Da,{label:_,onOpenContainer:l?()=>l(e.id,t.id):void 0})]}),f&&(0,V.jsx)(Sa,{project:e,worktree:t,selection:n,onSelectChild:c,onToggleChildPin:u,onReorderPanes:d})]})}function Pa({project:e,selection:t,onSelectWorktree:n,onSelectChild:r,onOpenContainer:i,onToggleChildPin:a,onReorderPanes:o,dragHandleProps:s,forceOpen:c=!1}){return(0,V.jsx)(V.Fragment,{children:(e.worktrees.length>0?e.worktrees:[{id:`wt:${e.path}`,name:e.isRepo===!1?`root`:`main`,path:e.path,active:!0,dirty:0,ahead:0,behind:0,children:[],hasWorkingChild:!1,hasAlertChild:!1}]).map((l,u)=>{let d=l.path===e.path;return(0,V.jsx)(Na,{project:e,worktree:l,selection:t,displayName:d?e.name:l.name,forceOpen:c,isProjectRoot:d,dragHandleProps:d&&u===0?s:void 0,onSelectWorktree:n,onSelectChild:r,onOpenContainer:i,onToggleChildPin:a,onReorderPanes:o},l.id)})})}function Fa(e,t){let n=[];for(let[r,i]of Object.entries(e??{}))for(let e of i??[])n.push({key:`${r}:${e.port}`,port:e.port,projectId:r,projectName:t?.[r]??`project`,reachable:e.reachable??e.bindsAll,url:`http://localhost:${e.port}`});return n.sort((e,t)=>e.projectName===t.projectName?e.port-t.port:e.projectName.localeCompare(t.projectName))}function Ia(e,t){let n=(0,B.useRef)(!1),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(()=>new Set),s=(0,B.useMemo)(()=>Fa(e,t),[e,t]),c=(0,B.useMemo)(()=>new Set(s.map(e=>e.key)),[s]);return(0,B.useEffect)(()=>{if(!n.current){n.current=!0,o(new Set(c));return}o(e=>{let t=new Set;for(let n of e)c.has(n)&&t.add(n);if(r)for(let e of c)t.add(e);return t})},[c,r]),{currentPortKeys:c,entries:s,hasUnread:s.some(e=>!a.has(e.key)),markCurrentSeen:()=>o(new Set(c)),open:r,setOpen:i}}function La({connected:e,portsByProjectId:t,projectNames:n,onOpenUrl:r}){let i=(0,B.useRef)(null),{entries:a,hasUnread:o,markCurrentSeen:s,open:c,setOpen:l}=Ia(t,n);return(0,B.useEffect)(()=>{if(!c)return;let e=e=>{let t=i.current;t&&e.target instanceof Node&&t.contains(e.target)||l(!1)},t=e=>{e.key===`Escape`&&l(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[c,l]),(0,V.jsxs)(`span`,{ref:i,className:`flex items-center gap-2`,children:[(0,V.jsxs)(Kt,{"aria-label":o?`Network ports, new ports`:`Network ports`,"aria-expanded":c,title:e?`Network ports`:`Offline`,tone:e?`accentPrimaryHover`:`dangerPrimaryHover`,onClick:()=>{l(e=>!e),s()},children:[(0,V.jsx)(h.connection,{}),o&&(0,V.jsx)(`span`,{"aria-hidden":!0,className:`absolute top-1 right-1 h-2 w-2 rounded-tag bg-accent shadow-[0_0_0_2px_var(--color-bg-secondary)]`})]}),c&&(0,V.jsxs)(`div`,{className:`fixed bottom-11 left-3 z-50 w-[min(20rem,calc(100vw-1.5rem))] rounded-window border border-border bg-bg-secondary p-2 text-left shadow-lg`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between px-1 pb-1.5`,children:[(0,V.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Detected ports`}),(0,V.jsx)(`span`,{className:`cm-mono text-xs text-text-secondary`,children:a.length})]}),a.length===0?(0,V.jsx)(`div`,{className:`px-1 py-2 text-xs text-text-secondary`,children:`No detected ports`}):(0,V.jsx)(`div`,{className:`max-h-64 overflow-y-auto`,children:a.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-2 rounded-control px-1.5 py-1.5 hover:bg-row-hover-bg`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:`h-2 w-2 shrink-0 rounded-tag ${e.reachable?`bg-accent`:`bg-warning`}`}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`cm-mono text-xs text-text-primary`,children:e.port}),(0,V.jsxs)(`div`,{className:`truncate text-xs text-text-secondary`,children:[e.projectName,!e.reachable&&` - localhost only`]})]}),(0,V.jsx)(`button`,{type:`button`,disabled:!e.reachable||!r,onClick:()=>{r?.(e.url,{projectId:e.projectId}),l(!1)},className:`flex h-7 shrink-0 items-center rounded-control px-2 text-xs text-accent hover:bg-row-hover-bg disabled:text-text-secondary disabled:opacity-50`,children:`Open`})]},e.key))})]})]})}function Ra({connected:e,portsByProjectId:t,projectNames:n,onOpenUrl:i,onOpenSettings:a,onNewProject:o,searchOpen:s=!1,onToggleSearch:c}){return(0,V.jsx)(r,{tone:`sidebar`,horizontalPaddingClassName:Ht[0],status:(0,V.jsx)(La,{connected:e,portsByProjectId:t,projectNames:n,onOpenUrl:i}),actions:(0,V.jsxs)(`span`,{className:`flex items-center gap-3`,children:[o&&(0,V.jsx)(Kt,{title:`New project`,"aria-label":`New project`,onClick:o,tone:`accentHover`,children:(0,V.jsx)(h.add,{})}),(0,V.jsx)(Kt,{title:`Filter sidebar`,"aria-label":s?`Close sidebar filter`:`Filter sidebar`,"aria-pressed":s,onClick:c,tone:s?`accent`:`default`,children:(0,V.jsx)(h.search,{})}),(0,V.jsx)(Kt,{title:`Settings`,"aria-label":`Open settings`,onClick:a,children:(0,V.jsx)(h.settings,{})})]})})}function za({query:e,onClose:t,onQueryChange:n}){let r=(0,B.useRef)(null),i=(0,B.useRef)(!1);return(0,B.useEffect)(()=>{i.current=!1;let e=requestAnimationFrame(()=>r.current?.focus());return()=>cancelAnimationFrame(e)},[]),(0,V.jsxs)(`div`,{className:`flex h-bar shrink-0 items-center gap-2 border-t border-border bg-bg-secondary ${Ht[0]}`,children:[(0,V.jsx)(`span`,{className:`shrink-0 text-text-secondary`,children:(0,V.jsx)(h.search,{})}),(0,V.jsx)(`input`,{ref:r,value:e,onChange:e=>n?.(e.target.value),onCompositionStart:()=>{i.current=!0},onCompositionEnd:()=>{i.current=!1},onBlur:()=>{i.current=!1},onKeyDown:e=>{e.key===`Escape`&&!e.nativeEvent.isComposing&&!i.current&&(e.preventDefault(),t?.())},maxLength:256,placeholder:`Filter sidebar…`,"aria-label":`Filter sidebar`,className:`flex-1 bg-transparent text-sm text-text-primary placeholder:text-text-secondary focus:outline-none`}),t&&(0,V.jsx)(Kt,{onClick:t,"aria-label":`Close sidebar filter`,children:(0,V.jsx)(h.close,{})})]})}function Ba({projects:e,selection:t,resetSignal:n,pendingReorderCount:r=0,onReorderProjects:i,onSelectWorktree:a,onSelectChild:o,onOpenContainer:s,onToggleChildPin:c,onReorderPanes:l}){let u=(0,B.useMemo)(()=>e.map(e=>e.id),[e]),[d,f]=(0,B.useState)(u),p=(0,B.useRef)(r);p.current=r,(0,B.useEffect)(()=>{f(e=>{let t=new Set(u),n=new Set(e);return t.size===n.size&&[...t].every(e=>n.has(e))&&(p.current>0||e.join(`
27
27
  `)===u.join(`
28
- `))?e:u})},[u,n]);let m=new Map(e.map(e=>[e.id,e])),h=d.map(e=>m.get(e)).filter(e=>!!e),g=Gn(Wn(Yr,{activationConstraint:{distance:8}}),Wn(Zr,{activationConstraint:{delay:250,tolerance:6}}),Wn(Vr,{coordinateGetter:ya}));function _(e){let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=d.indexOf(String(t.id)),a=d.indexOf(String(n.id));if(r===-1||a===-1)return;let o=Xi(d,r,a);f(o),i(o)}return(0,V.jsx)(Vi,{sensors:g,collisionDetection:$n,onDragEnd:_,children:(0,V.jsx)(sa,{items:d,strategy:ra,children:h.map(e=>(0,V.jsx)(Va,{project:e,selection:t,onSelectWorktree:a,onSelectChild:o,onOpenContainer:s,onToggleChildPin:c,onReorderPanes:l},e.id))})})}function Va({project:e,selection:t,onSelectWorktree:n,onSelectChild:r,onOpenContainer:i,onToggleChildPin:a,onReorderPanes:o}){let{attributes:s,listeners:c,setNodeRef:l,transform:u,transition:d,isDragging:f}=ha({id:e.id});return(0,V.jsx)(`div`,{ref:l,style:{transform:kn.Transform.toString(u),transition:d,opacity:f?.6:1,zIndex:f?5:void 0},children:(0,V.jsx)(Pa,{project:e,selection:t,onSelectWorktree:n,onSelectChild:r,onOpenContainer:i,onToggleChildPin:a,onReorderPanes:o,dragHandleProps:{...s,...c,"aria-label":`Reorder ${e.name}`,style:{WebkitTouchCallout:`none`}}})})}function Ha(e,t){let n=t.toLowerCase(),r=[];for(let t of e){let e=t.name.toLowerCase().includes(n),i=[];for(let r of t.worktrees){let t=r.name.toLowerCase().includes(n);if(e||t){i.push(r);continue}let a=r.children.filter(e=>e.label.toLowerCase().includes(n)||(e.hint?.toLowerCase().includes(n)??!1));a.length>0&&i.push({...r,children:a})}(e||i.length>0)&&r.push({...t,worktrees:i})}return r}function Ua({resizable:e,width:t,onWidthChange:n}){let r=(0,B.useRef)(null),i=(0,B.useRef)(!1),a=e?Bt(t):Number.isFinite(t)?Math.round(t):288,o=zt(),s=e&&!!n,c=(0,B.useCallback)(e=>{let t=r.current?.getBoundingClientRect();t&&n?.(Bt(e-t.left))},[n]),l=(0,B.useCallback)(e=>{n&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),i.current=!0,c(e.clientX))},[n,c]),u=(0,B.useCallback)(e=>{if(i.current){if(e.buttons===0){i.current=!1;return}c(e.clientX)}},[c]),d=(0,B.useCallback)(e=>{i.current=!1;try{e.currentTarget.releasePointerCapture?.(e.pointerId)}catch{}},[]);return{asideRef:r,effectiveMaxWidth:o,effectiveWidth:a,showResizeHandle:s,resizeHandleProps:{onKeyDown:(0,B.useCallback)(e=>{if(n&&!(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`&&e.key!==`Home`&&e.key!==`End`)){if(e.preventDefault(),e.key===`Home`){n(220);return}if(e.key===`End`){n(zt());return}n(Bt(a+(e.key===`ArrowLeft`?-1:1)*(e.shiftKey?48:16)))}},[a,n]),onPointerCancel:d,onPointerDown:l,onPointerMove:u,onPointerUp:d}}}function Wa({projects:e,selection:t,connected:n,portsByProjectId:r,projectNames:i,onOpenUrl:a,width:o=288,fill:s=!1,resizable:c=!1,onWidthChange:l,onSelectMonitor:u,onSelectWorktree:d,onSelectChild:f,onOpenContainer:p,onToggleChildPin:m,onNewProject:g,onOpenSettings:_,searchOpen:v=!1,searchQuery:y=``,onToggleSearch:b,onCloseSearch:x,onSearchQueryChange:S,pinnedMonitorCount:C=0,onReorderProjects:w,onReorderPanes:T,reorderResetSignal:E,pendingProjectReorderCount:D}){let O=(0,B.useDeferredValue)(y).trim(),k=v&&O.length>0,ee=(0,B.useMemo)(()=>k?Ha(e,O):e,[k,e,O]),{asideRef:A,effectiveMaxWidth:j,effectiveWidth:te,resizeHandleProps:ne,showResizeHandle:M}=Ua({onWidthChange:l,resizable:c,width:o});return(0,V.jsxs)(`aside`,{ref:A,"aria-label":`Workspace navigation`,className:`relative flex h-full min-h-0 shrink-0 flex-col bg-bg-secondary text-text-primary ${s?`w-full`:`border-r border-border`}`,style:s?void 0:{width:te},children:[(0,V.jsxs)(`div`,{className:`cm-scroll min-h-0 flex-1 overflow-y-auto pb-2.5`,children:[(0,V.jsx)(tn,{selected:t.monitor,pinnedCount:C,onClick:u}),k?ee.length===0?(0,V.jsxs)(`div`,{className:`${Ht[0]} py-6 text-center text-xs text-text-secondary`,children:[`No matches for`,` `,(0,V.jsxs)(`span`,{className:`text-text-primary`,children:[`"`,O,`"`]})]}):(0,V.jsx)(`div`,{children:ee.map(e=>(0,V.jsx)(Pa,{project:e,selection:t,forceOpen:!0,onSelectWorktree:d,onSelectChild:f,onOpenContainer:p,onToggleChildPin:m},e.id))}):(0,V.jsx)(Ba,{projects:ee,selection:t,resetSignal:E,pendingReorderCount:D,onReorderProjects:w??(()=>{}),onSelectWorktree:d,onSelectChild:f,onOpenContainer:p,onToggleChildPin:m,onReorderPanes:T}),g&&(0,V.jsx)(`div`,{className:`${Ht[0]} mt-2`,children:(0,V.jsxs)(`button`,{type:`button`,onClick:g,className:`flex h-bar w-full items-center justify-center gap-2 rounded-control border border-dashed border-border text-sm text-text-secondary hover:border-accent/60 hover:text-text-primary`,children:[(0,V.jsx)(h.add,{}),(0,V.jsx)(`span`,{children:`New Project`})]})})]}),v&&(0,V.jsx)(za,{query:y,onClose:x,onQueryChange:S}),(0,V.jsx)(Ra,{connected:n,portsByProjectId:r,projectNames:i,onOpenUrl:a,onOpenSettings:_,onNewProject:g,searchOpen:v,onToggleSearch:b}),M&&(0,V.jsx)(`hr`,{"aria-label":`Resize sidebar`,"aria-orientation":`vertical`,"aria-valuemin":220,"aria-valuemax":j,"aria-valuenow":te,tabIndex:0,...ne,className:`cm-sidebar-resizer absolute top-0 right-0 bottom-0 z-[3] w-px cursor-col-resize touch-none bg-border before:absolute before:inset-y-0 before:-inset-x-3 before:content-[''] focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`})]})}var Ga=null,Ka=new Set,qa=0,Ja=null;function Ya(){for(let e of Ka)e()}function Xa(e){return Ka.add(e),()=>{Ka.delete(e)}}function Za(){return Ga}function Qa(e,t=1800){qa+=1,Ga={message:e,seq:qa},Ja&&clearTimeout(Ja),Ja=setTimeout(()=>{Ga=null,Ja=null,Ya()},t),Ya()}function $a(){return(0,B.useSyncExternalStore)(Xa,Za,()=>null)}function eo(){let e=$a();return e?(0,V.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`cm-mono pointer-events-none fixed bottom-[max(env(safe-area-inset-bottom,0px),16px)] left-1/2 z-[60] -translate-x-1/2 rounded-window border border-border bg-bg-secondary px-3 py-1.5 text-sm text-text-primary shadow-[0_8px_24px_rgba(0,0,0,0.35)]`,children:e.message},e.seq):null}var to=5e3;function no({connected:e}){let[t,n]=(0,B.useState)(!1);return(0,B.useEffect)(()=>{if(e){n(!1);return}let t=setTimeout(()=>n(!0),to);return()=>clearTimeout(t)},[e]),t?(0,V.jsx)(ro,{}):null}function ro({onReload:e=()=>window.location.reload()}){let t=(0,B.useRef)(null),n=(0,B.useRef)(null);return(0,B.useEffect)(()=>{let e=document.activeElement;n.current=e instanceof HTMLElement&&e!==document.body&&e!==document.documentElement?e:null,t.current?.focus();let r=e=>{let n=t.current;if(n&&e.target instanceof Node&&n.contains(e.target)){if(e.key===`Tab`){e.preventDefault();return}if((e.key===`Enter`||e.key===` `)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey)return}e.stopPropagation(),e.preventDefault()};return document.addEventListener(`keydown`,r,!0),document.addEventListener(`keyup`,r,!0),()=>{document.removeEventListener(`keydown`,r,!0),document.removeEventListener(`keyup`,r,!0);let e=n.current;n.current=null,e&&document.contains(e)&&typeof e.focus==`function`&&e.focus()}},[]),(0,V.jsxs)(m,{open:!0,ariaLabelledBy:`offline-title`,dialogRole:`alertdialog`,onClose:()=>void 0,closeOnBackdrop:!1,closeOnEscape:!1,backdropClassName:`bg-black/50 p-6 backdrop-blur-sm`,widthClassName:`w-surface-sm max-w-full`,panelClassName:`flex flex-col overflow-hidden`,panelTabIndex:-1,onPanelContextMenu:e=>e.preventDefault(),children:[(0,V.jsx)(`div`,{"aria-hidden":!0,className:`h-1 shrink-0 bg-danger`}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3.5`,children:[(0,V.jsx)(`span`,{className:`cm-mono self-start text-xs font-bold uppercase tracking-[0.08em] text-danger`,children:`OFFLINE`}),(0,V.jsx)(`h2`,{id:`offline-title`,className:`text-sm font-semibold text-text-primary`,children:`Connection lost`}),(0,V.jsx)(`p`,{className:`text-sm leading-[1.55] text-text-secondary`,children:`Trying to reconnect…`}),(0,V.jsx)(d,{children:(0,V.jsx)(S,{ref:t,variant:`primary`,onClick:e,children:`Reload`})})]})]})}function io(){let[e,t]=(0,B.useState)([]);(0,B.useEffect)(()=>{let e=!1;return(async()=>{try{let n=await O(`/api/notices`);if(!n.ok)return;let r=await n.json();e||t(r.notices??[])}catch{}})(),()=>{e=!0}},[]);let n=(0,B.useCallback)(async e=>{t(t=>t.filter(t=>t.kind!==e));try{await O(`/api/notices/${e}`,{method:`DELETE`})}catch{}},[]);return e.length===0?null:(0,V.jsx)(`div`,{className:`flex flex-col`,children:e.map(e=>(0,V.jsx)(ao,{notice:e,onDismiss:()=>void n(e.kind)},e.kind))})}function ao({notice:e,onDismiss:t}){let n=oo(e);return(0,V.jsxs)(`div`,{role:`status`,className:`flex items-center gap-3 border-b border-border bg-warning/10 px-4 py-2 text-sm text-text-primary`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:`h-2 w-2 shrink-0 rounded-full bg-warning`}),(0,V.jsx)(`p`,{className:`flex-1 leading-snug`,children:n}),(0,V.jsx)(a,{kind:`dismiss`,size:`sm`,onClick:t,children:`Dismiss`})]})}function oo(e){switch(e.kind){case`daemon-auto-restarted`:return`セッションがリセットされました -- parasor が新しいバージョンに更新されたため、走行中だったターミナルセッションは終了しています。`}}var so={toasts:[]},G=new Set,K=new Map,co=0;function lo(){for(let e of G)e()}function uo(e){return G.add(e),()=>{G.delete(e)}}function fo(){return so}function po(e){let t=K.get(e);t&&(clearTimeout(t),K.delete(e))}function mo(e,t){po(e),K.set(e,setTimeout(()=>{go(e)},t))}function ho(e){let t=e.id??`sync-${++co}`,n={id:t,tone:e.tone,title:e.title,...e.sub!==void 0&&{sub:e.sub},...e.mono!==void 0&&{mono:e.mono},...e.actions!==void 0&&{actions:e.actions}},r=so.toasts.findIndex(e=>e.id===t);return so={toasts:r===-1?[...so.toasts,n]:so.toasts.map((e,t)=>t===r?n:e)},e.durationMs===void 0?po(t):mo(t,e.durationMs),lo(),t}function go(e){po(e),so.toasts.some(t=>t.id===e)&&(so={toasts:so.toasts.filter(t=>t.id!==e)},lo())}function _o(){return(0,B.useSyncExternalStore)(uo,fo,()=>so).toasts}var vo={info:`bg-accent`,working:`bg-warning`,ok:`bg-success`,err:`bg-danger`};function yo(){let e=_o();return e.length===0?null:(0,V.jsx)(`section`,{"aria-label":`sync status`,className:`pointer-events-none fixed right-[max(env(safe-area-inset-right,0px),16px)] bottom-[max(env(safe-area-inset-bottom,0px),16px)] z-[55] flex w-[min(var(--spacing-surface-sm),calc(100vw-32px))] flex-col gap-2`,children:e.map(e=>(0,V.jsx)(bo,{toast:e},e.id))})}function bo({toast:e}){return(0,V.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`pointer-events-auto flex items-start gap-2.5 rounded-window border border-border bg-bg-secondary px-3 py-2.5 shadow-[0_8px_24px_rgba(0,0,0,0.35)]`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:`mt-[5px] h-2 w-2 flex-none rounded-tag ${vo[e.tone]} ${e.tone===`working`?`animate-pulse`:``}`}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`text-sm font-semibold tracking-[-0.005em] text-text-primary`,children:e.title}),e.sub&&(0,V.jsx)(`div`,{className:`mt-0.5 text-xs text-text-secondary ${e.mono?`cm-mono`:``}`,children:e.sub}),e.actions&&e.actions.length>0&&(0,V.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:e.actions.map(e=>(0,V.jsx)(a,{kind:e.kind===`primary`?`submit`:`normal`,size:`xs`,onClick:e.onSelect,children:e.label},`${e.kind??`ghost`}:${e.label}`))})]}),(0,V.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,onClick:()=>go(e.id),className:`-m-1 p-1 text-text-secondary hover:text-text-primary`,children:(0,V.jsx)(h.close,{})})]})}function xo({pinned:e,onToggle:t}){return(0,V.jsx)(_,{label:e?`Unpin from Monitor`:`Pin to Monitor`,title:e?`Pinned to Monitor -- click to unpin`:`Pin to Monitor`,size:`md`,tone:e?`accent`:`normal`,pressed:e,onClick:t,children:(0,V.jsx)(h.pin,{})})}function So(e,t,n){let r=new Map;for(let t of e)r.set(t.id,t);let i=t.filter(e=>e.pinned===!0);return i.sort((e,t)=>{let n=r.get(e.projectId)?.name??``,i=r.get(t.projectId)?.name??``;return n===i?e.createdAt-t.createdAt:n.localeCompare(i)}),i.map(e=>{let t=r.get(e.projectId),i=t?n?.[t.id]?.[t.path]?.isRepo!==!1:!0,a=Co(e.cwd,t?.path,i);return{session:e,project:t,worktreeName:a,label:t?`${t.name} / ${a}`:a,crumb:e.cwd}})}function Co(e,t,n){if(t&&e===t)return n?`main`:`root`;let r=e.replace(/\/+$/,``).split(`/`).pop();return r&&r.length>0?r:e}var wo=(function(){let e=typeof document<`u`&&document.createElement(`link`).relList;return e&&e.supports&&e.supports(`modulepreload`)?`modulepreload`:`preload`})(),To=function(e){return`/`+e},Eo={},Do=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=To(t,n),t in Eo)return;Eo[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:wo,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Oo=(0,B.lazy)(()=>Do(async()=>{let{TerminalPane:e}=await import(`./TerminalPane-CjbYzePr.js`);return{TerminalPane:e}},__vite__mapDeps([0])).then(({TerminalPane:e})=>({default:e}))),ko=320,Ao=1200,jo=420,Mo=`parasor:monitor-col-widths`;function No(e){return Number.isNaN(e)?jo:Math.min(Ao,Math.max(ko,Math.round(e)))}function Po(){try{let e=localStorage.getItem(Mo);if(!e)return{};let t=JSON.parse(e);if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`number`&&(n[e]=No(r));return n}catch{return{}}}function Fo(e){try{localStorage.setItem(Mo,JSON.stringify(e))}catch{}}function Io({projects:e,sessions:t,agentStates:n,reviewPendingSessions:r,gitStates:i,attentionDismissed:a,isMobile:o,onToggleDrawer:s,onRestartSession:c,onOpenUrl:l,onTogglePin:u}){let d=(0,B.useMemo)(()=>So(e,t,i),[e,t,i]),f=(0,B.useMemo)(()=>{let e=a??{},t=new Map;for(let i of d){let a=n[i.session.id],o=Ct(a,e)?void 0:a?.lifecycle;t.set(i.session.id,qo(o,r.has(i.session.id)))}return t},[d,n,r,a]),p=(0,B.useMemo)(()=>{let e=0,t=0;for(let n of f.values())n===`attention`?e+=1:n===`working`&&(t+=1);return{attention:e,working:t}},[f]),[m,h]=(0,B.useState)(null),g=(0,B.useMemo)(()=>{if(!m)return 0;let e=d.findIndex(e=>e.session.id===m);return e<0?0:e},[d,m]);return(0,V.jsxs)(`section`,{className:`flex h-full min-h-0 w-full flex-col bg-bg-primary`,children:[(0,V.jsx)(Lo,{attention:p.attention,working:p.working,isMobile:o,onToggleDrawer:s,entries:d,focusedIndex:g,onGoToIndex:e=>{let t=d[Math.max(0,Math.min(d.length-1,e))];t&&h(t.session.id)}}),d.length===0?(0,V.jsx)(Ko,{}):o?(0,V.jsx)(Go,{entries:d,statuses:f,focusedIndex:g,onFocusSession:h,onRestartSession:c,onOpenUrl:l,onTogglePin:u}):(0,V.jsx)(zo,{entries:d,statuses:f,focusedSessionId:m??d[g]?.session.id??null,focusedIndex:g,onFocusSession:h,onRestartSession:c,onOpenUrl:l,onTogglePin:u})]})}function Lo({attention:e,working:t,isMobile:n,onToggleDrawer:r,entries:i,focusedIndex:a,onGoToIndex:o}){let s=i.length;return(0,V.jsxs)(`header`,{className:`flex h-bar shrink-0 items-center gap-2.5 border-b border-border bg-pane-header-bg px-3`,children:[n&&r&&(0,V.jsx)(_,{onClick:r,label:`Go to sessions`,size:`md`,children:(0,V.jsx)(h.menu,{})}),(0,V.jsx)(`span`,{className:`text-sm font-semibold tracking-[-0.005em] text-text-primary`,children:`Monitor`}),(0,V.jsxs)(`div`,{className:`cm-mono flex items-center gap-2 text-sm text-text-secondary`,children:[e>0&&(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,V.jsx)(u,{state:`attention`}),(0,V.jsx)(`span`,{children:e})]}),t>0&&(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,V.jsx)(u,{state:`working`}),(0,V.jsx)(`span`,{children:t})]})]}),(0,V.jsx)(`span`,{className:`flex-1`}),s>0&&(0,V.jsx)(Ro,{entries:i,focusedIndex:a,onGoToIndex:o})]})}function Ro({entries:e,focusedIndex:t,onGoToIndex:n}){let r=e.length,i=t<=0,a=t>=r-1;return(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,V.jsx)(_,{onClick:()=>n(t-1),disabled:i,label:`Previous pinned terminal`,children:(0,V.jsx)(h.back,{})}),(0,V.jsx)(`div`,{className:`flex items-center gap-[5px]`,children:e.map((e,r)=>(0,V.jsx)(`button`,{type:`button`,onClick:()=>n(r),"aria-label":`Go to pinned terminal ${r+1}`,"aria-current":r===t?`true`:void 0,className:`h-[5px] cursor-pointer rounded-control transition-all ${r===t?`w-3.5 bg-accent`:`w-[5px] bg-text-secondary/35 hover:bg-text-secondary/60`}`},e.session.id))}),(0,V.jsx)(_,{onClick:()=>n(t+1),disabled:a,label:`Next pinned terminal`,children:(0,V.jsx)(`span`,{className:`rotate-180 inline-flex`,children:(0,V.jsx)(h.back,{})})})]})}function zo({entries:e,statuses:t,focusedSessionId:n,focusedIndex:r,onFocusSession:i,onRestartSession:a,onOpenUrl:o,onTogglePin:s}){let c=Math.max(0,e.length-3),l=(0,B.useRef)([]);(0,B.useEffect)(()=>{let e=l.current[r];e&&e.scrollIntoView({behavior:`smooth`,inline:`nearest`,block:`nearest`})},[r,n]);let[u,d]=(0,B.useState)(Po);(0,B.useEffect)(()=>{let e=setTimeout(()=>Fo(u),200);return()=>clearTimeout(e)},[u]);let f=(0,B.useCallback)((e,t)=>{d(n=>{let r=No(t);return n[e]===r?n:{...n,[e]:r}})},[]);return(0,V.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`cm-scroll absolute inset-0 flex flex-row items-stretch justify-start overflow-x-auto overflow-y-hidden`,children:e.map((e,r)=>{let c=u[e.session.id]??jo;return(0,V.jsx)(Bo,{ref:e=>{l.current[r]=e},entry:e,status:t.get(e.session.id)??`idle`,focused:n===e.session.id,width:c,onFocus:()=>i(e.session.id),onResize:t=>f(e.session.id,t),onRestartSession:a,onOpenUrl:o,onTogglePin:s},e.session.id)})}),c>0&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute top-0 right-0 bottom-0 w-14`,style:{background:`linear-gradient(to right, transparent, var(--color-bg-primary))`}}),(0,V.jsxs)(`div`,{"aria-hidden":!0,className:`cm-mono pointer-events-none absolute top-2 right-2 rounded-tag border border-border bg-bg-tertiary px-2 py-px text-xs text-text-secondary`,children:[`->`,` `,c,` more`]})]})]})}function Bo({ref:e,entry:t,status:n,focused:r,width:i,onFocus:a,onResize:o,onRestartSession:s,onOpenUrl:c,onTogglePin:l}){let u=`Resize column for ${wt(t.session)}`;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{ref:e,className:`relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border bg-bg-primary`,style:{width:`${i}px`},onPointerDownCapture:a,onFocusCapture:a,children:[(0,V.jsx)(Uo,{entry:t,status:n,onTogglePin:l}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 touch-pan-y`,children:(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`h-full bg-bg-terminal`}),children:(0,V.jsx)(Oo,{paneId:`monitor:${t.session.id}`,sessionId:t.session.id,session:t.session,onRestartSession:s,onOpenUrl:c})})}),r&&(0,V.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 border-2 border-accent`})]}),(0,V.jsx)(Vo,{width:i,onResize:o,ariaLabel:u})]})}function Vo({width:e,onResize:t,ariaLabel:n}){let r=(0,B.useRef)(!1),i=(0,B.useRef)(0),a=(0,B.useRef)(e),o=(0,B.useCallback)(e=>{if(r.current=!1,e)try{e.target.releasePointerCapture(e.pointerId)}catch{}},[]);return(0,V.jsx)(`hr`,{"aria-label":n,"aria-orientation":`vertical`,"aria-valuenow":e,"aria-valuemin":ko,"aria-valuemax":Ao,tabIndex:0,onPointerDown:(0,B.useCallback)(t=>{t.preventDefault(),t.target.setPointerCapture(t.pointerId),r.current=!0,i.current=t.clientX,a.current=e},[e]),onPointerMove:(0,B.useCallback)(e=>{if(r.current){if(e.buttons===0){o(e);return}t(a.current+(e.clientX-i.current))}},[t,o]),onPointerUp:o,onPointerCancel:o,onKeyDown:(0,B.useCallback)(n=>{n.key!==`ArrowLeft`&&n.key!==`ArrowRight`||(n.preventDefault(),t(e+(n.key===`ArrowLeft`?-1:1)*(n.shiftKey?50:10)))},[t,e]),style:{touchAction:`none`},className:`cm-split-resizer relative z-[2] w-px shrink-0 cursor-col-resize bg-border before:absolute before:inset-y-0 before:-inset-x-3 before:content-[''] focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`})}function Ho({entry:e,status:t,onFocus:n,onRestartSession:r,onOpenUrl:i,onTogglePin:a}){return(0,V.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary`,onPointerDownCapture:n,onFocusCapture:n,children:[(0,V.jsx)(Uo,{entry:e,status:t,onTogglePin:a}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 touch-pan-y`,children:(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`h-full bg-bg-terminal`}),children:(0,V.jsx)(Oo,{paneId:`monitor:${e.session.id}`,sessionId:e.session.id,session:e.session,onRestartSession:r,onOpenUrl:i})})})]})}function Uo({entry:e,status:t,onTogglePin:n}){return(0,V.jsxs)(`div`,{className:`flex h-bar shrink-0 items-center gap-2 border-b border-border bg-pane-header-bg px-3`,children:[(0,V.jsx)(Wo,{entry:e}),t!==`idle`&&(0,V.jsx)(u,{state:t}),(0,V.jsx)(xo,{pinned:!0,onToggle:()=>void n(e.session.id)})]})}function Wo({entry:e}){let t=e.project?.name??``,n=e.worktreeName,r=wt(e.session);return(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,V.jsx)(`span`,{className:`cm-mono min-w-0 flex-shrink truncate text-sm text-text-secondary/85`,title:t,children:t}),(0,V.jsx)(`span`,{"aria-hidden":!0,className:`text-text-secondary/40`,children:`/`}),(0,V.jsx)(`span`,{className:`cm-mono min-w-0 flex-shrink truncate text-sm text-text-secondary/85`,title:n,children:n}),(0,V.jsx)(`span`,{"aria-hidden":!0,className:`text-text-secondary/40`,children:`/`}),(0,V.jsx)(`span`,{className:`cm-mono min-w-0 flex-shrink truncate text-sm font-semibold text-text-primary`,title:r,children:r})]})}function Go({entries:e,statuses:t,focusedIndex:n,onFocusSession:r,onRestartSession:i,onOpenUrl:a,onTogglePin:o}){let s=e[n];return s?(0,V.jsx)(`div`,{className:`flex min-h-0 flex-1`,children:(0,V.jsx)(Ho,{entry:s,status:t.get(s.session.id)??`idle`,onFocus:()=>r(s.session.id),onRestartSession:i,onOpenUrl:a,onTogglePin:o})}):null}function Ko(){return(0,V.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center bg-bg-primary p-8 text-center`,children:(0,V.jsxs)(`div`,{className:`max-w-md`,children:[(0,V.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-text-primary`,children:`No pinned terminals yet`}),(0,V.jsxs)(`p`,{className:`cm-mono text-sm leading-relaxed text-text-secondary`,children:[`Tap the`,` `,(0,V.jsx)(`span`,{className:`inline-flex translate-y-[2px] items-center text-accent`,children:(0,V.jsx)(h.pin,{})}),` `,`icon in a terminal header to surface it here. Monitor gives you a live tail of every pinned session across projects at once.`]})]})})}function qo(e,t){return t?`review`:e===`waiting`?`attention`:e===`running`?`working`:`idle`}async function Jo(e){let t=await O(`/api/service-config`,{method:`PATCH`,headers:{"Content-Type":`application/json`},credentials:`same-origin`,body:JSON.stringify(e)});if(!t.ok)throw Error(`Failed to update service config: ${t.status}`)}function Yo(e){let t=Object.keys(e)[0]??`service config`;Jo(e).catch(e=>{console.warn(`Failed to update ${t}:`,e)})}var Xo=`parasor:shell-ratio:workspace`,Zo=24,Qo=240,$o=520,es=45;function ts(e,t){if(!Number.isFinite(e))return Zo;let n=12,r=es;return t&&t>0&&(n=Math.max(n,Qo/t*100),r=Math.min(r,$o/t*100)),Math.min(r,Math.max(n,e))}function ns(){try{let e=localStorage.getItem(Xo);if(!e)return Zo;let t=JSON.parse(e);return typeof t==`number`?ts(t):Zo}catch{return Zo}}function rs(e){try{localStorage.setItem(Xo,JSON.stringify(e))}catch{}}function is({navigation:e,main:t}){let[n,r]=(0,B.useState)(ns),i=(0,B.useRef)(null),a=(0,B.useRef)(!1);(0,B.useEffect)(()=>{rs(n)},[n]);let o=(0,B.useCallback)(e=>{let t=i.current?.getBoundingClientRect().width;r(ts(e,t))},[]),s=(0,B.useMemo)(()=>({width:`${n}%`,minWidth:`${Qo}px`,maxWidth:`${$o}px`}),[n]),c=(0,B.useCallback)(e=>{e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),a.current=!0},[]),l=(0,B.useCallback)(e=>{if(!a.current)return;if(e.buttons===0){a.current=!1;return}let t=i.current?.getBoundingClientRect();t&&o((e.clientX-t.left)/t.width*100)},[o]),u=(0,B.useCallback)(e=>{a.current=!1;try{e.currentTarget.releasePointerCapture?.(e.pointerId)}catch{}},[]),d=(0,B.useCallback)(e=>{if(!(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`&&e.key!==`Home`&&e.key!==`End`)){if(e.preventDefault(),e.key===`Home`){o(0);return}if(e.key===`End`){o(100);return}o(n+(e.key===`ArrowLeft`?-1:1)*(e.shiftKey?5:1))}},[n,o]);return(0,V.jsxs)(`div`,{ref:i,className:`flex h-full min-w-0 flex-1 flex-row overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`min-w-0 overflow-hidden bg-bg-secondary`,style:s,children:e}),(0,V.jsx)(`hr`,{"aria-label":`Resize navigation pane`,"aria-orientation":`vertical`,"aria-valuenow":Math.round(n),"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,onPointerDown:c,onPointerMove:l,onPointerUp:u,onPointerCancel:u,onKeyDown:d,className:`cm-split-resizer relative z-[2] w-px shrink-0 cursor-col-resize bg-border before:absolute before:inset-y-0 before:-inset-x-3 before:content-[''] focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`}),(0,V.jsx)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-1 overflow-hidden`,children:t})]})}function as({paneTitle:t,paneKind:n,onCancel:r,onConfirm:i}){let a=n===`terminal`?`The shell session will terminate.`:`The browser tab state will be lost.`;return(0,V.jsxs)(e,{ariaLabel:`Close ${t}`,confirmLabel:`Close`,confirmVariant:`danger`,onCancel:r,onConfirm:i,children:[`Close `,(0,V.jsx)(`strong`,{children:t}),`? `,a]})}async function os(e){let t=await O(`/api/pane-commands`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({commands:e})});if(!t.ok)throw Error(`Failed to save commands`);return await t.json()}async function ss(e){let t=await O(`/api/ide-commands`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({commands:e})});if(!t.ok)throw Error(`Failed to save IDE commands`);return await t.json()}function cs({projectName:t,onCancel:n,onConfirm:r}){return(0,V.jsxs)(e,{ariaLabel:`Close project ${t}`,confirmLabel:`Close`,confirmVariant:`primary`,onCancel:n,onConfirm:r,children:[`Close `,(0,V.jsx)(`strong`,{children:t}),`? All sessions in this project will terminate and its layout will be cleared. The directory itself will not be deleted.`]})}async function ls(e){let t=await O(`/api/sessions`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectId:e.projectId,...e.command&&{command:e.command},...e.title&&{title:e.title},...e.cwd&&{cwd:e.cwd},...e.bootstrapInput&&{bootstrapInput:e.bootstrapInput}})});return t.ok?await t.json():null}async function us(e){await O(`/api/sessions/${e}/restart`,{method:`POST`})}async function ds(e,t){await O(`/api/sessions/${e}/title`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:t})})}async function fs(e,t){await O(`/api/sessions/${e}/pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pinned:t})})}async function ps(e){await O(`/api/sessions/${e}`,{method:`DELETE`})}var ms=4e3;function hs({activeProjectId:e,playAttentionSound:t,playCompletionSound:n,priorLifecycle:r,projectId:i,state:a}){return!i||i===e||a.confidence!==`high`?null:a.lifecycle===`waiting`?!t||r===`waiting`?null:`attention`:a.lifecycle===`completed`?!n||r===`completed`?null:`completion`:null}function gs({activeProjectId:e,agentStates:t,snapshotApplied:n,playAttentionSound:r,playCompletionSound:i,sessions:a}){let o=(0,B.useRef)(!1),s=(0,B.useRef)({}),c=(0,B.useRef)(new Map),l=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!r&&!i||typeof window>`u`)return;let e=()=>{let e=_s(l);e&&e.state===`suspended`&&e.resume().catch(()=>{})};return window.addEventListener(`pointerdown`,e,{passive:!0}),window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`pointerdown`,e),window.removeEventListener(`keydown`,e)}},[r,i]),(0,B.useEffect)(()=>{let u={};for(let[e,n]of Object.entries(t))u[e]=n.lifecycle;if(!n){s.current=u;return}if(!o.current){o.current=!0,s.current=u;return}let d=new Map(a.map(e=>[e.id,e])),f=Date.now();for(let[n,a]of Object.entries(t)){let t=hs({activeProjectId:e,playAttentionSound:r,playCompletionSound:i,priorLifecycle:s.current[n],projectId:d.get(n)?.projectId??null,state:a});if(!t)continue;let o=`${n}:${t}`;if(f-(c.current.get(o)??0)<ms)continue;let u=_s(l);!u||u.state!==`running`||(vs(u,t),c.current.set(o,f))}s.current=u},[e,t,n,r,i,a])}function _s(e){if(e.current)return e.current;if(typeof window>`u`)return null;let t=window,n=t.AudioContext??t.webkitAudioContext;return n?(e.current=new n,e.current):null}function vs(e,t){let n=e.currentTime+.01;if(t===`attention`){ys(e,n,880,.08,.035),ys(e,n+.14,988,.12,.04);return}ys(e,n,659,.1,.03),ys(e,n+.12,880,.16,.035)}function ys(e,t,n,r,i){let a=e.createOscillator(),o=e.createGain();a.type=`sine`,a.frequency.setValueAtTime(n,t),o.gain.setValueAtTime(1e-4,t),o.gain.exponentialRampToValueAtTime(i,t+.02),o.gain.exponentialRampToValueAtTime(1e-4,t+r),a.connect(o),o.connect(e.destination),a.start(t),a.stop(t+r+.02)}function bs(e){try{return mt(window.localStorage.getItem(ft(e)))}catch{return{}}}function xs(e,t){try{window.localStorage.setItem(ft(e),JSON.stringify(t))}catch{}}function Ss(){return typeof crypto<`u`&&`randomUUID`in crypto?`browser:${crypto.randomUUID()}`:`browser:${Math.random().toString(36).slice(2,10)}-${Date.now()}`}function Cs(e){let[t,n]=(0,B.useState)(()=>e?bs(e):{}),r=(0,B.useRef)(e);(0,B.useEffect)(()=>{r.current!==e&&(r.current=e,n(e?bs(e):{}))},[e]),(0,B.useEffect)(()=>{e&&xs(e,t)},[e,t]);let i=(0,B.useCallback)((t,r)=>{if(!e||!pt(r))return null;let i=Ss();return n(e=>{let n=e[t]??[];return{...e,[t]:[...n,{id:i,url:r}]}}),i},[e]),a=(0,B.useCallback)(e=>{n(t=>{let n={},r=!1;for(let[i,a]of Object.entries(t)){let t=a.filter(t=>t.id!==e);t.length!==a.length&&(r=!0),t.length>0&&(n[i]=t)}return r?n:t})},[]),o=(0,B.useCallback)((e,t)=>{pt(t)&&n(n=>{let r=!1,i={};for(let[a,o]of Object.entries(n))i[a]=o.map(n=>n.id!==e||n.url===t?n:(r=!0,{...n,url:t}));return r?i:n})},[]);return{panesByWorktree:(0,B.useMemo)(()=>t,[t]),addBrowser:i,closeBrowser:a,updateBrowserUrl:o}}function ws({onConfirm:e}){let[t,n]=(0,B.useState)(null);return{target:t,request:(0,B.useCallback)((e,t,r)=>{n({paneId:e,paneKind:t,title:r})},[]),cancel:(0,B.useCallback)(()=>{n(null)},[]),confirm:(0,B.useCallback)(async()=>{let r=t;r&&(n(null),await e(r))},[t,e])}}function Ts(e,t,n){return e===t?n?`main`:`root`:e.replace(/\/+$/,``).split(`/`).pop()??e}function Es({projects:e,gitStates:t}){let[n,r]=(0,B.useState)(null),i=(0,B.useCallback)((e,t)=>{r({projectId:e,worktreeId:t,worktreePath:t.startsWith(`wt:`)?t.slice(3):t})},[]),a=(0,B.useCallback)(()=>{r(null)},[]);return{target:n,context:(0,B.useMemo)(()=>{if(!n)return null;let r=e.find(e=>e.id===n.projectId);if(!r)return null;let i=t[r.id]?.[r.path]?.isRepo!==!1,a=Ts(n.worktreePath,r.path,i);return{project:{id:r.id,name:r.name,path:r.path},worktree:{id:n.worktreeId,name:a,path:n.worktreePath}}},[n,e,t]),open:i,close:a}}function Ds(e=5e3){let[t,n]=(0,B.useState)(null);return(0,B.useEffect)(()=>{if(!t)return;let r=window.setTimeout(()=>n(null),e);return()=>window.clearTimeout(r)},[t,e]),[t,n]}function Os(e){let[t,n]=(0,B.useState)(null),r=(0,B.useRef)(e);return(0,B.useEffect)(()=>{r.current!==e&&(r.current=e,n(null))},[e]),[t,n]}var ks=class extends Error{constructor(e,t){super(e),this.status=t,this.name=`GitOperationError`}};async function As(e,t){await js(e,`POST`,t)}async function js(e,t,n){let r=await O(e,{method:t,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok)throw new ks((await r.json().catch(()=>({}))).error??`Request failed (${r.status})`,r.status)}async function Ms(e,t){let n=`worktreePath=${encodeURIComponent(e.worktreePath)}`,r=`/api/projects/${encodeURIComponent(e.projectId)}/diff`,i=await O(e.sha?`${r}?sha=${encodeURIComponent(e.sha)}&${n}`:`${r}?${n}`,{signal:t});return i.ok?(await i.json()).diff:null}function Ns(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/commit`,{worktreePath:e.worktreePath,message:e.message,paths:e.paths})}function Ps(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/push`,{worktreePath:e.worktreePath,...e.setUpstream===!0&&{setUpstream:!0}})}function Fs(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/pull`,{worktreePath:e.worktreePath,...e.rebase===!0&&{rebase:!0}})}function Is(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/fetch`,{worktreePath:e.worktreePath})}function Ls(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/switch`,{worktreePath:e.worktreePath,branch:e.branch})}function Rs(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/branch`,{worktreePath:e.worktreePath,branch:e.branch,startPoint:e.startPoint})}async function zs(e){let t=new URLSearchParams({worktreePath:e.worktreePath});e.limit!==void 0&&t.set(`limit`,String(e.limit)),e.skip!==void 0&&e.skip>0&&t.set(`skip`,String(e.skip)),e.includeRemotes&&t.set(`includeRemotes`,`1`);let n=await O(`/api/projects/${encodeURIComponent(e.projectId)}/git/log?${t.toString()}`,{signal:e.signal});if(!n.ok)throw new ks((await n.json().catch(()=>({}))).error??`Request failed (${n.status})`,n.status);return await n.json()}function Bs(e){return As(`/api/projects/${encodeURIComponent(e)}/git/init`,{})}function Vs(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees/open-os`,{worktreePath:e.worktreePath})}async function Hs(){let e=await O(`/api/projects/local-ide-capability`);if(!e.ok)throw new ks((await e.json().catch(()=>({}))).error??`Request failed (${e.status})`,e.status);return{canOpenLocalIde:(await e.json()).canOpenLocalIde===!0}}function Us(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees/open-ide`,{worktreePath:e.worktreePath,editor:e.editor})}function Ws(e){return js(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees`,`PATCH`,{worktreePath:e.worktreePath,newBranch:e.newBranch})}function Gs(e){return js(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees`,`DELETE`,{worktreePath:e.worktreePath,...e.force===!0&&{force:!0}})}function Ks({activeProjectId:e,focusedWorktreePath:t,focusedWorktreeName:n,gitState:r}){let[i,a]=(0,B.useState)(null),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(null),u=r?.ahead??0,d=r?.behind??0,f=r?.branch??n??null,p=(0,B.useRef)(null),m=(0,B.useCallback)(()=>{o||(a(null),l(null))},[o]),h=(0,B.useCallback)(async function(e,t,n,r){s(!0),l(null);try{return await Ns({projectId:e,worktreePath:t,message:r.message,paths:r.paths}),ho({tone:`ok`,title:`Commit created`,sub:`${n??`branch`} · ${r.paths.length} file${r.paths.length===1?``:`s`}`,mono:!0,durationMs:4e3}),!0}catch(e){return l(e instanceof ks||e instanceof Error?e.message:`Commit failed`),!1}finally{s(!1)}},[]),g=(0,B.useCallback)(async e=>{i&&await h(i.projectId,i.worktreePath,i.branchName,e)&&a(null)},[i,h]),_=(0,B.useCallback)(async n=>{!e||!t||await h(e,t,f,n)},[e,t,f,h]),v=(0,B.useCallback)(()=>{l(null)},[]),y=(0,B.useCallback)(n=>{if(!e||!t)return;let r=f??`branch`,i=`git-push:${t}`;ho({id:i,tone:`working`,title:`Pushing ${r}`,sub:u>0?`origin · ${u} commit${u===1?``:`s`}`:`origin`,mono:!0}),Ps({projectId:e,worktreePath:t,...n?.setUpstream===!0&&{setUpstream:!0}}).then(()=>{ho({id:i,tone:`ok`,title:`Push complete`,sub:`${r} · pushed to origin`,mono:!0,durationMs:4e3})}).catch(e=>{let t=e instanceof ks||e instanceof Error?e.message:`Push failed`,n=/non-fast-forward|rejected/i.test(t);ho({id:i,tone:`err`,title:n?`Push rejected -- non-fast-forward`:`Push failed`,sub:t,actions:n?[{label:`Pull --rebase`,kind:`primary`,onSelect:()=>{go(i),p.current?.({rebase:!0})}},{label:`Dismiss`,onSelect:()=>go(i)}]:[{label:`Dismiss`,onSelect:()=>go(i)}]})})},[e,t,f,u]),b=(0,B.useCallback)(n=>{if(!e||!t)return;let r=f??`branch`,i=`git-pull:${t}`;ho({id:i,tone:`working`,title:`Pulling ${r}`,sub:d>0?`origin · ${d} commit${d===1?``:`s`}`:`origin`,mono:!0}),Fs({projectId:e,worktreePath:t,...n?.rebase===!0&&{rebase:!0}}).then(()=>{ho({id:i,tone:`ok`,title:`Up to date`,sub:`${r} · pulled from origin`,mono:!0,durationMs:4e3})}).catch(e=>{ho({id:i,tone:`err`,title:`Pull failed`,sub:e instanceof ks||e instanceof Error?e.message:`Pull failed`,actions:[{label:`Dismiss`,onSelect:()=>go(i)}]})})},[e,t,f,d]);return p.current=b,{commitDialog:i,commitBusy:o,commitError:c,closeCommitDialog:m,submitCommit:g,submitInlineCommit:_,clearCommitError:v,fetch:(0,B.useCallback)(()=>{if(!e||!t)return;let n=`git-fetch:${t}`;ho({id:n,tone:`working`,title:`Fetching origin`,sub:f??void 0,mono:!0}),Is({projectId:e,worktreePath:t}).then(()=>{ho({id:n,tone:`ok`,title:`Fetched origin`,mono:!0,durationMs:3e3})}).catch(e=>{ho({id:n,tone:`err`,title:`Fetch failed`,sub:e instanceof ks||e instanceof Error?e.message:`Fetch failed`,actions:[{label:`Dismiss`,onSelect:()=>go(n)}]})})},[e,t,f]),pull:b,push:y}}var qs=`parasor:pane-commands`,Js=64*1024,Ys={id:`builtin:terminal`,label:`Terminal`,initialInput:``,builtin:!0};function Xs(e){return[Ys,...e.map(e=>({...e,builtin:!1}))]}function Zs(e){if(!e||e.length>Js)return[];let t;try{t=JSON.parse(e)}catch{return[]}return Ce(t)}function Qs(e){return Zs(e.getItem(qs))}function $s({hydrated:e,paneCommandsCount:t,onMigrate:n}){let r=(0,B.useRef)(!1);(0,B.useEffect)(()=>{if(r.current||!e||t>0)return;r.current=!0;let i=[];try{i=Qs(window.localStorage)}catch{return}i.length>0&&n(i)},[e,t,n])}function ec(){let[e,t]=(0,B.useState)(null);(0,B.useEffect)(()=>{let e=!1;return Hs().then(n=>{e||t(n.canOpenLocalIde)}).catch(()=>{e||t(null)}),()=>{e=!0}},[]);let n=typeof window<`u`&&oe(window.location.hostname);return{capability:e,canOpenLocalIde:e??n}}function tc(){let e=Promise.resolve();return t=>{let n=e.catch(()=>void 0).then(()=>t());return e=n,n}}function nc({onError:e}){let[t,n]=(0,B.useState)(0),[r,i]=(0,B.useState)(0),a=(0,B.useRef)(tc());return{reorderResetSignal:t,pendingProjectReorderCount:r,reorder:(0,B.useCallback)(async t=>{i(e=>e+1);try{await a.current(async()=>{let r=!1;try{(await O(`/api/projects/order`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({ids:t})})).ok||(r=!0)}catch(e){if(e instanceof b)return;r=!0}r&&(n(e=>e+1),e(`Failed to reorder projects -- reverted to previous order.`))})}finally{i(e=>Math.max(0,e-1))}},[e])}}function rc({activeProjectId:e,agentStates:t,sessions:n}){let[r,i]=(0,B.useState)(()=>new Set),a=(0,B.useRef)({});return(0,B.useEffect)(()=>{let o=a.current,s={},c=new Set,l=new Set,u=!1,d=new Set(n.map(e=>e.id));for(let[r,i]of Object.entries(t)){s[r]=i.lifecycle;let t=o[r];if(t===i.lifecycle)continue;let a=n.find(e=>e.id===r)?.projectId;i.lifecycle===`completed`&&t!==`completed`&&a&&a!==e?(c.add(r),u=!0):(i.lifecycle===`running`||i.lifecycle===`waiting`)&&(l.add(r),u=!0)}a.current=s,(u||r.size>0)&&i(e=>{let t=new Set(e);for(let n of e)d.has(n)||t.delete(n);for(let e of l)t.delete(e);for(let e of c)t.add(e);return t})},[e,t,r.size,n]),(0,B.useEffect)(()=>{e&&i(t=>{if(t.size===0)return t;let r=new Set(t),i=!1;for(let a of t)n.find(e=>e.id===a)?.projectId===e&&(r.delete(a),i=!0);return i?r:t})},[e,n]),r}function ic({isMobile:e,onMobileOpenShortcut:t}){let[n,r]=(0,B.useState)(!1),[i,a]=(0,B.useState)(``);return(0,B.useEffect)(()=>{function n(n){!(n.metaKey||n.ctrlKey)||n.key.toLowerCase()!==`k`||n.altKey||n.shiftKey||(n.preventDefault(),r(n=>n?(a(``),!1):(e&&t?.(),!0)))}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),{open:n,query:i,setQuery:a,toggle:(0,B.useCallback)(()=>{r(e=>e?(a(``),!1):!0)},[]),close:(0,B.useCallback)(()=>{r(!1),a(``)},[])}}function ac({projectId:e,projectPath:t,worktrees:n,sessions:r,focusedPaneId:i,clientBrowserPanes:a}){return(0,B.useMemo)(()=>{if(!e||!t)return{worktrees:[],allPanes:[],paneById:new Map,focusedPane:null,effectiveFocusedPaneId:null};let o=r.filter(t=>t.projectId===e),s=oc(n,t,o),c=s.map(e=>({path:e,panes:[]}));for(let e of o){let n=sc(e.cwd,s,t),r=c.find(e=>e.path===n);r&&r.panes.push(je(De(e.id),n,e.id))}if(a)for(let e of c){let t=a[e.path];if(t)for(let n of t)e.panes.push(Me(n.id,e.path,n.url))}for(let e of c)e.panes=Ne(Pe(e.path,e.panes));let l=c.flatMap(e=>e.panes),u=new Map(l.map(e=>[e.id,e])),d=u.get(Te(t))??l[0]??null,f=(i?u.get(i)??null:null)??d;return{worktrees:c,allPanes:l,paneById:u,focusedPane:f,effectiveFocusedPaneId:f?.id??null}},[e,t,n,r,i,a])}function oc(e,t,n){let r=e.length>0?[...e]:[{path:t,head:``,branch:null,ahead:0,behind:0,dirtyCount:0}];r.sort((e,n)=>e.path===t?-1:+(n.path===t));let i=r.map(e=>e.path);for(let e of n)cc(e.cwd,i)||i.includes(e.cwd)||i.push(e.cwd);return i}function sc(e,t,n){return cc(e,t)||(t.includes(e)||!e.startsWith(`${n}/`)?e:n)}function cc(e,t){return t.filter(t=>e===t||e.startsWith(`${t}/`)).sort((e,t)=>t.length-e.length)[0]??null}var lc=`parasor:preferences`;function uc(){try{let e=localStorage.getItem(lc);return e?JSON.parse(e):{}}catch{return{}}}function dc(e){try{localStorage.setItem(lc,JSON.stringify(e))}catch{}}function fc(){let e=(0,B.useMemo)(uc,[]),[t,n]=(0,B.useState)(()=>Vt(e.sidebarWidth??256)),[r,i]=(0,B.useState)(e.focusedProjectId??null),[a,o]=(0,B.useState)(e.focusedPaneId??null),s=(0,B.useCallback)(e=>{n(t=>Bt(typeof e==`function`?e(t):e))},[]);return(0,B.useEffect)(()=>{dc({sidebarWidth:t,focusedProjectId:r,focusedPaneId:a})},[t,r,a]),{activeProjectId:r,focusedPaneId:a,setActiveProjectId:i,setFocusedPaneId:o,setSidebarWidth:s,sidebarWidth:t}}function pc({activeProjectId:e,projects:t,setActiveProjectId:n,seedProject:r}){let i=(0,B.useCallback)(async(e,t)=>{let i=await O(`/api/projects`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e,name:t})});if(i.ok){let e=await i.json();r?.(e),n(e.id)}},[r,n]),a=(0,B.useCallback)(async(e,t)=>{await O(`/api/projects/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})})},[]);return{createProject:i,deleteProject:(0,B.useCallback)(async r=>{await O(`/api/projects/${r}?force=true`,{method:`DELETE`}),e===r&&n(t.find(e=>e.id!==r)?.id??null)},[e,t,n]),pinProject:(0,B.useCallback)(async e=>{let n=t.find(t=>t.id===e);n&&await O(`/api/projects/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pinned:!n.pinned})})},[t]),renameProject:a,toggleProjectReadOnly:(0,B.useCallback)(async e=>{let n=t.find(t=>t.id===e);n&&await O(`/api/projects/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({readOnly:!n.readOnly})})},[t])}}function mc(e){let t=gc(e.pathname);if(t===`/`||t===``)return{kind:`root`};if(t===`/monitor`)return{kind:`monitor`};let n=_c(t,`/sessions/`);if(n!==null)return{kind:`session`,sessionId:n};let r=_c(t,`/panes/`);if(r!==null)return{kind:`pane`,paneId:r,projectId:new URLSearchParams(e.search).get(`project`)??void 0};if(t===`/worktree`){let t=new URLSearchParams(e.search),n=t.get(`project`),r=t.get(`path`),i=t.get(`tab`)===`git`?`git`:`files`;if(n&&r)return{kind:`worktree`,projectId:n,worktreePath:r,tab:i}}return{kind:`root`}}function hc(e){switch(e.kind){case`root`:return`/`;case`monitor`:return`/monitor`;case`session`:return`/sessions/${encodeURIComponent(e.sessionId)}`;case`pane`:{let t=e.projectId?`?project=${encodeURIComponent(e.projectId)}`:``;return`/panes/${encodeURIComponent(e.paneId)}${t}`}case`worktree`:return`/worktree?${new URLSearchParams({project:e.projectId,path:e.worktreePath,tab:e.tab}).toString()}`}}function gc(e){return e.length>1&&e.endsWith(`/`)?e.replace(/\/+$/,``):e}function _c(e,t){if(!e.startsWith(t))return null;let n=e.slice(t.length);if(!n||n.includes(`/`))return null;try{return decodeURIComponent(n)}catch{return null}}function vc(){let[e,t]=(0,B.useState)(()=>mc(window.location));return(0,B.useEffect)(()=>{let e=()=>t(mc(window.location));return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]),{navigate:(0,B.useCallback)((e,n)=>{let r=hc(e);r!==`${window.location.pathname}${window.location.search}`&&(n?.replace?window.history.replaceState(null,``,r):window.history.pushState(null,``,r)),t(e)},[]),route:e}}function yc({activeProjectId:e,connected:t,projects:n,setActiveProjectId:r}){(0,B.useEffect)(()=>{!e&&n.length>0?r(n[0].id):t&&e&&!n.some(t=>t.id===e)&&r(n[0]?.id??null)},[e,t,n,r])}var bc=`parasor:layout`;function xc(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName;return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}function Sc(e){return[...e].sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:t.lastAccessedAt-e.lastAccessedAt)}function Cc({activeProjectId:e,projects:t,setActiveProjectId:n}){let[r,i]=(0,B.useState)(!1),a=ne(`(max-width: 767px)`),o=(0,B.useCallback)(()=>{i(!0)},[]),s=(0,B.useCallback)(()=>{i(!1)},[]);return(0,B.useEffect)(()=>{localStorage.removeItem(bc)},[]),(0,B.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`,`){e.preventDefault(),i(e=>!e);return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&/^[1-9]$/.test(e.key)&&!xc(e.target)){let r=Sc(t)[Number(e.key)-1];r&&(e.preventDefault(),n(r.id))}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t,n]),{closeSettings:s,isMobile:a,openSettings:o,settingsOpen:r}}function wc(){let[e,t]=(0,B.useState)(null),[n,r]=(0,B.useState)(!1),[i,a]=(0,B.useState)(null),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(null);return{renameDialog:e,renameBusy:n,renameError:i,openRenameDialog:(0,B.useCallback)(e=>{a(null),t(e)},[]),closeRenameDialog:(0,B.useCallback)(()=>{n||(t(null),a(null))},[n]),submitRename:(0,B.useCallback)(async n=>{let i=e;if(i){r(!0),a(null);try{await Ws({projectId:i.projectId,worktreePath:i.worktreePath,newBranch:n}),ho({tone:`ok`,title:`Branch renamed`,sub:`${i.currentBranch} -> ${n}`,mono:!0,durationMs:3e3}),t(null)}catch(e){a(e instanceof ks||e instanceof Error?e.message:`Rename failed`)}finally{r(!1)}}},[e]),removeDialog:o,removeBusy:c,removeError:u,openRemoveDialog:(0,B.useCallback)(e=>{d(null),s(e)},[]),closeRemoveDialog:(0,B.useCallback)(()=>{c||(s(null),d(null))},[c]),submitRemove:(0,B.useCallback)(async({force:e})=>{let t=o;if(t){l(!0),d(null);try{await Gs({projectId:t.projectId,worktreePath:t.worktreePath,...e===!0&&{force:!0}}),ho({tone:`ok`,title:`Worktree removed`,sub:t.branch,mono:!0,durationMs:3e3}),s(null)}catch(e){d(e instanceof ks||e instanceof Error?e.message:`Remove failed`)}finally{l(!1)}}},[o]),copyWorktreePath:(0,B.useCallback)(e=>{Tc(e).then(e=>{Qa(e?`Copied path`:`Copy failed`)}).catch(()=>{Qa(`Copy failed`)})},[]),openWorktreeInFinder:(0,B.useCallback)(({projectId:e,worktreePath:t})=>{let n=`open-os:${t}`;ho({id:n,tone:`working`,title:`Opening in file manager`,sub:t,mono:!0}),Vs({projectId:e,worktreePath:t}).then(()=>{go(n)}).catch(e=>{ho({id:n,tone:`err`,title:`Could not open in file manager`,sub:e instanceof ks||e instanceof Error?e.message:`Open failed`,actions:[{label:`Dismiss`,onSelect:()=>go(n)}]})})},[]),openWorktreeInIde:(0,B.useCallback)(({projectId:e,worktreePath:t,editor:n})=>{let r=n===`cursor`?`Cursor`:`VS Code`,i=`open-ide:${n}:${t}`;ho({id:i,tone:`working`,title:`Opening in ${r}`,sub:t,mono:!0}),Us({projectId:e,worktreePath:t,editor:n}).then(()=>{go(i)}).catch(e=>{let t=e instanceof ks||e instanceof Error?e.message:`Open failed`;ho({id:i,tone:`err`,title:`Could not open in ${r}`,sub:t,actions:[{label:`Dismiss`,onSelect:()=>go(i)}]})})},[])}}async function Tc(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0;let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}var Ec=16,Dc=24,Oc=40;function kc(e){(0,B.useEffect)(()=>{if(!e)return;let t=null,n=!1;function r(e){if(e.touches.length!==1){t=null,n=!1;return}let r=e.touches[0];if(r.clientX>Ec){t=null,n=!1;return}t={x:r.clientX,y:r.clientY},n=!0}function i(e){if(!n||!t)return;if(e.touches.length!==1){n=!1,t=null;return}let r=e.touches[0];Math.abs(r.clientY-t.y)>Oc&&(n=!1,t=null)}function a(r){if(!n||!t){n=!1,t=null;return}let i=r.changedTouches[0],a=i?i.clientX-t.x:0,o=i?Math.abs(i.clientY-t.y):0;n=!1,t=null,a>=Dc&&o<=Oc&&e?.()}function o(){n=!1,t=null}return window.addEventListener(`touchstart`,r,{passive:!0}),window.addEventListener(`touchmove`,i,{passive:!0}),window.addEventListener(`touchend`,a,{passive:!0}),window.addEventListener(`touchcancel`,o,{passive:!0}),()=>{window.removeEventListener(`touchstart`,r),window.removeEventListener(`touchmove`,i),window.removeEventListener(`touchend`,a),window.removeEventListener(`touchcancel`,o)}},[e])}var Ac=`about:blank`;function jc(e){return e===Ac?``:e}function Mc({url:e,onUrlChange:t,paneId:n,headerActions:r}){let[i,a]=(0,B.useState)(jc(e)),[o,s]=(0,B.useState)(e),c=(0,B.useRef)(null);(0,B.useEffect)(()=>{s(e),a(jc(e))},[e]),le(n,(0,B.useCallback)(()=>{c.current?.contentWindow?.focus()},[]),!de());function l(e){let n=e.trim();if(n===``){a(jc(o));return}n===Ac?n=Ac:/^https?:\/\//i.test(n)||(n=`https://${n}`),s(n),a(jc(n)),t?.(n)}function u(e){e.preventDefault(),l(i)}return(0,V.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,V.jsxs)(`form`,{onSubmit:u,"aria-label":`Browser address bar`,className:`flex items-center gap-2 border-b border-border bg-bg-primary px-2 py-1`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>c.current?.contentWindow?.history.back(),"aria-label":`Browser back`,className:`text-text-secondary hover:text-text-primary text-sm px-1`,title:`Back`,children:`←`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>c.current?.contentWindow?.history.forward(),"aria-label":`Browser forward`,className:`text-text-secondary hover:text-text-primary text-sm px-1`,title:`Forward`,children:`->`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>c.current?.contentWindow?.location.reload(),"aria-label":`Browser reload`,className:`text-text-secondary hover:text-text-primary text-sm px-1`,title:`Reload`,children:`↻`}),(0,V.jsx)(`input`,{type:`text`,"aria-label":`URL`,value:i,onChange:e=>a(e.target.value),className:`flex-1 rounded-control bg-bg-primary px-2 py-1 text-xs text-text-primary outline-none focus:ring-1 focus:ring-accent`,placeholder:`URL`}),r]}),(0,V.jsx)(`iframe`,{ref:c,src:o,className:`flex-1 border-none bg-white`,sandbox:`allow-same-origin allow-scripts allow-forms allow-popups`,title:`Browser`})]})}function Nc({onClick:e}){return(0,V.jsx)(_,{label:`Close pane`,title:`Close pane`,size:`md`,tone:`danger`,onClick:e,children:(0,V.jsx)(h.close,{})})}function Pc({state:e,onUrlChange:t,paneId:n,onClose:r}){return(0,V.jsx)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(Mc,{url:e.url,onUrlChange:t,paneId:n,headerActions:r?(0,V.jsx)(Nc,{onClick:r}):null})})})}var Fc=class extends Error{constructor(){super(`upload aborted`),this.name=`FileUploadAbortedError`}},Ic=class extends Error{limit;constructor(e){super(`upload exceeds size limit`),this.name=`FileUploadTooLargeError`,this.limit=e}},Lc=class extends Error{reason;constructor(e){super(`invalid filename: ${e}`),this.name=`FileUploadInvalidFilenameError`,this.reason=e}},Rc=class extends Error{reason;constructor(e){super(`invalid target: ${e}`),this.name=`FileUploadInvalidTargetError`,this.reason=e}},zc=class extends Error{constructor(){super(`project is read-only`),this.name=`FileUploadReadOnlyError`}},Bc=class extends Error{constructor(e){super(e),this.name=`FileUploadIoError`}},Vc=class extends Error{conflicts;constructor(e){super(`conflict: ${e.join(`, `)}`),this.name=`FileUploadConflictError`,this.conflicts=[...e]}};async function Hc(e){let{projectId:t,targetPath:n,files:r,disposition:i,signal:a,onSlow:o,slowMs:s=300}=e;if(r.length===0)return[];let c=new FormData;for(let e of r)c.append(`files`,e,e.name);let l=new URLSearchParams;n&&l.set(`path`,n),i&&l.set(`disposition`,i);let u=l.toString(),d=`/api/projects/${encodeURIComponent(t)}/files/upload`+(u?`?${u}`:``),f=null;o&&(f=setTimeout(o,s));let p;try{let e={method:`POST`,body:c};a&&(e.signal=a),p=await O(d,e)}catch(e){throw f!==null&&clearTimeout(f),e instanceof DOMException&&e.name===`AbortError`?new Fc:e}finally{f!==null&&clearTimeout(f)}if(p.ok)return(await p.json()).files;let m=await p.json().catch(()=>({}));if(m&&`error`in m){if(m.error===`conflict`)throw new Vc(Array.isArray(m.conflicts)?m.conflicts:[]);if(m.error===`too-large`)throw new Ic(typeof m.limit==`number`?m.limit:0);if(m.error===`invalid-filename`)throw new Lc(m.reason??`control-char`);if(m.error===`invalid-target`)throw new Rc(m.reason??`missing`);if(m.error===`read-only`)throw new zc;if(m.error===`io-error`)throw new Bc(`io error`)}throw new Bc(`upload failed: HTTP ${p.status}`)}var Uc=800;function Wc(e){let{projectId:t,resolveTargetForRow:n,onAutoExpand:r,expandedPaths:i,onUploaded:a}=e,o=(0,B.useRef)(0),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(null),[h,g]=(0,B.useState)(null),_=(0,B.useRef)(null),v=(0,B.useRef)(null),y=(0,B.useCallback)(()=>{_.current&&=(clearTimeout(_.current),null),v.current=null},[]);(0,B.useEffect)(()=>()=>y(),[y]);let b=(0,B.useMemo)(()=>s?n(l===null?null:{path:l,isDirectory:x.current}):null,[l,s,n]),x=(0,B.useRef)(!1),S=(0,B.useCallback)(async(e,n)=>{f(!0),g(null);try{return await Hc({projectId:t,targetPath:e.targetPath,files:e.files,...n?{disposition:n}:{}})}catch(t){return t instanceof Vc?(m({...e,conflicts:t.conflicts}),null):t instanceof zc?(g({kind:`read-only`}),null):t instanceof Ic?(g({kind:`too-large`,limit:t.limit}),null):t instanceof Lc?(g({kind:`invalid-filename`,reason:t.reason}),null):t instanceof Rc?(g({kind:`invalid-target`,reason:t.reason}),null):t instanceof Bc?(g({kind:`io`}),null):(console.error(`[file-uploads] unexpected error`,t),g({kind:`io`}),null)}finally{f(!1)}},[t]),C=(0,B.useCallback)((e,t)=>{g({kind:`success`,count:e,targetLabel:t}),a()},[a]),w=e=>{R(e.dataTransfer)&&(e.preventDefault(),o.current+=1,s||c(!0))},T=e=>{R(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))},E=e=>{R(e.dataTransfer)&&(e.preventDefault(),o.current=Math.max(0,o.current-1),o.current===0&&(c(!1),u(null),x.current=!1,y()))},D=e=>{if(!R(e.dataTransfer))return;e.preventDefault();let t=e.dataTransfer;o.current=0,c(!1),y();let r=[];if(t)for(let e=0;e<t.files.length;e++){let n=t.files.item(e);n&&r.push(n)}if(r.length===0){u(null),x.current=!1;return}let i=n(l?{path:l,isDirectory:x.current}:null);u(null),x.current=!1,(async()=>{let e=await S({files:r,targetPath:i},void 0);e&&C(e.filter(e=>e.status!==`skipped`).length,i||`.`)})()},O=(0,B.useCallback)(e=>({onDragEnter:t=>{R(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),u(e.path),x.current=e.isDirectory,e.isDirectory&&!e.isExpanded?v.current!==e.path&&(y(),v.current=e.path,_.current=setTimeout(()=>{v.current===e.path&&(r(e.path),_.current=null,v.current=null)},Uc)):y())},onDragLeave:t=>{R(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),v.current===e.path&&y())}}),[r,y]),k=(0,B.useCallback)(()=>g(null),[]),ee=(0,B.useCallback)(()=>{m(null)},[]),A=(0,B.useCallback)((e,t)=>{let n=p;m(null),n&&(async()=>{let t=await S({files:n.files,targetPath:n.targetPath},e);t&&C(t.filter(e=>e.status!==`skipped`).length,n.targetPath||`.`)})()},[p,S,C]);return{rootHandlers:{onDragEnter:w,onDragOver:T,onDragLeave:E,onDrop:D},getRowHandlers:O,hoveredRowPath:l,targetPath:b,isDragging:s,uploading:d,conflict:p,message:h,dismissMessage:k,resolveConflict:A,cancelConflict:ee}}var Gc={M:`text-yellow-400`,A:`text-green-400`,D:`text-red-400`,R:`text-blue-400`,"?":`text-neutral-400`},Kc={D:4,M:3,A:2,R:1,"?":0};function qc(e){return Gc[e]??`text-neutral-400`}function Jc(e,t){let n=e===`.`?``:`${e}/`,r=null,i=-1;for(let[e,a]of Object.entries(t))if(e.startsWith(n)){let e=Kc[a]??0;if(e>i&&(r=a,i=e),i>=4)break}return r}function Yc(e,t){if(t===`directory`)return{base:e,ext:``};let n=e.lastIndexOf(`.`);return n<=0?{base:e,ext:``}:{base:e.slice(0,n),ext:e.slice(n)}}function Xc(e,t,n){return`${e}${n===1?` copy`:` copy ${n}`}${t}`}function Zc(e,t,n){let r=new Set(n),{base:i,ext:a}=Yc(e,t);for(let e=1;e<1e3;e+=1){let t=Xc(i,a,e);if(!r.has(t))return t}return Xc(i,a,Date.now())}async function Qc(e){try{await navigator.clipboard.writeText(e)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t)}}function $c({entry:e,projectPath:n,x:r,y:i,onClose:a,onDuplicate:o}){let s=`ontouchstart`in window,c=!s,l=!!n&&I(),u=[{id:`copy-path`,label:`Copy Path`,onSelect:()=>Qc(e.path)},{id:`copy-at-path`,label:`Copy as @path`,onSelect:()=>Qc(`@${e.path}`)}];if(l&&n){let t=`${n.replace(/\/+$/,``)}/${e.path}`;u.push({id:`insert-path`,label:`Insert path into terminal`,onSelect:()=>fe(L(t))})}return o&&u.push({id:`duplicate`,label:`Duplicate`,onSelect:()=>o(e)}),c&&u.push({id:`reveal-finder`,label:`Reveal in Finder`,separatorBefore:!0,onSelect:()=>Qc(e.path)}),s?(0,V.jsx)(ee,{open:!0,onDismiss:a,ariaLabel:`Actions for ${e.name}`,title:e.path,items:u}):(0,V.jsx)(t,{open:!0,anchorPoint:{x:r,y:i},items:u,onClose:a})}function el({open:e,conflicts:t,totalCount:n,targetLabel:r,onResolve:i,onCancel:a}){let[o,s]=(0,B.useState)(!0),c=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(e){s(!0);let e=requestAnimationFrame(()=>c.current?.focus());return()=>cancelAnimationFrame(e)}},[e]);let l=t.length,u=Math.max(0,n-l);return(0,V.jsxs)(m,{open:e,ariaLabel:`Resolve upload conflict`,onClose:a,children:[(0,V.jsx)(f,{title:`Files already exist`,onClose:a}),(0,V.jsxs)(`div`,{className:`px-4 py-3 text-sm text-text-primary`,children:[(0,V.jsxs)(`p`,{className:`mb-2 text-text-secondary`,children:[(0,V.jsx)(`span`,{className:`font-medium text-text-primary`,children:l}),` `,`of `,(0,V.jsx)(`span`,{className:`font-medium`,children:n}),` `,n===1?`file already exists`:`files already exist`,` `,`in`,` `,(0,V.jsx)(`code`,{className:`rounded-control bg-bg-primary px-1 text-xs`,children:r||`.`}),`.`]}),(0,V.jsx)(`ul`,{className:`mb-3 max-h-32 overflow-y-auto rounded-control border border-border bg-bg-primary px-2 py-1 text-xs text-text-secondary`,children:t.map(e=>(0,V.jsx)(`li`,{className:`truncate`,children:e},e))}),u>0?(0,V.jsxs)(`p`,{className:`mb-2 text-xs text-text-secondary`,children:[u,` other file`,u===1?``:`s`,` will follow your chosen action.`]}):null,(0,V.jsxs)(`label`,{className:`mt-1 flex items-center gap-2 text-xs text-text-secondary`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`accent-accent`}),`Apply to all files in this drop`]})]}),(0,V.jsx)(`div`,{className:`border-t border-border px-4 py-3`,children:(0,V.jsxs)(d,{children:[(0,V.jsx)(S,{onClick:a,children:`Cancel`}),(0,V.jsx)(S,{onClick:()=>i(`skip`,o),children:`Skip`}),(0,V.jsx)(S,{ref:c,variant:`primary`,onClick:()=>i(`keep-both`,o),children:`Keep both`}),(0,V.jsx)(S,{variant:`danger`,onClick:()=>i(`replace`,o),children:`Replace`})]})})]})}function tl(){return(0,V.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":!0,children:(0,V.jsx)(`path`,{d:`M5.7 4.3a1 1 0 0 1 1.4 0l3 3a1 1 0 0 1 0 1.4l-3 3a1 1 0 0 1-1.4-1.4L8 8 5.7 5.7a1 1 0 0 1 0-1.4Z`})})}function nl(){return(0,V.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":!0,children:(0,V.jsx)(`path`,{d:`M3.3 5.7a1 1 0 0 1 1.4 0L8 9l3.3-3.3a1 1 0 1 1 1.4 1.4l-4 4a1 1 0 0 1-1.4 0l-4-4a1 1 0 0 1 0-1.4Z`})})}function rl({projectId:e,projectPath:t,worktreePath:n,expandedPaths:r,onToggleExpand:i,onSelectFile:a,selectedFilePath:o,fileChangeSeq:s,manualRefreshSeq:c,gitFileStatuses:l,onRootCountChange:u}){let d=(0,B.useMemo)(()=>new Set(r),[r]),[f,p]=(0,B.useState)(new Map),[m,h]=(0,B.useState)(new Set),g=(0,B.useRef)(f);g.current=f;let _=(0,B.useCallback)(async(t,r)=>{if(!(!r&&g.current.has(t))){h(e=>new Set(e).add(t));try{let r=await M({projectId:e,path:t,worktreePath:n});if(!r)return;p(e=>new Map(e).set(t,r))}catch{}finally{h(e=>{let n=new Set(e);return n.delete(t),n})}}},[e,n]),v=(0,B.useCallback)(async t=>{try{return await M({projectId:e,path:t,worktreePath:n})}catch{return null}},[e,n]),y=(0,B.useRef)(`${e}|${n??``}`);(0,B.useEffect)(()=>{let t=`${e}|${n??``}`,r=y.current!==t;r&&(y.current=t,p(new Map),g.current=new Map),_(`.`,r)},[e,n,_]),(0,B.useEffect)(()=>{for(let e of r)g.current.has(e)||_(e)},[r,_]),(0,B.useEffect)(()=>{if(s===void 0||s===0)return;let e=setTimeout(()=>{let e=[...g.current.keys()];for(let t of e)_(t,!0)},300);return()=>clearTimeout(e)},[s,_]),(0,B.useEffect)(()=>{if(!c)return;let e=[...g.current.keys()];for(let t of e)_(t,!0)},[c,_]);let b=f.get(`.`);(0,B.useEffect)(()=>{u&&u(b?.length??0)},[b,u]);let x=e=>{if(e.type!==`directory`){a?.(e.path);return}let t=d.has(e.path);i(e.path,!t),!t&&!f.has(e.path)&&_(e.path)},S=(0,B.useCallback)(async t=>{let r=t.path.lastIndexOf(`/`),i=r===-1?`.`:t.path.slice(0,r),a=g.current.get(i)??await v(i);if(!a){window.alert(`Failed to duplicate: cannot read parent directory.`);return}let o=Zc(t.name,t.type,a.map(e=>e.name)),s=i===`.`?o:`${i}/${o}`,c=await ie({projectId:e,srcPath:t.path,destPath:s,...n?{worktreePath:n}:{}});if(!c.ok){let e=await c.text().catch(()=>``);window.alert(`Failed to duplicate${e?`: ${e}`:``}`);return}let l=[...g.current.keys()];l.includes(i)||l.push(i);for(let e of l)_(e,!0)},[e,n,_,v]),[C,w]=(0,B.useState)(null),T=(0,B.useRef)(null),E=(0,B.useRef)(null),D=()=>{T.current&&=(clearTimeout(T.current),null),E.current=null},O=(e,t)=>{e.preventDefault(),e.stopPropagation(),w({x:e.clientX,y:e.clientY,entry:t})},k=(e,t)=>{if(t.touches.length>1){D();return}let n=t.touches[0];E.current={x:n.clientX,y:n.clientY},T.current=setTimeout(()=>{w({x:n.clientX,y:n.clientY,entry:e}),E.current=null},500)},ee=e=>{if(e.touches.length>1){D();return}let t=E.current;if(!t||!T.current)return;let n=e.touches[0];n&&Math.hypot(n.clientX-t.x,n.clientY-t.y)>10&&D()},A=()=>{D()},j=(e,n)=>{if(!t){n.preventDefault();return}let r=`${t.replace(/\/+$/,``)}/${e.path}`;n.dataTransfer.effectAllowed=`copy`,n.dataTransfer.setData(me,JSON.stringify([r])),n.dataTransfer.setData(`text/plain`,r)},[te,ne]=(0,B.useState)(0),N=Wc({projectId:e,expandedPaths:d,resolveTargetForRow:e=>{if(!e)return`.`;if(e.isDirectory)return e.path;let t=e.path.lastIndexOf(`/`);return t>0?e.path.slice(0,t):`.`},onAutoExpand:e=>{d.has(e)||i(e,!0)},onUploaded:()=>ne(e=>e+1)});(0,B.useEffect)(()=>{if(te===0)return;let e=[...g.current.keys()];for(let t of e)_(t,!0)},[te,_]),(0,B.useEffect)(()=>{if(!N.message)return;let e=setTimeout(()=>N.dismissMessage(),4e3);return()=>clearTimeout(e)},[N.message,N.dismissMessage]);let P=(e,n)=>{let r=f.get(e);return r?r.map(e=>{let r=d.has(e.path),i=e.type===`directory`,a=!i&&o===e.path,s=i?re(e.name,r):ae(e.name),c=N.hoveredRowPath===e.path,u=N.getRowHandlers({path:e.path,isDirectory:i,isExpanded:r});return(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`button`,{type:`button`,draggable:!!t,"aria-current":a?`page`:void 0,className:`
28
+ `))?e:u})},[u,n]);let m=new Map(e.map(e=>[e.id,e])),h=d.map(e=>m.get(e)).filter(e=>!!e),g=Gn(Wn(Yr,{activationConstraint:{distance:8}}),Wn(Zr,{activationConstraint:{delay:250,tolerance:6}}),Wn(Vr,{coordinateGetter:ya}));function _(e){let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=d.indexOf(String(t.id)),a=d.indexOf(String(n.id));if(r===-1||a===-1)return;let o=Xi(d,r,a);f(o),i(o)}return(0,V.jsx)(Vi,{sensors:g,collisionDetection:$n,onDragEnd:_,children:(0,V.jsx)(sa,{items:d,strategy:ra,children:h.map(e=>(0,V.jsx)(Va,{project:e,selection:t,onSelectWorktree:a,onSelectChild:o,onOpenContainer:s,onToggleChildPin:c,onReorderPanes:l},e.id))})})}function Va({project:e,selection:t,onSelectWorktree:n,onSelectChild:r,onOpenContainer:i,onToggleChildPin:a,onReorderPanes:o}){let{attributes:s,listeners:c,setNodeRef:l,transform:u,transition:d,isDragging:f}=ha({id:e.id});return(0,V.jsx)(`div`,{ref:l,style:{transform:kn.Transform.toString(u),transition:d,opacity:f?.6:1,zIndex:f?5:void 0},children:(0,V.jsx)(Pa,{project:e,selection:t,onSelectWorktree:n,onSelectChild:r,onOpenContainer:i,onToggleChildPin:a,onReorderPanes:o,dragHandleProps:{...s,...c,"aria-label":`Reorder ${e.name}`,style:{WebkitTouchCallout:`none`}}})})}function Ha(e,t){let n=t.toLowerCase(),r=[];for(let t of e){let e=t.name.toLowerCase().includes(n),i=[];for(let r of t.worktrees){let t=r.name.toLowerCase().includes(n);if(e||t){i.push(r);continue}let a=r.children.filter(e=>e.label.toLowerCase().includes(n)||(e.hint?.toLowerCase().includes(n)??!1));a.length>0&&i.push({...r,children:a})}(e||i.length>0)&&r.push({...t,worktrees:i})}return r}function Ua({resizable:e,width:t,onWidthChange:n}){let r=(0,B.useRef)(null),i=(0,B.useRef)(!1),a=e?Bt(t):Number.isFinite(t)?Math.round(t):288,o=zt(),s=e&&!!n,c=(0,B.useCallback)(e=>{let t=r.current?.getBoundingClientRect();t&&n?.(Bt(e-t.left))},[n]),l=(0,B.useCallback)(e=>{n&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),i.current=!0,c(e.clientX))},[n,c]),u=(0,B.useCallback)(e=>{if(i.current){if(e.buttons===0){i.current=!1;return}c(e.clientX)}},[c]),d=(0,B.useCallback)(e=>{i.current=!1;try{e.currentTarget.releasePointerCapture?.(e.pointerId)}catch{}},[]);return{asideRef:r,effectiveMaxWidth:o,effectiveWidth:a,showResizeHandle:s,resizeHandleProps:{onKeyDown:(0,B.useCallback)(e=>{if(n&&!(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`&&e.key!==`Home`&&e.key!==`End`)){if(e.preventDefault(),e.key===`Home`){n(220);return}if(e.key===`End`){n(zt());return}n(Bt(a+(e.key===`ArrowLeft`?-1:1)*(e.shiftKey?48:16)))}},[a,n]),onPointerCancel:d,onPointerDown:l,onPointerMove:u,onPointerUp:d}}}function Wa({projects:e,selection:t,connected:n,portsByProjectId:r,projectNames:i,onOpenUrl:a,width:o=288,fill:s=!1,resizable:c=!1,onWidthChange:l,onSelectMonitor:u,onSelectWorktree:d,onSelectChild:f,onOpenContainer:p,onToggleChildPin:m,onNewProject:g,onOpenSettings:_,searchOpen:v=!1,searchQuery:y=``,onToggleSearch:b,onCloseSearch:x,onSearchQueryChange:S,pinnedMonitorCount:C=0,onReorderProjects:w,onReorderPanes:T,reorderResetSignal:E,pendingProjectReorderCount:D}){let O=(0,B.useDeferredValue)(y).trim(),k=v&&O.length>0,ee=(0,B.useMemo)(()=>k?Ha(e,O):e,[k,e,O]),{asideRef:A,effectiveMaxWidth:j,effectiveWidth:te,resizeHandleProps:ne,showResizeHandle:M}=Ua({onWidthChange:l,resizable:c,width:o});return(0,V.jsxs)(`aside`,{ref:A,"aria-label":`Workspace navigation`,className:`relative flex h-full min-h-0 shrink-0 flex-col bg-bg-secondary text-text-primary ${s?`w-full`:`border-r border-border`}`,style:s?void 0:{width:te},children:[(0,V.jsxs)(`div`,{className:`cm-scroll min-h-0 flex-1 overflow-y-auto pb-2.5`,children:[(0,V.jsx)(tn,{selected:t.monitor,pinnedCount:C,onClick:u}),k?ee.length===0?(0,V.jsxs)(`div`,{className:`${Ht[0]} py-6 text-center text-xs text-text-secondary`,children:[`No matches for`,` `,(0,V.jsxs)(`span`,{className:`text-text-primary`,children:[`"`,O,`"`]})]}):(0,V.jsx)(`div`,{children:ee.map(e=>(0,V.jsx)(Pa,{project:e,selection:t,forceOpen:!0,onSelectWorktree:d,onSelectChild:f,onOpenContainer:p,onToggleChildPin:m},e.id))}):(0,V.jsx)(Ba,{projects:ee,selection:t,resetSignal:E,pendingReorderCount:D,onReorderProjects:w??(()=>{}),onSelectWorktree:d,onSelectChild:f,onOpenContainer:p,onToggleChildPin:m,onReorderPanes:T}),g&&(0,V.jsx)(`div`,{className:`${Ht[0]} mt-2`,children:(0,V.jsxs)(`button`,{type:`button`,onClick:g,className:`flex h-bar w-full items-center justify-center gap-2 rounded-control border border-dashed border-border text-sm text-text-secondary hover:border-accent/60 hover:text-text-primary`,children:[(0,V.jsx)(h.add,{}),(0,V.jsx)(`span`,{children:`New Project`})]})})]}),v&&(0,V.jsx)(za,{query:y,onClose:x,onQueryChange:S}),(0,V.jsx)(Ra,{connected:n,portsByProjectId:r,projectNames:i,onOpenUrl:a,onOpenSettings:_,onNewProject:g,searchOpen:v,onToggleSearch:b}),M&&(0,V.jsx)(`hr`,{"aria-label":`Resize sidebar`,"aria-orientation":`vertical`,"aria-valuemin":220,"aria-valuemax":j,"aria-valuenow":te,tabIndex:0,...ne,className:`cm-sidebar-resizer absolute top-0 right-0 bottom-0 z-[3] w-px cursor-col-resize touch-none bg-border before:absolute before:inset-y-0 before:-inset-x-3 before:content-[''] focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`})]})}var Ga=null,Ka=new Set,qa=0,Ja=null;function Ya(){for(let e of Ka)e()}function Xa(e){return Ka.add(e),()=>{Ka.delete(e)}}function Za(){return Ga}function Qa(e,t=1800){qa+=1,Ga={message:e,seq:qa},Ja&&clearTimeout(Ja),Ja=setTimeout(()=>{Ga=null,Ja=null,Ya()},t),Ya()}function $a(){return(0,B.useSyncExternalStore)(Xa,Za,()=>null)}function eo(){let e=$a();return e?(0,V.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`cm-mono pointer-events-none fixed bottom-[max(env(safe-area-inset-bottom,0px),16px)] left-1/2 z-[60] -translate-x-1/2 rounded-window border border-border bg-bg-secondary px-3 py-1.5 text-sm text-text-primary shadow-[0_8px_24px_rgba(0,0,0,0.35)]`,children:e.message},e.seq):null}var to=5e3;function no({connected:e}){let[t,n]=(0,B.useState)(!1);return(0,B.useEffect)(()=>{if(e){n(!1);return}let t=setTimeout(()=>n(!0),to);return()=>clearTimeout(t)},[e]),t?(0,V.jsx)(ro,{}):null}function ro({onReload:e=()=>window.location.reload()}){let t=(0,B.useRef)(null),n=(0,B.useRef)(null);return(0,B.useEffect)(()=>{let e=document.activeElement;n.current=e instanceof HTMLElement&&e!==document.body&&e!==document.documentElement?e:null,t.current?.focus();let r=e=>{let n=t.current;if(n&&e.target instanceof Node&&n.contains(e.target)){if(e.key===`Tab`){e.preventDefault();return}if((e.key===`Enter`||e.key===` `)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey)return}e.stopPropagation(),e.preventDefault()};return document.addEventListener(`keydown`,r,!0),document.addEventListener(`keyup`,r,!0),()=>{document.removeEventListener(`keydown`,r,!0),document.removeEventListener(`keyup`,r,!0);let e=n.current;n.current=null,e&&document.contains(e)&&typeof e.focus==`function`&&e.focus()}},[]),(0,V.jsxs)(m,{open:!0,ariaLabelledBy:`offline-title`,dialogRole:`alertdialog`,onClose:()=>void 0,closeOnBackdrop:!1,closeOnEscape:!1,backdropClassName:`bg-black/50 p-6 backdrop-blur-sm`,widthClassName:`w-surface-sm max-w-full`,panelClassName:`flex flex-col overflow-hidden`,panelTabIndex:-1,onPanelContextMenu:e=>e.preventDefault(),children:[(0,V.jsx)(`div`,{"aria-hidden":!0,className:`h-1 shrink-0 bg-danger`}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3.5`,children:[(0,V.jsx)(`span`,{className:`cm-mono self-start text-xs font-bold uppercase tracking-[0.08em] text-danger`,children:`OFFLINE`}),(0,V.jsx)(`h2`,{id:`offline-title`,className:`text-sm font-semibold text-text-primary`,children:`Connection lost`}),(0,V.jsx)(`p`,{className:`text-sm leading-[1.55] text-text-secondary`,children:`Trying to reconnect…`}),(0,V.jsx)(d,{children:(0,V.jsx)(S,{ref:t,variant:`primary`,onClick:e,children:`Reload`})})]})]})}function io(){let[e,t]=(0,B.useState)([]);(0,B.useEffect)(()=>{let e=!1;return(async()=>{try{let n=await O(`/api/notices`);if(!n.ok)return;let r=await n.json();e||t(r.notices??[])}catch{}})(),()=>{e=!0}},[]);let n=(0,B.useCallback)(async e=>{t(t=>t.filter(t=>t.kind!==e));try{await O(`/api/notices/${e}`,{method:`DELETE`})}catch{}},[]);return e.length===0?null:(0,V.jsx)(`div`,{className:`flex flex-col`,children:e.map(e=>(0,V.jsx)(ao,{notice:e,onDismiss:()=>void n(e.kind)},e.kind))})}function ao({notice:e,onDismiss:t}){let n=oo(e);return(0,V.jsxs)(`div`,{role:`status`,className:`flex items-center gap-3 border-b border-border bg-warning/10 px-4 py-2 text-sm text-text-primary`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:`h-2 w-2 shrink-0 rounded-full bg-warning`}),(0,V.jsx)(`p`,{className:`flex-1 leading-snug`,children:n}),(0,V.jsx)(a,{kind:`dismiss`,size:`sm`,onClick:t,children:`Dismiss`})]})}function oo(e){switch(e.kind){case`daemon-auto-restarted`:return`セッションがリセットされました -- parasor が新しいバージョンに更新されたため、走行中だったターミナルセッションは終了しています。`}}var so={toasts:[]},G=new Set,K=new Map,co=0;function lo(){for(let e of G)e()}function uo(e){return G.add(e),()=>{G.delete(e)}}function fo(){return so}function po(e){let t=K.get(e);t&&(clearTimeout(t),K.delete(e))}function mo(e,t){po(e),K.set(e,setTimeout(()=>{go(e)},t))}function ho(e){let t=e.id??`sync-${++co}`,n={id:t,tone:e.tone,title:e.title,...e.sub!==void 0&&{sub:e.sub},...e.mono!==void 0&&{mono:e.mono},...e.actions!==void 0&&{actions:e.actions}},r=so.toasts.findIndex(e=>e.id===t);return so={toasts:r===-1?[...so.toasts,n]:so.toasts.map((e,t)=>t===r?n:e)},e.durationMs===void 0?po(t):mo(t,e.durationMs),lo(),t}function go(e){po(e),so.toasts.some(t=>t.id===e)&&(so={toasts:so.toasts.filter(t=>t.id!==e)},lo())}function _o(){return(0,B.useSyncExternalStore)(uo,fo,()=>so).toasts}var vo={info:`bg-accent`,working:`bg-warning`,ok:`bg-success`,err:`bg-danger`};function yo(){let e=_o();return e.length===0?null:(0,V.jsx)(`section`,{"aria-label":`sync status`,className:`pointer-events-none fixed right-[max(env(safe-area-inset-right,0px),16px)] bottom-[max(env(safe-area-inset-bottom,0px),16px)] z-[55] flex w-[min(var(--spacing-surface-sm),calc(100vw-32px))] flex-col gap-2`,children:e.map(e=>(0,V.jsx)(bo,{toast:e},e.id))})}function bo({toast:e}){return(0,V.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`pointer-events-auto flex items-start gap-2.5 rounded-window border border-border bg-bg-secondary px-3 py-2.5 shadow-[0_8px_24px_rgba(0,0,0,0.35)]`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:`mt-[5px] h-2 w-2 flex-none rounded-tag ${vo[e.tone]} ${e.tone===`working`?`animate-pulse`:``}`}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`text-sm font-semibold tracking-[-0.005em] text-text-primary`,children:e.title}),e.sub&&(0,V.jsx)(`div`,{className:`mt-0.5 text-xs text-text-secondary ${e.mono?`cm-mono`:``}`,children:e.sub}),e.actions&&e.actions.length>0&&(0,V.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:e.actions.map(e=>(0,V.jsx)(a,{kind:e.kind===`primary`?`submit`:`normal`,size:`xs`,onClick:e.onSelect,children:e.label},`${e.kind??`ghost`}:${e.label}`))})]}),(0,V.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,onClick:()=>go(e.id),className:`-m-1 p-1 text-text-secondary hover:text-text-primary`,children:(0,V.jsx)(h.close,{})})]})}function xo({pinned:e,onToggle:t}){return(0,V.jsx)(_,{label:e?`Unpin from Monitor`:`Pin to Monitor`,title:e?`Pinned to Monitor -- click to unpin`:`Pin to Monitor`,size:`md`,tone:e?`accent`:`normal`,pressed:e,onClick:t,children:(0,V.jsx)(h.pin,{})})}function So(e,t,n){let r=new Map;for(let t of e)r.set(t.id,t);let i=t.filter(e=>e.pinned===!0);return i.sort((e,t)=>{let n=r.get(e.projectId)?.name??``,i=r.get(t.projectId)?.name??``;return n===i?e.createdAt-t.createdAt:n.localeCompare(i)}),i.map(e=>{let t=r.get(e.projectId),i=t?n?.[t.id]?.[t.path]?.isRepo!==!1:!0,a=Co(e.cwd,t?.path,i);return{session:e,project:t,worktreeName:a,label:t?`${t.name} / ${a}`:a,crumb:e.cwd}})}function Co(e,t,n){if(t&&e===t)return n?`main`:`root`;let r=e.replace(/\/+$/,``).split(`/`).pop();return r&&r.length>0?r:e}var wo=(function(){let e=typeof document<`u`&&document.createElement(`link`).relList;return e&&e.supports&&e.supports(`modulepreload`)?`modulepreload`:`preload`})(),To=function(e){return`/`+e},Eo={},Do=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=To(t,n),t in Eo)return;Eo[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:wo,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Oo=(0,B.lazy)(()=>Do(async()=>{let{TerminalPane:e}=await import(`./TerminalPane-D3z_3Lr8.js`);return{TerminalPane:e}},__vite__mapDeps([0])).then(({TerminalPane:e})=>({default:e}))),ko=320,Ao=1200,jo=420,Mo=`parasor:monitor-col-widths`;function No(e){return Number.isNaN(e)?jo:Math.min(Ao,Math.max(ko,Math.round(e)))}function Po(){try{let e=localStorage.getItem(Mo);if(!e)return{};let t=JSON.parse(e);if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`number`&&(n[e]=No(r));return n}catch{return{}}}function Fo(e){try{localStorage.setItem(Mo,JSON.stringify(e))}catch{}}function Io({projects:e,sessions:t,agentStates:n,reviewPendingSessions:r,gitStates:i,attentionDismissed:a,isMobile:o,onToggleDrawer:s,onRestartSession:c,onOpenUrl:l,onTogglePin:u}){let d=(0,B.useMemo)(()=>So(e,t,i),[e,t,i]),f=(0,B.useMemo)(()=>{let e=a??{},t=new Map;for(let i of d){let a=n[i.session.id],o=Ct(a,e)?void 0:a?.lifecycle;t.set(i.session.id,qo(o,r.has(i.session.id)))}return t},[d,n,r,a]),p=(0,B.useMemo)(()=>{let e=0,t=0;for(let n of f.values())n===`attention`?e+=1:n===`working`&&(t+=1);return{attention:e,working:t}},[f]),[m,h]=(0,B.useState)(null),g=(0,B.useMemo)(()=>{if(!m)return 0;let e=d.findIndex(e=>e.session.id===m);return e<0?0:e},[d,m]);return(0,V.jsxs)(`section`,{className:`flex h-full min-h-0 w-full flex-col bg-bg-primary`,children:[(0,V.jsx)(Lo,{attention:p.attention,working:p.working,isMobile:o,onToggleDrawer:s,entries:d,focusedIndex:g,onGoToIndex:e=>{let t=d[Math.max(0,Math.min(d.length-1,e))];t&&h(t.session.id)}}),d.length===0?(0,V.jsx)(Ko,{}):o?(0,V.jsx)(Go,{entries:d,statuses:f,focusedIndex:g,onFocusSession:h,onRestartSession:c,onOpenUrl:l,onTogglePin:u}):(0,V.jsx)(zo,{entries:d,statuses:f,focusedSessionId:m??d[g]?.session.id??null,focusedIndex:g,onFocusSession:h,onRestartSession:c,onOpenUrl:l,onTogglePin:u})]})}function Lo({attention:e,working:t,isMobile:n,onToggleDrawer:r,entries:i,focusedIndex:a,onGoToIndex:o}){let s=i.length;return(0,V.jsxs)(`header`,{className:`flex h-bar shrink-0 items-center gap-2.5 border-b border-border bg-pane-header-bg px-3`,children:[n&&r&&(0,V.jsx)(_,{onClick:r,label:`Go to sessions`,size:`md`,children:(0,V.jsx)(h.menu,{})}),(0,V.jsx)(`span`,{className:`text-sm font-semibold tracking-[-0.005em] text-text-primary`,children:`Monitor`}),(0,V.jsxs)(`div`,{className:`cm-mono flex items-center gap-2 text-sm text-text-secondary`,children:[e>0&&(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,V.jsx)(u,{state:`attention`}),(0,V.jsx)(`span`,{children:e})]}),t>0&&(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,V.jsx)(u,{state:`working`}),(0,V.jsx)(`span`,{children:t})]})]}),(0,V.jsx)(`span`,{className:`flex-1`}),s>0&&(0,V.jsx)(Ro,{entries:i,focusedIndex:a,onGoToIndex:o})]})}function Ro({entries:e,focusedIndex:t,onGoToIndex:n}){let r=e.length,i=t<=0,a=t>=r-1;return(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,V.jsx)(_,{onClick:()=>n(t-1),disabled:i,label:`Previous pinned terminal`,children:(0,V.jsx)(h.back,{})}),(0,V.jsx)(`div`,{className:`flex items-center gap-[5px]`,children:e.map((e,r)=>(0,V.jsx)(`button`,{type:`button`,onClick:()=>n(r),"aria-label":`Go to pinned terminal ${r+1}`,"aria-current":r===t?`true`:void 0,className:`h-[5px] cursor-pointer rounded-control transition-all ${r===t?`w-3.5 bg-accent`:`w-[5px] bg-text-secondary/35 hover:bg-text-secondary/60`}`},e.session.id))}),(0,V.jsx)(_,{onClick:()=>n(t+1),disabled:a,label:`Next pinned terminal`,children:(0,V.jsx)(`span`,{className:`rotate-180 inline-flex`,children:(0,V.jsx)(h.back,{})})})]})}function zo({entries:e,statuses:t,focusedSessionId:n,focusedIndex:r,onFocusSession:i,onRestartSession:a,onOpenUrl:o,onTogglePin:s}){let c=Math.max(0,e.length-3),l=(0,B.useRef)([]);(0,B.useEffect)(()=>{let e=l.current[r];e&&e.scrollIntoView({behavior:`smooth`,inline:`nearest`,block:`nearest`})},[r,n]);let[u,d]=(0,B.useState)(Po);(0,B.useEffect)(()=>{let e=setTimeout(()=>Fo(u),200);return()=>clearTimeout(e)},[u]);let f=(0,B.useCallback)((e,t)=>{d(n=>{let r=No(t);return n[e]===r?n:{...n,[e]:r}})},[]);return(0,V.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`cm-scroll absolute inset-0 flex flex-row items-stretch justify-start overflow-x-auto overflow-y-hidden`,children:e.map((e,r)=>{let c=u[e.session.id]??jo;return(0,V.jsx)(Bo,{ref:e=>{l.current[r]=e},entry:e,status:t.get(e.session.id)??`idle`,focused:n===e.session.id,width:c,onFocus:()=>i(e.session.id),onResize:t=>f(e.session.id,t),onRestartSession:a,onOpenUrl:o,onTogglePin:s},e.session.id)})}),c>0&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute top-0 right-0 bottom-0 w-14`,style:{background:`linear-gradient(to right, transparent, var(--color-bg-primary))`}}),(0,V.jsxs)(`div`,{"aria-hidden":!0,className:`cm-mono pointer-events-none absolute top-2 right-2 rounded-tag border border-border bg-bg-tertiary px-2 py-px text-xs text-text-secondary`,children:[`->`,` `,c,` more`]})]})]})}function Bo({ref:e,entry:t,status:n,focused:r,width:i,onFocus:a,onResize:o,onRestartSession:s,onOpenUrl:c,onTogglePin:l}){let u=`Resize column for ${wt(t.session)}`;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{ref:e,className:`relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border bg-bg-primary`,style:{width:`${i}px`},onPointerDownCapture:a,onFocusCapture:a,children:[(0,V.jsx)(Uo,{entry:t,status:n,onTogglePin:l}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 touch-pan-y`,children:(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`h-full bg-bg-terminal`}),children:(0,V.jsx)(Oo,{paneId:`monitor:${t.session.id}`,sessionId:t.session.id,session:t.session,onRestartSession:s,onOpenUrl:c})})}),r&&(0,V.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 border-2 border-accent`})]}),(0,V.jsx)(Vo,{width:i,onResize:o,ariaLabel:u})]})}function Vo({width:e,onResize:t,ariaLabel:n}){let r=(0,B.useRef)(!1),i=(0,B.useRef)(0),a=(0,B.useRef)(e),o=(0,B.useCallback)(e=>{if(r.current=!1,e)try{e.target.releasePointerCapture(e.pointerId)}catch{}},[]);return(0,V.jsx)(`hr`,{"aria-label":n,"aria-orientation":`vertical`,"aria-valuenow":e,"aria-valuemin":ko,"aria-valuemax":Ao,tabIndex:0,onPointerDown:(0,B.useCallback)(t=>{t.preventDefault(),t.target.setPointerCapture(t.pointerId),r.current=!0,i.current=t.clientX,a.current=e},[e]),onPointerMove:(0,B.useCallback)(e=>{if(r.current){if(e.buttons===0){o(e);return}t(a.current+(e.clientX-i.current))}},[t,o]),onPointerUp:o,onPointerCancel:o,onKeyDown:(0,B.useCallback)(n=>{n.key!==`ArrowLeft`&&n.key!==`ArrowRight`||(n.preventDefault(),t(e+(n.key===`ArrowLeft`?-1:1)*(n.shiftKey?50:10)))},[t,e]),style:{touchAction:`none`},className:`cm-split-resizer relative z-[2] w-px shrink-0 cursor-col-resize bg-border before:absolute before:inset-y-0 before:-inset-x-3 before:content-[''] focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`})}function Ho({entry:e,status:t,onFocus:n,onRestartSession:r,onOpenUrl:i,onTogglePin:a}){return(0,V.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary`,onPointerDownCapture:n,onFocusCapture:n,children:[(0,V.jsx)(Uo,{entry:e,status:t,onTogglePin:a}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 touch-pan-y`,children:(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`h-full bg-bg-terminal`}),children:(0,V.jsx)(Oo,{paneId:`monitor:${e.session.id}`,sessionId:e.session.id,session:e.session,onRestartSession:r,onOpenUrl:i})})})]})}function Uo({entry:e,status:t,onTogglePin:n}){return(0,V.jsxs)(`div`,{className:`flex h-bar shrink-0 items-center gap-2 border-b border-border bg-pane-header-bg px-3`,children:[(0,V.jsx)(Wo,{entry:e}),t!==`idle`&&(0,V.jsx)(u,{state:t}),(0,V.jsx)(xo,{pinned:!0,onToggle:()=>void n(e.session.id)})]})}function Wo({entry:e}){let t=e.project?.name??``,n=e.worktreeName,r=wt(e.session);return(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,V.jsx)(`span`,{className:`cm-mono min-w-0 flex-shrink truncate text-sm text-text-secondary/85`,title:t,children:t}),(0,V.jsx)(`span`,{"aria-hidden":!0,className:`text-text-secondary/40`,children:`/`}),(0,V.jsx)(`span`,{className:`cm-mono min-w-0 flex-shrink truncate text-sm text-text-secondary/85`,title:n,children:n}),(0,V.jsx)(`span`,{"aria-hidden":!0,className:`text-text-secondary/40`,children:`/`}),(0,V.jsx)(`span`,{className:`cm-mono min-w-0 flex-shrink truncate text-sm font-semibold text-text-primary`,title:r,children:r})]})}function Go({entries:e,statuses:t,focusedIndex:n,onFocusSession:r,onRestartSession:i,onOpenUrl:a,onTogglePin:o}){let s=e[n];return s?(0,V.jsx)(`div`,{className:`flex min-h-0 flex-1`,children:(0,V.jsx)(Ho,{entry:s,status:t.get(s.session.id)??`idle`,onFocus:()=>r(s.session.id),onRestartSession:i,onOpenUrl:a,onTogglePin:o})}):null}function Ko(){return(0,V.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center bg-bg-primary p-8 text-center`,children:(0,V.jsxs)(`div`,{className:`max-w-md`,children:[(0,V.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-text-primary`,children:`No pinned terminals yet`}),(0,V.jsxs)(`p`,{className:`cm-mono text-sm leading-relaxed text-text-secondary`,children:[`Tap the`,` `,(0,V.jsx)(`span`,{className:`inline-flex translate-y-[2px] items-center text-accent`,children:(0,V.jsx)(h.pin,{})}),` `,`icon in a terminal header to surface it here. Monitor gives you a live tail of every pinned session across projects at once.`]})]})})}function qo(e,t){return t?`review`:e===`waiting`?`attention`:e===`running`?`working`:`idle`}async function Jo(e){let t=await O(`/api/service-config`,{method:`PATCH`,headers:{"Content-Type":`application/json`},credentials:`same-origin`,body:JSON.stringify(e)});if(!t.ok)throw Error(`Failed to update service config: ${t.status}`)}function Yo(e){let t=Object.keys(e)[0]??`service config`;Jo(e).catch(e=>{console.warn(`Failed to update ${t}:`,e)})}var Xo=`parasor:shell-ratio:workspace`,Zo=24,Qo=240,$o=520,es=45;function ts(e,t){if(!Number.isFinite(e))return Zo;let n=12,r=es;return t&&t>0&&(n=Math.max(n,Qo/t*100),r=Math.min(r,$o/t*100)),Math.min(r,Math.max(n,e))}function ns(){try{let e=localStorage.getItem(Xo);if(!e)return Zo;let t=JSON.parse(e);return typeof t==`number`?ts(t):Zo}catch{return Zo}}function rs(e){try{localStorage.setItem(Xo,JSON.stringify(e))}catch{}}function is({navigation:e,main:t}){let[n,r]=(0,B.useState)(ns),i=(0,B.useRef)(null),a=(0,B.useRef)(!1);(0,B.useEffect)(()=>{rs(n)},[n]);let o=(0,B.useCallback)(e=>{let t=i.current?.getBoundingClientRect().width;r(ts(e,t))},[]),s=(0,B.useMemo)(()=>({width:`${n}%`,minWidth:`${Qo}px`,maxWidth:`${$o}px`}),[n]),c=(0,B.useCallback)(e=>{e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),a.current=!0},[]),l=(0,B.useCallback)(e=>{if(!a.current)return;if(e.buttons===0){a.current=!1;return}let t=i.current?.getBoundingClientRect();t&&o((e.clientX-t.left)/t.width*100)},[o]),u=(0,B.useCallback)(e=>{a.current=!1;try{e.currentTarget.releasePointerCapture?.(e.pointerId)}catch{}},[]),d=(0,B.useCallback)(e=>{if(!(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`&&e.key!==`Home`&&e.key!==`End`)){if(e.preventDefault(),e.key===`Home`){o(0);return}if(e.key===`End`){o(100);return}o(n+(e.key===`ArrowLeft`?-1:1)*(e.shiftKey?5:1))}},[n,o]);return(0,V.jsxs)(`div`,{ref:i,className:`flex h-full min-w-0 flex-1 flex-row overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`min-w-0 overflow-hidden bg-bg-secondary`,style:s,children:e}),(0,V.jsx)(`hr`,{"aria-label":`Resize navigation pane`,"aria-orientation":`vertical`,"aria-valuenow":Math.round(n),"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,onPointerDown:c,onPointerMove:l,onPointerUp:u,onPointerCancel:u,onKeyDown:d,className:`cm-split-resizer relative z-[2] w-px shrink-0 cursor-col-resize bg-border before:absolute before:inset-y-0 before:-inset-x-3 before:content-[''] focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`}),(0,V.jsx)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-1 overflow-hidden`,children:t})]})}function as({paneTitle:t,paneKind:n,onCancel:r,onConfirm:i}){let a=n===`terminal`?`The shell session will terminate.`:`The browser tab state will be lost.`;return(0,V.jsxs)(e,{ariaLabel:`Close ${t}`,confirmLabel:`Close`,confirmVariant:`danger`,onCancel:r,onConfirm:i,children:[`Close `,(0,V.jsx)(`strong`,{children:t}),`? `,a]})}async function os(e){let t=await O(`/api/pane-commands`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({commands:e})});if(!t.ok)throw Error(`Failed to save commands`);return await t.json()}async function ss(e){let t=await O(`/api/ide-commands`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({commands:e})});if(!t.ok)throw Error(`Failed to save IDE commands`);return await t.json()}function cs({projectName:t,onCancel:n,onConfirm:r}){return(0,V.jsxs)(e,{ariaLabel:`Close project ${t}`,confirmLabel:`Close`,confirmVariant:`primary`,onCancel:n,onConfirm:r,children:[`Close `,(0,V.jsx)(`strong`,{children:t}),`? All sessions in this project will terminate and its layout will be cleared. The directory itself will not be deleted.`]})}async function ls(e){let t=await O(`/api/sessions`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectId:e.projectId,...e.command&&{command:e.command},...e.title&&{title:e.title},...e.cwd&&{cwd:e.cwd},...e.bootstrapInput&&{bootstrapInput:e.bootstrapInput}})});return t.ok?await t.json():null}async function us(e){await O(`/api/sessions/${e}/restart`,{method:`POST`})}async function ds(e,t){await O(`/api/sessions/${e}/title`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:t})})}async function fs(e,t){await O(`/api/sessions/${e}/pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pinned:t})})}async function ps(e){await O(`/api/sessions/${e}`,{method:`DELETE`})}var ms=4e3;function hs({activeProjectId:e,playAttentionSound:t,playCompletionSound:n,priorLifecycle:r,projectId:i,state:a}){return!i||i===e||a.confidence!==`high`?null:a.lifecycle===`waiting`?!t||r===`waiting`?null:`attention`:a.lifecycle===`completed`?!n||r===`completed`?null:`completion`:null}function gs({activeProjectId:e,agentStates:t,snapshotApplied:n,playAttentionSound:r,playCompletionSound:i,sessions:a}){let o=(0,B.useRef)(!1),s=(0,B.useRef)({}),c=(0,B.useRef)(new Map),l=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!r&&!i||typeof window>`u`)return;let e=()=>{let e=_s(l);e&&e.state===`suspended`&&e.resume().catch(()=>{})};return window.addEventListener(`pointerdown`,e,{passive:!0}),window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`pointerdown`,e),window.removeEventListener(`keydown`,e)}},[r,i]),(0,B.useEffect)(()=>{let u={};for(let[e,n]of Object.entries(t))u[e]=n.lifecycle;if(!n){s.current=u;return}if(!o.current){o.current=!0,s.current=u;return}let d=new Map(a.map(e=>[e.id,e])),f=Date.now();for(let[n,a]of Object.entries(t)){let t=hs({activeProjectId:e,playAttentionSound:r,playCompletionSound:i,priorLifecycle:s.current[n],projectId:d.get(n)?.projectId??null,state:a});if(!t)continue;let o=`${n}:${t}`;if(f-(c.current.get(o)??0)<ms)continue;let u=_s(l);!u||u.state!==`running`||(vs(u,t),c.current.set(o,f))}s.current=u},[e,t,n,r,i,a])}function _s(e){if(e.current)return e.current;if(typeof window>`u`)return null;let t=window,n=t.AudioContext??t.webkitAudioContext;return n?(e.current=new n,e.current):null}function vs(e,t){let n=e.currentTime+.01;if(t===`attention`){ys(e,n,880,.08,.035),ys(e,n+.14,988,.12,.04);return}ys(e,n,659,.1,.03),ys(e,n+.12,880,.16,.035)}function ys(e,t,n,r,i){let a=e.createOscillator(),o=e.createGain();a.type=`sine`,a.frequency.setValueAtTime(n,t),o.gain.setValueAtTime(1e-4,t),o.gain.exponentialRampToValueAtTime(i,t+.02),o.gain.exponentialRampToValueAtTime(1e-4,t+r),a.connect(o),o.connect(e.destination),a.start(t),a.stop(t+r+.02)}function bs(e){try{return mt(window.localStorage.getItem(ft(e)))}catch{return{}}}function xs(e,t){try{window.localStorage.setItem(ft(e),JSON.stringify(t))}catch{}}function Ss(){return typeof crypto<`u`&&`randomUUID`in crypto?`browser:${crypto.randomUUID()}`:`browser:${Math.random().toString(36).slice(2,10)}-${Date.now()}`}function Cs(e){let[t,n]=(0,B.useState)(()=>e?bs(e):{}),r=(0,B.useRef)(e);(0,B.useEffect)(()=>{r.current!==e&&(r.current=e,n(e?bs(e):{}))},[e]),(0,B.useEffect)(()=>{e&&xs(e,t)},[e,t]);let i=(0,B.useCallback)((t,r)=>{if(!e||!pt(r))return null;let i=Ss();return n(e=>{let n=e[t]??[];return{...e,[t]:[...n,{id:i,url:r}]}}),i},[e]),a=(0,B.useCallback)(e=>{n(t=>{let n={},r=!1;for(let[i,a]of Object.entries(t)){let t=a.filter(t=>t.id!==e);t.length!==a.length&&(r=!0),t.length>0&&(n[i]=t)}return r?n:t})},[]),o=(0,B.useCallback)((e,t)=>{pt(t)&&n(n=>{let r=!1,i={};for(let[a,o]of Object.entries(n))i[a]=o.map(n=>n.id!==e||n.url===t?n:(r=!0,{...n,url:t}));return r?i:n})},[]);return{panesByWorktree:(0,B.useMemo)(()=>t,[t]),addBrowser:i,closeBrowser:a,updateBrowserUrl:o}}function ws({onConfirm:e}){let[t,n]=(0,B.useState)(null);return{target:t,request:(0,B.useCallback)((e,t,r)=>{n({paneId:e,paneKind:t,title:r})},[]),cancel:(0,B.useCallback)(()=>{n(null)},[]),confirm:(0,B.useCallback)(async()=>{let r=t;r&&(n(null),await e(r))},[t,e])}}function Ts(e,t,n){return e===t?n?`main`:`root`:e.replace(/\/+$/,``).split(`/`).pop()??e}function Es({projects:e,gitStates:t}){let[n,r]=(0,B.useState)(null),i=(0,B.useCallback)((e,t)=>{r({projectId:e,worktreeId:t,worktreePath:t.startsWith(`wt:`)?t.slice(3):t})},[]),a=(0,B.useCallback)(()=>{r(null)},[]);return{target:n,context:(0,B.useMemo)(()=>{if(!n)return null;let r=e.find(e=>e.id===n.projectId);if(!r)return null;let i=t[r.id]?.[r.path]?.isRepo!==!1,a=Ts(n.worktreePath,r.path,i);return{project:{id:r.id,name:r.name,path:r.path},worktree:{id:n.worktreeId,name:a,path:n.worktreePath}}},[n,e,t]),open:i,close:a}}function Ds(e=5e3){let[t,n]=(0,B.useState)(null);return(0,B.useEffect)(()=>{if(!t)return;let r=window.setTimeout(()=>n(null),e);return()=>window.clearTimeout(r)},[t,e]),[t,n]}function Os(e){let[t,n]=(0,B.useState)(null),r=(0,B.useRef)(e);return(0,B.useEffect)(()=>{r.current!==e&&(r.current=e,n(null))},[e]),[t,n]}var ks=class extends Error{constructor(e,t){super(e),this.status=t,this.name=`GitOperationError`}};async function As(e,t){await js(e,`POST`,t)}async function js(e,t,n){let r=await O(e,{method:t,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok)throw new ks((await r.json().catch(()=>({}))).error??`Request failed (${r.status})`,r.status)}async function Ms(e,t){let n=`worktreePath=${encodeURIComponent(e.worktreePath)}`,r=`/api/projects/${encodeURIComponent(e.projectId)}/diff`,i=await O(e.sha?`${r}?sha=${encodeURIComponent(e.sha)}&${n}`:`${r}?${n}`,{signal:t});return i.ok?(await i.json()).diff:null}function Ns(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/commit`,{worktreePath:e.worktreePath,message:e.message,paths:e.paths})}function Ps(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/push`,{worktreePath:e.worktreePath,...e.setUpstream===!0&&{setUpstream:!0}})}function Fs(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/pull`,{worktreePath:e.worktreePath,...e.rebase===!0&&{rebase:!0}})}function Is(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/fetch`,{worktreePath:e.worktreePath})}function Ls(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/switch`,{worktreePath:e.worktreePath,branch:e.branch})}function Rs(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/git/branch`,{worktreePath:e.worktreePath,branch:e.branch,startPoint:e.startPoint})}async function zs(e){let t=new URLSearchParams({worktreePath:e.worktreePath});e.limit!==void 0&&t.set(`limit`,String(e.limit)),e.skip!==void 0&&e.skip>0&&t.set(`skip`,String(e.skip)),e.includeRemotes&&t.set(`includeRemotes`,`1`);let n=await O(`/api/projects/${encodeURIComponent(e.projectId)}/git/log?${t.toString()}`,{signal:e.signal});if(!n.ok)throw new ks((await n.json().catch(()=>({}))).error??`Request failed (${n.status})`,n.status);return await n.json()}function Bs(e){return As(`/api/projects/${encodeURIComponent(e)}/git/init`,{})}function Vs(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees/open-os`,{worktreePath:e.worktreePath})}async function Hs(){let e=await O(`/api/projects/local-ide-capability`);if(!e.ok)throw new ks((await e.json().catch(()=>({}))).error??`Request failed (${e.status})`,e.status);return{canOpenLocalIde:(await e.json()).canOpenLocalIde===!0}}function Us(e){return As(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees/open-ide`,{worktreePath:e.worktreePath,editor:e.editor})}function Ws(e){return js(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees`,`PATCH`,{worktreePath:e.worktreePath,newBranch:e.newBranch})}function Gs(e){return js(`/api/projects/${encodeURIComponent(e.projectId)}/worktrees`,`DELETE`,{worktreePath:e.worktreePath,...e.force===!0&&{force:!0}})}function Ks({activeProjectId:e,focusedWorktreePath:t,focusedWorktreeName:n,gitState:r}){let[i,a]=(0,B.useState)(null),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(null),u=r?.ahead??0,d=r?.behind??0,f=r?.branch??n??null,p=(0,B.useRef)(null),m=(0,B.useCallback)(()=>{o||(a(null),l(null))},[o]),h=(0,B.useCallback)(async function(e,t,n,r){s(!0),l(null);try{return await Ns({projectId:e,worktreePath:t,message:r.message,paths:r.paths}),ho({tone:`ok`,title:`Commit created`,sub:`${n??`branch`} · ${r.paths.length} file${r.paths.length===1?``:`s`}`,mono:!0,durationMs:4e3}),!0}catch(e){return l(e instanceof ks||e instanceof Error?e.message:`Commit failed`),!1}finally{s(!1)}},[]),g=(0,B.useCallback)(async e=>{i&&await h(i.projectId,i.worktreePath,i.branchName,e)&&a(null)},[i,h]),_=(0,B.useCallback)(async n=>{!e||!t||await h(e,t,f,n)},[e,t,f,h]),v=(0,B.useCallback)(()=>{l(null)},[]),y=(0,B.useCallback)(n=>{if(!e||!t)return;let r=f??`branch`,i=`git-push:${t}`;ho({id:i,tone:`working`,title:`Pushing ${r}`,sub:u>0?`origin · ${u} commit${u===1?``:`s`}`:`origin`,mono:!0}),Ps({projectId:e,worktreePath:t,...n?.setUpstream===!0&&{setUpstream:!0}}).then(()=>{ho({id:i,tone:`ok`,title:`Push complete`,sub:`${r} · pushed to origin`,mono:!0,durationMs:4e3})}).catch(e=>{let t=e instanceof ks||e instanceof Error?e.message:`Push failed`,n=/non-fast-forward|rejected/i.test(t);ho({id:i,tone:`err`,title:n?`Push rejected -- non-fast-forward`:`Push failed`,sub:t,actions:n?[{label:`Pull --rebase`,kind:`primary`,onSelect:()=>{go(i),p.current?.({rebase:!0})}},{label:`Dismiss`,onSelect:()=>go(i)}]:[{label:`Dismiss`,onSelect:()=>go(i)}]})})},[e,t,f,u]),b=(0,B.useCallback)(n=>{if(!e||!t)return;let r=f??`branch`,i=`git-pull:${t}`;ho({id:i,tone:`working`,title:`Pulling ${r}`,sub:d>0?`origin · ${d} commit${d===1?``:`s`}`:`origin`,mono:!0}),Fs({projectId:e,worktreePath:t,...n?.rebase===!0&&{rebase:!0}}).then(()=>{ho({id:i,tone:`ok`,title:`Up to date`,sub:`${r} · pulled from origin`,mono:!0,durationMs:4e3})}).catch(e=>{ho({id:i,tone:`err`,title:`Pull failed`,sub:e instanceof ks||e instanceof Error?e.message:`Pull failed`,actions:[{label:`Dismiss`,onSelect:()=>go(i)}]})})},[e,t,f,d]);return p.current=b,{commitDialog:i,commitBusy:o,commitError:c,closeCommitDialog:m,submitCommit:g,submitInlineCommit:_,clearCommitError:v,fetch:(0,B.useCallback)(()=>{if(!e||!t)return;let n=`git-fetch:${t}`;ho({id:n,tone:`working`,title:`Fetching origin`,sub:f??void 0,mono:!0}),Is({projectId:e,worktreePath:t}).then(()=>{ho({id:n,tone:`ok`,title:`Fetched origin`,mono:!0,durationMs:3e3})}).catch(e=>{ho({id:n,tone:`err`,title:`Fetch failed`,sub:e instanceof ks||e instanceof Error?e.message:`Fetch failed`,actions:[{label:`Dismiss`,onSelect:()=>go(n)}]})})},[e,t,f]),pull:b,push:y}}var qs=`parasor:pane-commands`,Js=64*1024,Ys={id:`builtin:terminal`,label:`Terminal`,initialInput:``,builtin:!0};function Xs(e){return[Ys,...e.map(e=>({...e,builtin:!1}))]}function Zs(e){if(!e||e.length>Js)return[];let t;try{t=JSON.parse(e)}catch{return[]}return Ce(t)}function Qs(e){return Zs(e.getItem(qs))}function $s({hydrated:e,paneCommandsCount:t,onMigrate:n}){let r=(0,B.useRef)(!1);(0,B.useEffect)(()=>{if(r.current||!e||t>0)return;r.current=!0;let i=[];try{i=Qs(window.localStorage)}catch{return}i.length>0&&n(i)},[e,t,n])}function ec(){let[e,t]=(0,B.useState)(null);(0,B.useEffect)(()=>{let e=!1;return Hs().then(n=>{e||t(n.canOpenLocalIde)}).catch(()=>{e||t(null)}),()=>{e=!0}},[]);let n=typeof window<`u`&&oe(window.location.hostname);return{capability:e,canOpenLocalIde:e??n}}function tc(){let e=Promise.resolve();return t=>{let n=e.catch(()=>void 0).then(()=>t());return e=n,n}}function nc({onError:e}){let[t,n]=(0,B.useState)(0),[r,i]=(0,B.useState)(0),a=(0,B.useRef)(tc());return{reorderResetSignal:t,pendingProjectReorderCount:r,reorder:(0,B.useCallback)(async t=>{i(e=>e+1);try{await a.current(async()=>{let r=!1;try{(await O(`/api/projects/order`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({ids:t})})).ok||(r=!0)}catch(e){if(e instanceof b)return;r=!0}r&&(n(e=>e+1),e(`Failed to reorder projects -- reverted to previous order.`))})}finally{i(e=>Math.max(0,e-1))}},[e])}}function rc({activeProjectId:e,agentStates:t,sessions:n}){let[r,i]=(0,B.useState)(()=>new Set),a=(0,B.useRef)({});return(0,B.useEffect)(()=>{let o=a.current,s={},c=new Set,l=new Set,u=!1,d=new Set(n.map(e=>e.id));for(let[r,i]of Object.entries(t)){s[r]=i.lifecycle;let t=o[r];if(t===i.lifecycle)continue;let a=n.find(e=>e.id===r)?.projectId;i.lifecycle===`completed`&&t!==`completed`&&a&&a!==e?(c.add(r),u=!0):(i.lifecycle===`running`||i.lifecycle===`waiting`)&&(l.add(r),u=!0)}a.current=s,(u||r.size>0)&&i(e=>{let t=new Set(e);for(let n of e)d.has(n)||t.delete(n);for(let e of l)t.delete(e);for(let e of c)t.add(e);return t})},[e,t,r.size,n]),(0,B.useEffect)(()=>{e&&i(t=>{if(t.size===0)return t;let r=new Set(t),i=!1;for(let a of t)n.find(e=>e.id===a)?.projectId===e&&(r.delete(a),i=!0);return i?r:t})},[e,n]),r}function ic({isMobile:e,onMobileOpenShortcut:t}){let[n,r]=(0,B.useState)(!1),[i,a]=(0,B.useState)(``);return(0,B.useEffect)(()=>{function n(n){!(n.metaKey||n.ctrlKey)||n.key.toLowerCase()!==`k`||n.altKey||n.shiftKey||(n.preventDefault(),r(n=>n?(a(``),!1):(e&&t?.(),!0)))}return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),{open:n,query:i,setQuery:a,toggle:(0,B.useCallback)(()=>{r(e=>e?(a(``),!1):!0)},[]),close:(0,B.useCallback)(()=>{r(!1),a(``)},[])}}function ac({projectId:e,projectPath:t,worktrees:n,sessions:r,focusedPaneId:i,clientBrowserPanes:a}){return(0,B.useMemo)(()=>{if(!e||!t)return{worktrees:[],allPanes:[],paneById:new Map,focusedPane:null,effectiveFocusedPaneId:null};let o=r.filter(t=>t.projectId===e),s=oc(n,t,o),c=s.map(e=>({path:e,panes:[]}));for(let e of o){let n=sc(e.cwd,s,t),r=c.find(e=>e.path===n);r&&r.panes.push(je(De(e.id),n,e.id))}if(a)for(let e of c){let t=a[e.path];if(t)for(let n of t)e.panes.push(Me(n.id,e.path,n.url))}for(let e of c)e.panes=Ne(Pe(e.path,e.panes));let l=c.flatMap(e=>e.panes),u=new Map(l.map(e=>[e.id,e])),d=u.get(Te(t))??l[0]??null,f=(i?u.get(i)??null:null)??d;return{worktrees:c,allPanes:l,paneById:u,focusedPane:f,effectiveFocusedPaneId:f?.id??null}},[e,t,n,r,i,a])}function oc(e,t,n){let r=e.length>0?[...e]:[{path:t,head:``,branch:null,ahead:0,behind:0,dirtyCount:0}];r.sort((e,n)=>e.path===t?-1:+(n.path===t));let i=r.map(e=>e.path);for(let e of n)cc(e.cwd,i)||i.includes(e.cwd)||i.push(e.cwd);return i}function sc(e,t,n){return cc(e,t)||(t.includes(e)||!e.startsWith(`${n}/`)?e:n)}function cc(e,t){return t.filter(t=>e===t||e.startsWith(`${t}/`)).sort((e,t)=>t.length-e.length)[0]??null}var lc=`parasor:preferences`;function uc(){try{let e=localStorage.getItem(lc);return e?JSON.parse(e):{}}catch{return{}}}function dc(e){try{localStorage.setItem(lc,JSON.stringify(e))}catch{}}function fc(){let e=(0,B.useMemo)(uc,[]),[t,n]=(0,B.useState)(()=>Vt(e.sidebarWidth??256)),[r,i]=(0,B.useState)(e.focusedProjectId??null),[a,o]=(0,B.useState)(e.focusedPaneId??null),s=(0,B.useCallback)(e=>{n(t=>Bt(typeof e==`function`?e(t):e))},[]);return(0,B.useEffect)(()=>{dc({sidebarWidth:t,focusedProjectId:r,focusedPaneId:a})},[t,r,a]),{activeProjectId:r,focusedPaneId:a,setActiveProjectId:i,setFocusedPaneId:o,setSidebarWidth:s,sidebarWidth:t}}function pc({activeProjectId:e,projects:t,setActiveProjectId:n,seedProject:r}){let i=(0,B.useCallback)(async(e,t)=>{let i=await O(`/api/projects`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e,name:t})});if(i.ok){let e=await i.json();r?.(e),n(e.id)}},[r,n]),a=(0,B.useCallback)(async(e,t)=>{await O(`/api/projects/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})})},[]);return{createProject:i,deleteProject:(0,B.useCallback)(async r=>{await O(`/api/projects/${r}?force=true`,{method:`DELETE`}),e===r&&n(t.find(e=>e.id!==r)?.id??null)},[e,t,n]),pinProject:(0,B.useCallback)(async e=>{let n=t.find(t=>t.id===e);n&&await O(`/api/projects/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pinned:!n.pinned})})},[t]),renameProject:a,toggleProjectReadOnly:(0,B.useCallback)(async e=>{let n=t.find(t=>t.id===e);n&&await O(`/api/projects/${e}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({readOnly:!n.readOnly})})},[t])}}function mc(e){let t=gc(e.pathname);if(t===`/`||t===``)return{kind:`root`};if(t===`/monitor`)return{kind:`monitor`};let n=_c(t,`/sessions/`);if(n!==null)return{kind:`session`,sessionId:n};let r=_c(t,`/panes/`);if(r!==null)return{kind:`pane`,paneId:r,projectId:new URLSearchParams(e.search).get(`project`)??void 0};if(t===`/worktree`){let t=new URLSearchParams(e.search),n=t.get(`project`),r=t.get(`path`),i=t.get(`tab`)===`git`?`git`:`files`;if(n&&r)return{kind:`worktree`,projectId:n,worktreePath:r,tab:i}}return{kind:`root`}}function hc(e){switch(e.kind){case`root`:return`/`;case`monitor`:return`/monitor`;case`session`:return`/sessions/${encodeURIComponent(e.sessionId)}`;case`pane`:{let t=e.projectId?`?project=${encodeURIComponent(e.projectId)}`:``;return`/panes/${encodeURIComponent(e.paneId)}${t}`}case`worktree`:return`/worktree?${new URLSearchParams({project:e.projectId,path:e.worktreePath,tab:e.tab}).toString()}`}}function gc(e){return e.length>1&&e.endsWith(`/`)?e.replace(/\/+$/,``):e}function _c(e,t){if(!e.startsWith(t))return null;let n=e.slice(t.length);if(!n||n.includes(`/`))return null;try{return decodeURIComponent(n)}catch{return null}}function vc(){let[e,t]=(0,B.useState)(()=>mc(window.location));return(0,B.useEffect)(()=>{let e=()=>t(mc(window.location));return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]),{navigate:(0,B.useCallback)((e,n)=>{let r=hc(e);r!==`${window.location.pathname}${window.location.search}`&&(n?.replace?window.history.replaceState(null,``,r):window.history.pushState(null,``,r)),t(e)},[]),route:e}}function yc({activeProjectId:e,connected:t,projects:n,setActiveProjectId:r}){(0,B.useEffect)(()=>{!e&&n.length>0?r(n[0].id):t&&e&&!n.some(t=>t.id===e)&&r(n[0]?.id??null)},[e,t,n,r])}var bc=`parasor:layout`;function xc(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName;return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}function Sc(e){return[...e].sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:t.lastAccessedAt-e.lastAccessedAt)}function Cc({activeProjectId:e,projects:t,setActiveProjectId:n}){let[r,i]=(0,B.useState)(!1),a=ne(`(max-width: 767px)`),o=(0,B.useCallback)(()=>{i(!0)},[]),s=(0,B.useCallback)(()=>{i(!1)},[]);return(0,B.useEffect)(()=>{localStorage.removeItem(bc)},[]),(0,B.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`,`){e.preventDefault(),i(e=>!e);return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&/^[1-9]$/.test(e.key)&&!xc(e.target)){let r=Sc(t)[Number(e.key)-1];r&&(e.preventDefault(),n(r.id))}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t,n]),{closeSettings:s,isMobile:a,openSettings:o,settingsOpen:r}}function wc(){let[e,t]=(0,B.useState)(null),[n,r]=(0,B.useState)(!1),[i,a]=(0,B.useState)(null),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(null);return{renameDialog:e,renameBusy:n,renameError:i,openRenameDialog:(0,B.useCallback)(e=>{a(null),t(e)},[]),closeRenameDialog:(0,B.useCallback)(()=>{n||(t(null),a(null))},[n]),submitRename:(0,B.useCallback)(async n=>{let i=e;if(i){r(!0),a(null);try{await Ws({projectId:i.projectId,worktreePath:i.worktreePath,newBranch:n}),ho({tone:`ok`,title:`Branch renamed`,sub:`${i.currentBranch} -> ${n}`,mono:!0,durationMs:3e3}),t(null)}catch(e){a(e instanceof ks||e instanceof Error?e.message:`Rename failed`)}finally{r(!1)}}},[e]),removeDialog:o,removeBusy:c,removeError:u,openRemoveDialog:(0,B.useCallback)(e=>{d(null),s(e)},[]),closeRemoveDialog:(0,B.useCallback)(()=>{c||(s(null),d(null))},[c]),submitRemove:(0,B.useCallback)(async({force:e})=>{let t=o;if(t){l(!0),d(null);try{await Gs({projectId:t.projectId,worktreePath:t.worktreePath,...e===!0&&{force:!0}}),ho({tone:`ok`,title:`Worktree removed`,sub:t.branch,mono:!0,durationMs:3e3}),s(null)}catch(e){d(e instanceof ks||e instanceof Error?e.message:`Remove failed`)}finally{l(!1)}}},[o]),copyWorktreePath:(0,B.useCallback)(e=>{Tc(e).then(e=>{Qa(e?`Copied path`:`Copy failed`)}).catch(()=>{Qa(`Copy failed`)})},[]),openWorktreeInFinder:(0,B.useCallback)(({projectId:e,worktreePath:t})=>{let n=`open-os:${t}`;ho({id:n,tone:`working`,title:`Opening in file manager`,sub:t,mono:!0}),Vs({projectId:e,worktreePath:t}).then(()=>{go(n)}).catch(e=>{ho({id:n,tone:`err`,title:`Could not open in file manager`,sub:e instanceof ks||e instanceof Error?e.message:`Open failed`,actions:[{label:`Dismiss`,onSelect:()=>go(n)}]})})},[]),openWorktreeInIde:(0,B.useCallback)(({projectId:e,worktreePath:t,editor:n})=>{let r=n===`cursor`?`Cursor`:`VS Code`,i=`open-ide:${n}:${t}`;ho({id:i,tone:`working`,title:`Opening in ${r}`,sub:t,mono:!0}),Us({projectId:e,worktreePath:t,editor:n}).then(()=>{go(i)}).catch(e=>{let t=e instanceof ks||e instanceof Error?e.message:`Open failed`;ho({id:i,tone:`err`,title:`Could not open in ${r}`,sub:t,actions:[{label:`Dismiss`,onSelect:()=>go(i)}]})})},[])}}async function Tc(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0;let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}var Ec=16,Dc=24,Oc=40;function kc(e){(0,B.useEffect)(()=>{if(!e)return;let t=null,n=!1;function r(e){if(e.touches.length!==1){t=null,n=!1;return}let r=e.touches[0];if(r.clientX>Ec){t=null,n=!1;return}t={x:r.clientX,y:r.clientY},n=!0}function i(e){if(!n||!t)return;if(e.touches.length!==1){n=!1,t=null;return}let r=e.touches[0];Math.abs(r.clientY-t.y)>Oc&&(n=!1,t=null)}function a(r){if(!n||!t){n=!1,t=null;return}let i=r.changedTouches[0],a=i?i.clientX-t.x:0,o=i?Math.abs(i.clientY-t.y):0;n=!1,t=null,a>=Dc&&o<=Oc&&e?.()}function o(){n=!1,t=null}return window.addEventListener(`touchstart`,r,{passive:!0}),window.addEventListener(`touchmove`,i,{passive:!0}),window.addEventListener(`touchend`,a,{passive:!0}),window.addEventListener(`touchcancel`,o,{passive:!0}),()=>{window.removeEventListener(`touchstart`,r),window.removeEventListener(`touchmove`,i),window.removeEventListener(`touchend`,a),window.removeEventListener(`touchcancel`,o)}},[e])}var Ac=`about:blank`;function jc(e){return e===Ac?``:e}function Mc({url:e,onUrlChange:t,paneId:n,headerActions:r}){let[i,a]=(0,B.useState)(jc(e)),[o,s]=(0,B.useState)(e),c=(0,B.useRef)(null);(0,B.useEffect)(()=>{s(e),a(jc(e))},[e]),le(n,(0,B.useCallback)(()=>{c.current?.contentWindow?.focus()},[]),!de());function l(e){let n=e.trim();if(n===``){a(jc(o));return}n===Ac?n=Ac:/^https?:\/\//i.test(n)||(n=`https://${n}`),s(n),a(jc(n)),t?.(n)}function u(e){e.preventDefault(),l(i)}return(0,V.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,V.jsxs)(`form`,{onSubmit:u,"aria-label":`Browser address bar`,className:`flex items-center gap-2 border-b border-border bg-bg-primary px-2 py-1`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>c.current?.contentWindow?.history.back(),"aria-label":`Browser back`,className:`text-text-secondary hover:text-text-primary text-sm px-1`,title:`Back`,children:`←`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>c.current?.contentWindow?.history.forward(),"aria-label":`Browser forward`,className:`text-text-secondary hover:text-text-primary text-sm px-1`,title:`Forward`,children:`->`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>c.current?.contentWindow?.location.reload(),"aria-label":`Browser reload`,className:`text-text-secondary hover:text-text-primary text-sm px-1`,title:`Reload`,children:`↻`}),(0,V.jsx)(`input`,{type:`text`,"aria-label":`URL`,value:i,onChange:e=>a(e.target.value),className:`flex-1 rounded-control bg-bg-primary px-2 py-1 text-xs text-text-primary outline-none focus:ring-1 focus:ring-accent`,placeholder:`URL`}),r]}),(0,V.jsx)(`iframe`,{ref:c,src:o,className:`flex-1 border-none bg-white`,sandbox:`allow-same-origin allow-scripts allow-forms allow-popups`,title:`Browser`})]})}function Nc({onClick:e}){return(0,V.jsx)(_,{label:`Close pane`,title:`Close pane`,size:`md`,tone:`danger`,onClick:e,children:(0,V.jsx)(h.close,{})})}function Pc({state:e,onUrlChange:t,paneId:n,onClose:r}){return(0,V.jsx)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(Mc,{url:e.url,onUrlChange:t,paneId:n,headerActions:r?(0,V.jsx)(Nc,{onClick:r}):null})})})}var Fc=class extends Error{constructor(){super(`upload aborted`),this.name=`FileUploadAbortedError`}},Ic=class extends Error{limit;constructor(e){super(`upload exceeds size limit`),this.name=`FileUploadTooLargeError`,this.limit=e}},Lc=class extends Error{reason;constructor(e){super(`invalid filename: ${e}`),this.name=`FileUploadInvalidFilenameError`,this.reason=e}},Rc=class extends Error{reason;constructor(e){super(`invalid target: ${e}`),this.name=`FileUploadInvalidTargetError`,this.reason=e}},zc=class extends Error{constructor(){super(`project is read-only`),this.name=`FileUploadReadOnlyError`}},Bc=class extends Error{constructor(e){super(e),this.name=`FileUploadIoError`}},Vc=class extends Error{conflicts;constructor(e){super(`conflict: ${e.join(`, `)}`),this.name=`FileUploadConflictError`,this.conflicts=[...e]}};async function Hc(e){let{projectId:t,targetPath:n,files:r,disposition:i,signal:a,onSlow:o,slowMs:s=300}=e;if(r.length===0)return[];let c=new FormData;for(let e of r)c.append(`files`,e,e.name);let l=new URLSearchParams;n&&l.set(`path`,n),i&&l.set(`disposition`,i);let u=l.toString(),d=`/api/projects/${encodeURIComponent(t)}/files/upload`+(u?`?${u}`:``),f=null;o&&(f=setTimeout(o,s));let p;try{let e={method:`POST`,body:c};a&&(e.signal=a),p=await O(d,e)}catch(e){throw f!==null&&clearTimeout(f),e instanceof DOMException&&e.name===`AbortError`?new Fc:e}finally{f!==null&&clearTimeout(f)}if(p.ok)return(await p.json()).files;let m=await p.json().catch(()=>({}));if(m&&`error`in m){if(m.error===`conflict`)throw new Vc(Array.isArray(m.conflicts)?m.conflicts:[]);if(m.error===`too-large`)throw new Ic(typeof m.limit==`number`?m.limit:0);if(m.error===`invalid-filename`)throw new Lc(m.reason??`control-char`);if(m.error===`invalid-target`)throw new Rc(m.reason??`missing`);if(m.error===`read-only`)throw new zc;if(m.error===`io-error`)throw new Bc(`io error`)}throw new Bc(`upload failed: HTTP ${p.status}`)}var Uc=800;function Wc(e){let{projectId:t,resolveTargetForRow:n,onAutoExpand:r,expandedPaths:i,onUploaded:a}=e,o=(0,B.useRef)(0),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(null),[h,g]=(0,B.useState)(null),_=(0,B.useRef)(null),v=(0,B.useRef)(null),y=(0,B.useCallback)(()=>{_.current&&=(clearTimeout(_.current),null),v.current=null},[]);(0,B.useEffect)(()=>()=>y(),[y]);let b=(0,B.useMemo)(()=>s?n(l===null?null:{path:l,isDirectory:x.current}):null,[l,s,n]),x=(0,B.useRef)(!1),S=(0,B.useCallback)(async(e,n)=>{f(!0),g(null);try{return await Hc({projectId:t,targetPath:e.targetPath,files:e.files,...n?{disposition:n}:{}})}catch(t){return t instanceof Vc?(m({...e,conflicts:t.conflicts}),null):t instanceof zc?(g({kind:`read-only`}),null):t instanceof Ic?(g({kind:`too-large`,limit:t.limit}),null):t instanceof Lc?(g({kind:`invalid-filename`,reason:t.reason}),null):t instanceof Rc?(g({kind:`invalid-target`,reason:t.reason}),null):t instanceof Bc?(g({kind:`io`}),null):(console.error(`[file-uploads] unexpected error`,t),g({kind:`io`}),null)}finally{f(!1)}},[t]),C=(0,B.useCallback)((e,t)=>{g({kind:`success`,count:e,targetLabel:t}),a()},[a]),w=e=>{R(e.dataTransfer)&&(e.preventDefault(),o.current+=1,s||c(!0))},T=e=>{R(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))},E=e=>{R(e.dataTransfer)&&(e.preventDefault(),o.current=Math.max(0,o.current-1),o.current===0&&(c(!1),u(null),x.current=!1,y()))},D=e=>{if(!R(e.dataTransfer))return;e.preventDefault();let t=e.dataTransfer;o.current=0,c(!1),y();let r=[];if(t)for(let e=0;e<t.files.length;e++){let n=t.files.item(e);n&&r.push(n)}if(r.length===0){u(null),x.current=!1;return}let i=n(l?{path:l,isDirectory:x.current}:null);u(null),x.current=!1,(async()=>{let e=await S({files:r,targetPath:i},void 0);e&&C(e.filter(e=>e.status!==`skipped`).length,i||`.`)})()},O=(0,B.useCallback)(e=>({onDragEnter:t=>{R(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),u(e.path),x.current=e.isDirectory,e.isDirectory&&!e.isExpanded?v.current!==e.path&&(y(),v.current=e.path,_.current=setTimeout(()=>{v.current===e.path&&(r(e.path),_.current=null,v.current=null)},Uc)):y())},onDragLeave:t=>{R(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),v.current===e.path&&y())}}),[r,y]),k=(0,B.useCallback)(()=>g(null),[]),ee=(0,B.useCallback)(()=>{m(null)},[]),A=(0,B.useCallback)((e,t)=>{let n=p;m(null),n&&(async()=>{let t=await S({files:n.files,targetPath:n.targetPath},e);t&&C(t.filter(e=>e.status!==`skipped`).length,n.targetPath||`.`)})()},[p,S,C]);return{rootHandlers:{onDragEnter:w,onDragOver:T,onDragLeave:E,onDrop:D},getRowHandlers:O,hoveredRowPath:l,targetPath:b,isDragging:s,uploading:d,conflict:p,message:h,dismissMessage:k,resolveConflict:A,cancelConflict:ee}}var Gc={M:`text-yellow-400`,A:`text-green-400`,D:`text-red-400`,R:`text-blue-400`,"?":`text-neutral-400`},Kc={D:4,M:3,A:2,R:1,"?":0};function qc(e){return Gc[e]??`text-neutral-400`}function Jc(e,t){let n=e===`.`?``:`${e}/`,r=null,i=-1;for(let[e,a]of Object.entries(t))if(e.startsWith(n)){let e=Kc[a]??0;if(e>i&&(r=a,i=e),i>=4)break}return r}function Yc(e,t){if(t===`directory`)return{base:e,ext:``};let n=e.lastIndexOf(`.`);return n<=0?{base:e,ext:``}:{base:e.slice(0,n),ext:e.slice(n)}}function Xc(e,t,n){return`${e}${n===1?` copy`:` copy ${n}`}${t}`}function Zc(e,t,n){let r=new Set(n),{base:i,ext:a}=Yc(e,t);for(let e=1;e<1e3;e+=1){let t=Xc(i,a,e);if(!r.has(t))return t}return Xc(i,a,Date.now())}async function Qc(e){try{await navigator.clipboard.writeText(e)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t)}}function $c({entry:e,projectPath:n,x:r,y:i,onClose:a,onDuplicate:o}){let s=`ontouchstart`in window,c=!s,l=!!n&&I(),u=[{id:`copy-path`,label:`Copy Path`,onSelect:()=>Qc(e.path)},{id:`copy-at-path`,label:`Copy as @path`,onSelect:()=>Qc(`@${e.path}`)}];if(l&&n){let t=`${n.replace(/\/+$/,``)}/${e.path}`;u.push({id:`insert-path`,label:`Insert path into terminal`,onSelect:()=>fe(L(t))})}return o&&u.push({id:`duplicate`,label:`Duplicate`,onSelect:()=>o(e)}),c&&u.push({id:`reveal-finder`,label:`Reveal in Finder`,separatorBefore:!0,onSelect:()=>Qc(e.path)}),s?(0,V.jsx)(ee,{open:!0,onDismiss:a,ariaLabel:`Actions for ${e.name}`,title:e.path,items:u}):(0,V.jsx)(t,{open:!0,anchorPoint:{x:r,y:i},items:u,onClose:a})}function el({open:e,conflicts:t,totalCount:n,targetLabel:r,onResolve:i,onCancel:a}){let[o,s]=(0,B.useState)(!0),c=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(e){s(!0);let e=requestAnimationFrame(()=>c.current?.focus());return()=>cancelAnimationFrame(e)}},[e]);let l=t.length,u=Math.max(0,n-l);return(0,V.jsxs)(m,{open:e,ariaLabel:`Resolve upload conflict`,onClose:a,children:[(0,V.jsx)(f,{title:`Files already exist`,onClose:a}),(0,V.jsxs)(`div`,{className:`px-4 py-3 text-sm text-text-primary`,children:[(0,V.jsxs)(`p`,{className:`mb-2 text-text-secondary`,children:[(0,V.jsx)(`span`,{className:`font-medium text-text-primary`,children:l}),` `,`of `,(0,V.jsx)(`span`,{className:`font-medium`,children:n}),` `,n===1?`file already exists`:`files already exist`,` `,`in`,` `,(0,V.jsx)(`code`,{className:`rounded-control bg-bg-primary px-1 text-xs`,children:r||`.`}),`.`]}),(0,V.jsx)(`ul`,{className:`mb-3 max-h-32 overflow-y-auto rounded-control border border-border bg-bg-primary px-2 py-1 text-xs text-text-secondary`,children:t.map(e=>(0,V.jsx)(`li`,{className:`truncate`,children:e},e))}),u>0?(0,V.jsxs)(`p`,{className:`mb-2 text-xs text-text-secondary`,children:[u,` other file`,u===1?``:`s`,` will follow your chosen action.`]}):null,(0,V.jsxs)(`label`,{className:`mt-1 flex items-center gap-2 text-xs text-text-secondary`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`accent-accent`}),`Apply to all files in this drop`]})]}),(0,V.jsx)(`div`,{className:`border-t border-border px-4 py-3`,children:(0,V.jsxs)(d,{children:[(0,V.jsx)(S,{onClick:a,children:`Cancel`}),(0,V.jsx)(S,{onClick:()=>i(`skip`,o),children:`Skip`}),(0,V.jsx)(S,{ref:c,variant:`primary`,onClick:()=>i(`keep-both`,o),children:`Keep both`}),(0,V.jsx)(S,{variant:`danger`,onClick:()=>i(`replace`,o),children:`Replace`})]})})]})}function tl(){return(0,V.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":!0,children:(0,V.jsx)(`path`,{d:`M5.7 4.3a1 1 0 0 1 1.4 0l3 3a1 1 0 0 1 0 1.4l-3 3a1 1 0 0 1-1.4-1.4L8 8 5.7 5.7a1 1 0 0 1 0-1.4Z`})})}function nl(){return(0,V.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":!0,children:(0,V.jsx)(`path`,{d:`M3.3 5.7a1 1 0 0 1 1.4 0L8 9l3.3-3.3a1 1 0 1 1 1.4 1.4l-4 4a1 1 0 0 1-1.4 0l-4-4a1 1 0 0 1 0-1.4Z`})})}function rl({projectId:e,projectPath:t,worktreePath:n,expandedPaths:r,onToggleExpand:i,onSelectFile:a,selectedFilePath:o,fileChangeSeq:s,manualRefreshSeq:c,gitFileStatuses:l,onRootCountChange:u}){let d=(0,B.useMemo)(()=>new Set(r),[r]),[f,p]=(0,B.useState)(new Map),[m,h]=(0,B.useState)(new Set),g=(0,B.useRef)(f);g.current=f;let _=(0,B.useCallback)(async(t,r)=>{if(!(!r&&g.current.has(t))){h(e=>new Set(e).add(t));try{let r=await M({projectId:e,path:t,worktreePath:n});if(!r)return;p(e=>new Map(e).set(t,r))}catch{}finally{h(e=>{let n=new Set(e);return n.delete(t),n})}}},[e,n]),v=(0,B.useCallback)(async t=>{try{return await M({projectId:e,path:t,worktreePath:n})}catch{return null}},[e,n]),y=(0,B.useRef)(`${e}|${n??``}`);(0,B.useEffect)(()=>{let t=`${e}|${n??``}`,r=y.current!==t;r&&(y.current=t,p(new Map),g.current=new Map),_(`.`,r)},[e,n,_]),(0,B.useEffect)(()=>{for(let e of r)g.current.has(e)||_(e)},[r,_]),(0,B.useEffect)(()=>{if(s===void 0||s===0)return;let e=setTimeout(()=>{let e=[...g.current.keys()];for(let t of e)_(t,!0)},300);return()=>clearTimeout(e)},[s,_]),(0,B.useEffect)(()=>{if(!c)return;let e=[...g.current.keys()];for(let t of e)_(t,!0)},[c,_]);let b=f.get(`.`);(0,B.useEffect)(()=>{u&&u(b?.length??0)},[b,u]);let x=e=>{if(e.type!==`directory`){a?.(e.path);return}let t=d.has(e.path);i(e.path,!t),!t&&!f.has(e.path)&&_(e.path)},S=(0,B.useCallback)(async t=>{let r=t.path.lastIndexOf(`/`),i=r===-1?`.`:t.path.slice(0,r),a=g.current.get(i)??await v(i);if(!a){window.alert(`Failed to duplicate: cannot read parent directory.`);return}let o=Zc(t.name,t.type,a.map(e=>e.name)),s=i===`.`?o:`${i}/${o}`,c=await ie({projectId:e,srcPath:t.path,destPath:s,...n?{worktreePath:n}:{}});if(!c.ok){let e=await c.text().catch(()=>``);window.alert(`Failed to duplicate${e?`: ${e}`:``}`);return}let l=[...g.current.keys()];l.includes(i)||l.push(i);for(let e of l)_(e,!0)},[e,n,_,v]),[C,w]=(0,B.useState)(null),T=(0,B.useRef)(null),E=(0,B.useRef)(null),D=()=>{T.current&&=(clearTimeout(T.current),null),E.current=null},O=(e,t)=>{e.preventDefault(),e.stopPropagation(),w({x:e.clientX,y:e.clientY,entry:t})},k=(e,t)=>{if(t.touches.length>1){D();return}let n=t.touches[0];E.current={x:n.clientX,y:n.clientY},T.current=setTimeout(()=>{w({x:n.clientX,y:n.clientY,entry:e}),E.current=null},500)},ee=e=>{if(e.touches.length>1){D();return}let t=E.current;if(!t||!T.current)return;let n=e.touches[0];n&&Math.hypot(n.clientX-t.x,n.clientY-t.y)>10&&D()},A=()=>{D()},j=(e,n)=>{if(!t){n.preventDefault();return}let r=`${t.replace(/\/+$/,``)}/${e.path}`;n.dataTransfer.effectAllowed=`copy`,n.dataTransfer.setData(me,JSON.stringify([r])),n.dataTransfer.setData(`text/plain`,r)},[te,ne]=(0,B.useState)(0),N=Wc({projectId:e,expandedPaths:d,resolveTargetForRow:e=>{if(!e)return`.`;if(e.isDirectory)return e.path;let t=e.path.lastIndexOf(`/`);return t>0?e.path.slice(0,t):`.`},onAutoExpand:e=>{d.has(e)||i(e,!0)},onUploaded:()=>ne(e=>e+1)});(0,B.useEffect)(()=>{if(te===0)return;let e=[...g.current.keys()];for(let t of e)_(t,!0)},[te,_]),(0,B.useEffect)(()=>{if(!N.message)return;let e=setTimeout(()=>N.dismissMessage(),4e3);return()=>clearTimeout(e)},[N.message,N.dismissMessage]);let P=(e,n)=>{let r=f.get(e);return r?r.map(e=>{let r=d.has(e.path),i=e.type===`directory`,a=!i&&o===e.path,s=i?re(e.name,r):ae(e.name),c=N.hoveredRowPath===e.path,u=N.getRowHandlers({path:e.path,isDirectory:i,isExpanded:r});return(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`button`,{type:`button`,draggable:!!t,"aria-current":a?`page`:void 0,className:`
29
29
  flex w-full items-center gap-2 py-1 text-left text-sm leading-tight hover:bg-bg-primary/50 active:bg-row-active-bg h-6 max-md:h-6.5
30
30
  ${e.isGitignored?`opacity-40`:``}
31
31
  ${a?`bg-row-selected-bg text-row-active-fg`:e.isHidden?`text-text-secondary`:`text-text-primary`}
32
32
  ${c?`ring-1 ring-accent ring-inset bg-accent/10`:``}
33
33
  `,style:{paddingLeft:n*16+8},onClick:()=>x(e),onContextMenu:t=>O(t,e),onDragStart:t=>j(e,t),onDragEnter:u.onDragEnter,onDragLeave:u.onDragLeave,onTouchStart:t=>k(e,t),onTouchMove:ee,onTouchEnd:A,onTouchCancel:A,children:[i?(0,V.jsx)(`span`,{className:`flex w-4 shrink-0 items-center justify-center text-text-secondary`,children:r?(0,V.jsx)(nl,{}):(0,V.jsx)(tl,{})}):(0,V.jsx)(`span`,{className:`w-4 shrink-0`}),(0,V.jsx)(s,{className:`h-icon-base w-icon-base shrink-0`}),(0,V.jsx)(`span`,{className:`truncate`,children:e.name}),l&&(()=>{if(i){let t=Jc(e.path,l);if(t)return(0,V.jsx)(`span`,{className:`ml-auto shrink-0 pr-2 text-xs ${qc(t)}`,children:`●`})}else{let t=l[e.path];if(t)return(0,V.jsx)(`span`,{className:`ml-auto shrink-0 pr-2 text-xs font-semibold ${qc(t)}`,children:t===`?`?`U`:t})}return null})()]}),i&&r&&P(e.path,n+1)]},e.path)}):m.has(e)?(0,V.jsx)(`div`,{className:`py-0.5 text-sm text-text-secondary`,style:{paddingLeft:n*16+8},children:`Loading…`}):null},F=N.targetPath??`.`;return(0,V.jsxs)(`div`,{className:`relative h-full overflow-y-auto bg-bg-primary text-text-primary ${N.isDragging?`ring-1 ring-accent ring-inset`:``}`,onDragEnter:N.rootHandlers.onDragEnter,onDragOver:N.rootHandlers.onDragOver,onDragLeave:N.rootHandlers.onDragLeave,onDrop:N.rootHandlers.onDrop,children:[(0,V.jsx)(`div`,{className:`py-1`,children:P(`.`,0)}),N.isDragging&&(0,V.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none sticky bottom-2 ml-2 mr-2 rounded-control border border-border bg-bg-secondary/95 px-3 py-1.5 text-xs text-text-secondary shadow-md`,children:[`Drop into`,` `,(0,V.jsx)(`code`,{className:`rounded-control bg-bg-primary px-1 text-text-primary`,children:F})]}),N.uploading&&(0,V.jsx)(`div`,{"aria-live":`polite`,className:`pointer-events-none sticky bottom-2 ml-2 mr-2 rounded-control border border-border bg-bg-secondary px-3 py-1.5 text-xs text-text-secondary shadow-md`,children:`Uploading…`}),N.message&&(0,V.jsxs)(`div`,{role:`status`,className:`sticky bottom-2 ml-2 mr-2 flex items-center justify-between gap-2 rounded-control border px-3 py-1.5 text-xs shadow-md ${N.message.kind===`success`?`border-accent bg-bg-secondary text-text-primary`:`border-red-500/40 bg-red-500/10 text-red-200`}`,children:[(0,V.jsxs)(`span`,{className:`truncate`,children:[N.message.kind===`success`&&`Uploaded ${N.message.count} file${N.message.count===1?``:`s`} to ${N.message.targetLabel}.`,N.message.kind===`read-only`&&`This project is read-only. Toggle write access in Settings to upload.`,N.message.kind===`too-large`&&`One of the files exceeds the ${Math.round(N.message.limit/(1024*1024))} MB upload limit.`,N.message.kind===`invalid-filename`&&`Filename rejected (${N.message.reason}).`,N.message.kind===`invalid-target`&&`Target folder rejected (${N.message.reason}).`,N.message.kind===`io`&&`Upload failed. Check the server logs and try again.`]}),(0,V.jsx)(`button`,{type:`button`,onClick:N.dismissMessage,className:`ml-2 shrink-0 text-xs text-text-secondary hover:text-text-primary`,"aria-label":`Dismiss`,children:`×`})]}),C&&(0,V.jsx)($c,{entry:C.entry,projectPath:t,x:C.x,y:C.y,onClose:()=>w(null),onDuplicate:e=>{S(e)}}),(0,V.jsx)(el,{open:N.conflict!==null,conflicts:N.conflict?.conflicts??[],totalCount:N.conflict?.files.length??0,targetLabel:N.conflict?.targetPath??`.`,onResolve:(e,t)=>N.resolveConflict(e,t),onCancel:N.cancelConflict})]})}var il=new Set([`.git`,`.DS_Store`,`Thumbs.db`]);function al(e){return e?e===`.`||e===`..`?`Name cannot be '.' or '..'.`:e.includes(`/`)||e.includes(`\\`)?`Name cannot contain '/' or '\\'.`:/[\x00-\x1f\x7f]/.test(e)?`Name contains control characters.`:il.has(e)?`'${e}' is reserved and won't appear in the tree.`:null:`Name cannot be empty.`}function ol({paneId:e,projectId:t,worktreePath:n,initialExpanded:i,fileChangeSeq:a,onExpandedPathsChange:o,onSelectFile:s,selectedFilePath:c,gitFileStatuses:l}){let u=P(t),[d,f]=(0,B.useState)(i),[m,g]=(0,B.useState)(0),[v,y]=(0,B.useState)(0),b=(0,B.useCallback)((t,n)=>{f(r=>{let i=n?[...r,t]:r.filter(e=>e!==t);return o?.(e,i),i})},[e,o]),x=(0,B.useCallback)(()=>{g(e=>e+1)},[]),S=(0,B.useCallback)(async e=>{let r=e===`file`?`New file name`:`New folder name`,i=window.prompt(r)?.trim();if(!i)return;let a=al(i);if(a){window.alert(a);return}let o=e===`file`?await j({projectId:t,path:i,content:``,...n?{worktreePath:n}:{}}):await A({projectId:t,path:i,...n?{worktreePath:n}:{}});if(!o.ok){let t=await o.text().catch(()=>``);window.alert(`Failed to create ${e}${t?`: ${t}`:``}`);return}x()},[t,n,x]);return(0,V.jsxs)(`div`,{className:`flex h-full flex-col bg-bg-primary text-text-primary`,children:[(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(rl,{projectId:t,projectPath:n??u?.path,worktreePath:n,expandedPaths:d,onToggleExpand:b,onSelectFile:s,selectedFilePath:c,fileChangeSeq:a,manualRefreshSeq:m,gitFileStatuses:l,onRootCountChange:y})}),(0,V.jsx)(r,{status:`${v} ${v===1?`file`:`files`}`,actions:(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,V.jsx)(p,{align:`end`,placement:`top`,items:[{id:`new-file`,label:`New file`,onSelect:()=>{S(`file`)}},{id:`new-folder`,label:`New folder`,onSelect:()=>{S(`folder`)}}],renderTrigger:({toggle:e,triggerRef:t,menuId:n,open:r})=>(0,V.jsx)(_,{ref:t,onClick:e,"aria-haspopup":`menu`,"aria-expanded":r,"aria-controls":n,label:`New file or folder`,children:(0,V.jsx)(h.add,{})})}),(0,V.jsx)(_,{onClick:x,label:`Refresh`,children:(0,V.jsx)(h.refresh,{})})]})})]})}var sl=15,cl=85;function ll(e){return`parasor:pane-ratio:${e}`}function ul(e){return Number.isNaN(e)?sl:Math.min(cl,Math.max(sl,e))}function dl(e,t){try{let n=localStorage.getItem(ll(e));if(!n)return t;let r=JSON.parse(n);if(!Array.isArray(r)||r.length!==2)return t;let[i,a]=r;if(typeof i!=`number`||typeof a!=`number`)return t;let o=ul(i/(i+a)*100);return[o,100-o]}catch{return t}}function fl(e,t){try{localStorage.setItem(ll(e),JSON.stringify(t))}catch{}}function pl({storageKey:e,defaultRatio:t,primary:n,secondary:r,isMobile:i,secondaryActive:a=!1}){let[o,s]=(0,B.useState)(()=>dl(e,t)),c=(0,B.useRef)(null),l=(0,B.useRef)(!1);(0,B.useEffect)(()=>{fl(e,o)},[e,o]);let u=(0,B.useCallback)(e=>{e.preventDefault(),e.target.setPointerCapture(e.pointerId),l.current=!0},[]),d=(0,B.useCallback)(e=>{if(!l.current)return;let t=c.current?.getBoundingClientRect();if(!t)return;let n=ul((e.clientX-t.left)/t.width*100);s([n,100-n])},[]),f=(0,B.useCallback)(e=>{l.current=!1;try{e.target.releasePointerCapture(e.pointerId)}catch{}},[]),p=(0,B.useCallback)(e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=e.key===`ArrowLeft`?-1:1,n=e.shiftKey?5:1;s(([e])=>{let r=ul(e+t*n);return[r,100-r]})},[]);return i?(0,V.jsx)(`div`,{className:`flex h-full w-full flex-col overflow-hidden`,children:(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:a?r:n})}):(0,V.jsxs)(`div`,{ref:c,className:`cm-worktree-split flex h-full w-full flex-row overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`cm-split-left min-w-0 overflow-hidden bg-bg-secondary`,style:{width:`${o[0]}%`},children:n}),(0,V.jsx)(`hr`,{"aria-orientation":`vertical`,"aria-valuenow":Math.round(o[0]),"aria-valuemin":sl,"aria-valuemax":cl,tabIndex:0,onPointerDown:u,onPointerMove:d,onPointerUp:f,onPointerCancel:f,onKeyDown:p,className:`cm-split-resizer relative z-[2] w-px shrink-0 cursor-col-resize bg-border before:absolute before:inset-y-0 before:-inset-x-3 before:content-[''] focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`}),(0,V.jsx)(`div`,{className:`cm-split-right min-w-0 flex-1 overflow-hidden`,style:{width:`${o[1]}%`},children:r})]})}var ml=`parasor:files-pane-selection:`,hl=new Map,gl=new Set;function _l(e){try{return localStorage.getItem(`${ml}${e}`)}catch{return null}}function vl(e){return hl.has(e)||hl.set(e,_l(e)),hl.get(e)??null}function yl(e,t){hl.set(e,t);try{t===null?localStorage.removeItem(`${ml}${e}`):localStorage.setItem(`${ml}${e}`,t)}catch{}for(let e of gl)e()}function bl(e,t){yl(e,t)}function xl(e){return gl.add(e),()=>{gl.delete(e)}}function Sl(e){return[(0,B.useSyncExternalStore)(xl,()=>e===null?null:vl(e),()=>null),(0,B.useCallback)(t=>{e!==null&&yl(e,t)},[e])]}var Cl=[{value:`files`,label:`Files`,glyph:(0,V.jsx)(h.files,{})},{value:`git`,label:`Git`,glyph:(0,V.jsx)(h.git,{})}];function wl({activeTab:e,onChangeTab:t}){return(0,V.jsx)(`div`,{role:`tablist`,"aria-label":`Worktree view`,className:`flex h-full`,children:Cl.map(n=>{let r=n.value===e;return(0,V.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>t(n.value),className:`inline-flex flex-1 items-center justify-center gap-2 text-sm transition-colors ${r?`bg-bg-primary font-semibold text-text-primary`:`bg-transparent font-medium text-text-secondary hover:bg-row-hover-bg hover:text-text-primary`}`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:r?`text-accent`:void 0,children:n.glyph}),(0,V.jsx)(`span`,{children:n.label})]},n.value)})})}var Tl=(0,B.lazy)(()=>Do(async()=>{let{EditorPane:e}=await import(`./EditorPane-CzzT3iYY.js`);return{EditorPane:e}},[]).then(({EditorPane:e})=>({default:e})));function El({paneId:e,projectId:t,worktreePath:n,fileChangeSeq:r,gitFileStatuses:i,isMobile:a,onChangeTab:o}){let[s,c]=Sl(e),l=(0,B.useCallback)(e=>{c(e)},[c]);return(0,V.jsx)(pl,{storageKey:`worktree`,defaultRatio:Oe,isMobile:a,secondaryActive:s!==null,primary:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,V.jsx)(`div`,{className:`hidden h-bar shrink-0 border-b border-border bg-tab-strip-bg md:block`,children:(0,V.jsx)(wl,{activeTab:`files`,onChangeTab:o})}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(ol,{paneId:e,projectId:t,worktreePath:n,initialExpanded:[],fileChangeSeq:r,onSelectFile:l,selectedFilePath:s,gitFileStatuses:i})})]}),secondary:s?(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(Dl,{}),children:(0,V.jsx)(Tl,{paneId:`${e}:editor`,projectId:t,worktreePath:n,filePath:s,fileChangeSeq:r})}):(0,V.jsx)(Ol,{})})}function Dl(){return(0,V.jsxs)(`div`,{className:`flex h-full flex-col bg-bg-primary text-text-primary`,children:[(0,V.jsx)(i,{icon:(0,V.jsx)(h.doc,{}),title:`Editor`}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1`})]})}function Ol(){return(0,V.jsxs)(`div`,{className:`flex h-full flex-col bg-bg-primary text-text-primary`,children:[(0,V.jsx)(i,{icon:(0,V.jsx)(h.doc,{}),title:`Editor`}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 p-3 text-sm text-text-secondary`,children:`Select a file to view or edit.`})]})}function kl(e){return e?new Date(e*1e3).toLocaleString(void 0,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,hour12:!1}):``}function Al({projectId:e,worktreePath:t,fileChangeSeq:n,commit:r}){let[a,o]=(0,B.useState)(``),[s,c]=(0,B.useState)(!0),l=!!r,u=r?.sha??null,d=(0,B.useRef)(null),f=(0,B.useCallback)(async()=>{d.current?.abort();let n=new AbortController;d.current=n,c(!0);try{let r=await Ms({projectId:e,worktreePath:t,...u?{sha:u}:{}},n.signal);if(n.signal.aborted)return;r!==null&&o(r)}catch{}finally{n.signal.aborted||c(!1)}},[e,t,u]),p=(0,B.useRef)(null);(0,B.useEffect)(()=>(p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{f()},300),()=>{p.current&&clearTimeout(p.current),d.current?.abort()}),[f,n]);let m=(0,B.useMemo)(()=>Be(a),[a]);return(0,V.jsxs)(`div`,{className:`flex h-full flex-col bg-bg-primary text-text-primary`,children:[(0,V.jsx)(i,{icon:(0,V.jsx)(h.diff,{}),title:l?`Commit`:`Diff`}),(0,V.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:[r&&(0,V.jsx)(jl,{commit:r}),s?(0,V.jsx)(`div`,{className:`cm-mono p-3 text-sm text-text-secondary`,children:`Loading...`}):m.length===0?(0,V.jsx)(`div`,{className:`cm-mono p-3 text-sm text-text-secondary`,children:`No changes`}):m.map(e=>(0,V.jsx)(Ve,{file:e},`${e.status}:${e.oldPath??``}:${e.path}`))]})]})}function jl({commit:e}){let t=e.sha.slice(0,7),n=kl(e.time);return(0,V.jsxs)(`div`,{className:`border-b border-border px-3 py-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-baseline gap-2 text-sm`,children:[(0,V.jsx)(`span`,{className:`cm-mono shrink-0 text-text-secondary/70`,title:e.sha,children:t}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 break-words font-semibold text-text-primary`,children:e.subject})]}),(0,V.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-baseline gap-x-2 gap-y-1 text-xs text-text-secondary`,children:[(0,V.jsx)(`span`,{title:e.author,children:e.author}),(0,V.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,V.jsx)(`span`,{className:`cm-mono`,children:n})]})]})}var Ml=5,Nl=16,Pl=6,Fl=4,Il=2,Ll=22,q=26,J=200,Y=`gitGraph:includeRemotes:`;function X(e){return Pl+Math.min(Math.max(e,0),Ml-1)*Nl+Pl}function Z(e){return Pl+Math.min(Math.max(e,0),Ml-1)*Nl}function Rl(e){return`var(--theme-graph-branch-${e%5+1})`}var zl=`var(--theme-graph-ref-base)`,Bl=zl;function Vl(e){return e.refs.some(e=>e.type===`head`)}function Hl(e){let t=new Map(e.map(e=>[e.sha,e])),n=e.find(Vl),r=new Set,i=n;for(;i&&!r.has(i.sha);){r.add(i.sha);let e=i.parents[0];i=e?t.get(e):void 0}return r}var Ul={dot:!1,input:new Set,output:new Set};function Wl(e){let t=Hl(e),n=new Map,r=null,i=e=>{let t=n.get(e);return t||(t={dot:!1,input:new Set,output:new Set},n.set(e,t)),t},a=e=>{let t=r;if(!t)return-1;let n=e.inputSwimlanes[t.index];return n&&Jl(n,t.snapshot)?t.index:e.inputSwimlanes.findIndex(e=>e!==null&&Jl(e,t.snapshot))},o=e=>{let n=e.parents[0];if(!n||!t.has(n))return-1;let r=e.outputSwimlanes[e.lane];return r&&r.colorId===e.colorId&&r.expectingSha===n?e.lane:e.outputSwimlanes.findIndex(t=>t!==null&&t.colorId===e.colorId&&t.expectingSha===n)};for(let n of e){let e=i(n.sha),s=a(n);if(s!==-1&&e.input.add(s),t.has(n.sha)){e.dot=!0;let t=o(n);if(t!==-1){e.output.add(t);let i=n.outputSwimlanes[t];r=i?{snapshot:i,index:t}:null}else r=null;continue}if(s===-1)continue;let c=n.inputSwimlanes[s],l=c?n.outputSwimlanes.findIndex((e,t)=>t===s&&e!==null&&Jl(e,c)):-1,u=l!==-1&&c?l:c?n.outputSwimlanes.findIndex(e=>e!==null&&Jl(e,c)):-1;if(u!==-1){e.output.add(u);let t=n.outputSwimlanes[u];r=t?{snapshot:t,index:u}:null}}return n}function Gl(e,t){return t.dot?zl:Rl(e.colorId)}function Kl(e,t,n,r){if(e===n)return`M${e} ${t}V${r}`;let i=(t+r)/2;return`M${e} ${t}C${e} ${i} ${n} ${i} ${n} ${r}`}function ql(e,t,n,r){if(e===t&&t===n)return`M${e} 0V${r}`;let i=r/2,a=`M${e} 0`;if(e===t)a+=`V${i}`;else{let n=i/2;a+=`C${e} ${n} ${t} ${n} ${t} ${i}`}if(t===n)a+=`V${r}`;else{let e=(i+r)/2;a+=`C${t} ${e} ${n} ${e} ${n} ${r}`}return a}function Jl(e,t){return e.colorId===t.colorId&&e.expectingSha===t.expectingSha}function Yl(e,t,n){let{inputSwimlanes:r,outputSwimlanes:i,lane:a,sha:o}=e,s=Z(a),c=t/2,l=[],u=new Set,d=(e,t)=>{if(t!==void 0&&t>=0&&t<i.length&&!u.has(t)&&i[t]!==null&&Jl(i[t],e))return u.add(t),t;for(let t=0;t<i.length;t++){if(u.has(t))continue;let n=i[t];if(n!==null&&Jl(n,e))return u.add(t),t}return-1},f=r.findIndex(e=>e!==null&&e.expectingSha===o),p=-1;if(f!==-1){let t=i[f]??null,n=e.parents[0]??null;t!==null&&t.colorId===e.colorId&&t.expectingSha===n&&(p=f,u.add(f))}return r.forEach((e,r)=>{if(!e)return;let i=r>=Ml,u=Z(r);if(e.expectingSha===o){if(r===f&&p!==-1){let a=Z(p),o=i&&p>=Ml;l.push({d:ql(u,s,a,t),color:n.input.has(r)||n.output.has(p)?zl:Rl(e.colorId),dimmed:o})}else{let t=i&&a>=Ml;l.push({d:Kl(u,0,s,c),color:n.input.has(r)?zl:Rl(e.colorId),dimmed:t})}return}let m=d(e,r);if(m===-1)return;let h=Z(m),g=i&&m>=Ml;l.push({d:Kl(u,0,h,t),color:n.input.has(r)||n.output.has(m)?zl:Rl(e.colorId),dimmed:g})}),i.forEach((e,r)=>{if(!e||u.has(r))return;let i=Z(r),o=r>=Ml&&a>=Ml;l.push({d:Kl(s,c,i,t),color:n.output.has(r)?zl:Rl(e.colorId),dimmed:o})}),l}function Xl(e){if(typeof window>`u`)return!0;try{let t=window.localStorage.getItem(Y+e);return t===null?!0:t===`1`}catch{return!0}}function Zl(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(Y+e,t?`1`:`0`)}catch{}}function Ql(e){let t=e.lane;return e.inputSwimlanes.length-1>t&&(t=e.inputSwimlanes.length-1),e.outputSwimlanes.length-1>t&&(t=e.outputSwimlanes.length-1),t}function $l(e){return[...e].sort((e,t)=>e.label.length-t.label.length)}function eu({projectId:e,worktreePath:t,refreshSeq:n,selection:i,onSelect:a,actions:o,ahead:s,behind:c,isMobile:l,currentBranch:u}){let d=l?q:Ll,[f,p]=(0,B.useState)(null),[m,g]=(0,B.useState)(!1),[v,y]=(0,B.useState)(null),[b,x]=(0,B.useState)(()=>Xl(t)),[S,C]=(0,B.useState)(!1),[w,T]=(0,B.useState)(!1),[E,D]=(0,B.useState)(!1),[O,k]=(0,B.useState)(null),ee=(0,B.useRef)(null),A=(0,B.useRef)(null),j=(0,B.useRef)(0),te=(0,B.useRef)(null),ne=(0,B.useRef)(null),M=(0,B.useRef)(!1),N=(0,B.useCallback)(async()=>{te.current?.abort(),ne.current?.abort();let n=new AbortController;te.current=n;let r=++j.current;y(null),C(!1);try{let i=await zs({projectId:e,worktreePath:t,limit:J,includeRemotes:b,signal:n.signal});if(r!==j.current)return;p(i.commits),g(i.hasUncommitted),i.commits.length<J&&C(!0)}catch(e){if(n.signal.aborted||r!==j.current)return;y(e instanceof ks||e instanceof Error?e.message:String(e)),p([]),C(!0)}},[e,t,b]),re=(0,B.useCallback)(async()=>{if(M.current||w||S||!f||f.length===0)return;M.current=!0,ne.current?.abort();let n=new AbortController;ne.current=n;let r=j.current,i=f.length;T(!0);try{let a=await zs({projectId:e,worktreePath:t,limit:J,skip:i,includeRemotes:b,signal:n.signal});if(r!==j.current)return;p(e=>{if(!e)return a.commits;let t=new Set(e.map(e=>e.sha)),n=a.commits.filter(e=>!t.has(e.sha));return[...e,...n]}),a.commits.length<J&&C(!0)}catch(e){if(n.signal.aborted||r!==j.current)return;y(e instanceof ks||e instanceof Error?e.message:String(e)),C(!0)}finally{M.current=!1,T(!1)}},[e,t,b,f,w,S]);(0,B.useEffect)(()=>{x(Xl(t))},[t]),(0,B.useEffect)(()=>{N()},[N,n]),(0,B.useEffect)(()=>()=>{te.current?.abort(),ne.current?.abort()},[]),(0,B.useEffect)(()=>{if(!ee.current||!A.current||S)return;let e=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&re()},{root:A.current,rootMargin:`200px 0px`});return e.observe(ee.current),()=>e.disconnect()},[re,S,f?.length??0]);let ie=(0,B.useCallback)(()=>{x(e=>{let n=!e;return Zl(t,n),n})},[t]);(0,B.useEffect)(()=>{k(null)},[e,t]);let ae=(0,B.useCallback)(async n=>{if(cu(n)&&!(n.type===`local`&&n.label===u)&&!(m&&!window.confirm(`Switch branches with uncommitted changes? Git may refuse if files would be overwritten.`))){D(!0),k(null);try{if(n.type===`local`)await Ls({projectId:e,worktreePath:t,branch:n.label});else if(n.type===`remote`){let r=au(n.label);try{await Rs({projectId:e,worktreePath:t,branch:r,startPoint:n.label})}catch(n){if(!tu(n,r))throw n;await Ls({projectId:e,worktreePath:t,branch:r})}}await N()}catch(e){let t=e instanceof ks||e instanceof Error?e.message:`Branch operation failed`;k(`${n.label}: ${t}`)}finally{D(!1)}}},[u,m,e,N,t]),P=(0,B.useMemo)(()=>f===null?`loading…`:v?`error`:`${f.length} commit${f.length===1?``:`s`}${S?``:`…`}${b?` · all branches`:` · HEAD`}`,[f,v,S,b]),F=(0,B.useMemo)(()=>Wl(f??[]),[f]),I=(0,B.useMemo)(()=>ou(f??[]),[f]);return(0,V.jsxs)(`div`,{className:`flex h-full flex-col bg-bg-primary text-text-primary`,children:[(0,V.jsxs)(`div`,{ref:A,className:`cm-scroll cm-mono min-h-0 flex-1 overflow-auto py-1 text-sm`,children:[v&&(0,V.jsx)(`div`,{className:`px-3 py-2 text-xs text-danger`,children:v}),O&&(0,V.jsx)(uu,{error:O,onDismiss:()=>k(null)}),m&&(0,V.jsx)(ru,{selected:i?.kind===`working-tree`,onSelect:()=>a({kind:`working-tree`}),rowHeight:d,headLane:f?.[0]?.lane??null}),(f??[]).map((e,t)=>(0,V.jsx)(iu,{commit:e,selected:i?.kind===`commit`&&i.commit.sha===e.sha,onSelect:()=>a({kind:`commit`,commit:e}),rowHeight:d,topConnectFromAbove:m&&t===0,currentMark:F.get(e.sha)??Ul,currentBranch:u,localBranches:I,branchBusy:E,onBranchRefSelect:ae},e.sha)),f?.length===0&&!v&&(0,V.jsx)(`div`,{className:`px-3 py-3 text-xs text-text-secondary`,children:`No commits yet.`}),!S&&f&&f.length>0&&(0,V.jsx)(`div`,{ref:ee,className:`px-3 py-2 text-center text-xs text-text-secondary/60`,"aria-live":`polite`,"data-testid":`git-graph-sentinel`,children:w?`loading more…`:``})]}),(0,V.jsx)(r,{status:P,actions:(0,V.jsxs)(V.Fragment,{children:[o?.onPull&&(0,V.jsx)(nu,{onClick:o.onPull,label:`Pull`,direction:`behind`,count:c,glyph:(0,V.jsx)(h.pull,{})}),o?.onPush&&(0,V.jsx)(nu,{onClick:o.onPush,label:`Push`,direction:`ahead`,count:s,glyph:(0,V.jsx)(h.push,{})}),(0,V.jsx)(_,{onClick:ie,label:b?`Hide remote branches`:`Show remote branches`,pressed:b,"data-testid":`git-graph-toggle-remotes`,tone:b?`active`:`normal`,children:b?(0,V.jsx)(h.eye,{}):(0,V.jsx)(h.eyeOff,{})}),(0,V.jsx)(_,{onClick:()=>void N(),label:`Refresh`,children:(0,V.jsx)(h.refresh,{})})]})})]})}function tu(e,t){if(!(e instanceof ks)||e.status!==409)return!1;let n=e.message.toLowerCase();return n.includes(`already exists`)&&n.includes(t.toLowerCase())}function nu({onClick:e,label:t,direction:n,glyph:r,count:i}){let a=typeof i==`number`&&i>0,o=a?i>99?`99+`:String(i):null;return(0,V.jsxs)(_,{onClick:e,label:a?`${t} (${i} ${i===1?`commit`:`commits`} ${n})`:t,className:`relative`,children:[r,o!==null&&(0,V.jsx)(`span`,{"aria-hidden":!0,className:`absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-tag bg-accent px-1 text-[11px] leading-none font-bold text-white drop-shadow-sm`,children:o})]})}function ru({selected:e,onSelect:t,rowHeight:n,headLane:r}){let i=r??0,a=Z(i),o=X(i),s=n/2,c=Bl;return(0,V.jsxs)(`button`,{type:`button`,onClick:t,className:`flex w-full items-center gap-0 px-3 text-left ${e?`bg-row-selected-bg`:`hover:bg-row-hover-bg`}`,style:{height:n,lineHeight:`${n}px`},"data-testid":`git-graph-working-tree-row`,children:[(0,V.jsxs)(`svg`,{"aria-hidden":!0,width:o,height:n,className:`flex-none`,style:{overflow:`visible`},shapeRendering:`geometricPrecision`,children:[c!==null&&(0,V.jsx)(`path`,{d:`M${a} ${s}V${n}`,stroke:c,strokeWidth:Il,strokeLinecap:`round`,fill:`none`}),(0,V.jsx)(`circle`,{cx:a,cy:s,r:Fl,fill:`var(--color-bg-primary)`,stroke:Bl,strokeWidth:1.5,strokeDasharray:`1.4 1`})]}),(0,V.jsx)(`span`,{className:`ml-2 min-w-0 flex-1 truncate text-text-primary`,style:{fontWeight:e?600:500},children:`Working tree (uncommitted)`})]})}function iu({commit:e,selected:t,onSelect:n,rowHeight:r,topConnectFromAbove:i=!1,currentMark:a,currentBranch:o,localBranches:s,branchBusy:c,onBranchRefSelect:l}){let u=Yl(e,r,a),d=Z(e.lane),f=Gl(e,a),p=e.lane>=Ml,m=Vl(e),h=$l(e.refs),g=i?{d:`M${d} 0V${r/2}`,color:f}:null,_=X(Ql(e));return(0,V.jsxs)(`div`,{className:`flex w-full items-center gap-2 px-3 ${t?`bg-row-selected-bg`:`hover:bg-row-hover-bg`}`,style:{height:r,lineHeight:`${r}px`},"data-testid":`git-graph-commit-row`,"data-lane":e.lane,"data-color-id":e.colorId,"data-head":m?`1`:void 0,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:n,className:`flex min-w-0 flex-1 items-center gap-2 text-left`,children:[(0,V.jsxs)(`svg`,{"aria-hidden":!0,width:_,height:r,className:`flex-none`,style:{overflow:`visible`},shapeRendering:`geometricPrecision`,children:[g!==null&&(0,V.jsx)(`path`,{d:g.d,stroke:g.color,strokeWidth:Il,strokeLinecap:`round`,fill:`none`},`${e.sha}-top-from-above`),u.map(t=>(0,V.jsx)(`path`,{d:t.d,stroke:t.color,strokeWidth:Il,strokeLinecap:`round`,fill:`none`,opacity:t.dimmed?.35:1},`${e.sha}:${t.d}:${t.color}:${t.dimmed?`dim`:`full`}`)),m?(0,V.jsx)(`circle`,{cx:d,cy:r/2,r:Fl,fill:`var(--color-bg-primary)`,stroke:f,strokeWidth:2,opacity:p?.55:1}):(0,V.jsx)(`circle`,{cx:d,cy:r/2,r:Fl,fill:f,stroke:`none`,opacity:p?.55:1})]}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,style:{fontWeight:t?600:400},children:e.subject})]}),h.length>0&&(0,V.jsx)(`span`,{className:`flex-none flex flex-row items-center gap-1 overflow-hidden`,style:{maxWidth:`60%`},children:h.map(t=>(0,V.jsx)(fu,{ref:t,laneColor:f,current:su(t,o,s),localBranches:s,busy:c,onSelect:l},`${e.sha}:${t.type}:${t.label}`))})]})}function au(e){let t=e.split(`/`).filter(Boolean);return t.length>1?t.slice(1).join(`/`):e}function ou(e){let t=new Set;for(let n of e)for(let e of n.refs)e.type===`local`&&t.add(e.label);return t}function su(e,t,n){if(!t)return!1;if(e.type===`local`)return e.label===t;if(e.type!==`remote`)return!1;let r=au(e.label);return n.has(r)&&r===t}function cu(e){return e.type===`local`||e.type===`remote`&&!lu(e)}function lu(e){return e.type===`remote`&&e.label.endsWith(`/HEAD`)}function uu({error:e,onDismiss:t}){return(0,V.jsx)(`div`,{className:`mx-2 mb-1 rounded-control border border-danger/40 bg-bg-secondary px-2 py-1.5 text-xs text-text-primary`,children:(0,V.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,V.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-danger`,children:e}),(0,V.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Dismiss branch error`,className:`shrink-0 rounded-control px-2 py-1 text-text-secondary hover:bg-row-hover-bg hover:text-text-primary`,children:`Dismiss`})]})})}function du(e,t){if(e.type===`head`)return{color:`var(--color-bg-primary)`,background:t,border:`none`};let n=e.type===`remote`?`dashed`:e.type===`tag`?`dotted`:`solid`;return{color:t,background:`color-mix(in oklab, ${t} 14%, transparent)`,border:`1px ${n} color-mix(in oklab, ${t} 45%, transparent)`}}function fu({ref:e,laneColor:n,current:r=!1,localBranches:i,busy:a=!1,onSelect:o}){let s=`cm-mono inline-block rounded-tag px-[5px] align-[1px] text-xs whitespace-nowrap`;return cu(e)&&o?(0,V.jsx)(t,{items:pu(e,r,i,a,o),align:`start`,portal:!0,renderTrigger:({open:t,toggle:i,triggerRef:a,menuId:o})=>(0,V.jsx)(`button`,{ref:a,type:`button`,"data-ref-type":e.type,"data-current-branch":r?`1`:void 0,className:`${s} cursor-pointer hover:brightness-125`,style:du(e,n),"aria-haspopup":`menu`,"aria-expanded":t,"aria-controls":o,"aria-label":`Branch actions for ${e.label}`,onClick:e=>{e.stopPropagation(),i()},children:e.label})}):(0,V.jsx)(`span`,{"data-ref-type":e.type,className:s,style:du(e,n),children:e.label})}function pu(e,t,n,r,i){if(e.type===`local`)return[{id:`switch`,label:t?`Current branch`:`Switch`,disabled:t||r,onSelect:()=>{i(e)}}];if(e.type===`remote`){let a=au(e.label);return n.has(a)?[{id:`switch`,label:t?`Current branch`:`Switch`,disabled:t||r,onSelect:()=>{i({label:a,type:`local`})}}]:[{id:`create-switch`,label:`Create & switch`,disabled:r,onSelect:()=>{i(e)}}]}return[]}function mu({projectId:e,projectPath:t}){let[n,r]=(0,B.useState)(!1),[i,o]=(0,B.useState)(null);async function s(){r(!0),o(null);try{await Bs(e),ho({tone:`ok`,title:`Initialized git repository`,sub:t??void 0,mono:!0,durationMs:4e3})}catch(e){o(e instanceof ks||e instanceof Error?e.message:`git init failed`)}finally{r(!1)}}return(0,V.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-bg-primary p-8 text-center`,children:[(0,V.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,V.jsx)(`span`,{className:`cm-mono text-sm font-semibold tracking-[-0.005em] text-text-primary`,children:`No git repository`}),(0,V.jsx)(`span`,{className:`text-sm text-text-secondary`,children:`This project is not a git repository yet.`}),t&&(0,V.jsx)(`span`,{className:`cm-mono mt-0.5 truncate text-xs text-text-secondary/70`,children:t})]}),(0,V.jsx)(a,{kind:`submit`,size:`sm`,onClick:()=>void s(),disabled:n,children:n?`Initializing…`:`Initialize git repository`}),i&&(0,V.jsx)(`span`,{className:`text-xs text-danger`,role:`alert`,children:i})]})}function hu({projectId:e,worktreePath:t,fileChangeSeq:n,files:o,busy:s,error:c,onClearError:l,onSubmit:u}){let[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(()=>new Set(o.map(e=>e.path))),[g,_]=(0,B.useState)(``),v=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(o.length===0){_(``);return}v.current?.abort();let n=new AbortController;return v.current=n,Ms({projectId:e,worktreePath:t},n.signal).then(e=>{e===null||n.signal.aborted||_(e)}).catch(()=>{}),()=>{n.abort()}},[e,t,n,o.length]);let y=(0,B.useMemo)(()=>{let e=new Map;for(let t of Be(g))e.set(t.path,t);return e},[g]);(0,B.useEffect)(()=>{let e=new Set(o.map(e=>e.path));m(t=>{let n=new Set;for(let r of t)e.has(r)&&n.add(r);for(let e of o)t.has(e.path)||n.add(e.path);return n})},[o]);let b=d.trim(),x=!s&&b.length>0&&p.size>0,S=Math.max(0,(d.split(`
34
- `,1)[0]?.length??0)-72);function C(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function w(e){m(e?new Set(o.map(e=>e.path)):new Set)}function T(){x&&(u({message:b,paths:Array.from(p)}),f(``))}return(0,V.jsxs)(`div`,{className:`flex h-full flex-col bg-bg-primary text-text-primary`,children:[(0,V.jsx)(i,{icon:(0,V.jsx)(h.diff,{}),iconTone:`warning`,title:`Working tree`}),o.length===0?(0,V.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-4 text-center text-sm text-text-secondary`,children:`No uncommitted changes.`}):(0,V.jsx)(Ke,{files:o,selected:p,toggle:C,toggleAll:w,message:d,setMessage:f,layout:`inline`,diffsByPath:y}),c&&(0,V.jsxs)(`div`,{className:`flex items-start gap-2 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[(0,V.jsx)(`span`,{className:`flex-1`,children:c}),(0,V.jsx)(`button`,{type:`button`,onClick:l,"aria-label":`Dismiss`,className:`text-danger/80 hover:text-danger`,children:(0,V.jsx)(h.close,{})})]}),(0,V.jsx)(r,{status:(0,V.jsxs)(V.Fragment,{children:[p.size,`/`,o.length,` selected`,S>0&&(0,V.jsxs)(`span`,{className:`ml-3 text-danger`,children:[`subject +`,S,` over`]})]}),actions:(0,V.jsx)(a,{kind:`submit`,onClick:T,disabled:!x,className:`shrink-0`,children:s?`Committing…`:`Commit`})})]})}function gu(e,t){return[e,t?.branch??``,t?.ahead??``,t?.behind??``,t?.dirtyCount??``,t?.isRepo===!1?`non-repo`:`repo`].join(`:`)}function _u({projectId:e,worktreePath:t,fileChangeSeq:n,isMobile:r,gitState:i,projectPath:a,selection:o,onSelectionChange:s,commitBusy:c,commitError:l,onClearCommitError:u,onSubmitInlineCommit:d,onChangeTab:f,gitActions:p}){let m=(0,B.useMemo)(()=>{let e=i?.fileStatuses;return e?Object.entries(e).map(([e,t])=>({path:e,status:t})).sort((e,t)=>e.path.localeCompare(t.path)):[]},[i?.fileStatuses]);if(i?.isRepo===!1)return(0,V.jsx)(mu,{projectId:e,projectPath:a});let h=o?.kind===`working-tree`,g=gu(n,i);return(0,V.jsx)(pl,{storageKey:`worktree`,defaultRatio:Oe,isMobile:r,secondaryActive:o!==null,primary:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,V.jsx)(`div`,{className:`hidden h-bar shrink-0 border-b border-border bg-tab-strip-bg md:block`,children:(0,V.jsx)(wl,{activeTab:`git`,onChangeTab:f})}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(eu,{projectId:e,worktreePath:t,refreshSeq:g,selection:o,onSelect:s,isMobile:r,currentBranch:i?.branch,ahead:i?.ahead,behind:i?.behind,...p&&{actions:p}})})]}),secondary:h?(0,V.jsx)(hu,{projectId:e,worktreePath:t,fileChangeSeq:n,files:m,busy:c,error:l,onClearError:u,onSubmit:e=>void d(e)}):(0,V.jsx)(Al,{projectId:e,worktreePath:t,fileChangeSeq:n,commit:o?.kind===`commit`?o.commit:null})})}var vu=350,yu=5;function bu(e,t){let[n,r]=(0,B.useState)(!1),i=(0,B.useRef)(!1),a=(0,B.useRef)(null),o=(0,B.useRef)(null),s=(0,B.useCallback)(()=>{o.current&&=(clearTimeout(o.current),null),a.current=null,i.current=!1,r(!1)},[]);return(0,B.useEffect)(()=>()=>s(),[s]),{onTouchStart:(0,B.useCallback)(t=>{if(!e)return;let n=t.touches[0];if(n){if(o.current&&=(clearTimeout(o.current),null),t.touches.length>1){a.current=null,i.current=!1,r(!1);return}a.current={x:n.clientX,y:n.clientY},i.current=!1,r(!1),o.current=setTimeout(()=>{i.current=!0,r(!0)},vu)}},[e]),onTouchMove:(0,B.useCallback)(e=>{let t=a.current;if(!t)return;let n=e.touches[0];if(!n)return;let r=n.clientX-t.x,i=n.clientY-t.y;Math.hypot(r,i)>yu&&s()},[s]),onTouchEnd:(0,B.useCallback)(n=>{if(!i.current||!e){s();return}n.preventDefault(),s(),xu(e,t)},[s,e,t]),onTouchCancel:(0,B.useCallback)(()=>{s()},[s]),armed:n}}async function xu(e,t){try{if(navigator.clipboard?.writeText)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t)}Qa(t?`Copied ${t}`:`Copied`)}catch{Qa(`Copy failed`)}}function Su({crumbs:e,onBack:t,onToggleDrawer:n,view:r,onChangeView:i,dirty:a,pin:o,onClose:s,moreMenuItems:c}){let l=(a??0)>0,u=new Map;return(0,V.jsxs)(`div`,{className:`relative shrink-0 border-b border-border bg-bg-secondary`,role:`toolbar`,"aria-label":`Workspace`,children:[(0,V.jsxs)(`div`,{className:`flex h-bar items-center gap-2 px-2 md:px-3`,children:[t?(0,V.jsx)(_,{onClick:t,label:`Back`,size:`md`,tone:`active`,className:`md:hidden`,children:(0,V.jsx)(h.back,{})}):(0,V.jsx)(_,{onClick:n,label:`Go to sessions`,size:`md`,tone:`active`,className:`md:hidden`,children:(0,V.jsx)(h.menu,{})}),(0,V.jsx)(`div`,{className:`-ml-2 flex min-w-0 flex-1 items-center gap-1 text-sm font-semibold tracking-[-0.005em] md:ml-0 md:gap-1.5 md:px-1`,children:e.map((t,n)=>{let r=n===e.length-1,i=u.get(t.label)??0;return u.set(t.label,i+1),(0,V.jsx)(Cu,{crumb:t,showSep:n>0,isLast:r,trailing:r&&o?(0,V.jsx)(xo,{pinned:o.pinned,onToggle:o.onToggle}):void 0},`${t.label}:${i}`)})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[l&&(0,V.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 px-1 text-sm font-medium text-[var(--theme-git-modified)]`,title:`${a} uncommitted changes`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-tag bg-[var(--theme-git-modified)]`}),a,`Δ`]}),s&&(0,V.jsx)(Nc,{onClick:s}),c&&c.length>0&&(0,V.jsx)(p,{align:`end`,items:c,renderTrigger:({toggle:e,triggerRef:t,menuId:n,open:r})=>(0,V.jsx)(_,{ref:t,onClick:e,"aria-haspopup":`menu`,"aria-expanded":r,"aria-controls":n,label:`Workspace menu`,size:`md`,children:(0,V.jsx)(h.more,{})})})]})]}),r!==void 0&&i?(0,V.jsx)(`div`,{className:`h-bar border-t border-border bg-tab-strip-bg md:hidden`,children:(0,V.jsx)(wl,{activeTab:r,onChangeTab:i})}):null]})}function Cu({crumb:e,showSep:t,isLast:n,trailing:r}){let i=bu(e.label,`name`);return(0,V.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,style:{flex:n?`1 1 auto`:`0 1 auto`},children:[t&&(0,V.jsx)(`span`,{"aria-hidden":!0,className:`shrink-0 text-text-secondary/50`,children:`·`}),e.glyph&&(0,V.jsx)(`span`,{"aria-hidden":!0,className:`shrink-0 ${e.dim?`text-text-secondary/70`:`text-accent`}`,children:e.glyph}),(0,V.jsx)(`span`,{title:e.label,onTouchStart:i.onTouchStart,onTouchMove:i.onTouchMove,onTouchEnd:i.onTouchEnd,onTouchCancel:i.onTouchCancel,className:`min-w-0 truncate transition-opacity ${e.dim?`font-medium text-text-secondary/70`:`text-text-primary`} ${i.armed?`opacity-60`:`opacity-100`}`,style:{maxWidth:e.maxWidth},children:e.label}),r]})}function wu({value:e,onSave:t}){let[n,r]=(0,B.useState)(!1),[i,a]=(0,B.useState)(e),[o,s]=(0,B.useState)(null),c=(0,B.useRef)(null),l=(0,B.useRef)(!1);(0,B.useEffect)(()=>{n||a(e)},[n,e]),(0,B.useEffect)(()=>{if(!n||c.current&&document.activeElement===c.current)return;let e=requestAnimationFrame(()=>{c.current?.focus(),c.current?.select()});return()=>cancelAnimationFrame(e)},[n]);let u=(0,B.useCallback)(()=>{(0,nn.flushSync)(()=>r(!0)),c.current?.focus(),c.current?.select()},[]),d=async()=>{let n=i.trim();if(r(!1),s(null),n!==e.trim())try{await t(n)}catch(t){s(t instanceof Error?t.message:`Rename failed`),a(e)}};return n?(0,V.jsx)(`input`,{ref:c,value:i,"aria-label":`Terminal title`,title:o??void 0,onChange:e=>a(e.currentTarget.value),onBlur:()=>{if(l.current){l.current=!1;return}d()},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),d()):t.key===`Escape`&&(t.preventDefault(),l.current=!0,a(e),r(!1),s(null))},className:`h-7 min-w-0 flex-shrink rounded-control border border-accent bg-bg-primary px-1.5 text-sm font-semibold text-text-primary outline-none`}):(0,V.jsx)(`button`,{type:`button`,"aria-label":`Rename terminal`,title:o??e,onClick:u,className:`min-w-0 flex-shrink truncate rounded-control px-1 text-left text-sm font-semibold text-text-primary hover:bg-row-hover-bg focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${o?`text-danger`:``}`,children:e})}var Tu=(0,B.lazy)(()=>Do(async()=>{let{TerminalPane:e}=await import(`./TerminalPane-CjbYzePr.js`);return{TerminalPane:e}},__vite__mapDeps([0])).then(({TerminalPane:e})=>({default:e})));function Eu({paneId:e,state:t,worktreePath:n,session:r,pin:a,onClose:o,onRestartSession:s,onRenameSession:c,onOpenUrl:l,onOpenFilePath:u,onClosePane:d}){let f=wt(r,`shell`),p=r!==void 0&&r.state!==`ended`;return(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:[(0,V.jsx)(i,{icon:(0,V.jsx)(h.terminal,{}),title:f,titleAttr:f,titleElement:r?(0,V.jsx)(wu,{value:f,onSave:e=>c(r.id,e)}):void 0,actions:(0,V.jsxs)(V.Fragment,{children:[p&&(0,V.jsx)(Ou,{sessionId:r.id,paneId:e}),a&&(0,V.jsx)(xo,{pinned:a.pinned,onToggle:a.onToggle}),o&&(0,V.jsx)(Nc,{onClick:o})]})}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`h-full bg-bg-terminal`}),children:(0,V.jsx)(Tu,{paneId:e,sessionId:t.sessionId,session:r,onRestartSession:s,onOpenUrl:l,worktreePath:n,onOpenFilePath:u,onClosePane:d})})})]})}function Du(e){switch(e){case`busy`:return`Capturing terminal diagnostics`;case`ok`:return`Captured terminal diagnostics`;case`error`:return`Failed to capture terminal diagnostics`;case`idle`:return`Capture terminal diagnostics`}}function Ou({sessionId:e,paneId:t}){let[n,r]=(0,B.useState)(`idle`),i=Du(n);return(0,V.jsx)(_,{label:i,title:i,tone:n===`ok`?`accent`:n===`error`?`danger`:`normal`,disabled:n===`busy`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>e.preventDefault(),onClick:()=>{r(`busy`),window.parasorTerminalTrace?.captureTerminalInput(`manual-terminal-button`,{sessionId:e,paneId:t}).then(()=>r(`ok`)).catch(()=>r(`error`))},children:(0,V.jsx)(h.doc,{})})}function ku({children:e}){return(0,V.jsx)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:e})})}function Au({activeProjectId:e,hydrated:t,onNewProject:n}){return t?(0,V.jsxs)(`div`,{className:`relative flex h-full items-center justify-center px-10`,children:[(0,V.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 opacity-30`,style:{backgroundImage:`linear-gradient(var(--color-border) 1px, transparent 1px), linear-gradient(90deg, var(--color-border) 1px, transparent 1px)`,backgroundSize:`42px 42px`,maskImage:`radial-gradient(ellipse 60% 60% at 50% 45%, #000, transparent)`,WebkitMaskImage:`radial-gradient(ellipse 60% 60% at 50% 45%, #000, transparent)`}}),(0,V.jsxs)(`div`,{className:`relative max-w-surface-md text-center`,children:[(0,V.jsx)(`p`,{className:`mb-3.5 text-[32px] font-normal leading-none tracking-normal text-text-primary`,children:`parasor`}),e?(0,V.jsxs)(`p`,{className:`mx-auto max-w-[440px] text-base leading-[1.6] text-text-secondary`,children:[`Pick a worktree from the sidebar, or filter it with`,` `,(0,V.jsxs)(`span`,{className:`inline-flex shrink-0 gap-[3px] align-middle`,children:[(0,V.jsx)(C,{children:`⌘`}),(0,V.jsx)(C,{children:`K`})]}),`.`]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`mb-7 text-base leading-[1.6] text-text-secondary`,children:`No project yet. Add one to get started.`}),(0,V.jsx)(a,{kind:`submit`,size:`sm`,onClick:n,children:`New Project…`})]})]})]}):(0,V.jsx)(`div`,{className:`h-full w-full`})}function ju(e){let t=e.replace(/\/+$/,``).split(`/`);return t[t.length-1]??e}function Mu(e){return`files:${e}`}function Nu({activeProjectId:e,activeProjectName:t,activeProjectPath:n,activeProjectIsRepo:r,allPanes:i=[],focusedPane:a,focusedWorktreeDirName:o,fileChangeSeq:s,gitState:c,hydrated:l,isMobile:u,gitMenuActions:d,gitGraphSelection:f,onGitGraphSelectionChange:p,gitBranchName:m,commitBusy:h,commitError:g,onClearCommitError:_,onSubmitInlineCommit:v,sessions:y,onToggleDrawer:b,onClosePane:x,onRequestClosePane:S,onNewProject:C,onOpenUrl:w,onBrowserUrlChange:T,onRestartSession:E,onRenameSession:D,onSelectWorktreeTab:O,onToggleSessionPin:k,onOpenWorktreeInFinder:ee,onOpenWorktreeInIde:A,ideCommands:j=[],canOpenLocalIde:te=!1,onCopyWorktreePath:ne,onRenameWorktree:M,onRemoveWorktree:N,onDeleteProject:re}){let ie=c?.fileStatuses,ae=c?.dirtyCount??0,P=c?{ahead:c.ahead,behind:c.behind,dirty:c.dirtyCount}:void 0,F=a?.state.kind===`files`?a:null,I=a?.state.kind===`git`?a:null,L=F??I,R=F!==null,oe=I!==null,se=L!==null,[ce,le]=Sl(F?.id??null),ue=R&&ce!==null,de=oe&&f!==null,fe=ue?ju(ce):de?Lu(f):a?Ru(a,y):null,pe=zu(t,o,!!a&&!!n&&a.worktreePath===n,r,m),me=L&&!ue&&!de?L.state.kind:void 0,he=L&&!ue&&!de?e=>O(L.worktreePath,e):void 0,z=ue?()=>le(null):de?()=>p(null):null,ge=a?.state.kind===`terminal`||a?.state.kind===`browser`?a.state.kind:null,_e=a&&ge?()=>S(a.id,ge,fe??`pane`):void 0,ve=a?.state.kind===`terminal`?a.state:null,ye=ve?y.find(e=>e.id===ve.sessionId):void 0,be=ye?{pinned:ye.pinned===!0,onToggle:()=>void k(ye.id)}:null,xe=a?.state.kind===`terminal`||a?.state.kind===`browser`,Se=xe?null:be,Ce=xe?void 0:_e,we=i.length>0?i:a?[a]:[],Te=(e,t)=>{bl(Mu(e),t),O(e,`files`)};kc(u?z:null);let Ee=(0,B.useMemo)(()=>{if(!a||!e)return[];let t=a.worktreePath,n=o??`main`,i=[];if(ee&&i.push({id:`open-finder`,label:`Open in Finder`,onSelect:()=>ee(e,t)}),A){let n=!te,r=n?`Available when parasor is opened from localhost on the server machine`:void 0;i.push({id:`open-cursor`,label:`Open in Cursor`,disabled:n,title:r,onSelect:()=>A(e,t,`cursor`)},{id:`open-vscode`,label:`Open in VS Code`,disabled:n,title:r,onSelect:()=>A(e,t,`vscode`)});for(let a of j)i.push({id:`open-custom-ide:${a.id}`,label:`Open in ${a.label}`,disabled:n,title:r,onSelect:()=>A(e,t,a.id)})}return ne&&i.push({id:`copy-path`,label:`Copy path`,onSelect:()=>ne(t)}),r&&M&&i.push({id:`rename`,label:`Rename branch…`,onSelect:()=>M(e,t,n)}),r&&N&&i.push({id:`remove`,label:`Remove worktree…`,onSelect:()=>N(e,t,n)}),re&&i.push({id:`close-project`,label:`Close project…`,onSelect:()=>re(e)}),i},[a,e,r,o,ee,A,j,te,ne,M,N,re]);return(0,V.jsxs)(`main`,{className:`flex-1 min-w-0 bg-bg-terminal flex flex-col touch-pan-y`,children:[a&&(0,V.jsx)(Su,{crumbs:pe,onBack:z,onToggleDrawer:b,view:me,onChangeView:he,dirty:se?ae:void 0,pin:Se,onClose:Ce,moreMenuItems:Ee}),(0,V.jsx)(`div`,{className:`relative flex-1 overflow-hidden`,children:a&&e?(0,V.jsxs)(V.Fragment,{children:[a.state.kind!==`terminal`&&(0,V.jsx)(`div`,{className:`absolute inset-0 min-h-0 min-w-0`,children:(0,V.jsx)(Iu,{activeProjectId:e,activeProjectPath:n,focusedPane:a,focusedWorktreeDirName:o,fileChangeSeq:s,gitState:c,gitFileStatuses:ie,gitBranchName:m,counters:P,gitMenuActions:d,gitGraphSelection:f,onGitGraphSelectionChange:p,commitBusy:h,commitError:g,onClearCommitError:_,onSubmitInlineCommit:v,isMobile:u,sessions:y,terminalPin:be,terminalOnClose:_e,browserOnClose:_e,onClosePane:x,onOpenUrl:w,onBrowserUrlChange:T,onRestartSession:E,onRenameSession:D,onSelectWorktreeTab:O})}),(0,V.jsx)(Pu,{panes:we,focusedPaneId:a.id,sessions:y,pin:be,onClose:_e,onClosePane:x,onOpenUrl:w,onOpenFilePath:Te,onRestartSession:E,onRenameSession:D})]}):(0,V.jsx)(Au,{activeProjectId:e,hydrated:l,onNewProject:C})})]})}function Pu({panes:e,focusedPaneId:t,sessions:n,pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:s,onRestartSession:c,onRenameSession:l}){return(0,V.jsx)(V.Fragment,{children:e.filter(e=>e.state.kind===`terminal`&&e.id===t).map(e=>{if(e.state.kind!==`terminal`)return null;let t=e.state;return(0,V.jsx)(Fu,{pane:e,state:t,session:n.find(e=>e.id===t.sessionId),pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:s,onRestartSession:c,onRenameSession:l},e.id)})})}function Fu({pane:e,state:t,session:n,pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:s,onRestartSession:c,onRenameSession:l}){let u=(0,B.useRef)(null);return(0,B.useEffect)(()=>{T(`terminal-layer-visibility`,{sessionId:t.sessionId,paneId:e.id,visible:!0});let n=window.requestAnimationFrame(()=>{let n=u.current?.getBoundingClientRect();T(`terminal-layer-layout`,{sessionId:t.sessionId,paneId:e.id,visible:!0,width:n?.width??0,height:n?.height??0})});return()=>window.cancelAnimationFrame(n)},[e.id,t.sessionId]),(0,V.jsx)(`div`,{ref:u,className:`pointer-events-auto absolute inset-0 min-h-0 min-w-0`,children:(0,V.jsx)(Eu,{paneId:e.id,state:t,worktreePath:e.worktreePath,session:n,pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:t=>s(e.worktreePath,t),onRestartSession:c,onRenameSession:l})})}function Iu({activeProjectId:e,activeProjectPath:t,focusedPane:n,focusedWorktreeDirName:r,fileChangeSeq:i,gitState:a,gitFileStatuses:o,counters:s,gitMenuActions:c,gitGraphSelection:l,onGitGraphSelectionChange:u,commitBusy:d,commitError:f,onClearCommitError:p,onSubmitInlineCommit:m,isMobile:h,sessions:g,terminalPin:_,terminalOnClose:v,browserOnClose:y,onClosePane:b,onOpenUrl:x,onBrowserUrlChange:S,onRestartSession:C,onRenameSession:w,onSelectWorktreeTab:T}){let{state:E}=n;switch(E.kind){case`files`:return(0,V.jsx)(ku,{activeTab:`files`,worktreeName:r,worktreePath:n.worktreePath,counters:s,children:(0,V.jsx)(El,{paneId:n.id,projectId:e,worktreePath:n.worktreePath,fileChangeSeq:i,gitFileStatuses:o,isMobile:h,onChangeTab:e=>T(n.worktreePath,e)})});case`terminal`:{let e=g.find(e=>e.id===E.sessionId);return(0,V.jsx)(Eu,{paneId:n.id,state:E,worktreePath:n.worktreePath,session:e,pin:_,onClose:v,onClosePane:b,onOpenUrl:x,onOpenFilePath:e=>{bl(Mu(n.worktreePath),e),T(n.worktreePath,`files`)},onRestartSession:C,onRenameSession:w})}case`browser`:return(0,V.jsx)(Pc,{state:E,paneId:n.id,onClose:y,onUrlChange:S?e=>S(n.id,e):void 0});case`git`:return(0,V.jsx)(ku,{activeTab:`git`,worktreeName:r,worktreePath:n.worktreePath,counters:s,children:(0,V.jsx)(_u,{projectId:e,worktreePath:n.worktreePath,fileChangeSeq:i,isMobile:h,gitState:a,projectPath:t,selection:l,onSelectionChange:u,commitBusy:d,commitError:f,onClearCommitError:p,onSubmitInlineCommit:m,onChangeTab:e=>T(n.worktreePath,e),...c&&{gitActions:c}})})}}function Lu(e){return e.kind===`working-tree`?`Working tree`:e.commit.sha.slice(0,7)}function Ru(e,t){let{state:n}=e;if(n.kind===`terminal`)return wt(t.find(e=>e.id===n.sessionId));if(n.kind===`browser`)try{return new URL(n.url).host||n.url}catch{return n.url}return null}function zu(e,t,n,r,i){let a=[];if(e&&a.push({label:e,maxWidth:96}),t){let e=r?n?(0,V.jsx)(h.worktreeActive,{}):(0,V.jsx)(h.worktreeInactive,{}):(0,V.jsx)(h.folder,{});a.push({label:t,dim:!0,maxWidth:96,glyph:e})}return i&&a.push({label:i,dim:!0,glyph:(0,V.jsx)(h.branch,{})}),a.length===0&&a.push({label:`parasor`}),a}async function Bu(e,t){let n=await O(`/api/projects/${e}/worktrees`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({branch:t.branch,...t.base.length>0&&{base:t.base},...t.copyLocalFiles.length>0&&{copyLocalFiles:t.copyLocalFiles},...t.rememberLocalFiles&&{rememberLocalFiles:!0}})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Request failed (${n.status})`)}let r=await n.json().catch(()=>({})),i=r.path;if(!i)throw Error(`Worktree response missing path`);return{path:i,localFileCopies:r.localFileCopies}}async function Vu(e){let t=await O(`/api/projects/${encodeURIComponent(e)}/worktree-local-files`);if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Request failed (${t.status})`)}return await t.json()}function Hu(e,t){return O(`/api/projects/${e}/worktrees`,{signal:t})}var Uu=200,Q=`parasor:store-cache`,Wu=6,Gu={projects:[],projectStates:{},sessions:[],agentStates:{},notifications:[],ports:{},gitStates:{},serviceConfig:{preventIdleSleep:!1,portDetection:`all-interfaces`,dropSizeMaxBytes:Fe,dropSizeHardMaxBytes:Ie},paneCommands:[],ideCommands:[],hostPlatform:null,fileChangeSeq:0,worktrees:{},pendingOpenUrl:null,connected:!1,hydrated:!1,snapshotApplied:!1};function Ku(e,t){switch(t.type){case`session-created`:return{...e,sessions:[...e.sessions,t.session]};case`session-closed`:{let n={...e.agentStates};return delete n[t.sessionId],{...e,sessions:e.sessions.filter(e=>e.id!==t.sessionId),agentStates:n}}case`session-restarted`:{let n=e.sessions.find(e=>e.id===t.session.id);return n&&t.generation<n.generation?e:{...e,sessions:e.sessions.map(e=>e.id===t.session.id?t.session:e)}}case`session-ended`:{let n=e.sessions.find(e=>e.id===t.sessionId);return n&&t.generation<n.generation?e:{...e,sessions:e.sessions.map(e=>e.id===t.sessionId?{...e,state:`ended`,pid:null,endedAt:Date.now(),endReason:t.endReason}:e)}}case`agent-state`:return{...e,agentStates:{...e.agentStates,[t.state.sessionId]:t.state}};case`notification`:{let n=[t.notification,...e.notifications];return n.length>Uu&&(n.length=Uu),{...e,notifications:n}}case`project-created`:{let n=e.projects.some(e=>e.id===t.project.id)?e.projects.map(e=>e.id===t.project.id?t.project:e):[...e.projects,t.project],r=t.project.id in e.projectStates?e.projectStates:{...e.projectStates,[t.project.id]:{projectId:t.project.id,layout:null,worktrees:[],openFiles:[],lastFocusedPaneId:null,focusedPaneId:null,lastAccessedAt:t.project.createdAt}};return{...e,projects:n,projectStates:r}}case`project-updated`:return{...e,projects:e.projects.map(e=>e.id===t.project.id?t.project:e)};case`project-deleted`:{let n=new Set(e.sessions.filter(e=>e.projectId===t.projectId).map(e=>e.id)),r={...e.agentStates};for(let e of n)delete r[e];let{[t.projectId]:i,...a}=e.projectStates,{[t.projectId]:o,...s}=e.worktrees,{[t.projectId]:c,...l}=e.gitStates;return{...e,projects:e.projects.filter(e=>e.id!==t.projectId),sessions:e.sessions.filter(e=>e.projectId!==t.projectId),projectStates:a,agentStates:r,gitStates:l,worktrees:s}}case`layout-updated`:{let n=e.projectStates[t.projectId];return n?{...e,projectStates:{...e.projectStates,[t.projectId]:{...n,layout:t.layout}}}:e}case`ports-updated`:return{...e,ports:{...e.ports,[t.projectId]:t.ports}};case`git-state`:{let n={...e.gitStates[t.projectId]??{},[t.worktreePath]:t.state};return{...e,gitStates:{...e.gitStates,[t.projectId]:n}}}case`session-cwd-changed`:return{...e,sessions:e.sessions.map(e=>e.id===t.sessionId?{...e,cwd:t.cwd}:e)};case`session-title-changed`:return{...e,sessions:e.sessions.map(e=>{if(e.id!==t.sessionId)return e;if(t.titleManual===!0)return{...e,title:t.title,titleManual:!0};let{titleManual:n,...r}=e;return{...r,title:t.title}})};case`session-pin-changed`:return{...e,sessions:e.sessions.map(e=>{if(e.id!==t.sessionId)return e;if(t.pinned)return{...e,pinned:!0};let{pinned:n,...r}=e;return r})};case`file-change`:case`gitignore-updated`:return{...e,fileChangeSeq:e.fileChangeSeq+1};case`browser-url-changed`:return{...e,pendingOpenUrl:t.url};case`service-config-changed`:return{...e,serviceConfig:t.config};case`pane-commands-changed`:return{...e,paneCommands:t.commands};case`ide-commands-changed`:return{...e,ideCommands:t.commands};case`worktree-created`:{if(!e.projects.some(e=>e.id===t.projectId))return e;let n=e.worktrees[t.projectId]??[],r=n.findIndex(e=>e.path===t.worktree.path),i=r===-1?[...n,t.worktree]:n.map((e,n)=>n===r?{...e,...t.worktree}:e);return{...e,worktrees:{...e.worktrees,[t.projectId]:i}}}case`worktree-renamed`:{let n=e.worktrees[t.projectId];if(!n)return e;let r=n.map(e=>e.path===t.worktreePath?{...e,branch:t.newBranch}:e);return{...e,worktrees:{...e.worktrees,[t.projectId]:r}}}case`worktree-removed`:{let n=e.worktrees[t.projectId];if(!n)return e;let r=n.filter(e=>e.path!==t.worktreePath),i={...e.worktrees,[t.projectId]:r},a=e.gitStates[t.projectId],o=e.gitStates;if(a&&t.worktreePath in a){let{[t.worktreePath]:n,...r}=a;o={...e.gitStates,[t.projectId]:r}}return{...e,worktrees:i,gitStates:o}}default:return e}}function qu(e){return{projects:e.state.projects,projectStates:e.state.projectStates,sessions:e.state.sessions,agentStates:e.agentStates,notifications:[...e.notifications].reverse(),ports:e.ports,gitStates:e.gitStates,serviceConfig:e.state.serviceConfig,paneCommands:e.state.paneCommands??[],ideCommands:e.state.ideCommands??[],hostPlatform:e.hostPlatform,fileChangeSeq:0,worktrees:e.worktrees??{},pendingOpenUrl:null,connected:!0,hydrated:!0,snapshotApplied:!0}}function Ju(){try{let e=localStorage.getItem(Q);if(!e)return null;let t=JSON.parse(e);return t.version!==Wu||!Array.isArray(t.projects)||typeof t.projectStates!=`object`?null:{...Gu,projects:t.projects,projectStates:t.projectStates,sessions:Array.isArray(t.sessions)?t.sessions:[],agentStates:t.agentStates&&typeof t.agentStates==`object`?t.agentStates:{},gitStates:t.gitStates&&typeof t.gitStates==`object`?t.gitStates:{},paneCommands:Array.isArray(t.paneCommands)?t.paneCommands:[],ideCommands:Array.isArray(t.ideCommands)?t.ideCommands:[],hydrated:!0}}catch{return null}}function Yu(e){try{let t={version:Wu,projects:e.projects,projectStates:e.projectStates,sessions:e.sessions,agentStates:e.agentStates,gitStates:e.gitStates,paneCommands:e.paneCommands,ideCommands:e.ideCommands};localStorage.setItem(Q,JSON.stringify(t))}catch{}}var Xu=1e3,Zu=500,Qu=1e4,$u=2e4,ed=1e4;async function td(e){return typeof e==`string`?e:e instanceof Blob?e.text():e instanceof ArrayBuffer||ArrayBuffer.isView(e)?new TextDecoder().decode(e):null}function nd(){let[e,t]=(0,B.useState)(()=>Ju()??Gu),[n,r]=(0,B.useState)(!1),i=(0,B.useRef)({state:`awaiting-snapshot`,buffer:[]}),a=(0,B.useRef)(null),o=(0,B.useRef)(0),s=(0,B.useRef)(null),c=(0,B.useRef)(null),l=(0,B.useRef)(!0);(0,B.useEffect)(()=>{l.current=!0;let e=e=>{s.current&&clearTimeout(s.current);let n=a.current;a.current=null,i.current={state:`awaiting-snapshot`,buffer:[]},r(!1),t(e=>({...e,connected:!1})),n?.close(),s.current=setTimeout(()=>{l.current&&u()},e)},n=t=>{if(t){e(0);return}o.current+=1,e(ce(o.current))},u=async()=>{let e=performance.now(),s=performance.now(),c=await g(),u=performance.now()-s;if(T(`event-socket-auth-complete`,{attempt:o.current,durationMs:u,status:c?`ok`:`unauthenticated`}),c&&u>=1e3&&E(`event-socket-auth-slow`,{type:`event-socket-auth-complete`,attempt:o.current,durationMs:u,status:`ok`}),!c||!l.current)return;let d=location.protocol===`https:`?`wss:`:`ws:`,f=new WebSocket(`${d}//${location.host}/ws/events`);a.current=f,i.current={state:`awaiting-snapshot`,buffer:[]};let p=null,m=null,h=null,_=!1,v=0,y=0,b=()=>{m!==null&&(clearTimeout(m),m=null)},x=()=>{h!==null&&(clearTimeout(h),h=null)},S=()=>{if(f.readyState===WebSocket.OPEN&&m===null){try{f.send(JSON.stringify({type:`ping`,ts:Date.now()}))}catch{return}m=setTimeout(()=>{m=null;try{f.close()}catch{}},ed)}},C=()=>{document.visibilityState===`visible`&&S()},w=()=>S(),D=()=>S(),O=e=>{e.persisted&&S()},k=()=>{p!==null&&(clearInterval(p),p=null),b(),x(),document.removeEventListener(`visibilitychange`,C),window.removeEventListener(`focus`,w),window.removeEventListener(`online`,D),window.removeEventListener(`pageshow`,O)};f.addEventListener(`open`,()=>{if(!l.current||a.current!==f)return;y=performance.now();let t=y-e;T(`event-socket-open`,{attempt:o.current,durationMs:t}),t>=5e3&&E(`event-socket-open-slow`,{type:`event-socket-open`,attempt:o.current,durationMs:t}),o.current=0,r(!0),h=setTimeout(()=>{h=null,E(`event-socket-snapshot-timeout`,{type:`event-socket-snapshot-timeout`,attempt:o.current,timeoutMs:Qu,durationMs:performance.now()-e});try{f.close()}catch{}},Qu),p=setInterval(S,$u),document.addEventListener(`visibilitychange`,C),window.addEventListener(`focus`,w),window.addEventListener(`online`,D),window.addEventListener(`pageshow`,O)});let ee=e=>{if(!l.current||a.current!==f)return;let r;try{r=JSON.parse(e)}catch{return}if(`type`in r&&r.type===`pong`){b();return}if(`type`in r&&r.type===`app-state-snapshot`){x();let e=r,n=y>0?performance.now()-y:void 0;T(`event-socket-snapshot`,{attempt:o.current,...n===void 0?{}:{durationMs:n},status:`ok`}),n!==void 0&&n>=5e3&&E(`event-socket-snapshot-slow`,{type:`event-socket-snapshot`,attempt:o.current,durationMs:n,status:`ok`});let a=i.current.state===`awaiting-snapshot`?i.current.buffer:[],s=qu(e.payload),c=e.payload.seq,l=c;for(let e of a)e.seq<=c||(s=Ku(s,e.message),l=e.seq);_=!0,v=Date.now(),i.current={state:`live`,lastAppliedSeq:l},t(s);return}let s=r,c=i.current;if(c.state===`awaiting-snapshot`){if(c.buffer.length>=Xu){n(!1);return}i.current={state:`awaiting-snapshot`,buffer:[...c.buffer,s]};return}if(!(s.seq<=c.lastAppliedSeq)){if(s.seq>c.lastAppliedSeq+1){n(!1);return}i.current={state:`live`,lastAppliedSeq:s.seq},t(e=>Ku(e,s.message))}};f.addEventListener(`message`,e=>{if(typeof e.data==`string`){ee(e.data);return}td(e.data).then(e=>{e!==null&&ee(e)})}),f.addEventListener(`close`,()=>{k(),!(!l.current||a.current!==f)&&(r(!1),t(e=>({...e,connected:!1})),n(_&&Date.now()-v>=3e3))}),f.addEventListener(`error`,()=>{})};return u(),()=>{l.current=!1,s.current&&clearTimeout(s.current),c.current&&clearTimeout(c.current),a.current?.close(),a.current=null}},[]);let u=(0,B.useMemo)(()=>({...Gu,projects:e.projects,projectStates:e.projectStates,sessions:e.sessions,agentStates:e.agentStates,gitStates:e.gitStates,paneCommands:e.paneCommands,ideCommands:e.ideCommands,hydrated:e.hydrated}),[e.projects,e.projectStates,e.sessions,e.agentStates,e.gitStates,e.paneCommands,e.ideCommands,e.hydrated]);(0,B.useEffect)(()=>{u.hydrated&&(c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{Yu(u)},Zu))},[u]);let d=(0,B.useCallback)(e=>{t(t=>({...t,notifications:t.notifications.map(t=>t.id===e?{...t,read:!0}:t)}))},[]),f=(0,B.useCallback)(()=>{t(e=>({...e,pendingOpenUrl:null}))},[]),p=(0,B.useCallback)(e=>{t(t=>Ku(t,{type:`project-created`,project:e}))},[]),m=(0,B.useCallback)(e=>{t(t=>({...t,paneCommands:e}))},[]),h=(0,B.useCallback)(e=>{t(t=>({...t,ideCommands:e}))},[]),_=(0,B.useMemo)(()=>e.notifications.filter(e=>!e.read).length,[e.notifications]);return{...e,eventSocketConnected:n,unreadCount:_,markRead:d,clearPendingUrl:f,seedProject:p,seedPaneCommands:m,seedIdeCommands:h}}function rd(){(0,B.useEffect)(()=>{let e=e=>{if(e.defaultPrevented)return;e.preventDefault();let t=e.dataTransfer;t&&(t.dropEffect=`none`)};return window.addEventListener(`dragover`,e),window.addEventListener(`drop`,e),()=>{window.removeEventListener(`dragover`,e),window.removeEventListener(`drop`,e)}},[])}function id(e,t,n){let r;try{r=new URL(e)}catch{return null}if(r.protocol!==`http:`&&r.protocol!==`https:`)return null;let i;if(oe(r.hostname)){let e=r.port?Number(r.port):r.protocol===`https:`?443:80;Number.isInteger(e)&&(i=n(e,t?.projectId))}return F(e,{fallbackToPageHostWithoutReachablePort:de(),reachablePort:i})}function ad(e,t,n,r){let i=vt(e),a=new Set(t);a.add(n);let o={};for(let[e,t]of Object.entries(i))a.has(e)&&(o[e]=t);return o[n]=r,o}function od(e){return typeof e==`number`&&Number.isInteger(e)&&e>0&&e<65536}function sd(e){let t=new Map,n=new Map,r=new Set;for(let[i,a]of Object.entries(e)){let e=new Map;for(let t of a??[])od(t.port)&&(od(t.reachablePort)?e.set(t.port,t.reachablePort):t.bindsAll&&e.set(t.port,t.port));if(e.size!==0){t.set(i,e);for(let[t,i]of e){let e=n.get(t);e===void 0?n.set(t,i):e!==i&&r.add(t)}}}return{ambiguousDevPorts:r,byProjectId:t,fallbackByDevPort:n}}function cd(e,t,n){if(n.projectId){let r=e.byProjectId.get(n.projectId)?.get(t);if(r!==void 0)return r}if(n.activeProjectId){let r=e.byProjectId.get(n.activeProjectId)?.get(t);if(r!==void 0)return r}if(!e.ambiguousDevPorts.has(t))return e.fallbackByDevPort.get(t)}function ld(e,t){if(t.length===0)return e;let n=new Set(e.map(e=>e.id)),r=t.filter(e=>!n.has(e.id));return r.length>0?[...e,...r]:e}function ud(e){if(!e||e.length===0)return null;let t=e.filter(e=>e.status===`copied`).length,n=e.filter(e=>e.status===`skipped`).length,r=e.filter(e=>e.status===`failed`).length,i=[];return t>0&&i.push(`Copied ${t}`),n>0&&i.push(`skipped ${n}`),r>0&&i.push(`failed ${r}`),`${i.join(`, `)} local ${e.length===1?`file`:`files`}`}function dd(){let e=(0,B.useRef)(performance.now()),t=(0,B.useRef)(!1);rd();let{playAttentionSound:n,playCompletionSound:r}=w(),{activeProjectId:i,focusedPaneId:a,setActiveProjectId:o,setFocusedPaneId:s}=fc(),{navigate:c,route:l}=vc(),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(null),[m,h]=(0,B.useState)(!1),[g,_]=(0,B.useState)(0),[v,y]=Ds(),[b,x]=(0,B.useState)([]),S=nd(),C=(0,B.useMemo)(()=>Xs(S.paneCommands),[S.paneCommands]),D=(0,B.useMemo)(()=>ld(S.sessions,b),[S.sessions,b]);(0,B.useEffect)(()=>{if(b.length===0)return;let e=new Set(S.sessions.map(e=>e.id));x(t=>{let n=t.filter(t=>!e.has(t.id));return n.length===t.length?t:n})},[b.length,S.sessions]);let O=(0,B.useMemo)(()=>i?S.worktrees[i]??[]:[],[i,S.worktrees]),k=(0,B.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(S.worktrees)){let r=S.gitStates[t]??{};e[t]=n.map(e=>{let t=r[e.path];return t?{...e,ahead:t.ahead,behind:t.behind,dirtyCount:t.dirtyCount}:e})}return e},[S.worktrees,S.gitStates]),ee=rc({activeProjectId:i,agentStates:S.agentStates,sessions:D}),A=St({focusedPaneId:a,agentStates:S.agentStates});gs({activeProjectId:i,agentStates:S.agentStates,snapshotApplied:S.snapshotApplied,playAttentionSound:n,playCompletionSound:r,sessions:D});let j=(0,B.useMemo)(()=>i?S.projects.find(e=>e.id===i)??null:null,[i,S.projects]),ne=j?.name??null,M=j?.path??null;yc({activeProjectId:i,connected:S.connected,projects:S.projects,setActiveProjectId:o});let re=(0,B.useMemo)(()=>f?S.projects.find(e=>e.id===f)??null:null,[f,S.projects]),ie=(0,B.useMemo)(()=>D.filter(e=>e.pinned===!0).length,[D]),ae=(0,B.useMemo)(()=>D.filter(e=>e.projectId===i),[D,i]),P=Cs(i),F=ac({projectId:i,projectPath:M,worktrees:O,sessions:D,focusedPaneId:a,clientBrowserPanes:P.panesByWorktree});(0,B.useEffect)(()=>{if(t.current)return;t.current=!0;let n=performance.now()-e.current,r=l.kind===`pane`?l.paneId:l.kind===`session`?De(l.sessionId):F.effectiveFocusedPaneId;T(`app-route-ready`,{routeKind:l.kind,paneId:r,sessionId:l.kind===`session`?l.sessionId:void 0,durationMs:n,status:S.hydrated?`hydrated`:`cached`}),n>=5e3&&E(`app-route-ready-slow`,{type:`app-route-ready`,routeKind:l.kind,paneId:r,sessionId:l.kind===`session`?l.sessionId:void 0,durationMs:n,status:S.hydrated?`hydrated`:`cached`})},[F.effectiveFocusedPaneId,l,S.hydrated]),(0,B.useEffect)(()=>{F.effectiveFocusedPaneId!==null&&F.effectiveFocusedPaneId!==a&&s(F.effectiveFocusedPaneId)},[F.effectiveFocusedPaneId,a,s]),(0,B.useEffect)(()=>{if(l.kind===`root`){m&&h(!1);return}if(l.kind===`monitor`){m||h(!0);return}if(l.kind===`session`){let e=D.find(e=>e.id===l.sessionId);if(!e)return;let t=De(e.id);m&&h(!1),i!==e.projectId&&o(e.projectId),a!==t&&(s(t),se(t));return}if(l.kind===`pane`){if(m&&h(!1),S.hydrated&&l.projectId&&!S.projects.some(e=>e.id===l.projectId)){c({kind:`root`},{replace:!0});return}l.projectId&&i!==l.projectId&&o(l.projectId),a!==l.paneId&&(s(l.paneId),se(l.paneId));return}if(l.kind===`worktree`){if(S.hydrated&&!S.projects.some(e=>e.id===l.projectId)){m&&h(!1),c({kind:`root`},{replace:!0});return}let e=l.tab===`git`?Ee(l.worktreePath):Te(l.worktreePath);m&&h(!1),i!==l.projectId&&o(l.projectId),a!==e&&(s(e),se(e))}},[i,a,m,l,o,s,D,S.hydrated,S.projects,c]);let I=F.focusedPane?.worktreePath??null,L=(0,B.useMemo)(()=>!i||!I?null:S.gitStates[i]?.[I]??null,[i,I,S.gitStates]),R=(0,B.useMemo)(()=>!i||!I?null:S.worktrees[i]?.find(e=>e.path===I)??null,[i,I,S.worktrees]),oe=(0,B.useMemo)(()=>{let e=F.focusedPane;return!e||!j?null:(L?.branch??R?.branch??null)||(e.worktreePath===j.path?`main`:e.worktreePath.replace(/\/+$/,``).split(`/`).pop()??e.worktreePath)},[F.focusedPane,j,L,R]),ce=(0,B.useMemo)(()=>j?S.gitStates[j.id]?.[j.path]?.isRepo!==!1:!0,[j,S.gitStates]),le=(0,B.useMemo)(()=>{let e=F.focusedPane;return!e||!j?null:Ts(e.worktreePath,j.path,ce)},[F.focusedPane,j,ce]),de=L?.branch??null,fe=F.focusedPane?.state.kind===`git`,me=Ks({activeProjectId:i,focusedWorktreePath:I,focusedWorktreeName:oe,gitState:L}),z=wc(),{canOpenLocalIde:ge}=ec(),_e=(0,B.useCallback)((e,t)=>{z.openWorktreeInFinder({projectId:e,worktreePath:t})},[z]),ve=(0,B.useCallback)((e,t,n)=>{z.openWorktreeInIde({projectId:e,worktreePath:t,editor:n})},[z]),ye=(0,B.useCallback)(e=>{z.copyWorktreePath(e)},[z]),be=(0,B.useCallback)((e,t,n)=>{let r=S.gitStates[e]?.[t]?.branch,i=r&&r.length>0?r:n;z.openRenameDialog({projectId:e,worktreePath:t,currentBranch:i})},[z,S.gitStates]),xe=(0,B.useCallback)((e,t,n)=>{let r=S.gitStates[e]?.[t],i=r?.branch&&r.branch.length>0?r.branch:n,a=r?.dirtyCount??0,o=S.worktrees[e]?.find(e=>e.path===t);z.openRemoveDialog({projectId:e,worktreePath:t,branch:i,dirtyCount:a,...o?.orphan===!0&&{orphan:!0}})},[z,S.gitStates,S.worktrees]),[Se,Ce]=Os(I),{createProject:we,deleteProject:Oe}=pc({activeProjectId:i,projects:S.projects,setActiveProjectId:o,seedProject:S.seedProject}),ke=(0,B.useCallback)(async(e,t,n,r,a)=>{let l=await ls({projectId:e,command:t,title:n,cwd:r,bootstrapInput:a});if(!l)return;x(e=>e.some(e=>e.id===l.id)?e:[...e,l]),e!==i&&o(e);let u=`terminal:${l.id}`;s(u),se(u),c({kind:`session`,sessionId:l.id})},[i,c,o,s]),Ae=(0,B.useCallback)((e,t,n)=>{let r=n.initialInput.trim(),i=r?`${r}\r`:void 0;ke(e,void 0,n.builtin?void 0:n.label,t,i)},[ke]),je=(0,B.useCallback)(async(e,t)=>{let n=await Bu(e,{branch:t.branch,base:t.base,copyLocalFiles:t.copyLocalFiles,rememberLocalFiles:t.rememberLocalFiles}),r=n.path,i=ud(n.localFileCopies);i&&y(i);let a=t.command.initialInput.trim(),o=a?`${a}\r`:void 0;await ke(e,void 0,t.command.builtin?void 0:t.command.label,r,o)},[ke,y]),Me=(0,B.useCallback)(e=>{let t=S.paneCommands;S.seedPaneCommands(e),os(e).then(e=>{Array.isArray(e.commands)&&S.seedPaneCommands(e.commands);try{window.localStorage.removeItem(qs)}catch{}}).catch(()=>{S.seedPaneCommands(t),y(`Failed to save terminal commands`)})},[S,y]),Ne=(0,B.useCallback)(e=>{let t=S.ideCommands;S.seedIdeCommands(e),ss(e).then(e=>{Array.isArray(e.commands)&&S.seedIdeCommands(e.commands)}).catch(()=>{S.seedIdeCommands(t),y(`Failed to save IDE commands`)})},[S,y]);$s({hydrated:S.hydrated,paneCommandsCount:S.paneCommands.length,onMigrate:Me});let Pe=(0,B.useCallback)(async e=>{await us(e)},[]),Fe=(0,B.useCallback)(async(e,t)=>{await ds(e,t)},[]),Ie=(0,B.useCallback)(async e=>{let t=D.find(t=>t.id===e);t&&await fs(e,t.pinned!==!0)},[D]),Le=(0,B.useCallback)(async e=>{let t=F.paneById.get(e);if(t){if(t.state.kind===`terminal`){await ps(t.state.sessionId);return}if(t.state.kind===`browser`){P.closeBrowser(e);return}}},[P,F.paneById]),Re=(0,B.useCallback)(e=>{let t=S.projects.find(t=>t.id===e.projectId);t&&(i!==e.projectId&&o(e.projectId),s(Te(t.path))),c({kind:`root`}),ps(e.id)},[i,c,o,s,S.projects]),ze=(0,B.useMemo)(()=>sd(S.ports),[S.ports]),Be=(0,B.useCallback)((e,t)=>cd(ze,e,{activeProjectId:i,projectId:t}),[i,ze]),Ve=(0,B.useCallback)((e,t)=>{let n=id(e,t,Be);n!==null&&ue(n)},[Be]);(0,B.useEffect)(()=>{S.pendingOpenUrl&&(Ve(S.pendingOpenUrl),S.clearPendingUrl())},[S.pendingOpenUrl,S.clearPendingUrl,Ve]);let{closeSettings:He,isMobile:Ue,openSettings:We,settingsOpen:Ge}=Cc({activeProjectId:i,projects:S.projects,setActiveProjectId:o});(0,B.useEffect)(()=>{T(`mobile-surface-route`,{routeKind:l.kind,surface:Ue?l.kind===`root`?`navigation`:`workspace`:`split`,paneId:F.focusedPane?.id??null})},[Ue,F.focusedPane?.id,l.kind]);let Ke=(0,B.useCallback)(async e=>{let t=l.kind===`pane`&&l.projectId===e||l.kind===`worktree`&&l.projectId===e||l.kind===`session`&&D.some(t=>t.id===l.sessionId&&t.projectId===e);await Oe(e),t&&c({kind:`root`},{replace:!0}),p(null)},[Oe,c,l,D]),Ye=ws({onConfirm:(0,B.useCallback)(async e=>{(Ue||l.kind===`session`&&e.paneId===De(l.sessionId)||l.kind===`pane`&&e.paneId===l.paneId)&&c({kind:`root`}),await Le(e.paneId)},[Le,Ue,c,l])}),Ze=(0,B.useCallback)(()=>{d(!0)},[]),{reorderResetSignal:Qe,pendingProjectReorderCount:$e,reorder:et}=nc({onError:y}),tt=(0,B.useCallback)((e,t,n)=>{let r=`paneOrder:${e}`,i=vt.current.find(t=>t.id===e)?.worktrees.map(e=>e.path)??[],a=ad(window.localStorage.getItem(r),i,t,n);try{window.localStorage.setItem(r,JSON.stringify(a))}catch{}_(e=>e+1)},[]),nt=(0,B.useCallback)(e=>Vu(e),[]),rt=(0,B.useCallback)(()=>{We()},[We]),it=(0,B.useCallback)(e=>{Yo({preventIdleSleep:e})},[]),at=(0,B.useCallback)(e=>{Yo({portDetection:e})},[]),ot=(0,B.useCallback)(e=>{Yo({dropSizeMaxBytes:e})},[]),st=(0,B.useMemo)(()=>Object.fromEntries(S.projects.map(e=>[e.id,e.name])),[S.projects]);(0,B.useEffect)(()=>{if(!S.connected||!i)return;let e=new AbortController;return Hu(i,e.signal).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||console.warn(`Worktree refresh failed:`,e)}),()=>e.abort()},[i,S.connected]);let{open:dt,query:ft,setQuery:pt,toggle:mt,close:ht}=ic({isMobile:Ue,onMobileOpenShortcut:(0,B.useCallback)(()=>c({kind:`root`}),[c])}),_t=(0,B.useMemo)(()=>bt(Ot({projects:S.projects,activeProjectId:i,activeWorktrees:F.worktrees,sessions:D,agentStates:S.agentStates,reviewPendingSessions:ee,worktreesByProject:k,gitStates:S.gitStates,attentionDismissed:A,inactiveChildPanesByProject:gt(S.projects)})),[S.projects,i,F.worktrees,D,S.agentStates,ee,k,S.gitStates,A,g]),vt=(0,B.useRef)(_t);vt.current=_t;let yt=(0,B.useCallback)(()=>{h(!0),ht(),c({kind:`monitor`})},[ht,c]),xt=(0,B.useCallback)((e,t)=>{h(!1),e!==i&&o(e);let n=t.startsWith(`wt:`)?t.slice(3):t,r=Te(n);s(r),se(r),ht(),c({kind:`worktree`,projectId:e,worktreePath:n,tab:`files`})},[i,ht,c,o,s]),Ct=(0,B.useCallback)((e,t,n)=>{h(!1),e!==i&&o(e),s(n),se(n),ht(),n.startsWith(`terminal:`)?c({kind:`session`,sessionId:n.slice(9)}):c({kind:`pane`,paneId:n,projectId:e})},[i,ht,c,o,s]),wt=Es({projects:S.projects,gitStates:S.gitStates}),Tt=(0,B.useCallback)((e,t)=>{wt.open(e,t),Ue&&ht()},[wt.open,ht,Ue]),Et=(0,B.useCallback)(e=>{e.startsWith(`terminal:`)&&Ie(e.slice(9))},[Ie]),Dt=(0,B.useMemo)(()=>({projects:_t,selection:{monitor:m,selectedWorktreeId:!m&&F.focusedPane?`wt:${F.focusedPane.worktreePath}`:null,selectedChildId:!m&&F.focusedPane&&(F.focusedPane.state.kind===`terminal`||F.focusedPane.state.kind===`browser`)?F.focusedPane.id:null},connected:S.connected,portsByProjectId:S.ports,projectNames:st,onOpenUrl:Ve,pinnedMonitorCount:ie,onSelectMonitor:yt,onSelectWorktree:xt,onSelectChild:Ct,onOpenContainer:Tt,onToggleChildPin:Et,onNewProject:Ze,onOpenSettings:rt,searchOpen:dt,searchQuery:ft,onToggleSearch:mt,onCloseSearch:ht,onSearchQueryChange:pt,onReorderProjects:et,onReorderPanes:tt,reorderResetSignal:Qe,pendingProjectReorderCount:$e}),[_t,m,F.focusedPane,S.connected,S.ports,st,Ve,ie,yt,xt,Ct,Tt,Et,Ze,rt,dt,ft,mt,ht,pt,et,tt,Qe,$e]),kt=wt.target,At=wt.context,jt=(0,V.jsx)(Wa,{...Dt,fill:!0}),Mt=l.kind===`session`?D.find(e=>e.id===l.sessionId)??null:null,Nt=l.kind===`session`&&!Mt?l.sessionId:null,Pt=Mt?.state===`ended`&&!pe(Mt.command,Mt.endReason)?Mt:null,Ft=Nt?(0,V.jsx)(Je,{sessionId:Nt,hydrated:S.hydrated,connected:S.eventSocketConnected,onClose:()=>c({kind:`root`})}):Pt?(0,V.jsx)(he,{sessionTitle:Pt.title.trim()||Pt.id,command:Pt.command,endReason:Pt.endReason,onRestart:()=>void Pe(Pt.id),onClose:()=>Re(Pt)}):m?(0,V.jsx)(Io,{projects:S.projects,sessions:D,agentStates:S.agentStates,reviewPendingSessions:ee,gitStates:S.gitStates,attentionDismissed:A,isMobile:Ue,onToggleDrawer:()=>c({kind:`root`}),onRestartSession:Pe,onOpenUrl:Ve,onTogglePin:Ie}):(0,V.jsx)(Nu,{activeProjectId:i,activeProjectName:ne,activeProjectPath:M,activeProjectIsRepo:ce,allPanes:F.allPanes,focusedPane:F.focusedPane,focusedWorktreeDirName:le,fileChangeSeq:S.fileChangeSeq,gitState:L,hydrated:S.hydrated,isMobile:Ue,gitMenuActions:fe?{onPull:()=>me.pull(),onPush:()=>me.push()}:void 0,gitGraphSelection:Se,onGitGraphSelectionChange:Ce,gitBranchName:de,commitBusy:me.commitBusy,commitError:me.commitError,onClearCommitError:me.clearCommitError,onSubmitInlineCommit:me.submitInlineCommit,sessions:ae,onToggleDrawer:()=>c({kind:`root`}),onClosePane:Le,onRequestClosePane:Ye.request,onNewProject:Ze,onOpenUrl:Ve,onBrowserUrlChange:P.updateBrowserUrl,onRestartSession:Pe,onRenameSession:Fe,onSelectWorktreeTab:(e,t)=>{s(t===`git`?Ee(e):Te(e)),i&&c({kind:`worktree`,projectId:i,worktreePath:e,tab:t})},onToggleSessionPin:Ie,onOpenWorktreeInFinder:_e,onOpenWorktreeInIde:ve,ideCommands:S.ideCommands,canOpenLocalIde:ge,onCopyWorktreePath:ye,onRenameWorktree:be,onRemoveWorktree:xe,onDeleteProject:e=>p(e)});return(0,V.jsx)(N,{projects:S.projects,children:(0,V.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,V.jsx)(no,{connected:S.eventSocketConnected}),(0,V.jsx)(io,{}),(0,V.jsx)(`div`,{className:`flex flex-1 overflow-hidden`,children:Ue?l.kind===`root`?jt:Ft:(0,V.jsx)(is,{navigation:jt,main:Ft})}),(0,V.jsx)(ct,{open:u,onClose:()=>d(!1),onCreate:(e,t)=>(h(!1),we(e,t)),isMobile:Ue}),(0,V.jsx)(te,{open:Ge,onClose:He,server:{serviceConfig:S.serviceConfig,hostPlatform:S.hostPlatform,onPreventIdleSleepChange:it,onPortDetectionChange:at,onDropSizeMaxBytesChange:ot,ideCommands:S.ideCommands,onIdeCommandsChange:Ne}}),v&&(0,V.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`pointer-events-none fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded-window border border-warning/60 bg-bg-secondary px-3 py-2 text-sm text-text-primary shadow-lg`,children:v}),re&&(0,V.jsx)(cs,{projectName:re.name,onCancel:()=>p(null),onConfirm:()=>void Ke(re.id)}),Ye.target&&(0,V.jsx)(as,{paneTitle:Ye.target.title,paneKind:Ye.target.paneKind,onCancel:Ye.cancel,onConfirm:()=>void Ye.confirm()}),kt&&At&&(0,V.jsx)(Xe,{open:!0,project:At.project,worktree:At.worktree,commands:C,isMobile:Ue,loadLocalFiles:nt,onClose:wt.close,onCommandsChange:Me,onCreateWorktreeSession:e=>je(kt.projectId,e),onRunCommand:(e,t)=>Ae(kt.projectId,e,t)}),z.renameDialog&&(0,V.jsx)(ut,{open:!0,currentBranch:z.renameDialog.currentBranch,busy:z.renameBusy,error:z.renameError,onClose:z.closeRenameDialog,onSubmit:z.submitRename}),z.removeDialog&&(0,V.jsx)(lt,{open:!0,branch:z.removeDialog.branch,worktreePath:z.removeDialog.worktreePath,dirtyCount:z.removeDialog.dirtyCount,orphan:z.removeDialog.orphan===!0,busy:z.removeBusy,error:z.removeError,onClose:z.closeRemoveDialog,onSubmit:z.submitRemove}),(0,V.jsx)(qe,{open:me.commitDialog!==null,busy:me.commitBusy,error:me.commitError,branchName:me.commitDialog?.branchName??null,files:me.commitDialog?.files??[],isMobile:Ue,onClose:me.closeCommitDialog,onCommit:me.submitCommit}),(0,V.jsx)(yo,{}),(0,V.jsx)(eo,{})]})})}function fd({children:e}){let[t,n]=(0,B.useState)(`loading`);return(0,B.useEffect)(()=>{let e=!1;(async()=>{let t=performance.now(),r=await g({dispatchOn401:!1}),i=performance.now()-t;T(`auth-gate-preflight-complete`,{durationMs:i,status:r?`ok`:`unauthenticated`}),r&&i>=1e3&&E(`auth-gate-preflight-slow`,{type:`auth-gate-preflight-complete`,durationMs:i,status:`ok`}),!e&&n(r?`authed`:`unauthenticated`)})();let t=()=>n(`expired`);return window.addEventListener(k,t),()=>{e=!0,window.removeEventListener(k,t)}},[]),t===`loading`?null:t===`unauthenticated`?(0,V.jsx)(pd,{}):t===`expired`?(0,V.jsx)(md,{}):(0,V.jsx)(V.Fragment,{children:e})}function pd(){return(0,V.jsxs)(`div`,{role:`alert`,"aria-live":`assertive`,className:`flex h-full flex-col items-center justify-center gap-4 bg-[--theme-background] p-6 text-center text-[--theme-foreground]`,children:[(0,V.jsx)(`h1`,{className:`text-base font-semibold`,children:`Authentication required`}),(0,V.jsxs)(`p`,{className:`max-w-md text-sm opacity-80`,children:[`Open the URL printed by`,` `,(0,V.jsx)(`code`,{className:`rounded-control bg-black/20 px-1 py-0.5`,children:`parasor qr`}),`, or scan the QR code on the host. If you copied the URL from a terminal that wrapped the line, the token may have been truncated -- scanning the QR avoids that.`]})]})}function md(){return(0,V.jsxs)(`div`,{role:`alert`,"aria-live":`assertive`,className:`flex h-full flex-col items-center justify-center gap-4 bg-[--theme-background] p-6 text-center text-[--theme-foreground]`,children:[(0,V.jsx)(`h1`,{className:`text-base font-semibold`,children:`Session expired`}),(0,V.jsxs)(`p`,{className:`max-w-md text-sm opacity-80`,children:[`Run`,` `,(0,V.jsx)(`code`,{className:`rounded-control bg-black/20 px-1 py-0.5`,children:`parasor qr`}),` `,`on the host and open the refreshed URL to sign back in.`]})]})}var hd=e=>e.preventDefault();document.addEventListener(`gesturestart`,hd),document.addEventListener(`gesturechange`,hd),document.addEventListener(`gestureend`,hd);var gd=class extends B.Component{state={error:null,info:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({error:e,info:t}),console.error(`[parasor ErrorBoundary]`,e,t),E(`react-error-boundary`,{type:`react-error-boundary`,status:e.name})}render(){return this.state.error?(0,V.jsxs)(`div`,{style:{position:`fixed`,inset:0,background:`#000`,color:`#fff`,padding:16,fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:12,overflow:`auto`,zIndex:2147483647},children:[(0,V.jsx)(`div`,{style:{color:`#ff5555`,fontSize:14,marginBottom:8},children:`⚠ React error caught`}),(0,V.jsxs)(`div`,{style:{color:`#ffaa00`,marginBottom:8},children:[this.state.error.name,`: `,this.state.error.message]}),(0,V.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,color:`#aaa`,fontSize:10},children:this.state.error.stack}),this.state.info&&(0,V.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,color:`#666`,fontSize:10,marginTop:8},children:this.state.info.componentStack}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>this.setState({error:null,info:null}),style:{marginTop:12,padding:`6px 12px`,background:`#2f81f7`,color:`#fff`,border:0,borderRadius:4,fontSize:12},children:`Try again`})]}):this.props.children}},_d=document.getElementById(`root`);if(!_d)throw Error(`Missing #root element`);(0,Le.createRoot)(_d).render((0,V.jsx)(gd,{children:(0,V.jsx)(x,{children:(0,V.jsx)(fd,{children:(0,V.jsx)(dd,{})})})}));
34
+ `,1)[0]?.length??0)-72);function C(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function w(e){m(e?new Set(o.map(e=>e.path)):new Set)}function T(){x&&(u({message:b,paths:Array.from(p)}),f(``))}return(0,V.jsxs)(`div`,{className:`flex h-full flex-col bg-bg-primary text-text-primary`,children:[(0,V.jsx)(i,{icon:(0,V.jsx)(h.diff,{}),iconTone:`warning`,title:`Working tree`}),o.length===0?(0,V.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-4 text-center text-sm text-text-secondary`,children:`No uncommitted changes.`}):(0,V.jsx)(Ke,{files:o,selected:p,toggle:C,toggleAll:w,message:d,setMessage:f,layout:`inline`,diffsByPath:y}),c&&(0,V.jsxs)(`div`,{className:`flex items-start gap-2 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[(0,V.jsx)(`span`,{className:`flex-1`,children:c}),(0,V.jsx)(`button`,{type:`button`,onClick:l,"aria-label":`Dismiss`,className:`text-danger/80 hover:text-danger`,children:(0,V.jsx)(h.close,{})})]}),(0,V.jsx)(r,{status:(0,V.jsxs)(V.Fragment,{children:[p.size,`/`,o.length,` selected`,S>0&&(0,V.jsxs)(`span`,{className:`ml-3 text-danger`,children:[`subject +`,S,` over`]})]}),actions:(0,V.jsx)(a,{kind:`submit`,onClick:T,disabled:!x,className:`shrink-0`,children:s?`Committing…`:`Commit`})})]})}function gu(e,t){return[e,t?.branch??``,t?.ahead??``,t?.behind??``,t?.dirtyCount??``,t?.isRepo===!1?`non-repo`:`repo`].join(`:`)}function _u({projectId:e,worktreePath:t,fileChangeSeq:n,isMobile:r,gitState:i,projectPath:a,selection:o,onSelectionChange:s,commitBusy:c,commitError:l,onClearCommitError:u,onSubmitInlineCommit:d,onChangeTab:f,gitActions:p}){let m=(0,B.useMemo)(()=>{let e=i?.fileStatuses;return e?Object.entries(e).map(([e,t])=>({path:e,status:t})).sort((e,t)=>e.path.localeCompare(t.path)):[]},[i?.fileStatuses]);if(i?.isRepo===!1)return(0,V.jsx)(mu,{projectId:e,projectPath:a});let h=o?.kind===`working-tree`,g=gu(n,i);return(0,V.jsx)(pl,{storageKey:`worktree`,defaultRatio:Oe,isMobile:r,secondaryActive:o!==null,primary:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,V.jsx)(`div`,{className:`hidden h-bar shrink-0 border-b border-border bg-tab-strip-bg md:block`,children:(0,V.jsx)(wl,{activeTab:`git`,onChangeTab:f})}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(eu,{projectId:e,worktreePath:t,refreshSeq:g,selection:o,onSelect:s,isMobile:r,currentBranch:i?.branch,ahead:i?.ahead,behind:i?.behind,...p&&{actions:p}})})]}),secondary:h?(0,V.jsx)(hu,{projectId:e,worktreePath:t,fileChangeSeq:n,files:m,busy:c,error:l,onClearError:u,onSubmit:e=>void d(e)}):(0,V.jsx)(Al,{projectId:e,worktreePath:t,fileChangeSeq:n,commit:o?.kind===`commit`?o.commit:null})})}var vu=350,yu=5;function bu(e,t){let[n,r]=(0,B.useState)(!1),i=(0,B.useRef)(!1),a=(0,B.useRef)(null),o=(0,B.useRef)(null),s=(0,B.useCallback)(()=>{o.current&&=(clearTimeout(o.current),null),a.current=null,i.current=!1,r(!1)},[]);return(0,B.useEffect)(()=>()=>s(),[s]),{onTouchStart:(0,B.useCallback)(t=>{if(!e)return;let n=t.touches[0];if(n){if(o.current&&=(clearTimeout(o.current),null),t.touches.length>1){a.current=null,i.current=!1,r(!1);return}a.current={x:n.clientX,y:n.clientY},i.current=!1,r(!1),o.current=setTimeout(()=>{i.current=!0,r(!0)},vu)}},[e]),onTouchMove:(0,B.useCallback)(e=>{let t=a.current;if(!t)return;let n=e.touches[0];if(!n)return;let r=n.clientX-t.x,i=n.clientY-t.y;Math.hypot(r,i)>yu&&s()},[s]),onTouchEnd:(0,B.useCallback)(n=>{if(!i.current||!e){s();return}n.preventDefault(),s(),xu(e,t)},[s,e,t]),onTouchCancel:(0,B.useCallback)(()=>{s()},[s]),armed:n}}async function xu(e,t){try{if(navigator.clipboard?.writeText)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t)}Qa(t?`Copied ${t}`:`Copied`)}catch{Qa(`Copy failed`)}}function Su({crumbs:e,onBack:t,onToggleDrawer:n,view:r,onChangeView:i,dirty:a,pin:o,onClose:s,moreMenuItems:c}){let l=(a??0)>0,u=new Map;return(0,V.jsxs)(`div`,{className:`relative shrink-0 border-b border-border bg-bg-secondary`,role:`toolbar`,"aria-label":`Workspace`,children:[(0,V.jsxs)(`div`,{className:`flex h-bar items-center gap-2 px-2 md:px-3`,children:[t?(0,V.jsx)(_,{onClick:t,label:`Back`,size:`md`,tone:`active`,className:`md:hidden`,children:(0,V.jsx)(h.back,{})}):(0,V.jsx)(_,{onClick:n,label:`Go to sessions`,size:`md`,tone:`active`,className:`md:hidden`,children:(0,V.jsx)(h.menu,{})}),(0,V.jsx)(`div`,{className:`-ml-2 flex min-w-0 flex-1 items-center gap-1 text-sm font-semibold tracking-[-0.005em] md:ml-0 md:gap-1.5 md:px-1`,children:e.map((t,n)=>{let r=n===e.length-1,i=u.get(t.label)??0;return u.set(t.label,i+1),(0,V.jsx)(Cu,{crumb:t,showSep:n>0,isLast:r,trailing:r&&o?(0,V.jsx)(xo,{pinned:o.pinned,onToggle:o.onToggle}):void 0},`${t.label}:${i}`)})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[l&&(0,V.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 px-1 text-sm font-medium text-[var(--theme-git-modified)]`,title:`${a} uncommitted changes`,children:[(0,V.jsx)(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 rounded-tag bg-[var(--theme-git-modified)]`}),a,`Δ`]}),s&&(0,V.jsx)(Nc,{onClick:s}),c&&c.length>0&&(0,V.jsx)(p,{align:`end`,items:c,renderTrigger:({toggle:e,triggerRef:t,menuId:n,open:r})=>(0,V.jsx)(_,{ref:t,onClick:e,"aria-haspopup":`menu`,"aria-expanded":r,"aria-controls":n,label:`Workspace menu`,size:`md`,children:(0,V.jsx)(h.more,{})})})]})]}),r!==void 0&&i?(0,V.jsx)(`div`,{className:`h-bar border-t border-border bg-tab-strip-bg md:hidden`,children:(0,V.jsx)(wl,{activeTab:r,onChangeTab:i})}):null]})}function Cu({crumb:e,showSep:t,isLast:n,trailing:r}){let i=bu(e.label,`name`);return(0,V.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,style:{flex:n?`1 1 auto`:`0 1 auto`},children:[t&&(0,V.jsx)(`span`,{"aria-hidden":!0,className:`shrink-0 text-text-secondary/50`,children:`·`}),e.glyph&&(0,V.jsx)(`span`,{"aria-hidden":!0,className:`shrink-0 ${e.dim?`text-text-secondary/70`:`text-accent`}`,children:e.glyph}),(0,V.jsx)(`span`,{title:e.label,onTouchStart:i.onTouchStart,onTouchMove:i.onTouchMove,onTouchEnd:i.onTouchEnd,onTouchCancel:i.onTouchCancel,className:`min-w-0 truncate transition-opacity ${e.dim?`font-medium text-text-secondary/70`:`text-text-primary`} ${i.armed?`opacity-60`:`opacity-100`}`,style:{maxWidth:e.maxWidth},children:e.label}),r]})}function wu({value:e,onSave:t}){let[n,r]=(0,B.useState)(!1),[i,a]=(0,B.useState)(e),[o,s]=(0,B.useState)(null),c=(0,B.useRef)(null),l=(0,B.useRef)(!1);(0,B.useEffect)(()=>{n||a(e)},[n,e]),(0,B.useEffect)(()=>{if(!n||c.current&&document.activeElement===c.current)return;let e=requestAnimationFrame(()=>{c.current?.focus(),c.current?.select()});return()=>cancelAnimationFrame(e)},[n]);let u=(0,B.useCallback)(()=>{(0,nn.flushSync)(()=>r(!0)),c.current?.focus(),c.current?.select()},[]),d=async()=>{let n=i.trim();if(r(!1),s(null),n!==e.trim())try{await t(n)}catch(t){s(t instanceof Error?t.message:`Rename failed`),a(e)}};return n?(0,V.jsx)(`input`,{ref:c,value:i,"aria-label":`Terminal title`,title:o??void 0,onChange:e=>a(e.currentTarget.value),onBlur:()=>{if(l.current){l.current=!1;return}d()},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),d()):t.key===`Escape`&&(t.preventDefault(),l.current=!0,a(e),r(!1),s(null))},className:`h-7 min-w-0 flex-shrink rounded-control border border-accent bg-bg-primary px-1.5 text-sm font-semibold text-text-primary outline-none`}):(0,V.jsx)(`button`,{type:`button`,"aria-label":`Rename terminal`,title:o??e,onClick:u,className:`min-w-0 flex-shrink truncate rounded-control px-1 text-left text-sm font-semibold text-text-primary hover:bg-row-hover-bg focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${o?`text-danger`:``}`,children:e})}var Tu=(0,B.lazy)(()=>Do(async()=>{let{TerminalPane:e}=await import(`./TerminalPane-D3z_3Lr8.js`);return{TerminalPane:e}},__vite__mapDeps([0])).then(({TerminalPane:e})=>({default:e})));function Eu({paneId:e,state:t,worktreePath:n,session:r,pin:a,onClose:o,onRestartSession:s,onRenameSession:c,onOpenUrl:l,onOpenFilePath:u,onClosePane:d}){let f=wt(r,`shell`),p=r!==void 0&&r.state!==`ended`;return(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:[(0,V.jsx)(i,{icon:(0,V.jsx)(h.terminal,{}),title:f,titleAttr:f,titleElement:r?(0,V.jsx)(wu,{value:f,onSave:e=>c(r.id,e)}):void 0,actions:(0,V.jsxs)(V.Fragment,{children:[p&&(0,V.jsx)(Ou,{sessionId:r.id,paneId:e}),a&&(0,V.jsx)(xo,{pinned:a.pinned,onToggle:a.onToggle}),o&&(0,V.jsx)(Nc,{onClick:o})]})}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`h-full bg-bg-terminal`}),children:(0,V.jsx)(Tu,{paneId:e,sessionId:t.sessionId,session:r,onRestartSession:s,onOpenUrl:l,worktreePath:n,onOpenFilePath:u,onClosePane:d})})})]})}function Du(e){switch(e){case`busy`:return`Capturing terminal diagnostics`;case`ok`:return`Captured terminal diagnostics`;case`error`:return`Failed to capture terminal diagnostics`;case`idle`:return`Capture terminal diagnostics`}}function Ou({sessionId:e,paneId:t}){let[n,r]=(0,B.useState)(`idle`),i=Du(n);return(0,V.jsx)(_,{label:i,title:i,tone:n===`ok`?`accent`:n===`error`?`danger`:`normal`,disabled:n===`busy`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>e.preventDefault(),onClick:()=>{r(`busy`),window.parasorTerminalTrace?.captureTerminalInput(`manual-terminal-button`,{sessionId:e,paneId:t}).then(()=>r(`ok`)).catch(()=>r(`error`))},children:(0,V.jsx)(h.doc,{})})}function ku({children:e}){return(0,V.jsx)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:(0,V.jsx)(`div`,{className:`min-h-0 flex-1`,children:e})})}function Au({activeProjectId:e,hydrated:t,onNewProject:n}){return t?(0,V.jsxs)(`div`,{className:`relative flex h-full items-center justify-center px-10`,children:[(0,V.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 opacity-30`,style:{backgroundImage:`linear-gradient(var(--color-border) 1px, transparent 1px), linear-gradient(90deg, var(--color-border) 1px, transparent 1px)`,backgroundSize:`42px 42px`,maskImage:`radial-gradient(ellipse 60% 60% at 50% 45%, #000, transparent)`,WebkitMaskImage:`radial-gradient(ellipse 60% 60% at 50% 45%, #000, transparent)`}}),(0,V.jsxs)(`div`,{className:`relative max-w-surface-md text-center`,children:[(0,V.jsx)(`p`,{className:`mb-3.5 text-[32px] font-normal leading-none tracking-normal text-text-primary`,children:`parasor`}),e?(0,V.jsxs)(`p`,{className:`mx-auto max-w-[440px] text-base leading-[1.6] text-text-secondary`,children:[`Pick a worktree from the sidebar, or filter it with`,` `,(0,V.jsxs)(`span`,{className:`inline-flex shrink-0 gap-[3px] align-middle`,children:[(0,V.jsx)(C,{children:`⌘`}),(0,V.jsx)(C,{children:`K`})]}),`.`]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`mb-7 text-base leading-[1.6] text-text-secondary`,children:`No project yet. Add one to get started.`}),(0,V.jsx)(a,{kind:`submit`,size:`sm`,onClick:n,children:`New Project…`})]})]})]}):(0,V.jsx)(`div`,{className:`h-full w-full`})}function ju(e){let t=e.replace(/\/+$/,``).split(`/`);return t[t.length-1]??e}function Mu(e){return`files:${e}`}function Nu({activeProjectId:e,activeProjectName:t,activeProjectPath:n,activeProjectIsRepo:r,allPanes:i=[],focusedPane:a,focusedWorktreeDirName:o,fileChangeSeq:s,gitState:c,hydrated:l,isMobile:u,gitMenuActions:d,gitGraphSelection:f,onGitGraphSelectionChange:p,gitBranchName:m,commitBusy:h,commitError:g,onClearCommitError:_,onSubmitInlineCommit:v,sessions:y,onToggleDrawer:b,onClosePane:x,onRequestClosePane:S,onNewProject:C,onOpenUrl:w,onBrowserUrlChange:T,onRestartSession:E,onRenameSession:D,onSelectWorktreeTab:O,onToggleSessionPin:k,onOpenWorktreeInFinder:ee,onOpenWorktreeInIde:A,ideCommands:j=[],canOpenLocalIde:te=!1,onCopyWorktreePath:ne,onRenameWorktree:M,onRemoveWorktree:N,onDeleteProject:re}){let ie=c?.fileStatuses,ae=c?.dirtyCount??0,P=c?{ahead:c.ahead,behind:c.behind,dirty:c.dirtyCount}:void 0,F=a?.state.kind===`files`?a:null,I=a?.state.kind===`git`?a:null,L=F??I,R=F!==null,oe=I!==null,se=L!==null,[ce,le]=Sl(F?.id??null),ue=R&&ce!==null,de=oe&&f!==null,fe=ue?ju(ce):de?Lu(f):a?Ru(a,y):null,pe=zu(t,o,!!a&&!!n&&a.worktreePath===n,r,m),me=L&&!ue&&!de?L.state.kind:void 0,he=L&&!ue&&!de?e=>O(L.worktreePath,e):void 0,z=ue?()=>le(null):de?()=>p(null):null,ge=a?.state.kind===`terminal`||a?.state.kind===`browser`?a.state.kind:null,_e=a&&ge?()=>S(a.id,ge,fe??`pane`):void 0,ve=a?.state.kind===`terminal`?a.state:null,ye=ve?y.find(e=>e.id===ve.sessionId):void 0,be=ye?{pinned:ye.pinned===!0,onToggle:()=>void k(ye.id)}:null,xe=a?.state.kind===`terminal`||a?.state.kind===`browser`,Se=xe?null:be,Ce=xe?void 0:_e,we=i.length>0?i:a?[a]:[],Te=(e,t)=>{bl(Mu(e),t),O(e,`files`)};kc(u?z:null);let Ee=(0,B.useMemo)(()=>{if(!a||!e)return[];let t=a.worktreePath,n=o??`main`,i=[];if(ee&&i.push({id:`open-finder`,label:`Open in Finder`,onSelect:()=>ee(e,t)}),A){let n=!te,r=n?`Available when parasor is opened from localhost on the server machine`:void 0;i.push({id:`open-cursor`,label:`Open in Cursor`,disabled:n,title:r,onSelect:()=>A(e,t,`cursor`)},{id:`open-vscode`,label:`Open in VS Code`,disabled:n,title:r,onSelect:()=>A(e,t,`vscode`)});for(let a of j)i.push({id:`open-custom-ide:${a.id}`,label:`Open in ${a.label}`,disabled:n,title:r,onSelect:()=>A(e,t,a.id)})}return ne&&i.push({id:`copy-path`,label:`Copy path`,onSelect:()=>ne(t)}),r&&M&&i.push({id:`rename`,label:`Rename branch…`,onSelect:()=>M(e,t,n)}),r&&N&&i.push({id:`remove`,label:`Remove worktree…`,onSelect:()=>N(e,t,n)}),re&&i.push({id:`close-project`,label:`Close project…`,onSelect:()=>re(e)}),i},[a,e,r,o,ee,A,j,te,ne,M,N,re]);return(0,V.jsxs)(`main`,{className:`flex-1 min-w-0 bg-bg-terminal flex flex-col touch-pan-y`,children:[a&&(0,V.jsx)(Su,{crumbs:pe,onBack:z,onToggleDrawer:b,view:me,onChangeView:he,dirty:se?ae:void 0,pin:Se,onClose:Ce,moreMenuItems:Ee}),(0,V.jsx)(`div`,{className:`relative flex-1 overflow-hidden`,children:a&&e?(0,V.jsxs)(V.Fragment,{children:[a.state.kind!==`terminal`&&(0,V.jsx)(`div`,{className:`absolute inset-0 min-h-0 min-w-0`,children:(0,V.jsx)(Iu,{activeProjectId:e,activeProjectPath:n,focusedPane:a,focusedWorktreeDirName:o,fileChangeSeq:s,gitState:c,gitFileStatuses:ie,gitBranchName:m,counters:P,gitMenuActions:d,gitGraphSelection:f,onGitGraphSelectionChange:p,commitBusy:h,commitError:g,onClearCommitError:_,onSubmitInlineCommit:v,isMobile:u,sessions:y,terminalPin:be,terminalOnClose:_e,browserOnClose:_e,onClosePane:x,onOpenUrl:w,onBrowserUrlChange:T,onRestartSession:E,onRenameSession:D,onSelectWorktreeTab:O})}),(0,V.jsx)(Pu,{panes:we,focusedPaneId:a.id,sessions:y,pin:be,onClose:_e,onClosePane:x,onOpenUrl:w,onOpenFilePath:Te,onRestartSession:E,onRenameSession:D})]}):(0,V.jsx)(Au,{activeProjectId:e,hydrated:l,onNewProject:C})})]})}function Pu({panes:e,focusedPaneId:t,sessions:n,pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:s,onRestartSession:c,onRenameSession:l}){return(0,V.jsx)(V.Fragment,{children:e.filter(e=>e.state.kind===`terminal`&&e.id===t).map(e=>{if(e.state.kind!==`terminal`)return null;let t=e.state;return(0,V.jsx)(Fu,{pane:e,state:t,session:n.find(e=>e.id===t.sessionId),pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:s,onRestartSession:c,onRenameSession:l},e.id)})})}function Fu({pane:e,state:t,session:n,pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:s,onRestartSession:c,onRenameSession:l}){let u=(0,B.useRef)(null);return(0,B.useEffect)(()=>{T(`terminal-layer-visibility`,{sessionId:t.sessionId,paneId:e.id,visible:!0});let n=window.requestAnimationFrame(()=>{let n=u.current?.getBoundingClientRect();T(`terminal-layer-layout`,{sessionId:t.sessionId,paneId:e.id,visible:!0,width:n?.width??0,height:n?.height??0})});return()=>window.cancelAnimationFrame(n)},[e.id,t.sessionId]),(0,V.jsx)(`div`,{ref:u,className:`pointer-events-auto absolute inset-0 min-h-0 min-w-0`,children:(0,V.jsx)(Eu,{paneId:e.id,state:t,worktreePath:e.worktreePath,session:n,pin:r,onClose:i,onClosePane:a,onOpenUrl:o,onOpenFilePath:t=>s(e.worktreePath,t),onRestartSession:c,onRenameSession:l})})}function Iu({activeProjectId:e,activeProjectPath:t,focusedPane:n,focusedWorktreeDirName:r,fileChangeSeq:i,gitState:a,gitFileStatuses:o,counters:s,gitMenuActions:c,gitGraphSelection:l,onGitGraphSelectionChange:u,commitBusy:d,commitError:f,onClearCommitError:p,onSubmitInlineCommit:m,isMobile:h,sessions:g,terminalPin:_,terminalOnClose:v,browserOnClose:y,onClosePane:b,onOpenUrl:x,onBrowserUrlChange:S,onRestartSession:C,onRenameSession:w,onSelectWorktreeTab:T}){let{state:E}=n;switch(E.kind){case`files`:return(0,V.jsx)(ku,{activeTab:`files`,worktreeName:r,worktreePath:n.worktreePath,counters:s,children:(0,V.jsx)(El,{paneId:n.id,projectId:e,worktreePath:n.worktreePath,fileChangeSeq:i,gitFileStatuses:o,isMobile:h,onChangeTab:e=>T(n.worktreePath,e)})});case`terminal`:{let e=g.find(e=>e.id===E.sessionId);return(0,V.jsx)(Eu,{paneId:n.id,state:E,worktreePath:n.worktreePath,session:e,pin:_,onClose:v,onClosePane:b,onOpenUrl:x,onOpenFilePath:e=>{bl(Mu(n.worktreePath),e),T(n.worktreePath,`files`)},onRestartSession:C,onRenameSession:w})}case`browser`:return(0,V.jsx)(Pc,{state:E,paneId:n.id,onClose:y,onUrlChange:S?e=>S(n.id,e):void 0});case`git`:return(0,V.jsx)(ku,{activeTab:`git`,worktreeName:r,worktreePath:n.worktreePath,counters:s,children:(0,V.jsx)(_u,{projectId:e,worktreePath:n.worktreePath,fileChangeSeq:i,isMobile:h,gitState:a,projectPath:t,selection:l,onSelectionChange:u,commitBusy:d,commitError:f,onClearCommitError:p,onSubmitInlineCommit:m,onChangeTab:e=>T(n.worktreePath,e),...c&&{gitActions:c}})})}}function Lu(e){return e.kind===`working-tree`?`Working tree`:e.commit.sha.slice(0,7)}function Ru(e,t){let{state:n}=e;if(n.kind===`terminal`)return wt(t.find(e=>e.id===n.sessionId));if(n.kind===`browser`)try{return new URL(n.url).host||n.url}catch{return n.url}return null}function zu(e,t,n,r,i){let a=[];if(e&&a.push({label:e,maxWidth:96}),t){let e=r?n?(0,V.jsx)(h.worktreeActive,{}):(0,V.jsx)(h.worktreeInactive,{}):(0,V.jsx)(h.folder,{});a.push({label:t,dim:!0,maxWidth:96,glyph:e})}return i&&a.push({label:i,dim:!0,glyph:(0,V.jsx)(h.branch,{})}),a.length===0&&a.push({label:`parasor`}),a}async function Bu(e,t){let n=await O(`/api/projects/${e}/worktrees`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({branch:t.branch,...t.base.length>0&&{base:t.base},...t.copyLocalFiles.length>0&&{copyLocalFiles:t.copyLocalFiles},...t.rememberLocalFiles&&{rememberLocalFiles:!0}})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Request failed (${n.status})`)}let r=await n.json().catch(()=>({})),i=r.path;if(!i)throw Error(`Worktree response missing path`);return{path:i,localFileCopies:r.localFileCopies}}async function Vu(e){let t=await O(`/api/projects/${encodeURIComponent(e)}/worktree-local-files`);if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Request failed (${t.status})`)}return await t.json()}function Hu(e,t){return O(`/api/projects/${e}/worktrees`,{signal:t})}var Uu=200,Q=`parasor:store-cache`,Wu=6,Gu={projects:[],projectStates:{},sessions:[],agentStates:{},notifications:[],ports:{},gitStates:{},serviceConfig:{preventIdleSleep:!1,portDetection:`all-interfaces`,dropSizeMaxBytes:Fe,dropSizeHardMaxBytes:Ie},paneCommands:[],ideCommands:[],hostPlatform:null,fileChangeSeq:0,worktrees:{},pendingOpenUrl:null,connected:!1,hydrated:!1,snapshotApplied:!1};function Ku(e,t){switch(t.type){case`session-created`:return{...e,sessions:[...e.sessions,t.session]};case`session-closed`:{let n={...e.agentStates};return delete n[t.sessionId],{...e,sessions:e.sessions.filter(e=>e.id!==t.sessionId),agentStates:n}}case`session-restarted`:{let n=e.sessions.find(e=>e.id===t.session.id);return n&&t.generation<n.generation?e:{...e,sessions:e.sessions.map(e=>e.id===t.session.id?t.session:e)}}case`session-ended`:{let n=e.sessions.find(e=>e.id===t.sessionId);return n&&t.generation<n.generation?e:{...e,sessions:e.sessions.map(e=>e.id===t.sessionId?{...e,state:`ended`,pid:null,endedAt:Date.now(),endReason:t.endReason}:e)}}case`agent-state`:return{...e,agentStates:{...e.agentStates,[t.state.sessionId]:t.state}};case`notification`:{let n=[t.notification,...e.notifications];return n.length>Uu&&(n.length=Uu),{...e,notifications:n}}case`project-created`:{let n=e.projects.some(e=>e.id===t.project.id)?e.projects.map(e=>e.id===t.project.id?t.project:e):[...e.projects,t.project],r=t.project.id in e.projectStates?e.projectStates:{...e.projectStates,[t.project.id]:{projectId:t.project.id,layout:null,worktrees:[],openFiles:[],lastFocusedPaneId:null,focusedPaneId:null,lastAccessedAt:t.project.createdAt}};return{...e,projects:n,projectStates:r}}case`project-updated`:return{...e,projects:e.projects.map(e=>e.id===t.project.id?t.project:e)};case`project-deleted`:{let n=new Set(e.sessions.filter(e=>e.projectId===t.projectId).map(e=>e.id)),r={...e.agentStates};for(let e of n)delete r[e];let{[t.projectId]:i,...a}=e.projectStates,{[t.projectId]:o,...s}=e.worktrees,{[t.projectId]:c,...l}=e.gitStates;return{...e,projects:e.projects.filter(e=>e.id!==t.projectId),sessions:e.sessions.filter(e=>e.projectId!==t.projectId),projectStates:a,agentStates:r,gitStates:l,worktrees:s}}case`layout-updated`:{let n=e.projectStates[t.projectId];return n?{...e,projectStates:{...e.projectStates,[t.projectId]:{...n,layout:t.layout}}}:e}case`ports-updated`:return{...e,ports:{...e.ports,[t.projectId]:t.ports}};case`git-state`:{let n={...e.gitStates[t.projectId]??{},[t.worktreePath]:t.state};return{...e,gitStates:{...e.gitStates,[t.projectId]:n}}}case`session-cwd-changed`:return{...e,sessions:e.sessions.map(e=>e.id===t.sessionId?{...e,cwd:t.cwd}:e)};case`session-title-changed`:return{...e,sessions:e.sessions.map(e=>{if(e.id!==t.sessionId)return e;if(t.titleManual===!0)return{...e,title:t.title,titleManual:!0};let{titleManual:n,...r}=e;return{...r,title:t.title}})};case`session-pin-changed`:return{...e,sessions:e.sessions.map(e=>{if(e.id!==t.sessionId)return e;if(t.pinned)return{...e,pinned:!0};let{pinned:n,...r}=e;return r})};case`file-change`:case`gitignore-updated`:return{...e,fileChangeSeq:e.fileChangeSeq+1};case`browser-url-changed`:return{...e,pendingOpenUrl:t.url};case`service-config-changed`:return{...e,serviceConfig:t.config};case`pane-commands-changed`:return{...e,paneCommands:t.commands};case`ide-commands-changed`:return{...e,ideCommands:t.commands};case`worktree-created`:{if(!e.projects.some(e=>e.id===t.projectId))return e;let n=e.worktrees[t.projectId]??[],r=n.findIndex(e=>e.path===t.worktree.path),i=r===-1?[...n,t.worktree]:n.map((e,n)=>n===r?{...e,...t.worktree}:e);return{...e,worktrees:{...e.worktrees,[t.projectId]:i}}}case`worktree-renamed`:{let n=e.worktrees[t.projectId];if(!n)return e;let r=n.map(e=>e.path===t.worktreePath?{...e,branch:t.newBranch}:e);return{...e,worktrees:{...e.worktrees,[t.projectId]:r}}}case`worktree-removed`:{let n=e.worktrees[t.projectId];if(!n)return e;let r=n.filter(e=>e.path!==t.worktreePath),i={...e.worktrees,[t.projectId]:r},a=e.gitStates[t.projectId],o=e.gitStates;if(a&&t.worktreePath in a){let{[t.worktreePath]:n,...r}=a;o={...e.gitStates,[t.projectId]:r}}return{...e,worktrees:i,gitStates:o}}default:return e}}function qu(e){return{projects:e.state.projects,projectStates:e.state.projectStates,sessions:e.state.sessions,agentStates:e.agentStates,notifications:[...e.notifications].reverse(),ports:e.ports,gitStates:e.gitStates,serviceConfig:e.state.serviceConfig,paneCommands:e.state.paneCommands??[],ideCommands:e.state.ideCommands??[],hostPlatform:e.hostPlatform,fileChangeSeq:0,worktrees:e.worktrees??{},pendingOpenUrl:null,connected:!0,hydrated:!0,snapshotApplied:!0}}function Ju(){try{let e=localStorage.getItem(Q);if(!e)return null;let t=JSON.parse(e);return t.version!==Wu||!Array.isArray(t.projects)||typeof t.projectStates!=`object`?null:{...Gu,projects:t.projects,projectStates:t.projectStates,sessions:Array.isArray(t.sessions)?t.sessions:[],agentStates:t.agentStates&&typeof t.agentStates==`object`?t.agentStates:{},gitStates:t.gitStates&&typeof t.gitStates==`object`?t.gitStates:{},paneCommands:Array.isArray(t.paneCommands)?t.paneCommands:[],ideCommands:Array.isArray(t.ideCommands)?t.ideCommands:[],hydrated:!0}}catch{return null}}function Yu(e){try{let t={version:Wu,projects:e.projects,projectStates:e.projectStates,sessions:e.sessions,agentStates:e.agentStates,gitStates:e.gitStates,paneCommands:e.paneCommands,ideCommands:e.ideCommands};localStorage.setItem(Q,JSON.stringify(t))}catch{}}var Xu=1e3,Zu=500,Qu=1e4,$u=2e4,ed=1e4;async function td(e){return typeof e==`string`?e:e instanceof Blob?e.text():e instanceof ArrayBuffer||ArrayBuffer.isView(e)?new TextDecoder().decode(e):null}function nd(){let[e,t]=(0,B.useState)(()=>Ju()??Gu),[n,r]=(0,B.useState)(!1),i=(0,B.useRef)({state:`awaiting-snapshot`,buffer:[]}),a=(0,B.useRef)(null),o=(0,B.useRef)(0),s=(0,B.useRef)(null),c=(0,B.useRef)(null),l=(0,B.useRef)(!0);(0,B.useEffect)(()=>{l.current=!0;let e=e=>{s.current&&clearTimeout(s.current);let n=a.current;a.current=null,i.current={state:`awaiting-snapshot`,buffer:[]},r(!1),t(e=>({...e,connected:!1})),n?.close(),s.current=setTimeout(()=>{l.current&&u()},e)},n=t=>{if(t){e(0);return}o.current+=1,e(ce(o.current))},u=async()=>{let e=performance.now(),s=performance.now(),c=await g(),u=performance.now()-s;if(T(`event-socket-auth-complete`,{attempt:o.current,durationMs:u,status:c?`ok`:`unauthenticated`}),c&&u>=1e3&&E(`event-socket-auth-slow`,{type:`event-socket-auth-complete`,attempt:o.current,durationMs:u,status:`ok`}),!c||!l.current)return;let d=location.protocol===`https:`?`wss:`:`ws:`,f=new WebSocket(`${d}//${location.host}/ws/events`);a.current=f,i.current={state:`awaiting-snapshot`,buffer:[]};let p=null,m=null,h=null,_=!1,v=0,y=0,b=()=>{m!==null&&(clearTimeout(m),m=null)},x=()=>{h!==null&&(clearTimeout(h),h=null)},S=()=>{if(f.readyState===WebSocket.OPEN&&m===null){try{f.send(JSON.stringify({type:`ping`,ts:Date.now()}))}catch{return}m=setTimeout(()=>{m=null;try{f.close()}catch{}},ed)}},C=()=>{document.visibilityState===`visible`&&S()},w=()=>S(),D=()=>S(),O=e=>{e.persisted&&S()},k=()=>{p!==null&&(clearInterval(p),p=null),b(),x(),document.removeEventListener(`visibilitychange`,C),window.removeEventListener(`focus`,w),window.removeEventListener(`online`,D),window.removeEventListener(`pageshow`,O)};f.addEventListener(`open`,()=>{if(!l.current||a.current!==f)return;y=performance.now();let t=y-e;T(`event-socket-open`,{attempt:o.current,durationMs:t}),t>=5e3&&E(`event-socket-open-slow`,{type:`event-socket-open`,attempt:o.current,durationMs:t}),o.current=0,r(!0),h=setTimeout(()=>{h=null,E(`event-socket-snapshot-timeout`,{type:`event-socket-snapshot-timeout`,attempt:o.current,timeoutMs:Qu,durationMs:performance.now()-e});try{f.close()}catch{}},Qu),p=setInterval(S,$u),document.addEventListener(`visibilitychange`,C),window.addEventListener(`focus`,w),window.addEventListener(`online`,D),window.addEventListener(`pageshow`,O)});let ee=e=>{if(!l.current||a.current!==f)return;let r;try{r=JSON.parse(e)}catch{return}if(`type`in r&&r.type===`pong`){b();return}if(`type`in r&&r.type===`app-state-snapshot`){x();let e=r,n=y>0?performance.now()-y:void 0;T(`event-socket-snapshot`,{attempt:o.current,...n===void 0?{}:{durationMs:n},status:`ok`}),n!==void 0&&n>=5e3&&E(`event-socket-snapshot-slow`,{type:`event-socket-snapshot`,attempt:o.current,durationMs:n,status:`ok`});let a=i.current.state===`awaiting-snapshot`?i.current.buffer:[],s=qu(e.payload),c=e.payload.seq,l=c;for(let e of a)e.seq<=c||(s=Ku(s,e.message),l=e.seq);_=!0,v=Date.now(),i.current={state:`live`,lastAppliedSeq:l},t(s);return}let s=r,c=i.current;if(c.state===`awaiting-snapshot`){if(c.buffer.length>=Xu){n(!1);return}i.current={state:`awaiting-snapshot`,buffer:[...c.buffer,s]};return}if(!(s.seq<=c.lastAppliedSeq)){if(s.seq>c.lastAppliedSeq+1){n(!1);return}i.current={state:`live`,lastAppliedSeq:s.seq},t(e=>Ku(e,s.message))}};f.addEventListener(`message`,e=>{if(typeof e.data==`string`){ee(e.data);return}td(e.data).then(e=>{e!==null&&ee(e)})}),f.addEventListener(`close`,()=>{k(),!(!l.current||a.current!==f)&&(r(!1),t(e=>({...e,connected:!1})),n(_&&Date.now()-v>=3e3))}),f.addEventListener(`error`,()=>{})};return u(),()=>{l.current=!1,s.current&&clearTimeout(s.current),c.current&&clearTimeout(c.current),a.current?.close(),a.current=null}},[]);let u=(0,B.useMemo)(()=>({...Gu,projects:e.projects,projectStates:e.projectStates,sessions:e.sessions,agentStates:e.agentStates,gitStates:e.gitStates,paneCommands:e.paneCommands,ideCommands:e.ideCommands,hydrated:e.hydrated}),[e.projects,e.projectStates,e.sessions,e.agentStates,e.gitStates,e.paneCommands,e.ideCommands,e.hydrated]);(0,B.useEffect)(()=>{u.hydrated&&(c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{Yu(u)},Zu))},[u]);let d=(0,B.useCallback)(e=>{t(t=>({...t,notifications:t.notifications.map(t=>t.id===e?{...t,read:!0}:t)}))},[]),f=(0,B.useCallback)(()=>{t(e=>({...e,pendingOpenUrl:null}))},[]),p=(0,B.useCallback)(e=>{t(t=>Ku(t,{type:`project-created`,project:e}))},[]),m=(0,B.useCallback)(e=>{t(t=>({...t,paneCommands:e}))},[]),h=(0,B.useCallback)(e=>{t(t=>({...t,ideCommands:e}))},[]),_=(0,B.useMemo)(()=>e.notifications.filter(e=>!e.read).length,[e.notifications]);return{...e,eventSocketConnected:n,unreadCount:_,markRead:d,clearPendingUrl:f,seedProject:p,seedPaneCommands:m,seedIdeCommands:h}}function rd(){(0,B.useEffect)(()=>{let e=e=>{if(e.defaultPrevented)return;e.preventDefault();let t=e.dataTransfer;t&&(t.dropEffect=`none`)};return window.addEventListener(`dragover`,e),window.addEventListener(`drop`,e),()=>{window.removeEventListener(`dragover`,e),window.removeEventListener(`drop`,e)}},[])}function id(e,t,n){let r;try{r=new URL(e)}catch{return null}if(r.protocol!==`http:`&&r.protocol!==`https:`)return null;let i;if(oe(r.hostname)){let e=r.port?Number(r.port):r.protocol===`https:`?443:80;Number.isInteger(e)&&(i=n(e,t?.projectId))}return F(e,{fallbackToPageHostWithoutReachablePort:de(),reachablePort:i})}function ad(e,t,n,r){let i=vt(e),a=new Set(t);a.add(n);let o={};for(let[e,t]of Object.entries(i))a.has(e)&&(o[e]=t);return o[n]=r,o}function od(e){return typeof e==`number`&&Number.isInteger(e)&&e>0&&e<65536}function sd(e){let t=new Map,n=new Map,r=new Set;for(let[i,a]of Object.entries(e)){let e=new Map;for(let t of a??[])od(t.port)&&(od(t.reachablePort)?e.set(t.port,t.reachablePort):t.bindsAll&&e.set(t.port,t.port));if(e.size!==0){t.set(i,e);for(let[t,i]of e){let e=n.get(t);e===void 0?n.set(t,i):e!==i&&r.add(t)}}}return{ambiguousDevPorts:r,byProjectId:t,fallbackByDevPort:n}}function cd(e,t,n){if(n.projectId){let r=e.byProjectId.get(n.projectId)?.get(t);if(r!==void 0)return r}if(n.activeProjectId){let r=e.byProjectId.get(n.activeProjectId)?.get(t);if(r!==void 0)return r}if(!e.ambiguousDevPorts.has(t))return e.fallbackByDevPort.get(t)}function ld(e,t){if(t.length===0)return e;let n=new Set(e.map(e=>e.id)),r=t.filter(e=>!n.has(e.id));return r.length>0?[...e,...r]:e}function ud(e){if(!e||e.length===0)return null;let t=e.filter(e=>e.status===`copied`).length,n=e.filter(e=>e.status===`skipped`).length,r=e.filter(e=>e.status===`failed`).length,i=[];return t>0&&i.push(`Copied ${t}`),n>0&&i.push(`skipped ${n}`),r>0&&i.push(`failed ${r}`),`${i.join(`, `)} local ${e.length===1?`file`:`files`}`}function dd(){let e=(0,B.useRef)(performance.now()),t=(0,B.useRef)(!1);rd();let{playAttentionSound:n,playCompletionSound:r}=w(),{activeProjectId:i,focusedPaneId:a,setActiveProjectId:o,setFocusedPaneId:s}=fc(),{navigate:c,route:l}=vc(),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(null),[m,h]=(0,B.useState)(!1),[g,_]=(0,B.useState)(0),[v,y]=Ds(),[b,x]=(0,B.useState)([]),S=nd(),C=(0,B.useMemo)(()=>Xs(S.paneCommands),[S.paneCommands]),D=(0,B.useMemo)(()=>ld(S.sessions,b),[S.sessions,b]);(0,B.useEffect)(()=>{if(b.length===0)return;let e=new Set(S.sessions.map(e=>e.id));x(t=>{let n=t.filter(t=>!e.has(t.id));return n.length===t.length?t:n})},[b.length,S.sessions]);let O=(0,B.useMemo)(()=>i?S.worktrees[i]??[]:[],[i,S.worktrees]),k=(0,B.useMemo)(()=>{let e={};for(let[t,n]of Object.entries(S.worktrees)){let r=S.gitStates[t]??{};e[t]=n.map(e=>{let t=r[e.path];return t?{...e,ahead:t.ahead,behind:t.behind,dirtyCount:t.dirtyCount}:e})}return e},[S.worktrees,S.gitStates]),ee=rc({activeProjectId:i,agentStates:S.agentStates,sessions:D}),A=St({focusedPaneId:a,agentStates:S.agentStates});gs({activeProjectId:i,agentStates:S.agentStates,snapshotApplied:S.snapshotApplied,playAttentionSound:n,playCompletionSound:r,sessions:D});let j=(0,B.useMemo)(()=>i?S.projects.find(e=>e.id===i)??null:null,[i,S.projects]),ne=j?.name??null,M=j?.path??null;yc({activeProjectId:i,connected:S.connected,projects:S.projects,setActiveProjectId:o});let re=(0,B.useMemo)(()=>f?S.projects.find(e=>e.id===f)??null:null,[f,S.projects]),ie=(0,B.useMemo)(()=>D.filter(e=>e.pinned===!0).length,[D]),ae=(0,B.useMemo)(()=>D.filter(e=>e.projectId===i),[D,i]),P=Cs(i),F=ac({projectId:i,projectPath:M,worktrees:O,sessions:D,focusedPaneId:a,clientBrowserPanes:P.panesByWorktree});(0,B.useEffect)(()=>{if(t.current)return;t.current=!0;let n=performance.now()-e.current,r=l.kind===`pane`?l.paneId:l.kind===`session`?De(l.sessionId):F.effectiveFocusedPaneId;T(`app-route-ready`,{routeKind:l.kind,paneId:r,sessionId:l.kind===`session`?l.sessionId:void 0,durationMs:n,status:S.hydrated?`hydrated`:`cached`}),n>=5e3&&E(`app-route-ready-slow`,{type:`app-route-ready`,routeKind:l.kind,paneId:r,sessionId:l.kind===`session`?l.sessionId:void 0,durationMs:n,status:S.hydrated?`hydrated`:`cached`})},[F.effectiveFocusedPaneId,l,S.hydrated]),(0,B.useEffect)(()=>{F.effectiveFocusedPaneId!==null&&F.effectiveFocusedPaneId!==a&&s(F.effectiveFocusedPaneId)},[F.effectiveFocusedPaneId,a,s]),(0,B.useEffect)(()=>{if(l.kind===`root`){m&&h(!1);return}if(l.kind===`monitor`){m||h(!0);return}if(l.kind===`session`){let e=D.find(e=>e.id===l.sessionId);if(!e)return;let t=De(e.id);m&&h(!1),i!==e.projectId&&o(e.projectId),a!==t&&(s(t),se(t));return}if(l.kind===`pane`){if(m&&h(!1),S.hydrated&&l.projectId&&!S.projects.some(e=>e.id===l.projectId)){c({kind:`root`},{replace:!0});return}l.projectId&&i!==l.projectId&&o(l.projectId),a!==l.paneId&&(s(l.paneId),se(l.paneId));return}if(l.kind===`worktree`){if(S.hydrated&&!S.projects.some(e=>e.id===l.projectId)){m&&h(!1),c({kind:`root`},{replace:!0});return}let e=l.tab===`git`?Ee(l.worktreePath):Te(l.worktreePath);m&&h(!1),i!==l.projectId&&o(l.projectId),a!==e&&(s(e),se(e))}},[i,a,m,l,o,s,D,S.hydrated,S.projects,c]);let I=F.focusedPane?.worktreePath??null,L=(0,B.useMemo)(()=>!i||!I?null:S.gitStates[i]?.[I]??null,[i,I,S.gitStates]),R=(0,B.useMemo)(()=>!i||!I?null:S.worktrees[i]?.find(e=>e.path===I)??null,[i,I,S.worktrees]),oe=(0,B.useMemo)(()=>{let e=F.focusedPane;return!e||!j?null:(L?.branch??R?.branch??null)||(e.worktreePath===j.path?`main`:e.worktreePath.replace(/\/+$/,``).split(`/`).pop()??e.worktreePath)},[F.focusedPane,j,L,R]),ce=(0,B.useMemo)(()=>j?S.gitStates[j.id]?.[j.path]?.isRepo!==!1:!0,[j,S.gitStates]),le=(0,B.useMemo)(()=>{let e=F.focusedPane;return!e||!j?null:Ts(e.worktreePath,j.path,ce)},[F.focusedPane,j,ce]),de=L?.branch??null,fe=F.focusedPane?.state.kind===`git`,me=Ks({activeProjectId:i,focusedWorktreePath:I,focusedWorktreeName:oe,gitState:L}),z=wc(),{canOpenLocalIde:ge}=ec(),_e=(0,B.useCallback)((e,t)=>{z.openWorktreeInFinder({projectId:e,worktreePath:t})},[z]),ve=(0,B.useCallback)((e,t,n)=>{z.openWorktreeInIde({projectId:e,worktreePath:t,editor:n})},[z]),ye=(0,B.useCallback)(e=>{z.copyWorktreePath(e)},[z]),be=(0,B.useCallback)((e,t,n)=>{let r=S.gitStates[e]?.[t]?.branch,i=r&&r.length>0?r:n;z.openRenameDialog({projectId:e,worktreePath:t,currentBranch:i})},[z,S.gitStates]),xe=(0,B.useCallback)((e,t,n)=>{let r=S.gitStates[e]?.[t],i=r?.branch&&r.branch.length>0?r.branch:n,a=r?.dirtyCount??0,o=S.worktrees[e]?.find(e=>e.path===t);z.openRemoveDialog({projectId:e,worktreePath:t,branch:i,dirtyCount:a,...o?.orphan===!0&&{orphan:!0}})},[z,S.gitStates,S.worktrees]),[Se,Ce]=Os(I),{createProject:we,deleteProject:Oe}=pc({activeProjectId:i,projects:S.projects,setActiveProjectId:o,seedProject:S.seedProject}),ke=(0,B.useCallback)(async(e,t,n,r,a)=>{let l=await ls({projectId:e,command:t,title:n,cwd:r,bootstrapInput:a});if(!l)return;x(e=>e.some(e=>e.id===l.id)?e:[...e,l]),e!==i&&o(e);let u=`terminal:${l.id}`;s(u),se(u),c({kind:`session`,sessionId:l.id})},[i,c,o,s]),Ae=(0,B.useCallback)((e,t,n)=>{let r=n.initialInput.trim(),i=r?`${r}\r`:void 0;ke(e,void 0,n.builtin?void 0:n.label,t,i)},[ke]),je=(0,B.useCallback)(async(e,t)=>{let n=await Bu(e,{branch:t.branch,base:t.base,copyLocalFiles:t.copyLocalFiles,rememberLocalFiles:t.rememberLocalFiles}),r=n.path,i=ud(n.localFileCopies);i&&y(i);let a=t.command.initialInput.trim(),o=a?`${a}\r`:void 0;await ke(e,void 0,t.command.builtin?void 0:t.command.label,r,o)},[ke,y]),Me=(0,B.useCallback)(e=>{let t=S.paneCommands;S.seedPaneCommands(e),os(e).then(e=>{Array.isArray(e.commands)&&S.seedPaneCommands(e.commands);try{window.localStorage.removeItem(qs)}catch{}}).catch(()=>{S.seedPaneCommands(t),y(`Failed to save terminal commands`)})},[S,y]),Ne=(0,B.useCallback)(e=>{let t=S.ideCommands;S.seedIdeCommands(e),ss(e).then(e=>{Array.isArray(e.commands)&&S.seedIdeCommands(e.commands)}).catch(()=>{S.seedIdeCommands(t),y(`Failed to save IDE commands`)})},[S,y]);$s({hydrated:S.hydrated,paneCommandsCount:S.paneCommands.length,onMigrate:Me});let Pe=(0,B.useCallback)(async e=>{await us(e)},[]),Fe=(0,B.useCallback)(async(e,t)=>{await ds(e,t)},[]),Ie=(0,B.useCallback)(async e=>{let t=D.find(t=>t.id===e);t&&await fs(e,t.pinned!==!0)},[D]),Le=(0,B.useCallback)(async e=>{let t=F.paneById.get(e);if(t){if(t.state.kind===`terminal`){await ps(t.state.sessionId);return}if(t.state.kind===`browser`){P.closeBrowser(e);return}}},[P,F.paneById]),Re=(0,B.useCallback)(e=>{let t=S.projects.find(t=>t.id===e.projectId);t&&(i!==e.projectId&&o(e.projectId),s(Te(t.path))),c({kind:`root`}),ps(e.id)},[i,c,o,s,S.projects]),ze=(0,B.useMemo)(()=>sd(S.ports),[S.ports]),Be=(0,B.useCallback)((e,t)=>cd(ze,e,{activeProjectId:i,projectId:t}),[i,ze]),Ve=(0,B.useCallback)((e,t)=>{let n=id(e,t,Be);n!==null&&ue(n)},[Be]);(0,B.useEffect)(()=>{S.pendingOpenUrl&&(Ve(S.pendingOpenUrl),S.clearPendingUrl())},[S.pendingOpenUrl,S.clearPendingUrl,Ve]);let{closeSettings:He,isMobile:Ue,openSettings:We,settingsOpen:Ge}=Cc({activeProjectId:i,projects:S.projects,setActiveProjectId:o});(0,B.useEffect)(()=>{T(`mobile-surface-route`,{routeKind:l.kind,surface:Ue?l.kind===`root`?`navigation`:`workspace`:`split`,paneId:F.focusedPane?.id??null})},[Ue,F.focusedPane?.id,l.kind]);let Ke=(0,B.useCallback)(async e=>{let t=l.kind===`pane`&&l.projectId===e||l.kind===`worktree`&&l.projectId===e||l.kind===`session`&&D.some(t=>t.id===l.sessionId&&t.projectId===e);await Oe(e),t&&c({kind:`root`},{replace:!0}),p(null)},[Oe,c,l,D]),Ye=ws({onConfirm:(0,B.useCallback)(async e=>{(Ue||l.kind===`session`&&e.paneId===De(l.sessionId)||l.kind===`pane`&&e.paneId===l.paneId)&&c({kind:`root`}),await Le(e.paneId)},[Le,Ue,c,l])}),Ze=(0,B.useCallback)(()=>{d(!0)},[]),{reorderResetSignal:Qe,pendingProjectReorderCount:$e,reorder:et}=nc({onError:y}),tt=(0,B.useCallback)((e,t,n)=>{let r=`paneOrder:${e}`,i=vt.current.find(t=>t.id===e)?.worktrees.map(e=>e.path)??[],a=ad(window.localStorage.getItem(r),i,t,n);try{window.localStorage.setItem(r,JSON.stringify(a))}catch{}_(e=>e+1)},[]),nt=(0,B.useCallback)(e=>Vu(e),[]),rt=(0,B.useCallback)(()=>{We()},[We]),it=(0,B.useCallback)(e=>{Yo({preventIdleSleep:e})},[]),at=(0,B.useCallback)(e=>{Yo({portDetection:e})},[]),ot=(0,B.useCallback)(e=>{Yo({dropSizeMaxBytes:e})},[]),st=(0,B.useMemo)(()=>Object.fromEntries(S.projects.map(e=>[e.id,e.name])),[S.projects]);(0,B.useEffect)(()=>{if(!S.connected||!i)return;let e=new AbortController;return Hu(i,e.signal).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||console.warn(`Worktree refresh failed:`,e)}),()=>e.abort()},[i,S.connected]);let{open:dt,query:ft,setQuery:pt,toggle:mt,close:ht}=ic({isMobile:Ue,onMobileOpenShortcut:(0,B.useCallback)(()=>c({kind:`root`}),[c])}),_t=(0,B.useMemo)(()=>bt(Ot({projects:S.projects,activeProjectId:i,activeWorktrees:F.worktrees,sessions:D,agentStates:S.agentStates,reviewPendingSessions:ee,worktreesByProject:k,gitStates:S.gitStates,attentionDismissed:A,inactiveChildPanesByProject:gt(S.projects)})),[S.projects,i,F.worktrees,D,S.agentStates,ee,k,S.gitStates,A,g]),vt=(0,B.useRef)(_t);vt.current=_t;let yt=(0,B.useCallback)(()=>{h(!0),ht(),c({kind:`monitor`})},[ht,c]),xt=(0,B.useCallback)((e,t)=>{h(!1),e!==i&&o(e);let n=t.startsWith(`wt:`)?t.slice(3):t,r=Te(n);s(r),se(r),ht(),c({kind:`worktree`,projectId:e,worktreePath:n,tab:`files`})},[i,ht,c,o,s]),Ct=(0,B.useCallback)((e,t,n)=>{h(!1),e!==i&&o(e),s(n),se(n),ht(),n.startsWith(`terminal:`)?c({kind:`session`,sessionId:n.slice(9)}):c({kind:`pane`,paneId:n,projectId:e})},[i,ht,c,o,s]),wt=Es({projects:S.projects,gitStates:S.gitStates}),Tt=(0,B.useCallback)((e,t)=>{wt.open(e,t),Ue&&ht()},[wt.open,ht,Ue]),Et=(0,B.useCallback)(e=>{e.startsWith(`terminal:`)&&Ie(e.slice(9))},[Ie]),Dt=(0,B.useMemo)(()=>({projects:_t,selection:{monitor:m,selectedWorktreeId:!m&&F.focusedPane?`wt:${F.focusedPane.worktreePath}`:null,selectedChildId:!m&&F.focusedPane&&(F.focusedPane.state.kind===`terminal`||F.focusedPane.state.kind===`browser`)?F.focusedPane.id:null},connected:S.connected,portsByProjectId:S.ports,projectNames:st,onOpenUrl:Ve,pinnedMonitorCount:ie,onSelectMonitor:yt,onSelectWorktree:xt,onSelectChild:Ct,onOpenContainer:Tt,onToggleChildPin:Et,onNewProject:Ze,onOpenSettings:rt,searchOpen:dt,searchQuery:ft,onToggleSearch:mt,onCloseSearch:ht,onSearchQueryChange:pt,onReorderProjects:et,onReorderPanes:tt,reorderResetSignal:Qe,pendingProjectReorderCount:$e}),[_t,m,F.focusedPane,S.connected,S.ports,st,Ve,ie,yt,xt,Ct,Tt,Et,Ze,rt,dt,ft,mt,ht,pt,et,tt,Qe,$e]),kt=wt.target,At=wt.context,jt=(0,V.jsx)(Wa,{...Dt,fill:!0}),Mt=l.kind===`session`?D.find(e=>e.id===l.sessionId)??null:null,Nt=l.kind===`session`&&!Mt?l.sessionId:null,Pt=Mt?.state===`ended`&&!pe(Mt.command,Mt.endReason)?Mt:null,Ft=Nt?(0,V.jsx)(Je,{sessionId:Nt,hydrated:S.hydrated,connected:S.eventSocketConnected,onClose:()=>c({kind:`root`})}):Pt?(0,V.jsx)(he,{sessionTitle:Pt.title.trim()||Pt.id,command:Pt.command,endReason:Pt.endReason,onRestart:()=>void Pe(Pt.id),onClose:()=>Re(Pt)}):m?(0,V.jsx)(Io,{projects:S.projects,sessions:D,agentStates:S.agentStates,reviewPendingSessions:ee,gitStates:S.gitStates,attentionDismissed:A,isMobile:Ue,onToggleDrawer:()=>c({kind:`root`}),onRestartSession:Pe,onOpenUrl:Ve,onTogglePin:Ie}):(0,V.jsx)(Nu,{activeProjectId:i,activeProjectName:ne,activeProjectPath:M,activeProjectIsRepo:ce,allPanes:F.allPanes,focusedPane:F.focusedPane,focusedWorktreeDirName:le,fileChangeSeq:S.fileChangeSeq,gitState:L,hydrated:S.hydrated,isMobile:Ue,gitMenuActions:fe?{onPull:()=>me.pull(),onPush:()=>me.push()}:void 0,gitGraphSelection:Se,onGitGraphSelectionChange:Ce,gitBranchName:de,commitBusy:me.commitBusy,commitError:me.commitError,onClearCommitError:me.clearCommitError,onSubmitInlineCommit:me.submitInlineCommit,sessions:ae,onToggleDrawer:()=>c({kind:`root`}),onClosePane:Le,onRequestClosePane:Ye.request,onNewProject:Ze,onOpenUrl:Ve,onBrowserUrlChange:P.updateBrowserUrl,onRestartSession:Pe,onRenameSession:Fe,onSelectWorktreeTab:(e,t)=>{s(t===`git`?Ee(e):Te(e)),i&&c({kind:`worktree`,projectId:i,worktreePath:e,tab:t})},onToggleSessionPin:Ie,onOpenWorktreeInFinder:_e,onOpenWorktreeInIde:ve,ideCommands:S.ideCommands,canOpenLocalIde:ge,onCopyWorktreePath:ye,onRenameWorktree:be,onRemoveWorktree:xe,onDeleteProject:e=>p(e)});return(0,V.jsx)(N,{projects:S.projects,children:(0,V.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,V.jsx)(no,{connected:S.eventSocketConnected}),(0,V.jsx)(io,{}),(0,V.jsx)(`div`,{className:`flex flex-1 overflow-hidden`,children:Ue?l.kind===`root`?jt:Ft:(0,V.jsx)(is,{navigation:jt,main:Ft})}),(0,V.jsx)(ct,{open:u,onClose:()=>d(!1),onCreate:(e,t)=>(h(!1),we(e,t)),isMobile:Ue}),(0,V.jsx)(te,{open:Ge,onClose:He,server:{serviceConfig:S.serviceConfig,hostPlatform:S.hostPlatform,onPreventIdleSleepChange:it,onPortDetectionChange:at,onDropSizeMaxBytesChange:ot,ideCommands:S.ideCommands,onIdeCommandsChange:Ne}}),v&&(0,V.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`pointer-events-none fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded-window border border-warning/60 bg-bg-secondary px-3 py-2 text-sm text-text-primary shadow-lg`,children:v}),re&&(0,V.jsx)(cs,{projectName:re.name,onCancel:()=>p(null),onConfirm:()=>void Ke(re.id)}),Ye.target&&(0,V.jsx)(as,{paneTitle:Ye.target.title,paneKind:Ye.target.paneKind,onCancel:Ye.cancel,onConfirm:()=>void Ye.confirm()}),kt&&At&&(0,V.jsx)(Xe,{open:!0,project:At.project,worktree:At.worktree,commands:C,isMobile:Ue,loadLocalFiles:nt,onClose:wt.close,onCommandsChange:Me,onCreateWorktreeSession:e=>je(kt.projectId,e),onRunCommand:(e,t)=>Ae(kt.projectId,e,t)}),z.renameDialog&&(0,V.jsx)(ut,{open:!0,currentBranch:z.renameDialog.currentBranch,busy:z.renameBusy,error:z.renameError,onClose:z.closeRenameDialog,onSubmit:z.submitRename}),z.removeDialog&&(0,V.jsx)(lt,{open:!0,branch:z.removeDialog.branch,worktreePath:z.removeDialog.worktreePath,dirtyCount:z.removeDialog.dirtyCount,orphan:z.removeDialog.orphan===!0,busy:z.removeBusy,error:z.removeError,onClose:z.closeRemoveDialog,onSubmit:z.submitRemove}),(0,V.jsx)(qe,{open:me.commitDialog!==null,busy:me.commitBusy,error:me.commitError,branchName:me.commitDialog?.branchName??null,files:me.commitDialog?.files??[],isMobile:Ue,onClose:me.closeCommitDialog,onCommit:me.submitCommit}),(0,V.jsx)(yo,{}),(0,V.jsx)(eo,{})]})})}function fd({children:e}){let[t,n]=(0,B.useState)(`loading`);return(0,B.useEffect)(()=>{let e=!1;(async()=>{let t=performance.now(),r=await g({dispatchOn401:!1}),i=performance.now()-t;T(`auth-gate-preflight-complete`,{durationMs:i,status:r?`ok`:`unauthenticated`}),r&&i>=1e3&&E(`auth-gate-preflight-slow`,{type:`auth-gate-preflight-complete`,durationMs:i,status:`ok`}),!e&&n(r?`authed`:`unauthenticated`)})();let t=()=>n(`expired`);return window.addEventListener(k,t),()=>{e=!0,window.removeEventListener(k,t)}},[]),t===`loading`?null:t===`unauthenticated`?(0,V.jsx)(pd,{}):t===`expired`?(0,V.jsx)(md,{}):(0,V.jsx)(V.Fragment,{children:e})}function pd(){return(0,V.jsxs)(`div`,{role:`alert`,"aria-live":`assertive`,className:`flex h-full flex-col items-center justify-center gap-4 bg-[--theme-background] p-6 text-center text-[--theme-foreground]`,children:[(0,V.jsx)(`h1`,{className:`text-base font-semibold`,children:`Authentication required`}),(0,V.jsxs)(`p`,{className:`max-w-md text-sm opacity-80`,children:[`Open the URL printed by`,` `,(0,V.jsx)(`code`,{className:`rounded-control bg-black/20 px-1 py-0.5`,children:`parasor qr`}),`, or scan the QR code on the host. If you copied the URL from a terminal that wrapped the line, the token may have been truncated -- scanning the QR avoids that.`]})]})}function md(){return(0,V.jsxs)(`div`,{role:`alert`,"aria-live":`assertive`,className:`flex h-full flex-col items-center justify-center gap-4 bg-[--theme-background] p-6 text-center text-[--theme-foreground]`,children:[(0,V.jsx)(`h1`,{className:`text-base font-semibold`,children:`Session expired`}),(0,V.jsxs)(`p`,{className:`max-w-md text-sm opacity-80`,children:[`Run`,` `,(0,V.jsx)(`code`,{className:`rounded-control bg-black/20 px-1 py-0.5`,children:`parasor qr`}),` `,`on the host and open the refreshed URL to sign back in.`]})]})}var hd=e=>e.preventDefault();document.addEventListener(`gesturestart`,hd),document.addEventListener(`gesturechange`,hd),document.addEventListener(`gestureend`,hd);var gd=class extends B.Component{state={error:null,info:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({error:e,info:t}),console.error(`[parasor ErrorBoundary]`,e,t),E(`react-error-boundary`,{type:`react-error-boundary`,status:e.name})}render(){return this.state.error?(0,V.jsxs)(`div`,{style:{position:`fixed`,inset:0,background:`#000`,color:`#fff`,padding:16,fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:12,overflow:`auto`,zIndex:2147483647},children:[(0,V.jsx)(`div`,{style:{color:`#ff5555`,fontSize:14,marginBottom:8},children:`⚠ React error caught`}),(0,V.jsxs)(`div`,{style:{color:`#ffaa00`,marginBottom:8},children:[this.state.error.name,`: `,this.state.error.message]}),(0,V.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,color:`#aaa`,fontSize:10},children:this.state.error.stack}),this.state.info&&(0,V.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,color:`#666`,fontSize:10,marginTop:8},children:this.state.info.componentStack}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>this.setState({error:null,info:null}),style:{marginTop:12,padding:`6px 12px`,background:`#2f81f7`,color:`#fff`,border:0,borderRadius:4,fontSize:12},children:`Try again`})]}):this.props.children}},_d=document.getElementById(`root`);if(!_d)throw Error(`Missing #root element`);(0,Le.createRoot)(_d).render((0,V.jsx)(gd,{children:(0,V.jsx)(x,{children:(0,V.jsx)(fd,{children:(0,V.jsx)(dd,{})})})}));