import{r as i,j as e}from"./vendor-markdown-CkTmV-He.js";import{u as o,a as k,h as y,D as W}from"./index-CKH_4wKU.js";import"./vendor-react-DAm3T7tM.js";import"./vendor-analytics-Bg9iiwD1.js";import"./vendor-diff-R4VRD87i.js";function E({status:c}){return c==="created"?e.jsx("span",{className:"w-3.5 h-3.5 shrink-0 flex items-center justify-center rounded-sm text-[10px] font-bold leading-none bg-green-500/20 text-green-400",children:"A"}):c==="deleted"?e.jsx("span",{className:"w-3.5 h-3.5 shrink-0 flex items-center justify-center rounded-sm text-[10px] font-bold leading-none bg-red-500/20 text-red-400",children:"D"}):e.jsx("span",{className:"w-3.5 h-3.5 shrink-0 flex items-center justify-center rounded-sm text-[10px] font-bold leading-none bg-cc-warning/20 text-cc-warning",children:"M"})}function V({sessionId:c}){const p=o(t=>t.sessions.get(c)),g=o(t=>t.sdkSessions.find(r=>r.sessionId===c)),s=o(t=>t.diffPanelSelectedFile.get(c)??null),f=o(t=>t.setDiffPanelSelectedFile),d=o(t=>t.diffBase),C=o(t=>t.setDiffBase),F=o(t=>t.changedFilesTick.get(c)??0),n=(p==null?void 0:p.cwd)||(g==null?void 0:g.cwd),[S,b]=i.useState(""),[D,j]=i.useState(!1),[x,h]=i.useState(()=>typeof window<"u"?window.innerWidth>=640:!0),[A,v]=i.useState([]),w=o(t=>t.setGitChangedFilesCount);i.useEffect(()=>{if(!n)return;let t=!1;return k.getChangedFiles(n,d).then(({files:r})=>{if(t)return;const m=`${n}/`,N=r.filter(l=>l.path===n||l.path.startsWith(m)).map(l=>({abs:l.path,rel:l.path.startsWith(m)?l.path.slice(m.length):l.path,status:l.status==="A"||l.status==="?"?"created":l.status==="D"?"deleted":"updated"})).sort((l,M)=>l.rel.localeCompare(M.rel));v(N),w(c,N.length)}).catch(r=>{t||(v([]),w(c,0),y(r,"load changed files"))}),()=>{t=!0}},[n,d,F,c,w]);const a=A;i.useEffect(()=>{!s&&a.length>0&&f(c,a[0].abs)},[s,a,c,f]),i.useEffect(()=>{var t;s&&(a.some(r=>r.abs===s)||f(c,((t=a[0])==null?void 0:t.abs)??null))},[s,a,c,f]),i.useEffect(()=>{if(!s){b("");return}let t=!1;return j(!0),k.getFileDiff(s,d).then(r=>{t||(b(r.diff),j(!1))}).catch(r=>{t||(b(""),j(!1),y(r,"load file diff"))}),()=>{t=!0}},[s,d]);const B=i.useCallback(t=>{f(c,t),typeof window<"u"&&window.innerWidth<640&&h(!1)},[c,f]),u=i.useMemo(()=>!s||!n?s:s.startsWith(n+"/")?s.slice(n.length+1):s,[s,n]);return n?a.length===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-4 select-none px-6",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-cc-card border border-cc-border flex items-center justify-center",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-7 h-7 text-cc-muted",children:e.jsx("path",{d:"M12 3v18M3 12h18",strokeLinecap:"round"})})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-sm text-cc-fg font-medium mb-1",children:"No changes yet"}),e.jsx("p",{className:"text-xs text-cc-muted leading-relaxed",children:"File changes compared to the base will appear here once the agent edits files."})]})]}):e.jsxs("div",{className:"h-full flex bg-cc-bg relative",children:[x&&e.jsx("div",{className:"fixed inset-0 bg-black/30 z-20 sm:hidden",onClick:()=>h(!1)}),e.jsxs("div",{className:`
          ${x?"w-[220px] translate-x-0":"w-0 -translate-x-full"}
          fixed sm:relative z-30 sm:z-auto
          ${x?"sm:w-[220px]":"sm:w-0 sm:-translate-x-full"}
          shrink-0 h-full flex flex-col bg-cc-sidebar border-r border-cc-border transition-all duration-200 overflow-hidden
        `,children:[e.jsxs("div",{className:"w-[220px] px-4 py-3 text-[11px] font-semibold text-cc-fg uppercase tracking-wider border-b border-cc-border shrink-0 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-warning"}),e.jsxs("span",{children:["Changed (",a.length,")"]})]}),e.jsx("button",{onClick:()=>h(!1),className:"w-5 h-5 flex items-center justify-center rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer sm:hidden",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3 h-3",children:e.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto overflow-x-hidden py-1",children:a.map(({abs:t,rel:r,status:m})=>e.jsxs("button",{onClick:()=>B(t),className:`flex items-center gap-2 w-full mx-1 px-2 py-1.5 text-[13px] rounded-[10px] hover:bg-cc-hover transition-colors cursor-pointer whitespace-nowrap ${t===s?"bg-cc-active text-cc-fg":"text-cc-fg/70"}`,style:{width:"calc(100% - 8px)"},children:[e.jsx(E,{status:m}),e.jsx("span",{className:"truncate leading-snug",children:r})]},t))})]}),e.jsxs("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[s&&e.jsxs("div",{className:"shrink-0 flex items-center gap-2 sm:gap-2.5 px-2 sm:px-4 py-2.5 bg-cc-card border-b border-cc-border",children:[!x&&e.jsx("button",{onClick:()=>h(!0),className:"flex items-center justify-center w-6 h-6 rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer shrink-0",title:"Show file list",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-cc-fg text-[13px] font-medium truncate block",children:u==null?void 0:u.split("/").pop()}),e.jsx("span",{className:"text-cc-muted truncate text-[11px] hidden sm:block font-mono-code",children:u})]}),e.jsx("button",{onClick:()=>C(d==="last-commit"?"default-branch":"last-commit"),className:"text-cc-muted text-[11px] shrink-0 hidden sm:inline hover:text-cc-fg transition-colors cursor-pointer",title:`Switch to ${d==="last-commit"?"default branch":"last commit"} comparison`,children:d==="default-branch"?"vs default branch":"vs last commit"})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:D?e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx("div",{className:"w-5 h-5 border-2 border-cc-primary border-t-transparent rounded-full animate-spin"})}):s?e.jsx("div",{className:"p-4",children:e.jsx(W,{unifiedDiff:S,fileName:u||void 0,mode:"full"})}):e.jsxs("div",{className:"h-full flex flex-col items-center justify-center",children:[!x&&e.jsxs("button",{onClick:()=>h(!0),className:"mb-4 flex items-center gap-2 px-3 py-2 rounded-lg text-xs text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),"Show file list"]}),e.jsx("p",{className:"text-cc-muted text-sm",children:"Select a file to view changes"})]})})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:e.jsx("p",{className:"text-cc-muted text-sm",children:"Waiting for session to initialize..."})})}export{V as DiffPanel};
