@self-review/serve 2.1.2 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/client/assets/{abnfDiagram-VCTEODGH-Dxm_OGm7.js → abnfDiagram-VCTEODGH-IKf-b5JY.js} +1 -1
  2. package/dist/client/assets/{arc-BkF-Cs_1.js → arc-DO7aMEvZ.js} +1 -1
  3. package/dist/client/assets/{architectureDiagram-5GKGNRK7-zB4eyVpl.js → architectureDiagram-5GKGNRK7-DElMPEwi.js} +1 -1
  4. package/dist/client/assets/{blockDiagram-I7D4REHJ-cinsJzJ1.js → blockDiagram-I7D4REHJ-BXdda29o.js} +1 -1
  5. package/dist/client/assets/{c4Diagram-7LVT6UL2-D4TGkD91.js → c4Diagram-7LVT6UL2-BUPE8OHg.js} +1 -1
  6. package/dist/client/assets/channel-D5KuYoCF.js +1 -0
  7. package/dist/client/assets/{chunk-2Q5K7J3B-C8HjvUMv.js → chunk-2Q5K7J3B-DyduR-xM.js} +1 -1
  8. package/dist/client/assets/{chunk-5VM5RSS4-45fUpmT8.js → chunk-5VM5RSS4-7hAWkbbN.js} +1 -1
  9. package/dist/client/assets/{chunk-F27PBJKO-DObAqHRK.js → chunk-F27PBJKO-BIZnCJRa.js} +1 -1
  10. package/dist/client/assets/{chunk-IMKFNOWR-DPvCBgjP.js → chunk-IMKFNOWR-Dq_kYduQ.js} +1 -1
  11. package/dist/client/assets/{chunk-JWPE2WC7-D3HxOmIl.js → chunk-JWPE2WC7-BnQEVXFo.js} +1 -1
  12. package/dist/client/assets/{chunk-POPQ4Y6H-CeetmS6D.js → chunk-POPQ4Y6H-DKV-lR-m.js} +1 -1
  13. package/dist/client/assets/{chunk-SVP7TREG-BltjJmw4.js → chunk-SVP7TREG-D9ubH7XA.js} +1 -1
  14. package/dist/client/assets/{chunk-TICWLB2K-CRp0Zdpy.js → chunk-TICWLB2K-CZVdHovU.js} +1 -1
  15. package/dist/client/assets/{chunk-XXDRQBXY-BhqJXAOb.js → chunk-XXDRQBXY-Bf9LVMaI.js} +1 -1
  16. package/dist/client/assets/classDiagram-ZZMXUADV-CcTcgvwv.js +1 -0
  17. package/dist/client/assets/classDiagram-v2-VYDZK3BY-CcTcgvwv.js +1 -0
  18. package/dist/client/assets/{cose-bilkent-JH36ORCC-D29IHBME.js → cose-bilkent-JH36ORCC-Rieo2UXl.js} +1 -1
  19. package/dist/client/assets/{cynefin-OW5HDTMX-DbO7Hdnr.js → cynefin-OW5HDTMX-D9NfHV5I.js} +1 -1
  20. package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-AmW3TeXb.js → cynefinDiagram-5FMLGOSQ-c9UsKcEs.js} +1 -1
  21. package/dist/client/assets/{dagre-GXQ25YYZ-BIyWjaCd.js → dagre-GXQ25YYZ-JoBGhSHF.js} +1 -1
  22. package/dist/client/assets/{diagram-S7CK7UJ4-CBHWhWpQ.js → diagram-S7CK7UJ4-D_omA6GE.js} +1 -1
  23. package/dist/client/assets/{diagram-UQ7AKVKN-DRTCWqRa.js → diagram-UQ7AKVKN-8HwSGyUj.js} +1 -1
  24. package/dist/client/assets/{diagram-VSXAHHWV-GE0ZO13U.js → diagram-VSXAHHWV-ZQH48Gbi.js} +1 -1
  25. package/dist/client/assets/{diagram-VX7I27RA-BBp26skq.js → diagram-VX7I27RA-qk9b0xw3.js} +1 -1
  26. package/dist/client/assets/{diagram-Z3DM3KII-CSUSeDRk.js → diagram-Z3DM3KII-DJyyWvwd.js} +1 -1
  27. package/dist/client/assets/{ebnfDiagram-PWID7BFC-2RgBVavT.js → ebnfDiagram-PWID7BFC-COFbDGpD.js} +1 -1
  28. package/dist/client/assets/{erDiagram-RLTQ6QDP-DoEVHzNL.js → erDiagram-RLTQ6QDP-D8IOuVle.js} +1 -1
  29. package/dist/client/assets/{flowDiagram-HODETNUW-BLeHpICc.js → flowDiagram-HODETNUW-D8zRNCrU.js} +1 -1
  30. package/dist/client/assets/{ganttDiagram-EL5Y4UJY-BE4gCIyJ.js → ganttDiagram-EL5Y4UJY-mPPl04h2.js} +1 -1
  31. package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-BuuJ4_PE.js → gitGraphDiagram-WWUBYQGX-cWo4cHu2.js} +1 -1
  32. package/dist/client/assets/{index-P5EmeykP.js → index-CJHW-oJl.js} +5 -5
  33. package/dist/client/assets/index-Ccp0a0yE.css +1 -0
  34. package/dist/client/assets/{infoDiagram-27XIBGKW-Dj6SJlyc.js → infoDiagram-27XIBGKW-2vulMq_D.js} +1 -1
  35. package/dist/client/assets/{ishikawaDiagram-5VMMS53U-BVxSH4Dd.js → ishikawaDiagram-5VMMS53U-CLRLZk0G.js} +1 -1
  36. package/dist/client/assets/{journeyDiagram-3NMN7TZE-BQIb4zis.js → journeyDiagram-3NMN7TZE-BAcqLfq0.js} +1 -1
  37. package/dist/client/assets/{kanban-definition-UXKFOSKX-zswZjsPL.js → kanban-definition-UXKFOSKX-Tmt9Kmcs.js} +1 -1
  38. package/dist/client/assets/{layout-i9tH82X4.js → layout-WaFAdD1v.js} +1 -1
  39. package/dist/client/assets/{linear-CGCu0_8r.js → linear-DsnFgJUl.js} +1 -1
  40. package/dist/client/assets/{mermaid.core-DGOIMnVG.js → mermaid.core-DQk_LOzK.js} +5 -5
  41. package/dist/client/assets/{mindmap-definition-YA3MSWOX-DXzfof8m.js → mindmap-definition-YA3MSWOX-uYjdz29j.js} +1 -1
  42. package/dist/client/assets/{pegDiagram-XKGWAZYB-CmhgC38j.js → pegDiagram-XKGWAZYB-YfdMtg7_.js} +1 -1
  43. package/dist/client/assets/{pieDiagram-E7YTZNPT-iiATrVql.js → pieDiagram-E7YTZNPT-BXj58KIk.js} +1 -1
  44. package/dist/client/assets/{quadrantDiagram-AXDQQJYC-eENXXuDO.js → quadrantDiagram-AXDQQJYC-DsxXxOur.js} +1 -1
  45. package/dist/client/assets/{railroadDiagram-O6MQD6OU-Ve9DVyyu.js → railroadDiagram-O6MQD6OU-DhOdwf1Z.js} +1 -1
  46. package/dist/client/assets/{requirementDiagram-BXWQKSXE-Ds3SiU76.js → requirementDiagram-BXWQKSXE-BUF_TYXO.js} +1 -1
  47. package/dist/client/assets/{sankeyDiagram-P5KCCOFB-Ca_9nHzQ.js → sankeyDiagram-P5KCCOFB-C_M_vy_-.js} +1 -1
  48. package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-YB9gvQgl.js → sequenceDiagram-WJ2MYXX4-Bi_pNWS0.js} +1 -1
  49. package/dist/client/assets/{sizeCapture-INFHLROL-CNrWHUe0.js → sizeCapture-INFHLROL-BH21lZ7F.js} +1 -1
  50. package/dist/client/assets/{stateDiagram-D77RDMKH-MSnDTD49.js → stateDiagram-D77RDMKH-Vkiy0PJf.js} +1 -1
  51. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-bEBHSK7Y.js +1 -0
  52. package/dist/client/assets/{swimlanes-42K2YHIH-DA1GpdIB.js → swimlanes-42K2YHIH-4vN-c4Dg.js} +1 -1
  53. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-CY4jBKOp.js +8 -0
  54. package/dist/client/assets/{timeline-definition-24CTP7MA-CKkqwVz6.js → timeline-definition-24CTP7MA-CHV3Rjpf.js} +1 -1
  55. package/dist/client/assets/{vennDiagram-4TSXK5OY-Bu9SbqJ4.js → vennDiagram-4TSXK5OY-DbCx-MNI.js} +1 -1
  56. package/dist/client/assets/{wardleyDiagram-VM6X3IG4-DCUikUwQ.js → wardleyDiagram-VM6X3IG4-_RdU0ouf.js} +1 -1
  57. package/dist/client/assets/{xychartDiagram-S5SC5T6Z-DS3iQdcW.js → xychartDiagram-S5SC5T6Z-BpPcNhQe.js} +1 -1
  58. package/dist/client/index.html +2 -2
  59. package/package.json +3 -3
  60. package/dist/client/assets/channel-BsuWTbtj.js +0 -1
  61. package/dist/client/assets/classDiagram-ZZMXUADV-CJ7wz9Pi.js +0 -1
  62. package/dist/client/assets/classDiagram-v2-VYDZK3BY-CJ7wz9Pi.js +0 -1
  63. package/dist/client/assets/index-D1YcCF2h.css +0 -1
  64. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-BqISu6Sp.js +0 -1
  65. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-DSERx6Gl.js +0 -8
@@ -299,14 +299,14 @@ ${n(e.suggestion.proposedCode)}`}return{...e,body:t,lineRange:null,suggestion:nu
299
299
 
300
300
  \`\`\`suggestion
301
301
  ${p.proposedCode}
302
- \`\`\``:p.body;i.rebind(r,d,{...c.location,existingComment:n.getSnapshot().files.flatMap(T=>T.comments).find(T=>T.id===c.location.existingComment?.id),lineRange:null,originalCode:void 0},{...p,body:v,showSuggestion:!1,proposedCode:""})}}}function _H({editor:e}){const{t}=We();return E.jsxs(E.Fragment,{children:[e.draft.stale&&E.jsxs("div",{role:"alert",className:"p-3 space-y-2",children:[E.jsx("p",{children:t("The reviewed content changed. Check this draft against the current diff before continuing.")}),e.canRebind&&E.jsx(Ye,{variant:"outline",onClick:e.rebind,children:t("Use current location")}),e.canMakeFileComment&&E.jsx(Ye,{variant:"outline",onClick:e.makeFileComment,children:t("Keep as file comment")})]}),e.draft.interrupted&&E.jsxs("div",{role:"alert",className:"p-3",children:[E.jsx("p",{children:t("Attachment preparation was interrupted. Attach the image again before saving.")}),E.jsx(Ye,{variant:"ghost",onClick:e.dismissInterrupted,children:t("Dismiss")})]})]})}var AH=oJ,Vt=PQ,zt=w.forwardRef(({asChild:e,children:t,...n},a)=>e&&w.isValidElement(t)?E.jsx(E6,{ref:a,...n,render:t}):E.jsx(E6,{ref:a,...n,children:t}));zt.displayName="TooltipTrigger";var Gt=w.forwardRef(({className:e,side:t,align:n,sideOffset:a=4,alignOffset:i,...r},o)=>{const l=Ys();return E.jsx(XQ,{container:l,children:E.jsx(iJ,{side:t,align:n,sideOffset:a,alignOffset:i,className:"z-50",children:E.jsx(sJ,{ref:o,className:Wt("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[closed]:animate-out data-[closed]:fade-out-0 data-[closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r})})})});Gt.displayName="TooltipContent";function MEe({value:e,onChange:t}){const n=Zx(),a=B$(n);return a.length===0?null:E.jsx("div",{"data-testid":"category-selector",className:"flex items-center gap-1",children:a.map(i=>{const r=e===i.name;return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{type:"button",variant:"ghost",size:"sm","data-testid":`category-option-${i.name}`,"data-hint-action":"select-category",onClick:()=>{r||t(i.name)},className:"h-7 px-2 text-xs gap-1.5",style:r?{backgroundColor:`${i.color}20`,color:i.color,borderColor:`${i.color}40`,borderWidth:"1px"}:void 0,children:[E.jsx("span",{className:"h-2 w-2 rounded-full flex-shrink-0",style:{backgroundColor:i.color}}),i.name]})}),E.jsx(Gt,{side:"bottom",children:i.description})]},i.name)})})}function FEe({popupId:e,isOpen:t,results:n,selectedIndex:a,position:i,onSelect:r,onHover:o}){const{t:l}=We(),c=w.useId(),d=e??`emoji-${c}`,p=n[a],m=t&&n.length>0,h=w.useRef(null);return w.useEffect(()=>{if(!h.current)return;h.current.children[a]?.scrollIntoView?.({block:"nearest"})},[a,m]),E.jsxs(E.Fragment,{children:[E.jsx("span",{id:`${d}-status`,role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:m&&p?l("Emoji suggestion {index} of {count}: {name}. Use Up and Down to choose, Enter or Tab to insert, Escape to close.",{index:a+1,count:n.length,name:p.name}):""}),m&&E.jsx("div",{ref:h,id:d,role:"listbox","aria-label":l("Emoji suggestions"),className:"absolute z-50 w-64 max-h-56 overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md",style:{top:i.top,left:i.left},"data-testid":"emoji-autocomplete",children:n.map((b,y)=>E.jsxs("div",{id:`${d}-option-${y}`,role:"option","aria-label":l("Emoji {name}",{name:b.name}),"aria-selected":y===a,className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-sm ${y===a?"bg-accent text-accent-foreground":""}`,onMouseDown:v=>{v.preventDefault(),r(b)},onMouseEnter:()=>o(y),children:[E.jsx("span",{className:"text-lg leading-none",children:b.native}),E.jsxs("span",{className:"text-muted-foreground truncate",children:[":",b.id,":"]})]},b.id))})]})}function BEe({attachment:e,onRemove:t}){const{t:n}=We(),[a,i]=w.useState(null);return w.useEffect(()=>{if(!e.data)return;const r=URL.createObjectURL(new Blob([e.data]));return i(r),()=>URL.revokeObjectURL(r)},[e.id,e.data]),E.jsxs("div",{className:"relative group",children:[a?E.jsx("img",{src:a,alt:n("Attachment preview"),className:"h-16 w-16 object-cover rounded border"}):E.jsx("div",{className:"h-16 w-16 flex items-center justify-center rounded border bg-muted",children:E.jsx(MP,{className:"h-4 w-4 text-muted-foreground"})}),E.jsx(Ye,{variant:"ghost",size:"icon",className:"absolute -top-2 -end-2 h-5 w-5 rounded-full bg-background border shadow-sm opacity-0 group-hover:opacity-100 focus-visible:opacity-100","aria-label":n("Remove attachment"),onClick:t,children:E.jsx(nk,{className:"h-3 w-3"})})]})}var wd=HU.emojis,CF=HU.aliases,PEe=8;function UEe(e){if(!e)return[];const t=e.toLowerCase(),n=[];for(const a of Object.values(wd)){if(n.length>=PEe)break;(a.id.startsWith(t)||a.name.toLowerCase().includes(t)||a.keywords.some(r=>r.includes(t)))&&n.push({id:a.id,name:a.name,native:a.skins[0].native})}return n}function $Ee(e){if(Object.prototype.hasOwnProperty.call(wd,e))return wd[e].skins[0].native;const t=Object.prototype.hasOwnProperty.call(CF,e)?CF[e]:null;return t&&Object.prototype.hasOwnProperty.call(wd,t)?wd[t].skins[0].native:null}var RF=/:(\w{2,})$/;function HEe(e,t){const n=document.createElement("div"),a=window.getComputedStyle(e),i=["font-family","font-size","font-weight","font-style","letter-spacing","line-height","text-transform","word-spacing","text-indent","white-space","word-wrap","overflow-wrap","padding-top","padding-right","padding-bottom","padding-left","border-top-width","border-right-width","border-bottom-width","border-left-width","box-sizing","width"];for(const d of i)n.style.setProperty(d,a.getPropertyValue(d));n.style.position="absolute",n.style.visibility="hidden",n.style.overflow="hidden",n.style.height="auto",n.style.whiteSpace="pre-wrap";const r=e.value.substring(0,t),o=document.createElement("span");n.textContent=r,o.textContent="​",n.appendChild(o),document.body.appendChild(n);const l=o.getBoundingClientRect(),c=n.getBoundingClientRect();return document.body.removeChild(n),{top:l.top-c.top-e.scrollTop,left:l.left-c.left-e.scrollLeft}}function jEe(e,t,n){const[a,i]=w.useState({isOpen:!1,results:[],selectedIndex:0,position:{top:0,left:0}}),r=`emoji-${w.useId()}`,o=w.useRef(-1),l=w.useRef(!1),c=w.useRef(""),d=w.useRef(null),p=w.useCallback(()=>{o.current=-1,i(y=>y.isOpen?{...y,isOpen:!1,results:[]}:y)},[]);w.useEffect(()=>()=>{d.current!==null&&cancelAnimationFrame(d.current)},[]),w.useEffect(()=>{const y=n.current?.querySelector(".w-md-editor-text-input");if(!y){p();return}const v=()=>{const N=y.selectionStart,x=`${N}:${y.value}`,I=RF.exec(y.value.substring(0,N));if(document.activeElement!==y||l.current||y.selectionEnd!==N||!I||c.current===x){p();return}const O=UEe(I[1]);if(!O.length){p();return}const D=N-I[0].length,M=o.current===D;o.current=D;const B=HEe(y,D),F=y.getBoundingClientRect(),G=n.current.getBoundingClientRect();i(z=>({isOpen:!0,results:O,selectedIndex:M&&z.results.map(W=>W.id).join()===O.map(W=>W.id).join()?z.selectedIndex:0,position:{top:B.top+F.top-G.top+(parseFloat(getComputedStyle(y).lineHeight)||20),left:B.left+F.left-G.left}}))},T=()=>{l.current=!0,p()},S=()=>{l.current=!1,v()},A=["focus","select","keyup","pointerup","scroll","input"];return A.forEach(N=>y.addEventListener(N,v)),y.addEventListener("blur",p),y.addEventListener("compositionstart",T),y.addEventListener("compositionend",S),document.addEventListener("selectionchange",v),v(),()=>{A.forEach(N=>y.removeEventListener(N,v)),y.removeEventListener("blur",p),y.removeEventListener("compositionstart",T),y.removeEventListener("compositionend",S),document.removeEventListener("selectionchange",v)}},[e,n,p]);const m=w.useCallback(y=>{const v=n.current?.querySelector(".w-md-editor-text-input");if(!v||document.activeElement!==v||l.current)return;const T=v.selectionStart,S=RF.exec(v.value.substring(0,T)),A=o.current;if(!S||A<0||T-S[0].length!==A||v.selectionEnd!==T){p();return}const N=v.value.substring(0,A)+y.native+v.value.substring(T);t(N),c.current=`${A+y.native.length}:${N}`,d.current!==null&&cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{d.current=null,v.isConnected&&document.activeElement===v&&v.value===N&&v.setSelectionRange(A+y.native.length,A+y.native.length)}),p()},[t,n,p]),h=w.useCallback(y=>{i(v=>({...v,selectedIndex:Math.max(0,Math.min(y,v.results.length-1))}))},[]),b=w.useCallback(y=>!a.isOpen||l.current||y.nativeEvent.isComposing||y.keyCode===229?!1:y.key==="ArrowDown"?(y.preventDefault(),i(v=>({...v,selectedIndex:(v.selectedIndex+1)%v.results.length})),!0):y.key==="ArrowUp"?(y.preventDefault(),i(v=>({...v,selectedIndex:(v.selectedIndex-1+v.results.length)%v.results.length})),!0):y.key==="Enter"||y.key==="Tab"?(y.preventDefault(),a.results[a.selectedIndex]&&m(a.results[a.selectedIndex]),!0):y.key==="Escape"?(y.preventDefault(),c.current=`${y.currentTarget.selectionStart}:${y.currentTarget.value}`,p(),!0):!1,[a.isOpen,a.results,a.selectedIndex,m,p]);return{isOpen:a.isOpen,results:a.results,selectedIndex:a.selectedIndex,position:a.position,onKeyDown:b,selectEmoji:m,setSelectedIndex:h,popupId:r,textareaProps:{"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":a.isOpen?r:void 0,"aria-activedescendant":a.isOpen?`${r}-option-${a.selectedIndex}`:void 0,"aria-describedby":`${r}-status`}}}var xF=10*1024*1024,zEe=16e6,IF=8192,GEe=64*1024,No=class extends Error{constructor(e){super(e),this.code=e}};function qEe(e){const t=new DataView(e),n=new Uint8Array(e),a=(i,r)=>[...r].every((o,l)=>n[i+l]===o.charCodeAt(0));if(n.length>=24&&n[0]===137&&a(1,`PNG\r
302
+ \`\`\``:p.body;i.rebind(r,d,{...c.location,existingComment:n.getSnapshot().files.flatMap(T=>T.comments).find(T=>T.id===c.location.existingComment?.id),lineRange:null,originalCode:void 0},{...p,body:v,showSuggestion:!1,proposedCode:""})}}}function _H({editor:e}){const{t}=We();return E.jsxs(E.Fragment,{children:[e.draft.stale&&E.jsxs("div",{role:"alert",className:"p-3 space-y-2",children:[E.jsx("p",{children:t("The reviewed content changed. Check this draft against the current diff before continuing.")}),e.canRebind&&E.jsx(Ye,{variant:"outline",onClick:e.rebind,children:t("Use current location")}),e.canMakeFileComment&&E.jsx(Ye,{variant:"outline",onClick:e.makeFileComment,children:t("Keep as file comment")})]}),e.draft.interrupted&&E.jsxs("div",{role:"alert",className:"p-3",children:[E.jsx("p",{children:t("Attachment preparation was interrupted. Attach the image again before saving.")}),E.jsx(Ye,{variant:"ghost",onClick:e.dismissInterrupted,children:t("Dismiss")})]})]})}var AH=oJ,Vt=PQ,zt=w.forwardRef(({asChild:e,children:t,...n},a)=>e&&w.isValidElement(t)?E.jsx(E6,{ref:a,...n,render:t}):E.jsx(E6,{ref:a,...n,children:t}));zt.displayName="TooltipTrigger";var Gt=w.forwardRef(({className:e,side:t,align:n,sideOffset:a=4,alignOffset:i,...r},o)=>{const l=Ys();return E.jsx(XQ,{container:l,children:E.jsx(iJ,{side:t,align:n,sideOffset:a,alignOffset:i,className:"z-50",children:E.jsx(sJ,{ref:o,className:Wt("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[closed]:animate-out data-[closed]:fade-out-0 data-[closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r})})})});Gt.displayName="TooltipContent";function MEe({value:e,onChange:t}){const n=Zx(),a=B$(n);return a.length===0?null:E.jsx("div",{"data-testid":"category-selector",className:"flex items-center gap-1",children:a.map(i=>{const r=e===i.name;return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{type:"button",variant:"ghost",size:"sm","data-testid":`category-option-${i.name}`,"data-hint-action":"select-category",onClick:()=>{r||t(i.name)},className:"h-7 px-2 text-xs gap-1.5",style:r?{backgroundColor:`${i.color}20`,borderColor:i.color,borderWidth:"1px"}:void 0,children:[E.jsx("span",{className:"h-2 w-2 rounded-full flex-shrink-0",style:{backgroundColor:i.color}}),i.name]})}),E.jsx(Gt,{side:"bottom",children:i.description})]},i.name)})})}function FEe({popupId:e,isOpen:t,results:n,selectedIndex:a,position:i,onSelect:r,onHover:o}){const{t:l}=We(),c=w.useId(),d=e??`emoji-${c}`,p=n[a],m=t&&n.length>0,h=w.useRef(null);return w.useEffect(()=>{if(!h.current)return;h.current.children[a]?.scrollIntoView?.({block:"nearest"})},[a,m]),E.jsxs(E.Fragment,{children:[E.jsx("span",{id:`${d}-status`,role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:m&&p?l("Emoji suggestion {index} of {count}: {name}. Use Up and Down to choose, Enter or Tab to insert, Escape to close.",{index:a+1,count:n.length,name:p.name}):""}),m&&E.jsx("div",{ref:h,id:d,role:"listbox","aria-label":l("Emoji suggestions"),className:"absolute z-50 w-64 max-h-56 overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md",style:{top:i.top,left:i.left},"data-testid":"emoji-autocomplete",children:n.map((b,y)=>E.jsxs("div",{id:`${d}-option-${y}`,role:"option","aria-label":l("Emoji {name}",{name:b.name}),"aria-selected":y===a,className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-sm ${y===a?"bg-accent text-accent-foreground":""}`,onMouseDown:v=>{v.preventDefault(),r(b)},onMouseEnter:()=>o(y),children:[E.jsx("span",{className:"text-lg leading-none",children:b.native}),E.jsxs("span",{className:"text-muted-foreground truncate",children:[":",b.id,":"]})]},b.id))})]})}function BEe({attachment:e,onRemove:t}){const{t:n}=We(),[a,i]=w.useState(null);return w.useEffect(()=>{if(!e.data)return;const r=URL.createObjectURL(new Blob([e.data]));return i(r),()=>URL.revokeObjectURL(r)},[e.id,e.data]),E.jsxs("div",{className:"relative group",children:[a?E.jsx("img",{src:a,alt:n("Attachment preview"),className:"h-16 w-16 object-cover rounded border"}):E.jsx("div",{className:"h-16 w-16 flex items-center justify-center rounded border bg-muted",children:E.jsx(MP,{className:"h-4 w-4 text-muted-foreground"})}),E.jsx(Ye,{variant:"ghost",size:"icon",className:"absolute -top-2 -end-2 h-5 w-5 rounded-full bg-background border shadow-sm opacity-0 group-hover:opacity-100 focus-visible:opacity-100","aria-label":n("Remove attachment"),onClick:t,children:E.jsx(nk,{className:"h-3 w-3"})})]})}var wd=HU.emojis,CF=HU.aliases,PEe=8;function UEe(e){if(!e)return[];const t=e.toLowerCase(),n=[];for(const a of Object.values(wd)){if(n.length>=PEe)break;(a.id.startsWith(t)||a.name.toLowerCase().includes(t)||a.keywords.some(r=>r.includes(t)))&&n.push({id:a.id,name:a.name,native:a.skins[0].native})}return n}function $Ee(e){if(Object.prototype.hasOwnProperty.call(wd,e))return wd[e].skins[0].native;const t=Object.prototype.hasOwnProperty.call(CF,e)?CF[e]:null;return t&&Object.prototype.hasOwnProperty.call(wd,t)?wd[t].skins[0].native:null}var RF=/:(\w{2,})$/;function HEe(e,t){const n=document.createElement("div"),a=window.getComputedStyle(e),i=["font-family","font-size","font-weight","font-style","letter-spacing","line-height","text-transform","word-spacing","text-indent","white-space","word-wrap","overflow-wrap","padding-top","padding-right","padding-bottom","padding-left","border-top-width","border-right-width","border-bottom-width","border-left-width","box-sizing","width"];for(const d of i)n.style.setProperty(d,a.getPropertyValue(d));n.style.position="absolute",n.style.visibility="hidden",n.style.overflow="hidden",n.style.height="auto",n.style.whiteSpace="pre-wrap";const r=e.value.substring(0,t),o=document.createElement("span");n.textContent=r,o.textContent="​",n.appendChild(o),document.body.appendChild(n);const l=o.getBoundingClientRect(),c=n.getBoundingClientRect();return document.body.removeChild(n),{top:l.top-c.top-e.scrollTop,left:l.left-c.left-e.scrollLeft}}function jEe(e,t,n){const[a,i]=w.useState({isOpen:!1,results:[],selectedIndex:0,position:{top:0,left:0}}),r=`emoji-${w.useId()}`,o=w.useRef(-1),l=w.useRef(!1),c=w.useRef(""),d=w.useRef(null),p=w.useCallback(()=>{o.current=-1,i(y=>y.isOpen?{...y,isOpen:!1,results:[]}:y)},[]);w.useEffect(()=>()=>{d.current!==null&&cancelAnimationFrame(d.current)},[]),w.useEffect(()=>{const y=n.current?.querySelector(".w-md-editor-text-input");if(!y){p();return}const v=()=>{const N=y.selectionStart,x=`${N}:${y.value}`,I=RF.exec(y.value.substring(0,N));if(document.activeElement!==y||l.current||y.selectionEnd!==N||!I||c.current===x){p();return}const O=UEe(I[1]);if(!O.length){p();return}const D=N-I[0].length,M=o.current===D;o.current=D;const B=HEe(y,D),F=y.getBoundingClientRect(),G=n.current.getBoundingClientRect();i(z=>({isOpen:!0,results:O,selectedIndex:M&&z.results.map(W=>W.id).join()===O.map(W=>W.id).join()?z.selectedIndex:0,position:{top:B.top+F.top-G.top+(parseFloat(getComputedStyle(y).lineHeight)||20),left:B.left+F.left-G.left}}))},T=()=>{l.current=!0,p()},S=()=>{l.current=!1,v()},A=["focus","select","keyup","pointerup","scroll","input"];return A.forEach(N=>y.addEventListener(N,v)),y.addEventListener("blur",p),y.addEventListener("compositionstart",T),y.addEventListener("compositionend",S),document.addEventListener("selectionchange",v),v(),()=>{A.forEach(N=>y.removeEventListener(N,v)),y.removeEventListener("blur",p),y.removeEventListener("compositionstart",T),y.removeEventListener("compositionend",S),document.removeEventListener("selectionchange",v)}},[e,n,p]);const m=w.useCallback(y=>{const v=n.current?.querySelector(".w-md-editor-text-input");if(!v||document.activeElement!==v||l.current)return;const T=v.selectionStart,S=RF.exec(v.value.substring(0,T)),A=o.current;if(!S||A<0||T-S[0].length!==A||v.selectionEnd!==T){p();return}const N=v.value.substring(0,A)+y.native+v.value.substring(T);t(N),c.current=`${A+y.native.length}:${N}`,d.current!==null&&cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{d.current=null,v.isConnected&&document.activeElement===v&&v.value===N&&v.setSelectionRange(A+y.native.length,A+y.native.length)}),p()},[t,n,p]),h=w.useCallback(y=>{i(v=>({...v,selectedIndex:Math.max(0,Math.min(y,v.results.length-1))}))},[]),b=w.useCallback(y=>!a.isOpen||l.current||y.nativeEvent.isComposing||y.keyCode===229?!1:y.key==="ArrowDown"?(y.preventDefault(),i(v=>({...v,selectedIndex:(v.selectedIndex+1)%v.results.length})),!0):y.key==="ArrowUp"?(y.preventDefault(),i(v=>({...v,selectedIndex:(v.selectedIndex-1+v.results.length)%v.results.length})),!0):y.key==="Enter"||y.key==="Tab"?(y.preventDefault(),a.results[a.selectedIndex]&&m(a.results[a.selectedIndex]),!0):y.key==="Escape"?(y.preventDefault(),c.current=`${y.currentTarget.selectionStart}:${y.currentTarget.value}`,p(),!0):!1,[a.isOpen,a.results,a.selectedIndex,m,p]);return{isOpen:a.isOpen,results:a.results,selectedIndex:a.selectedIndex,position:a.position,onKeyDown:b,selectEmoji:m,setSelectedIndex:h,popupId:r,textareaProps:{"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":a.isOpen?r:void 0,"aria-activedescendant":a.isOpen?`${r}-option-${a.selectedIndex}`:void 0,"aria-describedby":`${r}-status`}}}var xF=10*1024*1024,zEe=16e6,IF=8192,GEe=64*1024,No=class extends Error{constructor(e){super(e),this.code=e}};function qEe(e){const t=new DataView(e),n=new Uint8Array(e),a=(i,r)=>[...r].every((o,l)=>n[i+l]===o.charCodeAt(0));if(n.length>=24&&n[0]===137&&a(1,`PNG\r
303
303
  
304
- `))return{width:t.getUint32(16),height:t.getUint32(20)};if(n.length>=10&&(a(0,"GIF87a")||a(0,"GIF89a")))return{width:t.getUint16(6,!0),height:t.getUint16(8,!0)};if(n.length>=26&&a(0,"BM")){const i=t.getUint32(14,!0)===12;return{width:i?t.getUint16(18,!0):Math.abs(t.getInt32(18,!0)),height:i?t.getUint16(20,!0):Math.abs(t.getInt32(22,!0))}}if(n.length>=6&&t.getUint32(0,!0)===65536){const i=t.getUint16(4,!0);if(!i||6+i*16>n.length)throw new No("format");let r=0,o=0;for(let l=6;l<6+i*16;l+=16)r=Math.max(r,n[l]||256),o=Math.max(o,n[l+1]||256);return{width:r,height:o}}if(n.length>=30&&a(0,"RIFF")&&a(8,"WEBP")){if(a(12,"VP8X"))return{width:1+n[24]+(n[25]<<8)+(n[26]<<16),height:1+n[27]+(n[28]<<8)+(n[29]<<16)};if(a(12,"VP8L")&&n[20]===47)return{width:1+n[21]+((n[22]&63)<<8),height:1+(n[22]>>6)+(n[23]<<2)+((n[24]&15)<<10)};if(a(12,"VP8 ")&&n[23]===157&&n[24]===1&&n[25]===42)return{width:t.getUint16(26,!0)&16383,height:t.getUint16(28,!0)&16383}}if(n[0]===255&&n[1]===216){let i=2;for(;i+4<=n.length&&n[i++]===255;){for(;n[i]===255;)i++;const r=n[i++];if(r===217||r===218||i+2>n.length)break;if(r===1||r>=208&&r<=216)continue;const o=t.getUint16(i);if(o<2||i+o>n.length)break;if(r>=192&&r<=207&&![196,200,204].includes(r)&&o>=7)return{width:t.getUint16(i+5),height:t.getUint16(i+3)};i+=o}}throw new No("format")}function OF(e,t){if(e<=0||t<=0||e>IF||t>IF||e*t>zEe)throw new No("dimensions")}async function VEe(e,t,n=1920){if(t?.throwIfAborted(),e.size>xF)throw new No("size");const a=qEe(await e.slice(0,GEe).arrayBuffer());OF(a.width,a.height),t?.throwIfAborted();const i=await createImageBitmap(e);try{if(t?.throwIfAborted(),OF(i.width,i.height),i.width<=n&&i.height<=n)return e;const r=Math.min(n/i.width,n/i.height),o=document.createElement("canvas");o.width=Math.round(i.width*r),o.height=Math.round(i.height*r);const l=o.getContext("2d");if(!l)throw new No("decode");l.drawImage(i,0,0,o.width,o.height);const c=await new Promise(d=>o.toBlob(d,e.type));if(t?.throwIfAborted(),!c||c.size>xF)throw new No("decode");return c}finally{i.close()}}async function YEe(e,t){const n=await VEe(e,t),a=await n.arrayBuffer();t?.throwIfAborted();const i=n.type||e.type||"image/png",r=i.split("/")[1]||"png";return{id:crypto.randomUUID(),fileName:`image.${r}`,mediaType:i,data:a}}var WEe=8,KEe=30*1024*1024;function iI({process:e=YEe,...t}){const n=uc(),a=nI(),i=w.useRef({...t,isCurrent:a?.isCurrentSession});i.current={...t,isCurrent:a?.isCurrentSession};const r=w.useMemo(()=>({controller:new AbortController,jobs:[],running:!1,nextId:0,delivered:[],activeJob:null}),[n,t.owner,t.signal,e]),o=w.useRef(r);o.current=r;const[l,c]=w.useState([]),[d,p]=w.useState(!1);w.useLayoutEffect(()=>{t.attachments&&(r.delivered=[])},[t.attachments,r]);const m=()=>o.current===r&&!r.controller.signal.aborted&&!t.signal?.aborted&&(i.current.isCurrent?.()??!0),h=()=>{m()&&(c([...r.jobs]),i.current.onWorkChange?.(r.jobs.length>0),i.current.onProcessingChange?.(r.jobs.some(S=>S.status!=="error")))};w.useLayoutEffect(()=>{r.controller.signal.aborted&&(r.controller=new AbortController),o.current=r,c([]),p(!1);const S=i.current;return()=>{r.jobs.length>0&&S.onAbort?.(),r.controller.abort(),r.jobs=[],r.running=!1,o.current===r&&(o.current=null),S.onProcessingChange?.(!1),S.onWorkChange?.(!1)}},[r]);const b=async()=>{if(r.running||!m())return;r.running=!0;const S=r.controller,A=()=>m()&&S===r.controller;try{let N;for(;A()&&(N=r.jobs.find(x=>x.status==="queued"));){const x=N.id;r.jobs=r.jobs.map(O=>O.id===x?{...O,status:"processing"}:O),h();const I=new AbortController;r.activeJob={id:x,controller:I};try{const O=await e(N.file,AbortSignal.any([S.signal,I.signal,...t.signal?[t.signal]:[]]));if(!A())return;if(!r.jobs.some(D=>D.id===x))continue;r.jobs=r.jobs.filter(D=>D.id!==x),r.delivered.push(O),i.current.onAttach([O])}catch(O){if(!A())return;r.jobs=r.jobs.map(D=>D.id===x?{...D,status:"error",error:O instanceof No?O.code:"decode"}:D)}finally{r.activeJob?.id===x&&(r.activeJob=null)}h()}}finally{S===r.controller&&(r.running=!1)}};return{enqueue:S=>{if(!m()||!S.length)return;const A=i.current.attachments??[],N=[...A,...r.delivered.filter(I=>!A.some(O=>O.id===I.id))],x=N.reduce((I,O)=>I+(O.data?.byteLength??0),0)+r.jobs.reduce((I,O)=>I+O.file.size,0)+S.reduce((I,O)=>I+O.size,0);if(N.length+r.jobs.length+S.length>WEe||x>KEe){p(!0);return}p(!1),r.jobs.push(...S.map(I=>({file:I,id:++r.nextId,status:"queued"}))),h(),b()},retry:S=>{m()&&(r.jobs=r.jobs.map(A=>A.id===S&&A.status==="error"?{...A,status:"queued",error:void 0}:A),h(),b())},dismiss:S=>{r.jobs=r.jobs.filter(A=>A.id!==S),r.activeJob?.id===S&&r.activeJob.controller.abort(),h()},jobs:l,selectionError:d,pending:l.some(S=>S.status!=="error")}}var NH=w.createContext(null),CH=()=>w.useContext(NH);function rI({ingestion:e}){const{t}=We(),n={size:"Image exceeds the 10 MiB file limit.",dimensions:"Image exceeds the 16 megapixel or 8192 pixel dimension limit.",format:"Use PNG, JPEG, GIF, WebP, BMP or ICO with a readable raster header.",decode:"Image could not be decoded."};return E.jsxs("div",{className:"px-3 text-xs",children:[e.selectionError&&E.jsx("p",{role:"alert",children:t("Choose at most {count} images totaling at most {size} MiB.",{count:8,size:30})}),e.jobs.map(a=>E.jsxs("div",{className:"flex items-center gap-2 py-1",children:[E.jsx("span",{role:a.status==="error"?"alert":"status",children:a.status==="error"?t("Attachment failed: {name}. {detail}",{name:"name"in a.file?a.file.name:t("Pasted image"),detail:t(n[a.error??"decode"])}):t("Preparing attachment: {name}",{name:"name"in a.file?a.file.name:t("Pasted image")})}),a.status==="error"&&E.jsx(Ye,{size:"sm",variant:"outline",onClick:()=>e.retry(a.id),children:t("Retry")}),E.jsx(Ye,{size:"sm",variant:"ghost",onClick:()=>e.dismiss(a.id),children:t("Dismiss")})]},a.id))]})}function XEe({onAttach:e,children:t,isDragging:n,onDragChange:a}){const{t:i}=We(),r=w.useRef(0),o=CH(),l=iI({onAttach:e}),d=(o??l).enqueue,p=w.useCallback(y=>{const T=Array.from(y.clipboardData.items).filter(A=>A.type.startsWith("image/"));if(T.length===0)return;y.preventDefault();const S=T.map(A=>A.getAsFile()).filter(A=>A!==null);S.length>0&&d(S)},[d]),m=w.useCallback(y=>{y.preventDefault(),r.current=0,a(!1);const v=Array.from(y.dataTransfer.files).filter(T=>T.type.startsWith("image/"));v.length!==0&&d(v)},[d,a]),h=w.useCallback(y=>{y.preventDefault(),r.current++,y.dataTransfer.types.includes("Files")&&a(!0)},[a]),b=w.useCallback(y=>{y.preventDefault(),r.current--,r.current===0&&a(!1)},[a]);return E.jsxs("div",{onPaste:p,onDrop:m,onDragOver:y=>y.preventDefault(),onDragEnter:h,onDragLeave:b,children:[n&&E.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-primary/10 backdrop-blur-[1px] rounded-lg pointer-events-none",children:E.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-primary",children:[E.jsx(MP,{className:"h-5 w-5"}),i("Drop image to attach")]})}),t,!o&&E.jsx(rI,{ingestion:l})]})}var ZEe=[[xU,"Add bold text (ctrl + b)"],[DU,"Add italic text (ctrl + i)"],[El],[PU,"Insert a quote (ctrl + q)"],[OU,"Insert code (ctrl + j)"],[LU,"Add a link (ctrl + l)"],[El],[MU,"Add unordered list (ctrl + shift + u)"],[FU,"Add ordered list (ctrl + shift + o)"],[BU,"Add checked list (ctrl + shift + c)"]];function RH({body:e,attachmentOwner:t,attachmentSignal:n,onAttachmentsAborted:a,onAttachmentWorkChange:i,onProcessingChange:r,onBodyChange:o,attachments:l,setAttachments:c,placeholder:d,headerLabel:p,onSubmit:m,testId:h,actionsRef:b,height:y=240,children:v}){const{t:T}=We(),S=w.useMemo(()=>ZEe.map(([B,F])=>({...B,buttonProps:F?{...B.buttonProps,"aria-label":T(F),title:T(F)}:B.buttonProps,icon:B.icon?Bt.cloneElement(B.icon,{"aria-hidden":!0,focusable:!1}):void 0})),[T]),A=W$(),N=w.useRef(null),[x,I]=w.useState(!1),O=jEe(e,o,N),D=w.useCallback(B=>{c(F=>[...F,...B])},[c]),M=iI({onAttach:D,attachments:l,owner:t,signal:n,onAbort:a,onWorkChange:i,onProcessingChange:r});return w.useEffect(()=>{N.current?.querySelector(".w-md-editor-text-input")?.focus()},[]),E.jsx(NH.Provider,{value:M,children:E.jsxs("div",{className:`rounded-lg border bg-card shadow-sm overflow-hidden relative ${x?"border-primary border-2":"border-foreground/15"}`,"data-testid":h,children:[E.jsx(XEe,{onAttach:D,isDragging:x,onDragChange:I,children:E.jsxs("div",{className:"p-1 relative","data-color-mode":A,ref:N,children:[E.jsx($U,{value:e,onChange:B=>o(B||""),preview:"edit",highlightEnable:!1,commands:S,extraCommands:p?[{name:"header-label",keyCommand:"header-label",render:()=>E.jsx(E.Fragment,{children:p})}]:[],textareaProps:{...O.textareaProps,placeholder:d,"aria-label":d,onKeyDown:B=>{if(!(B.nativeEvent.isComposing||B.keyCode===229)&&!O.onKeyDown(B)&&((B.ctrlKey||B.metaKey)&&B.key==="Enter"&&(B.preventDefault(),M.pending||m()),B.key==="Escape")){B.preventDefault();const F=b?.current;F?F.focus():B.target.blur()}},onPaste:void 0},height:y,className:"md-editor-comment"}),E.jsx(FEe,{popupId:O.popupId,isOpen:O.isOpen,results:O.results,selectedIndex:O.selectedIndex,position:O.position,onSelect:O.selectEmoji,onHover:O.setSelectedIndex})]})}),l.length>0&&E.jsxs("div",{className:"flex gap-2 flex-wrap px-3 py-2 border-t border-border/50",children:[l.map(B=>E.jsx(BEe,{attachment:B,onRemove:()=>c(F=>F.filter(G=>G.id!==B.id))},B.id)),E.jsx("span",{className:"self-center text-[11px] text-muted-foreground",children:T("images",{count:l.length})})]}),E.jsx(rI,{ingestion:M}),v]})})}function xH({setAttachments:e}){const{t}=We(),n=w.useRef(null),a=CH(),i=iI({onAttach:o=>e(l=>[...l,...o])}),r=a??i;return E.jsxs(E.Fragment,{children:[E.jsxs(Ye,{type:"button",variant:"ghost",size:"sm",onClick:()=>n.current?.click(),className:"h-7 gap-1.5 text-xs",children:[E.jsx(pK,{className:"h-3.5 w-3.5"}),t("Attach")]}),!a&&E.jsx(rI,{ingestion:i}),E.jsx("input",{ref:n,type:"file","aria-label":t("Attach"),hidden:!0,accept:"image/*",multiple:!0,className:"hidden",onChange:o=>{const l=Array.from(o.target.files||[]);l.length>0&&r.enqueue(l),o.target.value=""}})]})}var jv=w.forwardRef(({className:e,...t},n)=>E.jsx("textarea",{className:Wt("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));jv.displayName="Textarea";function QEe({originalCode:e,proposedCode:t,onProposedChange:n,onSubmit:a}){const{t:i}=We(),r=w.useId();return E.jsxs(E.Fragment,{children:[E.jsx(ha,{}),E.jsxs("div",{className:"p-3 space-y-2 bg-muted/20",children:[E.jsxs("div",{"data-testid":"suggestion-original",children:[E.jsx("label",{htmlFor:`${r}-original`,className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-1 block",children:i("Original")}),E.jsx(jv,{id:`${r}-original`,value:e,disabled:!0,className:"font-mono text-xs bg-muted/30 resize-none",rows:3})]}),E.jsxs("div",{"data-testid":"suggestion-proposed",children:[E.jsx("label",{htmlFor:`${r}-proposed`,className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-1 block",children:i("Suggested")}),E.jsx(jv,{id:`${r}-proposed`,value:t,onChange:o=>n(o.target.value),onKeyDown:o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&(o.preventDefault(),a())},placeholder:i("Enter your suggested code..."),className:"font-mono text-xs resize-y",rows:3})]})]})]})}function rp({filePath:e,lineRange:t,onCancel:n,onSubmit:a,existingComment:i,originalCode:r}){const{t:o}=We(),{addComment:l,editComment:c}=Ws(),p=Zx()?.find(F$)?.name??"",m=SH({filePath:e,lineRange:t,existingComment:i,originalCode:r},{body:i?.body??"",category:i?.category||p,showSuggestion:!!i?.suggestion,proposedCode:i?.suggestion?.proposedCode??"",attachments:i?.attachments??[]}),{content:{body:h,category:b,showSuggestion:y,proposedCode:v,attachments:T},setBody:S,setCategory:A,setShowSuggestion:N,setProposedCode:x,setAttachments:I}=m,O=m.draft.target??m.draft.location,D=O.originalCode,M=w.useRef(null),F=(h.trim().length>0||y&&!!D||T.length>0)&&b.length>0,G=()=>{if(!F||!m.current()||m.draft.pending||m.draft.interrupted)return;const W=y&&D?{originalCode:D,proposedCode:v}:null;O.existingComment?c(O.existingComment.id,{...m.draft.target?{lineRange:O.lineRange}:{},body:h,category:b,suggestion:W,attachments:T.length?T:void 0}):l(O.filePath,O.lineRange,h,b,W,T.length?T:void 0),m.clear(),a?.()},z=()=>{m.clear(),n()};return E.jsxs(RH,{attachmentOwner:m.draft.key,attachmentSignal:m.draft.controller.signal,onAttachmentsAborted:m.onAttachmentsAborted,onAttachmentWorkChange:m.onProcessingChange,body:h,onBodyChange:S,attachments:T,setAttachments:I,placeholder:o("Add your review comment... (paste or drop images here)"),headerLabel:O.lineRange?E.jsx("span",{className:"text-xs font-medium text-muted-foreground whitespace-nowrap",children:O.lineRange.start===O.lineRange.end?o("Comment on line {line}",{line:O.lineRange.start}):o("Comment on lines {start} to {end}",{start:O.lineRange.start,end:O.lineRange.end})}):void 0,onSubmit:G,testId:"comment-input",actionsRef:M,children:[E.jsx(_H,{editor:m}),y&&D&&E.jsx(QEe,{originalCode:D,proposedCode:v,onProposedChange:x,onSubmit:G}),E.jsx(ha,{}),E.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/10 outline-none","data-testid":"comment-actions",tabIndex:-1,ref:M,children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx(MEe,{value:b,onChange:A}),D&&E.jsxs(Ye,{type:"button",variant:y?"secondary":"ghost",size:"sm","data-testid":"add-suggestion-btn",onClick:()=>{!y&&v.length===0&&x(D),N(!y)},className:"h-7 gap-1.5 text-xs",children:[E.jsx(_W,{className:"h-3.5 w-3.5"}),o(y?"Remove suggestion":"Suggest")]}),E.jsx(xH,{setAttachments:I})]}),E.jsxs("div",{className:"flex items-center gap-1.5",children:[E.jsx("span",{className:"text-[10px] text-muted-foreground/50 me-0.5",children:o("Esc to unfocus")}),E.jsx(Ye,{"data-testid":"cancel-comment-btn","data-hint-action":"cancel-comment",variant:"ghost",size:"sm",onClick:z,className:"h-7 text-xs",children:o("Cancel")}),E.jsxs(Ye,{"data-testid":"add-comment-btn","data-hint-action":"submit-comment",size:"sm",onClick:G,disabled:!F||m.draft.pending||m.draft.stale||m.draft.interrupted,className:"h-7 text-xs gap-1.5",children:[o(O.existingComment?"Update":"Comment"),E.jsxs("kbd",{className:"pointer-events-none inline-flex items-center rounded border border-current/20 px-1 font-mono text-[10px] font-medium opacity-60",children:[navigator.platform?.includes("Mac")?"⌘":"Ctrl","↵"]})]})]})]})]},m.draft.key)}var JEe=160;function sI({commentId:e,existingReply:t,onCancel:n,onSubmit:a}){const{t:i}=We(),{addReply:r,updateReply:o}=Ws(),l=SH({filePath:"",lineRange:null,commentId:e,existingReply:t},{body:t?.body??"",category:"",showSuggestion:!1,proposedCode:"",attachments:t?.attachments??[]}),{content:{body:c,attachments:d},setBody:p,setAttachments:m}=l,h=w.useRef(null),b=c.trim().length>0||d.length>0,y=()=>{!b||!l.current()||l.draft.pending||l.draft.interrupted||(t?o(e,t.id,{body:c,attachments:d.length?d:void 0}):r(e,c,void 0,d.length?d:void 0),l.clear(),a?.())},v=()=>{l.clear(),n()};return E.jsxs(RH,{attachmentOwner:l.draft.key,attachmentSignal:l.draft.controller.signal,onAttachmentsAborted:l.onAttachmentsAborted,onAttachmentWorkChange:l.onProcessingChange,body:c,onBodyChange:p,attachments:d,setAttachments:m,placeholder:i("Reply to this comment... (paste or drop images here)"),onSubmit:y,testId:"reply-input",actionsRef:h,height:JEe,children:[E.jsx(_H,{editor:l}),E.jsx(ha,{}),E.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/10 outline-none","data-testid":"reply-actions",tabIndex:-1,ref:h,children:[E.jsx("div",{className:"flex items-center gap-2",children:E.jsx(xH,{setAttachments:m})}),E.jsxs("div",{className:"flex items-center gap-1.5",children:[E.jsx("span",{className:"text-[10px] text-muted-foreground/50 me-0.5",children:i("Esc to unfocus")}),E.jsx(Ye,{"data-testid":"cancel-reply-btn",variant:"ghost",size:"sm",onClick:v,className:"h-7 text-xs",children:i("Cancel")}),E.jsxs(Ye,{"data-testid":"add-reply-btn",size:"sm",onClick:y,disabled:!b||l.draft.pending||l.draft.stale||l.draft.interrupted,className:"h-7 text-xs gap-1.5",children:[i(t?"Update":"Reply"),E.jsxs("kbd",{className:"pointer-events-none inline-flex items-center rounded border border-current/20 px-1 font-mono text-[10px] font-medium opacity-60",children:[navigator.platform?.includes("Mac")?"⌘":"Ctrl","↵"]})]})]})]})]},l.draft.key)}function eye(){const t=w.useContext(Ba).drafts,n=w.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot),[a,i]=w.useState(null),{t:r}=We(),o=n.filter(nH);return o.length?E.jsx("section",{"aria-label":r("Unfinished drafts"),className:"fixed bottom-2 end-2 z-40 max-h-[30vh] max-w-lg overflow-auto rounded-lg border border-border bg-background p-2 space-y-2 shadow-lg",children:o.map(l=>E.jsxs("div",{children:[E.jsx("span",{children:r("Unfinished draft: {path}",{path:l.location.filePath||r("Reply")})})," ",!t.isMounted(l.key)&&E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>i(l.key),children:r("Continue draft")})," ",E.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>t.clear(l.key,l.token),children:r("Cancel draft")}),a===l.key&&E.jsx(CEe,{open:!0,onOpenChange:c=>{c||i(null)},children:E.jsxs(bH,{children:[E.jsxs(EH,{children:[E.jsx(yH,{children:r("Continue draft")}),E.jsx(vH,{children:r("Finish or cancel unfinished drafts before saving the review.")})]}),l.location.commentId?E.jsx(sI,{...l.location,commentId:l.location.commentId,onCancel:()=>i(null),onSubmit:()=>i(null)}):E.jsx(rp,{...l.location,onCancel:()=>i(null),onSubmit:()=>i(null)}),E.jsx(kH,{children:r("Close")})]})})]},l.key))}):null}function tye(){return E.jsxs(E.Fragment,{children:[E.jsx(NEe,{}),E.jsx(eye,{})]})}function nye(){let e=null;return{register(t){return e=t,()=>{e===t&&(e=null)}},expand:()=>e?.()}}var IH=w.createContext(null);function aye({children:e}){const[t]=w.useState(nye);return E.jsx(IH.Provider,{value:t,children:e})}var OH=()=>w.useContext(IH),DF=new WeakMap,iye=1;function rye(e){if(!e)return 0;let t=DF.get(e);return t===void 0&&(t=iye++,DF.set(e,t)),t}function DH(e){const t=_i(),n=[rye(t),e.initialFiles?"static":"adapter",e.initialSource?Bo(e.initialSource):""].join("|");return E.jsx(SEe,{initialCharacterShortcuts:e.initialCharacterShortcuts,children:E.jsx(sye,{...e,recovery:e.recovery===void 0?E.jsx(tye,{}):e.recovery,adapter:t})},n)}function sye({children:e,initialFiles:t,initialSource:n,initialComments:a,recovery:i,adapter:r}){const[o]=w.useState(()=>eEe(rH(J1e(t,n,Hv(r)),{type:"hydrate",comments:a})));w.useLayoutEffect(()=>()=>o.drafts.abortPending(),[o]);const l=pEe(o,r,t!==void 0,a,{files:t,source:n}),c=w.useSyncExternalStore(o.subscribe,()=>o.getSnapshot().snapshotId,()=>o.getSnapshot().snapshotId),{createId:d}=Kb(),p=w.useMemo(()=>y=>o.dispatch({type:"files",update:y}),[o]),m=w.useMemo(()=>mEe(p,d),[p,d]),h=w.useMemo(()=>hEe(o,l.controller,m),[o,l.controller,m,c]),b=w.useMemo(fH,[c]);return E.jsx(Ba.Provider,{value:o,children:E.jsx(Jx.Provider,{value:h,children:E.jsx(pH.Provider,{value:b,children:E.jsx(oye,{store:o,commands:h,recovery:i,retryLoad:l.retryLoad,retryResume:l.retryResume,children:E.jsx(aye,{children:e})})})})})}function oye({store:e,commands:t,retryLoad:n,retryResume:a,recovery:i,children:r}){const o=w.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot),{config:l}=Xx(),c=w.useContext(Qx);w.useLayoutEffect(()=>{o.identity&&!rr(o.diffSource)&&c?.(o.identity)},[c,o.identity,o.diffSource]);const d=w.useMemo(()=>l.showUntracked?o.allDiffFiles:o.allDiffFiles.filter(b=>!b.isUntracked),[o.allDiffFiles,l.showUntracked]),p=w.useMemo(()=>gEe(o.files),[o.files]),m=bEe(e,o,d,t,p,n,a),h=w.useMemo(()=>({loadError:o.loadError,resumeError:o.resumeError,retryLoad:n,retryResume:a}),[o.loadError,o.resumeError,n,a]);return E.jsx(Wb.Provider,{value:m,children:E.jsx(dH.Provider,{value:h,children:E.jsxs(yEe,{sessionId:o.sessionId,files:d,isLargePayload:o.isLargePayload,reviewFiles:o.files,children:[i,r]})})})}function Zb(){const e=w.useContext(Wb);if(!e)throw new Error("useReview must be used within ReviewProvider");return e}function kl(e){const t=w.useContext(Ba);if(!t)throw new Error("Session selection must be used within ReviewProvider");return w.useSyncExternalStore(t.subscribe,()=>e(t.getSnapshot()),()=>e(t.getSnapshot()))}function Qb(e){const t=w.useContext(Ba);if(!t)throw new Error("Session selection must be used within ReviewProvider");return w.useSyncExternalStore(t.subscribe,()=>e(t),()=>e(t))}function oI(e){return Qb(t=>t.getFile(e))}function uye(e){return Qb(t=>t.getDiffFile(e))}function lye(){return Qb(e=>e.getNavigation())}function cye(){return Qb(e=>e.getProgress())}function LH(){return kl(e=>e.diffSource)}function Jb(){return kl(e=>e.sessionId)}function uI(){return kl(e=>e.snapshotId)}function lc(){const e=kl(a=>a.allDiffFiles),{config:t}=Xx();return{diffFiles:w.useMemo(()=>t.showUntracked?e:e.filter(a=>!a.isUntracked),[e,t.showUntracked]),diffSource:LH(),diagnostics:kl(a=>a.diagnostics),isLargePayload:kl(a=>a.isLargePayload),sessionId:Jb()}}function dye(){const e=w.useContext(Ba);if(!e)throw new Error("Save transactions require ReviewProvider");const{now:t}=Kb(),{t:n}=We(),a=w.useRef(t);a.current=t;const i=w.useRef(!0);return w.useLayoutEffect(()=>(i.current=!0,()=>{i.current=!1}),[]),w.useMemo(()=>({begin(){const r=e.getSnapshot();if(e.drafts.hasWork())throw new X1e(n("Finish or cancel unfinished drafts before saving the review."));if(!i.current||rr(r.diffSource)||r.loadError!==null||r.resumeError!==null||r.resumePending)throw new Error("The current review has not finished loading.");const o=a.current().toISOString(),l=e.lockMutations();return{state:{timestamp:o,source:r.diffSource,files:r.files},current:()=>i.current&&e.ownsMutations(l)&&e.getSnapshot().sessionId===r.sessionId&&e.getSnapshot().snapshotId===r.snapshotId,unlock:()=>{e.unlockMutations(l)}}}}),[e,n])}function MH(e,t){return Array.from(e?.querySelectorAll(t)??[]).filter(n=>n.closest(".self-review")===e)}function yf(e,t){return MH(e,t)[0]??null}var lI=w.createContext(null);function cI(){const e=w.useContext(lI);if(!e)throw new Error("useDiffNavigationContext must be used within a DiffNavigationProvider");return e}function dI(){return w.useContext(lI)}function FH({children:e}){const[t,n]=w.useState(null),a=Ys(),i=w.useRef(new Map),r=w.useRef(new Map),o=w.useRef(null),l=w.useCallback(()=>{let b=null,y=0;i.current.forEach((v,T)=>{v.forEach(S=>{const A=r.current.get(S)??0;A>y&&(y=A,b=T)})}),n(b)},[]),c=w.useCallback((b,y)=>{let v=i.current.get(b);v||(v=new Set,i.current.set(b,v)),v.add(y),o.current?.observe(y)},[]),d=w.useCallback((b,y)=>{o.current?.unobserve(y),r.current.delete(y);const v=i.current.get(b);v?.delete(y),v?.size===0&&i.current.delete(b),l()},[l]),p=w.useCallback(b=>i.current.get(b)?.values().next().value??null,[]),m=w.useCallback(b=>{const y=typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;p(b)?.scrollIntoView({behavior:y?"instant":"smooth",block:"start"})},[p]);w.useEffect(()=>{const b=new IntersectionObserver(y=>{if(o.current!==b)return;const v=new Set(Array.from(i.current.values()).flatMap(T=>Array.from(T)));y.forEach(T=>{v.has(T.target)&&r.current.set(T.target,T.isIntersecting?T.intersectionRatio:0)}),l()},{root:yf(a,'[data-scroll-container="diff"]'),threshold:[0,.25,.5,.75,1],rootMargin:"-20% 0px -20% 0px"});return o.current=b,r.current.clear(),i.current.forEach(y=>y.forEach(v=>b.observe(v))),()=>{b.disconnect(),o.current===b&&(o.current=null),r.current.clear()}},[a,l]);const h=w.useMemo(()=>({activeFilePath:t,scrollToFile:m,registerFileElement:c,unregisterFileElement:d,getFileElement:p}),[t,m,c,d,p]);return E.jsx(lI.Provider,{value:h,children:e})}var fye=8e3,pye=120,mye=800,LF=12,gye=256,hye=64;function BH(e){if(e.length>fye)return!0;let t="",n=0,a=0,i="";for(let d=0;d<e.length;d++){const p=e[d];if(t){if(++a>512)return!0;if(p==="\\"){d++,i+=" ";continue}p===t&&(t=""),i+=" "}else if(p==='"'||p==="'"||p==="`")t=p,a=0,i+=" ";else{if("([{".includes(p)){if(++n>LF)return!0}else")]}".includes(p)&&(n=Math.max(0,n-1));i+=p}}const r=i.split(/[;\n\r]/).filter(d=>d.trim());if(r.length>pye)return!0;let o=0,l=0,c=0;for(const d of r){if(d.length>512||(/^\s*(subgraph|loop|alt|opt|par|critical|break|rect|box)\b/.test(d)?c++:/^\s*end\b/.test(d)&&(c=Math.max(0,c-1)),c>LF))return!0;const p=d.match(/[\p{L}\p{N}_]+|[^\s]/gu)??[];if(o+=p.length,/[<>]|--|\.\.|==/.test(d)){const m=d.match(/[\p{L}\p{N}_]+/gu)?.length??0;l+=Math.max(1,m*m)}if(o>mye||l>gye)return!0}return!1}var dh=5e4,MF=1e4,bye=["secure","securityLevel","startOnLoad","maxTextSize","maxEdges","suppressErrorRendering","themeCSS","fontFamily","altFontFamily","htmlLabels","dompurifyConfig"],Eye=8,wl=class extends Error{constructor(e){super(e),this.kind=e}};function yye(e){let t=Promise.resolve(),n=0;return{render(a){if(a.source.length>dh||BH(a.source))return Promise.reject(new wl("source"));if(a.signal.aborted)return Promise.reject(a.signal.reason);if(n>=Eye)return Promise.reject(new wl("busy"));n++;const i=t.then(()=>(a.signal.throwIfAborted(),e(a))).finally(()=>{n--});return t=i.catch(()=>{}),i}}}var vye=0;async function kye({source:e,theme:t,signal:n}){const a=t==="dark";n.throwIfAborted();const i=(await nq(async()=>{const{default:l}=await import("./mermaid.core-DGOIMnVG.js").then(c=>c.cb);return{default:l}},[],import.meta.url)).default;n.throwIfAborted(),i.initialize({startOnLoad:!1,securityLevel:"strict",secure:[...bye],theme:a?"dark":"default",htmlLabels:!1,maxTextSize:dh,maxEdges:hye,suppressErrorRendering:!0});const r=document.createElement("div");r.setAttribute("data-mermaid-sandbox",""),r.setAttribute("aria-hidden","true"),r.style.cssText="position:fixed;top:0;left:-100000px;width:1024px;height:1px;overflow:hidden;visibility:hidden;pointer-events:none;",document.body.appendChild(r);const o=()=>r.remove();n.addEventListener("abort",o,{once:!0});try{const{svg:l}=await i.render(`mermaid-${vye++}`,e,r);return n.throwIfAborted(),{svg:l}}finally{n.removeEventListener("abort",o),r.remove()}}var wye=yye(kye),PH=w.createContext(void 0),UH=w.createContext(wye);function Tye({previewRenderer:e,diagramRenderer:t,children:n}){const a=fI(),i=$H();return E.jsx(PH.Provider,{value:e??a,children:E.jsx(UH.Provider,{value:t??i,children:n})})}function fI(){return w.useContext(PH)}function $H(){return w.useContext(UH)}function Sye({adapter:e,config:t,initialConfig:n,initialOutputPath:a,children:i,previewRenderer:r,diagramRenderer:o,services:l,...c}){return E.jsx(M$,{adapter:e,children:E.jsx(sEe,{services:l,children:E.jsx(Z$,{initialConfig:n??t,initialOutputPath:a,children:E.jsx(j1e,{children:E.jsx(DH,{...c,children:E.jsx(FH,{children:E.jsx(Tye,{previewRenderer:r,diagramRenderer:o,children:E.jsx(AH,{children:i})})})})})})})})}function HH(e,t){const n=new Map,a=new Map;for(const r of e){const o=JSON.stringify([r.oldPath,r.newPath,r.changeType]),l=n.get(o)??0;n.set(o,l+1);const c=a.get(r)??[];c.push(`${o}:${l}`),a.set(r,c)}const i=new Map;return t.map(r=>({...r,entries:r.entries.map(o=>{const l=i.get(o.file)??0;return i.set(o.file,l+1),{...o,key:a.get(o.file)[l]}})}))}function FF(e){return e.newPath||e.oldPath}function jH(e,t,n){if(n==="flat"||!t||t.length===0)return e.length===0?[]:[{entries:e.map(l=>({file:l}))}];const a=new Map;e.forEach(l=>{const c=FF(l),d=a.get(c)??[];d.push(l),a.set(c,d)});const i=new Set,r=[];t.forEach((l,c)=>{const d=[];for(const p of l.files){const m=a.get(p.path);!m||i.has(p.path)||(i.add(p.path),m.forEach(h=>d.push({file:h,description:p.description})))}d.length!==0&&r.push({header:{name:l.name,rationale:l.rationale,implicit:l.implicit,groupIndex:c},entries:d})});const o=e.filter(l=>!i.has(FF(l))).map(l=>({file:l}));if(o.length>0){const l=r[r.length-1];l?.header?.implicit?l.entries.push(...o):r.push({header:{name:"Everything else",implicit:!0},entries:o})}return r}var zH=w.forwardRef(({className:e,type:t,...n},a)=>E.jsx("input",{type:t,className:Wt("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),ref:a,...n}));zH.displayName="Input";function _ye(e){return e?e.type==="addition"?"bg-emerald-50/70 dark:bg-emerald-900/40":e.type==="deletion"?"bg-red-50/70 dark:bg-red-900/40":"":""}function Aye(e){return e?e.type==="addition"?"bg-emerald-100/80 dark:bg-emerald-900/50":e.type==="deletion"?"bg-red-100/80 dark:bg-red-900/50":"bg-muted/30":"bg-muted/30"}function GH(e){let t=0,n=0;for(const a of e.hunks)for(const i of a.lines)i.type==="addition"&&t++,i.type==="deletion"&&n++;return{additions:t,deletions:n}}function zv(e){switch(e){case"added":return{label:"A",className:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400"};case"modified":return{label:"M",className:"bg-amber-500/15 text-amber-700 dark:text-amber-400"};case"deleted":return{label:"D",className:"bg-red-500/15 text-red-700 dark:text-red-400"};case"renamed":return{label:"R",className:"bg-blue-500/15 text-blue-700 dark:text-blue-400"};case"copied":return{label:"C",className:"bg-violet-500/15 text-violet-700 dark:text-violet-400"};default:return{label:"?",className:""}}}function Nye(e){const t=e.lastIndexOf("/");return t===-1?{dir:"",fileName:e}:{dir:e.slice(0,t+1),fileName:e.slice(t+1)}}function qH({path:e,className:t=""}){const{dir:n,fileName:a}=Nye(e);return E.jsxs("span",{className:`flex-1 min-w-0 flex font-mono text-xs leading-tight ${t}`,children:[n&&E.jsx("span",{className:"truncate text-muted-foreground/70",children:n}),E.jsx("span",{className:"truncate flex-shrink-0 max-w-full",children:a})]})}var Cye=Bt.memo(function({file:t,isActive:n,commentCount:a,viewed:i,guideDescription:r,onScrollToFile:o,onToggleViewed:l}){const{t:c,number:d}=We(),p=t.newPath||t.oldPath,m=GH(t),h=zv(t.changeType);return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs("div",{className:"flex items-center rounded-md",children:[E.jsxs(Ye,{variant:"ghost","data-testid":`file-entry-${p}`,"data-file-path":p,"aria-current":n?"true":void 0,onClick:()=>o(p),className:`h-auto min-w-0 flex-1 flex-col items-stretch text-start px-2 py-1.5 rounded-md transition-colors cursor-pointer ${n?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"}`,children:[E.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[E.jsx("span",{className:`change-type-badge flex-shrink-0 inline-flex items-center justify-center w-[18px] h-[18px] rounded-sm text-[10px] font-bold leading-none ${h.className}`,children:h.label}),E.jsx(qH,{path:p||c("Review-level comments")}),E.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m.additions>0&&E.jsxs("span",{className:"text-[10px] tabular-nums font-medium text-emerald-600 dark:text-emerald-400",children:["+",d(m.additions)]}),m.deletions>0&&E.jsxs("span",{className:"text-[10px] tabular-nums font-medium text-red-600 dark:text-red-400",children:["-",d(m.deletions)]}),a>0&&E.jsxs("span",{className:"inline-flex items-center gap-0.5 text-muted-foreground",children:[E.jsx(Qd,{className:"h-3 w-3"}),E.jsx("span",{className:"text-[10px] tabular-nums",children:d(a)})]})]})]}),r&&E.jsx("div",{className:"ps-6 pe-1 mt-1 text-[11px] leading-snug text-muted-foreground/90 line-clamp-2","data-testid":`guide-file-description-${p}`,children:r})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",size:"icon","data-testid":`viewed-toggle-${p}`,type:"button","aria-label":c(i?"Mark as needs review: {path}":"Mark as done reviewing: {path}",{path:p}),"aria-pressed":i,onClick:b=>{b.stopPropagation(),l(p)},className:"inline-flex items-center justify-center h-5 w-5 rounded-sm hover:bg-accent/80 transition-colors cursor-pointer",children:i?E.jsx(kh,{className:"h-3.5 w-3.5 text-emerald-600 dark:text-emerald-400"}):E.jsx(DP,{className:"h-3.5 w-3.5 text-muted-foreground/60"})})}),E.jsx(Gt,{side:"right",children:c(i?"Mark as needs review":"Mark as done reviewing")})]})]})}),E.jsx(Gt,{side:"right",className:"max-w-sm",children:E.jsx("p",{className:"font-mono text-xs break-all",children:p})})]},p)}),Rye=Yv("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground shadow",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function wo({className:e,variant:t,...n}){return E.jsx("div",{className:Wt(Rye({variant:t}),e),...n})}var xye=Yv("inline-flex items-center justify-center whitespace-nowrap rounded-none text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[pressed]:bg-accent data-[pressed]:text-accent-foreground first:rounded-l-md last:rounded-r-md [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground"},size:{default:"h-9 px-3 min-w-9",sm:"h-8 px-2 min-w-8",lg:"h-10 px-3 min-w-10"}},defaultVariants:{variant:"default",size:"default"}}),VH=w.createContext({size:"default",variant:"default"}),vf=w.forwardRef(({className:e,type:t,variant:n,size:a,value:i,defaultValue:r,onValueChange:o,children:l,...c},d)=>{const p=i!=null?i?[i]:[]:void 0,m=r?[r]:void 0,h=w.useCallback(b=>{o&&o(b[0]||"")},[o]);return E.jsx(Jhe,{ref:d,multiple:!1,value:p,defaultValue:m,onValueChange:h,className:Wt("inline-flex -space-x-px rounded-md shadow-sm",e),...c,children:E.jsx(VH.Provider,{value:{variant:n,size:a},children:l})})});vf.displayName="ToggleGroup";var or=w.forwardRef(({className:e,children:t,variant:n,size:a,...i},r)=>{const o=w.useContext(VH);return E.jsx(obe,{ref:r,className:Wt(xye({variant:n||o.variant,size:a||o.size}),e),...i,children:t})});or.displayName="ToggleGroupItem";function Iye(){const{t:e,number:t}=We(),n=ip(),{updateConfig:a}=n,{diffFiles:i}=lc(),{expanded:r,setAllExpanded:o}=Xb(),l=i.map(m=>m.newPath||m.oldPath),c=l.length>0&&l.every(m=>r.get(m)),d=()=>o(!c,l),p=m=>{(m==="split"||m==="unified")&&a({diffView:m})};return E.jsxs("div",{className:"flex items-center gap-1",children:[E.jsxs(vf,{type:"single",variant:"outline",size:"sm",value:n.diffView,onValueChange:p,children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"split","data-testid":"view-mode-split",className:"h-5 w-5 p-0",children:[E.jsx(NW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:e("Split view")})]})}),E.jsx(Gt,{children:e("Side-by-side view")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"unified","data-testid":"view-mode-unified",className:"h-5 w-5 p-0",children:[E.jsx(AK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:e("Unified view")})]})}),E.jsx(Gt,{children:e("Unified view")})]})]}),E.jsx(ha,{orientation:"vertical",className:"h-4"}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",size:"icon","data-testid":"keyboard-shortcuts-btn","aria-label":e("Keyboard shortcuts"),className:"h-5 w-5 text-muted-foreground hover:text-foreground",children:E.jsx(FP,{className:"h-3.5 w-3.5"})})}),E.jsxs(Gt,{side:"right",className:"text-xs space-y-1 p-2",children:[E.jsx("div",{className:"font-medium mb-1",children:e("Keyboard Shortcuts")}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Find in page")}),E.jsx("kbd",{className:"font-mono",children:"Ctrl+F"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Comment on line")}),E.jsx("kbd",{className:"font-mono",children:"f"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Jump to file")}),E.jsx("kbd",{className:"font-mono",children:"g"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Scroll diffs")}),E.jsx("kbd",{className:"font-mono",children:"j/k"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Cancel")}),E.jsx("kbd",{className:"font-mono",children:"Esc"})]})]})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",size:"icon","data-testid":c?"collapse-all-btn":"expand-all-btn",onClick:d,"aria-label":e(c?"Collapse all files":"Expand all files"),className:"h-5 w-5 text-muted-foreground hover:text-foreground",children:c?E.jsx(EW,{className:"h-3.5 w-3.5"}):E.jsx(vW,{className:"h-3.5 w-3.5"})})}),E.jsx(Gt,{children:e(c?"Collapse all files":"Expand all files")})]}),E.jsx(wo,{variant:"secondary",className:"h-5 px-1.5 text-[11px] font-normal tabular-nums rounded",children:t(i.length)})]})}function Oye(){const{t:e}=We(),{outputPathInfo:t,setOutputPathInfo:n}=X$(),a=_i(),i=async()=>{if(!a?.changeOutputPath)return;const r=await a.changeOutputPath();r&&n(r)};return E.jsx(E.Fragment,{children:t.resolvedOutputPath&&E.jsxs(E.Fragment,{children:[E.jsx(ha,{}),E.jsxs("div",{className:"px-3 py-2 space-y-1",children:[E.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[E.jsx("span",{className:"font-medium",children:e("Output:")}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(qH,{path:t.resolvedOutputPath,className:"cursor-default"})}),E.jsx(Gt,{side:"right",className:"max-w-sm",children:E.jsx("p",{className:"font-mono text-xs break-all",children:t.resolvedOutputPath})})]}),t.outputPathWritable?E.jsx(kh,{className:"h-3.5 w-3.5 text-green-500 shrink-0"}):E.jsx($y,{className:"h-3.5 w-3.5 text-red-500 shrink-0"}),a?.changeOutputPath&&E.jsx(Ye,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs ms-auto",onClick:i,children:e("Change...")})]}),!t.outputPathWritable&&E.jsx("p",{className:"text-xs text-red-500",children:e("Path not writable")})]})]})})}var BF=[{text:"text-indigo-600 dark:text-indigo-400",ring:"ring-indigo-500 dark:ring-indigo-400",dot:"bg-indigo-500 dark:bg-indigo-400",dotSoft:"bg-indigo-500/50 dark:bg-indigo-400/50",dotFaint:"bg-indigo-500/25 dark:bg-indigo-400/25",segment:"bg-indigo-500/35 dark:bg-indigo-400/35",stroke:"stroke-indigo-500 dark:stroke-indigo-400",strokeSoft:"stroke-indigo-500/45 dark:stroke-indigo-400/45",fill:"fill-indigo-500 dark:fill-indigo-400",fillText:"fill-indigo-600 dark:fill-indigo-400",numeralStroke:"rgb(99 102 241 / 0.34)"},{text:"text-teal-600 dark:text-teal-400",ring:"ring-teal-500 dark:ring-teal-400",dot:"bg-teal-500 dark:bg-teal-400",dotSoft:"bg-teal-500/50 dark:bg-teal-400/50",dotFaint:"bg-teal-500/25 dark:bg-teal-400/25",segment:"bg-teal-500/35 dark:bg-teal-400/35",stroke:"stroke-teal-500 dark:stroke-teal-400",strokeSoft:"stroke-teal-500/45 dark:stroke-teal-400/45",fill:"fill-teal-500 dark:fill-teal-400",fillText:"fill-teal-600 dark:fill-teal-400",numeralStroke:"rgb(20 184 166 / 0.34)"},{text:"text-amber-600 dark:text-amber-400",ring:"ring-amber-500 dark:ring-amber-400",dot:"bg-amber-500 dark:bg-amber-400",dotSoft:"bg-amber-500/50 dark:bg-amber-400/50",dotFaint:"bg-amber-500/25 dark:bg-amber-400/25",segment:"bg-amber-500/35 dark:bg-amber-400/35",stroke:"stroke-amber-500 dark:stroke-amber-400",strokeSoft:"stroke-amber-500/45 dark:stroke-amber-400/45",fill:"fill-amber-500 dark:fill-amber-400",fillText:"fill-amber-600 dark:fill-amber-400",numeralStroke:"rgb(245 158 11 / 0.34)"},{text:"text-rose-600 dark:text-rose-400",ring:"ring-rose-500 dark:ring-rose-400",dot:"bg-rose-500 dark:bg-rose-400",dotSoft:"bg-rose-500/50 dark:bg-rose-400/50",dotFaint:"bg-rose-500/25 dark:bg-rose-400/25",segment:"bg-rose-500/35 dark:bg-rose-400/35",stroke:"stroke-rose-500 dark:stroke-rose-400",strokeSoft:"stroke-rose-500/45 dark:stroke-rose-400/45",fill:"fill-rose-500 dark:fill-rose-400",fillText:"fill-rose-600 dark:fill-rose-400",numeralStroke:"rgb(244 63 94 / 0.34)"},{text:"text-sky-600 dark:text-sky-400",ring:"ring-sky-500 dark:ring-sky-400",dot:"bg-sky-500 dark:bg-sky-400",dotSoft:"bg-sky-500/50 dark:bg-sky-400/50",dotFaint:"bg-sky-500/25 dark:bg-sky-400/25",segment:"bg-sky-500/35 dark:bg-sky-400/35",stroke:"stroke-sky-500 dark:stroke-sky-400",strokeSoft:"stroke-sky-500/45 dark:stroke-sky-400/45",fill:"fill-sky-500 dark:fill-sky-400",fillText:"fill-sky-600 dark:fill-sky-400",numeralStroke:"rgb(14 165 233 / 0.34)"},{text:"text-violet-600 dark:text-violet-400",ring:"ring-violet-500 dark:ring-violet-400",dot:"bg-violet-500 dark:bg-violet-400",dotSoft:"bg-violet-500/50 dark:bg-violet-400/50",dotFaint:"bg-violet-500/25 dark:bg-violet-400/25",segment:"bg-violet-500/35 dark:bg-violet-400/35",stroke:"stroke-violet-500 dark:stroke-violet-400",strokeSoft:"stroke-violet-500/45 dark:stroke-violet-400/45",fill:"fill-violet-500 dark:fill-violet-400",fillText:"fill-violet-600 dark:fill-violet-400",numeralStroke:"rgb(139 92 246 / 0.34)"}],Dye={text:"text-muted-foreground",ring:"ring-muted-foreground/40",dot:"bg-muted-foreground/60",dotSoft:"bg-muted-foreground/40",dotFaint:"bg-muted-foreground/25",segment:"bg-muted-foreground/25",stroke:"stroke-muted-foreground/60",strokeSoft:"stroke-muted-foreground/50",fill:"fill-muted-foreground/60",fillText:"fill-muted-foreground",numeralStroke:"hsl(240 4% 46% / 0.3)"};function Us(e,t=!1){return t?Dye:BF[e%BF.length]}function Lye({index:e,implicit:t,complete:n=!1,surfaceClassName:a="bg-background",className:i=""}){const{number:r}=We(),o=Us(e,t),l=o.ring,c=n?t?"bg-muted-foreground/60 text-background":`${o.dot} text-white`:`${a} ${o.text}`;return E.jsx("span",{className:`flex h-[22px] w-[22px] shrink-0 items-center justify-center rounded-full ring-2 text-[10px] font-semibold leading-none ${l} ${c} ${i}`,"aria-hidden":"true",children:n?E.jsx(Jv,{className:"h-3 w-3"}):t?E.jsx(WW,{className:"h-3 w-3"}):r(e+1)})}function Mye(){const{t:e,number:t}=We(),{diffFiles:n}=lc(),a=lye(),{toggleViewed:i}=Ws(),{activeFilePath:r,scrollToFile:o}=cI(),{guide:l,mode:c}=au(),[d,p]=w.useState(""),m=w.useMemo(()=>{if(!d.trim())return n;const b=d.toLowerCase();return n.filter(y=>(y.newPath||y.oldPath).toLowerCase().includes(b))},[n,d]),h=w.useMemo(()=>HH(n,jH(m,l?.groups??null,c)),[n,m,l,c]);return E.jsxs("div",{className:"flex flex-col h-full","data-testid":"file-tree",children:[E.jsxs("div",{className:"px-3 pt-3 pb-2",children:[E.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[E.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:e("Changed files")}),E.jsx(Iye,{})]}),E.jsxs("div",{className:"relative",children:[E.jsx(vK,{className:"absolute start-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground pointer-events-none"}),E.jsx(zH,{type:"text",placeholder:e("Filter files..."),"aria-label":e("Filter files..."),value:d,onChange:b=>p(b.target.value),className:"h-7 ps-7 text-xs bg-background","data-testid":"file-search"})]})]}),E.jsx(ha,{}),E.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden p-1",children:[h.map((b,y)=>{const v=b.header?.groupIndex??y,S=(b.header?.groupIndex!==void 0?l?.groups[b.header.groupIndex]?.files.map(O=>O.path):void 0)??b.entries.map(({file:O})=>O.newPath||O.oldPath),A=b.header?S.filter(O=>a.get(O)?.viewed).length:0,N=b.entries.map(({file:O,description:D,key:M})=>{const B=O.newPath||O.oldPath;return E.jsx(Cye,{file:O,isActive:r===B,commentCount:a.get(B)?.commentCount??0,viewed:a.get(B)?.viewed??!1,guideDescription:D,onScrollToFile:o,onToggleViewed:i},M)});if(!b.header)return E.jsx(Bt.Fragment,{children:N},`section-${y}-flat`);const x=y===0,I=y===h.length-1;return E.jsxs("div",{className:"relative",children:[E.jsx("div",{className:`pointer-events-none absolute start-[18px] w-[2px] ${x?"top-[27px]":"top-0"} ${I?"bottom-2":"bottom-0"} ${b.header.implicit?"guide-route-dashed-v":Us(v).segment}`,"aria-hidden":"true"}),E.jsxs("div",{className:"px-2 pt-4 pb-1.5","data-testid":`guide-group-${b.header.name}`,children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx(Lye,{index:v,implicit:b.header.implicit,complete:S.length>0&&A===S.length,surfaceClassName:"bg-sidebar",className:"relative z-10"}),E.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-semibold text-foreground",children:b.header.implicit?e("Everything else"):b.header.name}),E.jsxs("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground",children:[t(A),"/",t(S.length)]})]}),b.header.rationale&&E.jsx("div",{className:"mt-1 ps-[30px] text-[11px] leading-snug text-muted-foreground",children:b.header.rationale})]}),E.jsx("div",{className:"ps-6",children:N})]},`section-${y}-${b.header.name}`)}),m.length===0&&E.jsx("div",{className:"text-center text-muted-foreground text-xs py-8",children:e(d?"No files match your search":"No files in diff")})]}),E.jsx(Oye,{})]})}function YH(e,t){return t==="added"||t==="deleted"?"unified":e}function Fye({sectionRef:e,effectiveViewMode:t,file:n,filePath:a,onCommentRange:i}){const[r,o]=w.useState(null),l=w.useMemo(()=>{const S=new Map;return n.hunks.forEach((A,N)=>{let x=1/0,I=-1/0,O=1/0,D=-1/0;for(const M of A.lines)M.oldLineNumber!==null&&(x=Math.min(x,M.oldLineNumber),I=Math.max(I,M.oldLineNumber)),M.newLineNumber!==null&&(O=Math.min(O,M.newLineNumber),D=Math.max(D,M.newLineNumber));for(const M of A.lines)M.oldLineNumber!==null&&S.set(`old-${M.oldLineNumber}`,{hunkIndex:N,minLine:x,maxLine:I}),M.newLineNumber!==null&&S.set(`new-${M.newLineNumber}`,{hunkIndex:N,minLine:O,maxLine:D})}),S},[n]),c=w.useMemo(()=>{if(t!=="unified")return null;const S=new Map;let A=0;return n.hunks.forEach((N,x)=>{for(const I of N.lines){const O=I.type==="deletion"?I.oldLineNumber:I.newLineNumber,D=I.type==="deletion"?"old":"new";S.set(A,{lineNumber:O,side:D,hunkIndex:x}),A++}}),S},[n,t]),d=w.useMemo(()=>{if(t!=="unified")return null;const S=[];let A=0;for(const N of n.hunks)S.push({min:A,max:A+N.lines.length-1}),A+=N.lines.length;return S},[n,t]),p=w.useRef(r);p.current=r;const m=w.useRef(l);m.current=l;const h=w.useRef(c);h.current=c;const b=w.useRef(d);b.current=d;const y=w.useRef(t);y.current=t;const v=w.useRef(i);v.current=i;const T=(S,A,N=!1)=>{if(N){const I=t==="unified"?n.hunks.flatMap(D=>D.lines)[S]:null,O=I?A==="old"?I.oldLineNumber:I.newLineNumber:S;O!=null&&i(O,O,A);return}const x={startLine:S,currentLine:S,side:A};p.current=x,o(x)};return w.useEffect(()=>{const S=N=>{const x=p.current;if(!x)return;let I=null;if(I=document.elementFromPoint(N.clientX,N.clientY)?.closest("[data-line-number]"),!(I&&!e.current?.contains(I))){if(!I&&e.current){const D=e.current.querySelectorAll("[data-line-number]");for(const M of D){const B=M.getBoundingClientRect();if(N.clientY>=B.top&&N.clientY<=B.bottom&&N.clientX>=B.left&&N.clientX<=B.right){I=M;break}}}if(I)if(y.current==="unified"){const D=I.getAttribute("data-row-index");if(!D)return;const M=parseInt(D,10);if(isNaN(M))return;const B=h.current,F=b.current;if(!B||!F)return;const G=B.get(x.startLine);if(!G)return;const z=F[G.hunkIndex],W=Math.max(z.min,Math.min(z.max,M));o(ie=>{const te=ie?{...ie,currentLine:W}:null;return p.current=te,te})}else{const D=parseInt(I.getAttribute("data-line-number"),10),M=I.getAttribute("data-line-side");if(!isNaN(D)&&M===x.side){const B=`${x.side}-${x.startLine}`,F=m.current.get(B);if(!F)return;const G=Math.max(F.minLine,Math.min(F.maxLine,D));o(z=>{const W=z?{...z,currentLine:G}:null;return p.current=W,W})}}}},A=()=>{const N=p.current;if(N){if(y.current==="unified"&&h.current){const x=Math.min(N.startLine,N.currentLine),I=Math.max(N.startLine,N.currentLine),O=h.current,D=[],M=[];for(let B=x;B<=I;B++){const F=O.get(B);F&&(F.side==="new"?D.push(F.lineNumber):M.push(F.lineNumber))}D.length>0?v.current(Math.min(...D),Math.max(...D),"new"):M.length>0&&v.current(Math.min(...M),Math.max(...M),"old")}else{const x=Math.min(N.startLine,N.currentLine),I=Math.max(N.startLine,N.currentLine);v.current(x,I,N.side)}p.current=null,o(null)}};return document.addEventListener("mousemove",S),document.addEventListener("mouseup",A),()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",A)}},[]),w.useEffect(()=>{const S=N=>{const{filePath:x,lineNumber:I,side:O}=N.detail;x===a&&(p.current||v.current(I,I,O))},A=e.current;return A?.addEventListener("trigger-line-comment",S),()=>A?.removeEventListener("trigger-line-comment",S)},[a]),{dragState:r,handleDragStart:T}}function Bye(e,t,n){const[a,i]=w.useState(null),[r,o]=w.useState(!1),l=w.useCallback((b,y,v)=>{i({start:Math.min(b,y),end:Math.max(b,y),side:v})},[]),c=w.useCallback(()=>i(null),[]),d=w.useCallback(()=>o(!1),[]),p=w.useCallback(()=>o(!0),[]),{dragState:m,handleDragStart:h}=Fye({sectionRef:t,effectiveViewMode:n,file:e,filePath:e.newPath||e.oldPath,onCommentRange:l});return{lineComments:{commentRange:a,onCancelComment:c,onCommentSaved:c},rawSelection:{dragState:m,onDragStart:h},onCommentRange:l,fileComment:{showingFileComment:r,openFileComment:p,closeFileComment:d}}}function Pye(e,t){const n=t.available?e.hunks.flatMap(l=>l.lines.map(c=>c.content)):[],[a,i]=w.useState(()=>({path:e.newPath||e.oldPath,content:n,binary:e.isBinary,changeType:e.changeType,kind:t.builtIn.kind,renderer:t.renderer,mode:t.defaultMode})),r=e.newPath||e.oldPath,o=a.path!==r||a.content.length!==n.length||a.content.some((l,c)=>l!==n[c])||a.binary!==e.isBinary||a.changeType!==e.changeType||a.kind!==t.builtIn.kind||a.renderer!==t.renderer;return o&&i({path:r,content:n,binary:e.isBinary,changeType:e.changeType,kind:t.builtIn.kind,renderer:t.renderer,mode:t.defaultMode}),{renderViewMode:o?t.defaultMode:a.mode,setRenderViewMode:l=>i(c=>({...c,mode:l}))}}function fh(e,t){const n=wH(e,t);return n?n.map(a=>a.content).join(`
305
- `):void 0}function Uye(e){let t=1/0,n=-1/0,a=1/0,i=-1/0;for(const r of e.lines)r.type!=="context"&&(r.oldLineNumber!==null&&(t=Math.min(t,r.oldLineNumber),n=Math.max(n,r.oldLineNumber)),r.newLineNumber!==null&&(a=Math.min(a,r.newLineNumber),i=Math.max(i,r.newLineNumber)));return{oldRange:t<=n?[t,n]:null,newRange:a<=i?[a,i]:null}}function Gv(e){let t=0;for(const n of e.lines)if(n.type==="context")t++;else break;return t}function qv(e){let t=0;for(let n=e.lines.length-1;n>=0&&e.lines[n].type==="context";n--)t++;return t}function $ye(e,t){for(const n of e.lines)if(n.type!=="context"&&(t.oldRange&&n.oldLineNumber!==null&&n.oldLineNumber>=t.oldRange[0]&&n.oldLineNumber<=t.oldRange[1]||t.newRange&&n.newLineNumber!==null&&n.newLineNumber>=t.newRange[0]&&n.newLineNumber<=t.newRange[1]))return!0;return!1}function Hye(e,t,n){return e.map(a=>{const i=[];for(let S=0;S<t.length;S++)$ye(a,t[S])&&i.push(S);if(i.length===0)return a;const r=n[i[0]],o=n[i[i.length-1]],l=Gv(a),c=qv(a),d=Math.max(0,l-r.above),p=Math.max(0,c-o.below);if(d===0&&p===0)return a;const m=p>0?a.lines.length-p:a.lines.length,h=a.lines.slice(d,m);if(h.length===0)return a;let b=0,y=0;for(const S of h)(S.type==="context"||S.type==="deletion")&&b++,(S.type==="context"||S.type==="addition")&&y++;const v=a.oldStart+d,T=a.newStart+d;return{...a,lines:h,oldStart:v,newStart:T,oldLines:b,newLines:y,header:`@@ -${v},${b} +${T},${y} @@`}})}function jye(e,t,n,a,i,r){const o=n.map(h=>({...h})),l=e[i],c=h=>{const b=[];for(let y=0;y<t.length;y++){const v=t[y];for(const T of h.lines)if(T.type!=="context"){if(v.oldRange&&T.oldLineNumber!==null&&T.oldLineNumber>=v.oldRange[0]&&T.oldLineNumber<=v.oldRange[1]){b.push(y);break}if(v.newRange&&T.newLineNumber!==null&&T.newLineNumber>=v.newRange[0]&&T.newLineNumber<=v.newRange[1]){b.push(y);break}}}return b},d=5,p=99999;if(a==="up"){const h=c(l);h.length>0&&(o[h[0]].above+=d)}else if(a==="down"){const h=r==="bottom"?i:i-1,b=e[Math.max(0,h)],y=c(b);y.length>0&&(o[y[y.length-1]].below+=d)}else if(r==="top"){const h=c(l);h.length>0&&(o[h[0]].above=p)}else if(r==="bottom"){const h=c(l);h.length>0&&(o[h[h.length-1]].below=p)}else{const h=e[i-1],b=c(h);b.length>0&&(o[b[b.length-1]].below=p);const y=c(l);y.length>0&&(o[y[0]].above=p)}let m=0;for(const h of o)m=Math.max(m,h.above,h.below);return{budgets:o,maxBudget:m}}function zye(e,t,n,a){const i=t==="down"?Math.max(0,a==="bottom"?n:n-1):n,r=e[i]?.lines,o=t==="down"?r?.[r.length-1]:r?.[0];if(!o)return null;const l=o.type==="deletion"?"old":"new",c=l==="old"?o.oldLineNumber:o.newLineNumber;return c===null?null:{lineNumber:c,side:l}}function Gye(e,t,n){const a=w.useRef(null);return w.useLayoutEffect(()=>{const i=a.current;if(!i||(a.current=null,i.owner!==n))return;const r=e.current,o=r?.closest('[data-scroll-container="diff"]'),l=r?.querySelector(`[data-line-number="${i.lineNumber}"][data-line-side="${i.side}"]`);if(!l||!o)return;const c=l.getBoundingClientRect().top-o.getBoundingClientRect().top-i.offset;Math.abs(c)>1&&(o.scrollTop=i.scrollTop+c)},[t,n,e]),w.useMemo(()=>({clear:()=>{a.current=null},capture(i,r,o,l){a.current=null;const c=zye(i,r,o,l),d=e.current,p=d?.closest('[data-scroll-container="diff"]');if(!c||!p||!d)return;const m=d.querySelector(`[data-line-number="${c.lineNumber}"][data-line-side="${c.side}"]`);m&&(a.current={...c,owner:n,offset:m.getBoundingClientRect().top-p.getBoundingClientRect().top,scrollTop:p.scrollTop})}}),[n,e])}function qye({file:e,filePath:t,isExpandable:n,sectionRef:a,expanded:i=!0}){const{isCurrentSession:r,updateFileHunks:o}=Ws(),l=_i(),c=Jb(),d=uI(),[p,m]=w.useState(!1),[h,b]=w.useState(!1),[y,v]=w.useState(null),T=w.useRef(null),S=w.useRef(null),A=w.useRef(null),N=w.useRef(0),x=w.useMemo(()=>({}),[c,d,l,t]),I=w.useRef(x),O=w.useRef(null),D=w.useRef(i);D.current=i,w.useEffect(()=>()=>{O.current?.abort(),O.current=null,m(!1),G.current=!1},[x,i]);const M=w.useRef(!0);w.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]),I.current!==x&&(I.current=x,T.current=null,S.current=null,A.current=null,N.current=0,v(null),m(!1),b(!1)),T.current===null&&e.hunks.length>0&&(T.current=e.hunks.map(te=>Uye(te)),S.current=e.hunks.map(te=>({above:Gv(te),below:qv(te)})),N.current=Math.max(...e.hunks.flatMap(te=>[Gv(te),qv(te)]),0));const F=Gye(a,e.hunks,x),G=w.useRef(p);G.current=p;const z=w.useRef(e.hunks);z.current=e.hunks;const W=w.useRef(y);W.current=y;const ie=w.useCallback(async(te,K,ne)=>{if(!n||!D.current||G.current)return;b(!1);const Q=S.current,se=T.current;if(!Q||!se)return;const j=z.current,Y=jye(j,se,Q,te,K,ne);S.current=Y.budgets,F.capture(j,te,K,ne);const{maxBudget:oe}=Y,$=I.current,he=new AbortController;O.current=he;const Ne=()=>M.current&&D.current&&I.current===$&&!he.signal.aborted&&(r?.()??!0);G.current=!0,m(!0);let ke=null,be=W.current;if(oe>N.current||!A.current){let Ae=null;try{Ae=await uH(l,{filePath:t,contextLines:oe},he.signal)}catch{}if(!Ne())return;if(!Ae){b(!0),m(!1),G.current=!1,F.clear();return}ke=Ae.hunks,Ae.totalLines>0&&(be=Ae.totalLines),A.current=ke,N.current=oe}else ke=A.current;if(!Ne())return;const Ce=Hye(ke,se,Y.budgets);o(t,Ce),v(be),m(!1),G.current=!1},[n,t,l,r,o,F]);return{expandLoading:p,expandError:h,totalLines:y,handleExpandContext:ie}}var og={kind:"idle"};function Vye(e,t){return e instanceof Error&&e.message?e.message:typeof e=="string"&&e?e:t}function Yye({file:e,filePath:t,expanded:n}){const{t:a}=We(),{updateFileHunks:i}=Ws(),r=Jb(),o=uI(),l=_i(),c=w.useMemo(()=>({}),[e,r,o,l,t]),[d,p]=w.useState({owner:c,state:og}),m=d.owner===c?d.state:og,h=w.useRef(null),b=n&&e.contentLoaded===!1,y=w.useRef(0);w.useEffect(()=>()=>{y.current+=1,h.current?.abort(),h.current=null,p(T=>T.owner===c&&T.state.kind==="loading"?{owner:c,state:og}:T)},[c,b]),w.useEffect(()=>{if(!b||m.kind!=="idle")return;const T=x=>p({owner:c,state:x});if(!oEe(l)){T({kind:"error",message:a("this review host cannot load file content on demand")});return}const S=++y.current,A=new AbortController;h.current=A;const N=()=>S===y.current&&!A.signal.aborted;T({kind:"loading"}),uEe(l,t,A.signal).then(x=>{N()&&(x?(i(t,x),T({kind:"loaded"})):T({kind:"error",message:a("the review host returned no content for this file")}))},x=>{N()&&T({kind:"error",message:Vye(x,a("the request failed"))})})},[b,m.kind,c,t,l,i,a]);const v=w.useCallback(()=>{p(T=>T.owner===c&&T.state.kind==="error"?{owner:c,state:og}:T)},[c]);return{state:m,retry:v}}var Wye=new Set([".jpg",".jpeg",".png",".gif",".webp",".ico",".bmp"]),Kye=new Set([".md",".markdown"]),Xye=new Set([".html",".htm"]);function e0(e){const t=e.lastIndexOf(".");return t===-1||t===e.length-1?"":e.slice(t).toLowerCase()}function WH(e){return Wye.has(e0(e))}function Zye(e){return e0(e)===".svg"}function Qye(e){return Kye.has(e0(e))}function Jye(e){return Xye.has(e0(e))}function eve(e){return Qye(e)?"markdown":Jye(e)?"html":null}function KH(e){const t=e.split(".").pop()?.toLowerCase()||"",n={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",css:"css",json:"json",md:"markdown",markdown:"markdown",sh:"bash",bash:"bash",yml:"yaml",yaml:"yaml",java:"java",go:"go",rs:"rust",sql:"sql",html:"markup",htm:"markup",xml:"markup",rb:"ruby",php:"php",twig:"twig",c:"c",cpp:"cpp",h:"c",hpp:"cpp",ini:"ini",toml:"toml",csv:"csv",diff:"diff",patch:"diff",scss:"scss",sass:"sass",graphql:"graphql",gql:"graphql",conf:"nginx",mongodb:"mongodb",makefile:"makefile",mk:"makefile",mak:"makefile",vim:"vim",vimrc:"vim"},a=e.split("/").pop()?.toLowerCase()||"";return a==="dockerfile"||a.startsWith("dockerfile.")?"docker":a==="makefile"||a.startsWith("makefile.")?"makefile":a.startsWith(".git")?"git":a===".vimrc"||a.startsWith(".vim")?"vim":n[t]||"plaintext"}function tve(e){if(e.changeType!=="added")return{kind:"none"};const t=e.newPath||e.oldPath;if(e.isBinary&&WH(t))return{kind:"image"};if(Zye(t))return{kind:"svg"};const n=eve(t);return n?{kind:"text",mode:n}:{kind:"none"}}function nve(e){return e.kind==="image"||e.kind==="text"?"rendered":"raw"}function XH(e,t=null,n=tve(e)){const a=e.changeType==="added"&&t?.supports(e,n)?t:null;return{builtIn:n,renderer:a,available:n.kind!=="none"||a!==null,defaultMode:n.kind==="none"&&a?a.defaultMode??"raw":nve(n)}}function ave(e,t,n,a){const{expanded:i,setExpanded:r}=Xb(),o=n??i.get(e)??!1,l=w.useCallback(d=>{o!==d&&(a?a(e):r(e,d))},[o,a,e,r]),c=w.useRef(!1);return w.useEffect(()=>{c.current!==t&&l(!t),c.current=t},[t,l]),{expanded:o,changeExpanded:l}}async function ive(e,t){if(t?.writeClipboard)return t.writeClipboard(e);if(typeof navigator>"u"||!navigator.clipboard?.writeText)throw new Error("Clipboard unavailable");await navigator.clipboard.writeText(e)}function rve({bodyId:e,file:t,filePath:n,expanded:a,isViewed:i,isPreviewable:r,renderViewMode:o,commentCount:l,onToggle:c,onViewedToggle:d,onAddFileComment:p,onRenderViewModeChange:m}){const{t:h,number:b}=We(),{additions:y,deletions:v}=GH(t),T=t.changeType==="renamed"||t.changeType==="copied",S=T?`${t.oldPath} → ${t.newPath}`:n||h("Review-level comments"),A=zv(t.changeType).label==="?"?h("unknown"):h(t.changeType),N=w.useRef(null),[x,I]=w.useState(!1),[O,D]=w.useState(!1),[M,B]=w.useState(!1),F=_i(),G=uc(),z=w.useRef(0);w.useEffect(()=>(z.current++,D(!1),B(!1),()=>{z.current++}),[n,F,G]),w.useEffect(()=>{if(!O)return;const ie=setTimeout(()=>D(!1),1500);return()=>clearTimeout(ie)},[O]);const W=async()=>{const ie=T?t.newPath:n,te=++z.current;B(!1);try{if(await ive(ie,F),z.current!==te)return;D(!0)}catch{z.current===te&&B(!0)}};return w.useEffect(()=>{const ie=N.current;if(!ie)return;const te=new IntersectionObserver(([K])=>I(!K.isIntersecting),{threshold:0});return te.observe(ie),()=>te.disconnect()},[]),E.jsxs(E.Fragment,{children:[M&&E.jsx("p",{role:"alert",className:"px-3 text-sm text-destructive",children:h("The path could not be copied. Try again or copy it manually.")}),E.jsx("div",{ref:N,className:"h-0 w-0","aria-hidden":!0}),E.jsxs("div",{className:`sticky top-0 z-10 flex items-center gap-2 h-10 px-3 bg-muted/80 backdrop-blur-sm border-b border-border cursor-pointer select-none${x?"":" rounded-t-lg"}`,"data-testid":`file-header-${n}`,onClick:c,children:[E.jsxs(Ye,{variant:"ghost",className:"h-auto min-w-0 flex-1 justify-start gap-2 p-0 text-start","aria-expanded":a,"aria-controls":e,"aria-label":h(a?"Collapse {path}":"Expand {path}",{path:S}),onClick:ie=>{ie.stopPropagation(),c()},children:[E.jsx("span",{className:"text-muted-foreground","data-testid":"collapse-toggle",children:a?E.jsx(ek,{className:"h-4 w-4"}):E.jsx(gW,{className:"h-4 w-4"})}),E.jsx("span",{className:"font-mono text-[13px] font-medium truncate flex-1 min-w-0",children:S})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":`copy-file-path-${n}`,onClick:ie=>{ie.stopPropagation(),W()},className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",children:[O?E.jsx(Jv,{className:"h-3.5 w-3.5 text-emerald-600 dark:text-emerald-400"}):E.jsx(RW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:h("Copy file path")})]})}),E.jsx(Gt,{children:h(O?"Copied!":"Copy file path")})]}),E.jsx(wo,{variant:"secondary",className:`text-[10px] font-semibold px-1.5 py-0 h-5 ${zv(t.changeType).className}`,children:A}),E.jsxs("span",{className:"flex items-center gap-1 text-xs tabular-nums text-muted-foreground",children:[y>0&&E.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",b(y)]}),v>0&&E.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["-",b(v)]})]}),r&&E.jsxs(vf,{type:"single",value:o,onValueChange:ie=>ie&&m(ie),size:"sm",className:"h-6",onClick:ie=>ie.stopPropagation(),children:[E.jsx(or,{value:"raw","aria-label":h("Raw view"),className:"text-[10px] h-6 px-1.5",children:h("Raw")}),E.jsx(or,{value:"rendered","aria-label":h("Rendered view"),className:"text-[10px] h-6 px-1.5",children:h("Rendered")})]}),l>0&&E.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground tabular-nums",children:[E.jsx(Qd,{className:"h-3.5 w-3.5"}),b(l)]}),E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":`viewed-${n}`,"aria-pressed":i,"data-hint-action":"toggle-viewed","data-hint-file-path":n,onClick:ie=>{ie.stopPropagation(),d()},className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",children:[i?E.jsx(kh,{className:"h-3.5 w-3.5 text-emerald-600 dark:text-emerald-400"}):E.jsx(DP,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:h(i?"Done reviewing":"To review")})]})}),E.jsx(Gt,{children:h(i?"Mark as needs review":"Mark as done reviewing")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":`add-file-comment-${n}`,"data-hint-action":"add-file-comment","data-hint-file-path":n,onClick:ie=>{ie.stopPropagation(),p()},className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",children:[E.jsx(Qd,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:h("Add comment")})]})}),E.jsx(Gt,{children:h("Add file comment")})]})]})]})}var sve=new Set(["a","abbr","address","article","aside","b","bdi","bdo","blockquote","br","caption","cite","code","col","colgroup","dd","del","details","dfn","div","dl","dt","em","figcaption","figure","footer","h1","h2","h3","h4","h5","h6","header","hr","i","img","input","ins","kbd","li","main","mark","nav","ol","p","pre","q","rp","rt","ruby","s","samp","section","small","span","strong","sub","summary","sup","table","tbody","td","th","thead","time","tr","u","ul","var","wbr"]),ove=new Set(["className","title","lang","dir"]),uve={a:new Set(["href"]),img:new Set(["src","alt","width","height"]),input:new Set(["type","checked","disabled"]),ol:new Set(["start","reversed"]),li:new Set(["value"]),td:new Set(["align","colSpan","rowSpan"]),th:new Set(["align","colSpan","rowSpan","scope"]),col:new Set(["span"]),colgroup:new Set(["span"]),details:new Set(["open"]),time:new Set(["dateTime"])};function lve(e,t){return ove.has(t)||uve[e]?.has(t)===!0}var cve=/^language-[\w-]+$/;function dve(e){return(Array.isArray(e)?e:String(e??"").split(/\s+/)).map(String).filter(n=>cve.test(n))}function sp(){return e=>{function t(n){n.children=n.children.filter(a=>{if(a.type!=="element")return a.type==="text";if(!sve.has(a.tagName))return!1;for(const i of Object.keys(a.properties))lve(a.tagName,i)||delete a.properties[i];if("className"in a.properties){const i=dve(a.properties.className);i.length>0?a.properties.className=i:delete a.properties.className}if(a.tagName==="img"&&typeof a.properties.src=="string"){const i=a.properties.src;kf(i)||(QH(i)&&(a.properties["data-reviewed-image-source"]=i),delete a.properties.src)}return a.tagName==="input"&&(a.properties.type="checkbox",a.properties.disabled=!0),t(a),!0})}t(e)}}var fve=["href","src"];function ZH(e){for(const t of e.children)if(t.type==="element"){for(const n of fve)n in t.properties&&(t.properties[n]=op(String(t.properties[n]??""),n,t)??void 0);ZH(t)}}function pve(e){const t=yU(e,{fragment:!0});return sp()(t),ZH(t),t}function QH(e){const t=e.trim().replace(/[\t\r\n]/g,"");return!t||t.startsWith("//")||t.includes("\\")?!1:/^data:image\/(?:png|jpeg|gif|webp|bmp|x-icon|vnd\.microsoft\.icon|svg\+xml)[;,]/i.test(t)||/^blob:/i.test(t)?!0:!/^[a-z][a-z\d+.-]*:/i.test(t)}function kf(e){return QH(e)&&/^(?:data:image\/|blob:)/i.test(e.trim())}var op=(e,t,n)=>{if(n.tagName==="a"&&t==="href")return d7(e);if(n.tagName==="img"&&t==="src"&&kf(e))return e};function PF(e){for(const t of e)if(t.charCodeAt(0)<32||t.charCodeAt(0)===127)return!0;return!1}function mve(e,t){const n=e.trim();if(!n||PF(n)||n.includes("\\")||n.startsWith("//")||/^[a-z][a-z\d+.-]*:/i.test(n))return null;const a=n.split(/[?#]/,1)[0];if(!a)return null;const i=a.startsWith("/")?[]:t?.split("/").slice(0,-1)??[];if(i.some(r=>!r||r==="."||r===".."||r.includes("\\")))return null;try{for(const r of a.split("/")){const o=decodeURIComponent(r);if(PF(o)||o.includes("/")||o.includes("\\"))return null;if(!(!o||o==="."))if(o===".."){if(!i.length)return null;i.pop()}else i.push(o)}}catch{return null}return i.length?i.join("/"):null}var JH=w.createContext(void 0);function pI({documentPath:e,children:t}){return E.jsx(JH.Provider,{value:e,children:t})}function up({src:e,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,"data-reviewed-image-source":c}){const d={src:e,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,"data-reviewed-image-source":c},p=w.useContext(Ba);return p?E.jsx(gve,{...d,store:p}):E.jsx(hve,{...d})}var gve=w.memo(function({store:t,...n}){const a=()=>t.getSnapshot().allDiffFiles,i=w.useSyncExternalStore(t.subscribe,a,a),r=uc();return E.jsx(ej,{...n,files:i,snapshot:r})});function hve(e){const t=w.useContext(Wb),n=t?`${t.sessionId}:${t.snapshotId??""}`:"";return E.jsx(ej,{...e,files:t?.diffFiles,snapshot:n})}function ej({src:e,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,"data-reviewed-image-source":c,files:d,snapshot:p}){const{t:m}=We(),h=_i(),b=w.useContext(JH),[y,v]=w.useState(0),T=typeof e=="string"&&kf(e)?e:void 0,S=c?mve(c,b):null,A=!!(h?.reads?.loadImage||h?.loadImage),N=S&&WH(S)&&d?.filter(F=>F.newPath===S||F.oldPath===S).length===1,x=w.useMemo(()=>({}),[h,p,d,S,T,y]),[I,O]=w.useState(null),D=I?.request===x?I:null;w.useEffect(()=>{if(T||!S||!N||!A)return;const F=new AbortController;return oH(h,S,F.signal).then(G=>{F.signal.aborted||O({request:x,...G&&typeof G=="object"&&"dataUri"in G&&typeof G.dataUri=="string"&&kf(G.dataUri)?{url:G.dataUri}:{failed:!0}})},()=>{F.signal.aborted||O({request:x,failed:!0})}),()=>F.abort()},[h,S,N,A,T,x]);const M=D?.failed||!T&&(!N||!A),B=D?.failed?void 0:T??D?.url;return B?E.jsx("img",{src:B,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,onError:()=>O({request:x,failed:!0})}):M?E.jsxs("span",{role:"alert","aria-label":m("Image preview unavailable"),title:n,children:[t&&E.jsxs("span",{children:[t,": "]}),m(!A&&!T?"Image loading not supported in this context.":"Failed to load image."),N&&A&&E.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>{O(null),v(F=>F+1)},children:m("Retry")})]}):E.jsx("span",{role:"status","aria-label":m("Loading image..."),children:t||m("Loading image...")})}var UF={critical:{className:"bg-red-500/15 text-red-600 dark:text-red-400",description:"Critical: data loss, a security hole, or a crash on a path real usage reaches."},major:{className:"bg-orange-500/15 text-orange-600 dark:text-orange-400",description:"Major: wrong behaviour or a broken contract on a path real usage reaches."},minor:{className:"bg-yellow-500/15 text-yellow-700 dark:text-yellow-400",description:"Minor: real but bounded. Behaviour is correct today."},info:{className:"bg-muted text-muted-foreground",description:"Info: no defect. Style, naming, a question, or a note."}},$F={high:{className:"bg-muted text-muted-foreground",description:"High confidence: traceable from the diff, no unverified assumption needed."},medium:{className:"bg-muted text-muted-foreground",description:"Medium confidence: rests on one assumption the author did not verify."},low:{className:"bg-amber-500/15 text-amber-700 dark:text-amber-400",description:"Low confidence: speculative. Worth your eyes, not worth acting on unattended."}};function HF({label:e,styles:t,testId:n}){const{t:a}=We();return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(wo,{variant:"secondary",className:`h-5 px-1.5 text-[10px] font-medium ${t?.className??"bg-muted text-muted-foreground"}`,"data-testid":n,children:e})}),E.jsx(Gt,{side:"bottom",children:a(t?.description??"Unknown signal")})]})}function bve({comment:e,contentId:t,isCollapsed:n,anchorFullyVisible:a,onEdit:i,onDelete:r,onToggleCollapse:o}){const{t:l}=We(),d=Zx()?.find(p=>p.name===e.category);return E.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:o,"aria-expanded":!n,"aria-controls":t,className:"h-5 w-5 p-0 -ms-1","data-testid":`comment-collapse-toggle-${e.id}`,children:[n?E.jsx(ek,{className:"h-3.5 w-3.5"}):E.jsx(OP,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:l(n?"Expand":"Collapse")})]}),E.jsx("span",{className:"flex items-center gap-1 text-xs font-semibold text-foreground max-w-[200px] truncate",children:e.author?E.jsxs(E.Fragment,{children:[E.jsx(IP,{className:"h-3.5 w-3.5 shrink-0"}),e.author]}):E.jsxs(E.Fragment,{children:[E.jsx($P,{className:"h-3.5 w-3.5 shrink-0"}),l("You")]})}),e.lineRange&&E.jsx("span",{className:"text-[11px] text-muted-foreground",children:e.lineRange.start===e.lineRange.end?l("line {line}",{line:e.lineRange.start}):l("lines {start}–{end}",{start:e.lineRange.start,end:e.lineRange.end})}),e.category&&(d?E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(wo,{variant:"secondary",className:"category-badge h-5 px-1.5 text-[10px] font-medium",style:{backgroundColor:`${d.color}20`,color:d.color,borderColor:`${d.color}40`,borderWidth:"1px"},children:e.category})}),E.jsx(Gt,{side:"bottom",children:d.description})]}):E.jsx(wo,{variant:"secondary",className:"category-badge h-5 px-1.5 text-[10px] font-medium",style:{borderWidth:"1px"},children:e.category})),e.severity&&E.jsx(HF,{label:Object.prototype.hasOwnProperty.call(UF,e.severity)?l(e.severity):String(e.severity),styles:UF[e.severity],testId:`comment-severity-${e.severity}`}),e.confidence&&E.jsx(HF,{label:Object.prototype.hasOwnProperty.call($F,e.confidence)?l(`${e.confidence} confidence`):String(e.confidence),styles:$F[e.confidence],testId:`comment-confidence-${e.confidence}`}),e.orphaned&&E.jsx(wo,{variant:"secondary",className:"h-5 px-1.5 text-[10px] bg-orange-500/15 text-orange-600 dark:text-orange-400",children:l("Orphaned")}),e.lineRange&&!a&&E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(wo,{variant:"secondary",className:"h-5 px-1.5 text-[10px] bg-amber-500/15 text-amber-700 dark:text-amber-400","data-testid":"comment-anchor-partial",children:l("Partly hidden")})}),E.jsx(Gt,{side:"bottom",children:l("Some lines of this range are not in the loaded diff. The recorded original code is kept for its suggestion.")})]})]}),!n&&E.jsxs("div",{className:"flex gap-0.5",children:[E.jsx("div",{className:"opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:i,className:"h-6 w-6 p-0",children:[E.jsx(PP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:l("Edit")})]})}),E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:r,"data-hint-action":"delete-comment",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",children:[E.jsx(UP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:l("Delete")})]})]})]})}function Eve(e){const{deleteComment:t}=Ws(),{isCollapsed:n,setCollapsed:a}=eI(),[i,r]=w.useState(!1),[o,l]=w.useState(!1),c=n(e);return{isEditing:i,startEditing:()=>r(!0),finishEditing:()=>r(!1),isReplying:o,startReplying:()=>l(!0),finishReplying:()=>l(!1),isCollapsed:c,toggleCollapse:()=>a(e,!c),deleteThread:()=>t(e)}}var tj=(function(e){if(e==null)return wve;if(typeof e=="function")return t0(e);if(typeof e=="object")return Array.isArray(e)?yve(e):vve(e);if(typeof e=="string")return kve(e);throw new Error("Expected function, string, or object as test")});function yve(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=tj(e[n]);return t0(a);function a(...i){let r=-1;for(;++r<t.length;)if(t[r].apply(this,i))return!0;return!1}}function vve(e){const t=e;return t0(n);function n(a){const i=a;let r;for(r in e)if(i[r]!==t[r])return!1;return!0}}function kve(e){return t0(t);function t(n){return n&&n.type===e}}function t0(e){return t;function t(n,a,i){return!!(Tve(n)&&e.call(this,n,typeof a=="number"?a:void 0,i||void 0))}}function wve(){return!0}function Tve(e){return e!==null&&typeof e=="object"&&"type"in e}function Sve(e){return"\x1B[33m"+e+"\x1B[39m"}var nj=[],_ve=!0,jF=!1,Ave="skip";function Nve(e,t,n,a){let i;typeof t=="function"&&typeof n!="function"?(a=n,n=t):i=t;const r=tj(i),o=a?-1:1;l(e,void 0,[])();function l(c,d,p){const m=c&&typeof c=="object"?c:{};if(typeof m.type=="string"){const b=typeof m.tagName=="string"?m.tagName:typeof m.name=="string"?m.name:void 0;Object.defineProperty(h,"name",{value:"node ("+Sve(c.type+(b?"<"+b+">":""))+")"})}return h;function h(){let b=nj,y,v,T;if((!t||r(c,d,p[p.length-1]||void 0))&&(b=Cve(n(c,p)),b[0]===jF))return b;if("children"in c&&c.children){const S=c;if(S.children&&b[0]!==Ave)for(v=(a?S.children.length:-1)+o,T=p.concat(S);v>-1&&v<S.children.length;){const A=S.children[v];if(y=l(A,v,T)(),y[0]===jF)return y;v=typeof y[1]=="number"?y[1]:v+o}}return b}}}function Cve(e){return Array.isArray(e)?e:typeof e=="number"?[_ve,e]:e==null?nj:[e]}function Rve(e,t,n,a){let i,r,o;r=t,o=n,i=a,Nve(e,r,l,i);function l(c,d){const p=d[d.length-1],m=p?p.children.indexOf(c):void 0;return o(c,m,p)}}function n0(){return e=>{Rve(e,"text",(t,n,a)=>{if(a&&(a.type==="code"||a.type==="inlineCode"))return;const i=/:([a-z0-9_+-]+):/g;let r,o=0;const l=[];for(;(r=i.exec(t.value))!==null;){const c=$Ee(r[1]);c&&(r.index>o&&l.push({type:"text",value:t.value.slice(o,r.index)}),l.push({type:"text",value:c}),o=i.lastIndex)}l.length>0&&(o<t.value.length&&l.push({type:"text",value:t.value.slice(o)}),a&&typeof n=="number"&&a.children.splice(n,1,...l))})}}var aj=e0e,xve=n0e,Ive=i0e,ij=w.forwardRef(({className:e,...t},n)=>E.jsx(q7,{ref:n,className:Wt("fixed inset-0 z-50 bg-black/60 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));ij.displayName=q7.displayName;var mI=w.forwardRef(({className:e,children:t,...n},a)=>{const i=Ys(),{t:r}=We();return E.jsxs(Ive,{container:i,children:[E.jsx(ij,{}),E.jsxs(V7,{ref:a,className:Wt("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-lg",e),...n,children:[t,E.jsxs(f0e,{className:"absolute end-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none",children:[E.jsx(nk,{className:"h-4 w-4"}),E.jsx("span",{className:"sr-only",children:r("Close")})]})]})]})});mI.displayName=V7.displayName;var gI=w.forwardRef(({className:e,...t},n)=>E.jsx(W7,{ref:n,className:Wt("text-lg font-semibold",e),...t}));gI.displayName=W7.displayName;var rj=w.forwardRef(({className:e,...t},n)=>E.jsx(K7,{ref:n,className:Wt("text-sm text-muted-foreground",e),...t}));rj.displayName=K7.displayName;function sj({attachment:e}){const{t}=We(),n=uc(),[a,i]=w.useState(0),[r,o]=w.useState(null),[l,c]=w.useState(null),d=_i();return w.useEffect(()=>{let p=!0;const m=new AbortController;let h=null;o(null),c(null);const b=y=>{h=URL.createObjectURL(new Blob([y],{type:e.mediaType})),o(h)};return e.data?b(e.data):e.fileName&&(d?.reads?.readAttachment||d?.readAttachment)?lEe(d,e.fileName,m.signal).then(y=>{p&&(y?b(y):c(t("Image not found")))},y=>{p&&c(y instanceof Error?y.message:t("Image not found"))}):c(t("Image not found")),()=>{p=!1,m.abort(),h&&URL.revokeObjectURL(h)}},[e.data,e.fileName,e.mediaType,d,n,a,t]),l?E.jsxs("div",{role:"alert",className:"flex items-center gap-1 text-muted-foreground text-sm p-2 border rounded bg-muted",children:[E.jsx(jW,{className:"h-4 w-4"}),E.jsx("span",{children:l}),E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>i(p=>p+1),children:t("Retry")})]}):r?E.jsxs(aj,{children:[E.jsx(xve,{asChild:!0,children:E.jsx(Ye,{type:"button",variant:"ghost",className:"h-auto p-0","aria-label":t("Enlarge attachment"),children:E.jsx("img",{src:r,alt:t("Attachment"),className:"max-h-48 rounded border hover:opacity-80",onError:()=>c(t("Image not found"))})})}),E.jsxs(mI,{className:"max-w-[90vw] max-h-[90vh] overflow-auto",children:[E.jsx(gI,{children:t("Attachment")}),E.jsx(rj,{className:"sr-only",children:t("Enlarged attachment preview")}),E.jsx("img",{src:r,alt:t("Attachment"),className:"max-w-full max-h-[75vh] object-contain",onError:()=>c(t("Image not found"))})]})]}):E.jsx("span",{role:"status",children:t("Loading attachment...")})}var oj="[&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5 [&_pre]:my-2 [&_pre]:p-3 [&_pre]:bg-muted [&_pre]:rounded-md [&_pre]:overflow-x-auto [&_code]:text-[0.85em] [&_code]:px-1 [&_code]:py-0.5 [&_code]:rounded [&_code]:bg-muted [&_h1]:text-base [&_h1]:font-bold [&_h1]:my-2 [&_h2]:text-sm [&_h2]:font-semibold [&_h2]:my-2 [&_h3]:text-sm [&_h3]:font-medium [&_h3]:my-2 [&_a]:text-blue-600 [&_a]:underline dark:[&_a]:text-blue-400 [&_table]:border-collapse [&_th]:border [&_th]:border-border [&_th]:px-2 [&_th]:py-1 [&_th]:text-start [&_td]:border [&_td]:border-border [&_td]:px-2 [&_td]:py-1 [&_blockquote]:border-s-2 [&_blockquote]:border-border [&_blockquote]:ps-3 [&_blockquote]:text-muted-foreground [&_hr]:my-2 [&_hr]:border-border [&_pre_code]:bg-transparent [&_pre_code]:p-0";function Ove({commentId:e,reply:t}){const{t:n}=We(),{deleteReply:a}=Ws(),[i,r]=w.useState(!1);return i?E.jsx(sI,{commentId:e,existingReply:t,onCancel:()=>r(!1),onSubmit:()=>r(!1)}):E.jsxs("div",{className:"group/reply border-t border-border/50 pt-2","data-testid":`reply-${t.id}`,children:[E.jsxs("div",{className:"flex items-center justify-between px-3",children:[E.jsx("span",{className:"flex items-center gap-1 text-xs font-semibold text-foreground max-w-[200px] truncate",children:t.author?E.jsxs(E.Fragment,{children:[E.jsx(IP,{className:"h-3.5 w-3.5 shrink-0"}),t.author]}):E.jsxs(E.Fragment,{children:[E.jsx($P,{className:"h-3.5 w-3.5 shrink-0"}),n("You")]})}),E.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover/reply:opacity-100 focus-within:opacity-100 transition-opacity",children:[E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:()=>r(!0),"data-testid":`edit-reply-btn-${t.id}`,className:"h-6 w-6 p-0",children:[E.jsx(PP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:n("Edit reply")})]}),E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:()=>a(e,t.id),"data-testid":`delete-reply-btn-${t.id}`,className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",children:[E.jsx(UP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:n("Delete reply")})]})]})]}),E.jsx("div",{className:`px-3 pb-2 text-sm text-foreground leading-relaxed ${oj}`,children:E.jsx(Fb,{urlTransform:op,remarkPlugins:[jf,n0],rehypePlugins:[sp],components:{img:up},children:t.body})}),t.attachments&&t.attachments.length>0&&E.jsx("div",{className:"flex gap-2 flex-wrap px-3 pb-2",children:t.attachments.map(o=>E.jsx(sj,{attachment:o},o.id))})]})}var hI=2e3,Dve=1e5,Lve=1e3;function uj(){let e=0,t=0,n=!1;return{get limited(){return n},admit(a){return a.length>hI||e+a.length>Dve||t>=Lve?(n=!0,!1):(e+=a.length,t++,!0)}}}function lj(e){const t=new WeakSet,n=uj();for(const a of e.hunks)for(const i of a.lines)n.admit(i.content)&&t.add(i);return{lines:t,limited:n.limited}}var zF={"no-anchor":"A line range is required to apply this suggestion.","old-side-anchor":"Deleted lines cannot be applied to the working file.","invalid-anchor":"The suggestion has an invalid line range.","destination-not-absolute":"The destination must be an absolute path.","destination-missing":"The destination does not exist.","path-escapes-destination":"The file path is outside the destination.","control-file":"Git control files cannot be changed.","unsafe-target":"The destination file cannot be replaced safely.","unsupported-target":"Replacing the file would change its owner.","file-missing":"The file is missing from the destination.","file-unreadable":"The destination file could not be read.","file-not-utf8":"The destination file is not valid UTF-8.","anchor-out-of-range":"The line range is outside the destination file.","context-mismatch":"The original code no longer matches the destination.","file-changed":"The file changed while the suggestion was being applied.","write-failed":"The suggestion could not be written.","destination-required":"Choose a destination before applying this suggestion.","no-destination":"This review has no writable destination.","not-reviewed":"This file is not in the reviewed diff.","destination-not-a-directory":"The destination must be a directory.","destination-inside-temporary-clone":"Choose a destination outside the temporary clone.","request-rejected":"The host rejected the request before applying the proposal.","host-unavailable":"The destination could not be chosen."};function Mve(e){return Object.prototype.hasOwnProperty.call(zF,e)?zF[e]:void 0}var Fve=Bt.memo(function(t){const n=nI(),a=JSON.stringify([n?.sessionId,n?.snapshotId,t.filePath,t.lineRange,t.suggestion]);return E.jsx(Bve,{...t},a)});function Bve({filePath:e,lineRange:t,suggestion:n}){const{t:a}=We(),i=_i(),r=nI(),o=i?.applySuggestion,l=i?.chooseApplyDestination,c=TEe(JSON.stringify([e,t,n])),{outcome:d,pending:p,unknown:m}=c.state,[h,b]=w.useState(!1),y=F=>c.write({pending:!1,outcome:F,unknown:!1}),v=w.useRef(!1);w.useLayoutEffect(()=>(v.current=!0,()=>{v.current=!1}),[]);const T=()=>v.current&&(r?.isCurrentSession?.()??!0);if(!o)return null;if(r!==null&&r.diffSource.type!=="loading"&&r.diffSource.type!=="welcome"&&!r.reviewedPaths.has(e))return E.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-t border-border bg-muted/40 font-sans text-[11px] text-muted-foreground","data-testid":"suggestion-apply-unreviewed",children:[E.jsx($y,{className:"h-3 w-3 flex-shrink-0"}),E.jsx("span",{children:a("This file is not in the reviewed diff, so the suggestion cannot be applied.")})]});const A=d?.status==="applied",N=d?.status==="refused"?Mve(d.reason):void 0,x=N?a(N):void 0,I=r?.remote?.temporaryClone===!0&&r.applyDestination===null||d?.status==="refused"&&d.reason==="destination-required",O=I&&!!l,D=async()=>{try{if(!T())return;const F=await o({filePath:e,lineRange:t,suggestion:n});(r?.isCurrentSession?.()??v.current)&&y(F)}catch(F){if(!(r?.isCurrentSession?.()??v.current))return;F&&typeof F=="object"&&"uncertain"in F&&F.uncertain===!1?y({status:"refused",filePath:e,reason:"request-rejected",detail:a("The host rejected the request before applying the proposal.")}):c.write({pending:!1,outcome:null,unknown:!0})}},M=async()=>{if(!(c.read().pending||c.read().unknown||!T())){c.write({...c.read(),pending:!0});try{await D()}finally{(r?.isCurrentSession?.()??v.current)&&c.write({...c.read(),pending:!1})}}},B=async()=>{if(l&&!(c.read().pending||c.read().unknown||!T())){c.write({...c.read(),pending:!0});try{const F=await l();if(!T()||F.status==="cancelled")return;if(F.status==="rejected"){y({status:"refused",filePath:e,reason:F.reason,detail:F.detail});return}r?.setApplyDestination(F.destinationRoot),await D()}catch{if(!T())return;y({status:"refused",filePath:e,reason:"host-unavailable",detail:a("The destination could not be chosen.")})}finally{(r?.isCurrentSession?.()??v.current)&&c.write({...c.read(),pending:!1})}}};return E.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-1.5 border-t border-border bg-muted/40 font-sans text-[11px]","data-testid":"suggestion-apply",children:[m?E.jsxs("div",{role:"status","data-testid":"suggestion-apply-outcome","data-status":"unknown",children:[E.jsx("p",{children:a("The apply outcome is unknown. Inspect the destination file before allowing another attempt. Nothing is retried automatically.")}),E.jsxs("label",{children:[E.jsx("input",{type:"checkbox",checked:h,onChange:F=>b(F.target.checked)}),a("I inspected the destination file and confirmed this proposal was not applied.")]}),E.jsx(Ye,{variant:"outline",size:"sm",disabled:!h,onClick:()=>{c.write({pending:!1,outcome:null,unknown:!1}),b(!1)},children:a("Allow a separate retry")})]}):d?E.jsxs("span",{className:`flex items-start gap-1.5 ${A?"text-emerald-700 dark:text-emerald-400":"text-amber-700 dark:text-amber-400"}`,role:"status","data-testid":"suggestion-apply-outcome","data-status":d.status,"data-reason":d.status==="refused"?d.reason:void 0,children:[A?E.jsx(Jv,{className:"h-3 w-3 mt-px flex-shrink-0"}):E.jsx($y,{className:"h-3 w-3 mt-px flex-shrink-0"}),d.status==="applied"?E.jsx("span",{children:a("Applied suggestion",{path:d.filePath,count:d.replacedLines})}):E.jsxs("span",{children:[a("Not applied. {detail}",{detail:d.detail}),x&&x!==d.detail&&E.jsx("span",{className:"block",children:x})]})]}):E.jsx("span",{className:"text-muted-foreground",children:a(I?"This pull request was cloned into a temporary directory. Choose where to write it.":"Write the proposal into the working file.")}),!A&&!m&&E.jsxs(Ye,{variant:"outline",size:"sm",className:"h-6 shrink-0 px-2 text-[11px]",disabled:p,onClick:O?B:M,"data-testid":O?"suggestion-apply-choose-destination":"suggestion-apply-button",children:[p&&E.jsx(tk,{className:"h-3 w-3 animate-spin"}),!p&&O&&E.jsx(LP,{className:"h-3 w-3"}),a(p?"Applying…":O?"Choose destination…":"Apply")]})]})}function Pve({suggestion:e,language:t="typescript",filePath:n,lineRange:a=null}){const{t:i}=We(),r=uj(),o=(d,p)=>{if(!r.admit(d))return null;try{const m=Ao.languages[p]||Ao.languages.plaintext;return Ao.highlight(d,m,p)}catch{return null}},l=e.originalCode.split(`
304
+ `))return{width:t.getUint32(16),height:t.getUint32(20)};if(n.length>=10&&(a(0,"GIF87a")||a(0,"GIF89a")))return{width:t.getUint16(6,!0),height:t.getUint16(8,!0)};if(n.length>=26&&a(0,"BM")){const i=t.getUint32(14,!0)===12;return{width:i?t.getUint16(18,!0):Math.abs(t.getInt32(18,!0)),height:i?t.getUint16(20,!0):Math.abs(t.getInt32(22,!0))}}if(n.length>=6&&t.getUint32(0,!0)===65536){const i=t.getUint16(4,!0);if(!i||6+i*16>n.length)throw new No("format");let r=0,o=0;for(let l=6;l<6+i*16;l+=16)r=Math.max(r,n[l]||256),o=Math.max(o,n[l+1]||256);return{width:r,height:o}}if(n.length>=30&&a(0,"RIFF")&&a(8,"WEBP")){if(a(12,"VP8X"))return{width:1+n[24]+(n[25]<<8)+(n[26]<<16),height:1+n[27]+(n[28]<<8)+(n[29]<<16)};if(a(12,"VP8L")&&n[20]===47)return{width:1+n[21]+((n[22]&63)<<8),height:1+(n[22]>>6)+(n[23]<<2)+((n[24]&15)<<10)};if(a(12,"VP8 ")&&n[23]===157&&n[24]===1&&n[25]===42)return{width:t.getUint16(26,!0)&16383,height:t.getUint16(28,!0)&16383}}if(n[0]===255&&n[1]===216){let i=2;for(;i+4<=n.length&&n[i++]===255;){for(;n[i]===255;)i++;const r=n[i++];if(r===217||r===218||i+2>n.length)break;if(r===1||r>=208&&r<=216)continue;const o=t.getUint16(i);if(o<2||i+o>n.length)break;if(r>=192&&r<=207&&![196,200,204].includes(r)&&o>=7)return{width:t.getUint16(i+5),height:t.getUint16(i+3)};i+=o}}throw new No("format")}function OF(e,t){if(e<=0||t<=0||e>IF||t>IF||e*t>zEe)throw new No("dimensions")}async function VEe(e,t,n=1920){if(t?.throwIfAborted(),e.size>xF)throw new No("size");const a=qEe(await e.slice(0,GEe).arrayBuffer());OF(a.width,a.height),t?.throwIfAborted();const i=await createImageBitmap(e);try{if(t?.throwIfAborted(),OF(i.width,i.height),i.width<=n&&i.height<=n)return e;const r=Math.min(n/i.width,n/i.height),o=document.createElement("canvas");o.width=Math.round(i.width*r),o.height=Math.round(i.height*r);const l=o.getContext("2d");if(!l)throw new No("decode");l.drawImage(i,0,0,o.width,o.height);const c=await new Promise(d=>o.toBlob(d,e.type));if(t?.throwIfAborted(),!c||c.size>xF)throw new No("decode");return c}finally{i.close()}}async function YEe(e,t){const n=await VEe(e,t),a=await n.arrayBuffer();t?.throwIfAborted();const i=n.type||e.type||"image/png",r=i.split("/")[1]||"png";return{id:crypto.randomUUID(),fileName:`image.${r}`,mediaType:i,data:a}}var WEe=8,KEe=30*1024*1024;function iI({process:e=YEe,...t}){const n=uc(),a=nI(),i=w.useRef({...t,isCurrent:a?.isCurrentSession});i.current={...t,isCurrent:a?.isCurrentSession};const r=w.useMemo(()=>({controller:new AbortController,jobs:[],running:!1,nextId:0,delivered:[],activeJob:null}),[n,t.owner,t.signal,e]),o=w.useRef(r);o.current=r;const[l,c]=w.useState([]),[d,p]=w.useState(!1);w.useLayoutEffect(()=>{t.attachments&&(r.delivered=[])},[t.attachments,r]);const m=()=>o.current===r&&!r.controller.signal.aborted&&!t.signal?.aborted&&(i.current.isCurrent?.()??!0),h=()=>{m()&&(c([...r.jobs]),i.current.onWorkChange?.(r.jobs.length>0),i.current.onProcessingChange?.(r.jobs.some(S=>S.status!=="error")))};w.useLayoutEffect(()=>{r.controller.signal.aborted&&(r.controller=new AbortController),o.current=r,c([]),p(!1);const S=i.current;return()=>{r.jobs.length>0&&S.onAbort?.(),r.controller.abort(),r.jobs=[],r.running=!1,o.current===r&&(o.current=null),S.onProcessingChange?.(!1),S.onWorkChange?.(!1)}},[r]);const b=async()=>{if(r.running||!m())return;r.running=!0;const S=r.controller,A=()=>m()&&S===r.controller;try{let N;for(;A()&&(N=r.jobs.find(x=>x.status==="queued"));){const x=N.id;r.jobs=r.jobs.map(O=>O.id===x?{...O,status:"processing"}:O),h();const I=new AbortController;r.activeJob={id:x,controller:I};try{const O=await e(N.file,AbortSignal.any([S.signal,I.signal,...t.signal?[t.signal]:[]]));if(!A())return;if(!r.jobs.some(D=>D.id===x))continue;r.jobs=r.jobs.filter(D=>D.id!==x),r.delivered.push(O),i.current.onAttach([O])}catch(O){if(!A())return;r.jobs=r.jobs.map(D=>D.id===x?{...D,status:"error",error:O instanceof No?O.code:"decode"}:D)}finally{r.activeJob?.id===x&&(r.activeJob=null)}h()}}finally{S===r.controller&&(r.running=!1)}};return{enqueue:S=>{if(!m()||!S.length)return;const A=i.current.attachments??[],N=[...A,...r.delivered.filter(I=>!A.some(O=>O.id===I.id))],x=N.reduce((I,O)=>I+(O.data?.byteLength??0),0)+r.jobs.reduce((I,O)=>I+O.file.size,0)+S.reduce((I,O)=>I+O.size,0);if(N.length+r.jobs.length+S.length>WEe||x>KEe){p(!0);return}p(!1),r.jobs.push(...S.map(I=>({file:I,id:++r.nextId,status:"queued"}))),h(),b()},retry:S=>{m()&&(r.jobs=r.jobs.map(A=>A.id===S&&A.status==="error"?{...A,status:"queued",error:void 0}:A),h(),b())},dismiss:S=>{r.jobs=r.jobs.filter(A=>A.id!==S),r.activeJob?.id===S&&r.activeJob.controller.abort(),h()},jobs:l,selectionError:d,pending:l.some(S=>S.status!=="error")}}var NH=w.createContext(null),CH=()=>w.useContext(NH);function rI({ingestion:e}){const{t}=We(),n={size:"Image exceeds the 10 MiB file limit.",dimensions:"Image exceeds the 16 megapixel or 8192 pixel dimension limit.",format:"Use PNG, JPEG, GIF, WebP, BMP or ICO with a readable raster header.",decode:"Image could not be decoded."};return E.jsxs("div",{className:"px-3 text-xs",children:[e.selectionError&&E.jsx("p",{role:"alert",children:t("Choose at most {count} images totaling at most {size} MiB.",{count:8,size:30})}),e.jobs.map(a=>E.jsxs("div",{className:"flex items-center gap-2 py-1",children:[E.jsx("span",{role:a.status==="error"?"alert":"status",children:a.status==="error"?t("Attachment failed: {name}. {detail}",{name:"name"in a.file?a.file.name:t("Pasted image"),detail:t(n[a.error??"decode"])}):t("Preparing attachment: {name}",{name:"name"in a.file?a.file.name:t("Pasted image")})}),a.status==="error"&&E.jsx(Ye,{size:"sm",variant:"outline",onClick:()=>e.retry(a.id),children:t("Retry")}),E.jsx(Ye,{size:"sm",variant:"ghost",onClick:()=>e.dismiss(a.id),children:t("Dismiss")})]},a.id))]})}function XEe({onAttach:e,children:t,isDragging:n,onDragChange:a}){const{t:i}=We(),r=w.useRef(0),o=CH(),l=iI({onAttach:e}),d=(o??l).enqueue,p=w.useCallback(y=>{const T=Array.from(y.clipboardData.items).filter(A=>A.type.startsWith("image/"));if(T.length===0)return;y.preventDefault();const S=T.map(A=>A.getAsFile()).filter(A=>A!==null);S.length>0&&d(S)},[d]),m=w.useCallback(y=>{y.preventDefault(),r.current=0,a(!1);const v=Array.from(y.dataTransfer.files).filter(T=>T.type.startsWith("image/"));v.length!==0&&d(v)},[d,a]),h=w.useCallback(y=>{y.preventDefault(),r.current++,y.dataTransfer.types.includes("Files")&&a(!0)},[a]),b=w.useCallback(y=>{y.preventDefault(),r.current--,r.current===0&&a(!1)},[a]);return E.jsxs("div",{onPaste:p,onDrop:m,onDragOver:y=>y.preventDefault(),onDragEnter:h,onDragLeave:b,children:[n&&E.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-primary/10 backdrop-blur-[1px] rounded-lg pointer-events-none",children:E.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-primary",children:[E.jsx(MP,{className:"h-5 w-5"}),i("Drop image to attach")]})}),t,!o&&E.jsx(rI,{ingestion:l})]})}var ZEe=[[xU,"Add bold text (ctrl + b)"],[DU,"Add italic text (ctrl + i)"],[El],[PU,"Insert a quote (ctrl + q)"],[OU,"Insert code (ctrl + j)"],[LU,"Add a link (ctrl + l)"],[El],[MU,"Add unordered list (ctrl + shift + u)"],[FU,"Add ordered list (ctrl + shift + o)"],[BU,"Add checked list (ctrl + shift + c)"]];function RH({body:e,attachmentOwner:t,attachmentSignal:n,onAttachmentsAborted:a,onAttachmentWorkChange:i,onProcessingChange:r,onBodyChange:o,attachments:l,setAttachments:c,placeholder:d,headerLabel:p,onSubmit:m,testId:h,actionsRef:b,height:y=240,children:v}){const{t:T}=We(),S=w.useMemo(()=>ZEe.map(([B,F])=>({...B,buttonProps:F?{...B.buttonProps,"aria-label":T(F),title:T(F)}:B.buttonProps,icon:B.icon?Bt.cloneElement(B.icon,{"aria-hidden":!0,focusable:!1}):void 0})),[T]),A=W$(),N=w.useRef(null),[x,I]=w.useState(!1),O=jEe(e,o,N),D=w.useCallback(B=>{c(F=>[...F,...B])},[c]),M=iI({onAttach:D,attachments:l,owner:t,signal:n,onAbort:a,onWorkChange:i,onProcessingChange:r});return w.useEffect(()=>{N.current?.querySelector(".w-md-editor-text-input")?.focus()},[]),E.jsx(NH.Provider,{value:M,children:E.jsxs("div",{className:`rounded-lg border bg-card shadow-sm overflow-hidden relative ${x?"border-primary border-2":"border-foreground/15"}`,"data-testid":h,children:[E.jsx(XEe,{onAttach:D,isDragging:x,onDragChange:I,children:E.jsxs("div",{className:"p-1 relative","data-color-mode":A,ref:N,children:[E.jsx($U,{value:e,onChange:B=>o(B||""),preview:"edit",highlightEnable:!1,commands:S,extraCommands:p?[{name:"header-label",keyCommand:"header-label",render:()=>E.jsx(E.Fragment,{children:p})}]:[],textareaProps:{...O.textareaProps,placeholder:d,"aria-label":d,onKeyDown:B=>{if(!(B.nativeEvent.isComposing||B.keyCode===229)&&!O.onKeyDown(B)&&((B.ctrlKey||B.metaKey)&&B.key==="Enter"&&(B.preventDefault(),M.pending||m()),B.key==="Escape")){B.preventDefault();const F=b?.current;F?F.focus():B.target.blur()}},onPaste:void 0},height:y,className:"md-editor-comment"}),E.jsx(FEe,{popupId:O.popupId,isOpen:O.isOpen,results:O.results,selectedIndex:O.selectedIndex,position:O.position,onSelect:O.selectEmoji,onHover:O.setSelectedIndex})]})}),l.length>0&&E.jsxs("div",{className:"flex gap-2 flex-wrap px-3 py-2 border-t border-border/50",children:[l.map(B=>E.jsx(BEe,{attachment:B,onRemove:()=>c(F=>F.filter(G=>G.id!==B.id))},B.id)),E.jsx("span",{className:"self-center text-[11px] text-muted-foreground",children:T("images",{count:l.length})})]}),E.jsx(rI,{ingestion:M}),v]})})}function xH({setAttachments:e}){const{t}=We(),n=w.useRef(null),a=CH(),i=iI({onAttach:o=>e(l=>[...l,...o])}),r=a??i;return E.jsxs(E.Fragment,{children:[E.jsxs(Ye,{type:"button",variant:"ghost",size:"sm",onClick:()=>n.current?.click(),className:"h-7 gap-1.5 text-xs",children:[E.jsx(pK,{className:"h-3.5 w-3.5"}),t("Attach")]}),!a&&E.jsx(rI,{ingestion:i}),E.jsx("input",{ref:n,type:"file","aria-label":t("Attach"),hidden:!0,accept:"image/*",multiple:!0,className:"hidden",onChange:o=>{const l=Array.from(o.target.files||[]);l.length>0&&r.enqueue(l),o.target.value=""}})]})}var jv=w.forwardRef(({className:e,...t},n)=>E.jsx("textarea",{className:Wt("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));jv.displayName="Textarea";function QEe({originalCode:e,proposedCode:t,onProposedChange:n,onSubmit:a}){const{t:i}=We(),r=w.useId();return E.jsxs(E.Fragment,{children:[E.jsx(ha,{}),E.jsxs("div",{className:"p-3 space-y-2 bg-muted/20",children:[E.jsxs("div",{"data-testid":"suggestion-original",children:[E.jsx("label",{htmlFor:`${r}-original`,className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-1 block",children:i("Original")}),E.jsx(jv,{id:`${r}-original`,value:e,disabled:!0,className:"font-mono text-xs bg-muted/30 resize-none",rows:3})]}),E.jsxs("div",{"data-testid":"suggestion-proposed",children:[E.jsx("label",{htmlFor:`${r}-proposed`,className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-1 block",children:i("Suggested")}),E.jsx(jv,{id:`${r}-proposed`,value:t,onChange:o=>n(o.target.value),onKeyDown:o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&(o.preventDefault(),a())},placeholder:i("Enter your suggested code..."),className:"font-mono text-xs resize-y",rows:3})]})]})]})}function rp({filePath:e,lineRange:t,onCancel:n,onSubmit:a,existingComment:i,originalCode:r}){const{t:o}=We(),{addComment:l,editComment:c}=Ws(),p=Zx()?.find(F$)?.name??"",m=SH({filePath:e,lineRange:t,existingComment:i,originalCode:r},{body:i?.body??"",category:i?.category||p,showSuggestion:!!i?.suggestion,proposedCode:i?.suggestion?.proposedCode??"",attachments:i?.attachments??[]}),{content:{body:h,category:b,showSuggestion:y,proposedCode:v,attachments:T},setBody:S,setCategory:A,setShowSuggestion:N,setProposedCode:x,setAttachments:I}=m,O=m.draft.target??m.draft.location,D=O.originalCode,M=w.useRef(null),F=(h.trim().length>0||y&&!!D||T.length>0)&&b.length>0,G=()=>{if(!F||!m.current()||m.draft.pending||m.draft.interrupted)return;const W=y&&D?{originalCode:D,proposedCode:v}:null;O.existingComment?c(O.existingComment.id,{...m.draft.target?{lineRange:O.lineRange}:{},body:h,category:b,suggestion:W,attachments:T.length?T:void 0}):l(O.filePath,O.lineRange,h,b,W,T.length?T:void 0),m.clear(),a?.()},z=()=>{m.clear(),n()};return E.jsxs(RH,{attachmentOwner:m.draft.key,attachmentSignal:m.draft.controller.signal,onAttachmentsAborted:m.onAttachmentsAborted,onAttachmentWorkChange:m.onProcessingChange,body:h,onBodyChange:S,attachments:T,setAttachments:I,placeholder:o("Add your review comment... (paste or drop images here)"),headerLabel:O.lineRange?E.jsx("span",{className:"text-xs font-medium text-muted-foreground whitespace-nowrap",children:O.lineRange.start===O.lineRange.end?o("Comment on line {line}",{line:O.lineRange.start}):o("Comment on lines {start} to {end}",{start:O.lineRange.start,end:O.lineRange.end})}):void 0,onSubmit:G,testId:"comment-input",actionsRef:M,children:[E.jsx(_H,{editor:m}),y&&D&&E.jsx(QEe,{originalCode:D,proposedCode:v,onProposedChange:x,onSubmit:G}),E.jsx(ha,{}),E.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/10 outline-none","data-testid":"comment-actions",tabIndex:-1,ref:M,children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx(MEe,{value:b,onChange:A}),D&&E.jsxs(Ye,{type:"button",variant:y?"secondary":"ghost",size:"sm","data-testid":"add-suggestion-btn",onClick:()=>{!y&&v.length===0&&x(D),N(!y)},className:"h-7 gap-1.5 text-xs",children:[E.jsx(_W,{className:"h-3.5 w-3.5"}),o(y?"Remove suggestion":"Suggest")]}),E.jsx(xH,{setAttachments:I})]}),E.jsxs("div",{className:"flex items-center gap-1.5",children:[E.jsx("span",{className:"text-[10px] text-muted-foreground me-0.5",children:o("Esc to unfocus")}),E.jsx(Ye,{"data-testid":"cancel-comment-btn","data-hint-action":"cancel-comment",variant:"ghost",size:"sm",onClick:z,className:"h-7 text-xs",children:o("Cancel")}),E.jsxs(Ye,{"data-testid":"add-comment-btn","data-hint-action":"submit-comment",size:"sm",onClick:G,disabled:!F||m.draft.pending||m.draft.stale||m.draft.interrupted,className:"h-7 text-xs gap-1.5",children:[o(O.existingComment?"Update":"Comment"),E.jsxs("kbd",{className:"pointer-events-none inline-flex items-center rounded border border-current/20 px-1 font-mono text-[10px] font-medium opacity-60",children:[navigator.platform?.includes("Mac")?"⌘":"Ctrl","↵"]})]})]})]})]},m.draft.key)}var JEe=160;function sI({commentId:e,existingReply:t,onCancel:n,onSubmit:a}){const{t:i}=We(),{addReply:r,updateReply:o}=Ws(),l=SH({filePath:"",lineRange:null,commentId:e,existingReply:t},{body:t?.body??"",category:"",showSuggestion:!1,proposedCode:"",attachments:t?.attachments??[]}),{content:{body:c,attachments:d},setBody:p,setAttachments:m}=l,h=w.useRef(null),b=c.trim().length>0||d.length>0,y=()=>{!b||!l.current()||l.draft.pending||l.draft.interrupted||(t?o(e,t.id,{body:c,attachments:d.length?d:void 0}):r(e,c,void 0,d.length?d:void 0),l.clear(),a?.())},v=()=>{l.clear(),n()};return E.jsxs(RH,{attachmentOwner:l.draft.key,attachmentSignal:l.draft.controller.signal,onAttachmentsAborted:l.onAttachmentsAborted,onAttachmentWorkChange:l.onProcessingChange,body:c,onBodyChange:p,attachments:d,setAttachments:m,placeholder:i("Reply to this comment... (paste or drop images here)"),onSubmit:y,testId:"reply-input",actionsRef:h,height:JEe,children:[E.jsx(_H,{editor:l}),E.jsx(ha,{}),E.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/10 outline-none","data-testid":"reply-actions",tabIndex:-1,ref:h,children:[E.jsx("div",{className:"flex items-center gap-2",children:E.jsx(xH,{setAttachments:m})}),E.jsxs("div",{className:"flex items-center gap-1.5",children:[E.jsx("span",{className:"text-[10px] text-muted-foreground me-0.5",children:i("Esc to unfocus")}),E.jsx(Ye,{"data-testid":"cancel-reply-btn",variant:"ghost",size:"sm",onClick:v,className:"h-7 text-xs",children:i("Cancel")}),E.jsxs(Ye,{"data-testid":"add-reply-btn",size:"sm",onClick:y,disabled:!b||l.draft.pending||l.draft.stale||l.draft.interrupted,className:"h-7 text-xs gap-1.5",children:[i(t?"Update":"Reply"),E.jsxs("kbd",{className:"pointer-events-none inline-flex items-center rounded border border-current/20 px-1 font-mono text-[10px] font-medium opacity-60",children:[navigator.platform?.includes("Mac")?"⌘":"Ctrl","↵"]})]})]})]})]},l.draft.key)}function eye(){const t=w.useContext(Ba).drafts,n=w.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot),[a,i]=w.useState(null),{t:r}=We(),o=n.filter(nH);return o.length?E.jsx("section",{"aria-label":r("Unfinished drafts"),className:"fixed bottom-2 end-2 z-40 max-h-[30vh] max-w-lg overflow-auto rounded-lg border border-border bg-background p-2 space-y-2 shadow-lg",children:o.map(l=>E.jsxs("div",{children:[E.jsx("span",{children:r("Unfinished draft: {path}",{path:l.location.filePath||r("Reply")})})," ",!t.isMounted(l.key)&&E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>i(l.key),children:r("Continue draft")})," ",E.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>t.clear(l.key,l.token),children:r("Cancel draft")}),a===l.key&&E.jsx(CEe,{open:!0,onOpenChange:c=>{c||i(null)},children:E.jsxs(bH,{children:[E.jsxs(EH,{children:[E.jsx(yH,{children:r("Continue draft")}),E.jsx(vH,{children:r("Finish or cancel unfinished drafts before saving the review.")})]}),l.location.commentId?E.jsx(sI,{...l.location,commentId:l.location.commentId,onCancel:()=>i(null),onSubmit:()=>i(null)}):E.jsx(rp,{...l.location,onCancel:()=>i(null),onSubmit:()=>i(null)}),E.jsx(kH,{children:r("Close")})]})})]},l.key))}):null}function tye(){return E.jsxs(E.Fragment,{children:[E.jsx(NEe,{}),E.jsx(eye,{})]})}function nye(){let e=null;return{register(t){return e=t,()=>{e===t&&(e=null)}},expand:()=>e?.()}}var IH=w.createContext(null);function aye({children:e}){const[t]=w.useState(nye);return E.jsx(IH.Provider,{value:t,children:e})}var OH=()=>w.useContext(IH),DF=new WeakMap,iye=1;function rye(e){if(!e)return 0;let t=DF.get(e);return t===void 0&&(t=iye++,DF.set(e,t)),t}function DH(e){const t=_i(),n=[rye(t),e.initialFiles?"static":"adapter",e.initialSource?Bo(e.initialSource):""].join("|");return E.jsx(SEe,{initialCharacterShortcuts:e.initialCharacterShortcuts,children:E.jsx(sye,{...e,recovery:e.recovery===void 0?E.jsx(tye,{}):e.recovery,adapter:t})},n)}function sye({children:e,initialFiles:t,initialSource:n,initialComments:a,recovery:i,adapter:r}){const[o]=w.useState(()=>eEe(rH(J1e(t,n,Hv(r)),{type:"hydrate",comments:a})));w.useLayoutEffect(()=>()=>o.drafts.abortPending(),[o]);const l=pEe(o,r,t!==void 0,a,{files:t,source:n}),c=w.useSyncExternalStore(o.subscribe,()=>o.getSnapshot().snapshotId,()=>o.getSnapshot().snapshotId),{createId:d}=Kb(),p=w.useMemo(()=>y=>o.dispatch({type:"files",update:y}),[o]),m=w.useMemo(()=>mEe(p,d),[p,d]),h=w.useMemo(()=>hEe(o,l.controller,m),[o,l.controller,m,c]),b=w.useMemo(fH,[c]);return E.jsx(Ba.Provider,{value:o,children:E.jsx(Jx.Provider,{value:h,children:E.jsx(pH.Provider,{value:b,children:E.jsx(oye,{store:o,commands:h,recovery:i,retryLoad:l.retryLoad,retryResume:l.retryResume,children:E.jsx(aye,{children:e})})})})})}function oye({store:e,commands:t,retryLoad:n,retryResume:a,recovery:i,children:r}){const o=w.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot),{config:l}=Xx(),c=w.useContext(Qx);w.useLayoutEffect(()=>{o.identity&&!rr(o.diffSource)&&c?.(o.identity)},[c,o.identity,o.diffSource]);const d=w.useMemo(()=>l.showUntracked?o.allDiffFiles:o.allDiffFiles.filter(b=>!b.isUntracked),[o.allDiffFiles,l.showUntracked]),p=w.useMemo(()=>gEe(o.files),[o.files]),m=bEe(e,o,d,t,p,n,a),h=w.useMemo(()=>({loadError:o.loadError,resumeError:o.resumeError,retryLoad:n,retryResume:a}),[o.loadError,o.resumeError,n,a]);return E.jsx(Wb.Provider,{value:m,children:E.jsx(dH.Provider,{value:h,children:E.jsxs(yEe,{sessionId:o.sessionId,files:d,isLargePayload:o.isLargePayload,reviewFiles:o.files,children:[i,r]})})})}function Zb(){const e=w.useContext(Wb);if(!e)throw new Error("useReview must be used within ReviewProvider");return e}function kl(e){const t=w.useContext(Ba);if(!t)throw new Error("Session selection must be used within ReviewProvider");return w.useSyncExternalStore(t.subscribe,()=>e(t.getSnapshot()),()=>e(t.getSnapshot()))}function Qb(e){const t=w.useContext(Ba);if(!t)throw new Error("Session selection must be used within ReviewProvider");return w.useSyncExternalStore(t.subscribe,()=>e(t),()=>e(t))}function oI(e){return Qb(t=>t.getFile(e))}function uye(e){return Qb(t=>t.getDiffFile(e))}function lye(){return Qb(e=>e.getNavigation())}function cye(){return Qb(e=>e.getProgress())}function LH(){return kl(e=>e.diffSource)}function Jb(){return kl(e=>e.sessionId)}function uI(){return kl(e=>e.snapshotId)}function lc(){const e=kl(a=>a.allDiffFiles),{config:t}=Xx();return{diffFiles:w.useMemo(()=>t.showUntracked?e:e.filter(a=>!a.isUntracked),[e,t.showUntracked]),diffSource:LH(),diagnostics:kl(a=>a.diagnostics),isLargePayload:kl(a=>a.isLargePayload),sessionId:Jb()}}function dye(){const e=w.useContext(Ba);if(!e)throw new Error("Save transactions require ReviewProvider");const{now:t}=Kb(),{t:n}=We(),a=w.useRef(t);a.current=t;const i=w.useRef(!0);return w.useLayoutEffect(()=>(i.current=!0,()=>{i.current=!1}),[]),w.useMemo(()=>({begin(){const r=e.getSnapshot();if(e.drafts.hasWork())throw new X1e(n("Finish or cancel unfinished drafts before saving the review."));if(!i.current||rr(r.diffSource)||r.loadError!==null||r.resumeError!==null||r.resumePending)throw new Error("The current review has not finished loading.");const o=a.current().toISOString(),l=e.lockMutations();return{state:{timestamp:o,source:r.diffSource,files:r.files},current:()=>i.current&&e.ownsMutations(l)&&e.getSnapshot().sessionId===r.sessionId&&e.getSnapshot().snapshotId===r.snapshotId,unlock:()=>{e.unlockMutations(l)}}}}),[e,n])}function MH(e,t){return Array.from(e?.querySelectorAll(t)??[]).filter(n=>n.closest(".self-review")===e)}function yf(e,t){return MH(e,t)[0]??null}var lI=w.createContext(null);function cI(){const e=w.useContext(lI);if(!e)throw new Error("useDiffNavigationContext must be used within a DiffNavigationProvider");return e}function dI(){return w.useContext(lI)}function FH({children:e}){const[t,n]=w.useState(null),a=Ys(),i=w.useRef(new Map),r=w.useRef(new Map),o=w.useRef(null),l=w.useCallback(()=>{let b=null,y=0;i.current.forEach((v,T)=>{v.forEach(S=>{const A=r.current.get(S)??0;A>y&&(y=A,b=T)})}),n(b)},[]),c=w.useCallback((b,y)=>{let v=i.current.get(b);v||(v=new Set,i.current.set(b,v)),v.add(y),o.current?.observe(y)},[]),d=w.useCallback((b,y)=>{o.current?.unobserve(y),r.current.delete(y);const v=i.current.get(b);v?.delete(y),v?.size===0&&i.current.delete(b),l()},[l]),p=w.useCallback(b=>i.current.get(b)?.values().next().value??null,[]),m=w.useCallback(b=>{const y=typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;p(b)?.scrollIntoView({behavior:y?"instant":"smooth",block:"start"})},[p]);w.useEffect(()=>{const b=new IntersectionObserver(y=>{if(o.current!==b)return;const v=new Set(Array.from(i.current.values()).flatMap(T=>Array.from(T)));y.forEach(T=>{v.has(T.target)&&r.current.set(T.target,T.isIntersecting?T.intersectionRatio:0)}),l()},{root:yf(a,'[data-scroll-container="diff"]'),threshold:[0,.25,.5,.75,1],rootMargin:"-20% 0px -20% 0px"});return o.current=b,r.current.clear(),i.current.forEach(y=>y.forEach(v=>b.observe(v))),()=>{b.disconnect(),o.current===b&&(o.current=null),r.current.clear()}},[a,l]);const h=w.useMemo(()=>({activeFilePath:t,scrollToFile:m,registerFileElement:c,unregisterFileElement:d,getFileElement:p}),[t,m,c,d,p]);return E.jsx(lI.Provider,{value:h,children:e})}var fye=8e3,pye=120,mye=800,LF=12,gye=256,hye=64;function BH(e){if(e.length>fye)return!0;let t="",n=0,a=0,i="";for(let d=0;d<e.length;d++){const p=e[d];if(t){if(++a>512)return!0;if(p==="\\"){d++,i+=" ";continue}p===t&&(t=""),i+=" "}else if(p==='"'||p==="'"||p==="`")t=p,a=0,i+=" ";else{if("([{".includes(p)){if(++n>LF)return!0}else")]}".includes(p)&&(n=Math.max(0,n-1));i+=p}}const r=i.split(/[;\n\r]/).filter(d=>d.trim());if(r.length>pye)return!0;let o=0,l=0,c=0;for(const d of r){if(d.length>512||(/^\s*(subgraph|loop|alt|opt|par|critical|break|rect|box)\b/.test(d)?c++:/^\s*end\b/.test(d)&&(c=Math.max(0,c-1)),c>LF))return!0;const p=d.match(/[\p{L}\p{N}_]+|[^\s]/gu)??[];if(o+=p.length,/[<>]|--|\.\.|==/.test(d)){const m=d.match(/[\p{L}\p{N}_]+/gu)?.length??0;l+=Math.max(1,m*m)}if(o>mye||l>gye)return!0}return!1}var dh=5e4,MF=1e4,bye=["secure","securityLevel","startOnLoad","maxTextSize","maxEdges","suppressErrorRendering","themeCSS","fontFamily","altFontFamily","htmlLabels","dompurifyConfig"],Eye=8,wl=class extends Error{constructor(e){super(e),this.kind=e}};function yye(e){let t=Promise.resolve(),n=0;return{render(a){if(a.source.length>dh||BH(a.source))return Promise.reject(new wl("source"));if(a.signal.aborted)return Promise.reject(a.signal.reason);if(n>=Eye)return Promise.reject(new wl("busy"));n++;const i=t.then(()=>(a.signal.throwIfAborted(),e(a))).finally(()=>{n--});return t=i.catch(()=>{}),i}}}var vye=0;async function kye({source:e,theme:t,signal:n}){const a=t==="dark";n.throwIfAborted();const i=(await nq(async()=>{const{default:l}=await import("./mermaid.core-DQk_LOzK.js").then(c=>c.cb);return{default:l}},[],import.meta.url)).default;n.throwIfAborted(),i.initialize({startOnLoad:!1,securityLevel:"strict",secure:[...bye],theme:a?"dark":"default",htmlLabels:!1,maxTextSize:dh,maxEdges:hye,suppressErrorRendering:!0});const r=document.createElement("div");r.setAttribute("data-mermaid-sandbox",""),r.setAttribute("aria-hidden","true"),r.style.cssText="position:fixed;top:0;left:-100000px;width:1024px;height:1px;overflow:hidden;visibility:hidden;pointer-events:none;",document.body.appendChild(r);const o=()=>r.remove();n.addEventListener("abort",o,{once:!0});try{const{svg:l}=await i.render(`mermaid-${vye++}`,e,r);return n.throwIfAborted(),{svg:l}}finally{n.removeEventListener("abort",o),r.remove()}}var wye=yye(kye),PH=w.createContext(void 0),UH=w.createContext(wye);function Tye({previewRenderer:e,diagramRenderer:t,children:n}){const a=fI(),i=$H();return E.jsx(PH.Provider,{value:e??a,children:E.jsx(UH.Provider,{value:t??i,children:n})})}function fI(){return w.useContext(PH)}function $H(){return w.useContext(UH)}function Sye({adapter:e,config:t,initialConfig:n,initialOutputPath:a,children:i,previewRenderer:r,diagramRenderer:o,services:l,...c}){return E.jsx(M$,{adapter:e,children:E.jsx(sEe,{services:l,children:E.jsx(Z$,{initialConfig:n??t,initialOutputPath:a,children:E.jsx(j1e,{children:E.jsx(DH,{...c,children:E.jsx(FH,{children:E.jsx(Tye,{previewRenderer:r,diagramRenderer:o,children:E.jsx(AH,{children:i})})})})})})})})}function HH(e,t){const n=new Map,a=new Map;for(const r of e){const o=JSON.stringify([r.oldPath,r.newPath,r.changeType]),l=n.get(o)??0;n.set(o,l+1);const c=a.get(r)??[];c.push(`${o}:${l}`),a.set(r,c)}const i=new Map;return t.map(r=>({...r,entries:r.entries.map(o=>{const l=i.get(o.file)??0;return i.set(o.file,l+1),{...o,key:a.get(o.file)[l]}})}))}function FF(e){return e.newPath||e.oldPath}function jH(e,t,n){if(n==="flat"||!t||t.length===0)return e.length===0?[]:[{entries:e.map(l=>({file:l}))}];const a=new Map;e.forEach(l=>{const c=FF(l),d=a.get(c)??[];d.push(l),a.set(c,d)});const i=new Set,r=[];t.forEach((l,c)=>{const d=[];for(const p of l.files){const m=a.get(p.path);!m||i.has(p.path)||(i.add(p.path),m.forEach(h=>d.push({file:h,description:p.description})))}d.length!==0&&r.push({header:{name:l.name,rationale:l.rationale,implicit:l.implicit,groupIndex:c},entries:d})});const o=e.filter(l=>!i.has(FF(l))).map(l=>({file:l}));if(o.length>0){const l=r[r.length-1];l?.header?.implicit?l.entries.push(...o):r.push({header:{name:"Everything else",implicit:!0},entries:o})}return r}var zH=w.forwardRef(({className:e,type:t,...n},a)=>E.jsx("input",{type:t,className:Wt("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),ref:a,...n}));zH.displayName="Input";function _ye(e){return e?e.type==="addition"?"bg-emerald-50/70 dark:bg-emerald-900/40":e.type==="deletion"?"bg-red-50/70 dark:bg-red-900/40":"":""}function Aye(e){return e?e.type==="addition"?"bg-emerald-100/80 dark:bg-emerald-900/50":e.type==="deletion"?"bg-red-100/80 dark:bg-red-900/50":"bg-muted/30":"bg-muted/30"}function GH(e){let t=0,n=0;for(const a of e.hunks)for(const i of a.lines)i.type==="addition"&&t++,i.type==="deletion"&&n++;return{additions:t,deletions:n}}function zv(e){switch(e){case"added":return{label:"A",className:"bg-emerald-500/15 text-emerald-800 dark:text-emerald-400"};case"modified":return{label:"M",className:"bg-amber-500/15 text-amber-800 dark:text-amber-400"};case"deleted":return{label:"D",className:"bg-red-500/15 text-red-800 dark:text-red-400"};case"renamed":return{label:"R",className:"bg-blue-500/15 text-blue-700 dark:text-blue-400"};case"copied":return{label:"C",className:"bg-violet-500/15 text-violet-700 dark:text-violet-400"};default:return{label:"?",className:""}}}function Nye(e){const t=e.lastIndexOf("/");return t===-1?{dir:"",fileName:e}:{dir:e.slice(0,t+1),fileName:e.slice(t+1)}}function qH({path:e,className:t=""}){const{dir:n,fileName:a}=Nye(e);return E.jsxs("span",{className:`flex-1 min-w-0 flex font-mono text-xs leading-tight ${t}`,children:[n&&E.jsx("span",{className:"truncate text-muted-foreground",children:n}),E.jsx("span",{className:"truncate flex-shrink-0 max-w-full",children:a})]})}var Cye=Bt.memo(function({file:t,isActive:n,commentCount:a,viewed:i,guideDescription:r,onScrollToFile:o,onToggleViewed:l}){const{t:c,number:d}=We(),p=t.newPath||t.oldPath,m=GH(t),h=zv(t.changeType);return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs("div",{className:"flex items-center rounded-md",children:[E.jsxs(Ye,{variant:"ghost","data-testid":`file-entry-${p}`,"data-file-path":p,"aria-current":n?"true":void 0,onClick:()=>o(p),className:`h-auto min-w-0 flex-1 flex-col items-stretch text-start px-2 py-1.5 rounded-md transition-colors cursor-pointer ${n?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"}`,children:[E.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[E.jsx("span",{className:`change-type-badge flex-shrink-0 inline-flex items-center justify-center w-[18px] h-[18px] rounded-sm text-[10px] font-bold leading-none ${h.className}`,children:h.label}),E.jsx(qH,{path:p||c("Review-level comments")}),E.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m.additions>0&&E.jsxs("span",{className:"text-[10px] tabular-nums font-medium text-emerald-700 dark:text-emerald-400",children:["+",d(m.additions)]}),m.deletions>0&&E.jsxs("span",{className:"text-[10px] tabular-nums font-medium text-red-700 dark:text-red-400",children:["-",d(m.deletions)]}),a>0&&E.jsxs("span",{className:"inline-flex items-center gap-0.5 text-muted-foreground",children:[E.jsx(Qd,{className:"h-3 w-3"}),E.jsx("span",{className:"text-[10px] tabular-nums",children:d(a)})]})]})]}),r&&E.jsx("div",{className:"ps-6 pe-1 mt-1 text-[11px] leading-snug text-muted-foreground line-clamp-2","data-testid":`guide-file-description-${p}`,children:r})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",size:"icon","data-testid":`viewed-toggle-${p}`,type:"button","aria-label":c(i?"Mark as needs review: {path}":"Mark as done reviewing: {path}",{path:p}),"aria-pressed":i,onClick:b=>{b.stopPropagation(),l(p)},className:"inline-flex items-center justify-center h-5 w-5 rounded-sm hover:bg-accent/80 transition-colors cursor-pointer",children:i?E.jsx(kh,{className:"h-3.5 w-3.5 text-emerald-700 dark:text-emerald-400"}):E.jsx(DP,{className:"h-3.5 w-3.5 text-muted-foreground/60"})})}),E.jsx(Gt,{side:"right",children:c(i?"Mark as needs review":"Mark as done reviewing")})]})]})}),E.jsx(Gt,{side:"right",className:"max-w-sm",children:E.jsx("p",{className:"font-mono text-xs break-all",children:p})})]},p)}),Rye=Yv("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground shadow",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function wo({className:e,variant:t,...n}){return E.jsx("div",{className:Wt(Rye({variant:t}),e),...n})}var xye=Yv("inline-flex items-center justify-center whitespace-nowrap rounded-none text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[pressed]:bg-accent data-[pressed]:text-accent-foreground first:rounded-l-md last:rounded-r-md [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground"},size:{default:"h-9 px-3 min-w-9",sm:"h-8 px-2 min-w-8",lg:"h-10 px-3 min-w-10"}},defaultVariants:{variant:"default",size:"default"}}),VH=w.createContext({size:"default",variant:"default"}),vf=w.forwardRef(({className:e,type:t,variant:n,size:a,value:i,defaultValue:r,onValueChange:o,children:l,...c},d)=>{const p=i!=null?i?[i]:[]:void 0,m=r?[r]:void 0,h=w.useCallback(b=>{o&&o(b[0]||"")},[o]);return E.jsx(Jhe,{ref:d,multiple:!1,value:p,defaultValue:m,onValueChange:h,className:Wt("inline-flex -space-x-px rounded-md shadow-sm",e),...c,children:E.jsx(VH.Provider,{value:{variant:n,size:a},children:l})})});vf.displayName="ToggleGroup";var or=w.forwardRef(({className:e,children:t,variant:n,size:a,...i},r)=>{const o=w.useContext(VH);return E.jsx(obe,{ref:r,className:Wt(xye({variant:n||o.variant,size:a||o.size}),e),...i,children:t})});or.displayName="ToggleGroupItem";function Iye(){const{t:e,number:t}=We(),n=ip(),{updateConfig:a}=n,{diffFiles:i}=lc(),{expanded:r,setAllExpanded:o}=Xb(),l=i.map(m=>m.newPath||m.oldPath),c=l.length>0&&l.every(m=>r.get(m)),d=()=>o(!c,l),p=m=>{(m==="split"||m==="unified")&&a({diffView:m})};return E.jsxs("div",{className:"flex items-center gap-1",children:[E.jsxs(vf,{type:"single",variant:"outline",size:"sm",value:n.diffView,onValueChange:p,children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"split","data-testid":"view-mode-split",className:"h-5 w-5 p-0",children:[E.jsx(NW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:e("Split view")})]})}),E.jsx(Gt,{children:e("Side-by-side view")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"unified","data-testid":"view-mode-unified",className:"h-5 w-5 p-0",children:[E.jsx(AK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:e("Unified view")})]})}),E.jsx(Gt,{children:e("Unified view")})]})]}),E.jsx(ha,{orientation:"vertical",className:"h-4"}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",size:"icon","data-testid":"keyboard-shortcuts-btn","aria-label":e("Keyboard shortcuts"),className:"h-5 w-5 text-muted-foreground hover:text-foreground",children:E.jsx(FP,{className:"h-3.5 w-3.5"})})}),E.jsxs(Gt,{side:"right",className:"text-xs space-y-1 p-2",children:[E.jsx("div",{className:"font-medium mb-1",children:e("Keyboard Shortcuts")}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Find in page")}),E.jsx("kbd",{className:"font-mono",children:"Ctrl+F"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Comment on line")}),E.jsx("kbd",{className:"font-mono",children:"f"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Jump to file")}),E.jsx("kbd",{className:"font-mono",children:"g"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Scroll diffs")}),E.jsx("kbd",{className:"font-mono",children:"j/k"})]}),E.jsxs("div",{className:"flex justify-between gap-4",children:[E.jsx("span",{children:e("Cancel")}),E.jsx("kbd",{className:"font-mono",children:"Esc"})]})]})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",size:"icon","data-testid":c?"collapse-all-btn":"expand-all-btn",onClick:d,"aria-label":e(c?"Collapse all files":"Expand all files"),className:"h-5 w-5 text-muted-foreground hover:text-foreground",children:c?E.jsx(EW,{className:"h-3.5 w-3.5"}):E.jsx(vW,{className:"h-3.5 w-3.5"})})}),E.jsx(Gt,{children:e(c?"Collapse all files":"Expand all files")})]}),E.jsx(wo,{variant:"secondary",className:"h-5 px-1.5 text-[11px] font-normal tabular-nums rounded",children:t(i.length)})]})}function Oye(){const{t:e}=We(),{outputPathInfo:t,setOutputPathInfo:n}=X$(),a=_i(),i=async()=>{if(!a?.changeOutputPath)return;const r=await a.changeOutputPath();r&&n(r)};return E.jsx(E.Fragment,{children:t.resolvedOutputPath&&E.jsxs(E.Fragment,{children:[E.jsx(ha,{}),E.jsxs("div",{className:"px-3 py-2 space-y-1",children:[E.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[E.jsx("span",{className:"font-medium",children:e("Output:")}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(qH,{path:t.resolvedOutputPath,className:"cursor-default"})}),E.jsx(Gt,{side:"right",className:"max-w-sm",children:E.jsx("p",{className:"font-mono text-xs break-all",children:t.resolvedOutputPath})})]}),t.outputPathWritable?E.jsx(kh,{className:"h-3.5 w-3.5 text-green-500 shrink-0"}):E.jsx($y,{className:"h-3.5 w-3.5 text-red-500 shrink-0"}),a?.changeOutputPath&&E.jsx(Ye,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs ms-auto",onClick:i,children:e("Change...")})]}),!t.outputPathWritable&&E.jsx("p",{className:"text-xs text-red-500",children:e("Path not writable")})]})]})})}var BF=[{text:"text-indigo-600 dark:text-indigo-400",ring:"ring-indigo-500 dark:ring-indigo-400",dot:"bg-indigo-500 dark:bg-indigo-400",dotSoft:"bg-indigo-500/50 dark:bg-indigo-400/50",dotFaint:"bg-indigo-500/25 dark:bg-indigo-400/25",segment:"bg-indigo-500/35 dark:bg-indigo-400/35",stroke:"stroke-indigo-500 dark:stroke-indigo-400",strokeSoft:"stroke-indigo-500/45 dark:stroke-indigo-400/45",fill:"fill-indigo-500 dark:fill-indigo-400",fillText:"fill-indigo-600 dark:fill-indigo-400",numeralStroke:"rgb(99 102 241 / 0.34)"},{text:"text-teal-600 dark:text-teal-400",ring:"ring-teal-500 dark:ring-teal-400",dot:"bg-teal-500 dark:bg-teal-400",dotSoft:"bg-teal-500/50 dark:bg-teal-400/50",dotFaint:"bg-teal-500/25 dark:bg-teal-400/25",segment:"bg-teal-500/35 dark:bg-teal-400/35",stroke:"stroke-teal-500 dark:stroke-teal-400",strokeSoft:"stroke-teal-500/45 dark:stroke-teal-400/45",fill:"fill-teal-500 dark:fill-teal-400",fillText:"fill-teal-600 dark:fill-teal-400",numeralStroke:"rgb(20 184 166 / 0.34)"},{text:"text-amber-600 dark:text-amber-400",ring:"ring-amber-500 dark:ring-amber-400",dot:"bg-amber-500 dark:bg-amber-400",dotSoft:"bg-amber-500/50 dark:bg-amber-400/50",dotFaint:"bg-amber-500/25 dark:bg-amber-400/25",segment:"bg-amber-500/35 dark:bg-amber-400/35",stroke:"stroke-amber-500 dark:stroke-amber-400",strokeSoft:"stroke-amber-500/45 dark:stroke-amber-400/45",fill:"fill-amber-500 dark:fill-amber-400",fillText:"fill-amber-600 dark:fill-amber-400",numeralStroke:"rgb(245 158 11 / 0.34)"},{text:"text-rose-600 dark:text-rose-400",ring:"ring-rose-500 dark:ring-rose-400",dot:"bg-rose-500 dark:bg-rose-400",dotSoft:"bg-rose-500/50 dark:bg-rose-400/50",dotFaint:"bg-rose-500/25 dark:bg-rose-400/25",segment:"bg-rose-500/35 dark:bg-rose-400/35",stroke:"stroke-rose-500 dark:stroke-rose-400",strokeSoft:"stroke-rose-500/45 dark:stroke-rose-400/45",fill:"fill-rose-500 dark:fill-rose-400",fillText:"fill-rose-600 dark:fill-rose-400",numeralStroke:"rgb(244 63 94 / 0.34)"},{text:"text-sky-600 dark:text-sky-400",ring:"ring-sky-500 dark:ring-sky-400",dot:"bg-sky-500 dark:bg-sky-400",dotSoft:"bg-sky-500/50 dark:bg-sky-400/50",dotFaint:"bg-sky-500/25 dark:bg-sky-400/25",segment:"bg-sky-500/35 dark:bg-sky-400/35",stroke:"stroke-sky-500 dark:stroke-sky-400",strokeSoft:"stroke-sky-500/45 dark:stroke-sky-400/45",fill:"fill-sky-500 dark:fill-sky-400",fillText:"fill-sky-600 dark:fill-sky-400",numeralStroke:"rgb(14 165 233 / 0.34)"},{text:"text-violet-600 dark:text-violet-400",ring:"ring-violet-500 dark:ring-violet-400",dot:"bg-violet-500 dark:bg-violet-400",dotSoft:"bg-violet-500/50 dark:bg-violet-400/50",dotFaint:"bg-violet-500/25 dark:bg-violet-400/25",segment:"bg-violet-500/35 dark:bg-violet-400/35",stroke:"stroke-violet-500 dark:stroke-violet-400",strokeSoft:"stroke-violet-500/45 dark:stroke-violet-400/45",fill:"fill-violet-500 dark:fill-violet-400",fillText:"fill-violet-600 dark:fill-violet-400",numeralStroke:"rgb(139 92 246 / 0.34)"}],Dye={text:"text-muted-foreground",ring:"ring-muted-foreground/40",dot:"bg-muted-foreground/60",dotSoft:"bg-muted-foreground/40",dotFaint:"bg-muted-foreground/25",segment:"bg-muted-foreground/25",stroke:"stroke-muted-foreground/60",strokeSoft:"stroke-muted-foreground/50",fill:"fill-muted-foreground/60",fillText:"fill-muted-foreground",numeralStroke:"hsl(240 4% 46% / 0.3)"};function Us(e,t=!1){return t?Dye:BF[e%BF.length]}function Lye({index:e,implicit:t,complete:n=!1,surfaceClassName:a="bg-background",className:i=""}){const{number:r}=We(),o=Us(e,t),l=o.ring,c=n?t?"bg-muted-foreground/60 text-background":`${o.dot} text-white`:`${a} ${o.text}`;return E.jsx("span",{className:`flex h-[22px] w-[22px] shrink-0 items-center justify-center rounded-full ring-2 text-[10px] font-semibold leading-none ${l} ${c} ${i}`,"aria-hidden":"true",children:n?E.jsx(Jv,{className:"h-3 w-3"}):t?E.jsx(WW,{className:"h-3 w-3"}):r(e+1)})}function Mye(){const{t:e,number:t}=We(),{diffFiles:n}=lc(),a=lye(),{toggleViewed:i}=Ws(),{activeFilePath:r,scrollToFile:o}=cI(),{guide:l,mode:c}=au(),[d,p]=w.useState(""),m=w.useMemo(()=>{if(!d.trim())return n;const b=d.toLowerCase();return n.filter(y=>(y.newPath||y.oldPath).toLowerCase().includes(b))},[n,d]),h=w.useMemo(()=>HH(n,jH(m,l?.groups??null,c)),[n,m,l,c]);return E.jsxs("div",{className:"flex flex-col h-full","data-testid":"file-tree",children:[E.jsxs("div",{className:"px-3 pt-3 pb-2",children:[E.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[E.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:e("Changed files")}),E.jsx(Iye,{})]}),E.jsxs("div",{className:"relative",children:[E.jsx(vK,{className:"absolute start-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground pointer-events-none"}),E.jsx(zH,{type:"text",placeholder:e("Filter files..."),"aria-label":e("Filter files..."),value:d,onChange:b=>p(b.target.value),className:"h-7 ps-7 text-xs bg-background","data-testid":"file-search"})]})]}),E.jsx(ha,{}),E.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden p-1",children:[h.map((b,y)=>{const v=b.header?.groupIndex??y,S=(b.header?.groupIndex!==void 0?l?.groups[b.header.groupIndex]?.files.map(O=>O.path):void 0)??b.entries.map(({file:O})=>O.newPath||O.oldPath),A=b.header?S.filter(O=>a.get(O)?.viewed).length:0,N=b.entries.map(({file:O,description:D,key:M})=>{const B=O.newPath||O.oldPath;return E.jsx(Cye,{file:O,isActive:r===B,commentCount:a.get(B)?.commentCount??0,viewed:a.get(B)?.viewed??!1,guideDescription:D,onScrollToFile:o,onToggleViewed:i},M)});if(!b.header)return E.jsx(Bt.Fragment,{children:N},`section-${y}-flat`);const x=y===0,I=y===h.length-1;return E.jsxs("div",{className:"relative",children:[E.jsx("div",{className:`pointer-events-none absolute start-[18px] w-[2px] ${x?"top-[27px]":"top-0"} ${I?"bottom-2":"bottom-0"} ${b.header.implicit?"guide-route-dashed-v":Us(v).segment}`,"aria-hidden":"true"}),E.jsxs("div",{className:"px-2 pt-4 pb-1.5","data-testid":`guide-group-${b.header.name}`,children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx(Lye,{index:v,implicit:b.header.implicit,complete:S.length>0&&A===S.length,surfaceClassName:"bg-sidebar",className:"relative z-10"}),E.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-semibold text-foreground",children:b.header.implicit?e("Everything else"):b.header.name}),E.jsxs("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground",children:[t(A),"/",t(S.length)]})]}),b.header.rationale&&E.jsx("div",{className:"mt-1 ps-[30px] text-[11px] leading-snug text-muted-foreground",children:b.header.rationale})]}),E.jsx("div",{className:"ps-6",children:N})]},`section-${y}-${b.header.name}`)}),m.length===0&&E.jsx("div",{className:"text-center text-muted-foreground text-xs py-8",children:e(d?"No files match your search":"No files in diff")})]}),E.jsx(Oye,{})]})}function YH(e,t){return t==="added"||t==="deleted"?"unified":e}function Fye({sectionRef:e,effectiveViewMode:t,file:n,filePath:a,onCommentRange:i}){const[r,o]=w.useState(null),l=w.useMemo(()=>{const S=new Map;return n.hunks.forEach((A,N)=>{let x=1/0,I=-1/0,O=1/0,D=-1/0;for(const M of A.lines)M.oldLineNumber!==null&&(x=Math.min(x,M.oldLineNumber),I=Math.max(I,M.oldLineNumber)),M.newLineNumber!==null&&(O=Math.min(O,M.newLineNumber),D=Math.max(D,M.newLineNumber));for(const M of A.lines)M.oldLineNumber!==null&&S.set(`old-${M.oldLineNumber}`,{hunkIndex:N,minLine:x,maxLine:I}),M.newLineNumber!==null&&S.set(`new-${M.newLineNumber}`,{hunkIndex:N,minLine:O,maxLine:D})}),S},[n]),c=w.useMemo(()=>{if(t!=="unified")return null;const S=new Map;let A=0;return n.hunks.forEach((N,x)=>{for(const I of N.lines){const O=I.type==="deletion"?I.oldLineNumber:I.newLineNumber,D=I.type==="deletion"?"old":"new";S.set(A,{lineNumber:O,side:D,hunkIndex:x}),A++}}),S},[n,t]),d=w.useMemo(()=>{if(t!=="unified")return null;const S=[];let A=0;for(const N of n.hunks)S.push({min:A,max:A+N.lines.length-1}),A+=N.lines.length;return S},[n,t]),p=w.useRef(r);p.current=r;const m=w.useRef(l);m.current=l;const h=w.useRef(c);h.current=c;const b=w.useRef(d);b.current=d;const y=w.useRef(t);y.current=t;const v=w.useRef(i);v.current=i;const T=(S,A,N=!1)=>{if(N){const I=t==="unified"?n.hunks.flatMap(D=>D.lines)[S]:null,O=I?A==="old"?I.oldLineNumber:I.newLineNumber:S;O!=null&&i(O,O,A);return}const x={startLine:S,currentLine:S,side:A};p.current=x,o(x)};return w.useEffect(()=>{const S=N=>{const x=p.current;if(!x)return;let I=null;if(I=document.elementFromPoint(N.clientX,N.clientY)?.closest("[data-line-number]"),!(I&&!e.current?.contains(I))){if(!I&&e.current){const D=e.current.querySelectorAll("[data-line-number]");for(const M of D){const B=M.getBoundingClientRect();if(N.clientY>=B.top&&N.clientY<=B.bottom&&N.clientX>=B.left&&N.clientX<=B.right){I=M;break}}}if(I)if(y.current==="unified"){const D=I.getAttribute("data-row-index");if(!D)return;const M=parseInt(D,10);if(isNaN(M))return;const B=h.current,F=b.current;if(!B||!F)return;const G=B.get(x.startLine);if(!G)return;const z=F[G.hunkIndex],W=Math.max(z.min,Math.min(z.max,M));o(ie=>{const te=ie?{...ie,currentLine:W}:null;return p.current=te,te})}else{const D=parseInt(I.getAttribute("data-line-number"),10),M=I.getAttribute("data-line-side");if(!isNaN(D)&&M===x.side){const B=`${x.side}-${x.startLine}`,F=m.current.get(B);if(!F)return;const G=Math.max(F.minLine,Math.min(F.maxLine,D));o(z=>{const W=z?{...z,currentLine:G}:null;return p.current=W,W})}}}},A=()=>{const N=p.current;if(N){if(y.current==="unified"&&h.current){const x=Math.min(N.startLine,N.currentLine),I=Math.max(N.startLine,N.currentLine),O=h.current,D=[],M=[];for(let B=x;B<=I;B++){const F=O.get(B);F&&(F.side==="new"?D.push(F.lineNumber):M.push(F.lineNumber))}D.length>0?v.current(Math.min(...D),Math.max(...D),"new"):M.length>0&&v.current(Math.min(...M),Math.max(...M),"old")}else{const x=Math.min(N.startLine,N.currentLine),I=Math.max(N.startLine,N.currentLine);v.current(x,I,N.side)}p.current=null,o(null)}};return document.addEventListener("mousemove",S),document.addEventListener("mouseup",A),()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",A)}},[]),w.useEffect(()=>{const S=N=>{const{filePath:x,lineNumber:I,side:O}=N.detail;x===a&&(p.current||v.current(I,I,O))},A=e.current;return A?.addEventListener("trigger-line-comment",S),()=>A?.removeEventListener("trigger-line-comment",S)},[a]),{dragState:r,handleDragStart:T}}function Bye(e,t,n){const[a,i]=w.useState(null),[r,o]=w.useState(!1),l=w.useCallback((b,y,v)=>{i({start:Math.min(b,y),end:Math.max(b,y),side:v})},[]),c=w.useCallback(()=>i(null),[]),d=w.useCallback(()=>o(!1),[]),p=w.useCallback(()=>o(!0),[]),{dragState:m,handleDragStart:h}=Fye({sectionRef:t,effectiveViewMode:n,file:e,filePath:e.newPath||e.oldPath,onCommentRange:l});return{lineComments:{commentRange:a,onCancelComment:c,onCommentSaved:c},rawSelection:{dragState:m,onDragStart:h},onCommentRange:l,fileComment:{showingFileComment:r,openFileComment:p,closeFileComment:d}}}function Pye(e,t){const n=t.available?e.hunks.flatMap(l=>l.lines.map(c=>c.content)):[],[a,i]=w.useState(()=>({path:e.newPath||e.oldPath,content:n,binary:e.isBinary,changeType:e.changeType,kind:t.builtIn.kind,renderer:t.renderer,mode:t.defaultMode})),r=e.newPath||e.oldPath,o=a.path!==r||a.content.length!==n.length||a.content.some((l,c)=>l!==n[c])||a.binary!==e.isBinary||a.changeType!==e.changeType||a.kind!==t.builtIn.kind||a.renderer!==t.renderer;return o&&i({path:r,content:n,binary:e.isBinary,changeType:e.changeType,kind:t.builtIn.kind,renderer:t.renderer,mode:t.defaultMode}),{renderViewMode:o?t.defaultMode:a.mode,setRenderViewMode:l=>i(c=>({...c,mode:l}))}}function fh(e,t){const n=wH(e,t);return n?n.map(a=>a.content).join(`
305
+ `):void 0}function Uye(e){let t=1/0,n=-1/0,a=1/0,i=-1/0;for(const r of e.lines)r.type!=="context"&&(r.oldLineNumber!==null&&(t=Math.min(t,r.oldLineNumber),n=Math.max(n,r.oldLineNumber)),r.newLineNumber!==null&&(a=Math.min(a,r.newLineNumber),i=Math.max(i,r.newLineNumber)));return{oldRange:t<=n?[t,n]:null,newRange:a<=i?[a,i]:null}}function Gv(e){let t=0;for(const n of e.lines)if(n.type==="context")t++;else break;return t}function qv(e){let t=0;for(let n=e.lines.length-1;n>=0&&e.lines[n].type==="context";n--)t++;return t}function $ye(e,t){for(const n of e.lines)if(n.type!=="context"&&(t.oldRange&&n.oldLineNumber!==null&&n.oldLineNumber>=t.oldRange[0]&&n.oldLineNumber<=t.oldRange[1]||t.newRange&&n.newLineNumber!==null&&n.newLineNumber>=t.newRange[0]&&n.newLineNumber<=t.newRange[1]))return!0;return!1}function Hye(e,t,n){return e.map(a=>{const i=[];for(let S=0;S<t.length;S++)$ye(a,t[S])&&i.push(S);if(i.length===0)return a;const r=n[i[0]],o=n[i[i.length-1]],l=Gv(a),c=qv(a),d=Math.max(0,l-r.above),p=Math.max(0,c-o.below);if(d===0&&p===0)return a;const m=p>0?a.lines.length-p:a.lines.length,h=a.lines.slice(d,m);if(h.length===0)return a;let b=0,y=0;for(const S of h)(S.type==="context"||S.type==="deletion")&&b++,(S.type==="context"||S.type==="addition")&&y++;const v=a.oldStart+d,T=a.newStart+d;return{...a,lines:h,oldStart:v,newStart:T,oldLines:b,newLines:y,header:`@@ -${v},${b} +${T},${y} @@`}})}function jye(e,t,n,a,i,r){const o=n.map(h=>({...h})),l=e[i],c=h=>{const b=[];for(let y=0;y<t.length;y++){const v=t[y];for(const T of h.lines)if(T.type!=="context"){if(v.oldRange&&T.oldLineNumber!==null&&T.oldLineNumber>=v.oldRange[0]&&T.oldLineNumber<=v.oldRange[1]){b.push(y);break}if(v.newRange&&T.newLineNumber!==null&&T.newLineNumber>=v.newRange[0]&&T.newLineNumber<=v.newRange[1]){b.push(y);break}}}return b},d=5,p=99999;if(a==="up"){const h=c(l);h.length>0&&(o[h[0]].above+=d)}else if(a==="down"){const h=r==="bottom"?i:i-1,b=e[Math.max(0,h)],y=c(b);y.length>0&&(o[y[y.length-1]].below+=d)}else if(r==="top"){const h=c(l);h.length>0&&(o[h[0]].above=p)}else if(r==="bottom"){const h=c(l);h.length>0&&(o[h[h.length-1]].below=p)}else{const h=e[i-1],b=c(h);b.length>0&&(o[b[b.length-1]].below=p);const y=c(l);y.length>0&&(o[y[0]].above=p)}let m=0;for(const h of o)m=Math.max(m,h.above,h.below);return{budgets:o,maxBudget:m}}function zye(e,t,n,a){const i=t==="down"?Math.max(0,a==="bottom"?n:n-1):n,r=e[i]?.lines,o=t==="down"?r?.[r.length-1]:r?.[0];if(!o)return null;const l=o.type==="deletion"?"old":"new",c=l==="old"?o.oldLineNumber:o.newLineNumber;return c===null?null:{lineNumber:c,side:l}}function Gye(e,t,n){const a=w.useRef(null);return w.useLayoutEffect(()=>{const i=a.current;if(!i||(a.current=null,i.owner!==n))return;const r=e.current,o=r?.closest('[data-scroll-container="diff"]'),l=r?.querySelector(`[data-line-number="${i.lineNumber}"][data-line-side="${i.side}"]`);if(!l||!o)return;const c=l.getBoundingClientRect().top-o.getBoundingClientRect().top-i.offset;Math.abs(c)>1&&(o.scrollTop=i.scrollTop+c)},[t,n,e]),w.useMemo(()=>({clear:()=>{a.current=null},capture(i,r,o,l){a.current=null;const c=zye(i,r,o,l),d=e.current,p=d?.closest('[data-scroll-container="diff"]');if(!c||!p||!d)return;const m=d.querySelector(`[data-line-number="${c.lineNumber}"][data-line-side="${c.side}"]`);m&&(a.current={...c,owner:n,offset:m.getBoundingClientRect().top-p.getBoundingClientRect().top,scrollTop:p.scrollTop})}}),[n,e])}function qye({file:e,filePath:t,isExpandable:n,sectionRef:a,expanded:i=!0}){const{isCurrentSession:r,updateFileHunks:o}=Ws(),l=_i(),c=Jb(),d=uI(),[p,m]=w.useState(!1),[h,b]=w.useState(!1),[y,v]=w.useState(null),T=w.useRef(null),S=w.useRef(null),A=w.useRef(null),N=w.useRef(0),x=w.useMemo(()=>({}),[c,d,l,t]),I=w.useRef(x),O=w.useRef(null),D=w.useRef(i);D.current=i,w.useEffect(()=>()=>{O.current?.abort(),O.current=null,m(!1),G.current=!1},[x,i]);const M=w.useRef(!0);w.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]),I.current!==x&&(I.current=x,T.current=null,S.current=null,A.current=null,N.current=0,v(null),m(!1),b(!1)),T.current===null&&e.hunks.length>0&&(T.current=e.hunks.map(te=>Uye(te)),S.current=e.hunks.map(te=>({above:Gv(te),below:qv(te)})),N.current=Math.max(...e.hunks.flatMap(te=>[Gv(te),qv(te)]),0));const F=Gye(a,e.hunks,x),G=w.useRef(p);G.current=p;const z=w.useRef(e.hunks);z.current=e.hunks;const W=w.useRef(y);W.current=y;const ie=w.useCallback(async(te,K,ne)=>{if(!n||!D.current||G.current)return;b(!1);const Q=S.current,se=T.current;if(!Q||!se)return;const j=z.current,Y=jye(j,se,Q,te,K,ne);S.current=Y.budgets,F.capture(j,te,K,ne);const{maxBudget:oe}=Y,$=I.current,he=new AbortController;O.current=he;const Ne=()=>M.current&&D.current&&I.current===$&&!he.signal.aborted&&(r?.()??!0);G.current=!0,m(!0);let ke=null,be=W.current;if(oe>N.current||!A.current){let Ae=null;try{Ae=await uH(l,{filePath:t,contextLines:oe},he.signal)}catch{}if(!Ne())return;if(!Ae){b(!0),m(!1),G.current=!1,F.clear();return}ke=Ae.hunks,Ae.totalLines>0&&(be=Ae.totalLines),A.current=ke,N.current=oe}else ke=A.current;if(!Ne())return;const Ce=Hye(ke,se,Y.budgets);o(t,Ce),v(be),m(!1),G.current=!1},[n,t,l,r,o,F]);return{expandLoading:p,expandError:h,totalLines:y,handleExpandContext:ie}}var og={kind:"idle"};function Vye(e,t){return e instanceof Error&&e.message?e.message:typeof e=="string"&&e?e:t}function Yye({file:e,filePath:t,expanded:n}){const{t:a}=We(),{updateFileHunks:i}=Ws(),r=Jb(),o=uI(),l=_i(),c=w.useMemo(()=>({}),[e,r,o,l,t]),[d,p]=w.useState({owner:c,state:og}),m=d.owner===c?d.state:og,h=w.useRef(null),b=n&&e.contentLoaded===!1,y=w.useRef(0);w.useEffect(()=>()=>{y.current+=1,h.current?.abort(),h.current=null,p(T=>T.owner===c&&T.state.kind==="loading"?{owner:c,state:og}:T)},[c,b]),w.useEffect(()=>{if(!b||m.kind!=="idle")return;const T=x=>p({owner:c,state:x});if(!oEe(l)){T({kind:"error",message:a("this review host cannot load file content on demand")});return}const S=++y.current,A=new AbortController;h.current=A;const N=()=>S===y.current&&!A.signal.aborted;T({kind:"loading"}),uEe(l,t,A.signal).then(x=>{N()&&(x?(i(t,x),T({kind:"loaded"})):T({kind:"error",message:a("the review host returned no content for this file")}))},x=>{N()&&T({kind:"error",message:Vye(x,a("the request failed"))})})},[b,m.kind,c,t,l,i,a]);const v=w.useCallback(()=>{p(T=>T.owner===c&&T.state.kind==="error"?{owner:c,state:og}:T)},[c]);return{state:m,retry:v}}var Wye=new Set([".jpg",".jpeg",".png",".gif",".webp",".ico",".bmp"]),Kye=new Set([".md",".markdown"]),Xye=new Set([".html",".htm"]);function e0(e){const t=e.lastIndexOf(".");return t===-1||t===e.length-1?"":e.slice(t).toLowerCase()}function WH(e){return Wye.has(e0(e))}function Zye(e){return e0(e)===".svg"}function Qye(e){return Kye.has(e0(e))}function Jye(e){return Xye.has(e0(e))}function eve(e){return Qye(e)?"markdown":Jye(e)?"html":null}function KH(e){const t=e.split(".").pop()?.toLowerCase()||"",n={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",css:"css",json:"json",md:"markdown",markdown:"markdown",sh:"bash",bash:"bash",yml:"yaml",yaml:"yaml",java:"java",go:"go",rs:"rust",sql:"sql",html:"markup",htm:"markup",xml:"markup",rb:"ruby",php:"php",twig:"twig",c:"c",cpp:"cpp",h:"c",hpp:"cpp",ini:"ini",toml:"toml",csv:"csv",diff:"diff",patch:"diff",scss:"scss",sass:"sass",graphql:"graphql",gql:"graphql",conf:"nginx",mongodb:"mongodb",makefile:"makefile",mk:"makefile",mak:"makefile",vim:"vim",vimrc:"vim"},a=e.split("/").pop()?.toLowerCase()||"";return a==="dockerfile"||a.startsWith("dockerfile.")?"docker":a==="makefile"||a.startsWith("makefile.")?"makefile":a.startsWith(".git")?"git":a===".vimrc"||a.startsWith(".vim")?"vim":n[t]||"plaintext"}function tve(e){if(e.changeType!=="added")return{kind:"none"};const t=e.newPath||e.oldPath;if(e.isBinary&&WH(t))return{kind:"image"};if(Zye(t))return{kind:"svg"};const n=eve(t);return n?{kind:"text",mode:n}:{kind:"none"}}function nve(e){return e.kind==="image"||e.kind==="text"?"rendered":"raw"}function XH(e,t=null,n=tve(e)){const a=e.changeType==="added"&&t?.supports(e,n)?t:null;return{builtIn:n,renderer:a,available:n.kind!=="none"||a!==null,defaultMode:n.kind==="none"&&a?a.defaultMode??"raw":nve(n)}}function ave(e,t,n,a){const{expanded:i,setExpanded:r}=Xb(),o=n??i.get(e)??!1,l=w.useCallback(d=>{o!==d&&(a?a(e):r(e,d))},[o,a,e,r]),c=w.useRef(!1);return w.useEffect(()=>{c.current!==t&&l(!t),c.current=t},[t,l]),{expanded:o,changeExpanded:l}}async function ive(e,t){if(t?.writeClipboard)return t.writeClipboard(e);if(typeof navigator>"u"||!navigator.clipboard?.writeText)throw new Error("Clipboard unavailable");await navigator.clipboard.writeText(e)}function rve({bodyId:e,file:t,filePath:n,expanded:a,isViewed:i,isPreviewable:r,renderViewMode:o,commentCount:l,onToggle:c,onViewedToggle:d,onAddFileComment:p,onRenderViewModeChange:m}){const{t:h,number:b}=We(),{additions:y,deletions:v}=GH(t),T=t.changeType==="renamed"||t.changeType==="copied",S=T?`${t.oldPath} → ${t.newPath}`:n||h("Review-level comments"),A=zv(t.changeType).label==="?"?h("unknown"):h(t.changeType),N=w.useRef(null),[x,I]=w.useState(!1),[O,D]=w.useState(!1),[M,B]=w.useState(!1),F=_i(),G=uc(),z=w.useRef(0);w.useEffect(()=>(z.current++,D(!1),B(!1),()=>{z.current++}),[n,F,G]),w.useEffect(()=>{if(!O)return;const ie=setTimeout(()=>D(!1),1500);return()=>clearTimeout(ie)},[O]);const W=async()=>{const ie=T?t.newPath:n,te=++z.current;B(!1);try{if(await ive(ie,F),z.current!==te)return;D(!0)}catch{z.current===te&&B(!0)}};return w.useEffect(()=>{const ie=N.current;if(!ie)return;const te=new IntersectionObserver(([K])=>I(!K.isIntersecting),{threshold:0});return te.observe(ie),()=>te.disconnect()},[]),E.jsxs(E.Fragment,{children:[M&&E.jsx("p",{role:"alert",className:"px-3 text-sm text-destructive",children:h("The path could not be copied. Try again or copy it manually.")}),E.jsx("div",{ref:N,className:"h-0 w-0","aria-hidden":!0}),E.jsxs("div",{className:`sticky top-0 z-10 flex items-center gap-2 h-10 px-3 bg-muted/80 backdrop-blur-sm border-b border-border cursor-pointer select-none${x?"":" rounded-t-lg"}`,"data-testid":`file-header-${n}`,onClick:c,children:[E.jsxs(Ye,{variant:"ghost",className:"h-auto min-w-0 flex-1 justify-start gap-2 p-0 text-start","aria-expanded":a,"aria-controls":e,"aria-label":h(a?"Collapse {path}":"Expand {path}",{path:S}),onClick:ie=>{ie.stopPropagation(),c()},children:[E.jsx("span",{className:"text-muted-foreground","data-testid":"collapse-toggle",children:a?E.jsx(ek,{className:"h-4 w-4"}):E.jsx(gW,{className:"h-4 w-4"})}),E.jsx("span",{className:"font-mono text-[13px] font-medium truncate flex-1 min-w-0",children:S})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":`copy-file-path-${n}`,onClick:ie=>{ie.stopPropagation(),W()},className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",children:[O?E.jsx(Jv,{className:"h-3.5 w-3.5 text-emerald-700 dark:text-emerald-400"}):E.jsx(RW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:h("Copy file path")})]})}),E.jsx(Gt,{children:h(O?"Copied!":"Copy file path")})]}),E.jsx(wo,{variant:"secondary",className:`text-[10px] font-semibold px-1.5 py-0 h-5 ${zv(t.changeType).className}`,children:A}),E.jsxs("span",{className:"flex items-center gap-1 text-xs tabular-nums text-muted-foreground",children:[y>0&&E.jsxs("span",{className:"text-emerald-700 dark:text-emerald-400",children:["+",b(y)]}),v>0&&E.jsxs("span",{className:"text-red-700 dark:text-red-400",children:["-",b(v)]})]}),r&&E.jsxs(vf,{type:"single",value:o,onValueChange:ie=>ie&&m(ie),size:"sm",className:"h-6",onClick:ie=>ie.stopPropagation(),children:[E.jsx(or,{value:"raw","aria-label":h("Raw view"),className:"text-[10px] h-6 px-1.5",children:h("Raw")}),E.jsx(or,{value:"rendered","aria-label":h("Rendered view"),className:"text-[10px] h-6 px-1.5",children:h("Rendered")})]}),l>0&&E.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground tabular-nums",children:[E.jsx(Qd,{className:"h-3.5 w-3.5"}),b(l)]}),E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":`viewed-${n}`,"aria-pressed":i,"data-hint-action":"toggle-viewed","data-hint-file-path":n,onClick:ie=>{ie.stopPropagation(),d()},className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",children:[i?E.jsx(kh,{className:"h-3.5 w-3.5 text-emerald-700 dark:text-emerald-400"}):E.jsx(DP,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:h(i?"Done reviewing":"To review")})]})}),E.jsx(Gt,{children:h(i?"Mark as needs review":"Mark as done reviewing")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":`add-file-comment-${n}`,"data-hint-action":"add-file-comment","data-hint-file-path":n,onClick:ie=>{ie.stopPropagation(),p()},className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",children:[E.jsx(Qd,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:h("Add comment")})]})}),E.jsx(Gt,{children:h("Add file comment")})]})]})]})}var sve=new Set(["a","abbr","address","article","aside","b","bdi","bdo","blockquote","br","caption","cite","code","col","colgroup","dd","del","details","dfn","div","dl","dt","em","figcaption","figure","footer","h1","h2","h3","h4","h5","h6","header","hr","i","img","input","ins","kbd","li","main","mark","nav","ol","p","pre","q","rp","rt","ruby","s","samp","section","small","span","strong","sub","summary","sup","table","tbody","td","th","thead","time","tr","u","ul","var","wbr"]),ove=new Set(["className","title","lang","dir"]),uve={a:new Set(["href"]),img:new Set(["src","alt","width","height"]),input:new Set(["type","checked","disabled"]),ol:new Set(["start","reversed"]),li:new Set(["value"]),td:new Set(["align","colSpan","rowSpan"]),th:new Set(["align","colSpan","rowSpan","scope"]),col:new Set(["span"]),colgroup:new Set(["span"]),details:new Set(["open"]),time:new Set(["dateTime"])};function lve(e,t){return ove.has(t)||uve[e]?.has(t)===!0}var cve=/^language-[\w-]+$/;function dve(e){return(Array.isArray(e)?e:String(e??"").split(/\s+/)).map(String).filter(n=>cve.test(n))}function sp(){return e=>{function t(n){n.children=n.children.filter(a=>{if(a.type!=="element")return a.type==="text";if(!sve.has(a.tagName))return!1;for(const i of Object.keys(a.properties))lve(a.tagName,i)||delete a.properties[i];if("className"in a.properties){const i=dve(a.properties.className);i.length>0?a.properties.className=i:delete a.properties.className}if(a.tagName==="img"&&typeof a.properties.src=="string"){const i=a.properties.src;kf(i)||(QH(i)&&(a.properties["data-reviewed-image-source"]=i),delete a.properties.src)}return a.tagName==="input"&&(a.properties.type="checkbox",a.properties.disabled=!0),t(a),!0})}t(e)}}var fve=["href","src"];function ZH(e){for(const t of e.children)if(t.type==="element"){for(const n of fve)n in t.properties&&(t.properties[n]=op(String(t.properties[n]??""),n,t)??void 0);ZH(t)}}function pve(e){const t=yU(e,{fragment:!0});return sp()(t),ZH(t),t}function QH(e){const t=e.trim().replace(/[\t\r\n]/g,"");return!t||t.startsWith("//")||t.includes("\\")?!1:/^data:image\/(?:png|jpeg|gif|webp|bmp|x-icon|vnd\.microsoft\.icon|svg\+xml)[;,]/i.test(t)||/^blob:/i.test(t)?!0:!/^[a-z][a-z\d+.-]*:/i.test(t)}function kf(e){return QH(e)&&/^(?:data:image\/|blob:)/i.test(e.trim())}var op=(e,t,n)=>{if(n.tagName==="a"&&t==="href")return d7(e);if(n.tagName==="img"&&t==="src"&&kf(e))return e};function PF(e){for(const t of e)if(t.charCodeAt(0)<32||t.charCodeAt(0)===127)return!0;return!1}function mve(e,t){const n=e.trim();if(!n||PF(n)||n.includes("\\")||n.startsWith("//")||/^[a-z][a-z\d+.-]*:/i.test(n))return null;const a=n.split(/[?#]/,1)[0];if(!a)return null;const i=a.startsWith("/")?[]:t?.split("/").slice(0,-1)??[];if(i.some(r=>!r||r==="."||r===".."||r.includes("\\")))return null;try{for(const r of a.split("/")){const o=decodeURIComponent(r);if(PF(o)||o.includes("/")||o.includes("\\"))return null;if(!(!o||o==="."))if(o===".."){if(!i.length)return null;i.pop()}else i.push(o)}}catch{return null}return i.length?i.join("/"):null}var JH=w.createContext(void 0);function pI({documentPath:e,children:t}){return E.jsx(JH.Provider,{value:e,children:t})}function up({src:e,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,"data-reviewed-image-source":c}){const d={src:e,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,"data-reviewed-image-source":c},p=w.useContext(Ba);return p?E.jsx(gve,{...d,store:p}):E.jsx(hve,{...d})}var gve=w.memo(function({store:t,...n}){const a=()=>t.getSnapshot().allDiffFiles,i=w.useSyncExternalStore(t.subscribe,a,a),r=uc();return E.jsx(ej,{...n,files:i,snapshot:r})});function hve(e){const t=w.useContext(Wb),n=t?`${t.sessionId}:${t.snapshotId??""}`:"";return E.jsx(ej,{...e,files:t?.diffFiles,snapshot:n})}function ej({src:e,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,"data-reviewed-image-source":c,files:d,snapshot:p}){const{t:m}=We(),h=_i(),b=w.useContext(JH),[y,v]=w.useState(0),T=typeof e=="string"&&kf(e)?e:void 0,S=c?mve(c,b):null,A=!!(h?.reads?.loadImage||h?.loadImage),N=S&&WH(S)&&d?.filter(F=>F.newPath===S||F.oldPath===S).length===1,x=w.useMemo(()=>({}),[h,p,d,S,T,y]),[I,O]=w.useState(null),D=I?.request===x?I:null;w.useEffect(()=>{if(T||!S||!N||!A)return;const F=new AbortController;return oH(h,S,F.signal).then(G=>{F.signal.aborted||O({request:x,...G&&typeof G=="object"&&"dataUri"in G&&typeof G.dataUri=="string"&&kf(G.dataUri)?{url:G.dataUri}:{failed:!0}})},()=>{F.signal.aborted||O({request:x,failed:!0})}),()=>F.abort()},[h,S,N,A,T,x]);const M=D?.failed||!T&&(!N||!A),B=D?.failed?void 0:T??D?.url;return B?E.jsx("img",{src:B,alt:t,title:n,width:a,height:i,className:r,lang:o,dir:l,onError:()=>O({request:x,failed:!0})}):M?E.jsxs("span",{role:"alert","aria-label":m("Image preview unavailable"),title:n,children:[t&&E.jsxs("span",{children:[t,": "]}),m(!A&&!T?"Image loading not supported in this context.":"Failed to load image."),N&&A&&E.jsx(Ye,{variant:"ghost",size:"sm",onClick:()=>{O(null),v(F=>F+1)},children:m("Retry")})]}):E.jsx("span",{role:"status","aria-label":m("Loading image..."),children:t||m("Loading image...")})}var UF={critical:{className:"bg-red-500/15 text-red-800 dark:text-red-400",description:"Critical: data loss, a security hole, or a crash on a path real usage reaches."},major:{className:"bg-orange-500/15 text-orange-800 dark:text-orange-400",description:"Major: wrong behaviour or a broken contract on a path real usage reaches."},minor:{className:"bg-yellow-500/15 text-yellow-800 dark:text-yellow-400",description:"Minor: real but bounded. Behaviour is correct today."},info:{className:"bg-muted text-muted-foreground",description:"Info: no defect. Style, naming, a question, or a note."}},$F={high:{className:"bg-muted text-muted-foreground",description:"High confidence: traceable from the diff, no unverified assumption needed."},medium:{className:"bg-muted text-muted-foreground",description:"Medium confidence: rests on one assumption the author did not verify."},low:{className:"bg-amber-500/15 text-amber-800 dark:text-amber-400",description:"Low confidence: speculative. Worth your eyes, not worth acting on unattended."}};function HF({label:e,styles:t,testId:n}){const{t:a}=We();return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(wo,{variant:"secondary",className:`h-5 px-1.5 text-[10px] font-medium ${t?.className??"bg-muted text-muted-foreground"}`,"data-testid":n,children:e})}),E.jsx(Gt,{side:"bottom",children:a(t?.description??"Unknown signal")})]})}function bve({comment:e,contentId:t,isCollapsed:n,anchorFullyVisible:a,onEdit:i,onDelete:r,onToggleCollapse:o}){const{t:l}=We(),d=Zx()?.find(p=>p.name===e.category);return E.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:o,"aria-expanded":!n,"aria-controls":t,className:"h-5 w-5 p-0 -ms-1","data-testid":`comment-collapse-toggle-${e.id}`,children:[n?E.jsx(ek,{className:"h-3.5 w-3.5"}):E.jsx(OP,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:l(n?"Expand":"Collapse")})]}),E.jsx("span",{className:"flex items-center gap-1 text-xs font-semibold text-foreground max-w-[200px] truncate",children:e.author?E.jsxs(E.Fragment,{children:[E.jsx(IP,{className:"h-3.5 w-3.5 shrink-0"}),e.author]}):E.jsxs(E.Fragment,{children:[E.jsx($P,{className:"h-3.5 w-3.5 shrink-0"}),l("You")]})}),e.lineRange&&E.jsx("span",{className:"text-[11px] text-muted-foreground",children:e.lineRange.start===e.lineRange.end?l("line {line}",{line:e.lineRange.start}):l("lines {start}–{end}",{start:e.lineRange.start,end:e.lineRange.end})}),e.category&&(d?E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(wo,{variant:"secondary",className:"category-badge h-5 px-1.5 text-[10px] font-medium",style:{backgroundColor:`${d.color}20`,borderColor:d.color,borderWidth:"1px"},children:e.category})}),E.jsx(Gt,{side:"bottom",children:d.description})]}):E.jsx(wo,{variant:"secondary",className:"category-badge h-5 px-1.5 text-[10px] font-medium",style:{borderWidth:"1px"},children:e.category})),e.severity&&E.jsx(HF,{label:Object.prototype.hasOwnProperty.call(UF,e.severity)?l(e.severity):String(e.severity),styles:UF[e.severity],testId:`comment-severity-${e.severity}`}),e.confidence&&E.jsx(HF,{label:Object.prototype.hasOwnProperty.call($F,e.confidence)?l(`${e.confidence} confidence`):String(e.confidence),styles:$F[e.confidence],testId:`comment-confidence-${e.confidence}`}),e.orphaned&&E.jsx(wo,{variant:"secondary",className:"h-5 px-1.5 text-[10px] bg-orange-500/15 text-orange-800 dark:text-orange-400",children:l("Orphaned")}),e.lineRange&&!a&&E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(wo,{variant:"secondary",className:"h-5 px-1.5 text-[10px] bg-amber-500/15 text-amber-800 dark:text-amber-400","data-testid":"comment-anchor-partial",children:l("Partly hidden")})}),E.jsx(Gt,{side:"bottom",children:l("Some lines of this range are not in the loaded diff. The recorded original code is kept for its suggestion.")})]})]}),!n&&E.jsxs("div",{className:"flex gap-0.5",children:[E.jsx("div",{className:"opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:i,className:"h-6 w-6 p-0",children:[E.jsx(PP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:l("Edit")})]})}),E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:r,"data-hint-action":"delete-comment",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",children:[E.jsx(UP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:l("Delete")})]})]})]})}function Eve(e){const{deleteComment:t}=Ws(),{isCollapsed:n,setCollapsed:a}=eI(),[i,r]=w.useState(!1),[o,l]=w.useState(!1),c=n(e);return{isEditing:i,startEditing:()=>r(!0),finishEditing:()=>r(!1),isReplying:o,startReplying:()=>l(!0),finishReplying:()=>l(!1),isCollapsed:c,toggleCollapse:()=>a(e,!c),deleteThread:()=>t(e)}}var tj=(function(e){if(e==null)return wve;if(typeof e=="function")return t0(e);if(typeof e=="object")return Array.isArray(e)?yve(e):vve(e);if(typeof e=="string")return kve(e);throw new Error("Expected function, string, or object as test")});function yve(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=tj(e[n]);return t0(a);function a(...i){let r=-1;for(;++r<t.length;)if(t[r].apply(this,i))return!0;return!1}}function vve(e){const t=e;return t0(n);function n(a){const i=a;let r;for(r in e)if(i[r]!==t[r])return!1;return!0}}function kve(e){return t0(t);function t(n){return n&&n.type===e}}function t0(e){return t;function t(n,a,i){return!!(Tve(n)&&e.call(this,n,typeof a=="number"?a:void 0,i||void 0))}}function wve(){return!0}function Tve(e){return e!==null&&typeof e=="object"&&"type"in e}function Sve(e){return"\x1B[33m"+e+"\x1B[39m"}var nj=[],_ve=!0,jF=!1,Ave="skip";function Nve(e,t,n,a){let i;typeof t=="function"&&typeof n!="function"?(a=n,n=t):i=t;const r=tj(i),o=a?-1:1;l(e,void 0,[])();function l(c,d,p){const m=c&&typeof c=="object"?c:{};if(typeof m.type=="string"){const b=typeof m.tagName=="string"?m.tagName:typeof m.name=="string"?m.name:void 0;Object.defineProperty(h,"name",{value:"node ("+Sve(c.type+(b?"<"+b+">":""))+")"})}return h;function h(){let b=nj,y,v,T;if((!t||r(c,d,p[p.length-1]||void 0))&&(b=Cve(n(c,p)),b[0]===jF))return b;if("children"in c&&c.children){const S=c;if(S.children&&b[0]!==Ave)for(v=(a?S.children.length:-1)+o,T=p.concat(S);v>-1&&v<S.children.length;){const A=S.children[v];if(y=l(A,v,T)(),y[0]===jF)return y;v=typeof y[1]=="number"?y[1]:v+o}}return b}}}function Cve(e){return Array.isArray(e)?e:typeof e=="number"?[_ve,e]:e==null?nj:[e]}function Rve(e,t,n,a){let i,r,o;r=t,o=n,i=a,Nve(e,r,l,i);function l(c,d){const p=d[d.length-1],m=p?p.children.indexOf(c):void 0;return o(c,m,p)}}function n0(){return e=>{Rve(e,"text",(t,n,a)=>{if(a&&(a.type==="code"||a.type==="inlineCode"))return;const i=/:([a-z0-9_+-]+):/g;let r,o=0;const l=[];for(;(r=i.exec(t.value))!==null;){const c=$Ee(r[1]);c&&(r.index>o&&l.push({type:"text",value:t.value.slice(o,r.index)}),l.push({type:"text",value:c}),o=i.lastIndex)}l.length>0&&(o<t.value.length&&l.push({type:"text",value:t.value.slice(o)}),a&&typeof n=="number"&&a.children.splice(n,1,...l))})}}var aj=e0e,xve=n0e,Ive=i0e,ij=w.forwardRef(({className:e,...t},n)=>E.jsx(q7,{ref:n,className:Wt("fixed inset-0 z-50 bg-black/60 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));ij.displayName=q7.displayName;var mI=w.forwardRef(({className:e,children:t,...n},a)=>{const i=Ys(),{t:r}=We();return E.jsxs(Ive,{container:i,children:[E.jsx(ij,{}),E.jsxs(V7,{ref:a,className:Wt("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-lg",e),...n,children:[t,E.jsxs(f0e,{className:"absolute end-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none",children:[E.jsx(nk,{className:"h-4 w-4"}),E.jsx("span",{className:"sr-only",children:r("Close")})]})]})]})});mI.displayName=V7.displayName;var gI=w.forwardRef(({className:e,...t},n)=>E.jsx(W7,{ref:n,className:Wt("text-lg font-semibold",e),...t}));gI.displayName=W7.displayName;var rj=w.forwardRef(({className:e,...t},n)=>E.jsx(K7,{ref:n,className:Wt("text-sm text-muted-foreground",e),...t}));rj.displayName=K7.displayName;function sj({attachment:e}){const{t}=We(),n=uc(),[a,i]=w.useState(0),[r,o]=w.useState(null),[l,c]=w.useState(null),d=_i();return w.useEffect(()=>{let p=!0;const m=new AbortController;let h=null;o(null),c(null);const b=y=>{h=URL.createObjectURL(new Blob([y],{type:e.mediaType})),o(h)};return e.data?b(e.data):e.fileName&&(d?.reads?.readAttachment||d?.readAttachment)?lEe(d,e.fileName,m.signal).then(y=>{p&&(y?b(y):c(t("Image not found")))},y=>{p&&c(y instanceof Error?y.message:t("Image not found"))}):c(t("Image not found")),()=>{p=!1,m.abort(),h&&URL.revokeObjectURL(h)}},[e.data,e.fileName,e.mediaType,d,n,a,t]),l?E.jsxs("div",{role:"alert",className:"flex items-center gap-1 text-muted-foreground text-sm p-2 border rounded bg-muted",children:[E.jsx(jW,{className:"h-4 w-4"}),E.jsx("span",{children:l}),E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>i(p=>p+1),children:t("Retry")})]}):r?E.jsxs(aj,{children:[E.jsx(xve,{asChild:!0,children:E.jsx(Ye,{type:"button",variant:"ghost",className:"h-auto p-0","aria-label":t("Enlarge attachment"),children:E.jsx("img",{src:r,alt:t("Attachment"),className:"max-h-48 rounded border hover:opacity-80",onError:()=>c(t("Image not found"))})})}),E.jsxs(mI,{className:"max-w-[90vw] max-h-[90vh] overflow-auto",children:[E.jsx(gI,{children:t("Attachment")}),E.jsx(rj,{className:"sr-only",children:t("Enlarged attachment preview")}),E.jsx("img",{src:r,alt:t("Attachment"),className:"max-w-full max-h-[75vh] object-contain",onError:()=>c(t("Image not found"))})]})]}):E.jsx("span",{role:"status",children:t("Loading attachment...")})}var oj="[&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5 [&_pre]:my-2 [&_pre]:p-3 [&_pre]:bg-muted [&_pre]:rounded-md [&_pre]:overflow-x-auto [&_code]:text-[0.85em] [&_code]:px-1 [&_code]:py-0.5 [&_code]:rounded [&_code]:bg-muted [&_h1]:text-base [&_h1]:font-bold [&_h1]:my-2 [&_h2]:text-sm [&_h2]:font-semibold [&_h2]:my-2 [&_h3]:text-sm [&_h3]:font-medium [&_h3]:my-2 [&_a]:text-blue-600 [&_a]:underline dark:[&_a]:text-blue-400 [&_table]:border-collapse [&_th]:border [&_th]:border-border [&_th]:px-2 [&_th]:py-1 [&_th]:text-start [&_td]:border [&_td]:border-border [&_td]:px-2 [&_td]:py-1 [&_blockquote]:border-s-2 [&_blockquote]:border-border [&_blockquote]:ps-3 [&_blockquote]:text-muted-foreground [&_hr]:my-2 [&_hr]:border-border [&_pre_code]:bg-transparent [&_pre_code]:p-0";function Ove({commentId:e,reply:t}){const{t:n}=We(),{deleteReply:a}=Ws(),[i,r]=w.useState(!1);return i?E.jsx(sI,{commentId:e,existingReply:t,onCancel:()=>r(!1),onSubmit:()=>r(!1)}):E.jsxs("div",{className:"group/reply border-t border-border/50 pt-2","data-testid":`reply-${t.id}`,children:[E.jsxs("div",{className:"flex items-center justify-between px-3",children:[E.jsx("span",{className:"flex items-center gap-1 text-xs font-semibold text-foreground max-w-[200px] truncate",children:t.author?E.jsxs(E.Fragment,{children:[E.jsx(IP,{className:"h-3.5 w-3.5 shrink-0"}),t.author]}):E.jsxs(E.Fragment,{children:[E.jsx($P,{className:"h-3.5 w-3.5 shrink-0"}),n("You")]})}),E.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover/reply:opacity-100 focus-within:opacity-100 transition-opacity",children:[E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:()=>r(!0),"data-testid":`edit-reply-btn-${t.id}`,className:"h-6 w-6 p-0",children:[E.jsx(PP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:n("Edit reply")})]}),E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:()=>a(e,t.id),"data-testid":`delete-reply-btn-${t.id}`,className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",children:[E.jsx(UP,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:n("Delete reply")})]})]})]}),E.jsx("div",{className:`px-3 pb-2 text-sm text-foreground leading-relaxed ${oj}`,children:E.jsx(Fb,{urlTransform:op,remarkPlugins:[jf,n0],rehypePlugins:[sp],components:{img:up},children:t.body})}),t.attachments&&t.attachments.length>0&&E.jsx("div",{className:"flex gap-2 flex-wrap px-3 pb-2",children:t.attachments.map(o=>E.jsx(sj,{attachment:o},o.id))})]})}var hI=2e3,Dve=1e5,Lve=1e3;function uj(){let e=0,t=0,n=!1;return{get limited(){return n},admit(a){return a.length>hI||e+a.length>Dve||t>=Lve?(n=!0,!1):(e+=a.length,t++,!0)}}}function lj(e){const t=new WeakSet,n=uj();for(const a of e.hunks)for(const i of a.lines)n.admit(i.content)&&t.add(i);return{lines:t,limited:n.limited}}var zF={"no-anchor":"A line range is required to apply this suggestion.","old-side-anchor":"Deleted lines cannot be applied to the working file.","invalid-anchor":"The suggestion has an invalid line range.","destination-not-absolute":"The destination must be an absolute path.","destination-missing":"The destination does not exist.","path-escapes-destination":"The file path is outside the destination.","control-file":"Git control files cannot be changed.","unsafe-target":"The destination file cannot be replaced safely.","unsupported-target":"Replacing the file would change its owner.","file-missing":"The file is missing from the destination.","file-unreadable":"The destination file could not be read.","file-not-utf8":"The destination file is not valid UTF-8.","anchor-out-of-range":"The line range is outside the destination file.","context-mismatch":"The original code no longer matches the destination.","file-changed":"The file changed while the suggestion was being applied.","write-failed":"The suggestion could not be written.","destination-required":"Choose a destination before applying this suggestion.","no-destination":"This review has no writable destination.","not-reviewed":"This file is not in the reviewed diff.","destination-not-a-directory":"The destination must be a directory.","destination-inside-temporary-clone":"Choose a destination outside the temporary clone.","request-rejected":"The host rejected the request before applying the proposal.","host-unavailable":"The destination could not be chosen."};function Mve(e){return Object.prototype.hasOwnProperty.call(zF,e)?zF[e]:void 0}var Fve=Bt.memo(function(t){const n=nI(),a=JSON.stringify([n?.sessionId,n?.snapshotId,t.filePath,t.lineRange,t.suggestion]);return E.jsx(Bve,{...t},a)});function Bve({filePath:e,lineRange:t,suggestion:n}){const{t:a}=We(),i=_i(),r=nI(),o=i?.applySuggestion,l=i?.chooseApplyDestination,c=TEe(JSON.stringify([e,t,n])),{outcome:d,pending:p,unknown:m}=c.state,[h,b]=w.useState(!1),y=F=>c.write({pending:!1,outcome:F,unknown:!1}),v=w.useRef(!1);w.useLayoutEffect(()=>(v.current=!0,()=>{v.current=!1}),[]);const T=()=>v.current&&(r?.isCurrentSession?.()??!0);if(!o)return null;if(r!==null&&r.diffSource.type!=="loading"&&r.diffSource.type!=="welcome"&&!r.reviewedPaths.has(e))return E.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-t border-border bg-muted/40 font-sans text-[11px] text-muted-foreground","data-testid":"suggestion-apply-unreviewed",children:[E.jsx($y,{className:"h-3 w-3 flex-shrink-0"}),E.jsx("span",{children:a("This file is not in the reviewed diff, so the suggestion cannot be applied.")})]});const A=d?.status==="applied",N=d?.status==="refused"?Mve(d.reason):void 0,x=N?a(N):void 0,I=r?.remote?.temporaryClone===!0&&r.applyDestination===null||d?.status==="refused"&&d.reason==="destination-required",O=I&&!!l,D=async()=>{try{if(!T())return;const F=await o({filePath:e,lineRange:t,suggestion:n});(r?.isCurrentSession?.()??v.current)&&y(F)}catch(F){if(!(r?.isCurrentSession?.()??v.current))return;F&&typeof F=="object"&&"uncertain"in F&&F.uncertain===!1?y({status:"refused",filePath:e,reason:"request-rejected",detail:a("The host rejected the request before applying the proposal.")}):c.write({pending:!1,outcome:null,unknown:!0})}},M=async()=>{if(!(c.read().pending||c.read().unknown||!T())){c.write({...c.read(),pending:!0});try{await D()}finally{(r?.isCurrentSession?.()??v.current)&&c.write({...c.read(),pending:!1})}}},B=async()=>{if(l&&!(c.read().pending||c.read().unknown||!T())){c.write({...c.read(),pending:!0});try{const F=await l();if(!T()||F.status==="cancelled")return;if(F.status==="rejected"){y({status:"refused",filePath:e,reason:F.reason,detail:F.detail});return}r?.setApplyDestination(F.destinationRoot),await D()}catch{if(!T())return;y({status:"refused",filePath:e,reason:"host-unavailable",detail:a("The destination could not be chosen.")})}finally{(r?.isCurrentSession?.()??v.current)&&c.write({...c.read(),pending:!1})}}};return E.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-1.5 border-t border-border bg-muted/40 font-sans text-[11px]","data-testid":"suggestion-apply",children:[m?E.jsxs("div",{role:"status","data-testid":"suggestion-apply-outcome","data-status":"unknown",children:[E.jsx("p",{children:a("The apply outcome is unknown. Inspect the destination file before allowing another attempt. Nothing is retried automatically.")}),E.jsxs("label",{children:[E.jsx("input",{type:"checkbox",checked:h,onChange:F=>b(F.target.checked)}),a("I inspected the destination file and confirmed this proposal was not applied.")]}),E.jsx(Ye,{variant:"outline",size:"sm",disabled:!h,onClick:()=>{c.write({pending:!1,outcome:null,unknown:!1}),b(!1)},children:a("Allow a separate retry")})]}):d?E.jsxs("span",{className:`flex items-start gap-1.5 ${A?"text-emerald-700 dark:text-emerald-400":"text-amber-700 dark:text-amber-400"}`,role:"status","data-testid":"suggestion-apply-outcome","data-status":d.status,"data-reason":d.status==="refused"?d.reason:void 0,children:[A?E.jsx(Jv,{className:"h-3 w-3 mt-px flex-shrink-0"}):E.jsx($y,{className:"h-3 w-3 mt-px flex-shrink-0"}),d.status==="applied"?E.jsx("span",{children:a("Applied suggestion",{path:d.filePath,count:d.replacedLines})}):E.jsxs("span",{children:[a("Not applied. {detail}",{detail:d.detail}),x&&x!==d.detail&&E.jsx("span",{className:"block",children:x})]})]}):E.jsx("span",{className:"text-muted-foreground",children:a(I?"This pull request was cloned into a temporary directory. Choose where to write it.":"Write the proposal into the working file.")}),!A&&!m&&E.jsxs(Ye,{variant:"outline",size:"sm",className:"h-6 shrink-0 px-2 text-[11px]",disabled:p,onClick:O?B:M,"data-testid":O?"suggestion-apply-choose-destination":"suggestion-apply-button",children:[p&&E.jsx(tk,{className:"h-3 w-3 animate-spin"}),!p&&O&&E.jsx(LP,{className:"h-3 w-3"}),a(p?"Applying…":O?"Choose destination…":"Apply")]})]})}function Pve({suggestion:e,language:t="typescript",filePath:n,lineRange:a=null}){const{t:i}=We(),r=uj(),o=(d,p)=>{if(!r.admit(d))return null;try{const m=Ao.languages[p]||Ao.languages.plaintext;return Ao.highlight(d,m,p)}catch{return null}},l=e.originalCode.split(`
306
306
  `).map(d=>({line:d,html:o(d,t)})),c=e.proposedCode.split(`
307
307
  `).map(d=>({line:d,html:o(d,t)}));return E.jsxs("div",{className:"rounded-md border border-border overflow-hidden text-xs font-mono","data-testid":"suggestion-block",children:[E.jsx("div",{className:"flex items-center h-7 px-3 bg-muted text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:i("Suggested change")}),r.limited&&E.jsx("p",{role:"status",className:"px-3 py-1 font-sans text-muted-foreground",children:i("Highlighting is limited for this suggestion. All code remains available.")}),E.jsxs("div",{children:[l.map(({line:d,html:p},m)=>E.jsxs("div",{className:"suggestion-deletion flex bg-red-50/70 dark:bg-red-900/35 leading-[20px]",children:[E.jsx("span",{className:"inline-flex items-center justify-center w-7 flex-shrink-0 select-none text-red-500 dark:text-red-400 font-bold text-[11px]",children:"-"}),E.jsx("span",{className:"flex-1 text-foreground/80 whitespace-pre",dangerouslySetInnerHTML:p===null?void 0:{__html:p},children:p===null?d:void 0})]},`old-${m}`)),c.map(({line:d,html:p},m)=>E.jsxs("div",{className:"suggestion-addition flex bg-emerald-50/70 dark:bg-emerald-900/35 leading-[20px]",children:[E.jsx("span",{className:"inline-flex items-center justify-center w-7 flex-shrink-0 select-none text-emerald-500 dark:text-emerald-400 font-bold text-[11px]",children:"+"}),E.jsx("span",{className:"flex-1 text-foreground/80 whitespace-pre",dangerouslySetInnerHTML:p===null?void 0:{__html:p},children:p===null?d:void 0})]},`new-${m}`))]}),n!==void 0&&E.jsx(Fve,{filePath:n,lineRange:a,suggestion:e})]})}function ph({comment:e,originalCode:t,anchorFullyVisible:n=!0}){const{t:a}=We(),i=w.useId(),{isEditing:r,startEditing:o,finishEditing:l,isReplying:c,startReplying:d,finishReplying:p,isCollapsed:m,toggleCollapse:h,deleteThread:b}=Eve(e.id),y=t??e.suggestion?.originalCode;return r?E.jsx(rp,{filePath:e.filePath,lineRange:e.lineRange,onCancel:l,onSubmit:l,existingComment:e,originalCode:y}):E.jsxs("div",{className:"rounded-lg border border-foreground/15 bg-card text-sm group shadow-sm","data-testid":`comment-${e.id}`,children:[E.jsx(bve,{comment:e,contentId:i,isCollapsed:m,anchorFullyVisible:n,onEdit:o,onDelete:b,onToggleCollapse:h}),E.jsx(pI,{documentPath:e.filePath||void 0,children:E.jsxs("div",{id:i,hidden:m,children:[E.jsx("div",{className:`px-3 pb-3 text-sm text-foreground leading-relaxed ${oj}`,children:E.jsx(Fb,{urlTransform:op,remarkPlugins:[jf,n0],rehypePlugins:[sp],components:{img:up},children:e.body})}),e.suggestion&&E.jsx("div",{className:"px-3 pb-3",children:E.jsx(Pve,{suggestion:e.suggestion,language:"typescript",filePath:e.filePath,lineRange:e.lineRange})}),e.attachments&&e.attachments.length>0&&E.jsx("div",{className:"flex gap-2 flex-wrap px-3 pb-3",children:e.attachments.map(v=>E.jsx(sj,{attachment:v},v.id))}),e.replies&&e.replies.length>0&&E.jsx("div",{className:"ms-4 border-s-2 border-border/60","data-testid":`thread-${e.id}`,children:e.replies.map(v=>E.jsx(Ove,{commentId:e.id,reply:v},v.id))}),c?E.jsx("div",{className:"ms-4 px-3 pb-3 pt-2",children:E.jsx(sI,{commentId:e.id,onCancel:p,onSubmit:p})}):E.jsx("div",{className:"px-3 pb-3",children:E.jsxs(Ye,{variant:"ghost",size:"sm",onClick:d,"data-testid":`reply-btn-${e.id}`,className:"h-7 gap-1.5 text-xs text-muted-foreground",children:[E.jsx(hK,{className:"h-3.5 w-3.5"}),a("Reply")]})})]})})]})}function Uve({omittedReason:e,contentLoaded:t,contentLoad:n,onRetry:a,children:i}){const{t:r}=We();return e?E.jsxs("div",{role:"status","data-testid":"content-omitted",className:"m-3 flex items-start gap-2 text-sm text-muted-foreground p-3 border rounded",children:[E.jsx(Jd,{className:"h-4 w-4 mt-0.5 shrink-0","aria-hidden":"true"}),E.jsx("p",{className:"min-w-0 flex-1 break-words",children:e})]}):n.kind==="loading"||n.kind==="idle"&&t===!1?E.jsxs("div",{role:"status",className:"flex items-center justify-center py-12 text-sm text-muted-foreground",children:[E.jsx(tk,{className:"h-4 w-4 animate-spin me-2"}),r("Loading file content...")]}):n.kind==="error"?E.jsxs("div",{role:"alert","data-testid":"content-load-error",className:"m-3 flex items-start gap-2 text-destructive text-sm p-3 border border-destructive/20 rounded",children:[E.jsx(Jd,{className:"h-4 w-4 mt-0.5 shrink-0","aria-hidden":"true"}),E.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[E.jsx("p",{children:r("The content of this file could not be loaded.")}),E.jsx("p",{className:"text-xs text-muted-foreground break-words",children:n.message}),E.jsx("p",{className:"text-xs text-muted-foreground",children:r("Nothing will be requested again until you retry. If the review host stopped, restart it and then retry.")})]}),E.jsx(Ye,{variant:"outline",size:"sm",onClick:a,children:r("Retry")})]}):i}function $ve(e){const t=e.split(`
308
308
  `);if(t.length===0||t[0].trim()!=="---")return null;let n=-1;for(let i=1;i<t.length;i++)if(t[i].trim()==="---"){n=i;break}if(n===-1)return null;const a=t.slice(1,n).join(`
309
309
  `);try{const i=C1e(a),r=i!==null&&typeof i=="object"&&!Array.isArray(i)?i:{},o=n+1,l=t.slice(o).join(`
310
310
  `);return{metadata:r,body:l,lineOffset:o}}catch{return null}}var Hve=16,jve=2e3,ug=class extends Error{constructor(e){super(`front matter exceeds display limits: ${e}`),this.reason=e}};function zve(e){const t=new WeakSet;let n=0;function a(r,o){return Object.entries(r).map(([l,c])=>[l,i(c,o)])}function i(r,o){if(o>Hve)throw new ug("depth");if(n+=1,n>jve)throw new ug("nodes");if(r===null)return{kind:"null"};if(typeof r!="object")return{kind:"scalar",text:String(r)};if(t.has(r))throw new ug("cycle");t.add(r);try{return Array.isArray(r)?{kind:"list",items:r.map(l=>i(l,o+1))}:{kind:"map",entries:a(r,o+1)}}finally{t.delete(r)}}try{return t.add(e),{ok:!0,entries:a(e,1)}}catch(r){if(r instanceof ug)return{ok:!1,reason:r.reason};throw r}}var bI=w.forwardRef(({className:e,...t},n)=>E.jsx("div",{className:"relative w-full overflow-auto",children:E.jsx("table",{ref:n,className:Wt("w-full caption-bottom text-sm",e),...t})}));bI.displayName="Table";var Gve=w.forwardRef(({className:e,...t},n)=>E.jsx("thead",{ref:n,className:Wt("[&_tr]:border-b",e),...t}));Gve.displayName="TableHeader";var EI=w.forwardRef(({className:e,...t},n)=>E.jsx("tbody",{ref:n,className:Wt("[&_tr:last-child]:border-0",e),...t}));EI.displayName="TableBody";var qve=w.forwardRef(({className:e,...t},n)=>E.jsx("tfoot",{ref:n,className:Wt("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));qve.displayName="TableFooter";var yI=w.forwardRef(({className:e,...t},n)=>E.jsx("tr",{ref:n,className:Wt("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...t}));yI.displayName="TableRow";var vI=w.forwardRef(({className:e,...t},n)=>E.jsx("th",{ref:n,className:Wt("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...t}));vI.displayName="TableHead";var kI=w.forwardRef(({className:e,...t},n)=>E.jsx("td",{ref:n,className:Wt("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...t}));kI.displayName="TableCell";var Vve=w.forwardRef(({className:e,...t},n)=>E.jsx("caption",{ref:n,className:Wt("mt-4 text-sm text-muted-foreground",e),...t}));Vve.displayName="TableCaption";var Yve={cycle:"Front matter too complex to display: it refers to itself. The document body is shown below.",depth:"Front matter too complex to display: it is nested too deeply. The document body is shown below.",nodes:"Front matter too complex to display: it has too many values. The document body is shown below."};function Vv(e,t){switch(e.kind){case"null":return E.jsx("span",{className:"italic text-muted-foreground",children:t("null")});case"scalar":return E.jsx("span",{children:e.text});case"list":return E.jsx("ul",{className:"m-0 list-disc pl-5",children:e.items.map((n,a)=>E.jsx("li",{children:Vv(n,t)},a))});case"map":return E.jsx(bI,{className:"mt-1",children:E.jsx(EI,{children:e.entries.map(([n,a])=>E.jsxs(yI,{children:[E.jsx(vI,{className:"font-medium",children:n}),E.jsx(kI,{children:Vv(a,t)})]},n))})})}}function Wve({metadata:e}){const{t}=We(),n=w.useMemo(()=>zve(e),[e]);return n.ok&&n.entries.length===0?null:E.jsxs("div",{className:"not-prose",children:[n.ok?E.jsx(bI,{children:E.jsx(EI,{children:n.entries.map(([a,i])=>E.jsxs(yI,{children:[E.jsx(vI,{className:"font-bold w-[120px]",children:a}),E.jsx(kI,{children:Vv(i,t)})]},a))})}):E.jsx("div",{role:"note","data-testid":"front-matter-fallback",className:"text-sm text-muted-foreground p-2 border border-border rounded",children:"reason"in n&&t(Yve[n.reason])}),E.jsx(ha,{className:"my-6"})]})}function Kve(e){const t=[];let n=1;for(const a of e.hunks)for(const i of a.lines){if(i.type!=="addition")continue;const r=i.newLineNumber??n;t.push({lineNumber:r,content:i.content}),n=r+1}return t}function Xve(e){return e.map(t=>t.content).join(`
311
- `)}function Zve(e,t){return t[e-1]?.lineNumber??e}function cj({label:e,onStartDrag:t,onActivate:n,className:a,onKeyDown:i,...r}){return E.jsx(Ye,{...r,type:"button",variant:"ghost",size:"icon","aria-label":e,"data-comment-gutter":!0,className:`h-[22px] w-7 p-0 text-blue-600 dark:text-blue-400 focus-visible:opacity-100 ${a??""}`,onMouseDown:o=>{o.button===0&&(o.preventDefault(),o.stopPropagation(),(t??n)())},onClick:o=>{o.stopPropagation(),o.detail===0&&n()},onKeyDown:o=>{i?.(o),!(o.defaultPrevented||r.disabled)&&(o.key!=="Enter"&&o.key!==" "||(o.preventDefault(),o.stopPropagation(),n()))},children:null})}function dj(e){return`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(e)))}`}var GF="http://www.w3.org/2000/svg";function Qve(e){if(e.length>1e6)throw new wl("size");const t=new DOMParser().parseFromString(e,"image/svg+xml"),n=t.documentElement;if(!n||t.getElementsByTagName("parsererror").length>0||n.namespaceURI!==GF||n.localName!=="svg")throw new wl("svg");const a=(n.getAttribute("viewBox")??"").trim().split(/[\s,]+/).map(Number),[,,i,r]=a.length===4?a:[],o=i!==void 0&&i>0&&r!==void 0&&r>0;if(o&&(!Number.isFinite(i)||!Number.isFinite(r)||i>16384||r>16384||i*r>64e6))throw new wl("size");const l=(c,d)=>Array.from(n.children).find(p=>p.namespaceURI===GF&&p.localName===c)?.textContent?.trim().slice(0,d)||void 0;return{title:l("title",1e3),description:l("desc",4e3),src:dj(e),width:o?Math.ceil(i):void 0,height:o?Math.ceil(r):void 0}}function Jve({code:e}){const[t,n]=w.useState({status:"pending"}),[a,i]=w.useState(0),r=W$(),o=w.useId(),l=$H(),{t:c}=We();return w.useEffect(()=>{if(e.length>dh){n({status:"error",message:c("Diagram source is too large ({count} characters; the limit is {limit})",{count:e.length,limit:dh})});return}if(BH(e)){n({status:"error",message:c("Diagram exceeds the layout complexity limits. Read the source below.")});return}let d=!1;const p=new AbortController,m=b=>{d||(d=!0,n(b))};n({status:"pending"});const h=window.setTimeout(()=>{m({status:"error",message:c("Rendering timed out after {seconds} seconds. Synchronous layout cannot be interrupted.",{seconds:MF/1e3})}),p.abort()},MF);return Promise.resolve().then(()=>l.render({source:e,theme:r,signal:p.signal})).then(({svg:b})=>m({status:"rendered",image:Qve(b)})).catch(b=>m({status:"error",message:b instanceof wl?c(b.kind==="svg"?"The diagram did not render to a well-formed SVG image":b.kind==="busy"?"Too many diagrams are waiting. Retry after another diagram finishes.":"Diagram output exceeds the image size limit."):c("Failed to render diagram. {detail}",{detail:b instanceof Error?b.message:String(b)})})).finally(()=>window.clearTimeout(h)),()=>{d=!0,p.abort(),window.clearTimeout(h)}},[e,r,a,c,l]),t.status==="error"?E.jsxs("div",{"data-testid":"mermaid-error",className:"text-sm p-2 border border-destructive/20 rounded",children:[E.jsx("p",{role:"alert",className:"text-destructive",children:c("Mermaid error: {detail}",{detail:t.message})}),E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>i(d=>d+1),children:c("Retry")}),E.jsxs("details",{open:!0,children:[E.jsx("summary",{children:c("Diagram source")}),E.jsx("pre",{className:"overflow-auto whitespace-pre-wrap",children:e})]})]}):t.status==="pending"?E.jsx("div",{role:"status",className:"animate-pulse bg-muted p-2 h-32 rounded",children:c("Rendering diagram...")}):E.jsxs("figure",{className:"mermaid-block max-w-full rounded-lg border border-border bg-white dark:bg-muted/20 p-4",children:[E.jsx("div",{className:"flex justify-center overflow-x-auto",children:E.jsx("img",{src:t.image.src,alt:t.image.title??c("Mermaid diagram"),"aria-describedby":t.image.description?o:void 0,width:t.image.width,height:t.image.height,style:{maxWidth:"100%",height:"auto"}})}),E.jsxs("figcaption",{className:"mt-2 text-sm",children:[t.image.description&&E.jsx("p",{id:o,children:t.image.description}),E.jsxs("details",{children:[E.jsx("summary",{children:c("Diagram source")}),E.jsx("pre",{className:"overflow-auto whitespace-pre-wrap",children:e})]})]})]})}function fj({className:e,children:t,node:n,...a}){const i=/language-(\w+)/.exec(e||""),r=i?i[1]:"",o=String(t).replace(/\n$/,""),l=n?.position;if(r==="mermaid"&&l)return E.jsx(Jve,{code:o});if(o.length<=hI&&r&&Ao.languages[r]){const c=Ao.highlight(o,Ao.languages[r],r);return E.jsx("code",{className:e,dangerouslySetInnerHTML:{__html:c},...a})}return E.jsx("code",{className:e,...a,children:t})}var xy=w.createContext(!1),pj=w.createContext(null);function mj(){const e=w.useContext(pj);if(!e)throw new Error("Rendered blocks must be rendered inside RenderedMarkdownView");return e}var eke=new Set(["p","h1","h2","h3","h4","h5","h6","blockquote","pre","li","details"]),tke=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),nke=["p","h1","h2","h3","h4","h5","h6","ul","ol","li","blockquote","pre","table","hr","details"],gj=["address","article","aside","blockquote","details","div","dl","figcaption","figure","footer","h1","h2","h3","h4","h5","h6","header","hr","li","main","nav","ol","p","pre","section","table","ul"],ake=new Set(gj),ike=new Set(["article","aside","div","footer","header","main","nav","section"]);function rke(e){return e.children.some(t=>t.type==="element"&&ake.has(t.tagName))}function ske({startLine:e,endLine:t,children:n,tag:a,className:i,tagProps:r}){const{t:o,number:l}=We(),{commentRange:c,onGutterMouseDown:d}=mj();if(w.useContext(xy)||e===void 0||t===void 0)return E.jsx(a,{className:i,...r,children:n});const m=e===t?`${l(e)}`:`${l(e)}-${l(t)}`,h=tke.has(a),b=eke.has(a),y=b?"span":"div",v=E.jsxs(y,{className:"rendered-gutter absolute start-0 top-0 w-16 text-end pe-2 select-none cursor-pointer text-[11px] text-muted-foreground/70",style:{lineHeight:"inherit"},onMouseDown:A=>{A.preventDefault(),A.stopPropagation(),d(e,t)},children:[E.jsx(cj,{className:"absolute start-0 top-0 h-[1lh] opacity-0 group-hover/rendered-block:opacity-100",label:e===t?o("Comment on line {line}",{line:e}):o("Comment on lines {start} to {end}",{start:e,end:t}),onActivate:()=>d(e,t)}),E.jsx("span",{className:"pointer-events-none",children:m})]}),T=c?.side==="new"&&c.start<=t&&c.end>=e,S=[i,"rendered-block group/rendered-block relative",T?"bg-blue-100 dark:bg-blue-900/30":""].filter(Boolean).join(" ");return b?E.jsx(xy.Provider,{value:!0,children:E.jsxs(a,{className:S,"data-source-start-line":e,"data-source-end-line":t,style:{paddingInlineStart:"4rem"},...r,children:[v,n]})}):E.jsx(xy.Provider,{value:!0,children:E.jsxs("div",{className:"rendered-block group/rendered-block relative","data-source-start-line":e,"data-source-end-line":t,style:{paddingInlineStart:"4rem"},children:[v,h?E.jsx(a,{className:i,...r}):E.jsx(a,{className:i,...r,children:n})]})})}function oke(e,t=!1){function n({node:a,children:i,...r}){const{resolveLine:o}=mj(),l=a?.position,c=l!==void 0&&!(t&&a&&rke(a)),d=c?o(l.start.line):void 0,p=c?o(l.end.line):void 0;return E.jsx(ske,{startLine:d,endLine:p,tag:e,tagProps:r,children:i})}return n.displayName=`RenderedBlock(${e})`,n}function hj(e,t=new Set){const n={};for(const a of e)n[a]=oke(a,t.has(a));return n}var uke={...hj(nke),code:fj,img:up},lke={...hj(gj,ike),img:up},cke=[jf,n0],dke=[pA,sp];function fke({content:e}){return w.useMemo(()=>gA(pve(e),{Fragment:E.Fragment,jsx:E.jsx,jsxs:E.jsxs,components:lke,ignoreInvalidStyle:!0,passKeys:!0,passNode:!0}),[e])}function pke({content:e,contentMode:t,context:n}){return E.jsx(pj.Provider,{value:n,children:t==="markdown"?E.jsx(Fb,{urlTransform:op,remarkPlugins:cke,rehypePlugins:dke,components:uke,children:e}):E.jsx(fke,{content:e})})}var mke=[];function gke({file:e,contentMode:t,commentRange:n,onCancelComment:a,onCommentSaved:i,onGutterMouseDown:r}){const{t:o}=We(),l=w.useMemo(()=>Kve(e),[e]),c=w.useMemo(()=>Xve(l),[l]),d=w.useMemo(()=>t==="markdown"?$ve(c):null,[c,t]),p=d?d.body:c,m=d?d.lineOffset:0,h=e.newPath||e.oldPath,b=oI(h)?.comments??mke,y=w.useMemo(()=>aI(e),[e]),v=w.useMemo(()=>b.filter(A=>A.lineRange!==null&&y(A)),[b,y]),T=w.useMemo(()=>A=>Zve(A+m,l),[l,m]),S=w.useMemo(()=>({commentRange:n,resolveLine:T,onGutterMouseDown:r}),[n,T,r]);return E.jsxs(E.Fragment,{children:[E.jsxs("div",{className:"prose dark:prose-invert max-w-none p-4 rendered-markdown-view","data-rendered-text-mode":t,children:[d&&E.jsx(Wve,{metadata:d.metadata}),E.jsx(pI,{documentPath:h,children:E.jsx(pke,{content:p,contentMode:t,context:S})})]}),(v.length>0||n)&&E.jsxs("section",{"aria-label":o("Comments on source lines"),className:"space-y-3 border-t border-border bg-muted/30 p-4",children:[v.map(A=>{const N=A.lineRange?fh(e,A.lineRange):void 0;return E.jsxs("div",{children:[E.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:A.lineRange?.start===A.lineRange?.end?o("Line {line}",{line:A.lineRange.start}):o("Lines {start} to {end}",{start:A.lineRange.start,end:A.lineRange.end})}),E.jsx(ph,{comment:A,originalCode:N,anchorFullyVisible:N!==void 0})]},A.id)}),n&&E.jsx(rp,{filePath:h,lineRange:n,onCancel:a,onSubmit:i,originalCode:fh(e,n)})]})]})}function hke({filePath:e,onLoadImage:t}){const{t:n,number:a}=We(),i=_i(),r=uc(),[o,l]=w.useState(0),c=w.useMemo(()=>({}),[e,t,i,r,o]),d=w.useRef(c);d.current=c;const[p,m]=w.useState(null),h=p?.request===c?p:null,{dataUri:b,error:y,dimensions:v}=h??{},T=!h;return w.useEffect(()=>{d.current=c;const S=new AbortController,A=()=>!S.signal.aborted&&d.current===c;return!t&&!i?.reads?.loadImage&&!i?.loadImage?m({request:c,error:{unsupported:!0}}):(async()=>t&&t!==i?.loadImage?t(e):oH(i,e,S.signal))().then(x=>{A()&&(x?"error"in x?m({request:c,error:{detail:x.error}}):typeof x.dataUri=="string"&&kf(x.dataUri)?m({request:c,dataUri:x.dataUri}):m({request:c,error:{}}):m({request:c,error:{}}))},x=>{A()&&m({request:c,error:{detail:x instanceof Error?x.message:void 0}})}),()=>{S.abort(),d.current===c&&(d.current=null)}},[e,t,i,c]),T?E.jsxs("div",{role:"status","aria-label":n("Loading image..."),className:"flex justify-center items-center p-8",children:[E.jsx(tk,{"aria-hidden":"true",className:"h-6 w-6 animate-spin text-muted-foreground"}),E.jsx("span",{className:"sr-only",children:n("Loading image...")})]}):y||!b?E.jsxs("div",{role:"alert","aria-label":n("Image preview unavailable"),className:"flex flex-col justify-center items-center p-8 text-sm text-muted-foreground",children:[E.jsx("p",{children:n(y?.unsupported?"Image loading not supported in this context.":"Failed to load image.")}),y?.detail&&E.jsx("p",{children:y.detail}),!y?.unsupported&&E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>l(S=>S+1),children:n("Retry")})]}):E.jsxs("div",{className:"flex flex-col items-center p-4 gap-2",children:[E.jsx("img",{src:b,alt:e,onError:()=>{d.current===c&&m({request:c,error:{}})},style:{maxWidth:"100%",maxHeight:"80vh",objectFit:"contain"},onLoad:S=>{const A=S.currentTarget;d.current===c&&m({request:c,dataUri:b,dimensions:{w:A.naturalWidth,h:A.naturalHeight}})}}),v&&E.jsxs("span",{className:"text-xs text-muted-foreground",children:[a(v.w)," × ",a(v.h)]})]})}function bke(e){return e.hunks.flatMap(t=>t.lines).filter(t=>t.type==="addition").map(t=>t.content).join(`
312
- `)}function Eke({file:e}){const{t}=We(),[n,a]=w.useState(!1);w.useEffect(()=>a(!1),[e]);const i=w.useMemo(()=>bke(e),[e]);if(!i.trim()||n)return E.jsx("div",{role:"alert","aria-label":t("SVG preview unavailable"),className:"flex justify-center items-center p-8 text-sm text-muted-foreground",children:t(n?"Failed to load SVG preview.":"SVG content could not be extracted.")});const r=dj(i);return E.jsx("div",{className:"flex justify-center p-4",children:E.jsx("img",{src:r,alt:e.newPath||e.oldPath||t("SVG preview"),onError:()=>a(!0),style:{maxWidth:"100%",maxHeight:"80vh",objectFit:"contain"}})})}function yke({file:e,filePath:t,preview:n,descriptor:a,mode:i,commentRange:r,onCommentRange:o,onCancelComment:l,onCommentSaved:c,children:d}){const p=_i(),m=fI(),h=uc(),b=w.useCallback((N,x)=>o(N,x,"new"),[o]),y=a??XH(e,m,n),v=y.builtIn,T=y.renderer,S=i==="rendered"&&(T||v.kind!=="none"&&(v.kind!=="text"||!e.isBinary&&e.hunks.length>0)),A=()=>{switch(v.kind){case"image":return E.jsx(hke,{filePath:t,onLoadImage:p?.loadImage},h);case"svg":return E.jsx(Eke,{file:e});case"text":return e.isBinary||e.hunks.length===0?null:E.jsx(gke,{file:e,contentMode:v.mode,commentRange:r,onCancelComment:l,onCommentSaved:c,onGutterMouseDown:b})}return null};if(S){if(T){const N=T.component;return E.jsx(N,{file:e,filePath:t,preview:v,commentRange:r,onCommentRange:o,onCancelComment:l,onCommentSaved:c,children:A()})}return A()}return d}function qF(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\t/g," ")}function vke(e,t,n){if(t.length>hI||n==="plaintext")return null;try{const a=e.languages[n];return!a||n==="plaintext"?qF(t):e.highlight(t,a,n)}catch(a){return console.error(`[Prism] Error for ${n}:`,a),qF(t)}}var kke=Bt.memo(function({content:t,language:n,lineType:a,wordWrap:i}){const r=w.useMemo(()=>vke(Ao,t,n),[t,n]);return E.jsx("code",{className:`font-mono sr-diff-code ${i?"whitespace-pre-wrap":"whitespace-pre"} block`,dangerouslySetInnerHTML:r===null?void 0:{__html:r},children:r===null?t.replace(/\t/g," "):void 0})}),wke=kke;function bj(e){const t=w.useRef(e);return w.useLayoutEffect(()=>{t.current=e},[e]),w.useCallback((...n)=>t.current(...n),[])}var Ej=Bt.memo(function({layout:t,filePath:n,oldLineNumber:a,newLineNumber:i,lineType:r,content:o,language:l,wordWrap:c,isSelected:d,hasComment:p,rowIndex:m,onDragStart:h}){const{t:b}=We(),y=t==="unified",v=y?r==="deletion"?"old":"new":t,T=v==="old"?a:i,S={type:r},A=(N,x)=>{const I=y?`gutter-${N}`:"gutter",O=y?m:x;return E.jsxs("div",{className:`w-10 flex-shrink-0 text-end pe-2 text-[11px] leading-[22px] text-muted-foreground/70 select-none ${Aye(S)} ${I==="gutter-old"?"group/gutter-old":I==="gutter-new"?"group/gutter-new":"group/gutter"} relative`,"data-testid":x?`${N}-line-${n}-${x}`:void 0,children:[x&&E.jsx(cj,{className:`absolute start-0 top-1/2 -translate-y-1/2 opacity-0 ${I==="gutter-old"?"group-hover/gutter-old:opacity-100":I==="gutter-new"?"group-hover/gutter-new:opacity-100":"group-hover/gutter:opacity-100"}`,label:b(N==="old"?"Comment on old line {line}":"Comment on new line {line}",{line:x}),onStartDrag:()=>h(O,N),onActivate:()=>h(O,N,!0),"data-testid":`comment-icon-${N}-${x}`}),E.jsx("span",{className:"pointer-events-none",children:x||""})]})};return E.jsxs("div",{className:`${y?"flex":"split-half w-1/2 flex"} ${d?"bg-blue-100 dark:bg-blue-900/30":_ye(S)} ${p?"shadow-[inset_4px_0_0_0_#d97706] dark:shadow-[inset_4px_0_0_0_#fcd34d]":""} ${r==="addition"?"diff-line-addition":""} ${r==="deletion"?"diff-line-deletion":""}`,style:y?{contentVisibility:"auto",containIntrinsicSize:"auto 26px"}:void 0,"data-line-number":T||void 0,"data-line-side":v,"data-line-type":r,"data-row-index":y?m:void 0,children:[(y||v==="old")&&A("old",a),(y||v==="new")&&A("new",i),E.jsx("span",{role:"img","aria-label":b(r==="addition"?"Added line":r==="deletion"?"Removed line":"Unchanged line"),className:"w-4 shrink-0 select-none text-center leading-[26px] font-mono",style:{userSelect:"none"},children:E.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"inline-block size-3",fill:"none",stroke:"currentColor",children:r==="addition"?E.jsx("path",{d:"M8 3v10M3 8h10"}):r==="deletion"?E.jsx("path",{d:"M3 8h10"}):E.jsx("path",{d:"M3 6h10M3 10h10"})})}),E.jsx("div",{className:`flex-1 px-3 py-0.5 leading-[22px]${c?"":" [overflow-x:overlay]"}`,children:E.jsx(wke,{content:o,language:l,lineType:r,wordWrap:c})})]})}),VF=[];function Tke(e){const t=oI(e.newPath||e.oldPath)?.comments??VF;return w.useMemo(()=>{const n=new Map,a=new Set,i=aI(e);for(const r of t){const o=r.lineRange;if(!o||!i(r))continue;const l=`${o.side}:${o.end}`;n.set(l,[...n.get(l)??[],r]);for(let c=o.start;c<=o.end;c++)a.add(`${o.side}:${c}`)}return{endingAt:(r,o)=>n.get(`${o}:${r}`)??VF,covers:(r,o)=>a.has(`${o}:${r}`)}},[e,t])}function YF(e,t){return e.length===0?t:t.length===0?e:[...e,...t]}function yj(e,t){const n=Tke(e),a=w.useMemo(()=>t?fh(e,t):void 0,[e,t]),i=w.useMemo(()=>{let r=0;return e.hunks.map(o=>{const l=r;return r+=o.lines.length,l})},[e.hunks]);return{commentIndex:n,originalCode:a,rowOffsets:i,getOriginalCodeForComment:r=>r.lineRange?fh(e,r.lineRange):void 0,feedbackAt:(r,o,l)=>{const c=n.endingAt(r,"old"),d=n.endingAt(o,"new");return{comments:l==="old"?YF(c,d):YF(d,c),showInput:!!t&&(t.side==="old"?r:o)===t.end}}}}function Ske({header:e}){return E.jsx("div",{className:"hunk-header flex items-center h-7 px-3 text-xs font-mono bg-blue-500/10 dark:bg-blue-400/15 text-blue-700 dark:text-blue-300",children:e})}function _ke({position:e,hunkIndex:t,gapSize:n,onExpand:a,loading:i}){const{t:r}=We();if(n!==void 0&&n<=0)return null;const o=n!==void 0&&n<=20,l=(c,d,p)=>E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",type:"button",className:"flex items-center justify-center w-5 h-5 rounded-sm text-blue-700/70 dark:text-blue-300/70 hover:text-blue-700 dark:hover:text-blue-200 hover:bg-blue-500/20 dark:hover:bg-blue-400/20 transition-colors cursor-pointer",onClick:m=>{m.stopPropagation(),a(c,t,e)},disabled:i,"aria-label":p,children:E.jsx(d,{className:"h-3.5 w-3.5"})})}),E.jsx(Gt,{side:"right",children:p})]});return E.jsxs("div",{className:"expand-context-bar flex items-center h-[26px] bg-blue-500/10 dark:bg-blue-400/15 text-blue-700 dark:text-blue-300 select-none",children:[E.jsx("div",{className:"w-10 flex-shrink-0 flex items-center justify-center gap-0.5",children:i?E.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"..."}):o?l("all",OK,r("Show hidden lines",{count:n})):E.jsxs(E.Fragment,{children:[(e==="top"||e==="between")&&l("up",OP,r("Expand up")),(e==="bottom"||e==="between")&&l("down",ek,r("Expand down"))]})}),E.jsx("div",{className:"flex-1 px-2",children:o?E.jsx(Ye,{variant:"ghost",type:"button",className:"text-[11px] text-blue-700/70 dark:text-blue-300/70 hover:text-blue-700 dark:hover:text-blue-200 transition-colors cursor-pointer",onClick:()=>a("all",t,e),disabled:i,children:r("Show hidden lines",{count:n})}):E.jsx(Ye,{variant:"ghost",type:"button",className:"text-[11px] text-blue-700/70 dark:text-blue-300/70 hover:text-blue-700 dark:hover:text-blue-200 transition-colors cursor-pointer",onClick:()=>a("all",t,e),disabled:i,children:r("Show all hidden lines")})})]})}function Ake(e,t,n){if(e.length===0)return null;if(t===e.length){const i=e[t-1];return{position:"bottom",hunkIndex:t-1,gapSize:n==null?void 0:n-(i.newStart+i.newLines-1)}}const a=e[t];return{position:t===0?"top":"between",hunkIndex:t,gapSize:t===0?Math.max(a.oldStart,a.newStart)-1:a.newStart-(e[t-1].newStart+e[t-1].newLines)}}function mh({hunks:e,hunkIndex:t,isExpandable:n,onExpandContext:a,expandLoading:i,totalLines:r}){const o=n&&a?Ake(e,t,r):null;return E.jsxs(E.Fragment,{children:[o&&a&&E.jsx(_ke,{...o,onExpand:a,loading:i}),e[t]&&E.jsx(Ske,{header:e[t].header})]})}function vj({commentsToRender:e,showCommentInput:t,commentRange:n,filePath:a,originalCode:i,onCancel:r,onSaved:o,indentClass:l="",getOriginalCodeForComment:c}){return!t&&e.length===0?null:E.jsxs(E.Fragment,{children:[e.length>0&&E.jsx("div",{className:`border-y border-border bg-muted/50 px-4 py-3 space-y-2${l?` ${l}`:""}`,children:e.map(d=>{const p=c?.(d);return E.jsx(ph,{comment:d,originalCode:p,anchorFullyVisible:!c||d.lineRange===null||p!==void 0},d.id)})}),t&&n&&E.jsx("div",{className:`border-y border-border bg-muted/50 px-4 py-3${l?` ${l}`:""}`,children:E.jsx(rp,{filePath:a,lineRange:{side:n.side,start:n.start,end:n.end},onCancel:r,onSubmit:o,originalCode:i})})]})}function Nke({file:e,commentRange:t,dragState:n,onDragStart:a,onCancelComment:i,onCommentSaved:r,onExpandContext:o,isExpandable:l,expandLoading:c,totalLines:d}){const{t:p}=We(),m=bj(a),{commentIndex:h,originalCode:b,rowOffsets:y,feedbackAt:v,getOriginalCodeForComment:T}=yj(e,t),S=w.useMemo(()=>lj(e),[e]),A=ip(),N=KH(e.newPath||e.oldPath),x=e.newPath||e.oldPath;return E.jsxs("div",{className:"font-mono text-[13px] leading-[22px] unified-view",children:[S.limited&&E.jsx("p",{role:"status",className:"px-3 py-1 text-xs font-sans text-muted-foreground",children:p("Highlighting is limited for this file. All source lines remain available.")}),e.hunks.map((I,O)=>E.jsxs("div",{children:[E.jsx(mh,{hunks:e.hunks,hunkIndex:O,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d}),I.lines.map((D,M)=>{const B=y[O]+M,F=D.type==="deletion"?D.oldLineNumber:D.newLineNumber,G=D.type==="deletion"?"old":"new",{comments:z,showInput:W}=v(D.oldLineNumber,D.newLineNumber,"new"),ie=h.covers(F,G)||D.type==="context"&&h.covers(D.oldLineNumber,"old"),te=t?.side==="old"?D.oldLineNumber:D.newLineNumber,K=t&&te!==null&&te>=t.start&&te<=t.end,ne=n!==null&&B>=Math.min(n.startLine,n.currentLine)&&B<=Math.max(n.startLine,n.currentLine),Q=!!(K||ne);return E.jsxs(Bt.Fragment,{children:[E.jsx(Ej,{layout:"unified",filePath:x,oldLineNumber:D.oldLineNumber,newLineNumber:D.newLineNumber,lineType:D.type,content:D.content,language:S.lines.has(D)?N:"plaintext",wordWrap:A.wordWrap,isSelected:Q,hasComment:ie,rowIndex:B,onDragStart:m}),(z.length>0||W)&&E.jsx(vj,{commentsToRender:z,showCommentInput:!!W,commentRange:t,filePath:e.newPath||e.oldPath,originalCode:b,onCancel:i,onSaved:r,indentClass:"ms-[100px]",getOriginalCodeForComment:T})]},`${O}-${M}`)})]},O)),E.jsx(mh,{hunks:e.hunks,hunkIndex:e.hunks.length,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d})]})}function Cke(e){const t=[];let n=0;for(;n<e.length;){const a=e[n];if(a.type==="context")t.push({oldLine:a,newLine:a}),n++;else if(a.type==="deletion"){const i=[];for(;n<e.length&&e[n].type==="deletion";)i.push(e[n]),n++;const r=[];for(;n<e.length&&e[n].type==="addition";)r.push(e[n]),n++;const o=Math.max(i.length,r.length);for(let l=0;l<o;l++)t.push({oldLine:l<i.length?i[l]:null,newLine:l<r.length?r[l]:null})}else a.type==="addition"&&t.push({oldLine:null,newLine:a}),n++}return t}function Iy(){return E.jsxs("div",{className:"w-1/2 flex",children:[E.jsx("div",{className:"w-10 flex-shrink-0 bg-muted/20"}),E.jsx("div",{className:"flex-1 bg-muted/10"})]})}function Rke({file:e,commentRange:t,dragState:n,onDragStart:a,onCancelComment:i,onCommentSaved:r,onExpandContext:o,isExpandable:l,expandLoading:c,totalLines:d}){const{t:p}=We(),m=bj(a),{commentIndex:h,originalCode:b,feedbackAt:y,getOriginalCodeForComment:v}=yj(e,t),T=w.useMemo(()=>lj(e),[e]),S=ip(),A=e.newPath||e.oldPath,N=KH(A),x=(D,M)=>{if(t&&t.side===M&&D>=t.start&&D<=t.end)return!0;if(n&&n.side===M){const B=Math.min(n.startLine,n.currentLine),F=Math.max(n.startLine,n.currentLine);if(D>=B&&D<=F)return!0}return!1},I=w.useMemo(()=>e.hunks.map(D=>Cke(D.lines)),[e.hunks]),O=(D,M,B=!1)=>{if(!D)return E.jsx(Iy,{});const F=M==="old"?D.oldLineNumber:D.newLineNumber,G=F?x(F,M):!1;return E.jsx(Ej,{layout:M,filePath:A,oldLineNumber:D.oldLineNumber,newLineNumber:D.newLineNumber,lineType:D.type,content:D.content,language:T.lines.has(D)?N:"plaintext",wordWrap:S.wordWrap,isSelected:G,hasComment:B,onDragStart:m})};return E.jsxs("div",{className:"font-mono text-[13px] leading-[22px] split-view",children:[T.limited&&E.jsx("p",{role:"status",className:"px-3 py-1 text-xs font-sans text-muted-foreground",children:p("Highlighting is limited for this file. All source lines remain available.")}),e.hunks.map((D,M)=>E.jsxs("div",{children:[E.jsx(mh,{hunks:e.hunks,hunkIndex:M,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d}),I[M].map((B,F)=>{const G=B.oldLine?.oldLineNumber,z=B.newLine?.newLineNumber,{comments:W,showInput:ie}=y(G,z,"old");return E.jsxs(Bt.Fragment,{children:[E.jsxs("div",{className:"flex",style:{contentVisibility:"auto",containIntrinsicSize:"auto 26px"},children:[B.oldLine?O(B.oldLine,"old",h.covers(G,"old")):E.jsx(Iy,{}),B.newLine?O(B.newLine,"new",h.covers(z,"new")):E.jsx(Iy,{})]}),(W.length>0||ie)&&E.jsx(vj,{commentsToRender:W,showCommentInput:!!ie,commentRange:t,filePath:e.newPath||e.oldPath,originalCode:b,onCancel:i,onSaved:r,getOriginalCodeForComment:v})]},`${M}-${F}`)})]},M)),E.jsx(mh,{hunks:e.hunks,hunkIndex:e.hunks.length,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d})]})}function xke({viewMode:e,...t}){const{t:n}=We(),{file:a}=t;if(a.isBinary)return E.jsx("div",{className:"flex items-center justify-center py-12 text-sm text-muted-foreground",children:n("Binary file — no diff available")});if(a.hunks.length===0&&a.contentLoaded!==!1)return E.jsx("div",{className:"flex items-center justify-center py-12 text-sm text-muted-foreground",children:n("No changes to display")});const i=YH(e,a.changeType)==="split"?Rke:Nke;return E.jsx(i,{...t})}function Ike(e,t){return e.length!==t.length||e.some((n,a)=>!Object.is(n,t[a]))}var kj=class extends Bt.Component{constructor(){super(...arguments),this.state={error:null},this.retry=()=>{this.setState({error:null})}}static getDerivedStateFromError(e){return{error:e instanceof Error?e:new Error(String(e))}}componentDidCatch(e,t){console.error(`[self-review] Preview for ${JSON.stringify(this.props.filePath)} failed to render:`,e,t.componentStack??"")}componentDidUpdate(e){this.state.error&&Ike(e.resetKeys,this.props.resetKeys)&&this.setState({error:null})}render(){const{error:e}=this.state;return e?E.jsx(Oke,{filePath:this.props.filePath,error:e,retry:this.retry}):this.props.children}};function Oke({filePath:e,error:t,retry:n}){const{t:a}=We();return E.jsxs("div",{role:"alert","data-testid":"preview-error",className:"m-3 flex items-start gap-2 text-destructive text-sm p-3 border border-destructive/20 rounded",children:[E.jsx(Jd,{className:"h-4 w-4 mt-0.5 shrink-0","aria-hidden":"true"}),E.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[E.jsx("p",{children:a("This file could not be displayed: {path}",{path:e})}),E.jsx("p",{className:"text-xs text-muted-foreground break-words",children:t.message}),E.jsx("p",{className:"text-xs text-muted-foreground",children:a("The rest of the review is unaffected.")})]}),E.jsx(Ye,{variant:"outline",size:"sm",onClick:n,children:a("Try again")})]})}function Dke({filePath:e,fileComments:t,orphanedComments:n=[],showingFileComment:a,onCancelFileComment:i,onFileCommentSubmit:r,children:o}){const{t:l}=We();return E.jsxs("div",{className:"bg-background file-diff-content rounded-b-lg overflow-hidden",children:[n.length>0&&E.jsxs("section",{"aria-label":l("Comments outside the current diff"),className:"p-3 space-y-2 bg-amber-500/10 border-b border-border",children:[E.jsx("h3",{className:"text-sm font-medium",children:l("Comments outside the current diff")}),E.jsx("p",{className:"text-xs text-muted-foreground",children:l("These recorded line ranges are not in the loaded diff. Their original locations are preserved when you save.")}),n.map(c=>E.jsx(ph,{comment:c},c.id))]}),t.length>0&&E.jsx("div",{className:"p-3 space-y-2 bg-muted/20 border-b border-border",children:t.map(c=>E.jsx(ph,{comment:c},c.id))}),a&&E.jsx("div",{className:"p-3 bg-muted/20 border-b border-border",children:E.jsx(rp,{filePath:e,lineRange:null,onCancel:i,onSubmit:r})}),o]})}function wj({file:e,viewMode:t,expanded:n,onToggleExpanded:a}){const{t:i}=We(),{toggleViewed:r}=Ws(),o=LH(),l=oI(e.newPath||e.oldPath),{mode:c,getFileDescription:d,getFileGroupIndex:p}=au(),m=w.useId(),h=w.useRef(null),b=dI(),y=b?.registerFileElement,v=b?.unregisterFileElement,T=fI(),S=XH(e,T),{renderViewMode:A,setRenderViewMode:N}=Pye(e,S),x=e.newPath||e.oldPath,I=c==="guided"?d(x):void 0,O=l?.comments??[],D=O.filter(be=>be.lineRange===null),M=w.useMemo(()=>aI(e),[e]),B=O.filter(be=>!M(be)),F=l?.viewed||!1,{expanded:G,changeExpanded:z}=ave(x,F,n,a),W=w.useCallback(be=>{const Ce=h.current;h.current=be,Ce&&Ce!==be&&v?.(x,Ce),be&&y?.(x,be)},[x,y,v]),{state:ie,retry:te}=Yye({file:e,filePath:x,expanded:G}),K=o.type==="git"&&!e.isUntracked&&!e.isBinary,{expandLoading:ne,expandError:Q,totalLines:se,handleExpandContext:j}=qye({file:e,filePath:x,isExpandable:K,sectionRef:h,expanded:G}),Y=YH(t,e.changeType),{lineComments:oe,rawSelection:$,onCommentRange:he,fileComment:Ne}=Bye(e,h,Y),ke=()=>r(x);return E.jsxs("div",{ref:W,className:`mx-2 mt-2 border border-border rounded-lg shadow-sm${$.dragState?" select-none":""}`,"data-file-path":x,"data-testid":`file-section-${x}`,children:[E.jsx(rve,{bodyId:m,file:e,filePath:x,expanded:G,isViewed:F,isPreviewable:S.available,renderViewMode:A,commentCount:O.length,onToggle:()=>z(!G),onViewedToggle:ke,onAddFileComment:()=>{z(!0),Ne.openFileComment()},onRenderViewModeChange:N}),I&&E.jsxs("div",{className:"flex items-start gap-2.5 border-b border-border bg-muted/30 px-3 py-2",children:[E.jsx("span",{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full bg-background ring-2 ${Us(p(x)??0).ring}`,"aria-hidden":"true"}),E.jsx("span",{className:"text-xs leading-relaxed text-muted-foreground","data-testid":`file-guide-description-${x}`,children:I})]}),E.jsxs("div",{id:m,hidden:!G,children:[G&&Q&&E.jsx("p",{role:"alert",className:"m-3 text-sm text-destructive",children:i("Context could not be loaded. Use an expand button to try again.")}),G&&E.jsx(Dke,{filePath:x,fileComments:D,orphanedComments:B,showingFileComment:Ne.showingFileComment,onCancelFileComment:Ne.closeFileComment,onFileCommentSubmit:Ne.closeFileComment,children:E.jsx(kj,{filePath:x,resetKeys:[e,A,Y],children:E.jsx(Uve,{omittedReason:e.omittedReason,contentLoaded:e.contentLoaded,contentLoad:ie,onRetry:te,children:E.jsx(yke,{file:e,preview:S.builtIn,descriptor:S,filePath:x,mode:A,...oe,onCommentRange:he,children:E.jsx(xke,{file:e,viewMode:Y,...oe,...$,isExpandable:K,expandLoading:ne,totalLines:se,onExpandContext:K?j:void 0})})})})})]})]})}function Tj({diagnostics:e,title:t}){return e.length===0?null:E.jsxs("div",{role:"alert","data-testid":"diff-diagnostics",className:"rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-sm text-foreground",children:[E.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[E.jsx(Jd,{className:"h-4 w-4 text-amber-600 dark:text-amber-400","aria-hidden":!0}),E.jsx("span",{children:t})]}),E.jsx("ul",{className:"mt-2 list-disc space-y-1 pl-6 text-muted-foreground",children:e.map((n,a)=>E.jsx("li",{className:"font-mono text-xs break-words",children:n},a))})]})}function Lke({diffSource:e,diagnostics:t=[]}){const{t:n}=We();return e.type==="welcome"||e.type==="loading"?null:t.length>0?E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg w-full space-y-4",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("The review could not be loaded")}),E.jsx(Tj,{diagnostics:t,title:n("The diff could not be read in a form self-review can review")})]})}):e.type==="file"?E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg space-y-6",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("Could not read file")}),E.jsx("p",{className:"text-sm text-muted-foreground text-center",children:n("The file {path} could not be read or is empty.",{path:e.sourcePath})})]})}):e.type==="directory"?E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg space-y-6",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("No files found")}),E.jsx("p",{className:"text-sm text-muted-foreground text-center",children:n("No files found in the selected directory {path}. The directory may be empty or all files may be excluded by ignore rules.",{path:e.sourcePath})})]})}):E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg space-y-6",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("No changes found")}),E.jsxs("p",{className:"text-sm text-muted-foreground",children:[n("All arguments are passed directly to git diff."),e.gitDiffArgs&&E.jsxs("span",{children:[" ",n("The arguments {args} were passed to git diff. Try different arguments to see your changes.",{args:e.gitDiffArgs})]})]}),E.jsxs("div",{children:[E.jsx("h3",{className:"text-sm font-medium text-foreground mb-3",children:n("Common usage examples:")}),E.jsx("table",{className:"w-full text-sm",children:E.jsxs("tbody",{className:"text-muted-foreground",children:[E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review"}),E.jsx("td",{className:"py-1.5",children:n("Unstaged working tree changes (default)")})]}),E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review --staged"}),E.jsx("td",{className:"py-1.5",children:n("Changes staged for commit")})]}),E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review HEAD~1"}),E.jsx("td",{className:"py-1.5",children:n("Changes in the last commit")})]}),E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review main..HEAD"}),E.jsx("td",{className:"py-1.5",children:n("All changes since branching from main")})]}),E.jsxs("tr",{children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review -- src/"}),E.jsx("td",{className:"py-1.5",children:n("Limit diff to a specific directory")})]})]})})]})]})})}function Sj(e){const t=new Set,n=new Set,a=new Set;for(const i of e)i.viewed&&(a.add(i.path),t.has(i.path)||n.add(i.path)),t.add(i.path);return{first:n,any:a}}function WF(e,t){return e.size===t.size&&[...t].every(n=>e.has(n))}var KF=new WeakMap;function Mke(e){const t=e.getSnapshot().files,n=KF.get(e);if(n?.files===t)return n.viewed;const a=Sj(t),i=n&&WF(n.viewed.first,a.first)?n.viewed.first:a.first,r=n&&WF(n.viewed.any,a.any)?n.viewed.any:a.any,o=n?.viewed.first===i&&n.viewed.any===r?n.viewed:{first:i,any:r};return KF.set(e,{files:t,viewed:o}),o}function a0(e){const t=w.useContext(Ba);return t?E.jsx(Fke,{...e,store:t}):E.jsx(Bke,{...e})}function Fke({store:e,match:t,children:n}){const a=()=>Mke(e)[t],i=w.useSyncExternalStore(e.subscribe,a,a);return n(i)}function Bke({match:e,children:t}){const n=w.useContext(Wb);if(!n)throw new Error("useReview must be used within ReviewProvider");const{files:a}=n,i=w.useMemo(()=>Sj(a),[a]);return t(i[e])}var hd=960,Pke=200,lg=72,XF=74,Oy=122;function Uke(e,t=18){return e.length>t?`${e.slice(0,t-1)}…`:e}function $ke({groups:e,isGroupComplete:t,onJump:n}){const{t:a,number:i,direction:r}=We(),o=e.length;if(o===0)return null;const l=e.map((c,d)=>({x:o===1?hd/2:r==="rtl"?hd-lg-d*(hd-2*lg)/(o-1):lg+d*(hd-2*lg)/(o-1),y:o===1?(XF+Oy)/2:d%2===0?XF:Oy,r:11+Math.min(6,Math.max(0,c.files.length-1)*1.5)}));return E.jsxs("svg",{viewBox:`0 0 ${hd} ${Pke}`,role:"group","aria-label":a("Walkthrough route map"),className:"h-auto w-full select-none",style:{maxHeight:220},children:[l.map((c,d)=>{if(d===0)return null;const p=l[d-1],m=(c.x-p.x)*.45,h=e[d].implicit;return E.jsx("path",{d:`M ${p.x} ${p.y} C ${p.x+m} ${p.y}, ${c.x-m} ${c.y}, ${c.x} ${c.y}`,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:h?"2 7":void 0,className:h?"stroke-muted-foreground/50":Us(d).strokeSoft},`segment-${d}`)}),e.map((c,d)=>{const p=l[d],m=Us(d,c.implicit),h=t(c),b=c.files[0]?.path,v=p.y===Oy&&o>1?p.y-p.r-26:p.y+p.r+18;return E.jsxs("g",{role:n&&b?"button":void 0,tabIndex:n&&b?0:void 0,"aria-label":a("Go to stop {index}: {name}",{index:d+1,name:c.implicit?a("Everything else"):c.name}),onClick:n&&b?()=>n(b):void 0,onKeyDown:n&&b?S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),n(b))}:void 0,className:n&&b?"cursor-pointer":void 0,children:[c.rationale&&E.jsx("title",{children:c.rationale}),E.jsx("circle",{cx:p.x,cy:p.y,r:p.r,strokeWidth:2.5,strokeDasharray:c.implicit?"3 3":void 0,className:`${m.stroke} ${h?m.fill:"fill-background"}`}),!c.implicit&&E.jsx("text",{x:p.x,y:p.y+3.5,textAnchor:"middle",fontSize:11,fontWeight:600,className:h?"fill-white":m.fillText,children:h?"✓":i(d+1)}),E.jsx("text",{x:p.x,y:v,textAnchor:"middle",fontSize:13,fontWeight:600,className:"fill-foreground",children:Uke(c.implicit?a("Everything else"):c.name)}),E.jsx("text",{x:p.x,y:v+15,textAnchor:"middle",fontSize:10.5,fontFamily:"ui-monospace, monospace",className:"fill-muted-foreground",children:a("files",{count:c.files.length})})]},`station-${d}-${c.name}`)})]})}function _j(e){let t=0,n=0;const a=e.every(i=>!i.omittedReason&&(i.isBinary||i.contentLoaded!==!1));if(a){for(const i of e)if(!i.isBinary)for(const r of i.hunks)for(const o of r.lines)o.type==="addition"?t++:o.type==="deletion"&&n++}return{files:e.length,complete:a,additions:t,deletions:n}}function Aj(e){return w.useContext(Ba)?E.jsx(Hke,{...e}):E.jsx(jke,{...e})}function Hke(e){const{diffFiles:t}=lc();return E.jsx(a0,{match:"any",children:n=>E.jsx(Nj,{...e,diffFiles:t,viewedPaths:n})})}function jke(e){const{diffFiles:t}=Zb();return E.jsx(a0,{match:"any",children:n=>E.jsx(Nj,{...e,diffFiles:t,viewedPaths:n})})}function Nj({onNavigate:e,diffFiles:t,viewedPaths:n}){const{t:a,number:i}=We(),{guide:r}=au(),o=dI(),{additions:l,deletions:c,complete:d}=w.useMemo(()=>_j(t),[t]);if(!r?.overview)return null;const p=r.groups,m=p.reduce((b,y)=>b+y.files.length,0),h=b=>b.files.length>0&&b.files.every(y=>n.has(y.path));return E.jsxs("div",{children:[E.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 select-none",children:[E.jsxs("span",{className:"flex items-center gap-2",children:[E.jsx(BP,{className:"h-3.5 w-3.5 text-indigo-600 dark:text-indigo-400"}),E.jsx("span",{className:"font-mono text-[11px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("Review walkthrough")})]}),E.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-muted-foreground",children:[a("walkthrough totals",{stops:p.length,files:m}),!d&&E.jsxs("span",{children:[" · ",a("Line totals unavailable")]}),l>0&&E.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:[" +",i(l)]}),c>0&&E.jsxs("span",{className:"text-red-600 dark:text-red-400",children:[" −",i(c)]})]})]}),E.jsx("div",{className:"mt-4",children:E.jsx($ke,{groups:p,isGroupComplete:h,onJump:o?b=>{o.scrollToFile(b),e?.()}:void 0})}),E.jsx("div",{className:"guide-overview-prose prose prose-sm dark:prose-invert mt-5 max-w-none",children:E.jsx(pI,{children:E.jsx(Fb,{urlTransform:op,remarkPlugins:[jf,n0],rehypePlugins:[sp],components:{code:fj,img:up},children:r.overview})})})]})}function zke(){const{guide:e,mode:t}=au();return t!=="guided"||!e?.overview?null:E.jsx("section",{className:"border-b border-border","data-testid":"guide-overview",children:E.jsx("div",{className:"mx-auto max-w-4xl px-6 pb-7 pt-7",children:E.jsx(Aj,{})})})}function Gke(e){return E.jsx(a0,{match:"first",children:t=>E.jsx(qke,{...e,viewedPaths:t})})}function qke({header:e,index:t,totalStops:n,implicitLast:a,entries:i,viewedPaths:r}){const{t:o,locale:l}=We(),c=i.filter(({file:d})=>{const p=d.newPath||d.oldPath;return r.has(p)}).length;return E.jsxs("section",{className:"relative mt-5 overflow-hidden border-y border-border/60 bg-muted/20 px-6 py-5","data-testid":`guide-chapter-${e.name}`,children:[!e.implicit&&E.jsx("span",{className:"pointer-events-none absolute -top-4 end-2 select-none font-mono text-[104px] font-bold leading-none",style:{WebkitTextStroke:`1.5px ${Us(t).numeralStroke}`,color:"transparent"},"aria-hidden":"true",children:new Intl.NumberFormat(l,{minimumIntegerDigits:2,useGrouping:!1}).format(t+1)}),E.jsxs("div",{className:"relative",children:[E.jsxs("div",{className:"font-mono text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:[e.implicit?o("Appendix"):o("Stop {index} of {total}",{index:t+1,total:n})," ","· ",o("files",{count:i.length})," ·"," ",o("{viewed}/{total} reviewed",{viewed:c,total:i.length})]}),E.jsx("h3",{className:"mt-1.5 text-xl font-bold tracking-tight text-foreground",children:e.implicit?o("Everything else"):e.name}),e.rationale&&E.jsx("p",{className:"mt-1 max-w-2xl text-[13px] leading-relaxed text-muted-foreground",children:e.rationale}),E.jsx("div",{className:"mt-3 flex items-center gap-1.5","aria-hidden":"true",children:Array.from({length:n},(d,p)=>{const m=Us(p,a&&p===n-1);return E.jsx("span",{className:p===t?`h-2 w-2 rounded-full ${m.dot}`:`h-1.5 w-1.5 rounded-full ${p<t?m.dotSoft:m.dotFaint}`},p)})})]})]})}function Vke(){const{t:e}=We(),{diffFiles:t,diffSource:n,diagnostics:a=[],sessionId:i}=lc(),r=ip(),o=Ys(),{guide:l,mode:c}=au(),d=w.useRef(null),p=dI(),m=w.useMemo(()=>HH(t,jH(t,l?.groups??null,c)),[t,l,c]),h=m.filter(N=>N.header).length,b=!!m[m.length-1]?.header?.implicit,{expanded:y,setExpanded:v}=Xb(),T=N=>y.get(N)??!1,S=w.useRef(0);w.useLayoutEffect(()=>{if(S.current>0){const N=yf(o,'[data-scroll-container="diff"]');N&&(N.scrollTop-=S.current),S.current=0}},[y]);const A=N=>{const x=T(N);if(x){const I=yf(o,'[data-scroll-container="diff"]'),O=p?.getFileElement(N);if(I&&O){const D=I.getBoundingClientRect();if(O.getBoundingClientRect().top<D.top){const F=O.scrollHeight-40;F>0&&(S.current=F)}}}v(N,!x)};return t.length===0?E.jsx(Lke,{diffSource:n,diagnostics:a}):E.jsxs("div",{ref:d,className:`flex-1${h>0?" pb-16":""}`,"data-testid":"diff-viewer","data-diff-viewer":!0,children:[a.length>0&&E.jsx("div",{className:"px-4 pt-4",children:E.jsx(Tj,{diagnostics:a,title:e("Part of this diff could not be reviewed")})}),E.jsx(zke,{}),m.map((N,x)=>E.jsxs(Bt.Fragment,{children:[N.header&&E.jsx(Gke,{header:N.header,index:x,totalStops:h,implicitLast:b,entries:N.entries}),N.entries.map(({file:I,key:O})=>{const D=I.newPath||I.oldPath;return E.jsx(kj,{filePath:D,resetKeys:[I],children:E.jsx(wj,{file:I,viewMode:r.diffView,expanded:T(D),onToggleExpanded:A})},`${i}:${O}`)})]},`chapter-${x}-${N.header?.name??"flat"}`))]})}function Yke({open:e,onOpenChange:t}){const{t:n}=We();return E.jsx(aj,{open:e,onOpenChange:t,children:E.jsxs(mI,{className:"block max-h-[85vh] max-w-3xl overflow-y-auto","data-testid":"guide-overview-dialog",children:[E.jsx(gI,{className:"sr-only",children:n("Review walkthrough")}),E.jsx(Aj,{onNavigate:()=>t(!1)})]})})}function Wke(){return E.jsx(a0,{match:"any",children:e=>E.jsx(Kke,{viewedPaths:e})})}function Kke({viewedPaths:e}){const{t}=We(),{guide:n,mode:a}=au(),{activeFilePath:i,scrollToFile:r}=cI(),[o,l]=w.useState(!1);if(a!=="guided"||!n||n.groups.length===0)return null;const c=n.groups,d=c.findIndex(h=>h.files.some(b=>b.path===i)),p=d>=0?c[d]:null,m=!!n.overview;return E.jsxs("div",{className:"pointer-events-none absolute inset-x-0 bottom-4 z-30 flex justify-center",children:[E.jsxs("div",{className:"pointer-events-auto flex items-center gap-2 rounded-full border border-border bg-background/90 py-1.5 ps-2 pe-4 shadow-lg backdrop-blur","data-testid":"guide-route-hud",children:[m&&E.jsxs(E.Fragment,{children:[E.jsxs("button",{type:"button",title:t("Open the walkthrough overview"),onClick:()=>l(!0),className:"flex h-6 w-6 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground","data-testid":"guide-hud-overview-btn",children:[E.jsx(BP,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("Open the walkthrough overview")})]}),E.jsx("span",{className:"h-4 w-px bg-border","aria-hidden":"true"})]}),E.jsx("div",{className:"flex items-center gap-1",children:c.map((h,b)=>{const y=Us(b,h.implicit),v=b===d,T=h.files.length>0&&h.files.every(A=>e.has(A.path)),S=h.files[0]?.path;return E.jsx("button",{type:"button",title:h.implicit?t("Everything else"):h.name,"aria-label":t("Go to stop {index}: {name}",{index:b+1,name:h.implicit?t("Everything else"):h.name}),onClick:S?()=>r(S):void 0,className:"flex h-5 w-5 items-center justify-center rounded-full transition-colors hover:bg-muted",children:E.jsx("span",{className:v?`h-3 w-3 rounded-full ${y.dot}`:T?`h-2 w-2 rounded-full ${y.dotSoft}`:`h-2 w-2 rounded-full ${y.dotFaint}`,"aria-hidden":"true"})},`hud-stop-${b}-${h.name}`)})}),E.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] tabular-nums text-muted-foreground",children:p?t("{index}/{total} · {name}",{index:d+1,total:c.length,name:p.implicit?t("Everything else"):p.name}):t("stops",{count:c.length})})]}),m&&E.jsx(Yke,{open:o,onOpenChange:l})]})}function Xke({collapsed:e,controls:t,onToggle:n}){const a=e?"Show file tree":"Hide file tree",i=e?dK:lK;return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"outline",size:"icon",className:"h-7 w-7 rounded-full shadow-md text-muted-foreground hover:text-foreground","data-testid":"file-tree-toggle","data-review-navigation":"","aria-expanded":!e,"aria-controls":t,"aria-label":a,onClick:n,children:E.jsx(i,{className:"h-3.5 w-3.5"})})}),E.jsx(Gt,{side:"right",children:a})]})}function Zke(){const e=OH(),t=Ys(),n=w.useId(),a=`${n}-file-tree`,i=`${n}-diff-viewer`,r=w.useRef(null),[o,l]=w.useState(!1),c=w.useCallback(()=>{l(r.current?.isCollapsed()??!1)},[]),d=w.useCallback(()=>{const m=r.current;m&&(m.isCollapsed()?m.expand():m.collapse(),c())},[c]),p=w.useCallback(()=>{const m=r.current;return m?(m.isCollapsed()&&Ti.flushSync(()=>{m.expand(),c()}),!m.isCollapsed()):!1},[c]);return w.useLayoutEffect(()=>e?.register(p),[e,p]),w.useEffect(()=>{const m=()=>{p()};return t?.addEventListener("expand-file-tree",m),()=>t?.removeEventListener("expand-file-tree",m)},[p,t]),E.jsxs(t7,{orientation:"horizontal",style:{flex:1},children:[E.jsx(Tv,{id:a,panelRef:r,collapsible:!0,collapsedSize:"0%",defaultSize:"25%",minSize:"10%",maxSize:"60%",onResize:c,children:E.jsx("div",{className:"h-full overflow-hidden bg-sidebar text-sidebar-foreground",inert:o||void 0,children:E.jsx(Mye,{})})}),E.jsx(n7,{className:"relative flex w-px items-center justify-center bg-border",children:E.jsx("div",{className:"z-10 flex h-4 w-3.5 items-center justify-center rounded-sm border bg-border",children:E.jsx($W,{className:"h-2.5 w-2.5"})})}),E.jsx(Tv,{id:i,defaultSize:"75%",children:E.jsxs("div",{className:"relative h-full",children:[E.jsx("div",{className:"h-full overflow-y-auto bg-background","data-scroll-container":"diff",children:E.jsx(Vke,{})}),E.jsx("div",{className:"absolute bottom-4 left-4 z-30",children:E.jsx(Xke,{collapsed:o,controls:a,onToggle:d})}),E.jsx(Wke,{})]})})]})}var Qke=Bt.memo(Zke),cg="asdfjklhgqwertuiop".split(""),Jke=80,ZF='[data-comment-gutter], [data-hint-action], [data-testid="cancel-comment-btn"], [data-testid="add-comment-btn"], [data-testid^="category-option-"]',ewe="[data-line-type][data-line-number][data-line-side]";function twe(e){if(e<=cg.length)return cg.slice(0,e);const t=[];for(const n of cg)for(const a of cg)if(t.push(n+a),t.length>=e)return t;return t}function nwe(){const e=document.activeElement;if(!e)return!1;const t=e.tagName.toLowerCase();return!!(t==="input"||t==="textarea"||e.closest('[contenteditable]:not([contenteditable="false"])')||e.closest('[class*="md-editor"]')||e.closest("[data-color-mode]"))}function QF(e){const t=e instanceof Element?e.closest('input, textarea, select, button, a[href], [role="button"], [role="combobox"], [role="listbox"], [role="slider"], [role="spinbutton"], [role="menu"], [role="menuitem"], [role="checkbox"], [role="radio"], [role="switch"], [role="tab"], [role="textbox"], [contenteditable]:not([contenteditable="false"])'):null;return!!t&&!t.hasAttribute("data-review-navigation")}function JF(e,t){const n=yf(e,'[data-scroll-container="diff"]');n&&n.scrollBy({top:t*Jke,behavior:"instant"})}function awe(){const e=Ys(),n=gH()?.characterShortcuts??!0,a=w.useRef(n);a.current=n;const i=OH(),r=w.useRef(!1),[o,l]=w.useState("normal"),[c,d]=w.useState([]),[p,m]=w.useState(""),{scrollToFile:h}=cI(),b=w.useRef(o),y=w.useRef(c),v=w.useRef(p);b.current=o,y.current=c,v.current=p;const T=w.useCallback(()=>{l("normal"),d([]),m("")},[]),S=w.useRef(T);S.current=T;const A=w.useCallback(x=>{if(b.current==="hint-diff"){if(x.element.matches(ZF)){x.element.click(),S.current();return}const I=x.element.getAttribute("data-line-number"),O=x.element.getAttribute("data-line-side");let D=null,M=x.element;for(;M;){const B=M.getAttribute("data-file-path");if(B){D=B;break}M=M.parentElement}D&&I&&O&&x.element.dispatchEvent(new CustomEvent("trigger-line-comment",{bubbles:!0,detail:{filePath:D,lineNumber:parseInt(I,10),side:O}}))}else if(b.current==="hint-file"){const I=x.element.getAttribute("data-file-path");I&&h(I)}S.current()},[h]),N=w.useCallback(x=>{let I;if(x==="hint-diff")I=`${ZF}, ${ewe}`;else{const F=i?.expand();if(F===!1)return;F===void 0&&e?.dispatchEvent(new CustomEvent("expand-file-tree")),I='.file-tree [data-file-path], [data-testid="file-tree"] [data-file-path], button[data-file-path]'}const O=MH(e,I),D=[];if(O.forEach(F=>{if(F.hasAttribute("data-line-type")&&F.querySelector("[data-comment-gutter]"))return;const G=F.getBoundingClientRect();G.top>=0&&G.left>=0&&G.bottom<=window.innerHeight&&G.right<=window.innerWidth&&G.width>0&&G.height>0&&D.push({element:F,rect:G})}),D.length===0)return;const M=twe(D.length),B=D.map((F,G)=>({label:M[G],element:F.element,rect:F.rect}));l(x),d(B),m("")},[e,i]);return w.useEffect(()=>{if(!e)return;e.setAttribute("data-review-shortcuts","");const x=F=>{!F&&r.current&&S.current(),r.current=F,e.toggleAttribute("data-review-active",F)};x(document.querySelector("[data-review-shortcuts]")===e);const I=F=>{x(F.target instanceof Element&&F.target.closest("[data-review-shortcuts]")===e)};document.addEventListener("pointerdown",I,!0),document.addEventListener("focusin",I,!0);let O=!1;const D=()=>{O=!0,S.current()},M=()=>{O=!1};function B(F){if(F.defaultPrevented||F.isComposing||F.keyCode===229||O)return;const G=F.target;if(document.querySelector("[data-review-active]")||x(document.querySelector("[data-review-shortcuts]")===e),!r.current||nwe()||G instanceof Element&&G!==document.body&&!e?.contains(G))return;const z=document.activeElement;if(z&&z!==document.body&&!e?.contains(z))return;const W=b.current,ie=y.current,te=v.current;if(!(QF(G)||QF(z))&&!(F.altKey||F.ctrlKey||F.metaKey)){if(F.key==="Escape"&&W!=="normal"){F.preventDefault(),S.current();return}if(a.current){if(W==="normal")switch(F.key){case"f":F.preventDefault(),N("hint-diff");return;case"g":F.preventDefault(),N("hint-file");return;case"j":F.preventDefault(),JF(e,1);return;case"k":F.preventDefault(),JF(e,-1);return;default:return}if(/^[a-z0-9]$/i.test(F.key)){F.preventDefault();const K=te+F.key.toLowerCase(),ne=ie.find(se=>se.label===K);if(ne){A(ne);return}ie.some(se=>se.label.startsWith(K))?m(K):S.current()}}}}return document.addEventListener("keydown",B),document.addEventListener("compositionstart",D),document.addEventListener("compositionend",M),()=>{document.removeEventListener("keydown",B),document.removeEventListener("compositionstart",D),document.removeEventListener("compositionend",M),document.removeEventListener("pointerdown",I,!0),document.removeEventListener("focusin",I,!0),e.removeAttribute("data-review-shortcuts"),e.removeAttribute("data-review-active")}},[N,A,e]),w.useEffect(()=>{n||T()},[n,T]),w.useEffect(()=>{if(o==="normal")return;const x=yf(e,'[data-scroll-container="diff"]');if(!x)return;function I(){S.current()}return x.addEventListener("scroll",I,{passive:!0}),()=>x.removeEventListener("scroll",I)},[o,e]),{mode:o,hints:c,inputBuffer:p,clearHints:T}}function iwe({hints:e,inputBuffer:t}){const n=t?e.filter(a=>a.label.startsWith(t)):e;return n.length===0?null:Ti.createPortal(E.jsx("div",{"data-testid":"hint-overlay",style:{position:"fixed",inset:0,pointerEvents:"none",zIndex:9999},children:n.map(a=>E.jsxs("span",{"data-testid":`hint-label-${a.label}`,style:{position:"absolute",left:a.rect.left,top:a.rect.top,backgroundColor:"#facc15",color:"#000",fontFamily:"monospace",fontSize:"11px",fontWeight:"bold",padding:"1px 3px",borderRadius:"2px",lineHeight:1,zIndex:9999},children:[E.jsx("span",{style:{opacity:.4},children:a.label.slice(0,t.length)}),E.jsx("span",{children:a.label.slice(t.length)})]},a.label))}),document.body)}function rwe(){const{hints:e,inputBuffer:t}=awe();return E.jsx(iwe,{hints:e,inputBuffer:t})}function Cj(e,t){const{files:n,diffSource:a}=Zb(),i=dye(),{now:r}=Kb(),o=w.useRef(r);o.current=r;const l=w.useRef(n),c=w.useRef(a);l.current=n,c.current=a,w.useImperativeHandle(e,()=>({beginSave:i.begin,getReviewState:()=>({timestamp:o.current().toISOString(),source:c.current,files:l.current})}));const d=w.useRef(t);d.current=t;const p=w.useRef(null);w.useEffect(()=>{const m=n.flatMap(y=>y.comments),h=p.current;(h===null||h.length!==m.length||m.some((y,v)=>y!==h[v]))&&(p.current=m,d.current?.(m))},[n])}var swe=w.forwardRef(function({adapter:t,config:n,initialConfig:a,className:i,children:r,onReviewChange:o,previewRenderer:l,diagramRenderer:c,services:d,recovery:p,initialCharacterShortcuts:m},h){return E.jsx(Sye,{adapter:t,config:n,initialConfig:a,previewRenderer:l,diagramRenderer:c,services:d,recovery:p,initialCharacterShortcuts:m,children:E.jsx(owe,{ref:h,className:i,onReviewChange:o,children:r})})}),owe=w.forwardRef(function({className:t,children:n,onReviewChange:a},i){return Cj(i,a),E.jsxs("div",{className:t,children:[E.jsx(rwe,{}),n,E.jsx(Qke,{})]})}),uwe=w.forwardRef(function({file:t,viewMode:n,onReviewChange:a,className:i},r){Cj(r,a);const o=uye(t.newPath||t.oldPath);return E.jsx("div",{className:i,children:E.jsx(E.Fragment,{children:o&&E.jsx(wj,{file:o,viewMode:n})})})}),lwe=w.forwardRef(function({file:t,source:n,adapter:a,recovery:i,initialCharacterShortcuts:r,...o},l){const c=w.useRef({files:[t],source:n});c.current={files:[t],source:n};const d=w.useMemo(()=>({...a,loadDiff:async()=>c.current}),[a]),p=w.useMemo(()=>[t],[t]);return E.jsx(M$,{adapter:d,children:E.jsx(DH,{initialFiles:p,initialSource:n,recovery:i,initialCharacterShortcuts:r,children:E.jsx(FH,{children:E.jsx(AH,{children:E.jsx(uwe,{ref:l,file:t,...o})})})})})});w.forwardRef(function({file:t,source:n,config:a,initialConfig:i,onReviewChange:r,adapter:o,className:l,recovery:c,initialCharacterShortcuts:d,defaultViewMode:p="unified"},m){const h=n||{type:"file",sourcePath:t.newPath||t.oldPath},b=JSON.stringify([t.newPath||t.oldPath,Bo(h)]);return E.jsx(Z$,{initialConfig:{...i??a,diffView:p},children:E.jsx(lwe,{ref:m,file:t,source:h,adapter:o,viewMode:p,onReviewChange:r,className:l,recovery:c,initialCharacterShortcuts:d},b)})});function cwe(){const e=gH(),{t}=We();if(!e)return null;const n=e.characterShortcuts?FP:qW,a=`${t("Keyboard shortcuts")} (f, g, j, k)`;return E.jsxs(Ye,{variant:"ghost",size:"sm","data-hint-action":"toggle-character-shortcuts","aria-label":a,"aria-pressed":e.characterShortcuts,title:a,onClick:()=>e.setCharacterShortcuts(!e.characterShortcuts),children:[E.jsx(n,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:a})]})}function dwe(){const{t:e,number:t}=We(),{diffFiles:n}=lc(),a=cye(),{viewedCount:i,totalFiles:r,commentCount:o,filesWithComments:l}=w.useMemo(()=>{const d=new Set(n.map(v=>v.newPath||v.oldPath)),p=a.filter(v=>d.has(v.path)),m=p.filter(v=>v.viewed).length,h=n.length,b=p.reduce((v,T)=>v+T.commentCount,0),y=p.filter(v=>v.commentCount>0).length;return{viewedCount:m,totalFiles:h,commentCount:b,filesWithComments:y}},[a,n]);if(r===0)return null;const c=Math.round(i/r*100);return E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground","data-testid":"review-progress",children:[E.jsx(IW,{className:"h-3 w-3"}),E.jsxs("span",{className:"tabular-nums",children:[t(i),"/",t(r)]}),E.jsx("div",{role:"progressbar","aria-label":e("Review progress"),"aria-valuemin":0,"aria-valuemax":r,"aria-valuenow":i,className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:E.jsx("div",{className:"h-full rounded-full bg-green-600 dark:bg-green-500 transition-all duration-300",style:{width:`${c}%`}})})]})}),E.jsx(Gt,{children:e("files viewed",{viewed:i,total:r,percent:c})})]}),o>0&&E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground","data-testid":"review-stats",children:[E.jsx(Qd,{className:"h-3 w-3"}),E.jsx("span",{className:"tabular-nums",children:t(o)})]})}),E.jsx(Gt,{children:e("comments across files",{count:o,files:l})})]})]})}function fwe({onFinishReview:e}={}){const{t,number:n}=We(),{config:a,updateConfig:i}=Xx(),{outputPathInfo:r}=X$(),{diffFiles:o,diffSource:l}=lc(),{guide:c,mode:d,setMode:p}=au(),m=_i(),{allCollapsed:h,setAllCollapsed:b}=eI(),y=w.useMemo(()=>_j(o),[o]),v=()=>{b(!h)},T=S=>{i({theme:S})};return E.jsxs("div",{className:"flex shrink-0 z-20 items-center justify-between h-11 px-3 border-b border-border bg-background","data-testid":"toolbar",children:[E.jsxs("div",{className:"flex items-center gap-2",children:[l.type==="git"&&E.jsxs(E.Fragment,{children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":"toggle-untracked-btn",onClick:()=>i({showUntracked:!a.showUntracked}),className:"gap-1.5 h-8 px-2.5 text-muted-foreground hover:text-foreground",children:[a.showUntracked?E.jsx(BW,{className:"h-3.5 w-3.5"}):E.jsx(DW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t(a.showUntracked?"Hide New Files":"Show New Files")})]})}),E.jsx(Gt,{children:a.showUntracked?t("Hide new files not yet in git"):t("Show new files not yet in git")})]}),E.jsx(ha,{orientation:"vertical",className:"h-5"})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":h?"expand-all-comments-btn":"collapse-all-comments-btn",onClick:v,className:"gap-1.5 h-8 px-2.5 text-muted-foreground hover:text-foreground",children:[h?E.jsx(Qd,{className:"h-3.5 w-3.5"}):E.jsx(eK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t(h?"Expand Comments":"Collapse Comments")})]})}),E.jsx(Gt,{children:t(h?"Expand all comments":"Collapse all comments")})]}),c&&E.jsxs(E.Fragment,{children:[E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(vf,{type:"single",variant:"outline",size:"sm",value:d,onValueChange:S=>{(S==="guided"||S==="flat")&&p(S)},children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"guided","data-testid":"guide-mode-guided",className:"h-8 px-2.5 gap-1.5",children:[E.jsx(EK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t("Guided")})]})}),E.jsx(Gt,{children:t("Group files by the review walkthrough")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"flat","data-testid":"guide-mode-flat",className:"h-8 px-2.5 gap-1.5",children:[E.jsx(XW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t("Flat")})]})}),E.jsx(Gt,{children:t("Flat file list (diff order)")})]})]})]})]}),E.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground","data-testid":"diff-stats",children:[E.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[l.type==="file"?E.jsx(MW,{className:"h-3 w-3"}):l.type==="directory"?E.jsx(LP,{className:"h-3 w-3"}):E.jsx(SK,{className:"h-3 w-3"}),l.type==="git"?`git diff${l.gitDiffArgs?` ${l.gitDiffArgs}`:""}`:l.type==="directory"?t("Directory: {path}",{path:l.sourcePath}):l.type==="file"?t("File: {path}",{path:l.sourcePath.split("/").pop()??""}):""]}),E.jsx(ha,{orientation:"vertical",className:"h-3.5"}),E.jsx("span",{children:t("files changed",{count:y.files})}),!y.complete&&E.jsx("span",{children:t("Line totals unavailable")}),y.additions>0&&E.jsxs("span",{className:"text-green-600 dark:text-green-400",children:["+",n(y.additions)]}),y.deletions>0&&E.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["-",n(y.deletions)]})]}),E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx(cwe,{}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":"toggle-word-wrap-btn",onClick:()=>i({wordWrap:!a.wordWrap}),className:"gap-1.5 h-8 px-2.5 text-muted-foreground hover:text-foreground",children:[a.wordWrap?E.jsx(CK,{className:"h-3.5 w-3.5"}):E.jsx(oK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t(a.wordWrap?"Wrap Lines":"No Wrap")})]})}),E.jsx(Gt,{children:t(a.wordWrap?"Wrap long lines":"Scroll long lines horizontally")})]}),E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(vf,{type:"single",variant:"outline",size:"sm",value:a.theme,onValueChange:S=>S&&T(S),children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"light","data-testid":"theme-option-light",className:"h-8 w-8 p-0",children:[E.jsx(wK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("Light theme")})]})}),E.jsx(Gt,{children:t("Light theme")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"dark","data-testid":"theme-option-dark",className:"h-8 w-8 p-0",children:[E.jsx(rK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("Dark theme")})]})}),E.jsx(Gt,{children:t("Dark theme")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"system","data-testid":"theme-option-system",className:"h-8 w-8 p-0",children:[E.jsx(aK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("System theme")})]})}),E.jsx(Gt,{children:t("System theme")})]})]}),E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsx(dwe,{}),e&&E.jsxs(E.Fragment,{children:[E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx("span",{children:E.jsxs(Ye,{variant:"default",size:"sm","data-testid":"finish-review-btn","data-hint-action":"finish-review",onClick:()=>e(),className:"gap-1.5 h-8 px-3",disabled:!r.outputPathWritable||l.type==="loading",children:[E.jsx(kh,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs font-medium",children:t("Finish Review")})]})})}),!r.outputPathWritable&&E.jsx(Gt,{children:m?.changeOutputPath?t("Output path is not writable. Click 'Change...' in the file tree to pick a save location."):t("Output path is not writable.")})]})]})]})]})}var pwe=[];function mwe(){const e=w.useContext(Ba);return e?E.jsx(gwe,{store:e}):E.jsx(hwe,{})}function gwe({store:e}){const t=()=>e.getSnapshot().resumedReview?.importDiagnostics??pwe,n=()=>e.getSnapshot().anchorDiagnostics,a=()=>e.getSnapshot().sessionId,i=w.useSyncExternalStore(e.subscribe,t,t),r=w.useSyncExternalStore(e.subscribe,n,n),o=w.useSyncExternalStore(e.subscribe,a,a),l=w.useMemo(()=>[...i,...r],[i,r]);return E.jsx(Rj,{importDiagnostics:l},o)}function hwe(){const{importDiagnostics:e,sessionId:t}=Zb();return E.jsx(Rj,{importDiagnostics:e},t)}function Rj({importDiagnostics:e}){const{t}=We(),[n,a]=w.useState(!1);return e.length===0||n?null:E.jsxs("div",{role:"alert",className:"flex shrink-0 items-start justify-between gap-3 px-3 py-1.5 border-b border-border bg-amber-50 dark:bg-amber-950 text-xs","data-testid":"import-diagnostics-banner",children:[E.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[E.jsx(Jd,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400"}),E.jsxs("div",{className:"min-w-0",children:[E.jsx("span",{children:t("Resumed comments without anchors",{count:e.length})}),E.jsx("ul",{className:"mt-0.5 list-disc space-y-0.5 ps-5 text-muted-foreground",children:e.map((i,r)=>E.jsx("li",{className:"font-mono break-words",children:i},r))})]})]}),E.jsxs(Ye,{variant:"ghost",size:"sm",className:"h-5 w-5 shrink-0 p-0 text-muted-foreground hover:text-foreground",onClick:()=>a(!0),"data-testid":"import-diagnostics-banner-dismiss",children:[E.jsx(nk,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:t("Dismiss")})]})]})}function bwe(e,t=!0){w.useLayoutEffect(()=>{if(!t)return;const n=i=>{!e.current||i.target instanceof Element&&i.target.closest("[data-save-recovery]")||(i.preventDefault(),i.stopImmediatePropagation())},a=["keydown","click","beforeinput","input","change","submit","trigger-line-comment"];return a.forEach(i=>window.addEventListener(i,n,!0)),()=>a.forEach(i=>window.removeEventListener(i,n,!0))},[t,e])}const wI=32*1024*1024,eB=wI,Ewe="suggestion-too-large",xj="review-too-large",ywe="cap",vwe="Bearer";function kwe(e){const n=new URLSearchParams(e.startsWith("#")?e.slice(1):e).get(ywe);return n||null}function wwe(e){return`${vwe} ${e}`}function gh(e){return(e/(1024*1024)).toFixed(1)}const Twe="review server busy; retry after pending requests finish",Swe="server-busy";class Za extends Error{constructor(t,n){super(t),this.name="ServeRequestError",this.status=n.status,this.code=n.code??null,this.details=n.details??[],this.uncertain=n.uncertain??!1}}function _we(e){return e==="/api/review"||e==="/api/apply-suggestion"?"mutation":"read"}function TI(e,t={}){const n=t.fetch??globalThis.fetch.bind(globalThis),a=wwe(e),i=new Set;let r=!1;return{async request(o,l,c,d=_we(o)){const p=d==="mutation",m=new AbortController,h=T=>new Za(p?`${T} The operation may have completed. Check the terminal and destination before continuing; do not resend it blindly.`:T,{status:null,code:p?"outcome-unknown":"request-failed",uncertain:p});if(r)throw h("This page has disconnected from the review server.");if(l.signal?.aborted)throw h("The request was cancelled.");i.add(m);let b,y=()=>{};const v=()=>m.abort(l.signal?.reason);try{const T=new Promise((S,A)=>{y=()=>A(h("The request was cancelled or timed out.")),m.signal.addEventListener("abort",y,{once:!0}),b=setTimeout(()=>m.abort(),p?t.mutationTimeoutMs??6e4:t.readTimeoutMs??3e4)});return l.signal?.addEventListener("abort",v,{once:!0}),l.signal?.aborted&&v(),await Promise.race([T,(async()=>{m.signal.throwIfAborted();const S=new Headers(l.headers);S.set("authorization",a);const A=await n(o,{...l,signal:m.signal,headers:Object.fromEntries(S.entries())});return c(A)})()])}catch(T){throw T instanceof Za?T:h(T instanceof Error?T.message:String(T))}finally{clearTimeout(b),m.signal.removeEventListener("abort",y),l.signal?.removeEventListener("abort",v),i.delete(m)}},dispose(){r=!0;for(const o of i)o.abort();i.clear()}}}const bd=e=>new Za(e,{status:null,code:"request-failed"});function Awe(e,t){let n=null,a=!1;const i=()=>{if(n)return n;const r=new AbortController,o={abort:r,settled:!1,legacy:!1,borrowers:new Set,work:e(r.signal).then(l=>{if(o.settled=!0,a||n!==o||r.signal.aborted)throw bd("The request was cancelled.");return t(l),l}).catch(l=>{throw o.settled=!0,n===o&&(n=null),l})};return n=o,o};return{prefetch:()=>a?Promise.reject(bd("This page has disconnected from the review server.")):i().work,read(r){if(a)return Promise.reject(bd("This page has disconnected from the review server."));if(r?.aborted)return Promise.reject(bd("The request was cancelled."));const o=i();return r?new Promise((l,c)=>{const d={},p=()=>{r.removeEventListener("abort",m),o.borrowers.delete(d)},m=()=>{p(),!o.settled&&n===o&&!o.legacy&&!o.borrowers.size&&(n=null,o.abort.abort()),c(bd("The request was cancelled."))};o.borrowers.add(d),r.addEventListener("abort",m,{once:!0}),o.work.then(h=>{p(),l(h)},h=>{p(),c(h)}),r.aborted&&m()}):(o.legacy=!0,o.work)},dispose(){a=!0;const r=n;n=null,r?.abort.abort()}}}function Nwe(e,t){return e===503&&!("code"in t)&&t.error===Twe}function Dl(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function Kd(e,t,n=!1){let a=null;try{a=await e.json()}catch{}const r=n&&e.status>=500&&!(Dl(a)&&e.status===503&&(a.code===Swe||Nwe(e.status,a)))?{uncertain:!0,code:"outcome-unknown"}:{};if(Dl(a)){if(a.ok===!1&&typeof a.message=="string")return new Za(a.message,{status:e.status,code:typeof a.code=="string"?a.code:null,details:Array.isArray(a.details)?a.details.filter(o=>typeof o=="string"):[]});if(typeof a.error=="string")return new Za(`${t} failed (${e.status}): ${a.error}`,{status:e.status,...r})}return new Za(`${t} failed (${e.status})`,{status:e.status,...r})}function Ij(e){return{getJson:(t,n,a)=>e.request(t,{signal:n},async i=>{if(!i.ok)throw await Kd(i,`GET ${t}`);const r=await i.json();return a?a(r):r},"read"),postJsonText:(t,n,a)=>e.request(t,{method:"POST",headers:{"content-type":"application/json"},body:n},a,"mutation"),postJson:(t,n,a,i)=>e.request(t,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n),signal:a},async r=>{if(!r.ok)throw await Kd(r,`POST ${t}`);const o=await r.json();return i?i(o):o},"read")}}const rt=e=>typeof e=="string",Qa=e=>typeof e=="boolean",yi=e=>typeof e=="number"&&Number.isFinite(e),Fi=e=>t=>Array.isArray(t)&&t.every(e),Bi=e=>t=>t===null||e(t),$s=(...e)=>t=>typeof t=="string"&&e.includes(t);function cn(e,t={}){const n=Object.entries(e),a=Object.entries(t);return i=>Dl(i)&&n.every(([r,o])=>o(i[r]))&&a.every(([r,o])=>i[r]===void 0||o(i[r]))}const hh=Fi(rt),Cwe=$s("added","modified","deleted","renamed","copied"),Rwe=cn({side:$s("old","new"),start:yi,end:yi}),xwe=cn({originalCode:rt,proposedCode:rt}),Oj=cn({id:rt,fileName:rt,mediaType:rt}),Iwe=cn({id:rt,body:rt},{author:rt,remoteId:rt,attachments:Fi(Oj)}),Owe=cn({id:rt,filePath:rt,lineRange:Bi(Rwe),body:rt,category:rt,suggestion:Bi(xwe)},{author:rt,remoteId:rt,orphaned:Qa,severity:$s("critical","major","minor","info"),confidence:$s("high","medium","low"),attachments:Fi(Oj),replies:Fi(Iwe)}),Dwe=cn({type:$s("context","addition","deletion"),content:rt,oldLineNumber:Bi(yi),newLineNumber:Bi(yi)}),Lwe=cn({header:rt,oldStart:yi,oldLines:yi,newStart:yi,newLines:yi,lines:Fi(Dwe)}),SI=Fi(Lwe),Mwe=cn({oldPath:rt,newPath:rt,changeType:Cwe,isBinary:Qa,hunks:SI},{isUntracked:Qa,contentLoaded:Qa,omittedReason:rt}),Fwe=e=>{if(!Dl(e))return!1;switch(e.type){case"git":return rt(e.gitDiffArgs)&&rt(e.repository);case"directory":case"file":return rt(e.sourcePath);case"welcome":case"loading":return!0;default:return!1}},Bwe=cn({remoteUrl:rt,remoteBaseSha:rt,remoteHeadSha:rt,remoteForge:$s("github","gitlab"),threadSyncAvailable:Qa,temporaryClone:Qa}),Pwe=cn({files:Fi(Mwe),source:Fwe},{isLargePayload:Qa,diagnostics:hh,remote:Bwe}),Uwe=cn({path:rt},{description:rt}),$we=cn({name:rt,implicit:Qa,files:Fi(Uwe)},{rationale:rt}),Hwe=cn({groups:Fi($we)},{overview:rt}),jwe=cn({resolvedOutputPath:rt,outputPathWritable:Qa}),zwe={theme:$s("light","dark","system"),diffView:$s("split","unified"),fontSize:yi,outputFormat:rt,outputFile:rt,ignore:hh,categories:Fi(cn({name:rt,description:rt,color:rt})),defaultDiffArgs:rt,showUntracked:Qa,showUntrackedExplicit:Qa,wordWrap:Qa,maxFiles:yi,maxTotalLines:yi,guideFile:rt},{guideFile:Gwe,...qwe}=zwe,Vwe=cn(qwe,{guideFile:Gwe}),Ywe=cn({comments:Fi(Owe)},{viewedFiles:hh,importDiagnostics:hh,remoteDrift:cn({recordedHeadSha:rt,liveHeadSha:rt,drifted:Qa})});function cc(e,t){return n=>{if(!t(n))throw new Za(`Malformed response from ${e}`,{status:200,code:"malformed-read-response"});return n}}const Wwe=cc("/api/diff",Bi(cn({diff:Pwe,guide:Bi(Hwe)}))),Kwe=cc("/api/config",Bi(cn({config:Vwe,outputPathInfo:Bi(jwe)}))),tB=cc("/api/resume",Bi(Ywe)),Xwe=cc("/api/file",Bi(SI)),Zwe=cc("/api/expand-context",Bi(cn({hunks:SI,totalLines:yi}))),Qwe=cc("/api/image",e=>cn({dataUri:rt})(e)||cn({error:rt})(e)),nB=32768;function Jwe(e){const t=new Uint8Array(e);let n="";for(let a=0;a<t.length;a+=nB)n+=String.fromCharCode(...t.subarray(a,a+nB));return btoa(n)}function aB(e){return e.map(t=>{const{data:n,...a}=t;return!n||n.byteLength===0?a:{...a,dataBase64:Jwe(n)}})}function eTe(e){return{timestamp:e.timestamp,source:e.source,files:e.files.map(t=>({...t,comments:t.comments.map(n=>({...n,...n.attachments?{attachments:aB(n.attachments)}:{},...n.replies?{replies:n.replies.map(a=>({...a,...a.attachments?{attachments:aB(a.attachments)}:{}}))}:{}}))}))}}async function tTe(e,t){let n;try{n=await e.json()}catch{n=null}if(Dl(n)&&n.filePath===t.filePath&&(n.status==="applied"&&typeof n.replacedLines=="number"&&Number.isSafeInteger(n.replacedLines)&&n.replacedLines>=0||n.status==="refused"&&typeof n.reason=="string"&&typeof n.detail=="string"))return n;throw new Za("The server did not return a valid Apply outcome for this file. Inspect the destination before continuing; do not apply again blindly.",{status:e.status,code:"outcome-unknown",uncertain:!0})}async function nTe(e){const t=await e.json();if(!Dl(t)||t.ok!==!0)throw new Za("The server answered without acknowledging the review as written. Check the terminal and output file before continuing; do not resend blindly.",{status:e.status,code:"outcome-unknown",uncertain:!0})}function iB(e,t){return new Za(`This review is ${gh(e)} MB as sent, over the server's ${gh(wI)} MB limit. Image attachments are the usual cause — they are base64-encoded on the wire, which adds a third — so remove or shrink some and press Finish Review again. Nothing has been lost.`,{status:t,code:xj})}function rB(e){return new Blob([e]).size}function Dy(e,t){return`${e}?path=${encodeURIComponent(t)}`}async function aTe(e,t=TI(e)){return Ij(t).getJson("/api/config",void 0,Kwe)}function iTe(e,t=TI(e)){const{getJson:n,postJson:a,postJsonText:i}=Ij(t),r={expandContext:(h,b)=>a("/api/expand-context",h,b,Zwe),loadFileContent:(h,b)=>n(Dy("/api/file",h),b,Xwe),loadImage:(h,b)=>n(Dy("/api/image",h),b,Qwe),readAttachment:(h,b)=>t.request(Dy("/api/attachment",h),{signal:b},async y=>{if(y.status===404)return null;if(!y.ok)throw await Kd(y,"Read attachment");return y.arrayBuffer()},"read")};let o=null,l=!1;const c=new Set,d=Awe(async h=>{const b=await n("/api/diff",h,Wwe);if(b===null)throw new Error("The server has no diff to review");return b},h=>{if(!l){o=h;for(const b of[...c])c.has(b)&&b(h)}});function p(h,b){const y=v=>{const T=h(v);T!==null&&b(T)};if(c.add(y),o){const v=o;Promise.resolve().then(()=>{!l&&c.has(y)&&y(v)})}else d.prefetch().catch(()=>{});return()=>{c.delete(y)}}const m=async h=>{const b=JSON.stringify(eTe(h)),y=rB(b);if(y>wI)throw iB(y,null);return i("/api/review",b,async v=>{if(v.status===413)throw iB(y,v.status);if(!v.ok)throw await Kd(v,"POST /api/review",!0);return nTe(v)})};return{reads:r,dispose:()=>{l=!0,c.clear(),d.dispose(),t.dispose()},initialReads:{loadDiff:async h=>(await d.read(h)).diff,loadResumedReview:async h=>await n("/api/resume",h,tB)??{comments:[],viewedFiles:[]}},loadDiff:async()=>(await d.read()).diff,loadResumedReview:async()=>await n("/api/resume",void 0,tB)??{comments:[],viewedFiles:[]},applySuggestion:async h=>{const b=JSON.stringify(h),y=rB(b),v=T=>new Za(`This suggestion is ${gh(y)} MB as sent, over the server's ${gh(eB)} MB limit. Shorten the proposed code before applying. Nothing was applied.`,{status:T,code:Ewe});if(y>eB)throw v(null);return i("/api/apply-suggestion",b,async T=>{if(T.status===413)throw v(413);if(!T.ok)throw await Kd(T,"POST /api/apply-suggestion",!0);return tTe(T,h)})},submitReview:m,publishReview:m,expandContext:h=>r.expandContext(h),loadFileContent:h=>r.loadFileContent(h),loadImage:h=>r.loadImage(h),readAttachment:async h=>r.readAttachment(h),onGuideLoad:h=>p(b=>b.guide,h),onDiffLoad:h=>p(b=>b.diff,h)}}function rTe(e){const[t,n]=w.useState(0),[a,i]=w.useState(null),[r,o]=w.useState(null),l=w.useRef(null),c=w.useCallback(()=>{const p=l.current;!p||p.capability!==e||p.connected||p.unauthorized||(p.retire(),n(m=>m+1))},[e]);w.useEffect(()=>{if(e===null)return;let p=!0;const m=TI(e),h=iTe(e,m),b={capability:e,revision:t,connected:!1,unauthorized:!1,retire:()=>{p=!1,h.dispose()}};return l.current=b,i(null),o(null),aTe(e,m).then(y=>{p&&l.current===b&&(b.connected=!0,i({adapter:h,config:y?.config??{},outputPathInfo:y?.outputPathInfo??null}))},y=>{p&&l.current===b&&(b.unauthorized=y instanceof Za&&y.status===401,o({message:y instanceof Error?y.message:String(y),unauthorized:b.unauthorized}),b.retire())}),b.retire},[e,t]);const d=e!==null&&l.current?.capability===e&&l.current.revision===t;return{connection:d?a:null,error:d?r:null,retry:c}}function sB(e){return e instanceof Za?{code:e.code,message:e.message,details:e.details,uncertain:e.uncertain}:{code:null,message:e instanceof Error?e.message:String(e),details:[]}}function sTe({onChange:e}){const t=Jb(),n=uI();return w.useEffect(e,[e,t,n]),null}function oTe(e,t){const[n,a]=w.useState("reviewing"),[i,r]=w.useState(null),[o,l]=w.useState(!1),c=w.useRef(!1),d=w.useRef(null),p=w.useRef(!0),m=w.useCallback(()=>l(!0),[]),h=w.useCallback(()=>{!d.current||d.current.current()||(d.current=null,c.current=!1,a("reviewing"),r(null))},[]);bwe(c),w.useEffect(()=>(p.current=!0,()=>{p.current=!1}),[]),w.useEffect(()=>{if(n==="submitted"||!o&&n!=="submitting"&&n!=="uncertain")return;const v=T=>T.preventDefault();return window.addEventListener("beforeunload",v),()=>window.removeEventListener("beforeunload",v)},[o,n]);const b=w.useCallback(async()=>{if(c.current||n==="submitted"||!t)return;let v;try{const T=e.current?.beginSave;if(!T)throw new Error("The review is not ready to save.");v=T()}catch(T){r(sB(T)),a("failed");return}d.current=v,c.current=!0,a("submitting"),r(null);try{if(!t.publishReview)throw Object.assign(new Error("Publication is unavailable."),{uncertain:!1});if(await t.publishReview(v.state),!p.current||d.current!==v||!v.current())return;c.current=!1,a("submitted")}catch(T){if(!p.current||d.current!==v||!v.current())return;const S=typeof T=="object"&&T!==null&&"uncertain"in T&&T.uncertain===!1;S&&(v.unlock(),d.current=null,c.current=!1),r({...sB(T),uncertain:!S}),a(S?"failed":"uncertain")}},[t,e,n]),y=w.useCallback(()=>{n!=="uncertain"||!window.confirm("Have you checked the terminal and output file and confirmed that this review was not saved? Only allow a retry if the original server is still running.")||(d.current?.unlock(),d.current=null,c.current=!1,a("reviewing"),r(null))},[n]);return{status:n,failure:i,finish:b,allowRetry:y,markUnsaved:m,sessionChanged:h}}function uTe(){const e=kwe(window.location.hash);return window.location.hash!==""&&window.history.replaceState(window.history.state,"",window.location.pathname+window.location.search),e}function lTe(){return E.jsxs(bh,{title:"Open the URL printed in the terminal",children:[E.jsxs("p",{"data-testid":"capability-notice",children:["This page needs the exact URL ",E.jsx("code",{children:"self-review-serve"})," printed when it started. The part after ",E.jsx("code",{children:"#"})," is this session's key, and a reloaded or retyped address does not have it."]}),E.jsx("p",{children:"Copy the URL from the terminal again and open it in this tab. If the terminal is gone, or the server has been restarted since, stop it and start it again: a fresh URL is printed every time."})]})}function cTe({info:e}){const{setOutputPathInfo:t}=B1e();return w.useEffect(()=>{e&&t(e)},[e,t]),null}function dTe({onChange:e}){const{files:t}=Zb(),n=DEe(),a=TH();w.useEffect(()=>{const r=o=>{a()&&o.preventDefault()};return window.addEventListener("beforeunload",r),()=>window.removeEventListener("beforeunload",r)},[a]);const i=w.useRef(t);return w.useEffect(()=>{const r=i.current;i.current=t,(n||t.some(o=>o.viewed||o.comments.length>0)||r.some(o=>{const l=t.find(c=>c.path===o.path);return l&&(l.viewed!==o.viewed||l.comments!==o.comments)}))&&e()},[t,n,e]),null}function fTe({outputPath:e}){return E.jsxs(bh,{title:"Review saved",children:[E.jsxs("p",{children:["The review was written to ",e?E.jsx("code",{children:e}):"the output file"," and the server has stopped."]}),E.jsxs("p",{children:["You can close this tab. To keep reviewing, start the server again with"," ",E.jsx("code",{children:"--resume-from"}),"."]})]})}function pTe({failure:e}){const t=!e.uncertain&&e.code!==xj;return E.jsxs("div",{role:"alert","data-testid":"submit-error",style:{padding:"0.5rem 0.75rem",background:"#7f1d1d",color:"#fff",fontSize:"0.8125rem",lineHeight:1.4},children:[E.jsxs("div",{children:[E.jsxs("strong",{children:[e.uncertain?"The save outcome is unknown":"The review was not saved",e.code?` (${e.code})`:"",":"]})," ",e.message]}),e.details.length>0&&E.jsx("ul",{style:{margin:"0.25rem 0 0",paddingLeft:"1.25rem"},children:e.details.map((n,a)=>E.jsx("li",{children:n},a))}),e.uncertain&&E.jsx("div",{children:"Your comments are still here. Check the terminal and the output file on the server. Stop the original process before restarting with --resume-from if the file was saved. If it was not saved and the original server is still running, you can allow a retry below. Keep this page open to preserve unsaved comments. No submission is retried automatically."}),t&&E.jsx("div",{style:{marginTop:"0.25rem"},children:"Your comments are still here. Fix the problem on the machine running the server, then press Finish Review again."})]})}function bh({title:e,children:t}){return E.jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:"2rem"},children:E.jsxs("div",{style:{maxWidth:"34rem",lineHeight:1.5},children:[E.jsx("h1",{style:{fontSize:"1.25rem",margin:"0 0 0.75rem"},children:e}),t]})})}function mTe(e){return E.jsx(gTe,{...e},e.capability)}function gTe({capability:e}){const{connection:t,error:n,retry:a}=rTe(e),i=t?.adapter??null,r=t?.config??null,o=t?.outputPathInfo??null,l=w.useRef(null),{status:c,failure:d,finish:p,allowRetry:m,markUnsaved:h,sessionChanged:b}=oTe(l,i);return e===null||n?.unauthorized?E.jsx(lTe,{}):n?E.jsxs(bh,{title:"Could not reach the review server",children:[E.jsxs("div",{role:"alert",children:[E.jsx("p",{children:n.message}),E.jsx("p",{children:"The process that served this page may have exited."})]}),E.jsx(Ye,{onClick:a,children:"Retry connection"})]}):c==="submitted"?E.jsx(fTe,{outputPath:o?.resolvedOutputPath??null}):!r||!i?E.jsx(bh,{title:"Connecting to the review server",children:E.jsx("p",{role:"status",children:"Waiting for the review server."})}):E.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[(c==="failed"||c==="uncertain")&&d&&E.jsx(pTe,{failure:d}),c==="uncertain"&&E.jsx("div",{className:"p-2","data-save-recovery":!0,children:E.jsx(Ye,{variant:"outline",onClick:m,children:"Allow retry after checking output"})}),E.jsx("div",{inert:c==="submitting"||c==="uncertain","aria-busy":c==="submitting","data-testid":"review-interaction",style:{flex:1,display:"flex",minHeight:0},children:E.jsxs(swe,{ref:l,adapter:i,config:r,className:"flex-1 flex flex-col overflow-hidden bg-background text-foreground",children:[E.jsx(sTe,{onChange:b}),E.jsx(dTe,{onChange:h}),E.jsx(cTe,{info:o}),E.jsx(mwe,{}),E.jsx(fwe,{onFinishReview:c==="uncertain"?void 0:()=>{p()}})]})})]})}const oB=document.getElementById("root");oB&&JG.createRoot(oB).render(E.jsx(mTe,{capability:uTe()}));export{nq as _,Po as g};
311
+ `)}function Zve(e,t){return t[e-1]?.lineNumber??e}function cj({label:e,onStartDrag:t,onActivate:n,className:a,onKeyDown:i,...r}){return E.jsx(Ye,{...r,type:"button",variant:"ghost",size:"icon","aria-label":e,"data-comment-gutter":!0,className:`h-[22px] w-7 p-0 text-blue-600 dark:text-blue-400 focus-visible:opacity-100 ${a??""}`,onMouseDown:o=>{o.button===0&&(o.preventDefault(),o.stopPropagation(),(t??n)())},onClick:o=>{o.stopPropagation(),o.detail===0&&n()},onKeyDown:o=>{i?.(o),!(o.defaultPrevented||r.disabled)&&(o.key!=="Enter"&&o.key!==" "||(o.preventDefault(),o.stopPropagation(),n()))},children:null})}function dj(e){return`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(e)))}`}var GF="http://www.w3.org/2000/svg";function Qve(e){if(e.length>1e6)throw new wl("size");const t=new DOMParser().parseFromString(e,"image/svg+xml"),n=t.documentElement;if(!n||t.getElementsByTagName("parsererror").length>0||n.namespaceURI!==GF||n.localName!=="svg")throw new wl("svg");const a=(n.getAttribute("viewBox")??"").trim().split(/[\s,]+/).map(Number),[,,i,r]=a.length===4?a:[],o=i!==void 0&&i>0&&r!==void 0&&r>0;if(o&&(!Number.isFinite(i)||!Number.isFinite(r)||i>16384||r>16384||i*r>64e6))throw new wl("size");const l=(c,d)=>Array.from(n.children).find(p=>p.namespaceURI===GF&&p.localName===c)?.textContent?.trim().slice(0,d)||void 0;return{title:l("title",1e3),description:l("desc",4e3),src:dj(e),width:o?Math.ceil(i):void 0,height:o?Math.ceil(r):void 0}}function Jve({code:e}){const[t,n]=w.useState({status:"pending"}),[a,i]=w.useState(0),r=W$(),o=w.useId(),l=$H(),{t:c}=We();return w.useEffect(()=>{if(e.length>dh){n({status:"error",message:c("Diagram source is too large ({count} characters; the limit is {limit})",{count:e.length,limit:dh})});return}if(BH(e)){n({status:"error",message:c("Diagram exceeds the layout complexity limits. Read the source below.")});return}let d=!1;const p=new AbortController,m=b=>{d||(d=!0,n(b))};n({status:"pending"});const h=window.setTimeout(()=>{m({status:"error",message:c("Rendering timed out after {seconds} seconds. Synchronous layout cannot be interrupted.",{seconds:MF/1e3})}),p.abort()},MF);return Promise.resolve().then(()=>l.render({source:e,theme:r,signal:p.signal})).then(({svg:b})=>m({status:"rendered",image:Qve(b)})).catch(b=>m({status:"error",message:b instanceof wl?c(b.kind==="svg"?"The diagram did not render to a well-formed SVG image":b.kind==="busy"?"Too many diagrams are waiting. Retry after another diagram finishes.":"Diagram output exceeds the image size limit."):c("Failed to render diagram. {detail}",{detail:b instanceof Error?b.message:String(b)})})).finally(()=>window.clearTimeout(h)),()=>{d=!0,p.abort(),window.clearTimeout(h)}},[e,r,a,c,l]),t.status==="error"?E.jsxs("div",{"data-testid":"mermaid-error",className:"text-sm p-2 border border-destructive/20 rounded",children:[E.jsx("p",{role:"alert",className:"text-destructive",children:c("Mermaid error: {detail}",{detail:t.message})}),E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>i(d=>d+1),children:c("Retry")}),E.jsxs("details",{open:!0,children:[E.jsx("summary",{children:c("Diagram source")}),E.jsx("pre",{className:"overflow-auto whitespace-pre-wrap",children:e})]})]}):t.status==="pending"?E.jsx("div",{role:"status",className:"animate-pulse bg-muted p-2 h-32 rounded",children:c("Rendering diagram...")}):E.jsxs("figure",{className:"mermaid-block max-w-full rounded-lg border border-border bg-white dark:bg-muted/20 p-4",children:[E.jsx("div",{className:"flex justify-center overflow-x-auto",children:E.jsx("img",{src:t.image.src,alt:t.image.title??c("Mermaid diagram"),"aria-describedby":t.image.description?o:void 0,width:t.image.width,height:t.image.height,style:{maxWidth:"100%",height:"auto"}})}),E.jsxs("figcaption",{className:"mt-2 text-sm",children:[t.image.description&&E.jsx("p",{id:o,children:t.image.description}),E.jsxs("details",{children:[E.jsx("summary",{children:c("Diagram source")}),E.jsx("pre",{className:"overflow-auto whitespace-pre-wrap",children:e})]})]})]})}function fj({className:e,children:t,node:n,...a}){const i=/language-(\w+)/.exec(e||""),r=i?i[1]:"",o=String(t).replace(/\n$/,""),l=n?.position;if(r==="mermaid"&&l)return E.jsx(Jve,{code:o});if(o.length<=hI&&r&&Ao.languages[r]){const c=Ao.highlight(o,Ao.languages[r],r);return E.jsx("code",{className:e,dangerouslySetInnerHTML:{__html:c},...a})}return E.jsx("code",{className:e,...a,children:t})}var xy=w.createContext(!1),pj=w.createContext(null);function mj(){const e=w.useContext(pj);if(!e)throw new Error("Rendered blocks must be rendered inside RenderedMarkdownView");return e}var eke=new Set(["p","h1","h2","h3","h4","h5","h6","blockquote","pre","li","details"]),tke=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),nke=["p","h1","h2","h3","h4","h5","h6","ul","ol","li","blockquote","pre","table","hr","details"],gj=["address","article","aside","blockquote","details","div","dl","figcaption","figure","footer","h1","h2","h3","h4","h5","h6","header","hr","li","main","nav","ol","p","pre","section","table","ul"],ake=new Set(gj),ike=new Set(["article","aside","div","footer","header","main","nav","section"]);function rke(e){return e.children.some(t=>t.type==="element"&&ake.has(t.tagName))}function ske({startLine:e,endLine:t,children:n,tag:a,className:i,tagProps:r}){const{t:o,number:l}=We(),{commentRange:c,onGutterMouseDown:d}=mj();if(w.useContext(xy)||e===void 0||t===void 0)return E.jsx(a,{className:i,...r,children:n});const m=e===t?`${l(e)}`:`${l(e)}-${l(t)}`,h=tke.has(a),b=eke.has(a),y=b?"span":"div",v=E.jsxs(y,{className:"rendered-gutter absolute start-0 top-0 w-16 text-end pe-2 select-none cursor-pointer text-[11px] text-muted-foreground",style:{lineHeight:"inherit"},onMouseDown:A=>{A.preventDefault(),A.stopPropagation(),d(e,t)},children:[E.jsx(cj,{className:"absolute start-0 top-0 h-[1lh] opacity-0 group-hover/rendered-block:opacity-100",label:e===t?o("Comment on line {line}",{line:e}):o("Comment on lines {start} to {end}",{start:e,end:t}),onActivate:()=>d(e,t)}),E.jsx("span",{className:"pointer-events-none",children:m})]}),T=c?.side==="new"&&c.start<=t&&c.end>=e,S=[i,"rendered-block group/rendered-block relative",T?"bg-blue-100 dark:bg-blue-900/30":""].filter(Boolean).join(" ");return b?E.jsx(xy.Provider,{value:!0,children:E.jsxs(a,{className:S,"data-source-start-line":e,"data-source-end-line":t,style:{paddingInlineStart:"4rem"},...r,children:[v,n]})}):E.jsx(xy.Provider,{value:!0,children:E.jsxs("div",{className:"rendered-block group/rendered-block relative","data-source-start-line":e,"data-source-end-line":t,style:{paddingInlineStart:"4rem"},children:[v,h?E.jsx(a,{className:i,...r}):E.jsx(a,{className:i,...r,children:n})]})})}function oke(e,t=!1){function n({node:a,children:i,...r}){const{resolveLine:o}=mj(),l=a?.position,c=l!==void 0&&!(t&&a&&rke(a)),d=c?o(l.start.line):void 0,p=c?o(l.end.line):void 0;return E.jsx(ske,{startLine:d,endLine:p,tag:e,tagProps:r,children:i})}return n.displayName=`RenderedBlock(${e})`,n}function hj(e,t=new Set){const n={};for(const a of e)n[a]=oke(a,t.has(a));return n}var uke={...hj(nke),code:fj,img:up},lke={...hj(gj,ike),img:up},cke=[jf,n0],dke=[pA,sp];function fke({content:e}){return w.useMemo(()=>gA(pve(e),{Fragment:E.Fragment,jsx:E.jsx,jsxs:E.jsxs,components:lke,ignoreInvalidStyle:!0,passKeys:!0,passNode:!0}),[e])}function pke({content:e,contentMode:t,context:n}){return E.jsx(pj.Provider,{value:n,children:t==="markdown"?E.jsx(Fb,{urlTransform:op,remarkPlugins:cke,rehypePlugins:dke,components:uke,children:e}):E.jsx(fke,{content:e})})}var mke=[];function gke({file:e,contentMode:t,commentRange:n,onCancelComment:a,onCommentSaved:i,onGutterMouseDown:r}){const{t:o}=We(),l=w.useMemo(()=>Kve(e),[e]),c=w.useMemo(()=>Xve(l),[l]),d=w.useMemo(()=>t==="markdown"?$ve(c):null,[c,t]),p=d?d.body:c,m=d?d.lineOffset:0,h=e.newPath||e.oldPath,b=oI(h)?.comments??mke,y=w.useMemo(()=>aI(e),[e]),v=w.useMemo(()=>b.filter(A=>A.lineRange!==null&&y(A)),[b,y]),T=w.useMemo(()=>A=>Zve(A+m,l),[l,m]),S=w.useMemo(()=>({commentRange:n,resolveLine:T,onGutterMouseDown:r}),[n,T,r]);return E.jsxs(E.Fragment,{children:[E.jsxs("div",{className:"prose dark:prose-invert max-w-none p-4 rendered-markdown-view","data-rendered-text-mode":t,children:[d&&E.jsx(Wve,{metadata:d.metadata}),E.jsx(pI,{documentPath:h,children:E.jsx(pke,{content:p,contentMode:t,context:S})})]}),(v.length>0||n)&&E.jsxs("section",{"aria-label":o("Comments on source lines"),className:"space-y-3 border-t border-border bg-muted/30 p-4",children:[v.map(A=>{const N=A.lineRange?fh(e,A.lineRange):void 0;return E.jsxs("div",{children:[E.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:A.lineRange?.start===A.lineRange?.end?o("Line {line}",{line:A.lineRange.start}):o("Lines {start} to {end}",{start:A.lineRange.start,end:A.lineRange.end})}),E.jsx(ph,{comment:A,originalCode:N,anchorFullyVisible:N!==void 0})]},A.id)}),n&&E.jsx(rp,{filePath:h,lineRange:n,onCancel:a,onSubmit:i,originalCode:fh(e,n)})]})]})}function hke({filePath:e,onLoadImage:t}){const{t:n,number:a}=We(),i=_i(),r=uc(),[o,l]=w.useState(0),c=w.useMemo(()=>({}),[e,t,i,r,o]),d=w.useRef(c);d.current=c;const[p,m]=w.useState(null),h=p?.request===c?p:null,{dataUri:b,error:y,dimensions:v}=h??{},T=!h;return w.useEffect(()=>{d.current=c;const S=new AbortController,A=()=>!S.signal.aborted&&d.current===c;return!t&&!i?.reads?.loadImage&&!i?.loadImage?m({request:c,error:{unsupported:!0}}):(async()=>t&&t!==i?.loadImage?t(e):oH(i,e,S.signal))().then(x=>{A()&&(x?"error"in x?m({request:c,error:{detail:x.error}}):typeof x.dataUri=="string"&&kf(x.dataUri)?m({request:c,dataUri:x.dataUri}):m({request:c,error:{}}):m({request:c,error:{}}))},x=>{A()&&m({request:c,error:{detail:x instanceof Error?x.message:void 0}})}),()=>{S.abort(),d.current===c&&(d.current=null)}},[e,t,i,c]),T?E.jsxs("div",{role:"status","aria-label":n("Loading image..."),className:"flex justify-center items-center p-8",children:[E.jsx(tk,{"aria-hidden":"true",className:"h-6 w-6 animate-spin text-muted-foreground"}),E.jsx("span",{className:"sr-only",children:n("Loading image...")})]}):y||!b?E.jsxs("div",{role:"alert","aria-label":n("Image preview unavailable"),className:"flex flex-col justify-center items-center p-8 text-sm text-muted-foreground",children:[E.jsx("p",{children:n(y?.unsupported?"Image loading not supported in this context.":"Failed to load image.")}),y?.detail&&E.jsx("p",{children:y.detail}),!y?.unsupported&&E.jsx(Ye,{variant:"outline",size:"sm",onClick:()=>l(S=>S+1),children:n("Retry")})]}):E.jsxs("div",{className:"flex flex-col items-center p-4 gap-2",children:[E.jsx("img",{src:b,alt:e,onError:()=>{d.current===c&&m({request:c,error:{}})},style:{maxWidth:"100%",maxHeight:"80vh",objectFit:"contain"},onLoad:S=>{const A=S.currentTarget;d.current===c&&m({request:c,dataUri:b,dimensions:{w:A.naturalWidth,h:A.naturalHeight}})}}),v&&E.jsxs("span",{className:"text-xs text-muted-foreground",children:[a(v.w)," × ",a(v.h)]})]})}function bke(e){return e.hunks.flatMap(t=>t.lines).filter(t=>t.type==="addition").map(t=>t.content).join(`
312
+ `)}function Eke({file:e}){const{t}=We(),[n,a]=w.useState(!1);w.useEffect(()=>a(!1),[e]);const i=w.useMemo(()=>bke(e),[e]);if(!i.trim()||n)return E.jsx("div",{role:"alert","aria-label":t("SVG preview unavailable"),className:"flex justify-center items-center p-8 text-sm text-muted-foreground",children:t(n?"Failed to load SVG preview.":"SVG content could not be extracted.")});const r=dj(i);return E.jsx("div",{className:"flex justify-center p-4",children:E.jsx("img",{src:r,alt:e.newPath||e.oldPath||t("SVG preview"),onError:()=>a(!0),style:{maxWidth:"100%",maxHeight:"80vh",objectFit:"contain"}})})}function yke({file:e,filePath:t,preview:n,descriptor:a,mode:i,commentRange:r,onCommentRange:o,onCancelComment:l,onCommentSaved:c,children:d}){const p=_i(),m=fI(),h=uc(),b=w.useCallback((N,x)=>o(N,x,"new"),[o]),y=a??XH(e,m,n),v=y.builtIn,T=y.renderer,S=i==="rendered"&&(T||v.kind!=="none"&&(v.kind!=="text"||!e.isBinary&&e.hunks.length>0)),A=()=>{switch(v.kind){case"image":return E.jsx(hke,{filePath:t,onLoadImage:p?.loadImage},h);case"svg":return E.jsx(Eke,{file:e});case"text":return e.isBinary||e.hunks.length===0?null:E.jsx(gke,{file:e,contentMode:v.mode,commentRange:r,onCancelComment:l,onCommentSaved:c,onGutterMouseDown:b})}return null};if(S){if(T){const N=T.component;return E.jsx(N,{file:e,filePath:t,preview:v,commentRange:r,onCommentRange:o,onCancelComment:l,onCommentSaved:c,children:A()})}return A()}return d}function qF(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\t/g," ")}function vke(e,t,n){if(t.length>hI||n==="plaintext")return null;try{const a=e.languages[n];return!a||n==="plaintext"?qF(t):e.highlight(t,a,n)}catch(a){return console.error(`[Prism] Error for ${n}:`,a),qF(t)}}var kke=Bt.memo(function({content:t,language:n,lineType:a,wordWrap:i}){const r=w.useMemo(()=>vke(Ao,t,n),[t,n]);return E.jsx("code",{className:`font-mono sr-diff-code ${i?"whitespace-pre-wrap":"whitespace-pre"} block`,dangerouslySetInnerHTML:r===null?void 0:{__html:r},children:r===null?t.replace(/\t/g," "):void 0})}),wke=kke;function bj(e){const t=w.useRef(e);return w.useLayoutEffect(()=>{t.current=e},[e]),w.useCallback((...n)=>t.current(...n),[])}var Ej=Bt.memo(function({layout:t,filePath:n,oldLineNumber:a,newLineNumber:i,lineType:r,content:o,language:l,wordWrap:c,isSelected:d,hasComment:p,rowIndex:m,onDragStart:h}){const{t:b}=We(),y=t==="unified",v=y?r==="deletion"?"old":"new":t,T=v==="old"?a:i,S={type:r},A=(N,x)=>{const I=y?`gutter-${N}`:"gutter",O=y?m:x;return E.jsxs("div",{className:`w-10 flex-shrink-0 text-end pe-2 text-[11px] leading-[22px] text-muted-foreground select-none ${Aye(S)} ${I==="gutter-old"?"group/gutter-old":I==="gutter-new"?"group/gutter-new":"group/gutter"} relative`,"data-testid":x?`${N}-line-${n}-${x}`:void 0,children:[x&&E.jsx(cj,{className:`absolute start-0 top-1/2 -translate-y-1/2 opacity-0 ${I==="gutter-old"?"group-hover/gutter-old:opacity-100":I==="gutter-new"?"group-hover/gutter-new:opacity-100":"group-hover/gutter:opacity-100"}`,label:b(N==="old"?"Comment on old line {line}":"Comment on new line {line}",{line:x}),onStartDrag:()=>h(O,N),onActivate:()=>h(O,N,!0),"data-testid":`comment-icon-${N}-${x}`}),E.jsx("span",{className:"pointer-events-none",children:x||""})]})};return E.jsxs("div",{className:`${y?"flex":"split-half w-1/2 flex"} ${d?"bg-blue-100 dark:bg-blue-900/30":_ye(S)} ${p?"shadow-[inset_4px_0_0_0_#d97706] dark:shadow-[inset_4px_0_0_0_#fcd34d]":""} ${r==="addition"?"diff-line-addition":""} ${r==="deletion"?"diff-line-deletion":""}`,style:y?{contentVisibility:"auto",containIntrinsicSize:"auto 26px"}:void 0,"data-line-number":T||void 0,"data-line-side":v,"data-line-type":r,"data-row-index":y?m:void 0,children:[(y||v==="old")&&A("old",a),(y||v==="new")&&A("new",i),E.jsx("span",{role:"img","aria-label":b(r==="addition"?"Added line":r==="deletion"?"Removed line":"Unchanged line"),className:"w-4 shrink-0 select-none text-center leading-[26px] font-mono",style:{userSelect:"none"},children:E.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"inline-block size-3",fill:"none",stroke:"currentColor",children:r==="addition"?E.jsx("path",{d:"M8 3v10M3 8h10"}):r==="deletion"?E.jsx("path",{d:"M3 8h10"}):E.jsx("path",{d:"M3 6h10M3 10h10"})})}),E.jsx("div",{className:`flex-1 px-3 py-0.5 leading-[22px]${c?"":" [overflow-x:overlay]"}`,children:E.jsx(wke,{content:o,language:l,lineType:r,wordWrap:c})})]})}),VF=[];function Tke(e){const t=oI(e.newPath||e.oldPath)?.comments??VF;return w.useMemo(()=>{const n=new Map,a=new Set,i=aI(e);for(const r of t){const o=r.lineRange;if(!o||!i(r))continue;const l=`${o.side}:${o.end}`;n.set(l,[...n.get(l)??[],r]);for(let c=o.start;c<=o.end;c++)a.add(`${o.side}:${c}`)}return{endingAt:(r,o)=>n.get(`${o}:${r}`)??VF,covers:(r,o)=>a.has(`${o}:${r}`)}},[e,t])}function YF(e,t){return e.length===0?t:t.length===0?e:[...e,...t]}function yj(e,t){const n=Tke(e),a=w.useMemo(()=>t?fh(e,t):void 0,[e,t]),i=w.useMemo(()=>{let r=0;return e.hunks.map(o=>{const l=r;return r+=o.lines.length,l})},[e.hunks]);return{commentIndex:n,originalCode:a,rowOffsets:i,getOriginalCodeForComment:r=>r.lineRange?fh(e,r.lineRange):void 0,feedbackAt:(r,o,l)=>{const c=n.endingAt(r,"old"),d=n.endingAt(o,"new");return{comments:l==="old"?YF(c,d):YF(d,c),showInput:!!t&&(t.side==="old"?r:o)===t.end}}}}function Ske({header:e}){return E.jsx("div",{className:"hunk-header flex items-center h-7 px-3 text-xs font-mono bg-blue-500/10 dark:bg-blue-400/15 text-blue-700 dark:text-blue-300",children:e})}function _ke({position:e,hunkIndex:t,gapSize:n,onExpand:a,loading:i}){const{t:r}=We();if(n!==void 0&&n<=0)return null;const o=n!==void 0&&n<=20,l=(c,d,p)=>E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"ghost",type:"button",className:"flex items-center justify-center w-5 h-5 rounded-sm text-blue-700 dark:text-blue-300 hover:text-blue-900 dark:hover:text-blue-100 hover:bg-blue-500/20 dark:hover:bg-blue-400/20 transition-colors cursor-pointer",onClick:m=>{m.stopPropagation(),a(c,t,e)},disabled:i,"aria-label":p,children:E.jsx(d,{className:"h-3.5 w-3.5"})})}),E.jsx(Gt,{side:"right",children:p})]});return E.jsxs("div",{className:"expand-context-bar flex items-center h-[26px] bg-blue-500/10 dark:bg-blue-400/15 text-blue-700 dark:text-blue-300 select-none",children:[E.jsx("div",{className:"w-10 flex-shrink-0 flex items-center justify-center gap-0.5",children:i?E.jsx("span",{className:"text-[10px] text-muted-foreground",children:"..."}):o?l("all",OK,r("Show hidden lines",{count:n})):E.jsxs(E.Fragment,{children:[(e==="top"||e==="between")&&l("up",OP,r("Expand up")),(e==="bottom"||e==="between")&&l("down",ek,r("Expand down"))]})}),E.jsx("div",{className:"flex-1 px-2",children:o?E.jsx(Ye,{variant:"ghost",type:"button",className:"text-[11px] text-blue-700 dark:text-blue-300 hover:text-blue-900 dark:hover:text-blue-100 transition-colors cursor-pointer",onClick:()=>a("all",t,e),disabled:i,children:r("Show hidden lines",{count:n})}):E.jsx(Ye,{variant:"ghost",type:"button",className:"text-[11px] text-blue-700 dark:text-blue-300 hover:text-blue-900 dark:hover:text-blue-100 transition-colors cursor-pointer",onClick:()=>a("all",t,e),disabled:i,children:r("Show all hidden lines")})})]})}function Ake(e,t,n){if(e.length===0)return null;if(t===e.length){const i=e[t-1];return{position:"bottom",hunkIndex:t-1,gapSize:n==null?void 0:n-(i.newStart+i.newLines-1)}}const a=e[t];return{position:t===0?"top":"between",hunkIndex:t,gapSize:t===0?Math.max(a.oldStart,a.newStart)-1:a.newStart-(e[t-1].newStart+e[t-1].newLines)}}function mh({hunks:e,hunkIndex:t,isExpandable:n,onExpandContext:a,expandLoading:i,totalLines:r}){const o=n&&a?Ake(e,t,r):null;return E.jsxs(E.Fragment,{children:[o&&a&&E.jsx(_ke,{...o,onExpand:a,loading:i}),e[t]&&E.jsx(Ske,{header:e[t].header})]})}function vj({commentsToRender:e,showCommentInput:t,commentRange:n,filePath:a,originalCode:i,onCancel:r,onSaved:o,indentClass:l="",getOriginalCodeForComment:c}){return!t&&e.length===0?null:E.jsxs(E.Fragment,{children:[e.length>0&&E.jsx("div",{className:`border-y border-border bg-muted/50 px-4 py-3 space-y-2${l?` ${l}`:""}`,children:e.map(d=>{const p=c?.(d);return E.jsx(ph,{comment:d,originalCode:p,anchorFullyVisible:!c||d.lineRange===null||p!==void 0},d.id)})}),t&&n&&E.jsx("div",{className:`border-y border-border bg-muted/50 px-4 py-3${l?` ${l}`:""}`,children:E.jsx(rp,{filePath:a,lineRange:{side:n.side,start:n.start,end:n.end},onCancel:r,onSubmit:o,originalCode:i})})]})}function Nke({file:e,commentRange:t,dragState:n,onDragStart:a,onCancelComment:i,onCommentSaved:r,onExpandContext:o,isExpandable:l,expandLoading:c,totalLines:d}){const{t:p}=We(),m=bj(a),{commentIndex:h,originalCode:b,rowOffsets:y,feedbackAt:v,getOriginalCodeForComment:T}=yj(e,t),S=w.useMemo(()=>lj(e),[e]),A=ip(),N=KH(e.newPath||e.oldPath),x=e.newPath||e.oldPath;return E.jsxs("div",{className:"font-mono text-[13px] leading-[22px] unified-view",children:[S.limited&&E.jsx("p",{role:"status",className:"px-3 py-1 text-xs font-sans text-muted-foreground",children:p("Highlighting is limited for this file. All source lines remain available.")}),e.hunks.map((I,O)=>E.jsxs("div",{children:[E.jsx(mh,{hunks:e.hunks,hunkIndex:O,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d}),I.lines.map((D,M)=>{const B=y[O]+M,F=D.type==="deletion"?D.oldLineNumber:D.newLineNumber,G=D.type==="deletion"?"old":"new",{comments:z,showInput:W}=v(D.oldLineNumber,D.newLineNumber,"new"),ie=h.covers(F,G)||D.type==="context"&&h.covers(D.oldLineNumber,"old"),te=t?.side==="old"?D.oldLineNumber:D.newLineNumber,K=t&&te!==null&&te>=t.start&&te<=t.end,ne=n!==null&&B>=Math.min(n.startLine,n.currentLine)&&B<=Math.max(n.startLine,n.currentLine),Q=!!(K||ne);return E.jsxs(Bt.Fragment,{children:[E.jsx(Ej,{layout:"unified",filePath:x,oldLineNumber:D.oldLineNumber,newLineNumber:D.newLineNumber,lineType:D.type,content:D.content,language:S.lines.has(D)?N:"plaintext",wordWrap:A.wordWrap,isSelected:Q,hasComment:ie,rowIndex:B,onDragStart:m}),(z.length>0||W)&&E.jsx(vj,{commentsToRender:z,showCommentInput:!!W,commentRange:t,filePath:e.newPath||e.oldPath,originalCode:b,onCancel:i,onSaved:r,indentClass:"ms-[100px]",getOriginalCodeForComment:T})]},`${O}-${M}`)})]},O)),E.jsx(mh,{hunks:e.hunks,hunkIndex:e.hunks.length,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d})]})}function Cke(e){const t=[];let n=0;for(;n<e.length;){const a=e[n];if(a.type==="context")t.push({oldLine:a,newLine:a}),n++;else if(a.type==="deletion"){const i=[];for(;n<e.length&&e[n].type==="deletion";)i.push(e[n]),n++;const r=[];for(;n<e.length&&e[n].type==="addition";)r.push(e[n]),n++;const o=Math.max(i.length,r.length);for(let l=0;l<o;l++)t.push({oldLine:l<i.length?i[l]:null,newLine:l<r.length?r[l]:null})}else a.type==="addition"&&t.push({oldLine:null,newLine:a}),n++}return t}function Iy(){return E.jsxs("div",{className:"w-1/2 flex",children:[E.jsx("div",{className:"w-10 flex-shrink-0 bg-muted/20"}),E.jsx("div",{className:"flex-1 bg-muted/10"})]})}function Rke({file:e,commentRange:t,dragState:n,onDragStart:a,onCancelComment:i,onCommentSaved:r,onExpandContext:o,isExpandable:l,expandLoading:c,totalLines:d}){const{t:p}=We(),m=bj(a),{commentIndex:h,originalCode:b,feedbackAt:y,getOriginalCodeForComment:v}=yj(e,t),T=w.useMemo(()=>lj(e),[e]),S=ip(),A=e.newPath||e.oldPath,N=KH(A),x=(D,M)=>{if(t&&t.side===M&&D>=t.start&&D<=t.end)return!0;if(n&&n.side===M){const B=Math.min(n.startLine,n.currentLine),F=Math.max(n.startLine,n.currentLine);if(D>=B&&D<=F)return!0}return!1},I=w.useMemo(()=>e.hunks.map(D=>Cke(D.lines)),[e.hunks]),O=(D,M,B=!1)=>{if(!D)return E.jsx(Iy,{});const F=M==="old"?D.oldLineNumber:D.newLineNumber,G=F?x(F,M):!1;return E.jsx(Ej,{layout:M,filePath:A,oldLineNumber:D.oldLineNumber,newLineNumber:D.newLineNumber,lineType:D.type,content:D.content,language:T.lines.has(D)?N:"plaintext",wordWrap:S.wordWrap,isSelected:G,hasComment:B,onDragStart:m})};return E.jsxs("div",{className:"font-mono text-[13px] leading-[22px] split-view",children:[T.limited&&E.jsx("p",{role:"status",className:"px-3 py-1 text-xs font-sans text-muted-foreground",children:p("Highlighting is limited for this file. All source lines remain available.")}),e.hunks.map((D,M)=>E.jsxs("div",{children:[E.jsx(mh,{hunks:e.hunks,hunkIndex:M,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d}),I[M].map((B,F)=>{const G=B.oldLine?.oldLineNumber,z=B.newLine?.newLineNumber,{comments:W,showInput:ie}=y(G,z,"old");return E.jsxs(Bt.Fragment,{children:[E.jsxs("div",{className:"flex",style:{contentVisibility:"auto",containIntrinsicSize:"auto 26px"},children:[B.oldLine?O(B.oldLine,"old",h.covers(G,"old")):E.jsx(Iy,{}),B.newLine?O(B.newLine,"new",h.covers(z,"new")):E.jsx(Iy,{})]}),(W.length>0||ie)&&E.jsx(vj,{commentsToRender:W,showCommentInput:!!ie,commentRange:t,filePath:e.newPath||e.oldPath,originalCode:b,onCancel:i,onSaved:r,getOriginalCodeForComment:v})]},`${M}-${F}`)})]},M)),E.jsx(mh,{hunks:e.hunks,hunkIndex:e.hunks.length,isExpandable:l,onExpandContext:o,expandLoading:c,totalLines:d})]})}function xke({viewMode:e,...t}){const{t:n}=We(),{file:a}=t;if(a.isBinary)return E.jsx("div",{className:"flex items-center justify-center py-12 text-sm text-muted-foreground",children:n("Binary file — no diff available")});if(a.hunks.length===0&&a.contentLoaded!==!1)return E.jsx("div",{className:"flex items-center justify-center py-12 text-sm text-muted-foreground",children:n("No changes to display")});const i=YH(e,a.changeType)==="split"?Rke:Nke;return E.jsx(i,{...t})}function Ike(e,t){return e.length!==t.length||e.some((n,a)=>!Object.is(n,t[a]))}var kj=class extends Bt.Component{constructor(){super(...arguments),this.state={error:null},this.retry=()=>{this.setState({error:null})}}static getDerivedStateFromError(e){return{error:e instanceof Error?e:new Error(String(e))}}componentDidCatch(e,t){console.error(`[self-review] Preview for ${JSON.stringify(this.props.filePath)} failed to render:`,e,t.componentStack??"")}componentDidUpdate(e){this.state.error&&Ike(e.resetKeys,this.props.resetKeys)&&this.setState({error:null})}render(){const{error:e}=this.state;return e?E.jsx(Oke,{filePath:this.props.filePath,error:e,retry:this.retry}):this.props.children}};function Oke({filePath:e,error:t,retry:n}){const{t:a}=We();return E.jsxs("div",{role:"alert","data-testid":"preview-error",className:"m-3 flex items-start gap-2 text-destructive text-sm p-3 border border-destructive/20 rounded",children:[E.jsx(Jd,{className:"h-4 w-4 mt-0.5 shrink-0","aria-hidden":"true"}),E.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[E.jsx("p",{children:a("This file could not be displayed: {path}",{path:e})}),E.jsx("p",{className:"text-xs text-muted-foreground break-words",children:t.message}),E.jsx("p",{className:"text-xs text-muted-foreground",children:a("The rest of the review is unaffected.")})]}),E.jsx(Ye,{variant:"outline",size:"sm",onClick:n,children:a("Try again")})]})}function Dke({filePath:e,fileComments:t,orphanedComments:n=[],showingFileComment:a,onCancelFileComment:i,onFileCommentSubmit:r,children:o}){const{t:l}=We();return E.jsxs("div",{className:"bg-background file-diff-content rounded-b-lg overflow-hidden",children:[n.length>0&&E.jsxs("section",{"aria-label":l("Comments outside the current diff"),className:"p-3 space-y-2 bg-amber-500/10 border-b border-border",children:[E.jsx("h3",{className:"text-sm font-medium",children:l("Comments outside the current diff")}),E.jsx("p",{className:"text-xs text-muted-foreground",children:l("These recorded line ranges are not in the loaded diff. Their original locations are preserved when you save.")}),n.map(c=>E.jsx(ph,{comment:c},c.id))]}),t.length>0&&E.jsx("div",{className:"p-3 space-y-2 bg-muted/20 border-b border-border",children:t.map(c=>E.jsx(ph,{comment:c},c.id))}),a&&E.jsx("div",{className:"p-3 bg-muted/20 border-b border-border",children:E.jsx(rp,{filePath:e,lineRange:null,onCancel:i,onSubmit:r})}),o]})}function wj({file:e,viewMode:t,expanded:n,onToggleExpanded:a}){const{t:i}=We(),{toggleViewed:r}=Ws(),o=LH(),l=oI(e.newPath||e.oldPath),{mode:c,getFileDescription:d,getFileGroupIndex:p}=au(),m=w.useId(),h=w.useRef(null),b=dI(),y=b?.registerFileElement,v=b?.unregisterFileElement,T=fI(),S=XH(e,T),{renderViewMode:A,setRenderViewMode:N}=Pye(e,S),x=e.newPath||e.oldPath,I=c==="guided"?d(x):void 0,O=l?.comments??[],D=O.filter(be=>be.lineRange===null),M=w.useMemo(()=>aI(e),[e]),B=O.filter(be=>!M(be)),F=l?.viewed||!1,{expanded:G,changeExpanded:z}=ave(x,F,n,a),W=w.useCallback(be=>{const Ce=h.current;h.current=be,Ce&&Ce!==be&&v?.(x,Ce),be&&y?.(x,be)},[x,y,v]),{state:ie,retry:te}=Yye({file:e,filePath:x,expanded:G}),K=o.type==="git"&&!e.isUntracked&&!e.isBinary,{expandLoading:ne,expandError:Q,totalLines:se,handleExpandContext:j}=qye({file:e,filePath:x,isExpandable:K,sectionRef:h,expanded:G}),Y=YH(t,e.changeType),{lineComments:oe,rawSelection:$,onCommentRange:he,fileComment:Ne}=Bye(e,h,Y),ke=()=>r(x);return E.jsxs("div",{ref:W,className:`mx-2 mt-2 border border-border rounded-lg shadow-sm${$.dragState?" select-none":""}`,"data-file-path":x,"data-testid":`file-section-${x}`,children:[E.jsx(rve,{bodyId:m,file:e,filePath:x,expanded:G,isViewed:F,isPreviewable:S.available,renderViewMode:A,commentCount:O.length,onToggle:()=>z(!G),onViewedToggle:ke,onAddFileComment:()=>{z(!0),Ne.openFileComment()},onRenderViewModeChange:N}),I&&E.jsxs("div",{className:"flex items-start gap-2.5 border-b border-border bg-muted/30 px-3 py-2",children:[E.jsx("span",{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full bg-background ring-2 ${Us(p(x)??0).ring}`,"aria-hidden":"true"}),E.jsx("span",{className:"text-xs leading-relaxed text-muted-foreground","data-testid":`file-guide-description-${x}`,children:I})]}),E.jsxs("div",{id:m,hidden:!G,children:[G&&Q&&E.jsx("p",{role:"alert",className:"m-3 text-sm text-destructive",children:i("Context could not be loaded. Use an expand button to try again.")}),G&&E.jsx(Dke,{filePath:x,fileComments:D,orphanedComments:B,showingFileComment:Ne.showingFileComment,onCancelFileComment:Ne.closeFileComment,onFileCommentSubmit:Ne.closeFileComment,children:E.jsx(kj,{filePath:x,resetKeys:[e,A,Y],children:E.jsx(Uve,{omittedReason:e.omittedReason,contentLoaded:e.contentLoaded,contentLoad:ie,onRetry:te,children:E.jsx(yke,{file:e,preview:S.builtIn,descriptor:S,filePath:x,mode:A,...oe,onCommentRange:he,children:E.jsx(xke,{file:e,viewMode:Y,...oe,...$,isExpandable:K,expandLoading:ne,totalLines:se,onExpandContext:K?j:void 0})})})})})]})]})}function Tj({diagnostics:e,title:t}){return e.length===0?null:E.jsxs("div",{role:"alert","data-testid":"diff-diagnostics",className:"rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-sm text-foreground",children:[E.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[E.jsx(Jd,{className:"h-4 w-4 text-amber-600 dark:text-amber-400","aria-hidden":!0}),E.jsx("span",{children:t})]}),E.jsx("ul",{className:"mt-2 list-disc space-y-1 pl-6 text-muted-foreground",children:e.map((n,a)=>E.jsx("li",{className:"font-mono text-xs break-words",children:n},a))})]})}function Lke({diffSource:e,diagnostics:t=[]}){const{t:n}=We();return e.type==="welcome"||e.type==="loading"?null:t.length>0?E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg w-full space-y-4",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("The review could not be loaded")}),E.jsx(Tj,{diagnostics:t,title:n("The diff could not be read in a form self-review can review")})]})}):e.type==="file"?E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg space-y-6",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("Could not read file")}),E.jsx("p",{className:"text-sm text-muted-foreground text-center",children:n("The file {path} could not be read or is empty.",{path:e.sourcePath})})]})}):e.type==="directory"?E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg space-y-6",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("No files found")}),E.jsx("p",{className:"text-sm text-muted-foreground text-center",children:n("No files found in the selected directory {path}. The directory may be empty or all files may be excluded by ignore rules.",{path:e.sourcePath})})]})}):E.jsx("div",{className:"flex-1 flex items-center justify-center p-8","data-testid":"empty-diff-help",children:E.jsxs("div",{className:"max-w-lg space-y-6",children:[E.jsx("h2",{className:"text-lg font-semibold text-foreground text-center",children:n("No changes found")}),E.jsxs("p",{className:"text-sm text-muted-foreground",children:[n("All arguments are passed directly to git diff."),e.gitDiffArgs&&E.jsxs("span",{children:[" ",n("The arguments {args} were passed to git diff. Try different arguments to see your changes.",{args:e.gitDiffArgs})]})]}),E.jsxs("div",{children:[E.jsx("h3",{className:"text-sm font-medium text-foreground mb-3",children:n("Common usage examples:")}),E.jsx("table",{className:"w-full text-sm",children:E.jsxs("tbody",{className:"text-muted-foreground",children:[E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review"}),E.jsx("td",{className:"py-1.5",children:n("Unstaged working tree changes (default)")})]}),E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review --staged"}),E.jsx("td",{className:"py-1.5",children:n("Changes staged for commit")})]}),E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review HEAD~1"}),E.jsx("td",{className:"py-1.5",children:n("Changes in the last commit")})]}),E.jsxs("tr",{className:"border-b border-border/50",children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review main..HEAD"}),E.jsx("td",{className:"py-1.5",children:n("All changes since branching from main")})]}),E.jsxs("tr",{children:[E.jsx("td",{className:"py-1.5 pe-4 font-mono text-xs text-foreground",children:"self-review -- src/"}),E.jsx("td",{className:"py-1.5",children:n("Limit diff to a specific directory")})]})]})})]})]})})}function Sj(e){const t=new Set,n=new Set,a=new Set;for(const i of e)i.viewed&&(a.add(i.path),t.has(i.path)||n.add(i.path)),t.add(i.path);return{first:n,any:a}}function WF(e,t){return e.size===t.size&&[...t].every(n=>e.has(n))}var KF=new WeakMap;function Mke(e){const t=e.getSnapshot().files,n=KF.get(e);if(n?.files===t)return n.viewed;const a=Sj(t),i=n&&WF(n.viewed.first,a.first)?n.viewed.first:a.first,r=n&&WF(n.viewed.any,a.any)?n.viewed.any:a.any,o=n?.viewed.first===i&&n.viewed.any===r?n.viewed:{first:i,any:r};return KF.set(e,{files:t,viewed:o}),o}function a0(e){const t=w.useContext(Ba);return t?E.jsx(Fke,{...e,store:t}):E.jsx(Bke,{...e})}function Fke({store:e,match:t,children:n}){const a=()=>Mke(e)[t],i=w.useSyncExternalStore(e.subscribe,a,a);return n(i)}function Bke({match:e,children:t}){const n=w.useContext(Wb);if(!n)throw new Error("useReview must be used within ReviewProvider");const{files:a}=n,i=w.useMemo(()=>Sj(a),[a]);return t(i[e])}var hd=960,Pke=200,lg=72,XF=74,Oy=122;function Uke(e,t=18){return e.length>t?`${e.slice(0,t-1)}…`:e}function $ke({groups:e,isGroupComplete:t,onJump:n}){const{t:a,number:i,direction:r}=We(),o=e.length;if(o===0)return null;const l=e.map((c,d)=>({x:o===1?hd/2:r==="rtl"?hd-lg-d*(hd-2*lg)/(o-1):lg+d*(hd-2*lg)/(o-1),y:o===1?(XF+Oy)/2:d%2===0?XF:Oy,r:11+Math.min(6,Math.max(0,c.files.length-1)*1.5)}));return E.jsxs("svg",{viewBox:`0 0 ${hd} ${Pke}`,role:"group","aria-label":a("Walkthrough route map"),className:"h-auto w-full select-none",style:{maxHeight:220},children:[l.map((c,d)=>{if(d===0)return null;const p=l[d-1],m=(c.x-p.x)*.45,h=e[d].implicit;return E.jsx("path",{d:`M ${p.x} ${p.y} C ${p.x+m} ${p.y}, ${c.x-m} ${c.y}, ${c.x} ${c.y}`,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:h?"2 7":void 0,className:h?"stroke-muted-foreground/50":Us(d).strokeSoft},`segment-${d}`)}),e.map((c,d)=>{const p=l[d],m=Us(d,c.implicit),h=t(c),b=c.files[0]?.path,v=p.y===Oy&&o>1?p.y-p.r-26:p.y+p.r+18;return E.jsxs("g",{role:n&&b?"button":void 0,tabIndex:n&&b?0:void 0,"aria-label":a("Go to stop {index}: {name}",{index:d+1,name:c.implicit?a("Everything else"):c.name}),onClick:n&&b?()=>n(b):void 0,onKeyDown:n&&b?S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),n(b))}:void 0,className:n&&b?"cursor-pointer":void 0,children:[c.rationale&&E.jsx("title",{children:c.rationale}),E.jsx("circle",{cx:p.x,cy:p.y,r:p.r,strokeWidth:2.5,strokeDasharray:c.implicit?"3 3":void 0,className:`${m.stroke} ${h?m.fill:"fill-background"}`}),!c.implicit&&E.jsx("text",{x:p.x,y:p.y+3.5,textAnchor:"middle",fontSize:11,fontWeight:600,className:h?"fill-white":m.fillText,children:h?"✓":i(d+1)}),E.jsx("text",{x:p.x,y:v,textAnchor:"middle",fontSize:13,fontWeight:600,className:"fill-foreground",children:Uke(c.implicit?a("Everything else"):c.name)}),E.jsx("text",{x:p.x,y:v+15,textAnchor:"middle",fontSize:10.5,fontFamily:"ui-monospace, monospace",className:"fill-muted-foreground",children:a("files",{count:c.files.length})})]},`station-${d}-${c.name}`)})]})}function _j(e){let t=0,n=0;const a=e.every(i=>!i.omittedReason&&(i.isBinary||i.contentLoaded!==!1));if(a){for(const i of e)if(!i.isBinary)for(const r of i.hunks)for(const o of r.lines)o.type==="addition"?t++:o.type==="deletion"&&n++}return{files:e.length,complete:a,additions:t,deletions:n}}function Aj(e){return w.useContext(Ba)?E.jsx(Hke,{...e}):E.jsx(jke,{...e})}function Hke(e){const{diffFiles:t}=lc();return E.jsx(a0,{match:"any",children:n=>E.jsx(Nj,{...e,diffFiles:t,viewedPaths:n})})}function jke(e){const{diffFiles:t}=Zb();return E.jsx(a0,{match:"any",children:n=>E.jsx(Nj,{...e,diffFiles:t,viewedPaths:n})})}function Nj({onNavigate:e,diffFiles:t,viewedPaths:n}){const{t:a,number:i}=We(),{guide:r}=au(),o=dI(),{additions:l,deletions:c,complete:d}=w.useMemo(()=>_j(t),[t]);if(!r?.overview)return null;const p=r.groups,m=p.reduce((b,y)=>b+y.files.length,0),h=b=>b.files.length>0&&b.files.every(y=>n.has(y.path));return E.jsxs("div",{children:[E.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 select-none",children:[E.jsxs("span",{className:"flex items-center gap-2",children:[E.jsx(BP,{className:"h-3.5 w-3.5 text-indigo-600 dark:text-indigo-400"}),E.jsx("span",{className:"font-mono text-[11px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:a("Review walkthrough")})]}),E.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-muted-foreground",children:[a("walkthrough totals",{stops:p.length,files:m}),!d&&E.jsxs("span",{children:[" · ",a("Line totals unavailable")]}),l>0&&E.jsxs("span",{className:"text-emerald-700 dark:text-emerald-400",children:[" +",i(l)]}),c>0&&E.jsxs("span",{className:"text-red-700 dark:text-red-400",children:[" −",i(c)]})]})]}),E.jsx("div",{className:"mt-4",children:E.jsx($ke,{groups:p,isGroupComplete:h,onJump:o?b=>{o.scrollToFile(b),e?.()}:void 0})}),E.jsx("div",{className:"guide-overview-prose prose prose-sm dark:prose-invert mt-5 max-w-none",children:E.jsx(pI,{children:E.jsx(Fb,{urlTransform:op,remarkPlugins:[jf,n0],rehypePlugins:[sp],components:{code:fj,img:up},children:r.overview})})})]})}function zke(){const{guide:e,mode:t}=au();return t!=="guided"||!e?.overview?null:E.jsx("section",{className:"border-b border-border","data-testid":"guide-overview",children:E.jsx("div",{className:"mx-auto max-w-4xl px-6 pb-7 pt-7",children:E.jsx(Aj,{})})})}function Gke(e){return E.jsx(a0,{match:"first",children:t=>E.jsx(qke,{...e,viewedPaths:t})})}function qke({header:e,index:t,totalStops:n,implicitLast:a,entries:i,viewedPaths:r}){const{t:o,locale:l}=We(),c=i.filter(({file:d})=>{const p=d.newPath||d.oldPath;return r.has(p)}).length;return E.jsxs("section",{className:"relative mt-5 overflow-hidden border-y border-border/60 bg-muted/20 px-6 py-5","data-testid":`guide-chapter-${e.name}`,children:[!e.implicit&&E.jsx("span",{className:"pointer-events-none absolute -top-4 end-2 select-none font-mono text-[104px] font-bold leading-none",style:{WebkitTextStroke:`1.5px ${Us(t).numeralStroke}`,color:"transparent"},"aria-hidden":"true",children:new Intl.NumberFormat(l,{minimumIntegerDigits:2,useGrouping:!1}).format(t+1)}),E.jsxs("div",{className:"relative",children:[E.jsxs("div",{className:"font-mono text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:[e.implicit?o("Appendix"):o("Stop {index} of {total}",{index:t+1,total:n})," ","· ",o("files",{count:i.length})," ·"," ",o("{viewed}/{total} reviewed",{viewed:c,total:i.length})]}),E.jsx("h3",{className:"mt-1.5 text-xl font-bold tracking-tight text-foreground",children:e.implicit?o("Everything else"):e.name}),e.rationale&&E.jsx("p",{className:"mt-1 max-w-2xl text-[13px] leading-relaxed text-muted-foreground",children:e.rationale}),E.jsx("div",{className:"mt-3 flex items-center gap-1.5","aria-hidden":"true",children:Array.from({length:n},(d,p)=>{const m=Us(p,a&&p===n-1);return E.jsx("span",{className:p===t?`h-2 w-2 rounded-full ${m.dot}`:`h-1.5 w-1.5 rounded-full ${p<t?m.dotSoft:m.dotFaint}`},p)})})]})]})}function Vke(){const{t:e}=We(),{diffFiles:t,diffSource:n,diagnostics:a=[],sessionId:i}=lc(),r=ip(),o=Ys(),{guide:l,mode:c}=au(),d=w.useRef(null),p=dI(),m=w.useMemo(()=>HH(t,jH(t,l?.groups??null,c)),[t,l,c]),h=m.filter(N=>N.header).length,b=!!m[m.length-1]?.header?.implicit,{expanded:y,setExpanded:v}=Xb(),T=N=>y.get(N)??!1,S=w.useRef(0);w.useLayoutEffect(()=>{if(S.current>0){const N=yf(o,'[data-scroll-container="diff"]');N&&(N.scrollTop-=S.current),S.current=0}},[y]);const A=N=>{const x=T(N);if(x){const I=yf(o,'[data-scroll-container="diff"]'),O=p?.getFileElement(N);if(I&&O){const D=I.getBoundingClientRect();if(O.getBoundingClientRect().top<D.top){const F=O.scrollHeight-40;F>0&&(S.current=F)}}}v(N,!x)};return t.length===0?E.jsx(Lke,{diffSource:n,diagnostics:a}):E.jsxs("div",{ref:d,className:`flex-1${h>0?" pb-16":""}`,"data-testid":"diff-viewer","data-diff-viewer":!0,children:[a.length>0&&E.jsx("div",{className:"px-4 pt-4",children:E.jsx(Tj,{diagnostics:a,title:e("Part of this diff could not be reviewed")})}),E.jsx(zke,{}),m.map((N,x)=>E.jsxs(Bt.Fragment,{children:[N.header&&E.jsx(Gke,{header:N.header,index:x,totalStops:h,implicitLast:b,entries:N.entries}),N.entries.map(({file:I,key:O})=>{const D=I.newPath||I.oldPath;return E.jsx(kj,{filePath:D,resetKeys:[I],children:E.jsx(wj,{file:I,viewMode:r.diffView,expanded:T(D),onToggleExpanded:A})},`${i}:${O}`)})]},`chapter-${x}-${N.header?.name??"flat"}`))]})}function Yke({open:e,onOpenChange:t}){const{t:n}=We();return E.jsx(aj,{open:e,onOpenChange:t,children:E.jsxs(mI,{className:"block max-h-[85vh] max-w-3xl overflow-y-auto","data-testid":"guide-overview-dialog",children:[E.jsx(gI,{className:"sr-only",children:n("Review walkthrough")}),E.jsx(Aj,{onNavigate:()=>t(!1)})]})})}function Wke(){return E.jsx(a0,{match:"any",children:e=>E.jsx(Kke,{viewedPaths:e})})}function Kke({viewedPaths:e}){const{t}=We(),{guide:n,mode:a}=au(),{activeFilePath:i,scrollToFile:r}=cI(),[o,l]=w.useState(!1);if(a!=="guided"||!n||n.groups.length===0)return null;const c=n.groups,d=c.findIndex(h=>h.files.some(b=>b.path===i)),p=d>=0?c[d]:null,m=!!n.overview;return E.jsxs("div",{className:"pointer-events-none absolute inset-x-0 bottom-4 z-30 flex justify-center",children:[E.jsxs("div",{className:"pointer-events-auto flex items-center gap-2 rounded-full border border-border bg-background/90 py-1.5 ps-2 pe-4 shadow-lg backdrop-blur","data-testid":"guide-route-hud",children:[m&&E.jsxs(E.Fragment,{children:[E.jsxs("button",{type:"button",title:t("Open the walkthrough overview"),onClick:()=>l(!0),className:"flex h-6 w-6 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground","data-testid":"guide-hud-overview-btn",children:[E.jsx(BP,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("Open the walkthrough overview")})]}),E.jsx("span",{className:"h-4 w-px bg-border","aria-hidden":"true"})]}),E.jsx("div",{className:"flex items-center gap-1",children:c.map((h,b)=>{const y=Us(b,h.implicit),v=b===d,T=h.files.length>0&&h.files.every(A=>e.has(A.path)),S=h.files[0]?.path;return E.jsx("button",{type:"button",title:h.implicit?t("Everything else"):h.name,"aria-label":t("Go to stop {index}: {name}",{index:b+1,name:h.implicit?t("Everything else"):h.name}),onClick:S?()=>r(S):void 0,className:"flex h-5 w-5 items-center justify-center rounded-full transition-colors hover:bg-muted",children:E.jsx("span",{className:v?`h-3 w-3 rounded-full ${y.dot}`:T?`h-2 w-2 rounded-full ${y.dotSoft}`:`h-2 w-2 rounded-full ${y.dotFaint}`,"aria-hidden":"true"})},`hud-stop-${b}-${h.name}`)})}),E.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] tabular-nums text-muted-foreground",children:p?t("{index}/{total} · {name}",{index:d+1,total:c.length,name:p.implicit?t("Everything else"):p.name}):t("stops",{count:c.length})})]}),m&&E.jsx(Yke,{open:o,onOpenChange:l})]})}function Xke({collapsed:e,controls:t,onToggle:n}){const a=e?"Show file tree":"Hide file tree",i=e?dK:lK;return E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx(Ye,{variant:"outline",size:"icon",className:"h-7 w-7 rounded-full shadow-md text-muted-foreground hover:text-foreground","data-testid":"file-tree-toggle","data-review-navigation":"","aria-expanded":!e,"aria-controls":t,"aria-label":a,onClick:n,children:E.jsx(i,{className:"h-3.5 w-3.5"})})}),E.jsx(Gt,{side:"right",children:a})]})}function Zke(){const e=OH(),t=Ys(),n=w.useId(),a=`${n}-file-tree`,i=`${n}-diff-viewer`,r=w.useRef(null),[o,l]=w.useState(!1),c=w.useCallback(()=>{l(r.current?.isCollapsed()??!1)},[]),d=w.useCallback(()=>{const m=r.current;m&&(m.isCollapsed()?m.expand():m.collapse(),c())},[c]),p=w.useCallback(()=>{const m=r.current;return m?(m.isCollapsed()&&Ti.flushSync(()=>{m.expand(),c()}),!m.isCollapsed()):!1},[c]);return w.useLayoutEffect(()=>e?.register(p),[e,p]),w.useEffect(()=>{const m=()=>{p()};return t?.addEventListener("expand-file-tree",m),()=>t?.removeEventListener("expand-file-tree",m)},[p,t]),E.jsxs(t7,{orientation:"horizontal",style:{flex:1},children:[E.jsx(Tv,{id:a,panelRef:r,collapsible:!0,collapsedSize:"0%",defaultSize:"25%",minSize:"10%",maxSize:"60%",onResize:c,children:E.jsx("div",{className:"h-full overflow-hidden bg-sidebar text-sidebar-foreground",inert:o||void 0,children:E.jsx(Mye,{})})}),E.jsx(n7,{className:"relative flex w-px items-center justify-center bg-border",children:E.jsx("div",{className:"z-10 flex h-4 w-3.5 items-center justify-center rounded-sm border bg-border",children:E.jsx($W,{className:"h-2.5 w-2.5"})})}),E.jsx(Tv,{id:i,defaultSize:"75%",children:E.jsxs("div",{className:"relative h-full",children:[E.jsx("div",{className:"h-full overflow-y-auto bg-background","data-scroll-container":"diff",children:E.jsx(Vke,{})}),E.jsx("div",{className:"absolute bottom-4 left-4 z-30",children:E.jsx(Xke,{collapsed:o,controls:a,onToggle:d})}),E.jsx(Wke,{})]})})]})}var Qke=Bt.memo(Zke),cg="asdfjklhgqwertuiop".split(""),Jke=80,ZF='[data-comment-gutter], [data-hint-action], [data-testid="cancel-comment-btn"], [data-testid="add-comment-btn"], [data-testid^="category-option-"]',ewe="[data-line-type][data-line-number][data-line-side]";function twe(e){if(e<=cg.length)return cg.slice(0,e);const t=[];for(const n of cg)for(const a of cg)if(t.push(n+a),t.length>=e)return t;return t}function nwe(){const e=document.activeElement;if(!e)return!1;const t=e.tagName.toLowerCase();return!!(t==="input"||t==="textarea"||e.closest('[contenteditable]:not([contenteditable="false"])')||e.closest('[class*="md-editor"]')||e.closest("[data-color-mode]"))}function QF(e){const t=e instanceof Element?e.closest('input, textarea, select, button, a[href], [role="button"], [role="combobox"], [role="listbox"], [role="slider"], [role="spinbutton"], [role="menu"], [role="menuitem"], [role="checkbox"], [role="radio"], [role="switch"], [role="tab"], [role="textbox"], [contenteditable]:not([contenteditable="false"])'):null;return!!t&&!t.hasAttribute("data-review-navigation")}function JF(e,t){const n=yf(e,'[data-scroll-container="diff"]');n&&n.scrollBy({top:t*Jke,behavior:"instant"})}function awe(){const e=Ys(),n=gH()?.characterShortcuts??!0,a=w.useRef(n);a.current=n;const i=OH(),r=w.useRef(!1),[o,l]=w.useState("normal"),[c,d]=w.useState([]),[p,m]=w.useState(""),{scrollToFile:h}=cI(),b=w.useRef(o),y=w.useRef(c),v=w.useRef(p);b.current=o,y.current=c,v.current=p;const T=w.useCallback(()=>{l("normal"),d([]),m("")},[]),S=w.useRef(T);S.current=T;const A=w.useCallback(x=>{if(b.current==="hint-diff"){if(x.element.matches(ZF)){x.element.click(),S.current();return}const I=x.element.getAttribute("data-line-number"),O=x.element.getAttribute("data-line-side");let D=null,M=x.element;for(;M;){const B=M.getAttribute("data-file-path");if(B){D=B;break}M=M.parentElement}D&&I&&O&&x.element.dispatchEvent(new CustomEvent("trigger-line-comment",{bubbles:!0,detail:{filePath:D,lineNumber:parseInt(I,10),side:O}}))}else if(b.current==="hint-file"){const I=x.element.getAttribute("data-file-path");I&&h(I)}S.current()},[h]),N=w.useCallback(x=>{let I;if(x==="hint-diff")I=`${ZF}, ${ewe}`;else{const F=i?.expand();if(F===!1)return;F===void 0&&e?.dispatchEvent(new CustomEvent("expand-file-tree")),I='.file-tree [data-file-path], [data-testid="file-tree"] [data-file-path], button[data-file-path]'}const O=MH(e,I),D=[];if(O.forEach(F=>{if(F.hasAttribute("data-line-type")&&F.querySelector("[data-comment-gutter]"))return;const G=F.getBoundingClientRect();G.top>=0&&G.left>=0&&G.bottom<=window.innerHeight&&G.right<=window.innerWidth&&G.width>0&&G.height>0&&D.push({element:F,rect:G})}),D.length===0)return;const M=twe(D.length),B=D.map((F,G)=>({label:M[G],element:F.element,rect:F.rect}));l(x),d(B),m("")},[e,i]);return w.useEffect(()=>{if(!e)return;e.setAttribute("data-review-shortcuts","");const x=F=>{!F&&r.current&&S.current(),r.current=F,e.toggleAttribute("data-review-active",F)};x(document.querySelector("[data-review-shortcuts]")===e);const I=F=>{x(F.target instanceof Element&&F.target.closest("[data-review-shortcuts]")===e)};document.addEventListener("pointerdown",I,!0),document.addEventListener("focusin",I,!0);let O=!1;const D=()=>{O=!0,S.current()},M=()=>{O=!1};function B(F){if(F.defaultPrevented||F.isComposing||F.keyCode===229||O)return;const G=F.target;if(document.querySelector("[data-review-active]")||x(document.querySelector("[data-review-shortcuts]")===e),!r.current||nwe()||G instanceof Element&&G!==document.body&&!e?.contains(G))return;const z=document.activeElement;if(z&&z!==document.body&&!e?.contains(z))return;const W=b.current,ie=y.current,te=v.current;if(!(QF(G)||QF(z))&&!(F.altKey||F.ctrlKey||F.metaKey)){if(F.key==="Escape"&&W!=="normal"){F.preventDefault(),S.current();return}if(a.current){if(W==="normal")switch(F.key){case"f":F.preventDefault(),N("hint-diff");return;case"g":F.preventDefault(),N("hint-file");return;case"j":F.preventDefault(),JF(e,1);return;case"k":F.preventDefault(),JF(e,-1);return;default:return}if(/^[a-z0-9]$/i.test(F.key)){F.preventDefault();const K=te+F.key.toLowerCase(),ne=ie.find(se=>se.label===K);if(ne){A(ne);return}ie.some(se=>se.label.startsWith(K))?m(K):S.current()}}}}return document.addEventListener("keydown",B),document.addEventListener("compositionstart",D),document.addEventListener("compositionend",M),()=>{document.removeEventListener("keydown",B),document.removeEventListener("compositionstart",D),document.removeEventListener("compositionend",M),document.removeEventListener("pointerdown",I,!0),document.removeEventListener("focusin",I,!0),e.removeAttribute("data-review-shortcuts"),e.removeAttribute("data-review-active")}},[N,A,e]),w.useEffect(()=>{n||T()},[n,T]),w.useEffect(()=>{if(o==="normal")return;const x=yf(e,'[data-scroll-container="diff"]');if(!x)return;function I(){S.current()}return x.addEventListener("scroll",I,{passive:!0}),()=>x.removeEventListener("scroll",I)},[o,e]),{mode:o,hints:c,inputBuffer:p,clearHints:T}}function iwe({hints:e,inputBuffer:t}){const n=t?e.filter(a=>a.label.startsWith(t)):e;return n.length===0?null:Ti.createPortal(E.jsx("div",{"data-testid":"hint-overlay",style:{position:"fixed",inset:0,pointerEvents:"none",zIndex:9999},children:n.map(a=>E.jsxs("span",{"data-testid":`hint-label-${a.label}`,style:{position:"absolute",left:a.rect.left,top:a.rect.top,backgroundColor:"#facc15",color:"#000",fontFamily:"monospace",fontSize:"11px",fontWeight:"bold",padding:"1px 3px",borderRadius:"2px",lineHeight:1,zIndex:9999},children:[E.jsx("span",{style:{opacity:.4},children:a.label.slice(0,t.length)}),E.jsx("span",{children:a.label.slice(t.length)})]},a.label))}),document.body)}function rwe(){const{hints:e,inputBuffer:t}=awe();return E.jsx(iwe,{hints:e,inputBuffer:t})}function Cj(e,t){const{files:n,diffSource:a}=Zb(),i=dye(),{now:r}=Kb(),o=w.useRef(r);o.current=r;const l=w.useRef(n),c=w.useRef(a);l.current=n,c.current=a,w.useImperativeHandle(e,()=>({beginSave:i.begin,getReviewState:()=>({timestamp:o.current().toISOString(),source:c.current,files:l.current})}));const d=w.useRef(t);d.current=t;const p=w.useRef(null);w.useEffect(()=>{const m=n.flatMap(y=>y.comments),h=p.current;(h===null||h.length!==m.length||m.some((y,v)=>y!==h[v]))&&(p.current=m,d.current?.(m))},[n])}var swe=w.forwardRef(function({adapter:t,config:n,initialConfig:a,className:i,children:r,onReviewChange:o,previewRenderer:l,diagramRenderer:c,services:d,recovery:p,initialCharacterShortcuts:m},h){return E.jsx(Sye,{adapter:t,config:n,initialConfig:a,previewRenderer:l,diagramRenderer:c,services:d,recovery:p,initialCharacterShortcuts:m,children:E.jsx(owe,{ref:h,className:i,onReviewChange:o,children:r})})}),owe=w.forwardRef(function({className:t,children:n,onReviewChange:a},i){return Cj(i,a),E.jsxs("div",{className:t,children:[E.jsx(rwe,{}),n,E.jsx(Qke,{})]})}),uwe=w.forwardRef(function({file:t,viewMode:n,onReviewChange:a,className:i},r){Cj(r,a);const o=uye(t.newPath||t.oldPath);return E.jsx("div",{className:i,children:E.jsx(E.Fragment,{children:o&&E.jsx(wj,{file:o,viewMode:n})})})}),lwe=w.forwardRef(function({file:t,source:n,adapter:a,recovery:i,initialCharacterShortcuts:r,...o},l){const c=w.useRef({files:[t],source:n});c.current={files:[t],source:n};const d=w.useMemo(()=>({...a,loadDiff:async()=>c.current}),[a]),p=w.useMemo(()=>[t],[t]);return E.jsx(M$,{adapter:d,children:E.jsx(DH,{initialFiles:p,initialSource:n,recovery:i,initialCharacterShortcuts:r,children:E.jsx(FH,{children:E.jsx(AH,{children:E.jsx(uwe,{ref:l,file:t,...o})})})})})});w.forwardRef(function({file:t,source:n,config:a,initialConfig:i,onReviewChange:r,adapter:o,className:l,recovery:c,initialCharacterShortcuts:d,defaultViewMode:p="unified"},m){const h=n||{type:"file",sourcePath:t.newPath||t.oldPath},b=JSON.stringify([t.newPath||t.oldPath,Bo(h)]);return E.jsx(Z$,{initialConfig:{...i??a,diffView:p},children:E.jsx(lwe,{ref:m,file:t,source:h,adapter:o,viewMode:p,onReviewChange:r,className:l,recovery:c,initialCharacterShortcuts:d},b)})});function cwe(){const e=gH(),{t}=We();if(!e)return null;const n=e.characterShortcuts?FP:qW,a=`${t("Keyboard shortcuts")} (f, g, j, k)`;return E.jsxs(Ye,{variant:"ghost",size:"sm","data-hint-action":"toggle-character-shortcuts","aria-label":a,"aria-pressed":e.characterShortcuts,title:a,onClick:()=>e.setCharacterShortcuts(!e.characterShortcuts),children:[E.jsx(n,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:a})]})}function dwe(){const{t:e,number:t}=We(),{diffFiles:n}=lc(),a=cye(),{viewedCount:i,totalFiles:r,commentCount:o,filesWithComments:l}=w.useMemo(()=>{const d=new Set(n.map(v=>v.newPath||v.oldPath)),p=a.filter(v=>d.has(v.path)),m=p.filter(v=>v.viewed).length,h=n.length,b=p.reduce((v,T)=>v+T.commentCount,0),y=p.filter(v=>v.commentCount>0).length;return{viewedCount:m,totalFiles:h,commentCount:b,filesWithComments:y}},[a,n]);if(r===0)return null;const c=Math.round(i/r*100);return E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground","data-testid":"review-progress",children:[E.jsx(IW,{className:"h-3 w-3"}),E.jsxs("span",{className:"tabular-nums",children:[t(i),"/",t(r)]}),E.jsx("div",{role:"progressbar","aria-label":e("Review progress"),"aria-valuemin":0,"aria-valuemax":r,"aria-valuenow":i,className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:E.jsx("div",{className:"h-full rounded-full bg-green-600 dark:bg-green-500 transition-all duration-300",style:{width:`${c}%`}})})]})}),E.jsx(Gt,{children:e("files viewed",{viewed:i,total:r,percent:c})})]}),o>0&&E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground","data-testid":"review-stats",children:[E.jsx(Qd,{className:"h-3 w-3"}),E.jsx("span",{className:"tabular-nums",children:t(o)})]})}),E.jsx(Gt,{children:e("comments across files",{count:o,files:l})})]})]})}function fwe({onFinishReview:e}={}){const{t,number:n}=We(),{config:a,updateConfig:i}=Xx(),{outputPathInfo:r}=X$(),{diffFiles:o,diffSource:l}=lc(),{guide:c,mode:d,setMode:p}=au(),m=_i(),{allCollapsed:h,setAllCollapsed:b}=eI(),y=w.useMemo(()=>_j(o),[o]),v=()=>{b(!h)},T=S=>{i({theme:S})};return E.jsxs("div",{className:"flex shrink-0 z-20 items-center justify-between h-11 px-3 border-b border-border bg-background","data-testid":"toolbar",children:[E.jsxs("div",{className:"flex items-center gap-2",children:[l.type==="git"&&E.jsxs(E.Fragment,{children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":"toggle-untracked-btn",onClick:()=>i({showUntracked:!a.showUntracked}),className:"gap-1.5 h-8 px-2.5 text-muted-foreground hover:text-foreground",children:[a.showUntracked?E.jsx(BW,{className:"h-3.5 w-3.5"}):E.jsx(DW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t(a.showUntracked?"Hide New Files":"Show New Files")})]})}),E.jsx(Gt,{children:a.showUntracked?t("Hide new files not yet in git"):t("Show new files not yet in git")})]}),E.jsx(ha,{orientation:"vertical",className:"h-5"})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":h?"expand-all-comments-btn":"collapse-all-comments-btn",onClick:v,className:"gap-1.5 h-8 px-2.5 text-muted-foreground hover:text-foreground",children:[h?E.jsx(Qd,{className:"h-3.5 w-3.5"}):E.jsx(eK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t(h?"Expand Comments":"Collapse Comments")})]})}),E.jsx(Gt,{children:t(h?"Expand all comments":"Collapse all comments")})]}),c&&E.jsxs(E.Fragment,{children:[E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(vf,{type:"single",variant:"outline",size:"sm",value:d,onValueChange:S=>{(S==="guided"||S==="flat")&&p(S)},children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"guided","data-testid":"guide-mode-guided",className:"h-8 px-2.5 gap-1.5",children:[E.jsx(EK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t("Guided")})]})}),E.jsx(Gt,{children:t("Group files by the review walkthrough")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"flat","data-testid":"guide-mode-flat",className:"h-8 px-2.5 gap-1.5",children:[E.jsx(XW,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t("Flat")})]})}),E.jsx(Gt,{children:t("Flat file list (diff order)")})]})]})]})]}),E.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground","data-testid":"diff-stats",children:[E.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[l.type==="file"?E.jsx(MW,{className:"h-3 w-3"}):l.type==="directory"?E.jsx(LP,{className:"h-3 w-3"}):E.jsx(SK,{className:"h-3 w-3"}),l.type==="git"?`git diff${l.gitDiffArgs?` ${l.gitDiffArgs}`:""}`:l.type==="directory"?t("Directory: {path}",{path:l.sourcePath}):l.type==="file"?t("File: {path}",{path:l.sourcePath.split("/").pop()??""}):""]}),E.jsx(ha,{orientation:"vertical",className:"h-3.5"}),E.jsx("span",{children:t("files changed",{count:y.files})}),!y.complete&&E.jsx("span",{children:t("Line totals unavailable")}),y.additions>0&&E.jsxs("span",{className:"text-emerald-700 dark:text-emerald-400",children:["+",n(y.additions)]}),y.deletions>0&&E.jsxs("span",{className:"text-red-700 dark:text-red-400",children:["-",n(y.deletions)]})]}),E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx(cwe,{}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(Ye,{variant:"ghost",size:"sm","data-testid":"toggle-word-wrap-btn",onClick:()=>i({wordWrap:!a.wordWrap}),className:"gap-1.5 h-8 px-2.5 text-muted-foreground hover:text-foreground",children:[a.wordWrap?E.jsx(CK,{className:"h-3.5 w-3.5"}):E.jsx(oK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs",children:t(a.wordWrap?"Wrap Lines":"No Wrap")})]})}),E.jsx(Gt,{children:t(a.wordWrap?"Wrap long lines":"Scroll long lines horizontally")})]}),E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(vf,{type:"single",variant:"outline",size:"sm",value:a.theme,onValueChange:S=>S&&T(S),children:[E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"light","data-testid":"theme-option-light",className:"h-8 w-8 p-0",children:[E.jsx(wK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("Light theme")})]})}),E.jsx(Gt,{children:t("Light theme")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"dark","data-testid":"theme-option-dark",className:"h-8 w-8 p-0",children:[E.jsx(rK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("Dark theme")})]})}),E.jsx(Gt,{children:t("Dark theme")})]}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsxs(or,{value:"system","data-testid":"theme-option-system",className:"h-8 w-8 p-0",children:[E.jsx(aK,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"sr-only",children:t("System theme")})]})}),E.jsx(Gt,{children:t("System theme")})]})]}),E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsx(dwe,{}),e&&E.jsxs(E.Fragment,{children:[E.jsx(ha,{orientation:"vertical",className:"h-5"}),E.jsxs(Vt,{children:[E.jsx(zt,{asChild:!0,children:E.jsx("span",{children:E.jsxs(Ye,{variant:"default",size:"sm","data-testid":"finish-review-btn","data-hint-action":"finish-review",onClick:()=>e(),className:"gap-1.5 h-8 px-3",disabled:!r.outputPathWritable||l.type==="loading",children:[E.jsx(kh,{className:"h-3.5 w-3.5"}),E.jsx("span",{className:"text-xs font-medium",children:t("Finish Review")})]})})}),!r.outputPathWritable&&E.jsx(Gt,{children:m?.changeOutputPath?t("Output path is not writable. Click 'Change...' in the file tree to pick a save location."):t("Output path is not writable.")})]})]})]})]})}var pwe=[];function mwe(){const e=w.useContext(Ba);return e?E.jsx(gwe,{store:e}):E.jsx(hwe,{})}function gwe({store:e}){const t=()=>e.getSnapshot().resumedReview?.importDiagnostics??pwe,n=()=>e.getSnapshot().anchorDiagnostics,a=()=>e.getSnapshot().sessionId,i=w.useSyncExternalStore(e.subscribe,t,t),r=w.useSyncExternalStore(e.subscribe,n,n),o=w.useSyncExternalStore(e.subscribe,a,a),l=w.useMemo(()=>[...i,...r],[i,r]);return E.jsx(Rj,{importDiagnostics:l},o)}function hwe(){const{importDiagnostics:e,sessionId:t}=Zb();return E.jsx(Rj,{importDiagnostics:e},t)}function Rj({importDiagnostics:e}){const{t}=We(),[n,a]=w.useState(!1);return e.length===0||n?null:E.jsxs("div",{role:"alert",className:"flex shrink-0 items-start justify-between gap-3 px-3 py-1.5 border-b border-border bg-amber-50 dark:bg-amber-950 text-xs","data-testid":"import-diagnostics-banner",children:[E.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[E.jsx(Jd,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400"}),E.jsxs("div",{className:"min-w-0",children:[E.jsx("span",{children:t("Resumed comments without anchors",{count:e.length})}),E.jsx("ul",{className:"mt-0.5 list-disc space-y-0.5 ps-5 text-muted-foreground",children:e.map((i,r)=>E.jsx("li",{className:"font-mono break-words",children:i},r))})]})]}),E.jsxs(Ye,{variant:"ghost",size:"sm",className:"h-5 w-5 shrink-0 p-0 text-muted-foreground hover:text-foreground",onClick:()=>a(!0),"data-testid":"import-diagnostics-banner-dismiss",children:[E.jsx(nk,{className:"h-3 w-3"}),E.jsx("span",{className:"sr-only",children:t("Dismiss")})]})]})}function bwe(e,t=!0){w.useLayoutEffect(()=>{if(!t)return;const n=i=>{!e.current||i.target instanceof Element&&i.target.closest("[data-save-recovery]")||(i.preventDefault(),i.stopImmediatePropagation())},a=["keydown","click","beforeinput","input","change","submit","trigger-line-comment"];return a.forEach(i=>window.addEventListener(i,n,!0)),()=>a.forEach(i=>window.removeEventListener(i,n,!0))},[t,e])}const wI=32*1024*1024,eB=wI,Ewe="suggestion-too-large",xj="review-too-large",ywe="cap",vwe="Bearer";function kwe(e){const n=new URLSearchParams(e.startsWith("#")?e.slice(1):e).get(ywe);return n||null}function wwe(e){return`${vwe} ${e}`}function gh(e){return(e/(1024*1024)).toFixed(1)}const Twe="review server busy; retry after pending requests finish",Swe="server-busy";class Za extends Error{constructor(t,n){super(t),this.name="ServeRequestError",this.status=n.status,this.code=n.code??null,this.details=n.details??[],this.uncertain=n.uncertain??!1}}function _we(e){return e==="/api/review"||e==="/api/apply-suggestion"?"mutation":"read"}function TI(e,t={}){const n=t.fetch??globalThis.fetch.bind(globalThis),a=wwe(e),i=new Set;let r=!1;return{async request(o,l,c,d=_we(o)){const p=d==="mutation",m=new AbortController,h=T=>new Za(p?`${T} The operation may have completed. Check the terminal and destination before continuing; do not resend it blindly.`:T,{status:null,code:p?"outcome-unknown":"request-failed",uncertain:p});if(r)throw h("This page has disconnected from the review server.");if(l.signal?.aborted)throw h("The request was cancelled.");i.add(m);let b,y=()=>{};const v=()=>m.abort(l.signal?.reason);try{const T=new Promise((S,A)=>{y=()=>A(h("The request was cancelled or timed out.")),m.signal.addEventListener("abort",y,{once:!0}),b=setTimeout(()=>m.abort(),p?t.mutationTimeoutMs??6e4:t.readTimeoutMs??3e4)});return l.signal?.addEventListener("abort",v,{once:!0}),l.signal?.aborted&&v(),await Promise.race([T,(async()=>{m.signal.throwIfAborted();const S=new Headers(l.headers);S.set("authorization",a);const A=await n(o,{...l,signal:m.signal,headers:Object.fromEntries(S.entries())});return c(A)})()])}catch(T){throw T instanceof Za?T:h(T instanceof Error?T.message:String(T))}finally{clearTimeout(b),m.signal.removeEventListener("abort",y),l.signal?.removeEventListener("abort",v),i.delete(m)}},dispose(){r=!0;for(const o of i)o.abort();i.clear()}}}const bd=e=>new Za(e,{status:null,code:"request-failed"});function Awe(e,t){let n=null,a=!1;const i=()=>{if(n)return n;const r=new AbortController,o={abort:r,settled:!1,legacy:!1,borrowers:new Set,work:e(r.signal).then(l=>{if(o.settled=!0,a||n!==o||r.signal.aborted)throw bd("The request was cancelled.");return t(l),l}).catch(l=>{throw o.settled=!0,n===o&&(n=null),l})};return n=o,o};return{prefetch:()=>a?Promise.reject(bd("This page has disconnected from the review server.")):i().work,read(r){if(a)return Promise.reject(bd("This page has disconnected from the review server."));if(r?.aborted)return Promise.reject(bd("The request was cancelled."));const o=i();return r?new Promise((l,c)=>{const d={},p=()=>{r.removeEventListener("abort",m),o.borrowers.delete(d)},m=()=>{p(),!o.settled&&n===o&&!o.legacy&&!o.borrowers.size&&(n=null,o.abort.abort()),c(bd("The request was cancelled."))};o.borrowers.add(d),r.addEventListener("abort",m,{once:!0}),o.work.then(h=>{p(),l(h)},h=>{p(),c(h)}),r.aborted&&m()}):(o.legacy=!0,o.work)},dispose(){a=!0;const r=n;n=null,r?.abort.abort()}}}function Nwe(e,t){return e===503&&!("code"in t)&&t.error===Twe}function Dl(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function Kd(e,t,n=!1){let a=null;try{a=await e.json()}catch{}const r=n&&e.status>=500&&!(Dl(a)&&e.status===503&&(a.code===Swe||Nwe(e.status,a)))?{uncertain:!0,code:"outcome-unknown"}:{};if(Dl(a)){if(a.ok===!1&&typeof a.message=="string")return new Za(a.message,{status:e.status,code:typeof a.code=="string"?a.code:null,details:Array.isArray(a.details)?a.details.filter(o=>typeof o=="string"):[]});if(typeof a.error=="string")return new Za(`${t} failed (${e.status}): ${a.error}`,{status:e.status,...r})}return new Za(`${t} failed (${e.status})`,{status:e.status,...r})}function Ij(e){return{getJson:(t,n,a)=>e.request(t,{signal:n},async i=>{if(!i.ok)throw await Kd(i,`GET ${t}`);const r=await i.json();return a?a(r):r},"read"),postJsonText:(t,n,a)=>e.request(t,{method:"POST",headers:{"content-type":"application/json"},body:n},a,"mutation"),postJson:(t,n,a,i)=>e.request(t,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n),signal:a},async r=>{if(!r.ok)throw await Kd(r,`POST ${t}`);const o=await r.json();return i?i(o):o},"read")}}const rt=e=>typeof e=="string",Qa=e=>typeof e=="boolean",yi=e=>typeof e=="number"&&Number.isFinite(e),Fi=e=>t=>Array.isArray(t)&&t.every(e),Bi=e=>t=>t===null||e(t),$s=(...e)=>t=>typeof t=="string"&&e.includes(t);function cn(e,t={}){const n=Object.entries(e),a=Object.entries(t);return i=>Dl(i)&&n.every(([r,o])=>o(i[r]))&&a.every(([r,o])=>i[r]===void 0||o(i[r]))}const hh=Fi(rt),Cwe=$s("added","modified","deleted","renamed","copied"),Rwe=cn({side:$s("old","new"),start:yi,end:yi}),xwe=cn({originalCode:rt,proposedCode:rt}),Oj=cn({id:rt,fileName:rt,mediaType:rt}),Iwe=cn({id:rt,body:rt},{author:rt,remoteId:rt,attachments:Fi(Oj)}),Owe=cn({id:rt,filePath:rt,lineRange:Bi(Rwe),body:rt,category:rt,suggestion:Bi(xwe)},{author:rt,remoteId:rt,orphaned:Qa,severity:$s("critical","major","minor","info"),confidence:$s("high","medium","low"),attachments:Fi(Oj),replies:Fi(Iwe)}),Dwe=cn({type:$s("context","addition","deletion"),content:rt,oldLineNumber:Bi(yi),newLineNumber:Bi(yi)}),Lwe=cn({header:rt,oldStart:yi,oldLines:yi,newStart:yi,newLines:yi,lines:Fi(Dwe)}),SI=Fi(Lwe),Mwe=cn({oldPath:rt,newPath:rt,changeType:Cwe,isBinary:Qa,hunks:SI},{isUntracked:Qa,contentLoaded:Qa,omittedReason:rt}),Fwe=e=>{if(!Dl(e))return!1;switch(e.type){case"git":return rt(e.gitDiffArgs)&&rt(e.repository);case"directory":case"file":return rt(e.sourcePath);case"welcome":case"loading":return!0;default:return!1}},Bwe=cn({remoteUrl:rt,remoteBaseSha:rt,remoteHeadSha:rt,remoteForge:$s("github","gitlab"),threadSyncAvailable:Qa,temporaryClone:Qa}),Pwe=cn({files:Fi(Mwe),source:Fwe},{isLargePayload:Qa,diagnostics:hh,remote:Bwe}),Uwe=cn({path:rt},{description:rt}),$we=cn({name:rt,implicit:Qa,files:Fi(Uwe)},{rationale:rt}),Hwe=cn({groups:Fi($we)},{overview:rt}),jwe=cn({resolvedOutputPath:rt,outputPathWritable:Qa}),zwe={theme:$s("light","dark","system"),diffView:$s("split","unified"),fontSize:yi,outputFormat:rt,outputFile:rt,ignore:hh,categories:Fi(cn({name:rt,description:rt,color:rt})),defaultDiffArgs:rt,showUntracked:Qa,showUntrackedExplicit:Qa,wordWrap:Qa,maxFiles:yi,maxTotalLines:yi,guideFile:rt},{guideFile:Gwe,...qwe}=zwe,Vwe=cn(qwe,{guideFile:Gwe}),Ywe=cn({comments:Fi(Owe)},{viewedFiles:hh,importDiagnostics:hh,remoteDrift:cn({recordedHeadSha:rt,liveHeadSha:rt,drifted:Qa})});function cc(e,t){return n=>{if(!t(n))throw new Za(`Malformed response from ${e}`,{status:200,code:"malformed-read-response"});return n}}const Wwe=cc("/api/diff",Bi(cn({diff:Pwe,guide:Bi(Hwe)}))),Kwe=cc("/api/config",Bi(cn({config:Vwe,outputPathInfo:Bi(jwe)}))),tB=cc("/api/resume",Bi(Ywe)),Xwe=cc("/api/file",Bi(SI)),Zwe=cc("/api/expand-context",Bi(cn({hunks:SI,totalLines:yi}))),Qwe=cc("/api/image",e=>cn({dataUri:rt})(e)||cn({error:rt})(e)),nB=32768;function Jwe(e){const t=new Uint8Array(e);let n="";for(let a=0;a<t.length;a+=nB)n+=String.fromCharCode(...t.subarray(a,a+nB));return btoa(n)}function aB(e){return e.map(t=>{const{data:n,...a}=t;return!n||n.byteLength===0?a:{...a,dataBase64:Jwe(n)}})}function eTe(e){return{timestamp:e.timestamp,source:e.source,files:e.files.map(t=>({...t,comments:t.comments.map(n=>({...n,...n.attachments?{attachments:aB(n.attachments)}:{},...n.replies?{replies:n.replies.map(a=>({...a,...a.attachments?{attachments:aB(a.attachments)}:{}}))}:{}}))}))}}async function tTe(e,t){let n;try{n=await e.json()}catch{n=null}if(Dl(n)&&n.filePath===t.filePath&&(n.status==="applied"&&typeof n.replacedLines=="number"&&Number.isSafeInteger(n.replacedLines)&&n.replacedLines>=0||n.status==="refused"&&typeof n.reason=="string"&&typeof n.detail=="string"))return n;throw new Za("The server did not return a valid Apply outcome for this file. Inspect the destination before continuing; do not apply again blindly.",{status:e.status,code:"outcome-unknown",uncertain:!0})}async function nTe(e){const t=await e.json();if(!Dl(t)||t.ok!==!0)throw new Za("The server answered without acknowledging the review as written. Check the terminal and output file before continuing; do not resend blindly.",{status:e.status,code:"outcome-unknown",uncertain:!0})}function iB(e,t){return new Za(`This review is ${gh(e)} MB as sent, over the server's ${gh(wI)} MB limit. Image attachments are the usual cause — they are base64-encoded on the wire, which adds a third — so remove or shrink some and press Finish Review again. Nothing has been lost.`,{status:t,code:xj})}function rB(e){return new Blob([e]).size}function Dy(e,t){return`${e}?path=${encodeURIComponent(t)}`}async function aTe(e,t=TI(e)){return Ij(t).getJson("/api/config",void 0,Kwe)}function iTe(e,t=TI(e)){const{getJson:n,postJson:a,postJsonText:i}=Ij(t),r={expandContext:(h,b)=>a("/api/expand-context",h,b,Zwe),loadFileContent:(h,b)=>n(Dy("/api/file",h),b,Xwe),loadImage:(h,b)=>n(Dy("/api/image",h),b,Qwe),readAttachment:(h,b)=>t.request(Dy("/api/attachment",h),{signal:b},async y=>{if(y.status===404)return null;if(!y.ok)throw await Kd(y,"Read attachment");return y.arrayBuffer()},"read")};let o=null,l=!1;const c=new Set,d=Awe(async h=>{const b=await n("/api/diff",h,Wwe);if(b===null)throw new Error("The server has no diff to review");return b},h=>{if(!l){o=h;for(const b of[...c])c.has(b)&&b(h)}});function p(h,b){const y=v=>{const T=h(v);T!==null&&b(T)};if(c.add(y),o){const v=o;Promise.resolve().then(()=>{!l&&c.has(y)&&y(v)})}else d.prefetch().catch(()=>{});return()=>{c.delete(y)}}const m=async h=>{const b=JSON.stringify(eTe(h)),y=rB(b);if(y>wI)throw iB(y,null);return i("/api/review",b,async v=>{if(v.status===413)throw iB(y,v.status);if(!v.ok)throw await Kd(v,"POST /api/review",!0);return nTe(v)})};return{reads:r,dispose:()=>{l=!0,c.clear(),d.dispose(),t.dispose()},initialReads:{loadDiff:async h=>(await d.read(h)).diff,loadResumedReview:async h=>await n("/api/resume",h,tB)??{comments:[],viewedFiles:[]}},loadDiff:async()=>(await d.read()).diff,loadResumedReview:async()=>await n("/api/resume",void 0,tB)??{comments:[],viewedFiles:[]},applySuggestion:async h=>{const b=JSON.stringify(h),y=rB(b),v=T=>new Za(`This suggestion is ${gh(y)} MB as sent, over the server's ${gh(eB)} MB limit. Shorten the proposed code before applying. Nothing was applied.`,{status:T,code:Ewe});if(y>eB)throw v(null);return i("/api/apply-suggestion",b,async T=>{if(T.status===413)throw v(413);if(!T.ok)throw await Kd(T,"POST /api/apply-suggestion",!0);return tTe(T,h)})},submitReview:m,publishReview:m,expandContext:h=>r.expandContext(h),loadFileContent:h=>r.loadFileContent(h),loadImage:h=>r.loadImage(h),readAttachment:async h=>r.readAttachment(h),onGuideLoad:h=>p(b=>b.guide,h),onDiffLoad:h=>p(b=>b.diff,h)}}function rTe(e){const[t,n]=w.useState(0),[a,i]=w.useState(null),[r,o]=w.useState(null),l=w.useRef(null),c=w.useCallback(()=>{const p=l.current;!p||p.capability!==e||p.connected||p.unauthorized||(p.retire(),n(m=>m+1))},[e]);w.useEffect(()=>{if(e===null)return;let p=!0;const m=TI(e),h=iTe(e,m),b={capability:e,revision:t,connected:!1,unauthorized:!1,retire:()=>{p=!1,h.dispose()}};return l.current=b,i(null),o(null),aTe(e,m).then(y=>{p&&l.current===b&&(b.connected=!0,i({adapter:h,config:y?.config??{},outputPathInfo:y?.outputPathInfo??null}))},y=>{p&&l.current===b&&(b.unauthorized=y instanceof Za&&y.status===401,o({message:y instanceof Error?y.message:String(y),unauthorized:b.unauthorized}),b.retire())}),b.retire},[e,t]);const d=e!==null&&l.current?.capability===e&&l.current.revision===t;return{connection:d?a:null,error:d?r:null,retry:c}}function sB(e){return e instanceof Za?{code:e.code,message:e.message,details:e.details,uncertain:e.uncertain}:{code:null,message:e instanceof Error?e.message:String(e),details:[]}}function sTe({onChange:e}){const t=Jb(),n=uI();return w.useEffect(e,[e,t,n]),null}function oTe(e,t){const[n,a]=w.useState("reviewing"),[i,r]=w.useState(null),[o,l]=w.useState(!1),c=w.useRef(!1),d=w.useRef(null),p=w.useRef(!0),m=w.useCallback(()=>l(!0),[]),h=w.useCallback(()=>{!d.current||d.current.current()||(d.current=null,c.current=!1,a("reviewing"),r(null))},[]);bwe(c),w.useEffect(()=>(p.current=!0,()=>{p.current=!1}),[]),w.useEffect(()=>{if(n==="submitted"||!o&&n!=="submitting"&&n!=="uncertain")return;const v=T=>T.preventDefault();return window.addEventListener("beforeunload",v),()=>window.removeEventListener("beforeunload",v)},[o,n]);const b=w.useCallback(async()=>{if(c.current||n==="submitted"||!t)return;let v;try{const T=e.current?.beginSave;if(!T)throw new Error("The review is not ready to save.");v=T()}catch(T){r(sB(T)),a("failed");return}d.current=v,c.current=!0,a("submitting"),r(null);try{if(!t.publishReview)throw Object.assign(new Error("Publication is unavailable."),{uncertain:!1});if(await t.publishReview(v.state),!p.current||d.current!==v||!v.current())return;c.current=!1,a("submitted")}catch(T){if(!p.current||d.current!==v||!v.current())return;const S=typeof T=="object"&&T!==null&&"uncertain"in T&&T.uncertain===!1;S&&(v.unlock(),d.current=null,c.current=!1),r({...sB(T),uncertain:!S}),a(S?"failed":"uncertain")}},[t,e,n]),y=w.useCallback(()=>{n!=="uncertain"||!window.confirm("Have you checked the terminal and output file and confirmed that this review was not saved? Only allow a retry if the original server is still running.")||(d.current?.unlock(),d.current=null,c.current=!1,a("reviewing"),r(null))},[n]);return{status:n,failure:i,finish:b,allowRetry:y,markUnsaved:m,sessionChanged:h}}function uTe(){const e=kwe(window.location.hash);return window.location.hash!==""&&window.history.replaceState(window.history.state,"",window.location.pathname+window.location.search),e}function lTe(){return E.jsxs(bh,{title:"Open the URL printed in the terminal",children:[E.jsxs("p",{"data-testid":"capability-notice",children:["This page needs the exact URL ",E.jsx("code",{children:"self-review-serve"})," printed when it started. The part after ",E.jsx("code",{children:"#"})," is this session's key, and a reloaded or retyped address does not have it."]}),E.jsx("p",{children:"Copy the URL from the terminal again and open it in this tab. If the terminal is gone, or the server has been restarted since, stop it and start it again: a fresh URL is printed every time."})]})}function cTe({info:e}){const{setOutputPathInfo:t}=B1e();return w.useEffect(()=>{e&&t(e)},[e,t]),null}function dTe({onChange:e}){const{files:t}=Zb(),n=DEe(),a=TH();w.useEffect(()=>{const r=o=>{a()&&o.preventDefault()};return window.addEventListener("beforeunload",r),()=>window.removeEventListener("beforeunload",r)},[a]);const i=w.useRef(t);return w.useEffect(()=>{const r=i.current;i.current=t,(n||t.some(o=>o.viewed||o.comments.length>0)||r.some(o=>{const l=t.find(c=>c.path===o.path);return l&&(l.viewed!==o.viewed||l.comments!==o.comments)}))&&e()},[t,n,e]),null}function fTe({outputPath:e}){return E.jsxs(bh,{title:"Review saved",children:[E.jsxs("p",{children:["The review was written to ",e?E.jsx("code",{children:e}):"the output file"," and the server has stopped."]}),E.jsxs("p",{children:["You can close this tab. To keep reviewing, start the server again with"," ",E.jsx("code",{children:"--resume-from"}),"."]})]})}function pTe({failure:e}){const t=!e.uncertain&&e.code!==xj;return E.jsxs("div",{role:"alert","data-testid":"submit-error",style:{padding:"0.5rem 0.75rem",background:"#7f1d1d",color:"#fff",fontSize:"0.8125rem",lineHeight:1.4},children:[E.jsxs("div",{children:[E.jsxs("strong",{children:[e.uncertain?"The save outcome is unknown":"The review was not saved",e.code?` (${e.code})`:"",":"]})," ",e.message]}),e.details.length>0&&E.jsx("ul",{style:{margin:"0.25rem 0 0",paddingLeft:"1.25rem"},children:e.details.map((n,a)=>E.jsx("li",{children:n},a))}),e.uncertain&&E.jsx("div",{children:"Your comments are still here. Check the terminal and the output file on the server. Stop the original process before restarting with --resume-from if the file was saved. If it was not saved and the original server is still running, you can allow a retry below. Keep this page open to preserve unsaved comments. No submission is retried automatically."}),t&&E.jsx("div",{style:{marginTop:"0.25rem"},children:"Your comments are still here. Fix the problem on the machine running the server, then press Finish Review again."})]})}function bh({title:e,children:t}){return E.jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:"2rem"},children:E.jsxs("div",{style:{maxWidth:"34rem",lineHeight:1.5},children:[E.jsx("h1",{style:{fontSize:"1.25rem",margin:"0 0 0.75rem"},children:e}),t]})})}function mTe(e){return E.jsx(gTe,{...e},e.capability)}function gTe({capability:e}){const{connection:t,error:n,retry:a}=rTe(e),i=t?.adapter??null,r=t?.config??null,o=t?.outputPathInfo??null,l=w.useRef(null),{status:c,failure:d,finish:p,allowRetry:m,markUnsaved:h,sessionChanged:b}=oTe(l,i);return e===null||n?.unauthorized?E.jsx(lTe,{}):n?E.jsxs(bh,{title:"Could not reach the review server",children:[E.jsxs("div",{role:"alert",children:[E.jsx("p",{children:n.message}),E.jsx("p",{children:"The process that served this page may have exited."})]}),E.jsx(Ye,{onClick:a,children:"Retry connection"})]}):c==="submitted"?E.jsx(fTe,{outputPath:o?.resolvedOutputPath??null}):!r||!i?E.jsx(bh,{title:"Connecting to the review server",children:E.jsx("p",{role:"status",children:"Waiting for the review server."})}):E.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[(c==="failed"||c==="uncertain")&&d&&E.jsx(pTe,{failure:d}),c==="uncertain"&&E.jsx("div",{className:"p-2","data-save-recovery":!0,children:E.jsx(Ye,{variant:"outline",onClick:m,children:"Allow retry after checking output"})}),E.jsx("div",{inert:c==="submitting"||c==="uncertain","aria-busy":c==="submitting","data-testid":"review-interaction",style:{flex:1,display:"flex",minHeight:0},children:E.jsxs(swe,{ref:l,adapter:i,config:r,className:"flex-1 flex flex-col overflow-hidden bg-background text-foreground",children:[E.jsx(sTe,{onChange:b}),E.jsx(dTe,{onChange:h}),E.jsx(cTe,{info:o}),E.jsx(mwe,{}),E.jsx(fwe,{onFinishReview:c==="uncertain"?void 0:()=>{p()}})]})})]})}const oB=document.getElementById("root");oB&&JG.createRoot(oB).render(E.jsx(mTe,{capability:uTe()}));export{nq as _,Po as g};