clitrigger 0.2.68 → 0.2.69
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.
- package/dist/client/assets/{AnalyticsPanel-Df6PTxhA.js → AnalyticsPanel-Dr9Zypd4.js} +1 -1
- package/dist/client/assets/{CalendarGrid-Bsrf2InF.js → CalendarGrid-BRVf7WJK.js} +1 -1
- package/dist/client/assets/{DiscussionDetail-CpPbB3D-.js → DiscussionDetail-DetjETsr.js} +1 -1
- package/dist/client/assets/{DiscussionForm-DASNXVl-.js → DiscussionForm-Bi4L47Ly.js} +1 -1
- package/dist/client/assets/{EmptyState-BauJBCrW.js → EmptyState--9RqKIk6.js} +1 -1
- package/dist/client/assets/{FloatingComposerController-5A3GJtK4-K4SWepH8.js → FloatingComposerController-5A3GJtK4-85zrcVy6.js} +1 -1
- package/dist/client/assets/{LogViewer-zauAgB6I.js → LogViewer-BDuckIDB.js} +1 -1
- package/dist/client/assets/{MarkdownContent-B3oEjGwC.js → MarkdownContent-CwGbW814.js} +1 -1
- package/dist/client/assets/{PersonalAgenda-C8P8R7BW.js → PersonalAgenda-JNpWPEDQ.js} +1 -1
- package/dist/client/assets/{PlannerPageEditor-DPXI3Zfq.js → PlannerPageEditor-9_jJ-l98.js} +3 -3
- package/dist/client/assets/{ProjectDetail-eFpOIAWj.js → ProjectDetail-DwN6S3uf.js} +4 -4
- package/dist/client/assets/{ProjectList-BJo-FMR3.js → ProjectList-LeZ7mrEM.js} +1 -1
- package/dist/client/assets/{ReviewQueue-Bc7VQ6Gf.js → ReviewQueue-DzTHqZdO.js} +1 -1
- package/dist/client/assets/{TaskGraph-B97ITa4c.js → TaskGraph-BrHxqYJn.js} +1 -1
- package/dist/client/assets/{VaultLayout-CUbPgHod.js → VaultLayout-DftlF-Gd.js} +1 -1
- package/dist/client/assets/{folder-git-2-BqhO_WrT.js → folder-git-2-DocDG5LN.js} +1 -1
- package/dist/client/assets/{index-DxjV2Q9W.js → index--CryAcdA.js} +3 -3
- package/dist/client/assets/{rotate-ccw-aXuj01G0.js → rotate-ccw-CY6Wl56G.js} +1 -1
- package/dist/client/assets/{style-9nX9ra-f.js → style-D7Mv0Jex.js} +1 -1
- package/dist/client/assets/{with-selector-vbW186xh.js → with-selector-bSOP5zTp.js} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-
|
|
2
|
-
import{c as Fe,o as xt,p as lt,q as Gt,s as Yt,a as ye,j as e,r as s,t as Xa,R as Za,C as ms,v as St,w as Qa,x as er,y as tr,z as Wt,F as sr,A as nr,G as xs,T as Bt,I as Tt,B as ar,D as rr,M as vt,H as lr,E as en,J as Ws,X as ft,d as _t,K as ir,N as _s,O as Rt,Q as Kt,U as wt,V as mt,W as bs,Y as or,Z as jt,P as gt,_ as hs,$ as cr,a0 as dr,a1 as Ms,a2 as Bs,a3 as ur,a4 as mr,a5 as xr,a6 as Yn,a7 as hr,a8 as pr,a9 as tn,aa as Ds,ab as fr,ac as gr,ad as Jn,ae as ps,af as br,ag as qn,ah as Xn,ai as vr,aj as wr,ak as sn,al as yr,am as jr,an as Nr,ao as kr,ap as Zn,aq as Qn,ar as ea,as as Cr,at as Es,au as Ts,av as ta,aw as nn,ax as Sr,ay as _r,az as Mr,aA as Dr,aB as an,aC as rn,aD as Ze,aE as Er,u as Tr,aF as Rr,aG as sa,aH as $r,aI as Lr,aJ as Fr,aK as zr,aL as Pr,aM as Ar,aN as ln,aO as Rs,aP as $s,aQ as on,L as na,b as aa,aR as Ir,aS as Hr,aT as Or,aU as Wr,aV as Br,aW as Kr,aX as Ur,aY as Vr,aZ as Gr,a_ as Yr,a$ as Jr,b0 as qr,b1 as Xr,b2 as Zr,i as pt,b3 as Qr}from"./index
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-BrHxqYJn.js","assets/index--CryAcdA.js","assets/index-xIZH9sMw.css","assets/style-D7Mv0Jex.js","assets/value-BTdN53H7.js","assets/with-selector-bSOP5zTp.js","assets/style-BZV40eAE.css","assets/DiscussionForm-Bi4L47Ly.js","assets/rotate-ccw-CY6Wl56G.js","assets/LogViewer-BDuckIDB.js","assets/MarkdownContent-CwGbW814.js","assets/CalendarGrid-BRVf7WJK.js","assets/EmptyState--9RqKIk6.js","assets/PlannerPageEditor-9_jJ-l98.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-Dr9Zypd4.js","assets/VaultLayout-DftlF-Gd.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as Fe,o as xt,p as lt,q as Gt,s as Yt,a as ye,j as e,r as s,t as Xa,R as Za,C as ms,v as St,w as Qa,x as er,y as tr,z as Wt,F as sr,A as nr,G as xs,T as Bt,I as Tt,B as ar,D as rr,M as vt,H as lr,E as en,J as Ws,X as ft,d as _t,K as ir,N as _s,O as Rt,Q as Kt,U as wt,V as mt,W as bs,Y as or,Z as jt,P as gt,_ as hs,$ as cr,a0 as dr,a1 as Ms,a2 as Bs,a3 as ur,a4 as mr,a5 as xr,a6 as Yn,a7 as hr,a8 as pr,a9 as tn,aa as Ds,ab as fr,ac as gr,ad as Jn,ae as ps,af as br,ag as qn,ah as Xn,ai as vr,aj as wr,ak as sn,al as yr,am as jr,an as Nr,ao as kr,ap as Zn,aq as Qn,ar as ea,as as Cr,at as Es,au as Ts,av as ta,aw as nn,ax as Sr,ay as _r,az as Mr,aA as Dr,aB as an,aC as rn,aD as Ze,aE as Er,u as Tr,aF as Rr,aG as sa,aH as $r,aI as Lr,aJ as Fr,aK as zr,aL as Pr,aM as Ar,aN as ln,aO as Rs,aP as $s,aQ as on,L as na,b as aa,aR as Ir,aS as Hr,aT as Or,aU as Wr,aV as Br,aW as Kr,aX as Ur,aY as Vr,aZ as Gr,a_ as Yr,a$ as Jr,b0 as qr,b1 as Xr,b2 as Zr,i as pt,b3 as Qr}from"./index--CryAcdA.js";import{I as Ut,C as zt,a as yt,c as Be,b as Ks,d as ra,i as $t,D as la,e as ia,y as Jt,u as el,f as tl,g as sl,h as nl,s as al,H as cn}from"./CalendarGrid-BRVf7WJK.js";import{p as rs,g as Ls,a as rl,b as ll,T as dn,u as oa,d as il,L as ol,c as cl,e as vs,f as un,s as mn,h as dl,i as ul,j as qt,m as ml,k as xl,l as hl,r as pl,n as fl}from"./LogViewer-BDuckIDB.js";import{V as ca,G as Fs,E as xn,F as ss,C as gl,P as da,u as bl,c as vl,d as wl,g as yl,a as jl,D as Nl,b as hn,s as kl,e as Cl,f as Sl}from"./DiscussionForm-Bi4L47Ly.js";import{R as Vt,C as _l}from"./rotate-ccw-CY6Wl56G.js";import{E as At}from"./EmptyState--9RqKIk6.js";/**
|
|
3
3
|
* @license lucide-react v1.8.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -160,7 +160,7 @@ import{c as Fe,o as xt,p as lt,q as Gt,s as Yt,a as ye,j as e,r as s,t as Xa,R a
|
|
|
160
160
|
* This source code is licensed under the ISC license.
|
|
161
161
|
* See the LICENSE file in the root directory of this source tree.
|
|
162
162
|
*/const Si=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],_i=Fe("users",Si);function wn(t){return xt(`/api/projects/${t}/schedules`)}function Mi(t,n){return lt(`/api/projects/${t}/schedules`,n)}function Di(t,n){return Yt(`/api/schedules/${t}`,n)}function Ei(t,n,r=!1){return lt(`/api/todos/${t}/schedule`,{run_at:n,keep_original:r})}function Ti(t){return Gt(`/api/schedules/${t}`)}function Ri(t){return lt(`/api/schedules/${t}/activate`)}function $i(t){return lt(`/api/schedules/${t}/pause`)}function ws(t){return xt(`/api/schedules/${t}/runs`)}function Li(t){return lt(`/api/schedules/${t}/trigger`)}function Fi(){return xt("/api/rate-limit")}function zi(t,n){return lt(`/api/todos/${t}/schedule-on-reset`,{prompt:n})}function Xt(t){return xt(`/api/projects/${t}/planner`)}function Zt(t){return xt(`/api/projects/${t}/planner/tags`)}function Pi(t,n,r){return Yt(`/api/projects/${t}/planner/tags/${encodeURIComponent(n)}`,r)}function Ai(t,n){return Gt(`/api/projects/${t}/planner/tags/${encodeURIComponent(n)}`)}function Ii(t,n){return lt(`/api/projects/${t}/planner`,n)}function Hi(t,n){return Yt(`/api/planner/${t}`,n)}function Oi(t){return Gt(`/api/planner/${t}`)}function Wi(t){return xt(`/api/projects/${t}/planner/pages`)}function Bi(t,n,r){return lt(`/api/projects/${t}/planner/pages`,{title:n,content:r})}function Ki(t){return xt(`/api/planner/pages/${t}`)}function Ui(t,n){return Yt(`/api/planner/pages/${t}`,n)}function Vi(t){return Gt(`/api/planner/pages/${t}`)}function Qc(t){return xt(`/api/planner/pages/${t}/items`)}function Gi(t,n){return lt(`/api/planner/${t}/convert-to-todo`,n)}function ma(t,n){return lt(`/api/planner/${t}/images`,{images:n})}function xa(t,n){return Gt(`/api/planner/${t}/images/${n}`)}function os(t,n){return`/api/planner/${t}/images/${n}`}async function ed(t,n){const r=await new Promise((l,a)=>{const c=new FileReader;c.onload=()=>l(c.result),c.onerror=()=>a(new Error("Failed to read file")),c.readAsDataURL(n)});return(await lt(`/api/planner/pages/${t}/files`,{name:n.name,data:r})).url}function Yi(t,n){return lt(`/api/planner/${t}/convert-to-schedule`,n)}function Ji(t,n){return lt(`/api/planner/${t}/convert-to-session`,n)}async function qi(t){const n=await fetch(`/api/projects/${t}/planner/export`,{credentials:"include"});if(n.status===401)throw window.dispatchEvent(new CustomEvent("auth:unauthorized")),new Error("Unauthorized");if(!n.ok){const c=await n.text().catch(()=>n.statusText);let x=c;try{const o=JSON.parse(c);o.error&&(x=o.error)}catch{}throw new Error(x||"Export failed")}const i=(n.headers.get("Content-Disposition")||"").match(/filename="?([^"]+)"?/i),l=i?i[1]:`planner-${t}.md`;return{blob:await n.blob(),filename:l}}async function Xi(t,n){const r=await fetch(`/api/projects/${t}/planner/import`,{method:"POST",credentials:"include",headers:{"Content-Type":"text/markdown; charset=utf-8"},body:n});if(r.status===401)throw window.dispatchEvent(new CustomEvent("auth:unauthorized")),new Error("Unauthorized");if(!r.ok){const i=await r.text().catch(()=>r.statusText);let l=i;try{const a=JSON.parse(i);a.error&&(l=a.error)}catch{}throw new Error(l||"Import failed")}return r.json()}function Zi(t,n){return xt(`/api/plugins/${t}/config/${n}`)}function Qi(t,n,r){return Yt(`/api/plugins/${t}/config/${n}`,r)}function ha(t){var n,r;return{maxRounds:((n=t==null?void 0:t.maxRounds)==null?void 0:n.toString())??"10",check:(t==null?void 0:t.check)??"",donePhrase:(t==null?void 0:t.donePhrase)??"",rules:(t==null?void 0:t.rules)??"",maxCostUsd:((r=t==null?void 0:t.maxCostUsd)==null?void 0:r.toString())??"",stopWhenNoChanges:(t==null?void 0:t.stopWhenNoChanges)??!0,resume:(t==null?void 0:t.resume)??!1}}function pa(t){const n=parseFloat(t.maxCostUsd);return{maxRounds:Math.min(50,Math.max(1,parseInt(t.maxRounds,10)||10)),check:t.check.trim()||void 0,donePhrase:t.donePhrase.trim()||void 0,rules:t.rules.trim()||void 0,maxCostUsd:n>0?n:void 0,stopWhenNoChanges:t.stopWhenNoChanges,resume:t.resume}}function fa({draft:t,onChange:n,showStallGuard:r}){const{t:i}=ye(),l=(a,c)=>n({...t,[a]:c});return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-2xs font-medium text-warm-500 mb-1",children:i("todoForm.loopMaxRounds")}),e.jsx("input",{type:"number",min:"1",max:"50",value:t.maxRounds,onChange:a=>l("maxRounds",a.target.value),className:"input-field text-sm w-24"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-2xs font-medium text-warm-500 mb-1",children:i("todoForm.loopMaxCost")}),e.jsx("input",{type:"number",min:"0",step:"0.5",placeholder:i("todoForm.loopMaxCostPlaceholder"),value:t.maxCostUsd,onChange:a=>l("maxCostUsd",a.target.value),className:"input-field text-sm w-28"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-2xs font-medium text-warm-500 mb-1",children:i("todoForm.loopCheck")}),e.jsx("input",{type:"text",placeholder:"npm test && npm run typecheck",value:t.check,onChange:a=>l("check",a.target.value),className:"input-field text-sm w-full font-mono"}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("todoForm.loopCheckHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-2xs font-medium text-warm-500 mb-1",children:i("todoForm.loopDonePhrase")}),e.jsx("input",{type:"text",placeholder:"<promise>DONE</promise>",value:t.donePhrase,onChange:a=>l("donePhrase",a.target.value),className:"input-field text-sm w-full font-mono"}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("todoForm.loopDonePhraseHint")})]}),!t.check.trim()&&!t.donePhrase.trim()&&e.jsx("p",{className:"text-2xs text-status-warning",children:i("todoForm.loopNoDoneRule")}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-2xs font-medium text-warm-500 mb-1",children:i("todoForm.loopRules")}),e.jsx("textarea",{rows:3,placeholder:i("todoForm.loopRulesPlaceholder"),value:t.rules,onChange:a=>l("rules",a.target.value),className:"input-field text-sm w-full resize-y"}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("todoForm.loopRulesHint")})]}),r&&e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.stopWhenNoChanges,onChange:a=>l("stopWhenNoChanges",a.target.checked),className:"rounded-md border-warm-300"}),e.jsx("span",{className:"text-xs text-warm-600",children:i("todoForm.loopStopWhenNoChanges")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.resume,onChange:a=>l("resume",a.target.checked),className:"rounded-md border-warm-300"}),e.jsx("span",{className:"text-xs text-warm-600",children:i("todoForm.loopResume")})]}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("todoForm.loopResumeHint")})]})]})}function Vs(){return xt("/api/cli/status")}function eo(){return lt("/api/cli/status/refresh")}const Ps=[{value:"claude",label:"Claude Code",supportsInteractive:!0},{value:"antigravity",label:"Antigravity CLI",supportsInteractive:!0},{value:"codex",label:"Codex CLI",supportsInteractive:!0},{value:"raw-shell",label:"Raw Shell",supportsInteractive:!0}],bt=Ps;function As(t){return Ps.find(n=>n.value===t)??Ps[0]}function to(t){return t.name.toLowerCase()==="cmd.exe"&&t.children.length===1?t.children[0]:t}function ga(t){return t.children.reduce((n,r)=>n+1+ga(r),0)}function ba(t){return`${Math.round(t/1048576)} MB`}function va({node:t,depth:n}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 py-0.5 min-w-0 whitespace-nowrap",style:{paddingLeft:n*12},title:t.command,children:[e.jsx("span",{className:"text-warm-700 shrink-0",children:t.name}),e.jsx("span",{className:"text-warm-400 shrink-0",children:t.pid}),e.jsx("span",{className:"text-warm-400 shrink-0",children:ba(t.memoryBytes)}),e.jsx("span",{className:"text-warm-400 truncate",children:t.command})]}),t.children.map(r=>e.jsx(va,{node:r,depth:n+1},r.pid))]})}function so({title:t,tree:n}){const{t:r}=ye(),[i,l]=s.useState(!1);if(!n)return e.jsxs("div",{className:"py-2 flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"text-sm text-warm-700 truncate",children:t}),e.jsx("span",{className:"text-2xs text-warm-400 shrink-0",children:r("header.processesNotFound")})]});const a=to(n),c=ga(a);return e.jsxs("div",{className:"py-2",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"text-sm text-warm-700 truncate",children:t}),e.jsxs("span",{className:"font-mono text-2xs text-warm-500 shrink-0",title:a.command,children:[a.name," ",a.pid," · ",ba(a.memoryBytes)]}),e.jsxs("button",{type:"button",onClick:()=>l(x=>!x),disabled:c===0,className:"ml-auto flex items-center gap-1 text-2xs text-warm-500 hover:text-warm-800 disabled:opacity-40 disabled:cursor-default shrink-0",title:r("header.processesSubHint"),children:[i?e.jsx(ms,{size:12}):e.jsx(St,{size:12}),c===0?r("header.processesNoSub"):r("header.processesSub").replace("{count}",String(c))]})]}),i&&e.jsx("div",{className:"mt-1.5 font-mono text-2xs overflow-x-auto",children:a.children.map(x=>e.jsx(va,{node:x,depth:0},x.pid))})]})}function no({projectId:t}){const{t:n}=ye(),[r,i]=s.useState(!1),[l,a]=s.useState(null),c=s.useCallback(()=>{i(!0),Xa(t).then(a).catch(x=>a({available:!1,reason:x instanceof Error?x.message:String(x)})).finally(()=>i(!1))},[t]);return s.useEffect(()=>{c()},[c]),e.jsxs("div",{className:"p-4 border border-warm-200 rounded-xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-warm-700",children:n("header.processesTitle")}),e.jsxs("div",{className:"flex items-center gap-2",children:[l&&l.available&&e.jsx("span",{className:"text-2xs text-warm-400",title:n("header.processesSnapshotAt"),children:new Date(l.generatedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}),e.jsx("button",{type:"button",onClick:c,disabled:r,className:"btn-icon btn-icon-sm",title:n("header.processesRefresh"),children:e.jsx(Za,{size:14,className:r?"animate-spin":""})})]})]}),e.jsx("p",{className:"text-2xs text-warm-500 mb-3",children:n("header.processesHint")}),l?l.available?l.sessions.length===0?e.jsx("p",{className:"text-xs text-warm-400",children:n("header.processesNoneRunning")}):e.jsx("div",{className:"divide-y divide-warm-100",children:l.sessions.map(x=>e.jsx(so,{title:x.title,tree:x.tree},x.id))}):e.jsx("p",{className:"text-xs text-status-error",children:n("header.processesFailed").replace("{reason}",l.reason)}):e.jsx("p",{className:"text-xs text-warm-400",children:n("header.processesLoading")})]})}function ao({project:t,todos:n,sessions:r,onProjectUpdate:i}){var it;const{t:l}=ye(),[a,c]=s.useState(!1),[x,o]=s.useState("execution"),[g,f]=s.useState(!1),[p,h]=s.useState(t.name),m=s.useRef(null),[j,D]=s.useState(t.max_concurrent??3),[z,K]=s.useState(t.default_max_turns??30),[F,R]=s.useState(t.cli_tool||"claude"),[S,H]=s.useState(t.claude_options??""),[_,O]=s.useState(t.sandbox_mode||"strict"),[X,k]=s.useState(!!t.debug_logging),[se,G]=s.useState(!!t.show_token_usage),[b,v]=s.useState(t.use_worktree!==0),[y,d]=s.useState(t.auto_commit!==0),[C,N]=s.useState(!!t.npm_auto_install),[L,B]=s.useState(!!t.svn_enabled),[Y,le]=s.useState(()=>{try{return t.hidden_tabs?JSON.parse(t.hidden_tabs):[]}catch{return[]}}),ue=["web","files","planner","sessions",...t.is_git_repo?["git"]:[]],[me,pe]=s.useState(!1),[ae,w]=s.useState(!1),[J,M]=s.useState(!1),[te,re]=s.useState(!1),[we,I]=s.useState([]),[U,ce]=s.useState(!1),[$e,Ne]=s.useState({}),[Me,Re]=s.useState(()=>{try{return t.cli_fallback_chain?JSON.parse(t.cli_fallback_chain):[]}catch{return[]}}),[De,Je]=s.useState(()=>{try{return t.auto_delegate?JSON.parse(t.auto_delegate):null}catch{return null}}),[Q,W]=s.useState(!!rs(t.loop_defaults)),[de,be]=s.useState(()=>ha(rs(t.loop_defaults)));s.useEffect(()=>{const q=Qa();Promise.all(q.map(async Pe=>{try{const Ge=await Zi(Pe.id,t.id);return[Pe.id,Ge]}catch{return[Pe.id,{}]}})).then(Pe=>{const Ge={};for(const[nt,Qe]of Pe)Ge[nt]=Qe;Ne(Ge)})},[t.id]),s.useEffect(()=>{a&&Vs().then(q=>I(q)).catch(()=>{}).finally(()=>ce(!0))},[a]),s.useEffect(()=>{a&&er(t.id).then(q=>pe(q.isSvnRepository)).catch(()=>{})},[a,t.id]);const Ie=me||!!t.svn_enabled,He=we.find(q=>q.tool===F),Ee=s.useCallback(()=>{ce(!1),eo().then(q=>I(q)).catch(()=>{}).finally(()=>ce(!0))},[]),qe=s.useCallback(async()=>{re(!0);try{const q=await tr(t.id);i(q)}catch{}finally{re(!1)}},[t.id,i]),st=async()=>{M(!0);try{const q=!b&&t.is_git_repo?1:j,Pe=await en(t.id,{max_concurrent:q,default_max_turns:z,cli_tool:F,sandbox_mode:_,debug_logging:X?1:0,use_worktree:b?1:0,auto_commit:y?1:0,npm_auto_install:C?1:0,svn_enabled:L?1:0,hidden_tabs:Y.length>0?JSON.stringify(Y):null,show_token_usage:se?1:0,claude_options:S||null,cli_fallback_chain:Me.length>0?JSON.stringify(Me):null,auto_delegate:De?JSON.stringify(De):null,loop_defaults:Q?JSON.stringify(pa(de)):null});await Promise.all(Object.entries($e).map(([Ge,nt])=>Qi(Ge,t.id,nt))),i(Pe),c(!1)}catch{}finally{M(!1)}},A=async()=>{const q=p.trim();if(!q||q===t.name){h(t.name),f(!1);return}try{const Pe=await en(t.id,{name:q});i(Pe)}catch{h(t.name)}f(!1)},he=n.length,Ke=n.filter(q=>q.status==="completed"||q.status==="merged").length,_e=n.filter(q=>q.status==="running").length,ze=r.filter(q=>q.status==="running").length,Oe=he>0?Math.round(Ke/he*100):0;return e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"card px-4 py-3 sm:px-5",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[e.jsxs("div",{className:"min-w-[12rem] flex-1",children:[g?e.jsx("input",{ref:m,type:"text",value:p,onChange:q=>h(q.target.value),onBlur:A,onKeyDown:q=>{q.key==="Enter"&&A(),q.key==="Escape"&&(h(t.name),f(!1))},className:"text-base sm:text-lg font-semibold text-warm-800 bg-transparent border-b-2 border-accent outline-none w-full max-w-md leading-tight",autoFocus:!0}):e.jsxs("h1",{className:"text-base sm:text-lg font-semibold text-warm-800 truncate cursor-pointer hover:text-accent transition-colors group flex items-center gap-2 leading-tight",onClick:()=>{f(!0),h(t.name)},title:l("header.editName"),children:[t.name,e.jsx(Wt,{size:14,className:"opacity-0 group-hover:opacity-50 transition-opacity flex-shrink-0"})]}),e.jsxs("button",{type:"button",className:"mt-1 text-[11px] text-theme-text-tertiary font-mono truncate hover:text-accent transition-colors cursor-pointer flex items-center gap-1 max-w-full",title:l("header.openFolder"),onClick:()=>nr(t.path),children:[e.jsx(sr,{size:12,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t.path})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 order-3 basis-full text-2xs text-warm-400 lg:order-none lg:basis-auto",children:[t.is_git_repo?e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[e.jsx(xs,{size:12}),t.default_branch]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-status-warning"}),l("header.noGit")]}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{className:"font-mono",children:As(t.cli_tool||"claude").label}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:(t.sandbox_mode||"strict")==="strict"?l("header.sandboxBadgeStrict"):l("header.sandboxBadgePermissive")})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2 sm:gap-3 flex-shrink-0",children:[ze>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-status-running font-medium",title:l("tabs.sessions"),children:[e.jsx(Bt,{size:12,className:"flex-shrink-0"}),ze]}),_e>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-status-running font-medium",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-status-running animate-pulse"}),_e," ",l("projects.active")]}),e.jsxs("span",{className:"text-xs font-medium text-theme-text-secondary whitespace-nowrap",children:[Oe,"% ",e.jsxs("span",{className:"text-theme-text-tertiary",children:[Ke,"/",he]})]}),e.jsx(Tt,{onClick:()=>c(!a),label:l("header.settings"),variant:a?"active":"default",pressed:a,"aria-expanded":a,children:e.jsx(ar,{size:16})})]})]})}),a&&e.jsxs("div",{className:"mt-3 card p-6",children:[e.jsx("div",{className:"flex gap-1 mb-5 p-0.5 rounded-lg",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[{key:"harness",label:l("tabs.harness")},{key:"execution",label:l("header.execConfig")},...ue.map(q=>({key:q,label:l(`tabs.${q}`)})),...Ie?[{key:"svn",label:l("tabs.svn")||"SVN"}]:[]].map(q=>e.jsx("button",{onClick:()=>o(q.key),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-all ${x===q.key?"text-warm-800 shadow-soft":"text-warm-500 hover:text-warm-700"}`,style:x===q.key?{backgroundColor:"var(--color-bg-card)"}:void 0,children:q.label},q.key))}),x==="execution"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-2xs text-warm-400 mb-4",children:l("header.execConfigHint")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:l("header.maxWorkers")}),e.jsx("input",{type:"number",min:1,max:10,value:j,onChange:q=>D(Math.min(10,Math.max(1,parseInt(q.target.value,10)||1))),className:"input-field"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:l("settings.defaultMaxTurns")}),e.jsx("input",{type:"number",min:5,max:200,value:z,onChange:q=>K(Math.min(200,Math.max(5,parseInt(q.target.value,10)||30))),className:"input-field"}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:l("settings.defaultMaxTurnsHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:l("header.cliTool")}),e.jsx("select",{value:F,onChange:q=>R(q.target.value),className:"input-field",children:bt.map(q=>e.jsx("option",{value:q.value,children:q.label},q.value))}),F==="claude"&&e.jsxs("a",{href:"https://claude.ai/settings/usage",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-1.5 text-xs text-accent hover:text-accent-dark transition-colors",children:[e.jsx(Kl,{size:12}),l("header.usageLimit")]}),U&&He&&e.jsxs("div",{className:"flex items-center gap-1.5 mt-1.5",children:[e.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${He.installed?"bg-status-success":"bg-status-error"}`}),e.jsx("span",{className:"text-2xs text-warm-400",children:He.installed?He.version||l("header.cliInstalled"):l("header.cliNotFound")}),e.jsx("button",{type:"button",onClick:Ee,className:"text-warm-400 hover:text-warm-600 transition-colors ml-1",title:l("header.cliRefresh"),children:e.jsx(Vt,{size:12})})]}),U&&He&&!He.installed&&e.jsx("div",{className:"mt-2 p-2.5 bg-status-warning/5 border border-status-warning/20 rounded-xl",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(rr,{size:16,className:"text-status-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-status-warning",children:l("header.cliNotInstalled").replace("{tool}",((it=bt.find(q=>q.value===F))==null?void 0:it.label)||F)}),e.jsx("code",{className:"block mt-1 text-2xs text-warm-500 bg-warm-100 px-2 py-1 rounded-md select-all",children:l(`header.cliInstallHint.${F}`)})]})]})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:l("header.cliFlags")}),e.jsx("input",{type:"text",value:S,onChange:q=>H(q.target.value),placeholder:"--verbose",className:"input-field"})]})]}),e.jsxs("div",{className:"mt-5 p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-600 mb-2",children:l("header.fallbackChainTitle")}),e.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:l("header.fallbackChainHint")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:bt.map(q=>{const Pe=Me.indexOf(q.value),Ge=Pe!==-1;return e.jsxs("button",{type:"button",onClick:()=>{Re(nt=>Ge?nt.filter(Qe=>Qe!==q.value):[...nt,q.value])},className:`px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${Ge?"bg-accent/10 border-accent text-accent":"bg-warm-50 border-warm-200 text-warm-500 hover:border-warm-300"}`,children:[Ge&&e.jsxs("span",{className:"mr-1 font-bold",children:[Pe+1,"."]}),q.label]},q.value)})}),Me.length>0&&e.jsx("p",{className:"text-2xs text-warm-500 mt-2",children:Me.map(q=>{var Pe;return((Pe=bt.find(Ge=>Ge.value===q))==null?void 0:Pe.label)??q}).join(" → ")})]}),e.jsxs("div",{className:"mt-5 p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-600 mb-2",children:l("header.autoReviewerTitle")}),e.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:l("header.autoReviewerHint")}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!!De,onChange:q=>Je(q.target.checked?{from:"claude",to:"codex"}:null),className:"rounded-md border-warm-300"}),e.jsx("span",{className:"text-xs text-warm-600",children:l("header.autoReviewerEnable")})]}),De&&e.jsxs("div",{className:"grid grid-cols-2 gap-3 mt-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-2xs font-medium text-warm-500 mb-1",children:l("header.autoReviewerFrom")}),e.jsx("select",{value:De.from,onChange:q=>Je({...De,from:q.target.value}),className:"input-field",children:bt.filter(q=>q.value!=="raw-shell").map(q=>e.jsx("option",{value:q.value,children:q.label},q.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-2xs font-medium text-warm-500 mb-1",children:l("header.autoReviewerTo")}),e.jsx("select",{value:De.to,onChange:q=>Je({...De,to:q.target.value}),className:"input-field",children:bt.filter(q=>q.value!=="raw-shell").map(q=>e.jsx("option",{value:q.value,children:q.label},q.value))})]})]})]}),e.jsxs("div",{className:"mt-5 p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-600 mb-2",children:l("header.loopDefaultsTitle")}),e.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:l("header.loopDefaultsHint")}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:q=>W(q.target.checked),className:"rounded-md border-warm-300"}),e.jsx("span",{className:"text-xs text-warm-600",children:l("header.loopDefaultsEnable")})]}),Q&&e.jsx("div",{className:"mt-3",children:e.jsx(fa,{draft:de,onChange:be,showStallGuard:!!t.is_git_repo})})]}),e.jsxs("div",{className:"mt-6 p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-semibold text-warm-700 mb-2",children:l("header.sandboxTitle")}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>O("strict"),className:`flex-1 px-4 py-3 rounded-lg border text-left transition-colors ${_==="strict"?"bg-status-success/10 border-status-success text-status-success":"bg-warm-50 border-warm-200 text-warm-500 hover:border-warm-300"}`,children:[e.jsx("div",{className:"text-xs font-semibold",children:l("header.sandboxStrict")}),e.jsx("div",{className:"text-2xs mt-1 opacity-80",children:l("header.sandboxStrictDesc")})]}),e.jsxs("button",{type:"button",onClick:()=>{_!=="permissive"&&w(!0)},className:`flex-1 px-4 py-3 rounded-lg border text-left transition-colors ${_==="permissive"?"bg-status-warning/10 border-status-warning text-status-warning":"bg-warm-50 border-warm-200 text-warm-500 hover:border-warm-300"}`,children:[e.jsx("div",{className:"text-xs font-semibold",children:l("header.sandboxPermissive")}),e.jsx("div",{className:"text-2xs mt-1 opacity-80",children:l("header.sandboxPermissiveDesc")})]})]}),_==="permissive"&&e.jsx("p",{className:"text-2xs text-status-warning mt-2",children:l("header.sandboxWarning")})]}),ae&&e.jsx(vt,{open:!0,onClose:()=>w(!1),size:"sm",children:e.jsxs("div",{className:"bg-theme-card rounded-2xl p-6 shadow-xl",children:[e.jsx("p",{className:"text-sm text-warm-700 mb-4",children:l("header.sandboxWarning")}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>w(!1),className:"btn-ghost text-sm",children:l("header.cancel")}),e.jsx("button",{onClick:()=>{O("permissive"),w(!1)},className:"btn-danger text-sm",children:l("header.sandboxPermissive")})]})]})}),t.is_git_repo?e.jsxs("div",{className:"mt-6 p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-semibold text-warm-700 mb-2",children:l("header.worktreeTitle")}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>v(!0),className:`flex-1 px-4 py-3 rounded-lg border text-left transition-colors ${b?"bg-status-success/10 border-status-success text-status-success":"bg-warm-50 border-warm-200 text-warm-500 hover:border-warm-300"}`,children:[e.jsx("div",{className:"text-xs font-semibold",children:l("header.worktreeEnabled")}),e.jsx("div",{className:"text-2xs mt-1 opacity-80",children:l("header.worktreeEnabledDesc")})]}),e.jsxs("button",{type:"button",onClick:()=>v(!1),className:`flex-1 px-4 py-3 rounded-lg border text-left transition-colors ${b?"bg-warm-50 border-warm-200 text-warm-500 hover:border-warm-300":"bg-status-warning/10 border-status-warning text-status-warning"}`,children:[e.jsx("div",{className:"text-xs font-semibold",children:l("header.worktreeDisabled")}),e.jsx("div",{className:"text-2xs mt-1 opacity-80",children:l("header.worktreeDisabledDesc")})]})]}),!b&&e.jsx("p",{className:"text-2xs text-status-warning mt-2",children:l("header.worktreeWarning")}),e.jsxs("div",{className:"mt-3 pt-3 border-t border-warm-200",children:[e.jsxs("label",{className:`flex items-start gap-2 mb-2 ${b?"cursor-pointer":"opacity-50 cursor-not-allowed"}`,children:[e.jsx("input",{type:"checkbox",checked:y,disabled:!b,onChange:q=>d(q.target.checked),className:"mt-0.5 rounded-md"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-warm-700",children:l("header.autoCommitLabel")}),e.jsx("div",{className:"text-2xs text-warm-500 mt-0.5",children:l("header.autoCommitHint")})]})]}),e.jsxs("label",{className:`flex items-start gap-2 ${b?"cursor-pointer":"opacity-50 cursor-not-allowed"}`,children:[e.jsx("input",{type:"checkbox",checked:C,disabled:!b,onChange:q=>N(q.target.checked),className:"mt-0.5 rounded-md"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-warm-700",children:l("header.npmAutoInstallLabel")}),e.jsx("div",{className:"text-2xs text-warm-500 mt-0.5",children:l("header.npmAutoInstallHint")})]})]})]})]}):null,e.jsxs("div",{className:"mt-6 p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-semibold text-warm-700 mb-2",children:l("header.showTokenUsageTitle")}),e.jsx("p",{className:"text-2xs text-warm-500 mb-3",children:l("header.showTokenUsageDesc")}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:se,onChange:q=>G(q.target.checked),className:"rounded-md"}),e.jsx("span",{className:"text-xs text-warm-600",children:l("header.showTokenUsageEnable")})]})]}),e.jsxs("div",{className:"mt-6 p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-semibold text-warm-700 mb-2",children:l("header.debugLoggingTitle")}),e.jsx("p",{className:"text-2xs text-warm-500 mb-3",children:l("header.debugLoggingDesc")}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:X,onChange:q=>k(q.target.checked),className:"rounded-md"}),e.jsx("span",{className:"text-xs text-warm-600",children:l("header.debugLoggingEnable")})]})]})]}),ue.includes(x)&&e.jsxs("div",{className:"p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-semibold text-warm-700 mb-2",children:l(`tabs.${x}`)}),e.jsx("p",{className:"text-2xs text-warm-500 mb-3",children:l("header.tabShowHint")}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!Y.includes(x),onChange:q=>le(Pe=>q.target.checked?Pe.filter(Ge=>Ge!==x):[...Pe,x]),className:"rounded-md"}),e.jsx("span",{className:"text-xs text-warm-600",children:l("header.tabShowEnable").replace("{tab}",l(`tabs.${x}`))})]})]}),x==="sessions"&&e.jsx("div",{className:"mt-3",children:e.jsx(no,{projectId:t.id})}),x==="svn"&&e.jsxs("div",{className:"p-4 border border-warm-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-semibold text-warm-700 mb-2",children:l("header.svnTitle")}),e.jsx("p",{className:"text-2xs text-warm-500 mb-3",children:l("header.svnHint")}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:L,onChange:q=>B(q.target.checked),className:"rounded-md"}),e.jsx("span",{className:"text-xs text-warm-600",children:l("header.svnEnable")})]})]}),x==="harness"&&e.jsx(lr,{project:t,onImportAsTask:()=>{}}),!t.is_git_repo&&e.jsxs("div",{className:"mt-5 p-3 bg-status-warning/5 border border-status-warning/20 rounded-xl",children:[e.jsx("p",{className:"text-xs text-warm-600 mb-2",children:l("header.noGitHint")}),e.jsx("button",{onClick:qe,disabled:te,className:"btn-ghost text-xs",children:te?"...":l("header.recheckGit")})]}),e.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[e.jsx("button",{onClick:()=>c(!1),className:"btn-ghost text-sm",children:l("header.cancel")}),e.jsx("button",{onClick:st,disabled:J,className:"btn-primary text-sm",children:l(J?"header.saving":"header.save")})]})]})]})}function ro({status:t}){const{t:n}=ye(),r={pending:{labelKey:"status.pending",dotClass:"bg-warm-400"},running:{labelKey:"status.running",dotClass:"bg-status-running"},completed:{labelKey:"status.completed",dotClass:"bg-status-success"},failed:{labelKey:"status.failed",dotClass:"bg-status-error"},stopped:{labelKey:"status.stopped",dotClass:"bg-status-warning"},merged:{labelKey:"status.merged",dotClass:"bg-warm-400"}},{labelKey:i,dotClass:l}=r[t];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs font-medium text-warm-500 whitespace-nowrap flex-shrink-0",children:[t==="running"?e.jsx(Ws,{size:12,className:"animate-spin text-status-running"}):e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${l}`}),n(i)]})}function lo(t){if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.map(String).filter(Boolean):[]}catch{return[]}}let io=0;function wa({onSave:t,onCancel:n,initialTitle:r="",initialDescription:i="",initialCliTool:l,initialDependsOn:a,initialMaxTurns:c,initialUseWorktree:x=null,initialLoopConfig:o=null,projectLoopDefaults:g=null,loopMode:f="toggle",initialMemoryInjectMode:p="none",initialMemoryRawFilePaths:h=null,projectId:m,projectCliTool:j="claude",projectIsGitRepo:D=!1,projectUseWorktree:z=!0,existingImages:K=[],todoId:F,onDeleteImage:R,availableTodos:S=[]}){const[H,_]=s.useState(r),[O,X]=s.useState(i),[k,se]=s.useState(l||j||"claude"),[G,b]=s.useState(a??""),[v,y]=s.useState((c==null?void 0:c.toString())??""),[d,C]=s.useState(x===1?"force-on":x===0?"force-off":"inherit"),[N,L]=s.useState(f==="always"||!!o),[B,Y]=s.useState(()=>ha(o??g)),[le,ue]=s.useState(p),[me,pe]=s.useState(lo(h)),[ae,w]=s.useState(!1),[J,M]=s.useState([]),[te,re]=s.useState(K),we=s.useRef(null),I=s.useRef(null),{t:U}=ye(),ce=s.useCallback(W=>{const de=Array.from(W).filter(be=>be.type.startsWith("image/"));for(const be of de){const Ie=new FileReader;Ie.onload=()=>{const He=Ie.result,Ee=`pending-${++io}`;M(qe=>[...qe,{id:Ee,name:be.name,data:He,preview:He}])},Ie.readAsDataURL(be)}},[]),$e=s.useCallback(W=>{var He;const de=(He=W.clipboardData)==null?void 0:He.items;if(!de)return;const be=[];for(let Ee=0;Ee<de.length;Ee++)de[Ee].type.startsWith("image/")&&be.push(de[Ee]);if(be.length===0)return;W.preventDefault();const Ie=[];for(const Ee of be){const qe=Ee.getAsFile();qe&&Ie.push(qe)}ce(Ie)},[ce]),Ne=s.useCallback(W=>{var de;W.preventDefault(),W.stopPropagation(),(de=W.dataTransfer)!=null&&de.files&&ce(W.dataTransfer.files)},[ce]),Me=s.useCallback(W=>{W.preventDefault(),W.stopPropagation()},[]),Re=W=>{M(de=>de.filter(be=>be.id!==W))},De=W=>{R&&R(W),re(de=>de.filter(be=>be.id!==W))},Je=W=>{if(W.preventDefault(),!H.trim())return;const de=v?parseInt(v,10):void 0,be=d==="force-on"?1:d==="force-off"?0:null,Ie=f!=="none"&&N?pa(B):null;t(H.trim(),O.trim(),k,J.length>0?J:void 0,G||void 0,de||void 0,be,le,[],me,Ie)},Q=te.length+J.length;return e.jsxs("form",{onSubmit:Je,className:"card p-5 border-accent/30",children:[e.jsx("div",{className:"mb-3",children:e.jsx("input",{type:"text",placeholder:U("todoForm.titlePlaceholder"),value:H,onChange:W=>_(W.target.value),className:"input-field",autoFocus:!0})}),e.jsxs("div",{className:"mb-4",children:[e.jsx("textarea",{ref:we,placeholder:U("todoForm.descPlaceholder"),value:O,onChange:W=>X(W.target.value),onPaste:$e,onDrop:Ne,onDragOver:Me,rows:3,className:"input-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{var W;return(W=I.current)==null?void 0:W.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-2xs font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[e.jsx(Ut,{size:14}),U("todoForm.addImage")]}),e.jsx("span",{className:"text-2xs text-warm-300",children:U("todoForm.pasteHint")})]}),e.jsx("input",{ref:I,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:W=>{W.target.files&&ce(W.target.files),W.target.value=""}})]}),Q>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:U("todoForm.images")}),e.jsxs("span",{className:"text-2xs text-warm-400",children:["(",Q,")"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[te.map(W=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:F?Ls(F,W.id):"",alt:W.originalName,className:"h-20 w-20 object-cover rounded-lg border border-warm-200"}),e.jsx("button",{type:"button",onClick:()=>De(W.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:W.originalName})})]},W.id)),J.map(W=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:W.preview,alt:W.name,className:"h-20 w-20 object-cover rounded-lg border border-accent/30"}),e.jsx("button",{type:"button",onClick:()=>Re(W.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:W.name})})]},W.id))]})]}),e.jsx("div",{className:"mb-4 grid grid-cols-2 gap-3",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:U("todoForm.cliTool")}),e.jsx("select",{value:k,onChange:W=>se(W.target.value),className:"input-field text-sm",children:bt.map(W=>e.jsx("option",{value:W.value,children:W.label},W.value))})]})}),k==="claude"&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:U("todoForm.maxTurns")}),e.jsx("input",{type:"number",min:"1",max:"500",placeholder:U("todoForm.maxTurnsPlaceholder"),value:v,onChange:W=>y(W.target.value),className:"input-field text-sm w-32"}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:U("todoForm.maxTurnsHint")})]}),f!=="none"&&e.jsxs("div",{className:"mb-4",children:[f==="always"?e.jsx("label",{className:"block text-xs font-medium text-warm-500",children:U("todoForm.loopRulesTitle")}):e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:N,onChange:W=>L(W.target.checked),className:"rounded-md border-warm-300"}),e.jsx("span",{className:"text-xs font-medium text-warm-500",children:U("todoForm.loopEnable")})]}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:U("todoForm.loopHint")}),N&&e.jsx("div",{className:"mt-3 pl-3 border-l-2 border-warm-200",children:e.jsx(fa,{draft:B,onChange:Y,showStallGuard:D})})]}),D&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:U("todoForm.worktreeMode")}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx("input",{type:"radio",name:"useWorktreeMode",checked:d==="inherit",onChange:()=>C("inherit")}),e.jsxs("span",{children:[U("todoForm.worktreeInherit"),e.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["(",U(z?"todoForm.worktreeProjectDefaultOn":"todoForm.worktreeProjectDefaultOff"),")"]})]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx("input",{type:"radio",name:"useWorktreeMode",checked:d==="force-on",onChange:()=>C("force-on")}),e.jsx("span",{children:U("todoForm.worktreeForceOn")})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx("input",{type:"radio",name:"useWorktreeMode",checked:d==="force-off",onChange:()=>C("force-off")}),e.jsx("span",{children:U("todoForm.worktreeForceOff")})]})]}),(d==="force-off"||d==="inherit"&&!z)&&e.jsx("p",{className:"text-2xs text-status-warning mt-1.5",children:U("todoForm.worktreeMainWarning")})]}),S.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:U("todoForm.dependsOn")}),e.jsxs("select",{value:G,onChange:W=>b(W.target.value),className:"input-field text-sm",children:[e.jsx("option",{value:"",children:U("todoForm.noDependency")}),S.map(W=>e.jsxs("option",{value:W.id,children:[W.title," (",U(`status.${W.status}`),")"]},W.id))]}),G&&e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:U("todoForm.dependsOnHint")})]}),m&&e.jsx("div",{className:"mb-4",children:e.jsx(ca,{projectId:m,mode:le,selectedPaths:me,includeLinked:ae,onChange:(W,de,be)=>{ue(W),pe(de),w(be)}})}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx("button",{type:"button",onClick:n,className:"btn-ghost text-sm",children:U("todoForm.cancel")}),e.jsx("button",{type:"submit",disabled:!H.trim(),className:"btn-primary text-sm",children:U("todoForm.save")})]})]})}function oo({children:t}){const[n,r]=s.useState(!1),[i,l]=s.useState(!1),a=s.useRef(null),c=s.useRef(null),[x,o]=s.useState({top:0,left:0}),g=s.useCallback(()=>{if(!a.current)return;const p=a.current.getBoundingClientRect(),h=window.innerWidth,m=window.innerHeight;let j=p.bottom+4;const D=c.current;if(D){const z=D.offsetWidth,K=D.offsetHeight;let F=p.right-z;F<8&&(F=8),F+z>h-8&&(F=h-8-z),j+K>m-8&&(j=p.top-K-4),o({top:j,left:F}),l(!0)}else o({top:j,left:Math.max(8,p.right-180)})},[]);s.useEffect(()=>{if(!n){l(!1);return}g();const p=requestAnimationFrame(g),h=m=>{var D,z;const j=m.target;(D=a.current)!=null&&D.contains(j)||(z=c.current)!=null&&z.contains(j)||r(!1)};return document.addEventListener("mousedown",h),window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{cancelAnimationFrame(p),document.removeEventListener("mousedown",h),window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[n,g]);const f=(Array.isArray(t)?t:[t]).filter(Boolean);return f.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:a,onClick:()=>r(!n),className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-theme-hover rounded-lg transition-colors",title:"More",children:e.jsx(Us,{size:14})}),n&&jt.createPortal(e.jsx("div",{ref:c,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:x.top,left:x.left,opacity:i?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>r(!1),children:f}),document.body)]})}function co({todo:t,allTodos:n=[],projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,loopMode:a,onStart:c,onStop:x,onDelete:o,onEdit:g,onMerge:f,onCleanup:p,onRetry:h,onContinue:m,onFix:j,onSchedule:D,onScheduleOnReset:z,resetsAt:K,onEvent:F,isInteractive:R,onSendInput:S,isDragSource:H,isDragging:_,isDragOver:O,isValidDropTarget:X,onDragStart:k,onDragEnd:se,onDragOverTarget:G,onDragLeaveTarget:b,onDropTarget:v,onRemoveDependency:y,debugLogging:d,showTokenUsage:C,isChainMember:N}){const[L,B]=s.useState(!1),[Y,le]=s.useState(!1),[ue,me]=s.useState([]),[pe,ae]=s.useState(!1),[w,J]=s.useState(!1),[M,te]=s.useState(null),[re,we]=s.useState(!1),[I,U]=s.useState(null),[ce,$e]=s.useState(!1),[Ne,Me]=s.useState(null),[Re,De]=s.useState(!1),[Je,Q]=s.useState(null),[W,de]=s.useState(!1),[be,Ie]=s.useState(null),[He,Ee]=s.useState(!1),[qe,st]=s.useState(""),[A,he]=s.useState(!1),[Ke,_e]=s.useState(null),[ze,Oe]=s.useState(!1),[it,q]=s.useState(""),[Pe,Ge]=s.useState(!1),[nt,Qe]=s.useState(null),[Ue,ut]=s.useState(null),[ne,ve]=s.useState(!1),[je,Le]=s.useState(!1),[ge,Xe]=s.useState(!1),[Se,We]=s.useState(()=>{const P=new Date;P.setHours(P.getHours()+1),P.setMinutes(0,0,0);const Te=P.getFullYear(),Ye=String(P.getMonth()+1).padStart(2,"0"),ot=String(P.getDate()).padStart(2,"0"),ct=String(P.getHours()).padStart(2,"0"),gs=String(P.getMinutes()).padStart(2,"0");return`${Te}-${Ye}-${ot}T${ct}:${gs}`}),[et,V]=s.useState(!1),[xe,fe]=s.useState(null),{t:Z}=ye(),{confirm:tt}=_t(),u=t.status==="pending"||t.status==="failed"||t.status==="stopped",E=(t.status==="pending"||t.status==="failed"||t.status==="stopped")&&!!D,T=(t.status==="pending"||t.status==="completed"||t.status==="failed"||t.status==="stopped")&&!!z&&!!K&&K>Math.floor(Date.now()/1e3),ee=t.status==="running",ie=t.status==="completed"||t.status==="stopped"||t.status==="merged",ke=t.status==="completed"&&!N&&!!t.branch_name,Ve=t.status==="completed"||t.status==="failed"||t.status==="stopped",ht=!!m&&t.status==="completed"&&!!t.worktree_path,at=t.status!=="running"&&t.status!=="pending"&&!!t.worktree_path&&!N,$=t.status==="completed"||t.status==="failed"||t.status==="stopped"||t.status==="merged";s.useEffect(()=>{R&&t.status==="running"&&!L&&B(!0)},[R,t.status]),s.useEffect(()=>{L&&!pe&&rl(t.id).then(P=>{me(P),ae(!0)}).catch(()=>{})},[L,pe,t.id]),s.useEffect(()=>{L&&$&&!ne&&ll(t.id).then(P=>{ut(P),ve(!0)}).catch(()=>{ve(!0)})},[L,$,ne,t.id]),s.useEffect(()=>F(P=>{if(P.type==="todo:log"&&P.todoId===t.id&&P.message){const Te={id:`ws-${Date.now()}-${Math.random()}`,todo_id:t.id,log_type:P.logType||"output",message:P.message,created_at:new Date().toISOString()};me(Ye=>[...Ye.slice(1-dn),Te])}if(P.type==="todo:commit"&&P.todoId===t.id&&P.message){const Te={id:`ws-commit-${Date.now()}-${Math.random()}`,todo_id:t.id,log_type:"commit",message:`${P.commitHash?`[${P.commitHash}] `:""}${P.message}`,created_at:new Date().toISOString()};me(Ye=>[...Ye.slice(1-dn),Te])}}),[F,t.id]);const oe=async()=>{try{const{files:P}=await or(t.project_id,t.id);P.length>0&&window.open(`/api/projects/${t.project_id}/debug-logs/${encodeURIComponent(P[0].name)}`,"_blank")}catch{}},Ce=async()=>{if(w){J(!1);return}we(!0),U(null);try{const P=await cl(t.id);te(P),J(!0),B(!0)}catch(P){U(P instanceof Error?P.message:"Failed to load diff"),B(!0)}finally{we(!1)}},Ae=async()=>{$e(!0),Me(null);try{await f(t.id)}catch(P){Me(P instanceof Error?P.message:"Merge failed")}finally{$e(!1)}},rt=async()=>{const P=t.branch_name?await tt({message:Z("cleanup.confirmDeleteBranch").replace("{name}",t.branch_name),danger:!0}):!1;De(!0),Q(null);try{await p(t.id,P)}catch(Te){Q(Te instanceof Error?Te.message:"Cleanup failed")}finally{De(!1)}},It=async(P="headless")=>{de(!0),Ie(null),me([]),ae(!1),te(null),J(!1),ut(null),ve(!1);try{await h(t.id,P)}catch(Te){Ie(Te instanceof Error?Te.message:"Retry failed")}finally{de(!1)}},za=async(P="headless")=>{if(!m)return;const Te=qe.trim();if(!Te){_e(Z("todo.continuePromptRequired"));return}he(!0),_e(null);try{await m(t.id,Te,P),Ee(!1),st(""),me([]),ae(!1)}catch(Ye){_e(Ye instanceof Error?Ye.message:"Continue failed")}finally{he(!1)}},Pa=async()=>{if(!(!z||!it.trim())){Ge(!0),Qe(null);try{await z(t.id,it.trim()),Oe(!1),q("")}catch(P){Qe(P instanceof Error?P.message:"Failed")}finally{Ge(!1)}}},Aa=async()=>{if(!(!D||!Se)){V(!0);try{await D(t.id,new Date(Se).toISOString(),ge),Le(!1)}catch{}finally{V(!1)}}},Ia=P=>{if(P<60)return`${P}s`;const Te=Math.floor(P/60),Ye=P%60;if(Te<60)return Ye>0?`${Te}m ${Ye}s`:`${Te}m`;const ot=Math.floor(Te/60),ct=Te%60;return ct>0?`${ot}h ${ct}m`:`${ot}h`},Js=P=>P>=1e6?`${(P/1e6).toFixed(1)}M`:P>=1e3?`${(P/1e3).toFixed(1)}k`:String(P),Lt=t.images?JSON.parse(t.images):[],fs=rs(t.loop_config),kt=t.depends_on?n.find(P=>P.id===t.depends_on):null,Ht=n.find(P=>P.depends_on===t.id&&P.merged_from_branch),Ha=t.cli_tool||r||"claude",qs=As(Ha).supportsInteractive;if(Y)return e.jsx(wa,{initialTitle:t.title,initialDescription:t.description??void 0,initialCliTool:t.cli_tool??void 0,initialDependsOn:t.depends_on??void 0,initialMaxTurns:t.max_turns??void 0,initialUseWorktree:t.use_worktree??null,initialLoopConfig:fs,loopMode:a,initialMemoryInjectMode:t.memory_inject_mode??"none",initialMemoryRawFilePaths:t.memory_raw_file_paths??null,projectId:t.project_id,projectIsGitRepo:i,projectUseWorktree:l,existingImages:Lt,todoId:t.id,availableTodos:n.filter(P=>P.id!==t.id),onDeleteImage:async P=>{await il(t.id,P)},onSave:async(P,Te,Ye,ot,ct,gs,Va,Ga,Ya,Ja,qa)=>{await g(t.id,P,Te,Ye,ct,gs,Va,Ga,Ya,Ja,qa),ot&&ot.length>0&&await oa(t.id,ot.map(Qs=>({name:Qs.name,data:Qs.data}))),le(!1)},onCancel:()=>le(!1)});const Oa=P=>{P.dataTransfer.setData("text/plain",t.id),P.dataTransfer.effectAllowed="link",k==null||k(t.id)},Wa=()=>{se==null||se()},Ba=P=>{!_||H||(P.preventDefault(),P.dataTransfer.dropEffect=X?"link":"none",G==null||G(t.id))},Ka=()=>{b==null||b(t.id)},Ua=P=>{P.preventDefault(),!(!_||H||!X)&&(v==null||v(t.id))},Xs=_&&!H&&O&&X,Zs=_&&!H&&O&&!X;return e.jsxs("div",{className:`relative transition-opacity duration-200 ${H?"opacity-40":""}`,onDragOver:Ba,onDragLeave:Ka,onDrop:Ua,onContextMenu:P=>{$t(P)||(P.preventDefault(),P.stopPropagation(),fe({x:P.clientX,y:P.clientY}))},children:[e.jsxs("div",{className:`card overflow-hidden transition-all duration-200 ${Xs?"ring-2 ring-accent/50 ring-offset-1":""} ${Zs?"ring-2 ring-status-error/50 ring-offset-1":""}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 md:flex-nowrap md:gap-3 px-3 md:px-4 py-3 md:py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:()=>B(!L),children:[e.jsx("div",{draggable:!0,onDragStart:Oa,onDragEnd:Wa,onClick:P=>P.stopPropagation(),className:"flex-shrink-0 cursor-grab active:cursor-grabbing text-warm-300 hover:text-warm-500 transition-colors p-0.5 -ml-1",title:Z("dnd.dropHint"),children:e.jsx(ir,{size:16})}),e.jsx("button",{className:"text-warm-400 hover:text-accent flex-shrink-0 transition-colors",children:e.jsx(St,{size:14,className:`transition-transform duration-200 ${L?"rotate-90":""}`})}),e.jsxs("span",{className:"text-2xs font-mono text-warm-400 w-6 flex-shrink-0",children:["#",t.priority]}),e.jsx("span",{className:"flex-1 basis-[calc(100%-100px)] md:basis-auto min-w-0 text-sm text-warm-800 font-medium truncate order-none",children:t.title}),Lt.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-2xs font-mono text-warm-400 flex-shrink-0",children:[e.jsx(Ut,{size:12}),Lt.length]}),kt&&e.jsxs("span",{className:"hidden md:inline-flex items-center gap-1 text-2xs font-mono text-warm-400 flex-shrink-0 group/dep",title:`${Z("todo.dependsOn")}: ${kt.title}`,children:[e.jsx(_s,{size:12}),kt.title.length>20?kt.title.slice(0,20)+"...":kt.title,y&&e.jsx("button",{onClick:P=>{P.stopPropagation(),y(t.id)},className:"ml-0.5 h-3.5 w-3.5 rounded-full hover:bg-theme-hover inline-flex items-center justify-center opacity-0 group-hover/dep:opacity-100 transition-opacity",title:Z("dnd.removeDep"),children:e.jsx(ft,{size:12})})]}),t.cli_tool&&e.jsx("span",{className:"hidden md:inline-flex items-center gap-1 text-2xs font-mono text-warm-400 flex-shrink-0",children:As(t.cli_tool||"claude").label}),e.jsx(ro,{status:t.status}),fs&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-2xs font-mono text-warm-400 flex-shrink-0",title:Z("todoForm.loopEnable"),children:[e.jsx(gi,{size:10}),t.round_count??1,"/",fs.maxRounds]}),e.jsxs("div",{className:"flex items-center gap-0.5 ml-auto md:ml-2 flex-shrink-0",onClick:P=>P.stopPropagation(),children:[u&&e.jsx("button",{onClick:()=>c(t.id,"headless"),className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors",title:Z("todo.startHeadless"),children:e.jsx(Rt,{size:14})}),ee&&e.jsx("button",{onClick:()=>x(t.id),className:"p-1.5 text-status-error/60 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:Z("todo.stop"),children:e.jsx(Kt,{size:14})}),ke&&e.jsx("button",{onClick:Ae,disabled:ce,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Z("todo.merge"),children:e.jsx(Fs,{size:14})}),ht&&e.jsx("button",{onClick:()=>{Ee(P=>!P),_e(null)},disabled:A,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Z("todo.continue"),children:e.jsx(pn,{size:14})}),Ve&&e.jsx("button",{onClick:()=>It("headless"),disabled:W,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Z("todo.retry"),children:e.jsx(Vt,{size:14})}),e.jsxs(oo,{children:[u&&qs&&e.jsxs("button",{onClick:()=>c(t.id,"interactive"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left",title:Z("todo.startInteractiveDesc"),children:[e.jsx(Bt,{size:14}),Z("todo.startInteractive")]}),u&&e.jsxs("button",{onClick:()=>c(t.id,"verbose"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left",title:Z("todo.startVerboseDesc"),children:[e.jsx(xn,{size:14}),Z("todo.startVerbose")]}),E&&e.jsxs("button",{onClick:()=>Le(!je),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left",title:Z("todo.scheduleDesc"),children:[e.jsx(zs,{size:14}),Z("todo.schedule")]}),T&&e.jsxs("button",{onClick:()=>{Oe(P=>!P),Qe(null)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left",title:Z("todo.scheduleOnResetDesc"),children:[e.jsx(zt,{size:14}),Z("todo.scheduleOnReset")]}),ie&&e.jsxs("button",{onClick:Ce,disabled:re,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left disabled:opacity-30",children:[e.jsx(ss,{size:14}),Z("todo.viewDiff")]}),d&&$&&e.jsxs("button",{onClick:oe,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left",children:[e.jsx(bn,{size:14}),Z("todo.viewDebugLog")]}),at&&e.jsxs("button",{onClick:rt,disabled:Re,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left disabled:opacity-30",children:[e.jsx(ls,{size:14}),Z("todo.cleanup")]}),e.jsxs("button",{onClick:()=>le(!0),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left",children:[e.jsx(Wt,{size:14}),Z("todo.edit")]}),e.jsxs("button",{onClick:()=>o(t.id),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left",children:[e.jsx(wt,{size:14}),Z("todo.delete")]})]})]})]}),je&&e.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("label",{className:"text-xs font-medium text-theme-text-secondary",children:Z("todo.scheduleAt")}),e.jsx("input",{type:"datetime-local",value:Se,onChange:P=>We(P.target.value),className:"bg-theme-card border border-theme-border-strong rounded-lg px-2 py-1.5 text-sm font-mono text-warm-800 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20",min:new Date().toISOString().slice(0,16)}),e.jsx("button",{onClick:Aa,disabled:et||!Se,className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Z(et?"todo.scheduling":"todo.confirmSchedule")}),e.jsx("button",{onClick:()=>Le(!1),className:"btn-ghost text-xs py-1.5",children:Z("scheduleForm.cancel")}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-500",children:[e.jsx("input",{type:"checkbox",checked:ge,onChange:P=>Xe(P.target.checked),className:"rounded-md border-accent/40 text-accent focus:ring-accent"}),Z("todo.scheduleKeepOriginal")]})]})}),He&&e.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("label",{className:"text-xs font-medium text-theme-text-secondary",children:[Z("todo.continuePromptLabel"),(t.round_count??1)>1&&e.jsxs("span",{className:"ml-2 text-theme-muted",children:["(",Z("todo.roundLabel")," ",t.round_count,")"]})]}),e.jsx("textarea",{value:qe,onChange:P=>st(P.target.value),placeholder:Z("todo.continuePromptPlaceholder"),rows:3,className:"w-full bg-theme-card border border-theme-border-strong rounded-lg px-3 py-2 text-sm text-warm-800 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20 resize-y",disabled:A}),Ke&&e.jsx("p",{className:"text-xs text-status-error",children:Ke}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>za("headless"),disabled:A||!qe.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Z(A?"todo.continuing":"todo.confirmContinue")}),e.jsx("button",{onClick:()=>{Ee(!1),_e(null)},disabled:A,className:"btn-ghost text-xs py-1.5",children:Z("scheduleForm.cancel")})]})]})}),ze&&K&&e.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs font-medium text-theme-text-secondary",children:Z("todo.scheduleOnResetLabel")}),e.jsx("span",{className:"text-xs text-warm-400 font-mono",children:new Date(K*1e3).toLocaleString()})]}),e.jsx("textarea",{value:it,onChange:P=>q(P.target.value),placeholder:Z("todo.resetPromptPlaceholder"),rows:3,className:"w-full bg-theme-card border border-theme-border-strong rounded-lg px-3 py-2 text-sm text-warm-800 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20 resize-y",disabled:Pe}),nt&&e.jsx("p",{className:"text-xs text-status-error",children:nt}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:Pa,disabled:Pe||!it.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Z(Pe?"todo.scheduling":"todo.confirmResetSchedule")}),e.jsx("button",{onClick:()=>{Oe(!1),Qe(null)},disabled:Pe,className:"btn-ghost text-xs py-1.5",children:Z("scheduleForm.cancel")})]})]})}),L&&e.jsx("div",{className:"overflow-hidden border-t border-theme-border",children:e.jsxs("div",{className:"px-4 py-3 space-y-3",children:[e.jsxs("section",{children:[e.jsx("h4",{className:"section-label mb-1.5",children:Z("todo.description")}),e.jsx("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2",children:t.description?e.jsx("p",{className:"text-sm text-warm-700 whitespace-pre-wrap",children:t.description}):e.jsx("p",{className:"text-sm text-warm-400 italic",children:Z("todo.noDescription")})})]}),Lt.length>0&&e.jsxs("section",{children:[e.jsxs("h4",{className:"section-label mb-1.5",children:[Z("todo.attachedImages")," ",e.jsxs("span",{className:"text-warm-400 normal-case",children:["(",Lt.length,")"]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Lt.map(P=>e.jsx("a",{href:Ls(t.id,P.id),target:"_blank",rel:"noopener noreferrer",children:e.jsx("img",{src:Ls(t.id,P.id),alt:P.originalName,className:"h-16 w-16 object-cover rounded-md border border-theme-border"})},P.id))})]}),(kt||t.branch_name||Ht)&&e.jsxs("section",{children:[e.jsx("h4",{className:"section-label mb-1.5",children:Z("todo.branch")}),e.jsxs("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2 space-y-1.5",children:[kt&&e.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[e.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0 pt-0.5",children:Z("todo.dependsOn")}),e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-md bg-accent/10 text-accent text-2xs font-medium",children:kt.title})]}),t.branch_name&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:Z("todo.branch")}),e.jsx(xs,{size:12,className:"text-status-success flex-shrink-0"}),e.jsx("code",{className:"font-mono text-xs text-warm-700 break-all",children:t.branch_name})]}),t.worktree_path&&e.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[e.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0 pt-0.5",children:Z("todo.worktree")}),e.jsx("code",{className:"font-mono text-2xs text-warm-500 break-all",children:t.worktree_path})]}),t.merged_from_branch&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:Z("todo.mergedFrom")}),e.jsx("code",{className:"font-mono text-xs text-theme-text-secondary break-all",children:t.merged_from_branch})]}),!t.worktree_path&&Ht&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:Z("todo.transferredTo")}),e.jsx("span",{className:"text-warm-700 truncate",children:Ht.title.length>30?Ht.title.slice(0,27)+"...":Ht.title})]})]})]}),t.status==="failed"&&ue.length>0&&(()=>{var ot;const P=ue.filter(ct=>ct.log_type==="error");if(P.length===0)return null;const Te=P.find(ct=>/exited with code (\d+)/.test(ct.message)),Ye=Te?(ot=Te.message.match(/exited with code (\d+)/))==null?void 0:ot[1]:null;return e.jsxs("div",{style:{background:mt.bg,fontFamily:bs,fontSize:12,lineHeight:"1.5",padding:"10px 12px",borderRadius:8,border:`1px solid ${mt.separator}`,color:mt.text},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:mt.error},children:">"})," ",e.jsx("span",{style:{color:mt.error,fontWeight:700},children:"FAILED"}),Ye&&e.jsxs("span",{style:{color:mt.dim},children:[" (exit code: ",Ye,")"]}),j&&e.jsx("button",{onClick:()=>j(t,P),style:{marginLeft:12,color:mt.warning,background:"none",border:`1px solid ${mt.warning}`,padding:"1px 8px",borderRadius:2,cursor:"pointer",fontSize:11,fontFamily:bs},children:Z("failure.fix")})]}),e.jsx("div",{style:{maxHeight:192,overflowY:"auto",marginTop:4},children:P.map(ct=>e.jsxs("div",{children:[e.jsx("span",{style:{color:mt.dim},children:new Date(ct.created_at).toLocaleTimeString()})," ",e.jsx("span",{style:{color:mt.error},children:ct.message})]},ct.id))})]})})(),$&&Ue&&e.jsxs("section",{children:[e.jsx("h4",{className:"section-label mb-1.5",children:Z("todo.result")}),e.jsxs("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2 space-y-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs",children:[Ue.duration_seconds!==null&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(zt,{size:12,className:"text-warm-400"}),e.jsx("span",{className:"text-warm-400",children:Z("result.duration")}),e.jsx("span",{className:"text-warm-700 font-medium",children:Ia(Ue.duration_seconds)})]}),Ue.commits.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ei,{size:12,className:"text-status-success"}),e.jsx("span",{className:"text-status-success font-medium",children:Ue.commits.length}),e.jsx("span",{className:"text-warm-400",children:Z("result.commits")})]}),Ue.diff_stats.files_changed>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ss,{size:12,className:"text-warm-400"}),e.jsx("span",{className:"text-warm-700 font-medium",children:Ue.diff_stats.files_changed}),e.jsx("span",{className:"text-warm-400",children:Z("result.filesChanged")}),e.jsxs("span",{className:"text-status-success font-mono",children:["+",Ue.diff_stats.insertions]}),e.jsxs("span",{className:"text-status-error font-mono",children:["-",Ue.diff_stats.deletions]})]}),C&&Ue.token_usage&&(()=>{const P=Ue.token_usage,Te=(P.input_tokens??0)+(P.cache_read_input_tokens??0)+(P.cache_creation_input_tokens??0),Ye=Te+(P.output_tokens??0);let ot,ct;return Ye>=5e5?(ot=Z("result.levelHeavy"),ct="text-status-error"):Ye>=3e5?(ot=Z("result.levelHigh"),ct="text-status-warning"):Ye>=1e5?(ot=Z("result.levelModerate"),ct="text-status-warning"):(ot=Z("result.levelLight"),ct="text-status-info"),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[Te>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-warm-400",children:Z("result.inputTokens")}),e.jsx("span",{className:"text-warm-700 font-medium",children:Js(Te)})]}),Te>0&&P.output_tokens!==null&&e.jsx("span",{className:"text-warm-400",children:"·"}),P.output_tokens!==null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-warm-400",children:Z("result.outputTokens")}),e.jsx("span",{className:"text-warm-700 font-medium",children:Js(P.output_tokens)})]}),P.num_turns!=null&&P.num_turns>1&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-warm-400",children:"·"}),e.jsxs("span",{className:"text-warm-700",children:[P.num_turns,Z("result.turns")]})]}),e.jsx("span",{className:"text-warm-400",children:"·"}),e.jsx("span",{className:`font-medium ${ct}`,children:ot})]})})()]}),Ue.commits.length>0&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider mb-1",children:Z("result.commitHistory")}),e.jsx("div",{className:"space-y-0.5",children:Ue.commits.map((P,Te)=>e.jsxs("div",{className:"flex items-center gap-2 px-1.5 py-1 text-xs rounded-md hover:bg-theme-hover",children:[e.jsx("code",{className:"font-mono text-accent flex-shrink-0",children:P.hash.slice(0,7)||"-------"}),e.jsx("span",{className:"text-warm-700 truncate flex-1",children:P.message}),e.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:new Date(P.date).toLocaleTimeString()})]},Te))})]}),Ue.changed_files.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider",children:Z("result.changedFiles")}),ie&&e.jsxs("button",{onClick:Ce,disabled:re,className:"flex items-center gap-1 text-2xs text-warm-500 hover:text-accent transition-colors disabled:opacity-30",children:[e.jsx(St,{size:12,className:`transition-transform ${w?"rotate-90":""}`}),e.jsx("span",{children:Z(w?"todo.hideDiff":"todo.viewDiff")})]})]}),e.jsx("div",{className:"space-y-0.5",children:Ue.changed_files.map((P,Te)=>{const Ye=P.status==="A"?"bg-status-success/15 text-status-success":P.status==="D"?"bg-status-error/15 text-status-error":P.status==="M"?"bg-status-warning/15 text-status-warning":"bg-warm-200 text-warm-600";return e.jsxs("div",{className:"flex items-center gap-2 px-1.5 py-0.5 text-xs",children:[e.jsx("span",{className:`inline-flex items-center justify-center w-5 h-4 rounded-md text-[10px] font-bold ${Ye}`,children:P.status}),e.jsx("span",{className:"text-warm-700 font-mono text-2xs break-all flex-1",children:P.file}),P.renamedFrom&&e.jsxs("span",{className:"text-warm-400 text-2xs flex-shrink-0",children:["← ",P.renamedFrom]})]},Te)})})]})]})]}),Ne&&e.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Z("todo.mergeFailed"),": ",Ne]}),Je&&e.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Z("todo.cleanupFailed"),": ",Je]}),be&&e.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Z("todo.retryFailed"),": ",be]}),I&&e.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Z("todo.diffError"),": ",I]}),w&&M&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("h4",{className:"section-label",children:Z("todo.diffOutput")}),e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs",children:[e.jsxs("span",{className:"text-warm-500",children:[M.stats.files_changed," ",Z("todo.files")]}),e.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-md bg-status-success/10 text-status-success font-mono",children:["+",M.stats.insertions]}),e.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-md bg-status-error/10 text-status-error font-mono",children:["-",M.stats.deletions]})]})]}),e.jsx("div",{className:"max-h-80 overflow-y-auto rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2 font-mono text-xs leading-tight",children:M.diff?M.diff.split(`
|
|
163
|
-
`).map((P,Te)=>{let Ye="text-theme-text",ot="";return P.startsWith("+")&&!P.startsWith("+++")?Ye="text-theme-text bg-status-success/15":P.startsWith("-")&&!P.startsWith("---")?Ye="text-theme-text bg-status-error/15":P.startsWith("@@")?Ye="text-accent":P.startsWith("diff ")&&(Ye="text-warm-700",ot="font-semibold"),e.jsx("div",{className:`whitespace-pre ${Ye} ${ot}`,children:P},Te)}):e.jsx("span",{className:"text-warm-400 italic",children:Z("log.noChanges")})})]}),e.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:mt.bg,fontFamily:bs,border:`1px solid ${mt.separator}`},children:[e.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${mt.separator}`,fontSize:12,color:mt.text},children:[e.jsx("span",{style:{color:mt.prompt},children:"$"})," ",e.jsx("span",{style:{color:mt.bright},children:"tail"})," ",e.jsx("span",{style:{color:mt.dim},children:"-f task.log"})]}),e.jsx(ol,{logs:ue,interactive:R&&t.status==="running",todoId:t.id,onSendInput:S,embedded:!0})]})]})})]}),Xs&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-accent/50 bg-accent/5",children:[e.jsx(_s,{size:14,className:"text-accent flex-shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-accent",children:Z("dnd.dropHint")})]}),Zs&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-warm-300 bg-status-error/10",children:[e.jsx(Il,{size:14,className:"text-status-error flex-shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-status-error",children:Z("dnd.cyclicWarning")})]}),xe&&e.jsxs(yt,{x:xe.x,y:xe.y,onClose:()=>fe(null),children:[u&&e.jsxs("button",{onClick:()=>c(t.id,"headless"),className:Be,title:Z("todo.startHeadless"),children:[e.jsx(Rt,{size:14}),Z("todo.start")]}),u&&qs&&e.jsxs("button",{onClick:()=>c(t.id,"interactive"),className:Be,title:Z("todo.startInteractiveDesc"),children:[e.jsx(Bt,{size:14}),Z("todo.startInteractive")]}),u&&e.jsxs("button",{onClick:()=>c(t.id,"verbose"),className:Be,title:Z("todo.startVerboseDesc"),children:[e.jsx(xn,{size:14}),Z("todo.startVerbose")]}),ee&&e.jsxs("button",{onClick:()=>x(t.id),className:Be,children:[e.jsx(Kt,{size:14}),Z("todo.stop")]}),ke&&e.jsxs("button",{onClick:Ae,disabled:ce,className:Be,children:[e.jsx(Fs,{size:14}),Z("todo.merge")]}),ht&&e.jsxs("button",{onClick:()=>{Ee(!0),_e(null)},disabled:A,className:Be,children:[e.jsx(pn,{size:14}),Z("todo.continue")]}),Ve&&e.jsxs("button",{onClick:()=>It("headless"),disabled:W,className:Be,children:[e.jsx(Vt,{size:14}),Z("todo.retry")]}),E&&e.jsxs("button",{onClick:()=>Le(!0),className:Be,title:Z("todo.scheduleDesc"),children:[e.jsx(zs,{size:14}),Z("todo.schedule")]}),T&&e.jsxs("button",{onClick:()=>{Oe(!0),Qe(null)},className:Be,title:Z("todo.scheduleOnResetDesc"),children:[e.jsx(zt,{size:14}),Z("todo.scheduleOnReset")]}),ie&&e.jsxs("button",{onClick:Ce,disabled:re,className:Be,children:[e.jsx(ss,{size:14}),Z("todo.viewDiff")]}),d&&$&&e.jsxs("button",{onClick:oe,className:Be,children:[e.jsx(bn,{size:14}),Z("todo.viewDebugLog")]}),at&&e.jsxs("button",{onClick:rt,disabled:Re,className:Be,children:[e.jsx(ls,{size:14}),Z("todo.cleanup")]}),e.jsx(Ks,{}),e.jsxs("button",{onClick:()=>le(!0),className:Be,children:[e.jsx(Wt,{size:14}),Z("todo.edit")]}),e.jsxs("button",{onClick:()=>o(t.id),className:ra,children:[e.jsx(wt,{size:14}),Z("todo.delete")]})]})]})}const uo=s.lazy(()=>hs(()=>import("./TaskGraph-B97ITa4c.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12]))),Qt={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function yn(t,n,r){let i=r;const l=new Set;for(;i;){if(i===n)return!0;if(l.has(i))return!1;l.add(i);const a=t.find(c=>c.id===i);i=(a==null?void 0:a.depends_on)??null}return!1}function mo({todos:t,projectId:n,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,projectLoopDefaults:a,loopMode:c="toggle",onAddTodo:x,onStartAll:o,onStopAll:g,onStartTodo:f,onStopTodo:p,onDeleteTodo:h,onEditTodo:m,onMergeTodo:j,onMergeChain:D,onCleanupTodo:z,onRetryTodo:K,onContinueTodo:F,onFixTodo:R,onScheduleTodo:S,onScheduleOnResetTodo:H,resetsAt:_,onUpdateDependency:O,onUpdatePosition:X,onReorderTodos:k,onEvent:se,onSendInput:G,interactiveTodos:b,debugLogging:v,showTokenUsage:y}){var ut;const[d,C]=s.useState(!1),[N,L]=s.useState(null),[B,Y]=s.useState(null),[le,ue]=s.useState(null),[me,pe]=s.useState(null),[ae,w]=s.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[J,M]=s.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[te,re]=s.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[we,I]=s.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:U}=ye(),ce=s.useCallback(ne=>{w(ne);try{localStorage.setItem("todoViewMode",ne)}catch{}},[]),$e=s.useCallback(ne=>{M(ne);try{localStorage.setItem("todoStatusFilter",ne)}catch{}},[]),Ne=s.useCallback(()=>{re(ne=>{const ve=!ne;try{localStorage.setItem("todoStackModeEnabled",String(ve))}catch{}if(!ve){I(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return ve})},[]),Me=s.useCallback(()=>{I(ne=>{const ve=!ne;try{localStorage.setItem("todoStackCollapsed",String(ve))}catch{}return ve})},[]),Re=te&&we&&ae==="list",De=s.useMemo(()=>({all:t.length,active:t.filter(ne=>Qt.active.includes(ne.status)).length,completed:t.filter(ne=>Qt.completed.includes(ne.status)).length,cancelled:t.filter(ne=>Qt.cancelled.includes(ne.status)).length}),[t]),Je=s.useMemo(()=>{const ne=Qt[J];return ne?t.filter(ve=>ne.includes(ve.status)):t},[t,J]),Q=(()=>{const ne=[...Je].sort((Se,We)=>Se.priority-We.priority);if(J!=="all"||Re)return ne.map(Se=>({todo:Se,depth:0}));const ve=new Map,je=[];for(const Se of ne)if(Se.depends_on){const We=ve.get(Se.depends_on)||[];We.push(Se),ve.set(Se.depends_on,We)}else je.push(Se);const Le=[],ge=new Set,Xe=(Se,We)=>{if(ge.has(Se.id))return;ge.add(Se.id),Le.push({todo:Se,depth:We});const et=ve.get(Se.id);if(et)for(const V of et)Xe(V,We+1)};for(const Se of je)Xe(Se,0);for(const Se of ne)ge.has(Se.id)||Le.push({todo:Se,depth:0});return Le})(),{completedChainRoots:W,completedChainMembers:de}=s.useMemo(()=>{const ne=new Map;for(const ge of t)if(ge.depends_on){const Xe=ne.get(ge.depends_on)||[];Xe.push(ge.id),ne.set(ge.depends_on,Xe)}const ve=t.filter(ge=>!ge.depends_on&&ne.has(ge.id)),je=new Map,Le=new Set;for(const ge of ve){const Xe=[],Se=We=>{if(!t.find(xe=>xe.id===We))return;Xe.push(We);const V=ne.get(We)||[];for(const xe of V)Se(xe)};if(Se(ge.id),Xe.length>=2&&Xe.every(We=>{const et=t.find(V=>V.id===We);return(et==null?void 0:et.status)==="completed"||(et==null?void 0:et.status)==="merged"})){je.set(ge.id,Xe.length);for(const We of Xe)Le.add(We)}}return{completedChainRoots:je,completedChainMembers:Le}},[t]),[be,Ie]=s.useState(null),[He,Ee]=s.useState(null),qe=s.useCallback(async ne=>{if(D){Ie(ne),Ee(null);try{await D(ne)}catch(ve){Ee(ve instanceof Error?ve.message:"Merge failed")}finally{Ie(null)}}},[D]),st=s.useRef(!1),A=s.useCallback(ne=>{st.current=!1,Y(ne)},[]),he=s.useCallback(async()=>{if(!st.current&&B&&O){const ne=t.find(ve=>ve.id===B);ne!=null&&ne.depends_on&&await O(B,null)}Y(null),ue(null),pe(null)},[B,t,O]),Ke=s.useCallback(ne=>{ue(ne),pe(null)},[]),_e=s.useCallback(ne=>{ue(ve=>ve===ne?null:ve)},[]),ze=s.useCallback(async ne=>{!B||!O||B!==ne&&(yn(t,B,ne)||(st.current=!0,await O(B,ne),Y(null),ue(null),pe(null)))},[B,t,O]),Oe=s.useCallback(async ne=>{O&&await O(ne,null)},[O]),it=s.useCallback(ne=>!B||B===ne?!1:!yn(t,B,ne),[B,t]),q=s.useCallback(ne=>{pe(ne),ue(null)},[]),Pe=s.useCallback(ne=>{pe(ve=>ve===ne?null:ve)},[]),Ge=s.useCallback(async(ne,ve)=>{if(!B||!k)return;const je=ve.indexOf(B);if(je<0)return;const Le=ve.filter(Se=>Se!==B),ge=ne>je?ne-1:ne;if(ge===je){pe(null);return}const Xe=[...Le.slice(0,ge),B,...Le.slice(ge)];st.current=!0,await k(Xe),Y(null),pe(null),ue(null)},[B,k]),nt=t.some(ne=>ne.status==="pending"||ne.status==="failed"||ne.status==="stopped"),Qe=t.some(ne=>ne.status==="running"),Ue=e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:o,disabled:!nt,className:"btn-ghost text-sm",children:[e.jsx(Rt,{size:14}),U("header.runAll")]}),e.jsxs("button",{onClick:g,disabled:!Qe,className:"btn-ghost text-sm",children:[e.jsx(Kt,{size:14}),U("header.stopAll")]})]});return ae==="graph"?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:U("todos.title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[e.jsx(Tt,{onClick:()=>ce("list"),label:U("graph.listView"),size:"sm",children:e.jsx(is,{size:14})}),e.jsx(Tt,{onClick:()=>ce("graph"),label:U("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:e.jsx(gn,{size:14})})]}),Ue]})]}),e.jsx(s.Suspense,{fallback:null,children:e.jsx(uo,{todos:t,projectId:n,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,projectLoopDefaults:a,loopMode:c,onAddTodo:x,onStartTodo:f,onStopTodo:p,onDeleteTodo:h,onEditTodo:m,onMergeTodo:j,onCleanupTodo:z,onRetryTodo:K,onContinueTodo:F,onFixTodo:R,onUpdateDependency:O,onUpdatePosition:X,onEvent:se,onSendInput:G,interactiveTodos:b,debugLogging:v,showTokenUsage:y})})]}):e.jsxs("div",{className:"min-h-[50vh]",onContextMenu:ne=>{$t(ne)||(ne.preventDefault(),L({x:ne.clientX,y:ne.clientY}))},children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:U("todos.title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[e.jsx(Tt,{onClick:()=>ce("list"),label:U("graph.listView"),size:"sm",variant:"active",pressed:!0,children:e.jsx(is,{size:14})}),e.jsx(Tt,{onClick:()=>ce("graph"),label:U("graph.graphView"),size:"sm",children:e.jsx(gn,{size:14})})]}),e.jsx(Tt,{onClick:Ne,label:U(te?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:te?"active":"default",pressed:te,children:e.jsx(ri,{size:14})}),te&&!we&&ae==="list"&&Q.length>0&&e.jsx(Tt,{onClick:Me,label:U("todos.collapseStack"),size:"sm",children:e.jsx(Gl,{size:14})}),Ue,!d&&e.jsxs("button",{onClick:()=>C(!0),className:"btn-primary text-xs py-2",children:[e.jsx(gt,{size:14}),U("todos.add")]})]})]}),d&&e.jsx("div",{className:"mb-5",children:e.jsx(wa,{projectId:n,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,projectLoopDefaults:a,loopMode:c,availableTodos:t,onSave:async(ne,ve,je,Le,ge,Xe,Se,We,et,V,xe)=>{await x(ne,ve,je,Le,ge,Xe,Se,We,et,V,xe),C(!1)},onCancel:()=>C(!1)})}),e.jsx("div",{className:"flex items-center gap-1 mb-4 bg-warm-100 rounded-lg p-0.5 w-fit",children:["all","active","completed","cancelled"].map(ne=>{const ve=J===ne,je=ne==="all"?"todos.filterAll":ne==="active"?"todos.filterActive":ne==="completed"?"todos.filterCompleted":"todos.filterCancelled";return e.jsxs("button",{onClick:()=>$e(ne),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${ve?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[e.jsx("span",{children:U(je)}),e.jsx("span",{className:`text-2xs font-mono ${ve?"text-accent/70":"text-warm-400"}`,children:De[ne]})]},ne)})}),e.jsx("div",{className:Re?"relative cursor-pointer":"space-y-3",onClick:Re?Me:void 0,title:Re?U("todos.expandStack"):void 0,style:Re?{height:76+Math.max(Q.length-1,0)*6}:void 0,children:Q.length===0?e.jsx("div",{className:"card",children:e.jsx(At,{icon:gl,title:U(J==="all"?c==="always"?"loops.empty":"todos.empty":"todos.filterEmpty"),description:J==="all"?U(c==="always"?"loops.emptyHint":"todos.emptyHint"):void 0})}):(()=>{const ne=Q.map(({todo:je})=>je.id),ve=je=>{if(Re||!k)return null;const Le=B!==null&&me===je;return e.jsx("div",{onDragEnter:ge=>{ge.preventDefault(),q(je)},onDragOver:ge=>{ge.preventDefault(),ge.stopPropagation(),ge.dataTransfer.dropEffect="link",q(je)},onDragLeave:()=>Pe(je),onDrop:ge=>{ge.preventDefault(),ge.stopPropagation(),Ge(je,ne)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:Le&&e.jsx("div",{className:"absolute inset-x-0 top-1/2 -translate-y-1/2 h-0.5 bg-accent rounded-full shadow-[0_0_6px_rgba(0,0,0,0.15)]"})},`gap-${je}`)};return e.jsxs(e.Fragment,{children:[ve(0),Q.map(({todo:je,depth:Le},ge)=>{const Xe=W.has(je.id),Se=de.has(je.id),We=6,et="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",V=Re?{position:"absolute",top:ge*We,left:0,right:0,zIndex:Q.length+10-ge,opacity:ge===0?1:.9,pointerEvents:ge===0?"auto":"none",transition:et}:{transition:et};return e.jsxs("div",{className:"",style:V,children:[!Re&&Xe&&e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-2 rounded-lg bg-theme-bg-secondary/60 border border-theme-border",children:[e.jsx(_s,{size:16,className:"text-theme-muted flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:U("todo.chainComplete")}),e.jsx("span",{className:"text-2xs font-mono text-warm-400",children:U("todo.chainTasks").replace("{count}",String(W.get(je.id)))}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[He&&be===null&&e.jsx("span",{className:"text-2xs text-status-error",children:He}),e.jsxs("button",{onClick:()=>qe(je.id),disabled:be===je.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:U("todo.mergeChainDesc"),children:[e.jsx(Rl,{size:14}),be===je.id?"...":U("todo.mergeChain")]})]})]}),e.jsxs("div",{className:"relative",style:{marginLeft:Le>0?`${Le*24}px`:void 0},children:[Le>0&&e.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),e.jsx(co,{todo:je,allTodos:t,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,loopMode:c,onStart:f,onStop:p,onDelete:h,onEdit:m,onMerge:j,onCleanup:z,onRetry:K,onContinue:F,onFix:R,onSchedule:S,onScheduleOnReset:H,resetsAt:_,onEvent:se,isInteractive:b.has(je.id),onSendInput:G,isDragSource:B===je.id,isDragging:B!==null,isDragOver:le===je.id,isValidDropTarget:it(je.id),onDragStart:A,onDragEnd:he,onDragOverTarget:Ke,onDragLeaveTarget:_e,onDropTarget:ze,onRemoveDependency:O?Oe:void 0,debugLogging:v,showTokenUsage:y,isChainMember:Se})]}),ve(ge+1)]},je.id)})]})})()}),!Re&&B&&((ut=t.find(ne=>ne.id===B))==null?void 0:ut.depends_on)&&e.jsxs("div",{className:"mt-3 border-2 border-dashed border-warm-300 rounded-lg p-4 text-center text-sm text-status-error transition-colors hover:border-warm-400 hover:text-status-error hover:bg-status-error/10",onDragOver:ne=>{ne.preventDefault(),ne.dataTransfer.dropEffect="move"},onDrop:ne=>{ne.preventDefault(),B&&O&&(st.current=!0,O(B,null))},children:[e.jsx(ki,{size:20,className:"mx-auto mb-1"}),U("dnd.dropToRemoveDep")]}),N&&e.jsx(yt,{x:N.x,y:N.y,onClose:()=>L(null),children:e.jsxs("button",{onClick:()=>C(!0),className:Be,children:[e.jsx(gt,{size:14}),U("todos.add")]})})]})}const xo=[{value:1,labelKey:"cron.mon"},{value:2,labelKey:"cron.tue"},{value:3,labelKey:"cron.wed"},{value:4,labelKey:"cron.thu"},{value:5,labelKey:"cron.fri"},{value:6,labelKey:"cron.sat"},{value:0,labelKey:"cron.sun"}];function ho(t){const n={mode:"daily",everyMinutes:30,hourlyMinute:0,dailyHour:9,dailyMinute:0,weeklyDays:[1,2,3,4,5],weeklyHour:9,weeklyMinute:0,monthlyDay:1,monthlyHour:9,monthlyMinute:0};if(!t)return n;const r=t.trim().split(/\s+/);if(r.length!==5)return{...n,mode:"custom"};const[i,l,a,,c]=r,x=i.match(/^\*\/(\d+)$/);if(x&&l==="*"&&a==="*"&&c==="*")return{...n,mode:"minutes",everyMinutes:parseInt(x[1])};if(/^\d+$/.test(i)&&l==="*"&&a==="*"&&c==="*")return{...n,mode:"hourly",hourlyMinute:parseInt(i)};const o=/^\d+$/.test(i)?parseInt(i):-1,g=/^\d+$/.test(l)?parseInt(l):-1;if(o<0||g<0)return{...n,mode:"custom"};if(a==="*"&&c!=="*"){const f=c.split(",").map(p=>{const h=parseInt(p);return isNaN(h)?-1:h}).filter(p=>p>=0);if(f.length>0)return{...n,mode:"weekly",weeklyDays:f,weeklyHour:g,weeklyMinute:o}}return/^\d+$/.test(a)&&c==="*"?{...n,mode:"monthly",monthlyDay:parseInt(a),monthlyHour:g,monthlyMinute:o}:a==="*"&&c==="*"?{...n,mode:"daily",dailyHour:g,dailyMinute:o}:{...n,mode:"custom"}}function jn(t){switch(t.mode){case"minutes":return`*/${t.everyMinutes} * * * *`;case"hourly":return`${t.hourlyMinute} * * * *`;case"daily":return`${t.dailyMinute} ${t.dailyHour} * * *`;case"weekly":return`${t.weeklyMinute} ${t.weeklyHour} * * ${t.weeklyDays.sort((n,r)=>n-r).join(",")}`;case"monthly":return`${t.monthlyMinute} ${t.monthlyHour} ${t.monthlyDay} * *`;default:return""}}function po({value:t,onChange:n}){const{t:r}=ye(),[i,l]=s.useState(()=>ho(t)),[a,c]=s.useState(t);s.useEffect(()=>{if(i.mode==="custom")n(a);else{const m=jn(i);n(m)}},[i,a]);const x=m=>{l(j=>({...j,...m}))},o=m=>{l(j=>{const D=j.weeklyDays.includes(m)?j.weeklyDays.filter(z=>z!==m):[...j.weeklyDays,m];return{...j,weeklyDays:D.length>0?D:j.weeklyDays}})},g=[{value:"minutes",labelKey:"cron.everyMinutes"},{value:"hourly",labelKey:"cron.hourly"},{value:"daily",labelKey:"cron.daily"},{value:"weekly",labelKey:"cron.weekly"},{value:"monthly",labelKey:"cron.monthly"},{value:"custom",labelKey:"cron.custom"}],f="bg-warm-50 border border-warm-300 rounded-lg px-2 py-1.5 text-sm text-warm-800 font-mono text-center transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20",p=(m,j,D,z)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("select",{value:m,onChange:K=>D(parseInt(K.target.value)),className:`${f} w-16`,children:Array.from({length:24},(K,F)=>e.jsx("option",{value:F,children:String(F).padStart(2,"0")},F))}),e.jsx("span",{className:"text-warm-500 font-mono",children:":"}),e.jsx("select",{value:j,onChange:K=>z(parseInt(K.target.value)),className:`${f} w-16`,children:Array.from({length:12},(K,F)=>F*5).map(K=>e.jsx("option",{value:K,children:String(K).padStart(2,"0")},K))})]}),h=i.mode==="custom"?a:jn(i);return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.map(m=>e.jsx("button",{type:"button",onClick:()=>x({mode:m.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${i.mode===m.value?"bg-accent text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:r(m.labelKey)},m.value))}),e.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[i.mode==="minutes"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.every")}),e.jsx("select",{value:i.everyMinutes,onChange:m=>x({everyMinutes:parseInt(m.target.value)}),className:`${f} w-20`,children:[5,10,15,20,30].map(m=>e.jsx("option",{value:m,children:m},m))}),e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.minutesLabel")})]}),i.mode==="hourly"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.everyHourAt")}),e.jsx("select",{value:i.hourlyMinute,onChange:m=>x({hourlyMinute:parseInt(m.target.value)}),className:`${f} w-16`,children:Array.from({length:12},(m,j)=>j*5).map(m=>e.jsx("option",{value:m,children:String(m).padStart(2,"0")},m))}),e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.minutesPast")})]}),i.mode==="daily"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.everyDayAt")}),p(i.dailyHour,i.dailyMinute,m=>x({dailyHour:m}),m=>x({dailyMinute:m}))]}),i.mode==="weekly"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:xo.map(m=>e.jsx("button",{type:"button",onClick:()=>o(m.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${i.weeklyDays.includes(m.value)?"bg-accent text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-accent"}`,children:r(m.labelKey)},m.value))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.at")}),p(i.weeklyHour,i.weeklyMinute,m=>x({weeklyHour:m}),m=>x({weeklyMinute:m}))]})]}),i.mode==="monthly"&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.everyMonthOn")}),e.jsx("select",{value:i.monthlyDay,onChange:m=>x({monthlyDay:parseInt(m.target.value)}),className:`${f} w-16`,children:Array.from({length:28},(m,j)=>j+1).map(m=>e.jsx("option",{value:m,children:m},m))}),e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.dayAt")}),p(i.monthlyHour,i.monthlyMinute,m=>x({monthlyHour:m}),m=>x({monthlyMinute:m}))]}),i.mode==="custom"&&e.jsxs("div",{children:[e.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:a,onChange:m=>c(m.target.value),className:"bg-warm-50 border border-warm-300 rounded-lg px-3 py-1.5 w-full text-sm text-warm-800 font-mono transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20"}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:r("schedule.cronHint")})]})]}),i.mode!=="custom"&&h&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsxs("span",{className:"text-warm-400",children:[r("cron.expression"),":"]}),e.jsx("code",{className:"px-2 py-0.5 rounded-md bg-warm-100 text-warm-600 font-mono",children:h})]})]})}function fo(){const t=new Date;t.setHours(t.getHours()+1),t.setMinutes(0,0,0);const n=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0"),l=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0");return`${n}-${r}-${i}T${l}:${a}`}function go(t){const n=new Date(t),r=n.getFullYear(),i=String(n.getMonth()+1).padStart(2,"0"),l=String(n.getDate()).padStart(2,"0"),a=String(n.getHours()).padStart(2,"0"),c=String(n.getMinutes()).padStart(2,"0");return`${r}-${i}-${l}T${a}:${c}`}function ya({onSave:t,onCancel:n,initialTitle:r="",initialDescription:i="",initialCronExpression:l="",initialCliTool:a,initialSkipIfRunning:c=!0,initialScheduleType:x="recurring",initialRunAt:o,projectCliTool:g="claude"}){const[f,p]=s.useState(r),[h,m]=s.useState(i),[j,D]=s.useState(l),[z,K]=s.useState(a||g||"claude"),[F,R]=s.useState(c),[S,H]=s.useState(x),[_,O]=s.useState(o?go(o):fo()),{t:X}=ye(),k=S==="once",se=f.trim()&&(k?!!_:!!j.trim()),G=b=>{b.preventDefault(),se&&t({title:f.trim(),description:h.trim(),cronExpression:k?"":j.trim(),cliTool:z,skipIfRunning:F,scheduleType:S,runAt:k?new Date(_).toISOString():void 0})};return e.jsxs("form",{onSubmit:G,className:"card p-5",children:[e.jsx("div",{className:"mb-3",children:e.jsx("input",{type:"text",placeholder:X("scheduleForm.titlePlaceholder"),value:f,onChange:b=>p(b.target.value),className:"input-field",autoFocus:!0})}),e.jsx("div",{className:"mb-3",children:e.jsx("textarea",{placeholder:X("scheduleForm.descPlaceholder"),value:h,onChange:b=>m(b.target.value),rows:3,className:"input-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"})}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("schedule.type")}),e.jsxs("div",{className:"inline-flex gap-1 rounded-lg bg-warm-100 p-1",children:[e.jsx("button",{type:"button",onClick:()=>H("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${S==="recurring"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:X("schedule.recurring")}),e.jsx("button",{type:"button",onClick:()=>H("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${S==="once"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:X("schedule.once")})]})]}),k?e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("schedule.runAtLabel")}),e.jsx("input",{type:"datetime-local",value:_,onChange:b=>O(b.target.value),className:"input-field text-sm font-mono",min:new Date().toISOString().slice(0,16)})]}):e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("schedule.cronExpression")}),e.jsx(po,{value:j,onChange:D})]}),e.jsx("div",{className:"mb-3 grid grid-cols-2 gap-3",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("scheduleForm.cliTool")}),e.jsx("select",{value:z,onChange:b=>K(b.target.value),className:"input-field text-sm !py-2",children:bt.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]})}),!k&&e.jsx("div",{className:"mb-4",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:F,onChange:b=>R(b.target.checked),className:"rounded-md border-warm-300 text-accent focus:ring-accent"}),X("schedule.skipIfRunning")]})}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx("button",{type:"button",onClick:n,className:"btn-ghost text-sm",children:X("scheduleForm.cancel")}),e.jsx("button",{type:"submit",disabled:!se,className:"btn-primary text-sm",children:X("scheduleForm.save")})]})]})}function bo({schedule:t,onToggle:n,onDelete:r,onEdit:i,onTrigger:l,onMergeRun:a,onCleanupRun:c}){const[x,o]=s.useState(!1),[g,f]=s.useState(!1),[p,h]=s.useState([]),[m,j]=s.useState(!1),[D,z]=s.useState(!1),[K,F]=s.useState(null),{t:R}=ye(),S=async()=>{try{const y=await ws(t.id);h(y)}catch{}},H=async y=>{if(!(!y.todo_id||!a)){F(y.id);try{await a(y.todo_id),await S()}finally{F(null)}}},_=async y=>{if(!(!y.todo_id||!c)){F(y.id);try{await c(y.todo_id),await S()}finally{F(null)}}},O=t.schedule_type==="once",X=async()=>{if(!m)try{const y=await ws(t.id);h(y),j(!0)}catch{}},k=()=>{const y=!x;o(y),y&&X()},se=async()=>{z(!0);try{await l(t.id);const y=await ws(t.id);h(y),j(!0)}finally{z(!1)}};if(g)return e.jsx(ya,{initialTitle:t.title,initialDescription:t.description??"",initialCronExpression:O?"":t.cron_expression,initialCliTool:t.cli_tool??void 0,initialSkipIfRunning:!!t.skip_if_running,initialScheduleType:t.schedule_type,initialRunAt:t.run_at??void 0,onSave:async y=>{await i(t.id,{title:y.title,description:y.description,cron_expression:y.cronExpression||void 0,cli_tool:y.cliTool,skip_if_running:y.skipIfRunning,schedule_type:y.scheduleType,run_at:y.runAt}),f(!1)},onCancel:()=>f(!1)});const G={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},b={triggered:R("schedule.runTriggered"),skipped:R("schedule.runSkipped"),completed:R("schedule.runCompleted"),failed:R("schedule.runFailed")},v=y=>y?new Date(y).toLocaleString():"";return e.jsxs("div",{className:"card overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:k,children:[e.jsx("button",{className:"mt-0.5 text-warm-400 hover:text-warm-600 flex-shrink-0 transition-colors",children:e.jsx(St,{size:14,className:`transition-transform duration-200 ${x?"rotate-90":""}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm text-warm-800 font-medium truncate",children:t.title}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-2xs text-warm-400",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[e.jsx(zt,{size:12}),O?v(t.run_at):t.cron_expression]}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:R(O?"schedule.once":"schedule.recurring")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warm-500",children:[e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${t.is_active?"bg-status-success":"bg-warm-400"}`}),t.is_active?R("schedule.active"):R("schedule.paused")]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:y=>y.stopPropagation(),children:[e.jsx("button",{onClick:se,disabled:D,className:"p-1.5 text-status-warning hover:text-status-warning hover:bg-status-warning/10 rounded-lg transition-colors disabled:opacity-30",title:R("schedule.trigger"),children:e.jsx(Rt,{size:14})}),e.jsx("button",{onClick:()=>n(t.id,!t.is_active),className:`p-1.5 rounded-lg transition-colors ${t.is_active?"text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10":"text-status-success/60 hover:text-status-success hover:bg-status-success/10"}`,title:t.is_active?R("schedule.pause"):R("schedule.activate"),children:t.is_active?e.jsx(da,{size:14}):e.jsx(cr,{size:14})}),e.jsx("button",{onClick:()=>f(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:R("schedule.edit"),children:e.jsx(Wt,{size:14})}),e.jsx("button",{onClick:()=>r(t.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:R("schedule.delete"),children:e.jsx(wt,{size:14})})]})]}),x&&e.jsxs("div",{className:"border-t border-warm-200 px-5 py-5 space-y-4 bg-warm-50/50",children:[t.description&&e.jsx("div",{children:e.jsx("p",{className:"text-sm text-warm-600 whitespace-pre-wrap leading-relaxed",children:t.description})}),e.jsxs("div",{className:"grid gap-x-8 gap-y-2 text-xs sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[e.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:R(O?"schedule.runAtLabel":"schedule.cronExpression")}),e.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:O?v(t.run_at):t.cron_expression})]}),e.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[e.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:R("schedule.lastRun")}),e.jsx("span",{className:"min-w-0 truncate text-warm-600",children:t.last_run_at?new Date(t.last_run_at).toLocaleString():R("schedule.never")})]}),!O&&t.skip_if_running&&e.jsxs("div",{className:"flex items-center gap-2 text-warm-500 sm:col-span-2",children:[e.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-warm-400"}),R("schedule.skipIfRunning")]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:R("schedule.runs")}),p.length===0?e.jsx("p",{className:"text-xs text-warm-400 italic",children:R("schedule.noRuns")}):e.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:p.map(y=>{const d=y.todo_id&&y.todo_status==="completed"&&!!y.todo_branch_name,C=y.todo_id&&y.todo_status!=="running"&&y.todo_status!=="pending"&&(y.todo_worktree_path||y.todo_branch_name),N=K===y.id;return e.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 font-medium text-warm-600",children:[e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${G[y.status]||"bg-warm-400"}`}),b[y.status]||y.status]}),y.skipped_reason&&e.jsxs("span",{className:"text-warm-400",children:["(",y.skipped_reason,")"]}),e.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[d&&a&&e.jsx("button",{onClick:()=>H(y),disabled:N,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded-md transition-colors disabled:opacity-30",title:R("todo.merge"),children:e.jsx(Fs,{size:12})}),C&&c&&e.jsx("button",{onClick:()=>_(y),disabled:N,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded-md transition-colors disabled:opacity-30",title:R("todo.cleanup"),children:e.jsx(wt,{size:12})})]}),e.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(y.started_at).toLocaleString()})]},y.id)})})]})]})]})}function vo({schedules:t,projectCliTool:n,onAddSchedule:r,onToggleSchedule:i,onDeleteSchedule:l,onEditSchedule:a,onTriggerSchedule:c,onMergeRun:x,onCleanupRun:o}){const[g,f]=s.useState(!1),[p,h]=s.useState(null),{t:m}=ye();return e.jsxs("div",{className:"min-h-[50vh]",onContextMenu:j=>{$t(j)||(j.preventDefault(),h({x:j.clientX,y:j.clientY}))},children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:m("schedules.title")}),!g&&e.jsxs("button",{onClick:()=>f(!0),className:"btn-primary btn-sm",children:[e.jsx(gt,{size:14}),m("schedules.add")]})]}),g&&e.jsx("div",{className:"mb-5",children:e.jsx(ya,{projectCliTool:n,onSave:async j=>{await r(j),f(!1)},onCancel:()=>f(!1)})}),e.jsx("div",{className:"space-y-3",children:t.length===0?e.jsx("div",{className:"card",children:e.jsx(At,{icon:Ol,title:m("schedules.empty"),description:m("schedules.emptyHint")})}):t.map((j,D)=>e.jsx("div",{children:e.jsx(bo,{schedule:j,onToggle:i,onDelete:l,onEdit:a,onTrigger:c,onMergeRun:x,onCleanupRun:o})},j.id))}),p&&e.jsx(yt,{x:p.x,y:p.y,onClose:()=>h(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>f(!0),children:[e.jsx(gt,{size:14}),m("schedules.add")]})})]})}const Nn="__custom__";function wo({open:t,onClose:n,projectId:r,projectName:i,onPushed:l}){const{t:a}=ye(),[c,x]=s.useState(!1),[o,g]=s.useState(!1),[f,p]=s.useState(null),[h,m]=s.useState([]),[j,D]=s.useState("origin"),[z,K]=s.useState([]),[F,R]=s.useState([]),[S,H]=s.useState(!0),[_,O]=s.useState(!1);s.useEffect(()=>{if(!t)return;let d=!1;return x(!0),p(null),Promise.all([dr(r),Ms(r)]).then(([C,N])=>{var ae,w;if(d)return;const L=C.remotes||[];m(L);const B=((ae=L.find(J=>J.name==="origin"))==null?void 0:ae.name)||((w=L[0])==null?void 0:w.name)||"origin";D(B);const Y=N.branches||[],le=Y.filter(J=>!J.remote),ue=`remotes/${B}/`,me=Y.filter(J=>J.remote&&J.name.startsWith(ue)).map(J=>J.name.slice(ue.length)).filter(J=>J&&J!=="HEAD");R(me);const pe=new Set(me);K(le.map(J=>{const M=pe.has(J.name);return{local:J.name,current:J.current,remote:J.name,customRemote:!1,setUpstream:!M,checked:J.current}}))}).catch(C=>{d||p(C instanceof Error?C.message:"Failed to load remotes")}).finally(()=>{d||x(!1)}),()=>{d=!0}},[t,r]),s.useEffect(()=>{if(!t||!j)return;let d=!1;return Ms(r).then(C=>{if(d)return;const N=`remotes/${j}/`,L=(C.branches||[]).filter(B=>B.remote&&B.name.startsWith(N)).map(B=>B.name.slice(N.length)).filter(B=>B&&B!=="HEAD");R(L)}).catch(()=>{}),()=>{d=!0}},[j,r,t]);const X=z.length>0&&z.every(d=>d.checked),k=z.some(d=>d.checked),se=z.filter(d=>d.checked).length,G=s.useMemo(()=>{var d;return((d=h.find(C=>C.name===j))==null?void 0:d.url)||""},[h,j]),b=(d,C)=>{K(N=>N.map(L=>L.local===d?{...L,...C}:L))},v=()=>{const d=!X;K(C=>C.map(N=>({...N,checked:d})))},y=async()=>{p(null);const d=z.filter(N=>N.checked);if(d.length===0){p(a("git.pushDialog.errorRequireBranch"));return}const C=d.map(N=>({local:N.local,remote:(N.remote||"").trim()||N.local,setUpstream:N.setUpstream}));g(!0);try{await Bs(r,{remote:j,branches:C,pushAllTags:S,force:_}),l==null||l(),n()}catch(N){p(N instanceof Error?N.message:"Push failed")}finally{g(!1)}};return e.jsx(vt,{open:t,onClose:o?()=>{}:n,size:"2xl",disableBackdropClose:!0,disableEscClose:o,children:e.jsxs("div",{className:"card p-5 space-y-4",children:[e.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",i]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:a("git.pushDialog.targetRemote")}),e.jsxs("select",{value:j,onChange:d=>D(d.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:c||o||h.length===0,children:[h.length===0&&e.jsx("option",{value:"origin",children:"origin"}),h.map(d=>e.jsx("option",{value:d.name,children:d.name},d.name))]}),e.jsx("input",{readOnly:!0,value:G,className:"input-field text-xs font-mono py-1.5 px-3 flex-1 cursor-default"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"section-label mb-2",children:a("git.pushDialog.branchesHeader")}),e.jsx("div",{className:"rounded-xl border border-theme-border-strong overflow-hidden",children:e.jsx("div",{className:"overflow-auto max-h-[50vh]",children:e.jsxs("table",{className:"w-full text-sm border-collapse",children:[e.jsx("thead",{className:"sticky top-0 bg-warm-100 z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-12",children:a("git.pushDialog.colPush")}),e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:a("git.pushDialog.colLocal")}),e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:a("git.pushDialog.colRemote")}),e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-16",children:a("git.pushDialog.colTracking")})]})}),e.jsxs("tbody",{children:[c&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:a("git.pushDialog.loading")})}),!c&&z.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:a("git.pushDialog.noLocalBranches")})}),z.map(d=>e.jsxs("tr",{className:"border-t border-theme-border/50 hover:bg-theme-hover/40 transition-colors",children:[e.jsx("td",{className:"py-2 px-3",children:e.jsx("input",{type:"checkbox",checked:d.checked,onChange:C=>b(d.local,{checked:C.target.checked}),disabled:o,className:"cursor-pointer"})}),e.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[d.local,d.current&&e.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),e.jsx("td",{className:"py-2 px-3",children:d.customRemote?e.jsx("input",{type:"text",value:d.remote,onChange:C=>b(d.local,{remote:C.target.value}),placeholder:d.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:o}):e.jsxs("select",{value:F.includes(d.remote)||d.remote?d.remote:"",onChange:C=>{const N=C.target.value;N===Nn?b(d.local,{customRemote:!0}):b(d.local,{remote:N})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:o,children:[!F.includes(d.remote)&&d.remote&&e.jsxs("option",{value:d.remote,children:[d.remote," (",a("git.pushDialog.newBranch"),")"]}),F.map(C=>e.jsx("option",{value:C,children:C},C)),e.jsx("option",{value:Nn,children:a("git.pushDialog.customRemote")})]})}),e.jsx("td",{className:"py-2 px-3",children:e.jsx("input",{type:"checkbox",checked:d.setUpstream,onChange:C=>b(d.local,{setUpstream:C.target.checked}),disabled:o,className:"cursor-pointer"})})]},d.local))]})]})})})]}),e.jsxs("div",{className:"flex items-center gap-5 text-xs text-warm-700",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:X,ref:d=>{d&&(d.indeterminate=!X&&k)},onChange:v,disabled:o||z.length===0,className:"cursor-pointer"}),a("git.pushDialog.selectAll")]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:d=>H(d.target.checked),disabled:o,className:"cursor-pointer"}),a("git.pushDialog.allTags")]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:d=>O(d.target.checked),disabled:o,className:"cursor-pointer"}),e.jsx("span",{title:a("git.pushDialog.forceHint"),children:a("git.pushDialog.force")})]})]}),f&&e.jsx("div",{className:"text-xs text-status-error font-medium",children:f}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:n,disabled:o,className:"btn-secondary btn-md",children:a("git.pushDialog.cancel")}),e.jsx("button",{type:"button",onClick:y,disabled:o||c||se===0,className:"btn-primary btn-md",children:a(o?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function yo(t){const n=t.split(`
|
|
163
|
+
`).map((P,Te)=>{let Ye="text-theme-text",ot="";return P.startsWith("+")&&!P.startsWith("+++")?Ye="text-theme-text bg-status-success/15":P.startsWith("-")&&!P.startsWith("---")?Ye="text-theme-text bg-status-error/15":P.startsWith("@@")?Ye="text-accent":P.startsWith("diff ")&&(Ye="text-warm-700",ot="font-semibold"),e.jsx("div",{className:`whitespace-pre ${Ye} ${ot}`,children:P},Te)}):e.jsx("span",{className:"text-warm-400 italic",children:Z("log.noChanges")})})]}),e.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:mt.bg,fontFamily:bs,border:`1px solid ${mt.separator}`},children:[e.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${mt.separator}`,fontSize:12,color:mt.text},children:[e.jsx("span",{style:{color:mt.prompt},children:"$"})," ",e.jsx("span",{style:{color:mt.bright},children:"tail"})," ",e.jsx("span",{style:{color:mt.dim},children:"-f task.log"})]}),e.jsx(ol,{logs:ue,interactive:R&&t.status==="running",todoId:t.id,onSendInput:S,embedded:!0})]})]})})]}),Xs&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-accent/50 bg-accent/5",children:[e.jsx(_s,{size:14,className:"text-accent flex-shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-accent",children:Z("dnd.dropHint")})]}),Zs&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-warm-300 bg-status-error/10",children:[e.jsx(Il,{size:14,className:"text-status-error flex-shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-status-error",children:Z("dnd.cyclicWarning")})]}),xe&&e.jsxs(yt,{x:xe.x,y:xe.y,onClose:()=>fe(null),children:[u&&e.jsxs("button",{onClick:()=>c(t.id,"headless"),className:Be,title:Z("todo.startHeadless"),children:[e.jsx(Rt,{size:14}),Z("todo.start")]}),u&&qs&&e.jsxs("button",{onClick:()=>c(t.id,"interactive"),className:Be,title:Z("todo.startInteractiveDesc"),children:[e.jsx(Bt,{size:14}),Z("todo.startInteractive")]}),u&&e.jsxs("button",{onClick:()=>c(t.id,"verbose"),className:Be,title:Z("todo.startVerboseDesc"),children:[e.jsx(xn,{size:14}),Z("todo.startVerbose")]}),ee&&e.jsxs("button",{onClick:()=>x(t.id),className:Be,children:[e.jsx(Kt,{size:14}),Z("todo.stop")]}),ke&&e.jsxs("button",{onClick:Ae,disabled:ce,className:Be,children:[e.jsx(Fs,{size:14}),Z("todo.merge")]}),ht&&e.jsxs("button",{onClick:()=>{Ee(!0),_e(null)},disabled:A,className:Be,children:[e.jsx(pn,{size:14}),Z("todo.continue")]}),Ve&&e.jsxs("button",{onClick:()=>It("headless"),disabled:W,className:Be,children:[e.jsx(Vt,{size:14}),Z("todo.retry")]}),E&&e.jsxs("button",{onClick:()=>Le(!0),className:Be,title:Z("todo.scheduleDesc"),children:[e.jsx(zs,{size:14}),Z("todo.schedule")]}),T&&e.jsxs("button",{onClick:()=>{Oe(!0),Qe(null)},className:Be,title:Z("todo.scheduleOnResetDesc"),children:[e.jsx(zt,{size:14}),Z("todo.scheduleOnReset")]}),ie&&e.jsxs("button",{onClick:Ce,disabled:re,className:Be,children:[e.jsx(ss,{size:14}),Z("todo.viewDiff")]}),d&&$&&e.jsxs("button",{onClick:oe,className:Be,children:[e.jsx(bn,{size:14}),Z("todo.viewDebugLog")]}),at&&e.jsxs("button",{onClick:rt,disabled:Re,className:Be,children:[e.jsx(ls,{size:14}),Z("todo.cleanup")]}),e.jsx(Ks,{}),e.jsxs("button",{onClick:()=>le(!0),className:Be,children:[e.jsx(Wt,{size:14}),Z("todo.edit")]}),e.jsxs("button",{onClick:()=>o(t.id),className:ra,children:[e.jsx(wt,{size:14}),Z("todo.delete")]})]})]})}const uo=s.lazy(()=>hs(()=>import("./TaskGraph-BrHxqYJn.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12]))),Qt={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function yn(t,n,r){let i=r;const l=new Set;for(;i;){if(i===n)return!0;if(l.has(i))return!1;l.add(i);const a=t.find(c=>c.id===i);i=(a==null?void 0:a.depends_on)??null}return!1}function mo({todos:t,projectId:n,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,projectLoopDefaults:a,loopMode:c="toggle",onAddTodo:x,onStartAll:o,onStopAll:g,onStartTodo:f,onStopTodo:p,onDeleteTodo:h,onEditTodo:m,onMergeTodo:j,onMergeChain:D,onCleanupTodo:z,onRetryTodo:K,onContinueTodo:F,onFixTodo:R,onScheduleTodo:S,onScheduleOnResetTodo:H,resetsAt:_,onUpdateDependency:O,onUpdatePosition:X,onReorderTodos:k,onEvent:se,onSendInput:G,interactiveTodos:b,debugLogging:v,showTokenUsage:y}){var ut;const[d,C]=s.useState(!1),[N,L]=s.useState(null),[B,Y]=s.useState(null),[le,ue]=s.useState(null),[me,pe]=s.useState(null),[ae,w]=s.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[J,M]=s.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[te,re]=s.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[we,I]=s.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:U}=ye(),ce=s.useCallback(ne=>{w(ne);try{localStorage.setItem("todoViewMode",ne)}catch{}},[]),$e=s.useCallback(ne=>{M(ne);try{localStorage.setItem("todoStatusFilter",ne)}catch{}},[]),Ne=s.useCallback(()=>{re(ne=>{const ve=!ne;try{localStorage.setItem("todoStackModeEnabled",String(ve))}catch{}if(!ve){I(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return ve})},[]),Me=s.useCallback(()=>{I(ne=>{const ve=!ne;try{localStorage.setItem("todoStackCollapsed",String(ve))}catch{}return ve})},[]),Re=te&&we&&ae==="list",De=s.useMemo(()=>({all:t.length,active:t.filter(ne=>Qt.active.includes(ne.status)).length,completed:t.filter(ne=>Qt.completed.includes(ne.status)).length,cancelled:t.filter(ne=>Qt.cancelled.includes(ne.status)).length}),[t]),Je=s.useMemo(()=>{const ne=Qt[J];return ne?t.filter(ve=>ne.includes(ve.status)):t},[t,J]),Q=(()=>{const ne=[...Je].sort((Se,We)=>Se.priority-We.priority);if(J!=="all"||Re)return ne.map(Se=>({todo:Se,depth:0}));const ve=new Map,je=[];for(const Se of ne)if(Se.depends_on){const We=ve.get(Se.depends_on)||[];We.push(Se),ve.set(Se.depends_on,We)}else je.push(Se);const Le=[],ge=new Set,Xe=(Se,We)=>{if(ge.has(Se.id))return;ge.add(Se.id),Le.push({todo:Se,depth:We});const et=ve.get(Se.id);if(et)for(const V of et)Xe(V,We+1)};for(const Se of je)Xe(Se,0);for(const Se of ne)ge.has(Se.id)||Le.push({todo:Se,depth:0});return Le})(),{completedChainRoots:W,completedChainMembers:de}=s.useMemo(()=>{const ne=new Map;for(const ge of t)if(ge.depends_on){const Xe=ne.get(ge.depends_on)||[];Xe.push(ge.id),ne.set(ge.depends_on,Xe)}const ve=t.filter(ge=>!ge.depends_on&&ne.has(ge.id)),je=new Map,Le=new Set;for(const ge of ve){const Xe=[],Se=We=>{if(!t.find(xe=>xe.id===We))return;Xe.push(We);const V=ne.get(We)||[];for(const xe of V)Se(xe)};if(Se(ge.id),Xe.length>=2&&Xe.every(We=>{const et=t.find(V=>V.id===We);return(et==null?void 0:et.status)==="completed"||(et==null?void 0:et.status)==="merged"})){je.set(ge.id,Xe.length);for(const We of Xe)Le.add(We)}}return{completedChainRoots:je,completedChainMembers:Le}},[t]),[be,Ie]=s.useState(null),[He,Ee]=s.useState(null),qe=s.useCallback(async ne=>{if(D){Ie(ne),Ee(null);try{await D(ne)}catch(ve){Ee(ve instanceof Error?ve.message:"Merge failed")}finally{Ie(null)}}},[D]),st=s.useRef(!1),A=s.useCallback(ne=>{st.current=!1,Y(ne)},[]),he=s.useCallback(async()=>{if(!st.current&&B&&O){const ne=t.find(ve=>ve.id===B);ne!=null&&ne.depends_on&&await O(B,null)}Y(null),ue(null),pe(null)},[B,t,O]),Ke=s.useCallback(ne=>{ue(ne),pe(null)},[]),_e=s.useCallback(ne=>{ue(ve=>ve===ne?null:ve)},[]),ze=s.useCallback(async ne=>{!B||!O||B!==ne&&(yn(t,B,ne)||(st.current=!0,await O(B,ne),Y(null),ue(null),pe(null)))},[B,t,O]),Oe=s.useCallback(async ne=>{O&&await O(ne,null)},[O]),it=s.useCallback(ne=>!B||B===ne?!1:!yn(t,B,ne),[B,t]),q=s.useCallback(ne=>{pe(ne),ue(null)},[]),Pe=s.useCallback(ne=>{pe(ve=>ve===ne?null:ve)},[]),Ge=s.useCallback(async(ne,ve)=>{if(!B||!k)return;const je=ve.indexOf(B);if(je<0)return;const Le=ve.filter(Se=>Se!==B),ge=ne>je?ne-1:ne;if(ge===je){pe(null);return}const Xe=[...Le.slice(0,ge),B,...Le.slice(ge)];st.current=!0,await k(Xe),Y(null),pe(null),ue(null)},[B,k]),nt=t.some(ne=>ne.status==="pending"||ne.status==="failed"||ne.status==="stopped"),Qe=t.some(ne=>ne.status==="running"),Ue=e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:o,disabled:!nt,className:"btn-ghost text-sm",children:[e.jsx(Rt,{size:14}),U("header.runAll")]}),e.jsxs("button",{onClick:g,disabled:!Qe,className:"btn-ghost text-sm",children:[e.jsx(Kt,{size:14}),U("header.stopAll")]})]});return ae==="graph"?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:U("todos.title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[e.jsx(Tt,{onClick:()=>ce("list"),label:U("graph.listView"),size:"sm",children:e.jsx(is,{size:14})}),e.jsx(Tt,{onClick:()=>ce("graph"),label:U("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:e.jsx(gn,{size:14})})]}),Ue]})]}),e.jsx(s.Suspense,{fallback:null,children:e.jsx(uo,{todos:t,projectId:n,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,projectLoopDefaults:a,loopMode:c,onAddTodo:x,onStartTodo:f,onStopTodo:p,onDeleteTodo:h,onEditTodo:m,onMergeTodo:j,onCleanupTodo:z,onRetryTodo:K,onContinueTodo:F,onFixTodo:R,onUpdateDependency:O,onUpdatePosition:X,onEvent:se,onSendInput:G,interactiveTodos:b,debugLogging:v,showTokenUsage:y})})]}):e.jsxs("div",{className:"min-h-[50vh]",onContextMenu:ne=>{$t(ne)||(ne.preventDefault(),L({x:ne.clientX,y:ne.clientY}))},children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:U("todos.title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[e.jsx(Tt,{onClick:()=>ce("list"),label:U("graph.listView"),size:"sm",variant:"active",pressed:!0,children:e.jsx(is,{size:14})}),e.jsx(Tt,{onClick:()=>ce("graph"),label:U("graph.graphView"),size:"sm",children:e.jsx(gn,{size:14})})]}),e.jsx(Tt,{onClick:Ne,label:U(te?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:te?"active":"default",pressed:te,children:e.jsx(ri,{size:14})}),te&&!we&&ae==="list"&&Q.length>0&&e.jsx(Tt,{onClick:Me,label:U("todos.collapseStack"),size:"sm",children:e.jsx(Gl,{size:14})}),Ue,!d&&e.jsxs("button",{onClick:()=>C(!0),className:"btn-primary text-xs py-2",children:[e.jsx(gt,{size:14}),U("todos.add")]})]})]}),d&&e.jsx("div",{className:"mb-5",children:e.jsx(wa,{projectId:n,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,projectLoopDefaults:a,loopMode:c,availableTodos:t,onSave:async(ne,ve,je,Le,ge,Xe,Se,We,et,V,xe)=>{await x(ne,ve,je,Le,ge,Xe,Se,We,et,V,xe),C(!1)},onCancel:()=>C(!1)})}),e.jsx("div",{className:"flex items-center gap-1 mb-4 bg-warm-100 rounded-lg p-0.5 w-fit",children:["all","active","completed","cancelled"].map(ne=>{const ve=J===ne,je=ne==="all"?"todos.filterAll":ne==="active"?"todos.filterActive":ne==="completed"?"todos.filterCompleted":"todos.filterCancelled";return e.jsxs("button",{onClick:()=>$e(ne),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${ve?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[e.jsx("span",{children:U(je)}),e.jsx("span",{className:`text-2xs font-mono ${ve?"text-accent/70":"text-warm-400"}`,children:De[ne]})]},ne)})}),e.jsx("div",{className:Re?"relative cursor-pointer":"space-y-3",onClick:Re?Me:void 0,title:Re?U("todos.expandStack"):void 0,style:Re?{height:76+Math.max(Q.length-1,0)*6}:void 0,children:Q.length===0?e.jsx("div",{className:"card",children:e.jsx(At,{icon:gl,title:U(J==="all"?c==="always"?"loops.empty":"todos.empty":"todos.filterEmpty"),description:J==="all"?U(c==="always"?"loops.emptyHint":"todos.emptyHint"):void 0})}):(()=>{const ne=Q.map(({todo:je})=>je.id),ve=je=>{if(Re||!k)return null;const Le=B!==null&&me===je;return e.jsx("div",{onDragEnter:ge=>{ge.preventDefault(),q(je)},onDragOver:ge=>{ge.preventDefault(),ge.stopPropagation(),ge.dataTransfer.dropEffect="link",q(je)},onDragLeave:()=>Pe(je),onDrop:ge=>{ge.preventDefault(),ge.stopPropagation(),Ge(je,ne)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:Le&&e.jsx("div",{className:"absolute inset-x-0 top-1/2 -translate-y-1/2 h-0.5 bg-accent rounded-full shadow-[0_0_6px_rgba(0,0,0,0.15)]"})},`gap-${je}`)};return e.jsxs(e.Fragment,{children:[ve(0),Q.map(({todo:je,depth:Le},ge)=>{const Xe=W.has(je.id),Se=de.has(je.id),We=6,et="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",V=Re?{position:"absolute",top:ge*We,left:0,right:0,zIndex:Q.length+10-ge,opacity:ge===0?1:.9,pointerEvents:ge===0?"auto":"none",transition:et}:{transition:et};return e.jsxs("div",{className:"",style:V,children:[!Re&&Xe&&e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-2 rounded-lg bg-theme-bg-secondary/60 border border-theme-border",children:[e.jsx(_s,{size:16,className:"text-theme-muted flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:U("todo.chainComplete")}),e.jsx("span",{className:"text-2xs font-mono text-warm-400",children:U("todo.chainTasks").replace("{count}",String(W.get(je.id)))}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[He&&be===null&&e.jsx("span",{className:"text-2xs text-status-error",children:He}),e.jsxs("button",{onClick:()=>qe(je.id),disabled:be===je.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:U("todo.mergeChainDesc"),children:[e.jsx(Rl,{size:14}),be===je.id?"...":U("todo.mergeChain")]})]})]}),e.jsxs("div",{className:"relative",style:{marginLeft:Le>0?`${Le*24}px`:void 0},children:[Le>0&&e.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),e.jsx(co,{todo:je,allTodos:t,projectCliTool:r,projectIsGitRepo:i,projectUseWorktree:l,loopMode:c,onStart:f,onStop:p,onDelete:h,onEdit:m,onMerge:j,onCleanup:z,onRetry:K,onContinue:F,onFix:R,onSchedule:S,onScheduleOnReset:H,resetsAt:_,onEvent:se,isInteractive:b.has(je.id),onSendInput:G,isDragSource:B===je.id,isDragging:B!==null,isDragOver:le===je.id,isValidDropTarget:it(je.id),onDragStart:A,onDragEnd:he,onDragOverTarget:Ke,onDragLeaveTarget:_e,onDropTarget:ze,onRemoveDependency:O?Oe:void 0,debugLogging:v,showTokenUsage:y,isChainMember:Se})]}),ve(ge+1)]},je.id)})]})})()}),!Re&&B&&((ut=t.find(ne=>ne.id===B))==null?void 0:ut.depends_on)&&e.jsxs("div",{className:"mt-3 border-2 border-dashed border-warm-300 rounded-lg p-4 text-center text-sm text-status-error transition-colors hover:border-warm-400 hover:text-status-error hover:bg-status-error/10",onDragOver:ne=>{ne.preventDefault(),ne.dataTransfer.dropEffect="move"},onDrop:ne=>{ne.preventDefault(),B&&O&&(st.current=!0,O(B,null))},children:[e.jsx(ki,{size:20,className:"mx-auto mb-1"}),U("dnd.dropToRemoveDep")]}),N&&e.jsx(yt,{x:N.x,y:N.y,onClose:()=>L(null),children:e.jsxs("button",{onClick:()=>C(!0),className:Be,children:[e.jsx(gt,{size:14}),U("todos.add")]})})]})}const xo=[{value:1,labelKey:"cron.mon"},{value:2,labelKey:"cron.tue"},{value:3,labelKey:"cron.wed"},{value:4,labelKey:"cron.thu"},{value:5,labelKey:"cron.fri"},{value:6,labelKey:"cron.sat"},{value:0,labelKey:"cron.sun"}];function ho(t){const n={mode:"daily",everyMinutes:30,hourlyMinute:0,dailyHour:9,dailyMinute:0,weeklyDays:[1,2,3,4,5],weeklyHour:9,weeklyMinute:0,monthlyDay:1,monthlyHour:9,monthlyMinute:0};if(!t)return n;const r=t.trim().split(/\s+/);if(r.length!==5)return{...n,mode:"custom"};const[i,l,a,,c]=r,x=i.match(/^\*\/(\d+)$/);if(x&&l==="*"&&a==="*"&&c==="*")return{...n,mode:"minutes",everyMinutes:parseInt(x[1])};if(/^\d+$/.test(i)&&l==="*"&&a==="*"&&c==="*")return{...n,mode:"hourly",hourlyMinute:parseInt(i)};const o=/^\d+$/.test(i)?parseInt(i):-1,g=/^\d+$/.test(l)?parseInt(l):-1;if(o<0||g<0)return{...n,mode:"custom"};if(a==="*"&&c!=="*"){const f=c.split(",").map(p=>{const h=parseInt(p);return isNaN(h)?-1:h}).filter(p=>p>=0);if(f.length>0)return{...n,mode:"weekly",weeklyDays:f,weeklyHour:g,weeklyMinute:o}}return/^\d+$/.test(a)&&c==="*"?{...n,mode:"monthly",monthlyDay:parseInt(a),monthlyHour:g,monthlyMinute:o}:a==="*"&&c==="*"?{...n,mode:"daily",dailyHour:g,dailyMinute:o}:{...n,mode:"custom"}}function jn(t){switch(t.mode){case"minutes":return`*/${t.everyMinutes} * * * *`;case"hourly":return`${t.hourlyMinute} * * * *`;case"daily":return`${t.dailyMinute} ${t.dailyHour} * * *`;case"weekly":return`${t.weeklyMinute} ${t.weeklyHour} * * ${t.weeklyDays.sort((n,r)=>n-r).join(",")}`;case"monthly":return`${t.monthlyMinute} ${t.monthlyHour} ${t.monthlyDay} * *`;default:return""}}function po({value:t,onChange:n}){const{t:r}=ye(),[i,l]=s.useState(()=>ho(t)),[a,c]=s.useState(t);s.useEffect(()=>{if(i.mode==="custom")n(a);else{const m=jn(i);n(m)}},[i,a]);const x=m=>{l(j=>({...j,...m}))},o=m=>{l(j=>{const D=j.weeklyDays.includes(m)?j.weeklyDays.filter(z=>z!==m):[...j.weeklyDays,m];return{...j,weeklyDays:D.length>0?D:j.weeklyDays}})},g=[{value:"minutes",labelKey:"cron.everyMinutes"},{value:"hourly",labelKey:"cron.hourly"},{value:"daily",labelKey:"cron.daily"},{value:"weekly",labelKey:"cron.weekly"},{value:"monthly",labelKey:"cron.monthly"},{value:"custom",labelKey:"cron.custom"}],f="bg-warm-50 border border-warm-300 rounded-lg px-2 py-1.5 text-sm text-warm-800 font-mono text-center transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20",p=(m,j,D,z)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("select",{value:m,onChange:K=>D(parseInt(K.target.value)),className:`${f} w-16`,children:Array.from({length:24},(K,F)=>e.jsx("option",{value:F,children:String(F).padStart(2,"0")},F))}),e.jsx("span",{className:"text-warm-500 font-mono",children:":"}),e.jsx("select",{value:j,onChange:K=>z(parseInt(K.target.value)),className:`${f} w-16`,children:Array.from({length:12},(K,F)=>F*5).map(K=>e.jsx("option",{value:K,children:String(K).padStart(2,"0")},K))})]}),h=i.mode==="custom"?a:jn(i);return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.map(m=>e.jsx("button",{type:"button",onClick:()=>x({mode:m.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${i.mode===m.value?"bg-accent text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:r(m.labelKey)},m.value))}),e.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[i.mode==="minutes"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.every")}),e.jsx("select",{value:i.everyMinutes,onChange:m=>x({everyMinutes:parseInt(m.target.value)}),className:`${f} w-20`,children:[5,10,15,20,30].map(m=>e.jsx("option",{value:m,children:m},m))}),e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.minutesLabel")})]}),i.mode==="hourly"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.everyHourAt")}),e.jsx("select",{value:i.hourlyMinute,onChange:m=>x({hourlyMinute:parseInt(m.target.value)}),className:`${f} w-16`,children:Array.from({length:12},(m,j)=>j*5).map(m=>e.jsx("option",{value:m,children:String(m).padStart(2,"0")},m))}),e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.minutesPast")})]}),i.mode==="daily"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.everyDayAt")}),p(i.dailyHour,i.dailyMinute,m=>x({dailyHour:m}),m=>x({dailyMinute:m}))]}),i.mode==="weekly"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:xo.map(m=>e.jsx("button",{type:"button",onClick:()=>o(m.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${i.weeklyDays.includes(m.value)?"bg-accent text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-accent"}`,children:r(m.labelKey)},m.value))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.at")}),p(i.weeklyHour,i.weeklyMinute,m=>x({weeklyHour:m}),m=>x({weeklyMinute:m}))]})]}),i.mode==="monthly"&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.everyMonthOn")}),e.jsx("select",{value:i.monthlyDay,onChange:m=>x({monthlyDay:parseInt(m.target.value)}),className:`${f} w-16`,children:Array.from({length:28},(m,j)=>j+1).map(m=>e.jsx("option",{value:m,children:m},m))}),e.jsx("span",{className:"text-sm text-warm-600",children:r("cron.dayAt")}),p(i.monthlyHour,i.monthlyMinute,m=>x({monthlyHour:m}),m=>x({monthlyMinute:m}))]}),i.mode==="custom"&&e.jsxs("div",{children:[e.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:a,onChange:m=>c(m.target.value),className:"bg-warm-50 border border-warm-300 rounded-lg px-3 py-1.5 w-full text-sm text-warm-800 font-mono transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20"}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:r("schedule.cronHint")})]})]}),i.mode!=="custom"&&h&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsxs("span",{className:"text-warm-400",children:[r("cron.expression"),":"]}),e.jsx("code",{className:"px-2 py-0.5 rounded-md bg-warm-100 text-warm-600 font-mono",children:h})]})]})}function fo(){const t=new Date;t.setHours(t.getHours()+1),t.setMinutes(0,0,0);const n=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0"),l=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0");return`${n}-${r}-${i}T${l}:${a}`}function go(t){const n=new Date(t),r=n.getFullYear(),i=String(n.getMonth()+1).padStart(2,"0"),l=String(n.getDate()).padStart(2,"0"),a=String(n.getHours()).padStart(2,"0"),c=String(n.getMinutes()).padStart(2,"0");return`${r}-${i}-${l}T${a}:${c}`}function ya({onSave:t,onCancel:n,initialTitle:r="",initialDescription:i="",initialCronExpression:l="",initialCliTool:a,initialSkipIfRunning:c=!0,initialScheduleType:x="recurring",initialRunAt:o,projectCliTool:g="claude"}){const[f,p]=s.useState(r),[h,m]=s.useState(i),[j,D]=s.useState(l),[z,K]=s.useState(a||g||"claude"),[F,R]=s.useState(c),[S,H]=s.useState(x),[_,O]=s.useState(o?go(o):fo()),{t:X}=ye(),k=S==="once",se=f.trim()&&(k?!!_:!!j.trim()),G=b=>{b.preventDefault(),se&&t({title:f.trim(),description:h.trim(),cronExpression:k?"":j.trim(),cliTool:z,skipIfRunning:F,scheduleType:S,runAt:k?new Date(_).toISOString():void 0})};return e.jsxs("form",{onSubmit:G,className:"card p-5",children:[e.jsx("div",{className:"mb-3",children:e.jsx("input",{type:"text",placeholder:X("scheduleForm.titlePlaceholder"),value:f,onChange:b=>p(b.target.value),className:"input-field",autoFocus:!0})}),e.jsx("div",{className:"mb-3",children:e.jsx("textarea",{placeholder:X("scheduleForm.descPlaceholder"),value:h,onChange:b=>m(b.target.value),rows:3,className:"input-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"})}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("schedule.type")}),e.jsxs("div",{className:"inline-flex gap-1 rounded-lg bg-warm-100 p-1",children:[e.jsx("button",{type:"button",onClick:()=>H("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${S==="recurring"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:X("schedule.recurring")}),e.jsx("button",{type:"button",onClick:()=>H("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${S==="once"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:X("schedule.once")})]})]}),k?e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("schedule.runAtLabel")}),e.jsx("input",{type:"datetime-local",value:_,onChange:b=>O(b.target.value),className:"input-field text-sm font-mono",min:new Date().toISOString().slice(0,16)})]}):e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("schedule.cronExpression")}),e.jsx(po,{value:j,onChange:D})]}),e.jsx("div",{className:"mb-3 grid grid-cols-2 gap-3",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:X("scheduleForm.cliTool")}),e.jsx("select",{value:z,onChange:b=>K(b.target.value),className:"input-field text-sm !py-2",children:bt.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]})}),!k&&e.jsx("div",{className:"mb-4",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:F,onChange:b=>R(b.target.checked),className:"rounded-md border-warm-300 text-accent focus:ring-accent"}),X("schedule.skipIfRunning")]})}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx("button",{type:"button",onClick:n,className:"btn-ghost text-sm",children:X("scheduleForm.cancel")}),e.jsx("button",{type:"submit",disabled:!se,className:"btn-primary text-sm",children:X("scheduleForm.save")})]})]})}function bo({schedule:t,onToggle:n,onDelete:r,onEdit:i,onTrigger:l,onMergeRun:a,onCleanupRun:c}){const[x,o]=s.useState(!1),[g,f]=s.useState(!1),[p,h]=s.useState([]),[m,j]=s.useState(!1),[D,z]=s.useState(!1),[K,F]=s.useState(null),{t:R}=ye(),S=async()=>{try{const y=await ws(t.id);h(y)}catch{}},H=async y=>{if(!(!y.todo_id||!a)){F(y.id);try{await a(y.todo_id),await S()}finally{F(null)}}},_=async y=>{if(!(!y.todo_id||!c)){F(y.id);try{await c(y.todo_id),await S()}finally{F(null)}}},O=t.schedule_type==="once",X=async()=>{if(!m)try{const y=await ws(t.id);h(y),j(!0)}catch{}},k=()=>{const y=!x;o(y),y&&X()},se=async()=>{z(!0);try{await l(t.id);const y=await ws(t.id);h(y),j(!0)}finally{z(!1)}};if(g)return e.jsx(ya,{initialTitle:t.title,initialDescription:t.description??"",initialCronExpression:O?"":t.cron_expression,initialCliTool:t.cli_tool??void 0,initialSkipIfRunning:!!t.skip_if_running,initialScheduleType:t.schedule_type,initialRunAt:t.run_at??void 0,onSave:async y=>{await i(t.id,{title:y.title,description:y.description,cron_expression:y.cronExpression||void 0,cli_tool:y.cliTool,skip_if_running:y.skipIfRunning,schedule_type:y.scheduleType,run_at:y.runAt}),f(!1)},onCancel:()=>f(!1)});const G={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},b={triggered:R("schedule.runTriggered"),skipped:R("schedule.runSkipped"),completed:R("schedule.runCompleted"),failed:R("schedule.runFailed")},v=y=>y?new Date(y).toLocaleString():"";return e.jsxs("div",{className:"card overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:k,children:[e.jsx("button",{className:"mt-0.5 text-warm-400 hover:text-warm-600 flex-shrink-0 transition-colors",children:e.jsx(St,{size:14,className:`transition-transform duration-200 ${x?"rotate-90":""}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm text-warm-800 font-medium truncate",children:t.title}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-2xs text-warm-400",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[e.jsx(zt,{size:12}),O?v(t.run_at):t.cron_expression]}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:R(O?"schedule.once":"schedule.recurring")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warm-500",children:[e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${t.is_active?"bg-status-success":"bg-warm-400"}`}),t.is_active?R("schedule.active"):R("schedule.paused")]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:y=>y.stopPropagation(),children:[e.jsx("button",{onClick:se,disabled:D,className:"p-1.5 text-status-warning hover:text-status-warning hover:bg-status-warning/10 rounded-lg transition-colors disabled:opacity-30",title:R("schedule.trigger"),children:e.jsx(Rt,{size:14})}),e.jsx("button",{onClick:()=>n(t.id,!t.is_active),className:`p-1.5 rounded-lg transition-colors ${t.is_active?"text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10":"text-status-success/60 hover:text-status-success hover:bg-status-success/10"}`,title:t.is_active?R("schedule.pause"):R("schedule.activate"),children:t.is_active?e.jsx(da,{size:14}):e.jsx(cr,{size:14})}),e.jsx("button",{onClick:()=>f(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:R("schedule.edit"),children:e.jsx(Wt,{size:14})}),e.jsx("button",{onClick:()=>r(t.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:R("schedule.delete"),children:e.jsx(wt,{size:14})})]})]}),x&&e.jsxs("div",{className:"border-t border-warm-200 px-5 py-5 space-y-4 bg-warm-50/50",children:[t.description&&e.jsx("div",{children:e.jsx("p",{className:"text-sm text-warm-600 whitespace-pre-wrap leading-relaxed",children:t.description})}),e.jsxs("div",{className:"grid gap-x-8 gap-y-2 text-xs sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[e.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:R(O?"schedule.runAtLabel":"schedule.cronExpression")}),e.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:O?v(t.run_at):t.cron_expression})]}),e.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[e.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:R("schedule.lastRun")}),e.jsx("span",{className:"min-w-0 truncate text-warm-600",children:t.last_run_at?new Date(t.last_run_at).toLocaleString():R("schedule.never")})]}),!O&&t.skip_if_running&&e.jsxs("div",{className:"flex items-center gap-2 text-warm-500 sm:col-span-2",children:[e.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-warm-400"}),R("schedule.skipIfRunning")]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:R("schedule.runs")}),p.length===0?e.jsx("p",{className:"text-xs text-warm-400 italic",children:R("schedule.noRuns")}):e.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:p.map(y=>{const d=y.todo_id&&y.todo_status==="completed"&&!!y.todo_branch_name,C=y.todo_id&&y.todo_status!=="running"&&y.todo_status!=="pending"&&(y.todo_worktree_path||y.todo_branch_name),N=K===y.id;return e.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 font-medium text-warm-600",children:[e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${G[y.status]||"bg-warm-400"}`}),b[y.status]||y.status]}),y.skipped_reason&&e.jsxs("span",{className:"text-warm-400",children:["(",y.skipped_reason,")"]}),e.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[d&&a&&e.jsx("button",{onClick:()=>H(y),disabled:N,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded-md transition-colors disabled:opacity-30",title:R("todo.merge"),children:e.jsx(Fs,{size:12})}),C&&c&&e.jsx("button",{onClick:()=>_(y),disabled:N,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded-md transition-colors disabled:opacity-30",title:R("todo.cleanup"),children:e.jsx(wt,{size:12})})]}),e.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(y.started_at).toLocaleString()})]},y.id)})})]})]})]})}function vo({schedules:t,projectCliTool:n,onAddSchedule:r,onToggleSchedule:i,onDeleteSchedule:l,onEditSchedule:a,onTriggerSchedule:c,onMergeRun:x,onCleanupRun:o}){const[g,f]=s.useState(!1),[p,h]=s.useState(null),{t:m}=ye();return e.jsxs("div",{className:"min-h-[50vh]",onContextMenu:j=>{$t(j)||(j.preventDefault(),h({x:j.clientX,y:j.clientY}))},children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:m("schedules.title")}),!g&&e.jsxs("button",{onClick:()=>f(!0),className:"btn-primary btn-sm",children:[e.jsx(gt,{size:14}),m("schedules.add")]})]}),g&&e.jsx("div",{className:"mb-5",children:e.jsx(ya,{projectCliTool:n,onSave:async j=>{await r(j),f(!1)},onCancel:()=>f(!1)})}),e.jsx("div",{className:"space-y-3",children:t.length===0?e.jsx("div",{className:"card",children:e.jsx(At,{icon:Ol,title:m("schedules.empty"),description:m("schedules.emptyHint")})}):t.map((j,D)=>e.jsx("div",{children:e.jsx(bo,{schedule:j,onToggle:i,onDelete:l,onEdit:a,onTrigger:c,onMergeRun:x,onCleanupRun:o})},j.id))}),p&&e.jsx(yt,{x:p.x,y:p.y,onClose:()=>h(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>f(!0),children:[e.jsx(gt,{size:14}),m("schedules.add")]})})]})}const Nn="__custom__";function wo({open:t,onClose:n,projectId:r,projectName:i,onPushed:l}){const{t:a}=ye(),[c,x]=s.useState(!1),[o,g]=s.useState(!1),[f,p]=s.useState(null),[h,m]=s.useState([]),[j,D]=s.useState("origin"),[z,K]=s.useState([]),[F,R]=s.useState([]),[S,H]=s.useState(!0),[_,O]=s.useState(!1);s.useEffect(()=>{if(!t)return;let d=!1;return x(!0),p(null),Promise.all([dr(r),Ms(r)]).then(([C,N])=>{var ae,w;if(d)return;const L=C.remotes||[];m(L);const B=((ae=L.find(J=>J.name==="origin"))==null?void 0:ae.name)||((w=L[0])==null?void 0:w.name)||"origin";D(B);const Y=N.branches||[],le=Y.filter(J=>!J.remote),ue=`remotes/${B}/`,me=Y.filter(J=>J.remote&&J.name.startsWith(ue)).map(J=>J.name.slice(ue.length)).filter(J=>J&&J!=="HEAD");R(me);const pe=new Set(me);K(le.map(J=>{const M=pe.has(J.name);return{local:J.name,current:J.current,remote:J.name,customRemote:!1,setUpstream:!M,checked:J.current}}))}).catch(C=>{d||p(C instanceof Error?C.message:"Failed to load remotes")}).finally(()=>{d||x(!1)}),()=>{d=!0}},[t,r]),s.useEffect(()=>{if(!t||!j)return;let d=!1;return Ms(r).then(C=>{if(d)return;const N=`remotes/${j}/`,L=(C.branches||[]).filter(B=>B.remote&&B.name.startsWith(N)).map(B=>B.name.slice(N.length)).filter(B=>B&&B!=="HEAD");R(L)}).catch(()=>{}),()=>{d=!0}},[j,r,t]);const X=z.length>0&&z.every(d=>d.checked),k=z.some(d=>d.checked),se=z.filter(d=>d.checked).length,G=s.useMemo(()=>{var d;return((d=h.find(C=>C.name===j))==null?void 0:d.url)||""},[h,j]),b=(d,C)=>{K(N=>N.map(L=>L.local===d?{...L,...C}:L))},v=()=>{const d=!X;K(C=>C.map(N=>({...N,checked:d})))},y=async()=>{p(null);const d=z.filter(N=>N.checked);if(d.length===0){p(a("git.pushDialog.errorRequireBranch"));return}const C=d.map(N=>({local:N.local,remote:(N.remote||"").trim()||N.local,setUpstream:N.setUpstream}));g(!0);try{await Bs(r,{remote:j,branches:C,pushAllTags:S,force:_}),l==null||l(),n()}catch(N){p(N instanceof Error?N.message:"Push failed")}finally{g(!1)}};return e.jsx(vt,{open:t,onClose:o?()=>{}:n,size:"2xl",disableBackdropClose:!0,disableEscClose:o,children:e.jsxs("div",{className:"card p-5 space-y-4",children:[e.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",i]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:a("git.pushDialog.targetRemote")}),e.jsxs("select",{value:j,onChange:d=>D(d.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:c||o||h.length===0,children:[h.length===0&&e.jsx("option",{value:"origin",children:"origin"}),h.map(d=>e.jsx("option",{value:d.name,children:d.name},d.name))]}),e.jsx("input",{readOnly:!0,value:G,className:"input-field text-xs font-mono py-1.5 px-3 flex-1 cursor-default"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"section-label mb-2",children:a("git.pushDialog.branchesHeader")}),e.jsx("div",{className:"rounded-xl border border-theme-border-strong overflow-hidden",children:e.jsx("div",{className:"overflow-auto max-h-[50vh]",children:e.jsxs("table",{className:"w-full text-sm border-collapse",children:[e.jsx("thead",{className:"sticky top-0 bg-warm-100 z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-12",children:a("git.pushDialog.colPush")}),e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:a("git.pushDialog.colLocal")}),e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:a("git.pushDialog.colRemote")}),e.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-16",children:a("git.pushDialog.colTracking")})]})}),e.jsxs("tbody",{children:[c&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:a("git.pushDialog.loading")})}),!c&&z.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:a("git.pushDialog.noLocalBranches")})}),z.map(d=>e.jsxs("tr",{className:"border-t border-theme-border/50 hover:bg-theme-hover/40 transition-colors",children:[e.jsx("td",{className:"py-2 px-3",children:e.jsx("input",{type:"checkbox",checked:d.checked,onChange:C=>b(d.local,{checked:C.target.checked}),disabled:o,className:"cursor-pointer"})}),e.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[d.local,d.current&&e.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),e.jsx("td",{className:"py-2 px-3",children:d.customRemote?e.jsx("input",{type:"text",value:d.remote,onChange:C=>b(d.local,{remote:C.target.value}),placeholder:d.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:o}):e.jsxs("select",{value:F.includes(d.remote)||d.remote?d.remote:"",onChange:C=>{const N=C.target.value;N===Nn?b(d.local,{customRemote:!0}):b(d.local,{remote:N})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:o,children:[!F.includes(d.remote)&&d.remote&&e.jsxs("option",{value:d.remote,children:[d.remote," (",a("git.pushDialog.newBranch"),")"]}),F.map(C=>e.jsx("option",{value:C,children:C},C)),e.jsx("option",{value:Nn,children:a("git.pushDialog.customRemote")})]})}),e.jsx("td",{className:"py-2 px-3",children:e.jsx("input",{type:"checkbox",checked:d.setUpstream,onChange:C=>b(d.local,{setUpstream:C.target.checked}),disabled:o,className:"cursor-pointer"})})]},d.local))]})]})})})]}),e.jsxs("div",{className:"flex items-center gap-5 text-xs text-warm-700",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:X,ref:d=>{d&&(d.indeterminate=!X&&k)},onChange:v,disabled:o||z.length===0,className:"cursor-pointer"}),a("git.pushDialog.selectAll")]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:d=>H(d.target.checked),disabled:o,className:"cursor-pointer"}),a("git.pushDialog.allTags")]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:d=>O(d.target.checked),disabled:o,className:"cursor-pointer"}),e.jsx("span",{title:a("git.pushDialog.forceHint"),children:a("git.pushDialog.force")})]})]}),f&&e.jsx("div",{className:"text-xs text-status-error font-medium",children:f}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:n,disabled:o,className:"btn-secondary btn-md",children:a("git.pushDialog.cancel")}),e.jsx("button",{type:"button",onClick:y,disabled:o||c||se===0,className:"btn-primary btn-md",children:a(o?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function yo(t){const n=t.split(`
|
|
164
164
|
`),r=[];let i=[];const l=()=>{i.length&&(r.push({kind:"text",lines:i}),i=[])};let a=0;for(;a<n.length;){const c=n[a];if(c.startsWith("<<<<<<<")){l();const x=c.slice(7).trim()||"HEAD";a++;const o=[];for(;a<n.length&&!n[a].startsWith("|||||||")&&!n[a].startsWith("=======");)o.push(n[a]),a++;if(a<n.length&&n[a].startsWith("|||||||"))for(a++;a<n.length&&!n[a].startsWith("=======");)a++;a<n.length&&n[a].startsWith("=======")&&a++;const g=[];for(;a<n.length&&!n[a].startsWith(">>>>>>>");)g.push(n[a]),a++;a<n.length&&n[a].startsWith(">>>>>>>")&&a++,r.push({kind:"conflict",ours:o,theirs:g,label:x})}else i.push(c),a++}return l(),r}function jo(t,n){const r=[];return t.forEach((i,l)=>{if(i.kind==="text"){r.push(...i.lines);return}const a=n[l];a==="ours"?r.push(...i.ours):a==="theirs"?r.push(...i.theirs):a==="both"?r.push(...i.ours,...i.theirs):r.push(`<<<<<<< ${i.label}`,...i.ours,"=======",...i.theirs,">>>>>>> incoming")}),r.join(`
|
|
165
165
|
`)}const No=/^(<{7}|>{7})/m;function ys({lines:t,tint:n}){return e.jsx("pre",{className:`px-3 py-1.5 font-mono text-xs leading-relaxed overflow-x-auto ${n}`,children:t.length?t.map((r,i)=>e.jsx("div",{children:r||" "},i)):e.jsx("div",{className:"italic opacity-50",children:"∅"})})}function ko({projectId:t,worktreePath:n,filePath:r,onResolved:i,onError:l}){const{t:a}=ye(),[c,x]=s.useState(null),[o,g]=s.useState({}),[f,p]=s.useState(!1),[h,m]=s.useState(""),[j,D]=s.useState(!0),[z,K]=s.useState(!1),[F,R]=s.useState(!1);s.useEffect(()=>{let y=!1;return D(!0),p(!1),g({}),R(!1),ur(t,r,n).then(d=>{y||x(yo(d.content))}).catch(()=>{y||R(!0)}).finally(()=>{y||D(!1)}),()=>{y=!0}},[t,n,r]);const S=s.useMemo(()=>c?c.map((y,d)=>y.kind==="conflict"?d:-1).filter(y=>y>=0):[],[c]),H=S.filter(y=>o[y]).length,_=S.length-H,O=s.useMemo(()=>c?jo(c,o):"",[c,o]),X=f?h:O,k=No.test(X),se=z||k||!f&&_>0,G=(y,d)=>g(C=>({...C,[y]:d})),b=()=>{m(O),p(!0)},v=async()=>{K(!0),l(null);try{await mr(t,r,X,n),i()}catch(y){l(y instanceof Error?y.message:"Failed to save resolution")}finally{K(!1)}};return e.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A] text-gray-200",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-gray-100 truncate flex-1",title:r,children:r}),!j&&!F&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`text-2xs ${_>0?"text-amber-400":"text-emerald-400"}`,children:_>0?a("git.cr.unresolved").replace("{n}",String(_)):a("git.cr.allResolved")}),e.jsx("button",{className:"text-2xs px-2 py-0.5 rounded-md border border-gray-600 text-gray-300 hover:bg-gray-800",onClick:()=>f?p(!1):b(),children:a(f?"git.cr.guided":"git.cr.manual")}),e.jsx("button",{className:"text-2xs px-2 py-0.5 rounded-md bg-accent text-white disabled:opacity-40",disabled:se,onClick:v,title:k?a("git.cr.markersRemain"):void 0,children:z?"…":a("git.cr.save")})]})]}),j?e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-gray-400",children:a("git.loadingDiff")}):F?e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-status-error",children:a("git.cr.loadFailed")}):f?e.jsx("textarea",{className:"flex-1 w-full bg-[#1A1A1A] text-gray-100 font-mono text-xs p-3 resize-none focus:outline-none",value:h,onChange:y=>m(y.target.value),spellCheck:!1}):S.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-gray-400",children:a("git.cr.noConflicts")}):e.jsx("div",{className:"flex-1 overflow-auto",children:c.map((y,d)=>y.kind==="text"?e.jsx(ys,{lines:y.lines,tint:"text-gray-500"},d):e.jsxs("div",{className:"my-1 border-y border-gray-700",children:[e.jsx("div",{className:"flex items-center gap-1 px-3 py-1 bg-gray-800/60",children:["ours","theirs","both"].map(C=>e.jsx("button",{onClick:()=>G(d,C),className:`text-2xs px-2 py-0.5 rounded-md border transition-colors ${o[d]===C?"bg-accent text-white border-accent":"border-gray-600 text-gray-300 hover:bg-gray-700"}`,children:a(C==="ours"?"git.acceptOurs":C==="theirs"?"git.acceptTheirs":"git.cr.both")},C))}),e.jsxs("div",{className:o[d]==="theirs"?"opacity-40":"",children:[e.jsx("div",{className:"px-3 pt-1 text-2xs text-emerald-400",children:a("git.cr.ours")}),e.jsx(ys,{lines:y.ours,tint:"text-gray-100 bg-emerald-500/10"})]}),e.jsxs("div",{className:o[d]==="ours"?"opacity-40":"",children:[e.jsx("div",{className:"px-3 pt-1 text-2xs text-sky-400",children:a("git.cr.theirs")}),e.jsx(ys,{lines:y.theirs,tint:"text-gray-100 bg-sky-500/10"})]})]},d))})]})}const Ft=["#B08A3E","#4B8DFF","#7A8797","#5E748A","#8B8178","#667085","#78909C","#9A8F7F"];function Co(t){const n=new Map;t.forEach((l,a)=>n.set(l.hash,a));const r=[],i=[];for(let l=0;l<t.length;l++){const a=t[l];let c=r.indexOf(a.hash);c===-1&&(c=r.indexOf(null),c===-1&&(c=r.length,r.push(null))),r[c]=null;const x=Ft[c%Ft.length],o=[];for(let g=0;g<a.parentHashes.length;g++){const f=a.parentHashes[g],p=n.get(f);if(p===void 0)continue;let h=r.indexOf(f);if(h!==-1)o.push({fromLane:c,toLane:h,toRow:p,color:Ft[h%Ft.length]});else if(g===0)r[c]=f,o.push({fromLane:c,toLane:c,toRow:p,color:x});else{let m=r.indexOf(null);m===-1&&(m=r.length,r.push(null)),r[m]=f,o.push({fromLane:c,toLane:m,toRow:p,color:Ft[m%Ft.length]})}}i.push({lane:c,color:x,connections:o})}return i}function So({refStr:t}){const n=t.startsWith("HEAD"),r=t.startsWith("origin/")||t.includes("remotes/"),i=t.startsWith("tag: ");let l=t,a="";return i?(l=t.replace("tag: ",""),a="bg-status-merged/10 text-status-merged"):n?(l=t.replace("HEAD -> ",""),a="bg-status-success/10 text-status-success font-semibold"):r?a="bg-status-running/10 text-status-running":a="bg-status-warning/10 text-status-warning",e.jsx("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${a}`,children:l})}const Ct=32,Mt=16,_o=4,Mo=10;function Do({graphNodes:t,totalRows:n}){const i=(Math.min(Mo,t.reduce((l,a)=>{const c=a.connections.reduce((x,o)=>Math.max(x,o.fromLane,o.toLane),0);return Math.max(l,a.lane,c)},0)+1)+1)*Mt+8;return e.jsxs("svg",{width:i,height:n*Ct,className:"shrink-0",style:{minWidth:i},children:[t.map((l,a)=>l.connections.map((c,x)=>{const o=c.fromLane*Mt+Mt/2+4,g=a*Ct+Ct/2,f=c.toLane*Mt+Mt/2+4,p=c.toRow*Ct+Ct/2;if(o===f)return e.jsx("line",{x1:o,y1:g,x2:f,y2:p,stroke:c.color,strokeWidth:2,strokeOpacity:.7},`${a}-${x}`);{const h=(g+p)/2;return e.jsx("path",{d:`M${o},${g} C${o},${h} ${f},${h} ${f},${p}`,fill:"none",stroke:c.color,strokeWidth:2,strokeOpacity:.7},`${a}-${x}`)}})),t.map((l,a)=>{const c=l.lane*Mt+Mt/2+4,x=a*Ct+Ct/2;return e.jsx("circle",{cx:c,cy:x,r:_o,fill:l.color,stroke:"white",strokeWidth:1.5},`dot-${a}`)})]})}function Eo({projectId:t,projectName:n,onRefresh:r,busy:i,setBusy:l,branches:a,statusFiles:c,worktreePath:x}){const{t:o}=ye(),{confirm:g}=_t(),[f,p]=s.useState(null),[h,m]=s.useState(""),[j,D]=s.useState(""),[z,K]=s.useState(null),F=()=>{p(null),m(""),D(""),K(null)},R=async b=>{l(!0),K(null);try{await b(),F(),r()}catch(v){K(v instanceof Error?v.message:"Error")}finally{l(!1)}},S=c.some(b=>b.index!==" "&&b.index!=="?"),H=({label:b,onClick:v,icon:y,badge:d})=>e.jsxs("button",{onClick:v,disabled:i,className:"flex flex-col items-center gap-0.5 px-2.5 py-1.5 rounded-md hover:bg-warm-50 transition-colors disabled:opacity-50 relative",title:b,children:[e.jsx("div",{className:"h-5 w-5 flex items-center justify-center text-warm-500",children:y}),e.jsx("span",{className:"text-2xs text-warm-600 whitespace-nowrap",children:b}),d!==void 0&&d>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 bg-accent text-white text-[9px] font-bold rounded-full h-3.5 min-w-[14px] flex items-center justify-center px-0.5",children:d})]}),_=({title:b,children:v})=>e.jsx(vt,{open:!0,onClose:F,size:"sm",children:e.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated w-80 max-w-[90vw]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:[e.jsx("span",{className:"text-sm font-semibold text-warm-700",children:b}),e.jsx("button",{onClick:F,className:"text-warm-400 hover:text-warm-600",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[z&&e.jsx("p",{className:"text-status-error text-xs",children:z}),v]})]})}),O=a.filter(b=>!b.remote),X=a.find(b=>!b.remote&&b.current),k=c.length,se=(X==null?void 0:X.behind)??0,G=(X==null?void 0:X.ahead)??0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1 border-b border-warm-100 overflow-x-auto",children:[e.jsx(H,{label:o("git.commit"),onClick:()=>p("commit"),icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v6m3-3H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z"})}),badge:k}),e.jsx(H,{label:o("git.pull"),onClick:()=>R(()=>Qn(t)),icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3"})}),badge:se}),e.jsx(H,{label:o("git.push"),onClick:()=>p("push"),icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5"})}),badge:G}),e.jsx(H,{label:o("git.fetch"),onClick:()=>R(()=>ea(t)),icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7.5 7.5h-.75A2.25 2.25 0 004.5 9.75v7.5a2.25 2.25 0 002.25 2.25h7.5a2.25 2.25 0 002.25-2.25v-7.5a2.25 2.25 0 00-2.25-2.25h-.75m-6 3.75l3 3m0 0l3-3m-3 3V1.5"})})}),e.jsx("div",{className:"w-px h-8 bg-warm-200 mx-1"}),e.jsx(H,{label:o("git.branch"),onClick:()=>p("branch"),icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 3v12m0 0a3 3 0 103 3H15a3 3 0 100-3m-9 0h9m-9 0a3 3 0 01-3-3V6a3 3 0 013-3h0"})})}),e.jsx(H,{label:o("git.merge"),onClick:()=>p("merge"),icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7.5 21L3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5"})})}),e.jsx(H,{label:o("git.stash"),onClick:()=>p("stash"),icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z"})})}),e.jsx(H,{label:o("git.discard"),onClick:async()=>{c.length!==0&&await g({message:o("git.confirmDiscard"),danger:!0})&&R(()=>Cr(t,void 0,!0,x))},icon:e.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182"})})}),e.jsx(H,{label:o("git.tag"),onClick:()=>p("tag"),icon:e.jsxs("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.568 3H5.25A2.25 2.25 0 003 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 005.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 009.568 3z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]})})]}),e.jsx(wo,{open:f==="push",onClose:F,projectId:t,projectName:n,onPushed:r}),f==="commit"&&e.jsxs(_,{title:o("git.commit"),children:[e.jsx("textarea",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm resize-none focus:outline-none focus:ring-1 focus:ring-accent",rows:3,placeholder:o("git.commitMessage"),value:h,onChange:b=>m(b.target.value),autoFocus:!0}),e.jsxs("button",{className:"w-full btn-primary text-sm py-2",disabled:i||!h.trim()||!S,onClick:()=>R(()=>Zn(t,h.trim(),x)),children:[o("git.commit")," ",!S&&e.jsxs("span",{className:"text-xs opacity-70 ml-1",children:["(",o("git.staged"),": 0)"]})]})]}),f==="branch"&&e.jsxs(_,{title:o("git.newBranch"),children:[e.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:o("git.branchName"),value:h,onChange:b=>m(b.target.value),autoFocus:!0}),e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{className:"flex-1 btn-primary text-sm py-2",disabled:i||!h.trim(),onClick:()=>R(()=>qn(t,h.trim())),children:o("git.create")})}),O.length>0&&e.jsxs("div",{className:"border-t border-warm-100 pt-2 mt-1",children:[e.jsx("p",{className:"text-2xs text-warm-400 uppercase tracking-wider mb-1",children:o("git.selectBranch")}),e.jsx("div",{className:"max-h-32 overflow-y-auto space-y-px",children:O.filter(b=>!b.current).map(b=>e.jsxs("div",{className:"flex items-center justify-between px-2 py-1 text-xs hover:bg-warm-50 rounded-md group",children:[e.jsx("button",{className:"truncate text-warm-600 hover:text-accent",onClick:()=>R(()=>Es(t,b.name)),children:b.name}),e.jsx("button",{className:"text-warm-300 hover:text-status-error opacity-0 group-hover:opacity-100 transition-opacity text-2xs",onClick:async()=>{await g({message:o("git.confirmDelete").replace("{name}",b.name),danger:!0})&&R(()=>Ts(t,b.name))},children:o("git.delete")})]},b.name))})]})]}),f==="merge"&&e.jsxs(_,{title:o("git.merge"),children:[e.jsx("p",{className:"text-xs text-warm-500",children:o("git.selectBranch")}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-px",children:O.filter(b=>!b.current).map(b=>e.jsx("button",{className:"w-full text-left px-3 py-2 text-sm hover:bg-warm-50 rounded-md text-warm-600 truncate",disabled:i,onClick:()=>R(()=>ta(t,b.name)),children:b.name},b.name))})]}),f==="stash"&&e.jsx(To,{projectId:t,busy:i,exec:R,inputValue:h,setInputValue:m}),f==="tag"&&e.jsxs(_,{title:o("git.tag"),children:[e.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:o("git.tagName"),value:h,onChange:b=>m(b.target.value),autoFocus:!0}),e.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:o("git.tagMessage"),value:j,onChange:b=>D(b.target.value)}),e.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:i||!h.trim(),onClick:()=>R(()=>Xn(t,h.trim(),j.trim()||void 0)),children:o("git.create")})]})]})}function To({projectId:t,busy:n,exec:r,inputValue:i,setInputValue:l}){const{t:a}=ye(),[c,x]=s.useState([]);return s.useEffect(()=>{jr(t).then(x).catch(()=>{})},[t]),e.jsx(vt,{open:!0,onClose:()=>l(""),size:"sm",children:e.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated w-80 max-w-[90vw]",children:[e.jsx("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:e.jsx("span",{className:"text-sm font-semibold text-warm-700",children:a("git.stash")})}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:"flex-1 border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:a("git.stashMessage"),value:i,onChange:o=>l(o.target.value),autoFocus:!0}),e.jsx("button",{className:"btn-primary text-sm px-3 py-2",disabled:n,onClick:()=>r(()=>Nr(t,i.trim()||void 0)),children:a("git.stash")})]}),c.length>0?e.jsx("div",{className:"space-y-px max-h-40 overflow-y-auto",children:c.map(o=>e.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 text-xs hover:bg-warm-50 rounded-md",children:[e.jsx("span",{className:"text-warm-600 truncate flex-1",children:o.message||`stash@{${o.index}}`}),e.jsx("button",{className:"text-accent hover:underline text-[11px] ml-2 shrink-0",disabled:n,onClick:()=>r(()=>kr(t,o.index)),children:a("git.stashPop")})]},o.index))}):e.jsx("p",{className:"text-xs text-warm-400 text-center",children:a("git.noStashes")})]})]})})}function kn(t,n){if(t==="?"&&n==="?")return{label:"U",color:"text-warm-400",type:"untracked"};const i=t!==" "&&t!=="?",l=i?t:n;let a="text-accent",c=l;return l==="A"?a="text-status-success":l==="D"?a="text-status-error":l==="R"?a="text-status-merged":l==="C"?a="text-accent":(a="text-accent",c="M"),{label:c,color:a,type:i?"staged":"unstaged"}}function Cn({file:t,pane:n,selected:r,checked:i,onClick:l,onToggleCheck:a,onContextMenu:c}){const x=n==="staged"?kn(t.index," "):kn(" ",t.working_dir==="?"?"?":t.working_dir),o=n==="unstaged"&&t.index==="?"&&t.working_dir==="?"?{label:"U",color:"text-warm-400"}:x;return e.jsxs("div",{onClick:l,onContextMenu:c,className:`flex items-center gap-2 px-3 py-1 cursor-pointer text-xs select-none transition-colors ${r?"bg-accent/15 text-accent":"hover:bg-warm-50 text-warm-700"}`,children:[e.jsx("input",{type:"checkbox",checked:i,onChange:a,onClick:g=>g.stopPropagation(),className:"h-3 w-3 shrink-0 cursor-pointer","aria-label":t.path}),e.jsx("span",{className:`shrink-0 w-4 h-4 flex items-center justify-center rounded-md text-[10px] font-mono font-bold ${n==="staged"?"bg-status-success/15":"bg-warm-200"} ${o.color}`,children:n==="staged"||o.label==="U"?"+":"−"}),e.jsx("span",{className:"truncate flex-1",title:t.path,children:t.path})]})}function Ro({diff:t,loading:n,file:r}){const{t:i}=ye();if(!r)return e.jsx("div",{className:"h-full flex items-center justify-center bg-[#1A1A1A] text-gray-400",children:e.jsx("span",{className:"text-sm",children:i("git.selectFileForDiff")})});if(n)return e.jsx("div",{className:"h-full flex items-center justify-center bg-[#1A1A1A] text-gray-400",children:e.jsx("span",{className:"text-xs",children:i("git.loadingDiff")})});const l=r.index==="?"&&r.working_dir==="?";return e.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:r.path,children:r.path}),l&&e.jsx("span",{className:"text-2xs text-gray-400 italic",children:i("git.untrackedNewFile")})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:t?e.jsx("pre",{className:"p-3 font-mono text-xs leading-relaxed",children:t.split(`
|
|
166
166
|
`).map((a,c)=>{let x="text-gray-200";return a.startsWith("+")&&!a.startsWith("+++")?x="text-gray-100 bg-green-500/20":a.startsWith("-")&&!a.startsWith("---")?x="text-gray-100 bg-red-500/20":a.startsWith("@@")?x="text-blue-400":a.startsWith("diff ")&&(x="text-amber-300 font-bold"),e.jsx("div",{className:x,children:a||" "},c)})}):e.jsx("div",{className:"p-6 text-center text-xs text-gray-400 italic",children:i(l?"git.untrackedNewFile":"git.noFilesChanged")})})]})}function $o({projectId:t,worktreePath:n,branchName:r,files:i,conflicted:l,busy:a,setBusy:c,onRefresh:x,onError:o,isMobile:g=!1}){const{t:f}=ye(),p=s.useMemo(()=>new Set(l),[l]),h=s.useMemo(()=>i.filter(M=>p.has(M.path)),[i,p]),m=s.useMemo(()=>i.filter(M=>M.index!==" "&&M.index!=="?"&&!p.has(M.path)),[i,p]),j=s.useMemo(()=>i.filter(M=>M.working_dir!==" "&&M.working_dir!=="?"||M.index==="?"&&M.working_dir==="?").filter(M=>!(M.index!==" "&&M.index!=="?"&&M.working_dir===" ")).filter(M=>!p.has(M.path)),[i,p]),[D,z]=s.useState(null),[K,F]=s.useState(()=>new Set),[R,S]=s.useState(()=>new Set),[H,_]=s.useState(""),[O,X]=s.useState(!1),[k,se]=s.useState(""),[G,b]=s.useState(!1),[v,y]=s.useState(!1);s.useEffect(()=>{F(M=>{const te=new Set(m.map(I=>I.path));let re=!1;const we=new Set;return M.forEach(I=>{te.has(I)?we.add(I):re=!0}),re?we:M})},[m]),s.useEffect(()=>{S(M=>{const te=new Set(j.map(I=>I.path));let re=!1;const we=new Set;return M.forEach(I=>{te.has(I)?we.add(I):re=!0}),re?we:M})},[j]);const d=s.useCallback(M=>{F(te=>{const re=new Set(te);return re.has(M)?re.delete(M):re.add(M),re})},[]),C=s.useCallback(M=>{S(te=>{const re=new Set(te);return re.has(M)?re.delete(M):re.add(M),re})},[]),N=s.useRef(null),[L,B]=s.useState(()=>{if(typeof window>"u")return .55;const M=window.localStorage.getItem("clitrigger:git:working-pct"),te=M?parseFloat(M):NaN;return isNaN(te)?.55:Math.max(.3,Math.min(.8,te))});s.useEffect(()=>{localStorage.setItem("clitrigger:git:working-pct",String(L))},[L]);const Y=s.useCallback(M=>{if(!N.current)return;const te=N.current.getBoundingClientRect(),re=(M-te.left)/te.width;B(Math.max(.3,Math.min(.8,re)))},[]),le=s.useMemo(()=>{if(!D)return null;const[M,te]=D.split("::");return M==="conflict"?h.find(re=>re.path===te)||null:M==="staged"?m.find(re=>re.path===te)||null:j.find(re=>re.path===te)||null},[D,h,m,j]),ue=D?D.split("::")[0]:null;s.useEffect(()=>{D||(h.length>0?z(`conflict::${h[0].path}`):m.length>0?z(`staged::${m[0].path}`):j.length>0&&z(`unstaged::${j[0].path}`))},[D,h,m,j]),s.useEffect(()=>{if(!D)return;const[M,te]=D.split("::");(M==="conflict"?h:M==="staged"?m:j).some(we=>we.path===te)||z(null)},[D,h,m,j]),s.useEffect(()=>{if(!le||!ue){_("");return}let M=!1;return X(!0),yr(t,le.path,ue==="staged",n).then(te=>{M||_(te.diff)}).catch(()=>{M||_("")}).finally(()=>{M||X(!1)}),()=>{M=!0}},[t,n,le,ue]);const me=async M=>{c(!0),o(null);try{await M(),x()}catch(te){o(te instanceof Error?te.message:"Operation failed")}finally{c(!1)}},[pe,ae]=s.useState(null),w=(M,te)=>{M.preventDefault(),!g&&ae({file:te,x:M.clientX,y:M.clientY})},J=async()=>{if(!(!k.trim()||m.length===0)){y(!0),c(!0),o(null);try{if(await Zn(t,k.trim(),n),G)try{await Bs(t,n?{worktreePath:n}:void 0)}catch(M){o(M instanceof Error?`Commit OK, push failed: ${M.message}`:"Push failed")}se(""),x()}catch(M){o(M instanceof Error?M.message:"Commit failed")}finally{y(!1),c(!1)}}};return i.length===0?e.jsx("div",{className:"h-full flex items-center justify-center bg-theme-bg",children:e.jsx("span",{className:"text-sm text-warm-400",children:f("git.workingTreeClean")})}):e.jsxs("div",{ref:N,className:`h-full flex min-h-0 ${g?"flex-col":""}`,children:[e.jsxs("div",{style:g?void 0:{width:`${L*100}%`,minWidth:360},className:`shrink-0 flex flex-col min-h-0 ${g?"h-1/2":""}`,children:[h.length>0&&e.jsxs("div",{className:"flex flex-col min-h-0 border-b border-warm-200",style:{flex:"1 1 0"},children:[e.jsx("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center shrink-0 bg-status-error/10",children:e.jsxs("span",{className:"text-xs font-semibold text-status-error",children:[f("git.conflicts")," ",e.jsxs("span",{className:"text-warm-400 font-normal",children:["(",h.length,")"]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:h.map(M=>e.jsxs("div",{onClick:()=>z(`conflict::${M.path}`),className:`flex items-center gap-2 px-3 py-1 cursor-pointer text-xs select-none transition-colors ${D===`conflict::${M.path}`?"bg-accent/15 text-accent":"hover:bg-warm-50 text-warm-700"}`,children:[e.jsx("span",{className:"shrink-0 w-4 h-4 flex items-center justify-center rounded-md text-[10px] font-mono font-bold bg-status-error/15 text-status-error",children:"C"}),e.jsx("span",{className:"truncate flex-1",title:M.path,children:M.path}),e.jsx("button",{className:"shrink-0 text-2xs px-1.5 py-0.5 rounded-md border border-warm-300 text-warm-600 hover:bg-warm-100 disabled:opacity-40",disabled:a,onClick:te=>{te.stopPropagation(),me(()=>nn(t,M.path,"ours",n))},children:f("git.acceptOurs")}),e.jsx("button",{className:"shrink-0 text-2xs px-1.5 py-0.5 rounded-md border border-warm-300 text-warm-600 hover:bg-warm-100 disabled:opacity-40",disabled:a,onClick:te=>{te.stopPropagation(),me(()=>nn(t,M.path,"theirs",n))},children:f("git.acceptTheirs")})]},`c-${M.path}`))})]}),e.jsxs("div",{className:"flex flex-col min-h-0",style:{flex:"1 1 0"},children:[e.jsxs("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center justify-between shrink-0 bg-warm-50",children:[e.jsxs("span",{className:"text-xs font-semibold text-warm-700",children:[f("git.stagedFiles")," ",e.jsxs("span",{className:"text-warm-400 font-normal",children:["(",m.length,")"]})]}),e.jsx("button",{className:"text-2xs text-warm-500 hover:text-warm-700 disabled:opacity-40",disabled:a||m.length===0,onClick:()=>{const M=K.size>0?m.filter(te=>K.has(te.path)).map(te=>te.path):m.map(te=>te.path);M.length!==0&&me(()=>Sr(t,M,n))},children:K.size>0?`${f("git.unstageSelectedShort")} (${K.size})`:f("git.unstageAllShort")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:m.length===0?e.jsx("div",{className:"p-3 text-2xs text-warm-400 italic",children:"—"}):m.map(M=>e.jsx(Cn,{file:M,pane:"staged",selected:D===`staged::${M.path}`,checked:K.has(M.path),onClick:()=>z(`staged::${M.path}`),onToggleCheck:()=>d(M.path),onContextMenu:te=>w(te,M)},`s-${M.path}`))})]}),e.jsxs("div",{className:"flex flex-col min-h-0 border-t border-warm-200",style:{flex:"1 1 0"},children:[e.jsxs("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center justify-between shrink-0 bg-warm-50",children:[e.jsxs("span",{className:"text-xs font-semibold text-warm-700",children:[f("git.unstagedFiles")," ",e.jsxs("span",{className:"text-warm-400 font-normal",children:["(",j.length,")"]})]}),e.jsx("button",{className:"text-2xs text-warm-500 hover:text-warm-700 disabled:opacity-40",disabled:a||j.length===0,onClick:()=>{const M=R.size>0?j.filter(te=>R.has(te.path)).map(te=>te.path):j.map(te=>te.path);M.length!==0&&me(()=>_r(t,M,n))},children:R.size>0?`${f("git.stageSelectedShort")} (${R.size})`:f("git.stageAllShort")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j.length===0?e.jsx("div",{className:"p-3 text-2xs text-warm-400 italic",children:"—"}):j.map(M=>e.jsx(Cn,{file:M,pane:"unstaged",selected:D===`unstaged::${M.path}`,checked:R.has(M.path),onClick:()=>z(`unstaged::${M.path}`),onToggleCheck:()=>C(M.path),onContextMenu:te=>w(te,M)},`u-${M.path}`))})]}),e.jsxs("div",{className:"border-t border-warm-200 shrink-0 bg-theme-bg",children:[e.jsx("div",{className:"p-2",children:e.jsx("textarea",{className:"w-full px-3 py-2 text-sm rounded-md border resize-none focus:outline-none focus:ring-1 focus:ring-accent placeholder:text-warm-400",style:{backgroundColor:"var(--color-bg-card)",borderColor:"var(--color-border)",color:"var(--color-text-primary)"},rows:3,placeholder:f("git.commitMessage"),value:k,onChange:M=>se(M.target.value),onKeyDown:M=>{(M.metaKey||M.ctrlKey)&&M.key==="Enter"&&J()},disabled:v})}),e.jsxs("div",{className:"px-3 py-2 border-t border-warm-200 flex items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-2xs text-warm-600 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:G,onChange:M=>b(M.target.checked),className:"h-3 w-3",disabled:v}),f("git.pushImmediately").replace("{remote}",`origin/${r||"main"}`)]}),e.jsx("button",{className:"ml-auto btn-primary text-xs px-3 py-1.5 disabled:opacity-50",onClick:J,disabled:v||a||!k.trim()||m.length===0||h.length>0,children:v?"...":f("git.commitButton")})]})]})]}),!g&&e.jsx(ns,{axis:"x",onResize:Y}),e.jsx("div",{className:`flex-1 ${g?"min-h-0 border-t border-warm-200":"min-w-0"}`,children:ue==="conflict"&&le?e.jsx(ko,{projectId:t,worktreePath:n,filePath:le.path,onResolved:x,onError:o}):e.jsx(Ro,{diff:H,loading:O,file:le})}),pe&&e.jsx(yt,{x:pe.x,y:pe.y,onClose:()=>ae(null),children:e.jsx("button",{className:Be,disabled:a,onClick:()=>me(()=>Mr(t,pe.file.path,n)),children:f("git.addToGitignore")})})]})}function Lo({branches:t,tags:n,stashCount:r,projectId:i,busy:l,setBusy:a,onRefresh:c,onError:x}){const{t:o}=ye(),{confirm:g}=_t(),[f,p]=s.useState(new Set(["local","remote"])),[h,m]=s.useState(null),[j,D]=s.useState(null),[z,K]=s.useState(""),F=s.useRef(null),[R,S]=s.useState([]),[H,_]=s.useState(null);s.useEffect(()=>{Ds(i).then(d=>S(d.worktrees)).catch(()=>{})},[i]);const O=s.useCallback(()=>{Ds(i).then(d=>S(d.worktrees)).catch(()=>{})},[i]);s.useEffect(()=>{O()},[t,O]),s.useEffect(()=>{if(!h)return;const d=N=>{F.current&&!F.current.contains(N.target)&&m(null)},C=()=>m(null);return document.addEventListener("mousedown",d),document.addEventListener("scroll",C,!0),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("scroll",C,!0)}},[h]),s.useEffect(()=>{if(!h||!F.current)return;const d=F.current.getBoundingClientRect();let{x:C,y:N}=h;C+d.width>window.innerWidth&&(C=window.innerWidth-d.width-8),N+d.height>window.innerHeight&&(N=window.innerHeight-d.height-8),(C!==h.x||N!==h.y)&&m({...h,x:C,y:N})},[h]);const X=async(d,C)=>{a(!0),x(null),m(null);try{await d(),c(),C&&C()}catch(N){x(N instanceof Error?N.message:"Error")}finally{a(!1)}},k=(d,C,N,L)=>{d.preventDefault(),d.stopPropagation(),m({branch:C,isRemote:N,isCurrent:L,x:d.clientX,y:d.clientY})},se=d=>{p(C=>{const N=new Set(C);return N.has(d)?N.delete(d):N.add(d),N})},G=t.filter(d=>!d.remote),b=t.filter(d=>d.remote),v=({id:d,label:C,count:N})=>e.jsxs("button",{onClick:()=>se(d),className:"w-full flex items-center gap-1.5 py-1.5 text-[11px] font-semibold text-warm-500 uppercase tracking-wider hover:text-warm-700 transition-colors",children:[e.jsx("svg",{className:`h-3 w-3 transition-transform ${f.has(d)?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),C,e.jsx("span",{className:"text-warm-400 font-normal ml-auto",children:N})]}),y=({label:d,onClick:C,danger:N})=>e.jsx("button",{className:`w-full text-left px-3 py-1.5 hover:bg-theme-hover transition-colors ${N?"text-status-error":"text-theme-text"}`,disabled:l,onClick:C,children:d});return e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{id:"local",label:o("git.branches"),count:G.length}),f.has("local")&&e.jsx("div",{className:"pl-1 space-y-px",children:G.map(d=>e.jsxs("div",{className:`flex items-center gap-1.5 px-2 py-1 rounded-md text-xs truncate cursor-context-menu select-none ${d.current?"text-status-running font-semibold bg-status-running/10":"text-warm-600 hover:bg-warm-50"}`,onContextMenu:C=>k(C,d.name,!1,!!d.current),children:[d.current&&e.jsx("svg",{className:"h-3 w-3 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})}),e.jsx("span",{className:"truncate",children:d.name}),(!!d.ahead||!!d.behind)&&e.jsxs("span",{className:"ml-auto shrink-0 flex items-center gap-1 px-1.5 rounded-full border border-warm-300 dark:border-warm-600 text-[10px] font-semibold leading-tight",children:[!!d.ahead&&e.jsxs("span",{className:"text-status-success",title:`${d.ahead} ${o("git.ahead")}`,children:[d.ahead,"↑"]}),!!d.behind&&e.jsxs("span",{className:"text-status-warning",title:`${d.behind} ${o("git.behind")}`,children:[d.behind,"↓"]})]})]},d.name))}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(v,{id:"remote",label:o("git.remotes"),count:b.length}),f.has("remote")&&e.jsx("div",{className:"pl-1 space-y-px",children:b.map(d=>e.jsx("div",{className:"px-2 py-1 text-xs text-warm-500 truncate hover:bg-warm-50 rounded-md cursor-context-menu select-none",onContextMenu:C=>k(C,d.name,!0,!1),children:d.name.replace("remotes/","")},d.name))})]}),n.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(v,{id:"tags",label:o("git.tags"),count:n.length}),f.has("tags")&&e.jsx("div",{className:"pl-1 space-y-px",children:n.map(d=>e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-xs text-warm-500 truncate hover:bg-warm-50 rounded-md",children:[e.jsxs("svg",{className:"h-3 w-3 text-status-merged shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.568 3H5.25A2.25 2.25 0 003 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 005.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 009.568 3z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]}),d]},d))})]}),R.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(v,{id:"worktrees",label:o("git.worktrees"),count:R.length}),f.has("worktrees")&&e.jsx("div",{className:"pl-1 space-y-px",children:R.map(d=>e.jsxs("div",{className:"group flex items-center gap-1.5 px-2 py-1 text-xs text-warm-600 hover:bg-warm-50 dark:hover:bg-warm-800/50 rounded-md",children:[e.jsx("svg",{className:"h-3 w-3 text-status-warning shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),e.jsx("span",{className:"truncate flex-1",title:d.path,children:d.branch}),e.jsx("button",{className:"opacity-0 group-hover:opacity-100 shrink-0 p-0.5 text-warm-400 hover:text-status-error transition-all",disabled:l||H===d.path,title:o("git.cleanupWorktree"),onClick:async()=>{await g({message:o("git.confirmCleanupWorktree").replace("{name}",d.branch),danger:!0})&&(_(d.path),a(!0),x(null),sn(i,d.path,d.branch).then(()=>{S(C=>C.filter(N=>N.path!==d.path)),c()}).catch(C=>x(C instanceof Error?C.message:"Error")).finally(()=>{_(null),a(!1)}))},children:H===d.path?e.jsx("svg",{className:"h-3 w-3 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}):e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]},d.path))})]}),r>0&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:[o("git.stashes"),e.jsx("span",{className:"text-warm-400 font-normal ml-auto",children:r})]}),h&&jt.createPortal(e.jsxs("div",{ref:F,className:"fixed z-tooltip bg-theme-card border border-warm-200 dark:border-warm-700 rounded-lg shadow-elevated py-1 min-w-[220px] text-xs",style:{left:h.x,top:h.y},children:[!h.isCurrent&&!h.isRemote&&e.jsx(y,{label:`${o("git.checkout")} ${h.branch}`,onClick:()=>X(()=>Es(i,h.branch))}),!h.isCurrent&&h.isRemote&&e.jsx(y,{label:`${o("git.checkoutRemote")} ${h.branch.replace(/^(remotes\/)?origin\//,"")}`,onClick:()=>{const d=h.branch.replace(/^(remotes\/)?origin\//,"");X(()=>Es(i,d))}}),!h.isCurrent&&e.jsx(y,{label:`${o("git.mergeInto")} ${h.branch}`,onClick:()=>X(()=>ta(i,h.branch))}),!h.isCurrent&&!h.isRemote&&e.jsx(y,{label:`${o("git.rebaseOnto")} ${h.branch}`,onClick:()=>X(()=>Dr(i,h.branch))}),e.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),e.jsx(y,{label:`${o("git.fetch")}`,onClick:()=>X(()=>ea(i))}),!h.isRemote&&e.jsxs(e.Fragment,{children:[e.jsx(y,{label:`${o("git.pull")}`,onClick:()=>X(()=>Qn(i))}),e.jsx(y,{label:`${o("git.push")}`,onClick:()=>X(()=>Bs(i))})]}),!h.isRemote&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),e.jsx(y,{label:`${o("git.renameBranch")} ${h.branch}...`,onClick:()=>{D(h.branch),K(h.branch),m(null)}}),!h.isCurrent&&(()=>{const d=R.find(N=>N.branch===h.branch);if(d)return e.jsx(y,{danger:!0,label:`${o("git.deleteWorktreeAndBranch")} ${h.branch}`,onClick:async()=>{m(null),await g({message:o("git.confirmDeleteWorktreeAndBranch").replace("{name}",h.branch),danger:!0})&&X(()=>sn(i,d.path,h.branch))}});const C=h.branch;return e.jsx(y,{danger:!0,label:`${o("git.delete")} ${C}`,onClick:async()=>{m(null),await g({message:o("git.confirmDelete").replace("{name}",C),danger:!0})&&X(async()=>{try{await Ts(i,C)}catch(N){const L=N instanceof Error?N.message:"";if(/not fully merged/i.test(L)&&await g({message:o("git.confirmForceDelete").replace("{name}",C),danger:!0})){await Ts(i,C,!0);return}throw N}})}})})()]})]}),document.body),j&&e.jsx(vt,{open:!0,onClose:()=>D(null),size:"sm",children:e.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated w-80 max-w-[90vw]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:[e.jsx("span",{className:"text-sm font-semibold text-warm-700",children:o("git.renameBranch")}),e.jsx("button",{onClick:()=>D(null),className:"text-warm-400 hover:text-warm-600",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("p",{className:"text-xs text-warm-500",children:[j," →"]}),e.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent bg-transparent",placeholder:o("git.newBranchName"),value:z,onChange:d=>K(d.target.value),onKeyDown:d=>{if(d.key==="Enter"&&z.trim()&&z.trim()!==j){const C=j;X(()=>an(i,C,z.trim()),()=>D(null))}},autoFocus:!0}),e.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:l||!z.trim()||z.trim()===j,onClick:()=>{const d=j;X(()=>an(i,d,z.trim()),()=>D(null))},children:o("git.rename")})]})]})})]})}function Fo(t){const n=new Date(t);if(isNaN(n.getTime()))return"";const r=String(n.getFullYear()).slice(2),i=String(n.getMonth()+1).padStart(2,"0"),l=String(n.getDate()).padStart(2,"0"),a=String(n.getHours()).padStart(2,"0"),c=String(n.getMinutes()).padStart(2,"0");return`${r}-${i}-${l} ${a}:${c}`}function Sn({view:t,onChange:n,fileChangeCount:r,orientation:i="vertical"}){const{t:l}=ye(),a=i==="horizontal",c=({id:x,label:o,badge:g})=>{const f=t===x;return e.jsxs("button",{onClick:()=>n(x),className:`flex items-center gap-2 px-3 py-2 text-xs font-medium rounded-md transition-colors ${a?"flex-1 justify-center":"w-full"} ${f?"bg-accent/10 text-accent shadow-soft ring-1 ring-inset ring-accent/20":"text-warm-600 hover:bg-warm-200/60"}`,children:[e.jsx("span",{className:`${a?"":"flex-1 text-left"} truncate`,children:o}),g!==void 0&&g>0&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${f?"bg-accent/10 text-accent":"bg-warm-200 text-warm-600"}`,children:g})]})};return a?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(c,{id:"fileStatus",label:l("git.viewFileStatus"),badge:r}),e.jsx(c,{id:"history",label:l("git.viewHistory")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"px-2 text-[10px] font-bold text-warm-400 uppercase tracking-widest flex items-center gap-2",children:[e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),l("git.workspace")]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(c,{id:"fileStatus",label:l("git.viewFileStatus"),badge:r}),e.jsx(c,{id:"history",label:l("git.viewHistory")})]})]})}function ns({axis:t,onResize:n}){return e.jsx("div",{onMouseDown:r=>{r.preventDefault(),document.body.style.cursor=t==="x"?"col-resize":"row-resize",document.body.style.userSelect="none";const i=a=>n(a.clientX,a.clientY),l=()=>{document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",l)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",l)},role:"separator","aria-orientation":t==="x"?"vertical":"horizontal",className:t==="x"?"w-1 mx-1 shrink-0 cursor-col-resize bg-warm-200/60 hover:bg-accent transition-colors rounded-md":"h-1 my-0.5 shrink-0 cursor-row-resize bg-warm-200/60 hover:bg-accent transition-colors"})}function zo({x:t,y:n,message:r,onDismiss:i}){const l=s.useRef(null),[a,c]=s.useState(null);return s.useEffect(()=>{if(!l.current)return;const x=l.current.getBoundingClientRect(),o=x.width,g=x.height,f=window.innerWidth,p=window.innerHeight;let h=n-g-12;h<8&&(h=n+12),h+g>p-8&&(h=p-g-8);let m=t-o/2;m<8&&(m=8),m+o>f-8&&(m=f-o-8),c({top:h,left:m})},[t,n]),jt.createPortal(e.jsx("div",{onClick:i,onTouchStart:i,className:"fixed inset-0 z-tooltip",children:e.jsx("div",{ref:l,className:"absolute bg-warm-800 dark:bg-warm-900 text-white text-xs px-3 py-2 rounded-lg shadow-elevated max-w-[80vw] whitespace-pre-wrap break-words pointer-events-none",style:a?{top:a.top,left:a.left,opacity:1}:{top:0,left:0,opacity:0},children:r})}),document.body)}function as(t,n,r){return Math.max(n,Math.min(r,t))}function js(t,n,r,i){if(typeof window>"u")return n;const l=window.localStorage.getItem(t);if(!l)return n;const a=parseFloat(l);return isNaN(a)?n:as(a,r,i)}function Po({project:t,refreshTrigger:n,onEvent:r,sendMessage:i,connected:l}){const{t:a}=ye(),{confirm:c,prompt:x}=_t(),o=xr("(max-width: 767px)"),[g,f]=s.useState(!1),[p,h]=s.useState(null),m=s.useRef({timer:null,startX:0,startY:0,fired:!1}),[j,D]=s.useState(()=>{if(typeof window>"u")return"history";const V=window.localStorage.getItem(`git-view:${t.id}`);return V==="fileStatus"||V==="history"?V:"history"});s.useEffect(()=>{typeof window<"u"&&window.localStorage.setItem(`git-view:${t.id}`,j)},[j,t.id]);const[z,K]=s.useState([]),[F,R]=s.useState(!0),[S,H]=s.useState(!1),[_,O]=s.useState(!0),[X,k]=s.useState(null),[se,G]=s.useState([]),[b,v]=s.useState([]),[y,d]=s.useState(0),[C,N]=s.useState([]),[L,B]=s.useState(""),[Y,le]=s.useState(null),[ue,me]=s.useState([]),[pe,ae]=s.useState({merging:!1,rebasing:!1,conflicted:[]}),[w,J]=s.useState(!1),[M,te]=s.useState(null),[re,we]=s.useState(null),[I,U]=s.useState([]),[ce,$e]=s.useState(!1),[Ne,Me]=s.useState(null),[Re,De]=s.useState(""),[Je,Q]=s.useState(!1),[W,de]=s.useState(null),be=s.useRef(null),Ie=s.useRef(null),He=s.useRef(null),Ee=s.useRef(!1),qe=s.useRef(null),st=s.useRef(null),A=s.useRef(null),[he,Ke]=s.useState(()=>js("clitrigger:git:sidebar-w",224,180,480)),[_e,ze]=s.useState(()=>js("clitrigger:git:detail-h-pct",.5,.2,.8)),[Oe,it]=s.useState(()=>js("clitrigger:git:detail-fl-w",240,160,500));s.useEffect(()=>{localStorage.setItem("clitrigger:git:sidebar-w",String(he))},[he]),s.useEffect(()=>{localStorage.setItem("clitrigger:git:detail-h-pct",String(_e))},[_e]),s.useEffect(()=>{localStorage.setItem("clitrigger:git:detail-fl-w",String(Oe))},[Oe]);const q=s.useCallback(V=>{if(!qe.current)return;const xe=qe.current.getBoundingClientRect();Ke(as(V-xe.left,180,480))},[]),Pe=s.useCallback((V,xe)=>{if(!st.current)return;const fe=st.current.getBoundingClientRect();ze(as((fe.bottom-xe)/fe.height,.2,.8))},[]),Ge=s.useCallback(V=>{if(!A.current)return;const xe=A.current.getBoundingClientRect();it(as(V-xe.left,160,500))},[]),nt=s.useCallback(async()=>{try{const V=await Ms(t.id);G(V.branches),v(V.tags),d(V.stashCount)}catch{}},[t.id]),Qe=s.useCallback(async()=>{try{const V=await Yn(t.id,Y??void 0);N(V.files),B(V.branch||""),ae({merging:!!V.mergeInProgress,rebasing:!!V.rebaseInProgress,conflicted:V.conflicted??[]})}catch{}},[t.id,Y]),Ue=s.useCallback(async(V,xe=!1)=>{if(!Ee.current){Ee.current=!0,H(!0),k(null);try{const fe=await hr(t.id,V,50);K(Z=>xe?fe.commits:[...Z,...fe.commits]),R(fe.hasMore)}catch(fe){k(fe instanceof Error?fe.message:"Failed to fetch git log")}finally{H(!1),O(!1),Ee.current=!1}}},[t.id]),ut=s.useCallback(()=>{K([]),R(!0),O(!0),we(null),U([]),Me(null),De(""),Ue(0,!0),nt(),Qe()},[Ue,nt,Qe]),ne=s.useCallback(async V=>{J(!0),te(null);try{await V()}catch(xe){te(xe instanceof Error?xe.message:"Operation failed")}finally{J(!1),ut()}},[ut]),ve=s.useCallback(async V=>{if((re==null?void 0:re.hash)===V.hash){we(null),U([]),Me(null),De("");return}we(V),Me(null),De(""),$e(!0);try{const xe=await pr(t.id,V.hash);if(U(xe.files),xe.files.length>0){const fe=xe.files[0].path;Me(fe),Q(!0);try{const Z=await tn(t.id,V.hash,fe);De(Z.diff)}catch{De("")}finally{Q(!1)}}}catch{U([])}finally{$e(!1)}},[t.id,re==null?void 0:re.hash]),je=s.useCallback(async V=>{if(re){Me(V),Q(!0);try{const xe=await tn(t.id,re.hash,V);De(xe.diff)}catch{De("")}finally{Q(!1)}}},[t.id,re]);s.useEffect(()=>{if(!W)return;const V=fe=>{be.current&&!be.current.contains(fe.target)&&de(null)},xe=()=>de(null);return document.addEventListener("mousedown",V),document.addEventListener("scroll",xe,!0),()=>{document.removeEventListener("mousedown",V),document.removeEventListener("scroll",xe,!0)}},[W]),s.useEffect(()=>{if(!W||!be.current)return;const V=be.current.getBoundingClientRect();let{x:xe,y:fe}=W;xe+V.width>window.innerWidth&&(xe=window.innerWidth-V.width-8),fe+V.height>window.innerHeight&&(fe=window.innerHeight-V.height-8),(xe!==W.x||fe!==W.y)&&de({...W,x:xe,y:fe})},[W]);const Le=s.useCallback(async V=>{J(!0),te(null),de(null);try{await V(),ut()}catch(xe){te(xe instanceof Error?xe.message:"Operation failed")}finally{J(!1)}},[ut]),ge=s.useCallback(()=>{m.current.timer!==null&&(window.clearTimeout(m.current.timer),m.current.timer=null)},[]),Xe=s.useCallback((V,xe)=>{o&&(ge(),m.current.startX=V.clientX,m.current.startY=V.clientY,m.current.fired=!1,m.current.timer=window.setTimeout(()=>{if(m.current.fired=!0,m.current.timer=null,h({message:xe,x:m.current.startX,y:m.current.startY}),typeof navigator<"u"&&typeof navigator.vibrate=="function")try{navigator.vibrate(10)}catch{}},500))},[o,ge]),Se=s.useCallback(V=>{if(!o||m.current.timer===null)return;const xe=V.clientX-m.current.startX,fe=V.clientY-m.current.startY;xe*xe+fe*fe>64&&ge()},[o,ge]),We=s.useCallback(()=>{o&&ge()},[o,ge]);s.useEffect(()=>{if(!p)return;const V=()=>h(null);return window.addEventListener("scroll",V,!0),window.addEventListener("resize",V),()=>{window.removeEventListener("scroll",V,!0),window.removeEventListener("resize",V)}},[p]),s.useEffect(()=>{o||h(null)},[o]),s.useEffect(()=>{Ue(0,!0),nt()},[Ue,nt]),s.useEffect(()=>{Qe()},[Qe]),s.useEffect(()=>{let V=!1;return Ds(t.id).then(xe=>{V||me(xe.worktrees)}).catch(()=>{V||me([])}),()=>{V=!0}},[t.id,se]),s.useEffect(()=>{Y&&!ue.some(V=>V.path===Y)&&le(null)},[ue,Y]),s.useEffect(()=>{n&&n>0&&ut()},[n]),s.useEffect(()=>{if(!(!l||!i))return i({type:"git:watch",projectId:t.id}),()=>i({type:"git:unwatch",projectId:t.id})},[l,i,t.id]),s.useEffect(()=>{if(r)return r(V=>{V.type==="git:changed"&&V.projectId===t.id&&(Qe(),nt())})},[r,t.id,Qe,nt]),s.useEffect(()=>{const V=Ie.current;if(!V)return;const xe=new IntersectionObserver(fe=>{fe[0].isIntersecting&&F&&!Ee.current&&z.length>0&&Ue(z.length)},{rootMargin:"200px"});return xe.observe(V),()=>xe.disconnect()},[F,z.length,Ue]);const et=s.useMemo(()=>Co(z),[z]);return e.jsxs("div",{className:"flex flex-col",style:{height:"calc(100vh - 260px)",minHeight:"400px"},children:[e.jsx("div",{className:"card-static mb-2",children:e.jsx(Eo,{projectId:t.id,projectName:t.name,onRefresh:ut,busy:w,setBusy:J,branches:se,statusFiles:C,worktreePath:Y??void 0})}),(pe.merging||pe.rebasing||pe.conflicted.length>0)&&e.jsxs("div",{className:"mb-2 px-3 py-2 bg-status-warning/10 text-status-warning text-xs flex items-center gap-2 rounded-md border border-status-warning/30",children:[e.jsx("span",{className:"font-semibold shrink-0",children:pe.merging?a("git.conflictMergeInProgress"):pe.rebasing?a("git.conflictRebaseInProgress"):a("git.conflicts")}),e.jsx("span",{className:"flex-1 min-w-0 truncate",children:pe.conflicted.length>0?a("git.conflictBanner").replace("{n}",String(pe.conflicted.length)):a("git.conflictAllResolved")}),j!=="fileStatus"&&pe.conflicted.length>0&&e.jsx("button",{className:"shrink-0 px-2 py-1 rounded-md border border-status-warning/30 hover:bg-status-warning/10",onClick:()=>D("fileStatus"),children:a("git.viewConflicts")}),(pe.merging||pe.rebasing)&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"shrink-0 px-2 py-1 rounded-md border border-status-warning/30 hover:bg-status-warning/10 disabled:opacity-40",disabled:w||pe.conflicted.length>0,onClick:()=>ne(()=>fr(t.id)),children:a("git.conflictContinue")}),e.jsx("button",{className:"shrink-0 px-2 py-1 rounded-md border border-status-warning/30 hover:bg-status-warning/10 disabled:opacity-40",disabled:w,onClick:async()=>{await c({message:a("git.confirmConflictAbort"),danger:!0})&&ne(()=>gr(t.id))},children:a("git.conflictAbort")})]})]}),M&&e.jsxs("div",{className:"mb-2 px-3 py-2 bg-status-error/10 text-status-error text-xs flex items-center justify-between rounded-md",children:[e.jsx("span",{children:M}),e.jsx("button",{onClick:()=>te(null),className:"ml-2 shrink-0 hover:text-status-error",children:"×"})]}),e.jsxs("div",{ref:qe,className:`flex flex-1 min-h-0 ${o?"flex-col gap-2":""}`,children:[e.jsxs("div",{style:o?void 0:{width:he},className:`shrink-0 flex flex-col gap-2 ${o?"":"min-h-0"}`,children:[o?e.jsxs("div",{className:"card-static p-2 flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(Sn,{view:j,onChange:D,fileChangeCount:C.length,orientation:"horizontal"})}),e.jsxs("button",{onClick:()=>f(V=>!V),className:"btn-ghost text-xs flex items-center gap-1 shrink-0 px-3 py-2","aria-expanded":g,children:[e.jsx("svg",{className:`h-3 w-3 transition-transform ${g?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})}),a("git.branches")]})]}):e.jsx("div",{className:"card-static p-3 shrink-0",children:e.jsx(Sn,{view:j,onChange:D,fileChangeCount:C.length})}),(!o||g)&&e.jsx("div",{className:`card overflow-y-auto p-3 ${o?"":"flex-1 min-h-0"}`,style:o?{maxHeight:"40vh"}:void 0,children:e.jsx(Lo,{branches:se,tags:b,stashCount:y,projectId:t.id,busy:w,setBusy:J,onRefresh:ut,onError:te})})]}),!o&&e.jsx(ns,{axis:"x",onResize:q}),e.jsx("div",{className:"card-static flex-1 overflow-hidden flex flex-col min-h-0",children:j==="fileStatus"?e.jsxs(e.Fragment,{children:[ue.length>0&&e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-warm-100 shrink-0",children:[e.jsx("span",{className:"text-2xs text-warm-400 uppercase tracking-wider shrink-0",children:a("git.statusTarget")}),e.jsxs("select",{className:"text-xs border border-warm-200 rounded-md px-2 py-1 text-warm-700 focus:outline-none focus:ring-1 focus:ring-accent min-w-0 max-w-full",style:{backgroundColor:"var(--color-bg-card)"},value:Y??"",onChange:V=>le(V.target.value||null),children:[e.jsx("option",{value:"",children:a("git.mainCheckout")}),ue.map(V=>e.jsx("option",{value:V.path,children:V.branch},V.path))]})]}),e.jsx($o,{projectId:t.id,worktreePath:Y??void 0,branchName:L,files:C,conflicted:pe.conflicted,busy:w,setBusy:J,onRefresh:ut,onError:te,isMobile:o})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-warm-100",children:[e.jsx("span",{className:"text-sm font-semibold text-warm-700",children:a("git.commitHistory")}),e.jsxs("button",{onClick:ut,disabled:S,className:"btn-ghost text-xs flex items-center gap-1.5",children:[e.jsx("svg",{className:`h-3.5 w-3.5 ${S?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182"})}),a("git.refresh")]})]}),e.jsxs("div",{className:`flex items-center py-1.5 border-b border-warm-50 text-2xs text-warm-400 uppercase tracking-wider ${o?"px-3":"px-4"}`,children:[!o&&e.jsx("div",{className:"w-24 shrink-0",children:a("git.graph")}),e.jsx("div",{className:"flex-1 min-w-0",children:a("git.description")}),e.jsx("div",{className:"w-14 text-right shrink-0",children:a("git.date")}),!o&&e.jsx("div",{className:"shrink-0 ml-2",children:a("git.author")}),e.jsx("div",{className:"w-16 text-right shrink-0",children:a("git.hash")})]}),X&&e.jsx("div",{className:"p-6 text-center",children:e.jsx("p",{className:"text-status-error text-sm",children:X})}),_&&!X&&e.jsx("div",{className:"p-6 text-center",children:e.jsx("p",{className:"text-warm-500 text-sm",children:a("detail.loading")})}),!_&&!X&&z.length===0&&e.jsx("div",{className:"p-6 text-center",children:e.jsx("p",{className:"text-warm-500 text-sm",children:a("git.noCommits")})}),z.length>0&&e.jsxs("div",{ref:st,className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"overflow-y-auto",ref:He,style:re?{flex:`${(1-_e)*100} 1 0`,minHeight:0}:{flex:"1 1 0",minHeight:0},children:[e.jsxs("div",{className:"relative flex",children:[!o&&e.jsx("div",{className:"shrink-0 sticky left-0",children:e.jsx(Do,{graphNodes:et,totalRows:z.length})}),e.jsx("div",{className:"flex-1 min-w-0",children:z.map(V=>{const xe=(re==null?void 0:re.hash)===V.hash;return e.jsxs("div",{onClick:fe=>{if(m.current.fired){fe.stopPropagation(),m.current.fired=!1;return}ve(V)},onPointerDown:fe=>Xe(fe,V.message),onPointerMove:Se,onPointerUp:We,onPointerCancel:We,onContextMenu:fe=>{fe.preventDefault(),!o&&de({commit:V,x:fe.clientX,y:fe.clientY})},className:`flex items-center px-3 cursor-pointer transition-colors border-b border-warm-50/20 ${xe?"bg-accent/10 border-l-2 border-l-accent":"hover:bg-warm-50/50"}`,style:{height:Ct,...o?{touchAction:"pan-y",WebkitTouchCallout:"none",userSelect:"none"}:null},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[V.refs.length>0&&e.jsx("div",{className:"flex items-center gap-1 shrink-0",children:V.refs.map((fe,Z)=>e.jsx(So,{refStr:fe},Z))}),e.jsx("span",{className:"text-xs text-warm-700 truncate",title:V.message,children:V.message})]}),e.jsx("div",{className:"w-28 text-right shrink-0",children:e.jsx("span",{className:"text-[11px] font-mono text-warm-600",title:V.date,children:Fo(V.date)})}),!o&&e.jsx("div",{className:"shrink-0 ml-2",children:e.jsx("span",{className:"text-[11px] text-warm-600",children:V.author})}),e.jsx("div",{className:"w-16 text-right shrink-0",children:e.jsx("span",{className:"text-[11px] font-mono text-warm-600 cursor-pointer hover:text-accent transition-colors",title:V.hash,onClick:fe=>{fe.stopPropagation(),navigator.clipboard.writeText(V.hash)},children:V.hash.substring(0,7)})})]},V.hash)})})]}),e.jsx("div",{ref:Ie,className:"h-8 flex items-center justify-center",children:S&&e.jsx("span",{className:"text-xs text-warm-400",children:a("git.loadMore")})})]}),re&&e.jsxs(e.Fragment,{children:[e.jsx(ns,{axis:"y",onResize:Pe}),e.jsxs("div",{ref:A,className:`flex min-h-0 ${o?"flex-col":""}`,style:{flex:`${_e*100} 1 0`,minHeight:0},children:[e.jsx("div",{style:o?void 0:{width:Oe},className:`shrink-0 overflow-hidden ${o?"h-1/2":""}`,children:e.jsx(Jn,{files:I,loading:ce,selectedFile:Ne,onFileClick:je,commitHash:re.hash})}),!o&&e.jsx(ns,{axis:"x",onResize:Ge}),e.jsx("div",{className:`flex-1 overflow-hidden bg-warm-900 ${o?"min-h-0 border-t border-warm-200":"min-w-0"}`,children:e.jsx(ps,{diff:Re,loading:Je,selectedFile:Ne})})]})]})]})]})})]}),p&&e.jsx(zo,{x:p.x,y:p.y,message:p.message,onDismiss:()=>h(null)}),W&&jt.createPortal((()=>{const V=W.commit,xe=V.hash.substring(0,7),fe=(tt,u,E=!1)=>e.jsx("button",{className:`w-full text-left px-3 py-1.5 hover:bg-theme-hover transition-colors disabled:opacity-40 ${E?"text-status-error":"text-theme-text"}`,disabled:w,onClick:u,children:tt}),Z=tt=>fe(`${a("git.resetHere")} (${tt})`,async()=>{const u=tt==="hard"?a("git.confirmResetHard").replace("{hash}",xe):a("git.confirmReset").replace("{hash}",xe).replace("{mode}",tt);de(null),await c({message:u,danger:tt==="hard"})&&Le(()=>br(t.id,V.hash,tt))},tt==="hard");return e.jsxs("div",{ref:be,className:"fixed z-tooltip bg-theme-card border border-warm-200 dark:border-warm-700 rounded-lg shadow-elevated py-1 min-w-[240px] text-xs",style:{left:W.x,top:W.y},children:[fe(a("git.copySha"),()=>{navigator.clipboard.writeText(V.hash),de(null)}),e.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),fe(a("git.createBranchHere"),async()=>{de(null);const tt=await x(a("git.promptBranchName").replace("{hash}",xe));tt&&tt.trim()&&Le(()=>qn(t.id,tt.trim(),V.hash))}),fe(a("git.createTagHere"),async()=>{de(null);const tt=await x(a("git.promptTagName").replace("{hash}",xe));tt&&tt.trim()&&Le(()=>Xn(t.id,tt.trim(),void 0,V.hash))}),e.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),fe(a("git.cherryPick"),async()=>{de(null),await c(a("git.confirmCherryPick").replace("{hash}",xe))&&Le(async()=>{(await vr(t.id,V.hash)).conflict&&D("fileStatus")})}),fe(a("git.revertCommit"),async()=>{de(null),await c(a("git.confirmRevert").replace("{hash}",xe))&&Le(async()=>{(await wr(t.id,V.hash)).conflict&&D("fileStatus")})}),e.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),Z("soft"),Z("mixed"),Z("hard")]})})(),document.body)]})}function _n(t,n=!1){return xt(`/api/projects/${t}/svn-status${n?"?showUpdates=true":""}`)}function ja(t,n=0,r=50,i){const l=new URLSearchParams({skip:String(n),limit:String(r)});return i&&l.set("url",i),xt(`/api/projects/${t}/svn-log?${l}`)}function Ao(t,n){return xt(`/api/projects/${t}/svn-url-info?url=${encodeURIComponent(n)}`)}function Io(t,n){return xt(`/api/projects/${t}/svn-commit-files?revision=${encodeURIComponent(n)}`)}function Na(t,n,r,i){const l=new URLSearchParams({revision:n});return r&&l.set("file",r),i&&l.set("status",i),xt(`/api/projects/${t}/svn-commit-diff?${l}`)}function ka(t,n,r){const i=new URLSearchParams;n&&i.set("file",n),r&&i.set("revision",r);const l=i.toString();return xt(`/api/projects/${t}/svn-diff${l?`?${l}`:""}`)}function Ho(t,n){const r=new URLSearchParams;n&&r.set("file",n);const i=r.toString();return xt(`/api/projects/${t}/svn-properties${i?`?${i}`:""}`)}function Oo(t,n,r,i){return lt(`/api/projects/${t}/svn-propset`,{name:n,value:r,file:i})}function Wo(t,n){return lt(`/api/projects/${t}/svn-add`,{files:n})}function Bo(t,n){return lt(`/api/projects/${t}/svn-revert`,{files:n})}function Ko(t,n,r=!1){return lt(`/api/projects/${t}/svn-delete`,{files:n,keepLocal:r})}function Uo(t,n,r="working"){return lt(`/api/projects/${t}/svn-resolve`,{files:n,accept:r})}function Vo(t,n,r){return lt(`/api/projects/${t}/svn-changelist`,{name:n,files:r})}function Go(t,n,r){return lt(`/api/projects/${t}/svn-commit`,{message:n,files:r})}async function Mn(t,n,r){const i=await fetch(`/api/projects/${t}/svn-update`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({revision:n})});if(i.status===401)throw window.dispatchEvent(new CustomEvent("auth:unauthorized")),new rn(401,"Unauthorized");if(!i.ok){const g=await i.text().catch(()=>"");let f="";try{f=JSON.parse(g).error??""}catch{}throw new rn(i.status,f||`HTTP ${i.status}`)}const l=i.body.getReader(),a=new TextDecoder;let c="",x=null;const o=g=>{if(!g.trim())return;const f=JSON.parse(g);if(f.error)throw new Error(f.error);f.done?x=f.done:f.line!==void 0&&(r==null||r(f.line))};for(;;){const{value:g,done:f}=await l.read();if(f)break;c+=a.decode(g,{stream:!0});const p=c.split(`
|
|
@@ -170,7 +170,7 @@ import{c as Fe,o as xt,p as lt,q as Gt,s as Yt,a as ye,j as e,r as s,t as Xa,R a
|
|
|
170
170
|
`)[0].slice(0,40);!m||!j||(p([...c.filter(D=>D.name!==j),{name:j,body:m}]),g(""))};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:i,type:"button",onClick:()=>a(m=>!m),className:"btn btn-sm shrink-0",title:r("svn.templates"),children:[r("svn.templates")," ▾"]}),l&&e.jsxs(cs,{anchorRef:i,width:260,placement:"top",onClose:f,className:"rounded-lg shadow-elevated z-tooltip py-1",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-warm-400",children:c.length===0?r("svn.noTemplates"):r("svn.templatePickHint")}),c.map(m=>e.jsxs("div",{className:"flex items-center group",children:[e.jsx("button",{type:"button",className:`${Be} min-w-0`,title:m.body,onClick:j=>{const D=t.trimEnd();n(j.shiftKey||!D?m.body:`${D}
|
|
171
171
|
${m.body}`),f()},children:e.jsx("span",{className:"truncate",children:m.name})}),e.jsx("button",{type:"button",className:"p-1 mr-1 shrink-0 text-warm-400 hover:text-status-error opacity-0 group-hover:opacity-100 transition-opacity",title:r("svn.deleteTemplate"),"aria-label":`${r("svn.deleteTemplate")}: ${m.name}`,onClick:()=>p(c.filter(j=>j!==m)),children:e.jsx(ft,{size:12})})]},m.name)),e.jsx(Ks,{}),e.jsxs("form",{className:"flex items-center gap-1 px-2 py-1",onSubmit:m=>{m.preventDefault(),h()},children:[e.jsx("input",{value:o,onChange:m=>g(m.target.value),placeholder:r("svn.templateNamePlaceholder"),className:"input-field flex-1 min-w-0 text-xs py-1"}),e.jsx(Ze,{type:"submit",size:"sm",disabled:!t.trim(),title:r("svn.saveTemplateHint"),children:r("svn.saveTemplate")})]})]})]})}function oc({onResolve:t,onOpen:n}){const{t:r}=ye(),i=s.useRef(null),[l,a]=s.useState(null);s.useEffect(()=>{if(!l)return;const o=()=>a(null);return document.addEventListener("mousedown",o),document.addEventListener("scroll",o,!0),window.addEventListener("resize",o),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o)}},[l]);const c=o=>{var h;o.stopPropagation(),n==null||n();const g=(h=i.current)==null?void 0:h.getBoundingClientRect();if(!g)return;const f=Math.min(g.left,window.innerWidth-188),p=Math.min(g.bottom+2,window.innerHeight-148);a({x:Math.max(8,f),y:Math.max(8,p)})},x=o=>g=>{g.stopPropagation(),a(null),t(o)};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:i,draggable:!1,onClick:c,className:"shrink-0 text-2xs px-1.5 py-0.5 rounded-md bg-status-error/15 text-status-error hover:bg-status-error/25 font-medium",children:[r("svn.resolve")," ▾"]}),l&&jt.createPortal(e.jsxs("div",{className:"fixed z-tooltip bg-theme-card border border-warm-200 dark:border-warm-700 rounded-lg shadow-elevated py-1 min-w-[180px]",style:{left:l.x,top:l.y},onMouseDown:o=>o.stopPropagation(),children:[e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs text-warm-500 hover:bg-theme-hover transition-colors border-b border-warm-100 dark:border-warm-700",onClick:o=>{o.stopPropagation(),n==null||n(),a(null)},children:r("svn.previewDiff")}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs text-theme-text hover:bg-theme-hover transition-colors",onClick:x("working"),children:r("svn.resolveWorking")}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs text-theme-text hover:bg-theme-hover transition-colors",onClick:x("theirs-full"),children:r("svn.resolveTheirs")}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs text-theme-text hover:bg-theme-hover transition-colors",onClick:x("mine-full"),children:r("svn.resolveMine")})]}),document.body)]})}function Hs({file:t,indent:n,showDir:r,shared:i}){const{t:l}=ye(),a=Nt(t),c=i.activeFile===t.path;return e.jsxs("div",{draggable:!0,onDragStart:x=>i.onDragStart(x,t),onClick:()=>i.onActivate(t.path),onContextMenu:x=>i.onContextMenu(x,t),style:{paddingLeft:12+n*14},className:`group flex items-center gap-2 pr-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 ${c?"bg-accent/10 border-l-2 border-accent":""}`,children:[e.jsx("input",{type:"checkbox",checked:i.selectedFiles.has(t.path),onChange:x=>{x.stopPropagation(),i.onToggle(t.path)},onClick:x=>x.stopPropagation(),className:"shrink-0"}),e.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${tc(a)}`,children:a}),e.jsxs("span",{className:`truncate flex-1 ${a==="C"?"text-status-error font-medium":"text-warm-600"}`,title:t.path,children:[t.path.split("/").pop(),r&&t.path.includes("/")&&e.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:t.path.substring(0,t.path.lastIndexOf("/"))})]}),a==="C"&&e.jsx(oc,{onResolve:x=>i.onResolve(t.path,x),onOpen:()=>i.onActivate(t.path)}),e.jsx("button",{onClick:x=>i.onContextMenu(x,t),className:"shrink-0 opacity-0 group-hover:opacity-100 text-warm-400 hover:text-warm-700 px-1 transition-opacity",title:l("svn.fileStatus"),children:"⋯"})]})}function Ta({node:t,depth:n,collapsed:r,onToggleCollapse:i,fileProps:l,onDirContextMenu:a}){const{t:c}=ye(),x=r.has(t.path),o=Da(t),g=o.dirs>0?c("svn.dirFileCount").replace("{d}",String(o.dirs)).replace("{f}",String(o.files)):c("svn.fileCount").replace("{f}",String(o.files));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>i(t.path),onContextMenu:f=>a(f,t),style:{paddingLeft:12+n*14},className:"flex items-center gap-1 pr-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 select-none",children:[x?e.jsx(St,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}):e.jsx(ms,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}),e.jsx(Zl,{className:"w-3.5 h-3.5 shrink-0 text-status-warning"}),e.jsx("span",{className:"truncate text-warm-700 font-medium",title:t.path,children:t.name}),e.jsx("span",{className:"text-warm-400 text-2xs ml-1 shrink-0",children:g})]}),!x&&e.jsxs(e.Fragment,{children:[t.dirs.map(f=>e.jsx(Ta,{node:f,depth:n+1,collapsed:r,onToggleCollapse:i,fileProps:l,onDirContextMenu:a},f.path)),t.files.map(f=>e.jsx(Hs,{file:f,indent:n+1,shared:l},f.path))]})]})}function cc(t,n,r,i){const l=new Map,a=[],c=[],x=[];for(const f of t){const p=Nt(f);if(f.changelist){const h=l.get(f.changelist);h?h.push(f):l.set(f.changelist,[f])}else p==="?"?c.push(f):p==="!"?x.push(f):a.push(f)}for(const f of n)l.has(f)||l.set(f,[]);const o=Array.from(l.keys()).sort().map(f=>({key:`cl:${f}`,label:f,files:l.get(f)}));a.length&&o.push({key:"default",label:i("svn.changelistDefault"),files:a}),c.length&&o.push({key:"unversioned",label:i("svn.changelistUnversioned"),files:c}),x.length&&o.push({key:"missing",label:i("svn.changelistMissing"),files:x});const g=f=>r.indexOf(f.key);return o.sort((f,p)=>{const h=g(f),m=g(p);return h===-1||m===-1?(h===-1?1:0)-(m===-1?1:0):h-m})}function dc(t){const{t:n}=ye(),[r,i]=s.useState(()=>{try{return localStorage.getItem("svn.groupByDir")!=="false"}catch{return!0}}),[l,a]=s.useState(new Set),[c,x]=s.useState(null),o=s.useRef(null),[g,f]=s.useState(()=>ac(Ln,72,ks,Cs)),p=`svn.changelistOrder:${t.projectId}`,[h,m]=s.useState(()=>{try{const k=JSON.parse(localStorage.getItem(p)??"[]");return Array.isArray(k)?k:[]}catch{return[]}}),j=s.useMemo(()=>cc(t.statusFiles,t.pendingChangelists,h,n),[t.statusFiles,t.pendingChangelists,h,n]),D=(k,se)=>{const G=j.map(b=>b.key);G.splice(G.indexOf(k),1),G.splice(G.indexOf(se),0,k),m(G);try{localStorage.setItem(p,JSON.stringify(G))}catch{}},[z,K]=s.useState(null);s.useEffect(()=>{try{localStorage.setItem(Ln,String(g))}catch{}},[g]);const F=()=>i(k=>{const se=!k;try{localStorage.setItem("svn.groupByDir",String(se))}catch{}return se}),R=k=>a(se=>{const G=new Set(se);return G.has(k)?G.delete(k):G.add(k),G}),S={selectedFiles:t.selectedFiles,activeFile:t.activeFile,onActivate:t.onActivate,onToggle:t.onToggle,onContextMenu:t.onContextMenu,onDragStart:(k,se)=>{const G=t.selectedFiles.size>0&&t.selectedFiles.has(se.path)?t.statusFiles.filter(b=>t.selectedFiles.has(b.path)).map(b=>b.path):[se.path];k.dataTransfer.setData("text/plain",JSON.stringify(G)),k.dataTransfer.effectAllowed="move"},onResolve:t.onResolve},H=(k,se)=>{k.preventDefault(),x(null);const G=k.dataTransfer.getData(Ss);if(G){G!==se.key&&D(G,se.key);return}if(se.key==="unversioned"||se.key==="missing")return;let b;try{b=JSON.parse(k.dataTransfer.getData("text/plain"))}catch{return}const v=b.filter(y=>{const d=t.statusFiles.find(C=>C.path===y);return d&&Nt(d)!=="?"});v.length&&t.onChangelist(se.key.startsWith("cl:")?se.label:null,v)},_=k=>{(k.metaKey||k.ctrlKey)&&k.key==="Enter"&&(k.preventDefault(),t.onCommit())},O=s.useCallback(()=>{var G;const k=(G=o.current)==null?void 0:G.getBoundingClientRect().height;if(!k)return Cs;const se=k-sc;return Is(se,ks,Cs)},[]),X=k=>{k.preventDefault();const se=k.currentTarget,G=k.clientY,b=g;let v=null,y=null;const d=B=>{const Y=b+(G-B);f(Is(Y,ks,O()))},C=()=>{if(v=null,y===null)return;const B=y;y=null,d(B)},N=B=>{y=B.clientY,v===null&&(v=requestAnimationFrame(C))},L=B=>{v!==null&&cancelAnimationFrame(v),v=null,B.type==="pointerup"&&y!==null&&C(),y=null,document.body.style.cursor="",document.body.style.userSelect="",se.removeEventListener("pointermove",N),se.removeEventListener("pointerup",L),se.removeEventListener("pointercancel",L);try{se.releasePointerCapture(k.pointerId)}catch{}};se.setPointerCapture(k.pointerId),document.body.style.cursor="row-resize",document.body.style.userSelect="none",se.addEventListener("pointermove",N),se.addEventListener("pointerup",L),se.addEventListener("pointercancel",L)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center gap-2 shrink-0 flex-wrap",children:[e.jsx(Ze,{size:"sm",onClick:t.onRefresh,disabled:t.busy,children:t.statusLoading?n("svn.checking"):n("svn.refresh")}),e.jsxs(Ze,{size:"sm",onClick:t.onCheckRepository,disabled:t.busy,children:[t.remoteChecking?n("svn.checking"):n("svn.checkRepository"),e.jsx(Gs,{})]}),t.actionFlash&&e.jsx("span",{className:"text-2xs text-status-success ml-1",children:t.actionFlash}),t.error&&e.jsx("span",{className:"text-2xs text-status-error ml-1",children:t.error})]}),e.jsxs("div",{className:"flex-1 grid grid-cols-2 min-h-0",children:[e.jsxs("div",{ref:o,className:"border-r border-warm-100 flex flex-col min-h-0",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[e.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:n("svn.changed")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:F,title:n(r?"svn.viewFlat":"svn.groupByDir"),className:"text-warm-400 hover:text-warm-700 p-0.5 rounded-md hover:bg-warm-100",children:r?e.jsx(is,{className:"w-3.5 h-3.5"}):e.jsx(ql,{className:"w-3.5 h-3.5"})}),e.jsx("span",{className:"text-2xs text-warm-400",children:t.statusFiles.length})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",onContextMenu:k=>{k.preventDefault(),K({x:k.clientX,y:k.clientY})},children:t.statusLoading?e.jsx("div",{className:"p-6 text-center text-xs text-warm-400",children:n("git.loadingFiles")}):j.length===0?e.jsx("div",{className:"p-6 text-center text-xs text-warm-400",children:n("svn.noChanges")}):j.map(k=>{const se=`§${k.key}`,G=l.has(se),b=k.files.reduce((N,L)=>N+(t.selectedFiles.has(L.path)?1:0),0),v=k.files.length>0&&b===k.files.length,y=r?lc(k.files):null,d=k.key!=="unversioned"&&k.key!=="missing",C=c===k.key;return e.jsxs("div",{children:[e.jsxs("div",{draggable:!0,onClick:()=>R(se),onContextMenu:N=>t.onGroupContextMenu(N,k.label,k.files,null,k.key.startsWith("cl:")?k.label:void 0),onDragStart:N=>{N.dataTransfer.setData(Ss,k.key),N.dataTransfer.effectAllowed="move"},onDragOver:N=>{!d&&!N.dataTransfer.types.includes(Ss)||(N.preventDefault(),N.dataTransfer.dropEffect="move",c!==k.key&&x(k.key))},onDragLeave:()=>x(N=>N===k.key?null:N),onDrop:N=>H(N,k),className:`flex items-center gap-1.5 px-3 py-1.5 cursor-pointer text-xs select-none border-y border-warm-200/70 ${C?"bg-accent/20 ring-1 ring-inset ring-accent":"bg-warm-100 hover:bg-warm-200/60"}`,children:[G?e.jsx(St,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}):e.jsx(ms,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}),e.jsx("input",{type:"checkbox",checked:v,ref:N=>{N&&(N.indeterminate=b>0&&!v)},onChange:N=>{N.stopPropagation(),t.onSelectMany(k.files.map(L=>L.path),!v)},onClick:N=>N.stopPropagation(),className:"shrink-0"}),e.jsx("span",{className:"truncate text-warm-800 font-bold",children:k.label}),e.jsx("span",{className:"text-warm-400 text-2xs ml-1 shrink-0",children:k.files.length})]}),!G&&(y?e.jsxs(e.Fragment,{children:[y.dirs.map(N=>e.jsx(Ta,{node:N,depth:1,collapsed:l,onToggleCollapse:R,fileProps:S,onDirContextMenu:(L,B)=>t.onGroupContextMenu(L,B.path,Ea(B),B.path)},N.path)),y.files.map(N=>e.jsx(Hs,{file:N,indent:1,shared:S},N.path))]}):k.files.map(N=>e.jsx(Hs,{file:N,indent:1,showDir:!0,shared:S},N.path)))]},k.key)})}),z&&e.jsx(yt,{x:z.x,y:z.y,onClose:()=>K(null),children:e.jsx("button",{className:Be,onClick:t.onNewEmptyChangelist,children:n("svn.newChangelist")})}),e.jsxs("div",{className:"border-t border-warm-100 shrink-0 bg-theme-bg",children:[e.jsx("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize commit message",onPointerDown:X,className:"h-2 -mt-px cursor-row-resize touch-none flex items-center justify-center group",children:e.jsx("div",{className:"h-px w-10 bg-warm-300 group-hover:bg-accent transition-colors"})}),e.jsxs("div",{className:"p-2 pt-1",children:[e.jsx("textarea",{value:t.commitMessage,onChange:k=>t.onCommitMessageChange(k.target.value),onKeyDown:_,placeholder:n("svn.commitMessagePlaceholder"),className:"block w-full text-xs p-2 border border-warm-200 rounded-md resize-none focus:border-accent focus:ring-1 focus:ring-accent/30 outline-none",style:{height:g},rows:3}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(ic,{message:t.commitMessage,onPick:t.onCommitMessageChange}),e.jsx(Ze,{variant:"primary",size:"sm",onClick:t.onCommit,disabled:t.busy||!t.commitMessage.trim(),className:"flex-1",children:t.busy?n("svn.committing"):n("svn.commit")})]})]})]})]}),e.jsx("div",{className:"min-w-0",children:e.jsx(ps,{diff:t.workingDiff,loading:t.workingDiffLoading,selectedFile:t.activeFile})})]})]})}function uc(t){const{t:n}=ye();return t.loaded?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center gap-2 shrink-0",children:[e.jsx(Ze,{size:"sm",onClick:t.onLoad,disabled:t.loading,children:t.loading?n("svn.checking"):n("svn.refresh")}),t.error&&e.jsx("span",{className:"text-2xs text-status-error ml-1",children:t.error})]}),e.jsxs("div",{className:"flex-1 grid grid-cols-[1fr_1fr] min-h-0",children:[e.jsxs("div",{className:"border-r border-warm-100 flex flex-col min-h-0",children:[e.jsx("div",{className:"px-3 py-2 border-b border-warm-100 shrink-0",children:e.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:n("svn.history")})}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[t.entries.map(r=>e.jsxs("div",{onClick:()=>t.onSelectRev(r.hash),onContextMenu:i=>t.onRevContextMenu(i,r.hash),className:`px-3 py-2 cursor-pointer text-xs border-b border-warm-50 hover:bg-warm-50/50 ${t.selectedRev===r.hash?"bg-accent/10 border-l-2 border-accent":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-mono text-2xs text-warm-400 shrink-0",children:["r",r.hash]}),e.jsx("span",{className:"truncate flex-1 text-warm-700",title:r.message,children:r.message.split(`
|
|
172
172
|
`)[0]})]}),e.jsxs("div",{className:"mt-0.5 text-2xs text-warm-400 truncate",children:[r.author,r.date&&e.jsxs("span",{children:[" · ",new Date(r.date).toLocaleString()]})]})]},r.hash)),t.hasMore&&!t.loading&&e.jsxs("button",{onClick:t.onLoadMore,className:"w-full py-2 text-2xs text-warm-500 hover:bg-warm-50",children:["+ ",n("svn.loadMore")]})]})]}),e.jsxs("div",{className:"grid grid-rows-[1fr_2fr] min-h-0",children:[e.jsx("div",{className:"border-b border-warm-100 min-h-0",children:e.jsx(Jn,{files:t.revFiles,loading:t.revFilesLoading,selectedFile:t.selectedFile,onFileClick:t.onSelectFile,commitHash:t.selectedRev??void 0})}),e.jsx("div",{className:"min-h-0",children:e.jsx(ps,{diff:t.revDiff,loading:t.revDiffLoading,selectedFile:t.selectedFile})})]})]})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx("p",{className:"text-xs text-warm-400 max-w-xs",children:n("svn.logEmptyHint")}),e.jsxs(Ze,{variant:"primary",size:"md",onClick:t.onLoad,disabled:t.loading,children:[t.loading?n("svn.checking"):n("svn.loadLog"),e.jsx("span",{className:"text-[9px] uppercase tracking-wide px-1 rounded-md bg-white/20",children:n("svn.remoteBadge")})]}),t.error&&e.jsx("span",{className:"text-2xs text-status-error",children:t.error})]})}function mc(t){const{t:n}=ye(),r=s.useRef(null),[i,l]=s.useState({x:t.x,y:t.y}),a=s.useMemo(()=>{if(t.target.kind==="group")return t.target.files;const S=t.target.file;return t.selected.size>0&&t.selected.has(S.path)?t.allFiles.filter(H=>t.selected.has(H.path)):[S]},[t.target,t.selected,t.allFiles]),c=t.target.kind==="file"?t.target.file:null,x=t.target.kind==="group"?t.target.label:null,o=t.target.kind==="group"?t.target.dirPath:null,g=t.target.kind==="group"?t.target.changelist:void 0,f=c?Nt(c)!=="?"?c.path:null:o,p=a.filter(S=>Nt(S)==="?").map(S=>S.path),h=a.filter(S=>Nt(S)!=="?").map(S=>S.path),m=a.filter(S=>!["?","D"].includes(Nt(S))).map(S=>S.path),j=a.filter(S=>Nt(S)==="C").map(S=>S.path),D=a.filter(S=>Nt(S)!=="?").map(S=>S.path),z=a.filter(S=>S.changelist).map(S=>S.path);s.useEffect(()=>{const S=_=>{r.current&&!r.current.contains(_.target)&&t.onClose()},H=()=>t.onClose();return document.addEventListener("mousedown",S),document.addEventListener("scroll",H,!0),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("scroll",H,!0)}},[t]),s.useEffect(()=>{if(!r.current)return;const S=r.current.getBoundingClientRect();let{x:H,y:_}={x:t.x,y:t.y};H+S.width>window.innerWidth&&(H=window.innerWidth-S.width-8),_+S.height>window.innerHeight&&(_=window.innerHeight-S.height-8),l({x:H,y:_})},[t.x,t.y]);const K=a.length,F=K>1?` (${K})`:"",R=({label:S,onClick:H,danger:_})=>e.jsx("button",{className:`w-full text-left px-3 py-1.5 text-xs hover:bg-theme-hover transition-colors ${_?"text-status-error":"text-theme-text"}`,onClick:()=>{H(),t.onClose()},children:S});return jt.createPortal(e.jsxs("div",{ref:r,className:"fixed z-tooltip bg-theme-card border border-warm-200 dark:border-warm-700 rounded-lg shadow-elevated py-1 min-w-[200px]",style:{left:i.x,top:i.y},children:[x!==null&&e.jsxs("div",{className:"px-3 py-1.5 border-b border-warm-100 dark:border-warm-700 truncate",title:x,children:[e.jsx("span",{className:"text-xs font-semibold text-warm-700",children:x}),e.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["· ",a.length]})]}),g!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx(R,{label:n("svn.renameChangelist"),onClick:()=>t.onRenameChangelist(g,a.map(S=>S.path))}),a.length===0&&e.jsx(R,{label:n("svn.deleteChangelist"),danger:!0,onClick:()=>t.onDeleteChangelist(g)})]}),c&&e.jsx(R,{label:n("svn.viewDiff"),onClick:()=>t.onViewDiff(c.path)}),f!==null&&e.jsx(R,{label:n("svn.properties"),onClick:()=>t.onProperties(f)}),p.length>0&&e.jsx(R,{label:`${n("svn.add")}${F}`,onClick:()=>t.onAdd(p)}),h.length>0&&e.jsx(R,{label:`${n("svn.revert")}${F}`,onClick:()=>t.onRevert(h)}),m.length>0&&e.jsx(R,{label:`${n("svn.delete")}${F}`,danger:!0,onClick:()=>t.onDelete(m)}),j.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),e.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:n("svn.resolve")}),e.jsx(R,{label:n("svn.resolveWorking"),onClick:()=>t.onResolve(j,"working")}),e.jsx(R,{label:n("svn.resolveMine"),onClick:()=>t.onResolve(j,"mine-full")}),e.jsx(R,{label:n("svn.resolveTheirs"),onClick:()=>t.onResolve(j,"theirs-full")}),e.jsx(R,{label:n("svn.resolveBase"),onClick:()=>t.onResolve(j,"base")})]}),D.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),e.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:n("svn.moveToChangelist")}),z.length>0&&e.jsx(R,{label:`${n("svn.changelistDefault")}${F}`,onClick:()=>t.onChangelist(null,z)}),t.changelists.filter(S=>S!==g).map(S=>e.jsx(R,{label:`${S}${F}`,onClick:()=>t.onChangelist(S,D)},S)),e.jsx(R,{label:n("svn.newChangelist"),onClick:()=>t.onNewChangelist(D)})]})]}),document.body)}function xc({projectId:t,mode:n,revision:r,onClose:i}){const{t:l}=ye(),[a,c]=s.useState(""),[x,o]=s.useState(!0),[g,f]=s.useState(null);s.useEffect(()=>{let h=!1;return o(!0),f(null),(n==="commit"?Na(t,r):ka(t,void 0,r)).then(j=>{h||c(j.diff)}).catch(j=>{h||f(j instanceof Error?j.message:"Diff failed")}).finally(()=>{h||o(!1)}),()=>{h=!0}},[t,n,r]);const p=l(n==="commit"?"svn.revisionChangesTitle":"svn.compareWithWorkingTitle").replace("{rev}",r);return e.jsx(vt,{open:!0,onClose:i,size:"4xl",children:e.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated w-full h-[80vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-warm-100 flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",title:p,children:p}),e.jsx(Gs,{}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:i,className:"text-warm-400 hover:text-warm-600 shrink-0",children:e.jsx(ft,{size:14})})]}),e.jsx("div",{className:"flex-1 min-h-0",children:g?e.jsx("p",{className:"p-4 text-status-error text-xs whitespace-pre-wrap break-all",children:g}):e.jsx(ps,{fileHeaders:!0,diff:a,loading:x,selectedFile:p})})]})})}function hc({projectId:t,file:n,onClose:r}){const{t:i}=ye(),[l,a]=s.useState(null),[c,x]=s.useState(null),[o,g]=s.useState(null),[f,p]=s.useState(""),[h,m]=s.useState(!1),[j,D]=s.useState(!1),[z,K]=s.useState(0);s.useEffect(()=>{let S=!1;return a(null),x(null),Ho(t,n??void 0).then(H=>{S||a(H.properties)}).catch(H=>{S||x(H instanceof Error?H.message:"Failed to load properties")}),()=>{S=!0}},[t,n,z]);const F=async(S,H=f)=>{D(!0),x(null);try{await Oo(t,S,H,n??void 0),g(null),K(_=>_+1)}catch(_){x(_ instanceof Error?_.message:"Failed to save property")}finally{D(!1)}},R=n??i("svn.workingCopyRoot");return e.jsx(vt,{open:!0,onClose:r,size:"2xl",children:e.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated w-full max-h-[80vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-warm-100 flex items-center justify-between shrink-0",children:[e.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",title:R,children:i("svn.propertiesOf").replace("{target}",R)}),e.jsx("button",{onClick:r,className:"text-warm-400 hover:text-warm-600 shrink-0 ml-2",children:e.jsx(ft,{size:14})})]}),e.jsxs("div",{className:"p-4 overflow-y-auto",children:[c&&e.jsx("p",{className:"text-status-error text-xs mb-2 whitespace-pre-wrap break-all",children:c}),l===null?!c&&e.jsx("p",{className:"text-warm-400 text-xs",children:i("git.loadingFiles")}):l.length===0?e.jsx("p",{className:"text-warm-400 text-xs",children:i("svn.noProperties")}):e.jsx("div",{className:"space-y-3",children:l.map(S=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-xs font-mono font-semibold text-accent break-all",children:S.name}),o!==S.name&&e.jsx("button",{onClick:()=>{g(S.name),p(S.value),m(!1)},className:"text-2xs text-warm-400 hover:text-accent shrink-0",children:i("svn.editProperty")})]}),o===S.name&&S.name==="svn:externals"&&!h?e.jsx(ec,{projectId:t,value:f,saving:j,onCancel:()=>g(null),onSave:H=>{p(H),F(S.name,H)},onEditAsText:H=>{p(H),m(!0)}}):o===S.name?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{value:f,onChange:H=>p(H.target.value),rows:Math.min(12,Math.max(3,f.split(`
|
|
173
|
-
`).length+1)),spellCheck:!1,className:"mt-1 w-full text-2xs font-mono text-warm-700 bg-warm-50 dark:bg-warm-800/40 rounded-md p-2 border border-accent/40 focus:outline-none focus:border-accent resize-y"}),e.jsxs("div",{className:"mt-1 flex justify-end gap-2",children:[S.name==="svn:externals"&&e.jsx("button",{onClick:()=>m(!1),className:"text-2xs text-warm-400 hover:text-accent mr-auto",children:i("svn.ext.editTable")}),e.jsx(Ze,{size:"sm",onClick:()=>g(null),disabled:j,children:i("svn.cancel")}),e.jsx(Ze,{variant:"primary",size:"sm",onClick:()=>F(S.name),disabled:j,children:i("svn.saveProperty")})]})]}):e.jsx("pre",{className:"mt-1 text-2xs font-mono text-warm-600 bg-warm-50 dark:bg-warm-800/40 rounded-md p-2 whitespace-pre-wrap break-all",children:S.value||"—"})]},S.name))})]}),e.jsx("div",{className:"px-4 py-3 border-t border-warm-100 shrink-0 text-right",children:e.jsx(Ze,{size:"sm",onClick:r,children:i("svn.close")})})]})})}const pc=["architect","developer","reviewer","pm","tester","custom"],Dt=["#6366f1","#8b5cf6","#ec4899","#f43f5e","#f97316","#eab308","#22c55e","#14b8a6","#06b6d4","#3b82f6"],fc=[{name:"Architect",nameKo:"아키텍트",role:"architect",prompt:"You are a senior software architect. Focus on system design, scalability, maintainability, and separation of concerns. Evaluate proposals for architectural soundness and suggest patterns that work well."},{name:"Developer",nameKo:"개발자",role:"developer",prompt:"You are a senior full-stack developer. Focus on implementation feasibility, code quality, existing patterns in the codebase, and developer experience. Be pragmatic about what can realistically be built."},{name:"Reviewer",nameKo:"리뷰어",role:"reviewer",prompt:"You are a senior code reviewer and quality advocate. Focus on edge cases, error handling, security, performance, and testing strategy. Challenge assumptions and find potential issues."},{name:"Product Manager",nameKo:"PM",role:"pm",prompt:"You are a product manager. Focus on user experience, feature scope, priorities, and trade-offs. Ensure the discussion stays grounded in user needs and business value."},{name:"Tester",nameKo:"테스터",role:"tester",prompt:"You are a QA engineer and testing specialist. Focus on testability, test coverage strategy, edge cases, regression risks, and how to verify the feature works correctly."}];function gc({projectId:t,agents:n,onAgentsChange:r}){const{t:i,lang:l}=ye(),[a,c]=s.useState(!1),[x,o]=s.useState(null),[g,f]=s.useState(""),[p,h]=s.useState("developer"),[m,j]=s.useState(""),[D,z]=s.useState(""),[K,F]=s.useState(Dt[0]),[R,S]=s.useState(!1),[H,_]=s.useState(!1),O=()=>{f(""),h("developer"),j(""),z(""),F(Dt[Math.floor(Math.random()*Dt.length)]),S(!1),c(!1),o(null)},X=async()=>{if(!(!g.trim()||!m.trim())){_(!0);try{if(x){const b=await bl(x,{name:g,role:p,system_prompt:m,avatar_color:K,cli_tool:D||null,can_implement:R});r(n.map(v=>v.id===x?b:v))}else{const b=await vl(t,{name:g,role:p,system_prompt:m,avatar_color:K,...D?{cli_tool:D}:{},can_implement:R});r([...n,b])}O()}finally{_(!1)}}},k=b=>{o(b.id),f(b.name),h(b.role),j(b.system_prompt),z(b.cli_tool||""),F(b.avatar_color||Dt[0]),S(!!b.can_implement),c(!0)},se=async b=>{await wl(b),r(n.filter(v=>v.id!==b))},G=b=>{f(l==="ko"?b.nameKo:b.name),h(b.role),j(b.prompt),F(Dt[Math.floor(Math.random()*Dt.length)]),c(!0)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-warm-700",children:i("agents.title")}),e.jsxs("button",{onClick:()=>{O(),c(!0)},className:"btn btn-sm text-xs",children:["+ ",i("agents.add")]})]}),n.length===0&&!a&&e.jsx(At,{icon:_i,title:i("agents.empty"),size:"sm"}),e.jsx("div",{className:"space-y-2",children:n.map(b=>{var v;return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-warm-50 border border-warm-150 hover:border-warm-250 transition-colors group",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-white text-sm font-bold flex-shrink-0 shadow-sm",style:{backgroundColor:b.avatar_color||"#6366f1"},children:b.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",children:b.name}),!!b.can_implement&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-2xs font-medium bg-status-warning/10 text-status-warning border border-status-warning/30",title:i("agents.canImplementHelp"),children:[e.jsx(fn,{size:12}),i("agents.canImplementBadge")]})]}),e.jsxs("div",{className:"text-xs text-warm-400 mt-0.5",children:[i(`agents.roles.${b.role}`)||b.role,b.cli_tool&&e.jsxs("span",{className:"ml-1.5 text-warm-300",children:["· ",((v=bt.find(y=>y.value===b.cli_tool))==null?void 0:v.label)||b.cli_tool]})]})]}),e.jsxs("div",{className:"flex gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:()=>k(b),className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-lg transition-colors",children:e.jsx(Wt,{size:16})}),e.jsx("button",{onClick:()=>se(b.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",children:e.jsx(wt,{size:16})})]})]},b.id)})}),a&&e.jsxs("div",{className:"space-y-5 p-5 rounded-xl border border-warm-200 bg-theme-card shadow-sm",children:[!x&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.presets")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:fc.map(b=>e.jsx(Ze,{size:"sm",onClick:()=>G(b),children:l==="ko"?b.nameKo:b.name},b.role))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.name")}),e.jsx("input",{type:"text",value:g,onChange:b=>f(b.target.value),className:"input-field",placeholder:l==="ko"?"에이전트 이름":"Agent name"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.role")}),e.jsx("select",{value:p,onChange:b=>h(b.target.value),className:"input-field",children:pc.map(b=>e.jsx("option",{value:b,children:i(`agents.roles.${b}`)},b))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.systemPrompt")}),e.jsx("textarea",{value:m,onChange:b=>j(b.target.value),rows:5,className:"input-field resize-y min-h-[100px]",placeholder:l==="ko"?"이 에이전트의 전문 분야와 관점을 설명하세요...":"Describe this agent's expertise and perspective..."}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1.5",children:l==="ko"?"토론 시 이 에이전트가 어떤 관점에서 발언할지 결정합니다.":"Determines what perspective this agent brings to the discussion."})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.cliTool")}),e.jsxs("select",{value:D,onChange:b=>z(b.target.value),className:"input-field text-sm",children:[e.jsx("option",{value:"",children:l==="ko"?"프로젝트 기본값 사용":"Use project default"}),bt.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))]})]})}),e.jsx("div",{children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:R,onChange:b=>S(b.target.checked),className:"mt-0.5 w-4 h-4 rounded-md border-warm-300 text-warm-600 focus:ring-warm-400"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-warm-700",children:[e.jsx(fn,{size:12}),i("agents.canImplement")]}),e.jsx("p",{className:"text-2xs text-warm-400 mt-0.5",children:i("agents.canImplementHelp")})]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.color")}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-white text-sm font-bold flex-shrink-0 shadow-sm",style:{backgroundColor:K},children:g?g.charAt(0).toUpperCase():"?"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Dt.map(b=>e.jsx("button",{onClick:()=>F(b),className:`w-7 h-7 rounded-full transition-all ${K===b?"ring-2 ring-offset-2 ring-warm-400 scale-110":"hover:scale-105 opacity-70 hover:opacity-100"}`,style:{backgroundColor:b}},b))})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2 border-t border-warm-100",children:[e.jsx("button",{onClick:O,className:"btn btn-sm text-xs text-warm-500",children:i("header.cancel")}),e.jsx("button",{onClick:X,disabled:!g.trim()||!m.trim()||H,className:"btn btn-sm btn-primary text-xs",children:i(H?"header.saving":"header.save")})]})]})]})}const bc={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",paused:"bg-status-warning/10 text-status-warning",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",merged:"bg-accent/10 text-accent"};function vc({projectId:t,discussions:n,isGitRepo:r,projectUseWorktree:i,onAddDiscussion:l,onStartDiscussion:a,onStopDiscussion:c,onDeleteDiscussion:x}){const{t:o}=ye(),g=Tr(),[f,p]=s.useState([]),[h,m]=s.useState(!1),[j,D]=s.useState(!1),[z,K]=s.useState(!1),[F,R]=s.useState(null);s.useEffect(()=>{yl(t).then(p).catch(()=>{})},[t]);const S=s.useCallback(async _=>{K(!0);try{const O=await jl(t,_);l(O),m(!1)}finally{K(!1)}},[t,l]),H=_=>{try{return JSON.parse(_).map(X=>f.find(k=>k.id===X)).filter(X=>!!X)}catch{return[]}};return e.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:_=>{$t(_)||(_.preventDefault(),R({x:_.clientX,y:_.clientY}))},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:o("discussions.title")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>D(!j),className:"btn-secondary text-xs py-2",children:o("agents.manage")}),e.jsxs("button",{onClick:()=>m(!h),className:"btn-primary text-xs py-2",children:["+ ",o("discussions.add")]})]})]}),j&&e.jsx("div",{className:"card p-4",children:e.jsx(gc,{projectId:t,agents:f,onAgentsChange:p})}),h&&e.jsx(Nl,{agents:f,projectId:t,mode:"create",submitting:z,isGitRepo:r,projectUseWorktree:i,onSubmit:S,onCancel:()=>m(!1)}),n.length===0&&!h?e.jsx("div",{className:"card",children:e.jsx(At,{icon:ui,title:o("discussions.empty"),description:o("discussions.emptyHint")})}):e.jsx("div",{className:"space-y-3",children:n.map((_,O)=>{const X=H(_.agent_ids),k=_.status==="pending"||_.status==="paused"||_.status==="failed",se=_.status==="running";return e.jsx("div",{className:"card p-4 hover:shadow-md transition-all cursor-pointer",onClick:()=>g(`/projects/${t}/discussions/${_.id}`),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:_.title}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-semibold uppercase ${bc[_.status]||""}`,children:o(`status.${_.status}`)||_.status})]}),e.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:_.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsxs("span",{className:"text-2xs text-warm-400",children:[o("discussions.round")," ",_.current_round,"/",_.max_rounds]}),e.jsx("div",{className:"flex -space-x-1",children:X.slice(0,5).map(G=>e.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-white text-[8px] text-white font-bold flex items-center justify-center",style:{backgroundColor:G.avatar_color||"#6366f1"},title:G.name,children:G.name.charAt(0)},G.id))})]})]}),e.jsxs("div",{className:"flex gap-1",onClick:G=>G.stopPropagation(),children:[k&&e.jsx("button",{onClick:()=>a(_.id),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md transition-colors",title:o("header.runAll"),children:e.jsx(Rt,{size:16})}),se&&e.jsx("button",{onClick:()=>c(_.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:o("discussions.pause"),children:e.jsx(da,{size:16})}),e.jsx("button",{onClick:()=>x(_.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:o("todo.delete"),children:e.jsx(wt,{size:16})})]})]})},_.id)})}),F&&e.jsx(yt,{x:F.x,y:F.y,onClose:()=>R(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>{m(!0)},children:[e.jsx(gt,{size:14}),o("discussions.add")]})})]})}function wc(t){if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.map(String).filter(Boolean):[]}catch{return[]}}function Pn({projectId:t,initial:n,onSave:r,onCancel:i,projectCliTool:l,isGitRepo:a,projectUseWorktree:c}){const{t:x}=ye(),o=!!n,[g,f]=s.useState((n==null?void 0:n.title)??""),[p,h]=s.useState((n==null?void 0:n.description)??""),[m,j]=s.useState((n==null?void 0:n.cliTool)??(l||"")),[D,z]=s.useState((n==null?void 0:n.useWorktree)??!!c),[K,F]=s.useState((n==null?void 0:n.memoryInjectMode)??"none"),[R,S]=s.useState((n==null?void 0:n.memoryRawFilePaths)??[]),[H,_]=s.useState(!1),[O,X]=s.useState((n==null?void 0:n.tagId)??null),[k,se]=s.useState([]),[G,b]=s.useState([]),v=s.useRef(null);s.useEffect(()=>{var ue;Rr(()=>{var me;return(me=v.current)==null?void 0:me.focus()})||(ue=v.current)==null||ue.focus();const Y=Array.from(document.querySelectorAll(".xterm-helper-textarea")),le=Y.map(me=>({el:me,tabIndex:me.tabIndex,ariaHidden:me.getAttribute("aria-hidden")}));return Y.forEach(me=>{me.tabIndex=-1,me.setAttribute("aria-hidden","true"),me.blur()}),()=>{le.forEach(({el:me,tabIndex:pe,ariaHidden:ae})=>{me.tabIndex=pe,ae===null?me.removeAttribute("aria-hidden"):me.setAttribute("aria-hidden",ae)})}},[]),s.useEffect(()=>{let Y=!1;return sa().then(le=>{Y||se(le)}).catch(()=>{}),!o&&a&&$r().then(le=>{Y||z(le.defaultUseWorktree)}).catch(()=>{}),()=>{Y=!0}},[o,a]),s.useEffect(()=>{let Y=!1;return Vs().then(le=>{Y||b(le)}).catch(()=>{}),()=>{Y=!0}},[]);const y=bt.filter(Y=>Y.supportsInteractive),d=Y=>{const le=G.find(ue=>ue.tool===Y.value);return Y.value==="raw-shell"?le!=null&&le.version?`Raw Shell (${le.version})`:Y.label:le&&!le.installed?`${Y.label}${x("session.cliNotInstalled")}`:Y.label},N=(m||l||"claude")==="raw-shell",L=Y=>{Y.preventDefault(),r(g.trim(),p.trim(),m||void 0,D,K,[],R,O)},B=k.find(Y=>Y.id===O)??null;return e.jsxs("form",{onSubmit:L,className:"card p-4 space-y-3",children:[e.jsx("input",{ref:v,type:"text",value:g,onChange:Y=>f(Y.target.value),placeholder:x("session.title"),className:"input-field text-sm"}),!N&&e.jsx("textarea",{value:p,onChange:Y=>h(Y.target.value),placeholder:x("session.description"),className:"input-field text-sm min-h-[60px] max-h-[280px] resize-y [field-sizing:content]",rows:2}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("select",{value:m,onChange:Y=>j(Y.target.value),className:"input-field text-xs flex-1",children:[e.jsxs("option",{value:"",children:[x("session.cliTool")," (Default)"]}),y.map(Y=>e.jsx("option",{value:Y.value,children:d(Y)},Y.value))]})}),k.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[B&&e.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:B.color,borderColor:"rgba(0,0,0,0.08)"}}),e.jsxs("select",{value:O??"",onChange:Y=>X(Y.target.value||null),className:"input-field text-xs flex-1",children:[e.jsx("option",{value:"",children:x("session.tag.none")}),k.map(Y=>e.jsx("option",{value:Y.id,children:Y.name},Y.id))]})]}),a&&e.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-500 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:Y=>z(Y.target.checked),className:"rounded-md border-warm-300"}),e.jsx(xs,{size:14}),x("session.worktree")]}),!N&&e.jsx(ca,{projectId:t,mode:K,selectedPaths:R,includeLinked:H,onChange:(Y,le,ue)=>{F(Y),S(le),_(ue)}}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:i,className:"btn-secondary text-xs py-1.5 px-3",children:x("form.cancel")}),e.jsx("button",{type:"submit",className:"btn-primary text-xs py-1.5 px-3",children:x(o?"session.save":"session.create")})]})]})}function yc(t){if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.map(String).filter(Boolean):[]}catch{return[]}}const jc={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function Nc({projectId:t,sessions:n,projectCliTool:r,isGitRepo:i,projectUseWorktree:l,projectDefaultBranch:a,onAddSession:c,onUpdateSession:x,onStopSession:o,onDeleteSession:g,onCleanupSession:f}){const{t:p}=ye(),{confirm:h}=_t(),{openOrFocus:m,recallPopout:j}=Lr(),D=Fr(),z=zr(),K=s.useMemo(()=>{const w=new Map;for(const te of n){const re=z[te.id];re&&w.set(re,[...w.get(re)??[],te])}const J=new Set,M=[];for(const te of n){if(J.has(te.id))continue;const re=w.get(z[te.id]??"")??[te];re.forEach((we,I)=>{J.add(we.id);const U=re.length===1?"single":I===0?"first":I===re.length-1?"last":"middle";M.push({session:we,position:U})})}return M},[n,z]),[F,R]=s.useState(!1),[S,H]=s.useState(!1),[_,O]=s.useState(null),[X,k]=s.useState(!1),[se,G]=s.useState(null),[b,v]=s.useState([]),[y,d]=s.useState(""),[C,N]=s.useState(null);s.useEffect(()=>{let w=!1;return sa().then(J=>{w||v(J)}).catch(()=>{}),()=>{w=!0}},[]),s.useEffect(()=>{if(!i)return;let w=!1;return Yn(t).then(J=>{w||d(J.branch||"")}).catch(()=>{}),()=>{w=!0}},[t,i]);const L=s.useMemo(()=>{const w=new Map;for(const J of b)w.set(J.id,J);return w},[b]),B=s.useMemo(()=>_?n.find(w=>w.id===_)??null:null,[_,n]),Y=s.useMemo(()=>{if(B)return{title:B.title,description:B.description??"",cliTool:B.cli_tool??"",useWorktree:B.use_worktree===1,memoryInjectMode:B.memory_inject_mode??"none",memoryNodeIds:wc(B.memory_node_ids??null),memoryRawFilePaths:yc(B.memory_raw_file_paths??null),tagId:B.tag_id??null}},[B]),le=s.useCallback(()=>{O(null),G(null),R(w=>!w)},[]),ue=s.useCallback(w=>{R(!1),G(null),O(w)},[]),me=s.useCallback(()=>{R(!1),O(null),G(null)},[]),pe=s.useCallback(async(w,J,M,te,re,we,I,U)=>{H(!0);try{const ce=await Pr(t,{title:w,description:J||void 0,cli_tool:M,use_worktree:te,memory_inject_mode:re,memory_node_ids:we,memory_raw_file_paths:I,tag_id:U??null});c(ce),R(!1)}finally{H(!1)}},[t,c]),ae=s.useCallback(async(w,J,M,te,re,we,I,U)=>{if(_){k(!0),G(null);try{const ce=await Ar(_,{title:w,description:J||void 0,cli_tool:M,use_worktree:te,memory_inject_mode:re,memory_node_ids:we,memory_raw_file_paths:I,tag_id:U??null});x(ce),O(null)}catch(ce){G(ce instanceof Error?ce.message:String(ce))}finally{k(!1)}}},[_,x]);return e.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:w=>{$t(w)||(w.preventDefault(),N({x:w.clientX,y:w.clientY,sessionId:null}))},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:p("tabs.sessions")}),e.jsxs("button",{onClick:le,className:"btn-primary text-xs py-2",disabled:S,children:["+ ",p("session.new")]})]}),F&&e.jsx(Pn,{projectId:t,onSave:pe,onCancel:me,projectCliTool:r,isGitRepo:i,projectUseWorktree:l}),Y&&_&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Pn,{projectId:t,initial:Y,onSave:ae,onCancel:me,projectCliTool:r,isGitRepo:i},_),(X||se)&&e.jsxs("div",{className:"text-xs px-1",children:[X&&e.jsx("span",{className:"text-warm-500",children:p("session.saving")||"saving…"}),se&&e.jsx("span",{className:"text-status-error",children:se})]})]}),n.length===0&&!F?e.jsx("div",{className:"card",children:e.jsx(At,{icon:ln,title:p("session.empty"),description:p("session.emptyHint")})}):e.jsx("div",{className:"space-y-3",children:K.map(({session:w,position:J})=>{const M=["pending","failed","stopped","completed"].includes(w.status),te=w.status==="running",re=w.status!=="running",we=["stopped","failed","completed"].includes(w.status)&&!!w.resumable,I=_===w.id,U=D[w.id]??"closed",ce=U==="popped",$e={single:"",first:"rounded-b-none hover:!translate-y-0",middle:"!mt-0 rounded-none border-t-0 hover:!translate-y-0",last:"!mt-0 rounded-t-none border-t-0 hover:!translate-y-0"}[J];return e.jsx("div",{className:`card overflow-hidden ${$e} ${I?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:Ne=>{$t(Ne)||(Ne.preventDefault(),Ne.stopPropagation(),N({x:Ne.clientX,y:Ne.clientY,sessionId:w.id}))},children:e.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>ce?j(w.id):m(w.id,"open"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[w.tag_id&&L.get(w.tag_id)&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-2xs font-medium",style:{backgroundColor:`${L.get(w.tag_id).color}22`,color:L.get(w.tag_id).color},children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:L.get(w.tag_id).color}}),L.get(w.tag_id).name]}),e.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:w.title}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs font-medium text-warm-500 whitespace-nowrap",children:[e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${jc[w.status]||"bg-warm-400"}`}),p(`status.${w.status}`)||w.status]}),U!=="closed"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:ce?p("session.dock.poppedHint"):void 0,children:[ce?e.jsx(Rs,{size:12}):e.jsx("span",{"aria-hidden":"true",children:"·"}),p(`session.windowState.${U}`)]})]}),w.description&&e.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:w.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-2xs text-warm-300",children:w.cli_tool||"claude"}),(w.branch_name||i&&(y||a))&&e.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[e.jsx(xs,{size:12}),w.branch_name||y||a]})]})]}),e.jsxs("div",{className:"flex gap-1",onClick:Ne=>Ne.stopPropagation(),children:[ce&&e.jsx("button",{onClick:()=>j(w.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:p("session.recallToMain"),children:e.jsx($s,{size:16})}),M&&e.jsx("button",{onClick:()=>m(w.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md transition-colors",title:p("session.start"),children:e.jsx(Rt,{size:16})}),we&&e.jsx("button",{onClick:()=>m(w.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:p("session.resumeHint")||p("session.resume"),children:e.jsx(Vt,{size:16})}),e.jsx("button",{onClick:()=>ue(w.id),disabled:!re,className:"p-1.5 text-warm-500 hover:text-warm-800 hover:bg-warm-100 rounded-md transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-warm-500",title:p(re?"session.edit":"session.editDisabledRunning"),children:e.jsx(on,{size:16})}),te&&e.jsx("button",{onClick:()=>o(w.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:p("session.stop"),children:e.jsx(Kt,{size:16})}),w.status!=="running"&&(!!w.worktree_path||!!w.branch_name)&&e.jsx("button",{onClick:async()=>{const Ne=w.branch_name?await h({message:p("cleanup.confirmDeleteBranch").replace("{name}",w.branch_name),danger:!0}):!1;f(w.id,Ne)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:p("session.cleanup"),children:e.jsx(ls,{size:16})}),e.jsx("button",{onClick:()=>g(w.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:p("session.delete"),children:e.jsx(wt,{size:16})})]})]})})},w.id)})}),C&&(()=>{const w=()=>N(null),J=C.sessionId?n.find(Ne=>Ne.id===C.sessionId):void 0;if(!J)return e.jsx(yt,{x:C.x,y:C.y,onClose:w,children:e.jsxs("button",{type:"button",onClick:()=>{O(null),G(null),R(!0)},className:Be,children:[e.jsx(gt,{size:14}),p("session.new")]})});const M=["pending","failed","stopped","completed"].includes(J.status),te=J.status==="running",re=J.status!=="running",we=["stopped","failed","completed"].includes(J.status)&&!!J.resumable,I=J.status!=="running"&&(!!J.worktree_path||!!J.branch_name),U=D[J.id]??"closed",ce=U==="popped",$e=p(ce?"session.recallToMain":U==="minimized"?"session.restoreWindow":U==="floating"?"session.focusWindow":"session.openWindow");return e.jsxs(yt,{x:C.x,y:C.y,onClose:w,children:[e.jsxs("button",{type:"button",onClick:()=>ce?j(J.id):m(J.id,"open"),className:Be,children:[ce?e.jsx($s,{size:14}):e.jsx(ln,{size:14}),$e]}),M&&e.jsxs("button",{type:"button",onClick:()=>m(J.id,"start"),className:Be,children:[e.jsx(Rt,{size:14}),p("session.start")]}),we&&e.jsxs("button",{type:"button",onClick:()=>m(J.id,"resume"),className:Be,title:p("session.resumeHint")||p("session.resume"),children:[e.jsx(Vt,{size:14}),p("session.resume")]}),re&&e.jsxs("button",{type:"button",onClick:()=>ue(J.id),className:Be,children:[e.jsx(on,{size:14}),p("session.edit")]}),te&&e.jsxs("button",{type:"button",onClick:()=>o(J.id),className:Be,children:[e.jsx(Kt,{size:14}),p("session.stop")]}),I&&e.jsxs("button",{type:"button",onClick:async()=>{const Ne=J.branch_name?await h({message:p("cleanup.confirmDeleteBranch").replace("{name}",J.branch_name),danger:!0}):!1;f(J.id,Ne)},className:Be,children:[e.jsx(ls,{size:14}),p("session.cleanup")]}),e.jsx(Ks,{}),e.jsxs("button",{type:"button",onClick:()=>g(J.id),className:ra,children:[e.jsx(wt,{size:14}),p("session.delete")]})]})})()]})}const ds={default:{bg:"bg-warm-200/50",text:"text-warm-500",swatch:"bg-warm-300"},gray:{bg:"bg-gray-500/20",text:"text-gray-400",swatch:"bg-gray-400"},brown:{bg:"bg-amber-800/20",text:"text-amber-600",swatch:"bg-amber-700"},orange:{bg:"bg-orange-500/20",text:"text-orange-400",swatch:"bg-orange-500"},yellow:{bg:"bg-yellow-500/20",text:"text-yellow-400",swatch:"bg-yellow-500"},green:{bg:"bg-emerald-500/20",text:"text-emerald-400",swatch:"bg-emerald-500"},blue:{bg:"bg-blue-500/20",text:"text-blue-400",swatch:"bg-blue-500"},purple:{bg:"bg-purple-500/20",text:"text-purple-400",swatch:"bg-purple-500"},pink:{bg:"bg-pink-500/20",text:"text-pink-400",swatch:"bg-pink-500"},red:{bg:"bg-red-500/20",text:"text-red-400",swatch:"bg-red-500"}},kc=Object.keys(ds),us={pending:"bg-warm-200 text-warm-500",in_progress:"bg-status-running/10 text-status-running",done:"bg-status-success/10 text-status-success",moved:"bg-status-merged/10 text-status-merged"};function Pt(t){const n=ds[t]||ds.default;return`${n.bg} ${n.text}`}const An={0:{label:"—",style:"text-warm-300"},1:{label:"●",style:"text-warm-500"},2:{label:"●●",style:"text-status-warning"},3:{label:"●●●",style:"text-status-error"}};function Cc({item:t,tagColors:n,existingTags:r,onSave:i,onDelete:l,onConvertToTodo:a,onConvertToSchedule:c,onConvertToSession:x,onUpdateTag:o}){var qe,st;const{t:g}=ye(),{confirm:f}=_t(),[p,h]=s.useState(!1),[m,j]=s.useState(!1),[D,z]=s.useState(!1),K=s.useRef(null),F=s.useRef(null),[R,S]=s.useState({top:0,left:0}),[H,_]=s.useState(t.title),[O,X]=s.useState(t.description??""),[k,se]=s.useState(t.priority),[G,b]=s.useState(t.due_date??""),[v,y]=s.useState(t.status),[d,C]=s.useState(()=>{try{return t.tags?JSON.parse(t.tags):[]}catch{return[]}}),[N,L]=s.useState(""),[B,Y]=s.useState(!1),[le,ue]=s.useState(null),[me,pe]=s.useState(null),ae=s.useRef(null),w=s.useRef(null),[J,M]=s.useState(()=>{try{return t.images?JSON.parse(t.images):[]}catch{return[]}}),te=s.useRef(null);s.useEffect(()=>{_(t.title),X(t.description??""),se(t.priority),b(t.due_date??""),y(t.status);try{C(t.tags?JSON.parse(t.tags):[])}catch{C([])}try{M(t.images?JSON.parse(t.images):[])}catch{M([])}},[t]);const re=d,we=t.status==="moved",I=t.due_date&&new Date(t.due_date)<new Date&&!we&&t.status!=="done",U=s.useCallback(A=>{i(t.id,A)},[t.id,i]),ce=()=>{const A=H.trim();A&&A!==t.title?U({title:A}):_(t.title)},$e=()=>{const A=O.trim();A!==(t.description??"")&&U({description:A||void 0})},Ne=A=>{se(A),A!==t.priority&&U({priority:A})},Me=A=>{b(A),A!==(t.due_date??"")&&U({due_date:A||void 0})},Re=A=>{const he=A;y(he),he!==t.status&&U({status:he})},De=A=>{C(A);const he=(()=>{try{return t.tags?JSON.parse(t.tags):[]}catch{return[]}})();JSON.stringify(A)!==JSON.stringify(he)&&U({tags:A.length>0?JSON.stringify(A):void 0})},Je=A=>{var Ke;const he=A.trim();if(he&&!d.includes(he)&&(De([...d,he]),!n.has(he)&&o)){const _e=["blue","green","orange","purple","pink","red","yellow","brown"],ze=_e[n.size%_e.length];o(he,{color:ze})}L(""),(Ke=ae.current)==null||Ke.focus()},Q=A=>De(d.filter(he=>he!==A)),W=r.filter(A=>!d.includes(A)&&(!N||A.toLowerCase().includes(N.toLowerCase()))),de=s.useCallback(A=>{const he=Array.from(A).filter(ze=>ze.type.startsWith("image/")),Ke=[];let _e=0;for(const ze of he){const Oe=new FileReader;Oe.onload=()=>{Ke.push({name:ze.name,data:Oe.result}),_e++,_e===he.length&&ma(t.id,Ke).then(it=>M(it.images))},Oe.readAsDataURL(ze)}},[t.id]),be=s.useCallback(A=>{var _e;const he=(_e=A.clipboardData)==null?void 0:_e.items;if(!he)return;const Ke=[];for(let ze=0;ze<he.length;ze++)if(he[ze].type.startsWith("image/")){const Oe=he[ze].getAsFile();Oe&&Ke.push(Oe)}Ke.length!==0&&(A.preventDefault(),de(Ke))},[de]),Ie=s.useCallback(A=>{var he;A.preventDefault(),A.stopPropagation(),(he=A.dataTransfer)!=null&&he.files&&de(A.dataTransfer.files)},[de]),He=s.useCallback(A=>{xa(t.id,A).then(()=>{M(he=>he.filter(Ke=>Ke.id!==A))})},[t.id]),Ee=s.useCallback(()=>{if(!K.current)return;const A=K.current.getBoundingClientRect(),he=window.innerWidth,Ke=window.innerHeight;let _e=A.bottom+4;const ze=F.current;if(ze){const Oe=ze.offsetWidth,it=ze.offsetHeight;let q=A.right-Oe;q<8&&(q=8),q+Oe>he-8&&(q=he-8-Oe),_e+it>Ke-8&&(_e=A.top-it-4),S({top:_e,left:q}),z(!0)}else S({top:_e,left:Math.max(8,A.right-180)})},[]);return s.useEffect(()=>{if(!p){z(!1);return}Ee();const A=requestAnimationFrame(Ee),he=Ke=>{var ze,Oe;const _e=Ke.target;(ze=K.current)!=null&&ze.contains(_e)||(Oe=F.current)!=null&&Oe.contains(_e)||h(!1)};return document.addEventListener("mousedown",he),window.addEventListener("scroll",Ee,!0),window.addEventListener("resize",Ee),()=>{cancelAnimationFrame(A),document.removeEventListener("mousedown",he),window.removeEventListener("scroll",Ee,!0),window.removeEventListener("resize",Ee)}},[p,Ee]),e.jsxs("div",{className:`${we?"opacity-50":""}`,style:{borderBottom:"1px solid var(--color-border-muted)"},children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg transition-colors hover:bg-warm-50 cursor-pointer",onDoubleClick:()=>j(!m),children:[e.jsx(St,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${m?"rotate-90":""}`,onClick:A=>{A.stopPropagation(),j(!m)}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium truncate block",style:{color:"var(--color-text-primary)"},children:t.title}),we&&t.converted_type&&e.jsxs("span",{className:"text-2xs text-status-merged",children:["→ ",t.converted_type==="todo"?g("planner.movedToTodo"):t.converted_type==="session"?g("planner.movedToSession"):g("planner.movedToSchedule")]}),t.source_discussion_id&&e.jsxs(na,{to:`/projects/${t.project_id}/discussions/${t.source_discussion_id}`,onClick:A=>A.stopPropagation(),className:"inline-flex items-center gap-1 text-2xs text-accent hover:underline mt-0.5",title:g("planner.fromDiscussion"),children:[e.jsx(xi,{size:12}),g("planner.fromDiscussion")]})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[J.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-md text-[10px] font-medium bg-warm-100 text-warm-500 whitespace-nowrap",children:[e.jsx(Ut,{size:12}),J.length]}),re.map(A=>e.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${Pt(n.get(A)||"default")}`,children:A},A))]}),e.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:e.jsx("span",{className:`text-xs font-medium ${((qe=An[t.priority])==null?void 0:qe.style)??"text-warm-300"}`,children:((st=An[t.priority])==null?void 0:st.label)??"—"})}),e.jsx("div",{className:"hidden md:block w-20 text-right flex-shrink-0",children:t.due_date?e.jsx("span",{className:`text-xs ${I?"text-status-error font-medium":"text-warm-500"}`,children:new Date(t.due_date).toLocaleDateString(void 0,{month:"numeric",day:"numeric"})}):e.jsx("span",{className:"text-xs text-warm-300",children:g("planner.noDueDate")})}),e.jsx("div",{className:"w-16 flex-shrink-0",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${us[t.status]||us.pending}`,children:g(`plannerStatus.${t.status}`)})}),e.jsxs("div",{className:"w-8 flex-shrink-0",children:[e.jsx("button",{ref:K,onClick:A=>{A.stopPropagation(),h(!p)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:e.jsx(Us,{size:14})}),p&&jt.createPortal(e.jsxs("div",{ref:F,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:R.top,left:R.left,opacity:D?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>h(!1),children:[!we&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:a,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(ua,{size:12})," ",g("planner.convertToTask")]}),e.jsxs("button",{onClick:c,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(zt,{size:12})," ",g("planner.convertToSchedule")]}),e.jsxs("button",{onClick:x,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(Bt,{size:12})," ",g("planner.convertToTerminal")]})]}),e.jsxs("button",{onClick:async()=>{await f({message:g("planner.deleteConfirm"),danger:!0})&&l()},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left",children:[e.jsx(wt,{size:12})," ",g("planner.delete")]})]}),document.body)]})]}),m&&e.jsx("div",{className:"px-4 pb-3 pt-1 ml-8",children:e.jsxs("div",{className:"rounded-lg px-4 py-3 space-y-3",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[e.jsx("input",{className:"bg-transparent text-sm font-medium w-full outline-none border-b border-transparent focus:border-warm-300 pb-0.5 transition-colors",style:{color:"var(--color-text-primary)"},value:H,onChange:A=>_(A.target.value),onBlur:ce,onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),ce(),A.target.blur())}}),e.jsx("textarea",{className:"bg-transparent text-sm w-full outline-none border border-transparent focus:border-warm-300 rounded-md p-1 transition-colors min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",style:{color:"var(--color-text-secondary)"},rows:3,placeholder:g("plannerForm.descPlaceholder"),value:O,onChange:A=>X(A.target.value),onPaste:be,onDrop:Ie,onDragOver:A=>{A.preventDefault(),A.stopPropagation()},onBlur:$e}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{var A;return(A=te.current)==null?void 0:A.click()},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[e.jsx(Ut,{size:12}),g("plannerForm.addImage")]}),e.jsx("span",{className:"text-[10px] text-warm-300",children:g("plannerForm.pasteHint")})]}),e.jsx("input",{ref:te,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:A=>{A.target.files&&de(A.target.files),A.target.value=""}}),J.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:J.map(A=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:os(t.id,A.id),alt:A.originalName,onClick:()=>pe(os(t.id,A.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),e.jsx("button",{type:"button",onClick:()=>He(A.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:A.originalName})})]},A.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.tags")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[d.map(A=>e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-2xs font-medium cursor-pointer hover:ring-1 hover:ring-warm-400 transition-all ${Pt(n.get(A)||"default")}`,onClick:he=>{w.current=he.currentTarget,ue(le===A?null:A)},children:[A,e.jsx("button",{onClick:he=>{he.stopPropagation(),Q(A)},className:"opacity-60 hover:opacity-100",children:e.jsx(ft,{size:12})})]}),le===A&&e.jsxs(cs,{anchorRef:w,width:180,onClose:()=>ue(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[e.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:g("plannerTag.color")}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:kc.map(he=>e.jsx("button",{onClick:async()=>{o&&await o(A,{color:he}),ue(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${n.get(A)===he?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:g(`plannerTag.color.${he}`),children:e.jsx("div",{className:`w-5 h-5 rounded-md ${ds[he].swatch}`})},he))})]})]},A)),e.jsxs("div",{className:"relative",children:[e.jsx("input",{ref:ae,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:N,onChange:A=>{L(A.target.value),Y(!0)},onKeyDown:A=>{(A.key==="Enter"||A.key===",")&&N.trim()&&(A.preventDefault(),Je(N.replace(",",""))),A.key==="Backspace"&&!N&&d.length>0&&Q(d[d.length-1])},onFocus:()=>Y(!0),onBlur:()=>setTimeout(()=>Y(!1),150)}),B&&W.length>0&&e.jsx(cs,{anchorRef:ae,width:160,onClose:()=>Y(!1),className:"rounded-lg shadow-elevated z-tooltip py-1 max-h-32 overflow-y-auto",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:W.slice(0,8).map(A=>e.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>Je(A),children:e.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium ${Pt(n.get(A)||"default")}`,children:A})},A))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.priority")}),e.jsxs("select",{className:"input-field text-xs w-full py-1",value:k,onChange:A=>Ne(Number(A.target.value)),children:[e.jsx("option",{value:0,children:g("plannerForm.priorityLow")}),e.jsx("option",{value:1,children:g("plannerForm.priorityNormal")}),e.jsx("option",{value:2,children:g("plannerForm.priorityHigh")}),e.jsx("option",{value:3,children:g("plannerForm.priorityCritical")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.dueDate")}),e.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:G,onChange:A=>Me(A.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.status")}),e.jsxs("select",{className:"input-field text-xs w-full py-1",value:v,onChange:A=>Re(A.target.value),children:[e.jsx("option",{value:"pending",children:g("plannerStatus.pending")}),e.jsx("option",{value:"in_progress",children:g("plannerStatus.in_progress")}),e.jsx("option",{value:"done",children:g("plannerStatus.done")})]})]})]})]})}),me&&e.jsx(ia,{src:me,onClose:()=>pe(null)})]})}let Sc=0;function _c({existingTags:t,editItem:n,initialDueDate:r,onSave:i,onCancel:l,onUpdateTag:a}){const{t:c}=ye(),[x,o]=s.useState(""),[g,f]=s.useState(""),[p,h]=s.useState([]),[m,j]=s.useState(""),[D,z]=s.useState(r??""),[K,F]=s.useState(0),[R,S]=s.useState("pending"),[H,_]=s.useState(!1),[O,X]=s.useState(!1),[k,se]=s.useState([]),[G,b]=s.useState([]),[v,y]=s.useState(null),d=s.useRef(null),C=s.useRef(null),N=s.useRef(null),[L,B]=s.useState(new Map),Y=new Map([...t.map(I=>[I.name,I.color]),...L]),le=["blue","green","orange","purple","pink","red","yellow","brown"];s.useEffect(()=>{var I;if(n){o(n.title),f(n.description??""),h(n.tags?JSON.parse(n.tags):[]),z(n.due_date??""),F(n.priority),S(n.status);try{b(n.images?JSON.parse(n.images):[])}catch{b([])}}(I=d.current)==null||I.focus()},[n]);const ue=t.filter(I=>!p.includes(I.name)&&(!m||I.name.toLowerCase().includes(m.toLowerCase()))),me=I=>{var ce;const U=I.trim();U&&!p.includes(U)&&h($e=>{const Ne=[...$e,U];if(!Y.has(U)){const Me=le[Y.size%le.length];B(Re=>new Map([...Re,[U,Me]]))}return Ne}),j(""),X(!0),(ce=C.current)==null||ce.focus()},pe=I=>h(p.filter(U=>U!==I)),ae=s.useCallback(I=>{const U=Array.from(I).filter(ce=>ce.type.startsWith("image/"));for(const ce of U){const $e=new FileReader;$e.onload=()=>{const Ne=$e.result,Me=`pending-${++Sc}`;se(Re=>[...Re,{id:Me,name:ce.name,data:Ne,preview:Ne}])},$e.readAsDataURL(ce)}},[]),w=s.useCallback(I=>{var $e;const U=($e=I.clipboardData)==null?void 0:$e.items;if(!U)return;const ce=[];for(let Ne=0;Ne<U.length;Ne++)if(U[Ne].type.startsWith("image/")){const Me=U[Ne].getAsFile();Me&&ce.push(Me)}ce.length!==0&&(I.preventDefault(),ae(ce))},[ae]),J=s.useCallback(I=>{var U;I.preventDefault(),I.stopPropagation(),(U=I.dataTransfer)!=null&&U.files&&ae(I.dataTransfer.files)},[ae]),M=I=>se(U=>U.filter(ce=>ce.id!==I)),te=I=>{n&&xa(n.id,I),b(U=>U.filter(ce=>ce.id!==I))},re=G.length+k.length,we=async()=>{if(x.trim()){_(!0);try{const I=await i({title:x.trim(),description:g.trim()||void 0,tags:p.length>0?JSON.stringify(p):void 0,due_date:D||void 0,priority:K,...n?{status:R}:{}});if(a&&L.size>0&&await Promise.all([...L.entries()].map(([U,ce])=>a(U,{color:ce}))),k.length>0){const U=(n==null?void 0:n.id)??(I==null?void 0:I.id);U&&await ma(U,k.map(ce=>({name:ce.name,data:ce.data})))}}finally{_(!1)}}};return e.jsxs("div",{className:"card p-5",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[e.jsx("input",{ref:d,className:"input-field text-sm w-full mb-3",placeholder:c("plannerForm.titlePlaceholder"),value:x,onChange:I=>o(I.target.value),onKeyDown:I=>{I.key==="Enter"&&I.preventDefault()}}),e.jsx("textarea",{className:"input-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:c("plannerForm.descPlaceholder"),value:g,onChange:I=>f(I.target.value),onPaste:w,onDrop:J,onDragOver:I=>{I.preventDefault(),I.stopPropagation()}}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsxs("button",{type:"button",onClick:()=>{var I;return(I=N.current)==null?void 0:I.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[e.jsx(Ut,{size:14}),c("plannerForm.addImage")]}),e.jsx("span",{className:"text-[10px] text-warm-300",children:c("plannerForm.pasteHint")})]}),e.jsx("input",{ref:N,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:I=>{I.target.files&&ae(I.target.files),I.target.value=""}}),re>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:c("plannerForm.images")}),e.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",re,")"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[G.map(I=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:n?os(n.id,I.id):"",alt:I.originalName,onClick:()=>n&&y(os(n.id,I.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),e.jsx("button",{type:"button",onClick:()=>te(I.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:I.originalName})})]},I.id)),k.map(I=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:I.preview,alt:I.name,onClick:()=>y(I.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),e.jsx("button",{type:"button",onClick:()=>M(I.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:I.name})})]},I.id))]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.tags")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 p-2 rounded-xl",style:{backgroundColor:"var(--color-bg-input)",border:"1px solid var(--color-border-strong)"},children:[p.map(I=>e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Pt(Y.get(I)||"default")}`,children:[I,e.jsx("button",{onClick:()=>pe(I),className:"opacity-60 hover:opacity-100",children:e.jsx(ft,{size:12})})]},I)),e.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[e.jsx("input",{ref:C,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:p.length===0?c("plannerForm.tagsPlaceholder"):"",value:m,onChange:I=>{j(I.target.value),X(!0)},onKeyDown:I=>{(I.key==="Enter"||I.key===",")&&m.trim()&&(I.preventDefault(),me(m.replace(",",""))),I.key==="Backspace"&&!m&&p.length>0&&pe(p[p.length-1])},onFocus:()=>X(!0),onBlur:()=>setTimeout(()=>X(!1),150)}),O&&(ue.length>0||m.trim())&&e.jsxs(cs,{anchorRef:C,width:208,onClose:()=>X(!1),className:"rounded-lg shadow-elevated z-tooltip py-1.5 max-h-48 overflow-y-auto",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[ue.slice(0,10).map(I=>e.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>me(I.name),children:e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Pt(I.color)}`,children:I.name})},I.name)),m.trim()&&!t.some(I=>I.name===m.trim())&&e.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>me(m),children:e.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',m.trim(),'"']})})]})]})]})]}),e.jsxs("div",{className:`grid gap-3 mb-4 ${n?"grid-cols-3":"grid-cols-2"}`,children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.dueDate")}),e.jsx("input",{type:"date",className:"input-field text-xs w-full",value:D,onChange:I=>z(I.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.priority")}),e.jsxs("select",{className:"input-field text-xs w-full",value:K,onChange:I=>F(Number(I.target.value)),children:[e.jsx("option",{value:0,children:c("plannerForm.priorityLow")}),e.jsx("option",{value:1,children:c("plannerForm.priorityNormal")}),e.jsx("option",{value:2,children:c("plannerForm.priorityHigh")}),e.jsx("option",{value:3,children:c("plannerForm.priorityCritical")})]})]}),n&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.status")}),e.jsxs("select",{className:"input-field text-xs w-full",value:R,onChange:I=>S(I.target.value),children:[e.jsx("option",{value:"pending",children:c("plannerStatus.pending")}),e.jsx("option",{value:"in_progress",children:c("plannerStatus.in_progress")}),e.jsx("option",{value:"done",children:c("plannerStatus.done")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{className:"btn-ghost text-xs",onClick:l,children:c("plannerForm.cancel")}),e.jsx("button",{className:"btn-primary text-xs py-2",onClick:we,disabled:!x.trim()||H,children:c("plannerForm.save")})]}),v&&e.jsx(ia,{src:v,onClose:()=>y(null)})]})}function Ra({item:t,mode:n,projectCliTool:r,onConvert:i,onClose:l}){const{t:a}=ye(),[c,x]=s.useState(r||"claude"),[o,g]=s.useState(""),[f,p]=s.useState(!1),[h,m]=s.useState("once"),[j,D]=s.useState("0 0 * * *"),[z,K]=s.useState(""),[F,R]=s.useState(!1),S=async()=>{R(!0);try{n==="todo"?await i({cli_tool:c,max_turns:o?Number(o):void 0}):n==="session"?await i({cli_tool:c,use_worktree:f}):await i({cli_tool:c,schedule_type:h,cron_expression:h==="recurring"?j:void 0,run_at:h==="once"?z:void 0})}finally{R(!1)}};return e.jsx(vt,{open:!0,onClose:l,size:"md",position:"top",children:e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"text-sm font-semibold mb-4",style:{color:"var(--color-text-primary)"},children:a(n==="todo"?"plannerConvert.toTask":n==="session"?"plannerConvert.toTerminal":"plannerConvert.toSchedule")}),e.jsxs("p",{className:"text-xs text-warm-500 mb-4 truncate",children:['"',t.title,'"']}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.cliTool")}),e.jsxs("select",{className:"input-field text-xs w-full",value:c,onChange:H=>x(H.target.value),children:[e.jsx("option",{value:"claude",children:"Claude"}),e.jsx("option",{value:"antigravity",children:"Antigravity"}),e.jsx("option",{value:"codex",children:"Codex"})]})]}),n==="todo"&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.maxTurns")}),e.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:o,onChange:H=>g(H.target.value)})]}),n==="session"&&e.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:H=>p(H.target.checked)}),e.jsx("span",{className:"text-xs font-medium text-warm-500",children:a("plannerConvert.useWorktree")})]}),n==="schedule"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.scheduleType")}),e.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[e.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${h==="once"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>m("once"),children:a("plannerConvert.once")}),e.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${h==="recurring"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>m("recurring"),children:a("plannerConvert.recurring")})]})]}),h==="once"?e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.runAt")}),e.jsx("input",{type:"datetime-local",className:"input-field text-xs w-full",value:z,onChange:H=>K(H.target.value)})]}):e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.cronExpression")}),e.jsx("input",{className:"input-field text-xs w-full font-mono",value:j,onChange:H=>D(H.target.value),placeholder:"0 0 * * *"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{className:"btn-ghost text-xs",onClick:l,children:a("plannerConvert.cancel")}),e.jsx("button",{className:"btn-primary btn-sm",onClick:S,disabled:F||n==="schedule"&&h==="once"&&!z,children:a("plannerConvert.convert")})]})]})})}function Mc(t){if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>typeof r=="string"):[]}catch{return[]}}function Dc({view:t,items:n,tagColors:r,onQuickAdd:i,onEditItem:l,onConvert:a,onDeleteItem:c,onUpdateRange:x}){const{t:o,lang:g}=ye(),[f,p]=s.useState(()=>new Date),[h,m]=s.useState(()=>Jt(new Date)),[j,D]=s.useState(null),z=el(),{gridDays:K,cols:F,dimOutOfMonth:R}=tl(t,f),S=Jt(new Date),H=f.getMonth(),_=t==="month"?3:99,O=ae=>p(w=>al(w,t,ae)),X=()=>{p(new Date),m(Jt(new Date))},k=sl(f,t,g);s.useEffect(()=>{t==="day"&&m(Jt(f))},[t,f]);const se=260,G=760,b=s.useRef(null),[v,y]=s.useState(()=>{const ae=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ae)&&ae>=se&&ae<=G?ae:320});s.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(v))}catch{}},[v]);const d=ae=>{ae.preventDefault();const w=M=>{var re;const te=(re=b.current)==null?void 0:re.getBoundingClientRect();te&&y(Math.min(G,Math.max(se,te.right-M.clientX)))},J=()=>{window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",J),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",w),window.addEventListener("pointerup",J)},[C,N]=s.useState(new Map);s.useEffect(()=>{N(new Map)},[n]);const L=s.useMemo(()=>C.size===0?n:n.map(ae=>{const w=C.get(ae.id);return w?{...ae,due_date:w.due_date,end_date:w.end_date}:ae}),[n,C]),B=s.useCallback((ae,w,J)=>{N(M=>new Map(M).set(ae,{due_date:w,end_date:J})),x(ae,w,J)},[x]),Y=ae=>!!(ae.due_date&&ae.end_date&&ae.end_date.slice(0,10)>ae.due_date.slice(0,10)),le=s.useMemo(()=>{const ae=new Map;for(const w of L){if(!w.due_date||t==="month"&&Y(w))continue;const J=w.due_date.slice(0,10),M=w.status==="done",te=ae.get(J)??[];te.push({key:w.id,title:w.title,bg:"var(--color-bg-secondary)",fg:M?"var(--color-text-muted)":"var(--color-text-secondary)",done:M,payload:w,draggable:!0}),ae.set(J,te)}return ae},[L,t]),ue=s.useMemo(()=>t!=="month"?[]:L.filter(Y).map(ae=>{const w=ae.status==="done";return{key:ae.id,title:ae.title,startKey:ae.due_date.slice(0,10),endKey:ae.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:w?"var(--color-text-muted)":"var(--color-text-secondary)",done:w,payload:ae}}),[L,t]),me=s.useMemo(()=>n.filter(ae=>ae.due_date&&ae.due_date.slice(0,10)===h),[n,h]),pe=s.useMemo(()=>n.filter(ae=>!ae.due_date),[n]);return e.jsxs("div",{ref:b,className:"card flex overflow-hidden",style:{minHeight:520},children:[e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[e.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[e.jsx("button",{onClick:()=>O(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:e.jsx(_l,{size:16})}),e.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:k}),e.jsx("button",{onClick:()=>O(1),className:"btn-ghost p-1.5","aria-label":"next",children:e.jsx(St,{size:16})}),e.jsx("button",{onClick:X,className:"btn-ghost text-xs px-2.5 py-1.5",children:o("agenda.today")})]}),e.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:e.jsx(nl,{view:t,gridDays:K,cols:F,dimOutOfMonth:R,monthIdx:H,todayKey:S,selectedDate:h,chipsByDay:le,maxChips:_,weekdayLabels:z,addItemLabel:o("agenda.addItem"),onSelectDate:m,onQuickAdd:i,onChipClick:ae=>l(ae.payload),onCellContextMenu:(ae,w)=>{w.preventDefault(),D({x:w.clientX,y:w.clientY,dateKey:ae})},bars:ue,onBarClick:ae=>l(ae.payload),onBarDrag:(ae,w,J)=>B(ae.payload.id,w,J),onChipDrag:(ae,w,J)=>B(ae.payload.id,w,J)})})]}),e.jsx("div",{onPointerDown:d,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:o("agenda.resizePanel")}),e.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:v},children:[e.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--color-text-primary)"},children:new Date(h+"T00:00").toLocaleDateString(g,{month:"long",day:"numeric",weekday:"short"})}),e.jsxs("button",{onClick:()=>i(h),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[e.jsx(gt,{size:14}),o("agenda.add")]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[me.length===0&&e.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:o("agenda.dayEmpty")}),me.map(ae=>e.jsx(In,{item:ae,tagColors:r,onEdit:l,onConvert:a,onDelete:c},ae.id))]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:o("agenda.backlog")}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[pe.length===0&&e.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:o("agenda.backlogEmpty")}),pe.map(ae=>e.jsx(In,{item:ae,tagColors:r,onEdit:l,onConvert:a,onDelete:c},ae.id))]})]})]})]}),j&&e.jsx(yt,{x:j.x,y:j.y,onClose:()=>D(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>i(j.dateKey),children:[e.jsx(gt,{size:14}),o("planner.add")]})})]})}function In({item:t,tagColors:n,onEdit:r,onConvert:i,onDelete:l}){const{t:a}=ye(),{confirm:c}=_t(),[x,o]=s.useState(!1),[g,f]=s.useState(!1),[p,h]=s.useState({top:0,left:0}),m=s.useRef(null),j=s.useRef(null),D=Mc(t.tags),z=t.status==="moved",K=s.useCallback(()=>{if(!m.current)return;const F=m.current.getBoundingClientRect(),R=window.innerWidth,S=window.innerHeight;let H=F.bottom+4;const _=j.current;if(_){const O=_.offsetWidth,X=_.offsetHeight;let k=F.right-O;k<8&&(k=8),k+O>R-8&&(k=R-8-O),H+X>S-8&&(H=F.top-X-4),h({top:H,left:k}),f(!0)}else h({top:H,left:Math.max(8,F.right-180)})},[]);return s.useEffect(()=>{if(!x){f(!1);return}K();const F=requestAnimationFrame(K),R=S=>{var _,O;const H=S.target;(_=m.current)!=null&&_.contains(H)||(O=j.current)!=null&&O.contains(H)||o(!1)};return document.addEventListener("mousedown",R),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{cancelAnimationFrame(F),document.removeEventListener("mousedown",R),window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[x,K]),e.jsxs("div",{className:`group flex items-start gap-2 rounded-lg px-2.5 py-2 ${z?"opacity-50":""}`,style:{backgroundColor:"var(--color-bg-secondary)"},children:[e.jsxs("button",{onClick:()=>r(t),className:"flex-1 text-left min-w-0",children:[e.jsx("div",{className:"text-sm truncate",style:{color:"var(--color-text-primary)",textDecoration:t.status==="done"?"line-through":"none"},children:t.title}),t.description&&e.jsx("div",{className:"text-2xs truncate",style:{color:"var(--color-text-muted)"},children:t.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-2xs font-medium ${us[t.status]||us.pending}`,children:a(`plannerStatus.${t.status}`)}),D.map(F=>e.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Pt(n.get(F)||"default")}`,children:F},F))]})]}),e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx("button",{ref:m,onClick:F=>{F.stopPropagation(),o(!x)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors opacity-0 group-hover:opacity-100",children:e.jsx(Us,{size:14})}),x&&jt.createPortal(e.jsxs("div",{ref:j,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:p.top,left:p.left,opacity:g?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>o(!1),children:[!z&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>i(t,"todo"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(ua,{size:12})," ",a("planner.convertToTask")]}),e.jsxs("button",{onClick:()=>i(t,"schedule"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(zt,{size:12})," ",a("planner.convertToSchedule")]}),e.jsxs("button",{onClick:()=>i(t,"session"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(Bt,{size:12})," ",a("planner.convertToTerminal")]})]}),e.jsxs("button",{onClick:async()=>{await c({message:a("planner.deleteConfirm"),danger:!0})&&l(t.id)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left",children:[e.jsx(wt,{size:12})," ",a("planner.delete")]})]}),document.body)]})]})}const Hn={pending:0,in_progress:1,done:2,moved:3};function Ec({plannerItems:t,existingTags:n,projectCliTool:r,onAddItem:i,onEditItem:l,onDeleteItem:a,onConvertToTodo:c,onConvertToSchedule:x,onConvertToSession:o,onUpdateTag:g,onDeleteTag:f,onExport:p,onImport:h,view:m,onChangeView:j}){const{t:D}=ye(),{warning:z}=aa(),[K,F]=s.useState(!1),[R,S]=s.useState(null),[H,_]=s.useState(void 0),[O,X]=s.useState(""),[k,se]=s.useState(""),[G,b]=s.useState("created_at"),[v,y]=s.useState("desc"),[d,C]=s.useState(null),[N,L]=s.useState("todo"),[B,Y]=s.useState(!1),[le,ue]=s.useState(!1),[me,pe]=s.useState(null),ae=s.useRef(null),w=s.useRef(0),J=async()=>{if(!(!p||B)){Y(!0);try{await p()}finally{Y(!1)}}},M=()=>{var Q;!h||B||(Q=ae.current)==null||Q.click()},te=async Q=>{var de;const W=(de=Q.target.files)==null?void 0:de[0];if(Q.target.value="",!(!W||!h)){Y(!0);try{await h(W)}finally{Y(!1)}}},re=Q=>!!(/\.(md|markdown)$/i.test(Q.name)||Q.type==="text/markdown"),we=Q=>Array.from(Q.dataTransfer.types).includes("Files"),I=Q=>{!h||B||we(Q)&&(Q.preventDefault(),w.current++,ue(!0))},U=Q=>{!h||B||we(Q)&&(Q.preventDefault(),Q.dataTransfer.dropEffect="copy")},ce=Q=>{h&&(Q.preventDefault(),w.current=Math.max(0,w.current-1),w.current===0&&ue(!1))},$e=async Q=>{var de;if(!h||(Q.preventDefault(),w.current=0,ue(!1),B))return;const W=(de=Q.dataTransfer.files)==null?void 0:de[0];if(W){if(!re(W)){z(D("planner.dropInvalidFile"));return}Y(!0);try{await h(W)}finally{Y(!1)}}},Ne=s.useMemo(()=>n.map(Q=>Q.name),[n]),Me=s.useMemo(()=>new Map(n.map(Q=>[Q.name,Q.color])),[n]),Re=s.useMemo(()=>{let Q=t.filter(W=>!(k&&W.status!==k||O&&!(W.tags?(()=>{try{return JSON.parse(W.tags)}catch{return[]}})():[]).includes(O)));return Q=[...Q].sort((W,de)=>{let be=0;switch(G){case"title":be=W.title.localeCompare(de.title);break;case"tags":{const Ie=W.tags?(()=>{try{return JSON.parse(W.tags).join(",")}catch{return""}})():"",He=de.tags?(()=>{try{return JSON.parse(de.tags).join(",")}catch{return""}})():"";be=(Ie||"zzz").localeCompare(He||"zzz");break}case"priority":be=W.priority-de.priority;break;case"due_date":{const Ie=W.due_date||"9999",He=de.due_date||"9999";be=Ie.localeCompare(He);break}case"status":be=(Hn[W.status]??9)-(Hn[de.status]??9);break;case"created_at":be=W.created_at.localeCompare(de.created_at);break}return v==="asc"?be:-be}),Q},[t,O,k,G,v]),De=Q=>{G===Q?y(W=>W==="asc"?"desc":"asc"):(b(Q),y(Q==="priority"?"desc":"asc"))},Je=({field:Q})=>G!==Q?null:v==="asc"?e.jsx(Pl,{size:12,className:"inline ml-0.5"}):e.jsx(El,{size:12,className:"inline ml-0.5"});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-5 gap-3 flex-wrap",children:[e.jsxs("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:[D("planner.title"),e.jsx("span",{className:"ml-1 text-warm-400",children:t.length})]}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[m!=="table"&&e.jsx("div",{className:"flex gap-0.5 p-0.5 rounded-lg shrink-0",style:{backgroundColor:"var(--color-bg-tertiary)"},children:["month","week","day"].map(Q=>e.jsx("button",{onClick:()=>j(Q),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:m===Q?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:D(`agenda.view.${Q}`)},Q))}),e.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:O,onChange:Q=>X(Q.target.value),children:[e.jsx("option",{value:"",children:D("planner.filterTag")}),Ne.map(Q=>e.jsx("option",{value:Q,children:Q},Q))]}),e.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:k,onChange:Q=>se(Q.target.value),children:[e.jsx("option",{value:"",children:D("planner.filterStatus")}),e.jsx("option",{value:"pending",children:D("plannerStatus.pending")}),e.jsx("option",{value:"in_progress",children:D("plannerStatus.in_progress")}),e.jsx("option",{value:"done",children:D("plannerStatus.done")}),e.jsx("option",{value:"moved",children:D("plannerStatus.moved")})]}),p&&e.jsxs("button",{onClick:J,disabled:B||t.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:D("planner.exportTooltip"),children:[e.jsx(la,{size:14,className:"inline-block shrink-0"}),D("planner.export")]}),h&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:M,disabled:B,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:D("planner.importTooltip"),children:[e.jsx(vn,{size:14,className:"inline-block shrink-0"}),D("planner.import")]}),e.jsx("input",{ref:ae,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:te})]}),!K&&!R&&e.jsxs("button",{onClick:()=>F(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[e.jsx(gt,{size:14,className:"inline-block shrink-0"}),D("planner.add")]})]})]}),(K||R)&&e.jsx("div",{className:"mb-5",children:e.jsx(_c,{existingTags:n,editItem:R,initialDueDate:H,onSave:async Q=>{if(R){await l(R.id,Q),S(null);return}else{const W=await i(Q);return F(!1),_(void 0),W}},onCancel:()=>{F(!1),S(null),_(void 0)},onUpdateTag:g})}),m==="table"?e.jsxs("div",{className:"card relative",onDragEnter:h?I:void 0,onDragOver:h?U:void 0,onDragLeave:h?ce:void 0,onDrop:h?$e:void 0,onContextMenu:Q=>{$t(Q)||(Q.preventDefault(),pe({x:Q.clientX,y:Q.clientY}))},children:[le&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center pointer-events-none rounded-xl border-2 border-dashed",style:{borderColor:"var(--color-accent, #3b82f6)",backgroundColor:"var(--color-bg-secondary, rgba(59, 130, 246, 0.08))",backdropFilter:"blur(2px)"},children:e.jsxs("div",{className:"text-center",children:[e.jsx(vn,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),e.jsx("div",{className:"text-sm font-semibold",children:D("planner.dropHint")}),e.jsx("div",{className:"text-xs text-warm-500 mt-1",children:D("planner.dropHintSub")})]})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-3 px-4 py-2 rounded-t-xl select-none",style:{backgroundColor:"var(--color-bg-tertiary)",borderBottom:"1px solid var(--color-border-muted)"},children:[e.jsx("div",{className:"w-[14px] flex-shrink-0"}),e.jsxs("div",{className:"flex-1 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("title"),children:[D("planner.col.title"),e.jsx(Je,{field:"title"})]}),e.jsxs("div",{className:"w-[160px] section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("tags"),children:[D("planner.col.tags"),e.jsx(Je,{field:"tags"})]}),e.jsxs("div",{className:"w-12 text-center section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("priority"),children:[D("plannerForm.priority"),e.jsx(Je,{field:"priority"})]}),e.jsxs("div",{className:"hidden md:block w-20 text-right section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("due_date"),children:[D("planner.col.dueDate"),e.jsx(Je,{field:"due_date"})]}),e.jsxs("div",{className:"w-16 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("status"),children:[D("planner.col.status"),e.jsx(Je,{field:"status"})]}),e.jsx("div",{className:"w-8"})]}),Re.length===0?e.jsx(At,{icon:oi,title:D("planner.empty"),description:D("planner.emptyHint")}):Re.map((Q,W)=>e.jsx("div",{children:e.jsx(Cc,{item:Q,tagColors:Me,existingTags:Ne,onSave:async(de,be)=>{await l(de,be)},onDelete:()=>a(Q.id),onConvertToTodo:()=>{C(Q),L("todo")},onConvertToSchedule:()=>{C(Q),L("schedule")},onConvertToSession:()=>{C(Q),L("session")},onUpdateTag:g})},Q.id))]}):e.jsx(Dc,{view:m,items:Re,tagColors:Me,onQuickAdd:Q=>{S(null),_(Q),F(!0)},onEditItem:Q=>{F(!1),S(Q)},onConvert:(Q,W)=>{C(Q),L(W)},onDeleteItem:a,onUpdateRange:(Q,W,de)=>{l(Q,{due_date:W,end_date:de})}}),d&&e.jsx(Ra,{item:d,mode:N,projectCliTool:r,onConvert:async Q=>{N==="todo"?await c(d.id,Q):N==="session"?await o(d.id,Q):await x(d.id,Q),C(null)},onClose:()=>C(null)}),me&&e.jsx(yt,{x:me.x,y:me.y,onClose:()=>pe(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>{S(null),_(void 0),F(!0)},children:[e.jsx(gt,{size:14}),D("planner.add")]})})]})}const $a=s.createContext(null),Tc=$a.Provider;function td(){const t=s.useContext($a);if(!t)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return t}const Rc=s.lazy(()=>hs(()=>import("./PlannerPageEditor-DPXI3Zfq.js").then(t=>t.a),__vite__mapDeps([13,1,2,5,14,15,11,16]))),$c=800;function Lc({pageId:t,projectId:n,projectCliTool:r,existingTags:i,onTitleChange:l,onConvertToTodo:a,onConvertToSchedule:c,onConvertToSession:x}){const{t:o}=ye(),[g,f]=s.useState(null),[p,h]=s.useState("idle"),[m,j]=s.useState(null),D=s.useRef({title:"",content:null}),z=s.useRef(null);s.useEffect(()=>{let _=!1;return Ki(t).then(O=>{_||(f(O),D.current={title:O.title,content:O.content??null})}),()=>{_=!0}},[t]);const K=s.useCallback(()=>{z.current&&(clearTimeout(z.current),z.current=null);const{title:_,content:O}=D.current;return h("saving"),Ui(t,{title:_,content:O??void 0}).then(()=>h("saved"))},[t]);s.useEffect(()=>()=>{z.current&&K()},[K]);const F=s.useCallback(()=>{z.current&&clearTimeout(z.current),h("saving"),z.current=setTimeout(()=>{K()},$c)},[K]),R=_=>{D.current.title=_,f(O=>O&&{...O,title:_}),l(t,_),F()},S=_=>{D.current.content=_,F()},H=s.useCallback((_,O,X)=>{j({item:_,mode:O,onDone:X})},[]);return g?e.jsxs(Tc,{value:{projectId:n,pageId:t,projectCliTool:r,existingTags:i,openConvert:H},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[e.jsx("input",{value:g.title,onChange:_=>R(_.target.value),placeholder:o("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),e.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:p==="saving"?o("planner.pages.saving"):p==="saved"?o("planner.pages.saved"):""})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:e.jsx(s.Suspense,{fallback:null,children:e.jsx(Rc,{pageId:t,initialContent:g.content??null,onChange:S})})})]}),m&&e.jsx(Ra,{item:m.item,mode:m.mode,projectCliTool:r,onConvert:async _=>{const{item:O,mode:X,onDone:k}=m;X==="todo"?await a(O.id,_):X==="session"?await x(O.id,_):await c(O.id,_),k==null||k(),j(null)},onClose:()=>j(null)})]}):null}const dt=(t,n)=>({type:"heading",props:{level:t},content:n}),Ot=t=>t?{type:"paragraph",content:t}:{type:"paragraph"},On=t=>t?{type:"bulletListItem",content:t}:{type:"bulletListItem"},Et=t=>t?{type:"checkListItem",content:t}:{type:"checkListItem"},Wn=()=>({type:"tasklist"}),Bn=()=>({type:"calendar"}),Fc=[{id:"blank",labelKey:"planner.tpl.blank",descKey:"planner.tpl.blank.desc",title:"",blocks:null},{id:"meeting",labelKey:"planner.tpl.meeting",descKey:"planner.tpl.meeting.desc",title:"회의 노트",blocks:[dt(1,"회의 노트"),Ot("날짜: "),Ot("참석자: "),dt(2,"안건"),On(),dt(2,"논의"),Ot(),dt(2,"액션 아이템"),Wn()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[dt(1,"프로젝트 플랜"),dt(2,"개요"),Ot(),dt(2,"마일스톤"),Wn(),dt(2,"일정"),Bn(),dt(2,"리스크 / 메모"),Ot()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[dt(1,"위클리 플래너"),dt(2,"이번 주 목표"),On(),dt(2,"요일별 할 일"),dt(3,"월요일"),Et(),dt(3,"화요일"),Et(),dt(3,"수요일"),Et(),dt(3,"목요일"),Et(),dt(3,"금요일"),Et(),dt(3,"토요일"),Et(),dt(3,"일요일"),Et(),dt(2,"주간 일정"),Bn()]}];function zc({onResize:t}){return e.jsx("div",{role:"separator","aria-orientation":"vertical",onPointerDown:n=>{n.preventDefault();const r=n.currentTarget;r.setPointerCapture(n.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none";let i=null,l=null;const a=()=>{if(i=null,l===null)return;const o=l;l=null,t(o)},c=o=>{l=o.clientX,i===null&&(i=requestAnimationFrame(a))},x=o=>{i!==null&&cancelAnimationFrame(i),i=null,o.type==="pointerup"&&l!==null&&a(),l=null,document.body.style.cursor="",document.body.style.userSelect="",r.removeEventListener("pointermove",c),r.removeEventListener("pointerup",x),r.removeEventListener("pointercancel",x)};r.addEventListener("pointermove",c),r.addEventListener("pointerup",x),r.addEventListener("pointercancel",x)},className:"w-1.5 shrink-0 cursor-col-resize bg-warm-300 hover:bg-accent active:bg-accent transition-colors"})}const Kn=160,Un=480,Vn="plannerSidebarWidth",Gn="plannerSidebarCollapsed";function Pc({projectId:t,...n}){const{t:r}=ye(),{confirm:i}=_t(),[l,a]=s.useState([]),[c,x]=s.useState({kind:"work"}),[o,g]=s.useState("table"),[f,p]=s.useState(!1),[h,m]=s.useState({top:0,left:0}),j=s.useRef(null),D=s.useRef(null),z=s.useRef(!1),[K,F]=s.useState(()=>{const L=Number(localStorage.getItem(Vn));return L>=Kn&&L<=Un?L:208}),R=s.useCallback(L=>{var le;const B=((le=D.current)==null?void 0:le.getBoundingClientRect().left)??0,Y=Math.round(Math.max(Kn,Math.min(Un,L-B)));F(Y),localStorage.setItem(Vn,String(Y))},[]),[S,H]=s.useState(()=>localStorage.getItem(Gn)==="1"),_=()=>H(L=>(localStorage.setItem(Gn,L?"0":"1"),!L)),O=240,X=()=>{var B;const L=(B=j.current)==null?void 0:B.getBoundingClientRect();if(L){const Y=Math.min(L.left,window.innerWidth-O-8);m({top:L.bottom+4,left:Math.max(8,Y)})}p(!0)};s.useEffect(()=>{if(!f)return;const L=()=>p(!1),B=Y=>{var le;(le=j.current)!=null&&le.contains(Y.target)||Y.target.closest("[data-template-picker]")||p(!1)};return document.addEventListener("mousedown",B),window.addEventListener("scroll",L,!0),window.addEventListener("resize",L),()=>{document.removeEventListener("mousedown",B),window.removeEventListener("scroll",L,!0),window.removeEventListener("resize",L)}},[f]),s.useEffect(()=>{Wi(t).then(L=>{a(L),z.current||(z.current=!0,L.length>0&&x({kind:"page",id:L[0].id}))})},[t]);const k=async L=>{p(!1);const B=await Bi(t,L.title||r("planner.pages.untitled"),L.blocks?JSON.stringify(L.blocks):void 0);a(Y=>[...Y,B]),x({kind:"page",id:B.id})},se=async L=>{await i({message:r("planner.pages.deleteConfirm"),danger:!0})&&(await Vi(L),a(B=>B.filter(Y=>Y.id!==L)),x(B=>B.kind==="page"&&B.id===L?{kind:"work"}:B))},G=s.useCallback((L,B)=>{a(Y=>Y.map(le=>le.id===L?{...le,title:B}:le))},[]),b=()=>{x({kind:"work"}),g(L=>L==="table"?"month":L)},v=()=>{x({kind:"work"}),g("table")},y=c.kind==="work",d=y&&o!=="table",C=y&&o==="table",N=(L,B,Y,le,ue)=>e.jsxs("div",{onClick:B,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${L?"":"hover:bg-warm-50"}`,style:L?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[Y,e.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:le}),ue]});return e.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[S?e.jsx("div",{className:"flex-shrink-0 flex flex-col items-center card p-1.5",children:e.jsx("button",{onClick:_,className:"p-1 text-warm-400 hover:text-warm-600 transition-colors",title:r("sidebar.expand"),children:e.jsx(Ir,{size:14})})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:D,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:K},children:[e.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[e.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:r("planner.view.pages")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{ref:j,onClick:()=>f?p(!1):X(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:r("planner.pages.new"),children:e.jsx(gt,{size:14})}),e.jsx("button",{onClick:_,className:"text-warm-400 hover:text-warm-600 transition-colors",title:r("sidebar.collapse"),children:e.jsx(Hr,{size:14})})]})]}),l.map(L=>N(c.kind==="page"&&c.id===L.id,()=>x({kind:"page",id:L.id}),e.jsx(ss,{size:14,className:"text-warm-400 flex-shrink-0"}),L.title||r("planner.pages.untitled"),e.jsx("button",{onClick:B=>{B.stopPropagation(),se(L.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-status-error transition-all flex-shrink-0",children:e.jsx(wt,{size:14})}))),e.jsx("div",{className:"px-2.5 pt-3 pb-1 text-2xs font-semibold uppercase tracking-wider text-warm-400",children:r("planner.view.all")}),N(d,b,e.jsx(zs,{size:14,className:"text-warm-400 flex-shrink-0"}),r("planner.nav.calendar")),N(C,v,e.jsx(is,{size:14,className:"text-warm-400 flex-shrink-0"}),r("planner.nav.list"))]}),e.jsx(zc,{onResize:R})]}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:c.kind==="page"?e.jsx("div",{className:"card flex flex-col flex-1",children:e.jsx(Lc,{pageId:c.id,projectId:t,projectCliTool:n.projectCliTool,existingTags:n.existingTags,onTitleChange:G,onConvertToTodo:n.onConvertToTodo,onConvertToSchedule:n.onConvertToSchedule,onConvertToSession:n.onConvertToSession},c.id)}):e.jsx(Ec,{...n,view:o,onChangeView:g})}),f&&jt.createPortal(e.jsx("div",{"data-template-picker":!0,className:"fixed z-tooltip rounded-xl py-1 shadow-elevated",style:{top:h.top,left:h.left,width:O,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:Fc.map(L=>e.jsxs("button",{onClick:()=>k(L),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[e.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:r(L.labelKey)}),e.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:r(L.descKey)})]},L.id))}),document.body)]})}const La="webPanelTabs",Fa="webPanelFavorites",Ac="plannerWebPanelUrl",Ys="https://www.notion.so",Ic="electronAPI"in window;function Hc(t){const n=t.trim();return n?/^https?:\/\//i.test(n)?n:`https://${n}`:Ys}function Os(t=""){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,8),src:t,url:t,title:""}}function Oc(){var n;try{const r=JSON.parse(localStorage.getItem(La)||"");if((n=r.tabs)!=null&&n.length){const i=r.tabs.map(({id:a,url:c})=>({id:a,src:c,url:c,title:""})),l=i.some(a=>a.id===r.activeId)?r.activeId:i[0].id;return{tabs:i,activeId:l}}}catch{}const t=Os(localStorage.getItem(Ac)||Ys);return{tabs:[t],activeId:t.id}}function Wc(){try{const t=JSON.parse(localStorage.getItem(Fa)||"");return Array.isArray(t)?t:[]}catch{return[]}}function Bc({visible:t=!0}={}){const{t:n}=ye(),[{tabs:r,activeId:i},l]=s.useState(Oc),a=r.find(v=>v.id===i)??r[0],[c,x]=s.useState(()=>new Set);s.useEffect(()=>{t&&x(v=>v.has(a.id)?v:new Set(v).add(a.id))},[t,a.id]);const[o,g]=s.useState(a.url),[f,p]=s.useState(Wc),[h,m]=s.useState(!1),[j,D]=s.useState(!1),z=h&&j,K=s.useRef(null),F=s.useRef(null),R=s.useRef(new Map);s.useEffect(()=>{localStorage.setItem(La,JSON.stringify({tabs:r.map(({id:v,url:y})=>({id:v,url:y})),activeId:i}))},[r,i]),s.useEffect(()=>{localStorage.setItem(Fa,JSON.stringify(f))},[f]),s.useEffect(()=>{g(a.url)},[a.id,a.url]);const S=s.useCallback((v,y)=>{l(d=>({...d,tabs:d.tabs.map(C=>C.id===v?{...C,...y}:C)}))},[]),H=s.useCallback((v="")=>{var d;const y=Os(v);l(C=>({tabs:[...C.tabs,y],activeId:y.id})),v||(d=K.current)==null||d.focus()},[]),_=v=>{l(y=>{const d=y.tabs.findIndex(N=>N.id===v),C=y.tabs.filter(N=>N.id!==v);if(C.length===0){const N=Os();return{tabs:[N],activeId:N.id}}return y.activeId!==v?{...y,tabs:C}:{tabs:C,activeId:C[Math.min(d,C.length-1)].id}})},O=()=>{const v=Hc(o);g(v),S(a.id,{src:v,url:v})};s.useEffect(()=>{var y;const v=window.electronAPI;return(y=v==null?void 0:v.onWebPanelOpenUrl)==null?void 0:y.call(v,d=>H(d))},[H]),s.useEffect(()=>{const v=F.current;if(!v)return;const y=()=>{v.style.pointerEvents="none"},d=()=>{v.style.pointerEvents=""};return window.addEventListener("mousedown",y,!0),window.addEventListener("mouseup",d,!0),window.addEventListener("blur",d),()=>{window.removeEventListener("mousedown",y,!0),window.removeEventListener("mouseup",d,!0),window.removeEventListener("blur",d)}},[]);const X=s.useCallback(v=>{if(!v)return;const y=v,d=v.dataset.tabId;R.current.set(d,y);const C=L=>S(d,{title:L.title}),N=L=>{const{url:B,isMainFrame:Y}=L;Y!==!1&&S(d,{url:B,canGoBack:y.canGoBack()})};return v.addEventListener("page-title-updated",C),v.addEventListener("did-navigate",N),v.addEventListener("did-navigate-in-page",N),()=>{R.current.delete(d),v.removeEventListener("page-title-updated",C),v.removeEventListener("did-navigate",N),v.removeEventListener("did-navigate-in-page",N)}},[S]),k=v=>{if(v.title)return v.title;try{return new URL(v.url).hostname}catch{return n("web.newTab")}},se=f.some(v=>v.url===a.url),G=()=>{a.url&&p(v=>se?v.filter(y=>y.url!==a.url):[...v,{url:a.url,title:k(a)}])},b=v=>p(y=>y.filter(d=>d.url!==v));return e.jsxs("div",{className:h?"fixed inset-0 z-modal flex flex-col":"flex flex-col flex-1 min-h-0",style:h?{backgroundColor:"var(--color-bg-card)"}:void 0,onKeyDown:v=>{(v.ctrlKey||v.metaKey)&&!v.altKey&&!v.shiftKey&&v.key.toLowerCase()==="t"&&(v.preventDefault(),H())},children:[e.jsxs("div",{role:"tablist",className:`${z?"hidden":"flex"} items-end gap-0.5 px-2 border-b border-theme-border overflow-x-auto`,children:[r.map(v=>e.jsxs("div",{role:"tab","aria-selected":v.id===i,onClick:()=>l(y=>({...y,activeId:v.id})),onMouseDown:y=>{y.button===1&&y.preventDefault()},onAuxClick:y=>{y.button===1&&(y.preventDefault(),_(v.id))},className:`flex items-center gap-1 px-3 py-1.5 text-xs whitespace-nowrap cursor-pointer transition-colors ${v.id===i?"border-b-2 border-accent text-accent font-medium":"text-theme-text-secondary hover:text-theme-text"}`,children:[e.jsx("span",{className:"truncate max-w-[160px]",children:k(v)}),e.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),_(v.id)},className:"p-0.5 rounded hover:bg-theme-hover",title:n("web.closeTab"),"aria-label":n("web.closeTab"),children:e.jsx(ft,{size:12})})]},v.id)),e.jsx("button",{type:"button",onClick:()=>H(),className:"p-1 mb-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:n("web.newTab"),"aria-label":n("web.newTab"),children:e.jsx(gt,{size:14})})]}),e.jsxs("form",{onSubmit:v=>{v.preventDefault(),O()},className:`${z?"hidden":"flex"} items-center gap-2 p-2 border-b border-theme-border`,children:[e.jsx("button",{type:"button",onClick:()=>{var v;return(v=R.current.get(a.id))==null?void 0:v.goBack()},disabled:!a.canGoBack,className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0 disabled:opacity-40 disabled:pointer-events-none",title:n("web.back"),"aria-label":n("web.back"),children:e.jsx(Ll,{size:14})}),e.jsx("input",{ref:K,value:o,onChange:v=>g(v.target.value),placeholder:n("web.urlPlaceholder"),className:"input-field flex-1",spellCheck:!1}),e.jsx("button",{type:"button",onClick:G,disabled:!a.url,"aria-pressed":se,className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0 disabled:opacity-40 disabled:pointer-events-none",title:n(se?"web.removeFavorite":"web.addFavorite"),"aria-label":n(se?"web.removeFavorite":"web.addFavorite"),children:e.jsx(ji,{size:14,fill:se?"currentColor":"none",className:se?"text-accent":void 0})}),e.jsx("button",{type:"button",onClick:()=>window.open(a.url,"_blank","noopener"),disabled:!a.url,className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0 disabled:opacity-40 disabled:pointer-events-none",title:n("web.openExternal"),"aria-label":n("web.openExternal"),children:e.jsx(Rs,{size:14})}),e.jsx(Ze,{type:"submit",size:"sm",children:n("web.go")}),h&&e.jsx("button",{type:"button",onClick:()=>D(!0),className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:n("web.hideBar"),"aria-label":n("web.hideBar"),children:e.jsx(Or,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{m(v=>!v),D(!1)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:n(h?"web.exitFullscreen":"web.fullscreen"),children:h?e.jsx(Wr,{size:14}):e.jsx($s,{size:14})})]}),f.length>0&&e.jsx("div",{className:`${z?"hidden":"flex"} items-center gap-1 px-2 py-1 border-b border-theme-border overflow-x-auto`,children:f.map(v=>e.jsxs("div",{className:"group flex items-center flex-shrink-0 rounded-md hover:bg-theme-hover",children:[e.jsx("button",{type:"button",onClick:()=>S(a.id,{src:v.url,url:v.url}),className:"px-2 py-0.5 text-xs text-theme-text-secondary hover:text-theme-text truncate max-w-[160px]",title:v.url,children:v.title}),e.jsx("button",{type:"button",onClick:()=>b(v.url),className:"p-0.5 mr-0.5 rounded opacity-0 group-hover:opacity-100 focus:opacity-100 hover:bg-theme-hover",title:n("web.removeFavorite"),"aria-label":`${n("web.removeFavorite")}: ${v.title}`,children:e.jsx(ft,{size:10})})]},v.url))}),z&&e.jsx("button",{type:"button",onClick:()=>D(!1),className:"absolute top-0 left-1/2 -translate-x-1/2 z-10 px-3 py-0.5 rounded-b-md bg-theme-card border border-t-0 border-theme-border shadow-card text-warm-400 hover:text-warm-600 transition-colors",title:n("web.showBar"),"aria-label":n("web.showBar"),children:e.jsx(ms,{size:14})}),e.jsx("div",{ref:F,className:"flex-1 min-h-0 flex flex-col",children:Ic?r.map(v=>v.src&&c.has(v.id)?s.createElement("webview",{key:v.id,ref:X,"data-tab-id":v.id,src:v.src,partition:"persist:webpanel",allowpopups:"",className:v.id===i?"flex-1 min-h-0":"hidden"}):v.id===i&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-theme-text-secondary",children:n("web.emptyTab")},v.id)):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-sm text-theme-text-secondary",children:[e.jsx("span",{children:n("web.desktopOnly")}),e.jsxs(Ze,{size:"sm",className:"flex items-center gap-1.5",onClick:()=>window.open(a.url||Ys,"_blank","noopener"),children:[e.jsx(Rs,{size:14}),n("web.openExternal")]})]})})]})}const Kc=s.lazy(()=>hs(()=>import("./AnalyticsPanel-Df6PTxhA.js"),__vite__mapDeps([17,1,2,15,5,4]))),Uc=s.lazy(()=>hs(()=>import("./VaultLayout-CUbPgHod.js"),__vite__mapDeps([18,1,2,8,7,14,3,4,5,6,10,11,9,12])));function Vc({onEvent:t,connected:n,sendMessage:r,subscribeBinary:i}){const{id:l}=Br(),[a,c]=s.useState(null),[x,o]=s.useState([]),[g,f]=s.useState([]),[p,h]=s.useState(null),[m,j]=s.useState([]),[D,z]=s.useState([]),[K,F]=s.useState([]),[R,S]=s.useState([]),[H,_]=Kr(),O=["tasks","loops","discussions","schedules","analytics"],X=H.get("tab")||"tasks",[k,se]=s.useState(O.includes(X)?"automation":X),[G,b]=s.useState(O.includes(X)?X:"tasks"),v=s.useCallback(u=>{if(u==="automation"){se("automation"),_(G==="tasks"?{}:{tab:G},{replace:!0});return}se(u),_(u==="tasks"?{}:{tab:u},{replace:!0})},[_,G]),y=s.useCallback(u=>{se("automation"),b(u),_(u==="tasks"?{}:{tab:u},{replace:!0})},[_]),d=s.useMemo(()=>{if(!a)return[];let u=[];try{u=JSON.parse(a.hidden_tabs||"[]")}catch{}return a.is_git_repo||u.push("git"),a.svn_enabled||u.push("svn"),u},[a]);s.useEffect(()=>{d.includes(k)&&v("automation")},[d,k,v]);const[C,N]=s.useState(!0),[L,B]=s.useState(!1),[Y,le]=s.useState(new Set),ue=x.filter(u=>!!u.loop_config),me=x.filter(u=>!u.loop_config),[pe,ae]=s.useState(0),{t:w}=ye(),{success:J,error:M,info:te}=aa(),{sendNotification:re}=Ur(),we=s.useRef([]);s.useEffect(()=>{we.current=m},[m]),s.useEffect(()=>{l&&Promise.all([Vr(l),vs(l),wn(l),hn(l),Fi(),Gr(l),Xt(l),Zt(l)]).then(([u,E,T,ee,ie,ke,Ve,ht])=>{c(u),o(E),f(T),j(ee),z(ke),F(Ve),S(ht),ie.resetsAt&&h(ie.resetsAt);const at=E.filter($=>$.status==="running"&&$.execution_mode==="interactive").map($=>$.id);at.length>0&&le(new Set(at))}).catch(()=>B(!0)).finally(()=>N(!1))},[l]);const I=s.useRef(x);I.current=x,s.useEffect(()=>{if(!l)return;const u=setInterval(()=>{I.current.some(T=>T.status==="running")&&vs(l).then(T=>{o(ee=>ee.map(ie=>{const ke=T.find(Ve=>Ve.id===ie.id);return ke&&ke.status!==ie.status?ke:ie}))}).catch(()=>{})},5e3);return()=>clearInterval(u)},[l]);const U=s.useRef(n);s.useEffect(()=>{n&&!U.current&&l&&Promise.all([vs(l),wn(l),hn(l)]).then(([u,E,T])=>{o(u),f(E),j(T)}).catch(()=>{}),U.current=n},[n,l]),s.useEffect(()=>t(u=>{if(u.type==="todo:status-changed"&&u.todoId&&u.status){if(o(E=>E.map(T=>{if(T.id!==u.todoId)return T;const ee={status:u.status,updated_at:new Date().toISOString()};return u.worktree_path!==void 0&&(ee.worktree_path=u.worktree_path??null),u.branch_name!==void 0&&(ee.branch_name=u.branch_name??null),u.round_count!==void 0&&(ee.round_count=u.round_count),{...T,...ee}})),(u.status==="completed"||u.status==="merged"||u.status==="failed")&&ae(E=>E+1),u.status==="completed"||u.status==="failed"){const E=I.current.find(T=>T.id===u.todoId);E&&re(u.status==="completed"?w("notification.taskCompleted"):w("notification.taskFailed"),E.title)}u.status==="running"&&u.mode==="interactive"?le(E=>new Set(E).add(u.todoId)):u.status!=="running"&&le(E=>{const T=new Set(E);return T.delete(u.todoId),T})}if(u.type==="todo:created"&&u.todo&&u.todo.project_id===l){const E=u.todo;o(T=>T.some(ee=>ee.id===E.id)?T:[...T,E])}if(u.type==="schedule:status-changed"&&u.scheduleId&&f(E=>E.map(T=>T.id===u.scheduleId?{...T,is_active:u.isActive?1:0,updated_at:new Date().toISOString()}:T)),u.type==="rate-limit:updated"&&u.resetsAt&&h(u.resetsAt),u.type==="discussion:status-changed"&&u.discussionId&&(j(E=>E.map(T=>T.id===u.discussionId?{...T,status:u.status,current_round:u.currentRound??T.current_round,updated_at:new Date().toISOString()}:T)),u.status==="completed"||u.status==="failed")){const E=we.current.find(T=>T.id===u.discussionId);E&&re(u.status==="completed"?w("notification.discussionCompleted"):w("notification.discussionFailed"),E.title)}u.type==="session:status-changed"&&u.sessionId&&z(E=>E.map(T=>{if(T.id!==u.sessionId)return T;const ee={status:u.status,updated_at:new Date().toISOString()};return u.worktree_path!==void 0&&(ee.worktree_path=u.worktree_path),u.branch_name!==void 0&&(ee.branch_name=u.branch_name),u.cli_session_id!==void 0&&(ee.cli_session_id=u.cli_session_id),u.resumable!==void 0&&(ee.resumable=u.resumable),{...T,...ee}}))}),[t,re,w]);const ce=s.useCallback(async(u,E,T,ee,ie,ke,Ve,ht,at,$,oe)=>{if(!l)return;const Ce=await un(l,{title:u,description:E,cli_tool:T,depends_on:ie,max_turns:ke??null,use_worktree:Ve??null,...ht?{memory_inject_mode:ht}:{},...at?{memory_node_ids:at}:{},...$?{memory_raw_file_paths:$}:{},...oe?{loop_config:oe}:{}});if(ee&&ee.length>0){const Ae=await oa(Ce.id,ee.map(rt=>({name:rt.name,data:rt.data})));Ce.images=JSON.stringify(Ae.images)}o(Ae=>[...Ae,Ce])},[l]),$e=s.useCallback((u,E=[])=>{const T=u.split("/").filter(Boolean).pop()??u,ee=[u,...E].map(ie=>`@${ie}`).join(`
|
|
173
|
+
`).length+1)),spellCheck:!1,className:"mt-1 w-full text-2xs font-mono text-warm-700 bg-warm-50 dark:bg-warm-800/40 rounded-md p-2 border border-accent/40 focus:outline-none focus:border-accent resize-y"}),e.jsxs("div",{className:"mt-1 flex justify-end gap-2",children:[S.name==="svn:externals"&&e.jsx("button",{onClick:()=>m(!1),className:"text-2xs text-warm-400 hover:text-accent mr-auto",children:i("svn.ext.editTable")}),e.jsx(Ze,{size:"sm",onClick:()=>g(null),disabled:j,children:i("svn.cancel")}),e.jsx(Ze,{variant:"primary",size:"sm",onClick:()=>F(S.name),disabled:j,children:i("svn.saveProperty")})]})]}):e.jsx("pre",{className:"mt-1 text-2xs font-mono text-warm-600 bg-warm-50 dark:bg-warm-800/40 rounded-md p-2 whitespace-pre-wrap break-all",children:S.value||"—"})]},S.name))})]}),e.jsx("div",{className:"px-4 py-3 border-t border-warm-100 shrink-0 text-right",children:e.jsx(Ze,{size:"sm",onClick:r,children:i("svn.close")})})]})})}const pc=["architect","developer","reviewer","pm","tester","custom"],Dt=["#6366f1","#8b5cf6","#ec4899","#f43f5e","#f97316","#eab308","#22c55e","#14b8a6","#06b6d4","#3b82f6"],fc=[{name:"Architect",nameKo:"아키텍트",role:"architect",prompt:"You are a senior software architect. Focus on system design, scalability, maintainability, and separation of concerns. Evaluate proposals for architectural soundness and suggest patterns that work well."},{name:"Developer",nameKo:"개발자",role:"developer",prompt:"You are a senior full-stack developer. Focus on implementation feasibility, code quality, existing patterns in the codebase, and developer experience. Be pragmatic about what can realistically be built."},{name:"Reviewer",nameKo:"리뷰어",role:"reviewer",prompt:"You are a senior code reviewer and quality advocate. Focus on edge cases, error handling, security, performance, and testing strategy. Challenge assumptions and find potential issues."},{name:"Product Manager",nameKo:"PM",role:"pm",prompt:"You are a product manager. Focus on user experience, feature scope, priorities, and trade-offs. Ensure the discussion stays grounded in user needs and business value."},{name:"Tester",nameKo:"테스터",role:"tester",prompt:"You are a QA engineer and testing specialist. Focus on testability, test coverage strategy, edge cases, regression risks, and how to verify the feature works correctly."}];function gc({projectId:t,agents:n,onAgentsChange:r}){const{t:i,lang:l}=ye(),[a,c]=s.useState(!1),[x,o]=s.useState(null),[g,f]=s.useState(""),[p,h]=s.useState("developer"),[m,j]=s.useState(""),[D,z]=s.useState(""),[K,F]=s.useState(Dt[0]),[R,S]=s.useState(!1),[H,_]=s.useState(!1),O=()=>{f(""),h("developer"),j(""),z(""),F(Dt[Math.floor(Math.random()*Dt.length)]),S(!1),c(!1),o(null)},X=async()=>{if(!(!g.trim()||!m.trim())){_(!0);try{if(x){const b=await bl(x,{name:g,role:p,system_prompt:m,avatar_color:K,cli_tool:D||null,can_implement:R});r(n.map(v=>v.id===x?b:v))}else{const b=await vl(t,{name:g,role:p,system_prompt:m,avatar_color:K,...D?{cli_tool:D}:{},can_implement:R});r([...n,b])}O()}finally{_(!1)}}},k=b=>{o(b.id),f(b.name),h(b.role),j(b.system_prompt),z(b.cli_tool||""),F(b.avatar_color||Dt[0]),S(!!b.can_implement),c(!0)},se=async b=>{await wl(b),r(n.filter(v=>v.id!==b))},G=b=>{f(l==="ko"?b.nameKo:b.name),h(b.role),j(b.prompt),F(Dt[Math.floor(Math.random()*Dt.length)]),c(!0)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-warm-700",children:i("agents.title")}),e.jsxs("button",{onClick:()=>{O(),c(!0)},className:"btn btn-sm text-xs",children:["+ ",i("agents.add")]})]}),n.length===0&&!a&&e.jsx(At,{icon:_i,title:i("agents.empty"),size:"sm"}),e.jsx("div",{className:"space-y-2",children:n.map(b=>{var v;return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-warm-50 border border-warm-150 hover:border-warm-250 transition-colors group",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-white text-sm font-bold flex-shrink-0 shadow-sm",style:{backgroundColor:b.avatar_color||"#6366f1"},children:b.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",children:b.name}),!!b.can_implement&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-2xs font-medium bg-status-warning/10 text-status-warning border border-status-warning/30",title:i("agents.canImplementHelp"),children:[e.jsx(fn,{size:12}),i("agents.canImplementBadge")]})]}),e.jsxs("div",{className:"text-xs text-warm-400 mt-0.5",children:[i(`agents.roles.${b.role}`)||b.role,b.cli_tool&&e.jsxs("span",{className:"ml-1.5 text-warm-300",children:["· ",((v=bt.find(y=>y.value===b.cli_tool))==null?void 0:v.label)||b.cli_tool]})]})]}),e.jsxs("div",{className:"flex gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:()=>k(b),className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-lg transition-colors",children:e.jsx(Wt,{size:16})}),e.jsx("button",{onClick:()=>se(b.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",children:e.jsx(wt,{size:16})})]})]},b.id)})}),a&&e.jsxs("div",{className:"space-y-5 p-5 rounded-xl border border-warm-200 bg-theme-card shadow-sm",children:[!x&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.presets")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:fc.map(b=>e.jsx(Ze,{size:"sm",onClick:()=>G(b),children:l==="ko"?b.nameKo:b.name},b.role))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.name")}),e.jsx("input",{type:"text",value:g,onChange:b=>f(b.target.value),className:"input-field",placeholder:l==="ko"?"에이전트 이름":"Agent name"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.role")}),e.jsx("select",{value:p,onChange:b=>h(b.target.value),className:"input-field",children:pc.map(b=>e.jsx("option",{value:b,children:i(`agents.roles.${b}`)},b))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.systemPrompt")}),e.jsx("textarea",{value:m,onChange:b=>j(b.target.value),rows:5,className:"input-field resize-y min-h-[100px]",placeholder:l==="ko"?"이 에이전트의 전문 분야와 관점을 설명하세요...":"Describe this agent's expertise and perspective..."}),e.jsx("p",{className:"text-2xs text-warm-400 mt-1.5",children:l==="ko"?"토론 시 이 에이전트가 어떤 관점에서 발언할지 결정합니다.":"Determines what perspective this agent brings to the discussion."})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.cliTool")}),e.jsxs("select",{value:D,onChange:b=>z(b.target.value),className:"input-field text-sm",children:[e.jsx("option",{value:"",children:l==="ko"?"프로젝트 기본값 사용":"Use project default"}),bt.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))]})]})}),e.jsx("div",{children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:R,onChange:b=>S(b.target.checked),className:"mt-0.5 w-4 h-4 rounded-md border-warm-300 text-warm-600 focus:ring-warm-400"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-warm-700",children:[e.jsx(fn,{size:12}),i("agents.canImplement")]}),e.jsx("p",{className:"text-2xs text-warm-400 mt-0.5",children:i("agents.canImplementHelp")})]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:i("agents.color")}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-white text-sm font-bold flex-shrink-0 shadow-sm",style:{backgroundColor:K},children:g?g.charAt(0).toUpperCase():"?"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Dt.map(b=>e.jsx("button",{onClick:()=>F(b),className:`w-7 h-7 rounded-full transition-all ${K===b?"ring-2 ring-offset-2 ring-warm-400 scale-110":"hover:scale-105 opacity-70 hover:opacity-100"}`,style:{backgroundColor:b}},b))})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2 border-t border-warm-100",children:[e.jsx("button",{onClick:O,className:"btn btn-sm text-xs text-warm-500",children:i("header.cancel")}),e.jsx("button",{onClick:X,disabled:!g.trim()||!m.trim()||H,className:"btn btn-sm btn-primary text-xs",children:i(H?"header.saving":"header.save")})]})]})]})}const bc={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",paused:"bg-status-warning/10 text-status-warning",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",merged:"bg-accent/10 text-accent"};function vc({projectId:t,discussions:n,isGitRepo:r,projectUseWorktree:i,onAddDiscussion:l,onStartDiscussion:a,onStopDiscussion:c,onDeleteDiscussion:x}){const{t:o}=ye(),g=Tr(),[f,p]=s.useState([]),[h,m]=s.useState(!1),[j,D]=s.useState(!1),[z,K]=s.useState(!1),[F,R]=s.useState(null);s.useEffect(()=>{yl(t).then(p).catch(()=>{})},[t]);const S=s.useCallback(async _=>{K(!0);try{const O=await jl(t,_);l(O),m(!1)}finally{K(!1)}},[t,l]),H=_=>{try{return JSON.parse(_).map(X=>f.find(k=>k.id===X)).filter(X=>!!X)}catch{return[]}};return e.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:_=>{$t(_)||(_.preventDefault(),R({x:_.clientX,y:_.clientY}))},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:o("discussions.title")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>D(!j),className:"btn-secondary text-xs py-2",children:o("agents.manage")}),e.jsxs("button",{onClick:()=>m(!h),className:"btn-primary text-xs py-2",children:["+ ",o("discussions.add")]})]})]}),j&&e.jsx("div",{className:"card p-4",children:e.jsx(gc,{projectId:t,agents:f,onAgentsChange:p})}),h&&e.jsx(Nl,{agents:f,projectId:t,mode:"create",submitting:z,isGitRepo:r,projectUseWorktree:i,onSubmit:S,onCancel:()=>m(!1)}),n.length===0&&!h?e.jsx("div",{className:"card",children:e.jsx(At,{icon:ui,title:o("discussions.empty"),description:o("discussions.emptyHint")})}):e.jsx("div",{className:"space-y-3",children:n.map((_,O)=>{const X=H(_.agent_ids),k=_.status==="pending"||_.status==="paused"||_.status==="failed",se=_.status==="running";return e.jsx("div",{className:"card p-4 hover:shadow-md transition-all cursor-pointer",onClick:()=>g(`/projects/${t}/discussions/${_.id}`),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:_.title}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-semibold uppercase ${bc[_.status]||""}`,children:o(`status.${_.status}`)||_.status})]}),e.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:_.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsxs("span",{className:"text-2xs text-warm-400",children:[o("discussions.round")," ",_.current_round,"/",_.max_rounds]}),e.jsx("div",{className:"flex -space-x-1",children:X.slice(0,5).map(G=>e.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-white text-[8px] text-white font-bold flex items-center justify-center",style:{backgroundColor:G.avatar_color||"#6366f1"},title:G.name,children:G.name.charAt(0)},G.id))})]})]}),e.jsxs("div",{className:"flex gap-1",onClick:G=>G.stopPropagation(),children:[k&&e.jsx("button",{onClick:()=>a(_.id),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md transition-colors",title:o("header.runAll"),children:e.jsx(Rt,{size:16})}),se&&e.jsx("button",{onClick:()=>c(_.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:o("discussions.pause"),children:e.jsx(da,{size:16})}),e.jsx("button",{onClick:()=>x(_.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:o("todo.delete"),children:e.jsx(wt,{size:16})})]})]})},_.id)})}),F&&e.jsx(yt,{x:F.x,y:F.y,onClose:()=>R(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>{m(!0)},children:[e.jsx(gt,{size:14}),o("discussions.add")]})})]})}function wc(t){if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.map(String).filter(Boolean):[]}catch{return[]}}function Pn({projectId:t,initial:n,onSave:r,onCancel:i,projectCliTool:l,isGitRepo:a,projectUseWorktree:c}){const{t:x}=ye(),o=!!n,[g,f]=s.useState((n==null?void 0:n.title)??""),[p,h]=s.useState((n==null?void 0:n.description)??""),[m,j]=s.useState((n==null?void 0:n.cliTool)??(l||"")),[D,z]=s.useState((n==null?void 0:n.useWorktree)??!!c),[K,F]=s.useState((n==null?void 0:n.memoryInjectMode)??"none"),[R,S]=s.useState((n==null?void 0:n.memoryRawFilePaths)??[]),[H,_]=s.useState(!1),[O,X]=s.useState((n==null?void 0:n.tagId)??null),[k,se]=s.useState([]),[G,b]=s.useState([]),v=s.useRef(null);s.useEffect(()=>{var ue;Rr(()=>{var me;return(me=v.current)==null?void 0:me.focus()})||(ue=v.current)==null||ue.focus();const Y=Array.from(document.querySelectorAll(".xterm-helper-textarea")),le=Y.map(me=>({el:me,tabIndex:me.tabIndex,ariaHidden:me.getAttribute("aria-hidden")}));return Y.forEach(me=>{me.tabIndex=-1,me.setAttribute("aria-hidden","true"),me.blur()}),()=>{le.forEach(({el:me,tabIndex:pe,ariaHidden:ae})=>{me.tabIndex=pe,ae===null?me.removeAttribute("aria-hidden"):me.setAttribute("aria-hidden",ae)})}},[]),s.useEffect(()=>{let Y=!1;return sa().then(le=>{Y||se(le)}).catch(()=>{}),!o&&a&&$r().then(le=>{Y||z(le.defaultUseWorktree)}).catch(()=>{}),()=>{Y=!0}},[o,a]),s.useEffect(()=>{let Y=!1;return Vs().then(le=>{Y||b(le)}).catch(()=>{}),()=>{Y=!0}},[]);const y=bt.filter(Y=>Y.supportsInteractive),d=Y=>{const le=G.find(ue=>ue.tool===Y.value);return Y.value==="raw-shell"?le!=null&&le.version?`Raw Shell (${le.version})`:Y.label:le&&!le.installed?`${Y.label}${x("session.cliNotInstalled")}`:Y.label},N=(m||l||"claude")==="raw-shell",L=Y=>{Y.preventDefault(),r(g.trim(),p.trim(),m||void 0,D,K,[],R,O)},B=k.find(Y=>Y.id===O)??null;return e.jsxs("form",{onSubmit:L,className:"card p-4 space-y-3",children:[e.jsx("input",{ref:v,type:"text",value:g,onChange:Y=>f(Y.target.value),placeholder:x("session.title"),className:"input-field text-sm"}),!N&&e.jsx("textarea",{value:p,onChange:Y=>h(Y.target.value),placeholder:x("session.description"),className:"input-field text-sm min-h-[60px] max-h-[280px] resize-y [field-sizing:content]",rows:2}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("select",{value:m,onChange:Y=>j(Y.target.value),className:"input-field text-xs flex-1",children:[e.jsxs("option",{value:"",children:[x("session.cliTool")," (Default)"]}),y.map(Y=>e.jsx("option",{value:Y.value,children:d(Y)},Y.value))]})}),k.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[B&&e.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:B.color,borderColor:"rgba(0,0,0,0.08)"}}),e.jsxs("select",{value:O??"",onChange:Y=>X(Y.target.value||null),className:"input-field text-xs flex-1",children:[e.jsx("option",{value:"",children:x("session.tag.none")}),k.map(Y=>e.jsx("option",{value:Y.id,children:Y.name},Y.id))]})]}),a&&e.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-500 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:Y=>z(Y.target.checked),className:"rounded-md border-warm-300"}),e.jsx(xs,{size:14}),x("session.worktree")]}),!N&&e.jsx(ca,{projectId:t,mode:K,selectedPaths:R,includeLinked:H,onChange:(Y,le,ue)=>{F(Y),S(le),_(ue)}}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:i,className:"btn-secondary text-xs py-1.5 px-3",children:x("form.cancel")}),e.jsx("button",{type:"submit",className:"btn-primary text-xs py-1.5 px-3",children:x(o?"session.save":"session.create")})]})]})}function yc(t){if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.map(String).filter(Boolean):[]}catch{return[]}}const jc={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function Nc({projectId:t,sessions:n,projectCliTool:r,isGitRepo:i,projectUseWorktree:l,projectDefaultBranch:a,onAddSession:c,onUpdateSession:x,onStopSession:o,onDeleteSession:g,onCleanupSession:f}){const{t:p}=ye(),{confirm:h}=_t(),{openOrFocus:m,recallPopout:j}=Lr(),D=Fr(),z=zr(),K=s.useMemo(()=>{const w=new Map;for(const te of n){const re=z[te.id];re&&w.set(re,[...w.get(re)??[],te])}const J=new Set,M=[];for(const te of n){if(J.has(te.id))continue;const re=w.get(z[te.id]??"")??[te];re.forEach((we,I)=>{J.add(we.id);const U=re.length===1?"single":I===0?"first":I===re.length-1?"last":"middle";M.push({session:we,position:U})})}return M},[n,z]),[F,R]=s.useState(!1),[S,H]=s.useState(!1),[_,O]=s.useState(null),[X,k]=s.useState(!1),[se,G]=s.useState(null),[b,v]=s.useState([]),[y,d]=s.useState(""),[C,N]=s.useState(null);s.useEffect(()=>{let w=!1;return sa().then(J=>{w||v(J)}).catch(()=>{}),()=>{w=!0}},[]),s.useEffect(()=>{if(!i)return;let w=!1;return Yn(t).then(J=>{w||d(J.branch||"")}).catch(()=>{}),()=>{w=!0}},[t,i]);const L=s.useMemo(()=>{const w=new Map;for(const J of b)w.set(J.id,J);return w},[b]),B=s.useMemo(()=>_?n.find(w=>w.id===_)??null:null,[_,n]),Y=s.useMemo(()=>{if(B)return{title:B.title,description:B.description??"",cliTool:B.cli_tool??"",useWorktree:B.use_worktree===1,memoryInjectMode:B.memory_inject_mode??"none",memoryNodeIds:wc(B.memory_node_ids??null),memoryRawFilePaths:yc(B.memory_raw_file_paths??null),tagId:B.tag_id??null}},[B]),le=s.useCallback(()=>{O(null),G(null),R(w=>!w)},[]),ue=s.useCallback(w=>{R(!1),G(null),O(w)},[]),me=s.useCallback(()=>{R(!1),O(null),G(null)},[]),pe=s.useCallback(async(w,J,M,te,re,we,I,U)=>{H(!0);try{const ce=await Pr(t,{title:w,description:J||void 0,cli_tool:M,use_worktree:te,memory_inject_mode:re,memory_node_ids:we,memory_raw_file_paths:I,tag_id:U??null});c(ce),R(!1)}finally{H(!1)}},[t,c]),ae=s.useCallback(async(w,J,M,te,re,we,I,U)=>{if(_){k(!0),G(null);try{const ce=await Ar(_,{title:w,description:J||void 0,cli_tool:M,use_worktree:te,memory_inject_mode:re,memory_node_ids:we,memory_raw_file_paths:I,tag_id:U??null});x(ce),O(null)}catch(ce){G(ce instanceof Error?ce.message:String(ce))}finally{k(!1)}}},[_,x]);return e.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:w=>{$t(w)||(w.preventDefault(),N({x:w.clientX,y:w.clientY,sessionId:null}))},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:p("tabs.sessions")}),e.jsxs("button",{onClick:le,className:"btn-primary text-xs py-2",disabled:S,children:["+ ",p("session.new")]})]}),F&&e.jsx(Pn,{projectId:t,onSave:pe,onCancel:me,projectCliTool:r,isGitRepo:i,projectUseWorktree:l}),Y&&_&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Pn,{projectId:t,initial:Y,onSave:ae,onCancel:me,projectCliTool:r,isGitRepo:i},_),(X||se)&&e.jsxs("div",{className:"text-xs px-1",children:[X&&e.jsx("span",{className:"text-warm-500",children:p("session.saving")||"saving…"}),se&&e.jsx("span",{className:"text-status-error",children:se})]})]}),n.length===0&&!F?e.jsx("div",{className:"card",children:e.jsx(At,{icon:ln,title:p("session.empty"),description:p("session.emptyHint")})}):e.jsx("div",{className:"space-y-3",children:K.map(({session:w,position:J})=>{const M=["pending","failed","stopped","completed"].includes(w.status),te=w.status==="running",re=w.status!=="running",we=["stopped","failed","completed"].includes(w.status)&&!!w.resumable,I=_===w.id,U=D[w.id]??"closed",ce=U==="popped",$e={single:"",first:"rounded-b-none hover:!translate-y-0",middle:"!mt-0 rounded-none border-t-0 hover:!translate-y-0",last:"!mt-0 rounded-t-none border-t-0 hover:!translate-y-0"}[J];return e.jsx("div",{className:`card overflow-hidden ${$e} ${I?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:Ne=>{$t(Ne)||(Ne.preventDefault(),Ne.stopPropagation(),N({x:Ne.clientX,y:Ne.clientY,sessionId:w.id}))},children:e.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>ce?j(w.id):m(w.id,"open"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[w.tag_id&&L.get(w.tag_id)&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-2xs font-medium",style:{backgroundColor:`${L.get(w.tag_id).color}22`,color:L.get(w.tag_id).color},children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:L.get(w.tag_id).color}}),L.get(w.tag_id).name]}),e.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:w.title}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs font-medium text-warm-500 whitespace-nowrap",children:[e.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${jc[w.status]||"bg-warm-400"}`}),p(`status.${w.status}`)||w.status]}),U!=="closed"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:ce?p("session.dock.poppedHint"):void 0,children:[ce?e.jsx(Rs,{size:12}):e.jsx("span",{"aria-hidden":"true",children:"·"}),p(`session.windowState.${U}`)]})]}),w.description&&e.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:w.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-2xs text-warm-300",children:w.cli_tool||"claude"}),(w.branch_name||i&&(y||a))&&e.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[e.jsx(xs,{size:12}),w.branch_name||y||a]})]})]}),e.jsxs("div",{className:"flex gap-1",onClick:Ne=>Ne.stopPropagation(),children:[ce&&e.jsx("button",{onClick:()=>j(w.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:p("session.recallToMain"),children:e.jsx($s,{size:16})}),M&&e.jsx("button",{onClick:()=>m(w.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md transition-colors",title:p("session.start"),children:e.jsx(Rt,{size:16})}),we&&e.jsx("button",{onClick:()=>m(w.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:p("session.resumeHint")||p("session.resume"),children:e.jsx(Vt,{size:16})}),e.jsx("button",{onClick:()=>ue(w.id),disabled:!re,className:"p-1.5 text-warm-500 hover:text-warm-800 hover:bg-warm-100 rounded-md transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-warm-500",title:p(re?"session.edit":"session.editDisabledRunning"),children:e.jsx(on,{size:16})}),te&&e.jsx("button",{onClick:()=>o(w.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:p("session.stop"),children:e.jsx(Kt,{size:16})}),w.status!=="running"&&(!!w.worktree_path||!!w.branch_name)&&e.jsx("button",{onClick:async()=>{const Ne=w.branch_name?await h({message:p("cleanup.confirmDeleteBranch").replace("{name}",w.branch_name),danger:!0}):!1;f(w.id,Ne)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:p("session.cleanup"),children:e.jsx(ls,{size:16})}),e.jsx("button",{onClick:()=>g(w.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:p("session.delete"),children:e.jsx(wt,{size:16})})]})]})})},w.id)})}),C&&(()=>{const w=()=>N(null),J=C.sessionId?n.find(Ne=>Ne.id===C.sessionId):void 0;if(!J)return e.jsx(yt,{x:C.x,y:C.y,onClose:w,children:e.jsxs("button",{type:"button",onClick:()=>{O(null),G(null),R(!0)},className:Be,children:[e.jsx(gt,{size:14}),p("session.new")]})});const M=["pending","failed","stopped","completed"].includes(J.status),te=J.status==="running",re=J.status!=="running",we=["stopped","failed","completed"].includes(J.status)&&!!J.resumable,I=J.status!=="running"&&(!!J.worktree_path||!!J.branch_name),U=D[J.id]??"closed",ce=U==="popped",$e=p(ce?"session.recallToMain":U==="minimized"?"session.restoreWindow":U==="floating"?"session.focusWindow":"session.openWindow");return e.jsxs(yt,{x:C.x,y:C.y,onClose:w,children:[e.jsxs("button",{type:"button",onClick:()=>ce?j(J.id):m(J.id,"open"),className:Be,children:[ce?e.jsx($s,{size:14}):e.jsx(ln,{size:14}),$e]}),M&&e.jsxs("button",{type:"button",onClick:()=>m(J.id,"start"),className:Be,children:[e.jsx(Rt,{size:14}),p("session.start")]}),we&&e.jsxs("button",{type:"button",onClick:()=>m(J.id,"resume"),className:Be,title:p("session.resumeHint")||p("session.resume"),children:[e.jsx(Vt,{size:14}),p("session.resume")]}),re&&e.jsxs("button",{type:"button",onClick:()=>ue(J.id),className:Be,children:[e.jsx(on,{size:14}),p("session.edit")]}),te&&e.jsxs("button",{type:"button",onClick:()=>o(J.id),className:Be,children:[e.jsx(Kt,{size:14}),p("session.stop")]}),I&&e.jsxs("button",{type:"button",onClick:async()=>{const Ne=J.branch_name?await h({message:p("cleanup.confirmDeleteBranch").replace("{name}",J.branch_name),danger:!0}):!1;f(J.id,Ne)},className:Be,children:[e.jsx(ls,{size:14}),p("session.cleanup")]}),e.jsx(Ks,{}),e.jsxs("button",{type:"button",onClick:()=>g(J.id),className:ra,children:[e.jsx(wt,{size:14}),p("session.delete")]})]})})()]})}const ds={default:{bg:"bg-warm-200/50",text:"text-warm-500",swatch:"bg-warm-300"},gray:{bg:"bg-gray-500/20",text:"text-gray-400",swatch:"bg-gray-400"},brown:{bg:"bg-amber-800/20",text:"text-amber-600",swatch:"bg-amber-700"},orange:{bg:"bg-orange-500/20",text:"text-orange-400",swatch:"bg-orange-500"},yellow:{bg:"bg-yellow-500/20",text:"text-yellow-400",swatch:"bg-yellow-500"},green:{bg:"bg-emerald-500/20",text:"text-emerald-400",swatch:"bg-emerald-500"},blue:{bg:"bg-blue-500/20",text:"text-blue-400",swatch:"bg-blue-500"},purple:{bg:"bg-purple-500/20",text:"text-purple-400",swatch:"bg-purple-500"},pink:{bg:"bg-pink-500/20",text:"text-pink-400",swatch:"bg-pink-500"},red:{bg:"bg-red-500/20",text:"text-red-400",swatch:"bg-red-500"}},kc=Object.keys(ds),us={pending:"bg-warm-200 text-warm-500",in_progress:"bg-status-running/10 text-status-running",done:"bg-status-success/10 text-status-success",moved:"bg-status-merged/10 text-status-merged"};function Pt(t){const n=ds[t]||ds.default;return`${n.bg} ${n.text}`}const An={0:{label:"—",style:"text-warm-300"},1:{label:"●",style:"text-warm-500"},2:{label:"●●",style:"text-status-warning"},3:{label:"●●●",style:"text-status-error"}};function Cc({item:t,tagColors:n,existingTags:r,onSave:i,onDelete:l,onConvertToTodo:a,onConvertToSchedule:c,onConvertToSession:x,onUpdateTag:o}){var qe,st;const{t:g}=ye(),{confirm:f}=_t(),[p,h]=s.useState(!1),[m,j]=s.useState(!1),[D,z]=s.useState(!1),K=s.useRef(null),F=s.useRef(null),[R,S]=s.useState({top:0,left:0}),[H,_]=s.useState(t.title),[O,X]=s.useState(t.description??""),[k,se]=s.useState(t.priority),[G,b]=s.useState(t.due_date??""),[v,y]=s.useState(t.status),[d,C]=s.useState(()=>{try{return t.tags?JSON.parse(t.tags):[]}catch{return[]}}),[N,L]=s.useState(""),[B,Y]=s.useState(!1),[le,ue]=s.useState(null),[me,pe]=s.useState(null),ae=s.useRef(null),w=s.useRef(null),[J,M]=s.useState(()=>{try{return t.images?JSON.parse(t.images):[]}catch{return[]}}),te=s.useRef(null);s.useEffect(()=>{_(t.title),X(t.description??""),se(t.priority),b(t.due_date??""),y(t.status);try{C(t.tags?JSON.parse(t.tags):[])}catch{C([])}try{M(t.images?JSON.parse(t.images):[])}catch{M([])}},[t]);const re=d,we=t.status==="moved",I=t.due_date&&new Date(t.due_date)<new Date&&!we&&t.status!=="done",U=s.useCallback(A=>{i(t.id,A)},[t.id,i]),ce=()=>{const A=H.trim();A&&A!==t.title?U({title:A}):_(t.title)},$e=()=>{const A=O.trim();A!==(t.description??"")&&U({description:A||void 0})},Ne=A=>{se(A),A!==t.priority&&U({priority:A})},Me=A=>{b(A),A!==(t.due_date??"")&&U({due_date:A||void 0})},Re=A=>{const he=A;y(he),he!==t.status&&U({status:he})},De=A=>{C(A);const he=(()=>{try{return t.tags?JSON.parse(t.tags):[]}catch{return[]}})();JSON.stringify(A)!==JSON.stringify(he)&&U({tags:A.length>0?JSON.stringify(A):void 0})},Je=A=>{var Ke;const he=A.trim();if(he&&!d.includes(he)&&(De([...d,he]),!n.has(he)&&o)){const _e=["blue","green","orange","purple","pink","red","yellow","brown"],ze=_e[n.size%_e.length];o(he,{color:ze})}L(""),(Ke=ae.current)==null||Ke.focus()},Q=A=>De(d.filter(he=>he!==A)),W=r.filter(A=>!d.includes(A)&&(!N||A.toLowerCase().includes(N.toLowerCase()))),de=s.useCallback(A=>{const he=Array.from(A).filter(ze=>ze.type.startsWith("image/")),Ke=[];let _e=0;for(const ze of he){const Oe=new FileReader;Oe.onload=()=>{Ke.push({name:ze.name,data:Oe.result}),_e++,_e===he.length&&ma(t.id,Ke).then(it=>M(it.images))},Oe.readAsDataURL(ze)}},[t.id]),be=s.useCallback(A=>{var _e;const he=(_e=A.clipboardData)==null?void 0:_e.items;if(!he)return;const Ke=[];for(let ze=0;ze<he.length;ze++)if(he[ze].type.startsWith("image/")){const Oe=he[ze].getAsFile();Oe&&Ke.push(Oe)}Ke.length!==0&&(A.preventDefault(),de(Ke))},[de]),Ie=s.useCallback(A=>{var he;A.preventDefault(),A.stopPropagation(),(he=A.dataTransfer)!=null&&he.files&&de(A.dataTransfer.files)},[de]),He=s.useCallback(A=>{xa(t.id,A).then(()=>{M(he=>he.filter(Ke=>Ke.id!==A))})},[t.id]),Ee=s.useCallback(()=>{if(!K.current)return;const A=K.current.getBoundingClientRect(),he=window.innerWidth,Ke=window.innerHeight;let _e=A.bottom+4;const ze=F.current;if(ze){const Oe=ze.offsetWidth,it=ze.offsetHeight;let q=A.right-Oe;q<8&&(q=8),q+Oe>he-8&&(q=he-8-Oe),_e+it>Ke-8&&(_e=A.top-it-4),S({top:_e,left:q}),z(!0)}else S({top:_e,left:Math.max(8,A.right-180)})},[]);return s.useEffect(()=>{if(!p){z(!1);return}Ee();const A=requestAnimationFrame(Ee),he=Ke=>{var ze,Oe;const _e=Ke.target;(ze=K.current)!=null&&ze.contains(_e)||(Oe=F.current)!=null&&Oe.contains(_e)||h(!1)};return document.addEventListener("mousedown",he),window.addEventListener("scroll",Ee,!0),window.addEventListener("resize",Ee),()=>{cancelAnimationFrame(A),document.removeEventListener("mousedown",he),window.removeEventListener("scroll",Ee,!0),window.removeEventListener("resize",Ee)}},[p,Ee]),e.jsxs("div",{className:`${we?"opacity-50":""}`,style:{borderBottom:"1px solid var(--color-border-muted)"},children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg transition-colors hover:bg-warm-50 cursor-pointer",onDoubleClick:()=>j(!m),children:[e.jsx(St,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${m?"rotate-90":""}`,onClick:A=>{A.stopPropagation(),j(!m)}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium truncate block",style:{color:"var(--color-text-primary)"},children:t.title}),we&&t.converted_type&&e.jsxs("span",{className:"text-2xs text-status-merged",children:["→ ",t.converted_type==="todo"?g("planner.movedToTodo"):t.converted_type==="session"?g("planner.movedToSession"):g("planner.movedToSchedule")]}),t.source_discussion_id&&e.jsxs(na,{to:`/projects/${t.project_id}/discussions/${t.source_discussion_id}`,onClick:A=>A.stopPropagation(),className:"inline-flex items-center gap-1 text-2xs text-accent hover:underline mt-0.5",title:g("planner.fromDiscussion"),children:[e.jsx(xi,{size:12}),g("planner.fromDiscussion")]})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[J.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-md text-[10px] font-medium bg-warm-100 text-warm-500 whitespace-nowrap",children:[e.jsx(Ut,{size:12}),J.length]}),re.map(A=>e.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${Pt(n.get(A)||"default")}`,children:A},A))]}),e.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:e.jsx("span",{className:`text-xs font-medium ${((qe=An[t.priority])==null?void 0:qe.style)??"text-warm-300"}`,children:((st=An[t.priority])==null?void 0:st.label)??"—"})}),e.jsx("div",{className:"hidden md:block w-20 text-right flex-shrink-0",children:t.due_date?e.jsx("span",{className:`text-xs ${I?"text-status-error font-medium":"text-warm-500"}`,children:new Date(t.due_date).toLocaleDateString(void 0,{month:"numeric",day:"numeric"})}):e.jsx("span",{className:"text-xs text-warm-300",children:g("planner.noDueDate")})}),e.jsx("div",{className:"w-16 flex-shrink-0",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${us[t.status]||us.pending}`,children:g(`plannerStatus.${t.status}`)})}),e.jsxs("div",{className:"w-8 flex-shrink-0",children:[e.jsx("button",{ref:K,onClick:A=>{A.stopPropagation(),h(!p)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:e.jsx(Us,{size:14})}),p&&jt.createPortal(e.jsxs("div",{ref:F,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:R.top,left:R.left,opacity:D?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>h(!1),children:[!we&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:a,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(ua,{size:12})," ",g("planner.convertToTask")]}),e.jsxs("button",{onClick:c,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(zt,{size:12})," ",g("planner.convertToSchedule")]}),e.jsxs("button",{onClick:x,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(Bt,{size:12})," ",g("planner.convertToTerminal")]})]}),e.jsxs("button",{onClick:async()=>{await f({message:g("planner.deleteConfirm"),danger:!0})&&l()},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left",children:[e.jsx(wt,{size:12})," ",g("planner.delete")]})]}),document.body)]})]}),m&&e.jsx("div",{className:"px-4 pb-3 pt-1 ml-8",children:e.jsxs("div",{className:"rounded-lg px-4 py-3 space-y-3",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[e.jsx("input",{className:"bg-transparent text-sm font-medium w-full outline-none border-b border-transparent focus:border-warm-300 pb-0.5 transition-colors",style:{color:"var(--color-text-primary)"},value:H,onChange:A=>_(A.target.value),onBlur:ce,onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),ce(),A.target.blur())}}),e.jsx("textarea",{className:"bg-transparent text-sm w-full outline-none border border-transparent focus:border-warm-300 rounded-md p-1 transition-colors min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",style:{color:"var(--color-text-secondary)"},rows:3,placeholder:g("plannerForm.descPlaceholder"),value:O,onChange:A=>X(A.target.value),onPaste:be,onDrop:Ie,onDragOver:A=>{A.preventDefault(),A.stopPropagation()},onBlur:$e}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{var A;return(A=te.current)==null?void 0:A.click()},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[e.jsx(Ut,{size:12}),g("plannerForm.addImage")]}),e.jsx("span",{className:"text-[10px] text-warm-300",children:g("plannerForm.pasteHint")})]}),e.jsx("input",{ref:te,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:A=>{A.target.files&&de(A.target.files),A.target.value=""}}),J.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:J.map(A=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:os(t.id,A.id),alt:A.originalName,onClick:()=>pe(os(t.id,A.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),e.jsx("button",{type:"button",onClick:()=>He(A.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:A.originalName})})]},A.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.tags")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[d.map(A=>e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-2xs font-medium cursor-pointer hover:ring-1 hover:ring-warm-400 transition-all ${Pt(n.get(A)||"default")}`,onClick:he=>{w.current=he.currentTarget,ue(le===A?null:A)},children:[A,e.jsx("button",{onClick:he=>{he.stopPropagation(),Q(A)},className:"opacity-60 hover:opacity-100",children:e.jsx(ft,{size:12})})]}),le===A&&e.jsxs(cs,{anchorRef:w,width:180,onClose:()=>ue(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[e.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:g("plannerTag.color")}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:kc.map(he=>e.jsx("button",{onClick:async()=>{o&&await o(A,{color:he}),ue(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${n.get(A)===he?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:g(`plannerTag.color.${he}`),children:e.jsx("div",{className:`w-5 h-5 rounded-md ${ds[he].swatch}`})},he))})]})]},A)),e.jsxs("div",{className:"relative",children:[e.jsx("input",{ref:ae,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:N,onChange:A=>{L(A.target.value),Y(!0)},onKeyDown:A=>{(A.key==="Enter"||A.key===",")&&N.trim()&&(A.preventDefault(),Je(N.replace(",",""))),A.key==="Backspace"&&!N&&d.length>0&&Q(d[d.length-1])},onFocus:()=>Y(!0),onBlur:()=>setTimeout(()=>Y(!1),150)}),B&&W.length>0&&e.jsx(cs,{anchorRef:ae,width:160,onClose:()=>Y(!1),className:"rounded-lg shadow-elevated z-tooltip py-1 max-h-32 overflow-y-auto",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:W.slice(0,8).map(A=>e.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>Je(A),children:e.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium ${Pt(n.get(A)||"default")}`,children:A})},A))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.priority")}),e.jsxs("select",{className:"input-field text-xs w-full py-1",value:k,onChange:A=>Ne(Number(A.target.value)),children:[e.jsx("option",{value:0,children:g("plannerForm.priorityLow")}),e.jsx("option",{value:1,children:g("plannerForm.priorityNormal")}),e.jsx("option",{value:2,children:g("plannerForm.priorityHigh")}),e.jsx("option",{value:3,children:g("plannerForm.priorityCritical")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.dueDate")}),e.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:G,onChange:A=>Me(A.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:g("plannerForm.status")}),e.jsxs("select",{className:"input-field text-xs w-full py-1",value:v,onChange:A=>Re(A.target.value),children:[e.jsx("option",{value:"pending",children:g("plannerStatus.pending")}),e.jsx("option",{value:"in_progress",children:g("plannerStatus.in_progress")}),e.jsx("option",{value:"done",children:g("plannerStatus.done")})]})]})]})]})}),me&&e.jsx(ia,{src:me,onClose:()=>pe(null)})]})}let Sc=0;function _c({existingTags:t,editItem:n,initialDueDate:r,onSave:i,onCancel:l,onUpdateTag:a}){const{t:c}=ye(),[x,o]=s.useState(""),[g,f]=s.useState(""),[p,h]=s.useState([]),[m,j]=s.useState(""),[D,z]=s.useState(r??""),[K,F]=s.useState(0),[R,S]=s.useState("pending"),[H,_]=s.useState(!1),[O,X]=s.useState(!1),[k,se]=s.useState([]),[G,b]=s.useState([]),[v,y]=s.useState(null),d=s.useRef(null),C=s.useRef(null),N=s.useRef(null),[L,B]=s.useState(new Map),Y=new Map([...t.map(I=>[I.name,I.color]),...L]),le=["blue","green","orange","purple","pink","red","yellow","brown"];s.useEffect(()=>{var I;if(n){o(n.title),f(n.description??""),h(n.tags?JSON.parse(n.tags):[]),z(n.due_date??""),F(n.priority),S(n.status);try{b(n.images?JSON.parse(n.images):[])}catch{b([])}}(I=d.current)==null||I.focus()},[n]);const ue=t.filter(I=>!p.includes(I.name)&&(!m||I.name.toLowerCase().includes(m.toLowerCase()))),me=I=>{var ce;const U=I.trim();U&&!p.includes(U)&&h($e=>{const Ne=[...$e,U];if(!Y.has(U)){const Me=le[Y.size%le.length];B(Re=>new Map([...Re,[U,Me]]))}return Ne}),j(""),X(!0),(ce=C.current)==null||ce.focus()},pe=I=>h(p.filter(U=>U!==I)),ae=s.useCallback(I=>{const U=Array.from(I).filter(ce=>ce.type.startsWith("image/"));for(const ce of U){const $e=new FileReader;$e.onload=()=>{const Ne=$e.result,Me=`pending-${++Sc}`;se(Re=>[...Re,{id:Me,name:ce.name,data:Ne,preview:Ne}])},$e.readAsDataURL(ce)}},[]),w=s.useCallback(I=>{var $e;const U=($e=I.clipboardData)==null?void 0:$e.items;if(!U)return;const ce=[];for(let Ne=0;Ne<U.length;Ne++)if(U[Ne].type.startsWith("image/")){const Me=U[Ne].getAsFile();Me&&ce.push(Me)}ce.length!==0&&(I.preventDefault(),ae(ce))},[ae]),J=s.useCallback(I=>{var U;I.preventDefault(),I.stopPropagation(),(U=I.dataTransfer)!=null&&U.files&&ae(I.dataTransfer.files)},[ae]),M=I=>se(U=>U.filter(ce=>ce.id!==I)),te=I=>{n&&xa(n.id,I),b(U=>U.filter(ce=>ce.id!==I))},re=G.length+k.length,we=async()=>{if(x.trim()){_(!0);try{const I=await i({title:x.trim(),description:g.trim()||void 0,tags:p.length>0?JSON.stringify(p):void 0,due_date:D||void 0,priority:K,...n?{status:R}:{}});if(a&&L.size>0&&await Promise.all([...L.entries()].map(([U,ce])=>a(U,{color:ce}))),k.length>0){const U=(n==null?void 0:n.id)??(I==null?void 0:I.id);U&&await ma(U,k.map(ce=>({name:ce.name,data:ce.data})))}}finally{_(!1)}}};return e.jsxs("div",{className:"card p-5",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[e.jsx("input",{ref:d,className:"input-field text-sm w-full mb-3",placeholder:c("plannerForm.titlePlaceholder"),value:x,onChange:I=>o(I.target.value),onKeyDown:I=>{I.key==="Enter"&&I.preventDefault()}}),e.jsx("textarea",{className:"input-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:c("plannerForm.descPlaceholder"),value:g,onChange:I=>f(I.target.value),onPaste:w,onDrop:J,onDragOver:I=>{I.preventDefault(),I.stopPropagation()}}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsxs("button",{type:"button",onClick:()=>{var I;return(I=N.current)==null?void 0:I.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[e.jsx(Ut,{size:14}),c("plannerForm.addImage")]}),e.jsx("span",{className:"text-[10px] text-warm-300",children:c("plannerForm.pasteHint")})]}),e.jsx("input",{ref:N,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:I=>{I.target.files&&ae(I.target.files),I.target.value=""}}),re>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:c("plannerForm.images")}),e.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",re,")"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[G.map(I=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:n?os(n.id,I.id):"",alt:I.originalName,onClick:()=>n&&y(os(n.id,I.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),e.jsx("button",{type:"button",onClick:()=>te(I.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:I.originalName})})]},I.id)),k.map(I=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:I.preview,alt:I.name,onClick:()=>y(I.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),e.jsx("button",{type:"button",onClick:()=>M(I.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-status-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ft,{size:12})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:e.jsx("span",{className:"text-[8px] text-white truncate block",children:I.name})})]},I.id))]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.tags")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 p-2 rounded-xl",style:{backgroundColor:"var(--color-bg-input)",border:"1px solid var(--color-border-strong)"},children:[p.map(I=>e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Pt(Y.get(I)||"default")}`,children:[I,e.jsx("button",{onClick:()=>pe(I),className:"opacity-60 hover:opacity-100",children:e.jsx(ft,{size:12})})]},I)),e.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[e.jsx("input",{ref:C,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:p.length===0?c("plannerForm.tagsPlaceholder"):"",value:m,onChange:I=>{j(I.target.value),X(!0)},onKeyDown:I=>{(I.key==="Enter"||I.key===",")&&m.trim()&&(I.preventDefault(),me(m.replace(",",""))),I.key==="Backspace"&&!m&&p.length>0&&pe(p[p.length-1])},onFocus:()=>X(!0),onBlur:()=>setTimeout(()=>X(!1),150)}),O&&(ue.length>0||m.trim())&&e.jsxs(cs,{anchorRef:C,width:208,onClose:()=>X(!1),className:"rounded-lg shadow-elevated z-tooltip py-1.5 max-h-48 overflow-y-auto",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[ue.slice(0,10).map(I=>e.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>me(I.name),children:e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Pt(I.color)}`,children:I.name})},I.name)),m.trim()&&!t.some(I=>I.name===m.trim())&&e.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>me(m),children:e.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',m.trim(),'"']})})]})]})]})]}),e.jsxs("div",{className:`grid gap-3 mb-4 ${n?"grid-cols-3":"grid-cols-2"}`,children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.dueDate")}),e.jsx("input",{type:"date",className:"input-field text-xs w-full",value:D,onChange:I=>z(I.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.priority")}),e.jsxs("select",{className:"input-field text-xs w-full",value:K,onChange:I=>F(Number(I.target.value)),children:[e.jsx("option",{value:0,children:c("plannerForm.priorityLow")}),e.jsx("option",{value:1,children:c("plannerForm.priorityNormal")}),e.jsx("option",{value:2,children:c("plannerForm.priorityHigh")}),e.jsx("option",{value:3,children:c("plannerForm.priorityCritical")})]})]}),n&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:c("plannerForm.status")}),e.jsxs("select",{className:"input-field text-xs w-full",value:R,onChange:I=>S(I.target.value),children:[e.jsx("option",{value:"pending",children:c("plannerStatus.pending")}),e.jsx("option",{value:"in_progress",children:c("plannerStatus.in_progress")}),e.jsx("option",{value:"done",children:c("plannerStatus.done")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{className:"btn-ghost text-xs",onClick:l,children:c("plannerForm.cancel")}),e.jsx("button",{className:"btn-primary text-xs py-2",onClick:we,disabled:!x.trim()||H,children:c("plannerForm.save")})]}),v&&e.jsx(ia,{src:v,onClose:()=>y(null)})]})}function Ra({item:t,mode:n,projectCliTool:r,onConvert:i,onClose:l}){const{t:a}=ye(),[c,x]=s.useState(r||"claude"),[o,g]=s.useState(""),[f,p]=s.useState(!1),[h,m]=s.useState("once"),[j,D]=s.useState("0 0 * * *"),[z,K]=s.useState(""),[F,R]=s.useState(!1),S=async()=>{R(!0);try{n==="todo"?await i({cli_tool:c,max_turns:o?Number(o):void 0}):n==="session"?await i({cli_tool:c,use_worktree:f}):await i({cli_tool:c,schedule_type:h,cron_expression:h==="recurring"?j:void 0,run_at:h==="once"?z:void 0})}finally{R(!1)}};return e.jsx(vt,{open:!0,onClose:l,size:"md",position:"top",children:e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"text-sm font-semibold mb-4",style:{color:"var(--color-text-primary)"},children:a(n==="todo"?"plannerConvert.toTask":n==="session"?"plannerConvert.toTerminal":"plannerConvert.toSchedule")}),e.jsxs("p",{className:"text-xs text-warm-500 mb-4 truncate",children:['"',t.title,'"']}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.cliTool")}),e.jsxs("select",{className:"input-field text-xs w-full",value:c,onChange:H=>x(H.target.value),children:[e.jsx("option",{value:"claude",children:"Claude"}),e.jsx("option",{value:"antigravity",children:"Antigravity"}),e.jsx("option",{value:"codex",children:"Codex"})]})]}),n==="todo"&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.maxTurns")}),e.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:o,onChange:H=>g(H.target.value)})]}),n==="session"&&e.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:H=>p(H.target.checked)}),e.jsx("span",{className:"text-xs font-medium text-warm-500",children:a("plannerConvert.useWorktree")})]}),n==="schedule"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.scheduleType")}),e.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[e.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${h==="once"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>m("once"),children:a("plannerConvert.once")}),e.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${h==="recurring"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>m("recurring"),children:a("plannerConvert.recurring")})]})]}),h==="once"?e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.runAt")}),e.jsx("input",{type:"datetime-local",className:"input-field text-xs w-full",value:z,onChange:H=>K(H.target.value)})]}):e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:a("plannerConvert.cronExpression")}),e.jsx("input",{className:"input-field text-xs w-full font-mono",value:j,onChange:H=>D(H.target.value),placeholder:"0 0 * * *"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{className:"btn-ghost text-xs",onClick:l,children:a("plannerConvert.cancel")}),e.jsx("button",{className:"btn-primary btn-sm",onClick:S,disabled:F||n==="schedule"&&h==="once"&&!z,children:a("plannerConvert.convert")})]})]})})}function Mc(t){if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>typeof r=="string"):[]}catch{return[]}}function Dc({view:t,items:n,tagColors:r,onQuickAdd:i,onEditItem:l,onConvert:a,onDeleteItem:c,onUpdateRange:x}){const{t:o,lang:g}=ye(),[f,p]=s.useState(()=>new Date),[h,m]=s.useState(()=>Jt(new Date)),[j,D]=s.useState(null),z=el(),{gridDays:K,cols:F,dimOutOfMonth:R}=tl(t,f),S=Jt(new Date),H=f.getMonth(),_=t==="month"?3:99,O=ae=>p(w=>al(w,t,ae)),X=()=>{p(new Date),m(Jt(new Date))},k=sl(f,t,g);s.useEffect(()=>{t==="day"&&m(Jt(f))},[t,f]);const se=260,G=760,b=s.useRef(null),[v,y]=s.useState(()=>{const ae=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ae)&&ae>=se&&ae<=G?ae:320});s.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(v))}catch{}},[v]);const d=ae=>{ae.preventDefault();const w=M=>{var re;const te=(re=b.current)==null?void 0:re.getBoundingClientRect();te&&y(Math.min(G,Math.max(se,te.right-M.clientX)))},J=()=>{window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",J),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",w),window.addEventListener("pointerup",J)},[C,N]=s.useState(new Map);s.useEffect(()=>{N(new Map)},[n]);const L=s.useMemo(()=>C.size===0?n:n.map(ae=>{const w=C.get(ae.id);return w?{...ae,due_date:w.due_date,end_date:w.end_date}:ae}),[n,C]),B=s.useCallback((ae,w,J)=>{N(M=>new Map(M).set(ae,{due_date:w,end_date:J})),x(ae,w,J)},[x]),Y=ae=>!!(ae.due_date&&ae.end_date&&ae.end_date.slice(0,10)>ae.due_date.slice(0,10)),le=s.useMemo(()=>{const ae=new Map;for(const w of L){if(!w.due_date||t==="month"&&Y(w))continue;const J=w.due_date.slice(0,10),M=w.status==="done",te=ae.get(J)??[];te.push({key:w.id,title:w.title,bg:"var(--color-bg-secondary)",fg:M?"var(--color-text-muted)":"var(--color-text-secondary)",done:M,payload:w,draggable:!0}),ae.set(J,te)}return ae},[L,t]),ue=s.useMemo(()=>t!=="month"?[]:L.filter(Y).map(ae=>{const w=ae.status==="done";return{key:ae.id,title:ae.title,startKey:ae.due_date.slice(0,10),endKey:ae.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:w?"var(--color-text-muted)":"var(--color-text-secondary)",done:w,payload:ae}}),[L,t]),me=s.useMemo(()=>n.filter(ae=>ae.due_date&&ae.due_date.slice(0,10)===h),[n,h]),pe=s.useMemo(()=>n.filter(ae=>!ae.due_date),[n]);return e.jsxs("div",{ref:b,className:"card flex overflow-hidden",style:{minHeight:520},children:[e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[e.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[e.jsx("button",{onClick:()=>O(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:e.jsx(_l,{size:16})}),e.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:k}),e.jsx("button",{onClick:()=>O(1),className:"btn-ghost p-1.5","aria-label":"next",children:e.jsx(St,{size:16})}),e.jsx("button",{onClick:X,className:"btn-ghost text-xs px-2.5 py-1.5",children:o("agenda.today")})]}),e.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:e.jsx(nl,{view:t,gridDays:K,cols:F,dimOutOfMonth:R,monthIdx:H,todayKey:S,selectedDate:h,chipsByDay:le,maxChips:_,weekdayLabels:z,addItemLabel:o("agenda.addItem"),onSelectDate:m,onQuickAdd:i,onChipClick:ae=>l(ae.payload),onCellContextMenu:(ae,w)=>{w.preventDefault(),D({x:w.clientX,y:w.clientY,dateKey:ae})},bars:ue,onBarClick:ae=>l(ae.payload),onBarDrag:(ae,w,J)=>B(ae.payload.id,w,J),onChipDrag:(ae,w,J)=>B(ae.payload.id,w,J)})})]}),e.jsx("div",{onPointerDown:d,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:o("agenda.resizePanel")}),e.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:v},children:[e.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--color-text-primary)"},children:new Date(h+"T00:00").toLocaleDateString(g,{month:"long",day:"numeric",weekday:"short"})}),e.jsxs("button",{onClick:()=>i(h),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[e.jsx(gt,{size:14}),o("agenda.add")]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[me.length===0&&e.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:o("agenda.dayEmpty")}),me.map(ae=>e.jsx(In,{item:ae,tagColors:r,onEdit:l,onConvert:a,onDelete:c},ae.id))]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:o("agenda.backlog")}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[pe.length===0&&e.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:o("agenda.backlogEmpty")}),pe.map(ae=>e.jsx(In,{item:ae,tagColors:r,onEdit:l,onConvert:a,onDelete:c},ae.id))]})]})]})]}),j&&e.jsx(yt,{x:j.x,y:j.y,onClose:()=>D(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>i(j.dateKey),children:[e.jsx(gt,{size:14}),o("planner.add")]})})]})}function In({item:t,tagColors:n,onEdit:r,onConvert:i,onDelete:l}){const{t:a}=ye(),{confirm:c}=_t(),[x,o]=s.useState(!1),[g,f]=s.useState(!1),[p,h]=s.useState({top:0,left:0}),m=s.useRef(null),j=s.useRef(null),D=Mc(t.tags),z=t.status==="moved",K=s.useCallback(()=>{if(!m.current)return;const F=m.current.getBoundingClientRect(),R=window.innerWidth,S=window.innerHeight;let H=F.bottom+4;const _=j.current;if(_){const O=_.offsetWidth,X=_.offsetHeight;let k=F.right-O;k<8&&(k=8),k+O>R-8&&(k=R-8-O),H+X>S-8&&(H=F.top-X-4),h({top:H,left:k}),f(!0)}else h({top:H,left:Math.max(8,F.right-180)})},[]);return s.useEffect(()=>{if(!x){f(!1);return}K();const F=requestAnimationFrame(K),R=S=>{var _,O;const H=S.target;(_=m.current)!=null&&_.contains(H)||(O=j.current)!=null&&O.contains(H)||o(!1)};return document.addEventListener("mousedown",R),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{cancelAnimationFrame(F),document.removeEventListener("mousedown",R),window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[x,K]),e.jsxs("div",{className:`group flex items-start gap-2 rounded-lg px-2.5 py-2 ${z?"opacity-50":""}`,style:{backgroundColor:"var(--color-bg-secondary)"},children:[e.jsxs("button",{onClick:()=>r(t),className:"flex-1 text-left min-w-0",children:[e.jsx("div",{className:"text-sm truncate",style:{color:"var(--color-text-primary)",textDecoration:t.status==="done"?"line-through":"none"},children:t.title}),t.description&&e.jsx("div",{className:"text-2xs truncate",style:{color:"var(--color-text-muted)"},children:t.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-2xs font-medium ${us[t.status]||us.pending}`,children:a(`plannerStatus.${t.status}`)}),D.map(F=>e.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Pt(n.get(F)||"default")}`,children:F},F))]})]}),e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx("button",{ref:m,onClick:F=>{F.stopPropagation(),o(!x)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors opacity-0 group-hover:opacity-100",children:e.jsx(Us,{size:14})}),x&&jt.createPortal(e.jsxs("div",{ref:j,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:p.top,left:p.left,opacity:g?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>o(!1),children:[!z&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>i(t,"todo"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(ua,{size:12})," ",a("planner.convertToTask")]}),e.jsxs("button",{onClick:()=>i(t,"schedule"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(zt,{size:12})," ",a("planner.convertToSchedule")]}),e.jsxs("button",{onClick:()=>i(t,"session"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[e.jsx(Bt,{size:12})," ",a("planner.convertToTerminal")]})]}),e.jsxs("button",{onClick:async()=>{await c({message:a("planner.deleteConfirm"),danger:!0})&&l(t.id)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left",children:[e.jsx(wt,{size:12})," ",a("planner.delete")]})]}),document.body)]})]})}const Hn={pending:0,in_progress:1,done:2,moved:3};function Ec({plannerItems:t,existingTags:n,projectCliTool:r,onAddItem:i,onEditItem:l,onDeleteItem:a,onConvertToTodo:c,onConvertToSchedule:x,onConvertToSession:o,onUpdateTag:g,onDeleteTag:f,onExport:p,onImport:h,view:m,onChangeView:j}){const{t:D}=ye(),{warning:z}=aa(),[K,F]=s.useState(!1),[R,S]=s.useState(null),[H,_]=s.useState(void 0),[O,X]=s.useState(""),[k,se]=s.useState(""),[G,b]=s.useState("created_at"),[v,y]=s.useState("desc"),[d,C]=s.useState(null),[N,L]=s.useState("todo"),[B,Y]=s.useState(!1),[le,ue]=s.useState(!1),[me,pe]=s.useState(null),ae=s.useRef(null),w=s.useRef(0),J=async()=>{if(!(!p||B)){Y(!0);try{await p()}finally{Y(!1)}}},M=()=>{var Q;!h||B||(Q=ae.current)==null||Q.click()},te=async Q=>{var de;const W=(de=Q.target.files)==null?void 0:de[0];if(Q.target.value="",!(!W||!h)){Y(!0);try{await h(W)}finally{Y(!1)}}},re=Q=>!!(/\.(md|markdown)$/i.test(Q.name)||Q.type==="text/markdown"),we=Q=>Array.from(Q.dataTransfer.types).includes("Files"),I=Q=>{!h||B||we(Q)&&(Q.preventDefault(),w.current++,ue(!0))},U=Q=>{!h||B||we(Q)&&(Q.preventDefault(),Q.dataTransfer.dropEffect="copy")},ce=Q=>{h&&(Q.preventDefault(),w.current=Math.max(0,w.current-1),w.current===0&&ue(!1))},$e=async Q=>{var de;if(!h||(Q.preventDefault(),w.current=0,ue(!1),B))return;const W=(de=Q.dataTransfer.files)==null?void 0:de[0];if(W){if(!re(W)){z(D("planner.dropInvalidFile"));return}Y(!0);try{await h(W)}finally{Y(!1)}}},Ne=s.useMemo(()=>n.map(Q=>Q.name),[n]),Me=s.useMemo(()=>new Map(n.map(Q=>[Q.name,Q.color])),[n]),Re=s.useMemo(()=>{let Q=t.filter(W=>!(k&&W.status!==k||O&&!(W.tags?(()=>{try{return JSON.parse(W.tags)}catch{return[]}})():[]).includes(O)));return Q=[...Q].sort((W,de)=>{let be=0;switch(G){case"title":be=W.title.localeCompare(de.title);break;case"tags":{const Ie=W.tags?(()=>{try{return JSON.parse(W.tags).join(",")}catch{return""}})():"",He=de.tags?(()=>{try{return JSON.parse(de.tags).join(",")}catch{return""}})():"";be=(Ie||"zzz").localeCompare(He||"zzz");break}case"priority":be=W.priority-de.priority;break;case"due_date":{const Ie=W.due_date||"9999",He=de.due_date||"9999";be=Ie.localeCompare(He);break}case"status":be=(Hn[W.status]??9)-(Hn[de.status]??9);break;case"created_at":be=W.created_at.localeCompare(de.created_at);break}return v==="asc"?be:-be}),Q},[t,O,k,G,v]),De=Q=>{G===Q?y(W=>W==="asc"?"desc":"asc"):(b(Q),y(Q==="priority"?"desc":"asc"))},Je=({field:Q})=>G!==Q?null:v==="asc"?e.jsx(Pl,{size:12,className:"inline ml-0.5"}):e.jsx(El,{size:12,className:"inline ml-0.5"});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-5 gap-3 flex-wrap",children:[e.jsxs("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:[D("planner.title"),e.jsx("span",{className:"ml-1 text-warm-400",children:t.length})]}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[m!=="table"&&e.jsx("div",{className:"flex gap-0.5 p-0.5 rounded-lg shrink-0",style:{backgroundColor:"var(--color-bg-tertiary)"},children:["month","week","day"].map(Q=>e.jsx("button",{onClick:()=>j(Q),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:m===Q?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:D(`agenda.view.${Q}`)},Q))}),e.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:O,onChange:Q=>X(Q.target.value),children:[e.jsx("option",{value:"",children:D("planner.filterTag")}),Ne.map(Q=>e.jsx("option",{value:Q,children:Q},Q))]}),e.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:k,onChange:Q=>se(Q.target.value),children:[e.jsx("option",{value:"",children:D("planner.filterStatus")}),e.jsx("option",{value:"pending",children:D("plannerStatus.pending")}),e.jsx("option",{value:"in_progress",children:D("plannerStatus.in_progress")}),e.jsx("option",{value:"done",children:D("plannerStatus.done")}),e.jsx("option",{value:"moved",children:D("plannerStatus.moved")})]}),p&&e.jsxs("button",{onClick:J,disabled:B||t.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:D("planner.exportTooltip"),children:[e.jsx(la,{size:14,className:"inline-block shrink-0"}),D("planner.export")]}),h&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:M,disabled:B,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:D("planner.importTooltip"),children:[e.jsx(vn,{size:14,className:"inline-block shrink-0"}),D("planner.import")]}),e.jsx("input",{ref:ae,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:te})]}),!K&&!R&&e.jsxs("button",{onClick:()=>F(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[e.jsx(gt,{size:14,className:"inline-block shrink-0"}),D("planner.add")]})]})]}),(K||R)&&e.jsx("div",{className:"mb-5",children:e.jsx(_c,{existingTags:n,editItem:R,initialDueDate:H,onSave:async Q=>{if(R){await l(R.id,Q),S(null);return}else{const W=await i(Q);return F(!1),_(void 0),W}},onCancel:()=>{F(!1),S(null),_(void 0)},onUpdateTag:g})}),m==="table"?e.jsxs("div",{className:"card relative",onDragEnter:h?I:void 0,onDragOver:h?U:void 0,onDragLeave:h?ce:void 0,onDrop:h?$e:void 0,onContextMenu:Q=>{$t(Q)||(Q.preventDefault(),pe({x:Q.clientX,y:Q.clientY}))},children:[le&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center pointer-events-none rounded-xl border-2 border-dashed",style:{borderColor:"var(--color-accent, #3b82f6)",backgroundColor:"var(--color-bg-secondary, rgba(59, 130, 246, 0.08))",backdropFilter:"blur(2px)"},children:e.jsxs("div",{className:"text-center",children:[e.jsx(vn,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),e.jsx("div",{className:"text-sm font-semibold",children:D("planner.dropHint")}),e.jsx("div",{className:"text-xs text-warm-500 mt-1",children:D("planner.dropHintSub")})]})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-3 px-4 py-2 rounded-t-xl select-none",style:{backgroundColor:"var(--color-bg-tertiary)",borderBottom:"1px solid var(--color-border-muted)"},children:[e.jsx("div",{className:"w-[14px] flex-shrink-0"}),e.jsxs("div",{className:"flex-1 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("title"),children:[D("planner.col.title"),e.jsx(Je,{field:"title"})]}),e.jsxs("div",{className:"w-[160px] section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("tags"),children:[D("planner.col.tags"),e.jsx(Je,{field:"tags"})]}),e.jsxs("div",{className:"w-12 text-center section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("priority"),children:[D("plannerForm.priority"),e.jsx(Je,{field:"priority"})]}),e.jsxs("div",{className:"hidden md:block w-20 text-right section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("due_date"),children:[D("planner.col.dueDate"),e.jsx(Je,{field:"due_date"})]}),e.jsxs("div",{className:"w-16 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>De("status"),children:[D("planner.col.status"),e.jsx(Je,{field:"status"})]}),e.jsx("div",{className:"w-8"})]}),Re.length===0?e.jsx(At,{icon:oi,title:D("planner.empty"),description:D("planner.emptyHint")}):Re.map((Q,W)=>e.jsx("div",{children:e.jsx(Cc,{item:Q,tagColors:Me,existingTags:Ne,onSave:async(de,be)=>{await l(de,be)},onDelete:()=>a(Q.id),onConvertToTodo:()=>{C(Q),L("todo")},onConvertToSchedule:()=>{C(Q),L("schedule")},onConvertToSession:()=>{C(Q),L("session")},onUpdateTag:g})},Q.id))]}):e.jsx(Dc,{view:m,items:Re,tagColors:Me,onQuickAdd:Q=>{S(null),_(Q),F(!0)},onEditItem:Q=>{F(!1),S(Q)},onConvert:(Q,W)=>{C(Q),L(W)},onDeleteItem:a,onUpdateRange:(Q,W,de)=>{l(Q,{due_date:W,end_date:de})}}),d&&e.jsx(Ra,{item:d,mode:N,projectCliTool:r,onConvert:async Q=>{N==="todo"?await c(d.id,Q):N==="session"?await o(d.id,Q):await x(d.id,Q),C(null)},onClose:()=>C(null)}),me&&e.jsx(yt,{x:me.x,y:me.y,onClose:()=>pe(null),children:e.jsxs("button",{type:"button",className:Be,onClick:()=>{S(null),_(void 0),F(!0)},children:[e.jsx(gt,{size:14}),D("planner.add")]})})]})}const $a=s.createContext(null),Tc=$a.Provider;function td(){const t=s.useContext($a);if(!t)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return t}const Rc=s.lazy(()=>hs(()=>import("./PlannerPageEditor-9_jJ-l98.js").then(t=>t.a),__vite__mapDeps([13,1,2,5,14,15,11,16]))),$c=800;function Lc({pageId:t,projectId:n,projectCliTool:r,existingTags:i,onTitleChange:l,onConvertToTodo:a,onConvertToSchedule:c,onConvertToSession:x}){const{t:o}=ye(),[g,f]=s.useState(null),[p,h]=s.useState("idle"),[m,j]=s.useState(null),D=s.useRef({title:"",content:null}),z=s.useRef(null);s.useEffect(()=>{let _=!1;return Ki(t).then(O=>{_||(f(O),D.current={title:O.title,content:O.content??null})}),()=>{_=!0}},[t]);const K=s.useCallback(()=>{z.current&&(clearTimeout(z.current),z.current=null);const{title:_,content:O}=D.current;return h("saving"),Ui(t,{title:_,content:O??void 0}).then(()=>h("saved"))},[t]);s.useEffect(()=>()=>{z.current&&K()},[K]);const F=s.useCallback(()=>{z.current&&clearTimeout(z.current),h("saving"),z.current=setTimeout(()=>{K()},$c)},[K]),R=_=>{D.current.title=_,f(O=>O&&{...O,title:_}),l(t,_),F()},S=_=>{D.current.content=_,F()},H=s.useCallback((_,O,X)=>{j({item:_,mode:O,onDone:X})},[]);return g?e.jsxs(Tc,{value:{projectId:n,pageId:t,projectCliTool:r,existingTags:i,openConvert:H},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[e.jsx("input",{value:g.title,onChange:_=>R(_.target.value),placeholder:o("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),e.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:p==="saving"?o("planner.pages.saving"):p==="saved"?o("planner.pages.saved"):""})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:e.jsx(s.Suspense,{fallback:null,children:e.jsx(Rc,{pageId:t,initialContent:g.content??null,onChange:S})})})]}),m&&e.jsx(Ra,{item:m.item,mode:m.mode,projectCliTool:r,onConvert:async _=>{const{item:O,mode:X,onDone:k}=m;X==="todo"?await a(O.id,_):X==="session"?await x(O.id,_):await c(O.id,_),k==null||k(),j(null)},onClose:()=>j(null)})]}):null}const dt=(t,n)=>({type:"heading",props:{level:t},content:n}),Ot=t=>t?{type:"paragraph",content:t}:{type:"paragraph"},On=t=>t?{type:"bulletListItem",content:t}:{type:"bulletListItem"},Et=t=>t?{type:"checkListItem",content:t}:{type:"checkListItem"},Wn=()=>({type:"tasklist"}),Bn=()=>({type:"calendar"}),Fc=[{id:"blank",labelKey:"planner.tpl.blank",descKey:"planner.tpl.blank.desc",title:"",blocks:null},{id:"meeting",labelKey:"planner.tpl.meeting",descKey:"planner.tpl.meeting.desc",title:"회의 노트",blocks:[dt(1,"회의 노트"),Ot("날짜: "),Ot("참석자: "),dt(2,"안건"),On(),dt(2,"논의"),Ot(),dt(2,"액션 아이템"),Wn()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[dt(1,"프로젝트 플랜"),dt(2,"개요"),Ot(),dt(2,"마일스톤"),Wn(),dt(2,"일정"),Bn(),dt(2,"리스크 / 메모"),Ot()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[dt(1,"위클리 플래너"),dt(2,"이번 주 목표"),On(),dt(2,"요일별 할 일"),dt(3,"월요일"),Et(),dt(3,"화요일"),Et(),dt(3,"수요일"),Et(),dt(3,"목요일"),Et(),dt(3,"금요일"),Et(),dt(3,"토요일"),Et(),dt(3,"일요일"),Et(),dt(2,"주간 일정"),Bn()]}];function zc({onResize:t}){return e.jsx("div",{role:"separator","aria-orientation":"vertical",onPointerDown:n=>{n.preventDefault();const r=n.currentTarget;r.setPointerCapture(n.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none";let i=null,l=null;const a=()=>{if(i=null,l===null)return;const o=l;l=null,t(o)},c=o=>{l=o.clientX,i===null&&(i=requestAnimationFrame(a))},x=o=>{i!==null&&cancelAnimationFrame(i),i=null,o.type==="pointerup"&&l!==null&&a(),l=null,document.body.style.cursor="",document.body.style.userSelect="",r.removeEventListener("pointermove",c),r.removeEventListener("pointerup",x),r.removeEventListener("pointercancel",x)};r.addEventListener("pointermove",c),r.addEventListener("pointerup",x),r.addEventListener("pointercancel",x)},className:"w-1.5 shrink-0 cursor-col-resize bg-warm-300 hover:bg-accent active:bg-accent transition-colors"})}const Kn=160,Un=480,Vn="plannerSidebarWidth",Gn="plannerSidebarCollapsed";function Pc({projectId:t,...n}){const{t:r}=ye(),{confirm:i}=_t(),[l,a]=s.useState([]),[c,x]=s.useState({kind:"work"}),[o,g]=s.useState("table"),[f,p]=s.useState(!1),[h,m]=s.useState({top:0,left:0}),j=s.useRef(null),D=s.useRef(null),z=s.useRef(!1),[K,F]=s.useState(()=>{const L=Number(localStorage.getItem(Vn));return L>=Kn&&L<=Un?L:208}),R=s.useCallback(L=>{var le;const B=((le=D.current)==null?void 0:le.getBoundingClientRect().left)??0,Y=Math.round(Math.max(Kn,Math.min(Un,L-B)));F(Y),localStorage.setItem(Vn,String(Y))},[]),[S,H]=s.useState(()=>localStorage.getItem(Gn)==="1"),_=()=>H(L=>(localStorage.setItem(Gn,L?"0":"1"),!L)),O=240,X=()=>{var B;const L=(B=j.current)==null?void 0:B.getBoundingClientRect();if(L){const Y=Math.min(L.left,window.innerWidth-O-8);m({top:L.bottom+4,left:Math.max(8,Y)})}p(!0)};s.useEffect(()=>{if(!f)return;const L=()=>p(!1),B=Y=>{var le;(le=j.current)!=null&&le.contains(Y.target)||Y.target.closest("[data-template-picker]")||p(!1)};return document.addEventListener("mousedown",B),window.addEventListener("scroll",L,!0),window.addEventListener("resize",L),()=>{document.removeEventListener("mousedown",B),window.removeEventListener("scroll",L,!0),window.removeEventListener("resize",L)}},[f]),s.useEffect(()=>{Wi(t).then(L=>{a(L),z.current||(z.current=!0,L.length>0&&x({kind:"page",id:L[0].id}))})},[t]);const k=async L=>{p(!1);const B=await Bi(t,L.title||r("planner.pages.untitled"),L.blocks?JSON.stringify(L.blocks):void 0);a(Y=>[...Y,B]),x({kind:"page",id:B.id})},se=async L=>{await i({message:r("planner.pages.deleteConfirm"),danger:!0})&&(await Vi(L),a(B=>B.filter(Y=>Y.id!==L)),x(B=>B.kind==="page"&&B.id===L?{kind:"work"}:B))},G=s.useCallback((L,B)=>{a(Y=>Y.map(le=>le.id===L?{...le,title:B}:le))},[]),b=()=>{x({kind:"work"}),g(L=>L==="table"?"month":L)},v=()=>{x({kind:"work"}),g("table")},y=c.kind==="work",d=y&&o!=="table",C=y&&o==="table",N=(L,B,Y,le,ue)=>e.jsxs("div",{onClick:B,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${L?"":"hover:bg-warm-50"}`,style:L?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[Y,e.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:le}),ue]});return e.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[S?e.jsx("div",{className:"flex-shrink-0 flex flex-col items-center card p-1.5",children:e.jsx("button",{onClick:_,className:"p-1 text-warm-400 hover:text-warm-600 transition-colors",title:r("sidebar.expand"),children:e.jsx(Ir,{size:14})})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:D,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:K},children:[e.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[e.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:r("planner.view.pages")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{ref:j,onClick:()=>f?p(!1):X(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:r("planner.pages.new"),children:e.jsx(gt,{size:14})}),e.jsx("button",{onClick:_,className:"text-warm-400 hover:text-warm-600 transition-colors",title:r("sidebar.collapse"),children:e.jsx(Hr,{size:14})})]})]}),l.map(L=>N(c.kind==="page"&&c.id===L.id,()=>x({kind:"page",id:L.id}),e.jsx(ss,{size:14,className:"text-warm-400 flex-shrink-0"}),L.title||r("planner.pages.untitled"),e.jsx("button",{onClick:B=>{B.stopPropagation(),se(L.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-status-error transition-all flex-shrink-0",children:e.jsx(wt,{size:14})}))),e.jsx("div",{className:"px-2.5 pt-3 pb-1 text-2xs font-semibold uppercase tracking-wider text-warm-400",children:r("planner.view.all")}),N(d,b,e.jsx(zs,{size:14,className:"text-warm-400 flex-shrink-0"}),r("planner.nav.calendar")),N(C,v,e.jsx(is,{size:14,className:"text-warm-400 flex-shrink-0"}),r("planner.nav.list"))]}),e.jsx(zc,{onResize:R})]}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:c.kind==="page"?e.jsx("div",{className:"card flex flex-col flex-1",children:e.jsx(Lc,{pageId:c.id,projectId:t,projectCliTool:n.projectCliTool,existingTags:n.existingTags,onTitleChange:G,onConvertToTodo:n.onConvertToTodo,onConvertToSchedule:n.onConvertToSchedule,onConvertToSession:n.onConvertToSession},c.id)}):e.jsx(Ec,{...n,view:o,onChangeView:g})}),f&&jt.createPortal(e.jsx("div",{"data-template-picker":!0,className:"fixed z-tooltip rounded-xl py-1 shadow-elevated",style:{top:h.top,left:h.left,width:O,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:Fc.map(L=>e.jsxs("button",{onClick:()=>k(L),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[e.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:r(L.labelKey)}),e.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:r(L.descKey)})]},L.id))}),document.body)]})}const La="webPanelTabs",Fa="webPanelFavorites",Ac="plannerWebPanelUrl",Ys="https://www.notion.so",Ic="electronAPI"in window;function Hc(t){const n=t.trim();return n?/^https?:\/\//i.test(n)?n:`https://${n}`:Ys}function Os(t=""){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,8),src:t,url:t,title:""}}function Oc(){var n;try{const r=JSON.parse(localStorage.getItem(La)||"");if((n=r.tabs)!=null&&n.length){const i=r.tabs.map(({id:a,url:c})=>({id:a,src:c,url:c,title:""})),l=i.some(a=>a.id===r.activeId)?r.activeId:i[0].id;return{tabs:i,activeId:l}}}catch{}const t=Os(localStorage.getItem(Ac)||Ys);return{tabs:[t],activeId:t.id}}function Wc(){try{const t=JSON.parse(localStorage.getItem(Fa)||"");return Array.isArray(t)?t:[]}catch{return[]}}function Bc({visible:t=!0}={}){const{t:n}=ye(),[{tabs:r,activeId:i},l]=s.useState(Oc),a=r.find(v=>v.id===i)??r[0],[c,x]=s.useState(()=>new Set);s.useEffect(()=>{t&&x(v=>v.has(a.id)?v:new Set(v).add(a.id))},[t,a.id]);const[o,g]=s.useState(a.url),[f,p]=s.useState(Wc),[h,m]=s.useState(!1),[j,D]=s.useState(!1),z=h&&j,K=s.useRef(null),F=s.useRef(null),R=s.useRef(new Map);s.useEffect(()=>{localStorage.setItem(La,JSON.stringify({tabs:r.map(({id:v,url:y})=>({id:v,url:y})),activeId:i}))},[r,i]),s.useEffect(()=>{localStorage.setItem(Fa,JSON.stringify(f))},[f]),s.useEffect(()=>{g(a.url)},[a.id,a.url]);const S=s.useCallback((v,y)=>{l(d=>({...d,tabs:d.tabs.map(C=>C.id===v?{...C,...y}:C)}))},[]),H=s.useCallback((v="")=>{var d;const y=Os(v);l(C=>({tabs:[...C.tabs,y],activeId:y.id})),v||(d=K.current)==null||d.focus()},[]),_=v=>{l(y=>{const d=y.tabs.findIndex(N=>N.id===v),C=y.tabs.filter(N=>N.id!==v);if(C.length===0){const N=Os();return{tabs:[N],activeId:N.id}}return y.activeId!==v?{...y,tabs:C}:{tabs:C,activeId:C[Math.min(d,C.length-1)].id}})},O=()=>{const v=Hc(o);g(v),S(a.id,{src:v,url:v})};s.useEffect(()=>{var y;const v=window.electronAPI;return(y=v==null?void 0:v.onWebPanelOpenUrl)==null?void 0:y.call(v,d=>H(d))},[H]),s.useEffect(()=>{const v=F.current;if(!v)return;const y=()=>{v.style.pointerEvents="none"},d=()=>{v.style.pointerEvents=""};return window.addEventListener("mousedown",y,!0),window.addEventListener("mouseup",d,!0),window.addEventListener("blur",d),()=>{window.removeEventListener("mousedown",y,!0),window.removeEventListener("mouseup",d,!0),window.removeEventListener("blur",d)}},[]);const X=s.useCallback(v=>{if(!v)return;const y=v,d=v.dataset.tabId;R.current.set(d,y);const C=L=>S(d,{title:L.title}),N=L=>{const{url:B,isMainFrame:Y}=L;Y!==!1&&S(d,{url:B,canGoBack:y.canGoBack()})};return v.addEventListener("page-title-updated",C),v.addEventListener("did-navigate",N),v.addEventListener("did-navigate-in-page",N),()=>{R.current.delete(d),v.removeEventListener("page-title-updated",C),v.removeEventListener("did-navigate",N),v.removeEventListener("did-navigate-in-page",N)}},[S]),k=v=>{if(v.title)return v.title;try{return new URL(v.url).hostname}catch{return n("web.newTab")}},se=f.some(v=>v.url===a.url),G=()=>{a.url&&p(v=>se?v.filter(y=>y.url!==a.url):[...v,{url:a.url,title:k(a)}])},b=v=>p(y=>y.filter(d=>d.url!==v));return e.jsxs("div",{className:h?"fixed inset-0 z-modal flex flex-col":"flex flex-col flex-1 min-h-0",style:h?{backgroundColor:"var(--color-bg-card)"}:void 0,onKeyDown:v=>{(v.ctrlKey||v.metaKey)&&!v.altKey&&!v.shiftKey&&v.key.toLowerCase()==="t"&&(v.preventDefault(),H())},children:[e.jsxs("div",{role:"tablist",className:`${z?"hidden":"flex"} items-end gap-0.5 px-2 border-b border-theme-border overflow-x-auto`,children:[r.map(v=>e.jsxs("div",{role:"tab","aria-selected":v.id===i,onClick:()=>l(y=>({...y,activeId:v.id})),onMouseDown:y=>{y.button===1&&y.preventDefault()},onAuxClick:y=>{y.button===1&&(y.preventDefault(),_(v.id))},className:`flex items-center gap-1 px-3 py-1.5 text-xs whitespace-nowrap cursor-pointer transition-colors ${v.id===i?"border-b-2 border-accent text-accent font-medium":"text-theme-text-secondary hover:text-theme-text"}`,children:[e.jsx("span",{className:"truncate max-w-[160px]",children:k(v)}),e.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),_(v.id)},className:"p-0.5 rounded hover:bg-theme-hover",title:n("web.closeTab"),"aria-label":n("web.closeTab"),children:e.jsx(ft,{size:12})})]},v.id)),e.jsx("button",{type:"button",onClick:()=>H(),className:"p-1 mb-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:n("web.newTab"),"aria-label":n("web.newTab"),children:e.jsx(gt,{size:14})})]}),e.jsxs("form",{onSubmit:v=>{v.preventDefault(),O()},className:`${z?"hidden":"flex"} items-center gap-2 p-2 border-b border-theme-border`,children:[e.jsx("button",{type:"button",onClick:()=>{var v;return(v=R.current.get(a.id))==null?void 0:v.goBack()},disabled:!a.canGoBack,className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0 disabled:opacity-40 disabled:pointer-events-none",title:n("web.back"),"aria-label":n("web.back"),children:e.jsx(Ll,{size:14})}),e.jsx("input",{ref:K,value:o,onChange:v=>g(v.target.value),placeholder:n("web.urlPlaceholder"),className:"input-field flex-1",spellCheck:!1}),e.jsx("button",{type:"button",onClick:G,disabled:!a.url,"aria-pressed":se,className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0 disabled:opacity-40 disabled:pointer-events-none",title:n(se?"web.removeFavorite":"web.addFavorite"),"aria-label":n(se?"web.removeFavorite":"web.addFavorite"),children:e.jsx(ji,{size:14,fill:se?"currentColor":"none",className:se?"text-accent":void 0})}),e.jsx("button",{type:"button",onClick:()=>window.open(a.url,"_blank","noopener"),disabled:!a.url,className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0 disabled:opacity-40 disabled:pointer-events-none",title:n("web.openExternal"),"aria-label":n("web.openExternal"),children:e.jsx(Rs,{size:14})}),e.jsx(Ze,{type:"submit",size:"sm",children:n("web.go")}),h&&e.jsx("button",{type:"button",onClick:()=>D(!0),className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:n("web.hideBar"),"aria-label":n("web.hideBar"),children:e.jsx(Or,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{m(v=>!v),D(!1)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:n(h?"web.exitFullscreen":"web.fullscreen"),children:h?e.jsx(Wr,{size:14}):e.jsx($s,{size:14})})]}),f.length>0&&e.jsx("div",{className:`${z?"hidden":"flex"} items-center gap-1 px-2 py-1 border-b border-theme-border overflow-x-auto`,children:f.map(v=>e.jsxs("div",{className:"group flex items-center flex-shrink-0 rounded-md hover:bg-theme-hover",children:[e.jsx("button",{type:"button",onClick:()=>S(a.id,{src:v.url,url:v.url}),className:"px-2 py-0.5 text-xs text-theme-text-secondary hover:text-theme-text truncate max-w-[160px]",title:v.url,children:v.title}),e.jsx("button",{type:"button",onClick:()=>b(v.url),className:"p-0.5 mr-0.5 rounded opacity-0 group-hover:opacity-100 focus:opacity-100 hover:bg-theme-hover",title:n("web.removeFavorite"),"aria-label":`${n("web.removeFavorite")}: ${v.title}`,children:e.jsx(ft,{size:10})})]},v.url))}),z&&e.jsx("button",{type:"button",onClick:()=>D(!1),className:"absolute top-0 left-1/2 -translate-x-1/2 z-10 px-3 py-0.5 rounded-b-md bg-theme-card border border-t-0 border-theme-border shadow-card text-warm-400 hover:text-warm-600 transition-colors",title:n("web.showBar"),"aria-label":n("web.showBar"),children:e.jsx(ms,{size:14})}),e.jsx("div",{ref:F,className:"flex-1 min-h-0 flex flex-col",children:Ic?r.map(v=>v.src&&c.has(v.id)?s.createElement("webview",{key:v.id,ref:X,"data-tab-id":v.id,src:v.src,partition:"persist:webpanel",allowpopups:"",className:v.id===i?"flex-1 min-h-0":"hidden"}):v.id===i&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-theme-text-secondary",children:n("web.emptyTab")},v.id)):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-sm text-theme-text-secondary",children:[e.jsx("span",{children:n("web.desktopOnly")}),e.jsxs(Ze,{size:"sm",className:"flex items-center gap-1.5",onClick:()=>window.open(a.url||Ys,"_blank","noopener"),children:[e.jsx(Rs,{size:14}),n("web.openExternal")]})]})})]})}const Kc=s.lazy(()=>hs(()=>import("./AnalyticsPanel-Dr9Zypd4.js"),__vite__mapDeps([17,1,2,15,5,4]))),Uc=s.lazy(()=>hs(()=>import("./VaultLayout-DftlF-Gd.js"),__vite__mapDeps([18,1,2,8,7,14,3,4,5,6,10,11,9,12])));function Vc({onEvent:t,connected:n,sendMessage:r,subscribeBinary:i}){const{id:l}=Br(),[a,c]=s.useState(null),[x,o]=s.useState([]),[g,f]=s.useState([]),[p,h]=s.useState(null),[m,j]=s.useState([]),[D,z]=s.useState([]),[K,F]=s.useState([]),[R,S]=s.useState([]),[H,_]=Kr(),O=["tasks","loops","discussions","schedules","analytics"],X=H.get("tab")||"tasks",[k,se]=s.useState(O.includes(X)?"automation":X),[G,b]=s.useState(O.includes(X)?X:"tasks"),v=s.useCallback(u=>{if(u==="automation"){se("automation"),_(G==="tasks"?{}:{tab:G},{replace:!0});return}se(u),_(u==="tasks"?{}:{tab:u},{replace:!0})},[_,G]),y=s.useCallback(u=>{se("automation"),b(u),_(u==="tasks"?{}:{tab:u},{replace:!0})},[_]),d=s.useMemo(()=>{if(!a)return[];let u=[];try{u=JSON.parse(a.hidden_tabs||"[]")}catch{}return a.is_git_repo||u.push("git"),a.svn_enabled||u.push("svn"),u},[a]);s.useEffect(()=>{d.includes(k)&&v("automation")},[d,k,v]);const[C,N]=s.useState(!0),[L,B]=s.useState(!1),[Y,le]=s.useState(new Set),ue=x.filter(u=>!!u.loop_config),me=x.filter(u=>!u.loop_config),[pe,ae]=s.useState(0),{t:w}=ye(),{success:J,error:M,info:te}=aa(),{sendNotification:re}=Ur(),we=s.useRef([]);s.useEffect(()=>{we.current=m},[m]),s.useEffect(()=>{l&&Promise.all([Vr(l),vs(l),wn(l),hn(l),Fi(),Gr(l),Xt(l),Zt(l)]).then(([u,E,T,ee,ie,ke,Ve,ht])=>{c(u),o(E),f(T),j(ee),z(ke),F(Ve),S(ht),ie.resetsAt&&h(ie.resetsAt);const at=E.filter($=>$.status==="running"&&$.execution_mode==="interactive").map($=>$.id);at.length>0&&le(new Set(at))}).catch(()=>B(!0)).finally(()=>N(!1))},[l]);const I=s.useRef(x);I.current=x,s.useEffect(()=>{if(!l)return;const u=setInterval(()=>{I.current.some(T=>T.status==="running")&&vs(l).then(T=>{o(ee=>ee.map(ie=>{const ke=T.find(Ve=>Ve.id===ie.id);return ke&&ke.status!==ie.status?ke:ie}))}).catch(()=>{})},5e3);return()=>clearInterval(u)},[l]);const U=s.useRef(n);s.useEffect(()=>{n&&!U.current&&l&&Promise.all([vs(l),wn(l),hn(l)]).then(([u,E,T])=>{o(u),f(E),j(T)}).catch(()=>{}),U.current=n},[n,l]),s.useEffect(()=>t(u=>{if(u.type==="todo:status-changed"&&u.todoId&&u.status){if(o(E=>E.map(T=>{if(T.id!==u.todoId)return T;const ee={status:u.status,updated_at:new Date().toISOString()};return u.worktree_path!==void 0&&(ee.worktree_path=u.worktree_path??null),u.branch_name!==void 0&&(ee.branch_name=u.branch_name??null),u.round_count!==void 0&&(ee.round_count=u.round_count),{...T,...ee}})),(u.status==="completed"||u.status==="merged"||u.status==="failed")&&ae(E=>E+1),u.status==="completed"||u.status==="failed"){const E=I.current.find(T=>T.id===u.todoId);E&&re(u.status==="completed"?w("notification.taskCompleted"):w("notification.taskFailed"),E.title)}u.status==="running"&&u.mode==="interactive"?le(E=>new Set(E).add(u.todoId)):u.status!=="running"&&le(E=>{const T=new Set(E);return T.delete(u.todoId),T})}if(u.type==="todo:created"&&u.todo&&u.todo.project_id===l){const E=u.todo;o(T=>T.some(ee=>ee.id===E.id)?T:[...T,E])}if(u.type==="schedule:status-changed"&&u.scheduleId&&f(E=>E.map(T=>T.id===u.scheduleId?{...T,is_active:u.isActive?1:0,updated_at:new Date().toISOString()}:T)),u.type==="rate-limit:updated"&&u.resetsAt&&h(u.resetsAt),u.type==="discussion:status-changed"&&u.discussionId&&(j(E=>E.map(T=>T.id===u.discussionId?{...T,status:u.status,current_round:u.currentRound??T.current_round,updated_at:new Date().toISOString()}:T)),u.status==="completed"||u.status==="failed")){const E=we.current.find(T=>T.id===u.discussionId);E&&re(u.status==="completed"?w("notification.discussionCompleted"):w("notification.discussionFailed"),E.title)}u.type==="session:status-changed"&&u.sessionId&&z(E=>E.map(T=>{if(T.id!==u.sessionId)return T;const ee={status:u.status,updated_at:new Date().toISOString()};return u.worktree_path!==void 0&&(ee.worktree_path=u.worktree_path),u.branch_name!==void 0&&(ee.branch_name=u.branch_name),u.cli_session_id!==void 0&&(ee.cli_session_id=u.cli_session_id),u.resumable!==void 0&&(ee.resumable=u.resumable),{...T,...ee}}))}),[t,re,w]);const ce=s.useCallback(async(u,E,T,ee,ie,ke,Ve,ht,at,$,oe)=>{if(!l)return;const Ce=await un(l,{title:u,description:E,cli_tool:T,depends_on:ie,max_turns:ke??null,use_worktree:Ve??null,...ht?{memory_inject_mode:ht}:{},...at?{memory_node_ids:at}:{},...$?{memory_raw_file_paths:$}:{},...oe?{loop_config:oe}:{}});if(ee&&ee.length>0){const Ae=await oa(Ce.id,ee.map(rt=>({name:rt.name,data:rt.data})));Ce.images=JSON.stringify(Ae.images)}o(Ae=>[...Ae,Ce])},[l]),$e=s.useCallback((u,E=[])=>{const T=u.split("/").filter(Boolean).pop()??u,ee=[u,...E].map(ie=>`@${ie}`).join(`
|
|
174
174
|
`);return ce(T,`다음 파일을 참고하세요:
|
|
175
175
|
${ee}`)},[ce]),Ne=s.useCallback(async(u,E)=>{const T=E==="interactive";T&&le(ee=>new Set(ee).add(u));try{const ee=await mn(u,E);o(ie=>ie.map(ke=>ke.id===u?ee:ke))}catch(ee){throw T&&le(ie=>{const ke=new Set(ie);return ke.delete(u),ke}),ee}},[]),Me=s.useCallback(async u=>{const E=await dl(u);o(T=>T.map(ee=>ee.id===u?E:ee))},[]),Re=s.useCallback(async u=>{await ul(u),o(E=>E.filter(T=>T.id!==u))},[]),De=s.useCallback(async(u,E,T,ee,ie,ke,Ve,ht,at,$,oe)=>{const Ce=await qt(u,{title:E,description:T,cli_tool:ee,depends_on:ie??null,max_turns:ke??null,use_worktree:Ve===void 0?null:Ve,...ht?{memory_inject_mode:ht}:{},...at?{memory_node_ids:at}:{},...$?{memory_raw_file_paths:$}:{},loop_config:oe??null});o(Ae=>Ae.map(rt=>rt.id===u?Ce:rt))},[]),Je=s.useCallback(async u=>{await ml(u),o(E=>E.map(T=>T.id===u?{...T,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:T))},[]),Q=s.useCallback(async u=>{const E=await xl(u),T=new Set(E.mergedIds);o(ee=>ee.map(ie=>T.has(ie.id)?{...ie,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:ie))},[]),W=s.useCallback(async(u,E=!1)=>{await hl(u,E),o(T=>T.map(ee=>ee.id===u?{...ee,worktree_path:null,...E?{branch_name:null}:{},updated_at:new Date().toISOString()}:ee))},[]),de=s.useCallback(async(u,E)=>{const T=E==="interactive";T&&le(ee=>new Set(ee).add(u));try{const ee=await pl(u,E);o(ie=>ie.map(ke=>ke.id===u?ee:ke))}catch(ee){throw T&&le(ie=>{const ke=new Set(ie);return ke.delete(u),ke}),ee}},[]),be=s.useCallback(async(u,E,T)=>{const ee=T==="interactive";ee&&le(ie=>new Set(ie).add(u));try{const ie=await fl(u,E,T);o(ke=>ke.map(Ve=>Ve.id===u?ie:Ve))}catch(ie){throw ee&&le(ke=>{const Ve=new Set(ke);return Ve.delete(u),Ve}),ie}},[]),Ie=s.useCallback(async(u,E,T)=>{const ee=await Ei(u,E,T);ee.original_deleted&&o(ie=>ie.filter(ke=>ke.id!==u)),f(ie=>[ee.schedule,...ie])},[]),He=s.useCallback(async(u,E)=>{const T=await zi(u,E);f(ee=>[T.schedule,...ee])},[]),Ee=s.useCallback((u,E)=>{r({type:"todo:stdin",todoId:u,input:E})},[r]),qe=s.useCallback(async(u,E)=>{const T=await qt(u,{depends_on:E});o(ee=>ee.map(ie=>ie.id===u?T:ie))},[]),st=s.useCallback(async u=>{const E=u.map((T,ee)=>({id:T,priority:ee}));o(T=>T.map(ee=>{const ie=E.find(ke=>ke.id===ee.id);return ie?{...ee,priority:ie.priority}:ee})),await Promise.all(E.map(T=>qt(T.id,{priority:T.priority})))},[]),A=s.useCallback(async(u,E,T)=>{await qt(u,{position_x:E,position_y:T}),o(ee=>ee.map(ie=>ie.id===u?{...ie,position_x:E,position_y:T}:ie))},[]),he=s.useCallback(async(u,E)=>{if(!l)return;const T=E.map(Ve=>Ve.message).join(`
|
|
176
176
|
`),ee=`The previous task "${u.title}" failed with the following errors:
|