clitrigger 0.2.35 → 0.2.36

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-CIl9OUzG.js","assets/style-CuVlwvaN.js","assets/value-BTdN53H7.js","assets/with-selector-Dyu1i_cc.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-BUVPANE-.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-Tra_CsK-.js","assets/VaultLayout-Cx2o5uSE.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-BEUkqd9I.js","assets/style-BDV35G0X.js","assets/value-BTdN53H7.js","assets/with-selector-DUHpKoOb.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-Cvdr9ckv.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-CyIM0XTT.js","assets/VaultLayout-DrDkpfva.js"])))=>i.map(i=>d[i]);
2
2
  var mC=Object.defineProperty;var pC=(e,s,i)=>s in e?mC(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var ov=(e,s,i)=>pC(e,typeof s!="symbol"?s+"":s,i);function gC(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 qP=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 tf={exports:{}},Ho={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -599,7 +599,7 @@ Cancel = delete worktree only`,"todo.retry":"Retry","todo.retryDesc":"Cleans up
599
599
  *
600
600
  * This source code is licensed under the ISC license.
601
601
  * See the LICENSE file in the root directory of this source tree.
602
- */const JN=[["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"}]],QN=tt("zoom-out",JN);function ZN({onLogin:e}){const[s,i]=_.useState(""),[a,h]=_.useState(!1),[f,m]=_.useState(""),[o,c]=_.useState(!1),{t:d,toggleLang:p}=st(),u=async v=>{if(v.preventDefault(),!!s){m(""),c(!0);try{await e(s,a)}catch{m(d("login.error"))}finally{c(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:t.jsx(hl,{size:32,className:"text-accent",strokeWidth:1.5})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("login.subtitle")})]}),t.jsx("form",{onSubmit:u,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("login.password")}),t.jsx("input",{type:"password",value:s,onChange:v=>i(v.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),f&&t.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}),t.jsxs("label",{className:"flex items-center gap-2 mt-5 text-sm text-theme-text-secondary cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:a,onChange:v=>h(v.target.checked),className:"accent-accent w-4 h-4"}),d("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!s||o,className:"btn-primary w-full mt-6 py-3",children:d(o?"login.loading":"login.submit")})]})}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:d("login.footer")}),t.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:d("login.disclaimer")})]})]})}const zv=8;function eE({onSetup:e}){const[s,i]=_.useState(""),[a,h]=_.useState(""),[f,m]=_.useState(""),[o,c]=_.useState(!1),{t:d,toggleLang:p}=st(),u=s.length>0&&s.length<zv,v=a.length>0&&s!==a,b=s.length>=zv&&s===a&&!o,C=async S=>{if(S.preventDefault(),!!b){m(""),c(!0);try{await e(s,a)}catch(x){m(x instanceof Error&&x.message?x.message:d("setup.error"))}finally{c(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:t.jsx(hl,{size:32,className:"text-accent",strokeWidth:1.5})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("setup.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),t.jsx("form",{onSubmit:C,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),t.jsx("input",{type:"password",value:s,onChange:S=>i(S.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),u&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),t.jsx("input",{type:"password",value:a,onChange:S=>h(S.target.value),placeholder:"*************",className:"input-field text-base"}),v&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),f&&t.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}),t.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(o?"setup.loading":"setup.submit")})]})}),t.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 tE(e){return Ze("/api/projects/browse",{initialPath:e})}function nE(e){return Ze("/api/projects/open-folder",{path:e})}function Hu(){return dt("/api/projects")}function sE(e){return dt(`/api/projects/${e}`)}function zw(e){return Ze("/api/projects",e)}function rE(e){return dt(`/api/projects/${e}/svn-detect`)}function tm(e,s){return an(`/api/projects/${e}`,s)}function iE(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return dt(`/api/projects/${e}/debug-logs${i}`)}function Pw(e){return Bn(`/api/projects/${e}`)}function aE(e){return Ze("/api/projects/reorder",{ids:e})}function oE(e){return Ze(`/api/projects/${e}/start`)}function lE(e){return Ze(`/api/projects/${e}/stop`)}function Bw(e){return dt(`/api/projects/${e}/status`)}function Pv(){return dt("/api/active-work")}function cE(e){return Ze(`/api/projects/${e}/check-git`)}function Iw(e,s){return dt(`/api/projects/${e}/git-status`)}function uE(e,s=0,i=50,a){const h=new URLSearchParams({skip:String(s),limit:String(i)});return dt(`/api/projects/${e}/git-log?${h}`)}function nm(e,s){return dt(`/api/projects/${e}/git-refs`)}function dE(e,s){return Ze(`/api/projects/${e}/git-stage`,{files:s})}function hE(e,s){return Ze(`/api/projects/${e}/git-unstage`,{files:s})}function Hw(e,s){return Ze(`/api/projects/${e}/git-commit`,{message:s})}function Fw(e,s,i){return Ze(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function qm(e,s){return Ze(`/api/projects/${e}/git-push`,s||{})}function fE(e){return dt(`/api/projects/${e}/git-remotes`)}function $w(e,s,i){return Ze(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function mE(e,s,i){return Ze(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function sm(e,s,i){return Ze(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function rm(e,s){return Ze(`/api/projects/${e}/git-checkout`,{branch:s})}function Uw(e,s){return Ze(`/api/projects/${e}/git-merge`,{branch:s})}function Bv(e,s,i){return Ze(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i})}function pE(e){return Ze(`/api/projects/${e}/git-conflict-continue`)}function gE(e){return Ze(`/api/projects/${e}/git-conflict-abort`)}function xE(e,s){return Ze(`/api/projects/${e}/git-stash`,{message:s})}function vE(e,s){return Ze(`/api/projects/${e}/git-stash-pop`,{index:s})}function bE(e){return dt(`/api/projects/${e}/git-stash-list`)}function yE(e,s,i){return Ze(`/api/projects/${e}/git-discard`,{files:s,all:i})}function wE(e,s,i,a){return Ze(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function Iv(e,s,i){return Ze(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function _E(e,s){return Ze(`/api/projects/${e}/git-rebase`,{onto:s})}function SE(e,s,i){const a=new URLSearchParams;return s&&a.set("file",s),i&&a.set("staged","true"),dt(`/api/projects/${e}/git-diff?${a}`)}function kE(e,s){const i=new URLSearchParams({hash:s});return dt(`/api/projects/${e}/git-commit-files?${i}`)}function Hv(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),dt(`/api/projects/${e}/git-commit-diff?${a}`)}function Fv(e){return dt(`/api/projects/${e}/worktrees`)}function $v(e,s,i){return Ze(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function Ww(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 CE(e={}){return dt(`/api/review/queue${Ww(e)}`)}function Gw(e={}){return dt(`/api/review/summary${Ww(e)}`)}function jE(e){return dt(`/api/review/diff/${encodeURIComponent(e)}`)}function NE(e,s){return dt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function EE(){return dt("/api/favorites")}function TE(e){return Ze("/api/favorites",e)}function LE(e,s){return an(`/api/favorites/${e}`,s)}function DE(e){return Bn(`/api/favorites/${e}`)}function RE(e){return Ze(`/api/favorites/${e}/launch`)}function ME(e){return Ze("/api/favorites/browse-file",{initialPath:e})}function im(){return dt("/api/tunnel/status")}function AE(){return dt("/api/tunnel/config")}function OE(e){return an("/api/tunnel/config",e)}function qw(e){return Ze("/api/tunnel/start",{})}function zE(){return Ze("/api/tunnel/stop")}const Kw=_.createContext({theme:"light",toggleTheme:()=>{}});function PE(){const[e,s]=_.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});_.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=_.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function BE(){return _.useContext(Kw)}const Vw=_.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function IE(){const e="Notification"in window,[s,i]=_.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=_.useRef(s);_.useEffect(()=>{a.current=s},[s]);const h=_.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=_.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 Km(){return _.useContext(Vw)}let HE=0;const Yw=_.createContext(null);function FE({children:e}){const[s,i]=_.useState([]),a=_.useRef(new Map),h=_.useRef(new Map),f=_.useRef(new Map),m=_.useCallback(b=>{i(x=>x.filter(y=>y.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=_.useCallback((b,C="info",S=3500)=>{const x=`${C}:${b}`,y=h.current.get(x);if(y)return y;const w=`toast-${++HE}`;h.current.set(x,w),f.current.set(w,x),i(N=>[...N,{id:w,message:b,type:C,duration:S}]);const k=setTimeout(()=>m(w),S);return a.current.set(w,k),w},[m]),c=_.useCallback((b,C)=>o(b,"success",C),[o]),d=_.useCallback((b,C)=>o(b,"error",C),[o]),p=_.useCallback((b,C)=>o(b,"info",C),[o]),u=_.useCallback((b,C)=>o(b,"warning",C),[o]);_.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),h.current.clear(),f.current.clear()},[]);const v=_.useMemo(()=>({toasts:s,show:o,success:c,error:d,info:p,warning:u,dismiss:m}),[s,o,c,d,p,u,m]);return _.createElement(Yw.Provider,{value:v},e)}function Vi(){const e=_.useContext(Yw);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Xs(...e){return e.filter(Boolean).join(" ")}const $E={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl"},UE={scale:"animate-scale-in","slide-up":"animate-slide-up"};function $n({open:e,onClose:s,size:i="md",position:a="center",animation:h="scale",disableEscClose:f=!1,disableBackdropClose:m=!1,children:o}){const c=_.useRef(null);return _.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?rn.createPortal(t.jsx("div",{ref:c,className:Xs("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:t.jsx("div",{className:Xs("w-full",$E[i],UE[h]),children:o})}),document.body):null}function Xw({onSubmit:e,onCancel:s}){const[i,a]=_.useState(""),[h,f]=_.useState(""),[m,o]=_.useState(!1),[c,d]=_.useState(!1),[p,u]=_.useState(""),{t:v}=st(),b=async S=>{if(S.preventDefault(),!(!i.trim()||!h.trim())){u(""),d(!0);try{await e(i.trim(),h.trim())}catch(x){const y=x instanceof Error?x.message:String(x);u(y||v("form.createError"))}finally{d(!1)}}},C=async()=>{o(!0);try{const S=await tE(h||void 0);S.path&&f(S.path)}catch{}o(!1)};return t.jsx($n,{open:!0,onClose:s,size:"md",children:t.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:v("form.newProject")}),t.jsxs("form",{onSubmit:b,children:[t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:v("form.projectName")}),t.jsx("input",{type:"text",placeholder:"my-project",value:i,onChange:S=>a(S.target.value),className:"input-field",autoFocus:!0})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:v("form.folderPath")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:h,onChange:S=>f(S.target.value),className:"input-field text-sm flex-1"}),t.jsx("button",{type:"button",onClick:C,disabled:m,className:"btn-ghost text-sm px-3 shrink-0",title:v("browse.title"),children:m?t.jsx(Wi,{size:16,className:"animate-spin"}):t.jsx(zu,{size:16})})]})]}),p&&t.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:p}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:v("form.cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||!h.trim()||c,className:"btn-primary text-sm",children:v(c?"form.creating":"form.create")})]})]})]})})}const WE=[{value:"executable",icon:Wm},{value:"command",icon:di},{value:"url",icon:Ua}];function GE(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 Uv(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 qE({initial:e,onSubmit:s,onCancel:i}){const{t:a}=st(),[h,f]=_.useState((e==null?void 0:e.name)??""),[m,o]=_.useState((e==null?void 0:e.type)??"executable"),[c,d]=_.useState((e==null?void 0:e.target)??""),[p,u]=_.useState(Uv((e==null?void 0:e.args)??null)),[v,b]=_.useState((e==null?void 0:e.cwd)??""),[C,S]=_.useState(!1);_.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),d((e==null?void 0:e.target)??""),u(Uv((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[x,y]=_.useState(!1),w=m==="executable",k=async()=>{y(!0);try{const{path:O}=await ME(c||void 0);if(!O)return;if(d(O),!h.trim()){const z=O.replace(/\\/g,"/").split("/").pop()||"";f(z.replace(/\.[^.]+$/,""))}}catch{}finally{y(!1)}},N=!!e,D=h.trim(),j=c.trim(),R=m!=="url"||/^https?:\/\//i.test(j),E=!!D&&!!j&&R&&!C,L=async O=>{if(O.preventDefault(),!!E){S(!0);try{const z={name:D,type:m,target:j,args:m==="executable"&&p.trim()?GE(p.trim()):null,cwd:m!=="url"&&v.trim()?v.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 t.jsx($n,{open:!0,onClose:i,size:"md",children:t.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:a(N?"favorites.form.title.edit":"favorites.form.title.create")}),t.jsxs("form",{onSubmit:L,children:[t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.type")}),t.jsx("div",{className:"grid grid-cols-3 gap-2",children:WE.map(({value:O,icon:z})=>t.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:[t.jsx(z,{size:14}),a(`favorites.types.${O}`)]},O))})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.name")}),t.jsx("input",{type:"text",value:h,onChange:O=>f(O.target.value),className:"input-field",autoFocus:!0})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.target")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:c,onChange:O=>d(O.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),w&&t.jsxs("button",{type:"button",onClick:k,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx(zu,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),m==="executable"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.args")}),t.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"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.cwd")}),t.jsx("input",{type:"text",value:v,onChange:O=>b(O.target.value),className:"input-field text-sm font-mono",placeholder:"C:/Projects/my-project"})]}),t.jsx("p",{className:"mb-6 text-2xs leading-snug",style:{color:"var(--color-text-muted)"},children:a("favorites.security.notice")}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:i,className:"btn-ghost text-sm",children:a("favorites.form.cancel")}),t.jsx("button",{type:"submit",disabled:!E,className:"btn-primary text-sm",children:a(N?"favorites.form.save":"favorites.form.create")})]})]})]})})}const KE=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function VE({onClose:e}){const{t:s}=st(),{error:i,success:a}=Vi(),[h,f]=_.useState(""),[m,o]=_.useState(""),[c,d]=_.useState(""),[p,u]=_.useState(""),[v,b]=_.useState(!1),[C,S]=_.useState(!1),[x,y]=_.useState(!1),[w,k]=_.useState(null);_.useEffect(()=>{let z=!1;return Promise.all([AE(),im()]).then(([I,F])=>{z||(f(I.tunnelName),o(I.customHostname),d(I.tunnelName),u(I.customHostname),k(F))}).catch(()=>{}),()=>{z=!0}},[]);const N=h.trim(),D=m.trim(),j=N!==c.trim()||D!==p.trim(),R=!!D&&(!KE.test(D)||D.toLowerCase()==="localhost"||D.toLowerCase()==="127.0.0.1"),E=!!D&&!N,L=j&&!C&&!R&&!E,A=async()=>{if(L){S(!0);try{const z=await OE({tunnelName:N,customHostname:D});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()=>{y(!0);try{try{await zE()}catch{}const z=await qw();k({status:"running",url:z.url}),a(s("tunnel.restarted"))}catch(z){i(z instanceof Error?z.message:s("tunnel.restartFailed"))}finally{y(!1)}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),w&&t.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:[t.jsx("span",{className:`w-2 h-2 rounded-full ${w.status==="running"?"bg-status-success":w.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${w.status}`)}),w.url&&t.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})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),t.jsx("input",{type:"text",value:h,onChange:z=>f(z.target.value),placeholder:s("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.name.hint")})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.hostname.label")}),t.jsx("input",{type:"text",value:m,onChange:z=>o(z.target.value),placeholder:s("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.hostname.hint")}),R&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),E&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.needsName")})]}),t.jsxs("div",{className:"mb-5",children:[t.jsxs("button",{type:"button",onClick:()=>b(!v),className:"flex items-center gap-1 text-xs text-accent-dark hover:text-accent transition-colors",children:[t.jsx("span",{className:`inline-block transition-transform ${v?"rotate-90":""}`,children:"▶"}),s("tunnel.guide.toggle")]}),v&&t.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:[t.jsx("p",{className:"font-semibold text-warm-700 mb-1",children:s("tunnel.guide.heading")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 ml-1",children:[t.jsx("li",{children:t.jsx("code",{className:"font-mono",children:"cloudflared tunnel login"})}),t.jsx("li",{children:t.jsx("code",{className:"font-mono",children:"cloudflared tunnel create my-app"})}),t.jsx("li",{children:t.jsx("code",{className:"font-mono",children:"cloudflared tunnel route dns my-app app.your-domain.com"})}),t.jsx("li",{children:s("tunnel.guide.step4")})]}),t.jsx("p",{className:"text-2xs text-warm-400 pt-1",children:s("tunnel.guide.note")})]})]}),t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("button",{type:"button",onClick:O,disabled:x,className:"btn-ghost text-sm disabled:opacity-50",children:x?(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")}),t.jsxs("div",{className:"flex gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),t.jsx("button",{type:"button",onClick:A,disabled:!L,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const Wv=8;function YE({onClose:e}){const{t:s}=st(),{error:i,success:a}=Vi(),[h,f]=_.useState(""),[m,o]=_.useState(""),[c,d]=_.useState(""),[p,u]=_.useState(!1),v=m.length>0&&m.length<Wv,b=c.length>0&&m!==c,C=!!h&&m.length>=Wv&&m===c&&!p,S=()=>{f(""),o(""),d("")},x=async()=>{if(C){u(!0);try{await oj(h,m,c),a(s("account.saved")),S()}catch(y){i(y instanceof Error&&y.message?y.message:s("account.saveFailed"))}finally{u(!1)}}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("account.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("account.description")}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.oldPassword")}),t.jsx("input",{type:"password",value:h,onChange:y=>f(y.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.newPassword")}),t.jsx("input",{type:"password",value:m,onChange:y=>o(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),v&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.tooShort")})]}),t.jsxs("div",{className:"mb-6",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.confirm")}),t.jsx("input",{type:"password",value:c,onChange:y=>d(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),t.jsx("button",{type:"button",onClick:x,disabled:!C,className:"btn-primary text-sm",children:s(p?"account.saving":"account.save")})]})]})}function Vm(){return dt("/api/session-tags")}function XE(e){return Ze("/api/session-tags",e)}function JE(e,s){return an(`/api/session-tags/${e}`,s)}function QE(e){return Bn(`/api/session-tags/${e}`)}function Jw(){return dt("/api/session-aliases")}function Qw(e){return Ze("/api/session-aliases",e)}function ZE(e,s){return an(`/api/session-aliases/${e}`,s)}function e3(e){return Bn(`/api/session-aliases/${e}`)}function Ym(){return dt("/api/session-settings")}function hf(e){return an("/api/session-settings",e)}const Ie={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",Xm=13,el=8,tl=28,Wa=new Map,Fi=new Map;let vu=Xm;function Jm(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);Wa.delete(s);const i=Fi.get(s);if(i){const h=nl(s);i.forEach(f=>f(h))}});function am(e){return Number.isFinite(e)?Math.max(el,Math.min(tl,Math.round(e))):vu}function t3(e){if(Wa.has(e))return!0;try{return localStorage.getItem(Jm(e))!==null}catch{return!1}}function nl(e){const s=Wa.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(Jm(e));if(a!==null){const h=parseInt(a,10);Number.isFinite(h)&&(i=am(h))}}catch{}return i===null?am(vu):(Wa.set(e,i),i)}function om(e,s){const i=am(s);if(Wa.get(e)===i)return;Wa.set(e,i);try{localStorage.setItem(Jm(e),String(i))}catch{}const a=Fi.get(e);a&&a.forEach(h=>h(i))}function Wo(e,s){om(e,nl(e)+s)}function au(e){const s=Math.max(el,Math.min(tl,Math.round(e)));Number.isFinite(s)&&s!==vu&&(vu=s,Fi.forEach((i,a)=>{t3(a)||i.forEach(h=>h(s))}))}function Zw(e){const[s,i]=_.useState(()=>nl(e));_.useEffect(()=>{i(nl(e));let f=Fi.get(e);return f||(f=new Set,Fi.set(e,f)),f.add(i),()=>{const m=Fi.get(e);m&&(m.delete(i),m.size===0&&Fi.delete(e))}},[e]);const a=_.useCallback(f=>om(e,f),[e]),h=_.useCallback(f=>om(e,nl(e)+f),[e]);return[s,a,h]}const sl=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function Gv(e){for(const s of sl)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return sl[e.length%sl.length]}function n3({onClose:e}){const{t:s}=st(),{error:i,success:a}=Vi(),[h,f]=_.useState([]),[m,o]=_.useState(!1),[c,d]=_.useState(Xm),[p,u]=_.useState(!1),[v,b]=_.useState(!1),[C,S]=_.useState(!1),[x,y]=_.useState(!1),w=_.useRef(null),[k,N]=_.useState(""),[D,j]=_.useState(sl[0]),[R,E]=_.useState(!1),[L,A]=_.useState(null),[O,z]=_.useState(""),[I,F]=_.useState(sl[0]),[H,U]=_.useState(!1),[q,X]=_.useState([]),[B,P]=_.useState(""),[$,Y]=_.useState(""),[W,Z]=_.useState(!1),[he,re]=_.useState(null),[J,V]=_.useState(""),[pe,oe]=_.useState(""),[ge,le]=_.useState(!1);_.useEffect(()=>{let se=!1;return Promise.all([Vm(),Ym(),Jw()]).then(([ce,fe,ue])=>{se||(f(ce),o(fe.defaultUseWorktree),d(fe.defaultFontSize),au(fe.defaultFontSize),u(fe.imeDebug),j(Gv(ce)),X(ue),b(!0))}).catch(ce=>{se||i(ce instanceof Error?ce.message:"Failed to load")}),()=>{se=!0}},[i]);const Oe=k.trim(),He=!!Oe&&!R,Te=_.useMemo(()=>[...h].sort((se,ce)=>se.sort_order-ce.sort_order||se.name.localeCompare(ce.name)),[h]);_.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const ye=se=>{if(!Number.isFinite(se))return;const ce=Math.max(el,Math.min(tl,Math.round(se)));d(ce),au(ce),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{hf({defaultFontSize:ce}).then(fe=>{d(fe.defaultFontSize),au(fe.defaultFontSize)}).catch(fe=>i(fe instanceof Error?fe.message:"Save failed"))},350)},ke=async se=>{S(!0);try{const ce=await hf({defaultUseWorktree:se});o(ce.defaultUseWorktree),a(s("sessionSettings.saved"))}catch(ce){i(ce instanceof Error?ce.message:"Save failed")}finally{S(!1)}},Ke=async se=>{var ce,fe;y(!0);try{const ue=await hf({imeDebug:se});u(ue.imeDebug),(fe=(ce=window.electronAPI)==null?void 0:ce.imeSetDebug)==null||fe.call(ce,ue.imeDebug),a(s("sessionSettings.saved"))}catch(ue){i(ue instanceof Error?ue.message:"Save failed")}finally{y(!1)}},$e=async()=>{if(He){E(!0);try{const se=await XE({name:Oe,color:D});f(ce=>[...ce,se]),N(""),j(Gv([...h,se]))}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{E(!1)}}},be=se=>{A(se.id),z(se.name),F(se.color)},De=()=>{A(null),z("")},Fe=async()=>{if(!L)return;const se=O.trim();if(se){U(!0);try{const ce=await JE(L,{name:se,color:I});f(fe=>fe.map(ue=>ue.id===ce.id?ce:ue)),De()}catch(ce){i(ce instanceof Error?ce.message:"Save failed")}finally{U(!1)}}},qe=async se=>{if(confirm(s("sessionSettings.tags.deleteConfirm").replace("{name}",se.name)))try{await QE(se.id),f(ce=>ce.filter(fe=>fe.id!==se.id))}catch(ce){i(ce instanceof Error?ce.message:"Delete failed")}},Qe=B.trim(),nt=$.trim(),xe=!!Qe&&!!nt&&!W,ie=_.useMemo(()=>[...q].sort((se,ce)=>se.sort_order-ce.sort_order||se.name.localeCompare(ce.name)),[q]),we=async()=>{if(xe){Z(!0);try{const se=await Qw({name:Qe,command_template:nt});X(ce=>[...ce,se]),P(""),Y("")}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{Z(!1)}}},Q=se=>{re(se.id),V(se.name),oe(se.command_template)},K=()=>{re(null),V(""),oe("")},ne=async()=>{if(!he)return;const se=J.trim(),ce=pe.trim();if(!(!se||!ce)){le(!0);try{const fe=await ZE(he,{name:se,command_template:ce});X(ue=>ue.map(je=>je.id===fe.id?fe:je)),K()}catch(fe){i(fe instanceof Error?fe.message:"Save failed")}finally{le(!1)}}},ee=async se=>{if(confirm(`Delete alias "${se.name}"? Sessions using it will fall back to OS default shell.`))try{await e3(se.id),X(ce=>ce.filter(fe=>fe.id!==se.id))}catch(ce){i(ce instanceof Error?ce.message:"Delete failed")}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("sessionSettings.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("sessionSettings.description")}),t.jsxs("section",{className:"mb-7",children:[t.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[t.jsx(Ya,{size:14}),s("sessionSettings.worktree.title")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:m,disabled:C||!v,onChange:se=>ke(se.target.checked),className:"rounded border-warm-300"}),t.jsx("span",{className:"text-sm text-warm-600",children:s("sessionSettings.worktree.label")})]}),t.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.worktree.hint")})]}),t.jsxs("section",{className:"mb-7",children:[t.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[t.jsx($N,{size:14}),s("sessionSettings.fontSize.title")]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("input",{type:"range",min:el,max:tl,step:1,value:c,disabled:!v,onChange:se=>ye(parseInt(se.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),t.jsx("input",{type:"number",min:el,max:tl,step:1,value:c,disabled:!v,onChange:se=>ye(parseInt(se.target.value,10)),className:"input text-sm w-20"}),t.jsx("span",{className:"text-xs text-warm-400",children:"px"})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.fontSize.hint")})]}),t.jsxs("section",{children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:s("sessionSettings.tags.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-3",children:s("sessionSettings.tags.description")}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx("input",{type:"color",value:D,onChange:se=>j(se.target.value),className:"w-9 h-9 rounded cursor-pointer border border-warm-200",title:s("sessionSettings.tags.color")}),t.jsx("input",{type:"text",value:k,onChange:se=>N(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),$e())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),t.jsxs("button",{type:"button",onClick:$e,disabled:!He,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(mn,{size:14}),s("sessionSettings.tags.add")]})]}),Te.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:s("sessionSettings.tags.empty")}):t.jsx("ul",{className:"space-y-1.5",children:Te.map(se=>{const ce=L===se.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ce?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:I,onChange:fe=>F(fe.target.value),className:"w-7 h-7 rounded cursor-pointer border border-warm-200"}),t.jsx("input",{type:"text",value:O,onChange:fe=>z(fe.target.value),onKeyDown:fe=>{fe.key==="Enter"&&(fe.preventDefault(),Fe()),fe.key==="Escape"&&De()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),t.jsx("button",{type:"button",onClick:Fe,disabled:H||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:s("sessionSettings.tags.save"),children:t.jsx(ai,{size:14})}),t.jsx("button",{type:"button",onClick:De,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.cancel"),children:t.jsx(Qt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:se.color,borderColor:"rgba(0,0,0,0.08)"}}),t.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:se.name}),t.jsx("button",{type:"button",onClick:()=>be(se),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.edit"),children:t.jsx(ci,{size:14})}),t.jsx("button",{type:"button",onClick:()=>qe(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:s("sessionSettings.tags.delete"),children:t.jsx(jn,{size:14})})]})},se.id)})})]}),t.jsxs("section",{className:"mt-7",children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:"Terminal aliases"}),t.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."}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx("input",{type:"text",value:B,onChange:se=>P(se.target.value),placeholder:"Name (e.g. WSL Ubuntu)",className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:$,onChange:se=>Y(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),we())},placeholder:"Command (e.g. wsl -d Ubuntu)",className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsxs("button",{type:"button",onClick:we,disabled:!xe,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(mn,{size:14}),"Add"]})]}),ie.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:"No aliases yet."}):t.jsx("ul",{className:"space-y-1.5",children:ie.map(se=>{const ce=he===se.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ce?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:J,onChange:fe=>V(fe.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:pe,onChange:fe=>oe(fe.target.value),onKeyDown:fe=>{fe.key==="Enter"&&(fe.preventDefault(),ne()),fe.key==="Escape"&&K()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:ne,disabled:ge||!J.trim()||!pe.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:"Save",children:t.jsx(ai,{size:14})}),t.jsx("button",{type:"button",onClick:K,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:"Cancel",children:t.jsx(Qt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:se.name}),t.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:se.command_template}),t.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:t.jsx(ci,{size:14})}),t.jsx("button",{type:"button",onClick:()=>ee(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:"Delete",children:t.jsx(jn,{size:14})})]})},se.id)})})]}),t.jsxs("section",{className:"mt-7",children:[t.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[t.jsx(Oj,{size:14}),"IME 디버그 로그"]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:p,disabled:x||!v,onChange:se=>Ke(se.target.checked),className:"rounded border-warm-300"}),t.jsx("span",{className:"text-sm text-warm-600",children:"한글 입력(IME) 진단 로그 기록"})]}),t.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:"조합 창이 화면 좌상단에 뜨는 문제를 진단하기 위해 입력 시점 상태를 기록합니다. 데스크톱 앱에서만 동작하며, 로그는 앱 데이터 폴더의 ime-debug.log에 저장됩니다."})]}),e&&t.jsx("div",{className:"flex justify-end gap-3 mt-7",children:t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")})})]})}function qv({open:e,onClose:s}){const{t:i}=st(),[a,h]=_.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:G5},{id:"session",label:i("settings.tabs.session"),icon:hl},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:Tw}];return t.jsx($n,{open:e,onClose:s,size:"xl",children:t.jsx("div",{className:"card shadow-2xl rounded-2xl overflow-hidden",children:t.jsxs("div",{className:"flex",style:{minHeight:460},children:[t.jsxs("aside",{className:"w-44 shrink-0 border-r flex flex-col",style:{borderColor:"var(--color-border)",backgroundColor:"var(--color-bg-hover)"},children:[t.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")}),t.jsx("nav",{className:"flex flex-col",children:f.map(({id:m,label:o,icon:c})=>{const d=a===m;return t.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:[t.jsx(c,{size:14}),t.jsx("span",{children:o})]},m)})}),t.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.35"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(YE,{onClose:s}),a==="session"&&t.jsx(n3,{onClose:s}),a==="tunnel"&&t.jsx(VE,{onClose:s})]})]})})})}const lm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function s3(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 Ga(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:lm[s3(e.id,lm.length)]}const Kv=192,r3=88,Bc=8;function i3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:h}){const f=_.useRef(null),[m,o]=_.useState({left:s,top:i}),c=Ga(e);return _.useLayoutEffect(()=>{const d=Math.min(Math.max(s,Bc),window.innerWidth-Kv-Bc),p=Math.min(Math.max(i,Bc),window.innerHeight-r3-Bc);o({left:d,top:p})},[s,i]),_.useEffect(()=>{const d=u=>{var v;(v=f.current)!=null&&v.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]),rn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:Kv,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:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:8},children:lm.map(d=>{const p=e.color?d.toLowerCase()===e.color.toLowerCase():d===c&&!e.color;return t.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)})}),t.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 rl(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function a3(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 o3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},l3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},xn=_.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:h,type:f="button",title:m,className:o,...c},d){return t.jsx("button",{ref:d,type:f,"aria-label":s,"aria-pressed":h,title:m??s,className:Xs("btn-icon",o3[i],l3[a],o),...c})});function c3(e){return e==="executable"?Wm:e==="command"?di:Ua}function u3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:h,collapsed:f=!1,onToggleCollapsed:m}){var xe;const[o,c]=_.useState([]),[d,p]=_.useState({}),[u,v]=_.useState(null),[b,C]=_.useState(!1),[S,x]=_.useState(null),[y,w]=_.useState([]),[k,N]=_.useState(!1),[D,j]=_.useState(null),[R,E]=_.useState(!1),[L,A]=_.useState(null),[O,z]=_.useState(!1),[I,F]=_.useState(null),[H,U]=_.useState(null),q=Ds(),X=fi(),{t:B,toggleLang:P}=st(),{theme:$,toggleTheme:Y}=BE(),{enabled:W,supported:Z,toggleNotification:he}=Km(),{error:re,success:J,info:V,warning:pe}=Vi(),oe=((xe=q.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:xe[1])||null;_.useEffect(()=>{Ke(),le(),im().then(A).catch(()=>{})},[]);async function ge(){if(!O){z(!0);try{const ie=await im();if(A(ie),ie.status==="running"&&ie.url){await navigator.clipboard.writeText(ie.url),J(B("tunnel.urlCopied"));return}const we=await qw(),Q={status:"running",url:we.url};A(Q);try{await navigator.clipboard.writeText(we.url),J(B("tunnel.urlCopied"))}catch{J(we.url)}}catch(ie){re(ie instanceof Error?ie.message:B("tunnel.restartFailed"))}finally{z(!1)}}}function le(){EE().then(w).catch(()=>{})}const Oe=async ie=>{try{D?await LE(D.id,ie):await TE(ie),N(!1),j(null),le()}catch(we){re(we instanceof Error?we.message:"Failed to save favorite")}},He=async ie=>{try{await RE(ie)}catch(we){const Q=we instanceof Error?we.message:B("favorites.launchFailed");re(`${B("favorites.launchFailed")}: ${Q}`)}},Te=async(ie,we)=>{if(we.preventDefault(),we.stopPropagation(),!!confirm(B("favorites.deleteConfirm")))try{await DE(ie),w(Q=>Q.filter(K=>K.id!==ie))}catch(Q){re(Q instanceof Error?Q.message:"Failed to delete favorite")}},ye=(ie,we)=>{we.preventDefault(),we.stopPropagation(),j(ie),N(!0)};_.useEffect(()=>{const ie=()=>Ke();return window.addEventListener("projects:changed",ie),()=>window.removeEventListener("projects:changed",ie)},[]),_.useEffect(()=>{const ie=()=>ke();return window.addEventListener("review:changed",ie),()=>window.removeEventListener("review:changed",ie)},[]),_.useEffect(()=>a(ie=>{var we;if(ie.type==="project:status-changed"&&ie.projectId&&p(Q=>({...Q,[ie.projectId]:{running:ie.running??0,completed:ie.completed??0,total:ie.total??0,running_sessions:ie.running_sessions??0,running_discussions:ie.running_discussions??0}})),ie.type==="todo:status-changed"&&ke(),ie.type==="memory:ingest-finished"){const Q=o.find(je=>je.id===ie.projectId),K=(Q==null?void 0:Q.name)??"",ne=ie.sourceTitle?`“${ie.sourceTitle}”`:ie.sourceType??"",ee=K?`[${K}] `:"";if(ie.error){re(`${ee}${B("wiki.ingest.toast.failed")}: ${ie.error}`,6e3);return}const se=ie.created??0,ce=ie.updated??0,fe=ie.edgesAdded??0;if(se+ce+fe>0){const je=B("wiki.ingest.toast.success").replace("{source}",ne).replace("{created}",String(se)).replace("{updated}",String(ce)).replace("{edges}",String(fe));J(`${ee}${je}`)}else(we=ie.skipped)!=null&&we.parseFailed?pe(`${ee}${B("wiki.ingest.toast.parseFailed").replace("{source}",ne)}`,5e3):V(`${ee}${B("wiki.ingest.toast.empty").replace("{source}",ne)}`,4e3)}}),[a,o,B,re,V,J,pe]),_.useEffect(()=>{ke()},[]);function ke(){Gw({hours:24}).then(ie=>v(ie.total_todos)).catch(()=>{})}function Ke(){Hu().then(ie=>{c(ie),ie.forEach(we=>{Bw(we.id).then(Q=>{p(K=>({...K,[we.id]:Q}))}).catch(()=>{})})}).catch(()=>{})}const $e=()=>{h==null||h()},be=async(ie,we)=>{await zw({name:ie,path:we}),C(!1),window.dispatchEvent(new Event("projects:changed"))},De=_.useCallback(async(ie,we)=>{const Q=o.map(je=>je.id),K=Q.indexOf(ie);if(K<0)return;const ne=Q.filter(je=>je!==ie),ee=we>K?we-1:we;if(ee===K)return;const se=[...ne.slice(0,ee),ie,...ne.slice(ee)],ce=o,fe=new Map(o.map(je=>[je.id,je])),ue=se.map(je=>fe.get(je)).filter(Boolean);c(ue);try{await aE(se)}catch(je){c(ce),re(je instanceof Error?je.message:"Failed to reorder projects")}},[o,re]),Fe=_.useRef(!1),qe=_.useCallback((ie,we)=>{if(we.button!==0||we.target.closest("button"))return;we.preventDefault();const K=we.clientX,ne=we.clientY,ee=6;let se=!1,ce=null;const fe=Pe=>{const Ve=document.querySelectorAll("[data-workspace-item]");if(Ve.length===0)return null;const Ne=Ve[0].getBoundingClientRect();if(Pe<Ne.top)return 0;const it=Ve[Ve.length-1].getBoundingClientRect();if(Pe>it.bottom)return Ve.length;for(let lt=0;lt<Ve.length;lt++){const xt=Ve[lt].getBoundingClientRect();if(Pe>=xt.top&&Pe<=xt.bottom){const ft=xt.top+xt.height/2;return Pe<ft?lt:lt+1}}return null},ue=Pe=>{if(!se){if(Math.hypot(Pe.clientX-K,Pe.clientY-ne)<ee)return;se=!0,F(ie)}const Ve=fe(Pe.clientY);Ve!==ce&&(ce=Ve,U(Ve))},je=()=>{window.removeEventListener("mousemove",ue),window.removeEventListener("mouseup",Ue),window.removeEventListener("keydown",ut)},Ue=()=>{if(je(),!se)return;Fe.current=!0,requestAnimationFrame(()=>{Fe.current=!1});const Pe=ce;F(null),U(null),Pe!==null&&De(ie,Pe)},ut=Pe=>{Pe.key==="Escape"&&(je(),F(null),U(null),se&&(Fe.current=!0,requestAnimationFrame(()=>{Fe.current=!1})))};window.addEventListener("mousemove",ue),window.addEventListener("mouseup",Ue),window.addEventListener("keydown",ut)},[De]),Qe=async(ie,we)=>{if(we.preventDefault(),we.stopPropagation(),!!confirm(B("projects.deleteConfirm")))try{await Pw(ie),c(Q=>Q.filter(K=>K.id!==ie)),window.dispatchEvent(new Event("projects:changed")),oe===String(ie)&&X("/")}catch(Q){re(rl(Q,B("errors.projectDelete")))}},nt=ie=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...ie==="above"?{top:-1}:{bottom:-1}}});if(f){const ie=t.jsx("div",{className:"w-7 border-t my-1.5",style:{borderColor:"var(--color-border)"}});return t.jsxs("div",{className:"flex flex-col items-center h-full glass border-none py-3",children:[t.jsx(xn,{onClick:m,label:B("sidebar.expand"),size:"lg",children:t.jsx(yN,{size:18})}),ie,t.jsx(Pn,{to:"/",onClick:$e,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:B("sidebar.home"),children:t.jsx(Lv,{size:18})}),t.jsxs(Pn,{to:"/review",onClick:$e,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:B("sidebar.review"),children:[t.jsx(pu,{size:18}),u!==null&&u>0&&t.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]}),t.jsx(Pn,{to:"/agenda",onClick:$e,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:B("sidebar.agenda"),children:t.jsx(Xf,{size:18})}),ie,t.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(we=>{const Q=d[we.id],K=oe===String(we.id),ne=Q?Q.running+Q.running_sessions+Q.running_discussions:0,ee=ne>0,se=Ga(we);return t.jsxs(Pn,{to:`/projects/${we.id}`,onClick:$e,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:K?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:ee?`${we.name} · ${ne} ${B("detail.live")}`:we.name,children:[K&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),t.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${ee?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:K||ee?1:.55}})]},we.id)})}),ie,t.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?B("detail.live"):"Disconnected"}),t.jsx(xn,{onClick:Y,label:B($==="light"?"theme.dark":"theme.light"),size:"lg",children:$==="light"?t.jsx(Rv,{size:16}):t.jsx(Av,{size:16})}),t.jsx(xn,{onClick:()=>E(!0),label:B("settings.title"),size:"lg",children:t.jsx(xu,{size:16})}),t.jsx(qv,{open:R,onClose:()=>E(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full glass border-none",onDragStart:ie=>ie.preventDefault(),children:[t.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[t.jsx(Pn,{to:"/",onClick:$e,className:"block",children:t.jsxs("svg",{viewBox:"0 0 200 32",fill:"none",className:"h-6 w-auto",children:[t.jsxs("text",{x:"0",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-accent)",opacity:"0.5",children:[">","_"]}),t.jsx("text",{x:"38",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"700",fill:"var(--color-accent)",children:"CLI"}),t.jsx("text",{x:"96",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-text-primary)",children:"Trigger"})]})}),t.jsx(xn,{onClick:m,label:B("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(vN,{size:16})})]}),t.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[t.jsxs(Pn,{to:"/",onClick:$e,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==="/"&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),t.jsx(Lv,{size:16}),B("sidebar.home")]}),t.jsxs(Pn,{to:"/review",onClick:$e,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"&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),t.jsx(pu,{size:16}),t.jsx("span",{className:"flex-1",children:B("sidebar.review")}),u!==null&&u>0&&t.jsx("span",{className:"text-2xs px-1.5 py-0.5 rounded-full font-medium",style:{backgroundColor:"var(--color-accent)",color:"white"},children:u})]}),t.jsxs(Pn,{to:"/agenda",onClick:$e,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"&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),t.jsx(Xf,{size:16}),B("sidebar.agenda")]})]}),t.jsx("div",{className:"mx-4 border-t",style:{borderColor:"var(--color-border)"}}),t.jsxs("div",{className:"flex-1 overflow-y-auto px-3 pt-3",children:[t.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:B("sidebar.workspaces")}),t.jsx(xn,{onClick:()=>C(!0),label:B("projects.new"),size:"sm",children:t.jsx(mn,{size:14,strokeWidth:2})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((ie,we)=>{const Q=d[ie.id],K=oe===String(ie.id),ne=Q?Q.running+Q.running_sessions+Q.running_discussions:0,ee=ne>0,se=Ga(ie),ce=I===ie.id,fe=I!==null&&H===we,ue=I!==null&&we===o.length-1&&H===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[fe&&nt("above"),t.jsxs(Pn,{to:`/projects/${ie.id}`,draggable:!1,onDragStart:je=>je.preventDefault(),onClick:je=>{if(Fe.current){je.preventDefault();return}$e()},onMouseDown:je=>qe(ie.id,je),onContextMenu:je=>{je.preventDefault(),x({project:ie,x:je.clientX,y:je.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 ${K?"font-medium":""} ${ce?"opacity-50":""}`,style:K?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:I?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:I?"grabbing":"pointer",userSelect:"none"},children:[K&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),t.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${ee?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:K||ee?1:.55},title:ee?`${B("sidebar.workspaces")} · ${ne} ${B("detail.live")}`:ie.name}),t.jsx("span",{className:"truncate flex-1",children:ie.name}),t.jsx(xn,{onClick:je=>Qe(ie.id,je),label:B("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:t.jsx(Qt,{size:12,strokeWidth:2})})]}),ue&&nt("below")]},ie.id)})})]}),b&&t.jsx(Xw,{onSubmit:(ie,we)=>be(ie,we),onCancel:()=>C(!1)}),t.jsxs("div",{className:"px-3 pt-3 pb-2 border-t",style:{borderColor:"var(--color-border)"},children:[t.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:B("sidebar.favorites")}),t.jsx(xn,{onClick:()=>{j(null),N(!0)},label:B("favorites.add"),size:"sm",children:t.jsx(mn,{size:14,strokeWidth:2})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:y.map(ie=>{const we=c3(ie.type);return t.jsxs("button",{onClick:()=>He(ie.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:ie.target,children:[t.jsx(we,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:ie.name}),t.jsx("span",{onClick:Q=>ye(ie,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:B("favorites.edit"),children:t.jsx(em,{size:11,strokeWidth:2})}),t.jsx("span",{onClick:Q=>Te(ie.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:B("favorites.delete"),children:t.jsx(Qt,{size:12,strokeWidth:2})})]},ie.id)})})]}),k&&t.jsx(qE,{initial:D??void 0,onSubmit:Oe,onCancel:()=>{N(!1),j(null)}}),S&&t.jsx(i3,{project:S.project,anchorX:S.x,anchorY:S.y,onPick:async ie=>{try{const we=await tm(S.project.id,{color:ie});c(Q=>Q.map(K=>K.id===we.id?{...K,color:we.color}:K)),window.dispatchEvent(new Event("projects:changed"))}catch(we){re(we instanceof Error?we.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(qv,{open:R,onClose:()=>E(!1)}),t.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:t.jsxs("div",{className:"flex items-center gap-1 px-1",children:[t.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?B("detail.live"):"Disconnected"}),t.jsx(xn,{onClick:Y,label:B($==="light"?"theme.dark":"theme.light"),children:$==="light"?t.jsx(Rv,{size:16}):t.jsx(Av,{size:16})}),t.jsx(xn,{onClick:P,label:B("lang.toggle"),className:"text-xs font-medium",children:B("lang.toggle")}),Z&&t.jsx(xn,{onClick:he,label:"Notification"in window&&Notification.permission==="denied"?B("notification.blocked"):B("notification.toggle"),variant:W?"active":"default",pressed:W,children:W?t.jsx(Mj,{size:16}):t.jsx(Dj,{size:16})}),t.jsx(xn,{onClick:ge,disabled:O,label:B("tunnel.start"),variant:(L==null?void 0:L.status)==="running"?"active":"default",pressed:(L==null?void 0:L.status)==="running",title:(L==null?void 0:L.status)==="running"&&L.url?`${L.url} — ${B("tunnel.urlCopied")}`:B(O?"tunnel.starting":"tunnel.start"),children:t.jsx(Tw,{size:16})}),t.jsx(xn,{onClick:()=>E(!0),label:B("settings.title"),children:t.jsx(xu,{size:16})}),s&&t.jsx(xn,{onClick:e,label:B("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(rN,{size:16})})]})})]})}const d3=80,Vv=120,xr=180,Yv=.03,Xv=8;function h3(){const e=_.useRef(null),s=_.useRef({x:-1e3,y:-1e3}),i=_.useRef([]),a=_.useRef(0);return _.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<d3;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 v(){if(!f)return;f.clearRect(0,0,m,o);const b=i.current,C=s.current;for(const S of b){const x=S.x-C.x,y=S.y-C.y,w=Math.sqrt(x*x+y*y);if(w<xr&&w>0){const k=(xr-w)/xr,N=Math.atan2(y,x);S.vx+=Math.cos(N)*k*Xv*.05,S.vy+=Math.sin(N)*k*Xv*.05}S.vx+=(S.baseX-S.x)*Yv,S.vy+=(S.baseY-S.y)*Yv,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 k=S+1;k<b.length;k++){const N=b[S].x-b[k].x,D=b[S].y-b[k].y,j=Math.sqrt(N*N+D*D);if(j<Vv){const R=(1-j/Vv)*.15;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${R})`,f.lineWidth=.5,f.moveTo(b[S].x,b[S].y),f.lineTo(b[k].x,b[k].y),f.stroke()}}const x=b[S].x-C.x,y=b[S].y-C.y,w=Math.sqrt(x*x+y*y);if(w<xr){const k=(1-w/xr)*.3;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${k})`,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 x=S.x-C.x,y=S.y-C.y,w=Math.sqrt(x*x+y*y),k=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, ${k})`,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(v)}return c(),h.addEventListener("mousemove",p),h.addEventListener("mouseleave",u),window.addEventListener("resize",c),a.current=requestAnimationFrame(v),()=>{cancelAnimationFrame(a.current),h.removeEventListener("mousemove",p),h.removeEventListener("mouseleave",u),window.removeEventListener("resize",c)}},[]),t.jsx("canvas",{ref:e,className:"absolute inset-0 pointer-events-auto",style:{zIndex:0}})}function f3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:h}){const[f,m]=_.useState(!1),o=Ds(),{t:c}=st(),[d,p]=_.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),u=()=>{p(v=>{const b=!v;return localStorage.setItem("sidebarCollapsed",b?"1":"0"),b})};return t.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[t.jsx("aside",{className:`
602
+ */const JN=[["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"}]],QN=tt("zoom-out",JN);function ZN({onLogin:e}){const[s,i]=_.useState(""),[a,h]=_.useState(!1),[f,m]=_.useState(""),[o,c]=_.useState(!1),{t:d,toggleLang:p}=st(),u=async v=>{if(v.preventDefault(),!!s){m(""),c(!0);try{await e(s,a)}catch{m(d("login.error"))}finally{c(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:t.jsx(hl,{size:32,className:"text-accent",strokeWidth:1.5})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("login.subtitle")})]}),t.jsx("form",{onSubmit:u,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("login.password")}),t.jsx("input",{type:"password",value:s,onChange:v=>i(v.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),f&&t.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}),t.jsxs("label",{className:"flex items-center gap-2 mt-5 text-sm text-theme-text-secondary cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:a,onChange:v=>h(v.target.checked),className:"accent-accent w-4 h-4"}),d("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!s||o,className:"btn-primary w-full mt-6 py-3",children:d(o?"login.loading":"login.submit")})]})}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:d("login.footer")}),t.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:d("login.disclaimer")})]})]})}const zv=8;function eE({onSetup:e}){const[s,i]=_.useState(""),[a,h]=_.useState(""),[f,m]=_.useState(""),[o,c]=_.useState(!1),{t:d,toggleLang:p}=st(),u=s.length>0&&s.length<zv,v=a.length>0&&s!==a,b=s.length>=zv&&s===a&&!o,C=async S=>{if(S.preventDefault(),!!b){m(""),c(!0);try{await e(s,a)}catch(x){m(x instanceof Error&&x.message?x.message:d("setup.error"))}finally{c(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm animate-fade-in",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:t.jsx(hl,{size:32,className:"text-accent",strokeWidth:1.5})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("setup.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),t.jsx("form",{onSubmit:C,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),t.jsx("input",{type:"password",value:s,onChange:S=>i(S.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),u&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),t.jsx("input",{type:"password",value:a,onChange:S=>h(S.target.value),placeholder:"*************",className:"input-field text-base"}),v&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),f&&t.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}),t.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(o?"setup.loading":"setup.submit")})]})}),t.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 tE(e){return Ze("/api/projects/browse",{initialPath:e})}function nE(e){return Ze("/api/projects/open-folder",{path:e})}function Hu(){return dt("/api/projects")}function sE(e){return dt(`/api/projects/${e}`)}function zw(e){return Ze("/api/projects",e)}function rE(e){return dt(`/api/projects/${e}/svn-detect`)}function tm(e,s){return an(`/api/projects/${e}`,s)}function iE(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return dt(`/api/projects/${e}/debug-logs${i}`)}function Pw(e){return Bn(`/api/projects/${e}`)}function aE(e){return Ze("/api/projects/reorder",{ids:e})}function oE(e){return Ze(`/api/projects/${e}/start`)}function lE(e){return Ze(`/api/projects/${e}/stop`)}function Bw(e){return dt(`/api/projects/${e}/status`)}function Pv(){return dt("/api/active-work")}function cE(e){return Ze(`/api/projects/${e}/check-git`)}function Iw(e,s){return dt(`/api/projects/${e}/git-status`)}function uE(e,s=0,i=50,a){const h=new URLSearchParams({skip:String(s),limit:String(i)});return dt(`/api/projects/${e}/git-log?${h}`)}function nm(e,s){return dt(`/api/projects/${e}/git-refs`)}function dE(e,s){return Ze(`/api/projects/${e}/git-stage`,{files:s})}function hE(e,s){return Ze(`/api/projects/${e}/git-unstage`,{files:s})}function Hw(e,s){return Ze(`/api/projects/${e}/git-commit`,{message:s})}function Fw(e,s,i){return Ze(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function qm(e,s){return Ze(`/api/projects/${e}/git-push`,s||{})}function fE(e){return dt(`/api/projects/${e}/git-remotes`)}function $w(e,s,i){return Ze(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function mE(e,s,i){return Ze(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function sm(e,s,i){return Ze(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function rm(e,s){return Ze(`/api/projects/${e}/git-checkout`,{branch:s})}function Uw(e,s){return Ze(`/api/projects/${e}/git-merge`,{branch:s})}function Bv(e,s,i){return Ze(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i})}function pE(e){return Ze(`/api/projects/${e}/git-conflict-continue`)}function gE(e){return Ze(`/api/projects/${e}/git-conflict-abort`)}function xE(e,s){return Ze(`/api/projects/${e}/git-stash`,{message:s})}function vE(e,s){return Ze(`/api/projects/${e}/git-stash-pop`,{index:s})}function bE(e){return dt(`/api/projects/${e}/git-stash-list`)}function yE(e,s,i){return Ze(`/api/projects/${e}/git-discard`,{files:s,all:i})}function wE(e,s,i,a){return Ze(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function Iv(e,s,i){return Ze(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function _E(e,s){return Ze(`/api/projects/${e}/git-rebase`,{onto:s})}function SE(e,s,i){const a=new URLSearchParams;return s&&a.set("file",s),i&&a.set("staged","true"),dt(`/api/projects/${e}/git-diff?${a}`)}function kE(e,s){const i=new URLSearchParams({hash:s});return dt(`/api/projects/${e}/git-commit-files?${i}`)}function Hv(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),dt(`/api/projects/${e}/git-commit-diff?${a}`)}function Fv(e){return dt(`/api/projects/${e}/worktrees`)}function $v(e,s,i){return Ze(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function Ww(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 CE(e={}){return dt(`/api/review/queue${Ww(e)}`)}function Gw(e={}){return dt(`/api/review/summary${Ww(e)}`)}function jE(e){return dt(`/api/review/diff/${encodeURIComponent(e)}`)}function NE(e,s){return dt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function EE(){return dt("/api/favorites")}function TE(e){return Ze("/api/favorites",e)}function LE(e,s){return an(`/api/favorites/${e}`,s)}function DE(e){return Bn(`/api/favorites/${e}`)}function RE(e){return Ze(`/api/favorites/${e}/launch`)}function ME(e){return Ze("/api/favorites/browse-file",{initialPath:e})}function im(){return dt("/api/tunnel/status")}function AE(){return dt("/api/tunnel/config")}function OE(e){return an("/api/tunnel/config",e)}function qw(e){return Ze("/api/tunnel/start",{})}function zE(){return Ze("/api/tunnel/stop")}const Kw=_.createContext({theme:"light",toggleTheme:()=>{}});function PE(){const[e,s]=_.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});_.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=_.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function BE(){return _.useContext(Kw)}const Vw=_.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function IE(){const e="Notification"in window,[s,i]=_.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=_.useRef(s);_.useEffect(()=>{a.current=s},[s]);const h=_.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=_.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 Km(){return _.useContext(Vw)}let HE=0;const Yw=_.createContext(null);function FE({children:e}){const[s,i]=_.useState([]),a=_.useRef(new Map),h=_.useRef(new Map),f=_.useRef(new Map),m=_.useCallback(b=>{i(x=>x.filter(y=>y.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=_.useCallback((b,C="info",S=3500)=>{const x=`${C}:${b}`,y=h.current.get(x);if(y)return y;const w=`toast-${++HE}`;h.current.set(x,w),f.current.set(w,x),i(N=>[...N,{id:w,message:b,type:C,duration:S}]);const k=setTimeout(()=>m(w),S);return a.current.set(w,k),w},[m]),c=_.useCallback((b,C)=>o(b,"success",C),[o]),d=_.useCallback((b,C)=>o(b,"error",C),[o]),p=_.useCallback((b,C)=>o(b,"info",C),[o]),u=_.useCallback((b,C)=>o(b,"warning",C),[o]);_.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),h.current.clear(),f.current.clear()},[]);const v=_.useMemo(()=>({toasts:s,show:o,success:c,error:d,info:p,warning:u,dismiss:m}),[s,o,c,d,p,u,m]);return _.createElement(Yw.Provider,{value:v},e)}function Vi(){const e=_.useContext(Yw);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Xs(...e){return e.filter(Boolean).join(" ")}const $E={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl"},UE={scale:"animate-scale-in","slide-up":"animate-slide-up"};function $n({open:e,onClose:s,size:i="md",position:a="center",animation:h="scale",disableEscClose:f=!1,disableBackdropClose:m=!1,children:o}){const c=_.useRef(null);return _.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?rn.createPortal(t.jsx("div",{ref:c,className:Xs("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:t.jsx("div",{className:Xs("w-full",$E[i],UE[h]),children:o})}),document.body):null}function Xw({onSubmit:e,onCancel:s}){const[i,a]=_.useState(""),[h,f]=_.useState(""),[m,o]=_.useState(!1),[c,d]=_.useState(!1),[p,u]=_.useState(""),{t:v}=st(),b=async S=>{if(S.preventDefault(),!(!i.trim()||!h.trim())){u(""),d(!0);try{await e(i.trim(),h.trim())}catch(x){const y=x instanceof Error?x.message:String(x);u(y||v("form.createError"))}finally{d(!1)}}},C=async()=>{o(!0);try{const S=await tE(h||void 0);S.path&&f(S.path)}catch{}o(!1)};return t.jsx($n,{open:!0,onClose:s,size:"md",children:t.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:v("form.newProject")}),t.jsxs("form",{onSubmit:b,children:[t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:v("form.projectName")}),t.jsx("input",{type:"text",placeholder:"my-project",value:i,onChange:S=>a(S.target.value),className:"input-field",autoFocus:!0})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:v("form.folderPath")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:h,onChange:S=>f(S.target.value),className:"input-field text-sm flex-1"}),t.jsx("button",{type:"button",onClick:C,disabled:m,className:"btn-ghost text-sm px-3 shrink-0",title:v("browse.title"),children:m?t.jsx(Wi,{size:16,className:"animate-spin"}):t.jsx(zu,{size:16})})]})]}),p&&t.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:p}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:v("form.cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||!h.trim()||c,className:"btn-primary text-sm",children:v(c?"form.creating":"form.create")})]})]})]})})}const WE=[{value:"executable",icon:Wm},{value:"command",icon:di},{value:"url",icon:Ua}];function GE(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 Uv(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 qE({initial:e,onSubmit:s,onCancel:i}){const{t:a}=st(),[h,f]=_.useState((e==null?void 0:e.name)??""),[m,o]=_.useState((e==null?void 0:e.type)??"executable"),[c,d]=_.useState((e==null?void 0:e.target)??""),[p,u]=_.useState(Uv((e==null?void 0:e.args)??null)),[v,b]=_.useState((e==null?void 0:e.cwd)??""),[C,S]=_.useState(!1);_.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),d((e==null?void 0:e.target)??""),u(Uv((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[x,y]=_.useState(!1),w=m==="executable",k=async()=>{y(!0);try{const{path:O}=await ME(c||void 0);if(!O)return;if(d(O),!h.trim()){const z=O.replace(/\\/g,"/").split("/").pop()||"";f(z.replace(/\.[^.]+$/,""))}}catch{}finally{y(!1)}},N=!!e,D=h.trim(),j=c.trim(),R=m!=="url"||/^https?:\/\//i.test(j),E=!!D&&!!j&&R&&!C,L=async O=>{if(O.preventDefault(),!!E){S(!0);try{const z={name:D,type:m,target:j,args:m==="executable"&&p.trim()?GE(p.trim()):null,cwd:m!=="url"&&v.trim()?v.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 t.jsx($n,{open:!0,onClose:i,size:"md",children:t.jsxs("div",{className:"card p-8 shadow-2xl rounded-2xl",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:a(N?"favorites.form.title.edit":"favorites.form.title.create")}),t.jsxs("form",{onSubmit:L,children:[t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.type")}),t.jsx("div",{className:"grid grid-cols-3 gap-2",children:WE.map(({value:O,icon:z})=>t.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:[t.jsx(z,{size:14}),a(`favorites.types.${O}`)]},O))})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.name")}),t.jsx("input",{type:"text",value:h,onChange:O=>f(O.target.value),className:"input-field",autoFocus:!0})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.target")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:c,onChange:O=>d(O.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),w&&t.jsxs("button",{type:"button",onClick:k,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx(zu,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),m==="executable"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.args")}),t.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"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.cwd")}),t.jsx("input",{type:"text",value:v,onChange:O=>b(O.target.value),className:"input-field text-sm font-mono",placeholder:"C:/Projects/my-project"})]}),t.jsx("p",{className:"mb-6 text-2xs leading-snug",style:{color:"var(--color-text-muted)"},children:a("favorites.security.notice")}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:i,className:"btn-ghost text-sm",children:a("favorites.form.cancel")}),t.jsx("button",{type:"submit",disabled:!E,className:"btn-primary text-sm",children:a(N?"favorites.form.save":"favorites.form.create")})]})]})]})})}const KE=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function VE({onClose:e}){const{t:s}=st(),{error:i,success:a}=Vi(),[h,f]=_.useState(""),[m,o]=_.useState(""),[c,d]=_.useState(""),[p,u]=_.useState(""),[v,b]=_.useState(!1),[C,S]=_.useState(!1),[x,y]=_.useState(!1),[w,k]=_.useState(null);_.useEffect(()=>{let z=!1;return Promise.all([AE(),im()]).then(([I,F])=>{z||(f(I.tunnelName),o(I.customHostname),d(I.tunnelName),u(I.customHostname),k(F))}).catch(()=>{}),()=>{z=!0}},[]);const N=h.trim(),D=m.trim(),j=N!==c.trim()||D!==p.trim(),R=!!D&&(!KE.test(D)||D.toLowerCase()==="localhost"||D.toLowerCase()==="127.0.0.1"),E=!!D&&!N,L=j&&!C&&!R&&!E,A=async()=>{if(L){S(!0);try{const z=await OE({tunnelName:N,customHostname:D});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()=>{y(!0);try{try{await zE()}catch{}const z=await qw();k({status:"running",url:z.url}),a(s("tunnel.restarted"))}catch(z){i(z instanceof Error?z.message:s("tunnel.restartFailed"))}finally{y(!1)}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),w&&t.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:[t.jsx("span",{className:`w-2 h-2 rounded-full ${w.status==="running"?"bg-status-success":w.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${w.status}`)}),w.url&&t.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})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),t.jsx("input",{type:"text",value:h,onChange:z=>f(z.target.value),placeholder:s("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.name.hint")})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.hostname.label")}),t.jsx("input",{type:"text",value:m,onChange:z=>o(z.target.value),placeholder:s("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.hostname.hint")}),R&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),E&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.needsName")})]}),t.jsxs("div",{className:"mb-5",children:[t.jsxs("button",{type:"button",onClick:()=>b(!v),className:"flex items-center gap-1 text-xs text-accent-dark hover:text-accent transition-colors",children:[t.jsx("span",{className:`inline-block transition-transform ${v?"rotate-90":""}`,children:"▶"}),s("tunnel.guide.toggle")]}),v&&t.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:[t.jsx("p",{className:"font-semibold text-warm-700 mb-1",children:s("tunnel.guide.heading")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 ml-1",children:[t.jsx("li",{children:t.jsx("code",{className:"font-mono",children:"cloudflared tunnel login"})}),t.jsx("li",{children:t.jsx("code",{className:"font-mono",children:"cloudflared tunnel create my-app"})}),t.jsx("li",{children:t.jsx("code",{className:"font-mono",children:"cloudflared tunnel route dns my-app app.your-domain.com"})}),t.jsx("li",{children:s("tunnel.guide.step4")})]}),t.jsx("p",{className:"text-2xs text-warm-400 pt-1",children:s("tunnel.guide.note")})]})]}),t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("button",{type:"button",onClick:O,disabled:x,className:"btn-ghost text-sm disabled:opacity-50",children:x?(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")}),t.jsxs("div",{className:"flex gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),t.jsx("button",{type:"button",onClick:A,disabled:!L,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const Wv=8;function YE({onClose:e}){const{t:s}=st(),{error:i,success:a}=Vi(),[h,f]=_.useState(""),[m,o]=_.useState(""),[c,d]=_.useState(""),[p,u]=_.useState(!1),v=m.length>0&&m.length<Wv,b=c.length>0&&m!==c,C=!!h&&m.length>=Wv&&m===c&&!p,S=()=>{f(""),o(""),d("")},x=async()=>{if(C){u(!0);try{await oj(h,m,c),a(s("account.saved")),S()}catch(y){i(y instanceof Error&&y.message?y.message:s("account.saveFailed"))}finally{u(!1)}}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("account.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("account.description")}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.oldPassword")}),t.jsx("input",{type:"password",value:h,onChange:y=>f(y.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.newPassword")}),t.jsx("input",{type:"password",value:m,onChange:y=>o(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),v&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.tooShort")})]}),t.jsxs("div",{className:"mb-6",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.confirm")}),t.jsx("input",{type:"password",value:c,onChange:y=>d(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),t.jsx("button",{type:"button",onClick:x,disabled:!C,className:"btn-primary text-sm",children:s(p?"account.saving":"account.save")})]})]})}function Vm(){return dt("/api/session-tags")}function XE(e){return Ze("/api/session-tags",e)}function JE(e,s){return an(`/api/session-tags/${e}`,s)}function QE(e){return Bn(`/api/session-tags/${e}`)}function Jw(){return dt("/api/session-aliases")}function Qw(e){return Ze("/api/session-aliases",e)}function ZE(e,s){return an(`/api/session-aliases/${e}`,s)}function e3(e){return Bn(`/api/session-aliases/${e}`)}function Ym(){return dt("/api/session-settings")}function hf(e){return an("/api/session-settings",e)}const Ie={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",Xm=13,el=8,tl=28,Wa=new Map,Fi=new Map;let vu=Xm;function Jm(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);Wa.delete(s);const i=Fi.get(s);if(i){const h=nl(s);i.forEach(f=>f(h))}});function am(e){return Number.isFinite(e)?Math.max(el,Math.min(tl,Math.round(e))):vu}function t3(e){if(Wa.has(e))return!0;try{return localStorage.getItem(Jm(e))!==null}catch{return!1}}function nl(e){const s=Wa.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(Jm(e));if(a!==null){const h=parseInt(a,10);Number.isFinite(h)&&(i=am(h))}}catch{}return i===null?am(vu):(Wa.set(e,i),i)}function om(e,s){const i=am(s);if(Wa.get(e)===i)return;Wa.set(e,i);try{localStorage.setItem(Jm(e),String(i))}catch{}const a=Fi.get(e);a&&a.forEach(h=>h(i))}function Wo(e,s){om(e,nl(e)+s)}function au(e){const s=Math.max(el,Math.min(tl,Math.round(e)));Number.isFinite(s)&&s!==vu&&(vu=s,Fi.forEach((i,a)=>{t3(a)||i.forEach(h=>h(s))}))}function Zw(e){const[s,i]=_.useState(()=>nl(e));_.useEffect(()=>{i(nl(e));let f=Fi.get(e);return f||(f=new Set,Fi.set(e,f)),f.add(i),()=>{const m=Fi.get(e);m&&(m.delete(i),m.size===0&&Fi.delete(e))}},[e]);const a=_.useCallback(f=>om(e,f),[e]),h=_.useCallback(f=>om(e,nl(e)+f),[e]);return[s,a,h]}const sl=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function Gv(e){for(const s of sl)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return sl[e.length%sl.length]}function n3({onClose:e}){const{t:s}=st(),{error:i,success:a}=Vi(),[h,f]=_.useState([]),[m,o]=_.useState(!1),[c,d]=_.useState(Xm),[p,u]=_.useState(!1),[v,b]=_.useState(!1),[C,S]=_.useState(!1),[x,y]=_.useState(!1),w=_.useRef(null),[k,N]=_.useState(""),[D,j]=_.useState(sl[0]),[R,E]=_.useState(!1),[L,A]=_.useState(null),[O,z]=_.useState(""),[I,F]=_.useState(sl[0]),[H,U]=_.useState(!1),[q,X]=_.useState([]),[B,P]=_.useState(""),[$,Y]=_.useState(""),[W,Z]=_.useState(!1),[he,re]=_.useState(null),[J,V]=_.useState(""),[pe,oe]=_.useState(""),[ge,le]=_.useState(!1);_.useEffect(()=>{let se=!1;return Promise.all([Vm(),Ym(),Jw()]).then(([ce,fe,ue])=>{se||(f(ce),o(fe.defaultUseWorktree),d(fe.defaultFontSize),au(fe.defaultFontSize),u(fe.imeDebug),j(Gv(ce)),X(ue),b(!0))}).catch(ce=>{se||i(ce instanceof Error?ce.message:"Failed to load")}),()=>{se=!0}},[i]);const Oe=k.trim(),He=!!Oe&&!R,Te=_.useMemo(()=>[...h].sort((se,ce)=>se.sort_order-ce.sort_order||se.name.localeCompare(ce.name)),[h]);_.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const ye=se=>{if(!Number.isFinite(se))return;const ce=Math.max(el,Math.min(tl,Math.round(se)));d(ce),au(ce),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{hf({defaultFontSize:ce}).then(fe=>{d(fe.defaultFontSize),au(fe.defaultFontSize)}).catch(fe=>i(fe instanceof Error?fe.message:"Save failed"))},350)},ke=async se=>{S(!0);try{const ce=await hf({defaultUseWorktree:se});o(ce.defaultUseWorktree),a(s("sessionSettings.saved"))}catch(ce){i(ce instanceof Error?ce.message:"Save failed")}finally{S(!1)}},Ke=async se=>{var ce,fe;y(!0);try{const ue=await hf({imeDebug:se});u(ue.imeDebug),(fe=(ce=window.electronAPI)==null?void 0:ce.imeSetDebug)==null||fe.call(ce,ue.imeDebug),a(s("sessionSettings.saved"))}catch(ue){i(ue instanceof Error?ue.message:"Save failed")}finally{y(!1)}},$e=async()=>{if(He){E(!0);try{const se=await XE({name:Oe,color:D});f(ce=>[...ce,se]),N(""),j(Gv([...h,se]))}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{E(!1)}}},be=se=>{A(se.id),z(se.name),F(se.color)},De=()=>{A(null),z("")},Fe=async()=>{if(!L)return;const se=O.trim();if(se){U(!0);try{const ce=await JE(L,{name:se,color:I});f(fe=>fe.map(ue=>ue.id===ce.id?ce:ue)),De()}catch(ce){i(ce instanceof Error?ce.message:"Save failed")}finally{U(!1)}}},qe=async se=>{if(confirm(s("sessionSettings.tags.deleteConfirm").replace("{name}",se.name)))try{await QE(se.id),f(ce=>ce.filter(fe=>fe.id!==se.id))}catch(ce){i(ce instanceof Error?ce.message:"Delete failed")}},Qe=B.trim(),nt=$.trim(),xe=!!Qe&&!!nt&&!W,ie=_.useMemo(()=>[...q].sort((se,ce)=>se.sort_order-ce.sort_order||se.name.localeCompare(ce.name)),[q]),we=async()=>{if(xe){Z(!0);try{const se=await Qw({name:Qe,command_template:nt});X(ce=>[...ce,se]),P(""),Y("")}catch(se){i(se instanceof Error?se.message:"Create failed")}finally{Z(!1)}}},Q=se=>{re(se.id),V(se.name),oe(se.command_template)},K=()=>{re(null),V(""),oe("")},ne=async()=>{if(!he)return;const se=J.trim(),ce=pe.trim();if(!(!se||!ce)){le(!0);try{const fe=await ZE(he,{name:se,command_template:ce});X(ue=>ue.map(je=>je.id===fe.id?fe:je)),K()}catch(fe){i(fe instanceof Error?fe.message:"Save failed")}finally{le(!1)}}},ee=async se=>{if(confirm(`Delete alias "${se.name}"? Sessions using it will fall back to OS default shell.`))try{await e3(se.id),X(ce=>ce.filter(fe=>fe.id!==se.id))}catch(ce){i(ce instanceof Error?ce.message:"Delete failed")}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("sessionSettings.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("sessionSettings.description")}),t.jsxs("section",{className:"mb-7",children:[t.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[t.jsx(Ya,{size:14}),s("sessionSettings.worktree.title")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:m,disabled:C||!v,onChange:se=>ke(se.target.checked),className:"rounded border-warm-300"}),t.jsx("span",{className:"text-sm text-warm-600",children:s("sessionSettings.worktree.label")})]}),t.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.worktree.hint")})]}),t.jsxs("section",{className:"mb-7",children:[t.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[t.jsx($N,{size:14}),s("sessionSettings.fontSize.title")]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("input",{type:"range",min:el,max:tl,step:1,value:c,disabled:!v,onChange:se=>ye(parseInt(se.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),t.jsx("input",{type:"number",min:el,max:tl,step:1,value:c,disabled:!v,onChange:se=>ye(parseInt(se.target.value,10)),className:"input text-sm w-20"}),t.jsx("span",{className:"text-xs text-warm-400",children:"px"})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("sessionSettings.fontSize.hint")})]}),t.jsxs("section",{children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:s("sessionSettings.tags.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-3",children:s("sessionSettings.tags.description")}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx("input",{type:"color",value:D,onChange:se=>j(se.target.value),className:"w-9 h-9 rounded cursor-pointer border border-warm-200",title:s("sessionSettings.tags.color")}),t.jsx("input",{type:"text",value:k,onChange:se=>N(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),$e())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),t.jsxs("button",{type:"button",onClick:$e,disabled:!He,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(mn,{size:14}),s("sessionSettings.tags.add")]})]}),Te.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:s("sessionSettings.tags.empty")}):t.jsx("ul",{className:"space-y-1.5",children:Te.map(se=>{const ce=L===se.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ce?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:I,onChange:fe=>F(fe.target.value),className:"w-7 h-7 rounded cursor-pointer border border-warm-200"}),t.jsx("input",{type:"text",value:O,onChange:fe=>z(fe.target.value),onKeyDown:fe=>{fe.key==="Enter"&&(fe.preventDefault(),Fe()),fe.key==="Escape"&&De()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),t.jsx("button",{type:"button",onClick:Fe,disabled:H||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:s("sessionSettings.tags.save"),children:t.jsx(ai,{size:14})}),t.jsx("button",{type:"button",onClick:De,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.cancel"),children:t.jsx(Qt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:se.color,borderColor:"rgba(0,0,0,0.08)"}}),t.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:se.name}),t.jsx("button",{type:"button",onClick:()=>be(se),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded",title:s("sessionSettings.tags.edit"),children:t.jsx(ci,{size:14})}),t.jsx("button",{type:"button",onClick:()=>qe(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:s("sessionSettings.tags.delete"),children:t.jsx(jn,{size:14})})]})},se.id)})})]}),t.jsxs("section",{className:"mt-7",children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:"Terminal aliases"}),t.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."}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx("input",{type:"text",value:B,onChange:se=>P(se.target.value),placeholder:"Name (e.g. WSL Ubuntu)",className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:$,onChange:se=>Y(se.target.value),onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),we())},placeholder:"Command (e.g. wsl -d Ubuntu)",className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsxs("button",{type:"button",onClick:we,disabled:!xe,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(mn,{size:14}),"Add"]})]}),ie.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:"No aliases yet."}):t.jsx("ul",{className:"space-y-1.5",children:ie.map(se=>{const ce=he===se.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ce?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:J,onChange:fe=>V(fe.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:pe,onChange:fe=>oe(fe.target.value),onKeyDown:fe=>{fe.key==="Enter"&&(fe.preventDefault(),ne()),fe.key==="Escape"&&K()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:ne,disabled:ge||!J.trim()||!pe.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded",title:"Save",children:t.jsx(ai,{size:14})}),t.jsx("button",{type:"button",onClick:K,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded",title:"Cancel",children:t.jsx(Qt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:se.name}),t.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:se.command_template}),t.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:t.jsx(ci,{size:14})}),t.jsx("button",{type:"button",onClick:()=>ee(se),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded",title:"Delete",children:t.jsx(jn,{size:14})})]})},se.id)})})]}),t.jsxs("section",{className:"mt-7",children:[t.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[t.jsx(Oj,{size:14}),"IME 디버그 로그"]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:p,disabled:x||!v,onChange:se=>Ke(se.target.checked),className:"rounded border-warm-300"}),t.jsx("span",{className:"text-sm text-warm-600",children:"한글 입력(IME) 진단 로그 기록"})]}),t.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:"조합 창이 화면 좌상단에 뜨는 문제를 진단하기 위해 입력 시점 상태를 기록합니다. 데스크톱 앱에서만 동작하며, 로그는 앱 데이터 폴더의 ime-debug.log에 저장됩니다."})]}),e&&t.jsx("div",{className:"flex justify-end gap-3 mt-7",children:t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")})})]})}function qv({open:e,onClose:s}){const{t:i}=st(),[a,h]=_.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:G5},{id:"session",label:i("settings.tabs.session"),icon:hl},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:Tw}];return t.jsx($n,{open:e,onClose:s,size:"xl",children:t.jsx("div",{className:"card shadow-2xl rounded-2xl overflow-hidden",children:t.jsxs("div",{className:"flex",style:{minHeight:460},children:[t.jsxs("aside",{className:"w-44 shrink-0 border-r flex flex-col",style:{borderColor:"var(--color-border)",backgroundColor:"var(--color-bg-hover)"},children:[t.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")}),t.jsx("nav",{className:"flex flex-col",children:f.map(({id:m,label:o,icon:c})=>{const d=a===m;return t.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:[t.jsx(c,{size:14}),t.jsx("span",{children:o})]},m)})}),t.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.36"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(YE,{onClose:s}),a==="session"&&t.jsx(n3,{onClose:s}),a==="tunnel"&&t.jsx(VE,{onClose:s})]})]})})})}const lm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function s3(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 Ga(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:lm[s3(e.id,lm.length)]}const Kv=192,r3=88,Bc=8;function i3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:h}){const f=_.useRef(null),[m,o]=_.useState({left:s,top:i}),c=Ga(e);return _.useLayoutEffect(()=>{const d=Math.min(Math.max(s,Bc),window.innerWidth-Kv-Bc),p=Math.min(Math.max(i,Bc),window.innerHeight-r3-Bc);o({left:d,top:p})},[s,i]),_.useEffect(()=>{const d=u=>{var v;(v=f.current)!=null&&v.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]),rn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:Kv,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:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:8},children:lm.map(d=>{const p=e.color?d.toLowerCase()===e.color.toLowerCase():d===c&&!e.color;return t.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)})}),t.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 rl(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function a3(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 o3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},l3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},xn=_.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:h,type:f="button",title:m,className:o,...c},d){return t.jsx("button",{ref:d,type:f,"aria-label":s,"aria-pressed":h,title:m??s,className:Xs("btn-icon",o3[i],l3[a],o),...c})});function c3(e){return e==="executable"?Wm:e==="command"?di:Ua}function u3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:h,collapsed:f=!1,onToggleCollapsed:m}){var xe;const[o,c]=_.useState([]),[d,p]=_.useState({}),[u,v]=_.useState(null),[b,C]=_.useState(!1),[S,x]=_.useState(null),[y,w]=_.useState([]),[k,N]=_.useState(!1),[D,j]=_.useState(null),[R,E]=_.useState(!1),[L,A]=_.useState(null),[O,z]=_.useState(!1),[I,F]=_.useState(null),[H,U]=_.useState(null),q=Ds(),X=fi(),{t:B,toggleLang:P}=st(),{theme:$,toggleTheme:Y}=BE(),{enabled:W,supported:Z,toggleNotification:he}=Km(),{error:re,success:J,info:V,warning:pe}=Vi(),oe=((xe=q.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:xe[1])||null;_.useEffect(()=>{Ke(),le(),im().then(A).catch(()=>{})},[]);async function ge(){if(!O){z(!0);try{const ie=await im();if(A(ie),ie.status==="running"&&ie.url){await navigator.clipboard.writeText(ie.url),J(B("tunnel.urlCopied"));return}const we=await qw(),Q={status:"running",url:we.url};A(Q);try{await navigator.clipboard.writeText(we.url),J(B("tunnel.urlCopied"))}catch{J(we.url)}}catch(ie){re(ie instanceof Error?ie.message:B("tunnel.restartFailed"))}finally{z(!1)}}}function le(){EE().then(w).catch(()=>{})}const Oe=async ie=>{try{D?await LE(D.id,ie):await TE(ie),N(!1),j(null),le()}catch(we){re(we instanceof Error?we.message:"Failed to save favorite")}},He=async ie=>{try{await RE(ie)}catch(we){const Q=we instanceof Error?we.message:B("favorites.launchFailed");re(`${B("favorites.launchFailed")}: ${Q}`)}},Te=async(ie,we)=>{if(we.preventDefault(),we.stopPropagation(),!!confirm(B("favorites.deleteConfirm")))try{await DE(ie),w(Q=>Q.filter(K=>K.id!==ie))}catch(Q){re(Q instanceof Error?Q.message:"Failed to delete favorite")}},ye=(ie,we)=>{we.preventDefault(),we.stopPropagation(),j(ie),N(!0)};_.useEffect(()=>{const ie=()=>Ke();return window.addEventListener("projects:changed",ie),()=>window.removeEventListener("projects:changed",ie)},[]),_.useEffect(()=>{const ie=()=>ke();return window.addEventListener("review:changed",ie),()=>window.removeEventListener("review:changed",ie)},[]),_.useEffect(()=>a(ie=>{var we;if(ie.type==="project:status-changed"&&ie.projectId&&p(Q=>({...Q,[ie.projectId]:{running:ie.running??0,completed:ie.completed??0,total:ie.total??0,running_sessions:ie.running_sessions??0,running_discussions:ie.running_discussions??0}})),ie.type==="todo:status-changed"&&ke(),ie.type==="memory:ingest-finished"){const Q=o.find(je=>je.id===ie.projectId),K=(Q==null?void 0:Q.name)??"",ne=ie.sourceTitle?`“${ie.sourceTitle}”`:ie.sourceType??"",ee=K?`[${K}] `:"";if(ie.error){re(`${ee}${B("wiki.ingest.toast.failed")}: ${ie.error}`,6e3);return}const se=ie.created??0,ce=ie.updated??0,fe=ie.edgesAdded??0;if(se+ce+fe>0){const je=B("wiki.ingest.toast.success").replace("{source}",ne).replace("{created}",String(se)).replace("{updated}",String(ce)).replace("{edges}",String(fe));J(`${ee}${je}`)}else(we=ie.skipped)!=null&&we.parseFailed?pe(`${ee}${B("wiki.ingest.toast.parseFailed").replace("{source}",ne)}`,5e3):V(`${ee}${B("wiki.ingest.toast.empty").replace("{source}",ne)}`,4e3)}}),[a,o,B,re,V,J,pe]),_.useEffect(()=>{ke()},[]);function ke(){Gw({hours:24}).then(ie=>v(ie.total_todos)).catch(()=>{})}function Ke(){Hu().then(ie=>{c(ie),ie.forEach(we=>{Bw(we.id).then(Q=>{p(K=>({...K,[we.id]:Q}))}).catch(()=>{})})}).catch(()=>{})}const $e=()=>{h==null||h()},be=async(ie,we)=>{await zw({name:ie,path:we}),C(!1),window.dispatchEvent(new Event("projects:changed"))},De=_.useCallback(async(ie,we)=>{const Q=o.map(je=>je.id),K=Q.indexOf(ie);if(K<0)return;const ne=Q.filter(je=>je!==ie),ee=we>K?we-1:we;if(ee===K)return;const se=[...ne.slice(0,ee),ie,...ne.slice(ee)],ce=o,fe=new Map(o.map(je=>[je.id,je])),ue=se.map(je=>fe.get(je)).filter(Boolean);c(ue);try{await aE(se)}catch(je){c(ce),re(je instanceof Error?je.message:"Failed to reorder projects")}},[o,re]),Fe=_.useRef(!1),qe=_.useCallback((ie,we)=>{if(we.button!==0||we.target.closest("button"))return;we.preventDefault();const K=we.clientX,ne=we.clientY,ee=6;let se=!1,ce=null;const fe=Pe=>{const Ve=document.querySelectorAll("[data-workspace-item]");if(Ve.length===0)return null;const Ne=Ve[0].getBoundingClientRect();if(Pe<Ne.top)return 0;const it=Ve[Ve.length-1].getBoundingClientRect();if(Pe>it.bottom)return Ve.length;for(let lt=0;lt<Ve.length;lt++){const xt=Ve[lt].getBoundingClientRect();if(Pe>=xt.top&&Pe<=xt.bottom){const ft=xt.top+xt.height/2;return Pe<ft?lt:lt+1}}return null},ue=Pe=>{if(!se){if(Math.hypot(Pe.clientX-K,Pe.clientY-ne)<ee)return;se=!0,F(ie)}const Ve=fe(Pe.clientY);Ve!==ce&&(ce=Ve,U(Ve))},je=()=>{window.removeEventListener("mousemove",ue),window.removeEventListener("mouseup",Ue),window.removeEventListener("keydown",ut)},Ue=()=>{if(je(),!se)return;Fe.current=!0,requestAnimationFrame(()=>{Fe.current=!1});const Pe=ce;F(null),U(null),Pe!==null&&De(ie,Pe)},ut=Pe=>{Pe.key==="Escape"&&(je(),F(null),U(null),se&&(Fe.current=!0,requestAnimationFrame(()=>{Fe.current=!1})))};window.addEventListener("mousemove",ue),window.addEventListener("mouseup",Ue),window.addEventListener("keydown",ut)},[De]),Qe=async(ie,we)=>{if(we.preventDefault(),we.stopPropagation(),!!confirm(B("projects.deleteConfirm")))try{await Pw(ie),c(Q=>Q.filter(K=>K.id!==ie)),window.dispatchEvent(new Event("projects:changed")),oe===String(ie)&&X("/")}catch(Q){re(rl(Q,B("errors.projectDelete")))}},nt=ie=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...ie==="above"?{top:-1}:{bottom:-1}}});if(f){const ie=t.jsx("div",{className:"w-7 border-t my-1.5",style:{borderColor:"var(--color-border)"}});return t.jsxs("div",{className:"flex flex-col items-center h-full glass border-none py-3",children:[t.jsx(xn,{onClick:m,label:B("sidebar.expand"),size:"lg",children:t.jsx(yN,{size:18})}),ie,t.jsx(Pn,{to:"/",onClick:$e,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:B("sidebar.home"),children:t.jsx(Lv,{size:18})}),t.jsxs(Pn,{to:"/review",onClick:$e,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:B("sidebar.review"),children:[t.jsx(pu,{size:18}),u!==null&&u>0&&t.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]}),t.jsx(Pn,{to:"/agenda",onClick:$e,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:B("sidebar.agenda"),children:t.jsx(Xf,{size:18})}),ie,t.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(we=>{const Q=d[we.id],K=oe===String(we.id),ne=Q?Q.running+Q.running_sessions+Q.running_discussions:0,ee=ne>0,se=Ga(we);return t.jsxs(Pn,{to:`/projects/${we.id}`,onClick:$e,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:K?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:ee?`${we.name} · ${ne} ${B("detail.live")}`:we.name,children:[K&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),t.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${ee?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:K||ee?1:.55}})]},we.id)})}),ie,t.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?B("detail.live"):"Disconnected"}),t.jsx(xn,{onClick:Y,label:B($==="light"?"theme.dark":"theme.light"),size:"lg",children:$==="light"?t.jsx(Rv,{size:16}):t.jsx(Av,{size:16})}),t.jsx(xn,{onClick:()=>E(!0),label:B("settings.title"),size:"lg",children:t.jsx(xu,{size:16})}),t.jsx(qv,{open:R,onClose:()=>E(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full glass border-none",onDragStart:ie=>ie.preventDefault(),children:[t.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[t.jsx(Pn,{to:"/",onClick:$e,className:"block",children:t.jsxs("svg",{viewBox:"0 0 200 32",fill:"none",className:"h-6 w-auto",children:[t.jsxs("text",{x:"0",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-accent)",opacity:"0.5",children:[">","_"]}),t.jsx("text",{x:"38",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"700",fill:"var(--color-accent)",children:"CLI"}),t.jsx("text",{x:"96",y:"24",fontFamily:"'JetBrains Mono', monospace",fontSize:"22",fontWeight:"500",fill:"var(--color-text-primary)",children:"Trigger"})]})}),t.jsx(xn,{onClick:m,label:B("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(vN,{size:16})})]}),t.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[t.jsxs(Pn,{to:"/",onClick:$e,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==="/"&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),t.jsx(Lv,{size:16}),B("sidebar.home")]}),t.jsxs(Pn,{to:"/review",onClick:$e,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"&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),t.jsx(pu,{size:16}),t.jsx("span",{className:"flex-1",children:B("sidebar.review")}),u!==null&&u>0&&t.jsx("span",{className:"text-2xs px-1.5 py-0.5 rounded-full font-medium",style:{backgroundColor:"var(--color-accent)",color:"white"},children:u})]}),t.jsxs(Pn,{to:"/agenda",onClick:$e,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"&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),t.jsx(Xf,{size:16}),B("sidebar.agenda")]})]}),t.jsx("div",{className:"mx-4 border-t",style:{borderColor:"var(--color-border)"}}),t.jsxs("div",{className:"flex-1 overflow-y-auto px-3 pt-3",children:[t.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:B("sidebar.workspaces")}),t.jsx(xn,{onClick:()=>C(!0),label:B("projects.new"),size:"sm",children:t.jsx(mn,{size:14,strokeWidth:2})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((ie,we)=>{const Q=d[ie.id],K=oe===String(ie.id),ne=Q?Q.running+Q.running_sessions+Q.running_discussions:0,ee=ne>0,se=Ga(ie),ce=I===ie.id,fe=I!==null&&H===we,ue=I!==null&&we===o.length-1&&H===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[fe&&nt("above"),t.jsxs(Pn,{to:`/projects/${ie.id}`,draggable:!1,onDragStart:je=>je.preventDefault(),onClick:je=>{if(Fe.current){je.preventDefault();return}$e()},onMouseDown:je=>qe(ie.id,je),onContextMenu:je=>{je.preventDefault(),x({project:ie,x:je.clientX,y:je.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 ${K?"font-medium":""} ${ce?"opacity-50":""}`,style:K?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:I?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:I?"grabbing":"pointer",userSelect:"none"},children:[K&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:se}}),t.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${ee?"workspace-dot-pulse":""}`,style:{backgroundColor:se,opacity:K||ee?1:.55},title:ee?`${B("sidebar.workspaces")} · ${ne} ${B("detail.live")}`:ie.name}),t.jsx("span",{className:"truncate flex-1",children:ie.name}),t.jsx(xn,{onClick:je=>Qe(ie.id,je),label:B("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:t.jsx(Qt,{size:12,strokeWidth:2})})]}),ue&&nt("below")]},ie.id)})})]}),b&&t.jsx(Xw,{onSubmit:(ie,we)=>be(ie,we),onCancel:()=>C(!1)}),t.jsxs("div",{className:"px-3 pt-3 pb-2 border-t",style:{borderColor:"var(--color-border)"},children:[t.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:B("sidebar.favorites")}),t.jsx(xn,{onClick:()=>{j(null),N(!0)},label:B("favorites.add"),size:"sm",children:t.jsx(mn,{size:14,strokeWidth:2})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:y.map(ie=>{const we=c3(ie.type);return t.jsxs("button",{onClick:()=>He(ie.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:ie.target,children:[t.jsx(we,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:ie.name}),t.jsx("span",{onClick:Q=>ye(ie,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:B("favorites.edit"),children:t.jsx(em,{size:11,strokeWidth:2})}),t.jsx("span",{onClick:Q=>Te(ie.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:B("favorites.delete"),children:t.jsx(Qt,{size:12,strokeWidth:2})})]},ie.id)})})]}),k&&t.jsx(qE,{initial:D??void 0,onSubmit:Oe,onCancel:()=>{N(!1),j(null)}}),S&&t.jsx(i3,{project:S.project,anchorX:S.x,anchorY:S.y,onPick:async ie=>{try{const we=await tm(S.project.id,{color:ie});c(Q=>Q.map(K=>K.id===we.id?{...K,color:we.color}:K)),window.dispatchEvent(new Event("projects:changed"))}catch(we){re(we instanceof Error?we.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(qv,{open:R,onClose:()=>E(!1)}),t.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:t.jsxs("div",{className:"flex items-center gap-1 px-1",children:[t.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?B("detail.live"):"Disconnected"}),t.jsx(xn,{onClick:Y,label:B($==="light"?"theme.dark":"theme.light"),children:$==="light"?t.jsx(Rv,{size:16}):t.jsx(Av,{size:16})}),t.jsx(xn,{onClick:P,label:B("lang.toggle"),className:"text-xs font-medium",children:B("lang.toggle")}),Z&&t.jsx(xn,{onClick:he,label:"Notification"in window&&Notification.permission==="denied"?B("notification.blocked"):B("notification.toggle"),variant:W?"active":"default",pressed:W,children:W?t.jsx(Mj,{size:16}):t.jsx(Dj,{size:16})}),t.jsx(xn,{onClick:ge,disabled:O,label:B("tunnel.start"),variant:(L==null?void 0:L.status)==="running"?"active":"default",pressed:(L==null?void 0:L.status)==="running",title:(L==null?void 0:L.status)==="running"&&L.url?`${L.url} — ${B("tunnel.urlCopied")}`:B(O?"tunnel.starting":"tunnel.start"),children:t.jsx(Tw,{size:16})}),t.jsx(xn,{onClick:()=>E(!0),label:B("settings.title"),children:t.jsx(xu,{size:16})}),s&&t.jsx(xn,{onClick:e,label:B("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(rN,{size:16})})]})})]})}const d3=80,Vv=120,xr=180,Yv=.03,Xv=8;function h3(){const e=_.useRef(null),s=_.useRef({x:-1e3,y:-1e3}),i=_.useRef([]),a=_.useRef(0);return _.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<d3;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 v(){if(!f)return;f.clearRect(0,0,m,o);const b=i.current,C=s.current;for(const S of b){const x=S.x-C.x,y=S.y-C.y,w=Math.sqrt(x*x+y*y);if(w<xr&&w>0){const k=(xr-w)/xr,N=Math.atan2(y,x);S.vx+=Math.cos(N)*k*Xv*.05,S.vy+=Math.sin(N)*k*Xv*.05}S.vx+=(S.baseX-S.x)*Yv,S.vy+=(S.baseY-S.y)*Yv,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 k=S+1;k<b.length;k++){const N=b[S].x-b[k].x,D=b[S].y-b[k].y,j=Math.sqrt(N*N+D*D);if(j<Vv){const R=(1-j/Vv)*.15;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${R})`,f.lineWidth=.5,f.moveTo(b[S].x,b[S].y),f.lineTo(b[k].x,b[k].y),f.stroke()}}const x=b[S].x-C.x,y=b[S].y-C.y,w=Math.sqrt(x*x+y*y);if(w<xr){const k=(1-w/xr)*.3;f.beginPath(),f.strokeStyle=`rgba(75, 141, 255, ${k})`,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 x=S.x-C.x,y=S.y-C.y,w=Math.sqrt(x*x+y*y),k=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, ${k})`,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(v)}return c(),h.addEventListener("mousemove",p),h.addEventListener("mouseleave",u),window.addEventListener("resize",c),a.current=requestAnimationFrame(v),()=>{cancelAnimationFrame(a.current),h.removeEventListener("mousemove",p),h.removeEventListener("mouseleave",u),window.removeEventListener("resize",c)}},[]),t.jsx("canvas",{ref:e,className:"absolute inset-0 pointer-events-auto",style:{zIndex:0}})}function f3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:h}){const[f,m]=_.useState(!1),o=Ds(),{t:c}=st(),[d,p]=_.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),u=()=>{p(v=>{const b=!v;return localStorage.setItem("sidebarCollapsed",b?"1":"0"),b})};return t.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[t.jsx("aside",{className:`
603
603
  fixed inset-y-0 left-0 z-40 flex-shrink-0
604
604
  transition-[transform,width] duration-200 ease-in-out
605
605
  md:translate-x-0 md:static md:z-auto
@@ -646,7 +646,7 @@ ${A.message}
646
646
  `)?"":`
647
647
  `;await v6(e,a+m+h+`
648
648
  `)}async function eB(e,s,i){await Ze(`/api/projects/${e}/vault/ignore/unhide`,{path:s,isDir:i})}function b6(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(2)}MB`}function y6(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 xp({projectId:e,mode:s,selectedPaths:i,includeLinked:a,onChange:h}){const{t:f}=st(),[m,o]=_.useState([]),[c,d]=_.useState(!1),[p,u]=_.useState(!1),[v,b]=_.useState(""),[C,S]=_.useState(!1),[x,y]=_.useState("");_.useEffect(()=>{let R=!1;return p6(e).then(E=>{R||(o(E.files),d(!0))}).catch(E=>{console.error("Load vault files failed",E),d(!0)}),()=>{R=!0}},[e]);const w=_.useMemo(()=>{const R=x.toLowerCase(),E=R?m.filter(A=>A.stem.toLowerCase().includes(R)||A.title.toLowerCase().includes(R)||A.relativePath.toLowerCase().includes(R)):m,L={};for(const A of E){const O=A.relativePath.includes("/")?A.relativePath.split("/").slice(0,-1).join("/"):".";L[O]||(L[O]=[]),L[O].push(A)}return L},[m,x]),k=_.useMemo(()=>y6(m),[m]),N=R=>{const E=new Set(i);if(E.has(R))E.delete(R);else if(E.add(R),a){const L=k.get(R)??[];for(const A of L)E.add(A)}h("selected",Array.from(E),a)},D=async()=>{S(!0);try{const E=await g6(e,s==="auto"?"all":s,i);b(E.block||f("vault.empty"))}catch(R){b(R instanceof Error?R.message:"Preview failed")}finally{S(!1)}},j=s!=="none"&&s!=="auto";return _.useEffect(()=>{p&&j&&D()},[p,s,i]),t.jsxs("div",{className:"rounded-lg border border-warm-200 bg-warm-50 p-3",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("div",{className:"text-sm font-medium text-warm-800",children:f("vaultInject.title")}),j&&t.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?t.jsx(b5,{size:12}):t.jsx(Zf,{size:12}),f("vaultInject.previewToggle")]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:["none","auto","all","selected"].map(R=>t.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"&&t.jsx("div",{className:"text-xs text-warm-500 mt-1 leading-snug",children:f("vaultInject.autoHint").replace("{count}",String(m.length))}),s==="selected"&&t.jsx("div",{className:"mt-2",children:c?m.length===0?t.jsx("div",{className:"text-xs text-warm-500 italic",children:f("vaultInject.empty")}):t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-600 mb-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:a,onChange:R=>h(s,i,R.target.checked)}),f("vaultInject.includeLinked")]}),t.jsx("input",{value:x,onChange:R=>y(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"}),t.jsx("div",{className:"max-h-56 overflow-y-auto border border-warm-200 rounded-md",children:Object.keys(w).length===0?t.jsx("div",{className:"text-xs text-warm-500 italic px-2 py-2",children:f("vaultInject.noResults")}):Object.entries(w).sort(([R],[E])=>R.localeCompare(E)).map(([R,E])=>t.jsxs("div",{children:[t.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}),t.jsx("div",{className:"divide-y divide-warm-100",children:E.map(L=>{const A=(k.get(L.relativePath)??[]).length;return t.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-warm-100 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:i.includes(L.relativePath),onChange:()=>N(L.relativePath)}),L.kind==="html"?t.jsx(Wm,{size:12,className:"text-warm-500 shrink-0"}):t.jsx(Ui,{size:12,className:"text-warm-500 shrink-0"}),t.jsx("span",{className:"text-sm text-warm-800 truncate flex-1",title:L.relativePath,children:L.title||L.stem}),a&&A>0&&t.jsx("span",{className:"text-[10px] text-warm-600 bg-warm-200 px-1.5 py-0.5 rounded shrink-0",title:L.wikilinks.join(", "),children:f("vaultInject.linkedAdded").replace("{n}",String(A))}),t.jsx("span",{className:"text-[10px] text-warm-500 font-mono shrink-0",children:b6(L.size)})]},L.relativePath)})})]},R))}),t.jsx("div",{className:"text-xs text-warm-500 mt-1.5",children:f("vaultInject.injectedCount").replace("{count}",String(i.length))})]}):t.jsx("div",{className:"text-xs text-warm-500",children:f("vaultInject.loading")})}),s==="all"&&m.length>0&&t.jsx("div",{className:"text-xs text-warm-500 mt-1",children:f("vaultInject.allCount").replace("{count}",String(m.length))}),p&&j&&t.jsxs("div",{className:"mt-3",children:[t.jsx("textarea",{readOnly:!0,value:C?"...":v,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&&v&&t.jsxs("div",{className:"mt-1 flex items-center justify-end gap-3 text-[10px] text-warm-500 font-mono",children:[t.jsx("span",{children:f("vaultInject.previewChars").replace("{n}",v.length.toLocaleString())}),t.jsx("span",{children:f("vaultInject.previewTokens").replace("{n}",Math.ceil(v.length/4).toLocaleString())})]})]})]})}function w6(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}let _6=0;function __({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:v=!1,projectUseWorktree:b=!0,existingImages:C=[],todoId:S,onDeleteImage:x,availableTodos:y=[]}){const[w,k]=_.useState(i),[N,D]=_.useState(a),[j,R]=_.useState(h||u||"claude"),[E,L]=_.useState(f??""),[A,O]=_.useState((m==null?void 0:m.toString())??""),[z,I]=_.useState(o===1?"force-on":o===0?"force-off":"inherit"),[F,H]=_.useState(c),[U,q]=_.useState(w6(d)),[X,B]=_.useState(!1),[P,$]=_.useState([]),[Y,W]=_.useState(C),Z=_.useRef(null),he=_.useRef(null),{t:re}=st(),J=_.useCallback(Te=>{const ye=Array.from(Te).filter(ke=>ke.type.startsWith("image/"));for(const ke of ye){const Ke=new FileReader;Ke.onload=()=>{const $e=Ke.result,be=`pending-${++_6}`;$(De=>[...De,{id:be,name:ke.name,data:$e,preview:$e}])},Ke.readAsDataURL(ke)}},[]),V=_.useCallback(Te=>{var $e;const ye=($e=Te.clipboardData)==null?void 0:$e.items;if(!ye)return;const ke=[];for(let be=0;be<ye.length;be++)ye[be].type.startsWith("image/")&&ke.push(ye[be]);if(ke.length===0)return;Te.preventDefault();const Ke=[];for(const be of ke){const De=be.getAsFile();De&&Ke.push(De)}J(Ke)},[J]),pe=_.useCallback(Te=>{var ye;Te.preventDefault(),Te.stopPropagation(),(ye=Te.dataTransfer)!=null&&ye.files&&J(Te.dataTransfer.files)},[J]),oe=_.useCallback(Te=>{Te.preventDefault(),Te.stopPropagation()},[]),ge=Te=>{$(ye=>ye.filter(ke=>ke.id!==Te))},le=Te=>{x&&x(Te),W(ye=>ye.filter(ke=>ke.id!==Te))},Oe=Te=>{if(Te.preventDefault(),!w.trim())return;const ye=A?parseInt(A,10):void 0,ke=z==="force-on"?1:z==="force-off"?0:null;e(w.trim(),N.trim(),j,P.length>0?P:void 0,E||void 0,ye||void 0,ke,F,[],U)},He=Y.length+P.length;return t.jsxs("form",{onSubmit:Oe,className:"card p-5 border-accent/30",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:re("todoForm.titlePlaceholder"),value:w,onChange:Te=>k(Te.target.value),className:"input-field",autoFocus:!0})}),t.jsxs("div",{className:"mb-4",children:[t.jsx("textarea",{ref:Z,placeholder:re("todoForm.descPlaceholder"),value:N,onChange:Te=>D(Te.target.value),onPaste:V,onDrop:pe,onDragOver:oe,rows:3,className:"input-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{var Te;return(Te=he.current)==null?void 0:Te.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:[t.jsx($a,{size:14}),re("todoForm.addImage")]}),t.jsx("span",{className:"text-2xs text-warm-300",children:re("todoForm.pasteHint")})]}),t.jsx("input",{ref:he,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:Te=>{Te.target.files&&J(Te.target.files),Te.target.value=""}})]}),He>0&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:re("todoForm.images")}),t.jsxs("span",{className:"text-2xs text-warm-400",children:["(",He,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[Y.map(Te=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:S?um(S,Te.id):"",alt:Te.originalName,className:"h-20 w-20 object-cover rounded-lg border border-warm-200"}),t.jsx("button",{type:"button",onClick:()=>le(Te.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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:Te.originalName})})]},Te.id)),P.map(Te=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:Te.preview,alt:Te.name,className:"h-20 w-20 object-cover rounded-lg border border-accent/30"}),t.jsx("button",{type:"button",onClick:()=>ge(Te.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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:Te.name})})]},Te.id))]})]}),t.jsx("div",{className:"mb-4 grid grid-cols-2 gap-3",children:t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:re("todoForm.cliTool")}),t.jsx("select",{value:j,onChange:Te=>R(Te.target.value),className:"input-field text-sm",children:_r.map(Te=>t.jsx("option",{value:Te.value,children:Te.label},Te.value))})]})}),j==="claude"&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:re("todoForm.maxTurns")}),t.jsx("input",{type:"number",min:"1",max:"500",placeholder:re("todoForm.maxTurnsPlaceholder"),value:A,onChange:Te=>O(Te.target.value),className:"input-field text-sm w-32"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:re("todoForm.maxTurnsHint")})]}),v&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:re("todoForm.worktreeMode")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[t.jsx("input",{type:"radio",name:"useWorktreeMode",checked:z==="inherit",onChange:()=>I("inherit")}),t.jsxs("span",{children:[re("todoForm.worktreeInherit"),t.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["(",re(b?"todoForm.worktreeProjectDefaultOn":"todoForm.worktreeProjectDefaultOff"),")"]})]})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[t.jsx("input",{type:"radio",name:"useWorktreeMode",checked:z==="force-on",onChange:()=>I("force-on")}),t.jsx("span",{children:re("todoForm.worktreeForceOn")})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[t.jsx("input",{type:"radio",name:"useWorktreeMode",checked:z==="force-off",onChange:()=>I("force-off")}),t.jsx("span",{children:re("todoForm.worktreeForceOff")})]})]}),(z==="force-off"||z==="inherit"&&!b)&&t.jsx("p",{className:"text-2xs text-status-warning mt-1.5",children:re("todoForm.worktreeMainWarning")})]}),y.length>0&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:re("todoForm.dependsOn")}),t.jsxs("select",{value:E,onChange:Te=>L(Te.target.value),className:"input-field text-sm",children:[t.jsx("option",{value:"",children:re("todoForm.noDependency")}),y.map(Te=>t.jsxs("option",{value:Te.id,children:[Te.title," (",re(`status.${Te.status}`),")"]},Te.id))]}),E&&t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:re("todoForm.dependsOnHint")})]}),p&&t.jsx("div",{className:"mb-4",children:t.jsx(xp,{projectId:p,mode:F,selectedPaths:U,includeLinked:X,onChange:(Te,ye,ke)=>{H(Te),q(ye),B(ke)}})}),t.jsxs("div",{className:"flex gap-3 justify-end",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:re("todoForm.cancel")}),t.jsx("button",{type:"submit",disabled:!w.trim(),className:"btn-primary text-sm",children:re("todoForm.save")})]})]})}const sn="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",vp="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 S_(){return t.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=_.useRef(null),[f,m]=_.useState({top:s,left:e,visible:!1});return _.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]),_.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]),rn.createPortal(t.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 S6({children:e}){const[s,i]=_.useState(!1),[a,h]=_.useState(!1),f=_.useRef(null),m=_.useRef(null),[o,c]=_.useState({top:0,left:0}),d=_.useCallback(()=>{if(!f.current)return;const u=f.current.getBoundingClientRect(),v=window.innerWidth,b=window.innerHeight;let C=u.bottom+4;const S=m.current;if(S){const x=S.offsetWidth,y=S.offsetHeight;let w=u.right-x;w<8&&(w=8),w+x>v-8&&(w=v-8-x),C+y>b-8&&(C=u.top-y-4),c({top:C,left:w}),h(!0)}else c({top:C,left:Math.max(8,u.right-180)})},[]);_.useEffect(()=>{if(!s){h(!1);return}d();const u=requestAnimationFrame(d),v=b=>{var S,x;const C=b.target;(S=f.current)!=null&&S.contains(C)||(x=m.current)!=null&&x.contains(C)||i(!1)};return document.addEventListener("mousedown",v),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{cancelAnimationFrame(u),document.removeEventListener("mousedown",v),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:t.jsxs(t.Fragment,{children:[t.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:t.jsx(Um,{size:14})}),s&&rn.createPortal(t.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 k6({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:v,onFix:b,onSchedule:C,onScheduleOnReset:S,resetsAt:x,onEvent:y,isInteractive:w,onSendInput:k,isDragSource:N,isDragging:D,isDragOver:j,isValidDropTarget:R,onDragStart:E,onDragEnd:L,onDragOverTarget:A,onDragLeaveTarget:O,onDropTarget:z,onRemoveDependency:I,debugLogging:F,showTokenUsage:H,isChainMember:U}){const[q,X]=_.useState(!1),[B,P]=_.useState(!1),[$,Y]=_.useState([]),[W,Z]=_.useState(!1),[he,re]=_.useState(!1),[J,V]=_.useState(null),[pe,oe]=_.useState(!1),[ge,le]=_.useState(null),[Oe,He]=_.useState(!1),[Te,ye]=_.useState(null),[ke,Ke]=_.useState(!1),[$e,be]=_.useState(null),[De,Fe]=_.useState(!1),[qe,Qe]=_.useState(null),[nt,xe]=_.useState(!1),[ie,we]=_.useState(""),[Q,K]=_.useState(!1),[ne,ee]=_.useState(null),[se,ce]=_.useState(!1),[fe,ue]=_.useState(""),[je,Ue]=_.useState(!1),[ut,Pe]=_.useState(null),[Ve,Ne]=_.useState(null),[it,lt]=_.useState(!1),[xt,ft]=_.useState(!1),[rt,Le]=_.useState(!1),[et,wt]=_.useState(()=>{const _e=new Date;_e.setHours(_e.getHours()+1),_e.setMinutes(0,0,0);const ht=_e.getFullYear(),bt=String(_e.getMonth()+1).padStart(2,"0"),Kt=String(_e.getDate()).padStart(2,"0"),dn=String(_e.getHours()).padStart(2,"0"),xi=String(_e.getMinutes()).padStart(2,"0");return`${ht}-${bt}-${Kt}T${dn}:${xi}`}),[kt,de]=_.useState(!1),[Re,Ee]=_.useState(null),{t:ve}=st(),at=e.status==="pending"||e.status==="failed"||e.status==="stopped",vt=(e.status==="pending"||e.status==="failed"||e.status==="stopped")&&!!C,Ct=(e.status==="pending"||e.status==="completed"||e.status==="failed"||e.status==="stopped")&&!!S&&!!x&&x>Math.floor(Date.now()/1e3),Tt=e.status==="running",Nt=e.status==="completed"||e.status==="stopped"||e.status==="merged",Ft=e.status==="completed"&&!U&&!!e.branch_name,Dn=e.status==="completed"||e.status==="failed"||e.status==="stopped",Wn=!!v&&e.status==="completed"&&!!e.worktree_path,In=e.status!=="running"&&e.status!=="pending"&&!!e.worktree_path&&!U,Tn=e.status==="completed"||e.status==="failed"||e.status==="stopped"||e.status==="merged";_.useEffect(()=>{w&&e.status==="running"&&!q&&X(!0)},[w,e.status]),_.useEffect(()=>{q&&!W&&t1(e.id).then(_e=>{Y(_e),Z(!0)}).catch(()=>{})},[q,W,e.id]),_.useEffect(()=>{q&&Tn&&!it&&y3(e.id).then(_e=>{Ne(_e),lt(!0)}).catch(()=>{lt(!0)})},[q,Tn,it,e.id]),_.useEffect(()=>y(_e=>{if(_e.type==="todo:log"&&_e.todoId===e.id&&_e.message){const ht={id:`ws-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:_e.logType||"output",message:_e.message,created_at:new Date().toISOString()};Y(bt=>[...bt,ht])}if(_e.type==="todo:commit"&&_e.todoId===e.id&&_e.message){const ht={id:`ws-commit-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:"commit",message:`${_e.commitHash?`[${_e.commitHash}] `:""}${_e.message}`,created_at:new Date().toISOString()};Y(bt=>[...bt,ht])}}),[y,e.id]);const Fs=async()=>{try{const{files:_e}=await iE(e.project_id,e.id);_e.length>0&&window.open(`/api/projects/${e.project_id}/debug-logs/${encodeURIComponent(_e[0].name)}`,"_blank")}catch{}},ps=async()=>{if(he){re(!1);return}oe(!0),le(null);try{const _e=await b3(e.id);V(_e),re(!0),X(!0)}catch(_e){le(_e instanceof Error?_e.message:"Failed to load diff"),X(!0)}finally{oe(!1)}},Gn=async()=>{He(!0),ye(null);try{await d(e.id)}catch(_e){ye(_e instanceof Error?_e.message:"Merge failed")}finally{He(!1)}},gs=async()=>{const _e=e.branch_name?confirm(ve("cleanup.confirmDeleteBranch").replace("{name}",e.branch_name)):!1;Ke(!0),be(null);try{await p(e.id,_e)}catch(ht){be(ht instanceof Error?ht.message:"Cleanup failed")}finally{Ke(!1)}},Rs=async(_e="headless")=>{Fe(!0),Qe(null),Y([]),Z(!1),V(null),re(!1),Ne(null),lt(!1);try{await u(e.id,_e)}catch(ht){Qe(ht instanceof Error?ht.message:"Retry failed")}finally{Fe(!1)}},ss=async(_e="headless")=>{if(!v)return;const ht=ie.trim();if(!ht){ee(ve("todo.continuePromptRequired"));return}K(!0),ee(null);try{await v(e.id,ht,_e),xe(!1),we(""),Y([]),Z(!1)}catch(bt){ee(bt instanceof Error?bt.message:"Continue failed")}finally{K(!1)}},en=async()=>{if(!(!S||!fe.trim())){Ue(!0),Pe(null);try{await S(e.id,fe.trim()),ce(!1),ue("")}catch(_e){Pe(_e instanceof Error?_e.message:"Failed")}finally{Ue(!1)}}},Ji=async()=>{if(!(!C||!et)){de(!0);try{await C(e.id,new Date(et).toISOString(),rt),ft(!1)}catch{}finally{de(!1)}}},Qi=_e=>{if(_e<60)return`${_e}s`;const ht=Math.floor(_e/60),bt=_e%60;if(ht<60)return bt>0?`${ht}m ${bt}s`:`${ht}m`;const Kt=Math.floor(ht/60),dn=ht%60;return dn>0?`${Kt}h ${dn}m`:`${Kt}h`},xs=_e=>_e>=1e6?`${(_e/1e6).toFixed(1)}M`:_e>=1e3?`${(_e/1e3).toFixed(1)}k`:String(_e),qn=e.images?JSON.parse(e.images):[],vs=e.depends_on?s.find(_e=>_e.id===e.depends_on):null,Ms=s.find(_e=>_e.depends_on===e.id&&_e.merged_from_branch),pi=e.cli_tool||i||"claude",gi=fm(pi).supportsInteractive;if(B)return t.jsx(__,{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:qn,todoId:e.id,availableTodos:s.filter(_e=>_e.id!==e.id),onDeleteImage:async _e=>{await S3(e.id,_e)},onSave:async(_e,ht,bt,Kt,dn,xi,Nr,Cl,jl,Er)=>{await c(e.id,_e,ht,bt,dn,xi,Nr,Cl,jl,Er),Kt&&Kt.length>0&&await i1(e.id,Kt.map(Nl=>({name:Nl.name,data:Nl.data}))),P(!1)},onCancel:()=>P(!1)});const As={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],bs=_e=>{_e.dataTransfer.setData("text/plain",e.id),_e.dataTransfer.effectAllowed="link",E==null||E(e.id)},rs=()=>{L==null||L()},Rn=_e=>{!D||N||(_e.preventDefault(),_e.dataTransfer.dropEffect=R?"link":"none",A==null||A(e.id))},ae=()=>{O==null||O(e.id)},We=_e=>{_e.preventDefault(),!(!D||N||!R)&&(z==null||z(e.id))},ct=D&&!N&&j&&R,Ge=D&&!N&&j&&!R;return t.jsxs("div",{className:`relative transition-opacity duration-200 ${N?"opacity-40":""}`,onDragOver:Rn,onDragLeave:ae,onDrop:We,onContextMenu:_e=>{hi(_e)||(_e.preventDefault(),_e.stopPropagation(),Ee({x:_e.clientX,y:_e.clientY}))},children:[t.jsxs("div",{className:`card border-l-4 ${As} overflow-hidden transition-all duration-200 ${ct?"ring-2 ring-accent/50 ring-offset-1":""} ${Ge?"ring-2 ring-status-error/50 ring-offset-1":""}`,children:[t.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:()=>X(!q),children:[t.jsx("div",{draggable:!0,onDragStart:bs,onDragEnd:rs,onClick:_e=>_e.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:ve("dnd.dropHint"),children:t.jsx(Mw,{size:16})}),t.jsx("button",{className:"text-warm-400 hover:text-accent flex-shrink-0 transition-colors",children:t.jsx(Ts,{size:14,className:`transition-transform duration-200 ${q?"rotate-90":""}`})}),t.jsxs("span",{className:"text-2xs font-mono text-warm-400 w-6 flex-shrink-0",children:["#",e.priority]}),t.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}),qn.length>0&&t.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:[t.jsx($a,{size:12}),qn.length]}),vs&&t.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:`${ve("todo.dependsOn")}: ${vs.title}`,children:[t.jsx(Ua,{size:12}),vs.title.length>20?vs.title.slice(0,20)+"...":vs.title,I&&t.jsx("button",{onClick:_e=>{_e.stopPropagation(),I(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:ve("dnd.removeDep"),children:t.jsx(Qt,{size:10})})]}),e.cli_tool&&t.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:fm(e.cli_tool||"claude").label}),t.jsx($4,{status:e.status}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto md:ml-2 flex-shrink-0",onClick:_e=>_e.stopPropagation(),children:[at&&t.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:ve("todo.startHeadless"),children:t.jsx(kr,{size:14})}),Tt&&t.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:ve("todo.stop"),children:t.jsx(qi,{size:14})}),Ft&&t.jsx("button",{onClick:Gn,disabled:Oe,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:ve("todo.merge"),children:t.jsx(dl,{size:14})}),Wn&&t.jsx("button",{onClick:()=>{xe(_e=>!_e),ee(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:ve("todo.continue"),children:t.jsx(Ev,{size:14})}),Dn&&t.jsx("button",{onClick:()=>Rs("headless"),disabled:De,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:ve("todo.retry"),children:t.jsx(ui,{size:14})}),t.jsxs(S6,{children:[at&&gi&&t.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:ve("todo.startInteractiveDesc"),children:[t.jsx(di,{size:14}),ve("todo.startInteractive")]}),at&&t.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:ve("todo.startVerboseDesc"),children:[t.jsx(Zf,{size:14}),ve("todo.startVerbose")]}),vt&&t.jsxs("button",{onClick:()=>ft(!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:ve("todo.scheduleDesc"),children:[t.jsx(Jf,{size:14}),ve("todo.schedule")]}),Ct&&t.jsxs("button",{onClick:()=>{ce(_e=>!_e),Pe(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:ve("todo.scheduleOnResetDesc"),children:[t.jsx(oi,{size:14}),ve("todo.scheduleOnReset")]}),Nt&&t.jsxs("button",{onClick:ps,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:[t.jsx(Ui,{size:14}),ve("todo.viewDiff")]}),F&&Tn&&t.jsxs("button",{onClick:Fs,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:[t.jsx(Mv,{size:14}),ve("todo.viewDebugLog")]}),In&&t.jsxs("button",{onClick:gs,disabled:ke,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:[t.jsx(mu,{size:14}),ve("todo.cleanup")]}),t.jsxs("button",{onClick:()=>P(!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:[t.jsx(ci,{size:14}),ve("todo.edit")]}),t.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:[t.jsx(jn,{size:14}),ve("todo.delete")]})]})]})]}),xt&&t.jsx("div",{className:"border-t border-accent/20 px-5 py-3 bg-accent/5 animate-fade-in",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-accent",children:ve("todo.scheduleAt")}),t.jsx("input",{type:"datetime-local",value:et,onChange:_e=>wt(_e.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)}),t.jsx("button",{onClick:Ji,disabled:kt||!et,className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:ve(kt?"todo.scheduling":"todo.confirmSchedule")}),t.jsx("button",{onClick:()=>ft(!1),className:"btn-ghost text-xs py-1.5",children:ve("scheduleForm.cancel")}),t.jsxs("label",{className:"flex items-center gap-2 text-xs text-accent",children:[t.jsx("input",{type:"checkbox",checked:rt,onChange:_e=>Le(_e.target.checked),className:"rounded border-accent/40 text-accent focus:ring-accent"}),ve("todo.scheduleKeepOriginal")]})]})}),nt&&t.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50 animate-fade-in",children:t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("label",{className:"text-xs font-medium text-theme-text-secondary",children:[ve("todo.continuePromptLabel"),(e.round_count??1)>1&&t.jsxs("span",{className:"ml-2 text-theme-muted",children:["(",ve("todo.roundLabel")," ",e.round_count,")"]})]}),t.jsx("textarea",{value:ie,onChange:_e=>we(_e.target.value),placeholder:ve("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}),ne&&t.jsx("p",{className:"text-xs text-status-error",children:ne}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>ss("headless"),disabled:Q||!ie.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:ve(Q?"todo.continuing":"todo.confirmContinue")}),t.jsx("button",{onClick:()=>{xe(!1),ee(null)},disabled:Q,className:"btn-ghost text-xs py-1.5",children:ve("scheduleForm.cancel")})]})]})}),se&&x&&t.jsx("div",{className:"border-t border-amber-200 px-5 py-3 bg-amber-50/50 animate-fade-in",children:t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("label",{className:"text-xs font-medium text-amber-600",children:ve("todo.scheduleOnResetLabel")}),t.jsx("span",{className:"text-xs text-amber-500/80 font-mono",children:new Date(x*1e3).toLocaleString()})]}),t.jsx("textarea",{value:fe,onChange:_e=>ue(_e.target.value),placeholder:ve("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:je}),ut&&t.jsx("p",{className:"text-xs text-status-error",children:ut}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:en,disabled:je||!fe.trim(),className:"btn-primary text-xs py-1.5 !bg-amber-500 hover:!bg-amber-600 disabled:opacity-30",children:ve(je?"todo.scheduling":"todo.confirmResetSchedule")}),t.jsx("button",{onClick:()=>{ce(!1),Pe(null)},disabled:je,className:"btn-ghost text-xs py-1.5",children:ve("scheduleForm.cancel")})]})]})}),q&&t.jsx("div",{className:"animate-fade-in overflow-hidden border-t border-theme-border",children:t.jsxs("div",{className:"px-4 py-3 space-y-3",children:[t.jsxs("section",{children:[t.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:ve("todo.description")}),t.jsx("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2",children:e.description?t.jsx("p",{className:"text-sm text-warm-700 whitespace-pre-wrap",children:e.description}):t.jsx("p",{className:"text-sm text-warm-400 italic",children:ve("todo.noDescription")})})]}),qn.length>0&&t.jsxs("section",{children:[t.jsxs("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:[ve("todo.attachedImages")," ",t.jsxs("span",{className:"text-warm-400 normal-case",children:["(",qn.length,")"]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:qn.map(_e=>t.jsx("a",{href:um(e.id,_e.id),target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{src:um(e.id,_e.id),alt:_e.originalName,className:"h-16 w-16 object-cover rounded-md border border-theme-border"})},_e.id))})]}),(vs||e.branch_name||Ms)&&t.jsxs("section",{children:[t.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:ve("todo.branch")}),t.jsxs("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2 space-y-1.5",children:[vs&&t.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[t.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0 pt-0.5",children:ve("todo.dependsOn")}),t.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&&t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:ve("todo.branch")}),t.jsx(Ya,{size:12,className:"text-status-success flex-shrink-0"}),t.jsx("code",{className:"font-mono text-xs text-warm-700 break-all",children:e.branch_name})]}),e.worktree_path&&t.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[t.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0 pt-0.5",children:ve("todo.worktree")}),t.jsx("code",{className:"font-mono text-2xs text-warm-500 break-all",children:e.worktree_path})]}),e.merged_from_branch&&t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:ve("todo.mergedFrom")}),t.jsx("code",{className:"font-mono text-xs text-theme-text-secondary break-all",children:e.merged_from_branch})]}),!e.worktree_path&&Ms&&t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:ve("todo.transferredTo")}),t.jsx("span",{className:"text-warm-700 truncate",children:Ms.title.length>30?Ms.title.slice(0,27)+"...":Ms.title})]})]})]}),e.status==="failed"&&$.length>0&&(()=>{var Kt;const _e=$.filter(dn=>dn.log_type==="error");if(_e.length===0)return null;const ht=_e.find(dn=>/exited with code (\d+)/.test(dn.message)),bt=ht?(Kt=ht.message.match(/exited with code (\d+)/))==null?void 0:Kt[1]:null;return t.jsxs("div",{style:{background:Ie.bg,fontFamily:Rt,fontSize:12,lineHeight:"1.5",padding:"10px 12px",borderRadius:8,border:`1px solid ${Ie.separator}`,color:Ie.text},children:[t.jsxs("div",{children:[t.jsx("span",{style:{color:Ie.error},children:">"})," ",t.jsx("span",{style:{color:Ie.error,fontWeight:700},children:"FAILED"}),bt&&t.jsxs("span",{style:{color:Ie.dim},children:[" (exit code: ",bt,")"]}),b&&t.jsx("button",{onClick:()=>b(e,_e),style:{marginLeft:12,color:Ie.warning,background:"none",border:`1px solid ${Ie.warning}`,padding:"1px 8px",borderRadius:2,cursor:"pointer",fontSize:11,fontFamily:Rt},children:ve("failure.fix")})]}),t.jsx("div",{style:{maxHeight:192,overflowY:"auto",marginTop:4},children:_e.map(dn=>t.jsxs("div",{children:[t.jsx("span",{style:{color:Ie.dim},children:new Date(dn.created_at).toLocaleTimeString()})," ",t.jsx("span",{style:{color:Ie.error},children:dn.message})]},dn.id))})]})})(),Tn&&Ve&&t.jsxs("section",{children:[t.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider mb-1.5",children:ve("todo.result")}),t.jsxs("div",{className:"rounded-lg border border-theme-border bg-theme-card/50 px-3 py-2 space-y-2.5",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs",children:[Ve.duration_seconds!==null&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(oi,{size:12,className:"text-warm-400"}),t.jsx("span",{className:"text-warm-400",children:ve("result.duration")}),t.jsx("span",{className:"text-warm-700 font-medium",children:Qi(Ve.duration_seconds)})]}),Ve.commits.length>0&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(R5,{size:12,className:"text-status-success"}),t.jsx("span",{className:"text-status-success font-medium",children:Ve.commits.length}),t.jsx("span",{className:"text-warm-400",children:ve("result.commits")})]}),Ve.diff_stats.files_changed>0&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(Ui,{size:12,className:"text-warm-400"}),t.jsx("span",{className:"text-warm-700 font-medium",children:Ve.diff_stats.files_changed}),t.jsx("span",{className:"text-warm-400",children:ve("result.filesChanged")}),t.jsxs("span",{className:"text-status-success font-mono",children:["+",Ve.diff_stats.insertions]}),t.jsxs("span",{className:"text-status-error font-mono",children:["-",Ve.diff_stats.deletions]})]}),H&&Ve.token_usage&&(()=>{const _e=Ve.token_usage,ht=(_e.input_tokens??0)+(_e.cache_read_input_tokens??0)+(_e.cache_creation_input_tokens??0),bt=ht+(_e.output_tokens??0);let Kt,dn;return bt>=5e5?(Kt=ve("result.levelHeavy"),dn="text-status-error"):bt>=3e5?(Kt=ve("result.levelHigh"),dn="text-orange-500"):bt>=1e5?(Kt=ve("result.levelModerate"),dn="text-status-warning"):(Kt=ve("result.levelLight"),dn="text-status-info"),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[ht>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:ve("result.inputTokens")}),t.jsx("span",{className:"text-warm-700 font-medium",children:xs(ht)})]}),ht>0&&_e.output_tokens!==null&&t.jsx("span",{className:"text-warm-400",children:"·"}),_e.output_tokens!==null&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:ve("result.outputTokens")}),t.jsx("span",{className:"text-warm-700 font-medium",children:xs(_e.output_tokens)})]}),_e.num_turns!=null&&_e.num_turns>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:"·"}),t.jsxs("span",{className:"text-warm-700",children:[_e.num_turns,ve("result.turns")]})]}),t.jsx("span",{className:"text-warm-400",children:"·"}),t.jsx("span",{className:`font-medium ${dn}`,children:Kt})]})})()]}),Ve.commits.length>0&&t.jsxs("div",{children:[t.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider mb-1",children:ve("result.commitHistory")}),t.jsx("div",{className:"space-y-0.5",children:Ve.commits.map((_e,ht)=>t.jsxs("div",{className:"flex items-center gap-2 px-1.5 py-1 text-xs rounded hover:bg-theme-hover",children:[t.jsx("code",{className:"font-mono text-accent flex-shrink-0",children:_e.hash.slice(0,7)||"-------"}),t.jsx("span",{className:"text-warm-700 truncate flex-1",children:_e.message}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:new Date(_e.date).toLocaleTimeString()})]},ht))})]}),Ve.changed_files.length>0&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider",children:ve("result.changedFiles")}),Nt&&t.jsxs("button",{onClick:ps,disabled:pe,className:"flex items-center gap-1 text-2xs text-warm-500 hover:text-accent transition-colors disabled:opacity-30",children:[t.jsx(Ts,{size:10,className:`transition-transform ${he?"rotate-90":""}`}),t.jsx("span",{children:ve(he?"todo.hideDiff":"todo.viewDiff")})]})]}),t.jsx("div",{className:"space-y-0.5",children:Ve.changed_files.map((_e,ht)=>{const bt=_e.status==="A"?"bg-status-success/15 text-status-success":_e.status==="D"?"bg-status-error/15 text-status-error":_e.status==="M"?"bg-status-warning/15 text-status-warning":"bg-warm-200 text-warm-600";return t.jsxs("div",{className:"flex items-center gap-2 px-1.5 py-0.5 text-xs",children:[t.jsx("span",{className:`inline-flex items-center justify-center w-5 h-4 rounded text-[10px] font-bold ${bt}`,children:_e.status}),t.jsx("span",{className:"text-warm-700 font-mono text-2xs break-all flex-1",children:_e.file}),_e.renamedFrom&&t.jsxs("span",{className:"text-warm-400 text-2xs flex-shrink-0",children:["← ",_e.renamedFrom]})]},ht)})})]})]})]}),Te&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[ve("todo.mergeFailed"),": ",Te]}),$e&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[ve("todo.cleanupFailed"),": ",$e]}),qe&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[ve("todo.retryFailed"),": ",qe]}),ge&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[ve("todo.diffError"),": ",ge]}),he&&J&&t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[t.jsx("h4",{className:"text-2xs font-semibold text-warm-500 uppercase tracking-wider",children:ve("todo.diffOutput")}),t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs",children:[t.jsxs("span",{className:"text-warm-500",children:[J.stats.files_changed," ",ve("todo.files")]}),t.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-status-success/10 text-status-success font-mono",children:["+",J.stats.insertions]}),t.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-status-error/10 text-status-error font-mono",children:["-",J.stats.deletions]})]})]}),t.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:J.diff?J.diff.split(`
649
- `).map((_e,ht)=>{let bt="text-theme-text",Kt="";return _e.startsWith("+")&&!_e.startsWith("+++")?bt="text-theme-text bg-status-success/15":_e.startsWith("-")&&!_e.startsWith("---")?bt="text-theme-text bg-status-error/15":_e.startsWith("@@")?bt="text-accent":_e.startsWith("diff ")&&(bt="text-warm-700",Kt="font-semibold"),t.jsx("div",{className:`whitespace-pre ${bt} ${Kt}`,children:_e},ht)}):t.jsx("span",{className:"text-warm-400 italic",children:ve("log.noChanges")})})]}),t.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:Ie.bg,fontFamily:Rt,border:`1px solid ${Ie.separator}`},children:[t.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${Ie.separator}`,fontSize:12,color:Ie.text},children:[t.jsx("span",{style:{color:Ie.prompt},children:"$"})," ",t.jsx("span",{style:{color:Ie.bright},children:"tail"})," ",t.jsx("span",{style:{color:Ie.dim},children:"-f task.log"})]}),t.jsx(w_,{logs:$,interactive:w&&e.status==="running",todoId:e.id,onSendInput:k,embedded:!0})]})]})})]}),ct&&t.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:[t.jsx(Ua,{size:14,className:"text-accent flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-accent",children:ve("dnd.dropHint")})]}),Ge&&t.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:[t.jsx(Tj,{size:14,className:"text-red-400 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-red-400",children:ve("dnd.cyclicWarning")})]}),Re&&t.jsxs(Cr,{x:Re.x,y:Re.y,onClose:()=>Ee(null),children:[at&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:sn,title:ve("todo.startHeadless"),children:[t.jsx(kr,{size:14}),ve("todo.start")]}),at&&gi&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:sn,title:ve("todo.startInteractiveDesc"),children:[t.jsx(di,{size:14}),ve("todo.startInteractive")]}),at&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:sn,title:ve("todo.startVerboseDesc"),children:[t.jsx(Zf,{size:14}),ve("todo.startVerbose")]}),Tt&&t.jsxs("button",{onClick:()=>m(e.id),className:sn,children:[t.jsx(qi,{size:14}),ve("todo.stop")]}),Ft&&t.jsxs("button",{onClick:Gn,disabled:Oe,className:sn,children:[t.jsx(dl,{size:14}),ve("todo.merge")]}),Wn&&t.jsxs("button",{onClick:()=>{xe(!0),ee(null)},disabled:Q,className:sn,children:[t.jsx(Ev,{size:14}),ve("todo.continue")]}),Dn&&t.jsxs("button",{onClick:()=>Rs("headless"),disabled:De,className:sn,children:[t.jsx(ui,{size:14}),ve("todo.retry")]}),vt&&t.jsxs("button",{onClick:()=>ft(!0),className:sn,title:ve("todo.scheduleDesc"),children:[t.jsx(Jf,{size:14}),ve("todo.schedule")]}),Ct&&t.jsxs("button",{onClick:()=>{ce(!0),Pe(null)},className:sn,title:ve("todo.scheduleOnResetDesc"),children:[t.jsx(oi,{size:14}),ve("todo.scheduleOnReset")]}),Nt&&t.jsxs("button",{onClick:ps,disabled:pe,className:sn,children:[t.jsx(Ui,{size:14}),ve("todo.viewDiff")]}),F&&Tn&&t.jsxs("button",{onClick:Fs,className:sn,children:[t.jsx(Mv,{size:14}),ve("todo.viewDebugLog")]}),In&&t.jsxs("button",{onClick:gs,disabled:ke,className:sn,children:[t.jsx(mu,{size:14}),ve("todo.cleanup")]}),t.jsx(S_,{}),t.jsxs("button",{onClick:()=>P(!0),className:sn,children:[t.jsx(ci,{size:14}),ve("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:vp,children:[t.jsx(jn,{size:14}),ve("todo.delete")]})]})]})}const C6=_.lazy(()=>Fu(()=>import("./TaskGraph-CIl9OUzG.js"),__vite__mapDeps([0,1,2,3,4]))),qc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function Qb(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 j6({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:v,onMergeChain:b,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:x,onFixTodo:y,onScheduleTodo:w,onScheduleOnResetTodo:k,resetsAt:N,onUpdateDependency:D,onUpdatePosition:j,onReorderTodos:R,onEvent:E,onSendInput:L,interactiveTodos:A,debugLogging:O,showTokenUsage:z}){var Ve;const[I,F]=_.useState(!1),[H,U]=_.useState(null),[q,X]=_.useState(null),[B,P]=_.useState(null),[$,Y]=_.useState(null),[W,Z]=_.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[he,re]=_.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[J,V]=_.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[pe,oe]=_.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:ge}=st(),le=_.useCallback(Ne=>{Z(Ne);try{localStorage.setItem("todoViewMode",Ne)}catch{}},[]),Oe=_.useCallback(Ne=>{re(Ne);try{localStorage.setItem("todoStatusFilter",Ne)}catch{}},[]),He=_.useCallback(()=>{V(Ne=>{const it=!Ne;try{localStorage.setItem("todoStackModeEnabled",String(it))}catch{}if(!it){oe(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return it})},[]),Te=_.useCallback(()=>{oe(Ne=>{const it=!Ne;try{localStorage.setItem("todoStackCollapsed",String(it))}catch{}return it})},[]),ye=J&&pe&&W==="list",ke=_.useMemo(()=>({all:e.length,active:e.filter(Ne=>qc.active.includes(Ne.status)).length,completed:e.filter(Ne=>qc.completed.includes(Ne.status)).length,cancelled:e.filter(Ne=>qc.cancelled.includes(Ne.status)).length}),[e]),Ke=_.useMemo(()=>{const Ne=qc[he];return Ne?e.filter(it=>Ne.includes(it.status)):e},[e,he]),$e=(()=>{const Ne=[...Ke].sort((Le,et)=>Le.priority-et.priority);if(he!=="all"||ye)return Ne.map(Le=>({todo:Le,depth:0}));const it=new Map,lt=[];for(const Le of Ne)if(Le.depends_on){const et=it.get(Le.depends_on)||[];et.push(Le),it.set(Le.depends_on,et)}else lt.push(Le);const xt=[],ft=new Set,rt=(Le,et)=>{if(ft.has(Le.id))return;ft.add(Le.id),xt.push({todo:Le,depth:et});const wt=it.get(Le.id);if(wt)for(const kt of wt)rt(kt,et+1)};for(const Le of lt)rt(Le,0);for(const Le of Ne)ft.has(Le.id)||xt.push({todo:Le,depth:0});return xt})(),{completedChainRoots:be,completedChainMembers:De}=_.useMemo(()=>{const Ne=new Map;for(const ft of e)if(ft.depends_on){const rt=Ne.get(ft.depends_on)||[];rt.push(ft.id),Ne.set(ft.depends_on,rt)}const it=e.filter(ft=>!ft.depends_on&&Ne.has(ft.id)),lt=new Map,xt=new Set;for(const ft of it){const rt=[],Le=et=>{if(!e.find(de=>de.id===et))return;rt.push(et);const kt=Ne.get(et)||[];for(const de of kt)Le(de)};if(Le(ft.id),rt.length>=2&&rt.every(et=>{const wt=e.find(kt=>kt.id===et);return(wt==null?void 0:wt.status)==="completed"||(wt==null?void 0:wt.status)==="merged"})){lt.set(ft.id,rt.length);for(const et of rt)xt.add(et)}}return{completedChainRoots:lt,completedChainMembers:xt}},[e]),[Fe,qe]=_.useState(null),[Qe,nt]=_.useState(null),xe=_.useCallback(async Ne=>{if(b){qe(Ne),nt(null);try{await b(Ne)}catch(it){nt(it instanceof Error?it.message:"Merge failed")}finally{qe(null)}}},[b]),ie=_.useRef(!1),we=_.useCallback(Ne=>{ie.current=!1,X(Ne)},[]),Q=_.useCallback(async()=>{if(!ie.current&&q&&D){const Ne=e.find(it=>it.id===q);Ne!=null&&Ne.depends_on&&await D(q,null)}X(null),P(null),Y(null)},[q,e,D]),K=_.useCallback(Ne=>{P(Ne),Y(null)},[]),ne=_.useCallback(Ne=>{P(it=>it===Ne?null:it)},[]),ee=_.useCallback(async Ne=>{!q||!D||q!==Ne&&(Qb(e,q,Ne)||(ie.current=!0,await D(q,Ne),X(null),P(null),Y(null)))},[q,e,D]),se=_.useCallback(async Ne=>{D&&await D(Ne,null)},[D]),ce=_.useCallback(Ne=>!q||q===Ne?!1:!Qb(e,q,Ne),[q,e]),fe=_.useCallback(Ne=>{Y(Ne),P(null)},[]),ue=_.useCallback(Ne=>{Y(it=>it===Ne?null:it)},[]),je=_.useCallback(async(Ne,it)=>{if(!q||!R)return;const lt=it.indexOf(q);if(lt<0)return;const xt=it.filter(Le=>Le!==q),ft=Ne>lt?Ne-1:Ne;if(ft===lt){Y(null);return}const rt=[...xt.slice(0,ft),q,...xt.slice(ft)];ie.current=!0,await R(rt),X(null),Y(null),P(null)},[q,R]),Ue=e.some(Ne=>Ne.status==="pending"||Ne.status==="failed"||Ne.status==="stopped"),ut=e.some(Ne=>Ne.status==="running"),Pe=t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:m,disabled:!Ue,className:"btn-ghost text-sm",children:[t.jsx(kr,{size:14}),ge("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!ut,className:"btn-ghost text-sm",children:[t.jsx(qi,{size:14}),ge("header.stopAll")]})]});return W==="graph"?t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-5",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:ge("todos.title")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[t.jsx(xn,{onClick:()=>le("list"),label:ge("graph.listView"),size:"sm",children:t.jsx(gu,{size:14})}),t.jsx(xn,{onClick:()=>le("graph"),label:ge("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Dv,{size:14})})]}),Pe]})]}),t.jsx(_.Suspense,{fallback:null,children:t.jsx(C6,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onAddTodo:f,onStartTodo:c,onStopTodo:d,onDeleteTodo:p,onEditTodo:u,onMergeTodo:v,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:x,onFixTodo:y,onUpdateDependency:D,onUpdatePosition:j,onEvent:E,onSendInput:L,interactiveTodos:A,debugLogging:O,showTokenUsage:z})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:Ne=>{hi(Ne)||(Ne.preventDefault(),U({x:Ne.clientX,y:Ne.clientY}))},children:[t.jsxs("div",{className:"flex items-center justify-between mb-5",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:ge("todos.title")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[t.jsx(xn,{onClick:()=>le("list"),label:ge("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(gu,{size:14})}),t.jsx(xn,{onClick:()=>le("graph"),label:ge("graph.graphView"),size:"sm",children:t.jsx(Dv,{size:14})})]}),t.jsx(xn,{onClick:He,label:ge(J?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:J?"active":"default",pressed:J,children:t.jsx(K5,{size:14})}),J&&!pe&&W==="list"&&$e.length>0&&t.jsx(xn,{onClick:Te,label:ge("todos.collapseStack"),size:"sm",children:t.jsx(Xj,{size:14})}),Pe,!I&&t.jsxs("button",{onClick:()=>F(!0),className:"btn-primary text-xs py-2",children:[t.jsx(mn,{size:14}),ge("todos.add")]})]})]}),I&&t.jsx("div",{className:"mb-5 animate-slide-up",children:t.jsx(__,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,availableTodos:e,onSave:async(Ne,it,lt,xt,ft,rt,Le,et,wt,kt)=>{await f(Ne,it,lt,xt,ft,rt,Le,et,wt,kt),F(!1)},onCancel:()=>F(!1)})}),t.jsx("div",{className:"flex items-center gap-1 mb-4 bg-warm-100 rounded-lg p-0.5 w-fit",children:["all","active","completed","cancelled"].map(Ne=>{const it=he===Ne,lt=Ne==="all"?"todos.filterAll":Ne==="active"?"todos.filterActive":Ne==="completed"?"todos.filterCompleted":"todos.filterCancelled";return t.jsxs("button",{onClick:()=>Oe(Ne),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${it?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[t.jsx("span",{children:ge(lt)}),t.jsx("span",{className:`text-2xs font-mono ${it?"text-accent/70":"text-warm-400"}`,children:ke[Ne]})]},Ne)})}),t.jsx("div",{className:ye?"relative cursor-pointer":"space-y-3",onClick:ye?Te:void 0,title:ye?ge("todos.expandStack"):void 0,style:ye?{height:76+Math.max($e.length-1,0)*6}:void 0,children:$e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:Ew,title:ge(he==="all"?"todos.empty":"todos.filterEmpty"),description:he==="all"?ge("todos.emptyHint"):void 0})}):(()=>{const Ne=$e.map(({todo:lt})=>lt.id),it=lt=>{if(ye||!R)return null;const xt=q!==null&&$===lt;return t.jsx("div",{onDragEnter:ft=>{ft.preventDefault(),fe(lt)},onDragOver:ft=>{ft.preventDefault(),ft.stopPropagation(),ft.dataTransfer.dropEffect="link",fe(lt)},onDragLeave:()=>ue(lt),onDrop:ft=>{ft.preventDefault(),ft.stopPropagation(),je(lt,Ne)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:xt&&t.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 t.jsxs(t.Fragment,{children:[it(0),$e.map(({todo:lt,depth:xt},ft)=>{const rt=be.has(lt.id),Le=De.has(lt.id),et=6,wt="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",kt=ye?{position:"absolute",top:ft*et,left:0,right:0,zIndex:$e.length+10-ft,opacity:ft===0?1:.9,pointerEvents:ft===0?"auto":"none",transition:wt}:{transition:wt};return t.jsxs("div",{className:ye?"":"animate-fade-in",style:ye?kt:{animationDelay:`${ft*30}ms`,...kt},children:[!ye&&rt&&t.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:`${ft*30}ms`},children:[t.jsx(Ua,{size:16,className:"text-theme-muted flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:ge("todo.chainComplete")}),t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:ge("todo.chainTasks").replace("{count}",String(be.get(lt.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Qe&&Fe===null&&t.jsx("span",{className:"text-2xs text-status-error",children:Qe}),t.jsxs("button",{onClick:()=>xe(lt.id),disabled:Fe===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:ge("todo.mergeChainDesc"),children:[t.jsx(kj,{size:14}),Fe===lt.id?"...":ge("todo.mergeChain")]})]})]}),t.jsxs("div",{className:"relative animate-fade-in",style:{animationDelay:`${ft*30}ms`,marginLeft:xt>0?`${xt*24}px`:void 0},children:[xt>0&&t.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),t.jsx(k6,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onStart:c,onStop:d,onDelete:p,onEdit:u,onMerge:v,onCleanup:C,onRetry:S,onContinue:x,onFix:y,onSchedule:w,onScheduleOnReset:k,resetsAt:N,onEvent:E,isInteractive:A.has(lt.id),onSendInput:L,isDragSource:q===lt.id,isDragging:q!==null,isDragOver:B===lt.id,isValidDropTarget:ce(lt.id),onDragStart:we,onDragEnd:Q,onDragOverTarget:K,onDragLeaveTarget:ne,onDropTarget:ee,onRemoveDependency:D?se:void 0,debugLogging:O,showTokenUsage:z,isChainMember:Le})]}),it(ft+1)]},lt.id)})]})})()}),!ye&&q&&((Ve=e.find(Ne=>Ne.id===q))==null?void 0:Ve.depends_on)&&t.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:Ne=>{Ne.preventDefault(),Ne.dataTransfer.dropEffect="move"},onDrop:Ne=>{Ne.preventDefault(),q&&D&&(ie.current=!0,D(q,null))},children:[t.jsx(WN,{size:20,className:"mx-auto mb-1"}),ge("dnd.dropToRemoveDep")]}),H&&t.jsx(Cr,{x:H.x,y:H.y,onClose:()=>U(null),children:t.jsxs("button",{onClick:()=>F(!0),className:sn,children:[t.jsx(mn,{size:14}),ge("todos.add")]})})]})}const N6=[{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 E6(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 v=parseInt(u);return isNaN(v)?-1:v}).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 Zb(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 T6({value:e,onChange:s}){const{t:i}=st(),[a,h]=_.useState(()=>E6(e)),[f,m]=_.useState(e);_.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=Zb(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(x=>x!==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,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:b,onChange:y=>S(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:24},(y,w)=>t.jsx("option",{value:w,children:String(w).padStart(2,"0")},w))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:y=>x(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:12},(y,w)=>w*5).map(y=>t.jsx("option",{value:y,children:String(y).padStart(2,"0")},y))})]}),v=a.mode==="custom"?f:Zb(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map(b=>t.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))}),t.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[a.mode==="minutes"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.every")}),t.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=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),t.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=>t.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.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"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:N6.map(b=>t.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))}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.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"&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),t.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=>t.jsx("option",{value:b,children:b},b))}),t.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"&&t.jsxs("div",{children:[t.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"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&v&&t.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[t.jsxs("span",{className:"text-warm-400",children:[i("cron.expression"),":"]}),t.jsx("code",{className:"px-2 py-0.5 rounded bg-warm-100 text-warm-600 font-mono",children:v})]})]})}function L6(){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 D6(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 k_({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]=_.useState(i),[v,b]=_.useState(a),[C,S]=_.useState(h),[x,y]=_.useState(f||d||"claude"),[w,k]=_.useState(m),[N,D]=_.useState(o),[j,R]=_.useState(c?D6(c):L6()),{t:E}=st(),L=N==="once",A=p.trim()&&(L?!!j:!!C.trim()),O=z=>{z.preventDefault(),A&&e({title:p.trim(),description:v.trim(),cronExpression:L?"":C.trim(),cliTool:x,skipIfRunning:w,scheduleType:N,runAt:L?new Date(j).toISOString():void 0})};return t.jsxs("form",{onSubmit:O,className:"card p-5 border-amber-500/30",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:E("scheduleForm.titlePlaceholder"),value:p,onChange:z=>u(z.target.value),className:"input-field",autoFocus:!0})}),t.jsx("div",{className:"mb-3",children:t.jsx("textarea",{placeholder:E("scheduleForm.descPlaceholder"),value:v,onChange:z=>b(z.target.value),rows:3,className:"prompt-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"})}),t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("schedule.type")}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("button",{type:"button",onClick:()=>D("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${N==="recurring"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:E("schedule.recurring")}),t.jsx("button",{type:"button",onClick:()=>D("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${N==="once"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:E("schedule.once")})]})]}),L?t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("schedule.runAtLabel")}),t.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)})]}):t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("schedule.cronExpression")}),t.jsx(T6,{value:C,onChange:S})]}),t.jsx("div",{className:"mb-3 grid grid-cols-2 gap-3",children:t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("scheduleForm.cliTool")}),t.jsx("select",{value:x,onChange:z=>y(z.target.value),className:"input-field text-sm !py-2",children:_r.map(z=>t.jsx("option",{value:z.value,children:z.label},z.value))})]})}),!L&&t.jsx("div",{className:"mb-4",children:t.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:w,onChange:z=>k(z.target.checked),className:"rounded border-warm-300 text-amber-500 focus:ring-amber-500"}),E("schedule.skipIfRunning")]})}),t.jsxs("div",{className:"flex gap-3 justify-end",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:E("scheduleForm.cancel")}),t.jsx("button",{type:"submit",disabled:!A,className:"btn-primary text-sm",children:E("scheduleForm.save")})]})]})}function R6({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:h,onMergeRun:f,onCleanupRun:m}){const[o,c]=_.useState(!1),[d,p]=_.useState(!1),[u,v]=_.useState([]),[b,C]=_.useState(!1),[S,x]=_.useState(!1),[y,w]=_.useState(null),{t:k}=st(),N=async()=>{try{const H=await pf(e.id);v(H)}catch{}},D=async H=>{if(!(!H.todo_id||!f)){w(H.id);try{await f(H.todo_id),await N()}finally{w(null)}}},j=async H=>{if(!(!H.todo_id||!m)){w(H.id);try{await m(H.todo_id),await N()}finally{w(null)}}},R=e.schedule_type==="once",E=async()=>{if(!b)try{const H=await pf(e.id);v(H),C(!0)}catch{}},L=()=>{const H=!o;c(H),H&&E()},A=async()=>{x(!0);try{await h(e.id);const H=await pf(e.id);v(H),C(!0)}finally{x(!1)}};if(d)return t.jsx(k_,{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"},I={triggered:k("schedule.runTriggered"),skipped:k("schedule.runSkipped"),completed:k("schedule.runCompleted"),failed:k("schedule.runFailed")},F=H=>H?new Date(H).toLocaleString():"";return t.jsxs("div",{className:`card border-l-4 ${O} overflow-hidden`,children:[t.jsxs("div",{className:"flex items-center gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:L,children:[t.jsx("button",{className:"text-warm-400 hover:text-amber-500 flex-shrink-0 transition-colors",children:t.jsx(Ts,{size:14,className:`transition-transform duration-200 ${o?"rotate-90":""}`})}),t.jsx("span",{className:"flex-1 text-sm text-warm-800 font-medium truncate",children:e.title}),R?t.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:[t.jsx(oi,{size:12}),F(e.run_at)]}):t.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}),t.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:k(R?"schedule.once":"schedule.recurring")}),t.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?k("schedule.active"):k("schedule.paused")}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:H=>H.stopPropagation(),children:[t.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:k("schedule.trigger"),children:t.jsx(kr,{size:14})}),t.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?k("schedule.pause"):k("schedule.activate"),children:e.is_active?t.jsx(Gm,{size:14}):t.jsx(ai,{size:14})}),t.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:k("schedule.edit"),children:t.jsx(ci,{size:14})}),t.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:k("schedule.delete"),children:t.jsx(jn,{size:14})})]})]}),o&&t.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&&t.jsx("div",{children:t.jsx("p",{className:"text-sm text-warm-600 whitespace-pre-wrap leading-relaxed",children:e.description})}),t.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[R?t.jsxs("span",{className:"badge bg-blue-500/10 text-blue-600 font-mono",children:[k("schedule.runAtLabel"),": ",F(e.run_at)]}):t.jsx("span",{className:"badge bg-amber-500/10 text-amber-600 font-mono",children:e.cron_expression}),!R&&e.skip_if_running?t.jsx("span",{className:"badge bg-status-info/10 text-status-info",children:k("schedule.skipIfRunning")}):null,t.jsxs("span",{className:"badge bg-warm-200 text-warm-600",children:[k("schedule.lastRun"),": ",e.last_run_at?new Date(e.last_run_at).toLocaleString():k("schedule.never")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:k("schedule.runs")}),u.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:k("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:u.map(H=>{const U=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),X=y===H.id;return t.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[t.jsx("span",{className:`font-medium ${z[H.status]||"text-warm-500"}`,children:I[H.status]||H.status}),H.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",H.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[U&&f&&t.jsx("button",{onClick:()=>D(H),disabled:X,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded transition-colors disabled:opacity-30",title:k("todo.merge"),children:t.jsx(dl,{size:12})}),q&&m&&t.jsx("button",{onClick:()=>j(H),disabled:X,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded transition-colors disabled:opacity-30",title:k("todo.cleanup"),children:t.jsx(jn,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(H.started_at).toLocaleString()})]},H.id)})})]})]})]})}function M6({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:h,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:c}){const[d,p]=_.useState(!1),[u,v]=_.useState(null),{t:b}=st();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{hi(C)||(C.preventDefault(),v({x:C.clientX,y:C.clientY}))},children:[t.jsxs("div",{className:"flex items-center justify-between mb-5",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:b("schedules.title")}),!d&&t.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[t.jsx(mn,{size:14}),b("schedules.add")]})]}),d&&t.jsx("div",{className:"mb-5 animate-slide-up",children:t.jsx(k_,{projectCliTool:s,onSave:async C=>{await i(C),p(!1)},onCancel:()=>p(!1)})}),t.jsx("div",{className:"space-y-3",children:e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:Pj,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,S)=>t.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${S*30}ms`},children:t.jsx(R6,{schedule:C,onToggle:a,onDelete:h,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:c})},C.id))}),u&&t.jsx(Cr,{x:u.x,y:u.y,onClose:()=>v(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>p(!0),children:[t.jsx(mn,{size:14}),b("schedules.add")]})})]})}function C_(e){const[s,i]=_.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return _.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 ey="__custom__";function A6({open:e,onClose:s,projectId:i,projectName:a,onPushed:h}){const{t:f}=st(),[m,o]=_.useState(!1),[c,d]=_.useState(!1),[p,u]=_.useState(null),[v,b]=_.useState([]),[C,S]=_.useState("origin"),[x,y]=_.useState([]),[w,k]=_.useState([]),[N,D]=_.useState(!0),[j,R]=_.useState(!1);_.useEffect(()=>{if(!e)return;let H=!1;return o(!0),u(null),Promise.all([fE(i),nm(i)]).then(([U,q])=>{var he,re;if(H)return;const X=U.remotes||[];b(X);const B=((he=X.find(J=>J.name==="origin"))==null?void 0:he.name)||((re=X[0])==null?void 0:re.name)||"origin";S(B);const P=q.branches||[],$=P.filter(J=>!J.remote),Y=`remotes/${B}/`,W=P.filter(J=>J.remote&&J.name.startsWith(Y)).map(J=>J.name.slice(Y.length)).filter(J=>J&&J!=="HEAD");k(W);const Z=new Set(W);y($.map(J=>{const V=Z.has(J.name);return{local:J.name,current:J.current,remote:J.name,customRemote:!1,setUpstream:!V,checked:J.current}}))}).catch(U=>{H||u(U instanceof Error?U.message:"Failed to load remotes")}).finally(()=>{H||o(!1)}),()=>{H=!0}},[e,i]),_.useEffect(()=>{if(!e||!C)return;let H=!1;return nm(i).then(U=>{if(H)return;const q=`remotes/${C}/`,X=(U.branches||[]).filter(B=>B.remote&&B.name.startsWith(q)).map(B=>B.name.slice(q.length)).filter(B=>B&&B!=="HEAD");k(X)}).catch(()=>{}),()=>{H=!0}},[C,i,e]);const E=x.length>0&&x.every(H=>H.checked),L=x.some(H=>H.checked),A=x.filter(H=>H.checked).length,O=_.useMemo(()=>{var H;return((H=v.find(U=>U.name===C))==null?void 0:H.url)||""},[v,C]),z=(H,U)=>{y(q=>q.map(X=>X.local===H?{...X,...U}:X))},I=()=>{const H=!E;y(U=>U.map(q=>({...q,checked:H})))},F=async()=>{u(null);const H=x.filter(q=>q.checked);if(H.length===0){u(f("git.pushDialog.errorRequireBranch"));return}const U=H.map(q=>({local:q.local,remote:(q.remote||"").trim()||q.local,setUpstream:q.setUpstream}));d(!0);try{await qm(i,{remote:C,branches:U,pushAllTags:N,force:j}),h==null||h(),s()}catch(q){u(q instanceof Error?q.message:"Push failed")}finally{d(!1)}};return t.jsx($n,{open:e,onClose:c?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:c,children:t.jsxs("div",{className:"card p-5 space-y-4",children:[t.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),t.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||v.length===0,children:[v.length===0&&t.jsx("option",{value:"origin",children:"origin"}),v.map(H=>t.jsx("option",{value:H.name,children:H.name},H.name))]}),t.jsx("input",{readOnly:!0,value:O,className:"input-field text-xs font-mono py-1.5 px-3 flex-1 cursor-default"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"section-label mb-2",children:f("git.pushDialog.branchesHeader")}),t.jsx("div",{className:"rounded-xl border border-theme-border-strong overflow-hidden",children:t.jsx("div",{className:"overflow-auto max-h-[50vh]",children:t.jsxs("table",{className:"w-full text-sm border-collapse",children:[t.jsx("thead",{className:"sticky top-0 bg-warm-100 z-10",children:t.jsxs("tr",{children:[t.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")}),t.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colLocal")}),t.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colRemote")}),t.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")})]})}),t.jsxs("tbody",{children:[m&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!m&&x.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.noLocalBranches")})}),x.map(H=>t.jsxs("tr",{className:"border-t border-theme-border/50 hover:bg-theme-hover/40 transition-colors",children:[t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:H.checked,onChange:U=>z(H.local,{checked:U.target.checked}),disabled:c,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[H.local,H.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:H.customRemote?t.jsx("input",{type:"text",value:H.remote,onChange:U=>z(H.local,{remote:U.target.value}),placeholder:H.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c}):t.jsxs("select",{value:w.includes(H.remote)||H.remote?H.remote:"",onChange:U=>{const q=U.target.value;q===ey?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&&t.jsxs("option",{value:H.remote,children:[H.remote," (",f("git.pushDialog.newBranch"),")"]}),w.map(U=>t.jsx("option",{value:U,children:U},U)),t.jsx("option",{value:ey,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:H.setUpstream,onChange:U=>z(H.local,{setUpstream:U.target.checked}),disabled:c,className:"cursor-pointer"})})]},H.local))]})]})})})]}),t.jsxs("div",{className:"flex items-center gap-5 text-xs text-warm-700",children:[t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:E,ref:H=>{H&&(H.indeterminate=!E&&L)},onChange:I,disabled:c||x.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:N,onChange:H=>D(H.target.checked),disabled:c,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:j,onChange:H=>R(H.target.checked),disabled:c,className:"cursor-pointer"}),t.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),p&&t.jsx("div",{className:"text-xs text-status-error font-medium",children:p}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{type:"button",onClick:s,disabled:c,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.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 O6(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 bp({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:h}){const{t:f}=st();return t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[t.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:f("git.changedFiles")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-2xs text-warm-400",children:[e.length," ",f("git.files")]}),h&&t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:h.substring(0,7)})]})]}),s?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.loadingFiles")})}):e.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.noFilesChanged")})}):t.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(m=>{const o=O6(m.status),c=i===m.path;return t.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:[t.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),t.jsxs("span",{className:"truncate flex-1 text-warm-600",title:m.path,children:[m.path.split("/").pop(),t.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:m.path.includes("/")?m.path.substring(0,m.path.lastIndexOf("/")):""})]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",m.additions]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",m.deletions]})]},m.path)})})]})}function Ku({diff:e,loading:s,selectedFile:i}){const{t:a}=st();return i?s?t.jsx("div",{className:"h-full flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:a("git.loadingDiff")})}):t.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[t.jsx("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0",children:t.jsx("span",{className:"text-xs font-mono text-gray-100",children:i})}),t.jsx("div",{className:"flex-1 overflow-auto",children:t.jsx("pre",{className:"p-3 font-mono text-xs leading-relaxed",children:e?e.split(`
649
+ `).map((_e,ht)=>{let bt="text-theme-text",Kt="";return _e.startsWith("+")&&!_e.startsWith("+++")?bt="text-theme-text bg-status-success/15":_e.startsWith("-")&&!_e.startsWith("---")?bt="text-theme-text bg-status-error/15":_e.startsWith("@@")?bt="text-accent":_e.startsWith("diff ")&&(bt="text-warm-700",Kt="font-semibold"),t.jsx("div",{className:`whitespace-pre ${bt} ${Kt}`,children:_e},ht)}):t.jsx("span",{className:"text-warm-400 italic",children:ve("log.noChanges")})})]}),t.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:Ie.bg,fontFamily:Rt,border:`1px solid ${Ie.separator}`},children:[t.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${Ie.separator}`,fontSize:12,color:Ie.text},children:[t.jsx("span",{style:{color:Ie.prompt},children:"$"})," ",t.jsx("span",{style:{color:Ie.bright},children:"tail"})," ",t.jsx("span",{style:{color:Ie.dim},children:"-f task.log"})]}),t.jsx(w_,{logs:$,interactive:w&&e.status==="running",todoId:e.id,onSendInput:k,embedded:!0})]})]})})]}),ct&&t.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:[t.jsx(Ua,{size:14,className:"text-accent flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-accent",children:ve("dnd.dropHint")})]}),Ge&&t.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:[t.jsx(Tj,{size:14,className:"text-red-400 flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-red-400",children:ve("dnd.cyclicWarning")})]}),Re&&t.jsxs(Cr,{x:Re.x,y:Re.y,onClose:()=>Ee(null),children:[at&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:sn,title:ve("todo.startHeadless"),children:[t.jsx(kr,{size:14}),ve("todo.start")]}),at&&gi&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:sn,title:ve("todo.startInteractiveDesc"),children:[t.jsx(di,{size:14}),ve("todo.startInteractive")]}),at&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:sn,title:ve("todo.startVerboseDesc"),children:[t.jsx(Zf,{size:14}),ve("todo.startVerbose")]}),Tt&&t.jsxs("button",{onClick:()=>m(e.id),className:sn,children:[t.jsx(qi,{size:14}),ve("todo.stop")]}),Ft&&t.jsxs("button",{onClick:Gn,disabled:Oe,className:sn,children:[t.jsx(dl,{size:14}),ve("todo.merge")]}),Wn&&t.jsxs("button",{onClick:()=>{xe(!0),ee(null)},disabled:Q,className:sn,children:[t.jsx(Ev,{size:14}),ve("todo.continue")]}),Dn&&t.jsxs("button",{onClick:()=>Rs("headless"),disabled:De,className:sn,children:[t.jsx(ui,{size:14}),ve("todo.retry")]}),vt&&t.jsxs("button",{onClick:()=>ft(!0),className:sn,title:ve("todo.scheduleDesc"),children:[t.jsx(Jf,{size:14}),ve("todo.schedule")]}),Ct&&t.jsxs("button",{onClick:()=>{ce(!0),Pe(null)},className:sn,title:ve("todo.scheduleOnResetDesc"),children:[t.jsx(oi,{size:14}),ve("todo.scheduleOnReset")]}),Nt&&t.jsxs("button",{onClick:ps,disabled:pe,className:sn,children:[t.jsx(Ui,{size:14}),ve("todo.viewDiff")]}),F&&Tn&&t.jsxs("button",{onClick:Fs,className:sn,children:[t.jsx(Mv,{size:14}),ve("todo.viewDebugLog")]}),In&&t.jsxs("button",{onClick:gs,disabled:ke,className:sn,children:[t.jsx(mu,{size:14}),ve("todo.cleanup")]}),t.jsx(S_,{}),t.jsxs("button",{onClick:()=>P(!0),className:sn,children:[t.jsx(ci,{size:14}),ve("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:vp,children:[t.jsx(jn,{size:14}),ve("todo.delete")]})]})]})}const C6=_.lazy(()=>Fu(()=>import("./TaskGraph-BEUkqd9I.js"),__vite__mapDeps([0,1,2,3,4]))),qc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function Qb(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 j6({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:v,onMergeChain:b,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:x,onFixTodo:y,onScheduleTodo:w,onScheduleOnResetTodo:k,resetsAt:N,onUpdateDependency:D,onUpdatePosition:j,onReorderTodos:R,onEvent:E,onSendInput:L,interactiveTodos:A,debugLogging:O,showTokenUsage:z}){var Ve;const[I,F]=_.useState(!1),[H,U]=_.useState(null),[q,X]=_.useState(null),[B,P]=_.useState(null),[$,Y]=_.useState(null),[W,Z]=_.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[he,re]=_.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[J,V]=_.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[pe,oe]=_.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:ge}=st(),le=_.useCallback(Ne=>{Z(Ne);try{localStorage.setItem("todoViewMode",Ne)}catch{}},[]),Oe=_.useCallback(Ne=>{re(Ne);try{localStorage.setItem("todoStatusFilter",Ne)}catch{}},[]),He=_.useCallback(()=>{V(Ne=>{const it=!Ne;try{localStorage.setItem("todoStackModeEnabled",String(it))}catch{}if(!it){oe(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return it})},[]),Te=_.useCallback(()=>{oe(Ne=>{const it=!Ne;try{localStorage.setItem("todoStackCollapsed",String(it))}catch{}return it})},[]),ye=J&&pe&&W==="list",ke=_.useMemo(()=>({all:e.length,active:e.filter(Ne=>qc.active.includes(Ne.status)).length,completed:e.filter(Ne=>qc.completed.includes(Ne.status)).length,cancelled:e.filter(Ne=>qc.cancelled.includes(Ne.status)).length}),[e]),Ke=_.useMemo(()=>{const Ne=qc[he];return Ne?e.filter(it=>Ne.includes(it.status)):e},[e,he]),$e=(()=>{const Ne=[...Ke].sort((Le,et)=>Le.priority-et.priority);if(he!=="all"||ye)return Ne.map(Le=>({todo:Le,depth:0}));const it=new Map,lt=[];for(const Le of Ne)if(Le.depends_on){const et=it.get(Le.depends_on)||[];et.push(Le),it.set(Le.depends_on,et)}else lt.push(Le);const xt=[],ft=new Set,rt=(Le,et)=>{if(ft.has(Le.id))return;ft.add(Le.id),xt.push({todo:Le,depth:et});const wt=it.get(Le.id);if(wt)for(const kt of wt)rt(kt,et+1)};for(const Le of lt)rt(Le,0);for(const Le of Ne)ft.has(Le.id)||xt.push({todo:Le,depth:0});return xt})(),{completedChainRoots:be,completedChainMembers:De}=_.useMemo(()=>{const Ne=new Map;for(const ft of e)if(ft.depends_on){const rt=Ne.get(ft.depends_on)||[];rt.push(ft.id),Ne.set(ft.depends_on,rt)}const it=e.filter(ft=>!ft.depends_on&&Ne.has(ft.id)),lt=new Map,xt=new Set;for(const ft of it){const rt=[],Le=et=>{if(!e.find(de=>de.id===et))return;rt.push(et);const kt=Ne.get(et)||[];for(const de of kt)Le(de)};if(Le(ft.id),rt.length>=2&&rt.every(et=>{const wt=e.find(kt=>kt.id===et);return(wt==null?void 0:wt.status)==="completed"||(wt==null?void 0:wt.status)==="merged"})){lt.set(ft.id,rt.length);for(const et of rt)xt.add(et)}}return{completedChainRoots:lt,completedChainMembers:xt}},[e]),[Fe,qe]=_.useState(null),[Qe,nt]=_.useState(null),xe=_.useCallback(async Ne=>{if(b){qe(Ne),nt(null);try{await b(Ne)}catch(it){nt(it instanceof Error?it.message:"Merge failed")}finally{qe(null)}}},[b]),ie=_.useRef(!1),we=_.useCallback(Ne=>{ie.current=!1,X(Ne)},[]),Q=_.useCallback(async()=>{if(!ie.current&&q&&D){const Ne=e.find(it=>it.id===q);Ne!=null&&Ne.depends_on&&await D(q,null)}X(null),P(null),Y(null)},[q,e,D]),K=_.useCallback(Ne=>{P(Ne),Y(null)},[]),ne=_.useCallback(Ne=>{P(it=>it===Ne?null:it)},[]),ee=_.useCallback(async Ne=>{!q||!D||q!==Ne&&(Qb(e,q,Ne)||(ie.current=!0,await D(q,Ne),X(null),P(null),Y(null)))},[q,e,D]),se=_.useCallback(async Ne=>{D&&await D(Ne,null)},[D]),ce=_.useCallback(Ne=>!q||q===Ne?!1:!Qb(e,q,Ne),[q,e]),fe=_.useCallback(Ne=>{Y(Ne),P(null)},[]),ue=_.useCallback(Ne=>{Y(it=>it===Ne?null:it)},[]),je=_.useCallback(async(Ne,it)=>{if(!q||!R)return;const lt=it.indexOf(q);if(lt<0)return;const xt=it.filter(Le=>Le!==q),ft=Ne>lt?Ne-1:Ne;if(ft===lt){Y(null);return}const rt=[...xt.slice(0,ft),q,...xt.slice(ft)];ie.current=!0,await R(rt),X(null),Y(null),P(null)},[q,R]),Ue=e.some(Ne=>Ne.status==="pending"||Ne.status==="failed"||Ne.status==="stopped"),ut=e.some(Ne=>Ne.status==="running"),Pe=t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:m,disabled:!Ue,className:"btn-ghost text-sm",children:[t.jsx(kr,{size:14}),ge("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!ut,className:"btn-ghost text-sm",children:[t.jsx(qi,{size:14}),ge("header.stopAll")]})]});return W==="graph"?t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-5",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:ge("todos.title")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[t.jsx(xn,{onClick:()=>le("list"),label:ge("graph.listView"),size:"sm",children:t.jsx(gu,{size:14})}),t.jsx(xn,{onClick:()=>le("graph"),label:ge("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Dv,{size:14})})]}),Pe]})]}),t.jsx(_.Suspense,{fallback:null,children:t.jsx(C6,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onAddTodo:f,onStartTodo:c,onStopTodo:d,onDeleteTodo:p,onEditTodo:u,onMergeTodo:v,onCleanupTodo:C,onRetryTodo:S,onContinueTodo:x,onFixTodo:y,onUpdateDependency:D,onUpdatePosition:j,onEvent:E,onSendInput:L,interactiveTodos:A,debugLogging:O,showTokenUsage:z})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:Ne=>{hi(Ne)||(Ne.preventDefault(),U({x:Ne.clientX,y:Ne.clientY}))},children:[t.jsxs("div",{className:"flex items-center justify-between mb-5",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:ge("todos.title")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"flex items-center bg-warm-100 rounded-lg p-0.5",children:[t.jsx(xn,{onClick:()=>le("list"),label:ge("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(gu,{size:14})}),t.jsx(xn,{onClick:()=>le("graph"),label:ge("graph.graphView"),size:"sm",children:t.jsx(Dv,{size:14})})]}),t.jsx(xn,{onClick:He,label:ge(J?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:J?"active":"default",pressed:J,children:t.jsx(K5,{size:14})}),J&&!pe&&W==="list"&&$e.length>0&&t.jsx(xn,{onClick:Te,label:ge("todos.collapseStack"),size:"sm",children:t.jsx(Xj,{size:14})}),Pe,!I&&t.jsxs("button",{onClick:()=>F(!0),className:"btn-primary text-xs py-2",children:[t.jsx(mn,{size:14}),ge("todos.add")]})]})]}),I&&t.jsx("div",{className:"mb-5 animate-slide-up",children:t.jsx(__,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,availableTodos:e,onSave:async(Ne,it,lt,xt,ft,rt,Le,et,wt,kt)=>{await f(Ne,it,lt,xt,ft,rt,Le,et,wt,kt),F(!1)},onCancel:()=>F(!1)})}),t.jsx("div",{className:"flex items-center gap-1 mb-4 bg-warm-100 rounded-lg p-0.5 w-fit",children:["all","active","completed","cancelled"].map(Ne=>{const it=he===Ne,lt=Ne==="all"?"todos.filterAll":Ne==="active"?"todos.filterActive":Ne==="completed"?"todos.filterCompleted":"todos.filterCancelled";return t.jsxs("button",{onClick:()=>Oe(Ne),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${it?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[t.jsx("span",{children:ge(lt)}),t.jsx("span",{className:`text-2xs font-mono ${it?"text-accent/70":"text-warm-400"}`,children:ke[Ne]})]},Ne)})}),t.jsx("div",{className:ye?"relative cursor-pointer":"space-y-3",onClick:ye?Te:void 0,title:ye?ge("todos.expandStack"):void 0,style:ye?{height:76+Math.max($e.length-1,0)*6}:void 0,children:$e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:Ew,title:ge(he==="all"?"todos.empty":"todos.filterEmpty"),description:he==="all"?ge("todos.emptyHint"):void 0})}):(()=>{const Ne=$e.map(({todo:lt})=>lt.id),it=lt=>{if(ye||!R)return null;const xt=q!==null&&$===lt;return t.jsx("div",{onDragEnter:ft=>{ft.preventDefault(),fe(lt)},onDragOver:ft=>{ft.preventDefault(),ft.stopPropagation(),ft.dataTransfer.dropEffect="link",fe(lt)},onDragLeave:()=>ue(lt),onDrop:ft=>{ft.preventDefault(),ft.stopPropagation(),je(lt,Ne)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:xt&&t.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 t.jsxs(t.Fragment,{children:[it(0),$e.map(({todo:lt,depth:xt},ft)=>{const rt=be.has(lt.id),Le=De.has(lt.id),et=6,wt="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",kt=ye?{position:"absolute",top:ft*et,left:0,right:0,zIndex:$e.length+10-ft,opacity:ft===0?1:.9,pointerEvents:ft===0?"auto":"none",transition:wt}:{transition:wt};return t.jsxs("div",{className:ye?"":"animate-fade-in",style:ye?kt:{animationDelay:`${ft*30}ms`,...kt},children:[!ye&&rt&&t.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:`${ft*30}ms`},children:[t.jsx(Ua,{size:16,className:"text-theme-muted flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:ge("todo.chainComplete")}),t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:ge("todo.chainTasks").replace("{count}",String(be.get(lt.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Qe&&Fe===null&&t.jsx("span",{className:"text-2xs text-status-error",children:Qe}),t.jsxs("button",{onClick:()=>xe(lt.id),disabled:Fe===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:ge("todo.mergeChainDesc"),children:[t.jsx(kj,{size:14}),Fe===lt.id?"...":ge("todo.mergeChain")]})]})]}),t.jsxs("div",{className:"relative animate-fade-in",style:{animationDelay:`${ft*30}ms`,marginLeft:xt>0?`${xt*24}px`:void 0},children:[xt>0&&t.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),t.jsx(k6,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:h,onStart:c,onStop:d,onDelete:p,onEdit:u,onMerge:v,onCleanup:C,onRetry:S,onContinue:x,onFix:y,onSchedule:w,onScheduleOnReset:k,resetsAt:N,onEvent:E,isInteractive:A.has(lt.id),onSendInput:L,isDragSource:q===lt.id,isDragging:q!==null,isDragOver:B===lt.id,isValidDropTarget:ce(lt.id),onDragStart:we,onDragEnd:Q,onDragOverTarget:K,onDragLeaveTarget:ne,onDropTarget:ee,onRemoveDependency:D?se:void 0,debugLogging:O,showTokenUsage:z,isChainMember:Le})]}),it(ft+1)]},lt.id)})]})})()}),!ye&&q&&((Ve=e.find(Ne=>Ne.id===q))==null?void 0:Ve.depends_on)&&t.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:Ne=>{Ne.preventDefault(),Ne.dataTransfer.dropEffect="move"},onDrop:Ne=>{Ne.preventDefault(),q&&D&&(ie.current=!0,D(q,null))},children:[t.jsx(WN,{size:20,className:"mx-auto mb-1"}),ge("dnd.dropToRemoveDep")]}),H&&t.jsx(Cr,{x:H.x,y:H.y,onClose:()=>U(null),children:t.jsxs("button",{onClick:()=>F(!0),className:sn,children:[t.jsx(mn,{size:14}),ge("todos.add")]})})]})}const N6=[{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 E6(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 v=parseInt(u);return isNaN(v)?-1:v}).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 Zb(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 T6({value:e,onChange:s}){const{t:i}=st(),[a,h]=_.useState(()=>E6(e)),[f,m]=_.useState(e);_.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=Zb(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(x=>x!==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,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:b,onChange:y=>S(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:24},(y,w)=>t.jsx("option",{value:w,children:String(w).padStart(2,"0")},w))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:y=>x(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:12},(y,w)=>w*5).map(y=>t.jsx("option",{value:y,children:String(y).padStart(2,"0")},y))})]}),v=a.mode==="custom"?f:Zb(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map(b=>t.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))}),t.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[a.mode==="minutes"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.every")}),t.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=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),t.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=>t.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.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"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:N6.map(b=>t.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))}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.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"&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),t.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=>t.jsx("option",{value:b,children:b},b))}),t.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"&&t.jsxs("div",{children:[t.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"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&v&&t.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[t.jsxs("span",{className:"text-warm-400",children:[i("cron.expression"),":"]}),t.jsx("code",{className:"px-2 py-0.5 rounded bg-warm-100 text-warm-600 font-mono",children:v})]})]})}function L6(){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 D6(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 k_({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]=_.useState(i),[v,b]=_.useState(a),[C,S]=_.useState(h),[x,y]=_.useState(f||d||"claude"),[w,k]=_.useState(m),[N,D]=_.useState(o),[j,R]=_.useState(c?D6(c):L6()),{t:E}=st(),L=N==="once",A=p.trim()&&(L?!!j:!!C.trim()),O=z=>{z.preventDefault(),A&&e({title:p.trim(),description:v.trim(),cronExpression:L?"":C.trim(),cliTool:x,skipIfRunning:w,scheduleType:N,runAt:L?new Date(j).toISOString():void 0})};return t.jsxs("form",{onSubmit:O,className:"card p-5 border-amber-500/30",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:E("scheduleForm.titlePlaceholder"),value:p,onChange:z=>u(z.target.value),className:"input-field",autoFocus:!0})}),t.jsx("div",{className:"mb-3",children:t.jsx("textarea",{placeholder:E("scheduleForm.descPlaceholder"),value:v,onChange:z=>b(z.target.value),rows:3,className:"prompt-field min-h-[76px] max-h-[320px] resize-y [field-sizing:content]"})}),t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("schedule.type")}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("button",{type:"button",onClick:()=>D("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${N==="recurring"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:E("schedule.recurring")}),t.jsx("button",{type:"button",onClick:()=>D("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${N==="once"?"bg-amber-500 text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:E("schedule.once")})]})]}),L?t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("schedule.runAtLabel")}),t.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)})]}):t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("schedule.cronExpression")}),t.jsx(T6,{value:C,onChange:S})]}),t.jsx("div",{className:"mb-3 grid grid-cols-2 gap-3",children:t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:E("scheduleForm.cliTool")}),t.jsx("select",{value:x,onChange:z=>y(z.target.value),className:"input-field text-sm !py-2",children:_r.map(z=>t.jsx("option",{value:z.value,children:z.label},z.value))})]})}),!L&&t.jsx("div",{className:"mb-4",children:t.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:w,onChange:z=>k(z.target.checked),className:"rounded border-warm-300 text-amber-500 focus:ring-amber-500"}),E("schedule.skipIfRunning")]})}),t.jsxs("div",{className:"flex gap-3 justify-end",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:E("scheduleForm.cancel")}),t.jsx("button",{type:"submit",disabled:!A,className:"btn-primary text-sm",children:E("scheduleForm.save")})]})]})}function R6({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:h,onMergeRun:f,onCleanupRun:m}){const[o,c]=_.useState(!1),[d,p]=_.useState(!1),[u,v]=_.useState([]),[b,C]=_.useState(!1),[S,x]=_.useState(!1),[y,w]=_.useState(null),{t:k}=st(),N=async()=>{try{const H=await pf(e.id);v(H)}catch{}},D=async H=>{if(!(!H.todo_id||!f)){w(H.id);try{await f(H.todo_id),await N()}finally{w(null)}}},j=async H=>{if(!(!H.todo_id||!m)){w(H.id);try{await m(H.todo_id),await N()}finally{w(null)}}},R=e.schedule_type==="once",E=async()=>{if(!b)try{const H=await pf(e.id);v(H),C(!0)}catch{}},L=()=>{const H=!o;c(H),H&&E()},A=async()=>{x(!0);try{await h(e.id);const H=await pf(e.id);v(H),C(!0)}finally{x(!1)}};if(d)return t.jsx(k_,{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"},I={triggered:k("schedule.runTriggered"),skipped:k("schedule.runSkipped"),completed:k("schedule.runCompleted"),failed:k("schedule.runFailed")},F=H=>H?new Date(H).toLocaleString():"";return t.jsxs("div",{className:`card border-l-4 ${O} overflow-hidden`,children:[t.jsxs("div",{className:"flex items-center gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:L,children:[t.jsx("button",{className:"text-warm-400 hover:text-amber-500 flex-shrink-0 transition-colors",children:t.jsx(Ts,{size:14,className:`transition-transform duration-200 ${o?"rotate-90":""}`})}),t.jsx("span",{className:"flex-1 text-sm text-warm-800 font-medium truncate",children:e.title}),R?t.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:[t.jsx(oi,{size:12}),F(e.run_at)]}):t.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}),t.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:k(R?"schedule.once":"schedule.recurring")}),t.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?k("schedule.active"):k("schedule.paused")}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:H=>H.stopPropagation(),children:[t.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:k("schedule.trigger"),children:t.jsx(kr,{size:14})}),t.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?k("schedule.pause"):k("schedule.activate"),children:e.is_active?t.jsx(Gm,{size:14}):t.jsx(ai,{size:14})}),t.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:k("schedule.edit"),children:t.jsx(ci,{size:14})}),t.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:k("schedule.delete"),children:t.jsx(jn,{size:14})})]})]}),o&&t.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&&t.jsx("div",{children:t.jsx("p",{className:"text-sm text-warm-600 whitespace-pre-wrap leading-relaxed",children:e.description})}),t.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[R?t.jsxs("span",{className:"badge bg-blue-500/10 text-blue-600 font-mono",children:[k("schedule.runAtLabel"),": ",F(e.run_at)]}):t.jsx("span",{className:"badge bg-amber-500/10 text-amber-600 font-mono",children:e.cron_expression}),!R&&e.skip_if_running?t.jsx("span",{className:"badge bg-status-info/10 text-status-info",children:k("schedule.skipIfRunning")}):null,t.jsxs("span",{className:"badge bg-warm-200 text-warm-600",children:[k("schedule.lastRun"),": ",e.last_run_at?new Date(e.last_run_at).toLocaleString():k("schedule.never")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:k("schedule.runs")}),u.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:k("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:u.map(H=>{const U=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),X=y===H.id;return t.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[t.jsx("span",{className:`font-medium ${z[H.status]||"text-warm-500"}`,children:I[H.status]||H.status}),H.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",H.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[U&&f&&t.jsx("button",{onClick:()=>D(H),disabled:X,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded transition-colors disabled:opacity-30",title:k("todo.merge"),children:t.jsx(dl,{size:12})}),q&&m&&t.jsx("button",{onClick:()=>j(H),disabled:X,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded transition-colors disabled:opacity-30",title:k("todo.cleanup"),children:t.jsx(jn,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(H.started_at).toLocaleString()})]},H.id)})})]})]})]})}function M6({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:h,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:c}){const[d,p]=_.useState(!1),[u,v]=_.useState(null),{t:b}=st();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{hi(C)||(C.preventDefault(),v({x:C.clientX,y:C.clientY}))},children:[t.jsxs("div",{className:"flex items-center justify-between mb-5",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:b("schedules.title")}),!d&&t.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[t.jsx(mn,{size:14}),b("schedules.add")]})]}),d&&t.jsx("div",{className:"mb-5 animate-slide-up",children:t.jsx(k_,{projectCliTool:s,onSave:async C=>{await i(C),p(!1)},onCancel:()=>p(!1)})}),t.jsx("div",{className:"space-y-3",children:e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:Pj,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,S)=>t.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${S*30}ms`},children:t.jsx(R6,{schedule:C,onToggle:a,onDelete:h,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:c})},C.id))}),u&&t.jsx(Cr,{x:u.x,y:u.y,onClose:()=>v(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>p(!0),children:[t.jsx(mn,{size:14}),b("schedules.add")]})})]})}function C_(e){const[s,i]=_.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return _.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 ey="__custom__";function A6({open:e,onClose:s,projectId:i,projectName:a,onPushed:h}){const{t:f}=st(),[m,o]=_.useState(!1),[c,d]=_.useState(!1),[p,u]=_.useState(null),[v,b]=_.useState([]),[C,S]=_.useState("origin"),[x,y]=_.useState([]),[w,k]=_.useState([]),[N,D]=_.useState(!0),[j,R]=_.useState(!1);_.useEffect(()=>{if(!e)return;let H=!1;return o(!0),u(null),Promise.all([fE(i),nm(i)]).then(([U,q])=>{var he,re;if(H)return;const X=U.remotes||[];b(X);const B=((he=X.find(J=>J.name==="origin"))==null?void 0:he.name)||((re=X[0])==null?void 0:re.name)||"origin";S(B);const P=q.branches||[],$=P.filter(J=>!J.remote),Y=`remotes/${B}/`,W=P.filter(J=>J.remote&&J.name.startsWith(Y)).map(J=>J.name.slice(Y.length)).filter(J=>J&&J!=="HEAD");k(W);const Z=new Set(W);y($.map(J=>{const V=Z.has(J.name);return{local:J.name,current:J.current,remote:J.name,customRemote:!1,setUpstream:!V,checked:J.current}}))}).catch(U=>{H||u(U instanceof Error?U.message:"Failed to load remotes")}).finally(()=>{H||o(!1)}),()=>{H=!0}},[e,i]),_.useEffect(()=>{if(!e||!C)return;let H=!1;return nm(i).then(U=>{if(H)return;const q=`remotes/${C}/`,X=(U.branches||[]).filter(B=>B.remote&&B.name.startsWith(q)).map(B=>B.name.slice(q.length)).filter(B=>B&&B!=="HEAD");k(X)}).catch(()=>{}),()=>{H=!0}},[C,i,e]);const E=x.length>0&&x.every(H=>H.checked),L=x.some(H=>H.checked),A=x.filter(H=>H.checked).length,O=_.useMemo(()=>{var H;return((H=v.find(U=>U.name===C))==null?void 0:H.url)||""},[v,C]),z=(H,U)=>{y(q=>q.map(X=>X.local===H?{...X,...U}:X))},I=()=>{const H=!E;y(U=>U.map(q=>({...q,checked:H})))},F=async()=>{u(null);const H=x.filter(q=>q.checked);if(H.length===0){u(f("git.pushDialog.errorRequireBranch"));return}const U=H.map(q=>({local:q.local,remote:(q.remote||"").trim()||q.local,setUpstream:q.setUpstream}));d(!0);try{await qm(i,{remote:C,branches:U,pushAllTags:N,force:j}),h==null||h(),s()}catch(q){u(q instanceof Error?q.message:"Push failed")}finally{d(!1)}};return t.jsx($n,{open:e,onClose:c?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:c,children:t.jsxs("div",{className:"card p-5 space-y-4",children:[t.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),t.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||v.length===0,children:[v.length===0&&t.jsx("option",{value:"origin",children:"origin"}),v.map(H=>t.jsx("option",{value:H.name,children:H.name},H.name))]}),t.jsx("input",{readOnly:!0,value:O,className:"input-field text-xs font-mono py-1.5 px-3 flex-1 cursor-default"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"section-label mb-2",children:f("git.pushDialog.branchesHeader")}),t.jsx("div",{className:"rounded-xl border border-theme-border-strong overflow-hidden",children:t.jsx("div",{className:"overflow-auto max-h-[50vh]",children:t.jsxs("table",{className:"w-full text-sm border-collapse",children:[t.jsx("thead",{className:"sticky top-0 bg-warm-100 z-10",children:t.jsxs("tr",{children:[t.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")}),t.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colLocal")}),t.jsx("th",{className:"text-left text-2xs font-semibold uppercase tracking-wider text-warm-500 py-2 px-3",children:f("git.pushDialog.colRemote")}),t.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")})]})}),t.jsxs("tbody",{children:[m&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!m&&x.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.noLocalBranches")})}),x.map(H=>t.jsxs("tr",{className:"border-t border-theme-border/50 hover:bg-theme-hover/40 transition-colors",children:[t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:H.checked,onChange:U=>z(H.local,{checked:U.target.checked}),disabled:c,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[H.local,H.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:H.customRemote?t.jsx("input",{type:"text",value:H.remote,onChange:U=>z(H.local,{remote:U.target.value}),placeholder:H.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c}):t.jsxs("select",{value:w.includes(H.remote)||H.remote?H.remote:"",onChange:U=>{const q=U.target.value;q===ey?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&&t.jsxs("option",{value:H.remote,children:[H.remote," (",f("git.pushDialog.newBranch"),")"]}),w.map(U=>t.jsx("option",{value:U,children:U},U)),t.jsx("option",{value:ey,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:H.setUpstream,onChange:U=>z(H.local,{setUpstream:U.target.checked}),disabled:c,className:"cursor-pointer"})})]},H.local))]})]})})})]}),t.jsxs("div",{className:"flex items-center gap-5 text-xs text-warm-700",children:[t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:E,ref:H=>{H&&(H.indeterminate=!E&&L)},onChange:I,disabled:c||x.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:N,onChange:H=>D(H.target.checked),disabled:c,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:j,onChange:H=>R(H.target.checked),disabled:c,className:"cursor-pointer"}),t.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),p&&t.jsx("div",{className:"text-xs text-status-error font-medium",children:p}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{type:"button",onClick:s,disabled:c,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.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 O6(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 bp({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:h}){const{t:f}=st();return t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[t.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:f("git.changedFiles")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-2xs text-warm-400",children:[e.length," ",f("git.files")]}),h&&t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:h.substring(0,7)})]})]}),s?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.loadingFiles")})}):e.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.noFilesChanged")})}):t.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(m=>{const o=O6(m.status),c=i===m.path;return t.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:[t.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),t.jsxs("span",{className:"truncate flex-1 text-warm-600",title:m.path,children:[m.path.split("/").pop(),t.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:m.path.includes("/")?m.path.substring(0,m.path.lastIndexOf("/")):""})]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",m.additions]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",m.deletions]})]},m.path)})})]})}function Ku({diff:e,loading:s,selectedFile:i}){const{t:a}=st();return i?s?t.jsx("div",{className:"h-full flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:a("git.loadingDiff")})}):t.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[t.jsx("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0",children:t.jsx("span",{className:"text-xs font-mono text-gray-100",children:i})}),t.jsx("div",{className:"flex-1 overflow-auto",children:t.jsx("pre",{className:"p-3 font-mono text-xs leading-relaxed",children:e?e.split(`
650
650
  `).map((h,f)=>{let m="text-gray-200";return h.startsWith("+")&&!h.startsWith("+++")?m="text-gray-100 bg-green-500/20":h.startsWith("-")&&!h.startsWith("---")?m="text-gray-100 bg-red-500/20":h.startsWith("@@")?m="text-blue-400":h.startsWith("diff ")&&(m="text-amber-300 font-bold"),t.jsx("div",{className:m,children:h||" "},f)}):t.jsx("span",{className:"text-gray-400 italic",children:"No changes"})})})]}):t.jsx("div",{className:"h-full flex items-center justify-center",children:t.jsx("span",{className:"text-sm text-warm-400",children:a("git.selectFileToViewDiff")})})}const Ma=["#B08A3E","#4B8DFF","#7A8797","#5E748A","#8B8178","#667085","#78909C","#9A8F7F"];function z6(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=Ma[m%Ma.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 v=i.indexOf(p);if(v!==-1)c.push({fromLane:m,toLane:v,toRow:u,color:Ma[v%Ma.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:Ma[b%Ma.length]})}}a.push({lane:m,color:o,connections:c})}return a}function P6({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",t.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,zi=16,B6=4,I6=10;function H6({graphNodes:e,totalRows:s}){const a=(Math.min(I6,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)*zi+8;return t.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*zi+zi/2+4,d=f*ii+ii/2,p=m.toLane*zi+zi/2+4,u=m.toRow*ii+ii/2;if(c===p)return t.jsx("line",{x1:c,y1:d,x2:p,y2:u,stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`);{const v=(d+u)/2;return t.jsx("path",{d:`M${c},${d} C${c},${v} ${p},${v} ${p},${u}`,fill:"none",stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`)}})),e.map((h,f)=>{const m=h.lane*zi+zi/2+4,o=f*ii+ii/2;return t.jsx("circle",{cx:m,cy:o,r:B6,fill:h.color,stroke:"white",strokeWidth:1.5},`dot-${f}`)})]})}function F6({projectId:e,projectName:s,onRefresh:i,busy:a,setBusy:h,branches:f,statusFiles:m}){const{t:o}=st(),[c,d]=_.useState(null),[p,u]=_.useState(""),[v,b]=_.useState(""),[C,S]=_.useState(null),x=()=>{d(null),u(""),b(""),S(null)},y=async A=>{h(!0),S(null);try{await A(),x(),i()}catch(O){S(O instanceof Error?O.message:"Error")}finally{h(!1)}},w=m.some(A=>A.index!==" "&&A.index!=="?"),k=({label:A,onClick:O,icon:z,badge:I})=>t.jsxs("button",{onClick:O,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:A,children:[t.jsx("div",{className:"h-5 w-5 flex items-center justify-center text-warm-500",children:z}),t.jsx("span",{className:"text-2xs text-warm-600 whitespace-nowrap",children:A}),I!==void 0&&I>0&&t.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:I})]}),N=({title:A,children:O})=>t.jsx($n,{open:!0,onClose:x,size:"sm",children:t.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:[t.jsx("span",{className:"text-sm font-semibold text-warm-700",children:A}),t.jsx("button",{onClick:x,className:"text-warm-400 hover:text-warm-600",children:t.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),t.jsxs("div",{className:"p-4 space-y-3",children:[C&&t.jsx("p",{className:"text-status-error text-xs",children:C}),O]})]})}),D=f.filter(A=>!A.remote),j=f.find(A=>!A.remote&&A.current),R=m.length,E=(j==null?void 0:j.behind)??0,L=(j==null?void 0:j.ahead)??0;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1 border-b border-warm-100 overflow-x-auto",children:[t.jsx(k,{label:o("git.commit"),onClick:()=>d("commit"),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v6m3-3H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z"})}),badge:R}),t.jsx(k,{label:o("git.pull"),onClick:()=>y(()=>Fw(e)),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.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:E}),t.jsx(k,{label:o("git.push"),onClick:()=>d("push"),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.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:L}),t.jsx(k,{label:o("git.fetch"),onClick:()=>y(()=>$w(e)),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.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"})})}),t.jsx("div",{className:"w-px h-8 bg-warm-200 mx-1"}),t.jsx(k,{label:o("git.branch"),onClick:()=>d("branch"),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.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"})})}),t.jsx(k,{label:o("git.merge"),onClick:()=>d("merge"),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.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"})})}),t.jsx(k,{label:o("git.stash"),onClick:()=>d("stash"),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.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"})})}),t.jsx(k,{label:o("git.discard"),onClick:()=>{m.length!==0&&confirm(o("git.confirmDiscard"))&&y(()=>yE(e,void 0,!0))},icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.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"})})}),t.jsx(k,{label:o("git.tag"),onClick:()=>d("tag"),icon:t.jsxs("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:[t.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"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]})})]}),t.jsx(A6,{open:c==="push",onClose:x,projectId:e,projectName:s,onPushed:i}),c==="commit"&&t.jsxs(N,{title:o("git.commit"),children:[t.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:o("git.commitMessage"),value:p,onChange:A=>u(A.target.value),autoFocus:!0}),t.jsxs("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!p.trim()||!w,onClick:()=>y(()=>Hw(e,p.trim())),children:[o("git.commit")," ",!w&&t.jsxs("span",{className:"text-xs opacity-70 ml-1",children:["(",o("git.staged"),": 0)"]})]})]}),c==="branch"&&t.jsxs(N,{title:o("git.newBranch"),children:[t.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:o("git.branchName"),value:p,onChange:A=>u(A.target.value),autoFocus:!0}),t.jsx("div",{className:"flex gap-2",children:t.jsx("button",{className:"flex-1 btn-primary text-sm py-2",disabled:a||!p.trim(),onClick:()=>y(()=>mE(e,p.trim())),children:o("git.create")})}),D.length>0&&t.jsxs("div",{className:"border-t border-warm-100 pt-2 mt-1",children:[t.jsx("p",{className:"text-2xs text-warm-400 uppercase tracking-wider mb-1",children:o("git.selectBranch")}),t.jsx("div",{className:"max-h-32 overflow-y-auto space-y-px",children:D.filter(A=>!A.current).map(A=>t.jsxs("div",{className:"flex items-center justify-between px-2 py-1 text-xs hover:bg-warm-50 rounded group",children:[t.jsx("button",{className:"truncate text-warm-600 hover:text-accent",onClick:()=>y(()=>rm(e,A.name)),children:A.name}),t.jsx("button",{className:"text-warm-300 hover:text-status-error opacity-0 group-hover:opacity-100 transition-opacity text-2xs",onClick:()=>{confirm(`Delete branch ${A.name}?`)&&y(()=>sm(e,A.name))},children:o("git.delete")})]},A.name))})]})]}),c==="merge"&&t.jsxs(N,{title:o("git.merge"),children:[t.jsx("p",{className:"text-xs text-warm-500",children:o("git.selectBranch")}),t.jsx("div",{className:"max-h-48 overflow-y-auto space-y-px",children:D.filter(A=>!A.current).map(A=>t.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:()=>y(()=>Uw(e,A.name)),children:A.name},A.name))})]}),c==="stash"&&t.jsx($6,{projectId:e,busy:a,exec:y,inputValue:p,setInputValue:u}),c==="tag"&&t.jsxs(N,{title:o("git.tag"),children:[t.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:o("git.tagName"),value:p,onChange:A=>u(A.target.value),autoFocus:!0}),t.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:o("git.tagMessage"),value:v,onChange:A=>b(A.target.value)}),t.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!p.trim(),onClick:()=>y(()=>wE(e,p.trim(),v.trim()||void 0)),children:o("git.create")})]})]})}function $6({projectId:e,busy:s,exec:i,inputValue:a,setInputValue:h}){const{t:f}=st(),[m,o]=_.useState([]);return _.useEffect(()=>{bE(e).then(o).catch(()=>{})},[e]),t.jsx($n,{open:!0,onClose:()=>h(""),size:"sm",children:t.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[t.jsx("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:t.jsx("span",{className:"text-sm font-semibold text-warm-700",children:f("git.stash")})}),t.jsxs("div",{className:"p-4 space-y-3",children:[t.jsxs("div",{className:"flex gap-2",children:[t.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}),t.jsx("button",{className:"btn-primary text-sm px-3 py-2",disabled:s,onClick:()=>i(()=>xE(e,a.trim()||void 0)),children:f("git.stash")})]}),m.length>0?t.jsx("div",{className:"space-y-px max-h-40 overflow-y-auto",children:m.map(c=>t.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 text-xs hover:bg-warm-50 rounded",children:[t.jsx("span",{className:"text-warm-600 truncate flex-1",children:c.message||`stash@{${c.index}}`}),t.jsx("button",{className:"text-accent hover:underline text-[11px] ml-2 shrink-0",disabled:s,onClick:()=>i(()=>vE(e,c.index)),children:f("git.stashPop")})]},c.index))}):t.jsx("p",{className:"text-xs text-warm-400 text-center",children:f("git.noStashes")})]})]})})}function ty(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 ny({file:e,pane:s,selected:i,checked:a,onClick:h,onToggleCheck:f}){const m=s==="staged"?ty(e.index," "):ty(" ",e.working_dir==="?"?"?":e.working_dir),o=s==="unstaged"&&e.index==="?"&&e.working_dir==="?"?{label:"U",color:"text-warm-400"}:m;return t.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:[t.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}),t.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"?"+":"−"}),t.jsx("span",{className:"truncate flex-1",title:e.path,children:e.path})]})}function U6({diff:e,loading:s,file:i}){const{t:a}=st();if(!i)return t.jsx("div",{className:"h-full flex items-center justify-center bg-[#1A1A1A] text-gray-400",children:t.jsx("span",{className:"text-sm",children:a("git.selectFileForDiff")})});if(s)return t.jsx("div",{className:"h-full flex items-center justify-center bg-[#1A1A1A] text-gray-400",children:t.jsx("span",{className:"text-xs",children:a("git.loadingDiff")})});const h=i.index==="?"&&i.working_dir==="?";return t.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[t.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:i.path,children:i.path}),h&&t.jsx("span",{className:"text-2xs text-gray-400 italic",children:a("git.untrackedNewFile")})]}),t.jsx("div",{className:"flex-1 overflow-auto",children:e?t.jsx("pre",{className:"p-3 font-mono text-xs leading-relaxed",children:e.split(`
651
651
  `).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"),t.jsx("div",{className:o,children:f||" "},m)})}):t.jsx("div",{className:"p-6 text-center text-xs text-gray-400 italic",children:a(h?"git.untrackedNewFile":"git.noFilesChanged")})})]})}function W6({projectId:e,branchName:s,files:i,conflicted:a,busy:h,setBusy:f,onRefresh:m,onError:o,isMobile:c=!1}){const{t:d}=st(),p=_.useMemo(()=>new Set(a),[a]),u=_.useMemo(()=>i.filter(Z=>p.has(Z.path)),[i,p]),v=_.useMemo(()=>i.filter(Z=>Z.index!==" "&&Z.index!=="?"&&!p.has(Z.path)),[i,p]),b=_.useMemo(()=>i.filter(Z=>Z.working_dir!==" "&&Z.working_dir!=="?"||Z.index==="?"&&Z.working_dir==="?").filter(Z=>!(Z.index!==" "&&Z.index!=="?"&&Z.working_dir===" ")).filter(Z=>!p.has(Z.path)),[i,p]),[C,S]=_.useState(null),[x,y]=_.useState(()=>new Set),[w,k]=_.useState(()=>new Set),[N,D]=_.useState(""),[j,R]=_.useState(!1),[E,L]=_.useState(""),[A,O]=_.useState(!1),[z,I]=_.useState(!1);_.useEffect(()=>{y(Z=>{const he=new Set(v.map(V=>V.path));let re=!1;const J=new Set;return Z.forEach(V=>{he.has(V)?J.add(V):re=!0}),re?J:Z})},[v]),_.useEffect(()=>{k(Z=>{const he=new Set(b.map(V=>V.path));let re=!1;const J=new Set;return Z.forEach(V=>{he.has(V)?J.add(V):re=!0}),re?J:Z})},[b]);const F=_.useCallback(Z=>{y(he=>{const re=new Set(he);return re.has(Z)?re.delete(Z):re.add(Z),re})},[]),H=_.useCallback(Z=>{k(he=>{const re=new Set(he);return re.has(Z)?re.delete(Z):re.add(Z),re})},[]),U=_.useRef(null),[q,X]=_.useState(()=>{if(typeof window>"u")return .55;const Z=window.localStorage.getItem("clitrigger:git:working-pct"),he=Z?parseFloat(Z):NaN;return isNaN(he)?.55:Math.max(.3,Math.min(.8,he))});_.useEffect(()=>{localStorage.setItem("clitrigger:git:working-pct",String(q))},[q]);const B=_.useCallback(Z=>{if(!U.current)return;const he=U.current.getBoundingClientRect(),re=(Z-he.left)/he.width;X(Math.max(.3,Math.min(.8,re)))},[]),P=_.useMemo(()=>{if(!C)return null;const[Z,he]=C.split("::");return Z==="conflict"?u.find(re=>re.path===he)||null:Z==="staged"?v.find(re=>re.path===he)||null:b.find(re=>re.path===he)||null},[C,u,v,b]),$=C?C.split("::")[0]:null;_.useEffect(()=>{C||(u.length>0?S(`conflict::${u[0].path}`):v.length>0?S(`staged::${v[0].path}`):b.length>0&&S(`unstaged::${b[0].path}`))},[C,u,v,b]),_.useEffect(()=>{if(!C)return;const[Z,he]=C.split("::");(Z==="conflict"?u:Z==="staged"?v:b).some(J=>J.path===he)||S(null)},[C,u,v,b]),_.useEffect(()=>{if(!P||!$){D("");return}let Z=!1;return R(!0),SE(e,P.path,$==="staged").then(he=>{Z||D(he.diff)}).catch(()=>{Z||D("")}).finally(()=>{Z||R(!1)}),()=>{Z=!0}},[e,P,$]);const Y=async Z=>{f(!0),o(null);try{await Z(),m()}catch(he){o(he instanceof Error?he.message:"Operation failed")}finally{f(!1)}},W=async()=>{if(!(!E.trim()||v.length===0)){I(!0),f(!0),o(null);try{if(await Hw(e,E.trim()),A)try{await qm(e)}catch(Z){o(Z instanceof Error?`Commit OK, push failed: ${Z.message}`:"Push failed")}L(""),m()}catch(Z){o(Z instanceof Error?Z.message:"Commit failed")}finally{I(!1),f(!1)}}};return i.length===0?t.jsx("div",{className:"h-full flex items-center justify-center bg-theme-bg",children:t.jsx("span",{className:"text-sm text-warm-400",children:d("git.workingTreeClean")})}):t.jsxs("div",{ref:U,className:`h-full flex min-h-0 ${c?"flex-col":""}`,children:[t.jsxs("div",{style:c?void 0:{width:`${q*100}%`,minWidth:360},className:`shrink-0 flex flex-col min-h-0 ${c?"h-1/2":""}`,children:[u.length>0&&t.jsxs("div",{className:"flex flex-col min-h-0 border-b border-warm-200",style:{flex:"1 1 0"},children:[t.jsx("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center shrink-0 bg-status-error/10",children:t.jsxs("span",{className:"text-xs font-semibold text-status-error",children:[d("git.conflicts")," ",t.jsxs("span",{className:"text-warm-400 font-normal",children:["(",u.length,")"]})]})}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:u.map(Z=>t.jsxs("div",{onClick:()=>S(`conflict::${Z.path}`),className:`flex items-center gap-2 px-3 py-1 cursor-pointer text-xs select-none transition-colors ${C===`conflict::${Z.path}`?"bg-accent/15 text-accent":"hover:bg-warm-50 text-warm-700"}`,children:[t.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"}),t.jsx("span",{className:"truncate flex-1",title:Z.path,children:Z.path}),t.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:h,onClick:he=>{he.stopPropagation(),Y(()=>Bv(e,Z.path,"ours"))},children:d("git.acceptOurs")}),t.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:h,onClick:he=>{he.stopPropagation(),Y(()=>Bv(e,Z.path,"theirs"))},children:d("git.acceptTheirs")})]},`c-${Z.path}`))})]}),t.jsxs("div",{className:"flex flex-col min-h-0",style:{flex:"1 1 0"},children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center justify-between shrink-0 bg-warm-50",children:[t.jsxs("span",{className:"text-xs font-semibold text-warm-700",children:[d("git.stagedFiles")," ",t.jsxs("span",{className:"text-warm-400 font-normal",children:["(",v.length,")"]})]}),t.jsx("button",{className:"text-2xs text-warm-500 hover:text-warm-700 disabled:opacity-40",disabled:h||v.length===0,onClick:()=>{const Z=x.size>0?v.filter(he=>x.has(he.path)).map(he=>he.path):v.map(he=>he.path);Z.length!==0&&Y(()=>hE(e,Z))},children:x.size>0?`${d("git.unstageSelectedShort")} (${x.size})`:d("git.unstageAllShort")})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:v.length===0?t.jsx("div",{className:"p-3 text-2xs text-warm-400 italic",children:"—"}):v.map(Z=>t.jsx(ny,{file:Z,pane:"staged",selected:C===`staged::${Z.path}`,checked:x.has(Z.path),onClick:()=>S(`staged::${Z.path}`),onToggleCheck:()=>F(Z.path)},`s-${Z.path}`))})]}),t.jsxs("div",{className:"flex flex-col min-h-0 border-t border-warm-200",style:{flex:"1 1 0"},children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-200 flex items-center justify-between shrink-0 bg-warm-50",children:[t.jsxs("span",{className:"text-xs font-semibold text-warm-700",children:[d("git.unstagedFiles")," ",t.jsxs("span",{className:"text-warm-400 font-normal",children:["(",b.length,")"]})]}),t.jsx("button",{className:"text-2xs text-warm-500 hover:text-warm-700 disabled:opacity-40",disabled:h||b.length===0,onClick:()=>{const Z=w.size>0?b.filter(he=>w.has(he.path)).map(he=>he.path):b.map(he=>he.path);Z.length!==0&&Y(()=>dE(e,Z))},children:w.size>0?`${d("git.stageSelectedShort")} (${w.size})`:d("git.stageAllShort")})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:b.length===0?t.jsx("div",{className:"p-3 text-2xs text-warm-400 italic",children:"—"}):b.map(Z=>t.jsx(ny,{file:Z,pane:"unstaged",selected:C===`unstaged::${Z.path}`,checked:w.has(Z.path),onClick:()=>S(`unstaged::${Z.path}`),onToggleCheck:()=>H(Z.path)},`u-${Z.path}`))})]}),t.jsxs("div",{className:"border-t border-warm-200 shrink-0 bg-theme-bg",children:[t.jsx("div",{className:"p-2",children:t.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:d("git.commitMessage"),value:E,onChange:Z=>L(Z.target.value),onKeyDown:Z=>{(Z.metaKey||Z.ctrlKey)&&Z.key==="Enter"&&W()},disabled:z})}),t.jsxs("div",{className:"px-3 py-2 border-t border-warm-200 flex items-center gap-3",children:[t.jsxs("label",{className:"flex items-center gap-1.5 text-2xs text-warm-600 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:A,onChange:Z=>O(Z.target.checked),className:"h-3 w-3",disabled:z}),d("git.pushImmediately").replace("{remote}",`origin/${s||"main"}`)]}),t.jsx("button",{className:"ml-auto btn-primary text-xs px-3 py-1.5 disabled:opacity-50",onClick:W,disabled:z||h||!E.trim()||v.length===0||u.length>0,children:z?"...":d("git.commitButton")})]})]})]}),!c&&t.jsx(lu,{axis:"x",onResize:B}),t.jsx("div",{className:`flex-1 ${c?"min-h-0 border-t border-warm-200":"min-w-0"}`,children:t.jsx(U6,{diff:N,loading:j,file:P})})]})}function G6({branches:e,tags:s,stashCount:i,projectId:a,busy:h,setBusy:f,onRefresh:m,onError:o}){const{t:c}=st(),[d,p]=_.useState(new Set(["local","remote"])),[u,v]=_.useState(null),[b,C]=_.useState(null),[S,x]=_.useState(""),y=_.useRef(null),[w,k]=_.useState([]),[N,D]=_.useState(null);_.useEffect(()=>{Fv(a).then(F=>k(F.worktrees)).catch(()=>{})},[a]);const j=_.useCallback(()=>{Fv(a).then(F=>k(F.worktrees)).catch(()=>{})},[a]);_.useEffect(()=>{j()},[e,j]),_.useEffect(()=>{if(!u)return;const F=U=>{y.current&&!y.current.contains(U.target)&&v(null)},H=()=>v(null);return document.addEventListener("mousedown",F),document.addEventListener("scroll",H,!0),()=>{document.removeEventListener("mousedown",F),document.removeEventListener("scroll",H,!0)}},[u]),_.useEffect(()=>{if(!u||!y.current)return;const F=y.current.getBoundingClientRect();let{x:H,y:U}=u;H+F.width>window.innerWidth&&(H=window.innerWidth-F.width-8),U+F.height>window.innerHeight&&(U=window.innerHeight-F.height-8),(H!==u.x||U!==u.y)&&v({...u,x:H,y:U})},[u]);const R=async(F,H)=>{f(!0),o(null),v(null);try{await F(),m(),H&&H()}catch(U){o(U instanceof Error?U.message:"Error")}finally{f(!1)}},E=(F,H,U,q)=>{F.preventDefault(),F.stopPropagation(),v({branch:H,isRemote:U,isCurrent:q,x:F.clientX,y:F.clientY})},L=F=>{p(H=>{const U=new Set(H);return U.has(F)?U.delete(F):U.add(F),U})},A=e.filter(F=>!F.remote),O=e.filter(F=>F.remote),z=({id:F,label:H,count:U})=>t.jsxs("button",{onClick:()=>L(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:[t.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:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),H,t.jsx("span",{className:"text-warm-400 font-normal ml-auto",children:U})]}),I=({label:F,onClick:H,danger:U})=>t.jsx("button",{className:`w-full text-left px-3 py-1.5 hover:bg-theme-hover transition-colors ${U?"text-status-error":"text-theme-text"}`,disabled:h,onClick:H,children:F});return t.jsxs("div",{className:"space-y-1",children:[t.jsx(z,{id:"local",label:c("git.branches"),count:A.length}),d.has("local")&&t.jsx("div",{className:"pl-1 space-y-px",children:A.map(F=>t.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=>E(H,F.name,!1,!!F.current),children:[F.current&&t.jsx("svg",{className:"h-3 w-3 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})}),t.jsx("span",{className:"truncate",children:F.name}),(!!F.ahead||!!F.behind)&&t.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&&t.jsxs("span",{className:"text-emerald-700 dark:text-emerald-400",title:`${F.ahead} ${c("git.ahead")}`,children:[F.ahead,"↑"]}),!!F.behind&&t.jsxs("span",{className:"text-amber-700 dark:text-amber-400",title:`${F.behind} ${c("git.behind")}`,children:[F.behind,"↓"]})]})]},F.name))}),O.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(z,{id:"remote",label:c("git.remotes"),count:O.length}),d.has("remote")&&t.jsx("div",{className:"pl-1 space-y-px",children:O.map(F=>t.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=>E(H,F.name,!0,!1),children:F.name.replace("remotes/","")},F.name))})]}),s.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(z,{id:"tags",label:c("git.tags"),count:s.length}),d.has("tags")&&t.jsx("div",{className:"pl-1 space-y-px",children:s.map(F=>t.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:[t.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:[t.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"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 6h.008v.008H6V6z"})]}),F]},F))})]}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(z,{id:"worktrees",label:c("git.worktrees"),count:w.length}),d.has("worktrees")&&t.jsx("div",{className:"pl-1 space-y-px",children:w.map(F=>t.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:[t.jsx("svg",{className:"h-3 w-3 text-amber-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.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"})}),t.jsx("span",{className:"truncate flex-1",title:F.path,children:F.branch}),t.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||N===F.path,title:c("git.cleanupWorktree"),onClick:()=>{confirm(c("git.confirmCleanupWorktree").replace("{name}",F.branch))&&(D(F.path),f(!0),o(null),$v(a,F.path,F.branch).then(()=>{k(H=>H.filter(U=>U.path!==F.path)),m()}).catch(H=>o(H instanceof Error?H.message:"Error")).finally(()=>{D(null),f(!1)}))},children:N===F.path?t.jsx("svg",{className:"h-3 w-3 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.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"})}):t.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.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&&t.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"),t.jsx("span",{className:"text-warm-400 font-normal ml-auto",children:i})]}),u&&rn.createPortal(t.jsxs("div",{ref:y,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&&t.jsx(I,{label:`${c("git.checkout")} ${u.branch}`,onClick:()=>R(()=>rm(a,u.branch))}),!u.isCurrent&&u.isRemote&&t.jsx(I,{label:`${c("git.checkoutRemote")} ${u.branch.replace(/^(remotes\/)?origin\//,"")}`,onClick:()=>{const F=u.branch.replace(/^(remotes\/)?origin\//,"");R(()=>rm(a,F))}}),!u.isCurrent&&t.jsx(I,{label:`${c("git.mergeInto")} ${u.branch}`,onClick:()=>R(()=>Uw(a,u.branch))}),!u.isCurrent&&!u.isRemote&&t.jsx(I,{label:`${c("git.rebaseOnto")} ${u.branch}`,onClick:()=>R(()=>_E(a,u.branch))}),t.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),t.jsx(I,{label:`${c("git.fetch")}`,onClick:()=>R(()=>$w(a))}),!u.isRemote&&t.jsxs(t.Fragment,{children:[t.jsx(I,{label:`${c("git.pull")}`,onClick:()=>R(()=>Fw(a))}),t.jsx(I,{label:`${c("git.push")}`,onClick:()=>R(()=>qm(a))})]}),!u.isRemote&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),t.jsx(I,{label:`${c("git.renameBranch")} ${u.branch}...`,onClick:()=>{C(u.branch),x(u.branch),v(null)}}),!u.isCurrent&&(()=>{const F=w.find(U=>U.branch===u.branch);if(F)return t.jsx(I,{danger:!0,label:`${c("git.deleteWorktreeAndBranch")} ${u.branch}`,onClick:()=>{confirm(c("git.confirmDeleteWorktreeAndBranch").replace("{name}",u.branch))?R(()=>$v(a,F.path,u.branch)):v(null)}});const H=u.branch;return t.jsx(I,{danger:!0,label:`${c("git.delete")} ${H}`,onClick:()=>{if(!confirm(c("git.confirmDelete").replace("{name}",H))){v(null);return}R(async()=>{try{await sm(a,H)}catch(U){const q=U instanceof Error?U.message:"";if(/not fully merged/i.test(q)&&confirm(c("git.confirmForceDelete").replace("{name}",H))){await sm(a,H,!0);return}throw U}})}})})()]})]}),document.body),b&&t.jsx($n,{open:!0,onClose:()=>C(null),size:"sm",children:t.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:[t.jsx("span",{className:"text-sm font-semibold text-warm-700",children:c("git.renameBranch")}),t.jsx("button",{onClick:()=>C(null),className:"text-warm-400 hover:text-warm-600",children:t.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),t.jsxs("div",{className:"p-4 space-y-3",children:[t.jsxs("p",{className:"text-xs text-warm-500",children:[b," →"]}),t.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=>x(F.target.value),onKeyDown:F=>{if(F.key==="Enter"&&S.trim()&&S.trim()!==b){const H=b;R(()=>Iv(a,H,S.trim()),()=>C(null))}},autoFocus:!0}),t.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:h||!S.trim()||S.trim()===b,onClick:()=>{const F=b;R(()=>Iv(a,F,S.trim()),()=>C(null))},children:c("git.rename")})]})]})})]})}function q6(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 sy({view:e,onChange:s,fileChangeCount:i,orientation:a="vertical"}){const{t:h}=st(),f=a==="horizontal",m=({id:o,label:c,badge:d})=>{const p=e===o;return t.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:[t.jsx("span",{className:`${f?"":"flex-1 text-left"} truncate`,children:c}),d!==void 0&&d>0&&t.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?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(m,{id:"fileStatus",label:h("git.viewFileStatus"),badge:i}),t.jsx(m,{id:"history",label:h("git.viewHistory")})]}):t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"px-2 text-[10px] font-bold text-warm-400 uppercase tracking-widest flex items-center gap-2",children:[t.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.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")]}),t.jsxs("div",{className:"space-y-0.5",children:[t.jsx(m,{id:"fileStatus",label:h("git.viewFileStatus"),badge:i}),t.jsx(m,{id:"history",label:h("git.viewHistory")})]})]})}function lu({axis:e,onResize:s}){return t.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 K6({x:e,y:s,message:i,onDismiss:a}){const h=_.useRef(null),[f,m]=_.useState(null);return _.useEffect(()=>{if(!h.current)return;const o=h.current.getBoundingClientRect(),c=o.width,d=o.height,p=window.innerWidth,u=window.innerHeight;let v=s-d-12;v<8&&(v=s+12),v+d>u-8&&(v=u-d-8);let b=e-c/2;b<8&&(b=8),b+c>p-8&&(b=p-c-8),m({top:v,left:b})},[e,s]),rn.createPortal(t.jsx("div",{onClick:a,onTouchStart:a,className:"fixed inset-0 z-tooltip",children:t.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 cu(e,s,i){return Math.max(s,Math.min(i,e))}function Af(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:cu(f,i,a)}function V6({project:e,refreshTrigger:s}){const{t:i}=st(),a=C_("(max-width: 767px)"),[h,f]=_.useState(!1),[m,o]=_.useState(null),c=_.useRef({timer:null,startX:0,startY:0,fired:!1}),[d,p]=_.useState(()=>{if(typeof window>"u")return"history";const Pe=window.localStorage.getItem(`git-view:${e.id}`);return Pe==="fileStatus"||Pe==="history"?Pe:"history"});_.useEffect(()=>{typeof window<"u"&&window.localStorage.setItem(`git-view:${e.id}`,d)},[d,e.id]);const[u,v]=_.useState([]),[b,C]=_.useState(!0),[S,x]=_.useState(!1),[y,w]=_.useState(!0),[k,N]=_.useState(null),[D,j]=_.useState([]),[R,E]=_.useState([]),[L,A]=_.useState(0),[O,z]=_.useState([]),[I,F]=_.useState(""),[H,U]=_.useState({merging:!1,rebasing:!1,conflicted:[]}),[q,X]=_.useState(!1),[B,P]=_.useState(null),[$,Y]=_.useState(null),[W,Z]=_.useState([]),[he,re]=_.useState(!1),[J,V]=_.useState(null),[pe,oe]=_.useState(""),[ge,le]=_.useState(!1),Oe=_.useRef(null),He=_.useRef(null),Te=_.useRef(!1),ye=_.useRef(null),ke=_.useRef(null),Ke=_.useRef(null),[$e,be]=_.useState(()=>Af("clitrigger:git:sidebar-w",224,180,480)),[De,Fe]=_.useState(()=>Af("clitrigger:git:detail-h-pct",.5,.2,.8)),[qe,Qe]=_.useState(()=>Af("clitrigger:git:detail-fl-w",240,160,500));_.useEffect(()=>{localStorage.setItem("clitrigger:git:sidebar-w",String($e))},[$e]),_.useEffect(()=>{localStorage.setItem("clitrigger:git:detail-h-pct",String(De))},[De]),_.useEffect(()=>{localStorage.setItem("clitrigger:git:detail-fl-w",String(qe))},[qe]);const nt=_.useCallback(Pe=>{if(!ye.current)return;const Ve=ye.current.getBoundingClientRect();be(cu(Pe-Ve.left,180,480))},[]),xe=_.useCallback((Pe,Ve)=>{if(!ke.current)return;const Ne=ke.current.getBoundingClientRect();Fe(cu((Ne.bottom-Ve)/Ne.height,.2,.8))},[]),ie=_.useCallback(Pe=>{if(!Ke.current)return;const Ve=Ke.current.getBoundingClientRect();Qe(cu(Pe-Ve.left,160,500))},[]),we=_.useCallback(async()=>{try{const Pe=await nm(e.id);j(Pe.branches),E(Pe.tags),A(Pe.stashCount)}catch{}},[e.id]),Q=_.useCallback(async()=>{try{const Pe=await Iw(e.id);z(Pe.files),F(Pe.branch||""),U({merging:!!Pe.mergeInProgress,rebasing:!!Pe.rebaseInProgress,conflicted:Pe.conflicted??[]})}catch{}},[e.id]),K=_.useCallback(async(Pe,Ve=!1)=>{if(!Te.current){Te.current=!0,x(!0),N(null);try{const Ne=await uE(e.id,Pe,50);v(it=>Ve?Ne.commits:[...it,...Ne.commits]),C(Ne.hasMore)}catch(Ne){N(Ne instanceof Error?Ne.message:"Failed to fetch git log")}finally{x(!1),w(!1),Te.current=!1}}},[e.id]),ne=_.useCallback(()=>{v([]),C(!0),w(!0),Y(null),Z([]),V(null),oe(""),K(0,!0),we(),Q()},[K,we,Q]),ee=_.useCallback(async Pe=>{X(!0),P(null);try{await Pe()}catch(Ve){P(Ve instanceof Error?Ve.message:"Operation failed")}finally{X(!1),ne()}},[ne]),se=_.useCallback(async Pe=>{if(($==null?void 0:$.hash)===Pe.hash){Y(null),Z([]),V(null),oe("");return}Y(Pe),V(null),oe(""),re(!0);try{const Ve=await kE(e.id,Pe.hash);if(Z(Ve.files),Ve.files.length>0){const Ne=Ve.files[0].path;V(Ne),le(!0);try{const it=await Hv(e.id,Pe.hash,Ne);oe(it.diff)}catch{oe("")}finally{le(!1)}}}catch{Z([])}finally{re(!1)}},[e.id,$==null?void 0:$.hash]),ce=_.useCallback(async Pe=>{if($){V(Pe),le(!0);try{const Ve=await Hv(e.id,$.hash,Pe);oe(Ve.diff)}catch{oe("")}finally{le(!1)}}},[e.id,$]),fe=_.useCallback(()=>{c.current.timer!==null&&(window.clearTimeout(c.current.timer),c.current.timer=null)},[]),ue=_.useCallback((Pe,Ve)=>{a&&(fe(),c.current.startX=Pe.clientX,c.current.startY=Pe.clientY,c.current.fired=!1,c.current.timer=window.setTimeout(()=>{if(c.current.fired=!0,c.current.timer=null,o({message:Ve,x:c.current.startX,y:c.current.startY}),typeof navigator<"u"&&typeof navigator.vibrate=="function")try{navigator.vibrate(10)}catch{}},500))},[a,fe]),je=_.useCallback(Pe=>{if(!a||c.current.timer===null)return;const Ve=Pe.clientX-c.current.startX,Ne=Pe.clientY-c.current.startY;Ve*Ve+Ne*Ne>64&&fe()},[a,fe]),Ue=_.useCallback(()=>{a&&fe()},[a,fe]);_.useEffect(()=>{if(!m)return;const Pe=()=>o(null);return window.addEventListener("scroll",Pe,!0),window.addEventListener("resize",Pe),()=>{window.removeEventListener("scroll",Pe,!0),window.removeEventListener("resize",Pe)}},[m]),_.useEffect(()=>{a||o(null)},[a]),_.useEffect(()=>{K(0,!0),we(),Q()},[K,we,Q]),_.useEffect(()=>{s&&s>0&&ne()},[s]),_.useEffect(()=>{const Pe=Oe.current;if(!Pe)return;const Ve=new IntersectionObserver(Ne=>{Ne[0].isIntersecting&&b&&!Te.current&&u.length>0&&K(u.length)},{rootMargin:"200px"});return Ve.observe(Pe),()=>Ve.disconnect()},[b,u.length,K]);const ut=_.useMemo(()=>z6(u),[u]);return t.jsxs("div",{className:"animate-fade-in flex flex-col",style:{height:"calc(100vh - 260px)",minHeight:"400px"},children:[t.jsx("div",{className:"card mb-2 overflow-hidden",children:t.jsx(F6,{projectId:e.id,projectName:e.name,onRefresh:ne,busy:q,setBusy:X,branches:D,statusFiles:O})}),(H.merging||H.rebasing||H.conflicted.length>0)&&t.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:[t.jsx("span",{className:"font-semibold shrink-0",children:H.merging?i("git.conflictMergeInProgress"):H.rebasing?i("git.conflictRebaseInProgress"):i("git.conflicts")}),t.jsx("span",{className:"flex-1 min-w-0 truncate",children:H.conflicted.length>0?i("git.conflictBanner").replace("{n}",String(H.conflicted.length)):i("git.conflictAllResolved")}),d!=="fileStatus"&&H.conflicted.length>0&&t.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:()=>p("fileStatus"),children:i("git.viewConflicts")}),(H.merging||H.rebasing)&&t.jsxs(t.Fragment,{children:[t.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:q||H.conflicted.length>0,onClick:()=>ee(()=>pE(e.id)),children:i("git.conflictContinue")}),t.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:q,onClick:()=>{window.confirm(i("git.confirmConflictAbort"))&&ee(()=>gE(e.id))},children:i("git.conflictAbort")})]})]}),B&&t.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:[t.jsx("span",{children:B}),t.jsx("button",{onClick:()=>P(null),className:"ml-2 shrink-0 hover:text-red-800 dark:hover:text-red-300",children:"×"})]}),t.jsxs("div",{ref:ye,className:`flex flex-1 min-h-0 ${a?"flex-col gap-2":""}`,children:[t.jsxs("div",{style:a?void 0:{width:$e},className:`shrink-0 flex flex-col gap-2 ${a?"":"min-h-0"}`,children:[a?t.jsxs("div",{className:"card p-2 flex items-center gap-2",children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(sy,{view:d,onChange:p,fileChangeCount:O.length,orientation:"horizontal"})}),t.jsxs("button",{onClick:()=>f(Pe=>!Pe),className:"btn-ghost text-xs flex items-center gap-1 shrink-0 px-3 py-2","aria-expanded":h,children:[t.jsx("svg",{className:`h-3 w-3 transition-transform ${h?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})}),i("git.branches")]})]}):t.jsx("div",{className:"card p-3 shrink-0",children:t.jsx(sy,{view:d,onChange:p,fileChangeCount:O.length})}),(!a||h)&&t.jsx("div",{className:`card overflow-y-auto p-3 ${a?"":"flex-1 min-h-0"}`,style:a?{maxHeight:"40vh"}:void 0,children:t.jsx(G6,{branches:D,tags:R,stashCount:L,projectId:e.id,busy:q,setBusy:X,onRefresh:ne,onError:P})})]}),!a&&t.jsx(lu,{axis:"x",onResize:nt}),t.jsx("div",{className:"card flex-1 overflow-hidden flex flex-col min-h-0",children:d==="fileStatus"?t.jsx(W6,{projectId:e.id,branchName:I,files:O,conflicted:H.conflicted,busy:q,setBusy:X,onRefresh:ne,onError:P,isMobile:a}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-warm-100",children:[t.jsx("span",{className:"text-sm font-semibold text-warm-700",children:i("git.commitHistory")}),t.jsxs("button",{onClick:ne,disabled:S,className:"btn-ghost text-xs flex items-center gap-1.5",children:[t.jsx("svg",{className:`h-3.5 w-3.5 ${S?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.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"})}),i("git.refresh")]})]}),t.jsxs("div",{className:`flex items-center py-1.5 border-b border-warm-50 text-2xs text-warm-400 uppercase tracking-wider ${a?"px-3":"px-4"}`,children:[!a&&t.jsx("div",{className:"w-24 shrink-0",children:i("git.graph")}),t.jsx("div",{className:"flex-1 min-w-0",children:i("git.description")}),t.jsx("div",{className:"w-14 text-right shrink-0",children:i("git.date")}),!a&&t.jsx("div",{className:"shrink-0 ml-2",children:i("git.author")}),t.jsx("div",{className:"w-16 text-right shrink-0",children:i("git.hash")})]}),k&&t.jsx("div",{className:"p-6 text-center",children:t.jsx("p",{className:"text-status-error text-sm",children:k})}),y&&!k&&t.jsx("div",{className:"p-6 text-center",children:t.jsx("p",{className:"text-warm-500 text-sm",children:i("detail.loading")})}),!y&&!k&&u.length===0&&t.jsx("div",{className:"p-6 text-center",children:t.jsx("p",{className:"text-warm-500 text-sm",children:i("git.noCommits")})}),u.length>0&&t.jsxs("div",{ref:ke,className:"flex-1 flex flex-col min-h-0",children:[t.jsxs("div",{className:"overflow-y-auto",ref:He,style:$?{flex:`${(1-De)*100} 1 0`,minHeight:0}:{flex:"1 1 0",minHeight:0},children:[t.jsxs("div",{className:"relative flex",children:[!a&&t.jsx("div",{className:"shrink-0 sticky left-0",children:t.jsx(H6,{graphNodes:ut,totalRows:u.length})}),t.jsx("div",{className:"flex-1 min-w-0",children:u.map(Pe=>{const Ve=($==null?void 0:$.hash)===Pe.hash;return t.jsxs("div",{onClick:Ne=>{if(c.current.fired){Ne.stopPropagation(),c.current.fired=!1;return}se(Pe)},onPointerDown:Ne=>ue(Ne,Pe.message),onPointerMove:je,onPointerUp:Ue,onPointerCancel:Ue,onContextMenu:a?Ne=>Ne.preventDefault():void 0,className:`flex items-center px-3 cursor-pointer transition-colors border-b border-warm-50/20 ${Ve?"bg-accent/10 border-l-2 border-l-accent":"hover:bg-warm-50/50"}`,style:{height:ii,...a?{touchAction:"pan-y",WebkitTouchCallout:"none",userSelect:"none"}:null},children:[t.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[Pe.refs.length>0&&t.jsx("div",{className:"flex items-center gap-1 shrink-0",children:Pe.refs.map((Ne,it)=>t.jsx(P6,{refStr:Ne},it))}),t.jsx("span",{className:"text-xs text-warm-700 truncate",title:Pe.message,children:Pe.message})]}),t.jsx("div",{className:"w-28 text-right shrink-0",children:t.jsx("span",{className:"text-[11px] font-mono text-warm-600",title:Pe.date,children:q6(Pe.date)})}),!a&&t.jsx("div",{className:"shrink-0 ml-2",children:t.jsx("span",{className:"text-[11px] text-warm-600",children:Pe.author})}),t.jsx("div",{className:"w-16 text-right shrink-0",children:t.jsx("span",{className:"text-[11px] font-mono text-warm-600 cursor-pointer hover:text-accent transition-colors",title:Pe.hash,onClick:Ne=>{Ne.stopPropagation(),navigator.clipboard.writeText(Pe.hash)},children:Pe.hash.substring(0,7)})})]},Pe.hash)})})]}),t.jsx("div",{ref:Oe,className:"h-8 flex items-center justify-center",children:S&&t.jsx("span",{className:"text-xs text-warm-400",children:i("git.loadMore")})})]}),$&&t.jsxs(t.Fragment,{children:[t.jsx(lu,{axis:"y",onResize:xe}),t.jsxs("div",{ref:Ke,className:`flex min-h-0 ${a?"flex-col":""}`,style:{flex:`${De*100} 1 0`,minHeight:0},children:[t.jsx("div",{style:a?void 0:{width:qe},className:`shrink-0 overflow-hidden ${a?"h-1/2":""}`,children:t.jsx(bp,{files:W,loading:he,selectedFile:J,onFileClick:ce,commitHash:$.hash})}),!a&&t.jsx(lu,{axis:"x",onResize:ie}),t.jsx("div",{className:`flex-1 overflow-hidden bg-warm-900 ${a?"min-h-0 border-t border-warm-200":"min-w-0"}`,children:t.jsx(Ku,{diff:pe,loading:ge,selectedFile:J})})]})]})]})]})})]}),m&&t.jsx(K6,{x:m.x,y:m.y,message:m.message,onDismiss:()=>o(null)})]})}function ry(e,s=!1){return dt(`/api/projects/${e}/svn-status${s?"?showUpdates=true":""}`)}function Y6(e,s=0,i=50){const a=new URLSearchParams({skip:String(s),limit:String(i)});return dt(`/api/projects/${e}/svn-log?${a}`)}function X6(e,s){return dt(`/api/projects/${e}/svn-commit-files?revision=${encodeURIComponent(s)}`)}function J6(e,s,i,a){const h=new URLSearchParams({revision:s});return i&&h.set("file",i),a&&h.set("status",a),dt(`/api/projects/${e}/svn-commit-diff?${h}`)}function Q6(e,s){const i=new URLSearchParams;s&&i.set("file",s);const a=i.toString();return dt(`/api/projects/${e}/svn-diff${a?`?${a}`:""}`)}function Z6(e,s){const i=new URLSearchParams;s&&i.set("file",s);const a=i.toString();return dt(`/api/projects/${e}/svn-properties${a?`?${a}`:""}`)}function e8(e,s,i,a){return Ze(`/api/projects/${e}/svn-propset`,{name:s,value:i,file:a})}function t8(e,s){return Ze(`/api/projects/${e}/svn-add`,{files:s})}function n8(e,s){return Ze(`/api/projects/${e}/svn-revert`,{files:s})}function s8(e,s,i=!1){return Ze(`/api/projects/${e}/svn-delete`,{files:s,keepLocal:i})}function r8(e,s,i="working"){return Ze(`/api/projects/${e}/svn-resolve`,{files:s,accept:i})}function i8(e,s,i){return Ze(`/api/projects/${e}/svn-changelist`,{name:s,files:i})}function a8(e,s,i){return Ze(`/api/projects/${e}/svn-commit`,{message:s,files:i})}function iy(e,s){return Ze(`/api/projects/${e}/svn-update`,{revision:s})}function o8(e){return Ze(`/api/projects/${e}/svn-cleanup`,{})}const Of=new Map,vr=e=>e.working_dir.trim()||"?",l8=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";function c8({project:e,refreshTrigger:s}){const{t:i}=st(),[a,h]=_.useState("modifications"),[f,m]=_.useState(null),[o,c]=_.useState(null),[d,p]=_.useState(null);_.useEffect(()=>{let Le=!1;return Qm().then(et=>{if(Le)return;const wt=et.find(kt=>kt.tool==="svn");p(wt?wt.installed:null)}).catch(()=>{}),()=>{Le=!0}},[]);const[u,v]=_.useState(()=>Of.get(e.id)??null),[b,C]=_.useState(!1),[S,x]=_.useState(!1),[y,w]=_.useState(new Set),[k,N]=_.useState(null),[D,j]=_.useState(""),[R,E]=_.useState(!1),[L,A]=_.useState(""),[O,z]=_.useState(!1),I=_.useCallback(Le=>{Of.set(e.id,Le),v(Le),w(et=>{const wt=new Set(Le.files.map(de=>de.path)),kt=new Set;return et.forEach(de=>wt.has(de)&&kt.add(de)),kt}),N(et=>et&&!Le.files.some(wt=>wt.path===et)?null:et)},[e.id]),F=_.useCallback(async()=>{const Le=Of.has(e.id);Le||C(!0),m(null);try{I(await ry(e.id))}catch(et){m(et instanceof Error?et.message:"Failed to load SVN status")}finally{Le||C(!1)}},[e.id,I]);_.useEffect(()=>{F()},[F,s]);const H=_.useCallback(async()=>{x(!0),m(null),c(null);try{const Le=await ry(e.id,!0);I(Le),c(Le.behind>0?i("svn.behindCount").replace("{n}",String(Le.behind)):i("svn.upToDate"))}catch(Le){m(Le instanceof Error?Le.message:"Failed to contact server")}finally{x(!1)}},[e.id,I,i]);_.useEffect(()=>{if(!k){j("");return}let Le=!1;return E(!0),Q6(e.id,k).then(et=>{Le||j(et.diff)}).catch(et=>{Le||m(et instanceof Error?et.message:"Diff failed")}).finally(()=>{Le||E(!1)}),()=>{Le=!0}},[e.id,k]);const U=Le=>{w(et=>{const wt=new Set(et);return wt.has(Le)?wt.delete(Le):wt.add(Le),wt})},q=(Le,et)=>{w(wt=>{const kt=new Set(wt);return Le.forEach(de=>{et?kt.add(de):kt.delete(de)}),kt})},X=async(Le,et)=>{z(!0),m(null),c(null);try{await Le(),et&&c(et),await F()}catch(wt){m(wt instanceof Error?wt.message:"Action failed")}finally{z(!1)}},B=Le=>X(()=>t8(e.id,Le)),P=Le=>X(()=>n8(e.id,Le)),$=Le=>X(()=>s8(e.id,Le)),Y=(Le,et)=>X(()=>r8(e.id,Le,et)),W=(Le,et)=>X(()=>i8(e.id,Le,et)),[Z,he]=_.useState(null),re=Le=>{Le.conflicts.length>0?he(Le.conflicts):c(Le.revision?i("svn.updateSuccess").replace("{rev}",Le.revision):i("svn.update"))},J=()=>X(async()=>{re(await iy(e.id))}),[V,pe]=_.useState(!1),[oe,ge]=_.useState(""),le=()=>{const Le=oe.trim();Le&&(pe(!1),X(async()=>{re(await iy(e.id,Le)),ge("")}))},Oe=()=>X(()=>o8(e.id),i("svn.cleanupSuccess")),[He,Te]=_.useState(null),[ye,ke]=_.useState(""),Ke=()=>{const Le=ye.trim();if(!Le||!He)return;const et=He;Te(null),ke(""),W(Le,et)},$e=()=>{if(!L.trim()){m(i("svn.commitMessagePlaceholder"));return}const Le=y.size>0?Array.from(y):void 0;X(async()=>{const et=await a8(e.id,L.trim(),Le);A(""),et.revision&&c(i("svn.commitSuccess").replace("{rev}",et.revision))})},[be,De]=_.useState([]),[Fe,qe]=_.useState(!1),[Qe,nt]=_.useState(!1),[xe,ie]=_.useState(null),[we,Q]=_.useState([]),[K,ne]=_.useState(!1),[ee,se]=_.useState(null),[ce,fe]=_.useState(""),[ue,je]=_.useState(!1),Ue=_.useCallback(async(Le=0)=>{qe(!0),m(null);try{const et=await Y6(e.id,Le,50);De(wt=>Le===0?et.commits:[...wt,...et.commits]),nt(et.hasMore)}catch(et){m(et instanceof Error?et.message:"Log failed")}finally{qe(!1)}},[e.id]),ut=_.useCallback(async Le=>{ie(Le),se(null),fe(""),ne(!0);try{const et=await X6(e.id,Le);Q(et.files)}catch(et){m(et instanceof Error?et.message:"Failed to load revision files")}finally{ne(!1)}},[e.id]);_.useEffect(()=>{var wt;if(!xe||!ee){fe("");return}let Le=!1;je(!0);const et=(wt=we.find(kt=>kt.path===ee))==null?void 0:wt.status;return J6(e.id,xe,ee,et).then(kt=>{Le||fe(kt.diff)}).catch(kt=>{Le||m(kt instanceof Error?kt.message:"Diff failed")}).finally(()=>{Le||je(!1)}),()=>{Le=!0}},[e.id,xe,ee,we]);const[Pe,Ve]=_.useState(null),[Ne,it]=_.useState(null),lt=(Le,et)=>{Le.preventDefault(),Le.stopPropagation(),Ve({x:Le.clientX,y:Le.clientY,file:et})},xt=_.useMemo(()=>Array.from(new Set(((u==null?void 0:u.files)??[]).map(Le=>Le.changelist).filter(Le=>!!Le))).sort(),[u]),ft=_.useMemo(()=>{if(!u)return null;const Le=[];return u.branch&&Le.push(u.branch),u.revision&&Le.push(`r${u.revision}`),Le.join(" · ")},[u]),rt=O||b||S;return _.useEffect(()=>{Z&&u&&!u.files.some(Le=>Le.working_dir==="C")&&he(null)},[u,Z]),t.jsxs("div",{className:"animate-fade-in flex flex-col",style:{height:"calc(100vh - 260px)",minHeight:"400px"},children:[d===!1&&t.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")}),Z&&Z.length>0&&t.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:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"font-semibold",children:i("svn.updateConflicts").replace("{n}",String(Z.length))}),t.jsxs("div",{className:"mt-0.5 truncate",title:Z.join(", "),children:[Z.slice(0,5).join(", "),Z.length>5?` … (+${Z.length-5})`:""]})]}),t.jsx("button",{onClick:()=>he(null),className:"shrink-0 hover:opacity-70",children:"×"})]}),t.jsxs("div",{className:"flex flex-1 min-h-0 gap-2",children:[t.jsxs("div",{className:"card w-52 shrink-0 flex flex-col overflow-y-auto",children:[t.jsxs("div",{className:"px-3 py-3 border-b border-warm-100",children:[t.jsx("div",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:"SVN"}),ft&&t.jsx("div",{className:"mt-1 text-2xs text-warm-400 truncate",title:(u==null?void 0:u.tracking)??void 0,children:ft})]}),t.jsx(ay,{label:i("svn.viewsHeader")}),t.jsx(Aa,{label:i("svn.checkForModifications"),active:a==="modifications",onClick:()=>h("modifications")}),t.jsx(Aa,{label:i("svn.showLog"),remote:!0,active:a==="log",onClick:()=>h("log")}),t.jsx(ay,{label:i("svn.actionsHeader")}),t.jsx(Aa,{label:i("svn.update"),remote:!0,disabled:rt,onClick:J}),t.jsx(Aa,{label:i("svn.updateToRevision"),remote:!0,disabled:rt,onClick:()=>pe(!0)}),t.jsx(Aa,{label:i("svn.cleanup"),disabled:rt,onClick:Oe}),t.jsx(Aa,{label:i("svn.properties"),onClick:()=>it({file:null})}),t.jsx("div",{className:"flex-1"})]}),t.jsx("div",{className:"card flex-1 overflow-hidden flex flex-col min-w-0 min-h-0",children:a==="modifications"?t.jsx(f8,{statusFiles:(u==null?void 0:u.files)??[],statusLoading:b,remoteChecking:S,onRefresh:F,onCheckRepository:H,selectedFiles:y,onToggle:U,onSelectMany:q,activeFile:k,onActivate:N,onContextMenu:lt,onChangelist:W,onResolve:(Le,et)=>Y([Le],et),workingDiff:D,workingDiffLoading:R,commitMessage:L,onCommitMessageChange:A,onCommit:$e,busy:rt,actionFlash:o,error:f}):t.jsx(m8,{loaded:be.length>0,entries:be,loading:Fe,hasMore:Qe,onLoad:()=>Ue(0),onLoadMore:()=>Ue(be.length),selectedRev:xe,onSelectRev:ut,revFiles:we,revFilesLoading:K,selectedFile:ee,onSelectFile:se,revDiff:ce,revDiffLoading:ue,error:f})})]}),t.jsx($n,{open:V,onClose:()=>pe(!1),size:"sm",children:t.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[t.jsxs("div",{className:"px-4 py-3 border-b border-warm-100 flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-semibold text-warm-700",children:i("svn.updateToRevision")}),t.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")})]}),t.jsxs("div",{className:"p-4 space-y-3",children:[t.jsx("input",{autoFocus:!0,value:oe,onChange:Le=>ge(Le.target.value),onKeyDown:Le=>{Le.key==="Enter"&&le()},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"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{className:"flex-1 px-3 py-2 text-sm rounded border border-warm-200 hover:bg-warm-50",onClick:()=>pe(!1),children:i("svn.cancel")}),t.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:!oe.trim()||rt,onClick:le,children:i("svn.update")})]})]})]})}),t.jsx($n,{open:He!==null,onClose:()=>Te(null),size:"sm",children:t.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-80 max-w-[90vw]",children:[t.jsx("div",{className:"px-4 py-3 border-b border-warm-100",children:t.jsx("span",{className:"text-sm font-semibold text-warm-700",children:i("svn.newChangelist")})}),t.jsxs("div",{className:"p-4 space-y-3",children:[t.jsx("input",{autoFocus:!0,value:ye,onChange:Le=>ke(Le.target.value),onKeyDown:Le=>{Le.key==="Enter"&&Ke()},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"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{className:"flex-1 px-3 py-2 text-sm rounded border border-warm-200 hover:bg-warm-50",onClick:()=>Te(null),children:i("svn.cancel")}),t.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:!ye.trim()||rt,onClick:Ke,children:i("svn.moveToChangelist")})]})]})]})}),Pe&&t.jsx(p8,{x:Pe.x,y:Pe.y,file:Pe.file,allFiles:(u==null?void 0:u.files)??[],selected:y,onClose:()=>Ve(null),onAdd:B,onRevert:P,onDelete:$,onResolve:Y,changelists:xt,onChangelist:W,onNewChangelist:Le=>Te(Le),onViewDiff:Le=>{N(Le),Ve(null)},onProperties:Le=>{it({file:Le}),Ve(null)}}),Ne&&t.jsx(g8,{projectId:e.id,file:Ne.file,onClose:()=>it(null)})]})}function ay({label:e}){return t.jsx("div",{className:"px-3 pt-3 pb-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:e})}function Aa({label:e,active:s,remote:i,disabled:a,onClick:h}){const{t:f}=st();return t.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:[t.jsx("span",{className:"truncate flex-1",children:e}),i&&t.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 u8(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 j_(s),N_(s),s}function j_(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(j_)}function N_(e){e.dirs.sort((s,i)=>s.name.localeCompare(i.name)),e.files.sort((s,i)=>s.path.localeCompare(i.path)),e.dirs.forEach(N_)}function E_(e){let s=e.dirs.length,i=e.files.length;for(const a of e.dirs){const h=E_(a);s+=h.dirs,i+=h.files}return{dirs:s,files:i}}function d8({onResolve:e,onOpen:s}){const{t:i}=st(),a=_.useRef(null),[h,f]=_.useState(null);_.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 v;c.stopPropagation(),s==null||s();const d=(v=a.current)==null?void 0:v.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 t.jsxs(t.Fragment,{children:[t.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&&rn.createPortal(t.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:[t.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")}),t.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")}),t.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")}),t.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 Cm({file:e,indent:s,showDir:i,shared:a}){const{t:h}=st(),f=vr(e),m=a.activeFile===e.path;return t.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:[t.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"}),t.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${l8(f)}`,children:f}),t.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("/")&&t.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:e.path.substring(0,e.path.lastIndexOf("/"))})]}),f==="C"&&t.jsx(d8,{onResolve:o=>a.onResolve(e.path,o),onOpen:()=>a.onActivate(e.path)}),t.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 T_({node:e,depth:s,collapsed:i,onToggleCollapse:a,fileProps:h}){const{t:f}=st(),m=i.has(e.path),o=E_(e),c=o.dirs>0?f("svn.dirFileCount").replace("{d}",String(o.dirs)).replace("{f}",String(o.files)):f("svn.fileCount").replace("{f}",String(o.files));return t.jsxs(t.Fragment,{children:[t.jsxs("div",{onClick:()=>a(e.path),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:[m?t.jsx(Ts,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}):t.jsx(wl,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}),t.jsx(L5,{className:"w-3.5 h-3.5 shrink-0 text-amber-500"}),t.jsx("span",{className:"truncate text-warm-700 font-medium",title:e.path,children:e.name}),t.jsx("span",{className:"text-warm-400 text-2xs ml-1 shrink-0",children:c})]}),!m&&t.jsxs(t.Fragment,{children:[e.dirs.map(d=>t.jsx(T_,{node:d,depth:s+1,collapsed:i,onToggleCollapse:a,fileProps:h},d.path)),e.files.map(d=>t.jsx(Cm,{file:d,indent:s+1,shared:h},d.path))]})]})}function h8(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 f8(e){const{t:s}=st(),[i,a]=_.useState(()=>{try{return localStorage.getItem("svn.groupByDir")!=="false"}catch{return!0}}),[h,f]=_.useState(new Set),[m,o]=_.useState(null),c=_.useMemo(()=>h8(e.statusFiles,s),[e.statusFiles,s]),d=()=>a(C=>{const S=!C;try{localStorage.setItem("svn.groupByDir",String(S))}catch{}return S}),p=C=>f(S=>{const x=new Set(S);return x.has(C)?x.delete(C):x.add(C),x}),u={selectedFiles:e.selectedFiles,activeFile:e.activeFile,onActivate:e.onActivate,onToggle:e.onToggle,onContextMenu:e.onContextMenu,onDragStart:(C,S)=>{const x=e.selectedFiles.size>0&&e.selectedFiles.has(S.path)?e.statusFiles.filter(y=>e.selectedFiles.has(y.path)).map(y=>y.path):[S.path];C.dataTransfer.setData("text/plain",JSON.stringify(x)),C.dataTransfer.effectAllowed="move"},onResolve:e.onResolve},v=(C,S)=>{if(C.preventDefault(),o(null),S.key==="unversioned"||S.key==="missing")return;let x;try{x=JSON.parse(C.dataTransfer.getData("text/plain"))}catch{return}const y=x.filter(w=>{const k=e.statusFiles.find(N=>N.path===w);return k&&vr(k)!=="?"});y.length&&e.onChangelist(S.key.startsWith("cl:")?S.label:null,y)},b=C=>{(C.metaKey||C.ctrlKey)&&C.key==="Enter"&&(C.preventDefault(),e.onCommit())};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center gap-2 shrink-0 flex-wrap",children:[t.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")}),t.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"),t.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&&t.jsx("span",{className:"text-2xs text-status-success ml-1",children:e.actionFlash}),e.error&&t.jsx("span",{className:"text-2xs text-status-error ml-1",children:e.error})]}),t.jsxs("div",{className:"flex-1 grid grid-cols-2 min-h-0",children:[t.jsxs("div",{className:"border-r border-warm-100 flex flex-col min-h-0",children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[t.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:s("svn.changed")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:d,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?t.jsx(gu,{className:"w-3.5 h-3.5"}):t.jsx(E5,{className:"w-3.5 h-3.5"})}),t.jsx("span",{className:"text-2xs text-warm-400",children:e.statusFiles.length})]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:e.statusLoading?t.jsx("div",{className:"p-6 text-center text-xs text-warm-400",children:s("git.loadingFiles")}):e.statusFiles.length===0?t.jsx("div",{className:"p-6 text-center text-xs text-warm-400",children:s("svn.noChanges")}):c.map(C=>{const S=`§${C.key}`,x=h.has(S),y=C.files.reduce((j,R)=>j+(e.selectedFiles.has(R.path)?1:0),0),w=y===C.files.length,k=i?u8(C.files):null,N=C.key!=="unversioned"&&C.key!=="missing",D=m===C.key;return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>p(S),onDragOver:N?j=>{j.preventDefault(),j.dataTransfer.dropEffect="move",m!==C.key&&o(C.key)}:void 0,onDragLeave:N?()=>o(j=>j===C.key?null:j):void 0,onDrop:N?j=>v(j,C):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 ${D?"bg-accent/20 ring-1 ring-inset ring-accent":"bg-warm-100 hover:bg-warm-200/60"}`,children:[x?t.jsx(Ts,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}):t.jsx(wl,{className:"w-3.5 h-3.5 shrink-0 text-warm-400"}),t.jsx("input",{type:"checkbox",checked:w,ref:j=>{j&&(j.indeterminate=y>0&&!w)},onChange:j=>{j.stopPropagation(),e.onSelectMany(C.files.map(R=>R.path),!w)},onClick:j=>j.stopPropagation(),className:"shrink-0"}),t.jsx("span",{className:"truncate text-warm-800 font-bold",children:C.label}),t.jsx("span",{className:"text-warm-400 text-2xs ml-1 shrink-0",children:C.files.length})]}),!x&&(k?t.jsxs(t.Fragment,{children:[k.dirs.map(j=>t.jsx(T_,{node:j,depth:1,collapsed:h,onToggleCollapse:p,fileProps:u},j.path)),k.files.map(j=>t.jsx(Cm,{file:j,indent:1,shared:u},j.path))]}):C.files.map(j=>t.jsx(Cm,{file:j,indent:1,showDir:!0,shared:u},j.path)))]},C.key)})}),t.jsxs("div",{className:"border-t border-warm-100 p-2 shrink-0",children:[t.jsx("textarea",{value:e.commitMessage,onChange:C=>e.onCommitMessageChange(C.target.value),onKeyDown:b,placeholder:s("svn.commitMessagePlaceholder"),className:"w-full text-xs p-2 border border-warm-200 rounded resize-y min-h-[60px] focus:border-accent focus:ring-1 focus:ring-accent/30 outline-none",rows:3}),t.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")})]})]}),t.jsx("div",{className:"min-w-0",children:t.jsx(Ku,{diff:e.workingDiff,loading:e.workingDiffLoading,selectedFile:e.activeFile})})]})]})}function m8(e){const{t:s}=st();return e.loaded?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center gap-2 shrink-0",children:[t.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&&t.jsx("span",{className:"text-2xs text-status-error ml-1",children:e.error})]}),t.jsxs("div",{className:"flex-1 grid grid-cols-[1fr_1fr] min-h-0",children:[t.jsxs("div",{className:"border-r border-warm-100 flex flex-col min-h-0",children:[t.jsx("div",{className:"px-3 py-2 border-b border-warm-100 shrink-0",children:t.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:s("svn.history")})}),t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.entries.map(i=>t.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:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"font-mono text-2xs text-warm-400 shrink-0",children:["r",i.hash]}),t.jsx("span",{className:"truncate flex-1 text-warm-700",title:i.message,children:i.message.split(`
652
652
  `)[0]})]}),t.jsxs("div",{className:"mt-0.5 text-2xs text-warm-400 truncate",children:[i.author,i.date&&t.jsxs("span",{children:[" · ",new Date(i.date).toLocaleString()]})]})]},i.hash)),e.hasMore&&!e.loading&&t.jsxs("button",{onClick:e.onLoadMore,className:"w-full py-2 text-2xs text-warm-500 hover:bg-warm-50",children:["+ ",s("svn.loadMore")]})]})]}),t.jsxs("div",{className:"grid grid-rows-[1fr_2fr] min-h-0",children:[t.jsx("div",{className:"border-b border-warm-100 min-h-0",children:t.jsx(bp,{files:e.revFiles,loading:e.revFilesLoading,selectedFile:e.selectedFile,onFileClick:e.onSelectFile,commitHash:e.selectedRev??void 0})}),t.jsx("div",{className:"min-h-0",children:t.jsx(Ku,{diff:e.revDiff,loading:e.revDiffLoading,selectedFile:e.selectedFile})})]})]})]}):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-6 text-center",children:[t.jsx("p",{className:"text-xs text-warm-400 max-w-xs",children:s("svn.logEmptyHint")}),t.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"),t.jsx("span",{className:"text-[9px] uppercase tracking-wide px-1 rounded bg-white/20",children:s("svn.remoteBadge")})]}),e.error&&t.jsx("span",{className:"text-2xs text-status-error",children:e.error})]})}function p8(e){const{t:s}=st(),i=_.useRef(null),[a,h]=_.useState({x:e.x,y:e.y}),f=_.useMemo(()=>e.selected.size>0&&e.selected.has(e.file.path)?e.allFiles.filter(S=>e.selected.has(S.path)):[e.file],[e.selected,e.allFiles,e.file]),m=f.filter(S=>vr(S)==="?").map(S=>S.path),o=f.filter(S=>vr(S)!=="?").map(S=>S.path),c=f.filter(S=>!["?","D"].includes(vr(S))).map(S=>S.path),d=f.filter(S=>vr(S)==="C").map(S=>S.path),p=f.filter(S=>vr(S)!=="?").map(S=>S.path),u=f.filter(S=>S.changelist).map(S=>S.path);_.useEffect(()=>{const S=y=>{i.current&&!i.current.contains(y.target)&&e.onClose()},x=()=>e.onClose();return document.addEventListener("mousedown",S),document.addEventListener("scroll",x,!0),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("scroll",x,!0)}},[e]),_.useEffect(()=>{if(!i.current)return;const S=i.current.getBoundingClientRect();let{x,y}={x:e.x,y:e.y};x+S.width>window.innerWidth&&(x=window.innerWidth-S.width-8),y+S.height>window.innerHeight&&(y=window.innerHeight-S.height-8),h({x,y})},[e.x,e.y]);const v=f.length,b=v>1?` (${v})`:"",C=({label:S,onClick:x,danger:y})=>t.jsx("button",{className:`w-full text-left px-3 py-1.5 text-xs hover:bg-theme-hover transition-colors ${y?"text-status-error":"text-theme-text"}`,onClick:()=>{x(),e.onClose()},children:S});return rn.createPortal(t.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:[t.jsx(C,{label:s("svn.viewDiff"),onClick:()=>e.onViewDiff(e.file.path)}),vr(e.file)!=="?"&&t.jsx(C,{label:s("svn.properties"),onClick:()=>e.onProperties(e.file.path)}),m.length>0&&t.jsx(C,{label:`${s("svn.add")}${b}`,onClick:()=>e.onAdd(m)}),o.length>0&&t.jsx(C,{label:`${s("svn.revert")}${b}`,onClick:()=>e.onRevert(o)}),c.length>0&&t.jsx(C,{label:`${s("svn.delete")}${b}`,danger:!0,onClick:()=>e.onDelete(c)}),d.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),t.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:s("svn.resolve")}),t.jsx(C,{label:s("svn.resolveWorking"),onClick:()=>e.onResolve(d,"working")}),t.jsx(C,{label:s("svn.resolveMine"),onClick:()=>e.onResolve(d,"mine-full")}),t.jsx(C,{label:s("svn.resolveTheirs"),onClick:()=>e.onResolve(d,"theirs-full")}),t.jsx(C,{label:s("svn.resolveBase"),onClick:()=>e.onResolve(d,"base")})]}),p.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border-t border-warm-100 dark:border-warm-700 my-1"}),t.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-warm-400 uppercase tracking-wider",children:s("svn.moveToChangelist")}),e.changelists.map(S=>t.jsx(C,{label:`${S}${b}`,onClick:()=>e.onChangelist(S,p)},S)),t.jsx(C,{label:s("svn.newChangelist"),onClick:()=>e.onNewChangelist(p)}),u.length>0&&t.jsx(C,{label:`${s("svn.removeFromChangelist")}${b}`,onClick:()=>e.onChangelist(null,u)})]})]}),document.body)}function g8({projectId:e,file:s,onClose:i}){const{t:a}=st(),[h,f]=_.useState(null),[m,o]=_.useState(null),[c,d]=_.useState(null),[p,u]=_.useState(""),[v,b]=_.useState(!1),[C,S]=_.useState(0);_.useEffect(()=>{let w=!1;return f(null),o(null),Z6(e,s??void 0).then(k=>{w||f(k.properties)}).catch(k=>{w||o(k instanceof Error?k.message:"Failed to load properties")}),()=>{w=!0}},[e,s,C]);const x=async w=>{b(!0),o(null);try{await e8(e,w,p,s??void 0),d(null),S(k=>k+1)}catch(k){o(k instanceof Error?k.message:"Failed to save property")}finally{b(!1)}},y=s??a("svn.workingCopyRoot");return t.jsx($n,{open:!0,onClose:i,size:"2xl",children:t.jsxs("div",{className:"bg-theme-card rounded-lg shadow-xl w-full max-h-[80vh] flex flex-col",children:[t.jsxs("div",{className:"px-4 py-3 border-b border-warm-100 flex items-center justify-between shrink-0",children:[t.jsx("span",{className:"text-sm font-semibold text-warm-700 truncate",title:y,children:a("svn.propertiesOf").replace("{target}",y)}),t.jsx("button",{onClick:i,className:"text-warm-400 hover:text-warm-600 shrink-0 ml-2",children:"✕"})]}),t.jsxs("div",{className:"p-4 overflow-y-auto",children:[m&&t.jsx("p",{className:"text-status-error text-xs mb-2 whitespace-pre-wrap break-all",children:m}),h===null?!m&&t.jsx("p",{className:"text-warm-400 text-xs",children:a("git.loadingFiles")}):h.length===0?t.jsx("p",{className:"text-warm-400 text-xs",children:a("svn.noProperties")}):t.jsx("div",{className:"space-y-3",children:h.map(w=>t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("div",{className:"text-xs font-mono font-semibold text-accent break-all",children:w.name}),c!==w.name&&t.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?t.jsxs(t.Fragment,{children:[t.jsx("textarea",{value:p,onChange:k=>u(k.target.value),rows:Math.min(12,Math.max(3,p.split(`
@@ -662,7 +662,7 @@ WARNING: This link could potentially be dangerous`)){const y=window.open();if(y)
662
662
  `)?`\x1B[200~${e}\x1B[201~`:e}function L8(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1024))} KB`}function D8({sessionId:e,isRunning:s,subscribed:i,onFitted:a,sendMessage:h,subscribeBinary:f,onEvent:m,height:o="100%",fontSize:c=Xm,theme:d,inputBlocked:p=!1,autoFocusOnMount:u=!1,onRequestRefresh:v,disableImagePaste:b=!1,onCycleTab:C}){const S=_.useRef(d);S.current=d;const x=_.useRef(p);x.current=p;const y=_.useRef(b);y.current=b;const w=_.useRef(C);w.current=C;const k=_.useRef(v);k.current=v;const N=_.useRef(null),D=_.useRef(null),j=_.useRef(null),R=_.useRef(null),E=_.useRef({cols:0,rows:0}),L=_.useRef(null),A=_.useRef(null),O=_.useRef(!1),z=_.useRef(a);z.current=a;const I=_.useRef(null),[F,H]=_.useState(!0),[U,q]=_.useState(""),X=_.useRef(q);X.current=q;const[B,P]=_.useState(null),$=_.useRef(0),Y=(oe,ge,le)=>{const Oe=++$.current,He=Date.now();P({dataUrl:oe,bytes:ge});const Te=()=>{const ye=Math.max(0,600-(Date.now()-He));setTimeout(()=>{$.current===Oe&&P(null)},ye)};le.then(Te,Te)},W=_.useRef(Y);W.current=Y;const{warning:Z}=Vi(),he=_.useRef(Z);he.current=Z;const[re,J]=_.useState(null),V=_.useRef(()=>{});_.useEffect(()=>{if(!re)return;const oe=()=>J(null),ge=le=>{le.key==="Escape"&&oe()};return window.addEventListener("keydown",ge,!0),window.addEventListener("resize",oe),window.addEventListener("scroll",oe,!0),()=>{window.removeEventListener("keydown",ge,!0),window.removeEventListener("resize",oe),window.removeEventListener("scroll",oe,!0)}},[re]),_.useEffect(()=>{var fe;const oe=N.current;if(!oe)return;const ge=ue=>{const je=ue.type;x.current&&je==="session:terminal-input"||h(ue)},le=new C8.Terminal({fontFamily:Rt,fontSize:c,lineHeight:1,cursorBlink:s,convertEol:!1,scrollback:5e3,theme:S.current??Vc,minimumContrastRatio:my(S.current??Vc),allowProposedApi:!0,macOptionIsMeta:!0}),Oe=/Mac|iPhone|iPad|iPod/.test(navigator.platform);let He=0;const Te=async()=>{var je;if(x.current){console.debug("[paste] inputBlocked → ignored");return}if(!window.isSecureContext)return;if(He=Date.now(),!y.current)try{const Ue=await navigator.clipboard.read();for(const ut of Ue){const Pe=ut.types.find(Ve=>Ve.startsWith("image/"));if(Pe){const Ve=await ut.getType(Pe),Ne=new FileReader;Ne.onload=()=>{const it=Ne.result;console.debug("[paste] image via clipboard.read(), bytes=",Ve.size);const lt=d1(e,it);lt.catch(xt=>console.warn("[paste] pasteImage failed:",xt)),W.current(it,Ve.size,lt)},Ne.readAsDataURL(Ve);return}}}catch(Ue){console.debug("[paste] clipboard.read() rejected, falling through:",Ue)}let ue=null;try{ue=await navigator.clipboard.readText()}catch(Ue){console.warn("[paste] clipboard.readText() failed:",Ue)}if(ue){const Ue=ue.includes(`
663
663
  `);console.debug("[paste] sending text, len=",ue.length,"multiline=",Ue),ge({type:"session:terminal-input",sessionId:e,input:A_(ue)});return}try{const Ue=await e4(e);if(Ue.path){console.debug("[paste] empty browser clipboard, using OS file path:",Ue.path),ge({type:"session:terminal-input",sessionId:e,input:Ue.path});return}}catch(Ue){console.debug("[paste] getClipboardImagePath failed:",Ue)}console.warn("[paste] no content available (text empty, no image, no file path)"),(je=he.current)==null||je.call(he,"붙여넣을 내용을 클립보드에서 읽지 못했습니다. 우클릭 → 붙여넣기를 시도해 보세요.")};le.attachCustomKeyEventHandler(ue=>{var Ne;if(ue.type!=="keydown")return!0;const je=Oe?ue.metaKey:ue.ctrlKey,Ue=Oe?ue.ctrlKey:ue.metaKey,ut=je&&!Ue&&!ue.altKey&&!ue.shiftKey,Pe=je&&!Ue&&!ue.altKey&&ue.shiftKey,Ve=ue.key.toLowerCase();if(Ve==="tab"&&(ut||Pe)&&w.current)return ue.preventDefault(),w.current(Pe?"prev":"next"),!1;if(Ve==="t"&&ut||Ve==="r"&&Pe||Ve==="f5"&&!ue.ctrlKey&&!ue.metaKey&&!ue.altKey&&!ue.shiftKey||Pe&&["a","p","o","m","x"].includes(Ve))return ue.preventDefault(),!1;if(ut&&Ve==="c"){const it=le.getSelection();return it?(ue.preventDefault(),(Ne=navigator.clipboard)==null||Ne.writeText(it).catch(()=>{}),le.clearSelection(),!1):!Oe}if(ut&&Ve==="v"||ue.altKey&&!ue.ctrlKey&&!ue.metaKey&&!ue.shiftKey&&Ve==="v")return ue.preventDefault(),Te(),!1;if((ue.ctrlKey||ue.metaKey)&&!ue.altKey){if(ue.key==="+"||ue.key==="=")return ue.preventDefault(),Wo(e,1),!1;if(ue.key==="-"||ue.key==="_")return ue.preventDefault(),Wo(e,-1),!1}return!0});const ye=new N8.FitAddon;le.loadAddon(ye),le.open(oe),D.current=le,j.current=ye;try{const ue=new dy.CanvasAddon;le.loadAddon(ue),R.current=ue}catch{R.current=null}le.attachCustomWheelEventHandler(ue=>!ue.ctrlKey&&!ue.metaKey?!0:(ue.preventDefault(),ue.__zoomHandled=!0,ue.deltaY!==0&&Wo(e,ue.deltaY<0?1:-1),!1));const ke=ue=>{if(ue.ctrlKey||ue.metaKey){if(ue.preventDefault(),ue.stopPropagation(),ue.deltaY===0||ue.__zoomHandled)return;Wo(e,ue.deltaY<0?1:-1);return}ue.stopPropagation()};oe.addEventListener("wheel",ke,{passive:!1});const Ke=window.electronAPI,$e=(fe=Ke==null?void 0:Ke.onTerminalZoom)==null?void 0:fe.call(Ke,ue=>{var Pe;const je=oe.matches(":hover"),Ue=document.querySelector("[data-term-container]:hover")!==null,ut=!!le.textarea&&document.activeElement===le.textarea;(Pe=Ke.imeLog)==null||Pe.call(Ke,{reason:"zoom:recv",dir:ue,hovered:je,anyTermHovered:Ue,focused:ut,path:window.location.pathname}),(je||!Ue&&ut)&&Wo(e,ue==="in"?1:-1)});V.current=()=>{Te()};const be=ue=>{ue.preventDefault(),J({x:ue.clientX,y:ue.clientY,hasSelection:le.hasSelection()})};oe.addEventListener("contextmenu",be);try{ye.fit()}catch{}if(u){const ue=document.activeElement;if(!(!!ue&&(ue.tagName==="INPUT"||ue.tagName==="TEXTAREA"||ue.tagName==="SELECT"||ue.isContentEditable))&&(ue===null||ue===document.body))try{le.focus()}catch{}}const De=()=>{const ue=le.cols,je=le.rows;ue===E.current.cols&&je===E.current.rows||(E.current={cols:ue,rows:je},h({type:"session:resize",sessionId:e,cols:ue,rows:je}))};I.current=De;const Fe=f(e,ue=>{try{le.write(ue)}catch{}}),qe=m(ue=>{ue.type==="session:replay-end"&&ue.sessionId===e&&H(!1)}),Qe=()=>Date.now()-He<300,nt=()=>y.current,xe=ue=>X.current(ue),ie=(ue,je,Ue)=>W.current(ue,je,Ue),we=R8()?I8({container:oe,term:le,sessionId:e,sendMessage:ge}):B8({container:oe,term:le,sessionId:e,sendMessage:ge,isPasteAlreadyHandled:Qe,isImagePasteDisabled:nt,onComposingChange:xe,onImagePasted:ie}),Q=100;let K=null,ne=0,ee=!1;const se={cols:le.cols,rows:le.rows},ce=new ResizeObserver(()=>{if(K!==null)return;const ue=Math.max(0,Q-(performance.now()-ne));K=setTimeout(()=>{K=null,requestAnimationFrame(()=>{var Ue;ne=performance.now();const je=oe.getBoundingClientRect();if(!(je.width===0||je.height===0)){try{ye.fit(),(le.cols!==se.cols||le.rows!==se.rows)&&(se.cols=le.cols,se.rows=le.rows,le.refresh(0,le.rows-1))}catch{}!ee&&le.cols>=20&&le.rows>=5&&(ee=!0,(Ue=z.current)==null||Ue.call(z,le.cols,le.rows)),L.current&&clearTimeout(L.current),L.current=setTimeout(De,150)}})},ue)});return ce.observe(oe),()=>{var ue;ce.disconnect(),K!==null&&clearTimeout(K),L.current&&clearTimeout(L.current),A.current&&clearTimeout(A.current),oe.removeEventListener("wheel",ke),$e==null||$e(),oe.removeEventListener("contextmenu",be),J(null),we(),Fe(),qe();try{h({type:"session:unsubscribe",sessionId:e})}catch{}(ue=R.current)==null||ue.dispose(),R.current=null,le.dispose(),D.current=null,j.current=null,I.current=null,O.current=!1}},[e]),_.useEffect(()=>{if(!i||O.current)return;O.current=!0;const oe=D.current;oe&&oe.cols>0&&oe.rows>0&&(E.current={cols:0,rows:0},h({type:"session:resize",sessionId:e,cols:oe.cols,rows:oe.rows})),h({type:"session:subscribe",sessionId:e})},[i,e,h]),_.useEffect(()=>{D.current&&(D.current.options.cursorBlink=s)},[s]),_.useEffect(()=>{const oe=D.current,ge=j.current;if(!oe||!ge||oe.options.fontSize===c)return;if(oe.options.fontSize=c,R.current){try{R.current.dispose()}catch{}R.current=null;try{const Oe=new dy.CanvasAddon;oe.loadAddon(Oe),R.current=Oe}catch{}}if(oe.buffer.active.type==="alternate"){A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{var Oe;(Oe=k.current)==null||Oe.call(k)},500);return}try{ge.fit(),oe.refresh(0,oe.rows-1)}catch{}oe.cols===E.current.cols&&oe.rows===E.current.rows||(A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{var Oe;(Oe=I.current)==null||Oe.call(I)},300))},[c,e]),_.useEffect(()=>{const oe=D.current;if(oe){oe.options.theme=d??Vc,oe.options.minimumContrastRatio=my(d??Vc);try{oe.refresh(0,oe.rows-1)}catch{}}},[d]);const pe=(d==null?void 0:d.background)??Ie.bg;return t.jsxs("div",{style:{position:"relative",background:pe,padding:12,height:o,width:"100%",boxSizing:"border-box",overflow:"hidden"},children:[F&&i&&t.jsx("div",{style:{position:"absolute",top:8,right:12,fontFamily:Rt,fontSize:11,color:Ie.dim,zIndex:1,pointerEvents:"none"},children:"loading history…"}),t.jsx("div",{ref:N,"data-term-container":!0,style:{height:"100%",width:"100%"}}),(U||B)&&t.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:[B&&t.jsxs("div",{style:{padding:4,background:"rgba(0,0,0,0.72)",border:`1px solid ${Ie.separator}`,borderRadius:4,maxWidth:"100%"},children:[t.jsx("img",{src:B.dataUrl,alt:"",style:{display:"block",maxWidth:220,maxHeight:140,borderRadius:2}}),t.jsxs("div",{style:{fontFamily:Rt,fontSize:11,color:Ie.dim,marginTop:3},children:["이미지 붙여넣음 · ",L8(B.bytes)]})]}),U&&t.jsx("div",{style:{maxWidth:"100%",padding:"3px 8px",background:"rgba(0,0,0,0.72)",border:`1px solid ${Ie.separator}`,borderRadius:4,fontFamily:Rt,fontSize:Math.max(12,c),color:Ie.bright,lineHeight:1.3,whiteSpace:"pre",overflow:"hidden",textOverflow:"ellipsis"},children:U})]}),re&&rn.createPortal((()=>{const le=Math.max(8,Math.min(re.x,window.innerWidth-184-8)),Oe=Math.max(8,Math.min(re.y,window.innerHeight-116-8)),He=()=>J(null),Te=()=>{var $e,be;const Ke=(($e=D.current)==null?void 0:$e.getSelection())??"";Ke&&((be=navigator.clipboard)==null||be.writeText(Ke).catch(()=>{})),He()},ye=()=>{V.current(),He()},ke=()=>{var Ke;(Ke=D.current)==null||Ke.selectAll(),He()};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"fixed",inset:0,zIndex:2147483646},onMouseDown:He,onContextMenu:Ke=>{Ke.preventDefault(),He()}}),t.jsxs("div",{role:"menu",style:{position:"fixed",left:le,top:Oe,zIndex:2147483647,minWidth:168,background:Ie.bg,border:`1px solid ${Ie.separator}`,borderRadius:6,padding:4,fontFamily:Rt,fontSize:13,boxShadow:"0 8px 24px rgba(0,0,0,0.5)"},children:[t.jsx("button",{type:"button",disabled:!re.hasSelection,onClick:Te,className:"w-full text-left px-3 py-1.5 rounded hover:bg-white/10 disabled:opacity-40 disabled:cursor-not-allowed",style:{color:Ie.bright},children:"복사"}),t.jsx("button",{type:"button",onClick:ye,className:"w-full text-left px-3 py-1.5 rounded hover:bg-white/10",style:{color:Ie.bright},children:"붙여넣기"}),t.jsx("button",{type:"button",onClick:ke,className:"w-full text-left px-3 py-1.5 rounded hover:bg-white/10",style:{color:Ie.bright},children:"전체 선택"})]})]})})(),document.body)]})}function R8(){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 uu=[12593,12594,12596,12599,12600,12601,12609,12610,12611,12613,12614,12615,12616,12617,12618,12619,12620,12621,12622],O_=[12623,12624,12625,12626,12627,12628,12629,12630,12631,12632,12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643],py=[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 z_(e){return e>=12593&&e<=12622}function P_(e){return e>=12623&&e<=12643}function M8(e){return z_(e)||P_(e)}function A8(e){return e>=44032&&e<=55203}function O8(){return{cho:-1,jung:-1,jong:0}}function yp(e){return e.cho<0&&e.jung<0&&e.jong===0}function br(e){return yp(e)?"":e.cho>=0&&e.jung>=0?String.fromCharCode(44032+(e.cho*21+e.jung)*28+e.jong):e.cho>=0?String.fromCharCode(uu[e.cho]):e.jung>=0?String.fromCharCode(O_[e.jung]):""}function gy(e){const s=br(e);return e.cho=-1,e.jung=-1,e.jong=0,s}function z8(e,s){if(P_(s)){const i=O_.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=py[e.jong],h=uu.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(z_(s)){const i=uu.indexOf(s),a=py.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(uu[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 P8(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 xy(e){return yp(e)?!1:(e.cho=-1,e.jung=-1,e.jong=0,!0)}function B8({container:e,term:s,sessionId:i,sendMessage:a,isPasteAlreadyHandled:h,isImagePasteDisabled:f,onComposingChange:m,onImagePasted:o}){let c=!1;const d=E=>{try{m==null||m(E)}catch{}};let p=null;const u=(E,L={})=>{var A,O;try{(O=(A=window.electronAPI)==null?void 0:A.imeLog)==null||O.call(A,{reason:E,path:window.location.pathname,...L})}catch{}},v=(E=!1)=>{try{const L=e.querySelector(".xterm-helper-textarea"),A=e.querySelector(".xterm-screen");if(!L||!A){E||u("pos:no-dom",{hasHelper:!!L,hasScreen:!!A});return}const O=s.cols,z=s.rows;if(O<=0||z<=0){E||u("pos:no-grid",{cols:O,rows:z});return}const I=A.getBoundingClientRect();if(I.width===0||I.height===0){E||u("pos:zero-screen",{w:I.width,h:I.height});return}const F=I.width/O,H=I.height/z,U=s.buffer.active,q=Math.min(U.cursorX,O-1),X=Math.max(0,Math.min(U.cursorY,z-1));L.style.left=`${q*F}px`,L.style.top=`${X*H}px`,L.style.width=`${Math.max(F,1)}px`,L.style.height=`${Math.max(H,1)}px`,E||u("pos:applied",{cursorX:q,cursorY:X,left:q*F,top:X*H})}catch{}};v();let b=0;const C=()=>{b||(b=requestAnimationFrame(()=>{b=0,v(!0)}))},S=s.onCursorMove(C),x=()=>{var E;c=!0,v(),d("");try{const L=document.activeElement,A=e.querySelector(".xterm-helper-textarea"),O=A==null?void 0:A.getBoundingClientRect();u("compositionstart",{activeTag:L==null?void 0:L.tagName,activeClass:L==null?void 0:L.className,activeIsHelper:!!L&&((E=L.classList)==null?void 0:E.contains("xterm-helper-textarea")),helperStyleLeft:A==null?void 0:A.style.left,helperStyleTop:A==null?void 0:A.style.top,helperRectLeft:O==null?void 0:O.left,helperRectTop:O==null?void 0:O.top,visibility:document.visibilityState,hasFocus:document.hasFocus(),cols:s.cols,rows:s.rows})}catch{}},y=E=>{d(E.data??""),u("compositionupdate",{data:E.data??""})},w=E=>{c=!1,d("");const L=E.data;u("compositionend",{data:L??"",sent:!!L}),L&&(p=L,a({type:"session:terminal-input",sessionId:i,input:L}))},k=E=>{var O,z;if(h()){E.preventDefault();return}const L=(O=E.clipboardData)==null?void 0:O.items;if(L&&!(f!=null&&f())){for(let I=0;I<L.length;I++)if(L[I].type.startsWith("image/")){E.preventDefault();const F=L[I].getAsFile();if(!F)return;const H=new FileReader;H.onload=()=>{const U=H.result;console.debug("[paste-fallback] image via paste event, bytes=",F.size);const q=d1(i,U,F.name);q.catch(X=>console.warn("[paste-fallback] pasteImage failed:",X)),o==null||o(U,F.size,q)},H.readAsDataURL(F);return}}const A=(z=E.clipboardData)==null?void 0:z.getData("text/plain");if(A){E.preventDefault();const I=A.includes(`
664
664
  `);console.debug("[paste-fallback] sending text, len=",A.length,"multiline=",I),a({type:"session:terminal-input",sessionId:i,input:A_(A)})}else console.debug("[paste-fallback] paste event had no usable text/image")};let N=0;const D=()=>{var L,A;if(N||c)return;const E=window.electronAPI;E!=null&&E.imeReset&&(u("focus-rescue"),(A=(L=document.activeElement)==null?void 0:L.blur)==null||A.call(L),E.imeReset(),N=requestAnimationFrame(()=>{N=requestAnimationFrame(()=>{N=0;try{s.focus()}catch{}})}))},j=E=>{var L,A;u("keydown",{key:E.key,composing:c,activeIsHelper:!!((A=(L=document.activeElement)==null?void 0:L.classList)!=null&&A.contains("xterm-helper-textarea")),hasFocus:document.hasFocus()}),document.hasFocus()||D()};e.addEventListener("keydown",j,!0),e.addEventListener("compositionstart",x,!0),e.addEventListener("compositionupdate",y,!0),e.addEventListener("compositionend",w,!0),e.addEventListener("paste",k,!0);const R=s.onData(E=>{if(!c){if(p!==null&&E===p){p=null;return}p=null,a({type:"session:terminal-input",sessionId:i,input:E})}});return()=>{R.dispose(),S.dispose(),b&&cancelAnimationFrame(b),N&&cancelAnimationFrame(N),e.removeEventListener("keydown",j,!0),e.removeEventListener("compositionstart",x,!0),e.removeEventListener("compositionupdate",y,!0),e.removeEventListener("compositionend",w,!0),e.removeEventListener("paste",k,!0),d("")}}function I8({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,E=s.rows;if(R<=0||E<=0)return;const L=j.clientWidth/R,A=j.clientHeight/E,O=s.buffer.active.cursorX,z=s.buffer.active.cursorY,I=j.getBoundingClientRect(),F=e.getBoundingClientRect();Object.assign(o.style,{inset:"auto",left:`${I.left-F.left+O*L}px`,top:`${I.top-F.top+z*A}px`,width:`${Math.max(L*30,240)}px`,height:`${Math.max(A,20)}px`,color:Ie.text})};c(),e.appendChild(o);let p=!1;const u=O8();let v=null;const b=()=>{v&&(clearTimeout(v),v=null)},C=j=>{j&&a({type:"session:terminal-input",sessionId:i,input:j})},S=()=>{const j=gy(u);j&&C(j)},x=()=>{const j=br(u);o.value=j,j?d():c()},y=()=>{b(),v=setTimeout(()=>{v=null,S(),o.value="",c()},600)},w=()=>{p=!0,b(),S(),d()},k=j=>{p=!1,j.data&&C(j.data),o.value="",c()};o.addEventListener("compositionstart",w),o.addEventListener("compositionend",k);const N=j=>{if(p)return;const R=j;switch(R.inputType){case"insertCompositionText":case"insertFromComposition":return;case"deleteContentBackward":b(),xy(u)?x():(C(""),o.value="",c());return;case"insertLineBreak":case"insertParagraph":b(),S(),C("\r"),o.value="",c();return;default:if(!R.data){x();return}b();let E="";for(const L of R.data){const A=L.codePointAt(0);M8(A)?E+=z8(u,A):A8(A)?E+=P8(u,A):(E+=gy(u),E+=L)}C(E),x(),yp(u)||y()}};o.addEventListener("input",N);const D=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(xy(u)){x();return}}else S();C(R),o.value="",c();return}if(j.ctrlKey&&!j.metaKey&&!j.altKey&&j.key.length===1){const E=j.key.toUpperCase().charCodeAt(0);E>=64&&E<=95&&(j.preventDefault(),b(),S(),C(String.fromCharCode(E-64)),o.value="",c())}};return o.addEventListener("keydown",D),()=>{b(),S(),o.remove(),h&&(h.style.display=f,h.tabIndex=m)}}const H8={presetId:M_},pl=new Map,Ba=new Map;function B_(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);pl.delete(s);const i=Ba.get(s);if(i){const h=jm(s);i.forEach(f=>f(h))}});function F8(e){return typeof e!="string"?!1:e==="custom"||e in En}function jm(e){const s=pl.get(e);if(s!==void 0)return s;let i=H8;try{const a=localStorage.getItem(B_(e));if(a!==null){const h=JSON.parse(a);h&&F8(h.presetId)&&(i={presetId:h.presetId,custom:h.custom&&typeof h.custom=="object"?h.custom:void 0})}}catch{}return pl.set(e,i),i}function $8(e,s){const i=pl.get(e);if(i&&i.presetId===s.presetId&&U8(i.custom,s.custom))return;pl.set(e,s);try{localStorage.setItem(B_(e),JSON.stringify(s))}catch{}const a=Ba.get(e);a&&a.forEach(h=>h(s))}function U8(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 W8(e){if(e.presetId!=="custom")return fy(e.presetId).theme;const s=fy(M_).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 I_(e){const[s,i]=_.useState(()=>jm(e));_.useEffect(()=>{i(jm(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=_.useCallback(f=>$8(e,f),[e]),h=_.useMemo(()=>W8(s),[s]);return[s,h,a]}function H_({session:e,visible:s,intent:i,intentNonce:a,onClose:h,sendMessage:f,subscribeBinary:m,onEvent:o,onCycleTab:c,remountKey:d=0}){const{t:p}=st(),u=e.status==="running"||i==="start"||i==="resume"?"pendingFit":"replay-only",[v,b]=_.useState(u),[C,S]=_.useState(null),[x,y]=_.useState(0),w=_.useCallback(()=>y(V=>V+1),[]),k=_.useRef(null),N=_.useRef(!1),D=_.useRef(a),[j,R]=_.useState(null),[E,L]=_.useState(null),[A,O]=_.useState(!1),[z,I]=_.useState(null),[F,H]=_.useState(null),U=_.useRef(e.status==="running");_.useEffect(()=>{e.status==="running"&&v!=="subscribed"&&v!=="starting"&&v!=="pendingFit"&&(U.current=!0,b("subscribed"))},[e.status,v]),_.useEffect(()=>{if(e.status==="running"||!U.current||v!=="subscribed"&&v!=="stopping")return;const V=setTimeout(()=>h(),300);return()=>clearTimeout(V)},[e.status,v,h]);const q=_.useCallback(async()=>{const V=k.current;if(V&&!N.current){N.current=!0,b("starting"),S(null),H(null);try{const pe=await Y3(e.id,V,i==="resume"?{continueSession:!0}:void 0);b("subscribed"),pe.pendingInitialPrompt?(R(pe.pendingInitialPromptLength??0),L(null),O(!1)):(R(null),L(null))}catch(pe){const oe=pe instanceof Error?pe.message:String(pe);S(oe),b("error")}finally{N.current=!1}}},[e.id,i]),X=_.useCallback(async()=>{if(A){O(!1);return}if(O(!0),E===null)try{const V=await X3(e.id);L(V.prompt??"")}catch(V){H(V instanceof Error?V.message:String(V))}},[A,E,e.id]),B=_.useCallback(async()=>{if(!z){I("send"),H(null);try{await J3(e.id),R(null),L(null),O(!1)}catch(V){H(V instanceof Error?V.message:String(V))}finally{I(null)}}},[z,e.id]),P=_.useCallback(async()=>{if(!z){I("skip"),H(null);try{await Q3(e.id),R(null),L(null),O(!1)}catch(V){H(V instanceof Error?V.message:String(V))}finally{I(null)}}},[z,e.id]);_.useEffect(()=>{if(a===D.current)return;D.current=a,(i==="start"||i==="resume")&&v==="replay-only"&&e.status!=="running"&&(k.current?q():b("pendingFit"))},[a,i,v,e.status,q]);const $=_.useCallback(()=>{k.current?q():b("pendingFit")},[q]),Y=_.useCallback((V,pe)=>{k.current={cols:V,rows:pe},v==="pendingFit"&&(e.status==="running"?(U.current=!0,b("subscribed")):q())},[v,q,e.status]),W=e.status==="running",Z=v==="subscribed",[he]=Zw(e.id),[,re]=I_(e.id),J=v==="starting"||v==="pendingFit"?t.jsxs("div",{style:{...Yc,pointerEvents:"none"},children:[t.jsx("span",{style:{color:Ie.dim,fontFamily:Rt,fontSize:12},children:p("session.starting")||"starting…"}),t.jsx("span",{style:{color:Ie.dim,fontFamily:Rt,fontSize:10,marginTop:6},children:p("session.starting.typeAhead")||"type-ahead is captured and replayed once ready"})]}):v==="stopping"?t.jsx("div",{style:{...Yc,pointerEvents:"none"},children:t.jsx("span",{style:{color:Ie.dim,fontFamily:Rt,fontSize:12},children:p("session.stopping")||"stopping…"})}):v==="replay-only"?t.jsx("div",{style:Yc,children:t.jsxs("button",{onClick:$,style:{display:"flex",alignItems:"center",gap:8,fontFamily:Rt,fontSize:14,color:Ie.bright,background:"transparent",border:`1px solid ${Ie.separator}`,padding:"10px 22px",borderRadius:6,cursor:"pointer"},children:[t.jsx(kr,{size:16})," ",p("session.startInWindow")||"Start"]})}):v==="error"?t.jsxs("div",{style:Yc,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:Ie.error,fontFamily:Rt,fontSize:12,marginBottom:8},children:[t.jsx(Cw,{size:14})," ",p("session.startFailed")||"failed to start"]}),C&&t.jsx("div",{style:{color:Ie.dim,fontFamily:Rt,fontSize:11,marginBottom:8,maxWidth:360,textAlign:"center",wordBreak:"break-word"},children:C}),t.jsx("button",{onClick:()=>{q()},style:{fontFamily:Rt,fontSize:12,color:Ie.bright,background:"transparent",border:`1px solid ${Ie.separator}`,padding:"4px 12px",borderRadius:4,cursor:"pointer"},children:p("common.retry")||"Retry"})]}):null;return t.jsxs("div",{style:{display:s?"block":"none",position:"absolute",inset:0,background:Ie.bg},children:[t.jsx(D8,{sessionId:e.id,isRunning:W,subscribed:Z,onFitted:Y,sendMessage:f,subscribeBinary:m,onEvent:o,fontSize:he,theme:re,inputBlocked:j!==null,autoFocusOnMount:s,onRequestRefresh:w,disableImagePaste:e.cli_tool==="raw-shell",onCycleTab:c},`${d}:${x}`),J,j!==null&&t.jsxs("div",{style:G8,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{"aria-hidden":!0,style:{color:Ie.info,fontSize:14},children:"📋"}),t.jsxs("span",{style:{flex:1},children:[p("session.initialPrompt.ready")||"Initial prompt ready",t.jsxs("span",{style:{color:Ie.dim,marginLeft:8},children:[j.toLocaleString()," chars"]}),t.jsx("div",{style:{color:Ie.warning,fontSize:10,marginTop:2},children:p("session.initialPrompt.blocked")||"Press Send or Skip before typing — keystrokes are ignored until then."})]}),t.jsxs("button",{onClick:X,style:Hf("neutral"),title:A?p("session.initialPrompt.hidePreview")||"Hide preview":p("session.initialPrompt.preview")||"Preview",children:[A?t.jsx(Kj,{size:11}):t.jsx(wl,{size:11}),A?p("session.initialPrompt.hidePreview")||"Hide":p("session.initialPrompt.preview")||"Preview"]}),t.jsxs("button",{onClick:B,disabled:z!==null,style:Hf("primary"),children:[z==="send"?t.jsx(Wi,{size:11,style:{animation:"spin 1s linear infinite"}}):t.jsx(RN,{size:11}),p("session.initialPrompt.send")||"Send"]}),t.jsx("button",{onClick:P,disabled:z!==null,style:Hf("danger"),children:p("session.initialPrompt.skip")||"Skip"})]}),F&&t.jsx("div",{style:{color:Ie.error,fontSize:10,marginTop:4},children:F}),A&&t.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:Ie.bright,whiteSpace:"pre-wrap",wordBreak:"break-word",border:`1px solid ${Ie.separator}`,borderRadius:4},children:E===null?p("session.initialPrompt.loading")||"loading…":E})]})]})}const G8={position:"absolute",top:0,left:0,right:0,background:"rgba(28,28,38,0.96)",borderBottom:`1px solid ${Ie.separator}`,borderLeft:`3px solid ${Ie.warning}`,padding:"8px 10px",color:Ie.bright,fontFamily:Rt,fontSize:11,zIndex:3,display:"flex",flexDirection:"column"};function Hf(e){const s={display:"inline-flex",alignItems:"center",gap:4,fontFamily:Rt,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer",border:`1px solid ${Ie.separator}`,background:"transparent"};return e==="primary"?{...s,color:Ie.bright,borderColor:Ie.info,background:`${Ie.info}22`}:e==="danger"?{...s,color:Ie.dim}:{...s,color:Ie.bright}}const Yc={position:"absolute",inset:0,background:"rgba(12,12,12,0.85)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:1e3},vy=340;function q8({sessionId:e}){var C,S,x,y,w,k;const[s,,i]=I_(e),[a,h]=_.useState(!1),[f,m]=_.useState(!1),[o,c]=_.useState({top:0,left:0}),d=_.useRef(null),p=_.useRef(null),u=_.useCallback(()=>{if(!d.current)return;const N=d.current.getBoundingClientRect(),D=window.innerWidth,j=window.innerHeight,R=p.current;let E=N.bottom+4,L=N.right-vy;if(R){const A=R.offsetHeight,O=R.offsetWidth;L=N.right-O,L<8&&(L=8),L+O>D-8&&(L=D-8-O),E+A>j-8&&(E=Math.max(8,N.top-A-4))}else L<8&&(L=8);c({top:E,left:L}),m(!0)},[]);_.useEffect(()=>{if(!a){m(!1);return}u();const N=requestAnimationFrame(u),D=R=>{var L,A;const E=R.target;(L=d.current)!=null&&L.contains(E)||(A=p.current)!=null&&A.contains(E)||h(!1)},j=R=>{R.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",D),document.addEventListener("keydown",j),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{cancelAnimationFrame(N),document.removeEventListener("mousedown",D),document.removeEventListener("keydown",j),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[a,u]);const v=N=>{if(N==="custom"){const D=s.custom??{background:En.default.theme.background,foreground:En.default.theme.foreground,cursor:En.default.theme.cursor,selectionBackground:En.default.theme.selectionBackground,accent:En.default.theme.brightBlue};i({presetId:"custom",custom:D})}else i({presetId:N,custom:s.custom}),h(!1)},b=N=>{const D={...s.custom??{},...N};i({presetId:"custom",custom:D})};return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:d,"data-no-drag":!0,onMouseDown:N=>N.stopPropagation(),onClick:()=>h(N=>!N),"aria-label":"terminal-theme",title:"Terminal theme (Ctrl+Shift+P)",style:{background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},children:t.jsx(gN,{size:13})}),a&&rn.createPortal(t.jsxs("div",{ref:p,className:"z-tooltip",style:{position:"fixed",top:o.top,left:o.left,width:vy,background:"#1e1e1e",border:`1px solid ${Ie.separator}`,borderRadius:6,padding:10,fontFamily:Rt,color:Ie.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:f?1:0,transition:"opacity 80ms"},onMouseDown:N=>N.stopPropagation(),children:[t.jsx("div",{style:{fontSize:10,color:Ie.dim,marginBottom:6,letterSpacing:.5},children:"DARK"}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:hy.filter(N=>!En[N].light).map(N=>t.jsx(by,{preset:En[N],selected:s.presetId===N,onClick:()=>v(N)},N))}),t.jsx("div",{style:{fontSize:10,color:Ie.dim,marginBottom:6,letterSpacing:.5},children:"LIGHT"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:[hy.filter(N=>En[N].light).map(N=>t.jsx(by,{preset:En[N],selected:s.presetId===N,onClick:()=>v(N)},N)),t.jsx(K8,{selected:s.presetId==="custom",accent:((C=s.custom)==null?void 0:C.accent)??En.default.theme.brightBlue??"#569cd6",onClick:()=>v("custom")})]}),s.presetId==="custom"&&t.jsxs("div",{style:{borderTop:`1px solid ${Ie.separator}`,paddingTop:8},children:[t.jsx("div",{style:{fontSize:10,color:Ie.dim,marginBottom:6,letterSpacing:.5},children:"CUSTOM COLORS"}),t.jsx(Yo,{label:"Background",value:((S=s.custom)==null?void 0:S.background)??En.default.theme.background??"#0c0c0c",onChange:N=>b({background:N})}),t.jsx(Yo,{label:"Foreground",value:((x=s.custom)==null?void 0:x.foreground)??En.default.theme.foreground??"#cccccc",onChange:N=>b({foreground:N})}),t.jsx(Yo,{label:"Cursor",value:((y=s.custom)==null?void 0:y.cursor)??En.default.theme.cursor??"#f2f2f2",onChange:N=>b({cursor:N})}),t.jsx(Yo,{label:"Selection",value:((w=s.custom)==null?void 0:w.selectionBackground)??En.default.theme.selectionBackground??"#264f78",onChange:N=>b({selectionBackground:N})}),t.jsx(Yo,{label:"Accent",value:((k=s.custom)==null?void 0:k.accent)??En.default.theme.brightBlue??"#569cd6",onChange:N=>b({accent:N})})]})]}),document.body)]})}function by({preset:e,selected:s,onClick:i}){return t.jsxs("button",{onClick:i,style:{position:"relative",background:e.theme.background,border:`1px solid ${s?e.accent:Ie.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:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:e.accent,flexShrink:0}}),t.jsx("span",{style:{fontWeight:600,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),s&&t.jsx(ai,{size:10,style:{marginLeft:"auto",flexShrink:0}})]}),t.jsxs("div",{style:{fontSize:9,opacity:.85,fontFamily:Rt},children:[t.jsx("span",{style:{color:e.theme.green},children:"$"})," ",t.jsx("span",{style:{color:e.theme.brightBlue},children:"ls"})]})]})}function K8({selected:e,accent:s,onClick:i}){return t.jsxs("button",{onClick:i,style:{position:"relative",background:"#0c0c0c",border:`1px dashed ${e?s:Ie.separator}`,outline:e?`1px solid ${s}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:Rt,fontSize:10,color:Ie.text,textAlign:"left",height:52,display:"flex",flexDirection:"column",justifyContent:"space-between",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:s,flexShrink:0}}),t.jsx("span",{style:{fontWeight:600,fontSize:11},children:"Custom"}),e&&t.jsx(ai,{size:10,style:{marginLeft:"auto",flexShrink:0}})]}),t.jsx("div",{style:{fontSize:9,opacity:.7},children:"edit colors"})]})}function Yo({label:e,value:s,onChange:i}){const[a,h]=_.useState(s);_.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(yy(o))};return t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",fontSize:11,color:Ie.text},children:[t.jsx("span",{style:{flex:1},children:e}),t.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:Ie.text,background:"transparent",border:`1px solid ${Ie.separator}`,borderRadius:3}}),t.jsx("input",{type:"color",value:yy(s),onChange:m=>i(m.target.value),style:{width:28,height:22,padding:0,border:`1px solid ${Ie.separator}`,borderRadius:3,background:"transparent",cursor:"pointer"}})]})}function yy(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 wy=360;function V8({sessionId:e,sendMessage:s}){const[i,a]=_.useState(!1),[h,f]=_.useState(!1),[m,o]=_.useState({top:0,left:0}),[c,d]=_.useState(null),[p,u]=_.useState(""),[v,b]=_.useState(!1),[C,S]=_.useState(""),[x,y]=_.useState(""),[w,k]=_.useState(!1),[N,D]=_.useState(null),j=_.useRef(null),R=_.useRef(null),E=_.useRef(null),L=_.useCallback(()=>{if(!j.current)return;const H=j.current.getBoundingClientRect(),U=window.innerWidth,q=window.innerHeight,X=R.current;let B=H.bottom+4,P=H.right-wy;if(X){const $=X.offsetHeight,Y=X.offsetWidth;P=H.right-Y,P<8&&(P=8),P+Y>U-8&&(P=U-8-Y),B+$>q-8&&(B=Math.max(8,H.top-$-4))}else P<8&&(P=8);o({top:B,left:P}),f(!0)},[]);_.useEffect(()=>{if(!i)return;let H=!1;return Jw().then(U=>{H||d(U)}).catch(U=>{H||D(U instanceof Error?U.message:"Failed to load")}),()=>{H=!0}},[i]),_.useEffect(()=>{if(!i){f(!1);return}L();const H=requestAnimationFrame(L),U=requestAnimationFrame(()=>{requestAnimationFrame(()=>{var B;return(B=E.current)==null?void 0:B.focus()})}),q=B=>{var $,Y;const P=B.target;($=j.current)!=null&&$.contains(P)||(Y=R.current)!=null&&Y.contains(P)||a(!1)},X=B=>{B.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",q),document.addEventListener("keydown",X),window.addEventListener("scroll",L,!0),window.addEventListener("resize",L),()=>{cancelAnimationFrame(H),cancelAnimationFrame(U),document.removeEventListener("mousedown",q),document.removeEventListener("keydown",X),window.removeEventListener("scroll",L,!0),window.removeEventListener("resize",L)}},[i,L]),_.useEffect(()=>{i||(u(""),b(!1),S(""),y(""),D(null))},[i]);const A=_.useMemo(()=>{if(!c)return[];const H=p.trim().toLowerCase();return H?c.filter(U=>U.name.toLowerCase().includes(H)||U.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]))},I=!!C.trim()&&!!x.trim()&&!w,F=async()=>{if(I){k(!0),D(null);try{const H=await Qw({name:C.trim(),command_template:x.trim()});d(U=>U?[H,...U]:[H]),S(""),y(""),b(!1)}catch(H){D(H instanceof Error?H.message:"Failed")}finally{k(!1)}}};return t.jsxs(t.Fragment,{children:[t.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:Y8,children:t.jsx(m5,{size:13})}),i&&rn.createPortal(t.jsxs("div",{ref:R,className:"z-tooltip",style:{position:"fixed",top:m.top,left:m.left,width:wy,background:"#1e1e1e",border:`1px solid ${Ie.separator}`,borderRadius:6,padding:10,fontFamily:Rt,color:Ie.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:h?1:0,transition:"opacity 80ms"},onMouseDown:H=>H.stopPropagation(),children:[t.jsx("input",{ref:E,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 ${Ie.separator}`,borderRadius:4,color:Ie.bright,fontFamily:Rt,fontSize:11,padding:"6px 8px",outline:"none"}}),t.jsx("div",{style:{marginTop:8,maxHeight:280,overflowY:"auto"},children:c===null?t.jsx("div",{style:_y,children:"Loading…"}):A.length===0?t.jsx("div",{style:_y,children:c.length===0?"No aliases yet — add one below.":"No matches."}):A.map(H=>t.jsxs("button",{onClick:()=>O(H),style:X8,onMouseEnter:U=>U.currentTarget.style.background="rgba(255,255,255,0.06)",onMouseLeave:U=>U.currentTarget.style.background="transparent",title:`Insert: ${H.command_template}`,children:[t.jsx("span",{style:{fontSize:11,color:Ie.bright,fontWeight:600},children:H.name}),t.jsx("code",{style:{fontSize:10,color:Ie.dim,marginLeft:8,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:H.command_template})]},H.id))}),t.jsx("div",{style:{borderTop:`1px solid ${Ie.separator}`,marginTop:8,paddingTop:8},children:v?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("input",{type:"text",value:C,onChange:H=>S(H.target.value),placeholder:"Name (e.g. git status)",maxLength:64,style:Sy}),t.jsx("input",{type:"text",value:x,onChange:H=>y(H.target.value),onKeyDown:H=>{H.key==="Enter"&&(H.preventDefault(),F())},placeholder:"Command (e.g. git status -sb)",maxLength:1024,style:{...Sy,fontFamily:Rt}}),N&&t.jsx("div",{style:{fontSize:10,color:"#f87171"},children:N}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[t.jsxs("button",{type:"button",onClick:()=>{b(!1),D(null)},style:F_,children:[t.jsx(Qt,{size:10})," Cancel"]}),t.jsx("button",{type:"button",onClick:F,disabled:!I,style:{...J8,opacity:I?1:.5},children:"Save"})]})]}):t.jsxs("button",{type:"button",onClick:()=>{b(!0),D(null)},style:Q8,children:[t.jsx(mn,{size:12})," New alias"]})})]}),document.body)]})}const Y8={background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},_y={fontSize:11,color:Ie.dim,padding:"12px 4px",textAlign:"center"},X8={display:"flex",alignItems:"center",width:"100%",background:"transparent",border:"none",padding:"6px 8px",cursor:"pointer",textAlign:"left",borderRadius:3,transition:"background 80ms"},Sy={width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ie.separator}`,borderRadius:4,color:Ie.bright,fontSize:11,padding:"5px 7px",outline:"none"},F_={display:"inline-flex",alignItems:"center",gap:3,background:"transparent",border:`1px solid ${Ie.separator}`,color:Ie.dim,fontFamily:Rt,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer"},J8={...F_,background:"rgba(86,156,214,0.13)",border:"1px solid #569cd6",color:Ie.bright},Q8={display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",color:Ie.dim,fontFamily:Rt,fontSize:11,padding:"4px 0",cursor:"pointer"},Z8=26;function wp({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:v,onEvent:b,focusedSessionId:C,groupTopmost:S,onFocusStack:x,groupActions:y}){const{t:w}=st(),[k,,N]=Zw(e.activeTab),[D,j]=_.useState({}),R=()=>{const U=e.activeTab;U&&j(q=>({...q,[U]:(q[U]||0)+1}))},E=yO(),L=S===void 0?!0:S&&(!C||C===e.activeTab),A=S===!0&&!L,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(" · "),I=U=>{U.button===0&&e.activeTab&&(x?x(e.activeTab):E==null||E.focus(e.activeTab)),U.stopPropagation()},F=e.tabs.length>1?U=>{const q=e.tabs.indexOf(e.activeTab);if(q<0)return;const X=e.tabs.length,B=U==="next"?(q+1)%X:(q-1+X)%X;m(e.tabs[B])}:void 0,H=U=>{var Z;const q=/Mac|iPhone|iPad|iPod/.test(navigator.platform),X=q?U.metaKey:U.ctrlKey,B=q?U.ctrlKey:U.metaKey,P=X&&!B&&!U.altKey&&U.shiftKey,$=U.key.toLowerCase();if(U.key==="F5"&&!U.ctrlKey&&!U.metaKey&&!U.altKey&&!U.shiftKey||P&&$==="r"){U.preventDefault(),R();return}if(!P||$!=="a"&&$!=="p")return;U.preventDefault();const W=$==="a"?"alias-inserter":"terminal-theme";(Z=U.currentTarget.querySelector(`[aria-label="${W}"]`))==null||Z.click()};return t.jsxs("div",{onKeyDown:H,style:{flex:1,display:"flex",flexDirection:"column",background:Ie.bg,minWidth:0,minHeight:0,position:"relative",overflow:"hidden",opacity:A?S?.78:.88:1,filter:A?"saturate(0.78)":"none",boxShadow:L?`inset 0 0 0 1px ${Ie.info}`:"inset 0 0 0 1px transparent",transition:"opacity 140ms ease-out, filter 140ms ease-out, box-shadow 140ms ease-out"},children:[t.jsxs("div",{onDoubleClick:U=>{var q;U.target.closest("button")||(q=y==null?void 0:y.onToggleMaximize)==null||q.call(y)},style:{display:"flex",height:Z8,background:L?"#323a42":Ie.titleBg,borderBottom:`1px solid ${Ie.separator}`,flexShrink:0,overflowX:"auto",overflowY:"hidden"},children:[e.tabs.map(U=>{const q=a.get(U),X=U===e.activeTab,B=h[U]||Ie.titleText,P=(q==null?void 0:q.status)==="running"?Ie.success:(q==null?void 0:q.status)==="failed"?Ie.error:(q==null?void 0:q.status)==="completed"?Ie.info:Ie.dim,$=[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 t.jsxs("div",{onMouseDown:Y=>{if(Y.button===0){if(y){m(U);return}Y.stopPropagation(),m(U),c(U,s,Y)}},style:{display:"flex",alignItems:"center",gap:6,padding:"0 6px 0 10px",fontFamily:Rt,fontSize:11,color:X?Ie.bright:Ie.titleText,background:X?Ie.bg:"transparent",borderRight:`1px solid ${Ie.separator}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",maxWidth:200,position:"relative"},title:`${(q==null?void 0:q.title)||U}${$?`
665
- ${$}`:""}`,children:[t.jsx("span",{"aria-label":(q==null?void 0:q.status)||"unknown",style:{width:6,height:6,borderRadius:"50%",background:P,flexShrink:0}}),t.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Rt,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:B,width:16,textAlign:"center"},children:">_"}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(q==null?void 0:q.title)||U}),t.jsx("button",{"data-no-drag":!0,onMouseDown:Y=>Y.stopPropagation(),onClick:Y=>{Y.stopPropagation(),o(U)},"aria-label":"close-tab",title:w("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:t.jsx(Qt,{size:11})})]},U)}),E&&t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{E.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 ${Ie.separator}`,color:Ie.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:t.jsx(mn,{size:13})}),t.jsx("div",{style:{flex:1,minWidth:8}}),z&&t.jsx("span",{title:z,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ie.dim,fontFamily:Rt,fontSize:9,padding:"0 7px",flexShrink:1},children:z}),t.jsx(V8,{sessionId:e.activeTab,sendMessage:u}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.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:Ks,children:t.jsx(TN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>N(-1),"aria-label":"decrease-font",title:`${w("session.fontDecrease")||"Decrease font size"} (${k}px) · Ctrl+- · Ctrl+wheel`,style:Ks,children:t.jsx(QN,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>N(1),"aria-label":"increase-font",title:`${w("session.fontIncrease")||"Increase font size"} (${k}px) · Ctrl+= · Ctrl+wheel`,style:Ks,children:t.jsx(XN,{size:13})}),t.jsx(q8,{sessionId:e.activeTab}),y&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&y.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{var U;return(U=y.onApplyLayoutPreset)==null?void 0:U.call(y,"single")},"aria-label":"single-pane",title:w("session.layout.single"),style:Ks,children:t.jsx(qi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{var U;return(U=y.onApplyLayoutPreset)==null?void 0:U.call(y,"columns")},"aria-label":"two-columns",title:w("session.layout.columns"),style:Ks,children:t.jsx(Lw,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{var U;return(U=y.onApplyLayoutPreset)==null?void 0:U.call(y,"grid")},"aria-label":"grid-layout",title:w("session.layout.grid"),style:Ks,children:t.jsx(Rw,{size:13})})]}),y.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onToggleMaximize,"aria-label":"toggle-maximize",title:`${y.isMaximized?w("session.restoreSize"):w("session.maximize")} · ${w("session.maximizeHint")}`,style:Ks,children:y.isMaximized?t.jsx(Pu,{size:13}):t.jsx(Gi,{size:13})}),y.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onPopOutGroup,"aria-label":"pop-out",title:`${w("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Ks,children:t.jsx(li,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onMinimizeGroup,"aria-label":"minimize",title:`${w("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Ks,children:t.jsx(Aw,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onCloseGroup,"aria-label":"close",title:`${w("session.close")||"Close"} (Ctrl+Shift+X)`,style:Ks,children:t.jsx(Qt,{size:13})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:U=>{if(!U){p(s,null);return}const q=U.getBoundingClientRect();p(s,{x:q.left,y:q.top,w:q.width,h:q.height})},onMouseDown:I,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map(U=>{const q=a.get(U);if(!q)return null;const X=f[U]||{intent:"open",nonce:0};return t.jsx(H_,{session:q,visible:U===e.activeTab,intent:X.intent,intentNonce:X.nonce,onClose:()=>d(U),sendMessage:u,subscribeBinary:v,onEvent:b,onCycleTab:F,remountKey:D[U]||0},U)})})]})}const Ks={background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function eO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const h=_.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",v),document.removeEventListener("visibilitychange",b))},u=()=>{p(),a()},v=x=>{x.key==="Escape"&&u()},b=()=>{document.hidden&&u()},C=x=>{const y=e==="horizontal"?x.clientX-o:x.clientY-c;i(y)},S=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",S),window.addEventListener("blur",u),window.addEventListener("keydown",v),document.addEventListener("visibilitychange",b)},[e,s,i,a]),f=e==="horizontal";return t.jsx("div",{onMouseDown:h,style:{flex:"0 0 4px",background:Ie.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function _p(e){const{node:s,path:i,onSplitSizes:a,...h}=e;return s.kind==="stack"?t.jsx(wp,{stack:s,path:i,...h}):t.jsx(tO,{split:s,path:i,onSplitSizes:a,stackProps:h})}const ky=80;function tO({split:e,path:s,onSplitSizes:i,stackProps:a}){const h=e.orientation==="horizontal",f=_.useRef(null),m=_.useRef([]),o=_.useRef(null);return t.jsx("div",{ref:f,style:{display:"flex",flexDirection:h?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((c,d)=>t.jsxs(_.Fragment,{children:[t.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:t.jsx(_p,{node:c,path:[...s,d],onSplitSizes:i,...a})}),d<e.children.length-1&&t.jsx(eO,{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 v=u.initialSizes[u.i]/100*u.total,b=u.initialSizes[u.i+1]/100*u.total,C=v+b,S=Math.max(ky,Math.min(C-ky,v+p)),x=C-S,y=S/u.total*100,w=x/u.total*100,k=m.current[u.i],N=m.current[u.i+1];k&&(k.style.flexBasis=`${y}%`),N&&(N.style.flexBasis=`${w}%`);const D=u.initialSizes.slice();D[u.i]=y,D[u.i+1]=w,u.finalSizes=D},onDragEnd:()=>{const p=o.current;p&&i(s,p.finalSizes),o.current=null}})]},d))})}const nn=28,fs=68;function Vu(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)<=nn&&Math.abs(m)<=nn?"center":f>=-fs-nn&&f<=-fs+nn&&Math.abs(m)<=nn?"left":f>=fs-nn&&f<=fs+nn&&Math.abs(m)<=nn?"right":m>=-fs-nn&&m<=-fs+nn&&Math.abs(f)<=nn?"top":m>=fs-nn&&m<=fs+nn&&Math.abs(f)<=nn?"bottom":null}function Cu(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:Vu(e,s,c)}}return null}function nO(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 gl({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,h=s?nO(e,s):null;return rn.createPortal(t.jsxs(t.Fragment,{children:[h&&t.jsx("div",{style:{position:"fixed",left:h.x,top:h.y,width:h.w,height:h.h,background:`${Ie.info}33`,border:`2px dashed ${Ie.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=fs+nn;return t.jsxs("div",{style:{position:"fixed",left:i-f,top:a-f,width:f*2,height:f*2,pointerEvents:"none",zIndex:2500},children:[t.jsx(Xo,{offsetX:f-nn,offsetY:f-nn,active:s==="center",kind:"center"}),t.jsx(Xo,{offsetX:f-fs-nn,offsetY:f-nn,active:s==="left",kind:"left"}),t.jsx(Xo,{offsetX:f+fs-nn,offsetY:f-nn,active:s==="right",kind:"right"}),t.jsx(Xo,{offsetX:f-nn,offsetY:f-fs-nn,active:s==="top",kind:"top"}),t.jsx(Xo,{offsetX:f-nn,offsetY:f+fs-nn,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Xo({offsetX:e,offsetY:s,active:i,kind:a}){const h=nn*2,f=i?Ie.info:"#3a3a3a",m=i?Ie.bright:Ie.separator;return t.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 ${Ie.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:t.jsx(sO,{kind:a,fill:f})})}function sO({kind:e,fill:s}){const i={position:"absolute",background:s};switch(e){case"center":return t.jsx("div",{style:{...i,inset:4}});case"left":return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{...i,left:4,top:4,bottom:4,width:"calc(50% - 4px)"}}),t.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 t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"absolute",left:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),t.jsx("div",{style:{...i,right:4,top:4,bottom:4,width:"calc(50% - 4px)"}})]});case"top":return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{...i,top:4,left:4,right:4,height:"calc(50% - 4px)"}}),t.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 t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"absolute",top:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),t.jsx("div",{style:{...i,bottom:4,left:4,right:4,height:"calc(50% - 4px)"}})]})}}function wr(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function ll(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 Yu(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=Yu(e.children[i],s);if(a)return[i,...a]}return null}function un(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(un)}function ju(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(ju)}function rO(e,s){const i=un(e);if(i.length<=1||s==="single")return wr(i,ju(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),h=Array.from({length:a},()=>[]);i.forEach((u,v)=>h[v%a].push(u));const f=new Set(ju(e)),m=h.map(u=>wr(u,u.find(v=>f.has(v))||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 $i(e,s){return $_(e,s)}function $_(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=$_(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 Hi(e,s,i){return Xu(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 Ia(e,s,i,a){const h=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return Xu(e,s,m=>({kind:"split",orientation:h,children:f?[a,m]:[m,a],sizes:[50,50]}))}function Xu(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?Xu(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 U_(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=>U_(a,s,i))}}function W_(e,s,i){return Xu(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 iO(e,s,i,a){const h=ll(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=$i(e,s);if(!m)return null;const o=Yu(m,f);if(!o)return null;const c=a==="center"?Hi(m,o,s):Ia(m,o,a,wr([s]));return Bs(c,s)}function aO(e,s){const i=un(e);let a=e;for(const h of i){if(!a)break;s.has(h)||(a=$i(a,h))}return a}const Xc=320,Jc=200,Qc=80,Zc=22,oO=4,Cy=8,Zr=10,eu=60;function ei(e,s,i){return Math.max(s,Math.min(i,e))}function lO(e,s,i,a){const h=e<=Cy,f=e>=i-Cy;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 jy(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 cO(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 v=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-v)<=Zr?f=v-i:Math.abs(o-v)<=Zr?f=v:Math.abs(c-b)<=Zr&&(f=b-i)),o<b&&c>v&&(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 uO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:h,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:c}=st(),d=C_("(max-width: 767px)"),p=Y_(),u=_.useRef(null),[v,b]=_.useState(!1),C=_.useRef(null),[S,x]=_.useState(null),y=_.useRef({x:e.x,y:e.y,w:e.w,h:e.h});y.current={x:e.x,y:e.y,w:e.w,h:e.h};const[w,k]=_.useState(null),N=_.useRef(null),D=_.useRef(i);D.current=i;const[j,R]=_.useState(null),E=_.useRef(null),L=_.useCallback((J,V)=>{if(d||v||J.button!==0||J.target.closest("[data-no-drag]"))return;J.preventDefault(),p.focus(un(e.root)[0]||"");const oe=J.clientX,ge=J.clientY,le={...y.current},Oe=u.current,He=window.innerWidth,Te=window.innerHeight;let ye="";V&&Oe&&(ye=Oe.style.pointerEvents,Oe.style.pointerEvents="none");let ke=!1;const Ke=()=>{ke||(ke=!0,window.removeEventListener("mousemove",qe),window.removeEventListener("mouseup",Qe),window.removeEventListener("blur",$e),window.removeEventListener("keydown",be),document.removeEventListener("visibilitychange",De),V&&Oe&&(Oe.style.pointerEvents=ye))},$e=()=>{Ke(),E.current=null,R(null),N.current=null,k(null),p.setGroupGeometry(e.id,{...y.current})},be=nt=>{nt.key==="Escape"&&$e()},De=()=>{document.hidden&&$e()};let Fe=!1;const qe=nt=>{if(Fe)return;{const se=window.screenX,ce=window.screenY,fe=se+window.outerWidth,ue=ce+window.outerHeight;if(nt.screenX<se-eu||nt.screenX>fe+eu||nt.screenY<ce-eu||nt.screenY>ue+eu){Fe=!0,Ke(),E.current=null,R(null),N.current=null,k(null),p.setGroupGeometry(e.id,{...y.current}),p.popOutGroup(e.id,{atScreenX:nt.screenX,atScreenY:nt.screenY});return}}const xe=nt.clientX-oe,ie=nt.clientY-ge;let we=ei(le.x+xe,-(le.w-Qc),He-Qc),Q=ei(le.y+ie,0,Te-Zc);const K=D.current;if(K.length>0){const se=cO(we,Q,le.w,le.h,K);we=se.x,Q=se.y}if(Oe&&(Oe.style.left=`${we}px`,Oe.style.top=`${Q}px`),y.current.x=we,y.current.y=Q,V){let se=null;const ce=document.elementFromPoint(nt.clientX,nt.clientY),fe=ce==null?void 0:ce.closest("[data-group-id][data-stack-path]");if(fe){const ue=fe.dataset.groupId||"";if(ue!==e.id){const je=fe.dataset.stackPath||"",Ue=je===""?[]:je.split(".").map(Number),ut=fe.getBoundingClientRect(),Pe={x:ut.left,y:ut.top,w:ut.width,h:ut.height};se={groupId:ue,path:Ue,rect:Pe,zone:Vu(nt.clientX,nt.clientY,Pe)}}}E.current=se,R(se?{rect:se.rect,zone:se.zone}:null)}const ee=V&&E.current&&E.current.zone?null:lO(nt.clientX,nt.clientY,He,Te);ee!==N.current&&(N.current=ee,k(ee))},Qe=()=>{if(Ke(),V&&E.current&&E.current.zone){const nt=E.current;p.dockGroup(e.id,nt.groupId,nt.path,nt.zone),E.current=null,R(null),N.current=null,k(null);return}if(N.current){const nt=jy(N.current,He,Te);Oe&&(Oe.style.left=`${nt.x}px`,Oe.style.top=`${nt.y}px`,Oe.style.width=`${nt.w}px`,Oe.style.height=`${nt.h}px`),y.current=nt,N.current=null,k(null)}E.current=null,R(null),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",qe),window.addEventListener("mouseup",Qe),window.addEventListener("blur",$e),window.addEventListener("keydown",be),document.addEventListener("visibilitychange",De)},[d,v,p,e.id,e.root]),A=_.useCallback(J=>L(J,!1),[L]),O=_.useCallback(J=>L(J,!0),[L]),z=_.useCallback(J=>V=>{if(d||v||V.button!==0)return;V.preventDefault(),V.stopPropagation();const pe=V.clientX,oe=V.clientY,ge={...y.current},le=u.current,Oe=window.innerWidth,He=window.innerHeight,Te=Fe=>{const qe=Fe.clientX-pe,Qe=Fe.clientY-oe;let nt=ge.x,xe=ge.y,ie=ge.w,we=ge.h;J.includes("e")?ie=ei(ge.w+qe,Xc,Math.max(Xc,Oe-ge.x)):J.includes("w")&&(nt=ei(ge.x+qe,0,ge.x+ge.w-Xc),ie=ge.x+ge.w-nt),J.includes("s")?we=ei(ge.h+Qe,Jc,Math.max(Jc,He-ge.y)):J.includes("n")&&(xe=ei(ge.y+Qe,0,ge.y+ge.h-Jc),we=ge.y+ge.h-xe),le&&(le.style.left=`${nt}px`,le.style.top=`${xe}px`,le.style.width=`${ie}px`,le.style.height=`${we}px`),y.current={x:nt,y:xe,w:ie,h:we}};let ye=!1;const ke=()=>{ye||(ye=!0,window.removeEventListener("mousemove",Te),window.removeEventListener("mouseup",De),window.removeEventListener("blur",Ke),window.removeEventListener("keydown",$e),document.removeEventListener("visibilitychange",be))},Ke=()=>{ke(),p.setGroupGeometry(e.id,{...y.current})},$e=Fe=>{Fe.key==="Escape"&&Ke()},be=()=>{document.hidden&&Ke()},De=()=>{ke(),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",Te),window.addEventListener("mouseup",De),window.addEventListener("blur",Ke),window.addEventListener("keydown",$e),document.addEventListener("visibilitychange",be)},[d,v,p,e.id]);_.useEffect(()=>{if(d)return;const J=()=>{const V=window.innerWidth,pe=window.innerHeight,oe=y.current,ge=ei(oe.x,-(oe.w-Qc),V-Qc),le=ei(oe.y,0,pe-Zc);(ge!==oe.x||le!==oe.y)&&p.setGroupGeometry(e.id,{...oe,x:ge,y:le})};return window.addEventListener("resize",J),()=>window.removeEventListener("resize",J)},[d,p,e.id]);const I=_.useCallback(J=>{x(J),p.setActiveTab(e.id,J),p.focus(J)},[p,e.id]),F=_.useCallback(J=>{x(J),p.focus(J)},[p]),H=_.useCallback(J=>{p.close(J)},[p]),U=_.useCallback((J,V,pe)=>{p.beginTabDrag(e.id,J,V,pe)},[p,e.id]),q=_.useCallback(J=>{p.close(J)},[p]),X=_.useCallback((J,V)=>{p.setSplitSizes(e.id,J,V)},[p,e.id]),B=ju(e.root),P=un(e.root);_.useEffect(()=>{S&&P.includes(S)||x(B[0]||P[0]||null)},[S,B,P]);const $=_.useCallback(()=>{if(v){const J=C.current;J&&p.setGroupGeometry(e.id,J),C.current=null,b(!1);return}C.current={...y.current},p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(Xc,window.innerWidth-12),h:Math.max(Jc,window.innerHeight-12)}),b(!0)},[p,e.id,v]),Y=J=>{const V=/Mac|iPhone|iPad|iPod/.test(navigator.platform),pe=V?J.metaKey:J.ctrlKey,oe=V?J.ctrlKey:J.metaKey;if(!pe||oe||J.altKey||!J.shiftKey)return;const ge=J.key.toLowerCase();ge==="o"?(J.preventDefault(),p.popOutGroup(e.id)):ge==="m"?(J.preventDefault(),p.minimizeGroup(e.id)):ge==="x"&&(J.preventDefault(),p.closeGroup(e.id))};if(d){const J=B[0],V=J?s.get(J):null;if(!V)return null;const pe=e.intents[J]??{intent:"open",nonce:0};return rn.createPortal(t.jsxs("div",{style:{position:"fixed",inset:0,background:Ie.bg,display:"flex",flexDirection:"column",zIndex:110},children:[t.jsxs("div",{style:{background:Ie.titleBg,height:Zc,display:"flex",alignItems:"center",borderBottom:`1px solid ${Ie.separator}`},children:[t.jsx("span",{style:{flex:1,color:Ie.titleText,fontFamily:Rt,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:V.title}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ti,"aria-label":"close",children:t.jsx(Qt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(H_,{session:V,visible:!0,intent:pe.intent,intentNonce:pe.nonce,onClose:()=>p.close(J),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const W=w?(()=>{const J=window.innerWidth,V=window.innerHeight,pe=jy(w,J,V);return rn.createPortal(t.jsx("div",{style:{position:"fixed",left:pe.x,top:pe.y,width:pe.w,height:pe.h,background:`${Ie.info}33`,border:`2px dashed ${Ie.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,Z=(()=>{var V;if(P.length===0)return"";const J=((V=s.get(P[0]))==null?void 0:V.title)||P[0];return P.length===1?J:`${J} +${P.length-1}`})(),he=e.root.kind==="split",re=rn.createPortal(t.jsxs("div",{ref:u,onKeyDown:Y,onMouseDown:he?()=>p.focus(P[0]||""):O,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:h,background:Ie.bg,border:`1px solid ${a?Ie.info:Ie.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 ${Ie.info}66, 0 0 18px ${Ie.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:[he&&t.jsxs("div",{onMouseDown:A,onDoubleClick:J=>{J.target.closest("button")||$()},style:{height:Zc,flexShrink:0,display:"flex",flexDirection:"column",background:Ie.titleBg,borderBottom:`1px solid ${Ie.separator}`,userSelect:"none",cursor:"move"},children:[t.jsx("div",{style:{display:"flex",height:oO,flexShrink:0},children:B.map((J,V)=>t.jsx("div",{style:{flex:1,background:e.colors[J]||Ie.titleText}},V))}),t.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:Ie.titleText,fontFamily:Rt,fontSize:11},children:[t.jsx("span",{style:{color:Ie.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Z}),P.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:ti,"aria-label":"single-pane",title:c("session.layout.single"),children:t.jsx(qi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:ti,"aria-label":"two-columns",title:c("session.layout.columns"),children:t.jsx(Lw,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:ti,"aria-label":"grid-layout",title:c("session.layout.grid"),children:t.jsx(Rw,{size:13})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:$,style:ti,"aria-label":"toggle-maximize",title:`${c(v?"session.restoreSize":"session.maximize")} · ${c("session.maximizeHint")}`,children:v?t.jsx(Pu,{size:13}):t.jsx(Gi,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.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:t.jsx(li,{size:14})}),t.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:t.jsx(Aw,{size:14})}),t.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:t.jsx(Qt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(_p,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:I,onTabClose:H,onTabMouseDown:U,onPaneAutoClose:q,registerRect:()=>{},onSplitSizes:X,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:S||void 0,groupTopmost:a,onFocusStack:F}):t.jsx(wp,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:I,onTabClose:H,onTabMouseDown:U,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:$,isMaximized:v,onApplyLayoutPreset:J=>p.applyLayoutPreset(e.id,J)}})}),t.jsx("div",{onMouseDown:z("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),t.jsx("div",{onMouseDown:z("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:z("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.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 t.jsxs(t.Fragment,{children:[re,W,j&&t.jsx(gl,{targetRect:j.rect,activeZone:j.zone})]})}const ti={background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},Ff=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Ii(e){for(const s of Ff)if(!e.includes(s))return s;return Ff[e.length%Ff.length]}const dO="clitrigger:session-windows:global";function Sp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(dO),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 Bt="main",Nm=new Map;function hO(e,s){Nm.set(e,s)}function fO(e){const s=Nm.get(e);if(!s||s.closed)return Nm.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function mO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const G_=5e3,pO=15e3;let Pa=null;function q_(){if(typeof window>"u")return()=>{};const e=s=>{Pa={sx:s.screenX,sy:s.screenY,cx:s.clientX,cy:s.clientY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function Eu(e,s){if(Pa)return{x:Pa.cx+(e-Pa.sx),y:Pa.cy+(s-Pa.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 Tu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Em="clitrigger:popout-alive:";function gO(e){return`${Em}${e}`}function K_(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function xO(e){if(!K_())return()=>{};let s=()=>{};return navigator.locks.request(gO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function vO(){var e;if(!K_())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(Em)&&i.add(a.name.slice(Em.length));return i}catch{return new Set}}const kp=_.createContext(null),V_=_.createContext({});function Y_(){const e=_.useContext(kp);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function bO(){return _.useContext(V_)}function yO(){return _.useContext(kp)}const Lu=720,Cp=460,wO=320,_O=200,Ny=30,X_=80,J_=80,cl=80,Tm=28;function SO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=wO?e.w:Lu,h=Number.isFinite(e.h)&&e.h>=_O?e.h:Cp;a=Math.min(a,s),h=Math.min(h,i);let f=Number.isFinite(e.x)?e.x:X_,m=Number.isFinite(e.y)?e.y:J_;return f=Math.max(Math.min(f,s-cl),-(a-cl)),m=Math.max(Math.min(m,i-Tm),0),{x:f,y:m,w:a,h}}const kO=12,tu=60;function Q_(e){return`sessionGroups:${e}`}function du(e){try{const s=localStorage.getItem(Q_(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 Lm(e,s){try{localStorage.setItem(Q_(e),JSON.stringify(s))}catch{}}function CO(e,s){const i=du(e);!i||!i.groups.some(a=>a.id===s)||(Lm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function jO(e){const s=e%8;return{x:X_+s*Ny,y:J_+s*Ny,w:Lu,h:Cp}}function nu(e,s,i){return Math.max(s,Math.min(i,e))}function Ey(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function ni(e,s){for(const i of e)if(Yu(i.root,s))return i;return null}function NO({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:h,onAddSession:f,children:m}){const{t:o}=st(),[c]=_.useState(()=>{const Q=du(e);if(!Q)return{groups:[],zCounter:0};const K=Q.groups.map(ne=>{const ee=un(ne.root),se=new Set(ee),ce={};for(const Ue of Object.keys(ne.colors||{}))se.has(Ue)&&(ce[Ue]=ne.colors[Ue]);const fe={};for(const Ue of ee)fe[Ue]={intent:"open",nonce:0},ce[Ue]||(ce[Ue]=Ii(Object.values(ce)));const ue=SO({x:ne.x,y:ne.y,w:ne.w,h:ne.h}),je=ne.ownerWindowId||Bt;return{...ne,...ue,colors:ce,intents:fe,minimized:!!ne.minimized,ownerWindowId:je}});return{groups:K,zCounter:Q.zCounter||K.length}}),[d,p]=_.useState(c.groups),u=_.useRef(c.zCounter),v=_.useRef(d);v.current=d;const b=_.useRef(s);b.current=s;const[C,S]=_.useState(null),x=_.useRef(null);x.current=C;const[y,w]=_.useState({}),k=_.useRef(y);k.current=y,_.useEffect(()=>{var ee;const Q={},K=((ee=du(e))==null?void 0:ee.sessionProjects)??{},ne={};for(const se of d)for(const ce of un(se.root)){const fe=s.find(je=>je.id===ce)||y[ce];fe!=null&&fe.title&&(Q[ce]=fe.title);const ue=(fe==null?void 0:fe.project_id)||K[ce];ue&&(ne[ce]=ue)}Lm(e,{groups:d,zCounter:u.current,titles:Q,sessionProjects:ne}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,d,s,y]),_.useEffect(()=>()=>{var fe;const Q=v.current;if(Q.length===0)return;let K=!1;const ne=Q.map(ue=>(ue.ownerWindowId||Bt)!==Bt||ue.minimized?ue:(K=!0,{...ue,minimized:!0}));if(!K)return;const ee={},se=((fe=du(e))==null?void 0:fe.sessionProjects)??{},ce={};for(const ue of ne)for(const je of un(ue.root)){const Ue=b.current.find(Pe=>Pe.id===je)||k.current[je];Ue!=null&&Ue.title&&(ee[je]=Ue.title);const ut=(Ue==null?void 0:Ue.project_id)||se[je];ut&&(ce[je]=ut)}Lm(e,{groups:ne,zCounter:u.current,titles:ee,sessionProjects:ce}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]);const[N,D]=_.useState(()=>new Set),j=_.useRef(new Set);_.useEffect(()=>{if(s.length===0)return;const Q=s.filter(ne=>ne.project_id===e);if(Q.length===0)return;const K=new Set(Q.map(ne=>ne.id));for(const ne of d)for(const ee of un(ne.root))K.has(ee)||y[ee]||N.has(ee)||j.current.has(ee)||(j.current.add(ee),u1(ee).then(se=>w(ce=>({...ce,[ee]:se}))).catch(se=>{se instanceof fu&&se.status===404&&D(ce=>new Set(ce).add(ee))}).finally(()=>j.current.delete(ee)))},[d,s,e,y,N]),_.useEffect(()=>h(K=>{K.type!=="session:status-changed"||!K.sessionId||w(ne=>{const ee=ne[K.sessionId];if(!ee)return ne;const se={status:K.status};return K.worktree_path!==void 0&&(se.worktree_path=K.worktree_path),K.branch_name!==void 0&&(se.branch_name=K.branch_name),{...ne,[ee.id]:{...ee,...se}}})}),[h]),_.useEffect(()=>{N.size!==0&&p(Q=>{let K=!1;const ne=[];for(const ee of Q){const se=un(ee.root);if(!se.some(ut=>N.has(ut))){ne.push(ee);continue}K=!0;const ce=new Set(se.filter(ut=>!N.has(ut))),fe=aO(ee.root,ce);if(!fe)continue;const ue=new Set(un(fe)),je={};for(const ut of Object.keys(ee.colors))ue.has(ut)&&(je[ut]=ee.colors[ut]);const Ue={};for(const ut of Object.keys(ee.intents))ue.has(ut)&&(Ue[ut]=ee.intents[ut]);ne.push({...ee,root:fe,colors:je,intents:Ue})}return K?ne:Q})},[N]);const R=_.useCallback((Q,K)=>{const ne=v.current.length,ee=jO(ne);u.current+=1;const se=u.current;return{id:Ey(),...ee,z:se,minimized:!1,root:wr([Q],Q),colors:{[Q]:Ii([])},intents:{[Q]:{intent:K,nonce:0}},ownerWindowId:Bt}},[]),E=_.useCallback((Q,K="open")=>{p(ne=>{const ee=ni(ne,Q);u.current+=1;const se=u.current;return ee?ne.map(ce=>{var ut,Pe,Ve;if(ce.id!==ee.id)return ce;const fe=((ut=ce.intents[Q])==null?void 0:ut.intent)??"open",ue=K==="start"||K==="resume",je=ue?K:fe,Ue=je!==fe||ue;return{...ce,z:se,minimized:!1,root:Bs(ce.root,Q),intents:{...ce.intents,[Q]:{intent:je,nonce:Ue?(((Pe=ce.intents[Q])==null?void 0:Pe.nonce)??0)+1:((Ve=ce.intents[Q])==null?void 0:Ve.nonce)??0}}}}):[...ne,R(Q,K)]})},[R]),L=_.useCallback(Q=>{p(K=>{const ne=ni(K,Q);if(!ne)return K;const ee=K.reduce((ce,fe)=>fe.z>ce?fe.z:ce,0);if(ne.z===ee&&!ne.minimized)return K;u.current+=1;const se=u.current;return K.map(ce=>ce.id===ne.id?{...ce,z:se,minimized:!1}:ce)})},[]),A=_.useCallback(Q=>{const K=Q.map(ne=>b.current.find(ee=>ee.id===ne)||k.current[ne]).filter(ne=>!!ne&&ne.status==="running");if(K.length===0)return!0;if(!window.confirm(o("session.confirmStop")))return!1;for(const ne of K)bu(ne.id).catch(()=>{});return!0},[o]),O=_.useCallback(Q=>{A([Q])&&p(K=>{const ne=ni(K,Q);if(!ne)return K;const ee=$i(ne.root,Q);if(!ee)return K.filter(fe=>fe.id!==ne.id);new Set(un(ee));const se={...ne.colors};delete se[Q];const ce={...ne.intents};return delete ce[Q],K.map(fe=>fe.id===ne.id?{...fe,root:ee,colors:se,intents:ce}:fe)})},[A]),z=_.useCallback(Q=>{p(K=>{const ne=ni(K,Q);return ne?K.map(ee=>ee.id===ne.id?{...ee,minimized:!0}:ee):K})},[]),I=_.useCallback(Q=>{p(K=>{const ne=ni(K,Q);if(!ne)return K;u.current+=1;const ee=u.current;return K.map(se=>se.id===ne.id?{...se,minimized:!1,z:ee}:se)})},[]),F=_.useCallback(Q=>!!ni(v.current,Q),[]),H=_.useCallback(Q=>{const K=v.current.find(ne=>ne.id===Q);K&&!A(un(K.root))||p(ne=>ne.filter(ee=>ee.id!==Q))},[A]),U=_.useCallback(Q=>{p(K=>K.map(ne=>ne.id===Q?{...ne,minimized:!0}:ne))},[]);_.useEffect(()=>{const Q=ne=>{const ee=ne.detail;!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId===e&&p(se=>{if(!se.find(ue=>ue.id===ee.groupId))return se;u.current+=1;const fe=u.current;return se.map(ue=>ue.id===ee.groupId?{...ue,minimized:!1,z:fe}:ue)})},K=ne=>{var fe;const ee=ne.detail;if(!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId!==e)return;const se=v.current.find(ue=>ue.id===ee.groupId);if(se&&!A(un(se.root)))return;const ce=(se==null?void 0:se.ownerWindowId)||Bt;ce!==Bt&&(J.current.delete(ce),Oe.current.delete(ee.groupId),(fe=re.current)==null||fe.post({t:"group-reclaimed",popoutId:ce,groupIds:[ee.groupId],reason:"late-return"})),p(ue=>ue.filter(je=>je.id!==ee.groupId))};return window.addEventListener("session-windows:restore",Q),window.addEventListener("session-windows:close",K),()=>{window.removeEventListener("session-windows:restore",Q),window.removeEventListener("session-windows:close",K)}},[e,A]),_.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRestore");if(Q)try{const K=JSON.parse(Q);if(K.projectId!==e||!K.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),p(ne=>{if(!ne.find(ce=>ce.id===K.groupId))return ne;u.current+=1;const se=u.current;return ne.map(ce=>ce.id===K.groupId?{...ce,minimized:!1,z:se}:ce)})}catch{}},[e]);const q=_.useCallback(Q=>{p(K=>{if(!K.find(se=>se.id===Q))return K;u.current+=1;const ee=u.current;return K.map(se=>se.id===Q?{...se,minimized:!1,z:ee}:se)})},[]),X=_.useCallback((Q,K)=>{p(ne=>ne.map(ee=>ee.id===Q?{...ee,...K}:ee))},[]),B=_.useCallback((Q,K,ne)=>{p(ee=>ee.map(se=>se.id===Q?{...se,root:W_(se.root,K,ne)}:se))},[]),P=_.useCallback((Q,K)=>{p(ne=>ne.map(ee=>ee.id===Q?{...ee,root:Bs(ee.root,K)}:ee))},[]),$=_.useCallback((Q,K)=>{p(ne=>ne.map(ee=>ee.id===Q?{...ee,root:rO(ee.root,K)}:ee))},[]),Y=_.useCallback((Q,K,ne)=>{p(ee=>ee.map(se=>se.id===Q?{...se,root:U_(se.root,K,ne)}:se))},[]),W=_.useCallback((Q,K,ne,ee)=>{if(ee.button!==0||!v.current.find(rt=>rt.id===Q))return;ee.preventDefault();const ce=ee.clientX,fe=ee.clientY;let ue=null;S({groupId:Q,sessionId:K,fromPath:ne,startX:ce,startY:fe,mouseX:ce,mouseY:fe,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null});const je=(rt,Le)=>{const et=Ey();ue=et;const wt=window.innerWidth,kt=window.innerHeight,de={x:nu(rt-60,-Lu+cl,wt-cl),y:nu(Le-12,0,kt-Tm),w:Lu,h:Cp};p(Re=>{const Ee=Re.find(Ft=>Ft.id===Q);if(!Ee)return Re;const ve=$i(Ee.root,K),at=Ee.colors[K]||Ii([]),vt=Ee.intents[K]??{intent:"open",nonce:0};u.current+=1;const Ct=u.current,Tt={id:et,...de,z:Ct,minimized:!1,root:wr([K],K),colors:{[K]:at},intents:{[K]:vt},ownerWindowId:Bt},Nt=[];for(const Ft of Re)if(Ft.id===Q){if(ve){const Dn=new Set(un(ve)),Wn={};for(const Tn of Object.keys(Ft.colors))Dn.has(Tn)&&(Wn[Tn]=Ft.colors[Tn]);const In={};for(const Tn of Object.keys(Ft.intents))Dn.has(Tn)&&(In[Tn]=Ft.intents[Tn]);Nt.push({...Ft,root:Nu(ve),colors:Wn,intents:In})}}else Nt.push(Ft);return Nt.push(Tt),Nt})};let Ue=!1;const ut=rt=>{const Le=window.screenX,et=window.screenY,wt=Le+window.outerWidth,kt=et+window.outerHeight;return rt.screenX<Le-tu||rt.screenX>wt+tu||rt.screenY<et-tu||rt.screenY>kt+tu},Pe=rt=>{if(Ue)return;const Le=x.current;if(!Le)return;if(!ue)Math.hypot(rt.clientX-ce,rt.clientY-fe)>=kO&&je(rt.clientX,rt.clientY);else{const Ee=window.innerWidth,ve=window.innerHeight,at=nu(rt.clientX-60,-640,Ee-cl),vt=nu(rt.clientY-12,0,ve-Tm);p(Ct=>Ct.map(Tt=>Tt.id===ue?{...Tt,x:at,y:vt}:Tt))}if(ue&&ut(rt)&&v.current.some(Ee=>Ee.id===ue)){const Ee=He.current;if(Ee){Ue=!0;const ve=ue;Ne(),S(null),Ee(ve,{atScreenX:rt.screenX,atScreenY:rt.screenY});return}}let et=null,wt=null,kt=null,de=null;const Re=document.elementsFromPoint(rt.clientX,rt.clientY);for(const Ee of Re){const ve=Ee.closest("[data-group-id][data-stack-path]");if(!ve)continue;const at=ve.dataset.groupId||"",vt=ve.dataset.stackPath||"";if(ue?at===ue:at===Le.groupId&&vt===Le.fromPath.join("."))continue;const Tt=vt===""?[]:vt.split(".").map(Number),Nt=ve.getBoundingClientRect();et=at,wt=Tt,kt={x:Nt.left,y:Nt.top,w:Nt.width,h:Nt.height},de=Vu(rt.clientX,rt.clientY,kt);break}S({...Le,mouseX:rt.clientX,mouseY:rt.clientY,hoveredGroupId:et,hoveredPath:wt,hoveredRect:kt,zone:de})};let Ve=!1;const Ne=()=>{Ve||(Ve=!0,window.removeEventListener("mousemove",Pe),window.removeEventListener("mouseup",ft),window.removeEventListener("blur",it),window.removeEventListener("keydown",lt),document.removeEventListener("visibilitychange",xt))},it=()=>{Ne(),S(null)},lt=rt=>{rt.key==="Escape"&&it()},xt=()=>{document.hidden&&it()},ft=()=>{Ne();const rt=x.current;if(S(null),!!rt&&rt.hoveredGroupId&&rt.hoveredPath&&rt.zone){const Le=ue||rt.groupId;Z(Le,rt.sessionId,rt.hoveredGroupId,rt.hoveredPath,rt.zone);return}};window.addEventListener("mousemove",Pe),window.addEventListener("mouseup",ft),window.addEventListener("blur",it),window.addEventListener("keydown",lt),document.addEventListener("visibilitychange",xt)},[]),Z=_.useCallback((Q,K,ne,ee,se)=>{p(ce=>{const fe=ce.find(lt=>lt.id===Q),ue=ce.find(lt=>lt.id===ne);if(!fe||!ue)return ce;if(Q===ne){const lt=ll(fe.root,ee);if(!lt||lt.kind!=="stack")return ce;const xt=lt.tabs.find(et=>et!==K);if(!xt)return ce;const ft=$i(fe.root,K);if(!ft)return ce;const rt=Yu(ft,xt);if(!rt)return ce;let Le;return se==="center"?Le=Hi(ft,rt,K):Le=Ia(ft,rt,se,wr([K])),Le=Bs(Le,K),ce.map(et=>et.id!==Q?et:(u.current+=1,{...et,root:Le,z:u.current,minimized:!1}))}const je=$i(fe.root,K),Ue=fe.colors[K],ut=fe.intents[K]??{intent:"open",nonce:0};let Pe;if(se==="center")Pe=Hi(ue.root,ee,K);else{const lt=wr([K]);Pe=Ia(ue.root,ee,se,lt)}Pe=Bs(Pe,K);const Ve={...ue.colors};Ve[K]||(Ve[K]=Ue||Ii(Object.values(Ve)));const Ne={...ue.intents,[K]:ut},it=[];for(const lt of ce)if(lt.id===Q){if(je){const xt=new Set(un(je)),ft={};for(const Le of Object.keys(lt.colors))xt.has(Le)&&(ft[Le]=lt.colors[Le]);const rt={};for(const Le of Object.keys(lt.intents))xt.has(Le)&&(rt[Le]=lt.intents[Le]);it.push({...lt,root:je,colors:ft,intents:rt})}}else lt.id===ne?(u.current+=1,it.push({...lt,root:Pe,colors:Ve,intents:Ne,z:u.current,minimized:!1})):it.push(lt);return it})},[]),he=_.useCallback((Q,K,ne,ee)=>{p(se=>{if(Q===K)return se;const ce=se.find(Ve=>Ve.id===Q),fe=se.find(Ve=>Ve.id===K);if(!ce||!fe||ce.root.kind!=="stack")return se;const ue=ce.root;let je;ee==="center"?je=ue.tabs.reduce((Ve,Ne)=>Hi(Ve,ne,Ne),fe.root):je=Ia(fe.root,ne,ee,ue),je=Bs(je,ue.activeTab);const Ue={...fe.colors,...ce.colors},ut={...fe.intents,...ce.intents},Pe=[];for(const Ve of se)Ve.id!==Q&&(Ve.id===K?(u.current+=1,Pe.push({...Ve,root:je,colors:Ue,intents:ut,z:u.current,minimized:!1})):Pe.push(Ve));return Pe})},[]),re=_.useRef(null),J=_.useRef(new Map),[V,pe]=_.useState(null),oe=_.useRef(V);oe.current=V;const ge=_.useRef(null),le=_.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);_.useEffect(()=>{const Q=()=>{le.current=Date.now()};window.addEventListener("focus",Q);const K=q_();return()=>{window.removeEventListener("focus",Q),K(),ge.current&&clearTimeout(ge.current)}},[]);const Oe=_.useRef(new Map),He=_.useRef(null),Te=_.useCallback((Q,K)=>{var Pe;const ne=v.current.find(Ve=>Ve.id===Q);if(!ne)return;const ee=mO(),se={...ne,ownerWindowId:ee};Oe.current.set(Q,se),J.current.set(ee,Date.now()),p(Ve=>Ve.map(Ne=>Ne.id===Q?{...Ne,ownerWindowId:ee}:Ne)),(Pe=re.current)==null||Pe.post({t:"group-handoff",to:ee,groupId:Q,group:se});const ce=K&&(typeof K.atScreenX=="number"||typeof K.atScreenY=="number"),fe=ce?Math.max(0,((K==null?void 0:K.atScreenX)??window.screenX+ne.x)-40):Math.max(0,window.screenX+ne.x),ue=ce?Math.max(0,((K==null?void 0:K.atScreenY)??window.screenY+ne.y)-12):Math.max(0,window.screenY+ne.y),je=["popup",`width=${Math.max(400,ne.w)}`,`height=${Math.max(300,ne.h+40)}`,`left=${fe}`,`top=${ue}`].join(","),Ue=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(Q)}?wid=${encodeURIComponent(ee)}`,ut=window.open(Ue,"_blank",je);if(!ut){Oe.current.delete(Q),J.current.delete(ee),p(Ve=>Ve.map(Ne=>Ne.id===Q?{...Ne,ownerWindowId:Bt}:Ne)),window.alert(o("session.popout.blocked")||"Popup blocked. Allow popups for this site to use Pop Out.");return}hO(ee,ut)},[e,o]);He.current=Te;const ye=_.useCallback(Q=>{var ee;const K=v.current.find(se=>se.id===Q);if(!K)return;const ne=K.ownerWindowId||Bt;if(ne===Bt){q(Q);return}(ee=re.current)==null||ee.post({t:"group-recall",popoutId:ne,groupId:Q}),setTimeout(()=>{var fe;const se=v.current.find(ue=>ue.id===Q);if(!se||(se.ownerWindowId||Bt)===Bt)return;J.current.delete(ne),Oe.current.delete(Q),(fe=re.current)==null||fe.post({t:"group-reclaimed",popoutId:ne,groupIds:[Q],reason:"late-return"}),u.current+=1;const ce=u.current;p(ue=>ue.map(je=>je.id===Q?{...je,ownerWindowId:Bt,minimized:!1,z:ce}:je))},1500)},[q]),ke=_.useCallback(Q=>{const K=ni(v.current,Q);K&&ye(K.id)},[ye]);_.useEffect(()=>{const Q=K=>{const ne=K.detail;!(ne!=null&&ne.projectId)||!ne.groupId||ne.projectId!==e||ye(ne.groupId)};return window.addEventListener("session-windows:recall",Q),()=>window.removeEventListener("session-windows:recall",Q)},[e,ye]),_.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRecall");if(Q)try{const K=JSON.parse(Q);if(K.projectId!==e||!K.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const ne=K.groupId;setTimeout(()=>ye(ne),0)}catch{}},[e,ye]);const Ke=_.useCallback(Q=>Q.kind==="stack"?[]:[0,...Ke(Q.children[0])],[]),$e=_.useCallback((Q,K,ne)=>{const ee=K?v.current.find(ue=>ue.id===K):null,se=ee&&(ee.ownerWindowId||Bt)===Bt;if(!ee||!se){E(Q,"start");return}const ce=(()=>{if(ne){const ue=ll(ee.root,ne);if(ue&&ue.kind==="stack")return ne}return Ke(ee.root)})();u.current+=1;const fe=u.current;p(ue=>ue.map(je=>{if(je.id!==ee.id)return je;const Ue=Bs(Hi(je.root,ce,Q),Q);return{...je,root:Ue,z:fe,minimized:!1,colors:{...je.colors,[Q]:Ii(Object.values(je.colors))},intents:{...je.intents,[Q]:{intent:"start",nonce:0}}}}))},[E,Ke]),be=_.useCallback(async(Q,K)=>{const ne=new Date,ee=String(ne.getHours()).padStart(2,"0"),se=String(ne.getMinutes()).padStart(2,"0"),ce=String(ne.getSeconds()).padStart(2,"0"),fe=await dm(e,{title:`Shell ${ee}:${se}:${ce}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(fe),$e(fe.id,Q,K),fe.id},[e,f,$e]);_.useEffect(()=>{const Q=Sp();re.current=Q;const K=ee=>{var se;if(ee.t==="hello"){const ce=Oe.current.get(ee.groupId);if(ce&&ce.ownerWindowId===ee.from)Q.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:ce});else{const fe=v.current.find(ue=>ue.id===ee.groupId);fe&&fe.ownerWindowId===ee.from&&Q.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:fe})}}else if(ee.t==="group-return"||ee.t==="bye")if(ee.t==="group-return"){const ce=ee.group;ce&&ce.id===ee.groupId&&(Oe.current.delete(ee.groupId),J.current.delete(ee.from),ee.projectId&&ee.projectId!==e&&CO(ee.projectId,ee.groupId),p(fe=>{const ue=fe.find(Ue=>Ue.id===ee.groupId),je={...ce,ownerWindowId:Bt};return ue?fe.map(Ue=>Ue.id===ee.groupId?je:Ue):[...fe,je]}))}else J.current.delete(ee.from),p(ce=>ce.map(fe=>fe.ownerWindowId===ee.from?{...fe,ownerWindowId:Bt}:fe));else if(ee.t==="group-close")Oe.current.delete(ee.groupId),p(ce=>ce.filter(fe=>fe.id!==ee.groupId));else if(ee.t==="heartbeat")J.current.set(ee.from,Date.now());else if(ee.t==="group-update"){const ce=ee.patch;p(fe=>fe.map(ue=>ue.id===ee.groupId?{...ue,...ce}:ue))}else if(ee.t==="dock-probe"){if(document.visibilityState!=="visible")return;const ce=Eu(ee.x,ee.y),fe=Tu(ce)?Cu(ce.x,ce.y):null;if(fe){const ue=oe.current;(!ue||ue.zone!==fe.zone||ue.groupId!==fe.groupId||ue.path.join(".")!==fe.path.join("."))&&pe({rect:fe.rect,zone:fe.zone,path:fe.path,groupId:fe.groupId}),ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>pe(null),800),Q.post({t:"dock-probe-result",from:Bt,to:ee.from,hit:!0,focusAt:le.current})}else oe.current&&pe(null),Q.post({t:"dock-probe-result",from:Bt,to:ee.from,hit:!1,focusAt:le.current})}else if(ee.t==="dock-end")pe(null);else if(ee.t==="dock-commit"&&ee.to===Bt){const ce=Eu(ee.x,ee.y),fe=Tu(ce)?Cu(ce.x,ce.y):null,ue=fe&&fe.zone?fe:(se=oe.current)!=null&&se.zone?oe.current:null;let je=!1;const Ue=v.current.filter(ut=>(ut.ownerWindowId||Bt)===Bt);if(ue&&ue.zone&&!ni(Ue,ee.sessionId)){const ut=v.current.find(Ve=>Ve.id===ue.groupId),Pe=ut?ll(ut.root,ue.path):null;if(ut&&Pe&&Pe.kind==="stack"){je=!0;const Ve=ue.zone,Ne=ue.path;u.current+=1;const it=u.current;p(lt=>lt.map(xt=>{if(xt.id!==ut.id)return xt;const ft=Ve==="center"?Hi(xt.root,Ne,ee.sessionId):Ia(xt.root,Ne,Ve,wr([ee.sessionId])),rt=Bs(ft,ee.sessionId),Le={...xt.colors};Le[ee.sessionId]||(Le[ee.sessionId]=ee.color||Ii(Object.values(Le)));const et={...xt.intents,[ee.sessionId]:ee.intentInfo??{intent:"open",nonce:0}};return{...xt,root:rt,colors:Le,intents:et,z:it,minimized:!1}}))}}pe(null),Q.post({t:"dock-commit-ack",from:Bt,to:ee.from,sessionId:ee.sessionId,accepted:je})}},ne=Q.subscribe(K);return()=>{ne(),Q.close(),re.current=null}},[e]),_.useEffect(()=>{const Q=Date.now();for(const K of c.groups)K.ownerWindowId&&K.ownerWindowId!==Bt&&J.current.set(K.ownerWindowId,Q)},[]),_.useEffect(()=>{const Q=async()=>{var ue;const ne=Date.now(),ee=[];for(const[je,Ue]of J.current.entries())ne-Ue>pO&&ee.push(je);if(ee.length===0)return;const se=await vO(),ce=ee.filter(je=>se.has(je)?(J.current.set(je,ne),!1):!0);if(ce.length===0)return;for(const je of ce)J.current.delete(je);const fe=new Set(ce);for(const je of v.current)je.ownerWindowId&&fe.has(je.ownerWindowId)&&Oe.current.delete(je.id);for(const je of ce){const Ue=v.current.filter(ut=>ut.ownerWindowId===je).map(ut=>ut.id);Ue.length>0&&((ue=re.current)==null||ue.post({t:"group-reclaimed",popoutId:je,groupIds:Ue,reason:"heartbeat-timeout"}))}p(je=>je.map(Ue=>Ue.ownerWindowId&&ce.includes(Ue.ownerWindowId)?{...Ue,ownerWindowId:Bt}:Ue))},K=setInterval(()=>{Q()},G_);return()=>clearInterval(K)},[]);const De=_.useCallback((Q,K)=>{i({type:"session:terminal-input",sessionId:Q,input:K})},[i]),Fe=_.useCallback(()=>{var ne,ee;const Q=v.current.filter(se=>(se.ownerWindowId||Bt)===Bt).slice().sort((se,ce)=>ce.z-se.z),K=[];for(const se of Q)for(const ce of un(se.root)){const fe=((ne=b.current.find(ue=>ue.id===ce))==null?void 0:ne.title)||((ee=k.current[ce])==null?void 0:ee.title)||ce;K.push({sessionId:ce,label:fe})}return K},[]),qe=_.useCallback(async(Q,K)=>{const ee=v.current.filter(ce=>!ce.minimized&&(ce.ownerWindowId||Bt)===Bt).reduce((ce,fe)=>ce&&ce.z>=fe.z?ce:fe,null),se=await dm(e,{title:K||"",description:Q,use_worktree:!1,memory_inject_mode:"none"});f==null||f(se),$e(se.id,(ee==null?void 0:ee.id)??null)},[e,f,$e]),Qe=_.useMemo(()=>({openOrFocus:E,close:O,focus:L,minimize:z,restore:I,isOpen:F,recallPopout:ke,closeGroup:H,minimizeGroup:U,restoreGroup:q,setGroupGeometry:X,setSplitSizes:B,setActiveTab:P,applyLayoutPreset:$,reorderTab:Y,beginTabDrag:W,dockGroup:he,popOutGroup:Te,createRawShellTab:be,sendToSession:De,listOpenTerminals:Fe,sendToNewTerminal:qe}),[E,O,L,z,I,F,ke,H,U,q,X,B,P,$,Y,W,he,Te,be,De,Fe,qe]),nt=_.useMemo(()=>{const Q={};for(const K of d){const ee=(K.ownerWindowId||Bt)!==Bt?"popped":K.minimized?"minimized":"floating";for(const se of un(K.root))Q[se]=ee}return Q},[d]);_.useEffect(()=>{const Q=K=>{const ne=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ee=ne?K.metaKey:K.ctrlKey,se=ne?K.ctrlKey:K.metaKey;if(!ee||se||K.altKey||K.shiftKey||K.key.toLowerCase()!=="t")return;K.preventDefault();const fe=v.current.filter(ue=>!ue.minimized&&(ue.ownerWindowId||Bt)===Bt).reduce((ue,je)=>ue&&ue.z>=je.z?ue:je,null);be((fe==null?void 0:fe.id)??null).catch(()=>{})};return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[be]);const xe=_.useMemo(()=>{const Q=new Map;for(const K of Object.values(y))Q.set(K.id,K);for(const K of s)Q.set(K.id,K);return Q},[s,y]),ie=d.filter(Q=>!Q.minimized&&(Q.ownerWindowId||Bt)===Bt),we=ie.reduce((Q,K)=>K.z>Q.z?{id:K.id,z:K.z}:Q,{id:null,z:-1/0}).id;return t.jsx(kp.Provider,{value:Qe,children:t.jsxs(V_.Provider,{value:nt,children:[m,(()=>{const Q=new Map(ie.slice().sort((K,ne)=>K.z-ne.z).map((K,ne)=>[K.id,ne+1]));return ie.map(K=>{const ne=ie.filter(ee=>ee.id!==K.id).map(({x:ee,y:se,w:ce,h:fe})=>({x:ee,y:se,w:ce,h:fe}));return t.jsx(uO,{group:K,sessionsById:xe,neighbors:ne,isTopmost:K.id===we,zIndex:Q.get(K.id)??1,sendMessage:i,subscribeBinary:a,onEvent:h},K.id)})})(),C&&C.hoveredRect&&t.jsx(gl,{targetRect:C.hoveredRect,activeZone:C.zone}),V&&t.jsx(gl,{targetRect:V.rect,activeZone:V.zone})]})})}function EO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const TO={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"},LO={floating:"bg-accent/10 text-accent",minimized:"bg-warm-200 text-warm-600",popped:"bg-violet-500/15 text-violet-500"};function DO({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}=st(),{openOrFocus:v,recallPopout:b}=Y_(),C=bO(),[S,x]=_.useState(!1),[y,w]=_.useState(!1),[k,N]=_.useState(null),[D,j]=_.useState(!1),[R,E]=_.useState(null),[L,A]=_.useState([]),[O,z]=_.useState(""),[I,F]=_.useState(null);_.useEffect(()=>{let W=!1;return Vm().then(Z=>{W||A(Z)}).catch(()=>{}),()=>{W=!0}},[]),_.useEffect(()=>{if(!a)return;let W=!1;return Iw(e).then(Z=>{W||z(Z.branch||"")}).catch(()=>{}),()=>{W=!0}},[e,a]);const H=_.useMemo(()=>{const W=new Map;for(const Z of L)W.set(Z.id,Z);return W},[L]),U=_.useMemo(()=>k?s.find(W=>W.id===k)??null:null,[k,s]),q=_.useMemo(()=>{if(U)return{title:U.title,description:U.description??"",cliTool:U.cli_tool??"",useWorktree:U.use_worktree===1,memoryInjectMode:U.memory_inject_mode??"none",memoryNodeIds:S8(U.memory_node_ids??null),memoryRawFilePaths:EO(U.memory_raw_file_paths??null),tagId:U.tag_id??null}},[U]),X=_.useCallback(()=>{N(null),E(null),x(W=>!W)},[]),B=_.useCallback(W=>{x(!1),E(null),N(W)},[]),P=_.useCallback(()=>{x(!1),N(null),E(null)},[]),$=_.useCallback(async(W,Z,he,re,J,V,pe,oe)=>{w(!0);try{const ge=await dm(e,{title:W,description:Z||void 0,cli_tool:he,use_worktree:re,memory_inject_mode:J,memory_node_ids:V,memory_raw_file_paths:pe,tag_id:oe??null});m(ge),x(!1)}finally{w(!1)}},[e,m]),Y=_.useCallback(async(W,Z,he,re,J,V,pe,oe)=>{if(k){j(!0),E(null);try{const ge=await K3(k,{title:W,description:Z||void 0,cli_tool:he,use_worktree:re,memory_inject_mode:J,memory_node_ids:V,memory_raw_file_paths:pe,tag_id:oe??null});o(ge),N(null)}catch(ge){E(ge instanceof Error?ge.message:String(ge))}finally{j(!1)}}},[k,o]);return t.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:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:u("tabs.sessions")}),t.jsxs("button",{onClick:X,className:"btn-primary text-xs py-2",disabled:y,children:["+ ",u("session.new")]})]}),S&&t.jsx(oy,{projectId:e,onSave:$,onCancel:P,projectCliTool:i,isGitRepo:a,projectUseWorktree:h}),q&&k&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(oy,{projectId:e,initial:q,onSave:Y,onCancel:P,projectCliTool:i,isGitRepo:a},k),(D||R)&&t.jsxs("div",{className:"text-xs px-1",children:[D&&t.jsx("span",{className:"text-warm-500",children:u("session.saving")||"saving…"}),R&&t.jsx("span",{className:"text-status-error",children:R})]})]}),s.length===0&&!S?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:hl,title:u("session.empty"),description:u("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((W,Z)=>{const he=["pending","failed","stopped","completed"].includes(W.status),re=W.status==="running",J=W.status!=="running",V=["stopped","failed","completed"].includes(W.status)&&(W.cli_tool??"claude")==="claude"&&!!W.worktree_path,pe=k===W.id,oe=C[W.id]??"closed",ge=oe==="popped";return t.jsx("div",{className:`card overflow-hidden animate-slide-up ${pe?"border-l-4 border-accent bg-warm-100/30":""}`,style:{animationDelay:`${Z*50}ms`},onContextMenu:le=>{hi(le)||(le.preventDefault(),le.stopPropagation(),F({x:le.clientX,y:le.clientY,sessionId:W.id}))},children:t.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>ge?b(W.id):v(W.id,"open"),children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[W.tag_id&&H.get(W.tag_id)&&t.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:[t.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:H.get(W.tag_id).color}}),H.get(W.tag_id).name]}),t.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:W.title}),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-semibold uppercase ${TO[W.status]||""}`,children:u(`status.${W.status}`)||W.status}),oe!=="closed"&&t.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium ${LO[oe]}`,title:ge?u("session.dock.poppedHint"):void 0,children:[ge&&t.jsx(li,{size:10}),u(`session.windowState.${oe}`)]})]}),W.description&&t.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:W.description}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.jsx("span",{className:"text-2xs text-warm-300",children:W.cli_tool||"claude"}),(W.branch_name||a&&(O||f))&&t.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[t.jsx(Ya,{size:12}),W.branch_name||O||f]})]})]}),t.jsxs("div",{className:"flex gap-1",onClick:le=>le.stopPropagation(),children:[ge&&t.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:t.jsx(Gi,{size:16})}),he&&t.jsx("button",{onClick:()=>v(W.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded transition-colors",title:u("session.start"),children:t.jsx(kr,{size:16})}),V&&t.jsx("button",{onClick:()=>v(W.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded transition-colors",title:u("session.resumeHint")||u("session.resume"),children:t.jsx(ui,{size:16})}),t.jsx("button",{onClick:()=>B(W.id),disabled:!J,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(J?"session.edit":"session.editDisabledRunning"),children:t.jsx(em,{size:16})}),re&&t.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:t.jsx(qi,{size:16})}),W.status!=="running"&&(!!W.worktree_path||!!W.branch_name)&&t.jsx("button",{onClick:()=>{const le=W.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",W.branch_name)):!1;p(W.id,le)},className:"p-1.5 text-warm-400 hover:text-amber-600 rounded transition-colors",title:u("session.cleanup"),children:t.jsx(mu,{size:16})}),t.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:t.jsx(jn,{size:16})})]})]})})},W.id)})}),I&&(()=>{const W=()=>F(null),Z=I.sessionId?s.find(Oe=>Oe.id===I.sessionId):void 0;if(!Z)return t.jsx(Cr,{x:I.x,y:I.y,onClose:W,children:t.jsxs("button",{type:"button",onClick:()=>{N(null),E(null),x(!0)},className:sn,children:[t.jsx(mn,{size:14}),u("session.new")]})});const he=["pending","failed","stopped","completed"].includes(Z.status),re=Z.status==="running",J=Z.status!=="running",V=["stopped","failed","completed"].includes(Z.status)&&(Z.cli_tool??"claude")==="claude"&&!!Z.worktree_path,pe=Z.status!=="running"&&(!!Z.worktree_path||!!Z.branch_name),oe=C[Z.id]??"closed",ge=oe==="popped",le=u(ge?"session.recallToMain":oe==="minimized"?"session.restoreWindow":oe==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(Cr,{x:I.x,y:I.y,onClose:W,children:[t.jsxs("button",{type:"button",onClick:()=>ge?b(Z.id):v(Z.id,"open"),className:sn,children:[ge?t.jsx(Gi,{size:14}):t.jsx(hl,{size:14}),le]}),he&&t.jsxs("button",{type:"button",onClick:()=>v(Z.id,"start"),className:sn,children:[t.jsx(kr,{size:14}),u("session.start")]}),V&&t.jsxs("button",{type:"button",onClick:()=>v(Z.id,"resume"),className:sn,title:u("session.resumeHint")||u("session.resume"),children:[t.jsx(ui,{size:14}),u("session.resume")]}),J&&t.jsxs("button",{type:"button",onClick:()=>B(Z.id),className:sn,children:[t.jsx(em,{size:14}),u("session.edit")]}),re&&t.jsxs("button",{type:"button",onClick:()=>c(Z.id),className:sn,children:[t.jsx(qi,{size:14}),u("session.stop")]}),pe&&t.jsxs("button",{type:"button",onClick:()=>{const Oe=Z.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",Z.branch_name)):!1;p(Z.id,Oe)},className:sn,children:[t.jsx(mu,{size:14}),u("session.cleanup")]}),t.jsx(S_,{}),t.jsxs("button",{type:"button",onClick:()=>d(Z.id),className:vp,children:[t.jsx(jn,{size:14}),u("session.delete")]})]})})()]})}const Du={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"}},RO=Object.keys(Du);function Fa(e){const s=Du[e]||Du.default;return`${s.bg} ${s.text}`}function jp({src:e,alt:s,onClose:i}){return _.useEffect(()=>{const a=h=>{h.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),rn.createPortal(t.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:[t.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:t.jsx(Qt,{size:18})}),t.jsx("img",{src:e,alt:s,className:"max-w-full max-h-full object-contain rounded-lg",onClick:a=>a.stopPropagation()})]}),document.body)}function Dm({anchorRef:e,width:s,onClose:i,className:a,style:h,children:f}){const m=_.useRef(null),[o,c]=_.useState(null);return _.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]),_.useEffect(()=>{const d=u=>{var b,C;const v=u.target;(b=m.current)!=null&&b.contains(v)||(C=e.current)!=null&&C.contains(v)||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?rn.createPortal(t.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...h},children:f}),document.body):null}const Ty={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"},Ly={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 MO({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:c}){var ie,we;const{t:d}=st(),[p,u]=_.useState(!1),[v,b]=_.useState(!1),[C,S]=_.useState(!1),x=_.useRef(null),y=_.useRef(null),[w,k]=_.useState({top:0,left:0}),[N,D]=_.useState(e.title),[j,R]=_.useState(e.description??""),[E,L]=_.useState(e.priority),[A,O]=_.useState(e.due_date??""),[z,I]=_.useState(e.status),[F,H]=_.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[U,q]=_.useState(""),[X,B]=_.useState(!1),[P,$]=_.useState(null),[Y,W]=_.useState(null),Z=_.useRef(null),he=_.useRef(null),[re,J]=_.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),V=_.useRef(null);_.useEffect(()=>{D(e.title),R(e.description??""),L(e.priority),O(e.due_date??""),I(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{J(e.images?JSON.parse(e.images):[])}catch{J([])}},[e]);const pe=F,oe=e.status==="moved",ge=e.due_date&&new Date(e.due_date)<new Date&&!oe&&e.status!=="done",le=_.useCallback(Q=>{a(e.id,Q)},[e.id,a]),Oe=()=>{const Q=N.trim();Q&&Q!==e.title?le({title:Q}):D(e.title)},He=()=>{const Q=j.trim();Q!==(e.description??"")&&le({description:Q||void 0})},Te=Q=>{L(Q),Q!==e.priority&&le({priority:Q})},ye=Q=>{O(Q),Q!==(e.due_date??"")&&le({due_date:Q||void 0})},ke=Q=>{const K=Q;I(K),K!==e.status&&le({status:K})},Ke=Q=>{H(Q);const K=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(Q)!==JSON.stringify(K)&&le({tags:Q.length>0?JSON.stringify(Q):void 0})},$e=Q=>{var ne;const K=Q.trim();if(K&&!F.includes(K)&&(Ke([...F,K]),!s.has(K)&&c)){const ee=["blue","green","orange","purple","pink","red","yellow","brown"],se=ee[s.size%ee.length];c(K,{color:se})}q(""),(ne=Z.current)==null||ne.focus()},be=Q=>Ke(F.filter(K=>K!==Q)),De=i.filter(Q=>!F.includes(Q)&&(!U||Q.toLowerCase().includes(U.toLowerCase()))),Fe=_.useCallback(Q=>{const K=Array.from(Q).filter(se=>se.type.startsWith("image/")),ne=[];let ee=0;for(const se of K){const ce=new FileReader;ce.onload=()=>{ne.push({name:se.name,data:ce.result}),ee++,ee===K.length&&h1(e.id,ne).then(fe=>J(fe.images))},ce.readAsDataURL(se)}},[e.id]),qe=_.useCallback(Q=>{var ee;const K=(ee=Q.clipboardData)==null?void 0:ee.items;if(!K)return;const ne=[];for(let se=0;se<K.length;se++)if(K[se].type.startsWith("image/")){const ce=K[se].getAsFile();ce&&ne.push(ce)}ne.length!==0&&(Q.preventDefault(),Fe(ne))},[Fe]),Qe=_.useCallback(Q=>{var K;Q.preventDefault(),Q.stopPropagation(),(K=Q.dataTransfer)!=null&&K.files&&Fe(Q.dataTransfer.files)},[Fe]),nt=_.useCallback(Q=>{f1(e.id,Q).then(()=>{J(K=>K.filter(ne=>ne.id!==Q))})},[e.id]),xe=_.useCallback(()=>{if(!x.current)return;const Q=x.current.getBoundingClientRect(),K=window.innerWidth,ne=window.innerHeight;let ee=Q.bottom+4;const se=y.current;if(se){const ce=se.offsetWidth,fe=se.offsetHeight;let ue=Q.right-ce;ue<8&&(ue=8),ue+ce>K-8&&(ue=K-8-ce),ee+fe>ne-8&&(ee=Q.top-fe-4),k({top:ee,left:ue}),S(!0)}else k({top:ee,left:Math.max(8,Q.right-180)})},[]);return _.useEffect(()=>{if(!p){S(!1);return}xe();const Q=requestAnimationFrame(xe),K=ne=>{var se,ce;const ee=ne.target;(se=x.current)!=null&&se.contains(ee)||(ce=y.current)!=null&&ce.contains(ee)||u(!1)};return document.addEventListener("mousedown",K),window.addEventListener("scroll",xe,!0),window.addEventListener("resize",xe),()=>{cancelAnimationFrame(Q),document.removeEventListener("mousedown",K),window.removeEventListener("scroll",xe,!0),window.removeEventListener("resize",xe)}},[p,xe]),t.jsxs("div",{className:`${oe?"opacity-50":""}`,style:{borderBottom:"1px solid var(--color-border-muted)"},children:[t.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(!v),children:[t.jsx(Ts,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${v?"rotate-90":""}`,onClick:Q=>{Q.stopPropagation(),b(!v)}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm font-medium truncate block",style:{color:"var(--color-text-primary)"},children:e.title}),oe&&e.converted_type&&t.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&&t.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:[t.jsx(dN,{size:11}),d("planner.fromDiscussion")]})]}),t.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[re.length>0&&t.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:[t.jsx($a,{size:10}),re.length]}),pe.map(Q=>t.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium whitespace-nowrap ${Fa(s.get(Q)||"default")}`,children:Q},Q))]}),t.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:t.jsx("span",{className:`text-xs font-medium ${((ie=Ly[e.priority])==null?void 0:ie.style)??"text-warm-300"}`,children:((we=Ly[e.priority])==null?void 0:we.label)??"—"})}),t.jsx("div",{className:"hidden md:block w-20 text-right flex-shrink-0",children:e.due_date?t.jsx("span",{className:`text-xs ${ge?"text-red-500 font-medium":"text-warm-500"}`,children:new Date(e.due_date).toLocaleDateString(void 0,{month:"numeric",day:"numeric"})}):t.jsx("span",{className:"text-xs text-warm-300",children:d("planner.noDueDate")})}),t.jsx("div",{className:"w-16 flex-shrink-0",children:t.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${Ty[e.status]||Ty.pending}`,children:d(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:x,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:t.jsx(Um,{size:14})}),p&&rn.createPortal(t.jsxs("div",{ref:y,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:[!oe&&t.jsxs(t.Fragment,{children:[t.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:[t.jsx(kw,{size:12})," ",d("planner.convertToTask")]}),t.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:[t.jsx(oi,{size:12})," ",d("planner.convertToSchedule")]}),t.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:[t.jsx(di,{size:12})," ",d("planner.convertToTerminal")]})]}),t.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:[t.jsx(jn,{size:12})," ",d("planner.delete")]})]}),document.body)]})]}),v&&t.jsx("div",{className:"px-4 pb-3 pt-1 ml-8 animate-fade-in",children:t.jsxs("div",{className:"rounded-lg px-4 py-3 space-y-3",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[t.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:N,onChange:Q=>D(Q.target.value),onBlur:Oe,onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),Oe(),Q.target.blur())}}),t.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:qe,onDrop:Qe,onDragOver:Q=>{Q.preventDefault(),Q.stopPropagation()},onBlur:He}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{var Q;return(Q=V.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:[t.jsx($a,{size:12}),d("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:d("plannerForm.pasteHint")})]}),t.jsx("input",{ref:V,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:Q=>{Q.target.files&&Fe(Q.target.files),Q.target.value=""}}),re.length>0&&t.jsx("div",{className:"flex flex-wrap gap-2",children:re.map(Q=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:yu(e.id,Q.id),alt:Q.originalName,onClick:()=>W(yu(e.id,Q.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>nt(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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:Q.originalName})})]},Q.id))})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(Q=>t.jsxs("div",{className:"relative",children:[t.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:K=>{he.current=K.currentTarget,$(P===Q?null:Q)},children:[Q,t.jsx("button",{onClick:K=>{K.stopPropagation(),be(Q)},className:"opacity-60 hover:opacity-100",children:t.jsx(Qt,{size:9})})]}),P===Q&&t.jsxs(Dm,{anchorRef:he,width:180,onClose:()=>$(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[t.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:d("plannerTag.color")}),t.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:RO.map(K=>t.jsx("button",{onClick:async()=>{c&&await c(Q,{color:K}),$(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(Q)===K?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:d(`plannerTag.color.${K}`),children:t.jsx("div",{className:`w-5 h-5 rounded ${Du[K].swatch}`})},K))})]})]},Q)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:Z,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:U,onChange:Q=>{q(Q.target.value),B(!0)},onKeyDown:Q=>{(Q.key==="Enter"||Q.key===",")&&U.trim()&&(Q.preventDefault(),$e(U.replace(",",""))),Q.key==="Backspace"&&!U&&F.length>0&&be(F[F.length-1])},onFocus:()=>B(!0),onBlur:()=>setTimeout(()=>B(!1),150)}),X&&De.length>0&&t.jsx(Dm,{anchorRef:Z,width:160,onClose:()=>B(!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:De.slice(0,8).map(Q=>t.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>$e(Q),children:t.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium ${Fa(s.get(Q)||"default")}`,children:Q})},Q))})]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:E,onChange:Q=>Te(Number(Q.target.value)),children:[t.jsx("option",{value:0,children:d("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:d("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:d("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:d("plannerForm.priorityCritical")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:A,onChange:Q=>ye(Q.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:z,onChange:Q=>ke(Q.target.value),children:[t.jsx("option",{value:"pending",children:d("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:d("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:d("plannerStatus.done")})]})]})]})]})}),Y&&t.jsx(jp,{src:Y,onClose:()=>W(null)})]})}let AO=0;function OO({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:h,onUpdateTag:f}){const{t:m}=st(),[o,c]=_.useState(""),[d,p]=_.useState(""),[u,v]=_.useState([]),[b,C]=_.useState(""),[S,x]=_.useState(i??""),[y,w]=_.useState(0),[k,N]=_.useState("pending"),[D,j]=_.useState(!1),[R,E]=_.useState(!1),[L,A]=_.useState([]),[O,z]=_.useState([]),[I,F]=_.useState(null),H=_.useRef(null),U=_.useRef(null),q=_.useRef(null),[X,B]=_.useState(new Map),P=new Map([...e.map(le=>[le.name,le.color]),...X]),$=["blue","green","orange","purple","pink","red","yellow","brown"];_.useEffect(()=>{var le;if(s){c(s.title),p(s.description??""),v(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),w(s.priority),N(s.status);try{z(s.images?JSON.parse(s.images):[])}catch{z([])}}(le=H.current)==null||le.focus()},[s]);const Y=e.filter(le=>!u.includes(le.name)&&(!b||le.name.toLowerCase().includes(b.toLowerCase()))),W=le=>{var He;const Oe=le.trim();Oe&&!u.includes(Oe)&&v(Te=>{const ye=[...Te,Oe];if(!P.has(Oe)){const ke=$[P.size%$.length];B(Ke=>new Map([...Ke,[Oe,ke]]))}return ye}),C(""),E(!0),(He=U.current)==null||He.focus()},Z=le=>v(u.filter(Oe=>Oe!==le)),he=_.useCallback(le=>{const Oe=Array.from(le).filter(He=>He.type.startsWith("image/"));for(const He of Oe){const Te=new FileReader;Te.onload=()=>{const ye=Te.result,ke=`pending-${++AO}`;A(Ke=>[...Ke,{id:ke,name:He.name,data:ye,preview:ye}])},Te.readAsDataURL(He)}},[]),re=_.useCallback(le=>{var Te;const Oe=(Te=le.clipboardData)==null?void 0:Te.items;if(!Oe)return;const He=[];for(let ye=0;ye<Oe.length;ye++)if(Oe[ye].type.startsWith("image/")){const ke=Oe[ye].getAsFile();ke&&He.push(ke)}He.length!==0&&(le.preventDefault(),he(He))},[he]),J=_.useCallback(le=>{var Oe;le.preventDefault(),le.stopPropagation(),(Oe=le.dataTransfer)!=null&&Oe.files&&he(le.dataTransfer.files)},[he]),V=le=>A(Oe=>Oe.filter(He=>He.id!==le)),pe=le=>{s&&f1(s.id,le),z(Oe=>Oe.filter(He=>He.id!==le))},oe=O.length+L.length,ge=async()=>{if(o.trim()){j(!0);try{const le=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:y,...s?{status:k}:{}});if(f&&X.size>0&&await Promise.all([...X.entries()].map(([Oe,He])=>f(Oe,{color:He}))),L.length>0){const Oe=(s==null?void 0:s.id)??(le==null?void 0:le.id);Oe&&await h1(Oe,L.map(He=>({name:He.name,data:He.data})))}}finally{j(!1)}}};return t.jsxs("div",{className:"card p-5 animate-slide-up",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[t.jsx("input",{ref:H,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:le=>c(le.target.value),onKeyDown:le=>{le.key==="Enter"&&le.preventDefault()}}),t.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:le=>p(le.target.value),onPaste:re,onDrop:J,onDragOver:le=>{le.preventDefault(),le.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var le;return(le=q.current)==null?void 0:le.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:[t.jsx($a,{size:14}),m("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),t.jsx("input",{ref:q,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:le=>{le.target.files&&he(le.target.files),le.target.value=""}}),oe>0&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:m("plannerForm.images")}),t.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",oe,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[O.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?yu(s.id,le.id):"",alt:le.originalName,onClick:()=>s&&F(yu(s.id,le.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>pe(le.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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:le.originalName})})]},le.id)),L.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:le.preview,alt:le.name,onClick:()=>F(le.preview),className:"h-20 w-20 object-cover rounded-lg border border-blue-300/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>V(le.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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:le.name})})]},le.id))]})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.tags")}),t.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(le=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-medium ${Fa(P.get(le)||"default")}`,children:[le,t.jsx("button",{onClick:()=>Z(le),className:"opacity-60 hover:opacity-100",children:t.jsx(Qt,{size:10})})]},le)),t.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[t.jsx("input",{ref:U,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:le=>{C(le.target.value),E(!0)},onKeyDown:le=>{(le.key==="Enter"||le.key===",")&&b.trim()&&(le.preventDefault(),W(b.replace(",",""))),le.key==="Backspace"&&!b&&u.length>0&&Z(u[u.length-1])},onFocus:()=>E(!0),onBlur:()=>setTimeout(()=>E(!1),150)}),R&&(Y.length>0||b.trim())&&t.jsxs(Dm,{anchorRef:U,width:208,onClose:()=>E(!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:[Y.slice(0,10).map(le=>t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>W(le.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded text-[11px] font-medium ${Fa(le.color)}`,children:le.name})},le.name)),b.trim()&&!e.some(le=>le.name===b.trim())&&t.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:t.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',b.trim(),'"']})})]})]})]})]}),t.jsxs("div",{className:`grid gap-3 mb-4 ${s?"grid-cols-3":"grid-cols-2"}`,children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full",value:S,onChange:le=>x(le.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:le=>w(Number(le.target.value)),children:[t.jsx("option",{value:0,children:m("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:m("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:m("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:m("plannerForm.priorityCritical")})]})]}),s&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full",value:k,onChange:le=>N(le.target.value),children:[t.jsx("option",{value:"pending",children:m("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:m("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:m("plannerStatus.done")})]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:m("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:ge,disabled:!o.trim()||D,children:m("plannerForm.save")})]}),I&&t.jsx(jp,{src:I,onClose:()=>F(null)})]})}function Z_({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:h}){const{t:f}=st(),[m,o]=_.useState(i||"claude"),[c,d]=_.useState(""),[p,u]=_.useState(!1),[v,b]=_.useState("once"),[C,S]=_.useState("0 0 * * *"),[x,y]=_.useState(""),[w,k]=_.useState(!1),N=async()=>{k(!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:v,cron_expression:v==="recurring"?C:void 0,run_at:v==="once"?x:void 0})}finally{k(!1)}};return t.jsx($n,{open:!0,onClose:h,size:"md",position:"top",animation:"slide-up",children:t.jsxs("div",{className:"card p-6",children:[t.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")}),t.jsxs("p",{className:"text-xs text-warm-500 mb-4 truncate",children:['"',e.title,'"']}),t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cliTool")}),t.jsxs("select",{className:"input-field text-xs w-full",value:m,onChange:D=>o(D.target.value),children:[t.jsx("option",{value:"claude",children:"Claude"}),t.jsx("option",{value:"antigravity",children:"Antigravity"}),t.jsx("option",{value:"codex",children:"Codex"})]})]}),s==="todo"&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.maxTurns")}),t.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:c,onChange:D=>d(D.target.value)})]}),s==="session"&&t.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:D=>u(D.target.checked)}),t.jsx("span",{className:"text-xs font-medium text-warm-500",children:f("plannerConvert.useWorktree")})]}),s==="schedule"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.scheduleType")}),t.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${v==="once"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("once"),children:f("plannerConvert.once")}),t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${v==="recurring"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("recurring"),children:f("plannerConvert.recurring")})]})]}),v==="once"?t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.runAt")}),t.jsx("input",{type:"datetime-local",className:"input-field text-xs w-full",value:x,onChange:D=>y(D.target.value)})]}):t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cronExpression")}),t.jsx("input",{className:"input-field text-xs w-full font-mono",value:C,onChange:D=>S(D.target.value),placeholder:"0 0 * * *"})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:f("plannerConvert.cancel")}),t.jsx("button",{className:"btn-primary btn-sm",onClick:N,disabled:w||s==="schedule"&&v==="once"&&!x,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 Dy(e){return hn(new Date(e))}function Ry(e){return new Date(e.getFullYear(),e.getMonth(),1)}function eS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function yr(e,s){const i=eS(e);return i.setDate(i.getDate()+s),i}function tS(e){return yr(e,-e.getDay())}function zO(e,s){if(e==="day"){const f=eS(s);return{rangeStart:hn(f),rangeEnd:hn(yr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=tS(s),m=Array.from({length:7},(o,c)=>yr(f,c));return{rangeStart:hn(f),rangeEnd:hn(yr(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=Ry(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:hn(f),rangeEnd:hn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=Ry(s),a=yr(i,-i.getDay()),h=Array.from({length:42},(f,m)=>yr(a,m));return{rangeStart:hn(a),rangeEnd:hn(yr(a,42)),gridDays:h,cols:7,dimOutOfMonth:!0}}function nS(e,s){return _.useMemo(()=>zO(e,s),[e,s])}function sS(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 rS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=tS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${yr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function iS(){const{lang:e}=st();return _.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>yr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const PO=420,BO=140,IO=220,HO=26,$f=16,My=2;function FO(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 aS({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:v,onSelectDate:b,onQuickAdd:C,onChipClick:S,onCellContextMenu:x,onChipContextMenu:y,onBarContextMenu:w,monthCellHeight:k=92}){const{lang:N}=st(),[D,j]=_.useState(null),[R,E]=_.useState(!1),L=_.useRef(null),A=_.useRef(null),O=()=>{A.current&&(clearTimeout(A.current),A.current=null)},z=(q,X)=>{O(),L.current&&clearTimeout(L.current);const B=X.getBoundingClientRect();L.current=window.setTimeout(()=>j({key:q,rect:B}),PO)},I=()=>{L.current&&(clearTimeout(L.current),L.current=null),A.current=window.setTimeout(()=>j(null),BO)};_.useEffect(()=>{if(!D){E(!1);return}const q=requestAnimationFrame(()=>E(!0));return()=>cancelAnimationFrame(q)},[D]),_.useEffect(()=>()=>{L.current&&clearTimeout(L.current),A.current&&clearTimeout(A.current)},[]),_.useEffect(()=>{if(!D)return;const q=()=>j(null);return window.addEventListener("scroll",q,!0),window.addEventListener("resize",q),()=>{window.removeEventListener("scroll",q,!0),window.removeEventListener("resize",q)}},[D]);const F=D?o.get(D.key)??[]:[],H=(q,X)=>{const B=hn(q),P=o.get(B)??[],$=!a||q.getMonth()===h,Y=B===f,W=B===m,Z=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",he=e==="month"&&P.length>c;return t.jsxs("div",{onClick:()=>b(B),onContextMenu:x?re=>x(B,re):void 0,onMouseEnter:he?re=>z(B,re.currentTarget):void 0,onMouseLeave:he?I:void 0,className:`group relative ${Z} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?k+X:void 0,backgroundColor:W?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:$?1:.45},children:[t.jsxs("span",{className:"flex items-center gap-1.5",children:[e!=="month"&&t.jsx("span",{className:"text-2xs uppercase",style:{color:"var(--color-text-muted)"},children:q.toLocaleDateString(N,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:Y?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:q.getDate()})]}),t.jsx("button",{onClick:re=>{re.stopPropagation(),C(B)},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:t.jsx(mn,{size:13})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:X||void 0},children:[P.slice(0,c).map(re=>t.jsxs("span",{onClick:J=>{J.stopPropagation(),S(re)},onContextMenu:y?J=>y(re,J):void 0,className:"text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:re.bg,color:re.fg,textDecoration:re.done?"line-through":"none"},title:re.title,children:[re.prefix??"",re.time?`${re.time} `:"",re.title]},re.key)),P.length>c&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",P.length-c]})]})]},B)},U=[];if(e==="month")for(let q=0;q<s.length;q+=i)U.push(s.slice(q,q+i));return t.jsxs(t.Fragment,{children:[(e==="month"||e==="week")&&t.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(q=>t.jsx("div",{className:"px-2 py-1",children:q},q))}),e==="month"?t.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:U.map((q,X)=>{const{placed:B,laneCount:P}=FO(q,u??[]),$=P*($f+My);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[q.map(Y=>H(Y,$)),B.map(({bar:Y,startCol:W,endCol:Z,lane:he,contStart:re,contEnd:J})=>t.jsxs("div",{onClick:V=>{V.stopPropagation(),v==null||v(Y)},onContextMenu:w?V=>w(Y,V):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{left:`calc(${W} / ${i} * 100% + 2px)`,width:`calc(${Z-W+1} / ${i} * 100% - 4px)`,top:HO+he*($f+My),height:$f,backgroundColor:Y.bg,color:Y.fg,textDecoration:Y.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:re?0:4,borderBottomLeftRadius:re?0:4,borderTopRightRadius:J?0:4,borderBottomRightRadius:J?0:4},title:Y.title,children:[re?"◀ ":"",Y.title,J?" ▶":""]},Y.key))]},X)})}):t.jsx("div",{className:"grid gap-px rounded-xl overflow-hidden",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:s.map(q=>H(q,0))}),D&&(()=>{const q=Math.max(D.rect.width,IO),X=Math.min(Math.max(8,D.rect.left),window.innerWidth-q-8),B=Math.max(8,Math.min(D.rect.top,window.innerHeight-120)),P=window.innerHeight-B-16,$=Number(D.key.slice(8,10));return rn.createPortal(t.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:O,onMouseLeave:()=>j(null),style:{position:"fixed",left:X,top:B,width:q,maxHeight:P,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:R?"scale(1)":"scale(0.96)",opacity:R?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[t.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:$}),t.jsx("div",{className:"flex flex-col gap-0.5",children:F.map(Y=>t.jsxs("span",{onClick:W=>{W.stopPropagation(),S(Y),j(null)},onContextMenu:y?W=>y(Y,W):void 0,className:"text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:Y.bg,color:Y.fg,textDecoration:Y.done?"line-through":"none"},title:Y.title,children:[Y.prefix??"",Y.time?`${Y.time} `:"",Y.title]},Y.key))})]}),document.body)})()]})}const Ay={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 $O(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function UO({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:h,onConvert:f,onDeleteItem:m}){const{t:o,lang:c}=st(),[d,p]=_.useState(()=>new Date),[u,v]=_.useState(()=>hn(new Date)),[b,C]=_.useState(null),S=iS(),{gridDays:x,cols:y,dimOutOfMonth:w}=nS(e,d),k=hn(new Date),N=d.getMonth(),D=e==="month"?3:99,j=X=>p(B=>sS(B,e,X)),R=()=>{p(new Date),v(hn(new Date))},E=rS(d,e,c);_.useEffect(()=>{e==="day"&&v(hn(d))},[e,d]);const L=260,A=760,O=_.useRef(null),[z,I]=_.useState(()=>{const X=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(X)&&X>=L&&X<=A?X:320});_.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(z))}catch{}},[z]);const F=X=>{X.preventDefault();const B=$=>{var W;const Y=(W=O.current)==null?void 0:W.getBoundingClientRect();Y&&I(Math.min(A,Math.max(L,Y.right-$.clientX)))},P=()=>{window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",P),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",B),window.addEventListener("pointerup",P)},H=_.useMemo(()=>{const X=new Map;for(const B of s){if(!B.due_date)continue;const P=B.due_date.slice(0,10),$=B.status==="done",Y=X.get(P)??[];Y.push({key:B.id,title:B.title,bg:"var(--color-bg-secondary)",fg:$?"var(--color-text-muted)":"var(--color-text-secondary)",done:$,payload:B}),X.set(P,Y)}return X},[s]),U=_.useMemo(()=>s.filter(X=>X.due_date&&X.due_date.slice(0,10)===u),[s,u]),q=_.useMemo(()=>s.filter(X=>!X.due_date),[s]);return t.jsxs("div",{ref:O,className:"card flex overflow-hidden",style:{minHeight:520},children:[t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[t.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>j(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(Fm,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:E}),t.jsx("button",{onClick:()=>j(1),className:"btn-ghost p-1.5","aria-label":"next",children:t.jsx(Ts,{size:16})}),t.jsx("button",{onClick:R,className:"btn-ghost text-xs px-2.5 py-1.5",children:o("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(aS,{view:e,gridDays:x,cols:y,dimOutOfMonth:w,monthIdx:N,todayKey:k,selectedDate:u,chipsByDay:H,maxChips:D,weekdayLabels:S,addItemLabel:o("agenda.addItem"),onSelectDate:v,onQuickAdd:a,onChipClick:X=>h(X.payload),onCellContextMenu:(X,B)=>{B.preventDefault(),C({x:B.clientX,y:B.clientY,dateKey:X})}})})]}),t.jsx("div",{onPointerDown:F,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:o("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:z},children:[t.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center justify-between",children:[t.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--color-text-primary)"},children:new Date(u+"T00:00").toLocaleDateString(c,{month:"long",day:"numeric",weekday:"short"})}),t.jsxs("button",{onClick:()=>a(u),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[t.jsx(mn,{size:13}),o("agenda.add")]})]}),t.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[U.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:o("agenda.dayEmpty")}),U.map(X=>t.jsx(Oy,{item:X,tagColors:i,onEdit:h,onConvert:f,onDelete:m},X.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:o("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[q.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:o("agenda.backlogEmpty")}),q.map(X=>t.jsx(Oy,{item:X,tagColors:i,onEdit:h,onConvert:f,onDelete:m},X.id))]})]})]})]}),b&&t.jsx(Cr,{x:b.x,y:b.y,onClose:()=>C(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>a(b.dateKey),children:[t.jsx(mn,{size:14}),o("planner.add")]})})]})}function Oy({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:h}){const{t:f}=st(),[m,o]=_.useState(!1),[c,d]=_.useState(!1),[p,u]=_.useState({top:0,left:0}),v=_.useRef(null),b=_.useRef(null),C=$O(e.tags),S=e.status==="moved",x=_.useCallback(()=>{if(!v.current)return;const y=v.current.getBoundingClientRect(),w=window.innerWidth,k=window.innerHeight;let N=y.bottom+4;const D=b.current;if(D){const j=D.offsetWidth,R=D.offsetHeight;let E=y.right-j;E<8&&(E=8),E+j>w-8&&(E=w-8-j),N+R>k-8&&(N=y.top-R-4),u({top:N,left:E}),d(!0)}else u({top:N,left:Math.max(8,y.right-180)})},[]);return _.useEffect(()=>{if(!m){d(!1);return}x();const y=requestAnimationFrame(x),w=k=>{var D,j;const N=k.target;(D=v.current)!=null&&D.contains(N)||(j=b.current)!=null&&j.contains(N)||o(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{cancelAnimationFrame(y),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[m,x]),t.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:[t.jsxs("button",{onClick:()=>i(e),className:"flex-1 text-left min-w-0",children:[t.jsx("div",{className:"text-sm truncate",style:{color:"var(--color-text-primary)",textDecoration:e.status==="done"?"line-through":"none"},children:e.title}),e.description&&t.jsx("div",{className:"text-2xs truncate",style:{color:"var(--color-text-muted)"},children:e.description}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[t.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-2xs font-medium ${Ay[e.status]||Ay.pending}`,children:f(`plannerStatus.${e.status}`)}),C.map(y=>t.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-medium ${Fa(s.get(y)||"default")}`,children:y},y))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:v,onClick:y=>{y.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:t.jsx(Um,{size:14})}),m&&rn.createPortal(t.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&&t.jsxs(t.Fragment,{children:[t.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:[t.jsx(kw,{size:12})," ",f("planner.convertToTask")]}),t.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:[t.jsx(oi,{size:12})," ",f("planner.convertToSchedule")]}),t.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:[t.jsx(di,{size:12})," ",f("planner.convertToTerminal")]})]}),t.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:[t.jsx(jn,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const zy={pending:0,in_progress:1,done:2,moved:3};function WO({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:v,view:b,onChangeView:C}){const{t:S}=st(),[x,y]=_.useState(!1),[w,k]=_.useState(null),[N,D]=_.useState(void 0),[j,R]=_.useState(""),[E,L]=_.useState(""),[A,O]=_.useState("created_at"),[z,I]=_.useState("desc"),[F,H]=_.useState(null),[U,q]=_.useState("todo"),[X,B]=_.useState(!1),[P,$]=_.useState(!1),[Y,W]=_.useState(null),Z=_.useRef(null),he=_.useRef(0),re=async()=>{if(!(!u||X)){B(!0);try{await u()}finally{B(!1)}}},J=()=>{var be;!v||X||(be=Z.current)==null||be.click()},V=async be=>{var Fe;const De=(Fe=be.target.files)==null?void 0:Fe[0];if(be.target.value="",!(!De||!v)){B(!0);try{await v(De)}finally{B(!1)}}},pe=be=>!!(/\.(md|markdown)$/i.test(be.name)||be.type==="text/markdown"),oe=be=>Array.from(be.dataTransfer.types).includes("Files"),ge=be=>{!v||X||oe(be)&&(be.preventDefault(),he.current++,$(!0))},le=be=>{!v||X||oe(be)&&(be.preventDefault(),be.dataTransfer.dropEffect="copy")},Oe=be=>{v&&(be.preventDefault(),he.current=Math.max(0,he.current-1),he.current===0&&$(!1))},He=async be=>{var Fe;if(!v||(be.preventDefault(),he.current=0,$(!1),X))return;const De=(Fe=be.dataTransfer.files)==null?void 0:Fe[0];if(De){if(!pe(De)){window.alert(S("planner.dropInvalidFile"));return}B(!0);try{await v(De)}finally{B(!1)}}},Te=_.useMemo(()=>s.map(be=>be.name),[s]),ye=_.useMemo(()=>new Map(s.map(be=>[be.name,be.color])),[s]),ke=_.useMemo(()=>{let be=e.filter(De=>!(E&&De.status!==E||j&&!(De.tags?(()=>{try{return JSON.parse(De.tags)}catch{return[]}})():[]).includes(j)));return be=[...be].sort((De,Fe)=>{let qe=0;switch(A){case"title":qe=De.title.localeCompare(Fe.title);break;case"tags":{const Qe=De.tags?(()=>{try{return JSON.parse(De.tags).join(",")}catch{return""}})():"",nt=Fe.tags?(()=>{try{return JSON.parse(Fe.tags).join(",")}catch{return""}})():"";qe=(Qe||"zzz").localeCompare(nt||"zzz");break}case"priority":qe=De.priority-Fe.priority;break;case"due_date":{const Qe=De.due_date||"9999",nt=Fe.due_date||"9999";qe=Qe.localeCompare(nt);break}case"status":qe=(zy[De.status]??9)-(zy[Fe.status]??9);break;case"created_at":qe=De.created_at.localeCompare(Fe.created_at);break}return z==="asc"?qe:-qe}),be},[e,j,E,A,z]),Ke=be=>{A===be?I(De=>De==="asc"?"desc":"asc"):(O(be),I(be==="priority"?"desc":"asc"))},$e=({field:be})=>A!==be?null:z==="asc"?t.jsx(Nj,{size:10,className:"inline ml-0.5"}):t.jsx(_j,{size:10,className:"inline ml-0.5"});return t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-5 gap-3 flex-wrap",children:[t.jsxs("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:[S("planner.title"),t.jsx("span",{className:"ml-1 text-warm-400",children:e.length})]}),t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b!=="table"&&t.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(be=>t.jsx("button",{onClick:()=>C(be),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:b===be?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:S(`agenda.view.${be}`)},be))}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:j,onChange:be=>R(be.target.value),children:[t.jsx("option",{value:"",children:S("planner.filterTag")}),Te.map(be=>t.jsx("option",{value:be,children:be},be))]}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:E,onChange:be=>L(be.target.value),children:[t.jsx("option",{value:"",children:S("planner.filterStatus")}),t.jsx("option",{value:"pending",children:S("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:S("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:S("plannerStatus.done")}),t.jsx("option",{value:"moved",children:S("plannerStatus.moved")})]}),u&&t.jsxs("button",{onClick:re,disabled:X||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.exportTooltip"),children:[t.jsx(Qf,{size:14,className:"inline-block shrink-0"}),S("planner.export")]}),v&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:J,disabled:X,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.importTooltip"),children:[t.jsx(Ov,{size:14,className:"inline-block shrink-0"}),S("planner.import")]}),t.jsx("input",{ref:Z,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:V})]}),!x&&!w&&t.jsxs("button",{onClick:()=>y(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(mn,{size:14,className:"inline-block shrink-0"}),S("planner.add")]})]})]}),(x||w)&&t.jsx("div",{className:"mb-5",children:t.jsx(OO,{existingTags:s,editItem:w,initialDueDate:N,onSave:async be=>{if(w){await h(w.id,be),k(null);return}else{const De=await a(be);return y(!1),D(void 0),De}},onCancel:()=>{y(!1),k(null),D(void 0)},onUpdateTag:d})}),b==="table"?t.jsxs("div",{className:"card relative",onDragEnter:v?ge:void 0,onDragOver:v?le:void 0,onDragLeave:v?Oe:void 0,onDrop:v?He:void 0,onContextMenu:be=>{hi(be)||(be.preventDefault(),W({x:be.clientX,y:be.clientY}))},children:[P&&t.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:t.jsxs("div",{className:"text-center",children:[t.jsx(Ov,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),t.jsx("div",{className:"text-sm font-semibold",children:S("planner.dropHint")}),t.jsx("div",{className:"text-xs text-warm-500 mt-1",children:S("planner.dropHintSub")})]})}),t.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:[t.jsx("div",{className:"w-[14px] flex-shrink-0"}),t.jsxs("div",{className:"flex-1 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>Ke("title"),children:[S("planner.col.title"),t.jsx($e,{field:"title"})]}),t.jsxs("div",{className:"w-[160px] text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>Ke("tags"),children:[S("planner.col.tags"),t.jsx($e,{field:"tags"})]}),t.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:()=>Ke("priority"),children:[S("plannerForm.priority"),t.jsx($e,{field:"priority"})]}),t.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:()=>Ke("due_date"),children:[S("planner.col.dueDate"),t.jsx($e,{field:"due_date"})]}),t.jsxs("div",{className:"w-16 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>Ke("status"),children:[S("planner.col.status"),t.jsx($e,{field:"status"})]}),t.jsx("div",{className:"w-8"})]}),ke.length===0?t.jsx(Yi,{icon:J5,title:S("planner.empty"),description:S("planner.emptyHint")}):ke.map((be,De)=>t.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${De*20}ms`},children:t.jsx(MO,{item:be,tagColors:ye,existingTags:Te,onSave:async(Fe,qe)=>{await h(Fe,qe)},onDelete:()=>f(be.id),onConvertToTodo:()=>{H(be),q("todo")},onConvertToSchedule:()=>{H(be),q("schedule")},onConvertToSession:()=>{H(be),q("session")},onUpdateTag:d})},be.id))]}):t.jsx(UO,{view:b,items:ke,tagColors:ye,onQuickAdd:be=>{k(null),D(be),y(!0)},onEditItem:be=>{y(!1),k(be)},onConvert:(be,De)=>{H(be),q(De)},onDeleteItem:f}),F&&t.jsx(Z_,{item:F,mode:U,projectCliTool:i,onConvert:async be=>{U==="todo"?await m(F.id,be):U==="session"?await c(F.id,be):await o(F.id,be),H(null)},onClose:()=>H(null)}),Y&&t.jsx(Cr,{x:Y.x,y:Y.y,onClose:()=>W(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>{k(null),D(void 0),y(!0)},children:[t.jsx(mn,{size:14}),S("planner.add")]})})]})}const oS=_.createContext(null),GO=oS.Provider;function tB(){const e=_.useContext(oS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const qO=_.lazy(()=>Fu(()=>import("./PlannerPageEditor-BUVPANE-.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),KO=800;function VO({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:c}=st(),[d,p]=_.useState(null),[u,v]=_.useState("idle"),[b,C]=_.useState(null),S=_.useRef({title:"",content:null}),x=_.useRef(null);_.useEffect(()=>{let j=!1;return l4(e).then(R=>{j||(p(R),S.current={title:R.title,content:R.content??null})}),()=>{j=!0}},[e]);const y=_.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:j,content:R}=S.current;return v("saving"),c4(e,{title:j,content:R??void 0}).then(()=>v("saved"))},[e]);_.useEffect(()=>()=>{x.current&&y()},[y]);const w=_.useCallback(()=>{x.current&&clearTimeout(x.current),v("saving"),x.current=setTimeout(()=>{y()},KO)},[y]),k=j=>{S.current.title=j,p(R=>R&&{...R,title:j}),h(e,j),w()},N=j=>{S.current.content=j,w()},D=_.useCallback((j,R,E)=>{C({item:j,mode:R,onDone:E})},[]);return d?t.jsxs(GO,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:D},children:[t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[t.jsx("input",{value:d.title,onChange:j=>k(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)"}}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:u==="saving"?c("planner.pages.saving"):u==="saved"?c("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(_.Suspense,{fallback:null,children:t.jsx(qO,{initialContent:d.content??null,onChange:N})})})]}),b&&t.jsx(Z_,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:R,mode:E,onDone:L}=b;E==="todo"?await f(R.id,j):E==="session"?await o(R.id,j):await m(R.id,j),L==null||L(),C(null)},onClose:()=>C(null)})]}):null}const kn=(e,s)=>({type:"heading",props:{level:e},content:s}),Jo=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},Py=e=>({type:"bulletListItem"}),Bi=e=>({type:"checkListItem"}),By=()=>({type:"tasklist"}),Iy=()=>({type:"calendar"}),YO=[{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:[kn(1,"회의 노트"),Jo("📅 날짜: "),Jo("👥 참석자: "),kn(2,"안건"),Py(),kn(2,"논의"),Jo(),kn(2,"액션 아이템"),By()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[kn(1,"프로젝트 플랜"),kn(2,"개요"),Jo(),kn(2,"마일스톤"),By(),kn(2,"일정"),Iy(),kn(2,"리스크 / 메모"),Jo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[kn(1,"위클리 플래너"),kn(2,"이번 주 목표"),Py(),kn(2,"요일별 할 일"),kn(3,"월요일"),Bi(),kn(3,"화요일"),Bi(),kn(3,"수요일"),Bi(),kn(3,"목요일"),Bi(),kn(3,"금요일"),Bi(),kn(3,"토요일"),Bi(),kn(3,"일요일"),Bi(),kn(2,"주간 일정"),Iy()]}];function XO({onResize:e}){return t.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 Hy=160,Fy=480,$y="plannerSidebarWidth";function JO({projectId:e,...s}){const{t:i}=st(),[a,h]=_.useState([]),[f,m]=_.useState({kind:"work"}),[o,c]=_.useState("table"),[d,p]=_.useState(!1),[u,v]=_.useState({top:0,left:0}),b=_.useRef(null),C=_.useRef(null),S=_.useRef(!1),[x,y]=_.useState(()=>{const F=Number(localStorage.getItem($y));return F>=Hy&&F<=Fy?F:208}),w=_.useCallback(F=>{var q;const H=((q=C.current)==null?void 0:q.getBoundingClientRect().left)??0,U=Math.round(Math.max(Hy,Math.min(Fy,F-H)));y(U),localStorage.setItem($y,String(U))},[]),k=240,N=()=>{var H;const F=(H=b.current)==null?void 0:H.getBoundingClientRect();if(F){const U=Math.min(F.left,window.innerWidth-k-8);v({top:F.bottom+4,left:Math.max(8,U)})}p(!0)};_.useEffect(()=>{if(!d)return;const F=()=>p(!1),H=U=>{var q;(q=b.current)!=null&&q.contains(U.target)||U.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]),_.useEffect(()=>{a4(e).then(F=>{h(F),S.current||(S.current=!0,F.length>0&&m({kind:"page",id:F[0].id}))})},[e]);const D=async F=>{p(!1);const H=await o4(e,F.title||i("planner.pages.untitled"),F.blocks?JSON.stringify(F.blocks):void 0);h(U=>[...U,H]),m({kind:"page",id:H.id})},j=async F=>{confirm(i("planner.pages.deleteConfirm"))&&(await u4(F),h(H=>H.filter(U=>U.id!==F)),m(H=>H.kind==="page"&&H.id===F?{kind:"work"}:H))},R=_.useCallback((F,H)=>{h(U=>U.map(q=>q.id===F?{...q,title:H}:q))},[]),E=()=>{m({kind:"work"}),c(F=>F==="table"?"month":F)},L=()=>{m({kind:"work"}),c("table")},A=f.kind==="work",O=A&&o!=="table",z=A&&o==="table",I=(F,H,U,q,X)=>t.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:[U,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:q}),X]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[t.jsxs("div",{ref:C,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:x},children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),t.jsx("button",{ref:b,onClick:()=>d?p(!1):N(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(mn,{size:14})})]}),a.map(F=>I(f.kind==="page"&&f.id===F.id,()=>m({kind:"page",id:F.id}),t.jsx(Ui,{size:13,className:"text-warm-400 flex-shrink-0"}),F.title||i("planner.pages.untitled"),t.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:t.jsx(jn,{size:13})}))),t.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")}),I(O,E,t.jsx(Jf,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),I(z,L,t.jsx(gu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(XO,{onResize:w}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:f.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(VO,{pageId:f.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:R,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},f.id)}):t.jsx(WO,{...s,view:o,onChangeView:c})}),d&&rn.createPortal(t.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:k,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:YO.map(F=>t.jsxs("button",{onClick:()=>D(F),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[t.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:i(F.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(F.descKey)})]},F.id))}),document.body)]})}const QO=_.lazy(()=>Fu(()=>import("./AnalyticsPanel-Tra_CsK-.js"),__vite__mapDeps([9,7,3,2]))),ZO=_.lazy(()=>Fu(()=>import("./VaultLayout-Cx2o5uSE.js"),__vite__mapDeps([10,6,1,2,3,4])));function ez({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:h}=Om(),[f,m]=_.useState(null),[o,c]=_.useState([]),[d,p]=_.useState([]),[u,v]=_.useState(null),[b,C]=_.useState([]),[S,x]=_.useState([]),[y,w]=_.useState([]),[k,N]=_.useState([]),[D,j]=ww(),R=["tasks","discussions","schedules","analytics"],E=D.get("tab")||"tasks",[L,A]=_.useState(R.includes(E)?"automation":E),[O,z]=_.useState(R.includes(E)?E:"tasks"),I=_.useCallback(de=>{if(de==="automation"){A("automation"),j(O==="tasks"?{}:{tab:O},{replace:!0});return}A(de),j(de==="tasks"?{}:{tab:de},{replace:!0})},[j,O]),F=_.useCallback(de=>{A("automation"),z(de),j(de==="tasks"?{}:{tab:de},{replace:!0})},[j]),[H,U]=_.useState(!0),[q,X]=_.useState(!1),[B,P]=_.useState(new Set),[$,Y]=_.useState(0),{t:W}=st(),{sendNotification:Z}=Km(),he=_.useRef([]);_.useEffect(()=>{he.current=b},[b]),_.useEffect(()=>{h&&Promise.all([sE(h),ff(h),Zv(h),eb(h),D3(),c1(h),Hc(h),Fc(h)]).then(([de,Re,Ee,ve,at,vt,Ct,Tt])=>{m(de),c(Re),p(Ee),C(ve),x(vt),w(Ct),N(Tt),at.resetsAt&&v(at.resetsAt);const Nt=Re.filter(Ft=>Ft.status==="running"&&Ft.execution_mode==="interactive").map(Ft=>Ft.id);Nt.length>0&&P(new Set(Nt))}).catch(()=>X(!0)).finally(()=>U(!1))},[h]);const re=_.useRef(o);re.current=o,_.useEffect(()=>{if(!h)return;const de=setInterval(()=>{re.current.some(Ee=>Ee.status==="running")&&ff(h).then(Ee=>{c(ve=>ve.map(at=>{const vt=Ee.find(Ct=>Ct.id===at.id);return vt&&vt.status!==at.status?vt:at}))}).catch(()=>{})},5e3);return()=>clearInterval(de)},[h]);const J=_.useRef(s);_.useEffect(()=>{s&&!J.current&&h&&Promise.all([ff(h),Zv(h),eb(h)]).then(([de,Re,Ee])=>{c(de),p(Re),C(Ee)}).catch(()=>{}),J.current=s},[s,h]),_.useEffect(()=>e(de=>{if(de.type==="todo:status-changed"&&de.todoId&&de.status){if(c(Re=>Re.map(Ee=>{if(Ee.id!==de.todoId)return Ee;const ve={status:de.status,updated_at:new Date().toISOString()};return de.worktree_path!==void 0&&(ve.worktree_path=de.worktree_path??null),de.branch_name!==void 0&&(ve.branch_name=de.branch_name??null),{...Ee,...ve}})),(de.status==="completed"||de.status==="merged"||de.status==="failed")&&Y(Re=>Re+1),de.status==="completed"||de.status==="failed"){const Re=re.current.find(Ee=>Ee.id===de.todoId);Re&&Z(de.status==="completed"?W("notification.taskCompleted"):W("notification.taskFailed"),Re.title)}de.status==="running"&&de.mode==="interactive"?P(Re=>new Set(Re).add(de.todoId)):de.status!=="running"&&P(Re=>{const Ee=new Set(Re);return Ee.delete(de.todoId),Ee})}if(de.type==="schedule:status-changed"&&de.scheduleId&&p(Re=>Re.map(Ee=>Ee.id===de.scheduleId?{...Ee,is_active:de.isActive?1:0,updated_at:new Date().toISOString()}:Ee)),de.type==="rate-limit:updated"&&de.resetsAt&&v(de.resetsAt),de.type==="discussion:status-changed"&&de.discussionId&&(C(Re=>Re.map(Ee=>Ee.id===de.discussionId?{...Ee,status:de.status,current_round:de.currentRound??Ee.current_round,updated_at:new Date().toISOString()}:Ee)),de.status==="completed"||de.status==="failed")){const Re=he.current.find(Ee=>Ee.id===de.discussionId);Re&&Z(de.status==="completed"?W("notification.discussionCompleted"):W("notification.discussionFailed"),Re.title)}de.type==="session:status-changed"&&de.sessionId&&x(Re=>Re.map(Ee=>{if(Ee.id!==de.sessionId)return Ee;const ve={status:de.status,updated_at:new Date().toISOString()};return de.worktree_path!==void 0&&(ve.worktree_path=de.worktree_path),de.branch_name!==void 0&&(ve.branch_name=de.branch_name),{...Ee,...ve}}))}),[e,Z,W]);const V=_.useCallback(async(de,Re,Ee,ve,at,vt,Ct,Tt,Nt,Ft)=>{if(!h)return;const Dn=await mf(h,{title:de,description:Re,cli_tool:Ee,depends_on:at,max_turns:vt??null,use_worktree:Ct??null,...Tt?{memory_inject_mode:Tt}:{},...Nt?{memory_node_ids:Nt}:{},...Ft?{memory_raw_file_paths:Ft}:{}});if(ve&&ve.length>0){const Wn=await i1(Dn.id,ve.map(In=>({name:In.name,data:In.data})));Dn.images=JSON.stringify(Wn.images)}c(Wn=>[...Wn,Dn])},[h]),pe=_.useCallback((de,Re=[])=>{const Ee=de.split("/").filter(Boolean).pop()??de,ve=[de,...Re].map(at=>`@${at}`).join(`
665
+ ${$}`:""}`,children:[t.jsx("span",{"aria-label":(q==null?void 0:q.status)||"unknown",style:{width:6,height:6,borderRadius:"50%",background:P,flexShrink:0}}),t.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Rt,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:B,width:16,textAlign:"center"},children:">_"}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(q==null?void 0:q.title)||U}),t.jsx("button",{"data-no-drag":!0,onMouseDown:Y=>Y.stopPropagation(),onClick:Y=>{Y.stopPropagation(),o(U)},"aria-label":"close-tab",title:w("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:t.jsx(Qt,{size:11})})]},U)}),E&&t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{E.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 ${Ie.separator}`,color:Ie.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:t.jsx(mn,{size:13})}),t.jsx("div",{style:{flex:1,minWidth:8}}),z&&t.jsx("span",{title:z,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ie.dim,fontFamily:Rt,fontSize:9,padding:"0 7px",flexShrink:1},children:z}),t.jsx(V8,{sessionId:e.activeTab,sendMessage:u}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.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:Ks,children:t.jsx(TN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>N(-1),"aria-label":"decrease-font",title:`${w("session.fontDecrease")||"Decrease font size"} (${k}px) · Ctrl+- · Ctrl+wheel`,style:Ks,children:t.jsx(QN,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>N(1),"aria-label":"increase-font",title:`${w("session.fontIncrease")||"Increase font size"} (${k}px) · Ctrl+= · Ctrl+wheel`,style:Ks,children:t.jsx(XN,{size:13})}),t.jsx(q8,{sessionId:e.activeTab}),y&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&y.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{var U;return(U=y.onApplyLayoutPreset)==null?void 0:U.call(y,"single")},"aria-label":"single-pane",title:w("session.layout.single"),style:Ks,children:t.jsx(qi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{var U;return(U=y.onApplyLayoutPreset)==null?void 0:U.call(y,"columns")},"aria-label":"two-columns",title:w("session.layout.columns"),style:Ks,children:t.jsx(Lw,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:()=>{var U;return(U=y.onApplyLayoutPreset)==null?void 0:U.call(y,"grid")},"aria-label":"grid-layout",title:w("session.layout.grid"),style:Ks,children:t.jsx(Rw,{size:13})})]}),y.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onToggleMaximize,"aria-label":"toggle-maximize",title:`${y.isMaximized?w("session.restoreSize"):w("session.maximize")} · ${w("session.maximizeHint")}`,style:Ks,children:y.isMaximized?t.jsx(Pu,{size:13}):t.jsx(Gi,{size:13})}),y.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onPopOutGroup,"aria-label":"pop-out",title:`${w("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Ks,children:t.jsx(li,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onMinimizeGroup,"aria-label":"minimize",title:`${w("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Ks,children:t.jsx(Aw,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:U=>U.stopPropagation(),onClick:y.onCloseGroup,"aria-label":"close",title:`${w("session.close")||"Close"} (Ctrl+Shift+X)`,style:Ks,children:t.jsx(Qt,{size:13})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:U=>{if(!U){p(s,null);return}const q=U.getBoundingClientRect();p(s,{x:q.left,y:q.top,w:q.width,h:q.height})},onMouseDown:I,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map(U=>{const q=a.get(U);if(!q)return null;const X=f[U]||{intent:"open",nonce:0};return t.jsx(H_,{session:q,visible:U===e.activeTab,intent:X.intent,intentNonce:X.nonce,onClose:()=>d(U),sendMessage:u,subscribeBinary:v,onEvent:b,onCycleTab:F,remountKey:D[U]||0},U)})})]})}const Ks={background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function eO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const h=_.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",v),document.removeEventListener("visibilitychange",b))},u=()=>{p(),a()},v=x=>{x.key==="Escape"&&u()},b=()=>{document.hidden&&u()},C=x=>{const y=e==="horizontal"?x.clientX-o:x.clientY-c;i(y)},S=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",S),window.addEventListener("blur",u),window.addEventListener("keydown",v),document.addEventListener("visibilitychange",b)},[e,s,i,a]),f=e==="horizontal";return t.jsx("div",{onMouseDown:h,style:{flex:"0 0 4px",background:Ie.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function _p(e){const{node:s,path:i,onSplitSizes:a,...h}=e;return s.kind==="stack"?t.jsx(wp,{stack:s,path:i,...h}):t.jsx(tO,{split:s,path:i,onSplitSizes:a,stackProps:h})}const ky=80;function tO({split:e,path:s,onSplitSizes:i,stackProps:a}){const h=e.orientation==="horizontal",f=_.useRef(null),m=_.useRef([]),o=_.useRef(null);return t.jsx("div",{ref:f,style:{display:"flex",flexDirection:h?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((c,d)=>t.jsxs(_.Fragment,{children:[t.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:t.jsx(_p,{node:c,path:[...s,d],onSplitSizes:i,...a})}),d<e.children.length-1&&t.jsx(eO,{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 v=u.initialSizes[u.i]/100*u.total,b=u.initialSizes[u.i+1]/100*u.total,C=v+b,S=Math.max(ky,Math.min(C-ky,v+p)),x=C-S,y=S/u.total*100,w=x/u.total*100,k=m.current[u.i],N=m.current[u.i+1];k&&(k.style.flexBasis=`${y}%`),N&&(N.style.flexBasis=`${w}%`);const D=u.initialSizes.slice();D[u.i]=y,D[u.i+1]=w,u.finalSizes=D},onDragEnd:()=>{const p=o.current;p&&i(s,p.finalSizes),o.current=null}})]},d))})}const nn=28,fs=68;function Vu(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)<=nn&&Math.abs(m)<=nn?"center":f>=-fs-nn&&f<=-fs+nn&&Math.abs(m)<=nn?"left":f>=fs-nn&&f<=fs+nn&&Math.abs(m)<=nn?"right":m>=-fs-nn&&m<=-fs+nn&&Math.abs(f)<=nn?"top":m>=fs-nn&&m<=fs+nn&&Math.abs(f)<=nn?"bottom":null}function Cu(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:Vu(e,s,c)}}return null}function nO(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 gl({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,h=s?nO(e,s):null;return rn.createPortal(t.jsxs(t.Fragment,{children:[h&&t.jsx("div",{style:{position:"fixed",left:h.x,top:h.y,width:h.w,height:h.h,background:`${Ie.info}33`,border:`2px dashed ${Ie.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=fs+nn;return t.jsxs("div",{style:{position:"fixed",left:i-f,top:a-f,width:f*2,height:f*2,pointerEvents:"none",zIndex:2500},children:[t.jsx(Xo,{offsetX:f-nn,offsetY:f-nn,active:s==="center",kind:"center"}),t.jsx(Xo,{offsetX:f-fs-nn,offsetY:f-nn,active:s==="left",kind:"left"}),t.jsx(Xo,{offsetX:f+fs-nn,offsetY:f-nn,active:s==="right",kind:"right"}),t.jsx(Xo,{offsetX:f-nn,offsetY:f-fs-nn,active:s==="top",kind:"top"}),t.jsx(Xo,{offsetX:f-nn,offsetY:f+fs-nn,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Xo({offsetX:e,offsetY:s,active:i,kind:a}){const h=nn*2,f=i?Ie.info:"#3a3a3a",m=i?Ie.bright:Ie.separator;return t.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 ${Ie.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:t.jsx(sO,{kind:a,fill:f})})}function sO({kind:e,fill:s}){const i={position:"absolute",background:s};switch(e){case"center":return t.jsx("div",{style:{...i,inset:4}});case"left":return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{...i,left:4,top:4,bottom:4,width:"calc(50% - 4px)"}}),t.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 t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"absolute",left:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),t.jsx("div",{style:{...i,right:4,top:4,bottom:4,width:"calc(50% - 4px)"}})]});case"top":return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{...i,top:4,left:4,right:4,height:"calc(50% - 4px)"}}),t.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 t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"absolute",top:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${s}`,boxSizing:"border-box"}}),t.jsx("div",{style:{...i,bottom:4,left:4,right:4,height:"calc(50% - 4px)"}})]})}}function wr(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function ll(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 Yu(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=Yu(e.children[i],s);if(a)return[i,...a]}return null}function un(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(un)}function ju(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(ju)}function rO(e,s){const i=un(e);if(i.length<=1||s==="single")return wr(i,ju(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),h=Array.from({length:a},()=>[]);i.forEach((u,v)=>h[v%a].push(u));const f=new Set(ju(e)),m=h.map(u=>wr(u,u.find(v=>f.has(v))||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 $i(e,s){return $_(e,s)}function $_(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=$_(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 Hi(e,s,i){return Xu(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 Ia(e,s,i,a){const h=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return Xu(e,s,m=>({kind:"split",orientation:h,children:f?[a,m]:[m,a],sizes:[50,50]}))}function Xu(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?Xu(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 U_(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=>U_(a,s,i))}}function W_(e,s,i){return Xu(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 iO(e,s,i,a){const h=ll(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=$i(e,s);if(!m)return null;const o=Yu(m,f);if(!o)return null;const c=a==="center"?Hi(m,o,s):Ia(m,o,a,wr([s]));return Bs(c,s)}function aO(e,s){const i=un(e);let a=e;for(const h of i){if(!a)break;s.has(h)||(a=$i(a,h))}return a}const Xc=320,Jc=200,Qc=80,Zc=22,oO=4,Cy=8,Zr=10,eu=60;function ei(e,s,i){return Math.max(s,Math.min(i,e))}function lO(e,s,i,a){const h=e<=Cy,f=e>=i-Cy;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 jy(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 cO(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 v=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-v)<=Zr?f=v-i:Math.abs(o-v)<=Zr?f=v:Math.abs(c-b)<=Zr&&(f=b-i)),o<b&&c>v&&(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 uO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:h,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:c}=st(),d=C_("(max-width: 767px)"),p=Y_(),u=_.useRef(null),[v,b]=_.useState(!1),C=_.useRef(null),[S,x]=_.useState(null),y=_.useRef({x:e.x,y:e.y,w:e.w,h:e.h});y.current={x:e.x,y:e.y,w:e.w,h:e.h};const[w,k]=_.useState(null),N=_.useRef(null),D=_.useRef(i);D.current=i;const[j,R]=_.useState(null),E=_.useRef(null),L=_.useCallback((J,V)=>{if(d||v||J.button!==0||J.target.closest("[data-no-drag]"))return;J.preventDefault(),p.focus(un(e.root)[0]||"");const oe=J.clientX,ge=J.clientY,le={...y.current},Oe=u.current,He=window.innerWidth,Te=window.innerHeight;let ye="";V&&Oe&&(ye=Oe.style.pointerEvents,Oe.style.pointerEvents="none");let ke=!1;const Ke=()=>{ke||(ke=!0,window.removeEventListener("mousemove",qe),window.removeEventListener("mouseup",Qe),window.removeEventListener("blur",$e),window.removeEventListener("keydown",be),document.removeEventListener("visibilitychange",De),V&&Oe&&(Oe.style.pointerEvents=ye))},$e=()=>{Ke(),E.current=null,R(null),N.current=null,k(null),p.setGroupGeometry(e.id,{...y.current})},be=nt=>{nt.key==="Escape"&&$e()},De=()=>{document.hidden&&$e()};let Fe=!1;const qe=nt=>{if(Fe)return;{const se=window.screenX,ce=window.screenY,fe=se+window.outerWidth,ue=ce+window.outerHeight;if(nt.screenX<se-eu||nt.screenX>fe+eu||nt.screenY<ce-eu||nt.screenY>ue+eu){Fe=!0,Ke(),E.current=null,R(null),N.current=null,k(null),p.setGroupGeometry(e.id,{...y.current}),p.popOutGroup(e.id,{atScreenX:nt.screenX,atScreenY:nt.screenY});return}}const xe=nt.clientX-oe,ie=nt.clientY-ge;let we=ei(le.x+xe,-(le.w-Qc),He-Qc),Q=ei(le.y+ie,0,Te-Zc);const K=D.current;if(K.length>0){const se=cO(we,Q,le.w,le.h,K);we=se.x,Q=se.y}if(Oe&&(Oe.style.left=`${we}px`,Oe.style.top=`${Q}px`),y.current.x=we,y.current.y=Q,V){let se=null;const ce=document.elementFromPoint(nt.clientX,nt.clientY),fe=ce==null?void 0:ce.closest("[data-group-id][data-stack-path]");if(fe){const ue=fe.dataset.groupId||"";if(ue!==e.id){const je=fe.dataset.stackPath||"",Ue=je===""?[]:je.split(".").map(Number),ut=fe.getBoundingClientRect(),Pe={x:ut.left,y:ut.top,w:ut.width,h:ut.height};se={groupId:ue,path:Ue,rect:Pe,zone:Vu(nt.clientX,nt.clientY,Pe)}}}E.current=se,R(se?{rect:se.rect,zone:se.zone}:null)}const ee=V&&E.current&&E.current.zone?null:lO(nt.clientX,nt.clientY,He,Te);ee!==N.current&&(N.current=ee,k(ee))},Qe=()=>{if(Ke(),V&&E.current&&E.current.zone){const nt=E.current;p.dockGroup(e.id,nt.groupId,nt.path,nt.zone),E.current=null,R(null),N.current=null,k(null);return}if(N.current){const nt=jy(N.current,He,Te);Oe&&(Oe.style.left=`${nt.x}px`,Oe.style.top=`${nt.y}px`,Oe.style.width=`${nt.w}px`,Oe.style.height=`${nt.h}px`),y.current=nt,N.current=null,k(null)}E.current=null,R(null),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",qe),window.addEventListener("mouseup",Qe),window.addEventListener("blur",$e),window.addEventListener("keydown",be),document.addEventListener("visibilitychange",De)},[d,v,p,e.id,e.root]),A=_.useCallback(J=>L(J,!1),[L]),O=_.useCallback(J=>L(J,!0),[L]),z=_.useCallback(J=>V=>{if(d||v||V.button!==0)return;V.preventDefault(),V.stopPropagation();const pe=V.clientX,oe=V.clientY,ge={...y.current},le=u.current,Oe=window.innerWidth,He=window.innerHeight,Te=Fe=>{const qe=Fe.clientX-pe,Qe=Fe.clientY-oe;let nt=ge.x,xe=ge.y,ie=ge.w,we=ge.h;J.includes("e")?ie=ei(ge.w+qe,Xc,Math.max(Xc,Oe-ge.x)):J.includes("w")&&(nt=ei(ge.x+qe,0,ge.x+ge.w-Xc),ie=ge.x+ge.w-nt),J.includes("s")?we=ei(ge.h+Qe,Jc,Math.max(Jc,He-ge.y)):J.includes("n")&&(xe=ei(ge.y+Qe,0,ge.y+ge.h-Jc),we=ge.y+ge.h-xe),le&&(le.style.left=`${nt}px`,le.style.top=`${xe}px`,le.style.width=`${ie}px`,le.style.height=`${we}px`),y.current={x:nt,y:xe,w:ie,h:we}};let ye=!1;const ke=()=>{ye||(ye=!0,window.removeEventListener("mousemove",Te),window.removeEventListener("mouseup",De),window.removeEventListener("blur",Ke),window.removeEventListener("keydown",$e),document.removeEventListener("visibilitychange",be))},Ke=()=>{ke(),p.setGroupGeometry(e.id,{...y.current})},$e=Fe=>{Fe.key==="Escape"&&Ke()},be=()=>{document.hidden&&Ke()},De=()=>{ke(),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",Te),window.addEventListener("mouseup",De),window.addEventListener("blur",Ke),window.addEventListener("keydown",$e),document.addEventListener("visibilitychange",be)},[d,v,p,e.id]);_.useEffect(()=>{if(d)return;const J=()=>{const V=window.innerWidth,pe=window.innerHeight,oe=y.current,ge=ei(oe.x,-(oe.w-Qc),V-Qc),le=ei(oe.y,0,pe-Zc);(ge!==oe.x||le!==oe.y)&&p.setGroupGeometry(e.id,{...oe,x:ge,y:le})};return window.addEventListener("resize",J),()=>window.removeEventListener("resize",J)},[d,p,e.id]);const I=_.useCallback(J=>{x(J),p.setActiveTab(e.id,J),p.focus(J)},[p,e.id]),F=_.useCallback(J=>{x(J),p.focus(J)},[p]),H=_.useCallback(J=>{p.close(J)},[p]),U=_.useCallback((J,V,pe)=>{p.beginTabDrag(e.id,J,V,pe)},[p,e.id]),q=_.useCallback(J=>{p.close(J)},[p]),X=_.useCallback((J,V)=>{p.setSplitSizes(e.id,J,V)},[p,e.id]),B=ju(e.root),P=un(e.root);_.useEffect(()=>{S&&P.includes(S)||x(B[0]||P[0]||null)},[S,B,P]);const $=_.useCallback(()=>{if(v){const J=C.current;J&&p.setGroupGeometry(e.id,J),C.current=null,b(!1);return}C.current={...y.current},p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(Xc,window.innerWidth-12),h:Math.max(Jc,window.innerHeight-12)}),b(!0)},[p,e.id,v]),Y=J=>{const V=/Mac|iPhone|iPad|iPod/.test(navigator.platform),pe=V?J.metaKey:J.ctrlKey,oe=V?J.ctrlKey:J.metaKey;if(!pe||oe||J.altKey||!J.shiftKey)return;const ge=J.key.toLowerCase();ge==="o"?(J.preventDefault(),p.popOutGroup(e.id)):ge==="m"?(J.preventDefault(),p.minimizeGroup(e.id)):ge==="x"&&(J.preventDefault(),p.closeGroup(e.id))};if(d){const J=B[0],V=J?s.get(J):null;if(!V)return null;const pe=e.intents[J]??{intent:"open",nonce:0};return rn.createPortal(t.jsxs("div",{style:{position:"fixed",inset:0,background:Ie.bg,display:"flex",flexDirection:"column",zIndex:110},children:[t.jsxs("div",{style:{background:Ie.titleBg,height:Zc,display:"flex",alignItems:"center",borderBottom:`1px solid ${Ie.separator}`},children:[t.jsx("span",{style:{flex:1,color:Ie.titleText,fontFamily:Rt,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:V.title}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ti,"aria-label":"close",children:t.jsx(Qt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(H_,{session:V,visible:!0,intent:pe.intent,intentNonce:pe.nonce,onClose:()=>p.close(J),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const W=w?(()=>{const J=window.innerWidth,V=window.innerHeight,pe=jy(w,J,V);return rn.createPortal(t.jsx("div",{style:{position:"fixed",left:pe.x,top:pe.y,width:pe.w,height:pe.h,background:`${Ie.info}33`,border:`2px dashed ${Ie.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,Z=(()=>{var V;if(P.length===0)return"";const J=((V=s.get(P[0]))==null?void 0:V.title)||P[0];return P.length===1?J:`${J} +${P.length-1}`})(),he=e.root.kind==="split",re=rn.createPortal(t.jsxs("div",{ref:u,onKeyDown:Y,onMouseDown:he?()=>p.focus(P[0]||""):O,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:h,background:Ie.bg,border:`1px solid ${a?Ie.info:Ie.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 ${Ie.info}66, 0 0 18px ${Ie.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:[he&&t.jsxs("div",{onMouseDown:A,onDoubleClick:J=>{J.target.closest("button")||$()},style:{height:Zc,flexShrink:0,display:"flex",flexDirection:"column",background:Ie.titleBg,borderBottom:`1px solid ${Ie.separator}`,userSelect:"none",cursor:"move"},children:[t.jsx("div",{style:{display:"flex",height:oO,flexShrink:0},children:B.map((J,V)=>t.jsx("div",{style:{flex:1,background:e.colors[J]||Ie.titleText}},V))}),t.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:Ie.titleText,fontFamily:Rt,fontSize:11},children:[t.jsx("span",{style:{color:Ie.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Z}),P.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:ti,"aria-label":"single-pane",title:c("session.layout.single"),children:t.jsx(qi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:ti,"aria-label":"two-columns",title:c("session.layout.columns"),children:t.jsx(Lw,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:ti,"aria-label":"grid-layout",title:c("session.layout.grid"),children:t.jsx(Rw,{size:13})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.stopPropagation(),onClick:$,style:ti,"aria-label":"toggle-maximize",title:`${c(v?"session.restoreSize":"session.maximize")} · ${c("session.maximizeHint")}`,children:v?t.jsx(Pu,{size:13}):t.jsx(Gi,{size:13})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:J=>J.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:t.jsx(li,{size:14})}),t.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:t.jsx(Aw,{size:14})}),t.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:t.jsx(Qt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(_p,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:I,onTabClose:H,onTabMouseDown:U,onPaneAutoClose:q,registerRect:()=>{},onSplitSizes:X,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:S||void 0,groupTopmost:a,onFocusStack:F}):t.jsx(wp,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:I,onTabClose:H,onTabMouseDown:U,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:$,isMaximized:v,onApplyLayoutPreset:J=>p.applyLayoutPreset(e.id,J)}})}),t.jsx("div",{onMouseDown:z("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:z("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),t.jsx("div",{onMouseDown:z("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:z("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.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 t.jsxs(t.Fragment,{children:[re,W,j&&t.jsx(gl,{targetRect:j.rect,activeZone:j.zone})]})}const ti={background:"transparent",border:"none",color:Ie.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},Ff=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Ii(e){for(const s of Ff)if(!e.includes(s))return s;return Ff[e.length%Ff.length]}const dO="clitrigger:session-windows:global";function Sp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(dO),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 Bt="main",Nm=new Map;function hO(e,s){Nm.set(e,s)}function fO(e){const s=Nm.get(e);if(!s||s.closed)return Nm.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function mO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const G_=5e3,pO=15e3;let Pa=null;function q_(){if(typeof window>"u")return()=>{};const e=s=>{Pa={sx:s.screenX,sy:s.screenY,cx:s.clientX,cy:s.clientY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function Eu(e,s){if(Pa)return{x:Pa.cx+(e-Pa.sx),y:Pa.cy+(s-Pa.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 Tu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Em="clitrigger:popout-alive:";function gO(e){return`${Em}${e}`}function K_(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function xO(e){if(!K_())return()=>{};let s=()=>{};return navigator.locks.request(gO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function vO(){var e;if(!K_())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(Em)&&i.add(a.name.slice(Em.length));return i}catch{return new Set}}const kp=_.createContext(null),V_=_.createContext({});function Y_(){const e=_.useContext(kp);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function bO(){return _.useContext(V_)}function yO(){return _.useContext(kp)}const Lu=720,Cp=460,wO=320,_O=200,Ny=30,X_=80,J_=80,cl=80,Tm=28;function SO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=wO?e.w:Lu,h=Number.isFinite(e.h)&&e.h>=_O?e.h:Cp;a=Math.min(a,s),h=Math.min(h,i);let f=Number.isFinite(e.x)?e.x:X_,m=Number.isFinite(e.y)?e.y:J_;return f=Math.max(Math.min(f,s-cl),-(a-cl)),m=Math.max(Math.min(m,i-Tm),0),{x:f,y:m,w:a,h}}const kO=12,tu=60;function Q_(e){return`sessionGroups:${e}`}function du(e){try{const s=localStorage.getItem(Q_(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 Lm(e,s){try{localStorage.setItem(Q_(e),JSON.stringify(s))}catch{}}function CO(e,s){const i=du(e);!i||!i.groups.some(a=>a.id===s)||(Lm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function jO(e){const s=e%8;return{x:X_+s*Ny,y:J_+s*Ny,w:Lu,h:Cp}}function nu(e,s,i){return Math.max(s,Math.min(i,e))}function Ey(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function ni(e,s){for(const i of e)if(Yu(i.root,s))return i;return null}function NO({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:h,onAddSession:f,children:m}){const{t:o}=st(),[c]=_.useState(()=>{const Q=du(e);if(!Q)return{groups:[],zCounter:0};const K=Q.groups.map(ne=>{const ee=un(ne.root),se=new Set(ee),ce={};for(const Ue of Object.keys(ne.colors||{}))se.has(Ue)&&(ce[Ue]=ne.colors[Ue]);const fe={};for(const Ue of ee)fe[Ue]={intent:"open",nonce:0},ce[Ue]||(ce[Ue]=Ii(Object.values(ce)));const ue=SO({x:ne.x,y:ne.y,w:ne.w,h:ne.h}),je=ne.ownerWindowId||Bt;return{...ne,...ue,colors:ce,intents:fe,minimized:!!ne.minimized,ownerWindowId:je}});return{groups:K,zCounter:Q.zCounter||K.length}}),[d,p]=_.useState(c.groups),u=_.useRef(c.zCounter),v=_.useRef(d);v.current=d;const b=_.useRef(s);b.current=s;const[C,S]=_.useState(null),x=_.useRef(null);x.current=C;const[y,w]=_.useState({}),k=_.useRef(y);k.current=y,_.useEffect(()=>{var ee;const Q={},K=((ee=du(e))==null?void 0:ee.sessionProjects)??{},ne={};for(const se of d)for(const ce of un(se.root)){const fe=s.find(je=>je.id===ce)||y[ce];fe!=null&&fe.title&&(Q[ce]=fe.title);const ue=(fe==null?void 0:fe.project_id)||K[ce];ue&&(ne[ce]=ue)}Lm(e,{groups:d,zCounter:u.current,titles:Q,sessionProjects:ne}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,d,s,y]),_.useEffect(()=>()=>{var fe;const Q=v.current;if(Q.length===0)return;let K=!1;const ne=Q.map(ue=>(ue.ownerWindowId||Bt)!==Bt||ue.minimized?ue:(K=!0,{...ue,minimized:!0}));if(!K)return;const ee={},se=((fe=du(e))==null?void 0:fe.sessionProjects)??{},ce={};for(const ue of ne)for(const je of un(ue.root)){const Ue=b.current.find(Pe=>Pe.id===je)||k.current[je];Ue!=null&&Ue.title&&(ee[je]=Ue.title);const ut=(Ue==null?void 0:Ue.project_id)||se[je];ut&&(ce[je]=ut)}Lm(e,{groups:ne,zCounter:u.current,titles:ee,sessionProjects:ce}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]);const[N,D]=_.useState(()=>new Set),j=_.useRef(new Set);_.useEffect(()=>{if(s.length===0)return;const Q=s.filter(ne=>ne.project_id===e);if(Q.length===0)return;const K=new Set(Q.map(ne=>ne.id));for(const ne of d)for(const ee of un(ne.root))K.has(ee)||y[ee]||N.has(ee)||j.current.has(ee)||(j.current.add(ee),u1(ee).then(se=>w(ce=>({...ce,[ee]:se}))).catch(se=>{se instanceof fu&&se.status===404&&D(ce=>new Set(ce).add(ee))}).finally(()=>j.current.delete(ee)))},[d,s,e,y,N]),_.useEffect(()=>h(K=>{K.type!=="session:status-changed"||!K.sessionId||w(ne=>{const ee=ne[K.sessionId];if(!ee)return ne;const se={status:K.status};return K.worktree_path!==void 0&&(se.worktree_path=K.worktree_path),K.branch_name!==void 0&&(se.branch_name=K.branch_name),{...ne,[ee.id]:{...ee,...se}}})}),[h]),_.useEffect(()=>{N.size!==0&&p(Q=>{let K=!1;const ne=[];for(const ee of Q){const se=un(ee.root);if(!se.some(ut=>N.has(ut))){ne.push(ee);continue}K=!0;const ce=new Set(se.filter(ut=>!N.has(ut))),fe=aO(ee.root,ce);if(!fe)continue;const ue=new Set(un(fe)),je={};for(const ut of Object.keys(ee.colors))ue.has(ut)&&(je[ut]=ee.colors[ut]);const Ue={};for(const ut of Object.keys(ee.intents))ue.has(ut)&&(Ue[ut]=ee.intents[ut]);ne.push({...ee,root:fe,colors:je,intents:Ue})}return K?ne:Q})},[N]);const R=_.useCallback((Q,K)=>{const ne=v.current.length,ee=jO(ne);u.current+=1;const se=u.current;return{id:Ey(),...ee,z:se,minimized:!1,root:wr([Q],Q),colors:{[Q]:Ii([])},intents:{[Q]:{intent:K,nonce:0}},ownerWindowId:Bt}},[]),E=_.useCallback((Q,K="open")=>{p(ne=>{const ee=ni(ne,Q);u.current+=1;const se=u.current;return ee?ne.map(ce=>{var ut,Pe,Ve;if(ce.id!==ee.id)return ce;const fe=((ut=ce.intents[Q])==null?void 0:ut.intent)??"open",ue=K==="start"||K==="resume",je=ue?K:fe,Ue=je!==fe||ue;return{...ce,z:se,minimized:!1,root:Bs(ce.root,Q),intents:{...ce.intents,[Q]:{intent:je,nonce:Ue?(((Pe=ce.intents[Q])==null?void 0:Pe.nonce)??0)+1:((Ve=ce.intents[Q])==null?void 0:Ve.nonce)??0}}}}):[...ne,R(Q,K)]})},[R]),L=_.useCallback(Q=>{p(K=>{const ne=ni(K,Q);if(!ne)return K;const ee=K.reduce((ce,fe)=>fe.z>ce?fe.z:ce,0);if(ne.z===ee&&!ne.minimized)return K;u.current+=1;const se=u.current;return K.map(ce=>ce.id===ne.id?{...ce,z:se,minimized:!1}:ce)})},[]),A=_.useCallback(Q=>{const K=Q.map(ne=>b.current.find(ee=>ee.id===ne)||k.current[ne]).filter(ne=>!!ne&&ne.status==="running");if(K.length===0)return!0;if(!window.confirm(o("session.confirmStop")))return!1;for(const ne of K)bu(ne.id).catch(()=>{});return!0},[o]),O=_.useCallback(Q=>{A([Q])&&p(K=>{const ne=ni(K,Q);if(!ne)return K;const ee=$i(ne.root,Q);if(!ee)return K.filter(fe=>fe.id!==ne.id);new Set(un(ee));const se={...ne.colors};delete se[Q];const ce={...ne.intents};return delete ce[Q],K.map(fe=>fe.id===ne.id?{...fe,root:ee,colors:se,intents:ce}:fe)})},[A]),z=_.useCallback(Q=>{p(K=>{const ne=ni(K,Q);return ne?K.map(ee=>ee.id===ne.id?{...ee,minimized:!0}:ee):K})},[]),I=_.useCallback(Q=>{p(K=>{const ne=ni(K,Q);if(!ne)return K;u.current+=1;const ee=u.current;return K.map(se=>se.id===ne.id?{...se,minimized:!1,z:ee}:se)})},[]),F=_.useCallback(Q=>!!ni(v.current,Q),[]),H=_.useCallback(Q=>{const K=v.current.find(ne=>ne.id===Q);K&&!A(un(K.root))||p(ne=>ne.filter(ee=>ee.id!==Q))},[A]),U=_.useCallback(Q=>{p(K=>K.map(ne=>ne.id===Q?{...ne,minimized:!0}:ne))},[]);_.useEffect(()=>{const Q=ne=>{const ee=ne.detail;!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId===e&&p(se=>{if(!se.find(ue=>ue.id===ee.groupId))return se;u.current+=1;const fe=u.current;return se.map(ue=>ue.id===ee.groupId?{...ue,minimized:!1,z:fe}:ue)})},K=ne=>{var fe;const ee=ne.detail;if(!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId!==e)return;const se=v.current.find(ue=>ue.id===ee.groupId);if(se&&!A(un(se.root)))return;const ce=(se==null?void 0:se.ownerWindowId)||Bt;ce!==Bt&&(J.current.delete(ce),Oe.current.delete(ee.groupId),(fe=re.current)==null||fe.post({t:"group-reclaimed",popoutId:ce,groupIds:[ee.groupId],reason:"late-return"})),p(ue=>ue.filter(je=>je.id!==ee.groupId))};return window.addEventListener("session-windows:restore",Q),window.addEventListener("session-windows:close",K),()=>{window.removeEventListener("session-windows:restore",Q),window.removeEventListener("session-windows:close",K)}},[e,A]),_.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRestore");if(Q)try{const K=JSON.parse(Q);if(K.projectId!==e||!K.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),p(ne=>{if(!ne.find(ce=>ce.id===K.groupId))return ne;u.current+=1;const se=u.current;return ne.map(ce=>ce.id===K.groupId?{...ce,minimized:!1,z:se}:ce)})}catch{}},[e]);const q=_.useCallback(Q=>{p(K=>{if(!K.find(se=>se.id===Q))return K;u.current+=1;const ee=u.current;return K.map(se=>se.id===Q?{...se,minimized:!1,z:ee}:se)})},[]),X=_.useCallback((Q,K)=>{p(ne=>ne.map(ee=>ee.id===Q?{...ee,...K}:ee))},[]),B=_.useCallback((Q,K,ne)=>{p(ee=>ee.map(se=>se.id===Q?{...se,root:W_(se.root,K,ne)}:se))},[]),P=_.useCallback((Q,K)=>{p(ne=>ne.map(ee=>ee.id===Q?{...ee,root:Bs(ee.root,K)}:ee))},[]),$=_.useCallback((Q,K)=>{p(ne=>ne.map(ee=>ee.id===Q?{...ee,root:rO(ee.root,K)}:ee))},[]),Y=_.useCallback((Q,K,ne)=>{p(ee=>ee.map(se=>se.id===Q?{...se,root:U_(se.root,K,ne)}:se))},[]),W=_.useCallback((Q,K,ne,ee)=>{if(ee.button!==0||!v.current.find(rt=>rt.id===Q))return;ee.preventDefault();const ce=ee.clientX,fe=ee.clientY;let ue=null;S({groupId:Q,sessionId:K,fromPath:ne,startX:ce,startY:fe,mouseX:ce,mouseY:fe,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null});const je=(rt,Le)=>{const et=Ey();ue=et;const wt=window.innerWidth,kt=window.innerHeight,de={x:nu(rt-60,-Lu+cl,wt-cl),y:nu(Le-12,0,kt-Tm),w:Lu,h:Cp};p(Re=>{const Ee=Re.find(Ft=>Ft.id===Q);if(!Ee)return Re;const ve=$i(Ee.root,K),at=Ee.colors[K]||Ii([]),vt=Ee.intents[K]??{intent:"open",nonce:0};u.current+=1;const Ct=u.current,Tt={id:et,...de,z:Ct,minimized:!1,root:wr([K],K),colors:{[K]:at},intents:{[K]:vt},ownerWindowId:Bt},Nt=[];for(const Ft of Re)if(Ft.id===Q){if(ve){const Dn=new Set(un(ve)),Wn={};for(const Tn of Object.keys(Ft.colors))Dn.has(Tn)&&(Wn[Tn]=Ft.colors[Tn]);const In={};for(const Tn of Object.keys(Ft.intents))Dn.has(Tn)&&(In[Tn]=Ft.intents[Tn]);Nt.push({...Ft,root:Nu(ve),colors:Wn,intents:In})}}else Nt.push(Ft);return Nt.push(Tt),Nt})};let Ue=!1;const ut=rt=>{const Le=window.screenX,et=window.screenY,wt=Le+window.outerWidth,kt=et+window.outerHeight;return rt.screenX<Le-tu||rt.screenX>wt+tu||rt.screenY<et-tu||rt.screenY>kt+tu},Pe=rt=>{if(Ue)return;const Le=x.current;if(!Le)return;if(!ue)Math.hypot(rt.clientX-ce,rt.clientY-fe)>=kO&&je(rt.clientX,rt.clientY);else{const Ee=window.innerWidth,ve=window.innerHeight,at=nu(rt.clientX-60,-640,Ee-cl),vt=nu(rt.clientY-12,0,ve-Tm);p(Ct=>Ct.map(Tt=>Tt.id===ue?{...Tt,x:at,y:vt}:Tt))}if(ue&&ut(rt)&&v.current.some(Ee=>Ee.id===ue)){const Ee=He.current;if(Ee){Ue=!0;const ve=ue;Ne(),S(null),Ee(ve,{atScreenX:rt.screenX,atScreenY:rt.screenY});return}}let et=null,wt=null,kt=null,de=null;const Re=document.elementsFromPoint(rt.clientX,rt.clientY);for(const Ee of Re){const ve=Ee.closest("[data-group-id][data-stack-path]");if(!ve)continue;const at=ve.dataset.groupId||"",vt=ve.dataset.stackPath||"";if(ue?at===ue:at===Le.groupId&&vt===Le.fromPath.join("."))continue;const Tt=vt===""?[]:vt.split(".").map(Number),Nt=ve.getBoundingClientRect();et=at,wt=Tt,kt={x:Nt.left,y:Nt.top,w:Nt.width,h:Nt.height},de=Vu(rt.clientX,rt.clientY,kt);break}S({...Le,mouseX:rt.clientX,mouseY:rt.clientY,hoveredGroupId:et,hoveredPath:wt,hoveredRect:kt,zone:de})};let Ve=!1;const Ne=()=>{Ve||(Ve=!0,window.removeEventListener("mousemove",Pe),window.removeEventListener("mouseup",ft),window.removeEventListener("blur",it),window.removeEventListener("keydown",lt),document.removeEventListener("visibilitychange",xt))},it=()=>{Ne(),S(null)},lt=rt=>{rt.key==="Escape"&&it()},xt=()=>{document.hidden&&it()},ft=()=>{Ne();const rt=x.current;if(S(null),!!rt&&rt.hoveredGroupId&&rt.hoveredPath&&rt.zone){const Le=ue||rt.groupId;Z(Le,rt.sessionId,rt.hoveredGroupId,rt.hoveredPath,rt.zone);return}};window.addEventListener("mousemove",Pe),window.addEventListener("mouseup",ft),window.addEventListener("blur",it),window.addEventListener("keydown",lt),document.addEventListener("visibilitychange",xt)},[]),Z=_.useCallback((Q,K,ne,ee,se)=>{p(ce=>{const fe=ce.find(lt=>lt.id===Q),ue=ce.find(lt=>lt.id===ne);if(!fe||!ue)return ce;if(Q===ne){const lt=ll(fe.root,ee);if(!lt||lt.kind!=="stack")return ce;const xt=lt.tabs.find(et=>et!==K);if(!xt)return ce;const ft=$i(fe.root,K);if(!ft)return ce;const rt=Yu(ft,xt);if(!rt)return ce;let Le;return se==="center"?Le=Hi(ft,rt,K):Le=Ia(ft,rt,se,wr([K])),Le=Bs(Le,K),ce.map(et=>et.id!==Q?et:(u.current+=1,{...et,root:Le,z:u.current,minimized:!1}))}const je=$i(fe.root,K),Ue=fe.colors[K],ut=fe.intents[K]??{intent:"open",nonce:0};let Pe;if(se==="center")Pe=Hi(ue.root,ee,K);else{const lt=wr([K]);Pe=Ia(ue.root,ee,se,lt)}Pe=Bs(Pe,K);const Ve={...ue.colors};Ve[K]||(Ve[K]=Ue||Ii(Object.values(Ve)));const Ne={...ue.intents,[K]:ut},it=[];for(const lt of ce)if(lt.id===Q){if(je){const xt=new Set(un(je)),ft={};for(const Le of Object.keys(lt.colors))xt.has(Le)&&(ft[Le]=lt.colors[Le]);const rt={};for(const Le of Object.keys(lt.intents))xt.has(Le)&&(rt[Le]=lt.intents[Le]);it.push({...lt,root:je,colors:ft,intents:rt})}}else lt.id===ne?(u.current+=1,it.push({...lt,root:Pe,colors:Ve,intents:Ne,z:u.current,minimized:!1})):it.push(lt);return it})},[]),he=_.useCallback((Q,K,ne,ee)=>{p(se=>{if(Q===K)return se;const ce=se.find(Ve=>Ve.id===Q),fe=se.find(Ve=>Ve.id===K);if(!ce||!fe||ce.root.kind!=="stack")return se;const ue=ce.root;let je;ee==="center"?je=ue.tabs.reduce((Ve,Ne)=>Hi(Ve,ne,Ne),fe.root):je=Ia(fe.root,ne,ee,ue),je=Bs(je,ue.activeTab);const Ue={...fe.colors,...ce.colors},ut={...fe.intents,...ce.intents},Pe=[];for(const Ve of se)Ve.id!==Q&&(Ve.id===K?(u.current+=1,Pe.push({...Ve,root:je,colors:Ue,intents:ut,z:u.current,minimized:!1})):Pe.push(Ve));return Pe})},[]),re=_.useRef(null),J=_.useRef(new Map),[V,pe]=_.useState(null),oe=_.useRef(V);oe.current=V;const ge=_.useRef(null),le=_.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);_.useEffect(()=>{const Q=()=>{le.current=Date.now()};window.addEventListener("focus",Q);const K=q_();return()=>{window.removeEventListener("focus",Q),K(),ge.current&&clearTimeout(ge.current)}},[]);const Oe=_.useRef(new Map),He=_.useRef(null),Te=_.useCallback((Q,K)=>{var Pe;const ne=v.current.find(Ve=>Ve.id===Q);if(!ne)return;const ee=mO(),se={...ne,ownerWindowId:ee};Oe.current.set(Q,se),J.current.set(ee,Date.now()),p(Ve=>Ve.map(Ne=>Ne.id===Q?{...Ne,ownerWindowId:ee}:Ne)),(Pe=re.current)==null||Pe.post({t:"group-handoff",to:ee,groupId:Q,group:se});const ce=K&&(typeof K.atScreenX=="number"||typeof K.atScreenY=="number"),fe=ce?Math.max(0,((K==null?void 0:K.atScreenX)??window.screenX+ne.x)-40):Math.max(0,window.screenX+ne.x),ue=ce?Math.max(0,((K==null?void 0:K.atScreenY)??window.screenY+ne.y)-12):Math.max(0,window.screenY+ne.y),je=["popup",`width=${Math.max(400,ne.w)}`,`height=${Math.max(300,ne.h+40)}`,`left=${fe}`,`top=${ue}`].join(","),Ue=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(Q)}?wid=${encodeURIComponent(ee)}`,ut=window.open(Ue,"_blank",je);if(!ut){Oe.current.delete(Q),J.current.delete(ee),p(Ve=>Ve.map(Ne=>Ne.id===Q?{...Ne,ownerWindowId:Bt}:Ne)),window.alert(o("session.popout.blocked")||"Popup blocked. Allow popups for this site to use Pop Out.");return}hO(ee,ut)},[e,o]);He.current=Te;const ye=_.useCallback(Q=>{var ee;const K=v.current.find(se=>se.id===Q);if(!K)return;const ne=K.ownerWindowId||Bt;if(ne===Bt){q(Q);return}(ee=re.current)==null||ee.post({t:"group-recall",popoutId:ne,groupId:Q}),setTimeout(()=>{var fe;const se=v.current.find(ue=>ue.id===Q);if(!se||(se.ownerWindowId||Bt)===Bt)return;J.current.delete(ne),Oe.current.delete(Q),(fe=re.current)==null||fe.post({t:"group-reclaimed",popoutId:ne,groupIds:[Q],reason:"late-return"}),u.current+=1;const ce=u.current;p(ue=>ue.map(je=>je.id===Q?{...je,ownerWindowId:Bt,minimized:!1,z:ce}:je))},1500)},[q]),ke=_.useCallback(Q=>{const K=ni(v.current,Q);K&&ye(K.id)},[ye]);_.useEffect(()=>{const Q=K=>{const ne=K.detail;!(ne!=null&&ne.projectId)||!ne.groupId||ne.projectId!==e||ye(ne.groupId)};return window.addEventListener("session-windows:recall",Q),()=>window.removeEventListener("session-windows:recall",Q)},[e,ye]),_.useEffect(()=>{const Q=sessionStorage.getItem("pendingSessionRecall");if(Q)try{const K=JSON.parse(Q);if(K.projectId!==e||!K.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const ne=K.groupId;setTimeout(()=>ye(ne),0)}catch{}},[e,ye]);const Ke=_.useCallback(Q=>Q.kind==="stack"?[]:[0,...Ke(Q.children[0])],[]),$e=_.useCallback((Q,K,ne)=>{const ee=K?v.current.find(ue=>ue.id===K):null,se=ee&&(ee.ownerWindowId||Bt)===Bt;if(!ee||!se){E(Q,"start");return}const ce=(()=>{if(ne){const ue=ll(ee.root,ne);if(ue&&ue.kind==="stack")return ne}return Ke(ee.root)})();u.current+=1;const fe=u.current;p(ue=>ue.map(je=>{if(je.id!==ee.id)return je;const Ue=Bs(Hi(je.root,ce,Q),Q);return{...je,root:Ue,z:fe,minimized:!1,colors:{...je.colors,[Q]:Ii(Object.values(je.colors))},intents:{...je.intents,[Q]:{intent:"start",nonce:0}}}}))},[E,Ke]),be=_.useCallback(async(Q,K)=>{const ne=new Date,ee=String(ne.getHours()).padStart(2,"0"),se=String(ne.getMinutes()).padStart(2,"0"),ce=String(ne.getSeconds()).padStart(2,"0"),fe=await dm(e,{title:`Shell ${ee}:${se}:${ce}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(fe),$e(fe.id,Q,K),fe.id},[e,f,$e]);_.useEffect(()=>{const Q=Sp();re.current=Q;const K=ee=>{var se;if(ee.t==="hello"){const ce=Oe.current.get(ee.groupId);if(ce&&ce.ownerWindowId===ee.from)Q.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:ce});else{const fe=v.current.find(ue=>ue.id===ee.groupId);fe&&fe.ownerWindowId===ee.from&&Q.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:fe})}}else if(ee.t==="group-return"||ee.t==="bye")if(ee.t==="group-return"){const ce=ee.group;ce&&ce.id===ee.groupId&&(Oe.current.delete(ee.groupId),J.current.delete(ee.from),ee.projectId&&ee.projectId!==e&&CO(ee.projectId,ee.groupId),p(fe=>{const ue=fe.find(Ue=>Ue.id===ee.groupId),je={...ce,ownerWindowId:Bt};return ue?fe.map(Ue=>Ue.id===ee.groupId?je:Ue):[...fe,je]}))}else J.current.delete(ee.from),p(ce=>ce.map(fe=>fe.ownerWindowId===ee.from?{...fe,ownerWindowId:Bt}:fe));else if(ee.t==="group-close")Oe.current.delete(ee.groupId),p(ce=>ce.filter(fe=>fe.id!==ee.groupId));else if(ee.t==="heartbeat")J.current.set(ee.from,Date.now());else if(ee.t==="group-update"){const ce=ee.patch;p(fe=>fe.map(ue=>ue.id===ee.groupId?{...ue,...ce}:ue))}else if(ee.t==="dock-probe"){if(document.visibilityState!=="visible")return;const ce=Eu(ee.x,ee.y),fe=Tu(ce)?Cu(ce.x,ce.y):null;if(fe){const ue=oe.current;(!ue||ue.zone!==fe.zone||ue.groupId!==fe.groupId||ue.path.join(".")!==fe.path.join("."))&&pe({rect:fe.rect,zone:fe.zone,path:fe.path,groupId:fe.groupId}),ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>pe(null),800),Q.post({t:"dock-probe-result",from:Bt,to:ee.from,hit:!0,focusAt:le.current})}else oe.current&&pe(null),Q.post({t:"dock-probe-result",from:Bt,to:ee.from,hit:!1,focusAt:le.current})}else if(ee.t==="dock-end")pe(null);else if(ee.t==="dock-commit"&&ee.to===Bt){const ce=Eu(ee.x,ee.y),fe=Tu(ce)?Cu(ce.x,ce.y):null,ue=fe&&fe.zone?fe:(se=oe.current)!=null&&se.zone?oe.current:null;let je=!1;const Ue=v.current.filter(ut=>(ut.ownerWindowId||Bt)===Bt);if(ue&&ue.zone&&!ni(Ue,ee.sessionId)){const ut=v.current.find(Ve=>Ve.id===ue.groupId),Pe=ut?ll(ut.root,ue.path):null;if(ut&&Pe&&Pe.kind==="stack"){je=!0;const Ve=ue.zone,Ne=ue.path;u.current+=1;const it=u.current;p(lt=>lt.map(xt=>{if(xt.id!==ut.id)return xt;const ft=Ve==="center"?Hi(xt.root,Ne,ee.sessionId):Ia(xt.root,Ne,Ve,wr([ee.sessionId])),rt=Bs(ft,ee.sessionId),Le={...xt.colors};Le[ee.sessionId]||(Le[ee.sessionId]=ee.color||Ii(Object.values(Le)));const et={...xt.intents,[ee.sessionId]:ee.intentInfo??{intent:"open",nonce:0}};return{...xt,root:rt,colors:Le,intents:et,z:it,minimized:!1}}))}}pe(null),Q.post({t:"dock-commit-ack",from:Bt,to:ee.from,sessionId:ee.sessionId,accepted:je})}},ne=Q.subscribe(K);return()=>{ne(),Q.close(),re.current=null}},[e]),_.useEffect(()=>{const Q=Date.now();for(const K of c.groups)K.ownerWindowId&&K.ownerWindowId!==Bt&&J.current.set(K.ownerWindowId,Q)},[]),_.useEffect(()=>{const Q=async()=>{var ue;const ne=Date.now(),ee=[];for(const[je,Ue]of J.current.entries())ne-Ue>pO&&ee.push(je);if(ee.length===0)return;const se=await vO(),ce=ee.filter(je=>se.has(je)?(J.current.set(je,ne),!1):!0);if(ce.length===0)return;for(const je of ce)J.current.delete(je);const fe=new Set(ce);for(const je of v.current)je.ownerWindowId&&fe.has(je.ownerWindowId)&&Oe.current.delete(je.id);for(const je of ce){const Ue=v.current.filter(ut=>ut.ownerWindowId===je).map(ut=>ut.id);Ue.length>0&&((ue=re.current)==null||ue.post({t:"group-reclaimed",popoutId:je,groupIds:Ue,reason:"heartbeat-timeout"}))}p(je=>je.map(Ue=>Ue.ownerWindowId&&ce.includes(Ue.ownerWindowId)?{...Ue,ownerWindowId:Bt}:Ue))},K=setInterval(()=>{Q()},G_);return()=>clearInterval(K)},[]);const De=_.useCallback((Q,K)=>{i({type:"session:terminal-input",sessionId:Q,input:K})},[i]),Fe=_.useCallback(()=>{var ne,ee;const Q=v.current.filter(se=>(se.ownerWindowId||Bt)===Bt).slice().sort((se,ce)=>ce.z-se.z),K=[];for(const se of Q)for(const ce of un(se.root)){const fe=((ne=b.current.find(ue=>ue.id===ce))==null?void 0:ne.title)||((ee=k.current[ce])==null?void 0:ee.title)||ce;K.push({sessionId:ce,label:fe})}return K},[]),qe=_.useCallback(async(Q,K)=>{const ee=v.current.filter(ce=>!ce.minimized&&(ce.ownerWindowId||Bt)===Bt).reduce((ce,fe)=>ce&&ce.z>=fe.z?ce:fe,null),se=await dm(e,{title:K||"",description:Q,use_worktree:!1,memory_inject_mode:"none"});f==null||f(se),$e(se.id,(ee==null?void 0:ee.id)??null)},[e,f,$e]),Qe=_.useMemo(()=>({openOrFocus:E,close:O,focus:L,minimize:z,restore:I,isOpen:F,recallPopout:ke,closeGroup:H,minimizeGroup:U,restoreGroup:q,setGroupGeometry:X,setSplitSizes:B,setActiveTab:P,applyLayoutPreset:$,reorderTab:Y,beginTabDrag:W,dockGroup:he,popOutGroup:Te,createRawShellTab:be,sendToSession:De,listOpenTerminals:Fe,sendToNewTerminal:qe}),[E,O,L,z,I,F,ke,H,U,q,X,B,P,$,Y,W,he,Te,be,De,Fe,qe]),nt=_.useMemo(()=>{const Q={};for(const K of d){const ee=(K.ownerWindowId||Bt)!==Bt?"popped":K.minimized?"minimized":"floating";for(const se of un(K.root))Q[se]=ee}return Q},[d]);_.useEffect(()=>{const Q=K=>{const ne=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ee=ne?K.metaKey:K.ctrlKey,se=ne?K.ctrlKey:K.metaKey;if(!ee||se||K.altKey||K.shiftKey||K.key.toLowerCase()!=="t")return;K.preventDefault();const fe=v.current.filter(ue=>!ue.minimized&&(ue.ownerWindowId||Bt)===Bt).reduce((ue,je)=>ue&&ue.z>=je.z?ue:je,null);be((fe==null?void 0:fe.id)??null).catch(()=>{})};return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[be]);const xe=_.useMemo(()=>{const Q=new Map;for(const K of Object.values(y))Q.set(K.id,K);for(const K of s)Q.set(K.id,K);return Q},[s,y]),ie=d.filter(Q=>!Q.minimized&&(Q.ownerWindowId||Bt)===Bt),we=ie.reduce((Q,K)=>K.z>Q.z?{id:K.id,z:K.z}:Q,{id:null,z:-1/0}).id;return t.jsx(kp.Provider,{value:Qe,children:t.jsxs(V_.Provider,{value:nt,children:[m,(()=>{const Q=new Map(ie.slice().sort((K,ne)=>K.z-ne.z).map((K,ne)=>[K.id,ne+1]));return ie.map(K=>{const ne=ie.filter(ee=>ee.id!==K.id).map(({x:ee,y:se,w:ce,h:fe})=>({x:ee,y:se,w:ce,h:fe}));return t.jsx(uO,{group:K,sessionsById:xe,neighbors:ne,isTopmost:K.id===we,zIndex:Q.get(K.id)??1,sendMessage:i,subscribeBinary:a,onEvent:h},K.id)})})(),C&&C.hoveredRect&&t.jsx(gl,{targetRect:C.hoveredRect,activeZone:C.zone}),V&&t.jsx(gl,{targetRect:V.rect,activeZone:V.zone})]})})}function EO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const TO={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"},LO={floating:"bg-accent/10 text-accent",minimized:"bg-warm-200 text-warm-600",popped:"bg-violet-500/15 text-violet-500"};function DO({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}=st(),{openOrFocus:v,recallPopout:b}=Y_(),C=bO(),[S,x]=_.useState(!1),[y,w]=_.useState(!1),[k,N]=_.useState(null),[D,j]=_.useState(!1),[R,E]=_.useState(null),[L,A]=_.useState([]),[O,z]=_.useState(""),[I,F]=_.useState(null);_.useEffect(()=>{let W=!1;return Vm().then(Z=>{W||A(Z)}).catch(()=>{}),()=>{W=!0}},[]),_.useEffect(()=>{if(!a)return;let W=!1;return Iw(e).then(Z=>{W||z(Z.branch||"")}).catch(()=>{}),()=>{W=!0}},[e,a]);const H=_.useMemo(()=>{const W=new Map;for(const Z of L)W.set(Z.id,Z);return W},[L]),U=_.useMemo(()=>k?s.find(W=>W.id===k)??null:null,[k,s]),q=_.useMemo(()=>{if(U)return{title:U.title,description:U.description??"",cliTool:U.cli_tool??"",useWorktree:U.use_worktree===1,memoryInjectMode:U.memory_inject_mode??"none",memoryNodeIds:S8(U.memory_node_ids??null),memoryRawFilePaths:EO(U.memory_raw_file_paths??null),tagId:U.tag_id??null}},[U]),X=_.useCallback(()=>{N(null),E(null),x(W=>!W)},[]),B=_.useCallback(W=>{x(!1),E(null),N(W)},[]),P=_.useCallback(()=>{x(!1),N(null),E(null)},[]),$=_.useCallback(async(W,Z,he,re,J,V,pe,oe)=>{w(!0);try{const ge=await dm(e,{title:W,description:Z||void 0,cli_tool:he,use_worktree:re,memory_inject_mode:J,memory_node_ids:V,memory_raw_file_paths:pe,tag_id:oe??null});m(ge),x(!1)}finally{w(!1)}},[e,m]),Y=_.useCallback(async(W,Z,he,re,J,V,pe,oe)=>{if(k){j(!0),E(null);try{const ge=await K3(k,{title:W,description:Z||void 0,cli_tool:he,use_worktree:re,memory_inject_mode:J,memory_node_ids:V,memory_raw_file_paths:pe,tag_id:oe??null});o(ge),N(null)}catch(ge){E(ge instanceof Error?ge.message:String(ge))}finally{j(!1)}}},[k,o]);return t.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:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"text-sm font-semibold text-warm-700 tracking-wide uppercase",children:u("tabs.sessions")}),t.jsxs("button",{onClick:X,className:"btn-primary text-xs py-2",disabled:y,children:["+ ",u("session.new")]})]}),S&&t.jsx(oy,{projectId:e,onSave:$,onCancel:P,projectCliTool:i,isGitRepo:a,projectUseWorktree:h}),q&&k&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(oy,{projectId:e,initial:q,onSave:Y,onCancel:P,projectCliTool:i,isGitRepo:a},k),(D||R)&&t.jsxs("div",{className:"text-xs px-1",children:[D&&t.jsx("span",{className:"text-warm-500",children:u("session.saving")||"saving…"}),R&&t.jsx("span",{className:"text-status-error",children:R})]})]}),s.length===0&&!S?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:hl,title:u("session.empty"),description:u("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((W,Z)=>{const he=["pending","failed","stopped","completed"].includes(W.status),re=W.status==="running",J=W.status!=="running",V=["stopped","failed","completed"].includes(W.status)&&(W.cli_tool??"claude")==="claude"&&!!W.worktree_path,pe=k===W.id,oe=C[W.id]??"closed",ge=oe==="popped";return t.jsx("div",{className:`card overflow-hidden animate-slide-up ${pe?"border-l-4 border-accent bg-warm-100/30":""}`,style:{animationDelay:`${Z*50}ms`},onContextMenu:le=>{hi(le)||(le.preventDefault(),le.stopPropagation(),F({x:le.clientX,y:le.clientY,sessionId:W.id}))},children:t.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>ge?b(W.id):v(W.id,"open"),children:t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[W.tag_id&&H.get(W.tag_id)&&t.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:[t.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:H.get(W.tag_id).color}}),H.get(W.tag_id).name]}),t.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:W.title}),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-semibold uppercase ${TO[W.status]||""}`,children:u(`status.${W.status}`)||W.status}),oe!=="closed"&&t.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-2xs font-medium ${LO[oe]}`,title:ge?u("session.dock.poppedHint"):void 0,children:[ge&&t.jsx(li,{size:10}),u(`session.windowState.${oe}`)]})]}),W.description&&t.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:W.description}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.jsx("span",{className:"text-2xs text-warm-300",children:W.cli_tool||"claude"}),(W.branch_name||a&&(O||f))&&t.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[t.jsx(Ya,{size:12}),W.branch_name||O||f]})]})]}),t.jsxs("div",{className:"flex gap-1",onClick:le=>le.stopPropagation(),children:[ge&&t.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:t.jsx(Gi,{size:16})}),he&&t.jsx("button",{onClick:()=>v(W.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded transition-colors",title:u("session.start"),children:t.jsx(kr,{size:16})}),V&&t.jsx("button",{onClick:()=>v(W.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded transition-colors",title:u("session.resumeHint")||u("session.resume"),children:t.jsx(ui,{size:16})}),t.jsx("button",{onClick:()=>B(W.id),disabled:!J,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(J?"session.edit":"session.editDisabledRunning"),children:t.jsx(em,{size:16})}),re&&t.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:t.jsx(qi,{size:16})}),W.status!=="running"&&(!!W.worktree_path||!!W.branch_name)&&t.jsx("button",{onClick:()=>{const le=W.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",W.branch_name)):!1;p(W.id,le)},className:"p-1.5 text-warm-400 hover:text-amber-600 rounded transition-colors",title:u("session.cleanup"),children:t.jsx(mu,{size:16})}),t.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:t.jsx(jn,{size:16})})]})]})})},W.id)})}),I&&(()=>{const W=()=>F(null),Z=I.sessionId?s.find(Oe=>Oe.id===I.sessionId):void 0;if(!Z)return t.jsx(Cr,{x:I.x,y:I.y,onClose:W,children:t.jsxs("button",{type:"button",onClick:()=>{N(null),E(null),x(!0)},className:sn,children:[t.jsx(mn,{size:14}),u("session.new")]})});const he=["pending","failed","stopped","completed"].includes(Z.status),re=Z.status==="running",J=Z.status!=="running",V=["stopped","failed","completed"].includes(Z.status)&&(Z.cli_tool??"claude")==="claude"&&!!Z.worktree_path,pe=Z.status!=="running"&&(!!Z.worktree_path||!!Z.branch_name),oe=C[Z.id]??"closed",ge=oe==="popped",le=u(ge?"session.recallToMain":oe==="minimized"?"session.restoreWindow":oe==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(Cr,{x:I.x,y:I.y,onClose:W,children:[t.jsxs("button",{type:"button",onClick:()=>ge?b(Z.id):v(Z.id,"open"),className:sn,children:[ge?t.jsx(Gi,{size:14}):t.jsx(hl,{size:14}),le]}),he&&t.jsxs("button",{type:"button",onClick:()=>v(Z.id,"start"),className:sn,children:[t.jsx(kr,{size:14}),u("session.start")]}),V&&t.jsxs("button",{type:"button",onClick:()=>v(Z.id,"resume"),className:sn,title:u("session.resumeHint")||u("session.resume"),children:[t.jsx(ui,{size:14}),u("session.resume")]}),J&&t.jsxs("button",{type:"button",onClick:()=>B(Z.id),className:sn,children:[t.jsx(em,{size:14}),u("session.edit")]}),re&&t.jsxs("button",{type:"button",onClick:()=>c(Z.id),className:sn,children:[t.jsx(qi,{size:14}),u("session.stop")]}),pe&&t.jsxs("button",{type:"button",onClick:()=>{const Oe=Z.branch_name?confirm(u("cleanup.confirmDeleteBranch").replace("{name}",Z.branch_name)):!1;p(Z.id,Oe)},className:sn,children:[t.jsx(mu,{size:14}),u("session.cleanup")]}),t.jsx(S_,{}),t.jsxs("button",{type:"button",onClick:()=>d(Z.id),className:vp,children:[t.jsx(jn,{size:14}),u("session.delete")]})]})})()]})}const Du={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"}},RO=Object.keys(Du);function Fa(e){const s=Du[e]||Du.default;return`${s.bg} ${s.text}`}function jp({src:e,alt:s,onClose:i}){return _.useEffect(()=>{const a=h=>{h.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),rn.createPortal(t.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:[t.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:t.jsx(Qt,{size:18})}),t.jsx("img",{src:e,alt:s,className:"max-w-full max-h-full object-contain rounded-lg",onClick:a=>a.stopPropagation()})]}),document.body)}function Dm({anchorRef:e,width:s,onClose:i,className:a,style:h,children:f}){const m=_.useRef(null),[o,c]=_.useState(null);return _.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]),_.useEffect(()=>{const d=u=>{var b,C;const v=u.target;(b=m.current)!=null&&b.contains(v)||(C=e.current)!=null&&C.contains(v)||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?rn.createPortal(t.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...h},children:f}),document.body):null}const Ty={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"},Ly={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 MO({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:c}){var ie,we;const{t:d}=st(),[p,u]=_.useState(!1),[v,b]=_.useState(!1),[C,S]=_.useState(!1),x=_.useRef(null),y=_.useRef(null),[w,k]=_.useState({top:0,left:0}),[N,D]=_.useState(e.title),[j,R]=_.useState(e.description??""),[E,L]=_.useState(e.priority),[A,O]=_.useState(e.due_date??""),[z,I]=_.useState(e.status),[F,H]=_.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[U,q]=_.useState(""),[X,B]=_.useState(!1),[P,$]=_.useState(null),[Y,W]=_.useState(null),Z=_.useRef(null),he=_.useRef(null),[re,J]=_.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),V=_.useRef(null);_.useEffect(()=>{D(e.title),R(e.description??""),L(e.priority),O(e.due_date??""),I(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{J(e.images?JSON.parse(e.images):[])}catch{J([])}},[e]);const pe=F,oe=e.status==="moved",ge=e.due_date&&new Date(e.due_date)<new Date&&!oe&&e.status!=="done",le=_.useCallback(Q=>{a(e.id,Q)},[e.id,a]),Oe=()=>{const Q=N.trim();Q&&Q!==e.title?le({title:Q}):D(e.title)},He=()=>{const Q=j.trim();Q!==(e.description??"")&&le({description:Q||void 0})},Te=Q=>{L(Q),Q!==e.priority&&le({priority:Q})},ye=Q=>{O(Q),Q!==(e.due_date??"")&&le({due_date:Q||void 0})},ke=Q=>{const K=Q;I(K),K!==e.status&&le({status:K})},Ke=Q=>{H(Q);const K=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(Q)!==JSON.stringify(K)&&le({tags:Q.length>0?JSON.stringify(Q):void 0})},$e=Q=>{var ne;const K=Q.trim();if(K&&!F.includes(K)&&(Ke([...F,K]),!s.has(K)&&c)){const ee=["blue","green","orange","purple","pink","red","yellow","brown"],se=ee[s.size%ee.length];c(K,{color:se})}q(""),(ne=Z.current)==null||ne.focus()},be=Q=>Ke(F.filter(K=>K!==Q)),De=i.filter(Q=>!F.includes(Q)&&(!U||Q.toLowerCase().includes(U.toLowerCase()))),Fe=_.useCallback(Q=>{const K=Array.from(Q).filter(se=>se.type.startsWith("image/")),ne=[];let ee=0;for(const se of K){const ce=new FileReader;ce.onload=()=>{ne.push({name:se.name,data:ce.result}),ee++,ee===K.length&&h1(e.id,ne).then(fe=>J(fe.images))},ce.readAsDataURL(se)}},[e.id]),qe=_.useCallback(Q=>{var ee;const K=(ee=Q.clipboardData)==null?void 0:ee.items;if(!K)return;const ne=[];for(let se=0;se<K.length;se++)if(K[se].type.startsWith("image/")){const ce=K[se].getAsFile();ce&&ne.push(ce)}ne.length!==0&&(Q.preventDefault(),Fe(ne))},[Fe]),Qe=_.useCallback(Q=>{var K;Q.preventDefault(),Q.stopPropagation(),(K=Q.dataTransfer)!=null&&K.files&&Fe(Q.dataTransfer.files)},[Fe]),nt=_.useCallback(Q=>{f1(e.id,Q).then(()=>{J(K=>K.filter(ne=>ne.id!==Q))})},[e.id]),xe=_.useCallback(()=>{if(!x.current)return;const Q=x.current.getBoundingClientRect(),K=window.innerWidth,ne=window.innerHeight;let ee=Q.bottom+4;const se=y.current;if(se){const ce=se.offsetWidth,fe=se.offsetHeight;let ue=Q.right-ce;ue<8&&(ue=8),ue+ce>K-8&&(ue=K-8-ce),ee+fe>ne-8&&(ee=Q.top-fe-4),k({top:ee,left:ue}),S(!0)}else k({top:ee,left:Math.max(8,Q.right-180)})},[]);return _.useEffect(()=>{if(!p){S(!1);return}xe();const Q=requestAnimationFrame(xe),K=ne=>{var se,ce;const ee=ne.target;(se=x.current)!=null&&se.contains(ee)||(ce=y.current)!=null&&ce.contains(ee)||u(!1)};return document.addEventListener("mousedown",K),window.addEventListener("scroll",xe,!0),window.addEventListener("resize",xe),()=>{cancelAnimationFrame(Q),document.removeEventListener("mousedown",K),window.removeEventListener("scroll",xe,!0),window.removeEventListener("resize",xe)}},[p,xe]),t.jsxs("div",{className:`${oe?"opacity-50":""}`,style:{borderBottom:"1px solid var(--color-border-muted)"},children:[t.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(!v),children:[t.jsx(Ts,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${v?"rotate-90":""}`,onClick:Q=>{Q.stopPropagation(),b(!v)}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("span",{className:"text-sm font-medium truncate block",style:{color:"var(--color-text-primary)"},children:e.title}),oe&&e.converted_type&&t.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&&t.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:[t.jsx(dN,{size:11}),d("planner.fromDiscussion")]})]}),t.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[re.length>0&&t.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:[t.jsx($a,{size:10}),re.length]}),pe.map(Q=>t.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium whitespace-nowrap ${Fa(s.get(Q)||"default")}`,children:Q},Q))]}),t.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:t.jsx("span",{className:`text-xs font-medium ${((ie=Ly[e.priority])==null?void 0:ie.style)??"text-warm-300"}`,children:((we=Ly[e.priority])==null?void 0:we.label)??"—"})}),t.jsx("div",{className:"hidden md:block w-20 text-right flex-shrink-0",children:e.due_date?t.jsx("span",{className:`text-xs ${ge?"text-red-500 font-medium":"text-warm-500"}`,children:new Date(e.due_date).toLocaleDateString(void 0,{month:"numeric",day:"numeric"})}):t.jsx("span",{className:"text-xs text-warm-300",children:d("planner.noDueDate")})}),t.jsx("div",{className:"w-16 flex-shrink-0",children:t.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${Ty[e.status]||Ty.pending}`,children:d(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:x,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:t.jsx(Um,{size:14})}),p&&rn.createPortal(t.jsxs("div",{ref:y,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:[!oe&&t.jsxs(t.Fragment,{children:[t.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:[t.jsx(kw,{size:12})," ",d("planner.convertToTask")]}),t.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:[t.jsx(oi,{size:12})," ",d("planner.convertToSchedule")]}),t.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:[t.jsx(di,{size:12})," ",d("planner.convertToTerminal")]})]}),t.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:[t.jsx(jn,{size:12})," ",d("planner.delete")]})]}),document.body)]})]}),v&&t.jsx("div",{className:"px-4 pb-3 pt-1 ml-8 animate-fade-in",children:t.jsxs("div",{className:"rounded-lg px-4 py-3 space-y-3",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[t.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:N,onChange:Q=>D(Q.target.value),onBlur:Oe,onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),Oe(),Q.target.blur())}}),t.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:qe,onDrop:Qe,onDragOver:Q=>{Q.preventDefault(),Q.stopPropagation()},onBlur:He}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{var Q;return(Q=V.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:[t.jsx($a,{size:12}),d("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:d("plannerForm.pasteHint")})]}),t.jsx("input",{ref:V,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:Q=>{Q.target.files&&Fe(Q.target.files),Q.target.value=""}}),re.length>0&&t.jsx("div",{className:"flex flex-wrap gap-2",children:re.map(Q=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:yu(e.id,Q.id),alt:Q.originalName,onClick:()=>W(yu(e.id,Q.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>nt(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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:Q.originalName})})]},Q.id))})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(Q=>t.jsxs("div",{className:"relative",children:[t.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:K=>{he.current=K.currentTarget,$(P===Q?null:Q)},children:[Q,t.jsx("button",{onClick:K=>{K.stopPropagation(),be(Q)},className:"opacity-60 hover:opacity-100",children:t.jsx(Qt,{size:9})})]}),P===Q&&t.jsxs(Dm,{anchorRef:he,width:180,onClose:()=>$(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[t.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:d("plannerTag.color")}),t.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:RO.map(K=>t.jsx("button",{onClick:async()=>{c&&await c(Q,{color:K}),$(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(Q)===K?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:d(`plannerTag.color.${K}`),children:t.jsx("div",{className:`w-5 h-5 rounded ${Du[K].swatch}`})},K))})]})]},Q)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:Z,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:U,onChange:Q=>{q(Q.target.value),B(!0)},onKeyDown:Q=>{(Q.key==="Enter"||Q.key===",")&&U.trim()&&(Q.preventDefault(),$e(U.replace(",",""))),Q.key==="Backspace"&&!U&&F.length>0&&be(F[F.length-1])},onFocus:()=>B(!0),onBlur:()=>setTimeout(()=>B(!1),150)}),X&&De.length>0&&t.jsx(Dm,{anchorRef:Z,width:160,onClose:()=>B(!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:De.slice(0,8).map(Q=>t.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>$e(Q),children:t.jsx("span",{className:`px-2 py-0.5 rounded text-2xs font-medium ${Fa(s.get(Q)||"default")}`,children:Q})},Q))})]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:E,onChange:Q=>Te(Number(Q.target.value)),children:[t.jsx("option",{value:0,children:d("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:d("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:d("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:d("plannerForm.priorityCritical")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:A,onChange:Q=>ye(Q.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:z,onChange:Q=>ke(Q.target.value),children:[t.jsx("option",{value:"pending",children:d("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:d("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:d("plannerStatus.done")})]})]})]})]})}),Y&&t.jsx(jp,{src:Y,onClose:()=>W(null)})]})}let AO=0;function OO({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:h,onUpdateTag:f}){const{t:m}=st(),[o,c]=_.useState(""),[d,p]=_.useState(""),[u,v]=_.useState([]),[b,C]=_.useState(""),[S,x]=_.useState(i??""),[y,w]=_.useState(0),[k,N]=_.useState("pending"),[D,j]=_.useState(!1),[R,E]=_.useState(!1),[L,A]=_.useState([]),[O,z]=_.useState([]),[I,F]=_.useState(null),H=_.useRef(null),U=_.useRef(null),q=_.useRef(null),[X,B]=_.useState(new Map),P=new Map([...e.map(le=>[le.name,le.color]),...X]),$=["blue","green","orange","purple","pink","red","yellow","brown"];_.useEffect(()=>{var le;if(s){c(s.title),p(s.description??""),v(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),w(s.priority),N(s.status);try{z(s.images?JSON.parse(s.images):[])}catch{z([])}}(le=H.current)==null||le.focus()},[s]);const Y=e.filter(le=>!u.includes(le.name)&&(!b||le.name.toLowerCase().includes(b.toLowerCase()))),W=le=>{var He;const Oe=le.trim();Oe&&!u.includes(Oe)&&v(Te=>{const ye=[...Te,Oe];if(!P.has(Oe)){const ke=$[P.size%$.length];B(Ke=>new Map([...Ke,[Oe,ke]]))}return ye}),C(""),E(!0),(He=U.current)==null||He.focus()},Z=le=>v(u.filter(Oe=>Oe!==le)),he=_.useCallback(le=>{const Oe=Array.from(le).filter(He=>He.type.startsWith("image/"));for(const He of Oe){const Te=new FileReader;Te.onload=()=>{const ye=Te.result,ke=`pending-${++AO}`;A(Ke=>[...Ke,{id:ke,name:He.name,data:ye,preview:ye}])},Te.readAsDataURL(He)}},[]),re=_.useCallback(le=>{var Te;const Oe=(Te=le.clipboardData)==null?void 0:Te.items;if(!Oe)return;const He=[];for(let ye=0;ye<Oe.length;ye++)if(Oe[ye].type.startsWith("image/")){const ke=Oe[ye].getAsFile();ke&&He.push(ke)}He.length!==0&&(le.preventDefault(),he(He))},[he]),J=_.useCallback(le=>{var Oe;le.preventDefault(),le.stopPropagation(),(Oe=le.dataTransfer)!=null&&Oe.files&&he(le.dataTransfer.files)},[he]),V=le=>A(Oe=>Oe.filter(He=>He.id!==le)),pe=le=>{s&&f1(s.id,le),z(Oe=>Oe.filter(He=>He.id!==le))},oe=O.length+L.length,ge=async()=>{if(o.trim()){j(!0);try{const le=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:y,...s?{status:k}:{}});if(f&&X.size>0&&await Promise.all([...X.entries()].map(([Oe,He])=>f(Oe,{color:He}))),L.length>0){const Oe=(s==null?void 0:s.id)??(le==null?void 0:le.id);Oe&&await h1(Oe,L.map(He=>({name:He.name,data:He.data})))}}finally{j(!1)}}};return t.jsxs("div",{className:"card p-5 animate-slide-up",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[t.jsx("input",{ref:H,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:le=>c(le.target.value),onKeyDown:le=>{le.key==="Enter"&&le.preventDefault()}}),t.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:le=>p(le.target.value),onPaste:re,onDrop:J,onDragOver:le=>{le.preventDefault(),le.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var le;return(le=q.current)==null?void 0:le.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:[t.jsx($a,{size:14}),m("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),t.jsx("input",{ref:q,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:le=>{le.target.files&&he(le.target.files),le.target.value=""}}),oe>0&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:m("plannerForm.images")}),t.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",oe,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[O.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?yu(s.id,le.id):"",alt:le.originalName,onClick:()=>s&&F(yu(s.id,le.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>pe(le.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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:le.originalName})})]},le.id)),L.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:le.preview,alt:le.name,onClick:()=>F(le.preview),className:"h-20 w-20 object-cover rounded-lg border border-blue-300/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>V(le.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:t.jsx(Qt,{size:12,strokeWidth:3})}),t.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 rounded-b-lg px-1 py-0.5",children:t.jsx("span",{className:"text-[8px] text-white truncate block",children:le.name})})]},le.id))]})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.tags")}),t.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(le=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-medium ${Fa(P.get(le)||"default")}`,children:[le,t.jsx("button",{onClick:()=>Z(le),className:"opacity-60 hover:opacity-100",children:t.jsx(Qt,{size:10})})]},le)),t.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[t.jsx("input",{ref:U,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:le=>{C(le.target.value),E(!0)},onKeyDown:le=>{(le.key==="Enter"||le.key===",")&&b.trim()&&(le.preventDefault(),W(b.replace(",",""))),le.key==="Backspace"&&!b&&u.length>0&&Z(u[u.length-1])},onFocus:()=>E(!0),onBlur:()=>setTimeout(()=>E(!1),150)}),R&&(Y.length>0||b.trim())&&t.jsxs(Dm,{anchorRef:U,width:208,onClose:()=>E(!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:[Y.slice(0,10).map(le=>t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>W(le.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded text-[11px] font-medium ${Fa(le.color)}`,children:le.name})},le.name)),b.trim()&&!e.some(le=>le.name===b.trim())&&t.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:t.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',b.trim(),'"']})})]})]})]})]}),t.jsxs("div",{className:`grid gap-3 mb-4 ${s?"grid-cols-3":"grid-cols-2"}`,children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full",value:S,onChange:le=>x(le.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:le=>w(Number(le.target.value)),children:[t.jsx("option",{value:0,children:m("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:m("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:m("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:m("plannerForm.priorityCritical")})]})]}),s&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full",value:k,onChange:le=>N(le.target.value),children:[t.jsx("option",{value:"pending",children:m("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:m("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:m("plannerStatus.done")})]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:m("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:ge,disabled:!o.trim()||D,children:m("plannerForm.save")})]}),I&&t.jsx(jp,{src:I,onClose:()=>F(null)})]})}function Z_({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:h}){const{t:f}=st(),[m,o]=_.useState(i||"claude"),[c,d]=_.useState(""),[p,u]=_.useState(!1),[v,b]=_.useState("once"),[C,S]=_.useState("0 0 * * *"),[x,y]=_.useState(""),[w,k]=_.useState(!1),N=async()=>{k(!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:v,cron_expression:v==="recurring"?C:void 0,run_at:v==="once"?x:void 0})}finally{k(!1)}};return t.jsx($n,{open:!0,onClose:h,size:"md",position:"top",animation:"slide-up",children:t.jsxs("div",{className:"card p-6",children:[t.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")}),t.jsxs("p",{className:"text-xs text-warm-500 mb-4 truncate",children:['"',e.title,'"']}),t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cliTool")}),t.jsxs("select",{className:"input-field text-xs w-full",value:m,onChange:D=>o(D.target.value),children:[t.jsx("option",{value:"claude",children:"Claude"}),t.jsx("option",{value:"antigravity",children:"Antigravity"}),t.jsx("option",{value:"codex",children:"Codex"})]})]}),s==="todo"&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.maxTurns")}),t.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:c,onChange:D=>d(D.target.value)})]}),s==="session"&&t.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:D=>u(D.target.checked)}),t.jsx("span",{className:"text-xs font-medium text-warm-500",children:f("plannerConvert.useWorktree")})]}),s==="schedule"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.scheduleType")}),t.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${v==="once"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("once"),children:f("plannerConvert.once")}),t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${v==="recurring"?"bg-amber-500 text-white":"text-warm-500"}`,onClick:()=>b("recurring"),children:f("plannerConvert.recurring")})]})]}),v==="once"?t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.runAt")}),t.jsx("input",{type:"datetime-local",className:"input-field text-xs w-full",value:x,onChange:D=>y(D.target.value)})]}):t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.cronExpression")}),t.jsx("input",{className:"input-field text-xs w-full font-mono",value:C,onChange:D=>S(D.target.value),placeholder:"0 0 * * *"})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:h,children:f("plannerConvert.cancel")}),t.jsx("button",{className:"btn-primary btn-sm",onClick:N,disabled:w||s==="schedule"&&v==="once"&&!x,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 Dy(e){return hn(new Date(e))}function Ry(e){return new Date(e.getFullYear(),e.getMonth(),1)}function eS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function yr(e,s){const i=eS(e);return i.setDate(i.getDate()+s),i}function tS(e){return yr(e,-e.getDay())}function zO(e,s){if(e==="day"){const f=eS(s);return{rangeStart:hn(f),rangeEnd:hn(yr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=tS(s),m=Array.from({length:7},(o,c)=>yr(f,c));return{rangeStart:hn(f),rangeEnd:hn(yr(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=Ry(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:hn(f),rangeEnd:hn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=Ry(s),a=yr(i,-i.getDay()),h=Array.from({length:42},(f,m)=>yr(a,m));return{rangeStart:hn(a),rangeEnd:hn(yr(a,42)),gridDays:h,cols:7,dimOutOfMonth:!0}}function nS(e,s){return _.useMemo(()=>zO(e,s),[e,s])}function sS(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 rS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=tS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${yr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function iS(){const{lang:e}=st();return _.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>yr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const PO=420,BO=140,IO=220,HO=26,$f=16,My=2;function FO(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 aS({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:v,onSelectDate:b,onQuickAdd:C,onChipClick:S,onCellContextMenu:x,onChipContextMenu:y,onBarContextMenu:w,monthCellHeight:k=92}){const{lang:N}=st(),[D,j]=_.useState(null),[R,E]=_.useState(!1),L=_.useRef(null),A=_.useRef(null),O=()=>{A.current&&(clearTimeout(A.current),A.current=null)},z=(q,X)=>{O(),L.current&&clearTimeout(L.current);const B=X.getBoundingClientRect();L.current=window.setTimeout(()=>j({key:q,rect:B}),PO)},I=()=>{L.current&&(clearTimeout(L.current),L.current=null),A.current=window.setTimeout(()=>j(null),BO)};_.useEffect(()=>{if(!D){E(!1);return}const q=requestAnimationFrame(()=>E(!0));return()=>cancelAnimationFrame(q)},[D]),_.useEffect(()=>()=>{L.current&&clearTimeout(L.current),A.current&&clearTimeout(A.current)},[]),_.useEffect(()=>{if(!D)return;const q=()=>j(null);return window.addEventListener("scroll",q,!0),window.addEventListener("resize",q),()=>{window.removeEventListener("scroll",q,!0),window.removeEventListener("resize",q)}},[D]);const F=D?o.get(D.key)??[]:[],H=(q,X)=>{const B=hn(q),P=o.get(B)??[],$=!a||q.getMonth()===h,Y=B===f,W=B===m,Z=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",he=e==="month"&&P.length>c;return t.jsxs("div",{onClick:()=>b(B),onContextMenu:x?re=>x(B,re):void 0,onMouseEnter:he?re=>z(B,re.currentTarget):void 0,onMouseLeave:he?I:void 0,className:`group relative ${Z} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?k+X:void 0,backgroundColor:W?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:$?1:.45},children:[t.jsxs("span",{className:"flex items-center gap-1.5",children:[e!=="month"&&t.jsx("span",{className:"text-2xs uppercase",style:{color:"var(--color-text-muted)"},children:q.toLocaleDateString(N,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:Y?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:q.getDate()})]}),t.jsx("button",{onClick:re=>{re.stopPropagation(),C(B)},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:t.jsx(mn,{size:13})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:X||void 0},children:[P.slice(0,c).map(re=>t.jsxs("span",{onClick:J=>{J.stopPropagation(),S(re)},onContextMenu:y?J=>y(re,J):void 0,className:"text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:re.bg,color:re.fg,textDecoration:re.done?"line-through":"none"},title:re.title,children:[re.prefix??"",re.time?`${re.time} `:"",re.title]},re.key)),P.length>c&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",P.length-c]})]})]},B)},U=[];if(e==="month")for(let q=0;q<s.length;q+=i)U.push(s.slice(q,q+i));return t.jsxs(t.Fragment,{children:[(e==="month"||e==="week")&&t.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(q=>t.jsx("div",{className:"px-2 py-1",children:q},q))}),e==="month"?t.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:U.map((q,X)=>{const{placed:B,laneCount:P}=FO(q,u??[]),$=P*($f+My);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[q.map(Y=>H(Y,$)),B.map(({bar:Y,startCol:W,endCol:Z,lane:he,contStart:re,contEnd:J})=>t.jsxs("div",{onClick:V=>{V.stopPropagation(),v==null||v(Y)},onContextMenu:w?V=>w(Y,V):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{left:`calc(${W} / ${i} * 100% + 2px)`,width:`calc(${Z-W+1} / ${i} * 100% - 4px)`,top:HO+he*($f+My),height:$f,backgroundColor:Y.bg,color:Y.fg,textDecoration:Y.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:re?0:4,borderBottomLeftRadius:re?0:4,borderTopRightRadius:J?0:4,borderBottomRightRadius:J?0:4},title:Y.title,children:[re?"◀ ":"",Y.title,J?" ▶":""]},Y.key))]},X)})}):t.jsx("div",{className:"grid gap-px rounded-xl overflow-hidden",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:s.map(q=>H(q,0))}),D&&(()=>{const q=Math.max(D.rect.width,IO),X=Math.min(Math.max(8,D.rect.left),window.innerWidth-q-8),B=Math.max(8,Math.min(D.rect.top,window.innerHeight-120)),P=window.innerHeight-B-16,$=Number(D.key.slice(8,10));return rn.createPortal(t.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:O,onMouseLeave:()=>j(null),style:{position:"fixed",left:X,top:B,width:q,maxHeight:P,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:R?"scale(1)":"scale(0.96)",opacity:R?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[t.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:$}),t.jsx("div",{className:"flex flex-col gap-0.5",children:F.map(Y=>t.jsxs("span",{onClick:W=>{W.stopPropagation(),S(Y),j(null)},onContextMenu:y?W=>y(Y,W):void 0,className:"text-2xs truncate px-1 py-0.5 rounded cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:Y.bg,color:Y.fg,textDecoration:Y.done?"line-through":"none"},title:Y.title,children:[Y.prefix??"",Y.time?`${Y.time} `:"",Y.title]},Y.key))})]}),document.body)})()]})}const Ay={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 $O(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function UO({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:h,onConvert:f,onDeleteItem:m}){const{t:o,lang:c}=st(),[d,p]=_.useState(()=>new Date),[u,v]=_.useState(()=>hn(new Date)),[b,C]=_.useState(null),S=iS(),{gridDays:x,cols:y,dimOutOfMonth:w}=nS(e,d),k=hn(new Date),N=d.getMonth(),D=e==="month"?3:99,j=X=>p(B=>sS(B,e,X)),R=()=>{p(new Date),v(hn(new Date))},E=rS(d,e,c);_.useEffect(()=>{e==="day"&&v(hn(d))},[e,d]);const L=260,A=760,O=_.useRef(null),[z,I]=_.useState(()=>{const X=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(X)&&X>=L&&X<=A?X:320});_.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(z))}catch{}},[z]);const F=X=>{X.preventDefault();const B=$=>{var W;const Y=(W=O.current)==null?void 0:W.getBoundingClientRect();Y&&I(Math.min(A,Math.max(L,Y.right-$.clientX)))},P=()=>{window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",P),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",B),window.addEventListener("pointerup",P)},H=_.useMemo(()=>{const X=new Map;for(const B of s){if(!B.due_date)continue;const P=B.due_date.slice(0,10),$=B.status==="done",Y=X.get(P)??[];Y.push({key:B.id,title:B.title,bg:"var(--color-bg-secondary)",fg:$?"var(--color-text-muted)":"var(--color-text-secondary)",done:$,payload:B}),X.set(P,Y)}return X},[s]),U=_.useMemo(()=>s.filter(X=>X.due_date&&X.due_date.slice(0,10)===u),[s,u]),q=_.useMemo(()=>s.filter(X=>!X.due_date),[s]);return t.jsxs("div",{ref:O,className:"card flex overflow-hidden",style:{minHeight:520},children:[t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[t.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>j(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(Fm,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:E}),t.jsx("button",{onClick:()=>j(1),className:"btn-ghost p-1.5","aria-label":"next",children:t.jsx(Ts,{size:16})}),t.jsx("button",{onClick:R,className:"btn-ghost text-xs px-2.5 py-1.5",children:o("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(aS,{view:e,gridDays:x,cols:y,dimOutOfMonth:w,monthIdx:N,todayKey:k,selectedDate:u,chipsByDay:H,maxChips:D,weekdayLabels:S,addItemLabel:o("agenda.addItem"),onSelectDate:v,onQuickAdd:a,onChipClick:X=>h(X.payload),onCellContextMenu:(X,B)=>{B.preventDefault(),C({x:B.clientX,y:B.clientY,dateKey:X})}})})]}),t.jsx("div",{onPointerDown:F,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:o("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:z},children:[t.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center justify-between",children:[t.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--color-text-primary)"},children:new Date(u+"T00:00").toLocaleDateString(c,{month:"long",day:"numeric",weekday:"short"})}),t.jsxs("button",{onClick:()=>a(u),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[t.jsx(mn,{size:13}),o("agenda.add")]})]}),t.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[U.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:o("agenda.dayEmpty")}),U.map(X=>t.jsx(Oy,{item:X,tagColors:i,onEdit:h,onConvert:f,onDelete:m},X.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:o("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[q.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:o("agenda.backlogEmpty")}),q.map(X=>t.jsx(Oy,{item:X,tagColors:i,onEdit:h,onConvert:f,onDelete:m},X.id))]})]})]})]}),b&&t.jsx(Cr,{x:b.x,y:b.y,onClose:()=>C(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>a(b.dateKey),children:[t.jsx(mn,{size:14}),o("planner.add")]})})]})}function Oy({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:h}){const{t:f}=st(),[m,o]=_.useState(!1),[c,d]=_.useState(!1),[p,u]=_.useState({top:0,left:0}),v=_.useRef(null),b=_.useRef(null),C=$O(e.tags),S=e.status==="moved",x=_.useCallback(()=>{if(!v.current)return;const y=v.current.getBoundingClientRect(),w=window.innerWidth,k=window.innerHeight;let N=y.bottom+4;const D=b.current;if(D){const j=D.offsetWidth,R=D.offsetHeight;let E=y.right-j;E<8&&(E=8),E+j>w-8&&(E=w-8-j),N+R>k-8&&(N=y.top-R-4),u({top:N,left:E}),d(!0)}else u({top:N,left:Math.max(8,y.right-180)})},[]);return _.useEffect(()=>{if(!m){d(!1);return}x();const y=requestAnimationFrame(x),w=k=>{var D,j;const N=k.target;(D=v.current)!=null&&D.contains(N)||(j=b.current)!=null&&j.contains(N)||o(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{cancelAnimationFrame(y),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[m,x]),t.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:[t.jsxs("button",{onClick:()=>i(e),className:"flex-1 text-left min-w-0",children:[t.jsx("div",{className:"text-sm truncate",style:{color:"var(--color-text-primary)",textDecoration:e.status==="done"?"line-through":"none"},children:e.title}),e.description&&t.jsx("div",{className:"text-2xs truncate",style:{color:"var(--color-text-muted)"},children:e.description}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[t.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-2xs font-medium ${Ay[e.status]||Ay.pending}`,children:f(`plannerStatus.${e.status}`)}),C.map(y=>t.jsx("span",{className:`px-1.5 py-0.5 rounded text-2xs font-medium ${Fa(s.get(y)||"default")}`,children:y},y))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:v,onClick:y=>{y.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:t.jsx(Um,{size:14})}),m&&rn.createPortal(t.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&&t.jsxs(t.Fragment,{children:[t.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:[t.jsx(kw,{size:12})," ",f("planner.convertToTask")]}),t.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:[t.jsx(oi,{size:12})," ",f("planner.convertToSchedule")]}),t.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:[t.jsx(di,{size:12})," ",f("planner.convertToTerminal")]})]}),t.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:[t.jsx(jn,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const zy={pending:0,in_progress:1,done:2,moved:3};function WO({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:v,view:b,onChangeView:C}){const{t:S}=st(),[x,y]=_.useState(!1),[w,k]=_.useState(null),[N,D]=_.useState(void 0),[j,R]=_.useState(""),[E,L]=_.useState(""),[A,O]=_.useState("created_at"),[z,I]=_.useState("desc"),[F,H]=_.useState(null),[U,q]=_.useState("todo"),[X,B]=_.useState(!1),[P,$]=_.useState(!1),[Y,W]=_.useState(null),Z=_.useRef(null),he=_.useRef(0),re=async()=>{if(!(!u||X)){B(!0);try{await u()}finally{B(!1)}}},J=()=>{var be;!v||X||(be=Z.current)==null||be.click()},V=async be=>{var Fe;const De=(Fe=be.target.files)==null?void 0:Fe[0];if(be.target.value="",!(!De||!v)){B(!0);try{await v(De)}finally{B(!1)}}},pe=be=>!!(/\.(md|markdown)$/i.test(be.name)||be.type==="text/markdown"),oe=be=>Array.from(be.dataTransfer.types).includes("Files"),ge=be=>{!v||X||oe(be)&&(be.preventDefault(),he.current++,$(!0))},le=be=>{!v||X||oe(be)&&(be.preventDefault(),be.dataTransfer.dropEffect="copy")},Oe=be=>{v&&(be.preventDefault(),he.current=Math.max(0,he.current-1),he.current===0&&$(!1))},He=async be=>{var Fe;if(!v||(be.preventDefault(),he.current=0,$(!1),X))return;const De=(Fe=be.dataTransfer.files)==null?void 0:Fe[0];if(De){if(!pe(De)){window.alert(S("planner.dropInvalidFile"));return}B(!0);try{await v(De)}finally{B(!1)}}},Te=_.useMemo(()=>s.map(be=>be.name),[s]),ye=_.useMemo(()=>new Map(s.map(be=>[be.name,be.color])),[s]),ke=_.useMemo(()=>{let be=e.filter(De=>!(E&&De.status!==E||j&&!(De.tags?(()=>{try{return JSON.parse(De.tags)}catch{return[]}})():[]).includes(j)));return be=[...be].sort((De,Fe)=>{let qe=0;switch(A){case"title":qe=De.title.localeCompare(Fe.title);break;case"tags":{const Qe=De.tags?(()=>{try{return JSON.parse(De.tags).join(",")}catch{return""}})():"",nt=Fe.tags?(()=>{try{return JSON.parse(Fe.tags).join(",")}catch{return""}})():"";qe=(Qe||"zzz").localeCompare(nt||"zzz");break}case"priority":qe=De.priority-Fe.priority;break;case"due_date":{const Qe=De.due_date||"9999",nt=Fe.due_date||"9999";qe=Qe.localeCompare(nt);break}case"status":qe=(zy[De.status]??9)-(zy[Fe.status]??9);break;case"created_at":qe=De.created_at.localeCompare(Fe.created_at);break}return z==="asc"?qe:-qe}),be},[e,j,E,A,z]),Ke=be=>{A===be?I(De=>De==="asc"?"desc":"asc"):(O(be),I(be==="priority"?"desc":"asc"))},$e=({field:be})=>A!==be?null:z==="asc"?t.jsx(Nj,{size:10,className:"inline ml-0.5"}):t.jsx(_j,{size:10,className:"inline ml-0.5"});return t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-5 gap-3 flex-wrap",children:[t.jsxs("h2",{className:"text-sm font-semibold text-warm-600 uppercase tracking-wider",children:[S("planner.title"),t.jsx("span",{className:"ml-1 text-warm-400",children:e.length})]}),t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b!=="table"&&t.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(be=>t.jsx("button",{onClick:()=>C(be),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:b===be?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:S(`agenda.view.${be}`)},be))}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:j,onChange:be=>R(be.target.value),children:[t.jsx("option",{value:"",children:S("planner.filterTag")}),Te.map(be=>t.jsx("option",{value:be,children:be},be))]}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:E,onChange:be=>L(be.target.value),children:[t.jsx("option",{value:"",children:S("planner.filterStatus")}),t.jsx("option",{value:"pending",children:S("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:S("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:S("plannerStatus.done")}),t.jsx("option",{value:"moved",children:S("plannerStatus.moved")})]}),u&&t.jsxs("button",{onClick:re,disabled:X||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.exportTooltip"),children:[t.jsx(Qf,{size:14,className:"inline-block shrink-0"}),S("planner.export")]}),v&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:J,disabled:X,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:S("planner.importTooltip"),children:[t.jsx(Ov,{size:14,className:"inline-block shrink-0"}),S("planner.import")]}),t.jsx("input",{ref:Z,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:V})]}),!x&&!w&&t.jsxs("button",{onClick:()=>y(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(mn,{size:14,className:"inline-block shrink-0"}),S("planner.add")]})]})]}),(x||w)&&t.jsx("div",{className:"mb-5",children:t.jsx(OO,{existingTags:s,editItem:w,initialDueDate:N,onSave:async be=>{if(w){await h(w.id,be),k(null);return}else{const De=await a(be);return y(!1),D(void 0),De}},onCancel:()=>{y(!1),k(null),D(void 0)},onUpdateTag:d})}),b==="table"?t.jsxs("div",{className:"card relative",onDragEnter:v?ge:void 0,onDragOver:v?le:void 0,onDragLeave:v?Oe:void 0,onDrop:v?He:void 0,onContextMenu:be=>{hi(be)||(be.preventDefault(),W({x:be.clientX,y:be.clientY}))},children:[P&&t.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:t.jsxs("div",{className:"text-center",children:[t.jsx(Ov,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),t.jsx("div",{className:"text-sm font-semibold",children:S("planner.dropHint")}),t.jsx("div",{className:"text-xs text-warm-500 mt-1",children:S("planner.dropHintSub")})]})}),t.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:[t.jsx("div",{className:"w-[14px] flex-shrink-0"}),t.jsxs("div",{className:"flex-1 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>Ke("title"),children:[S("planner.col.title"),t.jsx($e,{field:"title"})]}),t.jsxs("div",{className:"w-[160px] text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>Ke("tags"),children:[S("planner.col.tags"),t.jsx($e,{field:"tags"})]}),t.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:()=>Ke("priority"),children:[S("plannerForm.priority"),t.jsx($e,{field:"priority"})]}),t.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:()=>Ke("due_date"),children:[S("planner.col.dueDate"),t.jsx($e,{field:"due_date"})]}),t.jsxs("div",{className:"w-16 text-2xs font-semibold text-warm-500 uppercase tracking-wider cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>Ke("status"),children:[S("planner.col.status"),t.jsx($e,{field:"status"})]}),t.jsx("div",{className:"w-8"})]}),ke.length===0?t.jsx(Yi,{icon:J5,title:S("planner.empty"),description:S("planner.emptyHint")}):ke.map((be,De)=>t.jsx("div",{className:"animate-slide-up",style:{animationDelay:`${De*20}ms`},children:t.jsx(MO,{item:be,tagColors:ye,existingTags:Te,onSave:async(Fe,qe)=>{await h(Fe,qe)},onDelete:()=>f(be.id),onConvertToTodo:()=>{H(be),q("todo")},onConvertToSchedule:()=>{H(be),q("schedule")},onConvertToSession:()=>{H(be),q("session")},onUpdateTag:d})},be.id))]}):t.jsx(UO,{view:b,items:ke,tagColors:ye,onQuickAdd:be=>{k(null),D(be),y(!0)},onEditItem:be=>{y(!1),k(be)},onConvert:(be,De)=>{H(be),q(De)},onDeleteItem:f}),F&&t.jsx(Z_,{item:F,mode:U,projectCliTool:i,onConvert:async be=>{U==="todo"?await m(F.id,be):U==="session"?await c(F.id,be):await o(F.id,be),H(null)},onClose:()=>H(null)}),Y&&t.jsx(Cr,{x:Y.x,y:Y.y,onClose:()=>W(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>{k(null),D(void 0),y(!0)},children:[t.jsx(mn,{size:14}),S("planner.add")]})})]})}const oS=_.createContext(null),GO=oS.Provider;function tB(){const e=_.useContext(oS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const qO=_.lazy(()=>Fu(()=>import("./PlannerPageEditor-Cvdr9ckv.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),KO=800;function VO({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:h,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:c}=st(),[d,p]=_.useState(null),[u,v]=_.useState("idle"),[b,C]=_.useState(null),S=_.useRef({title:"",content:null}),x=_.useRef(null);_.useEffect(()=>{let j=!1;return l4(e).then(R=>{j||(p(R),S.current={title:R.title,content:R.content??null})}),()=>{j=!0}},[e]);const y=_.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:j,content:R}=S.current;return v("saving"),c4(e,{title:j,content:R??void 0}).then(()=>v("saved"))},[e]);_.useEffect(()=>()=>{x.current&&y()},[y]);const w=_.useCallback(()=>{x.current&&clearTimeout(x.current),v("saving"),x.current=setTimeout(()=>{y()},KO)},[y]),k=j=>{S.current.title=j,p(R=>R&&{...R,title:j}),h(e,j),w()},N=j=>{S.current.content=j,w()},D=_.useCallback((j,R,E)=>{C({item:j,mode:R,onDone:E})},[]);return d?t.jsxs(GO,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:D},children:[t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[t.jsx("input",{value:d.title,onChange:j=>k(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)"}}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:u==="saving"?c("planner.pages.saving"):u==="saved"?c("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(_.Suspense,{fallback:null,children:t.jsx(qO,{initialContent:d.content??null,onChange:N})})})]}),b&&t.jsx(Z_,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:R,mode:E,onDone:L}=b;E==="todo"?await f(R.id,j):E==="session"?await o(R.id,j):await m(R.id,j),L==null||L(),C(null)},onClose:()=>C(null)})]}):null}const kn=(e,s)=>({type:"heading",props:{level:e},content:s}),Jo=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},Py=e=>({type:"bulletListItem"}),Bi=e=>({type:"checkListItem"}),By=()=>({type:"tasklist"}),Iy=()=>({type:"calendar"}),YO=[{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:[kn(1,"회의 노트"),Jo("📅 날짜: "),Jo("👥 참석자: "),kn(2,"안건"),Py(),kn(2,"논의"),Jo(),kn(2,"액션 아이템"),By()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[kn(1,"프로젝트 플랜"),kn(2,"개요"),Jo(),kn(2,"마일스톤"),By(),kn(2,"일정"),Iy(),kn(2,"리스크 / 메모"),Jo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[kn(1,"위클리 플래너"),kn(2,"이번 주 목표"),Py(),kn(2,"요일별 할 일"),kn(3,"월요일"),Bi(),kn(3,"화요일"),Bi(),kn(3,"수요일"),Bi(),kn(3,"목요일"),Bi(),kn(3,"금요일"),Bi(),kn(3,"토요일"),Bi(),kn(3,"일요일"),Bi(),kn(2,"주간 일정"),Iy()]}];function XO({onResize:e}){return t.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 Hy=160,Fy=480,$y="plannerSidebarWidth";function JO({projectId:e,...s}){const{t:i}=st(),[a,h]=_.useState([]),[f,m]=_.useState({kind:"work"}),[o,c]=_.useState("table"),[d,p]=_.useState(!1),[u,v]=_.useState({top:0,left:0}),b=_.useRef(null),C=_.useRef(null),S=_.useRef(!1),[x,y]=_.useState(()=>{const F=Number(localStorage.getItem($y));return F>=Hy&&F<=Fy?F:208}),w=_.useCallback(F=>{var q;const H=((q=C.current)==null?void 0:q.getBoundingClientRect().left)??0,U=Math.round(Math.max(Hy,Math.min(Fy,F-H)));y(U),localStorage.setItem($y,String(U))},[]),k=240,N=()=>{var H;const F=(H=b.current)==null?void 0:H.getBoundingClientRect();if(F){const U=Math.min(F.left,window.innerWidth-k-8);v({top:F.bottom+4,left:Math.max(8,U)})}p(!0)};_.useEffect(()=>{if(!d)return;const F=()=>p(!1),H=U=>{var q;(q=b.current)!=null&&q.contains(U.target)||U.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]),_.useEffect(()=>{a4(e).then(F=>{h(F),S.current||(S.current=!0,F.length>0&&m({kind:"page",id:F[0].id}))})},[e]);const D=async F=>{p(!1);const H=await o4(e,F.title||i("planner.pages.untitled"),F.blocks?JSON.stringify(F.blocks):void 0);h(U=>[...U,H]),m({kind:"page",id:H.id})},j=async F=>{confirm(i("planner.pages.deleteConfirm"))&&(await u4(F),h(H=>H.filter(U=>U.id!==F)),m(H=>H.kind==="page"&&H.id===F?{kind:"work"}:H))},R=_.useCallback((F,H)=>{h(U=>U.map(q=>q.id===F?{...q,title:H}:q))},[]),E=()=>{m({kind:"work"}),c(F=>F==="table"?"month":F)},L=()=>{m({kind:"work"}),c("table")},A=f.kind==="work",O=A&&o!=="table",z=A&&o==="table",I=(F,H,U,q,X)=>t.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:[U,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:q}),X]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[t.jsxs("div",{ref:C,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:x},children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),t.jsx("button",{ref:b,onClick:()=>d?p(!1):N(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(mn,{size:14})})]}),a.map(F=>I(f.kind==="page"&&f.id===F.id,()=>m({kind:"page",id:F.id}),t.jsx(Ui,{size:13,className:"text-warm-400 flex-shrink-0"}),F.title||i("planner.pages.untitled"),t.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:t.jsx(jn,{size:13})}))),t.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")}),I(O,E,t.jsx(Jf,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),I(z,L,t.jsx(gu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(XO,{onResize:w}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:f.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(VO,{pageId:f.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:R,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},f.id)}):t.jsx(WO,{...s,view:o,onChangeView:c})}),d&&rn.createPortal(t.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:k,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:YO.map(F=>t.jsxs("button",{onClick:()=>D(F),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[t.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:i(F.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(F.descKey)})]},F.id))}),document.body)]})}const QO=_.lazy(()=>Fu(()=>import("./AnalyticsPanel-CyIM0XTT.js"),__vite__mapDeps([9,7,3,2]))),ZO=_.lazy(()=>Fu(()=>import("./VaultLayout-DrDkpfva.js"),__vite__mapDeps([10,6,1,2,3,4])));function ez({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:h}=Om(),[f,m]=_.useState(null),[o,c]=_.useState([]),[d,p]=_.useState([]),[u,v]=_.useState(null),[b,C]=_.useState([]),[S,x]=_.useState([]),[y,w]=_.useState([]),[k,N]=_.useState([]),[D,j]=ww(),R=["tasks","discussions","schedules","analytics"],E=D.get("tab")||"tasks",[L,A]=_.useState(R.includes(E)?"automation":E),[O,z]=_.useState(R.includes(E)?E:"tasks"),I=_.useCallback(de=>{if(de==="automation"){A("automation"),j(O==="tasks"?{}:{tab:O},{replace:!0});return}A(de),j(de==="tasks"?{}:{tab:de},{replace:!0})},[j,O]),F=_.useCallback(de=>{A("automation"),z(de),j(de==="tasks"?{}:{tab:de},{replace:!0})},[j]),[H,U]=_.useState(!0),[q,X]=_.useState(!1),[B,P]=_.useState(new Set),[$,Y]=_.useState(0),{t:W}=st(),{sendNotification:Z}=Km(),he=_.useRef([]);_.useEffect(()=>{he.current=b},[b]),_.useEffect(()=>{h&&Promise.all([sE(h),ff(h),Zv(h),eb(h),D3(),c1(h),Hc(h),Fc(h)]).then(([de,Re,Ee,ve,at,vt,Ct,Tt])=>{m(de),c(Re),p(Ee),C(ve),x(vt),w(Ct),N(Tt),at.resetsAt&&v(at.resetsAt);const Nt=Re.filter(Ft=>Ft.status==="running"&&Ft.execution_mode==="interactive").map(Ft=>Ft.id);Nt.length>0&&P(new Set(Nt))}).catch(()=>X(!0)).finally(()=>U(!1))},[h]);const re=_.useRef(o);re.current=o,_.useEffect(()=>{if(!h)return;const de=setInterval(()=>{re.current.some(Ee=>Ee.status==="running")&&ff(h).then(Ee=>{c(ve=>ve.map(at=>{const vt=Ee.find(Ct=>Ct.id===at.id);return vt&&vt.status!==at.status?vt:at}))}).catch(()=>{})},5e3);return()=>clearInterval(de)},[h]);const J=_.useRef(s);_.useEffect(()=>{s&&!J.current&&h&&Promise.all([ff(h),Zv(h),eb(h)]).then(([de,Re,Ee])=>{c(de),p(Re),C(Ee)}).catch(()=>{}),J.current=s},[s,h]),_.useEffect(()=>e(de=>{if(de.type==="todo:status-changed"&&de.todoId&&de.status){if(c(Re=>Re.map(Ee=>{if(Ee.id!==de.todoId)return Ee;const ve={status:de.status,updated_at:new Date().toISOString()};return de.worktree_path!==void 0&&(ve.worktree_path=de.worktree_path??null),de.branch_name!==void 0&&(ve.branch_name=de.branch_name??null),{...Ee,...ve}})),(de.status==="completed"||de.status==="merged"||de.status==="failed")&&Y(Re=>Re+1),de.status==="completed"||de.status==="failed"){const Re=re.current.find(Ee=>Ee.id===de.todoId);Re&&Z(de.status==="completed"?W("notification.taskCompleted"):W("notification.taskFailed"),Re.title)}de.status==="running"&&de.mode==="interactive"?P(Re=>new Set(Re).add(de.todoId)):de.status!=="running"&&P(Re=>{const Ee=new Set(Re);return Ee.delete(de.todoId),Ee})}if(de.type==="schedule:status-changed"&&de.scheduleId&&p(Re=>Re.map(Ee=>Ee.id===de.scheduleId?{...Ee,is_active:de.isActive?1:0,updated_at:new Date().toISOString()}:Ee)),de.type==="rate-limit:updated"&&de.resetsAt&&v(de.resetsAt),de.type==="discussion:status-changed"&&de.discussionId&&(C(Re=>Re.map(Ee=>Ee.id===de.discussionId?{...Ee,status:de.status,current_round:de.currentRound??Ee.current_round,updated_at:new Date().toISOString()}:Ee)),de.status==="completed"||de.status==="failed")){const Re=he.current.find(Ee=>Ee.id===de.discussionId);Re&&Z(de.status==="completed"?W("notification.discussionCompleted"):W("notification.discussionFailed"),Re.title)}de.type==="session:status-changed"&&de.sessionId&&x(Re=>Re.map(Ee=>{if(Ee.id!==de.sessionId)return Ee;const ve={status:de.status,updated_at:new Date().toISOString()};return de.worktree_path!==void 0&&(ve.worktree_path=de.worktree_path),de.branch_name!==void 0&&(ve.branch_name=de.branch_name),{...Ee,...ve}}))}),[e,Z,W]);const V=_.useCallback(async(de,Re,Ee,ve,at,vt,Ct,Tt,Nt,Ft)=>{if(!h)return;const Dn=await mf(h,{title:de,description:Re,cli_tool:Ee,depends_on:at,max_turns:vt??null,use_worktree:Ct??null,...Tt?{memory_inject_mode:Tt}:{},...Nt?{memory_node_ids:Nt}:{},...Ft?{memory_raw_file_paths:Ft}:{}});if(ve&&ve.length>0){const Wn=await i1(Dn.id,ve.map(In=>({name:In.name,data:In.data})));Dn.images=JSON.stringify(Wn.images)}c(Wn=>[...Wn,Dn])},[h]),pe=_.useCallback((de,Re=[])=>{const Ee=de.split("/").filter(Boolean).pop()??de,ve=[de,...Re].map(at=>`@${at}`).join(`
666
666
  `);return V(Ee,`다음 파일을 참고하세요:
667
667
  ${ve}`)},[V]),oe=_.useCallback(async(de,Re)=>{const Ee=Re==="interactive";Ee&&P(ve=>new Set(ve).add(de));try{const ve=await Qv(de,Re);c(at=>at.map(vt=>vt.id===de?ve:vt))}catch(ve){throw Ee&&P(at=>{const vt=new Set(at);return vt.delete(de),vt}),ve}},[]),ge=_.useCallback(async de=>{const Re=await v3(de);c(Ee=>Ee.map(ve=>ve.id===de?Re:ve))},[]),le=_.useCallback(async de=>{await e1(de),c(Re=>Re.filter(Ee=>Ee.id!==de))},[]),Oe=_.useCallback(async(de,Re,Ee,ve,at,vt,Ct,Tt,Nt,Ft)=>{const Dn=await Ic(de,{title:Re,description:Ee,cli_tool:ve,depends_on:at??null,max_turns:vt??null,use_worktree:Ct===void 0?null:Ct,...Tt?{memory_inject_mode:Tt}:{},...Nt?{memory_node_ids:Nt}:{},...Ft?{memory_raw_file_paths:Ft}:{}});c(Wn=>Wn.map(In=>In.id===de?Dn:In))},[]),He=_.useCallback(async de=>{await n1(de),c(Re=>Re.map(Ee=>Ee.id===de?{...Ee,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:Ee))},[]),Te=_.useCallback(async de=>{const Re=await w3(de),Ee=new Set(Re.mergedIds);c(ve=>ve.map(at=>Ee.has(at.id)?{...at,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:at))},[]),ye=_.useCallback(async(de,Re=!1)=>{await s1(de,Re),c(Ee=>Ee.map(ve=>ve.id===de?{...ve,worktree_path:null,...Re?{branch_name:null}:{},updated_at:new Date().toISOString()}:ve))},[]),ke=_.useCallback(async(de,Re)=>{const Ee=Re==="interactive";Ee&&P(ve=>new Set(ve).add(de));try{const ve=await _3(de,Re);c(at=>at.map(vt=>vt.id===de?ve:vt))}catch(ve){throw Ee&&P(at=>{const vt=new Set(at);return vt.delete(de),vt}),ve}},[]),Ke=_.useCallback(async(de,Re,Ee)=>{const ve=Ee==="interactive";ve&&P(at=>new Set(at).add(de));try{const at=await r1(de,Re,Ee);c(vt=>vt.map(Ct=>Ct.id===de?at:Ct))}catch(at){throw ve&&P(vt=>{const Ct=new Set(vt);return Ct.delete(de),Ct}),at}},[]),$e=_.useCallback(async(de,Re,Ee)=>{const ve=await j3(de,Re,Ee);ve.original_deleted&&c(at=>at.filter(vt=>vt.id!==de)),p(at=>[ve.schedule,...at])},[]),be=_.useCallback(async(de,Re)=>{const Ee=await R3(de,Re);p(ve=>[Ee.schedule,...ve])},[]),De=_.useCallback((de,Re)=>{i({type:"todo:stdin",todoId:de,input:Re})},[i]),Fe=_.useCallback(async(de,Re)=>{const Ee=await Ic(de,{depends_on:Re});c(ve=>ve.map(at=>at.id===de?Ee:at))},[]),qe=_.useCallback(async de=>{const Re=de.map((Ee,ve)=>({id:Ee,priority:ve}));c(Ee=>Ee.map(ve=>{const at=Re.find(vt=>vt.id===ve.id);return at?{...ve,priority:at.priority}:ve})),await Promise.all(Re.map(Ee=>Ic(Ee.id,{priority:Ee.priority})))},[]),Qe=_.useCallback(async(de,Re,Ee)=>{await Ic(de,{position_x:Re,position_y:Ee}),c(ve=>ve.map(at=>at.id===de?{...at,position_x:Re,position_y:Ee}:at))},[]),nt=_.useCallback(async(de,Re)=>{if(!h)return;const Ee=Re.map(Ct=>Ct.message).join(`
668
668
  `),ve=`The previous task "${de.title}" failed with the following errors: