import{u as F,r as n,j as e}from"./index-gnHkq9KV.js";import{c as S}from"./CopyButton-CwvIhVJc.js";function M(u){return u.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function P(u){if(!u||u==="No changes")return[];const r=[],i=u.split(`
`);let l=null;for(let t=0;t<i.length;t++){const s=i[t];if(s.startsWith("diff --git ")){l&&r.push(l);const o=s.match(/diff --git a\/(.*?) b\/(.*)/);l={name:o?o[2]:s.substring(11),additions:0,deletions:0,startLine:t}}else l&&(s.startsWith("+")&&!s.startsWith("+++")?l.additions++:s.startsWith("-")&&!s.startsWith("---")&&l.deletions++)}return l&&r.push(l),r}function I(u){let r="",i=0,l=0;for(const t of u){const s=M(t);if(t.startsWith("diff --git "))r+=`<div class="diff-file-header">${s}</div>`;else if(t.startsWith("@@")){const o=t.match(/@@ -(\d+)/);o&&(i=parseInt(o[1]));const m=t.match(/@@ -\d+(?:,\d+)? \+(\d+)/);m&&(l=parseInt(m[1])),r+=`<div class="diff-hunk-header">${s}</div>`}else t.startsWith("---")||t.startsWith("+++")||t.startsWith("index ")||t.startsWith("new file")||t.startsWith("deleted file")||t.startsWith("old mode")||t.startsWith("new mode")||t.startsWith("similarity index")||t.startsWith("rename from")||t.startsWith("rename to")||t.startsWith("Binary files")?r+=`<div class="diff-meta-line">${s}</div>`:t.startsWith("+")?(r+=`<div class="diff-line diff-line-add"><span class="diff-line-num diff-line-num-old"></span><span class="diff-line-num diff-line-num-new">${l}</span><span class="diff-line-content">${s}</span></div>`,l++):t.startsWith("-")?(r+=`<div class="diff-line diff-line-del"><span class="diff-line-num diff-line-num-old">${i}</span><span class="diff-line-num diff-line-num-new"></span><span class="diff-line-content">${s}</span></div>`,i++):(r+=`<div class="diff-line diff-line-ctx"><span class="diff-line-num diff-line-num-old">${i||""}</span><span class="diff-line-num diff-line-num-new">${l||""}</span><span class="diff-line-content">${s}</span></div>`,i&&i++,l&&l++)}return r}function H(u,r){const i=u.split(`
`);let l=!1;const t=[];for(const s of i){if(s.startsWith("diff --git ")){if(l)break;const o=s.match(/diff --git a\/(.*?) b\/(.*)/);(o?o[2]:"")===r&&(l=!0)}l&&t.push(s)}return I(t)}function V({open:u,title:r,rawDiff:i,loading:l,onClose:t}){const{t:s}=F(),[o,m]=n.useState(null),[x,j]=n.useState(!1),a=n.useMemo(()=>P(i),[i]),v=a.reduce((c,d)=>c+d.additions,0),b=a.reduce((c,d)=>c+d.deletions,0),N=!i||!i.trim()||i==="No changes"||i==="No modified files",k=n.useMemo(()=>N?`<div class="diff-empty-state"><span class="text-dim">${s("No modified files")}</span></div>`:o?H(i,o):I(i.split(`
`)),[i,o,N]),C=n.useCallback(()=>{S(i).then(()=>{j(!0),setTimeout(()=>j(!1),2e3)}).catch(()=>{})},[i]),w=n.useCallback(c=>{m(d=>d===c?null:c)},[]);return u?e.jsx("div",{className:"diff-modal-overlay",onClick:t,children:e.jsxs("div",{className:"diff-modal",onClick:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"diff-modal-header",children:[e.jsx("h3",{className:"viewer-title",children:r}),!N&&e.jsxs("div",{className:"diff-modal-stats",children:[e.jsxs("span",{className:"diff-stat-files",children:[a.length," ",s(a.length===1?"file changed":"files changed")]}),e.jsxs("span",{className:"diff-stat-add",children:["+",v]}),e.jsxs("span",{className:"diff-stat-del",children:["-",b]})]}),e.jsxs("div",{className:"viewer-actions",children:[!N&&e.jsx("button",{className:`btn btn-sm${x?" copied":""}`,onClick:C,children:s(x?"Copied!":"Copy Raw")}),e.jsx("button",{className:"btn btn-sm",onClick:t,children:s("Close")})]})]}),e.jsxs("div",{className:"diff-modal-body",children:[a.length>0&&e.jsxs("div",{className:"diff-file-nav",children:[e.jsxs("div",{className:"diff-file-nav-header",children:[s("Files")," (",a.length,")"]}),a.map(c=>{const d=c.name.split("/"),p=d.pop()||c.name,h=d.join("/");return e.jsxs("div",{className:`diff-file-nav-item${o===c.name?" active":""}`,onClick:()=>w(c.name),children:[e.jsx("span",{className:"diff-file-nav-name",children:p}),h&&e.jsxs("span",{className:"diff-file-nav-path",children:[h,"/"]}),e.jsxs("div",{className:"diff-file-nav-counts",children:[e.jsxs("span",{className:"diff-file-nav-add",children:["+",c.additions]}),e.jsxs("span",{className:"diff-file-nav-del",children:["-",c.deletions]})]})]},c.name)})]}),e.jsx("div",{className:"diff-content-wrap",children:l?e.jsx("div",{className:"diff-content-area",children:e.jsx("div",{className:"diff-empty-state",children:e.jsx("span",{className:"text-dim",children:s("Loading diff...")})})}):e.jsx("div",{className:"diff-content-area",dangerouslySetInnerHTML:{__html:k}})})]})]})}):null}const _=[100,200,500,1e3];function A({open:u,title:r,content:i,totalLines:l,loading:t,completed:s,onClose:o,onLineCountChange:m,onRefresh:x,defaultLineCount:j=200}){const{t:a}=F(),[v,b]=n.useState(!1),[N,k]=n.useState(j),[C,w]=n.useState(!1),c=n.useRef(null),d=n.useRef(x);d.current=x;const p=n.useRef(null),h=n.useRef(!1),W=n.useCallback(()=>{var f;p.current||(h.current=!0,b(!0),(f=d.current)==null||f.call(d),p.current=setInterval(()=>{var $;h.current&&(($=d.current)==null||$.call(d))},1e3))},[]),g=n.useCallback(()=>{h.current=!1,b(!1),p.current&&(clearInterval(p.current),p.current=null)},[]),T=n.useCallback(()=>{h.current?g():W()},[W,g]);n.useEffect(()=>{h.current&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},[i]);const y=n.useRef(s);n.useEffect(()=>{var f;s&&!y.current&&h.current&&((f=d.current)==null||f.call(d),g()),y.current=s},[s,g]),n.useEffect(()=>()=>{p.current&&(clearInterval(p.current),p.current=null),h.current=!1},[]),n.useEffect(()=>{!u&&h.current&&g()},[u,g]);const E=n.useCallback(f=>{k(f),m==null||m(f)},[m]),L=n.useCallback(()=>{S(i).then(()=>{w(!0),setTimeout(()=>w(!1),2e3)}).catch(()=>{})},[i]);return u?e.jsx("div",{className:"viewer-overlay",onClick:o,children:e.jsxs("div",{className:"viewer-modal",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"viewer-header",children:[e.jsxs("h3",{className:"viewer-title",children:[r,s&&e.jsx("span",{className:"log-live-badge",style:{background:"var(--tag-complete-bg, #2d4a2d)",color:"var(--tag-complete-fg, #6fcf6f)"},children:a("Done")}),v&&!s&&e.jsx("span",{className:"log-live-badge",children:a("Live")})]}),e.jsxs("div",{className:"viewer-actions",children:[e.jsx("select",{className:"log-line-select",value:N,onChange:f=>E(parseInt(f.target.value,10)),children:_.map(f=>e.jsxs("option",{value:f,children:[f," ",a("lines")]},f))}),x&&!s&&e.jsxs("button",{className:`btn btn-sm ${v?"btn-follow-active":"btn-follow-inactive"}`,onClick:T,title:a(v?"Stop following":"Follow (auto-refresh)"),children:[e.jsx("span",{className:`follow-dot${v?" follow-dot-active":""}`}),a(v?"Following":"Follow")]}),s&&e.jsx("span",{style:{fontSize:"0.8em",color:"var(--text-dim)",padding:"0.25rem 0.5rem"},children:a("Completed")}),e.jsx("button",{className:`btn btn-sm${C?" copied":""}`,onClick:L,children:a(C?"Copied!":"Copy")}),e.jsx("button",{className:"btn btn-sm",onClick:o,children:a("Close")})]})]}),e.jsx("div",{className:"viewer-body-wrap",children:e.jsx("div",{ref:c,className:`viewer-body${v?"":" log-paused"}`,id:"log-viewer-content","data-i18n-skip":"true",children:t?a("Loading..."):i||a("No log output")})}),l!==void 0&&e.jsxs("div",{style:{padding:"0.4rem 1.25rem",borderTop:"1px solid var(--border)",fontSize:"0.75rem",color:"var(--text-dim)"},children:[a("Total lines"),": ",l]})]})}):null}export{V as D,A as L};
