termdock 1.4.123 → 1.4.124

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 (70) hide show
  1. package/dist/client/assets/{ModelPreview-DGvy0ViD.js → ModelPreview-Be2smem8.js} +1 -1
  2. package/dist/client/assets/{abnfDiagram-VRR7QNED-BRUTM7Ij.js → abnfDiagram-VRR7QNED-BlflMbiO.js} +1 -1
  3. package/dist/client/assets/{arc-DeKie3_7.js → arc-BLcH6XEC.js} +1 -1
  4. package/dist/client/assets/{architectureDiagram-ZJ3FMSHR-CAorViVK.js → architectureDiagram-ZJ3FMSHR-CnBbD-1o.js} +1 -1
  5. package/dist/client/assets/{blockDiagram-677ZJIJ3-DHq1C73O.js → blockDiagram-677ZJIJ3-DPF-Ts3E.js} +1 -1
  6. package/dist/client/assets/{c4Diagram-LMCZKHZV-DluWWKuh.js → c4Diagram-LMCZKHZV-bj_qgr87.js} +1 -1
  7. package/dist/client/assets/channel-CwqZRIbt.js +1 -0
  8. package/dist/client/assets/{chunk-2Q5K7J3B-BPSQsAYp.js → chunk-2Q5K7J3B-BLPLyR9K.js} +1 -1
  9. package/dist/client/assets/{chunk-32BRIVSS-g93sHdJF.js → chunk-32BRIVSS-DWlXbXJt.js} +1 -1
  10. package/dist/client/assets/{chunk-5VM5RSS4-CvtNtBa-.js → chunk-5VM5RSS4-CEM0N0ye.js} +1 -1
  11. package/dist/client/assets/{chunk-EX3LRPZG-DWnR2mqn.js → chunk-EX3LRPZG-Dty9y4gw.js} +1 -1
  12. package/dist/client/assets/{chunk-JWPE2WC7-Dzbpe3Xo.js → chunk-JWPE2WC7-dlwhK_i1.js} +1 -1
  13. package/dist/client/assets/{chunk-MOJQB5TN-Du2Jw6Ga.js → chunk-MOJQB5TN-CX08FiG7.js} +1 -1
  14. package/dist/client/assets/{chunk-RYQCIY6F-DIqqwReI.js → chunk-RYQCIY6F-CoYfVCEL.js} +1 -1
  15. package/dist/client/assets/{chunk-V7JOEXUC-BDK2KnFE.js → chunk-V7JOEXUC-C_nJAEZ6.js} +1 -1
  16. package/dist/client/assets/{chunk-VR4S4FIN-BncB3kMk.js → chunk-VR4S4FIN-CxTZ4h0g.js} +1 -1
  17. package/dist/client/assets/{chunk-XXDRQBXY-CRx51cPn.js → chunk-XXDRQBXY-CRcElLUQ.js} +1 -1
  18. package/dist/client/assets/classDiagram-OUVF2IWQ-CsBWdSSp.js +1 -0
  19. package/dist/client/assets/classDiagram-v2-EOCWNBFH-CsBWdSSp.js +1 -0
  20. package/dist/client/assets/{cose-bilkent-JH36ORCC-C4eOHhIl.js → cose-bilkent-JH36ORCC-DopCQZMr.js} +1 -1
  21. package/dist/client/assets/{cynefin-VYW2F7L2-BZuh5fJN.js → cynefin-VYW2F7L2-C5lwo5rG.js} +1 -1
  22. package/dist/client/assets/{cynefinDiagram-TSTJHNR4-BdyBy9fD.js → cynefinDiagram-TSTJHNR4-BqE-HnNf.js} +1 -1
  23. package/dist/client/assets/{dagre-VKFMJZFB-tlpcqDkv.js → dagre-VKFMJZFB-Qnuvs3u5.js} +1 -1
  24. package/dist/client/assets/{diagram-FQU43EPY-DmryDLBx.js → diagram-FQU43EPY-T6rXZ6sy.js} +1 -1
  25. package/dist/client/assets/{diagram-G47NLZAW-DyaVVj3y.js → diagram-G47NLZAW-BlKH1yFL.js} +1 -1
  26. package/dist/client/assets/{diagram-NH7WQ7WH-DfwqogJh.js → diagram-NH7WQ7WH-BsAh_h83.js} +1 -1
  27. package/dist/client/assets/{diagram-OA4YK3LP-BHGytgzq.js → diagram-OA4YK3LP-DFFBJ56F.js} +1 -1
  28. package/dist/client/assets/{diagram-WEI45ONY-BW70jDhO.js → diagram-WEI45ONY-BAt9TFgr.js} +1 -1
  29. package/dist/client/assets/{ebnfDiagram-CCIWWBDH-BkvYsVdX.js → ebnfDiagram-CCIWWBDH-CZqTgzyZ.js} +1 -1
  30. package/dist/client/assets/{erDiagram-Q63AITRT-B-qynR5w.js → erDiagram-Q63AITRT-Des9G2E2.js} +1 -1
  31. package/dist/client/assets/{flowDiagram-23GEKE2U-C0uDIjVs.js → flowDiagram-23GEKE2U-D-GCzapP.js} +1 -1
  32. package/dist/client/assets/{ganttDiagram-NO4QXBWP-jHMmeGdm.js → ganttDiagram-NO4QXBWP-BGH_iM7_.js} +1 -1
  33. package/dist/client/assets/{gitGraphDiagram-IHSO6WYX-Cyp33RGh.js → gitGraphDiagram-IHSO6WYX-dheKFUpw.js} +1 -1
  34. package/dist/client/assets/{index-DPxgzRe_.js → index-DjYnI5kP.js} +23 -23
  35. package/dist/client/assets/{infoDiagram-FWYZ7A6U-BX1T5ZRV.js → infoDiagram-FWYZ7A6U-BZYW2clU.js} +1 -1
  36. package/dist/client/assets/{ishikawaDiagram-FXEZZL3T-BehchXvq.js → ishikawaDiagram-FXEZZL3T-Di9GvVpK.js} +1 -1
  37. package/dist/client/assets/{journeyDiagram-5HDEW3XC-Bdy1ed1k.js → journeyDiagram-5HDEW3XC-Bm_oN9-6.js} +1 -1
  38. package/dist/client/assets/{kanban-definition-HUTT4EX6-C7n-XF4G.js → kanban-definition-HUTT4EX6-tj1z1JQG.js} +1 -1
  39. package/dist/client/assets/{linear-Cj0QkFq-.js → linear-QXJ-Ae7F.js} +1 -1
  40. package/dist/client/assets/{mermaid.core-kFgOOXNm.js → mermaid.core-C2fDWTc4.js} +4 -4
  41. package/dist/client/assets/{mindmap-definition-LN4V7U3C-X3xTk9oE.js → mindmap-definition-LN4V7U3C-BilCFNik.js} +1 -1
  42. package/dist/client/assets/{pegDiagram-2B236MQR-DHr3LWfT.js → pegDiagram-2B236MQR-Cedi8jLg.js} +1 -1
  43. package/dist/client/assets/{pieDiagram-ENE6RG2P-Cgk4qJXy.js → pieDiagram-ENE6RG2P-u8doKeCT.js} +1 -1
  44. package/dist/client/assets/{quadrantDiagram-ABIIQ3AL-Db452gS6.js → quadrantDiagram-ABIIQ3AL-CTksDMFb.js} +1 -1
  45. package/dist/client/assets/{railroadDiagram-RFXS5EU6-Ch79_eAD.js → railroadDiagram-RFXS5EU6-a3hmKcli.js} +1 -1
  46. package/dist/client/assets/{requirementDiagram-TGXJPOKE-WeVLc483.js → requirementDiagram-TGXJPOKE-0CbosJM9.js} +1 -1
  47. package/dist/client/assets/{sankeyDiagram-HTMAVEWB-2ClPBKFi.js → sankeyDiagram-HTMAVEWB-DM9MM942.js} +1 -1
  48. package/dist/client/assets/{sequenceDiagram-DBY2YBRQ-DMOUB-GA.js → sequenceDiagram-DBY2YBRQ-DJYOI_VF.js} +1 -1
  49. package/dist/client/assets/{sizeCapture-X5ZJPWSS-QASuTy1-.js → sizeCapture-X5ZJPWSS-CayWxIRi.js} +1 -1
  50. package/dist/client/assets/{stateDiagram-2N3HPSRC-BNeDpvX-.js → stateDiagram-2N3HPSRC-BktX6ilb.js} +1 -1
  51. package/dist/client/assets/stateDiagram-v2-6OUMAXLB-DK505RoL.js +1 -0
  52. package/dist/client/assets/{swimlanes-5IMT3BWC-DvuVVUtW.js → swimlanes-5IMT3BWC-Duvbluwj.js} +2 -2
  53. package/dist/client/assets/swimlanesDiagram-G3AALYLV-CZTzB1q3.js +8 -0
  54. package/dist/client/assets/{timeline-definition-FHXFAJF6-DuTo7eYA.js → timeline-definition-FHXFAJF6-TdPH8RG8.js} +1 -1
  55. package/dist/client/assets/{vennDiagram-L72KCM5P-Do7RZnUg.js → vennDiagram-L72KCM5P-MQSsBdGx.js} +1 -1
  56. package/dist/client/assets/{wardleyDiagram-EHGQE667-BSvQIlfU.js → wardleyDiagram-EHGQE667-BcsapLTw.js} +1 -1
  57. package/dist/client/assets/{xychartDiagram-FW5EYKEG-BONZO9-F.js → xychartDiagram-FW5EYKEG-BSUPwtFh.js} +1 -1
  58. package/dist/client/index.html +1 -1
  59. package/dist/client/sw.js +1 -1
  60. package/dist/server/cli.js +17 -2
  61. package/dist/server/routes/filesystem.js +9 -3
  62. package/dist/server/routes/terminal.js +18 -2
  63. package/dist/server/utils/terminalColorEnvironment.js +46 -0
  64. package/package.json +1 -1
  65. package/runtime-manifest.json +2 -2
  66. package/dist/client/assets/channel-DXiU4T4d.js +0 -1
  67. package/dist/client/assets/classDiagram-OUVF2IWQ-CreSS-cc.js +0 -1
  68. package/dist/client/assets/classDiagram-v2-EOCWNBFH-CreSS-cc.js +0 -1
  69. package/dist/client/assets/stateDiagram-v2-6OUMAXLB-DUPNitKK.js +0 -1
  70. package/dist/client/assets/swimlanesDiagram-G3AALYLV-BhOFXgln.js +0 -8
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Ca-rq7yX.js","assets/react-XDCjal2T.js","assets/ModelPreview-DGvy0ViD.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-kFgOOXNm.js","assets/purify.es-CC4Brkr_.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Ca-rq7yX.js","assets/react-XDCjal2T.js","assets/ModelPreview-Be2smem8.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-C2fDWTc4.js","assets/purify.es-CC4Brkr_.js"])))=>i.map(i=>d[i]);
2
2
  import{r as ug,a as Xk,g as T7}from"./react-XDCjal2T.js";import{b,R as D,r as sa,a as Zk}from"./dnd-BCFAPC0L.js";import{L as Jk,l as e_}from"./terminal-C7X98Amf.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=n(s);fetch(s.href,i)}})();var w1={exports:{}},$0={};var Iv;function t_(){if(Iv)return $0;Iv=1;var e=ug(),t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,s=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function a(c,u,f){var p,g={},y=null,v=null;f!==void 0&&(y=""+f),u.key!==void 0&&(y=""+u.key),u.ref!==void 0&&(v=u.ref);for(p in u)r.call(u,p)&&!i.hasOwnProperty(p)&&(g[p]=u[p]);if(c&&c.defaultProps)for(p in u=c.defaultProps,u)g[p]===void 0&&(g[p]=u[p]);return{$$typeof:t,type:c,key:y,ref:v,props:g,_owner:s.current}}return $0.Fragment=n,$0.jsx=a,$0.jsxs=a,$0}var Rv;function n_(){return Rv||(Rv=1,w1.exports=t_()),w1.exports}var o=n_(),sp={},Nv;function r_(){if(Nv)return sp;Nv=1;var e=Xk();return sp.createRoot=e.createRoot,sp.hydrateRoot=e.hydrateRoot,sp}var s_=r_();const i_=T7(s_);function Mv(e){return e!==null&&typeof e=="object"&&"constructor"in e&&e.constructor===Object}function K2(e={},t={}){const n=["__proto__","constructor","prototype"];Object.keys(t).filter(r=>n.indexOf(r)<0).forEach(r=>{typeof e[r]>"u"?e[r]=t[r]:Mv(t[r])&&Mv(e[r])&&Object.keys(t[r]).length>0&&K2(e[r],t[r])})}const C7={body:{},addEventListener(){},removeEventListener(){},activeElement:{blur(){},nodeName:""},querySelector(){return null},querySelectorAll(){return[]},getElementById(){return null},createEvent(){return{initEvent(){}}},createElement(){return{children:[],childNodes:[],style:{},setAttribute(){},getElementsByTagName(){return[]}}},createElementNS(){return{}},importNode(){return null},location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""}};function Ku(){const e=typeof document<"u"?document:{};return K2(e,C7),e}const o_={document:C7,navigator:{userAgent:""},location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""},history:{replaceState(){},pushState(){},go(){},back(){}},CustomEvent:function(){return this},addEventListener(){},removeEventListener(){},getComputedStyle(){return{getPropertyValue(){return""}}},Image(){},Date(){},screen:{},setTimeout(){},clearTimeout(){},matchMedia(){return{}},requestAnimationFrame(e){return typeof setTimeout>"u"?(e(),null):setTimeout(e,0)},cancelAnimationFrame(e){typeof setTimeout>"u"||clearTimeout(e)}};function $o(){const e=typeof window<"u"?window:{};return K2(e,o_),e}function a_(e=""){return e.trim().split(" ").filter(t=>!!t.trim())}function l_(e){const t=e;Object.keys(t).forEach(n=>{try{t[n]=null}catch{}try{delete t[n]}catch{}})}function k7(e,t=0){return setTimeout(e,t)}function wm(){return Date.now()}function c_(e){const t=$o();let n;return t.getComputedStyle&&(n=t.getComputedStyle(e,null)),!n&&e.currentStyle&&(n=e.currentStyle),n||(n=e.style),n}function u_(e,t="x"){const n=$o();let r,s,i;const a=c_(e);return n.WebKitCSSMatrix?(s=a.transform||a.webkitTransform,s.split(",").length>6&&(s=s.split(", ").map(c=>c.replace(",",".")).join(", ")),i=new n.WebKitCSSMatrix(s==="none"?"":s)):(i=a.MozTransform||a.OTransform||a.MsTransform||a.msTransform||a.transform||a.getPropertyValue("transform").replace("translate(","matrix(1, 0, 0, 1,"),r=i.toString().split(",")),t==="x"&&(n.WebKitCSSMatrix?s=i.m41:r.length===16?s=parseFloat(r[12]):s=parseFloat(r[4])),t==="y"&&(n.WebKitCSSMatrix?s=i.m42:r.length===16?s=parseFloat(r[13]):s=parseFloat(r[5])),s||0}function ip(e){return typeof e=="object"&&e!==null&&e.constructor&&Object.prototype.toString.call(e).slice(8,-1)==="Object"}function d_(e){return typeof window<"u"&&typeof window.HTMLElement<"u"?e instanceof HTMLElement:e&&(e.nodeType===1||e.nodeType===11)}function ka(...e){const t=Object(e[0]);for(let n=1;n<e.length;n+=1){const r=e[n];if(r!=null&&!d_(r)){const s=Object.keys(Object(r)).filter(i=>i!=="__proto__"&&i!=="constructor"&&i!=="prototype");for(let i=0,a=s.length;i<a;i+=1){const c=s[i],u=Object.getOwnPropertyDescriptor(r,c);u!==void 0&&u.enumerable&&(ip(t[c])&&ip(r[c])?r[c].__swiper__?t[c]=r[c]:ka(t[c],r[c]):!ip(t[c])&&ip(r[c])?(t[c]={},r[c].__swiper__?t[c]=r[c]:ka(t[c],r[c])):t[c]=r[c])}}}return t}function wd(e,t,n){e.style.setProperty(t,n)}function _7({swiper:e,targetPosition:t,side:n}){const r=$o(),s=-e.translate;let i=null,a;const c=e.params.speed;e.wrapperEl.style.scrollSnapType="none",r.cancelAnimationFrame(e.cssModeFrameID);const u=t>s?"next":"prev",f=(g,y)=>u==="next"&&g>=y||u==="prev"&&g<=y,p=()=>{a=new Date().getTime(),i===null&&(i=a);const g=Math.max(Math.min((a-i)/c,1),0),y=.5-Math.cos(g*Math.PI)/2;let v=s+y*(t-s);if(f(v,t)&&(v=t),e.wrapperEl.scrollTo({[n]:v}),f(v,t)){e.wrapperEl.style.overflow="hidden",e.wrapperEl.style.scrollSnapType="",setTimeout(()=>{e.wrapperEl.style.overflow="",e.wrapperEl.scrollTo({[n]:v})}),r.cancelAnimationFrame(e.cssModeFrameID);return}e.cssModeFrameID=r.requestAnimationFrame(p)};p()}function bc(e,t=""){const n=$o(),r=[...e.children];return n.HTMLSlotElement&&e instanceof HTMLSlotElement&&r.push(...e.assignedElements()),t?r.filter(s=>s.matches(t)):r}function f_(e,t){const n=[t];for(;n.length>0;){const r=n.shift();if(e===r)return!0;n.push(...r.children,...r.shadowRoot?r.shadowRoot.children:[],...r.assignedElements?r.assignedElements():[])}}function h_(e,t){const n=$o();let r=t.contains(e);return!r&&n.HTMLSlotElement&&t instanceof HTMLSlotElement&&(r=[...t.assignedElements()].includes(e),r||(r=f_(e,t))),r}function Sm(e){try{console.warn(e);return}catch{}}function gb(e,t=[]){const n=document.createElement(e);return n.classList.add(...Array.isArray(t)?t:a_(t)),n}function p_(e,t){const n=[];for(;e.previousElementSibling;){const r=e.previousElementSibling;t?r.matches(t)&&n.push(r):n.push(r),e=r}return n}function m_(e,t){const n=[];for(;e.nextElementSibling;){const r=e.nextElementSibling;t?r.matches(t)&&n.push(r):n.push(r),e=r}return n}function qc(e,t){return $o().getComputedStyle(e,null).getPropertyValue(t)}function Dv(e){let t=e,n;if(t){for(n=0;(t=t.previousSibling)!==null;)t.nodeType===1&&(n+=1);return n}}function g_(e,t){const n=[];let r=e.parentElement;for(;r;)n.push(r),r=r.parentElement;return n}function jv(e,t,n){const r=$o();return e[t==="width"?"offsetWidth":"offsetHeight"]+parseFloat(r.getComputedStyle(e,null).getPropertyValue(t==="width"?"margin-right":"margin-top"))+parseFloat(r.getComputedStyle(e,null).getPropertyValue(t==="width"?"margin-left":"margin-bottom"))}function Pv(e,t=""){typeof trustedTypes<"u"?e.innerHTML=trustedTypes.createPolicy("html",{createHTML:n=>n}).createHTML(t):e.innerHTML=t}let S1;function x_(){const e=$o(),t=Ku();return{smoothScroll:t.documentElement&&t.documentElement.style&&"scrollBehavior"in t.documentElement.style,touch:!!("ontouchstart"in e||e.DocumentTouch&&t instanceof e.DocumentTouch)}}function L7(){return S1||(S1=x_()),S1}let A1;function b_({userAgent:e}={}){const t=L7(),n=$o(),r=n.navigator.platform,s=e||n.navigator.userAgent,i={ios:!1,android:!1},a=n.screen.width,c=n.screen.height,u=s.match(/(Android);?[\s\/]+([\d.]+)?/);let f=s.match(/(iPad)(?!\1).*OS\s([\d_]+)/);const p=s.match(/(iPod)(.*OS\s([\d_]+))?/),g=!f&&s.match(/(iPhone\sOS|iOS)\s([\d_]+)/),y=r==="Win32";let v=r==="MacIntel";const S=["1024x1366","1366x1024","834x1194","1194x834","834x1112","1112x834","768x1024","1024x768","820x1180","1180x820","810x1080","1080x810"];return!f&&v&&t.touch&&S.indexOf(`${a}x${c}`)>=0&&(f=s.match(/(Version)\/([\d.]+)/),f||(f=[0,1,"13_0_0"]),v=!1),u&&!y&&(i.os="android",i.android=!0),(f||g||p)&&(i.os="ios",i.ios=!0),i}function E7(e={}){return A1||(A1=b_(e)),A1}let T1;function y_(){const e=$o(),t=E7();let n=!1;function r(){const c=e.navigator.userAgent.toLowerCase();return c.indexOf("safari")>=0&&c.indexOf("chrome")<0&&c.indexOf("android")<0}if(r()){const c=String(e.navigator.userAgent);if(c.includes("Version/")){const[u,f]=c.split("Version/")[1].split(" ")[0].split(".").map(p=>Number(p));n=u<16||u===16&&f<2}}const s=/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(e.navigator.userAgent),i=r(),a=i||s&&t.ios;return{isSafari:n||i,needPerspectiveFix:n,need3dFix:a,isWebView:s}}function I7(){return T1||(T1=y_()),T1}function v_({swiper:e,on:t,emit:n}){const r=$o();let s=null,i=null;const a=()=>{!e||e.destroyed||!e.initialized||(n("beforeResize"),n("resize"))},c=()=>{!e||e.destroyed||!e.initialized||(s=new ResizeObserver(p=>{i=r.requestAnimationFrame(()=>{const{width:g,height:y}=e;let v=g,S=y;p.forEach(({contentBoxSize:A,contentRect:T,target:L})=>{L&&L!==e.el||(v=T?T.width:(A[0]||A).inlineSize,S=T?T.height:(A[0]||A).blockSize)}),(v!==g||S!==y)&&a()})}),s.observe(e.el))},u=()=>{i&&r.cancelAnimationFrame(i),s&&s.unobserve&&e.el&&(s.unobserve(e.el),s=null)},f=()=>{!e||e.destroyed||!e.initialized||n("orientationchange")};t("init",()=>{if(e.params.resizeObserver&&typeof r.ResizeObserver<"u"){c();return}r.addEventListener("resize",a),r.addEventListener("orientationchange",f)}),t("destroy",()=>{u(),r.removeEventListener("resize",a),r.removeEventListener("orientationchange",f)})}function w_({swiper:e,extendParams:t,on:n,emit:r}){const s=[],i=$o(),a=(f,p={})=>{const g=i.MutationObserver||i.WebkitMutationObserver,y=new g(v=>{if(e.__preventObserver__)return;if(v.length===1){r("observerUpdate",v[0]);return}const S=function(){r("observerUpdate",v[0])};i.requestAnimationFrame?i.requestAnimationFrame(S):i.setTimeout(S,0)});y.observe(f,{attributes:typeof p.attributes>"u"?!0:p.attributes,childList:e.isElement||(typeof p.childList>"u"?!0:p).childList,characterData:typeof p.characterData>"u"?!0:p.characterData}),s.push(y)},c=()=>{if(e.params.observer){if(e.params.observeParents){const f=g_(e.hostEl);for(let p=0;p<f.length;p+=1)a(f[p])}a(e.hostEl,{childList:e.params.observeSlideChildren}),a(e.wrapperEl,{attributes:!1})}},u=()=>{s.forEach(f=>{f.disconnect()}),s.splice(0,s.length)};t({observer:!1,observeParents:!1,observeSlideChildren:!1}),n("init",c),n("destroy",u)}var S_={on(e,t,n){const r=this;if(!r.eventsListeners||r.destroyed||typeof t!="function")return r;const s=n?"unshift":"push";return e.split(" ").forEach(i=>{r.eventsListeners[i]||(r.eventsListeners[i]=[]),r.eventsListeners[i][s](t)}),r},once(e,t,n){const r=this;if(!r.eventsListeners||r.destroyed||typeof t!="function")return r;function s(...i){r.off(e,s),s.__emitterProxy&&delete s.__emitterProxy,t.apply(r,i)}return s.__emitterProxy=t,r.on(e,s,n)},onAny(e,t){const n=this;if(!n.eventsListeners||n.destroyed||typeof e!="function")return n;const r=t?"unshift":"push";return n.eventsAnyListeners.indexOf(e)<0&&n.eventsAnyListeners[r](e),n},offAny(e){const t=this;if(!t.eventsListeners||t.destroyed||!t.eventsAnyListeners)return t;const n=t.eventsAnyListeners.indexOf(e);return n>=0&&t.eventsAnyListeners.splice(n,1),t},off(e,t){const n=this;return!n.eventsListeners||n.destroyed||!n.eventsListeners||e.split(" ").forEach(r=>{typeof t>"u"?n.eventsListeners[r]=[]:n.eventsListeners[r]&&n.eventsListeners[r].forEach((s,i)=>{(s===t||s.__emitterProxy&&s.__emitterProxy===t)&&n.eventsListeners[r].splice(i,1)})}),n},emit(...e){const t=this;if(!t.eventsListeners||t.destroyed||!t.eventsListeners)return t;let n,r,s;return typeof e[0]=="string"||Array.isArray(e[0])?(n=e[0],r=e.slice(1,e.length),s=t):(n=e[0].events,r=e[0].data,s=e[0].context||t),r.unshift(s),(Array.isArray(n)?n:n.split(" ")).forEach(a=>{t.eventsAnyListeners&&t.eventsAnyListeners.length&&t.eventsAnyListeners.forEach(c=>{c.apply(s,[a,...r])}),t.eventsListeners&&t.eventsListeners[a]&&t.eventsListeners[a].forEach(c=>{c.apply(s,r)})}),t}};function A_(){const e=this;let t,n;const r=e.el;typeof e.params.width<"u"&&e.params.width!==null?t=e.params.width:t=r.clientWidth,typeof e.params.height<"u"&&e.params.height!==null?n=e.params.height:n=r.clientHeight,!(t===0&&e.isHorizontal()||n===0&&e.isVertical())&&(t=t-parseInt(qc(r,"padding-left")||0,10)-parseInt(qc(r,"padding-right")||0,10),n=n-parseInt(qc(r,"padding-top")||0,10)-parseInt(qc(r,"padding-bottom")||0,10),Number.isNaN(t)&&(t=0),Number.isNaN(n)&&(n=0),Object.assign(e,{width:t,height:n,size:e.isHorizontal()?t:n}))}function T_(){const e=this;function t(Y,V){return parseFloat(Y.getPropertyValue(e.getDirectionLabel(V))||0)}const n=e.params,{wrapperEl:r,slidesEl:s,rtlTranslate:i,wrongRTL:a}=e,c=e.virtual&&n.virtual.enabled,u=c?e.virtual.slides.length:e.slides.length,f=bc(s,`.${e.params.slideClass}, swiper-slide`),p=c?e.virtual.slides.length:f.length;let g=[];const y=[],v=[];let S=n.slidesOffsetBefore;typeof S=="function"&&(S=n.slidesOffsetBefore.call(e));let A=n.slidesOffsetAfter;typeof A=="function"&&(A=n.slidesOffsetAfter.call(e));const T=e.snapGrid.length,L=e.slidesGrid.length,I=e.size-S-A;let j=n.spaceBetween,P=-S,F=0,R=0;if(typeof I>"u")return;typeof j=="string"&&j.indexOf("%")>=0?j=parseFloat(j.replace("%",""))/100*I:typeof j=="string"&&(j=parseFloat(j)),e.virtualSize=-j-S-A,f.forEach(Y=>{i?Y.style.marginLeft="":Y.style.marginRight="",Y.style.marginBottom="",Y.style.marginTop=""}),n.centeredSlides&&n.cssMode&&(wd(r,"--swiper-centered-offset-before",""),wd(r,"--swiper-centered-offset-after","")),n.cssMode&&(wd(r,"--swiper-slides-offset-before",`${S}px`),wd(r,"--swiper-slides-offset-after",`${A}px`));const C=n.grid&&n.grid.rows>1&&e.grid;C?e.grid.initSlides(f):e.grid&&e.grid.unsetSlides();let $;const H=n.slidesPerView==="auto"&&n.breakpoints&&Object.keys(n.breakpoints).filter(Y=>typeof n.breakpoints[Y].slidesPerView<"u").length>0;for(let Y=0;Y<p;Y+=1){$=0;const V=f[Y];if(!(V&&(C&&e.grid.updateSlide(Y,V,f),qc(V,"display")==="none"))){if(c&&n.slidesPerView==="auto")n.virtual.slidesPerViewAutoSlideSize&&($=n.virtual.slidesPerViewAutoSlideSize),$&&V&&(n.roundLengths&&($=Math.floor($)),V.style[e.getDirectionLabel("width")]=`${$}px`);else if(n.slidesPerView==="auto"){H&&(V.style[e.getDirectionLabel("width")]="");const fe=getComputedStyle(V),X=V.style.transform,ve=V.style.webkitTransform;if(X&&(V.style.transform="none"),ve&&(V.style.webkitTransform="none"),n.roundLengths)$=e.isHorizontal()?jv(V,"width"):jv(V,"height");else{const we=t(fe,"width"),ie=t(fe,"padding-left"),ae=t(fe,"padding-right"),q=t(fe,"margin-left"),z=t(fe,"margin-right"),te=fe.getPropertyValue("box-sizing");if(te&&te==="border-box")$=we+q+z;else{const{clientWidth:pe,offsetWidth:de}=V;$=we+ie+ae+q+z+(de-pe)}}X&&(V.style.transform=X),ve&&(V.style.webkitTransform=ve),n.roundLengths&&($=Math.floor($))}else $=(I-(n.slidesPerView-1)*j)/n.slidesPerView,n.roundLengths&&($=Math.floor($)),V&&(V.style[e.getDirectionLabel("width")]=`${$}px`);V&&(V.swiperSlideSize=$),v.push($),n.centeredSlides?(P=P+$/2+F/2+j,F===0&&Y!==0&&(P=P-I/2-j),Y===0&&(P=P-I/2-j),Math.abs(P)<1/1e3&&(P=0),n.roundLengths&&(P=Math.floor(P)),R%n.slidesPerGroup===0&&g.push(P),y.push(P)):(n.roundLengths&&(P=Math.floor(P)),(R-Math.min(e.params.slidesPerGroupSkip,R))%e.params.slidesPerGroup===0&&g.push(P),y.push(P),P=P+$+j),e.virtualSize+=$+j,F=$,R+=1}}if(e.virtualSize=Math.max(e.virtualSize,I)+A,i&&a&&(n.effect==="slide"||n.effect==="coverflow")&&(r.style.width=`${e.virtualSize+j}px`),n.setWrapperSize&&(r.style[e.getDirectionLabel("width")]=`${e.virtualSize+j}px`),C&&e.grid.updateWrapperSize($,g),!n.centeredSlides){const Y=n.slidesPerView!=="auto"&&n.slidesPerView%1!==0,V=n.snapToSlideEdge&&!n.loop&&(n.slidesPerView==="auto"||Y);let fe=g.length;if(V){let ve;if(n.slidesPerView==="auto"){ve=1;let we=0;for(let ie=v.length-1;ie>=0&&(we+=v[ie]+(ie<v.length-1?j:0),we<=I);ie-=1)ve=v.length-ie}else ve=Math.floor(n.slidesPerView);fe=Math.max(p-ve,0)}const X=[];for(let ve=0;ve<g.length;ve+=1){let we=g[ve];n.roundLengths&&(we=Math.floor(we)),V?ve<=fe&&X.push(we):g[ve]<=e.virtualSize-I&&X.push(we)}g=X,Math.floor(e.virtualSize-I)-Math.floor(g[g.length-1])>1&&(V||g.push(e.virtualSize-I))}if(c&&n.loop){const Y=v[0]+j;if(n.slidesPerGroup>1){const V=Math.ceil((e.virtual.slidesBefore+e.virtual.slidesAfter)/n.slidesPerGroup),fe=Y*n.slidesPerGroup;for(let X=0;X<V;X+=1)g.push(g[g.length-1]+fe)}for(let V=0;V<e.virtual.slidesBefore+e.virtual.slidesAfter;V+=1)n.slidesPerGroup===1&&g.push(g[g.length-1]+Y),y.push(y[y.length-1]+Y),e.virtualSize+=Y}if(g.length===0&&(g=[0]),j!==0){const Y=e.isHorizontal()&&i?"marginLeft":e.getDirectionLabel("marginRight");f.filter((V,fe)=>!n.cssMode||n.loop?!0:fe!==f.length-1).forEach(V=>{V.style[Y]=`${j}px`})}if(n.centeredSlides&&n.centeredSlidesBounds){let Y=0;v.forEach(fe=>{Y+=fe+(j||0)}),Y-=j;const V=Y>I?Y-I:0;g=g.map(fe=>fe<=0?-S:fe>V?V+A:fe)}if(n.centerInsufficientSlides){let Y=0;if(v.forEach(V=>{Y+=V+(j||0)}),Y-=j,Y<I){const V=(I-Y)/2;g.forEach((fe,X)=>{g[X]=fe-V}),y.forEach((fe,X)=>{y[X]=fe+V})}}if(Object.assign(e,{slides:f,snapGrid:g,slidesGrid:y,slidesSizesGrid:v}),n.centeredSlides&&n.cssMode&&!n.centeredSlidesBounds){wd(r,"--swiper-centered-offset-before",`${-g[0]}px`),wd(r,"--swiper-centered-offset-after",`${e.size/2-v[v.length-1]/2}px`);const Y=-e.snapGrid[0],V=-e.slidesGrid[0];e.snapGrid=e.snapGrid.map(fe=>fe+Y),e.slidesGrid=e.slidesGrid.map(fe=>fe+V)}if(p!==u&&e.emit("slidesLengthChange"),g.length!==T&&(e.params.watchOverflow&&e.checkOverflow(),e.emit("snapGridLengthChange")),y.length!==L&&e.emit("slidesGridLengthChange"),n.watchSlidesProgress&&e.updateSlidesOffset(),e.emit("slidesUpdated"),!c&&!n.cssMode&&(n.effect==="slide"||n.effect==="fade")){const Y=`${n.containerModifierClass}backface-hidden`,V=e.el.classList.contains(Y);p<=n.maxBackfaceHiddenSlides?V||e.el.classList.add(Y):V&&e.el.classList.remove(Y)}}function C_(e){const t=this,n=[],r=t.virtual&&t.params.virtual.enabled;let s=0,i;typeof e=="number"?t.setTransition(e):e===!0&&t.setTransition(t.params.speed);const a=c=>r?t.slides[t.getSlideIndexByData(c)]:t.slides[c];if(t.params.slidesPerView!=="auto"&&t.params.slidesPerView>1)if(t.params.centeredSlides)(t.visibleSlides||[]).forEach(c=>{n.push(c)});else for(i=0;i<Math.ceil(t.params.slidesPerView);i+=1){const c=t.activeIndex+i;if(c>t.slides.length&&!r)break;n.push(a(c))}else n.push(a(t.activeIndex));for(i=0;i<n.length;i+=1)if(typeof n[i]<"u"){const c=n[i].offsetHeight;s=c>s?c:s}(s||s===0)&&(t.wrapperEl.style.height=`${s}px`)}function k_(){const e=this,t=e.slides,n=e.isElement?e.isHorizontal()?e.wrapperEl.offsetLeft:e.wrapperEl.offsetTop:0;for(let r=0;r<t.length;r+=1)t[r].swiperSlideOffset=(e.isHorizontal()?t[r].offsetLeft:t[r].offsetTop)-n-e.cssOverflowAdjustment()}const Bv=(e,t,n)=>{t&&!e.classList.contains(n)?e.classList.add(n):!t&&e.classList.contains(n)&&e.classList.remove(n)};function __(e=this&&this.translate||0){const t=this,n=t.params,{slides:r,rtlTranslate:s,snapGrid:i}=t;if(r.length===0)return;typeof r[0].swiperSlideOffset>"u"&&t.updateSlidesOffset();let a=-e;s&&(a=e),t.visibleSlidesIndexes=[],t.visibleSlides=[];let c=n.spaceBetween;typeof c=="string"&&c.indexOf("%")>=0?c=parseFloat(c.replace("%",""))/100*t.size:typeof c=="string"&&(c=parseFloat(c));for(let u=0;u<r.length;u+=1){const f=r[u];let p=f.swiperSlideOffset;n.cssMode&&n.centeredSlides&&(p-=r[0].swiperSlideOffset);const g=(a+(n.centeredSlides?t.minTranslate():0)-p)/(f.swiperSlideSize+c),y=(a-i[0]+(n.centeredSlides?t.minTranslate():0)-p)/(f.swiperSlideSize+c),v=-(a-p),S=v+t.slidesSizesGrid[u],A=v>=0&&v<=t.size-t.slidesSizesGrid[u],T=v>=0&&v<t.size-1||S>1&&S<=t.size||v<=0&&S>=t.size;T&&(t.visibleSlides.push(f),t.visibleSlidesIndexes.push(u)),Bv(f,T,n.slideVisibleClass),Bv(f,A,n.slideFullyVisibleClass),f.progress=s?-g:g,f.originalProgress=s?-y:y}}function L_(e){const t=this;if(typeof e>"u"){const p=t.rtlTranslate?-1:1;e=t&&t.translate&&t.translate*p||0}const n=t.params,r=t.maxTranslate()-t.minTranslate();let{progress:s,isBeginning:i,isEnd:a,progressLoop:c}=t;const u=i,f=a;if(r===0)s=0,i=!0,a=!0;else{s=(e-t.minTranslate())/r;const p=Math.abs(e-t.minTranslate())<1,g=Math.abs(e-t.maxTranslate())<1;i=p||s<=0,a=g||s>=1,p&&(s=0),g&&(s=1)}if(n.loop){const p=t.getSlideIndexByData(0),g=t.getSlideIndexByData(t.slides.length-1),y=t.slidesGrid[p],v=t.slidesGrid[g],S=t.slidesGrid[t.slidesGrid.length-1],A=Math.abs(e);A>=y?c=(A-y)/S:c=(A+S-v)/S,c>1&&(c-=1)}Object.assign(t,{progress:s,progressLoop:c,isBeginning:i,isEnd:a}),(n.watchSlidesProgress||n.centeredSlides&&n.autoHeight)&&t.updateSlidesProgress(e),i&&!u&&t.emit("reachBeginning toEdge"),a&&!f&&t.emit("reachEnd toEdge"),(u&&!i||f&&!a)&&t.emit("fromEdge"),t.emit("progress",s)}const C1=(e,t,n)=>{t&&!e.classList.contains(n)?e.classList.add(n):!t&&e.classList.contains(n)&&e.classList.remove(n)};function E_(){const e=this,{slides:t,params:n,slidesEl:r,activeIndex:s}=e,i=e.virtual&&n.virtual.enabled,a=e.grid&&n.grid&&n.grid.rows>1,c=g=>bc(r,`.${n.slideClass}${g}, swiper-slide${g}`)[0];let u,f,p;if(i)if(n.loop){let g=s-e.virtual.slidesBefore;g<0&&(g=e.virtual.slides.length+g),g>=e.virtual.slides.length&&(g-=e.virtual.slides.length),u=c(`[data-swiper-slide-index="${g}"]`)}else u=c(`[data-swiper-slide-index="${s}"]`);else a?(u=t.find(g=>g.column===s),p=t.find(g=>g.column===s+1),f=t.find(g=>g.column===s-1)):u=t[s];u&&(a||(p=m_(u,`.${n.slideClass}, swiper-slide`)[0],n.loop&&!p&&(p=t[0]),f=p_(u,`.${n.slideClass}, swiper-slide`)[0],n.loop&&!f===0&&(f=t[t.length-1]))),t.forEach(g=>{C1(g,g===u,n.slideActiveClass),C1(g,g===p,n.slideNextClass),C1(g,g===f,n.slidePrevClass)}),e.emitSlidesClasses()}const Kp=(e,t)=>{if(!e||e.destroyed||!e.params)return;const n=()=>e.isElement?"swiper-slide":`.${e.params.slideClass}`,r=t.closest(n());if(r){let s=r.querySelector(`.${e.params.lazyPreloaderClass}`);!s&&e.isElement&&(r.shadowRoot?s=r.shadowRoot.querySelector(`.${e.params.lazyPreloaderClass}`):requestAnimationFrame(()=>{r.shadowRoot&&(s=r.shadowRoot.querySelector(`.${e.params.lazyPreloaderClass}`),s&&!s.lazyPreloaderManaged&&s.remove())})),s&&!s.lazyPreloaderManaged&&s.remove()}},k1=(e,t)=>{if(!e.slides[t])return;const n=e.slides[t].querySelector('[loading="lazy"]');n&&n.removeAttribute("loading")},xb=e=>{if(!e||e.destroyed||!e.params)return;let t=e.params.lazyPreloadPrevNext;const n=e.slides.length;if(!n||!t||t<0)return;t=Math.min(t,n);const r=e.params.slidesPerView==="auto"?e.slidesPerViewDynamic():Math.ceil(e.params.slidesPerView),s=e.activeIndex;if(e.params.grid&&e.params.grid.rows>1){const a=s,c=[a-t];c.push(...Array.from({length:t}).map((u,f)=>a+r+f)),e.slides.forEach((u,f)=>{c.includes(u.column)&&k1(e,f)});return}const i=s+r-1;if(e.params.rewind||e.params.loop)for(let a=s-t;a<=i+t;a+=1){const c=(a%n+n)%n;(c<s||c>i)&&k1(e,c)}else for(let a=Math.max(s-t,0);a<=Math.min(i+t,n-1);a+=1)a!==s&&(a>i||a<s)&&k1(e,a)};function I_(e){const{slidesGrid:t,params:n}=e,r=e.rtlTranslate?e.translate:-e.translate;let s;for(let i=0;i<t.length;i+=1)typeof t[i+1]<"u"?r>=t[i]&&r<t[i+1]-(t[i+1]-t[i])/2?s=i:r>=t[i]&&r<t[i+1]&&(s=i+1):r>=t[i]&&(s=i);return n.normalizeSlideIndex&&(s<0||typeof s>"u")&&(s=0),s}function R_(e){const t=this,n=t.rtlTranslate?t.translate:-t.translate,{snapGrid:r,params:s,activeIndex:i,realIndex:a,snapIndex:c}=t;let u=e,f;const p=v=>{let S=v-t.virtual.slidesBefore;return S<0&&(S=t.virtual.slides.length+S),S>=t.virtual.slides.length&&(S-=t.virtual.slides.length),S};if(typeof u>"u"&&(u=I_(t)),r.indexOf(n)>=0)f=r.indexOf(n);else{const v=Math.min(s.slidesPerGroupSkip,u);f=v+Math.floor((u-v)/s.slidesPerGroup)}if(f>=r.length&&(f=r.length-1),u===i&&!t.params.loop){f!==c&&(t.snapIndex=f,t.emit("snapIndexChange"));return}if(u===i&&t.params.loop&&t.virtual&&t.params.virtual.enabled){t.realIndex=p(u);return}const g=t.grid&&s.grid&&s.grid.rows>1;let y;if(t.virtual&&s.virtual.enabled)s.loop?y=p(u):y=u;else if(g){const v=t.slides.find(A=>A.column===u);let S=parseInt(v.getAttribute("data-swiper-slide-index"),10);Number.isNaN(S)&&(S=Math.max(t.slides.indexOf(v),0)),y=Math.floor(S/s.grid.rows)}else if(t.slides[u]){const v=t.slides[u].getAttribute("data-swiper-slide-index");v?y=parseInt(v,10):y=u}else y=u;Object.assign(t,{previousSnapIndex:c,snapIndex:f,previousRealIndex:a,realIndex:y,previousIndex:i,activeIndex:u}),t.initialized&&xb(t),t.emit("activeIndexChange"),t.emit("snapIndexChange"),(t.initialized||t.params.runCallbacksOnInit)&&(a!==y&&t.emit("realIndexChange"),t.emit("slideChange"))}function N_(e,t){const n=this,r=n.params;let s=e.closest(`.${r.slideClass}, swiper-slide`);!s&&n.isElement&&t&&t.length>1&&t.includes(e)&&[...t.slice(t.indexOf(e)+1,t.length)].forEach(c=>{!s&&c.matches&&c.matches(`.${r.slideClass}, swiper-slide`)&&(s=c)});let i=!1,a;if(s){for(let c=0;c<n.slides.length;c+=1)if(n.slides[c]===s){i=!0,a=c;break}}if(s&&i)n.clickedSlide=s,n.virtual&&n.params.virtual.enabled?n.clickedIndex=parseInt(s.getAttribute("data-swiper-slide-index"),10):n.clickedIndex=a;else{n.clickedSlide=void 0,n.clickedIndex=void 0;return}r.slideToClickedSlide&&n.clickedIndex!==void 0&&n.clickedIndex!==n.activeIndex&&n.slideToClickedSlide()}var M_={updateSize:A_,updateSlides:T_,updateAutoHeight:C_,updateSlidesOffset:k_,updateSlidesProgress:__,updateProgress:L_,updateSlidesClasses:E_,updateActiveIndex:R_,updateClickedSlide:N_};function D_(e=this.isHorizontal()?"x":"y"){const t=this,{params:n,rtlTranslate:r,translate:s,wrapperEl:i}=t;if(n.virtualTranslate)return r?-s:s;if(n.cssMode)return s;let a=u_(i,e);return a+=t.cssOverflowAdjustment(),r&&(a=-a),a||0}function j_(e,t){const n=this,{rtlTranslate:r,params:s,wrapperEl:i,progress:a}=n;let c=0,u=0;const f=0;n.isHorizontal()?c=r?-e:e:u=e,s.roundLengths&&(c=Math.floor(c),u=Math.floor(u)),n.previousTranslate=n.translate,n.translate=n.isHorizontal()?c:u,s.cssMode?i[n.isHorizontal()?"scrollLeft":"scrollTop"]=n.isHorizontal()?-c:-u:s.virtualTranslate||(n.isHorizontal()?c-=n.cssOverflowAdjustment():u-=n.cssOverflowAdjustment(),i.style.transform=`translate3d(${c}px, ${u}px, ${f}px)`);let p;const g=n.maxTranslate()-n.minTranslate();g===0?p=0:p=(e-n.minTranslate())/g,p!==a&&n.updateProgress(e),n.emit("setTranslate",n.translate,t)}function P_(){return-this.snapGrid[0]}function B_(){return-this.snapGrid[this.snapGrid.length-1]}function F_(e=0,t=this.params.speed,n=!0,r=!0,s){const i=this,{params:a,wrapperEl:c}=i;if(i.animating&&a.preventInteractionOnTransition)return!1;const u=i.minTranslate(),f=i.maxTranslate();let p;if(r&&e>u?p=u:r&&e<f?p=f:p=e,i.updateProgress(p),a.cssMode){const g=i.isHorizontal();if(t===0)c[g?"scrollLeft":"scrollTop"]=-p;else{if(!i.support.smoothScroll)return _7({swiper:i,targetPosition:-p,side:g?"left":"top"}),!0;c.scrollTo({[g?"left":"top"]:-p,behavior:"smooth"})}return!0}return t===0?(i.setTransition(0),i.setTranslate(p),n&&(i.emit("beforeTransitionStart",t,s),i.emit("transitionEnd"))):(i.setTransition(t),i.setTranslate(p),n&&(i.emit("beforeTransitionStart",t,s),i.emit("transitionStart")),i.animating||(i.animating=!0,i.onTranslateToWrapperTransitionEnd||(i.onTranslateToWrapperTransitionEnd=function(y){!i||i.destroyed||y.target===this&&(i.wrapperEl.removeEventListener("transitionend",i.onTranslateToWrapperTransitionEnd),i.onTranslateToWrapperTransitionEnd=null,delete i.onTranslateToWrapperTransitionEnd,i.animating=!1,n&&i.emit("transitionEnd"))}),i.wrapperEl.addEventListener("transitionend",i.onTranslateToWrapperTransitionEnd))),!0}var O_={getTranslate:D_,setTranslate:j_,minTranslate:P_,maxTranslate:B_,translateTo:F_};function Q_(e,t){const n=this;n.params.cssMode||(n.wrapperEl.style.transitionDuration=`${e}ms`,n.wrapperEl.style.transitionDelay=e===0?"0ms":""),n.emit("setTransition",e,t)}function R7({swiper:e,runCallbacks:t,direction:n,step:r}){const{activeIndex:s,previousIndex:i}=e;let a=n;a||(s>i?a="next":s<i?a="prev":a="reset"),e.emit(`transition${r}`),t&&a==="reset"?e.emit(`slideResetTransition${r}`):t&&s!==i&&(e.emit(`slideChangeTransition${r}`),a==="next"?e.emit(`slideNextTransition${r}`):e.emit(`slidePrevTransition${r}`))}function $_(e=!0,t){const n=this,{params:r}=n;r.cssMode||(r.autoHeight&&n.updateAutoHeight(),R7({swiper:n,runCallbacks:e,direction:t,step:"Start"}))}function H_(e=!0,t){const n=this,{params:r}=n;n.animating=!1,!r.cssMode&&(n.setTransition(0),R7({swiper:n,runCallbacks:e,direction:t,step:"End"}))}var U_={setTransition:Q_,transitionStart:$_,transitionEnd:H_};function z_(e=0,t,n=!0,r,s){typeof e=="string"&&(e=parseInt(e,10));const i=this;let a=e;a<0&&(a=0);const{params:c,snapGrid:u,slidesGrid:f,previousIndex:p,activeIndex:g,rtlTranslate:y,wrapperEl:v,enabled:S}=i;if(!S&&!r&&!s||i.destroyed||i.animating&&c.preventInteractionOnTransition)return!1;typeof t>"u"&&(t=i.params.speed);const A=Math.min(i.params.slidesPerGroupSkip,a);let T=A+Math.floor((a-A)/i.params.slidesPerGroup);T>=u.length&&(T=u.length-1);const L=-u[T];if(c.normalizeSlideIndex)for(let C=0;C<f.length;C+=1){const $=-Math.floor(L*100),H=Math.floor(f[C]*100),Y=Math.floor(f[C+1]*100);typeof f[C+1]<"u"?$>=H&&$<Y-(Y-H)/2?a=C:$>=H&&$<Y&&(a=C+1):$>=H&&(a=C)}if(i.initialized&&a!==g&&(!i.allowSlideNext&&(y?L>i.translate&&L>i.minTranslate():L<i.translate&&L<i.minTranslate())||!i.allowSlidePrev&&L>i.translate&&L>i.maxTranslate()&&(g||0)!==a))return!1;a!==(p||0)&&n&&i.emit("beforeSlideChangeStart"),i.updateProgress(L);let I;a>g?I="next":a<g?I="prev":I="reset";const j=i.virtual&&i.params.virtual.enabled;if(!(j&&s)&&(y&&-L===i.translate||!y&&L===i.translate))return i.updateActiveIndex(a),c.autoHeight&&i.updateAutoHeight(),i.updateSlidesClasses(),c.effect!=="slide"&&i.setTranslate(L),I!=="reset"&&(i.transitionStart(n,I),i.transitionEnd(n,I)),!1;if(c.cssMode){const C=i.isHorizontal(),$=y?L:-L;if(t===0)j&&(i.wrapperEl.style.scrollSnapType="none",i._immediateVirtual=!0),j&&!i._cssModeVirtualInitialSet&&i.params.initialSlide>0?(i._cssModeVirtualInitialSet=!0,requestAnimationFrame(()=>{v[C?"scrollLeft":"scrollTop"]=$})):v[C?"scrollLeft":"scrollTop"]=$,j&&requestAnimationFrame(()=>{i.wrapperEl.style.scrollSnapType="",i._immediateVirtual=!1});else{if(!i.support.smoothScroll)return _7({swiper:i,targetPosition:$,side:C?"left":"top"}),!0;v.scrollTo({[C?"left":"top"]:$,behavior:"smooth"})}return!0}const R=I7().isSafari;return j&&!s&&R&&i.isElement&&i.virtual.update(!1,!1,a),i.setTransition(t),i.setTranslate(L),i.updateActiveIndex(a),i.updateSlidesClasses(),i.emit("beforeTransitionStart",t,r),i.transitionStart(n,I),t===0?i.transitionEnd(n,I):i.animating||(i.animating=!0,i.onSlideToWrapperTransitionEnd||(i.onSlideToWrapperTransitionEnd=function($){!i||i.destroyed||$.target===this&&(i.wrapperEl.removeEventListener("transitionend",i.onSlideToWrapperTransitionEnd),i.onSlideToWrapperTransitionEnd=null,delete i.onSlideToWrapperTransitionEnd,i.transitionEnd(n,I))}),i.wrapperEl.addEventListener("transitionend",i.onSlideToWrapperTransitionEnd)),!0}function G_(e=0,t,n=!0,r){typeof e=="string"&&(e=parseInt(e,10));const s=this;if(s.destroyed)return;typeof t>"u"&&(t=s.params.speed);const i=s.grid&&s.params.grid&&s.params.grid.rows>1;let a=e;if(s.params.loop)if(s.virtual&&s.params.virtual.enabled)a=a+s.virtual.slidesBefore;else{let c;if(i){const A=a*s.params.grid.rows;c=s.slides.find(T=>T.getAttribute("data-swiper-slide-index")*1===A).column}else c=s.getSlideIndexByData(a);const u=i?Math.ceil(s.slides.length/s.params.grid.rows):s.slides.length,{centeredSlides:f,slidesOffsetBefore:p,slidesOffsetAfter:g}=s.params,y=f||!!p||!!g;let v=s.params.slidesPerView;v==="auto"?v=s.slidesPerViewDynamic():(v=Math.ceil(parseFloat(s.params.slidesPerView,10)),y&&v%2===0&&(v=v+1));let S=u-c<v;if(y&&(S=S||c<Math.ceil(v/2)),r&&y&&s.params.slidesPerView!=="auto"&&!i&&(S=!1),S){const A=y?c<s.activeIndex?"prev":"next":c-s.activeIndex-1<s.params.slidesPerView?"next":"prev";s.loopFix({direction:A,slideTo:!0,activeSlideIndex:A==="next"?c+1:c-u+1,slideRealIndex:A==="next"?s.realIndex:void 0})}if(i){const A=a*s.params.grid.rows;a=s.slides.find(T=>T.getAttribute("data-swiper-slide-index")*1===A).column}else a=s.getSlideIndexByData(a)}return requestAnimationFrame(()=>{s.slideTo(a,t,n,r)}),s}function W_(e,t=!0,n){const r=this,{enabled:s,params:i,animating:a}=r;if(!s||r.destroyed)return r;typeof e>"u"&&(e=r.params.speed);let c=i.slidesPerGroup;i.slidesPerView==="auto"&&i.slidesPerGroup===1&&i.slidesPerGroupAuto&&(c=Math.max(r.slidesPerViewDynamic("current",!0),1));const u=r.activeIndex<i.slidesPerGroupSkip?1:c,f=r.virtual&&i.virtual.enabled;if(i.loop){if(a&&!f&&i.loopPreventsSliding)return!1;if(r.loopFix({direction:"next"}),r._clientLeft=r.wrapperEl.clientLeft,r.activeIndex===r.slides.length-1&&i.cssMode)return requestAnimationFrame(()=>{r.slideTo(r.activeIndex+u,e,t,n)}),!0}return i.rewind&&r.isEnd?r.slideTo(0,e,t,n):r.slideTo(r.activeIndex+u,e,t,n)}function V_(e,t=!0,n){const r=this,{params:s,snapGrid:i,slidesGrid:a,rtlTranslate:c,enabled:u,animating:f}=r;if(!u||r.destroyed)return r;typeof e>"u"&&(e=r.params.speed);const p=r.virtual&&s.virtual.enabled;if(s.loop){if(f&&!p&&s.loopPreventsSliding)return!1;r.loopFix({direction:"prev"}),r._clientLeft=r.wrapperEl.clientLeft}const g=c?r.translate:-r.translate;function y(I){return I<0?-Math.floor(Math.abs(I)):Math.floor(I)}const v=y(g),S=i.map(I=>y(I)),A=s.freeMode&&s.freeMode.enabled;let T=i[S.indexOf(v)-1];if(typeof T>"u"&&(s.cssMode||A)){let I;i.forEach((j,P)=>{v>=j&&(I=P)}),typeof I<"u"&&(T=A?i[I]:i[I>0?I-1:I])}let L=0;if(typeof T<"u"&&(L=a.indexOf(T),L<0&&(L=r.activeIndex-1),s.slidesPerView==="auto"&&s.slidesPerGroup===1&&s.slidesPerGroupAuto&&(L=L-r.slidesPerViewDynamic("previous",!0)+1,L=Math.max(L,0))),s.rewind&&r.isBeginning){const I=r.params.virtual&&r.params.virtual.enabled&&r.virtual?r.virtual.slides.length-1:r.slides.length-1;return r.slideTo(I,e,t,n)}else if(s.loop&&r.activeIndex===0&&s.cssMode)return requestAnimationFrame(()=>{r.slideTo(L,e,t,n)}),!0;return r.slideTo(L,e,t,n)}function q_(e,t=!0,n){const r=this;if(!r.destroyed)return typeof e>"u"&&(e=r.params.speed),r.slideTo(r.activeIndex,e,t,n)}function Y_(e,t=!0,n,r=.5){const s=this;if(s.destroyed)return;typeof e>"u"&&(e=s.params.speed);let i=s.activeIndex;const a=Math.min(s.params.slidesPerGroupSkip,i),c=a+Math.floor((i-a)/s.params.slidesPerGroup),u=s.rtlTranslate?s.translate:-s.translate;if(u>=s.snapGrid[c]){const f=s.snapGrid[c],p=s.snapGrid[c+1];u-f>(p-f)*r&&(i+=s.params.slidesPerGroup)}else{const f=s.snapGrid[c-1],p=s.snapGrid[c];u-f<=(p-f)*r&&(i-=s.params.slidesPerGroup)}return i=Math.max(i,0),i=Math.min(i,s.slidesGrid.length-1),s.slideTo(i,e,t,n)}function K_(){const e=this;if(e.destroyed)return;const{params:t,slidesEl:n}=e,r=t.slidesPerView==="auto"?e.slidesPerViewDynamic():t.slidesPerView;let s=e.getSlideIndexWhenGrid(e.clickedIndex),i;const a=e.isElement?"swiper-slide":`.${t.slideClass}`,c=e.grid&&e.params.grid&&e.params.grid.rows>1;if(t.loop){if(e.animating)return;i=parseInt(e.clickedSlide.getAttribute("data-swiper-slide-index"),10),t.centeredSlides?e.slideToLoop(i):s>(c?(e.slides.length-r)/2-(e.params.grid.rows-1):e.slides.length-r)?(e.loopFix(),s=e.getSlideIndex(bc(n,`${a}[data-swiper-slide-index="${i}"]`)[0]),k7(()=>{e.slideTo(s)})):e.slideTo(s)}else e.slideTo(s)}var X_={slideTo:z_,slideToLoop:G_,slideNext:W_,slidePrev:V_,slideReset:q_,slideToClosest:Y_,slideToClickedSlide:K_};function Z_(e,t){const n=this,{params:r,slidesEl:s}=n;if(!r.loop||n.virtual&&n.params.virtual.enabled)return;const i=()=>{bc(s,`.${r.slideClass}, swiper-slide`).forEach((S,A)=>{S.setAttribute("data-swiper-slide-index",A)})},a=()=>{const v=bc(s,`.${r.slideBlankClass}`);v.forEach(S=>{S.remove()}),v.length>0&&(n.recalcSlides(),n.updateSlides())},c=n.grid&&r.grid&&r.grid.rows>1;r.loopAddBlankSlides&&(r.slidesPerGroup>1||c)&&a();const u=r.slidesPerGroup*(c?r.grid.rows:1),f=n.slides.length%u!==0,p=c&&n.slides.length%r.grid.rows!==0,g=v=>{for(let S=0;S<v;S+=1){const A=n.isElement?gb("swiper-slide",[r.slideBlankClass]):gb("div",[r.slideClass,r.slideBlankClass]);n.slidesEl.append(A)}};if(f){if(r.loopAddBlankSlides){const v=u-n.slides.length%u;g(v),n.recalcSlides(),n.updateSlides()}else Sm("Swiper Loop Warning: The number of slides is not even to slidesPerGroup, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)");i()}else if(p){if(r.loopAddBlankSlides){const v=r.grid.rows-n.slides.length%r.grid.rows;g(v),n.recalcSlides(),n.updateSlides()}else Sm("Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)");i()}else i();const y=r.centeredSlides||!!r.slidesOffsetBefore||!!r.slidesOffsetAfter;n.loopFix({slideRealIndex:e,direction:y?void 0:"next",initial:t})}function J_({slideRealIndex:e,slideTo:t=!0,direction:n,setTranslate:r,activeSlideIndex:s,initial:i,byController:a,byMousewheel:c}={}){const u=this;if(!u.params.loop)return;u.emit("beforeLoopFix");const{slides:f,allowSlidePrev:p,allowSlideNext:g,slidesEl:y,params:v}=u,{centeredSlides:S,slidesOffsetBefore:A,slidesOffsetAfter:T,initialSlide:L}=v,I=S||!!A||!!T;if(u.allowSlidePrev=!0,u.allowSlideNext=!0,u.virtual&&v.virtual.enabled){t&&(!I&&u.snapIndex===0?u.slideTo(u.virtual.slides.length,0,!1,!0):I&&u.snapIndex<v.slidesPerView?u.slideTo(u.virtual.slides.length+u.snapIndex,0,!1,!0):u.snapIndex===u.snapGrid.length-1&&u.slideTo(u.virtual.slidesBefore,0,!1,!0)),u.allowSlidePrev=p,u.allowSlideNext=g,u.emit("loopFix");return}let j=v.slidesPerView;j==="auto"?j=u.slidesPerViewDynamic():(j=Math.ceil(parseFloat(v.slidesPerView,10)),I&&j%2===0&&(j=j+1));const P=v.slidesPerGroupAuto?j:v.slidesPerGroup;let F=I?Math.max(P,Math.ceil(j/2)):P;F%P!==0&&(F+=P-F%P),F+=v.loopAdditionalSlides,u.loopedSlides=F;const R=u.grid&&v.grid&&v.grid.rows>1;f.length<j+F||u.params.effect==="cards"&&f.length<j+F*2?Sm("Swiper Loop Warning: The number of slides is not enough for loop mode, it will be disabled or not function properly. You need to add more slides (or make duplicates) or lower the values of slidesPerView and slidesPerGroup parameters"):R&&v.grid.fill==="row"&&Sm("Swiper Loop Warning: Loop mode is not compatible with grid.fill = `row`");const C=[],$=[],H=R?Math.ceil(f.length/v.grid.rows):f.length,Y=i&&H-L<j&&!I;let V=Y?L:u.activeIndex;typeof s>"u"?s=u.getSlideIndex(f.find(q=>q.classList.contains(v.slideActiveClass))):V=s;const fe=n==="next"||!n,X=n==="prev"||!n;let ve=0,we=0;const ae=(R?f[s].column:s)+(I&&typeof r>"u"?-j/2+.5:0);if(ae<F){ve=Math.max(F-ae,P);for(let q=0;q<F-ae;q+=1){const z=q-Math.floor(q/H)*H;if(R){const te=H-z-1;for(let pe=f.length-1;pe>=0;pe-=1)f[pe].column===te&&C.push(pe)}else C.push(H-z-1)}}else if(ae+j>H-F){we=Math.max(ae-(H-F*2),P),Y&&(we=Math.max(we,j-H+L+1));for(let q=0;q<we;q+=1){const z=q-Math.floor(q/H)*H;R?f.forEach((te,pe)=>{te.column===z&&$.push(pe)}):$.push(z)}}if(u.__preventObserver__=!0,requestAnimationFrame(()=>{u.__preventObserver__=!1}),u.params.effect==="cards"&&f.length<j+F*2&&($.includes(s)&&$.splice($.indexOf(s),1),C.includes(s)&&C.splice(C.indexOf(s),1)),X&&C.forEach(q=>{f[q].swiperLoopMoveDOM=!0,y.prepend(f[q]),f[q].swiperLoopMoveDOM=!1}),fe&&$.forEach(q=>{f[q].swiperLoopMoveDOM=!0,y.append(f[q]),f[q].swiperLoopMoveDOM=!1}),u.recalcSlides(),v.slidesPerView==="auto"?u.updateSlides():R&&(C.length>0&&X||$.length>0&&fe)&&u.slides.forEach((q,z)=>{u.grid.updateSlide(z,q,u.slides)}),v.watchSlidesProgress&&u.updateSlidesOffset(),t){if(C.length>0&&X){if(typeof e>"u"){const q=u.slidesGrid[V],te=u.slidesGrid[V+ve]-q;c?u.setTranslate(u.translate-te):(u.slideTo(V+Math.ceil(ve),0,!1,!0),r&&(u.touchEventsData.startTranslate=u.touchEventsData.startTranslate-te,u.touchEventsData.currentTranslate=u.touchEventsData.currentTranslate-te))}else if(r){const q=R?C.length/v.grid.rows:C.length;u.slideTo(u.activeIndex+q,0,!1,!0),u.touchEventsData.currentTranslate=u.translate}}else if($.length>0&&fe)if(typeof e>"u"){const q=u.slidesGrid[V],te=u.slidesGrid[V-we]-q;c?u.setTranslate(u.translate-te):(u.slideTo(V-we,0,!1,!0),r&&(u.touchEventsData.startTranslate=u.touchEventsData.startTranslate-te,u.touchEventsData.currentTranslate=u.touchEventsData.currentTranslate-te))}else{const q=R?$.length/v.grid.rows:$.length;u.slideTo(u.activeIndex-q,0,!1,!0)}}if(u.allowSlidePrev=p,u.allowSlideNext=g,u.controller&&u.controller.control&&!a){const q={slideRealIndex:e,direction:n,setTranslate:r,activeSlideIndex:s,byController:!0};Array.isArray(u.controller.control)?u.controller.control.forEach(z=>{!z.destroyed&&z.params.loop&&z.loopFix({...q,slideTo:z.params.slidesPerView===v.slidesPerView?t:!1})}):u.controller.control instanceof u.constructor&&u.controller.control.params.loop&&u.controller.control.loopFix({...q,slideTo:u.controller.control.params.slidesPerView===v.slidesPerView?t:!1})}u.emit("loopFix")}function eL(){const e=this,{params:t,slidesEl:n}=e;if(!t.loop||!n||e.virtual&&e.params.virtual.enabled)return;e.recalcSlides();const r=[];e.slides.forEach(s=>{const i=typeof s.swiperSlideIndex>"u"?s.getAttribute("data-swiper-slide-index")*1:s.swiperSlideIndex;r[i]=s}),e.slides.forEach(s=>{s.removeAttribute("data-swiper-slide-index")}),r.forEach(s=>{n.append(s)}),e.recalcSlides(),e.slideTo(e.realIndex,0)}var tL={loopCreate:Z_,loopFix:J_,loopDestroy:eL};function nL(e){const t=this;if(!t.params.simulateTouch||t.params.watchOverflow&&t.isLocked||t.params.cssMode)return;const n=t.params.touchEventsTarget==="container"?t.el:t.wrapperEl;t.isElement&&(t.__preventObserver__=!0),n.style.cursor="move",n.style.cursor=e?"grabbing":"grab",t.isElement&&requestAnimationFrame(()=>{t.__preventObserver__=!1})}function rL(){const e=this;e.params.watchOverflow&&e.isLocked||e.params.cssMode||(e.isElement&&(e.__preventObserver__=!0),e[e.params.touchEventsTarget==="container"?"el":"wrapperEl"].style.cursor="",e.isElement&&requestAnimationFrame(()=>{e.__preventObserver__=!1}))}var sL={setGrabCursor:nL,unsetGrabCursor:rL};function iL(e,t=this){function n(r){if(!r||r===Ku()||r===$o())return null;r.assignedSlot&&(r=r.assignedSlot);const s=r.closest(e);return!s&&!r.getRootNode?null:s||n(r.getRootNode().host)}return n(t)}function Fv(e,t,n){const r=$o(),{params:s}=e,i=s.edgeSwipeDetection,a=s.edgeSwipeThreshold;return i&&(n<=a||n>=r.innerWidth-a)?i==="prevent"?(t.preventDefault(),!0):!1:!0}function oL(e){const t=this;if(t.destroyed)return;const n=Ku();let r=e;r.originalEvent&&(r=r.originalEvent);const s=t.touchEventsData;if(r.type==="pointerdown"){if(s.pointerId!==null&&s.pointerId!==r.pointerId)return;s.pointerId=r.pointerId}else r.type==="touchstart"&&r.targetTouches.length===1&&(s.touchId=r.targetTouches[0].identifier);if(r.type==="touchstart"){Fv(t,r,r.targetTouches[0].pageX);return}const{params:i,touches:a,enabled:c}=t;if(!c||!i.simulateTouch&&r.pointerType==="mouse"||t.animating&&i.preventInteractionOnTransition)return;!t.animating&&i.cssMode&&i.loop&&t.loopFix();let u=r.target;if(i.touchEventsTarget==="wrapper"&&!h_(u,t.wrapperEl)||"which"in r&&r.which===3||"button"in r&&r.button>0||s.isTouched&&s.isMoved)return;const f=!!i.noSwipingClass&&i.noSwipingClass!=="",p=r.composedPath?r.composedPath():r.path;f&&r.target&&r.target.shadowRoot&&p&&(u=p[0]);const g=i.noSwipingSelector?i.noSwipingSelector:`.${i.noSwipingClass}`,y=!!(r.target&&r.target.shadowRoot);if(i.noSwiping&&(y?iL(g,u):u.closest(g))){t.allowClick=!0;return}if(i.swipeHandler&&!u.closest(i.swipeHandler))return;a.currentX=r.pageX,a.currentY=r.pageY;const v=a.currentX,S=a.currentY;if(!Fv(t,r,v))return;Object.assign(s,{isTouched:!0,isMoved:!1,allowTouchCallbacks:!0,isScrolling:void 0,startMoving:void 0}),a.startX=v,a.startY=S,s.touchStartTime=wm(),t.allowClick=!0,t.updateSize(),t.swipeDirection=void 0,i.threshold>0&&(s.allowThresholdMove=!1);let A=!0;u.matches(s.focusableElements)&&(A=!1,u.nodeName==="SELECT"&&(s.isTouched=!1)),n.activeElement&&n.activeElement.matches(s.focusableElements)&&n.activeElement!==u&&(r.pointerType==="mouse"||r.pointerType!=="mouse"&&!u.matches(s.focusableElements))&&n.activeElement.blur();const T=A&&t.allowTouchMove&&i.touchStartPreventDefault;(i.touchStartForcePreventDefault||T)&&!u.isContentEditable&&r.preventDefault(),i.freeMode&&i.freeMode.enabled&&t.freeMode&&t.animating&&!i.cssMode&&t.freeMode.onTouchStart(),t.emit("touchStart",r)}function aL(e){const t=Ku(),n=this;if(n.destroyed)return;const r=n.touchEventsData,{params:s,touches:i,rtlTranslate:a,enabled:c}=n;if(!c||!s.simulateTouch&&e.pointerType==="mouse")return;let u=e;if(u.originalEvent&&(u=u.originalEvent),u.type==="pointermove"&&(r.touchId!==null||u.pointerId!==r.pointerId))return;let f;if(u.type==="touchmove"){if(f=[...u.changedTouches].find(F=>F.identifier===r.touchId),!f||f.identifier!==r.touchId)return}else f=u;if(!r.isTouched){r.startMoving&&r.isScrolling&&n.emit("touchMoveOpposite",u);return}const p=f.pageX,g=f.pageY;if(u.preventedByNestedSwiper){i.startX=p,i.startY=g;return}if(!n.allowTouchMove){u.target.matches(r.focusableElements)||(n.allowClick=!1),r.isTouched&&(Object.assign(i,{startX:p,startY:g,currentX:p,currentY:g}),r.touchStartTime=wm());return}if(s.touchReleaseOnEdges&&!s.loop)if(n.isVertical()){if(g<i.startY&&n.translate<=n.maxTranslate()||g>i.startY&&n.translate>=n.minTranslate()){r.isTouched=!1,r.isMoved=!1;return}}else{if(a&&(p>i.startX&&-n.translate<=n.maxTranslate()||p<i.startX&&-n.translate>=n.minTranslate()))return;if(!a&&(p<i.startX&&n.translate<=n.maxTranslate()||p>i.startX&&n.translate>=n.minTranslate()))return}if(t.activeElement&&t.activeElement.matches(r.focusableElements)&&t.activeElement!==u.target&&u.pointerType!=="mouse"&&t.activeElement.blur(),t.activeElement&&u.target===t.activeElement&&u.target.matches(r.focusableElements)){r.isMoved=!0,n.allowClick=!1;return}r.allowTouchCallbacks&&n.emit("touchMove",u),i.previousX=i.currentX,i.previousY=i.currentY,i.currentX=p,i.currentY=g;const y=i.currentX-i.startX,v=i.currentY-i.startY;if(n.params.threshold&&Math.sqrt(y**2+v**2)<n.params.threshold)return;if(typeof r.isScrolling>"u"){let F;n.isHorizontal()&&i.currentY===i.startY||n.isVertical()&&i.currentX===i.startX?r.isScrolling=!1:y*y+v*v>=25&&(F=Math.atan2(Math.abs(v),Math.abs(y))*180/Math.PI,r.isScrolling=n.isHorizontal()?F>s.touchAngle:90-F>s.touchAngle)}if(r.isScrolling&&n.emit("touchMoveOpposite",u),typeof r.startMoving>"u"&&(i.currentX!==i.startX||i.currentY!==i.startY)&&(r.startMoving=!0),r.isScrolling||u.type==="touchmove"&&r.preventTouchMoveFromPointerMove){r.isTouched=!1;return}if(!r.startMoving)return;n.allowClick=!1,!s.cssMode&&u.cancelable&&u.preventDefault(),s.touchMoveStopPropagation&&!s.nested&&u.stopPropagation();let S=n.isHorizontal()?y:v,A=n.isHorizontal()?i.currentX-i.previousX:i.currentY-i.previousY;s.oneWayMovement&&(S=Math.abs(S)*(a?1:-1),A=Math.abs(A)*(a?1:-1)),i.diff=S,S*=s.touchRatio,a&&(S=-S,A=-A);const T=n.touchesDirection;n.swipeDirection=S>0?"prev":"next",n.touchesDirection=A>0?"prev":"next";const L=n.params.loop&&!s.cssMode,I=n.touchesDirection==="next"&&n.allowSlideNext||n.touchesDirection==="prev"&&n.allowSlidePrev;if(!r.isMoved){if(L&&I&&n.loopFix({direction:n.swipeDirection}),r.startTranslate=n.getTranslate(),n.setTransition(0),n.animating){const F=new window.CustomEvent("transitionend",{bubbles:!0,cancelable:!0,detail:{bySwiperTouchMove:!0}});n.wrapperEl.dispatchEvent(F)}r.allowMomentumBounce=!1,s.grabCursor&&(n.allowSlideNext===!0||n.allowSlidePrev===!0)&&n.setGrabCursor(!0),n.emit("sliderFirstMove",u)}if(new Date().getTime(),s._loopSwapReset!==!1&&r.isMoved&&r.allowThresholdMove&&T!==n.touchesDirection&&L&&I&&Math.abs(S)>=1){Object.assign(i,{startX:p,startY:g,currentX:p,currentY:g,startTranslate:r.currentTranslate}),r.loopSwapReset=!0,r.startTranslate=r.currentTranslate;return}n.emit("sliderMove",u),r.isMoved=!0,r.currentTranslate=S+r.startTranslate;let j=!0,P=s.resistanceRatio;if(s.touchReleaseOnEdges&&(P=0),S>0?(L&&I&&r.allowThresholdMove&&r.currentTranslate>(s.centeredSlides?n.minTranslate()-n.slidesSizesGrid[n.activeIndex+1]-(s.slidesPerView!=="auto"&&n.slides.length-s.slidesPerView>=2?n.slidesSizesGrid[n.activeIndex+1]+n.params.spaceBetween:0)-n.params.spaceBetween:n.minTranslate())&&n.loopFix({direction:"prev",setTranslate:!0,activeSlideIndex:0}),r.currentTranslate>n.minTranslate()&&(j=!1,s.resistance&&(r.currentTranslate=n.minTranslate()-1+(-n.minTranslate()+r.startTranslate+S)**P))):S<0&&(L&&I&&r.allowThresholdMove&&r.currentTranslate<(s.centeredSlides?n.maxTranslate()+n.slidesSizesGrid[n.slidesSizesGrid.length-1]+n.params.spaceBetween+(s.slidesPerView!=="auto"&&n.slides.length-s.slidesPerView>=2?n.slidesSizesGrid[n.slidesSizesGrid.length-1]+n.params.spaceBetween:0):n.maxTranslate())&&n.loopFix({direction:"next",setTranslate:!0,activeSlideIndex:n.slides.length-(s.slidesPerView==="auto"?n.slidesPerViewDynamic():Math.ceil(parseFloat(s.slidesPerView,10)))}),r.currentTranslate<n.maxTranslate()&&(j=!1,s.resistance&&(r.currentTranslate=n.maxTranslate()+1-(n.maxTranslate()-r.startTranslate-S)**P))),j&&(u.preventedByNestedSwiper=!0),!n.allowSlideNext&&n.swipeDirection==="next"&&r.currentTranslate<r.startTranslate&&(r.currentTranslate=r.startTranslate),!n.allowSlidePrev&&n.swipeDirection==="prev"&&r.currentTranslate>r.startTranslate&&(r.currentTranslate=r.startTranslate),!n.allowSlidePrev&&!n.allowSlideNext&&(r.currentTranslate=r.startTranslate),s.threshold>0)if(Math.abs(S)>s.threshold||r.allowThresholdMove){if(!r.allowThresholdMove){r.allowThresholdMove=!0,i.startX=i.currentX,i.startY=i.currentY,r.currentTranslate=r.startTranslate,i.diff=n.isHorizontal()?i.currentX-i.startX:i.currentY-i.startY;return}}else{r.currentTranslate=r.startTranslate;return}!s.followFinger||s.cssMode||((s.freeMode&&s.freeMode.enabled&&n.freeMode||s.watchSlidesProgress)&&(n.updateActiveIndex(),n.updateSlidesClasses()),s.freeMode&&s.freeMode.enabled&&n.freeMode&&n.freeMode.onTouchMove(),n.updateProgress(r.currentTranslate),n.setTranslate(r.currentTranslate))}function lL(e){const t=this;if(t.destroyed)return;const n=t.touchEventsData;let r=e;r.originalEvent&&(r=r.originalEvent);let s;if(r.type==="touchend"||r.type==="touchcancel"){if(s=[...r.changedTouches].find(F=>F.identifier===n.touchId),!s||s.identifier!==n.touchId)return}else{if(n.touchId!==null||r.pointerId!==n.pointerId)return;s=r}if(["pointercancel","pointerout","pointerleave","contextmenu"].includes(r.type)&&!(["pointercancel","contextmenu"].includes(r.type)&&(t.browser.isSafari||t.browser.isWebView)))return;n.pointerId=null,n.touchId=null;const{params:a,touches:c,rtlTranslate:u,slidesGrid:f,enabled:p}=t;if(!p||!a.simulateTouch&&r.pointerType==="mouse")return;if(n.allowTouchCallbacks&&t.emit("touchEnd",r),n.allowTouchCallbacks=!1,!n.isTouched){n.isMoved&&a.grabCursor&&t.setGrabCursor(!1),n.isMoved=!1,n.startMoving=!1;return}a.grabCursor&&n.isMoved&&n.isTouched&&(t.allowSlideNext===!0||t.allowSlidePrev===!0)&&t.setGrabCursor(!1);const g=wm(),y=g-n.touchStartTime;if(t.allowClick){const F=r.path||r.composedPath&&r.composedPath();t.updateClickedSlide(F&&F[0]||r.target,F),t.emit("tap click",r),y<300&&g-n.lastClickTime<300&&t.emit("doubleTap doubleClick",r)}if(n.lastClickTime=wm(),k7(()=>{t.destroyed||(t.allowClick=!0)}),!n.isTouched||!n.isMoved||!t.swipeDirection||c.diff===0&&!n.loopSwapReset||n.currentTranslate===n.startTranslate&&!n.loopSwapReset){n.isTouched=!1,n.isMoved=!1,n.startMoving=!1;return}n.isTouched=!1,n.isMoved=!1,n.startMoving=!1;let v;if(a.followFinger?v=u?t.translate:-t.translate:v=-n.currentTranslate,a.cssMode)return;if(a.freeMode&&a.freeMode.enabled){t.freeMode.onTouchEnd({currentPos:v});return}const S=v>=-t.maxTranslate()&&!t.params.loop;let A=0,T=t.slidesSizesGrid[0];for(let F=0;F<f.length;F+=F<a.slidesPerGroupSkip?1:a.slidesPerGroup){const R=F<a.slidesPerGroupSkip-1?1:a.slidesPerGroup;typeof f[F+R]<"u"?(S||v>=f[F]&&v<f[F+R])&&(A=F,T=f[F+R]-f[F]):(S||v>=f[F])&&(A=F,T=f[f.length-1]-f[f.length-2])}let L=null,I=null;a.rewind&&(t.isBeginning?I=a.virtual&&a.virtual.enabled&&t.virtual?t.virtual.slides.length-1:t.slides.length-1:t.isEnd&&(L=0));const j=(v-f[A])/T,P=A<a.slidesPerGroupSkip-1?1:a.slidesPerGroup;if(y>a.longSwipesMs){if(!a.longSwipes){t.slideTo(t.activeIndex);return}t.swipeDirection==="next"&&(j>=a.longSwipesRatio?t.slideTo(a.rewind&&t.isEnd?L:A+P):t.slideTo(A)),t.swipeDirection==="prev"&&(j>1-a.longSwipesRatio?t.slideTo(A+P):I!==null&&j<0&&Math.abs(j)>a.longSwipesRatio?t.slideTo(I):t.slideTo(A))}else{if(!a.shortSwipes){t.slideTo(t.activeIndex);return}t.navigation&&(r.target===t.navigation.nextEl||r.target===t.navigation.prevEl)?r.target===t.navigation.nextEl?t.slideTo(A+P):t.slideTo(A):(t.swipeDirection==="next"&&t.slideTo(L!==null?L:A+P),t.swipeDirection==="prev"&&t.slideTo(I!==null?I:A))}}function Ov(){const e=this,{params:t,el:n}=e;if(n&&n.offsetWidth===0)return;t.breakpoints&&e.setBreakpoint();const{allowSlideNext:r,allowSlidePrev:s,snapGrid:i}=e,a=e.virtual&&e.params.virtual.enabled;e.allowSlideNext=!0,e.allowSlidePrev=!0,e.updateSize(),e.updateSlides(),e.updateSlidesClasses();const c=a&&t.loop;if((t.slidesPerView==="auto"||t.slidesPerView>1)&&e.isEnd&&!e.isBeginning&&!e.params.centeredSlides&&!c){const u=a?e.virtual.slides:e.slides;e.slideTo(u.length-1,0,!1,!0)}else e.params.loop&&!a?e.slideToLoop(e.realIndex,0,!1,!0):e.slideTo(e.activeIndex,0,!1,!0);e.autoplay&&e.autoplay.running&&e.autoplay.paused&&(clearTimeout(e.autoplay.resizeTimeout),e.autoplay.resizeTimeout=setTimeout(()=>{e.autoplay&&e.autoplay.running&&e.autoplay.paused&&e.autoplay.resume()},500)),e.allowSlidePrev=s,e.allowSlideNext=r,e.params.watchOverflow&&i!==e.snapGrid&&e.checkOverflow()}function cL(e){const t=this;t.destroyed||t.enabled&&(t.allowClick||(t.params.preventClicks&&e.preventDefault(),t.params.preventClicksPropagation&&t.animating&&(e.stopPropagation(),e.stopImmediatePropagation())))}function uL(){const e=this;if(e.destroyed)return;const{wrapperEl:t,rtlTranslate:n,enabled:r}=e;if(!r)return;e.previousTranslate=e.translate,e.isHorizontal()?e.translate=-t.scrollLeft:e.translate=-t.scrollTop,e.translate===0&&(e.translate=0),e.updateActiveIndex(),e.updateSlidesClasses();let s;const i=e.maxTranslate()-e.minTranslate();i===0?s=0:s=(e.translate-e.minTranslate())/i,s!==e.progress&&e.updateProgress(n?-e.translate:e.translate),e.emit("setTranslate",e.translate,!1)}function dL(e){const t=this;t.destroyed||(Kp(t,e.target),!(t.params.cssMode||t.params.slidesPerView!=="auto"&&!t.params.autoHeight)&&t.update())}function fL(){const e=this;e.destroyed||e.documentTouchHandlerProceeded||(e.documentTouchHandlerProceeded=!0,e.params.touchReleaseOnEdges&&(e.el.style.touchAction="auto"))}const N7=(e,t)=>{const n=Ku(),{params:r,el:s,wrapperEl:i,device:a}=e,c=!!r.nested,u=t==="on"?"addEventListener":"removeEventListener",f=t;!s||typeof s=="string"||(n[u]("touchstart",e.onDocumentTouchStart,{passive:!1,capture:c}),s[u]("touchstart",e.onTouchStart,{passive:!1}),s[u]("pointerdown",e.onTouchStart,{passive:!1}),n[u]("touchmove",e.onTouchMove,{passive:!1,capture:c}),n[u]("pointermove",e.onTouchMove,{passive:!1,capture:c}),n[u]("touchend",e.onTouchEnd,{passive:!0}),n[u]("pointerup",e.onTouchEnd,{passive:!0}),n[u]("pointercancel",e.onTouchEnd,{passive:!0}),n[u]("touchcancel",e.onTouchEnd,{passive:!0}),n[u]("pointerout",e.onTouchEnd,{passive:!0}),n[u]("pointerleave",e.onTouchEnd,{passive:!0}),n[u]("contextmenu",e.onTouchEnd,{passive:!0}),(r.preventClicks||r.preventClicksPropagation)&&s[u]("click",e.onClick,!0),r.cssMode&&i[u]("scroll",e.onScroll),r.updateOnWindowResize?e[f](a.ios||a.android?"resize orientationchange observerUpdate":"resize observerUpdate",Ov,!0):e[f]("observerUpdate",Ov,!0),s[u]("load",e.onLoad,{capture:!0}))};function hL(){const e=this,{params:t}=e;e.onTouchStart=oL.bind(e),e.onTouchMove=aL.bind(e),e.onTouchEnd=lL.bind(e),e.onDocumentTouchStart=fL.bind(e),t.cssMode&&(e.onScroll=uL.bind(e)),e.onClick=cL.bind(e),e.onLoad=dL.bind(e),N7(e,"on")}function pL(){N7(this,"off")}var mL={attachEvents:hL,detachEvents:pL};const Qv=(e,t)=>e.grid&&t.grid&&t.grid.rows>1;function gL(){const e=this,{realIndex:t,initialized:n,params:r,el:s}=e,i=r.breakpoints;if(!i||i&&Object.keys(i).length===0)return;const a=Ku(),c=r.breakpointsBase==="window"||!r.breakpointsBase?r.breakpointsBase:"container",u=["window","container"].includes(r.breakpointsBase)||!r.breakpointsBase?e.el:a.querySelector(r.breakpointsBase),f=e.getBreakpoint(i,c,u);if(!f||e.currentBreakpoint===f)return;const g=(f in i?i[f]:void 0)||e.originalParams,y=Qv(e,r),v=Qv(e,g),S=e.params.grabCursor,A=g.grabCursor,T=r.enabled;y&&!v?(s.classList.remove(`${r.containerModifierClass}grid`,`${r.containerModifierClass}grid-column`),e.emitContainerClasses()):!y&&v&&(s.classList.add(`${r.containerModifierClass}grid`),(g.grid.fill&&g.grid.fill==="column"||!g.grid.fill&&r.grid.fill==="column")&&s.classList.add(`${r.containerModifierClass}grid-column`),e.emitContainerClasses()),S&&!A?e.unsetGrabCursor():!S&&A&&e.setGrabCursor(),["navigation","pagination","scrollbar"].forEach(R=>{if(typeof g[R]>"u")return;const C=r[R]&&r[R].enabled,$=g[R]&&g[R].enabled;C&&!$&&e[R].disable(),!C&&$&&e[R].enable()});const L=g.direction&&g.direction!==r.direction,I=r.loop&&(g.slidesPerView!==r.slidesPerView||L),j=r.loop;L&&n&&e.changeDirection(),ka(e.params,g);const P=e.params.enabled,F=e.params.loop;Object.assign(e,{allowTouchMove:e.params.allowTouchMove,allowSlideNext:e.params.allowSlideNext,allowSlidePrev:e.params.allowSlidePrev}),T&&!P?e.disable():!T&&P&&e.enable(),e.currentBreakpoint=f,e.emit("_beforeBreakpoint",g),n&&(I?(e.loopDestroy(),e.loopCreate(t),e.updateSlides()):!j&&F?(e.loopCreate(t),e.updateSlides()):j&&!F&&e.loopDestroy()),e.emit("breakpoint",g)}function xL(e,t="window",n){if(!e||t==="container"&&!n)return;let r=!1;const s=$o(),i=t==="window"?s.innerHeight:n.clientHeight,a=Object.keys(e).map(c=>{if(typeof c=="string"&&c.indexOf("@")===0){const u=parseFloat(c.substr(1));return{value:i*u,point:c}}return{value:c,point:c}});a.sort((c,u)=>parseInt(c.value,10)-parseInt(u.value,10));for(let c=0;c<a.length;c+=1){const{point:u,value:f}=a[c];t==="window"?s.matchMedia(`(min-width: ${f}px)`).matches&&(r=u):f<=n.clientWidth&&(r=u)}return r||"max"}var bL={setBreakpoint:gL,getBreakpoint:xL};function yL(e,t){const n=[];return e.forEach(r=>{typeof r=="object"?Object.keys(r).forEach(s=>{r[s]&&n.push(t+s)}):typeof r=="string"&&n.push(t+r)}),n}function vL(){const e=this,{classNames:t,params:n,rtl:r,el:s,device:i}=e,a=yL(["initialized",n.direction,{"free-mode":e.params.freeMode&&n.freeMode.enabled},{autoheight:n.autoHeight},{rtl:r},{grid:n.grid&&n.grid.rows>1},{"grid-column":n.grid&&n.grid.rows>1&&n.grid.fill==="column"},{android:i.android},{ios:i.ios},{"css-mode":n.cssMode},{centered:n.cssMode&&n.centeredSlides},{"watch-progress":n.watchSlidesProgress}],n.containerModifierClass);t.push(...a),s.classList.add(...t),e.emitContainerClasses()}function wL(){const e=this,{el:t,classNames:n}=e;!t||typeof t=="string"||(t.classList.remove(...n),e.emitContainerClasses())}var SL={addClasses:vL,removeClasses:wL};function AL(){const e=this,{isLocked:t,params:n}=e,{slidesOffsetBefore:r}=n;if(r){const s=e.slides.length-1,i=e.slidesGrid[s]+e.slidesSizesGrid[s]+r*2;e.isLocked=e.size>i}else e.isLocked=e.snapGrid.length===1;n.allowSlideNext===!0&&(e.allowSlideNext=!e.isLocked),n.allowSlidePrev===!0&&(e.allowSlidePrev=!e.isLocked),t&&t!==e.isLocked&&(e.isEnd=!1),t!==e.isLocked&&e.emit(e.isLocked?"lock":"unlock")}var TL={checkOverflow:AL},bb={init:!0,direction:"horizontal",oneWayMovement:!1,swiperElementNodeName:"SWIPER-CONTAINER",touchEventsTarget:"wrapper",initialSlide:0,speed:300,cssMode:!1,updateOnWindowResize:!0,resizeObserver:!0,nested:!1,createElements:!1,eventsPrefix:"swiper",enabled:!0,focusableElements:"input, select, option, textarea, button, video, label",width:null,height:null,preventInteractionOnTransition:!1,userAgent:null,url:null,edgeSwipeDetection:!1,edgeSwipeThreshold:20,autoHeight:!1,setWrapperSize:!1,virtualTranslate:!1,effect:"slide",breakpoints:void 0,breakpointsBase:"window",spaceBetween:0,slidesPerView:1,slidesPerGroup:1,slidesPerGroupSkip:0,slidesPerGroupAuto:!1,centeredSlides:!1,centeredSlidesBounds:!1,slidesOffsetBefore:0,slidesOffsetAfter:0,normalizeSlideIndex:!0,centerInsufficientSlides:!1,snapToSlideEdge:!1,watchOverflow:!0,roundLengths:!1,touchRatio:1,touchAngle:45,simulateTouch:!0,shortSwipes:!0,longSwipes:!0,longSwipesRatio:.5,longSwipesMs:300,followFinger:!0,allowTouchMove:!0,threshold:5,touchMoveStopPropagation:!1,touchStartPreventDefault:!0,touchStartForcePreventDefault:!1,touchReleaseOnEdges:!1,uniqueNavElements:!0,resistance:!0,resistanceRatio:.85,watchSlidesProgress:!1,grabCursor:!1,preventClicks:!0,preventClicksPropagation:!0,slideToClickedSlide:!1,loop:!1,loopAddBlankSlides:!0,loopAdditionalSlides:0,loopPreventsSliding:!0,rewind:!1,allowSlidePrev:!0,allowSlideNext:!0,swipeHandler:null,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:null,passiveListeners:!0,maxBackfaceHiddenSlides:10,containerModifierClass:"swiper-",slideClass:"swiper-slide",slideBlankClass:"swiper-slide-blank",slideActiveClass:"swiper-slide-active",slideVisibleClass:"swiper-slide-visible",slideFullyVisibleClass:"swiper-slide-fully-visible",slideNextClass:"swiper-slide-next",slidePrevClass:"swiper-slide-prev",wrapperClass:"swiper-wrapper",lazyPreloaderClass:"swiper-lazy-preloader",lazyPreloadPrevNext:0,runCallbacksOnInit:!0,_emitClasses:!1};function CL(e,t){return function(r={}){const s=Object.keys(r)[0],i=r[s];if(typeof i!="object"||i===null){ka(t,r);return}if(e[s]===!0&&(e[s]={enabled:!0}),s==="navigation"&&e[s]&&e[s].enabled&&!e[s].prevEl&&!e[s].nextEl&&(e[s].auto=!0),["pagination","scrollbar"].indexOf(s)>=0&&e[s]&&e[s].enabled&&!e[s].el&&(e[s].auto=!0),!(s in e&&"enabled"in i)){ka(t,r);return}typeof e[s]=="object"&&!("enabled"in e[s])&&(e[s].enabled=!0),e[s]||(e[s]={enabled:!1}),ka(t,r)}}const _1={eventsEmitter:S_,update:M_,translate:O_,transition:U_,slide:X_,loop:tL,grabCursor:sL,events:mL,breakpoints:bL,checkOverflow:TL,classes:SL},L1={};let X2=class mc{constructor(...t){let n,r;t.length===1&&t[0].constructor&&Object.prototype.toString.call(t[0]).slice(8,-1)==="Object"?r=t[0]:[n,r]=t,r||(r={}),r=ka({},r),n&&!r.el&&(r.el=n);const s=Ku();if(r.el&&typeof r.el=="string"&&s.querySelectorAll(r.el).length>1){const u=[];return s.querySelectorAll(r.el).forEach(f=>{const p=ka({},r,{el:f});u.push(new mc(p))}),u}const i=this;i.__swiper__=!0,i.support=L7(),i.device=E7({userAgent:r.userAgent}),i.browser=I7(),i.eventsListeners={},i.eventsAnyListeners=[],i.modules=[...i.__modules__],r.modules&&Array.isArray(r.modules)&&r.modules.forEach(u=>{typeof u=="function"&&i.modules.indexOf(u)<0&&i.modules.push(u)});const a={};i.modules.forEach(u=>{u({params:r,swiper:i,extendParams:CL(r,a),on:i.on.bind(i),once:i.once.bind(i),off:i.off.bind(i),emit:i.emit.bind(i)})});const c=ka({},bb,a);return i.params=ka({},c,L1,r),i.originalParams=ka({},i.params),i.passedParams=ka({},r),i.params&&i.params.on&&Object.keys(i.params.on).forEach(u=>{i.on(u,i.params.on[u])}),i.params&&i.params.onAny&&i.onAny(i.params.onAny),Object.assign(i,{enabled:i.params.enabled,el:n,classNames:[],slides:[],slidesGrid:[],snapGrid:[],slidesSizesGrid:[],isHorizontal(){return i.params.direction==="horizontal"},isVertical(){return i.params.direction==="vertical"},activeIndex:0,realIndex:0,isBeginning:!0,isEnd:!1,translate:0,previousTranslate:0,progress:0,velocity:0,animating:!1,cssOverflowAdjustment(){return Math.trunc(this.translate/2**23)*2**23},allowSlideNext:i.params.allowSlideNext,allowSlidePrev:i.params.allowSlidePrev,touchEventsData:{isTouched:void 0,isMoved:void 0,allowTouchCallbacks:void 0,touchStartTime:void 0,isScrolling:void 0,currentTranslate:void 0,startTranslate:void 0,allowThresholdMove:void 0,focusableElements:i.params.focusableElements,lastClickTime:0,clickTimeout:void 0,velocities:[],allowMomentumBounce:void 0,startMoving:void 0,pointerId:null,touchId:null},allowClick:!0,allowTouchMove:i.params.allowTouchMove,touches:{startX:0,startY:0,currentX:0,currentY:0,diff:0},imagesToLoad:[],imagesLoaded:0}),i.emit("_swiper"),i.params.init&&i.init(),i}getDirectionLabel(t){return this.isHorizontal()?t:{width:"height","margin-top":"margin-left","margin-bottom ":"margin-right","margin-left":"margin-top","margin-right":"margin-bottom","padding-left":"padding-top","padding-right":"padding-bottom",marginRight:"marginBottom"}[t]}getSlideIndex(t){const{slidesEl:n,params:r}=this,s=bc(n,`.${r.slideClass}, swiper-slide`),i=Dv(s[0]);return Dv(t)-i}getSlideIndexByData(t){return this.getSlideIndex(this.slides.find(n=>n.getAttribute("data-swiper-slide-index")*1===t))}getSlideIndexWhenGrid(t){return this.grid&&this.params.grid&&this.params.grid.rows>1&&(this.params.grid.fill==="column"?t=Math.floor(t/this.params.grid.rows):this.params.grid.fill==="row"&&(t=t%Math.ceil(this.slides.length/this.params.grid.rows))),t}recalcSlides(){const t=this,{slidesEl:n,params:r}=t;t.slides=bc(n,`.${r.slideClass}, swiper-slide`)}enable(){const t=this;t.enabled||(t.enabled=!0,t.params.grabCursor&&t.setGrabCursor(),t.emit("enable"))}disable(){const t=this;t.enabled&&(t.enabled=!1,t.params.grabCursor&&t.unsetGrabCursor(),t.emit("disable"))}setProgress(t,n){const r=this;t=Math.min(Math.max(t,0),1);const s=r.minTranslate(),a=(r.maxTranslate()-s)*t+s;r.translateTo(a,typeof n>"u"?0:n),r.updateActiveIndex(),r.updateSlidesClasses()}emitContainerClasses(){const t=this;if(!t.params._emitClasses||!t.el)return;const n=t.el.className.split(" ").filter(r=>r.indexOf("swiper")===0||r.indexOf(t.params.containerModifierClass)===0);t.emit("_containerClasses",n.join(" "))}getSlideClasses(t){const n=this;return n.destroyed?"":t.className.split(" ").filter(r=>r.indexOf("swiper-slide")===0||r.indexOf(n.params.slideClass)===0).join(" ")}emitSlidesClasses(){const t=this;if(!t.params._emitClasses||!t.el)return;const n=[];t.slides.forEach(r=>{const s=t.getSlideClasses(r);n.push({slideEl:r,classNames:s}),t.emit("_slideClass",r,s)}),t.emit("_slideClasses",n)}slidesPerViewDynamic(t="current",n=!1){const r=this,{params:s,slides:i,slidesGrid:a,slidesSizesGrid:c,size:u,activeIndex:f}=r;let p=1;if(typeof s.slidesPerView=="number")return s.slidesPerView;if(s.centeredSlides){let g=i[f]?Math.ceil(i[f].swiperSlideSize):0,y;for(let v=f+1;v<i.length;v+=1)i[v]&&!y&&(g+=Math.ceil(i[v].swiperSlideSize),p+=1,g>u&&(y=!0));for(let v=f-1;v>=0;v-=1)i[v]&&!y&&(g+=i[v].swiperSlideSize,p+=1,g>u&&(y=!0))}else if(t==="current")for(let g=f+1;g<i.length;g+=1)(n?a[g]+c[g]-a[f]<u:a[g]-a[f]<u)&&(p+=1);else for(let g=f-1;g>=0;g-=1)a[f]-a[g]<u&&(p+=1);return p}update(){const t=this;if(!t||t.destroyed)return;const{snapGrid:n,params:r}=t;r.breakpoints&&t.setBreakpoint(),[...t.el.querySelectorAll('[loading="lazy"]')].forEach(a=>{a.complete&&Kp(t,a)}),t.updateSize(),t.updateSlides(),t.updateProgress(),t.updateSlidesClasses();function s(){const a=t.rtlTranslate?t.translate*-1:t.translate,c=Math.min(Math.max(a,t.maxTranslate()),t.minTranslate());t.setTranslate(c),t.updateActiveIndex(),t.updateSlidesClasses()}let i;if(r.freeMode&&r.freeMode.enabled&&!r.cssMode)s(),r.autoHeight&&t.updateAutoHeight();else{if((r.slidesPerView==="auto"||r.slidesPerView>1)&&t.isEnd&&!r.centeredSlides){const a=t.virtual&&r.virtual.enabled?t.virtual.slides:t.slides;i=t.slideTo(a.length-1,0,!1,!0)}else i=t.slideTo(t.activeIndex,0,!1,!0);i||s()}r.watchOverflow&&n!==t.snapGrid&&t.checkOverflow(),t.emit("update")}changeDirection(t,n=!0){const r=this,s=r.params.direction;return t||(t=s==="horizontal"?"vertical":"horizontal"),t===s||t!=="horizontal"&&t!=="vertical"||(r.el.classList.remove(`${r.params.containerModifierClass}${s}`),r.el.classList.add(`${r.params.containerModifierClass}${t}`),r.emitContainerClasses(),r.params.direction=t,r.slides.forEach(i=>{t==="vertical"?i.style.width="":i.style.height=""}),r.emit("changeDirection"),n&&r.update()),r}changeLanguageDirection(t){const n=this;n.rtl&&t==="rtl"||!n.rtl&&t==="ltr"||(n.rtl=t==="rtl",n.rtlTranslate=n.params.direction==="horizontal"&&n.rtl,n.rtl?(n.el.classList.add(`${n.params.containerModifierClass}rtl`),n.el.dir="rtl"):(n.el.classList.remove(`${n.params.containerModifierClass}rtl`),n.el.dir="ltr"),n.update())}mount(t){const n=this;if(n.mounted)return!0;let r=t||n.params.el;if(typeof r=="string"&&(r=document.querySelector(r)),!r)return!1;r.swiper=n,r.parentNode&&r.parentNode.host&&r.parentNode.host.nodeName===n.params.swiperElementNodeName.toUpperCase()&&(n.isElement=!0);const s=()=>`.${(n.params.wrapperClass||"").trim().split(" ").join(".")}`;let a=r&&r.shadowRoot&&r.shadowRoot.querySelector?r.shadowRoot.querySelector(s()):bc(r,s())[0];return!a&&n.params.createElements&&(a=gb("div",n.params.wrapperClass),r.append(a),bc(r,`.${n.params.slideClass}`).forEach(c=>{a.append(c)})),Object.assign(n,{el:r,wrapperEl:a,slidesEl:n.isElement&&!r.parentNode.host.slideSlots?r.parentNode.host:a,hostEl:n.isElement?r.parentNode.host:r,mounted:!0,rtl:r.dir.toLowerCase()==="rtl"||qc(r,"direction")==="rtl",rtlTranslate:n.params.direction==="horizontal"&&(r.dir.toLowerCase()==="rtl"||qc(r,"direction")==="rtl"),wrongRTL:qc(a,"display")==="-webkit-box"}),!0}init(t){const n=this;if(n.initialized||n.mount(t)===!1)return n;n.emit("beforeInit"),n.params.breakpoints&&n.setBreakpoint(),n.addClasses(),n.updateSize(),n.updateSlides(),n.params.watchOverflow&&n.checkOverflow(),n.params.grabCursor&&n.enabled&&n.setGrabCursor(),n.params.loop&&n.virtual&&n.params.virtual.enabled?n.slideTo(n.params.initialSlide+n.virtual.slidesBefore,0,n.params.runCallbacksOnInit,!1,!0):n.slideTo(n.params.initialSlide,0,n.params.runCallbacksOnInit,!1,!0),n.params.loop&&n.loopCreate(void 0,!0),n.attachEvents();const s=[...n.el.querySelectorAll('[loading="lazy"]')];return n.isElement&&s.push(...n.hostEl.querySelectorAll('[loading="lazy"]')),s.forEach(i=>{i.complete?Kp(n,i):i.addEventListener("load",a=>{Kp(n,a.target)})}),xb(n),n.initialized=!0,xb(n),n.emit("init"),n.emit("afterInit"),n}destroy(t=!0,n=!0){const r=this,{params:s,el:i,wrapperEl:a,slides:c}=r;return typeof r.params>"u"||r.destroyed||(r.emit("beforeDestroy"),r.initialized=!1,r.detachEvents(),s.loop&&r.loopDestroy(),n&&(r.removeClasses(),i&&typeof i!="string"&&i.removeAttribute("style"),a&&a.removeAttribute("style"),c&&c.length&&c.forEach(u=>{u.classList.remove(s.slideVisibleClass,s.slideFullyVisibleClass,s.slideActiveClass,s.slideNextClass,s.slidePrevClass),u.removeAttribute("style"),u.removeAttribute("data-swiper-slide-index")})),r.emit("destroy"),Object.keys(r.eventsListeners).forEach(u=>{r.off(u)}),t!==!1&&(r.el&&typeof r.el!="string"&&(r.el.swiper=null),l_(r)),r.destroyed=!0),null}static extendDefaults(t){ka(L1,t)}static get extendedDefaults(){return L1}static get defaults(){return bb}static installModule(t){mc.prototype.__modules__||(mc.prototype.__modules__=[]);const n=mc.prototype.__modules__;typeof t=="function"&&n.indexOf(t)<0&&n.push(t)}static use(t){return Array.isArray(t)?(t.forEach(n=>mc.installModule(n)),mc):(mc.installModule(t),mc)}};Object.keys(_1).forEach(e=>{Object.keys(_1[e]).forEach(t=>{X2.prototype[t]=_1[e][t]})});X2.use([v_,w_]);const M7=["eventsPrefix","injectStyles","injectStylesUrls","modules","init","_direction","oneWayMovement","swiperElementNodeName","touchEventsTarget","initialSlide","_speed","cssMode","updateOnWindowResize","resizeObserver","nested","focusableElements","_enabled","_width","_height","preventInteractionOnTransition","userAgent","url","_edgeSwipeDetection","_edgeSwipeThreshold","_freeMode","_autoHeight","setWrapperSize","virtualTranslate","_effect","breakpoints","breakpointsBase","_spaceBetween","_slidesPerView","maxBackfaceHiddenSlides","_grid","_slidesPerGroup","_slidesPerGroupSkip","_slidesPerGroupAuto","_centeredSlides","_centeredSlidesBounds","_slidesOffsetBefore","_slidesOffsetAfter","normalizeSlideIndex","_centerInsufficientSlides","_snapToSlideEdge","_watchOverflow","roundLengths","touchRatio","touchAngle","simulateTouch","_shortSwipes","_longSwipes","longSwipesRatio","longSwipesMs","_followFinger","allowTouchMove","_threshold","touchMoveStopPropagation","touchStartPreventDefault","touchStartForcePreventDefault","touchReleaseOnEdges","uniqueNavElements","_resistance","_resistanceRatio","_watchSlidesProgress","_grabCursor","preventClicks","preventClicksPropagation","_slideToClickedSlide","_loop","loopAdditionalSlides","loopAddBlankSlides","loopPreventsSliding","_rewind","_allowSlidePrev","_allowSlideNext","_swipeHandler","_noSwiping","noSwipingClass","noSwipingSelector","passiveListeners","containerModifierClass","slideClass","slideActiveClass","slideVisibleClass","slideFullyVisibleClass","slideNextClass","slidePrevClass","slideBlankClass","wrapperClass","lazyPreloaderClass","lazyPreloadPrevNext","runCallbacksOnInit","observer","observeParents","observeSlideChildren","a11y","_autoplay","_controller","coverflowEffect","cubeEffect","fadeEffect","flipEffect","creativeEffect","cardsEffect","hashNavigation","history","keyboard","mousewheel","_navigation","_pagination","parallax","_scrollbar","_thumbs","virtual","zoom","control"];function zu(e){return typeof e=="object"&&e!==null&&e.constructor&&Object.prototype.toString.call(e).slice(8,-1)==="Object"&&!e.__swiper__}function Kd(e,t){const n=["__proto__","constructor","prototype"];Object.keys(t).filter(r=>n.indexOf(r)<0).forEach(r=>{typeof e[r]>"u"?e[r]=t[r]:zu(t[r])&&zu(e[r])&&Object.keys(t[r]).length>0?t[r].__swiper__?e[r]=t[r]:Kd(e[r],t[r]):e[r]=t[r]})}function D7(e={}){return e.navigation&&typeof e.navigation.nextEl>"u"&&typeof e.navigation.prevEl>"u"}function j7(e={}){return e.pagination&&typeof e.pagination.el>"u"}function P7(e={}){return e.scrollbar&&typeof e.scrollbar.el>"u"}function B7(e=""){const t=e.split(" ").map(r=>r.trim()).filter(r=>!!r),n=[];return t.forEach(r=>{n.indexOf(r)<0&&n.push(r)}),n.join(" ")}function kL(e=""){return e?e.includes("swiper-wrapper")?e:`swiper-wrapper ${e}`:"swiper-wrapper"}function _L({swiper:e,slides:t,passedParams:n,changedParams:r,nextEl:s,prevEl:i,scrollbarEl:a,paginationEl:c}){const u=r.filter($=>$!=="children"&&$!=="direction"&&$!=="wrapperClass"),{params:f,pagination:p,navigation:g,scrollbar:y,virtual:v,thumbs:S}=e;let A,T,L,I,j,P,F,R;r.includes("thumbs")&&n.thumbs&&n.thumbs.swiper&&!n.thumbs.swiper.destroyed&&f.thumbs&&(!f.thumbs.swiper||f.thumbs.swiper.destroyed)&&(A=!0),r.includes("controller")&&n.controller&&n.controller.control&&f.controller&&!f.controller.control&&(T=!0),r.includes("pagination")&&n.pagination&&(n.pagination.el||c)&&(f.pagination||f.pagination===!1)&&p&&!p.el&&(L=!0),r.includes("scrollbar")&&n.scrollbar&&(n.scrollbar.el||a)&&(f.scrollbar||f.scrollbar===!1)&&y&&!y.el&&(I=!0),r.includes("navigation")&&n.navigation&&(n.navigation.prevEl||i)&&(n.navigation.nextEl||s)&&(f.navigation||f.navigation===!1)&&g&&!g.prevEl&&!g.nextEl&&(j=!0);const C=$=>{e[$]&&(e[$].destroy(),$==="navigation"?(e.isElement&&(e[$].prevEl.remove(),e[$].nextEl.remove()),f[$].prevEl=void 0,f[$].nextEl=void 0,e[$].prevEl=void 0,e[$].nextEl=void 0):(e.isElement&&e[$].el.remove(),f[$].el=void 0,e[$].el=void 0))};r.includes("loop")&&e.isElement&&(f.loop&&!n.loop?P=!0:!f.loop&&n.loop?F=!0:R=!0),u.forEach($=>{if(zu(f[$])&&zu(n[$]))Object.assign(f[$],n[$]),($==="navigation"||$==="pagination"||$==="scrollbar")&&"enabled"in n[$]&&!n[$].enabled&&C($);else{const H=n[$];(H===!0||H===!1)&&($==="navigation"||$==="pagination"||$==="scrollbar")?H===!1&&C($):f[$]=n[$]}}),u.includes("controller")&&!T&&e.controller&&e.controller.control&&f.controller&&f.controller.control&&(e.controller.control=f.controller.control),r.includes("children")&&t&&v&&f.virtual.enabled?(v.slides=t,v.update(!0)):r.includes("virtual")&&v&&f.virtual.enabled&&(t&&(v.slides=t),v.update(!0)),r.includes("children")&&t&&f.loop&&(R=!0),A&&S.init()&&S.update(!0),T&&(e.controller.control=f.controller.control),L&&(e.isElement&&(!c||typeof c=="string")&&(c=document.createElement("div"),c.classList.add("swiper-pagination"),c.part.add("pagination"),e.el.appendChild(c)),c&&(f.pagination.el=c),p.init(),p.render(),p.update()),I&&(e.isElement&&(!a||typeof a=="string")&&(a=document.createElement("div"),a.classList.add("swiper-scrollbar"),a.part.add("scrollbar"),e.el.appendChild(a)),a&&(f.scrollbar.el=a),y.init(),y.updateSize(),y.setTranslate()),j&&(e.isElement&&((!s||typeof s=="string")&&(s=document.createElement("div"),s.classList.add("swiper-button-next"),Pv(s,e.navigation.arrowSvg),s.part.add("button-next"),e.el.appendChild(s)),(!i||typeof i=="string")&&(i=document.createElement("div"),i.classList.add("swiper-button-prev"),Pv(i,e.navigation.arrowSvg),i.part.add("button-prev"),e.el.appendChild(i))),s&&(f.navigation.nextEl=s),i&&(f.navigation.prevEl=i),g.init(),g.update()),r.includes("allowSlideNext")&&(e.allowSlideNext=n.allowSlideNext),r.includes("allowSlidePrev")&&(e.allowSlidePrev=n.allowSlidePrev),r.includes("direction")&&e.changeDirection(n.direction,!1),(P||R)&&e.loopDestroy(),(F||R)&&e.loopCreate(),e.update()}function LL(e={},t=!0){const n={on:{}},r={},s={};Kd(n,bb),n._emitClasses=!0,n.init=!1;const i={},a=M7.map(u=>u.replace(/_/,"")),c=Object.assign({},e);return Object.keys(c).forEach(u=>{typeof e[u]>"u"||(a.indexOf(u)>=0?zu(e[u])?(n[u]={},s[u]={},Kd(n[u],e[u]),Kd(s[u],e[u])):(n[u]=e[u],s[u]=e[u]):u.search(/on[A-Z]/)===0&&typeof e[u]=="function"?t?r[`${u[2].toLowerCase()}${u.substr(3)}`]=e[u]:n.on[`${u[2].toLowerCase()}${u.substr(3)}`]=e[u]:i[u]=e[u])}),["navigation","pagination","scrollbar"].forEach(u=>{n[u]===!0&&(n[u]={}),n[u]===!1&&delete n[u]}),{params:n,passedParams:s,rest:i,events:r}}function EL({el:e,nextEl:t,prevEl:n,paginationEl:r,scrollbarEl:s,swiper:i},a){D7(a)&&t&&n&&(i.params.navigation.nextEl=t,i.originalParams.navigation.nextEl=t,i.params.navigation.prevEl=n,i.originalParams.navigation.prevEl=n),j7(a)&&r&&(i.params.pagination.el=r,i.originalParams.pagination.el=r),P7(a)&&s&&(i.params.scrollbar.el=s,i.originalParams.scrollbar.el=s),i.init(e)}function IL(e,t,n,r,s){const i=[];if(!t)return i;const a=u=>{i.indexOf(u)<0&&i.push(u)};if(n&&r){const u=r.map(s),f=n.map(s);u.join("")!==f.join("")&&a("children"),r.length!==n.length&&a("children")}return M7.filter(u=>u[0]==="_").map(u=>u.replace(/_/,"")).forEach(u=>{if(u in e&&u in t)if(zu(e[u])&&zu(t[u])){const f=Object.keys(e[u]),p=Object.keys(t[u]);f.length!==p.length?a(u):(f.forEach(g=>{e[u][g]!==t[u][g]&&a(u)}),p.forEach(g=>{e[u][g]!==t[u][g]&&a(u)}))}else e[u]!==t[u]&&a(u)}),i}const RL=e=>{!e||e.destroyed||!e.params.virtual||e.params.virtual&&!e.params.virtual.enabled||(e.updateSlides(),e.updateProgress(),e.updateSlidesClasses(),e.emit("_virtualUpdated"),e.parallax&&e.params.parallax&&e.params.parallax.enabled&&e.parallax.setTranslate())};function Am(){return Am=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Am.apply(this,arguments)}function F7(e){return e.type&&e.type.displayName&&e.type.displayName.includes("SwiperSlide")}function O7(e){const t=[];return D.Children.toArray(e).forEach(n=>{F7(n)?t.push(n):n.props&&n.props.children&&O7(n.props.children).forEach(r=>t.push(r))}),t}function NL(e){const t=[],n={"container-start":[],"container-end":[],"wrapper-start":[],"wrapper-end":[]};return D.Children.toArray(e).forEach(r=>{if(F7(r))t.push(r);else if(r.props&&r.props.slot&&n[r.props.slot])n[r.props.slot].push(r);else if(r.props&&r.props.children){const s=O7(r.props.children);s.length>0?s.forEach(i=>t.push(i)):n["container-end"].push(r)}else n["container-end"].push(r)}),{slides:t,slots:n}}function ML(e,t,n){if(!n)return null;const r=p=>{let g=p;return p<0?g=t.length+p:g>=t.length&&(g=g-t.length),g},s=e.isHorizontal()?{[e.rtlTranslate?"right":"left"]:`${n.offset}px`}:{top:`${n.offset}px`},{from:i,to:a}=n,c=e.params.loop?-t.length:0,u=e.params.loop?t.length*2:t.length,f=[];for(let p=c;p<u;p+=1)p>=i&&p<=a&&f.push(t[r(p)]);return f.map((p,g)=>D.cloneElement(p,{swiper:e,style:s,key:p.props.virtualIndex||p.key||`slide-${g}`}))}function Rf(e,t){return typeof window>"u"?b.useEffect(e,t):b.useLayoutEffect(e,t)}const $v=b.createContext(null),DL=b.createContext(null),uh=b.forwardRef(({className:e,tag:t="div",wrapperTag:n="div",children:r,onSwiper:s,...i}={},a)=>{let c=!1;const[u,f]=b.useState("swiper"),[p,g]=b.useState(null),[y,v]=b.useState(!1),S=b.useRef(!1),A=b.useRef(null),T=b.useRef(null),L=b.useRef(null),I=b.useRef(null),j=b.useRef(null),P=b.useRef(null),F=b.useRef(null),R=b.useRef(null),{params:C,passedParams:$,rest:H,events:Y}=LL(i),{slides:V,slots:fe}=NL(r),X=()=>{v(!y)};Object.assign(C.on,{_containerClasses(q,z){f(z)}});const ve=()=>{Object.assign(C.on,Y),c=!0;const q={...C};if(delete q.wrapperClass,T.current=new X2(q),T.current.virtual&&T.current.params.virtual.enabled){T.current.virtual.slides=V;const z={cache:!1,slides:V,renderExternal:g,renderExternalUpdate:!1};Kd(T.current.params.virtual,z),Kd(T.current.originalParams.virtual,z)}};A.current||ve(),T.current&&T.current.on("_beforeBreakpoint",X);const we=()=>{c||!Y||!T.current||Object.keys(Y).forEach(q=>{T.current.on(q,Y[q])})},ie=()=>{!Y||!T.current||Object.keys(Y).forEach(q=>{T.current.off(q,Y[q])})};b.useEffect(()=>()=>{T.current&&T.current.off("_beforeBreakpoint",X)}),b.useEffect(()=>{!S.current&&T.current&&(T.current.emitSlidesClasses(),S.current=!0)}),Rf(()=>{if(a&&(a.current=A.current),!!A.current)return T.current.destroyed&&ve(),EL({el:A.current,nextEl:j.current,prevEl:P.current,paginationEl:F.current,scrollbarEl:R.current,swiper:T.current},C),s&&!T.current.destroyed&&s(T.current),()=>{T.current&&!T.current.destroyed&&T.current.destroy(!0,!1)}},[]),Rf(()=>{we();const q=IL($,L.current,V,I.current,z=>z.key);return L.current=$,I.current=V,q.length&&T.current&&!T.current.destroyed&&_L({swiper:T.current,slides:V,passedParams:$,changedParams:q,nextEl:j.current,prevEl:P.current,scrollbarEl:R.current,paginationEl:F.current}),()=>{ie()}}),Rf(()=>{RL(T.current)},[p]);function ae(){return C.virtual?ML(T.current,V,p):V.map((q,z)=>D.cloneElement(q,{swiper:T.current,swiperSlideIndex:z}))}return D.createElement(t,Am({ref:A,className:B7(`${u}${e?` ${e}`:""}`)},H),D.createElement(DL.Provider,{value:T.current},fe["container-start"],D.createElement(n,{className:kL(C.wrapperClass)},fe["wrapper-start"],ae(),fe["wrapper-end"]),D7(C)&&D.createElement(D.Fragment,null,D.createElement("div",{ref:P,className:"swiper-button-prev"}),D.createElement("div",{ref:j,className:"swiper-button-next"})),P7(C)&&D.createElement("div",{ref:R,className:"swiper-scrollbar"}),j7(C)&&D.createElement("div",{ref:F,className:"swiper-pagination"}),fe["container-end"]))});uh.displayName="Swiper";const Gu=b.forwardRef(({tag:e="div",children:t,className:n="",swiper:r,zoom:s,lazy:i,virtualIndex:a,swiperSlideIndex:c,...u}={},f)=>{const p=b.useRef(null),[g,y]=b.useState("swiper-slide"),[v,S]=b.useState(!1);function A(j,P,F){P===p.current&&y(F)}Rf(()=>{if(typeof c<"u"&&(p.current.swiperSlideIndex=c),f&&(f.current=p.current),!(!p.current||!r)){if(r.destroyed){g!=="swiper-slide"&&y("swiper-slide");return}return r.on("_slideClass",A),()=>{r&&r.off("_slideClass",A)}}}),Rf(()=>{r&&p.current&&!r.destroyed&&y(r.getSlideClasses(p.current))},[r]);const T={isActive:g.indexOf("swiper-slide-active")>=0,isVisible:g.indexOf("swiper-slide-visible")>=0,isFullyVisible:g.indexOf("swiper-slide-fully-visible")>=0,isPrev:g.indexOf("swiper-slide-prev")>=0,isNext:g.indexOf("swiper-slide-next")>=0},L=()=>typeof t=="function"?t(T):t,I=()=>{S(!0)};return D.createElement(e,Am({ref:p,className:B7(`${g}${n?` ${n}`:""}`),"data-swiper-slide-index":a,onLoad:I},u),s&&D.createElement($v.Provider,{value:T},D.createElement("div",{className:"swiper-zoom-container","data-swiper-zoom":typeof s=="number"?s:void 0},L(),i&&!v&&D.createElement("div",{className:"swiper-lazy-preloader",ref:j=>{j&&(j.lazyPreloaderManaged=!0)}}))),!s&&D.createElement($v.Provider,{value:T},L(),i&&!v&&D.createElement("div",{className:"swiper-lazy-preloader",ref:j=>{j&&(j.lazyPreloaderManaged=!0)}})))});Gu.displayName="SwiperSlide";const ro=[];for(let e=0;e<256;++e)ro.push((e+256).toString(16).slice(1));function jL(e,t=0){return(ro[e[t+0]]+ro[e[t+1]]+ro[e[t+2]]+ro[e[t+3]]+"-"+ro[e[t+4]]+ro[e[t+5]]+"-"+ro[e[t+6]]+ro[e[t+7]]+"-"+ro[e[t+8]]+ro[e[t+9]]+"-"+ro[e[t+10]]+ro[e[t+11]]+ro[e[t+12]]+ro[e[t+13]]+ro[e[t+14]]+ro[e[t+15]]).toLowerCase()}let E1;const PL=new Uint8Array(16);function BL(){if(!E1){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");E1=crypto.getRandomValues.bind(crypto)}return E1(PL)}const FL=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Hv={randomUUID:FL};function OL(e,t,n){e=e||{};const r=e.random??e.rng?.()??BL();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,jL(r)}function QL(e,t,n){return Hv.randomUUID&&!e?Hv.randomUUID():OL(e)}const $L={},Uv=e=>{let t;const n=new Set,r=(p,g)=>{const y=typeof p=="function"?p(t):p;if(!Object.is(y,t)){const v=t;t=g??(typeof y!="object"||y===null)?y:Object.assign({},t,y),n.forEach(S=>S(t,v))}},s=()=>t,u={setState:r,getState:s,getInitialState:()=>f,subscribe:p=>(n.add(p),()=>n.delete(p)),destroy:()=>{($L?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},f=t=e(r,s,u);return u},HL=e=>e?Uv(e):Uv;var I1={exports:{}},R1={},N1={exports:{}},M1={};var zv;function UL(){if(zv)return M1;zv=1;var e=ug();function t(g,y){return g===y&&(g!==0||1/g===1/y)||g!==g&&y!==y}var n=typeof Object.is=="function"?Object.is:t,r=e.useState,s=e.useEffect,i=e.useLayoutEffect,a=e.useDebugValue;function c(g,y){var v=y(),S=r({inst:{value:v,getSnapshot:y}}),A=S[0].inst,T=S[1];return i(function(){A.value=v,A.getSnapshot=y,u(A)&&T({inst:A})},[g,v,y]),s(function(){return u(A)&&T({inst:A}),g(function(){u(A)&&T({inst:A})})},[g]),a(v),v}function u(g){var y=g.getSnapshot;g=g.value;try{var v=y();return!n(g,v)}catch{return!0}}function f(g,y){return y()}var p=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?f:c;return M1.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:p,M1}var Gv;function zL(){return Gv||(Gv=1,N1.exports=UL()),N1.exports}var Wv;function GL(){if(Wv)return R1;Wv=1;var e=ug(),t=zL();function n(f,p){return f===p&&(f!==0||1/f===1/p)||f!==f&&p!==p}var r=typeof Object.is=="function"?Object.is:n,s=t.useSyncExternalStore,i=e.useRef,a=e.useEffect,c=e.useMemo,u=e.useDebugValue;return R1.useSyncExternalStoreWithSelector=function(f,p,g,y,v){var S=i(null);if(S.current===null){var A={hasValue:!1,value:null};S.current=A}else A=S.current;S=c(function(){function L(R){if(!I){if(I=!0,j=R,R=y(R),v!==void 0&&A.hasValue){var C=A.value;if(v(C,R))return P=C}return P=R}if(C=P,r(j,R))return C;var $=y(R);return v!==void 0&&v(C,$)?(j=R,C):(j=R,P=$)}var I=!1,j,P,F=g===void 0?null:g;return[function(){return L(p())},F===null?void 0:function(){return L(F())}]},[p,g,y,v]);var T=s(f,S[0],S[1]);return a(function(){A.hasValue=!0,A.value=T},[T]),u(T),T},R1}var Vv;function WL(){return Vv||(Vv=1,I1.exports=GL()),I1.exports}var VL=WL();const qL=T7(VL),Q7={},{useDebugValue:YL}=D,{useSyncExternalStoreWithSelector:KL}=qL;let qv=!1;const XL=e=>e;function ZL(e,t=XL,n){(Q7?"production":void 0)!=="production"&&n&&!qv&&(console.warn("[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"),qv=!0);const r=KL(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return YL(r),r}const Yv=e=>{(Q7?"production":void 0)!=="production"&&typeof e!="function"&&console.warn("[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`.");const t=typeof e=="function"?HL(e):e,n=(r,s)=>ZL(t,r,s);return Object.assign(n,t),n},$7=e=>e?Yv(e):Yv,zf="auth:unauthorized";let Mu=null;class Da extends Error{constructor(t,n,r){super(t),this.status=n,this.code=r,this.name="TerminalApiError"}status;code}async function JL(){const e=await fetch("/api/terminal/update");if(!e.ok)throw new Da("Failed to load update state",e.status);return e.json()}async function eE(){const e=await pr(),t=await fetch("/api/terminal/update/check",{method:"POST",headers:{"X-XSRF-TOKEN":e}});if(!t.ok)throw new Da("Failed to check for updates",t.status);return t.json()}async function tE(){const e=await pr(),t=await fetch("/api/terminal/update/restart",{method:"POST",headers:{"X-XSRF-TOKEN":e}});if(!t.ok){const n=await t.json().catch(()=>({error:"Failed to restart Termdock"}));throw new Da(n.error||"Failed to restart Termdock",t.status)}return t.json()}async function nE(){const e=await fetch("/api/terminal/quota");if(!e.ok)throw new Da("Failed to fetch quota",e.status);return e.json()}async function rE(){const e=await pr(),t=await fetch("/api/terminal/quota/refresh",{method:"POST",headers:{"X-XSRF-TOKEN":e}});if(!t.ok)throw new Da("Failed to refresh quota",t.status);return t.json()}const iu=8e3,sE=32e3,Zl=1e4,Xd=45e3,iE=8e3,oE=8e3,aE=15e3,lE=1e4,i0=5e3;let cE=0;const Xp=[];let D1=!1;function Oc(e,t={}){if(typeof window>"u")return;const n=JSON.stringify({level:e==="error"||e==="timeout_or_abort"||e==="response_body_timeout"||e==="response_body_parse_error"?"warn":"info",message:`DIFF_API ${e}`,data:{seq:++cE,ts:Date.now(),...t}});Xp.push(n),uE()}async function uE(){if(!D1){D1=!0;try{for(;Xp.length>0;){const e=Xp[0];try{await fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:e,keepalive:!0}),Xp.shift()}catch{break}}}finally{D1=!1}}}function dE(e,t,n){const r=new AbortController;let s=setTimeout(()=>{r.abort(new DOMException(n,"TimeoutError"))},t);const i=()=>r.abort(e?.reason);return e&&(e.aborted?i():e.addEventListener("abort",i,{once:!0})),{signal:r.signal,cleanup:()=>{s&&(clearTimeout(s),s=null),e?.removeEventListener("abort",i)}}}async function Ls(e,t,n,r){const{signal:s,cleanup:i}=dE(t?.signal??void 0,n,r);try{return await fetch(e,{...t,signal:s})}catch(a){throw a instanceof DOMException&&a.name==="TimeoutError"?new Error(r):a}finally{i()}}async function H7(e,t,n){let r=null;const s=new Promise((i,a)=>{r=setTimeout(()=>a(new Error(n)),t)});try{return await Promise.race([e.text(),s])}finally{r&&clearTimeout(r)}}async function o0(e,t,n){const r=await H7(e,t,n);return JSON.parse(r)}if(typeof window<"u"&&!window.__termdockFetchPatched){window.__termdockFetchPatched=!0;const e=window.fetch.bind(window);window.fetch=async(...t)=>{const n=await e(...t);if(n.status===401){Mu=null;try{window.dispatchEvent(new CustomEvent(zf))}catch{}}return n}}async function pr(){if(Mu)return Mu;const e=await Ls("/api/csrf-token",void 0,iE,"CSRF token request timed out");if(!e.ok)throw new Error("Failed to get CSRF token");const t=await o0(e,i0,"CSRF token response timed out");if(!t.csrfToken)throw new Error("Invalid CSRF token response");return Mu=t.csrfToken,Mu}function U7(){Mu=null}const fE=2e4,Kv=8e3,hE=1500,fo=new Map,pE=24,mE=40,gE=40;function xE(e){return e.retryState.retryCount>=2||e.pendingInputs.length>=gE?"congested":e.retryState.retryCount>=1||e.pendingInputs.length>=8?"degraded":"good"}function Xv(e){if(e.pendingInputs.length===0||e.ws.readyState!==WebSocket.OPEN)return;const t=e.pendingInputs.splice(0);for(const n of t)try{e.ws.send(JSON.stringify({type:"input",data:n}))}catch{}}function z7(e){if(e.ws.readyState!==WebSocket.OPEN)return;const t=xE(e);if(t==="good"){Xv(e);return}if(e.inputFlushTimer)return;const n=t==="congested"?mE:pE;e.inputFlushTimer=setTimeout(()=>{e.inputFlushTimer=null,Xv(e)},n)}const Nf=new Map;function bE(e,t,n,r){const s=Nf.get(e);s&&(Nf.delete(e),t?s.resolve({success:!0,layout:n}):s.reject(new Error(r||"Tmux action failed")))}function yE(e,t){const r=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/terminal/${e}/ws`;return t>0?`${r}?since=${t}`:r}const Zv=new Map;async function vE(e){const t=await pr(),n=await fetch("/api/terminal/create",{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify({cols:e.cols||80,rows:e.rows||24,mode:e.mode||"shell",tmuxSessionName:e.tmuxSessionName,cwd:e.cwd,termType:e.termType})});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to create terminal"}));throw new Error(r.error||"Failed to create terminal session")}return n.json()}function wE(e,t,n,r={}){const{maxRetries:s=10,initialRetryDelay:i=1e3,maxRetryDelay:a=2e4,connectionTimeout:c=15e3}=r,u={maxRetries:s,initialDelayMs:i,maxDelayMs:a,connectionTimeoutMs:c,retryCount:0,retryTimeout:null,connectionTimeoutId:null,isClosed:!1,isSuspended:!1};let f=null,p=Zv.get(e)??0;Zv.delete(e);const g=[];let y=!1,v=null;const S=new WeakSet,A=()=>{u.retryTimeout&&(clearTimeout(u.retryTimeout),u.retryTimeout=null),u.connectionTimeoutId&&(clearTimeout(u.connectionTimeoutId),u.connectionTimeoutId=null),v&&(clearTimeout(v),v=null)},T=F=>{F.heartbeatTimer&&(clearInterval(F.heartbeatTimer),F.heartbeatTimer=null),F.pongTimer&&(clearTimeout(F.pongTimer),F.pongTimer=null),F.inputFlushTimer&&(clearTimeout(F.inputFlushTimer),F.inputFlushTimer=null)},L=F=>{T(F),F.heartbeatTimer=setInterval(()=>{if(F.ws.readyState===WebSocket.OPEN){try{F.ws.send(JSON.stringify({type:"ping"}))}catch{}F.pongTimer&&clearTimeout(F.pongTimer),F.pongTimer=setTimeout(()=>{if(Date.now()-F.lastInboundAt>=Kv)try{F.ws.close()}catch{}},Kv)}},fE)},I=()=>{if(u.isClosed=!0,A(),f){T(f),fo.delete(e);try{f.ws.close()}catch{}f=null}},j=()=>{if(u.isClosed)return;if(f){S.add(f.ws),T(f);try{f.ws.close()}catch{}}const F=yE(e,p),R=new WebSocket(F);y=!1,u.connectionTimeoutId=setTimeout(()=>{R.readyState!==WebSocket.OPEN&&(y=!0,R.close(),P(new Error("WebSocket connection timeout"),!1))},c);const C={ws:R,onEvent:t,onError:n,reconnectNow:()=>{if(!u.isClosed&&(u.isSuspended=!1,!v)){if(A(),f){S.add(f.ws),T(f);try{f.ws.close()}catch{}}t({type:"reconnecting",attempt:Math.min(u.retryCount+1,s),maxAttempts:s}),u.retryCount=Math.min(u.retryCount+1,s),y=!0,v=setTimeout(()=>{v=null,y=!1,j()},0)}},suspendReconnect:()=>{u.isClosed||(u.isSuspended=!0,u.retryTimeout&&(clearTimeout(u.retryTimeout),u.retryTimeout=null))},retryState:u,lastSeq:p,pendingInputs:g,inputFlushTimer:null,heartbeatTimer:null,pongTimer:null,lastInboundAt:Date.now(),inboundSequence:0};R.onopen=()=>{A(),u.retryCount=0,C.lastInboundAt=Date.now(),C.inboundSequence+=1,L(C),z7(C)},R.onmessage=$=>{C.lastInboundAt=Date.now(),C.inboundSequence+=1;try{const H=JSON.parse($.data);if(H.type==="pong"){C.pongTimer&&(clearTimeout(C.pongTimer),C.pongTimer=null);return}if(H.type==="tmux-result"&&H.reqId){bE(H.reqId,H.success!==!1,H.layout,H.error);return}if(H.type==="tmux-layout"&&H.layout){t({type:"tmux-layout",layout:H.layout});return}if(H.type==="tmux-screen-sync"&&Array.isArray(H.chunks)){t({type:"tmux-screen-sync",chunks:H.chunks.filter(V=>typeof V=="string"),cols:typeof H.cols=="number"?H.cols:void 0,rows:typeof H.rows=="number"?H.rows:void 0,generation:typeof H.generation=="number"?H.generation:void 0});return}if(H.type==="active-program"){t({type:"active-program",activeProgram:H.activeProgram,activeProgramRaw:H.activeProgramRaw,activeProgramSource:H.activeProgramSource});return}if(H.type==="cwd"){t({type:"cwd",cwd:H.cwd});return}if(H.type==="agent-status"){t({type:"agent-status",agentStatus:H.agentStatus??null,agentIndicator:H.agentIndicator??null,agentStatusDetail:H.agentStatusDetail??null,agent:H.agent??null,agentMessage:H.agentMessage??null,agentNativeSessionId:H.agentNativeSessionId??null,agentResumeRecovered:H.agentResumeRecovered===!0,agentRich:H.agentRich===!0,agentActivity:typeof H.agentActivity=="number"?H.agentActivity:0,agentCwd:H.agentCwd??null,reviewed:typeof H.reviewed=="boolean"?H.reviewed:null});return}if(H.type==="git-status"){t({type:"git-status",gitStatus:H.gitStatus??null});return}if(H.type==="quota-status"&&Array.isArray(H.providers)){window.dispatchEvent(new CustomEvent("termdock:quota-update",{detail:H.providers}));return}if(H.type==="focus-mode"){t({type:"focus-mode",focusTrackingRequested:H.focusTrackingRequested===!0});return}if(H.type==="resize-ack"){t({type:"resize-ack",seq:typeof H.seq=="number"?H.seq:void 0,cols:typeof H.cols=="number"?H.cols:void 0,rows:typeof H.rows=="number"?H.rows:void 0,ok:H.ok!==!1,error:typeof H.error=="string"?H.error:void 0});return}if(H.type==="pty-size"){t({type:"pty-size",cols:typeof H.cols=="number"?H.cols:void 0,rows:typeof H.rows=="number"?H.rows:void 0,source:typeof H.source=="string"?H.source:void 0});return}if(H.type==="shell-title"){t({type:"shell-title",title:typeof H.title=="string"?H.title:""});return}if(H.type==="prompt-state"){t({type:"prompt-state",state:H.state==="running"?"running":"idle",exitCode:typeof H.exitCode=="number"?H.exitCode:void 0});return}const Y=H;if(Y.type==="connected"){typeof Y.replayLastSeq=="number"&&Y.replayLastSeq>0&&(p=Y.replayLastSeq,C.lastSeq=p),t(Y);return}if(Y.type==="exit"){I(),t(Y);return}t(Y),Y.type==="data"&&typeof Y.seq=="number"&&Number.isFinite(Y.seq)&&Y.seq>p&&(p=Y.seq,C.lastSeq=p)}catch(H){n?.(H,!1)}},R.onerror=()=>{S.has(R)||(A(),T(C),y||(y=!0,P(new Error("WebSocket connection error"),!1)))},R.onclose=$=>{if(!S.has(R)&&(A(),T(C),!u.isClosed&&!y)){if(y=!0,$.code===4001){console.warn("[Terminal] WS 4001: Session not found on server",{code:$.code,reason:$.reason,stack:new Error().stack}),P(new Error("Session not found on server"),!0);return}if($.code===4003||$.code===4401){try{window.dispatchEvent(new CustomEvent(zf))}catch{}P(new Error("Authentication required"),!0);return}P(new Error("WebSocket connection closed"),!1)}},f=C,fo.set(e,f)},P=(F,R)=>{if(!u.isClosed)if(R)n?.(F,!0),I();else{u.retryCount=Math.min(u.retryCount+1,Math.max(1,s));const C=Math.min(i*Math.pow(2,u.retryCount-1),a);if(t({type:"reconnecting",attempt:u.retryCount,maxAttempts:s}),u.isSuspended)return;u.retryTimeout=setTimeout(()=>{u.isClosed||j()},C)}};return j(),I}async function G7(e,t){const n=fo.get(e);if(n){if(n.ws.readyState===WebSocket.OPEN){n.pendingInputs.push(t),z7(n);return}if(n.ws.readyState===WebSocket.CONNECTING){n.pendingInputs.push(t);return}}const r=await pr(),s=await fetch(`/api/terminal/${e}/input`,{method:"POST",headers:{"Content-Type":"text/plain","X-XSRF-TOKEN":r},body:t});if(!s.ok){const i=await s.json().catch(()=>({error:"Failed to send input"}));throw new Error(i.error||"Failed to send terminal input")}}function SE(e,t){const n=fo.get(e);if(!n)return!1;if(n.retryState.isSuspended=!1,n.ws.readyState!==WebSocket.OPEN)return n.reconnectNow(),!0;const r=n.inboundSequence;try{n.ws.send(JSON.stringify({type:"ping"}))}catch{}return setTimeout(()=>{fo.get(e)!==n||n.retryState.isClosed||(n.inboundSequence<=r?n.reconnectNow():t?.())},hE),!0}function AE(e){const t=fo.get(e);return t?(t.reconnectNow(),!0):!1}function Jv(){for(const e of fo.values())e.suspendReconnect()}function e5(e,t,n){const r=fo.get(e);if(!(!r||r.ws.readyState!==WebSocket.OPEN))try{r.ws.send(JSON.stringify({type:"focus",focused:t,reason:n}))}catch{}}function t5(e,t,n){const r=fo.get(e);if(!(!r||r.ws.readyState!==WebSocket.OPEN))try{r.ws.send(JSON.stringify({type:"viewing",viewing:t,reason:n}))}catch{}}function n5(e){const t=fo.get(e);if(!(!t||t.ws.readyState!==WebSocket.OPEN))try{t.ws.send(JSON.stringify({type:"agent-review-ack"}))}catch{}}function r5(e,t,n){const r=fo.get(e);if(!(!r||r.ws.readyState!==WebSocket.OPEN))try{r.ws.send(JSON.stringify({type:"flow-control",paused:t,reason:n}))}catch{}}async function TE(e,t,n,r){const s=fo.get(e);if(s&&s.ws.readyState===WebSocket.OPEN)try{s.ws.send(JSON.stringify({type:"resize",cols:t,rows:n,seq:r}));return}catch{}const i=await pr(),a=await fetch(`/api/terminal/${e}/resize`,{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":i},body:JSON.stringify({cols:t,rows:n,seq:r})});if(!a.ok){const u=await a.json().catch(()=>({error:"Failed to resize terminal"}));throw new Error(u.error||"Failed to resize terminal")}const c=await a.json().catch(()=>({success:!0}));if(c?.success===!1||c?.ok===!1)throw new Error(c?.error||"Failed to resize terminal")}async function CE(e,t){const n=fo.get(e);if(n&&n.ws.readyState===WebSocket.OPEN)return t.action==="scroll"?(n.ws.send(JSON.stringify({type:"tmux",...t})),{success:!0}):new Promise((i,a)=>{const c=Math.random().toString(36).substring(7);Nf.set(c,{resolve:i,reject:a}),n.ws.send(JSON.stringify({type:"tmux",reqId:c,...t})),setTimeout(()=>{Nf.has(c)&&(Nf.delete(c),a(new Error("Tmux action timed out")))},3e4)});const r=await pr(),s=await fetch(`/api/terminal/${e}/tmux`,{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":r},body:JSON.stringify(t)});if(!s.ok){const i=await s.json().catch(()=>({error:"Failed to execute tmux action"}));throw new Error(i.error||"Failed to execute tmux action")}return s.json()}async function W7(e){const t=fo.get(e);if(t){t.retryState.isClosed=!0;try{t.ws.close()}catch{}fo.delete(e)}const n=await pr(),r=await fetch(`/api/terminal/${e}`,{method:"DELETE",headers:{"X-XSRF-TOKEN":n}});if(r.status!==404&&!r.ok){const s=await r.json().catch(()=>({error:"Failed to close terminal"}));throw new Error(s.error||"Failed to close terminal")}}async function kE(e,t){const n=fo.get(e);if(n){n.retryState.isClosed=!0;try{n.ws.close()}catch{}fo.delete(e)}const r=await pr(),s=await fetch(`/api/terminal/${e}/restart`,{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":r},body:JSON.stringify({...t.cwd?{cwd:t.cwd}:{},cols:t.cols??80,rows:t.rows??24,mode:t.mode,tmuxSessionName:t.tmuxSessionName})});if(!s.ok){const i=await s.json().catch(()=>({error:"Failed to restart terminal"}));throw new Error(i.error||"Failed to restart terminal session")}return s.json()}async function _E(e){const t=await Ls(`/api/terminal/${e}/health`,{method:"GET"},oE,"Terminal health check timed out");if(!t.ok){if(t.status===404)return{healthy:!1,sessionId:e};const n=await o0(t,i0,"Terminal health error response timed out").catch(()=>({error:"Failed to check terminal health"}));throw new Error(n.error||"Failed to check terminal health")}return o0(t,i0,"Terminal health response timed out")}async function LE(e){const t=await pr(),n=await Ls("/api/terminal/force-kill",{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify(e)},lE,"Terminal force-kill request timed out");if(!n.ok){const r=await o0(n,i0,"Terminal force-kill error response timed out").catch(()=>({error:"Failed to force kill terminal"}));throw new Error(r.error||"Failed to force kill terminal")}}async function yb(){const e=await fetch("/api/terminal/tmux/sessions",{method:"GET"});if(!e.ok){const n=await e.json().catch(()=>({error:"Failed to list tmux sessions"}));throw new Error(n.error||"Failed to list tmux sessions")}const t=await e.json();return Array.isArray(t.sessions)?t.sessions:[]}async function vb(){const e=await fetch("/api/terminal/tmux/status",{method:"GET"});if(!e.ok){const t=await e.json().catch(()=>({error:"Failed to get tmux status"}));throw new Error(t.error||"Failed to get tmux status")}return e.json()}async function V7(e){const t=e.trim();if(!t)throw new Error("tmux session name is required");const n=await pr(),r=await fetch(`/api/terminal/tmux/sessions/${encodeURIComponent(t)}`,{method:"DELETE",headers:{"X-XSRF-TOKEN":n}});if(!r.ok){const i=await r.json().catch(()=>({error:"Failed to kill tmux session"}));throw new Error(i.error||"Failed to kill tmux session")}const s=await r.json();return{cleanedSessions:Array.isArray(s.cleanedSessions)?s.cleanedSessions:[],alreadyGone:!!s.alreadyGone}}async function EE(){const e=await pr(),t=await fetch("/api/terminal/tmux/recovery/restore-all",{method:"POST",headers:{"X-XSRF-TOKEN":e}}),n=await t.json().catch(()=>({}));if(!t.ok)throw new Da(n.error||"Failed to restore tmux Agent sessions",t.status);return n}async function IE(){const e=await pr(),t=await fetch("/api/terminal/tmux/recovery",{method:"DELETE",headers:{"X-XSRF-TOKEN":e}});if(!t.ok)throw new Da("Failed to dismiss tmux recovery",t.status)}const op=new Map;function RE(e){return JSON.stringify({preferredFrontendSessionId:e.preferredFrontendSessionId??null,mode:e.mode??null,tmuxSessionName:e.tmuxSessionName??null,cwd:e.cwd??null,termType:e.termType??null,createIfEmpty:e.createIfEmpty===!0,requireExisting:e.requireExisting===!0})}async function NE(){const e=await fetch("/api/terminal/session-inventory",{method:"GET"});if(!e.ok){const t=await e.json().catch(()=>({error:"Failed to load session inventory"}));throw new Error(t.error||"Failed to load session inventory")}return e.json()}async function q7(e){const t=RE(e),n=op.get(t);if(n)return n;const r=await pr(),s=Ls("/api/terminal/session-inventory/open",{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":r},body:JSON.stringify(e)},aE,"Terminal session open request timed out").then(async i=>{if(!i.ok){const a=await o0(i,i0,"Terminal session open error response timed out").catch(()=>({error:"Failed to open session"}));throw new Da(a.error||"Failed to open session",i.status,typeof a.code=="string"?a.code:void 0)}return o0(i,i0,"Terminal session open response timed out")}).finally(()=>{op.get(t)===s&&op.delete(t)});return op.set(t,s),s}async function Zp(e,t){const n=await pr(),r=await fetch(`/api/terminal/session-inventory/sessions/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":n},body:JSON.stringify(t)});if(!r.ok){const s=await r.json().catch(()=>({error:"Failed to update session"}));throw new Error(s.error||"Failed to update session")}return r.json()}async function ME(e){const t=await pr(),n=await fetch("/api/terminal/session-inventory/reorder",{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify({sessionIds:e})});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to reorder sessions"}));throw new Error(r.error||"Failed to reorder sessions")}return n.json()}async function DE(e){const t=await pr(),n=await fetch(`/api/terminal/session-inventory/sessions/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"X-XSRF-TOKEN":t}});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to remove session"}));throw new Error(r.error||"Failed to remove session")}}async function jE(){const e=await pr(),t=await fetch("/api/terminal/session-inventory/sessions",{method:"DELETE",headers:{"X-XSRF-TOKEN":e}});if(!t.ok){const n=await t.json().catch(()=>({error:"Failed to clear sessions"}));throw new Error(n.error||"Failed to clear sessions")}}async function s5(){const e=await fetch("/api/terminal/toolbar-presets",{method:"GET"});if(!e.ok){const t=await e.json().catch(()=>({error:"Failed to load toolbar presets"}));throw new Error(t.error||"Failed to load toolbar presets")}return e.json()}async function PE(e){const t=await pr(),n=await fetch("/api/terminal/toolbar-presets",{method:"PUT",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to save toolbar presets"})),s=new Error(r.error||"Failed to save toolbar presets");throw s.current=r.current,s.code=r.code,s}return n.json()}async function dh(){const e=await fetch("/api/terminal/settings",{method:"GET"});if(!e.ok){const t=await e.json().catch(()=>({error:"Failed to load settings"}));throw new Error(t.error||"Failed to load settings")}return e.json()}async function ta(e){const t=await pr(),n=await fetch("/api/terminal/settings",{method:"PUT",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to update settings"}));throw new Error(r.error||"Failed to update settings")}return n.json()}async function H0(e=!1){const t=await fetch(`/api/terminal/auto-title/catalog${e?"?refresh=1":""}`);if(!t.ok)throw new Error("Failed to discover title models");const n=await t.json();return Array.isArray(n?.namers)?n.namers:[]}async function BE(){const e=await fetch("/api/terminal/context-draft",{method:"GET"});if(!e.ok){const t=await e.json().catch(()=>({error:"Failed to load context draft"}));throw new Error(t.error||"Failed to load context draft")}return e.json()}async function FE(e,t){const n=await pr(),r=await fetch("/api/terminal/context-draft",{method:"PUT",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":n},body:JSON.stringify({text:e,origin:t})});if(!r.ok){const s=await r.json().catch(()=>({error:"Failed to update context draft"}));throw new Error(s.error||"Failed to update context draft")}return r.json()}async function OE(){const e=await fetch("/api/auth/status");if(!e.ok)throw new Error("Failed to query auth status");return e.json()}async function QE(e){const t=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:e})});if(t.ok)return U7(),{ok:!0};const n=await t.json().catch(()=>null);return t.status===429?{ok:!1,rateLimited:!0,retryAfterMs:typeof n?.retryAfterMs=="number"?n.retryAfterMs:void 0,error:n?.error||"Too many failed attempts. Please wait and try again."}:{ok:!1,error:n?.error||"Login failed"}}async function $E(){const e=await pr();await fetch("/api/auth/logout",{method:"POST",headers:{"X-XSRF-TOKEN":e}}),U7()}async function Y7(){const e=await fetch("/api/terminal/agent-launchers");if(!e.ok)throw new Error("Failed to detect agent launchers");const t=await e.json();return Array.isArray(t?.agents)?t.agents:[]}async function HE(){const e=await fetch("/api/terminal/agent-hooks");if(!e.ok)throw new Error("Failed to get agent hooks");const t=await e.json();return Array.isArray(t?.agents)?t.agents:[]}async function UE(e){const t=await pr(),n=await fetch(`/api/terminal/agent-hooks/${encodeURIComponent(e)}/install`,{method:"POST",headers:{"X-XSRF-TOKEN":t}}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Error(r.error||"Failed to install agent hooks");return{summary:r.summary??"Installed",devMode:r.devMode===!0}}async function zE(e){const t=await pr(),n=await fetch(`/api/terminal/agent-hooks/${encodeURIComponent(e)}/uninstall`,{method:"POST",headers:{"X-XSRF-TOKEN":t}}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Error(r.error||"Failed to uninstall agent hooks");return r.summary??"Removed"}class Z2 extends Error{constructor(t,n,r){super(t),this.code=n,this.migration=r,this.name="AgentPluginManifestError"}code;migration}async function GE(){const e=await fetch("/api/terminal/agent-plugins");if(!e.ok)throw new Error("Failed to get agent plugins");return await e.json()}async function WE(e){const t=await pr(),n=await fetch("/api/terminal/agent-plugins",{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify(e)}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Z2(r.error||"Failed to create agent plugin",r.code,r.migration);return r}async function VE(e){const t=await pr(),n=await fetch("/api/terminal/agent-plugins/install",{method:"POST",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify({source:e})}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Z2(r.error||"Failed to install agent plugin",r.code,r.migration);return r}async function qE(e){const t=await pr(),n=await fetch(`/api/terminal/agent-plugins/${encodeURIComponent(e)}/check-update`,{method:"POST",headers:{"X-XSRF-TOKEN":t}}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Error(r.error||"Failed to check plugin updates");return r}async function YE(e){const t=await pr(),n=await fetch(`/api/terminal/agent-plugins/${encodeURIComponent(e)}/update`,{method:"POST",headers:{"X-XSRF-TOKEN":t}}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Error(r.error||"Failed to update plugin");return r}async function KE(e){const t=await pr(),n=await fetch(`/api/terminal/agent-plugins/${encodeURIComponent(e)}/doctor`,{method:"POST",headers:{"X-XSRF-TOKEN":t}}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Error(r.error||"Failed to diagnose plugin");return r}async function XE(e){const t=await pr(),n=await fetch(`/api/terminal/agent-plugins/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"X-XSRF-TOKEN":t}});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||"Failed to delete agent plugin")}}async function ZE(e){const t=await pr(),n=await fetch(`/api/terminal/${encodeURIComponent(e)}/agent-resume`,{method:"POST",headers:{"X-XSRF-TOKEN":t}}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Da(r.error||"Failed to resume agent session",n.status,typeof r.code=="string"?r.code:void 0);return{command:r.command??""}}async function i5(){const e=await fetch("/api/terminal/agent-resume-history",{method:"GET"});if(!e.ok)throw new Error("Failed to load Agent resume history");const t=await e.json().catch(()=>({entries:[]}));return Array.isArray(t.entries)?t.entries:[]}async function K7(e){const t=await pr(),n=await fetch(`/api/terminal/agent-resume-history/${encodeURIComponent(e)}/prepare`,{method:"POST",headers:{"X-XSRF-TOKEN":t}}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Da(r.error||"Failed to prepare Agent session resume",n.status,typeof r.code=="string"?r.code:void 0);return r}async function JE(e){const t=await pr(),n=await fetch(`/api/terminal/agent-resume-history/${encodeURIComponent(e)}`,{method:"DELETE",headers:{"X-XSRF-TOKEN":t}});if(!n.ok&&n.status!==404)throw new Error("Failed to remove Agent resume history")}async function Sd(e){const t=await pr(),n=await fetch("/api/terminal/program-rules",{method:"PUT",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>({error:"Failed to update program rules"}));throw new Error(r.error||"Failed to update program rules")}return n.json()}async function eI(){const e=await pr(),t=await fetch("/api/terminal/program-rules",{method:"DELETE",headers:{"X-XSRF-TOKEN":e}});if(!t.ok)throw new Error("Failed to reset program rules");return t.json()}async function tI(){const e=await fetch("/api/terminal/program-detection");if(!e.ok)throw new Error("Failed to get program detection config");return e.json()}async function o5(e){const t=await pr(),n=await fetch("/api/terminal/program-detection",{method:"PUT",headers:{"Content-Type":"application/json","X-XSRF-TOKEN":t},body:JSON.stringify(e)});if(!n.ok)throw new Error("Failed to save program detection config");return n.json()}async function nI(){const e=await pr(),t=await fetch("/api/terminal/program-detection",{method:"DELETE",headers:{"X-XSRF-TOKEN":e}});if(!t.ok)throw new Error("Failed to reset program detection config");return t.json()}const rI={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".bmp":"image/bmp",".ico":"image/x-icon",".svg":"image/svg+xml",".heic":"image/heic",".heif":"image/heif"};function J2(e){const t=e.lastIndexOf(".");return t<0?null:rI[e.slice(t).toLowerCase()]??null}function ey(e){return J2(e)!==null}function X7(e){const t=J2(e);return t==="image/heic"||t==="image/heif"}const sI={".mp4":"video/mp4",".m4v":"video/x-m4v",".webm":"video/webm",".mov":"video/quicktime",".ogv":"video/ogg",".mpeg":"video/mpeg",".mpg":"video/mpeg"};function Z7(e){const t=e.lastIndexOf(".");return t<0?null:sI[e.slice(t).toLowerCase()]??null}function J7(e){return Z7(e)!==null}function iI(e){return`/api/terminal/fs/video?path=${encodeURIComponent(e)}&action=view_file`}const oI=[".stl",".glb",".gltf"];function e8(e){const t=e.lastIndexOf(".");if(t<0)return null;const n=e.slice(t).toLowerCase();return oI.includes(n)?n:null}function t8(e){return e8(e)!==null}function n8(e){const t=e.toLowerCase();return t.endsWith(".kicad_sch")?".kicad_sch":t.endsWith(".kicad_pcb")?".kicad_pcb":null}function aI(e){return n8(e)!==null}function lI(e){return n8(e)===".kicad_pcb"?"pcb-front":"schematic"}const cI=[".html",".htm"];function U0(e){const t=e.lastIndexOf(".");if(t<0)return!1;const n=e.slice(t).toLowerCase();return cI.includes(n)}function uI(e){return`/api/terminal/fs/preview/${e.split(/[\\/]+/).filter(Boolean).map(n=>encodeURIComponent(n)).join("/")}`}const dI={".stl":"model/stl",".glb":"model/gltf-binary",".gltf":"model/gltf+json"};async function r8(e,t,n,r="list_directory",s,i="name"){const a=new URLSearchParams({path:e});n&&a.set("showHidden","true"),i!=="name"&&a.set("sort",i),a.set("action",r),s&&a.set("requestSlotId",s);const c=await Ls(`/api/terminal/fs/list?${a}`,{signal:t},iu,"Directory listing took too long. The folder may be on slow storage or blocked by another process.");if(!c.ok){const u=await c.json().catch(()=>({error:"Failed to list directory"}));throw new Error(u.error||"Failed to list directory")}return c.json()}async function fI(e,t,n,r,s,i="name",a){const c=new URLSearchParams({path:e,query:t,stream:"true"});s&&c.set("showHidden","true"),i==="content"&&c.set("mode","content"),a&&c.set("requestSlotId",a);const u=await fetch(`/api/terminal/fs/search?${c}`,{signal:r});if(!u.ok||!u.body){const v=await u.json().catch(()=>({error:"Failed to search files"}));throw new Error(v.error||"Failed to search files")}const f=u.body.getReader(),p=new TextDecoder;let g="";const y=v=>{if(!v.trim())return;const S=JSON.parse(v);if(S.type==="meta")n({path:S.path,query:S.query,engine:S.engine,mode:S.mode,limited:S.limited});else if(S.type==="batch")n({entries:S.entries??[]});else if(S.type==="content-batch")n({contentEntries:S.contentEntries??[]});else{if(S.type==="error")throw new Error(S.message||"Search failed");S.type==="done"&&n({total:S.total,truncated:S.truncated,limited:S.limited,engine:S.engine,mode:S.mode,done:!0})}};for(;;){const{value:v,done:S}=await f.read();if(S)break;g+=p.decode(v,{stream:!0});let A=g.indexOf(`
3
3
  `);for(;A>=0;)y(g.slice(0,A)),g=g.slice(A+1),A=g.indexOf(`
4
4
  `)}g+=p.decode(),y(g)}async function hI(e,t,n){const r=new URLSearchParams;r.set("roots",e.join("|"));const s=await fetch(`/api/terminal/fs/watch?${r}`,{signal:n});if(!s.ok||!s.body){const p=await s.json().catch(()=>({error:"Failed to watch files"}));throw new Error(p.error||"Failed to watch files")}const i=s.body.getReader(),a=new TextDecoder;let c="",u=null;const f=p=>{if(!p.trim())return;const g=JSON.parse(p);if(g.type==="events"&&g.events?.length){t(g.events);const y=g.events.find(v=>v.type==="rescan-required"&&v.reason!=="event-storm"&&v.reason!=="reconnected");y?.reason&&(u=y.reason)}};for(;;){const{value:p,done:g}=await i.read();if(g)break;c+=a.decode(p,{stream:!0});let y=c.indexOf(`
@@ -167,44 +167,44 @@ ${r.length>0?`${r.join(`
167
167
  ${z.desc}`:""}`,"aria-pressed":T===z.key,onPointerEnter:()=>A(z.key),onPointerLeave:()=>A(J=>J===z.key?null:J),onClick:()=>{F(null),L(J=>J===z.key?null:z.key)},children:[o.jsxs("span",{className:"block font-bold tabular-nums",children:[z.fromNode.index+1," → ",z.toNode.index+1]}),o.jsx("span",{className:"block text-muted-foreground",children:te})]},`${z.key}-label`)}),R.nodes.map(({node:z,index:te,x:pe,y:de,height:ke})=>o.jsxs(m4,{elementRef:be=>{be?u.current.set(z.id,be):u.current.delete(z.id)},anchor:z.anchor??we.get(z.id),onActivate:()=>{F(z.id),L(null)},onNavigate:n,className:`absolute overflow-hidden rounded-lg border bg-surface/95 px-2.5 py-2 text-foreground shadow-[0_10px_24px_rgba(0,0,0,0.18)] transition-[opacity,border-color,box-shadow] duration-150 ${ve?.has(z.id)?"border-primary/60 shadow-[0_0_0_1px_rgb(var(--primary-rgb)/0.28),0_10px_24px_rgba(0,0,0,0.22)]":ve?"border-border/15 opacity-40":"border-border/25"}`,style:{left:pe,top:de,width:y0,minHeight:ke},children:[o.jsx("span",{className:"absolute inset-0",onPointerEnter:()=>j(z.id),onPointerLeave:()=>j(be=>be===z.id?null:be)}),o.jsx("span",{className:`pointer-events-none absolute bottom-2 left-0 top-2 w-[3px] rounded-r-full ${FZ(z.kind)}`}),o.jsxs("div",{className:"pointer-events-none relative flex min-w-0 items-center gap-1.5",children:[o.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-primary/15 text-[9px] font-bold text-primary",children:te+1}),o.jsx("span",{className:"min-w-0 flex-1 whitespace-normal break-words text-[11px] font-semibold leading-snug text-foreground",children:z.title}),z.anchor&&o.jsx(El,{size:11,className:"shrink-0 opacity-70"})]}),z.kind&&o.jsx("div",{className:"pointer-events-none relative mt-0.5 truncate text-[9px] font-semibold uppercase tracking-[0.08em] text-muted-foreground/80",children:z.kind}),o.jsx("div",{className:"pointer-events-none relative mt-0.5 whitespace-normal break-words text-[10px] leading-snug text-muted-foreground",children:z.business})]},z.id))]})})]}),(c.risks.length>0||c.checks.length>0)&&o.jsxs("div",{className:"mt-2 grid gap-1.5",children:[c.risks.slice(0,3).map((z,te)=>o.jsxs(m4,{anchor:z.anchor,onNavigate:n,className:"flex w-full items-start gap-1.5 rounded-md border border-[rgb(var(--warning-rgb)_/_0.25)] bg-[rgb(var(--warning-rgb)_/_0.10)] px-2 py-1.5 text-[10px] text-muted-foreground",children:[o.jsx(yg,{size:12,className:"mt-0.5 shrink-0 text-[color:var(--warning)]"}),o.jsx("span",{className:"min-w-0 whitespace-normal break-words leading-snug",children:z.title})]},`${z.title}-${te}`)),c.checks.slice(0,3).map((z,te)=>o.jsxs("div",{className:"flex items-start gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[10px] text-muted-foreground",children:[o.jsx(_b,{size:12,className:"mt-0.5 shrink-0 text-primary"}),o.jsx("span",{className:"min-w-0 whitespace-normal break-words leading-snug",children:z})]},`${z}-${te}`))]})]})}const wT="termdock:right-sidebar:diff-change-list-mode:v1";function qZ(e){return e==="list"||e==="tree"}function YZ(){return Or(wT,qZ)??"tree"}function KZ(e){for(const r of e){const s=r.hunk;if(s.oldPath&&s.newPath&&s.oldPath!==s.newPath)return"renamed";if(!s.oldPath&&s.newPath)return"added";if(s.oldPath&&!s.newPath)return"deleted"}const t=e.some(r=>r.hunk.additions>0),n=e.some(r=>r.hunk.deletions>0);return t&&!n?"added":!t&&n?"deleted":"modified"}function XZ(e){const t=new Map;for(const r of e){const s=t.get(r.hunk.filePath)??{key:r.hunk.filePath,filePath:r.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};s.items.push(r),s.additions+=r.hunk.additions,s.deletions+=r.hunk.deletions,r.current&&(s.explained+=1),r.stale&&(s.stale+=1),t.set(r.hunk.filePath,s)}const n=Array.from(t.values()).sort((r,s)=>r.filePath.localeCompare(s.filePath));for(const r of n)r.changeType=KZ(r.items);return n}function ZZ(e){const t=e.filePath.split("/").pop()??e.filePath;return{key:e.key,path:e.filePath,displayName:t,displayDir:e.filePath.includes("/")?e.filePath.slice(0,-t.length-1):"",status:e.changeType,title:e.filePath}}function JZ(e,t){const n=e.filter(i=>i.trim().length>0);if(n.length<=1)return n[0]??"";const r=[],s=new Set;for(const[i,a]of n.entries()){const c=a.split(`
168
168
  `),u=c.findIndex(g=>g.startsWith("@@ "));if(u<0){r.push(...c);continue}i===0&&r.push(...c.slice(0,u));const f=t[i];let p=u;for(;p>=0&&p<c.length;){const g=c.findIndex((L,I)=>I>p&&L.startsWith("@@ ")),y=g>=0?g:c.length,v=c.slice(p,y),S=v[0]??"",A=f?S===f:!0,T=S||f||v.join(`
169
169
  `);A&&!s.has(T)&&(r.push(...v),s.add(T)),p=g}}return r.join(`
170
- `)}function eJ({groups:e,onInsertDiffReference:t}){return e.map(n=>{const r=JZ(n.items.map(c=>c.hunk.diff||c.current?.diff||c.stale?.diff||""),n.items.map(c=>c.hunk.hunkHeader)),s=n.items.map(c=>c.current??c.stale).filter(c=>!!c).map(c=>({id:c.id,repoRoot:c.repoRoot,filePath:c.filePath,oldPath:c.oldPath,newPath:c.newPath,hunkHeader:c.hunkHeader,hunkIndex:c.hunkIndex,fingerprint:c.fingerprint,diff:c.diff,explanation:c.explanation,summary:c.summary,workspaceRoot:c.workspaceRoot,generatedBy:c.generatedBy,injectedAt:c.injectedAt})),i=n.filePath.split("/").pop()??n.filePath,a=n.filePath.includes("/")?n.filePath.slice(0,-i.length-1):"";return{key:n.key,path:n.filePath,absolutePath:s[0]?.repoRoot?`${s[0].repoRoot}/${n.filePath}`:n.filePath,status:n.changeType,repoRoot:s[0]?.repoRoot??null,displayName:i,displayDir:a,diffOverride:r,auditRecords:s,onInsertDiffReference:t}})}function tJ(e,t,n){const r=Array.from(e.querySelectorAll("[data-diff-stream-item]"));if(r.length===0)return null;const i=e.getBoundingClientRect().top+48;let a=null,c=Number.POSITIVE_INFINITY;for(const f of r){const p=f.getBoundingClientRect();if(p.bottom<i)continue;const g=Math.abs(p.top-i);g<c&&(a=f,c=g)}const u=a?.dataset.diffSelectionPath??a?.dataset.diffStreamItem??null;return!u||u===t||n(u),u}function A4({items:e,selectedKey:t,onSelect:n,emptyText:r,mobile:s=!1,backLabel:i="Back",headerTitle:a,headerMeta:c,onClose:u,closeLabel:f="Back",wrap:p=!0,onToggleWrap:g,wrapTitle:y,wrapOnLabel:v="Wrap on",wrapOffLabel:S="Wrap off",desktopLayout:A="split",onInsertDiffReference:T,onReferenceCopied:L,insertedReferenceKey:I,copiedReferenceKey:j,onClearAuditRecord:P,walkthroughs:F=[],onWalkthroughNavigate:R,initialDetailScrollTop:C,onDetailScrollPositionChange:$,scrollToKey:H,scrollToKeyNonce:Y,externalSwiperRef:V,onMobileSlideChange:fe}){const{t:X}=Yn(),ve=b.useMemo(()=>XZ(e),[e]),we=b.useMemo(()=>new Map(ve.map(ge=>[ge.key,ge])),[ve]),[ie,ae]=b.useState(()=>YZ()),[q,z]=b.useState(()=>new Set),[te,pe]=b.useState({key:null,nonce:0}),de=ve.find(ge=>ge.explained>0||ge.stale>0)?.key??ve[0]?.key??null,ke=t&&ve.some(ge=>ge.key===t)?t:de,be=b.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:ve.map(ZZ)}],[ve]),oe=b.useMemo(()=>eJ({groups:ve,onInsertDiffReference:T}),[ve,T]),he=b.useRef(de),J=b.useRef(n);he.current=de,J.current=n,b.useEffect(()=>{!t&&he.current&&J.current(he.current)},[t]);const Xe=g?o.jsxs("button",{type:"button",onClick:g,"aria-pressed":p,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${p?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[o.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),o.jsx("span",{children:p?v:S})]}):null,lt=ge=>o.jsxs("div",{className:"px-0 py-0",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[a&&o.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:a}),c&&o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:c})]}),u&&o.jsxs("button",{type:"button",onClick:u,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:[o.jsx(l0,{size:14}),f]})]}),o.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ge,Xe]})]});if(e.length===0){const ge=o.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:r});return!a&&!u?ge:o.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[lt(null),ge]})}const Ze=g?({slideToList:ge})=>o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:ge,children:[o.jsx(l0,{size:14}),i]}),o.jsxs("button",{type:"button",onClick:g,"aria-pressed":p,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${p?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[o.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),o.jsx("span",{children:p?v:S})]})]}):void 0;return o.jsx(eg,{mobile:s,desktopLayout:A,backLabel:i,groups:be,selectedKey:ke,mode:ie,onModeChange:ge=>{ae(ge),ge!=="ai"&&$n(wT,ge)},compact:s,collapsedDirectoryKeys:q,onToggleDirectory:ge=>{z(Fe=>{const Te=new Set(Fe);return Te.has(ge)?Te.delete(ge):Te.add(ge),Te})},onSelectFile:ge=>{n(ge.key),pe(Fe=>({key:ge.key,nonce:Fe.nonce+1}))},renderLeading:ge=>{const Fe=we.get(ge.key);return o.jsx(R2,{changeStatus:ge.status,auditStatus:Fe,renderChangeBadge:Te=>o.jsx(Hf,{status:Te})})},renderTrailing:ge=>{const Fe=we.get(ge.key);return Fe?o.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",Fe.additions," -",Fe.deletions]}):null},renderListHeader:lt,aiContent:({slideToDetail:ge,fullscreen:Fe,toggleFullscreen:Te})=>F.length>0&&R?o.jsx(ng,{walkthroughs:F,repoRoot:F[0]?.repoRoot,fullscreen:Fe,onToggleFullscreen:Te,onNavigate:ze=>{s&&window.requestAnimationFrame(ge),R(ze)}}):o.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:X("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Ze,externalSwiperRef:V,onMobileSlideChange:fe,detailContainerClassName:s?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:C,scrollToKey:H??te.key,scrollToKeyNonce:H==null?te.nonce:Y,onDetailScroll:ge=>{tJ(ge,ke,n),$?.(ge.scrollTop)},files:oe,activePane:!0,wrap:p,showScrollHint:!p,renderStreamBadge:(ge,Fe)=>{const Te=we.get(Fe.key);return o.jsx(R2,{changeStatus:ge,auditStatus:Te,renderChangeBadge:ze=>o.jsx(Hf,{status:ze})})},onInsertDiffReference:T,onReferenceCopied:L,insertedReferenceKey:I,copiedReferenceKey:j,onClearAuditRecord:P,emptyContent:o.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:r})})}const nJ=1400,rJ=1200,ST=44,sJ=.7;function Yx(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function M2(e){return`termdock:right-sidebar:context-draft-height:${e}:v1`}function iJ(e){try{const t=window.localStorage.getItem(M2(e)),n=t===null?NaN:Number(t);return Number.isFinite(n)&&n>=ST?n:null}catch{return null}}function T4(e,t){try{t===null?window.localStorage.removeItem(M2(e)):window.localStorage.setItem(M2(e),String(t))}catch{}}function Qp(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function oJ({value:e,collapsed:t,labels:n,focusRequest:r,insertError:s,autoCollapseAfterSend:i,onChange:a,onCollapsedChange:c,onAutoCollapseAfterSendChange:u,onDisable:f,onClear:p,onInsert:g,onInsertAndSend:y}){const[v,S]=b.useState(null),[A,T]=b.useState(!1),[L,I]=b.useState(()=>iJ(Yx())),j=b.useRef(L),P=b.useRef(null),F=b.useRef(null),R=b.useRef(e),C=b.useRef(null),$=b.useRef(null),H=!!e.trim(),Y=e.trim().split(`
171
- `)[0]??"",V=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";b.useEffect(()=>()=>{P.current!==null&&window.clearTimeout(P.current),F.current!==null&&window.clearTimeout(F.current)},[]),b.useEffect(()=>{let oe=!1;const he=Yx();return dh().then(J=>{if(oe)return;const Xe=J.contextDraftHeight?.[he]??null;T4(he,Xe),j.current=Xe,I(Xe)}).catch(()=>{}),()=>{oe=!0}},[]),b.useEffect(()=>{if(r!==void 0&&r>0){const oe=C.current;if(!oe)return;Qp()||oe.focus(),oe.setSelectionRange(oe.value.length,oe.value.length),oe.scrollTop=oe.scrollHeight}},[r]),b.useEffect(()=>{const oe=R.current;R.current=e,!(!t||e.length<=oe.length)&&(T(!0),F.current!==null&&window.clearTimeout(F.current),F.current=window.setTimeout(()=>{F.current=null,T(!1)},rJ))},[e,t]),b.useEffect(()=>{if(t)return;const oe=C.current;oe&&(oe.style.height=L!==null?`${L}px`:"")},[e,t,L]),b.useEffect(()=>{if(t)return;const oe=C.current;!oe||document.activeElement===oe||(oe.scrollTop=oe.scrollHeight)},[e,t]),b.useEffect(()=>{if(t||Qp())return;const oe=C.current;!oe||document.activeElement===oe||(oe.focus(),oe.setSelectionRange(oe.value.length,oe.value.length))},[t]);const fe=b.useRef(null);b.useLayoutEffect(()=>{if(!Qp())return;const oe=window.visualViewport;if(!oe)return;const he=()=>{const J=fe.current;if(!J)return;if(oe.height>=window.innerHeight*.75){J.style.transform="";return}const Xe=J.getBoundingClientRect(),lt=Math.round(oe.height-Xe.bottom);J.style.transform=lt!==0?`translateY(${lt}px)`:""};return he(),oe.addEventListener("resize",he),oe.addEventListener("scroll",he),()=>{oe.removeEventListener("resize",he),oe.removeEventListener("scroll",he),fe.current&&(fe.current.style.transform="")}},[t]);const X=oe=>{S(oe),P.current!==null&&window.clearTimeout(P.current),P.current=window.setTimeout(()=>{P.current=null,S(null)},nJ)},ve=oe=>{c(!1),Qp()&&window.requestAnimationFrame(()=>{const he=C.current;if(!he)return;he.focus();const J=he.value.length;he.setSelectionRange(J,J),window.requestAnimationFrame(()=>{he.setSelectionRange(J,J)})})},we=()=>{g(),X("inserted")},ie=()=>{H&&(y(),X("sent"))},ae=oe=>{if(oe.key==="Escape"){oe.preventDefault(),c(!0);return}oe.key!=="Enter"||!oe.metaKey&&!oe.ctrlKey||(oe.preventDefault(),ie())},q=oe=>{oe.preventDefault()},z=oe=>{oe.preventDefault();const he=C.current;he&&($.current={startY:oe.clientY,startHeight:he.getBoundingClientRect().height},oe.currentTarget.setPointerCapture?.(oe.pointerId))},te=oe=>{const he=$.current;if(!he)return;const J=window.visualViewport?.height??window.innerHeight,Xe=Math.round(Math.min(Math.max(he.startHeight+(he.startY-oe.clientY),ST),J*sJ));j.current=Xe,I(Xe)},pe=oe=>{const he=Yx();T4(he,oe),ta({contextDraftHeight:{[he]:oe}}).catch(()=>{})},de=()=>{$.current&&($.current=null,j.current!==null&&pe(j.current))},ke=()=>{j.current=null,I(null),pe(null)},be=e.length>0&&o.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:n.characterCount(e.length)});return t?o.jsx("section",{ref:fe,className:"shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:o.jsxs("div",{className:"flex h-8 items-center gap-1 px-2",children:[o.jsxs("button",{type:"button",onClick:()=>ve(),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!1,"aria-label":n.expand,title:n.expand,children:[o.jsx(S8,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),o.jsx("span",{className:`truncate text-[11px] ${s?"text-destructive":A?"text-primary":H?"text-foreground/80":"text-muted-foreground/50"}`,children:s??(A?n.appended:H?Y:n.title)})]}),be,o.jsx("button",{type:"button",onClick:ie,disabled:!H,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${H?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":n.send,title:n.send,children:v==="sent"?o.jsx(na,{size:12}):o.jsx(T5,{size:12})})]})}):o.jsxs("section",{ref:fe,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[o.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:z,onPointerMove:te,onPointerUp:de,onPointerCancel:de,onDoubleClick:ke,title:n.resize,"aria-hidden":"true",children:o.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),o.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[o.jsxs("button",{type:"button",onPointerDown:q,onClick:()=>c(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":n.collapse,title:n.collapse,children:[o.jsx(ra,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),o.jsx("span",{className:"truncate text-[10px] font-medium text-foreground/75",children:n.title}),be]}),o.jsx("button",{type:"button",role:"switch","aria-checked":i,onPointerDown:q,onClick:()=>u(!i),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":n.autoCollapseAfterSend,title:n.autoCollapseAfterSend,children:o.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${i?"bg-primary":"bg-surface-elevated"}`,children:o.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${i?"translate-x-2.5":"translate-x-0.5"}`})})}),o.jsx("button",{type:"button",onPointerDown:q,onClick:f,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":n.disable,title:n.disable,children:o.jsx(ts,{size:11})})]}),o.jsx("div",{className:"px-2 pb-2",children:o.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[o.jsx("textarea",{ref:C,value:e,onChange:oe=>a(oe.target.value),onKeyDown:ae,placeholder:n.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),o.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[o.jsx("button",{type:"button",onPointerDown:q,onClick:p,disabled:!H,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":n.clear,title:n.clear,children:o.jsx($i,{size:11})}),s?o.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:s}):o.jsx("span",{className:"flex-1"}),o.jsxs("button",{type:"button",onPointerDown:q,onClick:we,disabled:!H,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[o.jsx(y8,{size:11}),o.jsx("span",{children:v==="inserted"?n.inserted:n.insert})]}),o.jsxs("button",{type:"button",onPointerDown:q,onClick:ie,disabled:!H,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md bg-primary px-2 text-[10px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.98] disabled:opacity-30",title:`${n.insertAndSend} · ${V}`,children:[v==="sent"?o.jsx(na,{size:11}):o.jsx(T5,{size:11}),o.jsx("span",{children:v==="sent"?n.sent:n.send})]})]})]})})]})}function aJ(e,t){const n=t.trim();if(!n)return e;if(!e.trim())return n;const r=e.endsWith(`
170
+ `)}function eJ({groups:e,onInsertDiffReference:t}){return e.map(n=>{const r=JZ(n.items.map(c=>c.hunk.diff||c.current?.diff||c.stale?.diff||""),n.items.map(c=>c.hunk.hunkHeader)),s=n.items.map(c=>c.current??c.stale).filter(c=>!!c).map(c=>({id:c.id,repoRoot:c.repoRoot,filePath:c.filePath,oldPath:c.oldPath,newPath:c.newPath,hunkHeader:c.hunkHeader,hunkIndex:c.hunkIndex,fingerprint:c.fingerprint,diff:c.diff,explanation:c.explanation,summary:c.summary,workspaceRoot:c.workspaceRoot,generatedBy:c.generatedBy,injectedAt:c.injectedAt})),i=n.filePath.split("/").pop()??n.filePath,a=n.filePath.includes("/")?n.filePath.slice(0,-i.length-1):"";return{key:n.key,path:n.filePath,absolutePath:s[0]?.repoRoot?`${s[0].repoRoot}/${n.filePath}`:n.filePath,status:n.changeType,repoRoot:s[0]?.repoRoot??null,displayName:i,displayDir:a,diffOverride:r,auditRecords:s,onInsertDiffReference:t}})}function tJ(e,t,n){const r=Array.from(e.querySelectorAll("[data-diff-stream-item]"));if(r.length===0)return null;const i=e.getBoundingClientRect().top+48;let a=null,c=Number.POSITIVE_INFINITY;for(const f of r){const p=f.getBoundingClientRect();if(p.bottom<i)continue;const g=Math.abs(p.top-i);g<c&&(a=f,c=g)}const u=a?.dataset.diffSelectionPath??a?.dataset.diffStreamItem??null;return!u||u===t||n(u),u}function A4({items:e,selectedKey:t,onSelect:n,emptyText:r,mobile:s=!1,backLabel:i="Back",headerTitle:a,headerMeta:c,onClose:u,closeLabel:f="Back",wrap:p=!0,onToggleWrap:g,wrapTitle:y,wrapOnLabel:v="Wrap on",wrapOffLabel:S="Wrap off",desktopLayout:A="split",onInsertDiffReference:T,onReferenceCopied:L,insertedReferenceKey:I,copiedReferenceKey:j,onClearAuditRecord:P,walkthroughs:F=[],onWalkthroughNavigate:R,initialDetailScrollTop:C,onDetailScrollPositionChange:$,scrollToKey:H,scrollToKeyNonce:Y,externalSwiperRef:V,onMobileSlideChange:fe}){const{t:X}=Yn(),ve=b.useMemo(()=>XZ(e),[e]),we=b.useMemo(()=>new Map(ve.map(ge=>[ge.key,ge])),[ve]),[ie,ae]=b.useState(()=>YZ()),[q,z]=b.useState(()=>new Set),[te,pe]=b.useState({key:null,nonce:0}),de=ve.find(ge=>ge.explained>0||ge.stale>0)?.key??ve[0]?.key??null,ke=t&&ve.some(ge=>ge.key===t)?t:de,be=b.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:ve.map(ZZ)}],[ve]),oe=b.useMemo(()=>eJ({groups:ve,onInsertDiffReference:T}),[ve,T]),he=b.useRef(de),J=b.useRef(n);he.current=de,J.current=n,b.useEffect(()=>{!t&&he.current&&J.current(he.current)},[t]);const Xe=g?o.jsxs("button",{type:"button",onClick:g,"aria-pressed":p,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${p?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[o.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),o.jsx("span",{children:p?v:S})]}):null,lt=ge=>o.jsxs("div",{className:"px-0 py-0",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[a&&o.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:a}),c&&o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:c})]}),u&&o.jsxs("button",{type:"button",onClick:u,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:[o.jsx(l0,{size:14}),f]})]}),o.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[ge,Xe]})]});if(e.length===0){const ge=o.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:r});return!a&&!u?ge:o.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[lt(null),ge]})}const Ze=g?({slideToList:ge})=>o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:ge,children:[o.jsx(l0,{size:14}),i]}),o.jsxs("button",{type:"button",onClick:g,"aria-pressed":p,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${p?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[o.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),o.jsx("span",{children:p?v:S})]})]}):void 0;return o.jsx(eg,{mobile:s,desktopLayout:A,backLabel:i,groups:be,selectedKey:ke,mode:ie,onModeChange:ge=>{ae(ge),ge!=="ai"&&$n(wT,ge)},compact:s,collapsedDirectoryKeys:q,onToggleDirectory:ge=>{z(Fe=>{const Te=new Set(Fe);return Te.has(ge)?Te.delete(ge):Te.add(ge),Te})},onSelectFile:ge=>{n(ge.key),pe(Fe=>({key:ge.key,nonce:Fe.nonce+1}))},renderLeading:ge=>{const Fe=we.get(ge.key);return o.jsx(R2,{changeStatus:ge.status,auditStatus:Fe,renderChangeBadge:Te=>o.jsx(Hf,{status:Te})})},renderTrailing:ge=>{const Fe=we.get(ge.key);return Fe?o.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",Fe.additions," -",Fe.deletions]}):null},renderListHeader:lt,aiContent:({slideToDetail:ge,fullscreen:Fe,toggleFullscreen:Te})=>F.length>0&&R?o.jsx(ng,{walkthroughs:F,repoRoot:F[0]?.repoRoot,fullscreen:Fe,onToggleFullscreen:Te,onNavigate:ze=>{s&&window.requestAnimationFrame(ge),R(ze)}}):o.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:X("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:Ze,externalSwiperRef:V,onMobileSlideChange:fe,detailContainerClassName:s?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:C,scrollToKey:H??te.key,scrollToKeyNonce:H==null?te.nonce:Y,onDetailScroll:ge=>{tJ(ge,ke,n),$?.(ge.scrollTop)},files:oe,activePane:!0,wrap:p,showScrollHint:!p,renderStreamBadge:(ge,Fe)=>{const Te=we.get(Fe.key);return o.jsx(R2,{changeStatus:ge,auditStatus:Te,renderChangeBadge:ze=>o.jsx(Hf,{status:ze})})},onInsertDiffReference:T,onReferenceCopied:L,insertedReferenceKey:I,copiedReferenceKey:j,onClearAuditRecord:P,emptyContent:o.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:r})})}function nJ(e){return e.replace(/\/+$/,"")||"/"}function rJ(e,t){return e==="/"?t.startsWith("/"):t===e||t.startsWith(`${e}/`)}function sJ(e){const t=[...new Set(Array.from(e,nJ))].sort((r,s)=>r.split("/").length-s.split("/").length||r.localeCompare(s)),n=[];for(const r of t)n.some(s=>rJ(s,r))||n.push(r);return n}const iJ=1400,oJ=1200,ST=44,aJ=.7;function Yx(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function M2(e){return`termdock:right-sidebar:context-draft-height:${e}:v1`}function lJ(e){try{const t=window.localStorage.getItem(M2(e)),n=t===null?NaN:Number(t);return Number.isFinite(n)&&n>=ST?n:null}catch{return null}}function T4(e,t){try{t===null?window.localStorage.removeItem(M2(e)):window.localStorage.setItem(M2(e),String(t))}catch{}}function Qp(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function cJ({value:e,collapsed:t,labels:n,focusRequest:r,insertError:s,autoCollapseAfterSend:i,onChange:a,onCollapsedChange:c,onAutoCollapseAfterSendChange:u,onDisable:f,onClear:p,onInsert:g,onInsertAndSend:y}){const[v,S]=b.useState(null),[A,T]=b.useState(!1),[L,I]=b.useState(()=>lJ(Yx())),j=b.useRef(L),P=b.useRef(null),F=b.useRef(null),R=b.useRef(e),C=b.useRef(null),$=b.useRef(null),H=!!e.trim(),Y=e.trim().split(`
171
+ `)[0]??"",V=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";b.useEffect(()=>()=>{P.current!==null&&window.clearTimeout(P.current),F.current!==null&&window.clearTimeout(F.current)},[]),b.useEffect(()=>{let oe=!1;const he=Yx();return dh().then(J=>{if(oe)return;const Xe=J.contextDraftHeight?.[he]??null;T4(he,Xe),j.current=Xe,I(Xe)}).catch(()=>{}),()=>{oe=!0}},[]),b.useEffect(()=>{if(r!==void 0&&r>0){const oe=C.current;if(!oe)return;Qp()||oe.focus(),oe.setSelectionRange(oe.value.length,oe.value.length),oe.scrollTop=oe.scrollHeight}},[r]),b.useEffect(()=>{const oe=R.current;R.current=e,!(!t||e.length<=oe.length)&&(T(!0),F.current!==null&&window.clearTimeout(F.current),F.current=window.setTimeout(()=>{F.current=null,T(!1)},oJ))},[e,t]),b.useEffect(()=>{if(t)return;const oe=C.current;oe&&(oe.style.height=L!==null?`${L}px`:"")},[e,t,L]),b.useEffect(()=>{if(t)return;const oe=C.current;!oe||document.activeElement===oe||(oe.scrollTop=oe.scrollHeight)},[e,t]),b.useEffect(()=>{if(t||Qp())return;const oe=C.current;!oe||document.activeElement===oe||(oe.focus(),oe.setSelectionRange(oe.value.length,oe.value.length))},[t]);const fe=b.useRef(null);b.useLayoutEffect(()=>{if(!Qp())return;const oe=window.visualViewport;if(!oe)return;const he=()=>{const J=fe.current;if(!J)return;if(oe.height>=window.innerHeight*.75){J.style.transform="";return}const Xe=J.getBoundingClientRect(),lt=Math.round(oe.height-Xe.bottom);J.style.transform=lt!==0?`translateY(${lt}px)`:""};return he(),oe.addEventListener("resize",he),oe.addEventListener("scroll",he),()=>{oe.removeEventListener("resize",he),oe.removeEventListener("scroll",he),fe.current&&(fe.current.style.transform="")}},[t]);const X=oe=>{S(oe),P.current!==null&&window.clearTimeout(P.current),P.current=window.setTimeout(()=>{P.current=null,S(null)},iJ)},ve=oe=>{c(!1),Qp()&&window.requestAnimationFrame(()=>{const he=C.current;if(!he)return;he.focus();const J=he.value.length;he.setSelectionRange(J,J),window.requestAnimationFrame(()=>{he.setSelectionRange(J,J)})})},we=()=>{g(),X("inserted")},ie=()=>{H&&(y(),X("sent"))},ae=oe=>{if(oe.key==="Escape"){oe.preventDefault(),c(!0);return}oe.key!=="Enter"||!oe.metaKey&&!oe.ctrlKey||(oe.preventDefault(),ie())},q=oe=>{oe.preventDefault()},z=oe=>{oe.preventDefault();const he=C.current;he&&($.current={startY:oe.clientY,startHeight:he.getBoundingClientRect().height},oe.currentTarget.setPointerCapture?.(oe.pointerId))},te=oe=>{const he=$.current;if(!he)return;const J=window.visualViewport?.height??window.innerHeight,Xe=Math.round(Math.min(Math.max(he.startHeight+(he.startY-oe.clientY),ST),J*aJ));j.current=Xe,I(Xe)},pe=oe=>{const he=Yx();T4(he,oe),ta({contextDraftHeight:{[he]:oe}}).catch(()=>{})},de=()=>{$.current&&($.current=null,j.current!==null&&pe(j.current))},ke=()=>{j.current=null,I(null),pe(null)},be=e.length>0&&o.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:n.characterCount(e.length)});return t?o.jsx("section",{ref:fe,className:"shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:o.jsxs("div",{className:"flex h-8 items-center gap-1 px-2",children:[o.jsxs("button",{type:"button",onClick:()=>ve(),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!1,"aria-label":n.expand,title:n.expand,children:[o.jsx(S8,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),o.jsx("span",{className:`truncate text-[11px] ${s?"text-destructive":A?"text-primary":H?"text-foreground/80":"text-muted-foreground/50"}`,children:s??(A?n.appended:H?Y:n.title)})]}),be,o.jsx("button",{type:"button",onClick:ie,disabled:!H,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${H?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":n.send,title:n.send,children:v==="sent"?o.jsx(na,{size:12}):o.jsx(T5,{size:12})})]})}):o.jsxs("section",{ref:fe,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[o.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:z,onPointerMove:te,onPointerUp:de,onPointerCancel:de,onDoubleClick:ke,title:n.resize,"aria-hidden":"true",children:o.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),o.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[o.jsxs("button",{type:"button",onPointerDown:q,onClick:()=>c(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":n.collapse,title:n.collapse,children:[o.jsx(ra,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),o.jsx("span",{className:"truncate text-[10px] font-medium text-foreground/75",children:n.title}),be]}),o.jsx("button",{type:"button",role:"switch","aria-checked":i,onPointerDown:q,onClick:()=>u(!i),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":n.autoCollapseAfterSend,title:n.autoCollapseAfterSend,children:o.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${i?"bg-primary":"bg-surface-elevated"}`,children:o.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${i?"translate-x-2.5":"translate-x-0.5"}`})})}),o.jsx("button",{type:"button",onPointerDown:q,onClick:f,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":n.disable,title:n.disable,children:o.jsx(ts,{size:11})})]}),o.jsx("div",{className:"px-2 pb-2",children:o.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[o.jsx("textarea",{ref:C,value:e,onChange:oe=>a(oe.target.value),onKeyDown:ae,placeholder:n.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),o.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[o.jsx("button",{type:"button",onPointerDown:q,onClick:p,disabled:!H,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":n.clear,title:n.clear,children:o.jsx($i,{size:11})}),s?o.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:s}):o.jsx("span",{className:"flex-1"}),o.jsxs("button",{type:"button",onPointerDown:q,onClick:we,disabled:!H,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[o.jsx(y8,{size:11}),o.jsx("span",{children:v==="inserted"?n.inserted:n.insert})]}),o.jsxs("button",{type:"button",onPointerDown:q,onClick:ie,disabled:!H,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md bg-primary px-2 text-[10px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.98] disabled:opacity-30",title:`${n.insertAndSend} · ${V}`,children:[v==="sent"?o.jsx(na,{size:11}):o.jsx(T5,{size:11}),o.jsx("span",{children:v==="sent"?n.sent:n.send})]})]})]})})]})}function uJ(e,t){const n=t.trim();if(!n)return e;if(!e.trim())return n;const r=e.endsWith(`
172
172
 
173
173
  `)?"":e.endsWith(`
174
174
  `)?`
175
175
  `:`
176
176
 
177
- `;return`${e}${r}${n}`}function lJ(e,t){const n=e.trim();return n?t?`${n}\r`:/\s$/.test(e)?e:`${n} `:""}const D2="termdock:right-sidebar:html-view-mode-by-file:v1";function cJ(e){return e==="preview"||e==="source"}function AT(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.values(e).every(cJ)}function TT(e,t){if(!t)return null;const n=e&&!t.startsWith("/")?`${e}/${t}`:t;return e?`${e}::${n}`:n}function C4(e,t){const n=TT(e,t);return n?Or(D2,AT)?.[n]??"source":"source"}function uJ(e,t,n){const r=TT(e,t);if(!r)return;const s=Or(D2,AT)??{};$n(D2,{...s,[r]:n})}function Kx(e){const t=Number.isFinite(e)&&e>0?Math.floor(e):0,n=Math.floor(t/3600),r=Math.floor(t%3600/60),s=t%60,i=String(r).padStart(2,"0"),a=String(s).padStart(2,"0");return n>0?`${n}:${i}:${a}`:`${i}:${a}`}function dJ(e,t,n){return!Number.isFinite(n)||n<=0||!t.width?0:Math.min(1,Math.max(0,(e-t.left)/t.width))*n}const fJ=350,hJ=12,pJ=90;function mJ({url:e,onLoadError:t}){const{t:n}=Yn(),r=b.useRef(null),s=b.useRef(null),i=b.useRef(null),a=b.useRef(null),c=b.useRef(!1),u=b.useRef(null),f=b.useRef(null),p=b.useRef(0),g=b.useRef(!1),y=b.useRef(!1),v=b.useRef(!1),S=b.useRef(null),A=b.useRef(null),T=b.useRef(!1),L=b.useRef(1),I=b.useRef(!1),[j,P]=b.useState(0),[F,R]=b.useState(0),[C,$]=b.useState(!1),[H,Y]=b.useState(!1),[V,fe]=b.useState(null),[X,ve]=b.useState(!1),[we,ie]=b.useState(0),[ae,q]=b.useState(!1),[z,te]=b.useState({width:0,height:0}),pe=b.useCallback(()=>{S.current!==null&&(clearTimeout(S.current),S.current=null)},[]),de=b.useCallback(()=>{if(pe(),A.current=null,!T.current)return!1;const Ce=i.current;return Ce&&(Ce.playbackRate=L.current),T.current=!1,ve(!1),!0},[pe]);b.useEffect(()=>()=>{u.current!==null&&cancelAnimationFrame(u.current),f.current!==null&&clearTimeout(f.current),pe();const Ce=i.current;Ce&&T.current&&(Ce.playbackRate=L.current)},[pe]),b.useEffect(()=>{const Ce=s.current;if(!Ce||typeof ResizeObserver>"u")return;const Qe=new ResizeObserver(([pt])=>{pt&&te({width:pt.contentRect.width,height:pt.contentRect.height})});return Qe.observe(Ce),()=>Qe.disconnect()},[]),b.useEffect(()=>{const Ce=()=>q(document.fullscreenElement===r.current);return document.addEventListener("fullscreenchange",Ce),()=>document.removeEventListener("fullscreenchange",Ce)},[]);const ke=b.useCallback((Ce,Qe=!1)=>{const pt=i.current;if(!pt)return!1;const At=Number.isFinite(pt.duration)?pt.duration:Ce,yt=Math.min(Math.max(Ce,0),At);if(R(yt),Math.abs(pt.currentTime-yt)<1/120)return!1;const Yt=pt.fastSeek;return Qe&&typeof Yt=="function"?Yt.call(pt,yt):pt.currentTime=yt,!0},[]),be=b.useCallback(()=>{u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const Ce=i.current;if(!Ce||!g.current||y.current||Ce.seeking)return;const Qe=v.current;v.current=!1,y.current=ke(p.current,!Qe)}))},[ke]),oe=b.useCallback(Ce=>{const Qe=a.current,pt=i.current;if(!Qe||!pt)return;const At=Qe.getBoundingClientRect(),yt=dJ(Ce,At,pt.duration);p.current=yt,fe(yt),v.current=!1,be(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,v.current=!0,be()},pJ)},[be]),he=b.useCallback(()=>{u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),v.current=!1,y.current=!1,ke(p.current)},[ke]),J=b.useCallback(Ce=>{const Qe=i.current;if(!(!Qe||!Number.isFinite(Qe.duration)||Qe.duration<=0)){c.current=!Qe.paused,Qe.pause(),g.current=!0,Y(!0);try{Ce.currentTarget.setPointerCapture(Ce.pointerId)}catch{}oe(Ce.clientX)}},[oe]),Xe=b.useCallback(()=>{g.current=!1,he(),Y(!1),fe(null);const Ce=i.current;Ce&&c.current&&!Ce.ended&&Ce.play().catch(()=>{}),c.current=!1},[he]),lt=b.useCallback(()=>{const Ce=i.current;if(Ce){if(I.current){I.current=!1;return}Ce.paused?Ce.play().catch(()=>{}):Ce.pause()}},[]),Ze=b.useCallback(Ce=>{const Qe=i.current;!Qe||Qe.paused||Ce.button!==0||(pe(),A.current={id:Ce.pointerId,x:Ce.clientX,y:Ce.clientY},S.current=setTimeout(()=>{S.current=null,L.current=Qe.playbackRate,Qe.playbackRate=2,T.current=!0,ve(!0)},fJ))},[pe]),ge=b.useCallback(Ce=>{const Qe=A.current;!Qe||Qe.id!==Ce.pointerId||T.current||Math.hypot(Ce.clientX-Qe.x,Ce.clientY-Qe.y)>hJ&&(pe(),A.current=null)},[pe]),Fe=b.useCallback(()=>{de()&&(I.current=!0)},[de]);b.useEffect(()=>(window.addEventListener("pointerup",Fe),window.addEventListener("pointercancel",Fe),window.addEventListener("blur",Fe),()=>{window.removeEventListener("pointerup",Fe),window.removeEventListener("pointercancel",Fe),window.removeEventListener("blur",Fe)}),[Fe]);const Te=b.useCallback(async()=>{const Ce=r.current,Qe=i.current;if(!(!Ce||!Qe))try{document.fullscreenElement===Ce?await document.exitFullscreen():Ce.requestFullscreen?await Ce.requestFullscreen():Qe.webkitEnterFullscreen?.()}catch{Qe.webkitEnterFullscreen?.()}},[]),ze=b.useCallback(()=>ie(Ce=>(Ce+90)%360),[]),Be=b.useCallback(Ce=>{const Qe=i.current;if(!Qe||!Number.isFinite(Qe.duration))return;const pt=Ce.shiftKey?10:5;let At=null;Ce.key==="ArrowLeft"?At=Qe.currentTime-pt:Ce.key==="ArrowRight"?At=Qe.currentTime+pt:Ce.key==="Home"?At=0:Ce.key==="End"&&(At=Qe.duration),At!==null&&(Ce.preventDefault(),ke(At))},[ke]),We=H&&V!==null?V:F,W=j>0?Math.min(1,Math.max(0,We/j)):0,He=(we===90||we===270)&&z.width>0&&z.height>0?{width:`${z.height}px`,height:`${z.width}px`}:{width:"100%",height:"100%"};return o.jsxs("div",{ref:r,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":we,children:[o.jsxs("div",{ref:s,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[o.jsx("video",{ref:i,"data-testid":"file-preview-video",className:"absolute left-1/2 top-1/2 max-w-none object-contain transition-transform duration-200",style:{...He,transform:`translate(-50%, -50%) rotate(${we}deg)`},src:e,preload:"auto",playsInline:!0,onClick:lt,onPointerDown:Ze,onPointerMove:ge,onPointerUp:Fe,onPointerCancel:Fe,onContextMenu:Ce=>{T.current&&Ce.preventDefault()},onPlay:()=>$(!0),onPause:()=>$(!1),onTimeUpdate:Ce=>R(Ce.currentTarget.currentTime),onSeeked:Ce=>{const Qe=Ce.currentTarget;if(R(Qe.currentTime),y.current=!1,!g.current)return;const pt=Qe.requestVideoFrameCallback;typeof pt=="function"?pt.call(Qe,()=>{g.current&&be()}):requestAnimationFrame(()=>{g.current&&be()})},onLoadedMetadata:Ce=>P(Number.isFinite(Ce.currentTarget.duration)?Ce.currentTarget.duration:0),onDurationChange:Ce=>P(Number.isFinite(Ce.currentTarget.duration)?Ce.currentTarget.duration:0),onError:t,children:n("rightSidebar.videoUnsupported")}),X&&o.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:n("rightSidebar.videoLongPressSpeed")}),H&&V!==null&&o.jsx("div",{className:"pointer-events-none absolute bottom-1 z-10 -translate-x-1/2 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground shadow-md",style:{left:`${W*100}%`},"data-testid":"file-preview-video-scrub-time",children:Kx(V)})]}),o.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${y9}`,[v9]:"",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:lt,"aria-label":n(C?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:n(C?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:C?o.jsx(w8,{size:14}):o.jsx(Ib,{size:14})}),o.jsxs("div",{ref:a,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(j),"aria-valuenow":Math.floor(We),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:J,onPointerMove:Ce=>{H&&oe(Ce.clientX)},onPointerUp:Xe,onPointerCancel:Xe,onKeyDown:Be,children:[o.jsx("div",{className:"h-1 w-full rounded-full bg-surface-elevated"}),o.jsx("div",{className:"absolute inset-y-0 left-0 my-auto h-1 rounded-full bg-primary",style:{width:`${W*100}%`}}),o.jsx("div",{className:"absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary shadow",style:{left:`${W*100}%`}})]}),o.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Kx(We)," / ",Kx(j)]}),o.jsx("button",{type:"button",onClick:ze,"aria-label":n("rightSidebar.videoRotate"),title:n("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:o.jsx(IM,{size:14})}),o.jsx("button",{type:"button",onClick:()=>{Te()},"aria-label":n(ae?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:n(ae?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:ae?o.jsx(aM,{size:14}):o.jsx(nM,{size:14})})]})})]})}function gJ(e){const t=Math.max(0,Math.min(100,e.xPercent)),n=Math.max(0,Math.min(100,e.yPercent));return{...t<=50?{left:`calc(${t}% + 8px)`}:{right:`calc(${100-t}% + 8px)`},...n<=50?{top:`calc(${n}% + 8px)`}:{bottom:`calc(${100-n}% + 8px)`}}}function Og({anchor:e,children:t,disabled:n=!1,onClick:r,title:s}){return o.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:n,onClick:i=>{i.stopPropagation(),r()},title:s,style:gJ(e),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[o.jsx(El,{size:11}),t]})}function xJ(e,t,n,r){if(n.width<=0||n.height<=0||r.width<=0||r.height<=0)return null;const s=Math.min(n.width/r.width,n.height/r.height);if(!Number.isFinite(s)||s<=0)return null;const i=r.width*s,a=r.height*s,c=n.left+(n.width-i)/2,u=n.top+(n.height-a)/2,f=e-c,p=t-u;if(f<0||p<0||f>i||p>a)return null;const g=f/i*100,y=p/a*100;return{x:r.x+r.width*g/100,y:r.y+r.height*y/100,xPercent:g,yPercent:y}}function bJ(e,t,n){const r=[`SVG标注: ${e}`,`视图: ${t}`,`SVG坐标: (${n.x.toFixed(2)},${n.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${n.xPercent.toFixed(1)}%,${n.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return n.nearestText&&r.push(`最近文字: ${n.nearestText}`),`"${r.join(" / ")}"`}function yJ(e){const t=new DOMParser().parseFromString(e,"image/svg+xml"),n=t.documentElement;if(n.nodeName.toLowerCase()!=="svg"||t.querySelector("parsererror"))throw new Error("Invalid SVG document");return t.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(r=>r.remove()),t.querySelectorAll("*").forEach(r=>{for(const s of Array.from(r.attributes)){const i=s.name.toLowerCase(),a=s.value.trim();(i.startsWith("on")||(i==="href"||i.endsWith(":href"))&&a&&!a.startsWith("#"))&&r.removeAttribute(s.name)}}),n.removeAttribute("width"),n.removeAttribute("height"),n.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(n)}function vJ(e,t,n){let r=null;for(const s of Array.from(e.querySelectorAll("text"))){const i=(s.textContent??"").replace(/\s+/g," ").trim();if(!i)continue;const a=Number(s.getAttribute("x")),c=Number(s.getAttribute("y"));if(!Number.isFinite(a)||!Number.isFinite(c))continue;const u=Math.hypot(a-t,c-n);(!r||u<r.distance)&&(r={text:i,distance:u})}return r?.text.slice(0,120)}function CT({blobUrl:e,filePath:t,viewLabel:n,onInsertAnnotation:r}){const s=b.useRef(null),i=b.useRef(null),[a,c]=b.useState(null),[u,f]=b.useState(null),[p,g]=b.useState(1),[y,v]=b.useState(!1),[S,A]=b.useState(null),T=b.useRef(new Map),L=b.useRef(null),I=b.useRef(!1),j=b.useRef(null),P=b.useRef(p);P.current=p,b.useEffect(()=>{const ae=new AbortController;return c(null),f(null),A(null),g(1),fetch(e,{signal:ae.signal}).then(q=>q.text()).then(q=>c(yJ(q))).catch(q=>{ae.signal.aborted||f(q instanceof Error?q.message:"SVG preview failed")}),()=>ae.abort()},[e]),b.useEffect(()=>{if(!y)return;const ae=q=>{q.key==="Escape"&&v(!1)};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[y]),b.useLayoutEffect(()=>{const ae=i.current,q=ae?.querySelector("[data-svg-document] > svg");if(!ae||!q)return;let z;try{z=q.getBBox()}catch{return}if(!z.width||!z.height)return;const te=Math.max(2,Math.min(z.width,z.height)*.025);q.setAttribute("viewBox",`${z.x-te} ${z.y-te} ${z.width+2*te} ${z.height+2*te}`),q.style.width=`${p*100}%`,q.style.height=`${p*100}%`,q.style.minWidth=`${p*100}%`,q.style.minHeight=`${p*100}%`,q.style.display="block"},[a,p]);const F=b.useMemo(()=>S?bJ(t,n,S):null,[t,S,n]),R=ae=>{if(I.current){I.current=!1;return}const q=i.current,z=q?.querySelector("[data-svg-document] > svg"),te=s.current;if(!q||!z||!te)return;const pe=z.viewBox.baseVal,de=xJ(ae.clientX,ae.clientY,z.getBoundingClientRect(),pe);if(!de)return;const ke=te.getBoundingClientRect();A({...de,nearestText:vJ(z,de.x,de.y),stageX:ae.clientX-ke.left,stageY:ae.clientY-ke.top,stageXPercent:(ae.clientX-ke.left)/ke.width*100,stageYPercent:(ae.clientY-ke.top)/ke.height*100})},C=ae=>Math.max(1,Math.min(12,ae)),$=(ae,q)=>{const z=C(q),te=ae.querySelector("[data-svg-document] > svg");if(!te)return z;const pe=`${z*100}%`;return te.style.width=pe,te.style.height=pe,te.style.minWidth=pe,te.style.minHeight=pe,P.current=z,z},H=(ae,q,z,te)=>{const pe=P.current,de=ae.getBoundingClientRect(),ke=z-de.left,be=te-de.top,oe=(ae.scrollLeft+ke)/pe,he=(ae.scrollTop+be)/pe,J=$(ae,q);return ae.scrollLeft=oe*J-ke,ae.scrollTop=he*J-be,J},Y=()=>{const ae=Array.from(T.current.values());return ae.length>=2?Math.hypot(ae[0].x-ae[1].x,ae[0].y-ae[1].y):0},V=ae=>{if(ae.pointerType==="mouse"&&ae.button!==0)return;const q=i.current;q&&(T.current.set(ae.pointerId,{x:ae.clientX,y:ae.clientY}),q.setPointerCapture?.(ae.pointerId),T.current.size>=2?(L.current={kind:"pinch",startX:ae.clientX,startY:ae.clientY,startScrollLeft:q.scrollLeft,startScrollTop:q.scrollTop,startDistance:Y(),startZoom:P.current,moved:!1},I.current=!0):P.current>1&&(L.current={kind:"pan",startX:ae.clientX,startY:ae.clientY,startScrollLeft:q.scrollLeft,startScrollTop:q.scrollTop,startZoom:P.current,moved:!1}))},fe=ae=>{if(!T.current.has(ae.pointerId))return;T.current.set(ae.pointerId,{x:ae.clientX,y:ae.clientY});const q=i.current,z=L.current;if(!(!q||!z)){if(T.current.size>=2&&z.kind==="pinch"){const te=Y();if(!z.startDistance||!te)return;const pe=C(z.startZoom*te/z.startDistance);if(Math.abs(pe-P.current)<.01)return;const de=Array.from(T.current.values()),ke=(de[0].x+de[1].x)/2,be=(de[0].y+de[1].y)/2;z.moved=!0,I.current=!0,H(q,pe,ke,be),ae.preventDefault();return}if(z.kind==="pan"&&T.current.size===1){const te=ae.clientX-z.startX,pe=ae.clientY-z.startY;if(!z.moved&&Math.hypot(te,pe)<6)return;z.moved=!0,I.current=!0,q.scrollLeft=z.startScrollLeft-te,q.scrollTop=z.startScrollTop-pe,ae.preventDefault()}}},X=ae=>{const q=i.current,z=L.current,te=T.current.size===1&&!z?.moved;T.current.delete(ae.pointerId);try{q?.releasePointerCapture?.(ae.pointerId)}catch{}if(T.current.size===1&&z?.kind==="pinch"){const ke=Array.from(T.current.values())[0];L.current=q?{kind:"pan",startX:ke.x,startY:ke.y,startScrollLeft:q.scrollLeft,startScrollTop:q.scrollTop,startZoom:P.current,moved:!1}:null;return}if(T.current.size>0||(L.current=null,z?.kind==="pinch"&&g(P.current),!te||I.current))return;const pe=Date.now(),de=j.current;de&&pe-de.time<350&&Math.hypot(ae.clientX-de.x,ae.clientY-de.y)<24?(j.current=null,I.current=!0,g(ke=>ke>1?1:2.5)):j.current={time:pe,x:ae.clientX,y:ae.clientY}},ve=ae=>{if(!ae.ctrlKey&&!ae.metaKey)return;const q=i.current;if(!q)return;ae.preventDefault();const z=H(q,P.current*Math.exp(-ae.deltaY*.01),ae.clientX,ae.clientY);g(z)},we=()=>{g(1),P.current=1,i.current&&(i.current.scrollLeft=0,i.current.scrollTop=0)},ie=o.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[o.jsxs("div",{ref:s,className:"relative min-h-0 flex-1",children:[o.jsx("div",{ref:i,role:"button",tabIndex:0,onClick:R,onDoubleClick:ae=>{ae.preventDefault(),g(q=>q>1?1:2.5)},onPointerDown:V,onPointerMove:fe,onPointerUp:X,onPointerCancel:X,onWheel:ve,onScroll:()=>A(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:u?o.jsx("div",{className:"p-4 text-sm text-destructive",children:u}):a?o.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:a}}):o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),S&&o.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:S.stageX,top:S.stageY}}),S&&F&&o.jsx(Og,{anchor:{xPercent:S.stageXPercent,yPercent:S.stageYPercent},title:"引用 SVG 标注",onClick:()=>{r?.(F,`svg:${S.x.toFixed(2)}:${S.y.toFixed(2)}`),A(null)},children:"引用 SVG 标注"}),o.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[p>1.001&&o.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:ae=>{ae.stopPropagation(),we()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:o.jsx(MM,{size:14})}),o.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:ae=>{ae.stopPropagation(),v(q=>!q)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?o.jsx(ly,{size:14}):o.jsx(ay,{size:14})})]})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:S?`SVG (${S.x.toFixed(2)}, ${S.y.toFixed(2)}) · ${S.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?sa.createPortal(ie,document.body):ie}function bm(e){switch(e){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function wJ(e,t,n,r){const s=[`电子标注: ${e}`,`视图: ${bm(t)}`,`图片位置: (${n.xPercent.toFixed(1)}%,${n.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(r?.available&&r.xMm!==void 0&&r.yMm!==void 0&&(s.push(`PCB坐标: (${r.xMm.toFixed(2)},${r.yMm.toFixed(2)})mm [KiCad板坐标]`),r.layer&&s.push(`显示层: ${r.layer}`),r.nearest)){const i=[r.nearest.net?`网络 ${r.nearest.net}`:null,`对象层 ${r.nearest.layer}`,`距离 ${r.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");s.push(`最近对象: ${r.nearest.label}${i?`(${i})`:""}`)}return`"${s.join(" / ")}"`}function SJ({blobUrl:e,filePath:t,view:n,board:r,onViewChange:s,onInsertAnnotation:i,onRefresh:a,interactive3d:c}){const{t:u}=Yn(),f=b.useRef(null),p=b.useRef(null),g=b.useRef(null),[y,v]=b.useState(null),[S,A]=b.useState(!1);b.useEffect(()=>(g.current?.abort(),v(null),A(!1),()=>g.current?.abort()),[e,n]);const T=b.useMemo(()=>y?wJ(t,n,y,y.inspection):null,[t,y,n]),L=j=>{const P=f.current,F=p.current;if(!P||!F||!F.naturalWidth||!F.naturalHeight)return;const R=P.getBoundingClientRect(),C=Math.min(R.width/F.naturalWidth,R.height/F.naturalHeight),$=F.naturalWidth*C,H=F.naturalHeight*C,Y=R.left+(R.width-$)/2,V=R.top+(R.height-H)/2,fe=j.clientX-Y,X=j.clientY-V;if(fe<0||X<0||fe>$||X>H)return;const ve={xPercent:Math.max(0,Math.min(100,fe/$*100)),yPercent:Math.max(0,Math.min(100,X/H*100)),stageXPercent:(j.clientX-R.left)/R.width*100,stageYPercent:(j.clientY-R.top)/R.height*100,inspecting:r&&n!=="pcb-3d"};if(v(ve),g.current?.abort(),!ve.inspecting)return;const we=new AbortController;g.current=we,gI(t,n,ve.xPercent,ve.yPercent,we.signal).then(ie=>v(ae=>ae===ve?{...ae,inspection:ie,inspecting:!1}:ae)).catch(()=>{we.signal.aborted||v(ie=>ie===ve?{...ie,inspection:{available:!1},inspecting:!1}:ie)})},I=r?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return o.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[o.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[o.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:I.map(j=>o.jsx("button",{type:"button",onClick:()=>s(j),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${j===n?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:bm(j)},j))}),o.jsx("button",{type:"button",onClick:a,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:u("rightSidebar.edaRefresh"),"aria-label":u("rightSidebar.edaRefresh"),children:o.jsx(Us,{size:13})})]}),r&&c?o.jsx("div",{className:n==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:c}):null,r?n==="pcb-3d"?c?null:o.jsx("div",{className:"min-h-0 flex-1"}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{ref:f,role:"button",tabIndex:0,onClick:L,onKeyDown:j=>{j.key!=="Enter"&&j.key!==" "||(j.preventDefault(),v({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:u("rightSidebar.edaPickHint"),children:[o.jsx("img",{ref:p,src:e,alt:`${t} ${bm(n)}`,onLoad:()=>A(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${S?"opacity-100":"opacity-0"}`}),y&&o.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&T&&o.jsx(Og,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:u("rightSidebar.edaInsertAnnotation"),onClick:()=>{i?.(T,`eda:${n}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`),v(null)},children:u("rightSidebar.edaInsertAnnotation")})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?u("rightSidebar.edaInspecting"):y.inspection?.available?u("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??u("rightSidebar.edaNoNearbyObject")}):u("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):u("rightSidebar.edaPickHint")})})]}):o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:o.jsx(CT,{blobUrl:e,filePath:t,viewLabel:bm(n),onInsertAnnotation:i})})]})}function AJ(e){const t=[];let n=[],r="",s=!1;for(let i=0;i<e.length;i+=1){const a=e[i];s?a==='"'&&e[i+1]==='"'?(r+='"',i+=1):a==='"'?s=!1:r+=a:a==='"'?s=!0:a===","?(n.push(r),r=""):a===`
178
- `?(n.push(r.replace(/\r$/,"")),t.push(n),n=[],r=""):r+=a}return(r||n.length>0)&&(n.push(r.replace(/\r$/,"")),t.push(n)),t}function TJ(e,t,n,r,s){const i=t[s]||`第${s+1}列`,a=n[s]??"",c=t.map((u,f)=>`${u||`第${f+1}列`}=${n[f]??""}`).join(";");return`"表格标注: ${e} / 数据行: ${r+1} / 列: ${i} / 值: ${a} / 记录: ${c}"`}function CJ({content:e,filePath:t,onInsertAnnotation:n}){const{t:r}=Yn(),s=b.useMemo(()=>AJ(e),[e]),i=s[0]??[],a=s.slice(1),c=b.useRef(null),[u,f]=b.useState(null),p=u?a[u.row]:null,g=u&&p?TJ(t,i,p,u.row+1,u.column):null;return o.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[o.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[o.jsx("div",{className:"h-full overflow-auto",children:o.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),i.map((y,v)=>o.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:y||r("rightSidebar.csvUnnamedColumn",{index:v+1})},`${y}:${v}`))]})}),o.jsx("tbody",{children:a.map((y,v)=>o.jsxs("tr",{className:"hover:bg-surface-2",children:[o.jsx("th",{className:"sticky left-0 z-10 border-b border-r border-border/15 bg-surface px-2 py-2 text-right text-[10px] font-normal text-muted-foreground",children:v+1}),i.map((S,A)=>{const T=u?.row===v&&u.column===A;return o.jsx("td",{className:`border-b border-r border-border/15 p-0 ${T?"bg-primary/15":""}`,children:o.jsx("button",{type:"button",onClick:L=>{const I=c.current?.getBoundingClientRect(),j=L.currentTarget.getBoundingClientRect();if(!I?.width||!I.height)return;const P=L.clientX||j.left+j.width/2,F=L.clientY||j.top+j.height/2;f({row:v,column:A,xPercent:(P-I.left)/I.width*100,yPercent:(F-I.top)/I.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:y[A]||" "})},`cell:${v}:${A}`)})]},`row:${v}`))})]})}),u&&g&&o.jsx(Og,{anchor:{xPercent:u.xPercent,yPercent:u.yPercent},title:r("rightSidebar.csvInsertAnnotation"),onClick:()=>{n?.(g,`csv:${t}:${u.row+1}:${u.column+1}`),f(null)},children:r("rightSidebar.csvInsertAnnotation")})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:u&&p?r("rightSidebar.csvSelectedCell",{row:u.row+1,column:i[u.column]||u.column+1}):r("rightSidebar.csvPickHint",{rows:a.length,columns:i.length})})})]})}function Dd(e,t){let n=e;for(const r of t){if(!n||typeof n!="object")return;n=n[r]}return n}function kJ(e,t){const n=JSON.parse(e),r=Dd(n,["meta","version"]);if(t)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(r??"未知")},{label:"活动层编号",value:String(Dd(n,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Dd(n,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Dd(n,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const s=Dd(n,["net_settings","classes"]),i=Array.isArray(s)?s.find(c=>c&&typeof c=="object"&&c.name==="Default"):void 0,a=Dd(n,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(r??"未知")},{label:"网络类数量",value:String(Array.isArray(s)?s.length:0)},{label:"默认间距",value:i?.clearance!==void 0?`${i.clearance} mm`:"未设置"},{label:"默认线宽",value:i?.track_width!==void 0?`${i.track_width} mm`:"未设置"},{label:"默认过孔",value:i?.via_diameter!==void 0?`${i.via_diameter} / ${i.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(a)?a.length:0)}]}function _J(e,t){return`"KiCad项目标注: ${e} / 项: ${t.label} / 值: ${t.value}"`}function LJ({content:e,filePath:t,localState:n,onInsertAnnotation:r}){const{t:s}=Yn(),i=b.useRef(null),[a,c]=b.useState(null),u=b.useMemo(()=>{try{return{items:kJ(e,n),error:null}}catch(p){return{items:[],error:p instanceof Error?p.message:String(p)}}},[e,n]),f=a===null?null:u.items[a.index];return u.error?o.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:e}):o.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[n&&o.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:s("rightSidebar.kicadLocalStateNotice")}),o.jsxs("div",{ref:i,className:"relative min-h-0 flex-1",children:[o.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[o.jsx("div",{className:"divide-y divide-border/15",children:u.items.map((p,g)=>o.jsxs("button",{type:"button",onClick:y=>{const v=i.current?.getBoundingClientRect(),S=y.currentTarget.getBoundingClientRect();if(!v?.width||!v.height)return;const A=y.clientX||S.left+S.width/2,T=y.clientY||S.top+S.height/2;c({index:g,xPercent:(A-v.left)/v.width*100,yPercent:(T-v.top)/v.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${a?.index===g?"bg-primary/10":""}`,children:[o.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:p.label}),o.jsx("span",{className:"break-words text-xs text-foreground",children:p.value})]},p.label))}),o.jsxs("details",{className:"mt-3 border-t border-border/15 pt-3",children:[o.jsx("summary",{className:"cursor-pointer text-xs font-semibold text-muted-foreground",children:s("rightSidebar.kicadShowRawJson")}),o.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:e})]})]}),f&&a&&o.jsx(Og,{anchor:{xPercent:a.xPercent,yPercent:a.yPercent},title:s("rightSidebar.kicadInsertSetting"),onClick:()=>{r?.(_J(t,f),`kicad-project:${t}:${f.label}`),c(null)},children:s("rightSidebar.kicadInsertSetting")})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:f?`${f.label}: ${f.value}`:s("rightSidebar.kicadProjectPickHint")})})]})}const EJ=b.forwardRef(function({src:t,title:n,exitFullscreenLabel:r,onFullscreenChange:s},i){const a=b.useRef(null),[c,u]=b.useState(!1),[f,p]=b.useState(!1),g=c||f;b.useEffect(()=>{s?.(g)},[g,s]),b.useEffect(()=>{const S=()=>{u(document.fullscreenElement===a.current)};return document.addEventListener("fullscreenchange",S),()=>document.removeEventListener("fullscreenchange",S)},[]),b.useEffect(()=>{if(!f)return;const S=A=>{A.key==="Escape"&&p(!1)};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[f]);const y=b.useCallback(async()=>{const S=a.current;if(S){if(f){p(!1);return}if(document.fullscreenElement===S){await document.exitFullscreen();return}if(S.requestFullscreen&&document.fullscreenEnabled!==!1)try{await S.requestFullscreen();return}catch{}p(!0)}},[f]);b.useImperativeHandle(i,()=>({toggleFullscreen:y}),[y]);const v=o.jsxs("div",{ref:a,"data-html-preview-frame":!0,className:g?"fixed inset-0 z-modal-panel flex min-h-0 flex-col overflow-hidden bg-surface pt-[env(safe-area-inset-top,0px)] text-foreground":"flex h-full min-h-0 flex-col overflow-hidden bg-surface",children:[g&&o.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/15 bg-[var(--chrome-bg)] px-3",children:[o.jsx("span",{className:"min-w-0 truncate text-[12px] font-semibold",children:n}),o.jsx("button",{type:"button",onClick:()=>{y()},"aria-label":r,title:`${r} (Esc)`,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:o.jsx(ly,{size:15})})]}),o.jsx("iframe",{src:t,title:n,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return f?sa.createPortal(v,document.body):v}),kT="termdock-file-search-match",j2="termdock-file-search-current";function IJ(e){const t=e.metaKey||e.ctrlKey,n=e.key.toLocaleLowerCase();return t&&n==="f"?"open":t&&n==="g"||e.key==="F3"?e.shiftKey?"previous":"next":e.key==="Escape"?"close":null}function RJ(e){return e.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function NJ(e,t){const n=t.trim().toLocaleLowerCase();if(!n)return[];const r=[];let s="",i=null;const a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let p=a.nextNode();p;p=a.nextNode()){if(!(p instanceof Text)||!p.data)continue;const g=RJ(p);if(!g)continue;i&&i!==g&&(s+=`
179
- `);const y=s.length;s+=p.data,r.push({node:p,start:y,end:s.length,group:g}),i=g}const c=s.toLocaleLowerCase(),u=[];let f=0;for(;f<=c.length-n.length;){const p=c.indexOf(n,f);if(p<0)break;const g=p+n.length,y=r.find(S=>S.start<=p&&S.end>p),v=r.find(S=>S.start<g&&S.end>=g);if(y&&v&&y.group===v.group){const S=document.createRange();S.setStart(y.node,p-y.start),S.setEnd(v.node,g-v.start),u.push(S)}f=p+Math.max(n.length,1)}return u}function _T(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function $p(){const e=_T();e?.delete(kT),e?.delete(j2)}function k4(e,t){const n=_T();if(!n||typeof Highlight>"u")return;n.set(kT,new Highlight(...e));const r=e[t];r?n.set(j2,new Highlight(r)):n.delete(j2)}function _4(e){e?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}const av="termdock:right-sidebar:file-tree-scroll:v1",lv="termdock:right-sidebar:file-preview-reading-state:v1",Ef="termdock:right-sidebar:file-tree-width:v1",LT="termdock:right-sidebar:markdown-view-mode:v1",ET="termdock:right-sidebar:diff-change-list-mode:v1",IT="termdock:right-sidebar:diff-wrap:v1",RT="termdock:diff-viewer:view-type:v1",NT="termdock:right-sidebar:file-search-mode:v1",Xx="termdock:right-sidebar:collapsed-git-repo-groups:v1",L4="termdock:right-sidebar:collapsed-diff-directories:v1",Zx="termdock:right-sidebar:branch-audit-module-open:v1",MT="termdock:right-sidebar:branch-audit-module:v1",MJ=150,DT="termdock:right-sidebar:active-git-repo:v1",E4="termdock:right-sidebar:context-draft-enabled:v1",I4="termdock:right-sidebar:context-draft-collapsed:v1",R4="termdock:right-sidebar:context-draft-auto-collapse:v1",Jx="termdock:right-sidebar:context-draft-text:v1",DJ=300,jJ=20,PJ=120,BJ=250,FJ=250,OJ=120,QJ=700,eb=600,N4=[2e3,5e3,15e3,3e4],$J=320,HJ=500,UJ=20,zJ=12e3,P2=300,M4=240,GJ=560,jT="border-r px-2 py-1.5 sm:px-3 sm:py-2",rg="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",PT=`${jT} border-b border-border/15 font-semibold last:border-r-0`,BT=`${jT} border-border/10 align-top text-muted-foreground last:border-r-0`,cv="termdock-file-preview-horizontal-scroll",D4=b.lazy(()=>g0(()=>import("./ModelPreview-DGvy0ViD.js"),__vite__mapDeps([2,3,1,4]))),FT=`${cv} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function WJ(e,t,n){return e&&!t?"unified":n}const VJ=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function qJ(e){return e==="preview"||e==="source"}function YJ(e){return e==="list"||e==="tree"||e==="ai"}function j4(){return Or(LT,qJ)??"preview"}function KJ(){return Or(ET,YJ)??"tree"}function If(e){return typeof e=="boolean"}function XJ(e){return typeof e=="string"}function ZJ(){return Or(IT,If)??!0}function JJ(e){return e==="unified"||e==="split"}function eee(){return Or(RT,JJ)??"unified"}function tee(e){return e==="name"||e==="content"||e==="regex"}function nee(){return Or(NT,tee)??"name"}function OT(e){return e.repositories??(e.context?.root?[{id:e.context.root,root:e.context.root,relativeRoot:".",name:bo(e.context.root)||e.context.root,depth:0,nested:!1,available:e.available,files:e.files,context:e.context,error:e.error}]:[])}function ree(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.values(e).every(t=>t===null||typeof t=="string")}function QT(){return Or(DT,ree)??{}}function P4(e){if(!e)return;const t=QT();return Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0}function tb(e,t){e&&$n(DT,{...QT(),[e]:t})}function see(e,t){if(!t)return null;const n=new Set((e.repoFilters??[]).map(r=>r.root));return n.has(t)?t:n.size>0?null:(e.repositories??[]).some(r=>r.root===t)?t:null}function B2(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function B4(e){const t=Or(e,B2);return t?new Set(t):new Set}function nb(e,t){$n(e,[...t])}function iee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.filePath=="string"&&typeof t.hunkHeader=="string"&&typeof t.hunkIndex=="number"&&typeof t.fingerprint=="string"&&typeof t.additions=="number"&&typeof t.deletions=="number"&&typeof t.diff=="string"&&(t.oldPath===void 0||t.oldPath===null||typeof t.oldPath=="string")&&(t.newPath===void 0||t.newPath===null||typeof t.newPath=="string")&&(t.source===void 0||t.source==="committed"||t.source==="uncommitted"||t.source==="unknown")&&(t.commit===void 0||t.commit===null||typeof t.commit=="string")}function oee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.available=="boolean"&&(t.repoRoot===void 0||typeof t.repoRoot=="string")&&(t.workspaceRoot===void 0||typeof t.workspaceRoot=="string")&&(t.baseRef===void 0||typeof t.baseRef=="string")&&(t.baseBranch===void 0||typeof t.baseBranch=="string")&&(t.currentBranch===void 0||t.currentBranch===null||typeof t.currentBranch=="string")&&(t.headRef===void 0||t.headRef===null||typeof t.headRef=="string")&&(t.diffFingerprint===void 0||typeof t.diffFingerprint=="string")&&(t.stat===void 0||typeof t.stat=="string")&&(t.files===void 0||B2(t.files))&&(t.hunks===void 0||Array.isArray(t.hunks)&&t.hunks.every(iee))&&(t.commits===void 0||B2(t.commits))&&(t.commitCount===void 0||typeof t.commitCount=="number")&&(t.diff===void 0||typeof t.diff=="string")&&(t.truncated===void 0||typeof t.truncated=="boolean")&&(t.error===void 0||typeof t.error=="string")}function aee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.key=="string"&&oee(t.diff)&&typeof t.repoLabel=="string"&&typeof t.createdAt=="number"}function lee(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.values(e).every(t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return Array.isArray(n.selectedRepoRoots)&&n.selectedRepoRoots.every(r=>typeof r=="string")&&!!n.repoTargetBranches&&typeof n.repoTargetBranches=="object"&&!Array.isArray(n.repoTargetBranches)&&Object.values(n.repoTargetBranches).every(r=>typeof r=="string")&&(n.repoBaseBranches===void 0||!!n.repoBaseBranches&&typeof n.repoBaseBranches=="object"&&!Array.isArray(n.repoBaseBranches)&&Object.values(n.repoBaseBranches).every(r=>typeof r=="string"))&&(n.previewEntries===void 0||Array.isArray(n.previewEntries)&&n.previewEntries.every(aee))&&(n.selectedPreviewKey===void 0||n.selectedPreviewKey===null||typeof n.selectedPreviewKey=="string")&&(n.selectedPreviewFileKey===void 0||n.selectedPreviewFileKey===null||typeof n.selectedPreviewFileKey=="string")&&(n.previewDetailOpen===void 0||typeof n.previewDetailOpen=="boolean")&&(n.previewScrollTops===void 0||!!n.previewScrollTops&&typeof n.previewScrollTops=="object"&&!Array.isArray(n.previewScrollTops)&&Object.values(n.previewScrollTops).every(r=>typeof r=="number"))&&(n.previewMobileSlideIndex===void 0||typeof n.previewMobileSlideIndex=="number")&&(n.includeUncommitted===void 0||typeof n.includeUncommitted=="boolean")&&typeof n.updatedAt=="number"})}function F4(){return Or(MT,lee)??{}}function O4(e){return[e.repoRoot,e.baseRef,e.branchName??"",e.headRef??"",e.diffFingerprint??""].join("\0")}function Q4(e){const t=e?.trim()??"",n=t.indexOf("/");return n>=0?t.slice(n+1):t}function $T(e,t){const n=e?.trim(),r=t?.trim();return!n||!r?!1:n===r||Q4(n)===Q4(r)}function $4(e){const t=e?.branch??null;return[e?.upstream,...e?.remoteBranches??[],...e?.branches??[]].find(r=>r&&!$T(r,t))??""}function F2(e,t){const n=Math.max(M4,t-320),r=Math.min(GJ,n);return Math.min(r,Math.max(M4,e))}function cee(e){return typeof e=="number"&&Number.isFinite(e)}function uee(e){return F2(Or(Ef,cee)??P2,e)}function HT(e){const t=e.split(/[\\/]/).pop()??e,n=t.lastIndexOf(".");return n>=0?t.slice(n).toLowerCase():""}function mf(e){return VJ.has(HT(e))}function UT(e){const t=e.trim().replace(/\s+/g,"");return/^-{3,}$/.test(t)||/^\*{3,}$/.test(t)||/^_{3,}$/.test(t)}function O2(e){const t=e.trim();return/^#{1,6}\s+/.test(t)||UT(e)||/^>\s?/.test(t)||/^(```|~~~)/.test(t)||/^(?:[-+*]|\d+[.)])\s+/.test(t)}function dee(e){const t=e.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(t)||!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!/[<>]/.test(t)?t:null}const zT=b.createContext(null);function ym(e){return e.trim().replace(/\s+/g," ").toLowerCase()}function GT(e){return e.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function WT(e){return e.replace(/\s+#+\s*$/,"").trim()}function Q2(e,t){const r=GT(e).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",s=t.headingSlugCounts.get(r)??0;return t.headingSlugCounts.set(r,s+1),s===0?r:`${r}-${s}`}function H4(e){return GT(e)||e.trim()}function sg(e){const t=e.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!t)return null;const n=H2(t[2]);return n?{id:ym(t[1]),definition:{href:n.href,title:n.title}}:null}function fee(e){const t=new Map;for(const n of e){const r=sg(n);r&&t.set(r.id,r.definition)}return t}function VT(e){return e.trim().toLowerCase()}function qT(e){const t=e.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return t?{id:VT(t[1]),text:t[2]}:null}function hee(e){const t=new Map;let n=null;for(const r of e){const s=qT(r);if(s){n=s.id,t.set(s.id,{id:s.id,text:s.text,index:t.size+1});continue}if(n&&/^\s{4,}\S/.test(r)){const i=t.get(n);i&&(i.text=`${i.text} ${r.trim()}`);continue}r.trim()&&(n=null)}return t}function pee(e){const t=new Set;let n=!1;return e.forEach((r,s)=>{if(qT(r)){t.add(s),n=!0;return}if(n&&/^\s{4,}\S/.test(r)){t.add(s);return}r.trim()&&(n=!1)}),t}function mee(e){const t=[...e];let n=0;const r=e[0]?.trim();if(r==="---"||r==="+++"){for(t[0]="",n=1;n<e.length&&e[n].trim()!==r;)t[n]="",n+=1;n<e.length&&(t[n]="",n+=1)}for(;n<e.length;){const s=e[n].trim();if(s.startsWith("<!--")){if(t[n]="",!s.includes("-->")){for(n+=1;n<e.length&&!e[n].includes("-->");)t[n]="",n+=1;n<e.length&&(t[n]="")}n+=1;continue}n+=1}return t}function YT(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n<=0?n===0?"/":"":t.slice(0,n)}function Uf(e){const t=e.split(/[?#]/,1)[0],n=t.startsWith("/"),r=[];for(const i of t.split("/"))if(!(!i||i===".")){if(i===".."){r.length>0&&r.pop();continue}r.push(i)}return`${n?"/":""}${r.join("/")}`||(n?"/":".")}function gee(e,t,n){const r=e.trim();if(!r||/^(?:https?:|mailto:|javascript:|data:|#)/i.test(r)||/^[a-z][a-z0-9+.-]*:/i.test(r))return null;const s=r.indexOf("#"),i=s>=0?r.slice(0,s):r,a=s>=0?r.slice(s+1):"",c=i.split("?",1)[0];if(!c)return null;let u,f=null;try{u=decodeURIComponent(c),f=a?decodeURIComponent(a):null}catch{return null}const p=n?Uf(n):null;let g;if(u.startsWith("/")){const y=p&&(u===p||u.startsWith(`${p}/`));g=Uf(p&&!y?`${p}/${u.slice(1)}`:u)}else{if(!t)return null;g=Uf(`${YT(t)}/${u}`)}return p&&g!==p&&!g.startsWith(`${p}/`)?null:{path:g,fragment:f,directory:/\/$/.test(c)}}function xee(e,t,n){const r=e.trim();if(!r||/^(?:javascript|data):/i.test(r))return null;if(/^https?:\/\//i.test(r))return r;if(!ey(r.split(/[?#]/,1)[0]))return null;let s;if(r.startsWith("/")){const i=n&&(r===n||r.startsWith(`${n}/`));s=Uf(n&&!i?`${n}/${r.slice(1)}`:r)}else{if(!t)return null;s=Uf(`${YT(t)}/${r}`)}return`/api/terminal/fs/blob?path=${encodeURIComponent(s)}`}const $2=128,bee=360,rb=480;function uv(e){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(e))}catch{return!1}}function yee(e,t,n,r){if(!t||!n)return null;let s,i;return uv(e)?(i=Math.min(Math.max(n,$2),bee),s=t*i/n):(s=t,i=n),r>0&&s>r&&(i=i*r/s,s=r),i>rb&&(s=s*rb/i,i=rb),{width:Math.max(1,Math.round(s)),height:Math.max(1,Math.round(i))}}function vee(e){if(!e.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(e.slice(e.indexOf("?"))).get("path")}catch{return null}}function KT(e){const t=vee(e),n=ft(r=>t?(r.fileChangeVersions.get(t)??0)+r.fileWatchEpoch:0);return t&&n>0?`${e}&v=${n}`:e}function wee({src:e,alt:t,title:n}){const r=uv(e),s=KT(e),i=b.useRef(null),[a,c]=b.useState(!1),[u,f]=b.useState(0),[p,g]=b.useState({status:"loading"}),[y,v]=b.useState(null);b.useLayoutEffect(()=>{const T=i.current,L=T?.parentElement?.parentElement??T?.parentElement;if(!L)return;const I=()=>f(L.clientWidth);if(I(),typeof ResizeObserver>"u")return;const j=new ResizeObserver(I);return j.observe(L),()=>j.disconnect()},[]),b.useEffect(()=>{if(a)return;const T=i.current;if(!T||typeof IntersectionObserver>"u"){c(!0);return}const L=new IntersectionObserver(I=>{I.some(j=>j.isIntersecting)&&(c(!0),L.disconnect())},{rootMargin:"400px"});return L.observe(T),()=>L.disconnect()},[a]),b.useEffect(()=>{if(!a)return;const T=new AbortController;let L=null;g({status:"loading"});const I=window.setTimeout(()=>{T.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return fetch(s,{signal:T.signal}).then(async j=>{if(!j.ok)throw new Error(`HTTP ${j.status}`);const P=Number(j.headers.get("X-Image-Width"))||0,F=Number(j.headers.get("X-Image-Height"))||0;return{blob:await j.blob(),width:P,height:F}}).then(({blob:j,width:P,height:F})=>{T.signal.aborted||(L=URL.createObjectURL(j),P>0&&F>0&&v({width:P,height:F}),g({status:"ready",objectUrl:L}))}).catch(()=>{const j=T.signal.reason;T.signal.aborted&&!(j instanceof DOMException&&j.name==="TimeoutError")||g({status:"fallback"})}).finally(()=>{window.clearTimeout(I)}),()=>{window.clearTimeout(I),T.abort(),L&&URL.revokeObjectURL(L)}},[a,s]);const S=yee(e,y?.width??0,y?.height??0,u),A=S??{width:$2*2,height:$2};return o.jsx("div",{ref:i,className:"block max-w-full",style:S?{width:S.width,height:S.height}:void 0,children:p.status==="ready"?o.jsx("img",{src:p.objectUrl,alt:t,title:n,decoding:"async",className:`${r?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:S?{width:S.width,height:S.height}:void 0,onLoad:T=>{if(y)return;const L=T.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&v({width:L.naturalWidth,height:L.naturalHeight})}}):p.status==="fallback"?o.jsx("img",{src:s,alt:t,title:n,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:S?{width:S.width,height:S.height}:void 0,onLoad:T=>{if(y)return;const L=T.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&v({width:L.naturalWidth,height:L.naturalHeight})}}):o.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:A.width,height:A.height},children:o.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:t||"…"})})})}function sb(e,t,n,r,s){const i=xee(n,s.markdownFilePath,s.rootPath);if(!i)return`![${t}](${n})`;const a=s.images.length;s.images.push({kind:"image",src:i,alt:t,title:r});const c=o.jsx(wee,{src:i,alt:t,title:r});return s.onImageOpen?o.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:r||t||"Open image",onClick:u=>{u.stopPropagation(),s.onImageOpen?.(a)},children:c},e):o.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c},e)}function ib(e){let t=e,n="";for(;/[.,;:!?)]$/.test(t);)n=`${t.slice(-1)}${n}`,t=t.slice(0,-1);return{linkText:t,suffix:n}}function U4(e){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(e)}function H2(e){const t=e.trim(),n=t.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(n)return{href:n[1],title:n[2]??n[3]??n[4]};const r=t.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return r?{href:r[1],title:r[2]??r[3]??r[4]}:null}const XT="",See=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Aee(e){return e.replace(See,(t,n)=>`${XT}${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function z4(e){return e.replace(new RegExp(`${XT}([0-9a-f]{4})`,"g"),(t,n)=>String.fromCharCode(Number.parseInt(n,16))).replace(/\\([()])/g,"$1")}function Tee(e){const t=e.replace(/[\r\n]+/g," ");return/^ .+ $/.test(t)&&/[^ ]/.test(t.slice(1,-1))?t.slice(1,-1):t}const ZT={ALLOWED_TAGS:["a","abbr","b","blockquote","br","code","del","details","div","em","i","kbd","li","mark","ol","p","pre","s","span","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],ALLOWED_ATTR:["href","title","class","id","colspan","rowspan"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0};let Hp=null;function JT(){return Hp||(Hp=g0(()=>import("./purify.es-CC4Brkr_.js"),[]).then(e=>e.default??e).catch(e=>{throw Hp=null,e})),Hp}function eC({html:e}){const{t}=Yn(),[n,r]=b.useState(null);return b.useEffect(()=>{let s=!1;return r(null),JT().then(i=>{s||r(i.sanitize(e,ZT))}).catch(()=>{s||r("")}),()=>{s=!0}},[e]),n===null?o.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:t("rightSidebar.renderingHtml")}):n?o.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:n}}):null}function Cee({html:e}){const[t,n]=b.useState(null);return b.useEffect(()=>{let r=!1;return n(null),JT().then(s=>{r||n(s.sanitize(e,ZT))}).catch(()=>{r||n("")}),()=>{r=!0}},[e]),t===null?null:t?o.jsx("span",{dangerouslySetInnerHTML:{__html:t}}):e}function tC(e){const t=e.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!t)return null;const n=t[1].toLowerCase();return{tag:n,selfContained:new RegExp(`</${n}>`,"i").test(e)}}let Up=null;function kee(){return Up||(Up=Promise.all([g0(()=>import("./katex-DnlPpQZa.js"),[]),g0(()=>Promise.resolve({}),__vite__mapDeps([5]))]).then(([e])=>e.default??e).catch(e=>{throw Up=null,e})),Up}function lh({tex:e,display:t=!1}){const[n,r]=b.useState(null),[s,i]=b.useState(!1);if(b.useEffect(()=>{let c=!1;return r(null),i(!1),kee().then(u=>{c||r(u.renderToString(e,{displayMode:t,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{c||i(!0)}),()=>{c=!0}},[t,e]),s)return o.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:t?`$$${e}$$`:`$${e}$`});if(!n)return o.jsx("span",{className:"text-muted-foreground/70",children:t?"Rendering formula...":e});const a=t?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return o.jsx("span",{className:a,dangerouslySetInnerHTML:{__html:n}})}function _ee(e,t,n){if(/^<br\s*\/?>$/i.test(e))return o.jsx("br",{},t);const r=e.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!r)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(e)?o.jsx(Cee,{html:e},t):null;const s=r[1].toLowerCase(),i=Ci(r[2],`${t}-${s}`,!0,n);return s==="kbd"?o.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:i},t):s==="mark"?o.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:i},t):s==="sub"?o.jsx("sub",{children:i},t):o.jsx("sup",{children:i},t)}function Ci(e,t,n=!0,r){const s=Aee(e),i=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,a=[];let c=0,u;for(;(u=i.exec(s))!==null;){u.index>c&&a.push(z4(s.slice(c,u.index)));const f=u[0],p=`${t}-${u.index}`,g=f.startsWith("<")?_ee(f,p,r):null;if(g)a.push(g);else if(f.startsWith("\\(")&&f.endsWith("\\)"))a.push(o.jsx(lh,{tex:f.slice(2,-2)},p));else if(f.startsWith("$")&&f.endsWith("$"))a.push(o.jsx(lh,{tex:f.slice(1,-1)},p));else if(f.startsWith("`")){const y=f.match(/^`+/)?.[0].length??1;a.push(o.jsx("code",{className:`${n?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:Tee(f.slice(y,-y))},p))}else if(f.startsWith("~~"))a.push(o.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:Ci(f.slice(2,-2),`${p}-del`,n,r)},p));else if(f.startsWith("**")||f.startsWith("__"))a.push(o.jsx("strong",{className:"font-semibold text-foreground",children:Ci(f.slice(2,-2),`${p}-strong`,n,r)},p));else if(f.startsWith("*")||f.startsWith("_"))a.push(o.jsx("em",{className:"italic",children:Ci(f.slice(1,-1),`${p}-em`,n,r)},p));else if(f.startsWith("![")){const y=f.match(/^!\[([^\]]*)\]\((.*)\)$/),v=f.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),S=f.match(/^!\[([^\]]+)\]$/);if(y){const A=H2(y[2]);a.push(A?sb(p,y[1],A.href,A.title,r):f)}else if(v){const A=v[2]||v[1],T=r.referenceDefinitions.get(ym(A));a.push(T?sb(p,v[1],T.href,T.title,r):f)}else if(S){const A=r.referenceDefinitions.get(ym(S[1]));a.push(A?sb(p,S[1],A.href,A.title,r):f)}else a.push(f)}else if(f.startsWith("[^")){const y=VT(f.slice(2,-1)),v=r.footnoteDefinitions.get(y);a.push(v?o.jsx("sup",{id:`fnref-${v.id}`,title:v.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:o.jsx("a",{href:`#fn-${v.id}`,className:"text-primary no-underline",children:v.index})},p):f)}else if(f.startsWith("<http")){const y=f.slice(1,-1);a.push(o.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p))}else if(f.startsWith("<")&&f.endsWith(">")&&U4(f.slice(1,-1))){const y=f.slice(1,-1);a.push(o.jsx("a",{href:`mailto:${y}`,className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p))}else if(U4(ib(f).linkText)){const{linkText:y,suffix:v}=ib(f);a.push(o.jsx("a",{href:`mailto:${y}`,className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p)),v&&a.push(v)}else if(f.startsWith("http")||f.startsWith("www.")){const{linkText:y,suffix:v}=ib(f),S=y.startsWith("www.")?`https://${y}`:y;a.push(o.jsx("a",{href:S,target:"_blank",rel:"noreferrer",className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p)),v&&a.push(v)}else{const y=f.match(/^\[([^\]]+)\]\((.*)\)$/),v=f.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),S=f.match(/^\[([^\]]+)\]$/),A=v?v[2]||v[1]:S?.[1]??null,T=A?r.referenceDefinitions.get(ym(A)):null,L=y?H2(y[2]):null,I=L?.href??T?.href??null,j=I?dee(I):null,P=y?.[1]??v?.[1]??S?.[1]??"";a.push(j?o.jsx("a",{href:j,title:L?.title??T?.title,target:"_blank",rel:"noreferrer",className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:Ci(P,`${p}-link`,n,r)},p):f)}c=i.lastIndex}return c<s.length&&a.push(z4(s.slice(c))),a.length>0?a:[e]}function nC(e){return/(?: {2,}|\\)$/.test(e)}function rC(e){return e.replace(/(?: {2,}|\\)$/,"")}function ig(e){return/^(?: {4}|\t)/.test(e)}function sC(e){return e.startsWith(" ")?e.slice(1):e.replace(/^ {4}/,"")}function iC(e,t,n){const r=[];return e.forEach((s,i)=>{const a=nC(s);r.push(...Ci(rC(s),`${t}-${i}`,!0,n)),i<e.length-1&&r.push(a?o.jsx("br",{},`${t}-${i}-br`):" ")}),r}function U2(e,t,n){const r=[],s=[];return e.forEach((i,a)=>{s.push(nC(i)),r.push(Ci(rC(i),`${t}-${a}`,!0,n))}),{perLine:r,hardBreaks:s}}function z2(e,t,n,r,s){const i=[];return e.forEach((a,c)=>{const u=n[c]??0,f=!!(s&&u>=s.start&&u<=s.end);i.push(o.jsx("span",{"data-md-ref-start":u,"data-md-ref-end":u,"data-selected":f?"true":void 0,children:a},`${r}-ref-${c}`)),c<e.length-1&&i.push(t[c]?o.jsx("br",{},`${r}-${c}-br`):" ")}),i}function ch(e){const t=e.trim().replace(/^\|/,"").replace(/\|$/,""),n=[];let r="",s=!1,i=0,a=0;for(let c=0;c<t.length;c+=1){const u=t[c];if(s){r+=u,s=!1;continue}if(u==="\\"){s=!0;continue}if(u==="`"){const f=c;for(;c+1<t.length&&t[c+1]==="`";)c+=1;const p=c-f+1;r+="`".repeat(p),i===0?i=p:i===p&&(i=0);continue}if(i===0&&u==="["?a+=1:i===0&&u==="]"&&a>0&&(a-=1),u==="|"&&i===0&&a===0){n.push(r.trim()),r="";continue}r+=u}return s&&(r+="\\"),n.push(r.trim()),n}function oC(e){return ch(e).map(t=>/^:-+:$/.test(t)?"center":/^-+:$/.test(t)?"right":/^:-+$/.test(t)?"left":null)}function og(e){return e==="center"?"text-center":e==="right"?"text-right":"text-left"}function ag(e){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(e.trim())}function Lee(e,t){return e>96||e>44&&t>.35}function dv(e){return(e.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function fv(e){const t=e.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!t)return null;const n=/^\d+[.)]$/.test(t[1]);return{ordered:n,start:n?Number.parseInt(t[1],10):void 0,content:t[2]}}function aC(e,t,n,r,s,i=new Set){const a=[],c=[];let u=t;for(;u<e.length;){const f=e[u];if(s&&(sg(f)||i.has(u))){u+=1;continue}const p=fv(f),g=dv(f);if(!p){if(g>n&&c.length>0){([...c].reverse().find(A=>A.indent<g)?.item??c[c.length-1].item).paragraphs.push(f.trim());for(const A of c)A.item.lineEnd=u+1;u+=1;continue}break}if(g<n||g===n&&p.ordered!==r)break;const y={content:p.content,ordered:p.ordered,start:p.start,children:[],paragraphs:[],lineStart:u+1,lineEnd:u+1};for(;c.length>0&&c[c.length-1].indent>=g;)c.pop();const v=c[c.length-1]?.item??null;v?v.children.push(y):a.push(y),c.push({indent:g,item:y});for(const S of c)S.item.lineEnd=u+1;u+=1}return{items:a,nextIndex:u}}function hv(e,t,n,r=0){return e.map((s,i)=>{const a=s.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${i}`,taskItem:!!a,refStart:s.lineStart+r,refEnd:s.lineEnd+r,content:o.jsxs(o.Fragment,{children:[a?o.jsx("input",{type:"checkbox",checked:a[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,Ci(a?.[2]??s.content,`li-${t}-${i}`,!0,n),s.paragraphs.length>0&&o.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:s.paragraphs.map((c,u)=>o.jsx("p",{children:Ci(c,`li-${t}-${i}-p-${u}`,!0,n)},`paragraph-${u}`))})]}),groups:Eee(s.children,`${t}-${i}`,n,r)}})}function Eee(e,t,n,r=0){const s=[];for(const i of e){const a=s[s.length-1];a&&a.ordered===i.ordered?a.items.push(i):s.push({ordered:i.ordered,items:[i]})}return s.map((i,a)=>({ordered:i.ordered,start:i.ordered?i.items[0]?.start:void 0,items:hv(i.items,`${t}-g${a}`,n,r)}))}function pv(e,t){return e.map(n=>{const r=!!(t&&n.refStart<=t.end&&n.refEnd>=t.start);return o.jsxs("li",{className:n.taskItem?"list-none":void 0,"data-md-ref-start":n.refStart,"data-md-ref-end":n.refEnd,"data-selected":r?"true":void 0,children:[n.content,n.groups.length>0&&Iee(n.groups,t)]},n.key)})}function Iee(e,t){return e.map((n,r)=>{const s=n.ordered?"ol":"ul";return o.jsx(s,{start:n.start,className:`${n.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:pv(n.items,t)},`nested-${r}`)})}function Ree(e){const t=Array.from(e.footnoteDefinitions.values()).sort((n,r)=>n.index-r.index);return t.length===0?null:o.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[o.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:e.footnotesLabel}),o.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:t.map(n=>o.jsxs("li",{id:`fn-${n.id}`,children:[Ci(n.text,`footnote-${n.id}`,!0,e)," ",o.jsx("a",{href:`#fnref-${n.id}`,className:"text-primary no-underline","aria-label":e.backToFootnoteLabel(n.index),children:"↩"})]},n.id))})]})}function Nee(e,t,n,r){const s=[];let i=0;const a=c=>r?.[c]??c+1;for(;i<e.length;){const c=e[i],u=c.trim();if(!u){i+=1;continue}if(/^<details>\s*$/i.test(u)){const L=i;let I="Details";const j=[];for(i+=1;i<e.length&&!/^<\/details>\s*$/i.test(e[i].trim());){const P=e[i].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);P?I=P[1].trim()||I:j.push(e[i].trimStart()),i+=1}i<e.length&&(i+=1),s.push({kind:"static",node:o.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[o.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:Ci(I,`${t}-details-${L}-summary`,!0,n)}),j.length>0&&o.jsx("div",{className:"mt-2 text-sm leading-6",children:iC(j,`${t}-details-${L}`,n)})]},`${t}-details-${L}`)});continue}const f=tC(c);if(f){const L=[c],I=i;for(i+=1;i<e.length&&!f.selfContained&&!new RegExp(`</${f.tag}>`,"i").test(e[i]);)L.push(e[i]),i+=1;i<e.length&&!f.selfContained&&(L.push(e[i]),i+=1),s.push({kind:"static",node:o.jsx(eC,{html:L.join(`
177
+ `;return`${e}${r}${n}`}function dJ(e,t){const n=e.trim();return n?t?`${n}\r`:/\s$/.test(e)?e:`${n} `:""}const D2="termdock:right-sidebar:html-view-mode-by-file:v1";function fJ(e){return e==="preview"||e==="source"}function AT(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.values(e).every(fJ)}function TT(e,t){if(!t)return null;const n=e&&!t.startsWith("/")?`${e}/${t}`:t;return e?`${e}::${n}`:n}function C4(e,t){const n=TT(e,t);return n?Or(D2,AT)?.[n]??"source":"source"}function hJ(e,t,n){const r=TT(e,t);if(!r)return;const s=Or(D2,AT)??{};$n(D2,{...s,[r]:n})}function Kx(e){const t=Number.isFinite(e)&&e>0?Math.floor(e):0,n=Math.floor(t/3600),r=Math.floor(t%3600/60),s=t%60,i=String(r).padStart(2,"0"),a=String(s).padStart(2,"0");return n>0?`${n}:${i}:${a}`:`${i}:${a}`}function pJ(e,t,n){return!Number.isFinite(n)||n<=0||!t.width?0:Math.min(1,Math.max(0,(e-t.left)/t.width))*n}const mJ=350,gJ=12,xJ=90;function bJ({url:e,onLoadError:t}){const{t:n}=Yn(),r=b.useRef(null),s=b.useRef(null),i=b.useRef(null),a=b.useRef(null),c=b.useRef(!1),u=b.useRef(null),f=b.useRef(null),p=b.useRef(0),g=b.useRef(!1),y=b.useRef(!1),v=b.useRef(!1),S=b.useRef(null),A=b.useRef(null),T=b.useRef(!1),L=b.useRef(1),I=b.useRef(!1),[j,P]=b.useState(0),[F,R]=b.useState(0),[C,$]=b.useState(!1),[H,Y]=b.useState(!1),[V,fe]=b.useState(null),[X,ve]=b.useState(!1),[we,ie]=b.useState(0),[ae,q]=b.useState(!1),[z,te]=b.useState({width:0,height:0}),pe=b.useCallback(()=>{S.current!==null&&(clearTimeout(S.current),S.current=null)},[]),de=b.useCallback(()=>{if(pe(),A.current=null,!T.current)return!1;const Ce=i.current;return Ce&&(Ce.playbackRate=L.current),T.current=!1,ve(!1),!0},[pe]);b.useEffect(()=>()=>{u.current!==null&&cancelAnimationFrame(u.current),f.current!==null&&clearTimeout(f.current),pe();const Ce=i.current;Ce&&T.current&&(Ce.playbackRate=L.current)},[pe]),b.useEffect(()=>{const Ce=s.current;if(!Ce||typeof ResizeObserver>"u")return;const Qe=new ResizeObserver(([pt])=>{pt&&te({width:pt.contentRect.width,height:pt.contentRect.height})});return Qe.observe(Ce),()=>Qe.disconnect()},[]),b.useEffect(()=>{const Ce=()=>q(document.fullscreenElement===r.current);return document.addEventListener("fullscreenchange",Ce),()=>document.removeEventListener("fullscreenchange",Ce)},[]);const ke=b.useCallback((Ce,Qe=!1)=>{const pt=i.current;if(!pt)return!1;const At=Number.isFinite(pt.duration)?pt.duration:Ce,yt=Math.min(Math.max(Ce,0),At);if(R(yt),Math.abs(pt.currentTime-yt)<1/120)return!1;const Yt=pt.fastSeek;return Qe&&typeof Yt=="function"?Yt.call(pt,yt):pt.currentTime=yt,!0},[]),be=b.useCallback(()=>{u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const Ce=i.current;if(!Ce||!g.current||y.current||Ce.seeking)return;const Qe=v.current;v.current=!1,y.current=ke(p.current,!Qe)}))},[ke]),oe=b.useCallback(Ce=>{const Qe=a.current,pt=i.current;if(!Qe||!pt)return;const At=Qe.getBoundingClientRect(),yt=pJ(Ce,At,pt.duration);p.current=yt,fe(yt),v.current=!1,be(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,v.current=!0,be()},xJ)},[be]),he=b.useCallback(()=>{u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),v.current=!1,y.current=!1,ke(p.current)},[ke]),J=b.useCallback(Ce=>{const Qe=i.current;if(!(!Qe||!Number.isFinite(Qe.duration)||Qe.duration<=0)){c.current=!Qe.paused,Qe.pause(),g.current=!0,Y(!0);try{Ce.currentTarget.setPointerCapture(Ce.pointerId)}catch{}oe(Ce.clientX)}},[oe]),Xe=b.useCallback(()=>{g.current=!1,he(),Y(!1),fe(null);const Ce=i.current;Ce&&c.current&&!Ce.ended&&Ce.play().catch(()=>{}),c.current=!1},[he]),lt=b.useCallback(()=>{const Ce=i.current;if(Ce){if(I.current){I.current=!1;return}Ce.paused?Ce.play().catch(()=>{}):Ce.pause()}},[]),Ze=b.useCallback(Ce=>{const Qe=i.current;!Qe||Qe.paused||Ce.button!==0||(pe(),A.current={id:Ce.pointerId,x:Ce.clientX,y:Ce.clientY},S.current=setTimeout(()=>{S.current=null,L.current=Qe.playbackRate,Qe.playbackRate=2,T.current=!0,ve(!0)},mJ))},[pe]),ge=b.useCallback(Ce=>{const Qe=A.current;!Qe||Qe.id!==Ce.pointerId||T.current||Math.hypot(Ce.clientX-Qe.x,Ce.clientY-Qe.y)>gJ&&(pe(),A.current=null)},[pe]),Fe=b.useCallback(()=>{de()&&(I.current=!0)},[de]);b.useEffect(()=>(window.addEventListener("pointerup",Fe),window.addEventListener("pointercancel",Fe),window.addEventListener("blur",Fe),()=>{window.removeEventListener("pointerup",Fe),window.removeEventListener("pointercancel",Fe),window.removeEventListener("blur",Fe)}),[Fe]);const Te=b.useCallback(async()=>{const Ce=r.current,Qe=i.current;if(!(!Ce||!Qe))try{document.fullscreenElement===Ce?await document.exitFullscreen():Ce.requestFullscreen?await Ce.requestFullscreen():Qe.webkitEnterFullscreen?.()}catch{Qe.webkitEnterFullscreen?.()}},[]),ze=b.useCallback(()=>ie(Ce=>(Ce+90)%360),[]),Be=b.useCallback(Ce=>{const Qe=i.current;if(!Qe||!Number.isFinite(Qe.duration))return;const pt=Ce.shiftKey?10:5;let At=null;Ce.key==="ArrowLeft"?At=Qe.currentTime-pt:Ce.key==="ArrowRight"?At=Qe.currentTime+pt:Ce.key==="Home"?At=0:Ce.key==="End"&&(At=Qe.duration),At!==null&&(Ce.preventDefault(),ke(At))},[ke]),We=H&&V!==null?V:F,W=j>0?Math.min(1,Math.max(0,We/j)):0,He=(we===90||we===270)&&z.width>0&&z.height>0?{width:`${z.height}px`,height:`${z.width}px`}:{width:"100%",height:"100%"};return o.jsxs("div",{ref:r,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":we,children:[o.jsxs("div",{ref:s,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[o.jsx("video",{ref:i,"data-testid":"file-preview-video",className:"absolute left-1/2 top-1/2 max-w-none object-contain transition-transform duration-200",style:{...He,transform:`translate(-50%, -50%) rotate(${we}deg)`},src:e,preload:"auto",playsInline:!0,onClick:lt,onPointerDown:Ze,onPointerMove:ge,onPointerUp:Fe,onPointerCancel:Fe,onContextMenu:Ce=>{T.current&&Ce.preventDefault()},onPlay:()=>$(!0),onPause:()=>$(!1),onTimeUpdate:Ce=>R(Ce.currentTarget.currentTime),onSeeked:Ce=>{const Qe=Ce.currentTarget;if(R(Qe.currentTime),y.current=!1,!g.current)return;const pt=Qe.requestVideoFrameCallback;typeof pt=="function"?pt.call(Qe,()=>{g.current&&be()}):requestAnimationFrame(()=>{g.current&&be()})},onLoadedMetadata:Ce=>P(Number.isFinite(Ce.currentTarget.duration)?Ce.currentTarget.duration:0),onDurationChange:Ce=>P(Number.isFinite(Ce.currentTarget.duration)?Ce.currentTarget.duration:0),onError:t,children:n("rightSidebar.videoUnsupported")}),X&&o.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:n("rightSidebar.videoLongPressSpeed")}),H&&V!==null&&o.jsx("div",{className:"pointer-events-none absolute bottom-1 z-10 -translate-x-1/2 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground shadow-md",style:{left:`${W*100}%`},"data-testid":"file-preview-video-scrub-time",children:Kx(V)})]}),o.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${y9}`,[v9]:"",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:lt,"aria-label":n(C?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:n(C?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:C?o.jsx(w8,{size:14}):o.jsx(Ib,{size:14})}),o.jsxs("div",{ref:a,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(j),"aria-valuenow":Math.floor(We),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:J,onPointerMove:Ce=>{H&&oe(Ce.clientX)},onPointerUp:Xe,onPointerCancel:Xe,onKeyDown:Be,children:[o.jsx("div",{className:"h-1 w-full rounded-full bg-surface-elevated"}),o.jsx("div",{className:"absolute inset-y-0 left-0 my-auto h-1 rounded-full bg-primary",style:{width:`${W*100}%`}}),o.jsx("div",{className:"absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary shadow",style:{left:`${W*100}%`}})]}),o.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[Kx(We)," / ",Kx(j)]}),o.jsx("button",{type:"button",onClick:ze,"aria-label":n("rightSidebar.videoRotate"),title:n("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:o.jsx(IM,{size:14})}),o.jsx("button",{type:"button",onClick:()=>{Te()},"aria-label":n(ae?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:n(ae?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:ae?o.jsx(aM,{size:14}):o.jsx(nM,{size:14})})]})})]})}function yJ(e){const t=Math.max(0,Math.min(100,e.xPercent)),n=Math.max(0,Math.min(100,e.yPercent));return{...t<=50?{left:`calc(${t}% + 8px)`}:{right:`calc(${100-t}% + 8px)`},...n<=50?{top:`calc(${n}% + 8px)`}:{bottom:`calc(${100-n}% + 8px)`}}}function Og({anchor:e,children:t,disabled:n=!1,onClick:r,title:s}){return o.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:n,onClick:i=>{i.stopPropagation(),r()},title:s,style:yJ(e),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[o.jsx(El,{size:11}),t]})}function vJ(e,t,n,r){if(n.width<=0||n.height<=0||r.width<=0||r.height<=0)return null;const s=Math.min(n.width/r.width,n.height/r.height);if(!Number.isFinite(s)||s<=0)return null;const i=r.width*s,a=r.height*s,c=n.left+(n.width-i)/2,u=n.top+(n.height-a)/2,f=e-c,p=t-u;if(f<0||p<0||f>i||p>a)return null;const g=f/i*100,y=p/a*100;return{x:r.x+r.width*g/100,y:r.y+r.height*y/100,xPercent:g,yPercent:y}}function wJ(e,t,n){const r=[`SVG标注: ${e}`,`视图: ${t}`,`SVG坐标: (${n.x.toFixed(2)},${n.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${n.xPercent.toFixed(1)}%,${n.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return n.nearestText&&r.push(`最近文字: ${n.nearestText}`),`"${r.join(" / ")}"`}function SJ(e){const t=new DOMParser().parseFromString(e,"image/svg+xml"),n=t.documentElement;if(n.nodeName.toLowerCase()!=="svg"||t.querySelector("parsererror"))throw new Error("Invalid SVG document");return t.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(r=>r.remove()),t.querySelectorAll("*").forEach(r=>{for(const s of Array.from(r.attributes)){const i=s.name.toLowerCase(),a=s.value.trim();(i.startsWith("on")||(i==="href"||i.endsWith(":href"))&&a&&!a.startsWith("#"))&&r.removeAttribute(s.name)}}),n.removeAttribute("width"),n.removeAttribute("height"),n.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(n)}function AJ(e,t,n){let r=null;for(const s of Array.from(e.querySelectorAll("text"))){const i=(s.textContent??"").replace(/\s+/g," ").trim();if(!i)continue;const a=Number(s.getAttribute("x")),c=Number(s.getAttribute("y"));if(!Number.isFinite(a)||!Number.isFinite(c))continue;const u=Math.hypot(a-t,c-n);(!r||u<r.distance)&&(r={text:i,distance:u})}return r?.text.slice(0,120)}function CT({blobUrl:e,filePath:t,viewLabel:n,onInsertAnnotation:r}){const s=b.useRef(null),i=b.useRef(null),[a,c]=b.useState(null),[u,f]=b.useState(null),[p,g]=b.useState(1),[y,v]=b.useState(!1),[S,A]=b.useState(null),T=b.useRef(new Map),L=b.useRef(null),I=b.useRef(!1),j=b.useRef(null),P=b.useRef(p);P.current=p,b.useEffect(()=>{const ae=new AbortController;return c(null),f(null),A(null),g(1),fetch(e,{signal:ae.signal}).then(q=>q.text()).then(q=>c(SJ(q))).catch(q=>{ae.signal.aborted||f(q instanceof Error?q.message:"SVG preview failed")}),()=>ae.abort()},[e]),b.useEffect(()=>{if(!y)return;const ae=q=>{q.key==="Escape"&&v(!1)};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[y]),b.useLayoutEffect(()=>{const ae=i.current,q=ae?.querySelector("[data-svg-document] > svg");if(!ae||!q)return;let z;try{z=q.getBBox()}catch{return}if(!z.width||!z.height)return;const te=Math.max(2,Math.min(z.width,z.height)*.025);q.setAttribute("viewBox",`${z.x-te} ${z.y-te} ${z.width+2*te} ${z.height+2*te}`),q.style.width=`${p*100}%`,q.style.height=`${p*100}%`,q.style.minWidth=`${p*100}%`,q.style.minHeight=`${p*100}%`,q.style.display="block"},[a,p]);const F=b.useMemo(()=>S?wJ(t,n,S):null,[t,S,n]),R=ae=>{if(I.current){I.current=!1;return}const q=i.current,z=q?.querySelector("[data-svg-document] > svg"),te=s.current;if(!q||!z||!te)return;const pe=z.viewBox.baseVal,de=vJ(ae.clientX,ae.clientY,z.getBoundingClientRect(),pe);if(!de)return;const ke=te.getBoundingClientRect();A({...de,nearestText:AJ(z,de.x,de.y),stageX:ae.clientX-ke.left,stageY:ae.clientY-ke.top,stageXPercent:(ae.clientX-ke.left)/ke.width*100,stageYPercent:(ae.clientY-ke.top)/ke.height*100})},C=ae=>Math.max(1,Math.min(12,ae)),$=(ae,q)=>{const z=C(q),te=ae.querySelector("[data-svg-document] > svg");if(!te)return z;const pe=`${z*100}%`;return te.style.width=pe,te.style.height=pe,te.style.minWidth=pe,te.style.minHeight=pe,P.current=z,z},H=(ae,q,z,te)=>{const pe=P.current,de=ae.getBoundingClientRect(),ke=z-de.left,be=te-de.top,oe=(ae.scrollLeft+ke)/pe,he=(ae.scrollTop+be)/pe,J=$(ae,q);return ae.scrollLeft=oe*J-ke,ae.scrollTop=he*J-be,J},Y=()=>{const ae=Array.from(T.current.values());return ae.length>=2?Math.hypot(ae[0].x-ae[1].x,ae[0].y-ae[1].y):0},V=ae=>{if(ae.pointerType==="mouse"&&ae.button!==0)return;const q=i.current;q&&(T.current.set(ae.pointerId,{x:ae.clientX,y:ae.clientY}),q.setPointerCapture?.(ae.pointerId),T.current.size>=2?(L.current={kind:"pinch",startX:ae.clientX,startY:ae.clientY,startScrollLeft:q.scrollLeft,startScrollTop:q.scrollTop,startDistance:Y(),startZoom:P.current,moved:!1},I.current=!0):P.current>1&&(L.current={kind:"pan",startX:ae.clientX,startY:ae.clientY,startScrollLeft:q.scrollLeft,startScrollTop:q.scrollTop,startZoom:P.current,moved:!1}))},fe=ae=>{if(!T.current.has(ae.pointerId))return;T.current.set(ae.pointerId,{x:ae.clientX,y:ae.clientY});const q=i.current,z=L.current;if(!(!q||!z)){if(T.current.size>=2&&z.kind==="pinch"){const te=Y();if(!z.startDistance||!te)return;const pe=C(z.startZoom*te/z.startDistance);if(Math.abs(pe-P.current)<.01)return;const de=Array.from(T.current.values()),ke=(de[0].x+de[1].x)/2,be=(de[0].y+de[1].y)/2;z.moved=!0,I.current=!0,H(q,pe,ke,be),ae.preventDefault();return}if(z.kind==="pan"&&T.current.size===1){const te=ae.clientX-z.startX,pe=ae.clientY-z.startY;if(!z.moved&&Math.hypot(te,pe)<6)return;z.moved=!0,I.current=!0,q.scrollLeft=z.startScrollLeft-te,q.scrollTop=z.startScrollTop-pe,ae.preventDefault()}}},X=ae=>{const q=i.current,z=L.current,te=T.current.size===1&&!z?.moved;T.current.delete(ae.pointerId);try{q?.releasePointerCapture?.(ae.pointerId)}catch{}if(T.current.size===1&&z?.kind==="pinch"){const ke=Array.from(T.current.values())[0];L.current=q?{kind:"pan",startX:ke.x,startY:ke.y,startScrollLeft:q.scrollLeft,startScrollTop:q.scrollTop,startZoom:P.current,moved:!1}:null;return}if(T.current.size>0||(L.current=null,z?.kind==="pinch"&&g(P.current),!te||I.current))return;const pe=Date.now(),de=j.current;de&&pe-de.time<350&&Math.hypot(ae.clientX-de.x,ae.clientY-de.y)<24?(j.current=null,I.current=!0,g(ke=>ke>1?1:2.5)):j.current={time:pe,x:ae.clientX,y:ae.clientY}},ve=ae=>{if(!ae.ctrlKey&&!ae.metaKey)return;const q=i.current;if(!q)return;ae.preventDefault();const z=H(q,P.current*Math.exp(-ae.deltaY*.01),ae.clientX,ae.clientY);g(z)},we=()=>{g(1),P.current=1,i.current&&(i.current.scrollLeft=0,i.current.scrollTop=0)},ie=o.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[o.jsxs("div",{ref:s,className:"relative min-h-0 flex-1",children:[o.jsx("div",{ref:i,role:"button",tabIndex:0,onClick:R,onDoubleClick:ae=>{ae.preventDefault(),g(q=>q>1?1:2.5)},onPointerDown:V,onPointerMove:fe,onPointerUp:X,onPointerCancel:X,onWheel:ve,onScroll:()=>A(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:u?o.jsx("div",{className:"p-4 text-sm text-destructive",children:u}):a?o.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:a}}):o.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),S&&o.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:S.stageX,top:S.stageY}}),S&&F&&o.jsx(Og,{anchor:{xPercent:S.stageXPercent,yPercent:S.stageYPercent},title:"引用 SVG 标注",onClick:()=>{r?.(F,`svg:${S.x.toFixed(2)}:${S.y.toFixed(2)}`),A(null)},children:"引用 SVG 标注"}),o.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[p>1.001&&o.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:ae=>{ae.stopPropagation(),we()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:o.jsx(MM,{size:14})}),o.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:ae=>{ae.stopPropagation(),v(q=>!q)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?o.jsx(ly,{size:14}):o.jsx(ay,{size:14})})]})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:S?`SVG (${S.x.toFixed(2)}, ${S.y.toFixed(2)}) · ${S.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?sa.createPortal(ie,document.body):ie}function bm(e){switch(e){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function TJ(e,t,n,r){const s=[`电子标注: ${e}`,`视图: ${bm(t)}`,`图片位置: (${n.xPercent.toFixed(1)}%,${n.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(r?.available&&r.xMm!==void 0&&r.yMm!==void 0&&(s.push(`PCB坐标: (${r.xMm.toFixed(2)},${r.yMm.toFixed(2)})mm [KiCad板坐标]`),r.layer&&s.push(`显示层: ${r.layer}`),r.nearest)){const i=[r.nearest.net?`网络 ${r.nearest.net}`:null,`对象层 ${r.nearest.layer}`,`距离 ${r.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");s.push(`最近对象: ${r.nearest.label}${i?`(${i})`:""}`)}return`"${s.join(" / ")}"`}function CJ({blobUrl:e,filePath:t,view:n,board:r,onViewChange:s,onInsertAnnotation:i,onRefresh:a,interactive3d:c}){const{t:u}=Yn(),f=b.useRef(null),p=b.useRef(null),g=b.useRef(null),[y,v]=b.useState(null),[S,A]=b.useState(!1);b.useEffect(()=>(g.current?.abort(),v(null),A(!1),()=>g.current?.abort()),[e,n]);const T=b.useMemo(()=>y?TJ(t,n,y,y.inspection):null,[t,y,n]),L=j=>{const P=f.current,F=p.current;if(!P||!F||!F.naturalWidth||!F.naturalHeight)return;const R=P.getBoundingClientRect(),C=Math.min(R.width/F.naturalWidth,R.height/F.naturalHeight),$=F.naturalWidth*C,H=F.naturalHeight*C,Y=R.left+(R.width-$)/2,V=R.top+(R.height-H)/2,fe=j.clientX-Y,X=j.clientY-V;if(fe<0||X<0||fe>$||X>H)return;const ve={xPercent:Math.max(0,Math.min(100,fe/$*100)),yPercent:Math.max(0,Math.min(100,X/H*100)),stageXPercent:(j.clientX-R.left)/R.width*100,stageYPercent:(j.clientY-R.top)/R.height*100,inspecting:r&&n!=="pcb-3d"};if(v(ve),g.current?.abort(),!ve.inspecting)return;const we=new AbortController;g.current=we,gI(t,n,ve.xPercent,ve.yPercent,we.signal).then(ie=>v(ae=>ae===ve?{...ae,inspection:ie,inspecting:!1}:ae)).catch(()=>{we.signal.aborted||v(ie=>ie===ve?{...ie,inspection:{available:!1},inspecting:!1}:ie)})},I=r?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return o.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[o.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[o.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:I.map(j=>o.jsx("button",{type:"button",onClick:()=>s(j),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${j===n?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:bm(j)},j))}),o.jsx("button",{type:"button",onClick:a,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:u("rightSidebar.edaRefresh"),"aria-label":u("rightSidebar.edaRefresh"),children:o.jsx(Us,{size:13})})]}),r&&c?o.jsx("div",{className:n==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:c}):null,r?n==="pcb-3d"?c?null:o.jsx("div",{className:"min-h-0 flex-1"}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{ref:f,role:"button",tabIndex:0,onClick:L,onKeyDown:j=>{j.key!=="Enter"&&j.key!==" "||(j.preventDefault(),v({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:u("rightSidebar.edaPickHint"),children:[o.jsx("img",{ref:p,src:e,alt:`${t} ${bm(n)}`,onLoad:()=>A(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${S?"opacity-100":"opacity-0"}`}),y&&o.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&T&&o.jsx(Og,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:u("rightSidebar.edaInsertAnnotation"),onClick:()=>{i?.(T,`eda:${n}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`),v(null)},children:u("rightSidebar.edaInsertAnnotation")})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?u("rightSidebar.edaInspecting"):y.inspection?.available?u("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??u("rightSidebar.edaNoNearbyObject")}):u("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):u("rightSidebar.edaPickHint")})})]}):o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:o.jsx(CT,{blobUrl:e,filePath:t,viewLabel:bm(n),onInsertAnnotation:i})})]})}function kJ(e){const t=[];let n=[],r="",s=!1;for(let i=0;i<e.length;i+=1){const a=e[i];s?a==='"'&&e[i+1]==='"'?(r+='"',i+=1):a==='"'?s=!1:r+=a:a==='"'?s=!0:a===","?(n.push(r),r=""):a===`
178
+ `?(n.push(r.replace(/\r$/,"")),t.push(n),n=[],r=""):r+=a}return(r||n.length>0)&&(n.push(r.replace(/\r$/,"")),t.push(n)),t}function _J(e,t,n,r,s){const i=t[s]||`第${s+1}列`,a=n[s]??"",c=t.map((u,f)=>`${u||`第${f+1}列`}=${n[f]??""}`).join(";");return`"表格标注: ${e} / 数据行: ${r+1} / 列: ${i} / 值: ${a} / 记录: ${c}"`}function LJ({content:e,filePath:t,onInsertAnnotation:n}){const{t:r}=Yn(),s=b.useMemo(()=>kJ(e),[e]),i=s[0]??[],a=s.slice(1),c=b.useRef(null),[u,f]=b.useState(null),p=u?a[u.row]:null,g=u&&p?_J(t,i,p,u.row+1,u.column):null;return o.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[o.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[o.jsx("div",{className:"h-full overflow-auto",children:o.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),i.map((y,v)=>o.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:y||r("rightSidebar.csvUnnamedColumn",{index:v+1})},`${y}:${v}`))]})}),o.jsx("tbody",{children:a.map((y,v)=>o.jsxs("tr",{className:"hover:bg-surface-2",children:[o.jsx("th",{className:"sticky left-0 z-10 border-b border-r border-border/15 bg-surface px-2 py-2 text-right text-[10px] font-normal text-muted-foreground",children:v+1}),i.map((S,A)=>{const T=u?.row===v&&u.column===A;return o.jsx("td",{className:`border-b border-r border-border/15 p-0 ${T?"bg-primary/15":""}`,children:o.jsx("button",{type:"button",onClick:L=>{const I=c.current?.getBoundingClientRect(),j=L.currentTarget.getBoundingClientRect();if(!I?.width||!I.height)return;const P=L.clientX||j.left+j.width/2,F=L.clientY||j.top+j.height/2;f({row:v,column:A,xPercent:(P-I.left)/I.width*100,yPercent:(F-I.top)/I.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:y[A]||" "})},`cell:${v}:${A}`)})]},`row:${v}`))})]})}),u&&g&&o.jsx(Og,{anchor:{xPercent:u.xPercent,yPercent:u.yPercent},title:r("rightSidebar.csvInsertAnnotation"),onClick:()=>{n?.(g,`csv:${t}:${u.row+1}:${u.column+1}`),f(null)},children:r("rightSidebar.csvInsertAnnotation")})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:u&&p?r("rightSidebar.csvSelectedCell",{row:u.row+1,column:i[u.column]||u.column+1}):r("rightSidebar.csvPickHint",{rows:a.length,columns:i.length})})})]})}function Dd(e,t){let n=e;for(const r of t){if(!n||typeof n!="object")return;n=n[r]}return n}function EJ(e,t){const n=JSON.parse(e),r=Dd(n,["meta","version"]);if(t)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(r??"未知")},{label:"活动层编号",value:String(Dd(n,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Dd(n,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Dd(n,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const s=Dd(n,["net_settings","classes"]),i=Array.isArray(s)?s.find(c=>c&&typeof c=="object"&&c.name==="Default"):void 0,a=Dd(n,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(r??"未知")},{label:"网络类数量",value:String(Array.isArray(s)?s.length:0)},{label:"默认间距",value:i?.clearance!==void 0?`${i.clearance} mm`:"未设置"},{label:"默认线宽",value:i?.track_width!==void 0?`${i.track_width} mm`:"未设置"},{label:"默认过孔",value:i?.via_diameter!==void 0?`${i.via_diameter} / ${i.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(a)?a.length:0)}]}function IJ(e,t){return`"KiCad项目标注: ${e} / 项: ${t.label} / 值: ${t.value}"`}function RJ({content:e,filePath:t,localState:n,onInsertAnnotation:r}){const{t:s}=Yn(),i=b.useRef(null),[a,c]=b.useState(null),u=b.useMemo(()=>{try{return{items:EJ(e,n),error:null}}catch(p){return{items:[],error:p instanceof Error?p.message:String(p)}}},[e,n]),f=a===null?null:u.items[a.index];return u.error?o.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:e}):o.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[n&&o.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:s("rightSidebar.kicadLocalStateNotice")}),o.jsxs("div",{ref:i,className:"relative min-h-0 flex-1",children:[o.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[o.jsx("div",{className:"divide-y divide-border/15",children:u.items.map((p,g)=>o.jsxs("button",{type:"button",onClick:y=>{const v=i.current?.getBoundingClientRect(),S=y.currentTarget.getBoundingClientRect();if(!v?.width||!v.height)return;const A=y.clientX||S.left+S.width/2,T=y.clientY||S.top+S.height/2;c({index:g,xPercent:(A-v.left)/v.width*100,yPercent:(T-v.top)/v.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${a?.index===g?"bg-primary/10":""}`,children:[o.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:p.label}),o.jsx("span",{className:"break-words text-xs text-foreground",children:p.value})]},p.label))}),o.jsxs("details",{className:"mt-3 border-t border-border/15 pt-3",children:[o.jsx("summary",{className:"cursor-pointer text-xs font-semibold text-muted-foreground",children:s("rightSidebar.kicadShowRawJson")}),o.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:e})]})]}),f&&a&&o.jsx(Og,{anchor:{xPercent:a.xPercent,yPercent:a.yPercent},title:s("rightSidebar.kicadInsertSetting"),onClick:()=>{r?.(IJ(t,f),`kicad-project:${t}:${f.label}`),c(null)},children:s("rightSidebar.kicadInsertSetting")})]}),o.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:o.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:f?`${f.label}: ${f.value}`:s("rightSidebar.kicadProjectPickHint")})})]})}const NJ=b.forwardRef(function({src:t,title:n,exitFullscreenLabel:r,onFullscreenChange:s},i){const a=b.useRef(null),[c,u]=b.useState(!1),[f,p]=b.useState(!1),g=c||f;b.useEffect(()=>{s?.(g)},[g,s]),b.useEffect(()=>{const S=()=>{u(document.fullscreenElement===a.current)};return document.addEventListener("fullscreenchange",S),()=>document.removeEventListener("fullscreenchange",S)},[]),b.useEffect(()=>{if(!f)return;const S=A=>{A.key==="Escape"&&p(!1)};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[f]);const y=b.useCallback(async()=>{const S=a.current;if(S){if(f){p(!1);return}if(document.fullscreenElement===S){await document.exitFullscreen();return}if(S.requestFullscreen&&document.fullscreenEnabled!==!1)try{await S.requestFullscreen();return}catch{}p(!0)}},[f]);b.useImperativeHandle(i,()=>({toggleFullscreen:y}),[y]);const v=o.jsxs("div",{ref:a,"data-html-preview-frame":!0,className:g?"fixed inset-0 z-modal-panel flex min-h-0 flex-col overflow-hidden bg-surface pt-[env(safe-area-inset-top,0px)] text-foreground":"flex h-full min-h-0 flex-col overflow-hidden bg-surface",children:[g&&o.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/15 bg-[var(--chrome-bg)] px-3",children:[o.jsx("span",{className:"min-w-0 truncate text-[12px] font-semibold",children:n}),o.jsx("button",{type:"button",onClick:()=>{y()},"aria-label":r,title:`${r} (Esc)`,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:o.jsx(ly,{size:15})})]}),o.jsx("iframe",{src:t,title:n,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return f?sa.createPortal(v,document.body):v}),kT="termdock-file-search-match",j2="termdock-file-search-current";function MJ(e){const t=e.metaKey||e.ctrlKey,n=e.key.toLocaleLowerCase();return t&&n==="f"?"open":t&&n==="g"||e.key==="F3"?e.shiftKey?"previous":"next":e.key==="Escape"?"close":null}function DJ(e){return e.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function jJ(e,t){const n=t.trim().toLocaleLowerCase();if(!n)return[];const r=[];let s="",i=null;const a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let p=a.nextNode();p;p=a.nextNode()){if(!(p instanceof Text)||!p.data)continue;const g=DJ(p);if(!g)continue;i&&i!==g&&(s+=`
179
+ `);const y=s.length;s+=p.data,r.push({node:p,start:y,end:s.length,group:g}),i=g}const c=s.toLocaleLowerCase(),u=[];let f=0;for(;f<=c.length-n.length;){const p=c.indexOf(n,f);if(p<0)break;const g=p+n.length,y=r.find(S=>S.start<=p&&S.end>p),v=r.find(S=>S.start<g&&S.end>=g);if(y&&v&&y.group===v.group){const S=document.createRange();S.setStart(y.node,p-y.start),S.setEnd(v.node,g-v.start),u.push(S)}f=p+Math.max(n.length,1)}return u}function _T(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function $p(){const e=_T();e?.delete(kT),e?.delete(j2)}function k4(e,t){const n=_T();if(!n||typeof Highlight>"u")return;n.set(kT,new Highlight(...e));const r=e[t];r?n.set(j2,new Highlight(r)):n.delete(j2)}function _4(e){e?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}const av="termdock:right-sidebar:file-tree-scroll:v1",lv="termdock:right-sidebar:file-preview-reading-state:v1",Ef="termdock:right-sidebar:file-tree-width:v1",LT="termdock:right-sidebar:markdown-view-mode:v1",ET="termdock:right-sidebar:diff-change-list-mode:v1",IT="termdock:right-sidebar:diff-wrap:v1",RT="termdock:diff-viewer:view-type:v1",NT="termdock:right-sidebar:file-search-mode:v1",Xx="termdock:right-sidebar:collapsed-git-repo-groups:v1",L4="termdock:right-sidebar:collapsed-diff-directories:v1",Zx="termdock:right-sidebar:branch-audit-module-open:v1",MT="termdock:right-sidebar:branch-audit-module:v1",PJ=150,DT="termdock:right-sidebar:active-git-repo:v1",E4="termdock:right-sidebar:context-draft-enabled:v1",I4="termdock:right-sidebar:context-draft-collapsed:v1",R4="termdock:right-sidebar:context-draft-auto-collapse:v1",Jx="termdock:right-sidebar:context-draft-text:v1",BJ=300,FJ=20,OJ=120,QJ=250,$J=250,HJ=120,UJ=700,eb=600,N4=[2e3,5e3,15e3,3e4],zJ=320,GJ=500,WJ=20,VJ=12e3,P2=300,M4=240,qJ=560,jT="border-r px-2 py-1.5 sm:px-3 sm:py-2",rg="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",PT=`${jT} border-b border-border/15 font-semibold last:border-r-0`,BT=`${jT} border-border/10 align-top text-muted-foreground last:border-r-0`,cv="termdock-file-preview-horizontal-scroll",D4=b.lazy(()=>g0(()=>import("./ModelPreview-Be2smem8.js"),__vite__mapDeps([2,3,1,4]))),FT=`${cv} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function YJ(e,t,n){return e&&!t?"unified":n}const KJ=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function XJ(e){return e==="preview"||e==="source"}function ZJ(e){return e==="list"||e==="tree"||e==="ai"}function j4(){return Or(LT,XJ)??"preview"}function JJ(){return Or(ET,ZJ)??"tree"}function If(e){return typeof e=="boolean"}function eee(e){return typeof e=="string"}function tee(){return Or(IT,If)??!0}function nee(e){return e==="unified"||e==="split"}function ree(){return Or(RT,nee)??"unified"}function see(e){return e==="name"||e==="content"||e==="regex"}function iee(){return Or(NT,see)??"name"}function OT(e){return e.repositories??(e.context?.root?[{id:e.context.root,root:e.context.root,relativeRoot:".",name:bo(e.context.root)||e.context.root,depth:0,nested:!1,available:e.available,files:e.files,context:e.context,error:e.error}]:[])}function oee(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.values(e).every(t=>t===null||typeof t=="string")}function QT(){return Or(DT,oee)??{}}function P4(e){if(!e)return;const t=QT();return Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0}function tb(e,t){e&&$n(DT,{...QT(),[e]:t})}function aee(e,t){if(!t)return null;const n=new Set((e.repoFilters??[]).map(r=>r.root));return n.has(t)?t:n.size>0?null:(e.repositories??[]).some(r=>r.root===t)?t:null}function B2(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function B4(e){const t=Or(e,B2);return t?new Set(t):new Set}function nb(e,t){$n(e,[...t])}function lee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.filePath=="string"&&typeof t.hunkHeader=="string"&&typeof t.hunkIndex=="number"&&typeof t.fingerprint=="string"&&typeof t.additions=="number"&&typeof t.deletions=="number"&&typeof t.diff=="string"&&(t.oldPath===void 0||t.oldPath===null||typeof t.oldPath=="string")&&(t.newPath===void 0||t.newPath===null||typeof t.newPath=="string")&&(t.source===void 0||t.source==="committed"||t.source==="uncommitted"||t.source==="unknown")&&(t.commit===void 0||t.commit===null||typeof t.commit=="string")}function cee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.available=="boolean"&&(t.repoRoot===void 0||typeof t.repoRoot=="string")&&(t.workspaceRoot===void 0||typeof t.workspaceRoot=="string")&&(t.baseRef===void 0||typeof t.baseRef=="string")&&(t.baseBranch===void 0||typeof t.baseBranch=="string")&&(t.currentBranch===void 0||t.currentBranch===null||typeof t.currentBranch=="string")&&(t.headRef===void 0||t.headRef===null||typeof t.headRef=="string")&&(t.diffFingerprint===void 0||typeof t.diffFingerprint=="string")&&(t.stat===void 0||typeof t.stat=="string")&&(t.files===void 0||B2(t.files))&&(t.hunks===void 0||Array.isArray(t.hunks)&&t.hunks.every(lee))&&(t.commits===void 0||B2(t.commits))&&(t.commitCount===void 0||typeof t.commitCount=="number")&&(t.diff===void 0||typeof t.diff=="string")&&(t.truncated===void 0||typeof t.truncated=="boolean")&&(t.error===void 0||typeof t.error=="string")}function uee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.key=="string"&&cee(t.diff)&&typeof t.repoLabel=="string"&&typeof t.createdAt=="number"}function dee(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.values(e).every(t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;return Array.isArray(n.selectedRepoRoots)&&n.selectedRepoRoots.every(r=>typeof r=="string")&&!!n.repoTargetBranches&&typeof n.repoTargetBranches=="object"&&!Array.isArray(n.repoTargetBranches)&&Object.values(n.repoTargetBranches).every(r=>typeof r=="string")&&(n.repoBaseBranches===void 0||!!n.repoBaseBranches&&typeof n.repoBaseBranches=="object"&&!Array.isArray(n.repoBaseBranches)&&Object.values(n.repoBaseBranches).every(r=>typeof r=="string"))&&(n.previewEntries===void 0||Array.isArray(n.previewEntries)&&n.previewEntries.every(uee))&&(n.selectedPreviewKey===void 0||n.selectedPreviewKey===null||typeof n.selectedPreviewKey=="string")&&(n.selectedPreviewFileKey===void 0||n.selectedPreviewFileKey===null||typeof n.selectedPreviewFileKey=="string")&&(n.previewDetailOpen===void 0||typeof n.previewDetailOpen=="boolean")&&(n.previewScrollTops===void 0||!!n.previewScrollTops&&typeof n.previewScrollTops=="object"&&!Array.isArray(n.previewScrollTops)&&Object.values(n.previewScrollTops).every(r=>typeof r=="number"))&&(n.previewMobileSlideIndex===void 0||typeof n.previewMobileSlideIndex=="number")&&(n.includeUncommitted===void 0||typeof n.includeUncommitted=="boolean")&&typeof n.updatedAt=="number"})}function F4(){return Or(MT,dee)??{}}function O4(e){return[e.repoRoot,e.baseRef,e.branchName??"",e.headRef??"",e.diffFingerprint??""].join("\0")}function Q4(e){const t=e?.trim()??"",n=t.indexOf("/");return n>=0?t.slice(n+1):t}function $T(e,t){const n=e?.trim(),r=t?.trim();return!n||!r?!1:n===r||Q4(n)===Q4(r)}function $4(e){const t=e?.branch??null;return[e?.upstream,...e?.remoteBranches??[],...e?.branches??[]].find(r=>r&&!$T(r,t))??""}function F2(e,t){const n=Math.max(M4,t-320),r=Math.min(qJ,n);return Math.min(r,Math.max(M4,e))}function fee(e){return typeof e=="number"&&Number.isFinite(e)}function hee(e){return F2(Or(Ef,fee)??P2,e)}function HT(e){const t=e.split(/[\\/]/).pop()??e,n=t.lastIndexOf(".");return n>=0?t.slice(n).toLowerCase():""}function mf(e){return KJ.has(HT(e))}function UT(e){const t=e.trim().replace(/\s+/g,"");return/^-{3,}$/.test(t)||/^\*{3,}$/.test(t)||/^_{3,}$/.test(t)}function O2(e){const t=e.trim();return/^#{1,6}\s+/.test(t)||UT(e)||/^>\s?/.test(t)||/^(```|~~~)/.test(t)||/^(?:[-+*]|\d+[.)])\s+/.test(t)}function pee(e){const t=e.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(t)||!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!/[<>]/.test(t)?t:null}const zT=b.createContext(null);function ym(e){return e.trim().replace(/\s+/g," ").toLowerCase()}function GT(e){return e.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function WT(e){return e.replace(/\s+#+\s*$/,"").trim()}function Q2(e,t){const r=GT(e).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",s=t.headingSlugCounts.get(r)??0;return t.headingSlugCounts.set(r,s+1),s===0?r:`${r}-${s}`}function H4(e){return GT(e)||e.trim()}function sg(e){const t=e.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!t)return null;const n=H2(t[2]);return n?{id:ym(t[1]),definition:{href:n.href,title:n.title}}:null}function mee(e){const t=new Map;for(const n of e){const r=sg(n);r&&t.set(r.id,r.definition)}return t}function VT(e){return e.trim().toLowerCase()}function qT(e){const t=e.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return t?{id:VT(t[1]),text:t[2]}:null}function gee(e){const t=new Map;let n=null;for(const r of e){const s=qT(r);if(s){n=s.id,t.set(s.id,{id:s.id,text:s.text,index:t.size+1});continue}if(n&&/^\s{4,}\S/.test(r)){const i=t.get(n);i&&(i.text=`${i.text} ${r.trim()}`);continue}r.trim()&&(n=null)}return t}function xee(e){const t=new Set;let n=!1;return e.forEach((r,s)=>{if(qT(r)){t.add(s),n=!0;return}if(n&&/^\s{4,}\S/.test(r)){t.add(s);return}r.trim()&&(n=!1)}),t}function bee(e){const t=[...e];let n=0;const r=e[0]?.trim();if(r==="---"||r==="+++"){for(t[0]="",n=1;n<e.length&&e[n].trim()!==r;)t[n]="",n+=1;n<e.length&&(t[n]="",n+=1)}for(;n<e.length;){const s=e[n].trim();if(s.startsWith("<!--")){if(t[n]="",!s.includes("-->")){for(n+=1;n<e.length&&!e[n].includes("-->");)t[n]="",n+=1;n<e.length&&(t[n]="")}n+=1;continue}n+=1}return t}function YT(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n<=0?n===0?"/":"":t.slice(0,n)}function Uf(e){const t=e.split(/[?#]/,1)[0],n=t.startsWith("/"),r=[];for(const i of t.split("/"))if(!(!i||i===".")){if(i===".."){r.length>0&&r.pop();continue}r.push(i)}return`${n?"/":""}${r.join("/")}`||(n?"/":".")}function yee(e,t,n){const r=e.trim();if(!r||/^(?:https?:|mailto:|javascript:|data:|#)/i.test(r)||/^[a-z][a-z0-9+.-]*:/i.test(r))return null;const s=r.indexOf("#"),i=s>=0?r.slice(0,s):r,a=s>=0?r.slice(s+1):"",c=i.split("?",1)[0];if(!c)return null;let u,f=null;try{u=decodeURIComponent(c),f=a?decodeURIComponent(a):null}catch{return null}const p=n?Uf(n):null;let g;if(u.startsWith("/")){const y=p&&(u===p||u.startsWith(`${p}/`));g=Uf(p&&!y?`${p}/${u.slice(1)}`:u)}else{if(!t)return null;g=Uf(`${YT(t)}/${u}`)}return p&&g!==p&&!g.startsWith(`${p}/`)?null:{path:g,fragment:f,directory:/\/$/.test(c)}}function vee(e,t,n){const r=e.trim();if(!r||/^(?:javascript|data):/i.test(r))return null;if(/^https?:\/\//i.test(r))return r;if(!ey(r.split(/[?#]/,1)[0]))return null;let s;if(r.startsWith("/")){const i=n&&(r===n||r.startsWith(`${n}/`));s=Uf(n&&!i?`${n}/${r.slice(1)}`:r)}else{if(!t)return null;s=Uf(`${YT(t)}/${r}`)}return`/api/terminal/fs/blob?path=${encodeURIComponent(s)}`}const $2=128,wee=360,rb=480;function uv(e){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(e))}catch{return!1}}function See(e,t,n,r){if(!t||!n)return null;let s,i;return uv(e)?(i=Math.min(Math.max(n,$2),wee),s=t*i/n):(s=t,i=n),r>0&&s>r&&(i=i*r/s,s=r),i>rb&&(s=s*rb/i,i=rb),{width:Math.max(1,Math.round(s)),height:Math.max(1,Math.round(i))}}function Aee(e){if(!e.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(e.slice(e.indexOf("?"))).get("path")}catch{return null}}function KT(e){const t=Aee(e),n=ft(r=>t?(r.fileChangeVersions.get(t)??0)+r.fileWatchEpoch:0);return t&&n>0?`${e}&v=${n}`:e}function Tee({src:e,alt:t,title:n}){const r=uv(e),s=KT(e),i=b.useRef(null),[a,c]=b.useState(!1),[u,f]=b.useState(0),[p,g]=b.useState({status:"loading"}),[y,v]=b.useState(null);b.useLayoutEffect(()=>{const T=i.current,L=T?.parentElement?.parentElement??T?.parentElement;if(!L)return;const I=()=>f(L.clientWidth);if(I(),typeof ResizeObserver>"u")return;const j=new ResizeObserver(I);return j.observe(L),()=>j.disconnect()},[]),b.useEffect(()=>{if(a)return;const T=i.current;if(!T||typeof IntersectionObserver>"u"){c(!0);return}const L=new IntersectionObserver(I=>{I.some(j=>j.isIntersecting)&&(c(!0),L.disconnect())},{rootMargin:"400px"});return L.observe(T),()=>L.disconnect()},[a]),b.useEffect(()=>{if(!a)return;const T=new AbortController;let L=null;g({status:"loading"});const I=window.setTimeout(()=>{T.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return fetch(s,{signal:T.signal}).then(async j=>{if(!j.ok)throw new Error(`HTTP ${j.status}`);const P=Number(j.headers.get("X-Image-Width"))||0,F=Number(j.headers.get("X-Image-Height"))||0;return{blob:await j.blob(),width:P,height:F}}).then(({blob:j,width:P,height:F})=>{T.signal.aborted||(L=URL.createObjectURL(j),P>0&&F>0&&v({width:P,height:F}),g({status:"ready",objectUrl:L}))}).catch(()=>{const j=T.signal.reason;T.signal.aborted&&!(j instanceof DOMException&&j.name==="TimeoutError")||g({status:"fallback"})}).finally(()=>{window.clearTimeout(I)}),()=>{window.clearTimeout(I),T.abort(),L&&URL.revokeObjectURL(L)}},[a,s]);const S=See(e,y?.width??0,y?.height??0,u),A=S??{width:$2*2,height:$2};return o.jsx("div",{ref:i,className:"block max-w-full",style:S?{width:S.width,height:S.height}:void 0,children:p.status==="ready"?o.jsx("img",{src:p.objectUrl,alt:t,title:n,decoding:"async",className:`${r?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:S?{width:S.width,height:S.height}:void 0,onLoad:T=>{if(y)return;const L=T.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&v({width:L.naturalWidth,height:L.naturalHeight})}}):p.status==="fallback"?o.jsx("img",{src:s,alt:t,title:n,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:S?{width:S.width,height:S.height}:void 0,onLoad:T=>{if(y)return;const L=T.currentTarget;L.naturalWidth>0&&L.naturalHeight>0&&v({width:L.naturalWidth,height:L.naturalHeight})}}):o.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:A.width,height:A.height},children:o.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:t||"…"})})})}function sb(e,t,n,r,s){const i=vee(n,s.markdownFilePath,s.rootPath);if(!i)return`![${t}](${n})`;const a=s.images.length;s.images.push({kind:"image",src:i,alt:t,title:r});const c=o.jsx(Tee,{src:i,alt:t,title:r});return s.onImageOpen?o.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:r||t||"Open image",onClick:u=>{u.stopPropagation(),s.onImageOpen?.(a)},children:c},e):o.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c},e)}function ib(e){let t=e,n="";for(;/[.,;:!?)]$/.test(t);)n=`${t.slice(-1)}${n}`,t=t.slice(0,-1);return{linkText:t,suffix:n}}function U4(e){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(e)}function H2(e){const t=e.trim(),n=t.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(n)return{href:n[1],title:n[2]??n[3]??n[4]};const r=t.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return r?{href:r[1],title:r[2]??r[3]??r[4]}:null}const XT="",Cee=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function kee(e){return e.replace(Cee,(t,n)=>`${XT}${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function z4(e){return e.replace(new RegExp(`${XT}([0-9a-f]{4})`,"g"),(t,n)=>String.fromCharCode(Number.parseInt(n,16))).replace(/\\([()])/g,"$1")}function _ee(e){const t=e.replace(/[\r\n]+/g," ");return/^ .+ $/.test(t)&&/[^ ]/.test(t.slice(1,-1))?t.slice(1,-1):t}const ZT={ALLOWED_TAGS:["a","abbr","b","blockquote","br","code","del","details","div","em","i","kbd","li","mark","ol","p","pre","s","span","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],ALLOWED_ATTR:["href","title","class","id","colspan","rowspan"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0};let Hp=null;function JT(){return Hp||(Hp=g0(()=>import("./purify.es-CC4Brkr_.js"),[]).then(e=>e.default??e).catch(e=>{throw Hp=null,e})),Hp}function eC({html:e}){const{t}=Yn(),[n,r]=b.useState(null);return b.useEffect(()=>{let s=!1;return r(null),JT().then(i=>{s||r(i.sanitize(e,ZT))}).catch(()=>{s||r("")}),()=>{s=!0}},[e]),n===null?o.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:t("rightSidebar.renderingHtml")}):n?o.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:n}}):null}function Lee({html:e}){const[t,n]=b.useState(null);return b.useEffect(()=>{let r=!1;return n(null),JT().then(s=>{r||n(s.sanitize(e,ZT))}).catch(()=>{r||n("")}),()=>{r=!0}},[e]),t===null?null:t?o.jsx("span",{dangerouslySetInnerHTML:{__html:t}}):e}function tC(e){const t=e.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!t)return null;const n=t[1].toLowerCase();return{tag:n,selfContained:new RegExp(`</${n}>`,"i").test(e)}}let Up=null;function Eee(){return Up||(Up=Promise.all([g0(()=>import("./katex-DnlPpQZa.js"),[]),g0(()=>Promise.resolve({}),__vite__mapDeps([5]))]).then(([e])=>e.default??e).catch(e=>{throw Up=null,e})),Up}function lh({tex:e,display:t=!1}){const[n,r]=b.useState(null),[s,i]=b.useState(!1);if(b.useEffect(()=>{let c=!1;return r(null),i(!1),Eee().then(u=>{c||r(u.renderToString(e,{displayMode:t,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{c||i(!0)}),()=>{c=!0}},[t,e]),s)return o.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:t?`$$${e}$$`:`$${e}$`});if(!n)return o.jsx("span",{className:"text-muted-foreground/70",children:t?"Rendering formula...":e});const a=t?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return o.jsx("span",{className:a,dangerouslySetInnerHTML:{__html:n}})}function Iee(e,t,n){if(/^<br\s*\/?>$/i.test(e))return o.jsx("br",{},t);const r=e.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!r)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(e)?o.jsx(Lee,{html:e},t):null;const s=r[1].toLowerCase(),i=Ci(r[2],`${t}-${s}`,!0,n);return s==="kbd"?o.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:i},t):s==="mark"?o.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:i},t):s==="sub"?o.jsx("sub",{children:i},t):o.jsx("sup",{children:i},t)}function Ci(e,t,n=!0,r){const s=kee(e),i=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,a=[];let c=0,u;for(;(u=i.exec(s))!==null;){u.index>c&&a.push(z4(s.slice(c,u.index)));const f=u[0],p=`${t}-${u.index}`,g=f.startsWith("<")?Iee(f,p,r):null;if(g)a.push(g);else if(f.startsWith("\\(")&&f.endsWith("\\)"))a.push(o.jsx(lh,{tex:f.slice(2,-2)},p));else if(f.startsWith("$")&&f.endsWith("$"))a.push(o.jsx(lh,{tex:f.slice(1,-1)},p));else if(f.startsWith("`")){const y=f.match(/^`+/)?.[0].length??1;a.push(o.jsx("code",{className:`${n?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:_ee(f.slice(y,-y))},p))}else if(f.startsWith("~~"))a.push(o.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:Ci(f.slice(2,-2),`${p}-del`,n,r)},p));else if(f.startsWith("**")||f.startsWith("__"))a.push(o.jsx("strong",{className:"font-semibold text-foreground",children:Ci(f.slice(2,-2),`${p}-strong`,n,r)},p));else if(f.startsWith("*")||f.startsWith("_"))a.push(o.jsx("em",{className:"italic",children:Ci(f.slice(1,-1),`${p}-em`,n,r)},p));else if(f.startsWith("![")){const y=f.match(/^!\[([^\]]*)\]\((.*)\)$/),v=f.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),S=f.match(/^!\[([^\]]+)\]$/);if(y){const A=H2(y[2]);a.push(A?sb(p,y[1],A.href,A.title,r):f)}else if(v){const A=v[2]||v[1],T=r.referenceDefinitions.get(ym(A));a.push(T?sb(p,v[1],T.href,T.title,r):f)}else if(S){const A=r.referenceDefinitions.get(ym(S[1]));a.push(A?sb(p,S[1],A.href,A.title,r):f)}else a.push(f)}else if(f.startsWith("[^")){const y=VT(f.slice(2,-1)),v=r.footnoteDefinitions.get(y);a.push(v?o.jsx("sup",{id:`fnref-${v.id}`,title:v.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:o.jsx("a",{href:`#fn-${v.id}`,className:"text-primary no-underline",children:v.index})},p):f)}else if(f.startsWith("<http")){const y=f.slice(1,-1);a.push(o.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p))}else if(f.startsWith("<")&&f.endsWith(">")&&U4(f.slice(1,-1))){const y=f.slice(1,-1);a.push(o.jsx("a",{href:`mailto:${y}`,className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p))}else if(U4(ib(f).linkText)){const{linkText:y,suffix:v}=ib(f);a.push(o.jsx("a",{href:`mailto:${y}`,className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p)),v&&a.push(v)}else if(f.startsWith("http")||f.startsWith("www.")){const{linkText:y,suffix:v}=ib(f),S=y.startsWith("www.")?`https://${y}`:y;a.push(o.jsx("a",{href:S,target:"_blank",rel:"noreferrer",className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},p)),v&&a.push(v)}else{const y=f.match(/^\[([^\]]+)\]\((.*)\)$/),v=f.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),S=f.match(/^\[([^\]]+)\]$/),A=v?v[2]||v[1]:S?.[1]??null,T=A?r.referenceDefinitions.get(ym(A)):null,L=y?H2(y[2]):null,I=L?.href??T?.href??null,j=I?pee(I):null,P=y?.[1]??v?.[1]??S?.[1]??"";a.push(j?o.jsx("a",{href:j,title:L?.title??T?.title,target:"_blank",rel:"noreferrer",className:`${n?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:Ci(P,`${p}-link`,n,r)},p):f)}c=i.lastIndex}return c<s.length&&a.push(z4(s.slice(c))),a.length>0?a:[e]}function nC(e){return/(?: {2,}|\\)$/.test(e)}function rC(e){return e.replace(/(?: {2,}|\\)$/,"")}function ig(e){return/^(?: {4}|\t)/.test(e)}function sC(e){return e.startsWith(" ")?e.slice(1):e.replace(/^ {4}/,"")}function iC(e,t,n){const r=[];return e.forEach((s,i)=>{const a=nC(s);r.push(...Ci(rC(s),`${t}-${i}`,!0,n)),i<e.length-1&&r.push(a?o.jsx("br",{},`${t}-${i}-br`):" ")}),r}function U2(e,t,n){const r=[],s=[];return e.forEach((i,a)=>{s.push(nC(i)),r.push(Ci(rC(i),`${t}-${a}`,!0,n))}),{perLine:r,hardBreaks:s}}function z2(e,t,n,r,s){const i=[];return e.forEach((a,c)=>{const u=n[c]??0,f=!!(s&&u>=s.start&&u<=s.end);i.push(o.jsx("span",{"data-md-ref-start":u,"data-md-ref-end":u,"data-selected":f?"true":void 0,children:a},`${r}-ref-${c}`)),c<e.length-1&&i.push(t[c]?o.jsx("br",{},`${r}-${c}-br`):" ")}),i}function ch(e){const t=e.trim().replace(/^\|/,"").replace(/\|$/,""),n=[];let r="",s=!1,i=0,a=0;for(let c=0;c<t.length;c+=1){const u=t[c];if(s){r+=u,s=!1;continue}if(u==="\\"){s=!0;continue}if(u==="`"){const f=c;for(;c+1<t.length&&t[c+1]==="`";)c+=1;const p=c-f+1;r+="`".repeat(p),i===0?i=p:i===p&&(i=0);continue}if(i===0&&u==="["?a+=1:i===0&&u==="]"&&a>0&&(a-=1),u==="|"&&i===0&&a===0){n.push(r.trim()),r="";continue}r+=u}return s&&(r+="\\"),n.push(r.trim()),n}function oC(e){return ch(e).map(t=>/^:-+:$/.test(t)?"center":/^-+:$/.test(t)?"right":/^:-+$/.test(t)?"left":null)}function og(e){return e==="center"?"text-center":e==="right"?"text-right":"text-left"}function ag(e){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(e.trim())}function Ree(e,t){return e>96||e>44&&t>.35}function dv(e){return(e.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function fv(e){const t=e.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!t)return null;const n=/^\d+[.)]$/.test(t[1]);return{ordered:n,start:n?Number.parseInt(t[1],10):void 0,content:t[2]}}function aC(e,t,n,r,s,i=new Set){const a=[],c=[];let u=t;for(;u<e.length;){const f=e[u];if(s&&(sg(f)||i.has(u))){u+=1;continue}const p=fv(f),g=dv(f);if(!p){if(g>n&&c.length>0){([...c].reverse().find(A=>A.indent<g)?.item??c[c.length-1].item).paragraphs.push(f.trim());for(const A of c)A.item.lineEnd=u+1;u+=1;continue}break}if(g<n||g===n&&p.ordered!==r)break;const y={content:p.content,ordered:p.ordered,start:p.start,children:[],paragraphs:[],lineStart:u+1,lineEnd:u+1};for(;c.length>0&&c[c.length-1].indent>=g;)c.pop();const v=c[c.length-1]?.item??null;v?v.children.push(y):a.push(y),c.push({indent:g,item:y});for(const S of c)S.item.lineEnd=u+1;u+=1}return{items:a,nextIndex:u}}function hv(e,t,n,r=0){return e.map((s,i)=>{const a=s.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${i}`,taskItem:!!a,refStart:s.lineStart+r,refEnd:s.lineEnd+r,content:o.jsxs(o.Fragment,{children:[a?o.jsx("input",{type:"checkbox",checked:a[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,Ci(a?.[2]??s.content,`li-${t}-${i}`,!0,n),s.paragraphs.length>0&&o.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:s.paragraphs.map((c,u)=>o.jsx("p",{children:Ci(c,`li-${t}-${i}-p-${u}`,!0,n)},`paragraph-${u}`))})]}),groups:Nee(s.children,`${t}-${i}`,n,r)}})}function Nee(e,t,n,r=0){const s=[];for(const i of e){const a=s[s.length-1];a&&a.ordered===i.ordered?a.items.push(i):s.push({ordered:i.ordered,items:[i]})}return s.map((i,a)=>({ordered:i.ordered,start:i.ordered?i.items[0]?.start:void 0,items:hv(i.items,`${t}-g${a}`,n,r)}))}function pv(e,t){return e.map(n=>{const r=!!(t&&n.refStart<=t.end&&n.refEnd>=t.start);return o.jsxs("li",{className:n.taskItem?"list-none":void 0,"data-md-ref-start":n.refStart,"data-md-ref-end":n.refEnd,"data-selected":r?"true":void 0,children:[n.content,n.groups.length>0&&Mee(n.groups,t)]},n.key)})}function Mee(e,t){return e.map((n,r)=>{const s=n.ordered?"ol":"ul";return o.jsx(s,{start:n.start,className:`${n.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:pv(n.items,t)},`nested-${r}`)})}function Dee(e){const t=Array.from(e.footnoteDefinitions.values()).sort((n,r)=>n.index-r.index);return t.length===0?null:o.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[o.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:e.footnotesLabel}),o.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:t.map(n=>o.jsxs("li",{id:`fn-${n.id}`,children:[Ci(n.text,`footnote-${n.id}`,!0,e)," ",o.jsx("a",{href:`#fnref-${n.id}`,className:"text-primary no-underline","aria-label":e.backToFootnoteLabel(n.index),children:"↩"})]},n.id))})]})}function jee(e,t,n,r){const s=[];let i=0;const a=c=>r?.[c]??c+1;for(;i<e.length;){const c=e[i],u=c.trim();if(!u){i+=1;continue}if(/^<details>\s*$/i.test(u)){const L=i;let I="Details";const j=[];for(i+=1;i<e.length&&!/^<\/details>\s*$/i.test(e[i].trim());){const P=e[i].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);P?I=P[1].trim()||I:j.push(e[i].trimStart()),i+=1}i<e.length&&(i+=1),s.push({kind:"static",node:o.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[o.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:Ci(I,`${t}-details-${L}-summary`,!0,n)}),j.length>0&&o.jsx("div",{className:"mt-2 text-sm leading-6",children:iC(j,`${t}-details-${L}`,n)})]},`${t}-details-${L}`)});continue}const f=tC(c);if(f){const L=[c],I=i;for(i+=1;i<e.length&&!f.selfContained&&!new RegExp(`</${f.tag}>`,"i").test(e[i]);)L.push(e[i]),i+=1;i<e.length&&!f.selfContained&&(L.push(e[i]),i+=1),s.push({kind:"static",node:o.jsx(eC,{html:L.join(`
180
180
  `)},`${t}-html-${I}`)});continue}const p=u.match(/^(```|~~~)\s*(.*)$/);if(p){const L=[],I=p[1],j=p[2]?.trim(),P=i;for(i+=1;i<e.length&&!e[i].trim().startsWith(I);)L.push(e[i]),i+=1;i<e.length&&(i+=1),j.toLowerCase()==="mermaid"?s.push({kind:"static",node:o.jsx(cC,{code:L.join(`
181
181
  `),blockKey:`${t}-code-${P}`},`${t}-code-${P}`)}):["math","latex","tex"].includes(j.toLowerCase())?s.push({kind:"static",node:o.jsx(lh,{tex:L.join(`
182
182
  `),display:!0},`${t}-code-${P}`)}):s.push({kind:"code",key:`${t}-code-${P}`,code:L.join(`
183
183
  `),lang:j,blockKey:`${t}-code-${P}`,codeStartLine:a(P)+1});continue}if(ig(c)){const L=[],I=i;for(;i<e.length&&(ig(e[i])||!e[i].trim());)L.push(e[i].trim()?sC(e[i]):""),i+=1;s.push({kind:"code",key:`${t}-indented-code-${I}`,code:L.join(`
184
- `).replace(/\n+$/,""),lang:"",blockKey:`${t}-indented-code-${I}`,codeStartLine:a(I)});continue}const g=u.match(/^(#{1,6})\s+(.+)$/);if(g){const I=`h${Math.min(6,g[1].length+1)}`,j=WT(g[2]),P=Q2(j,n);s.push({kind:"static",node:o.jsx(I,{id:P,className:"scroll-mt-16 font-semibold text-foreground",children:Ci(j,`${t}-heading-${i}`,!0,n)},`${t}-heading-${i}`)}),i+=1;continue}if(i+1<e.length&&c.includes("|")&&ag(e[i+1])){const L=ch(c),I=oC(e[i+1]),j=[],P=i;for(i+=2;i<e.length&&e[i].includes("|")&&e[i].trim();)j.push(ch(e[i])),i+=1;s.push({kind:"static",node:o.jsx("div",{className:FT,"data-markdown-table-scroll":!0,children:o.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[o.jsx("thead",{className:"bg-surface-2 text-foreground",children:o.jsx("tr",{children:L.map((F,R)=>o.jsx("th",{className:`${PT} ${og(I[R]??null)}`,children:o.jsx("div",{className:rg,children:Ci(F,`${t}-th-${P}-${R}`,!0,n)})},`h-${R}`))})}),o.jsx("tbody",{children:j.map((F,R)=>o.jsx("tr",{className:"border-t border-border/10",children:L.map((C,$)=>o.jsx("td",{className:`${BT} ${og(I[$]??null)}`,children:o.jsx("div",{className:rg,children:Ci(F[$]??"",`${t}-td-${P}-${R}-${$}`,!0,n)})},`c-${$}`))},`r-${R}`))})]})},`${t}-table-${P}`)});continue}const y=fv(c);if(y){const L=y.ordered,I=dv(c),j=y.start,P=i,F=aC(e,i,I,L,!1);i=F.nextIndex,s.push({kind:"list",keyPrefix:`${t}-list-${P}`,ordered:L,start:L?j:void 0,renders:hv(F.items,`${t}-list-${P}`,n,a(0)-1)});continue}const v=[c.trimStart()],S=[a(i)],A=i;for(i+=1;i<e.length&&e[i].trim()&&!O2(e[i])&&!(i+1<e.length&&e[i].includes("|")&&ag(e[i+1]));)v.push(e[i].trimStart()),S.push(a(i)),i+=1;const T=U2(v,`${t}-p-${A}`,n);s.push({kind:"paragraph",keyPrefix:`${t}-p-${A}`,perLine:T.perLine,hardBreaks:T.hardBreaks,lineNums:S})}return s}function Mee(e,t){return e.map(n=>{switch(n.kind){case"static":return n.node;case"paragraph":return o.jsx("p",{children:z2(n.perLine,n.hardBreaks,n.lineNums,n.keyPrefix,t)},n.keyPrefix);case"list":{const r=n.ordered?"ol":"ul";return o.jsx(r,{start:n.start,className:`${n.ordered?"list-decimal":"list-disc"} space-y-0.5 pl-4 marker:text-muted-foreground/70`,children:pv(n.renders,t)},n.keyPrefix)}case"code":return o.jsx(lg,{code:n.code,lang:n.lang,blockKey:n.blockKey,codeStartLine:n.codeStartLine,lineRange:t},n.key)}})}let zp=null,G4=!1;const Gp=16,lC=192;function Dee(){return zp||(zp=g0(()=>import("./mermaid.core-kFgOOXNm.js").then(e=>e.aJ),__vite__mapDeps([6,1,7])).then(e=>e.default??e).catch(e=>{throw zp=null,e})),zp}function jee(e){G4||(e.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),G4=!0)}function Pee(e){const t=e.match(/\sviewBox=(["'])([^"']+)\1/i);if(!t)return e;const[,,n]=t,r=n.trim().split(/[\s,]+/).map(Number),[,,s,i]=r;if(!Number.isFinite(s)||!Number.isFinite(i)||s<=0||i<=0)return e;const a=Math.max(lC,Math.ceil(s)),c=Math.ceil(a/s*i);return e.replace(/<svg\b([^>]*)>/i,(u,f)=>`<svg${f.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${a}" height="${c}">`)}function Bee(e){const t=e?.querySelector("svg");if(!t)return;let n;try{n=t.getBBox()}catch{return}if(!Number.isFinite(n.width)||!Number.isFinite(n.height)||n.width<=0||n.height<=0)return;const r=n.x-Gp,s=n.y-Gp,i=n.width+Gp*2,a=n.height+Gp*2,c=Math.max(lC,Math.ceil(i)),u=Math.ceil(c/i*a);t.setAttribute("viewBox",`${r} ${s} ${i} ${a}`),t.setAttribute("width",String(c)),t.setAttribute("height",String(u)),t.removeAttribute("style")}function Fee(e){const t=e.trim().split(/\s+/,1)[0]?.toLowerCase();if(!t)return null;const n=t.replace(/^language-/,"");return r0(`code.${n}`)??n}function cC({code:e,blockKey:t}){const{t:n}=Yn(),[r,s]=b.useState(null),[i,a]=b.useState(!1),c=b.useRef(null),u=b.useContext(zT);b.useEffect(()=>{let p=!1;return s(null),a(!1),Dee().then(async g=>{jee(g);const y=`termdock-md-mermaid-${t.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:v}=await g.render(y,e);p||s(Pee(v))}).catch(()=>{p||a(!0)}),()=>{p=!0}},[t,e]),b.useLayoutEffect(()=>{r&&Bee(c.current)},[r]);const f=b.useCallback(()=>{const p=c.current?.querySelector("svg")?.outerHTML??r;p&&u?.(p)},[u,r]);return i?o.jsx(lg,{code:e,lang:"mermaid",blockKey:`${t}-fallback`}):o.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[o.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),o.jsx("div",{className:"bg-surface p-3",children:r?o.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:n("rightSidebar.openMermaidDiagram"),onClick:p=>{p.stopPropagation(),f()},children:o.jsx("span",{ref:c,role:"img","aria-label":n("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:r}})}):o.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:n("rightSidebar.renderingDiagram")})})]})}function lg({code:e,lang:t,blockKey:n,codeStartLine:r,lineRange:s}){const i=Fee(t),[a,c]=b.useState(null);b.useEffect(()=>{if(!i||!sT(e)){c(null);return}let f=!1;return iT().then(p=>{if(f||!p.registered(i)){f||c(null);return}try{c(oT(p,e,i))}catch{f||c(null)}}).catch(()=>{f||c(null)}),()=>{f=!0}},[n,e,i]);const u=a??(e||" ").split(`
184
+ `).replace(/\n+$/,""),lang:"",blockKey:`${t}-indented-code-${I}`,codeStartLine:a(I)});continue}const g=u.match(/^(#{1,6})\s+(.+)$/);if(g){const I=`h${Math.min(6,g[1].length+1)}`,j=WT(g[2]),P=Q2(j,n);s.push({kind:"static",node:o.jsx(I,{id:P,className:"scroll-mt-16 font-semibold text-foreground",children:Ci(j,`${t}-heading-${i}`,!0,n)},`${t}-heading-${i}`)}),i+=1;continue}if(i+1<e.length&&c.includes("|")&&ag(e[i+1])){const L=ch(c),I=oC(e[i+1]),j=[],P=i;for(i+=2;i<e.length&&e[i].includes("|")&&e[i].trim();)j.push(ch(e[i])),i+=1;s.push({kind:"static",node:o.jsx("div",{className:FT,"data-markdown-table-scroll":!0,children:o.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[o.jsx("thead",{className:"bg-surface-2 text-foreground",children:o.jsx("tr",{children:L.map((F,R)=>o.jsx("th",{className:`${PT} ${og(I[R]??null)}`,children:o.jsx("div",{className:rg,children:Ci(F,`${t}-th-${P}-${R}`,!0,n)})},`h-${R}`))})}),o.jsx("tbody",{children:j.map((F,R)=>o.jsx("tr",{className:"border-t border-border/10",children:L.map((C,$)=>o.jsx("td",{className:`${BT} ${og(I[$]??null)}`,children:o.jsx("div",{className:rg,children:Ci(F[$]??"",`${t}-td-${P}-${R}-${$}`,!0,n)})},`c-${$}`))},`r-${R}`))})]})},`${t}-table-${P}`)});continue}const y=fv(c);if(y){const L=y.ordered,I=dv(c),j=y.start,P=i,F=aC(e,i,I,L,!1);i=F.nextIndex,s.push({kind:"list",keyPrefix:`${t}-list-${P}`,ordered:L,start:L?j:void 0,renders:hv(F.items,`${t}-list-${P}`,n,a(0)-1)});continue}const v=[c.trimStart()],S=[a(i)],A=i;for(i+=1;i<e.length&&e[i].trim()&&!O2(e[i])&&!(i+1<e.length&&e[i].includes("|")&&ag(e[i+1]));)v.push(e[i].trimStart()),S.push(a(i)),i+=1;const T=U2(v,`${t}-p-${A}`,n);s.push({kind:"paragraph",keyPrefix:`${t}-p-${A}`,perLine:T.perLine,hardBreaks:T.hardBreaks,lineNums:S})}return s}function Pee(e,t){return e.map(n=>{switch(n.kind){case"static":return n.node;case"paragraph":return o.jsx("p",{children:z2(n.perLine,n.hardBreaks,n.lineNums,n.keyPrefix,t)},n.keyPrefix);case"list":{const r=n.ordered?"ol":"ul";return o.jsx(r,{start:n.start,className:`${n.ordered?"list-decimal":"list-disc"} space-y-0.5 pl-4 marker:text-muted-foreground/70`,children:pv(n.renders,t)},n.keyPrefix)}case"code":return o.jsx(lg,{code:n.code,lang:n.lang,blockKey:n.blockKey,codeStartLine:n.codeStartLine,lineRange:t},n.key)}})}let zp=null,G4=!1;const Gp=16,lC=192;function Bee(){return zp||(zp=g0(()=>import("./mermaid.core-C2fDWTc4.js").then(e=>e.aJ),__vite__mapDeps([6,1,7])).then(e=>e.default??e).catch(e=>{throw zp=null,e})),zp}function Fee(e){G4||(e.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),G4=!0)}function Oee(e){const t=e.match(/\sviewBox=(["'])([^"']+)\1/i);if(!t)return e;const[,,n]=t,r=n.trim().split(/[\s,]+/).map(Number),[,,s,i]=r;if(!Number.isFinite(s)||!Number.isFinite(i)||s<=0||i<=0)return e;const a=Math.max(lC,Math.ceil(s)),c=Math.ceil(a/s*i);return e.replace(/<svg\b([^>]*)>/i,(u,f)=>`<svg${f.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${a}" height="${c}">`)}function Qee(e){const t=e?.querySelector("svg");if(!t)return;let n;try{n=t.getBBox()}catch{return}if(!Number.isFinite(n.width)||!Number.isFinite(n.height)||n.width<=0||n.height<=0)return;const r=n.x-Gp,s=n.y-Gp,i=n.width+Gp*2,a=n.height+Gp*2,c=Math.max(lC,Math.ceil(i)),u=Math.ceil(c/i*a);t.setAttribute("viewBox",`${r} ${s} ${i} ${a}`),t.setAttribute("width",String(c)),t.setAttribute("height",String(u)),t.removeAttribute("style")}function $ee(e){const t=e.trim().split(/\s+/,1)[0]?.toLowerCase();if(!t)return null;const n=t.replace(/^language-/,"");return r0(`code.${n}`)??n}function cC({code:e,blockKey:t}){const{t:n}=Yn(),[r,s]=b.useState(null),[i,a]=b.useState(!1),c=b.useRef(null),u=b.useContext(zT);b.useEffect(()=>{let p=!1;return s(null),a(!1),Bee().then(async g=>{Fee(g);const y=`termdock-md-mermaid-${t.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:v}=await g.render(y,e);p||s(Oee(v))}).catch(()=>{p||a(!0)}),()=>{p=!0}},[t,e]),b.useLayoutEffect(()=>{r&&Qee(c.current)},[r]);const f=b.useCallback(()=>{const p=c.current?.querySelector("svg")?.outerHTML??r;p&&u?.(p)},[u,r]);return i?o.jsx(lg,{code:e,lang:"mermaid",blockKey:`${t}-fallback`}):o.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[o.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),o.jsx("div",{className:"bg-surface p-3",children:r?o.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:n("rightSidebar.openMermaidDiagram"),onClick:p=>{p.stopPropagation(),f()},children:o.jsx("span",{ref:c,role:"img","aria-label":n("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:r}})}):o.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:n("rightSidebar.renderingDiagram")})})]})}function lg({code:e,lang:t,blockKey:n,codeStartLine:r,lineRange:s}){const i=$ee(t),[a,c]=b.useState(null);b.useEffect(()=>{if(!i||!sT(e)){c(null);return}let f=!1;return iT().then(p=>{if(f||!p.registered(i)){f||c(null);return}try{c(oT(p,e,i))}catch{f||c(null)}}).catch(()=>{f||c(null)}),()=>{f=!0}},[n,e,i]);const u=a??(e||" ").split(`
185
185
  `).map(f=>[f||" "]);return o.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[t&&o.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:t}),o.jsx("pre",{className:`${cv} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:o.jsx("code",{children:u.map((f,p)=>{const g=r!=null?r+p:null,y=!!(s&&g!=null&&g>=s.start&&g<=s.end);return o.jsxs("span",{"data-md-ref-start":g??void 0,"data-md-ref-end":g??void 0,"data-selected":y?"true":void 0,children:[f,p<u.length-1?`
186
- `:null]},`${n}-line-${p}`)})})})]})}function Oee(e,t,n,r,s){e=mee(e);const i=fee(e),a=pee(e),c=[],u={markdownFilePath:t,rootPath:n,referenceDefinitions:i,footnoteDefinitions:hee(e),headingSlugCounts:new Map,images:c,onImageOpen:r,footnotesLabel:s?.footnotes??"Footnotes",backToFootnoteLabel:s?.backToFootnote??(y=>`Back to footnote ${y}`)},f=[];let p=0;for(;p<e.length;){const y=e[p],v=y.trim();if(sg(y)||a.has(p)){p+=1;continue}if(!v){p+=1;continue}if(/^<details>\s*$/i.test(v)){const R=p;let C="Details";const $=[];for(p+=1;p<e.length&&!/^<\/details>\s*$/i.test(e[p].trim());){const H=e[p].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);H?C=H[1].trim()||C:$.push(e[p].trimStart()),p+=1}p<e.length&&(p+=1),f.push({key:`details-${R}`,startLine:R+1,endLine:p,content:o.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[o.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:Ci(C,`details-${R}-summary`,!0,u)}),$.length>0&&o.jsx("div",{className:"mt-2 text-sm leading-6",children:iC($,`details-${R}`,u)})]})});continue}const S=tC(y);if(S){const R=[y],C=p;for(p+=1;p<e.length&&!S.selfContained&&!new RegExp(`</${S.tag}>`,"i").test(e[p]);)R.push(e[p]),p+=1;p<e.length&&!S.selfContained&&(R.push(e[p]),p+=1),f.push({key:`html-${C}`,startLine:C+1,endLine:p,content:o.jsx(eC,{html:R.join(`
186
+ `:null]},`${n}-line-${p}`)})})})]})}function Hee(e,t,n,r,s){e=bee(e);const i=mee(e),a=xee(e),c=[],u={markdownFilePath:t,rootPath:n,referenceDefinitions:i,footnoteDefinitions:gee(e),headingSlugCounts:new Map,images:c,onImageOpen:r,footnotesLabel:s?.footnotes??"Footnotes",backToFootnoteLabel:s?.backToFootnote??(y=>`Back to footnote ${y}`)},f=[];let p=0;for(;p<e.length;){const y=e[p],v=y.trim();if(sg(y)||a.has(p)){p+=1;continue}if(!v){p+=1;continue}if(/^<details>\s*$/i.test(v)){const R=p;let C="Details";const $=[];for(p+=1;p<e.length&&!/^<\/details>\s*$/i.test(e[p].trim());){const H=e[p].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);H?C=H[1].trim()||C:$.push(e[p].trimStart()),p+=1}p<e.length&&(p+=1),f.push({key:`details-${R}`,startLine:R+1,endLine:p,content:o.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[o.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:Ci(C,`details-${R}-summary`,!0,u)}),$.length>0&&o.jsx("div",{className:"mt-2 text-sm leading-6",children:iC($,`details-${R}`,u)})]})});continue}const S=tC(y);if(S){const R=[y],C=p;for(p+=1;p<e.length&&!S.selfContained&&!new RegExp(`</${S.tag}>`,"i").test(e[p]);)R.push(e[p]),p+=1;p<e.length&&!S.selfContained&&(R.push(e[p]),p+=1),f.push({key:`html-${C}`,startLine:C+1,endLine:p,content:o.jsx(eC,{html:R.join(`
187
187
  `)})});continue}const A=v.match(/^(```|~~~)\s*(.*)$/);if(A){const R=[],C=A[1],$=A[2]?.trim(),H=p;for(p+=1;p<e.length&&!e[p].trim().startsWith(C);)R.push(e[p]),p+=1;p<e.length&&(p+=1),f.push({key:`code-${H}`,startLine:H+1,endLine:p,fineGrained:$.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes($.toLowerCase()),content:$.toLowerCase()==="mermaid"?o.jsx(cC,{code:R.join(`
188
188
  `),blockKey:`code-${H}`}):["math","latex","tex"].includes($.toLowerCase())?o.jsx(lh,{tex:R.join(`
189
189
  `),display:!0}):Y=>o.jsx(lg,{code:R.join(`
190
190
  `),lang:$,blockKey:`code-${H}`,codeStartLine:H+2,lineRange:Y})});continue}if(ig(y)){const R=[],C=p;for(p+=0;p<e.length&&(ig(e[p])||!e[p].trim());)R.push(e[p].trim()?sC(e[p]):""),p+=1;f.push({key:`indented-code-${C}`,startLine:C+1,endLine:p,fineGrained:!0,content:$=>o.jsx(lg,{code:R.join(`
191
191
  `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${C}`,codeStartLine:C+1,lineRange:$})});continue}if(v.startsWith("$$")){const R=[],C=p,$=v.replace(/^\$\$\s*/,"");if($.endsWith("$$")&&$.length>2)R.push($.replace(/\s*\$\$$/,"")),p+=1;else{for($&&R.push($),p+=1;p<e.length&&!e[p].trim().endsWith("$$");)R.push(e[p]),p+=1;if(p<e.length){const H=e[p].trim().replace(/\s*\$\$$/,"");H&&R.push(H),p+=1}}f.push({key:`math-${C}`,startLine:C+1,endLine:p,content:o.jsx(lh,{tex:R.join(`
192
- `),display:!0})});continue}if(p+1<e.length&&v&&!O2(y)&&/^(=+|-+)\s*$/.test(e[p+1].trim())){const R=e[p+1].trim().startsWith("=")?1:2,C=`h${R}`,$=Q2(v,u),H={level:R,text:H4(v),id:$};f.push({key:`setext-heading-${p}`,startLine:p+1,endLine:p+2,heading:H,content:o.jsx(C,{id:$,className:`scroll-mt-16 font-semibold text-foreground ${R===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:Ci(v,`setext-heading-${p}`,!0,u)})}),p+=2;continue}const T=v.match(/^(#{1,6})\s+(.+)$/);if(T){const R=T[1].length,C=WT(T[2]),$={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},H=`h${R}`,Y=Q2(C,u),V={level:R,text:H4(C),id:Y};f.push({key:`heading-${p}`,startLine:p+1,endLine:p+1,heading:V,content:o.jsx(H,{id:Y,className:`scroll-mt-16 font-semibold text-foreground ${$[R]}`,children:Ci(C,`heading-${p}`,!0,u)})}),p+=1;continue}if(UT(y)){f.push({key:`hr-${p}`,startLine:p+1,endLine:p+1,content:o.jsx("hr",{className:"border-border/20"})}),p+=1;continue}if(v.startsWith(">")){const R=[],C=[],$=p;for(;p<e.length&&/^>\s?/.test(e[p].trim());)R.push(e[p].trim().replace(/^>\s?/,"")),C.push(p+1),p+=1;const H=R[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(H){const V=H[1].toUpperCase(),fe=H[2]?.trim(),X=[...fe?[fe]:[],...R.slice(1)],ve=[...fe?[C[0]]:[],...C.slice(1)],we=U2(X,`callout-${$}`,u);f.push({key:`callout-${$}`,startLine:$+1,endLine:p,fineGrained:!0,content:ie=>o.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[o.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:V}),X.length>0&&o.jsx("div",{children:z2(we.perLine,we.hardBreaks,ve,`callout-${$}`,ie)})]})});continue}const Y=Nee(R,`quote-${$}`,u,C);f.push({key:`quote-${$}`,startLine:$+1,endLine:p,fineGrained:!0,content:V=>o.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:Mee(Y,V)})});continue}if(p+1<e.length&&y.includes("|")&&ag(e[p+1])){const R=ch(y),C=oC(e[p+1]),$=[],H=p;for(p+=2;p<e.length&&e[p].includes("|")&&e[p].trim();)$.push(ch(e[p])),p+=1;const Y=R.map((fe,X)=>Ci(fe,`th-${H}-${X}`,!0,u)),V=$.map((fe,X)=>R.map((ve,we)=>Ci(fe[we]??"",`td-${H}-${X}-${we}`,!0,u)));f.push({key:`table-${H}`,startLine:H+1,endLine:p,interactive:!1,kind:"table",content:fe=>{const X=ve=>!!(fe&&ve>=fe.start&&ve<=fe.end);return o.jsx("div",{className:FT,"data-markdown-table-scroll":!0,children:o.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[o.jsx("thead",{className:"bg-surface-2 text-foreground",children:o.jsx("tr",{"data-markdown-table-row-line":H+1,"data-md-ref-start":H+1,"data-md-ref-end":H+1,"data-selected":X(H+1)?"true":void 0,children:Y.map((ve,we)=>o.jsx("th",{className:`${PT} ${og(C[we]??null)}`,children:o.jsx("div",{className:rg,children:ve})},`h-${we}`))})}),o.jsx("tbody",{children:V.map((ve,we)=>{const ie=H+we+3;return o.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":ie,"data-md-ref-start":ie,"data-md-ref-end":ie,"data-selected":X(ie)?"true":void 0,children:R.map((ae,q)=>o.jsx("td",{className:`${BT} ${og(C[q]??null)}`,children:o.jsx("div",{className:rg,children:ve[q]})},`c-${q}`))},`r-${we}`)})})]})})}});continue}const L=fv(y);if(L){const R=L.ordered,C=dv(y),$=L.start,H=p,Y=aC(e,p,C,R,!0,a);p=Y.nextIndex;const V=R?"ol":"ul",fe=hv(Y.items,`list-${H}`,u);f.push({key:`list-${H}`,startLine:H+1,endLine:p,fineGrained:!0,content:X=>o.jsx(V,{start:R?$:void 0,className:`${R?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:pv(fe,X)})});continue}const I=[y.trimStart()],j=[p+1],P=p;for(p+=1;p<e.length&&e[p].trim()&&!O2(e[p])&&!(p+1<e.length&&e[p].includes("|")&&ag(e[p+1]));){if(sg(e[p])||a.has(p)){p+=1;continue}I.push(e[p].trimStart()),j.push(p+1),p+=1}const F=U2(I,`p-${P}`,u);f.push({key:`p-${P}`,startLine:P+1,endLine:p,fineGrained:!0,content:R=>o.jsx("p",{className:"text-muted-foreground",children:z2(F.perLine,F.hardBreaks,j,`p-${P}`,R)})})}const g=Ree(u);return g&&f.push({key:"footnotes",startLine:e.length,endLine:e.length,content:g}),{blocks:f,images:c}}function Qee(e,t){const n=[];for(const r of e){if(r.startLine>t)break;if(r.heading){for(;n.length>0&&n[n.length-1].level>=r.heading.level;)n.pop();n.push({...r.heading,startLine:r.startLine})}}return n}function $ee(e){return e.filter(t=>!!t.heading).map(t=>({...t.heading,startLine:t.startLine}))}function Hee({src:e,alt:t,onZoomChange:n,onDoubleTap:r}){const s=KT(e);return o.jsx(yC,{src:s,alt:t,onLoad:()=>{},onError:()=>{},onZoomChange:n,onDoubleTap:r})}function Uee({images:e,index:t,onChange:n,onClose:r}){const{t:s}=Yn(),i=e[t],a=e.length>1,c=b.useRef(null),u=b.useRef(null),f=b.useRef(null),p=b.useRef(0),[g,y]=b.useState(!1),[v,S]=b.useState(0),[A,T]=b.useState(!1),L=b.useCallback(()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},[]),I=b.useCallback(()=>{g||Date.now()<p.current||(L(),f.current=window.setTimeout(()=>{f.current=null,r()},450))},[L,g,r]),j=b.useCallback(C=>{if(e.length===0)return;const $=(C+e.length)%e.length;c.current?.slideTo($),n($)},[e.length,n]),P=b.useCallback(()=>j(t-1),[j,t]),F=b.useCallback(()=>j(t+1),[j,t]);if(b.useEffect(()=>{L(),S(0),T(!1),y(!1)},[L,t]),b.useEffect(()=>{const C=c.current;C&&(C.allowTouchMove=a&&!g)},[a,g]),b.useEffect(()=>{const C=c.current;!C||C.activeIndex===t||C.slideTo(t,0)},[t]),b.useEffect(()=>L,[L]),b.useEffect(()=>{const C=$=>{if($.key==="Escape"){$.preventDefault(),r();return}a&&($.key==="ArrowLeft"?($.preventDefault(),P()):$.key==="ArrowRight"&&($.preventDefault(),F()))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[a,F,P,r]),b9({onDrag:({movement:[C,$],pinching:H})=>{H||g||Math.abs($)<Math.abs(C)*1.15&&v===0||(T(!0),Math.abs($)>8&&(p.current=Date.now()+300),S(Math.max(0,$)))},onDragEnd:({movement:[,C],velocity:[,$]})=>{if(!g){if(T(!1),Math.abs(C)>8&&(p.current=Date.now()+300),Lee(C,$)){r();return}S(0)}}},{target:u,drag:{filterTaps:!0,pointer:{touch:!0}}}),!i)return null;const R=i.title||i.alt||(i.kind==="mermaid"?s("rightSidebar.mermaidDiagram"):s("rightSidebar.image"));return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:r}),o.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[o.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate text-sm font-medium",children:R}),o.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[t+1," / ",e.length]})]}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[a&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:P,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":s("rightSidebar.previousImage"),title:s("common.previous"),children:o.jsx(l0,{size:17})}),o.jsx("button",{type:"button",onClick:F,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":s("rightSidebar.nextImage"),title:s("common.next"),children:o.jsx(m8,{size:17})})]}),o.jsx("button",{type:"button",onClick:r,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":s("rightSidebar.closeImagePreview"),title:s("common.close"),children:o.jsx(ts,{size:18})})]})]}),o.jsx("div",{ref:u,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onPointerDown:C=>C.stopPropagation(),onPointerMove:C=>C.stopPropagation(),onTouchStart:C=>C.stopPropagation(),onTouchMove:C=>C.stopPropagation(),onClick:I,children:o.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${v}px, 0) scale(${Math.max(.86,1-v/900)})`,opacity:Math.max(.35,1-v/360),transition:A?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:o.jsx(uh,{onSwiper:C=>{c.current=C,C.allowTouchMove=a&&!g},onSlideChange:C=>{C.activeIndex!==t&&n(C.activeIndex)},initialSlide:t,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:e.map((C,$)=>o.jsx(Gu,{className:"h-full",children:o.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:C.kind==="image"?o.jsx(Hee,{src:C.src,alt:C.alt||C.title||s("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:L}):o.jsx(ote,{svg:C.svg,title:C.title||C.alt||s("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:L})})},`${C.kind}-${$}-${C.alt}`))})})})]})]})}function zee({content:e,filePath:t,rootPath:n,lineRange:r,onLineRangeClick:s,onLineRangeDrag:i,scrollTop:a,outlineOpen:c,outlineCloseSignal:u,onOutlineOpen:f,onOutlineClose:p,lightboxOpen:g,lightboxCloseSignal:y,onLightboxOpen:v,onLightboxClose:S,onLocalLinkOpen:A}){const{t:T}=Yn(),[L,I]=b.useState(null),[j,P]=b.useState(null),[F,R]=b.useState(1),[C,$]=b.useState(null),H=b.useRef(null),Y=b.useRef(null),{blocks:V,images:fe}=b.useMemo(()=>Oee(e.split(`
193
- `),t,n,Te=>{P(null),I(Te),v?.()},{footnotes:T("rightSidebar.footnotes"),backToFootnote:Te=>T("rightSidebar.backToFootnote",{index:Te})}),[e,t,n,v,T]),X=b.useMemo(()=>j?[...fe,j]:fe,[fe,j]),ve=b.useCallback(Te=>{P({kind:"mermaid",svg:Te,alt:"Mermaid diagram",title:"Mermaid diagram"}),I(fe.length),v?.()},[fe.length,v]);b.useEffect(()=>{I(null),P(null)},[e,t]),b.useEffect(()=>{I(null),P(null)},[y]),b.useEffect(()=>{g||(I(null),P(null))},[g]),b.useEffect(()=>{R(1)},[e,t]),b.useLayoutEffect(()=>{const Te=H.current;if(!Te||V.length===0)return;const ze=Array.from(Te.querySelectorAll("[data-markdown-preview-block-start]"));let Be=1;const We=28;for(const W of ze)if(W.offsetTop-a<=We)Be=Number(W.dataset.markdownPreviewBlockStart)||Be;else break;R(W=>W===Be?W:Be)},[V,a]);const we=b.useMemo(()=>Qee(V,F),[F,V]),ie=b.useMemo(()=>$ee(V),[V]),ae=`${t??""}
194
- ${e}`,q=b.useRef(ae),z=b.useRef(null),te=b.useRef(null),pe=b.useRef(!1);b.useEffect(()=>{q.current!==ae&&(q.current=ae,p?.())},[p,ae]),b.useEffect(()=>{u!==void 0&&$(null)},[u]),b.useLayoutEffect(()=>{if(!c){$(null);return}const Te=()=>{const ze=Y.current;if(!ze)return;const Be=ze.getBoundingClientRect(),We=window.innerWidth;$({top:Be.bottom+6,right:Math.max(8,We-Be.right)})};return Te(),window.addEventListener("resize",Te),window.addEventListener("scroll",Te,!0),()=>{window.removeEventListener("resize",Te),window.removeEventListener("scroll",Te,!0)}},[c,a,we]);const de=b.useCallback(Te=>{const ze=H.current,Be=ze?.closest("[data-markdown-preview-scroller]"),We=ze?.querySelector(`[data-markdown-preview-block-start="${Te.startLine}"]`);if(!Be||!We)return;const W=Be.getBoundingClientRect(),xe=We.getBoundingClientRect(),Ce=ze?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,Qe=xe.top-W.top+Be.scrollTop;Be.scrollTo({top:Math.max(0,Qe-Ce-8),behavior:"smooth"}),R(Te.startLine),p?.()},[p]),ke=b.useCallback(Te=>{Te.pointerType==="mouse"&&Te.button!==0||db(Te.target)||(z.current={pointerId:Te.pointerId,startX:Te.clientX,startY:Te.clientY})},[]),be=b.useCallback((Te,ze,Be)=>{const We=z.current;if(z.current=null,!We||We.pointerId!==Te.pointerId)return;const W=Math.abs(Te.clientX-We.startX),xe=Math.abs(Te.clientY-We.startY);if(W>8||xe>8)return;const He=Te.target;if(db(He)||G2())return;const Ce=t7(He,ze,Be);s(Te,Ce.start,Ce.end)},[s]),oe=b.useCallback(Te=>{z.current?.pointerId===Te.pointerId&&(z.current=null)},[]),he=b.useCallback((Te,ze)=>{const Be=H.current;if(!Be||typeof document.elementFromPoint!="function")return null;const We=document.elementFromPoint(Te,ze);if(!(We instanceof HTMLElement)||!Be.contains(We))return null;const W=We.closest("[data-md-ref-start]");if(W){const At=Number(W.dataset.mdRefStart);if(Number.isFinite(At)&&At>0)return At}const xe=We.closest("[data-markdown-preview-block-start]");if(!xe)return null;const He=Number(xe.dataset.markdownPreviewBlockStart),Ce=V.find(At=>At.startLine===He);if(!Ce)return Number.isFinite(He)&&He>0?He:null;if(Ce.endLine<=Ce.startLine)return Ce.startLine;const Qe=xe.getBoundingClientRect(),pt=Qe.height>0?Math.min(1,Math.max(0,(ze-Qe.top)/Qe.height)):0;return Math.round(Ce.startLine+pt*(Ce.endLine-Ce.startLine))},[V]),J=b.useCallback(Te=>{if(!i||Te.pointerType==="mouse"&&Te.button!==0)return;const ze=he(Te.clientX+24,Te.clientY);if(ze!=null){te.current={pointerId:Te.pointerId,anchorLine:ze,moved:!1};try{Te.currentTarget.setPointerCapture(Te.pointerId)}catch{}}},[i,he]),Xe=b.useCallback(Te=>{const ze=te.current;if(!ze||ze.pointerId!==Te.pointerId||!i)return;const Be=he(Te.clientX+16,Te.clientY);Be!=null&&(!ze.moved&&Be===ze.anchorLine||(ze.moved=!0,pe.current=!0,i(Te,Math.min(ze.anchorLine,Be),Math.max(ze.anchorLine,Be),"move")))},[i,he]),lt=b.useCallback(Te=>{const ze=te.current;if(te.current=null,!ze||ze.pointerId!==Te.pointerId||!i||!ze.moved)return;const Be=he(Te.clientX+16,Te.clientY)??ze.anchorLine;i(Te,Math.min(ze.anchorLine,Be),Math.max(ze.anchorLine,Be),"end")},[i,he]),Ze=b.useCallback(Te=>{te.current?.pointerId===Te.pointerId&&(te.current=null)},[]),ge={onPointerDown:J,onPointerMove:Xe,onPointerUp:lt,onPointerCancel:Ze},Fe=()=>pe.current?(pe.current=!1,!0):!1;return V.length===0?o.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:o.jsx("p",{className:"text-muted-foreground",children:T("rightSidebar.emptyFile")})}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{ref:H,className:"relative min-w-0 max-w-full",onClickCapture:Te=>{const ze=Te.target instanceof Element?Te.target.closest("a[href]"):null;if(!ze||!A)return;const Be=ze.getAttribute("href");if(!Be)return;const We=gee(Be,t,n);We&&(Te.preventDefault(),A(We))},children:[we.length>0&&o.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:o.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:we.map(Te=>Te.text).join(" / "),children:[o.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:we[we.length-1].text}),ie.length>1&&o.jsxs("button",{ref:Y,type:"button",onClick:()=>{c?p?.():f?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${c?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":c,"aria-label":T("rightSidebar.markdownOutline"),title:T("rightSidebar.markdownOutline"),children:[o.jsx(oy,{size:12}),o.jsx("span",{children:T("rightSidebar.markdownOutlineShort")})]})]})}),c&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:p}),o.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:C?{top:`${C.top}px`,right:`${C.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:o.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:ie.map(Te=>{const ze=we[we.length-1]?.startLine===Te.startLine;return o.jsxs("button",{type:"button",onClick:()=>de(Te),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${ze?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(Te.level-1,4)*12+8}px`},title:Te.text,children:[o.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ze?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),o.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",Te.level]}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:Te.text})]},`desktop-${Te.id}-${Te.startLine}`)})})}),o.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[o.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[o.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:T("rightSidebar.markdownOutlineShort")}),o.jsx("button",{type:"button",onClick:p,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":T("rightSidebar.closeMarkdownOutline"),title:T("common.close"),children:o.jsx(ts,{size:14})})]}),o.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:ie.map(Te=>{const ze=we[we.length-1]?.startLine===Te.startLine;return o.jsxs("button",{type:"button",onClick:()=>de(Te),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${ze?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(Te.level-1,4)*12+8}px`},title:Te.text,children:[o.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ze?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),o.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",Te.level]}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:Te.text})]},`${Te.id}-${Te.startLine}`)})})]})]}),o.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:o.jsx(zT.Provider,{value:ve,children:V.map(Te=>{const ze=!!(r&&Te.startLine<=r.end&&Te.endLine>=r.start),Be=!!(r&&r.start<=Te.startLine&&r.end>=Te.endLine),We=Te.kind==="table"?!1:Te.fineGrained?Be:ze,W=Te.kind==="table"&&r?.start===Te.startLine&&r.end===Te.endLine;let xe=null;if(Te.kind!=="table"&&Te.fineGrained&&ze&&!Be&&r){const pt=Te.endLine-Te.startLine+1,At=Math.max(r.start,Te.startLine),yt=Math.min(r.end,Te.endLine),Yt=(At-Te.startLine)/pt,Mt=(yt-At+1)/pt;xe=o.jsx("span",{"aria-hidden":"true","data-md-rail-segment":!0,className:"absolute left-1/2 w-0.5 -translate-x-1/2 rounded-full bg-primary transition sm:w-1",style:{top:`calc(0.25rem + (100% - 0.5rem) * ${Yt})`,height:`calc((100% - 0.5rem) * ${Mt})`}})}const He=typeof Te.content=="function"?Te.content(r):Te.content,Ce=Te.startLine===Te.endLine?String(Te.startLine):`${Te.startLine}-${Te.endLine}`,Qe=o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:lb(We),"aria-hidden":"true",...ge,children:[o.jsx("span",{className:cb(We)}),xe]}),o.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:He})]});return Te.interactive===!1?o.jsxs("div",{"data-markdown-preview-block-start":Te.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${We?"bg-primary/10":""}`,title:`Line ${Ce}`,"aria-label":`Line ${Ce}`,children:[Te.kind==="table"?o.jsx("button",{type:"button",className:lb(W,"self"),onClick:pt=>{pt.preventDefault(),!Fe()&&s(pt,Te.startLine,Te.endLine)},title:`Reference table lines ${Ce}`,"aria-label":`Reference table lines ${Ce}`,...ge,children:o.jsx("span",{className:cb(W,"self")})}):o.jsxs("span",{className:lb(We,"none"),"aria-hidden":"true",...ge,children:[o.jsx("span",{className:cb(We,"none")}),xe]}),o.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:ke,onPointerUp:pt=>be(pt,Te.startLine,Te.endLine),onPointerCancel:oe,onKeyDown:pt=>{pt.key!=="Enter"&&pt.key!==" "||(pt.preventDefault(),s(pt,Te.startLine,Te.endLine))},title:`Reference line ${Ce}`,"aria-label":`Reference line ${Ce}`,children:He})]},Te.key):o.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":Te.startLine,onClick:pt=>{const At=pt.target;if(db(At)||G2()||Fe())return;const yt=t7(At,Te.startLine,Te.endLine);s(pt,yt.start,yt.end)},onKeyDown:pt=>{pt.key!=="Enter"&&pt.key!==" "||(pt.preventDefault(),s(pt,Te.startLine,Te.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${We?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Ce}`,"aria-label":`Reference line ${Ce}`,children:Qe},Te.key)})})})]}),g&&L!==null&&X[L]&&o.jsx(Uee,{images:X,index:L,onChange:I,onClose:()=>{I(null),P(null),S?.()}})]})}function jd({label:e,value:t,options:n,placeholder:r,searchPlaceholder:s,emptyText:i,disabled:a,onChange:c}){const{t:u}=Yn(),[f,p]=b.useState(!1),[g,y]=b.useState(""),[v,S]=b.useState(null),A=b.useRef(null),T=b.useRef(null),L=g.trim().toLowerCase(),I=b.useMemo(()=>L?n.filter(C=>`${C.label} ${C.meta??""}`.toLowerCase().includes(L)):n,[L,n]),j=n.find(C=>C.value===t),P=()=>{const C=g.trim();C&&(c(C),p(!1),y(""))},F=b.useCallback(()=>{const C=A.current?.getBoundingClientRect();if(!C)return!1;const $=12,H=Math.max(220,Math.min(C.width,window.innerWidth-$*2)),Y=Math.min(Math.max($,C.left),window.innerWidth-H-$),V=window.innerHeight-C.bottom-$,fe=C.top-$,X=V>=180||V>=fe,ve=Math.max(96,(X?V:fe)-4),we=Math.min(320,ve);return S({left:Y,top:X?C.bottom+4:Math.max($,C.top-we-4),width:H,maxHeight:we}),!0},[]),R=()=>{F(),p(!0)};return b.useEffect(()=>{if(!f)return;let C=0;const $=()=>{C||(C=window.requestAnimationFrame(()=>{C=0,F()}))},H=Y=>{const V=Y.target;V instanceof Node&&(A.current?.contains(V)||T.current?.contains(V)||(p(!1),y("")))};return window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),document.addEventListener("pointerdown",H,!0),()=>{C&&window.cancelAnimationFrame(C),window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0),document.removeEventListener("pointerdown",H,!0)}},[f,F]),o.jsxs("div",{className:"relative min-w-0",children:[o.jsxs("button",{ref:A,type:"button",disabled:a,onClick:()=>{if(!a){if(y(""),f){p(!1);return}R()}},className:"group flex w-full items-center justify-between gap-2 rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-left transition hover:bg-surface-elevated disabled:cursor-not-allowed disabled:opacity-50",children:[o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block text-[9px] font-medium uppercase tracking-wide text-muted-foreground",children:e}),o.jsx("span",{className:`block truncate text-[12px] ${t?"text-foreground":"text-muted-foreground/70"}`,children:j?.label??(t||r)})]}),o.jsx(ra,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${f?"rotate-180":""}`})]}),f&&!a&&typeof document<"u"&&sa.createPortal(o.jsxs("div",{ref:T,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:C=>C.stopPropagation(),style:{left:v?.left??12,top:v?.top??12,width:v?.width??260,maxHeight:v?.maxHeight??320},children:[o.jsx("div",{className:"border-b border-border/10 p-1.5",children:o.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[o.jsx(Jl,{size:12,className:"shrink-0 text-muted-foreground"}),o.jsx("input",{autoFocus:!0,value:g,onChange:C=>y(C.target.value),onKeyDown:C=>{if(C.key==="Escape"){C.preventDefault(),p(!1),y("");return}C.key==="Enter"&&(C.preventDefault(),P())},onBlur:()=>{g.trim()&&I.length===0&&P()},placeholder:s,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),o.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(v?.maxHeight??320)-46)},children:[g.trim()&&!n.some(C=>C.value===g.trim())&&o.jsxs("button",{type:"button",onMouseDown:C=>C.preventDefault(),onClick:P,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[o.jsx("span",{className:"min-w-0 truncate",children:g.trim()}),o.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:u("common.use")})]}),I.length>0?I.map(C=>o.jsxs("button",{type:"button",onClick:()=>{c(C.value),p(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${C.value===t?"bg-accent/10 text-accent":"text-foreground"}`,children:[o.jsx("span",{className:"min-w-0 truncate font-medium",children:C.label}),C.meta&&o.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:C.meta})]},C.value)):o.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:i})]})]}),document.body)]})}function W4({open:e,onOpenChange:t,showScopePicker:n,selectedAll:r,repos:s,selectedRoots:i,onToggleRepo:a,onGenerate:c,onSecondaryAction:u,disabled:f,generateDisabled:p,secondaryDisabled:g,inserted:y,buttonLabel:v,insertedLabel:S,title:A,ariaLabel:T,scopeTitle:L,scopeLabel:I,allLabel:j,generateLabel:P,secondaryLabel:F,secondaryTitle:R,secondaryLoading:C,loading:$,error:H,statusTitle:Y,extraContent:V,renderRepoExtra:fe}){return o.jsxs("div",{className:"relative inline-flex shrink-0",children:[o.jsxs("button",{type:"button",onClick:()=>{n?t(!e):p||c()},disabled:f,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${H?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":T,title:Y??(n?`${L}: ${I}`:A),children:[$?o.jsx(Fn,{size:13,className:"animate-spin"}):o.jsx(ru,{size:13}),o.jsx("span",{children:y?S:v}),n&&o.jsx(ra,{size:11,className:`shrink-0 transition ${e?"rotate-180":""}`}),H&&o.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),n&&e&&o.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] px-3 py-6 backdrop-blur-sm animate-fade-in",onClick:()=>t(!1),children:o.jsxs("div",{className:"fixed left-1/2 top-1/2 z-modal-panel flex max-h-[min(82vh,36rem)] w-[calc(100vw-1.5rem)] max-w-[42rem] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/20 bg-surface text-[11px] shadow-2xl",onClick:X=>X.stopPropagation(),children:[o.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:L}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:I})]}),o.jsx("button",{type:"button",onClick:()=>t(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:o.jsx(ts,{size:14})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[V,o.jsxs("button",{type:"button",onClick:()=>a(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${r?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[o.jsx("span",{className:"truncate",children:j}),r&&o.jsx("span",{className:"text-[10px]",children:"✓"})]}),s.map(X=>{const ve=i.includes(X.root);return o.jsxs("div",{className:`mt-1 rounded-md transition ${ve?"bg-primary/15 text-primary":""}`,children:[o.jsxs("button",{type:"button",onClick:()=>a(X.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${ve?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:X.root,children:[o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block truncate",children:X.label}),X.branch&&o.jsx("span",{className:"block truncate text-[9px] opacity-70",children:X.branch})]}),ve&&o.jsx("span",{className:"text-[10px]",children:"✓"})]}),fe&&(r||ve)&&o.jsx("div",{className:"px-2 pb-2",children:fe(X)})]},X.root)})]}),o.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${u&&F?"sm:grid-cols-2":""}`,children:[u&&F&&o.jsxs("button",{type:"button",onClick:()=>{g||(t(!1),u())},disabled:g,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:R,children:[C?o.jsx(Fn,{size:12,className:"animate-spin"}):o.jsx(Df,{size:12}),F]}),o.jsxs("button",{type:"button",onClick:()=>{p||(t(!1),c())},disabled:p,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:A,children:[o.jsx(ru,{size:12}),P]})]})]})})]})}function Gee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;for(const t of Object.values(e)){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;if(typeof n.top!="number"||!Number.isFinite(n.top)||typeof n.updatedAt!="number"||!Number.isFinite(n.updatedAt))return!1}return!0}function uC(){return Or(av,Gee)??{}}function Wee(e,t){const n=uC(),r=Object.entries({...n,[e]:{top:t,updatedAt:Date.now()}}).sort(([,s],[,i])=>i.updatedAt-s.updatedAt).slice(0,jJ);n0(av,Object.fromEntries(r),BJ)}function Vee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.start=="number"&&Number.isFinite(t.start)&&typeof t.end=="number"&&Number.isFinite(t.end)&&t.start>=1&&t.end>=t.start}function qee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;for(const t of Object.values(e)){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;if(typeof n.top!="number"||!Number.isFinite(n.top)||n.left!==void 0&&(typeof n.left!="number"||!Number.isFinite(n.left))||n.markdownTop!==void 0&&(typeof n.markdownTop!="number"||!Number.isFinite(n.markdownTop))||n.lineRange!==void 0&&n.lineRange!==null&&!Vee(n.lineRange)||typeof n.updatedAt!="number"||!Number.isFinite(n.updatedAt))return!1}return!0}function mv(e,t){if(!t)return null;const n=e&&!t.startsWith("/")?`${e}/${t}`:t;return e?`${e}::${n}`:n}function dC(){return Or(lv,qee)??{}}function V4(e,t){const n=mv(e,t);return n?dC()[n]??null:null}function ob(e,t,n){const r=mv(e,t);if(!r)return;const s=dC(),i=s[r]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},a=Object.entries({...s,[r]:{...i,...n,updatedAt:Date.now()}}).sort(([,c],[,u])=>u.updatedAt-c.updatedAt).slice(0,PJ);n0(lv,Object.fromEntries(a),FJ)}function ab({active:e,mounted:t=!0,fallback:n=null,children:r}){return o.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${e?"block":"hidden"}`,"aria-hidden":!e,children:t?typeof r=="function"?r():r:n})}function gf({slow:e}){const{t}=Yn();return o.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:[o.jsx(Fn,{size:20,className:"mx-auto mb-2 animate-spin text-muted-foreground/80"}),o.jsx("div",{children:t("rightSidebar.loadingGitChanges")}),e&&o.jsx("div",{className:"mt-1 text-xs text-muted-foreground/75",children:t("rightSidebar.loadingGitChangesSlow")})]})}function Wp({message:e,onRetry:t}){const{t:n}=Yn();return o.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[o.jsx("div",{className:"font-medium",children:n("rightSidebar.gitChangesLoadFailed")}),o.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:e}),o.jsx("button",{type:"button",onClick:t,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:n("rightSidebar.retryGitChanges")})]})}function vm(e,t){const n=t&&e.startsWith(`${t}/`)?e.slice(t.length+1):e,r=n.split("/").filter(Boolean);return{name:r.pop()||n,dir:r.join("/")}}function bo(e){if(!e)return"";const t=e.replace(/\/+$/,"");return t.split("/").pop()||t||"/"}function q4(e){if(!e)return null;const t=e.replace(/\/+$/,"")||"/";if(t==="/")return null;const n=t.slice(0,t.lastIndexOf("/"))||"/";return n===t?null:n}function Y4(e,t,n){const r=Math.min(t,n),s=Math.max(t,n);return e?.start===r&&e.end===s?null:e&&e.start===e.end?{start:Math.min(e.start,r),end:Math.max(e.end,s)}:{start:r,end:s}}function lb(e,t="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${e?"bg-primary/20":`bg-[var(--surface-2)] ${t==="group"?"group-hover:bg-[var(--surface-elevated)]":t==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function cb(e,t="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${e?"bg-primary":`bg-[var(--border-strong)] ${t==="group"?"group-hover:bg-[var(--muted-foreground)]":t==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function K4(e,t){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${e?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${t?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function fC(e){const t=new Map;for(const n of e)t.set(gv(n),n);return t}function hC(e,t){const n=new Map(e);for(const r of t)n.set(gv(r),r);return n}function X4(e,t){let n=0;for(const r of e){const s=Oo(r,t);s&&t&&s!==t&&(n+=1)}return n}function Yee(e){return e.reduce((t,n)=>t+(n.staged?1:0),0)}function Kee(e,t){return Array.from(hC(fC(e),t).values()).sort((n,r)=>n.path.localeCompare(r.path))}function Xee(e,t){if(e.files.length===0)return null;const n=e.relativeRoot==="."?bo(t??e.root)||e.name||e.root:e.relativeRoot||e.name||bo(e.root)||e.root;return{root:e.root,label:n,branch:e.context?.branch??null,count:e.files.length,staged:Yee(e.files)}}function pC(e,t){const n=bo(t??"")||t||"";return e.map(r=>Xee(r,t)).filter(r=>!!r).sort((r,s)=>n&&r.label===n?-1:n&&s.label===n?1:r.label.localeCompare(s.label))}function Zee(e,t,n,r,s){const i=OT(n),a=i.find(A=>A.root===r)??i[0]??null,c=t.find(A=>A.root===r)??null,u=c?.relativeRoot??a?.relativeRoot??".",f=c?.name??a?.name??(bo(r)||r),p=(a?.files??n.files).map(A=>({...A,repoRoot:r,repoRelativeRoot:u,repoName:f})),g=a?.context??n.context,y={...c??a??{id:r,root:r,relativeRoot:u,name:f,depth:0,nested:!!(s&&r!==s),available:n.available,files:[],context:null},...a??{},id:c?.id??a?.id??r,root:r,displayRoot:c?.displayRoot??a?.displayRoot,relativeRoot:u,name:f,depth:c?.depth??a?.depth??0,nested:c?.nested??a?.nested??!!(s&&r!==s),available:a?.available??n.available,files:p,context:g?{...g,root:r,changedFiles:p.map(A=>({path:A.path,absolutePath:A.absolutePath,status:A.status}))}:null,untrackedDeferred:a?.untrackedDeferred??n.untrackedDeferred,error:a?.error??n.error},v=c?t.map(A=>A.root===r?y:A):[...t,y];return{files:Array.from(e).filter(A=>Oo(A,s)!==r).concat(p),repositories:v,repoFilters:pC(v,s)}}function Oo(e,t){return e.repoRoot??t}function gv(e){return`${e.repoRoot??""}\0${e.path}`}function xo(e){return e.absolutePath||e.path}function ub(e){return gv(e)}function Jee(e){return e.repoRelativeRoot&&e.repoRelativeRoot!=="."?e.repoRelativeRoot:e.repoName??""}function Z4(e){return e.reduce((t,n)=>t+(n.staged?1:0),0)}function J4(e){const t={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const n of e)n.status==="added"?t.added+=1:n.status==="modified"?t.modified+=1:n.status==="deleted"?t.deleted+=1:n.status==="renamed"?t.renamed+=1:n.status==="copied"?t.copied+=1:n.status==="untracked"?t.untracked+=1:n.status==="conflicted"?t.conflicted+=1:t.other+=1,n.staged&&(t.staged+=1);return t}function Pd(e){let t=0;const n=e??"root";for(let r=0;r<n.length;r+=1)t=Math.imul(t^n.charCodeAt(r),16777619);return`right-sidebar-git-bundle:${(t>>>0).toString(36)}`}function xf(e,t){return typeof e!="number"||!Number.isFinite(e)||e<=0?null:new Intl.DateTimeFormat(t==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(e))}function pc(e){return e instanceof DOMException&&e.name==="AbortError"}function ete(e){const t=e.error??e.context?.error??"";return t.includes("request was cancelled")||t.includes("IO_REQUEST_CANCELLED")}function e7(e){return e?.available===!1&&e.code==="NOT_GIT_REPOSITORY"}function G2(){if(typeof window>"u")return!1;const e=window.getSelection();return!!(e&&!e.isCollapsed&&e.toString().trim())}function db(e){return e instanceof HTMLElement&&!!e.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function t7(e,t,n){const r=e instanceof HTMLElement?e.closest("[data-md-ref-start]"):null,s=Number(r?.dataset.mdRefStart),i=Number(r?.dataset.mdRefEnd??r?.dataset.mdRefStart);return Number.isFinite(s)&&s>0&&Number.isFinite(i)&&i>0?{start:Math.min(s,i),end:Math.max(s,i)}:{start:t,end:n}}function tte({actions:e,running:t,completed:n}){const{t:r}=Yn(),[s,i]=b.useState(!1),a=b.useRef(null),c=e.find(f=>t?.action===f.key),u=e.find(f=>n?.action===f.key);return e.length===0?null:(b.useEffect(()=>{if(!s)return;const f=g=>{const y=g.target;y instanceof Node&&a.current?.contains(y)||i(!1)},p=g=>{g.key==="Escape"&&i(!1)};return document.addEventListener("pointerdown",f),document.addEventListener("keydown",p),()=>{document.removeEventListener("pointerdown",f),document.removeEventListener("keydown",p)}},[s]),o.jsxs("div",{ref:a,className:"relative shrink-0",children:[o.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),i(p=>!p)},disabled:e.every(f=>f.disabled)&&!t&&!n,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-50 ${s?"bg-surface-elevated text-foreground":u?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:c?.label??u?.label??r("rightSidebar.gitQuickActions"),children:c?o.jsx(Fn,{size:13,className:"animate-spin"}):u?o.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):o.jsx(tu,{size:14})}),s&&o.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:e.map(f=>{const p=t?.action===f.key,g=n?.action===f.key;return o.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),f.onClick(),i(!1)},disabled:f.disabled||!!t,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${g?"bg-accent/10 text-accent":f.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[o.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:p?o.jsx(Fn,{size:13,className:"animate-spin"}):g?"✓":null}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:f.label})]},f.key)})})]}))}function nte(e){const t=window.getComputedStyle(e).overflowY;return(t==="auto"||t==="scroll")&&e.scrollHeight>e.clientHeight+1}function mC(e){let t=e;for(;t;){if(t.classList.contains("termdock-diff-stream-scroller")&&nte(t))return t;t=t.parentElement}return e.closest(".termdock-diff-stream-scroller")}function s0(e){return e.getClientRects().length>0&&window.getComputedStyle(e).visibility!=="hidden"}const fb=new WeakMap;function cg(e){const t=fb.get(e);t!==void 0&&window.clearTimeout(t),e.classList.remove("diff-walkthrough-target"),e.offsetWidth,e.classList.add("diff-walkthrough-target");const n=window.setTimeout(()=>{e.classList.remove("diff-walkthrough-target"),fb.delete(e)},1700);fb.set(e,n)}function rte(e){const t=CSS.escape(e),n=[`[data-diff-stream-item="${t}"]`,`[data-diff-selection-path="${t}"]`,`[data-diff-absolute-path="${t}"]`].join(","),r=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let s=null;for(const c of r){if(!s0(c))continue;const u=c.querySelector(n);if(u&&s0(u)){s=u;break}}if(s??=Array.from(document.querySelectorAll(n)).find(s0)??null,!s)return;const i=mC(s);if(!i){s.scrollIntoView({block:"start",behavior:"smooth"}),cg(s);return}const a=s.getBoundingClientRect().top-i.getBoundingClientRect().top+i.scrollTop;i.scrollTo({top:Math.max(0,a),behavior:"instant"}),cg(s)}function _u(e){const t=CSS.escape(e.filePath),n=typeof e.sectionIndex=="number"?String(e.sectionIndex):null,r=typeof e.hunkIndex=="number"?String(e.hunkIndex):null,s=e.sectionFingerprint?CSS.escape(e.sectionFingerprint):null,i=e.hunkFingerprint?CSS.escape(e.hunkFingerprint):null,a=[n!==null&&s?`[data-diff-section-audit="${t}"][data-diff-section-index="${n}"][data-diff-section-fingerprint="${s}"]`:null,n!==null&&s?`[data-diff-section-anchor="${t}"][data-diff-section-index="${n}"][data-diff-section-fingerprint="${s}"]`:null,n!==null?`[data-diff-section-audit="${t}"][data-diff-section-index="${n}"]`:null,n!==null?`[data-diff-section-anchor="${t}"][data-diff-section-index="${n}"]`:null,r!==null&&i?`[data-diff-hunk-anchor="${t}"][data-diff-hunk-index="${r}"][data-diff-hunk-fingerprint="${i}"]`:null,r!==null?`[data-diff-hunk-anchor="${t}"][data-diff-hunk-index="${r}"]`:null,`[data-diff-file-path="${t}"]`].filter(S=>!!S),c=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let u=null;for(const S of c)if(s0(S)){for(const A of a){const T=S.querySelector(A);if(T&&s0(T)){u=T;break}}if(u)break}if(u??=a.flatMap(S=>Array.from(document.querySelectorAll(S))).find(s0)??null,!u){rte(e.filePath);return}const f=mC(u);if(!f){u.scrollIntoView({block:"center",behavior:"smooth"}),cg(u);return}const p=u.getBoundingClientRect(),g=f.getBoundingClientRect(),v=p.top-g.top+f.scrollTop-Math.max(24,(f.clientHeight-p.height)/2);f.scrollTo({top:Math.max(0,v),behavior:"instant"}),cg(u)}const gC=1,xC=8;function ste(e){return Math.min(xC,Math.max(gC,e))}function bC({resetKey:e,onZoomChange:t,onDoubleTap:n,children:r}){const s=b.useRef(null),[i,a]=b.useState({scale:1,x:0,y:0}),[c,u]=b.useState(!1),f=b.useRef(null),p=b.useRef(new Set),g=b.useRef(!1),y=b.useRef(null),v=b.useRef(0),S=b.useRef(i);S.current=i,b.useEffect(()=>{a({scale:1,x:0,y:0})},[e]);const A=b.useCallback((j,P,F)=>{const R=s.current;if(!R)return{x:P,y:F};const C=R.firstElementChild instanceof HTMLElement?R.firstElementChild:null,$=C?.clientWidth||R.clientWidth,H=C?.clientHeight||R.clientHeight,Y=Math.max(0,($*j-R.clientWidth)/2),V=Math.max(0,(H*j-R.clientHeight)/2);return{x:Math.min(Y,Math.max(-Y,P)),y:Math.min(V,Math.max(-V,F))}},[]),T=b.useCallback((j,P,F)=>{a(R=>{const C=ste(j),$=s.current;if(!$||C===1)return{scale:C,x:0,y:0};const H=$.getBoundingClientRect(),Y=(P??H.left+H.width/2)-H.left-H.width/2,V=(F??H.top+H.height/2)-H.top-H.height/2,fe=C/R.scale,X=Y-(Y-R.x)*fe,ve=V-(V-R.y)*fe;return{scale:C,...A(C,X,ve)}})},[A]),L=b.useCallback((j,P)=>{u(!0),S.current.scale>1?a({scale:1,x:0,y:0}):T(2.5,j,P),window.setTimeout(()=>u(!1),220)},[T]);b.useEffect(()=>{const j=s.current;if(!j)return;const P=C=>{if(C.pointerType==="mouse"&&C.button!==0)return;const $=p.current.size===0;if(p.current.add(C.pointerId),$){const H=Date.now(),Y=y.current;if(Y&&H-Y.time<350&&Math.hypot(C.clientX-Y.x,C.clientY-Y.y)<24){y.current=null,v.current=H,n?.(),L(C.clientX,C.clientY);return}}if(p.current.size>1){g.current=!0,f.current=null;return}if(!(S.current.scale<=1)){C.preventDefault(),f.current={pointerId:C.pointerId,startX:C.clientX,startY:C.clientY,originX:S.current.x,originY:S.current.y,moved:!1};try{j.setPointerCapture?.(C.pointerId)}catch{}u(!1)}},F=C=>{const $=f.current;if(!$||$.pointerId!==C.pointerId)return;const H=C.clientX-$.startX,Y=C.clientY-$.startY;if(!$.moved){if(Math.hypot(H,Y)<6)return;$.moved=!0}C.stopPropagation(),C.preventDefault(),a(V=>({...V,...A(V.scale,$.originX+H,$.originY+Y)}))},R=C=>{const $=f.current,H=$?.pointerId===C.pointerId&&$.moved;if($?.pointerId===C.pointerId){$.moved&&C.stopPropagation(),f.current=null;try{j.releasePointerCapture?.(C.pointerId)}catch{}}p.current.delete(C.pointerId)&&p.current.size===0&&(!g.current&&!H&&(y.current={time:Date.now(),x:C.clientX,y:C.clientY}),g.current=!1)};return j.addEventListener("pointerdown",P,{capture:!0,passive:!1}),window.addEventListener("pointermove",F,{capture:!0,passive:!1}),window.addEventListener("pointerup",R,{capture:!0}),window.addEventListener("pointercancel",R,{capture:!0}),()=>{j.removeEventListener("pointerdown",P,{capture:!0}),window.removeEventListener("pointermove",F,{capture:!0}),window.removeEventListener("pointerup",R,{capture:!0}),window.removeEventListener("pointercancel",R,{capture:!0})}},[A,n,L]),b9({onPinch:({offset:[j],origin:[P,F]})=>{u(!1),T(j,P,F)},onWheel:({event:j,delta:[P,F],ctrlKey:R})=>{if(R){j.preventDefault(),j.stopPropagation(),u(!1),T(S.current.scale*(1-F*.01),j.clientX,j.clientY);return}S.current.scale<=1||(j.preventDefault(),j.stopPropagation(),u(!1),a(C=>({...C,...A(C.scale,C.x-P,C.y-F)})))}},{target:s,eventOptions:{passive:!1},pinch:{scaleBounds:{min:gC,max:xC},from:()=>[S.current.scale,0],rubberband:!0}});const I=i.scale>1;return b.useEffect(()=>{t?.(I)},[t,I]),o.jsx("div",{ref:s,"data-sidebar-gesture-ignore":I?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:I?"grab":"zoom-in"},onDoubleClick:j=>{j.stopPropagation(),!(Date.now()-v.current<500)&&(n?.(),L(j.clientX,j.clientY))},children:r({scale:i.scale,zoomed:I,animateTransform:c,transformStyle:{transform:`translate3d(${i.x}px, ${i.y}px, 0) scale(${i.scale})`,transformOrigin:"center center",transition:c?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${i.x}px, ${i.y}px, 0)`,transformOrigin:"center center",transition:c?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function yC({src:e,alt:t,vector:n,onLoad:r,onError:s,onZoomChange:i,onDoubleTap:a}){const[c,u]=b.useState(null),f=n??uv(e);return b.useEffect(()=>{u(null)},[e]),o.jsx(bC,{resetKey:e,onZoomChange:i,onDoubleTap:a,children:({transformStyle:p,vectorTransformStyle:g,scale:y,animateTransform:v})=>{const S=o.jsx("img",{src:e,alt:t,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&c?{position:"absolute",left:"50%",top:"50%",width:c.width*y,height:c.height*y,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:v?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:c?{...p,width:c.width,height:c.height}:f?g:p,onLoad:A=>{const T=A.currentTarget,L=T.parentElement;if(L&&T.naturalWidth>0&&T.naturalHeight>0){const I=Math.max(1,L.clientWidth-2),j=Math.max(1,L.clientHeight-2),P=Math.min(I/T.naturalWidth,j/T.naturalHeight),F=f?P:Math.min(P,1);u({width:Math.max(1,Math.round(T.naturalWidth*F)),height:Math.max(1,Math.round(T.naturalHeight*F))})}r(A)},onError:s});return!f||!c?S:o.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...g,width:c.width,height:c.height},children:S})}})}function ite({svg:e,title:t,scale:n,vectorTransformStyle:r}){const s=b.useRef(null);return b.useLayoutEffect(()=>{const i=s.current,a=i?.querySelector("svg");if(!i||!a)return;const c=()=>{const p=a.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let g=p[2],y=p[3];if((!Number.isFinite(g)||!Number.isFinite(y)||g<=0||y<=0)&&(g=Number(a.getAttribute("width")),y=Number(a.getAttribute("height"))),!Number.isFinite(g)||!Number.isFinite(y)||g<=0||y<=0)return;const v=Math.max(1,i.clientWidth-24),S=Math.max(1,i.clientHeight-24),A=Math.min(v/g,S/y,1);a.style.width=`${Math.max(1,Math.floor(g*A*n))}px`,a.style.height=`${Math.max(1,Math.floor(y*A*n))}px`,a.style.maxWidth="none",a.style.maxHeight="none",a.style.transform=String(r.transform??""),a.style.transformOrigin="center center",a.style.transition=String(r.transition??"none")};c();const u=typeof ResizeObserver>"u"?null:new ResizeObserver(c);return u?.observe(i),()=>u?.disconnect()},[n,e,r]),o.jsx("div",{ref:s,role:"img","aria-label":t,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:e}})}function ote({svg:e,title:t,onZoomChange:n,onDoubleTap:r}){return o.jsx(bC,{resetKey:e,onZoomChange:n,onDoubleTap:r,children:({vectorTransformStyle:s,scale:i})=>o.jsx(ite,{svg:e,title:t,scale:i,vectorTransformStyle:s})})}let ate=0,lte=0,cte=0,ute=0;function hb(e,t={}){if(typeof window>"u")return;const n=JSON.stringify({level:e==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${e}`,data:{ts:Date.now(),...t}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0}).catch(()=>{})}function oi(e,t={}){if(typeof window>"u")return;const n=JSON.stringify({level:e==="error"||e==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${e}`,data:{seq:++lte,ts:Date.now(),...t}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0}).catch(()=>{})}function Vp(e,t={}){if(typeof window>"u")return;const n=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${e}`,data:{seq:++cte,ts:Date.now(),...t}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0}).catch(()=>{})}function dte(){return`diff-ui-${Date.now().toString(36)}-${(++ute).toString(36)}`}function fte(e){return e instanceof Element?e.closest("[data-diff-selection-path]"):null}function hte(e){const t=e.target instanceof HTMLElement?e.target:null;return{eventType:e.type,button:e.button,pointerType:e instanceof globalThis.PointerEvent?e.pointerType:void 0,targetTag:t?.tagName,targetClass:t?.className,targetText:t?.textContent?.slice(0,80)}}function n7({filePath:e,onInsertReference:t,onInsertText:n,onInsertFeature:r,onReferenceCopied:s,onClose:i,onDirectoryLinkOpen:a,isMobile:c,markdownOutlineOpen:u,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:p,onCloseMarkdownOutline:g,markdownImageLightboxOpen:y,markdownImageLightboxCloseSignal:v,onOpenMarkdownImageLightbox:S,onCloseMarkdownImageLightbox:A,lineRange:T,onLineRangeChange:L,insertedReferenceKey:I,copiedReferenceKey:j,scrollToLine:P,onScrollToLineHandled:F}){const{t:R}=Yn(),C=ft(qe=>qe.rootPath),$=ft(qe=>qe.selectFile),[H,Y]=b.useState({kind:"idle"}),[V,fe]=b.useState("schematic"),[X,ve]=b.useState(null),we=b.useRef(null),[ie,ae]=b.useState(null),q=b.useRef(new Map),z=b.useRef(null),[te,pe]=b.useState(null),[de,ke]=b.useState(()=>j4()),[be,oe]=b.useState(()=>C4(C,e)),he=b.useRef(null),[J,Xe]=b.useState(!1),[lt,Ze]=b.useState(null),[ge,Fe]=b.useState(0),[Te,ze]=b.useState([]),[Be,We]=b.useState(null),W=b.useRef(null),xe=b.useRef(e),[He,Ce]=b.useState(null),[Qe,pt]=b.useState({status:"idle"}),[At,yt]=b.useState(!1),[Yt,Mt]=b.useState(""),[on,xr]=b.useState([]),[Cn,or]=b.useState(0),Le=b.useRef(null),ot=C0(s),Oe=mv(C,e);b.useEffect(()=>{if(xe.current===e)return;xe.current=e;const qe=e&&C&&!e.startsWith("/")?`${C}/${e}`:e;if(W.current===qe){W.current=null;return}W.current=null,ze([]),We(null),yt(!1),Mt("")},[e,C]);const Dt=e?C&&!e.startsWith("/")?`${C}/${e}`:e:null,$e=ft(qe=>Dt?(qe.fileChangeVersions.get(Dt)??0)+qe.fileWatchEpoch:qe.fileWatchEpoch),Ut=b.useRef(null),_t=b.useRef(null),[Ve,Ur]=b.useState(0),kn=b.useCallback(()=>Ur(qe=>qe+1),[]);b.useEffect(()=>{const qe=we.current;return we.current=null,ve(null),qe&&URL.revokeObjectURL(qe.objectUrl),()=>{const ct=we.current;we.current=null,ct&&URL.revokeObjectURL(ct.objectUrl)}},[Dt,$e,Ve]),b.useEffect(()=>{if(!e){Ut.current=null,Y({kind:"idle"});return}const qe=C&&!e.startsWith("/")?`${C}/${e}`:e,ct=new AbortController,jt=++ate,dn=`right-sidebar-file-preview:${jt}`,An=performance.now();let _n=!1;const ln=(st,wt={})=>{_n||(_n=!0,hb("end",{loadingId:jt,reason:st,durationMs:Math.round(performance.now()-An),filePath:e,fullPath:qe,rootPath:C,...wt}))};let pn=null;const tn=aI(qe),cn=tn?qe.toLowerCase().endsWith(".kicad_pcb")?V==="schematic"?"pcb-front":V:"schematic":V,sr=!tn&&ey(qe),ps=!tn&&!sr&&t8(qe),Qr=!tn&&!sr&&!ps&&J7(qe),se=mf(qe),_e=U0(qe),je=tn?"eda":sr?"image":ps?"model3d":Qr?"video":"text",tt=Ut.current!==qe;if(Ut.current=qe,tt){hb("start",{loadingId:jt,filePath:e,fullPath:qe,rootPath:C,mode:je,externalVersion:$e}),pt({status:"idle"}),Y({kind:"loading",mode:je}),_t.current=null;const st=V4(C,e);L(st?.lineRange??null),ke(se?j4():"source"),oe(_e?C4(C,e):"source"),tn&&fe(lI(qe))}const Qt=window.setTimeout(()=>{_n||ct.signal.aborted||hb("still_active",{loadingId:jt,filePath:e,fullPath:qe,rootPath:C,mode:je,durationMs:Math.round(performance.now()-An),isPathChange:tt})},3e3),Nt=window.setTimeout(()=>{if(_n||ct.signal.aborted)return;const st="File preview is still waiting on disk I/O. Try the file again or refresh the directory.";ct.abort(new DOMException(st,"TimeoutError")),Y({kind:"error",message:st}),ln("stuck_timeout",{error:st})},X7(qe)?35e3:zJ);if(tn){const st=cn==="pcb-3d"?we.current:null;st?(Y(st),ln("eda_3d_client_cache_hit",{bytes:st.meta.size,view:st.view,mimeType:st.meta.mimeType})):mI(qe,cn,ct.signal,"view_file",dn).then(wt=>{pn=URL.createObjectURL(wt.blob);const Lt={kind:"eda",objectUrl:pn,view:wt.view,meta:{size:wt.size,mimeType:wt.mimeType,modified:wt.modified}};if(wt.view==="pcb-3d"){const Tn=we.current;Tn&&Tn.objectUrl!==pn&&URL.revokeObjectURL(Tn.objectUrl),we.current=Lt,ve(Lt),pn=null}Y(Lt),ln("eda_loaded",{bytes:wt.size,view:wt.view,mimeType:wt.mimeType})}).catch(wt=>{ct.signal.aborted||(Y({kind:"error",message:wt instanceof Error?wt.message:R("rightSidebar.edaLoadFailed")}),ln("error",{error:wt instanceof Error?wt.message:String(wt)}))})}else if(sr)s8(qe,ct.signal,"view_file",dn).then(st=>{pn=URL.createObjectURL(st.blob),Y({kind:"image",objectUrl:pn,meta:{size:st.size,mimeType:st.mimeType,modified:st.modified}}),ln("image_loaded",{bytes:st.size,mimeType:st.mimeType})}).catch(st=>{ct.signal.aborted||(Y({kind:"error",message:st instanceof Error?st.message:R("rightSidebar.imageLoadFailed")}),ln("error",{error:st instanceof Error?st.message:String(st)}))});else if(ps)xI(qe,ct.signal,"view_file",dn).then(st=>{pn=URL.createObjectURL(st.blob),Y({kind:"model3d",objectUrl:pn,ext:st.ext,meta:{size:st.size,mimeType:st.mimeType,modified:st.modified}}),ln("model3d_loaded",{bytes:st.size,ext:st.ext})}).catch(st=>{ct.signal.aborted||(Y({kind:"error",message:st instanceof Error?st.message:R("rightSidebar.model3dLoadFailed")}),ln("error",{error:st instanceof Error?st.message:String(st)}))});else if(Qr){const st=Z7(qe)??"",wt=iI(qe);Y(Lt=>Lt.kind==="video"&&Lt.url===wt?Lt:{kind:"video",url:wt,meta:{size:null,mimeType:st,modified:null}}),ln("video_ready",{mimeType:st})}else a5(qe,ct.signal,"view_file",dn).then(st=>{if(st.binary){Y({kind:"binary"});return}Y({kind:"text",content:st.content,meta:{size:st.size,truncated:st.truncated}}),ln("text_loaded",{bytes:st.size,truncated:!!st.truncated})}).catch(st=>{ct.signal.aborted||(Y({kind:"error",message:st instanceof Error?st.message:"Failed to read file"}),ln("error",{error:st instanceof Error?st.message:String(st)}))});return()=>{ct.abort(),ao(dn),window.clearTimeout(Qt),window.clearTimeout(Nt),pn&&URL.revokeObjectURL(pn),ln("cleanup")}},[e,C,$e,Ve,L,R,V]),b.useEffect(()=>{if(H.kind!=="model3d"||!e){ae(null);return}let qe=!1;const ct=e.lastIndexOf("/"),jt=ct>=0?e.slice(ct+1):e,dn=ct>=0?e.slice(0,ct):"",An=dn.lastIndexOf("/"),_n=An>=0?dn.slice(0,An):"",ln=jt.replace(/\.(stl|glb|gltf)$/i,""),pn=`${_n?`${_n}/`:""}features/${ln}.json`;return a5(pn).then(tn=>{if(!qe)try{const cn=JSON.parse(tn.content);ae(cn.version===1&&Array.isArray(cn.features)&&cn.features.length>0?cn.features:null)}catch{ae(null)}}).catch(()=>{qe||ae(null)}),()=>{qe=!0}},[H,e]),b.useEffect(()=>{if(H.kind!=="text"){Ce(null);return}const qe=C&&e&&!e.startsWith("/")?`${C}/${e}`:e,ct=r0(qe),jt=H.content,dn=mf(qe??"")&&de==="preview",An=U0(qe??"")&&be==="preview";if(!ct||dn||An||!sT(jt)){Ce(null);return}let _n=!1;const ln=pn=>{if(_n||!pn.registered(ct)){_n||Ce(null);return}try{Ce(oT(pn,jt,ct))}catch{Ce(null)}};return lt?ln(lt):(Ce(null),iT().then(pn=>{_n||(Ze(pn),ln(pn))}).catch(()=>{})),()=>{_n=!0}},[H,lt,e,C,de,be]),b.useLayoutEffect(()=>{if(!Oe||H.kind!=="text")return;const qe=`${Oe}:${de}:${be}`;if(_t.current===qe)return;const ct=V4(C,e);if(_t.current=qe,!ct)return;const jt=requestAnimationFrame(()=>{const dn=z.current;if(!dn)return;const An=de==="preview"?ct.markdownTop??ct.top:ct.top;dn.scrollTo({top:Math.max(0,An??0),left:Math.max(0,ct.left??0)}),Fe(de==="preview"?Math.max(0,An??0):0)});return()=>cancelAnimationFrame(jt)},[e,de,be,H.kind,Oe,C]),b.useEffect(()=>{Oe&&ob(C,e,{lineRange:T})},[e,T,Oe,C]),b.useEffect(()=>{if(P==null||H.kind!=="text")return;pe(null),L({start:P,end:P});const qe=P,ct=requestAnimationFrame(()=>{const jt=q.current.get(qe);jt&&jt.scrollIntoView({block:"center"}),F?.()});return()=>cancelAnimationFrame(ct)},[P,H,L,F]);const Ft=b.useCallback(qe=>{const ct=z.current;if(!ct)return!1;const jt=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(qe):qe.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),dn=ct.querySelector(`#${jt}`);return dn?(dn.scrollIntoView({block:"start"}),!0):!1},[]);b.useEffect(()=>{const qe=C&&e&&!e.startsWith("/")?`${C}/${e}`:e,ct=H.kind==="text"&&mf(qe??"")&&de==="preview";if(!Be||!ct)return;const jt=requestAnimationFrame(()=>{Ft(Be)&&We(null)});return()=>cancelAnimationFrame(jt)},[e,Ft,de,Be,H,C]),b.useLayoutEffect(()=>{const qe=z.current;if(!qe||!T){pe(null);return}if(te)return;const ct=H.kind==="image"||H.kind==="loading"&&H.mode==="image",jt=C&&e&&!e.startsWith("/")?`${C}/${e}`:e,dn=H.kind==="text"&&mf(jt??"")&&de==="preview",An=H.kind==="text"&&U0(jt??"")&&be==="preview";if(H.kind!=="text"||ct||dn||An){pe(null);return}const _n=()=>{const pn=q.current.get(T.end);if(!pn||!qe){pe(null);return}const tn=pn.offsetTop+pn.offsetHeight/2,cn=qe.scrollLeft+Math.max(8,qe.clientWidth-120);pe({top:tn,left:cn})};_n();const ln=new ResizeObserver(()=>_n());return ln.observe(qe),()=>ln.disconnect()},[T,te,H,de,be,e,C,He]);const Zn=H.kind==="text"&&!(U0(Dt??"")&&be==="preview")&&!Dt?.toLowerCase().endsWith(".csv")&&!Dt?.toLowerCase().endsWith(".kicad_pro")&&!Dt?.toLowerCase().endsWith(".kicad_prl"),Gt=b.useCallback(()=>{yt(!1),Mt(""),xr([]),or(0),$p()},[]),Cr=b.useCallback(()=>{Zn&&(yt(!0),requestAnimationFrame(()=>{Le.current?.focus(),Le.current?.select()}))},[Zn]),nr=b.useCallback(qe=>{or(ct=>on.length===0?0:(ct+qe+on.length)%on.length)},[on.length]);if(b.useEffect(()=>{const qe=ct=>{const jt=IJ(ct);if(jt==="open"&&Zn){ct.preventDefault(),Cr();return}At&&(jt==="close"?(ct.preventDefault(),Gt()):(jt==="next"||jt==="previous")&&(ct.preventDefault(),nr(jt==="previous"?-1:1)))};return document.addEventListener("keydown",qe),()=>document.removeEventListener("keydown",qe)},[Gt,At,nr,Cr,Zn]),b.useLayoutEffect(()=>{if($p(),!At||!Yt.trim()||!z.current){xr([]),or(0);return}const qe=NJ(z.current,Yt);return xr(qe),or(0),k4(qe,0),_4(qe[0]),$p},[At,Yt,He,de,H]),b.useEffect(()=>{At&&(k4(on,Cn),_4(on[Cn]))},[Cn,on,At]),b.useEffect(()=>$p,[]),!e)return o.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:R("rightSidebar.selectFilePrompt")});const an=C&&!e.startsWith("/")?`${C}/${e}`:e,Er=vm(an,C),yr=Ag(an,C),Jn=H.kind==="text"&&H.content?H.content.split(`
192
+ `),display:!0})});continue}if(p+1<e.length&&v&&!O2(y)&&/^(=+|-+)\s*$/.test(e[p+1].trim())){const R=e[p+1].trim().startsWith("=")?1:2,C=`h${R}`,$=Q2(v,u),H={level:R,text:H4(v),id:$};f.push({key:`setext-heading-${p}`,startLine:p+1,endLine:p+2,heading:H,content:o.jsx(C,{id:$,className:`scroll-mt-16 font-semibold text-foreground ${R===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:Ci(v,`setext-heading-${p}`,!0,u)})}),p+=2;continue}const T=v.match(/^(#{1,6})\s+(.+)$/);if(T){const R=T[1].length,C=WT(T[2]),$={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},H=`h${R}`,Y=Q2(C,u),V={level:R,text:H4(C),id:Y};f.push({key:`heading-${p}`,startLine:p+1,endLine:p+1,heading:V,content:o.jsx(H,{id:Y,className:`scroll-mt-16 font-semibold text-foreground ${$[R]}`,children:Ci(C,`heading-${p}`,!0,u)})}),p+=1;continue}if(UT(y)){f.push({key:`hr-${p}`,startLine:p+1,endLine:p+1,content:o.jsx("hr",{className:"border-border/20"})}),p+=1;continue}if(v.startsWith(">")){const R=[],C=[],$=p;for(;p<e.length&&/^>\s?/.test(e[p].trim());)R.push(e[p].trim().replace(/^>\s?/,"")),C.push(p+1),p+=1;const H=R[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(H){const V=H[1].toUpperCase(),fe=H[2]?.trim(),X=[...fe?[fe]:[],...R.slice(1)],ve=[...fe?[C[0]]:[],...C.slice(1)],we=U2(X,`callout-${$}`,u);f.push({key:`callout-${$}`,startLine:$+1,endLine:p,fineGrained:!0,content:ie=>o.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[o.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:V}),X.length>0&&o.jsx("div",{children:z2(we.perLine,we.hardBreaks,ve,`callout-${$}`,ie)})]})});continue}const Y=jee(R,`quote-${$}`,u,C);f.push({key:`quote-${$}`,startLine:$+1,endLine:p,fineGrained:!0,content:V=>o.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:Pee(Y,V)})});continue}if(p+1<e.length&&y.includes("|")&&ag(e[p+1])){const R=ch(y),C=oC(e[p+1]),$=[],H=p;for(p+=2;p<e.length&&e[p].includes("|")&&e[p].trim();)$.push(ch(e[p])),p+=1;const Y=R.map((fe,X)=>Ci(fe,`th-${H}-${X}`,!0,u)),V=$.map((fe,X)=>R.map((ve,we)=>Ci(fe[we]??"",`td-${H}-${X}-${we}`,!0,u)));f.push({key:`table-${H}`,startLine:H+1,endLine:p,interactive:!1,kind:"table",content:fe=>{const X=ve=>!!(fe&&ve>=fe.start&&ve<=fe.end);return o.jsx("div",{className:FT,"data-markdown-table-scroll":!0,children:o.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[o.jsx("thead",{className:"bg-surface-2 text-foreground",children:o.jsx("tr",{"data-markdown-table-row-line":H+1,"data-md-ref-start":H+1,"data-md-ref-end":H+1,"data-selected":X(H+1)?"true":void 0,children:Y.map((ve,we)=>o.jsx("th",{className:`${PT} ${og(C[we]??null)}`,children:o.jsx("div",{className:rg,children:ve})},`h-${we}`))})}),o.jsx("tbody",{children:V.map((ve,we)=>{const ie=H+we+3;return o.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":ie,"data-md-ref-start":ie,"data-md-ref-end":ie,"data-selected":X(ie)?"true":void 0,children:R.map((ae,q)=>o.jsx("td",{className:`${BT} ${og(C[q]??null)}`,children:o.jsx("div",{className:rg,children:ve[q]})},`c-${q}`))},`r-${we}`)})})]})})}});continue}const L=fv(y);if(L){const R=L.ordered,C=dv(y),$=L.start,H=p,Y=aC(e,p,C,R,!0,a);p=Y.nextIndex;const V=R?"ol":"ul",fe=hv(Y.items,`list-${H}`,u);f.push({key:`list-${H}`,startLine:H+1,endLine:p,fineGrained:!0,content:X=>o.jsx(V,{start:R?$:void 0,className:`${R?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:pv(fe,X)})});continue}const I=[y.trimStart()],j=[p+1],P=p;for(p+=1;p<e.length&&e[p].trim()&&!O2(e[p])&&!(p+1<e.length&&e[p].includes("|")&&ag(e[p+1]));){if(sg(e[p])||a.has(p)){p+=1;continue}I.push(e[p].trimStart()),j.push(p+1),p+=1}const F=U2(I,`p-${P}`,u);f.push({key:`p-${P}`,startLine:P+1,endLine:p,fineGrained:!0,content:R=>o.jsx("p",{className:"text-muted-foreground",children:z2(F.perLine,F.hardBreaks,j,`p-${P}`,R)})})}const g=Dee(u);return g&&f.push({key:"footnotes",startLine:e.length,endLine:e.length,content:g}),{blocks:f,images:c}}function Uee(e,t){const n=[];for(const r of e){if(r.startLine>t)break;if(r.heading){for(;n.length>0&&n[n.length-1].level>=r.heading.level;)n.pop();n.push({...r.heading,startLine:r.startLine})}}return n}function zee(e){return e.filter(t=>!!t.heading).map(t=>({...t.heading,startLine:t.startLine}))}function Gee({src:e,alt:t,onZoomChange:n,onDoubleTap:r}){const s=KT(e);return o.jsx(yC,{src:s,alt:t,onLoad:()=>{},onError:()=>{},onZoomChange:n,onDoubleTap:r})}function Wee({images:e,index:t,onChange:n,onClose:r}){const{t:s}=Yn(),i=e[t],a=e.length>1,c=b.useRef(null),u=b.useRef(null),f=b.useRef(null),p=b.useRef(0),[g,y]=b.useState(!1),[v,S]=b.useState(0),[A,T]=b.useState(!1),L=b.useCallback(()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},[]),I=b.useCallback(()=>{g||Date.now()<p.current||(L(),f.current=window.setTimeout(()=>{f.current=null,r()},450))},[L,g,r]),j=b.useCallback(C=>{if(e.length===0)return;const $=(C+e.length)%e.length;c.current?.slideTo($),n($)},[e.length,n]),P=b.useCallback(()=>j(t-1),[j,t]),F=b.useCallback(()=>j(t+1),[j,t]);if(b.useEffect(()=>{L(),S(0),T(!1),y(!1)},[L,t]),b.useEffect(()=>{const C=c.current;C&&(C.allowTouchMove=a&&!g)},[a,g]),b.useEffect(()=>{const C=c.current;!C||C.activeIndex===t||C.slideTo(t,0)},[t]),b.useEffect(()=>L,[L]),b.useEffect(()=>{const C=$=>{if($.key==="Escape"){$.preventDefault(),r();return}a&&($.key==="ArrowLeft"?($.preventDefault(),P()):$.key==="ArrowRight"&&($.preventDefault(),F()))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[a,F,P,r]),b9({onDrag:({movement:[C,$],pinching:H})=>{H||g||Math.abs($)<Math.abs(C)*1.15&&v===0||(T(!0),Math.abs($)>8&&(p.current=Date.now()+300),S(Math.max(0,$)))},onDragEnd:({movement:[,C],velocity:[,$]})=>{if(!g){if(T(!1),Math.abs(C)>8&&(p.current=Date.now()+300),Ree(C,$)){r();return}S(0)}}},{target:u,drag:{filterTaps:!0,pointer:{touch:!0}}}),!i)return null;const R=i.title||i.alt||(i.kind==="mermaid"?s("rightSidebar.mermaidDiagram"):s("rightSidebar.image"));return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:r}),o.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[o.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"truncate text-sm font-medium",children:R}),o.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[t+1," / ",e.length]})]}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[a&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:P,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":s("rightSidebar.previousImage"),title:s("common.previous"),children:o.jsx(l0,{size:17})}),o.jsx("button",{type:"button",onClick:F,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":s("rightSidebar.nextImage"),title:s("common.next"),children:o.jsx(m8,{size:17})})]}),o.jsx("button",{type:"button",onClick:r,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":s("rightSidebar.closeImagePreview"),title:s("common.close"),children:o.jsx(ts,{size:18})})]})]}),o.jsx("div",{ref:u,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onPointerDown:C=>C.stopPropagation(),onPointerMove:C=>C.stopPropagation(),onTouchStart:C=>C.stopPropagation(),onTouchMove:C=>C.stopPropagation(),onClick:I,children:o.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${v}px, 0) scale(${Math.max(.86,1-v/900)})`,opacity:Math.max(.35,1-v/360),transition:A?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:o.jsx(uh,{onSwiper:C=>{c.current=C,C.allowTouchMove=a&&!g},onSlideChange:C=>{C.activeIndex!==t&&n(C.activeIndex)},initialSlide:t,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:e.map((C,$)=>o.jsx(Gu,{className:"h-full",children:o.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:C.kind==="image"?o.jsx(Gee,{src:C.src,alt:C.alt||C.title||s("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:L}):o.jsx(cte,{svg:C.svg,title:C.title||C.alt||s("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:L})})},`${C.kind}-${$}-${C.alt}`))})})})]})]})}function Vee({content:e,filePath:t,rootPath:n,lineRange:r,onLineRangeClick:s,onLineRangeDrag:i,scrollTop:a,outlineOpen:c,outlineCloseSignal:u,onOutlineOpen:f,onOutlineClose:p,lightboxOpen:g,lightboxCloseSignal:y,onLightboxOpen:v,onLightboxClose:S,onLocalLinkOpen:A}){const{t:T}=Yn(),[L,I]=b.useState(null),[j,P]=b.useState(null),[F,R]=b.useState(1),[C,$]=b.useState(null),H=b.useRef(null),Y=b.useRef(null),{blocks:V,images:fe}=b.useMemo(()=>Hee(e.split(`
193
+ `),t,n,Te=>{P(null),I(Te),v?.()},{footnotes:T("rightSidebar.footnotes"),backToFootnote:Te=>T("rightSidebar.backToFootnote",{index:Te})}),[e,t,n,v,T]),X=b.useMemo(()=>j?[...fe,j]:fe,[fe,j]),ve=b.useCallback(Te=>{P({kind:"mermaid",svg:Te,alt:"Mermaid diagram",title:"Mermaid diagram"}),I(fe.length),v?.()},[fe.length,v]);b.useEffect(()=>{I(null),P(null)},[e,t]),b.useEffect(()=>{I(null),P(null)},[y]),b.useEffect(()=>{g||(I(null),P(null))},[g]),b.useEffect(()=>{R(1)},[e,t]),b.useLayoutEffect(()=>{const Te=H.current;if(!Te||V.length===0)return;const ze=Array.from(Te.querySelectorAll("[data-markdown-preview-block-start]"));let Be=1;const We=28;for(const W of ze)if(W.offsetTop-a<=We)Be=Number(W.dataset.markdownPreviewBlockStart)||Be;else break;R(W=>W===Be?W:Be)},[V,a]);const we=b.useMemo(()=>Uee(V,F),[F,V]),ie=b.useMemo(()=>zee(V),[V]),ae=`${t??""}
194
+ ${e}`,q=b.useRef(ae),z=b.useRef(null),te=b.useRef(null),pe=b.useRef(!1);b.useEffect(()=>{q.current!==ae&&(q.current=ae,p?.())},[p,ae]),b.useEffect(()=>{u!==void 0&&$(null)},[u]),b.useLayoutEffect(()=>{if(!c){$(null);return}const Te=()=>{const ze=Y.current;if(!ze)return;const Be=ze.getBoundingClientRect(),We=window.innerWidth;$({top:Be.bottom+6,right:Math.max(8,We-Be.right)})};return Te(),window.addEventListener("resize",Te),window.addEventListener("scroll",Te,!0),()=>{window.removeEventListener("resize",Te),window.removeEventListener("scroll",Te,!0)}},[c,a,we]);const de=b.useCallback(Te=>{const ze=H.current,Be=ze?.closest("[data-markdown-preview-scroller]"),We=ze?.querySelector(`[data-markdown-preview-block-start="${Te.startLine}"]`);if(!Be||!We)return;const W=Be.getBoundingClientRect(),xe=We.getBoundingClientRect(),Ce=ze?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,Qe=xe.top-W.top+Be.scrollTop;Be.scrollTo({top:Math.max(0,Qe-Ce-8),behavior:"smooth"}),R(Te.startLine),p?.()},[p]),ke=b.useCallback(Te=>{Te.pointerType==="mouse"&&Te.button!==0||db(Te.target)||(z.current={pointerId:Te.pointerId,startX:Te.clientX,startY:Te.clientY})},[]),be=b.useCallback((Te,ze,Be)=>{const We=z.current;if(z.current=null,!We||We.pointerId!==Te.pointerId)return;const W=Math.abs(Te.clientX-We.startX),xe=Math.abs(Te.clientY-We.startY);if(W>8||xe>8)return;const He=Te.target;if(db(He)||G2())return;const Ce=t7(He,ze,Be);s(Te,Ce.start,Ce.end)},[s]),oe=b.useCallback(Te=>{z.current?.pointerId===Te.pointerId&&(z.current=null)},[]),he=b.useCallback((Te,ze)=>{const Be=H.current;if(!Be||typeof document.elementFromPoint!="function")return null;const We=document.elementFromPoint(Te,ze);if(!(We instanceof HTMLElement)||!Be.contains(We))return null;const W=We.closest("[data-md-ref-start]");if(W){const At=Number(W.dataset.mdRefStart);if(Number.isFinite(At)&&At>0)return At}const xe=We.closest("[data-markdown-preview-block-start]");if(!xe)return null;const He=Number(xe.dataset.markdownPreviewBlockStart),Ce=V.find(At=>At.startLine===He);if(!Ce)return Number.isFinite(He)&&He>0?He:null;if(Ce.endLine<=Ce.startLine)return Ce.startLine;const Qe=xe.getBoundingClientRect(),pt=Qe.height>0?Math.min(1,Math.max(0,(ze-Qe.top)/Qe.height)):0;return Math.round(Ce.startLine+pt*(Ce.endLine-Ce.startLine))},[V]),J=b.useCallback(Te=>{if(!i||Te.pointerType==="mouse"&&Te.button!==0)return;const ze=he(Te.clientX+24,Te.clientY);if(ze!=null){te.current={pointerId:Te.pointerId,anchorLine:ze,moved:!1};try{Te.currentTarget.setPointerCapture(Te.pointerId)}catch{}}},[i,he]),Xe=b.useCallback(Te=>{const ze=te.current;if(!ze||ze.pointerId!==Te.pointerId||!i)return;const Be=he(Te.clientX+16,Te.clientY);Be!=null&&(!ze.moved&&Be===ze.anchorLine||(ze.moved=!0,pe.current=!0,i(Te,Math.min(ze.anchorLine,Be),Math.max(ze.anchorLine,Be),"move")))},[i,he]),lt=b.useCallback(Te=>{const ze=te.current;if(te.current=null,!ze||ze.pointerId!==Te.pointerId||!i||!ze.moved)return;const Be=he(Te.clientX+16,Te.clientY)??ze.anchorLine;i(Te,Math.min(ze.anchorLine,Be),Math.max(ze.anchorLine,Be),"end")},[i,he]),Ze=b.useCallback(Te=>{te.current?.pointerId===Te.pointerId&&(te.current=null)},[]),ge={onPointerDown:J,onPointerMove:Xe,onPointerUp:lt,onPointerCancel:Ze},Fe=()=>pe.current?(pe.current=!1,!0):!1;return V.length===0?o.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:o.jsx("p",{className:"text-muted-foreground",children:T("rightSidebar.emptyFile")})}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{ref:H,className:"relative min-w-0 max-w-full",onClickCapture:Te=>{const ze=Te.target instanceof Element?Te.target.closest("a[href]"):null;if(!ze||!A)return;const Be=ze.getAttribute("href");if(!Be)return;const We=yee(Be,t,n);We&&(Te.preventDefault(),A(We))},children:[we.length>0&&o.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:o.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:we.map(Te=>Te.text).join(" / "),children:[o.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:we[we.length-1].text}),ie.length>1&&o.jsxs("button",{ref:Y,type:"button",onClick:()=>{c?p?.():f?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${c?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":c,"aria-label":T("rightSidebar.markdownOutline"),title:T("rightSidebar.markdownOutline"),children:[o.jsx(oy,{size:12}),o.jsx("span",{children:T("rightSidebar.markdownOutlineShort")})]})]})}),c&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:p}),o.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:C?{top:`${C.top}px`,right:`${C.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:o.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:ie.map(Te=>{const ze=we[we.length-1]?.startLine===Te.startLine;return o.jsxs("button",{type:"button",onClick:()=>de(Te),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${ze?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(Te.level-1,4)*12+8}px`},title:Te.text,children:[o.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ze?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),o.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",Te.level]}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:Te.text})]},`desktop-${Te.id}-${Te.startLine}`)})})}),o.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[o.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[o.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:T("rightSidebar.markdownOutlineShort")}),o.jsx("button",{type:"button",onClick:p,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":T("rightSidebar.closeMarkdownOutline"),title:T("common.close"),children:o.jsx(ts,{size:14})})]}),o.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:ie.map(Te=>{const ze=we[we.length-1]?.startLine===Te.startLine;return o.jsxs("button",{type:"button",onClick:()=>de(Te),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${ze?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(Te.level-1,4)*12+8}px`},title:Te.text,children:[o.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ze?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),o.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",Te.level]}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:Te.text})]},`${Te.id}-${Te.startLine}`)})})]})]}),o.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:o.jsx(zT.Provider,{value:ve,children:V.map(Te=>{const ze=!!(r&&Te.startLine<=r.end&&Te.endLine>=r.start),Be=!!(r&&r.start<=Te.startLine&&r.end>=Te.endLine),We=Te.kind==="table"?!1:Te.fineGrained?Be:ze,W=Te.kind==="table"&&r?.start===Te.startLine&&r.end===Te.endLine;let xe=null;if(Te.kind!=="table"&&Te.fineGrained&&ze&&!Be&&r){const pt=Te.endLine-Te.startLine+1,At=Math.max(r.start,Te.startLine),yt=Math.min(r.end,Te.endLine),Yt=(At-Te.startLine)/pt,Mt=(yt-At+1)/pt;xe=o.jsx("span",{"aria-hidden":"true","data-md-rail-segment":!0,className:"absolute left-1/2 w-0.5 -translate-x-1/2 rounded-full bg-primary transition sm:w-1",style:{top:`calc(0.25rem + (100% - 0.5rem) * ${Yt})`,height:`calc((100% - 0.5rem) * ${Mt})`}})}const He=typeof Te.content=="function"?Te.content(r):Te.content,Ce=Te.startLine===Te.endLine?String(Te.startLine):`${Te.startLine}-${Te.endLine}`,Qe=o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:lb(We),"aria-hidden":"true",...ge,children:[o.jsx("span",{className:cb(We)}),xe]}),o.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:He})]});return Te.interactive===!1?o.jsxs("div",{"data-markdown-preview-block-start":Te.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${We?"bg-primary/10":""}`,title:`Line ${Ce}`,"aria-label":`Line ${Ce}`,children:[Te.kind==="table"?o.jsx("button",{type:"button",className:lb(W,"self"),onClick:pt=>{pt.preventDefault(),!Fe()&&s(pt,Te.startLine,Te.endLine)},title:`Reference table lines ${Ce}`,"aria-label":`Reference table lines ${Ce}`,...ge,children:o.jsx("span",{className:cb(W,"self")})}):o.jsxs("span",{className:lb(We,"none"),"aria-hidden":"true",...ge,children:[o.jsx("span",{className:cb(We,"none")}),xe]}),o.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:ke,onPointerUp:pt=>be(pt,Te.startLine,Te.endLine),onPointerCancel:oe,onKeyDown:pt=>{pt.key!=="Enter"&&pt.key!==" "||(pt.preventDefault(),s(pt,Te.startLine,Te.endLine))},title:`Reference line ${Ce}`,"aria-label":`Reference line ${Ce}`,children:He})]},Te.key):o.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":Te.startLine,onClick:pt=>{const At=pt.target;if(db(At)||G2()||Fe())return;const yt=t7(At,Te.startLine,Te.endLine);s(pt,yt.start,yt.end)},onKeyDown:pt=>{pt.key!=="Enter"&&pt.key!==" "||(pt.preventDefault(),s(pt,Te.startLine,Te.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${We?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Ce}`,"aria-label":`Reference line ${Ce}`,children:Qe},Te.key)})})})]}),g&&L!==null&&X[L]&&o.jsx(Wee,{images:X,index:L,onChange:I,onClose:()=>{I(null),P(null),S?.()}})]})}function jd({label:e,value:t,options:n,placeholder:r,searchPlaceholder:s,emptyText:i,disabled:a,onChange:c}){const{t:u}=Yn(),[f,p]=b.useState(!1),[g,y]=b.useState(""),[v,S]=b.useState(null),A=b.useRef(null),T=b.useRef(null),L=g.trim().toLowerCase(),I=b.useMemo(()=>L?n.filter(C=>`${C.label} ${C.meta??""}`.toLowerCase().includes(L)):n,[L,n]),j=n.find(C=>C.value===t),P=()=>{const C=g.trim();C&&(c(C),p(!1),y(""))},F=b.useCallback(()=>{const C=A.current?.getBoundingClientRect();if(!C)return!1;const $=12,H=Math.max(220,Math.min(C.width,window.innerWidth-$*2)),Y=Math.min(Math.max($,C.left),window.innerWidth-H-$),V=window.innerHeight-C.bottom-$,fe=C.top-$,X=V>=180||V>=fe,ve=Math.max(96,(X?V:fe)-4),we=Math.min(320,ve);return S({left:Y,top:X?C.bottom+4:Math.max($,C.top-we-4),width:H,maxHeight:we}),!0},[]),R=()=>{F(),p(!0)};return b.useEffect(()=>{if(!f)return;let C=0;const $=()=>{C||(C=window.requestAnimationFrame(()=>{C=0,F()}))},H=Y=>{const V=Y.target;V instanceof Node&&(A.current?.contains(V)||T.current?.contains(V)||(p(!1),y("")))};return window.addEventListener("resize",$),window.addEventListener("scroll",$,!0),document.addEventListener("pointerdown",H,!0),()=>{C&&window.cancelAnimationFrame(C),window.removeEventListener("resize",$),window.removeEventListener("scroll",$,!0),document.removeEventListener("pointerdown",H,!0)}},[f,F]),o.jsxs("div",{className:"relative min-w-0",children:[o.jsxs("button",{ref:A,type:"button",disabled:a,onClick:()=>{if(!a){if(y(""),f){p(!1);return}R()}},className:"group flex w-full items-center justify-between gap-2 rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-left transition hover:bg-surface-elevated disabled:cursor-not-allowed disabled:opacity-50",children:[o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block text-[9px] font-medium uppercase tracking-wide text-muted-foreground",children:e}),o.jsx("span",{className:`block truncate text-[12px] ${t?"text-foreground":"text-muted-foreground/70"}`,children:j?.label??(t||r)})]}),o.jsx(ra,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${f?"rotate-180":""}`})]}),f&&!a&&typeof document<"u"&&sa.createPortal(o.jsxs("div",{ref:T,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:C=>C.stopPropagation(),style:{left:v?.left??12,top:v?.top??12,width:v?.width??260,maxHeight:v?.maxHeight??320},children:[o.jsx("div",{className:"border-b border-border/10 p-1.5",children:o.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[o.jsx(Jl,{size:12,className:"shrink-0 text-muted-foreground"}),o.jsx("input",{autoFocus:!0,value:g,onChange:C=>y(C.target.value),onKeyDown:C=>{if(C.key==="Escape"){C.preventDefault(),p(!1),y("");return}C.key==="Enter"&&(C.preventDefault(),P())},onBlur:()=>{g.trim()&&I.length===0&&P()},placeholder:s,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),o.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(v?.maxHeight??320)-46)},children:[g.trim()&&!n.some(C=>C.value===g.trim())&&o.jsxs("button",{type:"button",onMouseDown:C=>C.preventDefault(),onClick:P,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[o.jsx("span",{className:"min-w-0 truncate",children:g.trim()}),o.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:u("common.use")})]}),I.length>0?I.map(C=>o.jsxs("button",{type:"button",onClick:()=>{c(C.value),p(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${C.value===t?"bg-accent/10 text-accent":"text-foreground"}`,children:[o.jsx("span",{className:"min-w-0 truncate font-medium",children:C.label}),C.meta&&o.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:C.meta})]},C.value)):o.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:i})]})]}),document.body)]})}function W4({open:e,onOpenChange:t,showScopePicker:n,selectedAll:r,repos:s,selectedRoots:i,onToggleRepo:a,onGenerate:c,onSecondaryAction:u,disabled:f,generateDisabled:p,secondaryDisabled:g,inserted:y,buttonLabel:v,insertedLabel:S,title:A,ariaLabel:T,scopeTitle:L,scopeLabel:I,allLabel:j,generateLabel:P,secondaryLabel:F,secondaryTitle:R,secondaryLoading:C,loading:$,error:H,statusTitle:Y,extraContent:V,renderRepoExtra:fe}){return o.jsxs("div",{className:"relative inline-flex shrink-0",children:[o.jsxs("button",{type:"button",onClick:()=>{n?t(!e):p||c()},disabled:f,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${H?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":T,title:Y??(n?`${L}: ${I}`:A),children:[$?o.jsx(Fn,{size:13,className:"animate-spin"}):o.jsx(ru,{size:13}),o.jsx("span",{children:y?S:v}),n&&o.jsx(ra,{size:11,className:`shrink-0 transition ${e?"rotate-180":""}`}),H&&o.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),n&&e&&o.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] px-3 py-6 backdrop-blur-sm animate-fade-in",onClick:()=>t(!1),children:o.jsxs("div",{className:"fixed left-1/2 top-1/2 z-modal-panel flex max-h-[min(82vh,36rem)] w-[calc(100vw-1.5rem)] max-w-[42rem] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/20 bg-surface text-[11px] shadow-2xl",onClick:X=>X.stopPropagation(),children:[o.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:L}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:I})]}),o.jsx("button",{type:"button",onClick:()=>t(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:o.jsx(ts,{size:14})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[V,o.jsxs("button",{type:"button",onClick:()=>a(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${r?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[o.jsx("span",{className:"truncate",children:j}),r&&o.jsx("span",{className:"text-[10px]",children:"✓"})]}),s.map(X=>{const ve=i.includes(X.root);return o.jsxs("div",{className:`mt-1 rounded-md transition ${ve?"bg-primary/15 text-primary":""}`,children:[o.jsxs("button",{type:"button",onClick:()=>a(X.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${ve?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:X.root,children:[o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block truncate",children:X.label}),X.branch&&o.jsx("span",{className:"block truncate text-[9px] opacity-70",children:X.branch})]}),ve&&o.jsx("span",{className:"text-[10px]",children:"✓"})]}),fe&&(r||ve)&&o.jsx("div",{className:"px-2 pb-2",children:fe(X)})]},X.root)})]}),o.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${u&&F?"sm:grid-cols-2":""}`,children:[u&&F&&o.jsxs("button",{type:"button",onClick:()=>{g||(t(!1),u())},disabled:g,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:R,children:[C?o.jsx(Fn,{size:12,className:"animate-spin"}):o.jsx(Df,{size:12}),F]}),o.jsxs("button",{type:"button",onClick:()=>{p||(t(!1),c())},disabled:p,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:A,children:[o.jsx(ru,{size:12}),P]})]})]})})]})}function qee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;for(const t of Object.values(e)){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;if(typeof n.top!="number"||!Number.isFinite(n.top)||typeof n.updatedAt!="number"||!Number.isFinite(n.updatedAt))return!1}return!0}function uC(){return Or(av,qee)??{}}function Yee(e,t){const n=uC(),r=Object.entries({...n,[e]:{top:t,updatedAt:Date.now()}}).sort(([,s],[,i])=>i.updatedAt-s.updatedAt).slice(0,FJ);n0(av,Object.fromEntries(r),QJ)}function Kee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return typeof t.start=="number"&&Number.isFinite(t.start)&&typeof t.end=="number"&&Number.isFinite(t.end)&&t.start>=1&&t.end>=t.start}function Xee(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;for(const t of Object.values(e)){if(!t||typeof t!="object"||Array.isArray(t))return!1;const n=t;if(typeof n.top!="number"||!Number.isFinite(n.top)||n.left!==void 0&&(typeof n.left!="number"||!Number.isFinite(n.left))||n.markdownTop!==void 0&&(typeof n.markdownTop!="number"||!Number.isFinite(n.markdownTop))||n.lineRange!==void 0&&n.lineRange!==null&&!Kee(n.lineRange)||typeof n.updatedAt!="number"||!Number.isFinite(n.updatedAt))return!1}return!0}function mv(e,t){if(!t)return null;const n=e&&!t.startsWith("/")?`${e}/${t}`:t;return e?`${e}::${n}`:n}function dC(){return Or(lv,Xee)??{}}function V4(e,t){const n=mv(e,t);return n?dC()[n]??null:null}function ob(e,t,n){const r=mv(e,t);if(!r)return;const s=dC(),i=s[r]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},a=Object.entries({...s,[r]:{...i,...n,updatedAt:Date.now()}}).sort(([,c],[,u])=>u.updatedAt-c.updatedAt).slice(0,OJ);n0(lv,Object.fromEntries(a),$J)}function ab({active:e,mounted:t=!0,fallback:n=null,children:r}){return o.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${e?"block":"hidden"}`,"aria-hidden":!e,children:t?typeof r=="function"?r():r:n})}function gf({slow:e}){const{t}=Yn();return o.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:[o.jsx(Fn,{size:20,className:"mx-auto mb-2 animate-spin text-muted-foreground/80"}),o.jsx("div",{children:t("rightSidebar.loadingGitChanges")}),e&&o.jsx("div",{className:"mt-1 text-xs text-muted-foreground/75",children:t("rightSidebar.loadingGitChangesSlow")})]})}function Wp({message:e,onRetry:t}){const{t:n}=Yn();return o.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[o.jsx("div",{className:"font-medium",children:n("rightSidebar.gitChangesLoadFailed")}),o.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:e}),o.jsx("button",{type:"button",onClick:t,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:n("rightSidebar.retryGitChanges")})]})}function vm(e,t){const n=t&&e.startsWith(`${t}/`)?e.slice(t.length+1):e,r=n.split("/").filter(Boolean);return{name:r.pop()||n,dir:r.join("/")}}function bo(e){if(!e)return"";const t=e.replace(/\/+$/,"");return t.split("/").pop()||t||"/"}function q4(e){if(!e)return null;const t=e.replace(/\/+$/,"")||"/";if(t==="/")return null;const n=t.slice(0,t.lastIndexOf("/"))||"/";return n===t?null:n}function Y4(e,t,n){const r=Math.min(t,n),s=Math.max(t,n);return e?.start===r&&e.end===s?null:e&&e.start===e.end?{start:Math.min(e.start,r),end:Math.max(e.end,s)}:{start:r,end:s}}function lb(e,t="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${e?"bg-primary/20":`bg-[var(--surface-2)] ${t==="group"?"group-hover:bg-[var(--surface-elevated)]":t==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function cb(e,t="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${e?"bg-primary":`bg-[var(--border-strong)] ${t==="group"?"group-hover:bg-[var(--muted-foreground)]":t==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function K4(e,t){return`pointer-events-auto absolute z-30 inline-flex items-center gap-1 rounded-full font-semibold shadow-lg ring-1 transition active:scale-95 ${e?"h-9 px-4 text-[12px]":"h-7 px-3 text-[11px]"} ${t?"bg-surface-elevated text-foreground ring-border-strong/40 hover:bg-surface-2":"bg-primary text-primary-foreground ring-primary/30 hover:bg-primary/90"}`}function fC(e){const t=new Map;for(const n of e)t.set(gv(n),n);return t}function hC(e,t){const n=new Map(e);for(const r of t)n.set(gv(r),r);return n}function X4(e,t){let n=0;for(const r of e){const s=Oo(r,t);s&&t&&s!==t&&(n+=1)}return n}function Zee(e){return e.reduce((t,n)=>t+(n.staged?1:0),0)}function Jee(e,t){return Array.from(hC(fC(e),t).values()).sort((n,r)=>n.path.localeCompare(r.path))}function ete(e,t){if(e.files.length===0)return null;const n=e.relativeRoot==="."?bo(t??e.root)||e.name||e.root:e.relativeRoot||e.name||bo(e.root)||e.root;return{root:e.root,label:n,branch:e.context?.branch??null,count:e.files.length,staged:Zee(e.files)}}function pC(e,t){const n=bo(t??"")||t||"";return e.map(r=>ete(r,t)).filter(r=>!!r).sort((r,s)=>n&&r.label===n?-1:n&&s.label===n?1:r.label.localeCompare(s.label))}function tte(e,t,n,r,s){const i=OT(n),a=i.find(A=>A.root===r)??i[0]??null,c=t.find(A=>A.root===r)??null,u=c?.relativeRoot??a?.relativeRoot??".",f=c?.name??a?.name??(bo(r)||r),p=(a?.files??n.files).map(A=>({...A,repoRoot:r,repoRelativeRoot:u,repoName:f})),g=a?.context??n.context,y={...c??a??{id:r,root:r,relativeRoot:u,name:f,depth:0,nested:!!(s&&r!==s),available:n.available,files:[],context:null},...a??{},id:c?.id??a?.id??r,root:r,displayRoot:c?.displayRoot??a?.displayRoot,relativeRoot:u,name:f,depth:c?.depth??a?.depth??0,nested:c?.nested??a?.nested??!!(s&&r!==s),available:a?.available??n.available,files:p,context:g?{...g,root:r,changedFiles:p.map(A=>({path:A.path,absolutePath:A.absolutePath,status:A.status}))}:null,untrackedDeferred:a?.untrackedDeferred??n.untrackedDeferred,error:a?.error??n.error},v=c?t.map(A=>A.root===r?y:A):[...t,y];return{files:Array.from(e).filter(A=>Oo(A,s)!==r).concat(p),repositories:v,repoFilters:pC(v,s)}}function Oo(e,t){return e.repoRoot??t}function gv(e){return`${e.repoRoot??""}\0${e.path}`}function xo(e){return e.absolutePath||e.path}function ub(e){return gv(e)}function nte(e){return e.repoRelativeRoot&&e.repoRelativeRoot!=="."?e.repoRelativeRoot:e.repoName??""}function Z4(e){return e.reduce((t,n)=>t+(n.staged?1:0),0)}function J4(e){const t={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const n of e)n.status==="added"?t.added+=1:n.status==="modified"?t.modified+=1:n.status==="deleted"?t.deleted+=1:n.status==="renamed"?t.renamed+=1:n.status==="copied"?t.copied+=1:n.status==="untracked"?t.untracked+=1:n.status==="conflicted"?t.conflicted+=1:t.other+=1,n.staged&&(t.staged+=1);return t}function Pd(e){let t=0;const n=e??"root";for(let r=0;r<n.length;r+=1)t=Math.imul(t^n.charCodeAt(r),16777619);return`right-sidebar-git-bundle:${(t>>>0).toString(36)}`}function xf(e,t){return typeof e!="number"||!Number.isFinite(e)||e<=0?null:new Intl.DateTimeFormat(t==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(e))}function pc(e){return e instanceof DOMException&&e.name==="AbortError"}function rte(e){const t=e.error??e.context?.error??"";return t.includes("request was cancelled")||t.includes("IO_REQUEST_CANCELLED")}function e7(e){return e?.available===!1&&e.code==="NOT_GIT_REPOSITORY"}function G2(){if(typeof window>"u")return!1;const e=window.getSelection();return!!(e&&!e.isCollapsed&&e.toString().trim())}function db(e){return e instanceof HTMLElement&&!!e.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function t7(e,t,n){const r=e instanceof HTMLElement?e.closest("[data-md-ref-start]"):null,s=Number(r?.dataset.mdRefStart),i=Number(r?.dataset.mdRefEnd??r?.dataset.mdRefStart);return Number.isFinite(s)&&s>0&&Number.isFinite(i)&&i>0?{start:Math.min(s,i),end:Math.max(s,i)}:{start:t,end:n}}function ste({actions:e,running:t,completed:n}){const{t:r}=Yn(),[s,i]=b.useState(!1),a=b.useRef(null),c=e.find(f=>t?.action===f.key),u=e.find(f=>n?.action===f.key);return e.length===0?null:(b.useEffect(()=>{if(!s)return;const f=g=>{const y=g.target;y instanceof Node&&a.current?.contains(y)||i(!1)},p=g=>{g.key==="Escape"&&i(!1)};return document.addEventListener("pointerdown",f),document.addEventListener("keydown",p),()=>{document.removeEventListener("pointerdown",f),document.removeEventListener("keydown",p)}},[s]),o.jsxs("div",{ref:a,className:"relative shrink-0",children:[o.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),i(p=>!p)},disabled:e.every(f=>f.disabled)&&!t&&!n,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-50 ${s?"bg-surface-elevated text-foreground":u?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:c?.label??u?.label??r("rightSidebar.gitQuickActions"),children:c?o.jsx(Fn,{size:13,className:"animate-spin"}):u?o.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):o.jsx(tu,{size:14})}),s&&o.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:e.map(f=>{const p=t?.action===f.key,g=n?.action===f.key;return o.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),f.onClick(),i(!1)},disabled:f.disabled||!!t,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${g?"bg-accent/10 text-accent":f.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[o.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:p?o.jsx(Fn,{size:13,className:"animate-spin"}):g?"✓":null}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:f.label})]},f.key)})})]}))}function ite(e){const t=window.getComputedStyle(e).overflowY;return(t==="auto"||t==="scroll")&&e.scrollHeight>e.clientHeight+1}function mC(e){let t=e;for(;t;){if(t.classList.contains("termdock-diff-stream-scroller")&&ite(t))return t;t=t.parentElement}return e.closest(".termdock-diff-stream-scroller")}function s0(e){return e.getClientRects().length>0&&window.getComputedStyle(e).visibility!=="hidden"}const fb=new WeakMap;function cg(e){const t=fb.get(e);t!==void 0&&window.clearTimeout(t),e.classList.remove("diff-walkthrough-target"),e.offsetWidth,e.classList.add("diff-walkthrough-target");const n=window.setTimeout(()=>{e.classList.remove("diff-walkthrough-target"),fb.delete(e)},1700);fb.set(e,n)}function ote(e){const t=CSS.escape(e),n=[`[data-diff-stream-item="${t}"]`,`[data-diff-selection-path="${t}"]`,`[data-diff-absolute-path="${t}"]`].join(","),r=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let s=null;for(const c of r){if(!s0(c))continue;const u=c.querySelector(n);if(u&&s0(u)){s=u;break}}if(s??=Array.from(document.querySelectorAll(n)).find(s0)??null,!s)return;const i=mC(s);if(!i){s.scrollIntoView({block:"start",behavior:"smooth"}),cg(s);return}const a=s.getBoundingClientRect().top-i.getBoundingClientRect().top+i.scrollTop;i.scrollTo({top:Math.max(0,a),behavior:"instant"}),cg(s)}function _u(e){const t=CSS.escape(e.filePath),n=typeof e.sectionIndex=="number"?String(e.sectionIndex):null,r=typeof e.hunkIndex=="number"?String(e.hunkIndex):null,s=e.sectionFingerprint?CSS.escape(e.sectionFingerprint):null,i=e.hunkFingerprint?CSS.escape(e.hunkFingerprint):null,a=[n!==null&&s?`[data-diff-section-audit="${t}"][data-diff-section-index="${n}"][data-diff-section-fingerprint="${s}"]`:null,n!==null&&s?`[data-diff-section-anchor="${t}"][data-diff-section-index="${n}"][data-diff-section-fingerprint="${s}"]`:null,n!==null?`[data-diff-section-audit="${t}"][data-diff-section-index="${n}"]`:null,n!==null?`[data-diff-section-anchor="${t}"][data-diff-section-index="${n}"]`:null,r!==null&&i?`[data-diff-hunk-anchor="${t}"][data-diff-hunk-index="${r}"][data-diff-hunk-fingerprint="${i}"]`:null,r!==null?`[data-diff-hunk-anchor="${t}"][data-diff-hunk-index="${r}"]`:null,`[data-diff-file-path="${t}"]`].filter(S=>!!S),c=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let u=null;for(const S of c)if(s0(S)){for(const A of a){const T=S.querySelector(A);if(T&&s0(T)){u=T;break}}if(u)break}if(u??=a.flatMap(S=>Array.from(document.querySelectorAll(S))).find(s0)??null,!u){ote(e.filePath);return}const f=mC(u);if(!f){u.scrollIntoView({block:"center",behavior:"smooth"}),cg(u);return}const p=u.getBoundingClientRect(),g=f.getBoundingClientRect(),v=p.top-g.top+f.scrollTop-Math.max(24,(f.clientHeight-p.height)/2);f.scrollTo({top:Math.max(0,v),behavior:"instant"}),cg(u)}const gC=1,xC=8;function ate(e){return Math.min(xC,Math.max(gC,e))}function bC({resetKey:e,onZoomChange:t,onDoubleTap:n,children:r}){const s=b.useRef(null),[i,a]=b.useState({scale:1,x:0,y:0}),[c,u]=b.useState(!1),f=b.useRef(null),p=b.useRef(new Set),g=b.useRef(!1),y=b.useRef(null),v=b.useRef(0),S=b.useRef(i);S.current=i,b.useEffect(()=>{a({scale:1,x:0,y:0})},[e]);const A=b.useCallback((j,P,F)=>{const R=s.current;if(!R)return{x:P,y:F};const C=R.firstElementChild instanceof HTMLElement?R.firstElementChild:null,$=C?.clientWidth||R.clientWidth,H=C?.clientHeight||R.clientHeight,Y=Math.max(0,($*j-R.clientWidth)/2),V=Math.max(0,(H*j-R.clientHeight)/2);return{x:Math.min(Y,Math.max(-Y,P)),y:Math.min(V,Math.max(-V,F))}},[]),T=b.useCallback((j,P,F)=>{a(R=>{const C=ate(j),$=s.current;if(!$||C===1)return{scale:C,x:0,y:0};const H=$.getBoundingClientRect(),Y=(P??H.left+H.width/2)-H.left-H.width/2,V=(F??H.top+H.height/2)-H.top-H.height/2,fe=C/R.scale,X=Y-(Y-R.x)*fe,ve=V-(V-R.y)*fe;return{scale:C,...A(C,X,ve)}})},[A]),L=b.useCallback((j,P)=>{u(!0),S.current.scale>1?a({scale:1,x:0,y:0}):T(2.5,j,P),window.setTimeout(()=>u(!1),220)},[T]);b.useEffect(()=>{const j=s.current;if(!j)return;const P=C=>{if(C.pointerType==="mouse"&&C.button!==0)return;const $=p.current.size===0;if(p.current.add(C.pointerId),$){const H=Date.now(),Y=y.current;if(Y&&H-Y.time<350&&Math.hypot(C.clientX-Y.x,C.clientY-Y.y)<24){y.current=null,v.current=H,n?.(),L(C.clientX,C.clientY);return}}if(p.current.size>1){g.current=!0,f.current=null;return}if(!(S.current.scale<=1)){C.preventDefault(),f.current={pointerId:C.pointerId,startX:C.clientX,startY:C.clientY,originX:S.current.x,originY:S.current.y,moved:!1};try{j.setPointerCapture?.(C.pointerId)}catch{}u(!1)}},F=C=>{const $=f.current;if(!$||$.pointerId!==C.pointerId)return;const H=C.clientX-$.startX,Y=C.clientY-$.startY;if(!$.moved){if(Math.hypot(H,Y)<6)return;$.moved=!0}C.stopPropagation(),C.preventDefault(),a(V=>({...V,...A(V.scale,$.originX+H,$.originY+Y)}))},R=C=>{const $=f.current,H=$?.pointerId===C.pointerId&&$.moved;if($?.pointerId===C.pointerId){$.moved&&C.stopPropagation(),f.current=null;try{j.releasePointerCapture?.(C.pointerId)}catch{}}p.current.delete(C.pointerId)&&p.current.size===0&&(!g.current&&!H&&(y.current={time:Date.now(),x:C.clientX,y:C.clientY}),g.current=!1)};return j.addEventListener("pointerdown",P,{capture:!0,passive:!1}),window.addEventListener("pointermove",F,{capture:!0,passive:!1}),window.addEventListener("pointerup",R,{capture:!0}),window.addEventListener("pointercancel",R,{capture:!0}),()=>{j.removeEventListener("pointerdown",P,{capture:!0}),window.removeEventListener("pointermove",F,{capture:!0}),window.removeEventListener("pointerup",R,{capture:!0}),window.removeEventListener("pointercancel",R,{capture:!0})}},[A,n,L]),b9({onPinch:({offset:[j],origin:[P,F]})=>{u(!1),T(j,P,F)},onWheel:({event:j,delta:[P,F],ctrlKey:R})=>{if(R){j.preventDefault(),j.stopPropagation(),u(!1),T(S.current.scale*(1-F*.01),j.clientX,j.clientY);return}S.current.scale<=1||(j.preventDefault(),j.stopPropagation(),u(!1),a(C=>({...C,...A(C.scale,C.x-P,C.y-F)})))}},{target:s,eventOptions:{passive:!1},pinch:{scaleBounds:{min:gC,max:xC},from:()=>[S.current.scale,0],rubberband:!0}});const I=i.scale>1;return b.useEffect(()=>{t?.(I)},[t,I]),o.jsx("div",{ref:s,"data-sidebar-gesture-ignore":I?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:I?"grab":"zoom-in"},onDoubleClick:j=>{j.stopPropagation(),!(Date.now()-v.current<500)&&(n?.(),L(j.clientX,j.clientY))},children:r({scale:i.scale,zoomed:I,animateTransform:c,transformStyle:{transform:`translate3d(${i.x}px, ${i.y}px, 0) scale(${i.scale})`,transformOrigin:"center center",transition:c?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${i.x}px, ${i.y}px, 0)`,transformOrigin:"center center",transition:c?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function yC({src:e,alt:t,vector:n,onLoad:r,onError:s,onZoomChange:i,onDoubleTap:a}){const[c,u]=b.useState(null),f=n??uv(e);return b.useEffect(()=>{u(null)},[e]),o.jsx(bC,{resetKey:e,onZoomChange:i,onDoubleTap:a,children:({transformStyle:p,vectorTransformStyle:g,scale:y,animateTransform:v})=>{const S=o.jsx("img",{src:e,alt:t,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&c?{position:"absolute",left:"50%",top:"50%",width:c.width*y,height:c.height*y,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:v?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:c?{...p,width:c.width,height:c.height}:f?g:p,onLoad:A=>{const T=A.currentTarget,L=T.parentElement;if(L&&T.naturalWidth>0&&T.naturalHeight>0){const I=Math.max(1,L.clientWidth-2),j=Math.max(1,L.clientHeight-2),P=Math.min(I/T.naturalWidth,j/T.naturalHeight),F=f?P:Math.min(P,1);u({width:Math.max(1,Math.round(T.naturalWidth*F)),height:Math.max(1,Math.round(T.naturalHeight*F))})}r(A)},onError:s});return!f||!c?S:o.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...g,width:c.width,height:c.height},children:S})}})}function lte({svg:e,title:t,scale:n,vectorTransformStyle:r}){const s=b.useRef(null);return b.useLayoutEffect(()=>{const i=s.current,a=i?.querySelector("svg");if(!i||!a)return;const c=()=>{const p=a.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let g=p[2],y=p[3];if((!Number.isFinite(g)||!Number.isFinite(y)||g<=0||y<=0)&&(g=Number(a.getAttribute("width")),y=Number(a.getAttribute("height"))),!Number.isFinite(g)||!Number.isFinite(y)||g<=0||y<=0)return;const v=Math.max(1,i.clientWidth-24),S=Math.max(1,i.clientHeight-24),A=Math.min(v/g,S/y,1);a.style.width=`${Math.max(1,Math.floor(g*A*n))}px`,a.style.height=`${Math.max(1,Math.floor(y*A*n))}px`,a.style.maxWidth="none",a.style.maxHeight="none",a.style.transform=String(r.transform??""),a.style.transformOrigin="center center",a.style.transition=String(r.transition??"none")};c();const u=typeof ResizeObserver>"u"?null:new ResizeObserver(c);return u?.observe(i),()=>u?.disconnect()},[n,e,r]),o.jsx("div",{ref:s,role:"img","aria-label":t,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:e}})}function cte({svg:e,title:t,onZoomChange:n,onDoubleTap:r}){return o.jsx(bC,{resetKey:e,onZoomChange:n,onDoubleTap:r,children:({vectorTransformStyle:s,scale:i})=>o.jsx(lte,{svg:e,title:t,scale:i,vectorTransformStyle:s})})}let ute=0,dte=0,fte=0,hte=0;function hb(e,t={}){if(typeof window>"u")return;const n=JSON.stringify({level:e==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${e}`,data:{ts:Date.now(),...t}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0}).catch(()=>{})}function oi(e,t={}){if(typeof window>"u")return;const n=JSON.stringify({level:e==="error"||e==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${e}`,data:{seq:++dte,ts:Date.now(),...t}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0}).catch(()=>{})}function Vp(e,t={}){if(typeof window>"u")return;const n=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${e}`,data:{seq:++fte,ts:Date.now(),...t}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:n,keepalive:!0}).catch(()=>{})}function pte(){return`diff-ui-${Date.now().toString(36)}-${(++hte).toString(36)}`}function mte(e){return e instanceof Element?e.closest("[data-diff-selection-path]"):null}function gte(e){const t=e.target instanceof HTMLElement?e.target:null;return{eventType:e.type,button:e.button,pointerType:e instanceof globalThis.PointerEvent?e.pointerType:void 0,targetTag:t?.tagName,targetClass:t?.className,targetText:t?.textContent?.slice(0,80)}}function n7({filePath:e,onInsertReference:t,onInsertText:n,onInsertFeature:r,onReferenceCopied:s,onClose:i,onDirectoryLinkOpen:a,isMobile:c,markdownOutlineOpen:u,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:p,onCloseMarkdownOutline:g,markdownImageLightboxOpen:y,markdownImageLightboxCloseSignal:v,onOpenMarkdownImageLightbox:S,onCloseMarkdownImageLightbox:A,lineRange:T,onLineRangeChange:L,insertedReferenceKey:I,copiedReferenceKey:j,scrollToLine:P,onScrollToLineHandled:F}){const{t:R}=Yn(),C=ft(qe=>qe.rootPath),$=ft(qe=>qe.selectFile),[H,Y]=b.useState({kind:"idle"}),[V,fe]=b.useState("schematic"),[X,ve]=b.useState(null),we=b.useRef(null),[ie,ae]=b.useState(null),q=b.useRef(new Map),z=b.useRef(null),[te,pe]=b.useState(null),[de,ke]=b.useState(()=>j4()),[be,oe]=b.useState(()=>C4(C,e)),he=b.useRef(null),[J,Xe]=b.useState(!1),[lt,Ze]=b.useState(null),[ge,Fe]=b.useState(0),[Te,ze]=b.useState([]),[Be,We]=b.useState(null),W=b.useRef(null),xe=b.useRef(e),[He,Ce]=b.useState(null),[Qe,pt]=b.useState({status:"idle"}),[At,yt]=b.useState(!1),[Yt,Mt]=b.useState(""),[on,xr]=b.useState([]),[Cn,or]=b.useState(0),Le=b.useRef(null),ot=C0(s),Oe=mv(C,e);b.useEffect(()=>{if(xe.current===e)return;xe.current=e;const qe=e&&C&&!e.startsWith("/")?`${C}/${e}`:e;if(W.current===qe){W.current=null;return}W.current=null,ze([]),We(null),yt(!1),Mt("")},[e,C]);const Dt=e?C&&!e.startsWith("/")?`${C}/${e}`:e:null,$e=ft(qe=>Dt?(qe.fileChangeVersions.get(Dt)??0)+qe.fileWatchEpoch:qe.fileWatchEpoch),Ut=b.useRef(null),_t=b.useRef(null),[Ve,Ur]=b.useState(0),kn=b.useCallback(()=>Ur(qe=>qe+1),[]);b.useEffect(()=>{const qe=we.current;return we.current=null,ve(null),qe&&URL.revokeObjectURL(qe.objectUrl),()=>{const ct=we.current;we.current=null,ct&&URL.revokeObjectURL(ct.objectUrl)}},[Dt,$e,Ve]),b.useEffect(()=>{if(!e){Ut.current=null,Y({kind:"idle"});return}const qe=C&&!e.startsWith("/")?`${C}/${e}`:e,ct=new AbortController,jt=++ute,dn=`right-sidebar-file-preview:${jt}`,An=performance.now();let _n=!1;const ln=(st,wt={})=>{_n||(_n=!0,hb("end",{loadingId:jt,reason:st,durationMs:Math.round(performance.now()-An),filePath:e,fullPath:qe,rootPath:C,...wt}))};let pn=null;const tn=aI(qe),cn=tn?qe.toLowerCase().endsWith(".kicad_pcb")?V==="schematic"?"pcb-front":V:"schematic":V,sr=!tn&&ey(qe),ps=!tn&&!sr&&t8(qe),Qr=!tn&&!sr&&!ps&&J7(qe),se=mf(qe),_e=U0(qe),je=tn?"eda":sr?"image":ps?"model3d":Qr?"video":"text",tt=Ut.current!==qe;if(Ut.current=qe,tt){hb("start",{loadingId:jt,filePath:e,fullPath:qe,rootPath:C,mode:je,externalVersion:$e}),pt({status:"idle"}),Y({kind:"loading",mode:je}),_t.current=null;const st=V4(C,e);L(st?.lineRange??null),ke(se?j4():"source"),oe(_e?C4(C,e):"source"),tn&&fe(lI(qe))}const Qt=window.setTimeout(()=>{_n||ct.signal.aborted||hb("still_active",{loadingId:jt,filePath:e,fullPath:qe,rootPath:C,mode:je,durationMs:Math.round(performance.now()-An),isPathChange:tt})},3e3),Nt=window.setTimeout(()=>{if(_n||ct.signal.aborted)return;const st="File preview is still waiting on disk I/O. Try the file again or refresh the directory.";ct.abort(new DOMException(st,"TimeoutError")),Y({kind:"error",message:st}),ln("stuck_timeout",{error:st})},X7(qe)?35e3:VJ);if(tn){const st=cn==="pcb-3d"?we.current:null;st?(Y(st),ln("eda_3d_client_cache_hit",{bytes:st.meta.size,view:st.view,mimeType:st.meta.mimeType})):mI(qe,cn,ct.signal,"view_file",dn).then(wt=>{pn=URL.createObjectURL(wt.blob);const Lt={kind:"eda",objectUrl:pn,view:wt.view,meta:{size:wt.size,mimeType:wt.mimeType,modified:wt.modified}};if(wt.view==="pcb-3d"){const Tn=we.current;Tn&&Tn.objectUrl!==pn&&URL.revokeObjectURL(Tn.objectUrl),we.current=Lt,ve(Lt),pn=null}Y(Lt),ln("eda_loaded",{bytes:wt.size,view:wt.view,mimeType:wt.mimeType})}).catch(wt=>{ct.signal.aborted||(Y({kind:"error",message:wt instanceof Error?wt.message:R("rightSidebar.edaLoadFailed")}),ln("error",{error:wt instanceof Error?wt.message:String(wt)}))})}else if(sr)s8(qe,ct.signal,"view_file",dn).then(st=>{pn=URL.createObjectURL(st.blob),Y({kind:"image",objectUrl:pn,meta:{size:st.size,mimeType:st.mimeType,modified:st.modified}}),ln("image_loaded",{bytes:st.size,mimeType:st.mimeType})}).catch(st=>{ct.signal.aborted||(Y({kind:"error",message:st instanceof Error?st.message:R("rightSidebar.imageLoadFailed")}),ln("error",{error:st instanceof Error?st.message:String(st)}))});else if(ps)xI(qe,ct.signal,"view_file",dn).then(st=>{pn=URL.createObjectURL(st.blob),Y({kind:"model3d",objectUrl:pn,ext:st.ext,meta:{size:st.size,mimeType:st.mimeType,modified:st.modified}}),ln("model3d_loaded",{bytes:st.size,ext:st.ext})}).catch(st=>{ct.signal.aborted||(Y({kind:"error",message:st instanceof Error?st.message:R("rightSidebar.model3dLoadFailed")}),ln("error",{error:st instanceof Error?st.message:String(st)}))});else if(Qr){const st=Z7(qe)??"",wt=iI(qe);Y(Lt=>Lt.kind==="video"&&Lt.url===wt?Lt:{kind:"video",url:wt,meta:{size:null,mimeType:st,modified:null}}),ln("video_ready",{mimeType:st})}else a5(qe,ct.signal,"view_file",dn).then(st=>{if(st.binary){Y({kind:"binary"});return}Y({kind:"text",content:st.content,meta:{size:st.size,truncated:st.truncated}}),ln("text_loaded",{bytes:st.size,truncated:!!st.truncated})}).catch(st=>{ct.signal.aborted||(Y({kind:"error",message:st instanceof Error?st.message:"Failed to read file"}),ln("error",{error:st instanceof Error?st.message:String(st)}))});return()=>{ct.abort(),ao(dn),window.clearTimeout(Qt),window.clearTimeout(Nt),pn&&URL.revokeObjectURL(pn),ln("cleanup")}},[e,C,$e,Ve,L,R,V]),b.useEffect(()=>{if(H.kind!=="model3d"||!e){ae(null);return}let qe=!1;const ct=e.lastIndexOf("/"),jt=ct>=0?e.slice(ct+1):e,dn=ct>=0?e.slice(0,ct):"",An=dn.lastIndexOf("/"),_n=An>=0?dn.slice(0,An):"",ln=jt.replace(/\.(stl|glb|gltf)$/i,""),pn=`${_n?`${_n}/`:""}features/${ln}.json`;return a5(pn).then(tn=>{if(!qe)try{const cn=JSON.parse(tn.content);ae(cn.version===1&&Array.isArray(cn.features)&&cn.features.length>0?cn.features:null)}catch{ae(null)}}).catch(()=>{qe||ae(null)}),()=>{qe=!0}},[H,e]),b.useEffect(()=>{if(H.kind!=="text"){Ce(null);return}const qe=C&&e&&!e.startsWith("/")?`${C}/${e}`:e,ct=r0(qe),jt=H.content,dn=mf(qe??"")&&de==="preview",An=U0(qe??"")&&be==="preview";if(!ct||dn||An||!sT(jt)){Ce(null);return}let _n=!1;const ln=pn=>{if(_n||!pn.registered(ct)){_n||Ce(null);return}try{Ce(oT(pn,jt,ct))}catch{Ce(null)}};return lt?ln(lt):(Ce(null),iT().then(pn=>{_n||(Ze(pn),ln(pn))}).catch(()=>{})),()=>{_n=!0}},[H,lt,e,C,de,be]),b.useLayoutEffect(()=>{if(!Oe||H.kind!=="text")return;const qe=`${Oe}:${de}:${be}`;if(_t.current===qe)return;const ct=V4(C,e);if(_t.current=qe,!ct)return;const jt=requestAnimationFrame(()=>{const dn=z.current;if(!dn)return;const An=de==="preview"?ct.markdownTop??ct.top:ct.top;dn.scrollTo({top:Math.max(0,An??0),left:Math.max(0,ct.left??0)}),Fe(de==="preview"?Math.max(0,An??0):0)});return()=>cancelAnimationFrame(jt)},[e,de,be,H.kind,Oe,C]),b.useEffect(()=>{Oe&&ob(C,e,{lineRange:T})},[e,T,Oe,C]),b.useEffect(()=>{if(P==null||H.kind!=="text")return;pe(null),L({start:P,end:P});const qe=P,ct=requestAnimationFrame(()=>{const jt=q.current.get(qe);jt&&jt.scrollIntoView({block:"center"}),F?.()});return()=>cancelAnimationFrame(ct)},[P,H,L,F]);const Ft=b.useCallback(qe=>{const ct=z.current;if(!ct)return!1;const jt=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(qe):qe.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),dn=ct.querySelector(`#${jt}`);return dn?(dn.scrollIntoView({block:"start"}),!0):!1},[]);b.useEffect(()=>{const qe=C&&e&&!e.startsWith("/")?`${C}/${e}`:e,ct=H.kind==="text"&&mf(qe??"")&&de==="preview";if(!Be||!ct)return;const jt=requestAnimationFrame(()=>{Ft(Be)&&We(null)});return()=>cancelAnimationFrame(jt)},[e,Ft,de,Be,H,C]),b.useLayoutEffect(()=>{const qe=z.current;if(!qe||!T){pe(null);return}if(te)return;const ct=H.kind==="image"||H.kind==="loading"&&H.mode==="image",jt=C&&e&&!e.startsWith("/")?`${C}/${e}`:e,dn=H.kind==="text"&&mf(jt??"")&&de==="preview",An=H.kind==="text"&&U0(jt??"")&&be==="preview";if(H.kind!=="text"||ct||dn||An){pe(null);return}const _n=()=>{const pn=q.current.get(T.end);if(!pn||!qe){pe(null);return}const tn=pn.offsetTop+pn.offsetHeight/2,cn=qe.scrollLeft+Math.max(8,qe.clientWidth-120);pe({top:tn,left:cn})};_n();const ln=new ResizeObserver(()=>_n());return ln.observe(qe),()=>ln.disconnect()},[T,te,H,de,be,e,C,He]);const Zn=H.kind==="text"&&!(U0(Dt??"")&&be==="preview")&&!Dt?.toLowerCase().endsWith(".csv")&&!Dt?.toLowerCase().endsWith(".kicad_pro")&&!Dt?.toLowerCase().endsWith(".kicad_prl"),Gt=b.useCallback(()=>{yt(!1),Mt(""),xr([]),or(0),$p()},[]),Cr=b.useCallback(()=>{Zn&&(yt(!0),requestAnimationFrame(()=>{Le.current?.focus(),Le.current?.select()}))},[Zn]),nr=b.useCallback(qe=>{or(ct=>on.length===0?0:(ct+qe+on.length)%on.length)},[on.length]);if(b.useEffect(()=>{const qe=ct=>{const jt=MJ(ct);if(jt==="open"&&Zn){ct.preventDefault(),Cr();return}At&&(jt==="close"?(ct.preventDefault(),Gt()):(jt==="next"||jt==="previous")&&(ct.preventDefault(),nr(jt==="previous"?-1:1)))};return document.addEventListener("keydown",qe),()=>document.removeEventListener("keydown",qe)},[Gt,At,nr,Cr,Zn]),b.useLayoutEffect(()=>{if($p(),!At||!Yt.trim()||!z.current){xr([]),or(0);return}const qe=jJ(z.current,Yt);return xr(qe),or(0),k4(qe,0),_4(qe[0]),$p},[At,Yt,He,de,H]),b.useEffect(()=>{At&&(k4(on,Cn),_4(on[Cn]))},[Cn,on,At]),b.useEffect(()=>$p,[]),!e)return o.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:R("rightSidebar.selectFilePrompt")});const an=C&&!e.startsWith("/")?`${C}/${e}`:e,Er=vm(an,C),yr=Ag(an,C),Jn=H.kind==="text"&&H.content?H.content.split(`
195
195
  `):[],wr=Math.max(2,String(Jn.length).length)+1,Se=H.kind==="text"||H.kind==="image"||H.kind==="model3d"||H.kind==="video"||H.kind==="eda"?H.meta:null,le=mf(an),It=an.toLowerCase().endsWith(".csv"),Me=an.toLowerCase().endsWith(".kicad_pro"),Ee=an.toLowerCase().endsWith(".kicad_prl"),Ge=H.kind==="text"&&le&&de==="preview",dt=U0(an),gt=H.kind==="text"&&dt&&be==="preview",Kt=H.kind==="image"||H.kind==="loading"&&H.mode==="image",nn=H.kind==="model3d"||H.kind==="loading"&&H.mode==="model3d",vt=H.kind==="video"||H.kind==="loading"&&H.mode==="video",un=H.kind==="eda"||H.kind==="loading"&&H.mode==="eda",Hn=wO(an,C,T),rr=(()=>{if(!T||H.kind!=="text"||Jn.length===0)return Hn;const qe=[];for(let dn=T.start;dn<=T.end;dn+=1)qe.push(`${dn} ${Jn[dn-1]??""}`);const ct=HT(an).replace(/^\./,""),jt="```";return`${Hn}
196
196
  ${jt}${ct}
197
197
  ${qe.join(`
198
198
  `)}
199
199
  ${jt}
200
- `})(),fn=`path:${an}`,Un=T?`path:${an}:${T.start}-${T.end}`:fn,hn=I===fn,Kn=I===Un,sn=j===fn,zn=j===Un,as=Kn||zn,Bt=T?T.start===T.end?`L${T.start}`:`L${T.start}-${T.end}`:null,rn=qe=>{const ct=z.current;if(!ct)return;const jt=ct.getBoundingClientRect(),dn=qe.currentTarget.getBoundingClientRect(),An=qe.clientX||dn.left+dn.width/2,ln=(qe.clientY||dn.top+dn.height/2)-jt.top+ct.scrollTop,pn=c?116:132,tn=ct.scrollLeft+Math.max(8,ct.clientWidth-pn),cn=Math.min(Math.max(8,An-jt.left+ct.scrollLeft+10),tn);pe({top:ln,left:cn})},bt=(qe,ct)=>{G2()||(rn(qe),L(jt=>{const dn=Y4(jt,ct,ct);return dn||pe(null),dn}))},Tt=(qe,ct,jt)=>{rn(qe),L(dn=>{const An=Y4(dn,ct,jt);return An||pe(null),An})},at=(qe,ct,jt,dn)=>{dn==="end"&&rn(qe),L({start:ct,end:jt})},$t=qe=>{const{scrollTop:ct,scrollLeft:jt}=qe.currentTarget;Fe(ct),ob(C,e,{top:ct,left:jt,markdownTop:ct})},Rt=qe=>{if(qe.directory){a?.(qe.path);return}if(qe.path===an){qe.fragment&&Ft(qe.fragment);return}ze(ct=>[...ct,an]),W.current=qe.path,We(qe.fragment),L(null),$(qe.path)},vn=()=>{const qe=Te[Te.length-1];qe&&(ze(ct=>ct.slice(0,-1)),W.current=qe,We(null),L(null),$(qe))},Ot=qe=>{const{scrollTop:ct,scrollLeft:jt}=qe.currentTarget;ob(C,e,{top:ct,left:jt})},Jt=()=>{T&&n(rr,Un)},ar=async()=>{if(!(!an||Qe.status==="pending")&&!(H.kind==="loading"||H.kind==="error")){pt({status:"pending"});try{await ty(an),pt({status:"idle"})}catch(qe){pt({status:"error",message:qe instanceof Error?qe.message:R("rightSidebar.downloadFailed")})}}};return o.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[ot.popoverNode,o.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${c&&(Ge||gt)?"py-1.5":"py-2"}`,children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[c&&i&&o.jsx("button",{type:"button",onClick:i,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":R("rightSidebar.backToFileList"),title:R("rightSidebar.backToFileList"),children:o.jsx(oy,{size:16})}),Te.length>0&&o.jsxs("button",{type:"button",onClick:vn,className:"inline-flex h-9 shrink-0 items-center gap-1 rounded-full bg-primary/10 px-2.5 text-primary transition hover:bg-primary/15 active:scale-95","aria-label":R("rightSidebar.backToPreviousPreview"),title:R("rightSidebar.backToPreviousPreview"),children:[o.jsx(l0,{size:15}),o.jsx("span",{className:"text-[11px] font-medium",children:R("rightSidebar.backToPreviousPreview")})]}),o.jsxs("div",{className:"min-w-0",title:an,children:[o.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Er.name}),Er.dir&&o.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Er.dir})]})]}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Zn&&o.jsx("button",{type:"button",onClick:At?Gt:Cr,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${At?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":R("rightSidebar.findInFile"),title:`${R("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:o.jsx(Jl,{size:14})}),le&&H.kind==="text"&&o.jsx("button",{type:"button",onClick:()=>{u&&g?.(),ke(qe=>{const ct=qe==="preview"?"source":"preview";return $n(LT,ct),ct}),L(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${c?"w-9 px-0":"px-3"}`,"aria-label":R(de==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:R(de==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:c?de==="preview"?o.jsx(Eb,{size:14}):o.jsx(Lb,{size:14}):R(de==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),dt&&H.kind==="text"&&o.jsx("button",{type:"button",onClick:()=>{oe(qe=>{const ct=qe==="preview"?"source":"preview";return uJ(C,e,ct),ct}),L(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${c?"w-9 px-0":"px-3"}`,"aria-label":R(be==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:R(be==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:c?be==="preview"?o.jsx(Eb,{size:14}):o.jsx(Lb,{size:14}):R(be==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),gt&&o.jsx("button",{type:"button",onClick:()=>{he.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":R(J?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:R(J?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:o.jsx(ay,{size:15})}),!c&&o.jsx("button",{type:"button",onClick:()=>t(an,fn),...ot(yr,fn),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${hn||sn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:R("rightSidebar.insertReference",{reference:yr}),children:R(sn?"rightSidebar.copied":hn?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),o.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(yr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:R("rightSidebar.copyReference",{reference:yr}),"aria-label":R("rightSidebar.copyFileRef"),children:o.jsx(iy,{size:13})}),o.jsx("button",{type:"button",onClick:()=>{ar()},disabled:Qe.status==="pending"||H.kind==="loading"||H.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:Qe.status==="error"?Qe.message??R("rightSidebar.downloadFailed"):R("rightSidebar.downloadFile"),"aria-label":R("rightSidebar.downloadFile"),children:Qe.status==="pending"?o.jsx(Fn,{size:13,className:"animate-spin"}):o.jsx(c0,{size:14})})]})]}),At&&Zn&&o.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-1.5","data-file-preview-search":!0,children:[o.jsxs("div",{className:"flex min-w-0 flex-1 items-center rounded-lg bg-surface-2 px-2 focus-within:bg-surface-elevated",children:[o.jsx(Jl,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),o.jsx("input",{ref:Le,type:"search",value:Yt,onChange:qe=>Mt(qe.target.value),onKeyDown:qe=>{qe.key==="Enter"&&(qe.preventDefault(),nr(qe.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:R("rightSidebar.findInFilePlaceholder"),"aria-label":R("rightSidebar.findInFile")}),o.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:on.length>0?`${Cn+1}/${on.length}`:"0/0"})]}),o.jsx("button",{type:"button",onClick:()=>nr(-1),disabled:on.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":R("rightSidebar.previousSearchMatch"),title:`${R("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:o.jsx(xg,{size:13})}),o.jsx("button",{type:"button",onClick:()=>nr(1),disabled:on.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":R("rightSidebar.nextSearchMatch"),title:`${R("rightSidebar.nextSearchMatch")} (Enter)`,children:o.jsx(p8,{size:13})}),o.jsx("button",{type:"button",onClick:Gt,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":R("rightSidebar.closeFileSearch"),title:`${R("rightSidebar.closeFileSearch")} (Esc)`,children:o.jsx(ts,{size:13})})]}),Se&&!(c&&(Ge||gt))&&o.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[Se.size!==null&&o.jsx("span",{children:R("rightSidebar.byteCount",{count:Se.size.toLocaleString()})}),"truncated"in Se&&Se.truncated&&o.jsx("span",{className:"text-[color:var(--warning)]",children:R("rightSidebar.previewTruncated")}),"mimeType"in Se&&o.jsx("span",{children:Se.mimeType}),"dimensions"in H&&H.dimensions&&o.jsxs("span",{children:[H.dimensions.width," × ",H.dimensions.height]})]}),!(c&&(Ge||gt))&&!nn&&H.kind!=="binary"&&o.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:o.jsx("span",{className:"truncate",children:un?R("rightSidebar.edaPickHint"):It?R("rightSidebar.csvTablePreview"):Me||Ee?R("rightSidebar.kicadProjectPickHint"):vt?R("rightSidebar.videoPreviewHint"):Kt?R("rightSidebar.imagePreviewHint"):Ge?T?R("rightSidebar.selectedLineHint",{lineLabel:Bt??""}):R("rightSidebar.markdownPreviewHint"):gt?R("rightSidebar.htmlPreviewHint"):T?R("rightSidebar.selectedLineHint",{lineLabel:Bt??""}):R("rightSidebar.multiLineHint")})})]}),H.kind==="loading"?o.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:H.mode==="eda"?R("rightSidebar.edaLoading"):H.mode==="image"?R("rightSidebar.loadingImage"):H.mode==="model3d"?R("rightSidebar.model3dLoading"):H.mode==="video"?R("rightSidebar.loadingVideo"):"Loading file…"}):H.kind==="error"?o.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:o.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:H.message})}):H.kind==="binary"?o.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:o.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:R("rightSidebar.binaryPreviewHint")})}):H.kind==="image"?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:H.meta.mimeType==="image/svg+xml"?o.jsx(CT,{blobUrl:H.objectUrl,filePath:an,viewLabel:"SVG 文件",onInsertAnnotation:r}):o.jsx(yC,{src:H.objectUrl,alt:Er.name,vector:!1,onLoad:qe=>{const ct=qe.currentTarget;Y(jt=>jt.kind==="image"?{...jt,dimensions:{width:ct.naturalWidth,height:ct.naturalHeight}}:jt)},onError:()=>Y({kind:"error",message:R("rightSidebar.imageLoadFailed")})})}):H.kind==="video"?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:o.jsx(mJ,{url:H.url,onLoadError:()=>Y({kind:"error",message:R("rightSidebar.videoLoadFailed")})})}):H.kind==="eda"?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:o.jsx(SJ,{blobUrl:H.objectUrl,filePath:an,view:H.view,board:an.toLowerCase().endsWith(".kicad_pcb"),onViewChange:fe,onInsertAnnotation:r,onRefresh:kn,interactive3d:X?o.jsx(b.Suspense,{fallback:o.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:R("rightSidebar.model3dLoading")}),children:o.jsx(D4,{blobUrl:X.objectUrl,ext:".glb",fileName:Er.name,filePath:an,features:null,onInsertFeature:r,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:qe=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(qe)?qe:"PCB板体/铜箔/丝印",active:H.view==="pcb-3d"})}):void 0})}):H.kind==="model3d"?o.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:o.jsx(b.Suspense,{fallback:o.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:R("rightSidebar.model3dLoading")}),children:o.jsx(D4,{blobUrl:H.objectUrl,ext:H.ext,fileName:Er.name,filePath:an,features:ie,onInsertFeature:r,onRefresh:kn})})}):H.kind==="text"&&It?o.jsx(CJ,{content:H.content,filePath:an,onInsertAnnotation:r},an):H.kind==="text"&&(Me||Ee)?o.jsx(LJ,{content:H.content,filePath:an,localState:Ee,onInsertAnnotation:r},an):Ge?o.jsxs("div",{ref:z,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:$t,style:{touchAction:"pan-x pan-y"},children:[o.jsx(zee,{content:H.content,filePath:an,rootPath:C,lineRange:T,onLineRangeClick:Tt,onLineRangeDrag:at,scrollTop:ge,outlineOpen:u,outlineCloseSignal:f,onOutlineOpen:p,onOutlineClose:g,lightboxOpen:y,lightboxCloseSignal:v,onLightboxOpen:S,onLightboxClose:A,onLocalLinkOpen:Rt}),T&&te&&o.jsxs("button",{type:"button",onClick:Jt,...ot(rr,Un),style:{top:te.top,left:te.left,transform:"translateY(-50%)"},className:K4(c,as),title:`Insert markdown reference: ${Hn}`,children:[o.jsx(El,{size:c?13:11}),zn?R("rightSidebar.copied"):Kn?R("rightSidebar.inserted"):R("rightSidebar.insertLineRef",{lineLabel:Bt??""})]})]}):gt?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:o.jsx(EJ,{ref:he,src:uI(an),title:`${Er.name} preview`,exitFullscreenLabel:R("rightSidebar.htmlFullscreenExit"),onFullscreenChange:Xe},`${an}:${$e}:${Ve}`)}):H.kind==="text"?o.jsxs("div",{ref:z,onScroll:Ot,className:`${cv} termdock-native-select termdock-code relative min-h-0 flex-1 overflow-auto rounded-none bg-surface p-2 font-mono text-[11px] leading-relaxed text-foreground`,children:[Jn.length>0?o.jsx("div",{className:"min-w-full",children:Jn.map((qe,ct)=>{const jt=ct+1,dn=!!(T&&jt>=T.start&&jt<=T.end),An=He&&He.length===Jn.length?He[ct]:null;return o.jsxs("div",{ref:_n=>{_n?q.current.set(jt,_n):q.current.delete(jt)},role:"button","data-file-preview-line":jt,tabIndex:0,onClick:_n=>bt(_n,jt),onKeyDown:_n=>{_n.key!=="Enter"&&_n.key!==" "||(_n.preventDefault(),bt(_n,jt))},style:{gridTemplateColumns:`${wr}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${dn?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${yr}:${jt}`,children:[o.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${dn?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:jt}),o.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:An??(qe||" ")})]},ct)})}):"Empty file.",T&&te&&o.jsxs("button",{type:"button",onClick:Jt,...ot(rr,Un),style:{top:te.top,left:te.left,transform:"translateY(-50%)"},className:K4(c,as),title:`Insert code reference: ${Hn}`,children:[o.jsx(El,{size:c?13:11}),zn?R("rightSidebar.copied"):Kn?R("rightSidebar.inserted"):R("rightSidebar.insertLineRef",{lineLabel:Bt??""})]})]}):null]})}function r7({isOpen:e,drawerWidthPx:t,onClose:n,onOpen:r,push:s,pinned:i=!1,onTogglePinned:a,rightSidebarFilePreviewOpen:c=!1,rightSidebarFilePreviewCloseSignal:u,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:p,rightSidebarRepoPickerOpen:g=!1,rightSidebarRepoPickerCloseSignal:y,onOpenRightSidebarRepoPicker:v,onCloseRightSidebarRepoPicker:S,markdownOutlineOpen:A=!1,markdownOutlineCloseSignal:T,onOpenMarkdownOutline:L,onCloseMarkdownOutline:I,markdownImageLightboxOpen:j=!1,markdownImageLightboxCloseSignal:P,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:R}){const{t:C,locale:$}=Yn(),[H,Y]=b.useState(""),[V,fe]=b.useState(null),X=ft(_=>_.rightSearchOpen),ve=ft(_=>_.setRightSearchOpen),we=ft(_=>_.rightSidebarLayoutPreference),ie=ft(_=>_.setRightSidebarLayoutPreference),[ae,q]=b.useState(()=>nee()),z=b.useDeferredValue(H),[te,pe]=b.useState(null),[de,ke]=b.useState([]),[be,oe]=b.useState([]),[he,J]=b.useState(null),[Xe,lt]=b.useState(null),[Ze,ge]=b.useState(null),[Fe,Te]=b.useState(null),[ze,Be]=b.useState(()=>Or(E4,If)??!1),[We,W]=b.useState(()=>Or(I4,If)??!1),[xe,He]=b.useState(()=>Or(R4,If)??!1),[Ce,Qe]=b.useState(()=>Or(Jx,XJ)??""),[pt,At]=b.useState(0),[yt,Yt]=b.useState(!1),[Mt,on]=b.useState(!1),xr=b.useRef(null),Cn=b.useRef(null),[or,Le]=b.useState(!1),[ot,Oe]=b.useState(null),[Dt,$e]=b.useState(null),[Ut,_t]=b.useState(()=>B4(Xx)),[Ve,Ur]=b.useState(()=>B4(L4)),[kn,Ft]=b.useState(()=>KJ()),[Zn,Gt]=b.useState(()=>ZJ()),[Cr,nr]=b.useState(()=>eee()),an="words",[Er,yr]=b.useState(0),[Jn,wr]=b.useState([]),[Se,le]=b.useState([]),[It,Me]=b.useState(!1),[Ee,Ge]=b.useState(null),[dt,gt]=b.useState([]),[Kt,nn]=b.useState(!1),[vt,un]=b.useState([]),[Hn,rr]=b.useState([]),[fn,Un]=b.useState(!1),[hn,Kn]=b.useState(null),[sn,zn]=b.useState([]),[as,Bt]=b.useState({}),[rn,bt]=b.useState(!1),[Tt,at]=b.useState(null),[$t,Rt]=b.useState(null),[vn,Ot]=b.useState(null),[Jt,ar]=b.useState(null),[qe,ct]=b.useState(!1),[jt,dn]=b.useState(""),An=b.useDeferredValue(jt),[_n,ln]=b.useState([]),[pn,tn]=b.useState(!1),[cn,sr]=b.useState(!1),[ps,Qr]=b.useState(null),[se,_e]=b.useState(!1),je=b.useRef(null),tt=b.useRef(0),Qt=b.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[Nt,st]=b.useState(null),[wt,Lt]=b.useState(()=>Or(Zx,If)??!1),[Tn,mn]=b.useState(!1),[lr,zr]=b.useState([]),[jn,mr]=b.useState({}),[dr,en]=b.useState({}),[Vt,ir]=b.useState(!0),[Xn,Gr]=b.useState(()=>new Set),[gn,fr]=b.useState(null),[Ln,ns]=b.useState(null),[kr,ls]=b.useState(!1),[ms,ui]=b.useState(0),[,di]=b.useState(0),[ws,ja]=b.useState(!1),[fi,ia]=b.useState(!1),[hi,Es]=b.useState(()=>ft.getState().rightTab==="diff"),[cr,pi]=b.useState(null),[ho,rs]=b.useState(null),[er,Mr]=b.useState(null),[Is,Dr]=b.useState(null),[Cs,To]=b.useState(null),[Wr,oa]=b.useState(()=>Date.now()),[Co,zi]=b.useState(!1),[Js,Fs]=b.useState(!1),[aa,la]=b.useState(""),[Os,ca]=b.useState(""),[Gi,ki]=b.useState(""),[_i,gs]=b.useState(""),[mi,ei]=b.useState(null),[ko,Wi]=b.useState(!1),[ua,Pa]=b.useState(!1),[fl,Qs]=b.useState(!1),[gi,Li]=b.useState({key:null,nonce:0}),Ei=b.useRef(null),po=b.useRef(null),me=qO(t,i,we),ut=WJ(me,i,Cr),[xt,nt]=b.useState(()=>uee(t)),Ct=ft(_=>_.rightTab),On=ft(_=>_.setRightTab),Ae=ft(_=>_.rootPath),hr=ft(_=>_.explorerRoot),Ss=ft(_=>_.pinnedExplorerRootsCache),qn=ft(_=>_.setExplorerRoot),cs=ft(_=>_.resetExplorerToProject),Vr=ft(_=>_.pinExplorerRoot),Gs=ft(_=>_.unpinExplorerRoot),qr=ft(_=>_.selectedFilePath),Rr=ft(_=>_.selectFile),Ws=ft(_=>_.showHiddenFiles),tc=ft(_=>_.toggleShowHiddenFiles),Nn=ft(_=>_.changedFiles),Kr=ft(_=>_.setChangedFiles),Ho=ft(_=>_.invalidateDirectoryCache),_o=ft(_=>_.setDirectorySortMode),$s=ft(_=>_.applyFileWatchEvents),xi=ft(_=>_.bumpFileWatchEpoch),B=ft(_=>_.gitBundleLoading),K=ft(_=>_.gitBundleSlow),ee=ft(_=>_.gitBundleError),ce=ft(_=>_.gitBundleLastLoadedAt),Je=ft(_=>_.setGitBundleLoading),Ke=ft(_=>_.setGitBundleSlow),ht=ft(_=>_.setGitBundleError),Ht=ft(_=>_.markGitBundleLoaded),et=hr??Ae,Zt=ft(_=>et?_.fileSortModes[et]??"name":"name"),_r=ft(_=>!!(et&&_.directoryCache.has(et))),jr=b.useRef(null),Lr=b.useRef(0),Ir=b.useRef(null),xs=b.useRef(null),Gn=b.useRef(0),Wn=b.useRef(new Map),Pr=b.useRef(new Map),ur=b.useRef(new Set),da=b.useRef(new Set),us=b.useRef(0),ti=b.useRef(null),Br=b.useRef(0),Ii=b.useRef(null),Vi=b.useRef(0),ni=b.useRef(null),fa=b.useRef(new Set),ou=b.useRef(null),Il=b.useRef(null),Ec=b.useRef(null),Ic=b.useRef(null);b.useEffect(()=>{if(Cs===null)return;const _=Math.max(0,Date.now()-Cs),O=_<6e4?1e3:_<36e5?6e4:_<864e5?36e5:864e5,Z=Math.max(50,O-_%O),De=window.setTimeout(()=>oa(Date.now()),Z);return()=>window.clearTimeout(De)},[Wr,Cs]);const Rc=b.useRef(null),Ba=b.useRef(null),nc=b.useRef(null),Lo=b.useRef(null),vr=b.useCallback(_=>ft.getState().rootPath===_,[]);b.useEffect(()=>{if(!e||typeof window>"u")return;const _=O=>{const Z=fte(O.target);Z&&Vp("global_change_row_event",{...hte(O),selectionPath:Z.dataset.diffSelectionPath,filePath:Z.dataset.diffFilePath,absolutePath:Z.dataset.diffAbsolutePath,repoRoot:Z.dataset.diffRepoRoot,status:Z.dataset.diffStatus,selectedFilePath:ft.getState().selectedFilePath,rightTab:ft.getState().rightTab,activeGitRepoRoot:he,changedFiles:ft.getState().changedFiles.size})};return window.addEventListener("pointerdown",_,{capture:!0}),window.addEventListener("click",_,{capture:!0}),()=>{window.removeEventListener("pointerdown",_,{capture:!0}),window.removeEventListener("click",_,{capture:!0})}},[he,e]);const Fa=b.useCallback(async(_=Ae??void 0)=>{if(!_)return null;if(ur.current.has(_)||da.current.has(_))return oi("untracked_skip_cached",{cwd:_,rootPath:Ae,completed:ur.current.has(_),running:da.current.has(_)}),null;const O=Ae,Z=Gn.current+1;Gn.current=Z,Wn.current.set(_,Z);const De=`right-sidebar-git-untracked:${_}`,Ie=new AbortController;Pr.current.set(_,Ie),da.current.add(_),oi("untracked_start",{requestId:Z,cwd:_,rootPath:Ae});try{let Ye=await d5(_,Ie.signal,De),mt=0;for(;Ye.status==="running"&&mt<120;){if(Wn.current.get(_)!==Z||Ie.signal.aborted)return oi("untracked_stale_result",{requestId:Z,activeRequestId:Wn.current.get(_),cwd:_,status:Ye.status}),null;if(!vr(O))return oi("untracked_root_changed",{requestId:Z,cwd:_,expectedRootPath:O,currentRootPath:ft.getState().rootPath}),null;await new Promise(Et=>window.setTimeout(Et,mt<10?1e3:3e3)),mt+=1,Ye=await d5(_,Ie.signal,De)}if(Wn.current.get(_)!==Z||!vr(O))return oi("untracked_stale_result",{requestId:Z,activeRequestId:Wn.current.get(_),cwd:_,expectedRootPath:O,currentRootPath:ft.getState().rootPath,files:Ye.files.length,status:Ye.status}),null;if(Ye.status==="done")return Kr(hC(ft.getState().changedFiles,Ye.files)),Ye.files.length>0&&ke(Et=>{const Ps=new Map(Et.map(bs=>[bs.root,bs])).get(_);if(!Ps)return Et;const fs=Kee(Ps.files,Ye.files),Sn=Et.map(bs=>bs.root===_?{...bs,files:fs,context:bs.context?{...bs.context,changedFiles:fs.map(Bl=>({path:Bl.path,absolutePath:Bl.absolutePath,status:Bl.status})),truncated:!1}:bs.context,untrackedDeferred:!1}:bs);oe(pC(Sn,Ae));const Vn=Sn.find(bs=>bs.root===Ae);return Vn?.context&&pe(bs=>bs?.root===Vn.root?{...bs,...Vn.context}:bs),Sn}),ur.current.add(_),oi("untracked_apply",{requestId:Z,cwd:_,files:Ye.files.length}),Ye;const St=Ye.error||(Ye.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return ur.current.add(_),oi("untracked_error",{requestId:Z,cwd:_,message:St,code:Ye.code,status:Ye.status}),null}catch(Ye){if(Wn.current.get(_)!==Z||!vr(O)||pc(Ye))return oi("untracked_aborted",{requestId:Z,activeRequestId:Wn.current.get(_),cwd:_,expectedRootPath:O,currentRootPath:ft.getState().rootPath,message:Ye instanceof Error?Ye.message:String(Ye)}),null;const mt=Ye instanceof Error?Ye.message:"Failed to scan untracked files";return ur.current.add(_),oi("untracked_error",{requestId:Z,cwd:_,message:mt}),null}finally{Pr.current.get(_)===Ie&&Pr.current.delete(_),Wn.current.get(_)===Z&&Wn.current.delete(_),da.current.delete(_)}},[te,vr,Ae,Kr]),qi=b.useMemo(()=>{const _=new Set(be.map(Z=>Z.root)),O=dt.filter(Z=>_.has(Z));return O.length>0?O:he?[he]:[]},[he,dt,be]),Nc=qi.length===0,Oa=b.useMemo(()=>qi.map(_=>de.find(O=>O.root===_)).filter(_=>!!_),[qi,de]),ha=b.useMemo(()=>be.map(_=>({root:_.root,label:_.label,branch:_.branch??null})),[be]),Vs=b.useCallback(async()=>{if(!Ae){wr([]),le([]);return}const _=Ae,O=Br.current+1;Br.current=O,Ii.current?.abort();const Z=new AbortController;Ii.current=Z,Me(Jn.length===0),Ge(null);try{const De=qi.length>0?await Promise.all(qi.map(Ie=>c5({workspaceRoot:Ae,repoRoot:Ie},Z.signal))).then(Ie=>({records:Ie.flatMap(Ye=>Ye.records),walkthroughs:Ie.flatMap(Ye=>Ye.walkthroughs??[])})):await c5({workspaceRoot:Ae},Z.signal);if(Br.current!==O||!vr(_))return;wr(De.records),le(De.walkthroughs??[])}catch(De){if(Br.current!==O||!vr(_)||pc(De))return;Ge(De instanceof Error?De.message:"Failed to load change audit explanations")}finally{Ii.current===Z&&(Ii.current=null),Br.current===O&&vr(_)&&Me(!1)}},[Jn.length,qi,vr,Ae]),Uo=b.useCallback(async(_,O,Z)=>{if(!_&&!Ae){un([]),rr([]);return}const De=Ae,Ie=Vi.current+1;Vi.current=Ie,ni.current?.abort();const Ye=new AbortController;ni.current=Ye;try{const mt=_?[_]:Array.from(new Set([Ae,...de.map(Et=>Et.root)].filter(Et=>!!Et))),St=await Promise.all(mt.map(Et=>_I({repoRoot:Et,baseRef:O,branchName:Z},Ye.signal))).then(Et=>{const gr=new Map,Ps=new Map;for(const fs of Et){for(const Sn of fs.records)gr.set(Sn.id,Sn);for(const Sn of fs.walkthroughs??[])Ps.set(Sn.id,Sn)}return{records:Array.from(gr.values()),walkthroughs:Array.from(Ps.values())}});if(Vi.current!==Ie||!vr(De))return;un(St.records),rr(St.walkthroughs??[])}catch(mt){if(Vi.current!==Ie||!vr(De)||pc(mt))return;console.warn("[RightSidebar] Failed to load branch explanations",mt)}finally{ni.current===Ye&&(ni.current=null)}},[de,vr,Ae]),pa=b.useCallback((_,O={})=>{if(!vr(Ae)){oi("apply_skipped_root_changed",{expectedRootPath:Ae,currentRootPath:ft.getState().rootPath,bundleRoot:_.context?.root,files:_.files.length});return}oi(_.files.length===0?"empty_bundle":"apply",{rootPath:Ae,available:_.available,files:_.files.length,repositories:_.repositories?.map(Sn=>({root:Sn.root,relativeRoot:Sn.relativeRoot,files:Sn.files.length,available:Sn.available,error:Sn.error})),repoFilters:_.repoFilters?.map(Sn=>({root:Sn.root,label:Sn.label,count:Sn.count})),cached:_.cached,stale:_.stale,cacheAgeMs:_.cacheAgeMs,untrackedDeferred:_.untrackedDeferred,error:_.error});let Z=OT(_),De=_.repoFilters??[],Ie=_.files;const Ye=ft.getState().changedFiles;if(!!(O.cacheOnly&&!_.cached&&_.files.length===0&&Z.length===0)&&(Ye.size>0||de.length>0||te)){oi("cache_only_apply_skipped_empty_backend_cache",{rootPath:Ae,currentFiles:Ye.size,currentRepositories:de.length});return}const St=X4(Ye.values(),Ae),Et=X4(_.files,Ae),gr=Z.some(Sn=>Sn.root!==Ae);if(!!(O.background&&Ye.size>0&&(_.files.length===0&&!_.error||St>0&&Et===0&&!gr))){oi("background_apply_skipped_degraded_bundle",{rootPath:Ae,currentFiles:Ye.size,nextFiles:_.files.length,currentNestedCount:St,nextNestedCount:Et,nextRepositories:Z.map(Sn=>({root:Sn.root,relativeRoot:Sn.relativeRoot,files:Sn.files.length})),cached:_.cached,stale:_.stale,error:_.error});return}if(O.replaceRepoRoot){const Sn=Zee(Ye.values(),de,_,O.replaceRepoRoot,Ae);Ie=Sn.files,Z=Sn.repositories,De=Sn.repoFilters}if(Kr(fC(Ie)),ke(Z),oe(De),O.syncActiveRepo!==!1){const Sn=O.activeRepoRoot!==void 0?O.activeRepoRoot:he??P4(Ae),Vn=see({..._,repositories:Z,repoFilters:De},Sn);J(Vn),tb(Ae,Vn)}typeof _.cacheUpdatedAt=="number"&&To(_.cacheUpdatedAt),pe(Sn=>{if(O.replaceRepoRoot&&O.replaceRepoRoot!==Ae)return Sn;if(!_.context)return null;const Vn=Sn?.root??Ae;return!Sn?.available||Vn!==(_.context.root??Ae)?_.context:{...Sn,..._.context}}),O.reloadDiff&&yr(Sn=>Sn+1);const fs=ft.getState().selectedFilePath;if(fs&&!fs.startsWith("/")&&!Ie.some(Sn=>Sn.path===fs||Sn.absolutePath===fs)&&Rr(null),_t(Sn=>{const Vn=new Set(Ie.map(Bl=>Oo(Bl,Ae)).filter(Boolean)),bs=new Set;for(const Bl of Sn)Vn.has(Bl)&&bs.add(Bl);return nb(Xx,bs),bs}),O.loadDeferred!==!1){const Sn=Z.filter(Vn=>Vn.untrackedDeferred&&Vn.root).map(Vn=>Vn.root);for(const Vn of Sn)Fa(Vn)}O.loadAudit!==!1&&Vs()},[he,vr,Vs,Fa,Ae,Rr,Kr]);b.useEffect(()=>{ou.current=null,Il.current=Ae;const _=[],O=[],De=P4(Ae);Lr.current+=1,us.current+=1,Gn.current+=1,Ir.current?.abort(),ao(Pd(xs.current?.cwd??Ae??void 0)),xs.current=null,Ir.current=null,ti.current?.abort(),ao("right-sidebar-git-details"),ti.current=null;for(const Et of Pr.current.values())Et.abort();for(const Et of Pr.current.keys())ao(`right-sidebar-git-untracked:${Et}`);Pr.current.clear(),Wn.current.clear(),Br.current+=1,Ii.current?.abort(),Ii.current=null,Vi.current+=1,ni.current?.abort(),ni.current=null,tt.current+=1,je.current?.abort(),ao("right-sidebar-recent-commits"),je.current=null,wr([]),le([]),Me(!1),Ge(null),gt([]),nn(!1),un([]),rr([]),Un(!1),Kn(null),bt(!1),at(null),Rt(null),Ot(null),ar(null),ct(!1),dn(""),ln([]),tn(!1),sr(!1),Qr(null),_e(!1),st(null),fr(null),ns(null),Lt(!1),$n(Zx,!1),mn(!1);const Ie=Ae?F4()[Ae]:null,Ye=Ie?.previewEntries??[],mt=Ie?.selectedPreviewKey??null,St=mt?Ye.find(Et=>Et.key===mt)??null:null;zr(Ie?.selectedRepoRoots??[]),mr(Ie?.repoTargetBranches??{}),en(Ie?.repoBaseBranches??{}),zn(Ye),Bt(Ie?.previewScrollTops??{}),St&&Ie?.previewDetailOpen&&(St.diff.hunks?.length??0)>0&&(Kn(St.diff),fr(St.key),ns(Ie.selectedPreviewFileKey??(St.diff.hunks?.[0]?`${St.diff.hunks[0].filePath}\0${St.diff.hunks[0].hunkHeader}\0${St.diff.hunks[0].hunkIndex}`:null)),Un(!0)),ir(Ie?.includeUncommitted??!0),ou.current=Ae,Fs(!1),J(De??null),ur.current.clear(),da.current.clear(),pi(null),rs(null),Mr(null),Dr(null),To(null),ke(_),oe(O),pe(null),Ic.current=null},[Ae]);const qs=b.useCallback(async(_=Ae??void 0,O={})=>{if(!_)return null;const Z=Ae,De=O.includeNested??!0,Ie=O.refresh??O.reloadDiff??!1,Ye=O.cacheOnly??!1,mt=O.background??!1;Ie&&ur.current.clear();const St=xs.current;if(St&&St.cwd===_&&St.includeNested===De&&St.refresh===Ie&&St.cacheOnly===Ye)return oi("reuse_pending",{cwd:_,includeNested:De,refresh:Ie,cacheOnly:Ye}),St.promise;const Et=Lr.current+1;Lr.current=Et,Ir.current?.abort();const gr=Pd(_);ao(gr);const Ps=new AbortController;Ir.current=Ps;let fs=null;mt||(Je(!0),Ke(!1)),ht(null),oi("start",{requestId:Et,cwd:_,rootPath:Ae,requestSlotId:gr,includeNested:De,refresh:Ie,cacheOnly:Ye,background:mt,existingChanges:Nn.size,lastLoadedAt:ce}),!mt&&typeof window<"u"&&(fs=window.setTimeout(()=>{Lr.current===Et&&Ke(!0)},QJ));const Sn=(async()=>{const Vn=await ap(_,Ps.signal,{includeNested:De,refresh:Ie,cacheOnly:Ye,action:Ie?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:gr,requestTimeoutMs:Ie?null:void 0});return ete(Vn)?(oi("cancelled_result_ignored",{requestId:Et,activeRequestId:Lr.current,cwd:_,error:Vn.error??Vn.context?.error}),null):Lr.current!==Et||!vr(Z)?(oi("stale_result",{requestId:Et,activeRequestId:Lr.current,cwd:_,expectedRootPath:Z,currentRootPath:ft.getState().rootPath,files:Vn.files.length,repositories:Vn.repositories?.length??0}),null):(pa(Vn,{reloadDiff:O.reloadDiff,syncActiveRepo:De,background:mt,cacheOnly:Ye,replaceRepoRoot:O.replaceRepoRoot}),Vn)})();xs.current={cwd:_,includeNested:De,refresh:Ie,cacheOnly:Ye,promise:Sn};try{const Vn=await Sn;return Lr.current===Et&&Vn&&vr(Z)?Ht({cached:Vn.cached,stale:Vn.stale,cacheAgeMs:Vn.cacheAgeMs,nestedDeferred:!De||Vn.nestedDeferred,untrackedDeferred:Vn.untrackedDeferred}):Lr.current===Et&&vr(Z)&&(Je(!1),Ke(!1)),Vn}catch(Vn){return Lr.current!==Et||!vr(Z)||pc(Vn)?(oi("aborted",{requestId:Et,activeRequestId:Lr.current,cwd:_,expectedRootPath:Z,currentRootPath:ft.getState().rootPath,message:Vn instanceof Error?Vn.message:String(Vn)}),null):(oi("error",{requestId:Et,cwd:_,includeNested:De,refresh:Ie,background:mt,message:Vn instanceof Error?Vn.message:String(Vn)}),mt||(pe(null),ht(Vn instanceof Error?Vn.message:"Failed to load Git changes")),null)}finally{fs!==null&&window.clearTimeout(fs),Ir.current===Ps&&(Ir.current=null),xs.current?.promise===Sn&&(xs.current=null),!mt&&Lr.current===Et&&vr(Z)&&(Je(!1),Ke(!1))}},[pa,Nn.size,ce,vr,Ht,Ae,ht,Je,Ke]),hl=b.useCallback(async()=>{if(!Ae)return;await qs(he??Ae,{reloadDiff:!0,includeNested:!he,refresh:!0,replaceRepoRoot:he??void 0})},[he,qs,Ae]),Rl=b.useCallback(async(_=Ae??void 0)=>{if(!_)return null;const O=Ae,Z=us.current+1;us.current=Z,ti.current?.abort(),ao("right-sidebar-git-details");const De=new AbortController;ti.current=De,Fs(!0);try{const Ie=await l5(_,De.signal,"load_git_details","right-sidebar-git-details");return us.current!==Z||!vr(O)?null:(ke(Ye=>Ye.map(mt=>mt.root===Ie.root?{...mt,available:Ie.available,context:Ie,error:Ie.error}:mt)),pe(Ye=>Ye?.root&&Ie.root&&Ye.root!==Ie.root?Ye:!Ye?.available||!Ie.available?Ie:{...Ye,...Ie}),Ie)}catch(Ie){return pc(Ie)||!vr(O)||us.current===Z&&Dr(Ie instanceof Error?Ie.message:"Failed to load Git details"),null}finally{ti.current===De&&(ti.current=null),us.current===Z&&vr(O)&&Fs(!1)}},[vr,Ae]);b.useEffect(()=>{if(!e){Lr.current+=1,us.current+=1,Gn.current+=1,Ir.current?.abort(),ao(Pd(xs.current?.cwd??Ae??void 0)),xs.current=null,Ir.current=null,ti.current?.abort(),ao("right-sidebar-git-details"),ti.current=null;for(const _ of Pr.current.values())_.abort();for(const _ of Pr.current.keys())ao(`right-sidebar-git-untracked:${_}`);Pr.current.clear(),Wn.current.clear(),Vi.current+=1,ni.current?.abort(),ni.current=null,tt.current+=1,je.current?.abort(),ao("right-sidebar-recent-commits"),je.current=null,Fs(!1),bt(!1),at(null),Rt(null),Ot(null),ar(null),ct(!1),dn(""),ln([]),tn(!1),sr(!1),Qr(null),_e(!1),Y(""),ve(!1),Oe(null),ia(!1),me&&Es(!1)}},[me,e,ve]),b.useEffect(()=>{if(!X)return;const _=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(_)},[X]),b.useEffect(()=>{me||ls(!1)},[me]);const Nl=b.useCallback(_=>{di(_);const O=nc.current;O&&(O.update(),O.slideTo(_,0),window.requestAnimationFrame(()=>{O.update(),O.slideTo(_,0)}))},[]);b.useEffect(()=>{if(me)if(ls(c),c&&qr){ui(1);const _=Ba.current;_&&(_.update(),_.activeIndex!==1&&(Lo.current=1,_.slideTo(1,0)))}else{ui(0);const _=Ba.current;_&&_.activeIndex!==0&&(Lo.current=0,_.slideTo(0,0)),Oe(null)}},[me,c,Ae,qr]),b.useEffect(()=>{if(u!==void 0&&!c){ui(0);const _=Ba.current;_&&_.activeIndex!==0&&(Lo.current=0,_.slideTo(0,0)),ls(!1),Oe(null)}},[u,c]),b.useEffect(()=>{y!==void 0&&lt(null)},[y]),b.useEffect(()=>{!me&&c&&p?.()},[me,p,c]),b.useEffect(()=>{nt(_=>F2(_,t))},[t]);const Qa=b.useCallback(_=>{me||(_.preventDefault(),Rc.current={startX:_.clientX,startWidth:xt,pointerId:_.pointerId},_.currentTarget.setPointerCapture(_.pointerId))},[xt,me]),ma=b.useCallback(_=>{const O=Rc.current;if(!O||O.pointerId!==_.pointerId)return;const Z=F2(O.startWidth+_.clientX-O.startX,t);nt(Z),n0(Ef,Z,OJ)},[t]),rc=b.useCallback(_=>{const O=Rc.current;if(!(!O||O.pointerId!==_.pointerId)){Rc.current=null,$d(Ef);try{_.currentTarget.releasePointerCapture(_.pointerId)}catch{}}},[]),ga=!!(Ae&&ce!==null&&e7(te)),zo=ga?"files":Ct,As=zo==="git",bi=zo==="files",Rs=zo==="diff";b.useEffect(()=>{if(!me){ja(!0);return}if(!e){const O=window.setTimeout(()=>{ja(!1)},HJ);return()=>window.clearTimeout(O)}ja(!1);const _=window.setTimeout(()=>{ja(!0)},$J);return()=>window.clearTimeout(_)},[me,e]),b.useEffect(()=>{if(!me||!Rs)return;const _=nc.current;if(!_)return;const O=window.requestAnimationFrame(()=>{_.update()});return()=>window.cancelAnimationFrame(O)},[Rs,me]),b.useEffect(()=>{if(!ga||!Ae||B)return;const _=window.setTimeout(()=>{qs(Ae,{includeNested:!0,background:!0})},3e3);return()=>window.clearTimeout(_)},[ga,Ae,B,qs]),b.useEffect(()=>{if(!(e&&(As||Rs))||!Ae||B||!_r||Ic.current===Ae)return;Ic.current=Ae;const O=As&&!me?0:eb,Z=window.setTimeout(()=>{qs(Ae,{includeNested:!0,background:!0})},O);return()=>{window.clearTimeout(Z)}},[Rs,B,As,me,e,qs,_r,Ae]),b.useEffect(()=>{!e||!As||(!me||ws)&&ia(!0)},[As,me,e,ws]),b.useEffect(()=>{if(!e||As)return;const _=window.setTimeout(()=>{ia(!0)},eb);return()=>window.clearTimeout(_)},[As,e]),b.useEffect(()=>{Rs&&Es(!0)},[Rs]);const Ml=b.useCallback(_=>{et&&Wee(et,_.currentTarget.scrollTop)},[et]);b.useEffect(()=>()=>{Ir.current?.abort(),$d(av),$d(lv),$d(Ef),$d(Jx)},[]),b.useEffect(()=>{if(!et||!_r)return;const _=uC()[et]?.top;if(typeof _!="number")return;let O=window.requestAnimationFrame(()=>{jr.current&&(jr.current.scrollTop=_),O=window.requestAnimationFrame(()=>{jr.current&&(jr.current.scrollTop=_)})});return()=>window.cancelAnimationFrame(O)},[et,_r]),b.useEffect(()=>{if(!e)return;const _=new AbortController;return vI(_.signal).then(O=>Qs(!!O.available)).catch(()=>Qs(!1)),()=>_.abort()},[e]);const xa=b.useCallback(_=>{if(fe(null),Rr(_),Oe(null),me){ls(!0),ui(1),Ba.current?.slideTo(1),f?.();return}},[me,f,Rr]),au=b.useCallback((_,O)=>{if(fe(null),Rr(_),$e(O),me){ls(!0),ui(1),Ba.current?.slideTo(1),f?.();return}},[me,f,Rr]),Dl=b.useCallback(async(_,O)=>{const Z=O||hr||Ae;if(!(!Z||_.length===0)){Wi(!0);try{await wb(Z,_),Ho(Z,!1)}catch(De){Dr(De instanceof Error?De.message:C("rightSidebar.uploadFailed")),window.setTimeout(()=>Dr(null),4e3)}finally{Wi(!1)}}},[hr,Ae,Ho,C]),lu=b.useCallback(async _=>{try{await wI(_)}catch(O){Dr(O instanceof Error?O.message:C("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>Dr(null),4e3)}},[C]),sc=b.useCallback(_=>{_.preventDefault(),_.stopPropagation(),_.dataTransfer.types.includes("Files")&&Pa(!0)},[]),Mc=b.useCallback(_=>{_.preventDefault(),_.stopPropagation(),Pa(!1)},[]),ic=b.useCallback(_=>{_.preventDefault(),_.stopPropagation(),Pa(!1);const O=_.dataTransfer.files;O.length>0&&Dl(Array.from(O))},[Dl]),ba=b.useCallback(_=>{ge(_),window.setTimeout(()=>ge(O=>O===_?null:O),1400)},[]),ya=b.useCallback(_=>{Te(_),window.setTimeout(()=>Te(O=>O===_?null:O),1400)},[]);b.useEffect(()=>{$n(E4,ze)},[ze]),b.useEffect(()=>{$n(I4,We)},[We]),b.useEffect(()=>{$n(R4,xe)},[xe]),b.useEffect(()=>{n0(Jx,Ce,DJ)},[Ce]);const yi=b.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),$a=b.useRef(null),va=b.useRef(null);b.useEffect(()=>{let _=!1;BE().then(Z=>{_||($a.current=Z.text,Qe(De=>Z.text&&Z.text!==De?Z.text:De))}).catch(()=>{});const O=Mm(Z=>{Z.type==="context-draft"&&Z.origin!==yi.current&&($a.current=Z.text,Qe(Z.text))});return()=>{_=!0,O(),va.current!==null&&(window.clearTimeout(va.current),va.current=null)}},[]),b.useEffect(()=>{if($a.current===Ce)return;va.current!==null&&window.clearTimeout(va.current);const _=Ce;va.current=window.setTimeout(()=>{va.current=null,FE(_,yi.current).then(()=>{$a.current=_}).catch(()=>{})},500)},[Ce]);const pl=b.useCallback((_,O,Z)=>{_&&(ze?(Qe(De=>aJ(De,_)+(Z??"")),window.matchMedia("(pointer: coarse)").matches||(W(!1),At(De=>De+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:Z?_+Z:_,focus:!0}})),ba(O))},[ze,ba]),jl=b.useCallback(_=>{const O=kf(_,Ae);return qb(O,Ae)},[Ae]),Dc=C0(ya),Ys=b.useCallback((_,O)=>{const Z=kf(_,Ae);pl(AS(Z,Ae),O??`path:${Z}`)},[Ae,pl]),jc=b.useCallback(async _=>{Wi(!0);try{await AO(_,wb,O=>{Ys(O,`path:${O}`)}),me&&!ze&&n()}catch(O){Dr(O instanceof Error?O.message:C("rightSidebar.uploadFailed")),window.setTimeout(()=>Dr(null),4e3)}finally{Wi(!1)}},[ze,Ys,me,n,C]),oc=b.useCallback((_,O)=>{if(!_)return;const Z=_.includes(`
200
+ `})(),fn=`path:${an}`,Un=T?`path:${an}:${T.start}-${T.end}`:fn,hn=I===fn,Kn=I===Un,sn=j===fn,zn=j===Un,as=Kn||zn,Bt=T?T.start===T.end?`L${T.start}`:`L${T.start}-${T.end}`:null,rn=qe=>{const ct=z.current;if(!ct)return;const jt=ct.getBoundingClientRect(),dn=qe.currentTarget.getBoundingClientRect(),An=qe.clientX||dn.left+dn.width/2,ln=(qe.clientY||dn.top+dn.height/2)-jt.top+ct.scrollTop,pn=c?116:132,tn=ct.scrollLeft+Math.max(8,ct.clientWidth-pn),cn=Math.min(Math.max(8,An-jt.left+ct.scrollLeft+10),tn);pe({top:ln,left:cn})},bt=(qe,ct)=>{G2()||(rn(qe),L(jt=>{const dn=Y4(jt,ct,ct);return dn||pe(null),dn}))},Tt=(qe,ct,jt)=>{rn(qe),L(dn=>{const An=Y4(dn,ct,jt);return An||pe(null),An})},at=(qe,ct,jt,dn)=>{dn==="end"&&rn(qe),L({start:ct,end:jt})},$t=qe=>{const{scrollTop:ct,scrollLeft:jt}=qe.currentTarget;Fe(ct),ob(C,e,{top:ct,left:jt,markdownTop:ct})},Rt=qe=>{if(qe.directory){a?.(qe.path);return}if(qe.path===an){qe.fragment&&Ft(qe.fragment);return}ze(ct=>[...ct,an]),W.current=qe.path,We(qe.fragment),L(null),$(qe.path)},vn=()=>{const qe=Te[Te.length-1];qe&&(ze(ct=>ct.slice(0,-1)),W.current=qe,We(null),L(null),$(qe))},Ot=qe=>{const{scrollTop:ct,scrollLeft:jt}=qe.currentTarget;ob(C,e,{top:ct,left:jt})},Jt=()=>{T&&n(rr,Un)},ar=async()=>{if(!(!an||Qe.status==="pending")&&!(H.kind==="loading"||H.kind==="error")){pt({status:"pending"});try{await ty(an),pt({status:"idle"})}catch(qe){pt({status:"error",message:qe instanceof Error?qe.message:R("rightSidebar.downloadFailed")})}}};return o.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[ot.popoverNode,o.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${c&&(Ge||gt)?"py-1.5":"py-2"}`,children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[c&&i&&o.jsx("button",{type:"button",onClick:i,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":R("rightSidebar.backToFileList"),title:R("rightSidebar.backToFileList"),children:o.jsx(oy,{size:16})}),Te.length>0&&o.jsxs("button",{type:"button",onClick:vn,className:"inline-flex h-9 shrink-0 items-center gap-1 rounded-full bg-primary/10 px-2.5 text-primary transition hover:bg-primary/15 active:scale-95","aria-label":R("rightSidebar.backToPreviousPreview"),title:R("rightSidebar.backToPreviousPreview"),children:[o.jsx(l0,{size:15}),o.jsx("span",{className:"text-[11px] font-medium",children:R("rightSidebar.backToPreviousPreview")})]}),o.jsxs("div",{className:"min-w-0",title:an,children:[o.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Er.name}),Er.dir&&o.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Er.dir})]})]}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Zn&&o.jsx("button",{type:"button",onClick:At?Gt:Cr,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${At?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":R("rightSidebar.findInFile"),title:`${R("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:o.jsx(Jl,{size:14})}),le&&H.kind==="text"&&o.jsx("button",{type:"button",onClick:()=>{u&&g?.(),ke(qe=>{const ct=qe==="preview"?"source":"preview";return $n(LT,ct),ct}),L(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${c?"w-9 px-0":"px-3"}`,"aria-label":R(de==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:R(de==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:c?de==="preview"?o.jsx(Eb,{size:14}):o.jsx(Lb,{size:14}):R(de==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),dt&&H.kind==="text"&&o.jsx("button",{type:"button",onClick:()=>{oe(qe=>{const ct=qe==="preview"?"source":"preview";return hJ(C,e,ct),ct}),L(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${c?"w-9 px-0":"px-3"}`,"aria-label":R(be==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:R(be==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:c?be==="preview"?o.jsx(Eb,{size:14}):o.jsx(Lb,{size:14}):R(be==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),gt&&o.jsx("button",{type:"button",onClick:()=>{he.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":R(J?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:R(J?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:o.jsx(ay,{size:15})}),!c&&o.jsx("button",{type:"button",onClick:()=>t(an,fn),...ot(yr,fn),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${hn||sn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:R("rightSidebar.insertReference",{reference:yr}),children:R(sn?"rightSidebar.copied":hn?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),o.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(yr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:R("rightSidebar.copyReference",{reference:yr}),"aria-label":R("rightSidebar.copyFileRef"),children:o.jsx(iy,{size:13})}),o.jsx("button",{type:"button",onClick:()=>{ar()},disabled:Qe.status==="pending"||H.kind==="loading"||H.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:Qe.status==="error"?Qe.message??R("rightSidebar.downloadFailed"):R("rightSidebar.downloadFile"),"aria-label":R("rightSidebar.downloadFile"),children:Qe.status==="pending"?o.jsx(Fn,{size:13,className:"animate-spin"}):o.jsx(c0,{size:14})})]})]}),At&&Zn&&o.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-1.5","data-file-preview-search":!0,children:[o.jsxs("div",{className:"flex min-w-0 flex-1 items-center rounded-lg bg-surface-2 px-2 focus-within:bg-surface-elevated",children:[o.jsx(Jl,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),o.jsx("input",{ref:Le,type:"search",value:Yt,onChange:qe=>Mt(qe.target.value),onKeyDown:qe=>{qe.key==="Enter"&&(qe.preventDefault(),nr(qe.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:R("rightSidebar.findInFilePlaceholder"),"aria-label":R("rightSidebar.findInFile")}),o.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:on.length>0?`${Cn+1}/${on.length}`:"0/0"})]}),o.jsx("button",{type:"button",onClick:()=>nr(-1),disabled:on.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":R("rightSidebar.previousSearchMatch"),title:`${R("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:o.jsx(xg,{size:13})}),o.jsx("button",{type:"button",onClick:()=>nr(1),disabled:on.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":R("rightSidebar.nextSearchMatch"),title:`${R("rightSidebar.nextSearchMatch")} (Enter)`,children:o.jsx(p8,{size:13})}),o.jsx("button",{type:"button",onClick:Gt,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":R("rightSidebar.closeFileSearch"),title:`${R("rightSidebar.closeFileSearch")} (Esc)`,children:o.jsx(ts,{size:13})})]}),Se&&!(c&&(Ge||gt))&&o.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[Se.size!==null&&o.jsx("span",{children:R("rightSidebar.byteCount",{count:Se.size.toLocaleString()})}),"truncated"in Se&&Se.truncated&&o.jsx("span",{className:"text-[color:var(--warning)]",children:R("rightSidebar.previewTruncated")}),"mimeType"in Se&&o.jsx("span",{children:Se.mimeType}),"dimensions"in H&&H.dimensions&&o.jsxs("span",{children:[H.dimensions.width," × ",H.dimensions.height]})]}),!(c&&(Ge||gt))&&!nn&&H.kind!=="binary"&&o.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:o.jsx("span",{className:"truncate",children:un?R("rightSidebar.edaPickHint"):It?R("rightSidebar.csvTablePreview"):Me||Ee?R("rightSidebar.kicadProjectPickHint"):vt?R("rightSidebar.videoPreviewHint"):Kt?R("rightSidebar.imagePreviewHint"):Ge?T?R("rightSidebar.selectedLineHint",{lineLabel:Bt??""}):R("rightSidebar.markdownPreviewHint"):gt?R("rightSidebar.htmlPreviewHint"):T?R("rightSidebar.selectedLineHint",{lineLabel:Bt??""}):R("rightSidebar.multiLineHint")})})]}),H.kind==="loading"?o.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:H.mode==="eda"?R("rightSidebar.edaLoading"):H.mode==="image"?R("rightSidebar.loadingImage"):H.mode==="model3d"?R("rightSidebar.model3dLoading"):H.mode==="video"?R("rightSidebar.loadingVideo"):"Loading file…"}):H.kind==="error"?o.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:o.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:H.message})}):H.kind==="binary"?o.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:o.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:R("rightSidebar.binaryPreviewHint")})}):H.kind==="image"?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:H.meta.mimeType==="image/svg+xml"?o.jsx(CT,{blobUrl:H.objectUrl,filePath:an,viewLabel:"SVG 文件",onInsertAnnotation:r}):o.jsx(yC,{src:H.objectUrl,alt:Er.name,vector:!1,onLoad:qe=>{const ct=qe.currentTarget;Y(jt=>jt.kind==="image"?{...jt,dimensions:{width:ct.naturalWidth,height:ct.naturalHeight}}:jt)},onError:()=>Y({kind:"error",message:R("rightSidebar.imageLoadFailed")})})}):H.kind==="video"?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:o.jsx(bJ,{url:H.url,onLoadError:()=>Y({kind:"error",message:R("rightSidebar.videoLoadFailed")})})}):H.kind==="eda"?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:o.jsx(CJ,{blobUrl:H.objectUrl,filePath:an,view:H.view,board:an.toLowerCase().endsWith(".kicad_pcb"),onViewChange:fe,onInsertAnnotation:r,onRefresh:kn,interactive3d:X?o.jsx(b.Suspense,{fallback:o.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:R("rightSidebar.model3dLoading")}),children:o.jsx(D4,{blobUrl:X.objectUrl,ext:".glb",fileName:Er.name,filePath:an,features:null,onInsertFeature:r,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:qe=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(qe)?qe:"PCB板体/铜箔/丝印",active:H.view==="pcb-3d"})}):void 0})}):H.kind==="model3d"?o.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:o.jsx(b.Suspense,{fallback:o.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:R("rightSidebar.model3dLoading")}),children:o.jsx(D4,{blobUrl:H.objectUrl,ext:H.ext,fileName:Er.name,filePath:an,features:ie,onInsertFeature:r,onRefresh:kn})})}):H.kind==="text"&&It?o.jsx(LJ,{content:H.content,filePath:an,onInsertAnnotation:r},an):H.kind==="text"&&(Me||Ee)?o.jsx(RJ,{content:H.content,filePath:an,localState:Ee,onInsertAnnotation:r},an):Ge?o.jsxs("div",{ref:z,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:$t,style:{touchAction:"pan-x pan-y"},children:[o.jsx(Vee,{content:H.content,filePath:an,rootPath:C,lineRange:T,onLineRangeClick:Tt,onLineRangeDrag:at,scrollTop:ge,outlineOpen:u,outlineCloseSignal:f,onOutlineOpen:p,onOutlineClose:g,lightboxOpen:y,lightboxCloseSignal:v,onLightboxOpen:S,onLightboxClose:A,onLocalLinkOpen:Rt}),T&&te&&o.jsxs("button",{type:"button",onClick:Jt,...ot(rr,Un),style:{top:te.top,left:te.left,transform:"translateY(-50%)"},className:K4(c,as),title:`Insert markdown reference: ${Hn}`,children:[o.jsx(El,{size:c?13:11}),zn?R("rightSidebar.copied"):Kn?R("rightSidebar.inserted"):R("rightSidebar.insertLineRef",{lineLabel:Bt??""})]})]}):gt?o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:o.jsx(NJ,{ref:he,src:uI(an),title:`${Er.name} preview`,exitFullscreenLabel:R("rightSidebar.htmlFullscreenExit"),onFullscreenChange:Xe},`${an}:${$e}:${Ve}`)}):H.kind==="text"?o.jsxs("div",{ref:z,onScroll:Ot,className:`${cv} termdock-native-select termdock-code relative min-h-0 flex-1 overflow-auto rounded-none bg-surface p-2 font-mono text-[11px] leading-relaxed text-foreground`,children:[Jn.length>0?o.jsx("div",{className:"min-w-full",children:Jn.map((qe,ct)=>{const jt=ct+1,dn=!!(T&&jt>=T.start&&jt<=T.end),An=He&&He.length===Jn.length?He[ct]:null;return o.jsxs("div",{ref:_n=>{_n?q.current.set(jt,_n):q.current.delete(jt)},role:"button","data-file-preview-line":jt,tabIndex:0,onClick:_n=>bt(_n,jt),onKeyDown:_n=>{_n.key!=="Enter"&&_n.key!==" "||(_n.preventDefault(),bt(_n,jt))},style:{gridTemplateColumns:`${wr}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${dn?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${yr}:${jt}`,children:[o.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${dn?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:jt}),o.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:An??(qe||" ")})]},ct)})}):"Empty file.",T&&te&&o.jsxs("button",{type:"button",onClick:Jt,...ot(rr,Un),style:{top:te.top,left:te.left,transform:"translateY(-50%)"},className:K4(c,as),title:`Insert code reference: ${Hn}`,children:[o.jsx(El,{size:c?13:11}),zn?R("rightSidebar.copied"):Kn?R("rightSidebar.inserted"):R("rightSidebar.insertLineRef",{lineLabel:Bt??""})]})]}):null]})}function r7({isOpen:e,drawerWidthPx:t,onClose:n,onOpen:r,push:s,pinned:i=!1,onTogglePinned:a,rightSidebarFilePreviewOpen:c=!1,rightSidebarFilePreviewCloseSignal:u,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:p,rightSidebarRepoPickerOpen:g=!1,rightSidebarRepoPickerCloseSignal:y,onOpenRightSidebarRepoPicker:v,onCloseRightSidebarRepoPicker:S,markdownOutlineOpen:A=!1,markdownOutlineCloseSignal:T,onOpenMarkdownOutline:L,onCloseMarkdownOutline:I,markdownImageLightboxOpen:j=!1,markdownImageLightboxCloseSignal:P,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:R}){const{t:C,locale:$}=Yn(),[H,Y]=b.useState(""),[V,fe]=b.useState(null),X=ft(_=>_.rightSearchOpen),ve=ft(_=>_.setRightSearchOpen),we=ft(_=>_.rightSidebarLayoutPreference),ie=ft(_=>_.setRightSidebarLayoutPreference),[ae,q]=b.useState(()=>iee()),z=b.useDeferredValue(H),[te,pe]=b.useState(null),[de,ke]=b.useState([]),[be,oe]=b.useState([]),[he,J]=b.useState(null),[Xe,lt]=b.useState(null),[Ze,ge]=b.useState(null),[Fe,Te]=b.useState(null),[ze,Be]=b.useState(()=>Or(E4,If)??!1),[We,W]=b.useState(()=>Or(I4,If)??!1),[xe,He]=b.useState(()=>Or(R4,If)??!1),[Ce,Qe]=b.useState(()=>Or(Jx,eee)??""),[pt,At]=b.useState(0),[yt,Yt]=b.useState(!1),[Mt,on]=b.useState(!1),xr=b.useRef(null),Cn=b.useRef(null),[or,Le]=b.useState(!1),[ot,Oe]=b.useState(null),[Dt,$e]=b.useState(null),[Ut,_t]=b.useState(()=>B4(Xx)),[Ve,Ur]=b.useState(()=>B4(L4)),[kn,Ft]=b.useState(()=>JJ()),[Zn,Gt]=b.useState(()=>tee()),[Cr,nr]=b.useState(()=>ree()),an="words",[Er,yr]=b.useState(0),[Jn,wr]=b.useState([]),[Se,le]=b.useState([]),[It,Me]=b.useState(!1),[Ee,Ge]=b.useState(null),[dt,gt]=b.useState([]),[Kt,nn]=b.useState(!1),[vt,un]=b.useState([]),[Hn,rr]=b.useState([]),[fn,Un]=b.useState(!1),[hn,Kn]=b.useState(null),[sn,zn]=b.useState([]),[as,Bt]=b.useState({}),[rn,bt]=b.useState(!1),[Tt,at]=b.useState(null),[$t,Rt]=b.useState(null),[vn,Ot]=b.useState(null),[Jt,ar]=b.useState(null),[qe,ct]=b.useState(!1),[jt,dn]=b.useState(""),An=b.useDeferredValue(jt),[_n,ln]=b.useState([]),[pn,tn]=b.useState(!1),[cn,sr]=b.useState(!1),[ps,Qr]=b.useState(null),[se,_e]=b.useState(!1),je=b.useRef(null),tt=b.useRef(0),Qt=b.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[Nt,st]=b.useState(null),[wt,Lt]=b.useState(()=>Or(Zx,If)??!1),[Tn,mn]=b.useState(!1),[lr,zr]=b.useState([]),[jn,mr]=b.useState({}),[dr,en]=b.useState({}),[Vt,ir]=b.useState(!0),[Xn,Gr]=b.useState(()=>new Set),[gn,fr]=b.useState(null),[Ln,ns]=b.useState(null),[kr,ls]=b.useState(!1),[ms,ui]=b.useState(0),[,di]=b.useState(0),[ws,ja]=b.useState(!1),[fi,ia]=b.useState(!1),[hi,Es]=b.useState(()=>ft.getState().rightTab==="diff"),[cr,pi]=b.useState(null),[ho,rs]=b.useState(null),[er,Mr]=b.useState(null),[Is,Dr]=b.useState(null),[Cs,To]=b.useState(null),[Wr,oa]=b.useState(()=>Date.now()),[Co,zi]=b.useState(!1),[Js,Fs]=b.useState(!1),[aa,la]=b.useState(""),[Os,ca]=b.useState(""),[Gi,ki]=b.useState(""),[_i,gs]=b.useState(""),[mi,ei]=b.useState(null),[ko,Wi]=b.useState(!1),[ua,Pa]=b.useState(!1),[fl,Qs]=b.useState(!1),[gi,Li]=b.useState({key:null,nonce:0}),Ei=b.useRef(null),po=b.useRef(null),me=qO(t,i,we),ut=YJ(me,i,Cr),[xt,nt]=b.useState(()=>hee(t)),Ct=ft(_=>_.rightTab),On=ft(_=>_.setRightTab),Ae=ft(_=>_.rootPath),hr=ft(_=>_.explorerRoot),Ss=ft(_=>_.pinnedExplorerRootsCache),qn=ft(_=>_.setExplorerRoot),cs=ft(_=>_.resetExplorerToProject),Vr=ft(_=>_.pinExplorerRoot),Gs=ft(_=>_.unpinExplorerRoot),qr=ft(_=>_.selectedFilePath),Rr=ft(_=>_.selectFile),Ws=ft(_=>_.showHiddenFiles),tc=ft(_=>_.toggleShowHiddenFiles),Nn=ft(_=>_.changedFiles),Kr=ft(_=>_.setChangedFiles),Ho=ft(_=>_.invalidateDirectoryCache),_o=ft(_=>_.setDirectorySortMode),$s=ft(_=>_.applyFileWatchEvents),xi=ft(_=>_.bumpFileWatchEpoch),B=ft(_=>_.gitBundleLoading),K=ft(_=>_.gitBundleSlow),ee=ft(_=>_.gitBundleError),ce=ft(_=>_.gitBundleLastLoadedAt),Je=ft(_=>_.setGitBundleLoading),Ke=ft(_=>_.setGitBundleSlow),ht=ft(_=>_.setGitBundleError),Ht=ft(_=>_.markGitBundleLoaded),et=hr??Ae,Zt=ft(_=>et?_.fileSortModes[et]??"name":"name"),_r=ft(_=>!!(et&&_.directoryCache.has(et))),jr=b.useRef(null),Lr=b.useRef(0),Ir=b.useRef(null),xs=b.useRef(null),Gn=b.useRef(0),Wn=b.useRef(new Map),Pr=b.useRef(new Map),ur=b.useRef(new Set),da=b.useRef(new Set),us=b.useRef(0),ti=b.useRef(null),Br=b.useRef(0),Ii=b.useRef(null),Vi=b.useRef(0),ni=b.useRef(null),fa=b.useRef(new Set),ou=b.useRef(null),Il=b.useRef(null),Ec=b.useRef(null),Ic=b.useRef(null);b.useEffect(()=>{if(Cs===null)return;const _=Math.max(0,Date.now()-Cs),O=_<6e4?1e3:_<36e5?6e4:_<864e5?36e5:864e5,Z=Math.max(50,O-_%O),De=window.setTimeout(()=>oa(Date.now()),Z);return()=>window.clearTimeout(De)},[Wr,Cs]);const Rc=b.useRef(null),Ba=b.useRef(null),nc=b.useRef(null),Lo=b.useRef(null),vr=b.useCallback(_=>ft.getState().rootPath===_,[]);b.useEffect(()=>{if(!e||typeof window>"u")return;const _=O=>{const Z=mte(O.target);Z&&Vp("global_change_row_event",{...gte(O),selectionPath:Z.dataset.diffSelectionPath,filePath:Z.dataset.diffFilePath,absolutePath:Z.dataset.diffAbsolutePath,repoRoot:Z.dataset.diffRepoRoot,status:Z.dataset.diffStatus,selectedFilePath:ft.getState().selectedFilePath,rightTab:ft.getState().rightTab,activeGitRepoRoot:he,changedFiles:ft.getState().changedFiles.size})};return window.addEventListener("pointerdown",_,{capture:!0}),window.addEventListener("click",_,{capture:!0}),()=>{window.removeEventListener("pointerdown",_,{capture:!0}),window.removeEventListener("click",_,{capture:!0})}},[he,e]);const Fa=b.useCallback(async(_=Ae??void 0)=>{if(!_)return null;if(ur.current.has(_)||da.current.has(_))return oi("untracked_skip_cached",{cwd:_,rootPath:Ae,completed:ur.current.has(_),running:da.current.has(_)}),null;const O=Ae,Z=Gn.current+1;Gn.current=Z,Wn.current.set(_,Z);const De=`right-sidebar-git-untracked:${_}`,Ie=new AbortController;Pr.current.set(_,Ie),da.current.add(_),oi("untracked_start",{requestId:Z,cwd:_,rootPath:Ae});try{let Ye=await d5(_,Ie.signal,De),mt=0;for(;Ye.status==="running"&&mt<120;){if(Wn.current.get(_)!==Z||Ie.signal.aborted)return oi("untracked_stale_result",{requestId:Z,activeRequestId:Wn.current.get(_),cwd:_,status:Ye.status}),null;if(!vr(O))return oi("untracked_root_changed",{requestId:Z,cwd:_,expectedRootPath:O,currentRootPath:ft.getState().rootPath}),null;await new Promise(Et=>window.setTimeout(Et,mt<10?1e3:3e3)),mt+=1,Ye=await d5(_,Ie.signal,De)}if(Wn.current.get(_)!==Z||!vr(O))return oi("untracked_stale_result",{requestId:Z,activeRequestId:Wn.current.get(_),cwd:_,expectedRootPath:O,currentRootPath:ft.getState().rootPath,files:Ye.files.length,status:Ye.status}),null;if(Ye.status==="done")return Kr(hC(ft.getState().changedFiles,Ye.files)),Ye.files.length>0&&ke(Et=>{const Ps=new Map(Et.map(bs=>[bs.root,bs])).get(_);if(!Ps)return Et;const fs=Jee(Ps.files,Ye.files),Sn=Et.map(bs=>bs.root===_?{...bs,files:fs,context:bs.context?{...bs.context,changedFiles:fs.map(Bl=>({path:Bl.path,absolutePath:Bl.absolutePath,status:Bl.status})),truncated:!1}:bs.context,untrackedDeferred:!1}:bs);oe(pC(Sn,Ae));const Vn=Sn.find(bs=>bs.root===Ae);return Vn?.context&&pe(bs=>bs?.root===Vn.root?{...bs,...Vn.context}:bs),Sn}),ur.current.add(_),oi("untracked_apply",{requestId:Z,cwd:_,files:Ye.files.length}),Ye;const St=Ye.error||(Ye.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return ur.current.add(_),oi("untracked_error",{requestId:Z,cwd:_,message:St,code:Ye.code,status:Ye.status}),null}catch(Ye){if(Wn.current.get(_)!==Z||!vr(O)||pc(Ye))return oi("untracked_aborted",{requestId:Z,activeRequestId:Wn.current.get(_),cwd:_,expectedRootPath:O,currentRootPath:ft.getState().rootPath,message:Ye instanceof Error?Ye.message:String(Ye)}),null;const mt=Ye instanceof Error?Ye.message:"Failed to scan untracked files";return ur.current.add(_),oi("untracked_error",{requestId:Z,cwd:_,message:mt}),null}finally{Pr.current.get(_)===Ie&&Pr.current.delete(_),Wn.current.get(_)===Z&&Wn.current.delete(_),da.current.delete(_)}},[te,vr,Ae,Kr]),qi=b.useMemo(()=>{const _=new Set(be.map(Z=>Z.root)),O=dt.filter(Z=>_.has(Z));return O.length>0?O:he?[he]:[]},[he,dt,be]),Nc=qi.length===0,Oa=b.useMemo(()=>qi.map(_=>de.find(O=>O.root===_)).filter(_=>!!_),[qi,de]),ha=b.useMemo(()=>be.map(_=>({root:_.root,label:_.label,branch:_.branch??null})),[be]),Vs=b.useCallback(async()=>{if(!Ae){wr([]),le([]);return}const _=Ae,O=Br.current+1;Br.current=O,Ii.current?.abort();const Z=new AbortController;Ii.current=Z,Me(Jn.length===0),Ge(null);try{const De=qi.length>0?await Promise.all(qi.map(Ie=>c5({workspaceRoot:Ae,repoRoot:Ie},Z.signal))).then(Ie=>({records:Ie.flatMap(Ye=>Ye.records),walkthroughs:Ie.flatMap(Ye=>Ye.walkthroughs??[])})):await c5({workspaceRoot:Ae},Z.signal);if(Br.current!==O||!vr(_))return;wr(De.records),le(De.walkthroughs??[])}catch(De){if(Br.current!==O||!vr(_)||pc(De))return;Ge(De instanceof Error?De.message:"Failed to load change audit explanations")}finally{Ii.current===Z&&(Ii.current=null),Br.current===O&&vr(_)&&Me(!1)}},[Jn.length,qi,vr,Ae]),Uo=b.useCallback(async(_,O,Z)=>{if(!_&&!Ae){un([]),rr([]);return}const De=Ae,Ie=Vi.current+1;Vi.current=Ie,ni.current?.abort();const Ye=new AbortController;ni.current=Ye;try{const mt=_?[_]:Array.from(new Set([Ae,...de.map(Et=>Et.root)].filter(Et=>!!Et))),St=await Promise.all(mt.map(Et=>_I({repoRoot:Et,baseRef:O,branchName:Z},Ye.signal))).then(Et=>{const gr=new Map,Ps=new Map;for(const fs of Et){for(const Sn of fs.records)gr.set(Sn.id,Sn);for(const Sn of fs.walkthroughs??[])Ps.set(Sn.id,Sn)}return{records:Array.from(gr.values()),walkthroughs:Array.from(Ps.values())}});if(Vi.current!==Ie||!vr(De))return;un(St.records),rr(St.walkthroughs??[])}catch(mt){if(Vi.current!==Ie||!vr(De)||pc(mt))return;console.warn("[RightSidebar] Failed to load branch explanations",mt)}finally{ni.current===Ye&&(ni.current=null)}},[de,vr,Ae]),pa=b.useCallback((_,O={})=>{if(!vr(Ae)){oi("apply_skipped_root_changed",{expectedRootPath:Ae,currentRootPath:ft.getState().rootPath,bundleRoot:_.context?.root,files:_.files.length});return}oi(_.files.length===0?"empty_bundle":"apply",{rootPath:Ae,available:_.available,files:_.files.length,repositories:_.repositories?.map(Sn=>({root:Sn.root,relativeRoot:Sn.relativeRoot,files:Sn.files.length,available:Sn.available,error:Sn.error})),repoFilters:_.repoFilters?.map(Sn=>({root:Sn.root,label:Sn.label,count:Sn.count})),cached:_.cached,stale:_.stale,cacheAgeMs:_.cacheAgeMs,untrackedDeferred:_.untrackedDeferred,error:_.error});let Z=OT(_),De=_.repoFilters??[],Ie=_.files;const Ye=ft.getState().changedFiles;if(!!(O.cacheOnly&&!_.cached&&_.files.length===0&&Z.length===0)&&(Ye.size>0||de.length>0||te)){oi("cache_only_apply_skipped_empty_backend_cache",{rootPath:Ae,currentFiles:Ye.size,currentRepositories:de.length});return}const St=X4(Ye.values(),Ae),Et=X4(_.files,Ae),gr=Z.some(Sn=>Sn.root!==Ae);if(!!(O.background&&Ye.size>0&&(_.files.length===0&&!_.error||St>0&&Et===0&&!gr))){oi("background_apply_skipped_degraded_bundle",{rootPath:Ae,currentFiles:Ye.size,nextFiles:_.files.length,currentNestedCount:St,nextNestedCount:Et,nextRepositories:Z.map(Sn=>({root:Sn.root,relativeRoot:Sn.relativeRoot,files:Sn.files.length})),cached:_.cached,stale:_.stale,error:_.error});return}if(O.replaceRepoRoot){const Sn=tte(Ye.values(),de,_,O.replaceRepoRoot,Ae);Ie=Sn.files,Z=Sn.repositories,De=Sn.repoFilters}if(Kr(fC(Ie)),ke(Z),oe(De),O.syncActiveRepo!==!1){const Sn=O.activeRepoRoot!==void 0?O.activeRepoRoot:he??P4(Ae),Vn=aee({..._,repositories:Z,repoFilters:De},Sn);J(Vn),tb(Ae,Vn)}typeof _.cacheUpdatedAt=="number"&&To(_.cacheUpdatedAt),pe(Sn=>{if(O.replaceRepoRoot&&O.replaceRepoRoot!==Ae)return Sn;if(!_.context)return null;const Vn=Sn?.root??Ae;return!Sn?.available||Vn!==(_.context.root??Ae)?_.context:{...Sn,..._.context}}),O.reloadDiff&&yr(Sn=>Sn+1);const fs=ft.getState().selectedFilePath;if(fs&&!fs.startsWith("/")&&!Ie.some(Sn=>Sn.path===fs||Sn.absolutePath===fs)&&Rr(null),_t(Sn=>{const Vn=new Set(Ie.map(Bl=>Oo(Bl,Ae)).filter(Boolean)),bs=new Set;for(const Bl of Sn)Vn.has(Bl)&&bs.add(Bl);return nb(Xx,bs),bs}),O.loadDeferred!==!1){const Sn=Z.filter(Vn=>Vn.untrackedDeferred&&Vn.root).map(Vn=>Vn.root);for(const Vn of Sn)Fa(Vn)}O.loadAudit!==!1&&Vs()},[he,vr,Vs,Fa,Ae,Rr,Kr]);b.useEffect(()=>{ou.current=null,Il.current=Ae;const _=[],O=[],De=P4(Ae);Lr.current+=1,us.current+=1,Gn.current+=1,Ir.current?.abort(),ao(Pd(xs.current?.cwd??Ae??void 0)),xs.current=null,Ir.current=null,ti.current?.abort(),ao("right-sidebar-git-details"),ti.current=null;for(const Et of Pr.current.values())Et.abort();for(const Et of Pr.current.keys())ao(`right-sidebar-git-untracked:${Et}`);Pr.current.clear(),Wn.current.clear(),Br.current+=1,Ii.current?.abort(),Ii.current=null,Vi.current+=1,ni.current?.abort(),ni.current=null,tt.current+=1,je.current?.abort(),ao("right-sidebar-recent-commits"),je.current=null,wr([]),le([]),Me(!1),Ge(null),gt([]),nn(!1),un([]),rr([]),Un(!1),Kn(null),bt(!1),at(null),Rt(null),Ot(null),ar(null),ct(!1),dn(""),ln([]),tn(!1),sr(!1),Qr(null),_e(!1),st(null),fr(null),ns(null),Lt(!1),$n(Zx,!1),mn(!1);const Ie=Ae?F4()[Ae]:null,Ye=Ie?.previewEntries??[],mt=Ie?.selectedPreviewKey??null,St=mt?Ye.find(Et=>Et.key===mt)??null:null;zr(Ie?.selectedRepoRoots??[]),mr(Ie?.repoTargetBranches??{}),en(Ie?.repoBaseBranches??{}),zn(Ye),Bt(Ie?.previewScrollTops??{}),St&&Ie?.previewDetailOpen&&(St.diff.hunks?.length??0)>0&&(Kn(St.diff),fr(St.key),ns(Ie.selectedPreviewFileKey??(St.diff.hunks?.[0]?`${St.diff.hunks[0].filePath}\0${St.diff.hunks[0].hunkHeader}\0${St.diff.hunks[0].hunkIndex}`:null)),Un(!0)),ir(Ie?.includeUncommitted??!0),ou.current=Ae,Fs(!1),J(De??null),ur.current.clear(),da.current.clear(),pi(null),rs(null),Mr(null),Dr(null),To(null),ke(_),oe(O),pe(null),Ic.current=null},[Ae]);const qs=b.useCallback(async(_=Ae??void 0,O={})=>{if(!_)return null;const Z=Ae,De=O.includeNested??!0,Ie=O.refresh??O.reloadDiff??!1,Ye=O.cacheOnly??!1,mt=O.background??!1;Ie&&ur.current.clear();const St=xs.current;if(St&&St.cwd===_&&St.includeNested===De&&St.refresh===Ie&&St.cacheOnly===Ye)return oi("reuse_pending",{cwd:_,includeNested:De,refresh:Ie,cacheOnly:Ye}),St.promise;const Et=Lr.current+1;Lr.current=Et,Ir.current?.abort();const gr=Pd(_);ao(gr);const Ps=new AbortController;Ir.current=Ps;let fs=null;mt||(Je(!0),Ke(!1)),ht(null),oi("start",{requestId:Et,cwd:_,rootPath:Ae,requestSlotId:gr,includeNested:De,refresh:Ie,cacheOnly:Ye,background:mt,existingChanges:Nn.size,lastLoadedAt:ce}),!mt&&typeof window<"u"&&(fs=window.setTimeout(()=>{Lr.current===Et&&Ke(!0)},UJ));const Sn=(async()=>{const Vn=await ap(_,Ps.signal,{includeNested:De,refresh:Ie,cacheOnly:Ye,action:Ie?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:gr,requestTimeoutMs:Ie?null:void 0});return rte(Vn)?(oi("cancelled_result_ignored",{requestId:Et,activeRequestId:Lr.current,cwd:_,error:Vn.error??Vn.context?.error}),null):Lr.current!==Et||!vr(Z)?(oi("stale_result",{requestId:Et,activeRequestId:Lr.current,cwd:_,expectedRootPath:Z,currentRootPath:ft.getState().rootPath,files:Vn.files.length,repositories:Vn.repositories?.length??0}),null):(pa(Vn,{reloadDiff:O.reloadDiff,syncActiveRepo:De,background:mt,cacheOnly:Ye,replaceRepoRoot:O.replaceRepoRoot}),Vn)})();xs.current={cwd:_,includeNested:De,refresh:Ie,cacheOnly:Ye,promise:Sn};try{const Vn=await Sn;return Lr.current===Et&&Vn&&vr(Z)?Ht({cached:Vn.cached,stale:Vn.stale,cacheAgeMs:Vn.cacheAgeMs,nestedDeferred:!De||Vn.nestedDeferred,untrackedDeferred:Vn.untrackedDeferred}):Lr.current===Et&&vr(Z)&&(Je(!1),Ke(!1)),Vn}catch(Vn){return Lr.current!==Et||!vr(Z)||pc(Vn)?(oi("aborted",{requestId:Et,activeRequestId:Lr.current,cwd:_,expectedRootPath:Z,currentRootPath:ft.getState().rootPath,message:Vn instanceof Error?Vn.message:String(Vn)}),null):(oi("error",{requestId:Et,cwd:_,includeNested:De,refresh:Ie,background:mt,message:Vn instanceof Error?Vn.message:String(Vn)}),mt||(pe(null),ht(Vn instanceof Error?Vn.message:"Failed to load Git changes")),null)}finally{fs!==null&&window.clearTimeout(fs),Ir.current===Ps&&(Ir.current=null),xs.current?.promise===Sn&&(xs.current=null),!mt&&Lr.current===Et&&vr(Z)&&(Je(!1),Ke(!1))}},[pa,Nn.size,ce,vr,Ht,Ae,ht,Je,Ke]),hl=b.useCallback(async()=>{if(!Ae)return;await qs(he??Ae,{reloadDiff:!0,includeNested:!he,refresh:!0,replaceRepoRoot:he??void 0})},[he,qs,Ae]),Rl=b.useCallback(async(_=Ae??void 0)=>{if(!_)return null;const O=Ae,Z=us.current+1;us.current=Z,ti.current?.abort(),ao("right-sidebar-git-details");const De=new AbortController;ti.current=De,Fs(!0);try{const Ie=await l5(_,De.signal,"load_git_details","right-sidebar-git-details");return us.current!==Z||!vr(O)?null:(ke(Ye=>Ye.map(mt=>mt.root===Ie.root?{...mt,available:Ie.available,context:Ie,error:Ie.error}:mt)),pe(Ye=>Ye?.root&&Ie.root&&Ye.root!==Ie.root?Ye:!Ye?.available||!Ie.available?Ie:{...Ye,...Ie}),Ie)}catch(Ie){return pc(Ie)||!vr(O)||us.current===Z&&Dr(Ie instanceof Error?Ie.message:"Failed to load Git details"),null}finally{ti.current===De&&(ti.current=null),us.current===Z&&vr(O)&&Fs(!1)}},[vr,Ae]);b.useEffect(()=>{if(!e){Lr.current+=1,us.current+=1,Gn.current+=1,Ir.current?.abort(),ao(Pd(xs.current?.cwd??Ae??void 0)),xs.current=null,Ir.current=null,ti.current?.abort(),ao("right-sidebar-git-details"),ti.current=null;for(const _ of Pr.current.values())_.abort();for(const _ of Pr.current.keys())ao(`right-sidebar-git-untracked:${_}`);Pr.current.clear(),Wn.current.clear(),Vi.current+=1,ni.current?.abort(),ni.current=null,tt.current+=1,je.current?.abort(),ao("right-sidebar-recent-commits"),je.current=null,Fs(!1),bt(!1),at(null),Rt(null),Ot(null),ar(null),ct(!1),dn(""),ln([]),tn(!1),sr(!1),Qr(null),_e(!1),Y(""),ve(!1),Oe(null),ia(!1),me&&Es(!1)}},[me,e,ve]),b.useEffect(()=>{if(!X)return;const _=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(_)},[X]),b.useEffect(()=>{me||ls(!1)},[me]);const Nl=b.useCallback(_=>{di(_);const O=nc.current;O&&(O.update(),O.slideTo(_,0),window.requestAnimationFrame(()=>{O.update(),O.slideTo(_,0)}))},[]);b.useEffect(()=>{if(me)if(ls(c),c&&qr){ui(1);const _=Ba.current;_&&(_.update(),_.activeIndex!==1&&(Lo.current=1,_.slideTo(1,0)))}else{ui(0);const _=Ba.current;_&&_.activeIndex!==0&&(Lo.current=0,_.slideTo(0,0)),Oe(null)}},[me,c,Ae,qr]),b.useEffect(()=>{if(u!==void 0&&!c){ui(0);const _=Ba.current;_&&_.activeIndex!==0&&(Lo.current=0,_.slideTo(0,0)),ls(!1),Oe(null)}},[u,c]),b.useEffect(()=>{y!==void 0&&lt(null)},[y]),b.useEffect(()=>{!me&&c&&p?.()},[me,p,c]),b.useEffect(()=>{nt(_=>F2(_,t))},[t]);const Qa=b.useCallback(_=>{me||(_.preventDefault(),Rc.current={startX:_.clientX,startWidth:xt,pointerId:_.pointerId},_.currentTarget.setPointerCapture(_.pointerId))},[xt,me]),ma=b.useCallback(_=>{const O=Rc.current;if(!O||O.pointerId!==_.pointerId)return;const Z=F2(O.startWidth+_.clientX-O.startX,t);nt(Z),n0(Ef,Z,HJ)},[t]),rc=b.useCallback(_=>{const O=Rc.current;if(!(!O||O.pointerId!==_.pointerId)){Rc.current=null,$d(Ef);try{_.currentTarget.releasePointerCapture(_.pointerId)}catch{}}},[]),ga=!!(Ae&&ce!==null&&e7(te)),zo=ga?"files":Ct,As=zo==="git",bi=zo==="files",Rs=zo==="diff";b.useEffect(()=>{if(!me){ja(!0);return}if(!e){const O=window.setTimeout(()=>{ja(!1)},GJ);return()=>window.clearTimeout(O)}ja(!1);const _=window.setTimeout(()=>{ja(!0)},zJ);return()=>window.clearTimeout(_)},[me,e]),b.useEffect(()=>{if(!me||!Rs)return;const _=nc.current;if(!_)return;const O=window.requestAnimationFrame(()=>{_.update()});return()=>window.cancelAnimationFrame(O)},[Rs,me]),b.useEffect(()=>{if(!ga||!Ae||B)return;const _=window.setTimeout(()=>{qs(Ae,{includeNested:!0,background:!0})},3e3);return()=>window.clearTimeout(_)},[ga,Ae,B,qs]),b.useEffect(()=>{if(!(e&&(As||Rs))||!Ae||B||!_r||Ic.current===Ae)return;Ic.current=Ae;const O=As&&!me?0:eb,Z=window.setTimeout(()=>{qs(Ae,{includeNested:!0,background:!0})},O);return()=>{window.clearTimeout(Z)}},[Rs,B,As,me,e,qs,_r,Ae]),b.useEffect(()=>{!e||!As||(!me||ws)&&ia(!0)},[As,me,e,ws]),b.useEffect(()=>{if(!e||As)return;const _=window.setTimeout(()=>{ia(!0)},eb);return()=>window.clearTimeout(_)},[As,e]),b.useEffect(()=>{Rs&&Es(!0)},[Rs]);const Ml=b.useCallback(_=>{et&&Yee(et,_.currentTarget.scrollTop)},[et]);b.useEffect(()=>()=>{Ir.current?.abort(),$d(av),$d(lv),$d(Ef),$d(Jx)},[]),b.useEffect(()=>{if(!et||!_r)return;const _=uC()[et]?.top;if(typeof _!="number")return;let O=window.requestAnimationFrame(()=>{jr.current&&(jr.current.scrollTop=_),O=window.requestAnimationFrame(()=>{jr.current&&(jr.current.scrollTop=_)})});return()=>window.cancelAnimationFrame(O)},[et,_r]),b.useEffect(()=>{if(!e)return;const _=new AbortController;return vI(_.signal).then(O=>Qs(!!O.available)).catch(()=>Qs(!1)),()=>_.abort()},[e]);const xa=b.useCallback(_=>{if(fe(null),Rr(_),Oe(null),me){ls(!0),ui(1),Ba.current?.slideTo(1),f?.();return}},[me,f,Rr]),au=b.useCallback((_,O)=>{if(fe(null),Rr(_),$e(O),me){ls(!0),ui(1),Ba.current?.slideTo(1),f?.();return}},[me,f,Rr]),Dl=b.useCallback(async(_,O)=>{const Z=O||hr||Ae;if(!(!Z||_.length===0)){Wi(!0);try{await wb(Z,_),Ho(Z,!1)}catch(De){Dr(De instanceof Error?De.message:C("rightSidebar.uploadFailed")),window.setTimeout(()=>Dr(null),4e3)}finally{Wi(!1)}}},[hr,Ae,Ho,C]),lu=b.useCallback(async _=>{try{await wI(_)}catch(O){Dr(O instanceof Error?O.message:C("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>Dr(null),4e3)}},[C]),sc=b.useCallback(_=>{_.preventDefault(),_.stopPropagation(),_.dataTransfer.types.includes("Files")&&Pa(!0)},[]),Mc=b.useCallback(_=>{_.preventDefault(),_.stopPropagation(),Pa(!1)},[]),ic=b.useCallback(_=>{_.preventDefault(),_.stopPropagation(),Pa(!1);const O=_.dataTransfer.files;O.length>0&&Dl(Array.from(O))},[Dl]),ba=b.useCallback(_=>{ge(_),window.setTimeout(()=>ge(O=>O===_?null:O),1400)},[]),ya=b.useCallback(_=>{Te(_),window.setTimeout(()=>Te(O=>O===_?null:O),1400)},[]);b.useEffect(()=>{$n(E4,ze)},[ze]),b.useEffect(()=>{$n(I4,We)},[We]),b.useEffect(()=>{$n(R4,xe)},[xe]),b.useEffect(()=>{n0(Jx,Ce,BJ)},[Ce]);const yi=b.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),$a=b.useRef(null),va=b.useRef(null);b.useEffect(()=>{let _=!1;BE().then(Z=>{_||($a.current=Z.text,Qe(De=>Z.text&&Z.text!==De?Z.text:De))}).catch(()=>{});const O=Mm(Z=>{Z.type==="context-draft"&&Z.origin!==yi.current&&($a.current=Z.text,Qe(Z.text))});return()=>{_=!0,O(),va.current!==null&&(window.clearTimeout(va.current),va.current=null)}},[]),b.useEffect(()=>{if($a.current===Ce)return;va.current!==null&&window.clearTimeout(va.current);const _=Ce;va.current=window.setTimeout(()=>{va.current=null,FE(_,yi.current).then(()=>{$a.current=_}).catch(()=>{})},500)},[Ce]);const pl=b.useCallback((_,O,Z)=>{_&&(ze?(Qe(De=>uJ(De,_)+(Z??"")),window.matchMedia("(pointer: coarse)").matches||(W(!1),At(De=>De+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:Z?_+Z:_,focus:!0}})),ba(O))},[ze,ba]),jl=b.useCallback(_=>{const O=kf(_,Ae);return qb(O,Ae)},[Ae]),Dc=C0(ya),Ys=b.useCallback((_,O)=>{const Z=kf(_,Ae);pl(AS(Z,Ae),O??`path:${Z}`)},[Ae,pl]),jc=b.useCallback(async _=>{Wi(!0);try{await AO(_,wb,O=>{Ys(O,`path:${O}`)}),me&&!ze&&n()}catch(O){Dr(O instanceof Error?O.message:C("rightSidebar.uploadFailed")),window.setTimeout(()=>Dr(null),4e3)}finally{Wi(!1)}},[ze,Ys,me,n,C]),oc=b.useCallback((_,O)=>{if(!_)return;const Z=_.includes(`
201
201
  `)?`
202
202
  `:void 0;pl(_.endsWith(`
203
203
  `)||_.endsWith(" ")?_:`${_} `,O,Z)},[pl]),Yi=b.useCallback((_,O,Z)=>{O&&pl(O.endsWith(" ")?O:`${O} `,Z??`context:${_}`,`
204
- `)},[pl]),Hs=b.useCallback(_=>{const O=lJ(Ce,_);if(!O)return;const Z=_&&Ce.trim().includes(`
205
- `),De=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let Ie=!1;const Ye=Et=>{Ie||(Ie=!0,window.removeEventListener("termdock-insert-reference-ack",mt),window.clearTimeout(St),Et?(Le(!1),Qe(""),xe&&W(!0)):(Le(!0),W(!1)))},mt=Et=>{const gr=Et.detail;gr?.nonce===De&&Ye(gr.ok===!0)},St=window.setTimeout(()=>Ye(!1),1500);window.addEventListener("termdock-insert-reference-ack",mt),Le(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:O,focus:!0,paste:Z,nonce:De}}))},[xe,Ce]),js=b.useMemo(()=>Ae?bo(Ae):C("rightSidebar.workspace"),[Ae,C]),_0=b.useMemo(()=>bo(et)||js,[et,js]),ml=b.useMemo(()=>q4(et),[et]),M=b.useMemo(()=>Ae?Ss[Ae]??[]:[],[Ss,Ae]),G=b.useMemo(()=>new Set(M.map(_=>_.path)),[M]),Re=!!(et&&G.has(et)),rt=!!(Ae&&et&&et!==Ae),Pt=!!(Ae&&hr&&hr!==Ae),Wt=et?`path:${et}`:null,Pn="context:change-audit",Fr=b.useCallback(()=>{ml&&qn(ml)},[ml,qn]),Yr=b.useCallback(()=>{cs()},[cs]),Xr=b.useCallback(()=>{et&&(Ho(et,!0),xi())},[xi,et,Ho]),Go=b.useCallback(()=>{!et||!rt||(Re?Gs(et):Vr(et,"directory"))},[rt,et,Re,Vr,Gs]),Zr=b.useCallback(_=>{qn(_),Y("")},[qn]),vi=b.useCallback(_=>{!Ae||_===Ae||(G.has(_)?Gs(_):Vr(_,"directory"))},[Vr,G,Ae,Gs]),Ki=b.useCallback(_=>{!Ae||!_||(G.has(_)?Gs(_):Vr(_,"file"))},[Vr,G,Ae,Gs]),Xi=ft(_=>_.expandedPaths),Ri=b.useMemo(()=>{const _=new Set;if(bi&&et){const O=`${et.replace(/\/+$/,"")}/`;for(const Z of Xi)Z!==et&&Z.startsWith(O)&&_.add(Z)}if(bi&&Ae&&qr){const O=qr.startsWith("/")?qr:`${Ae}/${qr}`,Z=q4(O);Z&&Z!==et&&_.add(Z)}return[..._].sort().join(`
204
+ `)},[pl]),Hs=b.useCallback(_=>{const O=dJ(Ce,_);if(!O)return;const Z=_&&Ce.trim().includes(`
205
+ `),De=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let Ie=!1;const Ye=Et=>{Ie||(Ie=!0,window.removeEventListener("termdock-insert-reference-ack",mt),window.clearTimeout(St),Et?(Le(!1),Qe(""),xe&&W(!0)):(Le(!0),W(!1)))},mt=Et=>{const gr=Et.detail;gr?.nonce===De&&Ye(gr.ok===!0)},St=window.setTimeout(()=>Ye(!1),1500);window.addEventListener("termdock-insert-reference-ack",mt),Le(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:O,focus:!0,paste:Z,nonce:De}}))},[xe,Ce]),js=b.useMemo(()=>Ae?bo(Ae):C("rightSidebar.workspace"),[Ae,C]),_0=b.useMemo(()=>bo(et)||js,[et,js]),ml=b.useMemo(()=>q4(et),[et]),M=b.useMemo(()=>Ae?Ss[Ae]??[]:[],[Ss,Ae]),G=b.useMemo(()=>new Set(M.map(_=>_.path)),[M]),Re=!!(et&&G.has(et)),rt=!!(Ae&&et&&et!==Ae),Pt=!!(Ae&&hr&&hr!==Ae),Wt=et?`path:${et}`:null,Pn="context:change-audit",Fr=b.useCallback(()=>{ml&&qn(ml)},[ml,qn]),Yr=b.useCallback(()=>{cs()},[cs]),Xr=b.useCallback(()=>{et&&(Ho(et,!0),xi())},[xi,et,Ho]),Go=b.useCallback(()=>{!et||!rt||(Re?Gs(et):Vr(et,"directory"))},[rt,et,Re,Vr,Gs]),Zr=b.useCallback(_=>{qn(_),Y("")},[qn]),vi=b.useCallback(_=>{!Ae||_===Ae||(G.has(_)?Gs(_):Vr(_,"directory"))},[Vr,G,Ae,Gs]),Ki=b.useCallback(_=>{!Ae||!_||(G.has(_)?Gs(_):Vr(_,"file"))},[Vr,G,Ae,Gs]),Xi=ft(_=>_.expandedPaths),Ri=b.useMemo(()=>{const _=new Set;if(bi&&et){const O=`${et.replace(/\/+$/,"")}/`;for(const Z of Xi)Z!==et&&Z.startsWith(O)&&_.add(Z)}if(bi&&Ae&&qr){const O=qr.startsWith("/")?qr:`${Ae}/${qr}`,Z=q4(O);Z&&Z!==et&&_.add(Z)}return sJ(_).join(`
206
206
  `)},[Xi,bi,et,Ae,qr]);b.useEffect(()=>{const _=Ri?Ri.split(`
207
- `):[];if(!e||_.length===0)return;const O=new AbortController;let Z=!1,De=0,Ie=0;ei(null);const Ye=async()=>{let mt=0;for(;!Z&&!O.signal.aborted;){if(mt>0){for(const gr of _)Ho(gr,!0);xi()}let St=null;try{ei(null),await hI(_,gr=>{$s(gr);const Ps=gr.find(fs=>fs.type==="rescan-required"&&fs.reason!=="event-storm"&&fs.reason!=="reconnected");Ps?.reason&&ei(Ps.reason)},O.signal),St=new Error("File watch stream ended")}catch(gr){St=gr}if(Z||O.signal.aborted||pc(St))return;ei(St instanceof Error?St.message:"File watching unavailable");const Et=N4[Math.min(mt,N4.length-1)];mt+=1,await new Promise(gr=>{Ie=window.setTimeout(gr,Et)})}};return De=window.setTimeout(()=>{Z||Ye()},eb),()=>{Z=!0,window.clearTimeout(De),window.clearTimeout(Ie),O.abort()}},[$s,xi,Ho,e,Ri]),b.useEffect(()=>{if(!Ae||ou.current!==Ae)return;if(Il.current===Ae){Il.current=null;return}const _=F4();n0(MT,{..._,[Ae]:{selectedRepoRoots:lr,repoTargetBranches:jn,repoBaseBranches:dr,previewEntries:sn,selectedPreviewKey:hn&&fn?gn:null,selectedPreviewFileKey:hn&&fn?Ln:null,previewDetailOpen:!!(hn&&fn),previewScrollTops:as,previewMobileSlideIndex:1,includeUncommitted:Vt,updatedAt:Date.now()}},MJ)},[fn,Vt,hn,sn,as,dr,jn,lr,Ae,Ln,gn]);const Sr=b.useMemo(()=>J4(Nn.values()),[Nn]),ds=b.useMemo(()=>{const _=new Map;for(const O of de)_.set(O.root,O);return _},[de]),si=b.useMemo(()=>he?be.find(_=>_.root===he)??null:null,[he,be]),Zi=b.useMemo(()=>qr?Array.from(Nn.values()).find(_=>_.path===qr||_.absolutePath===qr)??null:null,[Nn,qr]),Ji=b.useMemo(()=>{const _=new Map;for(const O of de)O.available&&O.context?.available&&_.set(O.root,O);return _.size===0&&te?.available&&te.root&&_.set(te.root,{id:te.root,root:te.root,relativeRoot:".",name:js,depth:0,nested:!1,available:!0,files:Array.from(Nn.values()).filter(O=>Oo(O,Ae)===te.root),context:te}),Array.from(_.values()).sort((O,Z)=>O.root===Ae?-1:Z.root===Ae?1:(O.relativeRoot||O.name).localeCompare(Z.relativeRoot||Z.name)).map(O=>{const Z=O.relativeRoot==="."?js:O.relativeRoot||O.name||bo(O.root),De=Z4(O.files),Ie=O.files.length;return{value:O.root,label:Z,meta:[O.context?.branch,Ie>0?C("rightSidebar.repoChangedCount",{count:Ie}):null,De>0?C("rightSidebar.repoStagedCount",{count:De}):null].filter(Boolean).join(" · ")}})},[Nn,te,de,js,Ae,C]),tr=b.useMemo(()=>he&&Ji.some(_=>_.value===he)?he:Zi?.repoRoot&&Ji.some(_=>_.value===Zi.repoRoot)?Zi.repoRoot:Ji.length===1||Ji.length>1?Ji[0].value:null,[he,Ji,Zi?.repoRoot]),yh=tr?ds.get(tr)??null:null,Mn=yh?.context?.available?yh.context:tr===te?.root?te:null,ks=Ji.length>0&&!tr,vh=b.useMemo(()=>ks?[]:tr?Array.from(Nn.values()).filter(_=>Oo(_,Ae)===tr):Array.from(Nn.values()),[tr,Nn,ks,Ae]),Pl=b.useMemo(()=>J4(vh),[vh]),Wo=!!(Mn?.available&&Mn.root&&tr&&Mn.root===tr),gl=tr?Ji.find(_=>_.value===tr)?.label??bo(tr):C("rightSidebar.gitRepositoryPlaceholder"),cu=Wo?Mn?.branch??"HEAD":ks?C("rightSidebar.selectRepositoryForGitActions"):Js?C("rightSidebar.gitActionRunning"):"HEAD",Ha=!!(Mn?.available&&Mn.root===tr&&Mn.status);b.useEffect(()=>{Qt.current={count:_n.length,loading:pn,loadingMore:cn,hasMore:se}},[_n.length,se,pn,cn]),b.useEffect(()=>{tt.current+=1,je.current?.abort(),ao("right-sidebar-recent-commits"),je.current=null,dn(""),ln([]),tn(!1),sr(!1),Qr(null),_e(!1)},[tr]);const Eo=b.useCallback(async(_={})=>{if(!Ae||!tr||ks)return;const O=_.reset??!1,Z=Qt.current,De=O?0:Z.count;if(!O&&(Z.loading||Z.loadingMore||!Z.hasMore))return;const Ie=tt.current+1;tt.current=Ie,je.current?.abort(),ao("right-sidebar-recent-commits");const Ye=new AbortController;je.current=Ye,O?tn(!0):sr(!0),Qr(null);try{const mt=await kI({cwd:Ae,repoRoot:tr,limit:UJ,skip:De,query:An.trim(),requestSlotId:"right-sidebar-recent-commits"},Ye.signal);if(tt.current!==Ie)return;if(!mt.available){Qr(mt.error??"Recent commits are unavailable"),O&&ln([]),_e(!1);return}ln(St=>O?mt.commits:[...St,...mt.commits]),_e(mt.hasMore)}catch(mt){if(tt.current!==Ie||pc(mt))return;Qr(mt instanceof Error?mt.message:"Failed to load recent commits"),O&&ln([]),_e(!1)}finally{je.current===Ye&&(je.current=null),tt.current===Ie&&(tn(!1),sr(!1))}},[tr,An,ks,Ae]);b.useEffect(()=>{qe&&Eo({reset:!0})},[An,Eo,qe]);const uu=b.useCallback(_=>{const O=_.currentTarget;O.scrollTop+O.clientHeight<O.scrollHeight-48||Eo({reset:!1})},[Eo]);b.useEffect(()=>{!tr||!te?.available||!As||!fi||Ha||Js||ks||Rl(tr)},[tr,te?.available,Ha,Js,As,fi,Rl,ks]),b.useEffect(()=>{!e||!Rs&&!As||!Ae||Vs()},[Rs,As,e,Vs,Ae]),b.useEffect(()=>{!e||!As||!fi||!wt||!Ae||Uo(null)},[wt,As,fi,e,Uo,Ae]);const Ug=b.useMemo(()=>{if(!he)return 0;const _=be.findIndex(O=>O.root===he);return _>=0?_+1:0},[he,be]),xl=b.useCallback(_=>{if(!_)return null;const O=Array.from(Nn.values()).filter(Z=>Oo(Z,Ae)===_).sort((Z,De)=>Z.path.localeCompare(De.path))[0];return O?xo(O):null},[Nn,Ae]),Ua=be.length>1,du=b.useMemo(()=>[{root:null,label:C("rightSidebar.allRepositories"),count:Nn.size,branch:null},...be.map(_=>({root:_.root,label:_.label,count:_.count,branch:_.branch??null}))],[Nn.size,be,C]),L0=du[Ug]??du[0],fu=!!he;b.useEffect(()=>{he&&!Ji.some(_=>_.value===he)&&(J(null),tb(Ae,null)),gt(_=>_.filter(O=>be.some(Z=>Z.root===O)))},[he,Ji,be,Ae]);const wh=b.useMemo(()=>{const _=new Set;Mn?.branch&&_.add(Mn.branch);for(const O of Mn?.branches??[])_.add(O);return Array.from(_).map(O=>({value:O,label:O,meta:O===Mn?.branch?C("rightSidebar.pushCurrentBranchBadge"):void 0}))},[Mn?.branch,Mn?.branches,C]),E0=b.useMemo(()=>{const _=new Set;Mn?.upstreamRemote&&_.add(Mn.upstreamRemote);for(const O of Mn?.remotes??[])_.add(O);return Array.from(_).map(O=>({value:O,label:O,meta:O===Mn?.upstreamRemote?C("rightSidebar.pushUpstreamBadge"):void 0}))},[Mn?.remotes,Mn?.upstreamRemote,C]),I0=E0.length>1,zg=b.useMemo(()=>{const _=[],O=new Set,Z=(Ie,Ye)=>{!Ie||O.has(Ie)||(O.add(Ie),_.push({value:Ie,label:Ie,meta:Ye}))};Z(Mn?.upstreamBranch,Mn?.upstreamBranch?C("rightSidebar.pushUpstreamBadge"):void 0),Z(Mn?.branch,Mn?.branch?C("rightSidebar.pushCurrentBranchBadge"):void 0);for(const Ie of Mn?.branches??[])Z(Ie,Ie===Mn?.branch?C("rightSidebar.pushCurrentBranchBadge"):"local");const De=Mn?.upstreamRemote;for(const Ie of Mn?.remoteBranches??[]){const Ye=Ie.indexOf("/"),mt=Ye>=0?Ie.slice(0,Ye):null,St=Ye>=0?Ie.slice(Ye+1):Ie;(!De||mt===De)&&Z(St,"remote")}return _},[Mn?.branch,Mn?.branches,Mn?.remoteBranches,Mn?.upstreamBranch,Mn?.upstreamRemote,C]),Vo=b.useMemo(()=>Ji.map(_=>{const O=ds.get(_.value);return{root:_.value,label:_.label,branch:O?.context?.branch??null}}),[Ji,ds]);b.useEffect(()=>{Vo.length!==0&&(mr(_=>{let O=!1;const Z={..._},De=new Set(Vo.map(Ie=>Ie.root));for(const Ie of Object.keys(Z))De.has(Ie)||(delete Z[Ie],O=!0);for(const Ie of Vo)!Z[Ie.root]&&Ie.branch&&(Z[Ie.root]=Ie.branch,O=!0);return O?Z:_}),en(_=>{let O=!1;const Z={..._},De=new Set(Vo.map(Ie=>Ie.root));for(const Ie of Object.keys(Z))De.has(Ie)||(delete Z[Ie],O=!0);for(const Ie of Vo){const Ye=ds.get(Ie.root)?.context;if(Z[Ie.root]&&$T(Z[Ie.root],Ye?.branch)&&(delete Z[Ie.root],O=!0),Z[Ie.root])continue;const mt=$4(Ye);mt&&(Z[Ie.root]=mt,O=!0)}return O?Z:_}))},[Vo,ds]);const nd=b.useMemo(()=>{const _=new Set(Vo.map(O=>O.root));return lr.filter(O=>_.has(O))},[lr,Vo]),rd=nd.length===0,za=b.useMemo(()=>rd?Vo:Vo.filter(_=>nd.includes(_.root)),[Vo,nd,rd]),wa=b.useMemo(()=>za.filter(_=>!!dr[_.root]?.trim()),[dr,za]),Sh=b.useMemo(()=>za.filter(_=>!dr[_.root]?.trim()),[dr,za]),Ah=b.useCallback(async _=>{if(!_||fa.current.has(_))return;const O=ds.get(_)?.context;if((O?.branches?.length??0)>0||(O?.remoteBranches?.length??0)>0||O?.upstream)return;const Z=Ae;fa.current.add(_),Gr(De=>new Set(De).add(_));try{const De=await l5(_,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${_}`);if(!De.available||!vr(Z))return;ke(Ie=>Ie.map(Ye=>Ye.root===_?{...Ye,available:!0,context:{...Ye.context,...De},error:void 0}:Ye)),mr(Ie=>Ie[_]||!De.branch?Ie:{...Ie,[_]:De.branch}),en(Ie=>{if(Ie[_])return Ie;const Ye=$4(De);return Ye?{...Ie,[_]:Ye}:Ie})}catch(De){pc(De)||console.warn("[RightSidebar] Failed to load branch audit repo details",_,De)}finally{fa.current.delete(_),Gr(De=>{const Ie=new Set(De);return Ie.delete(_),Ie})}},[ds,vr,Ae]);b.useEffect(()=>{if(Tn)for(const _ of za)Ah(_.root)},[Tn,za,Ah]),b.useEffect(()=>{!Wo||!Mn||(ca(Mn.branch||(Mn.branches?.[0]??"")),ki(Mn.upstreamRemote||(Mn.remotes?.includes("origin")?"origin":Mn.remotes?.[0]??"")),gs(Mn.upstreamBranch||Mn.branch||(Mn.branches?.[0]??"")))},[Mn,Wo]);const Th=b.useMemo(()=>{if(ks)return{text:C("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Ha||Js)return{text:C("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!Mn?.upstream)return{text:C("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const _=Mn.ahead??0,O=Mn.behind??0;return _>0&&O>0?{text:C("rightSidebar.pushDivergedCount",{ahead:_,behind:O}),className:"bg-destructive/10 text-destructive"}:_>0?{text:C("rightSidebar.pushAheadCount",{count:_}),className:"bg-accent/10 text-accent"}:O>0?{text:C("rightSidebar.pushBehindCount",{count:O}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:C("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[Mn?.ahead,Mn?.behind,Mn?.upstream,Ha,Js,ks,C]),Gg=b.useCallback(_=>{if(_&&!me){const O=_.currentTarget.getBoundingClientRect();lt({x:Math.min(O.left,window.innerWidth-352),y:Math.min(O.bottom+6,window.innerHeight-64)})}else lt(null);v?.()},[me,v]),R0=b.useCallback(()=>{lt(null),S?.()},[S]);function Ch(){if(!Ua)return null;const _=L0?.label??C("rightSidebar.allRepositories"),O=L0?.count??Nn.size,Z=bo(_)||_;return o.jsxs("button",{type:"button",onClick:Gg,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${g?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":g,title:_,children:[o.jsx(ql,{size:12,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 truncate",children:Z}),o.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${O>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:O}),o.jsx(ra,{size:12,className:"shrink-0"})]})}function Wg(){if(!g||!Ua)return null;const _=typeof window>"u"?1024:window.innerWidth,O=typeof window>"u"?768:window.innerHeight,Z=Math.max(12,Math.min(Xe?.x??_-368,_-352)),De=Math.max(12,Math.min(Xe?.y??80,O-420)),Ie=me?void 0:{left:Z,top:De};return o.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${me?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:R0,children:o.jsxs("div",{className:me?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:Ie,onClick:Ye=>Ye.stopPropagation(),children:[o.jsxs("div",{className:me?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[o.jsxs("div",{children:[o.jsx("div",{className:me?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:C("rightSidebar.repositories")}),!me&&o.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[o.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:du.length}),o.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Nn.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Nn.size})]})]}),o.jsx("button",{type:"button",onClick:R0,className:me?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":C("rightSidebar.close"),children:o.jsx(ts,{size:me?16:14})})]}),o.jsx("div",{className:me?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:du.map(Ye=>{const mt=(Ye.root??null)===he,St=bo(Ye.label)||Ye.label;return o.jsxs("button",{type:"button",onClick:()=>{qh(Ye.root),R0()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${me?"px-3 py-2":"px-2 py-1.5"} ${mt?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:Ye.label,role:"option","aria-selected":mt,children:[o.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${mt?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),o.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${mt?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:o.jsx(ql,{size:13})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:`${me?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:St}),o.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:Ye.root===null?C("rightSidebar.allRepositories"):Ye.label})]}),Ye.branch&&o.jsx("span",{className:"hidden max-w-[5.5rem] shrink min-w-0 truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline",children:Ye.branch}),o.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${Ye.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Ye.count})]},Ye.root??"all")})})]})})}function Vg(){return Wg()}function kh(_){const O=Oo(_,Ae),Z=_.absolutePath||(O?`${O}/${_.path}`:_.path),De=vm(Z,O??Ae);return{key:xo(_),path:_.path,absolutePath:Z,displayName:De.name,displayDir:De.dir,oldPath:_.oldPath,status:_.status,title:Z}}function _h(_){return _.oldPath?o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:C("rightSidebar.changedFromPath",{path:_.oldPath})}):null}function Lh(_,O){const Z=kf(_,Ae),De=`path:${Z}`,Ie=Ze===De,Ye=Fe===De,mt=Ie||Ye;return o.jsx("button",{type:"button",onClick:St=>{St.stopPropagation(),Ys(Z,De)},...Dc(jl(Z),De),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${mt?"max-w-20 px-2":"max-w-20 px-2 md:max-w-0 md:px-0 md:opacity-0 md:group-hover:max-w-20 md:group-hover:px-2 md:group-hover:opacity-100"} ${mt?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:O,children:o.jsx("span",{className:"whitespace-nowrap",children:C(Ye?"rightSidebar.copied":Ie?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function Eh(_){const O=Oo(_,Ae),Z=_.absolutePath||(O?`${O}/${_.path}`:_.path),De=f1(_),Ie=ub(_);return o.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[o.jsx(tte,{actions:De,running:cr,completed:ho?.path===Ie?ho:null}),Lh(Z,C("rightSidebar.insertThisFile"))]})}function Ih(_,O){const Z=O.root??Ae;if(!Z)return null;const De=kf(_,Z);return Lh(De,C("fileTree.insertRefTitle"))}function N0(){return o.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":C("diffViewer.view"),children:[o.jsx("button",{type:"button",onClick:()=>Uh("unified"),"aria-pressed":Cr==="unified",title:C("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Cr==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:C("diffViewer.unified")}),o.jsx("button",{type:"button",onClick:()=>Uh("split"),"aria-pressed":Cr==="split",title:C("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Cr==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:C("diffViewer.split")})]})}function Rh(){return od.map(_=>{const O=Z4(_.files.map(([,Ye])=>Ye)),Z=!he&&(od.length>1||_.label!==js),De=!!(_.root&&Ut.has(_.root));return{key:_.root??_.label,root:_.root,label:_.label,branch:_.branch,collapsed:De,files:_.files.map(([,Ye])=>kh(Ye)),header:Z?o.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${De?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[o.jsxs("button",{type:"button",onClick:()=>a1(_.root),"aria-expanded":!De,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[o.jsx("span",{className:"shrink-0 text-muted-foreground",children:De?o.jsx(_l,{size:13}):o.jsx(ra,{size:13})}),o.jsx(ql,{size:12,className:"shrink-0 text-muted-foreground"}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:_.label}),_.branch&&o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:_.branch})]}),o.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:_.files.length}),O>0&&o.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:O})]}),_.root&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:Ye=>{Ye.stopPropagation(),gd("stage-all",_.root,_.label)},disabled:!!cr,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:C("rightSidebar.stageAll"),children:C("rightSidebar.stageAll")}),o.jsx("button",{type:"button",onClick:Ye=>{Ye.stopPropagation(),gd("stash-all",_.root,_.label)},disabled:!!cr,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:C("rightSidebar.stashAll"),children:C("rightSidebar.stashAll")})]})]}):null}})}function sd(){return Nn.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:C("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:ad.map(([,_])=>{const O=Oo(_,Ae),Z=_.absolutePath||(O?`${O}/${_.path}`:_.path);return{key:xo(_),path:_.path,absolutePath:Z,status:_.status,repoRoot:O,displayName:vm(Z,O).name,displayDir:vm(Z,O).dir,auditRecords:Jn}})}function Nh(_){const O=Array.from(Nn.values()).find(Ie=>xo(Ie)===_.key),Z=O?Oo(O,Ae):null,De=jZ(Jn,Z,O?.path??_.path);return o.jsx(R2,{changeStatus:_.status,auditStatus:De,renderChangeBadge:Ie=>o.jsx(Hf,{status:Ie})})}const id=b.useCallback(_=>{if(me)return null;const O=Array.from(_.querySelectorAll("[data-diff-stream-item]"));if(O.length===0)return null;const De=_.getBoundingClientRect().top+48;let Ie=null,Ye=Number.POSITIVE_INFINITY;for(const St of O){const Et=St.getBoundingClientRect();if(Et.bottom<De)continue;const gr=Math.abs(Et.top-De);gr<Ye&&(Ie=St,Ye=gr)}const mt=Ie?.dataset.diffSelectionPath??Ie?.dataset.diffStreamItem??null;return mt?(Ec.current===mt&&ft.getState().selectedFilePath===mt||(Ec.current=mt,Rr(mt)),mt):null},[me,Rr]),qg=!!(!cr&&tr&&!ks&&(Mn?.upstream||Gi.trim()&&_i.trim())),Yg=!!(!cr&&tr&&!ks&&(Mn?.upstream||Gi.trim()&&_i.trim())),Kg=!!(!cr&&tr&&!ks&&Os.trim()&&Os.trim()!==Mn?.branch),qo=b.useMemo(()=>{const _=z.trim().toLowerCase(),O=Array.from(Nn.entries()).filter(([,Z])=>!he||Oo(Z,Ae)===he).sort(([Z],[De])=>Z.localeCompare(De));return _?O.filter(([Z,De])=>`${Z} ${De.path} ${De.status} ${De.repoRelativeRoot??""} ${De.repoName??""}`.toLowerCase().includes(_)):O},[he,Nn,z,Ae]);b.useEffect(()=>{Vp("selected_file_state",{selectedFilePath:qr,selectedChangedFilePath:Zi?.path??null,selectedChangedFileAbsolutePath:Zi?.absolutePath??null,selectedChangedFileRepoRoot:Zi?.repoRoot??null,rootPath:Ae,activeGitRepoRoot:he,rightTab:Ct,effectiveRightTab:zo,diffPaneActive:Rs,changedFiles:Nn.size,filteredChangedFiles:qo.length,gitBundleLoading:B,gitBundleLastLoadedAt:ce})},[he,Nn.size,Rs,zo,qo.length,ce,B,Ct,Ae,Zi?.absolutePath,Zi?.path,Zi?.repoRoot,qr]);const od=b.useMemo(()=>{const _=new Map;for(const O of qo){const[,Z]=O,De=Oo(Z,Ae),Ie=Jee(Z)||js,Ye=De??Ie,mt=De?ds.get(De):void 0,St=_.get(Ye)??{root:De,label:Ie,branch:mt?.context?.branch,files:[]};St.files.push(O),_.set(Ye,St)}return Array.from(_.values()).sort((O,Z)=>O.label===js?-1:Z.label===js?1:O.label.localeCompare(Z.label))},[qo,ds,js,Ae]),ad=b.useMemo(()=>{const _=[],O=new Map;for(const Z of qo)O.set(xo(Z[1]),Z);for(const Z of od){if(Z.root&&Ut.has(Z.root))continue;if(kn!=="tree"){_.push(...Z.files);continue}const De=Z.files.map(([,Ie])=>kh(Ie));for(const Ie of M9(De)){const Ye=O.get(Ie.key);Ye&&_.push(Ye)}}return _},[Ut,kn,od,qo]);b.useEffect(()=>{if(!Rs||ad.length===0||me)return;const _=[],O=()=>{const Z=document.querySelector(".termdock-diff-stream-scroller");if(Z&&id(Z))return;const De=document.querySelector("[data-diff-stream-item]"),Ie=De?.dataset.diffSelectionPath??De?.dataset.diffStreamItem??null;if(Ie){Ec.current=Ie,Rr(Ie);return}const Ye=ad[0]?.[1];if(!Ye)return;const mt=xo(Ye);Ec.current=mt,Rr(mt)};for(const Z of[80,240,600,1200])_.push(window.setTimeout(O,Z));return()=>_.forEach(Z=>window.clearTimeout(Z))},[Rs,me,ad,Rr,id]);const ld=b.useMemo(()=>{const _=mt=>`'${mt.replace(/'/g,"'\\''")}'`,O=qi.length>0?Oa:de.filter(mt=>mt.files.length>0),Z=O.length>0?O:Ae?[{root:Ae,relativeRoot:".",name:js}]:[],De=Z.length>0?Z.map(mt=>`- ${mt.relativeRoot==="."?".":mt.relativeRoot} (${mt.root})`).join(`
207
+ `):[];if(!e||_.length===0)return;const O=new AbortController;let Z=!1,De=0,Ie=0;ei(null);const Ye=async()=>{let mt=0;for(;!Z&&!O.signal.aborted;){if(mt>0){for(const gr of _)Ho(gr,!0);xi()}let St=null;try{ei(null),await hI(_,gr=>{$s(gr);const Ps=gr.find(fs=>fs.type==="rescan-required"&&fs.reason!=="event-storm"&&fs.reason!=="reconnected");Ps?.reason&&ei(Ps.reason)},O.signal),St=new Error("File watch stream ended")}catch(gr){St=gr}if(Z||O.signal.aborted||pc(St))return;ei(St instanceof Error?St.message:"File watching unavailable");const Et=N4[Math.min(mt,N4.length-1)];mt+=1,await new Promise(gr=>{Ie=window.setTimeout(gr,Et)})}};return De=window.setTimeout(()=>{Z||Ye()},eb),()=>{Z=!0,window.clearTimeout(De),window.clearTimeout(Ie),O.abort()}},[$s,xi,Ho,e,Ri]),b.useEffect(()=>{if(!Ae||ou.current!==Ae)return;if(Il.current===Ae){Il.current=null;return}const _=F4();n0(MT,{..._,[Ae]:{selectedRepoRoots:lr,repoTargetBranches:jn,repoBaseBranches:dr,previewEntries:sn,selectedPreviewKey:hn&&fn?gn:null,selectedPreviewFileKey:hn&&fn?Ln:null,previewDetailOpen:!!(hn&&fn),previewScrollTops:as,previewMobileSlideIndex:1,includeUncommitted:Vt,updatedAt:Date.now()}},PJ)},[fn,Vt,hn,sn,as,dr,jn,lr,Ae,Ln,gn]);const Sr=b.useMemo(()=>J4(Nn.values()),[Nn]),ds=b.useMemo(()=>{const _=new Map;for(const O of de)_.set(O.root,O);return _},[de]),si=b.useMemo(()=>he?be.find(_=>_.root===he)??null:null,[he,be]),Zi=b.useMemo(()=>qr?Array.from(Nn.values()).find(_=>_.path===qr||_.absolutePath===qr)??null:null,[Nn,qr]),Ji=b.useMemo(()=>{const _=new Map;for(const O of de)O.available&&O.context?.available&&_.set(O.root,O);return _.size===0&&te?.available&&te.root&&_.set(te.root,{id:te.root,root:te.root,relativeRoot:".",name:js,depth:0,nested:!1,available:!0,files:Array.from(Nn.values()).filter(O=>Oo(O,Ae)===te.root),context:te}),Array.from(_.values()).sort((O,Z)=>O.root===Ae?-1:Z.root===Ae?1:(O.relativeRoot||O.name).localeCompare(Z.relativeRoot||Z.name)).map(O=>{const Z=O.relativeRoot==="."?js:O.relativeRoot||O.name||bo(O.root),De=Z4(O.files),Ie=O.files.length;return{value:O.root,label:Z,meta:[O.context?.branch,Ie>0?C("rightSidebar.repoChangedCount",{count:Ie}):null,De>0?C("rightSidebar.repoStagedCount",{count:De}):null].filter(Boolean).join(" · ")}})},[Nn,te,de,js,Ae,C]),tr=b.useMemo(()=>he&&Ji.some(_=>_.value===he)?he:Zi?.repoRoot&&Ji.some(_=>_.value===Zi.repoRoot)?Zi.repoRoot:Ji.length===1||Ji.length>1?Ji[0].value:null,[he,Ji,Zi?.repoRoot]),yh=tr?ds.get(tr)??null:null,Mn=yh?.context?.available?yh.context:tr===te?.root?te:null,ks=Ji.length>0&&!tr,vh=b.useMemo(()=>ks?[]:tr?Array.from(Nn.values()).filter(_=>Oo(_,Ae)===tr):Array.from(Nn.values()),[tr,Nn,ks,Ae]),Pl=b.useMemo(()=>J4(vh),[vh]),Wo=!!(Mn?.available&&Mn.root&&tr&&Mn.root===tr),gl=tr?Ji.find(_=>_.value===tr)?.label??bo(tr):C("rightSidebar.gitRepositoryPlaceholder"),cu=Wo?Mn?.branch??"HEAD":ks?C("rightSidebar.selectRepositoryForGitActions"):Js?C("rightSidebar.gitActionRunning"):"HEAD",Ha=!!(Mn?.available&&Mn.root===tr&&Mn.status);b.useEffect(()=>{Qt.current={count:_n.length,loading:pn,loadingMore:cn,hasMore:se}},[_n.length,se,pn,cn]),b.useEffect(()=>{tt.current+=1,je.current?.abort(),ao("right-sidebar-recent-commits"),je.current=null,dn(""),ln([]),tn(!1),sr(!1),Qr(null),_e(!1)},[tr]);const Eo=b.useCallback(async(_={})=>{if(!Ae||!tr||ks)return;const O=_.reset??!1,Z=Qt.current,De=O?0:Z.count;if(!O&&(Z.loading||Z.loadingMore||!Z.hasMore))return;const Ie=tt.current+1;tt.current=Ie,je.current?.abort(),ao("right-sidebar-recent-commits");const Ye=new AbortController;je.current=Ye,O?tn(!0):sr(!0),Qr(null);try{const mt=await kI({cwd:Ae,repoRoot:tr,limit:WJ,skip:De,query:An.trim(),requestSlotId:"right-sidebar-recent-commits"},Ye.signal);if(tt.current!==Ie)return;if(!mt.available){Qr(mt.error??"Recent commits are unavailable"),O&&ln([]),_e(!1);return}ln(St=>O?mt.commits:[...St,...mt.commits]),_e(mt.hasMore)}catch(mt){if(tt.current!==Ie||pc(mt))return;Qr(mt instanceof Error?mt.message:"Failed to load recent commits"),O&&ln([]),_e(!1)}finally{je.current===Ye&&(je.current=null),tt.current===Ie&&(tn(!1),sr(!1))}},[tr,An,ks,Ae]);b.useEffect(()=>{qe&&Eo({reset:!0})},[An,Eo,qe]);const uu=b.useCallback(_=>{const O=_.currentTarget;O.scrollTop+O.clientHeight<O.scrollHeight-48||Eo({reset:!1})},[Eo]);b.useEffect(()=>{!tr||!te?.available||!As||!fi||Ha||Js||ks||Rl(tr)},[tr,te?.available,Ha,Js,As,fi,Rl,ks]),b.useEffect(()=>{!e||!Rs&&!As||!Ae||Vs()},[Rs,As,e,Vs,Ae]),b.useEffect(()=>{!e||!As||!fi||!wt||!Ae||Uo(null)},[wt,As,fi,e,Uo,Ae]);const Ug=b.useMemo(()=>{if(!he)return 0;const _=be.findIndex(O=>O.root===he);return _>=0?_+1:0},[he,be]),xl=b.useCallback(_=>{if(!_)return null;const O=Array.from(Nn.values()).filter(Z=>Oo(Z,Ae)===_).sort((Z,De)=>Z.path.localeCompare(De.path))[0];return O?xo(O):null},[Nn,Ae]),Ua=be.length>1,du=b.useMemo(()=>[{root:null,label:C("rightSidebar.allRepositories"),count:Nn.size,branch:null},...be.map(_=>({root:_.root,label:_.label,count:_.count,branch:_.branch??null}))],[Nn.size,be,C]),L0=du[Ug]??du[0],fu=!!he;b.useEffect(()=>{he&&!Ji.some(_=>_.value===he)&&(J(null),tb(Ae,null)),gt(_=>_.filter(O=>be.some(Z=>Z.root===O)))},[he,Ji,be,Ae]);const wh=b.useMemo(()=>{const _=new Set;Mn?.branch&&_.add(Mn.branch);for(const O of Mn?.branches??[])_.add(O);return Array.from(_).map(O=>({value:O,label:O,meta:O===Mn?.branch?C("rightSidebar.pushCurrentBranchBadge"):void 0}))},[Mn?.branch,Mn?.branches,C]),E0=b.useMemo(()=>{const _=new Set;Mn?.upstreamRemote&&_.add(Mn.upstreamRemote);for(const O of Mn?.remotes??[])_.add(O);return Array.from(_).map(O=>({value:O,label:O,meta:O===Mn?.upstreamRemote?C("rightSidebar.pushUpstreamBadge"):void 0}))},[Mn?.remotes,Mn?.upstreamRemote,C]),I0=E0.length>1,zg=b.useMemo(()=>{const _=[],O=new Set,Z=(Ie,Ye)=>{!Ie||O.has(Ie)||(O.add(Ie),_.push({value:Ie,label:Ie,meta:Ye}))};Z(Mn?.upstreamBranch,Mn?.upstreamBranch?C("rightSidebar.pushUpstreamBadge"):void 0),Z(Mn?.branch,Mn?.branch?C("rightSidebar.pushCurrentBranchBadge"):void 0);for(const Ie of Mn?.branches??[])Z(Ie,Ie===Mn?.branch?C("rightSidebar.pushCurrentBranchBadge"):"local");const De=Mn?.upstreamRemote;for(const Ie of Mn?.remoteBranches??[]){const Ye=Ie.indexOf("/"),mt=Ye>=0?Ie.slice(0,Ye):null,St=Ye>=0?Ie.slice(Ye+1):Ie;(!De||mt===De)&&Z(St,"remote")}return _},[Mn?.branch,Mn?.branches,Mn?.remoteBranches,Mn?.upstreamBranch,Mn?.upstreamRemote,C]),Vo=b.useMemo(()=>Ji.map(_=>{const O=ds.get(_.value);return{root:_.value,label:_.label,branch:O?.context?.branch??null}}),[Ji,ds]);b.useEffect(()=>{Vo.length!==0&&(mr(_=>{let O=!1;const Z={..._},De=new Set(Vo.map(Ie=>Ie.root));for(const Ie of Object.keys(Z))De.has(Ie)||(delete Z[Ie],O=!0);for(const Ie of Vo)!Z[Ie.root]&&Ie.branch&&(Z[Ie.root]=Ie.branch,O=!0);return O?Z:_}),en(_=>{let O=!1;const Z={..._},De=new Set(Vo.map(Ie=>Ie.root));for(const Ie of Object.keys(Z))De.has(Ie)||(delete Z[Ie],O=!0);for(const Ie of Vo){const Ye=ds.get(Ie.root)?.context;if(Z[Ie.root]&&$T(Z[Ie.root],Ye?.branch)&&(delete Z[Ie.root],O=!0),Z[Ie.root])continue;const mt=$4(Ye);mt&&(Z[Ie.root]=mt,O=!0)}return O?Z:_}))},[Vo,ds]);const nd=b.useMemo(()=>{const _=new Set(Vo.map(O=>O.root));return lr.filter(O=>_.has(O))},[lr,Vo]),rd=nd.length===0,za=b.useMemo(()=>rd?Vo:Vo.filter(_=>nd.includes(_.root)),[Vo,nd,rd]),wa=b.useMemo(()=>za.filter(_=>!!dr[_.root]?.trim()),[dr,za]),Sh=b.useMemo(()=>za.filter(_=>!dr[_.root]?.trim()),[dr,za]),Ah=b.useCallback(async _=>{if(!_||fa.current.has(_))return;const O=ds.get(_)?.context;if((O?.branches?.length??0)>0||(O?.remoteBranches?.length??0)>0||O?.upstream)return;const Z=Ae;fa.current.add(_),Gr(De=>new Set(De).add(_));try{const De=await l5(_,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${_}`);if(!De.available||!vr(Z))return;ke(Ie=>Ie.map(Ye=>Ye.root===_?{...Ye,available:!0,context:{...Ye.context,...De},error:void 0}:Ye)),mr(Ie=>Ie[_]||!De.branch?Ie:{...Ie,[_]:De.branch}),en(Ie=>{if(Ie[_])return Ie;const Ye=$4(De);return Ye?{...Ie,[_]:Ye}:Ie})}catch(De){pc(De)||console.warn("[RightSidebar] Failed to load branch audit repo details",_,De)}finally{fa.current.delete(_),Gr(De=>{const Ie=new Set(De);return Ie.delete(_),Ie})}},[ds,vr,Ae]);b.useEffect(()=>{if(Tn)for(const _ of za)Ah(_.root)},[Tn,za,Ah]),b.useEffect(()=>{!Wo||!Mn||(ca(Mn.branch||(Mn.branches?.[0]??"")),ki(Mn.upstreamRemote||(Mn.remotes?.includes("origin")?"origin":Mn.remotes?.[0]??"")),gs(Mn.upstreamBranch||Mn.branch||(Mn.branches?.[0]??"")))},[Mn,Wo]);const Th=b.useMemo(()=>{if(ks)return{text:C("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Ha||Js)return{text:C("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!Mn?.upstream)return{text:C("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const _=Mn.ahead??0,O=Mn.behind??0;return _>0&&O>0?{text:C("rightSidebar.pushDivergedCount",{ahead:_,behind:O}),className:"bg-destructive/10 text-destructive"}:_>0?{text:C("rightSidebar.pushAheadCount",{count:_}),className:"bg-accent/10 text-accent"}:O>0?{text:C("rightSidebar.pushBehindCount",{count:O}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:C("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[Mn?.ahead,Mn?.behind,Mn?.upstream,Ha,Js,ks,C]),Gg=b.useCallback(_=>{if(_&&!me){const O=_.currentTarget.getBoundingClientRect();lt({x:Math.min(O.left,window.innerWidth-352),y:Math.min(O.bottom+6,window.innerHeight-64)})}else lt(null);v?.()},[me,v]),R0=b.useCallback(()=>{lt(null),S?.()},[S]);function Ch(){if(!Ua)return null;const _=L0?.label??C("rightSidebar.allRepositories"),O=L0?.count??Nn.size,Z=bo(_)||_;return o.jsxs("button",{type:"button",onClick:Gg,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${g?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":g,title:_,children:[o.jsx(ql,{size:12,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 truncate",children:Z}),o.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${O>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:O}),o.jsx(ra,{size:12,className:"shrink-0"})]})}function Wg(){if(!g||!Ua)return null;const _=typeof window>"u"?1024:window.innerWidth,O=typeof window>"u"?768:window.innerHeight,Z=Math.max(12,Math.min(Xe?.x??_-368,_-352)),De=Math.max(12,Math.min(Xe?.y??80,O-420)),Ie=me?void 0:{left:Z,top:De};return o.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${me?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:R0,children:o.jsxs("div",{className:me?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:Ie,onClick:Ye=>Ye.stopPropagation(),children:[o.jsxs("div",{className:me?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[o.jsxs("div",{children:[o.jsx("div",{className:me?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:C("rightSidebar.repositories")}),!me&&o.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[o.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:du.length}),o.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${Nn.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Nn.size})]})]}),o.jsx("button",{type:"button",onClick:R0,className:me?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":C("rightSidebar.close"),children:o.jsx(ts,{size:me?16:14})})]}),o.jsx("div",{className:me?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:du.map(Ye=>{const mt=(Ye.root??null)===he,St=bo(Ye.label)||Ye.label;return o.jsxs("button",{type:"button",onClick:()=>{qh(Ye.root),R0()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${me?"px-3 py-2":"px-2 py-1.5"} ${mt?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:Ye.label,role:"option","aria-selected":mt,children:[o.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${mt?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),o.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${mt?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:o.jsx(ql,{size:13})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:`${me?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:St}),o.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:Ye.root===null?C("rightSidebar.allRepositories"):Ye.label})]}),Ye.branch&&o.jsx("span",{className:"hidden max-w-[5.5rem] shrink min-w-0 truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline",children:Ye.branch}),o.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${Ye.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:Ye.count})]},Ye.root??"all")})})]})})}function Vg(){return Wg()}function kh(_){const O=Oo(_,Ae),Z=_.absolutePath||(O?`${O}/${_.path}`:_.path),De=vm(Z,O??Ae);return{key:xo(_),path:_.path,absolutePath:Z,displayName:De.name,displayDir:De.dir,oldPath:_.oldPath,status:_.status,title:Z}}function _h(_){return _.oldPath?o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:C("rightSidebar.changedFromPath",{path:_.oldPath})}):null}function Lh(_,O){const Z=kf(_,Ae),De=`path:${Z}`,Ie=Ze===De,Ye=Fe===De,mt=Ie||Ye;return o.jsx("button",{type:"button",onClick:St=>{St.stopPropagation(),Ys(Z,De)},...Dc(jl(Z),De),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${mt?"max-w-20 px-2":"max-w-20 px-2 md:max-w-0 md:px-0 md:opacity-0 md:group-hover:max-w-20 md:group-hover:px-2 md:group-hover:opacity-100"} ${mt?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:O,children:o.jsx("span",{className:"whitespace-nowrap",children:C(Ye?"rightSidebar.copied":Ie?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function Eh(_){const O=Oo(_,Ae),Z=_.absolutePath||(O?`${O}/${_.path}`:_.path),De=f1(_),Ie=ub(_);return o.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[o.jsx(ste,{actions:De,running:cr,completed:ho?.path===Ie?ho:null}),Lh(Z,C("rightSidebar.insertThisFile"))]})}function Ih(_,O){const Z=O.root??Ae;if(!Z)return null;const De=kf(_,Z);return Lh(De,C("fileTree.insertRefTitle"))}function N0(){return o.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":C("diffViewer.view"),children:[o.jsx("button",{type:"button",onClick:()=>Uh("unified"),"aria-pressed":Cr==="unified",title:C("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Cr==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:C("diffViewer.unified")}),o.jsx("button",{type:"button",onClick:()=>Uh("split"),"aria-pressed":Cr==="split",title:C("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Cr==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:C("diffViewer.split")})]})}function Rh(){return od.map(_=>{const O=Z4(_.files.map(([,Ye])=>Ye)),Z=!he&&(od.length>1||_.label!==js),De=!!(_.root&&Ut.has(_.root));return{key:_.root??_.label,root:_.root,label:_.label,branch:_.branch,collapsed:De,files:_.files.map(([,Ye])=>kh(Ye)),header:Z?o.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${De?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[o.jsxs("button",{type:"button",onClick:()=>a1(_.root),"aria-expanded":!De,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[o.jsx("span",{className:"shrink-0 text-muted-foreground",children:De?o.jsx(_l,{size:13}):o.jsx(ra,{size:13})}),o.jsx(ql,{size:12,className:"shrink-0 text-muted-foreground"}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:_.label}),_.branch&&o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:_.branch})]}),o.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:_.files.length}),O>0&&o.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:O})]}),_.root&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:Ye=>{Ye.stopPropagation(),gd("stage-all",_.root,_.label)},disabled:!!cr,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:C("rightSidebar.stageAll"),children:C("rightSidebar.stageAll")}),o.jsx("button",{type:"button",onClick:Ye=>{Ye.stopPropagation(),gd("stash-all",_.root,_.label)},disabled:!!cr,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:C("rightSidebar.stashAll"),children:C("rightSidebar.stashAll")})]})]}):null}})}function sd(){return Nn.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:C("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:ad.map(([,_])=>{const O=Oo(_,Ae),Z=_.absolutePath||(O?`${O}/${_.path}`:_.path);return{key:xo(_),path:_.path,absolutePath:Z,status:_.status,repoRoot:O,displayName:vm(Z,O).name,displayDir:vm(Z,O).dir,auditRecords:Jn}})}function Nh(_){const O=Array.from(Nn.values()).find(Ie=>xo(Ie)===_.key),Z=O?Oo(O,Ae):null,De=jZ(Jn,Z,O?.path??_.path);return o.jsx(R2,{changeStatus:_.status,auditStatus:De,renderChangeBadge:Ie=>o.jsx(Hf,{status:Ie})})}const id=b.useCallback(_=>{if(me)return null;const O=Array.from(_.querySelectorAll("[data-diff-stream-item]"));if(O.length===0)return null;const De=_.getBoundingClientRect().top+48;let Ie=null,Ye=Number.POSITIVE_INFINITY;for(const St of O){const Et=St.getBoundingClientRect();if(Et.bottom<De)continue;const gr=Math.abs(Et.top-De);gr<Ye&&(Ie=St,Ye=gr)}const mt=Ie?.dataset.diffSelectionPath??Ie?.dataset.diffStreamItem??null;return mt?(Ec.current===mt&&ft.getState().selectedFilePath===mt||(Ec.current=mt,Rr(mt)),mt):null},[me,Rr]),qg=!!(!cr&&tr&&!ks&&(Mn?.upstream||Gi.trim()&&_i.trim())),Yg=!!(!cr&&tr&&!ks&&(Mn?.upstream||Gi.trim()&&_i.trim())),Kg=!!(!cr&&tr&&!ks&&Os.trim()&&Os.trim()!==Mn?.branch),qo=b.useMemo(()=>{const _=z.trim().toLowerCase(),O=Array.from(Nn.entries()).filter(([,Z])=>!he||Oo(Z,Ae)===he).sort(([Z],[De])=>Z.localeCompare(De));return _?O.filter(([Z,De])=>`${Z} ${De.path} ${De.status} ${De.repoRelativeRoot??""} ${De.repoName??""}`.toLowerCase().includes(_)):O},[he,Nn,z,Ae]);b.useEffect(()=>{Vp("selected_file_state",{selectedFilePath:qr,selectedChangedFilePath:Zi?.path??null,selectedChangedFileAbsolutePath:Zi?.absolutePath??null,selectedChangedFileRepoRoot:Zi?.repoRoot??null,rootPath:Ae,activeGitRepoRoot:he,rightTab:Ct,effectiveRightTab:zo,diffPaneActive:Rs,changedFiles:Nn.size,filteredChangedFiles:qo.length,gitBundleLoading:B,gitBundleLastLoadedAt:ce})},[he,Nn.size,Rs,zo,qo.length,ce,B,Ct,Ae,Zi?.absolutePath,Zi?.path,Zi?.repoRoot,qr]);const od=b.useMemo(()=>{const _=new Map;for(const O of qo){const[,Z]=O,De=Oo(Z,Ae),Ie=nte(Z)||js,Ye=De??Ie,mt=De?ds.get(De):void 0,St=_.get(Ye)??{root:De,label:Ie,branch:mt?.context?.branch,files:[]};St.files.push(O),_.set(Ye,St)}return Array.from(_.values()).sort((O,Z)=>O.label===js?-1:Z.label===js?1:O.label.localeCompare(Z.label))},[qo,ds,js,Ae]),ad=b.useMemo(()=>{const _=[],O=new Map;for(const Z of qo)O.set(xo(Z[1]),Z);for(const Z of od){if(Z.root&&Ut.has(Z.root))continue;if(kn!=="tree"){_.push(...Z.files);continue}const De=Z.files.map(([,Ie])=>kh(Ie));for(const Ie of M9(De)){const Ye=O.get(Ie.key);Ye&&_.push(Ye)}}return _},[Ut,kn,od,qo]);b.useEffect(()=>{if(!Rs||ad.length===0||me)return;const _=[],O=()=>{const Z=document.querySelector(".termdock-diff-stream-scroller");if(Z&&id(Z))return;const De=document.querySelector("[data-diff-stream-item]"),Ie=De?.dataset.diffSelectionPath??De?.dataset.diffStreamItem??null;if(Ie){Ec.current=Ie,Rr(Ie);return}const Ye=ad[0]?.[1];if(!Ye)return;const mt=xo(Ye);Ec.current=mt,Rr(mt)};for(const Z of[80,240,600,1200])_.push(window.setTimeout(O,Z));return()=>_.forEach(Z=>window.clearTimeout(Z))},[Rs,me,ad,Rr,id]);const ld=b.useMemo(()=>{const _=mt=>`'${mt.replace(/'/g,"'\\''")}'`,O=qi.length>0?Oa:de.filter(mt=>mt.files.length>0),Z=O.length>0?O:Ae?[{root:Ae,relativeRoot:".",name:js}]:[],De=Z.length>0?Z.map(mt=>`- ${mt.relativeRoot==="."?".":mt.relativeRoot} (${mt.root})`).join(`
208
208
  `):`- ${Ae?".":""}`,Ie=Z.length>0?Z.map(mt=>` td audit-export ${_(mt.root)}`).join(`
209
209
  `):" td audit-export",Ye=Z.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${Ae??""}`,"目标仓库:",De,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",Ie,"2. 先检查 audit-export 输出的 coverage[]:确认 untrackedFiles 是否为空、未跟踪文件是否已经出现在 hunks[].filePath 中;如果 coverage 显示存在未跟踪文件但 hunks[] 未包含对应文件,必须汇报导出异常,不要假装已解释。","3. 读取 audit-export 输出的全部 hunks[].diff,包含 tracked 与 untracked hunks;先理解整批改动的业务目标、行为变化、文件分工和跨 hunk 依赖。","4. 以 audit-export 内置 diff 为分析依据。仅在单个 hunk 信息不足时执行:td audit-show <hunkId> <对应仓库绝对路径>","5. 在 ~/.termdock/change-audit/ 生成批量 payload JSON。"," mkdir -p ~/.termdock/change-audit","6. payload 顶层字段:workspaceRoot、repoRoot、generatedBy、walkthrough、records[]。","7. walkthrough 必须先生成,用三层结构说明整批改动:highlights[] 面向不了解代码的人讲“改了什么/带来什么效果”;nodes[]/edges[] 表达关键链路;risks[]/checks[] 写真实风险和验证。节点可带 anchor,点击后会跳到对应 diff。","8. records[] 必须覆盖每个 hunk 内的多个 section,而不是只写 hunk 总结;从 audit-export hunk 原样复制 filePath、oldPath、newPath、hunkHeader、hunkIndex、fingerprint;如果解释的是 section,额外填写 sectionIndex 和 sectionFingerprint;补充 summary、explanation。","9. 写入 payload 后批量注入:",Ye,'10. 少量 hunk 或临时补单条时使用:printf "%s\\n" "这里写该 hunk 的改动意义" | td audit-explain <hunkId> <对应仓库绝对路径>',"11. 注入成功后清理本次 payload:rm -f ~/.termdock/change-audit/payload*.json","","payload.walkthrough 示例字段:","{",' "title": "一句话标题",',' "summary": "整批改动的目的和结果",',' "highlights": [{ "what": "改了什么", "effect": "用户或系统得到什么", "tag": "体验" }],',' "nodes": [{ "id": "n1", "title": "节点标题", "kind": "ui", "business": "零上下文业务解释", "anchor": { "repoRoot": "<repoRoot>", "filePath": "<filePath>", "hunkIndex": 0, "hunkFingerprint": "<fingerprint>", "sectionIndex": 0, "sectionFingerprint": "<sectionFingerprint>" } }],',' "edges": [{ "from": "n1", "to": "n2", "label": "调用/传递/消费", "desc": "这条关系的业务含义" }],',' "risks": [{ "title": "真实风险或口径疑问", "anchor": { "filePath": "<filePath>" } }],',' "checks": ["可执行验证动作"]',"}","","写作标准:","- summary:一句话概括该 hunk 在整批改动中的职责。","- explanation:自包含说明业务链路、该 hunk 的作用、解决的问题、与其它 hunk 的关系。","- walkthrough.highlights 必须大白话,不要堆文件名/函数名;只看 highlights 应该知道这次改动干嘛。","- walkthrough.nodes 优先对应方法、关键业务步骤或关键 section;每个有 anchor 的节点必须能跳回真实 diff。","- 面向不了解本轮对话的 AI 编写,补足必要上下文。","- 输出高信息量结论;避免铺垫、套话、流程复述、泛泛风险、逐行翻译 diff。","","完成条件:汇报每个目标仓库已注入的 hunk 数和总数。"].join(`
210
210
  `)},[qi.length,Oa,de,js,Ae]),Mh=b.useCallback((_="generate")=>{if(Ua&&dt.length===0&&!he){nn(!0);return}const O=_==="generate"?ld:[_==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",ld].join(`
@@ -216,9 +216,9 @@ ${jt}
216
216
  `)},[Vt,wa,dr,jn,Ae]),n1=b.useCallback((_="generate")=>{const O=_==="generate"?D0:[_==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",D0].join(`
217
217
  `);Yi(C("rightSidebar.branchAuditShort"),O,`context:branch-audit-scope:${_}`),s||n()},[D0,Yi,n,s,C]),Ph=b.useCallback(async()=>{if(!Ae||wa.length===0)return;const _=Ae;bt(!0),at(null),Kn(null),Rt(null);try{const O=await Promise.all(wa.map(async St=>{const Et=dr[St.root]?.trim();if(!Et)throw new Error(C("rightSidebar.branchAuditMissingBase",{repo:St.label}));const gr=(jn[St.root]||St.branch||"").trim();return TI({cwd:Ae,repoRoot:St.root,base:Et,head:gr&&gr!==St.branch?gr:null,includeUncommitted:Vt,requestSlotId:`right-sidebar-branch-preview:${St.root}`})}));if(!vr(_))return;const Z=O.find(St=>!St.available);if(Z){at(Z.error??"Branch diff is unavailable");return}const De=O.length===1?O[0]:{available:!0,workspaceRoot:Ae,repoRoot:Ae,baseRef:O.map(St=>St.baseRef??St.baseBranch).filter(Boolean).join(", "),currentBranch:O.map(St=>St.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:O.map(St=>St.headRef).filter(Boolean).join(", "),diffFingerprint:O.map(St=>St.diffFingerprint).filter(Boolean).join("+"),stat:O.map(St=>St.stat).filter(Boolean).join(`
218
218
  `),files:O.flatMap((St,Et)=>{const gr=wa[Et];return(St.files??[]).map(Ps=>`${gr?.label??St.repoRoot??"repo"}/${Ps}`)}),hunks:O.flatMap((St,Et)=>{const Ps=wa[Et]?.label??St.repoRoot??"repo";return(St.hunks??[]).map(fs=>({...fs,filePath:`${Ps}/${fs.filePath}`,oldPath:fs.oldPath?`${Ps}/${fs.oldPath}`:fs.oldPath,newPath:fs.newPath?`${Ps}/${fs.newPath}`:fs.newPath}))}),commits:O.flatMap(St=>St.commits??[]),commitCount:O.reduce((St,Et)=>St+(Et.commitCount??Et.commits?.length??0),0),diff:O.map(St=>St.diff).filter(Boolean).join(`
219
- `),truncated:O.some(St=>St.truncated)};if((De.hunks??[]).length===0){at(C("rightSidebar.branchAuditDiffEmpty"));return}const Ie=Date.now(),Ye=["preview",De.repoRoot??Ae,De.baseRef??De.baseBranch??"",De.currentBranch??"",De.headRef??"",De.diffFingerprint??Ie].join("\0"),mt=wa.length===1?wa[0].label:`${wa.length} repos`;Kn(De),zn(St=>[{key:Ye,diff:De,repoLabel:mt,createdAt:Ie},...St.filter(Et=>Et.key!==Ye)].slice(0,8)),Bt(St=>St[Ye]===void 0?St:{...St,[Ye]:0}),fr(Ye),ns(De.hunks?.[0]?`${De.hunks[0].filePath}\0${De.hunks[0].hunkHeader}\0${De.hunks[0].hunkIndex}`:null),Un(!0)}catch(O){if(!vr(_)||pc(O))return;at(O instanceof Error?O.message:"Failed to load branch diff")}finally{vr(_)&&bt(!1)}},[Vt,wa,dr,jn,vr,Ae,C]),Bh=b.useCallback(_=>{Kn(_.diff),at(null),fr(_.key),ns(_.diff.hunks?.[0]?`${_.diff.hunks[0].filePath}\0${_.diff.hunks[0].hunkHeader}\0${_.diff.hunks[0].hunkIndex}`:null),Un(!0)},[]),r1=b.useCallback(_=>{zn(O=>O.filter(Z=>Z.key!==_)),Bt(O=>{if(!(_ in O))return O;const Z={...O};return delete Z[_],Z}),gn===_&&(fr(null),Kn(null),Un(!1))},[gn]),s1=b.useCallback(_=>{const O=Pc.find(Z=>Z.key===_);O&&(Kn(null),at(null),fr(_),ns(O.records[0]?.filePath??null),Un(!0))},[Pc]),i1=b.useCallback(async _=>{if(!Ae||!tr)return;const[O]=_.split(/\s+/);if(O){Ot(O),ar(null),Rt(null);try{const Z=await CI({cwd:Ae,repoRoot:tr,commit:O,requestSlotId:"right-sidebar-commit-diff"});if(!Z.available){ar(Z.error??"Commit diff is unavailable");return}Rt(Z);const De=Z.hunks?.[0];st(De?`${De.filePath}\0${De.hunkHeader}\0${De.hunkIndex}`:null)}catch(Z){ar(Z instanceof Error?Z.message:"Failed to load commit diff")}finally{Ot(null)}}},[tr,Ae]),o1=b.useCallback(_=>{if(!hn||!gn)return;const O=Math.max(0,Math.round(_));Bt(Z=>Math.abs((Z[gn]??0)-O)<24?Z:{...Z,[gn]:O})},[hn,gn]);b.useEffect(()=>{!me||!fn||!hn||Nl(1)},[fn,hn,me,Nl]);const Fh=b.useCallback(_=>{_&&Li(O=>NZ(O,_))},[]),Oh=gi.key===qr?gi.key:null,fd=b.useCallback(_=>{const O=ft.getState(),Z=dte();Vp("select_diff_file",{interactionId:Z,path:_,previousSelectedFilePath:O.selectedFilePath,rootPath:O.rootPath,activeGitRepoRoot:he,changedFiles:O.changedFiles.size,gitBundleLoading:O.gitBundleLoading,gitBundleLastLoadedAt:O.gitBundleLastLoadedAt,rightTab:O.rightTab}),Rr(_),On("diff"),me&&_&&Nl(1),Fh(_),queueMicrotask(()=>{const De=ft.getState();Vp("select_diff_file_after",{interactionId:Z,requestedPath:_,selectedFilePath:De.selectedFilePath,rootPath:De.rootPath,rightTab:De.rightTab,changedFiles:De.changedFiles.size,activeGitRepoRoot:he})})},[he,me,Fh,Rr,On,Nl]),Qh=b.useCallback(_=>{const O=Array.from(Nn.values()).find(Z=>{const De=Oo(Z,Ae),Ie=xo(Z);return Z.path===_.filePath||Ie===_.filePath||Z.absolutePath===_.filePath||(De?`${De}/${Z.path}`===_.filePath:!1)||_.repoRoot&&De===_.repoRoot&&Z.path===_.filePath});if(O){fd(xo(O)),window.setTimeout(()=>_u(_),90),window.setTimeout(()=>_u(_),320),window.setTimeout(()=>_u(_),760);return}_u(_)},[Nn,Ae,fd]),$h=b.useCallback(({slideToDetail:_,fullscreen:O,toggleFullscreen:Z}={})=>Se.length>0?o.jsx(ng,{walkthroughs:Se,repoRoot:he,fullscreen:O,onToggleFullscreen:Z,onNavigate:De=>{me&&window.requestAnimationFrame(()=>_?.()),Qh(De)}}):o.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[o.jsx(ru,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),C("rightSidebar.changeWalkthroughEmpty")]}),[he,Se,Qh,me,C]),a1=b.useCallback(_=>{_&&_t(O=>{const Z=new Set(O);return Z.has(_)?Z.delete(_):Z.add(_),nb(Xx,Z),Z})},[]),Hh=b.useCallback(_=>{Ur(O=>{const Z=new Set(O);return Z.has(_)?Z.delete(_):Z.add(_),nb(L4,Z),Z})},[]),hd=b.useCallback(_=>{Ft(_),$n(ET,_)},[]);b.useEffect(()=>{fu||kn!=="ai"||hd("tree")},[kn,hd,fu]);const j0=b.useCallback(()=>{Gt(_=>{const O=!_;return $n(IT,O),O})},[]),Uh=b.useCallback(_=>{nr(_),$n(RT,_)},[]),{whitespace:zh,context:pd}=uT(),Gh=b.useMemo(()=>({algorithm:"histogram",whitespace:zh,context:pd}),[zh,pd]),Wh=b.useCallback(_=>{q(_),$n(NT,_)},[]),md=b.useCallback(async(_,O,Z,De)=>{let Ie=_;for(;Ie.ok&&Ie.status==="running";)await new Promise(mt=>window.setTimeout(mt,1500)),Ie=await f5({jobId:Ie.jobId,cwd:O.cwd,action:O.action});if(!Ie.ok)throw new Error("Git action status is unavailable");if(Ie.status==="error")throw new Error(Ie.error||Ie.message||"Git action failed");const Ye={action:O.action,path:De,label:Z};return rs(Ye),window.setTimeout(()=>rs(mt=>mt?.action===Ye.action&&mt.path===Ye.path?null:mt),1400),Ie},[]),wi=b.useCallback(async(_,O,Z)=>{const De=Ae;Ae&&ur.current.delete(Ae),Dr(null),rs(null),pi({action:_.action,path:Z});try{const Ie=await EI(_),Ye=await md(Ie,_,O,Z);if(!vr(De))return!1;const mt=Ae?await ap(Ae,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Pd(Ae)}).catch(()=>Ye.bundle):Ye.bundle;return vr(De)?(mt&&pa(mt,{reloadDiff:!0,cacheOnly:!0}),Mr(null),!0):!1}catch(Ie){return rs(null),Dr(C("rightSidebar.gitActionFailed",{message:Ie instanceof Error?Ie.message:"Unknown error"})),!1}finally{vr(De)&&pi(null)}},[pa,vr,Ae,C,md]),Vh=b.useCallback(async _=>{const O=Ae,Z=await II(_);if(!vr(O))return;const De=Ae?await ap(Ae,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Pd(Ae)}).catch(()=>Z.bundle):Z.bundle;vr(O)&&De&&pa(De,{reloadDiff:!0,cacheOnly:!0})},[pa,vr,Ae]),gd=b.useCallback((_,O,Z)=>{if(O){if(_==="stage-all"){wi({action:"stage-all",cwd:O},C("rightSidebar.stageAll"),`repo:${O}`);return}Mr({kind:"stash-all",repoRoot:O,repoLabel:Z})}},[wi,C]),qh=b.useCallback(_=>{J(_),tb(Ae,_),ca(""),ki(""),gs(""),Rr(xl(_)),As||On("diff")},[xl,As,Ae,Rr,On]),l1=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=Os.trim();!_||_===Mn?.branch||await wi({action:"switch-branch",cwd:tr,branch:_},C("rightSidebar.switchBranch"))},[Mn?.branch,tr,ks,wi,Os,C]),Yh=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=aa.trim();if(!_)return;await wi({action:"commit",cwd:tr,message:_},C("rightSidebar.commitChanges"))&&la("")},[tr,aa,ks,wi,C]),c1=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=Gi.trim(),O=_i.trim();await wi({action:"push",cwd:tr,..._?{remote:_}:{},...O?{branch:O}:{}},C("rightSidebar.pushChanges"))},[tr,_i,Gi,ks,wi,C]),xd=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=Gi.trim(),O=_i.trim();await wi({action:"pull",cwd:tr,..._?{remote:_}:{},...O?{branch:O}:{}},C("rightSidebar.pullChanges"))},[tr,_i,Gi,ks,wi,C]);b.useEffect(()=>{if(!As||!tr||cr)return;let _=!1;const O={push:C("rightSidebar.pushChanges"),pull:C("rightSidebar.pullChanges"),commit:C("rightSidebar.commitChanges"),"switch-branch":C("rightSidebar.switchBranch"),"stage-all":C("rightSidebar.stageAll"),"stash-all":C("rightSidebar.stashAll")};return(async()=>{for(const Z of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(_)return;const De=await f5({cwd:tr,action:Z}).catch(()=>null);if(!De?.ok||De.status!=="running")continue;const Ie={action:Z,cwd:tr},Ye=O[Z]??Z;pi({action:Z});try{const mt=await md(De,Ie,Ye);if(_||!vr(Ae))return;const St=Ae?await ap(Ae,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Pd(Ae)}).catch(()=>mt.bundle):mt.bundle;St&&pa(St,{reloadDiff:!0,cacheOnly:!0})}catch(mt){_||Dr(C("rightSidebar.gitActionFailed",{message:mt instanceof Error?mt.message:"Unknown error"}))}finally{_||pi(null)}return}})(),()=>{_=!0}},[tr,pa,As,vr,Ae,cr,C,md]);const P0=ho?.action==="commit",pu=ho?.action==="switch-branch",B0=ho?.action==="pull",F0=ho?.action==="push",bd=As||Co,O0=rd?C("rightSidebar.changeAuditScopeAll"):za.length===1?za[0].label:`${za.length} repos`,u1=za.length>0,Kh=wa.length>0,Xh=Ae?o.jsx(W4,{open:Tn,onOpenChange:mn,showScopePicker:!0,selectedAll:rd,repos:Vo,selectedRoots:nd,onToggleRepo:Zg,onGenerate:()=>n1(M0?"regenerate":"generate"),disabled:!u1,generateDisabled:!Kh,inserted:Ze?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:C(M0?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:C("rightSidebar.inserted"),title:C("rightSidebar.branchAuditGenerateTitle"),ariaLabel:C("rightSidebar.branchAuditShort"),scopeTitle:C("rightSidebar.changeAuditScopeLabel"),scopeLabel:O0,allLabel:C("rightSidebar.changeAuditScopeAll"),generateLabel:C(M0?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Ph()},secondaryDisabled:!Kh||rn,secondaryLabel:C("rightSidebar.branchAuditViewDiff"),secondaryTitle:C("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:rn,loading:Xn.size>0,statusTitle:Xn.size>0?C("rightSidebar.branchCandidatesLoading"):void 0,extraContent:o.jsxs("div",{className:"mb-2 space-y-1.5",children:[o.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block font-medium",children:C("rightSidebar.includeUncommitted")}),o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:C("rightSidebar.includeUncommittedHint")})]}),o.jsx("input",{type:"checkbox",checked:Vt,onChange:_=>ir(_.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),Sh.length>0&&o.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:C("rightSidebar.missingBaseReposSkipped",{repositories:Sh.map(_=>_.label).join($==="zh"?"、":", ")})})]}),renderRepoExtra:_=>{const O=ds.get(_.root),Z=[],De=new Set,Ie=(Et,gr)=>{!Et||De.has(Et)||(De.add(Et),Z.push({value:Et,label:Et,meta:gr}))};Ie(jn[_.root]||O?.context?.branch,C("rightSidebar.pushCurrentBranchBadge"));for(const Et of O?.context?.branches??[])Ie(Et,Et===O?.context?.branch?C("rightSidebar.pushCurrentBranchBadge"):C("rightSidebar.localBranch"));for(const Et of O?.context?.remoteBranches??[])Ie(Et,C("rightSidebar.remoteBranch"));const Ye=[],mt=new Set,St=(Et,gr)=>{!Et||mt.has(Et)||(mt.add(Et),Ye.push({value:Et,label:Et,meta:gr}))};St(dr[_.root],dr[_.root]?C("rightSidebar.pushUpstreamBadge"):void 0),St(O?.context?.upstream,O?.context?.upstream?C("rightSidebar.pushUpstreamBadge"):void 0);for(const Et of O?.context?.remoteBranches??[])St(Et,"remote");for(const Et of O?.context?.branches??[])St(Et,Et===O?.context?.branch?C("rightSidebar.pushCurrentBranchBadge"):"local");return o.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[o.jsx(jd,{label:C("rightSidebar.currentBranchLabel"),value:jn[_.root]||O?.context?.branch||"",options:Z,placeholder:C("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:C("rightSidebar.switchBranchSearchPlaceholder"),emptyText:C("rightSidebar.switchNoBranches"),onChange:Et=>{mr(gr=>({...gr,[_.root]:Et}))}}),o.jsx(jd,{label:C("rightSidebar.branchAuditBaseLabel"),value:dr[_.root]||"",options:Ye,placeholder:C("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:C("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:C("rightSidebar.branchAuditBaseEmpty"),onChange:Et=>{en(gr=>({...gr,[_.root]:Et}))}})]})}}):null,Zh=xf(Jn.reduce((_,O)=>Math.max(_,O.injectedAt??0),0),$),d1=Ae?o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("button",{type:"button",onClick:()=>Lt(_=>{const O=!_;return $n(Zx,O),O}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":wt,children:[o.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:o.jsx(ru,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:C("rightSidebar.branchAuditTitle")}),o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:O0})]}),o.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${wt?"rotate-90":""}`,children:o.jsx(_l,{size:13})})]}),wt&&o.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[C("rightSidebar.changeAuditScopeLabel"),": ",O0]}),Xh]}),Tt&&o.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Tt}),o.jsxs("div",{className:"mt-2 space-y-1.5",children:[sn.map(_=>o.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${gn===_.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[o.jsxs("button",{type:"button",onClick:()=>Bh(_),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:_.repoLabel}),o.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[_.diff.hunks?.length??0," hunk"]})]}),o.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.diff.currentBranch??"HEAD"}),o.jsx("span",{className:"text-muted-foreground/60",children:"→"}),o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.diff.baseRef??_.diff.baseBranch}),o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:C("rightSidebar.branchAuditViewDiff")})]}),xf(_.createdAt,$)&&o.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:xf(_.createdAt,$)})]}),o.jsx("button",{type:"button",onClick:()=>r1(_.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:C("common.delete"),"aria-label":C("common.delete"),children:o.jsx($i,{size:12})})]},_.key)),Pc.length>0?Pc.slice(0,Math.max(0,8-sn.length)).map(_=>o.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${gn===_.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[o.jsxs("button",{type:"button",onClick:()=>s1(_.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:_.repoLabel}),o.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[_.records.length," hunk"]})]}),o.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.branchName??"HEAD"}),o.jsx("span",{className:"text-muted-foreground/60",children:"→"}),o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.baseRef}),_.diffFingerprint&&o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.diffFingerprint})]}),xf(_.latestInjectedAt,$)&&o.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:C("rightSidebar.branchAuditGeneratedAt",{time:xf(_.latestInjectedAt,$)??""})})]}),o.jsx("button",{type:"button",onClick:()=>{jh(_)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:C("rightSidebar.branchAuditClearTitle"),"aria-label":C("rightSidebar.branchAuditClearTitle"),children:o.jsx($i,{size:12})})]},_.key)):sn.length===0?o.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:C("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Jh=fi&&Ae&&Ha?o.jsxs("div",{className:bd?"overflow-visible":"overflow-hidden",children:[d1,o.jsxs("button",{type:"button",onClick:()=>{As||zi(_=>{const O=!_;return O&&tr&&!Ha&&!Js&&Rl(tr),O})},"aria-expanded":bd,className:`group flex w-full items-center gap-2 px-1 py-1.5 text-left transition ${As?"cursor-default":"rounded-lg hover:bg-surface-2 active:scale-[0.99]"}`,children:[o.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:o.jsx(ql,{size:14})}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:C("rightSidebar.gitQuickActions")}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[o.jsxs("span",{className:`inline-flex min-w-[4.5rem] items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${Pl.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[Js&&o.jsx(Fn,{size:10,className:"animate-spin"}),Pl.staged>0?C("rightSidebar.stagedCount",{count:Pl.staged}):C("rightSidebar.noStagedChangesShort")]}),!As&&o.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${bd?"rotate-90":""}`,children:o.jsx(_l,{size:13})})]})]}),bd&&o.jsxs("div",{className:"space-y-0",children:[Ji.length>1&&o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.gitRepositorySectionTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:gl})]})}),o.jsx(jd,{label:C("rightSidebar.gitRepositoryLabel"),value:tr??"",options:Ji,placeholder:C("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:C("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:C("rightSidebar.gitRepositoryEmpty"),disabled:!!cr,onChange:_=>{qh(_||null)}}),ks&&o.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:C("rightSidebar.selectRepositoryForGitActions")})]}),o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.branchSectionTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:cu})]}),o.jsxs("button",{type:"button",onClick:()=>{l1()},disabled:!Kg,className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${pu?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:C("rightSidebar.switchBranch"),children:[o.jsx("span",{className:cr?.action==="switch-branch"||pu?"opacity-0":"",children:C("rightSidebar.switchBranch")}),cr?.action==="switch-branch"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),pu&&cr?.action!=="switch-branch"&&o.jsx("span",{className:"absolute",children:"✓"})]})]}),o.jsx(jd,{label:C("rightSidebar.currentBranchLabel"),value:Os,options:wh,placeholder:C("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:C("rightSidebar.switchBranchSearchPlaceholder"),emptyText:C("rightSidebar.switchNoBranches"),disabled:!!cr,onChange:ca})]}),o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.commitSectionTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:ks?C("rightSidebar.selectRepositoryForGitActions"):Pl.staged>0?C("rightSidebar.commitReadyHint",{count:Pl.staged}):C("rightSidebar.commitNeedsStaged")})]}),o.jsxs("button",{type:"button",onClick:()=>{Yh()},disabled:!!cr||ks||Pl.staged===0||!aa.trim(),className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition active:scale-95 ${P0?"bg-accent/10 text-accent disabled:bg-accent/10 disabled:text-accent":"bg-primary text-primary-foreground hover:bg-primary/90 disabled:bg-surface-2 disabled:text-muted-foreground"} disabled:cursor-not-allowed`,title:ks?C("rightSidebar.selectRepositoryForGitActions"):Pl.staged===0?C("rightSidebar.commitNeedsStaged"):C("rightSidebar.commitChanges"),children:[o.jsx("span",{className:cr?.action==="commit"||P0?"opacity-0":"",children:C("rightSidebar.commitChanges")}),cr?.action==="commit"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),P0&&cr?.action!=="commit"&&o.jsx("span",{className:"absolute",children:"✓"})]})]}),o.jsx("input",{value:aa,onChange:_=>la(_.target.value),onKeyDown:_=>{(_.metaKey||_.ctrlKey)&&_.key==="Enter"&&(_.preventDefault(),Yh())},placeholder:C("rightSidebar.commitMessagePlaceholder"),disabled:!!cr,className:"w-full rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-[12px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary/35 focus:ring-1 focus:ring-primary/25 disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("button",{type:"button",onClick:()=>ct(_=>!_),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":qe,children:[o.jsx("span",{className:"min-w-0 text-[11px] font-semibold text-foreground",children:C("rightSidebar.recentCommitsTitle")}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[pn&&o.jsx(Fn,{size:12,className:"animate-spin text-muted-foreground"}),o.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${qe?"rotate-90":""}`,children:o.jsx(_l,{size:13})})]})]}),qe&&o.jsxs("div",{className:"mt-2 space-y-2",children:[o.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[o.jsx(Jl,{size:12,className:"shrink-0"}),o.jsx("input",{value:jt,onChange:_=>dn(_.target.value),placeholder:C("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),jt&&o.jsx("button",{type:"button",onClick:()=>dn(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":C("rightSidebar.clearSearch"),children:o.jsx(ts,{size:12})})]}),o.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:uu,children:[_n.length>0?_n.map(_=>{const[O,...Z]=_.split(/\s+/),De=Z.join(" ")||_;return o.jsxs("button",{type:"button",onClick:()=>{i1(_)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:De,children:[o.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:O}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:De,children:De}),vn===O&&o.jsx(Fn,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},_)}):pn?o.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:C("common.loading")}):o.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:C("rightSidebar.recentCommitsEmpty")}),cn&&o.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:o.jsx(Fn,{size:12,className:"animate-spin"})}),se&&!cn&&_n.length>0&&o.jsx("button",{type:"button",onClick:()=>{Eo({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:C("rightSidebar.recentCommitsLoadMore")})]})]}),Jt&&o.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Jt}),ps&&o.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:ps})]}),o.jsxs("div",{className:"px-1 py-3",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.pushSectionTitle")}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[o.jsxs("button",{type:"button",onClick:()=>{xd()},disabled:!qg,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${B0?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:C("rightSidebar.pullChanges"),children:[o.jsx("span",{className:cr?.action==="pull"||B0?"opacity-0":"",children:C("rightSidebar.pullChanges")}),cr?.action==="pull"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),B0&&cr?.action!=="pull"&&o.jsx("span",{className:"absolute",children:"✓"})]}),o.jsxs("button",{type:"button",onClick:()=>{c1()},disabled:!Yg,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${F0?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:C("rightSidebar.pushChanges"),children:[o.jsx("span",{className:cr?.action==="push"||F0?"opacity-0":"",children:C("rightSidebar.pushChanges")}),cr?.action==="push"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),F0&&cr?.action!=="push"&&o.jsx("span",{className:"absolute",children:"✓"})]})]})]}),o.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${Th.className}`,title:Mn?.upstream??void 0,children:[o.jsx("span",{className:"truncate font-medium",children:Th.text}),o.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:Mn?.upstream??""})]}),o.jsxs("div",{className:`grid gap-1.5 ${I0?"grid-cols-2":"grid-cols-1"}`,children:[I0&&o.jsx(jd,{label:C("rightSidebar.pushRemoteLabel"),value:Gi,options:E0,placeholder:C("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:C("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:C("rightSidebar.pushNoRemotes"),disabled:!!cr,onChange:ki}),o.jsx(jd,{label:C("rightSidebar.pushBranchLabel"),value:_i,options:zg,placeholder:C("rightSidebar.pushBranchPlaceholder",{branch:Mn?.branch??"HEAD"}),searchPlaceholder:C("rightSidebar.pushBranchSearchPlaceholder"),emptyText:C("rightSidebar.pushNoBranches"),disabled:!!cr,onChange:gs})]})]})]})]}):null,f1=b.useCallback(_=>{const O=Oo(_,Ae);if(!O)return[];const Z=ub(_),De=[];return _.canStage&&De.push({key:"stage-file",label:C("rightSidebar.stageFile"),onClick:()=>{wi({action:"stage-file",cwd:O,paths:[_.path]},C("rightSidebar.stageFile"),Z)}}),_.canUnstage&&De.push({key:"unstage-file",label:C("rightSidebar.unstageFile"),onClick:()=>{wi({action:"unstage-file",cwd:O,paths:[_.path]},C("rightSidebar.unstageFile"),Z)}}),_.canStash&&De.push({key:"stash-file",label:C("rightSidebar.stashFile"),onClick:()=>{wi({action:"stash-file",cwd:O,paths:[_.path]},C("rightSidebar.stashFile"),Z)}}),_.canRestoreWorktree&&De.push({key:"restore-worktree-file",label:C("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Mr({kind:"restore",file:_,phrase:""})}),De},[Ae,wi,C]),h1=b.useCallback(()=>{if(c){p?.();return}ui(0),Ba.current?.slideTo(0),ls(!1),Oe(null)},[p,c]),ep=b.useCallback(_=>{if(Y(""),qn(null),Rr(null),Oe(null),fe(O=>({path:_,nonce:(O?.nonce??0)+1})),me){c&&p?.(),ui(0),Ba.current?.slideTo(0),ls(!1);return}},[me,p,c,Rr,qn]);b.useEffect(()=>{e||(Yt(!1),on(!1))},[e]),b.useEffect(()=>{if(!yt&&!Mt)return;const _=O=>{O instanceof globalThis.KeyboardEvent&&O.key!=="Escape"||O instanceof globalThis.MouseEvent&&O.target instanceof Node&&(xr.current?.contains(O.target)||Cn.current?.contains(O.target))||(Yt(!1),on(!1))};return window.addEventListener("mousedown",_),window.addEventListener("keydown",_),()=>{window.removeEventListener("mousedown",_),window.removeEventListener("keydown",_)}},[Mt,yt]);const bl=o.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[o.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[o.jsx("button",{type:"button",onClick:Fr,disabled:!ml,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":C("rightSidebar.parentFolder"),title:C("rightSidebar.parentFolder"),children:o.jsx(xg,{size:14})}),o.jsx("button",{type:"button",onClick:Yr,disabled:!Ae||hr===Ae,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":C("rightSidebar.backToProjectRoot"),title:C("rightSidebar.backToProjectRoot"),children:o.jsx(S5,{size:14})}),o.jsx("button",{type:"button",onClick:Xr,disabled:!et,className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${mi?"text-destructive":"text-muted-foreground"}`,"aria-label":C("rightSidebar.refreshFiles"),title:mi?C("rightSidebar.fileWatchUnavailable",{message:mi}):C("rightSidebar.refreshFiles"),children:o.jsx(Us,{size:13})}),o.jsx("div",{className:"min-w-0 flex-1 px-1",title:et??void 0,children:o.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[o.jsx("span",{className:"truncate",children:_0}),Zt==="modified"&&o.jsx("span",{className:"inline-flex shrink-0 text-primary",title:C("fileTree.sortedByModified"),"aria-label":C("fileTree.sortedByModified"),children:o.jsx(Wu,{size:11})})]})}),o.jsx("button",{type:"button",onClick:()=>et&&Ys(et,Wt??void 0),disabled:!et,...et&&Wt?Dc(jl(et),Wt):{},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${Wt&&(Ze===Wt||Fe===Wt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":C(Wt&&Fe===Wt?"rightSidebar.copied":Wt&&Ze===Wt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:C("rightSidebar.insertCurrentFolder"),children:Wt&&(Ze===Wt||Fe===Wt)?o.jsx(na,{size:13}):o.jsx(El,{size:13})}),o.jsxs("div",{ref:Cn,className:"relative shrink-0",children:[o.jsx("button",{type:"button",onClick:()=>{Yt(!1),on(_=>!_)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${Mt?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":Mt,"aria-haspopup":"menu","aria-label":C("sidebar.moreActions"),title:C("sidebar.moreActions"),children:o.jsx(tu,{size:14})}),Mt&&o.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{on(!1),Go()},disabled:!rt,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${Re?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Re?o.jsx(Xc,{size:14}):o.jsx(yc,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(Re?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{on(!1),tc()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${Ws?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Ws?o.jsx(SN,{size:14}):o.jsx(Lb,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(Ws?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),o.jsxs("button",{type:"button",role:"menuitem",disabled:!et,onClick:()=>{et&&(on(!1),_o(et,Zt==="modified"?"name":"modified"))},className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-40",children:[Zt==="modified"?o.jsx(h8,{size:14}):o.jsx(Wu,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(Zt==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),Ae&&(M.length>0||Pt)&&o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[o.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:C("rightSidebar.pinnedFolders")}),o.jsxs("button",{type:"button",onClick:Yr,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-full px-2 py-0.5 font-medium transition active:scale-95 ${et===Ae?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:Ae,children:[o.jsx(S5,{size:10,className:"shrink-0"}),o.jsx("span",{className:"truncate",children:js})]}),M.map(_=>{const O=_.path,Z=_.kind==="file",De=Z?qr===O:et===O;return o.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-full transition ${De?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:O,children:[o.jsxs("button",{type:"button",onClick:()=>Z?xa(O):qn(O),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[Z?o.jsx(Eb,{size:10,className:"shrink-0"}):o.jsx(yc,{size:10,className:"shrink-0"}),o.jsx("span",{className:"truncate",children:bo(O)})]}),o.jsx("button",{type:"button",onClick:()=>Gs(O),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":C("rightSidebar.unpinFolder",{name:bo(O)}),title:C("rightSidebar.unpinFolder",{name:bo(O)}),children:o.jsx(ts,{size:9})})]},O)})]}),o.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),Ga=b.useMemo(()=>{if(Cs===null)return null;const _=typeof navigator>"u"?void 0:navigator.language,O=Math.max(0,Math.floor((Wr-Cs)/1e3)),Z=new Intl.RelativeTimeFormat(_,{numeric:"auto"}),[De,Ie]=O<60?[-O,"second"]:O<3600?[-Math.floor(O/60),"minute"]:O<86400?[-Math.floor(O/3600),"hour"]:[-Math.floor(O/86400),"day"];return Z.format(De,Ie)},[Wr,Cs]),bn=Ae?o.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Ga?o.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:C("rightSidebar.gitLastUpdated",{time:Ga}),children:Ga}):null,o.jsx("button",{type:"button",onClick:()=>{hl()},disabled:B,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":C("rightSidebar.refreshGit"),title:C("rightSidebar.refreshGit"),children:o.jsx(Us,{size:13,className:B?"animate-spin":""})})]}):null,p1=Nc?C("rightSidebar.changeAuditScopeAll"):Oa.length===1?Oa[0].relativeRoot==="."?js:Oa[0].relativeRoot||Oa[0].name:`${Oa.length} repos`,ac=Ae?o.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[o.jsx(W4,{open:Kt,onOpenChange:nn,showScopePicker:Ua,selectedAll:Nc,repos:ha,selectedRoots:qi,onToggleRepo:Xg,onGenerate:()=>Mh(),disabled:!Ae,inserted:Ze===Pn,buttonLabel:C("rightSidebar.changeAuditShort"),insertedLabel:C("rightSidebar.inserted"),title:C("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:C("rightSidebar.insertChangeAuditPrompt"),scopeTitle:C("rightSidebar.changeAuditScopeLabel"),scopeLabel:p1,allLabel:C("rightSidebar.changeAuditScopeAll"),generateLabel:C("rightSidebar.changeAuditShort"),loading:It,error:!!Ee,statusTitle:Ee??(It?C("rightSidebar.changeAuditLoading"):Jn.length>0?`${C("rightSidebar.changeAuditLoaded",{count:Jn.length})}${Zh?` · ${C("rightSidebar.changeAuditLoadedAt",{time:Zh})}`:""}`:void 0)}),o.jsx("button",{type:"button",onClick:()=>{Dh()},disabled:It||Jn.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Jn.length>0?"":"invisible"}`,title:C("rightSidebar.clearChangeAuditTitle"),"aria-label":C("rightSidebar.clearChangeAudit"),children:o.jsx($i,{size:12})})]}):null,Bc=Nn.size>0||te?.available||ce?o.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-[10px] font-medium",children:[te?.available&&te.branch&&o.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:te.branch,children:[o.jsx(ql,{size:10,className:"shrink-0"}),o.jsx("span",{className:"truncate",children:te.branch})]}),Sr.modified>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[Sr.modified,"M"]}),Sr.added>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",Sr.added]}),Sr.deleted>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",Sr.deleted]}),Sr.renamed>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[Sr.renamed,"R"]}),Sr.copied>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[Sr.copied,"C"]}),Sr.untracked>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[Sr.untracked,"U"]}),Sr.conflicted>0&&o.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[Sr.conflicted,"!"]}),Sr.other>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[Sr.other,"?"]}),Sr.staged>0&&o.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:C("rightSidebar.stagedCountShort",{count:Sr.staged})}),te?.available&&Ae&&Nn.size>0&&de.length<=1&&o.jsx("button",{type:"button",onClick:()=>{wi({action:"stage-all",cwd:Ae},C("rightSidebar.stageAll"))},disabled:!!cr,className:"rounded-full bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:C("rightSidebar.stageAll"),children:C("rightSidebar.stageAll")}),te?.available&&Ae&&Nn.size>0&&de.length<=1&&o.jsx("button",{type:"button",onClick:()=>Mr({kind:"stash-all",repoRoot:Ae,repoLabel:js}),disabled:!!cr,className:"rounded-full bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:C("rightSidebar.stashAll"),children:C("rightSidebar.stashAll")})]}):null;return o.jsxs(w9,{side:"right",isOpen:e,drawerWidthPx:t,onClose:n,onOpen:r,push:s,pinned:i,children:[Dc.popoverNode,o.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("div",{className:"min-w-0 flex-1 px-1",children:o.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[o.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:Ae??void 0,children:js}),(!me||ws)&&te?.available&&te.branch&&o.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:te.branch,children:[o.jsx(ql,{size:10,className:"shrink-0"}),o.jsx("span",{className:"max-w-[7rem] truncate",children:te.branch})]})]})}),o.jsx("button",{type:"button",onClick:()=>ve(!X),className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${X?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":C("rightSidebar.toggleSearch"),title:C("common.search"),children:o.jsx(Jl,{size:14})}),o.jsxs("button",{type:"button",role:"switch","aria-checked":ze,onClick:()=>{Be(_=>!_),W(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${ze?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":C("rightSidebar.toggleContextDraft"),title:C("rightSidebar.contextDraftTitle"),children:[o.jsx(wM,{size:14}),!ze&&Ce.trim()&&o.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),o.jsx("input",{ref:Ei,type:"file",multiple:!0,className:"hidden",onChange:_=>{const O=_.target.files;!O||O.length===0||(Dl(Array.from(O)),_.target.value="")}}),o.jsx("input",{ref:po,type:"file",accept:"image/*",className:"hidden",onChange:_=>{const O=_.target.files?.[0];_.target.value="",O&&jc(O)}}),a&&o.jsx("button",{type:"button",onClick:a,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${i?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":C(i?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:C(i?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:i?o.jsx(Xc,{size:14}):o.jsx(yc,{size:14})}),o.jsxs("div",{ref:xr,className:"relative shrink-0",children:[o.jsx("button",{type:"button",onClick:()=>{on(!1),Yt(_=>!_)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${yt?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":yt,"aria-haspopup":"menu","aria-label":C("sidebar.moreActions"),title:C("sidebar.moreActions"),children:o.jsx(tu,{size:15})}),yt&&o.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Yt(!1),Ei.current?.click()},disabled:ko,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ko?o.jsx(Fn,{size:14,className:"animate-spin text-muted-foreground"}):o.jsx(eD,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C("rightSidebar.uploadFiles")})]}),o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Yt(!1),po.current?.click()},disabled:ko,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ko?o.jsx(Fn,{size:14,className:"animate-spin text-muted-foreground"}):o.jsx(UN,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C("rightSidebar.insertLocalImage")})]}),a&&o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Yt(!1),a()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${i?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[i?o.jsx(Xc,{size:14}):o.jsx(yc,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(i?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),i&&o.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":C("rightSidebar.layoutMode"),children:[o.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:C("rightSidebar.layoutMode")}),o.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",C("rightSidebar.layoutModeAuto")],["narrow",C("rightSidebar.layoutModeNarrow")],["wide",C("rightSidebar.layoutModeWide")]].map(([_,O])=>{const Z=we===_;return o.jsx("button",{type:"button",role:"menuitemradio","aria-checked":Z,onClick:()=>{ie(_),Yt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${Z?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:O},_)})})]})]})]}),o.jsx("button",{type:"button",onClick:n,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":C("rightSidebar.close"),children:o.jsx(ts,{size:14})})]}),X&&o.jsx("div",{className:"mt-2 space-y-1.5",children:o.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-surface-2 px-3 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[o.jsx(Jl,{size:12,className:"shrink-0"}),o.jsx("input",{"data-right-search":!0,type:"search",value:H,onChange:_=>Y(_.target.value),placeholder:C(ae==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),o.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${me?"text-[11px]":"text-[10px]"}`,children:[o.jsx("button",{type:"button",onClick:()=>Wh("name"),"aria-pressed":ae==="name",className:`rounded-full px-2 transition active:scale-95 ${me?"py-1":"py-0.5"} ${ae==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:C("rightSidebar.searchModeName")}),o.jsx("button",{type:"button",onClick:()=>Wh("content"),"aria-pressed":ae==="content",className:`rounded-full px-2 transition active:scale-95 ${me?"py-1":"py-0.5"} ${ae==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:C("rightSidebar.searchModeContent")})]}),H&&o.jsx("button",{type:"button",onClick:()=>Y(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":C("rightSidebar.clearSearch"),children:o.jsx(ts,{size:12})})]})}),ga?null:o.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-0.5 rounded-md bg-surface-2 p-0.5",children:[o.jsxs("button",{type:"button",onClick:()=>On("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${zo==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[o.jsx(ql,{size:12}),C("rightSidebar.tabGit"),B&&zo==="git"?o.jsx(Fn,{size:12,className:"animate-spin text-muted-foreground"}):null]}),o.jsxs("button",{type:"button",onClick:()=>On("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${zo==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[o.jsx(Df,{size:12}),C("rightSidebar.tabChanges"),B?o.jsx(Fn,{size:12,className:"animate-spin text-muted-foreground"}):Nn.size>0?o.jsx("span",{className:"text-[10px] text-accent",children:Nn.size}):null]}),o.jsxs("button",{type:"button",onClick:()=>On("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${zo==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[o.jsx(nu,{size:12}),C("rightSidebar.tabFiles")]})]}),o.jsx("div",{className:"h-2"}),Is&&o.jsx("div",{className:"pointer-events-none absolute right-3 top-10 z-20 max-w-[72%] rounded-lg bg-destructive/95 px-3 py-2 text-[11px] font-medium text-destructive-foreground shadow-md animate-fade-in",children:Is})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[o.jsx(ab,{active:As,mounted:fi,fallback:o.jsx(gf,{slow:!1}),children:$t?o.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:o.jsx(A4,{items:Jg,selectedKey:Nt,onSelect:st,emptyText:C("rightSidebar.noChanges"),mobile:me,backLabel:C("rightSidebar.backToChangeList"),headerTitle:C("rightSidebar.recentCommitsTitle"),headerMeta:`${$t.headRef??""}${$t.commits?.[0]?` · ${$t.commits[0]}`:""}`,onClose:()=>{Rt(null),st(null)},closeLabel:C("common.back"),wrap:Zn,onToggleWrap:me?j0:void 0,wrapTitle:C("rightSidebar.wrapLongLines"),wrapOnLabel:C("rightSidebar.wrapOn"),wrapOffLabel:C("rightSidebar.wrapOff"),desktopLayout:me?"stacked":"split",onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu})}):fn?o.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:o.jsx(A4,{items:cd,selectedKey:Ln,onSelect:ns,emptyText:C(hn?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:me,backLabel:C("rightSidebar.backToChangeList"),headerTitle:C(hn?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:dd?`${dd.repoLabel} · ${dd.branchName??"HEAD"} → ${dd.baseRef}`:void 0,onClose:()=>{Un(!1),Kn(null)},closeLabel:C("common.back"),wrap:Zn,onToggleWrap:me?j0:void 0,wrapTitle:C("rightSidebar.wrapLongLines"),wrapOnLabel:C("rightSidebar.wrapOn"),wrapOffLabel:C("rightSidebar.wrapOff"),desktopLayout:me?"stacked":"split",onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu,walkthroughs:e1,onWalkthroughNavigate:t1,initialDetailScrollTop:hn&&gn?as[gn]:void 0,onDetailScrollPositionChange:o1,externalSwiperRef:me?nc:void 0,onMobileSlideChange:me?di:void 0})}):o.jsx("div",{className:"h-full overflow-y-auto overscroll-contain px-2 py-2",children:Jh||(B?o.jsx(gf,{slow:K}):ee?o.jsx(Wp,{message:ee,onRetry:()=>{hl()}}):e7(te)?o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C(Ae?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):te?.available===!1?o.jsx(Wp,{message:te.error??C("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{hl()}}):Ae?o.jsx(gf,{slow:K}):o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C(Ae?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}))})}),o.jsx(ab,{active:bi,children:me?o.jsxs(uh,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:_=>{Ba.current=_,_.slideTo(ms,0)},onSlideChange:_=>{if(ui(_.activeIndex),Lo.current===_.activeIndex){Lo.current=null;return}_.activeIndex===0&&(ls(!1),Oe(null),p?.())},children:[o.jsx(Gu,{className:"h-full min-h-0",children:o.jsxs("div",{ref:jr,onScroll:Ml,onDragOver:sc,onDragEnter:sc,onDragLeave:Mc,onDrop:ic,className:"h-full overflow-y-auto overscroll-contain bg-surface relative",children:[ua&&o.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:o.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:C("rightSidebar.dropToUpload")})}),bl,o.jsx(b2,{rootPath:et??"",onFileSelect:xa,onPathReference:Ys,getReferenceText:jl,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onDirectoryRoot:Zr,onDirectoryPinToggle:vi,onFilePinToggle:Ki,pinnedPaths:G,selectedFilePath:qr,query:z,searchMode:ae,onContentMatchSelect:au,onDirectoryDropFiles:(_,O)=>Dl(O,_),revealDirectory:V,canOpenInFileBrowser:fl,onOpenInFileBrowser:lu})]})}),o.jsx(Gu,{className:"h-full min-h-0",children:o.jsx("div",{className:"h-full overflow-hidden bg-surface",children:o.jsx(n7,{filePath:bi&&(kr||ms===1)?qr:null,onInsertReference:Ys,onInsertText:oc,onInsertFeature:oc,onReferenceCopied:ya,onClose:h1,onDirectoryLinkOpen:ep,isMobile:!0,lineRange:ot,onLineRangeChange:Oe,insertedReferenceKey:Ze,copiedReferenceKey:Fe,scrollToLine:Dt,onScrollToLineHandled:()=>$e(null),markdownOutlineOpen:A,markdownOutlineCloseSignal:T,onOpenMarkdownOutline:L,onCloseMarkdownOutline:I,markdownImageLightboxOpen:j,markdownImageLightboxCloseSignal:P,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:R})})})]}):o.jsxs("div",{className:"flex h-full min-h-0",children:[o.jsxs("div",{ref:jr,onScroll:Ml,onDragOver:sc,onDragEnter:sc,onDragLeave:Mc,onDrop:ic,className:"shrink-0 overflow-y-auto overscroll-contain bg-surface relative",style:{width:xt},children:[ua&&o.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:o.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:C("rightSidebar.dropToUpload")})}),bl,o.jsx(b2,{rootPath:et??"",onFileSelect:xa,onPathReference:Ys,getReferenceText:jl,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onDirectoryRoot:Zr,onDirectoryPinToggle:vi,onFilePinToggle:Ki,pinnedPaths:G,selectedFilePath:qr,query:z,searchMode:ae,onContentMatchSelect:au,onDirectoryDropFiles:(_,O)=>Dl(O,_),revealDirectory:V,canOpenInFileBrowser:fl,onOpenInFileBrowser:lu})]}),o.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":C("rightSidebar.resizeFileTree"),title:C("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:Qa,onPointerMove:ma,onPointerUp:rc,onPointerCancel:rc,onDoubleClick:()=>{nt(P2),$n(Ef,P2)},children:o.jsx("span",{className:"absolute left-1/2 top-0 h-full w-px -translate-x-1/2 bg-border/20 transition group-hover:bg-primary/45"})}),o.jsx("div",{className:"min-w-0 flex-1 overflow-hidden bg-surface",children:o.jsx(n7,{filePath:bi?qr:null,onInsertReference:Ys,onInsertText:oc,onInsertFeature:oc,onReferenceCopied:ya,onDirectoryLinkOpen:ep,isMobile:!1,lineRange:ot,onLineRangeChange:Oe,insertedReferenceKey:Ze,copiedReferenceKey:Fe,scrollToLine:Dt,onScrollToLineHandled:()=>$e(null),markdownOutlineOpen:A,markdownOutlineCloseSignal:T,onOpenMarkdownOutline:L,onCloseMarkdownOutline:I,markdownImageLightboxOpen:j,markdownImageLightboxCloseSignal:P,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:R})})]})}),o.jsx(ab,{active:Rs,mounted:hi||Rs,children:()=>me?o.jsx(eg,{mobile:!0,backLabel:C("rightSidebar.backToChangeList"),externalSwiperRef:nc,onMobileSlideChange:di,groups:qo.length>0?Rh():[],mode:kn,onModeChange:hd,selectedKey:qr,scrollToKey:Oh,scrollToKeyNonce:gi.nonce,compact:!1,collapsedDirectoryKeys:Ve,onToggleDirectory:Hh,onSelectFile:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);O&&fd(xo(O))},renderLeading:Nh,renderTrailing:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?Eh(O):null},renderDirectoryTrailing:Ih,renderSubtitle:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?_h(O):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:_=>Ae&&o.jsxs("div",{className:"px-0 py-0",children:[Bc&&o.jsx("div",{className:"mb-2",children:Bc}),o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"min-w-0",children:o.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:C("rightSidebar.allChanges")})}),o.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[qo.length,"/",Nn.size]})]}),o.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Ch(),_,i&&N0(),ac,bn]}),si&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:si.label}),si.branch&&o.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:si.branch})]}),!si&&Ua&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[o.jsx(ql,{size:12,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:C("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:fu?(_=>$h(_)):void 0,emptyContent:B&&Nn.size===0&&ce===null?o.jsx(gf,{slow:K}):ee&&Nn.size===0?o.jsx(Wp,{message:ee,onRetry:()=>{hl()}}):Nn.size===0?o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C("rightSidebar.noChanges")}):qo.length===0?o.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:C("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>Nl(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:C("rightSidebar.backToChangeList"),children:[o.jsx(l0,{size:14}),C("rightSidebar.backToChangeList")]}),o.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[i&&N0(),o.jsxs("button",{type:"button",onClick:j0,"aria-pressed":Zn,title:C("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${Zn?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[o.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),o.jsx("span",{children:C(Zn?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:sd(),activePane:Rs,wrap:Zn,showScrollHint:!Zn,diffViewType:ut,inlineMode:an,diffOptions:Gh,reloadKey:Er,renderStreamBadge:_=>o.jsx(Hf,{status:_}),onHunkGitAction:Vh,onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu,onDetailScroll:id}):o.jsx(eg,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:C("rightSidebar.backToChangeList"),groups:qo.length>0?Rh():[],mode:kn,onModeChange:hd,selectedKey:qr,scrollToKey:Oh,scrollToKeyNonce:gi.nonce,compact:!0,collapsedDirectoryKeys:Ve,onToggleDirectory:Hh,onSelectFile:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);O&&fd(xo(O))},renderLeading:Nh,renderTrailing:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?Eh(O):null},renderDirectoryTrailing:Ih,renderSubtitle:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?_h(O):null},aiContent:fu?(_=>$h(_)):void 0,emptyContent:B&&Nn.size===0&&ce===null?o.jsx(gf,{slow:K}):ee&&Nn.size===0?o.jsx(Wp,{message:ee,onRetry:()=>{hl()}}):Nn.size===0?o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C("rightSidebar.noChanges")}):qo.length===0?o.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:C("rightSidebar.noMatchingChanges")}):null,renderListHeader:_=>Ae&&o.jsxs("div",{className:"px-0 py-0",children:[Bc&&o.jsx("div",{className:"mb-2",children:Bc}),o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:C("rightSidebar.allChanges")}),o.jsx("div",{className:"flex items-center gap-1.5",children:o.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[qo.length,"/",Nn.size]})})]}),o.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Ch(),_,N0(),ac,bn]}),si&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:si.label}),si.branch&&o.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:si.branch}),o.jsx("button",{type:"button",onClick:()=>gd("stage-all",si.root,si.label),disabled:!!cr,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:C("rightSidebar.stageAll"),children:C("rightSidebar.stageAll")}),o.jsx("button",{type:"button",onClick:()=>gd("stash-all",si.root,si.label),disabled:!!cr,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:C("rightSidebar.stashAll"),children:C("rightSidebar.stashAll")})]}),!si&&Ua&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[o.jsx(ql,{size:12,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:C("rightSidebar.selectRepositoryForDiff")})]})]}),files:sd(),activePane:Rs,wrap:Zn,showScrollHint:!Zn,diffViewType:Cr,inlineMode:an,diffOptions:Gh,reloadKey:Er,renderStreamBadge:_=>o.jsx(Hf,{status:_}),onHunkGitAction:Vh,onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu,onDetailScroll:id})})]}),ze&&o.jsx(oJ,{value:Ce,collapsed:We,autoCollapseAfterSend:xe,focusRequest:pt,insertError:or?C("rightSidebar.contextDraftInsertFailed"):null,onChange:_=>{Le(!1),Qe(_)},onCollapsedChange:W,onAutoCollapseAfterSendChange:He,onDisable:()=>Be(!1),onClear:()=>Qe(""),onInsert:()=>Hs(!1),onInsertAndSend:()=>Hs(!0),labels:{title:C("rightSidebar.contextDraftTitle"),hint:C("rightSidebar.contextDraftHint"),placeholder:C("rightSidebar.contextDraftPlaceholder"),collapse:C("rightSidebar.contextDraftCollapse"),expand:C("rightSidebar.contextDraftExpand"),disable:C("rightSidebar.contextDraftDisable"),clear:C("rightSidebar.contextDraftClear"),insert:C("rightSidebar.contextDraftInsert"),insertAndSend:C("rightSidebar.contextDraftInsertAndSend"),inserted:C("rightSidebar.contextDraftInserted"),sent:C("rightSidebar.contextDraftSent"),send:C("rightSidebar.contextDraftSend"),appended:C("rightSidebar.contextDraftAppended"),resize:C("rightSidebar.contextDraftResize"),autoCollapseAfterSend:C("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:_=>C("rightSidebar.contextDraftCharacterCount",{count:_})}}),Vg(),er&&o.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Mr(null),children:o.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:_=>_.stopPropagation(),children:[o.jsx("div",{className:"text-sm font-semibold text-foreground",children:er.kind==="restore"?C("rightSidebar.confirmRestoreTitle"):C("rightSidebar.confirmStashAllTitle")}),o.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:er.kind==="restore"?C("rightSidebar.confirmRestoreDescription",{path:Ag(er.file.absolutePath,Ae)}):C("rightSidebar.confirmStashAllDescription")}),er.kind==="restore"&&o.jsx("input",{value:er.phrase,onChange:_=>Mr({...er,phrase:_.target.value}),placeholder:C("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),o.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[o.jsx("button",{type:"button",onClick:()=>Mr(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:C("common.cancel")}),o.jsx("button",{type:"button",disabled:!!cr||er.kind==="restore"&&er.phrase.trim()!==C("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(er.kind==="restore"){const _=Oo(er.file,Ae);if(!_)return;wi({action:"restore-worktree-file",cwd:_,paths:[er.file.path],confirm:{acknowledged:!0,phrase:er.phrase}},C("rightSidebar.restoreFile"),ub(er.file))}else{const _=er.repoRoot??Ae;if(!_)return;wi({action:"stash-all",cwd:_},C("rightSidebar.stashAll"),`repo:${_}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${er.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:C(cr?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})})]})}function pte(e){return e>=90?"var(--destructive)":e>=70?"var(--warning)":"var(--success)"}function mte(e){return e>=90?"var(--destructive)/0.15":e>=70?"var(--warning)/0.15":"var(--success)/0.12"}function gte(e){if(!e)return"";const t=new Date(e),n=Date.now(),r=t.getTime()-n;if(r<=0)return"";const s=Math.floor(r/6e4),i=Math.floor(s/60),a=Math.floor(i/24),c=i%24,u=s%60,f=t.toLocaleDateString(void 0,{month:"short",day:"numeric"}),p=t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"});let g;return a>0?g=`${a}d ${c}h`:c>0?g=`${c}h ${u}m`:u>0?g=`${u}m`:g="soon",`resets in ${g} (${f} ${p})`}function xte(e){return{claude:"🧠",codex:"✨",kimi:"🌙",copilot:"🐙",grok:"🚀",gemini:"💎"}[e]||"📊"}function bte({result:e}){const{t}=Yn(),n=e.windows.filter(c=>c.percent===0&&!c.resetAt),r=e.windows.filter(c=>c.percent>0||c.resetAt),s=n.length>0?n.map(c=>c.label).join(" · "):"",i=!!e.error;let a=null;return!i&&e.entitlement&&(e.usagePercent>=90?a=t("quota.exhausted"):e.remaining!==void 0&&e.remaining<e.entitlement?a=t("quota.left",{n:e.remaining}):a=`${Math.round(e.usagePercent)}%`),o.jsxs("div",{className:"rounded-xl border border-border/15 bg-surface-2 p-3 sm:p-4",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[13px] font-semibold text-foreground",children:[o.jsx("span",{className:"shrink-0",children:xte(e.slug)}),o.jsx("span",{className:"truncate",children:e.displayName}),s&&o.jsx("span",{className:"shrink-0 rounded-full bg-surface-elevated px-2 py-0.5 text-[10px] font-normal text-muted-foreground",children:s})]}),a&&o.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:a})]}),r.length>0?o.jsx("div",{className:"mt-2.5 space-y-2",children:r.map(c=>{const u=Math.max(0,Math.min(100,c.percent));return o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-2 text-[12px]",children:[o.jsx("span",{className:"w-14 shrink-0 truncate text-muted-foreground sm:w-16",children:c.label}),o.jsx("div",{className:"flex-1",children:o.jsx("div",{className:"h-2 rounded-full",style:{background:mte(c.percent)},children:o.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${u}%`,background:pte(c.percent)}})})}),o.jsxs("span",{className:"w-9 shrink-0 text-right tabular-nums font-medium text-foreground",children:[Math.round(c.percent),"%"]})]}),c.resetAt&&o.jsx("p",{className:"mt-1 pl-14 text-[10px] text-muted-foreground sm:pl-16",children:gte(c.resetAt)})]},c.label)})}):i?o.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:e.error}):null]})}function yte({isOpen:e,onClose:t}){const{t:n}=Yn(),[r,s]=b.useState([]),[i,a]=b.useState(!1),c=async(p=!1)=>{a(!0);try{const g=p?await rE():await nE();s(g.providers||[])}catch{}finally{a(!1)}};if(b.useEffect(()=>{e&&c()},[e]),b.useEffect(()=>{if(!e)return;const p=g=>{const y=g.detail;Array.isArray(y)&&s(y)};return window.addEventListener("termdock:quota-update",p),()=>{window.removeEventListener("termdock:quota-update",p)}},[e]),!e)return null;const u=r.filter(p=>!p.error),f=u.length>0?new Date(Math.max(...u.map(p=>p.fetchedAt||0))):null;return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:t}),o.jsxs("div",{className:"fixed inset-x-3 z-modal-panel mx-auto flex max-w-lg flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)]",style:{top:"max(1.5rem, env(safe-area-inset-top, 0px))",bottom:"max(1.5rem, env(safe-area-inset-bottom, 0px))"},children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-3 py-2.5 sm:px-6 sm:py-3",children:[o.jsx("h2",{className:"text-[14px] font-semibold text-foreground sm:text-base",children:n("quota.title")}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("button",{type:"button",onClick:()=>c(!0),disabled:i,className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50","aria-label":n("quota.refresh"),children:o.jsx(Us,{size:15,className:i?"animate-spin":""})}),o.jsx("button",{type:"button",onClick:t,className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":n("quota.close"),children:o.jsx(ts,{size:17})})]})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-3 sm:p-5",children:[i&&u.length===0?o.jsx("div",{className:"flex items-center justify-center py-12",children:o.jsx(Us,{size:24,className:"animate-spin text-muted-foreground"})}):u.length===0?o.jsxs("div",{className:"py-8 text-center text-[13px] text-muted-foreground",children:[o.jsx("p",{children:n("quota.noProviders")}),o.jsx("p",{className:"mt-1.5 text-[11px]",children:n("quota.noProvidersHint")})]}):o.jsx("div",{className:"space-y-2.5",children:u.map(p=>o.jsx(bte,{result:p},p.slug))}),f&&o.jsx("p",{className:"mt-3 text-center text-[10px] text-muted-foreground",children:n("quota.updated",{time:f.toLocaleTimeString()})})]})]})]})}const s7=[{label:"Esc",sequence:"\\u001b"},{label:"Tab",sequence:"\\t"},{label:"Enter",sequence:"\\r"},{label:"S-Tab",sequence:"\\u001b[Z"},{label:"C-c",sequence:"\\u0003"},{label:"C-d",sequence:"\\u0004"},{label:"C-l",sequence:"\\u000c"},{label:"C-r",sequence:"\\u0012"},{label:"C-z",sequence:"\\u001a"},{label:"C-w",sequence:"\\u0017"},{label:"Up",sequence:"\\u001b[A"},{label:"Down",sequence:"\\u001b[B"},{label:"Left",sequence:"\\u001b[D"},{label:"Right",sequence:"\\u001b[C"},{label:"PgUp",sequence:"\\u001b[5~"},{label:"PgDn",sequence:"\\u001b[6~"}],vte=2,wte=20;function Ste({label:e}){return o.jsx("div",{className:"h-7 rounded-full bg-surface-2 px-3 text-[11px] leading-7 text-center text-muted-foreground truncate",children:e})}function Ate({value:e,onChange:t,placeholder:n}){const{t:r}=Yn(),[s,i]=D.useState(""),a=g=>{const y=[];let v="",S=!1;const A=()=>{const L=v.trim();L&&y.push(L),v=""};for(let L=0;L<g.length;L+=1){const I=g[L];if(!S&&I==="/"&&v.trim().length===0){S=!0,v+=I;continue}if(S){if(v+=I,I==="/"&&g[L-1]!=="\\"&&v.length>1){for(;L+1<g.length&&/[gimsuy]/.test(g[L+1]??"");)L+=1,v+=g[L];A(),S=!1}continue}if(I===","||/\s/.test(I)){A();continue}v+=I}if(A(),y.length===0)return;const T=[...e];for(const L of y){const I=pS(L);I&&(T.includes(I)||T.push(I))}t(T),i("")},c=g=>{t(e.filter(y=>y!==g))},u=s.trim(),f=u.length>0&&Pw(u),p=f&&!Rm(u);return o.jsx("div",{className:"rounded-2xl bg-surface px-3 py-2 ring-1 ring-border/15 focus-within:ring-accent/40",children:o.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.map(g=>{const y=Pw(g),v=y&&!Rm(g);return o.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-[11px] ${v?"bg-destructive/15 text-destructive":y?"bg-accent/15 font-mono text-accent":"bg-surface-elevated text-foreground"}`,title:y?v?r("settings.invalidRegex"):"Regex match":"Substring match (case-insensitive)",children:[y&&o.jsx("span",{className:"text-[10px] opacity-70",children:"re"}),g,o.jsx("button",{type:"button",onClick:()=>c(g),className:"rounded-full p-0.5 text-muted-foreground hover:bg-destructive/20 hover:text-destructive","aria-label":r("toolbarPresets.removeAction",{name:g}),children:o.jsx(ts,{size:12})})]},g)}),o.jsx("input",{type:"text",value:s,onChange:g=>i(g.target.value),onKeyDown:g=>{g.key==="Enter"||g.key===","&&!f?(g.preventDefault(),a(s)):g.key==="Backspace"&&s.length===0&&e.length>0&&c(e[e.length-1])},onBlur:()=>a(s),placeholder:e.length===0?n:"",className:`min-w-[8ch] flex-1 bg-transparent py-1 text-sm outline-none placeholder:text-muted/60 ${f?"font-mono":""} ${p?"text-destructive":""}`,autoCapitalize:"off",autoCorrect:"off",autoComplete:"off"})]})})}function Tte({value:e,min:t,max:n,onChange:r}){const{t:s}=Yn();return o.jsxs("div",{className:"inline-flex items-center gap-1 rounded-full bg-surface px-1 py-1 ring-1 ring-border/15",children:[o.jsx("button",{type:"button",onClick:()=>r(Math.max(t,e-1)),disabled:e<=t,className:"h-7 w-7 rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated disabled:opacity-40 inline-flex items-center justify-center","aria-label":s("common.decrease"),children:o.jsx(iM,{size:14})}),o.jsx("span",{className:"w-6 text-center text-sm font-medium tabular-nums text-foreground",children:e}),o.jsx("button",{type:"button",onClick:()=>r(Math.min(n,e+1)),disabled:e>=n,className:"h-7 w-7 rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated disabled:opacity-40 inline-flex items-center justify-center","aria-label":s("common.increase"),children:o.jsx(Ao,{size:14})})]})}const Cte=({presets:e,selectedPresetId:t,onSelectPreset:n,onUpdatePreset:r,onAddPreset:s,onRemovePreset:i,onResetDefaults:a})=>{const{t:c}=Yn(),u=e.find(L=>L.id===t)??e[0]??null,[f,p]=D.useState(null);if(!u)return null;const g=u.actions.length>0,y=[{id:"preview-auto",label:u.label,kind:"preset"},...u.includeAlt?[{id:"preview-alt",label:"Alt"}]:[],...g?u.actions.map((L,I)=>({id:L.id,label:Ub(L,I)})):["Enter","Home","End","Ctrl-C","Ctrl-D"].map(L=>({id:L,label:L}))],v=mS(y,u.rowLayout),S=(L,I)=>{r(u.id,j=>{const P=j.actions.findIndex(C=>C.id===L);if(P===-1)return j;const F=P+I;if(F<0||F>=j.actions.length)return j;const R=[...j.actions];return[R[P],R[F]]=[R[F],R[P]],{...j,actions:R}})},A=u.rowLayout.reduce((L,I)=>L+I,0),T=1+(u.includeAlt?1:0);return o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{className:"sticky top-[-1rem] sm:top-[-1.5rem] z-10 -mx-4 -mt-4 sm:-mx-6 sm:-mt-6 border-b border-border/15 bg-surface/95 backdrop-blur px-4 py-3 sm:px-6",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.preview")}),o.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[u.actions.length," button",u.actions.length===1?"":"s"," · ",A," slot",A===1?"":"s"]})]}),o.jsx("div",{className:"space-y-1 rounded-2xl bg-surface-2/60 p-2",children:v.map((L,I)=>{const j=L.items[0]?.kind==="preset",P=Math.max(2,L.columns),F=j?`${gS}px repeat(${Math.max(1,P-1)}, minmax(0, 1fr))`:`repeat(${P}, minmax(0, 1fr))`;return o.jsx("div",{className:"grid gap-1",style:{gridTemplateColumns:F},children:L.items.map(R=>R.kind==="preset"?o.jsx(xS,{mode:"auto",presetLabel:R.label,title:`Auto preset · ${R.label}`,disabled:!0},R.id):o.jsx(Ste,{label:R.label},R.id))},`preview-row-${I}`)})}),u.actions.length>A-T&&o.jsx("p",{className:"mt-1.5 text-[10px] text-muted-foreground",children:c("toolbarPresets.overCapacityHint")})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.presets")}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs("button",{type:"button",onClick:s,className:"inline-flex items-center gap-1 rounded-full bg-surface-2 px-3 py-2 text-xs font-medium hover:bg-surface-elevated transition",children:[o.jsx(Ao,{size:14}),c("toolbarPresets.new")]}),o.jsxs("button",{type:"button",onClick:a,className:"inline-flex items-center gap-1 rounded-full bg-surface-2 px-3 py-2 text-xs font-medium hover:bg-surface-elevated transition",children:[o.jsx(Us,{size:14}),c("toolbarPresets.reset")]})]})]}),o.jsx("div",{className:"-mx-1 flex flex-wrap gap-1.5 px-1",children:e.map(L=>o.jsxs("button",{type:"button",onClick:()=>n(L.id),className:`rounded-full px-3 py-2 text-xs font-medium transition ${L.id===u.id?"bg-primary/20 text-primary ring-1 ring-primary/30":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated"}`,children:[L.label,L.actions.length>0&&o.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:L.actions.length})]},L.id))})]}),o.jsxs("div",{className:"space-y-4 rounded-2xl bg-surface p-4 ring-1 ring-border/10",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.label")}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("input",{type:"text",value:u.label,onChange:L=>r(u.id,I=>({...I,label:L.target.value})),className:"flex-1 rounded-full bg-surface-2 px-4 py-2.5 text-sm placeholder:text-muted/60 outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.presetLabelPlaceholder"),autoCapitalize:"off",autoCorrect:"off"}),u.id!=="default"&&o.jsx("button",{type:"button",onClick:()=>i(u.id),className:"shrink-0 rounded-full bg-surface-2 px-3 py-2.5 text-destructive hover:bg-destructive/15","aria-label":c("toolbarPresets.deletePreset",{name:u.label}),children:o.jsx($i,{size:14})})]})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.matchPrograms")}),o.jsx("span",{className:"text-[10px] text-muted-foreground",children:c("toolbarPresets.typeEnterHint")})]}),o.jsx(Ate,{value:u.programs,onChange:L=>r(u.id,I=>({...I,programs:L})),placeholder:c("toolbarPresets.programsPlaceholder")}),o.jsx("p",{className:"text-[10px] text-muted-foreground",children:c("toolbarPresets.programsHelp")})]}),o.jsxs("button",{type:"button",onClick:()=>r(u.id,L=>({...L,includeAlt:!L.includeAlt})),className:"flex w-full items-center justify-between rounded-2xl bg-surface-2 px-4 py-3 text-sm transition hover:bg-surface-elevated",children:[o.jsxs("span",{children:[o.jsx("span",{className:"block font-medium text-foreground",children:c("toolbarPresets.altSlot")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:c("toolbarPresets.altSlotHint")})]}),o.jsx(xc,{checked:u.includeAlt})]}),o.jsxs("button",{type:"button",onClick:()=>r(u.id,L=>({...L,showOnDesktop:!L.showOnDesktop})),className:"flex w-full items-center justify-between rounded-2xl bg-surface-2 px-4 py-3 text-sm transition hover:bg-surface-elevated",children:[o.jsxs("span",{children:[o.jsx("span",{className:"block font-medium text-foreground",children:c("toolbarPresets.desktopVisibility")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:c("toolbarPresets.desktopVisibilityHint")})]}),o.jsx(xc,{checked:u.showOnDesktop===!0})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.rowLayout")}),o.jsx("p",{className:"text-[11px] text-muted-foreground",children:c("toolbarPresets.rowLayoutHint")})]}),o.jsxs("button",{type:"button",onClick:()=>r(u.id,L=>({...L,rowLayout:[...yy(L.rowLayout),3]})),className:"inline-flex items-center gap-1 rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium hover:bg-surface-elevated",children:[o.jsx(Ao,{size:12}),c("toolbarPresets.addRow")]})]}),o.jsx("div",{className:"space-y-2",children:u.rowLayout.map((L,I)=>o.jsxs("div",{className:"flex items-center gap-3 rounded-2xl bg-surface-2 px-3 py-2",children:[o.jsx("span",{className:"w-12 shrink-0 text-xs text-muted-foreground",children:c("toolbarPresets.rowN",{n:I+1})}),o.jsx("div",{className:"flex-1"}),o.jsx(Tte,{value:L,min:vte,max:wte,onChange:j=>r(u.id,P=>({...P,rowLayout:P.rowLayout.map((F,R)=>R===I?j:F)}))}),u.rowLayout.length>1&&o.jsx("button",{type:"button",onClick:()=>r(u.id,j=>({...j,rowLayout:j.rowLayout.filter((P,F)=>F!==I)})),className:"rounded-full bg-surface px-2.5 py-1 text-[11px] text-muted-foreground hover:bg-destructive/15 hover:text-destructive","aria-label":c("toolbarPresets.removeRow",{n:I+1}),children:c("toolbarPresets.del")})]},`row-${I}`))})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.buttons")}),o.jsx("p",{className:"text-[11px] text-muted-foreground",children:c("toolbarPresets.buttonsHint")})]}),o.jsxs("button",{type:"button",onClick:()=>{const L=`${u.id}-action-${Date.now()}`;r(u.id,I=>({...I,actions:[...I.actions,{id:L,label:`Key ${I.actions.length+1}`,sequence:""}]})),p(L)},className:"inline-flex items-center gap-1 rounded-full bg-primary/15 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/25",children:[o.jsx(Ao,{size:12}),c("toolbarPresets.addButton")]})]}),u.actions.length===0&&o.jsx("div",{className:"rounded-2xl bg-surface-2/60 px-4 py-6 text-center text-[11px] text-muted-foreground",children:c("toolbarPresets.noCustomButtons")}),u.actions.map((L,I)=>{const j=f===L.id;return o.jsxs("div",{className:`rounded-2xl bg-surface-2 transition ${j?"ring-1 ring-accent/40":""}`,children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[o.jsxs("div",{className:"flex flex-col gap-0.5",children:[o.jsx("button",{type:"button",onClick:()=>S(L.id,-1),disabled:I===0,className:"h-6 w-6 rounded-full bg-surface text-muted-foreground hover:bg-surface-elevated disabled:opacity-30 inline-flex items-center justify-center","aria-label":c("toolbarPresets.moveUp"),children:o.jsx(xg,{size:12})}),o.jsx("button",{type:"button",onClick:()=>S(L.id,1),disabled:I===u.actions.length-1,className:"h-6 w-6 rounded-full bg-surface text-muted-foreground hover:bg-surface-elevated disabled:opacity-30 inline-flex items-center justify-center","aria-label":c("toolbarPresets.moveDown"),children:o.jsx(p8,{size:12})})]}),o.jsxs("button",{type:"button",onClick:()=>p(j?null:L.id),className:"min-w-0 flex-1 text-left",children:[o.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Ub(L,I)}),o.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[L.sequence?L.sequence:c("toolbarPresets.noSequence"),L.doubleTapSequence&&o.jsxs("span",{className:"ml-1 text-accent/70",children:["· 2× ",L.doubleTapSequence]})]})]}),o.jsx("button",{type:"button",onClick:()=>r(u.id,P=>({...P,actions:P.actions.filter(F=>F.id!==L.id)})),className:"shrink-0 rounded-full bg-surface p-2 text-muted-foreground hover:bg-destructive/15 hover:text-destructive","aria-label":c("toolbarPresets.removeAction",{name:L.label}),children:o.jsx($i,{size:14})})]}),j&&o.jsxs("div",{className:"space-y-3 border-t border-border/10 px-3 py-3",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c("toolbarPresets.labelField")}),o.jsx("input",{type:"text",value:L.label,onChange:P=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,label:P.target.value}:R)})),className:"w-full rounded-full bg-surface px-4 py-2.5 text-sm outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.labelPlaceholder"),autoCapitalize:"off",autoCorrect:"off"})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c("toolbarPresets.sequence")}),o.jsx("input",{type:"text",value:L.sequence,onChange:P=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,sequence:P.target.value}:R)})),className:"w-full rounded-full bg-surface px-4 py-2.5 font-mono text-sm outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.sequencePlaceholder"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),o.jsx("div",{className:"flex flex-wrap gap-1.5 pt-1",children:s7.map(P=>o.jsx("button",{type:"button",onClick:()=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,sequence:P.sequence}:R)})),className:"rounded-full bg-surface px-2.5 py-1 text-[11px] font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:P.label},P.label))})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c("toolbarPresets.doubleTap")}),!L.doubleTapSequence&&o.jsx("button",{type:"button",onClick:()=>r(u.id,P=>({...P,actions:P.actions.map(F=>F.id===L.id?{...F,doubleTapSequence:""}:F)})),className:"text-[10px] text-accent hover:text-accent/80",children:c("toolbarPresets.doubleTapAdd")})]}),L.doubleTapSequence!==void 0&&o.jsxs(o.Fragment,{children:[o.jsx("input",{type:"text",value:L.doubleTapSequence,onChange:P=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,doubleTapSequence:P.target.value}:R)})),className:"w-full rounded-full bg-surface px-4 py-2.5 font-mono text-sm outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.doubleTapPlaceholder"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),o.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[s7.map(P=>o.jsx("button",{type:"button",onClick:()=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,doubleTapSequence:(R.doubleTapSequence??"")+P.sequence}:R)})),className:"rounded-full bg-surface px-2.5 py-1 text-[11px] font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:P.label},P.label)),o.jsx("button",{type:"button",onClick:()=>r(u.id,P=>({...P,actions:P.actions.map(F=>{if(F.id!==L.id)return F;const{doubleTapSequence:R,...C}=F;return C})})),className:"rounded-full bg-destructive/10 px-2.5 py-1 text-[11px] font-medium text-destructive/70 hover:bg-destructive/20 hover:text-destructive",children:c("toolbarPresets.remove")})]})]})]})]})]},L.id)})]})]})]})},kte={installed:"text-[color:var(--success)]",outdated:"text-[color:var(--warning)]","needs-approval":"text-[color:var(--warning)]","not-installed":"text-muted-foreground"};function _te(){const{t:e}=Yn(),[t,n]=D.useState(null),[r,s]=D.useState(null),[i,a]=D.useState(null),[c,u]=D.useState(null),[f,p]=D.useState(!1),[g,y]=D.useState(!1),[v,S]=D.useState(""),[A,T]=D.useState(""),[L,I]=D.useState(null),[j,P]=D.useState([]),[F,R]=D.useState([]),[C,$]=D.useState(null),[H,Y]=D.useState(new Set),[V,fe]=D.useState(null),[X,ve]=D.useState("auto"),[we,ie]=D.useState({}),[ae,q]=D.useState(null),[z,te]=D.useState(null),[pe,de]=D.useState(10),[ke,be]=D.useState(""),[oe,he]=D.useState(""),[J,Xe]=D.useState(12e3),[lt,Ze]=D.useState(null),[ge,Fe]=D.useState(null),Te=D.useCallback(async()=>{const[Le,ot,Oe,Dt]=await Promise.allSettled([HE(),GE(),dh(),H0()]);if(n(Le.status==="fulfilled"?Le.value:[]),ot.status==="fulfilled"){const $e=ot.value;P($e.plugins??[]),R($e.errors??[])}else P([]),R([]);if(Oe.status==="fulfilled"){const $e=Oe.value;Y(new Set($e.autoRenameAgents??[])),ve($e.autoRenameNamer??"auto"),ie($e.autoRenameModels??{}),de($e.autoRenameIntervalMinutes??10),be($e.autoRenamePromptPreference??""),he($e.autoRenamePromptPreference??""),Xe($e.autoRenamePromptPayloadChars??12e3)}else Y(new Set);q(Dt.status==="fulfilled"?Dt.value:[])},[]);D.useEffect(()=>{Te()},[Te]);const ze=async(Le,ot)=>{s(Le),a(null);try{ot==="install"?(await UE(Le)).devMode&&u(Le):(await zE(Le),c===Le&&u(null)),await Te()}catch(Oe){a(Oe instanceof Error?Oe.message:String(Oe))}finally{s(null)}},Be=Le=>e(Le==="installed"?"settings.agentHooksInstalled":Le==="outdated"?"settings.agentHooksOutdated":Le==="needs-approval"?"settings.agentHooksNeedsApproval":"settings.agentHooksNotInstalled"),We=async()=>{I(null);let Le;try{Le=JSON.parse(A)}catch{I("Invalid JSON");return}try{await WE(Le),T(""),p(!1),await Te()}catch(ot){if(ot instanceof Z2&&ot.migration){R(Oe=>[{slug:typeof Le.slug=="string"?Le.slug:"manifest.json",errors:ot.message.split(`
219
+ `),truncated:O.some(St=>St.truncated)};if((De.hunks??[]).length===0){at(C("rightSidebar.branchAuditDiffEmpty"));return}const Ie=Date.now(),Ye=["preview",De.repoRoot??Ae,De.baseRef??De.baseBranch??"",De.currentBranch??"",De.headRef??"",De.diffFingerprint??Ie].join("\0"),mt=wa.length===1?wa[0].label:`${wa.length} repos`;Kn(De),zn(St=>[{key:Ye,diff:De,repoLabel:mt,createdAt:Ie},...St.filter(Et=>Et.key!==Ye)].slice(0,8)),Bt(St=>St[Ye]===void 0?St:{...St,[Ye]:0}),fr(Ye),ns(De.hunks?.[0]?`${De.hunks[0].filePath}\0${De.hunks[0].hunkHeader}\0${De.hunks[0].hunkIndex}`:null),Un(!0)}catch(O){if(!vr(_)||pc(O))return;at(O instanceof Error?O.message:"Failed to load branch diff")}finally{vr(_)&&bt(!1)}},[Vt,wa,dr,jn,vr,Ae,C]),Bh=b.useCallback(_=>{Kn(_.diff),at(null),fr(_.key),ns(_.diff.hunks?.[0]?`${_.diff.hunks[0].filePath}\0${_.diff.hunks[0].hunkHeader}\0${_.diff.hunks[0].hunkIndex}`:null),Un(!0)},[]),r1=b.useCallback(_=>{zn(O=>O.filter(Z=>Z.key!==_)),Bt(O=>{if(!(_ in O))return O;const Z={...O};return delete Z[_],Z}),gn===_&&(fr(null),Kn(null),Un(!1))},[gn]),s1=b.useCallback(_=>{const O=Pc.find(Z=>Z.key===_);O&&(Kn(null),at(null),fr(_),ns(O.records[0]?.filePath??null),Un(!0))},[Pc]),i1=b.useCallback(async _=>{if(!Ae||!tr)return;const[O]=_.split(/\s+/);if(O){Ot(O),ar(null),Rt(null);try{const Z=await CI({cwd:Ae,repoRoot:tr,commit:O,requestSlotId:"right-sidebar-commit-diff"});if(!Z.available){ar(Z.error??"Commit diff is unavailable");return}Rt(Z);const De=Z.hunks?.[0];st(De?`${De.filePath}\0${De.hunkHeader}\0${De.hunkIndex}`:null)}catch(Z){ar(Z instanceof Error?Z.message:"Failed to load commit diff")}finally{Ot(null)}}},[tr,Ae]),o1=b.useCallback(_=>{if(!hn||!gn)return;const O=Math.max(0,Math.round(_));Bt(Z=>Math.abs((Z[gn]??0)-O)<24?Z:{...Z,[gn]:O})},[hn,gn]);b.useEffect(()=>{!me||!fn||!hn||Nl(1)},[fn,hn,me,Nl]);const Fh=b.useCallback(_=>{_&&Li(O=>NZ(O,_))},[]),Oh=gi.key===qr?gi.key:null,fd=b.useCallback(_=>{const O=ft.getState(),Z=pte();Vp("select_diff_file",{interactionId:Z,path:_,previousSelectedFilePath:O.selectedFilePath,rootPath:O.rootPath,activeGitRepoRoot:he,changedFiles:O.changedFiles.size,gitBundleLoading:O.gitBundleLoading,gitBundleLastLoadedAt:O.gitBundleLastLoadedAt,rightTab:O.rightTab}),Rr(_),On("diff"),me&&_&&Nl(1),Fh(_),queueMicrotask(()=>{const De=ft.getState();Vp("select_diff_file_after",{interactionId:Z,requestedPath:_,selectedFilePath:De.selectedFilePath,rootPath:De.rootPath,rightTab:De.rightTab,changedFiles:De.changedFiles.size,activeGitRepoRoot:he})})},[he,me,Fh,Rr,On,Nl]),Qh=b.useCallback(_=>{const O=Array.from(Nn.values()).find(Z=>{const De=Oo(Z,Ae),Ie=xo(Z);return Z.path===_.filePath||Ie===_.filePath||Z.absolutePath===_.filePath||(De?`${De}/${Z.path}`===_.filePath:!1)||_.repoRoot&&De===_.repoRoot&&Z.path===_.filePath});if(O){fd(xo(O)),window.setTimeout(()=>_u(_),90),window.setTimeout(()=>_u(_),320),window.setTimeout(()=>_u(_),760);return}_u(_)},[Nn,Ae,fd]),$h=b.useCallback(({slideToDetail:_,fullscreen:O,toggleFullscreen:Z}={})=>Se.length>0?o.jsx(ng,{walkthroughs:Se,repoRoot:he,fullscreen:O,onToggleFullscreen:Z,onNavigate:De=>{me&&window.requestAnimationFrame(()=>_?.()),Qh(De)}}):o.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[o.jsx(ru,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),C("rightSidebar.changeWalkthroughEmpty")]}),[he,Se,Qh,me,C]),a1=b.useCallback(_=>{_&&_t(O=>{const Z=new Set(O);return Z.has(_)?Z.delete(_):Z.add(_),nb(Xx,Z),Z})},[]),Hh=b.useCallback(_=>{Ur(O=>{const Z=new Set(O);return Z.has(_)?Z.delete(_):Z.add(_),nb(L4,Z),Z})},[]),hd=b.useCallback(_=>{Ft(_),$n(ET,_)},[]);b.useEffect(()=>{fu||kn!=="ai"||hd("tree")},[kn,hd,fu]);const j0=b.useCallback(()=>{Gt(_=>{const O=!_;return $n(IT,O),O})},[]),Uh=b.useCallback(_=>{nr(_),$n(RT,_)},[]),{whitespace:zh,context:pd}=uT(),Gh=b.useMemo(()=>({algorithm:"histogram",whitespace:zh,context:pd}),[zh,pd]),Wh=b.useCallback(_=>{q(_),$n(NT,_)},[]),md=b.useCallback(async(_,O,Z,De)=>{let Ie=_;for(;Ie.ok&&Ie.status==="running";)await new Promise(mt=>window.setTimeout(mt,1500)),Ie=await f5({jobId:Ie.jobId,cwd:O.cwd,action:O.action});if(!Ie.ok)throw new Error("Git action status is unavailable");if(Ie.status==="error")throw new Error(Ie.error||Ie.message||"Git action failed");const Ye={action:O.action,path:De,label:Z};return rs(Ye),window.setTimeout(()=>rs(mt=>mt?.action===Ye.action&&mt.path===Ye.path?null:mt),1400),Ie},[]),wi=b.useCallback(async(_,O,Z)=>{const De=Ae;Ae&&ur.current.delete(Ae),Dr(null),rs(null),pi({action:_.action,path:Z});try{const Ie=await EI(_),Ye=await md(Ie,_,O,Z);if(!vr(De))return!1;const mt=Ae?await ap(Ae,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Pd(Ae)}).catch(()=>Ye.bundle):Ye.bundle;return vr(De)?(mt&&pa(mt,{reloadDiff:!0,cacheOnly:!0}),Mr(null),!0):!1}catch(Ie){return rs(null),Dr(C("rightSidebar.gitActionFailed",{message:Ie instanceof Error?Ie.message:"Unknown error"})),!1}finally{vr(De)&&pi(null)}},[pa,vr,Ae,C,md]),Vh=b.useCallback(async _=>{const O=Ae,Z=await II(_);if(!vr(O))return;const De=Ae?await ap(Ae,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Pd(Ae)}).catch(()=>Z.bundle):Z.bundle;vr(O)&&De&&pa(De,{reloadDiff:!0,cacheOnly:!0})},[pa,vr,Ae]),gd=b.useCallback((_,O,Z)=>{if(O){if(_==="stage-all"){wi({action:"stage-all",cwd:O},C("rightSidebar.stageAll"),`repo:${O}`);return}Mr({kind:"stash-all",repoRoot:O,repoLabel:Z})}},[wi,C]),qh=b.useCallback(_=>{J(_),tb(Ae,_),ca(""),ki(""),gs(""),Rr(xl(_)),As||On("diff")},[xl,As,Ae,Rr,On]),l1=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=Os.trim();!_||_===Mn?.branch||await wi({action:"switch-branch",cwd:tr,branch:_},C("rightSidebar.switchBranch"))},[Mn?.branch,tr,ks,wi,Os,C]),Yh=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=aa.trim();if(!_)return;await wi({action:"commit",cwd:tr,message:_},C("rightSidebar.commitChanges"))&&la("")},[tr,aa,ks,wi,C]),c1=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=Gi.trim(),O=_i.trim();await wi({action:"push",cwd:tr,..._?{remote:_}:{},...O?{branch:O}:{}},C("rightSidebar.pushChanges"))},[tr,_i,Gi,ks,wi,C]),xd=b.useCallback(async()=>{if(!tr||ks){Dr(C("rightSidebar.selectRepositoryForGitActions"));return}const _=Gi.trim(),O=_i.trim();await wi({action:"pull",cwd:tr,..._?{remote:_}:{},...O?{branch:O}:{}},C("rightSidebar.pullChanges"))},[tr,_i,Gi,ks,wi,C]);b.useEffect(()=>{if(!As||!tr||cr)return;let _=!1;const O={push:C("rightSidebar.pushChanges"),pull:C("rightSidebar.pullChanges"),commit:C("rightSidebar.commitChanges"),"switch-branch":C("rightSidebar.switchBranch"),"stage-all":C("rightSidebar.stageAll"),"stash-all":C("rightSidebar.stashAll")};return(async()=>{for(const Z of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(_)return;const De=await f5({cwd:tr,action:Z}).catch(()=>null);if(!De?.ok||De.status!=="running")continue;const Ie={action:Z,cwd:tr},Ye=O[Z]??Z;pi({action:Z});try{const mt=await md(De,Ie,Ye);if(_||!vr(Ae))return;const St=Ae?await ap(Ae,void 0,{includeNested:!0,cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Pd(Ae)}).catch(()=>mt.bundle):mt.bundle;St&&pa(St,{reloadDiff:!0,cacheOnly:!0})}catch(mt){_||Dr(C("rightSidebar.gitActionFailed",{message:mt instanceof Error?mt.message:"Unknown error"}))}finally{_||pi(null)}return}})(),()=>{_=!0}},[tr,pa,As,vr,Ae,cr,C,md]);const P0=ho?.action==="commit",pu=ho?.action==="switch-branch",B0=ho?.action==="pull",F0=ho?.action==="push",bd=As||Co,O0=rd?C("rightSidebar.changeAuditScopeAll"):za.length===1?za[0].label:`${za.length} repos`,u1=za.length>0,Kh=wa.length>0,Xh=Ae?o.jsx(W4,{open:Tn,onOpenChange:mn,showScopePicker:!0,selectedAll:rd,repos:Vo,selectedRoots:nd,onToggleRepo:Zg,onGenerate:()=>n1(M0?"regenerate":"generate"),disabled:!u1,generateDisabled:!Kh,inserted:Ze?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:C(M0?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:C("rightSidebar.inserted"),title:C("rightSidebar.branchAuditGenerateTitle"),ariaLabel:C("rightSidebar.branchAuditShort"),scopeTitle:C("rightSidebar.changeAuditScopeLabel"),scopeLabel:O0,allLabel:C("rightSidebar.changeAuditScopeAll"),generateLabel:C(M0?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Ph()},secondaryDisabled:!Kh||rn,secondaryLabel:C("rightSidebar.branchAuditViewDiff"),secondaryTitle:C("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:rn,loading:Xn.size>0,statusTitle:Xn.size>0?C("rightSidebar.branchCandidatesLoading"):void 0,extraContent:o.jsxs("div",{className:"mb-2 space-y-1.5",children:[o.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block font-medium",children:C("rightSidebar.includeUncommitted")}),o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:C("rightSidebar.includeUncommittedHint")})]}),o.jsx("input",{type:"checkbox",checked:Vt,onChange:_=>ir(_.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),Sh.length>0&&o.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:C("rightSidebar.missingBaseReposSkipped",{repositories:Sh.map(_=>_.label).join($==="zh"?"、":", ")})})]}),renderRepoExtra:_=>{const O=ds.get(_.root),Z=[],De=new Set,Ie=(Et,gr)=>{!Et||De.has(Et)||(De.add(Et),Z.push({value:Et,label:Et,meta:gr}))};Ie(jn[_.root]||O?.context?.branch,C("rightSidebar.pushCurrentBranchBadge"));for(const Et of O?.context?.branches??[])Ie(Et,Et===O?.context?.branch?C("rightSidebar.pushCurrentBranchBadge"):C("rightSidebar.localBranch"));for(const Et of O?.context?.remoteBranches??[])Ie(Et,C("rightSidebar.remoteBranch"));const Ye=[],mt=new Set,St=(Et,gr)=>{!Et||mt.has(Et)||(mt.add(Et),Ye.push({value:Et,label:Et,meta:gr}))};St(dr[_.root],dr[_.root]?C("rightSidebar.pushUpstreamBadge"):void 0),St(O?.context?.upstream,O?.context?.upstream?C("rightSidebar.pushUpstreamBadge"):void 0);for(const Et of O?.context?.remoteBranches??[])St(Et,"remote");for(const Et of O?.context?.branches??[])St(Et,Et===O?.context?.branch?C("rightSidebar.pushCurrentBranchBadge"):"local");return o.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[o.jsx(jd,{label:C("rightSidebar.currentBranchLabel"),value:jn[_.root]||O?.context?.branch||"",options:Z,placeholder:C("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:C("rightSidebar.switchBranchSearchPlaceholder"),emptyText:C("rightSidebar.switchNoBranches"),onChange:Et=>{mr(gr=>({...gr,[_.root]:Et}))}}),o.jsx(jd,{label:C("rightSidebar.branchAuditBaseLabel"),value:dr[_.root]||"",options:Ye,placeholder:C("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:C("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:C("rightSidebar.branchAuditBaseEmpty"),onChange:Et=>{en(gr=>({...gr,[_.root]:Et}))}})]})}}):null,Zh=xf(Jn.reduce((_,O)=>Math.max(_,O.injectedAt??0),0),$),d1=Ae?o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("button",{type:"button",onClick:()=>Lt(_=>{const O=!_;return $n(Zx,O),O}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":wt,children:[o.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:o.jsx(ru,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:C("rightSidebar.branchAuditTitle")}),o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:O0})]}),o.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${wt?"rotate-90":""}`,children:o.jsx(_l,{size:13})})]}),wt&&o.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[C("rightSidebar.changeAuditScopeLabel"),": ",O0]}),Xh]}),Tt&&o.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Tt}),o.jsxs("div",{className:"mt-2 space-y-1.5",children:[sn.map(_=>o.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${gn===_.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[o.jsxs("button",{type:"button",onClick:()=>Bh(_),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:_.repoLabel}),o.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[_.diff.hunks?.length??0," hunk"]})]}),o.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.diff.currentBranch??"HEAD"}),o.jsx("span",{className:"text-muted-foreground/60",children:"→"}),o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.diff.baseRef??_.diff.baseBranch}),o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:C("rightSidebar.branchAuditViewDiff")})]}),xf(_.createdAt,$)&&o.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:xf(_.createdAt,$)})]}),o.jsx("button",{type:"button",onClick:()=>r1(_.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:C("common.delete"),"aria-label":C("common.delete"),children:o.jsx($i,{size:12})})]},_.key)),Pc.length>0?Pc.slice(0,Math.max(0,8-sn.length)).map(_=>o.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${gn===_.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[o.jsxs("button",{type:"button",onClick:()=>s1(_.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:_.repoLabel}),o.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[10px] text-muted-foreground",children:[_.records.length," hunk"]})]}),o.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[10px] text-muted-foreground",children:[o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.branchName??"HEAD"}),o.jsx("span",{className:"text-muted-foreground/60",children:"→"}),o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.baseRef}),_.diffFingerprint&&o.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:_.diffFingerprint})]}),xf(_.latestInjectedAt,$)&&o.jsx("div",{className:"mt-1 truncate text-[10px] text-muted-foreground/70",children:C("rightSidebar.branchAuditGeneratedAt",{time:xf(_.latestInjectedAt,$)??""})})]}),o.jsx("button",{type:"button",onClick:()=>{jh(_)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:C("rightSidebar.branchAuditClearTitle"),"aria-label":C("rightSidebar.branchAuditClearTitle"),children:o.jsx($i,{size:12})})]},_.key)):sn.length===0?o.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:C("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Jh=fi&&Ae&&Ha?o.jsxs("div",{className:bd?"overflow-visible":"overflow-hidden",children:[d1,o.jsxs("button",{type:"button",onClick:()=>{As||zi(_=>{const O=!_;return O&&tr&&!Ha&&!Js&&Rl(tr),O})},"aria-expanded":bd,className:`group flex w-full items-center gap-2 px-1 py-1.5 text-left transition ${As?"cursor-default":"rounded-lg hover:bg-surface-2 active:scale-[0.99]"}`,children:[o.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:o.jsx(ql,{size:14})}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:C("rightSidebar.gitQuickActions")}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[o.jsxs("span",{className:`inline-flex min-w-[4.5rem] items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${Pl.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[Js&&o.jsx(Fn,{size:10,className:"animate-spin"}),Pl.staged>0?C("rightSidebar.stagedCount",{count:Pl.staged}):C("rightSidebar.noStagedChangesShort")]}),!As&&o.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${bd?"rotate-90":""}`,children:o.jsx(_l,{size:13})})]})]}),bd&&o.jsxs("div",{className:"space-y-0",children:[Ji.length>1&&o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.gitRepositorySectionTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:gl})]})}),o.jsx(jd,{label:C("rightSidebar.gitRepositoryLabel"),value:tr??"",options:Ji,placeholder:C("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:C("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:C("rightSidebar.gitRepositoryEmpty"),disabled:!!cr,onChange:_=>{qh(_||null)}}),ks&&o.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:C("rightSidebar.selectRepositoryForGitActions")})]}),o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.branchSectionTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:cu})]}),o.jsxs("button",{type:"button",onClick:()=>{l1()},disabled:!Kg,className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${pu?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:C("rightSidebar.switchBranch"),children:[o.jsx("span",{className:cr?.action==="switch-branch"||pu?"opacity-0":"",children:C("rightSidebar.switchBranch")}),cr?.action==="switch-branch"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),pu&&cr?.action!=="switch-branch"&&o.jsx("span",{className:"absolute",children:"✓"})]})]}),o.jsx(jd,{label:C("rightSidebar.currentBranchLabel"),value:Os,options:wh,placeholder:C("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:C("rightSidebar.switchBranchSearchPlaceholder"),emptyText:C("rightSidebar.switchNoBranches"),disabled:!!cr,onChange:ca})]}),o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.commitSectionTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:ks?C("rightSidebar.selectRepositoryForGitActions"):Pl.staged>0?C("rightSidebar.commitReadyHint",{count:Pl.staged}):C("rightSidebar.commitNeedsStaged")})]}),o.jsxs("button",{type:"button",onClick:()=>{Yh()},disabled:!!cr||ks||Pl.staged===0||!aa.trim(),className:`relative inline-flex h-7 shrink-0 items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition active:scale-95 ${P0?"bg-accent/10 text-accent disabled:bg-accent/10 disabled:text-accent":"bg-primary text-primary-foreground hover:bg-primary/90 disabled:bg-surface-2 disabled:text-muted-foreground"} disabled:cursor-not-allowed`,title:ks?C("rightSidebar.selectRepositoryForGitActions"):Pl.staged===0?C("rightSidebar.commitNeedsStaged"):C("rightSidebar.commitChanges"),children:[o.jsx("span",{className:cr?.action==="commit"||P0?"opacity-0":"",children:C("rightSidebar.commitChanges")}),cr?.action==="commit"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),P0&&cr?.action!=="commit"&&o.jsx("span",{className:"absolute",children:"✓"})]})]}),o.jsx("input",{value:aa,onChange:_=>la(_.target.value),onKeyDown:_=>{(_.metaKey||_.ctrlKey)&&_.key==="Enter"&&(_.preventDefault(),Yh())},placeholder:C("rightSidebar.commitMessagePlaceholder"),disabled:!!cr,className:"w-full rounded-md border border-border/15 bg-surface-2 px-2.5 py-1.5 text-[12px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary/35 focus:ring-1 focus:ring-primary/25 disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),o.jsxs("div",{className:"border-b border-border/10 px-1 py-3",children:[o.jsxs("button",{type:"button",onClick:()=>ct(_=>!_),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":qe,children:[o.jsx("span",{className:"min-w-0 text-[11px] font-semibold text-foreground",children:C("rightSidebar.recentCommitsTitle")}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[pn&&o.jsx(Fn,{size:12,className:"animate-spin text-muted-foreground"}),o.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${qe?"rotate-90":""}`,children:o.jsx(_l,{size:13})})]})]}),qe&&o.jsxs("div",{className:"mt-2 space-y-2",children:[o.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[o.jsx(Jl,{size:12,className:"shrink-0"}),o.jsx("input",{value:jt,onChange:_=>dn(_.target.value),placeholder:C("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),jt&&o.jsx("button",{type:"button",onClick:()=>dn(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":C("rightSidebar.clearSearch"),children:o.jsx(ts,{size:12})})]}),o.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:uu,children:[_n.length>0?_n.map(_=>{const[O,...Z]=_.split(/\s+/),De=Z.join(" ")||_;return o.jsxs("button",{type:"button",onClick:()=>{i1(_)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:De,children:[o.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:O}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:De,children:De}),vn===O&&o.jsx(Fn,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},_)}):pn?o.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:C("common.loading")}):o.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:C("rightSidebar.recentCommitsEmpty")}),cn&&o.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:o.jsx(Fn,{size:12,className:"animate-spin"})}),se&&!cn&&_n.length>0&&o.jsx("button",{type:"button",onClick:()=>{Eo({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:C("rightSidebar.recentCommitsLoadMore")})]})]}),Jt&&o.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Jt}),ps&&o.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:ps})]}),o.jsxs("div",{className:"px-1 py-3",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[o.jsx("div",{className:"text-[11px] font-semibold text-foreground",children:C("rightSidebar.pushSectionTitle")}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[o.jsxs("button",{type:"button",onClick:()=>{xd()},disabled:!qg,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${B0?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:C("rightSidebar.pullChanges"),children:[o.jsx("span",{className:cr?.action==="pull"||B0?"opacity-0":"",children:C("rightSidebar.pullChanges")}),cr?.action==="pull"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),B0&&cr?.action!=="pull"&&o.jsx("span",{className:"absolute",children:"✓"})]}),o.jsxs("button",{type:"button",onClick:()=>{c1()},disabled:!Yg,className:`relative inline-flex h-7 min-w-[3.25rem] items-center justify-center rounded-md px-2.5 text-[11px] font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${F0?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:C("rightSidebar.pushChanges"),children:[o.jsx("span",{className:cr?.action==="push"||F0?"opacity-0":"",children:C("rightSidebar.pushChanges")}),cr?.action==="push"&&o.jsx(Fn,{size:12,className:"absolute animate-spin"}),F0&&cr?.action!=="push"&&o.jsx("span",{className:"absolute",children:"✓"})]})]})]}),o.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${Th.className}`,title:Mn?.upstream??void 0,children:[o.jsx("span",{className:"truncate font-medium",children:Th.text}),o.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:Mn?.upstream??""})]}),o.jsxs("div",{className:`grid gap-1.5 ${I0?"grid-cols-2":"grid-cols-1"}`,children:[I0&&o.jsx(jd,{label:C("rightSidebar.pushRemoteLabel"),value:Gi,options:E0,placeholder:C("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:C("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:C("rightSidebar.pushNoRemotes"),disabled:!!cr,onChange:ki}),o.jsx(jd,{label:C("rightSidebar.pushBranchLabel"),value:_i,options:zg,placeholder:C("rightSidebar.pushBranchPlaceholder",{branch:Mn?.branch??"HEAD"}),searchPlaceholder:C("rightSidebar.pushBranchSearchPlaceholder"),emptyText:C("rightSidebar.pushNoBranches"),disabled:!!cr,onChange:gs})]})]})]})]}):null,f1=b.useCallback(_=>{const O=Oo(_,Ae);if(!O)return[];const Z=ub(_),De=[];return _.canStage&&De.push({key:"stage-file",label:C("rightSidebar.stageFile"),onClick:()=>{wi({action:"stage-file",cwd:O,paths:[_.path]},C("rightSidebar.stageFile"),Z)}}),_.canUnstage&&De.push({key:"unstage-file",label:C("rightSidebar.unstageFile"),onClick:()=>{wi({action:"unstage-file",cwd:O,paths:[_.path]},C("rightSidebar.unstageFile"),Z)}}),_.canStash&&De.push({key:"stash-file",label:C("rightSidebar.stashFile"),onClick:()=>{wi({action:"stash-file",cwd:O,paths:[_.path]},C("rightSidebar.stashFile"),Z)}}),_.canRestoreWorktree&&De.push({key:"restore-worktree-file",label:C("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Mr({kind:"restore",file:_,phrase:""})}),De},[Ae,wi,C]),h1=b.useCallback(()=>{if(c){p?.();return}ui(0),Ba.current?.slideTo(0),ls(!1),Oe(null)},[p,c]),ep=b.useCallback(_=>{if(Y(""),qn(null),Rr(null),Oe(null),fe(O=>({path:_,nonce:(O?.nonce??0)+1})),me){c&&p?.(),ui(0),Ba.current?.slideTo(0),ls(!1);return}},[me,p,c,Rr,qn]);b.useEffect(()=>{e||(Yt(!1),on(!1))},[e]),b.useEffect(()=>{if(!yt&&!Mt)return;const _=O=>{O instanceof globalThis.KeyboardEvent&&O.key!=="Escape"||O instanceof globalThis.MouseEvent&&O.target instanceof Node&&(xr.current?.contains(O.target)||Cn.current?.contains(O.target))||(Yt(!1),on(!1))};return window.addEventListener("mousedown",_),window.addEventListener("keydown",_),()=>{window.removeEventListener("mousedown",_),window.removeEventListener("keydown",_)}},[Mt,yt]);const bl=o.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[o.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[o.jsx("button",{type:"button",onClick:Fr,disabled:!ml,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":C("rightSidebar.parentFolder"),title:C("rightSidebar.parentFolder"),children:o.jsx(xg,{size:14})}),o.jsx("button",{type:"button",onClick:Yr,disabled:!Ae||hr===Ae,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":C("rightSidebar.backToProjectRoot"),title:C("rightSidebar.backToProjectRoot"),children:o.jsx(S5,{size:14})}),o.jsx("button",{type:"button",onClick:Xr,disabled:!et,className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${mi?"text-destructive":"text-muted-foreground"}`,"aria-label":C("rightSidebar.refreshFiles"),title:mi?C("rightSidebar.fileWatchUnavailable",{message:mi}):C("rightSidebar.refreshFiles"),children:o.jsx(Us,{size:13})}),o.jsx("div",{className:"min-w-0 flex-1 px-1",title:et??void 0,children:o.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[o.jsx("span",{className:"truncate",children:_0}),Zt==="modified"&&o.jsx("span",{className:"inline-flex shrink-0 text-primary",title:C("fileTree.sortedByModified"),"aria-label":C("fileTree.sortedByModified"),children:o.jsx(Wu,{size:11})})]})}),o.jsx("button",{type:"button",onClick:()=>et&&Ys(et,Wt??void 0),disabled:!et,...et&&Wt?Dc(jl(et),Wt):{},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${Wt&&(Ze===Wt||Fe===Wt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":C(Wt&&Fe===Wt?"rightSidebar.copied":Wt&&Ze===Wt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:C("rightSidebar.insertCurrentFolder"),children:Wt&&(Ze===Wt||Fe===Wt)?o.jsx(na,{size:13}):o.jsx(El,{size:13})}),o.jsxs("div",{ref:Cn,className:"relative shrink-0",children:[o.jsx("button",{type:"button",onClick:()=>{Yt(!1),on(_=>!_)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${Mt?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":Mt,"aria-haspopup":"menu","aria-label":C("sidebar.moreActions"),title:C("sidebar.moreActions"),children:o.jsx(tu,{size:14})}),Mt&&o.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{on(!1),Go()},disabled:!rt,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${Re?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Re?o.jsx(Xc,{size:14}):o.jsx(yc,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(Re?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{on(!1),tc()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${Ws?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Ws?o.jsx(SN,{size:14}):o.jsx(Lb,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(Ws?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),o.jsxs("button",{type:"button",role:"menuitem",disabled:!et,onClick:()=>{et&&(on(!1),_o(et,Zt==="modified"?"name":"modified"))},className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-40",children:[Zt==="modified"?o.jsx(h8,{size:14}):o.jsx(Wu,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(Zt==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),Ae&&(M.length>0||Pt)&&o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[o.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:C("rightSidebar.pinnedFolders")}),o.jsxs("button",{type:"button",onClick:Yr,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-full px-2 py-0.5 font-medium transition active:scale-95 ${et===Ae?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:Ae,children:[o.jsx(S5,{size:10,className:"shrink-0"}),o.jsx("span",{className:"truncate",children:js})]}),M.map(_=>{const O=_.path,Z=_.kind==="file",De=Z?qr===O:et===O;return o.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-full transition ${De?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:O,children:[o.jsxs("button",{type:"button",onClick:()=>Z?xa(O):qn(O),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[Z?o.jsx(Eb,{size:10,className:"shrink-0"}):o.jsx(yc,{size:10,className:"shrink-0"}),o.jsx("span",{className:"truncate",children:bo(O)})]}),o.jsx("button",{type:"button",onClick:()=>Gs(O),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":C("rightSidebar.unpinFolder",{name:bo(O)}),title:C("rightSidebar.unpinFolder",{name:bo(O)}),children:o.jsx(ts,{size:9})})]},O)})]}),o.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),Ga=b.useMemo(()=>{if(Cs===null)return null;const _=typeof navigator>"u"?void 0:navigator.language,O=Math.max(0,Math.floor((Wr-Cs)/1e3)),Z=new Intl.RelativeTimeFormat(_,{numeric:"auto"}),[De,Ie]=O<60?[-O,"second"]:O<3600?[-Math.floor(O/60),"minute"]:O<86400?[-Math.floor(O/3600),"hour"]:[-Math.floor(O/86400),"day"];return Z.format(De,Ie)},[Wr,Cs]),bn=Ae?o.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[Ga?o.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:C("rightSidebar.gitLastUpdated",{time:Ga}),children:Ga}):null,o.jsx("button",{type:"button",onClick:()=>{hl()},disabled:B,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":C("rightSidebar.refreshGit"),title:C("rightSidebar.refreshGit"),children:o.jsx(Us,{size:13,className:B?"animate-spin":""})})]}):null,p1=Nc?C("rightSidebar.changeAuditScopeAll"):Oa.length===1?Oa[0].relativeRoot==="."?js:Oa[0].relativeRoot||Oa[0].name:`${Oa.length} repos`,ac=Ae?o.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[o.jsx(W4,{open:Kt,onOpenChange:nn,showScopePicker:Ua,selectedAll:Nc,repos:ha,selectedRoots:qi,onToggleRepo:Xg,onGenerate:()=>Mh(),disabled:!Ae,inserted:Ze===Pn,buttonLabel:C("rightSidebar.changeAuditShort"),insertedLabel:C("rightSidebar.inserted"),title:C("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:C("rightSidebar.insertChangeAuditPrompt"),scopeTitle:C("rightSidebar.changeAuditScopeLabel"),scopeLabel:p1,allLabel:C("rightSidebar.changeAuditScopeAll"),generateLabel:C("rightSidebar.changeAuditShort"),loading:It,error:!!Ee,statusTitle:Ee??(It?C("rightSidebar.changeAuditLoading"):Jn.length>0?`${C("rightSidebar.changeAuditLoaded",{count:Jn.length})}${Zh?` · ${C("rightSidebar.changeAuditLoadedAt",{time:Zh})}`:""}`:void 0)}),o.jsx("button",{type:"button",onClick:()=>{Dh()},disabled:It||Jn.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Jn.length>0?"":"invisible"}`,title:C("rightSidebar.clearChangeAuditTitle"),"aria-label":C("rightSidebar.clearChangeAudit"),children:o.jsx($i,{size:12})})]}):null,Bc=Nn.size>0||te?.available||ce?o.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-[10px] font-medium",children:[te?.available&&te.branch&&o.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:te.branch,children:[o.jsx(ql,{size:10,className:"shrink-0"}),o.jsx("span",{className:"truncate",children:te.branch})]}),Sr.modified>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[Sr.modified,"M"]}),Sr.added>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",Sr.added]}),Sr.deleted>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",Sr.deleted]}),Sr.renamed>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[Sr.renamed,"R"]}),Sr.copied>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[Sr.copied,"C"]}),Sr.untracked>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[Sr.untracked,"U"]}),Sr.conflicted>0&&o.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[Sr.conflicted,"!"]}),Sr.other>0&&o.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[Sr.other,"?"]}),Sr.staged>0&&o.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:C("rightSidebar.stagedCountShort",{count:Sr.staged})}),te?.available&&Ae&&Nn.size>0&&de.length<=1&&o.jsx("button",{type:"button",onClick:()=>{wi({action:"stage-all",cwd:Ae},C("rightSidebar.stageAll"))},disabled:!!cr,className:"rounded-full bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:C("rightSidebar.stageAll"),children:C("rightSidebar.stageAll")}),te?.available&&Ae&&Nn.size>0&&de.length<=1&&o.jsx("button",{type:"button",onClick:()=>Mr({kind:"stash-all",repoRoot:Ae,repoLabel:js}),disabled:!!cr,className:"rounded-full bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:C("rightSidebar.stashAll"),children:C("rightSidebar.stashAll")})]}):null;return o.jsxs(w9,{side:"right",isOpen:e,drawerWidthPx:t,onClose:n,onOpen:r,push:s,pinned:i,children:[Dc.popoverNode,o.jsxs("div",{className:"relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("div",{className:"min-w-0 flex-1 px-1",children:o.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[o.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:Ae??void 0,children:js}),(!me||ws)&&te?.available&&te.branch&&o.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:te.branch,children:[o.jsx(ql,{size:10,className:"shrink-0"}),o.jsx("span",{className:"max-w-[7rem] truncate",children:te.branch})]})]})}),o.jsx("button",{type:"button",onClick:()=>ve(!X),className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${X?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":C("rightSidebar.toggleSearch"),title:C("common.search"),children:o.jsx(Jl,{size:14})}),o.jsxs("button",{type:"button",role:"switch","aria-checked":ze,onClick:()=>{Be(_=>!_),W(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${ze?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":C("rightSidebar.toggleContextDraft"),title:C("rightSidebar.contextDraftTitle"),children:[o.jsx(wM,{size:14}),!ze&&Ce.trim()&&o.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),o.jsx("input",{ref:Ei,type:"file",multiple:!0,className:"hidden",onChange:_=>{const O=_.target.files;!O||O.length===0||(Dl(Array.from(O)),_.target.value="")}}),o.jsx("input",{ref:po,type:"file",accept:"image/*",className:"hidden",onChange:_=>{const O=_.target.files?.[0];_.target.value="",O&&jc(O)}}),a&&o.jsx("button",{type:"button",onClick:a,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${i?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":C(i?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:C(i?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:i?o.jsx(Xc,{size:14}):o.jsx(yc,{size:14})}),o.jsxs("div",{ref:xr,className:"relative shrink-0",children:[o.jsx("button",{type:"button",onClick:()=>{on(!1),Yt(_=>!_)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${yt?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":yt,"aria-haspopup":"menu","aria-label":C("sidebar.moreActions"),title:C("sidebar.moreActions"),children:o.jsx(tu,{size:15})}),yt&&o.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Yt(!1),Ei.current?.click()},disabled:ko,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ko?o.jsx(Fn,{size:14,className:"animate-spin text-muted-foreground"}):o.jsx(eD,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C("rightSidebar.uploadFiles")})]}),o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Yt(!1),po.current?.click()},disabled:ko,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ko?o.jsx(Fn,{size:14,className:"animate-spin text-muted-foreground"}):o.jsx(UN,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C("rightSidebar.insertLocalImage")})]}),a&&o.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{Yt(!1),a()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${i?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[i?o.jsx(Xc,{size:14}):o.jsx(yc,{size:14,className:"text-muted-foreground"}),o.jsx("span",{children:C(i?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),i&&o.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":C("rightSidebar.layoutMode"),children:[o.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:C("rightSidebar.layoutMode")}),o.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",C("rightSidebar.layoutModeAuto")],["narrow",C("rightSidebar.layoutModeNarrow")],["wide",C("rightSidebar.layoutModeWide")]].map(([_,O])=>{const Z=we===_;return o.jsx("button",{type:"button",role:"menuitemradio","aria-checked":Z,onClick:()=>{ie(_),Yt(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${Z?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:O},_)})})]})]})]}),o.jsx("button",{type:"button",onClick:n,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":C("rightSidebar.close"),children:o.jsx(ts,{size:14})})]}),X&&o.jsx("div",{className:"mt-2 space-y-1.5",children:o.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-surface-2 px-3 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[o.jsx(Jl,{size:12,className:"shrink-0"}),o.jsx("input",{"data-right-search":!0,type:"search",value:H,onChange:_=>Y(_.target.value),placeholder:C(ae==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),o.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${me?"text-[11px]":"text-[10px]"}`,children:[o.jsx("button",{type:"button",onClick:()=>Wh("name"),"aria-pressed":ae==="name",className:`rounded-full px-2 transition active:scale-95 ${me?"py-1":"py-0.5"} ${ae==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:C("rightSidebar.searchModeName")}),o.jsx("button",{type:"button",onClick:()=>Wh("content"),"aria-pressed":ae==="content",className:`rounded-full px-2 transition active:scale-95 ${me?"py-1":"py-0.5"} ${ae==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:C("rightSidebar.searchModeContent")})]}),H&&o.jsx("button",{type:"button",onClick:()=>Y(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":C("rightSidebar.clearSearch"),children:o.jsx(ts,{size:12})})]})}),ga?null:o.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-0.5 rounded-md bg-surface-2 p-0.5",children:[o.jsxs("button",{type:"button",onClick:()=>On("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${zo==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[o.jsx(ql,{size:12}),C("rightSidebar.tabGit"),B&&zo==="git"?o.jsx(Fn,{size:12,className:"animate-spin text-muted-foreground"}):null]}),o.jsxs("button",{type:"button",onClick:()=>On("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${zo==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[o.jsx(Df,{size:12}),C("rightSidebar.tabChanges"),B?o.jsx(Fn,{size:12,className:"animate-spin text-muted-foreground"}):Nn.size>0?o.jsx("span",{className:"text-[10px] text-accent",children:Nn.size}):null]}),o.jsxs("button",{type:"button",onClick:()=>On("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${zo==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[o.jsx(nu,{size:12}),C("rightSidebar.tabFiles")]})]}),o.jsx("div",{className:"h-2"}),Is&&o.jsx("div",{className:"pointer-events-none absolute right-3 top-10 z-20 max-w-[72%] rounded-lg bg-destructive/95 px-3 py-2 text-[11px] font-medium text-destructive-foreground shadow-md animate-fade-in",children:Is})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[o.jsx(ab,{active:As,mounted:fi,fallback:o.jsx(gf,{slow:!1}),children:$t?o.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:o.jsx(A4,{items:Jg,selectedKey:Nt,onSelect:st,emptyText:C("rightSidebar.noChanges"),mobile:me,backLabel:C("rightSidebar.backToChangeList"),headerTitle:C("rightSidebar.recentCommitsTitle"),headerMeta:`${$t.headRef??""}${$t.commits?.[0]?` · ${$t.commits[0]}`:""}`,onClose:()=>{Rt(null),st(null)},closeLabel:C("common.back"),wrap:Zn,onToggleWrap:me?j0:void 0,wrapTitle:C("rightSidebar.wrapLongLines"),wrapOnLabel:C("rightSidebar.wrapOn"),wrapOffLabel:C("rightSidebar.wrapOff"),desktopLayout:me?"stacked":"split",onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu})}):fn?o.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:o.jsx(A4,{items:cd,selectedKey:Ln,onSelect:ns,emptyText:C(hn?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:me,backLabel:C("rightSidebar.backToChangeList"),headerTitle:C(hn?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:dd?`${dd.repoLabel} · ${dd.branchName??"HEAD"} → ${dd.baseRef}`:void 0,onClose:()=>{Un(!1),Kn(null)},closeLabel:C("common.back"),wrap:Zn,onToggleWrap:me?j0:void 0,wrapTitle:C("rightSidebar.wrapLongLines"),wrapOnLabel:C("rightSidebar.wrapOn"),wrapOffLabel:C("rightSidebar.wrapOff"),desktopLayout:me?"stacked":"split",onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu,walkthroughs:e1,onWalkthroughNavigate:t1,initialDetailScrollTop:hn&&gn?as[gn]:void 0,onDetailScrollPositionChange:o1,externalSwiperRef:me?nc:void 0,onMobileSlideChange:me?di:void 0})}):o.jsx("div",{className:"h-full overflow-y-auto overscroll-contain px-2 py-2",children:Jh||(B?o.jsx(gf,{slow:K}):ee?o.jsx(Wp,{message:ee,onRetry:()=>{hl()}}):e7(te)?o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C(Ae?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):te?.available===!1?o.jsx(Wp,{message:te.error??C("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{hl()}}):Ae?o.jsx(gf,{slow:K}):o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C(Ae?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}))})}),o.jsx(ab,{active:bi,children:me?o.jsxs(uh,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:_=>{Ba.current=_,_.slideTo(ms,0)},onSlideChange:_=>{if(ui(_.activeIndex),Lo.current===_.activeIndex){Lo.current=null;return}_.activeIndex===0&&(ls(!1),Oe(null),p?.())},children:[o.jsx(Gu,{className:"h-full min-h-0",children:o.jsxs("div",{ref:jr,onScroll:Ml,onDragOver:sc,onDragEnter:sc,onDragLeave:Mc,onDrop:ic,className:"h-full overflow-y-auto overscroll-contain bg-surface relative",children:[ua&&o.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:o.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:C("rightSidebar.dropToUpload")})}),bl,o.jsx(b2,{rootPath:et??"",onFileSelect:xa,onPathReference:Ys,getReferenceText:jl,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onDirectoryRoot:Zr,onDirectoryPinToggle:vi,onFilePinToggle:Ki,pinnedPaths:G,selectedFilePath:qr,query:z,searchMode:ae,onContentMatchSelect:au,onDirectoryDropFiles:(_,O)=>Dl(O,_),revealDirectory:V,canOpenInFileBrowser:fl,onOpenInFileBrowser:lu})]})}),o.jsx(Gu,{className:"h-full min-h-0",children:o.jsx("div",{className:"h-full overflow-hidden bg-surface",children:o.jsx(n7,{filePath:bi&&(kr||ms===1)?qr:null,onInsertReference:Ys,onInsertText:oc,onInsertFeature:oc,onReferenceCopied:ya,onClose:h1,onDirectoryLinkOpen:ep,isMobile:!0,lineRange:ot,onLineRangeChange:Oe,insertedReferenceKey:Ze,copiedReferenceKey:Fe,scrollToLine:Dt,onScrollToLineHandled:()=>$e(null),markdownOutlineOpen:A,markdownOutlineCloseSignal:T,onOpenMarkdownOutline:L,onCloseMarkdownOutline:I,markdownImageLightboxOpen:j,markdownImageLightboxCloseSignal:P,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:R})})})]}):o.jsxs("div",{className:"flex h-full min-h-0",children:[o.jsxs("div",{ref:jr,onScroll:Ml,onDragOver:sc,onDragEnter:sc,onDragLeave:Mc,onDrop:ic,className:"shrink-0 overflow-y-auto overscroll-contain bg-surface relative",style:{width:xt},children:[ua&&o.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:o.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:C("rightSidebar.dropToUpload")})}),bl,o.jsx(b2,{rootPath:et??"",onFileSelect:xa,onPathReference:Ys,getReferenceText:jl,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onDirectoryRoot:Zr,onDirectoryPinToggle:vi,onFilePinToggle:Ki,pinnedPaths:G,selectedFilePath:qr,query:z,searchMode:ae,onContentMatchSelect:au,onDirectoryDropFiles:(_,O)=>Dl(O,_),revealDirectory:V,canOpenInFileBrowser:fl,onOpenInFileBrowser:lu})]}),o.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":C("rightSidebar.resizeFileTree"),title:C("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:Qa,onPointerMove:ma,onPointerUp:rc,onPointerCancel:rc,onDoubleClick:()=>{nt(P2),$n(Ef,P2)},children:o.jsx("span",{className:"absolute left-1/2 top-0 h-full w-px -translate-x-1/2 bg-border/20 transition group-hover:bg-primary/45"})}),o.jsx("div",{className:"min-w-0 flex-1 overflow-hidden bg-surface",children:o.jsx(n7,{filePath:bi?qr:null,onInsertReference:Ys,onInsertText:oc,onInsertFeature:oc,onReferenceCopied:ya,onDirectoryLinkOpen:ep,isMobile:!1,lineRange:ot,onLineRangeChange:Oe,insertedReferenceKey:Ze,copiedReferenceKey:Fe,scrollToLine:Dt,onScrollToLineHandled:()=>$e(null),markdownOutlineOpen:A,markdownOutlineCloseSignal:T,onOpenMarkdownOutline:L,onCloseMarkdownOutline:I,markdownImageLightboxOpen:j,markdownImageLightboxCloseSignal:P,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:R})})]})}),o.jsx(ab,{active:Rs,mounted:hi||Rs,children:()=>me?o.jsx(eg,{mobile:!0,backLabel:C("rightSidebar.backToChangeList"),externalSwiperRef:nc,onMobileSlideChange:di,groups:qo.length>0?Rh():[],mode:kn,onModeChange:hd,selectedKey:qr,scrollToKey:Oh,scrollToKeyNonce:gi.nonce,compact:!1,collapsedDirectoryKeys:Ve,onToggleDirectory:Hh,onSelectFile:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);O&&fd(xo(O))},renderLeading:Nh,renderTrailing:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?Eh(O):null},renderDirectoryTrailing:Ih,renderSubtitle:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?_h(O):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:_=>Ae&&o.jsxs("div",{className:"px-0 py-0",children:[Bc&&o.jsx("div",{className:"mb-2",children:Bc}),o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("div",{className:"min-w-0",children:o.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:C("rightSidebar.allChanges")})}),o.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[qo.length,"/",Nn.size]})]}),o.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Ch(),_,i&&N0(),ac,bn]}),si&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:si.label}),si.branch&&o.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:si.branch})]}),!si&&Ua&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[o.jsx(ql,{size:12,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:C("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:fu?(_=>$h(_)):void 0,emptyContent:B&&Nn.size===0&&ce===null?o.jsx(gf,{slow:K}):ee&&Nn.size===0?o.jsx(Wp,{message:ee,onRetry:()=>{hl()}}):Nn.size===0?o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C("rightSidebar.noChanges")}):qo.length===0?o.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:C("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>Nl(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:C("rightSidebar.backToChangeList"),children:[o.jsx(l0,{size:14}),C("rightSidebar.backToChangeList")]}),o.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[i&&N0(),o.jsxs("button",{type:"button",onClick:j0,"aria-pressed":Zn,title:C("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${Zn?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[o.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),o.jsx("span",{children:C(Zn?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:sd(),activePane:Rs,wrap:Zn,showScrollHint:!Zn,diffViewType:ut,inlineMode:an,diffOptions:Gh,reloadKey:Er,renderStreamBadge:_=>o.jsx(Hf,{status:_}),onHunkGitAction:Vh,onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu,onDetailScroll:id}):o.jsx(eg,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:C("rightSidebar.backToChangeList"),groups:qo.length>0?Rh():[],mode:kn,onModeChange:hd,selectedKey:qr,scrollToKey:Oh,scrollToKeyNonce:gi.nonce,compact:!0,collapsedDirectoryKeys:Ve,onToggleDirectory:Hh,onSelectFile:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);O&&fd(xo(O))},renderLeading:Nh,renderTrailing:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?Eh(O):null},renderDirectoryTrailing:Ih,renderSubtitle:_=>{const O=Array.from(Nn.values()).find(Z=>xo(Z)===_.key);return O?_h(O):null},aiContent:fu?(_=>$h(_)):void 0,emptyContent:B&&Nn.size===0&&ce===null?o.jsx(gf,{slow:K}):ee&&Nn.size===0?o.jsx(Wp,{message:ee,onRetry:()=>{hl()}}):Nn.size===0?o.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:C("rightSidebar.noChanges")}):qo.length===0?o.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:C("rightSidebar.noMatchingChanges")}):null,renderListHeader:_=>Ae&&o.jsxs("div",{className:"px-0 py-0",children:[Bc&&o.jsx("div",{className:"mb-2",children:Bc}),o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:C("rightSidebar.allChanges")}),o.jsx("div",{className:"flex items-center gap-1.5",children:o.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[qo.length,"/",Nn.size]})})]}),o.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Ch(),_,N0(),ac,bn]}),si&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:si.label}),si.branch&&o.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:si.branch}),o.jsx("button",{type:"button",onClick:()=>gd("stage-all",si.root,si.label),disabled:!!cr,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:C("rightSidebar.stageAll"),children:C("rightSidebar.stageAll")}),o.jsx("button",{type:"button",onClick:()=>gd("stash-all",si.root,si.label),disabled:!!cr,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:C("rightSidebar.stashAll"),children:C("rightSidebar.stashAll")})]}),!si&&Ua&&o.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[o.jsx(ql,{size:12,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:C("rightSidebar.selectRepositoryForDiff")})]})]}),files:sd(),activePane:Rs,wrap:Zn,showScrollHint:!Zn,diffViewType:Cr,inlineMode:an,diffOptions:Gh,reloadKey:Er,renderStreamBadge:_=>o.jsx(Hf,{status:_}),onHunkGitAction:Vh,onInsertDiffReference:Yi,onReferenceCopied:ya,insertedReferenceKey:Ze,copiedReferenceKey:Fe,onClearAuditRecord:hu,onDetailScroll:id})})]}),ze&&o.jsx(cJ,{value:Ce,collapsed:We,autoCollapseAfterSend:xe,focusRequest:pt,insertError:or?C("rightSidebar.contextDraftInsertFailed"):null,onChange:_=>{Le(!1),Qe(_)},onCollapsedChange:W,onAutoCollapseAfterSendChange:He,onDisable:()=>Be(!1),onClear:()=>Qe(""),onInsert:()=>Hs(!1),onInsertAndSend:()=>Hs(!0),labels:{title:C("rightSidebar.contextDraftTitle"),hint:C("rightSidebar.contextDraftHint"),placeholder:C("rightSidebar.contextDraftPlaceholder"),collapse:C("rightSidebar.contextDraftCollapse"),expand:C("rightSidebar.contextDraftExpand"),disable:C("rightSidebar.contextDraftDisable"),clear:C("rightSidebar.contextDraftClear"),insert:C("rightSidebar.contextDraftInsert"),insertAndSend:C("rightSidebar.contextDraftInsertAndSend"),inserted:C("rightSidebar.contextDraftInserted"),sent:C("rightSidebar.contextDraftSent"),send:C("rightSidebar.contextDraftSend"),appended:C("rightSidebar.contextDraftAppended"),resize:C("rightSidebar.contextDraftResize"),autoCollapseAfterSend:C("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:_=>C("rightSidebar.contextDraftCharacterCount",{count:_})}}),Vg(),er&&o.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Mr(null),children:o.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:_=>_.stopPropagation(),children:[o.jsx("div",{className:"text-sm font-semibold text-foreground",children:er.kind==="restore"?C("rightSidebar.confirmRestoreTitle"):C("rightSidebar.confirmStashAllTitle")}),o.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:er.kind==="restore"?C("rightSidebar.confirmRestoreDescription",{path:Ag(er.file.absolutePath,Ae)}):C("rightSidebar.confirmStashAllDescription")}),er.kind==="restore"&&o.jsx("input",{value:er.phrase,onChange:_=>Mr({...er,phrase:_.target.value}),placeholder:C("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),o.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[o.jsx("button",{type:"button",onClick:()=>Mr(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:C("common.cancel")}),o.jsx("button",{type:"button",disabled:!!cr||er.kind==="restore"&&er.phrase.trim()!==C("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(er.kind==="restore"){const _=Oo(er.file,Ae);if(!_)return;wi({action:"restore-worktree-file",cwd:_,paths:[er.file.path],confirm:{acknowledged:!0,phrase:er.phrase}},C("rightSidebar.restoreFile"),ub(er.file))}else{const _=er.repoRoot??Ae;if(!_)return;wi({action:"stash-all",cwd:_},C("rightSidebar.stashAll"),`repo:${_}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${er.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:C(cr?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})})]})}function xte(e){return e>=90?"var(--destructive)":e>=70?"var(--warning)":"var(--success)"}function bte(e){return e>=90?"var(--destructive)/0.15":e>=70?"var(--warning)/0.15":"var(--success)/0.12"}function yte(e){if(!e)return"";const t=new Date(e),n=Date.now(),r=t.getTime()-n;if(r<=0)return"";const s=Math.floor(r/6e4),i=Math.floor(s/60),a=Math.floor(i/24),c=i%24,u=s%60,f=t.toLocaleDateString(void 0,{month:"short",day:"numeric"}),p=t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"});let g;return a>0?g=`${a}d ${c}h`:c>0?g=`${c}h ${u}m`:u>0?g=`${u}m`:g="soon",`resets in ${g} (${f} ${p})`}function vte(e){return{claude:"🧠",codex:"✨",kimi:"🌙",copilot:"🐙",grok:"🚀",gemini:"💎"}[e]||"📊"}function wte({result:e}){const{t}=Yn(),n=e.windows.filter(c=>c.percent===0&&!c.resetAt),r=e.windows.filter(c=>c.percent>0||c.resetAt),s=n.length>0?n.map(c=>c.label).join(" · "):"",i=!!e.error;let a=null;return!i&&e.entitlement&&(e.usagePercent>=90?a=t("quota.exhausted"):e.remaining!==void 0&&e.remaining<e.entitlement?a=t("quota.left",{n:e.remaining}):a=`${Math.round(e.usagePercent)}%`),o.jsxs("div",{className:"rounded-xl border border-border/15 bg-surface-2 p-3 sm:p-4",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[13px] font-semibold text-foreground",children:[o.jsx("span",{className:"shrink-0",children:vte(e.slug)}),o.jsx("span",{className:"truncate",children:e.displayName}),s&&o.jsx("span",{className:"shrink-0 rounded-full bg-surface-elevated px-2 py-0.5 text-[10px] font-normal text-muted-foreground",children:s})]}),a&&o.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:a})]}),r.length>0?o.jsx("div",{className:"mt-2.5 space-y-2",children:r.map(c=>{const u=Math.max(0,Math.min(100,c.percent));return o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-2 text-[12px]",children:[o.jsx("span",{className:"w-14 shrink-0 truncate text-muted-foreground sm:w-16",children:c.label}),o.jsx("div",{className:"flex-1",children:o.jsx("div",{className:"h-2 rounded-full",style:{background:bte(c.percent)},children:o.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${u}%`,background:xte(c.percent)}})})}),o.jsxs("span",{className:"w-9 shrink-0 text-right tabular-nums font-medium text-foreground",children:[Math.round(c.percent),"%"]})]}),c.resetAt&&o.jsx("p",{className:"mt-1 pl-14 text-[10px] text-muted-foreground sm:pl-16",children:yte(c.resetAt)})]},c.label)})}):i?o.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:e.error}):null]})}function Ste({isOpen:e,onClose:t}){const{t:n}=Yn(),[r,s]=b.useState([]),[i,a]=b.useState(!1),c=async(p=!1)=>{a(!0);try{const g=p?await rE():await nE();s(g.providers||[])}catch{}finally{a(!1)}};if(b.useEffect(()=>{e&&c()},[e]),b.useEffect(()=>{if(!e)return;const p=g=>{const y=g.detail;Array.isArray(y)&&s(y)};return window.addEventListener("termdock:quota-update",p),()=>{window.removeEventListener("termdock:quota-update",p)}},[e]),!e)return null;const u=r.filter(p=>!p.error),f=u.length>0?new Date(Math.max(...u.map(p=>p.fetchedAt||0))):null;return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:t}),o.jsxs("div",{className:"fixed inset-x-3 z-modal-panel mx-auto flex max-w-lg flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)]",style:{top:"max(1.5rem, env(safe-area-inset-top, 0px))",bottom:"max(1.5rem, env(safe-area-inset-bottom, 0px))"},children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-3 py-2.5 sm:px-6 sm:py-3",children:[o.jsx("h2",{className:"text-[14px] font-semibold text-foreground sm:text-base",children:n("quota.title")}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("button",{type:"button",onClick:()=>c(!0),disabled:i,className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50","aria-label":n("quota.refresh"),children:o.jsx(Us,{size:15,className:i?"animate-spin":""})}),o.jsx("button",{type:"button",onClick:t,className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":n("quota.close"),children:o.jsx(ts,{size:17})})]})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-3 sm:p-5",children:[i&&u.length===0?o.jsx("div",{className:"flex items-center justify-center py-12",children:o.jsx(Us,{size:24,className:"animate-spin text-muted-foreground"})}):u.length===0?o.jsxs("div",{className:"py-8 text-center text-[13px] text-muted-foreground",children:[o.jsx("p",{children:n("quota.noProviders")}),o.jsx("p",{className:"mt-1.5 text-[11px]",children:n("quota.noProvidersHint")})]}):o.jsx("div",{className:"space-y-2.5",children:u.map(p=>o.jsx(wte,{result:p},p.slug))}),f&&o.jsx("p",{className:"mt-3 text-center text-[10px] text-muted-foreground",children:n("quota.updated",{time:f.toLocaleTimeString()})})]})]})]})}const s7=[{label:"Esc",sequence:"\\u001b"},{label:"Tab",sequence:"\\t"},{label:"Enter",sequence:"\\r"},{label:"S-Tab",sequence:"\\u001b[Z"},{label:"C-c",sequence:"\\u0003"},{label:"C-d",sequence:"\\u0004"},{label:"C-l",sequence:"\\u000c"},{label:"C-r",sequence:"\\u0012"},{label:"C-z",sequence:"\\u001a"},{label:"C-w",sequence:"\\u0017"},{label:"Up",sequence:"\\u001b[A"},{label:"Down",sequence:"\\u001b[B"},{label:"Left",sequence:"\\u001b[D"},{label:"Right",sequence:"\\u001b[C"},{label:"PgUp",sequence:"\\u001b[5~"},{label:"PgDn",sequence:"\\u001b[6~"}],Ate=2,Tte=20;function Cte({label:e}){return o.jsx("div",{className:"h-7 rounded-full bg-surface-2 px-3 text-[11px] leading-7 text-center text-muted-foreground truncate",children:e})}function kte({value:e,onChange:t,placeholder:n}){const{t:r}=Yn(),[s,i]=D.useState(""),a=g=>{const y=[];let v="",S=!1;const A=()=>{const L=v.trim();L&&y.push(L),v=""};for(let L=0;L<g.length;L+=1){const I=g[L];if(!S&&I==="/"&&v.trim().length===0){S=!0,v+=I;continue}if(S){if(v+=I,I==="/"&&g[L-1]!=="\\"&&v.length>1){for(;L+1<g.length&&/[gimsuy]/.test(g[L+1]??"");)L+=1,v+=g[L];A(),S=!1}continue}if(I===","||/\s/.test(I)){A();continue}v+=I}if(A(),y.length===0)return;const T=[...e];for(const L of y){const I=pS(L);I&&(T.includes(I)||T.push(I))}t(T),i("")},c=g=>{t(e.filter(y=>y!==g))},u=s.trim(),f=u.length>0&&Pw(u),p=f&&!Rm(u);return o.jsx("div",{className:"rounded-2xl bg-surface px-3 py-2 ring-1 ring-border/15 focus-within:ring-accent/40",children:o.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.map(g=>{const y=Pw(g),v=y&&!Rm(g);return o.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-[11px] ${v?"bg-destructive/15 text-destructive":y?"bg-accent/15 font-mono text-accent":"bg-surface-elevated text-foreground"}`,title:y?v?r("settings.invalidRegex"):"Regex match":"Substring match (case-insensitive)",children:[y&&o.jsx("span",{className:"text-[10px] opacity-70",children:"re"}),g,o.jsx("button",{type:"button",onClick:()=>c(g),className:"rounded-full p-0.5 text-muted-foreground hover:bg-destructive/20 hover:text-destructive","aria-label":r("toolbarPresets.removeAction",{name:g}),children:o.jsx(ts,{size:12})})]},g)}),o.jsx("input",{type:"text",value:s,onChange:g=>i(g.target.value),onKeyDown:g=>{g.key==="Enter"||g.key===","&&!f?(g.preventDefault(),a(s)):g.key==="Backspace"&&s.length===0&&e.length>0&&c(e[e.length-1])},onBlur:()=>a(s),placeholder:e.length===0?n:"",className:`min-w-[8ch] flex-1 bg-transparent py-1 text-sm outline-none placeholder:text-muted/60 ${f?"font-mono":""} ${p?"text-destructive":""}`,autoCapitalize:"off",autoCorrect:"off",autoComplete:"off"})]})})}function _te({value:e,min:t,max:n,onChange:r}){const{t:s}=Yn();return o.jsxs("div",{className:"inline-flex items-center gap-1 rounded-full bg-surface px-1 py-1 ring-1 ring-border/15",children:[o.jsx("button",{type:"button",onClick:()=>r(Math.max(t,e-1)),disabled:e<=t,className:"h-7 w-7 rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated disabled:opacity-40 inline-flex items-center justify-center","aria-label":s("common.decrease"),children:o.jsx(iM,{size:14})}),o.jsx("span",{className:"w-6 text-center text-sm font-medium tabular-nums text-foreground",children:e}),o.jsx("button",{type:"button",onClick:()=>r(Math.min(n,e+1)),disabled:e>=n,className:"h-7 w-7 rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated disabled:opacity-40 inline-flex items-center justify-center","aria-label":s("common.increase"),children:o.jsx(Ao,{size:14})})]})}const Lte=({presets:e,selectedPresetId:t,onSelectPreset:n,onUpdatePreset:r,onAddPreset:s,onRemovePreset:i,onResetDefaults:a})=>{const{t:c}=Yn(),u=e.find(L=>L.id===t)??e[0]??null,[f,p]=D.useState(null);if(!u)return null;const g=u.actions.length>0,y=[{id:"preview-auto",label:u.label,kind:"preset"},...u.includeAlt?[{id:"preview-alt",label:"Alt"}]:[],...g?u.actions.map((L,I)=>({id:L.id,label:Ub(L,I)})):["Enter","Home","End","Ctrl-C","Ctrl-D"].map(L=>({id:L,label:L}))],v=mS(y,u.rowLayout),S=(L,I)=>{r(u.id,j=>{const P=j.actions.findIndex(C=>C.id===L);if(P===-1)return j;const F=P+I;if(F<0||F>=j.actions.length)return j;const R=[...j.actions];return[R[P],R[F]]=[R[F],R[P]],{...j,actions:R}})},A=u.rowLayout.reduce((L,I)=>L+I,0),T=1+(u.includeAlt?1:0);return o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{className:"sticky top-[-1rem] sm:top-[-1.5rem] z-10 -mx-4 -mt-4 sm:-mx-6 sm:-mt-6 border-b border-border/15 bg-surface/95 backdrop-blur px-4 py-3 sm:px-6",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.preview")}),o.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[u.actions.length," button",u.actions.length===1?"":"s"," · ",A," slot",A===1?"":"s"]})]}),o.jsx("div",{className:"space-y-1 rounded-2xl bg-surface-2/60 p-2",children:v.map((L,I)=>{const j=L.items[0]?.kind==="preset",P=Math.max(2,L.columns),F=j?`${gS}px repeat(${Math.max(1,P-1)}, minmax(0, 1fr))`:`repeat(${P}, minmax(0, 1fr))`;return o.jsx("div",{className:"grid gap-1",style:{gridTemplateColumns:F},children:L.items.map(R=>R.kind==="preset"?o.jsx(xS,{mode:"auto",presetLabel:R.label,title:`Auto preset · ${R.label}`,disabled:!0},R.id):o.jsx(Cte,{label:R.label},R.id))},`preview-row-${I}`)})}),u.actions.length>A-T&&o.jsx("p",{className:"mt-1.5 text-[10px] text-muted-foreground",children:c("toolbarPresets.overCapacityHint")})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.presets")}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs("button",{type:"button",onClick:s,className:"inline-flex items-center gap-1 rounded-full bg-surface-2 px-3 py-2 text-xs font-medium hover:bg-surface-elevated transition",children:[o.jsx(Ao,{size:14}),c("toolbarPresets.new")]}),o.jsxs("button",{type:"button",onClick:a,className:"inline-flex items-center gap-1 rounded-full bg-surface-2 px-3 py-2 text-xs font-medium hover:bg-surface-elevated transition",children:[o.jsx(Us,{size:14}),c("toolbarPresets.reset")]})]})]}),o.jsx("div",{className:"-mx-1 flex flex-wrap gap-1.5 px-1",children:e.map(L=>o.jsxs("button",{type:"button",onClick:()=>n(L.id),className:`rounded-full px-3 py-2 text-xs font-medium transition ${L.id===u.id?"bg-primary/20 text-primary ring-1 ring-primary/30":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated"}`,children:[L.label,L.actions.length>0&&o.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:L.actions.length})]},L.id))})]}),o.jsxs("div",{className:"space-y-4 rounded-2xl bg-surface p-4 ring-1 ring-border/10",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.label")}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("input",{type:"text",value:u.label,onChange:L=>r(u.id,I=>({...I,label:L.target.value})),className:"flex-1 rounded-full bg-surface-2 px-4 py-2.5 text-sm placeholder:text-muted/60 outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.presetLabelPlaceholder"),autoCapitalize:"off",autoCorrect:"off"}),u.id!=="default"&&o.jsx("button",{type:"button",onClick:()=>i(u.id),className:"shrink-0 rounded-full bg-surface-2 px-3 py-2.5 text-destructive hover:bg-destructive/15","aria-label":c("toolbarPresets.deletePreset",{name:u.label}),children:o.jsx($i,{size:14})})]})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.matchPrograms")}),o.jsx("span",{className:"text-[10px] text-muted-foreground",children:c("toolbarPresets.typeEnterHint")})]}),o.jsx(kte,{value:u.programs,onChange:L=>r(u.id,I=>({...I,programs:L})),placeholder:c("toolbarPresets.programsPlaceholder")}),o.jsx("p",{className:"text-[10px] text-muted-foreground",children:c("toolbarPresets.programsHelp")})]}),o.jsxs("button",{type:"button",onClick:()=>r(u.id,L=>({...L,includeAlt:!L.includeAlt})),className:"flex w-full items-center justify-between rounded-2xl bg-surface-2 px-4 py-3 text-sm transition hover:bg-surface-elevated",children:[o.jsxs("span",{children:[o.jsx("span",{className:"block font-medium text-foreground",children:c("toolbarPresets.altSlot")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:c("toolbarPresets.altSlotHint")})]}),o.jsx(xc,{checked:u.includeAlt})]}),o.jsxs("button",{type:"button",onClick:()=>r(u.id,L=>({...L,showOnDesktop:!L.showOnDesktop})),className:"flex w-full items-center justify-between rounded-2xl bg-surface-2 px-4 py-3 text-sm transition hover:bg-surface-elevated",children:[o.jsxs("span",{children:[o.jsx("span",{className:"block font-medium text-foreground",children:c("toolbarPresets.desktopVisibility")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:c("toolbarPresets.desktopVisibilityHint")})]}),o.jsx(xc,{checked:u.showOnDesktop===!0})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.rowLayout")}),o.jsx("p",{className:"text-[11px] text-muted-foreground",children:c("toolbarPresets.rowLayoutHint")})]}),o.jsxs("button",{type:"button",onClick:()=>r(u.id,L=>({...L,rowLayout:[...yy(L.rowLayout),3]})),className:"inline-flex items-center gap-1 rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium hover:bg-surface-elevated",children:[o.jsx(Ao,{size:12}),c("toolbarPresets.addRow")]})]}),o.jsx("div",{className:"space-y-2",children:u.rowLayout.map((L,I)=>o.jsxs("div",{className:"flex items-center gap-3 rounded-2xl bg-surface-2 px-3 py-2",children:[o.jsx("span",{className:"w-12 shrink-0 text-xs text-muted-foreground",children:c("toolbarPresets.rowN",{n:I+1})}),o.jsx("div",{className:"flex-1"}),o.jsx(_te,{value:L,min:Ate,max:Tte,onChange:j=>r(u.id,P=>({...P,rowLayout:P.rowLayout.map((F,R)=>R===I?j:F)}))}),u.rowLayout.length>1&&o.jsx("button",{type:"button",onClick:()=>r(u.id,j=>({...j,rowLayout:j.rowLayout.filter((P,F)=>F!==I)})),className:"rounded-full bg-surface px-2.5 py-1 text-[11px] text-muted-foreground hover:bg-destructive/15 hover:text-destructive","aria-label":c("toolbarPresets.removeRow",{n:I+1}),children:c("toolbarPresets.del")})]},`row-${I}`))})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{children:[o.jsx("span",{className:"ui-kicker",children:c("toolbarPresets.buttons")}),o.jsx("p",{className:"text-[11px] text-muted-foreground",children:c("toolbarPresets.buttonsHint")})]}),o.jsxs("button",{type:"button",onClick:()=>{const L=`${u.id}-action-${Date.now()}`;r(u.id,I=>({...I,actions:[...I.actions,{id:L,label:`Key ${I.actions.length+1}`,sequence:""}]})),p(L)},className:"inline-flex items-center gap-1 rounded-full bg-primary/15 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/25",children:[o.jsx(Ao,{size:12}),c("toolbarPresets.addButton")]})]}),u.actions.length===0&&o.jsx("div",{className:"rounded-2xl bg-surface-2/60 px-4 py-6 text-center text-[11px] text-muted-foreground",children:c("toolbarPresets.noCustomButtons")}),u.actions.map((L,I)=>{const j=f===L.id;return o.jsxs("div",{className:`rounded-2xl bg-surface-2 transition ${j?"ring-1 ring-accent/40":""}`,children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[o.jsxs("div",{className:"flex flex-col gap-0.5",children:[o.jsx("button",{type:"button",onClick:()=>S(L.id,-1),disabled:I===0,className:"h-6 w-6 rounded-full bg-surface text-muted-foreground hover:bg-surface-elevated disabled:opacity-30 inline-flex items-center justify-center","aria-label":c("toolbarPresets.moveUp"),children:o.jsx(xg,{size:12})}),o.jsx("button",{type:"button",onClick:()=>S(L.id,1),disabled:I===u.actions.length-1,className:"h-6 w-6 rounded-full bg-surface text-muted-foreground hover:bg-surface-elevated disabled:opacity-30 inline-flex items-center justify-center","aria-label":c("toolbarPresets.moveDown"),children:o.jsx(p8,{size:12})})]}),o.jsxs("button",{type:"button",onClick:()=>p(j?null:L.id),className:"min-w-0 flex-1 text-left",children:[o.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Ub(L,I)}),o.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[L.sequence?L.sequence:c("toolbarPresets.noSequence"),L.doubleTapSequence&&o.jsxs("span",{className:"ml-1 text-accent/70",children:["· 2× ",L.doubleTapSequence]})]})]}),o.jsx("button",{type:"button",onClick:()=>r(u.id,P=>({...P,actions:P.actions.filter(F=>F.id!==L.id)})),className:"shrink-0 rounded-full bg-surface p-2 text-muted-foreground hover:bg-destructive/15 hover:text-destructive","aria-label":c("toolbarPresets.removeAction",{name:L.label}),children:o.jsx($i,{size:14})})]}),j&&o.jsxs("div",{className:"space-y-3 border-t border-border/10 px-3 py-3",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c("toolbarPresets.labelField")}),o.jsx("input",{type:"text",value:L.label,onChange:P=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,label:P.target.value}:R)})),className:"w-full rounded-full bg-surface px-4 py-2.5 text-sm outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.labelPlaceholder"),autoCapitalize:"off",autoCorrect:"off"})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c("toolbarPresets.sequence")}),o.jsx("input",{type:"text",value:L.sequence,onChange:P=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,sequence:P.target.value}:R)})),className:"w-full rounded-full bg-surface px-4 py-2.5 font-mono text-sm outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.sequencePlaceholder"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),o.jsx("div",{className:"flex flex-wrap gap-1.5 pt-1",children:s7.map(P=>o.jsx("button",{type:"button",onClick:()=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,sequence:P.sequence}:R)})),className:"rounded-full bg-surface px-2.5 py-1 text-[11px] font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:P.label},P.label))})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c("toolbarPresets.doubleTap")}),!L.doubleTapSequence&&o.jsx("button",{type:"button",onClick:()=>r(u.id,P=>({...P,actions:P.actions.map(F=>F.id===L.id?{...F,doubleTapSequence:""}:F)})),className:"text-[10px] text-accent hover:text-accent/80",children:c("toolbarPresets.doubleTapAdd")})]}),L.doubleTapSequence!==void 0&&o.jsxs(o.Fragment,{children:[o.jsx("input",{type:"text",value:L.doubleTapSequence,onChange:P=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,doubleTapSequence:P.target.value}:R)})),className:"w-full rounded-full bg-surface px-4 py-2.5 font-mono text-sm outline-none ring-1 ring-transparent focus:ring-accent/40",placeholder:c("toolbarPresets.doubleTapPlaceholder"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),o.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[s7.map(P=>o.jsx("button",{type:"button",onClick:()=>r(u.id,F=>({...F,actions:F.actions.map(R=>R.id===L.id?{...R,doubleTapSequence:(R.doubleTapSequence??"")+P.sequence}:R)})),className:"rounded-full bg-surface px-2.5 py-1 text-[11px] font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:P.label},P.label)),o.jsx("button",{type:"button",onClick:()=>r(u.id,P=>({...P,actions:P.actions.map(F=>{if(F.id!==L.id)return F;const{doubleTapSequence:R,...C}=F;return C})})),className:"rounded-full bg-destructive/10 px-2.5 py-1 text-[11px] font-medium text-destructive/70 hover:bg-destructive/20 hover:text-destructive",children:c("toolbarPresets.remove")})]})]})]})]})]},L.id)})]})]})]})},Ete={installed:"text-[color:var(--success)]",outdated:"text-[color:var(--warning)]","needs-approval":"text-[color:var(--warning)]","not-installed":"text-muted-foreground"};function Ite(){const{t:e}=Yn(),[t,n]=D.useState(null),[r,s]=D.useState(null),[i,a]=D.useState(null),[c,u]=D.useState(null),[f,p]=D.useState(!1),[g,y]=D.useState(!1),[v,S]=D.useState(""),[A,T]=D.useState(""),[L,I]=D.useState(null),[j,P]=D.useState([]),[F,R]=D.useState([]),[C,$]=D.useState(null),[H,Y]=D.useState(new Set),[V,fe]=D.useState(null),[X,ve]=D.useState("auto"),[we,ie]=D.useState({}),[ae,q]=D.useState(null),[z,te]=D.useState(null),[pe,de]=D.useState(10),[ke,be]=D.useState(""),[oe,he]=D.useState(""),[J,Xe]=D.useState(12e3),[lt,Ze]=D.useState(null),[ge,Fe]=D.useState(null),Te=D.useCallback(async()=>{const[Le,ot,Oe,Dt]=await Promise.allSettled([HE(),GE(),dh(),H0()]);if(n(Le.status==="fulfilled"?Le.value:[]),ot.status==="fulfilled"){const $e=ot.value;P($e.plugins??[]),R($e.errors??[])}else P([]),R([]);if(Oe.status==="fulfilled"){const $e=Oe.value;Y(new Set($e.autoRenameAgents??[])),ve($e.autoRenameNamer??"auto"),ie($e.autoRenameModels??{}),de($e.autoRenameIntervalMinutes??10),be($e.autoRenamePromptPreference??""),he($e.autoRenamePromptPreference??""),Xe($e.autoRenamePromptPayloadChars??12e3)}else Y(new Set);q(Dt.status==="fulfilled"?Dt.value:[])},[]);D.useEffect(()=>{Te()},[Te]);const ze=async(Le,ot)=>{s(Le),a(null);try{ot==="install"?(await UE(Le)).devMode&&u(Le):(await zE(Le),c===Le&&u(null)),await Te()}catch(Oe){a(Oe instanceof Error?Oe.message:String(Oe))}finally{s(null)}},Be=Le=>e(Le==="installed"?"settings.agentHooksInstalled":Le==="outdated"?"settings.agentHooksOutdated":Le==="needs-approval"?"settings.agentHooksNeedsApproval":"settings.agentHooksNotInstalled"),We=async()=>{I(null);let Le;try{Le=JSON.parse(A)}catch{I("Invalid JSON");return}try{await WE(Le),T(""),p(!1),await Te()}catch(ot){if(ot instanceof Z2&&ot.migration){R(Oe=>[{slug:typeof Le.slug=="string"?Le.slug:"manifest.json",errors:ot.message.split(`
220
220
  `),code:ot.code,migration:ot.migration},...Oe.filter(Dt=>Dt.slug!==Le.slug)]);return}I(ot instanceof Error?ot.message:String(ot))}},W=async()=>{const Le=v.trim();if(Le){Ze("install"),I(null);try{await VE(Le),S(""),y(!1),await Te()}catch(ot){I(ot instanceof Error?ot.message:String(ot))}finally{Ze(null)}}},xe=async Le=>{Ze(`remove:${Le}`);try{await XE(Le),Fe(ot=>ot?.slug===Le?null:ot),await Te()}catch(ot){a(ot instanceof Error?ot.message:String(ot))}finally{Ze(null)}},He=async Le=>{Ze(`check:${Le}`),a(null);try{await qE(Le),await Te()}catch(ot){a(ot instanceof Error?ot.message:String(ot))}finally{Ze(null)}},Ce=async Le=>{Ze(`update:${Le}`),a(null);try{const ot=await YE(Le),Oe=[ot.hookWarning,ot.titleWarning].filter(Boolean).join(" ");Oe&&a(Oe),Fe(Dt=>Dt?.slug===Le?null:Dt),await Te()}catch(ot){a(ot instanceof Error?ot.message:String(ot))}finally{Ze(null)}},Qe=async Le=>{Ze(`doctor:${Le}`),a(null),Fe(null);try{const ot=await KE(Le);Fe(ot),q(await H0())}catch(ot){a(ot instanceof Error?ot.message:String(ot))}finally{Ze(null)}},pt=async Le=>{const ot=Le.migration?.aiPrompt??Le.errors.join(`
221
- `);try{await navigator.clipboard.writeText(ot),$(Le.slug),window.setTimeout(()=>$(Oe=>Oe===Le.slug?null:Oe),1800)}catch{I(ot)}},At=async Le=>{if(V)return;const ot=H,Oe=new Set(ot);Oe.has(Le)?Oe.delete(Le):Oe.add(Le),Y(Oe),fe(Le),a(null);try{const Dt=await ta({autoRenameAgents:[...Oe]});Y(new Set(Dt.autoRenameAgents??[])),q(await H0(!0))}catch(Dt){Y(ot),a(Dt instanceof Error?Dt.message:String(Dt))}finally{fe(null)}},yt=async Le=>{const ot=X;ve(Le),te("namer"),a(null);try{const Oe=await ta({autoRenameNamer:Le});ve(Oe.autoRenameNamer??"auto"),q(await H0(!0))}catch(Oe){ve(ot),a(Oe instanceof Error?Oe.message:String(Oe))}finally{te(null)}},Yt=async(Le,ot)=>{const Oe=we,Dt={...Oe};ot?Dt[Le]=ot:delete Dt[Le],ie(Dt),te(Le),a(null);try{const $e=await ta({autoRenameModels:Dt});ie($e.autoRenameModels??{})}catch($e){ie(Oe),a($e instanceof Error?$e.message:String($e))}finally{te(null)}},Mt=async Le=>{const ot=pe;de(Le),te("interval"),a(null);try{const Oe=await ta({autoRenameIntervalMinutes:Le});de(Oe.autoRenameIntervalMinutes??10)}catch(Oe){de(ot),a(Oe instanceof Error?Oe.message:String(Oe))}finally{te(null)}},on=async()=>{const Le=ke.trim();if(Le!==oe){te("preference"),a(null);try{const Oe=(await ta({autoRenamePromptPreference:Le})).autoRenamePromptPreference??"";be(Oe),he(Oe)}catch(ot){be(oe),a(ot instanceof Error?ot.message:String(ot))}finally{te(null)}}},xr=async Le=>{const ot=Math.max(1e3,Math.min(64e3,Math.round(Le||12e3))),Oe=J;Xe(ot),te("payload-limit"),a(null);try{const Dt=await ta({autoRenamePromptPayloadChars:ot});Xe(Dt.autoRenamePromptPayloadChars??12e3)}catch(Dt){Xe(Oe),a(Dt instanceof Error?Dt.message:String(Dt))}finally{te(null)}},Cn=new Set(j.map(Le=>Le.slug)),or=ge?{ok:e("settings.agentPluginDoctorStatusOk"),"missing-title-namer":e("settings.agentPluginDoctorStatusMissing"),"cli-default":e("settings.agentPluginDoctorStatusCliDefault"),"no-models":e("settings.agentPluginDoctorStatusNoModels"),"probe-failed":e("settings.agentPluginDoctorStatusFailed")}[ge.status]:"";return o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"rounded-xl bg-surface-2 px-3 py-2.5",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:e("settings.agentAutoRename")}),o.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:e("settings.agentAutoRenameHint")}),o.jsxs("label",{className:"mt-2 flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-[11px] text-muted-foreground",children:e("settings.agentAutoRenameNamer")}),o.jsxs("select",{value:X,disabled:z!==null,onChange:Le=>{yt(Le.target.value)},className:"min-w-0 rounded-lg bg-surface px-2.5 py-1.5 text-[11px] text-foreground outline-none disabled:opacity-50",children:[o.jsx("option",{value:"auto",children:e("settings.agentAutoRenameFollow")}),ae?.filter(Le=>Le.available).map(Le=>o.jsx("option",{value:Le.slug,children:Le.displayName},Le.slug))]})]}),o.jsxs("label",{className:"mt-2 flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-[11px] text-muted-foreground",children:e("settings.agentAutoRenameInterval")}),o.jsx("select",{value:pe,disabled:z!==null,onChange:Le=>{Mt(Number(Le.target.value))},className:"min-w-0 rounded-lg bg-surface px-2.5 py-1.5 text-[11px] text-foreground outline-none disabled:opacity-50",children:[5,10,30,60].map(Le=>o.jsxs("option",{value:Le,children:[Le," ",e("settings.agentAutoRenameMinutes")]},Le))})]}),o.jsxs("details",{className:"mt-2 border-t border-border/40 pt-2",children:[o.jsx("summary",{className:"cursor-pointer select-none text-[11px] text-muted-foreground transition hover:text-foreground",children:e("settings.agentAutoRenameAdvanced")}),o.jsxs("label",{className:"mt-2 block",children:[o.jsx("span",{className:"text-[11px] font-medium text-foreground",children:e("settings.agentAutoRenamePreference")}),o.jsx("span",{className:"mt-0.5 block text-[10px] text-muted-foreground",children:e("settings.agentAutoRenamePreferenceHint")}),o.jsx("textarea",{value:ke,maxLength:2e3,rows:3,disabled:z!==null,placeholder:e("settings.agentAutoRenamePreferencePlaceholder"),onChange:Le=>be(Le.target.value),onBlur:()=>{on()},className:"mt-1.5 w-full resize-y rounded-lg bg-surface px-2.5 py-2 text-[11px] text-foreground outline-none placeholder:text-muted-foreground/70 focus:ring-1 focus:ring-primary/50 disabled:opacity-50"}),o.jsx("span",{className:"mt-1 block text-right text-[10px] text-muted-foreground",children:z==="preference"?e("settings.saving"):`${ke.length}/2000`})]}),o.jsxs("label",{className:"mt-2 block",children:[o.jsx("span",{className:"text-[11px] font-medium text-foreground",children:e("settings.agentAutoRenamePayloadLimit")}),o.jsx("span",{className:"mt-0.5 block text-[10px] text-muted-foreground",children:e("settings.agentAutoRenamePayloadLimitHint")}),o.jsx("input",{type:"number",min:1e3,max:64e3,step:1e3,value:J,disabled:z!==null,onChange:Le=>Xe(Number(Le.target.value)),onBlur:Le=>{xr(Number(Le.target.value))},className:"mt-1.5 w-full rounded-lg bg-surface px-2.5 py-2 text-[11px] text-foreground outline-none focus:ring-1 focus:ring-primary/50 disabled:opacity-50"})]})]}),o.jsxs("div",{className:"mt-2 space-y-1.5 border-t border-border/40 pt-2",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("span",{className:"text-[10px] text-muted-foreground",children:e("settings.agentAutoRenameModelsFromCli")}),o.jsx("button",{type:"button",onClick:async()=>{q(null);try{q(await H0(!0))}catch{q([])}},className:"rounded p-1 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",title:e("settings.agentAutoRenameRefreshModels"),children:o.jsx(Us,{size:11,className:ae===null?"animate-spin":""})})]}),ae?.filter(Le=>Le.available).map(Le=>{const ot=Le.models.find(Oe=>Oe.id===Le.recommendedModel);return o.jsxs("label",{className:"flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-[11px] text-muted-foreground",children:Le.displayName}),o.jsxs("select",{value:we[Le.slug]??"",disabled:z!==null,onChange:Oe=>{Yt(Le.slug,Oe.target.value)},className:"min-w-0 max-w-[68%] rounded-lg bg-surface px-2.5 py-1.5 text-[11px] text-foreground outline-none disabled:opacity-50",children:[o.jsx("option",{value:"",children:ot?`${e("settings.agentAutoRenameAutomatic")} · ${ot.displayName}`:e("settings.agentAutoRenameCliDefault")}),Le.models.map(Oe=>o.jsx("option",{value:Oe.id,children:Oe.displayName},Oe.id))]})]},Le.slug)}),ae?.length===0&&o.jsx("div",{className:"text-[10px] text-[color:var(--warning)]",children:e("settings.agentAutoRenameNoCli")})]})]}),t===null&&o.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[o.jsx(Fn,{size:12,className:"animate-spin"})," …"]}),t?.map(Le=>{const ot=r===Le.slug,Oe=Le.state!=="not-installed",Dt=Cn.has(Le.slug);return o.jsxs("div",{className:"flex items-center gap-3 rounded-xl bg-surface-2 px-3 py-2.5",children:[o.jsx(Hu,{agent:{slug:Le.slug,displayName:Le.displayName,accentColor:Le.accentColor??"#878580",icon:Le.icon,isPlugin:Dt,iconMode:Le.iconMode,iconVersion:Le.iconVersion??void 0},size:18}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[13px] font-medium text-foreground",children:Le.displayName}),Dt&&o.jsx("span",{className:"rounded bg-[rgb(var(--success-rgb)_/_0.12)] px-1 py-px text-[9px] font-medium text-[color:var(--success)]",children:"plugin"}),o.jsxs("span",{className:`text-[10px] ${kte[Le.state]}`,children:[Le.state==="installed"&&o.jsx(_b,{size:10,className:"mr-0.5 inline"}),(Le.state==="outdated"||Le.state==="needs-approval")&&o.jsx(yg,{size:10,className:"mr-0.5 inline"}),Be(Le.state)]})]}),o.jsxs("div",{className:"truncate text-[10px] text-muted-foreground",title:Le.targetDisplay,children:[e("settings.agentHooksTarget")," ",Le.targetDisplay]}),c===Le.slug&&o.jsx("div",{className:"mt-0.5 text-[10px] text-[color:var(--warning)]",children:e("settings.agentHooksDevMode")}),Le.state==="needs-approval"&&o.jsx("div",{className:"mt-0.5 text-[10px] text-[color:var(--warning)]",children:e("settings.agentHooksApprovalHint")})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs("button",{type:"button",disabled:V!==null,onClick:()=>{At(Le.slug)},className:"flex shrink-0 items-center gap-1.5 rounded-full px-2 py-1 text-[10px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50","aria-pressed":H.has(Le.slug),title:e("settings.agentAutoRenameToggle"),children:[o.jsx("span",{children:e("settings.agentAutoRenameShort")}),o.jsx(xc,{checked:H.has(Le.slug),disabled:V!==null,size:"sm"})]}),o.jsxs("button",{type:"button",disabled:ot,onClick:()=>{ze(Le.slug,Oe?"uninstall":"install")},className:`flex shrink-0 items-center gap-1 rounded-full px-2.5 py-1 text-[11px] font-medium transition ${Oe?"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground":"bg-[rgb(var(--success-rgb)_/_0.14)] text-[color:var(--success)] hover:bg-[rgb(var(--success-rgb)_/_0.22)]"} disabled:opacity-50`,children:[ot?o.jsx(Fn,{size:11,className:"animate-spin"}):Oe?o.jsx($i,{size:11}):Le.state==="outdated"?o.jsx(Us,{size:11}):o.jsx(c0,{size:11}),ot?"…":Oe?e("settings.agentHooksUninstall"):Le.state==="outdated"?e("settings.agentHooksReinstall"):e("settings.agentHooksInstall")]})]})]},Le.slug)}),i&&o.jsx("div",{className:"rounded-xl bg-[rgb(var(--warning-rgb)_/_0.10)] px-3 py-2 text-[11px] text-[color:var(--warning)]",children:i}),o.jsxs("div",{className:"rounded-xl bg-surface-2 px-3 py-2.5",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground",children:e("settings.agentPlugins")}),o.jsxs("button",{type:"button",onClick:()=>y(!g),className:"flex items-center gap-1 rounded-full bg-[rgb(var(--success-rgb)_/_0.14)] px-2.5 py-1 text-[11px] font-medium text-[color:var(--success)] hover:bg-[rgb(var(--success-rgb)_/_0.22)] transition",children:[o.jsx(Ao,{size:11}),e("settings.agentPluginAdd")]})]}),o.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:e("settings.agentPluginHint")}),g&&o.jsxs("div",{className:"mt-2 space-y-2",children:[o.jsxs("div",{className:"flex gap-2",children:[o.jsx("input",{value:v,onChange:Le=>S(Le.target.value),onKeyDown:Le=>{Le.key==="Enter"&&W()},className:"min-w-0 flex-1 rounded-lg bg-surface px-3 py-2 font-mono text-[11px] text-foreground placeholder:text-muted-foreground outline-none",placeholder:e("settings.agentPluginSourcePlaceholder")}),o.jsxs("button",{type:"button",disabled:!v.trim()||lt!==null,onClick:()=>{W()},className:"flex items-center gap-1 rounded-full bg-[rgb(var(--success-rgb)_/_0.14)] px-3 py-1 text-[11px] font-medium text-[color:var(--success)] transition hover:bg-[rgb(var(--success-rgb)_/_0.22)] disabled:opacity-50",children:[lt==="install"?o.jsx(Fn,{size:11,className:"animate-spin"}):o.jsx(c0,{size:11}),e("settings.agentPluginInstallPackage")]})]}),o.jsx("button",{type:"button",onClick:()=>p(!f),className:"text-[10px] text-muted-foreground transition hover:text-foreground",children:e("settings.agentPluginAdvancedManifest")})]}),j.map(Le=>{const ot=Le.revision?.slice(0,8),Oe=lt?.endsWith(`:${Le.slug}`)===!0;return o.jsxs("div",{className:"mt-2 flex items-center gap-2 border-t border-border/40 pt-2",children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-medium text-foreground",children:[o.jsx("span",{className:"truncate",children:Le.displayName}),Le.updateAvailable&&o.jsx("span",{className:"text-[9px] text-[color:var(--warning)]",children:e("settings.agentPluginUpdateAvailable")})]}),o.jsxs("div",{className:"truncate text-[9px] text-muted-foreground",title:Le.source??void 0,children:[Le.source??e("settings.agentPluginManualSource"),ot?` · ${ot}`:""]})]}),o.jsxs("button",{type:"button",disabled:lt!==null,onClick:()=>{Qe(Le.slug)},className:"flex items-center gap-1 rounded-full bg-surface px-2 py-1 text-[10px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50",title:e("settings.agentPluginDoctorHint"),children:[lt===`doctor:${Le.slug}`?o.jsx(Fn,{size:10,className:"animate-spin"}):o.jsx(GM,{size:10}),e("settings.agentPluginDoctor")]}),Le.updateSupported&&o.jsxs("button",{type:"button",disabled:lt!==null,onClick:()=>{Le.updateAvailable?Ce(Le.slug):He(Le.slug)},className:"flex items-center gap-1 rounded-full bg-surface px-2 py-1 text-[10px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50",children:[Oe?o.jsx(Fn,{size:10,className:"animate-spin"}):o.jsx(Us,{size:10}),Le.updateAvailable?e("settings.agentPluginUpdate"):e("settings.agentPluginCheck")]}),o.jsx("button",{type:"button",disabled:lt!==null,onClick:()=>{xe(Le.slug)},className:"rounded-full p-1 text-muted-foreground transition hover:bg-surface-elevated hover:text-[color:var(--warning)] disabled:opacity-50",title:e("settings.agentPluginDelete"),children:o.jsx($i,{size:11})})]},Le.slug)}),ge&&o.jsxs("div",{className:`mt-2 rounded-lg px-3 py-2 text-[10px] ${ge.status==="ok"||ge.status==="cli-default"?"bg-[rgb(var(--success-rgb)_/_0.10)] text-[color:var(--success)]":"bg-[rgb(var(--warning-rgb)_/_0.10)] text-[color:var(--warning)]"}`,children:[o.jsxs("div",{className:"font-medium",children:[ge.displayName,": ",or]}),o.jsx("div",{className:"mt-1 text-muted-foreground",children:ge.models.length>0?`${ge.models.length} ${e("settings.agentPluginDoctorModels")}${ge.recommendedModel?` · ${e("settings.agentPluginDoctorAutomatic")} ${ge.recommendedModel}`:""}`:e("settings.agentPluginDoctorCliDefault")}),ge.error&&o.jsx("div",{className:"mt-1 break-words",children:ge.error}),ge.warnings.length>0&&o.jsx("div",{className:"mt-1 space-y-0.5 text-muted-foreground",children:ge.warnings.map(Le=>o.jsxs("div",{children:["• ",Le]},Le))}),ge.nextSteps.length>0&&o.jsx("div",{className:"mt-1 space-y-0.5 text-muted-foreground",children:ge.nextSteps.map(Le=>o.jsxs("div",{children:["→ ",Le]},Le))})]}),F.map(Le=>o.jsxs("div",{className:"mt-2 rounded-lg bg-[rgb(var(--warning-rgb)_/_0.10)] px-3 py-2 text-[10px] text-[color:var(--warning)]",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("span",{className:"font-medium",children:[Le.slug,": ",Le.code??e("settings.agentPluginInvalid")]}),o.jsxs("button",{type:"button",onClick:()=>{pt(Le)},className:"flex shrink-0 items-center gap-1 rounded-full bg-[rgb(var(--warning-rgb)_/_0.14)] px-2 py-1 font-medium transition hover:bg-[rgb(var(--warning-rgb)_/_0.22)]",children:[C===Le.slug?o.jsx(_b,{size:10}):o.jsx(b8,{size:10}),C===Le.slug?e("settings.agentPluginCopied"):e("settings.agentPluginCopyAiPrompt")]})]}),o.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-muted-foreground",children:Le.errors.join(`
221
+ `);try{await navigator.clipboard.writeText(ot),$(Le.slug),window.setTimeout(()=>$(Oe=>Oe===Le.slug?null:Oe),1800)}catch{I(ot)}},At=async Le=>{if(V)return;const ot=H,Oe=new Set(ot);Oe.has(Le)?Oe.delete(Le):Oe.add(Le),Y(Oe),fe(Le),a(null);try{const Dt=await ta({autoRenameAgents:[...Oe]});Y(new Set(Dt.autoRenameAgents??[])),q(await H0(!0))}catch(Dt){Y(ot),a(Dt instanceof Error?Dt.message:String(Dt))}finally{fe(null)}},yt=async Le=>{const ot=X;ve(Le),te("namer"),a(null);try{const Oe=await ta({autoRenameNamer:Le});ve(Oe.autoRenameNamer??"auto"),q(await H0(!0))}catch(Oe){ve(ot),a(Oe instanceof Error?Oe.message:String(Oe))}finally{te(null)}},Yt=async(Le,ot)=>{const Oe=we,Dt={...Oe};ot?Dt[Le]=ot:delete Dt[Le],ie(Dt),te(Le),a(null);try{const $e=await ta({autoRenameModels:Dt});ie($e.autoRenameModels??{})}catch($e){ie(Oe),a($e instanceof Error?$e.message:String($e))}finally{te(null)}},Mt=async Le=>{const ot=pe;de(Le),te("interval"),a(null);try{const Oe=await ta({autoRenameIntervalMinutes:Le});de(Oe.autoRenameIntervalMinutes??10)}catch(Oe){de(ot),a(Oe instanceof Error?Oe.message:String(Oe))}finally{te(null)}},on=async()=>{const Le=ke.trim();if(Le!==oe){te("preference"),a(null);try{const Oe=(await ta({autoRenamePromptPreference:Le})).autoRenamePromptPreference??"";be(Oe),he(Oe)}catch(ot){be(oe),a(ot instanceof Error?ot.message:String(ot))}finally{te(null)}}},xr=async Le=>{const ot=Math.max(1e3,Math.min(64e3,Math.round(Le||12e3))),Oe=J;Xe(ot),te("payload-limit"),a(null);try{const Dt=await ta({autoRenamePromptPayloadChars:ot});Xe(Dt.autoRenamePromptPayloadChars??12e3)}catch(Dt){Xe(Oe),a(Dt instanceof Error?Dt.message:String(Dt))}finally{te(null)}},Cn=new Set(j.map(Le=>Le.slug)),or=ge?{ok:e("settings.agentPluginDoctorStatusOk"),"missing-title-namer":e("settings.agentPluginDoctorStatusMissing"),"cli-default":e("settings.agentPluginDoctorStatusCliDefault"),"no-models":e("settings.agentPluginDoctorStatusNoModels"),"probe-failed":e("settings.agentPluginDoctorStatusFailed")}[ge.status]:"";return o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"rounded-xl bg-surface-2 px-3 py-2.5",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:e("settings.agentAutoRename")}),o.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:e("settings.agentAutoRenameHint")}),o.jsxs("label",{className:"mt-2 flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-[11px] text-muted-foreground",children:e("settings.agentAutoRenameNamer")}),o.jsxs("select",{value:X,disabled:z!==null,onChange:Le=>{yt(Le.target.value)},className:"min-w-0 rounded-lg bg-surface px-2.5 py-1.5 text-[11px] text-foreground outline-none disabled:opacity-50",children:[o.jsx("option",{value:"auto",children:e("settings.agentAutoRenameFollow")}),ae?.filter(Le=>Le.available).map(Le=>o.jsx("option",{value:Le.slug,children:Le.displayName},Le.slug))]})]}),o.jsxs("label",{className:"mt-2 flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-[11px] text-muted-foreground",children:e("settings.agentAutoRenameInterval")}),o.jsx("select",{value:pe,disabled:z!==null,onChange:Le=>{Mt(Number(Le.target.value))},className:"min-w-0 rounded-lg bg-surface px-2.5 py-1.5 text-[11px] text-foreground outline-none disabled:opacity-50",children:[5,10,30,60].map(Le=>o.jsxs("option",{value:Le,children:[Le," ",e("settings.agentAutoRenameMinutes")]},Le))})]}),o.jsxs("details",{className:"mt-2 border-t border-border/40 pt-2",children:[o.jsx("summary",{className:"cursor-pointer select-none text-[11px] text-muted-foreground transition hover:text-foreground",children:e("settings.agentAutoRenameAdvanced")}),o.jsxs("label",{className:"mt-2 block",children:[o.jsx("span",{className:"text-[11px] font-medium text-foreground",children:e("settings.agentAutoRenamePreference")}),o.jsx("span",{className:"mt-0.5 block text-[10px] text-muted-foreground",children:e("settings.agentAutoRenamePreferenceHint")}),o.jsx("textarea",{value:ke,maxLength:2e3,rows:3,disabled:z!==null,placeholder:e("settings.agentAutoRenamePreferencePlaceholder"),onChange:Le=>be(Le.target.value),onBlur:()=>{on()},className:"mt-1.5 w-full resize-y rounded-lg bg-surface px-2.5 py-2 text-[11px] text-foreground outline-none placeholder:text-muted-foreground/70 focus:ring-1 focus:ring-primary/50 disabled:opacity-50"}),o.jsx("span",{className:"mt-1 block text-right text-[10px] text-muted-foreground",children:z==="preference"?e("settings.saving"):`${ke.length}/2000`})]}),o.jsxs("label",{className:"mt-2 block",children:[o.jsx("span",{className:"text-[11px] font-medium text-foreground",children:e("settings.agentAutoRenamePayloadLimit")}),o.jsx("span",{className:"mt-0.5 block text-[10px] text-muted-foreground",children:e("settings.agentAutoRenamePayloadLimitHint")}),o.jsx("input",{type:"number",min:1e3,max:64e3,step:1e3,value:J,disabled:z!==null,onChange:Le=>Xe(Number(Le.target.value)),onBlur:Le=>{xr(Number(Le.target.value))},className:"mt-1.5 w-full rounded-lg bg-surface px-2.5 py-2 text-[11px] text-foreground outline-none focus:ring-1 focus:ring-primary/50 disabled:opacity-50"})]})]}),o.jsxs("div",{className:"mt-2 space-y-1.5 border-t border-border/40 pt-2",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("span",{className:"text-[10px] text-muted-foreground",children:e("settings.agentAutoRenameModelsFromCli")}),o.jsx("button",{type:"button",onClick:async()=>{q(null);try{q(await H0(!0))}catch{q([])}},className:"rounded p-1 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",title:e("settings.agentAutoRenameRefreshModels"),children:o.jsx(Us,{size:11,className:ae===null?"animate-spin":""})})]}),ae?.filter(Le=>Le.available).map(Le=>{const ot=Le.models.find(Oe=>Oe.id===Le.recommendedModel);return o.jsxs("label",{className:"flex items-center justify-between gap-3",children:[o.jsx("span",{className:"text-[11px] text-muted-foreground",children:Le.displayName}),o.jsxs("select",{value:we[Le.slug]??"",disabled:z!==null,onChange:Oe=>{Yt(Le.slug,Oe.target.value)},className:"min-w-0 max-w-[68%] rounded-lg bg-surface px-2.5 py-1.5 text-[11px] text-foreground outline-none disabled:opacity-50",children:[o.jsx("option",{value:"",children:ot?`${e("settings.agentAutoRenameAutomatic")} · ${ot.displayName}`:e("settings.agentAutoRenameCliDefault")}),Le.models.map(Oe=>o.jsx("option",{value:Oe.id,children:Oe.displayName},Oe.id))]})]},Le.slug)}),ae?.length===0&&o.jsx("div",{className:"text-[10px] text-[color:var(--warning)]",children:e("settings.agentAutoRenameNoCli")})]})]}),t===null&&o.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[o.jsx(Fn,{size:12,className:"animate-spin"})," …"]}),t?.map(Le=>{const ot=r===Le.slug,Oe=Le.state!=="not-installed",Dt=Cn.has(Le.slug);return o.jsxs("div",{className:"flex items-center gap-3 rounded-xl bg-surface-2 px-3 py-2.5",children:[o.jsx(Hu,{agent:{slug:Le.slug,displayName:Le.displayName,accentColor:Le.accentColor??"#878580",icon:Le.icon,isPlugin:Dt,iconMode:Le.iconMode,iconVersion:Le.iconVersion??void 0},size:18}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[13px] font-medium text-foreground",children:Le.displayName}),Dt&&o.jsx("span",{className:"rounded bg-[rgb(var(--success-rgb)_/_0.12)] px-1 py-px text-[9px] font-medium text-[color:var(--success)]",children:"plugin"}),o.jsxs("span",{className:`text-[10px] ${Ete[Le.state]}`,children:[Le.state==="installed"&&o.jsx(_b,{size:10,className:"mr-0.5 inline"}),(Le.state==="outdated"||Le.state==="needs-approval")&&o.jsx(yg,{size:10,className:"mr-0.5 inline"}),Be(Le.state)]})]}),o.jsxs("div",{className:"truncate text-[10px] text-muted-foreground",title:Le.targetDisplay,children:[e("settings.agentHooksTarget")," ",Le.targetDisplay]}),c===Le.slug&&o.jsx("div",{className:"mt-0.5 text-[10px] text-[color:var(--warning)]",children:e("settings.agentHooksDevMode")}),Le.state==="needs-approval"&&o.jsx("div",{className:"mt-0.5 text-[10px] text-[color:var(--warning)]",children:e("settings.agentHooksApprovalHint")})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsxs("button",{type:"button",disabled:V!==null,onClick:()=>{At(Le.slug)},className:"flex shrink-0 items-center gap-1.5 rounded-full px-2 py-1 text-[10px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50","aria-pressed":H.has(Le.slug),title:e("settings.agentAutoRenameToggle"),children:[o.jsx("span",{children:e("settings.agentAutoRenameShort")}),o.jsx(xc,{checked:H.has(Le.slug),disabled:V!==null,size:"sm"})]}),o.jsxs("button",{type:"button",disabled:ot,onClick:()=>{ze(Le.slug,Oe?"uninstall":"install")},className:`flex shrink-0 items-center gap-1 rounded-full px-2.5 py-1 text-[11px] font-medium transition ${Oe?"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground":"bg-[rgb(var(--success-rgb)_/_0.14)] text-[color:var(--success)] hover:bg-[rgb(var(--success-rgb)_/_0.22)]"} disabled:opacity-50`,children:[ot?o.jsx(Fn,{size:11,className:"animate-spin"}):Oe?o.jsx($i,{size:11}):Le.state==="outdated"?o.jsx(Us,{size:11}):o.jsx(c0,{size:11}),ot?"…":Oe?e("settings.agentHooksUninstall"):Le.state==="outdated"?e("settings.agentHooksReinstall"):e("settings.agentHooksInstall")]})]})]},Le.slug)}),i&&o.jsx("div",{className:"rounded-xl bg-[rgb(var(--warning-rgb)_/_0.10)] px-3 py-2 text-[11px] text-[color:var(--warning)]",children:i}),o.jsxs("div",{className:"rounded-xl bg-surface-2 px-3 py-2.5",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground",children:e("settings.agentPlugins")}),o.jsxs("button",{type:"button",onClick:()=>y(!g),className:"flex items-center gap-1 rounded-full bg-[rgb(var(--success-rgb)_/_0.14)] px-2.5 py-1 text-[11px] font-medium text-[color:var(--success)] hover:bg-[rgb(var(--success-rgb)_/_0.22)] transition",children:[o.jsx(Ao,{size:11}),e("settings.agentPluginAdd")]})]}),o.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:e("settings.agentPluginHint")}),g&&o.jsxs("div",{className:"mt-2 space-y-2",children:[o.jsxs("div",{className:"flex gap-2",children:[o.jsx("input",{value:v,onChange:Le=>S(Le.target.value),onKeyDown:Le=>{Le.key==="Enter"&&W()},className:"min-w-0 flex-1 rounded-lg bg-surface px-3 py-2 font-mono text-[11px] text-foreground placeholder:text-muted-foreground outline-none",placeholder:e("settings.agentPluginSourcePlaceholder")}),o.jsxs("button",{type:"button",disabled:!v.trim()||lt!==null,onClick:()=>{W()},className:"flex items-center gap-1 rounded-full bg-[rgb(var(--success-rgb)_/_0.14)] px-3 py-1 text-[11px] font-medium text-[color:var(--success)] transition hover:bg-[rgb(var(--success-rgb)_/_0.22)] disabled:opacity-50",children:[lt==="install"?o.jsx(Fn,{size:11,className:"animate-spin"}):o.jsx(c0,{size:11}),e("settings.agentPluginInstallPackage")]})]}),o.jsx("button",{type:"button",onClick:()=>p(!f),className:"text-[10px] text-muted-foreground transition hover:text-foreground",children:e("settings.agentPluginAdvancedManifest")})]}),j.map(Le=>{const ot=Le.revision?.slice(0,8),Oe=lt?.endsWith(`:${Le.slug}`)===!0;return o.jsxs("div",{className:"mt-2 flex items-center gap-2 border-t border-border/40 pt-2",children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-medium text-foreground",children:[o.jsx("span",{className:"truncate",children:Le.displayName}),Le.updateAvailable&&o.jsx("span",{className:"text-[9px] text-[color:var(--warning)]",children:e("settings.agentPluginUpdateAvailable")})]}),o.jsxs("div",{className:"truncate text-[9px] text-muted-foreground",title:Le.source??void 0,children:[Le.source??e("settings.agentPluginManualSource"),ot?` · ${ot}`:""]})]}),o.jsxs("button",{type:"button",disabled:lt!==null,onClick:()=>{Qe(Le.slug)},className:"flex items-center gap-1 rounded-full bg-surface px-2 py-1 text-[10px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50",title:e("settings.agentPluginDoctorHint"),children:[lt===`doctor:${Le.slug}`?o.jsx(Fn,{size:10,className:"animate-spin"}):o.jsx(GM,{size:10}),e("settings.agentPluginDoctor")]}),Le.updateSupported&&o.jsxs("button",{type:"button",disabled:lt!==null,onClick:()=>{Le.updateAvailable?Ce(Le.slug):He(Le.slug)},className:"flex items-center gap-1 rounded-full bg-surface px-2 py-1 text-[10px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50",children:[Oe?o.jsx(Fn,{size:10,className:"animate-spin"}):o.jsx(Us,{size:10}),Le.updateAvailable?e("settings.agentPluginUpdate"):e("settings.agentPluginCheck")]}),o.jsx("button",{type:"button",disabled:lt!==null,onClick:()=>{xe(Le.slug)},className:"rounded-full p-1 text-muted-foreground transition hover:bg-surface-elevated hover:text-[color:var(--warning)] disabled:opacity-50",title:e("settings.agentPluginDelete"),children:o.jsx($i,{size:11})})]},Le.slug)}),ge&&o.jsxs("div",{className:`mt-2 rounded-lg px-3 py-2 text-[10px] ${ge.status==="ok"||ge.status==="cli-default"?"bg-[rgb(var(--success-rgb)_/_0.10)] text-[color:var(--success)]":"bg-[rgb(var(--warning-rgb)_/_0.10)] text-[color:var(--warning)]"}`,children:[o.jsxs("div",{className:"font-medium",children:[ge.displayName,": ",or]}),o.jsx("div",{className:"mt-1 text-muted-foreground",children:ge.models.length>0?`${ge.models.length} ${e("settings.agentPluginDoctorModels")}${ge.recommendedModel?` · ${e("settings.agentPluginDoctorAutomatic")} ${ge.recommendedModel}`:""}`:e("settings.agentPluginDoctorCliDefault")}),ge.error&&o.jsx("div",{className:"mt-1 break-words",children:ge.error}),ge.warnings.length>0&&o.jsx("div",{className:"mt-1 space-y-0.5 text-muted-foreground",children:ge.warnings.map(Le=>o.jsxs("div",{children:["• ",Le]},Le))}),ge.nextSteps.length>0&&o.jsx("div",{className:"mt-1 space-y-0.5 text-muted-foreground",children:ge.nextSteps.map(Le=>o.jsxs("div",{children:["→ ",Le]},Le))})]}),F.map(Le=>o.jsxs("div",{className:"mt-2 rounded-lg bg-[rgb(var(--warning-rgb)_/_0.10)] px-3 py-2 text-[10px] text-[color:var(--warning)]",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("span",{className:"font-medium",children:[Le.slug,": ",Le.code??e("settings.agentPluginInvalid")]}),o.jsxs("button",{type:"button",onClick:()=>{pt(Le)},className:"flex shrink-0 items-center gap-1 rounded-full bg-[rgb(var(--warning-rgb)_/_0.14)] px-2 py-1 font-medium transition hover:bg-[rgb(var(--warning-rgb)_/_0.22)]",children:[C===Le.slug?o.jsx(_b,{size:10}):o.jsx(b8,{size:10}),C===Le.slug?e("settings.agentPluginCopied"):e("settings.agentPluginCopyAiPrompt")]})]}),o.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-muted-foreground",children:Le.errors.join(`
222
222
  `)}),Le.migration?.guideCommand&&o.jsx("code",{className:"mt-1 block select-all text-foreground",children:Le.migration.guideCommand})]},Le.slug)),g&&f&&o.jsxs("div",{className:"mt-2 space-y-2",children:[o.jsx("textarea",{value:A,onChange:Le=>T(Le.target.value),rows:10,className:"w-full rounded-lg bg-surface px-3 py-2 font-mono text-[11px] text-foreground placeholder:text-muted-foreground outline-none resize-y",placeholder:`{
223
223
  "version": 2,
224
224
  "slug": "my-agent",
@@ -238,14 +238,14 @@ ${jt}
238
238
  { "hook": "Stop", "event": "stop", "status": "complete" }
239
239
  ]
240
240
  }
241
- }`}),L&&o.jsx("div",{className:"whitespace-pre-wrap break-words text-[10px] text-[color:var(--warning)]",children:L}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>{We()},className:"flex items-center gap-1 rounded-full bg-[rgb(var(--success-rgb)_/_0.14)] px-3 py-1 text-[11px] font-medium text-[color:var(--success)] hover:bg-[rgb(var(--success-rgb)_/_0.22)] transition",children:[o.jsx(hN,{size:11}),e("settings.agentPluginCreate")]}),o.jsx("button",{type:"button",onClick:()=>{p(!1),T(""),I(null)},className:"rounded-full px-3 py-1 text-[11px] text-muted-foreground hover:text-foreground transition",children:e("common.cancel")})]})]})]})]})}function Lte({state:e,pending:t,onCheck:n,onConfirmRestart:r,desktopState:s,desktopPending:i=!1,onCheckDesktop:a,onInstallDesktop:c}){const{t:u}=Yn(),f=e?.status??"idle",p=t||f==="checking"||f==="installing"||f==="restarting",g=f==="ready"&&!!e?.latestVersion,y=f==="checking"?u("settings.updateChecking"):f==="installing"?u("sidebar.updateInstalling"):f==="ready"?u("sidebar.updateReady"):f==="restarting"?u("sidebar.updateRestarting"):f==="current"?u("settings.updateCurrent"):f==="error"?e?.error||u("sidebar.updateFailed"):u("settings.updateHint"),v=s?.status??"idle",S=i||v==="checking"||v==="downloading"||v==="installing",A=v==="ready",T=v==="unsupported"?u("settings.desktopUpdateUnsupported"):v==="checking"?u("settings.desktopUpdateChecking"):v==="current"?u("settings.desktopUpdateCurrent"):v==="downloading"?u("settings.desktopUpdateDownloading"):v==="ready"?u("settings.desktopUpdateReady"):v==="installing"?u("settings.desktopUpdateInstalling"):v==="error"&&s?.error||u("settings.desktopUpdateHint");return o.jsxs("section",{className:"mt-3 overflow-hidden rounded-xl bg-surface-2","aria-labelledby":"termdock-update-title",children:[o.jsx("div",{id:"termdock-update-title",className:"px-3 pt-3 text-[12px] font-semibold text-foreground",children:u("settings.updateTitle")}),o.jsxs("div",{className:"flex items-start justify-between gap-3 px-3 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[o.jsx("span",{className:`mt-0.5 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${g?"bg-[rgb(var(--warning-rgb)_/_0.16)] text-[color:var(--warning)]":"bg-primary/15 text-primary"}`,children:o.jsx(Us,{size:15,className:p?"animate-spin":""})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:u("settings.updateRuntimeTitle")}),o.jsx("div",{className:"mt-0.5 text-[10px] leading-relaxed text-muted-foreground",children:y}),e&&o.jsx("div",{className:"mt-1 text-[10px] tabular-nums text-muted-foreground/75",children:g&&e.latestVersion?`${e.currentVersion} → ${e.latestVersion}`:`v${e.currentVersion}`})]})]}),g?o.jsx("button",{type:"button",disabled:p,onClick:r,className:"shrink-0 rounded-full bg-[var(--warning)] px-3 py-1.5 text-[11px] font-semibold text-[color:var(--bg)] transition hover:opacity-90 disabled:cursor-wait disabled:opacity-60",children:u("sidebar.updateRestart")}):o.jsx("button",{type:"button",disabled:p,onClick:n,className:"shrink-0 rounded-full bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground transition hover:bg-surface-elevated disabled:cursor-wait disabled:opacity-60",children:u(f==="checking"?"settings.updateCheckingShort":f==="installing"?"settings.updateInstallingShort":f==="error"?"sidebar.updateRetry":f==="current"?"settings.updateCheckAgain":"settings.updateCheck")})]}),s&&o.jsxs("div",{className:"flex items-start justify-between gap-3 border-t border-border/10 px-3 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[o.jsx("span",{className:`mt-0.5 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${A?"bg-[rgb(var(--warning-rgb)_/_0.16)] text-[color:var(--warning)]":"bg-primary/15 text-primary"}`,children:o.jsx(Us,{size:15,className:S?"animate-spin":""})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:u("settings.desktopUpdateTitle")}),o.jsx("div",{className:"mt-0.5 text-[10px] leading-relaxed text-muted-foreground",children:T}),o.jsx("div",{className:"mt-1 text-[10px] tabular-nums text-muted-foreground/75",children:A&&s.latestVersion?`${s.currentVersion} → ${s.latestVersion}`:`v${s.currentVersion}`})]})]}),A?o.jsx("button",{type:"button",disabled:S||!c,onClick:c,className:"shrink-0 rounded-full bg-[var(--warning)] px-3 py-1.5 text-[11px] font-semibold text-[color:var(--bg)] transition hover:opacity-90 disabled:cursor-wait disabled:opacity-60",children:u("settings.desktopUpdateRestart")}):o.jsx("button",{type:"button",disabled:S||v==="unsupported"||!a,onClick:a,className:"shrink-0 rounded-full bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground transition hover:bg-surface-elevated disabled:cursor-wait disabled:opacity-60",children:u(v==="checking"?"settings.updateCheckingShort":v==="current"||v==="error"?"settings.desktopUpdateCheckAgain":"settings.desktopUpdateCheck")})]})]})}function Ete({bridge:e,runningCount:t,reviewCount:n,labels:r}){const[s,i]=D.useState([]),[a,c]=D.useState(!1),u=D.useRef(null);if(D.useEffect(()=>e.onServiceActivity(i),[e]),D.useEffect(()=>{e.reportServiceActivity({runningCount:t,reviewCount:n})},[e,n,t]),D.useEffect(()=>{if(!a)return;const A=L=>{u.current?.contains(L.target)||c(!1)},T=L=>{L.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",A),document.addEventListener("keydown",T),()=>{document.removeEventListener("pointerdown",A),document.removeEventListener("keydown",T)}},[a]),s.length<2)return null;const f=[...s].sort((A,T)=>A.current!==T.current?A.current?-1:1:A.reviewCount!==T.reviewCount?T.reviewCount-A.reviewCount:A.runningCount!==T.runningCount?T.runningCount-A.runningCount:A.label.localeCompare(T.label)),p=f.find(A=>A.current),g=f.filter(A=>!A.current),y=g.reduce((A,T)=>A+T.runningCount,0),v=g.reduce((A,T)=>A+T.reviewCount,0),S=async A=>{await e.focusService(A)&&c(!1)};return o.jsxs("div",{ref:u,className:"relative z-20 shrink-0","data-testid":"desktop-service-switcher",children:[o.jsxs("button",{type:"button",className:`inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-[11px] ring-1 transition sm:h-8 ${v>0?"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)] ring-[rgb(var(--warning-rgb)_/_0.22)] hover:bg-[rgb(var(--warning-rgb)_/_0.18)]":"bg-surface-2 text-muted-foreground ring-border/10 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"menu","aria-expanded":a,"aria-label":r.switchService,title:p?`${r.switchService} · ${p.label}`:r.switchService,onClick:()=>c(A=>!A),children:[o.jsx(C5,{size:13,className:"shrink-0"}),y>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[color:var(--success)]",title:`${r.running}: ${y}`,children:[o.jsx(Fn,{size:10,className:"animate-spin"}),o.jsx("span",{className:"tabular-nums",children:y})]}),v>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5",title:`${r.review}: ${v}`,children:[o.jsx(eu,{size:10,className:"animate-pulse"}),o.jsx("span",{className:"tabular-nums",children:v})]}),y===0&&v===0&&o.jsx("span",{className:"tabular-nums text-muted-foreground",children:s.length})]}),a&&o.jsxs("div",{role:"menu","aria-label":r.openServices,className:"absolute right-0 top-[calc(100%+0.4rem)] z-30 w-72 overflow-hidden rounded-xl border border-border/15 bg-surface-elevated p-1.5 text-foreground shadow-[0_18px_50px_var(--app-shadow-strong)]",children:[o.jsx("div",{className:"px-2.5 pb-1.5 pt-1 text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:r.openServices}),f.map(A=>{const T=A.runningCount===0&&A.reviewCount===0;return o.jsxs("button",{type:"button",role:"menuitem",className:"flex min-h-11 w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition hover:bg-surface-2 focus-visible:bg-surface-2 focus-visible:outline-none",onClick:()=>{S(A.origin)},children:[o.jsx("span",{className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-muted-foreground",children:A.current?o.jsx(na,{size:13,className:"text-primary"}):o.jsx(C5,{size:13})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"truncate text-[12px] font-medium",children:A.label}),A.current&&o.jsx("span",{className:"shrink-0 text-[9px] text-primary",children:r.current})]}),o.jsx("span",{className:"mt-0.5 block truncate text-[9px] text-muted-foreground",children:A.origin})]}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[10px] tabular-nums",children:[A.runningCount>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[color:var(--success)]",title:r.running,children:[o.jsx(Fn,{size:10,className:"animate-spin"}),A.runningCount]}),A.reviewCount>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[color:var(--warning)]",title:r.review,children:[o.jsx(eu,{size:10}),A.reviewCount]}),T&&o.jsx("span",{className:"text-muted-foreground",children:r.idle})]})]},A.origin)}),o.jsx("div",{className:"mt-1 border-t border-border/15 pt-1",children:o.jsxs("button",{type:"button",role:"menuitem",className:"flex min-h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-2 hover:text-foreground focus-visible:bg-surface-2 focus-visible:outline-none",onClick:()=>{c(!1),e.showConnectionCenter()},children:[o.jsx(FM,{size:13}),o.jsx("span",{children:r.manageServices})]})})]})]})}const W2="mobile-session-destroy";function Ite(e,t){return t&&e.type==="session"&&e.destination?.droppableId===W2}const Jo="termdock-program-rules-cache",qp="termdock-toolbar-presets-cache",bf="termdock-settings-cache",i7="termdock-color-theme",o7="termdock:right-sidebar:file-preview-open-by-session:v2",yf="termdock:running-session-button-enabled:v1",Rte=60,a7=320,l7=420,Tl=8;function c7(e,t,n){return Math.min(Math.max(e,t),n)}function u7(e){if(typeof window>"u")return{left:Tl,top:Tl};const t=window.innerWidth/2,n=Math.min(64,window.innerHeight/4),r=e?.x??t,s=e?.y??n,i=Math.max(Tl,window.innerWidth-a7-Tl),a=Math.max(Tl,window.innerHeight-l7-Tl);return{left:c7(r+Tl,Tl,i),top:c7(s+Tl,Tl,a),width:a7,maxHeight:`min(${l7}px, calc(100vh - ${Tl*2}px))`}}function Nte(e){return e==="dark"||e==="light"}function Mte(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.entries(e).every(([t,n])=>{if(!t||!n||typeof n!="object"||Array.isArray(n))return!1;const r=n;return typeof r.updatedAt=="number"&&Number.isFinite(r.updatedAt)})}function pb(e){const t=Object.entries(e).filter(([n,r])=>n&&Number.isFinite(r.updatedAt)).sort(([,n],[,r])=>r.updatedAt-n.updatedAt).slice(0,Rte);return Object.fromEntries(t)}function Dte(e){return Array.isArray(e)&&e.every(t=>{if(!t||typeof t!="object")return!1;const n=t;return typeof n.id=="string"&&typeof n.pattern=="string"&&typeof n.output=="string"&&(n.matchType==="exact"||n.matchType==="includes"||n.matchType==="prefix"||n.matchType==="regex")})}function jte(e){return typeof e=="object"&&e!==null&&typeof e.version=="number"&&Array.isArray(e.presets)}function Pte(e,t){const n=Vf(),r=new Set(BF()),s=Array.isArray(e)?e:[],i=qd(s),a=t<Tf;if(i.length===0)return n;if(a){const u=new Map(i.map(y=>[y.id,y])),f=new Map(s.map(y=>[typeof y.id=="string"?y.id.trim().toLowerCase().replace(/[^a-z0-9_-]/g,"-"):"",y])),p=i.filter(y=>!r.has(y.id));return[...n.map(y=>{const v=u.get(y.id),S=f.get(y.id);return v?{...y,rowLayout:v.rowLayout,showOnDesktop:typeof S?.showOnDesktop=="boolean"?S.showOnDesktop:y.showOnDesktop}:y}),...p]}const c=new Set(i.map(u=>u.id));return[...i,...n.filter(u=>!c.has(u.id))]}function Bte(e){return typeof e=="object"&&e!==null&&typeof e.preventSleep=="boolean"&&typeof e.networkAvailable=="boolean"}const Fte={name:"",source:"auto",hostname:"",fallbackHostname:"",url:"",fallbackUrl:"",onboardingUrl:null,status:"disabled",reason:null,httpsEnabled:!1,caAvailable:!1,lanAddresses:[],interfaces:[]},Qg="__termdockOverlay",$g="__termdockBaseAnchor",Hg="__termdockBaseGuard",Ote=3,d7=250,Qte="termdock-notification-target-v1",f7="/__termdock-notification-target",h7=3e4;function $te(e){return e==="left-sidebar"||e==="right-sidebar"||e==="right-sidebar-repo-picker"||e==="right-sidebar-file-preview"||e==="settings"||e==="markdown-outline"||e==="markdown-image-lightbox"}function Bd(e){if(!e||typeof e!="object")return null;const t=e[Qg];return $te(t)?t:null}function xv(e){return e&&typeof e=="object"?{...e}:{}}function vC(e){const t=xv(e);return delete t[Qg],t}function Hte(e){const t=vC(e);return delete t[Hg],{...t,[$g]:!0}}function Ute(){typeof window>"u"||window.history.pushState({...vC(window.history.state),[$g]:!0,[Hg]:!0},"",window.location.href)}function wC(){for(let e=0;e<Ote;e+=1)Ute()}function Yp(){typeof window>"u"||(window.history.replaceState(Hte(window.history.state),"",window.location.href),wC())}function vf(e){typeof window>"u"||window.history.pushState({...xv(window.history.state),[$g]:!0,[Qg]:e,[Hg]:!1},"",window.location.href)}function zte(e){typeof window>"u"||window.history.replaceState({...xv(window.history.state),[$g]:!0,[Qg]:e,[Hg]:!1},"",window.location.href)}const SC=["bash","zsh","fish","sh","dash","ksh","tcsh","csh","nu"];let rl=new Set(SC);function p7(e){const t=new Map;for(const[n,r]of e)t.set(n,{cwd:r.cwd,activeProgram:r.activeProgram,activeProgramRaw:r.activeProgramRaw,inCopyMode:r.inCopyMode,isConnecting:r.isConnecting,agentStatus:r.agentStatus,agentIndicator:r.agentIndicator,agentStatusDetail:r.agentStatusDetail,agent:r.agent,agentMessage:r.agentMessage,agentNativeSessionId:r.agentNativeSessionId,agentResumeRecovered:r.agentResumeRecovered,terminalSessionId:r.terminalSessionId,agentNeedsReview:r.agentNeedsReview,gitStatus:r.gitStatus,shellTitle:r.shellTitle,promptState:r.promptState,tuiProgress:r.tuiProgress});return t}function Gte(e,t){if(e.size!==t.size)return!1;for(const[n,r]of t){const s=e.get(n);if(!s||s.cwd!==r.cwd||s.activeProgram!==r.activeProgram||s.activeProgramRaw!==r.activeProgramRaw||s.inCopyMode!==r.inCopyMode||s.isConnecting!==r.isConnecting||s.agentStatus!==r.agentStatus||s.agentIndicator!==r.agentIndicator||s.agentStatusDetail!==r.agentStatusDetail||s.agent!==r.agent||s.agentMessage!==r.agentMessage||s.agentNativeSessionId!==r.agentNativeSessionId||s.agentResumeRecovered!==r.agentResumeRecovered||s.terminalSessionId!==r.terminalSessionId||s.agentNeedsReview!==r.agentNeedsReview||s.gitStatus!==r.gitStatus||s.shellTitle!==r.shellTitle||s.promptState!==r.promptState||s.tuiProgress?.state!==r.tuiProgress?.state||s.tuiProgress?.progress!==r.tuiProgress?.progress)return!1}return!0}function m7(e,t){return o.jsx(JV,{sessionMode:e,state:t})}function Wte(e,t){const n=new Map(e.map(a=>[a.id,a])),r=t.map(a=>n.get(a)).filter(a=>a!==void 0),s=new Set(t),i=e.filter(a=>!s.has(a.id));return[...r,...i]}function Vte(){const{t:e,locale:t,setLocale:n}=Yn(),r="env(safe-area-inset-top, 0px)",s="env(safe-area-inset-bottom, 0px)";iO();const i=D.useMemo(()=>typeof window>"u"?!1:/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1,[]),[a,c]=D.useState(!1),[u,f]=D.useState(()=>Or(i7,Nte)??"dark"),p=D.useRef(Or(bf,Bte)).current,[g,y]=D.useState(p?.preventSleep??!1),[v,S]=D.useState(p?.networkAvailable??!0),[A,T]=D.useState(dg),[L,I]=D.useState(fg),[j,P]=D.useState(ny),[F,R]=D.useState(Gf),[C,$]=D.useState(P1),[H,Y]=D.useState(p?.localAccess??Fte),[V,fe]=D.useState(p?.localAccess?.name??""),[X,ve]=D.useState(!1),[we,ie]=D.useState(null),[ae,q]=D.useState(null),[z,te]=D.useState(null),[pe,de]=D.useState(!1),ke=D.useMemo(()=>lo(),[]),be=!!(ke?.desktopUpdateState&&ke.checkDesktopUpdate&&ke.installDesktopUpdate),[oe,he]=D.useState(null),[J,Xe]=D.useState(null),[lt,Ze]=D.useState(!1),[ge,Fe]=D.useState(null),[Te,ze]=D.useState(!1),[Be,We]=D.useState(()=>pb(Or(o7,Mte)??{})),[W,xe]=D.useState(0),[He,Ce]=D.useState(!1),[Qe,pt]=D.useState(0),[At,yt]=D.useState(!1),[Yt,Mt]=D.useState(0),[on,xr]=D.useState(!1),[Cn,or]=D.useState(0),Le=D.useRef(null),[ot,Oe]=D.useState({}),{terminalSettings:Dt,updateTerminalSettings:$e}=aW(),Ut=Dt.fontSize,_t=Dt.rendererMode,[Ve,Ur]=D.useState(!1),kn=D.useRef(DO()).current,[Ft,Zn]=b.useState(()=>kn.sessions.map(M=>({id:M.sessionId,name:M.name,customName:M.customName,mode:M.mode,tmuxSessionName:M.tmuxSessionName}))),[Gt,Cr]=D.useState(kn.activeSessionId),[nr,an]=D.useState(null),[Er,yr]=D.useState(null),[Jn,wr]=D.useState([]),[Se,le]=b.useState(()=>{const M=es.getState();return kn.sessions.forEach(G=>{G.backendSessionId&&M.setTerminalSession(G.sessionId,{sessionId:G.backendSessionId,cols:80,rows:24,mode:G.mode,tmuxSessionName:G.tmuxSessionName}),G.activeProgram!=null&&M.setSessionActiveProgram(G.sessionId,G.activeProgram),G.cwd!=null&&M.setSessionCwd(G.sessionId,G.cwd)}),Ff("session-chrome-hydrated"),p7(M.sessions)});b.useEffect(()=>{!ke||!Ve||Promise.all([ke.snapshot(),ke.desktopUpdateState?.()??Promise.resolve(null)]).then(([M,G])=>{he(M),Xe(G)}).catch(M=>Fe(M instanceof Error?M.message:String(M)))},[ke,Ve]),b.useEffect(()=>{ke?.onDesktopUpdateState&&ke.onDesktopUpdateState(Xe)},[ke]),b.useEffect(()=>es.subscribe(M=>{const G=p7(M.sessions);le(Re=>Gte(Re,G)?Re:G)}),[]);const It=b.useCallback(async(M,G)=>{yr(null),an({sessionId:M,status:"submitting",error:null});try{await ZE(G),an(Re=>Re?.sessionId===M?{...Re,status:"waiting",error:null}:Re)}catch(Re){const Pt=(Re&&typeof Re=="object"&&"code"in Re?String(Re.code??""):"")==="AGENT_SESSION_ACTIVE_ELSEWHERE"?e("tab.resumeAgentConflict"):Re instanceof Error&&/busy/i.test(Re.message)?e("tab.resumeAgentBusy"):e("tab.resumeAgentFailed");an(Wt=>Wt?.sessionId===M?{...Wt,error:Pt}:Wt),yr({tone:"error",message:Pt})}},[e]);b.useEffect(()=>{if(!nr||nr.status!=="waiting")return;const M=Se.get(nr.sessionId);if(!M||M.agentResumeRecovered||M.agentStatus===null)return;const G=M.agent?.displayName??"Agent";an(null),yr({tone:"success",message:e("tab.resumeAgentSuccess",{agent:G})})},[nr,Se,e]),b.useEffect(()=>{if(!nr||nr.status!=="waiting"||nr.error)return;const M=nr.sessionId,G=window.setTimeout(()=>{const Re=e("tab.resumeAgentTimeout");an(rt=>rt?.sessionId===M&&rt.status==="waiting"?{...rt,error:Re}:rt),yr({tone:"error",message:Re})},15e3);return()=>window.clearTimeout(G)},[nr,e]),b.useEffect(()=>{if(Er?.tone!=="success")return;const M=window.setTimeout(()=>yr(null),3200);return()=>window.clearTimeout(M)},[Er]),b.useEffect(()=>{let M=!1;JL().then(Re=>{M||te(Re)}).catch(()=>{});const G=Mm(Re=>{Re.type==="update-state"&&!M&&te(Re.state)});return()=>{M=!0,G()}},[]);const Me=b.useCallback(async()=>{const M=z?.latestVersion;if(!(!M||pe)&&window.confirm(e("sidebar.updateRestartConfirm",{version:M}))){de(!0);try{te(await tE())}catch(G){window.alert(G instanceof Error?G.message:String(G))}finally{de(!1)}}},[z?.latestVersion,e,pe]),Ee=b.useCallback(async()=>{if(!pe){de(!0);try{te(await eE())}catch(M){window.alert(M instanceof Error?M.message:String(M))}finally{de(!1)}}},[pe]),Ge=b.useCallback(async()=>{if(!(!ke?.checkDesktopUpdate||lt)){Ze(!0);try{Xe(await ke.checkDesktopUpdate())}catch(M){Fe(M instanceof Error?M.message:String(M))}finally{Ze(!1)}}},[ke,lt]),dt=b.useCallback(async()=>{if(!(!ke?.installDesktopUpdate||lt||J?.status!=="ready")&&window.confirm(e("settings.desktopUpdateRestartConfirm"))){Ze(!0);try{Xe(await ke.installDesktopUpdate())}catch(M){Fe(M instanceof Error?M.message:String(M)),Ze(!1)}}},[ke,lt,J?.status,e]);b.useEffect(()=>{document.documentElement.dataset.theme=u,i9(u),$n(i7,u)},[u]),b.useEffect(()=>{$n(o7,pb(Be))},[Be]);const gt=ft(M=>M.leftOpen),Kt=ft(M=>M.rightOpen),nn=ft(M=>M.leftPinned),vt=ft(M=>M.leftSidebarWidth),un=ft(M=>M.rightPinned),Hn=ft(M=>M.rightSidebarWidth),rr=ft(M=>M.rootPath),fn=ft(M=>M.contextKey),Un=ft(M=>M.selectedFilePath),hn=ft(M=>M.groupByFolder),Kn=ft(M=>M.collapsedGroups),sn=ft(M=>M.toggleGroupCollapsed),[zn,as]=b.useState(()=>typeof window>"u"?!0:window.matchMedia("(min-width: 1024px)").matches),[Bt,rn]=b.useState(()=>typeof window>"u"?1024:window.innerWidth),[bt,Tt]=b.useState(()=>typeof window>"u"?!1:window.matchMedia("(orientation: landscape)").matches),[at,$t]=b.useState([]),[Rt,vn]=b.useState({available:!0,version:null,reason:null}),[Ot,Jt]=b.useState(!1),[ar,qe]=b.useState(null),[ct,jt]=b.useState(null),[dn,An]=b.useState(null),[_n,ln]=b.useState(null),[pn,tn]=b.useState(null),[cn,sr]=b.useState(null),[ps,Qr]=b.useState(null),[se,_e]=b.useState(null),[je,tt]=b.useState(null),[Qt,Nt]=b.useState(null),[st,wt]=b.useState(!1),[Lt,Tn]=b.useState(()=>Or(yf,M=>typeof M=="boolean")??!1),mn=b.useCallback(async M=>{const G=Lt;Tn(M),$n(yf,M);try{const Re=await ta({runningSessionButtonEnabled:M});Tn(Re.runningSessionButtonEnabled),$n(yf,Re.runningSessionButtonEnabled)}catch{Tn(G),$n(yf,G)}},[Lt]),[lr,zr]=b.useState(null),jn=b.useCallback(M=>{zr(M)},[]),mr=b.useRef(!1),[dr,en]=b.useState(null),[Vt,ir]=b.useState(null),Xn=D.useRef(null),Gr=D.useRef(!1),gn=D.useRef(null),fr=D.useRef(!1),Ln=b.useCallback(()=>{sr(null),Qr(null)},[]),ns=D.useRef(typeof window>"u"?null:new URLSearchParams(window.location.search).get("session")),[kr,ls]=D.useState(ns.current),[ms,ui]=D.useState(ns.current!==null||typeof caches>"u"),di=D.useRef(ns.current),ws=D.useRef(typeof window>"u"?null:new URLSearchParams(window.location.search).get("_notifTrace"));b.useEffect(()=>{if(typeof window>"u")return;const M=window.matchMedia("(min-width: 1024px)"),G=()=>{as(M.matches),rn(window.innerWidth)};return G(),M.addEventListener("change",G),window.addEventListener("resize",G),()=>{M.removeEventListener("change",G),window.removeEventListener("resize",G)}},[]),b.useEffect(()=>{if(typeof window>"u")return;const M=window.matchMedia("(orientation: landscape)"),G=()=>Tt(M.matches);return G(),M.addEventListener("change",G),()=>M.removeEventListener("change",G)},[]),D.useLayoutEffect(()=>((()=>{const G=Gt?es.getState().sessions.get(Gt)?.cwd??null:null;ft.getState().setRootPath(G,Gt)})(),es.subscribe((G,Re)=>{const rt=Gt?G.sessions.get(Gt)?.cwd??null:null,Pt=Gt?Re.sessions.get(Gt)?.cwd??null:null;rt!==Pt&&ft.getState().setRootPath(rt,Gt)})),[Gt]);const ja=zn||bt,fi=zn||bt,ia=ja?Math.min(Math.max(Bt*.9,360),Bt-56):Math.min(Bt*.92,420),hi=fi?Math.min(Math.max(Bt*.22,280),340):Math.min(Bt*.86,380),Es=Gt&&rr?`${Gt}\0${rr}`:"",cr=!!(Es&&Un&&Be[Es]),pi=b.useCallback(M=>{Es&&(M&&!ft.getState().selectedFilePath||We(G=>{if(!!G[Es]===M)return G;if(M)return pb({...G,[Es]:{updatedAt:Date.now()}});const rt={...G};return delete rt[Es],rt}))},[Es]);b.useEffect(()=>{pW(Es,fn,Un)&&We(M=>{if(!M[Es])return M;const G={...M};return delete G[Es],G})},[Es,fn,Un]);const rs=on?"markdown-image-lightbox":At?"markdown-outline":He?"right-sidebar-repo-picker":Kt&&cr?"right-sidebar-file-preview":Ve?"settings":Kt&&!(un&&zn)?"right-sidebar":gt&&!(nn&&zn)?"left-sidebar":null,er=D.useRef(rs),Mr=D.useRef(rs),Is=D.useRef(!1),Dr=D.useRef(!1),Cs=b.useCallback(()=>{if(typeof window>"u")return;const M=window.matchMedia("(hover: hover) and (pointer: fine)").matches;!zn||!M||navigator.maxTouchPoints>0||window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("focus-active-terminal-session"))},0)},[zn]),To=b.useCallback(M=>{if(M==="markdown-image-lightbox"){xr(!1),or(G=>G+1);return}if(M==="markdown-outline"){yt(!1),Mt(G=>G+1);return}if(M==="right-sidebar-file-preview"){yt(!1),Mt(G=>G+1),pi(!1),xe(G=>G+1);return}if(M==="right-sidebar-repo-picker"){Ce(!1),pt(G=>G+1);return}if(M==="settings"){Ur(!1),$s(!1),B(!1),Ir(!1);return}if(M==="left-sidebar"){ft.getState().closeLeft();return}yt(!1),Mt(G=>G+1),Ce(!1),pt(G=>G+1),xr(!1),or(G=>G+1),ft.getState().closeRight()},[pi]),Wr=b.useCallback(M=>{if(!i&&typeof window<"u"&&er.current===M&&Bd(window.history.state)===M){window.history.back();return}To(M)},[To,i]),oa=b.useCallback(()=>{Ur(!1);const M=ft.getState();M.closeRight(),M.openLeft()},[]),Co=b.useCallback(()=>{Ur(!1);const M=ft.getState();M.closeLeft(),M.openRight()},[]),zi=b.useCallback(()=>{Ur(!1);const M=ft.getState();M.closeLeft(),M.openRight(),M.setRightTab("files"),M.openRightSearch()},[]),Js=b.useCallback(()=>{const M=ft.getState();if(M.leftPinned){M.setLeftPinned(!1),M.closeLeft();return}if(gt){Wr("left-sidebar");return}oa()},[oa,Wr,gt]),Fs=b.useCallback(()=>{const M=ft.getState();M.leftPinned?(M.setLeftPinned(!1),M.openLeft()):(M.setLeftPinned(!0),M.openLeft())},[]),aa=b.useCallback(()=>{const M=ft.getState();M.setLeftPinned(!1),M.closeLeft()},[]),la=b.useCallback(()=>{const M=ft.getState();M.rightPinned?(M.setRightPinned(!1),M.openRight()):(M.setRightPinned(!0),M.openRight())},[]),Os=b.useCallback(()=>{const M=ft.getState();M.setRightPinned(!1),M.closeRight()},[]),ca=b.useRef(0),Gi=b.useRef(0),ki=b.useRef(null),_i=b.useCallback(M=>{M.preventDefault(),ca.current=M.clientX,Gi.current=ft.getState().leftSidebarWidth;const G=rt=>{ki.current===null&&(ki.current=requestAnimationFrame(()=>{ki.current=null;const Pt=rt.clientX-ca.current;ft.getState().setLeftSidebarWidth(Gi.current+Pt)}))},Re=()=>{window.removeEventListener("mousemove",G),window.removeEventListener("mouseup",Re),ki.current!==null&&(cancelAnimationFrame(ki.current),ki.current=null),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",G),window.addEventListener("mouseup",Re)},[]),gs=b.useRef(0),mi=b.useRef(0),ei=b.useRef(null),ko=b.useCallback(M=>{M.preventDefault(),gs.current=M.clientX;const G=ft.getState(),Re=G.leftPinned?G.leftSidebarWidth:0;mi.current=px(G.rightSidebarWidth,window.innerWidth,Re);const rt=Wt=>{ei.current===null&&(ei.current=requestAnimationFrame(()=>{ei.current=null;const Pn=gs.current-Wt.clientX,Fr=ft.getState(),Yr=Fr.leftPinned?Fr.leftSidebarWidth:0;Fr.setRightSidebarWidth(px(mi.current+Pn,window.innerWidth,Yr))}))},Pt=()=>{window.removeEventListener("mousemove",rt),window.removeEventListener("mouseup",Pt),ei.current!==null&&(cancelAnimationFrame(ei.current),ei.current=null),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",rt),window.addEventListener("mouseup",Pt)},[]),Wi=b.useCallback(()=>{const M=ft.getState();if(M.rightPinned){M.setRightPinned(!1),M.closeRight();return}if(Kt){Wr("right-sidebar");return}Co()},[Co,Wr,Kt]),ua=b.useCallback(()=>{!cr&&!i&&typeof window<"u"&&er.current==="right-sidebar"&&Bd(window.history.state)==="right-sidebar"&&(vf("right-sidebar-file-preview"),Mr.current="right-sidebar-file-preview"),pi(!0)},[cr,i,pi]),Pa=b.useCallback(()=>{Wr("right-sidebar-file-preview")},[Wr]),fl=b.useCallback(()=>{!He&&!i&&typeof window<"u"&&er.current==="right-sidebar"&&Bd(window.history.state)==="right-sidebar"&&(vf("right-sidebar-repo-picker"),Mr.current="right-sidebar-repo-picker"),Ce(!0)},[He,i]),Qs=b.useCallback(()=>{Wr("right-sidebar-repo-picker")},[Wr]),gi=b.useCallback(()=>{!At&&!i&&typeof window<"u"&&er.current&&Bd(window.history.state)===er.current&&(vf("markdown-outline"),Mr.current="markdown-outline"),yt(!0)},[At,i]),Li=b.useCallback(()=>{Wr("markdown-outline")},[Wr]),Ei=b.useCallback(()=>{!i&&typeof window<"u"&&er.current&&Bd(window.history.state)===er.current&&(vf("markdown-image-lightbox"),Mr.current="markdown-image-lightbox"),xr(!0)},[i]),po=b.useCallback(()=>{Wr("markdown-image-lightbox")},[Wr]),me=b.useCallback(()=>{!i&&typeof window<"u"&&er.current&&Bd(window.history.state)===er.current&&(zte("settings"),Mr.current="settings"),ft.getState().closeAll(),Ur(!0)},[i]),ut=b.useCallback(()=>{Wr("settings")},[Wr]);b.useEffect(()=>{if(!ke)return;const M=()=>me();return window.addEventListener("termdock:open-settings",M),()=>window.removeEventListener("termdock:open-settings",M)},[ke,me]);const xt=b.useCallback(()=>{ze(!0),Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null)},[]),nt=b.useCallback(()=>{Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null),ze(!1),Dr.current=!0,Yp(),Dr.current},[]);b.useEffect(()=>()=>{Le.current!==null&&window.clearTimeout(Le.current)},[]),b.useEffect(()=>{i||Yp()},[i]),b.useEffect(()=>{if(typeof window>"u"||i)return;let M=null;const G=()=>{M!==null&&(window.clearTimeout(M),M=null)},Re=Fr=>{if(er.current,Dr.current,er.current){er.current;return}!Fr?.force&&Dr.current||(Fr?.userActivated&&(Dr.current=!0),Yp(),Dr.current,void 0)},rt=()=>{G(),M=window.setTimeout(()=>{M=null,Re({force:!0})},d7)},Pt=()=>{Re({userActivated:!0})},Wt=()=>{rt()},Pn=()=>{document.visibilityState==="visible"&&rt()};return window.addEventListener("pointerdown",Pt,{capture:!0,passive:!0}),window.addEventListener("touchstart",Pt,{capture:!0,passive:!0}),window.addEventListener("keydown",Pt,{capture:!0}),window.addEventListener("pageshow",Wt),document.addEventListener("visibilitychange",Pn),()=>{G(),window.removeEventListener("pointerdown",Pt,{capture:!0}),window.removeEventListener("touchstart",Pt,{capture:!0}),window.removeEventListener("keydown",Pt,{capture:!0}),window.removeEventListener("pageshow",Wt),document.removeEventListener("visibilitychange",Pn)}},[i]),b.useEffect(()=>{er.current=rs},[rs]),b.useEffect(()=>{if(typeof window>"u"||rs||i)return;const M=window.setTimeout(()=>{er.current?(er.current,void 0):Yp()},d7);return()=>window.clearTimeout(M)},[rs,i]),b.useEffect(()=>{if(typeof window>"u"||i)return;const M=Mr.current;Is.current,rs&&rs!==M&&!Is.current&&vf(rs),!rs&&M&&Cs(),Mr.current=rs,!rs&&Is.current&&window.setTimeout(()=>{Is.current=!1},0)},[rs,i,Cs]),b.useEffect(()=>{if(typeof window>"u"||i)return;const M=()=>{const G=er.current;if(Dr.current,!G){Dr.current=!1,Dr.current,xt(),wC();return}Is.current=!0,To(G)};return window.addEventListener("popstate",M),()=>window.removeEventListener("popstate",M)},[To,xt,i]),b.useEffect(()=>{const M=G=>{const Re=G.metaKey||G.ctrlKey;if(Re&&G.key==="b"&&!G.shiftKey&&(G.preventDefault(),Js()),Re&&G.shiftKey&&G.key==="E"&&(G.preventDefault(),Wi()),Re&&G.shiftKey&&G.key==="P"&&(G.preventDefault(),zi()),Re&&!G.shiftKey&&G.altKey&&(G.key==="ArrowLeft"||G.key==="ArrowRight")){G.preventDefault();const rt=G.key==="ArrowRight"?"next":"prev";window.dispatchEvent(new CustomEvent("cycle-terminal-session",{detail:{direction:rt}}));return}if(Re&&G.shiftKey&&!G.altKey&&(G.code==="BracketLeft"||G.code==="BracketRight")){G.preventDefault();const rt=G.code==="BracketRight"?"next":"prev";window.dispatchEvent(new CustomEvent("cycle-terminal-session",{detail:{direction:rt}}));return}};return document.addEventListener("keydown",M),()=>{document.removeEventListener("keydown",M)}},[Js,Wi,zi]);const Ct=b.useCallback(async()=>{ve(!0),ie(null);try{const M=await ta({localAccess:{name:V}});Y(M.localAccess),fe(M.localAccess.name),$n(bf,{preventSleep:M.preventSleep,networkAvailable:M.networkAvailable,localAccess:M.localAccess})}catch(M){ie(M instanceof Error?M.message:"Failed to save local access name")}finally{ve(!1)}},[V]),On=b.useCallback(async()=>{ve(!0),ie(null);try{const M=await ta({localAccess:{reset:!0}});Y(M.localAccess),fe(M.localAccess.name),$n(bf,{preventSleep:M.preventSleep,networkAvailable:M.networkAvailable,localAccess:M.localAccess})}catch(M){ie(M instanceof Error?M.message:"Failed to reset local access name")}finally{ve(!1)}},[]),Ae=b.useCallback(async(M,G="url")=>{if(M)try{if(typeof navigator<"u"&&navigator.clipboard)await navigator.clipboard.writeText(M);else{const Re=document.createElement("textarea");Re.value=M,Re.style.position="fixed",Re.style.left="-9999px",document.body.appendChild(Re),Re.focus(),Re.select(),document.execCommand("copy"),document.body.removeChild(Re)}q(G),window.setTimeout(()=>q(Re=>Re===G?null:Re),1600)}catch{q(null)}},[]),hr=b.useCallback(M=>{const G=Wte(Ft,M);G.map(Re=>Re.id).join("\0")!==Ft.map(Re=>Re.id).join("\0")&&(Zn(G),window.dispatchEvent(new CustomEvent("reorder-terminal-session",{detail:{sessionIds:G.map(Re=>Re.id)}})))},[Ft]),Ss=b.useCallback(M=>{zn||M.type!=="session"||(mr.current=!1,wt(!1),Nt(M.draggableId))},[zn]),qn=b.useCallback(M=>{if(zn||M.type!=="session")return;const G=M.destination?.droppableId===W2;G!==mr.current&&(mr.current=G,wt(G),G&&navigator.vibrate?.(20))},[zn]),cs=b.useCallback(M=>{const G=Ite(M,!zn);return mr.current=!1,wt(!1),Nt(null),G?(window.dispatchEvent(new CustomEvent("close-terminal-session",{detail:{sessionId:M.draggableId,source:"other",closeMode:"destroy"}})),!0):!1},[zn]),Vr=b.useCallback(M=>{if(cs(M)||!M.destination||M.source.index===M.destination.index)return;const G=[...Ft],[Re]=G.splice(M.source.index,1);G.splice(M.destination.index,0,Re),hr(G.map(rt=>rt.id))},[hr,cs,Ft]),Gs=b.useCallback((M,G)=>{const Re=G.trim();Re&&window.dispatchEvent(new CustomEvent("rename-terminal-session",{detail:{sessionId:M,name:Re}}))},[]),qr=b.useCallback(M=>{window.dispatchEvent(new CustomEvent("reset-terminal-session-name",{detail:{sessionId:M}}))},[]),{newSessionMode:Rr,newSessionTmuxName:Ws,userSelectedNewSessionMode:tc,setNewSessionMode:Nn}=uW(),[Kr,Ho]=b.useState(null),[_o,$s]=D.useState(!1),[xi,B]=D.useState(!1),[K,ee]=D.useState("idle"),ce=D.useRef(Or(qp,jte)).current,[Je,Ke]=D.useState(()=>{const M=ce?.presets;if(M&&M.length>0){const G=qd(M);if(G.length>0)return G}return Vf()}),[ht,Ht]=D.useState(!1),[et,Zt]=D.useState("default"),_r=D.useRef(typeof ce?.updatedAt=="number"?ce.updatedAt:null),jr=D.useRef(!1),[Lr,Ir]=D.useState(!1),[xs,Gn]=D.useState(!1),Wn=D.useRef(Or(Jo,Dte)).current,[Pr,ur]=D.useState(Wn??[]),[da,us]=D.useState(Wn!==null),[ti,Br]=D.useState(!1),Ii=!rs&&!xi&&!_o&&!Lr&&!xs&&!cn&&!dr&&!Kr,Vi=D.useCallback(M=>{const G=typeof M.version=="number"?M.version:0,Re=Pte(Array.isArray(M.presets)?M.presets:[],G);_r.current=typeof M.updatedAt=="number"?M.updatedAt:null,Ke(rt=>PO(rt,Re)?rt:(jr.current=!0,Re)),$n(qp,{version:Tf,presets:Re,updatedAt:_r.current??void 0})},[]);b.useEffect(()=>{const M=G=>{if(G.key!=="Escape")return;if(xi){G.preventDefault(),B(!1);return}if(_o){G.preventDefault(),$s(!1);return}if(Lr){G.preventDefault(),Ir(!1);return}if(xs){G.preventDefault(),Gn(!1);return}if(cn){G.preventDefault(),Ln();return}if(se){G.preventDefault(),tn(null),_e(null);return}if(Ve){G.preventDefault(),ut();return}if(Kt&&!(un&&zn)){G.preventDefault(),Wr("right-sidebar");return}gt&&!(nn&&zn)&&(G.preventDefault(),Wr("left-sidebar"))};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[xi,_o,Lr,cn,Ln,Ve,Kt,un,gt,nn,zn,ut,Wr]),b.useEffect(()=>{us(!0)},[]);const[ni,fa]=D.useState({genericProgramNames:[],wrapperScriptNames:[],shellNames:SC}),[,ou]=D.useState(!1),Il=D.useCallback(()=>tI().then(M=>{fa(M),rl=new Set(M.shellNames),ou(!0)}).catch(()=>{}),[]);b.useEffect(()=>{Il()},[Il]),b.useEffect(()=>Mm(M=>{if(M.type==="config-updated"){if(M.key==="toolbar-presets"){s5().then(G=>Vi(G)).catch(G=>{console.warn("[toolbar-presets] Failed to refresh after remote update:",G)});return}M.key==="program-detection"&&Il()}}),[Vi,Il]),b.useEffect(()=>{let M=!1;return(async()=>{try{const G=await s5();if(M)return;Vi(G)}catch(G){console.warn("[toolbar-presets] Failed to load from server:",G)}finally{M||Ht(!0)}})(),()=>{M=!0}},[Vi]),b.useEffect(()=>{if(ht){if(jr.current){jr.current=!1;return}$n(qp,{version:Tf,presets:Je,updatedAt:_r.current??void 0}),PE({version:Tf,presets:Je,baseUpdatedAt:_r.current??void 0}).then(M=>{_r.current=typeof M.updatedAt=="number"?M.updatedAt:null,$n(qp,{version:Tf,presets:Je,updatedAt:_r.current??void 0})}).catch(M=>{const G=M instanceof Error&&"current"in M?M.current:null;G&&typeof G=="object"&&Vi(G),console.warn("[toolbar-presets] Failed to save to server:",M)})}},[Vi,Je,ht]),b.useEffect(()=>{dh().then(M=>{y(G=>G===M.preventSleep?G:M.preventSleep),S(G=>G===M.networkAvailable?G:M.networkAvailable),Y(M.localAccess),fe(M.localAccess.name),Tn(M.runningSessionButtonEnabled),$n(yf,M.runningSessionButtonEnabled),$n(bf,{preventSleep:M.preventSleep,networkAvailable:M.networkAvailable,localAccess:M.localAccess})}).catch(()=>{})},[]),b.useEffect(()=>{if(!A)return;const M=P1();$(M),M!=="granted"&&(T(!1),lp(!1))},[A]),b.useEffect(()=>{if(!A)return;Fd();const M=()=>{document.visibilityState==="visible"&&(Fd(),lR())},G=window.setInterval(()=>{Fd()},360*60*1e3);return document.addEventListener("visibilitychange",M),window.addEventListener("focus",M),()=>{window.clearInterval(G),document.removeEventListener("visibilitychange",M),window.removeEventListener("focus",M)}},[A]);const Ec=b.useCallback(async()=>{if(A){T(!1),lp(!1),aR(),$(P1());return}const M=await tR();if($(M),M!=="granted"){T(!1),lp(!1);return}T(!0),lp(!0),await Fd(!0,!0),ee("idle")},[A]),Ic=b.useCallback(async()=>{ee("checking"),await lo()?.prepareNotificationTest?.();const M=await Jp({title:"Termdock",body:e("settings.notificationsTestBody"),tag:"termdock-notification-test",requireHidden:!1,data:{url:"/"}});ee(M?"delivered":"failed")},[e]),Rc=b.useCallback(M=>{I(M),ZI(M),B1()},[]),Ba=b.useCallback(M=>{P(M),JI(M),B1()},[]),nc=b.useCallback(M=>{R(M),eR(M),B1()},[]);b.useEffect(()=>{Je.some(M=>M.id===et)||Zt(Je[0]?.id??"default")},[et,Je]),b.useEffect(()=>{if(!Rt.available&&Rr==="tmux"){Nn("shell",{userInitiated:!1});return}Rt.available&&tc!=="shell"&&Rr!=="tmux"&&Nn("tmux",{userInitiated:!1})},[Rr,Rt.available,tc,Nn]),b.useEffect(()=>{Ho(null)},[Ve,Rr,Rt.available]),b.useEffect(()=>{const M={};typeof navigator<"u"&&(M.userAgent=navigator.userAgent,M.platform=navigator.platform,M.maxTouchPoints=navigator.maxTouchPoints,M.hasTouch=navigator.maxTouchPoints>0||"ontouchstart"in window,M.vendor=navigator.vendor),typeof window<"u"&&(M.screenWidth=window.innerWidth,M.screenHeight=window.innerHeight,M.pixelRatio=window.devicePixelRatio,M.orientation=window.screen?.orientation?.type||"unknown",M.hasVisualViewport=!!window.visualViewport,M.visualViewportHeight=window.visualViewport?.height,M.visualViewportWidth=window.visualViewport?.width,M.location=window.location.href),M.timestamp=new Date().toISOString(),M.isIOS=/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1,M.isAndroid=/Android/.test(navigator.userAgent),Oe(M)},[]);const{groups:Lo}=D.useMemo(()=>uS(Ft,M=>Se.get(M.id)?.cwd??null,hn,e("sidebar.ungrouped")),[Ft,Se,hn,e]),vr=b.useCallback(M=>{if(cs(M)||!M.destination)return;if(M.type==="group"){if(M.source.index===M.destination.index)return;hr(cS(Lo,M.source.index,M.destination.index));return}if(M.source.droppableId!==M.destination.droppableId||M.source.index===M.destination.index)return;const G=M.source.droppableId.replace(/^group-sessions:/,"");hr(wF(Lo,G,M.source.index,M.destination.index))},[Lo,hr,cs]),Fa=D.useMemo(()=>Lo.length>0?Lo.flatMap(M=>M.sessions):Ft,[Lo,Ft]),qi=D.useMemo(()=>Fa.flatMap(M=>{const G=Se.get(M.id);if(G?.agentStatus!=="working")return[];const{primary:Re,secondary:rt}=gc(M,G?.activeProgram??null,G?.cwd??null,rl,G?.shellTitle??null,G?.promptState??null);return[{id:M.id,label:Re,detail:rt}]}),[Fa,Se]),Nc=Gt?Fa.findIndex(M=>M.id===Gt):-1,Oa=Fa.length>0&&Nc>=0?`${Nc+1}/${Fa.length}`:`${Fa.length}`,ha=D.useMemo(()=>{let M=0;for(const G of Ft){const Re=Se.get(G.id);(Re?.agentStatus==="waiting"||Re?.agentNeedsReview)&&(M+=1)}return{running:qi.length,review:M}},[qi.length,Ft,Se]),Vs=Gt?Ft.find(M=>M.id===Gt)??null:null,Uo=Vs?Se.get(Vs.id):void 0,pa=!!(Vs&&Uo?.agentResumeRecovered&&Uo.agentNativeSessionId&&Uo.terminalSessionId),qs=Vs&&nr?.sessionId===Vs.id?nr:null;D.useLayoutEffect(()=>{if(!ms)return;const M=gn.current;if(!M)return;const G=!fr.current;M.scrollIntoView({inline:"nearest",block:"nearest",behavior:G?"auto":"smooth"}),fr.current=!0,G&&Ff("active-tab-positioned")},[Gt,ms]),b.useEffect(()=>{pn&&Xn.current&&(Xn.current.scrollIntoView({block:"nearest",inline:"nearest"}),Xn.current.focus(),Xn.current.select()),pn||(Gr.current=!1)},[pn]);const hl=b.useCallback(M=>{window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:M}))},[]),Rl=b.useCallback((M,G)=>{Qr(G??null),sr(M)},[]),Nl=s9(),Qa=b.useCallback(M=>{if(!M)return;ls(M),ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-focus-request",{traceId:ws.current,requestedSessionId:M,activeSessionId:Gt,sessions:Ft.map(Re=>({id:Re.id,terminalSessionId:Se.get(Re.id)?.terminalSessionId??null}))}),cR(M);const G=Ft.find(Re=>Re.id===M||Se.get(Re.id)?.terminalSessionId===M);G?(di.current=null,ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-focus-dispatch",{traceId:ws.current,requestedSessionId:M,targetSessionId:G.id}),window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G.id}))):(di.current=M,ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-focus-pending",{traceId:ws.current,requestedSessionId:M}))},[Gt,Ft,Se]);b.useEffect(()=>{if(typeof window>"u"||typeof caches>"u")return;let M=!1;const G=async()=>{try{const rt=await caches.open(Qte),Pt=await rt.match(f7);if(!Pt)return;await rt.delete(f7);const Wt=await Pt.json();if(M)return;const Pn=typeof Wt.sessionId=="string"?Wt.sessionId:null,Fr=typeof Wt.traceId=="string"?Wt.traceId:null,Yr=typeof Wt.clickedAt=="number"?Wt.clickedAt:0,Xr=Date.now()-Yr;Ca("info","PWA_NOTIFICATION_CLICK app-cache-consumed",{traceId:Fr,sessionId:Pn,ageMs:Xr,valid:!!(Pn&&Xr>=0&&Xr<=h7),visibilityState:document.visibilityState}),Pn&&Xr>=0&&Xr<=h7&&(ws.current=Fr,Qa(Pn))}catch(rt){Ca("warn","PWA_NOTIFICATION_CLICK app-cache-failed",{error:rt instanceof Error?rt.message:String(rt)})}finally{M||ui(!0)}},Re=()=>{document.visibilityState==="visible"&&G()};return G(),document.addEventListener("visibilitychange",Re),window.addEventListener("pageshow",G),()=>{M=!0,document.removeEventListener("visibilitychange",Re),window.removeEventListener("pageshow",G)}},[Qa]),b.useEffect(()=>{if(typeof window>"u")return;const M=new URLSearchParams(window.location.search),G=M.get("session");if(!G)return;Ca("info","PWA_NOTIFICATION_CLICK app-url-received",{traceId:ws.current,targetSessionId:G,href:window.location.href,visibilityState:document.visibilityState}),di.current=G,M.delete("session"),M.delete("_notifTrace");const Re=M.toString(),rt=`${window.location.pathname}${Re?`?${Re}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",rt)},[]),b.useEffect(()=>{if(typeof window>"u")return;const M=new URLSearchParams(window.location.search);if(M.get("_notif")!=="1")return;const G=M.get("session");M.delete("_notif");const Re=M.toString(),rt=`${window.location.pathname}${Re?`?${Re}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",rt);const Pt=new BroadcastChannel("termdock:notif");let Wt=!1;const Pn=Yr=>{Yr.data?.type==="termdock:notif-pong"&&!Wt&&(Wt=!0,Pt.close(),window.close())};Pt.addEventListener("message",Pn),Pt.postMessage({type:"termdock:notif-ping",sessionId:G});const Fr=setTimeout(()=>{Wt||Pt.close()},500);return()=>{clearTimeout(Fr),Wt||Pt.close()}},[]),b.useEffect(()=>{if(typeof window>"u")return;const M=new BroadcastChannel("termdock:notif"),G=Re=>{Re.data?.type==="termdock:notif-ping"&&(M.postMessage({type:"termdock:notif-pong"}),typeof Re.data.sessionId=="string"&&Qa(Re.data.sessionId))};return M.addEventListener("message",G),()=>M.close()},[Qa]),b.useEffect(()=>{if(typeof navigator>"u"||!("serviceWorker"in navigator))return;const M=G=>{const Re=G.data;Re&&Re.type==="termdock:focus-session"&&typeof Re.sessionId=="string"?(G.ports[0]?.postMessage({type:"termdock:focus-session-ack"}),Qa(Re.sessionId)):Re?.type==="termdock:push-subscription-changed"?Fd(!0):Re?.type};return navigator.serviceWorker.addEventListener("message",M),()=>navigator.serviceWorker.removeEventListener("message",M)},[Qa]),b.useEffect(()=>{const M=G=>{const Re=G.detail;typeof Re=="string"&&Qa(Re)};return window.addEventListener("termdock:focus-session",M),()=>window.removeEventListener("termdock:focus-session",M)},[Qa]),b.useEffect(()=>{const M=di.current;if(!M)return;const G=Ft.find(Re=>Re.id===M||Se.get(Re.id)?.terminalSessionId===M);G?(di.current=null,ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-pending-dispatch",{traceId:ws.current,requestedSessionId:M,targetSessionId:G.id,activeSessionId:Gt}),window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G.id}))):ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-pending-unmatched",{traceId:ws.current,requestedSessionId:M,activeSessionId:Gt,sessions:Ft.map(Re=>({id:Re.id,terminalSessionId:Se.get(Re.id)?.terminalSessionId??null}))})},[Gt,Ft,Se]);const ma=D.useMemo(()=>{const M=[];for(const G of Ft){const Re=Se.get(G.id);(Re?.agentStatus==="waiting"||Re?.agentNeedsReview)&&M.push(G.id)}return M},[Ft,Se]),rc=b.useCallback(()=>{if(ma.length===0)return;Gt&&es.getState().clearAgentNeedsReview(Gt);const M=Gt?Ft.findIndex(Re=>Re.id===Gt):-1,G=ma.find(Re=>Ft.findIndex(rt=>rt.id===Re)>M)??ma[0];G&&window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G}))},[ma,Ft,Gt]),ga=b.useCallback(()=>{if(ma.length===0)return;Gt&&es.getState().clearAgentNeedsReview(Gt);const M=Gt?Ft.findIndex(Re=>Re.id===Gt):Ft.length,G=[...ma].reverse().find(Re=>Ft.findIndex(rt=>rt.id===Re)<M)??ma[ma.length-1];G&&window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G}))},[ma,Ft,Gt]);b.useEffect(()=>{const M=G=>{!G.altKey||!G.shiftKey||G.metaKey||G.ctrlKey||G.key!=="ArrowUp"&&G.key!=="ArrowDown"||(G.preventDefault(),G.key==="ArrowUp"?ga():rc())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[rc,ga]);const zo=b.useCallback(async M=>{const Re=es.getState().sessions.get(M)?.cwd;if(Re)try{await navigator.clipboard?.writeText(Re),tt(Re),window.setTimeout(()=>{tt(rt=>rt===Re?null:rt)},1400)}catch{}},[]),As=b.useCallback(M=>{Zn(M.sessions),Cr(M.activeSessionId),wr(M.splitWorkspaces),es.getState().setActiveSessionId(M.activeSessionId)},[]);b.useEffect(()=>{if(!kr||!Gt)return;Ft.find(G=>G.id===kr||Se.get(G.id)?.terminalSessionId===kr)?.id===Gt&&ls(null)},[Gt,kr,Ft,Se]);const bi=b.useCallback(M=>{const G=M?.mode??Rr,Re=G==="tmux"&&(M?.tmuxSessionName?.trim()||Ws.trim())||void 0,rt=M?.cwd||(Gt?es.getState().sessions.get(Gt)?.cwd:void 0);window.dispatchEvent(new CustomEvent("new-terminal-session",{detail:{mode:G,tmuxSessionName:Re,cwd:rt,command:M?.command}}))},[Rr,Ws,Gt]),Rs=b.useCallback(async()=>{Jt(!0);try{const M=await vb();if(vn(M),!M.available){$t([]);return}const G=await yb();$t(G)}catch{vn({available:!1,version:null,reason:"tmux integration is unavailable with the current server build."}),$t([])}finally{Jt(!1)}},[]),Ml=b.useCallback(async M=>{jt(M),An(null);try{const{cleanedSessions:G}=await V7(M);for(const Re of G)window.dispatchEvent(new CustomEvent("close-terminal-session-by-backend",{detail:Re}));qe(null),await Rs()}catch(G){An(G instanceof Error?G.message:"Failed to kill tmux session")}finally{jt(null)}},[Rs]);b.useEffect(()=>{if(!_n)return;if(at.find(Re=>Re.name===_n&&(Re.connected||Re.boundFrontendSessionId))){ln(null);return}const G=setTimeout(()=>ln(null),1e4);return()=>clearTimeout(G)},[_n,at]);const xa=b.useCallback(M=>{window.dispatchEvent(new CustomEvent("close-terminal-session",{detail:M}))},[]),au=b.useCallback(M=>{const G=M??Gt;G&&window.dispatchEvent(new CustomEvent("open-terminal-split-chooser",{detail:G}))},[Gt]),Dl=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("set-terminal-split-direction",{detail:{sessionId:M,layout:G}}))},[]),lu=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("reorder-terminal-split-workspace",{detail:{workspaceId:M,sessionIds:G}}))},[]),sc=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("rename-terminal-split-workspace",{detail:{workspaceId:M,name:G}}))},[]),Mc=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("combine-terminal-split-sessions",{detail:{primaryId:M,secondaryId:G}}))},[]),ic=b.useCallback((M,G)=>{const Re=Ft.find(Pt=>Pt.id===M);if(!Re)return;const rt=Se.get(M);if(hW({mode:Re.mode,activeProgram:rt?.activeProgram??null,promptState:rt?.promptState??null,shellNames:rl})){xa({sessionId:M,source:"sidebar",closeMode:Re.mode==="tmux"?"destroy":"auto"});return}ir(G?{x:G.clientX,y:G.clientY}:null),en(M),An(null)},[Ft,Se,xa]);b.useEffect(()=>{if(!ke)return;const M=G=>{const Re=G.detail;Re==="new-session"?bi():Re==="close-session"?Gt&&ic(Gt):Re==="previous-session"||Re==="next-session"?window.dispatchEvent(new CustomEvent("cycle-terminal-session",{detail:{direction:Re==="next-session"?"next":"prev"}})):Re==="toggle-left-sidebar"?Js():Re==="toggle-right-sidebar"?Wi():Re==="previous-attention"?ga():Re==="next-attention"&&rc()};return window.addEventListener("termdock:native-command",M),()=>window.removeEventListener("termdock:native-command",M)},[Gt,ke,bi,ic,Js,Wi,rc,ga]);const ba=D.useMemo(()=>Ft.find(M=>M.id===dr)??null,[Ft,dr]),ya=D.useMemo(()=>{if(!ba)return"";const M=Se.get(ba.id);return gc(ba,M?.activeProgram??null,M?.cwd??null,rl,M?.shellTitle??null,M?.promptState??null).primary},[ba,Se]);b.useEffect(()=>{if(!Ve)return;let M=!1,G=!1;const Re=async()=>{if(!G)try{const Pt=await vb();if(M||vn(Pt),!Pt.available){M||$t([]);return}const Wt=await yb();M||$t(Wt)}catch{G=!0,M||(vn({available:!1,version:null,reason:"tmux integration is unavailable with the current server build."}),$t([]))}};Re();const rt=setInterval(()=>{Re()},4e3);return()=>{M=!0,clearInterval(rt)}},[Ve]);const yi=Kr??Rr,$a=yi==="shell",va=yi==="tmux"&&Rt.available,pl=D.useMemo(()=>by(at.map(M=>({...M,id:M.name})),M=>M.cwd??null,e("sidebar.ungrouped")),[at,e]),jl=(M,G,Re,rt=!1)=>{const Pt=M.id===Gt,Wt=M.id===pn,Pn=Se.get(M.id),{primary:Fr,secondary:Yr}=gc(M,Pn?.activeProgram??null,Pn?.cwd??null,rl,Pn?.shellTitle??null,Pn?.promptState??null),Xr=Sc(Pn?.cwd??null),Go=G?Yr??(Xr&&Xr!==Fr?Xr:null):null,Zr=Pn?.gitStatus,vi=`${Pn?.cwd||M.name}${Zr?`
242
- ⎇ ${Zr.branch} +${Zr.added} −${Zr.removed}`:""}`,Ki=!!(Pn?.tuiProgress&&Pn.tuiProgress.state!=="remove"),Xi=Pn?.agentStatus==="working"||Ki?"var(--success)":Pn?.agentStatus==="waiting"||Pn?.agentNeedsReview?"var(--warning)":Pn?.inCopyMode?"var(--tmux)":null;if(Wt&&zn&&!se){const Ri=M.customName?M.name:Fr,Sr=(ds,si)=>{const Zi=si.trim();Zi?Zi!==Ri&&Gs(ds,Zi):qr(ds),tn(null)};return o.jsx("input",{ref:ds=>{Xn.current=ds},type:"text",defaultValue:Ri,className:"h-8 shrink-0 rounded-md bg-surface-elevated px-2 text-[12px] leading-none text-foreground outline-none ring-1 ring-primary/50 sm:h-8 min-w-[5rem]",style:{width:`${Math.max(Ri.length,5)}ch`},onKeyDown:ds=>{ds.key==="Enter"?Sr(M.id,ds.target.value):ds.key==="Escape"&&tn(null)},onBlur:ds=>Sr(M.id,ds.target.value)})}return o.jsx("div",{ref:Pt?gn:null,onContextMenu:Ri=>{Ri.preventDefault(),Qr({x:Ri.clientX,y:Ri.clientY}),sr(M.id)},...Nl(()=>Rl(M.id)),className:rt?`group relative inline-flex h-5 shrink-0 items-center rounded-sm text-[11px] leading-none transition ${Pt?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:bg-surface-elevated/40 hover:text-foreground"}`:`group relative inline-flex h-8 shrink-0 items-center rounded-md text-[12px] leading-none transition sm:h-8 ${Pt?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:bg-surface-elevated/50 hover:text-foreground"}`,style:!rt&&Pt&&Xi?{boxShadow:`inset 2px 0 0 0 ${Xi}`}:!rt&&Pt?{boxShadow:"inset 2px 0 0 0 rgb(var(--primary-rgb, 99 102 241))"}:void 0,title:vi,children:o.jsx("button",{type:"button",...Re??{},onClick:()=>hl(M.id),className:`inline-flex min-w-0 flex-1 items-center gap-1 overflow-hidden text-left ${rt?"px-1":"py-1 pl-1 pr-1.5 sm:pl-1.5 sm:pr-2"} ${Re?"cursor-grab active:cursor-grabbing":""}`,title:vi,children:o.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1 overflow-hidden",children:[o.jsxs("span",{className:"inline-flex shrink-0 items-center",children:[m7(M.mode,Pn),Pn?.agentResumeRecovered&&o.jsx(wf,{size:rt?9:10,className:"-ml-0.5 shrink-0 text-[color:var(--warning)]","aria-label":e("tab.resumeAgentAvailable")}),Ki&&!Pn?.agentStatus&&o.jsx(Fn,{size:rt?9:10,className:"-ml-0.5 shrink-0 animate-spin text-[color:var(--success)]"})]}),Go?o.jsxs("span",{className:"flex min-w-0 flex-col justify-center leading-[0.82rem] sm:leading-[0.85rem]",children:[o.jsx("span",{className:`whitespace-nowrap text-[11px] sm:text-[12px] ${Pn?.inCopyMode?"text-[color:var(--tmux)]":""}`,children:Fr}),o.jsx("span",{className:"truncate text-[9px] text-muted-foreground/80 sm:text-[9.5px]",children:Go})]}):o.jsx("span",{className:`whitespace-nowrap text-[11px] sm:text-[12px] ${Pn?.inCopyMode?"text-[color:var(--tmux)]":""}`,children:Fr})]})})})},Dc=()=>o.jsx(Bu,{droppableId:W2,type:"session",isDropDisabled:zn,children:(M,G)=>{const Re=st||G.isDraggingOver;return o.jsxs("div",{ref:M.innerRef,...M.droppableProps,className:"pointer-events-none fixed left-1/2 top-[42%] z-toast flex h-32 w-32 -translate-x-1/2 -translate-y-1/2 items-center justify-center",role:"status","aria-live":"polite","aria-hidden":!Qt,"data-mobile-session-destroy-target":"","data-active":Re?"true":"false",children:[o.jsxs("div",{className:`flex h-28 w-28 flex-col items-center justify-center gap-2 rounded-full border bg-surface-elevated/95 shadow-2xl backdrop-blur transition duration-200 ${Qt?Re?"scale-110 border-destructive bg-destructive text-destructive-foreground opacity-100":"scale-100 border-destructive/50 text-destructive opacity-100":"scale-75 border-transparent opacity-0"}`,children:[o.jsx($i,{size:28,strokeWidth:1.8}),o.jsx("span",{className:"px-2 text-center text-[11px] font-semibold leading-tight",children:e(Re?"tab.releaseToDestroy":"tab.dragToDestroy")})]}),M.placeholder]})}}),Ys=nn&&zn,jc=un&&zn,oc=px(Hn,Bt,Ys?vt:0),Yi=Ys?Ft.find(M=>M.id===Gt):null,Hs=Yi?Se.get(Yi.id):void 0,js=Yi?gc(Yi,Hs?.activeProgram??null,Hs?.cwd??null,rl,Hs?.shellTitle??null,Hs?.promptState??null).primary:"",_0=Ys&&Hs?Hs.agentStatus==="working"?"bg-gradient-to-r from-[rgb(var(--success-rgb)_/_0.08)] to-transparent":Hs.agentStatus==="waiting"?"bg-gradient-to-r from-[rgb(var(--warning-rgb)_/_0.14)] to-transparent":Hs.agentNeedsReview?"bg-gradient-to-r from-[rgb(var(--warning-rgb)_/_0.08)] to-transparent":Hs.inCopyMode?"bg-gradient-to-r from-[rgb(var(--tmux-rgb)_/_0.07)] to-transparent":"":"",ml=o.jsxs("div",{className:"w-full h-full flex flex-col app-chrome-bg text-foreground",children:[o.jsx("main",{className:"relative min-h-0 flex-1 overflow-visible px-0 pb-0 pt-0",children:o.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col overflow-visible app-chrome-bg",children:[o.jsxs("div",{className:`shrink-0 items-center gap-1 app-chrome-bg px-1 sm:px-1.5 transition-colors duration-500 ${Ys?"relative flex justify-end":"flex justify-between"} ${hn?"h-10 sm:h-10":"h-9 sm:h-10"} ${_0}`,children:[!Ys&&o.jsxs("button",{type:"button",onClick:Js,className:"relative inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-surface-elevated hover:text-foreground sm:h-8 sm:w-8","aria-label":e("tab.sessionsTitle"),title:`${e("tab.sessionsTitle")} · ${e("agent.aiRunning")}: ${ha.running} · ${e("agent.needsReview")}: ${ha.review}`,children:[o.jsx(mM,{size:14}),o.jsx(tq,{runningCount:ha.running,reviewCount:ha.review,className:"sm:hidden"})]}),Ys?o.jsx("div",{className:"absolute left-1/2 flex max-w-[40%] min-w-0 -translate-x-1/2 items-center justify-center gap-1.5 overflow-hidden",children:Yi?o.jsxs(o.Fragment,{children:[m7(Yi.mode,Hs),o.jsx("span",{className:`truncate text-[12px] font-medium ${Hs?.inCopyMode?"text-[color:var(--tmux)]":"text-foreground"}`,children:js}),Hs?.agentStatus==="working"&&o.jsx("span",{title:Hs?.agentMessage??void 0,children:o.jsx(Fn,{size:12,className:"shrink-0 animate-spin text-[color:var(--success)]"})}),Hs?.agentStatus==="waiting"&&o.jsx("span",{title:Hs?.agentMessage??void 0,children:o.jsx(Tm,{size:12,className:"shrink-0 animate-bounce-y text-[color:var(--warning)]"})}),!Hs?.agentStatus&&Hs?.agentNeedsReview&&o.jsx("span",{title:Hs?.agentMessage??void 0,children:o.jsx(eu,{size:13,className:"shrink-0 animate-pulse text-[color:var(--warning)]"})})]}):o.jsx("span",{className:"truncate px-2 text-[12px] text-muted-foreground",children:e("sidebar.sessions")})}):hn?o.jsxs(zm,{onDragStart:Ss,onDragUpdate:qn,onDragEnd:vr,children:[Dc(),o.jsx(Bu,{droppableId:"groups",type:"group",direction:"horizontal",children:M=>o.jsxs("div",{ref:M.innerRef,...M.droppableProps,className:"scrollbar-hidden flex h-full min-w-0 flex-1 items-center gap-1 overflow-x-auto overflow-y-hidden whitespace-nowrap px-0.5 py-0.5",style:{touchAction:"pan-x"},children:[Lo.map((G,Re)=>{let rt=0,Pt=0;for(const Yr of G.sessions){const Xr=Se.get(Yr.id);Xr?.agentStatus==="working"&&(rt+=1),(Xr?.agentStatus==="waiting"||Xr?.agentNeedsReview)&&(Pt+=1)}const Wt=G.sessions.some(Yr=>Yr.id===Gt),Pn=Kn.has(G.key),Fr=G.key==="";return o.jsx(Pu,{draggableId:`group-${G.key||"__ungrouped__"}`,index:Re,isDragDisabled:Fr,disableInteractiveElementBlocking:!0,children:(Yr,Xr)=>o.jsxs("div",{ref:Yr.innerRef,...Yr.draggableProps,className:`flex w-fit shrink-0 flex-col justify-center gap-px rounded-md py-0.5 px-1 ring-1 transition-colors ${Xr.isDragging?"bg-surface-elevated ring-primary/30 shadow-lg opacity-90":Wt?"bg-primary/[0.06] ring-primary/20":"bg-surface-2/40 ring-border/10"}`,children:[o.jsxs("button",{type:"button",...Fr?{}:Yr.dragHandleProps,onClick:()=>sn(G.key),className:`flex ${Pn?"":G.sessions.length>1?"w-0 min-w-full":""} items-center gap-0.5 rounded text-[9px] font-semibold uppercase tracking-[0.08em] leading-none transition hover:bg-surface-elevated/40 ${Fr?"":"cursor-grab active:cursor-grabbing"} ${Wt?"text-primary/80":"text-muted-foreground/55"}`,title:G.key||G.label,children:[o.jsx(_l,{size:9,className:`shrink-0 opacity-70 transition-transform ${Pn?"":"rotate-90"}`}),o.jsx("span",{className:"min-w-0 truncate",children:G.label}),rt>0&&o.jsx("span",{className:"ml-auto h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--success)]"}),Pt>0&&o.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--warning)] ${rt>0?"":"ml-auto"}`})]}),Pn?o.jsx("span",{className:"flex h-5 items-center text-[10px] leading-none text-muted-foreground/50",children:e("tab.sessionCount",{count:G.sessions.length})}):o.jsx(Bu,{droppableId:`group-sessions:${G.key}`,type:"session",direction:"horizontal",children:Go=>o.jsxs("div",{ref:Go.innerRef,...Go.droppableProps,className:"flex items-center gap-px",children:[G.sessions.map((Zr,vi)=>o.jsx(Pu,{draggableId:Zr.id,index:vi,disableInteractiveElementBlocking:!0,children:(Ki,Xi)=>o.jsx("div",{ref:Ki.innerRef,...Ki.draggableProps,className:`flex shrink-0 items-center ${Xi.isDragging?"opacity-70":""}`,children:jl(Zr,!1,Ki.dragHandleProps,!0)})},Zr.id)),Go.placeholder]})})]})},G.key||"__ungrouped__")}),M.placeholder,o.jsx("button",{type:"button",onClick:()=>bi(),className:"my-auto inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-primary/15 hover:text-primary active:scale-95","aria-label":e("tab.new"),title:e("tab.new"),children:o.jsx(Ao,{size:14})})]})})]}):o.jsxs(zm,{onDragStart:Ss,onDragUpdate:qn,onDragEnd:Vr,children:[Dc(),o.jsx(Bu,{droppableId:"tabs",type:"session",direction:"horizontal",children:M=>o.jsxs("div",{ref:M.innerRef,...M.droppableProps,className:"scrollbar-hidden flex h-full min-w-0 flex-1 items-center gap-1 overflow-x-auto overflow-y-hidden whitespace-nowrap",style:{touchAction:"pan-x"},children:[Ft.map((G,Re)=>G.id===pn?o.jsx(D.Fragment,{children:o.jsx(Pu,{draggableId:G.id,index:Re,isDragDisabled:!0,children:Pt=>o.jsx("div",{ref:Pt.innerRef,...Pt.draggableProps,className:"flex h-full items-center",children:jl(G,!0)})})},G.id):o.jsx(D.Fragment,{children:o.jsx(Pu,{draggableId:G.id,index:Re,disableInteractiveElementBlocking:!0,children:(Pt,Wt)=>o.jsx("div",{ref:Pt.innerRef,...Pt.draggableProps,className:`flex h-full shrink-0 items-center ${Wt.isDragging?"opacity-70":""}`,children:jl(G,!0,Pt.dragHandleProps)})})},G.id)),o.jsx("button",{type:"button",onClick:()=>bi(),className:"ml-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-primary/15 hover:text-primary active:scale-95","aria-label":e("tab.new"),title:e("tab.new"),children:o.jsx(Ao,{size:14})}),M.placeholder]})})]}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[GI(ke)&&o.jsx(Ete,{bridge:ke,runningCount:ha.running,reviewCount:ha.review,labels:{switchService:e("desktopServices.switchService"),openServices:e("desktopServices.openServices"),current:e("agent.currentSession"),running:e("agent.aiRunning"),review:e("agent.needsReview"),idle:e("desktopServices.idle"),manageServices:e("desktopServices.manageServices")}}),!Ys&&ha.running>0&&o.jsx("span",{className:"hidden items-center gap-1 sm:inline-flex",children:o.jsx(T9,{count:ha.running,tone:"running",title:e("agent.aiRunning")})}),!Ys&&Ft.length>0&&o.jsx("span",{className:"inline-flex shrink-0 items-center px-1 text-[10px] uppercase tracking-[0.16em] text-muted-foreground sm:text-[11px]",title:`Session ${Nc+1} of ${Ft.length}`,children:Oa}),!jc&&o.jsx("button",{type:"button",onClick:Wi,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-surface-elevated hover:text-foreground sm:h-8 sm:w-8","aria-label":e("tab.explorerTitle"),title:e("tab.explorerTitle"),children:o.jsx(xM,{size:14})})]})]}),pa&&Vs&&Uo?.terminalSessionId&&o.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/15 bg-surface/80 px-3 py-2 animate-fade-in sm:px-4",role:"status","data-testid":"agent-resume-recovery-banner",children:[o.jsx("span",{className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-[rgb(var(--warning-rgb)_/_0.14)] text-[color:var(--warning)]",children:!qs?.error&&(qs?.status==="submitting"||qs?.status==="waiting")?o.jsx(Fn,{size:14,className:"animate-spin"}):o.jsx(wf,{size:14})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:e("tab.resumeAgentRecoveredTitle",{agent:Uo.agent?.displayName??"Agent"})}),o.jsx("div",{className:`truncate text-[10px] sm:text-[11px] ${qs?.error?"text-destructive":"text-muted-foreground"}`,children:qs?.error??(qs?.status==="submitting"?e("tab.resumeAgentSubmitting"):qs?.status==="waiting"?e("tab.resumeAgentWaiting"):e("tab.resumeAgentRecoveredHint"))})]}),o.jsx("button",{type:"button",disabled:!qs?.error&&(qs?.status==="submitting"||qs?.status==="waiting"),onClick:()=>{It(Vs.id,Uo.terminalSessionId)},className:"shrink-0 rounded-full bg-primary px-3 py-1.5 text-[11px] font-semibold text-primary-foreground transition hover:opacity-90 active:scale-95 disabled:cursor-wait disabled:opacity-60 sm:text-[12px]",children:qs?.error?e("common.retry"):e("tab.resumeAgentNow")}),o.jsx("button",{type:"button",onClick:()=>{es.getState().setAgentResumeRecovered(Vs.id,!1),an(M=>M?.sessionId===Vs.id?null:M)},className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-2 hover:text-foreground","aria-label":e("tab.resumeAgentLater"),title:e("tab.resumeAgentLater"),children:o.jsx(ts,{size:13})})]}),o.jsx("div",{ref:jn,className:"min-h-0 flex-1 flex overflow-hidden app-chrome-bg",children:o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:o.jsx($Q,{terminalSettings:Dt,colorTheme:u,toolbarPresets:Je,showDebug:a,terminalFocusAvailable:Ii,defaultSessionMode:Rr,defaultTmuxSessionName:Ws,connectionPrioritySessionId:kr,connectionPriorityReady:ms,onSessionDataUpdate:As})})})]})}),o.jsx(oq,{reviewCount:ha.review,runningSessions:qi,activeSessionId:Gt,runningButtonEnabled:Lt,isDesktopLayout:zn,containerElement:lr}),Ve&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-drawer-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm animate-fade-in cursor-default",onClick:ut,"aria-label":e("settings.closeSettings")}),o.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"settings-dialog-title",className:"pointer-events-none fixed inset-0 z-drawer-panel flex items-stretch justify-center p-0 animate-fade-in sm:p-4 md:p-6",children:o.jsxs("div",{className:"pointer-events-auto flex h-full w-full max-w-5xl flex-col overflow-hidden bg-surface shadow-[0_28px_90px_var(--app-shadow-strong),0_14px_34px_var(--app-shadow-soft)] sm:max-h-[calc(100dvh-3rem)] sm:rounded-3xl sm:border sm:border-border/15",style:{paddingTop:r,paddingBottom:s},children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border/15 px-4 py-3 sm:px-6 sm:py-4",children:[o.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[o.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-full bg-primary/15 text-primary sm:h-9 sm:w-9",children:o.jsx(HM,{size:15})}),o.jsx("h2",{id:"settings-dialog-title",className:"text-[15px] font-semibold text-foreground sm:text-[16px]",children:e("settings.title")})]}),o.jsx("button",{type:"button",onClick:ut,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive","aria-label":e("common.close"),children:o.jsx(ts,{size:16})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto bg-background/25 px-3 py-3 sm:px-6 sm:py-5 md:px-8",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-2.5 py-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.font")}),o.jsx("button",{type:"button",onClick:()=>$e({fontSize:Math.max(8,Ut-1)}),className:"h-8 w-8 shrink-0 rounded-md bg-surface text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:"−"}),o.jsx("input",{type:"range",min:"8",max:"32",value:Ut,onChange:M=>$e({fontSize:parseInt(M.target.value,10)}),className:"min-w-0 flex-1","aria-label":e("settings.font")}),o.jsx("button",{type:"button",onClick:()=>$e({fontSize:Math.min(32,Ut+1)}),className:"h-8 w-8 shrink-0 rounded-md bg-surface text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:"+"}),o.jsxs("span",{className:"w-8 shrink-0 text-right text-[11px] tabular-nums text-muted-foreground",children:[Ut,"px"]})]}),o.jsx("div",{className:"space-y-1.5 rounded-xl bg-surface-2 px-2.5 py-2",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.render")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:["auto","webgl","canvas"].map(M=>{const G=_t===M;return o.jsx("button",{type:"button",onClick:()=>$e({rendererMode:M}),className:`flex-1 rounded px-2 py-1 text-[11px] font-medium transition ${G?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-surface-elevated"}`,children:e(M==="auto"?"settings.auto":M==="webgl"?"settings.webgl":"settings.canvas")},M)})})]})}),o.jsx("div",{className:"space-y-1.5 rounded-xl bg-surface-2 px-2.5 py-2",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.theme")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:[["dark",cM,e("settings.darkTheme")],["light",VM,e("settings.lightTheme")]].map(([M,G,Re])=>{const rt=u===M;return o.jsxs("button",{type:"button",onClick:()=>f(M),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition ${rt?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-surface-elevated"}`,children:[o.jsx(G,{size:12}),o.jsx("span",{children:Re})]},M)})})]})}),o.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-2.5 py-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.newTab")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:["shell","tmux"].map(M=>{const G=Rr===M,Re=M==="tmux"&&!Rt.available;return o.jsx("button",{type:"button",disabled:Re,onClick:()=>Nn(M,{userInitiated:!0}),className:`flex-1 rounded px-2 py-1 text-[11px] font-medium transition ${G?"bg-primary/20 text-primary":Re?"cursor-not-allowed text-muted-foreground/40":"text-muted-foreground hover:bg-surface-elevated"}`,title:Re?Rt.reason||e("settings.installTmuxHint"):void 0,children:e(M==="shell"?"settings.shell":"settings.tmux")},M)})})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>c(!a),className:`flex items-center justify-between rounded-xl px-3 py-2 text-[12px] transition ${a?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,children:[o.jsx("span",{className:"font-medium",children:e("settings.debug")}),o.jsx(xc,{checked:a,size:"sm"})]}),o.jsxs("button",{type:"button",onClick:async()=>{const M=!g;y(M);try{const G=await ta({preventSleep:M});y(G.preventSleep),S(G.networkAvailable),Y(G.localAccess),$n(bf,{preventSleep:G.preventSleep,networkAvailable:G.networkAvailable,localAccess:G.localAccess})}catch{y(!M)}},className:`flex items-center justify-between rounded-xl px-3 py-2 text-[12px] transition ${g?"bg-[rgb(var(--success-rgb)_/_0.15)] text-[color:var(--success)]":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:!v&&g?e("settings.noSleepUnavailable"):void 0,children:[o.jsx("span",{className:"font-medium truncate",children:e("settings.noSleep")}),o.jsx(xc,{checked:g,size:"sm"})]})]})]}),o.jsxs("button",{type:"button",onClick:()=>B(!0),className:"mt-3 flex w-full items-center justify-between gap-2 rounded-xl bg-surface-2 px-3 py-2.5 text-left text-[13px] transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[o.jsx(g8,{size:14,className:A?"shrink-0 text-primary":"shrink-0 text-muted-foreground"}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block font-medium text-foreground",children:e("settings.notifications")}),o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:e(A?L&&j?"settings.notificationsBothOnSummary":L?"settings.notificationsAiOnSummary":j?"settings.notificationsExitOnSummary":"settings.notificationsNoEventsSummary":"settings.notificationsOffSummary")})]})]}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[o.jsx("span",{children:e(A?"common.on":"common.off")}),o.jsx("span",{children:"›"})]})]}),o.jsxs("details",{className:"mt-3 rounded-xl bg-surface-2 px-3 py-3",open:!1,children:[o.jsxs("summary",{className:"flex cursor-pointer items-start justify-between gap-2 list-none",children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground/90",children:e("settings.localAccess")}),o.jsx("div",{className:"mt-0.5 text-[10px] text-muted-foreground",children:e("settings.localAccessHint")})]}),o.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] ${H.status==="active"?"bg-primary/15 text-primary":"bg-surface text-muted-foreground"}`,children:H.status})]}),o.jsxs("div",{className:"mt-3 flex items-center overflow-hidden rounded-lg bg-surface ring-1 ring-border/10 focus-within:ring-primary/40",children:[o.jsx("input",{value:V,onChange:M=>fe(M.target.value.toLowerCase()),className:"min-w-0 flex-1 bg-transparent px-2.5 py-2 text-[12px] text-foreground outline-none",placeholder:"jovn",spellCheck:!1}),o.jsx("span",{className:"shrink-0 border-l border-border/10 px-2.5 py-2 text-[11px] text-muted-foreground",children:".termdock.local"})]}),o.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",disabled:X,onClick:()=>{Ct()},className:"rounded-full bg-primary/15 px-3 py-1.5 text-[11px] font-medium text-primary transition hover:bg-primary/25 disabled:opacity-50",children:e(X?"settings.saving":"common.save")}),o.jsx("button",{type:"button",disabled:X,onClick:()=>{On()},className:"rounded-full bg-surface px-3 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated disabled:opacity-50",children:e("settings.resetAutoName")})]}),o.jsxs("div",{className:"mt-3 space-y-1.5 text-[11px]",children:[H.url&&o.jsxs("button",{type:"button",onClick:()=>{Ae(H.url,"lan")},className:"flex w-full items-center justify-between gap-2 rounded-lg bg-surface px-2.5 py-2 text-left text-muted-foreground transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"min-w-0 truncate",children:["Branded: ",H.url]}),o.jsx("span",{className:"shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium",children:ae==="lan"?"Copied":e("common.copy")})]}),H.interfaces.length>0&&o.jsxs("details",{className:"rounded-lg bg-surface px-2.5 py-2 text-muted-foreground",open:!1,children:[o.jsx("summary",{className:"cursor-pointer text-[11px] font-medium text-foreground/80",children:"IP fallback addresses"}),o.jsx("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:H.interfaces.map(M=>{const G=M.url??`${H.httpsEnabled?"https":"http"}://${M.address}:9834`;return o.jsxs("div",{className:"rounded-lg bg-surface-2 p-2",children:[o.jsxs("div",{className:"text-[11px] font-medium text-foreground/85",children:[M.label," (",M.name,")"]}),o.jsx("div",{className:"mt-0.5 text-[10px] text-muted-foreground",children:M.address}),M.qrDataUrl&&o.jsx("div",{className:"mt-2 inline-block rounded-lg bg-[var(--background)] p-1.5",children:o.jsx("img",{src:M.qrDataUrl,alt:`QR code for ${G}`,className:"h-28 w-28"})}),o.jsxs("button",{type:"button",onClick:()=>{Ae(G,`ip-${M.address}`)},className:"mt-2 flex w-full items-center justify-between gap-2 rounded-md bg-surface px-2 py-1.5 text-left text-[11px] transition hover:bg-surface-elevated",children:[o.jsx("span",{className:"min-w-0 truncate",children:G}),o.jsx("span",{className:"shrink-0 text-[10px]",children:ae===`ip-${M.address}`?"Copied":e("common.copy")})]})]},`${M.name}-${M.address}`)})})]}),H.onboardingUrl&&o.jsxs("button",{type:"button",onClick:()=>{Ae(H.onboardingUrl,"setup")},className:"flex w-full items-center justify-between gap-2 rounded-lg bg-surface px-2.5 py-2 text-left text-muted-foreground transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"min-w-0 truncate",children:[e("settings.onboardingUrl"),": ",H.onboardingUrl]}),o.jsx("span",{className:"shrink-0 rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium",children:ae==="setup"?"Copied":e("common.copy")})]}),o.jsxs("div",{className:"text-muted-foreground",children:[H.httpsEnabled?e("settings.httpsActive"):e("settings.httpsInactive"),!H.caAvailable&&` · ${e("settings.caMissing")}`]}),H.reason&&o.jsx("div",{className:"text-[color:var(--warning)]",children:H.reason}),we&&o.jsx("div",{className:"text-destructive",children:we})]})]}),o.jsx(Lte,{state:z,pending:pe,onCheck:()=>{Ee()},onConfirmRestart:()=>{Me()},desktopState:be?J:void 0,desktopPending:lt,onCheckDesktop:()=>{Ge()},onInstallDesktop:()=>{dt()}}),ke&&o.jsxs("div",{className:"mt-3 overflow-hidden rounded-xl bg-surface-2",children:[o.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border/10 px-3 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[o.jsx("span",{className:"mt-0.5 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/15 text-primary",children:o.jsx(MR,{size:15})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:e("settings.desktopTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:oe?`App ${oe.appVersion} · CLI ${oe.bundledCliVersion}`:e("settings.desktopStatusLoading")})]})]}),o.jsx("span",{className:"shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary",children:"macOS"})]}),o.jsxs("div",{className:"grid grid-cols-1 gap-px bg-border/10 sm:grid-cols-3",children:[o.jsxs("button",{type:"button",onClick:()=>{ke.showConnectionCenter()},className:"flex items-center gap-2 bg-surface-2 px-3 py-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:[o.jsx(GR,{size:13,className:"shrink-0 text-primary"}),e("settings.desktopSwitchService")]}),o.jsxs("button",{type:"button",onClick:()=>{Fe(null),ke.installCli().then(M=>{he(M),Fe(e("settings.desktopCliUpdated"))}).catch(M=>Fe(M instanceof Error?M.message:String(M)))},className:"flex items-center gap-2 bg-surface-2 px-3 py-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:[o.jsx(La,{size:13,className:"shrink-0 text-primary"}),e("settings.desktopInstallCli")]}),o.jsxs("button",{type:"button",onClick:()=>{Fe(null),ke.revealDataDirectory().catch(M=>Fe(M instanceof Error?M.message:String(M)))},className:"flex items-center gap-2 bg-surface-2 px-3 py-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:[o.jsx(Jd,{size:13,className:"shrink-0 text-primary"}),e("settings.desktopOpenDataDirectory")]})]}),ge&&o.jsx("div",{className:"border-t border-border/10 px-3 py-2 text-[10px] text-muted-foreground",children:ge})]}),o.jsxs("div",{className:"mt-3 flex gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>{Ho(null),bi({mode:"shell"}),ut()},className:`flex min-w-0 items-center justify-center gap-1.5 rounded-xl text-[13px] font-semibold transition active:scale-[0.98] ${$a?"flex-[2.7] bg-primary px-3 py-2.5 text-primary-foreground ring-1 ring-primary/40 shadow-md shadow-primary/25 hover:bg-primary/90":"flex-[0.78] bg-surface-2 px-2 py-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:e(Kr==="shell"?"sidebar.confirmNewShell":"settings.shell"),children:[o.jsx(Ao,{size:14,className:$a?"shrink-0":"hidden"}),o.jsx(La,{size:12}),o.jsx("span",{className:$a?"whitespace-nowrap":"hidden",children:e(Kr==="shell"?"sidebar.confirmNewShell":"settings.shell")})]}),o.jsxs("button",{type:"button",disabled:!Rt.available,onClick:()=>{Rt.available&&(Ho(null),bi({mode:"tmux"}),ut())},className:`flex min-w-0 items-center justify-center gap-1.5 rounded-xl text-[13px] font-semibold transition active:scale-[0.98] ${Rt.available?va?"flex-[2.7] bg-primary px-3 py-2.5 text-primary-foreground ring-1 ring-primary/40 shadow-md shadow-primary/25 hover:bg-primary/90":"flex-[0.78] bg-surface-2 px-2 py-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground":"flex-1 bg-surface-2/50 text-muted-foreground/50 cursor-not-allowed"}`,title:Rt.available?e(Kr==="tmux"?"sidebar.confirmNewTmux":"settings.tmux"):Rt.reason||e("settings.installTmuxHint"),children:[o.jsx(Ao,{size:14,className:va?"shrink-0":"hidden"}),o.jsx(Fu,{size:12}),o.jsx("span",{className:va?"whitespace-nowrap":"hidden",children:e(Kr==="tmux"?"sidebar.confirmNewTmux":"settings.tmux")})]})]}),(Rt.available||at.length>0)&&o.jsxs("details",{className:"mt-3 group rounded-xl bg-surface-2 [&[open]]:bg-surface-2",children:[o.jsxs("summary",{className:"flex cursor-pointer items-center justify-between rounded-xl px-3 py-2.5 text-[13px] hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx("span",{className:`inline-flex h-2 w-2 rounded-full ${Rt.available?"bg-primary":"bg-destructive"}`}),o.jsx("span",{className:"font-medium",children:e("settings.tmuxServer")}),o.jsx("span",{className:"text-[11px] text-muted-foreground",children:Rt.available?e("settings.sessions",{n:at.length}):e("settings.tmuxUnavailable")})]}),o.jsx("button",{type:"button",onClick:M=>{M.preventDefault(),Rs()},disabled:Ot,className:"inline-flex h-7 w-7 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50","aria-label":e("settings.refresh"),children:o.jsx(Us,{size:12,className:Ot?"animate-spin":""})})]}),o.jsx("div",{className:"px-2 pb-2",children:Rt.available?at.length===0?o.jsx("p",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:e("settings.noTmuxSessions")}):o.jsxs("div",{className:"space-y-2",children:[pl.map(M=>o.jsxs("div",{className:"space-y-1",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2 px-1.5 py-1 text-[10px] text-muted-foreground",children:[o.jsx(nu,{size:11,className:"shrink-0 text-muted-foreground/70"}),o.jsx("span",{className:"shrink-0 font-medium text-foreground/75",children:M.label}),o.jsx("span",{className:"shrink-0 text-muted-foreground/70",children:e("settings.sessions",{n:M.sessions.length})}),M.key&&o.jsx("span",{className:"min-w-0 truncate text-muted-foreground/60",children:M.key})]}),M.sessions.map(G=>{const Re=G.boundFrontendSessionId??null,rt=!!(G.connected||Re),Pt=Re?Ft.find(Sr=>Sr.id===Re)??null:null,Wt=G.friendlyName?.trim()||null,Pn=G.label&&G.label!==G.name?G.label:null,Fr=Wt||Pn||G.name,Yr=Wt||Pn?`tmux:${G.name}`:null,Xr=G.clientCount&&G.clientCount>0?t==="zh"?`网页连接 ${G.clientCount}`:`Web clients ${G.clientCount}`:null,Go=G.attached>0?t==="zh"?`原生 tmux ${G.attached}`:`Native tmux ${G.attached}`:null,Zr=[Yr,rt?G.restorable?e("settings.restorable"):e("settings.attached"):null,Xr,Go].filter(Sr=>!!Sr),vi=[e("settings.windows",{n:G.windows}),G.createdAt?new Date(G.createdAt).toLocaleDateString():null].filter(Sr=>!!Sr),Ki=ar===G.name,Xi=ct===G.name,Ri=_n===G.name;return o.jsxs("div",{className:`flex items-start gap-2 rounded-lg px-2.5 py-2 ${Ki?"bg-destructive/10 ring-1 ring-destructive/40":"bg-surface"}`,children:[o.jsx(Fu,{size:13,className:rt?"mt-0.5 shrink-0 text-primary":"mt-0.5 shrink-0 text-muted-foreground"}),o.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[o.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:Fr}),G.friendlyName&&o.jsx("span",{className:"shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[9px] font-medium text-primary",children:t==="zh"?"自定义":"custom"})]}),Zr.length>0&&o.jsx("div",{className:"flex min-w-0 flex-wrap gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground",children:Zr.map(Sr=>o.jsx("span",{className:"max-w-full truncate",children:Sr},Sr))}),(G.program||G.cwd)&&o.jsxs("div",{className:"grid min-w-0 gap-0.5 text-[10px] text-muted-foreground",children:[G.program&&o.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[o.jsx(ON,{size:10,className:"shrink-0 text-muted-foreground/70"}),o.jsx("span",{className:"truncate text-foreground/75",children:G.program})]}),G.cwd&&o.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[o.jsx(nu,{size:10,className:"shrink-0 text-muted-foreground/70"}),o.jsx("span",{className:"truncate",children:G.cwd})]})]}),o.jsx("div",{className:"flex min-w-0 flex-wrap gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground/80",children:vi.map(Sr=>o.jsxs("span",{className:"inline-flex items-center gap-1",children:[o.jsx(dN,{size:10,className:"shrink-0 text-muted-foreground/60"}),Sr]},Sr))})]}),Ki?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",disabled:Xi,onClick:()=>{Ml(G.name)},className:"shrink-0 rounded-full bg-destructive/90 px-2.5 py-1 text-[11px] font-medium text-destructive-foreground transition hover:bg-destructive disabled:opacity-50",children:Xi?"…":e("settings.destroy")}),o.jsx("button",{type:"button",disabled:Xi,onClick:()=>{qe(null),An(null)},className:"shrink-0 rounded-full bg-surface-2 px-2.5 py-1 text-[11px] font-medium text-foreground transition hover:bg-surface-elevated",children:e("common.cancel")})]}):o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:()=>{Pt?hl(Pt.id):(ln(G.name),bi({mode:"tmux",tmuxSessionName:G.name}))},disabled:Ri,className:`shrink-0 inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-[11px] font-medium transition disabled:opacity-50 ${rt?"bg-surface text-foreground hover:bg-surface-elevated":Ri?"bg-primary/10 text-primary":"bg-primary/15 text-primary hover:bg-primary/25"}`,children:Ri?o.jsxs(o.Fragment,{children:[o.jsx(Fn,{size:10,className:"animate-spin"}),e("settings.attaching")]}):e(rt?"settings.attached":"settings.attach")}),o.jsx("button",{type:"button",disabled:Xi,onClick:()=>{An(null),qe(G.name)},className:"shrink-0 inline-flex h-7 w-7 items-center justify-center rounded-full text-muted-foreground transition hover:bg-destructive/15 hover:text-destructive","aria-label":`Kill tmux session ${G.name}`,children:o.jsx($i,{size:12})})]})]},G.name)})]},M.key||"__ungrouped_tmux__")),dn&&o.jsx("p",{className:"px-2 text-[11px] text-destructive",children:dn})]}):o.jsx("p",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:Rt.reason||e("settings.installTmuxHint")})})]}),o.jsxs("button",{type:"button",onClick:()=>$s(!0),className:"mt-2 flex w-full items-center justify-between gap-2 rounded-xl bg-surface-2 px-3 py-2.5 text-left text-[13px] transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(GN,{size:14,className:"text-muted-foreground"}),o.jsx("span",{className:"font-medium text-foreground",children:e("settings.keyboardToolbar")})]}),o.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[o.jsx("span",{children:e("settings.sessions",{n:Je.length})}),o.jsx("span",{children:"›"})]})]}),o.jsxs("button",{type:"button",onClick:()=>Ir(!0),className:"mt-2 flex w-full items-center justify-between gap-2 rounded-xl bg-surface-2 px-3 py-2.5 text-left text-[13px] transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(bg,{size:14,className:"text-muted-foreground"}),o.jsx("span",{className:"font-medium text-foreground",children:e("settings.aiAgentDetection")})]}),o.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[o.jsx("span",{children:"hooks"}),o.jsx("span",{children:"›"})]})]}),o.jsxs("div",{className:"mt-3 flex items-center gap-2 rounded-xl bg-surface-2 px-2.5 py-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.language")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:[{code:"en",label:"English"},{code:"zh",label:"中文"}].map(M=>{const G=t===M.code;return o.jsx("button",{type:"button",onClick:()=>n(M.code),className:`flex-1 rounded px-2 py-1 text-[11px] font-medium transition ${G?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-surface-elevated"}`,children:M.label},M.code)})})]}),o.jsxs("button",{type:"button",onClick:async()=>{try{await $E()}catch{}window.dispatchEvent(new CustomEvent("auth:unauthorized"))},className:"mt-3 flex w-full items-center justify-center gap-2 rounded-xl bg-destructive/10 px-3 py-2.5 text-[13px] font-medium text-destructive transition hover:bg-destructive/20 active:scale-[0.98]",children:[o.jsx(ZM,{size:14}),e("settings.signOut")]})]})]})})]}),ba&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-menu-backdrop bg-[var(--app-backdrop-soft)] backdrop-blur-sm cursor-default animate-fade-in",onClick:()=>{en(null),ir(null),An(null)},"aria-label":e("common.close")}),o.jsxs("div",{className:`fixed z-menu-panel rounded-2xl bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in ${Vt&&zn?"":"inset-x-3 bottom-6 mx-auto max-w-sm sm:bottom-auto sm:top-[15%]"}`,style:Vt&&zn?{...u7(Vt),paddingBottom:s}:{paddingBottom:s},children:[o.jsxs("div",{className:"border-b border-border/15 px-4 py-3",children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.closeChooserTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[14px] font-medium text-foreground",children:ya}),o.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground/80",children:e("tab.closeChooserDescription")})]}),o.jsxs("div",{className:"flex flex-col py-1",children:[o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:ba.id,source:"sidebar",closeMode:"detach"}),en(null),ir(null),An(null)},className:"flex items-center gap-3 px-4 py-3 text-left text-[13px] text-foreground transition hover:bg-surface-2",children:[o.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground",children:o.jsx(La,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.detach")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.detachHint")})]})]}),o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:ba.id,source:"sidebar",closeMode:"destroy"}),en(null),ir(null)},className:"flex items-center gap-3 px-4 py-3 text-left text-[13px] text-destructive transition hover:bg-destructive/10",children:[o.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-destructive/15 text-destructive",children:o.jsx($i,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.destroySession")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.destroySessionHint")})]})]}),dn&&o.jsx("p",{className:"px-4 py-2 text-[11px] text-destructive",children:dn})]}),o.jsx("div",{className:"border-t border-border/15 px-3 py-2",children:o.jsx("button",{type:"button",onClick:()=>{en(null),ir(null),An(null)},className:"w-full rounded-full bg-surface-2 px-3 py-2 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")})})]})]}),cn&&(()=>{const M=Ft.find(Xr=>Xr.id===cn);if(!M)return null;const G=Se.get(M.id),{primary:Re}=gc(M,G?.activeProgram??null,G?.cwd??null,rl),rt=zn,Pt=rt?u7(ps):{paddingBottom:s},Wt=rt?"fixed z-menu-panel overflow-y-auto overflow-x-hidden rounded-lg bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in":"fixed inset-x-3 bottom-6 z-menu-panel mx-auto max-w-sm rounded-2xl bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in sm:bottom-auto sm:top-[15%]",Pn=rt?"border-b border-border/15 px-3 py-2":"border-b border-border/15 px-4 py-3",Fr=rt?"flex items-center gap-2 px-3 py-2 text-left text-[12px] transition":"flex items-center gap-3 px-4 py-3 text-left text-[13px] transition",Yr=rt?"inline-flex h-6 w-6 items-center justify-center rounded-md":"inline-flex h-7 w-7 items-center justify-center rounded-full";return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:`fixed inset-0 z-menu-backdrop cursor-default animate-fade-in ${rt?"bg-transparent":"bg-[var(--app-backdrop-soft)] backdrop-blur-sm"}`,onClick:Ln,"aria-label":"Close menu"}),o.jsxs("div",{className:Wt,style:Pt,children:[o.jsxs("div",{className:Pn,children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.session")}),o.jsx("div",{className:"mt-0.5 truncate text-[14px] font-medium text-foreground",children:Re}),G?.cwd&&o.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground/80",children:G.cwd})]}),o.jsxs("div",{className:"flex flex-col py-1",children:[o.jsxs("button",{type:"button",onClick:()=>{const Xr=ps;Ln(),_e(Xr),tn(M.id)},className:`${Fr} text-foreground hover:bg-surface-2`,children:[o.jsx("span",{className:`${Yr} bg-primary/15 text-primary`,children:o.jsx(S8,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.rename")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.renameHint")})]})]}),o.jsxs("button",{type:"button",disabled:!G?.cwd,onClick:()=>{zo(M.id),Ln()},className:`${Fr} ${G?.cwd?"text-foreground hover:bg-surface-2":"text-muted-foreground/50 cursor-not-allowed"}`,children:[o.jsx("span",{className:`${Yr} bg-surface-2 text-muted-foreground`,children:o.jsx(VN,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.copyCwd")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.copyCwdHint")})]}),je&&je===G?.cwd&&o.jsx("span",{className:"ml-auto text-[11px] text-primary",children:e("tab.copied")})]}),G?.agentNativeSessionId&&G.agentStatus!=="working"&&G.agentStatus!=="waiting"&&G.terminalSessionId&&o.jsxs("button",{type:"button",onClick:()=>{const Xr=G.terminalSessionId;Xr&&(Ln(),It(M.id,Xr))},className:`${Fr} text-foreground hover:bg-surface-2`,children:[o.jsx("span",{className:`${Yr} bg-[rgb(var(--success-rgb)_/_0.14)] text-[color:var(--success)]`,children:o.jsx(wf,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"block font-medium",children:[e("tab.resumeAgent"),G.agent?.displayName?` · ${G.agent.displayName}`:""]}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.resumeAgentHint")})]})]}),o.jsx("div",{className:"my-1 border-t border-border/15"}),M.mode==="tmux"?o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:M.id,source:"tab-menu",closeMode:"detach"}),Ln(),An(null)},className:`${Fr} text-foreground hover:bg-surface-2`,children:[o.jsx("span",{className:`${Yr} bg-surface-2 text-muted-foreground`,children:o.jsx(La,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.detach")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.detachHint")})]})]}),o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:M.id,source:"tab-menu",closeMode:"destroy"}),Ln()},className:`${Fr} text-destructive hover:bg-destructive/10`,children:[o.jsx("span",{className:`${Yr} bg-destructive/15 text-destructive`,children:o.jsx($i,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.destroySession")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.destroySessionHint")})]})]})]}):o.jsxs("button",{type:"button",onClick:()=>{Ln(),xa({sessionId:M.id,source:"tab-menu",closeMode:"auto"})},className:`${Fr} text-destructive hover:bg-destructive/10`,children:[o.jsx("span",{className:`${Yr} bg-destructive/15 text-destructive`,children:o.jsx(ts,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.close")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.closeHint")})]})]}),!rt&&o.jsx("button",{type:"button",className:"flex items-center justify-center px-4 py-2 text-[11px] text-muted-foreground/80 transition hover:text-foreground",onClick:()=>{Ln()},children:e("tab.longPressTip")})]}),!rt&&o.jsx("div",{className:"border-t border-border/15 px-3 py-2",children:o.jsx("button",{type:"button",onClick:Ln,className:"w-full rounded-full bg-surface-2 px-3 py-2 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")})})]})]})})(),pn&&se&&zn&&(()=>{const M=Ft.find(Zr=>Zr.id===pn);if(!M)return null;const G=Se.get(M.id),{primary:Re}=gc(M,G?.activeProgram??null,G?.cwd??null,rl,G?.shellTitle??null,G?.promptState??null),rt=M.customName?M.name:Re,Pt=Zr=>{const vi=Zr.trim();vi?vi!==rt&&Gs(M.id,vi):qr(M.id),tn(null),_e(null)},Wt=300,Pn=160,Fr=se.x,Yr=se.y,Xr=Math.min(Math.max(Fr-Wt/2,12),window.innerWidth-Wt-12),Go=Yr+Pn+20>window.innerHeight?Math.max(Yr-Pn-12,12):Yr+12;return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-menu-backdrop cursor-default animate-fade-in bg-transparent",onClick:()=>{tn(null),_e(null)},"aria-label":e("common.cancel")}),o.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":e("tab.rename"),className:"fixed z-menu-panel w-[300px] rounded-xl bg-surface-elevated border border-border/15 shadow-[0_12px_36px_var(--app-shadow-soft)] animate-fade-in",style:{left:`${Xr}px`,top:`${Go}px`},children:[o.jsxs("div",{className:"border-b border-border/15 px-3 py-2.5",children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.rename")}),o.jsx("div",{className:"mt-0.5 truncate text-[13px] font-medium text-foreground",children:Re}),G?.cwd&&o.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground/70",children:G.cwd})]}),o.jsxs("form",{className:"px-3 py-2.5",onSubmit:Zr=>{Zr.preventDefault();const vi=new FormData(Zr.currentTarget).get("session-name");Pt(typeof vi=="string"?vi:"")},children:[o.jsx("input",{ref:Zr=>{Xn.current=Zr,Zr&&!Gr.current&&(Gr.current=!0,Zr.focus({preventScroll:!0}),Zr.select())},type:"text",name:"session-name",defaultValue:rt,placeholder:e("tab.renamePlaceholder"),autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:"w-full rounded-lg bg-surface-2 px-3 py-2 text-[13px] leading-snug text-foreground outline-none ring-1 ring-primary/40 placeholder:text-muted-foreground/60 focus:ring-primary/70",onKeyDown:Zr=>{Zr.key==="Escape"&&(Zr.stopPropagation(),tn(null),_e(null))}}),o.jsxs("div",{className:"mt-2.5 flex gap-2",children:[o.jsx("button",{type:"button",onClick:()=>{tn(null),_e(null)},className:"flex-1 rounded-full bg-surface-2 px-3 py-1.5 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")}),o.jsx("button",{type:"submit",className:"flex-1 rounded-full bg-primary px-3 py-1.5 text-[12px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.97]",children:e("common.save")})]})]})]})]})})(),pn&&!zn&&(()=>{const M=Ft.find(Wt=>Wt.id===pn);if(!M)return null;const G=Se.get(M.id),{primary:Re}=gc(M,G?.activeProgram??null,G?.cwd??null,rl,G?.shellTitle??null,G?.promptState??null),rt=M.customName?M.name:Re,Pt=Wt=>{const Pn=Wt.trim();Pn?Pn!==rt&&Gs(M.id,Pn):qr(M.id),tn(null)};return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-menu-backdrop cursor-default animate-fade-in bg-[var(--app-backdrop-soft)] backdrop-blur-sm",onClick:()=>tn(null),"aria-label":e("common.cancel")}),o.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":e("tab.rename"),className:"fixed inset-x-3 z-menu-panel mx-auto max-w-sm rounded-2xl bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",style:{top:`calc(${r} + 3.5rem)`},children:[o.jsxs("div",{className:"border-b border-border/15 px-4 py-3",children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.session")}),o.jsx("div",{className:"mt-0.5 text-[14px] font-medium text-foreground",children:e("tab.rename")})]}),o.jsxs("form",{className:"px-4 py-3",onSubmit:Wt=>{Wt.preventDefault();const Pn=new FormData(Wt.currentTarget).get("session-name");Pt(typeof Pn=="string"?Pn:"")},children:[o.jsx("input",{ref:Wt=>{Xn.current=Wt,Wt&&!Gr.current&&(Gr.current=!0,Wt.focus({preventScroll:!0}),Wt.select())},type:"text",name:"session-name",defaultValue:rt,placeholder:e("tab.renamePlaceholder"),autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,enterKeyHint:"done",className:"w-full rounded-lg bg-surface-2 px-3 py-2.5 text-[16px] leading-snug text-foreground outline-none ring-1 ring-primary/40 placeholder:text-muted-foreground/60 focus:ring-primary/70",onKeyDown:Wt=>{Wt.key==="Escape"&&(Wt.stopPropagation(),tn(null))}}),o.jsxs("div",{className:"mt-3 flex gap-2",children:[o.jsx("button",{type:"button",onClick:()=>tn(null),className:"flex-1 rounded-full bg-surface-2 px-3 py-2 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")}),o.jsx("button",{type:"submit",className:"flex-1 rounded-full bg-primary/20 px-3 py-2 text-[12px] font-medium text-primary transition hover:bg-primary/30",children:e("common.save")})]})]})]})]})})(),xi&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:()=>B(!1)}),o.jsxs("div",{className:"fixed left-[max(0.75rem,env(safe-area-inset-left,0px))] right-[max(0.75rem,env(safe-area-inset-right,0px))] top-[max(1.5rem,env(safe-area-inset-top,0px))] bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto flex max-w-xl flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)] sm:top-[10%] sm:bottom-auto sm:max-h-[80vh]",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-4 py-4 sm:px-6",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.notifications")}),o.jsx("h2",{className:"section-title mt-1",children:e("settings.notificationsTitle")})]}),o.jsx("button",{type:"button",onClick:()=>B(!1),className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":"Close notifications settings",children:o.jsx(ts,{size:18})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-6",children:[o.jsx("p",{className:"text-[12px] leading-relaxed text-muted-foreground",children:e("settings.notificationsPageHint")}),o.jsxs("div",{className:"mt-4 rounded-2xl bg-surface-2 p-3",children:[o.jsxs("div",{className:"flex items-start justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsMaster")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:C==="denied"?e("settings.notificationsDenied"):Du()?e("settings.notificationsMasterHint"):e("settings.notificationsUnsupported")}),Du()&&!u8()&&o.jsx("div",{className:"mt-1.5 text-[11px] leading-relaxed text-[var(--warning)]",children:e("settings.notificationsIOSInstallHint")})]}),o.jsx("button",{type:"button",onClick:()=>{Ec()},disabled:!Du()||C==="denied",className:"shrink-0 transition disabled:cursor-not-allowed","aria-pressed":A,children:o.jsx(xc,{checked:A,disabled:!Du()||C==="denied"})})]}),o.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[11px]",children:[o.jsxs("span",{className:`rounded-full px-2 py-0.5 ${C==="granted"?"bg-primary/15 text-primary":"bg-surface text-muted-foreground"}`,children:[e("settings.notificationsPermission"),": ",lo()?e("settings.notificationsPermissionSystem"):C]}),o.jsx("button",{type:"button",disabled:!A||C!=="granted"||K==="checking",onClick:()=>{Ic()},className:"rounded-full bg-surface px-3 py-1.5 font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",children:e(K==="checking"?"settings.notificationsTestChecking":"settings.notificationsTest")}),lo()?.openNotificationSettings&&o.jsx("button",{type:"button",onClick:()=>{lo()?.openNotificationSettings?.()},className:"rounded-full bg-surface px-3 py-1.5 font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:e("settings.notificationsOpenSystemSettings")})]}),K!=="idle"&&K!=="checking"&&o.jsx("div",{className:`mt-2 text-[11px] leading-relaxed ${K==="delivered"?"text-primary":"text-[var(--warning)]"}`,children:e(K==="delivered"?"settings.notificationsTestDelivered":"settings.notificationsTestFailed")})]}),o.jsxs("div",{className:"mt-4 rounded-2xl bg-surface-2 p-3",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsAlertStyle")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:e("settings.notificationsAlertStyleHint")}),o.jsx("div",{className:"mt-3 grid grid-cols-3 gap-1 rounded-xl bg-surface p-1",children:[["normal",e("settings.notificationsStyleNormal"),e("settings.notificationsStyleNormalHint")],["quiet",e("settings.notificationsStyleQuiet"),e("settings.notificationsStyleQuietHint")],["persistent",e("settings.notificationsStylePersistent"),e("settings.notificationsStylePersistentHint")]].map(([M,G,Re])=>{const rt=F===M;return o.jsxs("button",{type:"button",disabled:!A,onClick:()=>nc(M),className:`min-w-0 rounded-lg px-2 py-2 text-left transition ${rt&&A?"bg-primary/15 text-primary":A?"text-muted-foreground hover:bg-surface-elevated hover:text-foreground":"cursor-not-allowed text-muted-foreground/40"}`,title:Re,children:[o.jsx("span",{className:"block truncate text-[11px] font-semibold",children:G}),o.jsx("span",{className:"mt-0.5 block truncate text-[9px] opacity-80",children:Re})]},M)})})]}),o.jsxs("div",{className:"mt-4",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.notificationsEvents")}),o.jsxs("div",{className:"mt-2 rounded-2xl bg-surface-2 p-3",children:[o.jsxs("div",{className:"flex items-start justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsAiFinished")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:e("settings.notificationsAiFinishedHint")})]}),o.jsx("button",{type:"button",disabled:!A,onClick:()=>Rc(!L),className:"shrink-0 transition disabled:cursor-not-allowed","aria-pressed":L&&A,children:o.jsx(xc,{checked:L&&A,disabled:!A})})]}),o.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3 border-t border-border/10 pt-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsSessionExited")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:e("settings.notificationsSessionExitedHint")})]}),o.jsx("button",{type:"button",disabled:!A,onClick:()=>Ba(!j),className:"shrink-0 transition disabled:cursor-not-allowed","aria-pressed":j&&A,children:o.jsx(xc,{checked:j&&A,disabled:!A})})]})]}),o.jsx("p",{className:"mt-2 text-[10px] text-muted-foreground",children:e("settings.notificationsFutureHint")})]})]})]})]}),_o&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:()=>$s(!1)}),o.jsxs("div",{className:"fixed left-[max(0.75rem,env(safe-area-inset-left,0px))] right-[max(0.75rem,env(safe-area-inset-right,0px))] top-[max(1.5rem,env(safe-area-inset-top,0px))] bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto flex max-w-4xl flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)]",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-4 py-4 sm:px-6",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.mobileKeyboard")}),o.jsx("h2",{className:"section-title mt-1",children:e("settings.toolbarPresets")})]}),o.jsx("button",{type:"button",onClick:()=>$s(!1),className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":"Close toolbar presets",children:o.jsx(ts,{size:18})})]}),o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-6",children:o.jsx(Cte,{presets:Je,selectedPresetId:et,onSelectPreset:Zt,onUpdatePreset:(M,G)=>{Ke(Re=>qd(Re.map(rt=>rt.id===M?G(rt):rt)))},onAddPreset:()=>{const M=`preset-${Date.now()}`;Ke(G=>qd([...G,{id:M,label:`Preset ${G.length}`,programs:[],includeAlt:!1,rowLayout:[3,3],actions:[],showOnDesktop:!1}])),Zt(M)},onRemovePreset:M=>{Ke(G=>qd(G.filter(Re=>Re.id!==M)))},onResetDefaults:()=>{Ke(Vf()),Zt("default")}})})]})]}),Lr&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:()=>Ir(!1)}),o.jsxs("div",{className:"fixed left-[max(0.75rem,env(safe-area-inset-left,0px))] right-[max(0.75rem,env(safe-area-inset-right,0px))] top-[max(1.5rem,env(safe-area-inset-top,0px))] bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto flex max-w-4xl flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)]",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-4 py-4 sm:px-6",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.aiAgentDetection")}),o.jsx("h2",{className:"section-title mt-1",children:e("settings.detectionRules")})]}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx("button",{type:"button",onClick:()=>Ir(!1),className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":"Close agent rules",children:o.jsx(ts,{size:18})})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-6",children:[o.jsx("p",{className:"mb-4 text-[11px] text-muted-foreground",children:e("settings.agentHooksHint")}),o.jsx(_te,{}),o.jsxs("div",{className:"mt-6 border-t border-border/15 pt-4",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.programLabelResolution")}),o.jsx("h3",{className:"mt-1 text-sm font-semibold text-foreground",children:e("settings.rawCommandMapping")}),o.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:e("settings.rawCommandMappingHint")}),o.jsx("div",{className:"mt-3 space-y-2 rounded-xl bg-surface-2 p-3",children:Ft.map(M=>{const G=Se.get(M.id),Re=G?.activeProgramRaw??null,rt=G?.activeProgram??null;return o.jsxs("div",{className:"rounded-lg bg-surface/60 px-2.5 py-2",children:[o.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:M.name}),o.jsxs("div",{className:"mt-0.5 text-[11px] text-foreground",children:[o.jsx("span",{className:"text-muted-foreground",children:"display:"})," ",rt||"—"]}),o.jsxs("div",{className:"mt-0.5 break-all font-mono text-[10px] text-muted-foreground",children:[o.jsx("span",{className:"text-muted-foreground/80",children:"raw:"})," ",Re||"—"]})]},`raw-${M.id}`)})}),o.jsxs("div",{className:"mt-3 space-y-3",children:[[{key:"genericProgramNames",label:e("settings.genericProgramNames"),hint:e("settings.genericProgramNamesHint")},{key:"wrapperScriptNames",label:e("settings.wrapperScriptNames"),hint:e("settings.wrapperScriptNamesHint")},{key:"shellNames",label:e("settings.shellNamesConfig"),hint:e("settings.shellNamesHint")}].map(({key:M,label:G,hint:Re})=>o.jsxs("div",{children:[o.jsx("div",{className:"mb-0.5 text-[11px] font-medium text-foreground",children:G}),o.jsx("div",{className:"text-[10px] text-muted-foreground",children:Re}),o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[ni[M].map(rt=>o.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-surface-2 px-2 py-0.5 text-[11px] font-mono text-foreground",children:[rt,o.jsx("button",{type:"button",onClick:()=>{const Pt={...ni,[M]:ni[M].filter(Wt=>Wt!==rt)};fa(Pt),M==="shellNames"&&(rl=new Set(Pt.shellNames)),o5(Pt).catch(()=>{})},className:"ml-0.5 text-muted-foreground hover:text-destructive",children:"×"})]},rt)),o.jsx("input",{placeholder:e("settings.addTag"),className:"w-16 rounded bg-surface px-1.5 py-0.5 text-[11px] font-mono",onKeyDown:rt=>{if(rt.key!=="Enter")return;const Pt=rt.target.value.trim().toLowerCase();if(!Pt||ni[M].includes(Pt))return;const Wt={...ni,[M]:[...ni[M],Pt]};fa(Wt),M==="shellNames"&&(rl=new Set(Wt.shellNames)),rt.target.value="",o5(Wt).catch(()=>{})}})]})]},M)),o.jsx("button",{type:"button",onClick:()=>{nI().then(M=>{fa(M),rl=new Set(M.shellNames)}).catch(()=>{})},className:"rounded-full bg-surface-2 px-3 py-1 text-[11px] text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:e("settings.resetDefaults")})]}),o.jsxs("div",{className:"mt-3",children:[o.jsx("div",{className:"mb-1 text-[11px] font-medium text-foreground",children:e("settings.customRules")}),Pr.map((M,G)=>o.jsx("div",{className:"mb-2 rounded-lg bg-surface-2 p-2.5",children:o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("input",{type:"checkbox",checked:M.enabled!==!1,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,enabled:Re.target.checked}:Pt);ur(rt),$n(Jo,rt),Br(!0),Sd(rt).then(Pt=>{ur(Pt),$n(Jo,Pt)}).catch(()=>{}).finally(()=>Br(!1))}}),o.jsxs("select",{value:M.matchType,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,matchType:Re.target.value}:Pt);ur(rt),$n(Jo,rt),Br(!0),Sd(rt).then(Pt=>{ur(Pt),$n(Jo,Pt)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded bg-surface px-2 py-1 text-[11px]",children:[o.jsx("option",{value:"includes",children:"includes"}),o.jsx("option",{value:"exact",children:"exact"}),o.jsx("option",{value:"prefix",children:"prefix"}),o.jsx("option",{value:"regex",children:"regex"})]}),o.jsx("input",{value:M.pattern,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,pattern:Re.target.value}:Pt);ur(rt),$n(Jo,rt)},onBlur:()=>{Br(!0),Sd(Pr).then(Re=>{ur(Re),$n(Jo,Re)}).catch(()=>{}).finally(()=>Br(!1))},placeholder:"pattern",className:"min-w-[180px] flex-1 rounded bg-surface px-2 py-1 text-[11px] font-mono"}),o.jsx("input",{value:M.output,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,output:Re.target.value}:Pt);ur(rt),$n(Jo,rt)},onBlur:()=>{Br(!0),Sd(Pr).then(Re=>{ur(Re),$n(Jo,Re)}).catch(()=>{}).finally(()=>Br(!1))},placeholder:"output",className:"w-28 rounded bg-surface px-2 py-1 text-[11px]"}),o.jsx("button",{type:"button",onClick:()=>{const Re=Pr.filter((rt,Pt)=>Pt!==G);ur(Re),$n(Jo,Re),Br(!0),Sd(Re).then(rt=>{ur(rt),$n(Jo,rt)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded bg-surface px-2 py-1 text-[11px] text-muted-foreground hover:text-destructive",children:e("common.delete")})]})},M.id)),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:()=>{const M=[...Pr,{id:`rule-${Date.now()}`,enabled:!0,priority:100,matchType:"includes",pattern:"",output:""}];ur(M),$n(Jo,M),Br(!0),Sd(M).then(G=>{ur(G),$n(Jo,G)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded-full bg-primary/15 px-3 py-1.5 text-[11px] font-medium text-primary hover:bg-primary/25",children:e("settings.addRule")}),o.jsx("button",{type:"button",onClick:()=>{Br(!0),eI().then(M=>{ur(M),$n(Jo,M)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded-full bg-surface-2 px-3 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:e("settings.resetDefaults")}),o.jsx("span",{className:"text-[11px] text-muted-foreground",children:ti?e("settings.saving"):da?`${Pr.length} rules`:"…"})]})]})]})]})]})]}),xs&&o.jsx(yte,{isOpen:xs,onClose:()=>Gn(!1)}),!Ys&&o.jsx(D6,{isOpen:gt,drawerWidthPx:hi,onClose:()=>Wr("left-sidebar"),onOpen:oa,sessions:Ft,activeSessionId:Gt,sessionStates:Se,onNewSession:M=>bi(M),onCloseSession:ic,onSplitSession:au,onCloseSplit:M=>window.dispatchEvent(new CustomEvent("close-terminal-split",{detail:M})),onRemoveFromSplit:M=>window.dispatchEvent(new CustomEvent("remove-terminal-split-pane",{detail:M})),splitWorkspaces:Jn,onSetSplitLayout:Dl,onReorderSplitWorkspace:lu,onRenameSplitWorkspace:sc,onCombineSplitSessions:Mc,onReorderSessions:hr,onSessionMenu:Rl,onOpenSettings:me,onOpenQuota:()=>Gn(!0),updateState:z,updateActionPending:pe,onConfirmUpdateRestart:Me,onRetryUpdate:Ee,tmuxAvailable:Rt.available,defaultSessionMode:Rr,runningSessionButtonEnabled:Lt,onRunningSessionButtonEnabledChange:mn,onTogglePinned:zn?Fs:void 0}),!jc&&o.jsx(r7,{isOpen:Kt,drawerWidthPx:ia,onClose:()=>Wr("right-sidebar"),onOpen:Co,rightSidebarFilePreviewOpen:cr,rightSidebarFilePreviewCloseSignal:W,onOpenRightSidebarFilePreview:ua,onCloseRightSidebarFilePreview:Pa,rightSidebarRepoPickerOpen:He,rightSidebarRepoPickerCloseSignal:Qe,onOpenRightSidebarRepoPicker:fl,onCloseRightSidebarRepoPicker:Qs,markdownOutlineOpen:At,markdownOutlineCloseSignal:Yt,onOpenMarkdownOutline:gi,onCloseMarkdownOutline:Li,markdownImageLightboxOpen:on,markdownImageLightboxCloseSignal:Cn,onOpenMarkdownImageLightbox:Ei,onCloseMarkdownImageLightbox:po,onTogglePinned:zn?la:void 0}),Te&&!i&&o.jsx("button",{type:"button",onClick:nt,className:"fixed inset-0 z-toast flex cursor-default items-center justify-center bg-[var(--app-backdrop-soft)] px-6 text-left backdrop-blur-[1px]","aria-label":t==="zh"?"继续使用 Termdock":"Continue using Termdock",children:o.jsxs("div",{className:"max-w-[18rem] rounded-2xl border border-border/15 bg-surface/95 px-5 py-4 text-center shadow-[0_18px_50px_var(--app-shadow-strong)] backdrop-blur animate-fade-in",children:[o.jsx("div",{className:"text-[14px] font-semibold text-foreground",children:t==="zh"?"建议使用 Home":"Use Home instead"}),o.jsx("div",{className:"mt-1.5 text-[12px] leading-relaxed text-muted-foreground",children:t==="zh"?"按 Home 退后台,点任意位置继续。":"Use Home to leave. Tap anywhere to continue."}),o.jsx("div",{className:"mt-3 text-[11px] font-medium text-muted-foreground/80",children:t==="zh"?"轻点关闭提示":"Tap to dismiss"})]})}),Er&&o.jsxs("div",{className:`fixed inset-x-3 bottom-4 z-toast mx-auto flex max-w-md items-center gap-2 rounded-xl border px-4 py-3 text-[12px] shadow-lg animate-fade-in ${Er.tone==="success"?"border-[rgb(var(--success-rgb)_/_0.24)] bg-surface-elevated text-foreground":"border-destructive/30 bg-surface-elevated text-destructive"}`,role:Er.tone==="error"?"alert":"status",children:[Er.tone==="success"?o.jsx(wf,{size:14,className:"shrink-0 text-[color:var(--success)]"}):o.jsx(Tm,{size:14,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1",children:Er.message}),o.jsx("button",{type:"button",onClick:()=>yr(null),className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-2 hover:text-foreground","aria-label":e("common.close"),children:o.jsx(ts,{size:12})})]}),a&&o.jsxs("div",{className:"fixed bottom-0 left-0 right-0 z-toast max-h-48 overflow-y-auto border-t border-border/15 bg-surface p-3 animate-fade-in",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("h4",{className:"ui-kicker",children:"Debug Info"}),o.jsx("button",{type:"button",onClick:()=>c(!1),className:"text-xs text-muted-foreground hover:text-foreground",children:"Close"})]}),o.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(ot,null,2)})]})]});return Ys||jc?o.jsxs("div",{className:"w-screen h-full flex flex-row",children:[Ys&&o.jsxs(o.Fragment,{children:[o.jsx("div",{style:{width:vt,flexShrink:0,height:"100%"},children:o.jsx(D6,{isOpen:gt,drawerWidthPx:vt,onClose:aa,onOpen:oa,sessions:Ft,activeSessionId:Gt,sessionStates:Se,onNewSession:M=>bi(M),onCloseSession:ic,onSplitSession:au,onCloseSplit:M=>window.dispatchEvent(new CustomEvent("close-terminal-split",{detail:M})),onRemoveFromSplit:M=>window.dispatchEvent(new CustomEvent("remove-terminal-split-pane",{detail:M})),splitWorkspaces:Jn,onSetSplitLayout:Dl,onReorderSplitWorkspace:lu,onRenameSplitWorkspace:sc,onCombineSplitSessions:Mc,onReorderSessions:hr,onSessionMenu:Rl,onOpenSettings:me,onOpenQuota:()=>Gn(!0),updateState:z,updateActionPending:pe,onConfirmUpdateRestart:Me,onRetryUpdate:Ee,tmuxAvailable:Rt.available,defaultSessionMode:Rr,runningSessionButtonEnabled:Lt,onRunningSessionButtonEnabledChange:mn,pinned:!0,onTogglePinned:Fs})}),o.jsx("div",{role:"separator",tabIndex:-1,className:"shrink-0 w-[5px] h-full cursor-col-resize bg-border/10 hover:bg-primary/30 active:bg-primary/50 transition-colors",onMouseDown:_i})]}),o.jsx("div",{className:"flex-1 min-w-0 h-full overflow-hidden",children:ml}),jc&&o.jsxs(o.Fragment,{children:[o.jsx("div",{role:"separator",tabIndex:-1,className:"h-full w-[5px] shrink-0 cursor-col-resize bg-border/10 transition-colors hover:bg-primary/30 active:bg-primary/50",onMouseDown:ko}),o.jsx("div",{style:{width:oc,flexShrink:0,height:"100%"},children:o.jsx(r7,{isOpen:!0,drawerWidthPx:oc,onClose:Os,onOpen:Co,pinned:!0,onTogglePinned:la,rightSidebarFilePreviewOpen:cr,rightSidebarFilePreviewCloseSignal:W,onOpenRightSidebarFilePreview:ua,onCloseRightSidebarFilePreview:Pa,rightSidebarRepoPickerOpen:He,rightSidebarRepoPickerCloseSignal:Qe,onOpenRightSidebarRepoPicker:fl,onCloseRightSidebarRepoPicker:Qs,markdownOutlineOpen:At,markdownOutlineCloseSignal:Yt,onOpenMarkdownOutline:gi,onCloseMarkdownOutline:Li,markdownImageLightboxOpen:on,markdownImageLightboxCloseSignal:Cn,onOpenMarkdownImageLightbox:Ei,onCloseMarkdownImageLightbox:po})})]})]}):ml}const qte=String.raw`
241
+ }`}),L&&o.jsx("div",{className:"whitespace-pre-wrap break-words text-[10px] text-[color:var(--warning)]",children:L}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>{We()},className:"flex items-center gap-1 rounded-full bg-[rgb(var(--success-rgb)_/_0.14)] px-3 py-1 text-[11px] font-medium text-[color:var(--success)] hover:bg-[rgb(var(--success-rgb)_/_0.22)] transition",children:[o.jsx(hN,{size:11}),e("settings.agentPluginCreate")]}),o.jsx("button",{type:"button",onClick:()=>{p(!1),T(""),I(null)},className:"rounded-full px-3 py-1 text-[11px] text-muted-foreground hover:text-foreground transition",children:e("common.cancel")})]})]})]})]})}function Rte({state:e,pending:t,onCheck:n,onConfirmRestart:r,desktopState:s,desktopPending:i=!1,onCheckDesktop:a,onInstallDesktop:c}){const{t:u}=Yn(),f=e?.status??"idle",p=t||f==="checking"||f==="installing"||f==="restarting",g=f==="ready"&&!!e?.latestVersion,y=f==="checking"?u("settings.updateChecking"):f==="installing"?u("sidebar.updateInstalling"):f==="ready"?u("sidebar.updateReady"):f==="restarting"?u("sidebar.updateRestarting"):f==="current"?u("settings.updateCurrent"):f==="error"?e?.error||u("sidebar.updateFailed"):u("settings.updateHint"),v=s?.status??"idle",S=i||v==="checking"||v==="downloading"||v==="installing",A=v==="ready",T=v==="unsupported"?u("settings.desktopUpdateUnsupported"):v==="checking"?u("settings.desktopUpdateChecking"):v==="current"?u("settings.desktopUpdateCurrent"):v==="downloading"?u("settings.desktopUpdateDownloading"):v==="ready"?u("settings.desktopUpdateReady"):v==="installing"?u("settings.desktopUpdateInstalling"):v==="error"&&s?.error||u("settings.desktopUpdateHint");return o.jsxs("section",{className:"mt-3 overflow-hidden rounded-xl bg-surface-2","aria-labelledby":"termdock-update-title",children:[o.jsx("div",{id:"termdock-update-title",className:"px-3 pt-3 text-[12px] font-semibold text-foreground",children:u("settings.updateTitle")}),o.jsxs("div",{className:"flex items-start justify-between gap-3 px-3 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[o.jsx("span",{className:`mt-0.5 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${g?"bg-[rgb(var(--warning-rgb)_/_0.16)] text-[color:var(--warning)]":"bg-primary/15 text-primary"}`,children:o.jsx(Us,{size:15,className:p?"animate-spin":""})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:u("settings.updateRuntimeTitle")}),o.jsx("div",{className:"mt-0.5 text-[10px] leading-relaxed text-muted-foreground",children:y}),e&&o.jsx("div",{className:"mt-1 text-[10px] tabular-nums text-muted-foreground/75",children:g&&e.latestVersion?`${e.currentVersion} → ${e.latestVersion}`:`v${e.currentVersion}`})]})]}),g?o.jsx("button",{type:"button",disabled:p,onClick:r,className:"shrink-0 rounded-full bg-[var(--warning)] px-3 py-1.5 text-[11px] font-semibold text-[color:var(--bg)] transition hover:opacity-90 disabled:cursor-wait disabled:opacity-60",children:u("sidebar.updateRestart")}):o.jsx("button",{type:"button",disabled:p,onClick:n,className:"shrink-0 rounded-full bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground transition hover:bg-surface-elevated disabled:cursor-wait disabled:opacity-60",children:u(f==="checking"?"settings.updateCheckingShort":f==="installing"?"settings.updateInstallingShort":f==="error"?"sidebar.updateRetry":f==="current"?"settings.updateCheckAgain":"settings.updateCheck")})]}),s&&o.jsxs("div",{className:"flex items-start justify-between gap-3 border-t border-border/10 px-3 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[o.jsx("span",{className:`mt-0.5 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${A?"bg-[rgb(var(--warning-rgb)_/_0.16)] text-[color:var(--warning)]":"bg-primary/15 text-primary"}`,children:o.jsx(Us,{size:15,className:S?"animate-spin":""})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:u("settings.desktopUpdateTitle")}),o.jsx("div",{className:"mt-0.5 text-[10px] leading-relaxed text-muted-foreground",children:T}),o.jsx("div",{className:"mt-1 text-[10px] tabular-nums text-muted-foreground/75",children:A&&s.latestVersion?`${s.currentVersion} → ${s.latestVersion}`:`v${s.currentVersion}`})]})]}),A?o.jsx("button",{type:"button",disabled:S||!c,onClick:c,className:"shrink-0 rounded-full bg-[var(--warning)] px-3 py-1.5 text-[11px] font-semibold text-[color:var(--bg)] transition hover:opacity-90 disabled:cursor-wait disabled:opacity-60",children:u("settings.desktopUpdateRestart")}):o.jsx("button",{type:"button",disabled:S||v==="unsupported"||!a,onClick:a,className:"shrink-0 rounded-full bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground transition hover:bg-surface-elevated disabled:cursor-wait disabled:opacity-60",children:u(v==="checking"?"settings.updateCheckingShort":v==="current"||v==="error"?"settings.desktopUpdateCheckAgain":"settings.desktopUpdateCheck")})]})]})}function Nte({bridge:e,runningCount:t,reviewCount:n,labels:r}){const[s,i]=D.useState([]),[a,c]=D.useState(!1),u=D.useRef(null);if(D.useEffect(()=>e.onServiceActivity(i),[e]),D.useEffect(()=>{e.reportServiceActivity({runningCount:t,reviewCount:n})},[e,n,t]),D.useEffect(()=>{if(!a)return;const A=L=>{u.current?.contains(L.target)||c(!1)},T=L=>{L.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",A),document.addEventListener("keydown",T),()=>{document.removeEventListener("pointerdown",A),document.removeEventListener("keydown",T)}},[a]),s.length<2)return null;const f=[...s].sort((A,T)=>A.current!==T.current?A.current?-1:1:A.reviewCount!==T.reviewCount?T.reviewCount-A.reviewCount:A.runningCount!==T.runningCount?T.runningCount-A.runningCount:A.label.localeCompare(T.label)),p=f.find(A=>A.current),g=f.filter(A=>!A.current),y=g.reduce((A,T)=>A+T.runningCount,0),v=g.reduce((A,T)=>A+T.reviewCount,0),S=async A=>{await e.focusService(A)&&c(!1)};return o.jsxs("div",{ref:u,className:"relative z-20 shrink-0","data-testid":"desktop-service-switcher",children:[o.jsxs("button",{type:"button",className:`inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-[11px] ring-1 transition sm:h-8 ${v>0?"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)] ring-[rgb(var(--warning-rgb)_/_0.22)] hover:bg-[rgb(var(--warning-rgb)_/_0.18)]":"bg-surface-2 text-muted-foreground ring-border/10 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"menu","aria-expanded":a,"aria-label":r.switchService,title:p?`${r.switchService} · ${p.label}`:r.switchService,onClick:()=>c(A=>!A),children:[o.jsx(C5,{size:13,className:"shrink-0"}),y>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[color:var(--success)]",title:`${r.running}: ${y}`,children:[o.jsx(Fn,{size:10,className:"animate-spin"}),o.jsx("span",{className:"tabular-nums",children:y})]}),v>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5",title:`${r.review}: ${v}`,children:[o.jsx(eu,{size:10,className:"animate-pulse"}),o.jsx("span",{className:"tabular-nums",children:v})]}),y===0&&v===0&&o.jsx("span",{className:"tabular-nums text-muted-foreground",children:s.length})]}),a&&o.jsxs("div",{role:"menu","aria-label":r.openServices,className:"absolute right-0 top-[calc(100%+0.4rem)] z-30 w-72 overflow-hidden rounded-xl border border-border/15 bg-surface-elevated p-1.5 text-foreground shadow-[0_18px_50px_var(--app-shadow-strong)]",children:[o.jsx("div",{className:"px-2.5 pb-1.5 pt-1 text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:r.openServices}),f.map(A=>{const T=A.runningCount===0&&A.reviewCount===0;return o.jsxs("button",{type:"button",role:"menuitem",className:"flex min-h-11 w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition hover:bg-surface-2 focus-visible:bg-surface-2 focus-visible:outline-none",onClick:()=>{S(A.origin)},children:[o.jsx("span",{className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-muted-foreground",children:A.current?o.jsx(na,{size:13,className:"text-primary"}):o.jsx(C5,{size:13})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"truncate text-[12px] font-medium",children:A.label}),A.current&&o.jsx("span",{className:"shrink-0 text-[9px] text-primary",children:r.current})]}),o.jsx("span",{className:"mt-0.5 block truncate text-[9px] text-muted-foreground",children:A.origin})]}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[10px] tabular-nums",children:[A.runningCount>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[color:var(--success)]",title:r.running,children:[o.jsx(Fn,{size:10,className:"animate-spin"}),A.runningCount]}),A.reviewCount>0&&o.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[color:var(--warning)]",title:r.review,children:[o.jsx(eu,{size:10}),A.reviewCount]}),T&&o.jsx("span",{className:"text-muted-foreground",children:r.idle})]})]},A.origin)}),o.jsx("div",{className:"mt-1 border-t border-border/15 pt-1",children:o.jsxs("button",{type:"button",role:"menuitem",className:"flex min-h-9 w-full items-center gap-2 rounded-lg px-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-2 hover:text-foreground focus-visible:bg-surface-2 focus-visible:outline-none",onClick:()=>{c(!1),e.showConnectionCenter()},children:[o.jsx(FM,{size:13}),o.jsx("span",{children:r.manageServices})]})})]})]})}const W2="mobile-session-destroy";function Mte(e,t){return t&&e.type==="session"&&e.destination?.droppableId===W2}const Jo="termdock-program-rules-cache",qp="termdock-toolbar-presets-cache",bf="termdock-settings-cache",i7="termdock-color-theme",o7="termdock:right-sidebar:file-preview-open-by-session:v2",yf="termdock:running-session-button-enabled:v1",Dte=60,a7=320,l7=420,Tl=8;function c7(e,t,n){return Math.min(Math.max(e,t),n)}function u7(e){if(typeof window>"u")return{left:Tl,top:Tl};const t=window.innerWidth/2,n=Math.min(64,window.innerHeight/4),r=e?.x??t,s=e?.y??n,i=Math.max(Tl,window.innerWidth-a7-Tl),a=Math.max(Tl,window.innerHeight-l7-Tl);return{left:c7(r+Tl,Tl,i),top:c7(s+Tl,Tl,a),width:a7,maxHeight:`min(${l7}px, calc(100vh - ${Tl*2}px))`}}function jte(e){return e==="dark"||e==="light"}function Pte(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.entries(e).every(([t,n])=>{if(!t||!n||typeof n!="object"||Array.isArray(n))return!1;const r=n;return typeof r.updatedAt=="number"&&Number.isFinite(r.updatedAt)})}function pb(e){const t=Object.entries(e).filter(([n,r])=>n&&Number.isFinite(r.updatedAt)).sort(([,n],[,r])=>r.updatedAt-n.updatedAt).slice(0,Dte);return Object.fromEntries(t)}function Bte(e){return Array.isArray(e)&&e.every(t=>{if(!t||typeof t!="object")return!1;const n=t;return typeof n.id=="string"&&typeof n.pattern=="string"&&typeof n.output=="string"&&(n.matchType==="exact"||n.matchType==="includes"||n.matchType==="prefix"||n.matchType==="regex")})}function Fte(e){return typeof e=="object"&&e!==null&&typeof e.version=="number"&&Array.isArray(e.presets)}function Ote(e,t){const n=Vf(),r=new Set(BF()),s=Array.isArray(e)?e:[],i=qd(s),a=t<Tf;if(i.length===0)return n;if(a){const u=new Map(i.map(y=>[y.id,y])),f=new Map(s.map(y=>[typeof y.id=="string"?y.id.trim().toLowerCase().replace(/[^a-z0-9_-]/g,"-"):"",y])),p=i.filter(y=>!r.has(y.id));return[...n.map(y=>{const v=u.get(y.id),S=f.get(y.id);return v?{...y,rowLayout:v.rowLayout,showOnDesktop:typeof S?.showOnDesktop=="boolean"?S.showOnDesktop:y.showOnDesktop}:y}),...p]}const c=new Set(i.map(u=>u.id));return[...i,...n.filter(u=>!c.has(u.id))]}function Qte(e){return typeof e=="object"&&e!==null&&typeof e.preventSleep=="boolean"&&typeof e.networkAvailable=="boolean"}const $te={name:"",source:"auto",hostname:"",fallbackHostname:"",url:"",fallbackUrl:"",onboardingUrl:null,status:"disabled",reason:null,httpsEnabled:!1,caAvailable:!1,lanAddresses:[],interfaces:[]},Qg="__termdockOverlay",$g="__termdockBaseAnchor",Hg="__termdockBaseGuard",Hte=3,d7=250,Ute="termdock-notification-target-v1",f7="/__termdock-notification-target",h7=3e4;function zte(e){return e==="left-sidebar"||e==="right-sidebar"||e==="right-sidebar-repo-picker"||e==="right-sidebar-file-preview"||e==="settings"||e==="markdown-outline"||e==="markdown-image-lightbox"}function Bd(e){if(!e||typeof e!="object")return null;const t=e[Qg];return zte(t)?t:null}function xv(e){return e&&typeof e=="object"?{...e}:{}}function vC(e){const t=xv(e);return delete t[Qg],t}function Gte(e){const t=vC(e);return delete t[Hg],{...t,[$g]:!0}}function Wte(){typeof window>"u"||window.history.pushState({...vC(window.history.state),[$g]:!0,[Hg]:!0},"",window.location.href)}function wC(){for(let e=0;e<Hte;e+=1)Wte()}function Yp(){typeof window>"u"||(window.history.replaceState(Gte(window.history.state),"",window.location.href),wC())}function vf(e){typeof window>"u"||window.history.pushState({...xv(window.history.state),[$g]:!0,[Qg]:e,[Hg]:!1},"",window.location.href)}function Vte(e){typeof window>"u"||window.history.replaceState({...xv(window.history.state),[$g]:!0,[Qg]:e,[Hg]:!1},"",window.location.href)}const SC=["bash","zsh","fish","sh","dash","ksh","tcsh","csh","nu"];let rl=new Set(SC);function p7(e){const t=new Map;for(const[n,r]of e)t.set(n,{cwd:r.cwd,activeProgram:r.activeProgram,activeProgramRaw:r.activeProgramRaw,inCopyMode:r.inCopyMode,isConnecting:r.isConnecting,agentStatus:r.agentStatus,agentIndicator:r.agentIndicator,agentStatusDetail:r.agentStatusDetail,agent:r.agent,agentMessage:r.agentMessage,agentNativeSessionId:r.agentNativeSessionId,agentResumeRecovered:r.agentResumeRecovered,terminalSessionId:r.terminalSessionId,agentNeedsReview:r.agentNeedsReview,gitStatus:r.gitStatus,shellTitle:r.shellTitle,promptState:r.promptState,tuiProgress:r.tuiProgress});return t}function qte(e,t){if(e.size!==t.size)return!1;for(const[n,r]of t){const s=e.get(n);if(!s||s.cwd!==r.cwd||s.activeProgram!==r.activeProgram||s.activeProgramRaw!==r.activeProgramRaw||s.inCopyMode!==r.inCopyMode||s.isConnecting!==r.isConnecting||s.agentStatus!==r.agentStatus||s.agentIndicator!==r.agentIndicator||s.agentStatusDetail!==r.agentStatusDetail||s.agent!==r.agent||s.agentMessage!==r.agentMessage||s.agentNativeSessionId!==r.agentNativeSessionId||s.agentResumeRecovered!==r.agentResumeRecovered||s.terminalSessionId!==r.terminalSessionId||s.agentNeedsReview!==r.agentNeedsReview||s.gitStatus!==r.gitStatus||s.shellTitle!==r.shellTitle||s.promptState!==r.promptState||s.tuiProgress?.state!==r.tuiProgress?.state||s.tuiProgress?.progress!==r.tuiProgress?.progress)return!1}return!0}function m7(e,t){return o.jsx(JV,{sessionMode:e,state:t})}function Yte(e,t){const n=new Map(e.map(a=>[a.id,a])),r=t.map(a=>n.get(a)).filter(a=>a!==void 0),s=new Set(t),i=e.filter(a=>!s.has(a.id));return[...r,...i]}function Kte(){const{t:e,locale:t,setLocale:n}=Yn(),r="env(safe-area-inset-top, 0px)",s="env(safe-area-inset-bottom, 0px)";iO();const i=D.useMemo(()=>typeof window>"u"?!1:/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1,[]),[a,c]=D.useState(!1),[u,f]=D.useState(()=>Or(i7,jte)??"dark"),p=D.useRef(Or(bf,Qte)).current,[g,y]=D.useState(p?.preventSleep??!1),[v,S]=D.useState(p?.networkAvailable??!0),[A,T]=D.useState(dg),[L,I]=D.useState(fg),[j,P]=D.useState(ny),[F,R]=D.useState(Gf),[C,$]=D.useState(P1),[H,Y]=D.useState(p?.localAccess??$te),[V,fe]=D.useState(p?.localAccess?.name??""),[X,ve]=D.useState(!1),[we,ie]=D.useState(null),[ae,q]=D.useState(null),[z,te]=D.useState(null),[pe,de]=D.useState(!1),ke=D.useMemo(()=>lo(),[]),be=!!(ke?.desktopUpdateState&&ke.checkDesktopUpdate&&ke.installDesktopUpdate),[oe,he]=D.useState(null),[J,Xe]=D.useState(null),[lt,Ze]=D.useState(!1),[ge,Fe]=D.useState(null),[Te,ze]=D.useState(!1),[Be,We]=D.useState(()=>pb(Or(o7,Pte)??{})),[W,xe]=D.useState(0),[He,Ce]=D.useState(!1),[Qe,pt]=D.useState(0),[At,yt]=D.useState(!1),[Yt,Mt]=D.useState(0),[on,xr]=D.useState(!1),[Cn,or]=D.useState(0),Le=D.useRef(null),[ot,Oe]=D.useState({}),{terminalSettings:Dt,updateTerminalSettings:$e}=aW(),Ut=Dt.fontSize,_t=Dt.rendererMode,[Ve,Ur]=D.useState(!1),kn=D.useRef(DO()).current,[Ft,Zn]=b.useState(()=>kn.sessions.map(M=>({id:M.sessionId,name:M.name,customName:M.customName,mode:M.mode,tmuxSessionName:M.tmuxSessionName}))),[Gt,Cr]=D.useState(kn.activeSessionId),[nr,an]=D.useState(null),[Er,yr]=D.useState(null),[Jn,wr]=D.useState([]),[Se,le]=b.useState(()=>{const M=es.getState();return kn.sessions.forEach(G=>{G.backendSessionId&&M.setTerminalSession(G.sessionId,{sessionId:G.backendSessionId,cols:80,rows:24,mode:G.mode,tmuxSessionName:G.tmuxSessionName}),G.activeProgram!=null&&M.setSessionActiveProgram(G.sessionId,G.activeProgram),G.cwd!=null&&M.setSessionCwd(G.sessionId,G.cwd)}),Ff("session-chrome-hydrated"),p7(M.sessions)});b.useEffect(()=>{!ke||!Ve||Promise.all([ke.snapshot(),ke.desktopUpdateState?.()??Promise.resolve(null)]).then(([M,G])=>{he(M),Xe(G)}).catch(M=>Fe(M instanceof Error?M.message:String(M)))},[ke,Ve]),b.useEffect(()=>{ke?.onDesktopUpdateState&&ke.onDesktopUpdateState(Xe)},[ke]),b.useEffect(()=>es.subscribe(M=>{const G=p7(M.sessions);le(Re=>qte(Re,G)?Re:G)}),[]);const It=b.useCallback(async(M,G)=>{yr(null),an({sessionId:M,status:"submitting",error:null});try{await ZE(G),an(Re=>Re?.sessionId===M?{...Re,status:"waiting",error:null}:Re)}catch(Re){const Pt=(Re&&typeof Re=="object"&&"code"in Re?String(Re.code??""):"")==="AGENT_SESSION_ACTIVE_ELSEWHERE"?e("tab.resumeAgentConflict"):Re instanceof Error&&/busy/i.test(Re.message)?e("tab.resumeAgentBusy"):e("tab.resumeAgentFailed");an(Wt=>Wt?.sessionId===M?{...Wt,error:Pt}:Wt),yr({tone:"error",message:Pt})}},[e]);b.useEffect(()=>{if(!nr||nr.status!=="waiting")return;const M=Se.get(nr.sessionId);if(!M||M.agentResumeRecovered||M.agentStatus===null)return;const G=M.agent?.displayName??"Agent";an(null),yr({tone:"success",message:e("tab.resumeAgentSuccess",{agent:G})})},[nr,Se,e]),b.useEffect(()=>{if(!nr||nr.status!=="waiting"||nr.error)return;const M=nr.sessionId,G=window.setTimeout(()=>{const Re=e("tab.resumeAgentTimeout");an(rt=>rt?.sessionId===M&&rt.status==="waiting"?{...rt,error:Re}:rt),yr({tone:"error",message:Re})},15e3);return()=>window.clearTimeout(G)},[nr,e]),b.useEffect(()=>{if(Er?.tone!=="success")return;const M=window.setTimeout(()=>yr(null),3200);return()=>window.clearTimeout(M)},[Er]),b.useEffect(()=>{let M=!1;JL().then(Re=>{M||te(Re)}).catch(()=>{});const G=Mm(Re=>{Re.type==="update-state"&&!M&&te(Re.state)});return()=>{M=!0,G()}},[]);const Me=b.useCallback(async()=>{const M=z?.latestVersion;if(!(!M||pe)&&window.confirm(e("sidebar.updateRestartConfirm",{version:M}))){de(!0);try{te(await tE())}catch(G){window.alert(G instanceof Error?G.message:String(G))}finally{de(!1)}}},[z?.latestVersion,e,pe]),Ee=b.useCallback(async()=>{if(!pe){de(!0);try{te(await eE())}catch(M){window.alert(M instanceof Error?M.message:String(M))}finally{de(!1)}}},[pe]),Ge=b.useCallback(async()=>{if(!(!ke?.checkDesktopUpdate||lt)){Ze(!0);try{Xe(await ke.checkDesktopUpdate())}catch(M){Fe(M instanceof Error?M.message:String(M))}finally{Ze(!1)}}},[ke,lt]),dt=b.useCallback(async()=>{if(!(!ke?.installDesktopUpdate||lt||J?.status!=="ready")&&window.confirm(e("settings.desktopUpdateRestartConfirm"))){Ze(!0);try{Xe(await ke.installDesktopUpdate())}catch(M){Fe(M instanceof Error?M.message:String(M)),Ze(!1)}}},[ke,lt,J?.status,e]);b.useEffect(()=>{document.documentElement.dataset.theme=u,i9(u),$n(i7,u)},[u]),b.useEffect(()=>{$n(o7,pb(Be))},[Be]);const gt=ft(M=>M.leftOpen),Kt=ft(M=>M.rightOpen),nn=ft(M=>M.leftPinned),vt=ft(M=>M.leftSidebarWidth),un=ft(M=>M.rightPinned),Hn=ft(M=>M.rightSidebarWidth),rr=ft(M=>M.rootPath),fn=ft(M=>M.contextKey),Un=ft(M=>M.selectedFilePath),hn=ft(M=>M.groupByFolder),Kn=ft(M=>M.collapsedGroups),sn=ft(M=>M.toggleGroupCollapsed),[zn,as]=b.useState(()=>typeof window>"u"?!0:window.matchMedia("(min-width: 1024px)").matches),[Bt,rn]=b.useState(()=>typeof window>"u"?1024:window.innerWidth),[bt,Tt]=b.useState(()=>typeof window>"u"?!1:window.matchMedia("(orientation: landscape)").matches),[at,$t]=b.useState([]),[Rt,vn]=b.useState({available:!0,version:null,reason:null}),[Ot,Jt]=b.useState(!1),[ar,qe]=b.useState(null),[ct,jt]=b.useState(null),[dn,An]=b.useState(null),[_n,ln]=b.useState(null),[pn,tn]=b.useState(null),[cn,sr]=b.useState(null),[ps,Qr]=b.useState(null),[se,_e]=b.useState(null),[je,tt]=b.useState(null),[Qt,Nt]=b.useState(null),[st,wt]=b.useState(!1),[Lt,Tn]=b.useState(()=>Or(yf,M=>typeof M=="boolean")??!1),mn=b.useCallback(async M=>{const G=Lt;Tn(M),$n(yf,M);try{const Re=await ta({runningSessionButtonEnabled:M});Tn(Re.runningSessionButtonEnabled),$n(yf,Re.runningSessionButtonEnabled)}catch{Tn(G),$n(yf,G)}},[Lt]),[lr,zr]=b.useState(null),jn=b.useCallback(M=>{zr(M)},[]),mr=b.useRef(!1),[dr,en]=b.useState(null),[Vt,ir]=b.useState(null),Xn=D.useRef(null),Gr=D.useRef(!1),gn=D.useRef(null),fr=D.useRef(!1),Ln=b.useCallback(()=>{sr(null),Qr(null)},[]),ns=D.useRef(typeof window>"u"?null:new URLSearchParams(window.location.search).get("session")),[kr,ls]=D.useState(ns.current),[ms,ui]=D.useState(ns.current!==null||typeof caches>"u"),di=D.useRef(ns.current),ws=D.useRef(typeof window>"u"?null:new URLSearchParams(window.location.search).get("_notifTrace"));b.useEffect(()=>{if(typeof window>"u")return;const M=window.matchMedia("(min-width: 1024px)"),G=()=>{as(M.matches),rn(window.innerWidth)};return G(),M.addEventListener("change",G),window.addEventListener("resize",G),()=>{M.removeEventListener("change",G),window.removeEventListener("resize",G)}},[]),b.useEffect(()=>{if(typeof window>"u")return;const M=window.matchMedia("(orientation: landscape)"),G=()=>Tt(M.matches);return G(),M.addEventListener("change",G),()=>M.removeEventListener("change",G)},[]),D.useLayoutEffect(()=>((()=>{const G=Gt?es.getState().sessions.get(Gt)?.cwd??null:null;ft.getState().setRootPath(G,Gt)})(),es.subscribe((G,Re)=>{const rt=Gt?G.sessions.get(Gt)?.cwd??null:null,Pt=Gt?Re.sessions.get(Gt)?.cwd??null:null;rt!==Pt&&ft.getState().setRootPath(rt,Gt)})),[Gt]);const ja=zn||bt,fi=zn||bt,ia=ja?Math.min(Math.max(Bt*.9,360),Bt-56):Math.min(Bt*.92,420),hi=fi?Math.min(Math.max(Bt*.22,280),340):Math.min(Bt*.86,380),Es=Gt&&rr?`${Gt}\0${rr}`:"",cr=!!(Es&&Un&&Be[Es]),pi=b.useCallback(M=>{Es&&(M&&!ft.getState().selectedFilePath||We(G=>{if(!!G[Es]===M)return G;if(M)return pb({...G,[Es]:{updatedAt:Date.now()}});const rt={...G};return delete rt[Es],rt}))},[Es]);b.useEffect(()=>{pW(Es,fn,Un)&&We(M=>{if(!M[Es])return M;const G={...M};return delete G[Es],G})},[Es,fn,Un]);const rs=on?"markdown-image-lightbox":At?"markdown-outline":He?"right-sidebar-repo-picker":Kt&&cr?"right-sidebar-file-preview":Ve?"settings":Kt&&!(un&&zn)?"right-sidebar":gt&&!(nn&&zn)?"left-sidebar":null,er=D.useRef(rs),Mr=D.useRef(rs),Is=D.useRef(!1),Dr=D.useRef(!1),Cs=b.useCallback(()=>{if(typeof window>"u")return;const M=window.matchMedia("(hover: hover) and (pointer: fine)").matches;!zn||!M||navigator.maxTouchPoints>0||window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("focus-active-terminal-session"))},0)},[zn]),To=b.useCallback(M=>{if(M==="markdown-image-lightbox"){xr(!1),or(G=>G+1);return}if(M==="markdown-outline"){yt(!1),Mt(G=>G+1);return}if(M==="right-sidebar-file-preview"){yt(!1),Mt(G=>G+1),pi(!1),xe(G=>G+1);return}if(M==="right-sidebar-repo-picker"){Ce(!1),pt(G=>G+1);return}if(M==="settings"){Ur(!1),$s(!1),B(!1),Ir(!1);return}if(M==="left-sidebar"){ft.getState().closeLeft();return}yt(!1),Mt(G=>G+1),Ce(!1),pt(G=>G+1),xr(!1),or(G=>G+1),ft.getState().closeRight()},[pi]),Wr=b.useCallback(M=>{if(!i&&typeof window<"u"&&er.current===M&&Bd(window.history.state)===M){window.history.back();return}To(M)},[To,i]),oa=b.useCallback(()=>{Ur(!1);const M=ft.getState();M.closeRight(),M.openLeft()},[]),Co=b.useCallback(()=>{Ur(!1);const M=ft.getState();M.closeLeft(),M.openRight()},[]),zi=b.useCallback(()=>{Ur(!1);const M=ft.getState();M.closeLeft(),M.openRight(),M.setRightTab("files"),M.openRightSearch()},[]),Js=b.useCallback(()=>{const M=ft.getState();if(M.leftPinned){M.setLeftPinned(!1),M.closeLeft();return}if(gt){Wr("left-sidebar");return}oa()},[oa,Wr,gt]),Fs=b.useCallback(()=>{const M=ft.getState();M.leftPinned?(M.setLeftPinned(!1),M.openLeft()):(M.setLeftPinned(!0),M.openLeft())},[]),aa=b.useCallback(()=>{const M=ft.getState();M.setLeftPinned(!1),M.closeLeft()},[]),la=b.useCallback(()=>{const M=ft.getState();M.rightPinned?(M.setRightPinned(!1),M.openRight()):(M.setRightPinned(!0),M.openRight())},[]),Os=b.useCallback(()=>{const M=ft.getState();M.setRightPinned(!1),M.closeRight()},[]),ca=b.useRef(0),Gi=b.useRef(0),ki=b.useRef(null),_i=b.useCallback(M=>{M.preventDefault(),ca.current=M.clientX,Gi.current=ft.getState().leftSidebarWidth;const G=rt=>{ki.current===null&&(ki.current=requestAnimationFrame(()=>{ki.current=null;const Pt=rt.clientX-ca.current;ft.getState().setLeftSidebarWidth(Gi.current+Pt)}))},Re=()=>{window.removeEventListener("mousemove",G),window.removeEventListener("mouseup",Re),ki.current!==null&&(cancelAnimationFrame(ki.current),ki.current=null),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",G),window.addEventListener("mouseup",Re)},[]),gs=b.useRef(0),mi=b.useRef(0),ei=b.useRef(null),ko=b.useCallback(M=>{M.preventDefault(),gs.current=M.clientX;const G=ft.getState(),Re=G.leftPinned?G.leftSidebarWidth:0;mi.current=px(G.rightSidebarWidth,window.innerWidth,Re);const rt=Wt=>{ei.current===null&&(ei.current=requestAnimationFrame(()=>{ei.current=null;const Pn=gs.current-Wt.clientX,Fr=ft.getState(),Yr=Fr.leftPinned?Fr.leftSidebarWidth:0;Fr.setRightSidebarWidth(px(mi.current+Pn,window.innerWidth,Yr))}))},Pt=()=>{window.removeEventListener("mousemove",rt),window.removeEventListener("mouseup",Pt),ei.current!==null&&(cancelAnimationFrame(ei.current),ei.current=null),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("mousemove",rt),window.addEventListener("mouseup",Pt)},[]),Wi=b.useCallback(()=>{const M=ft.getState();if(M.rightPinned){M.setRightPinned(!1),M.closeRight();return}if(Kt){Wr("right-sidebar");return}Co()},[Co,Wr,Kt]),ua=b.useCallback(()=>{!cr&&!i&&typeof window<"u"&&er.current==="right-sidebar"&&Bd(window.history.state)==="right-sidebar"&&(vf("right-sidebar-file-preview"),Mr.current="right-sidebar-file-preview"),pi(!0)},[cr,i,pi]),Pa=b.useCallback(()=>{Wr("right-sidebar-file-preview")},[Wr]),fl=b.useCallback(()=>{!He&&!i&&typeof window<"u"&&er.current==="right-sidebar"&&Bd(window.history.state)==="right-sidebar"&&(vf("right-sidebar-repo-picker"),Mr.current="right-sidebar-repo-picker"),Ce(!0)},[He,i]),Qs=b.useCallback(()=>{Wr("right-sidebar-repo-picker")},[Wr]),gi=b.useCallback(()=>{!At&&!i&&typeof window<"u"&&er.current&&Bd(window.history.state)===er.current&&(vf("markdown-outline"),Mr.current="markdown-outline"),yt(!0)},[At,i]),Li=b.useCallback(()=>{Wr("markdown-outline")},[Wr]),Ei=b.useCallback(()=>{!i&&typeof window<"u"&&er.current&&Bd(window.history.state)===er.current&&(vf("markdown-image-lightbox"),Mr.current="markdown-image-lightbox"),xr(!0)},[i]),po=b.useCallback(()=>{Wr("markdown-image-lightbox")},[Wr]),me=b.useCallback(()=>{!i&&typeof window<"u"&&er.current&&Bd(window.history.state)===er.current&&(Vte("settings"),Mr.current="settings"),ft.getState().closeAll(),Ur(!0)},[i]),ut=b.useCallback(()=>{Wr("settings")},[Wr]);b.useEffect(()=>{if(!ke)return;const M=()=>me();return window.addEventListener("termdock:open-settings",M),()=>window.removeEventListener("termdock:open-settings",M)},[ke,me]);const xt=b.useCallback(()=>{ze(!0),Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null)},[]),nt=b.useCallback(()=>{Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null),ze(!1),Dr.current=!0,Yp(),Dr.current},[]);b.useEffect(()=>()=>{Le.current!==null&&window.clearTimeout(Le.current)},[]),b.useEffect(()=>{i||Yp()},[i]),b.useEffect(()=>{if(typeof window>"u"||i)return;let M=null;const G=()=>{M!==null&&(window.clearTimeout(M),M=null)},Re=Fr=>{if(er.current,Dr.current,er.current){er.current;return}!Fr?.force&&Dr.current||(Fr?.userActivated&&(Dr.current=!0),Yp(),Dr.current,void 0)},rt=()=>{G(),M=window.setTimeout(()=>{M=null,Re({force:!0})},d7)},Pt=()=>{Re({userActivated:!0})},Wt=()=>{rt()},Pn=()=>{document.visibilityState==="visible"&&rt()};return window.addEventListener("pointerdown",Pt,{capture:!0,passive:!0}),window.addEventListener("touchstart",Pt,{capture:!0,passive:!0}),window.addEventListener("keydown",Pt,{capture:!0}),window.addEventListener("pageshow",Wt),document.addEventListener("visibilitychange",Pn),()=>{G(),window.removeEventListener("pointerdown",Pt,{capture:!0}),window.removeEventListener("touchstart",Pt,{capture:!0}),window.removeEventListener("keydown",Pt,{capture:!0}),window.removeEventListener("pageshow",Wt),document.removeEventListener("visibilitychange",Pn)}},[i]),b.useEffect(()=>{er.current=rs},[rs]),b.useEffect(()=>{if(typeof window>"u"||rs||i)return;const M=window.setTimeout(()=>{er.current?(er.current,void 0):Yp()},d7);return()=>window.clearTimeout(M)},[rs,i]),b.useEffect(()=>{if(typeof window>"u"||i)return;const M=Mr.current;Is.current,rs&&rs!==M&&!Is.current&&vf(rs),!rs&&M&&Cs(),Mr.current=rs,!rs&&Is.current&&window.setTimeout(()=>{Is.current=!1},0)},[rs,i,Cs]),b.useEffect(()=>{if(typeof window>"u"||i)return;const M=()=>{const G=er.current;if(Dr.current,!G){Dr.current=!1,Dr.current,xt(),wC();return}Is.current=!0,To(G)};return window.addEventListener("popstate",M),()=>window.removeEventListener("popstate",M)},[To,xt,i]),b.useEffect(()=>{const M=G=>{const Re=G.metaKey||G.ctrlKey;if(Re&&G.key==="b"&&!G.shiftKey&&(G.preventDefault(),Js()),Re&&G.shiftKey&&G.key==="E"&&(G.preventDefault(),Wi()),Re&&G.shiftKey&&G.key==="P"&&(G.preventDefault(),zi()),Re&&!G.shiftKey&&G.altKey&&(G.key==="ArrowLeft"||G.key==="ArrowRight")){G.preventDefault();const rt=G.key==="ArrowRight"?"next":"prev";window.dispatchEvent(new CustomEvent("cycle-terminal-session",{detail:{direction:rt}}));return}if(Re&&G.shiftKey&&!G.altKey&&(G.code==="BracketLeft"||G.code==="BracketRight")){G.preventDefault();const rt=G.code==="BracketRight"?"next":"prev";window.dispatchEvent(new CustomEvent("cycle-terminal-session",{detail:{direction:rt}}));return}};return document.addEventListener("keydown",M),()=>{document.removeEventListener("keydown",M)}},[Js,Wi,zi]);const Ct=b.useCallback(async()=>{ve(!0),ie(null);try{const M=await ta({localAccess:{name:V}});Y(M.localAccess),fe(M.localAccess.name),$n(bf,{preventSleep:M.preventSleep,networkAvailable:M.networkAvailable,localAccess:M.localAccess})}catch(M){ie(M instanceof Error?M.message:"Failed to save local access name")}finally{ve(!1)}},[V]),On=b.useCallback(async()=>{ve(!0),ie(null);try{const M=await ta({localAccess:{reset:!0}});Y(M.localAccess),fe(M.localAccess.name),$n(bf,{preventSleep:M.preventSleep,networkAvailable:M.networkAvailable,localAccess:M.localAccess})}catch(M){ie(M instanceof Error?M.message:"Failed to reset local access name")}finally{ve(!1)}},[]),Ae=b.useCallback(async(M,G="url")=>{if(M)try{if(typeof navigator<"u"&&navigator.clipboard)await navigator.clipboard.writeText(M);else{const Re=document.createElement("textarea");Re.value=M,Re.style.position="fixed",Re.style.left="-9999px",document.body.appendChild(Re),Re.focus(),Re.select(),document.execCommand("copy"),document.body.removeChild(Re)}q(G),window.setTimeout(()=>q(Re=>Re===G?null:Re),1600)}catch{q(null)}},[]),hr=b.useCallback(M=>{const G=Yte(Ft,M);G.map(Re=>Re.id).join("\0")!==Ft.map(Re=>Re.id).join("\0")&&(Zn(G),window.dispatchEvent(new CustomEvent("reorder-terminal-session",{detail:{sessionIds:G.map(Re=>Re.id)}})))},[Ft]),Ss=b.useCallback(M=>{zn||M.type!=="session"||(mr.current=!1,wt(!1),Nt(M.draggableId))},[zn]),qn=b.useCallback(M=>{if(zn||M.type!=="session")return;const G=M.destination?.droppableId===W2;G!==mr.current&&(mr.current=G,wt(G),G&&navigator.vibrate?.(20))},[zn]),cs=b.useCallback(M=>{const G=Mte(M,!zn);return mr.current=!1,wt(!1),Nt(null),G?(window.dispatchEvent(new CustomEvent("close-terminal-session",{detail:{sessionId:M.draggableId,source:"other",closeMode:"destroy"}})),!0):!1},[zn]),Vr=b.useCallback(M=>{if(cs(M)||!M.destination||M.source.index===M.destination.index)return;const G=[...Ft],[Re]=G.splice(M.source.index,1);G.splice(M.destination.index,0,Re),hr(G.map(rt=>rt.id))},[hr,cs,Ft]),Gs=b.useCallback((M,G)=>{const Re=G.trim();Re&&window.dispatchEvent(new CustomEvent("rename-terminal-session",{detail:{sessionId:M,name:Re}}))},[]),qr=b.useCallback(M=>{window.dispatchEvent(new CustomEvent("reset-terminal-session-name",{detail:{sessionId:M}}))},[]),{newSessionMode:Rr,newSessionTmuxName:Ws,userSelectedNewSessionMode:tc,setNewSessionMode:Nn}=uW(),[Kr,Ho]=b.useState(null),[_o,$s]=D.useState(!1),[xi,B]=D.useState(!1),[K,ee]=D.useState("idle"),ce=D.useRef(Or(qp,Fte)).current,[Je,Ke]=D.useState(()=>{const M=ce?.presets;if(M&&M.length>0){const G=qd(M);if(G.length>0)return G}return Vf()}),[ht,Ht]=D.useState(!1),[et,Zt]=D.useState("default"),_r=D.useRef(typeof ce?.updatedAt=="number"?ce.updatedAt:null),jr=D.useRef(!1),[Lr,Ir]=D.useState(!1),[xs,Gn]=D.useState(!1),Wn=D.useRef(Or(Jo,Bte)).current,[Pr,ur]=D.useState(Wn??[]),[da,us]=D.useState(Wn!==null),[ti,Br]=D.useState(!1),Ii=!rs&&!xi&&!_o&&!Lr&&!xs&&!cn&&!dr&&!Kr,Vi=D.useCallback(M=>{const G=typeof M.version=="number"?M.version:0,Re=Ote(Array.isArray(M.presets)?M.presets:[],G);_r.current=typeof M.updatedAt=="number"?M.updatedAt:null,Ke(rt=>PO(rt,Re)?rt:(jr.current=!0,Re)),$n(qp,{version:Tf,presets:Re,updatedAt:_r.current??void 0})},[]);b.useEffect(()=>{const M=G=>{if(G.key!=="Escape")return;if(xi){G.preventDefault(),B(!1);return}if(_o){G.preventDefault(),$s(!1);return}if(Lr){G.preventDefault(),Ir(!1);return}if(xs){G.preventDefault(),Gn(!1);return}if(cn){G.preventDefault(),Ln();return}if(se){G.preventDefault(),tn(null),_e(null);return}if(Ve){G.preventDefault(),ut();return}if(Kt&&!(un&&zn)){G.preventDefault(),Wr("right-sidebar");return}gt&&!(nn&&zn)&&(G.preventDefault(),Wr("left-sidebar"))};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[xi,_o,Lr,cn,Ln,Ve,Kt,un,gt,nn,zn,ut,Wr]),b.useEffect(()=>{us(!0)},[]);const[ni,fa]=D.useState({genericProgramNames:[],wrapperScriptNames:[],shellNames:SC}),[,ou]=D.useState(!1),Il=D.useCallback(()=>tI().then(M=>{fa(M),rl=new Set(M.shellNames),ou(!0)}).catch(()=>{}),[]);b.useEffect(()=>{Il()},[Il]),b.useEffect(()=>Mm(M=>{if(M.type==="config-updated"){if(M.key==="toolbar-presets"){s5().then(G=>Vi(G)).catch(G=>{console.warn("[toolbar-presets] Failed to refresh after remote update:",G)});return}M.key==="program-detection"&&Il()}}),[Vi,Il]),b.useEffect(()=>{let M=!1;return(async()=>{try{const G=await s5();if(M)return;Vi(G)}catch(G){console.warn("[toolbar-presets] Failed to load from server:",G)}finally{M||Ht(!0)}})(),()=>{M=!0}},[Vi]),b.useEffect(()=>{if(ht){if(jr.current){jr.current=!1;return}$n(qp,{version:Tf,presets:Je,updatedAt:_r.current??void 0}),PE({version:Tf,presets:Je,baseUpdatedAt:_r.current??void 0}).then(M=>{_r.current=typeof M.updatedAt=="number"?M.updatedAt:null,$n(qp,{version:Tf,presets:Je,updatedAt:_r.current??void 0})}).catch(M=>{const G=M instanceof Error&&"current"in M?M.current:null;G&&typeof G=="object"&&Vi(G),console.warn("[toolbar-presets] Failed to save to server:",M)})}},[Vi,Je,ht]),b.useEffect(()=>{dh().then(M=>{y(G=>G===M.preventSleep?G:M.preventSleep),S(G=>G===M.networkAvailable?G:M.networkAvailable),Y(M.localAccess),fe(M.localAccess.name),Tn(M.runningSessionButtonEnabled),$n(yf,M.runningSessionButtonEnabled),$n(bf,{preventSleep:M.preventSleep,networkAvailable:M.networkAvailable,localAccess:M.localAccess})}).catch(()=>{})},[]),b.useEffect(()=>{if(!A)return;const M=P1();$(M),M!=="granted"&&(T(!1),lp(!1))},[A]),b.useEffect(()=>{if(!A)return;Fd();const M=()=>{document.visibilityState==="visible"&&(Fd(),lR())},G=window.setInterval(()=>{Fd()},360*60*1e3);return document.addEventListener("visibilitychange",M),window.addEventListener("focus",M),()=>{window.clearInterval(G),document.removeEventListener("visibilitychange",M),window.removeEventListener("focus",M)}},[A]);const Ec=b.useCallback(async()=>{if(A){T(!1),lp(!1),aR(),$(P1());return}const M=await tR();if($(M),M!=="granted"){T(!1),lp(!1);return}T(!0),lp(!0),await Fd(!0,!0),ee("idle")},[A]),Ic=b.useCallback(async()=>{ee("checking"),await lo()?.prepareNotificationTest?.();const M=await Jp({title:"Termdock",body:e("settings.notificationsTestBody"),tag:"termdock-notification-test",requireHidden:!1,data:{url:"/"}});ee(M?"delivered":"failed")},[e]),Rc=b.useCallback(M=>{I(M),ZI(M),B1()},[]),Ba=b.useCallback(M=>{P(M),JI(M),B1()},[]),nc=b.useCallback(M=>{R(M),eR(M),B1()},[]);b.useEffect(()=>{Je.some(M=>M.id===et)||Zt(Je[0]?.id??"default")},[et,Je]),b.useEffect(()=>{if(!Rt.available&&Rr==="tmux"){Nn("shell",{userInitiated:!1});return}Rt.available&&tc!=="shell"&&Rr!=="tmux"&&Nn("tmux",{userInitiated:!1})},[Rr,Rt.available,tc,Nn]),b.useEffect(()=>{Ho(null)},[Ve,Rr,Rt.available]),b.useEffect(()=>{const M={};typeof navigator<"u"&&(M.userAgent=navigator.userAgent,M.platform=navigator.platform,M.maxTouchPoints=navigator.maxTouchPoints,M.hasTouch=navigator.maxTouchPoints>0||"ontouchstart"in window,M.vendor=navigator.vendor),typeof window<"u"&&(M.screenWidth=window.innerWidth,M.screenHeight=window.innerHeight,M.pixelRatio=window.devicePixelRatio,M.orientation=window.screen?.orientation?.type||"unknown",M.hasVisualViewport=!!window.visualViewport,M.visualViewportHeight=window.visualViewport?.height,M.visualViewportWidth=window.visualViewport?.width,M.location=window.location.href),M.timestamp=new Date().toISOString(),M.isIOS=/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1,M.isAndroid=/Android/.test(navigator.userAgent),Oe(M)},[]);const{groups:Lo}=D.useMemo(()=>uS(Ft,M=>Se.get(M.id)?.cwd??null,hn,e("sidebar.ungrouped")),[Ft,Se,hn,e]),vr=b.useCallback(M=>{if(cs(M)||!M.destination)return;if(M.type==="group"){if(M.source.index===M.destination.index)return;hr(cS(Lo,M.source.index,M.destination.index));return}if(M.source.droppableId!==M.destination.droppableId||M.source.index===M.destination.index)return;const G=M.source.droppableId.replace(/^group-sessions:/,"");hr(wF(Lo,G,M.source.index,M.destination.index))},[Lo,hr,cs]),Fa=D.useMemo(()=>Lo.length>0?Lo.flatMap(M=>M.sessions):Ft,[Lo,Ft]),qi=D.useMemo(()=>Fa.flatMap(M=>{const G=Se.get(M.id);if(G?.agentStatus!=="working")return[];const{primary:Re,secondary:rt}=gc(M,G?.activeProgram??null,G?.cwd??null,rl,G?.shellTitle??null,G?.promptState??null);return[{id:M.id,label:Re,detail:rt}]}),[Fa,Se]),Nc=Gt?Fa.findIndex(M=>M.id===Gt):-1,Oa=Fa.length>0&&Nc>=0?`${Nc+1}/${Fa.length}`:`${Fa.length}`,ha=D.useMemo(()=>{let M=0;for(const G of Ft){const Re=Se.get(G.id);(Re?.agentStatus==="waiting"||Re?.agentNeedsReview)&&(M+=1)}return{running:qi.length,review:M}},[qi.length,Ft,Se]),Vs=Gt?Ft.find(M=>M.id===Gt)??null:null,Uo=Vs?Se.get(Vs.id):void 0,pa=!!(Vs&&Uo?.agentResumeRecovered&&Uo.agentNativeSessionId&&Uo.terminalSessionId),qs=Vs&&nr?.sessionId===Vs.id?nr:null;D.useLayoutEffect(()=>{if(!ms)return;const M=gn.current;if(!M)return;const G=!fr.current;M.scrollIntoView({inline:"nearest",block:"nearest",behavior:G?"auto":"smooth"}),fr.current=!0,G&&Ff("active-tab-positioned")},[Gt,ms]),b.useEffect(()=>{pn&&Xn.current&&(Xn.current.scrollIntoView({block:"nearest",inline:"nearest"}),Xn.current.focus(),Xn.current.select()),pn||(Gr.current=!1)},[pn]);const hl=b.useCallback(M=>{window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:M}))},[]),Rl=b.useCallback((M,G)=>{Qr(G??null),sr(M)},[]),Nl=s9(),Qa=b.useCallback(M=>{if(!M)return;ls(M),ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-focus-request",{traceId:ws.current,requestedSessionId:M,activeSessionId:Gt,sessions:Ft.map(Re=>({id:Re.id,terminalSessionId:Se.get(Re.id)?.terminalSessionId??null}))}),cR(M);const G=Ft.find(Re=>Re.id===M||Se.get(Re.id)?.terminalSessionId===M);G?(di.current=null,ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-focus-dispatch",{traceId:ws.current,requestedSessionId:M,targetSessionId:G.id}),window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G.id}))):(di.current=M,ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-focus-pending",{traceId:ws.current,requestedSessionId:M}))},[Gt,Ft,Se]);b.useEffect(()=>{if(typeof window>"u"||typeof caches>"u")return;let M=!1;const G=async()=>{try{const rt=await caches.open(Ute),Pt=await rt.match(f7);if(!Pt)return;await rt.delete(f7);const Wt=await Pt.json();if(M)return;const Pn=typeof Wt.sessionId=="string"?Wt.sessionId:null,Fr=typeof Wt.traceId=="string"?Wt.traceId:null,Yr=typeof Wt.clickedAt=="number"?Wt.clickedAt:0,Xr=Date.now()-Yr;Ca("info","PWA_NOTIFICATION_CLICK app-cache-consumed",{traceId:Fr,sessionId:Pn,ageMs:Xr,valid:!!(Pn&&Xr>=0&&Xr<=h7),visibilityState:document.visibilityState}),Pn&&Xr>=0&&Xr<=h7&&(ws.current=Fr,Qa(Pn))}catch(rt){Ca("warn","PWA_NOTIFICATION_CLICK app-cache-failed",{error:rt instanceof Error?rt.message:String(rt)})}finally{M||ui(!0)}},Re=()=>{document.visibilityState==="visible"&&G()};return G(),document.addEventListener("visibilitychange",Re),window.addEventListener("pageshow",G),()=>{M=!0,document.removeEventListener("visibilitychange",Re),window.removeEventListener("pageshow",G)}},[Qa]),b.useEffect(()=>{if(typeof window>"u")return;const M=new URLSearchParams(window.location.search),G=M.get("session");if(!G)return;Ca("info","PWA_NOTIFICATION_CLICK app-url-received",{traceId:ws.current,targetSessionId:G,href:window.location.href,visibilityState:document.visibilityState}),di.current=G,M.delete("session"),M.delete("_notifTrace");const Re=M.toString(),rt=`${window.location.pathname}${Re?`?${Re}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",rt)},[]),b.useEffect(()=>{if(typeof window>"u")return;const M=new URLSearchParams(window.location.search);if(M.get("_notif")!=="1")return;const G=M.get("session");M.delete("_notif");const Re=M.toString(),rt=`${window.location.pathname}${Re?`?${Re}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",rt);const Pt=new BroadcastChannel("termdock:notif");let Wt=!1;const Pn=Yr=>{Yr.data?.type==="termdock:notif-pong"&&!Wt&&(Wt=!0,Pt.close(),window.close())};Pt.addEventListener("message",Pn),Pt.postMessage({type:"termdock:notif-ping",sessionId:G});const Fr=setTimeout(()=>{Wt||Pt.close()},500);return()=>{clearTimeout(Fr),Wt||Pt.close()}},[]),b.useEffect(()=>{if(typeof window>"u")return;const M=new BroadcastChannel("termdock:notif"),G=Re=>{Re.data?.type==="termdock:notif-ping"&&(M.postMessage({type:"termdock:notif-pong"}),typeof Re.data.sessionId=="string"&&Qa(Re.data.sessionId))};return M.addEventListener("message",G),()=>M.close()},[Qa]),b.useEffect(()=>{if(typeof navigator>"u"||!("serviceWorker"in navigator))return;const M=G=>{const Re=G.data;Re&&Re.type==="termdock:focus-session"&&typeof Re.sessionId=="string"?(G.ports[0]?.postMessage({type:"termdock:focus-session-ack"}),Qa(Re.sessionId)):Re?.type==="termdock:push-subscription-changed"?Fd(!0):Re?.type};return navigator.serviceWorker.addEventListener("message",M),()=>navigator.serviceWorker.removeEventListener("message",M)},[Qa]),b.useEffect(()=>{const M=G=>{const Re=G.detail;typeof Re=="string"&&Qa(Re)};return window.addEventListener("termdock:focus-session",M),()=>window.removeEventListener("termdock:focus-session",M)},[Qa]),b.useEffect(()=>{const M=di.current;if(!M)return;const G=Ft.find(Re=>Re.id===M||Se.get(Re.id)?.terminalSessionId===M);G?(di.current=null,ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-pending-dispatch",{traceId:ws.current,requestedSessionId:M,targetSessionId:G.id,activeSessionId:Gt}),window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G.id}))):ws.current&&Ca("info","PWA_NOTIFICATION_CLICK app-pending-unmatched",{traceId:ws.current,requestedSessionId:M,activeSessionId:Gt,sessions:Ft.map(Re=>({id:Re.id,terminalSessionId:Se.get(Re.id)?.terminalSessionId??null}))})},[Gt,Ft,Se]);const ma=D.useMemo(()=>{const M=[];for(const G of Ft){const Re=Se.get(G.id);(Re?.agentStatus==="waiting"||Re?.agentNeedsReview)&&M.push(G.id)}return M},[Ft,Se]),rc=b.useCallback(()=>{if(ma.length===0)return;Gt&&es.getState().clearAgentNeedsReview(Gt);const M=Gt?Ft.findIndex(Re=>Re.id===Gt):-1,G=ma.find(Re=>Ft.findIndex(rt=>rt.id===Re)>M)??ma[0];G&&window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G}))},[ma,Ft,Gt]),ga=b.useCallback(()=>{if(ma.length===0)return;Gt&&es.getState().clearAgentNeedsReview(Gt);const M=Gt?Ft.findIndex(Re=>Re.id===Gt):Ft.length,G=[...ma].reverse().find(Re=>Ft.findIndex(rt=>rt.id===Re)<M)??ma[ma.length-1];G&&window.dispatchEvent(new CustomEvent("switch-terminal-session",{detail:G}))},[ma,Ft,Gt]);b.useEffect(()=>{const M=G=>{!G.altKey||!G.shiftKey||G.metaKey||G.ctrlKey||G.key!=="ArrowUp"&&G.key!=="ArrowDown"||(G.preventDefault(),G.key==="ArrowUp"?ga():rc())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[rc,ga]);const zo=b.useCallback(async M=>{const Re=es.getState().sessions.get(M)?.cwd;if(Re)try{await navigator.clipboard?.writeText(Re),tt(Re),window.setTimeout(()=>{tt(rt=>rt===Re?null:rt)},1400)}catch{}},[]),As=b.useCallback(M=>{Zn(M.sessions),Cr(M.activeSessionId),wr(M.splitWorkspaces),es.getState().setActiveSessionId(M.activeSessionId)},[]);b.useEffect(()=>{if(!kr||!Gt)return;Ft.find(G=>G.id===kr||Se.get(G.id)?.terminalSessionId===kr)?.id===Gt&&ls(null)},[Gt,kr,Ft,Se]);const bi=b.useCallback(M=>{const G=M?.mode??Rr,Re=G==="tmux"&&(M?.tmuxSessionName?.trim()||Ws.trim())||void 0,rt=M?.cwd||(Gt?es.getState().sessions.get(Gt)?.cwd:void 0);window.dispatchEvent(new CustomEvent("new-terminal-session",{detail:{mode:G,tmuxSessionName:Re,cwd:rt,command:M?.command}}))},[Rr,Ws,Gt]),Rs=b.useCallback(async()=>{Jt(!0);try{const M=await vb();if(vn(M),!M.available){$t([]);return}const G=await yb();$t(G)}catch{vn({available:!1,version:null,reason:"tmux integration is unavailable with the current server build."}),$t([])}finally{Jt(!1)}},[]),Ml=b.useCallback(async M=>{jt(M),An(null);try{const{cleanedSessions:G}=await V7(M);for(const Re of G)window.dispatchEvent(new CustomEvent("close-terminal-session-by-backend",{detail:Re}));qe(null),await Rs()}catch(G){An(G instanceof Error?G.message:"Failed to kill tmux session")}finally{jt(null)}},[Rs]);b.useEffect(()=>{if(!_n)return;if(at.find(Re=>Re.name===_n&&(Re.connected||Re.boundFrontendSessionId))){ln(null);return}const G=setTimeout(()=>ln(null),1e4);return()=>clearTimeout(G)},[_n,at]);const xa=b.useCallback(M=>{window.dispatchEvent(new CustomEvent("close-terminal-session",{detail:M}))},[]),au=b.useCallback(M=>{const G=M??Gt;G&&window.dispatchEvent(new CustomEvent("open-terminal-split-chooser",{detail:G}))},[Gt]),Dl=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("set-terminal-split-direction",{detail:{sessionId:M,layout:G}}))},[]),lu=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("reorder-terminal-split-workspace",{detail:{workspaceId:M,sessionIds:G}}))},[]),sc=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("rename-terminal-split-workspace",{detail:{workspaceId:M,name:G}}))},[]),Mc=b.useCallback((M,G)=>{window.dispatchEvent(new CustomEvent("combine-terminal-split-sessions",{detail:{primaryId:M,secondaryId:G}}))},[]),ic=b.useCallback((M,G)=>{const Re=Ft.find(Pt=>Pt.id===M);if(!Re)return;const rt=Se.get(M);if(hW({mode:Re.mode,activeProgram:rt?.activeProgram??null,promptState:rt?.promptState??null,shellNames:rl})){xa({sessionId:M,source:"sidebar",closeMode:Re.mode==="tmux"?"destroy":"auto"});return}ir(G?{x:G.clientX,y:G.clientY}:null),en(M),An(null)},[Ft,Se,xa]);b.useEffect(()=>{if(!ke)return;const M=G=>{const Re=G.detail;Re==="new-session"?bi():Re==="close-session"?Gt&&ic(Gt):Re==="previous-session"||Re==="next-session"?window.dispatchEvent(new CustomEvent("cycle-terminal-session",{detail:{direction:Re==="next-session"?"next":"prev"}})):Re==="toggle-left-sidebar"?Js():Re==="toggle-right-sidebar"?Wi():Re==="previous-attention"?ga():Re==="next-attention"&&rc()};return window.addEventListener("termdock:native-command",M),()=>window.removeEventListener("termdock:native-command",M)},[Gt,ke,bi,ic,Js,Wi,rc,ga]);const ba=D.useMemo(()=>Ft.find(M=>M.id===dr)??null,[Ft,dr]),ya=D.useMemo(()=>{if(!ba)return"";const M=Se.get(ba.id);return gc(ba,M?.activeProgram??null,M?.cwd??null,rl,M?.shellTitle??null,M?.promptState??null).primary},[ba,Se]);b.useEffect(()=>{if(!Ve)return;let M=!1,G=!1;const Re=async()=>{if(!G)try{const Pt=await vb();if(M||vn(Pt),!Pt.available){M||$t([]);return}const Wt=await yb();M||$t(Wt)}catch{G=!0,M||(vn({available:!1,version:null,reason:"tmux integration is unavailable with the current server build."}),$t([]))}};Re();const rt=setInterval(()=>{Re()},4e3);return()=>{M=!0,clearInterval(rt)}},[Ve]);const yi=Kr??Rr,$a=yi==="shell",va=yi==="tmux"&&Rt.available,pl=D.useMemo(()=>by(at.map(M=>({...M,id:M.name})),M=>M.cwd??null,e("sidebar.ungrouped")),[at,e]),jl=(M,G,Re,rt=!1)=>{const Pt=M.id===Gt,Wt=M.id===pn,Pn=Se.get(M.id),{primary:Fr,secondary:Yr}=gc(M,Pn?.activeProgram??null,Pn?.cwd??null,rl,Pn?.shellTitle??null,Pn?.promptState??null),Xr=Sc(Pn?.cwd??null),Go=G?Yr??(Xr&&Xr!==Fr?Xr:null):null,Zr=Pn?.gitStatus,vi=`${Pn?.cwd||M.name}${Zr?`
242
+ ⎇ ${Zr.branch} +${Zr.added} −${Zr.removed}`:""}`,Ki=!!(Pn?.tuiProgress&&Pn.tuiProgress.state!=="remove"),Xi=Pn?.agentStatus==="working"||Ki?"var(--success)":Pn?.agentStatus==="waiting"||Pn?.agentNeedsReview?"var(--warning)":Pn?.inCopyMode?"var(--tmux)":null;if(Wt&&zn&&!se){const Ri=M.customName?M.name:Fr,Sr=(ds,si)=>{const Zi=si.trim();Zi?Zi!==Ri&&Gs(ds,Zi):qr(ds),tn(null)};return o.jsx("input",{ref:ds=>{Xn.current=ds},type:"text",defaultValue:Ri,className:"h-8 shrink-0 rounded-md bg-surface-elevated px-2 text-[12px] leading-none text-foreground outline-none ring-1 ring-primary/50 sm:h-8 min-w-[5rem]",style:{width:`${Math.max(Ri.length,5)}ch`},onKeyDown:ds=>{ds.key==="Enter"?Sr(M.id,ds.target.value):ds.key==="Escape"&&tn(null)},onBlur:ds=>Sr(M.id,ds.target.value)})}return o.jsx("div",{ref:Pt?gn:null,onContextMenu:Ri=>{Ri.preventDefault(),Qr({x:Ri.clientX,y:Ri.clientY}),sr(M.id)},...Nl(()=>Rl(M.id)),className:rt?`group relative inline-flex h-5 shrink-0 items-center rounded-sm text-[11px] leading-none transition ${Pt?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:bg-surface-elevated/40 hover:text-foreground"}`:`group relative inline-flex h-8 shrink-0 items-center rounded-md text-[12px] leading-none transition sm:h-8 ${Pt?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:bg-surface-elevated/50 hover:text-foreground"}`,style:!rt&&Pt&&Xi?{boxShadow:`inset 2px 0 0 0 ${Xi}`}:!rt&&Pt?{boxShadow:"inset 2px 0 0 0 rgb(var(--primary-rgb, 99 102 241))"}:void 0,title:vi,children:o.jsx("button",{type:"button",...Re??{},onClick:()=>hl(M.id),className:`inline-flex min-w-0 flex-1 items-center gap-1 overflow-hidden text-left ${rt?"px-1":"py-1 pl-1 pr-1.5 sm:pl-1.5 sm:pr-2"} ${Re?"cursor-grab active:cursor-grabbing":""}`,title:vi,children:o.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1 overflow-hidden",children:[o.jsxs("span",{className:"inline-flex shrink-0 items-center",children:[m7(M.mode,Pn),Pn?.agentResumeRecovered&&o.jsx(wf,{size:rt?9:10,className:"-ml-0.5 shrink-0 text-[color:var(--warning)]","aria-label":e("tab.resumeAgentAvailable")}),Ki&&!Pn?.agentStatus&&o.jsx(Fn,{size:rt?9:10,className:"-ml-0.5 shrink-0 animate-spin text-[color:var(--success)]"})]}),Go?o.jsxs("span",{className:"flex min-w-0 flex-col justify-center leading-[0.82rem] sm:leading-[0.85rem]",children:[o.jsx("span",{className:`whitespace-nowrap text-[11px] sm:text-[12px] ${Pn?.inCopyMode?"text-[color:var(--tmux)]":""}`,children:Fr}),o.jsx("span",{className:"truncate text-[9px] text-muted-foreground/80 sm:text-[9.5px]",children:Go})]}):o.jsx("span",{className:`whitespace-nowrap text-[11px] sm:text-[12px] ${Pn?.inCopyMode?"text-[color:var(--tmux)]":""}`,children:Fr})]})})})},Dc=()=>o.jsx(Bu,{droppableId:W2,type:"session",isDropDisabled:zn,children:(M,G)=>{const Re=st||G.isDraggingOver;return o.jsxs("div",{ref:M.innerRef,...M.droppableProps,className:"pointer-events-none fixed left-1/2 top-[42%] z-toast flex h-32 w-32 -translate-x-1/2 -translate-y-1/2 items-center justify-center",role:"status","aria-live":"polite","aria-hidden":!Qt,"data-mobile-session-destroy-target":"","data-active":Re?"true":"false",children:[o.jsxs("div",{className:`flex h-28 w-28 flex-col items-center justify-center gap-2 rounded-full border bg-surface-elevated/95 shadow-2xl backdrop-blur transition duration-200 ${Qt?Re?"scale-110 border-destructive bg-destructive text-destructive-foreground opacity-100":"scale-100 border-destructive/50 text-destructive opacity-100":"scale-75 border-transparent opacity-0"}`,children:[o.jsx($i,{size:28,strokeWidth:1.8}),o.jsx("span",{className:"px-2 text-center text-[11px] font-semibold leading-tight",children:e(Re?"tab.releaseToDestroy":"tab.dragToDestroy")})]}),M.placeholder]})}}),Ys=nn&&zn,jc=un&&zn,oc=px(Hn,Bt,Ys?vt:0),Yi=Ys?Ft.find(M=>M.id===Gt):null,Hs=Yi?Se.get(Yi.id):void 0,js=Yi?gc(Yi,Hs?.activeProgram??null,Hs?.cwd??null,rl,Hs?.shellTitle??null,Hs?.promptState??null).primary:"",_0=Ys&&Hs?Hs.agentStatus==="working"?"bg-gradient-to-r from-[rgb(var(--success-rgb)_/_0.08)] to-transparent":Hs.agentStatus==="waiting"?"bg-gradient-to-r from-[rgb(var(--warning-rgb)_/_0.14)] to-transparent":Hs.agentNeedsReview?"bg-gradient-to-r from-[rgb(var(--warning-rgb)_/_0.08)] to-transparent":Hs.inCopyMode?"bg-gradient-to-r from-[rgb(var(--tmux-rgb)_/_0.07)] to-transparent":"":"",ml=o.jsxs("div",{className:"w-full h-full flex flex-col app-chrome-bg text-foreground",children:[o.jsx("main",{className:"relative min-h-0 flex-1 overflow-visible px-0 pb-0 pt-0",children:o.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col overflow-visible app-chrome-bg",children:[o.jsxs("div",{className:`shrink-0 items-center gap-1 app-chrome-bg px-1 sm:px-1.5 transition-colors duration-500 ${Ys?"relative flex justify-end":"flex justify-between"} ${hn?"h-10 sm:h-10":"h-9 sm:h-10"} ${_0}`,children:[!Ys&&o.jsxs("button",{type:"button",onClick:Js,className:"relative inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-surface-elevated hover:text-foreground sm:h-8 sm:w-8","aria-label":e("tab.sessionsTitle"),title:`${e("tab.sessionsTitle")} · ${e("agent.aiRunning")}: ${ha.running} · ${e("agent.needsReview")}: ${ha.review}`,children:[o.jsx(mM,{size:14}),o.jsx(tq,{runningCount:ha.running,reviewCount:ha.review,className:"sm:hidden"})]}),Ys?o.jsx("div",{className:"absolute left-1/2 flex max-w-[40%] min-w-0 -translate-x-1/2 items-center justify-center gap-1.5 overflow-hidden",children:Yi?o.jsxs(o.Fragment,{children:[m7(Yi.mode,Hs),o.jsx("span",{className:`truncate text-[12px] font-medium ${Hs?.inCopyMode?"text-[color:var(--tmux)]":"text-foreground"}`,children:js}),Hs?.agentStatus==="working"&&o.jsx("span",{title:Hs?.agentMessage??void 0,children:o.jsx(Fn,{size:12,className:"shrink-0 animate-spin text-[color:var(--success)]"})}),Hs?.agentStatus==="waiting"&&o.jsx("span",{title:Hs?.agentMessage??void 0,children:o.jsx(Tm,{size:12,className:"shrink-0 animate-bounce-y text-[color:var(--warning)]"})}),!Hs?.agentStatus&&Hs?.agentNeedsReview&&o.jsx("span",{title:Hs?.agentMessage??void 0,children:o.jsx(eu,{size:13,className:"shrink-0 animate-pulse text-[color:var(--warning)]"})})]}):o.jsx("span",{className:"truncate px-2 text-[12px] text-muted-foreground",children:e("sidebar.sessions")})}):hn?o.jsxs(zm,{onDragStart:Ss,onDragUpdate:qn,onDragEnd:vr,children:[Dc(),o.jsx(Bu,{droppableId:"groups",type:"group",direction:"horizontal",children:M=>o.jsxs("div",{ref:M.innerRef,...M.droppableProps,className:"scrollbar-hidden flex h-full min-w-0 flex-1 items-center gap-1 overflow-x-auto overflow-y-hidden whitespace-nowrap px-0.5 py-0.5",style:{touchAction:"pan-x"},children:[Lo.map((G,Re)=>{let rt=0,Pt=0;for(const Yr of G.sessions){const Xr=Se.get(Yr.id);Xr?.agentStatus==="working"&&(rt+=1),(Xr?.agentStatus==="waiting"||Xr?.agentNeedsReview)&&(Pt+=1)}const Wt=G.sessions.some(Yr=>Yr.id===Gt),Pn=Kn.has(G.key),Fr=G.key==="";return o.jsx(Pu,{draggableId:`group-${G.key||"__ungrouped__"}`,index:Re,isDragDisabled:Fr,disableInteractiveElementBlocking:!0,children:(Yr,Xr)=>o.jsxs("div",{ref:Yr.innerRef,...Yr.draggableProps,className:`flex w-fit shrink-0 flex-col justify-center gap-px rounded-md py-0.5 px-1 ring-1 transition-colors ${Xr.isDragging?"bg-surface-elevated ring-primary/30 shadow-lg opacity-90":Wt?"bg-primary/[0.06] ring-primary/20":"bg-surface-2/40 ring-border/10"}`,children:[o.jsxs("button",{type:"button",...Fr?{}:Yr.dragHandleProps,onClick:()=>sn(G.key),className:`flex ${Pn?"":G.sessions.length>1?"w-0 min-w-full":""} items-center gap-0.5 rounded text-[9px] font-semibold uppercase tracking-[0.08em] leading-none transition hover:bg-surface-elevated/40 ${Fr?"":"cursor-grab active:cursor-grabbing"} ${Wt?"text-primary/80":"text-muted-foreground/55"}`,title:G.key||G.label,children:[o.jsx(_l,{size:9,className:`shrink-0 opacity-70 transition-transform ${Pn?"":"rotate-90"}`}),o.jsx("span",{className:"min-w-0 truncate",children:G.label}),rt>0&&o.jsx("span",{className:"ml-auto h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--success)]"}),Pt>0&&o.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--warning)] ${rt>0?"":"ml-auto"}`})]}),Pn?o.jsx("span",{className:"flex h-5 items-center text-[10px] leading-none text-muted-foreground/50",children:e("tab.sessionCount",{count:G.sessions.length})}):o.jsx(Bu,{droppableId:`group-sessions:${G.key}`,type:"session",direction:"horizontal",children:Go=>o.jsxs("div",{ref:Go.innerRef,...Go.droppableProps,className:"flex items-center gap-px",children:[G.sessions.map((Zr,vi)=>o.jsx(Pu,{draggableId:Zr.id,index:vi,disableInteractiveElementBlocking:!0,children:(Ki,Xi)=>o.jsx("div",{ref:Ki.innerRef,...Ki.draggableProps,className:`flex shrink-0 items-center ${Xi.isDragging?"opacity-70":""}`,children:jl(Zr,!1,Ki.dragHandleProps,!0)})},Zr.id)),Go.placeholder]})})]})},G.key||"__ungrouped__")}),M.placeholder,o.jsx("button",{type:"button",onClick:()=>bi(),className:"my-auto inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-primary/15 hover:text-primary active:scale-95","aria-label":e("tab.new"),title:e("tab.new"),children:o.jsx(Ao,{size:14})})]})})]}):o.jsxs(zm,{onDragStart:Ss,onDragUpdate:qn,onDragEnd:Vr,children:[Dc(),o.jsx(Bu,{droppableId:"tabs",type:"session",direction:"horizontal",children:M=>o.jsxs("div",{ref:M.innerRef,...M.droppableProps,className:"scrollbar-hidden flex h-full min-w-0 flex-1 items-center gap-1 overflow-x-auto overflow-y-hidden whitespace-nowrap",style:{touchAction:"pan-x"},children:[Ft.map((G,Re)=>G.id===pn?o.jsx(D.Fragment,{children:o.jsx(Pu,{draggableId:G.id,index:Re,isDragDisabled:!0,children:Pt=>o.jsx("div",{ref:Pt.innerRef,...Pt.draggableProps,className:"flex h-full items-center",children:jl(G,!0)})})},G.id):o.jsx(D.Fragment,{children:o.jsx(Pu,{draggableId:G.id,index:Re,disableInteractiveElementBlocking:!0,children:(Pt,Wt)=>o.jsx("div",{ref:Pt.innerRef,...Pt.draggableProps,className:`flex h-full shrink-0 items-center ${Wt.isDragging?"opacity-70":""}`,children:jl(G,!0,Pt.dragHandleProps)})})},G.id)),o.jsx("button",{type:"button",onClick:()=>bi(),className:"ml-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-primary/15 hover:text-primary active:scale-95","aria-label":e("tab.new"),title:e("tab.new"),children:o.jsx(Ao,{size:14})}),M.placeholder]})})]}),o.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[GI(ke)&&o.jsx(Nte,{bridge:ke,runningCount:ha.running,reviewCount:ha.review,labels:{switchService:e("desktopServices.switchService"),openServices:e("desktopServices.openServices"),current:e("agent.currentSession"),running:e("agent.aiRunning"),review:e("agent.needsReview"),idle:e("desktopServices.idle"),manageServices:e("desktopServices.manageServices")}}),!Ys&&ha.running>0&&o.jsx("span",{className:"hidden items-center gap-1 sm:inline-flex",children:o.jsx(T9,{count:ha.running,tone:"running",title:e("agent.aiRunning")})}),!Ys&&Ft.length>0&&o.jsx("span",{className:"inline-flex shrink-0 items-center px-1 text-[10px] uppercase tracking-[0.16em] text-muted-foreground sm:text-[11px]",title:`Session ${Nc+1} of ${Ft.length}`,children:Oa}),!jc&&o.jsx("button",{type:"button",onClick:Wi,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground ring-1 ring-border/10 transition hover:bg-surface-elevated hover:text-foreground sm:h-8 sm:w-8","aria-label":e("tab.explorerTitle"),title:e("tab.explorerTitle"),children:o.jsx(xM,{size:14})})]})]}),pa&&Vs&&Uo?.terminalSessionId&&o.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/15 bg-surface/80 px-3 py-2 animate-fade-in sm:px-4",role:"status","data-testid":"agent-resume-recovery-banner",children:[o.jsx("span",{className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-[rgb(var(--warning-rgb)_/_0.14)] text-[color:var(--warning)]",children:!qs?.error&&(qs?.status==="submitting"||qs?.status==="waiting")?o.jsx(Fn,{size:14,className:"animate-spin"}):o.jsx(wf,{size:14})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:e("tab.resumeAgentRecoveredTitle",{agent:Uo.agent?.displayName??"Agent"})}),o.jsx("div",{className:`truncate text-[10px] sm:text-[11px] ${qs?.error?"text-destructive":"text-muted-foreground"}`,children:qs?.error??(qs?.status==="submitting"?e("tab.resumeAgentSubmitting"):qs?.status==="waiting"?e("tab.resumeAgentWaiting"):e("tab.resumeAgentRecoveredHint"))})]}),o.jsx("button",{type:"button",disabled:!qs?.error&&(qs?.status==="submitting"||qs?.status==="waiting"),onClick:()=>{It(Vs.id,Uo.terminalSessionId)},className:"shrink-0 rounded-full bg-primary px-3 py-1.5 text-[11px] font-semibold text-primary-foreground transition hover:opacity-90 active:scale-95 disabled:cursor-wait disabled:opacity-60 sm:text-[12px]",children:qs?.error?e("common.retry"):e("tab.resumeAgentNow")}),o.jsx("button",{type:"button",onClick:()=>{es.getState().setAgentResumeRecovered(Vs.id,!1),an(M=>M?.sessionId===Vs.id?null:M)},className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-2 hover:text-foreground","aria-label":e("tab.resumeAgentLater"),title:e("tab.resumeAgentLater"),children:o.jsx(ts,{size:13})})]}),o.jsx("div",{ref:jn,className:"min-h-0 flex-1 flex overflow-hidden app-chrome-bg",children:o.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:o.jsx($Q,{terminalSettings:Dt,colorTheme:u,toolbarPresets:Je,showDebug:a,terminalFocusAvailable:Ii,defaultSessionMode:Rr,defaultTmuxSessionName:Ws,connectionPrioritySessionId:kr,connectionPriorityReady:ms,onSessionDataUpdate:As})})})]})}),o.jsx(oq,{reviewCount:ha.review,runningSessions:qi,activeSessionId:Gt,runningButtonEnabled:Lt,isDesktopLayout:zn,containerElement:lr}),Ve&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-drawer-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm animate-fade-in cursor-default",onClick:ut,"aria-label":e("settings.closeSettings")}),o.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"settings-dialog-title",className:"pointer-events-none fixed inset-0 z-drawer-panel flex items-stretch justify-center p-0 animate-fade-in sm:p-4 md:p-6",children:o.jsxs("div",{className:"pointer-events-auto flex h-full w-full max-w-5xl flex-col overflow-hidden bg-surface shadow-[0_28px_90px_var(--app-shadow-strong),0_14px_34px_var(--app-shadow-soft)] sm:max-h-[calc(100dvh-3rem)] sm:rounded-3xl sm:border sm:border-border/15",style:{paddingTop:r,paddingBottom:s},children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border/15 px-4 py-3 sm:px-6 sm:py-4",children:[o.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[o.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-full bg-primary/15 text-primary sm:h-9 sm:w-9",children:o.jsx(HM,{size:15})}),o.jsx("h2",{id:"settings-dialog-title",className:"text-[15px] font-semibold text-foreground sm:text-[16px]",children:e("settings.title")})]}),o.jsx("button",{type:"button",onClick:ut,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive","aria-label":e("common.close"),children:o.jsx(ts,{size:16})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto bg-background/25 px-3 py-3 sm:px-6 sm:py-5 md:px-8",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-2.5 py-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.font")}),o.jsx("button",{type:"button",onClick:()=>$e({fontSize:Math.max(8,Ut-1)}),className:"h-8 w-8 shrink-0 rounded-md bg-surface text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:"−"}),o.jsx("input",{type:"range",min:"8",max:"32",value:Ut,onChange:M=>$e({fontSize:parseInt(M.target.value,10)}),className:"min-w-0 flex-1","aria-label":e("settings.font")}),o.jsx("button",{type:"button",onClick:()=>$e({fontSize:Math.min(32,Ut+1)}),className:"h-8 w-8 shrink-0 rounded-md bg-surface text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:"+"}),o.jsxs("span",{className:"w-8 shrink-0 text-right text-[11px] tabular-nums text-muted-foreground",children:[Ut,"px"]})]}),o.jsx("div",{className:"space-y-1.5 rounded-xl bg-surface-2 px-2.5 py-2",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.render")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:["auto","webgl","canvas"].map(M=>{const G=_t===M;return o.jsx("button",{type:"button",onClick:()=>$e({rendererMode:M}),className:`flex-1 rounded px-2 py-1 text-[11px] font-medium transition ${G?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-surface-elevated"}`,children:e(M==="auto"?"settings.auto":M==="webgl"?"settings.webgl":"settings.canvas")},M)})})]})}),o.jsx("div",{className:"space-y-1.5 rounded-xl bg-surface-2 px-2.5 py-2",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.theme")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:[["dark",cM,e("settings.darkTheme")],["light",VM,e("settings.lightTheme")]].map(([M,G,Re])=>{const rt=u===M;return o.jsxs("button",{type:"button",onClick:()=>f(M),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition ${rt?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-surface-elevated"}`,children:[o.jsx(G,{size:12}),o.jsx("span",{children:Re})]},M)})})]})}),o.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-2.5 py-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.newTab")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:["shell","tmux"].map(M=>{const G=Rr===M,Re=M==="tmux"&&!Rt.available;return o.jsx("button",{type:"button",disabled:Re,onClick:()=>Nn(M,{userInitiated:!0}),className:`flex-1 rounded px-2 py-1 text-[11px] font-medium transition ${G?"bg-primary/20 text-primary":Re?"cursor-not-allowed text-muted-foreground/40":"text-muted-foreground hover:bg-surface-elevated"}`,title:Re?Rt.reason||e("settings.installTmuxHint"):void 0,children:e(M==="shell"?"settings.shell":"settings.tmux")},M)})})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>c(!a),className:`flex items-center justify-between rounded-xl px-3 py-2 text-[12px] transition ${a?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,children:[o.jsx("span",{className:"font-medium",children:e("settings.debug")}),o.jsx(xc,{checked:a,size:"sm"})]}),o.jsxs("button",{type:"button",onClick:async()=>{const M=!g;y(M);try{const G=await ta({preventSleep:M});y(G.preventSleep),S(G.networkAvailable),Y(G.localAccess),$n(bf,{preventSleep:G.preventSleep,networkAvailable:G.networkAvailable,localAccess:G.localAccess})}catch{y(!M)}},className:`flex items-center justify-between rounded-xl px-3 py-2 text-[12px] transition ${g?"bg-[rgb(var(--success-rgb)_/_0.15)] text-[color:var(--success)]":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:!v&&g?e("settings.noSleepUnavailable"):void 0,children:[o.jsx("span",{className:"font-medium truncate",children:e("settings.noSleep")}),o.jsx(xc,{checked:g,size:"sm"})]})]})]}),o.jsxs("button",{type:"button",onClick:()=>B(!0),className:"mt-3 flex w-full items-center justify-between gap-2 rounded-xl bg-surface-2 px-3 py-2.5 text-left text-[13px] transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[o.jsx(g8,{size:14,className:A?"shrink-0 text-primary":"shrink-0 text-muted-foreground"}),o.jsxs("span",{className:"min-w-0",children:[o.jsx("span",{className:"block font-medium text-foreground",children:e("settings.notifications")}),o.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:e(A?L&&j?"settings.notificationsBothOnSummary":L?"settings.notificationsAiOnSummary":j?"settings.notificationsExitOnSummary":"settings.notificationsNoEventsSummary":"settings.notificationsOffSummary")})]})]}),o.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[o.jsx("span",{children:e(A?"common.on":"common.off")}),o.jsx("span",{children:"›"})]})]}),o.jsxs("details",{className:"mt-3 rounded-xl bg-surface-2 px-3 py-3",open:!1,children:[o.jsxs("summary",{className:"flex cursor-pointer items-start justify-between gap-2 list-none",children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground/90",children:e("settings.localAccess")}),o.jsx("div",{className:"mt-0.5 text-[10px] text-muted-foreground",children:e("settings.localAccessHint")})]}),o.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] ${H.status==="active"?"bg-primary/15 text-primary":"bg-surface text-muted-foreground"}`,children:H.status})]}),o.jsxs("div",{className:"mt-3 flex items-center overflow-hidden rounded-lg bg-surface ring-1 ring-border/10 focus-within:ring-primary/40",children:[o.jsx("input",{value:V,onChange:M=>fe(M.target.value.toLowerCase()),className:"min-w-0 flex-1 bg-transparent px-2.5 py-2 text-[12px] text-foreground outline-none",placeholder:"jovn",spellCheck:!1}),o.jsx("span",{className:"shrink-0 border-l border-border/10 px-2.5 py-2 text-[11px] text-muted-foreground",children:".termdock.local"})]}),o.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[o.jsx("button",{type:"button",disabled:X,onClick:()=>{Ct()},className:"rounded-full bg-primary/15 px-3 py-1.5 text-[11px] font-medium text-primary transition hover:bg-primary/25 disabled:opacity-50",children:e(X?"settings.saving":"common.save")}),o.jsx("button",{type:"button",disabled:X,onClick:()=>{On()},className:"rounded-full bg-surface px-3 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated disabled:opacity-50",children:e("settings.resetAutoName")})]}),o.jsxs("div",{className:"mt-3 space-y-1.5 text-[11px]",children:[H.url&&o.jsxs("button",{type:"button",onClick:()=>{Ae(H.url,"lan")},className:"flex w-full items-center justify-between gap-2 rounded-lg bg-surface px-2.5 py-2 text-left text-muted-foreground transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"min-w-0 truncate",children:["Branded: ",H.url]}),o.jsx("span",{className:"shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium",children:ae==="lan"?"Copied":e("common.copy")})]}),H.interfaces.length>0&&o.jsxs("details",{className:"rounded-lg bg-surface px-2.5 py-2 text-muted-foreground",open:!1,children:[o.jsx("summary",{className:"cursor-pointer text-[11px] font-medium text-foreground/80",children:"IP fallback addresses"}),o.jsx("div",{className:"mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2",children:H.interfaces.map(M=>{const G=M.url??`${H.httpsEnabled?"https":"http"}://${M.address}:9834`;return o.jsxs("div",{className:"rounded-lg bg-surface-2 p-2",children:[o.jsxs("div",{className:"text-[11px] font-medium text-foreground/85",children:[M.label," (",M.name,")"]}),o.jsx("div",{className:"mt-0.5 text-[10px] text-muted-foreground",children:M.address}),M.qrDataUrl&&o.jsx("div",{className:"mt-2 inline-block rounded-lg bg-[var(--background)] p-1.5",children:o.jsx("img",{src:M.qrDataUrl,alt:`QR code for ${G}`,className:"h-28 w-28"})}),o.jsxs("button",{type:"button",onClick:()=>{Ae(G,`ip-${M.address}`)},className:"mt-2 flex w-full items-center justify-between gap-2 rounded-md bg-surface px-2 py-1.5 text-left text-[11px] transition hover:bg-surface-elevated",children:[o.jsx("span",{className:"min-w-0 truncate",children:G}),o.jsx("span",{className:"shrink-0 text-[10px]",children:ae===`ip-${M.address}`?"Copied":e("common.copy")})]})]},`${M.name}-${M.address}`)})})]}),H.onboardingUrl&&o.jsxs("button",{type:"button",onClick:()=>{Ae(H.onboardingUrl,"setup")},className:"flex w-full items-center justify-between gap-2 rounded-lg bg-surface px-2.5 py-2 text-left text-muted-foreground transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"min-w-0 truncate",children:[e("settings.onboardingUrl"),": ",H.onboardingUrl]}),o.jsx("span",{className:"shrink-0 rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium",children:ae==="setup"?"Copied":e("common.copy")})]}),o.jsxs("div",{className:"text-muted-foreground",children:[H.httpsEnabled?e("settings.httpsActive"):e("settings.httpsInactive"),!H.caAvailable&&` · ${e("settings.caMissing")}`]}),H.reason&&o.jsx("div",{className:"text-[color:var(--warning)]",children:H.reason}),we&&o.jsx("div",{className:"text-destructive",children:we})]})]}),o.jsx(Rte,{state:z,pending:pe,onCheck:()=>{Ee()},onConfirmRestart:()=>{Me()},desktopState:be?J:void 0,desktopPending:lt,onCheckDesktop:()=>{Ge()},onInstallDesktop:()=>{dt()}}),ke&&o.jsxs("div",{className:"mt-3 overflow-hidden rounded-xl bg-surface-2",children:[o.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border/10 px-3 py-3",children:[o.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[o.jsx("span",{className:"mt-0.5 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/15 text-primary",children:o.jsx(MR,{size:15})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[12px] font-medium text-foreground",children:e("settings.desktopTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:oe?`App ${oe.appVersion} · CLI ${oe.bundledCliVersion}`:e("settings.desktopStatusLoading")})]})]}),o.jsx("span",{className:"shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary",children:"macOS"})]}),o.jsxs("div",{className:"grid grid-cols-1 gap-px bg-border/10 sm:grid-cols-3",children:[o.jsxs("button",{type:"button",onClick:()=>{ke.showConnectionCenter()},className:"flex items-center gap-2 bg-surface-2 px-3 py-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:[o.jsx(GR,{size:13,className:"shrink-0 text-primary"}),e("settings.desktopSwitchService")]}),o.jsxs("button",{type:"button",onClick:()=>{Fe(null),ke.installCli().then(M=>{he(M),Fe(e("settings.desktopCliUpdated"))}).catch(M=>Fe(M instanceof Error?M.message:String(M)))},className:"flex items-center gap-2 bg-surface-2 px-3 py-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:[o.jsx(La,{size:13,className:"shrink-0 text-primary"}),e("settings.desktopInstallCli")]}),o.jsxs("button",{type:"button",onClick:()=>{Fe(null),ke.revealDataDirectory().catch(M=>Fe(M instanceof Error?M.message:String(M)))},className:"flex items-center gap-2 bg-surface-2 px-3 py-2.5 text-left text-[11px] text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:[o.jsx(Jd,{size:13,className:"shrink-0 text-primary"}),e("settings.desktopOpenDataDirectory")]})]}),ge&&o.jsx("div",{className:"border-t border-border/10 px-3 py-2 text-[10px] text-muted-foreground",children:ge})]}),o.jsxs("div",{className:"mt-3 flex gap-2",children:[o.jsxs("button",{type:"button",onClick:()=>{Ho(null),bi({mode:"shell"}),ut()},className:`flex min-w-0 items-center justify-center gap-1.5 rounded-xl text-[13px] font-semibold transition active:scale-[0.98] ${$a?"flex-[2.7] bg-primary px-3 py-2.5 text-primary-foreground ring-1 ring-primary/40 shadow-md shadow-primary/25 hover:bg-primary/90":"flex-[0.78] bg-surface-2 px-2 py-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:e(Kr==="shell"?"sidebar.confirmNewShell":"settings.shell"),children:[o.jsx(Ao,{size:14,className:$a?"shrink-0":"hidden"}),o.jsx(La,{size:12}),o.jsx("span",{className:$a?"whitespace-nowrap":"hidden",children:e(Kr==="shell"?"sidebar.confirmNewShell":"settings.shell")})]}),o.jsxs("button",{type:"button",disabled:!Rt.available,onClick:()=>{Rt.available&&(Ho(null),bi({mode:"tmux"}),ut())},className:`flex min-w-0 items-center justify-center gap-1.5 rounded-xl text-[13px] font-semibold transition active:scale-[0.98] ${Rt.available?va?"flex-[2.7] bg-primary px-3 py-2.5 text-primary-foreground ring-1 ring-primary/40 shadow-md shadow-primary/25 hover:bg-primary/90":"flex-[0.78] bg-surface-2 px-2 py-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground":"flex-1 bg-surface-2/50 text-muted-foreground/50 cursor-not-allowed"}`,title:Rt.available?e(Kr==="tmux"?"sidebar.confirmNewTmux":"settings.tmux"):Rt.reason||e("settings.installTmuxHint"),children:[o.jsx(Ao,{size:14,className:va?"shrink-0":"hidden"}),o.jsx(Fu,{size:12}),o.jsx("span",{className:va?"whitespace-nowrap":"hidden",children:e(Kr==="tmux"?"sidebar.confirmNewTmux":"settings.tmux")})]})]}),(Rt.available||at.length>0)&&o.jsxs("details",{className:"mt-3 group rounded-xl bg-surface-2 [&[open]]:bg-surface-2",children:[o.jsxs("summary",{className:"flex cursor-pointer items-center justify-between rounded-xl px-3 py-2.5 text-[13px] hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx("span",{className:`inline-flex h-2 w-2 rounded-full ${Rt.available?"bg-primary":"bg-destructive"}`}),o.jsx("span",{className:"font-medium",children:e("settings.tmuxServer")}),o.jsx("span",{className:"text-[11px] text-muted-foreground",children:Rt.available?e("settings.sessions",{n:at.length}):e("settings.tmuxUnavailable")})]}),o.jsx("button",{type:"button",onClick:M=>{M.preventDefault(),Rs()},disabled:Ot,className:"inline-flex h-7 w-7 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-50","aria-label":e("settings.refresh"),children:o.jsx(Us,{size:12,className:Ot?"animate-spin":""})})]}),o.jsx("div",{className:"px-2 pb-2",children:Rt.available?at.length===0?o.jsx("p",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:e("settings.noTmuxSessions")}):o.jsxs("div",{className:"space-y-2",children:[pl.map(M=>o.jsxs("div",{className:"space-y-1",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-2 px-1.5 py-1 text-[10px] text-muted-foreground",children:[o.jsx(nu,{size:11,className:"shrink-0 text-muted-foreground/70"}),o.jsx("span",{className:"shrink-0 font-medium text-foreground/75",children:M.label}),o.jsx("span",{className:"shrink-0 text-muted-foreground/70",children:e("settings.sessions",{n:M.sessions.length})}),M.key&&o.jsx("span",{className:"min-w-0 truncate text-muted-foreground/60",children:M.key})]}),M.sessions.map(G=>{const Re=G.boundFrontendSessionId??null,rt=!!(G.connected||Re),Pt=Re?Ft.find(Sr=>Sr.id===Re)??null:null,Wt=G.friendlyName?.trim()||null,Pn=G.label&&G.label!==G.name?G.label:null,Fr=Wt||Pn||G.name,Yr=Wt||Pn?`tmux:${G.name}`:null,Xr=G.clientCount&&G.clientCount>0?t==="zh"?`网页连接 ${G.clientCount}`:`Web clients ${G.clientCount}`:null,Go=G.attached>0?t==="zh"?`原生 tmux ${G.attached}`:`Native tmux ${G.attached}`:null,Zr=[Yr,rt?G.restorable?e("settings.restorable"):e("settings.attached"):null,Xr,Go].filter(Sr=>!!Sr),vi=[e("settings.windows",{n:G.windows}),G.createdAt?new Date(G.createdAt).toLocaleDateString():null].filter(Sr=>!!Sr),Ki=ar===G.name,Xi=ct===G.name,Ri=_n===G.name;return o.jsxs("div",{className:`flex items-start gap-2 rounded-lg px-2.5 py-2 ${Ki?"bg-destructive/10 ring-1 ring-destructive/40":"bg-surface"}`,children:[o.jsx(Fu,{size:13,className:rt?"mt-0.5 shrink-0 text-primary":"mt-0.5 shrink-0 text-muted-foreground"}),o.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[o.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[o.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:Fr}),G.friendlyName&&o.jsx("span",{className:"shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[9px] font-medium text-primary",children:t==="zh"?"自定义":"custom"})]}),Zr.length>0&&o.jsx("div",{className:"flex min-w-0 flex-wrap gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground",children:Zr.map(Sr=>o.jsx("span",{className:"max-w-full truncate",children:Sr},Sr))}),(G.program||G.cwd)&&o.jsxs("div",{className:"grid min-w-0 gap-0.5 text-[10px] text-muted-foreground",children:[G.program&&o.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[o.jsx(ON,{size:10,className:"shrink-0 text-muted-foreground/70"}),o.jsx("span",{className:"truncate text-foreground/75",children:G.program})]}),G.cwd&&o.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[o.jsx(nu,{size:10,className:"shrink-0 text-muted-foreground/70"}),o.jsx("span",{className:"truncate",children:G.cwd})]})]}),o.jsx("div",{className:"flex min-w-0 flex-wrap gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground/80",children:vi.map(Sr=>o.jsxs("span",{className:"inline-flex items-center gap-1",children:[o.jsx(dN,{size:10,className:"shrink-0 text-muted-foreground/60"}),Sr]},Sr))})]}),Ki?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",disabled:Xi,onClick:()=>{Ml(G.name)},className:"shrink-0 rounded-full bg-destructive/90 px-2.5 py-1 text-[11px] font-medium text-destructive-foreground transition hover:bg-destructive disabled:opacity-50",children:Xi?"…":e("settings.destroy")}),o.jsx("button",{type:"button",disabled:Xi,onClick:()=>{qe(null),An(null)},className:"shrink-0 rounded-full bg-surface-2 px-2.5 py-1 text-[11px] font-medium text-foreground transition hover:bg-surface-elevated",children:e("common.cancel")})]}):o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:()=>{Pt?hl(Pt.id):(ln(G.name),bi({mode:"tmux",tmuxSessionName:G.name}))},disabled:Ri,className:`shrink-0 inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-[11px] font-medium transition disabled:opacity-50 ${rt?"bg-surface text-foreground hover:bg-surface-elevated":Ri?"bg-primary/10 text-primary":"bg-primary/15 text-primary hover:bg-primary/25"}`,children:Ri?o.jsxs(o.Fragment,{children:[o.jsx(Fn,{size:10,className:"animate-spin"}),e("settings.attaching")]}):e(rt?"settings.attached":"settings.attach")}),o.jsx("button",{type:"button",disabled:Xi,onClick:()=>{An(null),qe(G.name)},className:"shrink-0 inline-flex h-7 w-7 items-center justify-center rounded-full text-muted-foreground transition hover:bg-destructive/15 hover:text-destructive","aria-label":`Kill tmux session ${G.name}`,children:o.jsx($i,{size:12})})]})]},G.name)})]},M.key||"__ungrouped_tmux__")),dn&&o.jsx("p",{className:"px-2 text-[11px] text-destructive",children:dn})]}):o.jsx("p",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:Rt.reason||e("settings.installTmuxHint")})})]}),o.jsxs("button",{type:"button",onClick:()=>$s(!0),className:"mt-2 flex w-full items-center justify-between gap-2 rounded-xl bg-surface-2 px-3 py-2.5 text-left text-[13px] transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(GN,{size:14,className:"text-muted-foreground"}),o.jsx("span",{className:"font-medium text-foreground",children:e("settings.keyboardToolbar")})]}),o.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[o.jsx("span",{children:e("settings.sessions",{n:Je.length})}),o.jsx("span",{children:"›"})]})]}),o.jsxs("button",{type:"button",onClick:()=>Ir(!0),className:"mt-2 flex w-full items-center justify-between gap-2 rounded-xl bg-surface-2 px-3 py-2.5 text-left text-[13px] transition hover:bg-surface-elevated",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(bg,{size:14,className:"text-muted-foreground"}),o.jsx("span",{className:"font-medium text-foreground",children:e("settings.aiAgentDetection")})]}),o.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[o.jsx("span",{children:"hooks"}),o.jsx("span",{children:"›"})]})]}),o.jsxs("div",{className:"mt-3 flex items-center gap-2 rounded-xl bg-surface-2 px-2.5 py-2",children:[o.jsx("span",{className:"text-[12px] font-medium text-foreground/90 w-14 shrink-0",children:e("settings.language")}),o.jsx("div",{className:"flex flex-1 items-center gap-1 rounded-md bg-surface p-0.5",children:[{code:"en",label:"English"},{code:"zh",label:"中文"}].map(M=>{const G=t===M.code;return o.jsx("button",{type:"button",onClick:()=>n(M.code),className:`flex-1 rounded px-2 py-1 text-[11px] font-medium transition ${G?"bg-primary/20 text-primary":"text-muted-foreground hover:bg-surface-elevated"}`,children:M.label},M.code)})})]}),o.jsxs("button",{type:"button",onClick:async()=>{try{await $E()}catch{}window.dispatchEvent(new CustomEvent("auth:unauthorized"))},className:"mt-3 flex w-full items-center justify-center gap-2 rounded-xl bg-destructive/10 px-3 py-2.5 text-[13px] font-medium text-destructive transition hover:bg-destructive/20 active:scale-[0.98]",children:[o.jsx(ZM,{size:14}),e("settings.signOut")]})]})]})})]}),ba&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-menu-backdrop bg-[var(--app-backdrop-soft)] backdrop-blur-sm cursor-default animate-fade-in",onClick:()=>{en(null),ir(null),An(null)},"aria-label":e("common.close")}),o.jsxs("div",{className:`fixed z-menu-panel rounded-2xl bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in ${Vt&&zn?"":"inset-x-3 bottom-6 mx-auto max-w-sm sm:bottom-auto sm:top-[15%]"}`,style:Vt&&zn?{...u7(Vt),paddingBottom:s}:{paddingBottom:s},children:[o.jsxs("div",{className:"border-b border-border/15 px-4 py-3",children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.closeChooserTitle")}),o.jsx("div",{className:"mt-0.5 truncate text-[14px] font-medium text-foreground",children:ya}),o.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground/80",children:e("tab.closeChooserDescription")})]}),o.jsxs("div",{className:"flex flex-col py-1",children:[o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:ba.id,source:"sidebar",closeMode:"detach"}),en(null),ir(null),An(null)},className:"flex items-center gap-3 px-4 py-3 text-left text-[13px] text-foreground transition hover:bg-surface-2",children:[o.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground",children:o.jsx(La,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.detach")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.detachHint")})]})]}),o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:ba.id,source:"sidebar",closeMode:"destroy"}),en(null),ir(null)},className:"flex items-center gap-3 px-4 py-3 text-left text-[13px] text-destructive transition hover:bg-destructive/10",children:[o.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-destructive/15 text-destructive",children:o.jsx($i,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.destroySession")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.destroySessionHint")})]})]}),dn&&o.jsx("p",{className:"px-4 py-2 text-[11px] text-destructive",children:dn})]}),o.jsx("div",{className:"border-t border-border/15 px-3 py-2",children:o.jsx("button",{type:"button",onClick:()=>{en(null),ir(null),An(null)},className:"w-full rounded-full bg-surface-2 px-3 py-2 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")})})]})]}),cn&&(()=>{const M=Ft.find(Xr=>Xr.id===cn);if(!M)return null;const G=Se.get(M.id),{primary:Re}=gc(M,G?.activeProgram??null,G?.cwd??null,rl),rt=zn,Pt=rt?u7(ps):{paddingBottom:s},Wt=rt?"fixed z-menu-panel overflow-y-auto overflow-x-hidden rounded-lg bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in":"fixed inset-x-3 bottom-6 z-menu-panel mx-auto max-w-sm rounded-2xl bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in sm:bottom-auto sm:top-[15%]",Pn=rt?"border-b border-border/15 px-3 py-2":"border-b border-border/15 px-4 py-3",Fr=rt?"flex items-center gap-2 px-3 py-2 text-left text-[12px] transition":"flex items-center gap-3 px-4 py-3 text-left text-[13px] transition",Yr=rt?"inline-flex h-6 w-6 items-center justify-center rounded-md":"inline-flex h-7 w-7 items-center justify-center rounded-full";return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:`fixed inset-0 z-menu-backdrop cursor-default animate-fade-in ${rt?"bg-transparent":"bg-[var(--app-backdrop-soft)] backdrop-blur-sm"}`,onClick:Ln,"aria-label":"Close menu"}),o.jsxs("div",{className:Wt,style:Pt,children:[o.jsxs("div",{className:Pn,children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.session")}),o.jsx("div",{className:"mt-0.5 truncate text-[14px] font-medium text-foreground",children:Re}),G?.cwd&&o.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground/80",children:G.cwd})]}),o.jsxs("div",{className:"flex flex-col py-1",children:[o.jsxs("button",{type:"button",onClick:()=>{const Xr=ps;Ln(),_e(Xr),tn(M.id)},className:`${Fr} text-foreground hover:bg-surface-2`,children:[o.jsx("span",{className:`${Yr} bg-primary/15 text-primary`,children:o.jsx(S8,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.rename")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.renameHint")})]})]}),o.jsxs("button",{type:"button",disabled:!G?.cwd,onClick:()=>{zo(M.id),Ln()},className:`${Fr} ${G?.cwd?"text-foreground hover:bg-surface-2":"text-muted-foreground/50 cursor-not-allowed"}`,children:[o.jsx("span",{className:`${Yr} bg-surface-2 text-muted-foreground`,children:o.jsx(VN,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.copyCwd")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.copyCwdHint")})]}),je&&je===G?.cwd&&o.jsx("span",{className:"ml-auto text-[11px] text-primary",children:e("tab.copied")})]}),G?.agentNativeSessionId&&G.agentStatus!=="working"&&G.agentStatus!=="waiting"&&G.terminalSessionId&&o.jsxs("button",{type:"button",onClick:()=>{const Xr=G.terminalSessionId;Xr&&(Ln(),It(M.id,Xr))},className:`${Fr} text-foreground hover:bg-surface-2`,children:[o.jsx("span",{className:`${Yr} bg-[rgb(var(--success-rgb)_/_0.14)] text-[color:var(--success)]`,children:o.jsx(wf,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"block font-medium",children:[e("tab.resumeAgent"),G.agent?.displayName?` · ${G.agent.displayName}`:""]}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.resumeAgentHint")})]})]}),o.jsx("div",{className:"my-1 border-t border-border/15"}),M.mode==="tmux"?o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:M.id,source:"tab-menu",closeMode:"detach"}),Ln(),An(null)},className:`${Fr} text-foreground hover:bg-surface-2`,children:[o.jsx("span",{className:`${Yr} bg-surface-2 text-muted-foreground`,children:o.jsx(La,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.detach")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.detachHint")})]})]}),o.jsxs("button",{type:"button",onClick:()=>{xa({sessionId:M.id,source:"tab-menu",closeMode:"destroy"}),Ln()},className:`${Fr} text-destructive hover:bg-destructive/10`,children:[o.jsx("span",{className:`${Yr} bg-destructive/15 text-destructive`,children:o.jsx($i,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.destroySession")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.destroySessionHint")})]})]})]}):o.jsxs("button",{type:"button",onClick:()=>{Ln(),xa({sessionId:M.id,source:"tab-menu",closeMode:"auto"})},className:`${Fr} text-destructive hover:bg-destructive/10`,children:[o.jsx("span",{className:`${Yr} bg-destructive/15 text-destructive`,children:o.jsx(ts,{size:14})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block font-medium",children:e("tab.close")}),o.jsx("span",{className:"block text-[11px] text-muted-foreground",children:e("tab.closeHint")})]})]}),!rt&&o.jsx("button",{type:"button",className:"flex items-center justify-center px-4 py-2 text-[11px] text-muted-foreground/80 transition hover:text-foreground",onClick:()=>{Ln()},children:e("tab.longPressTip")})]}),!rt&&o.jsx("div",{className:"border-t border-border/15 px-3 py-2",children:o.jsx("button",{type:"button",onClick:Ln,className:"w-full rounded-full bg-surface-2 px-3 py-2 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")})})]})]})})(),pn&&se&&zn&&(()=>{const M=Ft.find(Zr=>Zr.id===pn);if(!M)return null;const G=Se.get(M.id),{primary:Re}=gc(M,G?.activeProgram??null,G?.cwd??null,rl,G?.shellTitle??null,G?.promptState??null),rt=M.customName?M.name:Re,Pt=Zr=>{const vi=Zr.trim();vi?vi!==rt&&Gs(M.id,vi):qr(M.id),tn(null),_e(null)},Wt=300,Pn=160,Fr=se.x,Yr=se.y,Xr=Math.min(Math.max(Fr-Wt/2,12),window.innerWidth-Wt-12),Go=Yr+Pn+20>window.innerHeight?Math.max(Yr-Pn-12,12):Yr+12;return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-menu-backdrop cursor-default animate-fade-in bg-transparent",onClick:()=>{tn(null),_e(null)},"aria-label":e("common.cancel")}),o.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":e("tab.rename"),className:"fixed z-menu-panel w-[300px] rounded-xl bg-surface-elevated border border-border/15 shadow-[0_12px_36px_var(--app-shadow-soft)] animate-fade-in",style:{left:`${Xr}px`,top:`${Go}px`},children:[o.jsxs("div",{className:"border-b border-border/15 px-3 py-2.5",children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.rename")}),o.jsx("div",{className:"mt-0.5 truncate text-[13px] font-medium text-foreground",children:Re}),G?.cwd&&o.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground/70",children:G.cwd})]}),o.jsxs("form",{className:"px-3 py-2.5",onSubmit:Zr=>{Zr.preventDefault();const vi=new FormData(Zr.currentTarget).get("session-name");Pt(typeof vi=="string"?vi:"")},children:[o.jsx("input",{ref:Zr=>{Xn.current=Zr,Zr&&!Gr.current&&(Gr.current=!0,Zr.focus({preventScroll:!0}),Zr.select())},type:"text",name:"session-name",defaultValue:rt,placeholder:e("tab.renamePlaceholder"),autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:"w-full rounded-lg bg-surface-2 px-3 py-2 text-[13px] leading-snug text-foreground outline-none ring-1 ring-primary/40 placeholder:text-muted-foreground/60 focus:ring-primary/70",onKeyDown:Zr=>{Zr.key==="Escape"&&(Zr.stopPropagation(),tn(null),_e(null))}}),o.jsxs("div",{className:"mt-2.5 flex gap-2",children:[o.jsx("button",{type:"button",onClick:()=>{tn(null),_e(null)},className:"flex-1 rounded-full bg-surface-2 px-3 py-1.5 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")}),o.jsx("button",{type:"submit",className:"flex-1 rounded-full bg-primary px-3 py-1.5 text-[12px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.97]",children:e("common.save")})]})]})]})]})})(),pn&&!zn&&(()=>{const M=Ft.find(Wt=>Wt.id===pn);if(!M)return null;const G=Se.get(M.id),{primary:Re}=gc(M,G?.activeProgram??null,G?.cwd??null,rl,G?.shellTitle??null,G?.promptState??null),rt=M.customName?M.name:Re,Pt=Wt=>{const Pn=Wt.trim();Pn?Pn!==rt&&Gs(M.id,Pn):qr(M.id),tn(null)};return o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-menu-backdrop cursor-default animate-fade-in bg-[var(--app-backdrop-soft)] backdrop-blur-sm",onClick:()=>tn(null),"aria-label":e("common.cancel")}),o.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":e("tab.rename"),className:"fixed inset-x-3 z-menu-panel mx-auto max-w-sm rounded-2xl bg-surface-elevated border border-border/15 shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",style:{top:`calc(${r} + 3.5rem)`},children:[o.jsxs("div",{className:"border-b border-border/15 px-4 py-3",children:[o.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:e("tab.session")}),o.jsx("div",{className:"mt-0.5 text-[14px] font-medium text-foreground",children:e("tab.rename")})]}),o.jsxs("form",{className:"px-4 py-3",onSubmit:Wt=>{Wt.preventDefault();const Pn=new FormData(Wt.currentTarget).get("session-name");Pt(typeof Pn=="string"?Pn:"")},children:[o.jsx("input",{ref:Wt=>{Xn.current=Wt,Wt&&!Gr.current&&(Gr.current=!0,Wt.focus({preventScroll:!0}),Wt.select())},type:"text",name:"session-name",defaultValue:rt,placeholder:e("tab.renamePlaceholder"),autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,enterKeyHint:"done",className:"w-full rounded-lg bg-surface-2 px-3 py-2.5 text-[16px] leading-snug text-foreground outline-none ring-1 ring-primary/40 placeholder:text-muted-foreground/60 focus:ring-primary/70",onKeyDown:Wt=>{Wt.key==="Escape"&&(Wt.stopPropagation(),tn(null))}}),o.jsxs("div",{className:"mt-3 flex gap-2",children:[o.jsx("button",{type:"button",onClick:()=>tn(null),className:"flex-1 rounded-full bg-surface-2 px-3 py-2 text-[12px] font-medium text-muted-foreground transition hover:bg-surface hover:text-foreground",children:e("common.cancel")}),o.jsx("button",{type:"submit",className:"flex-1 rounded-full bg-primary/20 px-3 py-2 text-[12px] font-medium text-primary transition hover:bg-primary/30",children:e("common.save")})]})]})]})]})})(),xi&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:()=>B(!1)}),o.jsxs("div",{className:"fixed left-[max(0.75rem,env(safe-area-inset-left,0px))] right-[max(0.75rem,env(safe-area-inset-right,0px))] top-[max(1.5rem,env(safe-area-inset-top,0px))] bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto flex max-w-xl flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)] sm:top-[10%] sm:bottom-auto sm:max-h-[80vh]",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-4 py-4 sm:px-6",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.notifications")}),o.jsx("h2",{className:"section-title mt-1",children:e("settings.notificationsTitle")})]}),o.jsx("button",{type:"button",onClick:()=>B(!1),className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":"Close notifications settings",children:o.jsx(ts,{size:18})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-6",children:[o.jsx("p",{className:"text-[12px] leading-relaxed text-muted-foreground",children:e("settings.notificationsPageHint")}),o.jsxs("div",{className:"mt-4 rounded-2xl bg-surface-2 p-3",children:[o.jsxs("div",{className:"flex items-start justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsMaster")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:C==="denied"?e("settings.notificationsDenied"):Du()?e("settings.notificationsMasterHint"):e("settings.notificationsUnsupported")}),Du()&&!u8()&&o.jsx("div",{className:"mt-1.5 text-[11px] leading-relaxed text-[var(--warning)]",children:e("settings.notificationsIOSInstallHint")})]}),o.jsx("button",{type:"button",onClick:()=>{Ec()},disabled:!Du()||C==="denied",className:"shrink-0 transition disabled:cursor-not-allowed","aria-pressed":A,children:o.jsx(xc,{checked:A,disabled:!Du()||C==="denied"})})]}),o.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[11px]",children:[o.jsxs("span",{className:`rounded-full px-2 py-0.5 ${C==="granted"?"bg-primary/15 text-primary":"bg-surface text-muted-foreground"}`,children:[e("settings.notificationsPermission"),": ",lo()?e("settings.notificationsPermissionSystem"):C]}),o.jsx("button",{type:"button",disabled:!A||C!=="granted"||K==="checking",onClick:()=>{Ic()},className:"rounded-full bg-surface px-3 py-1.5 font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",children:e(K==="checking"?"settings.notificationsTestChecking":"settings.notificationsTest")}),lo()?.openNotificationSettings&&o.jsx("button",{type:"button",onClick:()=>{lo()?.openNotificationSettings?.()},className:"rounded-full bg-surface px-3 py-1.5 font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:e("settings.notificationsOpenSystemSettings")})]}),K!=="idle"&&K!=="checking"&&o.jsx("div",{className:`mt-2 text-[11px] leading-relaxed ${K==="delivered"?"text-primary":"text-[var(--warning)]"}`,children:e(K==="delivered"?"settings.notificationsTestDelivered":"settings.notificationsTestFailed")})]}),o.jsxs("div",{className:"mt-4 rounded-2xl bg-surface-2 p-3",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsAlertStyle")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:e("settings.notificationsAlertStyleHint")}),o.jsx("div",{className:"mt-3 grid grid-cols-3 gap-1 rounded-xl bg-surface p-1",children:[["normal",e("settings.notificationsStyleNormal"),e("settings.notificationsStyleNormalHint")],["quiet",e("settings.notificationsStyleQuiet"),e("settings.notificationsStyleQuietHint")],["persistent",e("settings.notificationsStylePersistent"),e("settings.notificationsStylePersistentHint")]].map(([M,G,Re])=>{const rt=F===M;return o.jsxs("button",{type:"button",disabled:!A,onClick:()=>nc(M),className:`min-w-0 rounded-lg px-2 py-2 text-left transition ${rt&&A?"bg-primary/15 text-primary":A?"text-muted-foreground hover:bg-surface-elevated hover:text-foreground":"cursor-not-allowed text-muted-foreground/40"}`,title:Re,children:[o.jsx("span",{className:"block truncate text-[11px] font-semibold",children:G}),o.jsx("span",{className:"mt-0.5 block truncate text-[9px] opacity-80",children:Re})]},M)})})]}),o.jsxs("div",{className:"mt-4",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.notificationsEvents")}),o.jsxs("div",{className:"mt-2 rounded-2xl bg-surface-2 p-3",children:[o.jsxs("div",{className:"flex items-start justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsAiFinished")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:e("settings.notificationsAiFinishedHint")})]}),o.jsx("button",{type:"button",disabled:!A,onClick:()=>Rc(!L),className:"shrink-0 transition disabled:cursor-not-allowed","aria-pressed":L&&A,children:o.jsx(xc,{checked:L&&A,disabled:!A})})]}),o.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3 border-t border-border/10 pt-3",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:e("settings.notificationsSessionExited")}),o.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-muted-foreground",children:e("settings.notificationsSessionExitedHint")})]}),o.jsx("button",{type:"button",disabled:!A,onClick:()=>Ba(!j),className:"shrink-0 transition disabled:cursor-not-allowed","aria-pressed":j&&A,children:o.jsx(xc,{checked:j&&A,disabled:!A})})]})]}),o.jsx("p",{className:"mt-2 text-[10px] text-muted-foreground",children:e("settings.notificationsFutureHint")})]})]})]})]}),_o&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:()=>$s(!1)}),o.jsxs("div",{className:"fixed left-[max(0.75rem,env(safe-area-inset-left,0px))] right-[max(0.75rem,env(safe-area-inset-right,0px))] top-[max(1.5rem,env(safe-area-inset-top,0px))] bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto flex max-w-4xl flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)]",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-4 py-4 sm:px-6",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.mobileKeyboard")}),o.jsx("h2",{className:"section-title mt-1",children:e("settings.toolbarPresets")})]}),o.jsx("button",{type:"button",onClick:()=>$s(!1),className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":"Close toolbar presets",children:o.jsx(ts,{size:18})})]}),o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-6",children:o.jsx(Lte,{presets:Je,selectedPresetId:et,onSelectPreset:Zt,onUpdatePreset:(M,G)=>{Ke(Re=>qd(Re.map(rt=>rt.id===M?G(rt):rt)))},onAddPreset:()=>{const M=`preset-${Date.now()}`;Ke(G=>qd([...G,{id:M,label:`Preset ${G.length}`,programs:[],includeAlt:!1,rowLayout:[3,3],actions:[],showOnDesktop:!1}])),Zt(M)},onRemovePreset:M=>{Ke(G=>qd(G.filter(Re=>Re.id!==M)))},onResetDefaults:()=>{Ke(Vf()),Zt("default")}})})]})]}),Lr&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm cursor-default",onClick:()=>Ir(!1)}),o.jsxs("div",{className:"fixed left-[max(0.75rem,env(safe-area-inset-left,0px))] right-[max(0.75rem,env(safe-area-inset-right,0px))] top-[max(1.5rem,env(safe-area-inset-top,0px))] bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto flex max-w-4xl flex-col overflow-hidden rounded-2xl bg-surface border border-border/15 shadow-[0_28px_70px_var(--app-shadow-strong),0_14px_32px_var(--app-shadow-soft)]",children:[o.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border/15 px-4 py-4 sm:px-6",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.aiAgentDetection")}),o.jsx("h2",{className:"section-title mt-1",children:e("settings.detectionRules")})]}),o.jsx("div",{className:"flex items-center gap-2",children:o.jsx("button",{type:"button",onClick:()=>Ir(!1),className:"shrink-0 rounded-full bg-surface-2 p-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":"Close agent rules",children:o.jsx(ts,{size:18})})})]}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-6",children:[o.jsx("p",{className:"mb-4 text-[11px] text-muted-foreground",children:e("settings.agentHooksHint")}),o.jsx(Ite,{}),o.jsxs("div",{className:"mt-6 border-t border-border/15 pt-4",children:[o.jsx("div",{className:"ui-kicker",children:e("settings.programLabelResolution")}),o.jsx("h3",{className:"mt-1 text-sm font-semibold text-foreground",children:e("settings.rawCommandMapping")}),o.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:e("settings.rawCommandMappingHint")}),o.jsx("div",{className:"mt-3 space-y-2 rounded-xl bg-surface-2 p-3",children:Ft.map(M=>{const G=Se.get(M.id),Re=G?.activeProgramRaw??null,rt=G?.activeProgram??null;return o.jsxs("div",{className:"rounded-lg bg-surface/60 px-2.5 py-2",children:[o.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:M.name}),o.jsxs("div",{className:"mt-0.5 text-[11px] text-foreground",children:[o.jsx("span",{className:"text-muted-foreground",children:"display:"})," ",rt||"—"]}),o.jsxs("div",{className:"mt-0.5 break-all font-mono text-[10px] text-muted-foreground",children:[o.jsx("span",{className:"text-muted-foreground/80",children:"raw:"})," ",Re||"—"]})]},`raw-${M.id}`)})}),o.jsxs("div",{className:"mt-3 space-y-3",children:[[{key:"genericProgramNames",label:e("settings.genericProgramNames"),hint:e("settings.genericProgramNamesHint")},{key:"wrapperScriptNames",label:e("settings.wrapperScriptNames"),hint:e("settings.wrapperScriptNamesHint")},{key:"shellNames",label:e("settings.shellNamesConfig"),hint:e("settings.shellNamesHint")}].map(({key:M,label:G,hint:Re})=>o.jsxs("div",{children:[o.jsx("div",{className:"mb-0.5 text-[11px] font-medium text-foreground",children:G}),o.jsx("div",{className:"text-[10px] text-muted-foreground",children:Re}),o.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[ni[M].map(rt=>o.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-surface-2 px-2 py-0.5 text-[11px] font-mono text-foreground",children:[rt,o.jsx("button",{type:"button",onClick:()=>{const Pt={...ni,[M]:ni[M].filter(Wt=>Wt!==rt)};fa(Pt),M==="shellNames"&&(rl=new Set(Pt.shellNames)),o5(Pt).catch(()=>{})},className:"ml-0.5 text-muted-foreground hover:text-destructive",children:"×"})]},rt)),o.jsx("input",{placeholder:e("settings.addTag"),className:"w-16 rounded bg-surface px-1.5 py-0.5 text-[11px] font-mono",onKeyDown:rt=>{if(rt.key!=="Enter")return;const Pt=rt.target.value.trim().toLowerCase();if(!Pt||ni[M].includes(Pt))return;const Wt={...ni,[M]:[...ni[M],Pt]};fa(Wt),M==="shellNames"&&(rl=new Set(Wt.shellNames)),rt.target.value="",o5(Wt).catch(()=>{})}})]})]},M)),o.jsx("button",{type:"button",onClick:()=>{nI().then(M=>{fa(M),rl=new Set(M.shellNames)}).catch(()=>{})},className:"rounded-full bg-surface-2 px-3 py-1 text-[11px] text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:e("settings.resetDefaults")})]}),o.jsxs("div",{className:"mt-3",children:[o.jsx("div",{className:"mb-1 text-[11px] font-medium text-foreground",children:e("settings.customRules")}),Pr.map((M,G)=>o.jsx("div",{className:"mb-2 rounded-lg bg-surface-2 p-2.5",children:o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("input",{type:"checkbox",checked:M.enabled!==!1,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,enabled:Re.target.checked}:Pt);ur(rt),$n(Jo,rt),Br(!0),Sd(rt).then(Pt=>{ur(Pt),$n(Jo,Pt)}).catch(()=>{}).finally(()=>Br(!1))}}),o.jsxs("select",{value:M.matchType,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,matchType:Re.target.value}:Pt);ur(rt),$n(Jo,rt),Br(!0),Sd(rt).then(Pt=>{ur(Pt),$n(Jo,Pt)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded bg-surface px-2 py-1 text-[11px]",children:[o.jsx("option",{value:"includes",children:"includes"}),o.jsx("option",{value:"exact",children:"exact"}),o.jsx("option",{value:"prefix",children:"prefix"}),o.jsx("option",{value:"regex",children:"regex"})]}),o.jsx("input",{value:M.pattern,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,pattern:Re.target.value}:Pt);ur(rt),$n(Jo,rt)},onBlur:()=>{Br(!0),Sd(Pr).then(Re=>{ur(Re),$n(Jo,Re)}).catch(()=>{}).finally(()=>Br(!1))},placeholder:"pattern",className:"min-w-[180px] flex-1 rounded bg-surface px-2 py-1 text-[11px] font-mono"}),o.jsx("input",{value:M.output,onChange:Re=>{const rt=Pr.map((Pt,Wt)=>Wt===G?{...Pt,output:Re.target.value}:Pt);ur(rt),$n(Jo,rt)},onBlur:()=>{Br(!0),Sd(Pr).then(Re=>{ur(Re),$n(Jo,Re)}).catch(()=>{}).finally(()=>Br(!1))},placeholder:"output",className:"w-28 rounded bg-surface px-2 py-1 text-[11px]"}),o.jsx("button",{type:"button",onClick:()=>{const Re=Pr.filter((rt,Pt)=>Pt!==G);ur(Re),$n(Jo,Re),Br(!0),Sd(Re).then(rt=>{ur(rt),$n(Jo,rt)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded bg-surface px-2 py-1 text-[11px] text-muted-foreground hover:text-destructive",children:e("common.delete")})]})},M.id)),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("button",{type:"button",onClick:()=>{const M=[...Pr,{id:`rule-${Date.now()}`,enabled:!0,priority:100,matchType:"includes",pattern:"",output:""}];ur(M),$n(Jo,M),Br(!0),Sd(M).then(G=>{ur(G),$n(Jo,G)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded-full bg-primary/15 px-3 py-1.5 text-[11px] font-medium text-primary hover:bg-primary/25",children:e("settings.addRule")}),o.jsx("button",{type:"button",onClick:()=>{Br(!0),eI().then(M=>{ur(M),$n(Jo,M)}).catch(()=>{}).finally(()=>Br(!1))},className:"rounded-full bg-surface-2 px-3 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:e("settings.resetDefaults")}),o.jsx("span",{className:"text-[11px] text-muted-foreground",children:ti?e("settings.saving"):da?`${Pr.length} rules`:"…"})]})]})]})]})]})]}),xs&&o.jsx(Ste,{isOpen:xs,onClose:()=>Gn(!1)}),!Ys&&o.jsx(D6,{isOpen:gt,drawerWidthPx:hi,onClose:()=>Wr("left-sidebar"),onOpen:oa,sessions:Ft,activeSessionId:Gt,sessionStates:Se,onNewSession:M=>bi(M),onCloseSession:ic,onSplitSession:au,onCloseSplit:M=>window.dispatchEvent(new CustomEvent("close-terminal-split",{detail:M})),onRemoveFromSplit:M=>window.dispatchEvent(new CustomEvent("remove-terminal-split-pane",{detail:M})),splitWorkspaces:Jn,onSetSplitLayout:Dl,onReorderSplitWorkspace:lu,onRenameSplitWorkspace:sc,onCombineSplitSessions:Mc,onReorderSessions:hr,onSessionMenu:Rl,onOpenSettings:me,onOpenQuota:()=>Gn(!0),updateState:z,updateActionPending:pe,onConfirmUpdateRestart:Me,onRetryUpdate:Ee,tmuxAvailable:Rt.available,defaultSessionMode:Rr,runningSessionButtonEnabled:Lt,onRunningSessionButtonEnabledChange:mn,onTogglePinned:zn?Fs:void 0}),!jc&&o.jsx(r7,{isOpen:Kt,drawerWidthPx:ia,onClose:()=>Wr("right-sidebar"),onOpen:Co,rightSidebarFilePreviewOpen:cr,rightSidebarFilePreviewCloseSignal:W,onOpenRightSidebarFilePreview:ua,onCloseRightSidebarFilePreview:Pa,rightSidebarRepoPickerOpen:He,rightSidebarRepoPickerCloseSignal:Qe,onOpenRightSidebarRepoPicker:fl,onCloseRightSidebarRepoPicker:Qs,markdownOutlineOpen:At,markdownOutlineCloseSignal:Yt,onOpenMarkdownOutline:gi,onCloseMarkdownOutline:Li,markdownImageLightboxOpen:on,markdownImageLightboxCloseSignal:Cn,onOpenMarkdownImageLightbox:Ei,onCloseMarkdownImageLightbox:po,onTogglePinned:zn?la:void 0}),Te&&!i&&o.jsx("button",{type:"button",onClick:nt,className:"fixed inset-0 z-toast flex cursor-default items-center justify-center bg-[var(--app-backdrop-soft)] px-6 text-left backdrop-blur-[1px]","aria-label":t==="zh"?"继续使用 Termdock":"Continue using Termdock",children:o.jsxs("div",{className:"max-w-[18rem] rounded-2xl border border-border/15 bg-surface/95 px-5 py-4 text-center shadow-[0_18px_50px_var(--app-shadow-strong)] backdrop-blur animate-fade-in",children:[o.jsx("div",{className:"text-[14px] font-semibold text-foreground",children:t==="zh"?"建议使用 Home":"Use Home instead"}),o.jsx("div",{className:"mt-1.5 text-[12px] leading-relaxed text-muted-foreground",children:t==="zh"?"按 Home 退后台,点任意位置继续。":"Use Home to leave. Tap anywhere to continue."}),o.jsx("div",{className:"mt-3 text-[11px] font-medium text-muted-foreground/80",children:t==="zh"?"轻点关闭提示":"Tap to dismiss"})]})}),Er&&o.jsxs("div",{className:`fixed inset-x-3 bottom-4 z-toast mx-auto flex max-w-md items-center gap-2 rounded-xl border px-4 py-3 text-[12px] shadow-lg animate-fade-in ${Er.tone==="success"?"border-[rgb(var(--success-rgb)_/_0.24)] bg-surface-elevated text-foreground":"border-destructive/30 bg-surface-elevated text-destructive"}`,role:Er.tone==="error"?"alert":"status",children:[Er.tone==="success"?o.jsx(wf,{size:14,className:"shrink-0 text-[color:var(--success)]"}):o.jsx(Tm,{size:14,className:"shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1",children:Er.message}),o.jsx("button",{type:"button",onClick:()=>yr(null),className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-2 hover:text-foreground","aria-label":e("common.close"),children:o.jsx(ts,{size:12})})]}),a&&o.jsxs("div",{className:"fixed bottom-0 left-0 right-0 z-toast max-h-48 overflow-y-auto border-t border-border/15 bg-surface p-3 animate-fade-in",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("h4",{className:"ui-kicker",children:"Debug Info"}),o.jsx("button",{type:"button",onClick:()=>c(!1),className:"text-xs text-muted-foreground hover:text-foreground",children:"Close"})]}),o.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(ot,null,2)})]})]});return Ys||jc?o.jsxs("div",{className:"w-screen h-full flex flex-row",children:[Ys&&o.jsxs(o.Fragment,{children:[o.jsx("div",{style:{width:vt,flexShrink:0,height:"100%"},children:o.jsx(D6,{isOpen:gt,drawerWidthPx:vt,onClose:aa,onOpen:oa,sessions:Ft,activeSessionId:Gt,sessionStates:Se,onNewSession:M=>bi(M),onCloseSession:ic,onSplitSession:au,onCloseSplit:M=>window.dispatchEvent(new CustomEvent("close-terminal-split",{detail:M})),onRemoveFromSplit:M=>window.dispatchEvent(new CustomEvent("remove-terminal-split-pane",{detail:M})),splitWorkspaces:Jn,onSetSplitLayout:Dl,onReorderSplitWorkspace:lu,onRenameSplitWorkspace:sc,onCombineSplitSessions:Mc,onReorderSessions:hr,onSessionMenu:Rl,onOpenSettings:me,onOpenQuota:()=>Gn(!0),updateState:z,updateActionPending:pe,onConfirmUpdateRestart:Me,onRetryUpdate:Ee,tmuxAvailable:Rt.available,defaultSessionMode:Rr,runningSessionButtonEnabled:Lt,onRunningSessionButtonEnabledChange:mn,pinned:!0,onTogglePinned:Fs})}),o.jsx("div",{role:"separator",tabIndex:-1,className:"shrink-0 w-[5px] h-full cursor-col-resize bg-border/10 hover:bg-primary/30 active:bg-primary/50 transition-colors",onMouseDown:_i})]}),o.jsx("div",{className:"flex-1 min-w-0 h-full overflow-hidden",children:ml}),jc&&o.jsxs(o.Fragment,{children:[o.jsx("div",{role:"separator",tabIndex:-1,className:"h-full w-[5px] shrink-0 cursor-col-resize bg-border/10 transition-colors hover:bg-primary/30 active:bg-primary/50",onMouseDown:ko}),o.jsx("div",{style:{width:oc,flexShrink:0,height:"100%"},children:o.jsx(r7,{isOpen:!0,drawerWidthPx:oc,onClose:Os,onOpen:Co,pinned:!0,onTogglePinned:la,rightSidebarFilePreviewOpen:cr,rightSidebarFilePreviewCloseSignal:W,onOpenRightSidebarFilePreview:ua,onCloseRightSidebarFilePreview:Pa,rightSidebarRepoPickerOpen:He,rightSidebarRepoPickerCloseSignal:Qe,onOpenRightSidebarRepoPicker:fl,onCloseRightSidebarRepoPicker:Qs,markdownOutlineOpen:At,markdownOutlineCloseSignal:Yt,onOpenMarkdownOutline:gi,onCloseMarkdownOutline:Li,markdownImageLightboxOpen:on,markdownImageLightboxCloseSignal:Cn,onOpenMarkdownImageLightbox:Ei,onCloseMarkdownImageLightbox:po})})]})]}):ml}const Xte=String.raw`
243
243
  ████████ ███████ ██████ ███ ███ ██████ ██████ ██████ ██ ██
244
244
  ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██
245
245
  ██ █████ ██████ ██ ████ ██ ██ ██ ██ ██ ██ █████
246
246
  ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
247
247
  ██ ███████ ██ ██ ██ ██ ██████ ██████ ██████ ██ ██
248
- `;function Yte({onLoginSuccess:e}){const{t}=Yn(),[n,r]=b.useState(""),[s,i]=b.useState(!1),[a,c]=b.useState(null),[u,f]=b.useState(0),p=b.useRef(null);b.useEffect(()=>{p.current?.focus()},[]),b.useEffect(()=>{if(u<=0)return;const A=setInterval(()=>{f(T=>T>1?T-1:0)},1e3);return()=>clearInterval(A)},[u]);const g=u>0,y=!s&&!g&&n.length>0,v=async A=>{if(A.preventDefault(),!!y){i(!0),c(null);try{const T=await QE(n);if(T.ok){r(""),e();return}c(T.error||t("login.invalidPassword")),T.rateLimited&&typeof T.retryAfterMs=="number"&&f(Math.max(1,Math.ceil(T.retryAfterMs/1e3)))}catch(T){c(T instanceof Error?T.message:t("login.failed"))}finally{i(!1)}}},S=g?t("login.placeholderBlocked",{s:u}):t("login.placeholder");return o.jsxs("div",{className:"flex w-screen flex-col items-center justify-center bg-background px-4 text-foreground",style:{height:"var(--app-vh, 100vh)",paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"20vh",gap:"clamp(20px, 4vh, 40px)"},children:[o.jsx("pre",{"aria-hidden":!0,className:"max-w-full select-none overflow-hidden whitespace-pre leading-[1.05] text-primary/80 font-mono",style:{fontSize:"clamp(5px, 2vw, 14px)"},children:qte}),o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground font-mono",children:[o.jsx("span",{className:"text-primary",children:"$"}),o.jsx("span",{children:t("login.prompt")}),o.jsx("span",{className:"terminal-cursor","aria-hidden":!0,children:"▍"})]}),o.jsxs("form",{onSubmit:v,className:"w-full max-w-xs",children:[o.jsxs("div",{className:`flex items-center gap-1 rounded-full border bg-surface-2 p-1 pl-4 transition ${a?"border-destructive/60":"border-border"}`,children:[o.jsx("input",{ref:p,type:"password",autoComplete:"current-password",value:n,placeholder:S,onChange:A=>{r(A.target.value),a&&c(null)},disabled:s||g,className:"flex-1 bg-transparent text-foreground placeholder:text-muted-foreground/70 focus:outline-none disabled:opacity-60",style:{minWidth:0,fontSize:"16px"}}),o.jsx("button",{type:"submit",disabled:!y,"aria-label":t("login.submit"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-40",children:s?o.jsx(Fn,{size:16,className:"animate-spin"}):o.jsx(m8,{size:16})})]}),a&&!g?o.jsx("div",{className:"mt-3 text-center text-xs text-destructive",children:a}):null]}),o.jsx("style",{children:`
248
+ `;function Zte({onLoginSuccess:e}){const{t}=Yn(),[n,r]=b.useState(""),[s,i]=b.useState(!1),[a,c]=b.useState(null),[u,f]=b.useState(0),p=b.useRef(null);b.useEffect(()=>{p.current?.focus()},[]),b.useEffect(()=>{if(u<=0)return;const A=setInterval(()=>{f(T=>T>1?T-1:0)},1e3);return()=>clearInterval(A)},[u]);const g=u>0,y=!s&&!g&&n.length>0,v=async A=>{if(A.preventDefault(),!!y){i(!0),c(null);try{const T=await QE(n);if(T.ok){r(""),e();return}c(T.error||t("login.invalidPassword")),T.rateLimited&&typeof T.retryAfterMs=="number"&&f(Math.max(1,Math.ceil(T.retryAfterMs/1e3)))}catch(T){c(T instanceof Error?T.message:t("login.failed"))}finally{i(!1)}}},S=g?t("login.placeholderBlocked",{s:u}):t("login.placeholder");return o.jsxs("div",{className:"flex w-screen flex-col items-center justify-center bg-background px-4 text-foreground",style:{height:"var(--app-vh, 100vh)",paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"20vh",gap:"clamp(20px, 4vh, 40px)"},children:[o.jsx("pre",{"aria-hidden":!0,className:"max-w-full select-none overflow-hidden whitespace-pre leading-[1.05] text-primary/80 font-mono",style:{fontSize:"clamp(5px, 2vw, 14px)"},children:Xte}),o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground font-mono",children:[o.jsx("span",{className:"text-primary",children:"$"}),o.jsx("span",{children:t("login.prompt")}),o.jsx("span",{className:"terminal-cursor","aria-hidden":!0,children:"▍"})]}),o.jsxs("form",{onSubmit:v,className:"w-full max-w-xs",children:[o.jsxs("div",{className:`flex items-center gap-1 rounded-full border bg-surface-2 p-1 pl-4 transition ${a?"border-destructive/60":"border-border"}`,children:[o.jsx("input",{ref:p,type:"password",autoComplete:"current-password",value:n,placeholder:S,onChange:A=>{r(A.target.value),a&&c(null)},disabled:s||g,className:"flex-1 bg-transparent text-foreground placeholder:text-muted-foreground/70 focus:outline-none disabled:opacity-60",style:{minWidth:0,fontSize:"16px"}}),o.jsx("button",{type:"submit",disabled:!y,"aria-label":t("login.submit"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-40",children:s?o.jsx(Fn,{size:16,className:"animate-spin"}):o.jsx(m8,{size:16})})]}),a&&!g?o.jsx("div",{className:"mt-3 text-center text-xs text-destructive",children:a}):null]}),o.jsx("style",{children:`
249
249
  @keyframes terminal-blink {
250
250
  0%, 49% { opacity: 1; }
251
251
  50%, 100% { opacity: 0; }
@@ -255,7 +255,7 @@ ${jt}
255
255
  animation: terminal-blink 1.05s steps(1, end) infinite;
256
256
  color: var(--primary);
257
257
  }
258
- `})]})}const Ta="/tmp/termdock-dag-playground",g7={version:1,id:"dag-playground",repoRoot:Ta,workspaceRoot:Ta,title:"改动解释升级为可点击导览",summary:"这是一页免登录 playground,用真实 ChangeWalkthroughPanel 调 DAG 的节点、边、label 和密度。",generatedBy:"dag-playground",injectedAt:Date.now(),highlights:[{what:"先看总览,再看链路",effect:"读者不用先进入 diff,也能理解整批改动目的。",tag:"理解"},{what:"多条链路直接画出来",effect:"分支、汇合、验证路径不再靠 next 文本猜。",tag:"链路"},{what:"点击节点跳回证据",effect:"导览和真实 diff 之间形成闭环。",tag:"导航"}],nodes:[{id:"export",title:"导出 section 级 diff",kind:"source",business:"CLI 把 hunk 拆成多个连续改动 section,并为每个 section 生成稳定 fingerprint。这里故意写长一点,用来验证 DAG 节点是否会按照真实文本高度撑开,而不是被固定高度裁掉。",anchor:{repoRoot:Ta,filePath:"src/server/cli.ts",hunkIndex:0,sectionIndex:0}},{id:"prompt",title:"约束 AI 输出",kind:"process",business:"提示词要求先写总览,再逐 section 生成解释。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/RightSidebar.tsx",hunkIndex:0}},{id:"schema",title:"校验导览结构",kind:"process",business:"检查节点、边和锚点字段是否完整。",anchor:{repoRoot:Ta,filePath:"src/server/utils/changeAuditStore.ts",hunkIndex:0}},{id:"fallback",title:"补齐兼容字段",kind:"process",business:"旧版结果缺字段时生成稳定回退值。",anchor:{repoRoot:Ta,filePath:"src/server/utils/changeAuditStore.ts",hunkIndex:1}},{id:"store",title:"保存整批导览结构",kind:"process",business:"服务端把 walkthrough 作为一等数据持久化。",anchor:{repoRoot:Ta,filePath:"src/server/utils/changeAuditStore.ts",hunkIndex:0}},{id:"api",title:"前端读取总览",kind:"api",business:"一次请求拿到 records 和 walkthroughs。",anchor:{repoRoot:Ta,filePath:"src/lib/terminal/api.ts",hunkIndex:0}},{id:"panel",title:"渲染 DAG 导览",kind:"ui",business:"用节点和边表达实现链路,节点可点击。节点内容可能是一两句话,也可能包含较长的业务解释;布局需要先测量 DOM 高度,再重新计算每一行节点的 y 坐标和连线端点。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/ChangeWalkthroughPanel.tsx",hunkIndex:0}},{id:"jump",title:"跳回真实 diff",kind:"ui",business:"点击节点后定位到文件、hunk 或 section。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/RightSidebar.tsx",hunkIndex:1}},{id:"section",title:"贴近改动展示解释",kind:"ui",business:"section 解释跟在对应 diff 块后面,而不是堆在 hunk 顶部。这个节点也故意写得更长,用来观察右侧分支和下方验证节点的连线是否会避让变高后的卡片。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/DiffViewer.tsx",hunkIndex:0,sectionIndex:1}},{id:"verify",title:"验证导出和注入",kind:"test",business:"跑 lint、install、health、资源检查和注入自测。"}],edges:[{from:"export",to:"prompt",label:"提供输入",desc:"sectionFingerprint 让 AI 可以稳定引用。"},{from:"export",to:"schema",label:"结构校验",desc:"先确认输入可以稳定落库。"},{from:"export",to:"fallback",label:"兼容旧数据",desc:"为历史记录补齐必要字段。"},{from:"prompt",to:"store",label:"注入",desc:"AI payload 写回本地服务。"},{from:"schema",to:"store",label:"通过后保存",desc:"合法结构进入存储层。"},{from:"fallback",to:"store",label:"归一化后保存",desc:"兼容数据与新数据走同一链路。"},{from:"store",to:"api",label:"读取",desc:"浏览器从服务端拿到导览。"},{from:"api",to:"panel",label:"渲染",desc:"结构化数据变成导览图。"},{from:"panel",to:"jump",label:"点击",desc:"节点驱动 diff 定位。"},{from:"jump",to:"section",label:"定位",desc:"落到对应 section 解释。"},{from:"export",to:"verify",label:"验证",desc:"导出结构要覆盖 tracked/untracked。"},{from:"section",to:"verify",label:"回归",desc:"确认展示位置和交互。"}],sections:[],risks:[{title:"边和 label 不能遮住节点主体。"},{title:"窄侧栏下横向滚动要可控。"}],checks:["在 360px、560px、900px 宽度下截图检查。","确认边的箭头、label 背板和节点层级清楚。","确认节点点击区域和 hover 状态可感知。"]};function Kte(){return o.jsx("div",{className:"min-h-screen bg-background p-5 text-foreground","data-dag-playground":!0,children:o.jsxs("div",{className:"mx-auto max-w-[72rem]",children:[o.jsxs("div",{className:"mb-3",children:[o.jsx("h1",{className:"text-sm font-semibold",children:"DAG Playground"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Auth-free playground for tuning the real ChangeWalkthroughPanel."})]}),o.jsxs("div",{className:"grid gap-4 lg:grid-cols-[360px_minmax(0,1fr)]",children:[o.jsx("div",{className:"min-w-0",children:o.jsx(ng,{walkthroughs:[g7],repoRoot:Ta,onNavigate:e=>{console.info("[DagPlayground] navigate",e)}})}),o.jsx("div",{className:"min-w-0",children:o.jsx(ng,{walkthroughs:[g7],repoRoot:Ta,onNavigate:e=>{console.info("[DagPlayground] navigate",e)}})})]})]})})}const V2={kotlin:{label:"Kotlin function signature + callback",path:"SearchHintIconHelper.kt",diff:`diff --git a/SearchHintIconHelper.kt b/SearchHintIconHelper.kt
258
+ `})]})}const Ta="/tmp/termdock-dag-playground",g7={version:1,id:"dag-playground",repoRoot:Ta,workspaceRoot:Ta,title:"改动解释升级为可点击导览",summary:"这是一页免登录 playground,用真实 ChangeWalkthroughPanel 调 DAG 的节点、边、label 和密度。",generatedBy:"dag-playground",injectedAt:Date.now(),highlights:[{what:"先看总览,再看链路",effect:"读者不用先进入 diff,也能理解整批改动目的。",tag:"理解"},{what:"多条链路直接画出来",effect:"分支、汇合、验证路径不再靠 next 文本猜。",tag:"链路"},{what:"点击节点跳回证据",effect:"导览和真实 diff 之间形成闭环。",tag:"导航"}],nodes:[{id:"export",title:"导出 section 级 diff",kind:"source",business:"CLI 把 hunk 拆成多个连续改动 section,并为每个 section 生成稳定 fingerprint。这里故意写长一点,用来验证 DAG 节点是否会按照真实文本高度撑开,而不是被固定高度裁掉。",anchor:{repoRoot:Ta,filePath:"src/server/cli.ts",hunkIndex:0,sectionIndex:0}},{id:"prompt",title:"约束 AI 输出",kind:"process",business:"提示词要求先写总览,再逐 section 生成解释。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/RightSidebar.tsx",hunkIndex:0}},{id:"schema",title:"校验导览结构",kind:"process",business:"检查节点、边和锚点字段是否完整。",anchor:{repoRoot:Ta,filePath:"src/server/utils/changeAuditStore.ts",hunkIndex:0}},{id:"fallback",title:"补齐兼容字段",kind:"process",business:"旧版结果缺字段时生成稳定回退值。",anchor:{repoRoot:Ta,filePath:"src/server/utils/changeAuditStore.ts",hunkIndex:1}},{id:"store",title:"保存整批导览结构",kind:"process",business:"服务端把 walkthrough 作为一等数据持久化。",anchor:{repoRoot:Ta,filePath:"src/server/utils/changeAuditStore.ts",hunkIndex:0}},{id:"api",title:"前端读取总览",kind:"api",business:"一次请求拿到 records 和 walkthroughs。",anchor:{repoRoot:Ta,filePath:"src/lib/terminal/api.ts",hunkIndex:0}},{id:"panel",title:"渲染 DAG 导览",kind:"ui",business:"用节点和边表达实现链路,节点可点击。节点内容可能是一两句话,也可能包含较长的业务解释;布局需要先测量 DOM 高度,再重新计算每一行节点的 y 坐标和连线端点。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/ChangeWalkthroughPanel.tsx",hunkIndex:0}},{id:"jump",title:"跳回真实 diff",kind:"ui",business:"点击节点后定位到文件、hunk 或 section。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/RightSidebar.tsx",hunkIndex:1}},{id:"section",title:"贴近改动展示解释",kind:"ui",business:"section 解释跟在对应 diff 块后面,而不是堆在 hunk 顶部。这个节点也故意写得更长,用来观察右侧分支和下方验证节点的连线是否会避让变高后的卡片。",anchor:{repoRoot:Ta,filePath:"src/lib/components/sidebar/DiffViewer.tsx",hunkIndex:0,sectionIndex:1}},{id:"verify",title:"验证导出和注入",kind:"test",business:"跑 lint、install、health、资源检查和注入自测。"}],edges:[{from:"export",to:"prompt",label:"提供输入",desc:"sectionFingerprint 让 AI 可以稳定引用。"},{from:"export",to:"schema",label:"结构校验",desc:"先确认输入可以稳定落库。"},{from:"export",to:"fallback",label:"兼容旧数据",desc:"为历史记录补齐必要字段。"},{from:"prompt",to:"store",label:"注入",desc:"AI payload 写回本地服务。"},{from:"schema",to:"store",label:"通过后保存",desc:"合法结构进入存储层。"},{from:"fallback",to:"store",label:"归一化后保存",desc:"兼容数据与新数据走同一链路。"},{from:"store",to:"api",label:"读取",desc:"浏览器从服务端拿到导览。"},{from:"api",to:"panel",label:"渲染",desc:"结构化数据变成导览图。"},{from:"panel",to:"jump",label:"点击",desc:"节点驱动 diff 定位。"},{from:"jump",to:"section",label:"定位",desc:"落到对应 section 解释。"},{from:"export",to:"verify",label:"验证",desc:"导出结构要覆盖 tracked/untracked。"},{from:"section",to:"verify",label:"回归",desc:"确认展示位置和交互。"}],sections:[],risks:[{title:"边和 label 不能遮住节点主体。"},{title:"窄侧栏下横向滚动要可控。"}],checks:["在 360px、560px、900px 宽度下截图检查。","确认边的箭头、label 背板和节点层级清楚。","确认节点点击区域和 hover 状态可感知。"]};function Jte(){return o.jsx("div",{className:"min-h-screen bg-background p-5 text-foreground","data-dag-playground":!0,children:o.jsxs("div",{className:"mx-auto max-w-[72rem]",children:[o.jsxs("div",{className:"mb-3",children:[o.jsx("h1",{className:"text-sm font-semibold",children:"DAG Playground"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Auth-free playground for tuning the real ChangeWalkthroughPanel."})]}),o.jsxs("div",{className:"grid gap-4 lg:grid-cols-[360px_minmax(0,1fr)]",children:[o.jsx("div",{className:"min-w-0",children:o.jsx(ng,{walkthroughs:[g7],repoRoot:Ta,onNavigate:e=>{console.info("[DagPlayground] navigate",e)}})}),o.jsx("div",{className:"min-w-0",children:o.jsx(ng,{walkthroughs:[g7],repoRoot:Ta,onNavigate:e=>{console.info("[DagPlayground] navigate",e)}})})]})]})})}const V2={kotlin:{label:"Kotlin function signature + callback",path:"SearchHintIconHelper.kt",diff:`diff --git a/SearchHintIconHelper.kt b/SearchHintIconHelper.kt
259
259
  --- a/SearchHintIconHelper.kt
260
260
  +++ b/SearchHintIconHelper.kt
261
261
  @@ -43,15 +43,20 @@ object SearchHintIconHelper {
@@ -453,5 +453,5 @@ ${jt}
453
453
  + finish(context);
454
454
  + }
455
455
  return context;
456
- }`}};function x7(){if(typeof window>"u")return"kotlin";const t=new URLSearchParams(window.location.search).get("fixture");return t&&t in V2?t:"kotlin"}function b7(){return typeof window>"u"?"unified":new URLSearchParams(window.location.search).get("view")==="split"?"split":"unified"}function y7(){if(typeof window>"u")return"words";const e=new URLSearchParams(window.location.search).get("inline");return e==="none"||e==="chars"||e==="words"?e:"words"}function v7(){return typeof window>"u"?!0:new URLSearchParams(window.location.search).get("wrap")!=="off"}function Xte(){const[e,t]=b.useState(()=>x7()),[n,r]=b.useState(()=>b7()),[s,i]=b.useState(()=>y7()),[a,c]=b.useState(()=>v7()),u=V2[e],f=b.useMemo(()=>Object.entries(V2),[]);return b.useEffect(()=>{if(typeof window>"u")return;let p=window.location.search;const g=()=>{window.location.search!==p&&(p=window.location.search,t(x7()),r(b7()),i(y7()),c(v7()))};window.addEventListener("popstate",g),window.addEventListener("pageshow",g),window.addEventListener("focus",g);const y=window.setInterval(g,250);return()=>{window.removeEventListener("popstate",g),window.removeEventListener("pageshow",g),window.removeEventListener("focus",g),window.clearInterval(y)}},[]),o.jsx("div",{className:"min-h-screen bg-background-subtle text-foreground","data-diff-lab":!0,"data-diff-lab-fixture":e,"data-diff-lab-view":n,"data-diff-lab-inline":s,"data-diff-lab-wrap":a?"on":"off",children:o.jsxs("div",{className:"mx-auto flex min-h-screen max-w-[1180px] flex-col px-4 py-4",children:[o.jsxs("header",{className:"mb-3 flex flex-wrap items-center justify-between gap-3 border-b border-border/20 pb-3",children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-semibold",children:"Diff Lab"}),o.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Fixed fixtures for iterating diff rendering without app auth, PWA state, or live Git data."})]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("select",{value:e,onChange:p=>t(p.target.value),"aria-label":"Fixture",className:"h-8 rounded-md border border-border/30 bg-surface px-2 text-xs text-foreground outline-none",children:f.map(([p,g])=>o.jsx("option",{value:p,children:g.label},p))}),o.jsxs("div",{className:"inline-flex h-8 overflow-hidden rounded-full bg-surface-2 p-0.5",children:[o.jsx("button",{type:"button",onClick:()=>r("unified"),className:`rounded-full px-3 text-xs font-semibold ${n==="unified"?"bg-surface-elevated text-foreground":"text-muted-foreground"}`,children:"Unified"}),o.jsx("button",{type:"button",onClick:()=>r("split"),className:`rounded-full px-3 text-xs font-semibold ${n==="split"?"bg-surface-elevated text-foreground":"text-muted-foreground"}`,children:"Split"})]}),o.jsx("div",{className:"inline-flex h-8 overflow-hidden rounded-full bg-surface-2 p-0.5",children:["none","words","chars"].map(p=>o.jsx("button",{type:"button",onClick:()=>i(p),className:`rounded-full px-3 text-xs font-semibold ${s===p?"bg-surface-elevated text-foreground":"text-muted-foreground"}`,children:p},p))}),o.jsxs("button",{type:"button",onClick:()=>c(p=>!p),className:`h-8 rounded-full px-3 text-xs font-semibold ${a?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground"}`,children:["Wrap ",a?"on":"off"]})]})]}),o.jsx("main",{className:"min-h-0 flex-1 overflow-auto rounded-lg border border-border/20 bg-surface",children:o.jsx(yT,{filePath:u.path,repoRoot:"/tmp/termdock-diff-lab",changedFile:{path:u.path,absolutePath:`/tmp/termdock-diff-lab/${u.path}`,repoRoot:"/tmp/termdock-diff-lab",status:"modified",staged:!1,unstaged:!0,untracked:!1,tracked:!0,canStage:!1,canUnstage:!1,canStash:!1,canRestoreWorktree:!1},diffOverride:u.diff,oldSourceOverride:u.oldSource,active:!0,wrap:a,showScrollHint:!a,viewType:n,inlineMode:s})})]})})}const AC=40,q2="/tmp/termdock-diff-review-lab";function w7(e,t){const n=[`diff --git a/${e} b/${e}`,`--- a/${e}`,`+++ b/${e}`,`@@ -1,${t} +1,${t} @@`];for(let r=0;r<t;r+=1)r%5===0&&n.push(`-const removed_${r} = ${r};`),r%3===0&&n.push(`+const added_${r} = ${r} * 2;`),n.push(` context line ${r} in ${e}`);return n.join(`
457
- `)}function Zte(e,t){return Array.from({length:AC},(n,r)=>{const s=6+r*7%60,i=`src/module${String(r).padStart(2,"0")}/File${r}.ts`,a=`${q2}/${i}`,c=w7(i,s),u=w7(i,1);return{key:a,path:i,absolutePath:a,status:"modified",repoRoot:q2,displayName:`File${r}.ts`,displayDir:`src/module${String(r).padStart(2,"0")} · ${s} lines`,diffOverride:!t||e.has(r)?c:u,auditRecords:[]}})}function Jte(){const e=b.useMemo(()=>{if(typeof window>"u")return 0;const L=new URLSearchParams(window.location.search).get("delay"),I=L===null?0:Number.parseInt(L,10);return Number.isInteger(I)&&I>0?I:0},[]),t=e>0,[n,r]=b.useState(()=>new Set);b.useEffect(()=>{if(!t)return;const L=Array.from({length:AC},(I,j)=>window.setTimeout(()=>{r(P=>{const F=new Set(P);return F.add(j),F})},e+j*20));return()=>L.forEach(I=>window.clearTimeout(I))},[t,e]);const s=b.useMemo(()=>Zte(n,t),[n,t]),i=b.useMemo(()=>[{key:"mock-repo",root:q2,label:"diff-review-lab",files:s.map(L=>({key:L.key,path:L.path,absolutePath:L.absolutePath,displayName:L.displayName,displayDir:L.displayDir,status:L.status}))}],[s]),a=b.useMemo(()=>{if(typeof window>"u")return null;const L=new URLSearchParams(window.location.search).get("select");if(L===null)return null;const I=Number.parseInt(L,10);return Number.isInteger(I)&&I>=0&&I<s.length?I:null},[s.length]),[c,u]=b.useState(()=>a!==null?s[a].key:null),[f,p]=b.useState(()=>({key:a!==null?s[a].key:null,nonce:a!==null?1:0})),[g,y]=b.useState("list"),[v,S]=b.useState(new Set),[A,T]=b.useState(a!==null?1:0);return o.jsxs("div",{className:"flex h-screen flex-col bg-background text-foreground","data-diff-review-lab":!0,children:[o.jsxs("div",{className:"shrink-0 border-b border-border/20 px-3 py-2 text-xs text-muted-foreground",children:["DiffReview Lab · ",s.length," mock files · selected: ",o.jsx("span",{"data-lab-selected":!0,children:c??"none"})," · slide ",A]}),o.jsx("div",{className:"min-h-0 flex-1",children:o.jsx(eg,{mobile:!0,backLabel:"Back",files:s,groups:i,selectedKey:c,scrollToKey:f.key,scrollToKeyNonce:f.nonce,mode:g,onModeChange:L=>{L!=="ai"&&y(L)},collapsedDirectoryKeys:v,onToggleDirectory:L=>S(I=>{const j=new Set(I);return j.has(L)?j.delete(L):j.add(L),j}),onSelectFile:L=>{u(L.key),p(I=>({key:L.key,nonce:I.nonce+1}))},onMobileSlideChange:T,renderLeading:()=>null,renderStreamBadge:L=>o.jsx("span",{className:"text-[10px] text-muted-foreground",children:L}),wrap:!0,showScrollHint:!1,activePane:!0})})]})}const ene=6e4,mb="termdock:build-id:v1";let S7=!1;function A7(){S7||(S7=!0,window.setTimeout(()=>{window.location.reload()},80))}function Y2(e){e.waiting?.postMessage({type:"SKIP_WAITING"})}async function tne(){if(typeof caches>"u")return;const e=await caches.keys();await Promise.all(e.map(t=>caches.delete(t)))}function nne(e){e.addEventListener("updatefound",()=>{const t=e.installing;t&&t.addEventListener("statechange",()=>{t.state==="installed"&&navigator.serviceWorker.controller&&Y2(e)})})}function rne(){if(typeof window>"u"||!("serviceWorker"in navigator))return;const e="1788183087687",t=window.localStorage.getItem(mb);if(t&&t!==e){tne().finally(()=>{window.localStorage.setItem(mb,e),A7()});return}t!==e&&window.localStorage.setItem(mb,e);let n=null;navigator.serviceWorker.addEventListener("controllerchange",A7),window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js",{scope:"/"}).then(r=>{nne(r),Y2(r);const s=()=>{document.visibilityState==="visible"&&r.update().then(()=>Y2(r)).catch(()=>{})};s(),n=window.setInterval(s,ene),document.addEventListener("visibilitychange",s)}).catch(()=>{})}),window.addEventListener("beforeunload",()=>{n!==null&&window.clearInterval(n)})}sO();rne();try{const e=JSON.parse(window.localStorage.getItem("termdock-color-theme")||"null");(e==="dark"||e==="light")&&(document.documentElement.dataset.theme=e,i9(e))}catch{}function sne(){const{t:e}=Yn(),[t,n]=b.useState(null),[r,s]=b.useState(null),i=b.useCallback(async()=>{try{const a=await OE();n(a),s(null)}catch(a){s(a instanceof Error?a.message:"Failed to query auth status")}},[]);return b.useEffect(()=>{i()},[i]),b.useEffect(()=>{const a=()=>{n(c=>c&&{...c,authenticated:!1})};return window.addEventListener(zf,a),()=>window.removeEventListener(zf,a)},[]),t===null?o.jsx("div",{className:"flex w-screen items-center justify-center bg-background text-muted-foreground",style:{height:"var(--app-vh, 100vh)"},children:r?`${e("common.error")}: ${r}`:e("common.loading")}):t.enabled&&!t.authenticated?o.jsx(Yte,{onLoginSuccess:i}):o.jsx(Vte,{})}i_.createRoot(document.getElementById("root")).render(o.jsx(D.StrictMode,{children:o.jsx(CR,{children:o.jsx(dS,{children:(()=>{const e=new URLSearchParams(window.location.search);return e.get("dag-playground")==="1"?o.jsx(Kte,{}):e.get("diff-review-lab")==="1"?o.jsx(Jte,{}):e.get("diff-lab")==="1"?o.jsx(Xte,{}):o.jsx(sne,{})})()})})}));export{nM as M,Us as R,VM as S,g0 as _,aM as a,cM as b,kt as c,o as j,Yn as u,QL as v};
456
+ }`}};function x7(){if(typeof window>"u")return"kotlin";const t=new URLSearchParams(window.location.search).get("fixture");return t&&t in V2?t:"kotlin"}function b7(){return typeof window>"u"?"unified":new URLSearchParams(window.location.search).get("view")==="split"?"split":"unified"}function y7(){if(typeof window>"u")return"words";const e=new URLSearchParams(window.location.search).get("inline");return e==="none"||e==="chars"||e==="words"?e:"words"}function v7(){return typeof window>"u"?!0:new URLSearchParams(window.location.search).get("wrap")!=="off"}function ene(){const[e,t]=b.useState(()=>x7()),[n,r]=b.useState(()=>b7()),[s,i]=b.useState(()=>y7()),[a,c]=b.useState(()=>v7()),u=V2[e],f=b.useMemo(()=>Object.entries(V2),[]);return b.useEffect(()=>{if(typeof window>"u")return;let p=window.location.search;const g=()=>{window.location.search!==p&&(p=window.location.search,t(x7()),r(b7()),i(y7()),c(v7()))};window.addEventListener("popstate",g),window.addEventListener("pageshow",g),window.addEventListener("focus",g);const y=window.setInterval(g,250);return()=>{window.removeEventListener("popstate",g),window.removeEventListener("pageshow",g),window.removeEventListener("focus",g),window.clearInterval(y)}},[]),o.jsx("div",{className:"min-h-screen bg-background-subtle text-foreground","data-diff-lab":!0,"data-diff-lab-fixture":e,"data-diff-lab-view":n,"data-diff-lab-inline":s,"data-diff-lab-wrap":a?"on":"off",children:o.jsxs("div",{className:"mx-auto flex min-h-screen max-w-[1180px] flex-col px-4 py-4",children:[o.jsxs("header",{className:"mb-3 flex flex-wrap items-center justify-between gap-3 border-b border-border/20 pb-3",children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-sm font-semibold",children:"Diff Lab"}),o.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Fixed fixtures for iterating diff rendering without app auth, PWA state, or live Git data."})]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx("select",{value:e,onChange:p=>t(p.target.value),"aria-label":"Fixture",className:"h-8 rounded-md border border-border/30 bg-surface px-2 text-xs text-foreground outline-none",children:f.map(([p,g])=>o.jsx("option",{value:p,children:g.label},p))}),o.jsxs("div",{className:"inline-flex h-8 overflow-hidden rounded-full bg-surface-2 p-0.5",children:[o.jsx("button",{type:"button",onClick:()=>r("unified"),className:`rounded-full px-3 text-xs font-semibold ${n==="unified"?"bg-surface-elevated text-foreground":"text-muted-foreground"}`,children:"Unified"}),o.jsx("button",{type:"button",onClick:()=>r("split"),className:`rounded-full px-3 text-xs font-semibold ${n==="split"?"bg-surface-elevated text-foreground":"text-muted-foreground"}`,children:"Split"})]}),o.jsx("div",{className:"inline-flex h-8 overflow-hidden rounded-full bg-surface-2 p-0.5",children:["none","words","chars"].map(p=>o.jsx("button",{type:"button",onClick:()=>i(p),className:`rounded-full px-3 text-xs font-semibold ${s===p?"bg-surface-elevated text-foreground":"text-muted-foreground"}`,children:p},p))}),o.jsxs("button",{type:"button",onClick:()=>c(p=>!p),className:`h-8 rounded-full px-3 text-xs font-semibold ${a?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground"}`,children:["Wrap ",a?"on":"off"]})]})]}),o.jsx("main",{className:"min-h-0 flex-1 overflow-auto rounded-lg border border-border/20 bg-surface",children:o.jsx(yT,{filePath:u.path,repoRoot:"/tmp/termdock-diff-lab",changedFile:{path:u.path,absolutePath:`/tmp/termdock-diff-lab/${u.path}`,repoRoot:"/tmp/termdock-diff-lab",status:"modified",staged:!1,unstaged:!0,untracked:!1,tracked:!0,canStage:!1,canUnstage:!1,canStash:!1,canRestoreWorktree:!1},diffOverride:u.diff,oldSourceOverride:u.oldSource,active:!0,wrap:a,showScrollHint:!a,viewType:n,inlineMode:s})})]})})}const AC=40,q2="/tmp/termdock-diff-review-lab";function w7(e,t){const n=[`diff --git a/${e} b/${e}`,`--- a/${e}`,`+++ b/${e}`,`@@ -1,${t} +1,${t} @@`];for(let r=0;r<t;r+=1)r%5===0&&n.push(`-const removed_${r} = ${r};`),r%3===0&&n.push(`+const added_${r} = ${r} * 2;`),n.push(` context line ${r} in ${e}`);return n.join(`
457
+ `)}function tne(e,t){return Array.from({length:AC},(n,r)=>{const s=6+r*7%60,i=`src/module${String(r).padStart(2,"0")}/File${r}.ts`,a=`${q2}/${i}`,c=w7(i,s),u=w7(i,1);return{key:a,path:i,absolutePath:a,status:"modified",repoRoot:q2,displayName:`File${r}.ts`,displayDir:`src/module${String(r).padStart(2,"0")} · ${s} lines`,diffOverride:!t||e.has(r)?c:u,auditRecords:[]}})}function nne(){const e=b.useMemo(()=>{if(typeof window>"u")return 0;const L=new URLSearchParams(window.location.search).get("delay"),I=L===null?0:Number.parseInt(L,10);return Number.isInteger(I)&&I>0?I:0},[]),t=e>0,[n,r]=b.useState(()=>new Set);b.useEffect(()=>{if(!t)return;const L=Array.from({length:AC},(I,j)=>window.setTimeout(()=>{r(P=>{const F=new Set(P);return F.add(j),F})},e+j*20));return()=>L.forEach(I=>window.clearTimeout(I))},[t,e]);const s=b.useMemo(()=>tne(n,t),[n,t]),i=b.useMemo(()=>[{key:"mock-repo",root:q2,label:"diff-review-lab",files:s.map(L=>({key:L.key,path:L.path,absolutePath:L.absolutePath,displayName:L.displayName,displayDir:L.displayDir,status:L.status}))}],[s]),a=b.useMemo(()=>{if(typeof window>"u")return null;const L=new URLSearchParams(window.location.search).get("select");if(L===null)return null;const I=Number.parseInt(L,10);return Number.isInteger(I)&&I>=0&&I<s.length?I:null},[s.length]),[c,u]=b.useState(()=>a!==null?s[a].key:null),[f,p]=b.useState(()=>({key:a!==null?s[a].key:null,nonce:a!==null?1:0})),[g,y]=b.useState("list"),[v,S]=b.useState(new Set),[A,T]=b.useState(a!==null?1:0);return o.jsxs("div",{className:"flex h-screen flex-col bg-background text-foreground","data-diff-review-lab":!0,children:[o.jsxs("div",{className:"shrink-0 border-b border-border/20 px-3 py-2 text-xs text-muted-foreground",children:["DiffReview Lab · ",s.length," mock files · selected: ",o.jsx("span",{"data-lab-selected":!0,children:c??"none"})," · slide ",A]}),o.jsx("div",{className:"min-h-0 flex-1",children:o.jsx(eg,{mobile:!0,backLabel:"Back",files:s,groups:i,selectedKey:c,scrollToKey:f.key,scrollToKeyNonce:f.nonce,mode:g,onModeChange:L=>{L!=="ai"&&y(L)},collapsedDirectoryKeys:v,onToggleDirectory:L=>S(I=>{const j=new Set(I);return j.has(L)?j.delete(L):j.add(L),j}),onSelectFile:L=>{u(L.key),p(I=>({key:L.key,nonce:I.nonce+1}))},onMobileSlideChange:T,renderLeading:()=>null,renderStreamBadge:L=>o.jsx("span",{className:"text-[10px] text-muted-foreground",children:L}),wrap:!0,showScrollHint:!1,activePane:!0})})]})}const rne=6e4,mb="termdock:build-id:v1";let S7=!1;function A7(){S7||(S7=!0,window.setTimeout(()=>{window.location.reload()},80))}function Y2(e){e.waiting?.postMessage({type:"SKIP_WAITING"})}async function sne(){if(typeof caches>"u")return;const e=await caches.keys();await Promise.all(e.map(t=>caches.delete(t)))}function ine(e){e.addEventListener("updatefound",()=>{const t=e.installing;t&&t.addEventListener("statechange",()=>{t.state==="installed"&&navigator.serviceWorker.controller&&Y2(e)})})}function one(){if(typeof window>"u"||!("serviceWorker"in navigator))return;const e="1788233610517",t=window.localStorage.getItem(mb);if(t&&t!==e){sne().finally(()=>{window.localStorage.setItem(mb,e),A7()});return}t!==e&&window.localStorage.setItem(mb,e);let n=null;navigator.serviceWorker.addEventListener("controllerchange",A7),window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js",{scope:"/"}).then(r=>{ine(r),Y2(r);const s=()=>{document.visibilityState==="visible"&&r.update().then(()=>Y2(r)).catch(()=>{})};s(),n=window.setInterval(s,rne),document.addEventListener("visibilitychange",s)}).catch(()=>{})}),window.addEventListener("beforeunload",()=>{n!==null&&window.clearInterval(n)})}sO();one();try{const e=JSON.parse(window.localStorage.getItem("termdock-color-theme")||"null");(e==="dark"||e==="light")&&(document.documentElement.dataset.theme=e,i9(e))}catch{}function ane(){const{t:e}=Yn(),[t,n]=b.useState(null),[r,s]=b.useState(null),i=b.useCallback(async()=>{try{const a=await OE();n(a),s(null)}catch(a){s(a instanceof Error?a.message:"Failed to query auth status")}},[]);return b.useEffect(()=>{i()},[i]),b.useEffect(()=>{const a=()=>{n(c=>c&&{...c,authenticated:!1})};return window.addEventListener(zf,a),()=>window.removeEventListener(zf,a)},[]),t===null?o.jsx("div",{className:"flex w-screen items-center justify-center bg-background text-muted-foreground",style:{height:"var(--app-vh, 100vh)"},children:r?`${e("common.error")}: ${r}`:e("common.loading")}):t.enabled&&!t.authenticated?o.jsx(Zte,{onLoginSuccess:i}):o.jsx(Kte,{})}i_.createRoot(document.getElementById("root")).render(o.jsx(D.StrictMode,{children:o.jsx(CR,{children:o.jsx(dS,{children:(()=>{const e=new URLSearchParams(window.location.search);return e.get("dag-playground")==="1"?o.jsx(Jte,{}):e.get("diff-review-lab")==="1"?o.jsx(nne,{}):e.get("diff-lab")==="1"?o.jsx(ene,{}):o.jsx(ane,{})})()})})}));export{nM as M,Us as R,VM as S,g0 as _,aM as a,cM as b,kt as c,o as j,Yn as u,QL as v};