clitrigger 0.2.46 → 0.2.48

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-QgGQqBdQ.js","assets/style-BHwYq-78.js","assets/value-BTdN53H7.js","assets/with-selector-D_Rh_ICO.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-eUAngWQt.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-CyoPYhlO.js","assets/VaultLayout-DhmT6euK.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-DF8aE2pm.js","assets/style-DTZ8aaqp.js","assets/value-BTdN53H7.js","assets/with-selector-D78IQbHq.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-DE461XLt.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-B4ZlfUK4.js","assets/VaultLayout-BkczecdH.js"])))=>i.map(i=>d[i]);
2
2
  var NC=Object.defineProperty;var LC=(e,s,i)=>s in e?NC(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var vv=(e,s,i)=>LC(e,typeof s!="symbol"?s+"":s,i);function DC(e,s){for(var i=0;i<s.length;i++){const a=s[i];if(typeof a!="string"&&!Array.isArray(a)){for(const h in a)if(h!=="default"&&!(h in e)){const f=Object.getOwnPropertyDescriptor(a,h);f&&Object.defineProperty(e,h,f.get?f:{enumerable:!0,get:()=>a[h]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const h of document.querySelectorAll('link[rel="modulepreload"]'))a(h);new MutationObserver(h=>{for(const f of h)if(f.type==="childList")for(const m of f.addedNodes)m.tagName==="LINK"&&m.rel==="modulepreload"&&a(m)}).observe(document,{childList:!0,subtree:!0});function i(h){const f={};return h.integrity&&(f.integrity=h.integrity),h.referrerPolicy&&(f.referrerPolicy=h.referrerPolicy),h.crossOrigin==="use-credentials"?f.credentials="include":h.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function a(h){if(h.ep)return;h.ep=!0;const f=i(h);fetch(h.href,f)}})();var WB=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function xl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ef={exports:{}},Po={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -614,7 +614,7 @@ Cancel = delete worktree only`,"todo.retry":"Retry","todo.retryDesc":"Cleans up
614
614
  *
615
615
  * This source code is licensed under the ISC license.
616
616
  * See the LICENSE file in the root directory of this source tree.
617
- */const vN=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],bN=Ze("zoom-out",vN),Vv=8;function yN({onLogin:e,onChangePassword:s}){const[i,a]=k.useState(""),[h,f]=k.useState(""),[m,o]=k.useState(""),[c,d]=k.useState(!1),[p,u]=k.useState(!1),[x,b]=k.useState(!1),[C,S]=k.useState(""),[g,_]=k.useState(!1),{t:w,toggleLang:y}=dt(),E=c&&h.length>0&&h.length<Vv,T=c&&m.length>0&&h!==m,j=c?!!i&&h.length>=Vv&&h===m:!!i,R=()=>{d(D=>!D),f(""),o(""),S("")},N=async D=>{if(D.preventDefault(),!(!j||g)){S(""),_(!0);try{c?await s(i,h,m,x):await e(i,x)}catch(A){S(c&&A instanceof Error&&A.message?A.message:w("login.error"))}finally{_(!1)}}};return n.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[n.jsx("button",{onClick:y,className:"lang-toggle absolute top-6 right-6",children:w("lang.toggle")}),n.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[n.jsxs("div",{className:"text-center mb-10",children:[n.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:n.jsx(dl,{size:32,className:"text-accent",strokeWidth:1.5})}),n.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:w("login.title")}),n.jsx("p",{className:"text-theme-muted text-sm mt-2",children:w("login.subtitle")})]}),n.jsx("form",{onSubmit:N,children:n.jsxs("div",{className:"card p-8",children:[n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:w(c?"account.oldPassword":"login.password")}),n.jsx("input",{type:"password",value:i,onChange:D=>a(D.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),c&&n.jsxs(n.Fragment,{children:[n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.newPassword")}),n.jsx("input",{type:"password",value:h,onChange:D=>f(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.newPassword")}),E&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.tooShort")}),n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.confirm")}),n.jsx("input",{type:"password",value:m,onChange:D=>o(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.confirm")}),T&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.mismatch")})]}),C&&n.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children:C}),n.jsxs("label",{className:"flex items-center gap-2 mt-5 text-sm text-theme-text-secondary cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:x,onChange:D=>b(D.target.checked),className:"accent-accent w-4 h-4"}),w("login.rememberMe")]}),n.jsx("button",{type:"submit",disabled:!j||g,className:"btn-primary w-full mt-6 py-3",children:w(g?"login.loading":c?"login.changeSubmit":"login.submit")})]})}),n.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[n.jsx("button",{type:"button",onClick:R,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w(c?"login.backToLogin":"login.changePassword")}),n.jsx("button",{type:"button",onClick:()=>u(D=>!D),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w("login.forgot")})]}),p&&n.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:w("login.forgotHint")}),n.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:w("login.footer")}),n.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:w("login.disclaimer")})]})]})}const Yv=8;function wN({onSetup:e}){const[s,i]=k.useState(""),[a,h]=k.useState(""),[f,m]=k.useState(""),[o,c]=k.useState(!1),{t:d,toggleLang:p}=dt(),u=s.length>0&&s.length<Yv,x=a.length>0&&s!==a,b=s.length>=Yv&&s===a&&!o,C=async S=>{if(S.preventDefault(),!!b){m(""),c(!0);try{await e(s,a)}catch(g){m(g instanceof Error&&g.message?g.message:d("setup.error"))}finally{c(!1)}}};return n.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[n.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),n.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[n.jsxs("div",{className:"text-center mb-10",children:[n.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:n.jsx(dl,{size:32,className:"text-accent",strokeWidth:1.5})}),n.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("setup.title")}),n.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),n.jsx("form",{onSubmit:C,children:n.jsxs("div",{className:"card p-8",children:[n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),n.jsx("input",{type:"password",value:s,onChange:S=>i(S.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),u&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),n.jsx("input",{type:"password",value:a,onChange:S=>h(S.target.value),placeholder:"*************",className:"input-field text-base"}),x&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),f&&n.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children:f}),n.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(o?"setup.loading":"setup.submit")})]})}),n.jsx("div",{className:"mt-4 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:d("setup.tunnelPaused")})]})]})}function _N(e){return et("/api/projects/browse",{initialPath:e})}function SN(e){return et("/api/projects/open-folder",{path:e})}function Iu(){return gt("/api/projects")}function kN(e){return gt(`/api/projects/${e}`)}function Gw(e){return et("/api/projects",e)}function CN(e){return gt(`/api/projects/${e}/svn-detect`)}function am(e,s){return on(`/api/projects/${e}`,s)}function jN(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return gt(`/api/projects/${e}/debug-logs${i}`)}function Vw(e){return In(`/api/projects/${e}`)}function EN(e){return et("/api/projects/reorder",{ids:e})}function NN(e){return et(`/api/projects/${e}/start`)}function LN(e){return et(`/api/projects/${e}/stop`)}function Yw(e){return gt(`/api/projects/${e}/status`)}function Xv(){return gt("/api/active-work")}function DN(e){return et(`/api/projects/${e}/check-git`)}function Xw(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return gt(`/api/projects/${e}/git-status${i}`)}function TN(e,s=0,i=50,a){const h=new URLSearchParams({skip:String(s),limit:String(i)});return gt(`/api/projects/${e}/git-log?${h}`)}function om(e,s){return gt(`/api/projects/${e}/git-refs`)}function RN(e,s,i){return et(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function MN(e,s,i){return et(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function Jw(e,s,i){return et(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function Qw(e,s,i){return et(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function tp(e,s){return et(`/api/projects/${e}/git-push`,s||{})}function AN(e){return gt(`/api/projects/${e}/git-remotes`)}function Zw(e,s,i){return et(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function e1(e,s,i){return et(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function lm(e,s,i){return et(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function cm(e,s){return et(`/api/projects/${e}/git-checkout`,{branch:s})}function t1(e,s){return et(`/api/projects/${e}/git-merge`,{branch:s})}function Jv(e,s,i,a){return et(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function ON(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return gt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function zN(e,s,i,a){return et(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function BN(e){return et(`/api/projects/${e}/git-conflict-continue`)}function PN(e){return et(`/api/projects/${e}/git-conflict-abort`)}function IN(e,s){return et(`/api/projects/${e}/git-stash`,{message:s})}function FN(e,s){return et(`/api/projects/${e}/git-stash-pop`,{index:s})}function HN(e){return gt(`/api/projects/${e}/git-stash-list`)}function $N(e,s,i,a){return et(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function n1(e,s,i,a){return et(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function Qv(e,s,i){return et(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function UN(e,s){return et(`/api/projects/${e}/git-rebase`,{onto:s})}function WN(e,s){return et(`/api/projects/${e}/git-revert`,{commit:s})}function qN(e,s){return et(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function KN(e,s,i){return et(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function GN(e,s,i,a){const h=new URLSearchParams;return s&&h.set("file",s),i&&h.set("staged","true"),a&&h.set("worktreePath",a),gt(`/api/projects/${e}/git-diff?${h}`)}function VN(e,s){const i=new URLSearchParams({hash:s});return gt(`/api/projects/${e}/git-commit-files?${i}`)}function Zv(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),gt(`/api/projects/${e}/git-commit-diff?${a}`)}function um(e){return gt(`/api/projects/${e}/worktrees`)}function eb(e,s,i){return et(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function s1(e){const s=new URLSearchParams;e.hours!==void 0&&s.set("hours",String(e.hours)),e.statuses&&e.statuses.length>0&&s.set("statuses",e.statuses.join(","));const i=s.toString();return i?`?${i}`:""}function YN(e={}){return gt(`/api/review/queue${s1(e)}`)}function r1(e={}){return gt(`/api/review/summary${s1(e)}`)}function XN(e){return gt(`/api/review/diff/${encodeURIComponent(e)}`)}function JN(e,s){return gt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function QN(){return gt("/api/favorites")}function ZN(e){return et("/api/favorites",e)}function e3(e,s){return on(`/api/favorites/${e}`,s)}function t3(e){return In(`/api/favorites/${e}`)}function n3(e){return et(`/api/favorites/${e}/launch`)}function s3(e){return et("/api/favorites/browse-file",{initialPath:e})}function dm(){return gt("/api/tunnel/status")}function r3(){return gt("/api/tunnel/config")}function i3(e){return on("/api/tunnel/config",e)}function i1(e){return et("/api/tunnel/start",{})}function a3(){return et("/api/tunnel/stop")}const a1=k.createContext({theme:"light",toggleTheme:()=>{}});function o3(){const[e,s]=k.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});k.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=k.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function l3(){return k.useContext(a1)}const o1=k.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function c3(){const e="Notification"in window,[s,i]=k.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=k.useRef(s);k.useEffect(()=>{a.current=s},[s]);const h=k.useCallback(async()=>{if(e)if(a.current)localStorage.setItem("clitrigger-notifications","off"),i(!1);else{if(Notification.permission==="denied"||Notification.permission==="default"&&await Notification.requestPermission()!=="granted")return;localStorage.setItem("clitrigger-notifications","on"),i(!0)}},[e]),f=k.useCallback((m,o)=>{if(!a.current)return;const c=new Notification(m,{body:o});c.onclick=()=>{window.focus(),c.close()}},[]);return{enabled:s,supported:e,toggleNotification:h,sendNotification:f}}function np(){return k.useContext(o1)}let u3=0;const l1=k.createContext(null);function d3({children:e}){const[s,i]=k.useState([]),a=k.useRef(new Map),h=k.useRef(new Map),f=k.useRef(new Map),m=k.useCallback(b=>{i(g=>g.filter(_=>_.id!==b));const C=f.current.get(b);C&&h.current.get(C)===b&&h.current.delete(C),f.current.delete(b);const S=a.current.get(b);S&&(clearTimeout(S),a.current.delete(b))},[]),o=k.useCallback((b,C="info",S=3500)=>{const g=`${C}:${b}`,_=h.current.get(g);if(_)return _;const w=`toast-${++u3}`;h.current.set(g,w),f.current.set(w,g),i(E=>[...E,{id:w,message:b,type:C,duration:S}]);const y=setTimeout(()=>m(w),S);return a.current.set(w,y),w},[m]),c=k.useCallback((b,C)=>o(b,"success",C),[o]),d=k.useCallback((b,C)=>o(b,"error",C),[o]),p=k.useCallback((b,C)=>o(b,"info",C),[o]),u=k.useCallback((b,C)=>o(b,"warning",C),[o]);k.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),h.current.clear(),f.current.clear()},[]);const x=k.useMemo(()=>({toasts:s,show:o,success:c,error:d,info:p,warning:u,dismiss:m}),[s,o,c,d,p,u,m]);return k.createElement(l1.Provider,{value:x},e)}function mi(){const e=k.useContext(l1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Ys(...e){return e.filter(Boolean).join(" ")}const h3={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl"},f3={scale:"animate-scale-in","slide-up":"animate-slide-up"};function Un({open:e,onClose:s,size:i="md",position:a="center",animation:h="scale",disableEscClose:f=!1,disableBackdropClose:m=!1,children:o}){const c=k.useRef(null);return k.useEffect(()=>{if(!e||f)return;const d=p=>{p.key==="Escape"&&s()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[e,f,s]),e?en.createPortal(n.jsx("div",{ref:c,className:Ys("fixed inset-0 bg-black/50 backdrop-blur-sm z-modal flex",a==="center"?"items-center justify-center p-4":"items-start justify-center px-4 pt-[20vh]"),onClick:d=>{!m&&d.target===c.current&&s()},children:n.jsx("div",{className:Ys("w-full",h3[i],f3[h]),children:o})}),document.body):null}function c1({onSubmit:e,onCancel:s}){const[i,a]=k.useState(""),[h,f]=k.useState(""),[m,o]=k.useState(!1),[c,d]=k.useState(!1),[p,u]=k.useState(""),{t:x}=dt(),b=async S=>{if(S.preventDefault(),!(!i.trim()||!h.trim())){u(""),d(!0);try{await e(i.trim(),h.trim())}catch(g){const _=g instanceof Error?g.message:String(g);u(_||x("form.createError"))}finally{d(!1)}}},C=async()=>{o(!0);try{const S=await _N(h||void 0);S.path&&f(S.path)}catch{}o(!1)};return n.jsx(Un,{open:!0,onClose:s,size:"md",children:n.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:x("form.newProject")}),n.jsxs("form",{onSubmit:b,children:[n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:x("form.projectName")}),n.jsx("input",{type:"text",placeholder:"my-project",value:i,onChange:S=>a(S.target.value),className:"input-field",autoFocus:!0})]}),n.jsxs("div",{className:"mb-8",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:x("form.folderPath")}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:h,onChange:S=>f(S.target.value),className:"input-field text-sm flex-1"}),n.jsx("button",{type:"button",onClick:C,disabled:m,className:"btn-ghost text-sm px-3 shrink-0",title:x("browse.title"),children:m?n.jsx(oi,{size:16,className:"animate-spin"}):n.jsx(zu,{size:16})})]})]}),p&&n.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:p}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:x("form.cancel")}),n.jsx("button",{type:"submit",disabled:!i.trim()||!h.trim()||c,className:"btn-primary text-sm",children:x(c?"form.creating":"form.create")})]})]})]})})}const m3=[{value:"executable",icon:Jm},{value:"command",icon:di},{value:"url",icon:ul}];function p3(e){const s=[],i=/"([^"]*)"|(\S+)/g;let a;for(;(a=i.exec(e))!==null;)s.push(a[1]!==void 0?a[1]:a[2]);return s}function tb(e){if(!e)return"";try{const s=JSON.parse(e);if(Array.isArray(s))return s.map(i=>typeof i=="string"&&/\s/.test(i)?`"${i}"`:String(i)).join(" ")}catch{}return""}function g3({initial:e,onSubmit:s,onCancel:i}){const{t:a}=dt(),[h,f]=k.useState((e==null?void 0:e.name)??""),[m,o]=k.useState((e==null?void 0:e.type)??"executable"),[c,d]=k.useState((e==null?void 0:e.target)??""),[p,u]=k.useState(tb((e==null?void 0:e.args)??null)),[x,b]=k.useState((e==null?void 0:e.cwd)??""),[C,S]=k.useState(!1);k.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),d((e==null?void 0:e.target)??""),u(tb((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[g,_]=k.useState(!1),w=m==="executable",y=async()=>{_(!0);try{const{path:O}=await s3(c||void 0);if(!O)return;if(d(O),!h.trim()){const z=O.replace(/\\/g,"/").split("/").pop()||"";f(z.replace(/\.[^.]+$/,""))}}catch{}finally{_(!1)}},E=!!e,T=h.trim(),j=c.trim(),R=m!=="url"||/^https?:\/\//i.test(j),N=!!T&&!!j&&R&&!C,D=async O=>{if(O.preventDefault(),!!N){S(!0);try{const z={name:T,type:m,target:j,args:m==="executable"&&p.trim()?p3(p.trim()):null,cwd:m!=="url"&&x.trim()?x.trim():null};await s(z)}finally{S(!1)}}},A=a(m==="executable"?"favorites.form.targetHint.executable":m==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return n.jsx(Un,{open:!0,onClose:i,size:"md",children:n.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:a(E?"favorites.form.title.edit":"favorites.form.title.create")}),n.jsxs("form",{onSubmit:D,children:[n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.type")}),n.jsx("div",{className:"grid grid-cols-3 gap-2",children:m3.map(({value:O,icon:z})=>n.jsxs("button",{type:"button",onClick:()=>o(O),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:m===O?{backgroundColor:"var(--color-accent)",color:"white",borderColor:"var(--color-accent)"}:{color:"var(--color-text-tertiary)",borderColor:"var(--color-border)"},children:[n.jsx(z,{size:14}),a(`favorites.types.${O}`)]},O))})]}),n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.name")}),n.jsx("input",{type:"text",value:h,onChange:O=>f(O.target.value),className:"input-field",autoFocus:!0})]}),n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.target")}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"text",value:c,onChange:O=>d(O.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),w&&n.jsxs("button",{type:"button",onClick:y,disabled:g,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[n.jsx(zu,{size:14}),a("favorites.form.browse")]})]}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),m==="executable"&&n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.args")}),n.jsx("input",{type:"text",value:p,onChange:O=>u(O.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),m!=="url"&&n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.cwd")}),n.jsx("input",{type:"text",value:x,onChange:O=>b(O.target.value),className:"input-field text-sm font-mono",placeholder:"C:/Projects/my-project"})]}),n.jsx("p",{className:"mb-6 text-2xs leading-snug",style:{color:"var(--color-text-muted)"},children:a("favorites.security.notice")}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{type:"button",onClick:i,className:"btn-ghost text-sm",children:a("favorites.form.cancel")}),n.jsx("button",{type:"submit",disabled:!N,className:"btn-primary text-sm",children:a(E?"favorites.form.save":"favorites.form.create")})]})]})]})})}const x3=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function v3({onClose:e}){const{t:s}=dt(),{error:i,success:a}=mi(),[h,f]=k.useState(""),[m,o]=k.useState(""),[c,d]=k.useState(""),[p,u]=k.useState(""),[x,b]=k.useState(!1),[C,S]=k.useState(!1),[g,_]=k.useState(!1),[w,y]=k.useState(null);k.useEffect(()=>{let z=!1;return Promise.all([r3(),dm()]).then(([P,F])=>{z||(f(P.tunnelName),o(P.customHostname),d(P.tunnelName),u(P.customHostname),y(F))}).catch(()=>{}),()=>{z=!0}},[]);const E=h.trim(),T=m.trim(),j=E!==c.trim()||T!==p.trim(),R=!!T&&(!x3.test(T)||T.toLowerCase()==="localhost"||T.toLowerCase()==="127.0.0.1"),N=!!T&&!E,D=j&&!C&&!R&&!N,A=async()=>{if(D){S(!0);try{const z=await i3({tunnelName:E,customHostname:T});d(z.tunnelName),u(z.customHostname),f(z.tunnelName),o(z.customHostname),a(s("tunnel.saved"))}catch(z){i(z instanceof Error?z.message:s("tunnel.saveFailed"))}finally{S(!1)}}},O=async()=>{_(!0);try{try{await a3()}catch{}const z=await i1();y({status:"running",url:z.url}),a(s("tunnel.restarted"))}catch(z){i(z instanceof Error?z.message:s("tunnel.restartFailed"))}finally{_(!1)}};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),w&&n.jsxs("div",{className:"mb-5 p-3 rounded-lg text-xs flex items-center gap-2",style:{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-tertiary)"},children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${w.status==="running"?"bg-status-success":w.status==="error"?"bg-status-error":"bg-status-pending"}`}),n.jsx("span",{className:"font-medium",children:s(`tunnel.status.${w.status}`)}),w.url&&n.jsx("a",{href:w.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:w.url})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),n.jsx("input",{type:"text",value:h,onChange:z=>f(z.target.value),placeholder:s("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.name.hint")})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.hostname.label")}),n.jsx("input",{type:"text",value:m,onChange:z=>o(z.target.value),placeholder:s("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.hostname.hint")}),R&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),N&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.needsName")})]}),n.jsxs("div",{className:"mb-5",children:[n.jsxs("button",{type:"button",onClick:()=>b(!x),className:"flex items-center gap-1 text-xs text-accent-dark hover:text-accent transition-colors",children:[n.jsx("span",{className:`inline-block transition-transform ${x?"rotate-90":""}`,children:"▶"}),s("tunnel.guide.toggle")]}),x&&n.jsxs("div",{className:"mt-3 p-3 bg-warm-50 border border-warm-150 rounded-lg text-xs text-warm-600 space-y-2",children:[n.jsx("p",{className:"font-semibold text-warm-700 mb-1",children:s("tunnel.guide.heading")}),n.jsxs("ol",{className:"list-decimal list-inside space-y-1 ml-1",children:[n.jsx("li",{children:n.jsx("code",{className:"font-mono",children:"cloudflared tunnel login"})}),n.jsx("li",{children:n.jsx("code",{className:"font-mono",children:"cloudflared tunnel create my-app"})}),n.jsx("li",{children:n.jsx("code",{className:"font-mono",children:"cloudflared tunnel route dns my-app app.your-domain.com"})}),n.jsx("li",{children:s("tunnel.guide.step4")})]}),n.jsx("p",{className:"text-2xs text-warm-400 pt-1",children:s("tunnel.guide.note")})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("button",{type:"button",onClick:O,disabled:g,className:"btn-ghost text-sm disabled:opacity-50",children:g?(w==null?void 0:w.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(w==null?void 0:w.status)==="running"?s("tunnel.restart"):s("tunnel.start")}),n.jsxs("div",{className:"flex gap-3",children:[e&&n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),n.jsx("button",{type:"button",onClick:A,disabled:!D,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const nb=8;function b3({onClose:e}){const{t:s}=dt(),{error:i,success:a}=mi(),[h,f]=k.useState(""),[m,o]=k.useState(""),[c,d]=k.useState(""),[p,u]=k.useState(!1),x=m.length>0&&m.length<nb,b=c.length>0&&m!==c,C=!!h&&m.length>=nb&&m===c&&!p,S=()=>{f(""),o(""),d("")},g=async()=>{if(C){u(!0);try{await Ow(h,m,c),a(s("account.saved")),S()}catch(_){i(_ instanceof Error&&_.message?_.message:s("account.saveFailed"))}finally{u(!1)}}};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("account.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("account.description")}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.oldPassword")}),n.jsx("input",{type:"password",value:h,onChange:_=>f(_.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.newPassword")}),n.jsx("input",{type:"password",value:m,onChange:_=>o(_.target.value),className:"input-field text-sm",autoComplete:"new-password"}),x&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.tooShort")})]}),n.jsxs("div",{className:"mb-6",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.confirm")}),n.jsx("input",{type:"password",value:c,onChange:_=>d(_.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),n.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),n.jsx("button",{type:"button",onClick:g,disabled:!C,className:"btn-primary text-sm",children:s(p?"account.saving":"account.save")})]})]})}function sp(){return gt("/api/session-tags")}function y3(e){return et("/api/session-tags",e)}function w3(e,s){return on(`/api/session-tags/${e}`,s)}function _3(e){return In(`/api/session-tags/${e}`)}function u1(){return gt("/api/session-aliases")}function d1(e){return et("/api/session-aliases",e)}function S3(e,s){return on(`/api/session-aliases/${e}`,s)}function k3(e){return In(`/api/session-aliases/${e}`)}function rp(){return gt("/api/session-settings")}function df(e){return on("/api/session-settings",e)}const He={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},Rt="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",ip=13,Qo=8,Zo=28,$a=new Map,Ui=new Map;let bu=ip;function ap(e){return`sessionFontSize:${e}`}window.addEventListener("storage",e=>{var a;if(e.storageArea!==localStorage||!((a=e.key)!=null&&a.startsWith("sessionFontSize:")))return;const s=e.key.slice(16);$a.delete(s);const i=Ui.get(s);if(i){const h=el(s);i.forEach(f=>f(h))}});function hm(e){return Number.isFinite(e)?Math.max(Qo,Math.min(Zo,Math.round(e))):bu}function C3(e){if($a.has(e))return!0;try{return localStorage.getItem(ap(e))!==null}catch{return!1}}function el(e){const s=$a.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(ap(e));if(a!==null){const h=parseInt(a,10);Number.isFinite(h)&&(i=hm(h))}}catch{}return i===null?hm(bu):($a.set(e,i),i)}function fm(e,s){const i=hm(s);if($a.get(e)===i)return;$a.set(e,i);try{localStorage.setItem(ap(e),String(i))}catch{}const a=Ui.get(e);a&&a.forEach(h=>h(i))}function Ho(e,s){fm(e,el(e)+s)}function ou(e){const s=Math.max(Qo,Math.min(Zo,Math.round(e)));Number.isFinite(s)&&s!==bu&&(bu=s,Ui.forEach((i,a)=>{C3(a)||i.forEach(h=>h(s))}))}function h1(e){const[s,i]=k.useState(()=>el(e));k.useEffect(()=>{i(el(e));let f=Ui.get(e);return f||(f=new Set,Ui.set(e,f)),f.add(i),()=>{const m=Ui.get(e);m&&(m.delete(i),m.size===0&&Ui.delete(e))}},[e]);const a=k.useCallback(f=>fm(e,f),[e]),h=k.useCallback(f=>fm(e,el(e)+f),[e]);return[s,a,h]}const tl=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function sb(e){for(const s of tl)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return tl[e.length%tl.length]}function j3({onClose:e}){const{t:s}=dt(),{error:i,success:a}=mi(),[h,f]=k.useState([]),[m,o]=k.useState(!1),[c,d]=k.useState(ip),[p,u]=k.useState(!1),[x,b]=k.useState(!1),[C,S]=k.useState(!1),[g,_]=k.useState(!1),w=k.useRef(null),[y,E]=k.useState(""),[T,j]=k.useState(tl[0]),[R,N]=k.useState(!1),[D,A]=k.useState(null),[O,z]=k.useState(""),[P,F]=k.useState(tl[0]),[H,$]=k.useState(!1),[q,Y]=k.useState([]),[I,B]=k.useState(""),[U,J]=k.useState(""),[W,oe]=k.useState(!1),[ee,Z]=k.useState(null),[X,G]=k.useState(""),[me,ge]=k.useState(""),[xe,he]=k.useState(!1);k.useEffect(()=>{let se=!1;return Promise.all([sp(),rp(),u1()]).then(([le,ve,Ce])=>{se||(f(le),o(ve.defaultUseWorktree),d(ve.defaultFontSize),ou(ve.defaultFontSize),u(ve.imeDebug),j(sb(le)),Y(Ce),b(!0))}).catch(le=>{se||i(le instanceof Error?le.message:"Failed to load")}),()=>{se=!0}},[i]);const Ie=y.trim(),Fe=!!Ie&&!R,be=k.useMemo(()=>[...h].sort((se,le)=>se.sort_order-le.sort_order||se.name.localeCompare(le.name)),[h]);k.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const Ue=se=>{if(!Number.isFinite(se))return;const le=Math.max(Qo,Math.min(Zo,Math.round(se)));d(le),ou(le),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{df({defaultFontSize:le}).then(ve=>{d(ve.defaultFontSize),ou(ve.defaultFontSize)}).catch(ve=>i(ve instanceof Error?ve.message:"Save failed"))},350)},Pe=async se=>{S(!0);try{const le=await df({defaultUseWorktree:se});o(le.defaultUseWorktree),a(s("sessionSettings.saved"))}catch(le){i(le instanceof Error?le.message:"Save failed")}finally{S(!1)}},tt=async se=>{var le,ve;_(!0);try{const Ce=await df({imeDebug:se});u(Ce.imeDebug),(ve=(le=window.electronAPI)==null?void 0:le.imeSetDebug)==null||ve.call(le,Ce.imeDebug),a(s("sessionSettings.saved"))}catch(Ce){i(Ce instanceof Error?Ce.message:"Save failed")}finally{_(!1)}},ke=async()=>{if(Fe){N(!0);try{const se=await y3({name:Ie,color:T});f(le=>[...le,se]),E(""),j(sb([...h,se]))}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{N(!1)}}},pe=se=>{A(se.id),z(se.name),F(se.color)},Ne=()=>{A(null),z("")},Le=async()=>{if(!D)return;const se=O.trim();if(se){$(!0);try{const le=await w3(D,{name:se,color:P});f(ve=>ve.map(Ce=>Ce.id===le.id?le:Ce)),Ne()}catch(le){i(le instanceof Error?le.message:"Save failed")}finally{$(!1)}}},ze=async se=>{if(confirm(s("sessionSettings.tags.deleteConfirm").replace("{name}",se.name)))try{await _3(se.id),f(le=>le.filter(ve=>ve.id!==se.id))}catch(le){i(le instanceof Error?le.message:"Delete failed")}},Ke=I.trim(),Ve=U.trim(),de=!!Ke&&!!Ve&&!W,fe=k.useMemo(()=>[...q].sort((se,le)=>se.sort_order-le.sort_order||se.name.localeCompare(le.name)),[q]),ce=async()=>{if(de){oe(!0);try{const se=await d1({name:Ke,command_template:Ve});Y(le=>[...le,se]),B(""),J("")}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{oe(!1)}}},Q=se=>{Z(se.id),G(se.name),ge(se.command_template)},V=()=>{Z(null),G(""),ge("")},re=async()=>{if(!ee)return;const se=X.trim(),le=me.trim();if(!(!se||!le)){he(!0);try{const ve=await S3(ee,{name:se,command_template:le});Y(Ce=>Ce.map(De=>De.id===ve.id?ve:De)),V()}catch(ve){i(ve instanceof Error?ve.message:"Save failed")}finally{he(!1)}}},te=async se=>{if(confirm(`Delete alias "${se.name}"? Sessions using it will fall back to OS default shell.`))try{await k3(se.id),Y(le=>le.filter(ve=>ve.id!==se.id))}catch(le){i(le instanceof Error?le.message:"Delete failed")}};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("sessionSettings.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("sessionSettings.description")}),n.jsxs("section",{className:"mb-7",children:[n.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[n.jsx(Ga,{size:14}),s("sessionSettings.worktree.title")]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:C||!x,onChange:se=>Pe(se.target.checked),className:"rounded border-warm-300"}),n.jsx("span",{className:"text-sm text-warm-600",children:s("sessionSettings.worktree.label")})]}),n.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.worktree.hint")})]}),n.jsxs("section",{className:"mb-7",children:[n.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[n.jsx(cN,{size:14}),s("sessionSettings.fontSize.title")]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"range",min:Qo,max:Zo,step:1,value:c,disabled:!x,onChange:se=>Ue(parseInt(se.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),n.jsx("input",{type:"number",min:Qo,max:Zo,step:1,value:c,disabled:!x,onChange:se=>Ue(parseInt(se.target.value,10)),className:"input text-sm w-20"}),n.jsx("span",{className:"text-xs text-warm-400",children:"px"})]}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.fontSize.hint")})]}),n.jsxs("section",{children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:s("sessionSettings.tags.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-3",children:s("sessionSettings.tags.description")}),n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx("input",{type:"color",value:T,onChange:se=>j(se.target.value),className:"w-9 h-9 rounded cursor-pointer border border-warm-200",title:s("sessionSettings.tags.color")}),n.jsx("input",{type:"text",value:y,onChange:se=>E(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),ke())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),n.jsxs("button",{type:"button",onClick:ke,disabled:!Fe,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[n.jsx(mn,{size:14}),s("sessionSettings.tags.add")]})]}),be.length===0?n.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:s("sessionSettings.tags.empty")}):n.jsx("ul",{className:"space-y-1.5",children:be.map(se=>{const le=D===se.id;return n.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:le?n.jsxs(n.Fragment,{children:[n.jsx("input",{type:"color",value:P,onChange:ve=>F(ve.target.value),className:"w-7 h-7 rounded cursor-pointer border border-warm-200"}),n.jsx("input",{type:"text",value:O,onChange:ve=>z(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&(ve.preventDefault(),Le()),ve.key==="Escape"&&Ne()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),n.jsx("button",{type:"button",onClick:Le,disabled:H||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:s("sessionSettings.tags.save"),children:n.jsx(_r,{size:14})}),n.jsx("button",{type:"button",onClick:Ne,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.cancel"),children:n.jsx(Jt,{size:14})})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:se.color,borderColor:"rgba(0,0,0,0.08)"}}),n.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:se.name}),n.jsx("button",{type:"button",onClick:()=>pe(se),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.edit"),children:n.jsx(ci,{size:14})}),n.jsx("button",{type:"button",onClick:()=>ze(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:s("sessionSettings.tags.delete"),children:n.jsx(Ln,{size:14})})]})},se.id)})})]}),n.jsxs("section",{className:"mt-7",children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:"Terminal aliases"}),n.jsx("p",{className:"text-xs text-warm-400 mb-3",children:"Saved command snippets. Click the ⌘ icon in any terminal window's titlebar to insert one as input — Enter is yours to press."}),n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx("input",{type:"text",value:I,onChange:se=>B(se.target.value),placeholder:"Name (e.g. WSL Ubuntu)",className:"input text-sm w-44",maxLength:64}),n.jsx("input",{type:"text",value:U,onChange:se=>J(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),ce())},placeholder:"Command (e.g. wsl -d Ubuntu)",className:"input text-sm flex-1 font-mono",maxLength:1024}),n.jsxs("button",{type:"button",onClick:ce,disabled:!de,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[n.jsx(mn,{size:14}),"Add"]})]}),fe.length===0?n.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:"No aliases yet."}):n.jsx("ul",{className:"space-y-1.5",children:fe.map(se=>{const le=ee===se.id;return n.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:le?n.jsxs(n.Fragment,{children:[n.jsx("input",{type:"text",value:X,onChange:ve=>G(ve.target.value),className:"input text-sm w-44",maxLength:64}),n.jsx("input",{type:"text",value:me,onChange:ve=>ge(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&(ve.preventDefault(),re()),ve.key==="Escape"&&V()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),n.jsx("button",{type:"button",onClick:re,disabled:xe||!X.trim()||!me.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:"Save",children:n.jsx(_r,{size:14})}),n.jsx("button",{type:"button",onClick:V,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:"Cancel",children:n.jsx(Jt,{size:14})})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:se.name}),n.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:se.command_template}),n.jsx("button",{type:"button",onClick:()=>Q(se),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded",title:"Edit",children:n.jsx(ci,{size:14})}),n.jsx("button",{type:"button",onClick:()=>te(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:"Delete",children:n.jsx(Ln,{size:14})})]})},se.id)})})]}),n.jsxs("section",{className:"mt-7",children:[n.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[n.jsx(V5,{size:14}),"IME 디버그 로그"]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:p,disabled:g||!x,onChange:se=>tt(se.target.checked),className:"rounded border-warm-300"}),n.jsx("span",{className:"text-sm text-warm-600",children:"한글 입력(IME) 진단 로그 기록"})]}),n.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:"조합 창이 화면 좌상단에 뜨는 문제를 진단하기 위해 입력 시점 상태를 기록합니다. 데스크톱 앱에서만 동작하며, 로그는 앱 데이터 폴더의 ime-debug.log에 저장됩니다."})]}),e&&n.jsx("div",{className:"flex justify-end gap-3 mt-7",children:n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")})})]})}function E3(){return gt("/api/mcp/connection")}function N3({onClose:e}){const{t:s}=dt(),{success:i,error:a}=mi(),[h,f]=k.useState(null),[m,o]=k.useState(null);k.useEffect(()=>{let x=!1;return E3().then(b=>{x||f(b)}).catch(()=>{}),()=>{x=!0}},[]);const c=async(x,b)=>{try{await navigator.clipboard.writeText(b),o(x),setTimeout(()=>o(C=>C===x?null:C),1500),i(s("mcp.copied"))}catch{a(s("mcp.copyFailed"))}},d=h?JSON.stringify(h.config,null,2):"",p=({label:x,text:b})=>n.jsxs("button",{type:"button",onClick:()=>c(x,b),className:"btn-ghost text-xs flex items-center gap-1",children:[m===x?n.jsx(_r,{size:13}):n.jsx(Dj,{size:13}),s("mcp.copy")]}),u={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("mcp.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("mcp.description")}),h?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mb-5",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600",children:s("mcp.config.label")}),n.jsx(p,{label:"config",text:d})]}),n.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:u,children:d})]}),n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:s("mcp.commands.label")}),n.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:s("mcp.commands.hint")}),n.jsx("div",{className:"space-y-3",children:h.commands.map(x=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-1",children:[n.jsx("span",{className:"text-xs text-warm-500",children:x.label}),n.jsx(p,{label:`command:${x.id}`,text:x.command})]}),n.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:u,children:x.command})]},x.id))})]}),n.jsx("p",{className:"text-2xs text-warm-400",children:s("mcp.tokenNote")})]}):n.jsx("p",{className:"text-sm text-warm-400",children:s("mcp.loading")}),e&&n.jsx("div",{className:"flex justify-end mt-6",children:n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("mcp.close")})})]})}function rb({open:e,onClose:s}){const{t:i}=dt(),[a,h]=k.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:oE},{id:"session",label:i("settings.tabs.session"),icon:dl},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:$w},{id:"mcp",label:i("settings.tabs.mcp"),icon:$E}];return n.jsx(Un,{open:e,onClose:s,size:"xl",children:n.jsx("div",{className:"card shadow-2xl rounded-2xl overflow-hidden",children:n.jsxs("div",{className:"flex",style:{minHeight:460},children:[n.jsxs("aside",{className:"w-44 shrink-0 border-r flex flex-col",style:{borderColor:"var(--color-border)",backgroundColor:"var(--color-bg-hover)"},children:[n.jsx("div",{className:"px-4 pt-5 pb-3 text-xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:i("settings.title")}),n.jsx("nav",{className:"flex flex-col",children:f.map(({id:m,label:o,icon:c})=>{const d=a===m;return n.jsxs("button",{type:"button",onClick:()=>h(m),className:"flex items-center gap-2 px-4 py-2.5 text-sm transition-colors text-left",style:{color:d?"var(--color-accent)":"var(--color-text-secondary)",backgroundColor:d?"var(--color-bg-primary)":"transparent",fontWeight:d?600:400},children:[n.jsx(c,{size:14}),n.jsx("span",{children:o})]},m)})}),n.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.46"]})]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&n.jsx(b3,{onClose:s}),a==="session"&&n.jsx(j3,{onClose:s}),a==="tunnel"&&n.jsx(v3,{onClose:s}),a==="mcp"&&n.jsx(N3,{onClose:s})]})]})})})}const mm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function L3(e,s){let i=0;for(let a=0;a<e.length;a++)i=(i<<5)-i+e.charCodeAt(a)|0;return Math.abs(i)%s}function Ua(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:mm[L3(e.id,mm.length)]}const ib=192,D3=88,Ic=8;function T3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:h}){const f=k.useRef(null),[m,o]=k.useState({left:s,top:i}),c=Ua(e);return k.useLayoutEffect(()=>{const d=Math.min(Math.max(s,Ic),window.innerWidth-ib-Ic),p=Math.min(Math.max(i,Ic),window.innerHeight-D3-Ic);o({left:d,top:p})},[s,i]),k.useEffect(()=>{const d=u=>{var x;(x=f.current)!=null&&x.contains(u.target)||h()},p=u=>{u.key==="Escape"&&h()};return window.addEventListener("mousedown",d),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",p)}},[h]),en.createPortal(n.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:ib,background:"var(--color-bg-elevated, #1f1f23)",border:"1px solid var(--color-border)",borderRadius:10,padding:10,boxShadow:"0 12px 32px rgba(0,0,0,0.45)"},children:[n.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:8},children:mm.map(d=>{const p=e.color?d.toLowerCase()===e.color.toLowerCase():d===c&&!e.color;return n.jsx("button",{onClick:()=>a(d),"aria-label":d,style:{width:20,height:20,borderRadius:6,background:d,border:p?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},d)})}),n.jsx("button",{onClick:()=>a(null),style:{width:"100%",background:"transparent",border:"1px solid var(--color-border)",color:"var(--color-text-tertiary)",padding:"4px 8px",borderRadius:6,fontSize:11,cursor:"pointer"},children:"자동 색 (기본값)"})]}),document.body)}function nl(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function R3(e){const s=e instanceof Error?e.message:typeof e=="string"?e:"";return/^ResizeObserver loop (?:limit exceeded|completed with undelivered notifications\.?)$/i.test(s.trim())}const M3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},A3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},bn=k.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:h,type:f="button",title:m,className:o,...c},d){return n.jsx("button",{ref:d,type:f,"aria-label":s,"aria-pressed":h,title:m??s,className:Ys("btn-icon",M3[i],A3[a],o),...c})});function O3(e){return e==="executable"?Jm:e==="command"?di:ul}function z3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:h,collapsed:f=!1,onToggleCollapsed:m}){var de;const[o,c]=k.useState([]),[d,p]=k.useState({}),[u,x]=k.useState(null),[b,C]=k.useState(!1),[S,g]=k.useState(null),[_,w]=k.useState([]),[y,E]=k.useState(!1),[T,j]=k.useState(null),[R,N]=k.useState(!1),[D,A]=k.useState(null),[O,z]=k.useState(!1),[P,F]=k.useState(null),[H,$]=k.useState(null),q=Ds(),Y=fi(),{t:I,toggleLang:B}=dt(),{theme:U,toggleTheme:J}=l3(),{enabled:W,supported:oe,toggleNotification:ee}=np(),{error:Z,success:X,info:G,warning:me}=mi(),ge=((de=q.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:de[1])||null;k.useEffect(()=>{tt(),he(),dm().then(A).catch(()=>{})},[]);async function xe(){if(!O){z(!0);try{const fe=await dm();if(A(fe),fe.status==="running"&&fe.url){await navigator.clipboard.writeText(fe.url),X(I("tunnel.urlCopied"));return}const ce=await i1(),Q={status:"running",url:ce.url};A(Q);try{await navigator.clipboard.writeText(ce.url),X(I("tunnel.urlCopied"))}catch{X(ce.url)}}catch(fe){Z(fe instanceof Error?fe.message:I("tunnel.restartFailed"))}finally{z(!1)}}}function he(){QN().then(w).catch(()=>{})}const Ie=async fe=>{try{T?await e3(T.id,fe):await ZN(fe),E(!1),j(null),he()}catch(ce){Z(ce instanceof Error?ce.message:"Failed to save favorite")}},Fe=async fe=>{try{await n3(fe)}catch(ce){const Q=ce instanceof Error?ce.message:I("favorites.launchFailed");Z(`${I("favorites.launchFailed")}: ${Q}`)}},be=async(fe,ce)=>{if(ce.preventDefault(),ce.stopPropagation(),!!confirm(I("favorites.deleteConfirm")))try{await t3(fe),w(Q=>Q.filter(V=>V.id!==fe))}catch(Q){Z(Q instanceof Error?Q.message:"Failed to delete favorite")}},Ue=(fe,ce)=>{ce.preventDefault(),ce.stopPropagation(),j(fe),E(!0)};k.useEffect(()=>{const fe=()=>tt();return window.addEventListener("projects:changed",fe),()=>window.removeEventListener("projects:changed",fe)},[]),k.useEffect(()=>{const fe=()=>Pe();return window.addEventListener("review:changed",fe),()=>window.removeEventListener("review:changed",fe)},[]),k.useEffect(()=>a(fe=>{var ce;if(fe.type==="project:status-changed"&&fe.projectId&&p(Q=>({...Q,[fe.projectId]:{running:fe.running??0,completed:fe.completed??0,total:fe.total??0,running_sessions:fe.running_sessions??0,running_discussions:fe.running_discussions??0}})),fe.type==="todo:status-changed"&&Pe(),fe.type==="memory:ingest-finished"){const Q=o.find(De=>De.id===fe.projectId),V=(Q==null?void 0:Q.name)??"",re=fe.sourceTitle?`“${fe.sourceTitle}”`:fe.sourceType??"",te=V?`[${V}] `:"";if(fe.error){Z(`${te}${I("wiki.ingest.toast.failed")}: ${fe.error}`,6e3);return}const se=fe.created??0,le=fe.updated??0,ve=fe.edgesAdded??0;if(se+le+ve>0){const De=I("wiki.ingest.toast.success").replace("{source}",re).replace("{created}",String(se)).replace("{updated}",String(le)).replace("{edges}",String(ve));X(`${te}${De}`)}else(ce=fe.skipped)!=null&&ce.parseFailed?me(`${te}${I("wiki.ingest.toast.parseFailed").replace("{source}",re)}`,5e3):G(`${te}${I("wiki.ingest.toast.empty").replace("{source}",re)}`,4e3)}}),[a,o,I,Z,G,X,me]),k.useEffect(()=>{Pe()},[]);function Pe(){r1({hours:24}).then(fe=>x(fe.total_todos)).catch(()=>{})}function tt(){Iu().then(fe=>{c(fe),fe.forEach(ce=>{Yw(ce.id).then(Q=>{p(V=>({...V,[ce.id]:Q}))}).catch(()=>{})})}).catch(()=>{})}const ke=()=>{h==null||h()},pe=async(fe,ce)=>{await Gw({name:fe,path:ce}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Ne=k.useCallback(async(fe,ce)=>{const Q=o.map(De=>De.id),V=Q.indexOf(fe);if(V<0)return;const re=Q.filter(De=>De!==fe),te=ce>V?ce-1:ce;if(te===V)return;const se=[...re.slice(0,te),fe,...re.slice(te)],le=o,ve=new Map(o.map(De=>[De.id,De])),Ce=se.map(De=>ve.get(De)).filter(Boolean);c(Ce);try{await EN(se)}catch(De){c(le),Z(De instanceof Error?De.message:"Failed to reorder projects")}},[o,Z]),Le=k.useRef(!1),ze=k.useCallback((fe,ce)=>{if(ce.button!==0||ce.target.closest("button"))return;ce.preventDefault();const V=ce.clientX,re=ce.clientY,te=6;let se=!1,le=null;const ve=ot=>{const Je=document.querySelectorAll("[data-workspace-item]");if(Je.length===0)return null;const qe=Je[0].getBoundingClientRect();if(ot<qe.top)return 0;const ft=Je[Je.length-1].getBoundingClientRect();if(ot>ft.bottom)return Je.length;for(let lt=0;lt<Je.length;lt++){const xt=Je[lt].getBoundingClientRect();if(ot>=xt.top&&ot<=xt.bottom){const pt=xt.top+xt.height/2;return ot<pt?lt:lt+1}}return null},Ce=ot=>{if(!se){if(Math.hypot(ot.clientX-V,ot.clientY-re)<te)return;se=!0,F(fe)}const Je=ve(ot.clientY);Je!==le&&(le=Je,$(Je))},De=()=>{window.removeEventListener("mousemove",Ce),window.removeEventListener("mouseup",Qe),window.removeEventListener("keydown",ut)},Qe=()=>{if(De(),!se)return;Le.current=!0,requestAnimationFrame(()=>{Le.current=!1});const ot=le;F(null),$(null),ot!==null&&Ne(fe,ot)},ut=ot=>{ot.key==="Escape"&&(De(),F(null),$(null),se&&(Le.current=!0,requestAnimationFrame(()=>{Le.current=!1})))};window.addEventListener("mousemove",Ce),window.addEventListener("mouseup",Qe),window.addEventListener("keydown",ut)},[Ne]),Ke=async(fe,ce)=>{if(ce.preventDefault(),ce.stopPropagation(),!!confirm(I("projects.deleteConfirm")))try{await Vw(fe),c(Q=>Q.filter(V=>V.id!==fe)),window.dispatchEvent(new Event("projects:changed")),ge===String(fe)&&Y("/")}catch(Q){Z(nl(Q,I("errors.projectDelete")))}},Ve=fe=>n.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...fe==="above"?{top:-1}:{bottom:-1}}});if(f){const fe=n.jsx("div",{className:"w-7 border-t my-1.5",style:{borderColor:"var(--color-border)"}});return n.jsxs("div",{className:"flex flex-col items-center h-full glass border-none py-3",children:[n.jsx(bn,{onClick:m,label:I("sidebar.expand"),size:"lg",children:n.jsx(zE,{size:18})}),fe,n.jsx(Pn,{to:"/",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:q.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.home"),children:n.jsx($v,{size:18})}),n.jsxs(Pn,{to:"/review",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:q.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.review"),children:[n.jsx(gu,{size:18}),u!==null&&u>0&&n.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]}),n.jsx(Pn,{to:"/agenda",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:q.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.agenda"),children:n.jsx(tm,{size:18})}),fe,n.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(ce=>{const Q=d[ce.id],V=ge===String(ce.id),re=Q?Q.running+Q.running_sessions+Q.running_discussions:0,te=re>0,se=Ua(ce);return n.jsxs(Pn,{to:`/projects/${ce.id}`,onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:V?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:te?`${ce.name} · ${re} ${I("detail.live")}`:ce.name,children:[V&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),n.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${te?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:V||te?1:.55}})]},ce.id)})}),fe,n.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?I("detail.live"):"Disconnected"}),n.jsx(bn,{onClick:J,label:I(U==="light"?"theme.dark":"theme.light"),size:"lg",children:U==="light"?n.jsx(Wv,{size:16}):n.jsx(Kv,{size:16})}),n.jsx(bn,{onClick:()=>N(!0),label:I("settings.title"),size:"lg",children:n.jsx(vu,{size:16})}),n.jsx(rb,{open:R,onClose:()=>N(!1)})]})}return n.jsxs("div",{className:"flex flex-col h-full glass border-none",onDragStart:fe=>fe.preventDefault(),children:[n.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[n.jsx(Pn,{to:"/",onClick:ke,className:"block",children:n.jsxs("svg",{viewBox:"0 0 200 32",fill:"none",className:"h-6 w-auto",children:[n.jsxs("text",{x:"0",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-accent)",opacity:"0.5",children:[">","_"]}),n.jsx("text",{x:"38",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"700",fill:"var(--color-accent)",children:"CLI"}),n.jsx("text",{x:"96",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-text-primary)",children:"Trigger"})]})}),n.jsx(bn,{onClick:m,label:I("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:n.jsx(AE,{size:16})})]}),n.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[n.jsxs(Pn,{to:"/",onClick:ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${q.pathname==="/"?"font-medium":""}`,style:q.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[q.pathname==="/"&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),n.jsx($v,{size:16}),I("sidebar.home")]}),n.jsxs(Pn,{to:"/review",onClick:ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${q.pathname==="/review"?"font-medium":""}`,style:q.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[q.pathname==="/review"&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),n.jsx(gu,{size:16}),n.jsx("span",{className:"flex-1",children:I("sidebar.review")}),u!==null&&u>0&&n.jsx("span",{className:"text-2xs px-1.5 py-0.5 rounded-full font-medium",style:{backgroundColor:"var(--color-accent)",color:"white"},children:u})]}),n.jsxs(Pn,{to:"/agenda",onClick:ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${q.pathname==="/agenda"?"font-medium":""}`,style:q.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[q.pathname==="/agenda"&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),n.jsx(tm,{size:16}),I("sidebar.agenda")]})]}),n.jsx("div",{className:"mx-4 border-t",style:{borderColor:"var(--color-border)"}}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 pt-3",children:[n.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:I("sidebar.workspaces")}),n.jsx(bn,{onClick:()=>C(!0),label:I("projects.new"),size:"sm",children:n.jsx(mn,{size:14,strokeWidth:2})})]}),n.jsx("div",{className:"space-y-0.5",children:o.map((fe,ce)=>{const Q=d[fe.id],V=ge===String(fe.id),re=Q?Q.running+Q.running_sessions+Q.running_discussions:0,te=re>0,se=Ua(fe),le=P===fe.id,ve=P!==null&&H===ce,Ce=P!==null&&ce===o.length-1&&H===o.length;return n.jsxs("div",{className:"relative","data-workspace-item":!0,children:[ve&&Ve("above"),n.jsxs(Pn,{to:`/projects/${fe.id}`,draggable:!1,onDragStart:De=>De.preventDefault(),onClick:De=>{if(Le.current){De.preventDefault();return}ke()},onMouseDown:De=>ze(fe.id,De),onContextMenu:De=>{De.preventDefault(),g({project:fe,x:De.clientX,y:De.clientY})},className:`relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group ${V?"font-medium":""} ${le?"opacity-50":""}`,style:V?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:P?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:P?"grabbing":"pointer",userSelect:"none"},children:[V&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),n.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${te?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:V||te?1:.55},title:te?`${I("sidebar.workspaces")} · ${re} ${I("detail.live")}`:fe.name}),n.jsx("span",{className:"truncate flex-1",children:fe.name}),n.jsx(bn,{onClick:De=>Ke(fe.id,De),label:I("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:n.jsx(Jt,{size:12,strokeWidth:2})})]}),Ce&&Ve("below")]},fe.id)})})]}),b&&n.jsx(c1,{onSubmit:(fe,ce)=>pe(fe,ce),onCancel:()=>C(!1)}),n.jsxs("div",{className:"px-3 pt-3 pb-2 border-t",style:{borderColor:"var(--color-border)"},children:[n.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:I("sidebar.favorites")}),n.jsx(bn,{onClick:()=>{j(null),E(!0)},label:I("favorites.add"),size:"sm",children:n.jsx(mn,{size:14,strokeWidth:2})})]}),n.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:_.map(fe=>{const ce=O3(fe.type);return n.jsxs("button",{onClick:()=>Fe(fe.id),className:"w-full relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group",style:{color:"var(--color-text-tertiary)"},title:fe.target,children:[n.jsx(ce,{size:14,className:"flex-shrink-0"}),n.jsx("span",{className:"truncate flex-1 text-left",children:fe.name}),n.jsx("span",{onClick:Q=>Ue(fe,Q),className:"flex-shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 transition-all hover:bg-theme-hover cursor-pointer",style:{color:"var(--color-text-muted)"},title:I("favorites.edit"),children:n.jsx(im,{size:11,strokeWidth:2})}),n.jsx("span",{onClick:Q=>be(fe.id,Q),className:"flex-shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 transition-all hover:bg-status-error/10 cursor-pointer",style:{color:"var(--color-text-muted)"},title:I("favorites.delete"),children:n.jsx(Jt,{size:12,strokeWidth:2})})]},fe.id)})})]}),y&&n.jsx(g3,{initial:T??void 0,onSubmit:Ie,onCancel:()=>{E(!1),j(null)}}),S&&n.jsx(T3,{project:S.project,anchorX:S.x,anchorY:S.y,onPick:async fe=>{try{const ce=await am(S.project.id,{color:fe});c(Q=>Q.map(V=>V.id===ce.id?{...V,color:ce.color}:V)),window.dispatchEvent(new Event("projects:changed"))}catch(ce){Z(ce instanceof Error?ce.message:"Failed to update color")}g(null)},onClose:()=>g(null)}),n.jsx(rb,{open:R,onClose:()=>N(!1)}),n.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:n.jsxs("div",{className:"flex items-center gap-1 px-1",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 mr-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?I("detail.live"):"Disconnected"}),n.jsx(bn,{onClick:J,label:I(U==="light"?"theme.dark":"theme.light"),children:U==="light"?n.jsx(Wv,{size:16}):n.jsx(Kv,{size:16})}),n.jsx(bn,{onClick:B,label:I("lang.toggle"),className:"text-xs font-medium",children:I("lang.toggle")}),oe&&n.jsx(bn,{onClick:ee,label:"Notification"in window&&Notification.permission==="denied"?I("notification.blocked"):I("notification.toggle"),variant:W?"active":"default",pressed:W,children:W?n.jsx(K5,{size:16}):n.jsx(W5,{size:16})}),n.jsx(bn,{onClick:xe,disabled:O,label:I("tunnel.start"),variant:(D==null?void 0:D.status)==="running"?"active":"default",pressed:(D==null?void 0:D.status)==="running",title:(D==null?void 0:D.status)==="running"&&D.url?`${D.url} — ${I("tunnel.urlCopied")}`:I(O?"tunnel.starting":"tunnel.start"),children:n.jsx($w,{size:16})}),n.jsx(bn,{onClick:()=>N(!0),label:I("settings.title"),children:n.jsx(vu,{size:16})}),s&&n.jsx(bn,{onClick:e,label:I("projects.logout"),variant:"danger",className:"ml-auto",children:n.jsx(yE,{size:16})})]})})]})}const B3=80,ab=120,xr=180,ob=.03,lb=8;function P3(){const e=k.useRef(null),s=k.useRef({x:-1e3,y:-1e3}),i=k.useRef([]),a=k.useRef(0);return k.useEffect(()=>{const h=e.current;if(!h)return;const f=h.getContext("2d");if(!f)return;let m=0,o=0;function c(){const b=h.parentElement;b&&(m=b.clientWidth,o=b.clientHeight,h.width=m*window.devicePixelRatio,h.height=o*window.devicePixelRatio,h.style.width=`${m}px`,h.style.height=`${o}px`,f.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),d())}function d(){i.current=[];for(let b=0;b<B3;b++){const C=Math.random()*m,S=Math.random()*o;i.current.push({x:C,y:S,baseX:C,baseY:S,vx:(Math.random()-.5)*.3,vy:(Math.random()-.5)*.3,size:Math.random()*1.5+.5,alpha:Math.random()*.4+.1})}}function p(b){const C=h.getBoundingClientRect();s.current.x=b.clientX-C.left,s.current.y=b.clientY-C.top}function u(){s.current.x=-1e3,s.current.y=-1e3}function x(){if(!f)return;f.clearRect(0,0,m,o);const b=i.current,C=s.current;for(const S of b){const g=S.x-C.x,_=S.y-C.y,w=Math.sqrt(g*g+_*_);if(w<xr&&w>0){const y=(xr-w)/xr,E=Math.atan2(_,g);S.vx+=Math.cos(E)*y*lb*.05,S.vy+=Math.sin(E)*y*lb*.05}S.vx+=(S.baseX-S.x)*ob,S.vy+=(S.baseY-S.y)*ob,S.baseX+=(Math.random()-.5)*.1,S.baseY+=(Math.random()-.5)*.1,S.baseX<0&&(S.baseX=0),S.baseX>m&&(S.baseX=m),S.baseY<0&&(S.baseY=0),S.baseY>o&&(S.baseY=o),S.vx*=.92,S.vy*=.92,S.x+=S.vx,S.y+=S.vy}for(let S=0;S<b.length;S++){for(let y=S+1;y<b.length;y++){const E=b[S].x-b[y].x,T=b[S].y-b[y].y,j=Math.sqrt(E*E+T*T);if(j<ab){const R=(1-j/ab)*.15;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${R})`,f.lineWidth=.5,f.moveTo(b[S].x,b[S].y),f.lineTo(b[y].x,b[y].y),f.stroke()}}const g=b[S].x-C.x,_=b[S].y-C.y,w=Math.sqrt(g*g+_*_);if(w<xr){const y=(1-w/xr)*.3;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${y})`,f.lineWidth=.8,f.moveTo(b[S].x,b[S].y),f.lineTo(C.x,C.y),f.stroke()}}for(const S of b){const g=S.x-C.x,_=S.y-C.y,w=Math.sqrt(g*g+_*_),y=w<xr?S.alpha+(1-w/xr)*.5:S.alpha;f.beginPath(),f.arc(S.x,S.y,S.size,0,Math.PI*2),f.fillStyle=`rgba(75, 141, 255, ${y})`,f.fill(),w<xr&&(f.beginPath(),f.arc(S.x,S.y,S.size*3,0,Math.PI*2),f.fillStyle=`rgba(75, 141, 255, ${(1-w/xr)*.08})`,f.fill())}a.current=requestAnimationFrame(x)}return c(),h.addEventListener("mousemove",p),h.addEventListener("mouseleave",u),window.addEventListener("resize",c),a.current=requestAnimationFrame(x),()=>{cancelAnimationFrame(a.current),h.removeEventListener("mousemove",p),h.removeEventListener("mouseleave",u),window.removeEventListener("resize",c)}},[]),n.jsx("canvas",{ref:e,className:"absolute inset-0 pointer-events-auto",style:{zIndex:0}})}function I3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:h}){const[f,m]=k.useState(!1),o=Ds(),{t:c}=dt(),[d,p]=k.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),u=()=>{p(x=>{const b=!x;return localStorage.setItem("sidebarCollapsed",b?"1":"0"),b})};return n.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[n.jsx("aside",{className:`
617
+ */const vN=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],bN=Ze("zoom-out",vN),Vv=8;function yN({onLogin:e,onChangePassword:s}){const[i,a]=k.useState(""),[h,f]=k.useState(""),[m,o]=k.useState(""),[c,d]=k.useState(!1),[p,u]=k.useState(!1),[x,b]=k.useState(!1),[C,S]=k.useState(""),[g,_]=k.useState(!1),{t:w,toggleLang:y}=dt(),E=c&&h.length>0&&h.length<Vv,T=c&&m.length>0&&h!==m,j=c?!!i&&h.length>=Vv&&h===m:!!i,R=()=>{d(D=>!D),f(""),o(""),S("")},N=async D=>{if(D.preventDefault(),!(!j||g)){S(""),_(!0);try{c?await s(i,h,m,x):await e(i,x)}catch(A){S(c&&A instanceof Error&&A.message?A.message:w("login.error"))}finally{_(!1)}}};return n.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[n.jsx("button",{onClick:y,className:"lang-toggle absolute top-6 right-6",children:w("lang.toggle")}),n.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[n.jsxs("div",{className:"text-center mb-10",children:[n.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:n.jsx(dl,{size:32,className:"text-accent",strokeWidth:1.5})}),n.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:w("login.title")}),n.jsx("p",{className:"text-theme-muted text-sm mt-2",children:w("login.subtitle")})]}),n.jsx("form",{onSubmit:N,children:n.jsxs("div",{className:"card p-8",children:[n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:w(c?"account.oldPassword":"login.password")}),n.jsx("input",{type:"password",value:i,onChange:D=>a(D.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),c&&n.jsxs(n.Fragment,{children:[n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.newPassword")}),n.jsx("input",{type:"password",value:h,onChange:D=>f(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.newPassword")}),E&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.tooShort")}),n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.confirm")}),n.jsx("input",{type:"password",value:m,onChange:D=>o(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.confirm")}),T&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.mismatch")})]}),C&&n.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children:C}),n.jsxs("label",{className:"flex items-center gap-2 mt-5 text-sm text-theme-text-secondary cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:x,onChange:D=>b(D.target.checked),className:"accent-accent w-4 h-4"}),w("login.rememberMe")]}),n.jsx("button",{type:"submit",disabled:!j||g,className:"btn-primary w-full mt-6 py-3",children:w(g?"login.loading":c?"login.changeSubmit":"login.submit")})]})}),n.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[n.jsx("button",{type:"button",onClick:R,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w(c?"login.backToLogin":"login.changePassword")}),n.jsx("button",{type:"button",onClick:()=>u(D=>!D),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w("login.forgot")})]}),p&&n.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:w("login.forgotHint")}),n.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:w("login.footer")}),n.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:w("login.disclaimer")})]})]})}const Yv=8;function wN({onSetup:e}){const[s,i]=k.useState(""),[a,h]=k.useState(""),[f,m]=k.useState(""),[o,c]=k.useState(!1),{t:d,toggleLang:p}=dt(),u=s.length>0&&s.length<Yv,x=a.length>0&&s!==a,b=s.length>=Yv&&s===a&&!o,C=async S=>{if(S.preventDefault(),!!b){m(""),c(!0);try{await e(s,a)}catch(g){m(g instanceof Error&&g.message?g.message:d("setup.error"))}finally{c(!1)}}};return n.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[n.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),n.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[n.jsxs("div",{className:"text-center mb-10",children:[n.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:n.jsx(dl,{size:32,className:"text-accent",strokeWidth:1.5})}),n.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("setup.title")}),n.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),n.jsx("form",{onSubmit:C,children:n.jsxs("div",{className:"card p-8",children:[n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),n.jsx("input",{type:"password",value:s,onChange:S=>i(S.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),u&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),n.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),n.jsx("input",{type:"password",value:a,onChange:S=>h(S.target.value),placeholder:"*************",className:"input-field text-base"}),x&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),f&&n.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children:f}),n.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(o?"setup.loading":"setup.submit")})]})}),n.jsx("div",{className:"mt-4 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:d("setup.tunnelPaused")})]})]})}function _N(e){return et("/api/projects/browse",{initialPath:e})}function SN(e){return et("/api/projects/open-folder",{path:e})}function Iu(){return gt("/api/projects")}function kN(e){return gt(`/api/projects/${e}`)}function Gw(e){return et("/api/projects",e)}function CN(e){return gt(`/api/projects/${e}/svn-detect`)}function am(e,s){return on(`/api/projects/${e}`,s)}function jN(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return gt(`/api/projects/${e}/debug-logs${i}`)}function Vw(e){return In(`/api/projects/${e}`)}function EN(e){return et("/api/projects/reorder",{ids:e})}function NN(e){return et(`/api/projects/${e}/start`)}function LN(e){return et(`/api/projects/${e}/stop`)}function Yw(e){return gt(`/api/projects/${e}/status`)}function Xv(){return gt("/api/active-work")}function DN(e){return et(`/api/projects/${e}/check-git`)}function Xw(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return gt(`/api/projects/${e}/git-status${i}`)}function TN(e,s=0,i=50,a){const h=new URLSearchParams({skip:String(s),limit:String(i)});return gt(`/api/projects/${e}/git-log?${h}`)}function om(e,s){return gt(`/api/projects/${e}/git-refs`)}function RN(e,s,i){return et(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function MN(e,s,i){return et(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function Jw(e,s,i){return et(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function Qw(e,s,i){return et(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function tp(e,s){return et(`/api/projects/${e}/git-push`,s||{})}function AN(e){return gt(`/api/projects/${e}/git-remotes`)}function Zw(e,s,i){return et(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function e1(e,s,i){return et(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function lm(e,s,i){return et(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function cm(e,s){return et(`/api/projects/${e}/git-checkout`,{branch:s})}function t1(e,s){return et(`/api/projects/${e}/git-merge`,{branch:s})}function Jv(e,s,i,a){return et(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function ON(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return gt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function zN(e,s,i,a){return et(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function BN(e){return et(`/api/projects/${e}/git-conflict-continue`)}function PN(e){return et(`/api/projects/${e}/git-conflict-abort`)}function IN(e,s){return et(`/api/projects/${e}/git-stash`,{message:s})}function FN(e,s){return et(`/api/projects/${e}/git-stash-pop`,{index:s})}function HN(e){return gt(`/api/projects/${e}/git-stash-list`)}function $N(e,s,i,a){return et(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function n1(e,s,i,a){return et(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function Qv(e,s,i){return et(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function UN(e,s){return et(`/api/projects/${e}/git-rebase`,{onto:s})}function WN(e,s){return et(`/api/projects/${e}/git-revert`,{commit:s})}function qN(e,s){return et(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function KN(e,s,i){return et(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function GN(e,s,i,a){const h=new URLSearchParams;return s&&h.set("file",s),i&&h.set("staged","true"),a&&h.set("worktreePath",a),gt(`/api/projects/${e}/git-diff?${h}`)}function VN(e,s){const i=new URLSearchParams({hash:s});return gt(`/api/projects/${e}/git-commit-files?${i}`)}function Zv(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),gt(`/api/projects/${e}/git-commit-diff?${a}`)}function um(e){return gt(`/api/projects/${e}/worktrees`)}function eb(e,s,i){return et(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function s1(e){const s=new URLSearchParams;e.hours!==void 0&&s.set("hours",String(e.hours)),e.statuses&&e.statuses.length>0&&s.set("statuses",e.statuses.join(","));const i=s.toString();return i?`?${i}`:""}function YN(e={}){return gt(`/api/review/queue${s1(e)}`)}function r1(e={}){return gt(`/api/review/summary${s1(e)}`)}function XN(e){return gt(`/api/review/diff/${encodeURIComponent(e)}`)}function JN(e,s){return gt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function QN(){return gt("/api/favorites")}function ZN(e){return et("/api/favorites",e)}function e3(e,s){return on(`/api/favorites/${e}`,s)}function t3(e){return In(`/api/favorites/${e}`)}function n3(e){return et(`/api/favorites/${e}/launch`)}function s3(e){return et("/api/favorites/browse-file",{initialPath:e})}function dm(){return gt("/api/tunnel/status")}function r3(){return gt("/api/tunnel/config")}function i3(e){return on("/api/tunnel/config",e)}function i1(e){return et("/api/tunnel/start",{})}function a3(){return et("/api/tunnel/stop")}const a1=k.createContext({theme:"light",toggleTheme:()=>{}});function o3(){const[e,s]=k.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});k.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=k.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function l3(){return k.useContext(a1)}const o1=k.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function c3(){const e="Notification"in window,[s,i]=k.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=k.useRef(s);k.useEffect(()=>{a.current=s},[s]);const h=k.useCallback(async()=>{if(e)if(a.current)localStorage.setItem("clitrigger-notifications","off"),i(!1);else{if(Notification.permission==="denied"||Notification.permission==="default"&&await Notification.requestPermission()!=="granted")return;localStorage.setItem("clitrigger-notifications","on"),i(!0)}},[e]),f=k.useCallback((m,o)=>{if(!a.current)return;const c=new Notification(m,{body:o});c.onclick=()=>{window.focus(),c.close()}},[]);return{enabled:s,supported:e,toggleNotification:h,sendNotification:f}}function np(){return k.useContext(o1)}let u3=0;const l1=k.createContext(null);function d3({children:e}){const[s,i]=k.useState([]),a=k.useRef(new Map),h=k.useRef(new Map),f=k.useRef(new Map),m=k.useCallback(b=>{i(g=>g.filter(_=>_.id!==b));const C=f.current.get(b);C&&h.current.get(C)===b&&h.current.delete(C),f.current.delete(b);const S=a.current.get(b);S&&(clearTimeout(S),a.current.delete(b))},[]),o=k.useCallback((b,C="info",S=3500)=>{const g=`${C}:${b}`,_=h.current.get(g);if(_)return _;const w=`toast-${++u3}`;h.current.set(g,w),f.current.set(w,g),i(E=>[...E,{id:w,message:b,type:C,duration:S}]);const y=setTimeout(()=>m(w),S);return a.current.set(w,y),w},[m]),c=k.useCallback((b,C)=>o(b,"success",C),[o]),d=k.useCallback((b,C)=>o(b,"error",C),[o]),p=k.useCallback((b,C)=>o(b,"info",C),[o]),u=k.useCallback((b,C)=>o(b,"warning",C),[o]);k.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),h.current.clear(),f.current.clear()},[]);const x=k.useMemo(()=>({toasts:s,show:o,success:c,error:d,info:p,warning:u,dismiss:m}),[s,o,c,d,p,u,m]);return k.createElement(l1.Provider,{value:x},e)}function mi(){const e=k.useContext(l1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Ys(...e){return e.filter(Boolean).join(" ")}const h3={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl"},f3={scale:"animate-scale-in","slide-up":"animate-slide-up"};function Un({open:e,onClose:s,size:i="md",position:a="center",animation:h="scale",disableEscClose:f=!1,disableBackdropClose:m=!1,children:o}){const c=k.useRef(null);return k.useEffect(()=>{if(!e||f)return;const d=p=>{p.key==="Escape"&&s()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[e,f,s]),e?en.createPortal(n.jsx("div",{ref:c,className:Ys("fixed inset-0 bg-black/50 backdrop-blur-sm z-modal flex",a==="center"?"items-center justify-center p-4":"items-start justify-center px-4 pt-[20vh]"),onClick:d=>{!m&&d.target===c.current&&s()},children:n.jsx("div",{className:Ys("w-full",h3[i],f3[h]),children:o})}),document.body):null}function c1({onSubmit:e,onCancel:s}){const[i,a]=k.useState(""),[h,f]=k.useState(""),[m,o]=k.useState(!1),[c,d]=k.useState(!1),[p,u]=k.useState(""),{t:x}=dt(),b=async S=>{if(S.preventDefault(),!(!i.trim()||!h.trim())){u(""),d(!0);try{await e(i.trim(),h.trim())}catch(g){const _=g instanceof Error?g.message:String(g);u(_||x("form.createError"))}finally{d(!1)}}},C=async()=>{o(!0);try{const S=await _N(h||void 0);S.path&&f(S.path)}catch{}o(!1)};return n.jsx(Un,{open:!0,onClose:s,size:"md",children:n.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:x("form.newProject")}),n.jsxs("form",{onSubmit:b,children:[n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:x("form.projectName")}),n.jsx("input",{type:"text",placeholder:"my-project",value:i,onChange:S=>a(S.target.value),className:"input-field",autoFocus:!0})]}),n.jsxs("div",{className:"mb-8",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:x("form.folderPath")}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:h,onChange:S=>f(S.target.value),className:"input-field text-sm flex-1"}),n.jsx("button",{type:"button",onClick:C,disabled:m,className:"btn-ghost text-sm px-3 shrink-0",title:x("browse.title"),children:m?n.jsx(oi,{size:16,className:"animate-spin"}):n.jsx(zu,{size:16})})]})]}),p&&n.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:p}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:x("form.cancel")}),n.jsx("button",{type:"submit",disabled:!i.trim()||!h.trim()||c,className:"btn-primary text-sm",children:x(c?"form.creating":"form.create")})]})]})]})})}const m3=[{value:"executable",icon:Jm},{value:"command",icon:di},{value:"url",icon:ul}];function p3(e){const s=[],i=/"([^"]*)"|(\S+)/g;let a;for(;(a=i.exec(e))!==null;)s.push(a[1]!==void 0?a[1]:a[2]);return s}function tb(e){if(!e)return"";try{const s=JSON.parse(e);if(Array.isArray(s))return s.map(i=>typeof i=="string"&&/\s/.test(i)?`"${i}"`:String(i)).join(" ")}catch{}return""}function g3({initial:e,onSubmit:s,onCancel:i}){const{t:a}=dt(),[h,f]=k.useState((e==null?void 0:e.name)??""),[m,o]=k.useState((e==null?void 0:e.type)??"executable"),[c,d]=k.useState((e==null?void 0:e.target)??""),[p,u]=k.useState(tb((e==null?void 0:e.args)??null)),[x,b]=k.useState((e==null?void 0:e.cwd)??""),[C,S]=k.useState(!1);k.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),d((e==null?void 0:e.target)??""),u(tb((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[g,_]=k.useState(!1),w=m==="executable",y=async()=>{_(!0);try{const{path:O}=await s3(c||void 0);if(!O)return;if(d(O),!h.trim()){const z=O.replace(/\\/g,"/").split("/").pop()||"";f(z.replace(/\.[^.]+$/,""))}}catch{}finally{_(!1)}},E=!!e,T=h.trim(),j=c.trim(),R=m!=="url"||/^https?:\/\//i.test(j),N=!!T&&!!j&&R&&!C,D=async O=>{if(O.preventDefault(),!!N){S(!0);try{const z={name:T,type:m,target:j,args:m==="executable"&&p.trim()?p3(p.trim()):null,cwd:m!=="url"&&x.trim()?x.trim():null};await s(z)}finally{S(!1)}}},A=a(m==="executable"?"favorites.form.targetHint.executable":m==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return n.jsx(Un,{open:!0,onClose:i,size:"md",children:n.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:a(E?"favorites.form.title.edit":"favorites.form.title.create")}),n.jsxs("form",{onSubmit:D,children:[n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.type")}),n.jsx("div",{className:"grid grid-cols-3 gap-2",children:m3.map(({value:O,icon:z})=>n.jsxs("button",{type:"button",onClick:()=>o(O),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:m===O?{backgroundColor:"var(--color-accent)",color:"white",borderColor:"var(--color-accent)"}:{color:"var(--color-text-tertiary)",borderColor:"var(--color-border)"},children:[n.jsx(z,{size:14}),a(`favorites.types.${O}`)]},O))})]}),n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.name")}),n.jsx("input",{type:"text",value:h,onChange:O=>f(O.target.value),className:"input-field",autoFocus:!0})]}),n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.target")}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"text",value:c,onChange:O=>d(O.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),w&&n.jsxs("button",{type:"button",onClick:y,disabled:g,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[n.jsx(zu,{size:14}),a("favorites.form.browse")]})]}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),m==="executable"&&n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.args")}),n.jsx("input",{type:"text",value:p,onChange:O=>u(O.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),m!=="url"&&n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.cwd")}),n.jsx("input",{type:"text",value:x,onChange:O=>b(O.target.value),className:"input-field text-sm font-mono",placeholder:"C:/Projects/my-project"})]}),n.jsx("p",{className:"mb-6 text-2xs leading-snug",style:{color:"var(--color-text-muted)"},children:a("favorites.security.notice")}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{type:"button",onClick:i,className:"btn-ghost text-sm",children:a("favorites.form.cancel")}),n.jsx("button",{type:"submit",disabled:!N,className:"btn-primary text-sm",children:a(E?"favorites.form.save":"favorites.form.create")})]})]})]})})}const x3=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function v3({onClose:e}){const{t:s}=dt(),{error:i,success:a}=mi(),[h,f]=k.useState(""),[m,o]=k.useState(""),[c,d]=k.useState(""),[p,u]=k.useState(""),[x,b]=k.useState(!1),[C,S]=k.useState(!1),[g,_]=k.useState(!1),[w,y]=k.useState(null);k.useEffect(()=>{let z=!1;return Promise.all([r3(),dm()]).then(([P,F])=>{z||(f(P.tunnelName),o(P.customHostname),d(P.tunnelName),u(P.customHostname),y(F))}).catch(()=>{}),()=>{z=!0}},[]);const E=h.trim(),T=m.trim(),j=E!==c.trim()||T!==p.trim(),R=!!T&&(!x3.test(T)||T.toLowerCase()==="localhost"||T.toLowerCase()==="127.0.0.1"),N=!!T&&!E,D=j&&!C&&!R&&!N,A=async()=>{if(D){S(!0);try{const z=await i3({tunnelName:E,customHostname:T});d(z.tunnelName),u(z.customHostname),f(z.tunnelName),o(z.customHostname),a(s("tunnel.saved"))}catch(z){i(z instanceof Error?z.message:s("tunnel.saveFailed"))}finally{S(!1)}}},O=async()=>{_(!0);try{try{await a3()}catch{}const z=await i1();y({status:"running",url:z.url}),a(s("tunnel.restarted"))}catch(z){i(z instanceof Error?z.message:s("tunnel.restartFailed"))}finally{_(!1)}};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),w&&n.jsxs("div",{className:"mb-5 p-3 rounded-lg text-xs flex items-center gap-2",style:{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-tertiary)"},children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${w.status==="running"?"bg-status-success":w.status==="error"?"bg-status-error":"bg-status-pending"}`}),n.jsx("span",{className:"font-medium",children:s(`tunnel.status.${w.status}`)}),w.url&&n.jsx("a",{href:w.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:w.url})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),n.jsx("input",{type:"text",value:h,onChange:z=>f(z.target.value),placeholder:s("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.name.hint")})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.hostname.label")}),n.jsx("input",{type:"text",value:m,onChange:z=>o(z.target.value),placeholder:s("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.hostname.hint")}),R&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),N&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.needsName")})]}),n.jsxs("div",{className:"mb-5",children:[n.jsxs("button",{type:"button",onClick:()=>b(!x),className:"flex items-center gap-1 text-xs text-accent-dark hover:text-accent transition-colors",children:[n.jsx("span",{className:`inline-block transition-transform ${x?"rotate-90":""}`,children:"▶"}),s("tunnel.guide.toggle")]}),x&&n.jsxs("div",{className:"mt-3 p-3 bg-warm-50 border border-warm-150 rounded-lg text-xs text-warm-600 space-y-2",children:[n.jsx("p",{className:"font-semibold text-warm-700 mb-1",children:s("tunnel.guide.heading")}),n.jsxs("ol",{className:"list-decimal list-inside space-y-1 ml-1",children:[n.jsx("li",{children:n.jsx("code",{className:"font-mono",children:"cloudflared tunnel login"})}),n.jsx("li",{children:n.jsx("code",{className:"font-mono",children:"cloudflared tunnel create my-app"})}),n.jsx("li",{children:n.jsx("code",{className:"font-mono",children:"cloudflared tunnel route dns my-app app.your-domain.com"})}),n.jsx("li",{children:s("tunnel.guide.step4")})]}),n.jsx("p",{className:"text-2xs text-warm-400 pt-1",children:s("tunnel.guide.note")})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("button",{type:"button",onClick:O,disabled:g,className:"btn-ghost text-sm disabled:opacity-50",children:g?(w==null?void 0:w.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(w==null?void 0:w.status)==="running"?s("tunnel.restart"):s("tunnel.start")}),n.jsxs("div",{className:"flex gap-3",children:[e&&n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),n.jsx("button",{type:"button",onClick:A,disabled:!D,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const nb=8;function b3({onClose:e}){const{t:s}=dt(),{error:i,success:a}=mi(),[h,f]=k.useState(""),[m,o]=k.useState(""),[c,d]=k.useState(""),[p,u]=k.useState(!1),x=m.length>0&&m.length<nb,b=c.length>0&&m!==c,C=!!h&&m.length>=nb&&m===c&&!p,S=()=>{f(""),o(""),d("")},g=async()=>{if(C){u(!0);try{await Ow(h,m,c),a(s("account.saved")),S()}catch(_){i(_ instanceof Error&&_.message?_.message:s("account.saveFailed"))}finally{u(!1)}}};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("account.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("account.description")}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.oldPassword")}),n.jsx("input",{type:"password",value:h,onChange:_=>f(_.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.newPassword")}),n.jsx("input",{type:"password",value:m,onChange:_=>o(_.target.value),className:"input-field text-sm",autoComplete:"new-password"}),x&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.tooShort")})]}),n.jsxs("div",{className:"mb-6",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.confirm")}),n.jsx("input",{type:"password",value:c,onChange:_=>d(_.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&n.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),n.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),n.jsx("button",{type:"button",onClick:g,disabled:!C,className:"btn-primary text-sm",children:s(p?"account.saving":"account.save")})]})]})}function sp(){return gt("/api/session-tags")}function y3(e){return et("/api/session-tags",e)}function w3(e,s){return on(`/api/session-tags/${e}`,s)}function _3(e){return In(`/api/session-tags/${e}`)}function u1(){return gt("/api/session-aliases")}function d1(e){return et("/api/session-aliases",e)}function S3(e,s){return on(`/api/session-aliases/${e}`,s)}function k3(e){return In(`/api/session-aliases/${e}`)}function rp(){return gt("/api/session-settings")}function df(e){return on("/api/session-settings",e)}const He={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},Rt="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",ip=13,Qo=8,Zo=28,$a=new Map,Ui=new Map;let bu=ip;function ap(e){return`sessionFontSize:${e}`}window.addEventListener("storage",e=>{var a;if(e.storageArea!==localStorage||!((a=e.key)!=null&&a.startsWith("sessionFontSize:")))return;const s=e.key.slice(16);$a.delete(s);const i=Ui.get(s);if(i){const h=el(s);i.forEach(f=>f(h))}});function hm(e){return Number.isFinite(e)?Math.max(Qo,Math.min(Zo,Math.round(e))):bu}function C3(e){if($a.has(e))return!0;try{return localStorage.getItem(ap(e))!==null}catch{return!1}}function el(e){const s=$a.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(ap(e));if(a!==null){const h=parseInt(a,10);Number.isFinite(h)&&(i=hm(h))}}catch{}return i===null?hm(bu):($a.set(e,i),i)}function fm(e,s){const i=hm(s);if($a.get(e)===i)return;$a.set(e,i);try{localStorage.setItem(ap(e),String(i))}catch{}const a=Ui.get(e);a&&a.forEach(h=>h(i))}function Ho(e,s){fm(e,el(e)+s)}function ou(e){const s=Math.max(Qo,Math.min(Zo,Math.round(e)));Number.isFinite(s)&&s!==bu&&(bu=s,Ui.forEach((i,a)=>{C3(a)||i.forEach(h=>h(s))}))}function h1(e){const[s,i]=k.useState(()=>el(e));k.useEffect(()=>{i(el(e));let f=Ui.get(e);return f||(f=new Set,Ui.set(e,f)),f.add(i),()=>{const m=Ui.get(e);m&&(m.delete(i),m.size===0&&Ui.delete(e))}},[e]);const a=k.useCallback(f=>fm(e,f),[e]),h=k.useCallback(f=>fm(e,el(e)+f),[e]);return[s,a,h]}const tl=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function sb(e){for(const s of tl)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return tl[e.length%tl.length]}function j3({onClose:e}){const{t:s}=dt(),{error:i,success:a}=mi(),[h,f]=k.useState([]),[m,o]=k.useState(!1),[c,d]=k.useState(ip),[p,u]=k.useState(!1),[x,b]=k.useState(!1),[C,S]=k.useState(!1),[g,_]=k.useState(!1),w=k.useRef(null),[y,E]=k.useState(""),[T,j]=k.useState(tl[0]),[R,N]=k.useState(!1),[D,A]=k.useState(null),[O,z]=k.useState(""),[P,F]=k.useState(tl[0]),[H,$]=k.useState(!1),[q,Y]=k.useState([]),[I,B]=k.useState(""),[U,J]=k.useState(""),[W,oe]=k.useState(!1),[ee,Z]=k.useState(null),[X,G]=k.useState(""),[me,ge]=k.useState(""),[xe,he]=k.useState(!1);k.useEffect(()=>{let se=!1;return Promise.all([sp(),rp(),u1()]).then(([le,ve,Ce])=>{se||(f(le),o(ve.defaultUseWorktree),d(ve.defaultFontSize),ou(ve.defaultFontSize),u(ve.imeDebug),j(sb(le)),Y(Ce),b(!0))}).catch(le=>{se||i(le instanceof Error?le.message:"Failed to load")}),()=>{se=!0}},[i]);const Ie=y.trim(),Fe=!!Ie&&!R,be=k.useMemo(()=>[...h].sort((se,le)=>se.sort_order-le.sort_order||se.name.localeCompare(le.name)),[h]);k.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const Ue=se=>{if(!Number.isFinite(se))return;const le=Math.max(Qo,Math.min(Zo,Math.round(se)));d(le),ou(le),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{df({defaultFontSize:le}).then(ve=>{d(ve.defaultFontSize),ou(ve.defaultFontSize)}).catch(ve=>i(ve instanceof Error?ve.message:"Save failed"))},350)},Pe=async se=>{S(!0);try{const le=await df({defaultUseWorktree:se});o(le.defaultUseWorktree),a(s("sessionSettings.saved"))}catch(le){i(le instanceof Error?le.message:"Save failed")}finally{S(!1)}},tt=async se=>{var le,ve;_(!0);try{const Ce=await df({imeDebug:se});u(Ce.imeDebug),(ve=(le=window.electronAPI)==null?void 0:le.imeSetDebug)==null||ve.call(le,Ce.imeDebug),a(s("sessionSettings.saved"))}catch(Ce){i(Ce instanceof Error?Ce.message:"Save failed")}finally{_(!1)}},ke=async()=>{if(Fe){N(!0);try{const se=await y3({name:Ie,color:T});f(le=>[...le,se]),E(""),j(sb([...h,se]))}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{N(!1)}}},pe=se=>{A(se.id),z(se.name),F(se.color)},Ne=()=>{A(null),z("")},Le=async()=>{if(!D)return;const se=O.trim();if(se){$(!0);try{const le=await w3(D,{name:se,color:P});f(ve=>ve.map(Ce=>Ce.id===le.id?le:Ce)),Ne()}catch(le){i(le instanceof Error?le.message:"Save failed")}finally{$(!1)}}},ze=async se=>{if(confirm(s("sessionSettings.tags.deleteConfirm").replace("{name}",se.name)))try{await _3(se.id),f(le=>le.filter(ve=>ve.id!==se.id))}catch(le){i(le instanceof Error?le.message:"Delete failed")}},Ke=I.trim(),Ve=U.trim(),de=!!Ke&&!!Ve&&!W,fe=k.useMemo(()=>[...q].sort((se,le)=>se.sort_order-le.sort_order||se.name.localeCompare(le.name)),[q]),ce=async()=>{if(de){oe(!0);try{const se=await d1({name:Ke,command_template:Ve});Y(le=>[...le,se]),B(""),J("")}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{oe(!1)}}},Q=se=>{Z(se.id),G(se.name),ge(se.command_template)},V=()=>{Z(null),G(""),ge("")},re=async()=>{if(!ee)return;const se=X.trim(),le=me.trim();if(!(!se||!le)){he(!0);try{const ve=await S3(ee,{name:se,command_template:le});Y(Ce=>Ce.map(De=>De.id===ve.id?ve:De)),V()}catch(ve){i(ve instanceof Error?ve.message:"Save failed")}finally{he(!1)}}},te=async se=>{if(confirm(`Delete alias "${se.name}"? Sessions using it will fall back to OS default shell.`))try{await k3(se.id),Y(le=>le.filter(ve=>ve.id!==se.id))}catch(le){i(le instanceof Error?le.message:"Delete failed")}};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("sessionSettings.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("sessionSettings.description")}),n.jsxs("section",{className:"mb-7",children:[n.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[n.jsx(Ga,{size:14}),s("sessionSettings.worktree.title")]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:C||!x,onChange:se=>Pe(se.target.checked),className:"rounded border-warm-300"}),n.jsx("span",{className:"text-sm text-warm-600",children:s("sessionSettings.worktree.label")})]}),n.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.worktree.hint")})]}),n.jsxs("section",{className:"mb-7",children:[n.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[n.jsx(cN,{size:14}),s("sessionSettings.fontSize.title")]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"range",min:Qo,max:Zo,step:1,value:c,disabled:!x,onChange:se=>Ue(parseInt(se.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),n.jsx("input",{type:"number",min:Qo,max:Zo,step:1,value:c,disabled:!x,onChange:se=>Ue(parseInt(se.target.value,10)),className:"input text-sm w-20"}),n.jsx("span",{className:"text-xs text-warm-400",children:"px"})]}),n.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.fontSize.hint")})]}),n.jsxs("section",{children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:s("sessionSettings.tags.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-3",children:s("sessionSettings.tags.description")}),n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx("input",{type:"color",value:T,onChange:se=>j(se.target.value),className:"w-9 h-9 rounded cursor-pointer border border-warm-200",title:s("sessionSettings.tags.color")}),n.jsx("input",{type:"text",value:y,onChange:se=>E(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),ke())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),n.jsxs("button",{type:"button",onClick:ke,disabled:!Fe,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[n.jsx(mn,{size:14}),s("sessionSettings.tags.add")]})]}),be.length===0?n.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:s("sessionSettings.tags.empty")}):n.jsx("ul",{className:"space-y-1.5",children:be.map(se=>{const le=D===se.id;return n.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:le?n.jsxs(n.Fragment,{children:[n.jsx("input",{type:"color",value:P,onChange:ve=>F(ve.target.value),className:"w-7 h-7 rounded cursor-pointer border border-warm-200"}),n.jsx("input",{type:"text",value:O,onChange:ve=>z(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&(ve.preventDefault(),Le()),ve.key==="Escape"&&Ne()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),n.jsx("button",{type:"button",onClick:Le,disabled:H||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:s("sessionSettings.tags.save"),children:n.jsx(_r,{size:14})}),n.jsx("button",{type:"button",onClick:Ne,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.cancel"),children:n.jsx(Jt,{size:14})})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:se.color,borderColor:"rgba(0,0,0,0.08)"}}),n.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:se.name}),n.jsx("button",{type:"button",onClick:()=>pe(se),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.edit"),children:n.jsx(ci,{size:14})}),n.jsx("button",{type:"button",onClick:()=>ze(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:s("sessionSettings.tags.delete"),children:n.jsx(Ln,{size:14})})]})},se.id)})})]}),n.jsxs("section",{className:"mt-7",children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:"Terminal aliases"}),n.jsx("p",{className:"text-xs text-warm-400 mb-3",children:"Saved command snippets. Click the ⌘ icon in any terminal window's titlebar to insert one as input — Enter is yours to press."}),n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx("input",{type:"text",value:I,onChange:se=>B(se.target.value),placeholder:"Name (e.g. WSL Ubuntu)",className:"input text-sm w-44",maxLength:64}),n.jsx("input",{type:"text",value:U,onChange:se=>J(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),ce())},placeholder:"Command (e.g. wsl -d Ubuntu)",className:"input text-sm flex-1 font-mono",maxLength:1024}),n.jsxs("button",{type:"button",onClick:ce,disabled:!de,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[n.jsx(mn,{size:14}),"Add"]})]}),fe.length===0?n.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:"No aliases yet."}):n.jsx("ul",{className:"space-y-1.5",children:fe.map(se=>{const le=ee===se.id;return n.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:le?n.jsxs(n.Fragment,{children:[n.jsx("input",{type:"text",value:X,onChange:ve=>G(ve.target.value),className:"input text-sm w-44",maxLength:64}),n.jsx("input",{type:"text",value:me,onChange:ve=>ge(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&(ve.preventDefault(),re()),ve.key==="Escape"&&V()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),n.jsx("button",{type:"button",onClick:re,disabled:xe||!X.trim()||!me.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:"Save",children:n.jsx(_r,{size:14})}),n.jsx("button",{type:"button",onClick:V,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:"Cancel",children:n.jsx(Jt,{size:14})})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:se.name}),n.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:se.command_template}),n.jsx("button",{type:"button",onClick:()=>Q(se),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded",title:"Edit",children:n.jsx(ci,{size:14})}),n.jsx("button",{type:"button",onClick:()=>te(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:"Delete",children:n.jsx(Ln,{size:14})})]})},se.id)})})]}),n.jsxs("section",{className:"mt-7",children:[n.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[n.jsx(V5,{size:14}),"IME 디버그 로그"]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:p,disabled:g||!x,onChange:se=>tt(se.target.checked),className:"rounded border-warm-300"}),n.jsx("span",{className:"text-sm text-warm-600",children:"한글 입력(IME) 진단 로그 기록"})]}),n.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:"조합 창이 화면 좌상단에 뜨는 문제를 진단하기 위해 입력 시점 상태를 기록합니다. 데스크톱 앱에서만 동작하며, 로그는 앱 데이터 폴더의 ime-debug.log에 저장됩니다."})]}),e&&n.jsx("div",{className:"flex justify-end gap-3 mt-7",children:n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")})})]})}function E3(){return gt("/api/mcp/connection")}function N3({onClose:e}){const{t:s}=dt(),{success:i,error:a}=mi(),[h,f]=k.useState(null),[m,o]=k.useState(null);k.useEffect(()=>{let x=!1;return E3().then(b=>{x||f(b)}).catch(()=>{}),()=>{x=!0}},[]);const c=async(x,b)=>{try{await navigator.clipboard.writeText(b),o(x),setTimeout(()=>o(C=>C===x?null:C),1500),i(s("mcp.copied"))}catch{a(s("mcp.copyFailed"))}},d=h?JSON.stringify(h.config,null,2):"",p=({label:x,text:b})=>n.jsxs("button",{type:"button",onClick:()=>c(x,b),className:"btn-ghost text-xs flex items-center gap-1",children:[m===x?n.jsx(_r,{size:13}):n.jsx(Dj,{size:13}),s("mcp.copy")]}),u={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return n.jsxs("div",{className:"p-8",children:[n.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("mcp.title")}),n.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("mcp.description")}),h?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mb-5",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600",children:s("mcp.config.label")}),n.jsx(p,{label:"config",text:d})]}),n.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:u,children:d})]}),n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:s("mcp.commands.label")}),n.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:s("mcp.commands.hint")}),n.jsx("div",{className:"space-y-3",children:h.commands.map(x=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-1",children:[n.jsx("span",{className:"text-xs text-warm-500",children:x.label}),n.jsx(p,{label:`command:${x.id}`,text:x.command})]}),n.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:u,children:x.command})]},x.id))})]}),n.jsx("p",{className:"text-2xs text-warm-400",children:s("mcp.tokenNote")})]}):n.jsx("p",{className:"text-sm text-warm-400",children:s("mcp.loading")}),e&&n.jsx("div",{className:"flex justify-end mt-6",children:n.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("mcp.close")})})]})}function rb({open:e,onClose:s}){const{t:i}=dt(),[a,h]=k.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:oE},{id:"session",label:i("settings.tabs.session"),icon:dl},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:$w},{id:"mcp",label:i("settings.tabs.mcp"),icon:$E}];return n.jsx(Un,{open:e,onClose:s,size:"xl",children:n.jsx("div",{className:"card shadow-2xl rounded-2xl overflow-hidden",children:n.jsxs("div",{className:"flex",style:{minHeight:460},children:[n.jsxs("aside",{className:"w-44 shrink-0 border-r flex flex-col",style:{borderColor:"var(--color-border)",backgroundColor:"var(--color-bg-hover)"},children:[n.jsx("div",{className:"px-4 pt-5 pb-3 text-xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:i("settings.title")}),n.jsx("nav",{className:"flex flex-col",children:f.map(({id:m,label:o,icon:c})=>{const d=a===m;return n.jsxs("button",{type:"button",onClick:()=>h(m),className:"flex items-center gap-2 px-4 py-2.5 text-sm transition-colors text-left",style:{color:d?"var(--color-accent)":"var(--color-text-secondary)",backgroundColor:d?"var(--color-bg-primary)":"transparent",fontWeight:d?600:400},children:[n.jsx(c,{size:14}),n.jsx("span",{children:o})]},m)})}),n.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.48"]})]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&n.jsx(b3,{onClose:s}),a==="session"&&n.jsx(j3,{onClose:s}),a==="tunnel"&&n.jsx(v3,{onClose:s}),a==="mcp"&&n.jsx(N3,{onClose:s})]})]})})})}const mm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function L3(e,s){let i=0;for(let a=0;a<e.length;a++)i=(i<<5)-i+e.charCodeAt(a)|0;return Math.abs(i)%s}function Ua(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:mm[L3(e.id,mm.length)]}const ib=192,D3=88,Ic=8;function T3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:h}){const f=k.useRef(null),[m,o]=k.useState({left:s,top:i}),c=Ua(e);return k.useLayoutEffect(()=>{const d=Math.min(Math.max(s,Ic),window.innerWidth-ib-Ic),p=Math.min(Math.max(i,Ic),window.innerHeight-D3-Ic);o({left:d,top:p})},[s,i]),k.useEffect(()=>{const d=u=>{var x;(x=f.current)!=null&&x.contains(u.target)||h()},p=u=>{u.key==="Escape"&&h()};return window.addEventListener("mousedown",d),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",p)}},[h]),en.createPortal(n.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:ib,background:"var(--color-bg-elevated, #1f1f23)",border:"1px solid var(--color-border)",borderRadius:10,padding:10,boxShadow:"0 12px 32px rgba(0,0,0,0.45)"},children:[n.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:8},children:mm.map(d=>{const p=e.color?d.toLowerCase()===e.color.toLowerCase():d===c&&!e.color;return n.jsx("button",{onClick:()=>a(d),"aria-label":d,style:{width:20,height:20,borderRadius:6,background:d,border:p?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},d)})}),n.jsx("button",{onClick:()=>a(null),style:{width:"100%",background:"transparent",border:"1px solid var(--color-border)",color:"var(--color-text-tertiary)",padding:"4px 8px",borderRadius:6,fontSize:11,cursor:"pointer"},children:"자동 색 (기본값)"})]}),document.body)}function nl(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function R3(e){const s=e instanceof Error?e.message:typeof e=="string"?e:"";return/^ResizeObserver loop (?:limit exceeded|completed with undelivered notifications\.?)$/i.test(s.trim())}const M3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},A3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},bn=k.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:h,type:f="button",title:m,className:o,...c},d){return n.jsx("button",{ref:d,type:f,"aria-label":s,"aria-pressed":h,title:m??s,className:Ys("btn-icon",M3[i],A3[a],o),...c})});function O3(e){return e==="executable"?Jm:e==="command"?di:ul}function z3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:h,collapsed:f=!1,onToggleCollapsed:m}){var de;const[o,c]=k.useState([]),[d,p]=k.useState({}),[u,x]=k.useState(null),[b,C]=k.useState(!1),[S,g]=k.useState(null),[_,w]=k.useState([]),[y,E]=k.useState(!1),[T,j]=k.useState(null),[R,N]=k.useState(!1),[D,A]=k.useState(null),[O,z]=k.useState(!1),[P,F]=k.useState(null),[H,$]=k.useState(null),q=Ds(),Y=fi(),{t:I,toggleLang:B}=dt(),{theme:U,toggleTheme:J}=l3(),{enabled:W,supported:oe,toggleNotification:ee}=np(),{error:Z,success:X,info:G,warning:me}=mi(),ge=((de=q.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:de[1])||null;k.useEffect(()=>{tt(),he(),dm().then(A).catch(()=>{})},[]);async function xe(){if(!O){z(!0);try{const fe=await dm();if(A(fe),fe.status==="running"&&fe.url){await navigator.clipboard.writeText(fe.url),X(I("tunnel.urlCopied"));return}const ce=await i1(),Q={status:"running",url:ce.url};A(Q);try{await navigator.clipboard.writeText(ce.url),X(I("tunnel.urlCopied"))}catch{X(ce.url)}}catch(fe){Z(fe instanceof Error?fe.message:I("tunnel.restartFailed"))}finally{z(!1)}}}function he(){QN().then(w).catch(()=>{})}const Ie=async fe=>{try{T?await e3(T.id,fe):await ZN(fe),E(!1),j(null),he()}catch(ce){Z(ce instanceof Error?ce.message:"Failed to save favorite")}},Fe=async fe=>{try{await n3(fe)}catch(ce){const Q=ce instanceof Error?ce.message:I("favorites.launchFailed");Z(`${I("favorites.launchFailed")}: ${Q}`)}},be=async(fe,ce)=>{if(ce.preventDefault(),ce.stopPropagation(),!!confirm(I("favorites.deleteConfirm")))try{await t3(fe),w(Q=>Q.filter(V=>V.id!==fe))}catch(Q){Z(Q instanceof Error?Q.message:"Failed to delete favorite")}},Ue=(fe,ce)=>{ce.preventDefault(),ce.stopPropagation(),j(fe),E(!0)};k.useEffect(()=>{const fe=()=>tt();return window.addEventListener("projects:changed",fe),()=>window.removeEventListener("projects:changed",fe)},[]),k.useEffect(()=>{const fe=()=>Pe();return window.addEventListener("review:changed",fe),()=>window.removeEventListener("review:changed",fe)},[]),k.useEffect(()=>a(fe=>{var ce;if(fe.type==="project:status-changed"&&fe.projectId&&p(Q=>({...Q,[fe.projectId]:{running:fe.running??0,completed:fe.completed??0,total:fe.total??0,running_sessions:fe.running_sessions??0,running_discussions:fe.running_discussions??0}})),fe.type==="todo:status-changed"&&Pe(),fe.type==="memory:ingest-finished"){const Q=o.find(De=>De.id===fe.projectId),V=(Q==null?void 0:Q.name)??"",re=fe.sourceTitle?`“${fe.sourceTitle}”`:fe.sourceType??"",te=V?`[${V}] `:"";if(fe.error){Z(`${te}${I("wiki.ingest.toast.failed")}: ${fe.error}`,6e3);return}const se=fe.created??0,le=fe.updated??0,ve=fe.edgesAdded??0;if(se+le+ve>0){const De=I("wiki.ingest.toast.success").replace("{source}",re).replace("{created}",String(se)).replace("{updated}",String(le)).replace("{edges}",String(ve));X(`${te}${De}`)}else(ce=fe.skipped)!=null&&ce.parseFailed?me(`${te}${I("wiki.ingest.toast.parseFailed").replace("{source}",re)}`,5e3):G(`${te}${I("wiki.ingest.toast.empty").replace("{source}",re)}`,4e3)}}),[a,o,I,Z,G,X,me]),k.useEffect(()=>{Pe()},[]);function Pe(){r1({hours:24}).then(fe=>x(fe.total_todos)).catch(()=>{})}function tt(){Iu().then(fe=>{c(fe),fe.forEach(ce=>{Yw(ce.id).then(Q=>{p(V=>({...V,[ce.id]:Q}))}).catch(()=>{})})}).catch(()=>{})}const ke=()=>{h==null||h()},pe=async(fe,ce)=>{await Gw({name:fe,path:ce}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Ne=k.useCallback(async(fe,ce)=>{const Q=o.map(De=>De.id),V=Q.indexOf(fe);if(V<0)return;const re=Q.filter(De=>De!==fe),te=ce>V?ce-1:ce;if(te===V)return;const se=[...re.slice(0,te),fe,...re.slice(te)],le=o,ve=new Map(o.map(De=>[De.id,De])),Ce=se.map(De=>ve.get(De)).filter(Boolean);c(Ce);try{await EN(se)}catch(De){c(le),Z(De instanceof Error?De.message:"Failed to reorder projects")}},[o,Z]),Le=k.useRef(!1),ze=k.useCallback((fe,ce)=>{if(ce.button!==0||ce.target.closest("button"))return;ce.preventDefault();const V=ce.clientX,re=ce.clientY,te=6;let se=!1,le=null;const ve=ot=>{const Je=document.querySelectorAll("[data-workspace-item]");if(Je.length===0)return null;const qe=Je[0].getBoundingClientRect();if(ot<qe.top)return 0;const ft=Je[Je.length-1].getBoundingClientRect();if(ot>ft.bottom)return Je.length;for(let lt=0;lt<Je.length;lt++){const xt=Je[lt].getBoundingClientRect();if(ot>=xt.top&&ot<=xt.bottom){const pt=xt.top+xt.height/2;return ot<pt?lt:lt+1}}return null},Ce=ot=>{if(!se){if(Math.hypot(ot.clientX-V,ot.clientY-re)<te)return;se=!0,F(fe)}const Je=ve(ot.clientY);Je!==le&&(le=Je,$(Je))},De=()=>{window.removeEventListener("mousemove",Ce),window.removeEventListener("mouseup",Qe),window.removeEventListener("keydown",ut)},Qe=()=>{if(De(),!se)return;Le.current=!0,requestAnimationFrame(()=>{Le.current=!1});const ot=le;F(null),$(null),ot!==null&&Ne(fe,ot)},ut=ot=>{ot.key==="Escape"&&(De(),F(null),$(null),se&&(Le.current=!0,requestAnimationFrame(()=>{Le.current=!1})))};window.addEventListener("mousemove",Ce),window.addEventListener("mouseup",Qe),window.addEventListener("keydown",ut)},[Ne]),Ke=async(fe,ce)=>{if(ce.preventDefault(),ce.stopPropagation(),!!confirm(I("projects.deleteConfirm")))try{await Vw(fe),c(Q=>Q.filter(V=>V.id!==fe)),window.dispatchEvent(new Event("projects:changed")),ge===String(fe)&&Y("/")}catch(Q){Z(nl(Q,I("errors.projectDelete")))}},Ve=fe=>n.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...fe==="above"?{top:-1}:{bottom:-1}}});if(f){const fe=n.jsx("div",{className:"w-7 border-t my-1.5",style:{borderColor:"var(--color-border)"}});return n.jsxs("div",{className:"flex flex-col items-center h-full glass border-none py-3",children:[n.jsx(bn,{onClick:m,label:I("sidebar.expand"),size:"lg",children:n.jsx(zE,{size:18})}),fe,n.jsx(Pn,{to:"/",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:q.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.home"),children:n.jsx($v,{size:18})}),n.jsxs(Pn,{to:"/review",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:q.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.review"),children:[n.jsx(gu,{size:18}),u!==null&&u>0&&n.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]}),n.jsx(Pn,{to:"/agenda",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:q.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.agenda"),children:n.jsx(tm,{size:18})}),fe,n.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(ce=>{const Q=d[ce.id],V=ge===String(ce.id),re=Q?Q.running+Q.running_sessions+Q.running_discussions:0,te=re>0,se=Ua(ce);return n.jsxs(Pn,{to:`/projects/${ce.id}`,onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:V?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:te?`${ce.name} · ${re} ${I("detail.live")}`:ce.name,children:[V&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),n.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${te?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:V||te?1:.55}})]},ce.id)})}),fe,n.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?I("detail.live"):"Disconnected"}),n.jsx(bn,{onClick:J,label:I(U==="light"?"theme.dark":"theme.light"),size:"lg",children:U==="light"?n.jsx(Wv,{size:16}):n.jsx(Kv,{size:16})}),n.jsx(bn,{onClick:()=>N(!0),label:I("settings.title"),size:"lg",children:n.jsx(vu,{size:16})}),n.jsx(rb,{open:R,onClose:()=>N(!1)})]})}return n.jsxs("div",{className:"flex flex-col h-full glass border-none",onDragStart:fe=>fe.preventDefault(),children:[n.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[n.jsx(Pn,{to:"/",onClick:ke,className:"block",children:n.jsxs("svg",{viewBox:"0 0 200 32",fill:"none",className:"h-6 w-auto",children:[n.jsxs("text",{x:"0",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-accent)",opacity:"0.5",children:[">","_"]}),n.jsx("text",{x:"38",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"700",fill:"var(--color-accent)",children:"CLI"}),n.jsx("text",{x:"96",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-text-primary)",children:"Trigger"})]})}),n.jsx(bn,{onClick:m,label:I("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:n.jsx(AE,{size:16})})]}),n.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[n.jsxs(Pn,{to:"/",onClick:ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${q.pathname==="/"?"font-medium":""}`,style:q.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[q.pathname==="/"&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),n.jsx($v,{size:16}),I("sidebar.home")]}),n.jsxs(Pn,{to:"/review",onClick:ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${q.pathname==="/review"?"font-medium":""}`,style:q.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[q.pathname==="/review"&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),n.jsx(gu,{size:16}),n.jsx("span",{className:"flex-1",children:I("sidebar.review")}),u!==null&&u>0&&n.jsx("span",{className:"text-2xs px-1.5 py-0.5 rounded-full font-medium",style:{backgroundColor:"var(--color-accent)",color:"white"},children:u})]}),n.jsxs(Pn,{to:"/agenda",onClick:ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${q.pathname==="/agenda"?"font-medium":""}`,style:q.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[q.pathname==="/agenda"&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),n.jsx(tm,{size:16}),I("sidebar.agenda")]})]}),n.jsx("div",{className:"mx-4 border-t",style:{borderColor:"var(--color-border)"}}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 pt-3",children:[n.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:I("sidebar.workspaces")}),n.jsx(bn,{onClick:()=>C(!0),label:I("projects.new"),size:"sm",children:n.jsx(mn,{size:14,strokeWidth:2})})]}),n.jsx("div",{className:"space-y-0.5",children:o.map((fe,ce)=>{const Q=d[fe.id],V=ge===String(fe.id),re=Q?Q.running+Q.running_sessions+Q.running_discussions:0,te=re>0,se=Ua(fe),le=P===fe.id,ve=P!==null&&H===ce,Ce=P!==null&&ce===o.length-1&&H===o.length;return n.jsxs("div",{className:"relative","data-workspace-item":!0,children:[ve&&Ve("above"),n.jsxs(Pn,{to:`/projects/${fe.id}`,draggable:!1,onDragStart:De=>De.preventDefault(),onClick:De=>{if(Le.current){De.preventDefault();return}ke()},onMouseDown:De=>ze(fe.id,De),onContextMenu:De=>{De.preventDefault(),g({project:fe,x:De.clientX,y:De.clientY})},className:`relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group ${V?"font-medium":""} ${le?"opacity-50":""}`,style:V?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:P?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:P?"grabbing":"pointer",userSelect:"none"},children:[V&&n.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),n.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${te?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:V||te?1:.55},title:te?`${I("sidebar.workspaces")} · ${re} ${I("detail.live")}`:fe.name}),n.jsx("span",{className:"truncate flex-1",children:fe.name}),n.jsx(bn,{onClick:De=>Ke(fe.id,De),label:I("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:n.jsx(Jt,{size:12,strokeWidth:2})})]}),Ce&&Ve("below")]},fe.id)})})]}),b&&n.jsx(c1,{onSubmit:(fe,ce)=>pe(fe,ce),onCancel:()=>C(!1)}),n.jsxs("div",{className:"px-3 pt-3 pb-2 border-t",style:{borderColor:"var(--color-border)"},children:[n.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:I("sidebar.favorites")}),n.jsx(bn,{onClick:()=>{j(null),E(!0)},label:I("favorites.add"),size:"sm",children:n.jsx(mn,{size:14,strokeWidth:2})})]}),n.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:_.map(fe=>{const ce=O3(fe.type);return n.jsxs("button",{onClick:()=>Fe(fe.id),className:"w-full relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group",style:{color:"var(--color-text-tertiary)"},title:fe.target,children:[n.jsx(ce,{size:14,className:"flex-shrink-0"}),n.jsx("span",{className:"truncate flex-1 text-left",children:fe.name}),n.jsx("span",{onClick:Q=>Ue(fe,Q),className:"flex-shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 transition-all hover:bg-theme-hover cursor-pointer",style:{color:"var(--color-text-muted)"},title:I("favorites.edit"),children:n.jsx(im,{size:11,strokeWidth:2})}),n.jsx("span",{onClick:Q=>be(fe.id,Q),className:"flex-shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 transition-all hover:bg-status-error/10 cursor-pointer",style:{color:"var(--color-text-muted)"},title:I("favorites.delete"),children:n.jsx(Jt,{size:12,strokeWidth:2})})]},fe.id)})})]}),y&&n.jsx(g3,{initial:T??void 0,onSubmit:Ie,onCancel:()=>{E(!1),j(null)}}),S&&n.jsx(T3,{project:S.project,anchorX:S.x,anchorY:S.y,onPick:async fe=>{try{const ce=await am(S.project.id,{color:fe});c(Q=>Q.map(V=>V.id===ce.id?{...V,color:ce.color}:V)),window.dispatchEvent(new Event("projects:changed"))}catch(ce){Z(ce instanceof Error?ce.message:"Failed to update color")}g(null)},onClose:()=>g(null)}),n.jsx(rb,{open:R,onClose:()=>N(!1)}),n.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:n.jsxs("div",{className:"flex items-center gap-1 px-1",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 mr-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?I("detail.live"):"Disconnected"}),n.jsx(bn,{onClick:J,label:I(U==="light"?"theme.dark":"theme.light"),children:U==="light"?n.jsx(Wv,{size:16}):n.jsx(Kv,{size:16})}),n.jsx(bn,{onClick:B,label:I("lang.toggle"),className:"text-xs font-medium",children:I("lang.toggle")}),oe&&n.jsx(bn,{onClick:ee,label:"Notification"in window&&Notification.permission==="denied"?I("notification.blocked"):I("notification.toggle"),variant:W?"active":"default",pressed:W,children:W?n.jsx(K5,{size:16}):n.jsx(W5,{size:16})}),n.jsx(bn,{onClick:xe,disabled:O,label:I("tunnel.start"),variant:(D==null?void 0:D.status)==="running"?"active":"default",pressed:(D==null?void 0:D.status)==="running",title:(D==null?void 0:D.status)==="running"&&D.url?`${D.url} — ${I("tunnel.urlCopied")}`:I(O?"tunnel.starting":"tunnel.start"),children:n.jsx($w,{size:16})}),n.jsx(bn,{onClick:()=>N(!0),label:I("settings.title"),children:n.jsx(vu,{size:16})}),s&&n.jsx(bn,{onClick:e,label:I("projects.logout"),variant:"danger",className:"ml-auto",children:n.jsx(yE,{size:16})})]})})]})}const B3=80,ab=120,xr=180,ob=.03,lb=8;function P3(){const e=k.useRef(null),s=k.useRef({x:-1e3,y:-1e3}),i=k.useRef([]),a=k.useRef(0);return k.useEffect(()=>{const h=e.current;if(!h)return;const f=h.getContext("2d");if(!f)return;let m=0,o=0;function c(){const b=h.parentElement;b&&(m=b.clientWidth,o=b.clientHeight,h.width=m*window.devicePixelRatio,h.height=o*window.devicePixelRatio,h.style.width=`${m}px`,h.style.height=`${o}px`,f.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),d())}function d(){i.current=[];for(let b=0;b<B3;b++){const C=Math.random()*m,S=Math.random()*o;i.current.push({x:C,y:S,baseX:C,baseY:S,vx:(Math.random()-.5)*.3,vy:(Math.random()-.5)*.3,size:Math.random()*1.5+.5,alpha:Math.random()*.4+.1})}}function p(b){const C=h.getBoundingClientRect();s.current.x=b.clientX-C.left,s.current.y=b.clientY-C.top}function u(){s.current.x=-1e3,s.current.y=-1e3}function x(){if(!f)return;f.clearRect(0,0,m,o);const b=i.current,C=s.current;for(const S of b){const g=S.x-C.x,_=S.y-C.y,w=Math.sqrt(g*g+_*_);if(w<xr&&w>0){const y=(xr-w)/xr,E=Math.atan2(_,g);S.vx+=Math.cos(E)*y*lb*.05,S.vy+=Math.sin(E)*y*lb*.05}S.vx+=(S.baseX-S.x)*ob,S.vy+=(S.baseY-S.y)*ob,S.baseX+=(Math.random()-.5)*.1,S.baseY+=(Math.random()-.5)*.1,S.baseX<0&&(S.baseX=0),S.baseX>m&&(S.baseX=m),S.baseY<0&&(S.baseY=0),S.baseY>o&&(S.baseY=o),S.vx*=.92,S.vy*=.92,S.x+=S.vx,S.y+=S.vy}for(let S=0;S<b.length;S++){for(let y=S+1;y<b.length;y++){const E=b[S].x-b[y].x,T=b[S].y-b[y].y,j=Math.sqrt(E*E+T*T);if(j<ab){const R=(1-j/ab)*.15;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${R})`,f.lineWidth=.5,f.moveTo(b[S].x,b[S].y),f.lineTo(b[y].x,b[y].y),f.stroke()}}const g=b[S].x-C.x,_=b[S].y-C.y,w=Math.sqrt(g*g+_*_);if(w<xr){const y=(1-w/xr)*.3;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${y})`,f.lineWidth=.8,f.moveTo(b[S].x,b[S].y),f.lineTo(C.x,C.y),f.stroke()}}for(const S of b){const g=S.x-C.x,_=S.y-C.y,w=Math.sqrt(g*g+_*_),y=w<xr?S.alpha+(1-w/xr)*.5:S.alpha;f.beginPath(),f.arc(S.x,S.y,S.size,0,Math.PI*2),f.fillStyle=`rgba(75, 141, 255, ${y})`,f.fill(),w<xr&&(f.beginPath(),f.arc(S.x,S.y,S.size*3,0,Math.PI*2),f.fillStyle=`rgba(75, 141, 255, ${(1-w/xr)*.08})`,f.fill())}a.current=requestAnimationFrame(x)}return c(),h.addEventListener("mousemove",p),h.addEventListener("mouseleave",u),window.addEventListener("resize",c),a.current=requestAnimationFrame(x),()=>{cancelAnimationFrame(a.current),h.removeEventListener("mousemove",p),h.removeEventListener("mouseleave",u),window.removeEventListener("resize",c)}},[]),n.jsx("canvas",{ref:e,className:"absolute inset-0 pointer-events-auto",style:{zIndex:0}})}function I3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:h}){const[f,m]=k.useState(!1),o=Ds(),{t:c}=dt(),[d,p]=k.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),u=()=>{p(x=>{const b=!x;return localStorage.setItem("sidebarCollapsed",b?"1":"0"),b})};return n.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[n.jsx("aside",{className:`
618
618
  fixed inset-y-0 left-0 z-40 flex-shrink-0
619
619
  transition-[transform,width] duration-200 ease-in-out
620
620
  md:translate-x-0 md:static md:z-auto
@@ -661,13 +661,13 @@ ${A.message}
661
661
  `)?"":`
662
662
  `;await V6(e,a+m+h+`
663
663
  `)}async function ZB(e,s,i){await et(`/api/projects/${e}/vault/ignore/unhide`,{path:s,isDir:i})}function Y6(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(2)}MB`}function X6(e){const s=new Map,i=new Map;for(const h of e){const f=h.stem.toLowerCase(),m=h.title.toLowerCase(),o=s.get(f)??[];o.push(h.relativePath),s.set(f,o);const c=i.get(m)??[];c.push(h.relativePath),i.set(m,c)}const a=new Map;for(const h of e){const f=h.relativePath.includes("/")?h.relativePath.slice(0,h.relativePath.lastIndexOf("/")+1):"",m=[];for(const o of h.wikilinks){const c=o.toLowerCase(),d=s.get(c)??i.get(c)??[];if(d.length===0)continue;const p=d.length===1?d[0]:d.find(u=>u.startsWith(f))??d[0];p&&p!==h.relativePath&&!m.includes(p)&&m.push(p)}a.set(h.relativePath,m)}return a}function jp({projectId:e,mode:s,selectedPaths:i,includeLinked:a,onChange:h}){const{t:f}=dt(),[m,o]=k.useState([]),[c,d]=k.useState(!1),[p,u]=k.useState(!1),[x,b]=k.useState(""),[C,S]=k.useState(!1),[g,_]=k.useState("");k.useEffect(()=>{let R=!1;return q6(e).then(N=>{R||(o(N.files),d(!0))}).catch(N=>{console.error("Load vault files failed",N),d(!0)}),()=>{R=!0}},[e]);const w=k.useMemo(()=>{const R=g.toLowerCase(),N=R?m.filter(A=>A.stem.toLowerCase().includes(R)||A.title.toLowerCase().includes(R)||A.relativePath.toLowerCase().includes(R)):m,D={};for(const A of N){const O=A.relativePath.includes("/")?A.relativePath.split("/").slice(0,-1).join("/"):".";D[O]||(D[O]=[]),D[O].push(A)}return D},[m,g]),y=k.useMemo(()=>X6(m),[m]),E=R=>{const N=new Set(i);if(N.has(R))N.delete(R);else if(N.add(R),a){const D=y.get(R)??[];for(const A of D)N.add(A)}h("selected",Array.from(N),a)},T=async()=>{S(!0);try{const N=await K6(e,s==="auto"?"all":s,i);b(N.block||f("vault.empty"))}catch(R){b(R instanceof Error?R.message:"Preview failed")}finally{S(!1)}},j=s!=="none"&&s!=="auto";return k.useEffect(()=>{p&&j&&T()},[p,s,i]),n.jsxs("div",{className:"rounded-lg border border-warm-200 bg-warm-50 p-3",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("div",{className:"text-sm font-medium text-warm-800",children:f("vaultInject.title")}),j&&n.jsxs("button",{type:"button",onClick:()=>u(R=>!R),className:"inline-flex items-center gap-1 text-xs text-warm-600 hover:text-warm-800",children:[p?n.jsx(Oj,{size:12}):n.jsx(rm,{size:12}),f("vaultInject.previewToggle")]})]}),n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:["none","auto","all","selected"].map(R=>n.jsx("button",{type:"button",onClick:()=>h(R,R==="selected"?i:[],a),className:`px-3 py-1.5 rounded-md text-xs ${s===R?"bg-warm-700 text-warm-50":"bg-warm-100 text-warm-700 hover:bg-warm-200"}`,children:f(`vaultInject.mode${R.charAt(0).toUpperCase()+R.slice(1)}`)},R))}),s==="auto"&&n.jsx("div",{className:"text-xs text-warm-500 mt-1 leading-snug",children:f("vaultInject.autoHint").replace("{count}",String(m.length))}),s==="selected"&&n.jsx("div",{className:"mt-2",children:c?m.length===0?n.jsx("div",{className:"text-xs text-warm-500 italic",children:f("vaultInject.empty")}):n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-600 mb-2 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:R=>h(s,i,R.target.checked)}),f("vaultInject.includeLinked")]}),n.jsx("input",{value:g,onChange:R=>_(R.target.value),placeholder:f("vaultInject.searchPlaceholder"),className:"w-full px-2 py-1.5 rounded-md border border-warm-200 bg-warm-0 text-sm focus:outline-none focus:ring-2 focus:ring-warm-400 mb-2"}),n.jsx("div",{className:"max-h-56 overflow-y-auto border border-warm-200 rounded-md",children:Object.keys(w).length===0?n.jsx("div",{className:"text-xs text-warm-500 italic px-2 py-2",children:f("vaultInject.noResults")}):Object.entries(w).sort(([R],[N])=>R.localeCompare(N)).map(([R,N])=>n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wide text-warm-500 px-2 py-1 bg-warm-100 sticky top-0 font-mono",children:R}),n.jsx("div",{className:"divide-y divide-warm-100",children:N.map(D=>{const A=(y.get(D.relativePath)??[]).length;return n.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-warm-100 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:i.includes(D.relativePath),onChange:()=>E(D.relativePath)}),D.kind==="html"?n.jsx(Jm,{size:12,className:"text-warm-500 shrink-0"}):n.jsx(Jo,{size:12,className:"text-warm-500 shrink-0"}),n.jsx("span",{className:"text-sm text-warm-800 truncate flex-1",title:D.relativePath,children:D.title||D.stem}),a&&A>0&&n.jsx("span",{className:"text-[10px] text-warm-600 bg-warm-200 px-1.5 py-0.5 rounded shrink-0",title:D.wikilinks.join(", "),children:f("vaultInject.linkedAdded").replace("{n}",String(A))}),n.jsx("span",{className:"text-[10px] text-warm-500 font-mono shrink-0",children:Y6(D.size)})]},D.relativePath)})})]},R))}),n.jsx("div",{className:"text-xs text-warm-500 mt-1.5",children:f("vaultInject.injectedCount").replace("{count}",String(i.length))})]}):n.jsx("div",{className:"text-xs text-warm-500",children:f("vaultInject.loading")})}),s==="all"&&m.length>0&&n.jsx("div",{className:"text-xs text-warm-500 mt-1",children:f("vaultInject.allCount").replace("{count}",String(m.length))}),p&&j&&n.jsxs("div",{className:"mt-3",children:[n.jsx("textarea",{readOnly:!0,value:C?"...":x,rows:8,className:"w-full px-2 py-1.5 rounded-md border border-warm-200 bg-warm-100 text-xs font-mono resize-y"}),!C&&x&&n.jsxs("div",{className:"mt-1 flex items-center justify-end gap-3 text-[10px] text-warm-500 font-mono",children:[n.jsx("span",{children:f("vaultInject.previewChars").replace("{n}",x.length.toLocaleString())}),n.jsx("span",{children:f("vaultInject.previewTokens").replace("{n}",Math.ceil(x.length/4).toLocaleString())})]})]})]})}function J6(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}let Q6=0;function O_({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCliTool:h,initialDependsOn:f,initialMaxTurns:m,initialUseWorktree:o=null,initialMemoryInjectMode:c="none",initialMemoryRawFilePaths:d=null,projectId:p,projectCliTool:u="claude",projectIsGitRepo:x=!1,projectUseWorktree:b=!0,existingImages:C=[],todoId:S,onDeleteImage:g,availableTodos:_=[]}){const[w,y]=k.useState(i),[E,T]=k.useState(a),[j,R]=k.useState(h||u||"claude"),[N,D]=k.useState(f??""),[A,O]=k.useState((m==null?void 0:m.toString())??""),[z,P]=k.useState(o===1?"force-on":o===0?"force-off":"inherit"),[F,H]=k.useState(c),[$,q]=k.useState(J6(d)),[Y,I]=k.useState(!1),[B,U]=k.useState([]),[J,W]=k.useState(C),oe=k.useRef(null),ee=k.useRef(null),{t:Z}=dt(),X=k.useCallback(be=>{const Ue=Array.from(be).filter(Pe=>Pe.type.startsWith("image/"));for(const Pe of Ue){const tt=new FileReader;tt.onload=()=>{const ke=tt.result,pe=`pending-${++Q6}`;U(Ne=>[...Ne,{id:pe,name:Pe.name,data:ke,preview:ke}])},tt.readAsDataURL(Pe)}},[]),G=k.useCallback(be=>{var ke;const Ue=(ke=be.clipboardData)==null?void 0:ke.items;if(!Ue)return;const Pe=[];for(let pe=0;pe<Ue.length;pe++)Ue[pe].type.startsWith("image/")&&Pe.push(Ue[pe]);if(Pe.length===0)return;be.preventDefault();const tt=[];for(const pe of Pe){const Ne=pe.getAsFile();Ne&&tt.push(Ne)}X(tt)},[X]),me=k.useCallback(be=>{var Ue;be.preventDefault(),be.stopPropagation(),(Ue=be.dataTransfer)!=null&&Ue.files&&X(be.dataTransfer.files)},[X]),ge=k.useCallback(be=>{be.preventDefault(),be.stopPropagation()},[]),xe=be=>{U(Ue=>Ue.filter(Pe=>Pe.id!==be))},he=be=>{g&&g(be),W(Ue=>Ue.filter(Pe=>Pe.id!==be))},Ie=be=>{if(be.preventDefault(),!w.trim())return;const Ue=A?parseInt(A,10):void 0,Pe=z==="force-on"?1:z==="force-off"?0:null;e(w.trim(),E.trim(),j,B.length>0?B:void 0,N||void 0,Ue||void 0,Pe,F,[],$)},Fe=J.length+B.length;return n.jsxs("form",{onSubmit:Ie,className:"card p-5 border-accent/30",children:[n.jsx("div",{className:"mb-3",children:n.jsx("input",{type:"text",placeholder:Z("todoForm.titlePlaceholder"),value:w,onChange:be=>y(be.target.value),className:"input-field",autoFocus:!0})}),n.jsxs("div",{className:"mb-4",children:[n.jsx("textarea",{ref:oe,placeholder:Z("todoForm.descPlaceholder"),value:E,onChange:be=>T(be.target.value),onPaste:G,onDrop:me,onDragOver:ge,rows:3,className:"input-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"}),n.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[n.jsxs("button",{type:"button",onClick:()=>{var be;return(be=ee.current)==null?void 0:be.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded text-2xs font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[n.jsx(Ha,{size:14}),Z("todoForm.addImage")]}),n.jsx("span",{className:"text-2xs text-warm-300",children:Z("todoForm.pasteHint")})]}),n.jsx("input",{ref:ee,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:be=>{be.target.files&&X(be.target.files),be.target.value=""}})]}),Fe>0&&n.jsxs("div",{className:"mb-4",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:Z("todoForm.images")}),n.jsxs("span",{className:"text-2xs text-warm-400",children:["(",Fe,")"]})]}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[J.map(be=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:S?gm(S,be.id):"",alt:be.originalName,className:"h-20 w-20 object-cover rounded-lg border border-warm-200"}),n.jsx("button",{type:"button",onClick:()=>he(be.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:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:be.originalName})})]},be.id)),B.map(be=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:be.preview,alt:be.name,className:"h-20 w-20 object-cover rounded-lg border border-accent/30"}),n.jsx("button",{type:"button",onClick:()=>xe(be.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:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:be.name})})]},be.id))]})]}),n.jsx("div",{className:"mb-4 grid grid-cols-2 gap-3",children:n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:Z("todoForm.cliTool")}),n.jsx("select",{value:j,onChange:be=>R(be.target.value),className:"input-field text-sm",children:wr.map(be=>n.jsx("option",{value:be.value,children:be.label},be.value))})]})}),j==="claude"&&n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:Z("todoForm.maxTurns")}),n.jsx("input",{type:"number",min:"1",max:"500",placeholder:Z("todoForm.maxTurnsPlaceholder"),value:A,onChange:be=>O(be.target.value),className:"input-field text-sm w-32"}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:Z("todoForm.maxTurnsHint")})]}),x&&n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:Z("todoForm.worktreeMode")}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[n.jsx("input",{type:"radio",name:"useWorktreeMode",checked:z==="inherit",onChange:()=>P("inherit")}),n.jsxs("span",{children:[Z("todoForm.worktreeInherit"),n.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["(",Z(b?"todoForm.worktreeProjectDefaultOn":"todoForm.worktreeProjectDefaultOff"),")"]})]})]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[n.jsx("input",{type:"radio",name:"useWorktreeMode",checked:z==="force-on",onChange:()=>P("force-on")}),n.jsx("span",{children:Z("todoForm.worktreeForceOn")})]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[n.jsx("input",{type:"radio",name:"useWorktreeMode",checked:z==="force-off",onChange:()=>P("force-off")}),n.jsx("span",{children:Z("todoForm.worktreeForceOff")})]})]}),(z==="force-off"||z==="inherit"&&!b)&&n.jsx("p",{className:"text-2xs text-status-warning mt-1.5",children:Z("todoForm.worktreeMainWarning")})]}),_.length>0&&n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:Z("todoForm.dependsOn")}),n.jsxs("select",{value:N,onChange:be=>D(be.target.value),className:"input-field text-sm",children:[n.jsx("option",{value:"",children:Z("todoForm.noDependency")}),_.map(be=>n.jsxs("option",{value:be.id,children:[be.title," (",Z(`status.${be.status}`),")"]},be.id))]}),N&&n.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:Z("todoForm.dependsOnHint")})]}),p&&n.jsx("div",{className:"mb-4",children:n.jsx(jp,{projectId:p,mode:F,selectedPaths:$,includeLinked:Y,onChange:(be,Ue,Pe)=>{H(be),q(Ue),I(Pe)}})}),n.jsxs("div",{className:"flex gap-3 justify-end",children:[n.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:Z("todoForm.cancel")}),n.jsx("button",{type:"submit",disabled:!w.trim(),className:"btn-primary text-sm",children:Z("todoForm.save")})]})]})}const an="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 disabled:cursor-not-allowed",Ep="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 disabled:opacity-30 disabled:cursor-not-allowed";function z_(){return n.jsx("div",{className:"my-1 border-t border-warm-200"})}function hi(e){var i;const s=e.target;return!!((i=s==null?void 0:s.closest)!=null&&i.call(s,'input, textarea, select, [contenteditable="true"], .xterm'))}function Cr({x:e,y:s,onClose:i,children:a}){const h=k.useRef(null),[f,m]=k.useState({top:s,left:e,visible:!1});return k.useLayoutEffect(()=>{const o=h.current;if(!o)return;const c=window.innerWidth,d=window.innerHeight;let p=e,u=s;p+o.offsetWidth>c-8&&(p=Math.max(8,c-8-o.offsetWidth)),u+o.offsetHeight>d-8&&(u=Math.max(8,d-8-o.offsetHeight)),p<8&&(p=8),u<8&&(u=8),m({top:u,left:p,visible:!0})},[e,s]),k.useEffect(()=>{const o=p=>{var u;(u=h.current)!=null&&u.contains(p.target)||i()},c=p=>{p.key==="Escape"&&i()},d=()=>i();return document.addEventListener("mousedown",o),document.addEventListener("keydown",c),window.addEventListener("scroll",d,!0),window.addEventListener("resize",i),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",c),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",i)}},[i]),en.createPortal(n.jsx("div",{ref:h,className:"fixed z-tooltip min-w-[180px] rounded-xl py-1 shadow-elevated",style:{top:f.top,left:f.left,opacity:f.visible?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:i,onContextMenu:o=>o.preventDefault(),children:a}),document.body)}function Z6({children:e}){const[s,i]=k.useState(!1),[a,h]=k.useState(!1),f=k.useRef(null),m=k.useRef(null),[o,c]=k.useState({top:0,left:0}),d=k.useCallback(()=>{if(!f.current)return;const u=f.current.getBoundingClientRect(),x=window.innerWidth,b=window.innerHeight;let C=u.bottom+4;const S=m.current;if(S){const g=S.offsetWidth,_=S.offsetHeight;let w=u.right-g;w<8&&(w=8),w+g>x-8&&(w=x-8-g),C+_>b-8&&(C=u.top-_-4),c({top:C,left:w}),h(!0)}else c({top:C,left:Math.max(8,u.right-180)})},[]);k.useEffect(()=>{if(!s){h(!1);return}d();const u=requestAnimationFrame(d),x=b=>{var S,g;const C=b.target;(S=f.current)!=null&&S.contains(C)||(g=m.current)!=null&&g.contains(C)||i(!1)};return document.addEventListener("mousedown",x),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{cancelAnimationFrame(u),document.removeEventListener("mousedown",x),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[s,d]);const p=(Array.isArray(e)?e:[e]).filter(Boolean);return p.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx("button",{ref:f,onClick:()=>i(!s),className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-theme-hover rounded-lg transition-colors",title:"More",children:n.jsx(Xm,{size:14})}),s&&en.createPortal(n.jsx("div",{ref:m,className:`fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated${a?" animate-scale-in":""}`,style:{top:o.top,left:o.left,opacity:a?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>i(!1),children:p}),document.body)]})}function e8({todo:e,allTodos:s=[],projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onStart:f,onStop:m,onDelete:o,onEdit:c,onMerge:d,onCleanup:p,onRetry:u,onContinue:x,onFix:b,onSchedule:C,onScheduleOnReset:S,resetsAt:g,onEvent:_,isInteractive:w,onSendInput:y,isDragSource:E,isDragging:T,isDragOver:j,isValidDropTarget:R,onDragStart:N,onDragEnd:D,onDragOverTarget:A,onDragLeaveTarget:O,onDropTarget:z,onRemoveDependency:P,debugLogging:F,showTokenUsage:H,isChainMember:$}){const[q,Y]=k.useState(!1),[I,B]=k.useState(!1),[U,J]=k.useState([]),[W,oe]=k.useState(!1),[ee,Z]=k.useState(!1),[X,G]=k.useState(null),[me,ge]=k.useState(!1),[xe,he]=k.useState(null),[Ie,Fe]=k.useState(!1),[be,Ue]=k.useState(null),[Pe,tt]=k.useState(!1),[ke,pe]=k.useState(null),[Ne,Le]=k.useState(!1),[ze,Ke]=k.useState(null),[Ve,de]=k.useState(!1),[fe,ce]=k.useState(""),[Q,V]=k.useState(!1),[re,te]=k.useState(null),[se,le]=k.useState(!1),[ve,Ce]=k.useState(""),[De,Qe]=k.useState(!1),[ut,ot]=k.useState(null),[Je,qe]=k.useState(null),[ft,lt]=k.useState(!1),[xt,pt]=k.useState(!1),[st,ht]=k.useState(!1),[Re,ct]=k.useState(()=>{const ue=new Date;ue.setHours(ue.getHours()+1),ue.setMinutes(0,0,0);const nt=ue.getFullYear(),mt=String(ue.getMonth()+1).padStart(2,"0"),Mt=String(ue.getDate()).padStart(2,"0"),Qt=String(ue.getHours()).padStart(2,"0"),bi=String(ue.getMinutes()).padStart(2,"0");return`${nt}-${mt}-${Mt}T${Qt}:${bi}`}),[Oe,ie]=k.useState(!1),[_e,je]=k.useState(null),{t:we}=dt(),rt=e.status==="pending"||e.status==="failed"||e.status==="stopped",Me=(e.status==="pending"||e.status==="failed"||e.status==="stopped")&&!!C,vt=(e.status==="pending"||e.status==="completed"||e.status==="failed"||e.status==="stopped")&&!!S&&!!g&&g>Math.floor(Date.now()/1e3),bt=e.status==="running",St=e.status==="completed"||e.status==="stopped"||e.status==="merged",Et=e.status==="completed"&&!$&&!!e.branch_name,Ht=e.status==="completed"||e.status==="failed"||e.status==="stopped",pn=!!x&&e.status==="completed"&&!!e.worktree_path,gn=e.status!=="running"&&e.status!=="pending"&&!!e.worktree_path&&!$,yn=e.status==="completed"||e.status==="failed"||e.status==="stopped"||e.status==="merged";k.useEffect(()=>{w&&e.status==="running"&&!q&&Y(!0)},[w,e.status]),k.useEffect(()=>{q&&!W&&m1(e.id).then(ue=>{J(ue),oe(!0)}).catch(()=>{})},[q,W,e.id]),k.useEffect(()=>{q&&yn&&!ft&&K3(e.id).then(ue=>{qe(ue),lt(!0)}).catch(()=>{lt(!0)})},[q,yn,ft,e.id]),k.useEffect(()=>_(ue=>{if(ue.type==="todo:log"&&ue.todoId===e.id&&ue.message){const nt={id:`ws-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:ue.logType||"output",message:ue.message,created_at:new Date().toISOString()};J(mt=>[...mt,nt])}if(ue.type==="todo:commit"&&ue.todoId===e.id&&ue.message){const nt={id:`ws-commit-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:"commit",message:`${ue.commitHash?`[${ue.commitHash}] `:""}${ue.message}`,created_at:new Date().toISOString()};J(mt=>[...mt,nt])}}),[_,e.id]);const ms=async()=>{try{const{files:ue}=await jN(e.project_id,e.id);ue.length>0&&window.open(`/api/projects/${e.project_id}/debug-logs/${encodeURIComponent(ue[0].name)}`,"_blank")}catch{}},ps=async()=>{if(ee){Z(!1);return}ge(!0),he(null);try{const ue=await q3(e.id);G(ue),Z(!0),Y(!0)}catch(ue){he(ue instanceof Error?ue.message:"Failed to load diff"),Y(!0)}finally{ge(!1)}},qn=async()=>{Fe(!0),Ue(null);try{await d(e.id)}catch(ue){Ue(ue instanceof Error?ue.message:"Merge failed")}finally{Fe(!1)}},gs=async()=>{const ue=e.branch_name?confirm(we("cleanup.confirmDeleteBranch").replace("{name}",e.branch_name)):!1;tt(!0),pe(null);try{await p(e.id,ue)}catch(nt){pe(nt instanceof Error?nt.message:"Cleanup failed")}finally{tt(!1)}},Ts=async(ue="headless")=>{Le(!0),Ke(null),J([]),oe(!1),G(null),Z(!1),qe(null),lt(!1);try{await u(e.id,ue)}catch(nt){Ke(nt instanceof Error?nt.message:"Retry failed")}finally{Le(!1)}},ss=async(ue="headless")=>{if(!x)return;const nt=fe.trim();if(!nt){te(we("todo.continuePromptRequired"));return}V(!0),te(null);try{await x(e.id,nt,ue),de(!1),ce(""),J([]),oe(!1)}catch(mt){te(mt instanceof Error?mt.message:"Continue failed")}finally{V(!1)}},nn=async()=>{if(!(!S||!ve.trim())){Qe(!0),ot(null);try{await S(e.id,ve.trim()),le(!1),Ce("")}catch(ue){ot(ue instanceof Error?ue.message:"Failed")}finally{Qe(!1)}}},Xi=async()=>{if(!(!C||!Re)){ie(!0);try{await C(e.id,new Date(Re).toISOString(),st),pt(!1)}catch{}finally{ie(!1)}}},Ji=ue=>{if(ue<60)return`${ue}s`;const nt=Math.floor(ue/60),mt=ue%60;if(nt<60)return mt>0?`${nt}m ${mt}s`:`${nt}m`;const Mt=Math.floor(nt/60),Qt=nt%60;return Qt>0?`${Mt}h ${Qt}m`:`${Mt}h`},xs=ue=>ue>=1e6?`${(ue/1e6).toFixed(1)}M`:ue>=1e3?`${(ue/1e3).toFixed(1)}k`:String(ue),Kn=e.images?JSON.parse(e.images):[],vs=e.depends_on?s.find(ue=>ue.id===e.depends_on):null,Rs=s.find(ue=>ue.depends_on===e.id&&ue.merged_from_branch),gi=e.cli_tool||i||"claude",xi=bm(gi).supportsInteractive;if(I)return n.jsx(O_,{initialTitle:e.title,initialDescription:e.description??void 0,initialCliTool:e.cli_tool??void 0,initialDependsOn:e.depends_on??void 0,initialMaxTurns:e.max_turns??void 0,initialUseWorktree:e.use_worktree??null,initialMemoryInjectMode:e.memory_inject_mode??"none",initialMemoryRawFilePaths:e.memory_raw_file_paths??null,projectId:e.project_id,projectIsGitRepo:a,projectUseWorktree:h,existingImages:Kn,todoId:e.id,availableTodos:s.filter(ue=>ue.id!==e.id),onDeleteImage:async ue=>{await Y3(e.id,ue)},onSave:async(ue,nt,mt,Mt,Qt,bi,Er,jl,El,Nr)=>{await c(e.id,ue,nt,mt,Qt,bi,Er,jl,El,Nr),Mt&&Mt.length>0&&await v1(e.id,Mt.map(Nl=>({name:Nl.name,data:Nl.data}))),B(!1)},onCancel:()=>B(!1)});const Zs={pending:"border-l-warm-300",running:"border-l-status-running",completed:"border-l-status-success",failed:"border-l-status-error",stopped:"border-l-status-warning",merged:"border-l-theme-border-strong"}[e.status],Ms=ue=>{ue.dataTransfer.setData("text/plain",e.id),ue.dataTransfer.effectAllowed="link",N==null||N(e.id)},Mn=()=>{D==null||D()},Fn=ue=>{!T||E||(ue.preventDefault(),ue.dataTransfer.dropEffect=R?"link":"none",A==null||A(e.id))},vi=()=>{O==null||O(e.id)},ae=ue=>{ue.preventDefault(),!(!T||E||!R)&&(z==null||z(e.id))},$e=T&&!E&&j&&R,it=T&&!E&&j&&!R;return n.jsxs("div",{className:`relative transition-opacity duration-200 ${E?"opacity-40":""}`,onDragOver:Fn,onDragLeave:vi,onDrop:ae,onContextMenu:ue=>{hi(ue)||(ue.preventDefault(),ue.stopPropagation(),je({x:ue.clientX,y:ue.clientY}))},children:[n.jsxs("div",{className:`card border-l-4 ${Zs} overflow-hidden transition-all duration-200 ${$e?"ring-2 ring-accent/50 ring-offset-1":""} ${it?"ring-2 ring-status-error/50 ring-offset-1":""}`,children:[n.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:()=>Y(!q),children:[n.jsx("div",{draggable:!0,onDragStart:Ms,onDragEnd:Mn,onClick:ue=>ue.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:we("dnd.dropHint"),children:n.jsx(Kw,{size:16})}),n.jsx("button",{className:"text-warm-400 hover:text-accent flex-shrink-0 transition-colors",children:n.jsx(Ns,{size:14,className:`transition-transform duration-200 ${q?"rotate-90":""}`})}),n.jsxs("span",{className:"text-2xs font-mono text-warm-400 w-6 flex-shrink-0",children:["#",e.priority]}),n.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:e.title}),Kn.length>0&&n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-2xs font-mono text-warm-400 bg-warm-100 flex-shrink-0",children:[n.jsx(Ha,{size:12}),Kn.length]}),vs&&n.jsxs("span",{className:"hidden md:inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-2xs font-mono font-medium bg-theme-bg-tertiary text-theme-text-secondary flex-shrink-0 group/dep",title:`${we("todo.dependsOn")}: ${vs.title}`,children:[n.jsx(ul,{size:12}),vs.title.length>20?vs.title.slice(0,20)+"...":vs.title,P&&n.jsx("button",{onClick:ue=>{ue.stopPropagation(),P(e.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:we("dnd.removeDep"),children:n.jsx(Jt,{size:10})})]}),e.cli_tool&&n.jsx("span",{className:"hidden md:inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-2xs font-mono font-medium bg-theme-bg-tertiary text-theme-muted flex-shrink-0",children:bm(e.cli_tool||"claude").label}),n.jsx(vL,{status:e.status}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-auto md:ml-2 flex-shrink-0",onClick:ue=>ue.stopPropagation(),children:[rt&&n.jsx("button",{onClick:()=>f(e.id,"headless"),className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors",title:we("todo.startHeadless"),children:n.jsx(kr,{size:14})}),bt&&n.jsx("button",{onClick:()=>m(e.id),className:"p-1.5 text-status-error/60 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:we("todo.stop"),children:n.jsx(Ki,{size:14})}),Et&&n.jsx("button",{onClick:qn,disabled:Ie,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:we("todo.merge"),children:n.jsx(cl,{size:14})}),pn&&n.jsx("button",{onClick:()=>{de(ue=>!ue),te(null)},disabled:Q,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:we("todo.continue"),children:n.jsx(Fv,{size:14})}),Ht&&n.jsx("button",{onClick:()=>Ts("headless"),disabled:Ne,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:we("todo.retry"),children:n.jsx(ui,{size:14})}),n.jsxs(Z6,{children:[rt&&xi&&n.jsxs("button",{onClick:()=>f(e.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:we("todo.startInteractiveDesc"),children:[n.jsx(di,{size:14}),we("todo.startInteractive")]}),rt&&n.jsxs("button",{onClick:()=>f(e.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:we("todo.startVerboseDesc"),children:[n.jsx(rm,{size:14}),we("todo.startVerbose")]}),Me&&n.jsxs("button",{onClick:()=>pt(!xt),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:we("todo.scheduleDesc"),children:[n.jsx(nm,{size:14}),we("todo.schedule")]}),vt&&n.jsxs("button",{onClick:()=>{le(ue=>!ue),ot(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:we("todo.scheduleOnResetDesc"),children:[n.jsx(ai,{size:14}),we("todo.scheduleOnReset")]}),St&&n.jsxs("button",{onClick:ps,disabled:me,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:[n.jsx(Jo,{size:14}),we("todo.viewDiff")]}),F&&yn&&n.jsxs("button",{onClick:ms,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:[n.jsx(qv,{size:14}),we("todo.viewDebugLog")]}),gn&&n.jsxs("button",{onClick:gs,disabled:Pe,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:[n.jsx(pu,{size:14}),we("todo.cleanup")]}),n.jsxs("button",{onClick:()=>B(!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:[n.jsx(ci,{size:14}),we("todo.edit")]}),n.jsxs("button",{onClick:()=>o(e.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:[n.jsx(Ln,{size:14}),we("todo.delete")]})]})]})]}),xt&&n.jsx("div",{className:"border-t border-accent/20 px-5 py-3 bg-accent/5 animate-fade-in",children:n.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[n.jsx("label",{className:"text-xs font-medium text-accent",children:we("todo.scheduleAt")}),n.jsx("input",{type:"datetime-local",value:Re,onChange:ue=>ct(ue.target.value),className:"bg-theme-card border border-accent/20 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)}),n.jsx("button",{onClick:Xi,disabled:Oe||!Re,className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:we(Oe?"todo.scheduling":"todo.confirmSchedule")}),n.jsx("button",{onClick:()=>pt(!1),className:"btn-ghost text-xs py-1.5",children:we("scheduleForm.cancel")}),n.jsxs("label",{className:"flex items-center gap-2 text-xs text-accent",children:[n.jsx("input",{type:"checkbox",checked:st,onChange:ue=>ht(ue.target.checked),className:"rounded border-accent/40 text-accent focus:ring-accent"}),we("todo.scheduleKeepOriginal")]})]})}),Ve&&n.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50 animate-fade-in",children:n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("label",{className:"text-xs font-medium text-theme-text-secondary",children:[we("todo.continuePromptLabel"),(e.round_count??1)>1&&n.jsxs("span",{className:"ml-2 text-theme-muted",children:["(",we("todo.roundLabel")," ",e.round_count,")"]})]}),n.jsx("textarea",{value:fe,onChange:ue=>ce(ue.target.value),placeholder:we("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:Q}),re&&n.jsx("p",{className:"text-xs text-status-error",children:re}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>ss("headless"),disabled:Q||!fe.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:we(Q?"todo.continuing":"todo.confirmContinue")}),n.jsx("button",{onClick:()=>{de(!1),te(null)},disabled:Q,className:"btn-ghost text-xs py-1.5",children:we("scheduleForm.cancel")})]})]})}),se&&g&&n.jsx("div",{className:"border-t border-amber-200 px-5 py-3 bg-amber-50/50 animate-fade-in",children:n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("label",{className:"text-xs font-medium text-amber-600",children:we("todo.scheduleOnResetLabel")}),n.jsx("span",{className:"text-xs text-amber-500/80 font-mono",children:new Date(g*1e3).toLocaleString()})]}),n.jsx("textarea",{value:ve,onChange:ue=>Ce(ue.target.value),placeholder:we("todo.resetPromptPlaceholder"),rows:3,className:"w-full bg-theme-card border border-amber-200 rounded-lg px-3 py-2 text-sm text-warm-800 focus:border-amber-400 focus:outline-none focus:ring-2 focus:ring-amber-400/20 resize-y",disabled:De}),ut&&n.jsx("p",{className:"text-xs text-status-error",children:ut}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:nn,disabled:De||!ve.trim(),className:"btn-primary text-xs py-1.5 !bg-amber-500 hover:!bg-amber-600 disabled:opacity-30",children:we(De?"todo.scheduling":"todo.confirmResetSchedule")}),n.jsx("button",{onClick:()=>{le(!1),ot(null)},disabled:De,className:"btn-ghost text-xs py-1.5",children:we("scheduleForm.cancel")})]})]})}),q&&n.jsx("div",{className:"animate-fade-in overflow-hidden border-t border-theme-border",children:n.jsxs("div",{className:"px-4 py-3 space-y-3",children:[n.jsxs("section",{children:[n.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:we("todo.description")}),n.jsx("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2",children:e.description?n.jsx("p",{className:"text-sm text-warm-700 whitespace-pre-wrap",children:e.description}):n.jsx("p",{className:"text-sm text-warm-400 italic",children:we("todo.noDescription")})})]}),Kn.length>0&&n.jsxs("section",{children:[n.jsxs("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:[we("todo.attachedImages")," ",n.jsxs("span",{className:"text-warm-400 normal-case",children:["(",Kn.length,")"]})]}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:Kn.map(ue=>n.jsx("a",{href:gm(e.id,ue.id),target:"_blank",rel:"noopener noreferrer",children:n.jsx("img",{src:gm(e.id,ue.id),alt:ue.originalName,className:"h-16 w-16 object-cover rounded-md border border-theme-border"})},ue.id))})]}),(vs||e.branch_name||Rs)&&n.jsxs("section",{children:[n.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:we("todo.branch")}),n.jsxs("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2 space-y-1.5",children:[vs&&n.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[n.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0 pt-0.5",children:we("todo.dependsOn")}),n.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-accent/10 text-accent text-2xs font-medium",children:vs.title})]}),e.branch_name&&n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:we("todo.branch")}),n.jsx(Ga,{size:12,className:"text-status-success flex-shrink-0"}),n.jsx("code",{className:"font-mono text-xs text-warm-700 break-all",children:e.branch_name})]}),e.worktree_path&&n.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[n.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0 pt-0.5",children:we("todo.worktree")}),n.jsx("code",{className:"font-mono text-2xs text-warm-500 break-all",children:e.worktree_path})]}),e.merged_from_branch&&n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:we("todo.mergedFrom")}),n.jsx("code",{className:"font-mono text-xs text-theme-text-secondary break-all",children:e.merged_from_branch})]}),!e.worktree_path&&Rs&&n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:we("todo.transferredTo")}),n.jsx("span",{className:"text-warm-700 truncate",children:Rs.title.length>30?Rs.title.slice(0,27)+"...":Rs.title})]})]})]}),e.status==="failed"&&U.length>0&&(()=>{var Mt;const ue=U.filter(Qt=>Qt.log_type==="error");if(ue.length===0)return null;const nt=ue.find(Qt=>/exited with code (\d+)/.test(Qt.message)),mt=nt?(Mt=nt.message.match(/exited with code (\d+)/))==null?void 0:Mt[1]:null;return n.jsxs("div",{style:{background:He.bg,fontFamily:Rt,fontSize:12,lineHeight:"1.5",padding:"10px 12px",borderRadius:8,border:`1px solid ${He.separator}`,color:He.text},children:[n.jsxs("div",{children:[n.jsx("span",{style:{color:He.error},children:">"})," ",n.jsx("span",{style:{color:He.error,fontWeight:700},children:"FAILED"}),mt&&n.jsxs("span",{style:{color:He.dim},children:[" (exit code: ",mt,")"]}),b&&n.jsx("button",{onClick:()=>b(e,ue),style:{marginLeft:12,color:He.warning,background:"none",border:`1px solid ${He.warning}`,padding:"1px 8px",borderRadius:2,cursor:"pointer",fontSize:11,fontFamily:Rt},children:we("failure.fix")})]}),n.jsx("div",{style:{maxHeight:192,overflowY:"auto",marginTop:4},children:ue.map(Qt=>n.jsxs("div",{children:[n.jsx("span",{style:{color:He.dim},children:new Date(Qt.created_at).toLocaleTimeString()})," ",n.jsx("span",{style:{color:He.error},children:Qt.message})]},Qt.id))})]})})(),yn&&Je&&n.jsxs("section",{children:[n.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:we("todo.result")}),n.jsxs("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2 space-y-2.5",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs",children:[Je.duration_seconds!==null&&n.jsxs("span",{className:"inline-flex items-center gap-1",children:[n.jsx(ai,{size:12,className:"text-warm-400"}),n.jsx("span",{className:"text-warm-400",children:we("result.duration")}),n.jsx("span",{className:"text-warm-700 font-medium",children:Ji(Je.duration_seconds)})]}),Je.commits.length>0&&n.jsxs("span",{className:"inline-flex items-center gap-1",children:[n.jsx(Vj,{size:12,className:"text-status-success"}),n.jsx("span",{className:"text-status-success font-medium",children:Je.commits.length}),n.jsx("span",{className:"text-warm-400",children:we("result.commits")})]}),Je.diff_stats.files_changed>0&&n.jsxs("span",{className:"inline-flex items-center gap-1",children:[n.jsx(Jo,{size:12,className:"text-warm-400"}),n.jsx("span",{className:"text-warm-700 font-medium",children:Je.diff_stats.files_changed}),n.jsx("span",{className:"text-warm-400",children:we("result.filesChanged")}),n.jsxs("span",{className:"text-status-success font-mono",children:["+",Je.diff_stats.insertions]}),n.jsxs("span",{className:"text-status-error font-mono",children:["-",Je.diff_stats.deletions]})]}),H&&Je.token_usage&&(()=>{const ue=Je.token_usage,nt=(ue.input_tokens??0)+(ue.cache_read_input_tokens??0)+(ue.cache_creation_input_tokens??0),mt=nt+(ue.output_tokens??0);let Mt,Qt;return mt>=5e5?(Mt=we("result.levelHeavy"),Qt="text-status-error"):mt>=3e5?(Mt=we("result.levelHigh"),Qt="text-orange-500"):mt>=1e5?(Mt=we("result.levelModerate"),Qt="text-status-warning"):(Mt=we("result.levelLight"),Qt="text-status-info"),n.jsxs("span",{className:"inline-flex items-center gap-1",children:[nt>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-warm-400",children:we("result.inputTokens")}),n.jsx("span",{className:"text-warm-700 font-medium",children:xs(nt)})]}),nt>0&&ue.output_tokens!==null&&n.jsx("span",{className:"text-warm-400",children:"·"}),ue.output_tokens!==null&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-warm-400",children:we("result.outputTokens")}),n.jsx("span",{className:"text-warm-700 font-medium",children:xs(ue.output_tokens)})]}),ue.num_turns!=null&&ue.num_turns>1&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-warm-400",children:"·"}),n.jsxs("span",{className:"text-warm-700",children:[ue.num_turns,we("result.turns")]})]}),n.jsx("span",{className:"text-warm-400",children:"·"}),n.jsx("span",{className:`font-medium ${Qt}`,children:Mt})]})})()]}),Je.commits.length>0&&n.jsxs("div",{children:[n.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider mb-1",children:we("result.commitHistory")}),n.jsx("div",{className:"space-y-0.5",children:Je.commits.map((ue,nt)=>n.jsxs("div",{className:"flex items-center gap-2 px-1.5 py-1 text-xs rounded hover:bg-theme-hover",children:[n.jsx("code",{className:"font-mono text-accent flex-shrink-0",children:ue.hash.slice(0,7)||"-------"}),n.jsx("span",{className:"text-warm-700 truncate flex-1",children:ue.message}),n.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:new Date(ue.date).toLocaleTimeString()})]},nt))})]}),Je.changed_files.length>0&&n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-1",children:[n.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider",children:we("result.changedFiles")}),St&&n.jsxs("button",{onClick:ps,disabled:me,className:"flex items-center gap-1 text-2xs text-warm-500 hover:text-accent transition-colors disabled:opacity-30",children:[n.jsx(Ns,{size:10,className:`transition-transform ${ee?"rotate-90":""}`}),n.jsx("span",{children:we(ee?"todo.hideDiff":"todo.viewDiff")})]})]}),n.jsx("div",{className:"space-y-0.5",children:Je.changed_files.map((ue,nt)=>{const mt=ue.status==="A"?"bg-status-success/15 text-status-success":ue.status==="D"?"bg-status-error/15 text-status-error":ue.status==="M"?"bg-status-warning/15 text-status-warning":"bg-warm-200 text-warm-600";return n.jsxs("div",{className:"flex items-center gap-2 px-1.5 py-0.5 text-xs",children:[n.jsx("span",{className:`inline-flex items-center justify-center w-5 h-4 rounded text-[10px] font-bold ${mt}`,children:ue.status}),n.jsx("span",{className:"text-warm-700 font-mono text-2xs break-all flex-1",children:ue.file}),ue.renamedFrom&&n.jsxs("span",{className:"text-warm-400 text-2xs flex-shrink-0",children:["← ",ue.renamedFrom]})]},nt)})})]})]})]}),be&&n.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[we("todo.mergeFailed"),": ",be]}),ke&&n.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[we("todo.cleanupFailed"),": ",ke]}),ze&&n.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[we("todo.retryFailed"),": ",ze]}),xe&&n.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[we("todo.diffError"),": ",xe]}),ee&&X&&n.jsxs("section",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[n.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider",children:we("todo.diffOutput")}),n.jsxs("div",{className:"flex items-center gap-1.5 text-2xs",children:[n.jsxs("span",{className:"text-warm-500",children:[X.stats.files_changed," ",we("todo.files")]}),n.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-status-success/10 text-status-success font-mono",children:["+",X.stats.insertions]}),n.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-status-error/10 text-status-error font-mono",children:["-",X.stats.deletions]})]})]}),n.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:X.diff?X.diff.split(`
664
- `).map((ue,nt)=>{let mt="text-theme-text",Mt="";return ue.startsWith("+")&&!ue.startsWith("+++")?mt="text-theme-text bg-status-success/15":ue.startsWith("-")&&!ue.startsWith("---")?mt="text-theme-text bg-status-error/15":ue.startsWith("@@")?mt="text-accent":ue.startsWith("diff ")&&(mt="text-warm-700",Mt="font-semibold"),n.jsx("div",{className:`whitespace-pre ${mt} ${Mt}`,children:ue},nt)}):n.jsx("span",{className:"text-warm-400 italic",children:we("log.noChanges")})})]}),n.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:He.bg,fontFamily:Rt,border:`1px solid ${He.separator}`},children:[n.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${He.separator}`,fontSize:12,color:He.text},children:[n.jsx("span",{style:{color:He.prompt},children:"$"})," ",n.jsx("span",{style:{color:He.bright},children:"tail"})," ",n.jsx("span",{style:{color:He.dim},children:"-f task.log"})]}),n.jsx(A_,{logs:U,interactive:w&&e.status==="running",todoId:e.id,onSendInput:y,embedded:!0})]})]})})]}),$e&&n.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 animate-fade-in",children:[n.jsx(ul,{size:14,className:"text-accent flex-shrink-0"}),n.jsx("span",{className:"text-xs font-medium text-accent",children:we("dnd.dropHint")})]}),it&&n.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-red-300 bg-red-50/50 animate-fade-in",children:[n.jsx($5,{size:14,className:"text-red-400 flex-shrink-0"}),n.jsx("span",{className:"text-xs font-medium text-red-400",children:we("dnd.cyclicWarning")})]}),_e&&n.jsxs(Cr,{x:_e.x,y:_e.y,onClose:()=>je(null),children:[rt&&n.jsxs("button",{onClick:()=>f(e.id,"headless"),className:an,title:we("todo.startHeadless"),children:[n.jsx(kr,{size:14}),we("todo.start")]}),rt&&xi&&n.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:an,title:we("todo.startInteractiveDesc"),children:[n.jsx(di,{size:14}),we("todo.startInteractive")]}),rt&&n.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:an,title:we("todo.startVerboseDesc"),children:[n.jsx(rm,{size:14}),we("todo.startVerbose")]}),bt&&n.jsxs("button",{onClick:()=>m(e.id),className:an,children:[n.jsx(Ki,{size:14}),we("todo.stop")]}),Et&&n.jsxs("button",{onClick:qn,disabled:Ie,className:an,children:[n.jsx(cl,{size:14}),we("todo.merge")]}),pn&&n.jsxs("button",{onClick:()=>{de(!0),te(null)},disabled:Q,className:an,children:[n.jsx(Fv,{size:14}),we("todo.continue")]}),Ht&&n.jsxs("button",{onClick:()=>Ts("headless"),disabled:Ne,className:an,children:[n.jsx(ui,{size:14}),we("todo.retry")]}),Me&&n.jsxs("button",{onClick:()=>pt(!0),className:an,title:we("todo.scheduleDesc"),children:[n.jsx(nm,{size:14}),we("todo.schedule")]}),vt&&n.jsxs("button",{onClick:()=>{le(!0),ot(null)},className:an,title:we("todo.scheduleOnResetDesc"),children:[n.jsx(ai,{size:14}),we("todo.scheduleOnReset")]}),St&&n.jsxs("button",{onClick:ps,disabled:me,className:an,children:[n.jsx(Jo,{size:14}),we("todo.viewDiff")]}),F&&yn&&n.jsxs("button",{onClick:ms,className:an,children:[n.jsx(qv,{size:14}),we("todo.viewDebugLog")]}),gn&&n.jsxs("button",{onClick:gs,disabled:Pe,className:an,children:[n.jsx(pu,{size:14}),we("todo.cleanup")]}),n.jsx(z_,{}),n.jsxs("button",{onClick:()=>B(!0),className:an,children:[n.jsx(ci,{size:14}),we("todo.edit")]}),n.jsxs("button",{onClick:()=>o(e.id),className:Ep,children:[n.jsx(Ln,{size:14}),we("todo.delete")]})]})]})}const t8=k.lazy(()=>Fu(()=>import("./TaskGraph-QgGQqBdQ.js"),__vite__mapDeps([0,1,2,3,4]))),Gc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function dy(e,s,i){let a=i;const h=new Set;for(;a;){if(a===s)return!0;if(h.has(a))return!1;h.add(a);const f=e.find(m=>m.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function n8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onAddTodo:f,onStartAll:m,onStopAll:o,onStartTodo:c,onStopTodo:d,onDeleteTodo:p,onEditTodo:u,onMergeTodo:x,onMergeChain:b,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:g,onFixTodo:_,onScheduleTodo:w,onScheduleOnResetTodo:y,resetsAt:E,onUpdateDependency:T,onUpdatePosition:j,onReorderTodos:R,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:O,showTokenUsage:z}){var Je;const[P,F]=k.useState(!1),[H,$]=k.useState(null),[q,Y]=k.useState(null),[I,B]=k.useState(null),[U,J]=k.useState(null),[W,oe]=k.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[ee,Z]=k.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[X,G]=k.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[me,ge]=k.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:xe}=dt(),he=k.useCallback(qe=>{oe(qe);try{localStorage.setItem("todoViewMode",qe)}catch{}},[]),Ie=k.useCallback(qe=>{Z(qe);try{localStorage.setItem("todoStatusFilter",qe)}catch{}},[]),Fe=k.useCallback(()=>{G(qe=>{const ft=!qe;try{localStorage.setItem("todoStackModeEnabled",String(ft))}catch{}if(!ft){ge(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return ft})},[]),be=k.useCallback(()=>{ge(qe=>{const ft=!qe;try{localStorage.setItem("todoStackCollapsed",String(ft))}catch{}return ft})},[]),Ue=X&&me&&W==="list",Pe=k.useMemo(()=>({all:e.length,active:e.filter(qe=>Gc.active.includes(qe.status)).length,completed:e.filter(qe=>Gc.completed.includes(qe.status)).length,cancelled:e.filter(qe=>Gc.cancelled.includes(qe.status)).length}),[e]),tt=k.useMemo(()=>{const qe=Gc[ee];return qe?e.filter(ft=>qe.includes(ft.status)):e},[e,ee]),ke=(()=>{const qe=[...tt].sort((ht,Re)=>ht.priority-Re.priority);if(ee!=="all"||Ue)return qe.map(ht=>({todo:ht,depth:0}));const ft=new Map,lt=[];for(const ht of qe)if(ht.depends_on){const Re=ft.get(ht.depends_on)||[];Re.push(ht),ft.set(ht.depends_on,Re)}else lt.push(ht);const xt=[],pt=new Set,st=(ht,Re)=>{if(pt.has(ht.id))return;pt.add(ht.id),xt.push({todo:ht,depth:Re});const ct=ft.get(ht.id);if(ct)for(const Oe of ct)st(Oe,Re+1)};for(const ht of lt)st(ht,0);for(const ht of qe)pt.has(ht.id)||xt.push({todo:ht,depth:0});return xt})(),{completedChainRoots:pe,completedChainMembers:Ne}=k.useMemo(()=>{const qe=new Map;for(const pt of e)if(pt.depends_on){const st=qe.get(pt.depends_on)||[];st.push(pt.id),qe.set(pt.depends_on,st)}const ft=e.filter(pt=>!pt.depends_on&&qe.has(pt.id)),lt=new Map,xt=new Set;for(const pt of ft){const st=[],ht=Re=>{if(!e.find(ie=>ie.id===Re))return;st.push(Re);const Oe=qe.get(Re)||[];for(const ie of Oe)ht(ie)};if(ht(pt.id),st.length>=2&&st.every(Re=>{const ct=e.find(Oe=>Oe.id===Re);return(ct==null?void 0:ct.status)==="completed"||(ct==null?void 0:ct.status)==="merged"})){lt.set(pt.id,st.length);for(const Re of st)xt.add(Re)}}return{completedChainRoots:lt,completedChainMembers:xt}},[e]),[Le,ze]=k.useState(null),[Ke,Ve]=k.useState(null),de=k.useCallback(async qe=>{if(b){ze(qe),Ve(null);try{await b(qe)}catch(ft){Ve(ft instanceof Error?ft.message:"Merge failed")}finally{ze(null)}}},[b]),fe=k.useRef(!1),ce=k.useCallback(qe=>{fe.current=!1,Y(qe)},[]),Q=k.useCallback(async()=>{if(!fe.current&&q&&T){const qe=e.find(ft=>ft.id===q);qe!=null&&qe.depends_on&&await T(q,null)}Y(null),B(null),J(null)},[q,e,T]),V=k.useCallback(qe=>{B(qe),J(null)},[]),re=k.useCallback(qe=>{B(ft=>ft===qe?null:ft)},[]),te=k.useCallback(async qe=>{!q||!T||q!==qe&&(dy(e,q,qe)||(fe.current=!0,await T(q,qe),Y(null),B(null),J(null)))},[q,e,T]),se=k.useCallback(async qe=>{T&&await T(qe,null)},[T]),le=k.useCallback(qe=>!q||q===qe?!1:!dy(e,q,qe),[q,e]),ve=k.useCallback(qe=>{J(qe),B(null)},[]),Ce=k.useCallback(qe=>{J(ft=>ft===qe?null:ft)},[]),De=k.useCallback(async(qe,ft)=>{if(!q||!R)return;const lt=ft.indexOf(q);if(lt<0)return;const xt=ft.filter(ht=>ht!==q),pt=qe>lt?qe-1:qe;if(pt===lt){J(null);return}const st=[...xt.slice(0,pt),q,...xt.slice(pt)];fe.current=!0,await R(st),Y(null),J(null),B(null)},[q,R]),Qe=e.some(qe=>qe.status==="pending"||qe.status==="failed"||qe.status==="stopped"),ut=e.some(qe=>qe.status==="running"),ot=n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:m,disabled:!Qe,className:"btn-ghost text-sm",children:[n.jsx(kr,{size:14}),xe("header.runAll")]}),n.jsxs("button",{onClick:o,disabled:!ut,className:"btn-ghost text-sm",children:[n.jsx(Ki,{size:14}),xe("header.stopAll")]})]});return W==="graph"?n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-5",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:xe("todos.title")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[n.jsx(bn,{onClick:()=>he("list"),label:xe("graph.listView"),size:"sm",children:n.jsx(xu,{size:14})}),n.jsx(bn,{onClick:()=>he("graph"),label:xe("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:n.jsx(Uv,{size:14})})]}),ot]})]}),n.jsx(k.Suspense,{fallback:null,children:n.jsx(t8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onAddTodo:f,onStartTodo:c,onStopTodo:d,onDeleteTodo:p,onEditTodo:u,onMergeTodo:x,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:g,onFixTodo:_,onUpdateDependency:T,onUpdatePosition:j,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:O,showTokenUsage:z})})]}):n.jsxs("div",{className:"min-h-[50vh]",onContextMenu:qe=>{hi(qe)||(qe.preventDefault(),$({x:qe.clientX,y:qe.clientY}))},children:[n.jsxs("div",{className:"flex items-center justify-between mb-5",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:xe("todos.title")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[n.jsx(bn,{onClick:()=>he("list"),label:xe("graph.listView"),size:"sm",variant:"active",pressed:!0,children:n.jsx(xu,{size:14})}),n.jsx(bn,{onClick:()=>he("graph"),label:xe("graph.graphView"),size:"sm",children:n.jsx(Uv,{size:14})})]}),n.jsx(bn,{onClick:Fe,label:xe(X?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:X?"active":"default",pressed:X,children:n.jsx(cE,{size:14})}),X&&!me&&W==="list"&&ke.length>0&&n.jsx(bn,{onClick:be,label:xe("todos.collapseStack"),size:"sm",children:n.jsx(dj,{size:14})}),ot,!P&&n.jsxs("button",{onClick:()=>F(!0),className:"btn-primary text-xs py-2",children:[n.jsx(mn,{size:14}),xe("todos.add")]})]})]}),P&&n.jsx("div",{className:"mb-5 animate-slide-up",children:n.jsx(O_,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,availableTodos:e,onSave:async(qe,ft,lt,xt,pt,st,ht,Re,ct,Oe)=>{await f(qe,ft,lt,xt,pt,st,ht,Re,ct,Oe),F(!1)},onCancel:()=>F(!1)})}),n.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(qe=>{const ft=ee===qe,lt=qe==="all"?"todos.filterAll":qe==="active"?"todos.filterActive":qe==="completed"?"todos.filterCompleted":"todos.filterCancelled";return n.jsxs("button",{onClick:()=>Ie(qe),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${ft?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[n.jsx("span",{children:xe(lt)}),n.jsx("span",{className:`text-2xs font-mono ${ft?"text-accent/70":"text-warm-400"}`,children:Pe[qe]})]},qe)})}),n.jsx("div",{className:Ue?"relative cursor-pointer":"space-y-3",onClick:Ue?be:void 0,title:Ue?xe("todos.expandStack"):void 0,style:Ue?{height:76+Math.max(ke.length-1,0)*6}:void 0,children:ke.length===0?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:Hw,title:xe(ee==="all"?"todos.empty":"todos.filterEmpty"),description:ee==="all"?xe("todos.emptyHint"):void 0})}):(()=>{const qe=ke.map(({todo:lt})=>lt.id),ft=lt=>{if(Ue||!R)return null;const xt=q!==null&&U===lt;return n.jsx("div",{onDragEnter:pt=>{pt.preventDefault(),ve(lt)},onDragOver:pt=>{pt.preventDefault(),pt.stopPropagation(),pt.dataTransfer.dropEffect="link",ve(lt)},onDragLeave:()=>Ce(lt),onDrop:pt=>{pt.preventDefault(),pt.stopPropagation(),De(lt,qe)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:xt&&n.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-${lt}`)};return n.jsxs(n.Fragment,{children:[ft(0),ke.map(({todo:lt,depth:xt},pt)=>{const st=pe.has(lt.id),ht=Ne.has(lt.id),Re=6,ct="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",Oe=Ue?{position:"absolute",top:pt*Re,left:0,right:0,zIndex:ke.length+10-pt,opacity:pt===0?1:.9,pointerEvents:pt===0?"auto":"none",transition:ct}:{transition:ct};return n.jsxs("div",{className:Ue?"":"animate-fade-in",style:Ue?Oe:{animationDelay:`${pt*30}ms`,...Oe},children:[!Ue&&st&&n.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 animate-slide-up",style:{animationDelay:`${pt*30}ms`},children:[n.jsx(ul,{size:16,className:"text-theme-muted flex-shrink-0"}),n.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:xe("todo.chainComplete")}),n.jsx("span",{className:"text-2xs font-mono text-warm-400",children:xe("todo.chainTasks").replace("{count}",String(pe.get(lt.id)))}),n.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Ke&&Le===null&&n.jsx("span",{className:"text-2xs text-status-error",children:Ke}),n.jsxs("button",{onClick:()=>de(lt.id),disabled:Le===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:xe("todo.mergeChainDesc"),children:[n.jsx(B5,{size:14}),Le===lt.id?"...":xe("todo.mergeChain")]})]})]}),n.jsxs("div",{className:"relative animate-fade-in",style:{animationDelay:`${pt*30}ms`,marginLeft:xt>0?`${xt*24}px`:void 0},children:[xt>0&&n.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),n.jsx(e8,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onStart:c,onStop:d,onDelete:p,onEdit:u,onMerge:x,onCleanup:C,onRetry:S,onContinue:g,onFix:_,onSchedule:w,onScheduleOnReset:y,resetsAt:E,onEvent:N,isInteractive:A.has(lt.id),onSendInput:D,isDragSource:q===lt.id,isDragging:q!==null,isDragOver:I===lt.id,isValidDropTarget:le(lt.id),onDragStart:ce,onDragEnd:Q,onDragOverTarget:V,onDragLeaveTarget:re,onDropTarget:te,onRemoveDependency:T?se:void 0,debugLogging:O,showTokenUsage:z,isChainMember:ht})]}),ft(pt+1)]},lt.id)})]})})()}),!Ue&&q&&((Je=e.find(qe=>qe.id===q))==null?void 0:Je.depends_on)&&n.jsxs("div",{className:"mt-3 border-2 border-dashed border-red-300 rounded-lg p-4 text-center text-sm text-red-400 transition-colors hover:border-red-400 hover:text-red-500 hover:bg-red-50",onDragOver:qe=>{qe.preventDefault(),qe.dataTransfer.dropEffect="move"},onDrop:qe=>{qe.preventDefault(),q&&T&&(fe.current=!0,T(q,null))},children:[n.jsx(dN,{size:20,className:"mx-auto mb-1"}),xe("dnd.dropToRemoveDep")]}),H&&n.jsx(Cr,{x:H.x,y:H.y,onClose:()=>$(null),children:n.jsxs("button",{onClick:()=>F(!0),className:an,children:[n.jsx(mn,{size:14}),xe("todos.add")]})})]})}const s8=[{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 r8(e){const s={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(!e)return s;const i=e.trim().split(/\s+/);if(i.length!==5)return{...s,mode:"custom"};const[a,h,f,,m]=i,o=a.match(/^\*\/(\d+)$/);if(o&&h==="*"&&f==="*"&&m==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&h==="*"&&f==="*"&&m==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const c=/^\d+$/.test(a)?parseInt(a):-1,d=/^\d+$/.test(h)?parseInt(h):-1;if(c<0||d<0)return{...s,mode:"custom"};if(f==="*"&&m!=="*"){const p=m.split(",").map(u=>{const x=parseInt(u);return isNaN(x)?-1:x}).filter(u=>u>=0);if(p.length>0)return{...s,mode:"weekly",weeklyDays:p,weeklyHour:d,weeklyMinute:c}}return/^\d+$/.test(f)&&m==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:d,monthlyMinute:c}:f==="*"&&m==="*"?{...s,mode:"daily",dailyHour:d,dailyMinute:c}:{...s,mode:"custom"}}function hy(e){switch(e.mode){case"minutes":return`*/${e.everyMinutes} * * * *`;case"hourly":return`${e.hourlyMinute} * * * *`;case"daily":return`${e.dailyMinute} ${e.dailyHour} * * *`;case"weekly":return`${e.weeklyMinute} ${e.weeklyHour} * * ${e.weeklyDays.sort((s,i)=>s-i).join(",")}`;case"monthly":return`${e.monthlyMinute} ${e.monthlyHour} ${e.monthlyDay} * *`;default:return""}}function i8({value:e,onChange:s}){const{t:i}=dt(),[a,h]=k.useState(()=>r8(e)),[f,m]=k.useState(e);k.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=hy(a);s(b)}},[a,f]);const o=b=>{h(C=>({...C,...b}))},c=b=>{h(C=>{const S=C.weeklyDays.includes(b)?C.weeklyDays.filter(g=>g!==b):[...C.weeklyDays,b];return{...C,weeklyDays:S.length>0?S:C.weeklyDays}})},d=[{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"}],p="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",u=(b,C,S,g)=>n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("select",{value:b,onChange:_=>S(parseInt(_.target.value)),className:`${p} w-16`,children:Array.from({length:24},(_,w)=>n.jsx("option",{value:w,children:String(w).padStart(2,"0")},w))}),n.jsx("span",{className:"text-warm-500 font-mono",children:":"}),n.jsx("select",{value:C,onChange:_=>g(parseInt(_.target.value)),className:`${p} w-16`,children:Array.from({length:12},(_,w)=>w*5).map(_=>n.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))})]}),x=a.mode==="custom"?f:hy(a);return n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map(b=>n.jsx("button",{type:"button",onClick:()=>o({mode:b.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===b.value?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:i(b.labelKey)},b.value))}),n.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[a.mode==="minutes"&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.every")}),n.jsx("select",{value:a.everyMinutes,onChange:b=>o({everyMinutes:parseInt(b.target.value)}),className:`${p} w-20`,children:[5,10,15,20,30].map(b=>n.jsx("option",{value:b,children:b},b))}),n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),n.jsx("select",{value:a.hourlyMinute,onChange:b=>o({hourlyMinute:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:12},(b,C)=>C*5).map(b=>n.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyDayAt")}),u(a.dailyHour,a.dailyMinute,b=>o({dailyHour:b}),b=>o({dailyMinute:b}))]}),a.mode==="weekly"&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"flex flex-wrap gap-1.5",children:s8.map(b=>n.jsx("button",{type:"button",onClick:()=>c(b.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${a.weeklyDays.includes(b.value)?"bg-amber-500 text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-amber-300"}`,children:i(b.labelKey)},b.value))}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.at")}),u(a.weeklyHour,a.weeklyMinute,b=>o({weeklyHour:b}),b=>o({weeklyMinute:b}))]})]}),a.mode==="monthly"&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),n.jsx("select",{value:a.monthlyDay,onChange:b=>o({monthlyDay:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:28},(b,C)=>C+1).map(b=>n.jsx("option",{value:b,children:b},b))}),n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),u(a.monthlyHour,a.monthlyMinute,b=>o({monthlyHour:b}),b=>o({monthlyMinute:b}))]}),a.mode==="custom"&&n.jsxs("div",{children:[n.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:b=>m(b.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"}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&x&&n.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[n.jsxs("span",{className:"text-warm-400",children:[i("cron.expression"),":"]}),n.jsx("code",{className:"px-2 py-0.5 rounded bg-warm-100 text-warm-600 font-mono",children:x})]})]})}function a8(){const e=new Date;e.setHours(e.getHours()+1),e.setMinutes(0,0,0);const s=e.getFullYear(),i=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0"),h=String(e.getHours()).padStart(2,"0"),f=String(e.getMinutes()).padStart(2,"0");return`${s}-${i}-${a}T${h}:${f}`}function o8(e){const s=new Date(e),i=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),h=String(s.getDate()).padStart(2,"0"),f=String(s.getHours()).padStart(2,"0"),m=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${h}T${f}:${m}`}function B_({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:h="",initialCliTool:f,initialSkipIfRunning:m=!0,initialScheduleType:o="recurring",initialRunAt:c,projectCliTool:d="claude"}){const[p,u]=k.useState(i),[x,b]=k.useState(a),[C,S]=k.useState(h),[g,_]=k.useState(f||d||"claude"),[w,y]=k.useState(m),[E,T]=k.useState(o),[j,R]=k.useState(c?o8(c):a8()),{t:N}=dt(),D=E==="once",A=p.trim()&&(D?!!j:!!C.trim()),O=z=>{z.preventDefault(),A&&e({title:p.trim(),description:x.trim(),cronExpression:D?"":C.trim(),cliTool:g,skipIfRunning:w,scheduleType:E,runAt:D?new Date(j).toISOString():void 0})};return n.jsxs("form",{onSubmit:O,className:"card p-5 border-amber-500/30",children:[n.jsx("div",{className:"mb-3",children:n.jsx("input",{type:"text",placeholder:N("scheduleForm.titlePlaceholder"),value:p,onChange:z=>u(z.target.value),className:"input-field",autoFocus:!0})}),n.jsx("div",{className:"mb-3",children:n.jsx("textarea",{placeholder:N("scheduleForm.descPlaceholder"),value:x,onChange:z=>b(z.target.value),rows:3,className:"prompt-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"})}),n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.type")}),n.jsxs("div",{className:"flex gap-1.5",children:[n.jsx("button",{type:"button",onClick:()=>T("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${E==="recurring"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:N("schedule.recurring")}),n.jsx("button",{type:"button",onClick:()=>T("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${E==="once"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:N("schedule.once")})]})]}),D?n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.runAtLabel")}),n.jsx("input",{type:"datetime-local",value:j,onChange:z=>R(z.target.value),className:"input-field text-sm font-mono",min:new Date().toISOString().slice(0,16)})]}):n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.cronExpression")}),n.jsx(i8,{value:C,onChange:S})]}),n.jsx("div",{className:"mb-3 grid grid-cols-2 gap-3",children:n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("scheduleForm.cliTool")}),n.jsx("select",{value:g,onChange:z=>_(z.target.value),className:"input-field text-sm !py-2",children:wr.map(z=>n.jsx("option",{value:z.value,children:z.label},z.value))})]})}),!D&&n.jsx("div",{className:"mb-4",children:n.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:w,onChange:z=>y(z.target.checked),className:"rounded border-warm-300 text-amber-500 focus:ring-amber-500"}),N("schedule.skipIfRunning")]})}),n.jsxs("div",{className:"flex gap-3 justify-end",children:[n.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:N("scheduleForm.cancel")}),n.jsx("button",{type:"submit",disabled:!A,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function l8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:h,onMergeRun:f,onCleanupRun:m}){const[o,c]=k.useState(!1),[d,p]=k.useState(!1),[u,x]=k.useState([]),[b,C]=k.useState(!1),[S,g]=k.useState(!1),[_,w]=k.useState(null),{t:y}=dt(),E=async()=>{try{const H=await ff(e.id);x(H)}catch{}},T=async H=>{if(!(!H.todo_id||!f)){w(H.id);try{await f(H.todo_id),await E()}finally{w(null)}}},j=async H=>{if(!(!H.todo_id||!m)){w(H.id);try{await m(H.todo_id),await E()}finally{w(null)}}},R=e.schedule_type==="once",N=async()=>{if(!b)try{const H=await ff(e.id);x(H),C(!0)}catch{}},D=()=>{const H=!o;c(H),H&&N()},A=async()=>{g(!0);try{await h(e.id);const H=await ff(e.id);x(H),C(!0)}finally{g(!1)}};if(d)return n.jsx(B_,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:R?"":e.cron_expression,initialCliTool:e.cli_tool??void 0,initialSkipIfRunning:!!e.skip_if_running,initialScheduleType:e.schedule_type,initialRunAt:e.run_at??void 0,onSave:async H=>{await a(e.id,{title:H.title,description:H.description,cron_expression:H.cronExpression||void 0,cli_tool:H.cliTool,skip_if_running:H.skipIfRunning,schedule_type:H.scheduleType,run_at:H.runAt}),p(!1)},onCancel:()=>p(!1)});const O=e.is_active?"border-l-amber-500":"border-l-warm-300",z={triggered:"text-status-running",skipped:"text-status-warning",completed:"text-status-success",failed:"text-status-error"},P={triggered:y("schedule.runTriggered"),skipped:y("schedule.runSkipped"),completed:y("schedule.runCompleted"),failed:y("schedule.runFailed")},F=H=>H?new Date(H).toLocaleString():"";return n.jsxs("div",{className:`card border-l-4 ${O} overflow-hidden`,children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:D,children:[n.jsx("button",{className:"text-warm-400 hover:text-amber-500 flex-shrink-0 transition-colors",children:n.jsx(Ns,{size:14,className:`transition-transform duration-200 ${o?"rotate-90":""}`})}),n.jsx("span",{className:"flex-1 text-sm text-warm-800 font-medium truncate",children:e.title}),R?n.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-2xs font-mono font-medium bg-blue-500/10 text-blue-600 flex-shrink-0",children:[n.jsx(ai,{size:12}),F(e.run_at)]}):n.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-mono font-medium bg-amber-500/10 text-amber-600 flex-shrink-0",children:e.cron_expression}),n.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${R?"bg-blue-500/10 text-blue-600":"bg-amber-500/10 text-amber-600"}`,children:y(R?"schedule.once":"schedule.recurring")}),n.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${e.is_active?"bg-status-success/10 text-status-success":"bg-warm-200 text-warm-500"}`,children:e.is_active?y("schedule.active"):y("schedule.paused")}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:H=>H.stopPropagation(),children:[n.jsx("button",{onClick:A,disabled:S,className:"p-1.5 text-amber-500/60 hover:text-amber-500 hover:bg-amber-500/10 rounded-lg transition-colors disabled:opacity-30",title:y("schedule.trigger"),children:n.jsx(kr,{size:14})}),n.jsx("button",{onClick:()=>s(e.id,!e.is_active),className:`p-1.5 rounded-lg transition-colors ${e.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:e.is_active?y("schedule.pause"):y("schedule.activate"),children:e.is_active?n.jsx(Zm,{size:14}):n.jsx(_r,{size:14})}),n.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:y("schedule.edit"),children:n.jsx(ci,{size:14})}),n.jsx("button",{onClick:()=>i(e.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:y("schedule.delete"),children:n.jsx(Ln,{size:14})})]})]}),o&&n.jsxs("div",{className:"border-t border-warm-200 px-5 py-5 space-y-4 animate-fade-in bg-warm-50/50",children:[e.description&&n.jsx("div",{children:n.jsx("p",{className:"text-sm text-warm-600 whitespace-pre-wrap leading-relaxed",children:e.description})}),n.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[R?n.jsxs("span",{className:"badge bg-blue-500/10 text-blue-600 font-mono",children:[y("schedule.runAtLabel"),": ",F(e.run_at)]}):n.jsx("span",{className:"badge bg-amber-500/10 text-amber-600 font-mono",children:e.cron_expression}),!R&&e.skip_if_running?n.jsx("span",{className:"badge bg-status-info/10 text-status-info",children:y("schedule.skipIfRunning")}):null,n.jsxs("span",{className:"badge bg-warm-200 text-warm-600",children:[y("schedule.lastRun"),": ",e.last_run_at?new Date(e.last_run_at).toLocaleString():y("schedule.never")]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:y("schedule.runs")}),u.length===0?n.jsx("p",{className:"text-xs text-warm-400 italic",children:y("schedule.noRuns")}):n.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:u.map(H=>{const $=H.todo_id&&H.todo_status==="completed"&&!!H.todo_branch_name,q=H.todo_id&&H.todo_status!=="running"&&H.todo_status!=="pending"&&(H.todo_worktree_path||H.todo_branch_name),Y=_===H.id;return n.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[n.jsx("span",{className:`font-medium ${z[H.status]||"text-warm-500"}`,children:P[H.status]||H.status}),H.skipped_reason&&n.jsxs("span",{className:"text-warm-400",children:["(",H.skipped_reason,")"]}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[$&&f&&n.jsx("button",{onClick:()=>T(H),disabled:Y,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded transition-colors disabled:opacity-30",title:y("todo.merge"),children:n.jsx(cl,{size:12})}),q&&m&&n.jsx("button",{onClick:()=>j(H),disabled:Y,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded transition-colors disabled:opacity-30",title:y("todo.cleanup"),children:n.jsx(Ln,{size:12})})]}),n.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(H.started_at).toLocaleString()})]},H.id)})})]})]})]})}function c8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:h,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:c}){const[d,p]=k.useState(!1),[u,x]=k.useState(null),{t:b}=dt();return n.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{hi(C)||(C.preventDefault(),x({x:C.clientX,y:C.clientY}))},children:[n.jsxs("div",{className:"flex items-center justify-between mb-5",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:b("schedules.title")}),!d&&n.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[n.jsx(mn,{size:14}),b("schedules.add")]})]}),d&&n.jsx("div",{className:"mb-5 animate-slide-up",children:n.jsx(B_,{projectCliTool:s,onSave:async C=>{await i(C),p(!1)},onCancel:()=>p(!1)})}),n.jsx("div",{className:"space-y-3",children:e.length===0?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:X5,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,S)=>n.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${S*30}ms`},children:n.jsx(l8,{schedule:C,onToggle:a,onDelete:h,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:c})},C.id))}),u&&n.jsx(Cr,{x:u.x,y:u.y,onClose:()=>x(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>p(!0),children:[n.jsx(mn,{size:14}),b("schedules.add")]})})]})}function P_(e){const[s,i]=k.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return k.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(e),h=f=>i(f.matches);return i(a.matches),a.addEventListener("change",h),()=>a.removeEventListener("change",h)},[e]),s}const fy="__custom__";function u8({open:e,onClose:s,projectId:i,projectName:a,onPushed:h}){const{t:f}=dt(),[m,o]=k.useState(!1),[c,d]=k.useState(!1),[p,u]=k.useState(null),[x,b]=k.useState([]),[C,S]=k.useState("origin"),[g,_]=k.useState([]),[w,y]=k.useState([]),[E,T]=k.useState(!0),[j,R]=k.useState(!1);k.useEffect(()=>{if(!e)return;let H=!1;return o(!0),u(null),Promise.all([AN(i),om(i)]).then(([$,q])=>{var ee,Z;if(H)return;const Y=$.remotes||[];b(Y);const I=((ee=Y.find(X=>X.name==="origin"))==null?void 0:ee.name)||((Z=Y[0])==null?void 0:Z.name)||"origin";S(I);const B=q.branches||[],U=B.filter(X=>!X.remote),J=`remotes/${I}/`,W=B.filter(X=>X.remote&&X.name.startsWith(J)).map(X=>X.name.slice(J.length)).filter(X=>X&&X!=="HEAD");y(W);const oe=new Set(W);_(U.map(X=>{const G=oe.has(X.name);return{local:X.name,current:X.current,remote:X.name,customRemote:!1,setUpstream:!G,checked:X.current}}))}).catch($=>{H||u($ instanceof Error?$.message:"Failed to load remotes")}).finally(()=>{H||o(!1)}),()=>{H=!0}},[e,i]),k.useEffect(()=>{if(!e||!C)return;let H=!1;return om(i).then($=>{if(H)return;const q=`remotes/${C}/`,Y=($.branches||[]).filter(I=>I.remote&&I.name.startsWith(q)).map(I=>I.name.slice(q.length)).filter(I=>I&&I!=="HEAD");y(Y)}).catch(()=>{}),()=>{H=!0}},[C,i,e]);const N=g.length>0&&g.every(H=>H.checked),D=g.some(H=>H.checked),A=g.filter(H=>H.checked).length,O=k.useMemo(()=>{var H;return((H=x.find($=>$.name===C))==null?void 0:H.url)||""},[x,C]),z=(H,$)=>{_(q=>q.map(Y=>Y.local===H?{...Y,...$}:Y))},P=()=>{const H=!N;_($=>$.map(q=>({...q,checked:H})))},F=async()=>{u(null);const H=g.filter(q=>q.checked);if(H.length===0){u(f("git.pushDialog.errorRequireBranch"));return}const $=H.map(q=>({local:q.local,remote:(q.remote||"").trim()||q.local,setUpstream:q.setUpstream}));d(!0);try{await tp(i,{remote:C,branches:$,pushAllTags:E,force:j}),h==null||h(),s()}catch(q){u(q instanceof Error?q.message:"Push failed")}finally{d(!1)}};return n.jsx(Un,{open:e,onClose:c?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:c,children:n.jsxs("div",{className:"card p-5 space-y-4",children:[n.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),n.jsxs("select",{value:C,onChange:H=>S(H.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:m||c||x.length===0,children:[x.length===0&&n.jsx("option",{value:"origin",children:"origin"}),x.map(H=>n.jsx("option",{value:H.name,children:H.name},H.name))]}),n.jsx("input",{readOnly:!0,value:O,className:"input-field text-xs font-mono py-1.5 px-3 flex-1 cursor-default"})]}),n.jsxs("div",{children:[n.jsx("div",{className:"section-label mb-2",children:f("git.pushDialog.branchesHeader")}),n.jsx("div",{className:"rounded-xl border border-theme-border-strong overflow-hidden",children:n.jsx("div",{className:"overflow-auto max-h-[50vh]",children:n.jsxs("table",{className:"w-full text-sm border-collapse",children:[n.jsx("thead",{className:"sticky top-0 bg-warm-100 z-10",children:n.jsxs("tr",{children:[n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-12",children:f("git.pushDialog.colPush")}),n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colLocal")}),n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colRemote")}),n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-16",children:f("git.pushDialog.colTracking")})]})}),n.jsxs("tbody",{children:[m&&n.jsx("tr",{children:n.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!m&&g.length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.noLocalBranches")})}),g.map(H=>n.jsxs("tr",{className:"border-t border-theme-border/50 hover:bg-theme-hover/40 transition-colors",children:[n.jsx("td",{className:"py-2 px-3",children:n.jsx("input",{type:"checkbox",checked:H.checked,onChange:$=>z(H.local,{checked:$.target.checked}),disabled:c,className:"cursor-pointer"})}),n.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[H.local,H.current&&n.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),n.jsx("td",{className:"py-2 px-3",children:H.customRemote?n.jsx("input",{type:"text",value:H.remote,onChange:$=>z(H.local,{remote:$.target.value}),placeholder:H.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c}):n.jsxs("select",{value:w.includes(H.remote)||H.remote?H.remote:"",onChange:$=>{const q=$.target.value;q===fy?z(H.local,{customRemote:!0}):z(H.local,{remote:q})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c,children:[!w.includes(H.remote)&&H.remote&&n.jsxs("option",{value:H.remote,children:[H.remote," (",f("git.pushDialog.newBranch"),")"]}),w.map($=>n.jsx("option",{value:$,children:$},$)),n.jsx("option",{value:fy,children:f("git.pushDialog.customRemote")})]})}),n.jsx("td",{className:"py-2 px-3",children:n.jsx("input",{type:"checkbox",checked:H.setUpstream,onChange:$=>z(H.local,{setUpstream:$.target.checked}),disabled:c,className:"cursor-pointer"})})]},H.local))]})]})})})]}),n.jsxs("div",{className:"flex items-center gap-5 text-xs text-warm-700",children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:N,ref:H=>{H&&(H.indeterminate=!N&&D)},onChange:P,disabled:c||g.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:E,onChange:H=>T(H.target.checked),disabled:c,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:j,onChange:H=>R(H.target.checked),disabled:c,className:"cursor-pointer"}),n.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),p&&n.jsx("div",{className:"text-xs text-status-error font-medium",children:p}),n.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[n.jsx("button",{type:"button",onClick:s,disabled:c,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),n.jsx("button",{type:"button",onClick:F,disabled:c||m||A===0,className:"btn-primary btn-md",children:f(c?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function d8(e){switch(e){case"A":return{label:"A",color:"text-status-success"};case"D":return{label:"D",color:"text-status-error"};case"R":return{label:"R",color:"text-purple-500"};case"C":return{label:"C",color:"text-blue-500"};default:return{label:"M",color:"text-accent"}}}function Ku({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:h}){const{t:f}=dt();return n.jsxs("div",{className:"h-full flex flex-col",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[n.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:f("git.changedFiles")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"text-2xs text-warm-400",children:[e.length," ",f("git.files")]}),h&&n.jsx("span",{className:"text-2xs font-mono text-warm-400",children:h.substring(0,7)})]})]}),s?n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx("span",{className:"text-xs text-warm-400",children:f("git.loadingFiles")})}):e.length===0?n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx("span",{className:"text-xs text-warm-400",children:f("git.noFilesChanged")})}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(m=>{const o=d8(m.status),c=i===m.path;return n.jsxs("div",{onClick:()=>a(m.path),className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 transition-colors ${c?"bg-accent/10 border-l-2 border-accent":""}`,children:[n.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),n.jsxs("span",{className:"truncate flex-1 text-warm-600",title:m.path,children:[m.path.split("/").pop(),n.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:m.path.includes("/")?m.path.substring(0,m.path.lastIndexOf("/")):""})]}),n.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",m.additions]}),n.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",m.deletions]})]},m.path)})})]})}function Cl({diff:e,loading:s,selectedFile:i}){const{t:a}=dt(),[h,f]=k.useState(!0);return i?s?n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx("span",{className:"text-xs text-warm-400",children:a("git.loadingDiff")})}):n.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:i,children:i}),n.jsx("button",{onClick:()=>f(m=>!m),title:a("git.wrapLines")||"Wrap lines",className:`p-1 rounded shrink-0 hover:bg-gray-700 ${h?"text-accent":"text-gray-500"}`,children:n.jsx(iN,{size:14})})]}),n.jsx("div",{className:"flex-1 overflow-auto",children:n.jsx("div",{className:"p-3 font-mono text-xs leading-relaxed",children:e?(()=>{let m=0,o=0,c=!1;return e.split(`
664
+ `).map((ue,nt)=>{let mt="text-theme-text",Mt="";return ue.startsWith("+")&&!ue.startsWith("+++")?mt="text-theme-text bg-status-success/15":ue.startsWith("-")&&!ue.startsWith("---")?mt="text-theme-text bg-status-error/15":ue.startsWith("@@")?mt="text-accent":ue.startsWith("diff ")&&(mt="text-warm-700",Mt="font-semibold"),n.jsx("div",{className:`whitespace-pre ${mt} ${Mt}`,children:ue},nt)}):n.jsx("span",{className:"text-warm-400 italic",children:we("log.noChanges")})})]}),n.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:He.bg,fontFamily:Rt,border:`1px solid ${He.separator}`},children:[n.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${He.separator}`,fontSize:12,color:He.text},children:[n.jsx("span",{style:{color:He.prompt},children:"$"})," ",n.jsx("span",{style:{color:He.bright},children:"tail"})," ",n.jsx("span",{style:{color:He.dim},children:"-f task.log"})]}),n.jsx(A_,{logs:U,interactive:w&&e.status==="running",todoId:e.id,onSendInput:y,embedded:!0})]})]})})]}),$e&&n.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 animate-fade-in",children:[n.jsx(ul,{size:14,className:"text-accent flex-shrink-0"}),n.jsx("span",{className:"text-xs font-medium text-accent",children:we("dnd.dropHint")})]}),it&&n.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-red-300 bg-red-50/50 animate-fade-in",children:[n.jsx($5,{size:14,className:"text-red-400 flex-shrink-0"}),n.jsx("span",{className:"text-xs font-medium text-red-400",children:we("dnd.cyclicWarning")})]}),_e&&n.jsxs(Cr,{x:_e.x,y:_e.y,onClose:()=>je(null),children:[rt&&n.jsxs("button",{onClick:()=>f(e.id,"headless"),className:an,title:we("todo.startHeadless"),children:[n.jsx(kr,{size:14}),we("todo.start")]}),rt&&xi&&n.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:an,title:we("todo.startInteractiveDesc"),children:[n.jsx(di,{size:14}),we("todo.startInteractive")]}),rt&&n.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:an,title:we("todo.startVerboseDesc"),children:[n.jsx(rm,{size:14}),we("todo.startVerbose")]}),bt&&n.jsxs("button",{onClick:()=>m(e.id),className:an,children:[n.jsx(Ki,{size:14}),we("todo.stop")]}),Et&&n.jsxs("button",{onClick:qn,disabled:Ie,className:an,children:[n.jsx(cl,{size:14}),we("todo.merge")]}),pn&&n.jsxs("button",{onClick:()=>{de(!0),te(null)},disabled:Q,className:an,children:[n.jsx(Fv,{size:14}),we("todo.continue")]}),Ht&&n.jsxs("button",{onClick:()=>Ts("headless"),disabled:Ne,className:an,children:[n.jsx(ui,{size:14}),we("todo.retry")]}),Me&&n.jsxs("button",{onClick:()=>pt(!0),className:an,title:we("todo.scheduleDesc"),children:[n.jsx(nm,{size:14}),we("todo.schedule")]}),vt&&n.jsxs("button",{onClick:()=>{le(!0),ot(null)},className:an,title:we("todo.scheduleOnResetDesc"),children:[n.jsx(ai,{size:14}),we("todo.scheduleOnReset")]}),St&&n.jsxs("button",{onClick:ps,disabled:me,className:an,children:[n.jsx(Jo,{size:14}),we("todo.viewDiff")]}),F&&yn&&n.jsxs("button",{onClick:ms,className:an,children:[n.jsx(qv,{size:14}),we("todo.viewDebugLog")]}),gn&&n.jsxs("button",{onClick:gs,disabled:Pe,className:an,children:[n.jsx(pu,{size:14}),we("todo.cleanup")]}),n.jsx(z_,{}),n.jsxs("button",{onClick:()=>B(!0),className:an,children:[n.jsx(ci,{size:14}),we("todo.edit")]}),n.jsxs("button",{onClick:()=>o(e.id),className:Ep,children:[n.jsx(Ln,{size:14}),we("todo.delete")]})]})]})}const t8=k.lazy(()=>Fu(()=>import("./TaskGraph-DF8aE2pm.js"),__vite__mapDeps([0,1,2,3,4]))),Gc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function dy(e,s,i){let a=i;const h=new Set;for(;a;){if(a===s)return!0;if(h.has(a))return!1;h.add(a);const f=e.find(m=>m.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function n8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onAddTodo:f,onStartAll:m,onStopAll:o,onStartTodo:c,onStopTodo:d,onDeleteTodo:p,onEditTodo:u,onMergeTodo:x,onMergeChain:b,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:g,onFixTodo:_,onScheduleTodo:w,onScheduleOnResetTodo:y,resetsAt:E,onUpdateDependency:T,onUpdatePosition:j,onReorderTodos:R,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:O,showTokenUsage:z}){var Je;const[P,F]=k.useState(!1),[H,$]=k.useState(null),[q,Y]=k.useState(null),[I,B]=k.useState(null),[U,J]=k.useState(null),[W,oe]=k.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[ee,Z]=k.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[X,G]=k.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[me,ge]=k.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:xe}=dt(),he=k.useCallback(qe=>{oe(qe);try{localStorage.setItem("todoViewMode",qe)}catch{}},[]),Ie=k.useCallback(qe=>{Z(qe);try{localStorage.setItem("todoStatusFilter",qe)}catch{}},[]),Fe=k.useCallback(()=>{G(qe=>{const ft=!qe;try{localStorage.setItem("todoStackModeEnabled",String(ft))}catch{}if(!ft){ge(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return ft})},[]),be=k.useCallback(()=>{ge(qe=>{const ft=!qe;try{localStorage.setItem("todoStackCollapsed",String(ft))}catch{}return ft})},[]),Ue=X&&me&&W==="list",Pe=k.useMemo(()=>({all:e.length,active:e.filter(qe=>Gc.active.includes(qe.status)).length,completed:e.filter(qe=>Gc.completed.includes(qe.status)).length,cancelled:e.filter(qe=>Gc.cancelled.includes(qe.status)).length}),[e]),tt=k.useMemo(()=>{const qe=Gc[ee];return qe?e.filter(ft=>qe.includes(ft.status)):e},[e,ee]),ke=(()=>{const qe=[...tt].sort((ht,Re)=>ht.priority-Re.priority);if(ee!=="all"||Ue)return qe.map(ht=>({todo:ht,depth:0}));const ft=new Map,lt=[];for(const ht of qe)if(ht.depends_on){const Re=ft.get(ht.depends_on)||[];Re.push(ht),ft.set(ht.depends_on,Re)}else lt.push(ht);const xt=[],pt=new Set,st=(ht,Re)=>{if(pt.has(ht.id))return;pt.add(ht.id),xt.push({todo:ht,depth:Re});const ct=ft.get(ht.id);if(ct)for(const Oe of ct)st(Oe,Re+1)};for(const ht of lt)st(ht,0);for(const ht of qe)pt.has(ht.id)||xt.push({todo:ht,depth:0});return xt})(),{completedChainRoots:pe,completedChainMembers:Ne}=k.useMemo(()=>{const qe=new Map;for(const pt of e)if(pt.depends_on){const st=qe.get(pt.depends_on)||[];st.push(pt.id),qe.set(pt.depends_on,st)}const ft=e.filter(pt=>!pt.depends_on&&qe.has(pt.id)),lt=new Map,xt=new Set;for(const pt of ft){const st=[],ht=Re=>{if(!e.find(ie=>ie.id===Re))return;st.push(Re);const Oe=qe.get(Re)||[];for(const ie of Oe)ht(ie)};if(ht(pt.id),st.length>=2&&st.every(Re=>{const ct=e.find(Oe=>Oe.id===Re);return(ct==null?void 0:ct.status)==="completed"||(ct==null?void 0:ct.status)==="merged"})){lt.set(pt.id,st.length);for(const Re of st)xt.add(Re)}}return{completedChainRoots:lt,completedChainMembers:xt}},[e]),[Le,ze]=k.useState(null),[Ke,Ve]=k.useState(null),de=k.useCallback(async qe=>{if(b){ze(qe),Ve(null);try{await b(qe)}catch(ft){Ve(ft instanceof Error?ft.message:"Merge failed")}finally{ze(null)}}},[b]),fe=k.useRef(!1),ce=k.useCallback(qe=>{fe.current=!1,Y(qe)},[]),Q=k.useCallback(async()=>{if(!fe.current&&q&&T){const qe=e.find(ft=>ft.id===q);qe!=null&&qe.depends_on&&await T(q,null)}Y(null),B(null),J(null)},[q,e,T]),V=k.useCallback(qe=>{B(qe),J(null)},[]),re=k.useCallback(qe=>{B(ft=>ft===qe?null:ft)},[]),te=k.useCallback(async qe=>{!q||!T||q!==qe&&(dy(e,q,qe)||(fe.current=!0,await T(q,qe),Y(null),B(null),J(null)))},[q,e,T]),se=k.useCallback(async qe=>{T&&await T(qe,null)},[T]),le=k.useCallback(qe=>!q||q===qe?!1:!dy(e,q,qe),[q,e]),ve=k.useCallback(qe=>{J(qe),B(null)},[]),Ce=k.useCallback(qe=>{J(ft=>ft===qe?null:ft)},[]),De=k.useCallback(async(qe,ft)=>{if(!q||!R)return;const lt=ft.indexOf(q);if(lt<0)return;const xt=ft.filter(ht=>ht!==q),pt=qe>lt?qe-1:qe;if(pt===lt){J(null);return}const st=[...xt.slice(0,pt),q,...xt.slice(pt)];fe.current=!0,await R(st),Y(null),J(null),B(null)},[q,R]),Qe=e.some(qe=>qe.status==="pending"||qe.status==="failed"||qe.status==="stopped"),ut=e.some(qe=>qe.status==="running"),ot=n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:m,disabled:!Qe,className:"btn-ghost text-sm",children:[n.jsx(kr,{size:14}),xe("header.runAll")]}),n.jsxs("button",{onClick:o,disabled:!ut,className:"btn-ghost text-sm",children:[n.jsx(Ki,{size:14}),xe("header.stopAll")]})]});return W==="graph"?n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-5",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:xe("todos.title")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[n.jsx(bn,{onClick:()=>he("list"),label:xe("graph.listView"),size:"sm",children:n.jsx(xu,{size:14})}),n.jsx(bn,{onClick:()=>he("graph"),label:xe("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:n.jsx(Uv,{size:14})})]}),ot]})]}),n.jsx(k.Suspense,{fallback:null,children:n.jsx(t8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onAddTodo:f,onStartTodo:c,onStopTodo:d,onDeleteTodo:p,onEditTodo:u,onMergeTodo:x,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:g,onFixTodo:_,onUpdateDependency:T,onUpdatePosition:j,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:O,showTokenUsage:z})})]}):n.jsxs("div",{className:"min-h-[50vh]",onContextMenu:qe=>{hi(qe)||(qe.preventDefault(),$({x:qe.clientX,y:qe.clientY}))},children:[n.jsxs("div",{className:"flex items-center justify-between mb-5",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:xe("todos.title")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[n.jsx(bn,{onClick:()=>he("list"),label:xe("graph.listView"),size:"sm",variant:"active",pressed:!0,children:n.jsx(xu,{size:14})}),n.jsx(bn,{onClick:()=>he("graph"),label:xe("graph.graphView"),size:"sm",children:n.jsx(Uv,{size:14})})]}),n.jsx(bn,{onClick:Fe,label:xe(X?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:X?"active":"default",pressed:X,children:n.jsx(cE,{size:14})}),X&&!me&&W==="list"&&ke.length>0&&n.jsx(bn,{onClick:be,label:xe("todos.collapseStack"),size:"sm",children:n.jsx(dj,{size:14})}),ot,!P&&n.jsxs("button",{onClick:()=>F(!0),className:"btn-primary text-xs py-2",children:[n.jsx(mn,{size:14}),xe("todos.add")]})]})]}),P&&n.jsx("div",{className:"mb-5 animate-slide-up",children:n.jsx(O_,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,availableTodos:e,onSave:async(qe,ft,lt,xt,pt,st,ht,Re,ct,Oe)=>{await f(qe,ft,lt,xt,pt,st,ht,Re,ct,Oe),F(!1)},onCancel:()=>F(!1)})}),n.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(qe=>{const ft=ee===qe,lt=qe==="all"?"todos.filterAll":qe==="active"?"todos.filterActive":qe==="completed"?"todos.filterCompleted":"todos.filterCancelled";return n.jsxs("button",{onClick:()=>Ie(qe),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${ft?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[n.jsx("span",{children:xe(lt)}),n.jsx("span",{className:`text-2xs font-mono ${ft?"text-accent/70":"text-warm-400"}`,children:Pe[qe]})]},qe)})}),n.jsx("div",{className:Ue?"relative cursor-pointer":"space-y-3",onClick:Ue?be:void 0,title:Ue?xe("todos.expandStack"):void 0,style:Ue?{height:76+Math.max(ke.length-1,0)*6}:void 0,children:ke.length===0?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:Hw,title:xe(ee==="all"?"todos.empty":"todos.filterEmpty"),description:ee==="all"?xe("todos.emptyHint"):void 0})}):(()=>{const qe=ke.map(({todo:lt})=>lt.id),ft=lt=>{if(Ue||!R)return null;const xt=q!==null&&U===lt;return n.jsx("div",{onDragEnter:pt=>{pt.preventDefault(),ve(lt)},onDragOver:pt=>{pt.preventDefault(),pt.stopPropagation(),pt.dataTransfer.dropEffect="link",ve(lt)},onDragLeave:()=>Ce(lt),onDrop:pt=>{pt.preventDefault(),pt.stopPropagation(),De(lt,qe)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:xt&&n.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-${lt}`)};return n.jsxs(n.Fragment,{children:[ft(0),ke.map(({todo:lt,depth:xt},pt)=>{const st=pe.has(lt.id),ht=Ne.has(lt.id),Re=6,ct="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",Oe=Ue?{position:"absolute",top:pt*Re,left:0,right:0,zIndex:ke.length+10-pt,opacity:pt===0?1:.9,pointerEvents:pt===0?"auto":"none",transition:ct}:{transition:ct};return n.jsxs("div",{className:Ue?"":"animate-fade-in",style:Ue?Oe:{animationDelay:`${pt*30}ms`,...Oe},children:[!Ue&&st&&n.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 animate-slide-up",style:{animationDelay:`${pt*30}ms`},children:[n.jsx(ul,{size:16,className:"text-theme-muted flex-shrink-0"}),n.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:xe("todo.chainComplete")}),n.jsx("span",{className:"text-2xs font-mono text-warm-400",children:xe("todo.chainTasks").replace("{count}",String(pe.get(lt.id)))}),n.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Ke&&Le===null&&n.jsx("span",{className:"text-2xs text-status-error",children:Ke}),n.jsxs("button",{onClick:()=>de(lt.id),disabled:Le===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:xe("todo.mergeChainDesc"),children:[n.jsx(B5,{size:14}),Le===lt.id?"...":xe("todo.mergeChain")]})]})]}),n.jsxs("div",{className:"relative animate-fade-in",style:{animationDelay:`${pt*30}ms`,marginLeft:xt>0?`${xt*24}px`:void 0},children:[xt>0&&n.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),n.jsx(e8,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onStart:c,onStop:d,onDelete:p,onEdit:u,onMerge:x,onCleanup:C,onRetry:S,onContinue:g,onFix:_,onSchedule:w,onScheduleOnReset:y,resetsAt:E,onEvent:N,isInteractive:A.has(lt.id),onSendInput:D,isDragSource:q===lt.id,isDragging:q!==null,isDragOver:I===lt.id,isValidDropTarget:le(lt.id),onDragStart:ce,onDragEnd:Q,onDragOverTarget:V,onDragLeaveTarget:re,onDropTarget:te,onRemoveDependency:T?se:void 0,debugLogging:O,showTokenUsage:z,isChainMember:ht})]}),ft(pt+1)]},lt.id)})]})})()}),!Ue&&q&&((Je=e.find(qe=>qe.id===q))==null?void 0:Je.depends_on)&&n.jsxs("div",{className:"mt-3 border-2 border-dashed border-red-300 rounded-lg p-4 text-center text-sm text-red-400 transition-colors hover:border-red-400 hover:text-red-500 hover:bg-red-50",onDragOver:qe=>{qe.preventDefault(),qe.dataTransfer.dropEffect="move"},onDrop:qe=>{qe.preventDefault(),q&&T&&(fe.current=!0,T(q,null))},children:[n.jsx(dN,{size:20,className:"mx-auto mb-1"}),xe("dnd.dropToRemoveDep")]}),H&&n.jsx(Cr,{x:H.x,y:H.y,onClose:()=>$(null),children:n.jsxs("button",{onClick:()=>F(!0),className:an,children:[n.jsx(mn,{size:14}),xe("todos.add")]})})]})}const s8=[{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 r8(e){const s={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(!e)return s;const i=e.trim().split(/\s+/);if(i.length!==5)return{...s,mode:"custom"};const[a,h,f,,m]=i,o=a.match(/^\*\/(\d+)$/);if(o&&h==="*"&&f==="*"&&m==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&h==="*"&&f==="*"&&m==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const c=/^\d+$/.test(a)?parseInt(a):-1,d=/^\d+$/.test(h)?parseInt(h):-1;if(c<0||d<0)return{...s,mode:"custom"};if(f==="*"&&m!=="*"){const p=m.split(",").map(u=>{const x=parseInt(u);return isNaN(x)?-1:x}).filter(u=>u>=0);if(p.length>0)return{...s,mode:"weekly",weeklyDays:p,weeklyHour:d,weeklyMinute:c}}return/^\d+$/.test(f)&&m==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:d,monthlyMinute:c}:f==="*"&&m==="*"?{...s,mode:"daily",dailyHour:d,dailyMinute:c}:{...s,mode:"custom"}}function hy(e){switch(e.mode){case"minutes":return`*/${e.everyMinutes} * * * *`;case"hourly":return`${e.hourlyMinute} * * * *`;case"daily":return`${e.dailyMinute} ${e.dailyHour} * * *`;case"weekly":return`${e.weeklyMinute} ${e.weeklyHour} * * ${e.weeklyDays.sort((s,i)=>s-i).join(",")}`;case"monthly":return`${e.monthlyMinute} ${e.monthlyHour} ${e.monthlyDay} * *`;default:return""}}function i8({value:e,onChange:s}){const{t:i}=dt(),[a,h]=k.useState(()=>r8(e)),[f,m]=k.useState(e);k.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=hy(a);s(b)}},[a,f]);const o=b=>{h(C=>({...C,...b}))},c=b=>{h(C=>{const S=C.weeklyDays.includes(b)?C.weeklyDays.filter(g=>g!==b):[...C.weeklyDays,b];return{...C,weeklyDays:S.length>0?S:C.weeklyDays}})},d=[{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"}],p="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",u=(b,C,S,g)=>n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("select",{value:b,onChange:_=>S(parseInt(_.target.value)),className:`${p} w-16`,children:Array.from({length:24},(_,w)=>n.jsx("option",{value:w,children:String(w).padStart(2,"0")},w))}),n.jsx("span",{className:"text-warm-500 font-mono",children:":"}),n.jsx("select",{value:C,onChange:_=>g(parseInt(_.target.value)),className:`${p} w-16`,children:Array.from({length:12},(_,w)=>w*5).map(_=>n.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))})]}),x=a.mode==="custom"?f:hy(a);return n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map(b=>n.jsx("button",{type:"button",onClick:()=>o({mode:b.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===b.value?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:i(b.labelKey)},b.value))}),n.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[a.mode==="minutes"&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.every")}),n.jsx("select",{value:a.everyMinutes,onChange:b=>o({everyMinutes:parseInt(b.target.value)}),className:`${p} w-20`,children:[5,10,15,20,30].map(b=>n.jsx("option",{value:b,children:b},b))}),n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),n.jsx("select",{value:a.hourlyMinute,onChange:b=>o({hourlyMinute:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:12},(b,C)=>C*5).map(b=>n.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyDayAt")}),u(a.dailyHour,a.dailyMinute,b=>o({dailyHour:b}),b=>o({dailyMinute:b}))]}),a.mode==="weekly"&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"flex flex-wrap gap-1.5",children:s8.map(b=>n.jsx("button",{type:"button",onClick:()=>c(b.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${a.weeklyDays.includes(b.value)?"bg-amber-500 text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-amber-300"}`,children:i(b.labelKey)},b.value))}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.at")}),u(a.weeklyHour,a.weeklyMinute,b=>o({weeklyHour:b}),b=>o({weeklyMinute:b}))]})]}),a.mode==="monthly"&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),n.jsx("select",{value:a.monthlyDay,onChange:b=>o({monthlyDay:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:28},(b,C)=>C+1).map(b=>n.jsx("option",{value:b,children:b},b))}),n.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),u(a.monthlyHour,a.monthlyMinute,b=>o({monthlyHour:b}),b=>o({monthlyMinute:b}))]}),a.mode==="custom"&&n.jsxs("div",{children:[n.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:b=>m(b.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"}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&x&&n.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[n.jsxs("span",{className:"text-warm-400",children:[i("cron.expression"),":"]}),n.jsx("code",{className:"px-2 py-0.5 rounded bg-warm-100 text-warm-600 font-mono",children:x})]})]})}function a8(){const e=new Date;e.setHours(e.getHours()+1),e.setMinutes(0,0,0);const s=e.getFullYear(),i=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0"),h=String(e.getHours()).padStart(2,"0"),f=String(e.getMinutes()).padStart(2,"0");return`${s}-${i}-${a}T${h}:${f}`}function o8(e){const s=new Date(e),i=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),h=String(s.getDate()).padStart(2,"0"),f=String(s.getHours()).padStart(2,"0"),m=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${h}T${f}:${m}`}function B_({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:h="",initialCliTool:f,initialSkipIfRunning:m=!0,initialScheduleType:o="recurring",initialRunAt:c,projectCliTool:d="claude"}){const[p,u]=k.useState(i),[x,b]=k.useState(a),[C,S]=k.useState(h),[g,_]=k.useState(f||d||"claude"),[w,y]=k.useState(m),[E,T]=k.useState(o),[j,R]=k.useState(c?o8(c):a8()),{t:N}=dt(),D=E==="once",A=p.trim()&&(D?!!j:!!C.trim()),O=z=>{z.preventDefault(),A&&e({title:p.trim(),description:x.trim(),cronExpression:D?"":C.trim(),cliTool:g,skipIfRunning:w,scheduleType:E,runAt:D?new Date(j).toISOString():void 0})};return n.jsxs("form",{onSubmit:O,className:"card p-5 border-amber-500/30",children:[n.jsx("div",{className:"mb-3",children:n.jsx("input",{type:"text",placeholder:N("scheduleForm.titlePlaceholder"),value:p,onChange:z=>u(z.target.value),className:"input-field",autoFocus:!0})}),n.jsx("div",{className:"mb-3",children:n.jsx("textarea",{placeholder:N("scheduleForm.descPlaceholder"),value:x,onChange:z=>b(z.target.value),rows:3,className:"prompt-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"})}),n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.type")}),n.jsxs("div",{className:"flex gap-1.5",children:[n.jsx("button",{type:"button",onClick:()=>T("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${E==="recurring"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:N("schedule.recurring")}),n.jsx("button",{type:"button",onClick:()=>T("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${E==="once"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:N("schedule.once")})]})]}),D?n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.runAtLabel")}),n.jsx("input",{type:"datetime-local",value:j,onChange:z=>R(z.target.value),className:"input-field text-sm font-mono",min:new Date().toISOString().slice(0,16)})]}):n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.cronExpression")}),n.jsx(i8,{value:C,onChange:S})]}),n.jsx("div",{className:"mb-3 grid grid-cols-2 gap-3",children:n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("scheduleForm.cliTool")}),n.jsx("select",{value:g,onChange:z=>_(z.target.value),className:"input-field text-sm !py-2",children:wr.map(z=>n.jsx("option",{value:z.value,children:z.label},z.value))})]})}),!D&&n.jsx("div",{className:"mb-4",children:n.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:w,onChange:z=>y(z.target.checked),className:"rounded border-warm-300 text-amber-500 focus:ring-amber-500"}),N("schedule.skipIfRunning")]})}),n.jsxs("div",{className:"flex gap-3 justify-end",children:[n.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:N("scheduleForm.cancel")}),n.jsx("button",{type:"submit",disabled:!A,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function l8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:h,onMergeRun:f,onCleanupRun:m}){const[o,c]=k.useState(!1),[d,p]=k.useState(!1),[u,x]=k.useState([]),[b,C]=k.useState(!1),[S,g]=k.useState(!1),[_,w]=k.useState(null),{t:y}=dt(),E=async()=>{try{const H=await ff(e.id);x(H)}catch{}},T=async H=>{if(!(!H.todo_id||!f)){w(H.id);try{await f(H.todo_id),await E()}finally{w(null)}}},j=async H=>{if(!(!H.todo_id||!m)){w(H.id);try{await m(H.todo_id),await E()}finally{w(null)}}},R=e.schedule_type==="once",N=async()=>{if(!b)try{const H=await ff(e.id);x(H),C(!0)}catch{}},D=()=>{const H=!o;c(H),H&&N()},A=async()=>{g(!0);try{await h(e.id);const H=await ff(e.id);x(H),C(!0)}finally{g(!1)}};if(d)return n.jsx(B_,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:R?"":e.cron_expression,initialCliTool:e.cli_tool??void 0,initialSkipIfRunning:!!e.skip_if_running,initialScheduleType:e.schedule_type,initialRunAt:e.run_at??void 0,onSave:async H=>{await a(e.id,{title:H.title,description:H.description,cron_expression:H.cronExpression||void 0,cli_tool:H.cliTool,skip_if_running:H.skipIfRunning,schedule_type:H.scheduleType,run_at:H.runAt}),p(!1)},onCancel:()=>p(!1)});const O=e.is_active?"border-l-amber-500":"border-l-warm-300",z={triggered:"text-status-running",skipped:"text-status-warning",completed:"text-status-success",failed:"text-status-error"},P={triggered:y("schedule.runTriggered"),skipped:y("schedule.runSkipped"),completed:y("schedule.runCompleted"),failed:y("schedule.runFailed")},F=H=>H?new Date(H).toLocaleString():"";return n.jsxs("div",{className:`card border-l-4 ${O} overflow-hidden`,children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:D,children:[n.jsx("button",{className:"text-warm-400 hover:text-amber-500 flex-shrink-0 transition-colors",children:n.jsx(Ns,{size:14,className:`transition-transform duration-200 ${o?"rotate-90":""}`})}),n.jsx("span",{className:"flex-1 text-sm text-warm-800 font-medium truncate",children:e.title}),R?n.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-2xs font-mono font-medium bg-blue-500/10 text-blue-600 flex-shrink-0",children:[n.jsx(ai,{size:12}),F(e.run_at)]}):n.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-mono font-medium bg-amber-500/10 text-amber-600 flex-shrink-0",children:e.cron_expression}),n.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${R?"bg-blue-500/10 text-blue-600":"bg-amber-500/10 text-amber-600"}`,children:y(R?"schedule.once":"schedule.recurring")}),n.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${e.is_active?"bg-status-success/10 text-status-success":"bg-warm-200 text-warm-500"}`,children:e.is_active?y("schedule.active"):y("schedule.paused")}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:H=>H.stopPropagation(),children:[n.jsx("button",{onClick:A,disabled:S,className:"p-1.5 text-amber-500/60 hover:text-amber-500 hover:bg-amber-500/10 rounded-lg transition-colors disabled:opacity-30",title:y("schedule.trigger"),children:n.jsx(kr,{size:14})}),n.jsx("button",{onClick:()=>s(e.id,!e.is_active),className:`p-1.5 rounded-lg transition-colors ${e.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:e.is_active?y("schedule.pause"):y("schedule.activate"),children:e.is_active?n.jsx(Zm,{size:14}):n.jsx(_r,{size:14})}),n.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:y("schedule.edit"),children:n.jsx(ci,{size:14})}),n.jsx("button",{onClick:()=>i(e.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:y("schedule.delete"),children:n.jsx(Ln,{size:14})})]})]}),o&&n.jsxs("div",{className:"border-t border-warm-200 px-5 py-5 space-y-4 animate-fade-in bg-warm-50/50",children:[e.description&&n.jsx("div",{children:n.jsx("p",{className:"text-sm text-warm-600 whitespace-pre-wrap leading-relaxed",children:e.description})}),n.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[R?n.jsxs("span",{className:"badge bg-blue-500/10 text-blue-600 font-mono",children:[y("schedule.runAtLabel"),": ",F(e.run_at)]}):n.jsx("span",{className:"badge bg-amber-500/10 text-amber-600 font-mono",children:e.cron_expression}),!R&&e.skip_if_running?n.jsx("span",{className:"badge bg-status-info/10 text-status-info",children:y("schedule.skipIfRunning")}):null,n.jsxs("span",{className:"badge bg-warm-200 text-warm-600",children:[y("schedule.lastRun"),": ",e.last_run_at?new Date(e.last_run_at).toLocaleString():y("schedule.never")]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:y("schedule.runs")}),u.length===0?n.jsx("p",{className:"text-xs text-warm-400 italic",children:y("schedule.noRuns")}):n.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:u.map(H=>{const $=H.todo_id&&H.todo_status==="completed"&&!!H.todo_branch_name,q=H.todo_id&&H.todo_status!=="running"&&H.todo_status!=="pending"&&(H.todo_worktree_path||H.todo_branch_name),Y=_===H.id;return n.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[n.jsx("span",{className:`font-medium ${z[H.status]||"text-warm-500"}`,children:P[H.status]||H.status}),H.skipped_reason&&n.jsxs("span",{className:"text-warm-400",children:["(",H.skipped_reason,")"]}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[$&&f&&n.jsx("button",{onClick:()=>T(H),disabled:Y,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded transition-colors disabled:opacity-30",title:y("todo.merge"),children:n.jsx(cl,{size:12})}),q&&m&&n.jsx("button",{onClick:()=>j(H),disabled:Y,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded transition-colors disabled:opacity-30",title:y("todo.cleanup"),children:n.jsx(Ln,{size:12})})]}),n.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(H.started_at).toLocaleString()})]},H.id)})})]})]})]})}function c8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:h,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:c}){const[d,p]=k.useState(!1),[u,x]=k.useState(null),{t:b}=dt();return n.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{hi(C)||(C.preventDefault(),x({x:C.clientX,y:C.clientY}))},children:[n.jsxs("div",{className:"flex items-center justify-between mb-5",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:b("schedules.title")}),!d&&n.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[n.jsx(mn,{size:14}),b("schedules.add")]})]}),d&&n.jsx("div",{className:"mb-5 animate-slide-up",children:n.jsx(B_,{projectCliTool:s,onSave:async C=>{await i(C),p(!1)},onCancel:()=>p(!1)})}),n.jsx("div",{className:"space-y-3",children:e.length===0?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:X5,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,S)=>n.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${S*30}ms`},children:n.jsx(l8,{schedule:C,onToggle:a,onDelete:h,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:c})},C.id))}),u&&n.jsx(Cr,{x:u.x,y:u.y,onClose:()=>x(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>p(!0),children:[n.jsx(mn,{size:14}),b("schedules.add")]})})]})}function P_(e){const[s,i]=k.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return k.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(e),h=f=>i(f.matches);return i(a.matches),a.addEventListener("change",h),()=>a.removeEventListener("change",h)},[e]),s}const fy="__custom__";function u8({open:e,onClose:s,projectId:i,projectName:a,onPushed:h}){const{t:f}=dt(),[m,o]=k.useState(!1),[c,d]=k.useState(!1),[p,u]=k.useState(null),[x,b]=k.useState([]),[C,S]=k.useState("origin"),[g,_]=k.useState([]),[w,y]=k.useState([]),[E,T]=k.useState(!0),[j,R]=k.useState(!1);k.useEffect(()=>{if(!e)return;let H=!1;return o(!0),u(null),Promise.all([AN(i),om(i)]).then(([$,q])=>{var ee,Z;if(H)return;const Y=$.remotes||[];b(Y);const I=((ee=Y.find(X=>X.name==="origin"))==null?void 0:ee.name)||((Z=Y[0])==null?void 0:Z.name)||"origin";S(I);const B=q.branches||[],U=B.filter(X=>!X.remote),J=`remotes/${I}/`,W=B.filter(X=>X.remote&&X.name.startsWith(J)).map(X=>X.name.slice(J.length)).filter(X=>X&&X!=="HEAD");y(W);const oe=new Set(W);_(U.map(X=>{const G=oe.has(X.name);return{local:X.name,current:X.current,remote:X.name,customRemote:!1,setUpstream:!G,checked:X.current}}))}).catch($=>{H||u($ instanceof Error?$.message:"Failed to load remotes")}).finally(()=>{H||o(!1)}),()=>{H=!0}},[e,i]),k.useEffect(()=>{if(!e||!C)return;let H=!1;return om(i).then($=>{if(H)return;const q=`remotes/${C}/`,Y=($.branches||[]).filter(I=>I.remote&&I.name.startsWith(q)).map(I=>I.name.slice(q.length)).filter(I=>I&&I!=="HEAD");y(Y)}).catch(()=>{}),()=>{H=!0}},[C,i,e]);const N=g.length>0&&g.every(H=>H.checked),D=g.some(H=>H.checked),A=g.filter(H=>H.checked).length,O=k.useMemo(()=>{var H;return((H=x.find($=>$.name===C))==null?void 0:H.url)||""},[x,C]),z=(H,$)=>{_(q=>q.map(Y=>Y.local===H?{...Y,...$}:Y))},P=()=>{const H=!N;_($=>$.map(q=>({...q,checked:H})))},F=async()=>{u(null);const H=g.filter(q=>q.checked);if(H.length===0){u(f("git.pushDialog.errorRequireBranch"));return}const $=H.map(q=>({local:q.local,remote:(q.remote||"").trim()||q.local,setUpstream:q.setUpstream}));d(!0);try{await tp(i,{remote:C,branches:$,pushAllTags:E,force:j}),h==null||h(),s()}catch(q){u(q instanceof Error?q.message:"Push failed")}finally{d(!1)}};return n.jsx(Un,{open:e,onClose:c?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:c,children:n.jsxs("div",{className:"card p-5 space-y-4",children:[n.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),n.jsxs("select",{value:C,onChange:H=>S(H.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:m||c||x.length===0,children:[x.length===0&&n.jsx("option",{value:"origin",children:"origin"}),x.map(H=>n.jsx("option",{value:H.name,children:H.name},H.name))]}),n.jsx("input",{readOnly:!0,value:O,className:"input-field text-xs font-mono py-1.5 px-3 flex-1 cursor-default"})]}),n.jsxs("div",{children:[n.jsx("div",{className:"section-label mb-2",children:f("git.pushDialog.branchesHeader")}),n.jsx("div",{className:"rounded-xl border border-theme-border-strong overflow-hidden",children:n.jsx("div",{className:"overflow-auto max-h-[50vh]",children:n.jsxs("table",{className:"w-full text-sm border-collapse",children:[n.jsx("thead",{className:"sticky top-0 bg-warm-100 z-10",children:n.jsxs("tr",{children:[n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-12",children:f("git.pushDialog.colPush")}),n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colLocal")}),n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colRemote")}),n.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3 w-16",children:f("git.pushDialog.colTracking")})]})}),n.jsxs("tbody",{children:[m&&n.jsx("tr",{children:n.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!m&&g.length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.noLocalBranches")})}),g.map(H=>n.jsxs("tr",{className:"border-t border-theme-border/50 hover:bg-theme-hover/40 transition-colors",children:[n.jsx("td",{className:"py-2 px-3",children:n.jsx("input",{type:"checkbox",checked:H.checked,onChange:$=>z(H.local,{checked:$.target.checked}),disabled:c,className:"cursor-pointer"})}),n.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[H.local,H.current&&n.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),n.jsx("td",{className:"py-2 px-3",children:H.customRemote?n.jsx("input",{type:"text",value:H.remote,onChange:$=>z(H.local,{remote:$.target.value}),placeholder:H.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c}):n.jsxs("select",{value:w.includes(H.remote)||H.remote?H.remote:"",onChange:$=>{const q=$.target.value;q===fy?z(H.local,{customRemote:!0}):z(H.local,{remote:q})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c,children:[!w.includes(H.remote)&&H.remote&&n.jsxs("option",{value:H.remote,children:[H.remote," (",f("git.pushDialog.newBranch"),")"]}),w.map($=>n.jsx("option",{value:$,children:$},$)),n.jsx("option",{value:fy,children:f("git.pushDialog.customRemote")})]})}),n.jsx("td",{className:"py-2 px-3",children:n.jsx("input",{type:"checkbox",checked:H.setUpstream,onChange:$=>z(H.local,{setUpstream:$.target.checked}),disabled:c,className:"cursor-pointer"})})]},H.local))]})]})})})]}),n.jsxs("div",{className:"flex items-center gap-5 text-xs text-warm-700",children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:N,ref:H=>{H&&(H.indeterminate=!N&&D)},onChange:P,disabled:c||g.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:E,onChange:H=>T(H.target.checked),disabled:c,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:j,onChange:H=>R(H.target.checked),disabled:c,className:"cursor-pointer"}),n.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),p&&n.jsx("div",{className:"text-xs text-status-error font-medium",children:p}),n.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[n.jsx("button",{type:"button",onClick:s,disabled:c,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),n.jsx("button",{type:"button",onClick:F,disabled:c||m||A===0,className:"btn-primary btn-md",children:f(c?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function d8(e){switch(e){case"A":return{label:"A",color:"text-status-success"};case"D":return{label:"D",color:"text-status-error"};case"R":return{label:"R",color:"text-purple-500"};case"C":return{label:"C",color:"text-blue-500"};default:return{label:"M",color:"text-accent"}}}function Ku({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:h}){const{t:f}=dt();return n.jsxs("div",{className:"h-full flex flex-col",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[n.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:f("git.changedFiles")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"text-2xs text-warm-400",children:[e.length," ",f("git.files")]}),h&&n.jsx("span",{className:"text-2xs font-mono text-warm-400",children:h.substring(0,7)})]})]}),s?n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx("span",{className:"text-xs text-warm-400",children:f("git.loadingFiles")})}):e.length===0?n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx("span",{className:"text-xs text-warm-400",children:f("git.noFilesChanged")})}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(m=>{const o=d8(m.status),c=i===m.path;return n.jsxs("div",{onClick:()=>a(m.path),className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 transition-colors ${c?"bg-accent/10 border-l-2 border-accent":""}`,children:[n.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),n.jsxs("span",{className:"truncate flex-1 text-warm-600",title:m.path,children:[m.path.split("/").pop(),n.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:m.path.includes("/")?m.path.substring(0,m.path.lastIndexOf("/")):""})]}),n.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",m.additions]}),n.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",m.deletions]})]},m.path)})})]})}function Cl({diff:e,loading:s,selectedFile:i}){const{t:a}=dt(),[h,f]=k.useState(!0);return i?s?n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx("span",{className:"text-xs text-warm-400",children:a("git.loadingDiff")})}):n.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:i,children:i}),n.jsx("button",{onClick:()=>f(m=>!m),title:a("git.wrapLines")||"Wrap lines",className:`p-1 rounded shrink-0 hover:bg-gray-700 ${h?"text-accent":"text-gray-500"}`,children:n.jsx(iN,{size:14})})]}),n.jsx("div",{className:"flex-1 overflow-auto",children:n.jsx("div",{className:"p-3 font-mono text-xs leading-relaxed",children:e?(()=>{let m=0,o=0,c=!1;return e.split(`
665
665
  `).map((d,p)=>{if(d.startsWith("@@")){const C=/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(d);return C&&(m=parseInt(C[1],10),o=parseInt(C[2],10),c=!0),null}if(!c)return null;let u="text-gray-200",x=null,b=null;if(d.startsWith("+")&&!d.startsWith("+++"))u="text-gray-100 bg-green-500/20",b=o++;else if(d.startsWith("-")&&!d.startsWith("---"))u="text-gray-100 bg-red-500/20",x=m++;else if(d.startsWith(" "))x=m++,b=o++;else return null;return n.jsxs("div",{className:`flex items-start ${u}`,children:[n.jsx("span",{className:"select-none shrink-0 w-9 pr-2 text-right text-gray-500",children:x??""}),n.jsx("span",{className:"select-none shrink-0 w-9 pr-2 text-right text-gray-500",children:b??""}),n.jsx("span",{className:`flex-1 min-w-0 ${h?"whitespace-pre-wrap break-words":"whitespace-pre"}`,children:d||" "})]},p)})})():n.jsx("span",{className:"text-gray-400 italic",children:"No changes"})})})]}):n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx("span",{className:"text-sm text-warm-400",children:a("git.selectFileToViewDiff")})})}function h8(e){const s=e.split(`
666
666
  `),i=[];let a=[];const h=()=>{a.length&&(i.push({kind:"text",lines:a}),a=[])};let f=0;for(;f<s.length;){const m=s[f];if(m.startsWith("<<<<<<<")){h();const o=m.slice(7).trim()||"HEAD";f++;const c=[];for(;f<s.length&&!s[f].startsWith("|||||||")&&!s[f].startsWith("=======");)c.push(s[f]),f++;if(f<s.length&&s[f].startsWith("|||||||"))for(f++;f<s.length&&!s[f].startsWith("=======");)f++;f<s.length&&s[f].startsWith("=======")&&f++;const d=[];for(;f<s.length&&!s[f].startsWith(">>>>>>>");)d.push(s[f]),f++;f<s.length&&s[f].startsWith(">>>>>>>")&&f++,i.push({kind:"conflict",ours:c,theirs:d,label:o})}else a.push(m),f++}return h(),i}function f8(e,s){const i=[];return e.forEach((a,h)=>{if(a.kind==="text"){i.push(...a.lines);return}const f=s[h];f==="ours"?i.push(...a.ours):f==="theirs"?i.push(...a.theirs):f==="both"?i.push(...a.ours,...a.theirs):i.push(`<<<<<<< ${a.label}`,...a.ours,"=======",...a.theirs,">>>>>>> incoming")}),i.join(`
667
667
  `)}const m8=/^(<{7}|>{7})/m;function Rf({lines:e,tint:s}){return n.jsx("pre",{className:`px-3 py-1.5 font-mono text-xs leading-relaxed overflow-x-auto ${s}`,children:e.length?e.map((i,a)=>n.jsx("div",{children:i||" "},a)):n.jsx("div",{className:"italic opacity-50",children:"∅"})})}function p8({projectId:e,worktreePath:s,filePath:i,onResolved:a,onError:h}){const{t:f}=dt(),[m,o]=k.useState(null),[c,d]=k.useState({}),[p,u]=k.useState(!1),[x,b]=k.useState(""),[C,S]=k.useState(!0),[g,_]=k.useState(!1),[w,y]=k.useState(!1);k.useEffect(()=>{let F=!1;return S(!0),u(!1),d({}),y(!1),ON(e,i,s).then(H=>{F||o(h8(H.content))}).catch(()=>{F||y(!0)}).finally(()=>{F||S(!1)}),()=>{F=!0}},[e,s,i]);const E=k.useMemo(()=>m?m.map((F,H)=>F.kind==="conflict"?H:-1).filter(F=>F>=0):[],[m]),T=E.filter(F=>c[F]).length,j=E.length-T,R=k.useMemo(()=>m?f8(m,c):"",[m,c]),N=p?x:R,D=m8.test(N),A=g||D||!p&&j>0,O=(F,H)=>d($=>({...$,[F]:H})),z=()=>{b(R),u(!0)},P=async()=>{_(!0),h(null);try{await zN(e,i,N,s),a()}catch(F){h(F instanceof Error?F.message:"Failed to save resolution")}finally{_(!1)}};return n.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A] text-gray-200",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center gap-2",children:[n.jsx("span",{className:"text-xs font-mono text-gray-100 truncate flex-1",title:i,children:i}),!C&&!w&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:`text-2xs ${j>0?"text-amber-400":"text-emerald-400"}`,children:j>0?f("git.cr.unresolved").replace("{n}",String(j)):f("git.cr.allResolved")}),n.jsx("button",{className:"text-2xs px-2 py-0.5 rounded border border-gray-600 text-gray-300 hover:bg-gray-800",onClick:()=>p?u(!1):z(),children:f(p?"git.cr.guided":"git.cr.manual")}),n.jsx("button",{className:"text-2xs px-2 py-0.5 rounded bg-accent text-white disabled:opacity-40",disabled:A,onClick:P,title:D?f("git.cr.markersRemain"):void 0,children:g?"…":f("git.cr.save")})]})]}),C?n.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-gray-400",children:f("git.loadingDiff")}):w?n.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-status-error",children:f("git.cr.loadFailed")}):p?n.jsx("textarea",{className:"flex-1 w-full bg-[#1A1A1A] text-gray-100 font-mono text-xs p-3 resize-none focus:outline-none",value:x,onChange:F=>b(F.target.value),spellCheck:!1}):E.length===0?n.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-gray-400",children:f("git.cr.noConflicts")}):n.jsx("div",{className:"flex-1 overflow-auto",children:m.map((F,H)=>F.kind==="text"?n.jsx(Rf,{lines:F.lines,tint:"text-gray-500"},H):n.jsxs("div",{className:"my-1 border-y border-gray-700",children:[n.jsx("div",{className:"flex items-center gap-1 px-3 py-1 bg-gray-800/60",children:["ours","theirs","both"].map($=>n.jsx("button",{onClick:()=>O(H,$),className:`text-2xs px-2 py-0.5 rounded border transition-colors ${c[H]===$?"bg-accent text-white border-accent":"border-gray-600 text-gray-300 hover:bg-gray-700"}`,children:f($==="ours"?"git.acceptOurs":$==="theirs"?"git.acceptTheirs":"git.cr.both")},$))}),n.jsxs("div",{className:c[H]==="theirs"?"opacity-40":"",children:[n.jsx("div",{className:"px-3 pt-1 text-2xs text-emerald-400",children:f("git.cr.ours")}),n.jsx(Rf,{lines:F.ours,tint:"text-gray-100 bg-emerald-500/10"})]}),n.jsxs("div",{className:c[H]==="ours"?"opacity-40":"",children:[n.jsx("div",{className:"px-3 pt-1 text-2xs text-sky-400",children:f("git.cr.theirs")}),n.jsx(Rf,{lines:F.theirs,tint:"text-gray-100 bg-sky-500/10"})]})]},H))})]})}const Ra=["#B08A3E","#4B8DFF","#7A8797","#5E748A","#8B8178","#667085","#78909C","#9A8F7F"];function g8(e){const s=new Map;e.forEach((h,f)=>s.set(h.hash,f));const i=[],a=[];for(let h=0;h<e.length;h++){const f=e[h];let m=i.indexOf(f.hash);m===-1&&(m=i.indexOf(null),m===-1&&(m=i.length,i.push(null))),i[m]=null;const o=Ra[m%Ra.length],c=[];for(let d=0;d<f.parentHashes.length;d++){const p=f.parentHashes[d],u=s.get(p);if(u===void 0)continue;let x=i.indexOf(p);if(x!==-1)c.push({fromLane:m,toLane:x,toRow:u,color:Ra[x%Ra.length]});else if(d===0)i[m]=p,c.push({fromLane:m,toLane:m,toRow:u,color:o});else{let b=i.indexOf(null);b===-1&&(b=i.length,i.push(null)),i[b]=p,c.push({fromLane:m,toLane:b,toRow:u,color:Ra[b%Ra.length]})}}a.push({lane:m,color:o,connections:c})}return a}function x8({refStr:e}){const s=e.startsWith("HEAD"),i=e.startsWith("origin/")||e.includes("remotes/"),a=e.startsWith("tag: ");let h=e,f="";return a?(h=e.replace("tag: ",""),f="bg-violet-500/10 text-violet-600 dark:text-violet-400"):s?(h=e.replace("HEAD -> ",""),f="bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 font-semibold"):i?f="bg-sky-500/10 text-sky-700 dark:text-sky-400":f="bg-amber-500/10 text-amber-700 dark:text-amber-400",n.jsx("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-2xs font-medium whitespace-nowrap ${f}`,children:h})}const ii=32,Pi=16,v8=4,b8=10;function y8({graphNodes:e,totalRows:s}){const a=(Math.min(b8,e.reduce((h,f)=>{const m=f.connections.reduce((o,c)=>Math.max(o,c.fromLane,c.toLane),0);return Math.max(h,f.lane,m)},0)+1)+1)*Pi+8;return n.jsxs("svg",{width:a,height:s*ii,className:"shrink-0",style:{minWidth:a},children:[e.map((h,f)=>h.connections.map((m,o)=>{const c=m.fromLane*Pi+Pi/2+4,d=f*ii+ii/2,p=m.toLane*Pi+Pi/2+4,u=m.toRow*ii+ii/2;if(c===p)return n.jsx("line",{x1:c,y1:d,x2:p,y2:u,stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`);{const x=(d+u)/2;return n.jsx("path",{d:`M${c},${d} C${c},${x} ${p},${x} ${p},${u}`,fill:"none",stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`)}})),e.map((h,f)=>{const m=h.lane*Pi+Pi/2+4,o=f*ii+ii/2;return n.jsx("circle",{cx:m,cy:o,r:v8,fill:h.color,stroke:"white",strokeWidth:1.5},`dot-${f}`)})]})}function w8({projectId:e,projectName:s,onRefresh:i,busy:a,setBusy:h,branches:f,statusFiles:m,worktreePath:o}){const{t:c}=dt(),[d,p]=k.useState(null),[u,x]=k.useState(""),[b,C]=k.useState(""),[S,g]=k.useState(null),_=()=>{p(null),x(""),C(""),g(null)},w=async O=>{h(!0),g(null);try{await O(),_(),i()}catch(z){g(z instanceof Error?z.message:"Error")}finally{h(!1)}},y=m.some(O=>O.index!==" "&&O.index!=="?"),E=({label:O,onClick:z,icon:P,badge:F})=>n.jsxs("button",{onClick:z,disabled:a,className:"flex flex-col items-center gap-0.5 px-2.5 py-1.5 rounded hover:bg-warm-50 transition-colors disabled:opacity-50 relative",title:O,children:[n.jsx("div",{className:"h-5 w-5 flex items-center justify-center text-warm-500",children:P}),n.jsx("span",{className:"text-2xs text-warm-600 whitespace-nowrap",children:O}),F!==void 0&&F>0&&n.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:F})]}),T=({title:O,children:z})=>n.jsx(Un,{open:!0,onClose:_,size:"sm",children:n.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:[n.jsx("span",{className:"text-sm font-semibold text-warm-700",children:O}),n.jsx("button",{onClick:_,className:"text-warm-400 hover:text-warm-600",children:n.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),n.jsxs("div",{className:"p-4 space-y-3",children:[S&&n.jsx("p",{className:"text-status-error text-xs",children:S}),z]})]})}),j=f.filter(O=>!O.remote),R=f.find(O=>!O.remote&&O.current),N=m.length,D=(R==null?void 0:R.behind)??0,A=(R==null?void 0:R.ahead)??0;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1 border-b border-warm-100 overflow-x-auto",children:[n.jsx(E,{label:c("git.commit"),onClick:()=>p("commit"),icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v6m3-3H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z"})}),badge:N}),n.jsx(E,{label:c("git.pull"),onClick:()=>w(()=>Qw(e)),icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.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:D}),n.jsx(E,{label:c("git.push"),onClick:()=>p("push"),icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.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:A}),n.jsx(E,{label:c("git.fetch"),onClick:()=>w(()=>Zw(e)),icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.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"})})}),n.jsx("div",{className:"w-px h-8 bg-warm-200 mx-1"}),n.jsx(E,{label:c("git.branch"),onClick:()=>p("branch"),icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.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"})})}),n.jsx(E,{label:c("git.merge"),onClick:()=>p("merge"),icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.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"})})}),n.jsx(E,{label:c("git.stash"),onClick:()=>p("stash"),icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.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"})})}),n.jsx(E,{label:c("git.discard"),onClick:()=>{m.length!==0&&confirm(c("git.confirmDiscard"))&&w(()=>$N(e,void 0,!0,o))},icon:n.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:n.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"})})}),n.jsx(E,{label:c("git.tag"),onClick:()=>p("tag"),icon:n.jsxs("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:[n.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"}),n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]})})]}),n.jsx(u8,{open:d==="push",onClose:_,projectId:e,projectName:s,onPushed:i}),d==="commit"&&n.jsxs(T,{title:c("git.commit"),children:[n.jsx("textarea",{className:"w-full border border-warm-200 rounded px-3 py-2 text-sm resize-none focus:outline-none focus:ring-1 focus:ring-accent",rows:3,placeholder:c("git.commitMessage"),value:u,onChange:O=>x(O.target.value),autoFocus:!0}),n.jsxs("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!u.trim()||!y,onClick:()=>w(()=>Jw(e,u.trim(),o)),children:[c("git.commit")," ",!y&&n.jsxs("span",{className:"text-xs opacity-70 ml-1",children:["(",c("git.staged"),": 0)"]})]})]}),d==="branch"&&n.jsxs(T,{title:c("git.newBranch"),children:[n.jsx("input",{className:"w-full border border-warm-200 rounded px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:c("git.branchName"),value:u,onChange:O=>x(O.target.value),autoFocus:!0}),n.jsx("div",{className:"flex gap-2",children:n.jsx("button",{className:"flex-1 btn-primary text-sm py-2",disabled:a||!u.trim(),onClick:()=>w(()=>e1(e,u.trim())),children:c("git.create")})}),j.length>0&&n.jsxs("div",{className:"border-t border-warm-100 pt-2 mt-1",children:[n.jsx("p",{className:"text-2xs text-warm-400 uppercase tracking-wider mb-1",children:c("git.selectBranch")}),n.jsx("div",{className:"max-h-32 overflow-y-auto space-y-px",children:j.filter(O=>!O.current).map(O=>n.jsxs("div",{className:"flex items-center justify-between px-2 py-1 text-xs hover:bg-warm-50 rounded group",children:[n.jsx("button",{className:"truncate text-warm-600 hover:text-accent",onClick:()=>w(()=>cm(e,O.name)),children:O.name}),n.jsx("button",{className:"text-warm-300 hover:text-status-error opacity-0 group-hover:opacity-100 transition-opacity text-2xs",onClick:()=>{confirm(`Delete branch ${O.name}?`)&&w(()=>lm(e,O.name))},children:c("git.delete")})]},O.name))})]})]}),d==="merge"&&n.jsxs(T,{title:c("git.merge"),children:[n.jsx("p",{className:"text-xs text-warm-500",children:c("git.selectBranch")}),n.jsx("div",{className:"max-h-48 overflow-y-auto space-y-px",children:j.filter(O=>!O.current).map(O=>n.jsx("button",{className:"w-full text-left px-3 py-2 text-sm hover:bg-warm-50 rounded text-warm-600 truncate",disabled:a,onClick:()=>w(()=>t1(e,O.name)),children:O.name},O.name))})]}),d==="stash"&&n.jsx(_8,{projectId:e,busy:a,exec:w,inputValue:u,setInputValue:x}),d==="tag"&&n.jsxs(T,{title:c("git.tag"),children:[n.jsx("input",{className:"w-full border border-warm-200 rounded px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:c("git.tagName"),value:u,onChange:O=>x(O.target.value),autoFocus:!0}),n.jsx("input",{className:"w-full border border-warm-200 rounded px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:c("git.tagMessage"),value:b,onChange:O=>C(O.target.value)}),n.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!u.trim(),onClick:()=>w(()=>n1(e,u.trim(),b.trim()||void 0)),children:c("git.create")})]})]})}function _8({projectId:e,busy:s,exec:i,inputValue:a,setInputValue:h}){const{t:f}=dt(),[m,o]=k.useState([]);return k.useEffect(()=>{HN(e).then(o).catch(()=>{})},[e]),n.jsx(Un,{open:!0,onClose:()=>h(""),size:"sm",children:n.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[n.jsx("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:n.jsx("span",{className:"text-sm font-semibold text-warm-700",children:f("git.stash")})}),n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{className:"flex-1 border border-warm-200 rounded px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:f("git.stashMessage"),value:a,onChange:c=>h(c.target.value),autoFocus:!0}),n.jsx("button",{className:"btn-primary text-sm px-3 py-2",disabled:s,onClick:()=>i(()=>IN(e,a.trim()||void 0)),children:f("git.stash")})]}),m.length>0?n.jsx("div",{className:"space-y-px max-h-40 overflow-y-auto",children:m.map(c=>n.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 text-xs hover:bg-warm-50 rounded",children:[n.jsx("span",{className:"text-warm-600 truncate flex-1",children:c.message||`stash@{${c.index}}`}),n.jsx("button",{className:"text-accent hover:underline text-[11px] ml-2 shrink-0",disabled:s,onClick:()=>i(()=>FN(e,c.index)),children:f("git.stashPop")})]},c.index))}):n.jsx("p",{className:"text-xs text-warm-400 text-center",children:f("git.noStashes")})]})]})})}function my(e,s){if(e==="?"&&s==="?")return{label:"U",color:"text-warm-400",type:"untracked"};const a=e!==" "&&e!=="?",h=a?e:s;let f="text-accent",m=h;return h==="A"?f="text-status-success":h==="D"?f="text-status-error":h==="R"?f="text-violet-600 dark:text-violet-400":h==="C"?f="text-blue-500":(f="text-accent",m="M"),{label:m,color:f,type:a?"staged":"unstaged"}}function py({file:e,pane:s,selected:i,checked:a,onClick:h,onToggleCheck:f}){const m=s==="staged"?my(e.index," "):my(" ",e.working_dir==="?"?"?":e.working_dir),o=s==="unstaged"&&e.index==="?"&&e.working_dir==="?"?{label:"U",color:"text-warm-400"}:m;return n.jsxs("div",{onClick:h,className:`flex items-center gap-2 px-3 py-1 cursor-pointer text-xs select-none transition-colors ${i?"bg-accent/15 text-accent":"hover:bg-warm-50 text-warm-700"}`,children:[n.jsx("input",{type:"checkbox",checked:a,onChange:f,onClick:c=>c.stopPropagation(),className:"h-3 w-3 shrink-0 cursor-pointer","aria-label":e.path}),n.jsx("span",{className:`shrink-0 w-4 h-4 flex items-center justify-center rounded text-[10px] font-mono font-bold ${s==="staged"?"bg-emerald-500/15":"bg-warm-200"} ${o.color}`,children:s==="staged"||o.label==="U"?"+":"−"}),n.jsx("span",{className:"truncate flex-1",title:e.path,children:e.path})]})}function S8({diff:e,loading:s,file:i}){const{t:a}=dt();if(!i)return n.jsx("div",{className:"h-full flex items-center justify-center bg-[#1A1A1A] text-gray-400",children:n.jsx("span",{className:"text-sm",children:a("git.selectFileForDiff")})});if(s)return n.jsx("div",{className:"h-full flex items-center justify-center bg-[#1A1A1A] text-gray-400",children:n.jsx("span",{className:"text-xs",children:a("git.loadingDiff")})});const h=i.index==="?"&&i.working_dir==="?";return n.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center gap-2",children:[n.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:i.path,children:i.path}),h&&n.jsx("span",{className:"text-2xs text-gray-400 italic",children:a("git.untrackedNewFile")})]}),n.jsx("div",{className:"flex-1 overflow-auto",children:e?n.jsx("pre",{className:"p-3 font-mono text-xs leading-relaxed",children:e.split(`
668
668
  `).map((f,m)=>{let o="text-gray-200";return f.startsWith("+")&&!f.startsWith("+++")?o="text-gray-100 bg-green-500/20":f.startsWith("-")&&!f.startsWith("---")?o="text-gray-100 bg-red-500/20":f.startsWith("@@")?o="text-blue-400":f.startsWith("diff ")&&(o="text-amber-300 font-bold"),n.jsx("div",{className:o,children:f||" "},m)})}):n.jsx("div",{className:"p-6 text-center text-xs text-gray-400 italic",children:a(h?"git.untrackedNewFile":"git.noFilesChanged")})})]})}function k8({projectId:e,worktreePath:s,branchName:i,files:a,conflicted:h,busy:f,setBusy:m,onRefresh:o,onError:c,isMobile:d=!1}){const{t:p}=dt(),u=k.useMemo(()=>new Set(h),[h]),x=k.useMemo(()=>a.filter(ee=>u.has(ee.path)),[a,u]),b=k.useMemo(()=>a.filter(ee=>ee.index!==" "&&ee.index!=="?"&&!u.has(ee.path)),[a,u]),C=k.useMemo(()=>a.filter(ee=>ee.working_dir!==" "&&ee.working_dir!=="?"||ee.index==="?"&&ee.working_dir==="?").filter(ee=>!(ee.index!==" "&&ee.index!=="?"&&ee.working_dir===" ")).filter(ee=>!u.has(ee.path)),[a,u]),[S,g]=k.useState(null),[_,w]=k.useState(()=>new Set),[y,E]=k.useState(()=>new Set),[T,j]=k.useState(""),[R,N]=k.useState(!1),[D,A]=k.useState(""),[O,z]=k.useState(!1),[P,F]=k.useState(!1);k.useEffect(()=>{w(ee=>{const Z=new Set(b.map(me=>me.path));let X=!1;const G=new Set;return ee.forEach(me=>{Z.has(me)?G.add(me):X=!0}),X?G:ee})},[b]),k.useEffect(()=>{E(ee=>{const Z=new Set(C.map(me=>me.path));let X=!1;const G=new Set;return ee.forEach(me=>{Z.has(me)?G.add(me):X=!0}),X?G:ee})},[C]);const H=k.useCallback(ee=>{w(Z=>{const X=new Set(Z);return X.has(ee)?X.delete(ee):X.add(ee),X})},[]),$=k.useCallback(ee=>{E(Z=>{const X=new Set(Z);return X.has(ee)?X.delete(ee):X.add(ee),X})},[]),q=k.useRef(null),[Y,I]=k.useState(()=>{if(typeof window>"u")return .55;const ee=window.localStorage.getItem("clitrigger:git:working-pct"),Z=ee?parseFloat(ee):NaN;return isNaN(Z)?.55:Math.max(.3,Math.min(.8,Z))});k.useEffect(()=>{localStorage.setItem("clitrigger:git:working-pct",String(Y))},[Y]);const B=k.useCallback(ee=>{if(!q.current)return;const Z=q.current.getBoundingClientRect(),X=(ee-Z.left)/Z.width;I(Math.max(.3,Math.min(.8,X)))},[]),U=k.useMemo(()=>{if(!S)return null;const[ee,Z]=S.split("::");return ee==="conflict"?x.find(X=>X.path===Z)||null:ee==="staged"?b.find(X=>X.path===Z)||null:C.find(X=>X.path===Z)||null},[S,x,b,C]),J=S?S.split("::")[0]:null;k.useEffect(()=>{S||(x.length>0?g(`conflict::${x[0].path}`):b.length>0?g(`staged::${b[0].path}`):C.length>0&&g(`unstaged::${C[0].path}`))},[S,x,b,C]),k.useEffect(()=>{if(!S)return;const[ee,Z]=S.split("::");(ee==="conflict"?x:ee==="staged"?b:C).some(G=>G.path===Z)||g(null)},[S,x,b,C]),k.useEffect(()=>{if(!U||!J){j("");return}let ee=!1;return N(!0),GN(e,U.path,J==="staged",s).then(Z=>{ee||j(Z.diff)}).catch(()=>{ee||j("")}).finally(()=>{ee||N(!1)}),()=>{ee=!0}},[e,s,U,J]);const W=async ee=>{m(!0),c(null);try{await ee(),o()}catch(Z){c(Z instanceof Error?Z.message:"Operation failed")}finally{m(!1)}},oe=async()=>{if(!(!D.trim()||b.length===0)){F(!0),m(!0),c(null);try{if(await Jw(e,D.trim(),s),O)try{await tp(e,s?{worktreePath:s}:void 0)}catch(ee){c(ee instanceof Error?`Commit OK, push failed: ${ee.message}`:"Push failed")}A(""),o()}catch(ee){c(ee instanceof Error?ee.message:"Commit failed")}finally{F(!1),m(!1)}}};return a.length===0?n.jsx("div",{className:"h-full flex items-center justify-center bg-theme-bg",children:n.jsx("span",{className:"text-sm text-warm-400",children:p("git.workingTreeClean")})}):n.jsxs("div",{ref:q,className:`h-full flex min-h-0 ${d?"flex-col":""}`,children:[n.jsxs("div",{style:d?void 0:{width:`${Y*100}%`,minWidth:360},className:`shrink-0 flex flex-col min-h-0 ${d?"h-1/2":""}`,children:[x.length>0&&n.jsxs("div",{className:"flex flex-col min-h-0 border-b border-warm-200",style:{flex:"1 1 0"},children:[n.jsx("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center shrink-0 bg-status-error/10",children:n.jsxs("span",{className:"text-xs font-semibold text-status-error",children:[p("git.conflicts")," ",n.jsxs("span",{className:"text-warm-400 font-normal",children:["(",x.length,")"]})]})}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:x.map(ee=>n.jsxs("div",{onClick:()=>g(`conflict::${ee.path}`),className:`flex items-center gap-2 px-3 py-1 cursor-pointer text-xs select-none transition-colors ${S===`conflict::${ee.path}`?"bg-accent/15 text-accent":"hover:bg-warm-50 text-warm-700"}`,children:[n.jsx("span",{className:"shrink-0 w-4 h-4 flex items-center justify-center rounded text-[10px] font-mono font-bold bg-status-error/15 text-status-error",children:"C"}),n.jsx("span",{className:"truncate flex-1",title:ee.path,children:ee.path}),n.jsx("button",{className:"shrink-0 text-2xs px-1.5 py-0.5 rounded border border-warm-300 text-warm-600 hover:bg-warm-100 disabled:opacity-40",disabled:f,onClick:Z=>{Z.stopPropagation(),W(()=>Jv(e,ee.path,"ours",s))},children:p("git.acceptOurs")}),n.jsx("button",{className:"shrink-0 text-2xs px-1.5 py-0.5 rounded border border-warm-300 text-warm-600 hover:bg-warm-100 disabled:opacity-40",disabled:f,onClick:Z=>{Z.stopPropagation(),W(()=>Jv(e,ee.path,"theirs",s))},children:p("git.acceptTheirs")})]},`c-${ee.path}`))})]}),n.jsxs("div",{className:"flex flex-col min-h-0",style:{flex:"1 1 0"},children:[n.jsxs("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center justify-between shrink-0 bg-warm-50",children:[n.jsxs("span",{className:"text-xs font-semibold text-warm-700",children:[p("git.stagedFiles")," ",n.jsxs("span",{className:"text-warm-400 font-normal",children:["(",b.length,")"]})]}),n.jsx("button",{className:"text-2xs text-warm-500 hover:text-warm-700 disabled:opacity-40",disabled:f||b.length===0,onClick:()=>{const ee=_.size>0?b.filter(Z=>_.has(Z.path)).map(Z=>Z.path):b.map(Z=>Z.path);ee.length!==0&&W(()=>MN(e,ee,s))},children:_.size>0?`${p("git.unstageSelectedShort")} (${_.size})`:p("git.unstageAllShort")})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:b.length===0?n.jsx("div",{className:"p-3 text-2xs text-warm-400 italic",children:"—"}):b.map(ee=>n.jsx(py,{file:ee,pane:"staged",selected:S===`staged::${ee.path}`,checked:_.has(ee.path),onClick:()=>g(`staged::${ee.path}`),onToggleCheck:()=>H(ee.path)},`s-${ee.path}`))})]}),n.jsxs("div",{className:"flex flex-col min-h-0 border-t border-warm-200",style:{flex:"1 1 0"},children:[n.jsxs("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center justify-between shrink-0 bg-warm-50",children:[n.jsxs("span",{className:"text-xs font-semibold text-warm-700",children:[p("git.unstagedFiles")," ",n.jsxs("span",{className:"text-warm-400 font-normal",children:["(",C.length,")"]})]}),n.jsx("button",{className:"text-2xs text-warm-500 hover:text-warm-700 disabled:opacity-40",disabled:f||C.length===0,onClick:()=>{const ee=y.size>0?C.filter(Z=>y.has(Z.path)).map(Z=>Z.path):C.map(Z=>Z.path);ee.length!==0&&W(()=>RN(e,ee,s))},children:y.size>0?`${p("git.stageSelectedShort")} (${y.size})`:p("git.stageAllShort")})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:C.length===0?n.jsx("div",{className:"p-3 text-2xs text-warm-400 italic",children:"—"}):C.map(ee=>n.jsx(py,{file:ee,pane:"unstaged",selected:S===`unstaged::${ee.path}`,checked:y.has(ee.path),onClick:()=>g(`unstaged::${ee.path}`),onToggleCheck:()=>$(ee.path)},`u-${ee.path}`))})]}),n.jsxs("div",{className:"border-t border-warm-200 shrink-0 bg-theme-bg",children:[n.jsx("div",{className:"p-2",children:n.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:p("git.commitMessage"),value:D,onChange:ee=>A(ee.target.value),onKeyDown:ee=>{(ee.metaKey||ee.ctrlKey)&&ee.key==="Enter"&&oe()},disabled:P})}),n.jsxs("div",{className:"px-3 py-2 border-t border-warm-200 flex items-center gap-3",children:[n.jsxs("label",{className:"flex items-center gap-1.5 text-2xs text-warm-600 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:O,onChange:ee=>z(ee.target.checked),className:"h-3 w-3",disabled:P}),p("git.pushImmediately").replace("{remote}",`origin/${i||"main"}`)]}),n.jsx("button",{className:"ml-auto btn-primary text-xs px-3 py-1.5 disabled:opacity-50",onClick:oe,disabled:P||f||!D.trim()||b.length===0||x.length>0,children:P?"...":p("git.commitButton")})]})]})]}),!d&&n.jsx(cu,{axis:"x",onResize:B}),n.jsx("div",{className:`flex-1 ${d?"min-h-0 border-t border-warm-200":"min-w-0"}`,children:J==="conflict"&&U?n.jsx(p8,{projectId:e,worktreePath:s,filePath:U.path,onResolved:o,onError:c}):n.jsx(S8,{diff:T,loading:R,file:U})})]})}function C8({branches:e,tags:s,stashCount:i,projectId:a,busy:h,setBusy:f,onRefresh:m,onError:o}){const{t:c}=dt(),[d,p]=k.useState(new Set(["local","remote"])),[u,x]=k.useState(null),[b,C]=k.useState(null),[S,g]=k.useState(""),_=k.useRef(null),[w,y]=k.useState([]),[E,T]=k.useState(null);k.useEffect(()=>{um(a).then(F=>y(F.worktrees)).catch(()=>{})},[a]);const j=k.useCallback(()=>{um(a).then(F=>y(F.worktrees)).catch(()=>{})},[a]);k.useEffect(()=>{j()},[e,j]),k.useEffect(()=>{if(!u)return;const F=$=>{_.current&&!_.current.contains($.target)&&x(null)},H=()=>x(null);return document.addEventListener("mousedown",F),document.addEventListener("scroll",H,!0),()=>{document.removeEventListener("mousedown",F),document.removeEventListener("scroll",H,!0)}},[u]),k.useEffect(()=>{if(!u||!_.current)return;const F=_.current.getBoundingClientRect();let{x:H,y:$}=u;H+F.width>window.innerWidth&&(H=window.innerWidth-F.width-8),$+F.height>window.innerHeight&&($=window.innerHeight-F.height-8),(H!==u.x||$!==u.y)&&x({...u,x:H,y:$})},[u]);const R=async(F,H)=>{f(!0),o(null),x(null);try{await F(),m(),H&&H()}catch($){o($ instanceof Error?$.message:"Error")}finally{f(!1)}},N=(F,H,$,q)=>{F.preventDefault(),F.stopPropagation(),x({branch:H,isRemote:$,isCurrent:q,x:F.clientX,y:F.clientY})},D=F=>{p(H=>{const $=new Set(H);return $.has(F)?$.delete(F):$.add(F),$})},A=e.filter(F=>!F.remote),O=e.filter(F=>F.remote),z=({id:F,label:H,count:$})=>n.jsxs("button",{onClick:()=>D(F),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:[n.jsx("svg",{className:`h-3 w-3 transition-transform ${d.has(F)?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),H,n.jsx("span",{className:"text-warm-400 font-normal ml-auto",children:$})]}),P=({label:F,onClick:H,danger:$})=>n.jsx("button",{className:`w-full text-left px-3 py-1.5 hover:bg-theme-hover transition-colors ${$?"text-status-error":"text-theme-text"}`,disabled:h,onClick:H,children:F});return n.jsxs("div",{className:"space-y-1",children:[n.jsx(z,{id:"local",label:c("git.branches"),count:A.length}),d.has("local")&&n.jsx("div",{className:"pl-1 space-y-px",children:A.map(F=>n.jsxs("div",{className:`flex items-center gap-1.5 px-2 py-1 rounded text-xs truncate cursor-context-menu select-none ${F.current?"text-sky-700 dark:text-sky-300 font-semibold bg-sky-500/10":"text-warm-600 hover:bg-warm-50"}`,onContextMenu:H=>N(H,F.name,!1,!!F.current),children:[F.current&&n.jsx("svg",{className:"h-3 w-3 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})}),n.jsx("span",{className:"truncate",children:F.name}),(!!F.ahead||!!F.behind)&&n.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:[!!F.ahead&&n.jsxs("span",{className:"text-emerald-700 dark:text-emerald-400",title:`${F.ahead} ${c("git.ahead")}`,children:[F.ahead,"↑"]}),!!F.behind&&n.jsxs("span",{className:"text-amber-700 dark:text-amber-400",title:`${F.behind} ${c("git.behind")}`,children:[F.behind,"↓"]})]})]},F.name))}),O.length>0&&n.jsxs(n.Fragment,{children:[n.jsx(z,{id:"remote",label:c("git.remotes"),count:O.length}),d.has("remote")&&n.jsx("div",{className:"pl-1 space-y-px",children:O.map(F=>n.jsx("div",{className:"px-2 py-1 text-xs text-warm-500 truncate hover:bg-warm-50 rounded cursor-context-menu select-none",onContextMenu:H=>N(H,F.name,!0,!1),children:F.name.replace("remotes/","")},F.name))})]}),s.length>0&&n.jsxs(n.Fragment,{children:[n.jsx(z,{id:"tags",label:c("git.tags"),count:s.length}),d.has("tags")&&n.jsx("div",{className:"pl-1 space-y-px",children:s.map(F=>n.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-xs text-warm-500 truncate hover:bg-warm-50 rounded",children:[n.jsxs("svg",{className:"h-3 w-3 text-violet-600/80 dark:text-violet-400/80 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[n.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"}),n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]}),F]},F))})]}),w.length>0&&n.jsxs(n.Fragment,{children:[n.jsx(z,{id:"worktrees",label:c("git.worktrees"),count:w.length}),d.has("worktrees")&&n.jsx("div",{className:"pl-1 space-y-px",children:w.map(F=>n.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",children:[n.jsx("svg",{className:"h-3 w-3 text-amber-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.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"})}),n.jsx("span",{className:"truncate flex-1",title:F.path,children:F.branch}),n.jsx("button",{className:"opacity-0 group-hover:opacity-100 shrink-0 p-0.5 text-warm-400 hover:text-status-error transition-all",disabled:h||E===F.path,title:c("git.cleanupWorktree"),onClick:()=>{confirm(c("git.confirmCleanupWorktree").replace("{name}",F.branch))&&(T(F.path),f(!0),o(null),eb(a,F.path,F.branch).then(()=>{y(H=>H.filter($=>$.path!==F.path)),m()}).catch(H=>o(H instanceof Error?H.message:"Error")).finally(()=>{T(null),f(!1)}))},children:E===F.path?n.jsx("svg",{className:"h-3 w-3 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.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"})}):n.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.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"})})})]},F.path))})]}),i>0&&n.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:[c("git.stashes"),n.jsx("span",{className:"text-warm-400 font-normal ml-auto",children:i})]}),u&&en.createPortal(n.jsxs("div",{ref:_,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:u.x,top:u.y},children:[!u.isCurrent&&!u.isRemote&&n.jsx(P,{label:`${c("git.checkout")} ${u.branch}`,onClick:()=>R(()=>cm(a,u.branch))}),!u.isCurrent&&u.isRemote&&n.jsx(P,{label:`${c("git.checkoutRemote")} ${u.branch.replace(/^(remotes\/)?origin\//,"")}`,onClick:()=>{const F=u.branch.replace(/^(remotes\/)?origin\//,"");R(()=>cm(a,F))}}),!u.isCurrent&&n.jsx(P,{label:`${c("git.mergeInto")} ${u.branch}`,onClick:()=>R(()=>t1(a,u.branch))}),!u.isCurrent&&!u.isRemote&&n.jsx(P,{label:`${c("git.rebaseOnto")} ${u.branch}`,onClick:()=>R(()=>UN(a,u.branch))}),n.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),n.jsx(P,{label:`${c("git.fetch")}`,onClick:()=>R(()=>Zw(a))}),!u.isRemote&&n.jsxs(n.Fragment,{children:[n.jsx(P,{label:`${c("git.pull")}`,onClick:()=>R(()=>Qw(a))}),n.jsx(P,{label:`${c("git.push")}`,onClick:()=>R(()=>tp(a))})]}),!u.isRemote&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),n.jsx(P,{label:`${c("git.renameBranch")} ${u.branch}...`,onClick:()=>{C(u.branch),g(u.branch),x(null)}}),!u.isCurrent&&(()=>{const F=w.find($=>$.branch===u.branch);if(F)return n.jsx(P,{danger:!0,label:`${c("git.deleteWorktreeAndBranch")} ${u.branch}`,onClick:()=>{confirm(c("git.confirmDeleteWorktreeAndBranch").replace("{name}",u.branch))?R(()=>eb(a,F.path,u.branch)):x(null)}});const H=u.branch;return n.jsx(P,{danger:!0,label:`${c("git.delete")} ${H}`,onClick:()=>{if(!confirm(c("git.confirmDelete").replace("{name}",H))){x(null);return}R(async()=>{try{await lm(a,H)}catch($){const q=$ instanceof Error?$.message:"";if(/not fully merged/i.test(q)&&confirm(c("git.confirmForceDelete").replace("{name}",H))){await lm(a,H,!0);return}throw $}})}})})()]})]}),document.body),b&&n.jsx(Un,{open:!0,onClose:()=>C(null),size:"sm",children:n.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:[n.jsx("span",{className:"text-sm font-semibold text-warm-700",children:c("git.renameBranch")}),n.jsx("button",{onClick:()=>C(null),className:"text-warm-400 hover:text-warm-600",children:n.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsxs("p",{className:"text-xs text-warm-500",children:[b," →"]}),n.jsx("input",{className:"w-full border border-warm-200 rounded px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent bg-transparent",placeholder:c("git.newBranchName"),value:S,onChange:F=>g(F.target.value),onKeyDown:F=>{if(F.key==="Enter"&&S.trim()&&S.trim()!==b){const H=b;R(()=>Qv(a,H,S.trim()),()=>C(null))}},autoFocus:!0}),n.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:h||!S.trim()||S.trim()===b,onClick:()=>{const F=b;R(()=>Qv(a,F,S.trim()),()=>C(null))},children:c("git.rename")})]})]})})]})}function j8(e){const s=new Date(e);if(isNaN(s.getTime()))return"";const i=String(s.getFullYear()).slice(2),a=String(s.getMonth()+1).padStart(2,"0"),h=String(s.getDate()).padStart(2,"0"),f=String(s.getHours()).padStart(2,"0"),m=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${h} ${f}:${m}`}function gy({view:e,onChange:s,fileChangeCount:i,orientation:a="vertical"}){const{t:h}=dt(),f=a==="horizontal",m=({id:o,label:c,badge:d})=>{const p=e===o;return n.jsxs("button",{onClick:()=>s(o),className:`flex items-center gap-2 px-3 py-2 text-xs font-medium rounded transition-colors ${f?"flex-1 justify-center":"w-full"} ${p?"bg-accent/10 text-accent shadow-soft ring-1 ring-inset ring-accent/20":"text-warm-600 hover:bg-warm-200/60"}`,children:[n.jsx("span",{className:`${f?"":"flex-1 text-left"} truncate`,children:c}),d!==void 0&&d>0&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${p?"bg-accent/10 text-accent":"bg-warm-200 text-warm-600"}`,children:d})]})};return f?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(m,{id:"fileStatus",label:h("git.viewFileStatus"),badge:i}),n.jsx(m,{id:"history",label:h("git.viewHistory")})]}):n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"px-2 text-[10px] font-bold text-warm-400 uppercase tracking-widest flex items-center gap-2",children:[n.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.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"})}),h("git.workspace")]}),n.jsxs("div",{className:"space-y-0.5",children:[n.jsx(m,{id:"fileStatus",label:h("git.viewFileStatus"),badge:i}),n.jsx(m,{id:"history",label:h("git.viewHistory")})]})]})}function cu({axis:e,onResize:s}){return n.jsx("div",{onMouseDown:i=>{i.preventDefault(),document.body.style.cursor=e==="x"?"col-resize":"row-resize",document.body.style.userSelect="none";const a=f=>s(f.clientX,f.clientY),h=()=>{document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",h)};window.addEventListener("mousemove",a),window.addEventListener("mouseup",h)},role:"separator","aria-orientation":e==="x"?"vertical":"horizontal",className:e==="x"?"w-1 mx-1 shrink-0 cursor-col-resize bg-warm-200/60 hover:bg-accent transition-colors rounded":"h-1 my-0.5 shrink-0 cursor-row-resize bg-warm-200/60 hover:bg-accent transition-colors"})}function E8({x:e,y:s,message:i,onDismiss:a}){const h=k.useRef(null),[f,m]=k.useState(null);return k.useEffect(()=>{if(!h.current)return;const o=h.current.getBoundingClientRect(),c=o.width,d=o.height,p=window.innerWidth,u=window.innerHeight;let x=s-d-12;x<8&&(x=s+12),x+d>u-8&&(x=u-d-8);let b=e-c/2;b<8&&(b=8),b+c>p-8&&(b=p-c-8),m({top:x,left:b})},[e,s]),en.createPortal(n.jsx("div",{onClick:a,onTouchStart:a,className:"fixed inset-0 z-tooltip",children:n.jsx("div",{ref:h,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:f?{top:f.top,left:f.left,opacity:1}:{top:0,left:0,opacity:0},children:i})}),document.body)}function uu(e,s,i){return Math.max(s,Math.min(i,e))}function Mf(e,s,i,a){if(typeof window>"u")return s;const h=window.localStorage.getItem(e);if(!h)return s;const f=parseFloat(h);return isNaN(f)?s:uu(f,i,a)}function N8({project:e,refreshTrigger:s,onEvent:i,sendMessage:a,connected:h}){const{t:f}=dt(),m=P_("(max-width: 767px)"),[o,c]=k.useState(!1),[d,p]=k.useState(null),u=k.useRef({timer:null,startX:0,startY:0,fired:!1}),[x,b]=k.useState(()=>{if(typeof window>"u")return"history";const Oe=window.localStorage.getItem(`git-view:${e.id}`);return Oe==="fileStatus"||Oe==="history"?Oe:"history"});k.useEffect(()=>{typeof window<"u"&&window.localStorage.setItem(`git-view:${e.id}`,x)},[x,e.id]);const[C,S]=k.useState([]),[g,_]=k.useState(!0),[w,y]=k.useState(!1),[E,T]=k.useState(!0),[j,R]=k.useState(null),[N,D]=k.useState([]),[A,O]=k.useState([]),[z,P]=k.useState(0),[F,H]=k.useState([]),[$,q]=k.useState(""),[Y,I]=k.useState(null),[B,U]=k.useState([]),[J,W]=k.useState({merging:!1,rebasing:!1,conflicted:[]}),[oe,ee]=k.useState(!1),[Z,X]=k.useState(null),[G,me]=k.useState(null),[ge,xe]=k.useState([]),[he,Ie]=k.useState(!1),[Fe,be]=k.useState(null),[Ue,Pe]=k.useState(""),[tt,ke]=k.useState(!1),[pe,Ne]=k.useState(null),Le=k.useRef(null),ze=k.useRef(null),Ke=k.useRef(null),Ve=k.useRef(!1),de=k.useRef(null),fe=k.useRef(null),ce=k.useRef(null),[Q,V]=k.useState(()=>Mf("clitrigger:git:sidebar-w",224,180,480)),[re,te]=k.useState(()=>Mf("clitrigger:git:detail-h-pct",.5,.2,.8)),[se,le]=k.useState(()=>Mf("clitrigger:git:detail-fl-w",240,160,500));k.useEffect(()=>{localStorage.setItem("clitrigger:git:sidebar-w",String(Q))},[Q]),k.useEffect(()=>{localStorage.setItem("clitrigger:git:detail-h-pct",String(re))},[re]),k.useEffect(()=>{localStorage.setItem("clitrigger:git:detail-fl-w",String(se))},[se]);const ve=k.useCallback(Oe=>{if(!de.current)return;const ie=de.current.getBoundingClientRect();V(uu(Oe-ie.left,180,480))},[]),Ce=k.useCallback((Oe,ie)=>{if(!fe.current)return;const _e=fe.current.getBoundingClientRect();te(uu((_e.bottom-ie)/_e.height,.2,.8))},[]),De=k.useCallback(Oe=>{if(!ce.current)return;const ie=ce.current.getBoundingClientRect();le(uu(Oe-ie.left,160,500))},[]),Qe=k.useCallback(async()=>{try{const Oe=await om(e.id);D(Oe.branches),O(Oe.tags),P(Oe.stashCount)}catch{}},[e.id]),ut=k.useCallback(async()=>{try{const Oe=await Xw(e.id,Y??void 0);H(Oe.files),q(Oe.branch||""),W({merging:!!Oe.mergeInProgress,rebasing:!!Oe.rebaseInProgress,conflicted:Oe.conflicted??[]})}catch{}},[e.id,Y]),ot=k.useCallback(async(Oe,ie=!1)=>{if(!Ve.current){Ve.current=!0,y(!0),R(null);try{const _e=await TN(e.id,Oe,50);S(je=>ie?_e.commits:[...je,..._e.commits]),_(_e.hasMore)}catch(_e){R(_e instanceof Error?_e.message:"Failed to fetch git log")}finally{y(!1),T(!1),Ve.current=!1}}},[e.id]),Je=k.useCallback(()=>{S([]),_(!0),T(!0),me(null),xe([]),be(null),Pe(""),ot(0,!0),Qe(),ut()},[ot,Qe,ut]),qe=k.useCallback(async Oe=>{ee(!0),X(null);try{await Oe()}catch(ie){X(ie instanceof Error?ie.message:"Operation failed")}finally{ee(!1),Je()}},[Je]),ft=k.useCallback(async Oe=>{if((G==null?void 0:G.hash)===Oe.hash){me(null),xe([]),be(null),Pe("");return}me(Oe),be(null),Pe(""),Ie(!0);try{const ie=await VN(e.id,Oe.hash);if(xe(ie.files),ie.files.length>0){const _e=ie.files[0].path;be(_e),ke(!0);try{const je=await Zv(e.id,Oe.hash,_e);Pe(je.diff)}catch{Pe("")}finally{ke(!1)}}}catch{xe([])}finally{Ie(!1)}},[e.id,G==null?void 0:G.hash]),lt=k.useCallback(async Oe=>{if(G){be(Oe),ke(!0);try{const ie=await Zv(e.id,G.hash,Oe);Pe(ie.diff)}catch{Pe("")}finally{ke(!1)}}},[e.id,G]);k.useEffect(()=>{if(!pe)return;const Oe=_e=>{Le.current&&!Le.current.contains(_e.target)&&Ne(null)},ie=()=>Ne(null);return document.addEventListener("mousedown",Oe),document.addEventListener("scroll",ie,!0),()=>{document.removeEventListener("mousedown",Oe),document.removeEventListener("scroll",ie,!0)}},[pe]),k.useEffect(()=>{if(!pe||!Le.current)return;const Oe=Le.current.getBoundingClientRect();let{x:ie,y:_e}=pe;ie+Oe.width>window.innerWidth&&(ie=window.innerWidth-Oe.width-8),_e+Oe.height>window.innerHeight&&(_e=window.innerHeight-Oe.height-8),(ie!==pe.x||_e!==pe.y)&&Ne({...pe,x:ie,y:_e})},[pe]);const xt=k.useCallback(async Oe=>{ee(!0),X(null),Ne(null);try{await Oe(),Je()}catch(ie){X(ie instanceof Error?ie.message:"Operation failed")}finally{ee(!1)}},[Je]),pt=k.useCallback(()=>{u.current.timer!==null&&(window.clearTimeout(u.current.timer),u.current.timer=null)},[]),st=k.useCallback((Oe,ie)=>{m&&(pt(),u.current.startX=Oe.clientX,u.current.startY=Oe.clientY,u.current.fired=!1,u.current.timer=window.setTimeout(()=>{if(u.current.fired=!0,u.current.timer=null,p({message:ie,x:u.current.startX,y:u.current.startY}),typeof navigator<"u"&&typeof navigator.vibrate=="function")try{navigator.vibrate(10)}catch{}},500))},[m,pt]),ht=k.useCallback(Oe=>{if(!m||u.current.timer===null)return;const ie=Oe.clientX-u.current.startX,_e=Oe.clientY-u.current.startY;ie*ie+_e*_e>64&&pt()},[m,pt]),Re=k.useCallback(()=>{m&&pt()},[m,pt]);k.useEffect(()=>{if(!d)return;const Oe=()=>p(null);return window.addEventListener("scroll",Oe,!0),window.addEventListener("resize",Oe),()=>{window.removeEventListener("scroll",Oe,!0),window.removeEventListener("resize",Oe)}},[d]),k.useEffect(()=>{m||p(null)},[m]),k.useEffect(()=>{ot(0,!0),Qe()},[ot,Qe]),k.useEffect(()=>{ut()},[ut]),k.useEffect(()=>{let Oe=!1;return um(e.id).then(ie=>{Oe||U(ie.worktrees)}).catch(()=>{Oe||U([])}),()=>{Oe=!0}},[e.id,N]),k.useEffect(()=>{Y&&!B.some(Oe=>Oe.path===Y)&&I(null)},[B,Y]),k.useEffect(()=>{s&&s>0&&Je()},[s]),k.useEffect(()=>{if(!(!h||!a))return a({type:"git:watch",projectId:e.id}),()=>a({type:"git:unwatch",projectId:e.id})},[h,a,e.id]),k.useEffect(()=>{if(i)return i(Oe=>{Oe.type==="git:changed"&&Oe.projectId===e.id&&(ut(),Qe())})},[i,e.id,ut,Qe]),k.useEffect(()=>{const Oe=ze.current;if(!Oe)return;const ie=new IntersectionObserver(_e=>{_e[0].isIntersecting&&g&&!Ve.current&&C.length>0&&ot(C.length)},{rootMargin:"200px"});return ie.observe(Oe),()=>ie.disconnect()},[g,C.length,ot]);const ct=k.useMemo(()=>g8(C),[C]);return n.jsxs("div",{className:"animate-fade-in flex flex-col",style:{height:"calc(100vh - 260px)",minHeight:"400px"},children:[n.jsx("div",{className:"card mb-2 overflow-hidden",children:n.jsx(w8,{projectId:e.id,projectName:e.name,onRefresh:Je,busy:oe,setBusy:ee,branches:N,statusFiles:F,worktreePath:Y??void 0})}),(J.merging||J.rebasing||J.conflicted.length>0)&&n.jsxs("div",{className:"mb-2 px-3 py-2 bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-400 text-xs flex items-center gap-2 rounded border border-amber-200 dark:border-amber-800",children:[n.jsx("span",{className:"font-semibold shrink-0",children:J.merging?f("git.conflictMergeInProgress"):J.rebasing?f("git.conflictRebaseInProgress"):f("git.conflicts")}),n.jsx("span",{className:"flex-1 min-w-0 truncate",children:J.conflicted.length>0?f("git.conflictBanner").replace("{n}",String(J.conflicted.length)):f("git.conflictAllResolved")}),x!=="fileStatus"&&J.conflicted.length>0&&n.jsx("button",{className:"shrink-0 px-2 py-1 rounded border border-amber-300 dark:border-amber-700 hover:bg-amber-100 dark:hover:bg-amber-900/40",onClick:()=>b("fileStatus"),children:f("git.viewConflicts")}),(J.merging||J.rebasing)&&n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"shrink-0 px-2 py-1 rounded border border-amber-300 dark:border-amber-700 hover:bg-amber-100 dark:hover:bg-amber-900/40 disabled:opacity-40",disabled:oe||J.conflicted.length>0,onClick:()=>qe(()=>BN(e.id)),children:f("git.conflictContinue")}),n.jsx("button",{className:"shrink-0 px-2 py-1 rounded border border-amber-300 dark:border-amber-700 hover:bg-amber-100 dark:hover:bg-amber-900/40 disabled:opacity-40",disabled:oe,onClick:()=>{window.confirm(f("git.confirmConflictAbort"))&&qe(()=>PN(e.id))},children:f("git.conflictAbort")})]})]}),Z&&n.jsxs("div",{className:"mb-2 px-3 py-2 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-xs flex items-center justify-between rounded border border-red-200 dark:border-red-800",children:[n.jsx("span",{children:Z}),n.jsx("button",{onClick:()=>X(null),className:"ml-2 shrink-0 hover:text-red-800 dark:hover:text-red-300",children:"×"})]}),n.jsxs("div",{ref:de,className:`flex flex-1 min-h-0 ${m?"flex-col gap-2":""}`,children:[n.jsxs("div",{style:m?void 0:{width:Q},className:`shrink-0 flex flex-col gap-2 ${m?"":"min-h-0"}`,children:[m?n.jsxs("div",{className:"card p-2 flex items-center gap-2",children:[n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(gy,{view:x,onChange:b,fileChangeCount:F.length,orientation:"horizontal"})}),n.jsxs("button",{onClick:()=>c(Oe=>!Oe),className:"btn-ghost text-xs flex items-center gap-1 shrink-0 px-3 py-2","aria-expanded":o,children:[n.jsx("svg",{className:`h-3 w-3 transition-transform ${o?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})}),f("git.branches")]})]}):n.jsx("div",{className:"card p-3 shrink-0",children:n.jsx(gy,{view:x,onChange:b,fileChangeCount:F.length})}),(!m||o)&&n.jsx("div",{className:`card overflow-y-auto p-3 ${m?"":"flex-1 min-h-0"}`,style:m?{maxHeight:"40vh"}:void 0,children:n.jsx(C8,{branches:N,tags:A,stashCount:z,projectId:e.id,busy:oe,setBusy:ee,onRefresh:Je,onError:X})})]}),!m&&n.jsx(cu,{axis:"x",onResize:ve}),n.jsx("div",{className:"card flex-1 overflow-hidden flex flex-col min-h-0",children:x==="fileStatus"?n.jsxs(n.Fragment,{children:[B.length>0&&n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-warm-100 shrink-0",children:[n.jsx("span",{className:"text-2xs text-warm-400 uppercase tracking-wider shrink-0",children:f("git.statusTarget")}),n.jsxs("select",{className:"text-xs border border-warm-200 rounded 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:Oe=>I(Oe.target.value||null),children:[n.jsx("option",{value:"",children:f("git.mainCheckout")}),B.map(Oe=>n.jsx("option",{value:Oe.path,children:Oe.branch},Oe.path))]})]}),n.jsx(k8,{projectId:e.id,worktreePath:Y??void 0,branchName:$,files:F,conflicted:J.conflicted,busy:oe,setBusy:ee,onRefresh:Je,onError:X,isMobile:m})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-warm-100",children:[n.jsx("span",{className:"text-sm font-semibold text-warm-700",children:f("git.commitHistory")}),n.jsxs("button",{onClick:Je,disabled:w,className:"btn-ghost text-xs flex items-center gap-1.5",children:[n.jsx("svg",{className:`h-3.5 w-3.5 ${w?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.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"})}),f("git.refresh")]})]}),n.jsxs("div",{className:`flex items-center py-1.5 border-b border-warm-50 text-2xs text-warm-400 uppercase tracking-wider ${m?"px-3":"px-4"}`,children:[!m&&n.jsx("div",{className:"w-24 shrink-0",children:f("git.graph")}),n.jsx("div",{className:"flex-1 min-w-0",children:f("git.description")}),n.jsx("div",{className:"w-14 text-right shrink-0",children:f("git.date")}),!m&&n.jsx("div",{className:"shrink-0 ml-2",children:f("git.author")}),n.jsx("div",{className:"w-16 text-right shrink-0",children:f("git.hash")})]}),j&&n.jsx("div",{className:"p-6 text-center",children:n.jsx("p",{className:"text-status-error text-sm",children:j})}),E&&!j&&n.jsx("div",{className:"p-6 text-center",children:n.jsx("p",{className:"text-warm-500 text-sm",children:f("detail.loading")})}),!E&&!j&&C.length===0&&n.jsx("div",{className:"p-6 text-center",children:n.jsx("p",{className:"text-warm-500 text-sm",children:f("git.noCommits")})}),C.length>0&&n.jsxs("div",{ref:fe,className:"flex-1 flex flex-col min-h-0",children:[n.jsxs("div",{className:"overflow-y-auto",ref:Ke,style:G?{flex:`${(1-re)*100} 1 0`,minHeight:0}:{flex:"1 1 0",minHeight:0},children:[n.jsxs("div",{className:"relative flex",children:[!m&&n.jsx("div",{className:"shrink-0 sticky left-0",children:n.jsx(y8,{graphNodes:ct,totalRows:C.length})}),n.jsx("div",{className:"flex-1 min-w-0",children:C.map(Oe=>{const ie=(G==null?void 0:G.hash)===Oe.hash;return n.jsxs("div",{onClick:_e=>{if(u.current.fired){_e.stopPropagation(),u.current.fired=!1;return}ft(Oe)},onPointerDown:_e=>st(_e,Oe.message),onPointerMove:ht,onPointerUp:Re,onPointerCancel:Re,onContextMenu:_e=>{_e.preventDefault(),!m&&Ne({commit:Oe,x:_e.clientX,y:_e.clientY})},className:`flex items-center px-3 cursor-pointer transition-colors border-b border-warm-50/20 ${ie?"bg-accent/10 border-l-2 border-l-accent":"hover:bg-warm-50/50"}`,style:{height:ii,...m?{touchAction:"pan-y",WebkitTouchCallout:"none",userSelect:"none"}:null},children:[n.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[Oe.refs.length>0&&n.jsx("div",{className:"flex items-center gap-1 shrink-0",children:Oe.refs.map((_e,je)=>n.jsx(x8,{refStr:_e},je))}),n.jsx("span",{className:"text-xs text-warm-700 truncate",title:Oe.message,children:Oe.message})]}),n.jsx("div",{className:"w-28 text-right shrink-0",children:n.jsx("span",{className:"text-[11px] font-mono text-warm-600",title:Oe.date,children:j8(Oe.date)})}),!m&&n.jsx("div",{className:"shrink-0 ml-2",children:n.jsx("span",{className:"text-[11px] text-warm-600",children:Oe.author})}),n.jsx("div",{className:"w-16 text-right shrink-0",children:n.jsx("span",{className:"text-[11px] font-mono text-warm-600 cursor-pointer hover:text-accent transition-colors",title:Oe.hash,onClick:_e=>{_e.stopPropagation(),navigator.clipboard.writeText(Oe.hash)},children:Oe.hash.substring(0,7)})})]},Oe.hash)})})]}),n.jsx("div",{ref:ze,className:"h-8 flex items-center justify-center",children:w&&n.jsx("span",{className:"text-xs text-warm-400",children:f("git.loadMore")})})]}),G&&n.jsxs(n.Fragment,{children:[n.jsx(cu,{axis:"y",onResize:Ce}),n.jsxs("div",{ref:ce,className:`flex min-h-0 ${m?"flex-col":""}`,style:{flex:`${re*100} 1 0`,minHeight:0},children:[n.jsx("div",{style:m?void 0:{width:se},className:`shrink-0 overflow-hidden ${m?"h-1/2":""}`,children:n.jsx(Ku,{files:ge,loading:he,selectedFile:Fe,onFileClick:lt,commitHash:G.hash})}),!m&&n.jsx(cu,{axis:"x",onResize:De}),n.jsx("div",{className:`flex-1 overflow-hidden bg-warm-900 ${m?"min-h-0 border-t border-warm-200":"min-w-0"}`,children:n.jsx(Cl,{diff:Ue,loading:tt,selectedFile:Fe})})]})]})]})]})})]}),d&&n.jsx(E8,{x:d.x,y:d.y,message:d.message,onDismiss:()=>p(null)}),pe&&en.createPortal((()=>{const Oe=pe.commit,ie=Oe.hash.substring(0,7),_e=(we,rt,Me=!1)=>n.jsx("button",{className:`w-full text-left px-3 py-1.5 hover:bg-theme-hover transition-colors disabled:opacity-40 ${Me?"text-status-error":"text-theme-text"}`,disabled:oe,onClick:rt,children:we}),je=we=>_e(`${f("git.resetHere")} (${we})`,()=>{const rt=we==="hard"?f("git.confirmResetHard").replace("{hash}",ie):f("git.confirmReset").replace("{hash}",ie).replace("{mode}",we);if(!window.confirm(rt)){Ne(null);return}xt(()=>KN(e.id,Oe.hash,we))},we==="hard");return n.jsxs("div",{ref:Le,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:pe.x,top:pe.y},children:[_e(f("git.copySha"),()=>{navigator.clipboard.writeText(Oe.hash),Ne(null)}),n.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),_e(f("git.createBranchHere"),()=>{const we=window.prompt(f("git.promptBranchName").replace("{hash}",ie));we&&we.trim()?xt(()=>e1(e.id,we.trim(),Oe.hash)):Ne(null)}),_e(f("git.createTagHere"),()=>{const we=window.prompt(f("git.promptTagName").replace("{hash}",ie));we&&we.trim()?xt(()=>n1(e.id,we.trim(),void 0,Oe.hash)):Ne(null)}),n.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),_e(f("git.cherryPick"),()=>{if(!window.confirm(f("git.confirmCherryPick").replace("{hash}",ie))){Ne(null);return}xt(async()=>{(await qN(e.id,Oe.hash)).conflict&&b("fileStatus")})}),_e(f("git.revertCommit"),()=>{if(!window.confirm(f("git.confirmRevert").replace("{hash}",ie))){Ne(null);return}xt(async()=>{(await WN(e.id,Oe.hash)).conflict&&b("fileStatus")})}),n.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),je("soft"),je("mixed"),je("hard")]})})(),document.body)]})}function xy(e,s=!1){return gt(`/api/projects/${e}/svn-status${s?"?showUpdates=true":""}`)}function L8(e,s=0,i=50){const a=new URLSearchParams({skip:String(s),limit:String(i)});return gt(`/api/projects/${e}/svn-log?${a}`)}function D8(e,s){return gt(`/api/projects/${e}/svn-commit-files?revision=${encodeURIComponent(s)}`)}function T8(e,s,i,a){const h=new URLSearchParams({revision:s});return i&&h.set("file",i),a&&h.set("status",a),gt(`/api/projects/${e}/svn-commit-diff?${h}`)}function R8(e,s){const i=new URLSearchParams;s&&i.set("file",s);const a=i.toString();return gt(`/api/projects/${e}/svn-diff${a?`?${a}`:""}`)}function M8(e,s){const i=new URLSearchParams;s&&i.set("file",s);const a=i.toString();return gt(`/api/projects/${e}/svn-properties${a?`?${a}`:""}`)}function A8(e,s,i,a){return et(`/api/projects/${e}/svn-propset`,{name:s,value:i,file:a})}function O8(e,s){return et(`/api/projects/${e}/svn-add`,{files:s})}function z8(e,s){return et(`/api/projects/${e}/svn-revert`,{files:s})}function B8(e,s,i=!1){return et(`/api/projects/${e}/svn-delete`,{files:s,keepLocal:i})}function P8(e,s,i="working"){return et(`/api/projects/${e}/svn-resolve`,{files:s,accept:i})}function I8(e,s,i){return et(`/api/projects/${e}/svn-changelist`,{name:s,files:i})}function F8(e,s,i){return et(`/api/projects/${e}/svn-commit`,{message:s,files:i})}function vy(e,s){return et(`/api/projects/${e}/svn-update`,{revision:s})}function H8(e){return et(`/api/projects/${e}/svn-cleanup`,{})}const Af=new Map,vr=e=>e.working_dir.trim()||"?",$8=e=>e==="A"?"text-status-success":e==="D"?"text-status-error":e==="M"?"text-accent":e==="C"?"text-status-error":e==="?"?"text-warm-400":"text-amber-500",by="clitrigger:svn:commit-message-h",Of=60,zf=280,U8=160;function Tm(e,s,i){return Math.max(s,Math.min(i,e))}function W8(e,s,i,a){if(typeof window>"u")return s;const h=window.localStorage.getItem(e);if(!h)return s;const f=Number.parseFloat(h);return Number.isFinite(f)?Tm(f,i,a):s}function q8({project:e,refreshTrigger:s}){const{t:i}=dt(),[a,h]=k.useState("modifications"),[f,m]=k.useState(null),[o,c]=k.useState(null),[d,p]=k.useState(null);k.useEffect(()=>{let Re=!1;return op().then(ct=>{if(Re)return;const Oe=ct.find(ie=>ie.tool==="svn");p(Oe?Oe.installed:null)}).catch(()=>{}),()=>{Re=!0}},[]);const[u,x]=k.useState(()=>Af.get(e.id)??null),[b,C]=k.useState(!1),[S,g]=k.useState(!1),[_,w]=k.useState(new Set),[y,E]=k.useState(null),[T,j]=k.useState(""),[R,N]=k.useState(!1),[D,A]=k.useState(""),[O,z]=k.useState(!1),P=k.useCallback(Re=>{Af.set(e.id,Re),x(Re),w(ct=>{const Oe=new Set(Re.files.map(_e=>_e.path)),ie=new Set;return ct.forEach(_e=>Oe.has(_e)&&ie.add(_e)),ie}),E(ct=>ct&&!Re.files.some(Oe=>Oe.path===ct)?null:ct)},[e.id]),F=k.useCallback(async()=>{const Re=Af.has(e.id);Re||C(!0),m(null);try{P(await xy(e.id))}catch(ct){m(ct instanceof Error?ct.message:"Failed to load SVN status")}finally{Re||C(!1)}},[e.id,P]);k.useEffect(()=>{F()},[F,s]);const H=k.useCallback(async()=>{g(!0),m(null),c(null);try{const Re=await xy(e.id,!0);P(Re),c(Re.behind>0?i("svn.behindCount").replace("{n}",String(Re.behind)):i("svn.upToDate"))}catch(Re){m(Re instanceof Error?Re.message:"Failed to contact server")}finally{g(!1)}},[e.id,P,i]);k.useEffect(()=>{if(!y){j("");return}let Re=!1;return N(!0),R8(e.id,y).then(ct=>{Re||j(ct.diff)}).catch(ct=>{Re||m(ct instanceof Error?ct.message:"Diff failed")}).finally(()=>{Re||N(!1)}),()=>{Re=!0}},[e.id,y]);const $=Re=>{w(ct=>{const Oe=new Set(ct);return Oe.has(Re)?Oe.delete(Re):Oe.add(Re),Oe})},q=(Re,ct)=>{w(Oe=>{const ie=new Set(Oe);return Re.forEach(_e=>{ct?ie.add(_e):ie.delete(_e)}),ie})},Y=async(Re,ct)=>{z(!0),m(null),c(null);try{await Re(),ct&&c(ct),await F()}catch(Oe){m(Oe instanceof Error?Oe.message:"Action failed")}finally{z(!1)}},I=Re=>Y(()=>O8(e.id,Re)),B=Re=>Y(()=>z8(e.id,Re)),U=Re=>Y(()=>B8(e.id,Re)),J=(Re,ct)=>Y(()=>P8(e.id,Re,ct)),W=(Re,ct)=>Y(()=>I8(e.id,Re,ct)),[oe,ee]=k.useState(null),Z=Re=>{Re.conflicts.length>0?ee(Re.conflicts):c(Re.revision?i("svn.updateSuccess").replace("{rev}",Re.revision):i("svn.update"))},X=()=>Y(async()=>{Z(await vy(e.id))}),[G,me]=k.useState(!1),[ge,xe]=k.useState(""),he=()=>{const Re=ge.trim();Re&&(me(!1),Y(async()=>{Z(await vy(e.id,Re)),xe("")}))},Ie=()=>Y(()=>H8(e.id),i("svn.cleanupSuccess")),[Fe,be]=k.useState(null),[Ue,Pe]=k.useState(""),tt=()=>{const Re=Ue.trim();if(!Re||!Fe)return;const ct=Fe;be(null),Pe(""),W(Re,ct)},ke=()=>{if(!D.trim()){m(i("svn.commitMessagePlaceholder"));return}const Re=_.size>0?Array.from(_):void 0;Y(async()=>{const ct=await F8(e.id,D.trim(),Re);A(""),ct.revision&&c(i("svn.commitSuccess").replace("{rev}",ct.revision))})},[pe,Ne]=k.useState([]),[Le,ze]=k.useState(!1),[Ke,Ve]=k.useState(!1),[de,fe]=k.useState(null),[ce,Q]=k.useState([]),[V,re]=k.useState(!1),[te,se]=k.useState(null),[le,ve]=k.useState(""),[Ce,De]=k.useState(!1),Qe=k.useCallback(async(Re=0)=>{ze(!0),m(null);try{const ct=await L8(e.id,Re,50);Ne(Oe=>Re===0?ct.commits:[...Oe,...ct.commits]),Ve(ct.hasMore)}catch(ct){m(ct instanceof Error?ct.message:"Log failed")}finally{ze(!1)}},[e.id]),ut=k.useCallback(async Re=>{fe(Re),se(null),ve(""),re(!0);try{const ct=await D8(e.id,Re);Q(ct.files)}catch(ct){m(ct instanceof Error?ct.message:"Failed to load revision files")}finally{re(!1)}},[e.id]);k.useEffect(()=>{var Oe;if(!de||!te){ve("");return}let Re=!1;De(!0);const ct=(Oe=ce.find(ie=>ie.path===te))==null?void 0:Oe.status;return T8(e.id,de,te,ct).then(ie=>{Re||ve(ie.diff)}).catch(ie=>{Re||m(ie instanceof Error?ie.message:"Diff failed")}).finally(()=>{Re||De(!1)}),()=>{Re=!0}},[e.id,de,te,ce]);const[ot,Je]=k.useState(null),[qe,ft]=k.useState(null),lt=(Re,ct)=>{Re.preventDefault(),Re.stopPropagation(),Je({x:Re.clientX,y:Re.clientY,target:{kind:"file",file:ct}})},xt=(Re,ct,Oe,ie)=>{Re.preventDefault(),Re.stopPropagation(),Oe.length!==0&&Je({x:Re.clientX,y:Re.clientY,target:{kind:"group",label:ct,files:Oe,dirPath:ie}})},pt=k.useMemo(()=>Array.from(new Set(((u==null?void 0:u.files)??[]).map(Re=>Re.changelist).filter(Re=>!!Re))).sort(),[u]),st=k.useMemo(()=>{if(!u)return null;const Re=[];return u.branch&&Re.push(u.branch),u.revision&&Re.push(`r${u.revision}`),Re.join(" · ")},[u]),ht=O||b||S;return k.useEffect(()=>{oe&&u&&!u.files.some(Re=>Re.working_dir==="C")&&ee(null)},[u,oe]),n.jsxs("div",{className:"animate-fade-in flex flex-col",style:{height:"calc(100vh - 260px)",minHeight:"400px"},children:[d===!1&&n.jsx("div",{className:"card mb-2 px-3 py-2 bg-status-warning/10 border border-status-warning/30 text-2xs text-status-warning",children:i("svn.cliMissing")}),oe&&oe.length>0&&n.jsxs("div",{className:"card mb-2 px-3 py-2 bg-status-warning/10 border border-status-warning/30 text-2xs text-status-warning flex items-start gap-2",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"font-semibold",children:i("svn.updateConflicts").replace("{n}",String(oe.length))}),n.jsxs("div",{className:"mt-0.5 truncate",title:oe.join(", "),children:[oe.slice(0,5).join(", "),oe.length>5?` … (+${oe.length-5})`:""]})]}),n.jsx("button",{onClick:()=>ee(null),className:"shrink-0 hover:opacity-70",children:"×"})]}),n.jsxs("div",{className:"flex flex-1 min-h-0 gap-2",children:[n.jsxs("div",{className:"card w-52 shrink-0 flex flex-col overflow-y-auto",children:[n.jsxs("div",{className:"px-3 py-3 border-b border-warm-100",children:[n.jsx("div",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:"SVN"}),st&&n.jsx("div",{className:"mt-1 text-2xs text-warm-400 truncate",title:(u==null?void 0:u.tracking)??void 0,children:st})]}),n.jsx(yy,{label:i("svn.viewsHeader")}),n.jsx(Ma,{label:i("svn.checkForModifications"),active:a==="modifications",onClick:()=>h("modifications")}),n.jsx(Ma,{label:i("svn.showLog"),remote:!0,active:a==="log",onClick:()=>h("log")}),n.jsx(yy,{label:i("svn.actionsHeader")}),n.jsx(Ma,{label:i("svn.update"),remote:!0,disabled:ht,onClick:X}),n.jsx(Ma,{label:i("svn.updateToRevision"),remote:!0,disabled:ht,onClick:()=>me(!0)}),n.jsx(Ma,{label:i("svn.cleanup"),disabled:ht,onClick:Ie}),n.jsx(Ma,{label:i("svn.properties"),onClick:()=>ft({file:null})}),n.jsx("div",{className:"flex-1"})]}),n.jsx("div",{className:"card flex-1 overflow-hidden flex flex-col min-w-0 min-h-0",children:a==="modifications"?n.jsx(Y8,{statusFiles:(u==null?void 0:u.files)??[],statusLoading:b,remoteChecking:S,onRefresh:F,onCheckRepository:H,selectedFiles:_,onToggle:$,onSelectMany:q,activeFile:y,onActivate:E,onContextMenu:lt,onGroupContextMenu:xt,onChangelist:W,onResolve:(Re,ct)=>J([Re],ct),workingDiff:T,workingDiffLoading:R,commitMessage:D,onCommitMessageChange:A,onCommit:ke,busy:ht,actionFlash:o,error:f}):n.jsx(X8,{loaded:pe.length>0,entries:pe,loading:Le,hasMore:Ke,onLoad:()=>Qe(0),onLoadMore:()=>Qe(pe.length),selectedRev:de,onSelectRev:ut,revFiles:ce,revFilesLoading:V,selectedFile:te,onSelectFile:se,revDiff:le,revDiffLoading:Ce,error:f})})]}),n.jsx(Un,{open:G,onClose:()=>me(!1),size:"sm",children:n.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[n.jsxs("div",{className:"px-4 py-3 border-b border-warm-100 flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-semibold text-warm-700",children:i("svn.updateToRevision")}),n.jsx("span",{className:"text-[9px] uppercase tracking-wide px-1 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",children:i("svn.remoteBadge")})]}),n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsx("input",{autoFocus:!0,value:ge,onChange:Re=>xe(Re.target.value),onKeyDown:Re=>{Re.key==="Enter"&&he()},placeholder:i("svn.revisionPlaceholder"),className:"w-full border border-warm-200 rounded px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{className:"flex-1 px-3 py-2 text-sm rounded border border-warm-200 hover:bg-warm-50",onClick:()=>me(!1),children:i("svn.cancel")}),n.jsx("button",{className:"flex-1 px-3 py-2 text-sm font-semibold rounded bg-accent text-white hover:bg-accent/90 disabled:opacity-40",disabled:!ge.trim()||ht,onClick:he,children:i("svn.update")})]})]})]})}),n.jsx(Un,{open:Fe!==null,onClose:()=>be(null),size:"sm",children:n.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[n.jsx("div",{className:"px-4 py-3 border-b border-warm-100",children:n.jsx("span",{className:"text-sm font-semibold text-warm-700",children:i("svn.newChangelist")})}),n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsx("input",{autoFocus:!0,value:Ue,onChange:Re=>Pe(Re.target.value),onKeyDown:Re=>{Re.key==="Enter"&&tt()},placeholder:i("svn.changelistNamePlaceholder"),className:"w-full border border-warm-200 rounded px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{className:"flex-1 px-3 py-2 text-sm rounded border border-warm-200 hover:bg-warm-50",onClick:()=>be(null),children:i("svn.cancel")}),n.jsx("button",{className:"flex-1 px-3 py-2 text-sm font-semibold rounded bg-accent text-white hover:bg-accent/90 disabled:opacity-40",disabled:!Ue.trim()||ht,onClick:tt,children:i("svn.moveToChangelist")})]})]})]})}),ot&&n.jsx(J8,{x:ot.x,y:ot.y,target:ot.target,allFiles:(u==null?void 0:u.files)??[],selected:_,onClose:()=>Je(null),onAdd:I,onRevert:B,onDelete:U,onResolve:J,changelists:pt,onChangelist:W,onNewChangelist:Re=>be(Re),onViewDiff:Re=>{E(Re),Je(null)},onProperties:Re=>{ft({file:Re}),Je(null)}}),qe&&n.jsx(Q8,{projectId:e.id,file:qe.file,onClose:()=>ft(null)})]})}function yy({label:e}){return n.jsx("div",{className:"px-3 pt-3 pb-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:e})}function Ma({label:e,active:s,remote:i,disabled:a,onClick:h}){const{t:f}=dt();return n.jsxs("button",{onClick:h,disabled:a,className:`text-left px-3 py-2 text-xs flex items-center gap-2 transition-colors disabled:opacity-40 ${s?"bg-accent/10 text-accent font-semibold border-l-2 border-accent":"text-warm-600 hover:bg-warm-50"}`,children:[n.jsx("span",{className:"truncate flex-1",children:e}),i&&n.jsx("span",{title:f("svn.remoteHint"),className:"shrink-0 text-[9px] uppercase tracking-wide px-1 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",children:f("svn.remoteBadge")})]})}function K8(e){const s={name:"",path:"",dirs:[],files:[]};for(const i of e){const a=i.path.split("/");a.pop();let h=s,f="";for(const m of a){f=f?`${f}/${m}`:m;let o=h.dirs.find(c=>c.name===m);o||(o={name:m,path:f,dirs:[],files:[]},h.dirs.push(o)),h=o}h.files.push(i)}return I_(s),F_(s),s}function I_(e){e.dirs=e.dirs.map(s=>{let i=s;for(;i.dirs.length===1&&i.files.length===0;){const a=i.dirs[0];i={name:`${i.name}/${a.name}`,path:a.path,dirs:a.dirs,files:a.files}}return i}),e.dirs.forEach(I_)}function F_(e){e.dirs.sort((s,i)=>s.name.localeCompare(i.name)),e.files.sort((s,i)=>s.path.localeCompare(i.path)),e.dirs.forEach(F_)}function H_(e){let s=e.dirs.length,i=e.files.length;for(const a of e.dirs){const h=H_(a);s+=h.dirs,i+=h.files}return{dirs:s,files:i}}function $_(e){const s=[...e.files];for(const i of e.dirs)s.push(...$_(i));return s}function G8({onResolve:e,onOpen:s}){const{t:i}=dt(),a=k.useRef(null),[h,f]=k.useState(null);k.useEffect(()=>{if(!h)return;const c=()=>f(null);return document.addEventListener("mousedown",c),document.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c)}},[h]);const m=c=>{var x;c.stopPropagation(),s==null||s();const d=(x=a.current)==null?void 0:x.getBoundingClientRect();if(!d)return;const p=Math.min(d.left,window.innerWidth-188),u=Math.min(d.bottom+2,window.innerHeight-148);f({x:Math.max(8,p),y:Math.max(8,u)})},o=c=>d=>{d.stopPropagation(),f(null),e(c)};return n.jsxs(n.Fragment,{children:[n.jsxs("button",{ref:a,draggable:!1,onClick:m,className:"shrink-0 text-2xs px-1.5 py-0.5 rounded bg-status-error/15 text-status-error hover:bg-status-error/25 font-medium",children:[i("svn.resolve")," ▾"]}),h&&en.createPortal(n.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:h.x,top:h.y},onMouseDown:c=>c.stopPropagation(),children:[n.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:c=>{c.stopPropagation(),s==null||s(),f(null)},children:i("svn.previewDiff")}),n.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs text-theme-text hover:bg-theme-hover transition-colors",onClick:o("working"),children:i("svn.resolveWorking")}),n.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs text-theme-text hover:bg-theme-hover transition-colors",onClick:o("theirs-full"),children:i("svn.resolveTheirs")}),n.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs text-theme-text hover:bg-theme-hover transition-colors",onClick:o("mine-full"),children:i("svn.resolveMine")})]}),document.body)]})}function Rm({file:e,indent:s,showDir:i,shared:a}){const{t:h}=dt(),f=vr(e),m=a.activeFile===e.path;return n.jsxs("div",{draggable:!0,onDragStart:o=>a.onDragStart(o,e),onClick:()=>a.onActivate(e.path),onContextMenu:o=>a.onContextMenu(o,e),style:{paddingLeft:12+s*14},className:`group flex items-center gap-2 pr-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 ${m?"bg-accent/10 border-l-2 border-accent":""}`,children:[n.jsx("input",{type:"checkbox",checked:a.selectedFiles.has(e.path),onChange:o=>{o.stopPropagation(),a.onToggle(e.path)},onClick:o=>o.stopPropagation(),className:"shrink-0"}),n.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${$8(f)}`,children:f}),n.jsxs("span",{className:`truncate flex-1 ${f==="C"?"text-status-error font-medium":"text-warm-600"}`,title:e.path,children:[e.path.split("/").pop(),i&&e.path.includes("/")&&n.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:e.path.substring(0,e.path.lastIndexOf("/"))})]}),f==="C"&&n.jsx(G8,{onResolve:o=>a.onResolve(e.path,o),onOpen:()=>a.onActivate(e.path)}),n.jsx("button",{onClick:o=>a.onContextMenu(o,e),className:"shrink-0 opacity-0 group-hover:opacity-100 text-warm-400 hover:text-warm-700 px-1 transition-opacity",title:h("svn.fileStatus"),children:"⋯"})]})}function U_({node:e,depth:s,collapsed:i,onToggleCollapse:a,fileProps:h,onDirContextMenu:f}){const{t:m}=dt(),o=i.has(e.path),c=H_(e),d=c.dirs>0?m("svn.dirFileCount").replace("{d}",String(c.dirs)).replace("{f}",String(c.files)):m("svn.fileCount").replace("{f}",String(c.files));return n.jsxs(n.Fragment,{children:[n.jsxs("div",{onClick:()=>a(e.path),onContextMenu:p=>f(p,e),style:{paddingLeft:12+s*14},className:"flex items-center gap-1 pr-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 select-none",children:[o?n.jsx(Ns,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}):n.jsx(wl,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}),n.jsx(Kj,{className:"w-3.5 h-3.5 shrink-0 text-amber-500"}),n.jsx("span",{className:"truncate text-warm-700 font-medium",title:e.path,children:e.name}),n.jsx("span",{className:"text-warm-400 text-2xs ml-1 shrink-0",children:d})]}),!o&&n.jsxs(n.Fragment,{children:[e.dirs.map(p=>n.jsx(U_,{node:p,depth:s+1,collapsed:i,onToggleCollapse:a,fileProps:h,onDirContextMenu:f},p.path)),e.files.map(p=>n.jsx(Rm,{file:p,indent:s+1,shared:h},p.path))]})]})}function V8(e,s){const i=new Map,a=[],h=[],f=[];for(const o of e){const c=vr(o);if(o.changelist){const d=i.get(o.changelist);d?d.push(o):i.set(o.changelist,[o])}else c==="?"?h.push(o):c==="!"?f.push(o):a.push(o)}const m=Array.from(i.keys()).sort().map(o=>({key:`cl:${o}`,label:o,files:i.get(o)}));return a.length&&m.push({key:"default",label:s("svn.changelistDefault"),files:a}),h.length&&m.push({key:"unversioned",label:s("svn.changelistUnversioned"),files:h}),f.length&&m.push({key:"missing",label:s("svn.changelistMissing"),files:f}),m}function Y8(e){const{t:s}=dt(),[i,a]=k.useState(()=>{try{return localStorage.getItem("svn.groupByDir")!=="false"}catch{return!0}}),[h,f]=k.useState(new Set),[m,o]=k.useState(null),c=k.useRef(null),[d,p]=k.useState(()=>W8(by,72,Of,zf)),u=k.useMemo(()=>V8(e.statusFiles,s),[e.statusFiles,s]);k.useEffect(()=>{try{localStorage.setItem(by,String(d))}catch{}},[d]);const x=()=>a(y=>{const E=!y;try{localStorage.setItem("svn.groupByDir",String(E))}catch{}return E}),b=y=>f(E=>{const T=new Set(E);return T.has(y)?T.delete(y):T.add(y),T}),C={selectedFiles:e.selectedFiles,activeFile:e.activeFile,onActivate:e.onActivate,onToggle:e.onToggle,onContextMenu:e.onContextMenu,onDragStart:(y,E)=>{const T=e.selectedFiles.size>0&&e.selectedFiles.has(E.path)?e.statusFiles.filter(j=>e.selectedFiles.has(j.path)).map(j=>j.path):[E.path];y.dataTransfer.setData("text/plain",JSON.stringify(T)),y.dataTransfer.effectAllowed="move"},onResolve:e.onResolve},S=(y,E)=>{if(y.preventDefault(),o(null),E.key==="unversioned"||E.key==="missing")return;let T;try{T=JSON.parse(y.dataTransfer.getData("text/plain"))}catch{return}const j=T.filter(R=>{const N=e.statusFiles.find(D=>D.path===R);return N&&vr(N)!=="?"});j.length&&e.onChangelist(E.key.startsWith("cl:")?E.label:null,j)},g=y=>{(y.metaKey||y.ctrlKey)&&y.key==="Enter"&&(y.preventDefault(),e.onCommit())},_=k.useCallback(()=>{var T;const y=(T=c.current)==null?void 0:T.getBoundingClientRect().height;if(!y)return zf;const E=y-U8;return Tm(E,Of,zf)},[]),w=y=>{y.preventDefault();const E=y.currentTarget,T=y.clientY,j=d;let R=null,N=null;const D=P=>{const F=j+(T-P);p(Tm(F,Of,_()))},A=()=>{if(R=null,N===null)return;const P=N;N=null,D(P)},O=P=>{N=P.clientY,R===null&&(R=requestAnimationFrame(A))},z=P=>{R!==null&&cancelAnimationFrame(R),R=null,P.type==="pointerup"&&N!==null&&A(),N=null,document.body.style.cursor="",document.body.style.userSelect="",E.removeEventListener("pointermove",O),E.removeEventListener("pointerup",z),E.removeEventListener("pointercancel",z);try{E.releasePointerCapture(y.pointerId)}catch{}};E.setPointerCapture(y.pointerId),document.body.style.cursor="row-resize",document.body.style.userSelect="none",E.addEventListener("pointermove",O),E.addEventListener("pointerup",z),E.addEventListener("pointercancel",z)};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center gap-2 shrink-0 flex-wrap",children:[n.jsx("button",{onClick:e.onRefresh,disabled:e.busy,className:"px-2 py-1 text-xs rounded border border-warm-200 hover:bg-warm-50 disabled:opacity-40",children:e.statusLoading?s("svn.checking"):s("svn.refresh")}),n.jsxs("button",{onClick:e.onCheckRepository,disabled:e.busy,className:"px-2 py-1 text-xs rounded border border-warm-200 hover:bg-warm-50 disabled:opacity-40 flex items-center gap-1",children:[e.remoteChecking?s("svn.checking"):s("svn.checkRepository"),n.jsx("span",{className:"text-[9px] uppercase tracking-wide px-1 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",children:s("svn.remoteBadge")})]}),e.actionFlash&&n.jsx("span",{className:"text-2xs text-status-success ml-1",children:e.actionFlash}),e.error&&n.jsx("span",{className:"text-2xs text-status-error ml-1",children:e.error})]}),n.jsxs("div",{className:"flex-1 grid grid-cols-2 min-h-0",children:[n.jsxs("div",{ref:c,className:"border-r border-warm-100 flex flex-col min-h-0",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[n.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:s("svn.changed")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:x,title:s(i?"svn.viewFlat":"svn.groupByDir"),className:"text-warm-400 hover:text-warm-700 p-0.5 rounded hover:bg-warm-100",children:i?n.jsx(xu,{className:"w-3.5 h-3.5"}):n.jsx(Wj,{className:"w-3.5 h-3.5"})}),n.jsx("span",{className:"text-2xs text-warm-400",children:e.statusFiles.length})]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:e.statusLoading?n.jsx("div",{className:"p-6 text-center text-xs text-warm-400",children:s("git.loadingFiles")}):e.statusFiles.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-warm-400",children:s("svn.noChanges")}):u.map(y=>{const E=`§${y.key}`,T=h.has(E),j=y.files.reduce((O,z)=>O+(e.selectedFiles.has(z.path)?1:0),0),R=j===y.files.length,N=i?K8(y.files):null,D=y.key!=="unversioned"&&y.key!=="missing",A=m===y.key;return n.jsxs("div",{children:[n.jsxs("div",{onClick:()=>b(E),onContextMenu:O=>e.onGroupContextMenu(O,y.label,y.files,null),onDragOver:D?O=>{O.preventDefault(),O.dataTransfer.dropEffect="move",m!==y.key&&o(y.key)}:void 0,onDragLeave:D?()=>o(O=>O===y.key?null:O):void 0,onDrop:D?O=>S(O,y):void 0,className:`flex items-center gap-1.5 px-3 py-1.5 cursor-pointer text-xs select-none border-y border-warm-200/70 ${A?"bg-accent/20 ring-1 ring-inset ring-accent":"bg-warm-100 hover:bg-warm-200/60"}`,children:[T?n.jsx(Ns,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}):n.jsx(wl,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}),n.jsx("input",{type:"checkbox",checked:R,ref:O=>{O&&(O.indeterminate=j>0&&!R)},onChange:O=>{O.stopPropagation(),e.onSelectMany(y.files.map(z=>z.path),!R)},onClick:O=>O.stopPropagation(),className:"shrink-0"}),n.jsx("span",{className:"truncate text-warm-800 font-bold",children:y.label}),n.jsx("span",{className:"text-warm-400 text-2xs ml-1 shrink-0",children:y.files.length})]}),!T&&(N?n.jsxs(n.Fragment,{children:[N.dirs.map(O=>n.jsx(U_,{node:O,depth:1,collapsed:h,onToggleCollapse:b,fileProps:C,onDirContextMenu:(z,P)=>e.onGroupContextMenu(z,P.path,$_(P),P.path)},O.path)),N.files.map(O=>n.jsx(Rm,{file:O,indent:1,shared:C},O.path))]}):y.files.map(O=>n.jsx(Rm,{file:O,indent:1,showDir:!0,shared:C},O.path)))]},y.key)})}),n.jsxs("div",{className:"border-t border-warm-100 shrink-0 bg-theme-bg",children:[n.jsx("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize commit message",onPointerDown:w,className:"h-2 -mt-px cursor-row-resize touch-none flex items-center justify-center group",children:n.jsx("div",{className:"h-px w-10 bg-warm-300 group-hover:bg-accent transition-colors"})}),n.jsxs("div",{className:"p-2 pt-1",children:[n.jsx("textarea",{value:e.commitMessage,onChange:y=>e.onCommitMessageChange(y.target.value),onKeyDown:g,placeholder:s("svn.commitMessagePlaceholder"),className:"block w-full text-xs p-2 border border-warm-200 rounded resize-none focus:border-accent focus:ring-1 focus:ring-accent/30 outline-none",style:{height:d},rows:3}),n.jsx("button",{onClick:e.onCommit,disabled:e.busy||!e.commitMessage.trim(),className:"mt-2 w-full px-3 py-1.5 text-xs font-semibold rounded bg-accent text-white hover:bg-accent/90 disabled:opacity-40",children:e.busy?s("svn.committing"):s("svn.commit")})]})]})]}),n.jsx("div",{className:"min-w-0",children:n.jsx(Cl,{diff:e.workingDiff,loading:e.workingDiffLoading,selectedFile:e.activeFile})})]})]})}function X8(e){const{t:s}=dt();return e.loaded?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center gap-2 shrink-0",children:[n.jsx("button",{onClick:e.onLoad,disabled:e.loading,className:"px-2 py-1 text-xs rounded border border-warm-200 hover:bg-warm-50 disabled:opacity-40",children:e.loading?s("svn.checking"):s("svn.refresh")}),e.error&&n.jsx("span",{className:"text-2xs text-status-error ml-1",children:e.error})]}),n.jsxs("div",{className:"flex-1 grid grid-cols-[1fr_1fr] min-h-0",children:[n.jsxs("div",{className:"border-r border-warm-100 flex flex-col min-h-0",children:[n.jsx("div",{className:"px-3 py-2 border-b border-warm-100 shrink-0",children:n.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:s("svn.history")})}),n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.entries.map(i=>n.jsxs("div",{onClick:()=>e.onSelectRev(i.hash),className:`px-3 py-2 cursor-pointer text-xs border-b border-warm-50 hover:bg-warm-50/50 ${e.selectedRev===i.hash?"bg-accent/10 border-l-2 border-accent":""}`,children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"font-mono text-2xs text-warm-400 shrink-0",children:["r",i.hash]}),n.jsx("span",{className:"truncate flex-1 text-warm-700",title:i.message,children:i.message.split(`
669
669
  `)[0]})]}),n.jsxs("div",{className:"mt-0.5 text-2xs text-warm-400 truncate",children:[i.author,i.date&&n.jsxs("span",{children:[" · ",new Date(i.date).toLocaleString()]})]})]},i.hash)),e.hasMore&&!e.loading&&n.jsxs("button",{onClick:e.onLoadMore,className:"w-full py-2 text-2xs text-warm-500 hover:bg-warm-50",children:["+ ",s("svn.loadMore")]})]})]}),n.jsxs("div",{className:"grid grid-rows-[1fr_2fr] min-h-0",children:[n.jsx("div",{className:"border-b border-warm-100 min-h-0",children:n.jsx(Ku,{files:e.revFiles,loading:e.revFilesLoading,selectedFile:e.selectedFile,onFileClick:e.onSelectFile,commitHash:e.selectedRev??void 0})}),n.jsx("div",{className:"min-h-0",children:n.jsx(Cl,{diff:e.revDiff,loading:e.revDiffLoading,selectedFile:e.selectedFile})})]})]})]}):n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-6 text-center",children:[n.jsx("p",{className:"text-xs text-warm-400 max-w-xs",children:s("svn.logEmptyHint")}),n.jsxs("button",{onClick:e.onLoad,disabled:e.loading,className:"px-4 py-2 text-xs font-semibold rounded bg-accent text-white hover:bg-accent/90 disabled:opacity-40 flex items-center gap-2",children:[e.loading?s("svn.checking"):s("svn.loadLog"),n.jsx("span",{className:"text-[9px] uppercase tracking-wide px-1 rounded bg-white/20",children:s("svn.remoteBadge")})]}),e.error&&n.jsx("span",{className:"text-2xs text-status-error",children:e.error})]})}function J8(e){const{t:s}=dt(),i=k.useRef(null),[a,h]=k.useState({x:e.x,y:e.y}),f=k.useMemo(()=>{if(e.target.kind==="group")return e.target.files;const y=e.target.file;return e.selected.size>0&&e.selected.has(y.path)?e.allFiles.filter(E=>e.selected.has(E.path)):[y]},[e.target,e.selected,e.allFiles]),m=e.target.kind==="file"?e.target.file:null,o=e.target.kind==="group"?e.target.label:null,c=e.target.kind==="group"?e.target.dirPath:null,d=m?vr(m)!=="?"?m.path:null:c,p=f.filter(y=>vr(y)==="?").map(y=>y.path),u=f.filter(y=>vr(y)!=="?").map(y=>y.path),x=f.filter(y=>!["?","D"].includes(vr(y))).map(y=>y.path),b=f.filter(y=>vr(y)==="C").map(y=>y.path),C=f.filter(y=>vr(y)!=="?").map(y=>y.path),S=f.filter(y=>y.changelist).map(y=>y.path);k.useEffect(()=>{const y=T=>{i.current&&!i.current.contains(T.target)&&e.onClose()},E=()=>e.onClose();return document.addEventListener("mousedown",y),document.addEventListener("scroll",E,!0),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("scroll",E,!0)}},[e]),k.useEffect(()=>{if(!i.current)return;const y=i.current.getBoundingClientRect();let{x:E,y:T}={x:e.x,y:e.y};E+y.width>window.innerWidth&&(E=window.innerWidth-y.width-8),T+y.height>window.innerHeight&&(T=window.innerHeight-y.height-8),h({x:E,y:T})},[e.x,e.y]);const g=f.length,_=g>1?` (${g})`:"",w=({label:y,onClick:E,danger:T})=>n.jsx("button",{className:`w-full text-left px-3 py-1.5 text-xs hover:bg-theme-hover transition-colors ${T?"text-status-error":"text-theme-text"}`,onClick:()=>{E(),e.onClose()},children:y});return en.createPortal(n.jsxs("div",{ref:i,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:a.x,top:a.y},children:[o!==null&&n.jsxs("div",{className:"px-3 py-1.5 border-b border-warm-100 dark:border-warm-700 truncate",title:o,children:[n.jsx("span",{className:"text-xs font-semibold text-warm-700",children:o}),n.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["· ",f.length]})]}),m&&n.jsx(w,{label:s("svn.viewDiff"),onClick:()=>e.onViewDiff(m.path)}),d!==null&&n.jsx(w,{label:s("svn.properties"),onClick:()=>e.onProperties(d)}),p.length>0&&n.jsx(w,{label:`${s("svn.add")}${_}`,onClick:()=>e.onAdd(p)}),u.length>0&&n.jsx(w,{label:`${s("svn.revert")}${_}`,onClick:()=>e.onRevert(u)}),x.length>0&&n.jsx(w,{label:`${s("svn.delete")}${_}`,danger:!0,onClick:()=>e.onDelete(x)}),b.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),n.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:s("svn.resolve")}),n.jsx(w,{label:s("svn.resolveWorking"),onClick:()=>e.onResolve(b,"working")}),n.jsx(w,{label:s("svn.resolveMine"),onClick:()=>e.onResolve(b,"mine-full")}),n.jsx(w,{label:s("svn.resolveTheirs"),onClick:()=>e.onResolve(b,"theirs-full")}),n.jsx(w,{label:s("svn.resolveBase"),onClick:()=>e.onResolve(b,"base")})]}),C.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),n.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:s("svn.moveToChangelist")}),e.changelists.map(y=>n.jsx(w,{label:`${y}${_}`,onClick:()=>e.onChangelist(y,C)},y)),n.jsx(w,{label:s("svn.newChangelist"),onClick:()=>e.onNewChangelist(C)}),S.length>0&&n.jsx(w,{label:`${s("svn.removeFromChangelist")}${_}`,onClick:()=>e.onChangelist(null,S)})]})]}),document.body)}function Q8({projectId:e,file:s,onClose:i}){const{t:a}=dt(),[h,f]=k.useState(null),[m,o]=k.useState(null),[c,d]=k.useState(null),[p,u]=k.useState(""),[x,b]=k.useState(!1),[C,S]=k.useState(0);k.useEffect(()=>{let w=!1;return f(null),o(null),M8(e,s??void 0).then(y=>{w||f(y.properties)}).catch(y=>{w||o(y instanceof Error?y.message:"Failed to load properties")}),()=>{w=!0}},[e,s,C]);const g=async w=>{b(!0),o(null);try{await A8(e,w,p,s??void 0),d(null),S(y=>y+1)}catch(y){o(y instanceof Error?y.message:"Failed to save property")}finally{b(!1)}},_=s??a("svn.workingCopyRoot");return n.jsx(Un,{open:!0,onClose:i,size:"2xl",children:n.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-full max-h-[80vh] flex flex-col",children:[n.jsxs("div",{className:"px-4 py-3 border-b border-warm-100 flex items-center justify-between shrink-0",children:[n.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",title:_,children:a("svn.propertiesOf").replace("{target}",_)}),n.jsx("button",{onClick:i,className:"text-warm-400 hover:text-warm-600 shrink-0 ml-2",children:"✕"})]}),n.jsxs("div",{className:"p-4 overflow-y-auto",children:[m&&n.jsx("p",{className:"text-status-error text-xs mb-2 whitespace-pre-wrap break-all",children:m}),h===null?!m&&n.jsx("p",{className:"text-warm-400 text-xs",children:a("git.loadingFiles")}):h.length===0?n.jsx("p",{className:"text-warm-400 text-xs",children:a("svn.noProperties")}):n.jsx("div",{className:"space-y-3",children:h.map(w=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("div",{className:"text-xs font-mono font-semibold text-accent break-all",children:w.name}),c!==w.name&&n.jsx("button",{onClick:()=>{d(w.name),u(w.value)},className:"text-2xs text-warm-400 hover:text-accent shrink-0",children:a("svn.editProperty")})]}),c===w.name?n.jsxs(n.Fragment,{children:[n.jsx("textarea",{value:p,onChange:y=>u(y.target.value),rows:Math.min(12,Math.max(3,p.split(`
670
- `).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 p-2 border border-accent/40 focus:outline-none focus:border-accent resize-y"}),n.jsxs("div",{className:"mt-1 flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>d(null),disabled:x,className:"px-2.5 py-1 text-2xs rounded border border-warm-200 hover:bg-warm-50 disabled:opacity-40",children:a("svn.cancel")}),n.jsx("button",{onClick:()=>g(w.name),disabled:x,className:"px-2.5 py-1 text-2xs font-semibold rounded bg-accent text-white hover:bg-accent/90 disabled:opacity-40",children:a("svn.saveProperty")})]})]}):n.jsx("pre",{className:"mt-1 text-2xs font-mono text-warm-600 bg-warm-50 dark:bg-warm-800/40 rounded p-2 whitespace-pre-wrap break-all",children:w.value||"—"})]},w.name))})]}),n.jsx("div",{className:"px-4 py-3 border-t border-warm-100 shrink-0 text-right",children:n.jsx("button",{onClick:i,className:"px-3 py-1.5 text-xs rounded border border-warm-200 hover:bg-warm-50",children:a("svn.close")})})]})})}const Z8=["architect","developer","reviewer","pm","tester","custom"],Ii=["#6366f1","#8b5cf6","#ec4899","#f43f5e","#f97316","#eab308","#22c55e","#14b8a6","#06b6d4","#3b82f6"],eO=[{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 tO({projectId:e,agents:s,onAgentsChange:i}){const{t:a,lang:h}=dt(),[f,m]=k.useState(!1),[o,c]=k.useState(null),[d,p]=k.useState(""),[u,x]=k.useState("developer"),[b,C]=k.useState(""),[S,g]=k.useState(""),[_,w]=k.useState(Ii[0]),[y,E]=k.useState(!1),[T,j]=k.useState(!1),R=()=>{p(""),x("developer"),C(""),g(""),w(Ii[Math.floor(Math.random()*Ii.length)]),E(!1),m(!1),c(null)},N=async()=>{if(!(!d.trim()||!b.trim())){j(!0);try{if(o){const z=await a4(o,{name:d,role:u,system_prompt:b,avatar_color:_,cli_tool:S||null,can_implement:y});i(s.map(P=>P.id===o?z:P))}else{const z=await i4(e,{name:d,role:u,system_prompt:b,avatar_color:_,...S?{cli_tool:S}:{},can_implement:y});i([...s,z])}R()}finally{j(!1)}}},D=z=>{c(z.id),p(z.name),x(z.role),C(z.system_prompt),g(z.cli_tool||""),w(z.avatar_color||Ii[0]),E(!!z.can_implement),m(!0)},A=async z=>{await o4(z),i(s.filter(P=>P.id!==z))},O=z=>{p(h==="ko"?z.nameKo:z.name),x(z.role),C(z.prompt),w(Ii[Math.floor(Math.random()*Ii.length)]),m(!0)};return n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700",children:a("agents.title")}),n.jsxs("button",{onClick:()=>{R(),m(!0)},className:"btn btn-sm text-xs",children:["+ ",a("agents.add")]})]}),s.length===0&&!f&&n.jsx(Vi,{icon:mN,title:a("agents.empty"),size:"sm"}),n.jsx("div",{className:"space-y-2",children:s.map(z=>{var P;return n.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:[n.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:z.avatar_color||"#6366f1"},children:z.name.charAt(0).toUpperCase()}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",children:z.name}),!!z.can_implement&&n.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium bg-amber-50 text-amber-700 border border-amber-200",title:a("agents.canImplementHelp"),children:[n.jsx(Hv,{size:10}),a("agents.canImplementBadge")]})]}),n.jsxs("div",{className:"text-xs text-warm-400 mt-0.5",children:[a(`agents.roles.${z.role}`)||z.role,z.cli_tool&&n.jsxs("span",{className:"ml-1.5 text-warm-300",children:["· ",((P=wr.find(F=>F.value===z.cli_tool))==null?void 0:P.label)||z.cli_tool]})]})]}),n.jsxs("div",{className:"flex gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx("button",{onClick:()=>D(z),className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-lg transition-colors",children:n.jsx(ci,{size:16})}),n.jsx("button",{onClick:()=>A(z.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-red-50 rounded-lg transition-colors",children:n.jsx(Ln,{size:16})})]})]},z.id)})}),f&&n.jsxs("div",{className:"space-y-5 p-5 rounded-xl border border-warm-200 bg-theme-card shadow-sm",children:[!o&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.presets")}),n.jsx("div",{className:"flex flex-wrap gap-2",children:eO.map(z=>n.jsx("button",{onClick:()=>O(z),className:"px-3 py-1.5 text-xs rounded-lg bg-warm-50 text-warm-600 hover:bg-warm-100 border border-warm-150 hover:border-warm-300 transition-colors font-medium",children:h==="ko"?z.nameKo:z.name},z.role))})]}),n.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.name")}),n.jsx("input",{type:"text",value:d,onChange:z=>p(z.target.value),className:"input-field",placeholder:h==="ko"?"에이전트 이름":"Agent name"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.role")}),n.jsx("select",{value:u,onChange:z=>x(z.target.value),className:"input-field",children:Z8.map(z=>n.jsx("option",{value:z,children:a(`agents.roles.${z}`)},z))})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.systemPrompt")}),n.jsx("textarea",{value:b,onChange:z=>C(z.target.value),rows:5,className:"input-field resize-y min-h-[100px]",placeholder:h==="ko"?"이 에이전트의 전문 분야와 관점을 설명하세요...":"Describe this agent's expertise and perspective..."}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1.5",children:h==="ko"?"토론 시 이 에이전트가 어떤 관점에서 발언할지 결정합니다.":"Determines what perspective this agent brings to the discussion."})]}),n.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.cliTool")}),n.jsxs("select",{value:S,onChange:z=>g(z.target.value),className:"input-field text-sm",children:[n.jsx("option",{value:"",children:h==="ko"?"프로젝트 기본값 사용":"Use project default"}),wr.map(z=>n.jsx("option",{value:z.value,children:z.label},z.value))]})]})}),n.jsx("div",{children:n.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:y,onChange:z=>E(z.target.checked),className:"mt-0.5 w-4 h-4 rounded border-warm-300 text-warm-600 focus:ring-warm-400"}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-warm-700",children:[n.jsx(Hv,{size:12}),a("agents.canImplement")]}),n.jsx("p",{className:"text-2xs text-warm-400 mt-0.5",children:a("agents.canImplementHelp")})]})]})}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.color")}),n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.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:_},children:d?d.charAt(0).toUpperCase():"?"}),n.jsx("div",{className:"flex flex-wrap gap-2",children:Ii.map(z=>n.jsx("button",{onClick:()=>w(z),className:`w-7 h-7 rounded-full transition-all ${_===z?"ring-2 ring-offset-2 ring-warm-400 scale-110":"hover:scale-105 opacity-70 hover:opacity-100"}`,style:{backgroundColor:z}},z))})]})]}),n.jsxs("div",{className:"flex justify-end gap-3 pt-2 border-t border-warm-100",children:[n.jsx("button",{onClick:R,className:"btn btn-sm text-xs text-warm-500",children:a("header.cancel")}),n.jsx("button",{onClick:N,disabled:!d.trim()||!b.trim()||T,className:"btn btn-sm btn-primary text-xs",children:a(T?"header.saving":"header.save")})]})]})]})}const nO={title:"",description:"",agent_ids:[],max_rounds:3,auto_implement:!1,implement_agent_id:"",memory_inject_mode:"none",memory_node_ids:[],memory_raw_file_paths:[],use_worktree:!0};function W_({agents:e,projectId:s,initialValues:i,mode:a,allowAdvancedFields:h=!0,submitting:f=!1,isGitRepo:m=!1,projectUseWorktree:o=!0,onSubmit:c,onCancel:d}){const{t:p,lang:u}=dt(),x=()=>({...nO,use_worktree:o,...i}),[b,C]=k.useState(x),[S,g]=k.useState(!1);k.useEffect(()=>{C(x())},[i,o]);const _=(N,D)=>{C(A=>({...A,[N]:D}))},w=N=>p(`agents.roles.${N.role}`)||N.role,y=b.agent_ids.map(N=>e.find(D=>D.id===N)).filter(N=>!!N),E=N=>{C(D=>{const A=D.agent_ids.includes(N)?D.agent_ids.filter(O=>O!==N):[...D.agent_ids,N];return{...D,agent_ids:A,implement_agent_id:D.implement_agent_id&&!A.includes(D.implement_agent_id)?"":D.implement_agent_id}})},T=(N,D)=>{C(A=>{const O=A.agent_ids.indexOf(N),z=O+D;if(O===-1||z<0||z>=A.agent_ids.length)return A;const P=[...A.agent_ids];return[P[O],P[z]]=[P[z],P[O]],{...A,agent_ids:P}})},j=async()=>{!b.title.trim()||!b.description.trim()||h&&b.agent_ids.length<2||h&&b.auto_implement&&!b.implement_agent_id||await c({title:b.title.trim(),description:b.description.trim(),agent_ids:b.agent_ids,max_rounds:b.max_rounds,auto_implement:h?b.auto_implement:!1,implement_agent_id:h&&b.auto_implement?b.implement_agent_id:void 0,memory_inject_mode:h?b.memory_inject_mode:"none",memory_node_ids:h&&b.memory_inject_mode==="selected"?b.memory_node_ids:[],memory_raw_file_paths:h?b.memory_raw_file_paths:[],...m?{use_worktree:b.use_worktree}:{}})},R=b.title.trim()&&b.description.trim()&&(!h||b.agent_ids.length>=2)&&(!h||!b.auto_implement||!!b.implement_agent_id);return n.jsxs("div",{className:"card p-5 space-y-5",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:u==="ko"?"제목":"Title"}),n.jsx("input",{type:"text",value:b.title,onChange:N=>_("title",N.target.value),className:"input-field",placeholder:u==="ko"?"토론 주제를 입력하세요":"Enter discussion topic"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:u==="ko"?"설명":"Description"}),n.jsx("textarea",{value:b.description,onChange:N=>_("description",N.target.value),rows:4,className:"input-field resize-y min-h-[80px]",placeholder:u==="ko"?"토론할 기능이나 의사결정 배경을 자세히 설명하세요":"Describe the feature to discuss in detail"})]}),h&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{children:[n.jsxs("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:[p("discussions.agents"),n.jsx("span",{className:"ml-2 text-warm-400 font-normal",children:u==="ko"?`(${b.agent_ids.length}명 선택됨 · 최소 2명)`:`(${b.agent_ids.length} selected · min 2)`})]}),n.jsx("p",{className:"text-[11px] text-warm-400",children:u==="ko"?"참여 에이전트를 고른 뒤, 아래 발언 순서에서 실제 토론 진행 순서를 조정합니다.":"Select participants first, then adjust the actual speaking order below."})]}),n.jsxs("div",{className:"rounded-2xl border border-accent/30 bg-accent/5 p-3 space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-semibold text-warm-700",children:u==="ko"?"발언 순서":"Speaking Order"}),n.jsx("p",{className:"text-[11px] text-warm-500 mt-1",children:u==="ko"?"1라운드 기준이며, 이후 라운드에도 같은 순서로 반복됩니다.":"This order is used for round 1 and repeats in later rounds."})]}),y.length>=2&&n.jsx("div",{className:"text-2xs font-semibold text-accent-dark bg-white/70 border border-accent/30 rounded-full px-2.5 py-1",children:u==="ko"?"순서 조정 가능":"Reorder enabled"})]}),y.length===0?n.jsx("div",{className:"rounded-xl border border-dashed border-warm-200 bg-white/70 px-4 py-5 text-center text-xs text-warm-400",children:u==="ko"?"에이전트를 선택하면 여기서 발언 순서를 바로 조정할 수 있습니다.":"Select agents to adjust the speaking order here."}):n.jsx("div",{className:"space-y-2",children:y.map((N,D)=>{const A=D===0,O=D===y.length-1,z=A?u==="ko"?"첫 발언":"Opens the round":O?u==="ko"?"마지막 발언":"Closes the round":u==="ko"?`${D+1}번째 발언`:`Turn ${D+1}`;return n.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-warm-200 bg-white/85 px-3 py-3 md:flex-row md:items-center md:justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[n.jsx("div",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-accent text-[11px] font-bold text-white flex-shrink-0",children:D+1}),n.jsx("div",{className:"w-6 h-6 rounded-full flex-shrink-0 border border-white/80 shadow-sm",style:{backgroundColor:N.avatar_color||"#6366f1"}}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-semibold text-warm-700 truncate",children:N.name}),n.jsxs("div",{className:"text-[11px] text-warm-500",children:[w(N)," · ",z]})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{type:"button",onClick:()=>T(N.id,-1),disabled:A,className:"px-2.5 py-1.5 rounded-lg border border-warm-200 bg-warm-50 text-[11px] font-medium text-warm-600 hover:bg-warm-100 disabled:opacity-40 disabled:cursor-not-allowed",children:u==="ko"?"앞으로":"Earlier"}),n.jsx("button",{type:"button",onClick:()=>T(N.id,1),disabled:O,className:"px-2.5 py-1.5 rounded-lg border border-warm-200 bg-warm-50 text-[11px] font-medium text-warm-600 hover:bg-warm-100 disabled:opacity-40 disabled:cursor-not-allowed",children:u==="ko"?"뒤로":"Later"})]})]},N.id)})})]}),e.length===0?n.jsx("p",{className:"text-xs text-warm-400 py-3 px-4 bg-warm-50 rounded-xl border border-warm-150",children:p("agents.empty")}):n.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:e.map(N=>{const D=b.agent_ids.includes(N.id),A=b.agent_ids.indexOf(N.id)+1;return n.jsxs("button",{type:"button",onClick:()=>E(N.id),className:`text-left rounded-2xl border px-3.5 py-3 transition-all ${D?"border-accent bg-accent/5 shadow-sm":"border-warm-200 bg-warm-50 hover:border-warm-300 hover:bg-warm-100"}`,children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[n.jsx("div",{className:"w-6 h-6 rounded-full flex-shrink-0 border border-white/80 shadow-sm",style:{backgroundColor:N.avatar_color||"#6366f1"}}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold truncate ${D?"text-warm-700":"text-warm-600"}`,children:N.name}),n.jsx("div",{className:"text-[11px] text-warm-400",children:w(N)})]})]}),D&&n.jsx("div",{className:"inline-flex items-center justify-center min-w-7 h-7 rounded-full bg-accent text-[11px] font-bold text-white flex-shrink-0",children:A})]}),n.jsx("div",{className:`mt-3 text-[11px] ${D?"text-accent-dark":"text-warm-400"}`,children:D?u==="ko"?`${A}번째 발언으로 참여 중`:`Included as turn ${A}`:u==="ko"?"클릭해서 참여 에이전트에 추가":"Click to add this participant"})]},N.id)})})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:p("discussions.maxRounds")}),n.jsx("input",{type:"number",min:1,max:10,value:b.max_rounds,onChange:N=>_("max_rounds",Number(N.target.value)),className:"input-field w-24 text-center"}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1.5",children:p("discussions.roundExplain")})]}),m&&n.jsxs("div",{children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:b.use_worktree,onChange:N=>_("use_worktree",N.target.checked),className:"rounded border-warm-300 text-accent focus:ring-accent"}),n.jsx(Ga,{size:14,className:"text-warm-500"}),n.jsx("span",{className:"text-xs font-medium text-warm-500",children:u==="ko"?"워크트리에서 격리 실행":"Run in isolated worktree"})]}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1 ml-6",children:u==="ko"?"체크하면 전용 브랜치/워크트리를 만들어 격리 실행합니다. 해제하면 프로젝트 원본 경로에서 바로 실행합니다.":"Checked: create a dedicated branch/worktree for isolation. Unchecked: run directly in the project root."})]}),s&&n.jsx("div",{children:n.jsx(jp,{projectId:s,mode:b.memory_inject_mode,selectedPaths:b.memory_raw_file_paths,includeLinked:S,onChange:(N,D,A)=>{C(O=>({...O,memory_inject_mode:N,memory_node_ids:[],memory_raw_file_paths:D})),g(A)}})}),n.jsxs("div",{children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:b.auto_implement,onChange:N=>{const D=N.target.checked;C(A=>({...A,auto_implement:D,implement_agent_id:D?A.implement_agent_id:""}))},className:"rounded border-warm-300 text-accent focus:ring-accent"}),n.jsx("span",{className:"text-xs font-medium text-warm-500",children:p("discussions.autoImplement")})]}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1 ml-6",children:p("discussions.autoImplementHint")}),b.auto_implement&&n.jsxs("div",{className:"mt-2 ml-6",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1",children:p("discussions.selectAgent")}),n.jsxs("select",{value:b.implement_agent_id,onChange:N=>_("implement_agent_id",N.target.value),className:"input-field text-xs w-56",children:[n.jsx("option",{value:"",children:u==="ko"?"-- 에이전트 선택 --":"-- Select agent --"}),y.map(N=>n.jsxs("option",{value:N.id,children:[N.name," (",w(N),")"]},N.id))]})]})]})]}),n.jsxs("div",{className:"flex justify-end gap-3 pt-2 border-t border-warm-100",children:[n.jsx("button",{type:"button",onClick:d,className:"btn-secondary text-xs py-2",children:p("header.cancel")}),n.jsx("button",{type:"button",onClick:j,disabled:!R||f,className:"btn-primary text-xs py-2",children:p(f?"header.saving":a==="create"?"discussions.add":"header.save")})]})]})}const sO={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",paused:"bg-amber-100 text-amber-700",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",merged:"bg-accent/10 text-accent"};function rO({projectId:e,discussions:s,isGitRepo:i,projectUseWorktree:a,onAddDiscussion:h,onStartDiscussion:f,onStopDiscussion:m,onDeleteDiscussion:o}){const{t:c}=dt(),d=fi(),[p,u]=k.useState([]),[x,b]=k.useState(!1),[C,S]=k.useState(!1),[g,_]=k.useState(!1),[w,y]=k.useState(null);k.useEffect(()=>{b1(e).then(u).catch(()=>{})},[e]);const E=k.useCallback(async j=>{_(!0);try{const R=await l4(e,j);h(R),b(!1)}finally{_(!1)}},[e,h]),T=j=>{try{return JSON.parse(j).map(N=>p.find(D=>D.id===N)).filter(N=>!!N)}catch{return[]}};return n.jsxs("div",{className:"space-y-4 animate-fade-in min-h-[50vh]",onContextMenu:j=>{hi(j)||(j.preventDefault(),y({x:j.clientX,y:j.clientY}))},children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:c("discussions.title")}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>S(!C),className:"btn-secondary text-xs py-2",children:c("agents.manage")}),n.jsxs("button",{onClick:()=>b(!x),className:"btn-primary text-xs py-2",children:["+ ",c("discussions.add")]})]})]}),C&&n.jsx("div",{className:"card p-4",children:n.jsx(tO,{projectId:e,agents:p,onAgentsChange:u})}),x&&n.jsx(W_,{agents:p,projectId:e,mode:"create",submitting:g,isGitRepo:i,projectUseWorktree:a,onSubmit:E,onCancel:()=>b(!1)}),s.length===0&&!x?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:CE,title:c("discussions.empty"),description:c("discussions.emptyHint")})}):n.jsx("div",{className:"space-y-3",children:s.map((j,R)=>{const N=T(j.agent_ids),D=j.status==="pending"||j.status==="paused"||j.status==="failed",A=j.status==="running";return n.jsx("div",{className:"card p-4 hover:shadow-md transition-all cursor-pointer animate-slide-up",onClick:()=>d(`/projects/${e}/discussions/${j.id}`),style:{animationDelay:`${R*50}ms`},children:n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:j.title}),n.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-semibold uppercase ${sO[j.status]||""}`,children:c(`status.${j.status}`)||j.status})]}),n.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:j.description}),n.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[n.jsxs("span",{className:"text-2xs text-warm-400",children:[c("discussions.round")," ",j.current_round,"/",j.max_rounds]}),n.jsx("div",{className:"flex -space-x-1",children:N.slice(0,5).map(O=>n.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:O.avatar_color||"#6366f1"},title:O.name,children:O.name.charAt(0)},O.id))})]})]}),n.jsxs("div",{className:"flex gap-1",onClick:O=>O.stopPropagation(),children:[D&&n.jsx("button",{onClick:()=>f(j.id),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded transition-colors",title:c("header.runAll"),children:n.jsx(kr,{size:16})}),A&&n.jsx("button",{onClick:()=>m(j.id),className:"p-1.5 text-amber-600 hover:bg-amber-50 rounded transition-colors",title:c("discussions.pause"),children:n.jsx(Zm,{size:16})}),n.jsx("button",{onClick:()=>o(j.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded transition-colors",title:c("todo.delete"),children:n.jsx(Ln,{size:16})})]})]})},j.id)})}),w&&n.jsx(Cr,{x:w.x,y:w.y,onClose:()=>y(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>{b(!0)},children:[n.jsx(mn,{size:14}),c("discussions.add")]})})]})}function iO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}let Bf=!1;function Np(e){var f,m;const s=window.electronAPI;if(!(s!=null&&s.imeReset)||Bf)return!1;Bf=!0;let i=!1;const a=()=>{i=!0,Bf=!1},h=window.setTimeout(a,1e3);return(m=(f=document.activeElement)==null?void 0:f.blur)==null||m.call(f),s.imeReset(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{window.clearTimeout(h);try{e()}finally{i||a()}})}),!0}function wy({projectId:e,initial:s,onSave:i,onCancel:a,projectCliTool:h,isGitRepo:f,projectUseWorktree:m}){const{t:o}=dt(),c=!!s,[d,p]=k.useState((s==null?void 0:s.title)??""),[u,x]=k.useState((s==null?void 0:s.description)??""),[b,C]=k.useState((s==null?void 0:s.cliTool)??(h||"")),[S,g]=k.useState((s==null?void 0:s.useWorktree)??!!m),[_,w]=k.useState((s==null?void 0:s.memoryInjectMode)??"none"),[y,E]=k.useState((s==null?void 0:s.memoryRawFilePaths)??[]),[T,j]=k.useState(!1),[R,N]=k.useState((s==null?void 0:s.tagId)??null),[D,A]=k.useState([]),[O,z]=k.useState([]),P=k.useRef(null);k.useEffect(()=>{var J;Np(()=>{var W;return(W=P.current)==null?void 0:W.focus()})||(J=P.current)==null||J.focus();const B=Array.from(document.querySelectorAll(".xterm-helper-textarea")),U=B.map(W=>({el:W,tabIndex:W.tabIndex,ariaHidden:W.getAttribute("aria-hidden")}));return B.forEach(W=>{W.tabIndex=-1,W.setAttribute("aria-hidden","true"),W.blur()}),()=>{U.forEach(({el:W,tabIndex:oe,ariaHidden:ee})=>{W.tabIndex=oe,ee===null?W.removeAttribute("aria-hidden"):W.setAttribute("aria-hidden",ee)})}},[]),k.useEffect(()=>{let B=!1;return sp().then(U=>{B||A(U)}).catch(()=>{}),!c&&f&&rp().then(U=>{B||g(U.defaultUseWorktree)}).catch(()=>{}),()=>{B=!0}},[c,f]),k.useEffect(()=>{let B=!1;return op().then(U=>{B||z(U)}).catch(()=>{}),()=>{B=!0}},[]);const F=wr.filter(B=>B.supportsInteractive),H=B=>{const U=O.find(J=>J.tool===B.value);return B.value==="raw-shell"?U!=null&&U.version?`Raw Shell (${U.version})`:B.label:U&&!U.installed?`${B.label}${o("session.cliNotInstalled")}`:B.label},q=(b||h||"claude")==="raw-shell",Y=B=>{B.preventDefault(),i(d.trim(),u.trim(),b||void 0,S,_,[],y,R)},I=D.find(B=>B.id===R)??null;return n.jsxs("form",{onSubmit:Y,className:"card p-4 space-y-3 animate-scale-in",children:[n.jsx("input",{ref:P,type:"text",value:d,onChange:B=>p(B.target.value),placeholder:o("session.title"),className:"input-field text-sm"}),!q&&n.jsx("textarea",{value:u,onChange:B=>x(B.target.value),placeholder:o("session.description"),className:"input-field text-sm min-h-[60px] max-h-[280px] resize-y [field-sizing:content]",rows:2}),n.jsx("div",{className:"flex gap-2",children:n.jsxs("select",{value:b,onChange:B=>C(B.target.value),className:"input-field text-xs flex-1",children:[n.jsxs("option",{value:"",children:[o("session.cliTool")," (Default)"]}),F.map(B=>n.jsx("option",{value:B.value,children:H(B)},B.value))]})}),D.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[I&&n.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:I.color,borderColor:"rgba(0,0,0,0.08)"}}),n.jsxs("select",{value:R??"",onChange:B=>N(B.target.value||null),className:"input-field text-xs flex-1",children:[n.jsx("option",{value:"",children:o("session.tag.none")}),D.map(B=>n.jsx("option",{value:B.id,children:B.name},B.id))]})]}),f&&n.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-500 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:S,onChange:B=>g(B.target.checked),className:"rounded border-warm-300"}),n.jsx(Ga,{size:14}),o("session.worktree")]}),!q&&n.jsx(jp,{projectId:e,mode:_,selectedPaths:y,includeLinked:T,onChange:(B,U,J)=>{w(B),E(U),j(J)}}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:a,className:"btn-secondary text-xs py-1.5 px-3",children:o("form.cancel")}),n.jsx("button",{type:"submit",className:"btn-primary text-xs py-1.5 px-3",children:o(c?"session.save":"session.create")})]})]})}var Pf={exports:{}},_y;function aO(){return _y||(_y=1,(function(e,s){(function(i,a){e.exports=a()})(globalThis,(()=>(()=>{var i={4567:function(m,o,c){var d=this&&this.__decorate||function(w,y,E,T){var j,R=arguments.length,N=R<3?y:T===null?T=Object.getOwnPropertyDescriptor(y,E):T;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")N=Reflect.decorate(w,y,E,T);else for(var D=w.length-1;D>=0;D--)(j=w[D])&&(N=(R<3?j(N):R>3?j(y,E,N):j(y,E))||N);return R>3&&N&&Object.defineProperty(y,E,N),N},p=this&&this.__param||function(w,y){return function(E,T){y(E,T,w)}};Object.defineProperty(o,"__esModule",{value:!0}),o.AccessibilityManager=void 0;const u=c(9042),x=c(9924),b=c(844),C=c(4725),S=c(2585),g=c(3656);let _=o.AccessibilityManager=class extends b.Disposable{constructor(w,y,E,T){super(),this._terminal=w,this._coreBrowserService=E,this._renderService=T,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="",this._accessibilityContainer=this._coreBrowserService.mainDocument.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=this._coreBrowserService.mainDocument.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let j=0;j<this._terminal.rows;j++)this._rowElements[j]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[j]);if(this._topBoundaryFocusListener=j=>this._handleBoundaryFocus(j,0),this._bottomBoundaryFocusListener=j=>this._handleBoundaryFocus(j,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions(),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=this._coreBrowserService.mainDocument.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this.register(new x.TimeBasedDebouncer(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this.register(this._terminal.onResize((j=>this._handleResize(j.rows)))),this.register(this._terminal.onRender((j=>this._refreshRows(j.start,j.end)))),this.register(this._terminal.onScroll((()=>this._refreshRows()))),this.register(this._terminal.onA11yChar((j=>this._handleChar(j)))),this.register(this._terminal.onLineFeed((()=>this._handleChar(`
670
+ `).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 p-2 border border-accent/40 focus:outline-none focus:border-accent resize-y"}),n.jsxs("div",{className:"mt-1 flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>d(null),disabled:x,className:"px-2.5 py-1 text-2xs rounded border border-warm-200 hover:bg-warm-50 disabled:opacity-40",children:a("svn.cancel")}),n.jsx("button",{onClick:()=>g(w.name),disabled:x,className:"px-2.5 py-1 text-2xs font-semibold rounded bg-accent text-white hover:bg-accent/90 disabled:opacity-40",children:a("svn.saveProperty")})]})]}):n.jsx("pre",{className:"mt-1 text-2xs font-mono text-warm-600 bg-warm-50 dark:bg-warm-800/40 rounded p-2 whitespace-pre-wrap break-all",children:w.value||"—"})]},w.name))})]}),n.jsx("div",{className:"px-4 py-3 border-t border-warm-100 shrink-0 text-right",children:n.jsx("button",{onClick:i,className:"px-3 py-1.5 text-xs rounded border border-warm-200 hover:bg-warm-50",children:a("svn.close")})})]})})}const Z8=["architect","developer","reviewer","pm","tester","custom"],Ii=["#6366f1","#8b5cf6","#ec4899","#f43f5e","#f97316","#eab308","#22c55e","#14b8a6","#06b6d4","#3b82f6"],eO=[{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 tO({projectId:e,agents:s,onAgentsChange:i}){const{t:a,lang:h}=dt(),[f,m]=k.useState(!1),[o,c]=k.useState(null),[d,p]=k.useState(""),[u,x]=k.useState("developer"),[b,C]=k.useState(""),[S,g]=k.useState(""),[_,w]=k.useState(Ii[0]),[y,E]=k.useState(!1),[T,j]=k.useState(!1),R=()=>{p(""),x("developer"),C(""),g(""),w(Ii[Math.floor(Math.random()*Ii.length)]),E(!1),m(!1),c(null)},N=async()=>{if(!(!d.trim()||!b.trim())){j(!0);try{if(o){const z=await a4(o,{name:d,role:u,system_prompt:b,avatar_color:_,cli_tool:S||null,can_implement:y});i(s.map(P=>P.id===o?z:P))}else{const z=await i4(e,{name:d,role:u,system_prompt:b,avatar_color:_,...S?{cli_tool:S}:{},can_implement:y});i([...s,z])}R()}finally{j(!1)}}},D=z=>{c(z.id),p(z.name),x(z.role),C(z.system_prompt),g(z.cli_tool||""),w(z.avatar_color||Ii[0]),E(!!z.can_implement),m(!0)},A=async z=>{await o4(z),i(s.filter(P=>P.id!==z))},O=z=>{p(h==="ko"?z.nameKo:z.name),x(z.role),C(z.prompt),w(Ii[Math.floor(Math.random()*Ii.length)]),m(!0)};return n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700",children:a("agents.title")}),n.jsxs("button",{onClick:()=>{R(),m(!0)},className:"btn btn-sm text-xs",children:["+ ",a("agents.add")]})]}),s.length===0&&!f&&n.jsx(Vi,{icon:mN,title:a("agents.empty"),size:"sm"}),n.jsx("div",{className:"space-y-2",children:s.map(z=>{var P;return n.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:[n.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:z.avatar_color||"#6366f1"},children:z.name.charAt(0).toUpperCase()}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",children:z.name}),!!z.can_implement&&n.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium bg-amber-50 text-amber-700 border border-amber-200",title:a("agents.canImplementHelp"),children:[n.jsx(Hv,{size:10}),a("agents.canImplementBadge")]})]}),n.jsxs("div",{className:"text-xs text-warm-400 mt-0.5",children:[a(`agents.roles.${z.role}`)||z.role,z.cli_tool&&n.jsxs("span",{className:"ml-1.5 text-warm-300",children:["· ",((P=wr.find(F=>F.value===z.cli_tool))==null?void 0:P.label)||z.cli_tool]})]})]}),n.jsxs("div",{className:"flex gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx("button",{onClick:()=>D(z),className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-lg transition-colors",children:n.jsx(ci,{size:16})}),n.jsx("button",{onClick:()=>A(z.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-red-50 rounded-lg transition-colors",children:n.jsx(Ln,{size:16})})]})]},z.id)})}),f&&n.jsxs("div",{className:"space-y-5 p-5 rounded-xl border border-warm-200 bg-theme-card shadow-sm",children:[!o&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.presets")}),n.jsx("div",{className:"flex flex-wrap gap-2",children:eO.map(z=>n.jsx("button",{onClick:()=>O(z),className:"px-3 py-1.5 text-xs rounded-lg bg-warm-50 text-warm-600 hover:bg-warm-100 border border-warm-150 hover:border-warm-300 transition-colors font-medium",children:h==="ko"?z.nameKo:z.name},z.role))})]}),n.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.name")}),n.jsx("input",{type:"text",value:d,onChange:z=>p(z.target.value),className:"input-field",placeholder:h==="ko"?"에이전트 이름":"Agent name"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.role")}),n.jsx("select",{value:u,onChange:z=>x(z.target.value),className:"input-field",children:Z8.map(z=>n.jsx("option",{value:z,children:a(`agents.roles.${z}`)},z))})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.systemPrompt")}),n.jsx("textarea",{value:b,onChange:z=>C(z.target.value),rows:5,className:"input-field resize-y min-h-[100px]",placeholder:h==="ko"?"이 에이전트의 전문 분야와 관점을 설명하세요...":"Describe this agent's expertise and perspective..."}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1.5",children:h==="ko"?"토론 시 이 에이전트가 어떤 관점에서 발언할지 결정합니다.":"Determines what perspective this agent brings to the discussion."})]}),n.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.cliTool")}),n.jsxs("select",{value:S,onChange:z=>g(z.target.value),className:"input-field text-sm",children:[n.jsx("option",{value:"",children:h==="ko"?"프로젝트 기본값 사용":"Use project default"}),wr.map(z=>n.jsx("option",{value:z.value,children:z.label},z.value))]})]})}),n.jsx("div",{children:n.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:y,onChange:z=>E(z.target.checked),className:"mt-0.5 w-4 h-4 rounded border-warm-300 text-warm-600 focus:ring-warm-400"}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-warm-700",children:[n.jsx(Hv,{size:12}),a("agents.canImplement")]}),n.jsx("p",{className:"text-2xs text-warm-400 mt-0.5",children:a("agents.canImplementHelp")})]})]})}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:a("agents.color")}),n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.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:_},children:d?d.charAt(0).toUpperCase():"?"}),n.jsx("div",{className:"flex flex-wrap gap-2",children:Ii.map(z=>n.jsx("button",{onClick:()=>w(z),className:`w-7 h-7 rounded-full transition-all ${_===z?"ring-2 ring-offset-2 ring-warm-400 scale-110":"hover:scale-105 opacity-70 hover:opacity-100"}`,style:{backgroundColor:z}},z))})]})]}),n.jsxs("div",{className:"flex justify-end gap-3 pt-2 border-t border-warm-100",children:[n.jsx("button",{onClick:R,className:"btn btn-sm text-xs text-warm-500",children:a("header.cancel")}),n.jsx("button",{onClick:N,disabled:!d.trim()||!b.trim()||T,className:"btn btn-sm btn-primary text-xs",children:a(T?"header.saving":"header.save")})]})]})]})}const nO={title:"",description:"",agent_ids:[],max_rounds:3,auto_implement:!1,implement_agent_id:"",memory_inject_mode:"none",memory_node_ids:[],memory_raw_file_paths:[],use_worktree:!0};function W_({agents:e,projectId:s,initialValues:i,mode:a,allowAdvancedFields:h=!0,submitting:f=!1,isGitRepo:m=!1,projectUseWorktree:o=!0,onSubmit:c,onCancel:d}){const{t:p,lang:u}=dt(),x=()=>({...nO,use_worktree:o,...i}),[b,C]=k.useState(x),[S,g]=k.useState(!1);k.useEffect(()=>{C(x())},[i,o]);const _=(N,D)=>{C(A=>({...A,[N]:D}))},w=N=>p(`agents.roles.${N.role}`)||N.role,y=b.agent_ids.map(N=>e.find(D=>D.id===N)).filter(N=>!!N),E=N=>{C(D=>{const A=D.agent_ids.includes(N)?D.agent_ids.filter(O=>O!==N):[...D.agent_ids,N];return{...D,agent_ids:A,implement_agent_id:D.implement_agent_id&&!A.includes(D.implement_agent_id)?"":D.implement_agent_id}})},T=(N,D)=>{C(A=>{const O=A.agent_ids.indexOf(N),z=O+D;if(O===-1||z<0||z>=A.agent_ids.length)return A;const P=[...A.agent_ids];return[P[O],P[z]]=[P[z],P[O]],{...A,agent_ids:P}})},j=async()=>{!b.title.trim()||!b.description.trim()||h&&b.agent_ids.length<2||h&&b.auto_implement&&!b.implement_agent_id||await c({title:b.title.trim(),description:b.description.trim(),agent_ids:b.agent_ids,max_rounds:b.max_rounds,auto_implement:h?b.auto_implement:!1,implement_agent_id:h&&b.auto_implement?b.implement_agent_id:void 0,memory_inject_mode:h?b.memory_inject_mode:"none",memory_node_ids:h&&b.memory_inject_mode==="selected"?b.memory_node_ids:[],memory_raw_file_paths:h?b.memory_raw_file_paths:[],...m?{use_worktree:b.use_worktree}:{}})},R=b.title.trim()&&b.description.trim()&&(!h||b.agent_ids.length>=2)&&(!h||!b.auto_implement||!!b.implement_agent_id);return n.jsxs("div",{className:"card p-5 space-y-5",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:u==="ko"?"제목":"Title"}),n.jsx("input",{type:"text",value:b.title,onChange:N=>_("title",N.target.value),className:"input-field",placeholder:u==="ko"?"토론 주제를 입력하세요":"Enter discussion topic"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:u==="ko"?"설명":"Description"}),n.jsx("textarea",{value:b.description,onChange:N=>_("description",N.target.value),rows:4,className:"input-field resize-y min-h-[80px]",placeholder:u==="ko"?"토론할 기능이나 의사결정 배경을 자세히 설명하세요":"Describe the feature to discuss in detail"})]}),h&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{children:[n.jsxs("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:[p("discussions.agents"),n.jsx("span",{className:"ml-2 text-warm-400 font-normal",children:u==="ko"?`(${b.agent_ids.length}명 선택됨 · 최소 2명)`:`(${b.agent_ids.length} selected · min 2)`})]}),n.jsx("p",{className:"text-[11px] text-warm-400",children:u==="ko"?"참여 에이전트를 고른 뒤, 아래 발언 순서에서 실제 토론 진행 순서를 조정합니다.":"Select participants first, then adjust the actual speaking order below."})]}),n.jsxs("div",{className:"rounded-2xl border border-accent/30 bg-accent/5 p-3 space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-semibold text-warm-700",children:u==="ko"?"발언 순서":"Speaking Order"}),n.jsx("p",{className:"text-[11px] text-warm-500 mt-1",children:u==="ko"?"1라운드 기준이며, 이후 라운드에도 같은 순서로 반복됩니다.":"This order is used for round 1 and repeats in later rounds."})]}),y.length>=2&&n.jsx("div",{className:"text-2xs font-semibold text-accent-dark bg-white/70 border border-accent/30 rounded-full px-2.5 py-1",children:u==="ko"?"순서 조정 가능":"Reorder enabled"})]}),y.length===0?n.jsx("div",{className:"rounded-xl border border-dashed border-warm-200 bg-white/70 px-4 py-5 text-center text-xs text-warm-400",children:u==="ko"?"에이전트를 선택하면 여기서 발언 순서를 바로 조정할 수 있습니다.":"Select agents to adjust the speaking order here."}):n.jsx("div",{className:"space-y-2",children:y.map((N,D)=>{const A=D===0,O=D===y.length-1,z=A?u==="ko"?"첫 발언":"Opens the round":O?u==="ko"?"마지막 발언":"Closes the round":u==="ko"?`${D+1}번째 발언`:`Turn ${D+1}`;return n.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-warm-200 bg-white/85 px-3 py-3 md:flex-row md:items-center md:justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[n.jsx("div",{className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-accent text-[11px] font-bold text-white flex-shrink-0",children:D+1}),n.jsx("div",{className:"w-6 h-6 rounded-full flex-shrink-0 border border-white/80 shadow-sm",style:{backgroundColor:N.avatar_color||"#6366f1"}}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-semibold text-warm-700 truncate",children:N.name}),n.jsxs("div",{className:"text-[11px] text-warm-500",children:[w(N)," · ",z]})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{type:"button",onClick:()=>T(N.id,-1),disabled:A,className:"px-2.5 py-1.5 rounded-lg border border-warm-200 bg-warm-50 text-[11px] font-medium text-warm-600 hover:bg-warm-100 disabled:opacity-40 disabled:cursor-not-allowed",children:u==="ko"?"앞으로":"Earlier"}),n.jsx("button",{type:"button",onClick:()=>T(N.id,1),disabled:O,className:"px-2.5 py-1.5 rounded-lg border border-warm-200 bg-warm-50 text-[11px] font-medium text-warm-600 hover:bg-warm-100 disabled:opacity-40 disabled:cursor-not-allowed",children:u==="ko"?"뒤로":"Later"})]})]},N.id)})})]}),e.length===0?n.jsx("p",{className:"text-xs text-warm-400 py-3 px-4 bg-warm-50 rounded-xl border border-warm-150",children:p("agents.empty")}):n.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:e.map(N=>{const D=b.agent_ids.includes(N.id),A=b.agent_ids.indexOf(N.id)+1;return n.jsxs("button",{type:"button",onClick:()=>E(N.id),className:`text-left rounded-2xl border px-3.5 py-3 transition-all ${D?"border-accent bg-accent/5 shadow-sm":"border-warm-200 bg-warm-50 hover:border-warm-300 hover:bg-warm-100"}`,children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[n.jsx("div",{className:"w-6 h-6 rounded-full flex-shrink-0 border border-white/80 shadow-sm",style:{backgroundColor:N.avatar_color||"#6366f1"}}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold truncate ${D?"text-warm-700":"text-warm-600"}`,children:N.name}),n.jsx("div",{className:"text-[11px] text-warm-400",children:w(N)})]})]}),D&&n.jsx("div",{className:"inline-flex items-center justify-center min-w-7 h-7 rounded-full bg-accent text-[11px] font-bold text-white flex-shrink-0",children:A})]}),n.jsx("div",{className:`mt-3 text-[11px] ${D?"text-accent-dark":"text-warm-400"}`,children:D?u==="ko"?`${A}번째 발언으로 참여 중`:`Included as turn ${A}`:u==="ko"?"클릭해서 참여 에이전트에 추가":"Click to add this participant"})]},N.id)})})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-2",children:p("discussions.maxRounds")}),n.jsx("input",{type:"number",min:1,max:10,value:b.max_rounds,onChange:N=>_("max_rounds",Number(N.target.value)),className:"input-field w-24 text-center"}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1.5",children:p("discussions.roundExplain")})]}),m&&n.jsxs("div",{children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:b.use_worktree,onChange:N=>_("use_worktree",N.target.checked),className:"rounded border-warm-300 text-accent focus:ring-accent"}),n.jsx(Ga,{size:14,className:"text-warm-500"}),n.jsx("span",{className:"text-xs font-medium text-warm-500",children:u==="ko"?"워크트리에서 격리 실행":"Run in isolated worktree"})]}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1 ml-6",children:u==="ko"?"체크하면 전용 브랜치/워크트리를 만들어 격리 실행합니다. 해제하면 프로젝트 원본 경로에서 바로 실행합니다.":"Checked: create a dedicated branch/worktree for isolation. Unchecked: run directly in the project root."})]}),s&&n.jsx("div",{children:n.jsx(jp,{projectId:s,mode:b.memory_inject_mode,selectedPaths:b.memory_raw_file_paths,includeLinked:S,onChange:(N,D,A)=>{C(O=>({...O,memory_inject_mode:N,memory_node_ids:[],memory_raw_file_paths:D})),g(A)}})}),n.jsxs("div",{children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:b.auto_implement,onChange:N=>{const D=N.target.checked;C(A=>({...A,auto_implement:D,implement_agent_id:D?A.implement_agent_id:""}))},className:"rounded border-warm-300 text-accent focus:ring-accent"}),n.jsx("span",{className:"text-xs font-medium text-warm-500",children:p("discussions.autoImplement")})]}),n.jsx("p",{className:"text-2xs text-warm-400 mt-1 ml-6",children:p("discussions.autoImplementHint")}),b.auto_implement&&n.jsxs("div",{className:"mt-2 ml-6",children:[n.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1",children:p("discussions.selectAgent")}),n.jsxs("select",{value:b.implement_agent_id,onChange:N=>_("implement_agent_id",N.target.value),className:"input-field text-xs w-56",children:[n.jsx("option",{value:"",children:u==="ko"?"-- 에이전트 선택 --":"-- Select agent --"}),y.map(N=>n.jsxs("option",{value:N.id,children:[N.name," (",w(N),")"]},N.id))]})]})]})]}),n.jsxs("div",{className:"flex justify-end gap-3 pt-2 border-t border-warm-100",children:[n.jsx("button",{type:"button",onClick:d,className:"btn-secondary text-xs py-2",children:p("header.cancel")}),n.jsx("button",{type:"button",onClick:j,disabled:!R||f,className:"btn-primary text-xs py-2",children:p(f?"header.saving":a==="create"?"discussions.add":"header.save")})]})]})}const sO={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",paused:"bg-amber-100 text-amber-700",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",merged:"bg-accent/10 text-accent"};function rO({projectId:e,discussions:s,isGitRepo:i,projectUseWorktree:a,onAddDiscussion:h,onStartDiscussion:f,onStopDiscussion:m,onDeleteDiscussion:o}){const{t:c}=dt(),d=fi(),[p,u]=k.useState([]),[x,b]=k.useState(!1),[C,S]=k.useState(!1),[g,_]=k.useState(!1),[w,y]=k.useState(null);k.useEffect(()=>{b1(e).then(u).catch(()=>{})},[e]);const E=k.useCallback(async j=>{_(!0);try{const R=await l4(e,j);h(R),b(!1)}finally{_(!1)}},[e,h]),T=j=>{try{return JSON.parse(j).map(N=>p.find(D=>D.id===N)).filter(N=>!!N)}catch{return[]}};return n.jsxs("div",{className:"space-y-4 animate-fade-in min-h-[50vh]",onContextMenu:j=>{hi(j)||(j.preventDefault(),y({x:j.clientX,y:j.clientY}))},children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:c("discussions.title")}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>S(!C),className:"btn-secondary text-xs py-2",children:c("agents.manage")}),n.jsxs("button",{onClick:()=>b(!x),className:"btn-primary text-xs py-2",children:["+ ",c("discussions.add")]})]})]}),C&&n.jsx("div",{className:"card p-4",children:n.jsx(tO,{projectId:e,agents:p,onAgentsChange:u})}),x&&n.jsx(W_,{agents:p,projectId:e,mode:"create",submitting:g,isGitRepo:i,projectUseWorktree:a,onSubmit:E,onCancel:()=>b(!1)}),s.length===0&&!x?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:CE,title:c("discussions.empty"),description:c("discussions.emptyHint")})}):n.jsx("div",{className:"space-y-3",children:s.map((j,R)=>{const N=T(j.agent_ids),D=j.status==="pending"||j.status==="paused"||j.status==="failed",A=j.status==="running";return n.jsx("div",{className:"card p-4 hover:shadow-md transition-all cursor-pointer animate-slide-up",onClick:()=>d(`/projects/${e}/discussions/${j.id}`),style:{animationDelay:`${R*50}ms`},children:n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:j.title}),n.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-semibold uppercase ${sO[j.status]||""}`,children:c(`status.${j.status}`)||j.status})]}),n.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:j.description}),n.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[n.jsxs("span",{className:"text-2xs text-warm-400",children:[c("discussions.round")," ",j.current_round,"/",j.max_rounds]}),n.jsx("div",{className:"flex -space-x-1",children:N.slice(0,5).map(O=>n.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:O.avatar_color||"#6366f1"},title:O.name,children:O.name.charAt(0)},O.id))})]})]}),n.jsxs("div",{className:"flex gap-1",onClick:O=>O.stopPropagation(),children:[D&&n.jsx("button",{onClick:()=>f(j.id),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded transition-colors",title:c("header.runAll"),children:n.jsx(kr,{size:16})}),A&&n.jsx("button",{onClick:()=>m(j.id),className:"p-1.5 text-amber-600 hover:bg-amber-50 rounded transition-colors",title:c("discussions.pause"),children:n.jsx(Zm,{size:16})}),n.jsx("button",{onClick:()=>o(j.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded transition-colors",title:c("todo.delete"),children:n.jsx(Ln,{size:16})})]})]})},j.id)})}),w&&n.jsx(Cr,{x:w.x,y:w.y,onClose:()=>y(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>{b(!0)},children:[n.jsx(mn,{size:14}),c("discussions.add")]})})]})}function iO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}let Bf=!1;function Np(e){var o,c;const s=window.electronAPI;if(!(s!=null&&s.imeReset)||Bf)return!1;Bf=!0;let i=!1;const a=()=>{i=!0,Bf=!1,window.clearTimeout(f),window.removeEventListener("focus",m)},h=()=>{if(!i)try{e()}finally{a()}},f=window.setTimeout(h,1e3),m=()=>{requestAnimationFrame(()=>{requestAnimationFrame(h)})};return window.addEventListener("focus",m),(c=(o=document.activeElement)==null?void 0:o.blur)==null||c.call(o),s.imeReset(!0),!0}function wy({projectId:e,initial:s,onSave:i,onCancel:a,projectCliTool:h,isGitRepo:f,projectUseWorktree:m}){const{t:o}=dt(),c=!!s,[d,p]=k.useState((s==null?void 0:s.title)??""),[u,x]=k.useState((s==null?void 0:s.description)??""),[b,C]=k.useState((s==null?void 0:s.cliTool)??(h||"")),[S,g]=k.useState((s==null?void 0:s.useWorktree)??!!m),[_,w]=k.useState((s==null?void 0:s.memoryInjectMode)??"none"),[y,E]=k.useState((s==null?void 0:s.memoryRawFilePaths)??[]),[T,j]=k.useState(!1),[R,N]=k.useState((s==null?void 0:s.tagId)??null),[D,A]=k.useState([]),[O,z]=k.useState([]),P=k.useRef(null);k.useEffect(()=>{var J;Np(()=>{var W;return(W=P.current)==null?void 0:W.focus()})||(J=P.current)==null||J.focus();const B=Array.from(document.querySelectorAll(".xterm-helper-textarea")),U=B.map(W=>({el:W,tabIndex:W.tabIndex,ariaHidden:W.getAttribute("aria-hidden")}));return B.forEach(W=>{W.tabIndex=-1,W.setAttribute("aria-hidden","true"),W.blur()}),()=>{U.forEach(({el:W,tabIndex:oe,ariaHidden:ee})=>{W.tabIndex=oe,ee===null?W.removeAttribute("aria-hidden"):W.setAttribute("aria-hidden",ee)})}},[]),k.useEffect(()=>{let B=!1;return sp().then(U=>{B||A(U)}).catch(()=>{}),!c&&f&&rp().then(U=>{B||g(U.defaultUseWorktree)}).catch(()=>{}),()=>{B=!0}},[c,f]),k.useEffect(()=>{let B=!1;return op().then(U=>{B||z(U)}).catch(()=>{}),()=>{B=!0}},[]);const F=wr.filter(B=>B.supportsInteractive),H=B=>{const U=O.find(J=>J.tool===B.value);return B.value==="raw-shell"?U!=null&&U.version?`Raw Shell (${U.version})`:B.label:U&&!U.installed?`${B.label}${o("session.cliNotInstalled")}`:B.label},q=(b||h||"claude")==="raw-shell",Y=B=>{B.preventDefault(),i(d.trim(),u.trim(),b||void 0,S,_,[],y,R)},I=D.find(B=>B.id===R)??null;return n.jsxs("form",{onSubmit:Y,className:"card p-4 space-y-3 animate-scale-in",children:[n.jsx("input",{ref:P,type:"text",value:d,onChange:B=>p(B.target.value),placeholder:o("session.title"),className:"input-field text-sm"}),!q&&n.jsx("textarea",{value:u,onChange:B=>x(B.target.value),placeholder:o("session.description"),className:"input-field text-sm min-h-[60px] max-h-[280px] resize-y [field-sizing:content]",rows:2}),n.jsx("div",{className:"flex gap-2",children:n.jsxs("select",{value:b,onChange:B=>C(B.target.value),className:"input-field text-xs flex-1",children:[n.jsxs("option",{value:"",children:[o("session.cliTool")," (Default)"]}),F.map(B=>n.jsx("option",{value:B.value,children:H(B)},B.value))]})}),D.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[I&&n.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:I.color,borderColor:"rgba(0,0,0,0.08)"}}),n.jsxs("select",{value:R??"",onChange:B=>N(B.target.value||null),className:"input-field text-xs flex-1",children:[n.jsx("option",{value:"",children:o("session.tag.none")}),D.map(B=>n.jsx("option",{value:B.id,children:B.name},B.id))]})]}),f&&n.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-500 cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:S,onChange:B=>g(B.target.checked),className:"rounded border-warm-300"}),n.jsx(Ga,{size:14}),o("session.worktree")]}),!q&&n.jsx(jp,{projectId:e,mode:_,selectedPaths:y,includeLinked:T,onChange:(B,U,J)=>{w(B),E(U),j(J)}}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:a,className:"btn-secondary text-xs py-1.5 px-3",children:o("form.cancel")}),n.jsx("button",{type:"submit",className:"btn-primary text-xs py-1.5 px-3",children:o(c?"session.save":"session.create")})]})]})}var Pf={exports:{}},_y;function aO(){return _y||(_y=1,(function(e,s){(function(i,a){e.exports=a()})(globalThis,(()=>(()=>{var i={4567:function(m,o,c){var d=this&&this.__decorate||function(w,y,E,T){var j,R=arguments.length,N=R<3?y:T===null?T=Object.getOwnPropertyDescriptor(y,E):T;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")N=Reflect.decorate(w,y,E,T);else for(var D=w.length-1;D>=0;D--)(j=w[D])&&(N=(R<3?j(N):R>3?j(y,E,N):j(y,E))||N);return R>3&&N&&Object.defineProperty(y,E,N),N},p=this&&this.__param||function(w,y){return function(E,T){y(E,T,w)}};Object.defineProperty(o,"__esModule",{value:!0}),o.AccessibilityManager=void 0;const u=c(9042),x=c(9924),b=c(844),C=c(4725),S=c(2585),g=c(3656);let _=o.AccessibilityManager=class extends b.Disposable{constructor(w,y,E,T){super(),this._terminal=w,this._coreBrowserService=E,this._renderService=T,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="",this._accessibilityContainer=this._coreBrowserService.mainDocument.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=this._coreBrowserService.mainDocument.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let j=0;j<this._terminal.rows;j++)this._rowElements[j]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[j]);if(this._topBoundaryFocusListener=j=>this._handleBoundaryFocus(j,0),this._bottomBoundaryFocusListener=j=>this._handleBoundaryFocus(j,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions(),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=this._coreBrowserService.mainDocument.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this.register(new x.TimeBasedDebouncer(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this.register(this._terminal.onResize((j=>this._handleResize(j.rows)))),this.register(this._terminal.onRender((j=>this._refreshRows(j.start,j.end)))),this.register(this._terminal.onScroll((()=>this._refreshRows()))),this.register(this._terminal.onA11yChar((j=>this._handleChar(j)))),this.register(this._terminal.onLineFeed((()=>this._handleChar(`
671
671
  `)))),this.register(this._terminal.onA11yTab((j=>this._handleTab(j)))),this.register(this._terminal.onKey((j=>this._handleKey(j.key)))),this.register(this._terminal.onBlur((()=>this._clearLiveRegion()))),this.register(this._renderService.onDimensionsChange((()=>this._refreshRowsDimensions()))),this.register((0,g.addDisposableDomListener)(document,"selectionchange",(()=>this._handleSelectionChange()))),this.register(this._coreBrowserService.onDprChange((()=>this._refreshRowsDimensions()))),this._refreshRows(),this.register((0,b.toDisposable)((()=>{this._accessibilityContainer.remove(),this._rowElements.length=0})))}_handleTab(w){for(let y=0;y<w;y++)this._handleChar(" ")}_handleChar(w){this._liveRegionLineCount<21&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==w&&(this._charsToAnnounce+=w):this._charsToAnnounce+=w,w===`
672
672
  `&&(this._liveRegionLineCount++,this._liveRegionLineCount===21&&(this._liveRegion.textContent+=u.tooMuchOutput)))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(w){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(w)||this._charsToConsume.push(w)}_refreshRows(w,y){this._liveRegionDebouncer.refresh(w,y,this._terminal.rows)}_renderRows(w,y){const E=this._terminal.buffer,T=E.lines.length.toString();for(let j=w;j<=y;j++){const R=E.lines.get(E.ydisp+j),N=[],D=(R==null?void 0:R.translateToString(!0,void 0,void 0,N))||"",A=(E.ydisp+j+1).toString(),O=this._rowElements[j];O&&(D.length===0?(O.innerText=" ",this._rowColumns.set(O,[0,1])):(O.textContent=D,this._rowColumns.set(O,N)),O.setAttribute("aria-posinset",A),O.setAttribute("aria-setsize",T))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(w,y){const E=w.target,T=this._rowElements[y===0?1:this._rowElements.length-2];if(E.getAttribute("aria-posinset")===(y===0?"1":`${this._terminal.buffer.lines.length}`)||w.relatedTarget!==T)return;let j,R;if(y===0?(j=E,R=this._rowElements.pop(),this._rowContainer.removeChild(R)):(j=this._rowElements.shift(),R=E,this._rowContainer.removeChild(j)),j.removeEventListener("focus",this._topBoundaryFocusListener),R.removeEventListener("focus",this._bottomBoundaryFocusListener),y===0){const N=this._createAccessibilityTreeNode();this._rowElements.unshift(N),this._rowContainer.insertAdjacentElement("afterbegin",N)}else{const N=this._createAccessibilityTreeNode();this._rowElements.push(N),this._rowContainer.appendChild(N)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(y===0?-1:1),this._rowElements[y===0?1:this._rowElements.length-2].focus(),w.preventDefault(),w.stopImmediatePropagation()}_handleSelectionChange(){var D;if(this._rowElements.length===0)return;const w=document.getSelection();if(!w)return;if(w.isCollapsed)return void(this._rowContainer.contains(w.anchorNode)&&this._terminal.clearSelection());if(!w.anchorNode||!w.focusNode)return void console.error("anchorNode and/or focusNode are null");let y={node:w.anchorNode,offset:w.anchorOffset},E={node:w.focusNode,offset:w.focusOffset};if((y.node.compareDocumentPosition(E.node)&Node.DOCUMENT_POSITION_PRECEDING||y.node===E.node&&y.offset>E.offset)&&([y,E]=[E,y]),y.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(y={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(y.node))return;const T=this._rowElements.slice(-1)[0];if(E.node.compareDocumentPosition(T)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(E={node:T,offset:((D=T.textContent)==null?void 0:D.length)??0}),!this._rowContainer.contains(E.node))return;const j=({node:A,offset:O})=>{const z=A instanceof Text?A.parentNode:A;let P=parseInt(z==null?void 0:z.getAttribute("aria-posinset"),10)-1;if(isNaN(P))return console.warn("row is invalid. Race condition?"),null;const F=this._rowColumns.get(z);if(!F)return console.warn("columns is null. Race condition?"),null;let H=O<F.length?F[O]:F.slice(-1)[0]+1;return H>=this._terminal.cols&&(++P,H=0),{row:P,column:H}},R=j(y),N=j(E);if(R&&N){if(R.row>N.row||R.row===N.row&&R.column>=N.column)throw new Error("invalid range");this._terminal.select(R.column,R.row,(N.row-R.row)*this._terminal.cols-R.column+N.column)}}_handleResize(w){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let y=this._rowContainer.children.length;y<this._terminal.rows;y++)this._rowElements[y]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[y]);for(;this._rowElements.length>w;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){const w=this._coreBrowserService.mainDocument.createElement("div");return w.setAttribute("role","listitem"),w.tabIndex=-1,this._refreshRowDimensions(w),w}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){this._accessibilityContainer.style.width=`${this._renderService.dimensions.css.canvas.width}px`,this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let w=0;w<this._terminal.rows;w++)this._refreshRowDimensions(this._rowElements[w])}}_refreshRowDimensions(w){w.style.height=`${this._renderService.dimensions.css.cell.height}px`}};o.AccessibilityManager=_=d([p(1,S.IInstantiationService),p(2,C.ICoreBrowserService),p(3,C.IRenderService)],_)},3614:(m,o)=>{function c(x){return x.replace(/\r?\n/g,"\r")}function d(x,b){return b?"\x1B[200~"+x+"\x1B[201~":x}function p(x,b,C,S){x=d(x=c(x),C.decPrivateModes.bracketedPasteMode&&S.rawOptions.ignoreBracketedPasteMode!==!0),C.triggerDataEvent(x,!0),b.value=""}function u(x,b,C){const S=C.getBoundingClientRect(),g=x.clientX-S.left-10,_=x.clientY-S.top-10;b.style.width="20px",b.style.height="20px",b.style.left=`${g}px`,b.style.top=`${_}px`,b.style.zIndex="1000",b.focus()}Object.defineProperty(o,"__esModule",{value:!0}),o.rightClickHandler=o.moveTextAreaUnderMouseCursor=o.paste=o.handlePasteEvent=o.copyHandler=o.bracketTextForPaste=o.prepareTextForTerminal=void 0,o.prepareTextForTerminal=c,o.bracketTextForPaste=d,o.copyHandler=function(x,b){x.clipboardData&&x.clipboardData.setData("text/plain",b.selectionText),x.preventDefault()},o.handlePasteEvent=function(x,b,C,S){x.stopPropagation(),x.clipboardData&&p(x.clipboardData.getData("text/plain"),b,C,S)},o.paste=p,o.moveTextAreaUnderMouseCursor=u,o.rightClickHandler=function(x,b,C,S,g){u(x,b,C),g&&S.rightClickSelect(x),b.value=S.selectionText,b.select()}},7239:(m,o,c)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.ColorContrastCache=void 0;const d=c(1505);o.ColorContrastCache=class{constructor(){this._color=new d.TwoKeyMap,this._css=new d.TwoKeyMap}setCss(p,u,x){this._css.set(p,u,x)}getCss(p,u){return this._css.get(p,u)}setColor(p,u,x){this._color.set(p,u,x)}getColor(p,u){return this._color.get(p,u)}clear(){this._color.clear(),this._css.clear()}}},3656:(m,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.addDisposableDomListener=void 0,o.addDisposableDomListener=function(c,d,p,u){c.addEventListener(d,p,u);let x=!1;return{dispose:()=>{x||(x=!0,c.removeEventListener(d,p,u))}}}},3551:function(m,o,c){var d=this&&this.__decorate||function(_,w,y,E){var T,j=arguments.length,R=j<3?w:E===null?E=Object.getOwnPropertyDescriptor(w,y):E;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")R=Reflect.decorate(_,w,y,E);else for(var N=_.length-1;N>=0;N--)(T=_[N])&&(R=(j<3?T(R):j>3?T(w,y,R):T(w,y))||R);return j>3&&R&&Object.defineProperty(w,y,R),R},p=this&&this.__param||function(_,w){return function(y,E){w(y,E,_)}};Object.defineProperty(o,"__esModule",{value:!0}),o.Linkifier=void 0;const u=c(3656),x=c(8460),b=c(844),C=c(2585),S=c(4725);let g=o.Linkifier=class extends b.Disposable{get currentLink(){return this._currentLink}constructor(_,w,y,E,T){super(),this._element=_,this._mouseService=w,this._renderService=y,this._bufferService=E,this._linkProviderService=T,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this.register(new x.EventEmitter),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this.register(new x.EventEmitter),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this.register((0,b.getDisposeArrayDisposable)(this._linkCacheDisposables)),this.register((0,b.toDisposable)((()=>{var j;this._lastMouseEvent=void 0,(j=this._activeProviderReplies)==null||j.clear()}))),this.register(this._bufferService.onResize((()=>{this._clearCurrentLink(),this._wasResized=!0}))),this.register((0,u.addDisposableDomListener)(this._element,"mouseleave",(()=>{this._isMouseOut=!0,this._clearCurrentLink()}))),this.register((0,u.addDisposableDomListener)(this._element,"mousemove",this._handleMouseMove.bind(this))),this.register((0,u.addDisposableDomListener)(this._element,"mousedown",this._handleMouseDown.bind(this))),this.register((0,u.addDisposableDomListener)(this._element,"mouseup",this._handleMouseUp.bind(this)))}_handleMouseMove(_){this._lastMouseEvent=_;const w=this._positionFromMouseEvent(_,this._element,this._mouseService);if(!w)return;this._isMouseOut=!1;const y=_.composedPath();for(let E=0;E<y.length;E++){const T=y[E];if(T.classList.contains("xterm"))break;if(T.classList.contains("xterm-hover"))return}this._lastBufferCell&&w.x===this._lastBufferCell.x&&w.y===this._lastBufferCell.y||(this._handleHover(w),this._lastBufferCell=w)}_handleHover(_){if(this._activeLine!==_.y||this._wasResized)return this._clearCurrentLink(),this._askForLink(_,!1),void(this._wasResized=!1);this._currentLink&&this._linkAtPosition(this._currentLink.link,_)||(this._clearCurrentLink(),this._askForLink(_,!0))}_askForLink(_,w){var E,T;this._activeProviderReplies&&w||((E=this._activeProviderReplies)==null||E.forEach((j=>{j==null||j.forEach((R=>{R.link.dispose&&R.link.dispose()}))})),this._activeProviderReplies=new Map,this._activeLine=_.y);let y=!1;for(const[j,R]of this._linkProviderService.linkProviders.entries())w?(T=this._activeProviderReplies)!=null&&T.get(j)&&(y=this._checkLinkProviderResult(j,_,y)):R.provideLinks(_.y,(N=>{var A,O;if(this._isMouseOut)return;const D=N==null?void 0:N.map((z=>({link:z})));(A=this._activeProviderReplies)==null||A.set(j,D),y=this._checkLinkProviderResult(j,_,y),((O=this._activeProviderReplies)==null?void 0:O.size)===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(_.y,this._activeProviderReplies)}))}_removeIntersectingLinks(_,w){const y=new Set;for(let E=0;E<w.size;E++){const T=w.get(E);if(T)for(let j=0;j<T.length;j++){const R=T[j],N=R.link.range.start.y<_?0:R.link.range.start.x,D=R.link.range.end.y>_?this._bufferService.cols:R.link.range.end.x;for(let A=N;A<=D;A++){if(y.has(A)){T.splice(j--,1);break}y.add(A)}}}}_checkLinkProviderResult(_,w,y){var j;if(!this._activeProviderReplies)return y;const E=this._activeProviderReplies.get(_);let T=!1;for(let R=0;R<_;R++)this._activeProviderReplies.has(R)&&!this._activeProviderReplies.get(R)||(T=!0);if(!T&&E){const R=E.find((N=>this._linkAtPosition(N.link,w)));R&&(y=!0,this._handleNewLink(R))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!y)for(let R=0;R<this._activeProviderReplies.size;R++){const N=(j=this._activeProviderReplies.get(R))==null?void 0:j.find((D=>this._linkAtPosition(D.link,w)));if(N){y=!0,this._handleNewLink(N);break}}return y}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(_){if(!this._currentLink)return;const w=this._positionFromMouseEvent(_,this._element,this._mouseService);w&&this._mouseDownLink===this._currentLink&&this._linkAtPosition(this._currentLink.link,w)&&this._currentLink.link.activate(_,this._currentLink.link.text)}_clearCurrentLink(_,w){this._currentLink&&this._lastMouseEvent&&(!_||!w||this._currentLink.link.range.start.y>=_&&this._currentLink.link.range.end.y<=w)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,(0,b.disposeArray)(this._linkCacheDisposables))}_handleNewLink(_){if(!this._lastMouseEvent)return;const w=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);w&&this._linkAtPosition(_.link,w)&&(this._currentLink=_,this._currentLink.state={decorations:{underline:_.link.decorations===void 0||_.link.decorations.underline,pointerCursor:_.link.decorations===void 0||_.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,_.link,this._lastMouseEvent),_.link.decorations={},Object.defineProperties(_.link.decorations,{pointerCursor:{get:()=>{var y,E;return(E=(y=this._currentLink)==null?void 0:y.state)==null?void 0:E.decorations.pointerCursor},set:y=>{var E;(E=this._currentLink)!=null&&E.state&&this._currentLink.state.decorations.pointerCursor!==y&&(this._currentLink.state.decorations.pointerCursor=y,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",y))}},underline:{get:()=>{var y,E;return(E=(y=this._currentLink)==null?void 0:y.state)==null?void 0:E.decorations.underline},set:y=>{var E,T,j;(E=this._currentLink)!=null&&E.state&&((j=(T=this._currentLink)==null?void 0:T.state)==null?void 0:j.decorations.underline)!==y&&(this._currentLink.state.decorations.underline=y,this._currentLink.state.isHovered&&this._fireUnderlineEvent(_.link,y))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange((y=>{if(!this._currentLink)return;const E=y.start===0?0:y.start+1+this._bufferService.buffer.ydisp,T=this._bufferService.buffer.ydisp+1+y.end;if(this._currentLink.link.range.start.y>=E&&this._currentLink.link.range.end.y<=T&&(this._clearCurrentLink(E,T),this._lastMouseEvent)){const j=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);j&&this._askForLink(j,!1)}}))))}_linkHover(_,w,y){var E;(E=this._currentLink)!=null&&E.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(w,!0),this._currentLink.state.decorations.pointerCursor&&_.classList.add("xterm-cursor-pointer")),w.hover&&w.hover(y,w.text)}_fireUnderlineEvent(_,w){const y=_.range,E=this._bufferService.buffer.ydisp,T=this._createLinkUnderlineEvent(y.start.x-1,y.start.y-E-1,y.end.x,y.end.y-E-1,void 0);(w?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(T)}_linkLeave(_,w,y){var E;(E=this._currentLink)!=null&&E.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(w,!1),this._currentLink.state.decorations.pointerCursor&&_.classList.remove("xterm-cursor-pointer")),w.leave&&w.leave(y,w.text)}_linkAtPosition(_,w){const y=_.range.start.y*this._bufferService.cols+_.range.start.x,E=_.range.end.y*this._bufferService.cols+_.range.end.x,T=w.y*this._bufferService.cols+w.x;return y<=T&&T<=E}_positionFromMouseEvent(_,w,y){const E=y.getCoords(_,w,this._bufferService.cols,this._bufferService.rows);if(E)return{x:E[0],y:E[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(_,w,y,E,T){return{x1:_,y1:w,x2:y,y2:E,cols:this._bufferService.cols,fg:T}}};o.Linkifier=g=d([p(1,S.IMouseService),p(2,S.IRenderService),p(3,C.IBufferService),p(4,S.ILinkProviderService)],g)},9042:(m,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.tooMuchOutput=o.promptLabel=void 0,o.promptLabel="Terminal input",o.tooMuchOutput="Too much output to announce, navigate to rows manually to read"},3730:function(m,o,c){var d=this&&this.__decorate||function(S,g,_,w){var y,E=arguments.length,T=E<3?g:w===null?w=Object.getOwnPropertyDescriptor(g,_):w;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")T=Reflect.decorate(S,g,_,w);else for(var j=S.length-1;j>=0;j--)(y=S[j])&&(T=(E<3?y(T):E>3?y(g,_,T):y(g,_))||T);return E>3&&T&&Object.defineProperty(g,_,T),T},p=this&&this.__param||function(S,g){return function(_,w){g(_,w,S)}};Object.defineProperty(o,"__esModule",{value:!0}),o.OscLinkProvider=void 0;const u=c(511),x=c(2585);let b=o.OscLinkProvider=class{constructor(S,g,_){this._bufferService=S,this._optionsService=g,this._oscLinkService=_}provideLinks(S,g){var D;const _=this._bufferService.buffer.lines.get(S-1);if(!_)return void g(void 0);const w=[],y=this._optionsService.rawOptions.linkHandler,E=new u.CellData,T=_.getTrimmedLength();let j=-1,R=-1,N=!1;for(let A=0;A<T;A++)if(R!==-1||_.hasContent(A)){if(_.loadCell(A,E),E.hasExtendedAttrs()&&E.extended.urlId){if(R===-1){R=A,j=E.extended.urlId;continue}N=E.extended.urlId!==j}else R!==-1&&(N=!0);if(N||R!==-1&&A===T-1){const O=(D=this._oscLinkService.getLinkData(j))==null?void 0:D.uri;if(O){const z={start:{x:R+1,y:S},end:{x:A+(N||A!==T-1?0:1),y:S}};let P=!1;if(!(y!=null&&y.allowNonHttpProtocols))try{const F=new URL(O);["http:","https:"].includes(F.protocol)||(P=!0)}catch{P=!0}P||w.push({text:O,range:z,activate:(F,H)=>y?y.activate(F,H,z):C(0,H),hover:(F,H)=>{var $;return($=y==null?void 0:y.hover)==null?void 0:$.call(y,F,H,z)},leave:(F,H)=>{var $;return($=y==null?void 0:y.leave)==null?void 0:$.call(y,F,H,z)}})}N=!1,E.hasExtendedAttrs()&&E.extended.urlId?(R=A,j=E.extended.urlId):(R=-1,j=-1)}}g(w)}};function C(S,g){if(confirm(`Do you want to navigate to ${g}?
673
673
 
@@ -680,7 +680,7 @@ WARNING: This link could potentially be dangerous`)){const _=window.open();if(_)
680
680
  `)&&G(ce),he.current=!0,Z(!0)},Fe=k.useRef(Ie);Fe.current=Ie;const be=()=>{var ce,Q;he.current=!1,Z(!1),(ce=W.current)==null||ce.clearDecorations(),ge({index:-1,count:0});try{(Q=R.current)==null||Q.focus()}catch{}},Ue=k.useRef(be);Ue.current=be;const Pe=k.useRef(0),tt=(ce,Q,V)=>{const re=++Pe.current,te=Date.now();J({dataUrl:ce,bytes:Q});const se=()=>{const le=Math.max(0,600-(Date.now()-te));setTimeout(()=>{Pe.current===re&&J(null)},le)};V.then(se,se)},ke=k.useRef(tt);ke.current=tt;const{warning:pe}=mi(),Ne=k.useRef(pe);Ne.current=pe;const[Le,ze]=k.useState(null),Ke=k.useRef(()=>{});k.useEffect(()=>{if(!Le)return;const ce=()=>ze(null),Q=V=>{V.key==="Escape"&&ce()};return window.addEventListener("keydown",Q,!0),window.addEventListener("resize",ce),window.addEventListener("scroll",ce,!0),()=>{window.removeEventListener("keydown",Q,!0),window.removeEventListener("resize",ce),window.removeEventListener("scroll",ce,!0)}},[Le]),k.useEffect(()=>{var rt;const ce=j.current;if(!ce)return;const Q=Me=>{const vt=Me.type;_.current&&vt==="session:terminal-input"||h(Me)},V=new oO.Terminal({fontFamily:Rt,fontSize:c,lineHeight:1,cursorBlink:s,convertEol:!1,scrollback:5e3,theme:g.current??Yc,minimumContrastRatio:Ly(g.current??Yc),allowProposedApi:!0,macOptionIsMeta:!0}),re=/Mac|iPhone|iPad|iPod/.test(navigator.platform);let te=0;const se=async()=>{var vt;if(_.current){console.debug("[paste] inputBlocked → ignored");return}if(!window.isSecureContext)return;if(te=Date.now(),!w.current)try{const bt=await navigator.clipboard.read();for(const St of bt){const Et=St.types.find(Ht=>Ht.startsWith("image/"));if(Et){const Ht=await St.getType(Et),pn=new FileReader;pn.onload=()=>{const gn=pn.result;console.debug("[paste] image via clipboard.read(), bytes=",Ht.size);const yn=k1(e,gn);yn.catch(ms=>console.warn("[paste] pasteImage failed:",ms)),ke.current(gn,Ht.size,yn)},pn.readAsDataURL(Ht);return}}}catch(bt){console.debug("[paste] clipboard.read() rejected, falling through:",bt)}let Me=null;try{Me=await navigator.clipboard.readText()}catch(bt){console.warn("[paste] clipboard.readText() failed:",bt)}if(Me){const bt=Me.includes(`
681
681
  `);console.debug("[paste] sending text, len=",Me.length,"multiline=",bt),Q({type:"session:terminal-input",sessionId:e,input:V_(Me)});return}try{const bt=await D4(e);if(bt.path){console.debug("[paste] empty browser clipboard, using OS file path:",bt.path),Q({type:"session:terminal-input",sessionId:e,input:bt.path});return}}catch(bt){console.debug("[paste] getClipboardImagePath failed:",bt)}console.warn("[paste] no content available (text empty, no image, no file path)"),(vt=Ne.current)==null||vt.call(Ne,"붙여넣을 내용을 클립보드에서 읽지 못했습니다. 우클릭 → 붙여넣기를 시도해 보세요.")};V.attachCustomKeyEventHandler(Me=>{var pn;if(Me.type!=="keydown")return!0;const vt=re?Me.metaKey:Me.ctrlKey,bt=re?Me.ctrlKey:Me.metaKey,St=vt&&!bt&&!Me.altKey&&!Me.shiftKey,Et=vt&&!bt&&!Me.altKey&&Me.shiftKey,Ht=Me.key.toLowerCase();if(Ht==="tab"&&(St||Et)&&y.current)return Me.preventDefault(),y.current(Et?"prev":"next"),!1;if(Ht==="f"&&St)return Me.preventDefault(),Fe.current(),!1;if(Ht==="t"&&St||Ht==="r"&&Et||Ht==="f5"&&!Me.ctrlKey&&!Me.metaKey&&!Me.altKey&&!Me.shiftKey)return Me.preventDefault(),!1;if(Ht==="d"&&Et&&E.current)return Me.preventDefault(),E.current(),!1;if(Et&&["a","p","o","m","x"].includes(Ht))return Me.preventDefault(),!1;if(St&&Ht==="c"){const gn=V.getSelection();return gn?(Me.preventDefault(),(pn=navigator.clipboard)==null||pn.writeText(gn).catch(()=>{}),V.clearSelection(),!1):!re}if(St&&Ht==="v"||Me.altKey&&!Me.ctrlKey&&!Me.metaKey&&!Me.shiftKey&&Ht==="v")return Me.preventDefault(),se(),!1;if((Me.ctrlKey||Me.metaKey)&&!Me.altKey){if(Me.key==="+"||Me.key==="=")return Me.preventDefault(),Ho(e,1),!1;if(Me.key==="-"||Me.key==="_")return Me.preventDefault(),Ho(e,-1),!1}return!0});const le=new cO.FitAddon;V.loadAddon(le),V.open(ce),R.current=V,N.current=le;try{const Me=new Cy.CanvasAddon;V.loadAddon(Me),D.current=Me}catch{D.current=null}const ve=new hO.SearchAddon;V.loadAddon(ve),W.current=ve;const Ce=ve.onDidChangeResults(({resultIndex:Me,resultCount:vt})=>{xe.current({index:Me,count:vt})}),De=()=>{he.current&&Ue.current()};ce.addEventListener("focusin",De),V.attachCustomWheelEventHandler(Me=>!Me.ctrlKey&&!Me.metaKey?!0:(Me.preventDefault(),Me.__zoomHandled=!0,Me.deltaY!==0&&Ho(e,Me.deltaY<0?1:-1),!1));const Qe=Me=>{if(Me.ctrlKey||Me.metaKey){if(Me.preventDefault(),Me.stopPropagation(),Me.deltaY===0||Me.__zoomHandled)return;Ho(e,Me.deltaY<0?1:-1);return}Me.stopPropagation()};ce.addEventListener("wheel",Qe,{passive:!1});const ut=window.electronAPI,ot=(rt=ut==null?void 0:ut.onTerminalZoom)==null?void 0:rt.call(ut,Me=>{var Et;const vt=ce.matches(":hover"),bt=document.querySelector("[data-term-container]:hover")!==null,St=!!V.textarea&&document.activeElement===V.textarea;(Et=ut.imeLog)==null||Et.call(ut,{reason:"zoom:recv",dir:Me,hovered:vt,anyTermHovered:bt,focused:St,path:window.location.pathname}),(vt||!bt&&St)&&Ho(e,Me==="in"?1:-1)});Ke.current=()=>{se()};const Je=Me=>{Me.preventDefault(),ze({x:Me.clientX,y:Me.clientY,hasSelection:V.hasSelection()})};ce.addEventListener("contextmenu",Je);try{le.fit()}catch{}if(u){const Me=document.activeElement;if(!(!!Me&&(Me.tagName==="INPUT"||Me.tagName==="TEXTAREA"||Me.tagName==="SELECT"||Me.isContentEditable))&&(Me===null||Me===document.body))try{V.focus()}catch{}}const qe=()=>{const Me=V.cols,vt=V.rows;Me===A.current.cols&&vt===A.current.rows||(A.current={cols:Me,rows:vt},h({type:"session:resize",sessionId:e,cols:Me,rows:vt}))};H.current=qe;const ft=f(e,Me=>{try{V.write(Me)}catch{}}),lt=m(Me=>{Me.type==="session:replay-end"&&Me.sessionId===e&&q(!1)}),xt=()=>Date.now()-te<300,pt=()=>w.current,st=Me=>B.current(Me),ht=(Me,vt,bt)=>ke.current(Me,vt,bt),Re=xO()?kO({container:ce,term:V,sessionId:e,sendMessage:Q}):SO({container:ce,term:V,sessionId:e,sendMessage:Q,isPasteAlreadyHandled:xt,isImagePasteDisabled:pt,onComposingChange:st,onImagePasted:ht}),ct=100;let Oe=null,ie=0,_e=!1;const je={cols:V.cols,rows:V.rows},we=new ResizeObserver(()=>{if(Oe!==null)return;const Me=Math.max(0,ct-(performance.now()-ie));Oe=setTimeout(()=>{Oe=null,requestAnimationFrame(()=>{var bt;ie=performance.now();const vt=ce.getBoundingClientRect();if(!(vt.width===0||vt.height===0)){try{le.fit(),(V.cols!==je.cols||V.rows!==je.rows)&&(je.cols=V.cols,je.rows=V.rows,V.refresh(0,V.rows-1))}catch{}!_e&&V.cols>=20&&V.rows>=5&&(_e=!0,(bt=F.current)==null||bt.call(F,V.cols,V.rows)),O.current&&clearTimeout(O.current),O.current=setTimeout(qe,150)}})},Me)});return we.observe(ce),()=>{var Me;we.disconnect(),Oe!==null&&clearTimeout(Oe),O.current&&clearTimeout(O.current),z.current&&clearTimeout(z.current),ce.removeEventListener("wheel",Qe),ot==null||ot(),ce.removeEventListener("contextmenu",Je),ze(null),Re(),ft(),lt();try{h({type:"session:unsubscribe",sessionId:e})}catch{}ce.removeEventListener("focusin",De),Ce.dispose(),W.current=null,(Me=D.current)==null||Me.dispose(),D.current=null,V.dispose(),R.current=null,N.current=null,H.current=null,P.current=!1}},[e]),k.useEffect(()=>{if(!i||P.current)return;P.current=!0;const ce=R.current;ce&&ce.cols>0&&ce.rows>0&&(A.current={cols:0,rows:0},h({type:"session:resize",sessionId:e,cols:ce.cols,rows:ce.rows})),h({type:"session:subscribe",sessionId:e})},[i,e,h]),k.useEffect(()=>{R.current&&(R.current.options.cursorBlink=s)},[s]),k.useEffect(()=>{var re;if(!u)return;const ce=document.activeElement;if(!(!(!!ce&&ce.classList.contains("xterm-helper-textarea"))&&!!ce&&(ce.tagName==="INPUT"||ce.tagName==="TEXTAREA"||ce.tagName==="SELECT"||ce.isContentEditable)))try{(re=R.current)==null||re.focus()}catch{}},[u]),k.useEffect(()=>{const ce=R.current,Q=N.current;if(!ce||!Q||ce.options.fontSize===c)return;if(ce.options.fontSize=c,D.current){try{D.current.dispose()}catch{}D.current=null;try{const re=new Cy.CanvasAddon;ce.loadAddon(re),D.current=re}catch{}}if(ce.buffer.active.type==="alternate"){z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{var re;(re=T.current)==null||re.call(T)},500);return}try{Q.fit(),ce.refresh(0,ce.rows-1)}catch{}ce.cols===A.current.cols&&ce.rows===A.current.rows||(z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{var re;(re=H.current)==null||re.call(H)},300))},[c,e]),k.useEffect(()=>{const ce=R.current;if(ce){ce.options.theme=d??Yc,ce.options.minimumContrastRatio=Ly(d??Yc);try{ce.refresh(0,ce.rows-1)}catch{}}},[d]),k.useEffect(()=>{if(!ee)return;const ce=W.current;if(!ce)return;const Q=setTimeout(()=>{X?ce.findNext(X,{...Uf,incremental:!0}):(ce.clearDecorations(),ge({index:-1,count:0}))},120);return()=>clearTimeout(Q)},[X,ee]),k.useEffect(()=>{var ce;ee&&((ce=oe.current)==null||ce.select())},[ee]);const Ve=(d==null?void 0:d.background)??He.bg,de=()=>{var ce;X&&((ce=W.current)==null||ce.findNext(X,Uf))},fe=()=>{var ce;X&&((ce=W.current)==null||ce.findPrevious(X,Uf))};return n.jsxs("div",{style:{position:"relative",background:Ve,padding:12,height:o,width:"100%",boxSizing:"border-box",overflow:"hidden"},children:[$&&i&&n.jsx("div",{style:{position:"absolute",top:8,right:12,fontFamily:Rt,fontSize:11,color:He.dim,zIndex:1,pointerEvents:"none"},children:"loading history…"}),n.jsx("div",{ref:j,"data-term-container":!0,style:{height:"100%",width:"100%"}}),ee&&n.jsxs("div",{style:{position:"absolute",top:8,right:12,zIndex:5,display:"flex",alignItems:"center",gap:6,padding:"4px 6px",background:"rgba(0,0,0,0.85)",border:`1px solid ${He.separator}`,borderRadius:6,fontFamily:Rt,fontSize:12,boxShadow:"0 4px 16px rgba(0,0,0,0.5)"},children:[n.jsx("input",{ref:oe,value:X,onChange:ce=>G(ce.target.value),onKeyDown:ce=>{ce.key==="Enter"?(ce.preventDefault(),ce.shiftKey?fe():de()):ce.key==="Escape"&&(ce.preventDefault(),be())},placeholder:"검색",spellCheck:!1,style:{width:160,background:"transparent",border:"none",outline:"none",color:He.bright,fontFamily:Rt,fontSize:12}}),n.jsx("span",{style:{color:He.dim,minWidth:44,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:X?me.count>0?`${me.index+1}/${me.count}`:"0/0":""}),[{label:"↑",title:"이전 (Shift+Enter)",onClick:fe},{label:"↓",title:"다음 (Enter)",onClick:de},{label:"×",title:"닫기 (Esc)",onClick:be}].map(ce=>n.jsx("button",{type:"button",title:ce.title,onClick:ce.onClick,className:"px-1.5 rounded hover:bg-white/10",style:{color:He.bright,lineHeight:"18px"},children:ce.label},ce.label))]}),(Y||U)&&n.jsxs("div",{style:{position:"absolute",right:12,bottom:12,maxWidth:"calc(100% - 24px)",display:"flex",flexDirection:"column",alignItems:"flex-end",gap:6,zIndex:2,pointerEvents:"none"},children:[U&&n.jsxs("div",{style:{padding:4,background:"rgba(0,0,0,0.72)",border:`1px solid ${He.separator}`,borderRadius:4,maxWidth:"100%"},children:[n.jsx("img",{src:U.dataUrl,alt:"",style:{display:"block",maxWidth:220,maxHeight:140,borderRadius:2}}),n.jsxs("div",{style:{fontFamily:Rt,fontSize:11,color:He.dim,marginTop:3},children:["이미지 붙여넣음 · ",pO(U.bytes)]})]}),Y&&n.jsx("div",{style:{maxWidth:"100%",padding:"3px 8px",background:"rgba(0,0,0,0.72)",border:`1px solid ${He.separator}`,borderRadius:4,fontFamily:Rt,fontSize:Math.max(12,c),color:He.bright,lineHeight:1.3,whiteSpace:"pre",overflow:"hidden",textOverflow:"ellipsis"},children:Y})]}),Le&&en.createPortal((()=>{const V=Math.max(8,Math.min(Le.x,window.innerWidth-184-8)),re=Math.max(8,Math.min(Le.y,window.innerHeight-116-8)),te=()=>ze(null),se=()=>{var De,Qe;const Ce=((De=R.current)==null?void 0:De.getSelection())??"";Ce&&((Qe=navigator.clipboard)==null||Qe.writeText(Ce).catch(()=>{})),te()},le=()=>{Ke.current(),te()},ve=()=>{var Ce;(Ce=R.current)==null||Ce.selectAll(),te()};return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"fixed",inset:0,zIndex:2147483646},onMouseDown:te,onContextMenu:Ce=>{Ce.preventDefault(),te()}}),n.jsxs("div",{role:"menu",style:{position:"fixed",left:V,top:re,zIndex:2147483647,minWidth:168,background:He.bg,border:`1px solid ${He.separator}`,borderRadius:6,padding:4,fontFamily:Rt,fontSize:13,boxShadow:"0 8px 24px rgba(0,0,0,0.5)"},children:[n.jsx("button",{type:"button",disabled:!Le.hasSelection,onClick:se,className:"w-full text-left px-3 py-1.5 rounded hover:bg-white/10 disabled:opacity-40 disabled:cursor-not-allowed",style:{color:He.bright},children:"복사"}),n.jsx("button",{type:"button",onClick:le,className:"w-full text-left px-3 py-1.5 rounded hover:bg-white/10",style:{color:He.bright},children:"붙여넣기"}),n.jsx("button",{type:"button",onClick:ve,className:"w-full text-left px-3 py-1.5 rounded hover:bg-white/10",style:{color:He.bright},children:"전체 선택"})]})]})})(),document.body)]})}function xO(){if(typeof navigator>"u")return!1;const e=navigator.userAgent;return/iPad|iPhone|iPod/.test(e)||/Mac/.test(e)&&navigator.maxTouchPoints>1||/Android/i.test(e)}const du=[12593,12594,12596,12599,12600,12601,12609,12610,12611,12613,12614,12615,12616,12617,12618,12619,12620,12621,12622],Y_=[12623,12624,12625,12626,12627,12628,12629,12630,12631,12632,12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643],Dy=[0,12593,12594,12595,12596,12597,12598,12599,12601,12602,12603,12604,12605,12606,12607,12608,12609,12610,12612,12613,12614,12615,12616,12618,12619,12620,12621,12622];function X_(e){return e>=12593&&e<=12622}function J_(e){return e>=12623&&e<=12643}function vO(e){return X_(e)||J_(e)}function bO(e){return e>=44032&&e<=55203}function yO(){return{cho:-1,jung:-1,jong:0}}function Lp(e){return e.cho<0&&e.jung<0&&e.jong===0}function br(e){return Lp(e)?"":e.cho>=0&&e.jung>=0?String.fromCharCode(44032+(e.cho*21+e.jung)*28+e.jong):e.cho>=0?String.fromCharCode(du[e.cho]):e.jung>=0?String.fromCharCode(Y_[e.jung]):""}function Ty(e){const s=br(e);return e.cho=-1,e.jung=-1,e.jong=0,s}function wO(e,s){if(J_(s)){const i=Y_.indexOf(s);if(i<0)return"";if(e.cho<0&&e.jung<0||e.cho>=0&&e.jung<0)return e.jung=i,"";if(e.cho<0&&e.jung>=0){const m=br(e);return e.jung=i,m}if(e.jong===0){const m=br(e);return e.cho=-1,e.jung=i,e.jong=0,m}const a=Dy[e.jong],h=du.indexOf(a);e.jong=0;const f=br(e);return h>=0?(e.cho=h,e.jung=i,e.jong=0):(e.cho=-1,e.jung=i,e.jong=0),f}if(X_(s)){const i=du.indexOf(s),a=Dy.indexOf(s);if(e.cho<0&&e.jung<0)return i>=0?(e.cho=i,""):String.fromCharCode(s);if(e.cho>=0&&e.jung<0){const f=String.fromCharCode(du[e.cho]);return i>=0?(e.cho=i,f):(e.cho=-1,f+String.fromCharCode(s))}if(e.cho<0&&e.jung>=0){const f=br(e);return e.jung=-1,i>=0?(e.cho=i,f):f+String.fromCharCode(s)}if(e.jong===0){if(a>0)return e.jong=a,"";const f=br(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,f}const h=br(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,i<0?h+String.fromCharCode(s):h}return""}function _O(e,s){const i=br(e),a=s-44032;return e.cho=Math.floor(a/588),e.jung=Math.floor(a/28)%21,e.jong=a%28,i}function Ry(e){return Lp(e)?!1:(e.cho=-1,e.jung=-1,e.jong=0,!0)}function SO({container:e,term:s,sessionId:i,sendMessage:a,isPasteAlreadyHandled:h,isImagePasteDisabled:f,onComposingChange:m,onImagePasted:o}){let c=!1;const d=D=>{try{m==null||m(D)}catch{}};let p=null;const u=(D,A={})=>{var O,z;try{(z=(O=window.electronAPI)==null?void 0:O.imeLog)==null||z.call(O,{reason:D,path:window.location.pathname,...A})}catch{}},x=(D=!1)=>{try{const A=e.querySelector(".xterm-helper-textarea"),O=e.querySelector(".xterm-screen");if(!A||!O){D||u("pos:no-dom",{hasHelper:!!A,hasScreen:!!O});return}const z=s.cols,P=s.rows;if(z<=0||P<=0){D||u("pos:no-grid",{cols:z,rows:P});return}const F=O.getBoundingClientRect();if(F.width===0||F.height===0){D||u("pos:zero-screen",{w:F.width,h:F.height});return}const H=F.width/z,$=F.height/P,q=s.buffer.active,Y=Math.min(q.cursorX,z-1),I=Math.max(0,Math.min(q.cursorY,P-1));A.style.left=`${Y*H}px`,A.style.top=`${I*$}px`,A.style.width=`${Math.max(H,1)}px`,A.style.height=`${Math.max($,1)}px`,D||u("pos:applied",{cursorX:Y,cursorY:I,left:Y*H,top:I*$})}catch{}};x();let b=0;const C=()=>{b||(b=requestAnimationFrame(()=>{b=0,x(!0)}))},S=s.onCursorMove(C),g=()=>{var D;c=!0,x(),d("");try{const A=document.activeElement,O=e.querySelector(".xterm-helper-textarea"),z=O==null?void 0:O.getBoundingClientRect();u("compositionstart",{activeTag:A==null?void 0:A.tagName,activeClass:A==null?void 0:A.className,activeIsHelper:!!A&&((D=A.classList)==null?void 0:D.contains("xterm-helper-textarea")),helperStyleLeft:O==null?void 0:O.style.left,helperStyleTop:O==null?void 0:O.style.top,helperRectLeft:z==null?void 0:z.left,helperRectTop:z==null?void 0:z.top,visibility:document.visibilityState,hasFocus:document.hasFocus(),cols:s.cols,rows:s.rows})}catch{}},_=D=>{d(D.data??""),u("compositionupdate",{data:D.data??""})},w=D=>{c=!1,d("");const A=D.data;u("compositionend",{data:A??"",sent:!!A}),A&&(p=A,a({type:"session:terminal-input",sessionId:i,input:A}))},y=D=>{var z,P;if(h()){D.preventDefault();return}const A=(z=D.clipboardData)==null?void 0:z.items;if(A&&!(f!=null&&f())){for(let F=0;F<A.length;F++)if(A[F].type.startsWith("image/")){D.preventDefault();const H=A[F].getAsFile();if(!H)return;const $=new FileReader;$.onload=()=>{const q=$.result;console.debug("[paste-fallback] image via paste event, bytes=",H.size);const Y=k1(i,q,H.name);Y.catch(I=>console.warn("[paste-fallback] pasteImage failed:",I)),o==null||o(q,H.size,Y)},$.readAsDataURL(H);return}}const O=(P=D.clipboardData)==null?void 0:P.getData("text/plain");if(O){D.preventDefault();const F=O.includes(`
682
682
  `);console.debug("[paste-fallback] sending text, len=",O.length,"multiline=",F),a({type:"session:terminal-input",sessionId:i,input:V_(O)})}else console.debug("[paste-fallback] paste event had no usable text/image")},E=D=>{var F,H;const A=(F=D.dataTransfer)==null?void 0:F.files;if(!A||A.length===0)return;D.preventDefault();const O=(H=window.electronAPI)==null?void 0:H.getDroppedFilePath;if(!O)return;const z=[];for(let $=0;$<A.length;$++){const q=O(A[$]);q&&z.push(q)}const P=mO(z);P&&a({type:"session:terminal-input",sessionId:i,input:P})},T=D=>{var A,O;(O=(A=D.dataTransfer)==null?void 0:A.types)!=null&&O.includes("Files")&&(D.preventDefault(),D.dataTransfer.dropEffect="copy")},j=()=>{if(c)return;Np(()=>{try{s.focus()}catch{}})&&u("focus-rescue")},R=D=>{var A,O;u("keydown",{key:D.key,composing:c,activeIsHelper:!!((O=(A=document.activeElement)==null?void 0:A.classList)!=null&&O.contains("xterm-helper-textarea")),hasFocus:document.hasFocus()}),document.hasFocus()||j()};e.addEventListener("keydown",R,!0),e.addEventListener("compositionstart",g,!0),e.addEventListener("compositionupdate",_,!0),e.addEventListener("compositionend",w,!0),e.addEventListener("paste",y,!0),e.addEventListener("dragover",T),e.addEventListener("drop",E);const N=s.onData(D=>{if(!c){if(p!==null&&D===p){p=null;return}p=null,a({type:"session:terminal-input",sessionId:i,input:D})}});return()=>{N.dispose(),S.dispose(),b&&cancelAnimationFrame(b),e.removeEventListener("keydown",R,!0),e.removeEventListener("compositionstart",g,!0),e.removeEventListener("compositionupdate",_,!0),e.removeEventListener("compositionend",w,!0),e.removeEventListener("paste",y,!0),e.removeEventListener("dragover",T),e.removeEventListener("drop",E),d("")}}function kO({container:e,term:s,sessionId:i,sendMessage:a}){const h=e.querySelector(".xterm-helper-textarea");let f="",m=0;h&&(f=h.style.display,m=h.tabIndex,h.style.display="none",h.tabIndex=-1),getComputedStyle(e).position==="static"&&(e.style.position="relative");const o=document.createElement("textarea");o.setAttribute("autocomplete","off"),o.setAttribute("lang","ko"),o.setAttribute("inputmode","text"),o.rows=1,Object.assign(o.style,{position:"absolute",background:"transparent",border:"none",outline:"none",padding:"0",margin:"0",fontFamily:Rt,fontSize:"16px",lineHeight:"1.2",resize:"none",overflow:"hidden",whiteSpace:"pre",caretColor:"rgba(255,255,255,0.001)",zIndex:"5"});const c=()=>{Object.assign(o.style,{inset:"0",left:"auto",top:"auto",width:"100%",height:"100%",color:"transparent"})},d=()=>{const j=e.querySelector(".xterm-screen");if(!j)return;const R=s.cols,N=s.rows;if(R<=0||N<=0)return;const D=j.clientWidth/R,A=j.clientHeight/N,O=s.buffer.active.cursorX,z=s.buffer.active.cursorY,P=j.getBoundingClientRect(),F=e.getBoundingClientRect();Object.assign(o.style,{inset:"auto",left:`${P.left-F.left+O*D}px`,top:`${P.top-F.top+z*A}px`,width:`${Math.max(D*30,240)}px`,height:`${Math.max(A,20)}px`,color:He.text})};c(),e.appendChild(o);let p=!1;const u=yO();let x=null;const b=()=>{x&&(clearTimeout(x),x=null)},C=j=>{j&&a({type:"session:terminal-input",sessionId:i,input:j})},S=()=>{const j=Ty(u);j&&C(j)},g=()=>{const j=br(u);o.value=j,j?d():c()},_=()=>{b(),x=setTimeout(()=>{x=null,S(),o.value="",c()},600)},w=()=>{p=!0,b(),S(),d()},y=j=>{p=!1,j.data&&C(j.data),o.value="",c()};o.addEventListener("compositionstart",w),o.addEventListener("compositionend",y);const E=j=>{if(p)return;const R=j;switch(R.inputType){case"insertCompositionText":case"insertFromComposition":return;case"deleteContentBackward":b(),Ry(u)?g():(C(""),o.value="",c());return;case"insertLineBreak":case"insertParagraph":b(),S(),C("\r"),o.value="",c();return;default:if(!R.data){g();return}b();let N="";for(const D of R.data){const A=D.codePointAt(0);vO(A)?N+=wO(u,A):bO(A)?N+=_O(u,A):(N+=Ty(u),N+=D)}C(N),g(),Lp(u)||_()}};o.addEventListener("input",E);const T=j=>{if(p||j.isComposing)return;let R=null;switch(j.key){case"Enter":R="\r";break;case"Backspace":R="";break;case"Tab":R=" ";break;case"Escape":R="\x1B";break;case"ArrowUp":R="\x1B[A";break;case"ArrowDown":R="\x1B[B";break;case"ArrowRight":R="\x1B[C";break;case"ArrowLeft":R="\x1B[D";break;case"Home":R="\x1B[H";break;case"End":R="\x1B[F";break}if(R){if(j.preventDefault(),b(),j.key==="Backspace"){if(Ry(u)){g();return}}else S();C(R),o.value="",c();return}if(j.ctrlKey&&!j.metaKey&&!j.altKey&&j.key.length===1){const N=j.key.toUpperCase().charCodeAt(0);N>=64&&N<=95&&(j.preventDefault(),b(),S(),C(String.fromCharCode(N-64)),o.value="",c())}};return o.addEventListener("keydown",T),()=>{b(),S(),o.remove(),h&&(h.style.display=f,h.tabIndex=m)}}function CO({sessionId:e,onClose:s,projectId:i,onEvent:a,sendMessage:h}){const{t:f}=dt(),[m,o]=k.useState([]),[c,d]=k.useState(!0),[p,u]=k.useState(null),[x,b]=k.useState(!1),[C,S]=k.useState(null),[g,_]=k.useState(""),[w,y]=k.useState(!1),[E,T]=k.useState(0),[j,R]=k.useState([]),[N,D]=k.useState(null),[A,O]=k.useState(!1),[z,P]=k.useState({from:null,now:null}),F=k.useRef(new Map),H=k.useCallback(()=>T(Y=>Y+1),[]);k.useEffect(()=>{if(!(!h||!i))return h({type:"git:watch",projectId:i}),()=>h({type:"git:unwatch",projectId:i})},[h,i]),k.useEffect(()=>{if(!(!a||!i))return a(Y=>{Y.type==="git:changed"&&Y.projectId===i&&H()})},[a,i,H]),k.useEffect(()=>{let Y=!1;return w4(e).then(I=>{Y||R(I.snapshots??[])}).catch(()=>{Y||R([])}),()=>{Y=!0}},[e,E]),k.useEffect(()=>{let Y=!1;return b(!0),b4(e,N??void 0).then(I=>{if(Y)return;d(I.available),u(I.reason??null);const B=I.available&&I.files?I.files.map(U=>({path:U.path,status:U.status,additions:U.insertions,deletions:U.deletions})):[];o(B),F.current.clear(),P({from:N,now:I.now??null}),S(U=>U&&B.some(J=>J.path===U)?U:B.length>0?B[0].path:null)}).catch(()=>{Y||(d(!1),u("error"),o([]))}).finally(()=>{Y||b(!1)}),()=>{Y=!0}},[e,N,E]),k.useEffect(()=>{if(!C){_("");return}const Y=`${z.now??""}:${C}`,I=F.current.get(Y);if(I!==void 0){_(I),y(!1);return}let B=!1;return y(!0),_(""),y4(e,C,z.from??void 0,z.now??void 0).then(U=>{if(B)return;const J=U.available&&U.diff?U.diff:"";F.current.set(Y,J),_(J)}).catch(()=>{B||_("")}).finally(()=>{B||y(!1)}),()=>{B=!0}},[e,C,z]);const $=k.useCallback(()=>{O(!0),_4(e).then(Y=>{if(Y.available&&Y.snapshots){R(Y.snapshots);const I=Y.snapshots[Y.snapshots.length-1];I&&D(I.sha)}}).catch(()=>{}).finally(()=>O(!1))},[e]),q=Y=>{const I=new Date(Y);return Number.isNaN(I.getTime())?Y:I.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})};return n.jsxs("div",{className:"h-full flex flex-col bg-warm-50",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-warm-100 shrink-0",children:[n.jsx("span",{className:"text-xs font-semibold text-warm-600",children:f("session.diff.title")||"Diff"}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("button",{onClick:$,disabled:A||!c,title:f("session.diff.capture")||"Capture snapshot",className:"p-1 rounded hover:bg-warm-100 text-warm-500 disabled:opacity-40",children:n.jsx(ej,{size:13,className:A?"animate-pulse":""})}),n.jsx("button",{onClick:H,title:f("common.refresh")||"Refresh",className:"p-1 rounded hover:bg-warm-100 text-warm-500",children:n.jsx(ep,{size:13,className:x?"animate-spin":""})}),n.jsx("button",{onClick:s,title:f("common.close")||"Close",className:"p-1 rounded hover:bg-warm-100 text-warm-500",children:n.jsx(Jt,{size:14})})]})]}),j.length>0&&n.jsxs("div",{className:"flex items-center gap-1 px-3 py-1.5 border-b border-warm-100 overflow-x-auto shrink-0",children:[n.jsx(My,{active:N===null,onClick:()=>D(null),label:f("session.diff.pageStart")||"From start"}),j.map(Y=>n.jsx(My,{active:N===Y.sha,onClick:()=>D(Y.sha),label:`#${Y.seq} ${q(Y.at)}`},Y.sha))]}),c?n.jsxs("div",{className:"flex-1 flex min-h-0",children:[n.jsx("div",{className:"w-2/5 min-w-[180px] max-w-[320px] border-r border-warm-100 overflow-hidden",children:n.jsx(Ku,{files:m,loading:x,selectedFile:C,onFileClick:S})}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(Cl,{diff:g,loading:w,selectedFile:C})})]}):n.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:n.jsx("span",{className:"text-xs text-warm-400",children:p==="not-git"?f("session.diff.notGit")||"Not a git repository":f("session.diff.unavailable")||"Diff unavailable"})})]})}function My({active:e,onClick:s,label:i}){return n.jsx("button",{onClick:s,className:`px-2 py-0.5 rounded text-[11px] whitespace-nowrap shrink-0 ${e?"bg-warm-600 text-white":"bg-warm-100 text-warm-600 hover:bg-warm-200"}`,children:i})}const jO={presetId:G_},ml=new Map,Ba=new Map;function Q_(e){return`sessionTheme:${e}`}window.addEventListener("storage",e=>{var a;if(e.storageArea!==localStorage||!((a=e.key)!=null&&a.startsWith("sessionTheme:")))return;const s=e.key.slice(13);ml.delete(s);const i=Ba.get(s);if(i){const h=Mm(s);i.forEach(f=>f(h))}});function EO(e){return typeof e!="string"?!1:e==="custom"||e in Tn}function Mm(e){const s=ml.get(e);if(s!==void 0)return s;let i=jO;try{const a=localStorage.getItem(Q_(e));if(a!==null){const h=JSON.parse(a);h&&EO(h.presetId)&&(i={presetId:h.presetId,custom:h.custom&&typeof h.custom=="object"?h.custom:void 0})}}catch{}return ml.set(e,i),i}function NO(e,s){const i=ml.get(e);if(i&&i.presetId===s.presetId&&LO(i.custom,s.custom))return;ml.set(e,s);try{localStorage.setItem(Q_(e),JSON.stringify(s))}catch{}const a=Ba.get(e);a&&a.forEach(h=>h(s))}function LO(e,s){return e===s?!0:!e||!s?!1:e.background===s.background&&e.foreground===s.foreground&&e.cursor===s.cursor&&e.selectionBackground===s.selectionBackground&&e.accent===s.accent}function DO(e){if(e.presetId!=="custom")return Ny(e.presetId).theme;const s=Ny(G_).theme,i=e.custom??{},a=i.cursor??i.accent??s.cursor;return{...s,background:i.background??s.background,foreground:i.foreground??s.foreground,cursor:a,cursorAccent:i.background??s.cursorAccent,selectionBackground:i.selectionBackground??s.selectionBackground,brightBlue:i.accent??s.brightBlue,blue:i.accent??s.blue}}function Z_(e){const[s,i]=k.useState(()=>Mm(e));k.useEffect(()=>{i(Mm(e));let f=Ba.get(e);return f||(f=new Set,Ba.set(e,f)),f.add(i),()=>{const m=Ba.get(e);m&&(m.delete(i),m.size===0&&Ba.delete(e))}},[e]);const a=k.useCallback(f=>NO(e,f),[e]),h=k.useMemo(()=>DO(s),[s]);return[s,h,a]}function eS({session:e,visible:s,intent:i,intentNonce:a,onClose:h,sendMessage:f,subscribeBinary:m,onEvent:o,onCycleTab:c,remountKey:d=0}){const{t:p}=dt(),u=e.status==="running"||i==="start"||i==="resume"?"pendingFit":"replay-only",[x,b]=k.useState(u),[C,S]=k.useState(null),[g,_]=k.useState(!1),[w,y]=k.useState(480),E=!!e.is_git_repo,T=k.useRef(null),j=k.useCallback(be=>{be.preventDefault();const Ue=T.current;if(!Ue)return;const Pe=ke=>{const pe=Ue.getBoundingClientRect(),Ne=240,Le=Math.max(Ne,pe.width-200);y(Math.min(Le,Math.max(Ne,pe.right-ke.clientX)))},tt=()=>{window.removeEventListener("mousemove",Pe),window.removeEventListener("mouseup",tt),document.body.style.cursor="",document.body.style.userSelect=""};window.addEventListener("mousemove",Pe),window.addEventListener("mouseup",tt),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[R,N]=k.useState(0),D=k.useCallback(()=>N(be=>be+1),[]),A=k.useRef(null),O=k.useRef(!1),z=k.useRef(a),[P,F]=k.useState(null),[H,$]=k.useState(null),[q,Y]=k.useState(!1),[I,B]=k.useState(null),[U,J]=k.useState(null),W=k.useRef(e.status==="running");k.useEffect(()=>{e.status==="running"&&x!=="subscribed"&&x!=="starting"&&x!=="pendingFit"&&(W.current=!0,b("subscribed"))},[e.status,x]),k.useEffect(()=>{if(e.status==="running"||!W.current||x!=="subscribed"&&x!=="stopping")return;const be=setTimeout(()=>h(),300);return()=>clearTimeout(be)},[e.status,x,h]);const oe=k.useCallback(async()=>{const be=A.current;if(be&&!O.current){O.current=!0,b("starting"),S(null),J(null);try{const Ue=await C4(e.id,be,i==="resume"?{continueSession:!0}:void 0);b("subscribed"),Ue.pendingInitialPrompt?(F(Ue.pendingInitialPromptLength??0),$(null),Y(!1)):(F(null),$(null))}catch(Ue){const Pe=Ue instanceof Error?Ue.message:String(Ue);S(Pe),b("error")}finally{O.current=!1}}},[e.id,i]),ee=k.useCallback(async()=>{if(q){Y(!1);return}if(Y(!0),H===null)try{const be=await j4(e.id);$(be.prompt??"")}catch(be){J(be instanceof Error?be.message:String(be))}},[q,H,e.id]),Z=k.useCallback(async()=>{if(!I){B("send"),J(null);try{await E4(e.id),F(null),$(null),Y(!1)}catch(be){J(be instanceof Error?be.message:String(be))}finally{B(null)}}},[I,e.id]),X=k.useCallback(async()=>{if(!I){B("skip"),J(null);try{await N4(e.id),F(null),$(null),Y(!1)}catch(be){J(be instanceof Error?be.message:String(be))}finally{B(null)}}},[I,e.id]);k.useEffect(()=>{if(a===z.current)return;z.current=a,(i==="start"||i==="resume")&&x==="replay-only"&&e.status!=="running"&&(A.current?oe():b("pendingFit"))},[a,i,x,e.status,oe]);const G=k.useCallback(()=>{A.current?oe():b("pendingFit")},[oe]),me=k.useCallback((be,Ue)=>{A.current={cols:be,rows:Ue},x==="pendingFit"&&(e.status==="running"?(W.current=!0,b("subscribed")):oe())},[x,oe,e.status]),ge=e.status==="running",xe=x==="subscribed",[he]=h1(e.id),[,Ie]=Z_(e.id),Fe=x==="starting"||x==="pendingFit"?n.jsxs("div",{style:{...Xc,pointerEvents:"none"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[n.jsx(oi,{size:14,style:{animation:"spin 1s linear infinite",color:He.dim}}),n.jsx("span",{style:{color:He.dim,fontFamily:Rt,fontSize:12},children:p("session.starting")||"starting…"})]}),n.jsx("span",{style:{color:He.dim,fontFamily:Rt,fontSize:10,marginTop:6},children:p("session.starting.typeAhead")||"type-ahead is captured and replayed once ready"})]}):x==="stopping"?n.jsx("div",{style:{...Xc,pointerEvents:"none"},children:n.jsx("span",{style:{color:He.dim,fontFamily:Rt,fontSize:12},children:p("session.stopping")||"stopping…"})}):x==="replay-only"?n.jsx("div",{style:Xc,children:n.jsxs("button",{onClick:G,style:{display:"flex",alignItems:"center",gap:8,fontFamily:Rt,fontSize:14,color:He.bright,background:"transparent",border:`1px solid ${He.separator}`,padding:"10px 22px",borderRadius:6,cursor:"pointer"},children:[n.jsx(kr,{size:16})," ",p("session.startInWindow")||"Start"]})}):x==="error"?n.jsxs("div",{style:Xc,children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:He.error,fontFamily:Rt,fontSize:12,marginBottom:8},children:[n.jsx(Iw,{size:14})," ",p("session.startFailed")||"failed to start"]}),C&&n.jsx("div",{style:{color:He.dim,fontFamily:Rt,fontSize:11,marginBottom:8,maxWidth:360,textAlign:"center",wordBreak:"break-word"},children:C}),n.jsx("button",{onClick:()=>{oe()},style:{fontFamily:Rt,fontSize:12,color:He.bright,background:"transparent",border:`1px solid ${He.separator}`,padding:"4px 12px",borderRadius:4,cursor:"pointer"},children:p("common.retry")||"Retry"})]}):null;return n.jsxs("div",{ref:T,style:{display:s?"flex":"none",flexDirection:"row",position:"absolute",inset:0,background:He.bg},children:[n.jsxs("div",{style:{position:"relative",flex:1,minWidth:0,height:"100%"},children:[n.jsx(gO,{sessionId:e.id,isRunning:ge,subscribed:xe,onFitted:me,sendMessage:f,subscribeBinary:m,onEvent:o,fontSize:he,theme:Ie,inputBlocked:P!==null,autoFocusOnMount:s,onRequestRefresh:D,disableImagePaste:e.cli_tool==="raw-shell",onCycleTab:c,onToggleDiff:()=>{E&&_(be=>!be)}},`${d}:${R}`),Fe,E&&!g&&n.jsxs("button",{onClick:()=>_(!0),title:`${p("session.diff.title")||"Diff"} (${navigator.platform.startsWith("Mac")?"⌘":"Ctrl"}+Shift+D)`,style:{position:"absolute",top:4,right:8,zIndex:1002,display:"inline-flex",alignItems:"center",gap:4,fontFamily:Rt,fontSize:10,color:He.dim,background:"rgba(20,20,28,0.7)",border:`1px solid ${He.separator}`,padding:"2px 8px",borderRadius:4,cursor:"pointer"},children:[n.jsx(Jj,{size:11})," Diff"]}),P!==null&&n.jsxs("div",{style:TO,children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[n.jsx("span",{"aria-hidden":!0,style:{color:He.info,fontSize:14},children:"📋"}),n.jsxs("span",{style:{flex:1},children:[p("session.initialPrompt.ready")||"Initial prompt ready",n.jsxs("span",{style:{color:He.dim,marginLeft:8},children:[P.toLocaleString()," chars"]}),n.jsx("div",{style:{color:He.warning,fontSize:10,marginTop:2},children:p("session.initialPrompt.blocked")||"Press Send or Skip before typing — keystrokes are ignored until then."})]}),n.jsxs("button",{onClick:ee,style:Wf("neutral"),title:q?p("session.initialPrompt.hidePreview")||"Hide preview":p("session.initialPrompt.preview")||"Preview",children:[q?n.jsx(lj,{size:11}):n.jsx(wl,{size:11}),q?p("session.initialPrompt.hidePreview")||"Hide":p("session.initialPrompt.preview")||"Preview"]}),n.jsxs("button",{onClick:Z,disabled:I!==null,style:Wf("primary"),children:[I==="send"?n.jsx(oi,{size:11,style:{animation:"spin 1s linear infinite"}}):n.jsx(JE,{size:11}),p("session.initialPrompt.send")||"Send"]}),n.jsx("button",{onClick:X,disabled:I!==null,style:Wf("danger"),children:p("session.initialPrompt.skip")||"Skip"})]}),U&&n.jsx("div",{style:{color:He.error,fontSize:10,marginTop:4},children:U}),q&&n.jsx("pre",{style:{margin:0,marginTop:6,maxHeight:240,overflow:"auto",background:"rgba(0,0,0,0.4)",padding:8,fontFamily:Rt,fontSize:10,color:He.bright,whiteSpace:"pre-wrap",wordBreak:"break-word",border:`1px solid ${He.separator}`,borderRadius:4},children:H===null?p("session.initialPrompt.loading")||"loading…":H})]})]}),E&&g&&n.jsxs(n.Fragment,{children:[n.jsx("div",{onMouseDown:j,style:{width:5,flexShrink:0,cursor:"col-resize",background:He.separator}}),n.jsx("div",{style:{width:w,flexShrink:0,minWidth:0,height:"100%"},children:n.jsx(CO,{sessionId:e.id,projectId:e.project_id,onEvent:o,sendMessage:f,onClose:()=>_(!1)})})]})]})}const TO={position:"absolute",top:0,left:0,right:0,background:"rgba(28,28,38,0.96)",borderBottom:`1px solid ${He.separator}`,borderLeft:`3px solid ${He.warning}`,padding:"8px 10px",color:He.bright,fontFamily:Rt,fontSize:11,zIndex:3,display:"flex",flexDirection:"column"};function Wf(e){const s={display:"inline-flex",alignItems:"center",gap:4,fontFamily:Rt,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer",border:`1px solid ${He.separator}`,background:"transparent"};return e==="primary"?{...s,color:He.bright,borderColor:He.info,background:`${He.info}22`}:e==="danger"?{...s,color:He.dim}:{...s,color:He.bright}}const Xc={position:"absolute",inset:0,background:"rgba(12,12,12,0.85)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:1e3},Ay=340;function RO({sessionId:e}){var C,S,g,_,w,y;const[s,,i]=Z_(e),[a,h]=k.useState(!1),[f,m]=k.useState(!1),[o,c]=k.useState({top:0,left:0}),d=k.useRef(null),p=k.useRef(null),u=k.useCallback(()=>{if(!d.current)return;const E=d.current.getBoundingClientRect(),T=window.innerWidth,j=window.innerHeight,R=p.current;let N=E.bottom+4,D=E.right-Ay;if(R){const A=R.offsetHeight,O=R.offsetWidth;D=E.right-O,D<8&&(D=8),D+O>T-8&&(D=T-8-O),N+A>j-8&&(N=Math.max(8,E.top-A-4))}else D<8&&(D=8);c({top:N,left:D}),m(!0)},[]);k.useEffect(()=>{if(!a){m(!1);return}u();const E=requestAnimationFrame(u),T=R=>{var D,A;const N=R.target;(D=d.current)!=null&&D.contains(N)||(A=p.current)!=null&&A.contains(N)||h(!1)},j=R=>{R.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",T),document.addEventListener("keydown",j),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{cancelAnimationFrame(E),document.removeEventListener("mousedown",T),document.removeEventListener("keydown",j),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[a,u]);const x=E=>{if(E==="custom"){const T=s.custom??{background:Tn.default.theme.background,foreground:Tn.default.theme.foreground,cursor:Tn.default.theme.cursor,selectionBackground:Tn.default.theme.selectionBackground,accent:Tn.default.theme.brightBlue};i({presetId:"custom",custom:T})}else i({presetId:E,custom:s.custom}),h(!1)},b=E=>{const T={...s.custom??{},...E};i({presetId:"custom",custom:T})};return n.jsxs(n.Fragment,{children:[n.jsx("button",{ref:d,"data-no-drag":!0,onMouseDown:E=>E.stopPropagation(),onClick:()=>h(E=>!E),"aria-label":"terminal-theme",title:"Terminal theme (Ctrl+Shift+P)",style:{background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},children:n.jsx(RE,{size:13})}),a&&en.createPortal(n.jsxs("div",{ref:p,className:"z-tooltip",style:{position:"fixed",top:o.top,left:o.left,width:Ay,background:"#1e1e1e",border:`1px solid ${He.separator}`,borderRadius:6,padding:10,fontFamily:Rt,color:He.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:f?1:0,transition:"opacity 80ms"},onMouseDown:E=>E.stopPropagation(),children:[n.jsx("div",{style:{fontSize:10,color:He.dim,marginBottom:6,letterSpacing:.5},children:"DARK"}),n.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:Ey.filter(E=>!Tn[E].light).map(E=>n.jsx(Oy,{preset:Tn[E],selected:s.presetId===E,onClick:()=>x(E)},E))}),n.jsx("div",{style:{fontSize:10,color:He.dim,marginBottom:6,letterSpacing:.5},children:"LIGHT"}),n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:[Ey.filter(E=>Tn[E].light).map(E=>n.jsx(Oy,{preset:Tn[E],selected:s.presetId===E,onClick:()=>x(E)},E)),n.jsx(MO,{selected:s.presetId==="custom",accent:((C=s.custom)==null?void 0:C.accent)??Tn.default.theme.brightBlue??"#569cd6",onClick:()=>x("custom")})]}),s.presetId==="custom"&&n.jsxs("div",{style:{borderTop:`1px solid ${He.separator}`,paddingTop:8},children:[n.jsx("div",{style:{fontSize:10,color:He.dim,marginBottom:6,letterSpacing:.5},children:"CUSTOM COLORS"}),n.jsx(Ko,{label:"Background",value:((S=s.custom)==null?void 0:S.background)??Tn.default.theme.background??"#0c0c0c",onChange:E=>b({background:E})}),n.jsx(Ko,{label:"Foreground",value:((g=s.custom)==null?void 0:g.foreground)??Tn.default.theme.foreground??"#cccccc",onChange:E=>b({foreground:E})}),n.jsx(Ko,{label:"Cursor",value:((_=s.custom)==null?void 0:_.cursor)??Tn.default.theme.cursor??"#f2f2f2",onChange:E=>b({cursor:E})}),n.jsx(Ko,{label:"Selection",value:((w=s.custom)==null?void 0:w.selectionBackground)??Tn.default.theme.selectionBackground??"#264f78",onChange:E=>b({selectionBackground:E})}),n.jsx(Ko,{label:"Accent",value:((y=s.custom)==null?void 0:y.accent)??Tn.default.theme.brightBlue??"#569cd6",onChange:E=>b({accent:E})})]})]}),document.body)]})}function Oy({preset:e,selected:s,onClick:i}){return n.jsxs("button",{onClick:i,style:{position:"relative",background:e.theme.background,border:`1px solid ${s?e.accent:He.separator}`,outline:s?`1px solid ${e.accent}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:Rt,fontSize:10,color:e.theme.foreground,textAlign:"left",height:52,display:"flex",flexDirection:"column",justifyContent:"space-between",overflow:"hidden"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:e.accent,flexShrink:0}}),n.jsx("span",{style:{fontWeight:600,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),s&&n.jsx(_r,{size:10,style:{marginLeft:"auto",flexShrink:0}})]}),n.jsxs("div",{style:{fontSize:9,opacity:.85,fontFamily:Rt},children:[n.jsx("span",{style:{color:e.theme.green},children:"$"})," ",n.jsx("span",{style:{color:e.theme.brightBlue},children:"ls"})]})]})}function MO({selected:e,accent:s,onClick:i}){return n.jsxs("button",{onClick:i,style:{position:"relative",background:"#0c0c0c",border:`1px dashed ${e?s:He.separator}`,outline:e?`1px solid ${s}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:Rt,fontSize:10,color:He.text,textAlign:"left",height:52,display:"flex",flexDirection:"column",justifyContent:"space-between",overflow:"hidden"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:s,flexShrink:0}}),n.jsx("span",{style:{fontWeight:600,fontSize:11},children:"Custom"}),e&&n.jsx(_r,{size:10,style:{marginLeft:"auto",flexShrink:0}})]}),n.jsx("div",{style:{fontSize:9,opacity:.7},children:"edit colors"})]})}function Ko({label:e,value:s,onChange:i}){const[a,h]=k.useState(s);k.useEffect(()=>{h(s)},[s]);const f=m=>{h(m);const o=m.startsWith("#")?m:`#${m}`;(/^#[0-9a-fA-F]{6}$/.test(o)||/^#[0-9a-fA-F]{3}$/.test(o))&&i(zy(o))};return n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",fontSize:11,color:He.text},children:[n.jsx("span",{style:{flex:1},children:e}),n.jsx("input",{type:"text",value:a,onChange:m=>f(m.target.value),onBlur:()=>h(s),spellCheck:!1,style:{width:64,padding:"2px 4px",fontSize:10,fontFamily:Rt,color:He.text,background:"transparent",border:`1px solid ${He.separator}`,borderRadius:3}}),n.jsx("input",{type:"color",value:zy(s),onChange:m=>i(m.target.value),style:{width:28,height:22,padding:0,border:`1px solid ${He.separator}`,borderRadius:3,background:"transparent",cursor:"pointer"}})]})}function zy(e){return/^#[0-9a-fA-F]{6}$/.test(e)?e.toLowerCase():/^#[0-9a-fA-F]{3}$/.test(e)?("#"+e.slice(1).split("").map(s=>s+s).join("")).toLowerCase():"#000000"}const By=360;function AO({sessionId:e,sendMessage:s}){const[i,a]=k.useState(!1),[h,f]=k.useState(!1),[m,o]=k.useState({top:0,left:0}),[c,d]=k.useState(null),[p,u]=k.useState(""),[x,b]=k.useState(!1),[C,S]=k.useState(""),[g,_]=k.useState(""),[w,y]=k.useState(!1),[E,T]=k.useState(null),j=k.useRef(null),R=k.useRef(null),N=k.useRef(null),D=k.useCallback(()=>{if(!j.current)return;const H=j.current.getBoundingClientRect(),$=window.innerWidth,q=window.innerHeight,Y=R.current;let I=H.bottom+4,B=H.right-By;if(Y){const U=Y.offsetHeight,J=Y.offsetWidth;B=H.right-J,B<8&&(B=8),B+J>$-8&&(B=$-8-J),I+U>q-8&&(I=Math.max(8,H.top-U-4))}else B<8&&(B=8);o({top:I,left:B}),f(!0)},[]);k.useEffect(()=>{if(!i)return;let H=!1;return u1().then($=>{H||d($)}).catch($=>{H||T($ instanceof Error?$.message:"Failed to load")}),()=>{H=!0}},[i]),k.useEffect(()=>{if(!i){f(!1);return}D();const H=requestAnimationFrame(D),$=requestAnimationFrame(()=>{requestAnimationFrame(()=>{var I;return(I=N.current)==null?void 0:I.focus()})}),q=I=>{var U,J;const B=I.target;(U=j.current)!=null&&U.contains(B)||(J=R.current)!=null&&J.contains(B)||a(!1)},Y=I=>{I.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",q),document.addEventListener("keydown",Y),window.addEventListener("scroll",D,!0),window.addEventListener("resize",D),()=>{cancelAnimationFrame(H),cancelAnimationFrame($),document.removeEventListener("mousedown",q),document.removeEventListener("keydown",Y),window.removeEventListener("scroll",D,!0),window.removeEventListener("resize",D)}},[i,D]),k.useEffect(()=>{i||(u(""),b(!1),S(""),_(""),T(null))},[i]);const A=k.useMemo(()=>{if(!c)return[];const H=p.trim().toLowerCase();return H?c.filter($=>$.name.toLowerCase().includes(H)||$.command_template.toLowerCase().includes(H)):c},[c,p]),O=H=>{s({type:"session:terminal-input",sessionId:e,input:H.command_template}),a(!1)},z=H=>{H.key==="Enter"&&A.length>0&&(H.preventDefault(),O(A[0]))},P=!!C.trim()&&!!g.trim()&&!w,F=async()=>{if(P){y(!0),T(null);try{const H=await d1({name:C.trim(),command_template:g.trim()});d($=>$?[H,...$]:[H]),S(""),_(""),b(!1)}catch(H){T(H instanceof Error?H.message:"Failed")}finally{y(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsx("button",{ref:j,"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>a(H=>!H),"aria-label":"alias-inserter",title:"Insert saved command (alias) (Ctrl+Shift+A)",style:OO,children:n.jsx(Nj,{size:13})}),i&&en.createPortal(n.jsxs("div",{ref:R,className:"z-tooltip",style:{position:"fixed",top:m.top,left:m.left,width:By,background:"#1e1e1e",border:`1px solid ${He.separator}`,borderRadius:6,padding:10,fontFamily:Rt,color:He.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:h?1:0,transition:"opacity 80ms"},onMouseDown:H=>H.stopPropagation(),children:[n.jsx("input",{ref:N,type:"text",value:p,onChange:H=>u(H.target.value),onKeyDown:z,placeholder:"Filter aliases… (Enter inserts first match)",style:{width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${He.separator}`,borderRadius:4,color:He.bright,fontFamily:Rt,fontSize:11,padding:"6px 8px",outline:"none"}}),n.jsx("div",{style:{marginTop:8,maxHeight:280,overflowY:"auto"},children:c===null?n.jsx("div",{style:Py,children:"Loading…"}):A.length===0?n.jsx("div",{style:Py,children:c.length===0?"No aliases yet — add one below.":"No matches."}):A.map(H=>n.jsxs("button",{onClick:()=>O(H),style:zO,onMouseEnter:$=>$.currentTarget.style.background="rgba(255,255,255,0.06)",onMouseLeave:$=>$.currentTarget.style.background="transparent",title:`Insert: ${H.command_template}`,children:[n.jsx("span",{style:{fontSize:11,color:He.bright,fontWeight:600},children:H.name}),n.jsx("code",{style:{fontSize:10,color:He.dim,marginLeft:8,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:H.command_template})]},H.id))}),n.jsx("div",{style:{borderTop:`1px solid ${He.separator}`,marginTop:8,paddingTop:8},children:x?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[n.jsx("input",{type:"text",value:C,onChange:H=>S(H.target.value),placeholder:"Name (e.g. git status)",maxLength:64,style:Iy}),n.jsx("input",{type:"text",value:g,onChange:H=>_(H.target.value),onKeyDown:H=>{H.key==="Enter"&&(H.preventDefault(),F())},placeholder:"Command (e.g. git status -sb)",maxLength:1024,style:{...Iy,fontFamily:Rt}}),E&&n.jsx("div",{style:{fontSize:10,color:"#f87171"},children:E}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[n.jsxs("button",{type:"button",onClick:()=>{b(!1),T(null)},style:tS,children:[n.jsx(Jt,{size:10})," Cancel"]}),n.jsx("button",{type:"button",onClick:F,disabled:!P,style:{...BO,opacity:P?1:.5},children:"Save"})]})]}):n.jsxs("button",{type:"button",onClick:()=>{b(!0),T(null)},style:PO,children:[n.jsx(mn,{size:12})," New alias"]})})]}),document.body)]})}const OO={background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},Py={fontSize:11,color:He.dim,padding:"12px 4px",textAlign:"center"},zO={display:"flex",alignItems:"center",width:"100%",background:"transparent",border:"none",padding:"6px 8px",cursor:"pointer",textAlign:"left",borderRadius:3,transition:"background 80ms"},Iy={width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${He.separator}`,borderRadius:4,color:He.bright,fontSize:11,padding:"5px 7px",outline:"none"},tS={display:"inline-flex",alignItems:"center",gap:3,background:"transparent",border:`1px solid ${He.separator}`,color:He.dim,fontFamily:Rt,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer"},BO={...tS,background:"rgba(86,156,214,0.13)",border:"1px solid #569cd6",color:He.bright},PO={display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",color:He.dim,fontFamily:Rt,fontSize:11,padding:"4px 0",cursor:"pointer"},IO=26;function Dp({stack:e,path:s,groupId:i,sessionsById:a,colors:h,intents:f,onTabClick:m,onTabClose:o,onTabMouseDown:c,onPaneAutoClose:d,registerRect:p,sendMessage:u,subscribeBinary:x,onEvent:b,focusedSessionId:C,groupTopmost:S,onFocusStack:g,groupActions:_}){const{t:w}=dt(),[y,,E]=h1(e.activeTab),[T,j]=k.useState({}),R=()=>{const $=e.activeTab;$&&j(q=>({...q,[$]:(q[$]||0)+1}))},N=rz(),D=S===void 0?!0:S&&(!C||C===e.activeTab),A=S===!0&&!D,O=a.get(e.activeTab),z=[[O==null?void 0:O.cli_tool,O==null?void 0:O.cli_model].filter(Boolean).join("/"),O==null?void 0:O.branch_name,O==null?void 0:O.status,O!=null&&O.total_tokens?`${O.total_tokens.toLocaleString()} tok`:""].filter(Boolean).join(" · "),P=$=>{$.button===0&&e.activeTab&&(g?g(e.activeTab):N==null||N.focus(e.activeTab)),$.stopPropagation()},F=e.tabs.length>1?$=>{const q=e.tabs.indexOf(e.activeTab);if(q<0)return;const Y=e.tabs.length,I=$==="next"?(q+1)%Y:(q-1+Y)%Y;m(e.tabs[I])}:void 0,H=$=>{var oe;const q=/Mac|iPhone|iPad|iPod/.test(navigator.platform),Y=q?$.metaKey:$.ctrlKey,I=q?$.ctrlKey:$.metaKey,B=Y&&!I&&!$.altKey&&$.shiftKey,U=$.key.toLowerCase();if($.key==="F5"&&!$.ctrlKey&&!$.metaKey&&!$.altKey&&!$.shiftKey||B&&U==="r"){$.preventDefault(),R();return}if(!B||U!=="a"&&U!=="p")return;$.preventDefault();const W=U==="a"?"alias-inserter":"terminal-theme";(oe=$.currentTarget.querySelector(`[aria-label="${W}"]`))==null||oe.click()};return n.jsxs("div",{onKeyDown:H,style:{flex:1,display:"flex",flexDirection:"column",background:He.bg,minWidth:0,minHeight:0,position:"relative",overflow:"hidden",opacity:A?S?.78:.88:1,filter:A?"saturate(0.78)":"none",boxShadow:D?`inset 0 0 0 1px ${He.info}`:"inset 0 0 0 1px transparent",transition:"opacity 140ms ease-out, filter 140ms ease-out, box-shadow 140ms ease-out"},children:[n.jsxs("div",{onDoubleClick:$=>{var q;$.target.closest("button")||(q=_==null?void 0:_.onToggleMaximize)==null||q.call(_)},style:{display:"flex",height:IO,background:D?"#323a42":He.titleBg,borderBottom:`1px solid ${He.separator}`,flexShrink:0,overflowX:"auto",overflowY:"hidden"},children:[e.tabs.map($=>{const q=a.get($),Y=$===e.activeTab,I=h[$]||He.titleText,B=(q==null?void 0:q.status)==="running"?He.success:(q==null?void 0:q.status)==="failed"?He.error:(q==null?void 0:q.status)==="completed"?He.info:He.dim,U=[q==null?void 0:q.status,q==null?void 0:q.cli_tool,q==null?void 0:q.cli_model,q==null?void 0:q.branch_name].filter(Boolean).join(" · ");return n.jsxs("div",{onMouseDown:J=>{if(J.button===0){if(_){m($);return}J.stopPropagation(),m($),c($,s,J)}},style:{display:"flex",alignItems:"center",gap:6,padding:"0 6px 0 10px",fontFamily:Rt,fontSize:11,color:Y?He.bright:He.titleText,background:Y?He.bg:"transparent",borderRight:`1px solid ${He.separator}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",maxWidth:200,position:"relative"},title:`${(q==null?void 0:q.title)||$}${U?`
683
- ${U}`:""}`,children:[n.jsx("span",{"aria-label":(q==null?void 0:q.status)||"unknown",style:{width:6,height:6,borderRadius:"50%",background:B,flexShrink:0}}),n.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Rt,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:I,width:16,textAlign:"center"},children:">_"}),n.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(q==null?void 0:q.title)||$}),n.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:J=>{J.stopPropagation(),o($)},"aria-label":"close-tab",title:w("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:n.jsx(Jt,{size:11})})]},$)}),N&&n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{N.createRawShellTab(i,s).catch(()=>{})},"aria-label":"new-tab",title:`${w("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${He.separator}`,color:He.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:n.jsx(mn,{size:13})}),n.jsx("div",{style:{flex:1,minWidth:8}}),z&&n.jsx("span",{title:z,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:He.dim,fontFamily:Rt,fontSize:9,padding:"0 7px",flexShrink:1},children:z}),n.jsx(AO,{sessionId:e.activeTab,sendMessage:u}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:R,"aria-label":"refresh-terminal",title:`${w("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${w("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:qs,children:n.jsx(GE,{size:12})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>E(-1),"aria-label":"decrease-font",title:`${w("session.fontDecrease")||"Decrease font size"} (${y}px) · Ctrl+- · Ctrl+wheel`,style:qs,children:n.jsx(bN,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>E(1),"aria-label":"increase-font",title:`${w("session.fontIncrease")||"Increase font size"} (${y}px) · Ctrl+= · Ctrl+wheel`,style:qs,children:n.jsx(xN,{size:13})}),n.jsx(RO,{sessionId:e.activeTab}),_&&n.jsxs(n.Fragment,{children:[e.tabs.length>1&&_.onApplyLayoutPreset&&n.jsxs(n.Fragment,{children:[n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{var $;return($=_.onApplyLayoutPreset)==null?void 0:$.call(_,"single")},"aria-label":"single-pane",title:w("session.layout.single"),style:qs,children:n.jsx(Ki,{size:12})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{var $;return($=_.onApplyLayoutPreset)==null?void 0:$.call(_,"columns")},"aria-label":"two-columns",title:w("session.layout.columns"),style:qs,children:n.jsx(Uw,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{var $;return($=_.onApplyLayoutPreset)==null?void 0:$.call(_,"grid")},"aria-label":"grid-layout",title:w("session.layout.grid"),style:qs,children:n.jsx(qw,{size:13})})]}),_.onToggleMaximize&&n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onToggleMaximize,"aria-label":"toggle-maximize",title:`${_.isMaximized?w("session.restoreSize"):w("session.maximize")} · ${w("session.maximizeHint")}`,style:qs,children:_.isMaximized?n.jsx(Bu,{size:13}):n.jsx(qi,{size:13})}),_.onPopOutGroup&&n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onPopOutGroup,"aria-label":"pop-out",title:`${w("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:qs,children:n.jsx(li,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onMinimizeGroup,"aria-label":"minimize",title:`${w("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:qs,children:n.jsx(Qm,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onCloseGroup,"aria-label":"close",title:`${w("session.close")||"Close"} (Ctrl+Shift+X)`,style:qs,children:n.jsx(Jt,{size:13})})]})]}),n.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:$=>{if(!$){p(s,null);return}const q=$.getBoundingClientRect();p(s,{x:q.left,y:q.top,w:q.width,h:q.height})},onMouseDown:P,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map($=>{const q=a.get($);if(!q)return null;const Y=f[$]||{intent:"open",nonce:0};return n.jsx(eS,{session:q,visible:$===e.activeTab,intent:Y.intent,intentNonce:Y.nonce,onClose:()=>d($),sendMessage:u,subscribeBinary:x,onEvent:b,onCycleTab:F,remountKey:T[$]||0},$)})})]})}const qs={background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function FO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const h=k.useCallback(m=>{if(m.button!==0)return;m.preventDefault(),m.stopPropagation();const o=m.clientX,c=m.clientY;s();let d=!1;const p=()=>{d||(d=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",S),window.removeEventListener("blur",u),window.removeEventListener("keydown",x),document.removeEventListener("visibilitychange",b))},u=()=>{p(),a()},x=g=>{g.key==="Escape"&&u()},b=()=>{document.hidden&&u()},C=g=>{const _=e==="horizontal"?g.clientX-o:g.clientY-c;i(_)},S=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",S),window.addEventListener("blur",u),window.addEventListener("keydown",x),document.addEventListener("visibilitychange",b)},[e,s,i,a]),f=e==="horizontal";return n.jsx("div",{onMouseDown:h,style:{flex:"0 0 4px",background:He.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function Tp(e){const{node:s,path:i,onSplitSizes:a,...h}=e;return s.kind==="stack"?n.jsx(Dp,{stack:s,path:i,...h}):n.jsx(HO,{split:s,path:i,onSplitSizes:a,stackProps:h})}const Fy=80;function HO({split:e,path:s,onSplitSizes:i,stackProps:a}){const h=e.orientation==="horizontal",f=k.useRef(null),m=k.useRef([]),o=k.useRef(null);return n.jsx("div",{ref:f,style:{display:"flex",flexDirection:h?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((c,d)=>n.jsxs(k.Fragment,{children:[n.jsx("div",{ref:p=>{m.current[d]=p},style:{flex:`0 0 ${e.sizes[d]}%`,display:"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:n.jsx(Tp,{node:c,path:[...s,d],onSplitSizes:i,...a})}),d<e.children.length-1&&n.jsx(FO,{orientation:e.orientation,onDragStart:()=>{const p=f.current;if(!p)return;const u=e.sizes.slice();o.current={i:d,initialSizes:u,finalSizes:u.slice(),total:h?p.clientWidth:p.clientHeight}},onDrag:p=>{const u=o.current;if(!u||u.total<=0)return;const x=u.initialSizes[u.i]/100*u.total,b=u.initialSizes[u.i+1]/100*u.total,C=x+b,S=Math.max(Fy,Math.min(C-Fy,x+p)),g=C-S,_=S/u.total*100,w=g/u.total*100,y=m.current[u.i],E=m.current[u.i+1];y&&(y.style.flexBasis=`${_}%`),E&&(E.style.flexBasis=`${w}%`);const T=u.initialSizes.slice();T[u.i]=_,T[u.i+1]=w,u.finalSizes=T},onDragEnd:()=>{const p=o.current;p&&i(s,p.finalSizes),o.current=null}})]},d))})}const rn=28,hs=68;function Gu(e,s,i){const a=e-i.x,h=s-i.y;if(a<0||h<0||a>i.w||h>i.h)return null;const f=a-i.w/2,m=h-i.h/2;return Math.abs(f)<=rn&&Math.abs(m)<=rn?"center":f>=-hs-rn&&f<=-hs+rn&&Math.abs(m)<=rn?"left":f>=hs-rn&&f<=hs+rn&&Math.abs(m)<=rn?"right":m>=-hs-rn&&m<=-hs+rn&&Math.abs(f)<=rn?"top":m>=hs-rn&&m<=hs+rn&&Math.abs(f)<=rn?"bottom":null}function ju(e,s){const i=document.elementsFromPoint(e,s);for(const a of i){const h=a.closest("[data-group-id][data-stack-path]");if(!h)continue;const f=h.dataset.stackPath||"",m=f===""?[]:f.split(".").map(Number),o=h.getBoundingClientRect(),c={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:h.dataset.groupId||"",path:m,rect:c,zone:Gu(e,s,c)}}return null}function $O(e,s){const i=e.w/2,a=e.h/2;switch(s){case"center":return e;case"left":return{x:e.x,y:e.y,w:i,h:e.h};case"right":return{x:e.x+i,y:e.y,w:i,h:e.h};case"top":return{x:e.x,y:e.y,w:e.w,h:a};case"bottom":return{x:e.x,y:e.y+a,w:e.w,h:a}}}function pl({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,h=s?$O(e,s):null;return en.createPortal(n.jsxs(n.Fragment,{children:[h&&n.jsx("div",{style:{position:"fixed",left:h.x,top:h.y,width:h.w,height:h.h,background:`${He.info}33`,border:`2px dashed ${He.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=hs+rn;return n.jsxs("div",{style:{position:"fixed",left:i-f,top:a-f,width:f*2,height:f*2,pointerEvents:"none",zIndex:2500},children:[n.jsx(Go,{offsetX:f-rn,offsetY:f-rn,active:s==="center",kind:"center"}),n.jsx(Go,{offsetX:f-hs-rn,offsetY:f-rn,active:s==="left",kind:"left"}),n.jsx(Go,{offsetX:f+hs-rn,offsetY:f-rn,active:s==="right",kind:"right"}),n.jsx(Go,{offsetX:f-rn,offsetY:f-hs-rn,active:s==="top",kind:"top"}),n.jsx(Go,{offsetX:f-rn,offsetY:f+hs-rn,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Go({offsetX:e,offsetY:s,active:i,kind:a}){const h=rn*2,f=i?He.info:"#3a3a3a",m=i?He.bright:He.separator;return n.jsx("div",{style:{position:"absolute",left:e,top:s,width:h,height:h,background:"#1a1a1a",border:`1px solid ${m}`,borderRadius:4,boxShadow:i?`0 0 8px ${He.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:n.jsx(UO,{kind:a,fill:f})})}function UO({kind:e,fill:s}){const i={position:"absolute",background:s};switch(e){case"center":return n.jsx("div",{style:{...i,inset:4}});case"left":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{...i,left:4,top:4,bottom:4,width:"calc(50% - 4px)"}}),n.jsx("div",{style:{position:"absolute",right:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}})]});case"right":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",left:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),n.jsx("div",{style:{...i,right:4,top:4,bottom:4,width:"calc(50% - 4px)"}})]});case"top":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{...i,top:4,left:4,right:4,height:"calc(50% - 4px)"}}),n.jsx("div",{style:{position:"absolute",bottom:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}})]});case"bottom":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",top:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),n.jsx("div",{style:{...i,bottom:4,left:4,right:4,height:"calc(50% - 4px)"}})]})}}function yr(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function al(e,s){let i=e;for(const a of s){if(i.kind!=="split"||a<0||a>=i.children.length)return null;i=i.children[a]}return i}function Vu(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=Vu(e.children[i],s);if(a)return[i,...a]}return null}function dn(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(dn)}function Eu(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(Eu)}function WO(e,s){const i=dn(e);if(i.length<=1||s==="single")return yr(i,Eu(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),h=Array.from({length:a},()=>[]);i.forEach((u,x)=>h[x%a].push(u));const f=new Set(Eu(e)),m=h.map(u=>yr(u,u.find(x=>f.has(x))||u[0]));if(s==="columns"||m.length<=2)return{kind:"split",orientation:"horizontal",children:m,sizes:m.map(()=>100/m.length)};const o=m.slice(0,2),c=m.slice(2),d=u=>u.length===1?u[0]:{kind:"split",orientation:"horizontal",children:u,sizes:u.map(()=>100/u.length)};return{kind:"split",orientation:"vertical",children:[d(o),d(c)],sizes:[50,50]}}function Wi(e,s){return nS(e,s)}function nS(e,s){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const f=e.tabs.filter(o=>o!==s);if(f.length===0)return null;const m=e.activeTab===s?f[0]:e.activeTab;return{kind:"stack",tabs:f,activeTab:m}}const i=[],a=[];for(let f=0;f<e.children.length;f++){const m=nS(e.children[f],s);m!==null&&(i.push(m),a.push(e.sizes[f]))}if(i.length===0)return null;if(i.length===1)return i[0];const h=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/h*100)}}function $i(e,s,i){return Yu(e,s,a=>{if(a.kind!=="stack")throw new Error("insertIntoStack: target must be a stack");return a.tabs.includes(i)?{...a,activeTab:i}:{kind:"stack",tabs:[...a.tabs,i],activeTab:i}})}function Pa(e,s,i,a){const h=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return Yu(e,s,m=>({kind:"split",orientation:h,children:f?[a,m]:[m,a],sizes:[50,50]}))}function Yu(e,s,i){if(s.length===0)return Nu(i(e));if(e.kind!=="split")throw new Error("replaceAt: path traverses non-split");const[a,...h]=s;if(a<0||a>=e.children.length)throw new Error("replaceAt: bad path");const f=e.children.map((m,o)=>o===a?Yu(m,h,i):m);return Nu({...e,children:f})}function Nu(e){if(e.kind==="stack")return e;const s=e.children.map(Nu),i=[],a=[];for(let f=0;f<s.length;f++){const m=s[f],o=e.sizes[f]??100/s.length;if(m.kind==="split"&&m.orientation===e.orientation){const c=m.sizes.reduce((d,p)=>d+p,0)||1;for(let d=0;d<m.children.length;d++)i.push(m.children[d]),a.push(m.sizes[d]/c*o)}else i.push(m),a.push(o)}if(i.length===1)return i[0];const h=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/h*100)}}function Bs(e,s){return e.kind==="stack"?e.tabs.includes(s)?{...e,activeTab:s}:e:{...e,children:e.children.map(i=>Bs(i,s))}}function sS(e,s,i){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const a=e.tabs.indexOf(s),h=Math.max(0,Math.min(i,e.tabs.length-1));if(h===a)return e;const f=e.tabs.slice();return f.splice(a,1),f.splice(h,0,s),{...e,tabs:f}}return{...e,children:e.children.map(a=>sS(a,s,i))}}function rS(e,s,i){return Yu(e,s,a=>{if(a.kind!=="split")throw new Error("setSplitSizes: target must be a split");if(a.children.length!==i.length)throw new Error("setSplitSizes: size count mismatch");return{...a,sizes:i}})}function qO(e,s,i,a){const h=al(e,i);if(!h||h.kind!=="stack"||a==="center"&&h.tabs.includes(s))return null;const f=h.tabs.find(d=>d!==s);if(!f)return null;const m=Wi(e,s);if(!m)return null;const o=Vu(m,f);if(!o)return null;const c=a==="center"?$i(m,o,s):Pa(m,o,a,yr([s]));return Bs(c,s)}function KO(e,s){const i=dn(e);let a=e;for(const h of i){if(!a)break;s.has(h)||(a=Wi(a,h))}return a}const Jc=320,Qc=200,Zc=80,eu=22,GO=4,Hy=8,Zr=10,tu=60;function ei(e,s,i){return Math.max(s,Math.min(i,e))}function VO(e,s,i,a){const h=e<=Hy,f=e>=i-Hy;if(!h&&!f)return null;const m=a/3,o=a*2/3;return h?s<m?"top-left":s>o?"bottom-left":"left":s<m?"top-right":s>o?"bottom-right":"right"}function $y(e,s,i){const a=Math.round(s/2),h=Math.round(i/2);switch(e){case"left":return{x:0,y:0,w:a,h:i};case"right":return{x:s-a,y:0,w:a,h:i};case"top-left":return{x:0,y:0,w:a,h};case"top-right":return{x:s-a,y:0,w:a,h};case"bottom-left":return{x:0,y:i-h,w:a,h};case"bottom-right":return{x:s-a,y:i-h,w:a,h}}}function YO(e,s,i,a,h){let f=e,m=s;const o=f,c=f+i,d=m,p=m+a;for(const u of h){const x=u.x,b=u.x+u.w,C=u.y,S=u.y+u.h;d<S&&p>C&&(Math.abs(o-b)<=Zr?f=b:Math.abs(c-x)<=Zr?f=x-i:Math.abs(o-x)<=Zr?f=x:Math.abs(c-b)<=Zr&&(f=b-i)),o<b&&c>x&&(Math.abs(d-S)<=Zr?m=S:Math.abs(p-C)<=Zr?m=C-a:Math.abs(d-C)<=Zr?m=C:Math.abs(p-S)<=Zr&&(m=S-a))}return{x:f,y:m}}function XO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:h,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:c}=dt(),d=P_("(max-width: 767px)"),p=cS(),u=k.useRef(null),[x,b]=k.useState(!1),C=k.useRef(null),[S,g]=k.useState(null),_=k.useRef({x:e.x,y:e.y,w:e.w,h:e.h});_.current={x:e.x,y:e.y,w:e.w,h:e.h};const[w,y]=k.useState(null),E=k.useRef(null),T=k.useRef(i);T.current=i;const[j,R]=k.useState(null),N=k.useRef(null),D=k.useCallback((X,G)=>{if(d||x||X.button!==0||X.target.closest("[data-no-drag]"))return;X.preventDefault(),p.focus(dn(e.root)[0]||"");const ge=X.clientX,xe=X.clientY,he={..._.current},Ie=u.current,Fe=window.innerWidth,be=window.innerHeight;let Ue="";G&&Ie&&(Ue=Ie.style.pointerEvents,Ie.style.pointerEvents="none");let Pe=!1;const tt=()=>{Pe||(Pe=!0,window.removeEventListener("mousemove",ze),window.removeEventListener("mouseup",Ke),window.removeEventListener("blur",ke),window.removeEventListener("keydown",pe),document.removeEventListener("visibilitychange",Ne),G&&Ie&&(Ie.style.pointerEvents=Ue))},ke=()=>{tt(),N.current=null,R(null),E.current=null,y(null),p.setGroupGeometry(e.id,{..._.current})},pe=Ve=>{Ve.key==="Escape"&&ke()},Ne=()=>{document.hidden&&ke()};let Le=!1;const ze=Ve=>{if(Le)return;{const se=window.screenX,le=window.screenY,ve=se+window.outerWidth,Ce=le+window.outerHeight;if(Ve.screenX<se-tu||Ve.screenX>ve+tu||Ve.screenY<le-tu||Ve.screenY>Ce+tu){Le=!0,tt(),N.current=null,R(null),E.current=null,y(null),p.setGroupGeometry(e.id,{..._.current}),p.popOutGroup(e.id,{atScreenX:Ve.screenX,atScreenY:Ve.screenY});return}}const de=Ve.clientX-ge,fe=Ve.clientY-xe;let ce=ei(he.x+de,-(he.w-Zc),Fe-Zc),Q=ei(he.y+fe,0,be-eu);const V=T.current;if(V.length>0){const se=YO(ce,Q,he.w,he.h,V);ce=se.x,Q=se.y}if(Ie&&(Ie.style.left=`${ce}px`,Ie.style.top=`${Q}px`),_.current.x=ce,_.current.y=Q,G){let se=null;const le=document.elementFromPoint(Ve.clientX,Ve.clientY),ve=le==null?void 0:le.closest("[data-group-id][data-stack-path]");if(ve){const Ce=ve.dataset.groupId||"";if(Ce!==e.id){const De=ve.dataset.stackPath||"",Qe=De===""?[]:De.split(".").map(Number),ut=ve.getBoundingClientRect(),ot={x:ut.left,y:ut.top,w:ut.width,h:ut.height};se={groupId:Ce,path:Qe,rect:ot,zone:Gu(Ve.clientX,Ve.clientY,ot)}}}N.current=se,R(se?{rect:se.rect,zone:se.zone}:null)}const te=G&&N.current&&N.current.zone?null:VO(Ve.clientX,Ve.clientY,Fe,be);te!==E.current&&(E.current=te,y(te))},Ke=()=>{if(tt(),G&&N.current&&N.current.zone){const Ve=N.current;p.dockGroup(e.id,Ve.groupId,Ve.path,Ve.zone),N.current=null,R(null),E.current=null,y(null);return}if(E.current){const Ve=$y(E.current,Fe,be);Ie&&(Ie.style.left=`${Ve.x}px`,Ie.style.top=`${Ve.y}px`,Ie.style.width=`${Ve.w}px`,Ie.style.height=`${Ve.h}px`),_.current=Ve,E.current=null,y(null)}N.current=null,R(null),p.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",ze),window.addEventListener("mouseup",Ke),window.addEventListener("blur",ke),window.addEventListener("keydown",pe),document.addEventListener("visibilitychange",Ne)},[d,x,p,e.id,e.root]),A=k.useCallback(X=>D(X,!1),[D]),O=k.useCallback(X=>D(X,!0),[D]),z=k.useCallback(X=>G=>{if(d||x||G.button!==0)return;G.preventDefault(),G.stopPropagation();const me=G.clientX,ge=G.clientY,xe={..._.current},he=u.current,Ie=window.innerWidth,Fe=window.innerHeight,be=Le=>{const ze=Le.clientX-me,Ke=Le.clientY-ge;let Ve=xe.x,de=xe.y,fe=xe.w,ce=xe.h;X.includes("e")?fe=ei(xe.w+ze,Jc,Math.max(Jc,Ie-xe.x)):X.includes("w")&&(Ve=ei(xe.x+ze,0,xe.x+xe.w-Jc),fe=xe.x+xe.w-Ve),X.includes("s")?ce=ei(xe.h+Ke,Qc,Math.max(Qc,Fe-xe.y)):X.includes("n")&&(de=ei(xe.y+Ke,0,xe.y+xe.h-Qc),ce=xe.y+xe.h-de),he&&(he.style.left=`${Ve}px`,he.style.top=`${de}px`,he.style.width=`${fe}px`,he.style.height=`${ce}px`),_.current={x:Ve,y:de,w:fe,h:ce}};let Ue=!1;const Pe=()=>{Ue||(Ue=!0,window.removeEventListener("mousemove",be),window.removeEventListener("mouseup",Ne),window.removeEventListener("blur",tt),window.removeEventListener("keydown",ke),document.removeEventListener("visibilitychange",pe))},tt=()=>{Pe(),p.setGroupGeometry(e.id,{..._.current})},ke=Le=>{Le.key==="Escape"&&tt()},pe=()=>{document.hidden&&tt()},Ne=()=>{Pe(),p.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",be),window.addEventListener("mouseup",Ne),window.addEventListener("blur",tt),window.addEventListener("keydown",ke),document.addEventListener("visibilitychange",pe)},[d,x,p,e.id]);k.useEffect(()=>{if(d)return;const X=()=>{const G=window.innerWidth,me=window.innerHeight,ge=_.current,xe=ei(ge.x,-(ge.w-Zc),G-Zc),he=ei(ge.y,0,me-eu);(xe!==ge.x||he!==ge.y)&&p.setGroupGeometry(e.id,{...ge,x:xe,y:he})};return window.addEventListener("resize",X),()=>window.removeEventListener("resize",X)},[d,p,e.id]);const P=k.useCallback(X=>{g(X),p.setActiveTab(e.id,X),p.focus(X)},[p,e.id]),F=k.useCallback(X=>{g(X),p.focus(X)},[p]),H=k.useCallback(X=>{p.close(X)},[p]),$=k.useCallback((X,G,me)=>{p.beginTabDrag(e.id,X,G,me)},[p,e.id]),q=k.useCallback(X=>{p.close(X)},[p]),Y=k.useCallback((X,G)=>{p.setSplitSizes(e.id,X,G)},[p,e.id]),I=Eu(e.root),B=dn(e.root);k.useEffect(()=>{S&&B.includes(S)||g(I[0]||B[0]||null)},[S,I,B]);const U=k.useCallback(()=>{if(x){const X=C.current;X&&p.setGroupGeometry(e.id,X),C.current=null,b(!1);return}C.current={..._.current},p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(Jc,window.innerWidth-12),h:Math.max(Qc,window.innerHeight-12)}),b(!0)},[p,e.id,x]),J=X=>{const G=/Mac|iPhone|iPad|iPod/.test(navigator.platform),me=G?X.metaKey:X.ctrlKey,ge=G?X.ctrlKey:X.metaKey;if(!me||ge||X.altKey||!X.shiftKey)return;const xe=X.key.toLowerCase();xe==="o"?(X.preventDefault(),p.popOutGroup(e.id)):xe==="m"?(X.preventDefault(),p.minimizeGroup(e.id)):xe==="x"&&(X.preventDefault(),p.closeGroup(e.id))};if(d){const X=I[0],G=X?s.get(X):null;if(!G)return null;const me=e.intents[X]??{intent:"open",nonce:0};return en.createPortal(n.jsxs("div",{style:{position:"fixed",inset:0,background:He.bg,display:"flex",flexDirection:"column",zIndex:110},children:[n.jsxs("div",{style:{background:He.titleBg,height:eu,display:"flex",alignItems:"center",borderBottom:`1px solid ${He.separator}`},children:[n.jsx("span",{style:{flex:1,color:He.titleText,fontFamily:Rt,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G.title}),n.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ti,"aria-label":"close",children:n.jsx(Jt,{size:14})})]}),n.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:n.jsx(eS,{session:G,visible:!0,intent:me.intent,intentNonce:me.nonce,onClose:()=>p.close(X),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const W=w?(()=>{const X=window.innerWidth,G=window.innerHeight,me=$y(w,X,G);return en.createPortal(n.jsx("div",{style:{position:"fixed",left:me.x,top:me.y,width:me.w,height:me.h,background:`${He.info}33`,border:`2px dashed ${He.info}`,borderRadius:8,pointerEvents:"none",zIndex:2e3,transition:"left 80ms ease-out, top 80ms ease-out, width 80ms ease-out, height 80ms ease-out",boxSizing:"border-box"}}),document.body)})():null,oe=(()=>{var G;if(B.length===0)return"";const X=((G=s.get(B[0]))==null?void 0:G.title)||B[0];return B.length===1?X:`${X} +${B.length-1}`})(),ee=e.root.kind==="split",Z=en.createPortal(n.jsxs("div",{ref:u,onKeyDown:J,onMouseDown:ee?()=>p.focus(B[0]||""):O,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:h,background:He.bg,border:`1px solid ${a?He.info:He.separator}`,borderRadius:8,boxShadow:a?`0 10px 40px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.3), 0 0 0 1px ${He.info}66, 0 0 18px ${He.info}33`:"0 10px 40px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden",opacity:a?1:.88,filter:a?"none":"saturate(0.82)",transition:"box-shadow 120ms ease-out, border-color 120ms ease-out, opacity 140ms ease-out, filter 140ms ease-out"},children:[ee&&n.jsxs("div",{onMouseDown:A,onDoubleClick:X=>{X.target.closest("button")||U()},style:{height:eu,flexShrink:0,display:"flex",flexDirection:"column",background:He.titleBg,borderBottom:`1px solid ${He.separator}`,userSelect:"none",cursor:"move"},children:[n.jsx("div",{style:{display:"flex",height:GO,flexShrink:0},children:I.map((X,G)=>n.jsx("div",{style:{flex:1,background:e.colors[X]||He.titleText}},G))}),n.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:He.titleText,fontFamily:Rt,fontSize:11},children:[n.jsx("span",{style:{color:He.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),n.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:oe}),B.length>1&&n.jsxs(n.Fragment,{children:[n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:ti,"aria-label":"single-pane",title:c("session.layout.single"),children:n.jsx(Ki,{size:12})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:ti,"aria-label":"two-columns",title:c("session.layout.columns"),children:n.jsx(Uw,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:ti,"aria-label":"grid-layout",title:c("session.layout.grid"),children:n.jsx(qw,{size:13})})]}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:U,style:ti,"aria-label":"toggle-maximize",title:`${c(x?"session.restoreSize":"session.maximize")} · ${c("session.maximizeHint")}`,children:x?n.jsx(Bu,{size:13}):n.jsx(qi,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.popOutGroup(e.id),style:ti,"aria-label":"pop-out",title:`${c("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:n.jsx(li,{size:14})}),n.jsx("button",{"data-no-drag":!0,onClick:()=>p.minimizeGroup(e.id),style:ti,"aria-label":"minimize",title:`${c("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:n.jsx(Qm,{size:14})}),n.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ti,"aria-label":"close",title:`${c("session.close")||"Close"} (Ctrl+Shift+X)`,children:n.jsx(Jt,{size:14})})]})]}),n.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?n.jsx(Tp,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:P,onTabClose:H,onTabMouseDown:$,onPaneAutoClose:q,registerRect:()=>{},onSplitSizes:Y,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:S||void 0,groupTopmost:a,onFocusStack:F}):n.jsx(Dp,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:P,onTabClose:H,onTabMouseDown:$,onPaneAutoClose:q,registerRect:()=>{},sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:S||void 0,groupTopmost:a,onFocusStack:F,groupActions:{onMinimizeGroup:()=>p.minimizeGroup(e.id),onCloseGroup:()=>p.closeGroup(e.id),onPopOutGroup:()=>p.popOutGroup(e.id),onToggleMaximize:U,isMaximized:x,onApplyLayoutPreset:X=>p.applyLayoutPreset(e.id,X)}})}),n.jsx("div",{onMouseDown:z("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),n.jsx("div",{onMouseDown:z("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),n.jsx("div",{onMouseDown:z("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),n.jsx("div",{onMouseDown:z("se"),title:"resize",style:{position:"absolute",right:0,bottom:0,width:14,height:14,cursor:"nwse-resize",background:"linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.2) 50%)",zIndex:4}})]}),document.body);return n.jsxs(n.Fragment,{children:[Z,W,j&&n.jsx(pl,{targetRect:j.rect,activeZone:j.zone})]})}const ti={background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},qf=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Hi(e){for(const s of qf)if(!e.includes(s))return s;return qf[e.length%qf.length]}const JO="clitrigger:session-windows:global";function Rp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(JO),s=new Set;return e.onmessage=i=>{const a=i.data;for(const h of s)try{h(a)}catch{}},{post:i=>{e.postMessage(i)},subscribe:i=>(s.add(i),()=>{s.delete(i)}),close:()=>{s.clear(),e.close()}}}const zt="main",Am=new Map;function QO(e,s){Am.set(e,s)}function ZO(e){const s=Am.get(e);if(!s||s.closed)return Am.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function ez(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Mp=5e3,iS=15e3;let za=null;function aS(){if(typeof window>"u")return()=>{};const e=s=>{za={sx:s.screenX,sy:s.screenY,cx:s.clientX,cy:s.clientY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function Lu(e,s){if(za)return{x:za.cx+(e-za.sx),y:za.cy+(s-za.sy)};const i=Math.max(0,(window.outerWidth-window.innerWidth)/2),a=Math.max(0,window.outerHeight-window.innerHeight-i);return{x:e-window.screenX-i,y:s-window.screenY-a}}function Du(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Om="clitrigger:popout-alive:";function tz(e){return`${Om}${e}`}function Ap(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function nz(e){if(!Ap())return()=>{};let s=()=>{};return navigator.locks.request(tz(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function oS(){var e;if(!Ap())return new Set;try{const s=await navigator.locks.query(),i=new Set;for(const a of s.held??[])(e=a.name)!=null&&e.startsWith(Om)&&i.add(a.name.slice(Om.length));return i}catch{return new Set}}const Op=k.createContext(null),lS=k.createContext({});function cS(){const e=k.useContext(Op);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function sz(){return k.useContext(lS)}function rz(){return k.useContext(Op)}const Tu=720,zp=460,iz=320,az=200,Uy=30,uS=80,dS=80,ol=80,zm=28;function oz(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=iz?e.w:Tu,h=Number.isFinite(e.h)&&e.h>=az?e.h:zp;a=Math.min(a,s),h=Math.min(h,i);let f=Number.isFinite(e.x)?e.x:uS,m=Number.isFinite(e.y)?e.y:dS;return f=Math.max(Math.min(f,s-ol),-(a-ol)),m=Math.max(Math.min(m,i-zm),0),{x:f,y:m,w:a,h}}const lz=12,nu=60;function hS(e){return`sessionGroups:${e}`}function hu(e){try{const s=localStorage.getItem(hS(e));if(!s)return null;const i=JSON.parse(s);if(Array.isArray(i==null?void 0:i.groups)&&typeof(i==null?void 0:i.zCounter)=="number")return i}catch{}return null}function Bm(e,s){try{localStorage.setItem(hS(e),JSON.stringify(s))}catch{}}function cz(e,s){const i=hu(e);!i||!i.groups.some(a=>a.id===s)||(Bm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function uz(e){const s=e%8;return{x:uS+s*Uy,y:dS+s*Uy,w:Tu,h:zp}}function su(e,s,i){return Math.max(s,Math.min(i,e))}function Wy(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function ni(e,s){for(const i of e)if(Vu(i.root,s))return i;return null}function dz({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:h,onAddSession:f,children:m}){const{t:o}=dt(),[c]=k.useState(()=>{const Q=hu(e);if(!Q)return{groups:[],zCounter:0};const V=Q.groups.map(re=>{const te=dn(re.root),se=new Set(te),le={};for(const Qe of Object.keys(re.colors||{}))se.has(Qe)&&(le[Qe]=re.colors[Qe]);const ve={};for(const Qe of te)ve[Qe]={intent:"open",nonce:0},le[Qe]||(le[Qe]=Hi(Object.values(le)));const Ce=oz({x:re.x,y:re.y,w:re.w,h:re.h}),De=re.ownerWindowId||zt;return{...re,...Ce,colors:le,intents:ve,minimized:!!re.minimized,ownerWindowId:De}});return{groups:V,zCounter:Q.zCounter||V.length}}),[d,p]=k.useState(c.groups),u=k.useRef(c.zCounter),x=k.useRef(d);x.current=d;const b=k.useRef(s);b.current=s;const[C,S]=k.useState(null),g=k.useRef(null);g.current=C;const[_,w]=k.useState({}),y=k.useRef(_);y.current=_,k.useEffect(()=>{var te;const Q={},V=((te=hu(e))==null?void 0:te.sessionProjects)??{},re={};for(const se of d)for(const le of dn(se.root)){const ve=s.find(De=>De.id===le)||_[le];ve!=null&&ve.title&&(Q[le]=ve.title);const Ce=(ve==null?void 0:ve.project_id)||V[le];Ce&&(re[le]=Ce)}Bm(e,{groups:d,zCounter:u.current,titles:Q,sessionProjects:re}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,d,s,_]),k.useEffect(()=>()=>{var ve;const Q=x.current;if(Q.length===0)return;let V=!1;const re=Q.map(Ce=>(Ce.ownerWindowId||zt)!==zt||Ce.minimized?Ce:(V=!0,{...Ce,minimized:!0}));if(!V)return;const te={},se=((ve=hu(e))==null?void 0:ve.sessionProjects)??{},le={};for(const Ce of re)for(const De of dn(Ce.root)){const Qe=b.current.find(ot=>ot.id===De)||y.current[De];Qe!=null&&Qe.title&&(te[De]=Qe.title);const ut=(Qe==null?void 0:Qe.project_id)||se[De];ut&&(le[De]=ut)}Bm(e,{groups:re,zCounter:u.current,titles:te,sessionProjects:le}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]);const[E,T]=k.useState(()=>new Set),j=k.useRef(new Set);k.useEffect(()=>{if(s.length===0)return;const Q=s.filter(re=>re.project_id===e);if(Q.length===0)return;const V=new Set(Q.map(re=>re.id));for(const re of d)for(const te of dn(re.root))V.has(te)||_[te]||E.has(te)||j.current.has(te)||(j.current.add(te),S1(te).then(se=>w(le=>({...le,[te]:se}))).catch(se=>{se instanceof mu&&se.status===404&&T(le=>new Set(le).add(te))}).finally(()=>j.current.delete(te)))},[d,s,e,_,E]),k.useEffect(()=>h(V=>{V.type!=="session:status-changed"||!V.sessionId||w(re=>{const te=re[V.sessionId];if(!te)return re;const se={status:V.status};return V.worktree_path!==void 0&&(se.worktree_path=V.worktree_path),V.branch_name!==void 0&&(se.branch_name=V.branch_name),{...re,[te.id]:{...te,...se}}})}),[h]),k.useEffect(()=>{E.size!==0&&p(Q=>{let V=!1;const re=[];for(const te of Q){const se=dn(te.root);if(!se.some(ut=>E.has(ut))){re.push(te);continue}V=!0;const le=new Set(se.filter(ut=>!E.has(ut))),ve=KO(te.root,le);if(!ve)continue;const Ce=new Set(dn(ve)),De={};for(const ut of Object.keys(te.colors))Ce.has(ut)&&(De[ut]=te.colors[ut]);const Qe={};for(const ut of Object.keys(te.intents))Ce.has(ut)&&(Qe[ut]=te.intents[ut]);re.push({...te,root:ve,colors:De,intents:Qe})}return V?re:Q})},[E]);const R=k.useCallback((Q,V)=>{const re=x.current.length,te=uz(re);u.current+=1;const se=u.current;return{id:Wy(),...te,z:se,minimized:!1,root:yr([Q],Q),colors:{[Q]:Hi([])},intents:{[Q]:{intent:V,nonce:0}},ownerWindowId:zt}},[]),N=k.useCallback((Q,V="open")=>{p(re=>{const te=ni(re,Q);u.current+=1;const se=u.current;return te?re.map(le=>{var ut,ot,Je;if(le.id!==te.id)return le;const ve=((ut=le.intents[Q])==null?void 0:ut.intent)??"open",Ce=V==="start"||V==="resume",De=Ce?V:ve,Qe=De!==ve||Ce;return{...le,z:se,minimized:!1,root:Bs(le.root,Q),intents:{...le.intents,[Q]:{intent:De,nonce:Qe?(((ot=le.intents[Q])==null?void 0:ot.nonce)??0)+1:((Je=le.intents[Q])==null?void 0:Je.nonce)??0}}}}):[...re,R(Q,V)]})},[R]),D=k.useCallback(Q=>{p(V=>{const re=ni(V,Q);if(!re)return V;const te=V.reduce((le,ve)=>ve.z>le?ve.z:le,0);if(re.z===te&&!re.minimized)return V;u.current+=1;const se=u.current;return V.map(le=>le.id===re.id?{...le,z:se,minimized:!1}:le)})},[]),A=k.useCallback(Q=>{const V=Q.map(re=>b.current.find(te=>te.id===re)||y.current[re]).filter(re=>!!re&&re.status==="running");if(V.length===0)return!0;if(!window.confirm(o("session.confirmStop")))return!1;for(const re of V)yu(re.id).catch(()=>{});return!0},[o]),O=k.useCallback(Q=>{A([Q])&&p(V=>{const re=ni(V,Q);if(!re)return V;const te=Wi(re.root,Q);if(!te)return V.filter(ve=>ve.id!==re.id);new Set(dn(te));const se={...re.colors};delete se[Q];const le={...re.intents};return delete le[Q],V.map(ve=>ve.id===re.id?{...ve,root:te,colors:se,intents:le}:ve)})},[A]),z=k.useCallback(Q=>{p(V=>{const re=ni(V,Q);return re?V.map(te=>te.id===re.id?{...te,minimized:!0}:te):V})},[]),P=k.useCallback(Q=>{p(V=>{const re=ni(V,Q);if(!re)return V;u.current+=1;const te=u.current;return V.map(se=>se.id===re.id?{...se,minimized:!1,z:te}:se)})},[]),F=k.useCallback(Q=>!!ni(x.current,Q),[]),H=k.useCallback(Q=>{const V=x.current.find(re=>re.id===Q);V&&!A(dn(V.root))||p(re=>re.filter(te=>te.id!==Q))},[A]),$=k.useCallback(Q=>{p(V=>V.map(re=>re.id===Q?{...re,minimized:!0}:re))},[]);k.useEffect(()=>{const Q=re=>{const te=re.detail;!(te!=null&&te.projectId)||!te.groupId||te.projectId===e&&p(se=>{if(!se.find(Ce=>Ce.id===te.groupId))return se;u.current+=1;const ve=u.current;return se.map(Ce=>Ce.id===te.groupId?{...Ce,minimized:!1,z:ve}:Ce)})},V=re=>{var ve;const te=re.detail;if(!(te!=null&&te.projectId)||!te.groupId||te.projectId!==e)return;const se=x.current.find(Ce=>Ce.id===te.groupId);if(se&&!A(dn(se.root)))return;const le=(se==null?void 0:se.ownerWindowId)||zt;le!==zt&&(X.current.delete(le),Ie.current.delete(te.groupId),(ve=Z.current)==null||ve.post({t:"group-reclaimed",popoutId:le,groupIds:[te.groupId],reason:"late-return"})),p(Ce=>Ce.filter(De=>De.id!==te.groupId))};return window.addEventListener("session-windows:restore",Q),window.addEventListener("session-windows:close",V),()=>{window.removeEventListener("session-windows:restore",Q),window.removeEventListener("session-windows:close",V)}},[e,A]),k.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRestore");if(Q)try{const V=JSON.parse(Q);if(V.projectId!==e||!V.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),p(re=>{if(!re.find(le=>le.id===V.groupId))return re;u.current+=1;const se=u.current;return re.map(le=>le.id===V.groupId?{...le,minimized:!1,z:se}:le)})}catch{}},[e]);const q=k.useCallback(Q=>{p(V=>{if(!V.find(se=>se.id===Q))return V;u.current+=1;const te=u.current;return V.map(se=>se.id===Q?{...se,minimized:!1,z:te}:se)})},[]),Y=k.useCallback((Q,V)=>{p(re=>re.map(te=>te.id===Q?{...te,...V}:te))},[]),I=k.useCallback((Q,V,re)=>{p(te=>te.map(se=>se.id===Q?{...se,root:rS(se.root,V,re)}:se))},[]),B=k.useCallback((Q,V)=>{p(re=>re.map(te=>te.id===Q?{...te,root:Bs(te.root,V)}:te))},[]),U=k.useCallback((Q,V)=>{p(re=>re.map(te=>te.id===Q?{...te,root:WO(te.root,V)}:te))},[]),J=k.useCallback((Q,V,re)=>{p(te=>te.map(se=>se.id===Q?{...se,root:sS(se.root,V,re)}:se))},[]),W=k.useCallback((Q,V,re,te)=>{if(te.button!==0||!x.current.find(st=>st.id===Q))return;te.preventDefault();const le=te.clientX,ve=te.clientY;let Ce=null;S({groupId:Q,sessionId:V,fromPath:re,startX:le,startY:ve,mouseX:le,mouseY:ve,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null});const De=(st,ht)=>{const Re=Wy();Ce=Re;const ct=window.innerWidth,Oe=window.innerHeight,ie={x:su(st-60,-Tu+ol,ct-ol),y:su(ht-12,0,Oe-zm),w:Tu,h:zp};p(_e=>{const je=_e.find(Et=>Et.id===Q);if(!je)return _e;const we=Wi(je.root,V),rt=je.colors[V]||Hi([]),Me=je.intents[V]??{intent:"open",nonce:0};u.current+=1;const vt=u.current,bt={id:Re,...ie,z:vt,minimized:!1,root:yr([V],V),colors:{[V]:rt},intents:{[V]:Me},ownerWindowId:zt},St=[];for(const Et of _e)if(Et.id===Q){if(we){const Ht=new Set(dn(we)),pn={};for(const yn of Object.keys(Et.colors))Ht.has(yn)&&(pn[yn]=Et.colors[yn]);const gn={};for(const yn of Object.keys(Et.intents))Ht.has(yn)&&(gn[yn]=Et.intents[yn]);St.push({...Et,root:Nu(we),colors:pn,intents:gn})}}else St.push(Et);return St.push(bt),St})};let Qe=!1;const ut=st=>{const ht=window.screenX,Re=window.screenY,ct=ht+window.outerWidth,Oe=Re+window.outerHeight;return st.screenX<ht-nu||st.screenX>ct+nu||st.screenY<Re-nu||st.screenY>Oe+nu},ot=st=>{if(Qe)return;const ht=g.current;if(!ht)return;if(!Ce)Math.hypot(st.clientX-le,st.clientY-ve)>=lz&&De(st.clientX,st.clientY);else{const je=window.innerWidth,we=window.innerHeight,rt=su(st.clientX-60,-640,je-ol),Me=su(st.clientY-12,0,we-zm);p(vt=>vt.map(bt=>bt.id===Ce?{...bt,x:rt,y:Me}:bt))}if(Ce&&ut(st)&&x.current.some(je=>je.id===Ce)){const je=Fe.current;if(je){Qe=!0;const we=Ce;qe(),S(null),je(we,{atScreenX:st.screenX,atScreenY:st.screenY});return}}let Re=null,ct=null,Oe=null,ie=null;const _e=document.elementsFromPoint(st.clientX,st.clientY);for(const je of _e){const we=je.closest("[data-group-id][data-stack-path]");if(!we)continue;const rt=we.dataset.groupId||"",Me=we.dataset.stackPath||"";if(Ce?rt===Ce:rt===ht.groupId&&Me===ht.fromPath.join("."))continue;const bt=Me===""?[]:Me.split(".").map(Number),St=we.getBoundingClientRect();Re=rt,ct=bt,Oe={x:St.left,y:St.top,w:St.width,h:St.height},ie=Gu(st.clientX,st.clientY,Oe);break}S({...ht,mouseX:st.clientX,mouseY:st.clientY,hoveredGroupId:Re,hoveredPath:ct,hoveredRect:Oe,zone:ie})};let Je=!1;const qe=()=>{Je||(Je=!0,window.removeEventListener("mousemove",ot),window.removeEventListener("mouseup",pt),window.removeEventListener("blur",ft),window.removeEventListener("keydown",lt),document.removeEventListener("visibilitychange",xt))},ft=()=>{qe(),S(null)},lt=st=>{st.key==="Escape"&&ft()},xt=()=>{document.hidden&&ft()},pt=()=>{qe();const st=g.current;if(S(null),!!st&&st.hoveredGroupId&&st.hoveredPath&&st.zone){const ht=Ce||st.groupId;oe(ht,st.sessionId,st.hoveredGroupId,st.hoveredPath,st.zone);return}};window.addEventListener("mousemove",ot),window.addEventListener("mouseup",pt),window.addEventListener("blur",ft),window.addEventListener("keydown",lt),document.addEventListener("visibilitychange",xt)},[]),oe=k.useCallback((Q,V,re,te,se)=>{p(le=>{const ve=le.find(lt=>lt.id===Q),Ce=le.find(lt=>lt.id===re);if(!ve||!Ce)return le;if(Q===re){const lt=al(ve.root,te);if(!lt||lt.kind!=="stack")return le;const xt=lt.tabs.find(Re=>Re!==V);if(!xt)return le;const pt=Wi(ve.root,V);if(!pt)return le;const st=Vu(pt,xt);if(!st)return le;let ht;return se==="center"?ht=$i(pt,st,V):ht=Pa(pt,st,se,yr([V])),ht=Bs(ht,V),le.map(Re=>Re.id!==Q?Re:(u.current+=1,{...Re,root:ht,z:u.current,minimized:!1}))}const De=Wi(ve.root,V),Qe=ve.colors[V],ut=ve.intents[V]??{intent:"open",nonce:0};let ot;if(se==="center")ot=$i(Ce.root,te,V);else{const lt=yr([V]);ot=Pa(Ce.root,te,se,lt)}ot=Bs(ot,V);const Je={...Ce.colors};Je[V]||(Je[V]=Qe||Hi(Object.values(Je)));const qe={...Ce.intents,[V]:ut},ft=[];for(const lt of le)if(lt.id===Q){if(De){const xt=new Set(dn(De)),pt={};for(const ht of Object.keys(lt.colors))xt.has(ht)&&(pt[ht]=lt.colors[ht]);const st={};for(const ht of Object.keys(lt.intents))xt.has(ht)&&(st[ht]=lt.intents[ht]);ft.push({...lt,root:De,colors:pt,intents:st})}}else lt.id===re?(u.current+=1,ft.push({...lt,root:ot,colors:Je,intents:qe,z:u.current,minimized:!1})):ft.push(lt);return ft})},[]),ee=k.useCallback((Q,V,re,te)=>{p(se=>{if(Q===V)return se;const le=se.find(Je=>Je.id===Q),ve=se.find(Je=>Je.id===V);if(!le||!ve||le.root.kind!=="stack")return se;const Ce=le.root;let De;te==="center"?De=Ce.tabs.reduce((Je,qe)=>$i(Je,re,qe),ve.root):De=Pa(ve.root,re,te,Ce),De=Bs(De,Ce.activeTab);const Qe={...ve.colors,...le.colors},ut={...ve.intents,...le.intents},ot=[];for(const Je of se)Je.id!==Q&&(Je.id===V?(u.current+=1,ot.push({...Je,root:De,colors:Qe,intents:ut,z:u.current,minimized:!1})):ot.push(Je));return ot})},[]),Z=k.useRef(null),X=k.useRef(new Map),[G,me]=k.useState(null),ge=k.useRef(G);ge.current=G;const xe=k.useRef(null),he=k.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);k.useEffect(()=>{const Q=()=>{he.current=Date.now()};window.addEventListener("focus",Q);const V=aS();return()=>{window.removeEventListener("focus",Q),V(),xe.current&&clearTimeout(xe.current)}},[]);const Ie=k.useRef(new Map),Fe=k.useRef(null),be=k.useCallback((Q,V)=>{var ot;const re=x.current.find(Je=>Je.id===Q);if(!re)return;const te=ez(),se={...re,ownerWindowId:te};Ie.current.set(Q,se),X.current.set(te,Date.now()),p(Je=>Je.map(qe=>qe.id===Q?{...qe,ownerWindowId:te}:qe)),(ot=Z.current)==null||ot.post({t:"group-handoff",to:te,groupId:Q,group:se});const le=V&&(typeof V.atScreenX=="number"||typeof V.atScreenY=="number"),ve=le?Math.max(0,((V==null?void 0:V.atScreenX)??window.screenX+re.x)-40):Math.max(0,window.screenX+re.x),Ce=le?Math.max(0,((V==null?void 0:V.atScreenY)??window.screenY+re.y)-12):Math.max(0,window.screenY+re.y),De=["popup",`width=${Math.max(400,re.w)}`,`height=${Math.max(300,re.h+40)}`,`left=${ve}`,`top=${Ce}`].join(","),Qe=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(Q)}?wid=${encodeURIComponent(te)}`,ut=window.open(Qe,"_blank",De);if(!ut){Ie.current.delete(Q),X.current.delete(te),p(Je=>Je.map(qe=>qe.id===Q?{...qe,ownerWindowId:zt}:qe)),window.alert(o("session.popout.blocked")||"Popup blocked. Allow popups for this site to use Pop Out.");return}QO(te,ut)},[e,o]);Fe.current=be;const Ue=k.useCallback(Q=>{var te;const V=x.current.find(se=>se.id===Q);if(!V)return;const re=V.ownerWindowId||zt;if(re===zt){q(Q);return}(te=Z.current)==null||te.post({t:"group-recall",popoutId:re,groupId:Q}),setTimeout(()=>{var ve;const se=x.current.find(Ce=>Ce.id===Q);if(!se||(se.ownerWindowId||zt)===zt)return;X.current.delete(re),Ie.current.delete(Q),(ve=Z.current)==null||ve.post({t:"group-reclaimed",popoutId:re,groupIds:[Q],reason:"late-return"}),u.current+=1;const le=u.current;p(Ce=>Ce.map(De=>De.id===Q?{...De,ownerWindowId:zt,minimized:!1,z:le}:De))},1500)},[q]),Pe=k.useCallback(Q=>{const V=ni(x.current,Q);V&&Ue(V.id)},[Ue]);k.useEffect(()=>{const Q=V=>{const re=V.detail;!(re!=null&&re.projectId)||!re.groupId||re.projectId!==e||Ue(re.groupId)};return window.addEventListener("session-windows:recall",Q),()=>window.removeEventListener("session-windows:recall",Q)},[e,Ue]),k.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRecall");if(Q)try{const V=JSON.parse(Q);if(V.projectId!==e||!V.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const re=V.groupId;setTimeout(()=>Ue(re),0)}catch{}},[e,Ue]);const tt=k.useCallback(Q=>Q.kind==="stack"?[]:[0,...tt(Q.children[0])],[]),ke=k.useCallback((Q,V,re)=>{const te=V?x.current.find(Ce=>Ce.id===V):null,se=te&&(te.ownerWindowId||zt)===zt;if(!te||!se){N(Q,"start");return}const le=(()=>{if(re){const Ce=al(te.root,re);if(Ce&&Ce.kind==="stack")return re}return tt(te.root)})();u.current+=1;const ve=u.current;p(Ce=>Ce.map(De=>{if(De.id!==te.id)return De;const Qe=Bs($i(De.root,le,Q),Q);return{...De,root:Qe,z:ve,minimized:!1,colors:{...De.colors,[Q]:Hi(Object.values(De.colors))},intents:{...De.intents,[Q]:{intent:"start",nonce:0}}}}))},[N,tt]),pe=k.useCallback(async(Q,V)=>{const re=new Date,te=String(re.getHours()).padStart(2,"0"),se=String(re.getMinutes()).padStart(2,"0"),le=String(re.getSeconds()).padStart(2,"0"),ve=await xm(e,{title:`Shell ${te}:${se}:${le}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(ve),ke(ve.id,Q,V),ve.id},[e,f,ke]);k.useEffect(()=>{const Q=Rp();Z.current=Q;const V=te=>{var se;if(te.t==="hello"){const le=Ie.current.get(te.groupId);if(le&&le.ownerWindowId===te.from)Q.post({t:"group-handoff",to:te.from,groupId:te.groupId,group:le});else{const ve=x.current.find(Ce=>Ce.id===te.groupId);ve&&ve.ownerWindowId===te.from&&Q.post({t:"group-handoff",to:te.from,groupId:te.groupId,group:ve})}}else if(te.t==="group-return"||te.t==="bye")if(te.t==="group-return"){const le=te.group;le&&le.id===te.groupId&&(Ie.current.delete(te.groupId),X.current.delete(te.from),te.projectId&&te.projectId!==e&&cz(te.projectId,te.groupId),p(ve=>{const Ce=ve.find(Qe=>Qe.id===te.groupId),De={...le,ownerWindowId:zt};return Ce?ve.map(Qe=>Qe.id===te.groupId?De:Qe):[...ve,De]}))}else X.current.delete(te.from),p(le=>le.map(ve=>ve.ownerWindowId===te.from?{...ve,ownerWindowId:zt}:ve));else if(te.t==="group-close")Ie.current.delete(te.groupId),p(le=>le.filter(ve=>ve.id!==te.groupId));else if(te.t==="heartbeat")X.current.set(te.from,Date.now());else if(te.t==="group-update"){const le=te.patch;p(ve=>ve.map(Ce=>Ce.id===te.groupId?{...Ce,...le}:Ce))}else if(te.t==="dock-probe"){if(document.visibilityState!=="visible")return;const le=Lu(te.x,te.y),ve=Du(le)?ju(le.x,le.y):null;if(ve){const Ce=ge.current;(!Ce||Ce.zone!==ve.zone||Ce.groupId!==ve.groupId||Ce.path.join(".")!==ve.path.join("."))&&me({rect:ve.rect,zone:ve.zone,path:ve.path,groupId:ve.groupId}),xe.current&&clearTimeout(xe.current),xe.current=setTimeout(()=>me(null),800),Q.post({t:"dock-probe-result",from:zt,to:te.from,hit:!0,focusAt:he.current})}else ge.current&&me(null),Q.post({t:"dock-probe-result",from:zt,to:te.from,hit:!1,focusAt:he.current})}else if(te.t==="dock-end")me(null);else if(te.t==="dock-commit"&&te.to===zt){const le=Lu(te.x,te.y),ve=Du(le)?ju(le.x,le.y):null,Ce=ve&&ve.zone?ve:(se=ge.current)!=null&&se.zone?ge.current:null;let De=!1;const Qe=x.current.filter(ut=>(ut.ownerWindowId||zt)===zt);if(Ce&&Ce.zone&&!ni(Qe,te.sessionId)){const ut=x.current.find(Je=>Je.id===Ce.groupId),ot=ut?al(ut.root,Ce.path):null;if(ut&&ot&&ot.kind==="stack"){De=!0;const Je=Ce.zone,qe=Ce.path;u.current+=1;const ft=u.current;p(lt=>lt.map(xt=>{if(xt.id!==ut.id)return xt;const pt=Je==="center"?$i(xt.root,qe,te.sessionId):Pa(xt.root,qe,Je,yr([te.sessionId])),st=Bs(pt,te.sessionId),ht={...xt.colors};ht[te.sessionId]||(ht[te.sessionId]=te.color||Hi(Object.values(ht)));const Re={...xt.intents,[te.sessionId]:te.intentInfo??{intent:"open",nonce:0}};return{...xt,root:st,colors:ht,intents:Re,z:ft,minimized:!1}}))}}me(null),Q.post({t:"dock-commit-ack",from:zt,to:te.from,sessionId:te.sessionId,accepted:De})}},re=Q.subscribe(V);return()=>{re(),Q.close(),Z.current=null}},[e]),k.useEffect(()=>{const Q=Date.now();for(const V of c.groups)V.ownerWindowId&&V.ownerWindowId!==zt&&X.current.set(V.ownerWindowId,Q)},[]),k.useEffect(()=>{const Q=async()=>{var Ce;const re=Date.now(),te=[];for(const[De,Qe]of X.current.entries())re-Qe>iS&&te.push(De);if(te.length===0)return;const se=await oS(),le=te.filter(De=>se.has(De)?(X.current.set(De,re),!1):!0);if(le.length===0)return;for(const De of le)X.current.delete(De);const ve=new Set(le);for(const De of x.current)De.ownerWindowId&&ve.has(De.ownerWindowId)&&Ie.current.delete(De.id);for(const De of le){const Qe=x.current.filter(ut=>ut.ownerWindowId===De).map(ut=>ut.id);Qe.length>0&&((Ce=Z.current)==null||Ce.post({t:"group-reclaimed",popoutId:De,groupIds:Qe,reason:"heartbeat-timeout"}))}p(De=>De.map(Qe=>Qe.ownerWindowId&&le.includes(Qe.ownerWindowId)?{...Qe,ownerWindowId:zt}:Qe))},V=setInterval(()=>{Q()},Mp);return()=>clearInterval(V)},[]);const Ne=k.useCallback((Q,V)=>{i({type:"session:terminal-input",sessionId:Q,input:V})},[i]),Le=k.useCallback(()=>{var re,te;const Q=x.current.filter(se=>(se.ownerWindowId||zt)===zt).slice().sort((se,le)=>le.z-se.z),V=[];for(const se of Q)for(const le of dn(se.root)){const ve=((re=b.current.find(Ce=>Ce.id===le))==null?void 0:re.title)||((te=y.current[le])==null?void 0:te.title)||le;V.push({sessionId:le,label:ve})}return V},[]),ze=k.useCallback(async(Q,V)=>{const te=x.current.filter(le=>!le.minimized&&(le.ownerWindowId||zt)===zt).reduce((le,ve)=>le&&le.z>=ve.z?le:ve,null),se=await xm(e,{title:V||"",description:Q,use_worktree:!1,memory_inject_mode:"none"});f==null||f(se),ke(se.id,(te==null?void 0:te.id)??null)},[e,f,ke]),Ke=k.useMemo(()=>({openOrFocus:N,close:O,focus:D,minimize:z,restore:P,isOpen:F,recallPopout:Pe,closeGroup:H,minimizeGroup:$,restoreGroup:q,setGroupGeometry:Y,setSplitSizes:I,setActiveTab:B,applyLayoutPreset:U,reorderTab:J,beginTabDrag:W,dockGroup:ee,popOutGroup:be,createRawShellTab:pe,sendToSession:Ne,listOpenTerminals:Le,sendToNewTerminal:ze}),[N,O,D,z,P,F,Pe,H,$,q,Y,I,B,U,J,W,ee,be,pe,Ne,Le,ze]),Ve=k.useMemo(()=>{const Q={};for(const V of d){const te=(V.ownerWindowId||zt)!==zt?"popped":V.minimized?"minimized":"floating";for(const se of dn(V.root))Q[se]=te}return Q},[d]);k.useEffect(()=>{const Q=V=>{const re=/Mac|iPhone|iPad|iPod/.test(navigator.platform),te=re?V.metaKey:V.ctrlKey,se=re?V.ctrlKey:V.metaKey;if(!te||se||V.altKey||V.shiftKey||V.key.toLowerCase()!=="t")return;V.preventDefault();const ve=x.current.filter(Ce=>!Ce.minimized&&(Ce.ownerWindowId||zt)===zt).reduce((Ce,De)=>Ce&&Ce.z>=De.z?Ce:De,null);pe((ve==null?void 0:ve.id)??null).catch(()=>{})};return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[pe]);const de=k.useMemo(()=>{const Q=new Map;for(const V of Object.values(_))Q.set(V.id,V);for(const V of s)Q.set(V.id,V);return Q},[s,_]),fe=d.filter(Q=>!Q.minimized&&(Q.ownerWindowId||zt)===zt),ce=fe.reduce((Q,V)=>V.z>Q.z?{id:V.id,z:V.z}:Q,{id:null,z:-1/0}).id;return n.jsx(Op.Provider,{value:Ke,children:n.jsxs(lS.Provider,{value:Ve,children:[m,(()=>{const Q=new Map(fe.slice().sort((V,re)=>V.z-re.z).map((V,re)=>[V.id,re+1]));return fe.map(V=>{const re=fe.filter(te=>te.id!==V.id).map(({x:te,y:se,w:le,h:ve})=>({x:te,y:se,w:le,h:ve}));return n.jsx(XO,{group:V,sessionsById:de,neighbors:re,isTopmost:V.id===ce,zIndex:Q.get(V.id)??1,sendMessage:i,subscribeBinary:a,onEvent:h},V.id)})})(),C&&C.hoveredRect&&n.jsx(pl,{targetRect:C.hoveredRect,activeZone:C.zone}),G&&n.jsx(pl,{targetRect:G.rect,activeZone:G.zone})]})})}function hz(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const fz={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",stopped:"bg-amber-100 text-amber-700"},mz={floating:"bg-accent/10 text-accent",minimized:"bg-warm-200 text-warm-600",popped:"bg-violet-500/15 text-violet-500"};function pz({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:h,projectDefaultBranch:f,onAddSession:m,onUpdateSession:o,onStopSession:c,onDeleteSession:d,onCleanupSession:p}){const{t:u}=dt(),{openOrFocus:x,recallPopout:b}=cS(),C=sz(),[S,g]=k.useState(!1),[_,w]=k.useState(!1),[y,E]=k.useState(null),[T,j]=k.useState(!1),[R,N]=k.useState(null),[D,A]=k.useState([]),[O,z]=k.useState(""),[P,F]=k.useState(null);k.useEffect(()=>{let W=!1;return sp().then(oe=>{W||A(oe)}).catch(()=>{}),()=>{W=!0}},[]),k.useEffect(()=>{if(!a)return;let W=!1;return Xw(e).then(oe=>{W||z(oe.branch||"")}).catch(()=>{}),()=>{W=!0}},[e,a]);const H=k.useMemo(()=>{const W=new Map;for(const oe of D)W.set(oe.id,oe);return W},[D]),$=k.useMemo(()=>y?s.find(W=>W.id===y)??null:null,[y,s]),q=k.useMemo(()=>{if($)return{title:$.title,description:$.description??"",cliTool:$.cli_tool??"",useWorktree:$.use_worktree===1,memoryInjectMode:$.memory_inject_mode??"none",memoryNodeIds:iO($.memory_node_ids??null),memoryRawFilePaths:hz($.memory_raw_file_paths??null),tagId:$.tag_id??null}},[$]),Y=k.useCallback(()=>{E(null),N(null),g(W=>!W)},[]),I=k.useCallback(W=>{g(!1),N(null),E(W)},[]),B=k.useCallback(()=>{g(!1),E(null),N(null)},[]),U=k.useCallback(async(W,oe,ee,Z,X,G,me,ge)=>{w(!0);try{const xe=await xm(e,{title:W,description:oe||void 0,cli_tool:ee,use_worktree:Z,memory_inject_mode:X,memory_node_ids:G,memory_raw_file_paths:me,tag_id:ge??null});m(xe),g(!1)}finally{w(!1)}},[e,m]),J=k.useCallback(async(W,oe,ee,Z,X,G,me,ge)=>{if(y){j(!0),N(null);try{const xe=await S4(y,{title:W,description:oe||void 0,cli_tool:ee,use_worktree:Z,memory_inject_mode:X,memory_node_ids:G,memory_raw_file_paths:me,tag_id:ge??null});o(xe),E(null)}catch(xe){N(xe instanceof Error?xe.message:String(xe))}finally{j(!1)}}},[y,o]);return n.jsxs("div",{className:"space-y-4 animate-fade-in min-h-[50vh]",onContextMenu:W=>{hi(W)||(W.preventDefault(),F({x:W.clientX,y:W.clientY,sessionId:null}))},children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:u("tabs.sessions")}),n.jsxs("button",{onClick:Y,className:"btn-primary text-xs py-2",disabled:_,children:["+ ",u("session.new")]})]}),S&&n.jsx(wy,{projectId:e,onSave:U,onCancel:B,projectCliTool:i,isGitRepo:a,projectUseWorktree:h}),q&&y&&n.jsxs("div",{className:"space-y-2",children:[n.jsx(wy,{projectId:e,initial:q,onSave:J,onCancel:B,projectCliTool:i,isGitRepo:a},y),(T||R)&&n.jsxs("div",{className:"text-xs px-1",children:[T&&n.jsx("span",{className:"text-warm-500",children:u("session.saving")||"saving…"}),R&&n.jsx("span",{className:"text-status-error",children:R})]})]}),s.length===0&&!S?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:dl,title:u("session.empty"),description:u("session.emptyHint")})}):n.jsx("div",{className:"space-y-3",children:s.map((W,oe)=>{const ee=["pending","failed","stopped","completed"].includes(W.status),Z=W.status==="running",X=W.status!=="running",G=["stopped","failed","completed"].includes(W.status)&&(W.cli_tool??"claude")==="claude"&&!!W.worktree_path,me=y===W.id,ge=C[W.id]??"closed",xe=ge==="popped";return n.jsx("div",{className:`card overflow-hidden animate-slide-up ${me?"border-l-4 border-accent bg-warm-100/30":""}`,style:{animationDelay:`${oe*50}ms`},onContextMenu:he=>{hi(he)||(he.preventDefault(),he.stopPropagation(),F({x:he.clientX,y:he.clientY,sessionId:W.id}))},children:n.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>xe?b(W.id):x(W.id,"open"),children:n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[W.tag_id&&H.get(W.tag_id)&&n.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium",style:{backgroundColor:`${H.get(W.tag_id).color}22`,color:H.get(W.tag_id).color},children:[n.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:H.get(W.tag_id).color}}),H.get(W.tag_id).name]}),n.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:W.title}),n.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-semibold uppercase ${fz[W.status]||""}`,children:u(`status.${W.status}`)||W.status}),ge!=="closed"&&n.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium ${mz[ge]}`,title:xe?u("session.dock.poppedHint"):void 0,children:[xe&&n.jsx(li,{size:10}),u(`session.windowState.${ge}`)]})]}),W.description&&n.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:W.description}),n.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[n.jsx("span",{className:"text-2xs text-warm-300",children:W.cli_tool||"claude"}),(W.branch_name||a&&(O||f))&&n.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[n.jsx(Ga,{size:12}),W.branch_name||O||f]})]})]}),n.jsxs("div",{className:"flex gap-1",onClick:he=>he.stopPropagation(),children:[xe&&n.jsx("button",{onClick:()=>b(W.id),className:"p-1.5 text-violet-500 hover:bg-violet-500/10 rounded transition-colors",title:u("session.recallToMain"),children:n.jsx(qi,{size:16})}),ee&&n.jsx("button",{onClick:()=>x(W.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded transition-colors",title:u("session.start"),children:n.jsx(kr,{size:16})}),G&&n.jsx("button",{onClick:()=>x(W.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded transition-colors",title:u("session.resumeHint")||u("session.resume"),children:n.jsx(ui,{size:16})}),n.jsx("button",{onClick:()=>I(W.id),disabled:!X,className:"p-1.5 text-warm-500 hover:text-warm-800 hover:bg-warm-100 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-warm-500",title:u(X?"session.edit":"session.editDisabledRunning"),children:n.jsx(im,{size:16})}),Z&&n.jsx("button",{onClick:()=>c(W.id),className:"p-1.5 text-amber-600 hover:bg-amber-50 rounded transition-colors",title:u("session.stop"),children:n.jsx(Ki,{size:16})}),W.status!=="running"&&(!!W.worktree_path||!!W.branch_name)&&n.jsx("button",{onClick:()=>{const he=W.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",W.branch_name)):!1;p(W.id,he)},className:"p-1.5 text-warm-400 hover:text-amber-600 rounded transition-colors",title:u("session.cleanup"),children:n.jsx(pu,{size:16})}),n.jsx("button",{onClick:()=>d(W.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded transition-colors",title:u("session.delete"),children:n.jsx(Ln,{size:16})})]})]})})},W.id)})}),P&&(()=>{const W=()=>F(null),oe=P.sessionId?s.find(Ie=>Ie.id===P.sessionId):void 0;if(!oe)return n.jsx(Cr,{x:P.x,y:P.y,onClose:W,children:n.jsxs("button",{type:"button",onClick:()=>{E(null),N(null),g(!0)},className:an,children:[n.jsx(mn,{size:14}),u("session.new")]})});const ee=["pending","failed","stopped","completed"].includes(oe.status),Z=oe.status==="running",X=oe.status!=="running",G=["stopped","failed","completed"].includes(oe.status)&&(oe.cli_tool??"claude")==="claude"&&!!oe.worktree_path,me=oe.status!=="running"&&(!!oe.worktree_path||!!oe.branch_name),ge=C[oe.id]??"closed",xe=ge==="popped",he=u(xe?"session.recallToMain":ge==="minimized"?"session.restoreWindow":ge==="floating"?"session.focusWindow":"session.openWindow");return n.jsxs(Cr,{x:P.x,y:P.y,onClose:W,children:[n.jsxs("button",{type:"button",onClick:()=>xe?b(oe.id):x(oe.id,"open"),className:an,children:[xe?n.jsx(qi,{size:14}):n.jsx(dl,{size:14}),he]}),ee&&n.jsxs("button",{type:"button",onClick:()=>x(oe.id,"start"),className:an,children:[n.jsx(kr,{size:14}),u("session.start")]}),G&&n.jsxs("button",{type:"button",onClick:()=>x(oe.id,"resume"),className:an,title:u("session.resumeHint")||u("session.resume"),children:[n.jsx(ui,{size:14}),u("session.resume")]}),X&&n.jsxs("button",{type:"button",onClick:()=>I(oe.id),className:an,children:[n.jsx(im,{size:14}),u("session.edit")]}),Z&&n.jsxs("button",{type:"button",onClick:()=>c(oe.id),className:an,children:[n.jsx(Ki,{size:14}),u("session.stop")]}),me&&n.jsxs("button",{type:"button",onClick:()=>{const Ie=oe.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",oe.branch_name)):!1;p(oe.id,Ie)},className:an,children:[n.jsx(pu,{size:14}),u("session.cleanup")]}),n.jsx(z_,{}),n.jsxs("button",{type:"button",onClick:()=>d(oe.id),className:Ep,children:[n.jsx(Ln,{size:14}),u("session.delete")]})]})})()]})}const Ru={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"}},gz=Object.keys(Ru);function Fa(e){const s=Ru[e]||Ru.default;return`${s.bg} ${s.text}`}function Bp({src:e,alt:s,onClose:i}){return k.useEffect(()=>{const a=h=>{h.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),en.createPortal(n.jsxs("div",{className:"fixed inset-0 z-tooltip flex items-center justify-center p-6",style:{backgroundColor:"rgba(0,0,0,0.85)"},onClick:i,children:[n.jsx("button",{type:"button",onClick:i,className:"absolute top-4 right-4 h-9 w-9 rounded-full bg-white/10 text-white flex items-center justify-center hover:bg-white/20 transition-colors","aria-label":"close",children:n.jsx(Jt,{size:18})}),n.jsx("img",{src:e,alt:s,className:"max-w-full max-h-full object-contain rounded-lg",onClick:a=>a.stopPropagation()})]}),document.body)}function Pm({anchorRef:e,width:s,onClose:i,className:a,style:h,children:f}){const m=k.useRef(null),[o,c]=k.useState(null);return k.useLayoutEffect(()=>{const d=e.current;if(!d)return;const p=d.getBoundingClientRect();let u=p.left;u+s>window.innerWidth-8&&(u=Math.max(8,window.innerWidth-8-s)),u<8&&(u=8),c({top:p.bottom+4,left:u})},[e,s]),k.useEffect(()=>{const d=u=>{var b,C;const x=u.target;(b=m.current)!=null&&b.contains(x)||(C=e.current)!=null&&C.contains(x)||i()},p=()=>i();return document.addEventListener("mousedown",d),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("mousedown",d),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[i,e]),o?en.createPortal(n.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...h},children:f}),document.body):null}const qy={pending:"bg-warm-200 text-warm-500",in_progress:"bg-blue-500/10 text-blue-600",done:"bg-emerald-500/10 text-emerald-600",moved:"bg-purple-500/10 text-purple-600"},Ky={0:{label:"—",style:"text-warm-300"},1:{label:"●",style:"text-warm-500"},2:{label:"●●",style:"text-amber-500"},3:{label:"●●●",style:"text-red-500"}};function xz({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:c}){var fe,ce;const{t:d}=dt(),[p,u]=k.useState(!1),[x,b]=k.useState(!1),[C,S]=k.useState(!1),g=k.useRef(null),_=k.useRef(null),[w,y]=k.useState({top:0,left:0}),[E,T]=k.useState(e.title),[j,R]=k.useState(e.description??""),[N,D]=k.useState(e.priority),[A,O]=k.useState(e.due_date??""),[z,P]=k.useState(e.status),[F,H]=k.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[$,q]=k.useState(""),[Y,I]=k.useState(!1),[B,U]=k.useState(null),[J,W]=k.useState(null),oe=k.useRef(null),ee=k.useRef(null),[Z,X]=k.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),G=k.useRef(null);k.useEffect(()=>{T(e.title),R(e.description??""),D(e.priority),O(e.due_date??""),P(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{X(e.images?JSON.parse(e.images):[])}catch{X([])}},[e]);const me=F,ge=e.status==="moved",xe=e.due_date&&new Date(e.due_date)<new Date&&!ge&&e.status!=="done",he=k.useCallback(Q=>{a(e.id,Q)},[e.id,a]),Ie=()=>{const Q=E.trim();Q&&Q!==e.title?he({title:Q}):T(e.title)},Fe=()=>{const Q=j.trim();Q!==(e.description??"")&&he({description:Q||void 0})},be=Q=>{D(Q),Q!==e.priority&&he({priority:Q})},Ue=Q=>{O(Q),Q!==(e.due_date??"")&&he({due_date:Q||void 0})},Pe=Q=>{const V=Q;P(V),V!==e.status&&he({status:V})},tt=Q=>{H(Q);const V=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(Q)!==JSON.stringify(V)&&he({tags:Q.length>0?JSON.stringify(Q):void 0})},ke=Q=>{var re;const V=Q.trim();if(V&&!F.includes(V)&&(tt([...F,V]),!s.has(V)&&c)){const te=["blue","green","orange","purple","pink","red","yellow","brown"],se=te[s.size%te.length];c(V,{color:se})}q(""),(re=oe.current)==null||re.focus()},pe=Q=>tt(F.filter(V=>V!==Q)),Ne=i.filter(Q=>!F.includes(Q)&&(!$||Q.toLowerCase().includes($.toLowerCase()))),Le=k.useCallback(Q=>{const V=Array.from(Q).filter(se=>se.type.startsWith("image/")),re=[];let te=0;for(const se of V){const le=new FileReader;le.onload=()=>{re.push({name:se.name,data:le.result}),te++,te===V.length&&C1(e.id,re).then(ve=>X(ve.images))},le.readAsDataURL(se)}},[e.id]),ze=k.useCallback(Q=>{var te;const V=(te=Q.clipboardData)==null?void 0:te.items;if(!V)return;const re=[];for(let se=0;se<V.length;se++)if(V[se].type.startsWith("image/")){const le=V[se].getAsFile();le&&re.push(le)}re.length!==0&&(Q.preventDefault(),Le(re))},[Le]),Ke=k.useCallback(Q=>{var V;Q.preventDefault(),Q.stopPropagation(),(V=Q.dataTransfer)!=null&&V.files&&Le(Q.dataTransfer.files)},[Le]),Ve=k.useCallback(Q=>{j1(e.id,Q).then(()=>{X(V=>V.filter(re=>re.id!==Q))})},[e.id]),de=k.useCallback(()=>{if(!g.current)return;const Q=g.current.getBoundingClientRect(),V=window.innerWidth,re=window.innerHeight;let te=Q.bottom+4;const se=_.current;if(se){const le=se.offsetWidth,ve=se.offsetHeight;let Ce=Q.right-le;Ce<8&&(Ce=8),Ce+le>V-8&&(Ce=V-8-le),te+ve>re-8&&(te=Q.top-ve-4),y({top:te,left:Ce}),S(!0)}else y({top:te,left:Math.max(8,Q.right-180)})},[]);return k.useEffect(()=>{if(!p){S(!1);return}de();const Q=requestAnimationFrame(de),V=re=>{var se,le;const te=re.target;(se=g.current)!=null&&se.contains(te)||(le=_.current)!=null&&le.contains(te)||u(!1)};return document.addEventListener("mousedown",V),window.addEventListener("scroll",de,!0),window.addEventListener("resize",de),()=>{cancelAnimationFrame(Q),document.removeEventListener("mousedown",V),window.removeEventListener("scroll",de,!0),window.removeEventListener("resize",de)}},[p,de]),n.jsxs("div",{className:`${ge?"opacity-50":""}`,style:{borderBottom:"1px solid var(--color-border-muted)"},children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg transition-colors hover:bg-warm-50 cursor-pointer",onDoubleClick:()=>b(!x),children:[n.jsx(Ns,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${x?"rotate-90":""}`,onClick:Q=>{Q.stopPropagation(),b(!x)}}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("span",{className:"text-sm font-medium truncate block",style:{color:"var(--color-text-primary)"},children:e.title}),ge&&e.converted_type&&n.jsxs("span",{className:"text-2xs text-purple-500",children:["→ ",e.converted_type==="todo"?d("planner.movedToTodo"):e.converted_type==="session"?d("planner.movedToSession"):d("planner.movedToSchedule")]}),e.source_discussion_id&&n.jsxs(Pn,{to:`/projects/${e.project_id}/discussions/${e.source_discussion_id}`,onClick:Q=>Q.stopPropagation(),className:"inline-flex items-center gap-1 text-2xs text-accent hover:underline mt-0.5",title:d("planner.fromDiscussion"),children:[n.jsx(EE,{size:11}),d("planner.fromDiscussion")]})]}),n.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[Z.length>0&&n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-warm-100 text-warm-500 whitespace-nowrap",children:[n.jsx(Ha,{size:10}),Z.length]}),me.map(Q=>n.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium whitespace-nowrap ${Fa(s.get(Q)||"default")}`,children:Q},Q))]}),n.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:n.jsx("span",{className:`text-xs font-medium ${((fe=Ky[e.priority])==null?void 0:fe.style)??"text-warm-300"}`,children:((ce=Ky[e.priority])==null?void 0:ce.label)??"—"})}),n.jsx("div",{className:"hidden md:block w-20 text-right flex-shrink-0",children:e.due_date?n.jsx("span",{className:`text-xs ${xe?"text-red-500 font-medium":"text-warm-500"}`,children:new Date(e.due_date).toLocaleDateString(void 0,{month:"numeric",day:"numeric"})}):n.jsx("span",{className:"text-xs text-warm-300",children:d("planner.noDueDate")})}),n.jsx("div",{className:"w-16 flex-shrink-0",children:n.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${qy[e.status]||qy.pending}`,children:d(`plannerStatus.${e.status}`)})}),n.jsxs("div",{className:"w-8 flex-shrink-0",children:[n.jsx("button",{ref:g,onClick:Q=>{Q.stopPropagation(),u(!p)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:n.jsx(Xm,{size:14})}),p&&en.createPortal(n.jsxs("div",{ref:_,className:`fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated${C?" animate-scale-in":""}`,style:{top:w.top,left:w.left,opacity:C?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>u(!1),children:[!ge&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:f,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:[n.jsx(Pw,{size:12})," ",d("planner.convertToTask")]}),n.jsxs("button",{onClick:m,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:[n.jsx(ai,{size:12})," ",d("planner.convertToSchedule")]}),n.jsxs("button",{onClick:o,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:[n.jsx(di,{size:12})," ",d("planner.convertToTerminal")]})]}),n.jsxs("button",{onClick:()=>{confirm(d("planner.deleteConfirm"))&&h()},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-red-500 hover:bg-red-50 rounded-md transition-colors text-left",children:[n.jsx(Ln,{size:12})," ",d("planner.delete")]})]}),document.body)]})]}),x&&n.jsx("div",{className:"px-4 pb-3 pt-1 ml-8 animate-fade-in",children:n.jsxs("div",{className:"rounded-lg px-4 py-3 space-y-3",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[n.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:E,onChange:Q=>T(Q.target.value),onBlur:Ie,onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),Ie(),Q.target.blur())}}),n.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:d("plannerForm.descPlaceholder"),value:j,onChange:Q=>R(Q.target.value),onPaste:ze,onDrop:Ke,onDragOver:Q=>{Q.preventDefault(),Q.stopPropagation()},onBlur:Fe}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[n.jsxs("button",{type:"button",onClick:()=>{var Q;return(Q=G.current)==null?void 0:Q.click()},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[n.jsx(Ha,{size:12}),d("plannerForm.addImage")]}),n.jsx("span",{className:"text-[10px] text-warm-300",children:d("plannerForm.pasteHint")})]}),n.jsx("input",{ref:G,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:Q=>{Q.target.files&&Le(Q.target.files),Q.target.value=""}}),Z.length>0&&n.jsx("div",{className:"flex flex-wrap gap-2",children:Z.map(Q=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:wu(e.id,Q.id),alt:Q.originalName,onClick:()=>W(wu(e.id,Q.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),n.jsx("button",{type:"button",onClick:()=>Ve(Q.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:Q.originalName})})]},Q.id))})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.tags")}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(Q=>n.jsxs("div",{className:"relative",children:[n.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-2xs font-medium cursor-pointer hover:ring-1 hover:ring-warm-400 transition-all ${Fa(s.get(Q)||"default")}`,onClick:V=>{ee.current=V.currentTarget,U(B===Q?null:Q)},children:[Q,n.jsx("button",{onClick:V=>{V.stopPropagation(),pe(Q)},className:"opacity-60 hover:opacity-100",children:n.jsx(Jt,{size:9})})]}),B===Q&&n.jsxs(Pm,{anchorRef:ee,width:180,onClose:()=>U(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[n.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:d("plannerTag.color")}),n.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:gz.map(V=>n.jsx("button",{onClick:async()=>{c&&await c(Q,{color:V}),U(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(Q)===V?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:d(`plannerTag.color.${V}`),children:n.jsx("div",{className:`w-5 h-5 rounded ${Ru[V].swatch}`})},V))})]})]},Q)),n.jsxs("div",{className:"relative",children:[n.jsx("input",{ref:oe,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:$,onChange:Q=>{q(Q.target.value),I(!0)},onKeyDown:Q=>{(Q.key==="Enter"||Q.key===",")&&$.trim()&&(Q.preventDefault(),ke($.replace(",",""))),Q.key==="Backspace"&&!$&&F.length>0&&pe(F[F.length-1])},onFocus:()=>I(!0),onBlur:()=>setTimeout(()=>I(!1),150)}),Y&&Ne.length>0&&n.jsx(Pm,{anchorRef:oe,width:160,onClose:()=>I(!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:Ne.slice(0,8).map(Q=>n.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>ke(Q),children:n.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium ${Fa(s.get(Q)||"default")}`,children:Q})},Q))})]})]})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.priority")}),n.jsxs("select",{className:"input-field text-xs w-full py-1",value:N,onChange:Q=>be(Number(Q.target.value)),children:[n.jsx("option",{value:0,children:d("plannerForm.priorityLow")}),n.jsx("option",{value:1,children:d("plannerForm.priorityNormal")}),n.jsx("option",{value:2,children:d("plannerForm.priorityHigh")}),n.jsx("option",{value:3,children:d("plannerForm.priorityCritical")})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.dueDate")}),n.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:A,onChange:Q=>Ue(Q.target.value)})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.status")}),n.jsxs("select",{className:"input-field text-xs w-full py-1",value:z,onChange:Q=>Pe(Q.target.value),children:[n.jsx("option",{value:"pending",children:d("plannerStatus.pending")}),n.jsx("option",{value:"in_progress",children:d("plannerStatus.in_progress")}),n.jsx("option",{value:"done",children:d("plannerStatus.done")})]})]})]})]})}),J&&n.jsx(Bp,{src:J,onClose:()=>W(null)})]})}let vz=0;function bz({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:h,onUpdateTag:f}){const{t:m}=dt(),[o,c]=k.useState(""),[d,p]=k.useState(""),[u,x]=k.useState([]),[b,C]=k.useState(""),[S,g]=k.useState(i??""),[_,w]=k.useState(0),[y,E]=k.useState("pending"),[T,j]=k.useState(!1),[R,N]=k.useState(!1),[D,A]=k.useState([]),[O,z]=k.useState([]),[P,F]=k.useState(null),H=k.useRef(null),$=k.useRef(null),q=k.useRef(null),[Y,I]=k.useState(new Map),B=new Map([...e.map(he=>[he.name,he.color]),...Y]),U=["blue","green","orange","purple","pink","red","yellow","brown"];k.useEffect(()=>{var he;if(s){c(s.title),p(s.description??""),x(s.tags?JSON.parse(s.tags):[]),g(s.due_date??""),w(s.priority),E(s.status);try{z(s.images?JSON.parse(s.images):[])}catch{z([])}}(he=H.current)==null||he.focus()},[s]);const J=e.filter(he=>!u.includes(he.name)&&(!b||he.name.toLowerCase().includes(b.toLowerCase()))),W=he=>{var Fe;const Ie=he.trim();Ie&&!u.includes(Ie)&&x(be=>{const Ue=[...be,Ie];if(!B.has(Ie)){const Pe=U[B.size%U.length];I(tt=>new Map([...tt,[Ie,Pe]]))}return Ue}),C(""),N(!0),(Fe=$.current)==null||Fe.focus()},oe=he=>x(u.filter(Ie=>Ie!==he)),ee=k.useCallback(he=>{const Ie=Array.from(he).filter(Fe=>Fe.type.startsWith("image/"));for(const Fe of Ie){const be=new FileReader;be.onload=()=>{const Ue=be.result,Pe=`pending-${++vz}`;A(tt=>[...tt,{id:Pe,name:Fe.name,data:Ue,preview:Ue}])},be.readAsDataURL(Fe)}},[]),Z=k.useCallback(he=>{var be;const Ie=(be=he.clipboardData)==null?void 0:be.items;if(!Ie)return;const Fe=[];for(let Ue=0;Ue<Ie.length;Ue++)if(Ie[Ue].type.startsWith("image/")){const Pe=Ie[Ue].getAsFile();Pe&&Fe.push(Pe)}Fe.length!==0&&(he.preventDefault(),ee(Fe))},[ee]),X=k.useCallback(he=>{var Ie;he.preventDefault(),he.stopPropagation(),(Ie=he.dataTransfer)!=null&&Ie.files&&ee(he.dataTransfer.files)},[ee]),G=he=>A(Ie=>Ie.filter(Fe=>Fe.id!==he)),me=he=>{s&&j1(s.id,he),z(Ie=>Ie.filter(Fe=>Fe.id!==he))},ge=O.length+D.length,xe=async()=>{if(o.trim()){j(!0);try{const he=await a({title:o.trim(),description:d.trim()||void 0,tags:u.length>0?JSON.stringify(u):void 0,due_date:S||void 0,priority:_,...s?{status:y}:{}});if(f&&Y.size>0&&await Promise.all([...Y.entries()].map(([Ie,Fe])=>f(Ie,{color:Fe}))),D.length>0){const Ie=(s==null?void 0:s.id)??(he==null?void 0:he.id);Ie&&await C1(Ie,D.map(Fe=>({name:Fe.name,data:Fe.data})))}}finally{j(!1)}}};return n.jsxs("div",{className:"card p-5 animate-slide-up",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[n.jsx("input",{ref:H,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:he=>c(he.target.value),onKeyDown:he=>{he.key==="Enter"&&he.preventDefault()}}),n.jsx("textarea",{className:"prompt-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:m("plannerForm.descPlaceholder"),value:d,onChange:he=>p(he.target.value),onPaste:Z,onDrop:X,onDragOver:he=>{he.preventDefault(),he.stopPropagation()}}),n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsxs("button",{type:"button",onClick:()=>{var he;return(he=q.current)==null?void 0:he.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[n.jsx(Ha,{size:14}),m("plannerForm.addImage")]}),n.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),n.jsx("input",{ref:q,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:he=>{he.target.files&&ee(he.target.files),he.target.value=""}}),ge>0&&n.jsxs("div",{className:"mb-4",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:m("plannerForm.images")}),n.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",ge,")"]})]}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[O.map(he=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:s?wu(s.id,he.id):"",alt:he.originalName,onClick:()=>s&&F(wu(s.id,he.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),n.jsx("button",{type:"button",onClick:()=>me(he.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:he.originalName})})]},he.id)),D.map(he=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:he.preview,alt:he.name,onClick:()=>F(he.preview),className:"h-20 w-20 object-cover rounded-lg border border-blue-300/30 cursor-zoom-in"}),n.jsx("button",{type:"button",onClick:()=>G(he.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:he.name})})]},he.id))]})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.tags")}),n.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:[u.map(he=>n.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-medium ${Fa(B.get(he)||"default")}`,children:[he,n.jsx("button",{onClick:()=>oe(he),className:"opacity-60 hover:opacity-100",children:n.jsx(Jt,{size:10})})]},he)),n.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[n.jsx("input",{ref:$,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:u.length===0?m("plannerForm.tagsPlaceholder"):"",value:b,onChange:he=>{C(he.target.value),N(!0)},onKeyDown:he=>{(he.key==="Enter"||he.key===",")&&b.trim()&&(he.preventDefault(),W(b.replace(",",""))),he.key==="Backspace"&&!b&&u.length>0&&oe(u[u.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),R&&(J.length>0||b.trim())&&n.jsxs(Pm,{anchorRef:$,width:208,onClose:()=>N(!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:[J.slice(0,10).map(he=>n.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>W(he.name),children:n.jsx("span",{className:`px-2 py-0.5 rounded text-[11px] font-medium ${Fa(he.color)}`,children:he.name})},he.name)),b.trim()&&!e.some(he=>he.name===b.trim())&&n.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>W(b),children:n.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',b.trim(),'"']})})]})]})]})]}),n.jsxs("div",{className:`grid gap-3 mb-4 ${s?"grid-cols-3":"grid-cols-2"}`,children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.dueDate")}),n.jsx("input",{type:"date",className:"input-field text-xs w-full",value:S,onChange:he=>g(he.target.value)})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.priority")}),n.jsxs("select",{className:"input-field text-xs w-full",value:_,onChange:he=>w(Number(he.target.value)),children:[n.jsx("option",{value:0,children:m("plannerForm.priorityLow")}),n.jsx("option",{value:1,children:m("plannerForm.priorityNormal")}),n.jsx("option",{value:2,children:m("plannerForm.priorityHigh")}),n.jsx("option",{value:3,children:m("plannerForm.priorityCritical")})]})]}),s&&n.jsxs("div",{children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.status")}),n.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:he=>E(he.target.value),children:[n.jsx("option",{value:"pending",children:m("plannerStatus.pending")}),n.jsx("option",{value:"in_progress",children:m("plannerStatus.in_progress")}),n.jsx("option",{value:"done",children:m("plannerStatus.done")})]})]})]}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:m("plannerForm.cancel")}),n.jsx("button",{className:"btn-primary text-xs py-2",onClick:xe,disabled:!o.trim()||T,children:m("plannerForm.save")})]}),P&&n.jsx(Bp,{src:P,onClose:()=>F(null)})]})}function fS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:h}){const{t:f}=dt(),[m,o]=k.useState(i||"claude"),[c,d]=k.useState(""),[p,u]=k.useState(!1),[x,b]=k.useState("once"),[C,S]=k.useState("0 0 * * *"),[g,_]=k.useState(""),[w,y]=k.useState(!1),E=async()=>{y(!0);try{s==="todo"?await a({cli_tool:m,max_turns:c?Number(c):void 0}):s==="session"?await a({cli_tool:m,use_worktree:p}):await a({cli_tool:m,schedule_type:x,cron_expression:x==="recurring"?C:void 0,run_at:x==="once"?g:void 0})}finally{y(!1)}};return n.jsx(Un,{open:!0,onClose:h,size:"md",position:"top",animation:"slide-up",children:n.jsxs("div",{className:"card p-6",children:[n.jsx("h3",{className:"text-sm font-semibold mb-4",style:{color:"var(--color-text-primary)"},children:f(s==="todo"?"plannerConvert.toTask":s==="session"?"plannerConvert.toTerminal":"plannerConvert.toSchedule")}),n.jsxs("p",{className:"text-xs text-warm-500 mb-4 truncate",children:['"',e.title,'"']}),n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cliTool")}),n.jsxs("select",{className:"input-field text-xs w-full",value:m,onChange:T=>o(T.target.value),children:[n.jsx("option",{value:"claude",children:"Claude"}),n.jsx("option",{value:"antigravity",children:"Antigravity"}),n.jsx("option",{value:"codex",children:"Codex"})]})]}),s==="todo"&&n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.maxTurns")}),n.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:c,onChange:T=>d(T.target.value)})]}),s==="session"&&n.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:p,onChange:T=>u(T.target.checked)}),n.jsx("span",{className:"text-xs font-medium text-warm-500",children:f("plannerConvert.useWorktree")})]}),s==="schedule"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.scheduleType")}),n.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[n.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${x==="once"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("once"),children:f("plannerConvert.once")}),n.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${x==="recurring"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("recurring"),children:f("plannerConvert.recurring")})]})]}),x==="once"?n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.runAt")}),n.jsx("input",{type:"datetime-local",className:"input-field text-xs w-full",value:g,onChange:T=>_(T.target.value)})]}):n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cronExpression")}),n.jsx("input",{className:"input-field text-xs w-full font-mono",value:C,onChange:T=>S(T.target.value),placeholder:"0 0 * * *"})]})]}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:f("plannerConvert.cancel")}),n.jsx("button",{className:"btn-primary btn-sm",onClick:E,disabled:w||s==="schedule"&&x==="once"&&!g,children:f("plannerConvert.convert")})]})]})})}function hn(e){const s=e.getFullYear(),i=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return`${s}-${i}-${a}`}function Gy(e){return hn(new Date(e))}function Vy(e){return new Date(e.getFullYear(),e.getMonth(),1)}function mS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function Vs(e,s){const i=mS(e);return i.setDate(i.getDate()+s),i}function pS(e){return Vs(e,-e.getDay())}function yz(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function wz(e,s,i,a){if(e==="resize-end")return{startKey:s.startKey,endKey:i<s.startKey?s.startKey:i};if(e==="resize-start")return{startKey:i>s.endKey?s.endKey:i,endKey:s.endKey};const h=yz(a,i),f=m=>hn(Vs(new Date(m+"T00:00"),h));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function _z(e,s){if(e==="day"){const f=mS(s);return{rangeStart:hn(f),rangeEnd:hn(Vs(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=pS(s),m=Array.from({length:7},(o,c)=>Vs(f,c));return{rangeStart:hn(f),rangeEnd:hn(Vs(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=Vy(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:hn(f),rangeEnd:hn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=Vy(s),a=Vs(i,-i.getDay()),h=Array.from({length:42},(f,m)=>Vs(a,m));return{rangeStart:hn(a),rangeEnd:hn(Vs(a,42)),gridDays:h,cols:7,dimOutOfMonth:!0}}function gS(e,s){return k.useMemo(()=>_z(e,s),[e,s])}function xS(e,s,i){const a=new Date(e);return s==="month"||s==="table"?a.setMonth(a.getMonth()+i):s==="week"?a.setDate(a.getDate()+7*i):a.setDate(a.getDate()+i),a}function vS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=pS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${Vs(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function bS(){const{lang:e}=dt();return k.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>Vs(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const Sz=420,kz=140,Cz=220,jz=26,Kf=16,Yy=2;function Ez(e,s){if(!s.length)return{placed:[],laneCount:0};const i=hn(e[0]),a=hn(e[e.length-1]),h=s.filter(o=>o.startKey<=a&&o.endKey>=i).map(o=>{const c=o.startKey<i?i:o.startKey,d=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(p=>hn(p)===c),endCol:e.findIndex(p=>hn(p)===d),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,c)=>o.startCol-c.startCol||c.endCol-c.startCol-(o.endCol-o.startCol)),f=[];return{placed:h.map(o=>{let c=0;for(;c<f.length&&f[c]>=o.startCol;)c++;return f[c]=o.endCol,{...o,lane:c}}),laneCount:f.length}}function yS({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:h,todayKey:f,selectedDate:m,chipsByDay:o,maxChips:c,weekdayLabels:d,addItemLabel:p,bars:u,onBarClick:x,onSelectDate:b,onQuickAdd:C,onChipClick:S,onCellContextMenu:g,onChipContextMenu:_,onBarContextMenu:w,onBarDrag:y,onChipDrag:E,monthCellHeight:T=92}){const{lang:j}=dt(),[R,N]=k.useState(null),[D,A]=k.useState(!1),O=k.useRef(null),z=k.useRef(null),P=()=>{z.current&&(clearTimeout(z.current),z.current=null)},F=(Z,X)=>{P(),O.current&&clearTimeout(O.current);const G=X.getBoundingClientRect();O.current=window.setTimeout(()=>N({key:Z,rect:G}),Sz)},H=()=>{O.current&&(clearTimeout(O.current),O.current=null),z.current=window.setTimeout(()=>N(null),kz)};k.useEffect(()=>{if(!R){A(!1);return}const Z=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(Z)},[R]),k.useEffect(()=>()=>{O.current&&clearTimeout(O.current),z.current&&clearTimeout(z.current)},[]),k.useEffect(()=>{if(!R)return;const Z=()=>N(null);return window.addEventListener("scroll",Z,!0),window.addEventListener("resize",Z),()=>{window.removeEventListener("scroll",Z,!0),window.removeEventListener("resize",Z)}},[R]);const $=R?o.get(R.key)??[]:[],[q,Y]=k.useState(null),I=k.useRef(!1),B=4,U=(Z,X)=>{var G,me;return((me=(G=document.elementFromPoint(Z,X))==null?void 0:G.closest("[data-daykey]"))==null?void 0:me.getAttribute("data-daykey"))??null},J=(Z,X,G)=>{Z.preventDefault(),Z.stopPropagation();const me=U(Z.clientX,Z.clientY)??G.origStart,ge=Z.clientX,xe=Z.clientY,he=X!=="move";let Ie=he,Fe={startKey:G.origStart,endKey:G.origEnd};const be=()=>Y({kind:G.kind,entryKey:G.entryKey,curStart:Fe.startKey,curEnd:Fe.endKey,title:G.title,bg:G.bg,fg:G.fg,done:G.done}),Ue=()=>{document.body.style.cursor=he?"ew-resize":"grabbing",document.body.style.userSelect="none"};he&&(Ue(),be());const Pe=ke=>{if(!Ie){if(Math.abs(ke.clientX-ge)<B&&Math.abs(ke.clientY-xe)<B)return;Ie=!0,Ue()}const pe=U(ke.clientX,ke.clientY);pe&&(Fe=wz(X,{startKey:G.origStart,endKey:G.origEnd},pe,me),be())},tt=()=>{window.removeEventListener("pointermove",Pe),window.removeEventListener("pointerup",tt),document.body.style.cursor="",document.body.style.userSelect="",Y(null),Ie&&(I.current=!0,setTimeout(()=>{I.current=!1},0),!(Fe.startKey===G.origStart&&Fe.endKey===G.origEnd)&&(G.kind==="bar"&&G.bar?y==null||y(G.bar,Fe.startKey,Fe.endKey):G.kind==="chip"&&G.chip&&(E==null||E(G.chip,Fe.startKey,Fe.endKey))))};window.addEventListener("pointermove",Pe),window.addEventListener("pointerup",tt)},W=(()=>{const Z=u??[];return q?q.kind==="bar"?Z.map(X=>X.key===q.entryKey?{...X,startKey:q.curStart,endKey:q.curEnd}:X):[...Z,{key:`__drag__${q.entryKey}`,title:q.title,startKey:q.curStart,endKey:q.curEnd,bg:q.bg,fg:q.fg,done:q.done}]:Z})(),oe=(Z,X)=>{const G=hn(Z),me=o.get(G)??[],ge=!a||Z.getMonth()===h,xe=G===f,he=G===m,Ie=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",Fe=e==="month"&&me.length>c;return n.jsxs("div",{"data-daykey":G,onClick:()=>{I.current||b(G)},onContextMenu:g?be=>g(G,be):void 0,onMouseEnter:Fe?be=>F(G,be.currentTarget):void 0,onMouseLeave:Fe?H:void 0,className:`group relative ${Ie} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?T+X:void 0,backgroundColor:he?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:ge?1:.45},children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[e!=="month"&&n.jsx("span",{className:"text-2xs uppercase",style:{color:"var(--color-text-muted)"},children:Z.toLocaleDateString(j,{weekday:"short"})}),n.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:xe?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:Z.getDate()})]}),n.jsx("button",{onClick:be=>{be.stopPropagation(),C(G)},className:"absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity rounded-md w-5 h-5 flex items-center justify-center hover:bg-theme-hover",title:p,style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:n.jsx(mn,{size:13})}),n.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:X||void 0},children:[me.slice(0,c).map(be=>{if((q==null?void 0:q.kind)==="chip"&&q.entryKey===be.key)return null;const Ue=e==="month"&&!!(be.draggable&&E),Pe={kind:"chip",entryKey:be.key,origStart:G,origEnd:G,title:be.title,bg:be.bg,fg:be.fg,done:be.done,chip:be};return n.jsxs("span",{onClick:tt=>{tt.stopPropagation(),!I.current&&S(be)},onPointerDown:Ue?tt=>J(tt,"move",Pe):void 0,onContextMenu:_?tt=>_(be,tt):void 0,className:`text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity ${Ue?"relative group/chip":""}`,style:{backgroundColor:be.bg,color:be.fg,textDecoration:be.done?"line-through":"none"},title:be.title,children:[be.prefix??"",be.time?`${be.time} `:"",be.title,Ue&&n.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),J(tt,"resize-end",Pe)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 group-hover/chip:opacity-100 cursor-ew-resize rounded-r",style:{backgroundColor:"rgba(127,127,127,0.5)"}})]},be.key)}),me.length>c&&n.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",me.length-c]})]})]},G)},ee=[];if(e==="month")for(let Z=0;Z<s.length;Z+=i)ee.push(s.slice(Z,Z+i));return n.jsxs(n.Fragment,{children:[(e==="month"||e==="week")&&n.jsx("div",{className:"grid gap-px text-2xs uppercase tracking-wider mb-1",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,color:"var(--color-text-muted)"},children:d.map(Z=>n.jsx("div",{className:"px-2 py-1",children:Z},Z))}),e==="month"?n.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:ee.map((Z,X)=>{const{placed:G,laneCount:me}=Ez(Z,W),ge=me*(Kf+Yy);return n.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[Z.map(xe=>oe(xe,ge)),G.map(({bar:xe,startCol:he,endCol:Ie,lane:Fe,contStart:be,contEnd:Ue})=>{const Pe=!!y&&!xe.key.startsWith("__drag__"),tt={kind:"bar",entryKey:xe.key,origStart:xe.startKey,origEnd:xe.endKey,title:xe.title,bg:xe.bg,fg:xe.fg,done:xe.done,bar:xe};return n.jsxs("div",{onClick:ke=>{ke.stopPropagation(),!I.current&&(x==null||x(xe))},onPointerDown:Pe?ke=>J(ke,"move",tt):void 0,onContextMenu:w?ke=>w(xe,ke):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{pointerEvents:q?"none":void 0,left:`calc(${he} / ${i} * 100% + 2px)`,width:`calc(${Ie-he+1} / ${i} * 100% - 4px)`,top:jz+Fe*(Kf+Yy),height:Kf,backgroundColor:xe.bg,color:xe.fg,textDecoration:xe.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:be?0:4,borderBottomLeftRadius:be?0:4,borderTopRightRadius:Ue?0:4,borderBottomRightRadius:Ue?0:4},title:xe.title,children:[be?"◀ ":"",xe.title,Ue?" ▶":"",Pe&&!be&&n.jsx("span",{onPointerDown:ke=>{ke.stopPropagation(),J(ke,"resize-start",tt)},onClick:ke=>ke.stopPropagation(),className:"absolute top-0 left-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}}),Pe&&!Ue&&n.jsx("span",{onPointerDown:ke=>{ke.stopPropagation(),J(ke,"resize-end",tt)},onClick:ke=>ke.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}})]},xe.key)})]},X)})}):n.jsx("div",{className:"grid gap-px rounded-xl overflow-hidden",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:s.map(Z=>oe(Z,0))}),R&&(()=>{const Z=Math.max(R.rect.width,Cz),X=Math.min(Math.max(8,R.rect.left),window.innerWidth-Z-8),G=Math.max(8,Math.min(R.rect.top,window.innerHeight-120)),me=window.innerHeight-G-16,ge=Number(R.key.slice(8,10));return en.createPortal(n.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:P,onMouseLeave:()=>N(null),style:{position:"fixed",left:X,top:G,width:Z,maxHeight:me,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:D?"scale(1)":"scale(0.96)",opacity:D?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[n.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:ge}),n.jsx("div",{className:"flex flex-col gap-0.5",children:$.map(xe=>n.jsxs("span",{onClick:he=>{he.stopPropagation(),S(xe),N(null)},onContextMenu:_?he=>_(xe,he):void 0,className:"text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:xe.bg,color:xe.fg,textDecoration:xe.done?"line-through":"none"},title:xe.title,children:[xe.prefix??"",xe.time?`${xe.time} `:"",xe.title]},xe.key))})]}),document.body)})()]})}const Xy={pending:"bg-warm-200 text-warm-500",in_progress:"bg-blue-500/10 text-blue-600",done:"bg-emerald-500/10 text-emerald-600",moved:"bg-purple-500/10 text-purple-600"};function Nz(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function Lz({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:h,onConvert:f,onDeleteItem:m,onUpdateRange:o}){const{t:c,lang:d}=dt(),[p,u]=k.useState(()=>new Date),[x,b]=k.useState(()=>hn(new Date)),[C,S]=k.useState(null),g=bS(),{gridDays:_,cols:w,dimOutOfMonth:y}=gS(e,p),E=hn(new Date),T=p.getMonth(),j=e==="month"?3:99,R=ee=>u(Z=>xS(Z,e,ee)),N=()=>{u(new Date),b(hn(new Date))},D=vS(p,e,d);k.useEffect(()=>{e==="day"&&b(hn(p))},[e,p]);const A=260,O=760,z=k.useRef(null),[P,F]=k.useState(()=>{const ee=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ee)&&ee>=A&&ee<=O?ee:320});k.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(P))}catch{}},[P]);const H=ee=>{ee.preventDefault();const Z=G=>{var ge;const me=(ge=z.current)==null?void 0:ge.getBoundingClientRect();me&&F(Math.min(O,Math.max(A,me.right-G.clientX)))},X=()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",X),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",Z),window.addEventListener("pointerup",X)},[$,q]=k.useState(new Map);k.useEffect(()=>{q(new Map)},[s]);const Y=k.useMemo(()=>$.size===0?s:s.map(ee=>{const Z=$.get(ee.id);return Z?{...ee,due_date:Z.due_date,end_date:Z.end_date}:ee}),[s,$]),I=k.useCallback((ee,Z,X)=>{q(G=>new Map(G).set(ee,{due_date:Z,end_date:X})),o(ee,Z,X)},[o]),B=ee=>!!(ee.due_date&&ee.end_date&&ee.end_date.slice(0,10)>ee.due_date.slice(0,10)),U=k.useMemo(()=>{const ee=new Map;for(const Z of Y){if(!Z.due_date||e==="month"&&B(Z))continue;const X=Z.due_date.slice(0,10),G=Z.status==="done",me=ee.get(X)??[];me.push({key:Z.id,title:Z.title,bg:"var(--color-bg-secondary)",fg:G?"var(--color-text-muted)":"var(--color-text-secondary)",done:G,payload:Z,draggable:!0}),ee.set(X,me)}return ee},[Y,e]),J=k.useMemo(()=>e!=="month"?[]:Y.filter(B).map(ee=>{const Z=ee.status==="done";return{key:ee.id,title:ee.title,startKey:ee.due_date.slice(0,10),endKey:ee.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:Z?"var(--color-text-muted)":"var(--color-text-secondary)",done:Z,payload:ee}}),[Y,e]),W=k.useMemo(()=>s.filter(ee=>ee.due_date&&ee.due_date.slice(0,10)===x),[s,x]),oe=k.useMemo(()=>s.filter(ee=>!ee.due_date),[s]);return n.jsxs("div",{ref:z,className:"card flex overflow-hidden",style:{minHeight:520},children:[n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[n.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[n.jsx("button",{onClick:()=>R(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:n.jsx(Vm,{size:16})}),n.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:D}),n.jsx("button",{onClick:()=>R(1),className:"btn-ghost p-1.5","aria-label":"next",children:n.jsx(Ns,{size:16})}),n.jsx("button",{onClick:N,className:"btn-ghost text-xs px-2.5 py-1.5",children:c("agenda.today")})]}),n.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:n.jsx(yS,{view:e,gridDays:_,cols:w,dimOutOfMonth:y,monthIdx:T,todayKey:E,selectedDate:x,chipsByDay:U,maxChips:j,weekdayLabels:g,addItemLabel:c("agenda.addItem"),onSelectDate:b,onQuickAdd:a,onChipClick:ee=>h(ee.payload),onCellContextMenu:(ee,Z)=>{Z.preventDefault(),S({x:Z.clientX,y:Z.clientY,dateKey:ee})},bars:J,onBarClick:ee=>h(ee.payload),onBarDrag:(ee,Z,X)=>I(ee.payload.id,Z,X),onChipDrag:(ee,Z,X)=>I(ee.payload.id,Z,X)})})]}),n.jsx("div",{onPointerDown:H,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:c("agenda.resizePanel")}),n.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:P},children:[n.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--color-text-primary)"},children:new Date(x+"T00:00").toLocaleDateString(d,{month:"long",day:"numeric",weekday:"short"})}),n.jsxs("button",{onClick:()=>a(x),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[n.jsx(mn,{size:13}),c("agenda.add")]})]}),n.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[n.jsxs("div",{className:"flex flex-col gap-1.5",children:[W.length===0&&n.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:c("agenda.dayEmpty")}),W.map(ee=>n.jsx(Jy,{item:ee,tagColors:i,onEdit:h,onConvert:f,onDelete:m},ee.id))]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:c("agenda.backlog")}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[oe.length===0&&n.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:c("agenda.backlogEmpty")}),oe.map(ee=>n.jsx(Jy,{item:ee,tagColors:i,onEdit:h,onConvert:f,onDelete:m},ee.id))]})]})]})]}),C&&n.jsx(Cr,{x:C.x,y:C.y,onClose:()=>S(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>a(C.dateKey),children:[n.jsx(mn,{size:14}),c("planner.add")]})})]})}function Jy({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:h}){const{t:f}=dt(),[m,o]=k.useState(!1),[c,d]=k.useState(!1),[p,u]=k.useState({top:0,left:0}),x=k.useRef(null),b=k.useRef(null),C=Nz(e.tags),S=e.status==="moved",g=k.useCallback(()=>{if(!x.current)return;const _=x.current.getBoundingClientRect(),w=window.innerWidth,y=window.innerHeight;let E=_.bottom+4;const T=b.current;if(T){const j=T.offsetWidth,R=T.offsetHeight;let N=_.right-j;N<8&&(N=8),N+j>w-8&&(N=w-8-j),E+R>y-8&&(E=_.top-R-4),u({top:E,left:N}),d(!0)}else u({top:E,left:Math.max(8,_.right-180)})},[]);return k.useEffect(()=>{if(!m){d(!1);return}g();const _=requestAnimationFrame(g),w=y=>{var T,j;const E=y.target;(T=x.current)!=null&&T.contains(E)||(j=b.current)!=null&&j.contains(E)||o(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{cancelAnimationFrame(_),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[m,g]),n.jsxs("div",{className:`group flex items-start gap-2 rounded-lg px-2.5 py-2 ${S?"opacity-50":""}`,style:{backgroundColor:"var(--color-bg-secondary)"},children:[n.jsxs("button",{onClick:()=>i(e),className:"flex-1 text-left min-w-0",children:[n.jsx("div",{className:"text-sm truncate",style:{color:"var(--color-text-primary)",textDecoration:e.status==="done"?"line-through":"none"},children:e.title}),e.description&&n.jsx("div",{className:"text-2xs truncate",style:{color:"var(--color-text-muted)"},children:e.description}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[n.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-2xs font-medium ${Xy[e.status]||Xy.pending}`,children:f(`plannerStatus.${e.status}`)}),C.map(_=>n.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-medium ${Fa(s.get(_)||"default")}`,children:_},_))]})]}),n.jsxs("div",{className:"flex-shrink-0",children:[n.jsx("button",{ref:x,onClick:_=>{_.stopPropagation(),o(!m)},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:n.jsx(Xm,{size:14})}),m&&en.createPortal(n.jsxs("div",{ref:b,className:`fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated${c?" animate-scale-in":""}`,style:{top:p.top,left:p.left,opacity:c?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>o(!1),children:[!S&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>a(e,"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:[n.jsx(Pw,{size:12})," ",f("planner.convertToTask")]}),n.jsxs("button",{onClick:()=>a(e,"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:[n.jsx(ai,{size:12})," ",f("planner.convertToSchedule")]}),n.jsxs("button",{onClick:()=>a(e,"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:[n.jsx(di,{size:12})," ",f("planner.convertToTerminal")]})]}),n.jsxs("button",{onClick:()=>{confirm(f("planner.deleteConfirm"))&&h(e.id)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-red-500 hover:bg-red-50 rounded-md transition-colors text-left",children:[n.jsx(Ln,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const Qy={pending:0,in_progress:1,done:2,moved:3};function Dz({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:h,onDeleteItem:f,onConvertToTodo:m,onConvertToSchedule:o,onConvertToSession:c,onUpdateTag:d,onDeleteTag:p,onExport:u,onImport:x,view:b,onChangeView:C}){const{t:S}=dt(),[g,_]=k.useState(!1),[w,y]=k.useState(null),[E,T]=k.useState(void 0),[j,R]=k.useState(""),[N,D]=k.useState(""),[A,O]=k.useState("created_at"),[z,P]=k.useState("desc"),[F,H]=k.useState(null),[$,q]=k.useState("todo"),[Y,I]=k.useState(!1),[B,U]=k.useState(!1),[J,W]=k.useState(null),oe=k.useRef(null),ee=k.useRef(0),Z=async()=>{if(!(!u||Y)){I(!0);try{await u()}finally{I(!1)}}},X=()=>{var pe;!x||Y||(pe=oe.current)==null||pe.click()},G=async pe=>{var Le;const Ne=(Le=pe.target.files)==null?void 0:Le[0];if(pe.target.value="",!(!Ne||!x)){I(!0);try{await x(Ne)}finally{I(!1)}}},me=pe=>!!(/\.(md|markdown)$/i.test(pe.name)||pe.type==="text/markdown"),ge=pe=>Array.from(pe.dataTransfer.types).includes("Files"),xe=pe=>{!x||Y||ge(pe)&&(pe.preventDefault(),ee.current++,U(!0))},he=pe=>{!x||Y||ge(pe)&&(pe.preventDefault(),pe.dataTransfer.dropEffect="copy")},Ie=pe=>{x&&(pe.preventDefault(),ee.current=Math.max(0,ee.current-1),ee.current===0&&U(!1))},Fe=async pe=>{var Le;if(!x||(pe.preventDefault(),ee.current=0,U(!1),Y))return;const Ne=(Le=pe.dataTransfer.files)==null?void 0:Le[0];if(Ne){if(!me(Ne)){window.alert(S("planner.dropInvalidFile"));return}I(!0);try{await x(Ne)}finally{I(!1)}}},be=k.useMemo(()=>s.map(pe=>pe.name),[s]),Ue=k.useMemo(()=>new Map(s.map(pe=>[pe.name,pe.color])),[s]),Pe=k.useMemo(()=>{let pe=e.filter(Ne=>!(N&&Ne.status!==N||j&&!(Ne.tags?(()=>{try{return JSON.parse(Ne.tags)}catch{return[]}})():[]).includes(j)));return pe=[...pe].sort((Ne,Le)=>{let ze=0;switch(A){case"title":ze=Ne.title.localeCompare(Le.title);break;case"tags":{const Ke=Ne.tags?(()=>{try{return JSON.parse(Ne.tags).join(",")}catch{return""}})():"",Ve=Le.tags?(()=>{try{return JSON.parse(Le.tags).join(",")}catch{return""}})():"";ze=(Ke||"zzz").localeCompare(Ve||"zzz");break}case"priority":ze=Ne.priority-Le.priority;break;case"due_date":{const Ke=Ne.due_date||"9999",Ve=Le.due_date||"9999";ze=Ke.localeCompare(Ve);break}case"status":ze=(Qy[Ne.status]??9)-(Qy[Le.status]??9);break;case"created_at":ze=Ne.created_at.localeCompare(Le.created_at);break}return z==="asc"?ze:-ze}),pe},[e,j,N,A,z]),tt=pe=>{A===pe?P(Ne=>Ne==="asc"?"desc":"asc"):(O(pe),P(pe==="priority"?"desc":"asc"))},ke=({field:pe})=>A!==pe?null:z==="asc"?n.jsx(F5,{size:10,className:"inline ml-0.5"}):n.jsx(O5,{size:10,className:"inline ml-0.5"});return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-5 gap-3 flex-wrap",children:[n.jsxs("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:[S("planner.title"),n.jsx("span",{className:"ml-1 text-warm-400",children:e.length})]}),n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b!=="table"&&n.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(pe=>n.jsx("button",{onClick:()=>C(pe),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:b===pe?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:S(`agenda.view.${pe}`)},pe))}),n.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:j,onChange:pe=>R(pe.target.value),children:[n.jsx("option",{value:"",children:S("planner.filterTag")}),be.map(pe=>n.jsx("option",{value:pe,children:pe},pe))]}),n.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:N,onChange:pe=>D(pe.target.value),children:[n.jsx("option",{value:"",children:S("planner.filterStatus")}),n.jsx("option",{value:"pending",children:S("plannerStatus.pending")}),n.jsx("option",{value:"in_progress",children:S("plannerStatus.in_progress")}),n.jsx("option",{value:"done",children:S("plannerStatus.done")}),n.jsx("option",{value:"moved",children:S("plannerStatus.moved")})]}),u&&n.jsxs("button",{onClick:Z,disabled:Y||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.exportTooltip"),children:[n.jsx(sm,{size:14,className:"inline-block shrink-0"}),S("planner.export")]}),x&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:X,disabled:Y,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.importTooltip"),children:[n.jsx(Gv,{size:14,className:"inline-block shrink-0"}),S("planner.import")]}),n.jsx("input",{ref:oe,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:G})]}),!g&&!w&&n.jsxs("button",{onClick:()=>_(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[n.jsx(mn,{size:14,className:"inline-block shrink-0"}),S("planner.add")]})]})]}),(g||w)&&n.jsx("div",{className:"mb-5",children:n.jsx(bz,{existingTags:s,editItem:w,initialDueDate:E,onSave:async pe=>{if(w){await h(w.id,pe),y(null);return}else{const Ne=await a(pe);return _(!1),T(void 0),Ne}},onCancel:()=>{_(!1),y(null),T(void 0)},onUpdateTag:d})}),b==="table"?n.jsxs("div",{className:"card relative",onDragEnter:x?xe:void 0,onDragOver:x?he:void 0,onDragLeave:x?Ie:void 0,onDrop:x?Fe:void 0,onContextMenu:pe=>{hi(pe)||(pe.preventDefault(),W({x:pe.clientX,y:pe.clientY}))},children:[B&&n.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:n.jsxs("div",{className:"text-center",children:[n.jsx(Gv,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),n.jsx("div",{className:"text-sm font-semibold",children:S("planner.dropHint")}),n.jsx("div",{className:"text-xs text-warm-500 mt-1",children:S("planner.dropHintSub")})]})}),n.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:[n.jsx("div",{className:"w-[14px] flex-shrink-0"}),n.jsxs("div",{className:"flex-1 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("title"),children:[S("planner.col.title"),n.jsx(ke,{field:"title"})]}),n.jsxs("div",{className:"w-[160px] text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("tags"),children:[S("planner.col.tags"),n.jsx(ke,{field:"tags"})]}),n.jsxs("div",{className:"w-12 text-center text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("priority"),children:[S("plannerForm.priority"),n.jsx(ke,{field:"priority"})]}),n.jsxs("div",{className:"hidden md:block w-20 text-right text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("due_date"),children:[S("planner.col.dueDate"),n.jsx(ke,{field:"due_date"})]}),n.jsxs("div",{className:"w-16 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("status"),children:[S("planner.col.status"),n.jsx(ke,{field:"status"})]}),n.jsx("div",{className:"w-8"})]}),Pe.length===0?n.jsx(Vi,{icon:fE,title:S("planner.empty"),description:S("planner.emptyHint")}):Pe.map((pe,Ne)=>n.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${Ne*20}ms`},children:n.jsx(xz,{item:pe,tagColors:Ue,existingTags:be,onSave:async(Le,ze)=>{await h(Le,ze)},onDelete:()=>f(pe.id),onConvertToTodo:()=>{H(pe),q("todo")},onConvertToSchedule:()=>{H(pe),q("schedule")},onConvertToSession:()=>{H(pe),q("session")},onUpdateTag:d})},pe.id))]}):n.jsx(Lz,{view:b,items:Pe,tagColors:Ue,onQuickAdd:pe=>{y(null),T(pe),_(!0)},onEditItem:pe=>{_(!1),y(pe)},onConvert:(pe,Ne)=>{H(pe),q(Ne)},onDeleteItem:f,onUpdateRange:(pe,Ne,Le)=>{h(pe,{due_date:Ne,end_date:Le})}}),F&&n.jsx(fS,{item:F,mode:$,projectCliTool:i,onConvert:async pe=>{$==="todo"?await m(F.id,pe):$==="session"?await c(F.id,pe):await o(F.id,pe),H(null)},onClose:()=>H(null)}),J&&n.jsx(Cr,{x:J.x,y:J.y,onClose:()=>W(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>{y(null),T(void 0),_(!0)},children:[n.jsx(mn,{size:14}),S("planner.add")]})})]})}const wS=k.createContext(null),Tz=wS.Provider;function e7(){const e=k.useContext(wS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const Rz=k.lazy(()=>Fu(()=>import("./PlannerPageEditor-eUAngWQt.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),Mz=800;function Az({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:c}=dt(),[d,p]=k.useState(null),[u,x]=k.useState("idle"),[b,C]=k.useState(null),S=k.useRef({title:"",content:null}),g=k.useRef(null);k.useEffect(()=>{let j=!1;return P4(e).then(R=>{j||(p(R),S.current={title:R.title,content:R.content??null})}),()=>{j=!0}},[e]);const _=k.useCallback(()=>{g.current&&(clearTimeout(g.current),g.current=null);const{title:j,content:R}=S.current;return x("saving"),I4(e,{title:j,content:R??void 0}).then(()=>x("saved"))},[e]);k.useEffect(()=>()=>{g.current&&_()},[_]);const w=k.useCallback(()=>{g.current&&clearTimeout(g.current),x("saving"),g.current=setTimeout(()=>{_()},Mz)},[_]),y=j=>{S.current.title=j,p(R=>R&&{...R,title:j}),h(e,j),w()},E=j=>{S.current.content=j,w()},T=k.useCallback((j,R,N)=>{C({item:j,mode:R,onDone:N})},[]);return d?n.jsxs(Tz,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:T},children:[n.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[n.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[n.jsx("input",{value:d.title,onChange:j=>y(j.target.value),placeholder:c("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),n.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:u==="saving"?c("planner.pages.saving"):u==="saved"?c("planner.pages.saved"):""})]}),n.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:n.jsx(k.Suspense,{fallback:null,children:n.jsx(Rz,{pageId:e,initialContent:d.content??null,onChange:E})})})]}),b&&n.jsx(fS,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:R,mode:N,onDone:D}=b;N==="todo"?await f(R.id,j):N==="session"?await o(R.id,j):await m(R.id,j),D==null||D(),C(null)},onClose:()=>C(null)})]}):null}const En=(e,s)=>({type:"heading",props:{level:e},content:s}),Vo=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},Zy=e=>({type:"bulletListItem"}),Fi=e=>({type:"checkListItem"}),ew=()=>({type:"tasklist"}),tw=()=>({type:"calendar"}),Oz=[{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:[En(1,"회의 노트"),Vo("📅 날짜: "),Vo("👥 참석자: "),En(2,"안건"),Zy(),En(2,"논의"),Vo(),En(2,"액션 아이템"),ew()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[En(1,"프로젝트 플랜"),En(2,"개요"),Vo(),En(2,"마일스톤"),ew(),En(2,"일정"),tw(),En(2,"리스크 / 메모"),Vo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[En(1,"위클리 플래너"),En(2,"이번 주 목표"),Zy(),En(2,"요일별 할 일"),En(3,"월요일"),Fi(),En(3,"화요일"),Fi(),En(3,"수요일"),Fi(),En(3,"목요일"),Fi(),En(3,"금요일"),Fi(),En(3,"토요일"),Fi(),En(3,"일요일"),Fi(),En(2,"주간 일정"),tw()]}];function zz({onResize:e}){return n.jsx("div",{role:"separator","aria-orientation":"vertical",onPointerDown:s=>{s.preventDefault();const i=s.currentTarget;i.setPointerCapture(s.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none";let a=null,h=null;const f=()=>{if(a=null,h===null)return;const c=h;h=null,e(c)},m=c=>{h=c.clientX,a===null&&(a=requestAnimationFrame(f))},o=c=>{a!==null&&cancelAnimationFrame(a),a=null,c.type==="pointerup"&&h!==null&&f(),h=null,document.body.style.cursor="",document.body.style.userSelect="",i.removeEventListener("pointermove",m),i.removeEventListener("pointerup",o),i.removeEventListener("pointercancel",o)};i.addEventListener("pointermove",m),i.addEventListener("pointerup",o),i.addEventListener("pointercancel",o)},className:"w-1.5 shrink-0 cursor-col-resize bg-warm-300 hover:bg-accent active:bg-accent transition-colors"})}const nw=160,sw=480,rw="plannerSidebarWidth";function Bz({projectId:e,...s}){const{t:i}=dt(),[a,h]=k.useState([]),[f,m]=k.useState({kind:"work"}),[o,c]=k.useState("table"),[d,p]=k.useState(!1),[u,x]=k.useState({top:0,left:0}),b=k.useRef(null),C=k.useRef(null),S=k.useRef(!1),[g,_]=k.useState(()=>{const F=Number(localStorage.getItem(rw));return F>=nw&&F<=sw?F:208}),w=k.useCallback(F=>{var q;const H=((q=C.current)==null?void 0:q.getBoundingClientRect().left)??0,$=Math.round(Math.max(nw,Math.min(sw,F-H)));_($),localStorage.setItem(rw,String($))},[]),y=240,E=()=>{var H;const F=(H=b.current)==null?void 0:H.getBoundingClientRect();if(F){const $=Math.min(F.left,window.innerWidth-y-8);x({top:F.bottom+4,left:Math.max(8,$)})}p(!0)};k.useEffect(()=>{if(!d)return;const F=()=>p(!1),H=$=>{var q;(q=b.current)!=null&&q.contains($.target)||$.target.closest("[data-template-picker]")||p(!1)};return document.addEventListener("mousedown",H),window.addEventListener("scroll",F,!0),window.addEventListener("resize",F),()=>{document.removeEventListener("mousedown",H),window.removeEventListener("scroll",F,!0),window.removeEventListener("resize",F)}},[d]),k.useEffect(()=>{z4(e).then(F=>{h(F),S.current||(S.current=!0,F.length>0&&m({kind:"page",id:F[0].id}))})},[e]);const T=async F=>{p(!1);const H=await B4(e,F.title||i("planner.pages.untitled"),F.blocks?JSON.stringify(F.blocks):void 0);h($=>[...$,H]),m({kind:"page",id:H.id})},j=async F=>{confirm(i("planner.pages.deleteConfirm"))&&(await F4(F),h(H=>H.filter($=>$.id!==F)),m(H=>H.kind==="page"&&H.id===F?{kind:"work"}:H))},R=k.useCallback((F,H)=>{h($=>$.map(q=>q.id===F?{...q,title:H}:q))},[]),N=()=>{m({kind:"work"}),c(F=>F==="table"?"month":F)},D=()=>{m({kind:"work"}),c("table")},A=f.kind==="work",O=A&&o!=="table",z=A&&o==="table",P=(F,H,$,q,Y)=>n.jsxs("div",{onClick:H,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${F?"":"hover:bg-warm-50"}`,style:F?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[$,n.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:q}),Y]});return n.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[n.jsxs("div",{ref:C,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:g},children:[n.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),n.jsx("button",{ref:b,onClick:()=>d?p(!1):E(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:n.jsx(mn,{size:14})})]}),a.map(F=>P(f.kind==="page"&&f.id===F.id,()=>m({kind:"page",id:F.id}),n.jsx(Jo,{size:13,className:"text-warm-400 flex-shrink-0"}),F.title||i("planner.pages.untitled"),n.jsx("button",{onClick:H=>{H.stopPropagation(),j(F.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-red-500 transition-all flex-shrink-0",children:n.jsx(Ln,{size:13})}))),n.jsx("div",{className:"px-2.5 pt-3 pb-1 text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.all")}),P(O,N,n.jsx(nm,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),P(z,D,n.jsx(xu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),n.jsx(zz,{onResize:w}),n.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:f.kind==="page"?n.jsx("div",{className:"card flex flex-col flex-1",children:n.jsx(Az,{pageId:f.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:R,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},f.id)}):n.jsx(Dz,{...s,view:o,onChangeView:c})}),d&&en.createPortal(n.jsx("div",{"data-template-picker":!0,className:"fixed z-tooltip rounded-xl py-1 shadow-elevated animate-scale-in",style:{top:u.top,left:u.left,width:y,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:Oz.map(F=>n.jsxs("button",{onClick:()=>T(F),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[n.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:i(F.labelKey)}),n.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(F.descKey)})]},F.id))}),document.body)]})}const Pz=k.lazy(()=>Fu(()=>import("./AnalyticsPanel-CyoPYhlO.js"),__vite__mapDeps([9,7,3,2]))),Iz=k.lazy(()=>Fu(()=>import("./VaultLayout-DhmT6euK.js"),__vite__mapDeps([10,6,1,2,3,4])));function Fz({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:h}=$m(),[f,m]=k.useState(null),[o,c]=k.useState([]),[d,p]=k.useState([]),[u,x]=k.useState(null),[b,C]=k.useState([]),[S,g]=k.useState([]),[_,w]=k.useState([]),[y,E]=k.useState([]),[T,j]=Aw(),R=["tasks","discussions","schedules","analytics"],N=T.get("tab")||"tasks",[D,A]=k.useState(R.includes(N)?"automation":N),[O,z]=k.useState(R.includes(N)?N:"tasks"),P=k.useCallback(ie=>{if(ie==="automation"){A("automation"),j(O==="tasks"?{}:{tab:O},{replace:!0});return}A(ie),j(ie==="tasks"?{}:{tab:ie},{replace:!0})},[j,O]),F=k.useCallback(ie=>{A("automation"),z(ie),j(ie==="tasks"?{}:{tab:ie},{replace:!0})},[j]),[H,$]=k.useState(!0),[q,Y]=k.useState(!1),[I,B]=k.useState(new Set),[U,J]=k.useState(0),{t:W}=dt(),{sendNotification:oe}=np(),ee=k.useRef([]);k.useEffect(()=>{ee.current=b},[b]),k.useEffect(()=>{h&&Promise.all([kN(h),hf(h),hb(h),fb(h),s4(),_1(h),Hc(h),$c(h)]).then(([ie,_e,je,we,rt,Me,vt,bt])=>{m(ie),c(_e),p(je),C(we),g(Me),w(vt),E(bt),rt.resetsAt&&x(rt.resetsAt);const St=_e.filter(Et=>Et.status==="running"&&Et.execution_mode==="interactive").map(Et=>Et.id);St.length>0&&B(new Set(St))}).catch(()=>Y(!0)).finally(()=>$(!1))},[h]);const Z=k.useRef(o);Z.current=o,k.useEffect(()=>{if(!h)return;const ie=setInterval(()=>{Z.current.some(je=>je.status==="running")&&hf(h).then(je=>{c(we=>we.map(rt=>{const Me=je.find(vt=>vt.id===rt.id);return Me&&Me.status!==rt.status?Me:rt}))}).catch(()=>{})},5e3);return()=>clearInterval(ie)},[h]);const X=k.useRef(s);k.useEffect(()=>{s&&!X.current&&h&&Promise.all([hf(h),hb(h),fb(h)]).then(([ie,_e,je])=>{c(ie),p(_e),C(je)}).catch(()=>{}),X.current=s},[s,h]),k.useEffect(()=>e(ie=>{if(ie.type==="todo:status-changed"&&ie.todoId&&ie.status){if(c(_e=>_e.map(je=>{if(je.id!==ie.todoId)return je;const we={status:ie.status,updated_at:new Date().toISOString()};return ie.worktree_path!==void 0&&(we.worktree_path=ie.worktree_path??null),ie.branch_name!==void 0&&(we.branch_name=ie.branch_name??null),{...je,...we}})),(ie.status==="completed"||ie.status==="merged"||ie.status==="failed")&&J(_e=>_e+1),ie.status==="completed"||ie.status==="failed"){const _e=Z.current.find(je=>je.id===ie.todoId);_e&&oe(ie.status==="completed"?W("notification.taskCompleted"):W("notification.taskFailed"),_e.title)}ie.status==="running"&&ie.mode==="interactive"?B(_e=>new Set(_e).add(ie.todoId)):ie.status!=="running"&&B(_e=>{const je=new Set(_e);return je.delete(ie.todoId),je})}if(ie.type==="schedule:status-changed"&&ie.scheduleId&&p(_e=>_e.map(je=>je.id===ie.scheduleId?{...je,is_active:ie.isActive?1:0,updated_at:new Date().toISOString()}:je)),ie.type==="rate-limit:updated"&&ie.resetsAt&&x(ie.resetsAt),ie.type==="discussion:status-changed"&&ie.discussionId&&(C(_e=>_e.map(je=>je.id===ie.discussionId?{...je,status:ie.status,current_round:ie.currentRound??je.current_round,updated_at:new Date().toISOString()}:je)),ie.status==="completed"||ie.status==="failed")){const _e=ee.current.find(je=>je.id===ie.discussionId);_e&&oe(ie.status==="completed"?W("notification.discussionCompleted"):W("notification.discussionFailed"),_e.title)}ie.type==="session:status-changed"&&ie.sessionId&&g(_e=>_e.map(je=>{if(je.id!==ie.sessionId)return je;const we={status:ie.status,updated_at:new Date().toISOString()};return ie.worktree_path!==void 0&&(we.worktree_path=ie.worktree_path),ie.branch_name!==void 0&&(we.branch_name=ie.branch_name),{...je,...we}}))}),[e,oe,W]);const G=k.useCallback(async(ie,_e,je,we,rt,Me,vt,bt,St,Et)=>{if(!h)return;const Ht=await ub(h,{title:ie,description:_e,cli_tool:je,depends_on:rt,max_turns:Me??null,use_worktree:vt??null,...bt?{memory_inject_mode:bt}:{},...St?{memory_node_ids:St}:{},...Et?{memory_raw_file_paths:Et}:{}});if(we&&we.length>0){const pn=await v1(Ht.id,we.map(gn=>({name:gn.name,data:gn.data})));Ht.images=JSON.stringify(pn.images)}c(pn=>[...pn,Ht])},[h]),me=k.useCallback((ie,_e=[])=>{const je=ie.split("/").filter(Boolean).pop()??ie,we=[ie,..._e].map(rt=>`@${rt}`).join(`
683
+ ${U}`:""}`,children:[n.jsx("span",{"aria-label":(q==null?void 0:q.status)||"unknown",style:{width:6,height:6,borderRadius:"50%",background:B,flexShrink:0}}),n.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Rt,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:I,width:16,textAlign:"center"},children:">_"}),n.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(q==null?void 0:q.title)||$}),n.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:J=>{J.stopPropagation(),o($)},"aria-label":"close-tab",title:w("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:n.jsx(Jt,{size:11})})]},$)}),N&&n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{N.createRawShellTab(i,s).catch(()=>{})},"aria-label":"new-tab",title:`${w("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${He.separator}`,color:He.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:n.jsx(mn,{size:13})}),n.jsx("div",{style:{flex:1,minWidth:8}}),z&&n.jsx("span",{title:z,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:He.dim,fontFamily:Rt,fontSize:9,padding:"0 7px",flexShrink:1},children:z}),n.jsx(AO,{sessionId:e.activeTab,sendMessage:u}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:R,"aria-label":"refresh-terminal",title:`${w("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${w("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:qs,children:n.jsx(GE,{size:12})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>E(-1),"aria-label":"decrease-font",title:`${w("session.fontDecrease")||"Decrease font size"} (${y}px) · Ctrl+- · Ctrl+wheel`,style:qs,children:n.jsx(bN,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>E(1),"aria-label":"increase-font",title:`${w("session.fontIncrease")||"Increase font size"} (${y}px) · Ctrl+= · Ctrl+wheel`,style:qs,children:n.jsx(xN,{size:13})}),n.jsx(RO,{sessionId:e.activeTab}),_&&n.jsxs(n.Fragment,{children:[e.tabs.length>1&&_.onApplyLayoutPreset&&n.jsxs(n.Fragment,{children:[n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{var $;return($=_.onApplyLayoutPreset)==null?void 0:$.call(_,"single")},"aria-label":"single-pane",title:w("session.layout.single"),style:qs,children:n.jsx(Ki,{size:12})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{var $;return($=_.onApplyLayoutPreset)==null?void 0:$.call(_,"columns")},"aria-label":"two-columns",title:w("session.layout.columns"),style:qs,children:n.jsx(Uw,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:()=>{var $;return($=_.onApplyLayoutPreset)==null?void 0:$.call(_,"grid")},"aria-label":"grid-layout",title:w("session.layout.grid"),style:qs,children:n.jsx(qw,{size:13})})]}),_.onToggleMaximize&&n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onToggleMaximize,"aria-label":"toggle-maximize",title:`${_.isMaximized?w("session.restoreSize"):w("session.maximize")} · ${w("session.maximizeHint")}`,style:qs,children:_.isMaximized?n.jsx(Bu,{size:13}):n.jsx(qi,{size:13})}),_.onPopOutGroup&&n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onPopOutGroup,"aria-label":"pop-out",title:`${w("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:qs,children:n.jsx(li,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onMinimizeGroup,"aria-label":"minimize",title:`${w("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:qs,children:n.jsx(Qm,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:$=>$.stopPropagation(),onClick:_.onCloseGroup,"aria-label":"close",title:`${w("session.close")||"Close"} (Ctrl+Shift+X)`,style:qs,children:n.jsx(Jt,{size:13})})]})]}),n.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:$=>{if(!$){p(s,null);return}const q=$.getBoundingClientRect();p(s,{x:q.left,y:q.top,w:q.width,h:q.height})},onMouseDown:P,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map($=>{const q=a.get($);if(!q)return null;const Y=f[$]||{intent:"open",nonce:0};return n.jsx(eS,{session:q,visible:$===e.activeTab,intent:Y.intent,intentNonce:Y.nonce,onClose:()=>d($),sendMessage:u,subscribeBinary:x,onEvent:b,onCycleTab:F,remountKey:T[$]||0},$)})})]})}const qs={background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function FO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const h=k.useCallback(m=>{if(m.button!==0)return;m.preventDefault(),m.stopPropagation();const o=m.clientX,c=m.clientY;s();let d=!1;const p=()=>{d||(d=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",S),window.removeEventListener("blur",u),window.removeEventListener("keydown",x),document.removeEventListener("visibilitychange",b))},u=()=>{p(),a()},x=g=>{g.key==="Escape"&&u()},b=()=>{document.hidden&&u()},C=g=>{const _=e==="horizontal"?g.clientX-o:g.clientY-c;i(_)},S=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",S),window.addEventListener("blur",u),window.addEventListener("keydown",x),document.addEventListener("visibilitychange",b)},[e,s,i,a]),f=e==="horizontal";return n.jsx("div",{onMouseDown:h,style:{flex:"0 0 4px",background:He.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function Tp(e){const{node:s,path:i,onSplitSizes:a,...h}=e;return s.kind==="stack"?n.jsx(Dp,{stack:s,path:i,...h}):n.jsx(HO,{split:s,path:i,onSplitSizes:a,stackProps:h})}const Fy=80;function HO({split:e,path:s,onSplitSizes:i,stackProps:a}){const h=e.orientation==="horizontal",f=k.useRef(null),m=k.useRef([]),o=k.useRef(null);return n.jsx("div",{ref:f,style:{display:"flex",flexDirection:h?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((c,d)=>n.jsxs(k.Fragment,{children:[n.jsx("div",{ref:p=>{m.current[d]=p},style:{flex:`0 0 ${e.sizes[d]}%`,display:"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:n.jsx(Tp,{node:c,path:[...s,d],onSplitSizes:i,...a})}),d<e.children.length-1&&n.jsx(FO,{orientation:e.orientation,onDragStart:()=>{const p=f.current;if(!p)return;const u=e.sizes.slice();o.current={i:d,initialSizes:u,finalSizes:u.slice(),total:h?p.clientWidth:p.clientHeight}},onDrag:p=>{const u=o.current;if(!u||u.total<=0)return;const x=u.initialSizes[u.i]/100*u.total,b=u.initialSizes[u.i+1]/100*u.total,C=x+b,S=Math.max(Fy,Math.min(C-Fy,x+p)),g=C-S,_=S/u.total*100,w=g/u.total*100,y=m.current[u.i],E=m.current[u.i+1];y&&(y.style.flexBasis=`${_}%`),E&&(E.style.flexBasis=`${w}%`);const T=u.initialSizes.slice();T[u.i]=_,T[u.i+1]=w,u.finalSizes=T},onDragEnd:()=>{const p=o.current;p&&i(s,p.finalSizes),o.current=null}})]},d))})}const rn=28,hs=68;function Gu(e,s,i){const a=e-i.x,h=s-i.y;if(a<0||h<0||a>i.w||h>i.h)return null;const f=a-i.w/2,m=h-i.h/2;return Math.abs(f)<=rn&&Math.abs(m)<=rn?"center":f>=-hs-rn&&f<=-hs+rn&&Math.abs(m)<=rn?"left":f>=hs-rn&&f<=hs+rn&&Math.abs(m)<=rn?"right":m>=-hs-rn&&m<=-hs+rn&&Math.abs(f)<=rn?"top":m>=hs-rn&&m<=hs+rn&&Math.abs(f)<=rn?"bottom":null}function ju(e,s){const i=document.elementsFromPoint(e,s);for(const a of i){const h=a.closest("[data-group-id][data-stack-path]");if(!h)continue;const f=h.dataset.stackPath||"",m=f===""?[]:f.split(".").map(Number),o=h.getBoundingClientRect(),c={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:h.dataset.groupId||"",path:m,rect:c,zone:Gu(e,s,c)}}return null}function $O(e,s){const i=e.w/2,a=e.h/2;switch(s){case"center":return e;case"left":return{x:e.x,y:e.y,w:i,h:e.h};case"right":return{x:e.x+i,y:e.y,w:i,h:e.h};case"top":return{x:e.x,y:e.y,w:e.w,h:a};case"bottom":return{x:e.x,y:e.y+a,w:e.w,h:a}}}function pl({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,h=s?$O(e,s):null;return en.createPortal(n.jsxs(n.Fragment,{children:[h&&n.jsx("div",{style:{position:"fixed",left:h.x,top:h.y,width:h.w,height:h.h,background:`${He.info}33`,border:`2px dashed ${He.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=hs+rn;return n.jsxs("div",{style:{position:"fixed",left:i-f,top:a-f,width:f*2,height:f*2,pointerEvents:"none",zIndex:2500},children:[n.jsx(Go,{offsetX:f-rn,offsetY:f-rn,active:s==="center",kind:"center"}),n.jsx(Go,{offsetX:f-hs-rn,offsetY:f-rn,active:s==="left",kind:"left"}),n.jsx(Go,{offsetX:f+hs-rn,offsetY:f-rn,active:s==="right",kind:"right"}),n.jsx(Go,{offsetX:f-rn,offsetY:f-hs-rn,active:s==="top",kind:"top"}),n.jsx(Go,{offsetX:f-rn,offsetY:f+hs-rn,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Go({offsetX:e,offsetY:s,active:i,kind:a}){const h=rn*2,f=i?He.info:"#3a3a3a",m=i?He.bright:He.separator;return n.jsx("div",{style:{position:"absolute",left:e,top:s,width:h,height:h,background:"#1a1a1a",border:`1px solid ${m}`,borderRadius:4,boxShadow:i?`0 0 8px ${He.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:n.jsx(UO,{kind:a,fill:f})})}function UO({kind:e,fill:s}){const i={position:"absolute",background:s};switch(e){case"center":return n.jsx("div",{style:{...i,inset:4}});case"left":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{...i,left:4,top:4,bottom:4,width:"calc(50% - 4px)"}}),n.jsx("div",{style:{position:"absolute",right:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}})]});case"right":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",left:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),n.jsx("div",{style:{...i,right:4,top:4,bottom:4,width:"calc(50% - 4px)"}})]});case"top":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{...i,top:4,left:4,right:4,height:"calc(50% - 4px)"}}),n.jsx("div",{style:{position:"absolute",bottom:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}})]});case"bottom":return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",top:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),n.jsx("div",{style:{...i,bottom:4,left:4,right:4,height:"calc(50% - 4px)"}})]})}}function yr(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function al(e,s){let i=e;for(const a of s){if(i.kind!=="split"||a<0||a>=i.children.length)return null;i=i.children[a]}return i}function Vu(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=Vu(e.children[i],s);if(a)return[i,...a]}return null}function dn(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(dn)}function Eu(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(Eu)}function WO(e,s){const i=dn(e);if(i.length<=1||s==="single")return yr(i,Eu(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),h=Array.from({length:a},()=>[]);i.forEach((u,x)=>h[x%a].push(u));const f=new Set(Eu(e)),m=h.map(u=>yr(u,u.find(x=>f.has(x))||u[0]));if(s==="columns"||m.length<=2)return{kind:"split",orientation:"horizontal",children:m,sizes:m.map(()=>100/m.length)};const o=m.slice(0,2),c=m.slice(2),d=u=>u.length===1?u[0]:{kind:"split",orientation:"horizontal",children:u,sizes:u.map(()=>100/u.length)};return{kind:"split",orientation:"vertical",children:[d(o),d(c)],sizes:[50,50]}}function Wi(e,s){return nS(e,s)}function nS(e,s){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const f=e.tabs.filter(o=>o!==s);if(f.length===0)return null;const m=e.activeTab===s?f[0]:e.activeTab;return{kind:"stack",tabs:f,activeTab:m}}const i=[],a=[];for(let f=0;f<e.children.length;f++){const m=nS(e.children[f],s);m!==null&&(i.push(m),a.push(e.sizes[f]))}if(i.length===0)return null;if(i.length===1)return i[0];const h=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/h*100)}}function $i(e,s,i){return Yu(e,s,a=>{if(a.kind!=="stack")throw new Error("insertIntoStack: target must be a stack");return a.tabs.includes(i)?{...a,activeTab:i}:{kind:"stack",tabs:[...a.tabs,i],activeTab:i}})}function Pa(e,s,i,a){const h=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return Yu(e,s,m=>({kind:"split",orientation:h,children:f?[a,m]:[m,a],sizes:[50,50]}))}function Yu(e,s,i){if(s.length===0)return Nu(i(e));if(e.kind!=="split")throw new Error("replaceAt: path traverses non-split");const[a,...h]=s;if(a<0||a>=e.children.length)throw new Error("replaceAt: bad path");const f=e.children.map((m,o)=>o===a?Yu(m,h,i):m);return Nu({...e,children:f})}function Nu(e){if(e.kind==="stack")return e;const s=e.children.map(Nu),i=[],a=[];for(let f=0;f<s.length;f++){const m=s[f],o=e.sizes[f]??100/s.length;if(m.kind==="split"&&m.orientation===e.orientation){const c=m.sizes.reduce((d,p)=>d+p,0)||1;for(let d=0;d<m.children.length;d++)i.push(m.children[d]),a.push(m.sizes[d]/c*o)}else i.push(m),a.push(o)}if(i.length===1)return i[0];const h=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/h*100)}}function Bs(e,s){return e.kind==="stack"?e.tabs.includes(s)?{...e,activeTab:s}:e:{...e,children:e.children.map(i=>Bs(i,s))}}function sS(e,s,i){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const a=e.tabs.indexOf(s),h=Math.max(0,Math.min(i,e.tabs.length-1));if(h===a)return e;const f=e.tabs.slice();return f.splice(a,1),f.splice(h,0,s),{...e,tabs:f}}return{...e,children:e.children.map(a=>sS(a,s,i))}}function rS(e,s,i){return Yu(e,s,a=>{if(a.kind!=="split")throw new Error("setSplitSizes: target must be a split");if(a.children.length!==i.length)throw new Error("setSplitSizes: size count mismatch");return{...a,sizes:i}})}function qO(e,s,i,a){const h=al(e,i);if(!h||h.kind!=="stack"||a==="center"&&h.tabs.includes(s))return null;const f=h.tabs.find(d=>d!==s);if(!f)return null;const m=Wi(e,s);if(!m)return null;const o=Vu(m,f);if(!o)return null;const c=a==="center"?$i(m,o,s):Pa(m,o,a,yr([s]));return Bs(c,s)}function KO(e,s){const i=dn(e);let a=e;for(const h of i){if(!a)break;s.has(h)||(a=Wi(a,h))}return a}const Jc=320,Qc=200,Zc=80,eu=22,GO=4,Hy=8,Zr=10,tu=60;function ei(e,s,i){return Math.max(s,Math.min(i,e))}function VO(e,s,i,a){const h=e<=Hy,f=e>=i-Hy;if(!h&&!f)return null;const m=a/3,o=a*2/3;return h?s<m?"top-left":s>o?"bottom-left":"left":s<m?"top-right":s>o?"bottom-right":"right"}function $y(e,s,i){const a=Math.round(s/2),h=Math.round(i/2);switch(e){case"left":return{x:0,y:0,w:a,h:i};case"right":return{x:s-a,y:0,w:a,h:i};case"top-left":return{x:0,y:0,w:a,h};case"top-right":return{x:s-a,y:0,w:a,h};case"bottom-left":return{x:0,y:i-h,w:a,h};case"bottom-right":return{x:s-a,y:i-h,w:a,h}}}function YO(e,s,i,a,h){let f=e,m=s;const o=f,c=f+i,d=m,p=m+a;for(const u of h){const x=u.x,b=u.x+u.w,C=u.y,S=u.y+u.h;d<S&&p>C&&(Math.abs(o-b)<=Zr?f=b:Math.abs(c-x)<=Zr?f=x-i:Math.abs(o-x)<=Zr?f=x:Math.abs(c-b)<=Zr&&(f=b-i)),o<b&&c>x&&(Math.abs(d-S)<=Zr?m=S:Math.abs(p-C)<=Zr?m=C-a:Math.abs(d-C)<=Zr?m=C:Math.abs(p-S)<=Zr&&(m=S-a))}return{x:f,y:m}}function XO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:h,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:c}=dt(),d=P_("(max-width: 767px)"),p=cS(),u=k.useRef(null),[x,b]=k.useState(!1),C=k.useRef(null),[S,g]=k.useState(null),_=k.useRef({x:e.x,y:e.y,w:e.w,h:e.h});_.current={x:e.x,y:e.y,w:e.w,h:e.h};const[w,y]=k.useState(null),E=k.useRef(null),T=k.useRef(i);T.current=i;const[j,R]=k.useState(null),N=k.useRef(null),D=k.useCallback((X,G)=>{if(d||x||X.button!==0||X.target.closest("[data-no-drag]"))return;X.preventDefault(),p.focus(dn(e.root)[0]||"");const ge=X.clientX,xe=X.clientY,he={..._.current},Ie=u.current,Fe=window.innerWidth,be=window.innerHeight;let Ue="";G&&Ie&&(Ue=Ie.style.pointerEvents,Ie.style.pointerEvents="none");let Pe=!1;const tt=()=>{Pe||(Pe=!0,window.removeEventListener("mousemove",ze),window.removeEventListener("mouseup",Ke),window.removeEventListener("blur",ke),window.removeEventListener("keydown",pe),document.removeEventListener("visibilitychange",Ne),G&&Ie&&(Ie.style.pointerEvents=Ue))},ke=()=>{tt(),N.current=null,R(null),E.current=null,y(null),p.setGroupGeometry(e.id,{..._.current})},pe=Ve=>{Ve.key==="Escape"&&ke()},Ne=()=>{document.hidden&&ke()};let Le=!1;const ze=Ve=>{if(Le)return;{const se=window.screenX,le=window.screenY,ve=se+window.outerWidth,Ce=le+window.outerHeight;if(Ve.screenX<se-tu||Ve.screenX>ve+tu||Ve.screenY<le-tu||Ve.screenY>Ce+tu){Le=!0,tt(),N.current=null,R(null),E.current=null,y(null),p.setGroupGeometry(e.id,{..._.current}),p.popOutGroup(e.id,{atScreenX:Ve.screenX,atScreenY:Ve.screenY});return}}const de=Ve.clientX-ge,fe=Ve.clientY-xe;let ce=ei(he.x+de,-(he.w-Zc),Fe-Zc),Q=ei(he.y+fe,0,be-eu);const V=T.current;if(V.length>0){const se=YO(ce,Q,he.w,he.h,V);ce=se.x,Q=se.y}if(Ie&&(Ie.style.left=`${ce}px`,Ie.style.top=`${Q}px`),_.current.x=ce,_.current.y=Q,G){let se=null;const le=document.elementFromPoint(Ve.clientX,Ve.clientY),ve=le==null?void 0:le.closest("[data-group-id][data-stack-path]");if(ve){const Ce=ve.dataset.groupId||"";if(Ce!==e.id){const De=ve.dataset.stackPath||"",Qe=De===""?[]:De.split(".").map(Number),ut=ve.getBoundingClientRect(),ot={x:ut.left,y:ut.top,w:ut.width,h:ut.height};se={groupId:Ce,path:Qe,rect:ot,zone:Gu(Ve.clientX,Ve.clientY,ot)}}}N.current=se,R(se?{rect:se.rect,zone:se.zone}:null)}const te=G&&N.current&&N.current.zone?null:VO(Ve.clientX,Ve.clientY,Fe,be);te!==E.current&&(E.current=te,y(te))},Ke=()=>{if(tt(),G&&N.current&&N.current.zone){const Ve=N.current;p.dockGroup(e.id,Ve.groupId,Ve.path,Ve.zone),N.current=null,R(null),E.current=null,y(null);return}if(E.current){const Ve=$y(E.current,Fe,be);Ie&&(Ie.style.left=`${Ve.x}px`,Ie.style.top=`${Ve.y}px`,Ie.style.width=`${Ve.w}px`,Ie.style.height=`${Ve.h}px`),_.current=Ve,E.current=null,y(null)}N.current=null,R(null),p.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",ze),window.addEventListener("mouseup",Ke),window.addEventListener("blur",ke),window.addEventListener("keydown",pe),document.addEventListener("visibilitychange",Ne)},[d,x,p,e.id,e.root]),A=k.useCallback(X=>D(X,!1),[D]),O=k.useCallback(X=>D(X,!0),[D]),z=k.useCallback(X=>G=>{if(d||x||G.button!==0)return;G.preventDefault(),G.stopPropagation();const me=G.clientX,ge=G.clientY,xe={..._.current},he=u.current,Ie=window.innerWidth,Fe=window.innerHeight,be=Le=>{const ze=Le.clientX-me,Ke=Le.clientY-ge;let Ve=xe.x,de=xe.y,fe=xe.w,ce=xe.h;X.includes("e")?fe=ei(xe.w+ze,Jc,Math.max(Jc,Ie-xe.x)):X.includes("w")&&(Ve=ei(xe.x+ze,0,xe.x+xe.w-Jc),fe=xe.x+xe.w-Ve),X.includes("s")?ce=ei(xe.h+Ke,Qc,Math.max(Qc,Fe-xe.y)):X.includes("n")&&(de=ei(xe.y+Ke,0,xe.y+xe.h-Qc),ce=xe.y+xe.h-de),he&&(he.style.left=`${Ve}px`,he.style.top=`${de}px`,he.style.width=`${fe}px`,he.style.height=`${ce}px`),_.current={x:Ve,y:de,w:fe,h:ce}};let Ue=!1;const Pe=()=>{Ue||(Ue=!0,window.removeEventListener("mousemove",be),window.removeEventListener("mouseup",Ne),window.removeEventListener("blur",tt),window.removeEventListener("keydown",ke),document.removeEventListener("visibilitychange",pe))},tt=()=>{Pe(),p.setGroupGeometry(e.id,{..._.current})},ke=Le=>{Le.key==="Escape"&&tt()},pe=()=>{document.hidden&&tt()},Ne=()=>{Pe(),p.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",be),window.addEventListener("mouseup",Ne),window.addEventListener("blur",tt),window.addEventListener("keydown",ke),document.addEventListener("visibilitychange",pe)},[d,x,p,e.id]);k.useEffect(()=>{if(d)return;const X=()=>{const G=window.innerWidth,me=window.innerHeight,ge=_.current,xe=ei(ge.x,-(ge.w-Zc),G-Zc),he=ei(ge.y,0,me-eu);(xe!==ge.x||he!==ge.y)&&p.setGroupGeometry(e.id,{...ge,x:xe,y:he})};return window.addEventListener("resize",X),()=>window.removeEventListener("resize",X)},[d,p,e.id]);const P=k.useCallback(X=>{g(X),p.setActiveTab(e.id,X),p.focus(X)},[p,e.id]),F=k.useCallback(X=>{g(X),p.focus(X)},[p]),H=k.useCallback(X=>{p.close(X)},[p]),$=k.useCallback((X,G,me)=>{p.beginTabDrag(e.id,X,G,me)},[p,e.id]),q=k.useCallback(X=>{p.close(X)},[p]),Y=k.useCallback((X,G)=>{p.setSplitSizes(e.id,X,G)},[p,e.id]),I=Eu(e.root),B=dn(e.root);k.useEffect(()=>{S&&B.includes(S)||g(I[0]||B[0]||null)},[S,I,B]);const U=k.useCallback(()=>{if(x){const X=C.current;X&&p.setGroupGeometry(e.id,X),C.current=null,b(!1);return}C.current={..._.current},p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(Jc,window.innerWidth-12),h:Math.max(Qc,window.innerHeight-12)}),b(!0)},[p,e.id,x]),J=X=>{const G=/Mac|iPhone|iPad|iPod/.test(navigator.platform),me=G?X.metaKey:X.ctrlKey,ge=G?X.ctrlKey:X.metaKey;if(!me||ge||X.altKey||!X.shiftKey)return;const xe=X.key.toLowerCase();xe==="o"?(X.preventDefault(),p.popOutGroup(e.id)):xe==="m"?(X.preventDefault(),p.minimizeGroup(e.id)):xe==="x"&&(X.preventDefault(),p.closeGroup(e.id))};if(d){const X=I[0],G=X?s.get(X):null;if(!G)return null;const me=e.intents[X]??{intent:"open",nonce:0};return en.createPortal(n.jsxs("div",{style:{position:"fixed",inset:0,background:He.bg,display:"flex",flexDirection:"column",zIndex:110},children:[n.jsxs("div",{style:{background:He.titleBg,height:eu,display:"flex",alignItems:"center",borderBottom:`1px solid ${He.separator}`},children:[n.jsx("span",{style:{flex:1,color:He.titleText,fontFamily:Rt,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G.title}),n.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ti,"aria-label":"close",children:n.jsx(Jt,{size:14})})]}),n.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:n.jsx(eS,{session:G,visible:!0,intent:me.intent,intentNonce:me.nonce,onClose:()=>p.close(X),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const W=w?(()=>{const X=window.innerWidth,G=window.innerHeight,me=$y(w,X,G);return en.createPortal(n.jsx("div",{style:{position:"fixed",left:me.x,top:me.y,width:me.w,height:me.h,background:`${He.info}33`,border:`2px dashed ${He.info}`,borderRadius:8,pointerEvents:"none",zIndex:2e3,transition:"left 80ms ease-out, top 80ms ease-out, width 80ms ease-out, height 80ms ease-out",boxSizing:"border-box"}}),document.body)})():null,oe=(()=>{var G;if(B.length===0)return"";const X=((G=s.get(B[0]))==null?void 0:G.title)||B[0];return B.length===1?X:`${X} +${B.length-1}`})(),ee=e.root.kind==="split",Z=en.createPortal(n.jsxs("div",{ref:u,onKeyDown:J,onMouseDown:ee?()=>p.focus(B[0]||""):O,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:h,background:He.bg,border:`1px solid ${a?He.info:He.separator}`,borderRadius:8,boxShadow:a?`0 10px 40px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.3), 0 0 0 1px ${He.info}66, 0 0 18px ${He.info}33`:"0 10px 40px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden",opacity:a?1:.88,filter:a?"none":"saturate(0.82)",transition:"box-shadow 120ms ease-out, border-color 120ms ease-out, opacity 140ms ease-out, filter 140ms ease-out"},children:[ee&&n.jsxs("div",{onMouseDown:A,onDoubleClick:X=>{X.target.closest("button")||U()},style:{height:eu,flexShrink:0,display:"flex",flexDirection:"column",background:He.titleBg,borderBottom:`1px solid ${He.separator}`,userSelect:"none",cursor:"move"},children:[n.jsx("div",{style:{display:"flex",height:GO,flexShrink:0},children:I.map((X,G)=>n.jsx("div",{style:{flex:1,background:e.colors[X]||He.titleText}},G))}),n.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:He.titleText,fontFamily:Rt,fontSize:11},children:[n.jsx("span",{style:{color:He.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),n.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:oe}),B.length>1&&n.jsxs(n.Fragment,{children:[n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:ti,"aria-label":"single-pane",title:c("session.layout.single"),children:n.jsx(Ki,{size:12})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:ti,"aria-label":"two-columns",title:c("session.layout.columns"),children:n.jsx(Uw,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:ti,"aria-label":"grid-layout",title:c("session.layout.grid"),children:n.jsx(qw,{size:13})})]}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:U,style:ti,"aria-label":"toggle-maximize",title:`${c(x?"session.restoreSize":"session.maximize")} · ${c("session.maximizeHint")}`,children:x?n.jsx(Bu,{size:13}):n.jsx(qi,{size:13})}),n.jsx("button",{"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>p.popOutGroup(e.id),style:ti,"aria-label":"pop-out",title:`${c("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:n.jsx(li,{size:14})}),n.jsx("button",{"data-no-drag":!0,onClick:()=>p.minimizeGroup(e.id),style:ti,"aria-label":"minimize",title:`${c("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:n.jsx(Qm,{size:14})}),n.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ti,"aria-label":"close",title:`${c("session.close")||"Close"} (Ctrl+Shift+X)`,children:n.jsx(Jt,{size:14})})]})]}),n.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?n.jsx(Tp,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:P,onTabClose:H,onTabMouseDown:$,onPaneAutoClose:q,registerRect:()=>{},onSplitSizes:Y,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:S||void 0,groupTopmost:a,onFocusStack:F}):n.jsx(Dp,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:P,onTabClose:H,onTabMouseDown:$,onPaneAutoClose:q,registerRect:()=>{},sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:S||void 0,groupTopmost:a,onFocusStack:F,groupActions:{onMinimizeGroup:()=>p.minimizeGroup(e.id),onCloseGroup:()=>p.closeGroup(e.id),onPopOutGroup:()=>p.popOutGroup(e.id),onToggleMaximize:U,isMaximized:x,onApplyLayoutPreset:X=>p.applyLayoutPreset(e.id,X)}})}),n.jsx("div",{onMouseDown:z("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),n.jsx("div",{onMouseDown:z("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),n.jsx("div",{onMouseDown:z("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),n.jsx("div",{onMouseDown:z("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),n.jsx("div",{onMouseDown:z("se"),title:"resize",style:{position:"absolute",right:0,bottom:0,width:14,height:14,cursor:"nwse-resize",background:"linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.2) 50%)",zIndex:4}})]}),document.body);return n.jsxs(n.Fragment,{children:[Z,W,j&&n.jsx(pl,{targetRect:j.rect,activeZone:j.zone})]})}const ti={background:"transparent",border:"none",color:He.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},qf=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Hi(e){for(const s of qf)if(!e.includes(s))return s;return qf[e.length%qf.length]}const JO="clitrigger:session-windows:global";function Rp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(JO),s=new Set;return e.onmessage=i=>{const a=i.data;for(const h of s)try{h(a)}catch{}},{post:i=>{e.postMessage(i)},subscribe:i=>(s.add(i),()=>{s.delete(i)}),close:()=>{s.clear(),e.close()}}}const zt="main",Am=new Map;function QO(e,s){Am.set(e,s)}function ZO(e){const s=Am.get(e);if(!s||s.closed)return Am.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function ez(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Mp=5e3,iS=15e3;let za=null;function aS(){if(typeof window>"u")return()=>{};const e=s=>{za={sx:s.screenX,sy:s.screenY,cx:s.clientX,cy:s.clientY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function Lu(e,s){if(za)return{x:za.cx+(e-za.sx),y:za.cy+(s-za.sy)};const i=Math.max(0,(window.outerWidth-window.innerWidth)/2),a=Math.max(0,window.outerHeight-window.innerHeight-i);return{x:e-window.screenX-i,y:s-window.screenY-a}}function Du(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Om="clitrigger:popout-alive:";function tz(e){return`${Om}${e}`}function Ap(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function nz(e){if(!Ap())return()=>{};let s=()=>{};return navigator.locks.request(tz(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function oS(){var e;if(!Ap())return new Set;try{const s=await navigator.locks.query(),i=new Set;for(const a of s.held??[])(e=a.name)!=null&&e.startsWith(Om)&&i.add(a.name.slice(Om.length));return i}catch{return new Set}}const Op=k.createContext(null),lS=k.createContext({});function cS(){const e=k.useContext(Op);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function sz(){return k.useContext(lS)}function rz(){return k.useContext(Op)}const Tu=720,zp=460,iz=320,az=200,Uy=30,uS=80,dS=80,ol=80,zm=28;function oz(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=iz?e.w:Tu,h=Number.isFinite(e.h)&&e.h>=az?e.h:zp;a=Math.min(a,s),h=Math.min(h,i);let f=Number.isFinite(e.x)?e.x:uS,m=Number.isFinite(e.y)?e.y:dS;return f=Math.max(Math.min(f,s-ol),-(a-ol)),m=Math.max(Math.min(m,i-zm),0),{x:f,y:m,w:a,h}}const lz=12,nu=60;function hS(e){return`sessionGroups:${e}`}function hu(e){try{const s=localStorage.getItem(hS(e));if(!s)return null;const i=JSON.parse(s);if(Array.isArray(i==null?void 0:i.groups)&&typeof(i==null?void 0:i.zCounter)=="number")return i}catch{}return null}function Bm(e,s){try{localStorage.setItem(hS(e),JSON.stringify(s))}catch{}}function cz(e,s){const i=hu(e);!i||!i.groups.some(a=>a.id===s)||(Bm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function uz(e){const s=e%8;return{x:uS+s*Uy,y:dS+s*Uy,w:Tu,h:zp}}function su(e,s,i){return Math.max(s,Math.min(i,e))}function Wy(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function ni(e,s){for(const i of e)if(Vu(i.root,s))return i;return null}function dz({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:h,onAddSession:f,children:m}){const{t:o}=dt(),[c]=k.useState(()=>{const Q=hu(e);if(!Q)return{groups:[],zCounter:0};const V=Q.groups.map(re=>{const te=dn(re.root),se=new Set(te),le={};for(const Qe of Object.keys(re.colors||{}))se.has(Qe)&&(le[Qe]=re.colors[Qe]);const ve={};for(const Qe of te)ve[Qe]={intent:"open",nonce:0},le[Qe]||(le[Qe]=Hi(Object.values(le)));const Ce=oz({x:re.x,y:re.y,w:re.w,h:re.h}),De=re.ownerWindowId||zt;return{...re,...Ce,colors:le,intents:ve,minimized:!!re.minimized,ownerWindowId:De}});return{groups:V,zCounter:Q.zCounter||V.length}}),[d,p]=k.useState(c.groups),u=k.useRef(c.zCounter),x=k.useRef(d);x.current=d;const b=k.useRef(s);b.current=s;const[C,S]=k.useState(null),g=k.useRef(null);g.current=C;const[_,w]=k.useState({}),y=k.useRef(_);y.current=_,k.useEffect(()=>{var te;const Q={},V=((te=hu(e))==null?void 0:te.sessionProjects)??{},re={};for(const se of d)for(const le of dn(se.root)){const ve=s.find(De=>De.id===le)||_[le];ve!=null&&ve.title&&(Q[le]=ve.title);const Ce=(ve==null?void 0:ve.project_id)||V[le];Ce&&(re[le]=Ce)}Bm(e,{groups:d,zCounter:u.current,titles:Q,sessionProjects:re}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,d,s,_]),k.useEffect(()=>()=>{var ve;const Q=x.current;if(Q.length===0)return;let V=!1;const re=Q.map(Ce=>(Ce.ownerWindowId||zt)!==zt||Ce.minimized?Ce:(V=!0,{...Ce,minimized:!0}));if(!V)return;const te={},se=((ve=hu(e))==null?void 0:ve.sessionProjects)??{},le={};for(const Ce of re)for(const De of dn(Ce.root)){const Qe=b.current.find(ot=>ot.id===De)||y.current[De];Qe!=null&&Qe.title&&(te[De]=Qe.title);const ut=(Qe==null?void 0:Qe.project_id)||se[De];ut&&(le[De]=ut)}Bm(e,{groups:re,zCounter:u.current,titles:te,sessionProjects:le}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]);const[E,T]=k.useState(()=>new Set),j=k.useRef(new Set);k.useEffect(()=>{if(s.length===0)return;const Q=s.filter(re=>re.project_id===e);if(Q.length===0)return;const V=new Set(Q.map(re=>re.id));for(const re of d)for(const te of dn(re.root))V.has(te)||_[te]||E.has(te)||j.current.has(te)||(j.current.add(te),S1(te).then(se=>w(le=>({...le,[te]:se}))).catch(se=>{se instanceof mu&&se.status===404&&T(le=>new Set(le).add(te))}).finally(()=>j.current.delete(te)))},[d,s,e,_,E]),k.useEffect(()=>h(V=>{V.type!=="session:status-changed"||!V.sessionId||w(re=>{const te=re[V.sessionId];if(!te)return re;const se={status:V.status};return V.worktree_path!==void 0&&(se.worktree_path=V.worktree_path),V.branch_name!==void 0&&(se.branch_name=V.branch_name),{...re,[te.id]:{...te,...se}}})}),[h]),k.useEffect(()=>{E.size!==0&&p(Q=>{let V=!1;const re=[];for(const te of Q){const se=dn(te.root);if(!se.some(ut=>E.has(ut))){re.push(te);continue}V=!0;const le=new Set(se.filter(ut=>!E.has(ut))),ve=KO(te.root,le);if(!ve)continue;const Ce=new Set(dn(ve)),De={};for(const ut of Object.keys(te.colors))Ce.has(ut)&&(De[ut]=te.colors[ut]);const Qe={};for(const ut of Object.keys(te.intents))Ce.has(ut)&&(Qe[ut]=te.intents[ut]);re.push({...te,root:ve,colors:De,intents:Qe})}return V?re:Q})},[E]);const R=k.useCallback((Q,V)=>{const re=x.current.length,te=uz(re);u.current+=1;const se=u.current;return{id:Wy(),...te,z:se,minimized:!1,root:yr([Q],Q),colors:{[Q]:Hi([])},intents:{[Q]:{intent:V,nonce:0}},ownerWindowId:zt}},[]),N=k.useCallback((Q,V="open")=>{p(re=>{const te=ni(re,Q);u.current+=1;const se=u.current;return te?re.map(le=>{var ut,ot,Je;if(le.id!==te.id)return le;const ve=((ut=le.intents[Q])==null?void 0:ut.intent)??"open",Ce=V==="start"||V==="resume",De=Ce?V:ve,Qe=De!==ve||Ce;return{...le,z:se,minimized:!1,root:Bs(le.root,Q),intents:{...le.intents,[Q]:{intent:De,nonce:Qe?(((ot=le.intents[Q])==null?void 0:ot.nonce)??0)+1:((Je=le.intents[Q])==null?void 0:Je.nonce)??0}}}}):[...re,R(Q,V)]})},[R]),D=k.useCallback(Q=>{p(V=>{const re=ni(V,Q);if(!re)return V;const te=V.reduce((le,ve)=>ve.z>le?ve.z:le,0);if(re.z===te&&!re.minimized)return V;u.current+=1;const se=u.current;return V.map(le=>le.id===re.id?{...le,z:se,minimized:!1}:le)})},[]),A=k.useCallback(Q=>{const V=Q.map(re=>b.current.find(te=>te.id===re)||y.current[re]).filter(re=>!!re&&re.status==="running");if(V.length===0)return!0;if(!window.confirm(o("session.confirmStop")))return!1;for(const re of V)yu(re.id).catch(()=>{});return!0},[o]),O=k.useCallback(Q=>{A([Q])&&p(V=>{const re=ni(V,Q);if(!re)return V;const te=Wi(re.root,Q);if(!te)return V.filter(ve=>ve.id!==re.id);new Set(dn(te));const se={...re.colors};delete se[Q];const le={...re.intents};return delete le[Q],V.map(ve=>ve.id===re.id?{...ve,root:te,colors:se,intents:le}:ve)})},[A]),z=k.useCallback(Q=>{p(V=>{const re=ni(V,Q);return re?V.map(te=>te.id===re.id?{...te,minimized:!0}:te):V})},[]),P=k.useCallback(Q=>{p(V=>{const re=ni(V,Q);if(!re)return V;u.current+=1;const te=u.current;return V.map(se=>se.id===re.id?{...se,minimized:!1,z:te}:se)})},[]),F=k.useCallback(Q=>!!ni(x.current,Q),[]),H=k.useCallback(Q=>{const V=x.current.find(re=>re.id===Q);V&&!A(dn(V.root))||p(re=>re.filter(te=>te.id!==Q))},[A]),$=k.useCallback(Q=>{p(V=>V.map(re=>re.id===Q?{...re,minimized:!0}:re))},[]);k.useEffect(()=>{const Q=re=>{const te=re.detail;!(te!=null&&te.projectId)||!te.groupId||te.projectId===e&&p(se=>{if(!se.find(Ce=>Ce.id===te.groupId))return se;u.current+=1;const ve=u.current;return se.map(Ce=>Ce.id===te.groupId?{...Ce,minimized:!1,z:ve}:Ce)})},V=re=>{var ve;const te=re.detail;if(!(te!=null&&te.projectId)||!te.groupId||te.projectId!==e)return;const se=x.current.find(Ce=>Ce.id===te.groupId);if(se&&!A(dn(se.root)))return;const le=(se==null?void 0:se.ownerWindowId)||zt;le!==zt&&(X.current.delete(le),Ie.current.delete(te.groupId),(ve=Z.current)==null||ve.post({t:"group-reclaimed",popoutId:le,groupIds:[te.groupId],reason:"late-return"})),p(Ce=>Ce.filter(De=>De.id!==te.groupId))};return window.addEventListener("session-windows:restore",Q),window.addEventListener("session-windows:close",V),()=>{window.removeEventListener("session-windows:restore",Q),window.removeEventListener("session-windows:close",V)}},[e,A]),k.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRestore");if(Q)try{const V=JSON.parse(Q);if(V.projectId!==e||!V.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),p(re=>{if(!re.find(le=>le.id===V.groupId))return re;u.current+=1;const se=u.current;return re.map(le=>le.id===V.groupId?{...le,minimized:!1,z:se}:le)})}catch{}},[e]);const q=k.useCallback(Q=>{p(V=>{if(!V.find(se=>se.id===Q))return V;u.current+=1;const te=u.current;return V.map(se=>se.id===Q?{...se,minimized:!1,z:te}:se)})},[]),Y=k.useCallback((Q,V)=>{p(re=>re.map(te=>te.id===Q?{...te,...V}:te))},[]),I=k.useCallback((Q,V,re)=>{p(te=>te.map(se=>se.id===Q?{...se,root:rS(se.root,V,re)}:se))},[]),B=k.useCallback((Q,V)=>{p(re=>re.map(te=>te.id===Q?{...te,root:Bs(te.root,V)}:te))},[]),U=k.useCallback((Q,V)=>{p(re=>re.map(te=>te.id===Q?{...te,root:WO(te.root,V)}:te))},[]),J=k.useCallback((Q,V,re)=>{p(te=>te.map(se=>se.id===Q?{...se,root:sS(se.root,V,re)}:se))},[]),W=k.useCallback((Q,V,re,te)=>{if(te.button!==0||!x.current.find(st=>st.id===Q))return;te.preventDefault();const le=te.clientX,ve=te.clientY;let Ce=null;S({groupId:Q,sessionId:V,fromPath:re,startX:le,startY:ve,mouseX:le,mouseY:ve,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null});const De=(st,ht)=>{const Re=Wy();Ce=Re;const ct=window.innerWidth,Oe=window.innerHeight,ie={x:su(st-60,-Tu+ol,ct-ol),y:su(ht-12,0,Oe-zm),w:Tu,h:zp};p(_e=>{const je=_e.find(Et=>Et.id===Q);if(!je)return _e;const we=Wi(je.root,V),rt=je.colors[V]||Hi([]),Me=je.intents[V]??{intent:"open",nonce:0};u.current+=1;const vt=u.current,bt={id:Re,...ie,z:vt,minimized:!1,root:yr([V],V),colors:{[V]:rt},intents:{[V]:Me},ownerWindowId:zt},St=[];for(const Et of _e)if(Et.id===Q){if(we){const Ht=new Set(dn(we)),pn={};for(const yn of Object.keys(Et.colors))Ht.has(yn)&&(pn[yn]=Et.colors[yn]);const gn={};for(const yn of Object.keys(Et.intents))Ht.has(yn)&&(gn[yn]=Et.intents[yn]);St.push({...Et,root:Nu(we),colors:pn,intents:gn})}}else St.push(Et);return St.push(bt),St})};let Qe=!1;const ut=st=>{const ht=window.screenX,Re=window.screenY,ct=ht+window.outerWidth,Oe=Re+window.outerHeight;return st.screenX<ht-nu||st.screenX>ct+nu||st.screenY<Re-nu||st.screenY>Oe+nu},ot=st=>{if(Qe)return;const ht=g.current;if(!ht)return;if(!Ce)Math.hypot(st.clientX-le,st.clientY-ve)>=lz&&De(st.clientX,st.clientY);else{const je=window.innerWidth,we=window.innerHeight,rt=su(st.clientX-60,-640,je-ol),Me=su(st.clientY-12,0,we-zm);p(vt=>vt.map(bt=>bt.id===Ce?{...bt,x:rt,y:Me}:bt))}if(Ce&&ut(st)&&x.current.some(je=>je.id===Ce)){const je=Fe.current;if(je){Qe=!0;const we=Ce;qe(),S(null),je(we,{atScreenX:st.screenX,atScreenY:st.screenY});return}}let Re=null,ct=null,Oe=null,ie=null;const _e=document.elementsFromPoint(st.clientX,st.clientY);for(const je of _e){const we=je.closest("[data-group-id][data-stack-path]");if(!we)continue;const rt=we.dataset.groupId||"",Me=we.dataset.stackPath||"";if(Ce?rt===Ce:rt===ht.groupId&&Me===ht.fromPath.join("."))continue;const bt=Me===""?[]:Me.split(".").map(Number),St=we.getBoundingClientRect();Re=rt,ct=bt,Oe={x:St.left,y:St.top,w:St.width,h:St.height},ie=Gu(st.clientX,st.clientY,Oe);break}S({...ht,mouseX:st.clientX,mouseY:st.clientY,hoveredGroupId:Re,hoveredPath:ct,hoveredRect:Oe,zone:ie})};let Je=!1;const qe=()=>{Je||(Je=!0,window.removeEventListener("mousemove",ot),window.removeEventListener("mouseup",pt),window.removeEventListener("blur",ft),window.removeEventListener("keydown",lt),document.removeEventListener("visibilitychange",xt))},ft=()=>{qe(),S(null)},lt=st=>{st.key==="Escape"&&ft()},xt=()=>{document.hidden&&ft()},pt=()=>{qe();const st=g.current;if(S(null),!!st&&st.hoveredGroupId&&st.hoveredPath&&st.zone){const ht=Ce||st.groupId;oe(ht,st.sessionId,st.hoveredGroupId,st.hoveredPath,st.zone);return}};window.addEventListener("mousemove",ot),window.addEventListener("mouseup",pt),window.addEventListener("blur",ft),window.addEventListener("keydown",lt),document.addEventListener("visibilitychange",xt)},[]),oe=k.useCallback((Q,V,re,te,se)=>{p(le=>{const ve=le.find(lt=>lt.id===Q),Ce=le.find(lt=>lt.id===re);if(!ve||!Ce)return le;if(Q===re){const lt=al(ve.root,te);if(!lt||lt.kind!=="stack")return le;const xt=lt.tabs.find(Re=>Re!==V);if(!xt)return le;const pt=Wi(ve.root,V);if(!pt)return le;const st=Vu(pt,xt);if(!st)return le;let ht;return se==="center"?ht=$i(pt,st,V):ht=Pa(pt,st,se,yr([V])),ht=Bs(ht,V),le.map(Re=>Re.id!==Q?Re:(u.current+=1,{...Re,root:ht,z:u.current,minimized:!1}))}const De=Wi(ve.root,V),Qe=ve.colors[V],ut=ve.intents[V]??{intent:"open",nonce:0};let ot;if(se==="center")ot=$i(Ce.root,te,V);else{const lt=yr([V]);ot=Pa(Ce.root,te,se,lt)}ot=Bs(ot,V);const Je={...Ce.colors};Je[V]||(Je[V]=Qe||Hi(Object.values(Je)));const qe={...Ce.intents,[V]:ut},ft=[];for(const lt of le)if(lt.id===Q){if(De){const xt=new Set(dn(De)),pt={};for(const ht of Object.keys(lt.colors))xt.has(ht)&&(pt[ht]=lt.colors[ht]);const st={};for(const ht of Object.keys(lt.intents))xt.has(ht)&&(st[ht]=lt.intents[ht]);ft.push({...lt,root:De,colors:pt,intents:st})}}else lt.id===re?(u.current+=1,ft.push({...lt,root:ot,colors:Je,intents:qe,z:u.current,minimized:!1})):ft.push(lt);return ft})},[]),ee=k.useCallback((Q,V,re,te)=>{p(se=>{if(Q===V)return se;const le=se.find(Je=>Je.id===Q),ve=se.find(Je=>Je.id===V);if(!le||!ve||le.root.kind!=="stack")return se;const Ce=le.root;let De;te==="center"?De=Ce.tabs.reduce((Je,qe)=>$i(Je,re,qe),ve.root):De=Pa(ve.root,re,te,Ce),De=Bs(De,Ce.activeTab);const Qe={...ve.colors,...le.colors},ut={...ve.intents,...le.intents},ot=[];for(const Je of se)Je.id!==Q&&(Je.id===V?(u.current+=1,ot.push({...Je,root:De,colors:Qe,intents:ut,z:u.current,minimized:!1})):ot.push(Je));return ot})},[]),Z=k.useRef(null),X=k.useRef(new Map),[G,me]=k.useState(null),ge=k.useRef(G);ge.current=G;const xe=k.useRef(null),he=k.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);k.useEffect(()=>{const Q=()=>{he.current=Date.now()};window.addEventListener("focus",Q);const V=aS();return()=>{window.removeEventListener("focus",Q),V(),xe.current&&clearTimeout(xe.current)}},[]);const Ie=k.useRef(new Map),Fe=k.useRef(null),be=k.useCallback((Q,V)=>{var ot;const re=x.current.find(Je=>Je.id===Q);if(!re)return;const te=ez(),se={...re,ownerWindowId:te};Ie.current.set(Q,se),X.current.set(te,Date.now()),p(Je=>Je.map(qe=>qe.id===Q?{...qe,ownerWindowId:te}:qe)),(ot=Z.current)==null||ot.post({t:"group-handoff",to:te,groupId:Q,group:se});const le=V&&(typeof V.atScreenX=="number"||typeof V.atScreenY=="number"),ve=le?Math.max(0,((V==null?void 0:V.atScreenX)??window.screenX+re.x)-40):Math.max(0,window.screenX+re.x),Ce=le?Math.max(0,((V==null?void 0:V.atScreenY)??window.screenY+re.y)-12):Math.max(0,window.screenY+re.y),De=["popup",`width=${Math.max(400,re.w)}`,`height=${Math.max(300,re.h+40)}`,`left=${ve}`,`top=${Ce}`].join(","),Qe=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(Q)}?wid=${encodeURIComponent(te)}`,ut=window.open(Qe,"_blank",De);if(!ut){Ie.current.delete(Q),X.current.delete(te),p(Je=>Je.map(qe=>qe.id===Q?{...qe,ownerWindowId:zt}:qe)),window.alert(o("session.popout.blocked")||"Popup blocked. Allow popups for this site to use Pop Out.");return}QO(te,ut)},[e,o]);Fe.current=be;const Ue=k.useCallback(Q=>{var te;const V=x.current.find(se=>se.id===Q);if(!V)return;const re=V.ownerWindowId||zt;if(re===zt){q(Q);return}(te=Z.current)==null||te.post({t:"group-recall",popoutId:re,groupId:Q}),setTimeout(()=>{var ve;const se=x.current.find(Ce=>Ce.id===Q);if(!se||(se.ownerWindowId||zt)===zt)return;X.current.delete(re),Ie.current.delete(Q),(ve=Z.current)==null||ve.post({t:"group-reclaimed",popoutId:re,groupIds:[Q],reason:"late-return"}),u.current+=1;const le=u.current;p(Ce=>Ce.map(De=>De.id===Q?{...De,ownerWindowId:zt,minimized:!1,z:le}:De))},1500)},[q]),Pe=k.useCallback(Q=>{const V=ni(x.current,Q);V&&Ue(V.id)},[Ue]);k.useEffect(()=>{const Q=V=>{const re=V.detail;!(re!=null&&re.projectId)||!re.groupId||re.projectId!==e||Ue(re.groupId)};return window.addEventListener("session-windows:recall",Q),()=>window.removeEventListener("session-windows:recall",Q)},[e,Ue]),k.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRecall");if(Q)try{const V=JSON.parse(Q);if(V.projectId!==e||!V.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const re=V.groupId;setTimeout(()=>Ue(re),0)}catch{}},[e,Ue]);const tt=k.useCallback(Q=>Q.kind==="stack"?[]:[0,...tt(Q.children[0])],[]),ke=k.useCallback((Q,V,re)=>{const te=V?x.current.find(Ce=>Ce.id===V):null,se=te&&(te.ownerWindowId||zt)===zt;if(!te||!se){N(Q,"start");return}const le=(()=>{if(re){const Ce=al(te.root,re);if(Ce&&Ce.kind==="stack")return re}return tt(te.root)})();u.current+=1;const ve=u.current;p(Ce=>Ce.map(De=>{if(De.id!==te.id)return De;const Qe=Bs($i(De.root,le,Q),Q);return{...De,root:Qe,z:ve,minimized:!1,colors:{...De.colors,[Q]:Hi(Object.values(De.colors))},intents:{...De.intents,[Q]:{intent:"start",nonce:0}}}}))},[N,tt]),pe=k.useCallback(async(Q,V)=>{const re=new Date,te=String(re.getHours()).padStart(2,"0"),se=String(re.getMinutes()).padStart(2,"0"),le=String(re.getSeconds()).padStart(2,"0"),ve=await xm(e,{title:`Shell ${te}:${se}:${le}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(ve),ke(ve.id,Q,V),ve.id},[e,f,ke]);k.useEffect(()=>{const Q=Rp();Z.current=Q;const V=te=>{var se;if(te.t==="hello"){const le=Ie.current.get(te.groupId);if(le&&le.ownerWindowId===te.from)Q.post({t:"group-handoff",to:te.from,groupId:te.groupId,group:le});else{const ve=x.current.find(Ce=>Ce.id===te.groupId);ve&&ve.ownerWindowId===te.from&&Q.post({t:"group-handoff",to:te.from,groupId:te.groupId,group:ve})}}else if(te.t==="group-return"||te.t==="bye")if(te.t==="group-return"){const le=te.group;le&&le.id===te.groupId&&(Ie.current.delete(te.groupId),X.current.delete(te.from),te.projectId&&te.projectId!==e&&cz(te.projectId,te.groupId),p(ve=>{const Ce=ve.find(Qe=>Qe.id===te.groupId),De={...le,ownerWindowId:zt};return Ce?ve.map(Qe=>Qe.id===te.groupId?De:Qe):[...ve,De]}))}else X.current.delete(te.from),p(le=>le.map(ve=>ve.ownerWindowId===te.from?{...ve,ownerWindowId:zt}:ve));else if(te.t==="group-close")Ie.current.delete(te.groupId),p(le=>le.filter(ve=>ve.id!==te.groupId));else if(te.t==="heartbeat")X.current.set(te.from,Date.now());else if(te.t==="group-update"){const le=te.patch;p(ve=>ve.map(Ce=>Ce.id===te.groupId?{...Ce,...le}:Ce))}else if(te.t==="dock-probe"){if(document.visibilityState!=="visible")return;const le=Lu(te.x,te.y),ve=Du(le)?ju(le.x,le.y):null;if(ve){const Ce=ge.current;(!Ce||Ce.zone!==ve.zone||Ce.groupId!==ve.groupId||Ce.path.join(".")!==ve.path.join("."))&&me({rect:ve.rect,zone:ve.zone,path:ve.path,groupId:ve.groupId}),xe.current&&clearTimeout(xe.current),xe.current=setTimeout(()=>me(null),800),Q.post({t:"dock-probe-result",from:zt,to:te.from,hit:!0,focusAt:he.current})}else ge.current&&me(null),Q.post({t:"dock-probe-result",from:zt,to:te.from,hit:!1,focusAt:he.current})}else if(te.t==="dock-end")me(null);else if(te.t==="dock-commit"&&te.to===zt){const le=Lu(te.x,te.y),ve=Du(le)?ju(le.x,le.y):null,Ce=ve&&ve.zone?ve:(se=ge.current)!=null&&se.zone?ge.current:null;let De=!1;const Qe=x.current.filter(ut=>(ut.ownerWindowId||zt)===zt);if(Ce&&Ce.zone&&!ni(Qe,te.sessionId)){const ut=x.current.find(Je=>Je.id===Ce.groupId),ot=ut?al(ut.root,Ce.path):null;if(ut&&ot&&ot.kind==="stack"){De=!0;const Je=Ce.zone,qe=Ce.path;u.current+=1;const ft=u.current;p(lt=>lt.map(xt=>{if(xt.id!==ut.id)return xt;const pt=Je==="center"?$i(xt.root,qe,te.sessionId):Pa(xt.root,qe,Je,yr([te.sessionId])),st=Bs(pt,te.sessionId),ht={...xt.colors};ht[te.sessionId]||(ht[te.sessionId]=te.color||Hi(Object.values(ht)));const Re={...xt.intents,[te.sessionId]:te.intentInfo??{intent:"open",nonce:0}};return{...xt,root:st,colors:ht,intents:Re,z:ft,minimized:!1}}))}}me(null),Q.post({t:"dock-commit-ack",from:zt,to:te.from,sessionId:te.sessionId,accepted:De})}},re=Q.subscribe(V);return()=>{re(),Q.close(),Z.current=null}},[e]),k.useEffect(()=>{const Q=Date.now();for(const V of c.groups)V.ownerWindowId&&V.ownerWindowId!==zt&&X.current.set(V.ownerWindowId,Q)},[]),k.useEffect(()=>{const Q=async()=>{var Ce;const re=Date.now(),te=[];for(const[De,Qe]of X.current.entries())re-Qe>iS&&te.push(De);if(te.length===0)return;const se=await oS(),le=te.filter(De=>se.has(De)?(X.current.set(De,re),!1):!0);if(le.length===0)return;for(const De of le)X.current.delete(De);const ve=new Set(le);for(const De of x.current)De.ownerWindowId&&ve.has(De.ownerWindowId)&&Ie.current.delete(De.id);for(const De of le){const Qe=x.current.filter(ut=>ut.ownerWindowId===De).map(ut=>ut.id);Qe.length>0&&((Ce=Z.current)==null||Ce.post({t:"group-reclaimed",popoutId:De,groupIds:Qe,reason:"heartbeat-timeout"}))}p(De=>De.map(Qe=>Qe.ownerWindowId&&le.includes(Qe.ownerWindowId)?{...Qe,ownerWindowId:zt}:Qe))},V=setInterval(()=>{Q()},Mp);return()=>clearInterval(V)},[]);const Ne=k.useCallback((Q,V)=>{i({type:"session:terminal-input",sessionId:Q,input:V})},[i]),Le=k.useCallback(()=>{var re,te;const Q=x.current.filter(se=>(se.ownerWindowId||zt)===zt).slice().sort((se,le)=>le.z-se.z),V=[];for(const se of Q)for(const le of dn(se.root)){const ve=((re=b.current.find(Ce=>Ce.id===le))==null?void 0:re.title)||((te=y.current[le])==null?void 0:te.title)||le;V.push({sessionId:le,label:ve})}return V},[]),ze=k.useCallback(async(Q,V)=>{const te=x.current.filter(le=>!le.minimized&&(le.ownerWindowId||zt)===zt).reduce((le,ve)=>le&&le.z>=ve.z?le:ve,null),se=await xm(e,{title:V||"",description:Q,use_worktree:!1,memory_inject_mode:"none"});f==null||f(se),ke(se.id,(te==null?void 0:te.id)??null)},[e,f,ke]),Ke=k.useMemo(()=>({openOrFocus:N,close:O,focus:D,minimize:z,restore:P,isOpen:F,recallPopout:Pe,closeGroup:H,minimizeGroup:$,restoreGroup:q,setGroupGeometry:Y,setSplitSizes:I,setActiveTab:B,applyLayoutPreset:U,reorderTab:J,beginTabDrag:W,dockGroup:ee,popOutGroup:be,createRawShellTab:pe,sendToSession:Ne,listOpenTerminals:Le,sendToNewTerminal:ze}),[N,O,D,z,P,F,Pe,H,$,q,Y,I,B,U,J,W,ee,be,pe,Ne,Le,ze]),Ve=k.useMemo(()=>{const Q={};for(const V of d){const te=(V.ownerWindowId||zt)!==zt?"popped":V.minimized?"minimized":"floating";for(const se of dn(V.root))Q[se]=te}return Q},[d]);k.useEffect(()=>{const Q=V=>{const re=/Mac|iPhone|iPad|iPod/.test(navigator.platform),te=re?V.metaKey:V.ctrlKey,se=re?V.ctrlKey:V.metaKey;if(!te||se||V.altKey||V.shiftKey||V.key.toLowerCase()!=="t")return;V.preventDefault();const ve=x.current.filter(Ce=>!Ce.minimized&&(Ce.ownerWindowId||zt)===zt).reduce((Ce,De)=>Ce&&Ce.z>=De.z?Ce:De,null);pe((ve==null?void 0:ve.id)??null).catch(()=>{})};return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[pe]);const de=k.useMemo(()=>{const Q=new Map;for(const V of Object.values(_))Q.set(V.id,V);for(const V of s)Q.set(V.id,V);return Q},[s,_]),fe=d.filter(Q=>!Q.minimized&&(Q.ownerWindowId||zt)===zt),ce=fe.reduce((Q,V)=>V.z>Q.z?{id:V.id,z:V.z}:Q,{id:null,z:-1/0}).id;return n.jsx(Op.Provider,{value:Ke,children:n.jsxs(lS.Provider,{value:Ve,children:[m,(()=>{const Q=new Map(fe.slice().sort((V,re)=>V.z-re.z).map((V,re)=>[V.id,re+1]));return fe.map(V=>{const re=fe.filter(te=>te.id!==V.id).map(({x:te,y:se,w:le,h:ve})=>({x:te,y:se,w:le,h:ve}));return n.jsx(XO,{group:V,sessionsById:de,neighbors:re,isTopmost:V.id===ce,zIndex:Q.get(V.id)??1,sendMessage:i,subscribeBinary:a,onEvent:h},V.id)})})(),C&&C.hoveredRect&&n.jsx(pl,{targetRect:C.hoveredRect,activeZone:C.zone}),G&&n.jsx(pl,{targetRect:G.rect,activeZone:G.zone})]})})}function hz(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const fz={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",stopped:"bg-amber-100 text-amber-700"},mz={floating:"bg-accent/10 text-accent",minimized:"bg-warm-200 text-warm-600",popped:"bg-violet-500/15 text-violet-500"};function pz({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:h,projectDefaultBranch:f,onAddSession:m,onUpdateSession:o,onStopSession:c,onDeleteSession:d,onCleanupSession:p}){const{t:u}=dt(),{openOrFocus:x,recallPopout:b}=cS(),C=sz(),[S,g]=k.useState(!1),[_,w]=k.useState(!1),[y,E]=k.useState(null),[T,j]=k.useState(!1),[R,N]=k.useState(null),[D,A]=k.useState([]),[O,z]=k.useState(""),[P,F]=k.useState(null);k.useEffect(()=>{let W=!1;return sp().then(oe=>{W||A(oe)}).catch(()=>{}),()=>{W=!0}},[]),k.useEffect(()=>{if(!a)return;let W=!1;return Xw(e).then(oe=>{W||z(oe.branch||"")}).catch(()=>{}),()=>{W=!0}},[e,a]);const H=k.useMemo(()=>{const W=new Map;for(const oe of D)W.set(oe.id,oe);return W},[D]),$=k.useMemo(()=>y?s.find(W=>W.id===y)??null:null,[y,s]),q=k.useMemo(()=>{if($)return{title:$.title,description:$.description??"",cliTool:$.cli_tool??"",useWorktree:$.use_worktree===1,memoryInjectMode:$.memory_inject_mode??"none",memoryNodeIds:iO($.memory_node_ids??null),memoryRawFilePaths:hz($.memory_raw_file_paths??null),tagId:$.tag_id??null}},[$]),Y=k.useCallback(()=>{E(null),N(null),g(W=>!W)},[]),I=k.useCallback(W=>{g(!1),N(null),E(W)},[]),B=k.useCallback(()=>{g(!1),E(null),N(null)},[]),U=k.useCallback(async(W,oe,ee,Z,X,G,me,ge)=>{w(!0);try{const xe=await xm(e,{title:W,description:oe||void 0,cli_tool:ee,use_worktree:Z,memory_inject_mode:X,memory_node_ids:G,memory_raw_file_paths:me,tag_id:ge??null});m(xe),g(!1)}finally{w(!1)}},[e,m]),J=k.useCallback(async(W,oe,ee,Z,X,G,me,ge)=>{if(y){j(!0),N(null);try{const xe=await S4(y,{title:W,description:oe||void 0,cli_tool:ee,use_worktree:Z,memory_inject_mode:X,memory_node_ids:G,memory_raw_file_paths:me,tag_id:ge??null});o(xe),E(null)}catch(xe){N(xe instanceof Error?xe.message:String(xe))}finally{j(!1)}}},[y,o]);return n.jsxs("div",{className:"space-y-4 animate-fade-in min-h-[50vh]",onContextMenu:W=>{hi(W)||(W.preventDefault(),F({x:W.clientX,y:W.clientY,sessionId:null}))},children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:u("tabs.sessions")}),n.jsxs("button",{onClick:Y,className:"btn-primary text-xs py-2",disabled:_,children:["+ ",u("session.new")]})]}),S&&n.jsx(wy,{projectId:e,onSave:U,onCancel:B,projectCliTool:i,isGitRepo:a,projectUseWorktree:h}),q&&y&&n.jsxs("div",{className:"space-y-2",children:[n.jsx(wy,{projectId:e,initial:q,onSave:J,onCancel:B,projectCliTool:i,isGitRepo:a},y),(T||R)&&n.jsxs("div",{className:"text-xs px-1",children:[T&&n.jsx("span",{className:"text-warm-500",children:u("session.saving")||"saving…"}),R&&n.jsx("span",{className:"text-status-error",children:R})]})]}),s.length===0&&!S?n.jsx("div",{className:"card",children:n.jsx(Vi,{icon:dl,title:u("session.empty"),description:u("session.emptyHint")})}):n.jsx("div",{className:"space-y-3",children:s.map((W,oe)=>{const ee=["pending","failed","stopped","completed"].includes(W.status),Z=W.status==="running",X=W.status!=="running",G=["stopped","failed","completed"].includes(W.status)&&(W.cli_tool??"claude")==="claude"&&!!W.worktree_path,me=y===W.id,ge=C[W.id]??"closed",xe=ge==="popped";return n.jsx("div",{className:`card overflow-hidden animate-slide-up ${me?"border-l-4 border-accent bg-warm-100/30":""}`,style:{animationDelay:`${oe*50}ms`},onContextMenu:he=>{hi(he)||(he.preventDefault(),he.stopPropagation(),F({x:he.clientX,y:he.clientY,sessionId:W.id}))},children:n.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>xe?b(W.id):x(W.id,"open"),children:n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[W.tag_id&&H.get(W.tag_id)&&n.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium",style:{backgroundColor:`${H.get(W.tag_id).color}22`,color:H.get(W.tag_id).color},children:[n.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:H.get(W.tag_id).color}}),H.get(W.tag_id).name]}),n.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:W.title}),n.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-semibold uppercase ${fz[W.status]||""}`,children:u(`status.${W.status}`)||W.status}),ge!=="closed"&&n.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium ${mz[ge]}`,title:xe?u("session.dock.poppedHint"):void 0,children:[xe&&n.jsx(li,{size:10}),u(`session.windowState.${ge}`)]})]}),W.description&&n.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:W.description}),n.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[n.jsx("span",{className:"text-2xs text-warm-300",children:W.cli_tool||"claude"}),(W.branch_name||a&&(O||f))&&n.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[n.jsx(Ga,{size:12}),W.branch_name||O||f]})]})]}),n.jsxs("div",{className:"flex gap-1",onClick:he=>he.stopPropagation(),children:[xe&&n.jsx("button",{onClick:()=>b(W.id),className:"p-1.5 text-violet-500 hover:bg-violet-500/10 rounded transition-colors",title:u("session.recallToMain"),children:n.jsx(qi,{size:16})}),ee&&n.jsx("button",{onClick:()=>x(W.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded transition-colors",title:u("session.start"),children:n.jsx(kr,{size:16})}),G&&n.jsx("button",{onClick:()=>x(W.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded transition-colors",title:u("session.resumeHint")||u("session.resume"),children:n.jsx(ui,{size:16})}),n.jsx("button",{onClick:()=>I(W.id),disabled:!X,className:"p-1.5 text-warm-500 hover:text-warm-800 hover:bg-warm-100 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-warm-500",title:u(X?"session.edit":"session.editDisabledRunning"),children:n.jsx(im,{size:16})}),Z&&n.jsx("button",{onClick:()=>c(W.id),className:"p-1.5 text-amber-600 hover:bg-amber-50 rounded transition-colors",title:u("session.stop"),children:n.jsx(Ki,{size:16})}),W.status!=="running"&&(!!W.worktree_path||!!W.branch_name)&&n.jsx("button",{onClick:()=>{const he=W.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",W.branch_name)):!1;p(W.id,he)},className:"p-1.5 text-warm-400 hover:text-amber-600 rounded transition-colors",title:u("session.cleanup"),children:n.jsx(pu,{size:16})}),n.jsx("button",{onClick:()=>d(W.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded transition-colors",title:u("session.delete"),children:n.jsx(Ln,{size:16})})]})]})})},W.id)})}),P&&(()=>{const W=()=>F(null),oe=P.sessionId?s.find(Ie=>Ie.id===P.sessionId):void 0;if(!oe)return n.jsx(Cr,{x:P.x,y:P.y,onClose:W,children:n.jsxs("button",{type:"button",onClick:()=>{E(null),N(null),g(!0)},className:an,children:[n.jsx(mn,{size:14}),u("session.new")]})});const ee=["pending","failed","stopped","completed"].includes(oe.status),Z=oe.status==="running",X=oe.status!=="running",G=["stopped","failed","completed"].includes(oe.status)&&(oe.cli_tool??"claude")==="claude"&&!!oe.worktree_path,me=oe.status!=="running"&&(!!oe.worktree_path||!!oe.branch_name),ge=C[oe.id]??"closed",xe=ge==="popped",he=u(xe?"session.recallToMain":ge==="minimized"?"session.restoreWindow":ge==="floating"?"session.focusWindow":"session.openWindow");return n.jsxs(Cr,{x:P.x,y:P.y,onClose:W,children:[n.jsxs("button",{type:"button",onClick:()=>xe?b(oe.id):x(oe.id,"open"),className:an,children:[xe?n.jsx(qi,{size:14}):n.jsx(dl,{size:14}),he]}),ee&&n.jsxs("button",{type:"button",onClick:()=>x(oe.id,"start"),className:an,children:[n.jsx(kr,{size:14}),u("session.start")]}),G&&n.jsxs("button",{type:"button",onClick:()=>x(oe.id,"resume"),className:an,title:u("session.resumeHint")||u("session.resume"),children:[n.jsx(ui,{size:14}),u("session.resume")]}),X&&n.jsxs("button",{type:"button",onClick:()=>I(oe.id),className:an,children:[n.jsx(im,{size:14}),u("session.edit")]}),Z&&n.jsxs("button",{type:"button",onClick:()=>c(oe.id),className:an,children:[n.jsx(Ki,{size:14}),u("session.stop")]}),me&&n.jsxs("button",{type:"button",onClick:()=>{const Ie=oe.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",oe.branch_name)):!1;p(oe.id,Ie)},className:an,children:[n.jsx(pu,{size:14}),u("session.cleanup")]}),n.jsx(z_,{}),n.jsxs("button",{type:"button",onClick:()=>d(oe.id),className:Ep,children:[n.jsx(Ln,{size:14}),u("session.delete")]})]})})()]})}const Ru={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"}},gz=Object.keys(Ru);function Fa(e){const s=Ru[e]||Ru.default;return`${s.bg} ${s.text}`}function Bp({src:e,alt:s,onClose:i}){return k.useEffect(()=>{const a=h=>{h.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),en.createPortal(n.jsxs("div",{className:"fixed inset-0 z-tooltip flex items-center justify-center p-6",style:{backgroundColor:"rgba(0,0,0,0.85)"},onClick:i,children:[n.jsx("button",{type:"button",onClick:i,className:"absolute top-4 right-4 h-9 w-9 rounded-full bg-white/10 text-white flex items-center justify-center hover:bg-white/20 transition-colors","aria-label":"close",children:n.jsx(Jt,{size:18})}),n.jsx("img",{src:e,alt:s,className:"max-w-full max-h-full object-contain rounded-lg",onClick:a=>a.stopPropagation()})]}),document.body)}function Pm({anchorRef:e,width:s,onClose:i,className:a,style:h,children:f}){const m=k.useRef(null),[o,c]=k.useState(null);return k.useLayoutEffect(()=>{const d=e.current;if(!d)return;const p=d.getBoundingClientRect();let u=p.left;u+s>window.innerWidth-8&&(u=Math.max(8,window.innerWidth-8-s)),u<8&&(u=8),c({top:p.bottom+4,left:u})},[e,s]),k.useEffect(()=>{const d=u=>{var b,C;const x=u.target;(b=m.current)!=null&&b.contains(x)||(C=e.current)!=null&&C.contains(x)||i()},p=()=>i();return document.addEventListener("mousedown",d),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("mousedown",d),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[i,e]),o?en.createPortal(n.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...h},children:f}),document.body):null}const qy={pending:"bg-warm-200 text-warm-500",in_progress:"bg-blue-500/10 text-blue-600",done:"bg-emerald-500/10 text-emerald-600",moved:"bg-purple-500/10 text-purple-600"},Ky={0:{label:"—",style:"text-warm-300"},1:{label:"●",style:"text-warm-500"},2:{label:"●●",style:"text-amber-500"},3:{label:"●●●",style:"text-red-500"}};function xz({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:c}){var fe,ce;const{t:d}=dt(),[p,u]=k.useState(!1),[x,b]=k.useState(!1),[C,S]=k.useState(!1),g=k.useRef(null),_=k.useRef(null),[w,y]=k.useState({top:0,left:0}),[E,T]=k.useState(e.title),[j,R]=k.useState(e.description??""),[N,D]=k.useState(e.priority),[A,O]=k.useState(e.due_date??""),[z,P]=k.useState(e.status),[F,H]=k.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[$,q]=k.useState(""),[Y,I]=k.useState(!1),[B,U]=k.useState(null),[J,W]=k.useState(null),oe=k.useRef(null),ee=k.useRef(null),[Z,X]=k.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),G=k.useRef(null);k.useEffect(()=>{T(e.title),R(e.description??""),D(e.priority),O(e.due_date??""),P(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{X(e.images?JSON.parse(e.images):[])}catch{X([])}},[e]);const me=F,ge=e.status==="moved",xe=e.due_date&&new Date(e.due_date)<new Date&&!ge&&e.status!=="done",he=k.useCallback(Q=>{a(e.id,Q)},[e.id,a]),Ie=()=>{const Q=E.trim();Q&&Q!==e.title?he({title:Q}):T(e.title)},Fe=()=>{const Q=j.trim();Q!==(e.description??"")&&he({description:Q||void 0})},be=Q=>{D(Q),Q!==e.priority&&he({priority:Q})},Ue=Q=>{O(Q),Q!==(e.due_date??"")&&he({due_date:Q||void 0})},Pe=Q=>{const V=Q;P(V),V!==e.status&&he({status:V})},tt=Q=>{H(Q);const V=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(Q)!==JSON.stringify(V)&&he({tags:Q.length>0?JSON.stringify(Q):void 0})},ke=Q=>{var re;const V=Q.trim();if(V&&!F.includes(V)&&(tt([...F,V]),!s.has(V)&&c)){const te=["blue","green","orange","purple","pink","red","yellow","brown"],se=te[s.size%te.length];c(V,{color:se})}q(""),(re=oe.current)==null||re.focus()},pe=Q=>tt(F.filter(V=>V!==Q)),Ne=i.filter(Q=>!F.includes(Q)&&(!$||Q.toLowerCase().includes($.toLowerCase()))),Le=k.useCallback(Q=>{const V=Array.from(Q).filter(se=>se.type.startsWith("image/")),re=[];let te=0;for(const se of V){const le=new FileReader;le.onload=()=>{re.push({name:se.name,data:le.result}),te++,te===V.length&&C1(e.id,re).then(ve=>X(ve.images))},le.readAsDataURL(se)}},[e.id]),ze=k.useCallback(Q=>{var te;const V=(te=Q.clipboardData)==null?void 0:te.items;if(!V)return;const re=[];for(let se=0;se<V.length;se++)if(V[se].type.startsWith("image/")){const le=V[se].getAsFile();le&&re.push(le)}re.length!==0&&(Q.preventDefault(),Le(re))},[Le]),Ke=k.useCallback(Q=>{var V;Q.preventDefault(),Q.stopPropagation(),(V=Q.dataTransfer)!=null&&V.files&&Le(Q.dataTransfer.files)},[Le]),Ve=k.useCallback(Q=>{j1(e.id,Q).then(()=>{X(V=>V.filter(re=>re.id!==Q))})},[e.id]),de=k.useCallback(()=>{if(!g.current)return;const Q=g.current.getBoundingClientRect(),V=window.innerWidth,re=window.innerHeight;let te=Q.bottom+4;const se=_.current;if(se){const le=se.offsetWidth,ve=se.offsetHeight;let Ce=Q.right-le;Ce<8&&(Ce=8),Ce+le>V-8&&(Ce=V-8-le),te+ve>re-8&&(te=Q.top-ve-4),y({top:te,left:Ce}),S(!0)}else y({top:te,left:Math.max(8,Q.right-180)})},[]);return k.useEffect(()=>{if(!p){S(!1);return}de();const Q=requestAnimationFrame(de),V=re=>{var se,le;const te=re.target;(se=g.current)!=null&&se.contains(te)||(le=_.current)!=null&&le.contains(te)||u(!1)};return document.addEventListener("mousedown",V),window.addEventListener("scroll",de,!0),window.addEventListener("resize",de),()=>{cancelAnimationFrame(Q),document.removeEventListener("mousedown",V),window.removeEventListener("scroll",de,!0),window.removeEventListener("resize",de)}},[p,de]),n.jsxs("div",{className:`${ge?"opacity-50":""}`,style:{borderBottom:"1px solid var(--color-border-muted)"},children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg transition-colors hover:bg-warm-50 cursor-pointer",onDoubleClick:()=>b(!x),children:[n.jsx(Ns,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${x?"rotate-90":""}`,onClick:Q=>{Q.stopPropagation(),b(!x)}}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("span",{className:"text-sm font-medium truncate block",style:{color:"var(--color-text-primary)"},children:e.title}),ge&&e.converted_type&&n.jsxs("span",{className:"text-2xs text-purple-500",children:["→ ",e.converted_type==="todo"?d("planner.movedToTodo"):e.converted_type==="session"?d("planner.movedToSession"):d("planner.movedToSchedule")]}),e.source_discussion_id&&n.jsxs(Pn,{to:`/projects/${e.project_id}/discussions/${e.source_discussion_id}`,onClick:Q=>Q.stopPropagation(),className:"inline-flex items-center gap-1 text-2xs text-accent hover:underline mt-0.5",title:d("planner.fromDiscussion"),children:[n.jsx(EE,{size:11}),d("planner.fromDiscussion")]})]}),n.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[Z.length>0&&n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-warm-100 text-warm-500 whitespace-nowrap",children:[n.jsx(Ha,{size:10}),Z.length]}),me.map(Q=>n.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium whitespace-nowrap ${Fa(s.get(Q)||"default")}`,children:Q},Q))]}),n.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:n.jsx("span",{className:`text-xs font-medium ${((fe=Ky[e.priority])==null?void 0:fe.style)??"text-warm-300"}`,children:((ce=Ky[e.priority])==null?void 0:ce.label)??"—"})}),n.jsx("div",{className:"hidden md:block w-20 text-right flex-shrink-0",children:e.due_date?n.jsx("span",{className:`text-xs ${xe?"text-red-500 font-medium":"text-warm-500"}`,children:new Date(e.due_date).toLocaleDateString(void 0,{month:"numeric",day:"numeric"})}):n.jsx("span",{className:"text-xs text-warm-300",children:d("planner.noDueDate")})}),n.jsx("div",{className:"w-16 flex-shrink-0",children:n.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${qy[e.status]||qy.pending}`,children:d(`plannerStatus.${e.status}`)})}),n.jsxs("div",{className:"w-8 flex-shrink-0",children:[n.jsx("button",{ref:g,onClick:Q=>{Q.stopPropagation(),u(!p)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:n.jsx(Xm,{size:14})}),p&&en.createPortal(n.jsxs("div",{ref:_,className:`fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated${C?" animate-scale-in":""}`,style:{top:w.top,left:w.left,opacity:C?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>u(!1),children:[!ge&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:f,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:[n.jsx(Pw,{size:12})," ",d("planner.convertToTask")]}),n.jsxs("button",{onClick:m,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:[n.jsx(ai,{size:12})," ",d("planner.convertToSchedule")]}),n.jsxs("button",{onClick:o,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:[n.jsx(di,{size:12})," ",d("planner.convertToTerminal")]})]}),n.jsxs("button",{onClick:()=>{confirm(d("planner.deleteConfirm"))&&h()},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-red-500 hover:bg-red-50 rounded-md transition-colors text-left",children:[n.jsx(Ln,{size:12})," ",d("planner.delete")]})]}),document.body)]})]}),x&&n.jsx("div",{className:"px-4 pb-3 pt-1 ml-8 animate-fade-in",children:n.jsxs("div",{className:"rounded-lg px-4 py-3 space-y-3",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[n.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:E,onChange:Q=>T(Q.target.value),onBlur:Ie,onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),Ie(),Q.target.blur())}}),n.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:d("plannerForm.descPlaceholder"),value:j,onChange:Q=>R(Q.target.value),onPaste:ze,onDrop:Ke,onDragOver:Q=>{Q.preventDefault(),Q.stopPropagation()},onBlur:Fe}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[n.jsxs("button",{type:"button",onClick:()=>{var Q;return(Q=G.current)==null?void 0:Q.click()},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[n.jsx(Ha,{size:12}),d("plannerForm.addImage")]}),n.jsx("span",{className:"text-[10px] text-warm-300",children:d("plannerForm.pasteHint")})]}),n.jsx("input",{ref:G,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:Q=>{Q.target.files&&Le(Q.target.files),Q.target.value=""}}),Z.length>0&&n.jsx("div",{className:"flex flex-wrap gap-2",children:Z.map(Q=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:wu(e.id,Q.id),alt:Q.originalName,onClick:()=>W(wu(e.id,Q.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),n.jsx("button",{type:"button",onClick:()=>Ve(Q.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:Q.originalName})})]},Q.id))})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.tags")}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(Q=>n.jsxs("div",{className:"relative",children:[n.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-2xs font-medium cursor-pointer hover:ring-1 hover:ring-warm-400 transition-all ${Fa(s.get(Q)||"default")}`,onClick:V=>{ee.current=V.currentTarget,U(B===Q?null:Q)},children:[Q,n.jsx("button",{onClick:V=>{V.stopPropagation(),pe(Q)},className:"opacity-60 hover:opacity-100",children:n.jsx(Jt,{size:9})})]}),B===Q&&n.jsxs(Pm,{anchorRef:ee,width:180,onClose:()=>U(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[n.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:d("plannerTag.color")}),n.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:gz.map(V=>n.jsx("button",{onClick:async()=>{c&&await c(Q,{color:V}),U(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(Q)===V?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:d(`plannerTag.color.${V}`),children:n.jsx("div",{className:`w-5 h-5 rounded ${Ru[V].swatch}`})},V))})]})]},Q)),n.jsxs("div",{className:"relative",children:[n.jsx("input",{ref:oe,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:$,onChange:Q=>{q(Q.target.value),I(!0)},onKeyDown:Q=>{(Q.key==="Enter"||Q.key===",")&&$.trim()&&(Q.preventDefault(),ke($.replace(",",""))),Q.key==="Backspace"&&!$&&F.length>0&&pe(F[F.length-1])},onFocus:()=>I(!0),onBlur:()=>setTimeout(()=>I(!1),150)}),Y&&Ne.length>0&&n.jsx(Pm,{anchorRef:oe,width:160,onClose:()=>I(!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:Ne.slice(0,8).map(Q=>n.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>ke(Q),children:n.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium ${Fa(s.get(Q)||"default")}`,children:Q})},Q))})]})]})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.priority")}),n.jsxs("select",{className:"input-field text-xs w-full py-1",value:N,onChange:Q=>be(Number(Q.target.value)),children:[n.jsx("option",{value:0,children:d("plannerForm.priorityLow")}),n.jsx("option",{value:1,children:d("plannerForm.priorityNormal")}),n.jsx("option",{value:2,children:d("plannerForm.priorityHigh")}),n.jsx("option",{value:3,children:d("plannerForm.priorityCritical")})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.dueDate")}),n.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:A,onChange:Q=>Ue(Q.target.value)})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.status")}),n.jsxs("select",{className:"input-field text-xs w-full py-1",value:z,onChange:Q=>Pe(Q.target.value),children:[n.jsx("option",{value:"pending",children:d("plannerStatus.pending")}),n.jsx("option",{value:"in_progress",children:d("plannerStatus.in_progress")}),n.jsx("option",{value:"done",children:d("plannerStatus.done")})]})]})]})]})}),J&&n.jsx(Bp,{src:J,onClose:()=>W(null)})]})}let vz=0;function bz({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:h,onUpdateTag:f}){const{t:m}=dt(),[o,c]=k.useState(""),[d,p]=k.useState(""),[u,x]=k.useState([]),[b,C]=k.useState(""),[S,g]=k.useState(i??""),[_,w]=k.useState(0),[y,E]=k.useState("pending"),[T,j]=k.useState(!1),[R,N]=k.useState(!1),[D,A]=k.useState([]),[O,z]=k.useState([]),[P,F]=k.useState(null),H=k.useRef(null),$=k.useRef(null),q=k.useRef(null),[Y,I]=k.useState(new Map),B=new Map([...e.map(he=>[he.name,he.color]),...Y]),U=["blue","green","orange","purple","pink","red","yellow","brown"];k.useEffect(()=>{var he;if(s){c(s.title),p(s.description??""),x(s.tags?JSON.parse(s.tags):[]),g(s.due_date??""),w(s.priority),E(s.status);try{z(s.images?JSON.parse(s.images):[])}catch{z([])}}(he=H.current)==null||he.focus()},[s]);const J=e.filter(he=>!u.includes(he.name)&&(!b||he.name.toLowerCase().includes(b.toLowerCase()))),W=he=>{var Fe;const Ie=he.trim();Ie&&!u.includes(Ie)&&x(be=>{const Ue=[...be,Ie];if(!B.has(Ie)){const Pe=U[B.size%U.length];I(tt=>new Map([...tt,[Ie,Pe]]))}return Ue}),C(""),N(!0),(Fe=$.current)==null||Fe.focus()},oe=he=>x(u.filter(Ie=>Ie!==he)),ee=k.useCallback(he=>{const Ie=Array.from(he).filter(Fe=>Fe.type.startsWith("image/"));for(const Fe of Ie){const be=new FileReader;be.onload=()=>{const Ue=be.result,Pe=`pending-${++vz}`;A(tt=>[...tt,{id:Pe,name:Fe.name,data:Ue,preview:Ue}])},be.readAsDataURL(Fe)}},[]),Z=k.useCallback(he=>{var be;const Ie=(be=he.clipboardData)==null?void 0:be.items;if(!Ie)return;const Fe=[];for(let Ue=0;Ue<Ie.length;Ue++)if(Ie[Ue].type.startsWith("image/")){const Pe=Ie[Ue].getAsFile();Pe&&Fe.push(Pe)}Fe.length!==0&&(he.preventDefault(),ee(Fe))},[ee]),X=k.useCallback(he=>{var Ie;he.preventDefault(),he.stopPropagation(),(Ie=he.dataTransfer)!=null&&Ie.files&&ee(he.dataTransfer.files)},[ee]),G=he=>A(Ie=>Ie.filter(Fe=>Fe.id!==he)),me=he=>{s&&j1(s.id,he),z(Ie=>Ie.filter(Fe=>Fe.id!==he))},ge=O.length+D.length,xe=async()=>{if(o.trim()){j(!0);try{const he=await a({title:o.trim(),description:d.trim()||void 0,tags:u.length>0?JSON.stringify(u):void 0,due_date:S||void 0,priority:_,...s?{status:y}:{}});if(f&&Y.size>0&&await Promise.all([...Y.entries()].map(([Ie,Fe])=>f(Ie,{color:Fe}))),D.length>0){const Ie=(s==null?void 0:s.id)??(he==null?void 0:he.id);Ie&&await C1(Ie,D.map(Fe=>({name:Fe.name,data:Fe.data})))}}finally{j(!1)}}};return n.jsxs("div",{className:"card p-5 animate-slide-up",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[n.jsx("input",{ref:H,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:he=>c(he.target.value),onKeyDown:he=>{he.key==="Enter"&&he.preventDefault()}}),n.jsx("textarea",{className:"prompt-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:m("plannerForm.descPlaceholder"),value:d,onChange:he=>p(he.target.value),onPaste:Z,onDrop:X,onDragOver:he=>{he.preventDefault(),he.stopPropagation()}}),n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsxs("button",{type:"button",onClick:()=>{var he;return(he=q.current)==null?void 0:he.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[n.jsx(Ha,{size:14}),m("plannerForm.addImage")]}),n.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),n.jsx("input",{ref:q,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:he=>{he.target.files&&ee(he.target.files),he.target.value=""}}),ge>0&&n.jsxs("div",{className:"mb-4",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:m("plannerForm.images")}),n.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",ge,")"]})]}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[O.map(he=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:s?wu(s.id,he.id):"",alt:he.originalName,onClick:()=>s&&F(wu(s.id,he.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),n.jsx("button",{type:"button",onClick:()=>me(he.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:he.originalName})})]},he.id)),D.map(he=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:he.preview,alt:he.name,onClick:()=>F(he.preview),className:"h-20 w-20 object-cover rounded-lg border border-blue-300/30 cursor-zoom-in"}),n.jsx("button",{type:"button",onClick:()=>G(he.id),className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Jt,{size:12,strokeWidth:3})}),n.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:n.jsx("span",{className:"text-[8px] text-white truncate block",children:he.name})})]},he.id))]})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.tags")}),n.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:[u.map(he=>n.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-medium ${Fa(B.get(he)||"default")}`,children:[he,n.jsx("button",{onClick:()=>oe(he),className:"opacity-60 hover:opacity-100",children:n.jsx(Jt,{size:10})})]},he)),n.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[n.jsx("input",{ref:$,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:u.length===0?m("plannerForm.tagsPlaceholder"):"",value:b,onChange:he=>{C(he.target.value),N(!0)},onKeyDown:he=>{(he.key==="Enter"||he.key===",")&&b.trim()&&(he.preventDefault(),W(b.replace(",",""))),he.key==="Backspace"&&!b&&u.length>0&&oe(u[u.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),R&&(J.length>0||b.trim())&&n.jsxs(Pm,{anchorRef:$,width:208,onClose:()=>N(!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:[J.slice(0,10).map(he=>n.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>W(he.name),children:n.jsx("span",{className:`px-2 py-0.5 rounded text-[11px] font-medium ${Fa(he.color)}`,children:he.name})},he.name)),b.trim()&&!e.some(he=>he.name===b.trim())&&n.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>W(b),children:n.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',b.trim(),'"']})})]})]})]})]}),n.jsxs("div",{className:`grid gap-3 mb-4 ${s?"grid-cols-3":"grid-cols-2"}`,children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.dueDate")}),n.jsx("input",{type:"date",className:"input-field text-xs w-full",value:S,onChange:he=>g(he.target.value)})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.priority")}),n.jsxs("select",{className:"input-field text-xs w-full",value:_,onChange:he=>w(Number(he.target.value)),children:[n.jsx("option",{value:0,children:m("plannerForm.priorityLow")}),n.jsx("option",{value:1,children:m("plannerForm.priorityNormal")}),n.jsx("option",{value:2,children:m("plannerForm.priorityHigh")}),n.jsx("option",{value:3,children:m("plannerForm.priorityCritical")})]})]}),s&&n.jsxs("div",{children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.status")}),n.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:he=>E(he.target.value),children:[n.jsx("option",{value:"pending",children:m("plannerStatus.pending")}),n.jsx("option",{value:"in_progress",children:m("plannerStatus.in_progress")}),n.jsx("option",{value:"done",children:m("plannerStatus.done")})]})]})]}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:m("plannerForm.cancel")}),n.jsx("button",{className:"btn-primary text-xs py-2",onClick:xe,disabled:!o.trim()||T,children:m("plannerForm.save")})]}),P&&n.jsx(Bp,{src:P,onClose:()=>F(null)})]})}function fS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:h}){const{t:f}=dt(),[m,o]=k.useState(i||"claude"),[c,d]=k.useState(""),[p,u]=k.useState(!1),[x,b]=k.useState("once"),[C,S]=k.useState("0 0 * * *"),[g,_]=k.useState(""),[w,y]=k.useState(!1),E=async()=>{y(!0);try{s==="todo"?await a({cli_tool:m,max_turns:c?Number(c):void 0}):s==="session"?await a({cli_tool:m,use_worktree:p}):await a({cli_tool:m,schedule_type:x,cron_expression:x==="recurring"?C:void 0,run_at:x==="once"?g:void 0})}finally{y(!1)}};return n.jsx(Un,{open:!0,onClose:h,size:"md",position:"top",animation:"slide-up",children:n.jsxs("div",{className:"card p-6",children:[n.jsx("h3",{className:"text-sm font-semibold mb-4",style:{color:"var(--color-text-primary)"},children:f(s==="todo"?"plannerConvert.toTask":s==="session"?"plannerConvert.toTerminal":"plannerConvert.toSchedule")}),n.jsxs("p",{className:"text-xs text-warm-500 mb-4 truncate",children:['"',e.title,'"']}),n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cliTool")}),n.jsxs("select",{className:"input-field text-xs w-full",value:m,onChange:T=>o(T.target.value),children:[n.jsx("option",{value:"claude",children:"Claude"}),n.jsx("option",{value:"antigravity",children:"Antigravity"}),n.jsx("option",{value:"codex",children:"Codex"})]})]}),s==="todo"&&n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.maxTurns")}),n.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:c,onChange:T=>d(T.target.value)})]}),s==="session"&&n.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:p,onChange:T=>u(T.target.checked)}),n.jsx("span",{className:"text-xs font-medium text-warm-500",children:f("plannerConvert.useWorktree")})]}),s==="schedule"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mb-3",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.scheduleType")}),n.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[n.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${x==="once"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("once"),children:f("plannerConvert.once")}),n.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${x==="recurring"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("recurring"),children:f("plannerConvert.recurring")})]})]}),x==="once"?n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.runAt")}),n.jsx("input",{type:"datetime-local",className:"input-field text-xs w-full",value:g,onChange:T=>_(T.target.value)})]}):n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cronExpression")}),n.jsx("input",{className:"input-field text-xs w-full font-mono",value:C,onChange:T=>S(T.target.value),placeholder:"0 0 * * *"})]})]}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:f("plannerConvert.cancel")}),n.jsx("button",{className:"btn-primary btn-sm",onClick:E,disabled:w||s==="schedule"&&x==="once"&&!g,children:f("plannerConvert.convert")})]})]})})}function hn(e){const s=e.getFullYear(),i=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return`${s}-${i}-${a}`}function Gy(e){return hn(new Date(e))}function Vy(e){return new Date(e.getFullYear(),e.getMonth(),1)}function mS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function Vs(e,s){const i=mS(e);return i.setDate(i.getDate()+s),i}function pS(e){return Vs(e,-e.getDay())}function yz(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function wz(e,s,i,a){if(e==="resize-end")return{startKey:s.startKey,endKey:i<s.startKey?s.startKey:i};if(e==="resize-start")return{startKey:i>s.endKey?s.endKey:i,endKey:s.endKey};const h=yz(a,i),f=m=>hn(Vs(new Date(m+"T00:00"),h));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function _z(e,s){if(e==="day"){const f=mS(s);return{rangeStart:hn(f),rangeEnd:hn(Vs(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=pS(s),m=Array.from({length:7},(o,c)=>Vs(f,c));return{rangeStart:hn(f),rangeEnd:hn(Vs(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=Vy(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:hn(f),rangeEnd:hn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=Vy(s),a=Vs(i,-i.getDay()),h=Array.from({length:42},(f,m)=>Vs(a,m));return{rangeStart:hn(a),rangeEnd:hn(Vs(a,42)),gridDays:h,cols:7,dimOutOfMonth:!0}}function gS(e,s){return k.useMemo(()=>_z(e,s),[e,s])}function xS(e,s,i){const a=new Date(e);return s==="month"||s==="table"?a.setMonth(a.getMonth()+i):s==="week"?a.setDate(a.getDate()+7*i):a.setDate(a.getDate()+i),a}function vS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=pS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${Vs(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function bS(){const{lang:e}=dt();return k.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>Vs(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const Sz=420,kz=140,Cz=220,jz=26,Kf=16,Yy=2;function Ez(e,s){if(!s.length)return{placed:[],laneCount:0};const i=hn(e[0]),a=hn(e[e.length-1]),h=s.filter(o=>o.startKey<=a&&o.endKey>=i).map(o=>{const c=o.startKey<i?i:o.startKey,d=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(p=>hn(p)===c),endCol:e.findIndex(p=>hn(p)===d),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,c)=>o.startCol-c.startCol||c.endCol-c.startCol-(o.endCol-o.startCol)),f=[];return{placed:h.map(o=>{let c=0;for(;c<f.length&&f[c]>=o.startCol;)c++;return f[c]=o.endCol,{...o,lane:c}}),laneCount:f.length}}function yS({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:h,todayKey:f,selectedDate:m,chipsByDay:o,maxChips:c,weekdayLabels:d,addItemLabel:p,bars:u,onBarClick:x,onSelectDate:b,onQuickAdd:C,onChipClick:S,onCellContextMenu:g,onChipContextMenu:_,onBarContextMenu:w,onBarDrag:y,onChipDrag:E,monthCellHeight:T=92}){const{lang:j}=dt(),[R,N]=k.useState(null),[D,A]=k.useState(!1),O=k.useRef(null),z=k.useRef(null),P=()=>{z.current&&(clearTimeout(z.current),z.current=null)},F=(Z,X)=>{P(),O.current&&clearTimeout(O.current);const G=X.getBoundingClientRect();O.current=window.setTimeout(()=>N({key:Z,rect:G}),Sz)},H=()=>{O.current&&(clearTimeout(O.current),O.current=null),z.current=window.setTimeout(()=>N(null),kz)};k.useEffect(()=>{if(!R){A(!1);return}const Z=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(Z)},[R]),k.useEffect(()=>()=>{O.current&&clearTimeout(O.current),z.current&&clearTimeout(z.current)},[]),k.useEffect(()=>{if(!R)return;const Z=()=>N(null);return window.addEventListener("scroll",Z,!0),window.addEventListener("resize",Z),()=>{window.removeEventListener("scroll",Z,!0),window.removeEventListener("resize",Z)}},[R]);const $=R?o.get(R.key)??[]:[],[q,Y]=k.useState(null),I=k.useRef(!1),B=4,U=(Z,X)=>{var G,me;return((me=(G=document.elementFromPoint(Z,X))==null?void 0:G.closest("[data-daykey]"))==null?void 0:me.getAttribute("data-daykey"))??null},J=(Z,X,G)=>{Z.preventDefault(),Z.stopPropagation();const me=U(Z.clientX,Z.clientY)??G.origStart,ge=Z.clientX,xe=Z.clientY,he=X!=="move";let Ie=he,Fe={startKey:G.origStart,endKey:G.origEnd};const be=()=>Y({kind:G.kind,entryKey:G.entryKey,curStart:Fe.startKey,curEnd:Fe.endKey,title:G.title,bg:G.bg,fg:G.fg,done:G.done}),Ue=()=>{document.body.style.cursor=he?"ew-resize":"grabbing",document.body.style.userSelect="none"};he&&(Ue(),be());const Pe=ke=>{if(!Ie){if(Math.abs(ke.clientX-ge)<B&&Math.abs(ke.clientY-xe)<B)return;Ie=!0,Ue()}const pe=U(ke.clientX,ke.clientY);pe&&(Fe=wz(X,{startKey:G.origStart,endKey:G.origEnd},pe,me),be())},tt=()=>{window.removeEventListener("pointermove",Pe),window.removeEventListener("pointerup",tt),document.body.style.cursor="",document.body.style.userSelect="",Y(null),Ie&&(I.current=!0,setTimeout(()=>{I.current=!1},0),!(Fe.startKey===G.origStart&&Fe.endKey===G.origEnd)&&(G.kind==="bar"&&G.bar?y==null||y(G.bar,Fe.startKey,Fe.endKey):G.kind==="chip"&&G.chip&&(E==null||E(G.chip,Fe.startKey,Fe.endKey))))};window.addEventListener("pointermove",Pe),window.addEventListener("pointerup",tt)},W=(()=>{const Z=u??[];return q?q.kind==="bar"?Z.map(X=>X.key===q.entryKey?{...X,startKey:q.curStart,endKey:q.curEnd}:X):[...Z,{key:`__drag__${q.entryKey}`,title:q.title,startKey:q.curStart,endKey:q.curEnd,bg:q.bg,fg:q.fg,done:q.done}]:Z})(),oe=(Z,X)=>{const G=hn(Z),me=o.get(G)??[],ge=!a||Z.getMonth()===h,xe=G===f,he=G===m,Ie=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",Fe=e==="month"&&me.length>c;return n.jsxs("div",{"data-daykey":G,onClick:()=>{I.current||b(G)},onContextMenu:g?be=>g(G,be):void 0,onMouseEnter:Fe?be=>F(G,be.currentTarget):void 0,onMouseLeave:Fe?H:void 0,className:`group relative ${Ie} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?T+X:void 0,backgroundColor:he?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:ge?1:.45},children:[n.jsxs("span",{className:"flex items-center gap-1.5",children:[e!=="month"&&n.jsx("span",{className:"text-2xs uppercase",style:{color:"var(--color-text-muted)"},children:Z.toLocaleDateString(j,{weekday:"short"})}),n.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:xe?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:Z.getDate()})]}),n.jsx("button",{onClick:be=>{be.stopPropagation(),C(G)},className:"absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity rounded-md w-5 h-5 flex items-center justify-center hover:bg-theme-hover",title:p,style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:n.jsx(mn,{size:13})}),n.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:X||void 0},children:[me.slice(0,c).map(be=>{if((q==null?void 0:q.kind)==="chip"&&q.entryKey===be.key)return null;const Ue=e==="month"&&!!(be.draggable&&E),Pe={kind:"chip",entryKey:be.key,origStart:G,origEnd:G,title:be.title,bg:be.bg,fg:be.fg,done:be.done,chip:be};return n.jsxs("span",{onClick:tt=>{tt.stopPropagation(),!I.current&&S(be)},onPointerDown:Ue?tt=>J(tt,"move",Pe):void 0,onContextMenu:_?tt=>_(be,tt):void 0,className:`text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity ${Ue?"relative group/chip":""}`,style:{backgroundColor:be.bg,color:be.fg,textDecoration:be.done?"line-through":"none"},title:be.title,children:[be.prefix??"",be.time?`${be.time} `:"",be.title,Ue&&n.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),J(tt,"resize-end",Pe)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 group-hover/chip:opacity-100 cursor-ew-resize rounded-r",style:{backgroundColor:"rgba(127,127,127,0.5)"}})]},be.key)}),me.length>c&&n.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",me.length-c]})]})]},G)},ee=[];if(e==="month")for(let Z=0;Z<s.length;Z+=i)ee.push(s.slice(Z,Z+i));return n.jsxs(n.Fragment,{children:[(e==="month"||e==="week")&&n.jsx("div",{className:"grid gap-px text-2xs uppercase tracking-wider mb-1",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,color:"var(--color-text-muted)"},children:d.map(Z=>n.jsx("div",{className:"px-2 py-1",children:Z},Z))}),e==="month"?n.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:ee.map((Z,X)=>{const{placed:G,laneCount:me}=Ez(Z,W),ge=me*(Kf+Yy);return n.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[Z.map(xe=>oe(xe,ge)),G.map(({bar:xe,startCol:he,endCol:Ie,lane:Fe,contStart:be,contEnd:Ue})=>{const Pe=!!y&&!xe.key.startsWith("__drag__"),tt={kind:"bar",entryKey:xe.key,origStart:xe.startKey,origEnd:xe.endKey,title:xe.title,bg:xe.bg,fg:xe.fg,done:xe.done,bar:xe};return n.jsxs("div",{onClick:ke=>{ke.stopPropagation(),!I.current&&(x==null||x(xe))},onPointerDown:Pe?ke=>J(ke,"move",tt):void 0,onContextMenu:w?ke=>w(xe,ke):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{pointerEvents:q?"none":void 0,left:`calc(${he} / ${i} * 100% + 2px)`,width:`calc(${Ie-he+1} / ${i} * 100% - 4px)`,top:jz+Fe*(Kf+Yy),height:Kf,backgroundColor:xe.bg,color:xe.fg,textDecoration:xe.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:be?0:4,borderBottomLeftRadius:be?0:4,borderTopRightRadius:Ue?0:4,borderBottomRightRadius:Ue?0:4},title:xe.title,children:[be?"◀ ":"",xe.title,Ue?" ▶":"",Pe&&!be&&n.jsx("span",{onPointerDown:ke=>{ke.stopPropagation(),J(ke,"resize-start",tt)},onClick:ke=>ke.stopPropagation(),className:"absolute top-0 left-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}}),Pe&&!Ue&&n.jsx("span",{onPointerDown:ke=>{ke.stopPropagation(),J(ke,"resize-end",tt)},onClick:ke=>ke.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}})]},xe.key)})]},X)})}):n.jsx("div",{className:"grid gap-px rounded-xl overflow-hidden",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:s.map(Z=>oe(Z,0))}),R&&(()=>{const Z=Math.max(R.rect.width,Cz),X=Math.min(Math.max(8,R.rect.left),window.innerWidth-Z-8),G=Math.max(8,Math.min(R.rect.top,window.innerHeight-120)),me=window.innerHeight-G-16,ge=Number(R.key.slice(8,10));return en.createPortal(n.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:P,onMouseLeave:()=>N(null),style:{position:"fixed",left:X,top:G,width:Z,maxHeight:me,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:D?"scale(1)":"scale(0.96)",opacity:D?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[n.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:ge}),n.jsx("div",{className:"flex flex-col gap-0.5",children:$.map(xe=>n.jsxs("span",{onClick:he=>{he.stopPropagation(),S(xe),N(null)},onContextMenu:_?he=>_(xe,he):void 0,className:"text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:xe.bg,color:xe.fg,textDecoration:xe.done?"line-through":"none"},title:xe.title,children:[xe.prefix??"",xe.time?`${xe.time} `:"",xe.title]},xe.key))})]}),document.body)})()]})}const Xy={pending:"bg-warm-200 text-warm-500",in_progress:"bg-blue-500/10 text-blue-600",done:"bg-emerald-500/10 text-emerald-600",moved:"bg-purple-500/10 text-purple-600"};function Nz(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function Lz({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:h,onConvert:f,onDeleteItem:m,onUpdateRange:o}){const{t:c,lang:d}=dt(),[p,u]=k.useState(()=>new Date),[x,b]=k.useState(()=>hn(new Date)),[C,S]=k.useState(null),g=bS(),{gridDays:_,cols:w,dimOutOfMonth:y}=gS(e,p),E=hn(new Date),T=p.getMonth(),j=e==="month"?3:99,R=ee=>u(Z=>xS(Z,e,ee)),N=()=>{u(new Date),b(hn(new Date))},D=vS(p,e,d);k.useEffect(()=>{e==="day"&&b(hn(p))},[e,p]);const A=260,O=760,z=k.useRef(null),[P,F]=k.useState(()=>{const ee=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ee)&&ee>=A&&ee<=O?ee:320});k.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(P))}catch{}},[P]);const H=ee=>{ee.preventDefault();const Z=G=>{var ge;const me=(ge=z.current)==null?void 0:ge.getBoundingClientRect();me&&F(Math.min(O,Math.max(A,me.right-G.clientX)))},X=()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",X),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",Z),window.addEventListener("pointerup",X)},[$,q]=k.useState(new Map);k.useEffect(()=>{q(new Map)},[s]);const Y=k.useMemo(()=>$.size===0?s:s.map(ee=>{const Z=$.get(ee.id);return Z?{...ee,due_date:Z.due_date,end_date:Z.end_date}:ee}),[s,$]),I=k.useCallback((ee,Z,X)=>{q(G=>new Map(G).set(ee,{due_date:Z,end_date:X})),o(ee,Z,X)},[o]),B=ee=>!!(ee.due_date&&ee.end_date&&ee.end_date.slice(0,10)>ee.due_date.slice(0,10)),U=k.useMemo(()=>{const ee=new Map;for(const Z of Y){if(!Z.due_date||e==="month"&&B(Z))continue;const X=Z.due_date.slice(0,10),G=Z.status==="done",me=ee.get(X)??[];me.push({key:Z.id,title:Z.title,bg:"var(--color-bg-secondary)",fg:G?"var(--color-text-muted)":"var(--color-text-secondary)",done:G,payload:Z,draggable:!0}),ee.set(X,me)}return ee},[Y,e]),J=k.useMemo(()=>e!=="month"?[]:Y.filter(B).map(ee=>{const Z=ee.status==="done";return{key:ee.id,title:ee.title,startKey:ee.due_date.slice(0,10),endKey:ee.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:Z?"var(--color-text-muted)":"var(--color-text-secondary)",done:Z,payload:ee}}),[Y,e]),W=k.useMemo(()=>s.filter(ee=>ee.due_date&&ee.due_date.slice(0,10)===x),[s,x]),oe=k.useMemo(()=>s.filter(ee=>!ee.due_date),[s]);return n.jsxs("div",{ref:z,className:"card flex overflow-hidden",style:{minHeight:520},children:[n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[n.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[n.jsx("button",{onClick:()=>R(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:n.jsx(Vm,{size:16})}),n.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:D}),n.jsx("button",{onClick:()=>R(1),className:"btn-ghost p-1.5","aria-label":"next",children:n.jsx(Ns,{size:16})}),n.jsx("button",{onClick:N,className:"btn-ghost text-xs px-2.5 py-1.5",children:c("agenda.today")})]}),n.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:n.jsx(yS,{view:e,gridDays:_,cols:w,dimOutOfMonth:y,monthIdx:T,todayKey:E,selectedDate:x,chipsByDay:U,maxChips:j,weekdayLabels:g,addItemLabel:c("agenda.addItem"),onSelectDate:b,onQuickAdd:a,onChipClick:ee=>h(ee.payload),onCellContextMenu:(ee,Z)=>{Z.preventDefault(),S({x:Z.clientX,y:Z.clientY,dateKey:ee})},bars:J,onBarClick:ee=>h(ee.payload),onBarDrag:(ee,Z,X)=>I(ee.payload.id,Z,X),onChipDrag:(ee,Z,X)=>I(ee.payload.id,Z,X)})})]}),n.jsx("div",{onPointerDown:H,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:c("agenda.resizePanel")}),n.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:P},children:[n.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--color-text-primary)"},children:new Date(x+"T00:00").toLocaleDateString(d,{month:"long",day:"numeric",weekday:"short"})}),n.jsxs("button",{onClick:()=>a(x),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[n.jsx(mn,{size:13}),c("agenda.add")]})]}),n.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[n.jsxs("div",{className:"flex flex-col gap-1.5",children:[W.length===0&&n.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:c("agenda.dayEmpty")}),W.map(ee=>n.jsx(Jy,{item:ee,tagColors:i,onEdit:h,onConvert:f,onDelete:m},ee.id))]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:c("agenda.backlog")}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[oe.length===0&&n.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:c("agenda.backlogEmpty")}),oe.map(ee=>n.jsx(Jy,{item:ee,tagColors:i,onEdit:h,onConvert:f,onDelete:m},ee.id))]})]})]})]}),C&&n.jsx(Cr,{x:C.x,y:C.y,onClose:()=>S(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>a(C.dateKey),children:[n.jsx(mn,{size:14}),c("planner.add")]})})]})}function Jy({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:h}){const{t:f}=dt(),[m,o]=k.useState(!1),[c,d]=k.useState(!1),[p,u]=k.useState({top:0,left:0}),x=k.useRef(null),b=k.useRef(null),C=Nz(e.tags),S=e.status==="moved",g=k.useCallback(()=>{if(!x.current)return;const _=x.current.getBoundingClientRect(),w=window.innerWidth,y=window.innerHeight;let E=_.bottom+4;const T=b.current;if(T){const j=T.offsetWidth,R=T.offsetHeight;let N=_.right-j;N<8&&(N=8),N+j>w-8&&(N=w-8-j),E+R>y-8&&(E=_.top-R-4),u({top:E,left:N}),d(!0)}else u({top:E,left:Math.max(8,_.right-180)})},[]);return k.useEffect(()=>{if(!m){d(!1);return}g();const _=requestAnimationFrame(g),w=y=>{var T,j;const E=y.target;(T=x.current)!=null&&T.contains(E)||(j=b.current)!=null&&j.contains(E)||o(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{cancelAnimationFrame(_),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[m,g]),n.jsxs("div",{className:`group flex items-start gap-2 rounded-lg px-2.5 py-2 ${S?"opacity-50":""}`,style:{backgroundColor:"var(--color-bg-secondary)"},children:[n.jsxs("button",{onClick:()=>i(e),className:"flex-1 text-left min-w-0",children:[n.jsx("div",{className:"text-sm truncate",style:{color:"var(--color-text-primary)",textDecoration:e.status==="done"?"line-through":"none"},children:e.title}),e.description&&n.jsx("div",{className:"text-2xs truncate",style:{color:"var(--color-text-muted)"},children:e.description}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[n.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-2xs font-medium ${Xy[e.status]||Xy.pending}`,children:f(`plannerStatus.${e.status}`)}),C.map(_=>n.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-medium ${Fa(s.get(_)||"default")}`,children:_},_))]})]}),n.jsxs("div",{className:"flex-shrink-0",children:[n.jsx("button",{ref:x,onClick:_=>{_.stopPropagation(),o(!m)},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:n.jsx(Xm,{size:14})}),m&&en.createPortal(n.jsxs("div",{ref:b,className:`fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated${c?" animate-scale-in":""}`,style:{top:p.top,left:p.left,opacity:c?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>o(!1),children:[!S&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>a(e,"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:[n.jsx(Pw,{size:12})," ",f("planner.convertToTask")]}),n.jsxs("button",{onClick:()=>a(e,"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:[n.jsx(ai,{size:12})," ",f("planner.convertToSchedule")]}),n.jsxs("button",{onClick:()=>a(e,"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:[n.jsx(di,{size:12})," ",f("planner.convertToTerminal")]})]}),n.jsxs("button",{onClick:()=>{confirm(f("planner.deleteConfirm"))&&h(e.id)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-red-500 hover:bg-red-50 rounded-md transition-colors text-left",children:[n.jsx(Ln,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const Qy={pending:0,in_progress:1,done:2,moved:3};function Dz({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:h,onDeleteItem:f,onConvertToTodo:m,onConvertToSchedule:o,onConvertToSession:c,onUpdateTag:d,onDeleteTag:p,onExport:u,onImport:x,view:b,onChangeView:C}){const{t:S}=dt(),[g,_]=k.useState(!1),[w,y]=k.useState(null),[E,T]=k.useState(void 0),[j,R]=k.useState(""),[N,D]=k.useState(""),[A,O]=k.useState("created_at"),[z,P]=k.useState("desc"),[F,H]=k.useState(null),[$,q]=k.useState("todo"),[Y,I]=k.useState(!1),[B,U]=k.useState(!1),[J,W]=k.useState(null),oe=k.useRef(null),ee=k.useRef(0),Z=async()=>{if(!(!u||Y)){I(!0);try{await u()}finally{I(!1)}}},X=()=>{var pe;!x||Y||(pe=oe.current)==null||pe.click()},G=async pe=>{var Le;const Ne=(Le=pe.target.files)==null?void 0:Le[0];if(pe.target.value="",!(!Ne||!x)){I(!0);try{await x(Ne)}finally{I(!1)}}},me=pe=>!!(/\.(md|markdown)$/i.test(pe.name)||pe.type==="text/markdown"),ge=pe=>Array.from(pe.dataTransfer.types).includes("Files"),xe=pe=>{!x||Y||ge(pe)&&(pe.preventDefault(),ee.current++,U(!0))},he=pe=>{!x||Y||ge(pe)&&(pe.preventDefault(),pe.dataTransfer.dropEffect="copy")},Ie=pe=>{x&&(pe.preventDefault(),ee.current=Math.max(0,ee.current-1),ee.current===0&&U(!1))},Fe=async pe=>{var Le;if(!x||(pe.preventDefault(),ee.current=0,U(!1),Y))return;const Ne=(Le=pe.dataTransfer.files)==null?void 0:Le[0];if(Ne){if(!me(Ne)){window.alert(S("planner.dropInvalidFile"));return}I(!0);try{await x(Ne)}finally{I(!1)}}},be=k.useMemo(()=>s.map(pe=>pe.name),[s]),Ue=k.useMemo(()=>new Map(s.map(pe=>[pe.name,pe.color])),[s]),Pe=k.useMemo(()=>{let pe=e.filter(Ne=>!(N&&Ne.status!==N||j&&!(Ne.tags?(()=>{try{return JSON.parse(Ne.tags)}catch{return[]}})():[]).includes(j)));return pe=[...pe].sort((Ne,Le)=>{let ze=0;switch(A){case"title":ze=Ne.title.localeCompare(Le.title);break;case"tags":{const Ke=Ne.tags?(()=>{try{return JSON.parse(Ne.tags).join(",")}catch{return""}})():"",Ve=Le.tags?(()=>{try{return JSON.parse(Le.tags).join(",")}catch{return""}})():"";ze=(Ke||"zzz").localeCompare(Ve||"zzz");break}case"priority":ze=Ne.priority-Le.priority;break;case"due_date":{const Ke=Ne.due_date||"9999",Ve=Le.due_date||"9999";ze=Ke.localeCompare(Ve);break}case"status":ze=(Qy[Ne.status]??9)-(Qy[Le.status]??9);break;case"created_at":ze=Ne.created_at.localeCompare(Le.created_at);break}return z==="asc"?ze:-ze}),pe},[e,j,N,A,z]),tt=pe=>{A===pe?P(Ne=>Ne==="asc"?"desc":"asc"):(O(pe),P(pe==="priority"?"desc":"asc"))},ke=({field:pe})=>A!==pe?null:z==="asc"?n.jsx(F5,{size:10,className:"inline ml-0.5"}):n.jsx(O5,{size:10,className:"inline ml-0.5"});return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-5 gap-3 flex-wrap",children:[n.jsxs("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:[S("planner.title"),n.jsx("span",{className:"ml-1 text-warm-400",children:e.length})]}),n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b!=="table"&&n.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(pe=>n.jsx("button",{onClick:()=>C(pe),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:b===pe?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:S(`agenda.view.${pe}`)},pe))}),n.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:j,onChange:pe=>R(pe.target.value),children:[n.jsx("option",{value:"",children:S("planner.filterTag")}),be.map(pe=>n.jsx("option",{value:pe,children:pe},pe))]}),n.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:N,onChange:pe=>D(pe.target.value),children:[n.jsx("option",{value:"",children:S("planner.filterStatus")}),n.jsx("option",{value:"pending",children:S("plannerStatus.pending")}),n.jsx("option",{value:"in_progress",children:S("plannerStatus.in_progress")}),n.jsx("option",{value:"done",children:S("plannerStatus.done")}),n.jsx("option",{value:"moved",children:S("plannerStatus.moved")})]}),u&&n.jsxs("button",{onClick:Z,disabled:Y||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.exportTooltip"),children:[n.jsx(sm,{size:14,className:"inline-block shrink-0"}),S("planner.export")]}),x&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:X,disabled:Y,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.importTooltip"),children:[n.jsx(Gv,{size:14,className:"inline-block shrink-0"}),S("planner.import")]}),n.jsx("input",{ref:oe,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:G})]}),!g&&!w&&n.jsxs("button",{onClick:()=>_(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[n.jsx(mn,{size:14,className:"inline-block shrink-0"}),S("planner.add")]})]})]}),(g||w)&&n.jsx("div",{className:"mb-5",children:n.jsx(bz,{existingTags:s,editItem:w,initialDueDate:E,onSave:async pe=>{if(w){await h(w.id,pe),y(null);return}else{const Ne=await a(pe);return _(!1),T(void 0),Ne}},onCancel:()=>{_(!1),y(null),T(void 0)},onUpdateTag:d})}),b==="table"?n.jsxs("div",{className:"card relative",onDragEnter:x?xe:void 0,onDragOver:x?he:void 0,onDragLeave:x?Ie:void 0,onDrop:x?Fe:void 0,onContextMenu:pe=>{hi(pe)||(pe.preventDefault(),W({x:pe.clientX,y:pe.clientY}))},children:[B&&n.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:n.jsxs("div",{className:"text-center",children:[n.jsx(Gv,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),n.jsx("div",{className:"text-sm font-semibold",children:S("planner.dropHint")}),n.jsx("div",{className:"text-xs text-warm-500 mt-1",children:S("planner.dropHintSub")})]})}),n.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:[n.jsx("div",{className:"w-[14px] flex-shrink-0"}),n.jsxs("div",{className:"flex-1 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("title"),children:[S("planner.col.title"),n.jsx(ke,{field:"title"})]}),n.jsxs("div",{className:"w-[160px] text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("tags"),children:[S("planner.col.tags"),n.jsx(ke,{field:"tags"})]}),n.jsxs("div",{className:"w-12 text-center text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("priority"),children:[S("plannerForm.priority"),n.jsx(ke,{field:"priority"})]}),n.jsxs("div",{className:"hidden md:block w-20 text-right text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("due_date"),children:[S("planner.col.dueDate"),n.jsx(ke,{field:"due_date"})]}),n.jsxs("div",{className:"w-16 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("status"),children:[S("planner.col.status"),n.jsx(ke,{field:"status"})]}),n.jsx("div",{className:"w-8"})]}),Pe.length===0?n.jsx(Vi,{icon:fE,title:S("planner.empty"),description:S("planner.emptyHint")}):Pe.map((pe,Ne)=>n.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${Ne*20}ms`},children:n.jsx(xz,{item:pe,tagColors:Ue,existingTags:be,onSave:async(Le,ze)=>{await h(Le,ze)},onDelete:()=>f(pe.id),onConvertToTodo:()=>{H(pe),q("todo")},onConvertToSchedule:()=>{H(pe),q("schedule")},onConvertToSession:()=>{H(pe),q("session")},onUpdateTag:d})},pe.id))]}):n.jsx(Lz,{view:b,items:Pe,tagColors:Ue,onQuickAdd:pe=>{y(null),T(pe),_(!0)},onEditItem:pe=>{_(!1),y(pe)},onConvert:(pe,Ne)=>{H(pe),q(Ne)},onDeleteItem:f,onUpdateRange:(pe,Ne,Le)=>{h(pe,{due_date:Ne,end_date:Le})}}),F&&n.jsx(fS,{item:F,mode:$,projectCliTool:i,onConvert:async pe=>{$==="todo"?await m(F.id,pe):$==="session"?await c(F.id,pe):await o(F.id,pe),H(null)},onClose:()=>H(null)}),J&&n.jsx(Cr,{x:J.x,y:J.y,onClose:()=>W(null),children:n.jsxs("button",{type:"button",className:an,onClick:()=>{y(null),T(void 0),_(!0)},children:[n.jsx(mn,{size:14}),S("planner.add")]})})]})}const wS=k.createContext(null),Tz=wS.Provider;function e7(){const e=k.useContext(wS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const Rz=k.lazy(()=>Fu(()=>import("./PlannerPageEditor-DE461XLt.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),Mz=800;function Az({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:c}=dt(),[d,p]=k.useState(null),[u,x]=k.useState("idle"),[b,C]=k.useState(null),S=k.useRef({title:"",content:null}),g=k.useRef(null);k.useEffect(()=>{let j=!1;return P4(e).then(R=>{j||(p(R),S.current={title:R.title,content:R.content??null})}),()=>{j=!0}},[e]);const _=k.useCallback(()=>{g.current&&(clearTimeout(g.current),g.current=null);const{title:j,content:R}=S.current;return x("saving"),I4(e,{title:j,content:R??void 0}).then(()=>x("saved"))},[e]);k.useEffect(()=>()=>{g.current&&_()},[_]);const w=k.useCallback(()=>{g.current&&clearTimeout(g.current),x("saving"),g.current=setTimeout(()=>{_()},Mz)},[_]),y=j=>{S.current.title=j,p(R=>R&&{...R,title:j}),h(e,j),w()},E=j=>{S.current.content=j,w()},T=k.useCallback((j,R,N)=>{C({item:j,mode:R,onDone:N})},[]);return d?n.jsxs(Tz,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:T},children:[n.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[n.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[n.jsx("input",{value:d.title,onChange:j=>y(j.target.value),placeholder:c("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),n.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:u==="saving"?c("planner.pages.saving"):u==="saved"?c("planner.pages.saved"):""})]}),n.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:n.jsx(k.Suspense,{fallback:null,children:n.jsx(Rz,{pageId:e,initialContent:d.content??null,onChange:E})})})]}),b&&n.jsx(fS,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:R,mode:N,onDone:D}=b;N==="todo"?await f(R.id,j):N==="session"?await o(R.id,j):await m(R.id,j),D==null||D(),C(null)},onClose:()=>C(null)})]}):null}const En=(e,s)=>({type:"heading",props:{level:e},content:s}),Vo=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},Zy=e=>({type:"bulletListItem"}),Fi=e=>({type:"checkListItem"}),ew=()=>({type:"tasklist"}),tw=()=>({type:"calendar"}),Oz=[{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:[En(1,"회의 노트"),Vo("📅 날짜: "),Vo("👥 참석자: "),En(2,"안건"),Zy(),En(2,"논의"),Vo(),En(2,"액션 아이템"),ew()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[En(1,"프로젝트 플랜"),En(2,"개요"),Vo(),En(2,"마일스톤"),ew(),En(2,"일정"),tw(),En(2,"리스크 / 메모"),Vo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[En(1,"위클리 플래너"),En(2,"이번 주 목표"),Zy(),En(2,"요일별 할 일"),En(3,"월요일"),Fi(),En(3,"화요일"),Fi(),En(3,"수요일"),Fi(),En(3,"목요일"),Fi(),En(3,"금요일"),Fi(),En(3,"토요일"),Fi(),En(3,"일요일"),Fi(),En(2,"주간 일정"),tw()]}];function zz({onResize:e}){return n.jsx("div",{role:"separator","aria-orientation":"vertical",onPointerDown:s=>{s.preventDefault();const i=s.currentTarget;i.setPointerCapture(s.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none";let a=null,h=null;const f=()=>{if(a=null,h===null)return;const c=h;h=null,e(c)},m=c=>{h=c.clientX,a===null&&(a=requestAnimationFrame(f))},o=c=>{a!==null&&cancelAnimationFrame(a),a=null,c.type==="pointerup"&&h!==null&&f(),h=null,document.body.style.cursor="",document.body.style.userSelect="",i.removeEventListener("pointermove",m),i.removeEventListener("pointerup",o),i.removeEventListener("pointercancel",o)};i.addEventListener("pointermove",m),i.addEventListener("pointerup",o),i.addEventListener("pointercancel",o)},className:"w-1.5 shrink-0 cursor-col-resize bg-warm-300 hover:bg-accent active:bg-accent transition-colors"})}const nw=160,sw=480,rw="plannerSidebarWidth";function Bz({projectId:e,...s}){const{t:i}=dt(),[a,h]=k.useState([]),[f,m]=k.useState({kind:"work"}),[o,c]=k.useState("table"),[d,p]=k.useState(!1),[u,x]=k.useState({top:0,left:0}),b=k.useRef(null),C=k.useRef(null),S=k.useRef(!1),[g,_]=k.useState(()=>{const F=Number(localStorage.getItem(rw));return F>=nw&&F<=sw?F:208}),w=k.useCallback(F=>{var q;const H=((q=C.current)==null?void 0:q.getBoundingClientRect().left)??0,$=Math.round(Math.max(nw,Math.min(sw,F-H)));_($),localStorage.setItem(rw,String($))},[]),y=240,E=()=>{var H;const F=(H=b.current)==null?void 0:H.getBoundingClientRect();if(F){const $=Math.min(F.left,window.innerWidth-y-8);x({top:F.bottom+4,left:Math.max(8,$)})}p(!0)};k.useEffect(()=>{if(!d)return;const F=()=>p(!1),H=$=>{var q;(q=b.current)!=null&&q.contains($.target)||$.target.closest("[data-template-picker]")||p(!1)};return document.addEventListener("mousedown",H),window.addEventListener("scroll",F,!0),window.addEventListener("resize",F),()=>{document.removeEventListener("mousedown",H),window.removeEventListener("scroll",F,!0),window.removeEventListener("resize",F)}},[d]),k.useEffect(()=>{z4(e).then(F=>{h(F),S.current||(S.current=!0,F.length>0&&m({kind:"page",id:F[0].id}))})},[e]);const T=async F=>{p(!1);const H=await B4(e,F.title||i("planner.pages.untitled"),F.blocks?JSON.stringify(F.blocks):void 0);h($=>[...$,H]),m({kind:"page",id:H.id})},j=async F=>{confirm(i("planner.pages.deleteConfirm"))&&(await F4(F),h(H=>H.filter($=>$.id!==F)),m(H=>H.kind==="page"&&H.id===F?{kind:"work"}:H))},R=k.useCallback((F,H)=>{h($=>$.map(q=>q.id===F?{...q,title:H}:q))},[]),N=()=>{m({kind:"work"}),c(F=>F==="table"?"month":F)},D=()=>{m({kind:"work"}),c("table")},A=f.kind==="work",O=A&&o!=="table",z=A&&o==="table",P=(F,H,$,q,Y)=>n.jsxs("div",{onClick:H,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${F?"":"hover:bg-warm-50"}`,style:F?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[$,n.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:q}),Y]});return n.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[n.jsxs("div",{ref:C,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:g},children:[n.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),n.jsx("button",{ref:b,onClick:()=>d?p(!1):E(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:n.jsx(mn,{size:14})})]}),a.map(F=>P(f.kind==="page"&&f.id===F.id,()=>m({kind:"page",id:F.id}),n.jsx(Jo,{size:13,className:"text-warm-400 flex-shrink-0"}),F.title||i("planner.pages.untitled"),n.jsx("button",{onClick:H=>{H.stopPropagation(),j(F.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-red-500 transition-all flex-shrink-0",children:n.jsx(Ln,{size:13})}))),n.jsx("div",{className:"px-2.5 pt-3 pb-1 text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.all")}),P(O,N,n.jsx(nm,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),P(z,D,n.jsx(xu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),n.jsx(zz,{onResize:w}),n.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:f.kind==="page"?n.jsx("div",{className:"card flex flex-col flex-1",children:n.jsx(Az,{pageId:f.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:R,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},f.id)}):n.jsx(Dz,{...s,view:o,onChangeView:c})}),d&&en.createPortal(n.jsx("div",{"data-template-picker":!0,className:"fixed z-tooltip rounded-xl py-1 shadow-elevated animate-scale-in",style:{top:u.top,left:u.left,width:y,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:Oz.map(F=>n.jsxs("button",{onClick:()=>T(F),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[n.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:i(F.labelKey)}),n.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(F.descKey)})]},F.id))}),document.body)]})}const Pz=k.lazy(()=>Fu(()=>import("./AnalyticsPanel-B4ZlfUK4.js"),__vite__mapDeps([9,7,3,2]))),Iz=k.lazy(()=>Fu(()=>import("./VaultLayout-BkczecdH.js"),__vite__mapDeps([10,6,1,2,3,4])));function Fz({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:h}=$m(),[f,m]=k.useState(null),[o,c]=k.useState([]),[d,p]=k.useState([]),[u,x]=k.useState(null),[b,C]=k.useState([]),[S,g]=k.useState([]),[_,w]=k.useState([]),[y,E]=k.useState([]),[T,j]=Aw(),R=["tasks","discussions","schedules","analytics"],N=T.get("tab")||"tasks",[D,A]=k.useState(R.includes(N)?"automation":N),[O,z]=k.useState(R.includes(N)?N:"tasks"),P=k.useCallback(ie=>{if(ie==="automation"){A("automation"),j(O==="tasks"?{}:{tab:O},{replace:!0});return}A(ie),j(ie==="tasks"?{}:{tab:ie},{replace:!0})},[j,O]),F=k.useCallback(ie=>{A("automation"),z(ie),j(ie==="tasks"?{}:{tab:ie},{replace:!0})},[j]),[H,$]=k.useState(!0),[q,Y]=k.useState(!1),[I,B]=k.useState(new Set),[U,J]=k.useState(0),{t:W}=dt(),{sendNotification:oe}=np(),ee=k.useRef([]);k.useEffect(()=>{ee.current=b},[b]),k.useEffect(()=>{h&&Promise.all([kN(h),hf(h),hb(h),fb(h),s4(),_1(h),Hc(h),$c(h)]).then(([ie,_e,je,we,rt,Me,vt,bt])=>{m(ie),c(_e),p(je),C(we),g(Me),w(vt),E(bt),rt.resetsAt&&x(rt.resetsAt);const St=_e.filter(Et=>Et.status==="running"&&Et.execution_mode==="interactive").map(Et=>Et.id);St.length>0&&B(new Set(St))}).catch(()=>Y(!0)).finally(()=>$(!1))},[h]);const Z=k.useRef(o);Z.current=o,k.useEffect(()=>{if(!h)return;const ie=setInterval(()=>{Z.current.some(je=>je.status==="running")&&hf(h).then(je=>{c(we=>we.map(rt=>{const Me=je.find(vt=>vt.id===rt.id);return Me&&Me.status!==rt.status?Me:rt}))}).catch(()=>{})},5e3);return()=>clearInterval(ie)},[h]);const X=k.useRef(s);k.useEffect(()=>{s&&!X.current&&h&&Promise.all([hf(h),hb(h),fb(h)]).then(([ie,_e,je])=>{c(ie),p(_e),C(je)}).catch(()=>{}),X.current=s},[s,h]),k.useEffect(()=>e(ie=>{if(ie.type==="todo:status-changed"&&ie.todoId&&ie.status){if(c(_e=>_e.map(je=>{if(je.id!==ie.todoId)return je;const we={status:ie.status,updated_at:new Date().toISOString()};return ie.worktree_path!==void 0&&(we.worktree_path=ie.worktree_path??null),ie.branch_name!==void 0&&(we.branch_name=ie.branch_name??null),{...je,...we}})),(ie.status==="completed"||ie.status==="merged"||ie.status==="failed")&&J(_e=>_e+1),ie.status==="completed"||ie.status==="failed"){const _e=Z.current.find(je=>je.id===ie.todoId);_e&&oe(ie.status==="completed"?W("notification.taskCompleted"):W("notification.taskFailed"),_e.title)}ie.status==="running"&&ie.mode==="interactive"?B(_e=>new Set(_e).add(ie.todoId)):ie.status!=="running"&&B(_e=>{const je=new Set(_e);return je.delete(ie.todoId),je})}if(ie.type==="schedule:status-changed"&&ie.scheduleId&&p(_e=>_e.map(je=>je.id===ie.scheduleId?{...je,is_active:ie.isActive?1:0,updated_at:new Date().toISOString()}:je)),ie.type==="rate-limit:updated"&&ie.resetsAt&&x(ie.resetsAt),ie.type==="discussion:status-changed"&&ie.discussionId&&(C(_e=>_e.map(je=>je.id===ie.discussionId?{...je,status:ie.status,current_round:ie.currentRound??je.current_round,updated_at:new Date().toISOString()}:je)),ie.status==="completed"||ie.status==="failed")){const _e=ee.current.find(je=>je.id===ie.discussionId);_e&&oe(ie.status==="completed"?W("notification.discussionCompleted"):W("notification.discussionFailed"),_e.title)}ie.type==="session:status-changed"&&ie.sessionId&&g(_e=>_e.map(je=>{if(je.id!==ie.sessionId)return je;const we={status:ie.status,updated_at:new Date().toISOString()};return ie.worktree_path!==void 0&&(we.worktree_path=ie.worktree_path),ie.branch_name!==void 0&&(we.branch_name=ie.branch_name),{...je,...we}}))}),[e,oe,W]);const G=k.useCallback(async(ie,_e,je,we,rt,Me,vt,bt,St,Et)=>{if(!h)return;const Ht=await ub(h,{title:ie,description:_e,cli_tool:je,depends_on:rt,max_turns:Me??null,use_worktree:vt??null,...bt?{memory_inject_mode:bt}:{},...St?{memory_node_ids:St}:{},...Et?{memory_raw_file_paths:Et}:{}});if(we&&we.length>0){const pn=await v1(Ht.id,we.map(gn=>({name:gn.name,data:gn.data})));Ht.images=JSON.stringify(pn.images)}c(pn=>[...pn,Ht])},[h]),me=k.useCallback((ie,_e=[])=>{const je=ie.split("/").filter(Boolean).pop()??ie,we=[ie,..._e].map(rt=>`@${rt}`).join(`
684
684
  `);return G(je,`다음 파일을 참고하세요:
685
685
  ${we}`)},[G]),ge=k.useCallback(async(ie,_e)=>{const je=_e==="interactive";je&&B(we=>new Set(we).add(ie));try{const we=await db(ie,_e);c(rt=>rt.map(Me=>Me.id===ie?we:Me))}catch(we){throw je&&B(rt=>{const Me=new Set(rt);return Me.delete(ie),Me}),we}},[]),xe=k.useCallback(async ie=>{const _e=await W3(ie);c(je=>je.map(we=>we.id===ie?_e:we))},[]),he=k.useCallback(async ie=>{await f1(ie),c(_e=>_e.filter(je=>je.id!==ie))},[]),Ie=k.useCallback(async(ie,_e,je,we,rt,Me,vt,bt,St,Et)=>{const Ht=await Fc(ie,{title:_e,description:je,cli_tool:we,depends_on:rt??null,max_turns:Me??null,use_worktree:vt===void 0?null:vt,...bt?{memory_inject_mode:bt}:{},...St?{memory_node_ids:St}:{},...Et?{memory_raw_file_paths:Et}:{}});c(pn=>pn.map(gn=>gn.id===ie?Ht:gn))},[]),Fe=k.useCallback(async ie=>{await p1(ie),c(_e=>_e.map(je=>je.id===ie?{...je,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:je))},[]),be=k.useCallback(async ie=>{const _e=await G3(ie),je=new Set(_e.mergedIds);c(we=>we.map(rt=>je.has(rt.id)?{...rt,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:rt))},[]),Ue=k.useCallback(async(ie,_e=!1)=>{await g1(ie,_e),c(je=>je.map(we=>we.id===ie?{...we,worktree_path:null,..._e?{branch_name:null}:{},updated_at:new Date().toISOString()}:we))},[]),Pe=k.useCallback(async(ie,_e)=>{const je=_e==="interactive";je&&B(we=>new Set(we).add(ie));try{const we=await V3(ie,_e);c(rt=>rt.map(Me=>Me.id===ie?we:Me))}catch(we){throw je&&B(rt=>{const Me=new Set(rt);return Me.delete(ie),Me}),we}},[]),tt=k.useCallback(async(ie,_e,je)=>{const we=je==="interactive";we&&B(rt=>new Set(rt).add(ie));try{const rt=await x1(ie,_e,je);c(Me=>Me.map(vt=>vt.id===ie?rt:vt))}catch(rt){throw we&&B(Me=>{const vt=new Set(Me);return vt.delete(ie),vt}),rt}},[]),ke=k.useCallback(async(ie,_e,je)=>{const we=await Q3(ie,_e,je);we.original_deleted&&c(rt=>rt.filter(Me=>Me.id!==ie)),p(rt=>[we.schedule,...rt])},[]),pe=k.useCallback(async(ie,_e)=>{const je=await r4(ie,_e);p(we=>[je.schedule,...we])},[]),Ne=k.useCallback((ie,_e)=>{i({type:"todo:stdin",todoId:ie,input:_e})},[i]),Le=k.useCallback(async(ie,_e)=>{const je=await Fc(ie,{depends_on:_e});c(we=>we.map(rt=>rt.id===ie?je:rt))},[]),ze=k.useCallback(async ie=>{const _e=ie.map((je,we)=>({id:je,priority:we}));c(je=>je.map(we=>{const rt=_e.find(Me=>Me.id===we.id);return rt?{...we,priority:rt.priority}:we})),await Promise.all(_e.map(je=>Fc(je.id,{priority:je.priority})))},[]),Ke=k.useCallback(async(ie,_e,je)=>{await Fc(ie,{position_x:_e,position_y:je}),c(we=>we.map(rt=>rt.id===ie?{...rt,position_x:_e,position_y:je}:rt))},[]),Ve=k.useCallback(async(ie,_e)=>{if(!h)return;const je=_e.map(vt=>vt.message).join(`
686
686
  `),we=`The previous task "${ie.title}" failed with the following errors: