clitrigger 0.2.62 → 0.2.63

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.
Files changed (44) hide show
  1. package/dist/client/assets/{AnalyticsPanel-CP-29VIV.js → AnalyticsPanel-DtuQq2KX.js} +1 -1
  2. package/dist/client/assets/{FloatingComposerController-5A3GJtK4-964OUsel.js → FloatingComposerController-5A3GJtK4-B4wUxMjg.js} +1 -1
  3. package/dist/client/assets/{PlannerPageEditor-tQ8cSsEl.js → PlannerPageEditor-BO6Tm17g.js} +3 -3
  4. package/dist/client/assets/{TaskGraph-DVvS2YsK.js → TaskGraph-BJfyaO8u.js} +1 -1
  5. package/dist/client/assets/{VaultLayout-D9R8grOG.js → VaultLayout-DH6m6VLs.js} +1 -1
  6. package/dist/client/assets/{index-B_c_NGU8.js → index-B2zvNYwl.js} +4 -4
  7. package/dist/client/assets/{style-2Q6xFyWI.js → style-BlI6Zxrd.js} +1 -1
  8. package/dist/client/assets/{with-selector-BOuuo9Zj.js → with-selector-XYAE1sJo.js} +1 -1
  9. package/dist/client/index.html +1 -1
  10. package/dist/server/db/connection.d.ts.map +1 -1
  11. package/dist/server/db/connection.js +4 -0
  12. package/dist/server/db/connection.js.map +1 -1
  13. package/dist/server/db/queries.d.ts +14 -0
  14. package/dist/server/db/queries.d.ts.map +1 -1
  15. package/dist/server/db/queries.js +36 -3
  16. package/dist/server/db/queries.js.map +1 -1
  17. package/dist/server/db/schema.d.ts.map +1 -1
  18. package/dist/server/db/schema.js +14 -0
  19. package/dist/server/db/schema.js.map +1 -1
  20. package/dist/server/index.d.ts.map +1 -1
  21. package/dist/server/index.js +2 -0
  22. package/dist/server/index.js.map +1 -1
  23. package/dist/server/routes/sessions.js +2 -2
  24. package/dist/server/routes/sessions.js.map +1 -1
  25. package/dist/server/services/claude-manager.d.ts.map +1 -1
  26. package/dist/server/services/claude-manager.js +6 -16
  27. package/dist/server/services/claude-manager.js.map +1 -1
  28. package/dist/server/services/debug-logger.d.ts.map +1 -1
  29. package/dist/server/services/debug-logger.js +14 -16
  30. package/dist/server/services/debug-logger.js.map +1 -1
  31. package/dist/server/services/project-status.d.ts.map +1 -1
  32. package/dist/server/services/project-status.js +1 -14
  33. package/dist/server/services/project-status.js.map +1 -1
  34. package/dist/server/services/pty-output-filter.d.ts.map +1 -1
  35. package/dist/server/services/pty-output-filter.js +8 -3
  36. package/dist/server/services/pty-output-filter.js.map +1 -1
  37. package/dist/server/services/session-manager.d.ts +0 -10
  38. package/dist/server/services/session-manager.d.ts.map +1 -1
  39. package/dist/server/services/session-manager.js +3 -121
  40. package/dist/server/services/session-manager.js.map +1 -1
  41. package/dist/server/services/worktree-manager.d.ts.map +1 -1
  42. package/dist/server/services/worktree-manager.js +7 -3
  43. package/dist/server/services/worktree-manager.js.map +1 -1
  44. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-DVvS2YsK.js","assets/style-2Q6xFyWI.js","assets/value-BTdN53H7.js","assets/with-selector-BOuuo9Zj.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-tQ8cSsEl.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-CP-29VIV.js","assets/VaultLayout-D9R8grOG.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-BJfyaO8u.js","assets/style-BlI6Zxrd.js","assets/value-BTdN53H7.js","assets/with-selector-XYAE1sJo.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-BO6Tm17g.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-DtuQq2KX.js","assets/VaultLayout-DH6m6VLs.js"])))=>i.map(i=>d[i]);
2
2
  var u2=Object.defineProperty;var d2=(e,s,i)=>s in e?u2(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var R0=(e,s,i)=>d2(e,typeof s!="symbol"?s+"":s,i);function h2(e,s){for(var i=0;i<s.length;i++){const a=s[i];if(typeof a!="string"&&!Array.isArray(a)){for(const u in a)if(u!=="default"&&!(u in e)){const f=Object.getOwnPropertyDescriptor(a,u);f&&Object.defineProperty(e,u,f.get?f:{enumerable:!0,get:()=>a[u]})}}}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 u of document.querySelectorAll('link[rel="modulepreload"]'))a(u);new MutationObserver(u=>{for(const f of u)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(u){const f={};return u.integrity&&(f.integrity=u.integrity),u.referrerPolicy&&(f.referrerPolicy=u.referrerPolicy),u.crossOrigin==="use-credentials"?f.credentials="include":u.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function a(u){if(u.ep)return;u.ep=!0;const f=i(u);fetch(u.href,f)}})();var FP=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function El(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var df={exports:{}},Xo={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -609,7 +609,7 @@ Cancel = delete worktree only`,"todo.retry":"Retry","todo.retryDesc":"Cleans up
609
609
  *
610
610
  * This source code is licensed under the ISC license.
611
611
  * See the LICENSE file in the root directory of this source tree.
612
- */const VN=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],YN=ft("zoom-out",VN),lb=8;function XN({onLogin:e,onChangePassword:s}){const[i,a]=y.useState(""),[u,f]=y.useState(""),[m,o]=y.useState(""),[l,h]=y.useState(!1),[p,d]=y.useState(!1),[g,v]=y.useState(!1),[C,k]=y.useState(""),[x,S]=y.useState(!1),{t:_,toggleLang:w}=xt(),j=l&&u.length>0&&u.length<lb,R=l&&m.length>0&&u!==m,E=l?!!i&&u.length>=lb&&u===m:!!i,D=()=>{h(T=>!T),f(""),o(""),k("")},N=async T=>{if(T.preventDefault(),!(!E||x)){k(""),S(!0);try{l?await s(i,u,m,g):await e(i,g)}catch(z){k(l&&z instanceof Error&&z.message?z.message:_("login.error"))}finally{S(!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:w,className:"lang-toggle absolute top-6 right-6",children:_("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm",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(wl,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:_("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:_("login.subtitle")})]}),t.jsx("form",{onSubmit:N,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:_(l?"account.oldPassword":"login.password")}),t.jsx("input",{type:"password",value:i,onChange:T=>a(T.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),l&&t.jsxs(t.Fragment,{children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.newPassword")}),t.jsx("input",{type:"password",value:u,onChange:T=>f(T.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.newPassword")}),j&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.confirm")}),t.jsx("input",{type:"password",value:m,onChange:T=>o(T.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.confirm")}),R&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.mismatch")})]}),C&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:C}),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:g,onChange:T=>v(T.target.checked),className:"accent-accent w-4 h-4"}),_("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!E||x,className:"btn-primary w-full mt-6 py-3",children:_(x?"login.loading":l?"login.changeSubmit":"login.submit")})]})}),t.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[t.jsx("button",{type:"button",onClick:D,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_(l?"login.backToLogin":"login.changePassword")}),t.jsx("button",{type:"button",onClick:()=>d(T=>!T),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_("login.forgot")})]}),p&&t.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:_("login.forgotHint")}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:_("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:_("login.disclaimer")})]})]})}const cb=8;function JN({onSetup:e}){const[s,i]=y.useState(""),[a,u]=y.useState(""),[f,m]=y.useState(""),[o,l]=y.useState(!1),{t:h,toggleLang:p}=xt(),d=s.length>0&&s.length<cb,g=a.length>0&&s!==a,v=s.length>=cb&&s===a&&!o,C=async k=>{if(k.preventDefault(),!!v){m(""),l(!0);try{await e(s,a)}catch(x){m(x instanceof Error&&x.message?x.message:h("setup.error"))}finally{l(!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:h("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm",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(wl,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:h("setup.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:h("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:h("setup.password")}),t.jsx("input",{type:"password",value:s,onChange:k=>i(k.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),d&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("setup.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:h("setup.confirm")}),t.jsx("input",{type:"password",value:a,onChange:k=>u(k.target.value),placeholder:"*************",className:"input-field text-base"}),g&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("setup.mismatch")}),f&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:f}),t.jsx("button",{type:"submit",disabled:!v,className:"btn-primary w-full mt-6 py-3",children:h(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:h("setup.tunnelPaused")})]})]})}function QN(e){return ht("/api/projects/browse",{initialPath:e})}function ZN(e){return ht("/api/projects/open-folder",{path:e})}function Yu(){return wt("/api/projects")}function e4(e){return wt(`/api/projects/${e}`)}function m1(e){return ht("/api/projects",e)}function t4(e){return wt(`/api/projects/${e}/svn-detect`)}function xm(e,s){return pn(`/api/projects/${e}`,s)}function n4(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return wt(`/api/projects/${e}/debug-logs${i}`)}function p1(e){return Vn(`/api/projects/${e}`)}function s4(e){return ht("/api/projects/reorder",{ids:e})}function r4(e){return ht(`/api/projects/${e}/start`)}function i4(e){return ht(`/api/projects/${e}/stop`)}function g1(e){return wt(`/api/projects/${e}/status`)}function ub(){return wt("/api/active-work")}function a4(e){return ht(`/api/projects/${e}/check-git`)}function x1(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return wt(`/api/projects/${e}/git-status${i}`)}function o4(e,s=0,i=50,a){const u=new URLSearchParams({skip:String(s),limit:String(i)});return wt(`/api/projects/${e}/git-log?${u}`)}function vm(e,s){return wt(`/api/projects/${e}/git-refs`)}function l4(e,s,i){return ht(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function c4(e,s,i){return ht(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function u4(e,s,i){return ht(`/api/projects/${e}/git-ignore`,{path:s,worktreePath:i})}function v1(e,s,i){return ht(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function b1(e,s,i){return ht(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function fp(e,s){return ht(`/api/projects/${e}/git-push`,s||{})}function d4(e){return wt(`/api/projects/${e}/git-remotes`)}function y1(e,s,i){return ht(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function w1(e,s,i){return ht(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function bm(e,s,i){return ht(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function ym(e,s){return ht(`/api/projects/${e}/git-checkout`,{branch:s})}function _1(e,s){return ht(`/api/projects/${e}/git-merge`,{branch:s})}function db(e,s,i,a){return ht(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function h4(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return wt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function f4(e,s,i,a){return ht(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function m4(e){return ht(`/api/projects/${e}/git-conflict-continue`)}function p4(e){return ht(`/api/projects/${e}/git-conflict-abort`)}function g4(e,s){return ht(`/api/projects/${e}/git-stash`,{message:s})}function x4(e,s){return ht(`/api/projects/${e}/git-stash-pop`,{index:s})}function v4(e){return wt(`/api/projects/${e}/git-stash-list`)}function b4(e,s,i,a){return ht(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function S1(e,s,i,a){return ht(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function hb(e,s,i){return ht(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function y4(e,s){return ht(`/api/projects/${e}/git-rebase`,{onto:s})}function w4(e,s){return ht(`/api/projects/${e}/git-revert`,{commit:s})}function _4(e,s){return ht(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function S4(e,s,i){return ht(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function k4(e,s,i,a){const u=new URLSearchParams;return s&&u.set("file",s),i&&u.set("staged","true"),a&&u.set("worktreePath",a),wt(`/api/projects/${e}/git-diff?${u}`)}function C4(e,s){const i=new URLSearchParams({hash:s});return wt(`/api/projects/${e}/git-commit-files?${i}`)}function fb(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),wt(`/api/projects/${e}/git-commit-diff?${a}`)}function wm(e){return wt(`/api/projects/${e}/worktrees`)}function mb(e,s,i){return ht(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function k1(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 j4(e={}){return wt(`/api/review/queue${k1(e)}`)}function C1(e={}){return wt(`/api/review/summary${k1(e)}`)}function E4(e){return wt(`/api/review/diff/${encodeURIComponent(e)}`)}function N4(e,s){return wt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function L4(){return wt("/api/favorites")}function D4(e){return ht("/api/favorites",e)}function T4(e,s){return pn(`/api/favorites/${e}`,s)}function R4(e){return Vn(`/api/favorites/${e}`)}function M4(e){return ht(`/api/favorites/${e}/launch`)}function A4(e){return ht("/api/favorites/browse-file",{initialPath:e})}function _m(){return wt("/api/tunnel/status")}function z4(){return wt("/api/tunnel/config")}function O4(e){return pn("/api/tunnel/config",e)}function j1(e){return ht("/api/tunnel/start",{})}function B4(){return ht("/api/tunnel/stop")}const E1=y.createContext({theme:"light",toggleTheme:()=>{}});function P4(){const[e,s]=y.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});y.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=y.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function I4(){return y.useContext(E1)}const N1=y.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function F4(){const e="Notification"in window,[s,i]=y.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=y.useRef(s);y.useEffect(()=>{a.current=s},[s]);const u=y.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=y.useCallback((m,o)=>{if(!a.current)return;const l=new Notification(m,{body:o});l.onclick=()=>{window.focus(),l.close()}},[]);return{enabled:s,supported:e,toggleNotification:u,sendNotification:f}}function ro(){return y.useContext(N1)}let H4=0;const L1=y.createContext(null);function $4({children:e}){const[s,i]=y.useState([]),a=y.useRef(new Map),u=y.useRef(new Map),f=y.useRef(new Map),m=y.useCallback(v=>{i(x=>x.filter(S=>S.id!==v));const C=f.current.get(v);C&&u.current.get(C)===v&&u.current.delete(C),f.current.delete(v);const k=a.current.get(v);k&&(clearTimeout(k),a.current.delete(v))},[]),o=y.useCallback((v,C="info",k=3500)=>{const x=`${C}:${v}`,S=u.current.get(x);if(S)return S;const _=`toast-${++H4}`;u.current.set(x,_),f.current.set(_,x),i(j=>[...j,{id:_,message:v,type:C,duration:k}]);const w=setTimeout(()=>m(_),k);return a.current.set(_,w),_},[m]),l=y.useCallback((v,C)=>o(v,"success",C),[o]),h=y.useCallback((v,C)=>o(v,"error",C),[o]),p=y.useCallback((v,C)=>o(v,"info",C),[o]),d=y.useCallback((v,C)=>o(v,"warning",C),[o]);y.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),u.current.clear(),f.current.clear()},[]);const g=y.useMemo(()=>({toasts:s,show:o,success:l,error:h,info:p,warning:d,dismiss:m}),[s,o,l,h,p,d,m]);return y.createElement(L1.Provider,{value:g},e)}function Rs(){const e=y.useContext(L1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function $s(...e){return e.filter(Boolean).join(" ")}const U4={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl","4xl":"max-w-4xl"};function Dn({open:e,onClose:s,size:i="md",position:a="center",disableEscClose:u=!1,disableBackdropClose:f=!1,children:m}){const o=y.useRef(null);return y.useEffect(()=>{if(!e||u)return;const l=h=>{h.key==="Escape"&&s()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[e,u,s]),e?cn.createPortal(t.jsx("div",{ref:o,className:$s("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:l=>{!f&&l.target===o.current&&s()},children:t.jsx("div",{className:$s("w-full",U4[i]),children:m})}),document.body):null}const W4={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},q4={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},$t=y.forwardRef(function({variant:s="default",size:i,type:a="button",className:u,...f},m){return t.jsx("button",{ref:m,type:a,className:$s(W4[s],i&&q4[i],u),...f})}),D1=y.createContext(null);let pb=0;function G4({children:e}){const[s,i]=y.useState(null),a=y.useRef(null),u=y.useCallback(h=>{const p=a.current;p&&(p.kind==="confirm"?p.resolve(!1):p.resolve(null)),a.current=h,i(h)},[]),f=y.useCallback(()=>{a.current=null,i(null)},[]),m=y.useCallback(h=>{const p=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++pb,kind:"confirm",options:p,resolve:d})})},[u]),o=y.useCallback(h=>{const p=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++pb,kind:"prompt",options:p,resolve:d})})},[u]),l=y.useMemo(()=>({confirm:m,prompt:o}),[m,o]);return t.jsxs(D1.Provider,{value:l,children:[e,s&&t.jsx(K4,{dialog:s,onSettled:f},s.id)]})}function K4({dialog:e,onSettled:s}){const{t:i}=xt(),[a,u]=y.useState(e.kind==="prompt"?e.options.initialValue??"":""),f=()=>{e.kind==="confirm"?e.resolve(!1):e.resolve(null),s()},m=()=>{e.kind==="confirm"?e.resolve(!0):e.resolve(a),s()},o=e.kind==="confirm"&&!!e.options.danger,l=e.kind==="confirm"&&e.options.confirmLabel||i("common.ok"),h=e.kind==="confirm"&&e.options.cancelLabel||i("common.cancel"),p=t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx($t,{size:"sm",onClick:f,autoFocus:o,children:h}),t.jsx($t,{variant:o?"danger":"primary",size:"sm",type:e.kind==="prompt"?"submit":"button",onClick:e.kind==="prompt"?void 0:m,autoFocus:e.kind==="confirm"&&!o,children:l})]});return t.jsx(Dn,{open:!0,onClose:f,size:"sm",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-5",children:[e.options.title&&t.jsx("div",{className:"text-sm font-semibold text-theme-text mb-2",children:e.options.title}),t.jsx("p",{className:"text-sm text-theme-text-secondary whitespace-pre-line break-words",children:e.options.message}),e.kind==="prompt"?t.jsxs("form",{onSubmit:d=>{d.preventDefault(),m()},children:[t.jsx("input",{autoFocus:!0,value:a,onChange:d=>u(d.target.value),placeholder:e.options.placeholder,className:"input-field mt-3"}),p]}):p]})})}function Yn(){const e=y.useContext(D1);if(!e)throw new Error("useDialog must be used within DialogProvider");return e}function T1({onSubmit:e,onCancel:s}){const[i,a]=y.useState(""),[u,f]=y.useState(""),[m,o]=y.useState(!1),[l,h]=y.useState(!1),[p,d]=y.useState(""),{t:g}=xt(),v=async k=>{if(k.preventDefault(),!(!i.trim()||!u.trim())){d(""),h(!0);try{await e(i.trim(),u.trim())}catch(x){const S=x instanceof Error?x.message:String(x);d(S||g("form.createError"))}finally{h(!1)}}},C=async()=>{o(!0);try{const k=await QN(u||void 0);k.path&&f(k.path)}catch{}o(!1)};return t.jsx(Dn,{open:!0,onClose:s,size:"md",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:g("form.newProject")}),t.jsxs("form",{onSubmit:v,children:[t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:g("form.projectName")}),t.jsx("input",{type:"text",placeholder:"my-project",value:i,onChange:k=>a(k.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:g("form.folderPath")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:u,onChange:k=>f(k.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:g("browse.title"),children:m?t.jsx(Tr,{size:16,className:"animate-spin"}):t.jsx(Gu,{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:g("form.cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||!u.trim()||l,className:"btn-primary text-sm",children:g(l?"form.creating":"form.create")})]})]})]})})}const V4=[{value:"executable",icon:up},{value:"command",icon:bi},{value:"url",icon:yl}];function Y4(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 gb(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 X4({initial:e,onSubmit:s,onCancel:i}){const{t:a}=xt(),[u,f]=y.useState((e==null?void 0:e.name)??""),[m,o]=y.useState((e==null?void 0:e.type)??"executable"),[l,h]=y.useState((e==null?void 0:e.target)??""),[p,d]=y.useState(gb((e==null?void 0:e.args)??null)),[g,v]=y.useState((e==null?void 0:e.cwd)??""),[C,k]=y.useState(!1);y.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),h((e==null?void 0:e.target)??""),d(gb((e==null?void 0:e.args)??null)),v((e==null?void 0:e.cwd)??"")},[e]);const[x,S]=y.useState(!1),_=m==="executable",w=async()=>{S(!0);try{const{path:P}=await A4(l||void 0);if(!P)return;if(h(P),!u.trim()){const O=P.replace(/\\/g,"/").split("/").pop()||"";f(O.replace(/\.[^.]+$/,""))}}catch{}finally{S(!1)}},j=!!e,R=u.trim(),E=l.trim(),D=m!=="url"||/^https?:\/\//i.test(E),N=!!R&&!!E&&D&&!C,T=async P=>{if(P.preventDefault(),!!N){k(!0);try{const O={name:R,type:m,target:E,args:m==="executable"&&p.trim()?Y4(p.trim()):null,cwd:m!=="url"&&g.trim()?g.trim():null};await s(O)}finally{k(!1)}}},z=a(m==="executable"?"favorites.form.targetHint.executable":m==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return t.jsx(Dn,{open:!0,onClose:i,size:"md",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:a(j?"favorites.form.title.edit":"favorites.form.title.create")}),t.jsxs("form",{onSubmit:T,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:V4.map(({value:P,icon:O})=>t.jsxs("button",{type:"button",onClick:()=>o(P),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:m===P?{backgroundColor:"var(--color-accent)",color:"white",borderColor:"var(--color-accent)"}:{color:"var(--color-text-tertiary)",borderColor:"var(--color-border)"},children:[t.jsx(O,{size:14}),a(`favorites.types.${P}`)]},P))})]}),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:u,onChange:P=>f(P.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:l,onChange:P=>h(P.target.value),className:"input-field text-sm font-mono flex-1",placeholder:z}),_&&t.jsxs("button",{type:"button",onClick:w,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx(Gu,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:z})]}),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:P=>d(P.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:g,onChange:P=>v(P.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:!N,className:"btn-primary text-sm",children:a(j?"favorites.form.save":"favorites.form.create")})]})]})]})})}const J4=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function Q4({onClose:e}){const{t:s}=xt(),{error:i,success:a}=Rs(),[u,f]=y.useState(""),[m,o]=y.useState(""),[l,h]=y.useState(""),[p,d]=y.useState(""),[g,v]=y.useState(!1),[C,k]=y.useState(!1),[x,S]=y.useState(!1),[_,w]=y.useState(null);y.useEffect(()=>{let O=!1;return Promise.all([z4(),_m()]).then(([H,U])=>{O||(f(H.tunnelName),o(H.customHostname),h(H.tunnelName),d(H.customHostname),w(U))}).catch(()=>{}),()=>{O=!0}},[]);const j=u.trim(),R=m.trim(),E=j!==l.trim()||R!==p.trim(),D=!!R&&(!J4.test(R)||R.toLowerCase()==="localhost"||R.toLowerCase()==="127.0.0.1"),N=!!R&&!j,T=E&&!C&&!D&&!N,z=async()=>{if(T){k(!0);try{const O=await O4({tunnelName:j,customHostname:R});h(O.tunnelName),d(O.customHostname),f(O.tunnelName),o(O.customHostname),a(s("tunnel.saved"))}catch(O){i(O instanceof Error?O.message:s("tunnel.saveFailed"))}finally{k(!1)}}},P=async()=>{S(!0);try{try{await B4()}catch{}const O=await j1();w({status:"running",url:O.url}),a(s("tunnel.restarted"))}catch(O){i(O instanceof Error?O.message:s("tunnel.restartFailed"))}finally{S(!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")}),_&&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 ${_.status==="running"?"bg-status-success":_.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${_.status}`)}),_.url&&t.jsx("a",{href:_.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:_.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:u,onChange:O=>f(O.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:O=>o(O.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")}),D&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),N&&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:()=>v(!g),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 ${g?"rotate-90":""}`,children:"▶"}),s("tunnel.guide.toggle")]}),g&&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:P,disabled:x,className:"btn-ghost text-sm disabled:opacity-50",children:x?(_==null?void 0:_.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(_==null?void 0:_.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:z,disabled:!T,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const xb=8;function Z4({onClose:e}){const{t:s}=xt(),{error:i,success:a}=Rs(),[u,f]=y.useState(""),[m,o]=y.useState(""),[l,h]=y.useState(""),[p,d]=y.useState(!1),g=m.length>0&&m.length<xb,v=l.length>0&&m!==l,C=!!u&&m.length>=xb&&m===l&&!p,k=()=>{f(""),o(""),h("")},x=async()=>{if(C){d(!0);try{await Zw(u,m,l),a(s("account.saved")),k()}catch(S){i(S instanceof Error&&S.message?S.message:s("account.saveFailed"))}finally{d(!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:u,onChange:S=>f(S.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:S=>o(S.target.value),className:"input-field text-sm",autoComplete:"new-password"}),g&&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:l,onChange:S=>h(S.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.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 mp(){return wt("/api/session-tags")}function e3(e){return ht("/api/session-tags",e)}function t3(e,s){return pn(`/api/session-tags/${e}`,s)}function n3(e){return Vn(`/api/session-tags/${e}`)}function R1(){return wt("/api/session-aliases")}function M1(e){return ht("/api/session-aliases",e)}function s3(e,s){return pn(`/api/session-aliases/${e}`,s)}function r3(e){return Vn(`/api/session-aliases/${e}`)}function pp(){return wt("/api/session-settings")}function wf(e){return pn("/api/session-settings",e)}const Ge={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},Ht="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",gp=13,cl=8,ul=28,Ja=new Map,Gi=new Map;let Lu=gp;function xp(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);Ja.delete(s);const i=Gi.get(s);if(i){const u=dl(s);i.forEach(f=>f(u))}});function Sm(e){return Number.isFinite(e)?Math.max(cl,Math.min(ul,Math.round(e))):Lu}function i3(e){if(Ja.has(e))return!0;try{return localStorage.getItem(xp(e))!==null}catch{return!1}}function dl(e){const s=Ja.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(xp(e));if(a!==null){const u=parseInt(a,10);Number.isFinite(u)&&(i=Sm(u))}}catch{}return i===null?Sm(Lu):(Ja.set(e,i),i)}function km(e,s){const i=Sm(s);if(Ja.get(e)===i)return;Ja.set(e,i);try{localStorage.setItem(xp(e),String(i))}catch{}const a=Gi.get(e);a&&a.forEach(u=>u(i))}function Zo(e,s){km(e,dl(e)+s)}function xu(e){const s=Math.max(cl,Math.min(ul,Math.round(e)));Number.isFinite(s)&&s!==Lu&&(Lu=s,Gi.forEach((i,a)=>{i3(a)||i.forEach(u=>u(s))}))}function A1(e){const[s,i]=y.useState(()=>dl(e));y.useEffect(()=>{i(dl(e));let f=Gi.get(e);return f||(f=new Set,Gi.set(e,f)),f.add(i),()=>{const m=Gi.get(e);m&&(m.delete(i),m.size===0&&Gi.delete(e))}},[e]);const a=y.useCallback(f=>km(e,f),[e]),u=y.useCallback(f=>km(e,dl(e)+f),[e]);return[s,a,u]}const hl=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function vb(e){for(const s of hl)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return hl[e.length%hl.length]}function a3({onClose:e}){const{t:s}=xt(),{confirm:i}=Yn(),{error:a,success:u}=Rs(),[f,m]=y.useState([]),[o,l]=y.useState(!1),[h,p]=y.useState(gp),[d,g]=y.useState(!1),[v,C]=y.useState(!1),[k,x]=y.useState(!1),[S,_]=y.useState(!1),w=y.useRef(null),[j,R]=y.useState(""),[E,D]=y.useState(hl[0]),[N,T]=y.useState(!1),[z,P]=y.useState(null),[O,H]=y.useState(""),[U,F]=y.useState(hl[0]),[q,$]=y.useState(!1),[K,B]=y.useState([]),[A,I]=y.useState(""),[Y,G]=y.useState(""),[J,re]=y.useState(!1),[Z,Q]=y.useState(null),[W,oe]=y.useState(""),[le,ge]=y.useState(""),[ue,Ve]=y.useState(!1);y.useEffect(()=>{let ie=!1;return Promise.all([mp(),pp(),R1()]).then(([ke,_e,st])=>{ie||(m(ke),l(_e.defaultUseWorktree),p(_e.defaultFontSize),xu(_e.defaultFontSize),g(_e.imeDebug),D(vb(ke)),B(st),C(!0))}).catch(ke=>{ie||a(ke instanceof Error?ke.message:"Failed to load")}),()=>{ie=!0}},[a]);const We=j.trim(),De=!!We&&!N,be=y.useMemo(()=>[...f].sort((ie,ke)=>ie.sort_order-ke.sort_order||ie.name.localeCompare(ke.name)),[f]);y.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const Re=ie=>{if(!Number.isFinite(ie))return;const ke=Math.max(cl,Math.min(ul,Math.round(ie)));p(ke),xu(ke),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{wf({defaultFontSize:ke}).then(_e=>{p(_e.defaultFontSize),xu(_e.defaultFontSize)}).catch(_e=>a(_e instanceof Error?_e.message:"Save failed"))},350)},ct=async ie=>{x(!0);try{const ke=await wf({defaultUseWorktree:ie});l(ke.defaultUseWorktree),u(s("sessionSettings.saved"))}catch(ke){a(ke instanceof Error?ke.message:"Save failed")}finally{x(!1)}},tt=async ie=>{var ke,_e;_(!0);try{const st=await wf({imeDebug:ie});g(st.imeDebug),(_e=(ke=window.electronAPI)==null?void 0:ke.imeSetDebug)==null||_e.call(ke,st.imeDebug),u(s("sessionSettings.saved"))}catch(st){a(st instanceof Error?st.message:"Save failed")}finally{_(!1)}},Ke=async()=>{if(De){T(!0);try{const ie=await e3({name:We,color:E});m(ke=>[...ke,ie]),R(""),D(vb([...f,ie]))}catch(ie){a(ie instanceof Error?ie.message:"Create failed")}finally{T(!1)}}},Le=ie=>{P(ie.id),H(ie.name),F(ie.color)},$e=()=>{P(null),H("")},Ie=async()=>{if(!z)return;const ie=O.trim();if(ie){$(!0);try{const ke=await t3(z,{name:ie,color:U});m(_e=>_e.map(st=>st.id===ke.id?ke:st)),$e()}catch(ke){a(ke instanceof Error?ke.message:"Save failed")}finally{$(!1)}}},it=async ie=>{if(await i({message:s("sessionSettings.tags.deleteConfirm").replace("{name}",ie.name),danger:!0}))try{await n3(ie.id),m(ke=>ke.filter(_e=>_e.id!==ie.id))}catch(ke){a(ke instanceof Error?ke.message:"Delete failed")}},vt=A.trim(),Ce=Y.trim(),Ue=!!vt&&!!Ce&&!J,we=y.useMemo(()=>[...K].sort((ie,ke)=>ie.sort_order-ke.sort_order||ie.name.localeCompare(ke.name)),[K]),Pe=async()=>{if(Ue){re(!0);try{const ie=await M1({name:vt,command_template:Ce});B(ke=>[...ke,ie]),I(""),G("")}catch(ie){a(ie instanceof Error?ie.message:"Create failed")}finally{re(!1)}}},X=ie=>{Q(ie.id),oe(ie.name),ge(ie.command_template)},ne=()=>{Q(null),oe(""),ge("")},Se=async()=>{if(!Z)return;const ie=W.trim(),ke=le.trim();if(!(!ie||!ke)){Ve(!0);try{const _e=await s3(Z,{name:ie,command_template:ke});B(st=>st.map(Ze=>Ze.id===_e.id?_e:Ze)),ne()}catch(_e){a(_e instanceof Error?_e.message:"Save failed")}finally{Ve(!1)}}},fe=async ie=>{if(await i({message:s("sessionSettings.aliases.deleteConfirm").replace("{name}",ie.name),danger:!0}))try{await r3(ie.id),B(ke=>ke.filter(_e=>_e.id!==ie.id))}catch(ke){a(ke instanceof Error?ke.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(Qi,{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:o,disabled:k||!v,onChange:ie=>ct(ie.target.checked),className:"rounded-md 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(IN,{size:14}),s("sessionSettings.fontSize.title")]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("input",{type:"range",min:cl,max:ul,step:1,value:h,disabled:!v,onChange:ie=>Re(parseInt(ie.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),t.jsx("input",{type:"number",min:cl,max:ul,step:1,value:h,disabled:!v,onChange:ie=>Re(parseInt(ie.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:E,onChange:ie=>D(ie.target.value),className:"w-9 h-9 rounded-md cursor-pointer border border-warm-200",title:s("sessionSettings.tags.color")}),t.jsx("input",{type:"text",value:j,onChange:ie=>R(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&(ie.preventDefault(),Ke())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),t.jsxs("button",{type:"button",onClick:Ke,disabled:!De,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(wn,{size:14}),s("sessionSettings.tags.add")]})]}),be.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:be.map(ie=>{const ke=z===ie.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ke?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:U,onChange:_e=>F(_e.target.value),className:"w-7 h-7 rounded-md cursor-pointer border border-warm-200"}),t.jsx("input",{type:"text",value:O,onChange:_e=>H(_e.target.value),onKeyDown:_e=>{_e.key==="Enter"&&(_e.preventDefault(),Ie()),_e.key==="Escape"&&$e()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),t.jsx("button",{type:"button",onClick:Ie,disabled:q||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("sessionSettings.tags.save"),children:t.jsx(ar,{size:14})}),t.jsx("button",{type:"button",onClick:$e,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.cancel"),children:t.jsx(Jt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:ie.color,borderColor:"rgba(0,0,0,0.08)"}}),t.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:ie.name}),t.jsx("button",{type:"button",onClick:()=>Le(ie),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.edit"),children:t.jsx(xi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>it(ie),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.delete"),children:t.jsx(Pn,{size:14})})]})},ie.id)})})]}),t.jsxs("section",{className:"mt-7",children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:s("sessionSettings.aliases.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-3",children:s("sessionSettings.aliases.description")}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx("input",{type:"text",value:A,onChange:ie=>I(ie.target.value),placeholder:s("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:Y,onChange:ie=>G(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&(ie.preventDefault(),Pe())},placeholder:s("sessionSettings.aliases.commandPlaceholder"),className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsxs("button",{type:"button",onClick:Pe,disabled:!Ue,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(wn,{size:14}),s("sessionSettings.aliases.add")]})]}),we.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:s("sessionSettings.aliases.empty")}):t.jsx("ul",{className:"space-y-1.5",children:we.map(ie=>{const ke=Z===ie.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ke?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:W,onChange:_e=>oe(_e.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:le,onChange:_e=>ge(_e.target.value),onKeyDown:_e=>{_e.key==="Enter"&&(_e.preventDefault(),Se()),_e.key==="Escape"&&ne()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:Se,disabled:ue||!W.trim()||!le.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("common.save"),children:t.jsx(ar,{size:14})}),t.jsx("button",{type:"button",onClick:ne,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("common.cancel"),children:t.jsx(Jt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:ie.name}),t.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:ie.command_template}),t.jsx("button",{type:"button",onClick:()=>X(ie),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:s("common.edit"),children:t.jsx(xi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>fe(ie),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:s("common.delete"),children:t.jsx(Pn,{size:14})})]})},ie.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(D5,{size:14}),"IME 디버그 로그"]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:d,disabled:S||!v,onChange:ie=>tt(ie.target.checked),className:"rounded-md 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 o3(){return wt("/api/mcp/connection")}function l3({onClose:e}){const{t:s}=xt(),{success:i,error:a}=Rs(),[u,f]=y.useState(null),[m,o]=y.useState(null);y.useEffect(()=>{let g=!1;return o3().then(v=>{g||f(v)}).catch(()=>{}),()=>{g=!0}},[]);const l=async(g,v)=>{try{await navigator.clipboard.writeText(v),o(g),setTimeout(()=>o(C=>C===g?null:C),1500),i(s("mcp.copied"))}catch{a(s("mcp.copyFailed"))}},h=u?JSON.stringify(u.config,null,2):"",p=({label:g,text:v})=>t.jsxs("button",{type:"button",onClick:()=>l(g,v),className:"btn-ghost text-xs flex items-center gap-1",children:[m===g?t.jsx(ar,{size:14}):t.jsx(cE,{size:14}),s("mcp.copy")]}),d={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("mcp.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("mcp.description")}),u?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600",children:s("mcp.config.label")}),t.jsx(p,{label:"config",text:h})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:d,children:h})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:s("mcp.commands.label")}),t.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:s("mcp.commands.hint")}),t.jsx("div",{className:"space-y-3",children:u.commands.map(g=>t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-xs text-warm-500",children:g.label}),t.jsx(p,{label:`command:${g.id}`,text:g.command})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:d,children:g.command})]},g.id))})]}),t.jsx("p",{className:"text-2xs text-warm-400",children:s("mcp.tokenNote")})]}):t.jsx("p",{className:"text-sm text-warm-400",children:s("mcp.loading")}),e&&t.jsx("div",{className:"flex justify-end mt-6",children:t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("mcp.close")})})]})}function bb({open:e,onClose:s}){const{t:i}=xt(),[a,u]=y.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:FE},{id:"session",label:i("settings.tabs.session"),icon:wl},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:o1},{id:"mcp",label:i("settings.tabs.mcp"),icon:bN}];return t.jsx(Dn,{open:e,onClose:s,size:"xl",children:t.jsx("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated 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:l})=>{const h=a===m;return t.jsxs("button",{type:"button",onClick:()=>u(m),className:"flex items-center gap-2 px-4 py-2.5 text-sm transition-colors text-left",style:{color:h?"var(--color-accent)":"var(--color-text-secondary)",backgroundColor:h?"var(--color-bg-primary)":"transparent",fontWeight:h?600:400},children:[t.jsx(l,{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.62"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(Z4,{onClose:s}),a==="session"&&t.jsx(a3,{onClose:s}),a==="tunnel"&&t.jsx(Q4,{onClose:s}),a==="mcp"&&t.jsx(l3,{onClose:s})]})]})})})}const Cm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function c3(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 Qa(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:Cm[c3(e.id,Cm.length)]}const yb=192,u3=88,Vc=8;function d3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:u}){const f=y.useRef(null),[m,o]=y.useState({left:s,top:i}),l=Qa(e);return y.useLayoutEffect(()=>{const h=Math.min(Math.max(s,Vc),window.innerWidth-yb-Vc),p=Math.min(Math.max(i,Vc),window.innerHeight-u3-Vc);o({left:h,top:p})},[s,i]),y.useEffect(()=>{const h=d=>{var g;(g=f.current)!=null&&g.contains(d.target)||u()},p=d=>{d.key==="Escape"&&u()};return window.addEventListener("mousedown",h),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",p)}},[u]),cn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:yb,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:Cm.map(h=>{const p=e.color?h.toLowerCase()===e.color.toLowerCase():h===l&&!e.color;return t.jsx("button",{onClick:()=>a(h),"aria-label":h,style:{width:20,height:20,borderRadius:6,background:h,border:p?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},h)})}),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 fl(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function h3(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 f3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},m3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},En=y.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:u,type:f="button",title:m,className:o,...l},h){return t.jsx("button",{ref:h,type:f,"aria-label":s,"aria-pressed":u,title:m??s,className:$s("btn-icon",f3[i],m3[a],o),...l})});function p3(e){return e==="executable"?up:e==="command"?bi:yl}function g3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:u,collapsed:f=!1,onToggleCollapsed:m}){var Ue;const[o,l]=y.useState([]),[h,p]=y.useState({}),[d,g]=y.useState(null),[v,C]=y.useState(!1),[k,x]=y.useState(null),[S,_]=y.useState([]),[w,j]=y.useState(!1),[R,E]=y.useState(null),[D,N]=y.useState(!1),[T,z]=y.useState(null),[P,O]=y.useState(!1),[H,U]=y.useState(null),[F,q]=y.useState(null),$=Ks(),K=wi(),{t:B,toggleLang:A}=xt(),{theme:I,toggleTheme:Y}=I4(),{enabled:G,supported:J,toggleNotification:re}=ro(),{error:Z,success:Q,info:W,warning:oe}=Rs(),{confirm:le}=Yn(),ge=((Ue=$.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:Ue[1])||null;y.useEffect(()=>{tt(),Ve(),_m().then(z).catch(()=>{})},[]);async function ue(){if(!P){O(!0);try{const we=await _m();if(z(we),we.status==="running"&&we.url){await navigator.clipboard.writeText(we.url),Q(B("tunnel.urlCopied"));return}const Pe=await j1(),X={status:"running",url:Pe.url};z(X);try{await navigator.clipboard.writeText(Pe.url),Q(B("tunnel.urlCopied"))}catch{Q(Pe.url)}}catch(we){Z(we instanceof Error?we.message:B("tunnel.restartFailed"))}finally{O(!1)}}}function Ve(){L4().then(_).catch(()=>{})}const We=async we=>{try{R?await T4(R.id,we):await D4(we),j(!1),E(null),Ve()}catch(Pe){Z(Pe instanceof Error?Pe.message:"Failed to save favorite")}},De=async we=>{try{await M4(we)}catch(Pe){const X=Pe instanceof Error?Pe.message:B("favorites.launchFailed");Z(`${B("favorites.launchFailed")}: ${X}`)}},be=async(we,Pe)=>{if(Pe.preventDefault(),Pe.stopPropagation(),!!await le({message:B("favorites.deleteConfirm"),danger:!0}))try{await R4(we),_(X=>X.filter(ne=>ne.id!==we))}catch(X){Z(X instanceof Error?X.message:"Failed to delete favorite")}},Re=(we,Pe)=>{Pe.preventDefault(),Pe.stopPropagation(),E(we),j(!0)};y.useEffect(()=>{const we=()=>tt();return window.addEventListener("projects:changed",we),()=>window.removeEventListener("projects:changed",we)},[]),y.useEffect(()=>{const we=()=>ct();return window.addEventListener("review:changed",we),()=>window.removeEventListener("review:changed",we)},[]),y.useEffect(()=>a(we=>{var Pe;if(we.type==="project:status-changed"&&we.projectId&&p(X=>({...X,[we.projectId]:{running:we.running??0,completed:we.completed??0,total:we.total??0,running_sessions:we.running_sessions??0,running_discussions:we.running_discussions??0}})),we.type==="todo:status-changed"&&ct(),we.type==="memory:ingest-finished"){const X=o.find(Ze=>Ze.id===we.projectId),ne=(X==null?void 0:X.name)??"",Se=we.sourceTitle?`“${we.sourceTitle}”`:we.sourceType??"",fe=ne?`[${ne}] `:"";if(we.error){Z(`${fe}${B("wiki.ingest.toast.failed")}: ${we.error}`,6e3);return}const ie=we.created??0,ke=we.updated??0,_e=we.edgesAdded??0;if(ie+ke+_e>0){const Ze=B("wiki.ingest.toast.success").replace("{source}",Se).replace("{created}",String(ie)).replace("{updated}",String(ke)).replace("{edges}",String(_e));Q(`${fe}${Ze}`)}else(Pe=we.skipped)!=null&&Pe.parseFailed?oe(`${fe}${B("wiki.ingest.toast.parseFailed").replace("{source}",Se)}`,5e3):W(`${fe}${B("wiki.ingest.toast.empty").replace("{source}",Se)}`,4e3)}}),[a,o,B,Z,W,Q,oe]),y.useEffect(()=>{ct()},[]);function ct(){C1({hours:24}).then(we=>g(we.total_todos)).catch(()=>{})}function tt(){Yu().then(we=>{l(we),we.forEach(Pe=>{g1(Pe.id).then(X=>{p(ne=>({...ne,[Pe.id]:X}))}).catch(()=>{})})}).catch(()=>{})}const Ke=()=>{u==null||u()},Le=async(we,Pe)=>{await m1({name:we,path:Pe}),C(!1),window.dispatchEvent(new Event("projects:changed"))},$e=y.useCallback(async(we,Pe)=>{const X=o.map(Ze=>Ze.id),ne=X.indexOf(we);if(ne<0)return;const Se=X.filter(Ze=>Ze!==we),fe=Pe>ne?Pe-1:Pe;if(fe===ne)return;const ie=[...Se.slice(0,fe),we,...Se.slice(fe)],ke=o,_e=new Map(o.map(Ze=>[Ze.id,Ze])),st=ie.map(Ze=>_e.get(Ze)).filter(Boolean);l(st);try{await s4(ie)}catch(Ze){l(ke),Z(Ze instanceof Error?Ze.message:"Failed to reorder projects")}},[o,Z]),Ie=y.useRef(!1),it=y.useCallback((we,Pe)=>{if(Pe.button!==0||Pe.target.closest("button"))return;Pe.preventDefault();const ne=Pe.clientX,Se=Pe.clientY,fe=6;let ie=!1,ke=null;const _e=ce=>{const ee=document.querySelectorAll("[data-workspace-item]");if(ee.length===0)return null;const Ne=ee[0].getBoundingClientRect();if(ce<Ne.top)return 0;const je=ee[ee.length-1].getBoundingClientRect();if(ce>je.bottom)return ee.length;for(let Me=0;Me<ee.length;Me++){const Te=ee[Me].getBoundingClientRect();if(ce>=Te.top&&ce<=Te.bottom){const et=Te.top+Te.height/2;return ce<et?Me:Me+1}}return null},st=ce=>{if(!ie){if(Math.hypot(ce.clientX-ne,ce.clientY-Se)<fe)return;ie=!0,U(we)}const ee=_e(ce.clientY);ee!==ke&&(ke=ee,q(ee))},Ze=()=>{window.removeEventListener("mousemove",st),window.removeEventListener("mouseup",he),window.removeEventListener("keydown",de)},he=()=>{if(Ze(),!ie)return;Ie.current=!0,requestAnimationFrame(()=>{Ie.current=!1});const ce=ke;U(null),q(null),ce!==null&&$e(we,ce)},de=ce=>{ce.key==="Escape"&&(Ze(),U(null),q(null),ie&&(Ie.current=!0,requestAnimationFrame(()=>{Ie.current=!1})))};window.addEventListener("mousemove",st),window.addEventListener("mouseup",he),window.addEventListener("keydown",de)},[$e]),vt=async(we,Pe)=>{if(Pe.preventDefault(),Pe.stopPropagation(),!!await le({message:B("projects.deleteConfirm"),danger:!0}))try{await p1(we),l(X=>X.filter(ne=>ne.id!==we)),window.dispatchEvent(new Event("projects:changed")),ge===String(we)&&K("/")}catch(X){Z(fl(X,B("errors.projectDelete")))}},Ce=we=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...we==="above"?{top:-1}:{bottom:-1}}});if(f){const we=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 bg-theme-bg-secondary border-none py-3",children:[t.jsx(En,{onClick:m,label:B("sidebar.expand"),size:"lg",children:t.jsx(f1,{size:16})}),we,t.jsx(Kn,{to:"/",onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:B("sidebar.home"),children:t.jsx(nb,{size:16})}),t.jsxs(Kn,{to:"/review",onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:B("sidebar.review"),children:[t.jsx(ju,{size:16}),d!==null&&d>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(Kn,{to:"/agenda",onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:B("sidebar.agenda"),children:t.jsx(dm,{size:16})}),we,t.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(Pe=>{const X=h[Pe.id],ne=ge===String(Pe.id),Se=X?X.running+X.running_sessions+X.running_discussions:0,fe=Se>0,ie=Qa(Pe);return t.jsxs(Kn,{to:`/projects/${Pe.id}`,onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:ne?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:fe?`${Pe.name} · ${Se} ${B("detail.live")}`:Pe.name,children:[ne&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ie}}),t.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${fe?"workspace-dot-pulse":""}`,style:{backgroundColor:ie,opacity:ne||fe?1:.55}})]},Pe.id)})}),we,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(En,{onClick:Y,label:B(I==="light"?"theme.dark":"theme.light"),size:"lg",children:I==="light"?t.jsx(rb,{size:16}):t.jsx(ab,{size:16})}),t.jsx(En,{onClick:()=>N(!0),label:B("settings.title"),size:"lg",children:t.jsx(Nu,{size:16})}),t.jsx(bb,{open:D,onClose:()=>N(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:we=>we.preventDefault(),children:[t.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[t.jsxs(Kn,{to:"/",onClick:Ke,className:"block font-mono text-[22px] leading-none whitespace-nowrap select-none",children:[t.jsxs("span",{className:"font-medium text-accent/50",children:[">","_ "]}),t.jsx("span",{className:"font-bold text-accent",children:"CLI"}),t.jsx("span",{className:"font-medium text-theme-text",children:"Trigger"})]}),t.jsx(En,{onClick:m,label:B("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(h1,{size:16})})]}),t.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[t.jsxs(Kn,{to:"/",onClick:Ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/"?"font-medium":""}`,style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.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(nb,{size:16}),B("sidebar.home")]}),t.jsxs(Kn,{to:"/review",onClick:Ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/review"?"font-medium":""}`,style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.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(ju,{size:16}),t.jsx("span",{className:"flex-1",children:B("sidebar.review")}),d!==null&&d>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:d})]}),t.jsxs(Kn,{to:"/agenda",onClick:Ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/agenda"?"font-medium":""}`,style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.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(dm,{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(En,{onClick:()=>C(!0),label:B("projects.new"),size:"sm",children:t.jsx(wn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((we,Pe)=>{const X=h[we.id],ne=ge===String(we.id),Se=X?X.running+X.running_sessions+X.running_discussions:0,fe=Se>0,ie=Qa(we),ke=H===we.id,_e=H!==null&&F===Pe,st=H!==null&&Pe===o.length-1&&F===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[_e&&Ce("above"),t.jsxs(Kn,{to:`/projects/${we.id}`,draggable:!1,onDragStart:Ze=>Ze.preventDefault(),onClick:Ze=>{if(Ie.current){Ze.preventDefault();return}Ke()},onMouseDown:Ze=>it(we.id,Ze),onContextMenu:Ze=>{Ze.preventDefault(),x({project:we,x:Ze.clientX,y:Ze.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 ${ne?"font-medium":""} ${ke?"opacity-50":""}`,style:ne?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:H?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:H?"grabbing":"pointer",userSelect:"none"},children:[ne&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ie}}),t.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${fe?"workspace-dot-pulse":""}`,style:{backgroundColor:ie,opacity:ne||fe?1:.55},title:fe?`${B("sidebar.workspaces")} · ${Se} ${B("detail.live")}`:we.name}),t.jsx("span",{className:"truncate flex-1",children:we.name}),t.jsx(En,{onClick:Ze=>vt(we.id,Ze),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(Jt,{size:12})})]}),st&&Ce("below")]},we.id)})})]}),v&&t.jsx(T1,{onSubmit:(we,Pe)=>Le(we,Pe),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(En,{onClick:()=>{E(null),j(!0)},label:B("favorites.add"),size:"sm",children:t.jsx(wn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:S.map(we=>{const Pe=p3(we.type);return t.jsxs("button",{onClick:()=>De(we.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:we.target,children:[t.jsx(Pe,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:we.name}),t.jsx("span",{onClick:X=>Re(we,X),className:"flex-shrink-0 p-0.5 rounded-md 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(pm,{size:12})}),t.jsx("span",{onClick:X=>be(we.id,X),className:"flex-shrink-0 p-0.5 rounded-md 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(Jt,{size:12})})]},we.id)})})]}),w&&t.jsx(X4,{initial:R??void 0,onSubmit:We,onCancel:()=>{j(!1),E(null)}}),k&&t.jsx(d3,{project:k.project,anchorX:k.x,anchorY:k.y,onPick:async we=>{try{const Pe=await xm(k.project.id,{color:we});l(X=>X.map(ne=>ne.id===Pe.id?{...ne,color:Pe.color}:ne)),window.dispatchEvent(new Event("projects:changed"))}catch(Pe){Z(Pe instanceof Error?Pe.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(bb,{open:D,onClose:()=>N(!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(En,{onClick:Y,label:B(I==="light"?"theme.dark":"theme.light"),children:I==="light"?t.jsx(rb,{size:16}):t.jsx(ab,{size:16})}),t.jsx(En,{onClick:A,label:B("lang.toggle"),className:"text-xs font-medium",children:B("lang.toggle")}),J&&t.jsx(En,{onClick:re,label:"Notification"in window&&Notification.permission==="denied"?B("notification.blocked"):B("notification.toggle"),variant:G?"active":"default",pressed:G,children:G?t.jsx(N5,{size:16}):t.jsx(j5,{size:16})}),t.jsx(En,{onClick:ue,disabled:P,label:B("tunnel.start"),variant:(T==null?void 0:T.status)==="running"?"active":"default",pressed:(T==null?void 0:T.status)==="running",title:(T==null?void 0:T.status)==="running"&&T.url?`${T.url} — ${B("tunnel.urlCopied")}`:B(P?"tunnel.starting":"tunnel.start"),children:t.jsx(o1,{size:16})}),t.jsx(En,{onClick:()=>N(!0),label:B("settings.title"),children:t.jsx(Nu,{size:16})}),s&&t.jsx(En,{onClick:e,label:B("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(ZE,{size:16})})]})})]})}function x3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:u}){const[f,m]=y.useState(!1),{t:o}=xt(),[l,h]=y.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),p=()=>{h(d=>{const g=!d;return localStorage.setItem("sidebarCollapsed",g?"1":"0"),g})};return t.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[t.jsx("aside",{"data-app-sidebar":!0,className:`
612
+ */const VN=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],YN=ft("zoom-out",VN),lb=8;function XN({onLogin:e,onChangePassword:s}){const[i,a]=y.useState(""),[u,f]=y.useState(""),[m,o]=y.useState(""),[l,h]=y.useState(!1),[p,d]=y.useState(!1),[g,v]=y.useState(!1),[C,k]=y.useState(""),[x,S]=y.useState(!1),{t:_,toggleLang:w}=xt(),j=l&&u.length>0&&u.length<lb,R=l&&m.length>0&&u!==m,E=l?!!i&&u.length>=lb&&u===m:!!i,D=()=>{h(T=>!T),f(""),o(""),k("")},N=async T=>{if(T.preventDefault(),!(!E||x)){k(""),S(!0);try{l?await s(i,u,m,g):await e(i,g)}catch(z){k(l&&z instanceof Error&&z.message?z.message:_("login.error"))}finally{S(!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:w,className:"lang-toggle absolute top-6 right-6",children:_("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm",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(wl,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:_("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:_("login.subtitle")})]}),t.jsx("form",{onSubmit:N,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:_(l?"account.oldPassword":"login.password")}),t.jsx("input",{type:"password",value:i,onChange:T=>a(T.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),l&&t.jsxs(t.Fragment,{children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.newPassword")}),t.jsx("input",{type:"password",value:u,onChange:T=>f(T.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.newPassword")}),j&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.confirm")}),t.jsx("input",{type:"password",value:m,onChange:T=>o(T.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.confirm")}),R&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.mismatch")})]}),C&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:C}),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:g,onChange:T=>v(T.target.checked),className:"accent-accent w-4 h-4"}),_("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!E||x,className:"btn-primary w-full mt-6 py-3",children:_(x?"login.loading":l?"login.changeSubmit":"login.submit")})]})}),t.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[t.jsx("button",{type:"button",onClick:D,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_(l?"login.backToLogin":"login.changePassword")}),t.jsx("button",{type:"button",onClick:()=>d(T=>!T),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_("login.forgot")})]}),p&&t.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:_("login.forgotHint")}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:_("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:_("login.disclaimer")})]})]})}const cb=8;function JN({onSetup:e}){const[s,i]=y.useState(""),[a,u]=y.useState(""),[f,m]=y.useState(""),[o,l]=y.useState(!1),{t:h,toggleLang:p}=xt(),d=s.length>0&&s.length<cb,g=a.length>0&&s!==a,v=s.length>=cb&&s===a&&!o,C=async k=>{if(k.preventDefault(),!!v){m(""),l(!0);try{await e(s,a)}catch(x){m(x instanceof Error&&x.message?x.message:h("setup.error"))}finally{l(!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:h("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm",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(wl,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:h("setup.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:h("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:h("setup.password")}),t.jsx("input",{type:"password",value:s,onChange:k=>i(k.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),d&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("setup.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:h("setup.confirm")}),t.jsx("input",{type:"password",value:a,onChange:k=>u(k.target.value),placeholder:"*************",className:"input-field text-base"}),g&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("setup.mismatch")}),f&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:f}),t.jsx("button",{type:"submit",disabled:!v,className:"btn-primary w-full mt-6 py-3",children:h(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:h("setup.tunnelPaused")})]})]})}function QN(e){return ht("/api/projects/browse",{initialPath:e})}function ZN(e){return ht("/api/projects/open-folder",{path:e})}function Yu(){return wt("/api/projects")}function e4(e){return wt(`/api/projects/${e}`)}function m1(e){return ht("/api/projects",e)}function t4(e){return wt(`/api/projects/${e}/svn-detect`)}function xm(e,s){return pn(`/api/projects/${e}`,s)}function n4(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return wt(`/api/projects/${e}/debug-logs${i}`)}function p1(e){return Vn(`/api/projects/${e}`)}function s4(e){return ht("/api/projects/reorder",{ids:e})}function r4(e){return ht(`/api/projects/${e}/start`)}function i4(e){return ht(`/api/projects/${e}/stop`)}function g1(e){return wt(`/api/projects/${e}/status`)}function ub(){return wt("/api/active-work")}function a4(e){return ht(`/api/projects/${e}/check-git`)}function x1(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return wt(`/api/projects/${e}/git-status${i}`)}function o4(e,s=0,i=50,a){const u=new URLSearchParams({skip:String(s),limit:String(i)});return wt(`/api/projects/${e}/git-log?${u}`)}function vm(e,s){return wt(`/api/projects/${e}/git-refs`)}function l4(e,s,i){return ht(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function c4(e,s,i){return ht(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function u4(e,s,i){return ht(`/api/projects/${e}/git-ignore`,{path:s,worktreePath:i})}function v1(e,s,i){return ht(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function b1(e,s,i){return ht(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function fp(e,s){return ht(`/api/projects/${e}/git-push`,s||{})}function d4(e){return wt(`/api/projects/${e}/git-remotes`)}function y1(e,s,i){return ht(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function w1(e,s,i){return ht(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function bm(e,s,i){return ht(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function ym(e,s){return ht(`/api/projects/${e}/git-checkout`,{branch:s})}function _1(e,s){return ht(`/api/projects/${e}/git-merge`,{branch:s})}function db(e,s,i,a){return ht(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function h4(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return wt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function f4(e,s,i,a){return ht(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function m4(e){return ht(`/api/projects/${e}/git-conflict-continue`)}function p4(e){return ht(`/api/projects/${e}/git-conflict-abort`)}function g4(e,s){return ht(`/api/projects/${e}/git-stash`,{message:s})}function x4(e,s){return ht(`/api/projects/${e}/git-stash-pop`,{index:s})}function v4(e){return wt(`/api/projects/${e}/git-stash-list`)}function b4(e,s,i,a){return ht(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function S1(e,s,i,a){return ht(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function hb(e,s,i){return ht(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function y4(e,s){return ht(`/api/projects/${e}/git-rebase`,{onto:s})}function w4(e,s){return ht(`/api/projects/${e}/git-revert`,{commit:s})}function _4(e,s){return ht(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function S4(e,s,i){return ht(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function k4(e,s,i,a){const u=new URLSearchParams;return s&&u.set("file",s),i&&u.set("staged","true"),a&&u.set("worktreePath",a),wt(`/api/projects/${e}/git-diff?${u}`)}function C4(e,s){const i=new URLSearchParams({hash:s});return wt(`/api/projects/${e}/git-commit-files?${i}`)}function fb(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),wt(`/api/projects/${e}/git-commit-diff?${a}`)}function wm(e){return wt(`/api/projects/${e}/worktrees`)}function mb(e,s,i){return ht(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function k1(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 j4(e={}){return wt(`/api/review/queue${k1(e)}`)}function C1(e={}){return wt(`/api/review/summary${k1(e)}`)}function E4(e){return wt(`/api/review/diff/${encodeURIComponent(e)}`)}function N4(e,s){return wt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function L4(){return wt("/api/favorites")}function D4(e){return ht("/api/favorites",e)}function T4(e,s){return pn(`/api/favorites/${e}`,s)}function R4(e){return Vn(`/api/favorites/${e}`)}function M4(e){return ht(`/api/favorites/${e}/launch`)}function A4(e){return ht("/api/favorites/browse-file",{initialPath:e})}function _m(){return wt("/api/tunnel/status")}function z4(){return wt("/api/tunnel/config")}function O4(e){return pn("/api/tunnel/config",e)}function j1(e){return ht("/api/tunnel/start",{})}function B4(){return ht("/api/tunnel/stop")}const E1=y.createContext({theme:"light",toggleTheme:()=>{}});function P4(){const[e,s]=y.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});y.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=y.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function I4(){return y.useContext(E1)}const N1=y.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function F4(){const e="Notification"in window,[s,i]=y.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=y.useRef(s);y.useEffect(()=>{a.current=s},[s]);const u=y.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=y.useCallback((m,o)=>{if(!a.current)return;const l=new Notification(m,{body:o});l.onclick=()=>{window.focus(),l.close()}},[]);return{enabled:s,supported:e,toggleNotification:u,sendNotification:f}}function ro(){return y.useContext(N1)}let H4=0;const L1=y.createContext(null);function $4({children:e}){const[s,i]=y.useState([]),a=y.useRef(new Map),u=y.useRef(new Map),f=y.useRef(new Map),m=y.useCallback(v=>{i(x=>x.filter(S=>S.id!==v));const C=f.current.get(v);C&&u.current.get(C)===v&&u.current.delete(C),f.current.delete(v);const k=a.current.get(v);k&&(clearTimeout(k),a.current.delete(v))},[]),o=y.useCallback((v,C="info",k=3500)=>{const x=`${C}:${v}`,S=u.current.get(x);if(S)return S;const _=`toast-${++H4}`;u.current.set(x,_),f.current.set(_,x),i(j=>[...j,{id:_,message:v,type:C,duration:k}]);const w=setTimeout(()=>m(_),k);return a.current.set(_,w),_},[m]),l=y.useCallback((v,C)=>o(v,"success",C),[o]),h=y.useCallback((v,C)=>o(v,"error",C),[o]),p=y.useCallback((v,C)=>o(v,"info",C),[o]),d=y.useCallback((v,C)=>o(v,"warning",C),[o]);y.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),u.current.clear(),f.current.clear()},[]);const g=y.useMemo(()=>({toasts:s,show:o,success:l,error:h,info:p,warning:d,dismiss:m}),[s,o,l,h,p,d,m]);return y.createElement(L1.Provider,{value:g},e)}function Rs(){const e=y.useContext(L1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function $s(...e){return e.filter(Boolean).join(" ")}const U4={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl","2xl":"max-w-2xl","4xl":"max-w-4xl"};function Dn({open:e,onClose:s,size:i="md",position:a="center",disableEscClose:u=!1,disableBackdropClose:f=!1,children:m}){const o=y.useRef(null);return y.useEffect(()=>{if(!e||u)return;const l=h=>{h.key==="Escape"&&s()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[e,u,s]),e?cn.createPortal(t.jsx("div",{ref:o,className:$s("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:l=>{!f&&l.target===o.current&&s()},children:t.jsx("div",{className:$s("w-full",U4[i]),children:m})}),document.body):null}const W4={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},q4={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},$t=y.forwardRef(function({variant:s="default",size:i,type:a="button",className:u,...f},m){return t.jsx("button",{ref:m,type:a,className:$s(W4[s],i&&q4[i],u),...f})}),D1=y.createContext(null);let pb=0;function G4({children:e}){const[s,i]=y.useState(null),a=y.useRef(null),u=y.useCallback(h=>{const p=a.current;p&&(p.kind==="confirm"?p.resolve(!1):p.resolve(null)),a.current=h,i(h)},[]),f=y.useCallback(()=>{a.current=null,i(null)},[]),m=y.useCallback(h=>{const p=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++pb,kind:"confirm",options:p,resolve:d})})},[u]),o=y.useCallback(h=>{const p=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++pb,kind:"prompt",options:p,resolve:d})})},[u]),l=y.useMemo(()=>({confirm:m,prompt:o}),[m,o]);return t.jsxs(D1.Provider,{value:l,children:[e,s&&t.jsx(K4,{dialog:s,onSettled:f},s.id)]})}function K4({dialog:e,onSettled:s}){const{t:i}=xt(),[a,u]=y.useState(e.kind==="prompt"?e.options.initialValue??"":""),f=()=>{e.kind==="confirm"?e.resolve(!1):e.resolve(null),s()},m=()=>{e.kind==="confirm"?e.resolve(!0):e.resolve(a),s()},o=e.kind==="confirm"&&!!e.options.danger,l=e.kind==="confirm"&&e.options.confirmLabel||i("common.ok"),h=e.kind==="confirm"&&e.options.cancelLabel||i("common.cancel"),p=t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx($t,{size:"sm",onClick:f,autoFocus:o,children:h}),t.jsx($t,{variant:o?"danger":"primary",size:"sm",type:e.kind==="prompt"?"submit":"button",onClick:e.kind==="prompt"?void 0:m,autoFocus:e.kind==="confirm"&&!o,children:l})]});return t.jsx(Dn,{open:!0,onClose:f,size:"sm",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-5",children:[e.options.title&&t.jsx("div",{className:"text-sm font-semibold text-theme-text mb-2",children:e.options.title}),t.jsx("p",{className:"text-sm text-theme-text-secondary whitespace-pre-line break-words",children:e.options.message}),e.kind==="prompt"?t.jsxs("form",{onSubmit:d=>{d.preventDefault(),m()},children:[t.jsx("input",{autoFocus:!0,value:a,onChange:d=>u(d.target.value),placeholder:e.options.placeholder,className:"input-field mt-3"}),p]}):p]})})}function Yn(){const e=y.useContext(D1);if(!e)throw new Error("useDialog must be used within DialogProvider");return e}function T1({onSubmit:e,onCancel:s}){const[i,a]=y.useState(""),[u,f]=y.useState(""),[m,o]=y.useState(!1),[l,h]=y.useState(!1),[p,d]=y.useState(""),{t:g}=xt(),v=async k=>{if(k.preventDefault(),!(!i.trim()||!u.trim())){d(""),h(!0);try{await e(i.trim(),u.trim())}catch(x){const S=x instanceof Error?x.message:String(x);d(S||g("form.createError"))}finally{h(!1)}}},C=async()=>{o(!0);try{const k=await QN(u||void 0);k.path&&f(k.path)}catch{}o(!1)};return t.jsx(Dn,{open:!0,onClose:s,size:"md",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:g("form.newProject")}),t.jsxs("form",{onSubmit:v,children:[t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:g("form.projectName")}),t.jsx("input",{type:"text",placeholder:"my-project",value:i,onChange:k=>a(k.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:g("form.folderPath")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:u,onChange:k=>f(k.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:g("browse.title"),children:m?t.jsx(Tr,{size:16,className:"animate-spin"}):t.jsx(Gu,{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:g("form.cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||!u.trim()||l,className:"btn-primary text-sm",children:g(l?"form.creating":"form.create")})]})]})]})})}const V4=[{value:"executable",icon:up},{value:"command",icon:bi},{value:"url",icon:yl}];function Y4(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 gb(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 X4({initial:e,onSubmit:s,onCancel:i}){const{t:a}=xt(),[u,f]=y.useState((e==null?void 0:e.name)??""),[m,o]=y.useState((e==null?void 0:e.type)??"executable"),[l,h]=y.useState((e==null?void 0:e.target)??""),[p,d]=y.useState(gb((e==null?void 0:e.args)??null)),[g,v]=y.useState((e==null?void 0:e.cwd)??""),[C,k]=y.useState(!1);y.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),h((e==null?void 0:e.target)??""),d(gb((e==null?void 0:e.args)??null)),v((e==null?void 0:e.cwd)??"")},[e]);const[x,S]=y.useState(!1),_=m==="executable",w=async()=>{S(!0);try{const{path:P}=await A4(l||void 0);if(!P)return;if(h(P),!u.trim()){const O=P.replace(/\\/g,"/").split("/").pop()||"";f(O.replace(/\.[^.]+$/,""))}}catch{}finally{S(!1)}},j=!!e,R=u.trim(),E=l.trim(),D=m!=="url"||/^https?:\/\//i.test(E),N=!!R&&!!E&&D&&!C,T=async P=>{if(P.preventDefault(),!!N){k(!0);try{const O={name:R,type:m,target:E,args:m==="executable"&&p.trim()?Y4(p.trim()):null,cwd:m!=="url"&&g.trim()?g.trim():null};await s(O)}finally{k(!1)}}},z=a(m==="executable"?"favorites.form.targetHint.executable":m==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return t.jsx(Dn,{open:!0,onClose:i,size:"md",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:a(j?"favorites.form.title.edit":"favorites.form.title.create")}),t.jsxs("form",{onSubmit:T,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:V4.map(({value:P,icon:O})=>t.jsxs("button",{type:"button",onClick:()=>o(P),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:m===P?{backgroundColor:"var(--color-accent)",color:"white",borderColor:"var(--color-accent)"}:{color:"var(--color-text-tertiary)",borderColor:"var(--color-border)"},children:[t.jsx(O,{size:14}),a(`favorites.types.${P}`)]},P))})]}),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:u,onChange:P=>f(P.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:l,onChange:P=>h(P.target.value),className:"input-field text-sm font-mono flex-1",placeholder:z}),_&&t.jsxs("button",{type:"button",onClick:w,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx(Gu,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:z})]}),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:P=>d(P.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:g,onChange:P=>v(P.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:!N,className:"btn-primary text-sm",children:a(j?"favorites.form.save":"favorites.form.create")})]})]})]})})}const J4=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function Q4({onClose:e}){const{t:s}=xt(),{error:i,success:a}=Rs(),[u,f]=y.useState(""),[m,o]=y.useState(""),[l,h]=y.useState(""),[p,d]=y.useState(""),[g,v]=y.useState(!1),[C,k]=y.useState(!1),[x,S]=y.useState(!1),[_,w]=y.useState(null);y.useEffect(()=>{let O=!1;return Promise.all([z4(),_m()]).then(([H,U])=>{O||(f(H.tunnelName),o(H.customHostname),h(H.tunnelName),d(H.customHostname),w(U))}).catch(()=>{}),()=>{O=!0}},[]);const j=u.trim(),R=m.trim(),E=j!==l.trim()||R!==p.trim(),D=!!R&&(!J4.test(R)||R.toLowerCase()==="localhost"||R.toLowerCase()==="127.0.0.1"),N=!!R&&!j,T=E&&!C&&!D&&!N,z=async()=>{if(T){k(!0);try{const O=await O4({tunnelName:j,customHostname:R});h(O.tunnelName),d(O.customHostname),f(O.tunnelName),o(O.customHostname),a(s("tunnel.saved"))}catch(O){i(O instanceof Error?O.message:s("tunnel.saveFailed"))}finally{k(!1)}}},P=async()=>{S(!0);try{try{await B4()}catch{}const O=await j1();w({status:"running",url:O.url}),a(s("tunnel.restarted"))}catch(O){i(O instanceof Error?O.message:s("tunnel.restartFailed"))}finally{S(!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")}),_&&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 ${_.status==="running"?"bg-status-success":_.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${_.status}`)}),_.url&&t.jsx("a",{href:_.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:_.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:u,onChange:O=>f(O.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:O=>o(O.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")}),D&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),N&&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:()=>v(!g),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 ${g?"rotate-90":""}`,children:"▶"}),s("tunnel.guide.toggle")]}),g&&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:P,disabled:x,className:"btn-ghost text-sm disabled:opacity-50",children:x?(_==null?void 0:_.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(_==null?void 0:_.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:z,disabled:!T,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const xb=8;function Z4({onClose:e}){const{t:s}=xt(),{error:i,success:a}=Rs(),[u,f]=y.useState(""),[m,o]=y.useState(""),[l,h]=y.useState(""),[p,d]=y.useState(!1),g=m.length>0&&m.length<xb,v=l.length>0&&m!==l,C=!!u&&m.length>=xb&&m===l&&!p,k=()=>{f(""),o(""),h("")},x=async()=>{if(C){d(!0);try{await Zw(u,m,l),a(s("account.saved")),k()}catch(S){i(S instanceof Error&&S.message?S.message:s("account.saveFailed"))}finally{d(!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:u,onChange:S=>f(S.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:S=>o(S.target.value),className:"input-field text-sm",autoComplete:"new-password"}),g&&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:l,onChange:S=>h(S.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.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 mp(){return wt("/api/session-tags")}function e3(e){return ht("/api/session-tags",e)}function t3(e,s){return pn(`/api/session-tags/${e}`,s)}function n3(e){return Vn(`/api/session-tags/${e}`)}function R1(){return wt("/api/session-aliases")}function M1(e){return ht("/api/session-aliases",e)}function s3(e,s){return pn(`/api/session-aliases/${e}`,s)}function r3(e){return Vn(`/api/session-aliases/${e}`)}function pp(){return wt("/api/session-settings")}function wf(e){return pn("/api/session-settings",e)}const Ge={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},Ht="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",gp=13,cl=8,ul=28,Ja=new Map,Gi=new Map;let Lu=gp;function xp(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);Ja.delete(s);const i=Gi.get(s);if(i){const u=dl(s);i.forEach(f=>f(u))}});function Sm(e){return Number.isFinite(e)?Math.max(cl,Math.min(ul,Math.round(e))):Lu}function i3(e){if(Ja.has(e))return!0;try{return localStorage.getItem(xp(e))!==null}catch{return!1}}function dl(e){const s=Ja.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(xp(e));if(a!==null){const u=parseInt(a,10);Number.isFinite(u)&&(i=Sm(u))}}catch{}return i===null?Sm(Lu):(Ja.set(e,i),i)}function km(e,s){const i=Sm(s);if(Ja.get(e)===i)return;Ja.set(e,i);try{localStorage.setItem(xp(e),String(i))}catch{}const a=Gi.get(e);a&&a.forEach(u=>u(i))}function Zo(e,s){km(e,dl(e)+s)}function xu(e){const s=Math.max(cl,Math.min(ul,Math.round(e)));Number.isFinite(s)&&s!==Lu&&(Lu=s,Gi.forEach((i,a)=>{i3(a)||i.forEach(u=>u(s))}))}function A1(e){const[s,i]=y.useState(()=>dl(e));y.useEffect(()=>{i(dl(e));let f=Gi.get(e);return f||(f=new Set,Gi.set(e,f)),f.add(i),()=>{const m=Gi.get(e);m&&(m.delete(i),m.size===0&&Gi.delete(e))}},[e]);const a=y.useCallback(f=>km(e,f),[e]),u=y.useCallback(f=>km(e,dl(e)+f),[e]);return[s,a,u]}const hl=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function vb(e){for(const s of hl)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return hl[e.length%hl.length]}function a3({onClose:e}){const{t:s}=xt(),{confirm:i}=Yn(),{error:a,success:u}=Rs(),[f,m]=y.useState([]),[o,l]=y.useState(!1),[h,p]=y.useState(gp),[d,g]=y.useState(!1),[v,C]=y.useState(!1),[k,x]=y.useState(!1),[S,_]=y.useState(!1),w=y.useRef(null),[j,R]=y.useState(""),[E,D]=y.useState(hl[0]),[N,T]=y.useState(!1),[z,P]=y.useState(null),[O,H]=y.useState(""),[U,F]=y.useState(hl[0]),[q,$]=y.useState(!1),[K,B]=y.useState([]),[A,I]=y.useState(""),[Y,G]=y.useState(""),[J,re]=y.useState(!1),[Z,Q]=y.useState(null),[W,oe]=y.useState(""),[le,ge]=y.useState(""),[ue,Ve]=y.useState(!1);y.useEffect(()=>{let ie=!1;return Promise.all([mp(),pp(),R1()]).then(([ke,_e,st])=>{ie||(m(ke),l(_e.defaultUseWorktree),p(_e.defaultFontSize),xu(_e.defaultFontSize),g(_e.imeDebug),D(vb(ke)),B(st),C(!0))}).catch(ke=>{ie||a(ke instanceof Error?ke.message:"Failed to load")}),()=>{ie=!0}},[a]);const We=j.trim(),De=!!We&&!N,be=y.useMemo(()=>[...f].sort((ie,ke)=>ie.sort_order-ke.sort_order||ie.name.localeCompare(ke.name)),[f]);y.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const Re=ie=>{if(!Number.isFinite(ie))return;const ke=Math.max(cl,Math.min(ul,Math.round(ie)));p(ke),xu(ke),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{wf({defaultFontSize:ke}).then(_e=>{p(_e.defaultFontSize),xu(_e.defaultFontSize)}).catch(_e=>a(_e instanceof Error?_e.message:"Save failed"))},350)},ct=async ie=>{x(!0);try{const ke=await wf({defaultUseWorktree:ie});l(ke.defaultUseWorktree),u(s("sessionSettings.saved"))}catch(ke){a(ke instanceof Error?ke.message:"Save failed")}finally{x(!1)}},tt=async ie=>{var ke,_e;_(!0);try{const st=await wf({imeDebug:ie});g(st.imeDebug),(_e=(ke=window.electronAPI)==null?void 0:ke.imeSetDebug)==null||_e.call(ke,st.imeDebug),u(s("sessionSettings.saved"))}catch(st){a(st instanceof Error?st.message:"Save failed")}finally{_(!1)}},Ke=async()=>{if(De){T(!0);try{const ie=await e3({name:We,color:E});m(ke=>[...ke,ie]),R(""),D(vb([...f,ie]))}catch(ie){a(ie instanceof Error?ie.message:"Create failed")}finally{T(!1)}}},Le=ie=>{P(ie.id),H(ie.name),F(ie.color)},$e=()=>{P(null),H("")},Ie=async()=>{if(!z)return;const ie=O.trim();if(ie){$(!0);try{const ke=await t3(z,{name:ie,color:U});m(_e=>_e.map(st=>st.id===ke.id?ke:st)),$e()}catch(ke){a(ke instanceof Error?ke.message:"Save failed")}finally{$(!1)}}},it=async ie=>{if(await i({message:s("sessionSettings.tags.deleteConfirm").replace("{name}",ie.name),danger:!0}))try{await n3(ie.id),m(ke=>ke.filter(_e=>_e.id!==ie.id))}catch(ke){a(ke instanceof Error?ke.message:"Delete failed")}},vt=A.trim(),Ce=Y.trim(),Ue=!!vt&&!!Ce&&!J,we=y.useMemo(()=>[...K].sort((ie,ke)=>ie.sort_order-ke.sort_order||ie.name.localeCompare(ke.name)),[K]),Pe=async()=>{if(Ue){re(!0);try{const ie=await M1({name:vt,command_template:Ce});B(ke=>[...ke,ie]),I(""),G("")}catch(ie){a(ie instanceof Error?ie.message:"Create failed")}finally{re(!1)}}},X=ie=>{Q(ie.id),oe(ie.name),ge(ie.command_template)},ne=()=>{Q(null),oe(""),ge("")},Se=async()=>{if(!Z)return;const ie=W.trim(),ke=le.trim();if(!(!ie||!ke)){Ve(!0);try{const _e=await s3(Z,{name:ie,command_template:ke});B(st=>st.map(Ze=>Ze.id===_e.id?_e:Ze)),ne()}catch(_e){a(_e instanceof Error?_e.message:"Save failed")}finally{Ve(!1)}}},fe=async ie=>{if(await i({message:s("sessionSettings.aliases.deleteConfirm").replace("{name}",ie.name),danger:!0}))try{await r3(ie.id),B(ke=>ke.filter(_e=>_e.id!==ie.id))}catch(ke){a(ke instanceof Error?ke.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(Qi,{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:o,disabled:k||!v,onChange:ie=>ct(ie.target.checked),className:"rounded-md 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(IN,{size:14}),s("sessionSettings.fontSize.title")]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("input",{type:"range",min:cl,max:ul,step:1,value:h,disabled:!v,onChange:ie=>Re(parseInt(ie.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),t.jsx("input",{type:"number",min:cl,max:ul,step:1,value:h,disabled:!v,onChange:ie=>Re(parseInt(ie.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:E,onChange:ie=>D(ie.target.value),className:"w-9 h-9 rounded-md cursor-pointer border border-warm-200",title:s("sessionSettings.tags.color")}),t.jsx("input",{type:"text",value:j,onChange:ie=>R(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&(ie.preventDefault(),Ke())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),t.jsxs("button",{type:"button",onClick:Ke,disabled:!De,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(wn,{size:14}),s("sessionSettings.tags.add")]})]}),be.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:be.map(ie=>{const ke=z===ie.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ke?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:U,onChange:_e=>F(_e.target.value),className:"w-7 h-7 rounded-md cursor-pointer border border-warm-200"}),t.jsx("input",{type:"text",value:O,onChange:_e=>H(_e.target.value),onKeyDown:_e=>{_e.key==="Enter"&&(_e.preventDefault(),Ie()),_e.key==="Escape"&&$e()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),t.jsx("button",{type:"button",onClick:Ie,disabled:q||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("sessionSettings.tags.save"),children:t.jsx(ar,{size:14})}),t.jsx("button",{type:"button",onClick:$e,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.cancel"),children:t.jsx(Jt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:ie.color,borderColor:"rgba(0,0,0,0.08)"}}),t.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:ie.name}),t.jsx("button",{type:"button",onClick:()=>Le(ie),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.edit"),children:t.jsx(xi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>it(ie),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.delete"),children:t.jsx(Pn,{size:14})})]})},ie.id)})})]}),t.jsxs("section",{className:"mt-7",children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:s("sessionSettings.aliases.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-3",children:s("sessionSettings.aliases.description")}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx("input",{type:"text",value:A,onChange:ie=>I(ie.target.value),placeholder:s("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:Y,onChange:ie=>G(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&(ie.preventDefault(),Pe())},placeholder:s("sessionSettings.aliases.commandPlaceholder"),className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsxs("button",{type:"button",onClick:Pe,disabled:!Ue,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(wn,{size:14}),s("sessionSettings.aliases.add")]})]}),we.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:s("sessionSettings.aliases.empty")}):t.jsx("ul",{className:"space-y-1.5",children:we.map(ie=>{const ke=Z===ie.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:ke?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:W,onChange:_e=>oe(_e.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:le,onChange:_e=>ge(_e.target.value),onKeyDown:_e=>{_e.key==="Enter"&&(_e.preventDefault(),Se()),_e.key==="Escape"&&ne()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:Se,disabled:ue||!W.trim()||!le.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("common.save"),children:t.jsx(ar,{size:14})}),t.jsx("button",{type:"button",onClick:ne,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("common.cancel"),children:t.jsx(Jt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:ie.name}),t.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:ie.command_template}),t.jsx("button",{type:"button",onClick:()=>X(ie),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:s("common.edit"),children:t.jsx(xi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>fe(ie),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:s("common.delete"),children:t.jsx(Pn,{size:14})})]})},ie.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(D5,{size:14}),"IME 디버그 로그"]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:d,disabled:S||!v,onChange:ie=>tt(ie.target.checked),className:"rounded-md 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 o3(){return wt("/api/mcp/connection")}function l3({onClose:e}){const{t:s}=xt(),{success:i,error:a}=Rs(),[u,f]=y.useState(null),[m,o]=y.useState(null);y.useEffect(()=>{let g=!1;return o3().then(v=>{g||f(v)}).catch(()=>{}),()=>{g=!0}},[]);const l=async(g,v)=>{try{await navigator.clipboard.writeText(v),o(g),setTimeout(()=>o(C=>C===g?null:C),1500),i(s("mcp.copied"))}catch{a(s("mcp.copyFailed"))}},h=u?JSON.stringify(u.config,null,2):"",p=({label:g,text:v})=>t.jsxs("button",{type:"button",onClick:()=>l(g,v),className:"btn-ghost text-xs flex items-center gap-1",children:[m===g?t.jsx(ar,{size:14}):t.jsx(cE,{size:14}),s("mcp.copy")]}),d={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("mcp.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("mcp.description")}),u?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600",children:s("mcp.config.label")}),t.jsx(p,{label:"config",text:h})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:d,children:h})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:s("mcp.commands.label")}),t.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:s("mcp.commands.hint")}),t.jsx("div",{className:"space-y-3",children:u.commands.map(g=>t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-xs text-warm-500",children:g.label}),t.jsx(p,{label:`command:${g.id}`,text:g.command})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:d,children:g.command})]},g.id))})]}),t.jsx("p",{className:"text-2xs text-warm-400",children:s("mcp.tokenNote")})]}):t.jsx("p",{className:"text-sm text-warm-400",children:s("mcp.loading")}),e&&t.jsx("div",{className:"flex justify-end mt-6",children:t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("mcp.close")})})]})}function bb({open:e,onClose:s}){const{t:i}=xt(),[a,u]=y.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:FE},{id:"session",label:i("settings.tabs.session"),icon:wl},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:o1},{id:"mcp",label:i("settings.tabs.mcp"),icon:bN}];return t.jsx(Dn,{open:e,onClose:s,size:"xl",children:t.jsx("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated 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:l})=>{const h=a===m;return t.jsxs("button",{type:"button",onClick:()=>u(m),className:"flex items-center gap-2 px-4 py-2.5 text-sm transition-colors text-left",style:{color:h?"var(--color-accent)":"var(--color-text-secondary)",backgroundColor:h?"var(--color-bg-primary)":"transparent",fontWeight:h?600:400},children:[t.jsx(l,{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.63"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(Z4,{onClose:s}),a==="session"&&t.jsx(a3,{onClose:s}),a==="tunnel"&&t.jsx(Q4,{onClose:s}),a==="mcp"&&t.jsx(l3,{onClose:s})]})]})})})}const Cm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function c3(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 Qa(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:Cm[c3(e.id,Cm.length)]}const yb=192,u3=88,Vc=8;function d3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:u}){const f=y.useRef(null),[m,o]=y.useState({left:s,top:i}),l=Qa(e);return y.useLayoutEffect(()=>{const h=Math.min(Math.max(s,Vc),window.innerWidth-yb-Vc),p=Math.min(Math.max(i,Vc),window.innerHeight-u3-Vc);o({left:h,top:p})},[s,i]),y.useEffect(()=>{const h=d=>{var g;(g=f.current)!=null&&g.contains(d.target)||u()},p=d=>{d.key==="Escape"&&u()};return window.addEventListener("mousedown",h),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",p)}},[u]),cn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:yb,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:Cm.map(h=>{const p=e.color?h.toLowerCase()===e.color.toLowerCase():h===l&&!e.color;return t.jsx("button",{onClick:()=>a(h),"aria-label":h,style:{width:20,height:20,borderRadius:6,background:h,border:p?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},h)})}),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 fl(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function h3(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 f3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},m3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},En=y.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:u,type:f="button",title:m,className:o,...l},h){return t.jsx("button",{ref:h,type:f,"aria-label":s,"aria-pressed":u,title:m??s,className:$s("btn-icon",f3[i],m3[a],o),...l})});function p3(e){return e==="executable"?up:e==="command"?bi:yl}function g3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:u,collapsed:f=!1,onToggleCollapsed:m}){var Ue;const[o,l]=y.useState([]),[h,p]=y.useState({}),[d,g]=y.useState(null),[v,C]=y.useState(!1),[k,x]=y.useState(null),[S,_]=y.useState([]),[w,j]=y.useState(!1),[R,E]=y.useState(null),[D,N]=y.useState(!1),[T,z]=y.useState(null),[P,O]=y.useState(!1),[H,U]=y.useState(null),[F,q]=y.useState(null),$=Ks(),K=wi(),{t:B,toggleLang:A}=xt(),{theme:I,toggleTheme:Y}=I4(),{enabled:G,supported:J,toggleNotification:re}=ro(),{error:Z,success:Q,info:W,warning:oe}=Rs(),{confirm:le}=Yn(),ge=((Ue=$.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:Ue[1])||null;y.useEffect(()=>{tt(),Ve(),_m().then(z).catch(()=>{})},[]);async function ue(){if(!P){O(!0);try{const we=await _m();if(z(we),we.status==="running"&&we.url){await navigator.clipboard.writeText(we.url),Q(B("tunnel.urlCopied"));return}const Pe=await j1(),X={status:"running",url:Pe.url};z(X);try{await navigator.clipboard.writeText(Pe.url),Q(B("tunnel.urlCopied"))}catch{Q(Pe.url)}}catch(we){Z(we instanceof Error?we.message:B("tunnel.restartFailed"))}finally{O(!1)}}}function Ve(){L4().then(_).catch(()=>{})}const We=async we=>{try{R?await T4(R.id,we):await D4(we),j(!1),E(null),Ve()}catch(Pe){Z(Pe instanceof Error?Pe.message:"Failed to save favorite")}},De=async we=>{try{await M4(we)}catch(Pe){const X=Pe instanceof Error?Pe.message:B("favorites.launchFailed");Z(`${B("favorites.launchFailed")}: ${X}`)}},be=async(we,Pe)=>{if(Pe.preventDefault(),Pe.stopPropagation(),!!await le({message:B("favorites.deleteConfirm"),danger:!0}))try{await R4(we),_(X=>X.filter(ne=>ne.id!==we))}catch(X){Z(X instanceof Error?X.message:"Failed to delete favorite")}},Re=(we,Pe)=>{Pe.preventDefault(),Pe.stopPropagation(),E(we),j(!0)};y.useEffect(()=>{const we=()=>tt();return window.addEventListener("projects:changed",we),()=>window.removeEventListener("projects:changed",we)},[]),y.useEffect(()=>{const we=()=>ct();return window.addEventListener("review:changed",we),()=>window.removeEventListener("review:changed",we)},[]),y.useEffect(()=>a(we=>{var Pe;if(we.type==="project:status-changed"&&we.projectId&&p(X=>({...X,[we.projectId]:{running:we.running??0,completed:we.completed??0,total:we.total??0,running_sessions:we.running_sessions??0,running_discussions:we.running_discussions??0}})),we.type==="todo:status-changed"&&ct(),we.type==="memory:ingest-finished"){const X=o.find(Ze=>Ze.id===we.projectId),ne=(X==null?void 0:X.name)??"",Se=we.sourceTitle?`“${we.sourceTitle}”`:we.sourceType??"",fe=ne?`[${ne}] `:"";if(we.error){Z(`${fe}${B("wiki.ingest.toast.failed")}: ${we.error}`,6e3);return}const ie=we.created??0,ke=we.updated??0,_e=we.edgesAdded??0;if(ie+ke+_e>0){const Ze=B("wiki.ingest.toast.success").replace("{source}",Se).replace("{created}",String(ie)).replace("{updated}",String(ke)).replace("{edges}",String(_e));Q(`${fe}${Ze}`)}else(Pe=we.skipped)!=null&&Pe.parseFailed?oe(`${fe}${B("wiki.ingest.toast.parseFailed").replace("{source}",Se)}`,5e3):W(`${fe}${B("wiki.ingest.toast.empty").replace("{source}",Se)}`,4e3)}}),[a,o,B,Z,W,Q,oe]),y.useEffect(()=>{ct()},[]);function ct(){C1({hours:24}).then(we=>g(we.total_todos)).catch(()=>{})}function tt(){Yu().then(we=>{l(we),we.forEach(Pe=>{g1(Pe.id).then(X=>{p(ne=>({...ne,[Pe.id]:X}))}).catch(()=>{})})}).catch(()=>{})}const Ke=()=>{u==null||u()},Le=async(we,Pe)=>{await m1({name:we,path:Pe}),C(!1),window.dispatchEvent(new Event("projects:changed"))},$e=y.useCallback(async(we,Pe)=>{const X=o.map(Ze=>Ze.id),ne=X.indexOf(we);if(ne<0)return;const Se=X.filter(Ze=>Ze!==we),fe=Pe>ne?Pe-1:Pe;if(fe===ne)return;const ie=[...Se.slice(0,fe),we,...Se.slice(fe)],ke=o,_e=new Map(o.map(Ze=>[Ze.id,Ze])),st=ie.map(Ze=>_e.get(Ze)).filter(Boolean);l(st);try{await s4(ie)}catch(Ze){l(ke),Z(Ze instanceof Error?Ze.message:"Failed to reorder projects")}},[o,Z]),Ie=y.useRef(!1),it=y.useCallback((we,Pe)=>{if(Pe.button!==0||Pe.target.closest("button"))return;Pe.preventDefault();const ne=Pe.clientX,Se=Pe.clientY,fe=6;let ie=!1,ke=null;const _e=ce=>{const ee=document.querySelectorAll("[data-workspace-item]");if(ee.length===0)return null;const Ne=ee[0].getBoundingClientRect();if(ce<Ne.top)return 0;const je=ee[ee.length-1].getBoundingClientRect();if(ce>je.bottom)return ee.length;for(let Me=0;Me<ee.length;Me++){const Te=ee[Me].getBoundingClientRect();if(ce>=Te.top&&ce<=Te.bottom){const et=Te.top+Te.height/2;return ce<et?Me:Me+1}}return null},st=ce=>{if(!ie){if(Math.hypot(ce.clientX-ne,ce.clientY-Se)<fe)return;ie=!0,U(we)}const ee=_e(ce.clientY);ee!==ke&&(ke=ee,q(ee))},Ze=()=>{window.removeEventListener("mousemove",st),window.removeEventListener("mouseup",he),window.removeEventListener("keydown",de)},he=()=>{if(Ze(),!ie)return;Ie.current=!0,requestAnimationFrame(()=>{Ie.current=!1});const ce=ke;U(null),q(null),ce!==null&&$e(we,ce)},de=ce=>{ce.key==="Escape"&&(Ze(),U(null),q(null),ie&&(Ie.current=!0,requestAnimationFrame(()=>{Ie.current=!1})))};window.addEventListener("mousemove",st),window.addEventListener("mouseup",he),window.addEventListener("keydown",de)},[$e]),vt=async(we,Pe)=>{if(Pe.preventDefault(),Pe.stopPropagation(),!!await le({message:B("projects.deleteConfirm"),danger:!0}))try{await p1(we),l(X=>X.filter(ne=>ne.id!==we)),window.dispatchEvent(new Event("projects:changed")),ge===String(we)&&K("/")}catch(X){Z(fl(X,B("errors.projectDelete")))}},Ce=we=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...we==="above"?{top:-1}:{bottom:-1}}});if(f){const we=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 bg-theme-bg-secondary border-none py-3",children:[t.jsx(En,{onClick:m,label:B("sidebar.expand"),size:"lg",children:t.jsx(f1,{size:16})}),we,t.jsx(Kn,{to:"/",onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:B("sidebar.home"),children:t.jsx(nb,{size:16})}),t.jsxs(Kn,{to:"/review",onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:B("sidebar.review"),children:[t.jsx(ju,{size:16}),d!==null&&d>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(Kn,{to:"/agenda",onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:B("sidebar.agenda"),children:t.jsx(dm,{size:16})}),we,t.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(Pe=>{const X=h[Pe.id],ne=ge===String(Pe.id),Se=X?X.running+X.running_sessions+X.running_discussions:0,fe=Se>0,ie=Qa(Pe);return t.jsxs(Kn,{to:`/projects/${Pe.id}`,onClick:Ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:ne?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:fe?`${Pe.name} · ${Se} ${B("detail.live")}`:Pe.name,children:[ne&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ie}}),t.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${fe?"workspace-dot-pulse":""}`,style:{backgroundColor:ie,opacity:ne||fe?1:.55}})]},Pe.id)})}),we,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(En,{onClick:Y,label:B(I==="light"?"theme.dark":"theme.light"),size:"lg",children:I==="light"?t.jsx(rb,{size:16}):t.jsx(ab,{size:16})}),t.jsx(En,{onClick:()=>N(!0),label:B("settings.title"),size:"lg",children:t.jsx(Nu,{size:16})}),t.jsx(bb,{open:D,onClose:()=>N(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:we=>we.preventDefault(),children:[t.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[t.jsxs(Kn,{to:"/",onClick:Ke,className:"block font-mono text-[22px] leading-none whitespace-nowrap select-none",children:[t.jsxs("span",{className:"font-medium text-accent/50",children:[">","_ "]}),t.jsx("span",{className:"font-bold text-accent",children:"CLI"}),t.jsx("span",{className:"font-medium text-theme-text",children:"Trigger"})]}),t.jsx(En,{onClick:m,label:B("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(h1,{size:16})})]}),t.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[t.jsxs(Kn,{to:"/",onClick:Ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/"?"font-medium":""}`,style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.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(nb,{size:16}),B("sidebar.home")]}),t.jsxs(Kn,{to:"/review",onClick:Ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/review"?"font-medium":""}`,style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.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(ju,{size:16}),t.jsx("span",{className:"flex-1",children:B("sidebar.review")}),d!==null&&d>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:d})]}),t.jsxs(Kn,{to:"/agenda",onClick:Ke,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/agenda"?"font-medium":""}`,style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.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(dm,{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(En,{onClick:()=>C(!0),label:B("projects.new"),size:"sm",children:t.jsx(wn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((we,Pe)=>{const X=h[we.id],ne=ge===String(we.id),Se=X?X.running+X.running_sessions+X.running_discussions:0,fe=Se>0,ie=Qa(we),ke=H===we.id,_e=H!==null&&F===Pe,st=H!==null&&Pe===o.length-1&&F===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[_e&&Ce("above"),t.jsxs(Kn,{to:`/projects/${we.id}`,draggable:!1,onDragStart:Ze=>Ze.preventDefault(),onClick:Ze=>{if(Ie.current){Ze.preventDefault();return}Ke()},onMouseDown:Ze=>it(we.id,Ze),onContextMenu:Ze=>{Ze.preventDefault(),x({project:we,x:Ze.clientX,y:Ze.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 ${ne?"font-medium":""} ${ke?"opacity-50":""}`,style:ne?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:H?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:H?"grabbing":"pointer",userSelect:"none"},children:[ne&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ie}}),t.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${fe?"workspace-dot-pulse":""}`,style:{backgroundColor:ie,opacity:ne||fe?1:.55},title:fe?`${B("sidebar.workspaces")} · ${Se} ${B("detail.live")}`:we.name}),t.jsx("span",{className:"truncate flex-1",children:we.name}),t.jsx(En,{onClick:Ze=>vt(we.id,Ze),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(Jt,{size:12})})]}),st&&Ce("below")]},we.id)})})]}),v&&t.jsx(T1,{onSubmit:(we,Pe)=>Le(we,Pe),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(En,{onClick:()=>{E(null),j(!0)},label:B("favorites.add"),size:"sm",children:t.jsx(wn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:S.map(we=>{const Pe=p3(we.type);return t.jsxs("button",{onClick:()=>De(we.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:we.target,children:[t.jsx(Pe,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:we.name}),t.jsx("span",{onClick:X=>Re(we,X),className:"flex-shrink-0 p-0.5 rounded-md 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(pm,{size:12})}),t.jsx("span",{onClick:X=>be(we.id,X),className:"flex-shrink-0 p-0.5 rounded-md 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(Jt,{size:12})})]},we.id)})})]}),w&&t.jsx(X4,{initial:R??void 0,onSubmit:We,onCancel:()=>{j(!1),E(null)}}),k&&t.jsx(d3,{project:k.project,anchorX:k.x,anchorY:k.y,onPick:async we=>{try{const Pe=await xm(k.project.id,{color:we});l(X=>X.map(ne=>ne.id===Pe.id?{...ne,color:Pe.color}:ne)),window.dispatchEvent(new Event("projects:changed"))}catch(Pe){Z(Pe instanceof Error?Pe.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(bb,{open:D,onClose:()=>N(!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(En,{onClick:Y,label:B(I==="light"?"theme.dark":"theme.light"),children:I==="light"?t.jsx(rb,{size:16}):t.jsx(ab,{size:16})}),t.jsx(En,{onClick:A,label:B("lang.toggle"),className:"text-xs font-medium",children:B("lang.toggle")}),J&&t.jsx(En,{onClick:re,label:"Notification"in window&&Notification.permission==="denied"?B("notification.blocked"):B("notification.toggle"),variant:G?"active":"default",pressed:G,children:G?t.jsx(N5,{size:16}):t.jsx(j5,{size:16})}),t.jsx(En,{onClick:ue,disabled:P,label:B("tunnel.start"),variant:(T==null?void 0:T.status)==="running"?"active":"default",pressed:(T==null?void 0:T.status)==="running",title:(T==null?void 0:T.status)==="running"&&T.url?`${T.url} — ${B("tunnel.urlCopied")}`:B(P?"tunnel.starting":"tunnel.start"),children:t.jsx(o1,{size:16})}),t.jsx(En,{onClick:()=>N(!0),label:B("settings.title"),children:t.jsx(Nu,{size:16})}),s&&t.jsx(En,{onClick:e,label:B("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(ZE,{size:16})})]})})]})}function x3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:u}){const[f,m]=y.useState(!1),{t:o}=xt(),[l,h]=y.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),p=()=>{h(d=>{const g=!d;return localStorage.setItem("sidebarCollapsed",g?"1":"0"),g})};return t.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[t.jsx("aside",{"data-app-sidebar":!0,className:`
613
613
  fixed inset-y-0 left-0 z-40 flex-shrink-0
614
614
  transition-[transform,width] duration-200 ease-in-out
615
615
  md:translate-x-0 md:static md:z-auto
@@ -657,7 +657,7 @@ ${P.message}
657
657
  `)?"":`
658
658
  `;await T8(e,a+m+u+`
659
659
  `)}async function YP(e,s,i){await ht(`/api/projects/${e}/vault/ignore/unhide`,{path:s,isDir:i})}function R8(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(2)}MB`}function M8(e){const s=new Map,i=new Map;for(const u of e){const f=u.stem.toLowerCase(),m=u.title.toLowerCase(),o=s.get(f)??[];o.push(u.relativePath),s.set(f,o);const l=i.get(m)??[];l.push(u.relativePath),i.set(m,l)}const a=new Map;for(const u of e){const f=u.relativePath.includes("/")?u.relativePath.slice(0,u.relativePath.lastIndexOf("/")+1):"",m=[];for(const o of u.wikilinks){const l=o.toLowerCase(),h=s.get(l)??i.get(l)??[];if(h.length===0)continue;const p=h.length===1?h[0]:h.find(d=>d.startsWith(f))??h[0];p&&p!==u.relativePath&&!m.includes(p)&&m.push(p)}a.set(u.relativePath,m)}return a}function Bp({projectId:e,mode:s,selectedPaths:i,includeLinked:a,onChange:u}){const{t:f}=xt(),[m,o]=y.useState([]),[l,h]=y.useState(!1),[p,d]=y.useState(!1),[g,v]=y.useState(""),[C,k]=y.useState(!1),[x,S]=y.useState("");y.useEffect(()=>{let D=!1;return N8(e).then(N=>{D||(o(N.files),h(!0))}).catch(N=>{console.error("Load vault files failed",N),h(!0)}),()=>{D=!0}},[e]);const _=y.useMemo(()=>{const D=x.toLowerCase(),N=D?m.filter(z=>z.stem.toLowerCase().includes(D)||z.title.toLowerCase().includes(D)||z.relativePath.toLowerCase().includes(D)):m,T={};for(const z of N){const P=z.relativePath.includes("/")?z.relativePath.split("/").slice(0,-1).join("/"):".";T[P]||(T[P]=[]),T[P].push(z)}return T},[m,x]),w=y.useMemo(()=>M8(m),[m]),j=D=>{const N=new Set(i);if(N.has(D))N.delete(D);else if(N.add(D),a){const T=w.get(D)??[];for(const z of T)N.add(z)}u("selected",Array.from(N),a)},R=async()=>{k(!0);try{const N=await L8(e,s==="auto"?"all":s,i);v(N.block||f("vault.empty"))}catch(D){v(D instanceof Error?D.message:"Preview failed")}finally{k(!1)}},E=s!=="none"&&s!=="auto";return y.useEffect(()=>{p&&E&&R()},[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")}),E&&t.jsxs("button",{type:"button",onClick:()=>d(D=>!D),className:"inline-flex items-center gap-1 text-xs text-warm-600 hover:text-warm-800",children:[p?t.jsx(mE,{size:12}):t.jsx(mm,{size:12}),f("vaultInject.previewToggle")]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:["none","auto","all","selected"].map(D=>t.jsx("button",{type:"button",onClick:()=>u(D,D==="selected"?i:[],a),className:`px-3 py-1.5 rounded-md text-xs ${s===D?"bg-warm-700 text-warm-50":"bg-warm-100 text-warm-700 hover:bg-warm-200"}`,children:f(`vaultInject.mode${D.charAt(0).toUpperCase()+D.slice(1)}`)},D))}),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:l?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:D=>u(s,i,D.target.checked)}),f("vaultInject.includeLinked")]}),t.jsx("input",{value:x,onChange:D=>S(D.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(_).length===0?t.jsx("div",{className:"text-xs text-warm-500 italic px-2 py-2",children:f("vaultInject.noResults")}):Object.entries(_).sort(([D],[N])=>D.localeCompare(N)).map(([D,N])=>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:D}),t.jsx("div",{className:"divide-y divide-warm-100",children:N.map(T=>{const z=(w.get(T.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(T.relativePath),onChange:()=>j(T.relativePath)}),T.kind==="html"?t.jsx(up,{size:12,className:"text-warm-500 shrink-0"}):t.jsx(ll,{size:12,className:"text-warm-500 shrink-0"}),t.jsx("span",{className:"text-sm text-warm-800 truncate flex-1",title:T.relativePath,children:T.title||T.stem}),a&&z>0&&t.jsx("span",{className:"text-[10px] text-warm-600 bg-warm-200 px-1.5 py-0.5 rounded-md shrink-0",title:T.wikilinks.join(", "),children:f("vaultInject.linkedAdded").replace("{n}",String(z))}),t.jsx("span",{className:"text-[10px] text-warm-500 font-mono shrink-0",children:R8(T.size)})]},T.relativePath)})})]},D))}),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&&E&&t.jsxs("div",{className:"mt-3",children:[t.jsx("textarea",{readOnly:!0,value:C?"...":g,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&&g&&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}",g.length.toLocaleString())}),t.jsx("span",{children:f("vaultInject.previewTokens").replace("{n}",Math.ceil(g.length/4).toLocaleString())})]})]})]})}function A8(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}let z8=0;function aS({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCliTool:u,initialDependsOn:f,initialMaxTurns:m,initialUseWorktree:o=null,initialMemoryInjectMode:l="none",initialMemoryRawFilePaths:h=null,projectId:p,projectCliTool:d="claude",projectIsGitRepo:g=!1,projectUseWorktree:v=!0,existingImages:C=[],todoId:k,onDeleteImage:x,availableTodos:S=[]}){const[_,w]=y.useState(i),[j,R]=y.useState(a),[E,D]=y.useState(u||d||"claude"),[N,T]=y.useState(f??""),[z,P]=y.useState((m==null?void 0:m.toString())??""),[O,H]=y.useState(o===1?"force-on":o===0?"force-off":"inherit"),[U,F]=y.useState(l),[q,$]=y.useState(A8(h)),[K,B]=y.useState(!1),[A,I]=y.useState([]),[Y,G]=y.useState(C),J=y.useRef(null),re=y.useRef(null),{t:Z}=xt(),Q=y.useCallback(De=>{const be=Array.from(De).filter(Re=>Re.type.startsWith("image/"));for(const Re of be){const ct=new FileReader;ct.onload=()=>{const tt=ct.result,Ke=`pending-${++z8}`;I(Le=>[...Le,{id:Ke,name:Re.name,data:tt,preview:tt}])},ct.readAsDataURL(Re)}},[]),W=y.useCallback(De=>{var tt;const be=(tt=De.clipboardData)==null?void 0:tt.items;if(!be)return;const Re=[];for(let Ke=0;Ke<be.length;Ke++)be[Ke].type.startsWith("image/")&&Re.push(be[Ke]);if(Re.length===0)return;De.preventDefault();const ct=[];for(const Ke of Re){const Le=Ke.getAsFile();Le&&ct.push(Le)}Q(ct)},[Q]),oe=y.useCallback(De=>{var be;De.preventDefault(),De.stopPropagation(),(be=De.dataTransfer)!=null&&be.files&&Q(De.dataTransfer.files)},[Q]),le=y.useCallback(De=>{De.preventDefault(),De.stopPropagation()},[]),ge=De=>{I(be=>be.filter(Re=>Re.id!==De))},ue=De=>{x&&x(De),G(be=>be.filter(Re=>Re.id!==De))},Ve=De=>{if(De.preventDefault(),!_.trim())return;const be=z?parseInt(z,10):void 0,Re=O==="force-on"?1:O==="force-off"?0:null;e(_.trim(),j.trim(),E,A.length>0?A:void 0,N||void 0,be||void 0,Re,U,[],q)},We=Y.length+A.length;return t.jsxs("form",{onSubmit:Ve,className:"card p-5 border-accent/30",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:Z("todoForm.titlePlaceholder"),value:_,onChange:De=>w(De.target.value),className:"input-field",autoFocus:!0})}),t.jsxs("div",{className:"mb-4",children:[t.jsx("textarea",{ref:J,placeholder:Z("todoForm.descPlaceholder"),value:j,onChange:De=>R(De.target.value),onPaste:W,onDrop:oe,onDragOver:le,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 De;return(De=re.current)==null?void 0:De.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-2xs font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[t.jsx(Xa,{size:14}),Z("todoForm.addImage")]}),t.jsx("span",{className:"text-2xs text-warm-300",children:Z("todoForm.pasteHint")})]}),t.jsx("input",{ref:re,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:De=>{De.target.files&&Q(De.target.files),De.target.value=""}})]}),We>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:Z("todoForm.images")}),t.jsxs("span",{className:"text-2xs text-warm-400",children:["(",We,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[Y.map(De=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:k?Em(k,De.id):"",alt:De.originalName,className:"h-20 w-20 object-cover rounded-lg border border-warm-200"}),t.jsx("button",{type:"button",onClick:()=>ue(De.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(Jt,{size:12})}),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:De.originalName})})]},De.id)),A.map(De=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:De.preview,alt:De.name,className:"h-20 w-20 object-cover rounded-lg border border-accent/30"}),t.jsx("button",{type:"button",onClick:()=>ge(De.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(Jt,{size:12})}),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:De.name})})]},De.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:Z("todoForm.cliTool")}),t.jsx("select",{value:E,onChange:De=>D(De.target.value),className:"input-field text-sm",children:Fs.map(De=>t.jsx("option",{value:De.value,children:De.label},De.value))})]})}),E==="claude"&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:Z("todoForm.maxTurns")}),t.jsx("input",{type:"number",min:"1",max:"500",placeholder:Z("todoForm.maxTurnsPlaceholder"),value:z,onChange:De=>P(De.target.value),className:"input-field text-sm w-32"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:Z("todoForm.maxTurnsHint")})]}),g&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:Z("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:O==="inherit",onChange:()=>H("inherit")}),t.jsxs("span",{children:[Z("todoForm.worktreeInherit"),t.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["(",Z(v?"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:O==="force-on",onChange:()=>H("force-on")}),t.jsx("span",{children:Z("todoForm.worktreeForceOn")})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[t.jsx("input",{type:"radio",name:"useWorktreeMode",checked:O==="force-off",onChange:()=>H("force-off")}),t.jsx("span",{children:Z("todoForm.worktreeForceOff")})]})]}),(O==="force-off"||O==="inherit"&&!v)&&t.jsx("p",{className:"text-2xs text-status-warning mt-1.5",children:Z("todoForm.worktreeMainWarning")})]}),S.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:Z("todoForm.dependsOn")}),t.jsxs("select",{value:N,onChange:De=>T(De.target.value),className:"input-field text-sm",children:[t.jsx("option",{value:"",children:Z("todoForm.noDependency")}),S.map(De=>t.jsxs("option",{value:De.id,children:[De.title," (",Z(`status.${De.status}`),")"]},De.id))]}),N&&t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:Z("todoForm.dependsOnHint")})]}),p&&t.jsx("div",{className:"mb-4",children:t.jsx(Bp,{projectId:p,mode:U,selectedPaths:q,includeLinked:K,onChange:(De,be,Re)=>{F(De),$(be),B(Re)}})}),t.jsxs("div",{className:"flex gap-3 justify-end",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:Z("todoForm.cancel")}),t.jsx("button",{type:"submit",disabled:!_.trim(),className:"btn-primary text-sm",children:Z("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",Pp="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 oS(){return t.jsx("div",{className:"my-1 border-t border-warm-200"})}function yi(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 Gs({x:e,y:s,onClose:i,children:a}){const u=y.useRef(null),[f,m]=y.useState({top:s,left:e,visible:!1});return y.useLayoutEffect(()=>{const o=u.current;if(!o)return;const l=window.innerWidth,h=window.innerHeight;let p=e,d=s;p+o.offsetWidth>l-8&&(p=Math.max(8,l-8-o.offsetWidth)),d+o.offsetHeight>h-8&&(d=Math.max(8,h-8-o.offsetHeight)),p<8&&(p=8),d<8&&(d=8),m({top:d,left:p,visible:!0})},[e,s]),y.useEffect(()=>{const o=p=>{var d;(d=u.current)!=null&&d.contains(p.target)||i()},l=p=>{p.key==="Escape"&&i()},h=()=>i();return document.addEventListener("mousedown",o),document.addEventListener("keydown",l),window.addEventListener("scroll",h,!0),window.addEventListener("resize",i),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",l),window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",i)}},[i]),cn.createPortal(t.jsx("div",{ref:u,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 O8({children:e}){const[s,i]=y.useState(!1),[a,u]=y.useState(!1),f=y.useRef(null),m=y.useRef(null),[o,l]=y.useState({top:0,left:0}),h=y.useCallback(()=>{if(!f.current)return;const d=f.current.getBoundingClientRect(),g=window.innerWidth,v=window.innerHeight;let C=d.bottom+4;const k=m.current;if(k){const x=k.offsetWidth,S=k.offsetHeight;let _=d.right-x;_<8&&(_=8),_+x>g-8&&(_=g-8-x),C+S>v-8&&(C=d.top-S-4),l({top:C,left:_}),u(!0)}else l({top:C,left:Math.max(8,d.right-180)})},[]);y.useEffect(()=>{if(!s){u(!1);return}h();const d=requestAnimationFrame(h),g=v=>{var k,x;const C=v.target;(k=f.current)!=null&&k.contains(C)||(x=m.current)!=null&&x.contains(C)||i(!1)};return document.addEventListener("mousedown",g),window.addEventListener("scroll",h,!0),window.addEventListener("resize",h),()=>{cancelAnimationFrame(d),document.removeEventListener("mousedown",g),window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h)}},[s,h]);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(cp,{size:14})}),s&&cn.createPortal(t.jsx("div",{ref:m,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",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 B8({todo:e,allTodos:s=[],projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:f,onStop:m,onDelete:o,onEdit:l,onMerge:h,onCleanup:p,onRetry:d,onContinue:g,onFix:v,onSchedule:C,onScheduleOnReset:k,resetsAt:x,onEvent:S,isInteractive:_,onSendInput:w,isDragSource:j,isDragging:R,isDragOver:E,isValidDropTarget:D,onDragStart:N,onDragEnd:T,onDragOverTarget:z,onDragLeaveTarget:P,onDropTarget:O,onRemoveDependency:H,debugLogging:U,showTokenUsage:F,isChainMember:q}){const[$,K]=y.useState(!1),[B,A]=y.useState(!1),[I,Y]=y.useState([]),[G,J]=y.useState(!1),[re,Z]=y.useState(!1),[Q,W]=y.useState(null),[oe,le]=y.useState(!1),[ge,ue]=y.useState(null),[Ve,We]=y.useState(!1),[De,be]=y.useState(null),[Re,ct]=y.useState(!1),[tt,Ke]=y.useState(null),[Le,$e]=y.useState(!1),[Ie,it]=y.useState(null),[vt,Ce]=y.useState(!1),[Ue,we]=y.useState(""),[Pe,X]=y.useState(!1),[ne,Se]=y.useState(null),[fe,ie]=y.useState(!1),[ke,_e]=y.useState(""),[st,Ze]=y.useState(!1),[he,de]=y.useState(null),[ce,ee]=y.useState(null),[Ne,je]=y.useState(!1),[Me,Te]=y.useState(!1),[et,Ye]=y.useState(!1),[mt,bt]=y.useState(()=>{const pe=new Date;pe.setHours(pe.getHours()+1),pe.setMinutes(0,0,0);const Be=pe.getFullYear(),dt=String(pe.getMonth()+1).padStart(2,"0"),kt=String(pe.getDate()).padStart(2,"0"),Ut=String(pe.getHours()).padStart(2,"0"),zs=String(pe.getMinutes()).padStart(2,"0");return`${Be}-${dt}-${kt}T${Ut}:${zs}`}),[yt,Et]=y.useState(!1),[Xe,lt]=y.useState(null),{t:Oe}=xt(),{confirm:ae}=Yn(),ve=e.status==="pending"||e.status==="failed"||e.status==="stopped",ye=(e.status==="pending"||e.status==="failed"||e.status==="stopped")&&!!C,me=(e.status==="pending"||e.status==="completed"||e.status==="failed"||e.status==="stopped")&&!!k&&!!x&&x>Math.floor(Date.now()/1e3),nt=e.status==="running",pt=e.status==="completed"||e.status==="stopped"||e.status==="merged",jt=e.status==="completed"&&!q&&!!e.branch_name,Bt=e.status==="completed"||e.status==="failed"||e.status==="stopped",ze=!!g&&e.status==="completed"&&!!e.worktree_path,ut=e.status!=="running"&&e.status!=="pending"&&!!e.worktree_path&&!q,_t=e.status==="completed"||e.status==="failed"||e.status==="stopped"||e.status==="merged";y.useEffect(()=>{_&&e.status==="running"&&!$&&K(!0)},[_,e.status]),y.useEffect(()=>{$&&!G&&O1(e.id).then(pe=>{Y(pe),J(!0)}).catch(()=>{})},[$,G,e.id]),y.useEffect(()=>{$&&_t&&!Ne&&k3(e.id).then(pe=>{ee(pe),je(!0)}).catch(()=>{je(!0)})},[$,_t,Ne,e.id]),y.useEffect(()=>S(pe=>{if(pe.type==="todo:log"&&pe.todoId===e.id&&pe.message){const Be={id:`ws-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:pe.logType||"output",message:pe.message,created_at:new Date().toISOString()};Y(dt=>[...dt,Be])}if(pe.type==="todo:commit"&&pe.todoId===e.id&&pe.message){const Be={id:`ws-commit-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:"commit",message:`${pe.commitHash?`[${pe.commitHash}] `:""}${pe.message}`,created_at:new Date().toISOString()};Y(dt=>[...dt,Be])}}),[S,e.id]);const Mt=async()=>{try{const{files:pe}=await n4(e.project_id,e.id);pe.length>0&&window.open(`/api/projects/${e.project_id}/debug-logs/${encodeURIComponent(pe[0].name)}`,"_blank")}catch{}},At=async()=>{if(re){Z(!1);return}le(!0),ue(null);try{const pe=await S3(e.id);W(pe),Z(!0),K(!0)}catch(pe){ue(pe instanceof Error?pe.message:"Failed to load diff"),K(!0)}finally{le(!1)}},_n=async()=>{We(!0),be(null);try{await h(e.id)}catch(pe){be(pe instanceof Error?pe.message:"Merge failed")}finally{We(!1)}},kn=async()=>{const pe=e.branch_name?await ae({message:Oe("cleanup.confirmDeleteBranch").replace("{name}",e.branch_name),danger:!0}):!1;ct(!0),Ke(null);try{await p(e.id,pe)}catch(Be){Ke(Be instanceof Error?Be.message:"Cleanup failed")}finally{ct(!1)}},un=async(pe="headless")=>{$e(!0),it(null),Y([]),J(!1),W(null),Z(!1),ee(null),je(!1);try{await d(e.id,pe)}catch(Be){it(Be instanceof Error?Be.message:"Retry failed")}finally{$e(!1)}},rn=async(pe="headless")=>{if(!g)return;const Be=Ue.trim();if(!Be){Se(Oe("todo.continuePromptRequired"));return}X(!0),Se(null);try{await g(e.id,Be,pe),Ce(!1),we(""),Y([]),J(!1)}catch(dt){Se(dt instanceof Error?dt.message:"Continue failed")}finally{X(!1)}},us=async()=>{if(!(!k||!ke.trim())){Ze(!0),de(null);try{await k(e.id,ke.trim()),ie(!1),_e("")}catch(pe){de(pe instanceof Error?pe.message:"Failed")}finally{Ze(!1)}}},cr=async()=>{if(!(!C||!mt)){Et(!0);try{await C(e.id,new Date(mt).toISOString(),et),Te(!1)}catch{}finally{Et(!1)}}},In=pe=>{if(pe<60)return`${pe}s`;const Be=Math.floor(pe/60),dt=pe%60;if(Be<60)return dt>0?`${Be}m ${dt}s`:`${Be}m`;const kt=Math.floor(Be/60),Ut=Be%60;return Ut>0?`${kt}h ${Ut}m`:`${kt}h`},Ms=pe=>pe>=1e6?`${(pe/1e6).toFixed(1)}M`:pe>=1e3?`${(pe/1e3).toFixed(1)}k`:String(pe),Vs=e.images?JSON.parse(e.images):[],ds=e.depends_on?s.find(pe=>pe.id===e.depends_on):null,As=s.find(pe=>pe.depends_on===e.id&&pe.merged_from_branch),ta=e.cli_tool||i||"claude",Ys=Dm(ta).supportsInteractive;if(B)return t.jsx(aS,{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:u,existingImages:Vs,todoId:e.id,availableTodos:s.filter(pe=>pe.id!==e.id),onDeleteImage:async pe=>{await E3(e.id,pe)},onSave:async(pe,Be,dt,kt,Ut,zs,zr,zl,Ol,Or)=>{await l(e.id,pe,Be,dt,Ut,zs,zr,zl,Ol,Or),kt&&kt.length>0&&await F1(e.id,kt.map(Bl=>({name:Bl.name,data:Bl.data}))),A(!1)},onCancel:()=>A(!1)});const ur=pe=>{pe.dataTransfer.setData("text/plain",e.id),pe.dataTransfer.effectAllowed="link",N==null||N(e.id)},Xn=()=>{T==null||T()},Tn=pe=>{!R||j||(pe.preventDefault(),pe.dataTransfer.dropEffect=D?"link":"none",z==null||z(e.id))},na=()=>{P==null||P(e.id)},sa=pe=>{pe.preventDefault(),!(!R||j||!D)&&(O==null||O(e.id))},se=R&&!j&&E&&D,Je=R&&!j&&E&&!D;return t.jsxs("div",{className:`relative transition-opacity duration-200 ${j?"opacity-40":""}`,onDragOver:Tn,onDragLeave:na,onDrop:sa,onContextMenu:pe=>{yi(pe)||(pe.preventDefault(),pe.stopPropagation(),lt({x:pe.clientX,y:pe.clientY}))},children:[t.jsxs("div",{className:`card overflow-hidden transition-all duration-200 ${se?"ring-2 ring-accent/50 ring-offset-1":""} ${Je?"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:()=>K(!$),children:[t.jsx("div",{draggable:!0,onDragStart:ur,onDragEnd:Xn,onClick:pe=>pe.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:Oe("dnd.dropHint"),children:t.jsx(d1,{size:16})}),t.jsx("button",{className:"text-warm-400 hover:text-accent flex-shrink-0 transition-colors",children:t.jsx(ws,{size:14,className:`transition-transform duration-200 ${$?"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}),Vs.length>0&&t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-2xs font-mono text-warm-400 flex-shrink-0",children:[t.jsx(Xa,{size:12}),Vs.length]}),ds&&t.jsxs("span",{className:"hidden md:inline-flex items-center gap-1 text-2xs font-mono text-warm-400 flex-shrink-0 group/dep",title:`${Oe("todo.dependsOn")}: ${ds.title}`,children:[t.jsx(yl,{size:12}),ds.title.length>20?ds.title.slice(0,20)+"...":ds.title,H&&t.jsx("button",{onClick:pe=>{pe.stopPropagation(),H(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:Oe("dnd.removeDep"),children:t.jsx(Jt,{size:12})})]}),e.cli_tool&&t.jsx("span",{className:"hidden md:inline-flex items-center gap-1 text-2xs font-mono text-warm-400 flex-shrink-0",children:Dm(e.cli_tool||"claude").label}),t.jsx(tD,{status:e.status}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto md:ml-2 flex-shrink-0",onClick:pe=>pe.stopPropagation(),children:[ve&&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:Oe("todo.startHeadless"),children:t.jsx(Mr,{size:14})}),nt&&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:Oe("todo.stop"),children:t.jsx(Yi,{size:14})}),jt&&t.jsx("button",{onClick:_n,disabled:Ve,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Oe("todo.merge"),children:t.jsx(Cu,{size:14})}),ze&&t.jsx("button",{onClick:()=>{Ce(pe=>!pe),Se(null)},disabled:Pe,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Oe("todo.continue"),children:t.jsx(eb,{size:14})}),Bt&&t.jsx("button",{onClick:()=>un("headless"),disabled:Le,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Oe("todo.retry"),children:t.jsx(vi,{size:14})}),t.jsxs(O8,{children:[ve&&Ys&&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:Oe("todo.startInteractiveDesc"),children:[t.jsx(bi,{size:14}),Oe("todo.startInteractive")]}),ve&&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:Oe("todo.startVerboseDesc"),children:[t.jsx(mm,{size:14}),Oe("todo.startVerbose")]}),ye&&t.jsxs("button",{onClick:()=>Te(!Me),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left",title:Oe("todo.scheduleDesc"),children:[t.jsx(hm,{size:14}),Oe("todo.schedule")]}),me&&t.jsxs("button",{onClick:()=>{ie(pe=>!pe),de(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:Oe("todo.scheduleOnResetDesc"),children:[t.jsx(Vi,{size:14}),Oe("todo.scheduleOnReset")]}),pt&&t.jsxs("button",{onClick:At,disabled:oe,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left disabled:opacity-30",children:[t.jsx(ll,{size:14}),Oe("todo.viewDiff")]}),U&&_t&&t.jsxs("button",{onClick:Mt,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(ib,{size:14}),Oe("todo.viewDebugLog")]}),ut&&t.jsxs("button",{onClick:kn,disabled:Re,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-warm-600 hover:bg-theme-hover rounded-md transition-colors text-left disabled:opacity-30",children:[t.jsx(ku,{size:14}),Oe("todo.cleanup")]}),t.jsxs("button",{onClick:()=>A(!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(xi,{size:14}),Oe("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(Pn,{size:14}),Oe("todo.delete")]})]})]})]}),Me&&t.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-theme-text-secondary",children:Oe("todo.scheduleAt")}),t.jsx("input",{type:"datetime-local",value:mt,onChange:pe=>bt(pe.target.value),className:"bg-theme-card border border-theme-border-strong rounded-lg px-2 py-1.5 text-sm font-mono text-warm-800 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20",min:new Date().toISOString().slice(0,16)}),t.jsx("button",{onClick:cr,disabled:yt||!mt,className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Oe(yt?"todo.scheduling":"todo.confirmSchedule")}),t.jsx("button",{onClick:()=>Te(!1),className:"btn-ghost text-xs py-1.5",children:Oe("scheduleForm.cancel")}),t.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-500",children:[t.jsx("input",{type:"checkbox",checked:et,onChange:pe=>Ye(pe.target.checked),className:"rounded-md border-accent/40 text-accent focus:ring-accent"}),Oe("todo.scheduleKeepOriginal")]})]})}),vt&&t.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50",children:t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxs("label",{className:"text-xs font-medium text-theme-text-secondary",children:[Oe("todo.continuePromptLabel"),(e.round_count??1)>1&&t.jsxs("span",{className:"ml-2 text-theme-muted",children:["(",Oe("todo.roundLabel")," ",e.round_count,")"]})]}),t.jsx("textarea",{value:Ue,onChange:pe=>we(pe.target.value),placeholder:Oe("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:Pe}),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:()=>rn("headless"),disabled:Pe||!Ue.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Oe(Pe?"todo.continuing":"todo.confirmContinue")}),t.jsx("button",{onClick:()=>{Ce(!1),Se(null)},disabled:Pe,className:"btn-ghost text-xs py-1.5",children:Oe("scheduleForm.cancel")})]})]})}),fe&&x&&t.jsx("div",{className:"border-t border-theme-border px-5 py-3 bg-theme-bg-secondary/50",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-theme-text-secondary",children:Oe("todo.scheduleOnResetLabel")}),t.jsx("span",{className:"text-xs text-warm-400 font-mono",children:new Date(x*1e3).toLocaleString()})]}),t.jsx("textarea",{value:ke,onChange:pe=>_e(pe.target.value),placeholder:Oe("todo.resetPromptPlaceholder"),rows:3,className:"w-full bg-theme-card border border-theme-border-strong rounded-lg px-3 py-2 text-sm text-warm-800 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20 resize-y",disabled:st}),he&&t.jsx("p",{className:"text-xs text-status-error",children:he}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:us,disabled:st||!ke.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Oe(st?"todo.scheduling":"todo.confirmResetSchedule")}),t.jsx("button",{onClick:()=>{ie(!1),de(null)},disabled:st,className:"btn-ghost text-xs py-1.5",children:Oe("scheduleForm.cancel")})]})]})}),$&&t.jsx("div",{className:"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:"section-label mb-1.5",children:Oe("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:Oe("todo.noDescription")})})]}),Vs.length>0&&t.jsxs("section",{children:[t.jsxs("h4",{className:"section-label mb-1.5",children:[Oe("todo.attachedImages")," ",t.jsxs("span",{className:"text-warm-400 normal-case",children:["(",Vs.length,")"]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Vs.map(pe=>t.jsx("a",{href:Em(e.id,pe.id),target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{src:Em(e.id,pe.id),alt:pe.originalName,className:"h-16 w-16 object-cover rounded-md border border-theme-border"})},pe.id))})]}),(ds||e.branch_name||As)&&t.jsxs("section",{children:[t.jsx("h4",{className:"section-label mb-1.5",children:Oe("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:[ds&&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:Oe("todo.dependsOn")}),t.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-md bg-accent/10 text-accent text-2xs font-medium",children:ds.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:Oe("todo.branch")}),t.jsx(Qi,{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:Oe("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:Oe("todo.mergedFrom")}),t.jsx("code",{className:"font-mono text-xs text-theme-text-secondary break-all",children:e.merged_from_branch})]}),!e.worktree_path&&As&&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:Oe("todo.transferredTo")}),t.jsx("span",{className:"text-warm-700 truncate",children:As.title.length>30?As.title.slice(0,27)+"...":As.title})]})]})]}),e.status==="failed"&&I.length>0&&(()=>{var kt;const pe=I.filter(Ut=>Ut.log_type==="error");if(pe.length===0)return null;const Be=pe.find(Ut=>/exited with code (\d+)/.test(Ut.message)),dt=Be?(kt=Be.message.match(/exited with code (\d+)/))==null?void 0:kt[1]:null;return t.jsxs("div",{style:{background:Ge.bg,fontFamily:Ht,fontSize:12,lineHeight:"1.5",padding:"10px 12px",borderRadius:8,border:`1px solid ${Ge.separator}`,color:Ge.text},children:[t.jsxs("div",{children:[t.jsx("span",{style:{color:Ge.error},children:">"})," ",t.jsx("span",{style:{color:Ge.error,fontWeight:700},children:"FAILED"}),dt&&t.jsxs("span",{style:{color:Ge.dim},children:[" (exit code: ",dt,")"]}),v&&t.jsx("button",{onClick:()=>v(e,pe),style:{marginLeft:12,color:Ge.warning,background:"none",border:`1px solid ${Ge.warning}`,padding:"1px 8px",borderRadius:2,cursor:"pointer",fontSize:11,fontFamily:Ht},children:Oe("failure.fix")})]}),t.jsx("div",{style:{maxHeight:192,overflowY:"auto",marginTop:4},children:pe.map(Ut=>t.jsxs("div",{children:[t.jsx("span",{style:{color:Ge.dim},children:new Date(Ut.created_at).toLocaleTimeString()})," ",t.jsx("span",{style:{color:Ge.error},children:Ut.message})]},Ut.id))})]})})(),_t&&ce&&t.jsxs("section",{children:[t.jsx("h4",{className:"section-label mb-1.5",children:Oe("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:[ce.duration_seconds!==null&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(Vi,{size:12,className:"text-warm-400"}),t.jsx("span",{className:"text-warm-400",children:Oe("result.duration")}),t.jsx("span",{className:"text-warm-700 font-medium",children:In(ce.duration_seconds)})]}),ce.commits.length>0&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(EE,{size:12,className:"text-status-success"}),t.jsx("span",{className:"text-status-success font-medium",children:ce.commits.length}),t.jsx("span",{className:"text-warm-400",children:Oe("result.commits")})]}),ce.diff_stats.files_changed>0&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(ll,{size:12,className:"text-warm-400"}),t.jsx("span",{className:"text-warm-700 font-medium",children:ce.diff_stats.files_changed}),t.jsx("span",{className:"text-warm-400",children:Oe("result.filesChanged")}),t.jsxs("span",{className:"text-status-success font-mono",children:["+",ce.diff_stats.insertions]}),t.jsxs("span",{className:"text-status-error font-mono",children:["-",ce.diff_stats.deletions]})]}),F&&ce.token_usage&&(()=>{const pe=ce.token_usage,Be=(pe.input_tokens??0)+(pe.cache_read_input_tokens??0)+(pe.cache_creation_input_tokens??0),dt=Be+(pe.output_tokens??0);let kt,Ut;return dt>=5e5?(kt=Oe("result.levelHeavy"),Ut="text-status-error"):dt>=3e5?(kt=Oe("result.levelHigh"),Ut="text-status-warning"):dt>=1e5?(kt=Oe("result.levelModerate"),Ut="text-status-warning"):(kt=Oe("result.levelLight"),Ut="text-status-info"),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[Be>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:Oe("result.inputTokens")}),t.jsx("span",{className:"text-warm-700 font-medium",children:Ms(Be)})]}),Be>0&&pe.output_tokens!==null&&t.jsx("span",{className:"text-warm-400",children:"·"}),pe.output_tokens!==null&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:Oe("result.outputTokens")}),t.jsx("span",{className:"text-warm-700 font-medium",children:Ms(pe.output_tokens)})]}),pe.num_turns!=null&&pe.num_turns>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:"·"}),t.jsxs("span",{className:"text-warm-700",children:[pe.num_turns,Oe("result.turns")]})]}),t.jsx("span",{className:"text-warm-400",children:"·"}),t.jsx("span",{className:`font-medium ${Ut}`,children:kt})]})})()]}),ce.commits.length>0&&t.jsxs("div",{children:[t.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider mb-1",children:Oe("result.commitHistory")}),t.jsx("div",{className:"space-y-0.5",children:ce.commits.map((pe,Be)=>t.jsxs("div",{className:"flex items-center gap-2 px-1.5 py-1 text-xs rounded-md hover:bg-theme-hover",children:[t.jsx("code",{className:"font-mono text-accent flex-shrink-0",children:pe.hash.slice(0,7)||"-------"}),t.jsx("span",{className:"text-warm-700 truncate flex-1",children:pe.message}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:new Date(pe.date).toLocaleTimeString()})]},Be))})]}),ce.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:Oe("result.changedFiles")}),pt&&t.jsxs("button",{onClick:At,disabled:oe,className:"flex items-center gap-1 text-2xs text-warm-500 hover:text-accent transition-colors disabled:opacity-30",children:[t.jsx(ws,{size:12,className:`transition-transform ${re?"rotate-90":""}`}),t.jsx("span",{children:Oe(re?"todo.hideDiff":"todo.viewDiff")})]})]}),t.jsx("div",{className:"space-y-0.5",children:ce.changed_files.map((pe,Be)=>{const dt=pe.status==="A"?"bg-status-success/15 text-status-success":pe.status==="D"?"bg-status-error/15 text-status-error":pe.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-md text-[10px] font-bold ${dt}`,children:pe.status}),t.jsx("span",{className:"text-warm-700 font-mono text-2xs break-all flex-1",children:pe.file}),pe.renamedFrom&&t.jsxs("span",{className:"text-warm-400 text-2xs flex-shrink-0",children:["← ",pe.renamedFrom]})]},Be)})})]})]})]}),De&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Oe("todo.mergeFailed"),": ",De]}),tt&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Oe("todo.cleanupFailed"),": ",tt]}),Ie&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Oe("todo.retryFailed"),": ",Ie]}),ge&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Oe("todo.diffError"),": ",ge]}),re&&Q&&t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[t.jsx("h4",{className:"section-label",children:Oe("todo.diffOutput")}),t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs",children:[t.jsxs("span",{className:"text-warm-500",children:[Q.stats.files_changed," ",Oe("todo.files")]}),t.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-md bg-status-success/10 text-status-success font-mono",children:["+",Q.stats.insertions]}),t.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-md bg-status-error/10 text-status-error font-mono",children:["-",Q.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:Q.diff?Q.diff.split(`
660
- `).map((pe,Be)=>{let dt="text-theme-text",kt="";return pe.startsWith("+")&&!pe.startsWith("+++")?dt="text-theme-text bg-status-success/15":pe.startsWith("-")&&!pe.startsWith("---")?dt="text-theme-text bg-status-error/15":pe.startsWith("@@")?dt="text-accent":pe.startsWith("diff ")&&(dt="text-warm-700",kt="font-semibold"),t.jsx("div",{className:`whitespace-pre ${dt} ${kt}`,children:pe},Be)}):t.jsx("span",{className:"text-warm-400 italic",children:Oe("log.noChanges")})})]}),t.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:Ge.bg,fontFamily:Ht,border:`1px solid ${Ge.separator}`},children:[t.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${Ge.separator}`,fontSize:12,color:Ge.text},children:[t.jsx("span",{style:{color:Ge.prompt},children:"$"})," ",t.jsx("span",{style:{color:Ge.bright},children:"tail"})," ",t.jsx("span",{style:{color:Ge.dim},children:"-f task.log"})]}),t.jsx(iS,{logs:I,interactive:_&&e.status==="running",todoId:e.id,onSendInput:w,embedded:!0})]})]})})]}),se&&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",children:[t.jsx(yl,{size:14,className:"text-accent flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-accent",children:Oe("dnd.dropHint")})]}),Je&&t.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-warm-300 bg-status-error/10",children:[t.jsx(k5,{size:14,className:"text-status-error flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-status-error",children:Oe("dnd.cyclicWarning")})]}),Xe&&t.jsxs(Gs,{x:Xe.x,y:Xe.y,onClose:()=>lt(null),children:[ve&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:sn,title:Oe("todo.startHeadless"),children:[t.jsx(Mr,{size:14}),Oe("todo.start")]}),ve&&Ys&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:sn,title:Oe("todo.startInteractiveDesc"),children:[t.jsx(bi,{size:14}),Oe("todo.startInteractive")]}),ve&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:sn,title:Oe("todo.startVerboseDesc"),children:[t.jsx(mm,{size:14}),Oe("todo.startVerbose")]}),nt&&t.jsxs("button",{onClick:()=>m(e.id),className:sn,children:[t.jsx(Yi,{size:14}),Oe("todo.stop")]}),jt&&t.jsxs("button",{onClick:_n,disabled:Ve,className:sn,children:[t.jsx(Cu,{size:14}),Oe("todo.merge")]}),ze&&t.jsxs("button",{onClick:()=>{Ce(!0),Se(null)},disabled:Pe,className:sn,children:[t.jsx(eb,{size:14}),Oe("todo.continue")]}),Bt&&t.jsxs("button",{onClick:()=>un("headless"),disabled:Le,className:sn,children:[t.jsx(vi,{size:14}),Oe("todo.retry")]}),ye&&t.jsxs("button",{onClick:()=>Te(!0),className:sn,title:Oe("todo.scheduleDesc"),children:[t.jsx(hm,{size:14}),Oe("todo.schedule")]}),me&&t.jsxs("button",{onClick:()=>{ie(!0),de(null)},className:sn,title:Oe("todo.scheduleOnResetDesc"),children:[t.jsx(Vi,{size:14}),Oe("todo.scheduleOnReset")]}),pt&&t.jsxs("button",{onClick:At,disabled:oe,className:sn,children:[t.jsx(ll,{size:14}),Oe("todo.viewDiff")]}),U&&_t&&t.jsxs("button",{onClick:Mt,className:sn,children:[t.jsx(ib,{size:14}),Oe("todo.viewDebugLog")]}),ut&&t.jsxs("button",{onClick:kn,disabled:Re,className:sn,children:[t.jsx(ku,{size:14}),Oe("todo.cleanup")]}),t.jsx(oS,{}),t.jsxs("button",{onClick:()=>A(!0),className:sn,children:[t.jsx(xi,{size:14}),Oe("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:Pp,children:[t.jsx(Pn,{size:14}),Oe("todo.delete")]})]})]})}const P8=y.lazy(()=>Xu(()=>import("./TaskGraph-DVvS2YsK.js"),__vite__mapDeps([0,1,2,3,4]))),nu={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function ky(e,s,i){let a=i;const u=new Set;for(;a;){if(a===s)return!0;if(u.has(a))return!1;u.add(a);const f=e.find(m=>m.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function I8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartAll:m,onStopAll:o,onStartTodo:l,onStopTodo:h,onDeleteTodo:p,onEditTodo:d,onMergeTodo:g,onMergeChain:v,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:S,onScheduleTodo:_,onScheduleOnResetTodo:w,resetsAt:j,onUpdateDependency:R,onUpdatePosition:E,onReorderTodos:D,onEvent:N,onSendInput:T,interactiveTodos:z,debugLogging:P,showTokenUsage:O}){var ce;const[H,U]=y.useState(!1),[F,q]=y.useState(null),[$,K]=y.useState(null),[B,A]=y.useState(null),[I,Y]=y.useState(null),[G,J]=y.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[re,Z]=y.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[Q,W]=y.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[oe,le]=y.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:ge}=xt(),ue=y.useCallback(ee=>{J(ee);try{localStorage.setItem("todoViewMode",ee)}catch{}},[]),Ve=y.useCallback(ee=>{Z(ee);try{localStorage.setItem("todoStatusFilter",ee)}catch{}},[]),We=y.useCallback(()=>{W(ee=>{const Ne=!ee;try{localStorage.setItem("todoStackModeEnabled",String(Ne))}catch{}if(!Ne){le(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return Ne})},[]),De=y.useCallback(()=>{le(ee=>{const Ne=!ee;try{localStorage.setItem("todoStackCollapsed",String(Ne))}catch{}return Ne})},[]),be=Q&&oe&&G==="list",Re=y.useMemo(()=>({all:e.length,active:e.filter(ee=>nu.active.includes(ee.status)).length,completed:e.filter(ee=>nu.completed.includes(ee.status)).length,cancelled:e.filter(ee=>nu.cancelled.includes(ee.status)).length}),[e]),ct=y.useMemo(()=>{const ee=nu[re];return ee?e.filter(Ne=>ee.includes(Ne.status)):e},[e,re]),tt=(()=>{const ee=[...ct].sort((Ye,mt)=>Ye.priority-mt.priority);if(re!=="all"||be)return ee.map(Ye=>({todo:Ye,depth:0}));const Ne=new Map,je=[];for(const Ye of ee)if(Ye.depends_on){const mt=Ne.get(Ye.depends_on)||[];mt.push(Ye),Ne.set(Ye.depends_on,mt)}else je.push(Ye);const Me=[],Te=new Set,et=(Ye,mt)=>{if(Te.has(Ye.id))return;Te.add(Ye.id),Me.push({todo:Ye,depth:mt});const bt=Ne.get(Ye.id);if(bt)for(const yt of bt)et(yt,mt+1)};for(const Ye of je)et(Ye,0);for(const Ye of ee)Te.has(Ye.id)||Me.push({todo:Ye,depth:0});return Me})(),{completedChainRoots:Ke,completedChainMembers:Le}=y.useMemo(()=>{const ee=new Map;for(const Te of e)if(Te.depends_on){const et=ee.get(Te.depends_on)||[];et.push(Te.id),ee.set(Te.depends_on,et)}const Ne=e.filter(Te=>!Te.depends_on&&ee.has(Te.id)),je=new Map,Me=new Set;for(const Te of Ne){const et=[],Ye=mt=>{if(!e.find(Et=>Et.id===mt))return;et.push(mt);const yt=ee.get(mt)||[];for(const Et of yt)Ye(Et)};if(Ye(Te.id),et.length>=2&&et.every(mt=>{const bt=e.find(yt=>yt.id===mt);return(bt==null?void 0:bt.status)==="completed"||(bt==null?void 0:bt.status)==="merged"})){je.set(Te.id,et.length);for(const mt of et)Me.add(mt)}}return{completedChainRoots:je,completedChainMembers:Me}},[e]),[$e,Ie]=y.useState(null),[it,vt]=y.useState(null),Ce=y.useCallback(async ee=>{if(v){Ie(ee),vt(null);try{await v(ee)}catch(Ne){vt(Ne instanceof Error?Ne.message:"Merge failed")}finally{Ie(null)}}},[v]),Ue=y.useRef(!1),we=y.useCallback(ee=>{Ue.current=!1,K(ee)},[]),Pe=y.useCallback(async()=>{if(!Ue.current&&$&&R){const ee=e.find(Ne=>Ne.id===$);ee!=null&&ee.depends_on&&await R($,null)}K(null),A(null),Y(null)},[$,e,R]),X=y.useCallback(ee=>{A(ee),Y(null)},[]),ne=y.useCallback(ee=>{A(Ne=>Ne===ee?null:Ne)},[]),Se=y.useCallback(async ee=>{!$||!R||$!==ee&&(ky(e,$,ee)||(Ue.current=!0,await R($,ee),K(null),A(null),Y(null)))},[$,e,R]),fe=y.useCallback(async ee=>{R&&await R(ee,null)},[R]),ie=y.useCallback(ee=>!$||$===ee?!1:!ky(e,$,ee),[$,e]),ke=y.useCallback(ee=>{Y(ee),A(null)},[]),_e=y.useCallback(ee=>{Y(Ne=>Ne===ee?null:Ne)},[]),st=y.useCallback(async(ee,Ne)=>{if(!$||!D)return;const je=Ne.indexOf($);if(je<0)return;const Me=Ne.filter(Ye=>Ye!==$),Te=ee>je?ee-1:ee;if(Te===je){Y(null);return}const et=[...Me.slice(0,Te),$,...Me.slice(Te)];Ue.current=!0,await D(et),K(null),Y(null),A(null)},[$,D]),Ze=e.some(ee=>ee.status==="pending"||ee.status==="failed"||ee.status==="stopped"),he=e.some(ee=>ee.status==="running"),de=t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:m,disabled:!Ze,className:"btn-ghost text-sm",children:[t.jsx(Mr,{size:14}),ge("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!he,className:"btn-ghost text-sm",children:[t.jsx(Yi,{size:14}),ge("header.stopAll")]})]});return G==="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(En,{onClick:()=>ue("list"),label:ge("graph.listView"),size:"sm",children:t.jsx(Eu,{size:14})}),t.jsx(En,{onClick:()=>ue("graph"),label:ge("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(sb,{size:14})})]}),de]})]}),t.jsx(y.Suspense,{fallback:null,children:t.jsx(P8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartTodo:l,onStopTodo:h,onDeleteTodo:p,onEditTodo:d,onMergeTodo:g,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:S,onUpdateDependency:R,onUpdatePosition:E,onEvent:N,onSendInput:T,interactiveTodos:z,debugLogging:P,showTokenUsage:O})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:ee=>{yi(ee)||(ee.preventDefault(),q({x:ee.clientX,y:ee.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(En,{onClick:()=>ue("list"),label:ge("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Eu,{size:14})}),t.jsx(En,{onClick:()=>ue("graph"),label:ge("graph.graphView"),size:"sm",children:t.jsx(sb,{size:14})})]}),t.jsx(En,{onClick:We,label:ge(Q?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:Q?"active":"default",pressed:Q,children:t.jsx($E,{size:14})}),Q&&!oe&&G==="list"&&tt.length>0&&t.jsx(En,{onClick:De,label:ge("todos.collapseStack"),size:"sm",children:t.jsx(G5,{size:14})}),de,!H&&t.jsxs("button",{onClick:()=>U(!0),className:"btn-primary text-xs py-2",children:[t.jsx(wn,{size:14}),ge("todos.add")]})]})]}),H&&t.jsx("div",{className:"mb-5",children:t.jsx(aS,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,availableTodos:e,onSave:async(ee,Ne,je,Me,Te,et,Ye,mt,bt,yt)=>{await f(ee,Ne,je,Me,Te,et,Ye,mt,bt,yt),U(!1)},onCancel:()=>U(!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(ee=>{const Ne=re===ee,je=ee==="all"?"todos.filterAll":ee==="active"?"todos.filterActive":ee==="completed"?"todos.filterCompleted":"todos.filterCancelled";return t.jsxs("button",{onClick:()=>Ve(ee),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${Ne?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[t.jsx("span",{children:ge(je)}),t.jsx("span",{className:`text-2xs font-mono ${Ne?"text-accent/70":"text-warm-400"}`,children:Re[ee]})]},ee)})}),t.jsx("div",{className:be?"relative cursor-pointer":"space-y-3",onClick:be?De:void 0,title:be?ge("todos.expandStack"):void 0,style:be?{height:76+Math.max(tt.length-1,0)*6}:void 0,children:tt.length===0?t.jsx("div",{className:"card",children:t.jsx(Zi,{icon:a1,title:ge(re==="all"?"todos.empty":"todos.filterEmpty"),description:re==="all"?ge("todos.emptyHint"):void 0})}):(()=>{const ee=tt.map(({todo:je})=>je.id),Ne=je=>{if(be||!D)return null;const Me=$!==null&&I===je;return t.jsx("div",{onDragEnter:Te=>{Te.preventDefault(),ke(je)},onDragOver:Te=>{Te.preventDefault(),Te.stopPropagation(),Te.dataTransfer.dropEffect="link",ke(je)},onDragLeave:()=>_e(je),onDrop:Te=>{Te.preventDefault(),Te.stopPropagation(),st(je,ee)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:Me&&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-${je}`)};return t.jsxs(t.Fragment,{children:[Ne(0),tt.map(({todo:je,depth:Me},Te)=>{const et=Ke.has(je.id),Ye=Le.has(je.id),mt=6,bt="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",yt=be?{position:"absolute",top:Te*mt,left:0,right:0,zIndex:tt.length+10-Te,opacity:Te===0?1:.9,pointerEvents:Te===0?"auto":"none",transition:bt}:{transition:bt};return t.jsxs("div",{className:"",style:yt,children:[!be&&et&&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",children:[t.jsx(yl,{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(Ke.get(je.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[it&&$e===null&&t.jsx("span",{className:"text-2xs text-status-error",children:it}),t.jsxs("button",{onClick:()=>Ce(je.id),disabled:$e===je.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:ge("todo.mergeChainDesc"),children:[t.jsx(b5,{size:14}),$e===je.id?"...":ge("todo.mergeChain")]})]})]}),t.jsxs("div",{className:"relative",style:{marginLeft:Me>0?`${Me*24}px`:void 0},children:[Me>0&&t.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),t.jsx(B8,{todo:je,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:l,onStop:h,onDelete:p,onEdit:d,onMerge:g,onCleanup:C,onRetry:k,onContinue:x,onFix:S,onSchedule:_,onScheduleOnReset:w,resetsAt:j,onEvent:N,isInteractive:z.has(je.id),onSendInput:T,isDragSource:$===je.id,isDragging:$!==null,isDragOver:B===je.id,isValidDropTarget:ie(je.id),onDragStart:we,onDragEnd:Pe,onDragOverTarget:X,onDragLeaveTarget:ne,onDropTarget:Se,onRemoveDependency:R?fe:void 0,debugLogging:P,showTokenUsage:O,isChainMember:Ye})]}),Ne(Te+1)]},je.id)})]})})()}),!be&&$&&((ce=e.find(ee=>ee.id===$))==null?void 0:ce.depends_on)&&t.jsxs("div",{className:"mt-3 border-2 border-dashed border-warm-300 rounded-lg p-4 text-center text-sm text-status-error transition-colors hover:border-warm-400 hover:text-status-error hover:bg-status-error/10",onDragOver:ee=>{ee.preventDefault(),ee.dataTransfer.dropEffect="move"},onDrop:ee=>{ee.preventDefault(),$&&R&&(Ue.current=!0,R($,null))},children:[t.jsx(HN,{size:20,className:"mx-auto mb-1"}),ge("dnd.dropToRemoveDep")]}),F&&t.jsx(Gs,{x:F.x,y:F.y,onClose:()=>q(null),children:t.jsxs("button",{onClick:()=>U(!0),className:sn,children:[t.jsx(wn,{size:14}),ge("todos.add")]})})]})}const F8=[{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 H8(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,u,f,,m]=i,o=a.match(/^\*\/(\d+)$/);if(o&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const l=/^\d+$/.test(a)?parseInt(a):-1,h=/^\d+$/.test(u)?parseInt(u):-1;if(l<0||h<0)return{...s,mode:"custom"};if(f==="*"&&m!=="*"){const p=m.split(",").map(d=>{const g=parseInt(d);return isNaN(g)?-1:g}).filter(d=>d>=0);if(p.length>0)return{...s,mode:"weekly",weeklyDays:p,weeklyHour:h,weeklyMinute:l}}return/^\d+$/.test(f)&&m==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:h,monthlyMinute:l}:f==="*"&&m==="*"?{...s,mode:"daily",dailyHour:h,dailyMinute:l}:{...s,mode:"custom"}}function Cy(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 $8({value:e,onChange:s}){const{t:i}=xt(),[a,u]=y.useState(()=>H8(e)),[f,m]=y.useState(e);y.useEffect(()=>{if(a.mode==="custom")s(f);else{const v=Cy(a);s(v)}},[a,f]);const o=v=>{u(C=>({...C,...v}))},l=v=>{u(C=>{const k=C.weeklyDays.includes(v)?C.weeklyDays.filter(x=>x!==v):[...C.weeklyDays,v];return{...C,weeklyDays:k.length>0?k:C.weeklyDays}})},h=[{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",d=(v,C,k,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:v,onChange:S=>k(parseInt(S.target.value)),className:`${p} w-16`,children:Array.from({length:24},(S,_)=>t.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:S=>x(parseInt(S.target.value)),className:`${p} w-16`,children:Array.from({length:12},(S,_)=>_*5).map(S=>t.jsx("option",{value:S,children:String(S).padStart(2,"0")},S))})]}),g=a.mode==="custom"?f:Cy(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.map(v=>t.jsx("button",{type:"button",onClick:()=>o({mode:v.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===v.value?"bg-accent text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:i(v.labelKey)},v.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:v=>o({everyMinutes:parseInt(v.target.value)}),className:`${p} w-20`,children:[5,10,15,20,30].map(v=>t.jsx("option",{value:v,children:v},v))}),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:v=>o({hourlyMinute:parseInt(v.target.value)}),className:`${p} w-16`,children:Array.from({length:12},(v,C)=>C*5).map(v=>t.jsx("option",{value:v,children:String(v).padStart(2,"0")},v))}),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")}),d(a.dailyHour,a.dailyMinute,v=>o({dailyHour:v}),v=>o({dailyMinute:v}))]}),a.mode==="weekly"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:F8.map(v=>t.jsx("button",{type:"button",onClick:()=>l(v.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${a.weeklyDays.includes(v.value)?"bg-accent text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-accent"}`,children:i(v.labelKey)},v.value))}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.at")}),d(a.weeklyHour,a.weeklyMinute,v=>o({weeklyHour:v}),v=>o({weeklyMinute:v}))]})]}),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:v=>o({monthlyDay:parseInt(v.target.value)}),className:`${p} w-16`,children:Array.from({length:28},(v,C)=>C+1).map(v=>t.jsx("option",{value:v,children:v},v))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),d(a.monthlyHour,a.monthlyMinute,v=>o({monthlyHour:v}),v=>o({monthlyMinute:v}))]}),a.mode==="custom"&&t.jsxs("div",{children:[t.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:v=>m(v.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"&&g&&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-md bg-warm-100 text-warm-600 font-mono",children:g})]})]})}function U8(){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"),u=String(e.getHours()).padStart(2,"0"),f=String(e.getMinutes()).padStart(2,"0");return`${s}-${i}-${a}T${u}:${f}`}function W8(e){const s=new Date(e),i=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0"),f=String(s.getHours()).padStart(2,"0"),m=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${u}T${f}:${m}`}function lS({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:u="",initialCliTool:f,initialSkipIfRunning:m=!0,initialScheduleType:o="recurring",initialRunAt:l,projectCliTool:h="claude"}){const[p,d]=y.useState(i),[g,v]=y.useState(a),[C,k]=y.useState(u),[x,S]=y.useState(f||h||"claude"),[_,w]=y.useState(m),[j,R]=y.useState(o),[E,D]=y.useState(l?W8(l):U8()),{t:N}=xt(),T=j==="once",z=p.trim()&&(T?!!E:!!C.trim()),P=O=>{O.preventDefault(),z&&e({title:p.trim(),description:g.trim(),cronExpression:T?"":C.trim(),cliTool:x,skipIfRunning:_,scheduleType:j,runAt:T?new Date(E).toISOString():void 0})};return t.jsxs("form",{onSubmit:P,className:"card p-5",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:N("scheduleForm.titlePlaceholder"),value:p,onChange:O=>d(O.target.value),className:"input-field",autoFocus:!0})}),t.jsx("div",{className:"mb-3",children:t.jsx("textarea",{placeholder:N("scheduleForm.descPlaceholder"),value:g,onChange:O=>v(O.target.value),rows:3,className:"input-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:N("schedule.type")}),t.jsxs("div",{className:"inline-flex gap-1 rounded-lg bg-warm-100 p-1",children:[t.jsx("button",{type:"button",onClick:()=>R("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${j==="recurring"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:N("schedule.recurring")}),t.jsx("button",{type:"button",onClick:()=>R("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${j==="once"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:N("schedule.once")})]})]}),T?t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.runAtLabel")}),t.jsx("input",{type:"datetime-local",value:E,onChange:O=>D(O.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:N("schedule.cronExpression")}),t.jsx($8,{value:C,onChange:k})]}),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:N("scheduleForm.cliTool")}),t.jsx("select",{value:x,onChange:O=>S(O.target.value),className:"input-field text-sm !py-2",children:Fs.map(O=>t.jsx("option",{value:O.value,children:O.label},O.value))})]})}),!T&&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:_,onChange:O=>w(O.target.checked),className:"rounded-md border-warm-300 text-accent focus:ring-accent"}),N("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:N("scheduleForm.cancel")}),t.jsx("button",{type:"submit",disabled:!z,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function q8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:u,onMergeRun:f,onCleanupRun:m}){const[o,l]=y.useState(!1),[h,p]=y.useState(!1),[d,g]=y.useState([]),[v,C]=y.useState(!1),[k,x]=y.useState(!1),[S,_]=y.useState(null),{t:w}=xt(),j=async()=>{try{const U=await Sf(e.id);g(U)}catch{}},R=async U=>{if(!(!U.todo_id||!f)){_(U.id);try{await f(U.todo_id),await j()}finally{_(null)}}},E=async U=>{if(!(!U.todo_id||!m)){_(U.id);try{await m(U.todo_id),await j()}finally{_(null)}}},D=e.schedule_type==="once",N=async()=>{if(!v)try{const U=await Sf(e.id);g(U),C(!0)}catch{}},T=()=>{const U=!o;l(U),U&&N()},z=async()=>{x(!0);try{await u(e.id);const U=await Sf(e.id);g(U),C(!0)}finally{x(!1)}};if(h)return t.jsx(lS,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:D?"":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 U=>{await a(e.id,{title:U.title,description:U.description,cron_expression:U.cronExpression||void 0,cli_tool:U.cliTool,skip_if_running:U.skipIfRunning,schedule_type:U.scheduleType,run_at:U.runAt}),p(!1)},onCancel:()=>p(!1)});const P={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},O={triggered:w("schedule.runTriggered"),skipped:w("schedule.runSkipped"),completed:w("schedule.runCompleted"),failed:w("schedule.runFailed")},H=U=>U?new Date(U).toLocaleString():"";return t.jsxs("div",{className:"card overflow-hidden",children:[t.jsxs("div",{className:"flex items-start gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:T,children:[t.jsx("button",{className:"mt-0.5 text-warm-400 hover:text-warm-600 flex-shrink-0 transition-colors",children:t.jsx(ws,{size:14,className:`transition-transform duration-200 ${o?"rotate-90":""}`})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"text-sm text-warm-800 font-medium truncate",children:e.title}),t.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-2xs text-warm-400",children:[t.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[t.jsx(Vi,{size:12}),D?H(e.run_at):e.cron_expression]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{children:w(D?"schedule.once":"schedule.recurring")}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warm-500",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${e.is_active?"bg-status-success":"bg-warm-400"}`}),e.is_active?w("schedule.active"):w("schedule.paused")]})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:U=>U.stopPropagation(),children:[t.jsx("button",{onClick:z,disabled:k,className:"p-1.5 text-status-warning hover:text-status-warning hover:bg-status-warning/10 rounded-lg transition-colors disabled:opacity-30",title:w("schedule.trigger"),children:t.jsx(Mr,{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?w("schedule.pause"):w("schedule.activate"),children:e.is_active?t.jsx(hp,{size:14}):t.jsx(ar,{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:w("schedule.edit"),children:t.jsx(xi,{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:w("schedule.delete"),children:t.jsx(Pn,{size:14})})]})]}),o&&t.jsxs("div",{className:"border-t border-warm-200 px-5 py-5 space-y-4 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:"grid gap-x-8 gap-y-2 text-xs sm:grid-cols-2",children:[t.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[t.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:w(D?"schedule.runAtLabel":"schedule.cronExpression")}),t.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:D?H(e.run_at):e.cron_expression})]}),t.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[t.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:w("schedule.lastRun")}),t.jsx("span",{className:"min-w-0 truncate text-warm-600",children:e.last_run_at?new Date(e.last_run_at).toLocaleString():w("schedule.never")})]}),!D&&e.skip_if_running&&t.jsxs("div",{className:"flex items-center gap-2 text-warm-500 sm:col-span-2",children:[t.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-warm-400"}),w("schedule.skipIfRunning")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:w("schedule.runs")}),d.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:w("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:d.map(U=>{const F=U.todo_id&&U.todo_status==="completed"&&!!U.todo_branch_name,q=U.todo_id&&U.todo_status!=="running"&&U.todo_status!=="pending"&&(U.todo_worktree_path||U.todo_branch_name),$=S===U.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.jsxs("span",{className:"inline-flex items-center gap-1.5 font-medium text-warm-600",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${P[U.status]||"bg-warm-400"}`}),O[U.status]||U.status]}),U.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",U.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[F&&f&&t.jsx("button",{onClick:()=>R(U),disabled:$,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded-md transition-colors disabled:opacity-30",title:w("todo.merge"),children:t.jsx(Cu,{size:12})}),q&&m&&t.jsx("button",{onClick:()=>E(U),disabled:$,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded-md transition-colors disabled:opacity-30",title:w("todo.cleanup"),children:t.jsx(Pn,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(U.started_at).toLocaleString()})]},U.id)})})]})]})]})}function G8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:u,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:l}){const[h,p]=y.useState(!1),[d,g]=y.useState(null),{t:v}=xt();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{yi(C)||(C.preventDefault(),g({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:v("schedules.title")}),!h&&t.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[t.jsx(wn,{size:14}),v("schedules.add")]})]}),h&&t.jsx("div",{className:"mb-5",children:t.jsx(lS,{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(Zi,{icon:R5,title:v("schedules.empty"),description:v("schedules.emptyHint")})}):e.map((C,k)=>t.jsx("div",{children:t.jsx(q8,{schedule:C,onToggle:a,onDelete:u,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:l})},C.id))}),d&&t.jsx(Gs,{x:d.x,y:d.y,onClose:()=>g(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>p(!0),children:[t.jsx(wn,{size:14}),v("schedules.add")]})})]})}function cS(e){const[s,i]=y.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return y.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(e),u=f=>i(f.matches);return i(a.matches),a.addEventListener("change",u),()=>a.removeEventListener("change",u)},[e]),s}const jy="__custom__";function K8({open:e,onClose:s,projectId:i,projectName:a,onPushed:u}){const{t:f}=xt(),[m,o]=y.useState(!1),[l,h]=y.useState(!1),[p,d]=y.useState(null),[g,v]=y.useState([]),[C,k]=y.useState("origin"),[x,S]=y.useState([]),[_,w]=y.useState([]),[j,R]=y.useState(!0),[E,D]=y.useState(!1);y.useEffect(()=>{if(!e)return;let F=!1;return o(!0),d(null),Promise.all([d4(i),vm(i)]).then(([q,$])=>{var re,Z;if(F)return;const K=q.remotes||[];v(K);const B=((re=K.find(Q=>Q.name==="origin"))==null?void 0:re.name)||((Z=K[0])==null?void 0:Z.name)||"origin";k(B);const A=$.branches||[],I=A.filter(Q=>!Q.remote),Y=`remotes/${B}/`,G=A.filter(Q=>Q.remote&&Q.name.startsWith(Y)).map(Q=>Q.name.slice(Y.length)).filter(Q=>Q&&Q!=="HEAD");w(G);const J=new Set(G);S(I.map(Q=>{const W=J.has(Q.name);return{local:Q.name,current:Q.current,remote:Q.name,customRemote:!1,setUpstream:!W,checked:Q.current}}))}).catch(q=>{F||d(q instanceof Error?q.message:"Failed to load remotes")}).finally(()=>{F||o(!1)}),()=>{F=!0}},[e,i]),y.useEffect(()=>{if(!e||!C)return;let F=!1;return vm(i).then(q=>{if(F)return;const $=`remotes/${C}/`,K=(q.branches||[]).filter(B=>B.remote&&B.name.startsWith($)).map(B=>B.name.slice($.length)).filter(B=>B&&B!=="HEAD");w(K)}).catch(()=>{}),()=>{F=!0}},[C,i,e]);const N=x.length>0&&x.every(F=>F.checked),T=x.some(F=>F.checked),z=x.filter(F=>F.checked).length,P=y.useMemo(()=>{var F;return((F=g.find(q=>q.name===C))==null?void 0:F.url)||""},[g,C]),O=(F,q)=>{S($=>$.map(K=>K.local===F?{...K,...q}:K))},H=()=>{const F=!N;S(q=>q.map($=>({...$,checked:F})))},U=async()=>{d(null);const F=x.filter($=>$.checked);if(F.length===0){d(f("git.pushDialog.errorRequireBranch"));return}const q=F.map($=>({local:$.local,remote:($.remote||"").trim()||$.local,setUpstream:$.setUpstream}));h(!0);try{await fp(i,{remote:C,branches:q,pushAllTags:j,force:E}),u==null||u(),s()}catch($){d($ instanceof Error?$.message:"Push failed")}finally{h(!1)}};return t.jsx(Dn,{open:e,onClose:l?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:l,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:F=>k(F.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:m||l||g.length===0,children:[g.length===0&&t.jsx("option",{value:"origin",children:"origin"}),g.map(F=>t.jsx("option",{value:F.name,children:F.name},F.name))]}),t.jsx("input",{readOnly:!0,value:P,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(F=>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:F.checked,onChange:q=>O(F.local,{checked:q.target.checked}),disabled:l,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[F.local,F.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:F.customRemote?t.jsx("input",{type:"text",value:F.remote,onChange:q=>O(F.local,{remote:q.target.value}),placeholder:F.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l}):t.jsxs("select",{value:_.includes(F.remote)||F.remote?F.remote:"",onChange:q=>{const $=q.target.value;$===jy?O(F.local,{customRemote:!0}):O(F.local,{remote:$})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l,children:[!_.includes(F.remote)&&F.remote&&t.jsxs("option",{value:F.remote,children:[F.remote," (",f("git.pushDialog.newBranch"),")"]}),_.map(q=>t.jsx("option",{value:q,children:q},q)),t.jsx("option",{value:jy,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:F.setUpstream,onChange:q=>O(F.local,{setUpstream:q.target.checked}),disabled:l,className:"cursor-pointer"})})]},F.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:N,ref:F=>{F&&(F.indeterminate=!N&&T)},onChange:H,disabled:l||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:j,onChange:F=>R(F.target.checked),disabled:l,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:E,onChange:F=>D(F.target.checked),disabled:l,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:l,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.jsx("button",{type:"button",onClick:U,disabled:l||m||z===0,className:"btn-primary btn-md",children:f(l?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function V8(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 nd({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:u}){const{t:f}=xt();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")]}),u&&t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:u.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=V8(m.status),l=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 ${l?"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 oo({diff:e,loading:s,selectedFile:i,fileHeaders:a}){const{t:u}=xt(),[f,m]=y.useState(!0);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:u("git.loadingDiff")})}):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 justify-between gap-2",children:[t.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:i,children:i}),t.jsx("button",{onClick:()=>m(o=>!o),title:u("git.wrapLines")||"Wrap lines",className:`p-1 rounded-md shrink-0 hover:bg-gray-700 ${f?"text-accent":"text-gray-500"}`,children:t.jsx(zN,{size:14})})]}),t.jsx("div",{className:"flex-1 overflow-auto",children:t.jsx("div",{className:"p-3 font-mono text-xs leading-relaxed",children:e?(()=>{let o=0,l=0,h=!1;return e.split(`
660
+ `).map((pe,Be)=>{let dt="text-theme-text",kt="";return pe.startsWith("+")&&!pe.startsWith("+++")?dt="text-theme-text bg-status-success/15":pe.startsWith("-")&&!pe.startsWith("---")?dt="text-theme-text bg-status-error/15":pe.startsWith("@@")?dt="text-accent":pe.startsWith("diff ")&&(dt="text-warm-700",kt="font-semibold"),t.jsx("div",{className:`whitespace-pre ${dt} ${kt}`,children:pe},Be)}):t.jsx("span",{className:"text-warm-400 italic",children:Oe("log.noChanges")})})]}),t.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:Ge.bg,fontFamily:Ht,border:`1px solid ${Ge.separator}`},children:[t.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${Ge.separator}`,fontSize:12,color:Ge.text},children:[t.jsx("span",{style:{color:Ge.prompt},children:"$"})," ",t.jsx("span",{style:{color:Ge.bright},children:"tail"})," ",t.jsx("span",{style:{color:Ge.dim},children:"-f task.log"})]}),t.jsx(iS,{logs:I,interactive:_&&e.status==="running",todoId:e.id,onSendInput:w,embedded:!0})]})]})})]}),se&&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",children:[t.jsx(yl,{size:14,className:"text-accent flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-accent",children:Oe("dnd.dropHint")})]}),Je&&t.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-warm-300 bg-status-error/10",children:[t.jsx(k5,{size:14,className:"text-status-error flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-status-error",children:Oe("dnd.cyclicWarning")})]}),Xe&&t.jsxs(Gs,{x:Xe.x,y:Xe.y,onClose:()=>lt(null),children:[ve&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:sn,title:Oe("todo.startHeadless"),children:[t.jsx(Mr,{size:14}),Oe("todo.start")]}),ve&&Ys&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:sn,title:Oe("todo.startInteractiveDesc"),children:[t.jsx(bi,{size:14}),Oe("todo.startInteractive")]}),ve&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:sn,title:Oe("todo.startVerboseDesc"),children:[t.jsx(mm,{size:14}),Oe("todo.startVerbose")]}),nt&&t.jsxs("button",{onClick:()=>m(e.id),className:sn,children:[t.jsx(Yi,{size:14}),Oe("todo.stop")]}),jt&&t.jsxs("button",{onClick:_n,disabled:Ve,className:sn,children:[t.jsx(Cu,{size:14}),Oe("todo.merge")]}),ze&&t.jsxs("button",{onClick:()=>{Ce(!0),Se(null)},disabled:Pe,className:sn,children:[t.jsx(eb,{size:14}),Oe("todo.continue")]}),Bt&&t.jsxs("button",{onClick:()=>un("headless"),disabled:Le,className:sn,children:[t.jsx(vi,{size:14}),Oe("todo.retry")]}),ye&&t.jsxs("button",{onClick:()=>Te(!0),className:sn,title:Oe("todo.scheduleDesc"),children:[t.jsx(hm,{size:14}),Oe("todo.schedule")]}),me&&t.jsxs("button",{onClick:()=>{ie(!0),de(null)},className:sn,title:Oe("todo.scheduleOnResetDesc"),children:[t.jsx(Vi,{size:14}),Oe("todo.scheduleOnReset")]}),pt&&t.jsxs("button",{onClick:At,disabled:oe,className:sn,children:[t.jsx(ll,{size:14}),Oe("todo.viewDiff")]}),U&&_t&&t.jsxs("button",{onClick:Mt,className:sn,children:[t.jsx(ib,{size:14}),Oe("todo.viewDebugLog")]}),ut&&t.jsxs("button",{onClick:kn,disabled:Re,className:sn,children:[t.jsx(ku,{size:14}),Oe("todo.cleanup")]}),t.jsx(oS,{}),t.jsxs("button",{onClick:()=>A(!0),className:sn,children:[t.jsx(xi,{size:14}),Oe("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:Pp,children:[t.jsx(Pn,{size:14}),Oe("todo.delete")]})]})]})}const P8=y.lazy(()=>Xu(()=>import("./TaskGraph-BJfyaO8u.js"),__vite__mapDeps([0,1,2,3,4]))),nu={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function ky(e,s,i){let a=i;const u=new Set;for(;a;){if(a===s)return!0;if(u.has(a))return!1;u.add(a);const f=e.find(m=>m.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function I8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartAll:m,onStopAll:o,onStartTodo:l,onStopTodo:h,onDeleteTodo:p,onEditTodo:d,onMergeTodo:g,onMergeChain:v,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:S,onScheduleTodo:_,onScheduleOnResetTodo:w,resetsAt:j,onUpdateDependency:R,onUpdatePosition:E,onReorderTodos:D,onEvent:N,onSendInput:T,interactiveTodos:z,debugLogging:P,showTokenUsage:O}){var ce;const[H,U]=y.useState(!1),[F,q]=y.useState(null),[$,K]=y.useState(null),[B,A]=y.useState(null),[I,Y]=y.useState(null),[G,J]=y.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[re,Z]=y.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[Q,W]=y.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[oe,le]=y.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:ge}=xt(),ue=y.useCallback(ee=>{J(ee);try{localStorage.setItem("todoViewMode",ee)}catch{}},[]),Ve=y.useCallback(ee=>{Z(ee);try{localStorage.setItem("todoStatusFilter",ee)}catch{}},[]),We=y.useCallback(()=>{W(ee=>{const Ne=!ee;try{localStorage.setItem("todoStackModeEnabled",String(Ne))}catch{}if(!Ne){le(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return Ne})},[]),De=y.useCallback(()=>{le(ee=>{const Ne=!ee;try{localStorage.setItem("todoStackCollapsed",String(Ne))}catch{}return Ne})},[]),be=Q&&oe&&G==="list",Re=y.useMemo(()=>({all:e.length,active:e.filter(ee=>nu.active.includes(ee.status)).length,completed:e.filter(ee=>nu.completed.includes(ee.status)).length,cancelled:e.filter(ee=>nu.cancelled.includes(ee.status)).length}),[e]),ct=y.useMemo(()=>{const ee=nu[re];return ee?e.filter(Ne=>ee.includes(Ne.status)):e},[e,re]),tt=(()=>{const ee=[...ct].sort((Ye,mt)=>Ye.priority-mt.priority);if(re!=="all"||be)return ee.map(Ye=>({todo:Ye,depth:0}));const Ne=new Map,je=[];for(const Ye of ee)if(Ye.depends_on){const mt=Ne.get(Ye.depends_on)||[];mt.push(Ye),Ne.set(Ye.depends_on,mt)}else je.push(Ye);const Me=[],Te=new Set,et=(Ye,mt)=>{if(Te.has(Ye.id))return;Te.add(Ye.id),Me.push({todo:Ye,depth:mt});const bt=Ne.get(Ye.id);if(bt)for(const yt of bt)et(yt,mt+1)};for(const Ye of je)et(Ye,0);for(const Ye of ee)Te.has(Ye.id)||Me.push({todo:Ye,depth:0});return Me})(),{completedChainRoots:Ke,completedChainMembers:Le}=y.useMemo(()=>{const ee=new Map;for(const Te of e)if(Te.depends_on){const et=ee.get(Te.depends_on)||[];et.push(Te.id),ee.set(Te.depends_on,et)}const Ne=e.filter(Te=>!Te.depends_on&&ee.has(Te.id)),je=new Map,Me=new Set;for(const Te of Ne){const et=[],Ye=mt=>{if(!e.find(Et=>Et.id===mt))return;et.push(mt);const yt=ee.get(mt)||[];for(const Et of yt)Ye(Et)};if(Ye(Te.id),et.length>=2&&et.every(mt=>{const bt=e.find(yt=>yt.id===mt);return(bt==null?void 0:bt.status)==="completed"||(bt==null?void 0:bt.status)==="merged"})){je.set(Te.id,et.length);for(const mt of et)Me.add(mt)}}return{completedChainRoots:je,completedChainMembers:Me}},[e]),[$e,Ie]=y.useState(null),[it,vt]=y.useState(null),Ce=y.useCallback(async ee=>{if(v){Ie(ee),vt(null);try{await v(ee)}catch(Ne){vt(Ne instanceof Error?Ne.message:"Merge failed")}finally{Ie(null)}}},[v]),Ue=y.useRef(!1),we=y.useCallback(ee=>{Ue.current=!1,K(ee)},[]),Pe=y.useCallback(async()=>{if(!Ue.current&&$&&R){const ee=e.find(Ne=>Ne.id===$);ee!=null&&ee.depends_on&&await R($,null)}K(null),A(null),Y(null)},[$,e,R]),X=y.useCallback(ee=>{A(ee),Y(null)},[]),ne=y.useCallback(ee=>{A(Ne=>Ne===ee?null:Ne)},[]),Se=y.useCallback(async ee=>{!$||!R||$!==ee&&(ky(e,$,ee)||(Ue.current=!0,await R($,ee),K(null),A(null),Y(null)))},[$,e,R]),fe=y.useCallback(async ee=>{R&&await R(ee,null)},[R]),ie=y.useCallback(ee=>!$||$===ee?!1:!ky(e,$,ee),[$,e]),ke=y.useCallback(ee=>{Y(ee),A(null)},[]),_e=y.useCallback(ee=>{Y(Ne=>Ne===ee?null:Ne)},[]),st=y.useCallback(async(ee,Ne)=>{if(!$||!D)return;const je=Ne.indexOf($);if(je<0)return;const Me=Ne.filter(Ye=>Ye!==$),Te=ee>je?ee-1:ee;if(Te===je){Y(null);return}const et=[...Me.slice(0,Te),$,...Me.slice(Te)];Ue.current=!0,await D(et),K(null),Y(null),A(null)},[$,D]),Ze=e.some(ee=>ee.status==="pending"||ee.status==="failed"||ee.status==="stopped"),he=e.some(ee=>ee.status==="running"),de=t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:m,disabled:!Ze,className:"btn-ghost text-sm",children:[t.jsx(Mr,{size:14}),ge("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!he,className:"btn-ghost text-sm",children:[t.jsx(Yi,{size:14}),ge("header.stopAll")]})]});return G==="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(En,{onClick:()=>ue("list"),label:ge("graph.listView"),size:"sm",children:t.jsx(Eu,{size:14})}),t.jsx(En,{onClick:()=>ue("graph"),label:ge("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(sb,{size:14})})]}),de]})]}),t.jsx(y.Suspense,{fallback:null,children:t.jsx(P8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartTodo:l,onStopTodo:h,onDeleteTodo:p,onEditTodo:d,onMergeTodo:g,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:S,onUpdateDependency:R,onUpdatePosition:E,onEvent:N,onSendInput:T,interactiveTodos:z,debugLogging:P,showTokenUsage:O})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:ee=>{yi(ee)||(ee.preventDefault(),q({x:ee.clientX,y:ee.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(En,{onClick:()=>ue("list"),label:ge("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Eu,{size:14})}),t.jsx(En,{onClick:()=>ue("graph"),label:ge("graph.graphView"),size:"sm",children:t.jsx(sb,{size:14})})]}),t.jsx(En,{onClick:We,label:ge(Q?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:Q?"active":"default",pressed:Q,children:t.jsx($E,{size:14})}),Q&&!oe&&G==="list"&&tt.length>0&&t.jsx(En,{onClick:De,label:ge("todos.collapseStack"),size:"sm",children:t.jsx(G5,{size:14})}),de,!H&&t.jsxs("button",{onClick:()=>U(!0),className:"btn-primary text-xs py-2",children:[t.jsx(wn,{size:14}),ge("todos.add")]})]})]}),H&&t.jsx("div",{className:"mb-5",children:t.jsx(aS,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,availableTodos:e,onSave:async(ee,Ne,je,Me,Te,et,Ye,mt,bt,yt)=>{await f(ee,Ne,je,Me,Te,et,Ye,mt,bt,yt),U(!1)},onCancel:()=>U(!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(ee=>{const Ne=re===ee,je=ee==="all"?"todos.filterAll":ee==="active"?"todos.filterActive":ee==="completed"?"todos.filterCompleted":"todos.filterCancelled";return t.jsxs("button",{onClick:()=>Ve(ee),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${Ne?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[t.jsx("span",{children:ge(je)}),t.jsx("span",{className:`text-2xs font-mono ${Ne?"text-accent/70":"text-warm-400"}`,children:Re[ee]})]},ee)})}),t.jsx("div",{className:be?"relative cursor-pointer":"space-y-3",onClick:be?De:void 0,title:be?ge("todos.expandStack"):void 0,style:be?{height:76+Math.max(tt.length-1,0)*6}:void 0,children:tt.length===0?t.jsx("div",{className:"card",children:t.jsx(Zi,{icon:a1,title:ge(re==="all"?"todos.empty":"todos.filterEmpty"),description:re==="all"?ge("todos.emptyHint"):void 0})}):(()=>{const ee=tt.map(({todo:je})=>je.id),Ne=je=>{if(be||!D)return null;const Me=$!==null&&I===je;return t.jsx("div",{onDragEnter:Te=>{Te.preventDefault(),ke(je)},onDragOver:Te=>{Te.preventDefault(),Te.stopPropagation(),Te.dataTransfer.dropEffect="link",ke(je)},onDragLeave:()=>_e(je),onDrop:Te=>{Te.preventDefault(),Te.stopPropagation(),st(je,ee)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:Me&&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-${je}`)};return t.jsxs(t.Fragment,{children:[Ne(0),tt.map(({todo:je,depth:Me},Te)=>{const et=Ke.has(je.id),Ye=Le.has(je.id),mt=6,bt="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",yt=be?{position:"absolute",top:Te*mt,left:0,right:0,zIndex:tt.length+10-Te,opacity:Te===0?1:.9,pointerEvents:Te===0?"auto":"none",transition:bt}:{transition:bt};return t.jsxs("div",{className:"",style:yt,children:[!be&&et&&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",children:[t.jsx(yl,{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(Ke.get(je.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[it&&$e===null&&t.jsx("span",{className:"text-2xs text-status-error",children:it}),t.jsxs("button",{onClick:()=>Ce(je.id),disabled:$e===je.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:ge("todo.mergeChainDesc"),children:[t.jsx(b5,{size:14}),$e===je.id?"...":ge("todo.mergeChain")]})]})]}),t.jsxs("div",{className:"relative",style:{marginLeft:Me>0?`${Me*24}px`:void 0},children:[Me>0&&t.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),t.jsx(B8,{todo:je,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:l,onStop:h,onDelete:p,onEdit:d,onMerge:g,onCleanup:C,onRetry:k,onContinue:x,onFix:S,onSchedule:_,onScheduleOnReset:w,resetsAt:j,onEvent:N,isInteractive:z.has(je.id),onSendInput:T,isDragSource:$===je.id,isDragging:$!==null,isDragOver:B===je.id,isValidDropTarget:ie(je.id),onDragStart:we,onDragEnd:Pe,onDragOverTarget:X,onDragLeaveTarget:ne,onDropTarget:Se,onRemoveDependency:R?fe:void 0,debugLogging:P,showTokenUsage:O,isChainMember:Ye})]}),Ne(Te+1)]},je.id)})]})})()}),!be&&$&&((ce=e.find(ee=>ee.id===$))==null?void 0:ce.depends_on)&&t.jsxs("div",{className:"mt-3 border-2 border-dashed border-warm-300 rounded-lg p-4 text-center text-sm text-status-error transition-colors hover:border-warm-400 hover:text-status-error hover:bg-status-error/10",onDragOver:ee=>{ee.preventDefault(),ee.dataTransfer.dropEffect="move"},onDrop:ee=>{ee.preventDefault(),$&&R&&(Ue.current=!0,R($,null))},children:[t.jsx(HN,{size:20,className:"mx-auto mb-1"}),ge("dnd.dropToRemoveDep")]}),F&&t.jsx(Gs,{x:F.x,y:F.y,onClose:()=>q(null),children:t.jsxs("button",{onClick:()=>U(!0),className:sn,children:[t.jsx(wn,{size:14}),ge("todos.add")]})})]})}const F8=[{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 H8(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,u,f,,m]=i,o=a.match(/^\*\/(\d+)$/);if(o&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const l=/^\d+$/.test(a)?parseInt(a):-1,h=/^\d+$/.test(u)?parseInt(u):-1;if(l<0||h<0)return{...s,mode:"custom"};if(f==="*"&&m!=="*"){const p=m.split(",").map(d=>{const g=parseInt(d);return isNaN(g)?-1:g}).filter(d=>d>=0);if(p.length>0)return{...s,mode:"weekly",weeklyDays:p,weeklyHour:h,weeklyMinute:l}}return/^\d+$/.test(f)&&m==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:h,monthlyMinute:l}:f==="*"&&m==="*"?{...s,mode:"daily",dailyHour:h,dailyMinute:l}:{...s,mode:"custom"}}function Cy(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 $8({value:e,onChange:s}){const{t:i}=xt(),[a,u]=y.useState(()=>H8(e)),[f,m]=y.useState(e);y.useEffect(()=>{if(a.mode==="custom")s(f);else{const v=Cy(a);s(v)}},[a,f]);const o=v=>{u(C=>({...C,...v}))},l=v=>{u(C=>{const k=C.weeklyDays.includes(v)?C.weeklyDays.filter(x=>x!==v):[...C.weeklyDays,v];return{...C,weeklyDays:k.length>0?k:C.weeklyDays}})},h=[{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",d=(v,C,k,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:v,onChange:S=>k(parseInt(S.target.value)),className:`${p} w-16`,children:Array.from({length:24},(S,_)=>t.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:S=>x(parseInt(S.target.value)),className:`${p} w-16`,children:Array.from({length:12},(S,_)=>_*5).map(S=>t.jsx("option",{value:S,children:String(S).padStart(2,"0")},S))})]}),g=a.mode==="custom"?f:Cy(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.map(v=>t.jsx("button",{type:"button",onClick:()=>o({mode:v.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===v.value?"bg-accent text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:i(v.labelKey)},v.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:v=>o({everyMinutes:parseInt(v.target.value)}),className:`${p} w-20`,children:[5,10,15,20,30].map(v=>t.jsx("option",{value:v,children:v},v))}),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:v=>o({hourlyMinute:parseInt(v.target.value)}),className:`${p} w-16`,children:Array.from({length:12},(v,C)=>C*5).map(v=>t.jsx("option",{value:v,children:String(v).padStart(2,"0")},v))}),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")}),d(a.dailyHour,a.dailyMinute,v=>o({dailyHour:v}),v=>o({dailyMinute:v}))]}),a.mode==="weekly"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:F8.map(v=>t.jsx("button",{type:"button",onClick:()=>l(v.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${a.weeklyDays.includes(v.value)?"bg-accent text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-accent"}`,children:i(v.labelKey)},v.value))}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.at")}),d(a.weeklyHour,a.weeklyMinute,v=>o({weeklyHour:v}),v=>o({weeklyMinute:v}))]})]}),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:v=>o({monthlyDay:parseInt(v.target.value)}),className:`${p} w-16`,children:Array.from({length:28},(v,C)=>C+1).map(v=>t.jsx("option",{value:v,children:v},v))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),d(a.monthlyHour,a.monthlyMinute,v=>o({monthlyHour:v}),v=>o({monthlyMinute:v}))]}),a.mode==="custom"&&t.jsxs("div",{children:[t.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:v=>m(v.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"&&g&&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-md bg-warm-100 text-warm-600 font-mono",children:g})]})]})}function U8(){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"),u=String(e.getHours()).padStart(2,"0"),f=String(e.getMinutes()).padStart(2,"0");return`${s}-${i}-${a}T${u}:${f}`}function W8(e){const s=new Date(e),i=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0"),f=String(s.getHours()).padStart(2,"0"),m=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${u}T${f}:${m}`}function lS({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:u="",initialCliTool:f,initialSkipIfRunning:m=!0,initialScheduleType:o="recurring",initialRunAt:l,projectCliTool:h="claude"}){const[p,d]=y.useState(i),[g,v]=y.useState(a),[C,k]=y.useState(u),[x,S]=y.useState(f||h||"claude"),[_,w]=y.useState(m),[j,R]=y.useState(o),[E,D]=y.useState(l?W8(l):U8()),{t:N}=xt(),T=j==="once",z=p.trim()&&(T?!!E:!!C.trim()),P=O=>{O.preventDefault(),z&&e({title:p.trim(),description:g.trim(),cronExpression:T?"":C.trim(),cliTool:x,skipIfRunning:_,scheduleType:j,runAt:T?new Date(E).toISOString():void 0})};return t.jsxs("form",{onSubmit:P,className:"card p-5",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:N("scheduleForm.titlePlaceholder"),value:p,onChange:O=>d(O.target.value),className:"input-field",autoFocus:!0})}),t.jsx("div",{className:"mb-3",children:t.jsx("textarea",{placeholder:N("scheduleForm.descPlaceholder"),value:g,onChange:O=>v(O.target.value),rows:3,className:"input-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:N("schedule.type")}),t.jsxs("div",{className:"inline-flex gap-1 rounded-lg bg-warm-100 p-1",children:[t.jsx("button",{type:"button",onClick:()=>R("recurring"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${j==="recurring"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:N("schedule.recurring")}),t.jsx("button",{type:"button",onClick:()=>R("once"),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${j==="once"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:N("schedule.once")})]})]}),T?t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.runAtLabel")}),t.jsx("input",{type:"datetime-local",value:E,onChange:O=>D(O.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:N("schedule.cronExpression")}),t.jsx($8,{value:C,onChange:k})]}),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:N("scheduleForm.cliTool")}),t.jsx("select",{value:x,onChange:O=>S(O.target.value),className:"input-field text-sm !py-2",children:Fs.map(O=>t.jsx("option",{value:O.value,children:O.label},O.value))})]})}),!T&&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:_,onChange:O=>w(O.target.checked),className:"rounded-md border-warm-300 text-accent focus:ring-accent"}),N("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:N("scheduleForm.cancel")}),t.jsx("button",{type:"submit",disabled:!z,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function q8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:u,onMergeRun:f,onCleanupRun:m}){const[o,l]=y.useState(!1),[h,p]=y.useState(!1),[d,g]=y.useState([]),[v,C]=y.useState(!1),[k,x]=y.useState(!1),[S,_]=y.useState(null),{t:w}=xt(),j=async()=>{try{const U=await Sf(e.id);g(U)}catch{}},R=async U=>{if(!(!U.todo_id||!f)){_(U.id);try{await f(U.todo_id),await j()}finally{_(null)}}},E=async U=>{if(!(!U.todo_id||!m)){_(U.id);try{await m(U.todo_id),await j()}finally{_(null)}}},D=e.schedule_type==="once",N=async()=>{if(!v)try{const U=await Sf(e.id);g(U),C(!0)}catch{}},T=()=>{const U=!o;l(U),U&&N()},z=async()=>{x(!0);try{await u(e.id);const U=await Sf(e.id);g(U),C(!0)}finally{x(!1)}};if(h)return t.jsx(lS,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:D?"":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 U=>{await a(e.id,{title:U.title,description:U.description,cron_expression:U.cronExpression||void 0,cli_tool:U.cliTool,skip_if_running:U.skipIfRunning,schedule_type:U.scheduleType,run_at:U.runAt}),p(!1)},onCancel:()=>p(!1)});const P={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},O={triggered:w("schedule.runTriggered"),skipped:w("schedule.runSkipped"),completed:w("schedule.runCompleted"),failed:w("schedule.runFailed")},H=U=>U?new Date(U).toLocaleString():"";return t.jsxs("div",{className:"card overflow-hidden",children:[t.jsxs("div",{className:"flex items-start gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:T,children:[t.jsx("button",{className:"mt-0.5 text-warm-400 hover:text-warm-600 flex-shrink-0 transition-colors",children:t.jsx(ws,{size:14,className:`transition-transform duration-200 ${o?"rotate-90":""}`})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"text-sm text-warm-800 font-medium truncate",children:e.title}),t.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-2xs text-warm-400",children:[t.jsxs("span",{className:"inline-flex items-center gap-1 font-mono",children:[t.jsx(Vi,{size:12}),D?H(e.run_at):e.cron_expression]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{children:w(D?"schedule.once":"schedule.recurring")}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warm-500",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${e.is_active?"bg-status-success":"bg-warm-400"}`}),e.is_active?w("schedule.active"):w("schedule.paused")]})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:U=>U.stopPropagation(),children:[t.jsx("button",{onClick:z,disabled:k,className:"p-1.5 text-status-warning hover:text-status-warning hover:bg-status-warning/10 rounded-lg transition-colors disabled:opacity-30",title:w("schedule.trigger"),children:t.jsx(Mr,{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?w("schedule.pause"):w("schedule.activate"),children:e.is_active?t.jsx(hp,{size:14}):t.jsx(ar,{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:w("schedule.edit"),children:t.jsx(xi,{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:w("schedule.delete"),children:t.jsx(Pn,{size:14})})]})]}),o&&t.jsxs("div",{className:"border-t border-warm-200 px-5 py-5 space-y-4 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:"grid gap-x-8 gap-y-2 text-xs sm:grid-cols-2",children:[t.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[t.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:w(D?"schedule.runAtLabel":"schedule.cronExpression")}),t.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:D?H(e.run_at):e.cron_expression})]}),t.jsxs("div",{className:"flex items-baseline gap-3 min-w-0",children:[t.jsx("span",{className:"w-20 shrink-0 text-warm-400",children:w("schedule.lastRun")}),t.jsx("span",{className:"min-w-0 truncate text-warm-600",children:e.last_run_at?new Date(e.last_run_at).toLocaleString():w("schedule.never")})]}),!D&&e.skip_if_running&&t.jsxs("div",{className:"flex items-center gap-2 text-warm-500 sm:col-span-2",children:[t.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-warm-400"}),w("schedule.skipIfRunning")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:w("schedule.runs")}),d.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:w("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:d.map(U=>{const F=U.todo_id&&U.todo_status==="completed"&&!!U.todo_branch_name,q=U.todo_id&&U.todo_status!=="running"&&U.todo_status!=="pending"&&(U.todo_worktree_path||U.todo_branch_name),$=S===U.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.jsxs("span",{className:"inline-flex items-center gap-1.5 font-medium text-warm-600",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${P[U.status]||"bg-warm-400"}`}),O[U.status]||U.status]}),U.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",U.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[F&&f&&t.jsx("button",{onClick:()=>R(U),disabled:$,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded-md transition-colors disabled:opacity-30",title:w("todo.merge"),children:t.jsx(Cu,{size:12})}),q&&m&&t.jsx("button",{onClick:()=>E(U),disabled:$,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded-md transition-colors disabled:opacity-30",title:w("todo.cleanup"),children:t.jsx(Pn,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(U.started_at).toLocaleString()})]},U.id)})})]})]})]})}function G8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:u,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:l}){const[h,p]=y.useState(!1),[d,g]=y.useState(null),{t:v}=xt();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{yi(C)||(C.preventDefault(),g({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:v("schedules.title")}),!h&&t.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[t.jsx(wn,{size:14}),v("schedules.add")]})]}),h&&t.jsx("div",{className:"mb-5",children:t.jsx(lS,{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(Zi,{icon:R5,title:v("schedules.empty"),description:v("schedules.emptyHint")})}):e.map((C,k)=>t.jsx("div",{children:t.jsx(q8,{schedule:C,onToggle:a,onDelete:u,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:l})},C.id))}),d&&t.jsx(Gs,{x:d.x,y:d.y,onClose:()=>g(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>p(!0),children:[t.jsx(wn,{size:14}),v("schedules.add")]})})]})}function cS(e){const[s,i]=y.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return y.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(e),u=f=>i(f.matches);return i(a.matches),a.addEventListener("change",u),()=>a.removeEventListener("change",u)},[e]),s}const jy="__custom__";function K8({open:e,onClose:s,projectId:i,projectName:a,onPushed:u}){const{t:f}=xt(),[m,o]=y.useState(!1),[l,h]=y.useState(!1),[p,d]=y.useState(null),[g,v]=y.useState([]),[C,k]=y.useState("origin"),[x,S]=y.useState([]),[_,w]=y.useState([]),[j,R]=y.useState(!0),[E,D]=y.useState(!1);y.useEffect(()=>{if(!e)return;let F=!1;return o(!0),d(null),Promise.all([d4(i),vm(i)]).then(([q,$])=>{var re,Z;if(F)return;const K=q.remotes||[];v(K);const B=((re=K.find(Q=>Q.name==="origin"))==null?void 0:re.name)||((Z=K[0])==null?void 0:Z.name)||"origin";k(B);const A=$.branches||[],I=A.filter(Q=>!Q.remote),Y=`remotes/${B}/`,G=A.filter(Q=>Q.remote&&Q.name.startsWith(Y)).map(Q=>Q.name.slice(Y.length)).filter(Q=>Q&&Q!=="HEAD");w(G);const J=new Set(G);S(I.map(Q=>{const W=J.has(Q.name);return{local:Q.name,current:Q.current,remote:Q.name,customRemote:!1,setUpstream:!W,checked:Q.current}}))}).catch(q=>{F||d(q instanceof Error?q.message:"Failed to load remotes")}).finally(()=>{F||o(!1)}),()=>{F=!0}},[e,i]),y.useEffect(()=>{if(!e||!C)return;let F=!1;return vm(i).then(q=>{if(F)return;const $=`remotes/${C}/`,K=(q.branches||[]).filter(B=>B.remote&&B.name.startsWith($)).map(B=>B.name.slice($.length)).filter(B=>B&&B!=="HEAD");w(K)}).catch(()=>{}),()=>{F=!0}},[C,i,e]);const N=x.length>0&&x.every(F=>F.checked),T=x.some(F=>F.checked),z=x.filter(F=>F.checked).length,P=y.useMemo(()=>{var F;return((F=g.find(q=>q.name===C))==null?void 0:F.url)||""},[g,C]),O=(F,q)=>{S($=>$.map(K=>K.local===F?{...K,...q}:K))},H=()=>{const F=!N;S(q=>q.map($=>({...$,checked:F})))},U=async()=>{d(null);const F=x.filter($=>$.checked);if(F.length===0){d(f("git.pushDialog.errorRequireBranch"));return}const q=F.map($=>({local:$.local,remote:($.remote||"").trim()||$.local,setUpstream:$.setUpstream}));h(!0);try{await fp(i,{remote:C,branches:q,pushAllTags:j,force:E}),u==null||u(),s()}catch($){d($ instanceof Error?$.message:"Push failed")}finally{h(!1)}};return t.jsx(Dn,{open:e,onClose:l?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:l,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:F=>k(F.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:m||l||g.length===0,children:[g.length===0&&t.jsx("option",{value:"origin",children:"origin"}),g.map(F=>t.jsx("option",{value:F.name,children:F.name},F.name))]}),t.jsx("input",{readOnly:!0,value:P,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(F=>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:F.checked,onChange:q=>O(F.local,{checked:q.target.checked}),disabled:l,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[F.local,F.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:F.customRemote?t.jsx("input",{type:"text",value:F.remote,onChange:q=>O(F.local,{remote:q.target.value}),placeholder:F.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l}):t.jsxs("select",{value:_.includes(F.remote)||F.remote?F.remote:"",onChange:q=>{const $=q.target.value;$===jy?O(F.local,{customRemote:!0}):O(F.local,{remote:$})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l,children:[!_.includes(F.remote)&&F.remote&&t.jsxs("option",{value:F.remote,children:[F.remote," (",f("git.pushDialog.newBranch"),")"]}),_.map(q=>t.jsx("option",{value:q,children:q},q)),t.jsx("option",{value:jy,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:F.setUpstream,onChange:q=>O(F.local,{setUpstream:q.target.checked}),disabled:l,className:"cursor-pointer"})})]},F.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:N,ref:F=>{F&&(F.indeterminate=!N&&T)},onChange:H,disabled:l||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:j,onChange:F=>R(F.target.checked),disabled:l,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:E,onChange:F=>D(F.target.checked),disabled:l,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:l,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.jsx("button",{type:"button",onClick:U,disabled:l||m||z===0,className:"btn-primary btn-md",children:f(l?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function V8(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 nd({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:u}){const{t:f}=xt();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")]}),u&&t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:u.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=V8(m.status),l=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 ${l?"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 oo({diff:e,loading:s,selectedFile:i,fileHeaders:a}){const{t:u}=xt(),[f,m]=y.useState(!0);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:u("git.loadingDiff")})}):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 justify-between gap-2",children:[t.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:i,children:i}),t.jsx("button",{onClick:()=>m(o=>!o),title:u("git.wrapLines")||"Wrap lines",className:`p-1 rounded-md shrink-0 hover:bg-gray-700 ${f?"text-accent":"text-gray-500"}`,children:t.jsx(zN,{size:14})})]}),t.jsx("div",{className:"flex-1 overflow-auto",children:t.jsx("div",{className:"p-3 font-mono text-xs leading-relaxed",children:e?(()=>{let o=0,l=0,h=!1;return e.split(`
661
661
  `).map((p,d)=>{if(a&&p.startsWith("Index: "))return h=!1,t.jsx("div",{className:"mt-3 first:mt-0 mb-1 pb-1 border-b border-gray-700 font-semibold text-gray-100",children:p.slice(7)},d);if(p.startsWith("@@")){const k=/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(p);return k&&(o=parseInt(k[1],10),l=parseInt(k[2],10),h=!0),null}if(!h)return null;let g="text-gray-200",v=null,C=null;if(p.startsWith("+")&&!p.startsWith("+++"))g="text-gray-100 bg-green-500/20",C=l++;else if(p.startsWith("-")&&!p.startsWith("---"))g="text-gray-100 bg-red-500/20",v=o++;else if(p.startsWith(" "))v=o++,C=l++;else return null;return t.jsxs("div",{className:`flex items-start ${g}`,children:[t.jsx("span",{className:"select-none shrink-0 w-9 pr-2 text-right text-gray-500",children:v??""}),t.jsx("span",{className:"select-none shrink-0 w-9 pr-2 text-right text-gray-500",children:C??""}),t.jsx("span",{className:`flex-1 min-w-0 ${f?"whitespace-pre-wrap break-words":"whitespace-pre"}`,children:p||" "})]},d)})})():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:u("git.selectFileToViewDiff")})})}function Y8(e){const s=e.split(`
662
662
  `),i=[];let a=[];const u=()=>{a.length&&(i.push({kind:"text",lines:a}),a=[])};let f=0;for(;f<s.length;){const m=s[f];if(m.startsWith("<<<<<<<")){u();const o=m.slice(7).trim()||"HEAD";f++;const l=[];for(;f<s.length&&!s[f].startsWith("|||||||")&&!s[f].startsWith("=======");)l.push(s[f]),f++;if(f<s.length&&s[f].startsWith("|||||||"))for(f++;f<s.length&&!s[f].startsWith("=======");)f++;f<s.length&&s[f].startsWith("=======")&&f++;const h=[];for(;f<s.length&&!s[f].startsWith(">>>>>>>");)h.push(s[f]),f++;f<s.length&&s[f].startsWith(">>>>>>>")&&f++,i.push({kind:"conflict",ours:l,theirs:h,label:o})}else a.push(m),f++}return u(),i}function X8(e,s){const i=[];return e.forEach((a,u)=>{if(a.kind==="text"){i.push(...a.lines);return}const f=s[u];f==="ours"?i.push(...a.ours):f==="theirs"?i.push(...a.theirs):f==="both"?i.push(...a.ours,...a.theirs):i.push(`<<<<<<< ${a.label}`,...a.ours,"=======",...a.theirs,">>>>>>> incoming")}),i.join(`
663
663
  `)}const J8=/^(<{7}|>{7})/m;function $f({lines:e,tint:s}){return t.jsx("pre",{className:`px-3 py-1.5 font-mono text-xs leading-relaxed overflow-x-auto ${s}`,children:e.length?e.map((i,a)=>t.jsx("div",{children:i||" "},a)):t.jsx("div",{className:"italic opacity-50",children:"∅"})})}function Q8({projectId:e,worktreePath:s,filePath:i,onResolved:a,onError:u}){const{t:f}=xt(),[m,o]=y.useState(null),[l,h]=y.useState({}),[p,d]=y.useState(!1),[g,v]=y.useState(""),[C,k]=y.useState(!0),[x,S]=y.useState(!1),[_,w]=y.useState(!1);y.useEffect(()=>{let U=!1;return k(!0),d(!1),h({}),w(!1),h4(e,i,s).then(F=>{U||o(Y8(F.content))}).catch(()=>{U||w(!0)}).finally(()=>{U||k(!1)}),()=>{U=!0}},[e,s,i]);const j=y.useMemo(()=>m?m.map((U,F)=>U.kind==="conflict"?F:-1).filter(U=>U>=0):[],[m]),R=j.filter(U=>l[U]).length,E=j.length-R,D=y.useMemo(()=>m?X8(m,l):"",[m,l]),N=p?g:D,T=J8.test(N),z=x||T||!p&&E>0,P=(U,F)=>h(q=>({...q,[U]:F})),O=()=>{v(D),d(!0)},H=async()=>{S(!0),u(null);try{await f4(e,i,N,s),a()}catch(U){u(U instanceof Error?U.message:"Failed to save resolution")}finally{S(!1)}};return t.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A] text-gray-200",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 flex-1",title:i,children:i}),!C&&!_&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:`text-2xs ${E>0?"text-amber-400":"text-emerald-400"}`,children:E>0?f("git.cr.unresolved").replace("{n}",String(E)):f("git.cr.allResolved")}),t.jsx("button",{className:"text-2xs px-2 py-0.5 rounded-md border border-gray-600 text-gray-300 hover:bg-gray-800",onClick:()=>p?d(!1):O(),children:f(p?"git.cr.guided":"git.cr.manual")}),t.jsx("button",{className:"text-2xs px-2 py-0.5 rounded-md bg-accent text-white disabled:opacity-40",disabled:z,onClick:H,title:T?f("git.cr.markersRemain"):void 0,children:x?"…":f("git.cr.save")})]})]}),C?t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-gray-400",children:f("git.loadingDiff")}):_?t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-status-error",children:f("git.cr.loadFailed")}):p?t.jsx("textarea",{className:"flex-1 w-full bg-[#1A1A1A] text-gray-100 font-mono text-xs p-3 resize-none focus:outline-none",value:g,onChange:U=>v(U.target.value),spellCheck:!1}):j.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-gray-400",children:f("git.cr.noConflicts")}):t.jsx("div",{className:"flex-1 overflow-auto",children:m.map((U,F)=>U.kind==="text"?t.jsx($f,{lines:U.lines,tint:"text-gray-500"},F):t.jsxs("div",{className:"my-1 border-y border-gray-700",children:[t.jsx("div",{className:"flex items-center gap-1 px-3 py-1 bg-gray-800/60",children:["ours","theirs","both"].map(q=>t.jsx("button",{onClick:()=>P(F,q),className:`text-2xs px-2 py-0.5 rounded-md border transition-colors ${l[F]===q?"bg-accent text-white border-accent":"border-gray-600 text-gray-300 hover:bg-gray-700"}`,children:f(q==="ours"?"git.acceptOurs":q==="theirs"?"git.acceptTheirs":"git.cr.both")},q))}),t.jsxs("div",{className:l[F]==="theirs"?"opacity-40":"",children:[t.jsx("div",{className:"px-3 pt-1 text-2xs text-emerald-400",children:f("git.cr.ours")}),t.jsx($f,{lines:U.ours,tint:"text-gray-100 bg-emerald-500/10"})]}),t.jsxs("div",{className:l[F]==="ours"?"opacity-40":"",children:[t.jsx("div",{className:"px-3 pt-1 text-2xs text-sky-400",children:f("git.cr.theirs")}),t.jsx($f,{lines:U.theirs,tint:"text-gray-100 bg-sky-500/10"})]})]},F))})]})}const Pa=["#B08A3E","#4B8DFF","#7A8797","#5E748A","#8B8178","#667085","#78909C","#9A8F7F"];function Z8(e){const s=new Map;e.forEach((u,f)=>s.set(u.hash,f));const i=[],a=[];for(let u=0;u<e.length;u++){const f=e[u];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=Pa[m%Pa.length],l=[];for(let h=0;h<f.parentHashes.length;h++){const p=f.parentHashes[h],d=s.get(p);if(d===void 0)continue;let g=i.indexOf(p);if(g!==-1)l.push({fromLane:m,toLane:g,toRow:d,color:Pa[g%Pa.length]});else if(h===0)i[m]=p,l.push({fromLane:m,toLane:m,toRow:d,color:o});else{let v=i.indexOf(null);v===-1&&(v=i.length,i.push(null)),i[v]=p,l.push({fromLane:m,toLane:v,toRow:d,color:Pa[v%Pa.length]})}}a.push({lane:m,color:o,connections:l})}return a}function ez({refStr:e}){const s=e.startsWith("HEAD"),i=e.startsWith("origin/")||e.includes("remotes/"),a=e.startsWith("tag: ");let u=e,f="";return a?(u=e.replace("tag: ",""),f="bg-status-merged/10 text-status-merged"):s?(u=e.replace("HEAD -> ",""),f="bg-status-success/10 text-status-success font-semibold"):i?f="bg-status-running/10 text-status-running":f="bg-status-warning/10 text-status-warning",t.jsx("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${f}`,children:u})}const fi=32,$i=16,tz=4,nz=10;function sz({graphNodes:e,totalRows:s}){const a=(Math.min(nz,e.reduce((u,f)=>{const m=f.connections.reduce((o,l)=>Math.max(o,l.fromLane,l.toLane),0);return Math.max(u,f.lane,m)},0)+1)+1)*$i+8;return t.jsxs("svg",{width:a,height:s*fi,className:"shrink-0",style:{minWidth:a},children:[e.map((u,f)=>u.connections.map((m,o)=>{const l=m.fromLane*$i+$i/2+4,h=f*fi+fi/2,p=m.toLane*$i+$i/2+4,d=m.toRow*fi+fi/2;if(l===p)return t.jsx("line",{x1:l,y1:h,x2:p,y2:d,stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`);{const g=(h+d)/2;return t.jsx("path",{d:`M${l},${h} C${l},${g} ${p},${g} ${p},${d}`,fill:"none",stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`)}})),e.map((u,f)=>{const m=u.lane*$i+$i/2+4,o=f*fi+fi/2;return t.jsx("circle",{cx:m,cy:o,r:tz,fill:u.color,stroke:"white",strokeWidth:1.5},`dot-${f}`)})]})}function rz({projectId:e,projectName:s,onRefresh:i,busy:a,setBusy:u,branches:f,statusFiles:m,worktreePath:o}){const{t:l}=xt(),{confirm:h}=Yn(),[p,d]=y.useState(null),[g,v]=y.useState(""),[C,k]=y.useState(""),[x,S]=y.useState(null),_=()=>{d(null),v(""),k(""),S(null)},w=async O=>{u(!0),S(null);try{await O(),_(),i()}catch(H){S(H instanceof Error?H.message:"Error")}finally{u(!1)}},j=m.some(O=>O.index!==" "&&O.index!=="?"),R=({label:O,onClick:H,icon:U,badge:F})=>t.jsxs("button",{onClick:H,disabled:a,className:"flex flex-col items-center gap-0.5 px-2.5 py-1.5 rounded-md hover:bg-warm-50 transition-colors disabled:opacity-50 relative",title:O,children:[t.jsx("div",{className:"h-5 w-5 flex items-center justify-center text-warm-500",children:U}),t.jsx("span",{className:"text-2xs text-warm-600 whitespace-nowrap",children:O}),F!==void 0&&F>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:F})]}),E=({title:O,children:H})=>t.jsx(Dn,{open:!0,onClose:_,size:"sm",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated 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:O}),t.jsx("button",{onClick:_,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:[x&&t.jsx("p",{className:"text-status-error text-xs",children:x}),H]})]})}),D=f.filter(O=>!O.remote),N=f.find(O=>!O.remote&&O.current),T=m.length,z=(N==null?void 0:N.behind)??0,P=(N==null?void 0:N.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(R,{label:l("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:T}),t.jsx(R,{label:l("git.pull"),onClick:()=>w(()=>b1(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:z}),t.jsx(R,{label:l("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:P}),t.jsx(R,{label:l("git.fetch"),onClick:()=>w(()=>y1(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(R,{label:l("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(R,{label:l("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(R,{label:l("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(R,{label:l("git.discard"),onClick:async()=>{m.length!==0&&await h({message:l("git.confirmDiscard"),danger:!0})&&w(()=>b4(e,void 0,!0,o))},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(R,{label:l("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(K8,{open:p==="push",onClose:_,projectId:e,projectName:s,onPushed:i}),p==="commit"&&t.jsxs(E,{title:l("git.commit"),children:[t.jsx("textarea",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm resize-none focus:outline-none focus:ring-1 focus:ring-accent",rows:3,placeholder:l("git.commitMessage"),value:g,onChange:O=>v(O.target.value),autoFocus:!0}),t.jsxs("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!g.trim()||!j,onClick:()=>w(()=>v1(e,g.trim(),o)),children:[l("git.commit")," ",!j&&t.jsxs("span",{className:"text-xs opacity-70 ml-1",children:["(",l("git.staged"),": 0)"]})]})]}),p==="branch"&&t.jsxs(E,{title:l("git.newBranch"),children:[t.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:l("git.branchName"),value:g,onChange:O=>v(O.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||!g.trim(),onClick:()=>w(()=>w1(e,g.trim())),children:l("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:l("git.selectBranch")}),t.jsx("div",{className:"max-h-32 overflow-y-auto space-y-px",children:D.filter(O=>!O.current).map(O=>t.jsxs("div",{className:"flex items-center justify-between px-2 py-1 text-xs hover:bg-warm-50 rounded-md group",children:[t.jsx("button",{className:"truncate text-warm-600 hover:text-accent",onClick:()=>w(()=>ym(e,O.name)),children:O.name}),t.jsx("button",{className:"text-warm-300 hover:text-status-error opacity-0 group-hover:opacity-100 transition-opacity text-2xs",onClick:async()=>{await h({message:l("git.confirmDelete").replace("{name}",O.name),danger:!0})&&w(()=>bm(e,O.name))},children:l("git.delete")})]},O.name))})]})]}),p==="merge"&&t.jsxs(E,{title:l("git.merge"),children:[t.jsx("p",{className:"text-xs text-warm-500",children:l("git.selectBranch")}),t.jsx("div",{className:"max-h-48 overflow-y-auto space-y-px",children:D.filter(O=>!O.current).map(O=>t.jsx("button",{className:"w-full text-left px-3 py-2 text-sm hover:bg-warm-50 rounded-md text-warm-600 truncate",disabled:a,onClick:()=>w(()=>_1(e,O.name)),children:O.name},O.name))})]}),p==="stash"&&t.jsx(iz,{projectId:e,busy:a,exec:w,inputValue:g,setInputValue:v}),p==="tag"&&t.jsxs(E,{title:l("git.tag"),children:[t.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:l("git.tagName"),value:g,onChange:O=>v(O.target.value),autoFocus:!0}),t.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:l("git.tagMessage"),value:C,onChange:O=>k(O.target.value)}),t.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!g.trim(),onClick:()=>w(()=>S1(e,g.trim(),C.trim()||void 0)),children:l("git.create")})]})]})}function iz({projectId:e,busy:s,exec:i,inputValue:a,setInputValue:u}){const{t:f}=xt(),[m,o]=y.useState([]);return y.useEffect(()=>{v4(e).then(o).catch(()=>{})},[e]),t.jsx(Dn,{open:!0,onClose:()=>u(""),size:"sm",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated 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-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:f("git.stashMessage"),value:a,onChange:l=>u(l.target.value),autoFocus:!0}),t.jsx("button",{className:"btn-primary text-sm px-3 py-2",disabled:s,onClick:()=>i(()=>g4(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(l=>t.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 text-xs hover:bg-warm-50 rounded-md",children:[t.jsx("span",{className:"text-warm-600 truncate flex-1",children:l.message||`stash@{${l.index}}`}),t.jsx("button",{className:"text-accent hover:underline text-[11px] ml-2 shrink-0",disabled:s,onClick:()=>i(()=>x4(e,l.index)),children:f("git.stashPop")})]},l.index))}):t.jsx("p",{className:"text-xs text-warm-400 text-center",children:f("git.noStashes")})]})]})})}function Ey(e,s){if(e==="?"&&s==="?")return{label:"U",color:"text-warm-400",type:"untracked"};const a=e!==" "&&e!=="?",u=a?e:s;let f="text-accent",m=u;return u==="A"?f="text-status-success":u==="D"?f="text-status-error":u==="R"?f="text-status-merged":u==="C"?f="text-accent":(f="text-accent",m="M"),{label:m,color:f,type:a?"staged":"unstaged"}}function Ny({file:e,pane:s,selected:i,checked:a,onClick:u,onToggleCheck:f,onContextMenu:m}){const o=s==="staged"?Ey(e.index," "):Ey(" ",e.working_dir==="?"?"?":e.working_dir),l=s==="unstaged"&&e.index==="?"&&e.working_dir==="?"?{label:"U",color:"text-warm-400"}:o;return t.jsxs("div",{onClick:u,onContextMenu:m,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:h=>h.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-md text-[10px] font-mono font-bold ${s==="staged"?"bg-status-success/15":"bg-warm-200"} ${l.color}`,children:s==="staged"||l.label==="U"?"+":"−"}),t.jsx("span",{className:"truncate flex-1",title:e.path,children:e.path})]})}function az({diff:e,loading:s,file:i}){const{t:a}=xt();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 u=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}),u&&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(`
@@ -679,7 +679,7 @@ WARNING: This link could potentially be dangerous`)){const S=window.open();if(S)
679
679
  `)&&le(X),We.current=!0,W(!0)},be=y.useRef(De);be.current=De;const Re=()=>{var X,ne;We.current=!1,W(!1),(X=re.current)==null||X.clearDecorations(),ue({index:-1,count:0});try{(ne=T.current)==null||ne.focus()}catch{}},ct=y.useRef(Re);ct.current=Re;const tt=y.useRef(0),Ke=(X,ne,Se)=>{const fe=++tt.current,ie=Date.now();J({dataUrl:X,bytes:ne});const ke=()=>{const _e=Math.max(0,600-(Date.now()-ie));setTimeout(()=>{tt.current===fe&&J(null)},_e)};Se.then(ke,ke)},Le=y.useRef(Ke);Le.current=Ke;const{warning:$e}=Rs(),Ie=y.useRef($e);Ie.current=$e;const[it,vt]=y.useState(null),Ce=y.useRef(()=>{});y.useEffect(()=>{if(!it)return;const X=()=>vt(null),ne=Se=>{Se.key==="Escape"&&X()};return window.addEventListener("keydown",ne,!0),window.addEventListener("resize",X),window.addEventListener("scroll",X,!0),()=>{window.removeEventListener("keydown",ne,!0),window.removeEventListener("resize",X),window.removeEventListener("scroll",X,!0)}},[it]),y.useEffect(()=>{var ye;const X=N.current;if(!X)return;const ne=me=>{const nt=me.type;_.current&&nt==="session:terminal-input"||u(me)},Se=new Yz.Terminal({fontFamily:Ht,fontSize:l,lineHeight:1,cursorBlink:s,convertEol:!1,scrollback:5e3,theme:S.current??iu,minimumContrastRatio:Gy(S.current??iu),allowProposedApi:!0,macOptionIsMeta:!0}),fe=/Mac|iPhone|iPad|iPod/.test(navigator.platform);let ie=0;const ke=async()=>{var nt;if(_.current){console.debug("[paste] inputBlocked → ignored");return}if(!window.isSecureContext)return;if(ie=Date.now(),!w.current)try{const pt=await navigator.clipboard.read();for(const jt of pt){const Bt=jt.types.find(ze=>ze.startsWith("image/"));if(Bt){const ze=await jt.getType(Bt),ut=new FileReader;ut.onload=()=>{const _t=ut.result;console.debug("[paste] image via clipboard.read(), bytes=",ze.size);const Mt=G1(e,_t);Mt.catch(At=>console.warn("[paste] pasteImage failed:",At)),Le.current(_t,ze.size,Mt)},ut.readAsDataURL(ze);return}}}catch(pt){console.debug("[paste] clipboard.read() rejected, falling through:",pt)}let me=null;try{me=await navigator.clipboard.readText()}catch(pt){console.warn("[paste] clipboard.readText() failed:",pt)}if(me){const pt=me.includes(`
680
680
  `);console.debug("[paste] sending text, len=",me.length,"multiline=",pt),ne({type:"session:terminal-input",sessionId:e,input:_S(me)});return}try{const pt=await lL(e);if(pt.path){console.debug("[paste] empty browser clipboard, using OS file path:",pt.path),ne({type:"session:terminal-input",sessionId:e,input:pt.path});return}}catch(pt){console.debug("[paste] getClipboardImagePath failed:",pt)}console.warn("[paste] no content available (text empty, no image, no file path)"),(nt=Ie.current)==null||nt.call(Ie,"붙여넣을 내용을 클립보드에서 읽지 못했습니다. 우클릭 → 붙여넣기를 사용하세요.")};Se.attachCustomKeyEventHandler(me=>{var ut;if(me.type!=="keydown")return!0;const nt=fe?me.metaKey:me.ctrlKey,pt=fe?me.ctrlKey:me.metaKey,jt=nt&&!pt&&!me.altKey&&!me.shiftKey,Bt=nt&&!pt&&!me.altKey&&me.shiftKey,ze=me.key.toLowerCase();if(ze==="tab"&&(jt||Bt)&&j.current)return me.preventDefault(),j.current(Bt?"prev":"next"),!1;if(jt&&/^[1-9]$/.test(ze)&&R.current)return me.preventDefault(),R.current(Number(ze)-1),!1;if(ze==="f"&&jt)return me.preventDefault(),be.current(),!1;if(ze==="t"&&jt||ze==="r"&&Bt||ze==="f5"&&!me.ctrlKey&&!me.metaKey&&!me.altKey&&!me.shiftKey)return me.preventDefault(),!1;if(ze==="d"&&Bt&&E.current)return me.preventDefault(),E.current(),!1;if(Bt&&(["a","p","o","m","x","z"].includes(ze)||ze.startsWith("arrow")))return me.preventDefault(),!1;if(jt&&ze==="c"){const _t=Se.getSelection();return _t?(me.preventDefault(),(ut=navigator.clipboard)==null||ut.writeText(_t).catch(()=>{}),Se.clearSelection(),!1):!fe}if(jt&&ze==="v"||me.altKey&&!me.ctrlKey&&!me.metaKey&&!me.shiftKey&&ze==="v")return me.preventDefault(),ke(),!1;if((me.ctrlKey||me.metaKey)&&!me.altKey){if(me.key==="+"||me.key==="=")return me.preventDefault(),Zo(e,1),!1;if(me.key==="-"||me.key==="_")return me.preventDefault(),Zo(e,-1),!1}return!0});const _e=new Jz.FitAddon;Se.loadAddon(_e),Se.open(X),T.current=Se,z.current=_e;try{const me=new $y.CanvasAddon;Se.loadAddon(me),P.current=me}catch{P.current=null}const st=new eO.SearchAddon;Se.loadAddon(st),re.current=st;const Ze=st.onDidChangeResults(({resultIndex:me,resultCount:nt})=>{Ve.current({index:me,count:nt})}),he=()=>{We.current&&ct.current()};X.addEventListener("focusin",he),Se.attachCustomWheelEventHandler(me=>!me.ctrlKey&&!me.metaKey?!0:(me.preventDefault(),me.__zoomHandled=!0,me.deltaY!==0&&Zo(e,me.deltaY<0?1:-1),!1));const de=me=>{if(me.ctrlKey||me.metaKey){if(me.preventDefault(),me.stopPropagation(),me.deltaY===0||me.__zoomHandled)return;Zo(e,me.deltaY<0?1:-1);return}me.stopPropagation()};X.addEventListener("wheel",de,{passive:!1});const ce=window.electronAPI,ee=(ye=ce==null?void 0:ce.onTerminalZoom)==null?void 0:ye.call(ce,me=>{var pt;const nt=X.matches(":hover");(pt=ce.imeLog)==null||pt.call(ce,{reason:"zoom:recv",dir:me,hovered:nt,path:window.location.pathname}),nt&&Zo(e,me==="in"?1:-1)});Ce.current=()=>{ke()};const Ne=me=>{me.preventDefault(),vt({x:me.clientX,y:me.clientY,hasSelection:Se.hasSelection()})};X.addEventListener("contextmenu",Ne);try{_e.fit()}catch{}if(d){const me=document.activeElement;if(!(!!me&&(me.tagName==="INPUT"||me.tagName==="TEXTAREA"||me.tagName==="SELECT"||me.isContentEditable))&&(me===null||me===document.body))try{Se.focus()}catch{}}const je=()=>{const me=Se.cols,nt=Se.rows;me===O.current.cols&&nt===O.current.rows||(O.current={cols:me,rows:nt},u({type:"session:resize",sessionId:e,cols:me,rows:nt}))};$.current=je;const Me=f(e,me=>{try{Se.write(me)}catch{}}),Te=m(me=>{me.type==="session:replay-end"&&me.sessionId===e&&B(!1)}),et=()=>Date.now()-ie<300,Ye=()=>w.current,mt=me=>Y.current(me),bt=(me,nt,pt)=>Le.current(me,nt,pt),yt=iO()?hO({container:X,term:Se,sessionId:e,sendMessage:ne}):dO({container:X,term:Se,sessionId:e,sendMessage:ne,isPasteAlreadyHandled:et,isImagePasteDisabled:Ye,onComposingChange:mt,onImagePasted:bt}),Et=100;let Xe=null,lt=0,Oe=!1;const ae={cols:Se.cols,rows:Se.rows},ve=new ResizeObserver(()=>{if(Xe!==null)return;const me=Math.max(0,Et-(performance.now()-lt));Xe=setTimeout(()=>{Xe=null,requestAnimationFrame(()=>{var pt;lt=performance.now();const nt=X.getBoundingClientRect();if(!(nt.width===0||nt.height===0)){try{_e.fit(),(Se.cols!==ae.cols||Se.rows!==ae.rows)&&(ae.cols=Se.cols,ae.rows=Se.rows,Se.refresh(0,Se.rows-1))}catch{}!Oe&&Se.cols>=20&&Se.rows>=5&&(Oe=!0,(pt=q.current)==null||pt.call(q,Se.cols,Se.rows)),H.current&&clearTimeout(H.current),H.current=setTimeout(je,150)}})},me)});return ve.observe(X),()=>{var me;ve.disconnect(),Xe!==null&&clearTimeout(Xe),H.current&&clearTimeout(H.current),U.current&&clearTimeout(U.current),X.removeEventListener("wheel",de),ee==null||ee(),X.removeEventListener("contextmenu",Ne),vt(null),yt(),Me(),Te();try{u({type:"session:unsubscribe",sessionId:e})}catch{}X.removeEventListener("focusin",he),Ze.dispose(),re.current=null,(me=P.current)==null||me.dispose(),P.current=null,Se.dispose(),T.current=null,z.current=null,$.current=null,F.current=!1}},[e]),y.useEffect(()=>{if(!i||F.current)return;F.current=!0;const X=T.current;X&&X.cols>0&&X.rows>0&&(O.current={cols:0,rows:0},u({type:"session:resize",sessionId:e,cols:X.cols,rows:X.rows})),u({type:"session:subscribe",sessionId:e})},[i,e,u]),y.useEffect(()=>{T.current&&(T.current.options.cursorBlink=s)},[s]),y.useEffect(()=>{var fe;if(!d)return;const X=document.activeElement;if(!(!(!!X&&X.classList.contains("xterm-helper-textarea"))&&!!X&&(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.tagName==="SELECT"||X.isContentEditable)))try{(fe=T.current)==null||fe.focus()}catch{}},[d]),y.useEffect(()=>{const X=T.current,ne=z.current;if(!X||!ne||X.options.fontSize===l)return;if(X.options.fontSize=l,P.current){try{P.current.dispose()}catch{}P.current=null;try{const fe=new $y.CanvasAddon;X.loadAddon(fe),P.current=fe}catch{}}if(X.buffer.active.type==="alternate"){U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{var fe;(fe=D.current)==null||fe.call(D)},500);return}try{ne.fit(),X.refresh(0,X.rows-1)}catch{}X.cols===O.current.cols&&X.rows===O.current.rows||(U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{var fe;(fe=$.current)==null||fe.call($)},300))},[l,e]),y.useEffect(()=>{const X=T.current;if(X){X.options.theme=h??iu,X.options.minimumContrastRatio=Gy(h??iu);try{X.refresh(0,X.rows-1)}catch{}}},[h]),y.useEffect(()=>{if(!Q)return;const X=re.current;if(!X)return;const ne=setTimeout(()=>{oe?X.findNext(oe,{...Zf,incremental:!0}):(X.clearDecorations(),ue({index:-1,count:0}))},120);return()=>clearTimeout(ne)},[oe,Q]),y.useEffect(()=>{var X;Q&&((X=Z.current)==null||X.select())},[Q]);const Ue=(h==null?void 0:h.background)??Ge.bg,we=()=>{var X;oe&&((X=re.current)==null||X.findNext(oe,Zf))},Pe=()=>{var X;oe&&((X=re.current)==null||X.findPrevious(oe,Zf))};return t.jsxs("div",{style:{position:"relative",background:Ue,padding:12,height:o,width:"100%",boxSizing:"border-box",overflow:"hidden"},children:[K&&i&&t.jsx("div",{style:{position:"absolute",top:8,right:12,fontFamily:Ht,fontSize:11,color:Ge.dim,zIndex:1,pointerEvents:"none"},children:"loading history…"}),t.jsx("div",{ref:N,"data-term-container":!0,style:{height:"100%",width:"100%"}}),Q&&t.jsxs("div",{style:{position:"absolute",top:8,right:12,zIndex:5,display:"flex",alignItems:"center",gap:6,padding:"4px 6px",background:"rgba(0,0,0,0.85)",border:`1px solid ${Ge.separator}`,borderRadius:6,fontFamily:Ht,fontSize:12,boxShadow:"0 4px 16px rgba(0,0,0,0.5)"},children:[t.jsx("input",{ref:Z,value:oe,onChange:X=>le(X.target.value),onKeyDown:X=>{X.key==="Enter"?(X.preventDefault(),X.shiftKey?Pe():we()):X.key==="Escape"&&(X.preventDefault(),Re())},placeholder:"검색",spellCheck:!1,style:{width:160,background:"transparent",border:"none",outline:"none",color:Ge.bright,fontFamily:Ht,fontSize:12}}),t.jsx("span",{style:{color:Ge.dim,minWidth:44,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:oe?ge.count>0?`${ge.index+1}/${ge.count}`:"0/0":""}),[{label:"↑",title:"이전 (Shift+Enter)",onClick:Pe},{label:"↓",title:"다음 (Enter)",onClick:we},{label:"×",title:"닫기 (Esc)",onClick:Re}].map(X=>t.jsx("button",{type:"button",title:X.title,onClick:X.onClick,className:"px-1.5 rounded-md hover:bg-white/10",style:{color:Ge.bright,lineHeight:"18px"},children:X.label},X.label))]}),(A||G)&&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:[G&&t.jsxs("div",{style:{padding:4,background:"rgba(0,0,0,0.72)",border:`1px solid ${Ge.separator}`,borderRadius:4,maxWidth:"100%"},children:[t.jsx("img",{src:G.dataUrl,alt:"",style:{display:"block",maxWidth:220,maxHeight:140,borderRadius:2}}),t.jsxs("div",{style:{fontFamily:Ht,fontSize:11,color:Ge.dim,marginTop:3},children:["이미지 붙여넣음 · ",sO(G.bytes)]})]}),A&&t.jsx("div",{style:{maxWidth:"100%",padding:"3px 8px",background:"rgba(0,0,0,0.72)",border:`1px solid ${Ge.separator}`,borderRadius:4,fontFamily:Ht,fontSize:Math.max(12,l),color:Ge.bright,lineHeight:1.3,whiteSpace:"pre",overflow:"hidden",textOverflow:"ellipsis"},children:A})]}),it&&cn.createPortal((()=>{const Se=Math.max(8,Math.min(it.x,window.innerWidth-184-8)),fe=Math.max(8,Math.min(it.y,window.innerHeight-116-8)),ie=()=>vt(null),ke=()=>{var he,de;const Ze=((he=T.current)==null?void 0:he.getSelection())??"";Ze&&((de=navigator.clipboard)==null||de.writeText(Ze).catch(()=>{})),ie()},_e=()=>{Ce.current(),ie()},st=()=>{var Ze;(Ze=T.current)==null||Ze.selectAll(),ie()};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"fixed",inset:0,zIndex:2147483646},onMouseDown:ie,onContextMenu:Ze=>{Ze.preventDefault(),ie()}}),t.jsxs("div",{role:"menu",style:{position:"fixed",left:Se,top:fe,zIndex:2147483647,minWidth:168,background:Ge.bg,border:`1px solid ${Ge.separator}`,borderRadius:6,padding:4,fontFamily:Ht,fontSize:13,boxShadow:"0 8px 24px rgba(0,0,0,0.5)"},children:[t.jsx("button",{type:"button",disabled:!it.hasSelection,onClick:ke,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10 disabled:opacity-40 disabled:cursor-not-allowed",style:{color:Ge.bright},children:"복사"}),t.jsx("button",{type:"button",onClick:_e,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10",style:{color:Ge.bright},children:"붙여넣기"}),t.jsx("button",{type:"button",onClick:st,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10",style:{color:Ge.bright},children:"전체 선택"})]})]})})(),document.body)]})}function iO(){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 wu=[12593,12594,12596,12599,12600,12601,12609,12610,12611,12613,12614,12615,12616,12617,12618,12619,12620,12621,12622],SS=[12623,12624,12625,12626,12627,12628,12629,12630,12631,12632,12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643],Ky=[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 kS(e){return e>=12593&&e<=12622}function CS(e){return e>=12623&&e<=12643}function aO(e){return kS(e)||CS(e)}function oO(e){return e>=44032&&e<=55203}function lO(){return{cho:-1,jung:-1,jong:0}}function Fp(e){return e.cho<0&&e.jung<0&&e.jong===0}function Dr(e){return Fp(e)?"":e.cho>=0&&e.jung>=0?String.fromCharCode(44032+(e.cho*21+e.jung)*28+e.jong):e.cho>=0?String.fromCharCode(wu[e.cho]):e.jung>=0?String.fromCharCode(SS[e.jung]):""}function Vy(e){const s=Dr(e);return e.cho=-1,e.jung=-1,e.jong=0,s}function cO(e,s){if(CS(s)){const i=SS.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=Dr(e);return e.jung=i,m}if(e.jong===0){const m=Dr(e);return e.cho=-1,e.jung=i,e.jong=0,m}const a=Ky[e.jong],u=wu.indexOf(a);e.jong=0;const f=Dr(e);return u>=0?(e.cho=u,e.jung=i,e.jong=0):(e.cho=-1,e.jung=i,e.jong=0),f}if(kS(s)){const i=wu.indexOf(s),a=Ky.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(wu[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=Dr(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=Dr(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,f}const u=Dr(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,i<0?u+String.fromCharCode(s):u}return""}function uO(e,s){const i=Dr(e),a=s-44032;return e.cho=Math.floor(a/588),e.jung=Math.floor(a/28)%21,e.jong=a%28,i}function Yy(e){return Fp(e)?!1:(e.cho=-1,e.jung=-1,e.jong=0,!0)}function dO({container:e,term:s,sessionId:i,sendMessage:a,isPasteAlreadyHandled:u,isImagePasteDisabled:f,onComposingChange:m,onImagePasted:o}){let l=!1;const h=T=>{try{m==null||m(T)}catch{}};let p=null;const d=(T,z={})=>{var P,O;try{(O=(P=window.electronAPI)==null?void 0:P.imeLog)==null||O.call(P,{reason:T,path:window.location.pathname,...z})}catch{}},g=(T=!1)=>{try{const z=e.querySelector(".xterm-helper-textarea"),P=e.querySelector(".xterm-screen");if(!z||!P){T||d("pos:no-dom",{hasHelper:!!z,hasScreen:!!P});return}const O=s.cols,H=s.rows;if(O<=0||H<=0){T||d("pos:no-grid",{cols:O,rows:H});return}const U=P.getBoundingClientRect();if(U.width===0||U.height===0){T||d("pos:zero-screen",{w:U.width,h:U.height});return}const F=U.width/O,q=U.height/H,$=s.buffer.active,K=Math.min($.cursorX,O-1),B=Math.max(0,Math.min($.cursorY,H-1));z.style.left=`${K*F}px`,z.style.top=`${B*q}px`,z.style.width=`${Math.max(F,1)}px`,z.style.height=`${Math.max(q,1)}px`,T||d("pos:applied",{cursorX:K,cursorY:B,left:K*F,top:B*q})}catch{}};g();let v=0;const C=()=>{v||(v=requestAnimationFrame(()=>{v=0,g(!0)}))},k=s.onCursorMove(C),x=()=>{var T;l=!0,g(),h("");try{const z=document.activeElement,P=e.querySelector(".xterm-helper-textarea"),O=P==null?void 0:P.getBoundingClientRect();d("compositionstart",{activeTag:z==null?void 0:z.tagName,activeClass:z==null?void 0:z.className,activeIsHelper:!!z&&((T=z.classList)==null?void 0:T.contains("xterm-helper-textarea")),helperStyleLeft:P==null?void 0:P.style.left,helperStyleTop:P==null?void 0:P.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{}},S=T=>{h(T.data??""),d("compositionupdate",{data:T.data??""})},_=T=>{l=!1,h("");const z=T.data;d("compositionend",{data:z??"",sent:!!z}),z&&(p=z,a({type:"session:terminal-input",sessionId:i,input:z}))},w=T=>{var O,H;if(u()){T.preventDefault();return}const z=(O=T.clipboardData)==null?void 0:O.items;if(z&&!(f!=null&&f())){for(let U=0;U<z.length;U++)if(z[U].type.startsWith("image/")){T.preventDefault();const F=z[U].getAsFile();if(!F)return;const q=new FileReader;q.onload=()=>{const $=q.result;console.debug("[paste-fallback] image via paste event, bytes=",F.size);const K=G1(i,$,F.name);K.catch(B=>console.warn("[paste-fallback] pasteImage failed:",B)),o==null||o($,F.size,K)},q.readAsDataURL(F);return}}const P=(H=T.clipboardData)==null?void 0:H.getData("text/plain");if(P){T.preventDefault();const U=P.includes(`
681
681
  `);console.debug("[paste-fallback] sending text, len=",P.length,"multiline=",U),a({type:"session:terminal-input",sessionId:i,input:_S(P)})}else console.debug("[paste-fallback] paste event had no usable text/image")},j=T=>{var U,F;const z=(U=T.dataTransfer)==null?void 0:U.files;if(!z||z.length===0)return;T.preventDefault();const P=(F=window.electronAPI)==null?void 0:F.getDroppedFilePath;if(!P)return;const O=[];for(let q=0;q<z.length;q++){const $=P(z[q]);$&&O.push($)}const H=nO(O);H&&a({type:"session:terminal-input",sessionId:i,input:H})},R=T=>{var z,P;(P=(z=T.dataTransfer)==null?void 0:z.types)!=null&&P.includes("Files")&&(T.preventDefault(),T.dataTransfer.dropEffect="copy")},E=()=>{if(l)return;Ip(()=>{try{s.focus()}catch{}})&&d("focus-rescue")},D=T=>{var z,P;d("keydown",{key:T.key,composing:l,activeIsHelper:!!((P=(z=document.activeElement)==null?void 0:z.classList)!=null&&P.contains("xterm-helper-textarea")),hasFocus:document.hasFocus()}),document.hasFocus()||E()};e.addEventListener("keydown",D,!0),e.addEventListener("compositionstart",x,!0),e.addEventListener("compositionupdate",S,!0),e.addEventListener("compositionend",_,!0),e.addEventListener("paste",w,!0),e.addEventListener("dragover",R),e.addEventListener("drop",j);const N=s.onData(T=>{if(!l){if(p!==null&&T===p){p=null;return}p=null,a({type:"session:terminal-input",sessionId:i,input:T})}});return()=>{N.dispose(),k.dispose(),v&&cancelAnimationFrame(v),e.removeEventListener("keydown",D,!0),e.removeEventListener("compositionstart",x,!0),e.removeEventListener("compositionupdate",S,!0),e.removeEventListener("compositionend",_,!0),e.removeEventListener("paste",w,!0),e.removeEventListener("dragover",R),e.removeEventListener("drop",j),h("")}}function hO({container:e,term:s,sessionId:i,sendMessage:a}){const u=e.querySelector(".xterm-helper-textarea");let f="",m=0;u&&(f=u.style.display,m=u.tabIndex,u.style.display="none",u.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:Ht,fontSize:"16px",lineHeight:"1.2",resize:"none",overflow:"hidden",whiteSpace:"pre",caretColor:"rgba(255,255,255,0.001)",zIndex:"5"});const l=()=>{Object.assign(o.style,{inset:"0",left:"auto",top:"auto",width:"100%",height:"100%",color:"transparent"})},h=()=>{const E=e.querySelector(".xterm-screen");if(!E)return;const D=s.cols,N=s.rows;if(D<=0||N<=0)return;const T=E.clientWidth/D,z=E.clientHeight/N,P=s.buffer.active.cursorX,O=s.buffer.active.cursorY,H=E.getBoundingClientRect(),U=e.getBoundingClientRect();Object.assign(o.style,{inset:"auto",left:`${H.left-U.left+P*T}px`,top:`${H.top-U.top+O*z}px`,width:`${Math.max(T*30,240)}px`,height:`${Math.max(z,20)}px`,color:Ge.text})};l(),e.appendChild(o);let p=!1;const d=lO();let g=null;const v=()=>{g&&(clearTimeout(g),g=null)},C=E=>{E&&a({type:"session:terminal-input",sessionId:i,input:E})},k=()=>{const E=Vy(d);E&&C(E)},x=()=>{const E=Dr(d);o.value=E,E?h():l()},S=()=>{v(),g=setTimeout(()=>{g=null,k(),o.value="",l()},600)},_=()=>{p=!0,v(),k(),h()},w=E=>{p=!1,E.data&&C(E.data),o.value="",l()};o.addEventListener("compositionstart",_),o.addEventListener("compositionend",w);const j=E=>{if(p)return;const D=E;switch(D.inputType){case"insertCompositionText":case"insertFromComposition":return;case"deleteContentBackward":v(),Yy(d)?x():(C(""),o.value="",l());return;case"insertLineBreak":case"insertParagraph":v(),k(),C("\r"),o.value="",l();return;default:if(!D.data){x();return}v();let N="";for(const T of D.data){const z=T.codePointAt(0);aO(z)?N+=cO(d,z):oO(z)?N+=uO(d,z):(N+=Vy(d),N+=T)}C(N),x(),Fp(d)||S()}};o.addEventListener("input",j);const R=E=>{if(p||E.isComposing)return;let D=null;switch(E.key){case"Enter":D="\r";break;case"Backspace":D="";break;case"Tab":D=" ";break;case"Escape":D="\x1B";break;case"ArrowUp":D="\x1B[A";break;case"ArrowDown":D="\x1B[B";break;case"ArrowRight":D="\x1B[C";break;case"ArrowLeft":D="\x1B[D";break;case"Home":D="\x1B[H";break;case"End":D="\x1B[F";break}if(D){if(E.preventDefault(),v(),E.key==="Backspace"){if(Yy(d)){x();return}}else k();C(D),o.value="",l();return}if(E.ctrlKey&&!E.metaKey&&!E.altKey&&E.key.length===1){const N=E.key.toUpperCase().charCodeAt(0);N>=64&&N<=95&&(E.preventDefault(),v(),k(),C(String.fromCharCode(N-64)),o.value="",l())}};return o.addEventListener("keydown",R),()=>{v(),k(),o.remove(),u&&(u.style.display=f,u.tabIndex=m)}}function fO({sessionId:e,onClose:s,projectId:i,onEvent:a,sendMessage:u}){const{t:f}=xt(),[m,o]=y.useState([]),[l,h]=y.useState(!0),[p,d]=y.useState(null),[g,v]=y.useState(!1),[C,k]=y.useState(null),[x,S]=y.useState(""),[_,w]=y.useState(!1),[j,R]=y.useState(0),[E,D]=y.useState([]),[N,T]=y.useState(null),[z,P]=y.useState(!1),[O,H]=y.useState({from:null,now:null}),U=y.useRef(new Map),F=y.useCallback(()=>R(K=>K+1),[]);y.useEffect(()=>{if(!(!u||!i))return u({type:"git:watch",projectId:i}),()=>u({type:"git:unwatch",projectId:i})},[u,i]),y.useEffect(()=>{if(!(!a||!i))return a(K=>{K.type==="git:changed"&&K.projectId===i&&F()})},[a,i,F]),y.useEffect(()=>{let K=!1;return Z3(e).then(B=>{K||D(B.snapshots??[])}).catch(()=>{K||D([])}),()=>{K=!0}},[e,j]),y.useEffect(()=>{let K=!1;return v(!0),J3(e,N??void 0).then(B=>{if(K)return;h(B.available),d(B.reason??null);const A=B.available&&B.files?B.files.map(I=>({path:I.path,status:I.status,additions:I.insertions,deletions:I.deletions})):[];o(A),U.current.clear(),H({from:N,now:B.now??null}),k(I=>I&&A.some(Y=>Y.path===I)?I:A.length>0?A[0].path:null)}).catch(()=>{K||(h(!1),d("error"),o([]))}).finally(()=>{K||v(!1)}),()=>{K=!0}},[e,N,j]),y.useEffect(()=>{if(!C){S("");return}const K=`${O.now??""}:${C}`,B=U.current.get(K);if(B!==void 0){S(B),w(!1);return}let A=!1;return w(!0),S(""),Q3(e,C,O.from??void 0,O.now??void 0).then(I=>{if(A)return;const Y=I.available&&I.diff?I.diff:"";U.current.set(K,Y),S(Y)}).catch(()=>{A||S("")}).finally(()=>{A||w(!1)}),()=>{A=!0}},[e,C,O]);const q=y.useCallback(()=>{P(!0),eL(e).then(K=>{if(K.available&&K.snapshots){D(K.snapshots);const B=K.snapshots[K.snapshots.length-1];B&&T(B.sha)}}).catch(()=>{}).finally(()=>P(!1))},[e]),$=K=>{const B=new Date(K);return Number.isNaN(B.getTime())?K:B.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})};return t.jsxs("div",{className:"h-full flex flex-col bg-warm-50",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-warm-100 shrink-0",children:[t.jsx("span",{className:"text-xs font-semibold text-warm-600",children:f("session.diff.title")||"Diff"}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("button",{onClick:q,disabled:z||!l,title:f("session.diff.capture")||"Capture snapshot",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500 disabled:opacity-40",children:t.jsx(O5,{size:14,className:z?"animate-pulse":""})}),t.jsx("button",{onClick:F,title:f("common.refresh")||"Refresh",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500",children:t.jsx(Ku,{size:14,className:g?"animate-spin":""})}),t.jsx("button",{onClick:s,title:f("common.close")||"Close",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500",children:t.jsx(Jt,{size:14})})]})]}),E.length>0&&t.jsxs("div",{className:"flex items-center gap-1 px-3 py-1.5 border-b border-warm-100 overflow-x-auto shrink-0",children:[t.jsx(Xy,{active:N===null,onClick:()=>T(null),label:f("session.diff.pageStart")||"From start"}),E.map(K=>t.jsx(Xy,{active:N===K.sha,onClick:()=>T(K.sha),label:`#${K.seq} ${$(K.at)}`},K.sha))]}),l?t.jsxs("div",{className:"flex-1 flex min-h-0",children:[t.jsx("div",{className:"w-2/5 min-w-[180px] max-w-[320px] border-r border-warm-100 overflow-hidden",children:t.jsx(nd,{files:m,loading:g,selectedFile:C,onFileClick:k})}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(oo,{diff:x,loading:_,selectedFile:C})})]}):t.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:p==="not-git"?f("session.diff.notGit")||"Not a git repository":f("session.diff.unavailable")||"Diff unavailable"})})]})}function Xy({active:e,onClick:s,label:i}){return t.jsx("button",{onClick:s,className:`px-2 py-0.5 rounded-md text-[11px] whitespace-nowrap shrink-0 ${e?"bg-warm-600 text-white":"bg-warm-100 text-warm-600 hover:bg-warm-200"}`,children:i})}const mO={presetId:wS},kl=new Map,Ua=new Map;function jS(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);kl.delete(s);const i=Ua.get(s);if(i){const u=Wm(s);i.forEach(f=>f(u))}});function pO(e){return typeof e!="string"?!1:e==="custom"||e in Hn}function Wm(e){const s=kl.get(e);if(s!==void 0)return s;let i=mO;try{const a=localStorage.getItem(jS(e));if(a!==null){const u=JSON.parse(a);u&&pO(u.presetId)&&(i={presetId:u.presetId,custom:u.custom&&typeof u.custom=="object"?u.custom:void 0})}}catch{}return kl.set(e,i),i}function gO(e,s){const i=kl.get(e);if(i&&i.presetId===s.presetId&&xO(i.custom,s.custom))return;kl.set(e,s);try{localStorage.setItem(jS(e),JSON.stringify(s))}catch{}const a=Ua.get(e);a&&a.forEach(u=>u(s))}function xO(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 vO(e){if(e.presetId!=="custom")return qy(e.presetId).theme;const s=qy(wS).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 ES(e){const[s,i]=y.useState(()=>Wm(e));y.useEffect(()=>{i(Wm(e));let f=Ua.get(e);return f||(f=new Set,Ua.set(e,f)),f.add(i),()=>{const m=Ua.get(e);m&&(m.delete(i),m.size===0&&Ua.delete(e))}},[e]);const a=y.useCallback(f=>gO(e,f),[e]),u=y.useMemo(()=>vO(s),[s]);return[s,u,a]}function NS({session:e,visible:s,intent:i,intentNonce:a,onClose:u,sendMessage:f,subscribeBinary:m,onEvent:o,onCycleTab:l,onSelectTab:h,remountKey:p=0}){const{t:d}=xt(),g=e.status==="running"||i==="start"||i==="resume"?"pendingFit":"replay-only",[v,C]=y.useState(g),[k,x]=y.useState(null),[S,_]=y.useState(!1),[w,j]=y.useState(480),R=!!e.is_git_repo,E=y.useRef(null),D=y.useCallback(be=>{be.preventDefault();const Re=E.current;if(!Re)return;const ct=Ke=>{const Le=Re.getBoundingClientRect(),$e=240,Ie=Math.max($e,Le.width-200);j(Math.min(Ie,Math.max($e,Le.right-Ke.clientX)))},tt=()=>{window.removeEventListener("mousemove",ct),window.removeEventListener("mouseup",tt),document.body.style.cursor="",document.body.style.userSelect=""};window.addEventListener("mousemove",ct),window.addEventListener("mouseup",tt),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[N,T]=y.useState(0),z=y.useCallback(()=>T(be=>be+1),[]),P=y.useRef(null),O=y.useRef(!1),H=y.useRef(a),[U,F]=y.useState(null),[q,$]=y.useState(null),[K,B]=y.useState(!1),[A,I]=y.useState(null),[Y,G]=y.useState(null),J=y.useRef(e.status==="running");y.useEffect(()=>{e.status==="running"&&v!=="subscribed"&&v!=="starting"&&v!=="pendingFit"&&(J.current=!0,C("subscribed"))},[e.status,v]),y.useEffect(()=>{if(e.status==="running"||!J.current||v!=="subscribed"&&v!=="stopping")return;const be=setTimeout(()=>u(),300);return()=>clearTimeout(be)},[e.status,v,u]);const re=y.useCallback(async()=>{const be=P.current;if(be&&!O.current){O.current=!0,C("starting"),x(null),G(null);try{const Re=await sL(e.id,be,i==="resume"?{continueSession:!0}:void 0);C("subscribed"),Re.pendingInitialPrompt?(F(Re.pendingInitialPromptLength??0),$(null),B(!1)):(F(null),$(null))}catch(Re){const ct=Re instanceof Error?Re.message:String(Re);x(ct),C("error")}finally{O.current=!1}}},[e.id,i]),Z=y.useCallback(async()=>{if(K){B(!1);return}if(B(!0),q===null)try{const be=await rL(e.id);$(be.prompt??"")}catch(be){G(be instanceof Error?be.message:String(be))}},[K,q,e.id]),Q=y.useCallback(async()=>{if(!A){I("send"),G(null);try{await iL(e.id),F(null),$(null),B(!1)}catch(be){G(be instanceof Error?be.message:String(be))}finally{I(null)}}},[A,e.id]),W=y.useCallback(async()=>{if(!A){I("skip"),G(null);try{await aL(e.id),F(null),$(null),B(!1)}catch(be){G(be instanceof Error?be.message:String(be))}finally{I(null)}}},[A,e.id]);y.useEffect(()=>{if(a===H.current)return;H.current=a,(i==="start"||i==="resume")&&v==="replay-only"&&e.status!=="running"&&(P.current?re():C("pendingFit"))},[a,i,v,e.status,re]);const oe=y.useCallback(()=>{P.current?re():C("pendingFit")},[re]),le=y.useCallback((be,Re)=>{P.current={cols:be,rows:Re},v==="pendingFit"&&(e.status==="running"?(J.current=!0,C("subscribed")):re())},[v,re,e.status]),ge=e.status==="running",ue=v==="subscribed",[Ve]=A1(e.id),[,We]=ES(e.id),De=v==="starting"||v==="pendingFit"?t.jsxs("div",{style:{...au,pointerEvents:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Tr,{size:14,style:{animation:"spin 1s linear infinite",color:Ge.dim}}),t.jsx("span",{style:{color:Ge.dim,fontFamily:Ht,fontSize:12},children:d("session.starting")||"starting…"})]}),t.jsx("span",{style:{color:Ge.dim,fontFamily:Ht,fontSize:10,marginTop:6},children:d("session.starting.typeAhead")||"type-ahead is captured and replayed once ready"})]}):v==="stopping"?t.jsx("div",{style:{...au,pointerEvents:"none"},children:t.jsx("span",{style:{color:Ge.dim,fontFamily:Ht,fontSize:12},children:d("session.stopping")||"stopping…"})}):v==="replay-only"?t.jsx("div",{style:au,children:t.jsxs("button",{onClick:oe,style:{display:"flex",alignItems:"center",gap:8,fontFamily:Ht,fontSize:14,color:Ge.bright,background:"transparent",border:`1px solid ${Ge.separator}`,padding:"10px 22px",borderRadius:6,cursor:"pointer"},children:[t.jsx(Mr,{size:16})," ",d("session.startInWindow")||"Start"]})}):v==="error"?t.jsxs("div",{style:au,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:Ge.error,fontFamily:Ht,fontSize:12,marginBottom:8},children:[t.jsx(s1,{size:14})," ",d("session.startFailed")||"failed to start"]}),k&&t.jsx("div",{style:{color:Ge.dim,fontFamily:Ht,fontSize:11,marginBottom:8,maxWidth:360,textAlign:"center",wordBreak:"break-word"},children:k}),t.jsx("button",{onClick:()=>{re()},style:{fontFamily:Ht,fontSize:12,color:Ge.bright,background:"transparent",border:`1px solid ${Ge.separator}`,padding:"4px 12px",borderRadius:4,cursor:"pointer"},children:d("common.retry")||"Retry"})]}):null;return t.jsxs("div",{ref:E,style:{display:s?"flex":"none",flexDirection:"row",position:"absolute",inset:0,background:Ge.bg},children:[t.jsxs("div",{style:{position:"relative",flex:1,minWidth:0,height:"100%"},children:[t.jsx(rO,{sessionId:e.id,isRunning:ge,subscribed:ue,onFitted:le,sendMessage:f,subscribeBinary:m,onEvent:o,fontSize:Ve,theme:We,inputBlocked:U!==null,autoFocusOnMount:s,onRequestRefresh:z,disableImagePaste:e.cli_tool==="raw-shell",onCycleTab:l,onSelectTab:h,onToggleDiff:()=>{R&&_(be=>!be)}},`${p}:${N}`),De,R&&!S&&t.jsxs("button",{onClick:()=>_(!0),title:`${d("session.diff.title")||"Diff"} (${navigator.platform.startsWith("Mac")?"⌘":"Ctrl"}+Shift+D)`,style:{position:"absolute",top:4,right:8,zIndex:1002,display:"inline-flex",alignItems:"center",gap:4,fontFamily:Ht,fontSize:10,color:Ge.dim,background:"rgba(20,20,28,0.7)",border:`1px solid ${Ge.separator}`,padding:"2px 8px",borderRadius:4,cursor:"pointer"},children:[t.jsx(DE,{size:12})," Diff"]}),U!==null&&t.jsxs("div",{style:bO,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(eE,{"aria-hidden":!0,size:14,style:{color:Ge.info}}),t.jsxs("span",{style:{flex:1},children:[d("session.initialPrompt.ready")||"Initial prompt ready",t.jsxs("span",{style:{color:Ge.dim,marginLeft:8},children:[U.toLocaleString()," chars"]}),t.jsx("div",{style:{color:Ge.warning,fontSize:10,marginTop:2},children:d("session.initialPrompt.blocked")||"Press Send or Skip before typing — keystrokes are ignored until then."})]}),t.jsxs("button",{onClick:Z,style:em("neutral"),title:K?d("session.initialPrompt.hidePreview")||"Hide preview":d("session.initialPrompt.preview")||"Preview",children:[K?t.jsx(lp,{size:12}):t.jsx(_i,{size:12}),K?d("session.initialPrompt.hidePreview")||"Hide":d("session.initialPrompt.preview")||"Preview"]}),t.jsxs("button",{onClick:Q,disabled:A!==null,style:em("primary"),children:[A==="send"?t.jsx(Tr,{size:12,style:{animation:"spin 1s linear infinite"}}):t.jsx(EN,{size:12}),d("session.initialPrompt.send")||"Send"]}),t.jsx("button",{onClick:W,disabled:A!==null,style:em("danger"),children:d("session.initialPrompt.skip")||"Skip"})]}),Y&&t.jsx("div",{style:{color:Ge.error,fontSize:10,marginTop:4},children:Y}),K&&t.jsx("pre",{style:{margin:0,marginTop:6,maxHeight:240,overflow:"auto",background:"rgba(0,0,0,0.4)",padding:8,fontFamily:Ht,fontSize:10,color:Ge.bright,whiteSpace:"pre-wrap",wordBreak:"break-word",border:`1px solid ${Ge.separator}`,borderRadius:4},children:q===null?d("session.initialPrompt.loading")||"loading…":q})]})]}),R&&S&&t.jsxs(t.Fragment,{children:[t.jsx("div",{onMouseDown:D,style:{width:5,flexShrink:0,cursor:"col-resize",background:Ge.separator}}),t.jsx("div",{style:{width:w,flexShrink:0,minWidth:0,height:"100%"},children:t.jsx(fO,{sessionId:e.id,projectId:e.project_id,onEvent:o,sendMessage:f,onClose:()=>_(!1)})})]})]})}const bO={position:"absolute",top:0,left:0,right:0,background:"rgba(28,28,38,0.96)",borderBottom:`1px solid ${Ge.separator}`,borderLeft:`3px solid ${Ge.warning}`,padding:"8px 10px",color:Ge.bright,fontFamily:Ht,fontSize:11,zIndex:3,display:"flex",flexDirection:"column"};function em(e){const s={display:"inline-flex",alignItems:"center",gap:4,fontFamily:Ht,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer",border:`1px solid ${Ge.separator}`,background:"transparent"};return e==="primary"?{...s,color:Ge.bright,borderColor:Ge.info,background:`${Ge.info}22`}:e==="danger"?{...s,color:Ge.dim}:{...s,color:Ge.bright}}const au={position:"absolute",inset:0,background:"rgba(12,12,12,0.85)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:1e3},Jy=340;function yO({sessionId:e}){var C,k,x,S,_,w;const[s,,i]=ES(e),[a,u]=y.useState(!1),[f,m]=y.useState(!1),[o,l]=y.useState({top:0,left:0}),h=y.useRef(null),p=y.useRef(null),d=y.useCallback(()=>{if(!h.current)return;const j=h.current.getBoundingClientRect(),R=window.innerWidth,E=window.innerHeight,D=p.current;let N=j.bottom+4,T=j.right-Jy;if(D){const z=D.offsetHeight,P=D.offsetWidth;T=j.right-P,T<8&&(T=8),T+P>R-8&&(T=R-8-P),N+z>E-8&&(N=Math.max(8,j.top-z-4))}else T<8&&(T=8);l({top:N,left:T}),m(!0)},[]);y.useEffect(()=>{if(!a){m(!1);return}d();const j=requestAnimationFrame(d),R=D=>{var T,z;const N=D.target;(T=h.current)!=null&&T.contains(N)||(z=p.current)!=null&&z.contains(N)||u(!1)},E=D=>{D.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",R),document.addEventListener("keydown",E),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{cancelAnimationFrame(j),document.removeEventListener("mousedown",R),document.removeEventListener("keydown",E),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[a,d]);const g=j=>{if(j==="custom"){const R=s.custom??{background:Hn.default.theme.background,foreground:Hn.default.theme.foreground,cursor:Hn.default.theme.cursor,selectionBackground:Hn.default.theme.selectionBackground,accent:Hn.default.theme.brightBlue};i({presetId:"custom",custom:R})}else i({presetId:j,custom:s.custom}),u(!1)},v=j=>{const R={...s.custom??{},...j};i({presetId:"custom",custom:R})};return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:h,"data-no-drag":!0,onMouseDown:j=>j.stopPropagation(),onClick:()=>u(j=>!j),"aria-label":"terminal-theme",title:"Terminal theme (Ctrl+Shift+P)",style:{background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},children:t.jsx(dN,{size:14})}),a&&cn.createPortal(t.jsxs("div",{ref:p,className:"z-tooltip",style:{position:"fixed",top:o.top,left:o.left,width:Jy,background:"#1e1e1e",border:`1px solid ${Ge.separator}`,borderRadius:6,padding:10,fontFamily:Ht,color:Ge.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:f?1:0,transition:"opacity 80ms"},onMouseDown:j=>j.stopPropagation(),children:[t.jsx("div",{style:{fontSize:10,color:Ge.dim,marginBottom:6,letterSpacing:.5},children:"DARK"}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:Wy.filter(j=>!Hn[j].light).map(j=>t.jsx(Qy,{preset:Hn[j],selected:s.presetId===j,onClick:()=>g(j)},j))}),t.jsx("div",{style:{fontSize:10,color:Ge.dim,marginBottom:6,letterSpacing:.5},children:"LIGHT"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:[Wy.filter(j=>Hn[j].light).map(j=>t.jsx(Qy,{preset:Hn[j],selected:s.presetId===j,onClick:()=>g(j)},j)),t.jsx(wO,{selected:s.presetId==="custom",accent:((C=s.custom)==null?void 0:C.accent)??Hn.default.theme.brightBlue??"#569cd6",onClick:()=>g("custom")})]}),s.presetId==="custom"&&t.jsxs("div",{style:{borderTop:`1px solid ${Ge.separator}`,paddingTop:8},children:[t.jsx("div",{style:{fontSize:10,color:Ge.dim,marginBottom:6,letterSpacing:.5},children:"CUSTOM COLORS"}),t.jsx(rl,{label:"Background",value:((k=s.custom)==null?void 0:k.background)??Hn.default.theme.background??"#0c0c0c",onChange:j=>v({background:j})}),t.jsx(rl,{label:"Foreground",value:((x=s.custom)==null?void 0:x.foreground)??Hn.default.theme.foreground??"#cccccc",onChange:j=>v({foreground:j})}),t.jsx(rl,{label:"Cursor",value:((S=s.custom)==null?void 0:S.cursor)??Hn.default.theme.cursor??"#f2f2f2",onChange:j=>v({cursor:j})}),t.jsx(rl,{label:"Selection",value:((_=s.custom)==null?void 0:_.selectionBackground)??Hn.default.theme.selectionBackground??"#264f78",onChange:j=>v({selectionBackground:j})}),t.jsx(rl,{label:"Accent",value:((w=s.custom)==null?void 0:w.accent)??Hn.default.theme.brightBlue??"#569cd6",onChange:j=>v({accent:j})})]})]}),document.body)]})}function Qy({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:Ge.separator}`,outline:s?`1px solid ${e.accent}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:Ht,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(ar,{size:12,style:{marginLeft:"auto",flexShrink:0}})]}),t.jsxs("div",{style:{fontSize:9,opacity:.85,fontFamily:Ht},children:[t.jsx("span",{style:{color:e.theme.green},children:"$"})," ",t.jsx("span",{style:{color:e.theme.brightBlue},children:"ls"})]})]})}function wO({selected:e,accent:s,onClick:i}){return t.jsxs("button",{onClick:i,style:{position:"relative",background:"#0c0c0c",border:`1px dashed ${e?s:Ge.separator}`,outline:e?`1px solid ${s}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:Ht,fontSize:10,color:Ge.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(ar,{size:12,style:{marginLeft:"auto",flexShrink:0}})]}),t.jsx("div",{style:{fontSize:9,opacity:.7},children:"edit colors"})]})}function rl({label:e,value:s,onChange:i}){const[a,u]=y.useState(s);y.useEffect(()=>{u(s)},[s]);const f=m=>{u(m);const o=m.startsWith("#")?m:`#${m}`;(/^#[0-9a-fA-F]{6}$/.test(o)||/^#[0-9a-fA-F]{3}$/.test(o))&&i(Zy(o))};return t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",fontSize:11,color:Ge.text},children:[t.jsx("span",{style:{flex:1},children:e}),t.jsx("input",{type:"text",value:a,onChange:m=>f(m.target.value),onBlur:()=>u(s),spellCheck:!1,style:{width:64,padding:"2px 4px",fontSize:10,fontFamily:Ht,color:Ge.text,background:"transparent",border:`1px solid ${Ge.separator}`,borderRadius:3}}),t.jsx("input",{type:"color",value:Zy(s),onChange:m=>i(m.target.value),style:{width:28,height:22,padding:0,border:`1px solid ${Ge.separator}`,borderRadius:3,background:"transparent",cursor:"pointer"}})]})}function Zy(e){return/^#[0-9a-fA-F]{6}$/.test(e)?e.toLowerCase():/^#[0-9a-fA-F]{3}$/.test(e)?("#"+e.slice(1).split("").map(s=>s+s).join("")).toLowerCase():"#000000"}const ew=360;function _O({sessionId:e,sendMessage:s}){const[i,a]=y.useState(!1),[u,f]=y.useState(!1),[m,o]=y.useState({top:0,left:0}),[l,h]=y.useState(null),[p,d]=y.useState(""),[g,v]=y.useState(!1),[C,k]=y.useState(""),[x,S]=y.useState(""),[_,w]=y.useState(!1),[j,R]=y.useState(null),E=y.useRef(null),D=y.useRef(null),N=y.useRef(null),T=y.useCallback(()=>{if(!E.current)return;const F=E.current.getBoundingClientRect(),q=window.innerWidth,$=window.innerHeight,K=D.current;let B=F.bottom+4,A=F.right-ew;if(K){const I=K.offsetHeight,Y=K.offsetWidth;A=F.right-Y,A<8&&(A=8),A+Y>q-8&&(A=q-8-Y),B+I>$-8&&(B=Math.max(8,F.top-I-4))}else A<8&&(A=8);o({top:B,left:A}),f(!0)},[]);y.useEffect(()=>{if(!i)return;let F=!1;return R1().then(q=>{F||h(q)}).catch(q=>{F||R(q instanceof Error?q.message:"Failed to load")}),()=>{F=!0}},[i]),y.useEffect(()=>{if(!i){f(!1);return}T();const F=requestAnimationFrame(T),q=requestAnimationFrame(()=>{requestAnimationFrame(()=>{var B;return(B=N.current)==null?void 0:B.focus()})}),$=B=>{var I,Y;const A=B.target;(I=E.current)!=null&&I.contains(A)||(Y=D.current)!=null&&Y.contains(A)||a(!1)},K=B=>{B.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",$),document.addEventListener("keydown",K),window.addEventListener("scroll",T,!0),window.addEventListener("resize",T),()=>{cancelAnimationFrame(F),cancelAnimationFrame(q),document.removeEventListener("mousedown",$),document.removeEventListener("keydown",K),window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}},[i,T]),y.useEffect(()=>{i||(d(""),v(!1),k(""),S(""),R(null))},[i]);const z=y.useMemo(()=>{if(!l)return[];const F=p.trim().toLowerCase();return F?l.filter(q=>q.name.toLowerCase().includes(F)||q.command_template.toLowerCase().includes(F)):l},[l,p]),P=F=>{s({type:"session:terminal-input",sessionId:e,input:F.command_template}),a(!1)},O=F=>{F.key==="Enter"&&z.length>0&&(F.preventDefault(),P(z[0]))},H=!!C.trim()&&!!x.trim()&&!_,U=async()=>{if(H){w(!0),R(null);try{const F=await M1({name:C.trim(),command_template:x.trim()});h(q=>q?[F,...q]:[F]),k(""),S(""),v(!1)}catch(F){R(F instanceof Error?F.message:"Failed")}finally{w(!1)}}};return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:E,"data-no-drag":!0,onMouseDown:F=>F.stopPropagation(),onClick:()=>a(F=>!F),"aria-label":"alias-inserter",title:"Insert saved command (alias) (Ctrl+Shift+A)",style:SO,children:t.jsx(oE,{size:14})}),i&&cn.createPortal(t.jsxs("div",{ref:D,className:"z-tooltip",style:{position:"fixed",top:m.top,left:m.left,width:ew,background:"#1e1e1e",border:`1px solid ${Ge.separator}`,borderRadius:6,padding:10,fontFamily:Ht,color:Ge.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:u?1:0,transition:"opacity 80ms"},onMouseDown:F=>F.stopPropagation(),children:[t.jsx("input",{ref:N,type:"text",value:p,onChange:F=>d(F.target.value),onKeyDown:O,placeholder:"Filter aliases… (Enter inserts first match)",style:{width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ge.separator}`,borderRadius:4,color:Ge.bright,fontFamily:Ht,fontSize:11,padding:"6px 8px",outline:"none"}}),t.jsx("div",{style:{marginTop:8,maxHeight:280,overflowY:"auto"},children:l===null?t.jsx("div",{style:tw,children:"Loading…"}):z.length===0?t.jsx("div",{style:tw,children:l.length===0?"No aliases yet — add one below.":"No matches."}):z.map(F=>t.jsxs("button",{onClick:()=>P(F),style:kO,onMouseEnter:q=>q.currentTarget.style.background="rgba(255,255,255,0.06)",onMouseLeave:q=>q.currentTarget.style.background="transparent",title:`Insert: ${F.command_template}`,children:[t.jsx("span",{style:{fontSize:11,color:Ge.bright,fontWeight:600},children:F.name}),t.jsx("code",{style:{fontSize:10,color:Ge.dim,marginLeft:8,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:F.command_template})]},F.id))}),t.jsx("div",{style:{borderTop:`1px solid ${Ge.separator}`,marginTop:8,paddingTop:8},children:g?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("input",{type:"text",value:C,onChange:F=>k(F.target.value),placeholder:"Name (e.g. git status)",maxLength:64,style:nw}),t.jsx("input",{type:"text",value:x,onChange:F=>S(F.target.value),onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),U())},placeholder:"Command (e.g. git status -sb)",maxLength:1024,style:{...nw,fontFamily:Ht}}),j&&t.jsx("div",{style:{fontSize:10,color:"#f87171"},children:j}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[t.jsxs("button",{type:"button",onClick:()=>{v(!1),R(null)},style:LS,children:[t.jsx(Jt,{size:12})," Cancel"]}),t.jsx("button",{type:"button",onClick:U,disabled:!H,style:{...CO,opacity:H?1:.5},children:"Save"})]})]}):t.jsxs("button",{type:"button",onClick:()=>{v(!0),R(null)},style:jO,children:[t.jsx(wn,{size:12})," New alias"]})})]}),document.body)]})}const SO={background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},tw={fontSize:11,color:Ge.dim,padding:"12px 4px",textAlign:"center"},kO={display:"flex",alignItems:"center",width:"100%",background:"transparent",border:"none",padding:"6px 8px",cursor:"pointer",textAlign:"left",borderRadius:3,transition:"background 80ms"},nw={width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ge.separator}`,borderRadius:4,color:Ge.bright,fontSize:11,padding:"5px 7px",outline:"none"},LS={display:"inline-flex",alignItems:"center",gap:3,background:"transparent",border:`1px solid ${Ge.separator}`,color:Ge.dim,fontFamily:Ht,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer"},CO={...LS,background:"rgba(86,156,214,0.13)",border:"1px solid #569cd6",color:Ge.bright},jO={display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",color:Ge.dim,fontFamily:Ht,fontSize:11,padding:"4px 0",cursor:"pointer"},EO={states:{},attention:new Set},Hp=y.createContext(EO);function $p(e,s,i){const[a,u]=y.useState({}),[f,m]=y.useState(()=>new Set),o=y.useRef(a);o.current=a;const l=y.useRef(s);l.current=s;const h=y.useRef(i);return h.current=i,y.useEffect(()=>e(p=>{var C;if(p.type!=="session:agent-state"||!p.sessionId||!p.state)return;const d=p.sessionId,g=p.state;if(o.current[d]===g)return;u(k=>({...k,[d]:g})),(g==="blocked"||g==="done"&&p.reason!=="stopped")&&!l.current.has(d)?(m(k=>k.has(d)?k:new Set(k).add(d)),(C=h.current)==null||C.call(h,d,g)):m(k=>{if(!k.has(d))return k;const x=new Set(k);return x.delete(d),x})}),[e]),y.useEffect(()=>{m(p=>{let d=null;for(const g of s)p.has(g)&&(d||(d=new Set(p)),d.delete(g));return d??p})},[s]),{states:a,attention:f}}const NO=26;function Up({stack:e,path:s,groupId:i,sessionsById:a,colors:u,intents:f,onTabClick:m,onTabClose:o,onTabMouseDown:l,onPaneAutoClose:h,registerRect:p,sendMessage:d,subscribeBinary:g,onEvent:v,focusedSessionId:C,groupTopmost:k,onFocusStack:x,groupActions:S}){const{t:_}=xt(),[w,,j]=A1(e.activeTab),[R,E]=y.useState({}),D=()=>{const B=e.activeTab;B&&E(A=>({...A,[B]:(A[B]||0)+1}))},N=XO(),{states:T,attention:z}=y.useContext(Hp),P=k===void 0?!0:k&&(!C||C===e.activeTab),O=k===!0&&!P,H=a.get(e.activeTab),U=[[H==null?void 0:H.cli_tool,H==null?void 0:H.cli_model].filter(Boolean).join("/"),H==null?void 0:H.branch_name,H==null?void 0:H.status,H!=null&&H.total_tokens?`${H.total_tokens.toLocaleString()} tok`:""].filter(Boolean).join(" · "),F=B=>{B.button===0&&e.activeTab&&(x?x(e.activeTab):N==null||N.focus(e.activeTab)),B.stopPropagation()},q=e.tabs.length>1?B=>{const A=e.tabs.indexOf(e.activeTab);if(A<0)return;const I=e.tabs.length,Y=B==="next"?(A+1)%I:(A-1+I)%I;m(e.tabs[Y])}:void 0,$=e.tabs.length>1?B=>{const A=e.tabs[B];A&&m(A)}:void 0,K=B=>{var Q;const A=/Mac|iPhone|iPad|iPod/.test(navigator.platform),I=A?B.metaKey:B.ctrlKey,Y=A?B.ctrlKey:B.metaKey,G=I&&!Y&&!B.altKey&&B.shiftKey,J=B.key.toLowerCase();if(B.key==="F5"&&!B.ctrlKey&&!B.metaKey&&!B.altKey&&!B.shiftKey||G&&J==="r"){B.preventDefault(),D();return}if(!G||J!=="a"&&J!=="p")return;B.preventDefault();const Z=J==="a"?"alias-inserter":"terminal-theme";(Q=B.currentTarget.querySelector(`[aria-label="${Z}"]`))==null||Q.click()};return t.jsxs("div",{onKeyDown:K,style:{flex:1,display:"flex",flexDirection:"column",background:Ge.bg,minWidth:0,minHeight:0,position:"relative",overflow:"hidden",opacity:O?k?.78:.88:1,filter:O?"saturate(0.78)":"none",boxShadow:P?`inset 0 0 0 1px ${Ge.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:B=>{var A;B.target.closest("button")||(A=S==null?void 0:S.onToggleMaximize)==null||A.call(S)},style:{display:"flex",height:NO,background:P?"#323a42":Ge.titleBg,borderBottom:`1px solid ${Ge.separator}`,flexShrink:0,overflowX:"auto",overflowY:"hidden"},children:[e.tabs.map((B,A)=>{const I=a.get(B),Y=B===e.activeTab,G=u[B]||Ge.titleText,J=(I==null?void 0:I.status)==="running"?Ge.success:(I==null?void 0:I.status)==="failed"?Ge.error:(I==null?void 0:I.status)==="completed"?Ge.info:Ge.dim,re=T[B]??(I==null?void 0:I.agent_state)??"unknown",Z=re==="working"?Ge.info:re==="blocked"?Ge.warning:J,Q=z.has(B),W=e.tabs.length>1&&A<9?`Ctrl+${A+1}`:"",oe=[I==null?void 0:I.status,re!=="unknown"?re:"",I==null?void 0:I.cli_tool,I==null?void 0:I.cli_model,I==null?void 0:I.branch_name,W].filter(Boolean).join(" · ");return t.jsxs("div",{onMouseDown:le=>{if(le.button===0){if(S){m(B);return}le.stopPropagation(),m(B),l(B,s,le)}},style:{display:"flex",alignItems:"center",gap:6,padding:"0 6px 0 10px",fontFamily:Ht,fontSize:11,color:Y?Ge.bright:Ge.titleText,background:Y?Ge.bg:"transparent",borderRight:`1px solid ${Ge.separator}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",maxWidth:200,position:"relative",boxShadow:Q?`inset 0 -2px 0 ${Z}`:void 0},title:`${(I==null?void 0:I.title)||B}${oe?`
682
- ${oe}`:""}`,children:[t.jsx("span",{"aria-label":re!=="unknown"?re:(I==null?void 0:I.status)||"unknown",className:re==="working"?"workspace-dot-pulse":void 0,style:{width:6,height:6,borderRadius:"50%",background:Z,flexShrink:0}}),t.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Ht,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:G,width:16,textAlign:"center"},children:">_"}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,color:Q?Z:void 0,fontWeight:Q?600:void 0},children:(I==null?void 0:I.title)||B}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:le=>{le.stopPropagation(),o(B)},"aria-label":"close-tab",title:_("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:t.jsx(Jt,{size:12})})]},B)}),N&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{N.createRawShellTab(i,s).catch(()=>{})},"aria-label":"new-tab",title:`${_("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${Ge.separator}`,color:Ge.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:t.jsx(wn,{size:14})}),t.jsx("div",{style:{flex:1,minWidth:8}}),U&&t.jsx("span",{title:U,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ge.dim,fontFamily:Ht,fontSize:9,padding:"0 7px",flexShrink:1},children:U}),t.jsx(_O,{sessionId:e.activeTab,sendMessage:d}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:D,"aria-label":"refresh-terminal",title:`${_("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${_("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:Is,children:t.jsx(kN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>j(-1),"aria-label":"decrease-font",title:`${_("session.fontDecrease")||"Decrease font size"} (${w}px) · Ctrl+- · Ctrl+wheel`,style:Is,children:t.jsx(YN,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>j(1),"aria-label":"increase-font",title:`${_("session.fontIncrease")||"Increase font size"} (${w}px) · Ctrl+= · Ctrl+wheel`,style:Is,children:t.jsx(KN,{size:14})}),t.jsx(yO,{sessionId:e.activeTab}),S&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&S.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{var B;return(B=S.onApplyLayoutPreset)==null?void 0:B.call(S,"single")},"aria-label":"single-pane",title:_("session.layout.single"),style:Is,children:t.jsx(Yi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{var B;return(B=S.onApplyLayoutPreset)==null?void 0:B.call(S,"columns")},"aria-label":"two-columns",title:_("session.layout.columns"),style:Is,children:t.jsx(l1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{var B;return(B=S.onApplyLayoutPreset)==null?void 0:B.call(S,"grid")},"aria-label":"grid-layout",title:_("session.layout.grid"),style:Is,children:t.jsx(u1,{size:14})})]}),S.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onToggleMaximize,"aria-label":"toggle-maximize",title:`${S.isMaximized?_("session.restoreSize"):_("session.maximize")} · ${_("session.maximizeHint")}`,style:Is,children:S.isMaximized?t.jsx(Tl,{size:14}):t.jsx(gi,{size:14})}),S.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onPopOutGroup,"aria-label":"pop-out",title:`${_("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Is,children:t.jsx(qs,{size:14})}),S.onReDockGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onReDockGroup,"aria-label":"redock",title:_("session.popout.redock")||"Re-dock to main window",style:Is,children:t.jsx(qs,{size:14,style:{transform:"scaleX(-1)"}})}),S.onMinimizeGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onMinimizeGroup,"aria-label":"minimize",title:`${_("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Is,children:t.jsx(dp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onCloseGroup,"aria-label":"close",title:`${_("session.close")||"Close"} (Ctrl+Shift+X)`,style:Is,children:t.jsx(Jt,{size:14})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:B=>{if(!B){p(s,null);return}const A=B.getBoundingClientRect();p(s,{x:A.left,y:A.top,w:A.width,h:A.height})},onMouseDown:F,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map(B=>{const A=a.get(B);if(!A)return null;const I=f[B]||{intent:"open",nonce:0};return t.jsx(NS,{session:A,visible:B===e.activeTab,intent:I.intent,intentNonce:I.nonce,onClose:()=>h(B),sendMessage:d,subscribeBinary:g,onEvent:v,onCycleTab:q,onSelectTab:$,remountKey:R[B]||0},B)})})]})}const Is={background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function LO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const u=y.useCallback(m=>{if(m.button!==0)return;m.preventDefault(),m.stopPropagation();const o=m.clientX,l=m.clientY;s();let h=!1;const p=()=>{h||(h=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",k),window.removeEventListener("blur",d),window.removeEventListener("keydown",g),document.removeEventListener("visibilitychange",v))},d=()=>{p(),a()},g=x=>{x.key==="Escape"&&d()},v=()=>{document.hidden&&d()},C=x=>{const S=e==="horizontal"?x.clientX-o:x.clientY-l;i(S)},k=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",k),window.addEventListener("blur",d),window.addEventListener("keydown",g),document.addEventListener("visibilitychange",v)},[e,s,i,a]),f=e==="horizontal";return t.jsx("div",{onMouseDown:u,style:{flex:"0 0 4px",background:Ge.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function Wp(e){const{node:s,path:i,onSplitSizes:a,zoomPath:u,...f}=e;return s.kind==="stack"?t.jsx(Up,{stack:s,path:i,...f}):t.jsx(DO,{split:s,path:i,onSplitSizes:a,zoomPath:u,stackProps:f})}const sw=80;function DO({split:e,path:s,onSplitSizes:i,zoomPath:a,stackProps:u}){const f=e.orientation==="horizontal",m=y.useRef(null),o=y.useRef([]),l=y.useRef(null);return t.jsx("div",{ref:m,style:{display:"flex",flexDirection:f?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((h,p)=>t.jsxs(y.Fragment,{children:[t.jsx("div",{ref:d=>{o.current[p]=d},style:{flex:a?"1 1 0%":`0 0 ${e.sizes[p]}%`,display:a&&a[s.length]!==p?"none":"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:t.jsx(Wp,{node:h,path:[...s,p],onSplitSizes:i,zoomPath:a,...u})}),!a&&p<e.children.length-1&&t.jsx(LO,{orientation:e.orientation,onDragStart:()=>{const d=m.current;if(!d)return;const g=e.sizes.slice();l.current={i:p,initialSizes:g,finalSizes:g.slice(),total:f?d.clientWidth:d.clientHeight}},onDrag:d=>{const g=l.current;if(!g||g.total<=0)return;const v=g.initialSizes[g.i]/100*g.total,C=g.initialSizes[g.i+1]/100*g.total,k=v+C,x=Math.max(sw,Math.min(k-sw,v+d)),S=k-x,_=x/g.total*100,w=S/g.total*100,j=o.current[g.i],R=o.current[g.i+1];j&&(j.style.flexBasis=`${_}%`),R&&(R.style.flexBasis=`${w}%`);const E=g.initialSizes.slice();E[g.i]=_,E[g.i+1]=w,g.finalSizes=E},onDragEnd:()=>{const d=l.current;d&&i(s,d.finalSizes),l.current=null}})]},p))})}const Lt=28,mn=68;function rd(e,s,i){const a=e-i.x,u=s-i.y;if(a<0||u<0||a>i.w||u>i.h)return null;const f=a-i.w/2,m=u-i.h/2;return Math.abs(f)<=Lt&&Math.abs(m)<=Lt?"center":f>=-mn-Lt&&f<=-mn+Lt&&Math.abs(m)<=Lt?"left":f>=mn-Lt&&f<=mn+Lt&&Math.abs(m)<=Lt?"right":m>=-mn-Lt&&m<=-mn+Lt&&Math.abs(f)<=Lt?"top":m>=mn-Lt&&m<=mn+Lt&&Math.abs(f)<=Lt?"bottom":null}function Ou(e,s){const i=document.elementsFromPoint(e,s);for(const a of i){const u=a.closest("[data-group-id][data-stack-path]");if(!u)continue;const f=u.dataset.stackPath||"",m=f===""?[]:f.split(".").map(Number),o=u.getBoundingClientRect(),l={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:u.dataset.groupId||"",path:m,rect:l,zone:rd(e,s,l)}}return null}function TO(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}}}const qm=mn*2+12;function DS(e,s,i,a){const u=e-i/2,f=s-a/2;return Math.abs(u)<=Lt&&Math.abs(f)<=Lt?"max":u>=-mn-Lt&&u<=-mn+Lt&&Math.abs(f)<=Lt?"left":u>=mn-Lt&&u<=mn+Lt&&Math.abs(f)<=Lt?"right":f>=-mn-Lt&&f<=-mn+Lt&&Math.abs(u)<=Lt?"top":f>=mn-Lt&&f<=mn+Lt&&Math.abs(u)<=Lt?"bottom":f>=-qm-Lt&&f<=-qm+Lt&&Math.abs(u)<=Lt?"popout":null}function TS(e,s,i,a,u){switch(e){case"left":return{x:u,y:0,w:s,h:a};case"right":return{x:i-s,y:0,w:s,h:a};case"top":return{x:u,y:0,w:i-u,h:s};case"bottom":return{x:u,y:a-s,w:i-u,h:s}}}function Cl(e,s,i,a){if(e==="max")return{x:a,y:0,w:s-a,h:i};const u=Math.round(e==="left"||e==="right"?(s-a)/2:i/2);return TS(e,u,s,i,a)}function Wa(){const e=document.querySelector("[data-app-sidebar]");return Math.max(0,e?e.getBoundingClientRect().right:0)}function RS({activeZone:e}){const s=window.innerWidth,i=window.innerHeight,a=s/2,u=i/2,f=e&&e!=="popout"?Cl(e,s,i,Wa()):null;return cn.createPortal(t.jsxs(t.Fragment,{children:[f&&t.jsx("div",{style:{position:"fixed",left:f.x,top:f.y,width:f.w,height:f.h,background:`${Ge.info}33`,border:`2px dashed ${Ge.info}`,borderRadius:8,pointerEvents:"none",zIndex:2400,transition:"left 80ms ease-out, top 80ms ease-out, width 80ms ease-out, height 80ms ease-out",boxSizing:"border-box"}}),t.jsxs("div",{style:{position:"fixed",inset:0,pointerEvents:"none",zIndex:2500},children:[t.jsx(Hs,{offsetX:a-Lt,offsetY:u-Lt,active:e==="max",kind:"center"}),t.jsx(Hs,{offsetX:a-mn-Lt,offsetY:u-Lt,active:e==="left",kind:"left"}),t.jsx(Hs,{offsetX:a+mn-Lt,offsetY:u-Lt,active:e==="right",kind:"right"}),t.jsx(Hs,{offsetX:a-Lt,offsetY:u-mn-Lt,active:e==="top",kind:"top"}),t.jsx(Hs,{offsetX:a-Lt,offsetY:u+mn-Lt,active:e==="bottom",kind:"bottom"}),t.jsx(Hs,{offsetX:a-Lt,offsetY:u-qm-Lt,active:e==="popout",kind:"popout"})]})]}),document.body)}function Ka({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,u=s?TO(e,s):null;return cn.createPortal(t.jsxs(t.Fragment,{children:[u&&t.jsx("div",{style:{position:"fixed",left:u.x,top:u.y,width:u.w,height:u.h,background:`${Ge.info}33`,border:`2px dashed ${Ge.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=mn+Lt;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(Hs,{offsetX:f-Lt,offsetY:f-Lt,active:s==="center",kind:"center"}),t.jsx(Hs,{offsetX:f-mn-Lt,offsetY:f-Lt,active:s==="left",kind:"left"}),t.jsx(Hs,{offsetX:f+mn-Lt,offsetY:f-Lt,active:s==="right",kind:"right"}),t.jsx(Hs,{offsetX:f-Lt,offsetY:f-mn-Lt,active:s==="top",kind:"top"}),t.jsx(Hs,{offsetX:f-Lt,offsetY:f+mn-Lt,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Hs({offsetX:e,offsetY:s,active:i,kind:a}){const u=Lt*2,f=i?Ge.info:"#3a3a3a",m=i?Ge.bright:Ge.separator;return t.jsx("div",{style:{position:"absolute",left:e,top:s,width:u,height:u,background:"#1a1a1a",border:`1px solid ${m}`,borderRadius:4,boxShadow:i?`0 0 8px ${Ge.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:t.jsx(RO,{kind:a,fill:f})})}function RO({kind:e,fill:s}){const i={position:"absolute",background:s};switch(e){case"center":return t.jsx("div",{style:{...i,inset:4}});case"popout":return t.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:t.jsx(qs,{size:24,color:s})});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 mi(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function pi(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 eo(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=eo(e.children[i],s);if(a)return[i,...a]}return null}function vn(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(vn)}function to(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(to)}function MS(e,s){const i=vn(e);if(i.length<=1||s==="single")return mi(i,to(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),u=Array.from({length:a},()=>[]);i.forEach((d,g)=>u[g%a].push(d));const f=new Set(to(e)),m=u.map(d=>mi(d,d.find(g=>f.has(g))||d[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),l=m.slice(2),h=d=>d.length===1?d[0]:{kind:"split",orientation:"horizontal",children:d,sizes:d.map(()=>100/d.length)};return{kind:"split",orientation:"vertical",children:[h(o),h(l)],sizes:[50,50]}}function Ki(e,s){return AS(e,s)}function AS(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=AS(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 u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function qa(e,s,i){return id(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 xl(e,s,i,a){const u=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return id(e,s,m=>({kind:"split",orientation:u,children:f?[a,m]:[m,a],sizes:[50,50]}))}function zS(e,s,i,a,u){const f=u&&a.includes(u)?u:a[a.length-1],m=i==="center"?a.reduce((o,l)=>qa(o,s,l),e):xl(e,s,i,mi(a,f));return sr(m,f)}function id(e,s,i){if(s.length===0)return Bu(i(e));if(e.kind!=="split")throw new Error("replaceAt: path traverses non-split");const[a,...u]=s;if(a<0||a>=e.children.length)throw new Error("replaceAt: bad path");const f=e.children.map((m,o)=>o===a?id(m,u,i):m);return Bu({...e,children:f})}function Bu(e){if(e.kind==="stack")return e;const s=e.children.map(Bu),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 l=m.sizes.reduce((h,p)=>h+p,0)||1;for(let h=0;h<m.children.length;h++)i.push(m.children[h]),a.push(m.sizes[h]/l*o)}else i.push(m),a.push(o)}if(i.length===1)return i[0];const u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function sr(e,s){return e.kind==="stack"?e.tabs.includes(s)?{...e,activeTab:s}:e:{...e,children:e.children.map(i=>sr(i,s))}}function OS(e,s,i){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const a=e.tabs.indexOf(s),u=Math.max(0,Math.min(i,e.tabs.length-1));if(u===a)return e;const f=e.tabs.slice();return f.splice(a,1),f.splice(u,0,s),{...e,tabs:f}}return{...e,children:e.children.map(a=>OS(a,s,i))}}function BS(e,s,i){return id(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 MO(e,s,i,a){const u=pi(e,i);if(!u||u.kind!=="stack"||a==="center"&&u.tabs.includes(s))return null;const f=u.tabs.find(h=>h!==s);if(!f)return null;const m=Ki(e,s);if(!m)return null;const o=eo(m,f);if(!o)return null;const l=a==="center"?qa(m,o,s):xl(m,o,a,mi([s]));return sr(l,s)}function AO(e,s,i){const a=i==="left"||i==="right"?"horizontal":"vertical",u=i==="right"||i==="down";for(let f=s.length-1;f>=0;f--){const m=pi(e,s.slice(0,f));if(!m||m.kind!=="split"||m.orientation!==a)continue;const o=s[f]+(u?1:-1);if(o<0||o>=m.children.length)continue;const l=zO(e,s,f,a);return[...s.slice(0,f),o,...OO(m.children[o],u,l,a)]}return null}function zO(e,s,i,a){let u=0,f=1;for(let m=i;m<s.length;m++){const o=pi(e,s.slice(0,m));if(!o||o.kind!=="split"||o.orientation===a)continue;const l=o.sizes.reduce((g,v)=>g+v,0)||1,h=o.sizes.slice(0,s[m]).reduce((g,v)=>g+v,0)/l,p=o.sizes[s[m]]/l,d=f-u;f=u+d*(h+p),u=u+d*h}return(u+f)/2}function OO(e,s,i,a){const u=[];let f=e,m=i;for(;f.kind==="split";){let o=f.children.length-1;if(f.orientation===a)o=s?0:f.children.length-1;else{const l=f.sizes.reduce((p,d)=>p+d,0)||1;let h=0;for(let p=0;p<f.children.length;p++){const d=f.sizes[p]/l;if(m<h+d||p===f.children.length-1){o=p,m=d>0?(m-h)/d:.5;break}h+=d}}u.push(o),f=f.children[o]}return u}function BO(e,s){const i=vn(e);let a=e;for(const u of i){if(!a)break;s.has(u)||(a=Ki(a,u))}return a}const ou=320,lu=200,cu=80,uu=22,PO=4,rw=8,oi=10,du=60,IO=12;function li(e,s,i){return Math.max(s,Math.min(i,e))}function FO(e,s,i,a){const u=e<=rw,f=e>=i-rw;if(!u&&!f)return null;const m=a/3,o=a*2/3;return u?s<m?"top-left":s>o?"bottom-left":"left":s<m?"top-right":s>o?"bottom-right":"right"}function iw(e,s,i){const a=Math.round(s/2),u=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:u};case"top-right":return{x:s-a,y:0,w:a,h:u};case"bottom-left":return{x:0,y:i-u,w:a,h:u};case"bottom-right":return{x:s-a,y:i-u,w:a,h:u}}}function HO(e,s,i,a,u){let f=e,m=s;const o=f,l=f+i,h=m,p=m+a;for(const d of u){const g=d.x,v=d.x+d.w,C=d.y,k=d.y+d.h;h<k&&p>C&&(Math.abs(o-v)<=oi?f=v:Math.abs(l-g)<=oi?f=g-i:Math.abs(o-g)<=oi?f=g:Math.abs(l-v)<=oi&&(f=v-i)),o<v&&l>g&&(Math.abs(h-k)<=oi?m=k:Math.abs(p-C)<=oi?m=C-a:Math.abs(h-C)<=oi?m=C:Math.abs(p-k)<=oi&&(m=k-a))}return{x:f,y:m}}function $O({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:u,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:l}=xt(),h=cS("(max-width: 767px)"),p=WS(),d=y.useRef(null),[g,v]=y.useState(!1),C=y.useRef(null),[k,x]=y.useState(null),S=y.useRef({x:e.x,y:e.y,w:e.w,h:e.h});S.current={x:e.x,y:e.y,w:e.w,h:e.h};const[_,w]=y.useState(null),j=y.useRef(null),[R,E]=y.useState(!1),[D,N]=y.useState(null),T=y.useRef(null),z=y.useRef(i);z.current=i;const[P,O]=y.useState(null),H=y.useRef(null),U=y.useCallback((be,Re)=>{if(h||g||be.button!==0||be.target.closest("[data-no-drag]"))return;be.preventDefault(),p.focus(vn(e.root)[0]||"");const tt=be.clientX,Ke=be.clientY,Le={...S.current},$e=d.current,Ie=window.innerWidth,it=window.innerHeight,vt=Wa();let Ce=!1,Ue="";Re&&$e&&(Ue=$e.style.pointerEvents,$e.style.pointerEvents="none");let we=!1;const Pe=()=>{we||(we=!0,window.removeEventListener("mousemove",ie),window.removeEventListener("mouseup",ke),window.removeEventListener("blur",X),window.removeEventListener("keydown",ne),document.removeEventListener("visibilitychange",Se),Re&&$e&&($e.style.pointerEvents=Ue))},X=()=>{Pe(),H.current=null,O(null),j.current=null,w(null),T.current=null,N(null),E(!1),p.setGroupGeometry(e.id,{...S.current})},ne=_e=>{_e.key==="Escape"&&X()},Se=()=>{document.hidden&&X()};let fe=!1;const ie=_e=>{if(fe)return;{const Me=window.screenX,Te=window.screenY,et=Me+window.outerWidth,Ye=Te+window.outerHeight;if(_e.screenX<Me-du||_e.screenX>et+du||_e.screenY<Te-du||_e.screenY>Ye+du){fe=!0,Pe(),H.current=null,O(null),j.current=null,w(null),T.current=null,N(null),E(!1),p.setGroupGeometry(e.id,{...S.current}),p.popOutGroup(e.id,{atScreenX:_e.screenX,atScreenY:_e.screenY});return}}const st=_e.clientX-tt,Ze=_e.clientY-Ke;let he=li(Le.x+st,-(Le.w-cu),Ie-cu),de=li(Le.y+Ze,0,it-uu);const ce=z.current;if(ce.length>0){const Me=HO(he,de,Le.w,Le.h,ce);he=Me.x,de=Me.y}if($e&&($e.style.left=`${he}px`,$e.style.top=`${de}px`),S.current.x=he,S.current.y=de,Re){let Me=null;const Te=document.elementFromPoint(_e.clientX,_e.clientY),et=Te==null?void 0:Te.closest("[data-group-id][data-stack-path]");if(et){const Ye=et.dataset.groupId||"";if(Ye!==e.id){const mt=et.dataset.stackPath||"",bt=mt===""?[]:mt.split(".").map(Number),yt=et.getBoundingClientRect(),Et={x:yt.left,y:yt.top,w:yt.width,h:yt.height};Me={groupId:Ye,path:bt,rect:Et,zone:rd(_e.clientX,_e.clientY,Et)}}}H.current=Me,O(Me?{rect:Me.rect,zone:Me.zone}:null)}!Ce&&Math.hypot(_e.clientX-tt,_e.clientY-Ke)>=IO&&(Ce=!0,E(!0),e.dock&&p.setGroupDock(e.id,null));const ee=Re&&H.current&&H.current.zone,Ne=ee||!Ce?null:DS(_e.clientX,_e.clientY,Ie,it);Ne!==T.current&&(T.current=Ne,N(Ne));const je=ee||Ne?null:FO(_e.clientX,_e.clientY,Ie,it);je!==j.current&&(j.current=je,w(je))},ke=_e=>{Pe(),E(!1);const st=T.current;if(T.current=null,N(null),Re&&H.current&&H.current.zone){const he=H.current;p.dockGroup(e.id,he.groupId,he.path,he.zone),H.current=null,O(null),j.current=null,w(null);return}if(st==="popout"){H.current=null,O(null),j.current=null,w(null),p.setGroupGeometry(e.id,{...S.current}),p.popOutGroup(e.id,{atScreenX:_e.screenX,atScreenY:_e.screenY});return}if(st&&st!=="max"){const he=Cl(st,Ie,it,vt);$e&&($e.style.left=`${he.x}px`,$e.style.top=`${he.y}px`,$e.style.width=`${he.w}px`,$e.style.height=`${he.h}px`),S.current=he,H.current=null,O(null),j.current=null,w(null),p.setGroupDock(e.id,st);return}const Ze=st?Cl(st,Ie,it,vt):j.current?iw(j.current,Ie,it):null;Ze&&($e&&($e.style.left=`${Ze.x}px`,$e.style.top=`${Ze.y}px`,$e.style.width=`${Ze.w}px`,$e.style.height=`${Ze.h}px`),S.current=Ze,j.current=null,w(null)),H.current=null,O(null),p.setGroupGeometry(e.id,{...S.current})};window.addEventListener("mousemove",ie),window.addEventListener("mouseup",ke),window.addEventListener("blur",X),window.addEventListener("keydown",ne),document.addEventListener("visibilitychange",Se)},[h,g,p,e.id,e.root,e.dock]),F=y.useCallback(be=>U(be,!1),[U]),q=y.useCallback(be=>U(be,!0),[U]),$=y.useCallback(be=>Re=>{if(h||g||Re.button!==0)return;Re.preventDefault(),Re.stopPropagation();const ct=Re.clientX,tt=Re.clientY,Ke={...S.current},Le=d.current,$e=window.innerWidth,Ie=window.innerHeight,it=ne=>{const Se=ne.clientX-ct,fe=ne.clientY-tt;let ie=Ke.x,ke=Ke.y,_e=Ke.w,st=Ke.h;be.includes("e")?_e=li(Ke.w+Se,ou,Math.max(ou,$e-Ke.x)):be.includes("w")&&(ie=li(Ke.x+Se,0,Ke.x+Ke.w-ou),_e=Ke.x+Ke.w-ie),be.includes("s")?st=li(Ke.h+fe,lu,Math.max(lu,Ie-Ke.y)):be.includes("n")&&(ke=li(Ke.y+fe,0,Ke.y+Ke.h-lu),st=Ke.y+Ke.h-ke),Le&&(Le.style.left=`${ie}px`,Le.style.top=`${ke}px`,Le.style.width=`${_e}px`,Le.style.height=`${st}px`),S.current={x:ie,y:ke,w:_e,h:st}};let vt=!1;const Ce=()=>{vt||(vt=!0,window.removeEventListener("mousemove",it),window.removeEventListener("mouseup",X),window.removeEventListener("blur",Ue),window.removeEventListener("keydown",we),document.removeEventListener("visibilitychange",Pe))},Ue=()=>{Ce(),p.setGroupGeometry(e.id,{...S.current})},we=ne=>{ne.key==="Escape"&&Ue()},Pe=()=>{document.hidden&&Ue()},X=()=>{Ce(),p.setGroupGeometry(e.id,{...S.current})};window.addEventListener("mousemove",it),window.addEventListener("mouseup",X),window.addEventListener("blur",Ue),window.addEventListener("keydown",we),document.addEventListener("visibilitychange",Pe)},[h,g,p,e.id]);y.useEffect(()=>{if(h||e.dock)return;const be=()=>{const Re=window.innerWidth,ct=window.innerHeight,tt=S.current,Ke=li(tt.x,-(tt.w-cu),Re-cu),Le=li(tt.y,0,ct-uu);(Ke!==tt.x||Le!==tt.y)&&p.setGroupGeometry(e.id,{...tt,x:Ke,y:Le})};return window.addEventListener("resize",be),()=>window.removeEventListener("resize",be)},[h,p,e.id,e.dock]);const K=y.useCallback(be=>{x(be),p.setActiveTab(e.id,be),p.focus(be)},[p,e.id]),B=y.useCallback(be=>{x(be),p.focus(be)},[p]),A=y.useCallback(be=>{p.close(be)},[p]),I=y.useCallback((be,Re,ct)=>{p.beginTabDrag(e.id,be,Re,ct)},[p,e.id]),Y=y.useCallback(be=>{p.close(be)},[p]),G=y.useCallback((be,Re)=>{p.setSplitSizes(e.id,be,Re)},[p,e.id]),J=to(e.root),re=vn(e.root);y.useEffect(()=>{k&&re.includes(k)||x(J[0]||re[0]||null)},[k,J,re]);const[Z,Q]=y.useState(null),W=Z&&e.root.kind==="split"?eo(e.root,Z):null,oe=!!Z&&!W;y.useEffect(()=>{oe&&Q(null)},[oe]);const le=y.useCallback(()=>{if(g){const be=C.current;be&&p.setGroupGeometry(e.id,be),C.current=null,v(!1);return}C.current={...S.current},e.dock&&p.setGroupDock(e.id,null),p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(ou,window.innerWidth-12),h:Math.max(lu,window.innerHeight-12)}),v(!0)},[p,e.id,g,e.dock]),ge=be=>{const Re=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ct=Re?be.metaKey:be.ctrlKey,tt=Re?be.ctrlKey:be.metaKey;if(!ct||tt||be.altKey||!be.shiftKey)return;const Ke=be.key.toLowerCase();if(Ke==="o")be.preventDefault(),p.popOutGroup(e.id);else if(Ke==="m")be.preventDefault(),p.minimizeGroup(e.id);else if(Ke==="x")be.preventDefault(),p.closeGroup(e.id);else if(Ke==="z")be.preventDefault(),e.root.kind==="split"?Q(Le=>Le?null:k):le();else if(Ke.startsWith("arrow")){be.preventDefault();const Le=k?eo(e.root,k):null,$e=Le?AO(e.root,Le,Ke.slice(5)):null,Ie=$e?pi(e.root,$e):null;if(!$e||!Ie||Ie.kind!=="stack")return;B(Ie.activeTab),Z&&Q(Ie.activeTab);const it=`[data-stack-path="${$e.join(".")}"] .xterm-helper-textarea`;requestAnimationFrame(()=>{var Ce,Ue;(Ue=Array.from(((Ce=d.current)==null?void 0:Ce.querySelectorAll(it))??[]).find(we=>we.offsetParent!==null))==null||Ue.focus()})}};if(h){const be=J[0],Re=be?s.get(be):null;if(!Re)return null;const ct=e.intents[be]??{intent:"open",nonce:0};return cn.createPortal(t.jsxs("div",{style:{position:"fixed",inset:0,background:Ge.bg,display:"flex",flexDirection:"column",zIndex:110},children:[t.jsxs("div",{style:{background:Ge.titleBg,height:uu,display:"flex",alignItems:"center",borderBottom:`1px solid ${Ge.separator}`},children:[t.jsx("span",{style:{flex:1,color:Ge.titleText,fontFamily:Ht,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Re.title}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ci,"aria-label":"close",children:t.jsx(Jt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(NS,{session:Re,visible:!0,intent:ct.intent,intentNonce:ct.nonce,onClose:()=>p.close(be),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const ue=_?(()=>{const be=window.innerWidth,Re=window.innerHeight,ct=iw(_,be,Re);return cn.createPortal(t.jsx("div",{style:{position:"fixed",left:ct.x,top:ct.y,width:ct.w,height:ct.h,background:`${Ge.info}33`,border:`2px dashed ${Ge.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,Ve=(()=>{var Re;if(re.length===0)return"";const be=((Re=s.get(re[0]))==null?void 0:Re.title)||re[0];return re.length===1?be:`${be} +${re.length-1}`})(),We=e.root.kind==="split",De=cn.createPortal(t.jsxs("div",{ref:d,onKeyDown:ge,onMouseDown:We?()=>p.focus(re[0]||""):q,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:u,background:Ge.bg,border:`1px solid ${a?Ge.info:Ge.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 ${Ge.info}66, 0 0 18px ${Ge.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:[We&&t.jsxs("div",{onMouseDown:F,onDoubleClick:be=>{be.target.closest("button")||le()},style:{height:uu,flexShrink:0,display:"flex",flexDirection:"column",background:Ge.titleBg,borderBottom:`1px solid ${Ge.separator}`,userSelect:"none",cursor:"move"},children:[t.jsx("div",{style:{display:"flex",height:PO,flexShrink:0},children:J.map((be,Re)=>t.jsx("div",{style:{flex:1,background:e.colors[be]||Ge.titleText}},Re))}),t.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:Ge.titleText,fontFamily:Ht,fontSize:11},children:[t.jsx("span",{style:{color:Ge.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ve}),re.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:ci,"aria-label":"single-pane",title:l("session.layout.single"),children:t.jsx(Yi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:ci,"aria-label":"two-columns",title:l("session.layout.columns"),children:t.jsx(l1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:ci,"aria-label":"grid-layout",title:l("session.layout.grid"),children:t.jsx(u1,{size:14})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:le,style:ci,"aria-label":"toggle-maximize",title:`${l(g?"session.restoreSize":"session.maximize")} · ${l("session.maximizeHint")}`,children:g?t.jsx(Tl,{size:14}):t.jsx(gi,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.popOutGroup(e.id),style:ci,"aria-label":"pop-out",title:`${l("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:t.jsx(qs,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.minimizeGroup(e.id),style:ci,"aria-label":"minimize",title:`${l("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:t.jsx(dp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ci,"aria-label":"close",title:`${l("session.close")||"Close"} (Ctrl+Shift+X)`,children:t.jsx(Jt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(Wp,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:A,onTabMouseDown:I,onPaneAutoClose:Y,registerRect:()=>{},onSplitSizes:G,zoomPath:W??void 0,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:B}):t.jsx(Up,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:A,onTabMouseDown:I,onPaneAutoClose:Y,registerRect:()=>{},sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:B,groupActions:{onMinimizeGroup:()=>p.minimizeGroup(e.id),onCloseGroup:()=>p.closeGroup(e.id),onPopOutGroup:()=>p.popOutGroup(e.id),onToggleMaximize:le,isMaximized:g,onApplyLayoutPreset:be=>p.applyLayoutPreset(e.id,be)}})}),t.jsx("div",{onMouseDown:$("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),t.jsx("div",{onMouseDown:$("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:$("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:$("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:[De,ue,R&&!(P!=null&&P.zone)&&t.jsx(RS,{activeZone:D}),P&&t.jsx(Ka,{targetRect:P.rect,activeZone:P.zone})]})}const ci={background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},tm=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function qi(e){for(const s of tm)if(!e.includes(s))return s;return tm[e.length%tm.length]}const UO="clitrigger:session-windows:global";function qp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(UO),s=new Set;return e.onmessage=i=>{const a=i.data;for(const u of s)try{u(a)}catch{}},{post:i=>{e.postMessage(i)},subscribe:i=>(s.add(i),()=>{s.delete(i)}),close:()=>{s.clear(),e.close()}}}const Ft="main",Gm=new Map;function WO(e,s){Gm.set(e,s)}function qO(e){const s=Gm.get(e);if(!s||s.closed)return Gm.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function GO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Gp=5e3,PS=15e3;let $a=null;function Ji(){var i;const e=window.electronAPI,s=(i=e==null?void 0:e.getZoomFactor)==null?void 0:i.call(e);return typeof s=="number"&&s>0?s:1}function IS(){if(typeof window>"u")return()=>{};const e=s=>{const i=Ji();$a={ox:s.screenX-s.clientX*i,oy:s.screenY-s.clientY*i,wx:window.screenX,wy:window.screenY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function FS(){if($a)return{ox:$a.ox+(window.screenX-$a.wx),oy:$a.oy+(window.screenY-$a.wy)};const e=Ji(),s=Math.max(0,(window.outerWidth-window.innerWidth*e)/2),i=Math.max(0,window.outerHeight-window.innerHeight*e-s);return{ox:window.screenX+s,oy:window.screenY+i}}function Pu(e,s){const i=Ji(),{ox:a,oy:u}=FS();return{x:(e-a)/i,y:(s-u)/i}}function HS(e,s){const i=Ji(),{ox:a,oy:u}=FS();return{x:a+e*i,y:u+s*i}}function Iu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Km="clitrigger:popout-alive:";function KO(e){return`${Km}${e}`}function Kp(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function VO(e){if(!Kp())return()=>{};let s=()=>{};return navigator.locks.request(KO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function $S(){var e;if(!Kp())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(Km)&&i.add(a.name.slice(Km.length));return i}catch{return new Set}}const Vp=y.createContext(null),US=y.createContext({});function WS(){const e=y.useContext(Vp);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function YO(){return y.useContext(US)}function XO(){return y.useContext(Vp)}const Fu=720,Yp=460,JO=320,QO=200,aw=30,qS=80,GS=80,vl=80,Vm=28;function ZO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=JO?e.w:Fu,u=Number.isFinite(e.h)&&e.h>=QO?e.h:Yp;a=Math.min(a,s),u=Math.min(u,i);let f=Number.isFinite(e.x)?e.x:qS,m=Number.isFinite(e.y)?e.y:GS;return f=Math.max(Math.min(f,s-vl),-(a-vl)),m=Math.max(Math.min(m,i-Vm),0),{x:f,y:m,w:a,h:u}}const ow=12,hu=60;function KS(e){return`sessionGroups:${e}`}function _u(e){try{const s=localStorage.getItem(KS(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 Ym(e,s){try{localStorage.setItem(KS(e),JSON.stringify(s))}catch{}}function eB(e,s){const i=_u(e);!i||!i.groups.some(a=>a.id===s)||(Ym(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function tB(e){const s=e%8;return{x:qS+s*aw,y:GS+s*aw,w:Fu,h:Yp}}function fu(e,s,i){return Math.max(s,Math.min(i,e))}function lw(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function Nr(e,s){for(const i of e)if(eo(i.root,s))return i;return null}function nB({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:u,onAddSession:f,children:m}){const{t:o}=xt(),{warning:l}=Rs(),{confirm:h}=Yn(),{sendNotification:p}=ro(),[d]=y.useState(()=>{const he=_u(e);if(!he)return{groups:[],zCounter:0};const de=he.groups.map(ce=>{const ee=vn(ce.root),Ne=new Set(ee),je={};for(const Ye of Object.keys(ce.colors||{}))Ne.has(Ye)&&(je[Ye]=ce.colors[Ye]);const Me={};for(const Ye of ee)Me[Ye]={intent:"open",nonce:0},je[Ye]||(je[Ye]=qi(Object.values(je)));const Te=ZO({x:ce.x,y:ce.y,w:ce.w,h:ce.h}),et=ce.ownerWindowId||Ft;return{...ce,...Te,colors:je,intents:Me,minimized:!!ce.minimized,ownerWindowId:et}});return{groups:de,zCounter:he.zCounter||de.length}}),[g,v]=y.useState(d.groups),C=y.useRef(d.zCounter),k=y.useRef(g);k.current=g;const x=y.useRef(s);x.current=s;const[S,_]=y.useState(null),w=y.useRef(null);w.current=S;const[j,R]=y.useState({}),E=y.useRef(j);E.current=j,y.useEffect(()=>{var ee;const he={},de=((ee=_u(e))==null?void 0:ee.sessionProjects)??{},ce={};for(const Ne of g)for(const je of vn(Ne.root)){const Me=s.find(et=>et.id===je)||j[je];Me!=null&&Me.title&&(he[je]=Me.title);const Te=(Me==null?void 0:Me.project_id)||de[je];Te&&(ce[je]=Te)}Ym(e,{groups:g,zCounter:C.current,titles:he,sessionProjects:ce}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,g,s,j]),y.useEffect(()=>()=>{var Me;const he=k.current;if(he.length===0)return;let de=!1;const ce=he.map(Te=>(Te.ownerWindowId||Ft)!==Ft||Te.minimized?Te:(de=!0,{...Te,minimized:!0}));if(!de)return;const ee={},Ne=((Me=_u(e))==null?void 0:Me.sessionProjects)??{},je={};for(const Te of ce)for(const et of vn(Te.root)){const Ye=x.current.find(bt=>bt.id===et)||E.current[et];Ye!=null&&Ye.title&&(ee[et]=Ye.title);const mt=(Ye==null?void 0:Ye.project_id)||Ne[et];mt&&(je[et]=mt)}Ym(e,{groups:ce,zCounter:C.current,titles:ee,sessionProjects:je}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]),y.useEffect(()=>{const he=document.documentElement.style,de={left:0,right:0,top:0,bottom:0};for(const ce of g)!ce.dock||ce.minimized||(ce.ownerWindowId||Ft)!==Ft||(ce.dock==="left"?de.left=Math.max(de.left,ce.x+ce.w-Wa()):ce.dock==="right"?de.right=Math.max(de.right,window.innerWidth-ce.x):ce.dock==="top"?de.top=Math.max(de.top,ce.y+ce.h):de.bottom=Math.max(de.bottom,window.innerHeight-ce.y));for(const ce of["left","right","top","bottom"])he.setProperty(`--dock-inset-${ce}`,`${Math.max(0,Math.round(de[ce]))}px`);return()=>{for(const ce of["left","right","top","bottom"])he.removeProperty(`--dock-inset-${ce}`)}},[g]),y.useEffect(()=>{const he=()=>{const ee=window.innerWidth,Ne=window.innerHeight,je=Wa();v(Me=>{let Te=!1;const et=Me.map(Ye=>{if(!Ye.dock)return Ye;const mt=Ye.dock==="left"||Ye.dock==="right"?Ye.w:Ye.h,bt=TS(Ye.dock,mt,ee,Ne,je);return bt.x===Ye.x&&bt.y===Ye.y&&bt.w===Ye.w&&bt.h===Ye.h?Ye:(Te=!0,{...Ye,...bt})});return Te?et:Me})};he();const de=document.querySelector("main"),ce=de?new ResizeObserver(he):null;return de&&ce&&ce.observe(de),window.addEventListener("resize",he),()=>{ce==null||ce.disconnect(),window.removeEventListener("resize",he)}},[]);const[D,N]=y.useState(()=>new Set),T=y.useRef(new Set);y.useEffect(()=>{if(s.length===0)return;const he=s.filter(ce=>ce.project_id===e);if(he.length===0)return;const de=new Set(he.map(ce=>ce.id));for(const ce of g)for(const ee of vn(ce.root))de.has(ee)||j[ee]||D.has(ee)||T.current.has(ee)||(T.current.add(ee),q1(ee).then(Ne=>R(je=>({...je,[ee]:Ne}))).catch(Ne=>{Ne instanceof Ya&&Ne.status===404&&N(je=>new Set(je).add(ee))}).finally(()=>T.current.delete(ee)))},[g,s,e,j,D]),y.useEffect(()=>u(de=>{de.type!=="session:status-changed"||!de.sessionId||R(ce=>{const ee=ce[de.sessionId];if(!ee)return ce;const Ne={status:de.status};return de.worktree_path!==void 0&&(Ne.worktree_path=de.worktree_path),de.branch_name!==void 0&&(Ne.branch_name=de.branch_name),{...ce,[ee.id]:{...ee,...Ne}}})}),[u]),y.useEffect(()=>{D.size!==0&&v(he=>{let de=!1;const ce=[];for(const ee of he){const Ne=vn(ee.root);if(!Ne.some(mt=>D.has(mt))){ce.push(ee);continue}de=!0;const je=new Set(Ne.filter(mt=>!D.has(mt))),Me=BO(ee.root,je);if(!Me)continue;const Te=new Set(vn(Me)),et={};for(const mt of Object.keys(ee.colors))Te.has(mt)&&(et[mt]=ee.colors[mt]);const Ye={};for(const mt of Object.keys(ee.intents))Te.has(mt)&&(Ye[mt]=ee.intents[mt]);ce.push({...ee,root:Me,colors:et,intents:Ye})}return de?ce:he})},[D]);const z=y.useCallback((he,de)=>{const ce=k.current.length,ee=tB(ce);C.current+=1;const Ne=C.current;return{id:lw(),...ee,z:Ne,minimized:!1,root:mi([he],he),colors:{[he]:qi([])},intents:{[he]:{intent:de,nonce:0}},ownerWindowId:Ft}},[]),P=y.useCallback((he,de="open")=>{v(ce=>{const ee=Nr(ce,he);C.current+=1;const Ne=C.current;return ee?ce.map(je=>{var mt,bt,yt;if(je.id!==ee.id)return je;const Me=((mt=je.intents[he])==null?void 0:mt.intent)??"open",Te=de==="start"||de==="resume",et=Te?de:Me,Ye=et!==Me||Te;return{...je,z:Ne,minimized:!1,root:sr(je.root,he),intents:{...je.intents,[he]:{intent:et,nonce:Ye?(((bt=je.intents[he])==null?void 0:bt.nonce)??0)+1:((yt=je.intents[he])==null?void 0:yt.nonce)??0}}}}):[...ce,z(he,de)]})},[z]),O=y.useCallback(he=>{v(de=>{const ce=Nr(de,he);if(!ce)return de;const ee=de.reduce((je,Me)=>Me.z>je?Me.z:je,0);if(ce.z===ee&&!ce.minimized)return de;C.current+=1;const Ne=C.current;return de.map(je=>je.id===ce.id?{...je,z:Ne,minimized:!1}:je)})},[]),H=y.useCallback(async he=>{const de=he.map(ce=>x.current.find(ee=>ee.id===ce)||E.current[ce]).filter(ce=>!!ce&&ce.status==="running");if(de.length===0)return!0;if(!await h({message:o("session.confirmStop"),danger:!0}))return!1;for(const ce of de)Du(ce.id).catch(()=>{});return!0},[o,h]),U=y.useCallback(async he=>{await H([he])&&v(de=>{const ce=Nr(de,he);if(!ce)return de;const ee=Ki(ce.root,he);if(!ee)return de.filter(Me=>Me.id!==ce.id);new Set(vn(ee));const Ne={...ce.colors};delete Ne[he];const je={...ce.intents};return delete je[he],de.map(Me=>Me.id===ce.id?{...Me,root:ee,colors:Ne,intents:je}:Me)})},[H]),F=y.useCallback(he=>{v(de=>{const ce=Nr(de,he);return ce?de.map(ee=>ee.id===ce.id?{...ee,minimized:!0}:ee):de})},[]),q=y.useCallback(he=>{v(de=>{const ce=Nr(de,he);if(!ce)return de;C.current+=1;const ee=C.current;return de.map(Ne=>Ne.id===ce.id?{...Ne,minimized:!1,z:ee}:Ne)})},[]),$=y.useCallback(he=>!!Nr(k.current,he),[]),K=y.useCallback(async he=>{const de=k.current.find(ce=>ce.id===he);de&&!await H(vn(de.root))||v(ce=>ce.filter(ee=>ee.id!==he))},[H]),B=y.useCallback(he=>{v(de=>de.map(ce=>ce.id===he?{...ce,minimized:!0}:ce))},[]);y.useEffect(()=>{const he=ce=>{const ee=ce.detail;!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId===e&&v(Ne=>{if(!Ne.find(Te=>Te.id===ee.groupId))return Ne;C.current+=1;const Me=C.current;return Ne.map(Te=>Te.id===ee.groupId?{...Te,minimized:!1,z:Me}:Te)})},de=async ce=>{var Me;const ee=ce.detail;if(!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId!==e)return;const Ne=k.current.find(Te=>Te.id===ee.groupId);if(Ne&&!await H(vn(Ne.root)))return;const je=(Ne==null?void 0:Ne.ownerWindowId)||Ft;je!==Ft&&(ge.current.delete(je),tt.current.delete(ee.groupId),(Me=le.current)==null||Me.post({t:"group-reclaimed",popoutId:je,groupIds:[ee.groupId],reason:"late-return"})),v(Te=>Te.filter(et=>et.id!==ee.groupId))};return window.addEventListener("session-windows:restore",he),window.addEventListener("session-windows:close",de),()=>{window.removeEventListener("session-windows:restore",he),window.removeEventListener("session-windows:close",de)}},[e,H]),y.useEffect(()=>{const he=sessionStorage.getItem("pendingSessionRestore");if(he)try{const de=JSON.parse(he);if(de.projectId!==e||!de.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),v(ce=>{if(!ce.find(je=>je.id===de.groupId))return ce;C.current+=1;const Ne=C.current;return ce.map(je=>je.id===de.groupId?{...je,minimized:!1,z:Ne}:je)})}catch{}},[e]);const A=y.useCallback(he=>{v(de=>{if(!de.find(Ne=>Ne.id===he))return de;C.current+=1;const ee=C.current;return de.map(Ne=>Ne.id===he?{...Ne,minimized:!1,z:ee}:Ne)})},[]),I=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>ee.id===he?{...ee,...de}:ee))},[]),Y=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>{if(ee.id===he){if(!de)return ee.dock?{...ee,dock:void 0}:ee;const Ne=Cl(de,window.innerWidth,window.innerHeight,Wa());return{...ee,...Ne,dock:de}}return de&&ee.dock===de?{...ee,dock:void 0}:ee}))},[]),G=y.useCallback((he,de,ce)=>{v(ee=>ee.map(Ne=>Ne.id===he?{...Ne,root:BS(Ne.root,de,ce)}:Ne))},[]),J=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>ee.id===he?{...ee,root:sr(ee.root,de)}:ee))},[]),re=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>ee.id===he?{...ee,root:MS(ee.root,de)}:ee))},[]),Z=y.useCallback((he,de,ce)=>{v(ee=>ee.map(Ne=>Ne.id===he?{...Ne,root:OS(Ne.root,de,ce)}:Ne))},[]),Q=y.useCallback((he,de,ce,ee)=>{if(ee.button!==0||!k.current.find(ve=>ve.id===he))return;ee.preventDefault();const je=ee.clientX,Me=ee.clientY;let Te=null;_({groupId:he,sessionId:de,fromPath:ce,startX:je,startY:Me,mouseX:je,mouseY:Me,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null,viewportZone:null});const et=(ve,ye)=>{const me=lw();Te=me;const nt=window.innerWidth,pt=window.innerHeight,jt={x:fu(ve-60,-Fu+vl,nt-vl),y:fu(ye-12,0,pt-Vm),w:Fu,h:Yp};v(Bt=>{const ze=Bt.find(un=>un.id===he);if(!ze)return Bt;const ut=Ki(ze.root,de),_t=ze.colors[de]||qi([]),Mt=ze.intents[de]??{intent:"open",nonce:0};C.current+=1;const At=C.current,_n={id:me,...jt,z:At,minimized:!1,root:mi([de],de),colors:{[de]:_t},intents:{[de]:Mt},ownerWindowId:Ft},kn=[];for(const un of Bt)if(un.id===he){if(ut){const rn=new Set(vn(ut)),us={};for(const In of Object.keys(un.colors))rn.has(In)&&(us[In]=un.colors[In]);const cr={};for(const In of Object.keys(un.intents))rn.has(In)&&(cr[In]=un.intents[In]);kn.push({...un,root:Bu(ut),colors:us,intents:cr})}}else kn.push(un);return kn.push(_n),kn})};let Ye=!1;const mt=ve=>{const ye=window.screenX,me=window.screenY,nt=ye+window.outerWidth,pt=me+window.outerHeight;return ve.screenX<ye-hu||ve.screenX>nt+hu||ve.screenY<me-hu||ve.screenY>pt+hu},bt=ve=>{if(Ye)return;const ye=w.current;if(!ye)return;if(!Te)Math.hypot(ve.clientX-je,ve.clientY-Me)>=ow&&et(ve.clientX,ve.clientY);else{const ut=window.innerWidth,_t=window.innerHeight,Mt=fu(ve.clientX-60,-640,ut-vl),At=fu(ve.clientY-12,0,_t-Vm);v(_n=>_n.map(kn=>kn.id===Te?{...kn,x:Mt,y:At}:kn))}if(Te&&mt(ve)&&k.current.some(ut=>ut.id===Te)){const ut=Ke.current;if(ut){Ye=!0;const _t=Te;Et(),_(null),ut(_t,{atScreenX:ve.screenX,atScreenY:ve.screenY});return}}let me=null,nt=null,pt=null,jt=null;const Bt=document.elementsFromPoint(ve.clientX,ve.clientY);for(const ut of Bt){const _t=ut.closest("[data-group-id][data-stack-path]");if(!_t)continue;const Mt=_t.dataset.groupId||"",At=_t.dataset.stackPath||"";if(Te?Mt===Te:Mt===ye.groupId&&At===ye.fromPath.join("."))continue;const kn=At===""?[]:At.split(".").map(Number),un=_t.getBoundingClientRect();me=Mt,nt=kn,pt={x:un.left,y:un.top,w:un.width,h:un.height},jt=rd(ve.clientX,ve.clientY,pt);break}const ze=jt||!Te?null:DS(ve.clientX,ve.clientY,window.innerWidth,window.innerHeight);_({...ye,mouseX:ve.clientX,mouseY:ve.clientY,hoveredGroupId:me,hoveredPath:nt,hoveredRect:pt,zone:jt,viewportZone:ze})};let yt=!1;const Et=()=>{yt||(yt=!0,window.removeEventListener("mousemove",bt),window.removeEventListener("mouseup",ae),window.removeEventListener("blur",Xe),window.removeEventListener("keydown",lt),document.removeEventListener("visibilitychange",Oe))},Xe=()=>{Et(),_(null)},lt=ve=>{ve.key==="Escape"&&Xe()},Oe=()=>{document.hidden&&Xe()},ae=ve=>{var nt;Et();const ye=w.current;if(_(null),!ye)return;if(ye.hoveredGroupId&&ye.hoveredPath&&ye.zone){const pt=Te||ye.groupId;W(pt,ye.sessionId,ye.hoveredGroupId,ye.hoveredPath,ye.zone);return}const me=ye.viewportZone;if(me&&Te&&k.current.some(pt=>pt.id===Te)){const pt=Te;if(me==="popout")(nt=Ke.current)==null||nt.call(Ke,pt,{atScreenX:ve.screenX,atScreenY:ve.screenY});else if(me==="max"){const jt=Cl(me,window.innerWidth,window.innerHeight,Wa());v(Bt=>Bt.map(ze=>ze.id===pt?{...ze,x:jt.x,y:jt.y,w:jt.w,h:jt.h}:ze))}else Y(pt,me);return}};window.addEventListener("mousemove",bt),window.addEventListener("mouseup",ae),window.addEventListener("blur",Xe),window.addEventListener("keydown",lt),document.addEventListener("visibilitychange",Oe)},[]),W=y.useCallback((he,de,ce,ee,Ne)=>{v(je=>{const Me=je.find(lt=>lt.id===he),Te=je.find(lt=>lt.id===ce);if(!Me||!Te)return je;if(he===ce){const lt=pi(Me.root,ee);if(!lt||lt.kind!=="stack")return je;const Oe=lt.tabs.find(me=>me!==de);if(!Oe)return je;const ae=Ki(Me.root,de);if(!ae)return je;const ve=eo(ae,Oe);if(!ve)return je;let ye;return Ne==="center"?ye=qa(ae,ve,de):ye=xl(ae,ve,Ne,mi([de])),ye=sr(ye,de),je.map(me=>me.id!==he?me:(C.current+=1,{...me,root:ye,z:C.current,minimized:!1}))}const et=Ki(Me.root,de),Ye=Me.colors[de],mt=Me.intents[de]??{intent:"open",nonce:0};let bt;if(Ne==="center")bt=qa(Te.root,ee,de);else{const lt=mi([de]);bt=xl(Te.root,ee,Ne,lt)}bt=sr(bt,de);const yt={...Te.colors};yt[de]||(yt[de]=Ye||qi(Object.values(yt)));const Et={...Te.intents,[de]:mt},Xe=[];for(const lt of je)if(lt.id===he){if(et){const Oe=new Set(vn(et)),ae={};for(const ye of Object.keys(lt.colors))Oe.has(ye)&&(ae[ye]=lt.colors[ye]);const ve={};for(const ye of Object.keys(lt.intents))Oe.has(ye)&&(ve[ye]=lt.intents[ye]);Xe.push({...lt,root:et,colors:ae,intents:ve})}}else lt.id===ce?(C.current+=1,Xe.push({...lt,root:bt,colors:yt,intents:Et,z:C.current,minimized:!1})):Xe.push(lt);return Xe})},[]),oe=y.useCallback((he,de,ce,ee)=>{v(Ne=>{if(he===de)return Ne;const je=Ne.find(yt=>yt.id===he),Me=Ne.find(yt=>yt.id===de);if(!je||!Me||je.root.kind!=="stack")return Ne;const Te=je.root;let et;ee==="center"?et=Te.tabs.reduce((yt,Et)=>qa(yt,ce,Et),Me.root):et=xl(Me.root,ce,ee,Te),et=sr(et,Te.activeTab);const Ye={...Me.colors,...je.colors},mt={...Me.intents,...je.intents},bt=[];for(const yt of Ne)yt.id!==he&&(yt.id===de?(C.current+=1,bt.push({...yt,root:et,colors:Ye,intents:mt,z:C.current,minimized:!1})):bt.push(yt));return bt})},[]),le=y.useRef(null),ge=y.useRef(new Map),[ue,Ve]=y.useState(null),We=y.useRef(ue);We.current=ue;const De=y.useRef(null),be=y.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0),[Re,ct]=y.useState(()=>typeof document<"u"&&document.hasFocus());y.useEffect(()=>{const he=()=>{be.current=Date.now(),ct(!0)},de=()=>ct(!1);window.addEventListener("focus",he),window.addEventListener("blur",de);const ce=IS();return()=>{window.removeEventListener("focus",he),window.removeEventListener("blur",de),ce(),De.current&&clearTimeout(De.current)}},[]);const tt=y.useRef(new Map),Ke=y.useRef(null),Le=y.useCallback((he,de)=>{var bt;const ce=k.current.find(yt=>yt.id===he);if(!ce)return;const ee=GO(),Ne={...ce,ownerWindowId:ee,dock:void 0};tt.current.set(he,Ne),ge.current.set(ee,Date.now()),v(yt=>yt.map(Et=>Et.id===he?{...Et,ownerWindowId:ee,dock:void 0}:Et)),(bt=le.current)==null||bt.post({t:"group-handoff",to:ee,groupId:he,group:Ne});const je=de&&(typeof de.atScreenX=="number"||typeof de.atScreenY=="number"),Me=je?Math.max(0,((de==null?void 0:de.atScreenX)??window.screenX+ce.x)-40):Math.max(0,window.screenX+ce.x),Te=je?Math.max(0,((de==null?void 0:de.atScreenY)??window.screenY+ce.y)-12):Math.max(0,window.screenY+ce.y),et=["popup",`width=${Math.max(400,ce.w)}`,`height=${Math.max(300,ce.h+40)}`,`left=${Me}`,`top=${Te}`].join(","),Ye=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(he)}?wid=${encodeURIComponent(ee)}`,mt=window.open(Ye,"_blank",et);if(!mt){tt.current.delete(he),ge.current.delete(ee),v(yt=>yt.map(Et=>Et.id===he?{...Et,ownerWindowId:Ft}:Et)),l(o("session.popout.blocked"));return}WO(ee,mt)},[e,o,l]);Ke.current=Le;const $e=y.useCallback(he=>{var ee;const de=k.current.find(Ne=>Ne.id===he);if(!de)return;const ce=de.ownerWindowId||Ft;if(ce===Ft){A(he);return}(ee=le.current)==null||ee.post({t:"group-recall",popoutId:ce,groupId:he}),setTimeout(()=>{var Me;const Ne=k.current.find(Te=>Te.id===he);if(!Ne||(Ne.ownerWindowId||Ft)===Ft)return;ge.current.delete(ce),tt.current.delete(he),(Me=le.current)==null||Me.post({t:"group-reclaimed",popoutId:ce,groupIds:[he],reason:"late-return"}),C.current+=1;const je=C.current;v(Te=>Te.map(et=>et.id===he?{...et,ownerWindowId:Ft,minimized:!1,z:je}:et))},1500)},[A]),Ie=y.useCallback(he=>{const de=Nr(k.current,he);de&&$e(de.id)},[$e]);y.useEffect(()=>{const he=de=>{const ce=de.detail;!(ce!=null&&ce.projectId)||!ce.groupId||ce.projectId!==e||$e(ce.groupId)};return window.addEventListener("session-windows:recall",he),()=>window.removeEventListener("session-windows:recall",he)},[e,$e]),y.useEffect(()=>{const he=sessionStorage.getItem("pendingSessionRecall");if(he)try{const de=JSON.parse(he);if(de.projectId!==e||!de.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const ce=de.groupId;setTimeout(()=>$e(ce),0)}catch{}},[e,$e]);const it=y.useCallback(he=>he.kind==="stack"?[]:[0,...it(he.children[0])],[]),vt=y.useCallback((he,de,ce)=>{const ee=de?k.current.find(Te=>Te.id===de):null,Ne=ee&&(ee.ownerWindowId||Ft)===Ft;if(!ee||!Ne){P(he,"start");return}const je=(()=>{if(ce){const Te=pi(ee.root,ce);if(Te&&Te.kind==="stack")return ce}return it(ee.root)})();C.current+=1;const Me=C.current;v(Te=>Te.map(et=>{if(et.id!==ee.id)return et;const Ye=sr(qa(et.root,je,he),he);return{...et,root:Ye,z:Me,minimized:!1,colors:{...et.colors,[he]:qi(Object.values(et.colors))},intents:{...et.intents,[he]:{intent:"start",nonce:0}}}}))},[P,it]),Ce=y.useCallback(async(he,de)=>{const ce=new Date,ee=String(ce.getHours()).padStart(2,"0"),Ne=String(ce.getMinutes()).padStart(2,"0"),je=String(ce.getSeconds()).padStart(2,"0"),Me=await Nm(e,{title:`Shell ${ee}:${Ne}:${je}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(Me),vt(Me.id,he,de),Me.id},[e,f,vt]);y.useEffect(()=>{const he=qp();le.current=he;const de=ee=>{var Ne;if(ee.t==="hello"){const je=tt.current.get(ee.groupId);if(je&&je.ownerWindowId===ee.from)he.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:je});else{const Me=k.current.find(Te=>Te.id===ee.groupId);Me&&Me.ownerWindowId===ee.from&&he.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:Me})}}else if(ee.t==="group-return"||ee.t==="bye")if(ee.t==="group-return"){const je=ee.group;je&&je.id===ee.groupId&&(tt.current.delete(ee.groupId),ge.current.delete(ee.from),ee.projectId&&ee.projectId!==e&&eB(ee.projectId,ee.groupId),v(Me=>{const Te=Me.find(Ye=>Ye.id===ee.groupId),et={...je,ownerWindowId:Ft,dock:void 0};return Te?Me.map(Ye=>Ye.id===ee.groupId?et:Ye):[...Me,et]}))}else ge.current.delete(ee.from),v(je=>je.map(Me=>Me.ownerWindowId===ee.from?{...Me,ownerWindowId:Ft}:Me));else if(ee.t==="group-close")tt.current.delete(ee.groupId),v(je=>je.filter(Me=>Me.id!==ee.groupId));else if(ee.t==="heartbeat")ge.current.set(ee.from,Date.now());else if(ee.t==="group-update"){const je=ee.patch;v(Me=>Me.map(Te=>Te.id===ee.groupId?{...Te,...je}:Te))}else if(ee.t==="dock-probe"){if(document.visibilityState!=="visible")return;const je=Pu(ee.x,ee.y),Me=Iu(je)?Ou(je.x,je.y):null;if(Me){const Te=We.current;(!Te||Te.zone!==Me.zone||Te.groupId!==Me.groupId||Te.path.join(".")!==Me.path.join("."))&&Ve({rect:Me.rect,zone:Me.zone,path:Me.path,groupId:Me.groupId}),De.current&&clearTimeout(De.current),De.current=setTimeout(()=>Ve(null),800);const et=Ji();he.post({t:"dock-probe-result",from:Ft,to:ee.from,hit:!0,focusAt:be.current,rect:{...HS(Me.rect.x,Me.rect.y),w:Me.rect.w*et,h:Me.rect.h*et},zone:Me.zone})}else We.current&&Ve(null),he.post({t:"dock-probe-result",from:Ft,to:ee.from,hit:!1,focusAt:be.current})}else if(ee.t==="dock-end")Ve(null);else if(ee.t==="dock-commit"&&ee.to===Ft){const je=Pu(ee.x,ee.y),Me=Iu(je)?Ou(je.x,je.y):null,Te=Me&&Me.zone?Me:(Ne=We.current)!=null&&Ne.zone?We.current:null;let et=!1;const Ye=ee.sessions.map(bt=>bt.id),mt=k.current.filter(bt=>(bt.ownerWindowId||Ft)===Ft);if(Te&&Te.zone&&!Ye.some(bt=>Nr(mt,bt))){const bt=k.current.find(Et=>Et.id===Te.groupId),yt=bt?pi(bt.root,Te.path):null;if(bt&&yt&&yt.kind==="stack"){et=!0;const Et=Te.zone,Xe=Te.path;C.current+=1;const lt=C.current;v(Oe=>Oe.map(ae=>{if(ae.id!==bt.id)return ae;const ve=zS(ae.root,Xe,Et,Ye,ee.activeId),ye={...ae.colors},me={...ae.intents};for(const nt of ee.sessions)ye[nt.id]||(ye[nt.id]=nt.color||qi(Object.values(ye))),me[nt.id]=nt.intentInfo??{intent:"open",nonce:0};return{...ae,root:ve,colors:ye,intents:me,z:lt,minimized:!1}}))}}Ve(null),he.post({t:"dock-commit-ack",from:Ft,to:ee.from,commitId:ee.commitId,accepted:et})}},ce=he.subscribe(de);return()=>{ce(),he.close(),le.current=null}},[e]),y.useEffect(()=>{const he=Date.now();for(const de of d.groups)de.ownerWindowId&&de.ownerWindowId!==Ft&&ge.current.set(de.ownerWindowId,he)},[]),y.useEffect(()=>{const he=async()=>{var Te;const ce=Date.now(),ee=[];for(const[et,Ye]of ge.current.entries())ce-Ye>PS&&ee.push(et);if(ee.length===0)return;const Ne=await $S(),je=ee.filter(et=>Ne.has(et)?(ge.current.set(et,ce),!1):!0);if(je.length===0)return;for(const et of je)ge.current.delete(et);const Me=new Set(je);for(const et of k.current)et.ownerWindowId&&Me.has(et.ownerWindowId)&&tt.current.delete(et.id);for(const et of je){const Ye=k.current.filter(mt=>mt.ownerWindowId===et).map(mt=>mt.id);Ye.length>0&&((Te=le.current)==null||Te.post({t:"group-reclaimed",popoutId:et,groupIds:Ye,reason:"heartbeat-timeout"}))}v(et=>et.map(Ye=>Ye.ownerWindowId&&je.includes(Ye.ownerWindowId)?{...Ye,ownerWindowId:Ft}:Ye))},de=setInterval(()=>{he()},Gp);return()=>clearInterval(de)},[]);const Ue=y.useCallback((he,de)=>{i({type:"session:terminal-input",sessionId:he,input:de})},[i]),we=y.useCallback(()=>{var ce,ee;const he=k.current.filter(Ne=>(Ne.ownerWindowId||Ft)===Ft).slice().sort((Ne,je)=>je.z-Ne.z),de=[];for(const Ne of he)for(const je of vn(Ne.root)){const Me=((ce=x.current.find(Te=>Te.id===je))==null?void 0:ce.title)||((ee=E.current[je])==null?void 0:ee.title)||je;de.push({sessionId:je,label:Me})}return de},[]),Pe=y.useCallback(async(he,de)=>{const ee=k.current.filter(je=>!je.minimized&&(je.ownerWindowId||Ft)===Ft).reduce((je,Me)=>je&&je.z>=Me.z?je:Me,null),Ne=await Nm(e,{title:de||"",description:he,use_worktree:!1,memory_inject_mode:"none"});f==null||f(Ne),vt(Ne.id,(ee==null?void 0:ee.id)??null)},[e,f,vt]),X=y.useMemo(()=>({openOrFocus:P,close:U,focus:O,minimize:F,restore:q,isOpen:$,recallPopout:Ie,closeGroup:K,minimizeGroup:B,restoreGroup:A,setGroupGeometry:I,setGroupDock:Y,setSplitSizes:G,setActiveTab:J,applyLayoutPreset:re,reorderTab:Z,beginTabDrag:Q,dockGroup:oe,popOutGroup:Le,createRawShellTab:Ce,sendToSession:Ue,listOpenTerminals:we,sendToNewTerminal:Pe}),[P,U,O,F,q,$,Ie,K,B,A,I,Y,G,J,re,Z,Q,oe,Le,Ce,Ue,we,Pe]),ne=y.useMemo(()=>{const he={};for(const de of g){const ee=(de.ownerWindowId||Ft)!==Ft?"popped":de.minimized?"minimized":"floating";for(const Ne of vn(de.root))he[Ne]=ee}return he},[g]);y.useEffect(()=>{const he=de=>{const ce=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ee=ce?de.metaKey:de.ctrlKey,Ne=ce?de.ctrlKey:de.metaKey;if(!ee||Ne||de.altKey||de.shiftKey||de.key.toLowerCase()!=="t")return;de.preventDefault();const Me=k.current.filter(Te=>!Te.minimized&&(Te.ownerWindowId||Ft)===Ft).reduce((Te,et)=>Te&&Te.z>=et.z?Te:et,null);Ce((Me==null?void 0:Me.id)??null).catch(()=>{})};return window.addEventListener("keydown",he),()=>window.removeEventListener("keydown",he)},[Ce]);const Se=y.useMemo(()=>{const he=new Map;for(const de of Object.values(j))he.set(de.id,de);for(const de of s)he.set(de.id,de);return he},[s,j]),fe=g.filter(he=>!he.minimized&&(he.ownerWindowId||Ft)===Ft),ie=fe.reduce((he,de)=>de.z>he.z?{id:de.id,z:de.z}:he,{id:null,z:-1/0}).id,ke=fe.find(he=>he.id===ie),_e=Re&&ke?to(ke.root).join(","):"",st=y.useMemo(()=>new Set(_e?_e.split(","):[]),[_e]),Ze=$p(u,st,(he,de)=>{var ee;const ce=Nr(k.current,he);!ce||ce.minimized||(ce.ownerWindowId||Ft)!==Ft||p(o(de==="blocked"?"notification.sessionBlocked":"notification.sessionDone"),((ee=Se.get(he))==null?void 0:ee.title)||he)});return t.jsx(Vp.Provider,{value:X,children:t.jsx(US.Provider,{value:ne,children:t.jsxs(Hp.Provider,{value:Ze,children:[m,(()=>{const he=new Map(fe.slice().sort((de,ce)=>de.z-ce.z).map((de,ce)=>[de.id,ce+1]));return fe.map(de=>{const ce=fe.filter(ee=>ee.id!==de.id).map(({x:ee,y:Ne,w:je,h:Me})=>({x:ee,y:Ne,w:je,h:Me}));return t.jsx($O,{group:de,sessionsById:Se,neighbors:ce,isTopmost:de.id===ie,zIndex:he.get(de.id)??1,sendMessage:i,subscribeBinary:a,onEvent:u},de.id)})})(),S&&S.hoveredRect&&t.jsx(Ka,{targetRect:S.hoveredRect,activeZone:S.zone}),S&&!S.zone&&Math.hypot(S.mouseX-S.startX,S.mouseY-S.startY)>=ow&&t.jsx(RS,{activeZone:S.viewportZone}),ue&&t.jsx(Ka,{targetRect:ue.rect,activeZone:ue.zone})]})})})}function sB(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const rB={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function iB({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:u,projectDefaultBranch:f,onAddSession:m,onUpdateSession:o,onStopSession:l,onDeleteSession:h,onCleanupSession:p}){const{t:d}=xt(),{confirm:g}=Yn(),{openOrFocus:v,recallPopout:C}=WS(),k=YO(),[x,S]=y.useState(!1),[_,w]=y.useState(!1),[j,R]=y.useState(null),[E,D]=y.useState(!1),[N,T]=y.useState(null),[z,P]=y.useState([]),[O,H]=y.useState(""),[U,F]=y.useState(null);y.useEffect(()=>{let J=!1;return mp().then(re=>{J||P(re)}).catch(()=>{}),()=>{J=!0}},[]),y.useEffect(()=>{if(!a)return;let J=!1;return x1(e).then(re=>{J||H(re.branch||"")}).catch(()=>{}),()=>{J=!0}},[e,a]);const q=y.useMemo(()=>{const J=new Map;for(const re of z)J.set(re.id,re);return J},[z]),$=y.useMemo(()=>j?s.find(J=>J.id===j)??null:null,[j,s]),K=y.useMemo(()=>{if($)return{title:$.title,description:$.description??"",cliTool:$.cli_tool??"",useWorktree:$.use_worktree===1,memoryInjectMode:$.memory_inject_mode??"none",memoryNodeIds:Kz($.memory_node_ids??null),memoryRawFilePaths:sB($.memory_raw_file_paths??null),tagId:$.tag_id??null}},[$]),B=y.useCallback(()=>{R(null),T(null),S(J=>!J)},[]),A=y.useCallback(J=>{S(!1),T(null),R(J)},[]),I=y.useCallback(()=>{S(!1),R(null),T(null)},[]),Y=y.useCallback(async(J,re,Z,Q,W,oe,le,ge)=>{w(!0);try{const ue=await Nm(e,{title:J,description:re||void 0,cli_tool:Z,use_worktree:Q,memory_inject_mode:W,memory_node_ids:oe,memory_raw_file_paths:le,tag_id:ge??null});m(ue),S(!1)}finally{w(!1)}},[e,m]),G=y.useCallback(async(J,re,Z,Q,W,oe,le,ge)=>{if(j){D(!0),T(null);try{const ue=await tL(j,{title:J,description:re||void 0,cli_tool:Z,use_worktree:Q,memory_inject_mode:W,memory_node_ids:oe,memory_raw_file_paths:le,tag_id:ge??null});o(ue),R(null)}catch(ue){T(ue instanceof Error?ue.message:String(ue))}finally{D(!1)}}},[j,o]);return t.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:J=>{yi(J)||(J.preventDefault(),F({x:J.clientX,y:J.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:d("tabs.sessions")}),t.jsxs("button",{onClick:B,className:"btn-primary text-xs py-2",disabled:_,children:["+ ",d("session.new")]})]}),x&&t.jsx(Py,{projectId:e,onSave:Y,onCancel:I,projectCliTool:i,isGitRepo:a,projectUseWorktree:u}),K&&j&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(Py,{projectId:e,initial:K,onSave:G,onCancel:I,projectCliTool:i,isGitRepo:a},j),(E||N)&&t.jsxs("div",{className:"text-xs px-1",children:[E&&t.jsx("span",{className:"text-warm-500",children:d("session.saving")||"saving…"}),N&&t.jsx("span",{className:"text-status-error",children:N})]})]}),s.length===0&&!x?t.jsx("div",{className:"card",children:t.jsx(Zi,{icon:wl,title:d("session.empty"),description:d("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((J,re)=>{const Z=["pending","failed","stopped","completed"].includes(J.status),Q=J.status==="running",W=J.status!=="running",oe=["stopped","failed","completed"].includes(J.status)&&!!J.resumable,le=j===J.id,ge=k[J.id]??"closed",ue=ge==="popped";return t.jsx("div",{className:`card overflow-hidden ${le?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:Ve=>{yi(Ve)||(Ve.preventDefault(),Ve.stopPropagation(),F({x:Ve.clientX,y:Ve.clientY,sessionId:J.id}))},children:t.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>ue?C(J.id):v(J.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:[J.tag_id&&q.get(J.tag_id)&&t.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-2xs font-medium",style:{backgroundColor:`${q.get(J.tag_id).color}22`,color:q.get(J.tag_id).color},children:[t.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:q.get(J.tag_id).color}}),q.get(J.tag_id).name]}),t.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:J.title}),t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs font-medium text-warm-500 whitespace-nowrap",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${rB[J.status]||"bg-warm-400"}`}),d(`status.${J.status}`)||J.status]}),ge!=="closed"&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:ue?d("session.dock.poppedHint"):void 0,children:[ue?t.jsx(qs,{size:12}):t.jsx("span",{"aria-hidden":"true",children:"·"}),d(`session.windowState.${ge}`)]})]}),J.description&&t.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:J.description}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.jsx("span",{className:"text-2xs text-warm-300",children:J.cli_tool||"claude"}),(J.branch_name||a&&(O||f))&&t.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[t.jsx(Qi,{size:12}),J.branch_name||O||f]})]})]}),t.jsxs("div",{className:"flex gap-1",onClick:Ve=>Ve.stopPropagation(),children:[ue&&t.jsx("button",{onClick:()=>C(J.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:d("session.recallToMain"),children:t.jsx(gi,{size:16})}),Z&&t.jsx("button",{onClick:()=>v(J.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md transition-colors",title:d("session.start"),children:t.jsx(Mr,{size:16})}),oe&&t.jsx("button",{onClick:()=>v(J.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:d("session.resumeHint")||d("session.resume"),children:t.jsx(vi,{size:16})}),t.jsx("button",{onClick:()=>A(J.id),disabled:!W,className:"p-1.5 text-warm-500 hover:text-warm-800 hover:bg-warm-100 rounded-md transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-warm-500",title:d(W?"session.edit":"session.editDisabledRunning"),children:t.jsx(pm,{size:16})}),Q&&t.jsx("button",{onClick:()=>l(J.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:d("session.stop"),children:t.jsx(Yi,{size:16})}),J.status!=="running"&&(!!J.worktree_path||!!J.branch_name)&&t.jsx("button",{onClick:async()=>{const Ve=J.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",J.branch_name),danger:!0}):!1;p(J.id,Ve)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:d("session.cleanup"),children:t.jsx(ku,{size:16})}),t.jsx("button",{onClick:()=>h(J.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:d("session.delete"),children:t.jsx(Pn,{size:16})})]})]})})},J.id)})}),U&&(()=>{const J=()=>F(null),re=U.sessionId?s.find(We=>We.id===U.sessionId):void 0;if(!re)return t.jsx(Gs,{x:U.x,y:U.y,onClose:J,children:t.jsxs("button",{type:"button",onClick:()=>{R(null),T(null),S(!0)},className:sn,children:[t.jsx(wn,{size:14}),d("session.new")]})});const Z=["pending","failed","stopped","completed"].includes(re.status),Q=re.status==="running",W=re.status!=="running",oe=["stopped","failed","completed"].includes(re.status)&&!!re.resumable,le=re.status!=="running"&&(!!re.worktree_path||!!re.branch_name),ge=k[re.id]??"closed",ue=ge==="popped",Ve=d(ue?"session.recallToMain":ge==="minimized"?"session.restoreWindow":ge==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(Gs,{x:U.x,y:U.y,onClose:J,children:[t.jsxs("button",{type:"button",onClick:()=>ue?C(re.id):v(re.id,"open"),className:sn,children:[ue?t.jsx(gi,{size:14}):t.jsx(wl,{size:14}),Ve]}),Z&&t.jsxs("button",{type:"button",onClick:()=>v(re.id,"start"),className:sn,children:[t.jsx(Mr,{size:14}),d("session.start")]}),oe&&t.jsxs("button",{type:"button",onClick:()=>v(re.id,"resume"),className:sn,title:d("session.resumeHint")||d("session.resume"),children:[t.jsx(vi,{size:14}),d("session.resume")]}),W&&t.jsxs("button",{type:"button",onClick:()=>A(re.id),className:sn,children:[t.jsx(pm,{size:14}),d("session.edit")]}),Q&&t.jsxs("button",{type:"button",onClick:()=>l(re.id),className:sn,children:[t.jsx(Yi,{size:14}),d("session.stop")]}),le&&t.jsxs("button",{type:"button",onClick:async()=>{const We=re.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",re.branch_name),danger:!0}):!1;p(re.id,We)},className:sn,children:[t.jsx(ku,{size:14}),d("session.cleanup")]}),t.jsx(oS,{}),t.jsxs("button",{type:"button",onClick:()=>h(re.id),className:Pp,children:[t.jsx(Pn,{size:14}),d("session.delete")]})]})})()]})}const Hu={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"}},aB=Object.keys(Hu),$u={pending:"bg-warm-200 text-warm-500",in_progress:"bg-status-running/10 text-status-running",done:"bg-status-success/10 text-status-success",moved:"bg-status-merged/10 text-status-merged"};function Va(e){const s=Hu[e]||Hu.default;return`${s.bg} ${s.text}`}function Xp({src:e,alt:s,onClose:i}){return y.useEffect(()=>{const a=u=>{u.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),cn.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(Jt,{size:16})}),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 Xm({anchorRef:e,width:s,onClose:i,className:a,style:u,children:f}){const m=y.useRef(null),[o,l]=y.useState(null);return y.useLayoutEffect(()=>{const h=e.current;if(!h)return;const p=h.getBoundingClientRect();let d=p.left;d+s>window.innerWidth-8&&(d=Math.max(8,window.innerWidth-8-s)),d<8&&(d=8),l({top:p.bottom+4,left:d})},[e,s]),y.useEffect(()=>{const h=d=>{var v,C;const g=d.target;(v=m.current)!=null&&v.contains(g)||(C=e.current)!=null&&C.contains(g)||i()},p=()=>i();return document.addEventListener("mousedown",h),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("mousedown",h),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[i,e]),o?cn.createPortal(t.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...u},children:f}),document.body):null}const cw={0:{label:"—",style:"text-warm-300"},1:{label:"●",style:"text-warm-500"},2:{label:"●●",style:"text-status-warning"},3:{label:"●●●",style:"text-status-error"}};function oB({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:l}){var we,Pe;const{t:h}=xt(),{confirm:p}=Yn(),[d,g]=y.useState(!1),[v,C]=y.useState(!1),[k,x]=y.useState(!1),S=y.useRef(null),_=y.useRef(null),[w,j]=y.useState({top:0,left:0}),[R,E]=y.useState(e.title),[D,N]=y.useState(e.description??""),[T,z]=y.useState(e.priority),[P,O]=y.useState(e.due_date??""),[H,U]=y.useState(e.status),[F,q]=y.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[$,K]=y.useState(""),[B,A]=y.useState(!1),[I,Y]=y.useState(null),[G,J]=y.useState(null),re=y.useRef(null),Z=y.useRef(null),[Q,W]=y.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),oe=y.useRef(null);y.useEffect(()=>{E(e.title),N(e.description??""),z(e.priority),O(e.due_date??""),U(e.status);try{q(e.tags?JSON.parse(e.tags):[])}catch{q([])}try{W(e.images?JSON.parse(e.images):[])}catch{W([])}},[e]);const le=F,ge=e.status==="moved",ue=e.due_date&&new Date(e.due_date)<new Date&&!ge&&e.status!=="done",Ve=y.useCallback(X=>{a(e.id,X)},[e.id,a]),We=()=>{const X=R.trim();X&&X!==e.title?Ve({title:X}):E(e.title)},De=()=>{const X=D.trim();X!==(e.description??"")&&Ve({description:X||void 0})},be=X=>{z(X),X!==e.priority&&Ve({priority:X})},Re=X=>{O(X),X!==(e.due_date??"")&&Ve({due_date:X||void 0})},ct=X=>{const ne=X;U(ne),ne!==e.status&&Ve({status:ne})},tt=X=>{q(X);const ne=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(X)!==JSON.stringify(ne)&&Ve({tags:X.length>0?JSON.stringify(X):void 0})},Ke=X=>{var Se;const ne=X.trim();if(ne&&!F.includes(ne)&&(tt([...F,ne]),!s.has(ne)&&l)){const fe=["blue","green","orange","purple","pink","red","yellow","brown"],ie=fe[s.size%fe.length];l(ne,{color:ie})}K(""),(Se=re.current)==null||Se.focus()},Le=X=>tt(F.filter(ne=>ne!==X)),$e=i.filter(X=>!F.includes(X)&&(!$||X.toLowerCase().includes($.toLowerCase()))),Ie=y.useCallback(X=>{const ne=Array.from(X).filter(ie=>ie.type.startsWith("image/")),Se=[];let fe=0;for(const ie of ne){const ke=new FileReader;ke.onload=()=>{Se.push({name:ie.name,data:ke.result}),fe++,fe===ne.length&&K1(e.id,Se).then(_e=>W(_e.images))},ke.readAsDataURL(ie)}},[e.id]),it=y.useCallback(X=>{var fe;const ne=(fe=X.clipboardData)==null?void 0:fe.items;if(!ne)return;const Se=[];for(let ie=0;ie<ne.length;ie++)if(ne[ie].type.startsWith("image/")){const ke=ne[ie].getAsFile();ke&&Se.push(ke)}Se.length!==0&&(X.preventDefault(),Ie(Se))},[Ie]),vt=y.useCallback(X=>{var ne;X.preventDefault(),X.stopPropagation(),(ne=X.dataTransfer)!=null&&ne.files&&Ie(X.dataTransfer.files)},[Ie]),Ce=y.useCallback(X=>{V1(e.id,X).then(()=>{W(ne=>ne.filter(Se=>Se.id!==X))})},[e.id]),Ue=y.useCallback(()=>{if(!S.current)return;const X=S.current.getBoundingClientRect(),ne=window.innerWidth,Se=window.innerHeight;let fe=X.bottom+4;const ie=_.current;if(ie){const ke=ie.offsetWidth,_e=ie.offsetHeight;let st=X.right-ke;st<8&&(st=8),st+ke>ne-8&&(st=ne-8-ke),fe+_e>Se-8&&(fe=X.top-_e-4),j({top:fe,left:st}),x(!0)}else j({top:fe,left:Math.max(8,X.right-180)})},[]);return y.useEffect(()=>{if(!d){x(!1);return}Ue();const X=requestAnimationFrame(Ue),ne=Se=>{var ie,ke;const fe=Se.target;(ie=S.current)!=null&&ie.contains(fe)||(ke=_.current)!=null&&ke.contains(fe)||g(!1)};return document.addEventListener("mousedown",ne),window.addEventListener("scroll",Ue,!0),window.addEventListener("resize",Ue),()=>{cancelAnimationFrame(X),document.removeEventListener("mousedown",ne),window.removeEventListener("scroll",Ue,!0),window.removeEventListener("resize",Ue)}},[d,Ue]),t.jsxs("div",{className:`${ge?"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:()=>C(!v),children:[t.jsx(ws,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${v?"rotate-90":""}`,onClick:X=>{X.stopPropagation(),C(!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}),ge&&e.converted_type&&t.jsxs("span",{className:"text-2xs text-status-merged",children:["→ ",e.converted_type==="todo"?h("planner.movedToTodo"):e.converted_type==="session"?h("planner.movedToSession"):h("planner.movedToSchedule")]}),e.source_discussion_id&&t.jsxs(Kn,{to:`/projects/${e.project_id}/discussions/${e.source_discussion_id}`,onClick:X=>X.stopPropagation(),className:"inline-flex items-center gap-1 text-2xs text-accent hover:underline mt-0.5",title:h("planner.fromDiscussion"),children:[t.jsx(aN,{size:12}),h("planner.fromDiscussion")]})]}),t.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[Q.length>0&&t.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-md text-[10px] font-medium bg-warm-100 text-warm-500 whitespace-nowrap",children:[t.jsx(Xa,{size:12}),Q.length]}),le.map(X=>t.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${Va(s.get(X)||"default")}`,children:X},X))]}),t.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:t.jsx("span",{className:`text-xs font-medium ${((we=cw[e.priority])==null?void 0:we.style)??"text-warm-300"}`,children:((Pe=cw[e.priority])==null?void 0:Pe.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 ${ue?"text-status-error 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:h("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 ${$u[e.status]||$u.pending}`,children:h(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:S,onClick:X=>{X.stopPropagation(),g(!d)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:t.jsx(cp,{size:14})}),d&&cn.createPortal(t.jsxs("div",{ref:_,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:w.top,left:w.left,opacity:k?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>g(!1),children:[!ge&&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(n1,{size:12})," ",h("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(Vi,{size:12})," ",h("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(bi,{size:12})," ",h("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await p({message:h("planner.deleteConfirm"),danger:!0})&&u()},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(Pn,{size:12})," ",h("planner.delete")]})]}),document.body)]})]}),v&&t.jsx("div",{className:"px-4 pb-3 pt-1 ml-8",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:R,onChange:X=>E(X.target.value),onBlur:We,onKeyDown:X=>{X.key==="Enter"&&(X.preventDefault(),We(),X.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:h("plannerForm.descPlaceholder"),value:D,onChange:X=>N(X.target.value),onPaste:it,onDrop:vt,onDragOver:X=>{X.preventDefault(),X.stopPropagation()},onBlur:De}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{var X;return(X=oe.current)==null?void 0:X.click()},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[t.jsx(Xa,{size:12}),h("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:h("plannerForm.pasteHint")})]}),t.jsx("input",{ref:oe,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:X=>{X.target.files&&Ie(X.target.files),X.target.value=""}}),Q.length>0&&t.jsx("div",{className:"flex flex-wrap gap-2",children:Q.map(X=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:Tu(e.id,X.id),alt:X.originalName,onClick:()=>J(Tu(e.id,X.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>Ce(X.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(Jt,{size:12})}),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:X.originalName})})]},X.id))})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:h("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(X=>t.jsxs("div",{className:"relative",children:[t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-2xs font-medium cursor-pointer hover:ring-1 hover:ring-warm-400 transition-all ${Va(s.get(X)||"default")}`,onClick:ne=>{Z.current=ne.currentTarget,Y(I===X?null:X)},children:[X,t.jsx("button",{onClick:ne=>{ne.stopPropagation(),Le(X)},className:"opacity-60 hover:opacity-100",children:t.jsx(Jt,{size:12})})]}),I===X&&t.jsxs(Xm,{anchorRef:Z,width:180,onClose:()=>Y(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:h("plannerTag.color")}),t.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:aB.map(ne=>t.jsx("button",{onClick:async()=>{l&&await l(X,{color:ne}),Y(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(X)===ne?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:h(`plannerTag.color.${ne}`),children:t.jsx("div",{className:`w-5 h-5 rounded-md ${Hu[ne].swatch}`})},ne))})]})]},X)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:re,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:$,onChange:X=>{K(X.target.value),A(!0)},onKeyDown:X=>{(X.key==="Enter"||X.key===",")&&$.trim()&&(X.preventDefault(),Ke($.replace(",",""))),X.key==="Backspace"&&!$&&F.length>0&&Le(F[F.length-1])},onFocus:()=>A(!0),onBlur:()=>setTimeout(()=>A(!1),150)}),B&&$e.length>0&&t.jsx(Xm,{anchorRef:re,width:160,onClose:()=>A(!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:$e.slice(0,8).map(X=>t.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>Ke(X),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium ${Va(s.get(X)||"default")}`,children:X})},X))})]})]})]}),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:h("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:T,onChange:X=>be(Number(X.target.value)),children:[t.jsx("option",{value:0,children:h("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:h("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:h("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:h("plannerForm.priorityCritical")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:h("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:P,onChange:X=>Re(X.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:h("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:H,onChange:X=>ct(X.target.value),children:[t.jsx("option",{value:"pending",children:h("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:h("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:h("plannerStatus.done")})]})]})]})]})}),G&&t.jsx(Xp,{src:G,onClose:()=>J(null)})]})}let lB=0;function cB({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:u,onUpdateTag:f}){const{t:m}=xt(),[o,l]=y.useState(""),[h,p]=y.useState(""),[d,g]=y.useState([]),[v,C]=y.useState(""),[k,x]=y.useState(i??""),[S,_]=y.useState(0),[w,j]=y.useState("pending"),[R,E]=y.useState(!1),[D,N]=y.useState(!1),[T,z]=y.useState([]),[P,O]=y.useState([]),[H,U]=y.useState(null),F=y.useRef(null),q=y.useRef(null),$=y.useRef(null),[K,B]=y.useState(new Map),A=new Map([...e.map(ue=>[ue.name,ue.color]),...K]),I=["blue","green","orange","purple","pink","red","yellow","brown"];y.useEffect(()=>{var ue;if(s){l(s.title),p(s.description??""),g(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),_(s.priority),j(s.status);try{O(s.images?JSON.parse(s.images):[])}catch{O([])}}(ue=F.current)==null||ue.focus()},[s]);const Y=e.filter(ue=>!d.includes(ue.name)&&(!v||ue.name.toLowerCase().includes(v.toLowerCase()))),G=ue=>{var We;const Ve=ue.trim();Ve&&!d.includes(Ve)&&g(De=>{const be=[...De,Ve];if(!A.has(Ve)){const Re=I[A.size%I.length];B(ct=>new Map([...ct,[Ve,Re]]))}return be}),C(""),N(!0),(We=q.current)==null||We.focus()},J=ue=>g(d.filter(Ve=>Ve!==ue)),re=y.useCallback(ue=>{const Ve=Array.from(ue).filter(We=>We.type.startsWith("image/"));for(const We of Ve){const De=new FileReader;De.onload=()=>{const be=De.result,Re=`pending-${++lB}`;z(ct=>[...ct,{id:Re,name:We.name,data:be,preview:be}])},De.readAsDataURL(We)}},[]),Z=y.useCallback(ue=>{var De;const Ve=(De=ue.clipboardData)==null?void 0:De.items;if(!Ve)return;const We=[];for(let be=0;be<Ve.length;be++)if(Ve[be].type.startsWith("image/")){const Re=Ve[be].getAsFile();Re&&We.push(Re)}We.length!==0&&(ue.preventDefault(),re(We))},[re]),Q=y.useCallback(ue=>{var Ve;ue.preventDefault(),ue.stopPropagation(),(Ve=ue.dataTransfer)!=null&&Ve.files&&re(ue.dataTransfer.files)},[re]),W=ue=>z(Ve=>Ve.filter(We=>We.id!==ue)),oe=ue=>{s&&V1(s.id,ue),O(Ve=>Ve.filter(We=>We.id!==ue))},le=P.length+T.length,ge=async()=>{if(o.trim()){E(!0);try{const ue=await a({title:o.trim(),description:h.trim()||void 0,tags:d.length>0?JSON.stringify(d):void 0,due_date:k||void 0,priority:S,...s?{status:w}:{}});if(f&&K.size>0&&await Promise.all([...K.entries()].map(([Ve,We])=>f(Ve,{color:We}))),T.length>0){const Ve=(s==null?void 0:s.id)??(ue==null?void 0:ue.id);Ve&&await K1(Ve,T.map(We=>({name:We.name,data:We.data})))}}finally{E(!1)}}};return t.jsxs("div",{className:"card p-5",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[t.jsx("input",{ref:F,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:ue=>l(ue.target.value),onKeyDown:ue=>{ue.key==="Enter"&&ue.preventDefault()}}),t.jsx("textarea",{className:"input-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:m("plannerForm.descPlaceholder"),value:h,onChange:ue=>p(ue.target.value),onPaste:Z,onDrop:Q,onDragOver:ue=>{ue.preventDefault(),ue.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var ue;return(ue=$.current)==null?void 0:ue.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[t.jsx(Xa,{size:14}),m("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),t.jsx("input",{ref:$,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:ue=>{ue.target.files&&re(ue.target.files),ue.target.value=""}}),le>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:["(",le,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[P.map(ue=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?Tu(s.id,ue.id):"",alt:ue.originalName,onClick:()=>s&&U(Tu(s.id,ue.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>oe(ue.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(Jt,{size:12})}),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:ue.originalName})})]},ue.id)),T.map(ue=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:ue.preview,alt:ue.name,onClick:()=>U(ue.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>W(ue.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(Jt,{size:12})}),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:ue.name})})]},ue.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:[d.map(ue=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Va(A.get(ue)||"default")}`,children:[ue,t.jsx("button",{onClick:()=>J(ue),className:"opacity-60 hover:opacity-100",children:t.jsx(Jt,{size:12})})]},ue)),t.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[t.jsx("input",{ref:q,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:d.length===0?m("plannerForm.tagsPlaceholder"):"",value:v,onChange:ue=>{C(ue.target.value),N(!0)},onKeyDown:ue=>{(ue.key==="Enter"||ue.key===",")&&v.trim()&&(ue.preventDefault(),G(v.replace(",",""))),ue.key==="Backspace"&&!v&&d.length>0&&J(d[d.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),D&&(Y.length>0||v.trim())&&t.jsxs(Xm,{anchorRef:q,width:208,onClose:()=>N(!1),className:"rounded-lg shadow-elevated z-tooltip py-1.5 max-h-48 overflow-y-auto",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[Y.slice(0,10).map(ue=>t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>G(ue.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Va(ue.color)}`,children:ue.name})},ue.name)),v.trim()&&!e.some(ue=>ue.name===v.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:()=>G(v),children:t.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',v.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:k,onChange:ue=>x(ue.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:S,onChange:ue=>_(Number(ue.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:w,onChange:ue=>j(ue.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:u,children:m("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:ge,disabled:!o.trim()||R,children:m("plannerForm.save")})]}),H&&t.jsx(Xp,{src:H,onClose:()=>U(null)})]})}function VS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:u}){const{t:f}=xt(),[m,o]=y.useState(i||"claude"),[l,h]=y.useState(""),[p,d]=y.useState(!1),[g,v]=y.useState("once"),[C,k]=y.useState("0 0 * * *"),[x,S]=y.useState(""),[_,w]=y.useState(!1),j=async()=>{w(!0);try{s==="todo"?await a({cli_tool:m,max_turns:l?Number(l):void 0}):s==="session"?await a({cli_tool:m,use_worktree:p}):await a({cli_tool:m,schedule_type:g,cron_expression:g==="recurring"?C:void 0,run_at:g==="once"?x:void 0})}finally{w(!1)}};return t.jsx(Dn,{open:!0,onClose:u,size:"md",position:"top",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:R=>o(R.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:l,onChange:R=>h(R.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:R=>d(R.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 ${g==="once"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>v("once"),children:f("plannerConvert.once")}),t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${g==="recurring"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>v("recurring"),children:f("plannerConvert.recurring")})]})]}),g==="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:R=>S(R.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:R=>k(R.target.value),placeholder:"0 0 * * *"})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:u,children:f("plannerConvert.cancel")}),t.jsx("button",{className:"btn-primary btn-sm",onClick:j,disabled:_||s==="schedule"&&g==="once"&&!x,children:f("plannerConvert.convert")})]})]})})}function yn(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 uw(e){return yn(new Date(e))}function dw(e){return new Date(e.getFullYear(),e.getMonth(),1)}function YS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function rr(e,s){const i=YS(e);return i.setDate(i.getDate()+s),i}function XS(e){return rr(e,-e.getDay())}function uB(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function dB(e,s,i,a){if(e==="resize-end")return{startKey:s.startKey,endKey:i<s.startKey?s.startKey:i};if(e==="resize-start")return{startKey:i>s.endKey?s.endKey:i,endKey:s.endKey};const u=uB(a,i),f=m=>yn(rr(new Date(m+"T00:00"),u));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function hB(e,s){if(e==="day"){const f=YS(s);return{rangeStart:yn(f),rangeEnd:yn(rr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=XS(s),m=Array.from({length:7},(o,l)=>rr(f,l));return{rangeStart:yn(f),rangeEnd:yn(rr(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=dw(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:yn(f),rangeEnd:yn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=dw(s),a=rr(i,-i.getDay()),u=Array.from({length:42},(f,m)=>rr(a,m));return{rangeStart:yn(a),rangeEnd:yn(rr(a,42)),gridDays:u,cols:7,dimOutOfMonth:!0}}function JS(e,s){return y.useMemo(()=>hB(e,s),[e,s])}function QS(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 ZS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=XS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${rr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function ek(){const{lang:e}=xt();return y.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>rr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const fB=420,mB=140,pB=220,gB=26,nm=16,hw=2;function xB(e,s){if(!s.length)return{placed:[],laneCount:0};const i=yn(e[0]),a=yn(e[e.length-1]),u=s.filter(o=>o.startKey<=a&&o.endKey>=i).map(o=>{const l=o.startKey<i?i:o.startKey,h=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(p=>yn(p)===l),endCol:e.findIndex(p=>yn(p)===h),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,l)=>o.startCol-l.startCol||l.endCol-l.startCol-(o.endCol-o.startCol)),f=[];return{placed:u.map(o=>{let l=0;for(;l<f.length&&f[l]>=o.startCol;)l++;return f[l]=o.endCol,{...o,lane:l}}),laneCount:f.length}}function tk({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:u,todayKey:f,selectedDate:m,chipsByDay:o,maxChips:l,weekdayLabels:h,addItemLabel:p,bars:d,onBarClick:g,onSelectDate:v,onQuickAdd:C,onChipClick:k,onCellContextMenu:x,onChipContextMenu:S,onBarContextMenu:_,onBarDrag:w,onChipDrag:j,monthCellHeight:R=92}){const{lang:E}=xt(),[D,N]=y.useState(null),[T,z]=y.useState(!1),P=y.useRef(null),O=y.useRef(null),H=()=>{O.current&&(clearTimeout(O.current),O.current=null)},U=(Z,Q)=>{H(),P.current&&clearTimeout(P.current);const W=Q.getBoundingClientRect();P.current=window.setTimeout(()=>N({key:Z,rect:W}),fB)},F=()=>{P.current&&(clearTimeout(P.current),P.current=null),O.current=window.setTimeout(()=>N(null),mB)};y.useEffect(()=>{if(!D){z(!1);return}const Z=requestAnimationFrame(()=>z(!0));return()=>cancelAnimationFrame(Z)},[D]),y.useEffect(()=>()=>{P.current&&clearTimeout(P.current),O.current&&clearTimeout(O.current)},[]),y.useEffect(()=>{if(!D)return;const Z=()=>N(null);return window.addEventListener("scroll",Z,!0),window.addEventListener("resize",Z),()=>{window.removeEventListener("scroll",Z,!0),window.removeEventListener("resize",Z)}},[D]);const q=D?o.get(D.key)??[]:[],[$,K]=y.useState(null),B=y.useRef(!1),A=4,I=(Z,Q)=>{var W,oe;return((oe=(W=document.elementFromPoint(Z,Q))==null?void 0:W.closest("[data-daykey]"))==null?void 0:oe.getAttribute("data-daykey"))??null},Y=(Z,Q,W)=>{Z.preventDefault(),Z.stopPropagation();const oe=I(Z.clientX,Z.clientY)??W.origStart,le=Z.clientX,ge=Z.clientY,ue=Q!=="move";let Ve=ue,We={startKey:W.origStart,endKey:W.origEnd};const De=()=>K({kind:W.kind,entryKey:W.entryKey,curStart:We.startKey,curEnd:We.endKey,title:W.title,bg:W.bg,fg:W.fg,done:W.done}),be=()=>{document.body.style.cursor=ue?"ew-resize":"grabbing",document.body.style.userSelect="none"};ue&&(be(),De());const Re=tt=>{if(!Ve){if(Math.abs(tt.clientX-le)<A&&Math.abs(tt.clientY-ge)<A)return;Ve=!0,be()}const Ke=I(tt.clientX,tt.clientY);Ke&&(We=dB(Q,{startKey:W.origStart,endKey:W.origEnd},Ke,oe),De())},ct=()=>{window.removeEventListener("pointermove",Re),window.removeEventListener("pointerup",ct),document.body.style.cursor="",document.body.style.userSelect="",K(null),Ve&&(B.current=!0,setTimeout(()=>{B.current=!1},0),!(We.startKey===W.origStart&&We.endKey===W.origEnd)&&(W.kind==="bar"&&W.bar?w==null||w(W.bar,We.startKey,We.endKey):W.kind==="chip"&&W.chip&&(j==null||j(W.chip,We.startKey,We.endKey))))};window.addEventListener("pointermove",Re),window.addEventListener("pointerup",ct)},G=(()=>{const Z=d??[];return $?$.kind==="bar"?Z.map(Q=>Q.key===$.entryKey?{...Q,startKey:$.curStart,endKey:$.curEnd}:Q):[...Z,{key:`__drag__${$.entryKey}`,title:$.title,startKey:$.curStart,endKey:$.curEnd,bg:$.bg,fg:$.fg,done:$.done}]:Z})(),J=(Z,Q)=>{const W=yn(Z),oe=o.get(W)??[],le=!a||Z.getMonth()===u,ge=W===f,ue=W===m,Ve=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",We=e==="month"&&oe.length>l;return t.jsxs("div",{"data-daykey":W,onClick:()=>{B.current||v(W)},onContextMenu:x?De=>x(W,De):void 0,onMouseEnter:We?De=>U(W,De.currentTarget):void 0,onMouseLeave:We?F:void 0,className:`group relative ${Ve} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?R+Q:void 0,backgroundColor:ue?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:le?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:Z.toLocaleDateString(E,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:ge?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:Z.getDate()})]}),t.jsx("button",{onClick:De=>{De.stopPropagation(),C(W)},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(wn,{size:14})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:Q||void 0},children:[oe.slice(0,l).map(De=>{if(($==null?void 0:$.kind)==="chip"&&$.entryKey===De.key)return null;const be=e==="month"&&!!(De.draggable&&j),Re={kind:"chip",entryKey:De.key,origStart:W,origEnd:W,title:De.title,bg:De.bg,fg:De.fg,done:De.done,chip:De};return t.jsxs("span",{onClick:ct=>{ct.stopPropagation(),!B.current&&k(De)},onPointerDown:be?ct=>Y(ct,"move",Re):void 0,onContextMenu:S?ct=>S(De,ct):void 0,className:`text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity ${be?"relative group/chip":""}`,style:{backgroundColor:De.bg,color:De.fg,textDecoration:De.done?"line-through":"none"},title:De.title,children:[De.prefix??"",De.time?`${De.time} `:"",De.title,be&&t.jsx("span",{onPointerDown:ct=>{ct.stopPropagation(),Y(ct,"resize-end",Re)},onClick:ct=>ct.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 group-hover/chip:opacity-100 cursor-ew-resize rounded-r-md",style:{backgroundColor:"rgba(127,127,127,0.5)"}})]},De.key)}),oe.length>l&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",oe.length-l]})]})]},W)},re=[];if(e==="month")for(let Z=0;Z<s.length;Z+=i)re.push(s.slice(Z,Z+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:h.map(Z=>t.jsx("div",{className:"px-2 py-1",children:Z},Z))}),e==="month"?t.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:re.map((Z,Q)=>{const{placed:W,laneCount:oe}=xB(Z,G),le=oe*(nm+hw);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[Z.map(ge=>J(ge,le)),W.map(({bar:ge,startCol:ue,endCol:Ve,lane:We,contStart:De,contEnd:be})=>{const Re=!!w&&!ge.key.startsWith("__drag__"),ct={kind:"bar",entryKey:ge.key,origStart:ge.startKey,origEnd:ge.endKey,title:ge.title,bg:ge.bg,fg:ge.fg,done:ge.done,bar:ge};return t.jsxs("div",{onClick:tt=>{tt.stopPropagation(),!B.current&&(g==null||g(ge))},onPointerDown:Re?tt=>Y(tt,"move",ct):void 0,onContextMenu:_?tt=>_(ge,tt):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{pointerEvents:$?"none":void 0,left:`calc(${ue} / ${i} * 100% + 2px)`,width:`calc(${Ve-ue+1} / ${i} * 100% - 4px)`,top:gB+We*(nm+hw),height:nm,backgroundColor:ge.bg,color:ge.fg,textDecoration:ge.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:De?0:4,borderBottomLeftRadius:De?0:4,borderTopRightRadius:be?0:4,borderBottomRightRadius:be?0:4},title:ge.title,children:[De?"◀ ":"",ge.title,be?" ▶":"",Re&&!De&&t.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),Y(tt,"resize-start",ct)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 left-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}}),Re&&!be&&t.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),Y(tt,"resize-end",ct)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}})]},ge.key)})]},Q)})}):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(Z=>J(Z,0))}),D&&(()=>{const Z=Math.max(D.rect.width,pB),Q=Math.min(Math.max(8,D.rect.left),window.innerWidth-Z-8),W=Math.max(8,Math.min(D.rect.top,window.innerHeight-120)),oe=window.innerHeight-W-16,le=Number(D.key.slice(8,10));return cn.createPortal(t.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:H,onMouseLeave:()=>N(null),style:{position:"fixed",left:Q,top:W,width:Z,maxHeight:oe,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:T?"scale(1)":"scale(0.96)",opacity:T?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:le}),t.jsx("div",{className:"flex flex-col gap-0.5",children:q.map(ge=>t.jsxs("span",{onClick:ue=>{ue.stopPropagation(),k(ge),N(null)},onContextMenu:S?ue=>S(ge,ue):void 0,className:"text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:ge.bg,color:ge.fg,textDecoration:ge.done?"line-through":"none"},title:ge.title,children:[ge.prefix??"",ge.time?`${ge.time} `:"",ge.title]},ge.key))})]}),document.body)})()]})}function vB(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function bB({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:u,onConvert:f,onDeleteItem:m,onUpdateRange:o}){const{t:l,lang:h}=xt(),[p,d]=y.useState(()=>new Date),[g,v]=y.useState(()=>yn(new Date)),[C,k]=y.useState(null),x=ek(),{gridDays:S,cols:_,dimOutOfMonth:w}=JS(e,p),j=yn(new Date),R=p.getMonth(),E=e==="month"?3:99,D=re=>d(Z=>QS(Z,e,re)),N=()=>{d(new Date),v(yn(new Date))},T=ZS(p,e,h);y.useEffect(()=>{e==="day"&&v(yn(p))},[e,p]);const z=260,P=760,O=y.useRef(null),[H,U]=y.useState(()=>{const re=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(re)&&re>=z&&re<=P?re:320});y.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(H))}catch{}},[H]);const F=re=>{re.preventDefault();const Z=W=>{var le;const oe=(le=O.current)==null?void 0:le.getBoundingClientRect();oe&&U(Math.min(P,Math.max(z,oe.right-W.clientX)))},Q=()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",Q),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",Z),window.addEventListener("pointerup",Q)},[q,$]=y.useState(new Map);y.useEffect(()=>{$(new Map)},[s]);const K=y.useMemo(()=>q.size===0?s:s.map(re=>{const Z=q.get(re.id);return Z?{...re,due_date:Z.due_date,end_date:Z.end_date}:re}),[s,q]),B=y.useCallback((re,Z,Q)=>{$(W=>new Map(W).set(re,{due_date:Z,end_date:Q})),o(re,Z,Q)},[o]),A=re=>!!(re.due_date&&re.end_date&&re.end_date.slice(0,10)>re.due_date.slice(0,10)),I=y.useMemo(()=>{const re=new Map;for(const Z of K){if(!Z.due_date||e==="month"&&A(Z))continue;const Q=Z.due_date.slice(0,10),W=Z.status==="done",oe=re.get(Q)??[];oe.push({key:Z.id,title:Z.title,bg:"var(--color-bg-secondary)",fg:W?"var(--color-text-muted)":"var(--color-text-secondary)",done:W,payload:Z,draggable:!0}),re.set(Q,oe)}return re},[K,e]),Y=y.useMemo(()=>e!=="month"?[]:K.filter(A).map(re=>{const Z=re.status==="done";return{key:re.id,title:re.title,startKey:re.due_date.slice(0,10),endKey:re.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:Z?"var(--color-text-muted)":"var(--color-text-secondary)",done:Z,payload:re}}),[K,e]),G=y.useMemo(()=>s.filter(re=>re.due_date&&re.due_date.slice(0,10)===g),[s,g]),J=y.useMemo(()=>s.filter(re=>!re.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:()=>D(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(op,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:T}),t.jsx("button",{onClick:()=>D(1),className:"btn-ghost p-1.5","aria-label":"next",children:t.jsx(ws,{size:16})}),t.jsx("button",{onClick:N,className:"btn-ghost text-xs px-2.5 py-1.5",children:l("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(tk,{view:e,gridDays:S,cols:_,dimOutOfMonth:w,monthIdx:R,todayKey:j,selectedDate:g,chipsByDay:I,maxChips:E,weekdayLabels:x,addItemLabel:l("agenda.addItem"),onSelectDate:v,onQuickAdd:a,onChipClick:re=>u(re.payload),onCellContextMenu:(re,Z)=>{Z.preventDefault(),k({x:Z.clientX,y:Z.clientY,dateKey:re})},bars:Y,onBarClick:re=>u(re.payload),onBarDrag:(re,Z,Q)=>B(re.payload.id,Z,Q),onChipDrag:(re,Z,Q)=>B(re.payload.id,Z,Q)})})]}),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:l("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:H},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(g+"T00:00").toLocaleDateString(h,{month:"long",day:"numeric",weekday:"short"})}),t.jsxs("button",{onClick:()=>a(g),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[t.jsx(wn,{size:14}),l("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:[G.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:l("agenda.dayEmpty")}),G.map(re=>t.jsx(fw,{item:re,tagColors:i,onEdit:u,onConvert:f,onDelete:m},re.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:l("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[J.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:l("agenda.backlogEmpty")}),J.map(re=>t.jsx(fw,{item:re,tagColors:i,onEdit:u,onConvert:f,onDelete:m},re.id))]})]})]})]}),C&&t.jsx(Gs,{x:C.x,y:C.y,onClose:()=>k(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>a(C.dateKey),children:[t.jsx(wn,{size:14}),l("planner.add")]})})]})}function fw({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:u}){const{t:f}=xt(),{confirm:m}=Yn(),[o,l]=y.useState(!1),[h,p]=y.useState(!1),[d,g]=y.useState({top:0,left:0}),v=y.useRef(null),C=y.useRef(null),k=vB(e.tags),x=e.status==="moved",S=y.useCallback(()=>{if(!v.current)return;const _=v.current.getBoundingClientRect(),w=window.innerWidth,j=window.innerHeight;let R=_.bottom+4;const E=C.current;if(E){const D=E.offsetWidth,N=E.offsetHeight;let T=_.right-D;T<8&&(T=8),T+D>w-8&&(T=w-8-D),R+N>j-8&&(R=_.top-N-4),g({top:R,left:T}),p(!0)}else g({top:R,left:Math.max(8,_.right-180)})},[]);return y.useEffect(()=>{if(!o){p(!1);return}S();const _=requestAnimationFrame(S),w=j=>{var E,D;const R=j.target;(E=v.current)!=null&&E.contains(R)||(D=C.current)!=null&&D.contains(R)||l(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",S,!0),window.addEventListener("resize",S),()=>{cancelAnimationFrame(_),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",S)}},[o,S]),t.jsxs("div",{className:`group flex items-start gap-2 rounded-lg px-2.5 py-2 ${x?"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 ${$u[e.status]||$u.pending}`,children:f(`plannerStatus.${e.status}`)}),k.map(_=>t.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Va(s.get(_)||"default")}`,children:_},_))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:v,onClick:_=>{_.stopPropagation(),l(!o)},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(cp,{size:14})}),o&&cn.createPortal(t.jsxs("div",{ref:C,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:d.top,left:d.left,opacity:h?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>l(!1),children:[!x&&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(n1,{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(Vi,{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(bi,{size:12})," ",f("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await m({message:f("planner.deleteConfirm"),danger:!0})&&u(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(Pn,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const mw={pending:0,in_progress:1,done:2,moved:3};function yB({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:u,onDeleteItem:f,onConvertToTodo:m,onConvertToSchedule:o,onConvertToSession:l,onUpdateTag:h,onDeleteTag:p,onExport:d,onImport:g,view:v,onChangeView:C}){const{t:k}=xt(),{warning:x}=Rs(),[S,_]=y.useState(!1),[w,j]=y.useState(null),[R,E]=y.useState(void 0),[D,N]=y.useState(""),[T,z]=y.useState(""),[P,O]=y.useState("created_at"),[H,U]=y.useState("desc"),[F,q]=y.useState(null),[$,K]=y.useState("todo"),[B,A]=y.useState(!1),[I,Y]=y.useState(!1),[G,J]=y.useState(null),re=y.useRef(null),Z=y.useRef(0),Q=async()=>{if(!(!d||B)){A(!0);try{await d()}finally{A(!1)}}},W=()=>{var Le;!g||B||(Le=re.current)==null||Le.click()},oe=async Le=>{var Ie;const $e=(Ie=Le.target.files)==null?void 0:Ie[0];if(Le.target.value="",!(!$e||!g)){A(!0);try{await g($e)}finally{A(!1)}}},le=Le=>!!(/\.(md|markdown)$/i.test(Le.name)||Le.type==="text/markdown"),ge=Le=>Array.from(Le.dataTransfer.types).includes("Files"),ue=Le=>{!g||B||ge(Le)&&(Le.preventDefault(),Z.current++,Y(!0))},Ve=Le=>{!g||B||ge(Le)&&(Le.preventDefault(),Le.dataTransfer.dropEffect="copy")},We=Le=>{g&&(Le.preventDefault(),Z.current=Math.max(0,Z.current-1),Z.current===0&&Y(!1))},De=async Le=>{var Ie;if(!g||(Le.preventDefault(),Z.current=0,Y(!1),B))return;const $e=(Ie=Le.dataTransfer.files)==null?void 0:Ie[0];if($e){if(!le($e)){x(k("planner.dropInvalidFile"));return}A(!0);try{await g($e)}finally{A(!1)}}},be=y.useMemo(()=>s.map(Le=>Le.name),[s]),Re=y.useMemo(()=>new Map(s.map(Le=>[Le.name,Le.color])),[s]),ct=y.useMemo(()=>{let Le=e.filter($e=>!(T&&$e.status!==T||D&&!($e.tags?(()=>{try{return JSON.parse($e.tags)}catch{return[]}})():[]).includes(D)));return Le=[...Le].sort(($e,Ie)=>{let it=0;switch(P){case"title":it=$e.title.localeCompare(Ie.title);break;case"tags":{const vt=$e.tags?(()=>{try{return JSON.parse($e.tags).join(",")}catch{return""}})():"",Ce=Ie.tags?(()=>{try{return JSON.parse(Ie.tags).join(",")}catch{return""}})():"";it=(vt||"zzz").localeCompare(Ce||"zzz");break}case"priority":it=$e.priority-Ie.priority;break;case"due_date":{const vt=$e.due_date||"9999",Ce=Ie.due_date||"9999";it=vt.localeCompare(Ce);break}case"status":it=(mw[$e.status]??9)-(mw[Ie.status]??9);break;case"created_at":it=$e.created_at.localeCompare(Ie.created_at);break}return H==="asc"?it:-it}),Le},[e,D,T,P,H]),tt=Le=>{P===Le?U($e=>$e==="asc"?"desc":"asc"):(O(Le),U(Le==="priority"?"desc":"asc"))},Ke=({field:Le})=>P!==Le?null:H==="asc"?t.jsx(_5,{size:12,className:"inline ml-0.5"}):t.jsx(x5,{size:12,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:[k("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:[v!=="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(Le=>t.jsx("button",{onClick:()=>C(Le),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:v===Le?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:k(`agenda.view.${Le}`)},Le))}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:D,onChange:Le=>N(Le.target.value),children:[t.jsx("option",{value:"",children:k("planner.filterTag")}),be.map(Le=>t.jsx("option",{value:Le,children:Le},Le))]}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:T,onChange:Le=>z(Le.target.value),children:[t.jsx("option",{value:"",children:k("planner.filterStatus")}),t.jsx("option",{value:"pending",children:k("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:k("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:k("plannerStatus.done")}),t.jsx("option",{value:"moved",children:k("plannerStatus.moved")})]}),d&&t.jsxs("button",{onClick:Q,disabled:B||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.exportTooltip"),children:[t.jsx(fm,{size:14,className:"inline-block shrink-0"}),k("planner.export")]}),g&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:W,disabled:B,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.importTooltip"),children:[t.jsx(ob,{size:14,className:"inline-block shrink-0"}),k("planner.import")]}),t.jsx("input",{ref:re,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:oe})]}),!S&&!w&&t.jsxs("button",{onClick:()=>_(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(wn,{size:14,className:"inline-block shrink-0"}),k("planner.add")]})]})]}),(S||w)&&t.jsx("div",{className:"mb-5",children:t.jsx(cB,{existingTags:s,editItem:w,initialDueDate:R,onSave:async Le=>{if(w){await u(w.id,Le),j(null);return}else{const $e=await a(Le);return _(!1),E(void 0),$e}},onCancel:()=>{_(!1),j(null),E(void 0)},onUpdateTag:h})}),v==="table"?t.jsxs("div",{className:"card relative",onDragEnter:g?ue:void 0,onDragOver:g?Ve:void 0,onDragLeave:g?We:void 0,onDrop:g?De:void 0,onContextMenu:Le=>{yi(Le)||(Le.preventDefault(),J({x:Le.clientX,y:Le.clientY}))},children:[I&&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(ob,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),t.jsx("div",{className:"text-sm font-semibold",children:k("planner.dropHint")}),t.jsx("div",{className:"text-xs text-warm-500 mt-1",children:k("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 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("title"),children:[k("planner.col.title"),t.jsx(Ke,{field:"title"})]}),t.jsxs("div",{className:"w-[160px] section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("tags"),children:[k("planner.col.tags"),t.jsx(Ke,{field:"tags"})]}),t.jsxs("div",{className:"w-12 text-center section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("priority"),children:[k("plannerForm.priority"),t.jsx(Ke,{field:"priority"})]}),t.jsxs("div",{className:"hidden md:block w-20 text-right section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("due_date"),children:[k("planner.col.dueDate"),t.jsx(Ke,{field:"due_date"})]}),t.jsxs("div",{className:"w-16 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("status"),children:[k("planner.col.status"),t.jsx(Ke,{field:"status"})]}),t.jsx("div",{className:"w-8"})]}),ct.length===0?t.jsx(Zi,{icon:GE,title:k("planner.empty"),description:k("planner.emptyHint")}):ct.map((Le,$e)=>t.jsx("div",{children:t.jsx(oB,{item:Le,tagColors:Re,existingTags:be,onSave:async(Ie,it)=>{await u(Ie,it)},onDelete:()=>f(Le.id),onConvertToTodo:()=>{q(Le),K("todo")},onConvertToSchedule:()=>{q(Le),K("schedule")},onConvertToSession:()=>{q(Le),K("session")},onUpdateTag:h})},Le.id))]}):t.jsx(bB,{view:v,items:ct,tagColors:Re,onQuickAdd:Le=>{j(null),E(Le),_(!0)},onEditItem:Le=>{_(!1),j(Le)},onConvert:(Le,$e)=>{q(Le),K($e)},onDeleteItem:f,onUpdateRange:(Le,$e,Ie)=>{u(Le,{due_date:$e,end_date:Ie})}}),F&&t.jsx(VS,{item:F,mode:$,projectCliTool:i,onConvert:async Le=>{$==="todo"?await m(F.id,Le):$==="session"?await l(F.id,Le):await o(F.id,Le),q(null)},onClose:()=>q(null)}),G&&t.jsx(Gs,{x:G.x,y:G.y,onClose:()=>J(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>{j(null),E(void 0),_(!0)},children:[t.jsx(wn,{size:14}),k("planner.add")]})})]})}const nk=y.createContext(null),wB=nk.Provider;function XP(){const e=y.useContext(nk);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const _B=y.lazy(()=>Xu(()=>import("./PlannerPageEditor-tQ8cSsEl.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),SB=800;function kB({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:l}=xt(),[h,p]=y.useState(null),[d,g]=y.useState("idle"),[v,C]=y.useState(null),k=y.useRef({title:"",content:null}),x=y.useRef(null);y.useEffect(()=>{let E=!1;return xL(e).then(D=>{E||(p(D),k.current={title:D.title,content:D.content??null})}),()=>{E=!0}},[e]);const S=y.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:E,content:D}=k.current;return g("saving"),vL(e,{title:E,content:D??void 0}).then(()=>g("saved"))},[e]);y.useEffect(()=>()=>{x.current&&S()},[S]);const _=y.useCallback(()=>{x.current&&clearTimeout(x.current),g("saving"),x.current=setTimeout(()=>{S()},SB)},[S]),w=E=>{k.current.title=E,p(D=>D&&{...D,title:E}),u(e,E),_()},j=E=>{k.current.content=E,_()},R=y.useCallback((E,D,N)=>{C({item:E,mode:D,onDone:N})},[]);return h?t.jsxs(wB,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:R},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:h.title,onChange:E=>w(E.target.value),placeholder:l("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:d==="saving"?l("planner.pages.saving"):d==="saved"?l("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(y.Suspense,{fallback:null,children:t.jsx(_B,{pageId:e,initialContent:h.content??null,onChange:j})})})]}),v&&t.jsx(VS,{item:v.item,mode:v.mode,projectCliTool:i,onConvert:async E=>{const{item:D,mode:N,onDone:T}=v;N==="todo"?await f(D.id,E):N==="session"?await o(D.id,E):await m(D.id,E),T==null||T(),C(null)},onClose:()=>C(null)})]}):null}const On=(e,s)=>({type:"heading",props:{level:e},content:s}),il=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},pw=e=>({type:"bulletListItem"}),Wi=e=>({type:"checkListItem"}),gw=()=>({type:"tasklist"}),xw=()=>({type:"calendar"}),CB=[{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:[On(1,"회의 노트"),il("날짜: "),il("참석자: "),On(2,"안건"),pw(),On(2,"논의"),il(),On(2,"액션 아이템"),gw()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[On(1,"프로젝트 플랜"),On(2,"개요"),il(),On(2,"마일스톤"),gw(),On(2,"일정"),xw(),On(2,"리스크 / 메모"),il()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[On(1,"위클리 플래너"),On(2,"이번 주 목표"),pw(),On(2,"요일별 할 일"),On(3,"월요일"),Wi(),On(3,"화요일"),Wi(),On(3,"수요일"),Wi(),On(3,"목요일"),Wi(),On(3,"금요일"),Wi(),On(3,"토요일"),Wi(),On(3,"일요일"),Wi(),On(2,"주간 일정"),xw()]}];function jB({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,u=null;const f=()=>{if(a=null,u===null)return;const l=u;u=null,e(l)},m=l=>{u=l.clientX,a===null&&(a=requestAnimationFrame(f))},o=l=>{a!==null&&cancelAnimationFrame(a),a=null,l.type==="pointerup"&&u!==null&&f(),u=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 vw=160,bw=480,yw="plannerSidebarWidth",ww="plannerSidebarCollapsed";function EB({projectId:e,...s}){const{t:i}=xt(),{confirm:a}=Yn(),[u,f]=y.useState([]),[m,o]=y.useState({kind:"work"}),[l,h]=y.useState("table"),[p,d]=y.useState(!1),[g,v]=y.useState({top:0,left:0}),C=y.useRef(null),k=y.useRef(null),x=y.useRef(!1),[S,_]=y.useState(()=>{const K=Number(localStorage.getItem(yw));return K>=vw&&K<=bw?K:208}),w=y.useCallback(K=>{var I;const B=((I=k.current)==null?void 0:I.getBoundingClientRect().left)??0,A=Math.round(Math.max(vw,Math.min(bw,K-B)));_(A),localStorage.setItem(yw,String(A))},[]),[j,R]=y.useState(()=>localStorage.getItem(ww)==="1"),E=()=>R(K=>(localStorage.setItem(ww,K?"0":"1"),!K)),D=240,N=()=>{var B;const K=(B=C.current)==null?void 0:B.getBoundingClientRect();if(K){const A=Math.min(K.left,window.innerWidth-D-8);v({top:K.bottom+4,left:Math.max(8,A)})}d(!0)};y.useEffect(()=>{if(!p)return;const K=()=>d(!1),B=A=>{var I;(I=C.current)!=null&&I.contains(A.target)||A.target.closest("[data-template-picker]")||d(!1)};return document.addEventListener("mousedown",B),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{document.removeEventListener("mousedown",B),window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[p]),y.useEffect(()=>{pL(e).then(K=>{f(K),x.current||(x.current=!0,K.length>0&&o({kind:"page",id:K[0].id}))})},[e]);const T=async K=>{d(!1);const B=await gL(e,K.title||i("planner.pages.untitled"),K.blocks?JSON.stringify(K.blocks):void 0);f(A=>[...A,B]),o({kind:"page",id:B.id})},z=async K=>{await a({message:i("planner.pages.deleteConfirm"),danger:!0})&&(await bL(K),f(B=>B.filter(A=>A.id!==K)),o(B=>B.kind==="page"&&B.id===K?{kind:"work"}:B))},P=y.useCallback((K,B)=>{f(A=>A.map(I=>I.id===K?{...I,title:B}:I))},[]),O=()=>{o({kind:"work"}),h(K=>K==="table"?"month":K)},H=()=>{o({kind:"work"}),h("table")},U=m.kind==="work",F=U&&l!=="table",q=U&&l==="table",$=(K,B,A,I,Y)=>t.jsxs("div",{onClick:B,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${K?"":"hover:bg-warm-50"}`,style:K?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[A,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:I}),Y]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[j?t.jsx("div",{className:"flex-shrink-0 flex flex-col items-center card p-1.5",children:t.jsx("button",{onClick:E,className:"p-1 text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.expand"),children:t.jsx(f1,{size:14})})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:k,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:S},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.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{ref:C,onClick:()=>p?d(!1):N(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(wn,{size:14})}),t.jsx("button",{onClick:E,className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.collapse"),children:t.jsx(h1,{size:14})})]})]}),u.map(K=>$(m.kind==="page"&&m.id===K.id,()=>o({kind:"page",id:K.id}),t.jsx(ll,{size:14,className:"text-warm-400 flex-shrink-0"}),K.title||i("planner.pages.untitled"),t.jsx("button",{onClick:B=>{B.stopPropagation(),z(K.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-status-error transition-all flex-shrink-0",children:t.jsx(Pn,{size:14})}))),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")}),$(F,O,t.jsx(hm,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),$(q,H,t.jsx(Eu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(jB,{onResize:w})]}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:m.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(kB,{pageId:m.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:P,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},m.id)}):t.jsx(yB,{...s,view:l,onChangeView:h})}),p&&cn.createPortal(t.jsx("div",{"data-template-picker":!0,className:"fixed z-tooltip rounded-xl py-1 shadow-elevated",style:{top:g.top,left:g.left,width:D,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:CB.map(K=>t.jsxs("button",{onClick:()=>T(K),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(K.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(K.descKey)})]},K.id))}),document.body)]})}const sk="webPanelTabs",NB="plannerWebPanelUrl",Jp="https://www.notion.so",LB="electronAPI"in window;function DB(e){const s=e.trim();return s?/^https?:\/\//i.test(s)?s:`https://${s}`:Jp}function Jm(e=""){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,8),src:e,url:e,title:""}}function TB(){var s;try{const i=JSON.parse(localStorage.getItem(sk)||"");if((s=i.tabs)!=null&&s.length){const a=i.tabs.map(({id:f,url:m})=>({id:f,src:m,url:m,title:""})),u=a.some(f=>f.id===i.activeId)?i.activeId:a[0].id;return{tabs:a,activeId:u}}}catch{}const e=Jm(localStorage.getItem(NB)||Jp);return{tabs:[e],activeId:e.id}}function RB(){const{t:e}=xt(),[{tabs:s,activeId:i},a]=y.useState(TB),u=s.find(j=>j.id===i)??s[0],[f,m]=y.useState(u.url),[o,l]=y.useState(!1),[h,p]=y.useState(!1),d=o&&h,g=y.useRef(null),v=y.useRef(null);y.useEffect(()=>{localStorage.setItem(sk,JSON.stringify({tabs:s.map(({id:j,url:R})=>({id:j,url:R})),activeId:i}))},[s,i]),y.useEffect(()=>{m(u.url)},[u.id,u.url]);const C=y.useCallback((j,R)=>{a(E=>({...E,tabs:E.tabs.map(D=>D.id===j?{...D,...R}:D)}))},[]),k=y.useCallback((j="")=>{var E;const R=Jm(j);a(D=>({tabs:[...D.tabs,R],activeId:R.id})),j||(E=g.current)==null||E.focus()},[]),x=j=>{a(R=>{const E=R.tabs.findIndex(N=>N.id===j),D=R.tabs.filter(N=>N.id!==j);if(D.length===0){const N=Jm();return{tabs:[N],activeId:N.id}}return R.activeId!==j?{...R,tabs:D}:{tabs:D,activeId:D[Math.min(E,D.length-1)].id}})},S=()=>{const j=DB(f);m(j),C(u.id,{src:j,url:j})};y.useEffect(()=>{var R;const j=window.electronAPI;return(R=j==null?void 0:j.onWebPanelOpenUrl)==null?void 0:R.call(j,E=>k(E))},[k]),y.useEffect(()=>{const j=v.current;if(!j)return;const R=()=>{j.style.pointerEvents="none"},E=()=>{j.style.pointerEvents=""};return window.addEventListener("mousedown",R,!0),window.addEventListener("mouseup",E,!0),window.addEventListener("blur",E),()=>{window.removeEventListener("mousedown",R,!0),window.removeEventListener("mouseup",E,!0),window.removeEventListener("blur",E)}},[]);const _=y.useCallback(j=>{if(!j)return;const R=j.dataset.tabId,E=N=>C(R,{title:N.title}),D=N=>{const{url:T,isMainFrame:z}=N;z!==!1&&C(R,{url:T})};return j.addEventListener("page-title-updated",E),j.addEventListener("did-navigate",D),j.addEventListener("did-navigate-in-page",D),()=>{j.removeEventListener("page-title-updated",E),j.removeEventListener("did-navigate",D),j.removeEventListener("did-navigate-in-page",D)}},[C]),w=j=>{if(j.title)return j.title;try{return new URL(j.url).hostname}catch{return e("web.newTab")}};return t.jsxs("div",{className:o?"fixed inset-0 z-modal flex flex-col":"flex flex-col flex-1 min-h-0",style:o?{backgroundColor:"var(--color-bg-card)"}:void 0,onKeyDown:j=>{(j.ctrlKey||j.metaKey)&&!j.altKey&&!j.shiftKey&&j.key.toLowerCase()==="t"&&(j.preventDefault(),k())},children:[t.jsxs("div",{role:"tablist",className:`${d?"hidden":"flex"} items-end gap-0.5 px-2 border-b border-theme-border overflow-x-auto`,children:[s.map(j=>t.jsxs("div",{role:"tab","aria-selected":j.id===i,onClick:()=>a(R=>({...R,activeId:j.id})),onMouseDown:R=>{R.button===1&&R.preventDefault()},onAuxClick:R=>{R.button===1&&(R.preventDefault(),x(j.id))},className:`flex items-center gap-1 px-3 py-1.5 text-xs whitespace-nowrap cursor-pointer transition-colors ${j.id===i?"border-b-2 border-accent text-accent font-medium":"text-theme-text-secondary hover:text-theme-text"}`,children:[t.jsx("span",{className:"truncate max-w-[160px]",children:w(j)}),t.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),x(j.id)},className:"p-0.5 rounded hover:bg-theme-hover",title:e("web.closeTab"),"aria-label":e("web.closeTab"),children:t.jsx(Jt,{size:12})})]},j.id)),t.jsx("button",{type:"button",onClick:()=>k(),className:"p-1 mb-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e("web.newTab"),"aria-label":e("web.newTab"),children:t.jsx(wn,{size:14})})]}),t.jsxs("form",{onSubmit:j=>{j.preventDefault(),S()},className:`${d?"hidden":"flex"} items-center gap-2 p-2 border-b border-theme-border`,children:[t.jsx("input",{ref:g,value:f,onChange:j=>m(j.target.value),placeholder:e("web.urlPlaceholder"),className:"input-field flex-1",spellCheck:!1}),t.jsx($t,{type:"submit",size:"sm",children:e("web.go")}),o&&t.jsx("button",{type:"button",onClick:()=>p(!0),className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e("web.hideBar"),"aria-label":e("web.hideBar"),children:t.jsx(lp,{size:14})}),t.jsx("button",{type:"button",onClick:()=>{l(j=>!j),p(!1)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e(o?"web.exitFullscreen":"web.fullscreen"),children:o?t.jsx(Tl,{size:14}):t.jsx(gi,{size:14})})]}),d&&t.jsx("button",{type:"button",onClick:()=>p(!1),className:"absolute top-0 left-1/2 -translate-x-1/2 z-10 px-3 py-0.5 rounded-b-md bg-theme-card border border-t-0 border-theme-border shadow-card text-warm-400 hover:text-warm-600 transition-colors",title:e("web.showBar"),"aria-label":e("web.showBar"),children:t.jsx(_i,{size:14})}),t.jsx("div",{ref:v,className:"flex-1 min-h-0 flex flex-col",children:LB?s.map(j=>j.src?y.createElement("webview",{key:j.id,ref:_,"data-tab-id":j.id,src:j.src,partition:"persist:webpanel",allowpopups:"",className:j.id===i?"flex-1 min-h-0":"hidden"}):j.id===i&&t.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-theme-text-secondary",children:e("web.emptyTab")},j.id)):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-sm text-theme-text-secondary",children:[t.jsx("span",{children:e("web.desktopOnly")}),t.jsxs($t,{size:"sm",className:"flex items-center gap-1.5",onClick:()=>window.open(u.url||Jp,"_blank","noopener"),children:[t.jsx(qs,{size:14}),e("web.openExternal")]})]})})]})}const MB=y.lazy(()=>Xu(()=>import("./AnalyticsPanel-CP-29VIV.js"),__vite__mapDeps([9,7,3,2]))),AB=y.lazy(()=>Xu(()=>import("./VaultLayout-D9R8grOG.js"),__vite__mapDeps([10,6,1,2,3,4])));function zB({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:u}=tp(),[f,m]=y.useState(null),[o,l]=y.useState([]),[h,p]=y.useState([]),[d,g]=y.useState(null),[v,C]=y.useState([]),[k,x]=y.useState([]),[S,_]=y.useState([]),[w,j]=y.useState([]),[R,E]=Qw(),D=["tasks","discussions","schedules","analytics"],N=R.get("tab")||"tasks",[T,z]=y.useState(D.includes(N)?"automation":N),[P,O]=y.useState(D.includes(N)?N:"tasks"),H=y.useCallback(ae=>{if(ae==="automation"){z("automation"),E(P==="tasks"?{}:{tab:P},{replace:!0});return}z(ae),E(ae==="tasks"?{}:{tab:ae},{replace:!0})},[E,P]),U=y.useCallback(ae=>{z("automation"),O(ae),E(ae==="tasks"?{}:{tab:ae},{replace:!0})},[E]),F=y.useMemo(()=>{if(!f)return[];let ae=[];try{ae=JSON.parse(f.hidden_tabs||"[]")}catch{}return f.is_git_repo||ae.push("git"),f.svn_enabled||ae.push("svn"),ae},[f]);y.useEffect(()=>{F.includes(T)&&H("automation")},[F,T,H]);const[q,$]=y.useState(!0),[K,B]=y.useState(!1),[A,I]=y.useState(new Set),[Y,G]=y.useState(0),{t:J}=xt(),{success:re,error:Z,info:Q}=Rs(),{sendNotification:W}=ro(),oe=y.useRef([]);y.useEffect(()=>{oe.current=v},[v]),y.useEffect(()=>{u&&Promise.all([e4(u),_f(u),kb(u),Cb(u),z3(),W1(u),Xc(u),Jc(u)]).then(([ae,ve,ye,me,nt,pt,jt,Bt])=>{m(ae),l(ve),p(ye),C(me),x(pt),_(jt),j(Bt),nt.resetsAt&&g(nt.resetsAt);const ze=ve.filter(ut=>ut.status==="running"&&ut.execution_mode==="interactive").map(ut=>ut.id);ze.length>0&&I(new Set(ze))}).catch(()=>B(!0)).finally(()=>$(!1))},[u]);const le=y.useRef(o);le.current=o,y.useEffect(()=>{if(!u)return;const ae=setInterval(()=>{le.current.some(ye=>ye.status==="running")&&_f(u).then(ye=>{l(me=>me.map(nt=>{const pt=ye.find(jt=>jt.id===nt.id);return pt&&pt.status!==nt.status?pt:nt}))}).catch(()=>{})},5e3);return()=>clearInterval(ae)},[u]);const ge=y.useRef(s);y.useEffect(()=>{s&&!ge.current&&u&&Promise.all([_f(u),kb(u),Cb(u)]).then(([ae,ve,ye])=>{l(ae),p(ve),C(ye)}).catch(()=>{}),ge.current=s},[s,u]),y.useEffect(()=>e(ae=>{if(ae.type==="todo:status-changed"&&ae.todoId&&ae.status){if(l(ve=>ve.map(ye=>{if(ye.id!==ae.todoId)return ye;const me={status:ae.status,updated_at:new Date().toISOString()};return ae.worktree_path!==void 0&&(me.worktree_path=ae.worktree_path??null),ae.branch_name!==void 0&&(me.branch_name=ae.branch_name??null),{...ye,...me}})),(ae.status==="completed"||ae.status==="merged"||ae.status==="failed")&&G(ve=>ve+1),ae.status==="completed"||ae.status==="failed"){const ve=le.current.find(ye=>ye.id===ae.todoId);ve&&W(ae.status==="completed"?J("notification.taskCompleted"):J("notification.taskFailed"),ve.title)}ae.status==="running"&&ae.mode==="interactive"?I(ve=>new Set(ve).add(ae.todoId)):ae.status!=="running"&&I(ve=>{const ye=new Set(ve);return ye.delete(ae.todoId),ye})}if(ae.type==="todo:created"&&ae.todo&&ae.todo.project_id===u){const ve=ae.todo;l(ye=>ye.some(me=>me.id===ve.id)?ye:[...ye,ve])}if(ae.type==="schedule:status-changed"&&ae.scheduleId&&p(ve=>ve.map(ye=>ye.id===ae.scheduleId?{...ye,is_active:ae.isActive?1:0,updated_at:new Date().toISOString()}:ye)),ae.type==="rate-limit:updated"&&ae.resetsAt&&g(ae.resetsAt),ae.type==="discussion:status-changed"&&ae.discussionId&&(C(ve=>ve.map(ye=>ye.id===ae.discussionId?{...ye,status:ae.status,current_round:ae.currentRound??ye.current_round,updated_at:new Date().toISOString()}:ye)),ae.status==="completed"||ae.status==="failed")){const ve=oe.current.find(ye=>ye.id===ae.discussionId);ve&&W(ae.status==="completed"?J("notification.discussionCompleted"):J("notification.discussionFailed"),ve.title)}ae.type==="session:status-changed"&&ae.sessionId&&x(ve=>ve.map(ye=>{if(ye.id!==ae.sessionId)return ye;const me={status:ae.status,updated_at:new Date().toISOString()};return ae.worktree_path!==void 0&&(me.worktree_path=ae.worktree_path),ae.branch_name!==void 0&&(me.branch_name=ae.branch_name),ae.cli_session_id!==void 0&&(me.cli_session_id=ae.cli_session_id),ae.resumable!==void 0&&(me.resumable=ae.resumable),{...ye,...me}}))}),[e,W,J]);const ue=y.useCallback(async(ae,ve,ye,me,nt,pt,jt,Bt,ze,ut)=>{if(!u)return;const _t=await _b(u,{title:ae,description:ve,cli_tool:ye,depends_on:nt,max_turns:pt??null,use_worktree:jt??null,...Bt?{memory_inject_mode:Bt}:{},...ze?{memory_node_ids:ze}:{},...ut?{memory_raw_file_paths:ut}:{}});if(me&&me.length>0){const Mt=await F1(_t.id,me.map(At=>({name:At.name,data:At.data})));_t.images=JSON.stringify(Mt.images)}l(Mt=>[...Mt,_t])},[u]),Ve=y.useCallback((ae,ve=[])=>{const ye=ae.split("/").filter(Boolean).pop()??ae,me=[ae,...ve].map(nt=>`@${nt}`).join(`
682
+ ${oe}`:""}`,children:[t.jsx("span",{"aria-label":re!=="unknown"?re:(I==null?void 0:I.status)||"unknown",className:re==="working"?"workspace-dot-pulse":void 0,style:{width:6,height:6,borderRadius:"50%",background:Z,flexShrink:0}}),t.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Ht,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:G,width:16,textAlign:"center"},children:">_"}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,color:Q?Z:void 0,fontWeight:Q?600:void 0},children:(I==null?void 0:I.title)||B}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:le=>{le.stopPropagation(),o(B)},"aria-label":"close-tab",title:_("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:t.jsx(Jt,{size:12})})]},B)}),N&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{N.createRawShellTab(i,s).catch(()=>{})},"aria-label":"new-tab",title:`${_("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${Ge.separator}`,color:Ge.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:t.jsx(wn,{size:14})}),t.jsx("div",{style:{flex:1,minWidth:8}}),U&&t.jsx("span",{title:U,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ge.dim,fontFamily:Ht,fontSize:9,padding:"0 7px",flexShrink:1},children:U}),t.jsx(_O,{sessionId:e.activeTab,sendMessage:d}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:D,"aria-label":"refresh-terminal",title:`${_("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${_("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:Is,children:t.jsx(kN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>j(-1),"aria-label":"decrease-font",title:`${_("session.fontDecrease")||"Decrease font size"} (${w}px) · Ctrl+- · Ctrl+wheel`,style:Is,children:t.jsx(YN,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>j(1),"aria-label":"increase-font",title:`${_("session.fontIncrease")||"Increase font size"} (${w}px) · Ctrl+= · Ctrl+wheel`,style:Is,children:t.jsx(KN,{size:14})}),t.jsx(yO,{sessionId:e.activeTab}),S&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&S.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{var B;return(B=S.onApplyLayoutPreset)==null?void 0:B.call(S,"single")},"aria-label":"single-pane",title:_("session.layout.single"),style:Is,children:t.jsx(Yi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{var B;return(B=S.onApplyLayoutPreset)==null?void 0:B.call(S,"columns")},"aria-label":"two-columns",title:_("session.layout.columns"),style:Is,children:t.jsx(l1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:()=>{var B;return(B=S.onApplyLayoutPreset)==null?void 0:B.call(S,"grid")},"aria-label":"grid-layout",title:_("session.layout.grid"),style:Is,children:t.jsx(u1,{size:14})})]}),S.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onToggleMaximize,"aria-label":"toggle-maximize",title:`${S.isMaximized?_("session.restoreSize"):_("session.maximize")} · ${_("session.maximizeHint")}`,style:Is,children:S.isMaximized?t.jsx(Tl,{size:14}):t.jsx(gi,{size:14})}),S.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onPopOutGroup,"aria-label":"pop-out",title:`${_("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Is,children:t.jsx(qs,{size:14})}),S.onReDockGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onReDockGroup,"aria-label":"redock",title:_("session.popout.redock")||"Re-dock to main window",style:Is,children:t.jsx(qs,{size:14,style:{transform:"scaleX(-1)"}})}),S.onMinimizeGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onMinimizeGroup,"aria-label":"minimize",title:`${_("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Is,children:t.jsx(dp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:B=>B.stopPropagation(),onClick:S.onCloseGroup,"aria-label":"close",title:`${_("session.close")||"Close"} (Ctrl+Shift+X)`,style:Is,children:t.jsx(Jt,{size:14})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:B=>{if(!B){p(s,null);return}const A=B.getBoundingClientRect();p(s,{x:A.left,y:A.top,w:A.width,h:A.height})},onMouseDown:F,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map(B=>{const A=a.get(B);if(!A)return null;const I=f[B]||{intent:"open",nonce:0};return t.jsx(NS,{session:A,visible:B===e.activeTab,intent:I.intent,intentNonce:I.nonce,onClose:()=>h(B),sendMessage:d,subscribeBinary:g,onEvent:v,onCycleTab:q,onSelectTab:$,remountKey:R[B]||0},B)})})]})}const Is={background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function LO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const u=y.useCallback(m=>{if(m.button!==0)return;m.preventDefault(),m.stopPropagation();const o=m.clientX,l=m.clientY;s();let h=!1;const p=()=>{h||(h=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",k),window.removeEventListener("blur",d),window.removeEventListener("keydown",g),document.removeEventListener("visibilitychange",v))},d=()=>{p(),a()},g=x=>{x.key==="Escape"&&d()},v=()=>{document.hidden&&d()},C=x=>{const S=e==="horizontal"?x.clientX-o:x.clientY-l;i(S)},k=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",k),window.addEventListener("blur",d),window.addEventListener("keydown",g),document.addEventListener("visibilitychange",v)},[e,s,i,a]),f=e==="horizontal";return t.jsx("div",{onMouseDown:u,style:{flex:"0 0 4px",background:Ge.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function Wp(e){const{node:s,path:i,onSplitSizes:a,zoomPath:u,...f}=e;return s.kind==="stack"?t.jsx(Up,{stack:s,path:i,...f}):t.jsx(DO,{split:s,path:i,onSplitSizes:a,zoomPath:u,stackProps:f})}const sw=80;function DO({split:e,path:s,onSplitSizes:i,zoomPath:a,stackProps:u}){const f=e.orientation==="horizontal",m=y.useRef(null),o=y.useRef([]),l=y.useRef(null);return t.jsx("div",{ref:m,style:{display:"flex",flexDirection:f?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((h,p)=>t.jsxs(y.Fragment,{children:[t.jsx("div",{ref:d=>{o.current[p]=d},style:{flex:a?"1 1 0%":`0 0 ${e.sizes[p]}%`,display:a&&a[s.length]!==p?"none":"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:t.jsx(Wp,{node:h,path:[...s,p],onSplitSizes:i,zoomPath:a,...u})}),!a&&p<e.children.length-1&&t.jsx(LO,{orientation:e.orientation,onDragStart:()=>{const d=m.current;if(!d)return;const g=e.sizes.slice();l.current={i:p,initialSizes:g,finalSizes:g.slice(),total:f?d.clientWidth:d.clientHeight}},onDrag:d=>{const g=l.current;if(!g||g.total<=0)return;const v=g.initialSizes[g.i]/100*g.total,C=g.initialSizes[g.i+1]/100*g.total,k=v+C,x=Math.max(sw,Math.min(k-sw,v+d)),S=k-x,_=x/g.total*100,w=S/g.total*100,j=o.current[g.i],R=o.current[g.i+1];j&&(j.style.flexBasis=`${_}%`),R&&(R.style.flexBasis=`${w}%`);const E=g.initialSizes.slice();E[g.i]=_,E[g.i+1]=w,g.finalSizes=E},onDragEnd:()=>{const d=l.current;d&&i(s,d.finalSizes),l.current=null}})]},p))})}const Lt=28,mn=68;function rd(e,s,i){const a=e-i.x,u=s-i.y;if(a<0||u<0||a>i.w||u>i.h)return null;const f=a-i.w/2,m=u-i.h/2;return Math.abs(f)<=Lt&&Math.abs(m)<=Lt?"center":f>=-mn-Lt&&f<=-mn+Lt&&Math.abs(m)<=Lt?"left":f>=mn-Lt&&f<=mn+Lt&&Math.abs(m)<=Lt?"right":m>=-mn-Lt&&m<=-mn+Lt&&Math.abs(f)<=Lt?"top":m>=mn-Lt&&m<=mn+Lt&&Math.abs(f)<=Lt?"bottom":null}function Ou(e,s){const i=document.elementsFromPoint(e,s);for(const a of i){const u=a.closest("[data-group-id][data-stack-path]");if(!u)continue;const f=u.dataset.stackPath||"",m=f===""?[]:f.split(".").map(Number),o=u.getBoundingClientRect(),l={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:u.dataset.groupId||"",path:m,rect:l,zone:rd(e,s,l)}}return null}function TO(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}}}const qm=mn*2+12;function DS(e,s,i,a){const u=e-i/2,f=s-a/2;return Math.abs(u)<=Lt&&Math.abs(f)<=Lt?"max":u>=-mn-Lt&&u<=-mn+Lt&&Math.abs(f)<=Lt?"left":u>=mn-Lt&&u<=mn+Lt&&Math.abs(f)<=Lt?"right":f>=-mn-Lt&&f<=-mn+Lt&&Math.abs(u)<=Lt?"top":f>=mn-Lt&&f<=mn+Lt&&Math.abs(u)<=Lt?"bottom":f>=-qm-Lt&&f<=-qm+Lt&&Math.abs(u)<=Lt?"popout":null}function TS(e,s,i,a,u){switch(e){case"left":return{x:u,y:0,w:s,h:a};case"right":return{x:i-s,y:0,w:s,h:a};case"top":return{x:u,y:0,w:i-u,h:s};case"bottom":return{x:u,y:a-s,w:i-u,h:s}}}function Cl(e,s,i,a){if(e==="max")return{x:a,y:0,w:s-a,h:i};const u=Math.round(e==="left"||e==="right"?(s-a)/2:i/2);return TS(e,u,s,i,a)}function Wa(){const e=document.querySelector("[data-app-sidebar]");return Math.max(0,e?e.getBoundingClientRect().right:0)}function RS({activeZone:e}){const s=window.innerWidth,i=window.innerHeight,a=s/2,u=i/2,f=e&&e!=="popout"?Cl(e,s,i,Wa()):null;return cn.createPortal(t.jsxs(t.Fragment,{children:[f&&t.jsx("div",{style:{position:"fixed",left:f.x,top:f.y,width:f.w,height:f.h,background:`${Ge.info}33`,border:`2px dashed ${Ge.info}`,borderRadius:8,pointerEvents:"none",zIndex:2400,transition:"left 80ms ease-out, top 80ms ease-out, width 80ms ease-out, height 80ms ease-out",boxSizing:"border-box"}}),t.jsxs("div",{style:{position:"fixed",inset:0,pointerEvents:"none",zIndex:2500},children:[t.jsx(Hs,{offsetX:a-Lt,offsetY:u-Lt,active:e==="max",kind:"center"}),t.jsx(Hs,{offsetX:a-mn-Lt,offsetY:u-Lt,active:e==="left",kind:"left"}),t.jsx(Hs,{offsetX:a+mn-Lt,offsetY:u-Lt,active:e==="right",kind:"right"}),t.jsx(Hs,{offsetX:a-Lt,offsetY:u-mn-Lt,active:e==="top",kind:"top"}),t.jsx(Hs,{offsetX:a-Lt,offsetY:u+mn-Lt,active:e==="bottom",kind:"bottom"}),t.jsx(Hs,{offsetX:a-Lt,offsetY:u-qm-Lt,active:e==="popout",kind:"popout"})]})]}),document.body)}function Ka({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,u=s?TO(e,s):null;return cn.createPortal(t.jsxs(t.Fragment,{children:[u&&t.jsx("div",{style:{position:"fixed",left:u.x,top:u.y,width:u.w,height:u.h,background:`${Ge.info}33`,border:`2px dashed ${Ge.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=mn+Lt;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(Hs,{offsetX:f-Lt,offsetY:f-Lt,active:s==="center",kind:"center"}),t.jsx(Hs,{offsetX:f-mn-Lt,offsetY:f-Lt,active:s==="left",kind:"left"}),t.jsx(Hs,{offsetX:f+mn-Lt,offsetY:f-Lt,active:s==="right",kind:"right"}),t.jsx(Hs,{offsetX:f-Lt,offsetY:f-mn-Lt,active:s==="top",kind:"top"}),t.jsx(Hs,{offsetX:f-Lt,offsetY:f+mn-Lt,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Hs({offsetX:e,offsetY:s,active:i,kind:a}){const u=Lt*2,f=i?Ge.info:"#3a3a3a",m=i?Ge.bright:Ge.separator;return t.jsx("div",{style:{position:"absolute",left:e,top:s,width:u,height:u,background:"#1a1a1a",border:`1px solid ${m}`,borderRadius:4,boxShadow:i?`0 0 8px ${Ge.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:t.jsx(RO,{kind:a,fill:f})})}function RO({kind:e,fill:s}){const i={position:"absolute",background:s};switch(e){case"center":return t.jsx("div",{style:{...i,inset:4}});case"popout":return t.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:t.jsx(qs,{size:24,color:s})});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 mi(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function pi(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 eo(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=eo(e.children[i],s);if(a)return[i,...a]}return null}function vn(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(vn)}function to(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(to)}function MS(e,s){const i=vn(e);if(i.length<=1||s==="single")return mi(i,to(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),u=Array.from({length:a},()=>[]);i.forEach((d,g)=>u[g%a].push(d));const f=new Set(to(e)),m=u.map(d=>mi(d,d.find(g=>f.has(g))||d[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),l=m.slice(2),h=d=>d.length===1?d[0]:{kind:"split",orientation:"horizontal",children:d,sizes:d.map(()=>100/d.length)};return{kind:"split",orientation:"vertical",children:[h(o),h(l)],sizes:[50,50]}}function Ki(e,s){return AS(e,s)}function AS(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=AS(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 u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function qa(e,s,i){return id(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 xl(e,s,i,a){const u=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return id(e,s,m=>({kind:"split",orientation:u,children:f?[a,m]:[m,a],sizes:[50,50]}))}function zS(e,s,i,a,u){const f=u&&a.includes(u)?u:a[a.length-1],m=i==="center"?a.reduce((o,l)=>qa(o,s,l),e):xl(e,s,i,mi(a,f));return sr(m,f)}function id(e,s,i){if(s.length===0)return Bu(i(e));if(e.kind!=="split")throw new Error("replaceAt: path traverses non-split");const[a,...u]=s;if(a<0||a>=e.children.length)throw new Error("replaceAt: bad path");const f=e.children.map((m,o)=>o===a?id(m,u,i):m);return Bu({...e,children:f})}function Bu(e){if(e.kind==="stack")return e;const s=e.children.map(Bu),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 l=m.sizes.reduce((h,p)=>h+p,0)||1;for(let h=0;h<m.children.length;h++)i.push(m.children[h]),a.push(m.sizes[h]/l*o)}else i.push(m),a.push(o)}if(i.length===1)return i[0];const u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function sr(e,s){return e.kind==="stack"?e.tabs.includes(s)?{...e,activeTab:s}:e:{...e,children:e.children.map(i=>sr(i,s))}}function OS(e,s,i){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const a=e.tabs.indexOf(s),u=Math.max(0,Math.min(i,e.tabs.length-1));if(u===a)return e;const f=e.tabs.slice();return f.splice(a,1),f.splice(u,0,s),{...e,tabs:f}}return{...e,children:e.children.map(a=>OS(a,s,i))}}function BS(e,s,i){return id(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 MO(e,s,i,a){const u=pi(e,i);if(!u||u.kind!=="stack"||a==="center"&&u.tabs.includes(s))return null;const f=u.tabs.find(h=>h!==s);if(!f)return null;const m=Ki(e,s);if(!m)return null;const o=eo(m,f);if(!o)return null;const l=a==="center"?qa(m,o,s):xl(m,o,a,mi([s]));return sr(l,s)}function AO(e,s,i){const a=i==="left"||i==="right"?"horizontal":"vertical",u=i==="right"||i==="down";for(let f=s.length-1;f>=0;f--){const m=pi(e,s.slice(0,f));if(!m||m.kind!=="split"||m.orientation!==a)continue;const o=s[f]+(u?1:-1);if(o<0||o>=m.children.length)continue;const l=zO(e,s,f,a);return[...s.slice(0,f),o,...OO(m.children[o],u,l,a)]}return null}function zO(e,s,i,a){let u=0,f=1;for(let m=i;m<s.length;m++){const o=pi(e,s.slice(0,m));if(!o||o.kind!=="split"||o.orientation===a)continue;const l=o.sizes.reduce((g,v)=>g+v,0)||1,h=o.sizes.slice(0,s[m]).reduce((g,v)=>g+v,0)/l,p=o.sizes[s[m]]/l,d=f-u;f=u+d*(h+p),u=u+d*h}return(u+f)/2}function OO(e,s,i,a){const u=[];let f=e,m=i;for(;f.kind==="split";){let o=f.children.length-1;if(f.orientation===a)o=s?0:f.children.length-1;else{const l=f.sizes.reduce((p,d)=>p+d,0)||1;let h=0;for(let p=0;p<f.children.length;p++){const d=f.sizes[p]/l;if(m<h+d||p===f.children.length-1){o=p,m=d>0?(m-h)/d:.5;break}h+=d}}u.push(o),f=f.children[o]}return u}function BO(e,s){const i=vn(e);let a=e;for(const u of i){if(!a)break;s.has(u)||(a=Ki(a,u))}return a}const ou=320,lu=200,cu=80,uu=22,PO=4,rw=8,oi=10,du=60,IO=12;function li(e,s,i){return Math.max(s,Math.min(i,e))}function FO(e,s,i,a){const u=e<=rw,f=e>=i-rw;if(!u&&!f)return null;const m=a/3,o=a*2/3;return u?s<m?"top-left":s>o?"bottom-left":"left":s<m?"top-right":s>o?"bottom-right":"right"}function iw(e,s,i){const a=Math.round(s/2),u=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:u};case"top-right":return{x:s-a,y:0,w:a,h:u};case"bottom-left":return{x:0,y:i-u,w:a,h:u};case"bottom-right":return{x:s-a,y:i-u,w:a,h:u}}}function HO(e,s,i,a,u){let f=e,m=s;const o=f,l=f+i,h=m,p=m+a;for(const d of u){const g=d.x,v=d.x+d.w,C=d.y,k=d.y+d.h;h<k&&p>C&&(Math.abs(o-v)<=oi?f=v:Math.abs(l-g)<=oi?f=g-i:Math.abs(o-g)<=oi?f=g:Math.abs(l-v)<=oi&&(f=v-i)),o<v&&l>g&&(Math.abs(h-k)<=oi?m=k:Math.abs(p-C)<=oi?m=C-a:Math.abs(h-C)<=oi?m=C:Math.abs(p-k)<=oi&&(m=k-a))}return{x:f,y:m}}function $O({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:u,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:l}=xt(),h=cS("(max-width: 767px)"),p=WS(),d=y.useRef(null),[g,v]=y.useState(!1),C=y.useRef(null),[k,x]=y.useState(null),S=y.useRef({x:e.x,y:e.y,w:e.w,h:e.h});S.current={x:e.x,y:e.y,w:e.w,h:e.h};const[_,w]=y.useState(null),j=y.useRef(null),[R,E]=y.useState(!1),[D,N]=y.useState(null),T=y.useRef(null),z=y.useRef(i);z.current=i;const[P,O]=y.useState(null),H=y.useRef(null),U=y.useCallback((be,Re)=>{if(h||g||be.button!==0||be.target.closest("[data-no-drag]"))return;be.preventDefault(),p.focus(vn(e.root)[0]||"");const tt=be.clientX,Ke=be.clientY,Le={...S.current},$e=d.current,Ie=window.innerWidth,it=window.innerHeight,vt=Wa();let Ce=!1,Ue="";Re&&$e&&(Ue=$e.style.pointerEvents,$e.style.pointerEvents="none");let we=!1;const Pe=()=>{we||(we=!0,window.removeEventListener("mousemove",ie),window.removeEventListener("mouseup",ke),window.removeEventListener("blur",X),window.removeEventListener("keydown",ne),document.removeEventListener("visibilitychange",Se),Re&&$e&&($e.style.pointerEvents=Ue))},X=()=>{Pe(),H.current=null,O(null),j.current=null,w(null),T.current=null,N(null),E(!1),p.setGroupGeometry(e.id,{...S.current})},ne=_e=>{_e.key==="Escape"&&X()},Se=()=>{document.hidden&&X()};let fe=!1;const ie=_e=>{if(fe)return;{const Me=window.screenX,Te=window.screenY,et=Me+window.outerWidth,Ye=Te+window.outerHeight;if(_e.screenX<Me-du||_e.screenX>et+du||_e.screenY<Te-du||_e.screenY>Ye+du){fe=!0,Pe(),H.current=null,O(null),j.current=null,w(null),T.current=null,N(null),E(!1),p.setGroupGeometry(e.id,{...S.current}),p.popOutGroup(e.id,{atScreenX:_e.screenX,atScreenY:_e.screenY});return}}const st=_e.clientX-tt,Ze=_e.clientY-Ke;let he=li(Le.x+st,-(Le.w-cu),Ie-cu),de=li(Le.y+Ze,0,it-uu);const ce=z.current;if(ce.length>0){const Me=HO(he,de,Le.w,Le.h,ce);he=Me.x,de=Me.y}if($e&&($e.style.left=`${he}px`,$e.style.top=`${de}px`),S.current.x=he,S.current.y=de,Re){let Me=null;const Te=document.elementFromPoint(_e.clientX,_e.clientY),et=Te==null?void 0:Te.closest("[data-group-id][data-stack-path]");if(et){const Ye=et.dataset.groupId||"";if(Ye!==e.id){const mt=et.dataset.stackPath||"",bt=mt===""?[]:mt.split(".").map(Number),yt=et.getBoundingClientRect(),Et={x:yt.left,y:yt.top,w:yt.width,h:yt.height};Me={groupId:Ye,path:bt,rect:Et,zone:rd(_e.clientX,_e.clientY,Et)}}}H.current=Me,O(Me?{rect:Me.rect,zone:Me.zone}:null)}!Ce&&Math.hypot(_e.clientX-tt,_e.clientY-Ke)>=IO&&(Ce=!0,E(!0),e.dock&&p.setGroupDock(e.id,null));const ee=Re&&H.current&&H.current.zone,Ne=ee||!Ce?null:DS(_e.clientX,_e.clientY,Ie,it);Ne!==T.current&&(T.current=Ne,N(Ne));const je=ee||Ne?null:FO(_e.clientX,_e.clientY,Ie,it);je!==j.current&&(j.current=je,w(je))},ke=_e=>{Pe(),E(!1);const st=T.current;if(T.current=null,N(null),Re&&H.current&&H.current.zone){const he=H.current;p.dockGroup(e.id,he.groupId,he.path,he.zone),H.current=null,O(null),j.current=null,w(null);return}if(st==="popout"){H.current=null,O(null),j.current=null,w(null),p.setGroupGeometry(e.id,{...S.current}),p.popOutGroup(e.id,{atScreenX:_e.screenX,atScreenY:_e.screenY});return}if(st&&st!=="max"){const he=Cl(st,Ie,it,vt);$e&&($e.style.left=`${he.x}px`,$e.style.top=`${he.y}px`,$e.style.width=`${he.w}px`,$e.style.height=`${he.h}px`),S.current=he,H.current=null,O(null),j.current=null,w(null),p.setGroupDock(e.id,st);return}const Ze=st?Cl(st,Ie,it,vt):j.current?iw(j.current,Ie,it):null;Ze&&($e&&($e.style.left=`${Ze.x}px`,$e.style.top=`${Ze.y}px`,$e.style.width=`${Ze.w}px`,$e.style.height=`${Ze.h}px`),S.current=Ze,j.current=null,w(null)),H.current=null,O(null),p.setGroupGeometry(e.id,{...S.current})};window.addEventListener("mousemove",ie),window.addEventListener("mouseup",ke),window.addEventListener("blur",X),window.addEventListener("keydown",ne),document.addEventListener("visibilitychange",Se)},[h,g,p,e.id,e.root,e.dock]),F=y.useCallback(be=>U(be,!1),[U]),q=y.useCallback(be=>U(be,!0),[U]),$=y.useCallback(be=>Re=>{if(h||g||Re.button!==0)return;Re.preventDefault(),Re.stopPropagation();const ct=Re.clientX,tt=Re.clientY,Ke={...S.current},Le=d.current,$e=window.innerWidth,Ie=window.innerHeight,it=ne=>{const Se=ne.clientX-ct,fe=ne.clientY-tt;let ie=Ke.x,ke=Ke.y,_e=Ke.w,st=Ke.h;be.includes("e")?_e=li(Ke.w+Se,ou,Math.max(ou,$e-Ke.x)):be.includes("w")&&(ie=li(Ke.x+Se,0,Ke.x+Ke.w-ou),_e=Ke.x+Ke.w-ie),be.includes("s")?st=li(Ke.h+fe,lu,Math.max(lu,Ie-Ke.y)):be.includes("n")&&(ke=li(Ke.y+fe,0,Ke.y+Ke.h-lu),st=Ke.y+Ke.h-ke),Le&&(Le.style.left=`${ie}px`,Le.style.top=`${ke}px`,Le.style.width=`${_e}px`,Le.style.height=`${st}px`),S.current={x:ie,y:ke,w:_e,h:st}};let vt=!1;const Ce=()=>{vt||(vt=!0,window.removeEventListener("mousemove",it),window.removeEventListener("mouseup",X),window.removeEventListener("blur",Ue),window.removeEventListener("keydown",we),document.removeEventListener("visibilitychange",Pe))},Ue=()=>{Ce(),p.setGroupGeometry(e.id,{...S.current})},we=ne=>{ne.key==="Escape"&&Ue()},Pe=()=>{document.hidden&&Ue()},X=()=>{Ce(),p.setGroupGeometry(e.id,{...S.current})};window.addEventListener("mousemove",it),window.addEventListener("mouseup",X),window.addEventListener("blur",Ue),window.addEventListener("keydown",we),document.addEventListener("visibilitychange",Pe)},[h,g,p,e.id]);y.useEffect(()=>{if(h||e.dock)return;const be=()=>{const Re=window.innerWidth,ct=window.innerHeight,tt=S.current,Ke=li(tt.x,-(tt.w-cu),Re-cu),Le=li(tt.y,0,ct-uu);(Ke!==tt.x||Le!==tt.y)&&p.setGroupGeometry(e.id,{...tt,x:Ke,y:Le})};return window.addEventListener("resize",be),()=>window.removeEventListener("resize",be)},[h,p,e.id,e.dock]);const K=y.useCallback(be=>{x(be),p.setActiveTab(e.id,be),p.focus(be)},[p,e.id]),B=y.useCallback(be=>{x(be),p.focus(be)},[p]),A=y.useCallback(be=>{p.close(be)},[p]),I=y.useCallback((be,Re,ct)=>{p.beginTabDrag(e.id,be,Re,ct)},[p,e.id]),Y=y.useCallback(be=>{p.close(be)},[p]),G=y.useCallback((be,Re)=>{p.setSplitSizes(e.id,be,Re)},[p,e.id]),J=to(e.root),re=vn(e.root);y.useEffect(()=>{k&&re.includes(k)||x(J[0]||re[0]||null)},[k,J,re]);const[Z,Q]=y.useState(null),W=Z&&e.root.kind==="split"?eo(e.root,Z):null,oe=!!Z&&!W;y.useEffect(()=>{oe&&Q(null)},[oe]);const le=y.useCallback(()=>{if(g){const be=C.current;be&&p.setGroupGeometry(e.id,be),C.current=null,v(!1);return}C.current={...S.current},e.dock&&p.setGroupDock(e.id,null),p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(ou,window.innerWidth-12),h:Math.max(lu,window.innerHeight-12)}),v(!0)},[p,e.id,g,e.dock]),ge=be=>{const Re=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ct=Re?be.metaKey:be.ctrlKey,tt=Re?be.ctrlKey:be.metaKey;if(!ct||tt||be.altKey||!be.shiftKey)return;const Ke=be.key.toLowerCase();if(Ke==="o")be.preventDefault(),p.popOutGroup(e.id);else if(Ke==="m")be.preventDefault(),p.minimizeGroup(e.id);else if(Ke==="x")be.preventDefault(),p.closeGroup(e.id);else if(Ke==="z")be.preventDefault(),e.root.kind==="split"?Q(Le=>Le?null:k):le();else if(Ke.startsWith("arrow")){be.preventDefault();const Le=k?eo(e.root,k):null,$e=Le?AO(e.root,Le,Ke.slice(5)):null,Ie=$e?pi(e.root,$e):null;if(!$e||!Ie||Ie.kind!=="stack")return;B(Ie.activeTab),Z&&Q(Ie.activeTab);const it=`[data-stack-path="${$e.join(".")}"] .xterm-helper-textarea`;requestAnimationFrame(()=>{var Ce,Ue;(Ue=Array.from(((Ce=d.current)==null?void 0:Ce.querySelectorAll(it))??[]).find(we=>we.offsetParent!==null))==null||Ue.focus()})}};if(h){const be=J[0],Re=be?s.get(be):null;if(!Re)return null;const ct=e.intents[be]??{intent:"open",nonce:0};return cn.createPortal(t.jsxs("div",{style:{position:"fixed",inset:0,background:Ge.bg,display:"flex",flexDirection:"column",zIndex:110},children:[t.jsxs("div",{style:{background:Ge.titleBg,height:uu,display:"flex",alignItems:"center",borderBottom:`1px solid ${Ge.separator}`},children:[t.jsx("span",{style:{flex:1,color:Ge.titleText,fontFamily:Ht,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Re.title}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ci,"aria-label":"close",children:t.jsx(Jt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(NS,{session:Re,visible:!0,intent:ct.intent,intentNonce:ct.nonce,onClose:()=>p.close(be),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const ue=_?(()=>{const be=window.innerWidth,Re=window.innerHeight,ct=iw(_,be,Re);return cn.createPortal(t.jsx("div",{style:{position:"fixed",left:ct.x,top:ct.y,width:ct.w,height:ct.h,background:`${Ge.info}33`,border:`2px dashed ${Ge.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,Ve=(()=>{var Re;if(re.length===0)return"";const be=((Re=s.get(re[0]))==null?void 0:Re.title)||re[0];return re.length===1?be:`${be} +${re.length-1}`})(),We=e.root.kind==="split",De=cn.createPortal(t.jsxs("div",{ref:d,onKeyDown:ge,onMouseDown:We?()=>p.focus(re[0]||""):q,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:u,background:Ge.bg,border:`1px solid ${a?Ge.info:Ge.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 ${Ge.info}66, 0 0 18px ${Ge.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:[We&&t.jsxs("div",{onMouseDown:F,onDoubleClick:be=>{be.target.closest("button")||le()},style:{height:uu,flexShrink:0,display:"flex",flexDirection:"column",background:Ge.titleBg,borderBottom:`1px solid ${Ge.separator}`,userSelect:"none",cursor:"move"},children:[t.jsx("div",{style:{display:"flex",height:PO,flexShrink:0},children:J.map((be,Re)=>t.jsx("div",{style:{flex:1,background:e.colors[be]||Ge.titleText}},Re))}),t.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:Ge.titleText,fontFamily:Ht,fontSize:11},children:[t.jsx("span",{style:{color:Ge.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ve}),re.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:ci,"aria-label":"single-pane",title:l("session.layout.single"),children:t.jsx(Yi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:ci,"aria-label":"two-columns",title:l("session.layout.columns"),children:t.jsx(l1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:ci,"aria-label":"grid-layout",title:l("session.layout.grid"),children:t.jsx(u1,{size:14})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:le,style:ci,"aria-label":"toggle-maximize",title:`${l(g?"session.restoreSize":"session.maximize")} · ${l("session.maximizeHint")}`,children:g?t.jsx(Tl,{size:14}):t.jsx(gi,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:be=>be.stopPropagation(),onClick:()=>p.popOutGroup(e.id),style:ci,"aria-label":"pop-out",title:`${l("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:t.jsx(qs,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.minimizeGroup(e.id),style:ci,"aria-label":"minimize",title:`${l("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:t.jsx(dp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:ci,"aria-label":"close",title:`${l("session.close")||"Close"} (Ctrl+Shift+X)`,children:t.jsx(Jt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(Wp,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:A,onTabMouseDown:I,onPaneAutoClose:Y,registerRect:()=>{},onSplitSizes:G,zoomPath:W??void 0,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:B}):t.jsx(Up,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:A,onTabMouseDown:I,onPaneAutoClose:Y,registerRect:()=>{},sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:B,groupActions:{onMinimizeGroup:()=>p.minimizeGroup(e.id),onCloseGroup:()=>p.closeGroup(e.id),onPopOutGroup:()=>p.popOutGroup(e.id),onToggleMaximize:le,isMaximized:g,onApplyLayoutPreset:be=>p.applyLayoutPreset(e.id,be)}})}),t.jsx("div",{onMouseDown:$("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:$("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),t.jsx("div",{onMouseDown:$("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:$("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:$("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:[De,ue,R&&!(P!=null&&P.zone)&&t.jsx(RS,{activeZone:D}),P&&t.jsx(Ka,{targetRect:P.rect,activeZone:P.zone})]})}const ci={background:"transparent",border:"none",color:Ge.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},tm=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function qi(e){for(const s of tm)if(!e.includes(s))return s;return tm[e.length%tm.length]}const UO="clitrigger:session-windows:global";function qp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(UO),s=new Set;return e.onmessage=i=>{const a=i.data;for(const u of s)try{u(a)}catch{}},{post:i=>{e.postMessage(i)},subscribe:i=>(s.add(i),()=>{s.delete(i)}),close:()=>{s.clear(),e.close()}}}const Ft="main",Gm=new Map;function WO(e,s){Gm.set(e,s)}function qO(e){const s=Gm.get(e);if(!s||s.closed)return Gm.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function GO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Gp=5e3,PS=15e3;let $a=null;function Ji(){var i;const e=window.electronAPI,s=(i=e==null?void 0:e.getZoomFactor)==null?void 0:i.call(e);return typeof s=="number"&&s>0?s:1}function IS(){if(typeof window>"u")return()=>{};const e=s=>{const i=Ji();$a={ox:s.screenX-s.clientX*i,oy:s.screenY-s.clientY*i,wx:window.screenX,wy:window.screenY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function FS(){if($a)return{ox:$a.ox+(window.screenX-$a.wx),oy:$a.oy+(window.screenY-$a.wy)};const e=Ji(),s=Math.max(0,(window.outerWidth-window.innerWidth*e)/2),i=Math.max(0,window.outerHeight-window.innerHeight*e-s);return{ox:window.screenX+s,oy:window.screenY+i}}function Pu(e,s){const i=Ji(),{ox:a,oy:u}=FS();return{x:(e-a)/i,y:(s-u)/i}}function HS(e,s){const i=Ji(),{ox:a,oy:u}=FS();return{x:a+e*i,y:u+s*i}}function Iu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Km="clitrigger:popout-alive:";function KO(e){return`${Km}${e}`}function Kp(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function VO(e){if(!Kp())return()=>{};let s=()=>{};return navigator.locks.request(KO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function $S(){var e;if(!Kp())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(Km)&&i.add(a.name.slice(Km.length));return i}catch{return new Set}}const Vp=y.createContext(null),US=y.createContext({});function WS(){const e=y.useContext(Vp);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function YO(){return y.useContext(US)}function XO(){return y.useContext(Vp)}const Fu=720,Yp=460,JO=320,QO=200,aw=30,qS=80,GS=80,vl=80,Vm=28;function ZO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=JO?e.w:Fu,u=Number.isFinite(e.h)&&e.h>=QO?e.h:Yp;a=Math.min(a,s),u=Math.min(u,i);let f=Number.isFinite(e.x)?e.x:qS,m=Number.isFinite(e.y)?e.y:GS;return f=Math.max(Math.min(f,s-vl),-(a-vl)),m=Math.max(Math.min(m,i-Vm),0),{x:f,y:m,w:a,h:u}}const ow=12,hu=60;function KS(e){return`sessionGroups:${e}`}function _u(e){try{const s=localStorage.getItem(KS(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 Ym(e,s){try{localStorage.setItem(KS(e),JSON.stringify(s))}catch{}}function eB(e,s){const i=_u(e);!i||!i.groups.some(a=>a.id===s)||(Ym(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function tB(e){const s=e%8;return{x:qS+s*aw,y:GS+s*aw,w:Fu,h:Yp}}function fu(e,s,i){return Math.max(s,Math.min(i,e))}function lw(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function Nr(e,s){for(const i of e)if(eo(i.root,s))return i;return null}function nB({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:u,onAddSession:f,children:m}){const{t:o}=xt(),{warning:l}=Rs(),{confirm:h}=Yn(),{sendNotification:p}=ro(),[d]=y.useState(()=>{const he=_u(e);if(!he)return{groups:[],zCounter:0};const de=he.groups.map(ce=>{const ee=vn(ce.root),Ne=new Set(ee),je={};for(const Ye of Object.keys(ce.colors||{}))Ne.has(Ye)&&(je[Ye]=ce.colors[Ye]);const Me={};for(const Ye of ee)Me[Ye]={intent:"open",nonce:0},je[Ye]||(je[Ye]=qi(Object.values(je)));const Te=ZO({x:ce.x,y:ce.y,w:ce.w,h:ce.h}),et=ce.ownerWindowId||Ft;return{...ce,...Te,colors:je,intents:Me,minimized:!!ce.minimized,ownerWindowId:et}});return{groups:de,zCounter:he.zCounter||de.length}}),[g,v]=y.useState(d.groups),C=y.useRef(d.zCounter),k=y.useRef(g);k.current=g;const x=y.useRef(s);x.current=s;const[S,_]=y.useState(null),w=y.useRef(null);w.current=S;const[j,R]=y.useState({}),E=y.useRef(j);E.current=j,y.useEffect(()=>{var ee;const he={},de=((ee=_u(e))==null?void 0:ee.sessionProjects)??{},ce={};for(const Ne of g)for(const je of vn(Ne.root)){const Me=s.find(et=>et.id===je)||j[je];Me!=null&&Me.title&&(he[je]=Me.title);const Te=(Me==null?void 0:Me.project_id)||de[je];Te&&(ce[je]=Te)}Ym(e,{groups:g,zCounter:C.current,titles:he,sessionProjects:ce}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,g,s,j]),y.useEffect(()=>()=>{var Me;const he=k.current;if(he.length===0)return;let de=!1;const ce=he.map(Te=>(Te.ownerWindowId||Ft)!==Ft||Te.minimized?Te:(de=!0,{...Te,minimized:!0}));if(!de)return;const ee={},Ne=((Me=_u(e))==null?void 0:Me.sessionProjects)??{},je={};for(const Te of ce)for(const et of vn(Te.root)){const Ye=x.current.find(bt=>bt.id===et)||E.current[et];Ye!=null&&Ye.title&&(ee[et]=Ye.title);const mt=(Ye==null?void 0:Ye.project_id)||Ne[et];mt&&(je[et]=mt)}Ym(e,{groups:ce,zCounter:C.current,titles:ee,sessionProjects:je}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]),y.useEffect(()=>{const he=document.documentElement.style,de={left:0,right:0,top:0,bottom:0};for(const ce of g)!ce.dock||ce.minimized||(ce.ownerWindowId||Ft)!==Ft||(ce.dock==="left"?de.left=Math.max(de.left,ce.x+ce.w-Wa()):ce.dock==="right"?de.right=Math.max(de.right,window.innerWidth-ce.x):ce.dock==="top"?de.top=Math.max(de.top,ce.y+ce.h):de.bottom=Math.max(de.bottom,window.innerHeight-ce.y));for(const ce of["left","right","top","bottom"])he.setProperty(`--dock-inset-${ce}`,`${Math.max(0,Math.round(de[ce]))}px`);return()=>{for(const ce of["left","right","top","bottom"])he.removeProperty(`--dock-inset-${ce}`)}},[g]),y.useEffect(()=>{const he=()=>{const ee=window.innerWidth,Ne=window.innerHeight,je=Wa();v(Me=>{let Te=!1;const et=Me.map(Ye=>{if(!Ye.dock)return Ye;const mt=Ye.dock==="left"||Ye.dock==="right"?Ye.w:Ye.h,bt=TS(Ye.dock,mt,ee,Ne,je);return bt.x===Ye.x&&bt.y===Ye.y&&bt.w===Ye.w&&bt.h===Ye.h?Ye:(Te=!0,{...Ye,...bt})});return Te?et:Me})};he();const de=document.querySelector("main"),ce=de?new ResizeObserver(he):null;return de&&ce&&ce.observe(de),window.addEventListener("resize",he),()=>{ce==null||ce.disconnect(),window.removeEventListener("resize",he)}},[]);const[D,N]=y.useState(()=>new Set),T=y.useRef(new Set);y.useEffect(()=>{if(s.length===0)return;const he=s.filter(ce=>ce.project_id===e);if(he.length===0)return;const de=new Set(he.map(ce=>ce.id));for(const ce of g)for(const ee of vn(ce.root))de.has(ee)||j[ee]||D.has(ee)||T.current.has(ee)||(T.current.add(ee),q1(ee).then(Ne=>R(je=>({...je,[ee]:Ne}))).catch(Ne=>{Ne instanceof Ya&&Ne.status===404&&N(je=>new Set(je).add(ee))}).finally(()=>T.current.delete(ee)))},[g,s,e,j,D]),y.useEffect(()=>u(de=>{de.type!=="session:status-changed"||!de.sessionId||R(ce=>{const ee=ce[de.sessionId];if(!ee)return ce;const Ne={status:de.status};return de.worktree_path!==void 0&&(Ne.worktree_path=de.worktree_path),de.branch_name!==void 0&&(Ne.branch_name=de.branch_name),{...ce,[ee.id]:{...ee,...Ne}}})}),[u]),y.useEffect(()=>{D.size!==0&&v(he=>{let de=!1;const ce=[];for(const ee of he){const Ne=vn(ee.root);if(!Ne.some(mt=>D.has(mt))){ce.push(ee);continue}de=!0;const je=new Set(Ne.filter(mt=>!D.has(mt))),Me=BO(ee.root,je);if(!Me)continue;const Te=new Set(vn(Me)),et={};for(const mt of Object.keys(ee.colors))Te.has(mt)&&(et[mt]=ee.colors[mt]);const Ye={};for(const mt of Object.keys(ee.intents))Te.has(mt)&&(Ye[mt]=ee.intents[mt]);ce.push({...ee,root:Me,colors:et,intents:Ye})}return de?ce:he})},[D]);const z=y.useCallback((he,de)=>{const ce=k.current.length,ee=tB(ce);C.current+=1;const Ne=C.current;return{id:lw(),...ee,z:Ne,minimized:!1,root:mi([he],he),colors:{[he]:qi([])},intents:{[he]:{intent:de,nonce:0}},ownerWindowId:Ft}},[]),P=y.useCallback((he,de="open")=>{v(ce=>{const ee=Nr(ce,he);C.current+=1;const Ne=C.current;return ee?ce.map(je=>{var mt,bt,yt;if(je.id!==ee.id)return je;const Me=((mt=je.intents[he])==null?void 0:mt.intent)??"open",Te=de==="start"||de==="resume",et=Te?de:Me,Ye=et!==Me||Te;return{...je,z:Ne,minimized:!1,root:sr(je.root,he),intents:{...je.intents,[he]:{intent:et,nonce:Ye?(((bt=je.intents[he])==null?void 0:bt.nonce)??0)+1:((yt=je.intents[he])==null?void 0:yt.nonce)??0}}}}):[...ce,z(he,de)]})},[z]),O=y.useCallback(he=>{v(de=>{const ce=Nr(de,he);if(!ce)return de;const ee=de.reduce((je,Me)=>Me.z>je?Me.z:je,0);if(ce.z===ee&&!ce.minimized)return de;C.current+=1;const Ne=C.current;return de.map(je=>je.id===ce.id?{...je,z:Ne,minimized:!1}:je)})},[]),H=y.useCallback(async he=>{const de=he.map(ce=>x.current.find(ee=>ee.id===ce)||E.current[ce]).filter(ce=>!!ce&&ce.status==="running");if(de.length===0)return!0;if(!await h({message:o("session.confirmStop"),danger:!0}))return!1;for(const ce of de)Du(ce.id).catch(()=>{});return!0},[o,h]),U=y.useCallback(async he=>{await H([he])&&v(de=>{const ce=Nr(de,he);if(!ce)return de;const ee=Ki(ce.root,he);if(!ee)return de.filter(Me=>Me.id!==ce.id);new Set(vn(ee));const Ne={...ce.colors};delete Ne[he];const je={...ce.intents};return delete je[he],de.map(Me=>Me.id===ce.id?{...Me,root:ee,colors:Ne,intents:je}:Me)})},[H]),F=y.useCallback(he=>{v(de=>{const ce=Nr(de,he);return ce?de.map(ee=>ee.id===ce.id?{...ee,minimized:!0}:ee):de})},[]),q=y.useCallback(he=>{v(de=>{const ce=Nr(de,he);if(!ce)return de;C.current+=1;const ee=C.current;return de.map(Ne=>Ne.id===ce.id?{...Ne,minimized:!1,z:ee}:Ne)})},[]),$=y.useCallback(he=>!!Nr(k.current,he),[]),K=y.useCallback(async he=>{const de=k.current.find(ce=>ce.id===he);de&&!await H(vn(de.root))||v(ce=>ce.filter(ee=>ee.id!==he))},[H]),B=y.useCallback(he=>{v(de=>de.map(ce=>ce.id===he?{...ce,minimized:!0}:ce))},[]);y.useEffect(()=>{const he=ce=>{const ee=ce.detail;!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId===e&&v(Ne=>{if(!Ne.find(Te=>Te.id===ee.groupId))return Ne;C.current+=1;const Me=C.current;return Ne.map(Te=>Te.id===ee.groupId?{...Te,minimized:!1,z:Me}:Te)})},de=async ce=>{var Me;const ee=ce.detail;if(!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId!==e)return;const Ne=k.current.find(Te=>Te.id===ee.groupId);if(Ne&&!await H(vn(Ne.root)))return;const je=(Ne==null?void 0:Ne.ownerWindowId)||Ft;je!==Ft&&(ge.current.delete(je),tt.current.delete(ee.groupId),(Me=le.current)==null||Me.post({t:"group-reclaimed",popoutId:je,groupIds:[ee.groupId],reason:"late-return"})),v(Te=>Te.filter(et=>et.id!==ee.groupId))};return window.addEventListener("session-windows:restore",he),window.addEventListener("session-windows:close",de),()=>{window.removeEventListener("session-windows:restore",he),window.removeEventListener("session-windows:close",de)}},[e,H]),y.useEffect(()=>{const he=sessionStorage.getItem("pendingSessionRestore");if(he)try{const de=JSON.parse(he);if(de.projectId!==e||!de.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),v(ce=>{if(!ce.find(je=>je.id===de.groupId))return ce;C.current+=1;const Ne=C.current;return ce.map(je=>je.id===de.groupId?{...je,minimized:!1,z:Ne}:je)})}catch{}},[e]);const A=y.useCallback(he=>{v(de=>{if(!de.find(Ne=>Ne.id===he))return de;C.current+=1;const ee=C.current;return de.map(Ne=>Ne.id===he?{...Ne,minimized:!1,z:ee}:Ne)})},[]),I=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>ee.id===he?{...ee,...de}:ee))},[]),Y=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>{if(ee.id===he){if(!de)return ee.dock?{...ee,dock:void 0}:ee;const Ne=Cl(de,window.innerWidth,window.innerHeight,Wa());return{...ee,...Ne,dock:de}}return de&&ee.dock===de?{...ee,dock:void 0}:ee}))},[]),G=y.useCallback((he,de,ce)=>{v(ee=>ee.map(Ne=>Ne.id===he?{...Ne,root:BS(Ne.root,de,ce)}:Ne))},[]),J=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>ee.id===he?{...ee,root:sr(ee.root,de)}:ee))},[]),re=y.useCallback((he,de)=>{v(ce=>ce.map(ee=>ee.id===he?{...ee,root:MS(ee.root,de)}:ee))},[]),Z=y.useCallback((he,de,ce)=>{v(ee=>ee.map(Ne=>Ne.id===he?{...Ne,root:OS(Ne.root,de,ce)}:Ne))},[]),Q=y.useCallback((he,de,ce,ee)=>{if(ee.button!==0||!k.current.find(ve=>ve.id===he))return;ee.preventDefault();const je=ee.clientX,Me=ee.clientY;let Te=null;_({groupId:he,sessionId:de,fromPath:ce,startX:je,startY:Me,mouseX:je,mouseY:Me,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null,viewportZone:null});const et=(ve,ye)=>{const me=lw();Te=me;const nt=window.innerWidth,pt=window.innerHeight,jt={x:fu(ve-60,-Fu+vl,nt-vl),y:fu(ye-12,0,pt-Vm),w:Fu,h:Yp};v(Bt=>{const ze=Bt.find(un=>un.id===he);if(!ze)return Bt;const ut=Ki(ze.root,de),_t=ze.colors[de]||qi([]),Mt=ze.intents[de]??{intent:"open",nonce:0};C.current+=1;const At=C.current,_n={id:me,...jt,z:At,minimized:!1,root:mi([de],de),colors:{[de]:_t},intents:{[de]:Mt},ownerWindowId:Ft},kn=[];for(const un of Bt)if(un.id===he){if(ut){const rn=new Set(vn(ut)),us={};for(const In of Object.keys(un.colors))rn.has(In)&&(us[In]=un.colors[In]);const cr={};for(const In of Object.keys(un.intents))rn.has(In)&&(cr[In]=un.intents[In]);kn.push({...un,root:Bu(ut),colors:us,intents:cr})}}else kn.push(un);return kn.push(_n),kn})};let Ye=!1;const mt=ve=>{const ye=window.screenX,me=window.screenY,nt=ye+window.outerWidth,pt=me+window.outerHeight;return ve.screenX<ye-hu||ve.screenX>nt+hu||ve.screenY<me-hu||ve.screenY>pt+hu},bt=ve=>{if(Ye)return;const ye=w.current;if(!ye)return;if(!Te)Math.hypot(ve.clientX-je,ve.clientY-Me)>=ow&&et(ve.clientX,ve.clientY);else{const ut=window.innerWidth,_t=window.innerHeight,Mt=fu(ve.clientX-60,-640,ut-vl),At=fu(ve.clientY-12,0,_t-Vm);v(_n=>_n.map(kn=>kn.id===Te?{...kn,x:Mt,y:At}:kn))}if(Te&&mt(ve)&&k.current.some(ut=>ut.id===Te)){const ut=Ke.current;if(ut){Ye=!0;const _t=Te;Et(),_(null),ut(_t,{atScreenX:ve.screenX,atScreenY:ve.screenY});return}}let me=null,nt=null,pt=null,jt=null;const Bt=document.elementsFromPoint(ve.clientX,ve.clientY);for(const ut of Bt){const _t=ut.closest("[data-group-id][data-stack-path]");if(!_t)continue;const Mt=_t.dataset.groupId||"",At=_t.dataset.stackPath||"";if(Te?Mt===Te:Mt===ye.groupId&&At===ye.fromPath.join("."))continue;const kn=At===""?[]:At.split(".").map(Number),un=_t.getBoundingClientRect();me=Mt,nt=kn,pt={x:un.left,y:un.top,w:un.width,h:un.height},jt=rd(ve.clientX,ve.clientY,pt);break}const ze=jt||!Te?null:DS(ve.clientX,ve.clientY,window.innerWidth,window.innerHeight);_({...ye,mouseX:ve.clientX,mouseY:ve.clientY,hoveredGroupId:me,hoveredPath:nt,hoveredRect:pt,zone:jt,viewportZone:ze})};let yt=!1;const Et=()=>{yt||(yt=!0,window.removeEventListener("mousemove",bt),window.removeEventListener("mouseup",ae),window.removeEventListener("blur",Xe),window.removeEventListener("keydown",lt),document.removeEventListener("visibilitychange",Oe))},Xe=()=>{Et(),_(null)},lt=ve=>{ve.key==="Escape"&&Xe()},Oe=()=>{document.hidden&&Xe()},ae=ve=>{var nt;Et();const ye=w.current;if(_(null),!ye)return;if(ye.hoveredGroupId&&ye.hoveredPath&&ye.zone){const pt=Te||ye.groupId;W(pt,ye.sessionId,ye.hoveredGroupId,ye.hoveredPath,ye.zone);return}const me=ye.viewportZone;if(me&&Te&&k.current.some(pt=>pt.id===Te)){const pt=Te;if(me==="popout")(nt=Ke.current)==null||nt.call(Ke,pt,{atScreenX:ve.screenX,atScreenY:ve.screenY});else if(me==="max"){const jt=Cl(me,window.innerWidth,window.innerHeight,Wa());v(Bt=>Bt.map(ze=>ze.id===pt?{...ze,x:jt.x,y:jt.y,w:jt.w,h:jt.h}:ze))}else Y(pt,me);return}};window.addEventListener("mousemove",bt),window.addEventListener("mouseup",ae),window.addEventListener("blur",Xe),window.addEventListener("keydown",lt),document.addEventListener("visibilitychange",Oe)},[]),W=y.useCallback((he,de,ce,ee,Ne)=>{v(je=>{const Me=je.find(lt=>lt.id===he),Te=je.find(lt=>lt.id===ce);if(!Me||!Te)return je;if(he===ce){const lt=pi(Me.root,ee);if(!lt||lt.kind!=="stack")return je;const Oe=lt.tabs.find(me=>me!==de);if(!Oe)return je;const ae=Ki(Me.root,de);if(!ae)return je;const ve=eo(ae,Oe);if(!ve)return je;let ye;return Ne==="center"?ye=qa(ae,ve,de):ye=xl(ae,ve,Ne,mi([de])),ye=sr(ye,de),je.map(me=>me.id!==he?me:(C.current+=1,{...me,root:ye,z:C.current,minimized:!1}))}const et=Ki(Me.root,de),Ye=Me.colors[de],mt=Me.intents[de]??{intent:"open",nonce:0};let bt;if(Ne==="center")bt=qa(Te.root,ee,de);else{const lt=mi([de]);bt=xl(Te.root,ee,Ne,lt)}bt=sr(bt,de);const yt={...Te.colors};yt[de]||(yt[de]=Ye||qi(Object.values(yt)));const Et={...Te.intents,[de]:mt},Xe=[];for(const lt of je)if(lt.id===he){if(et){const Oe=new Set(vn(et)),ae={};for(const ye of Object.keys(lt.colors))Oe.has(ye)&&(ae[ye]=lt.colors[ye]);const ve={};for(const ye of Object.keys(lt.intents))Oe.has(ye)&&(ve[ye]=lt.intents[ye]);Xe.push({...lt,root:et,colors:ae,intents:ve})}}else lt.id===ce?(C.current+=1,Xe.push({...lt,root:bt,colors:yt,intents:Et,z:C.current,minimized:!1})):Xe.push(lt);return Xe})},[]),oe=y.useCallback((he,de,ce,ee)=>{v(Ne=>{if(he===de)return Ne;const je=Ne.find(yt=>yt.id===he),Me=Ne.find(yt=>yt.id===de);if(!je||!Me||je.root.kind!=="stack")return Ne;const Te=je.root;let et;ee==="center"?et=Te.tabs.reduce((yt,Et)=>qa(yt,ce,Et),Me.root):et=xl(Me.root,ce,ee,Te),et=sr(et,Te.activeTab);const Ye={...Me.colors,...je.colors},mt={...Me.intents,...je.intents},bt=[];for(const yt of Ne)yt.id!==he&&(yt.id===de?(C.current+=1,bt.push({...yt,root:et,colors:Ye,intents:mt,z:C.current,minimized:!1})):bt.push(yt));return bt})},[]),le=y.useRef(null),ge=y.useRef(new Map),[ue,Ve]=y.useState(null),We=y.useRef(ue);We.current=ue;const De=y.useRef(null),be=y.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0),[Re,ct]=y.useState(()=>typeof document<"u"&&document.hasFocus());y.useEffect(()=>{const he=()=>{be.current=Date.now(),ct(!0)},de=()=>ct(!1);window.addEventListener("focus",he),window.addEventListener("blur",de);const ce=IS();return()=>{window.removeEventListener("focus",he),window.removeEventListener("blur",de),ce(),De.current&&clearTimeout(De.current)}},[]);const tt=y.useRef(new Map),Ke=y.useRef(null),Le=y.useCallback((he,de)=>{var bt;const ce=k.current.find(yt=>yt.id===he);if(!ce)return;const ee=GO(),Ne={...ce,ownerWindowId:ee,dock:void 0};tt.current.set(he,Ne),ge.current.set(ee,Date.now()),v(yt=>yt.map(Et=>Et.id===he?{...Et,ownerWindowId:ee,dock:void 0}:Et)),(bt=le.current)==null||bt.post({t:"group-handoff",to:ee,groupId:he,group:Ne});const je=de&&(typeof de.atScreenX=="number"||typeof de.atScreenY=="number"),Me=je?Math.max(0,((de==null?void 0:de.atScreenX)??window.screenX+ce.x)-40):Math.max(0,window.screenX+ce.x),Te=je?Math.max(0,((de==null?void 0:de.atScreenY)??window.screenY+ce.y)-12):Math.max(0,window.screenY+ce.y),et=["popup",`width=${Math.max(400,ce.w)}`,`height=${Math.max(300,ce.h+40)}`,`left=${Me}`,`top=${Te}`].join(","),Ye=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(he)}?wid=${encodeURIComponent(ee)}`,mt=window.open(Ye,"_blank",et);if(!mt){tt.current.delete(he),ge.current.delete(ee),v(yt=>yt.map(Et=>Et.id===he?{...Et,ownerWindowId:Ft}:Et)),l(o("session.popout.blocked"));return}WO(ee,mt)},[e,o,l]);Ke.current=Le;const $e=y.useCallback(he=>{var ee;const de=k.current.find(Ne=>Ne.id===he);if(!de)return;const ce=de.ownerWindowId||Ft;if(ce===Ft){A(he);return}(ee=le.current)==null||ee.post({t:"group-recall",popoutId:ce,groupId:he}),setTimeout(()=>{var Me;const Ne=k.current.find(Te=>Te.id===he);if(!Ne||(Ne.ownerWindowId||Ft)===Ft)return;ge.current.delete(ce),tt.current.delete(he),(Me=le.current)==null||Me.post({t:"group-reclaimed",popoutId:ce,groupIds:[he],reason:"late-return"}),C.current+=1;const je=C.current;v(Te=>Te.map(et=>et.id===he?{...et,ownerWindowId:Ft,minimized:!1,z:je}:et))},1500)},[A]),Ie=y.useCallback(he=>{const de=Nr(k.current,he);de&&$e(de.id)},[$e]);y.useEffect(()=>{const he=de=>{const ce=de.detail;!(ce!=null&&ce.projectId)||!ce.groupId||ce.projectId!==e||$e(ce.groupId)};return window.addEventListener("session-windows:recall",he),()=>window.removeEventListener("session-windows:recall",he)},[e,$e]),y.useEffect(()=>{const he=sessionStorage.getItem("pendingSessionRecall");if(he)try{const de=JSON.parse(he);if(de.projectId!==e||!de.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const ce=de.groupId;setTimeout(()=>$e(ce),0)}catch{}},[e,$e]);const it=y.useCallback(he=>he.kind==="stack"?[]:[0,...it(he.children[0])],[]),vt=y.useCallback((he,de,ce)=>{const ee=de?k.current.find(Te=>Te.id===de):null,Ne=ee&&(ee.ownerWindowId||Ft)===Ft;if(!ee||!Ne){P(he,"start");return}const je=(()=>{if(ce){const Te=pi(ee.root,ce);if(Te&&Te.kind==="stack")return ce}return it(ee.root)})();C.current+=1;const Me=C.current;v(Te=>Te.map(et=>{if(et.id!==ee.id)return et;const Ye=sr(qa(et.root,je,he),he);return{...et,root:Ye,z:Me,minimized:!1,colors:{...et.colors,[he]:qi(Object.values(et.colors))},intents:{...et.intents,[he]:{intent:"start",nonce:0}}}}))},[P,it]),Ce=y.useCallback(async(he,de)=>{const ce=new Date,ee=String(ce.getHours()).padStart(2,"0"),Ne=String(ce.getMinutes()).padStart(2,"0"),je=String(ce.getSeconds()).padStart(2,"0"),Me=await Nm(e,{title:`Shell ${ee}:${Ne}:${je}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(Me),vt(Me.id,he,de),Me.id},[e,f,vt]);y.useEffect(()=>{const he=qp();le.current=he;const de=ee=>{var Ne;if(ee.t==="hello"){const je=tt.current.get(ee.groupId);if(je&&je.ownerWindowId===ee.from)he.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:je});else{const Me=k.current.find(Te=>Te.id===ee.groupId);Me&&Me.ownerWindowId===ee.from&&he.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:Me})}}else if(ee.t==="group-return"||ee.t==="bye")if(ee.t==="group-return"){const je=ee.group;je&&je.id===ee.groupId&&(tt.current.delete(ee.groupId),ge.current.delete(ee.from),ee.projectId&&ee.projectId!==e&&eB(ee.projectId,ee.groupId),v(Me=>{const Te=Me.find(Ye=>Ye.id===ee.groupId),et={...je,ownerWindowId:Ft,dock:void 0};return Te?Me.map(Ye=>Ye.id===ee.groupId?et:Ye):[...Me,et]}))}else ge.current.delete(ee.from),v(je=>je.map(Me=>Me.ownerWindowId===ee.from?{...Me,ownerWindowId:Ft}:Me));else if(ee.t==="group-close")tt.current.delete(ee.groupId),v(je=>je.filter(Me=>Me.id!==ee.groupId));else if(ee.t==="heartbeat")ge.current.set(ee.from,Date.now());else if(ee.t==="group-update"){const je=ee.patch;v(Me=>Me.map(Te=>Te.id===ee.groupId?{...Te,...je}:Te))}else if(ee.t==="dock-probe"){if(document.visibilityState!=="visible")return;const je=Pu(ee.x,ee.y),Me=Iu(je)?Ou(je.x,je.y):null;if(Me){const Te=We.current;(!Te||Te.zone!==Me.zone||Te.groupId!==Me.groupId||Te.path.join(".")!==Me.path.join("."))&&Ve({rect:Me.rect,zone:Me.zone,path:Me.path,groupId:Me.groupId}),De.current&&clearTimeout(De.current),De.current=setTimeout(()=>Ve(null),800);const et=Ji();he.post({t:"dock-probe-result",from:Ft,to:ee.from,hit:!0,focusAt:be.current,rect:{...HS(Me.rect.x,Me.rect.y),w:Me.rect.w*et,h:Me.rect.h*et},zone:Me.zone})}else We.current&&Ve(null),he.post({t:"dock-probe-result",from:Ft,to:ee.from,hit:!1,focusAt:be.current})}else if(ee.t==="dock-end")Ve(null);else if(ee.t==="dock-commit"&&ee.to===Ft){const je=Pu(ee.x,ee.y),Me=Iu(je)?Ou(je.x,je.y):null,Te=Me&&Me.zone?Me:(Ne=We.current)!=null&&Ne.zone?We.current:null;let et=!1;const Ye=ee.sessions.map(bt=>bt.id),mt=k.current.filter(bt=>(bt.ownerWindowId||Ft)===Ft);if(Te&&Te.zone&&!Ye.some(bt=>Nr(mt,bt))){const bt=k.current.find(Et=>Et.id===Te.groupId),yt=bt?pi(bt.root,Te.path):null;if(bt&&yt&&yt.kind==="stack"){et=!0;const Et=Te.zone,Xe=Te.path;C.current+=1;const lt=C.current;v(Oe=>Oe.map(ae=>{if(ae.id!==bt.id)return ae;const ve=zS(ae.root,Xe,Et,Ye,ee.activeId),ye={...ae.colors},me={...ae.intents};for(const nt of ee.sessions)ye[nt.id]||(ye[nt.id]=nt.color||qi(Object.values(ye))),me[nt.id]=nt.intentInfo??{intent:"open",nonce:0};return{...ae,root:ve,colors:ye,intents:me,z:lt,minimized:!1}}))}}Ve(null),he.post({t:"dock-commit-ack",from:Ft,to:ee.from,commitId:ee.commitId,accepted:et})}},ce=he.subscribe(de);return()=>{ce(),he.close(),le.current=null}},[e]),y.useEffect(()=>{const he=Date.now();for(const de of d.groups)de.ownerWindowId&&de.ownerWindowId!==Ft&&ge.current.set(de.ownerWindowId,he)},[]),y.useEffect(()=>{const he=async()=>{var Te;const ce=Date.now(),ee=[];for(const[et,Ye]of ge.current.entries())ce-Ye>PS&&ee.push(et);if(ee.length===0)return;const Ne=await $S(),je=ee.filter(et=>Ne.has(et)?(ge.current.set(et,ce),!1):!0);if(je.length===0)return;for(const et of je)ge.current.delete(et);const Me=new Set(je);for(const et of k.current)et.ownerWindowId&&Me.has(et.ownerWindowId)&&tt.current.delete(et.id);for(const et of je){const Ye=k.current.filter(mt=>mt.ownerWindowId===et).map(mt=>mt.id);Ye.length>0&&((Te=le.current)==null||Te.post({t:"group-reclaimed",popoutId:et,groupIds:Ye,reason:"heartbeat-timeout"}))}v(et=>et.map(Ye=>Ye.ownerWindowId&&je.includes(Ye.ownerWindowId)?{...Ye,ownerWindowId:Ft}:Ye))},de=setInterval(()=>{he()},Gp);return()=>clearInterval(de)},[]);const Ue=y.useCallback((he,de)=>{i({type:"session:terminal-input",sessionId:he,input:de})},[i]),we=y.useCallback(()=>{var ce,ee;const he=k.current.filter(Ne=>(Ne.ownerWindowId||Ft)===Ft).slice().sort((Ne,je)=>je.z-Ne.z),de=[];for(const Ne of he)for(const je of vn(Ne.root)){const Me=((ce=x.current.find(Te=>Te.id===je))==null?void 0:ce.title)||((ee=E.current[je])==null?void 0:ee.title)||je;de.push({sessionId:je,label:Me})}return de},[]),Pe=y.useCallback(async(he,de)=>{const ee=k.current.filter(je=>!je.minimized&&(je.ownerWindowId||Ft)===Ft).reduce((je,Me)=>je&&je.z>=Me.z?je:Me,null),Ne=await Nm(e,{title:de||"",description:he,use_worktree:!1,memory_inject_mode:"none"});f==null||f(Ne),vt(Ne.id,(ee==null?void 0:ee.id)??null)},[e,f,vt]),X=y.useMemo(()=>({openOrFocus:P,close:U,focus:O,minimize:F,restore:q,isOpen:$,recallPopout:Ie,closeGroup:K,minimizeGroup:B,restoreGroup:A,setGroupGeometry:I,setGroupDock:Y,setSplitSizes:G,setActiveTab:J,applyLayoutPreset:re,reorderTab:Z,beginTabDrag:Q,dockGroup:oe,popOutGroup:Le,createRawShellTab:Ce,sendToSession:Ue,listOpenTerminals:we,sendToNewTerminal:Pe}),[P,U,O,F,q,$,Ie,K,B,A,I,Y,G,J,re,Z,Q,oe,Le,Ce,Ue,we,Pe]),ne=y.useMemo(()=>{const he={};for(const de of g){const ee=(de.ownerWindowId||Ft)!==Ft?"popped":de.minimized?"minimized":"floating";for(const Ne of vn(de.root))he[Ne]=ee}return he},[g]);y.useEffect(()=>{const he=de=>{const ce=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ee=ce?de.metaKey:de.ctrlKey,Ne=ce?de.ctrlKey:de.metaKey;if(!ee||Ne||de.altKey||de.shiftKey||de.key.toLowerCase()!=="t")return;de.preventDefault();const Me=k.current.filter(Te=>!Te.minimized&&(Te.ownerWindowId||Ft)===Ft).reduce((Te,et)=>Te&&Te.z>=et.z?Te:et,null);Ce((Me==null?void 0:Me.id)??null).catch(()=>{})};return window.addEventListener("keydown",he),()=>window.removeEventListener("keydown",he)},[Ce]);const Se=y.useMemo(()=>{const he=new Map;for(const de of Object.values(j))he.set(de.id,de);for(const de of s)he.set(de.id,de);return he},[s,j]),fe=g.filter(he=>!he.minimized&&(he.ownerWindowId||Ft)===Ft),ie=fe.reduce((he,de)=>de.z>he.z?{id:de.id,z:de.z}:he,{id:null,z:-1/0}).id,ke=fe.find(he=>he.id===ie),_e=Re&&ke?to(ke.root).join(","):"",st=y.useMemo(()=>new Set(_e?_e.split(","):[]),[_e]),Ze=$p(u,st,(he,de)=>{var ee;const ce=Nr(k.current,he);!ce||ce.minimized||(ce.ownerWindowId||Ft)!==Ft||p(o(de==="blocked"?"notification.sessionBlocked":"notification.sessionDone"),((ee=Se.get(he))==null?void 0:ee.title)||he)});return t.jsx(Vp.Provider,{value:X,children:t.jsx(US.Provider,{value:ne,children:t.jsxs(Hp.Provider,{value:Ze,children:[m,(()=>{const he=new Map(fe.slice().sort((de,ce)=>de.z-ce.z).map((de,ce)=>[de.id,ce+1]));return fe.map(de=>{const ce=fe.filter(ee=>ee.id!==de.id).map(({x:ee,y:Ne,w:je,h:Me})=>({x:ee,y:Ne,w:je,h:Me}));return t.jsx($O,{group:de,sessionsById:Se,neighbors:ce,isTopmost:de.id===ie,zIndex:he.get(de.id)??1,sendMessage:i,subscribeBinary:a,onEvent:u},de.id)})})(),S&&S.hoveredRect&&t.jsx(Ka,{targetRect:S.hoveredRect,activeZone:S.zone}),S&&!S.zone&&Math.hypot(S.mouseX-S.startX,S.mouseY-S.startY)>=ow&&t.jsx(RS,{activeZone:S.viewportZone}),ue&&t.jsx(Ka,{targetRect:ue.rect,activeZone:ue.zone})]})})})}function sB(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const rB={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function iB({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:u,projectDefaultBranch:f,onAddSession:m,onUpdateSession:o,onStopSession:l,onDeleteSession:h,onCleanupSession:p}){const{t:d}=xt(),{confirm:g}=Yn(),{openOrFocus:v,recallPopout:C}=WS(),k=YO(),[x,S]=y.useState(!1),[_,w]=y.useState(!1),[j,R]=y.useState(null),[E,D]=y.useState(!1),[N,T]=y.useState(null),[z,P]=y.useState([]),[O,H]=y.useState(""),[U,F]=y.useState(null);y.useEffect(()=>{let J=!1;return mp().then(re=>{J||P(re)}).catch(()=>{}),()=>{J=!0}},[]),y.useEffect(()=>{if(!a)return;let J=!1;return x1(e).then(re=>{J||H(re.branch||"")}).catch(()=>{}),()=>{J=!0}},[e,a]);const q=y.useMemo(()=>{const J=new Map;for(const re of z)J.set(re.id,re);return J},[z]),$=y.useMemo(()=>j?s.find(J=>J.id===j)??null:null,[j,s]),K=y.useMemo(()=>{if($)return{title:$.title,description:$.description??"",cliTool:$.cli_tool??"",useWorktree:$.use_worktree===1,memoryInjectMode:$.memory_inject_mode??"none",memoryNodeIds:Kz($.memory_node_ids??null),memoryRawFilePaths:sB($.memory_raw_file_paths??null),tagId:$.tag_id??null}},[$]),B=y.useCallback(()=>{R(null),T(null),S(J=>!J)},[]),A=y.useCallback(J=>{S(!1),T(null),R(J)},[]),I=y.useCallback(()=>{S(!1),R(null),T(null)},[]),Y=y.useCallback(async(J,re,Z,Q,W,oe,le,ge)=>{w(!0);try{const ue=await Nm(e,{title:J,description:re||void 0,cli_tool:Z,use_worktree:Q,memory_inject_mode:W,memory_node_ids:oe,memory_raw_file_paths:le,tag_id:ge??null});m(ue),S(!1)}finally{w(!1)}},[e,m]),G=y.useCallback(async(J,re,Z,Q,W,oe,le,ge)=>{if(j){D(!0),T(null);try{const ue=await tL(j,{title:J,description:re||void 0,cli_tool:Z,use_worktree:Q,memory_inject_mode:W,memory_node_ids:oe,memory_raw_file_paths:le,tag_id:ge??null});o(ue),R(null)}catch(ue){T(ue instanceof Error?ue.message:String(ue))}finally{D(!1)}}},[j,o]);return t.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:J=>{yi(J)||(J.preventDefault(),F({x:J.clientX,y:J.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:d("tabs.sessions")}),t.jsxs("button",{onClick:B,className:"btn-primary text-xs py-2",disabled:_,children:["+ ",d("session.new")]})]}),x&&t.jsx(Py,{projectId:e,onSave:Y,onCancel:I,projectCliTool:i,isGitRepo:a,projectUseWorktree:u}),K&&j&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(Py,{projectId:e,initial:K,onSave:G,onCancel:I,projectCliTool:i,isGitRepo:a},j),(E||N)&&t.jsxs("div",{className:"text-xs px-1",children:[E&&t.jsx("span",{className:"text-warm-500",children:d("session.saving")||"saving…"}),N&&t.jsx("span",{className:"text-status-error",children:N})]})]}),s.length===0&&!x?t.jsx("div",{className:"card",children:t.jsx(Zi,{icon:wl,title:d("session.empty"),description:d("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((J,re)=>{const Z=["pending","failed","stopped","completed"].includes(J.status),Q=J.status==="running",W=J.status!=="running",oe=["stopped","failed","completed"].includes(J.status)&&!!J.resumable,le=j===J.id,ge=k[J.id]??"closed",ue=ge==="popped";return t.jsx("div",{className:`card overflow-hidden ${le?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:Ve=>{yi(Ve)||(Ve.preventDefault(),Ve.stopPropagation(),F({x:Ve.clientX,y:Ve.clientY,sessionId:J.id}))},children:t.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>ue?C(J.id):v(J.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:[J.tag_id&&q.get(J.tag_id)&&t.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-2xs font-medium",style:{backgroundColor:`${q.get(J.tag_id).color}22`,color:q.get(J.tag_id).color},children:[t.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:q.get(J.tag_id).color}}),q.get(J.tag_id).name]}),t.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:J.title}),t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs font-medium text-warm-500 whitespace-nowrap",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${rB[J.status]||"bg-warm-400"}`}),d(`status.${J.status}`)||J.status]}),ge!=="closed"&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:ue?d("session.dock.poppedHint"):void 0,children:[ue?t.jsx(qs,{size:12}):t.jsx("span",{"aria-hidden":"true",children:"·"}),d(`session.windowState.${ge}`)]})]}),J.description&&t.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:J.description}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.jsx("span",{className:"text-2xs text-warm-300",children:J.cli_tool||"claude"}),(J.branch_name||a&&(O||f))&&t.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[t.jsx(Qi,{size:12}),J.branch_name||O||f]})]})]}),t.jsxs("div",{className:"flex gap-1",onClick:Ve=>Ve.stopPropagation(),children:[ue&&t.jsx("button",{onClick:()=>C(J.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:d("session.recallToMain"),children:t.jsx(gi,{size:16})}),Z&&t.jsx("button",{onClick:()=>v(J.id,"start"),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md transition-colors",title:d("session.start"),children:t.jsx(Mr,{size:16})}),oe&&t.jsx("button",{onClick:()=>v(J.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:d("session.resumeHint")||d("session.resume"),children:t.jsx(vi,{size:16})}),t.jsx("button",{onClick:()=>A(J.id),disabled:!W,className:"p-1.5 text-warm-500 hover:text-warm-800 hover:bg-warm-100 rounded-md transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-warm-500",title:d(W?"session.edit":"session.editDisabledRunning"),children:t.jsx(pm,{size:16})}),Q&&t.jsx("button",{onClick:()=>l(J.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:d("session.stop"),children:t.jsx(Yi,{size:16})}),J.status!=="running"&&(!!J.worktree_path||!!J.branch_name)&&t.jsx("button",{onClick:async()=>{const Ve=J.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",J.branch_name),danger:!0}):!1;p(J.id,Ve)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:d("session.cleanup"),children:t.jsx(ku,{size:16})}),t.jsx("button",{onClick:()=>h(J.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:d("session.delete"),children:t.jsx(Pn,{size:16})})]})]})})},J.id)})}),U&&(()=>{const J=()=>F(null),re=U.sessionId?s.find(We=>We.id===U.sessionId):void 0;if(!re)return t.jsx(Gs,{x:U.x,y:U.y,onClose:J,children:t.jsxs("button",{type:"button",onClick:()=>{R(null),T(null),S(!0)},className:sn,children:[t.jsx(wn,{size:14}),d("session.new")]})});const Z=["pending","failed","stopped","completed"].includes(re.status),Q=re.status==="running",W=re.status!=="running",oe=["stopped","failed","completed"].includes(re.status)&&!!re.resumable,le=re.status!=="running"&&(!!re.worktree_path||!!re.branch_name),ge=k[re.id]??"closed",ue=ge==="popped",Ve=d(ue?"session.recallToMain":ge==="minimized"?"session.restoreWindow":ge==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(Gs,{x:U.x,y:U.y,onClose:J,children:[t.jsxs("button",{type:"button",onClick:()=>ue?C(re.id):v(re.id,"open"),className:sn,children:[ue?t.jsx(gi,{size:14}):t.jsx(wl,{size:14}),Ve]}),Z&&t.jsxs("button",{type:"button",onClick:()=>v(re.id,"start"),className:sn,children:[t.jsx(Mr,{size:14}),d("session.start")]}),oe&&t.jsxs("button",{type:"button",onClick:()=>v(re.id,"resume"),className:sn,title:d("session.resumeHint")||d("session.resume"),children:[t.jsx(vi,{size:14}),d("session.resume")]}),W&&t.jsxs("button",{type:"button",onClick:()=>A(re.id),className:sn,children:[t.jsx(pm,{size:14}),d("session.edit")]}),Q&&t.jsxs("button",{type:"button",onClick:()=>l(re.id),className:sn,children:[t.jsx(Yi,{size:14}),d("session.stop")]}),le&&t.jsxs("button",{type:"button",onClick:async()=>{const We=re.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",re.branch_name),danger:!0}):!1;p(re.id,We)},className:sn,children:[t.jsx(ku,{size:14}),d("session.cleanup")]}),t.jsx(oS,{}),t.jsxs("button",{type:"button",onClick:()=>h(re.id),className:Pp,children:[t.jsx(Pn,{size:14}),d("session.delete")]})]})})()]})}const Hu={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"}},aB=Object.keys(Hu),$u={pending:"bg-warm-200 text-warm-500",in_progress:"bg-status-running/10 text-status-running",done:"bg-status-success/10 text-status-success",moved:"bg-status-merged/10 text-status-merged"};function Va(e){const s=Hu[e]||Hu.default;return`${s.bg} ${s.text}`}function Xp({src:e,alt:s,onClose:i}){return y.useEffect(()=>{const a=u=>{u.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),cn.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(Jt,{size:16})}),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 Xm({anchorRef:e,width:s,onClose:i,className:a,style:u,children:f}){const m=y.useRef(null),[o,l]=y.useState(null);return y.useLayoutEffect(()=>{const h=e.current;if(!h)return;const p=h.getBoundingClientRect();let d=p.left;d+s>window.innerWidth-8&&(d=Math.max(8,window.innerWidth-8-s)),d<8&&(d=8),l({top:p.bottom+4,left:d})},[e,s]),y.useEffect(()=>{const h=d=>{var v,C;const g=d.target;(v=m.current)!=null&&v.contains(g)||(C=e.current)!=null&&C.contains(g)||i()},p=()=>i();return document.addEventListener("mousedown",h),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("mousedown",h),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[i,e]),o?cn.createPortal(t.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...u},children:f}),document.body):null}const cw={0:{label:"—",style:"text-warm-300"},1:{label:"●",style:"text-warm-500"},2:{label:"●●",style:"text-status-warning"},3:{label:"●●●",style:"text-status-error"}};function oB({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:l}){var we,Pe;const{t:h}=xt(),{confirm:p}=Yn(),[d,g]=y.useState(!1),[v,C]=y.useState(!1),[k,x]=y.useState(!1),S=y.useRef(null),_=y.useRef(null),[w,j]=y.useState({top:0,left:0}),[R,E]=y.useState(e.title),[D,N]=y.useState(e.description??""),[T,z]=y.useState(e.priority),[P,O]=y.useState(e.due_date??""),[H,U]=y.useState(e.status),[F,q]=y.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[$,K]=y.useState(""),[B,A]=y.useState(!1),[I,Y]=y.useState(null),[G,J]=y.useState(null),re=y.useRef(null),Z=y.useRef(null),[Q,W]=y.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),oe=y.useRef(null);y.useEffect(()=>{E(e.title),N(e.description??""),z(e.priority),O(e.due_date??""),U(e.status);try{q(e.tags?JSON.parse(e.tags):[])}catch{q([])}try{W(e.images?JSON.parse(e.images):[])}catch{W([])}},[e]);const le=F,ge=e.status==="moved",ue=e.due_date&&new Date(e.due_date)<new Date&&!ge&&e.status!=="done",Ve=y.useCallback(X=>{a(e.id,X)},[e.id,a]),We=()=>{const X=R.trim();X&&X!==e.title?Ve({title:X}):E(e.title)},De=()=>{const X=D.trim();X!==(e.description??"")&&Ve({description:X||void 0})},be=X=>{z(X),X!==e.priority&&Ve({priority:X})},Re=X=>{O(X),X!==(e.due_date??"")&&Ve({due_date:X||void 0})},ct=X=>{const ne=X;U(ne),ne!==e.status&&Ve({status:ne})},tt=X=>{q(X);const ne=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(X)!==JSON.stringify(ne)&&Ve({tags:X.length>0?JSON.stringify(X):void 0})},Ke=X=>{var Se;const ne=X.trim();if(ne&&!F.includes(ne)&&(tt([...F,ne]),!s.has(ne)&&l)){const fe=["blue","green","orange","purple","pink","red","yellow","brown"],ie=fe[s.size%fe.length];l(ne,{color:ie})}K(""),(Se=re.current)==null||Se.focus()},Le=X=>tt(F.filter(ne=>ne!==X)),$e=i.filter(X=>!F.includes(X)&&(!$||X.toLowerCase().includes($.toLowerCase()))),Ie=y.useCallback(X=>{const ne=Array.from(X).filter(ie=>ie.type.startsWith("image/")),Se=[];let fe=0;for(const ie of ne){const ke=new FileReader;ke.onload=()=>{Se.push({name:ie.name,data:ke.result}),fe++,fe===ne.length&&K1(e.id,Se).then(_e=>W(_e.images))},ke.readAsDataURL(ie)}},[e.id]),it=y.useCallback(X=>{var fe;const ne=(fe=X.clipboardData)==null?void 0:fe.items;if(!ne)return;const Se=[];for(let ie=0;ie<ne.length;ie++)if(ne[ie].type.startsWith("image/")){const ke=ne[ie].getAsFile();ke&&Se.push(ke)}Se.length!==0&&(X.preventDefault(),Ie(Se))},[Ie]),vt=y.useCallback(X=>{var ne;X.preventDefault(),X.stopPropagation(),(ne=X.dataTransfer)!=null&&ne.files&&Ie(X.dataTransfer.files)},[Ie]),Ce=y.useCallback(X=>{V1(e.id,X).then(()=>{W(ne=>ne.filter(Se=>Se.id!==X))})},[e.id]),Ue=y.useCallback(()=>{if(!S.current)return;const X=S.current.getBoundingClientRect(),ne=window.innerWidth,Se=window.innerHeight;let fe=X.bottom+4;const ie=_.current;if(ie){const ke=ie.offsetWidth,_e=ie.offsetHeight;let st=X.right-ke;st<8&&(st=8),st+ke>ne-8&&(st=ne-8-ke),fe+_e>Se-8&&(fe=X.top-_e-4),j({top:fe,left:st}),x(!0)}else j({top:fe,left:Math.max(8,X.right-180)})},[]);return y.useEffect(()=>{if(!d){x(!1);return}Ue();const X=requestAnimationFrame(Ue),ne=Se=>{var ie,ke;const fe=Se.target;(ie=S.current)!=null&&ie.contains(fe)||(ke=_.current)!=null&&ke.contains(fe)||g(!1)};return document.addEventListener("mousedown",ne),window.addEventListener("scroll",Ue,!0),window.addEventListener("resize",Ue),()=>{cancelAnimationFrame(X),document.removeEventListener("mousedown",ne),window.removeEventListener("scroll",Ue,!0),window.removeEventListener("resize",Ue)}},[d,Ue]),t.jsxs("div",{className:`${ge?"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:()=>C(!v),children:[t.jsx(ws,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${v?"rotate-90":""}`,onClick:X=>{X.stopPropagation(),C(!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}),ge&&e.converted_type&&t.jsxs("span",{className:"text-2xs text-status-merged",children:["→ ",e.converted_type==="todo"?h("planner.movedToTodo"):e.converted_type==="session"?h("planner.movedToSession"):h("planner.movedToSchedule")]}),e.source_discussion_id&&t.jsxs(Kn,{to:`/projects/${e.project_id}/discussions/${e.source_discussion_id}`,onClick:X=>X.stopPropagation(),className:"inline-flex items-center gap-1 text-2xs text-accent hover:underline mt-0.5",title:h("planner.fromDiscussion"),children:[t.jsx(aN,{size:12}),h("planner.fromDiscussion")]})]}),t.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[Q.length>0&&t.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-md text-[10px] font-medium bg-warm-100 text-warm-500 whitespace-nowrap",children:[t.jsx(Xa,{size:12}),Q.length]}),le.map(X=>t.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${Va(s.get(X)||"default")}`,children:X},X))]}),t.jsx("div",{className:"hidden sm:block w-12 text-center flex-shrink-0",children:t.jsx("span",{className:`text-xs font-medium ${((we=cw[e.priority])==null?void 0:we.style)??"text-warm-300"}`,children:((Pe=cw[e.priority])==null?void 0:Pe.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 ${ue?"text-status-error 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:h("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 ${$u[e.status]||$u.pending}`,children:h(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:S,onClick:X=>{X.stopPropagation(),g(!d)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:t.jsx(cp,{size:14})}),d&&cn.createPortal(t.jsxs("div",{ref:_,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:w.top,left:w.left,opacity:k?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>g(!1),children:[!ge&&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(n1,{size:12})," ",h("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(Vi,{size:12})," ",h("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(bi,{size:12})," ",h("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await p({message:h("planner.deleteConfirm"),danger:!0})&&u()},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(Pn,{size:12})," ",h("planner.delete")]})]}),document.body)]})]}),v&&t.jsx("div",{className:"px-4 pb-3 pt-1 ml-8",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:R,onChange:X=>E(X.target.value),onBlur:We,onKeyDown:X=>{X.key==="Enter"&&(X.preventDefault(),We(),X.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:h("plannerForm.descPlaceholder"),value:D,onChange:X=>N(X.target.value),onPaste:it,onDrop:vt,onDragOver:X=>{X.preventDefault(),X.stopPropagation()},onBlur:De}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{var X;return(X=oe.current)==null?void 0:X.click()},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[t.jsx(Xa,{size:12}),h("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:h("plannerForm.pasteHint")})]}),t.jsx("input",{ref:oe,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:X=>{X.target.files&&Ie(X.target.files),X.target.value=""}}),Q.length>0&&t.jsx("div",{className:"flex flex-wrap gap-2",children:Q.map(X=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:Tu(e.id,X.id),alt:X.originalName,onClick:()=>J(Tu(e.id,X.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>Ce(X.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(Jt,{size:12})}),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:X.originalName})})]},X.id))})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:h("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[F.map(X=>t.jsxs("div",{className:"relative",children:[t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-2xs font-medium cursor-pointer hover:ring-1 hover:ring-warm-400 transition-all ${Va(s.get(X)||"default")}`,onClick:ne=>{Z.current=ne.currentTarget,Y(I===X?null:X)},children:[X,t.jsx("button",{onClick:ne=>{ne.stopPropagation(),Le(X)},className:"opacity-60 hover:opacity-100",children:t.jsx(Jt,{size:12})})]}),I===X&&t.jsxs(Xm,{anchorRef:Z,width:180,onClose:()=>Y(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:h("plannerTag.color")}),t.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:aB.map(ne=>t.jsx("button",{onClick:async()=>{l&&await l(X,{color:ne}),Y(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(X)===ne?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:h(`plannerTag.color.${ne}`),children:t.jsx("div",{className:`w-5 h-5 rounded-md ${Hu[ne].swatch}`})},ne))})]})]},X)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:re,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:$,onChange:X=>{K(X.target.value),A(!0)},onKeyDown:X=>{(X.key==="Enter"||X.key===",")&&$.trim()&&(X.preventDefault(),Ke($.replace(",",""))),X.key==="Backspace"&&!$&&F.length>0&&Le(F[F.length-1])},onFocus:()=>A(!0),onBlur:()=>setTimeout(()=>A(!1),150)}),B&&$e.length>0&&t.jsx(Xm,{anchorRef:re,width:160,onClose:()=>A(!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:$e.slice(0,8).map(X=>t.jsx("button",{className:"flex items-center w-full px-2 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>Ke(X),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium ${Va(s.get(X)||"default")}`,children:X})},X))})]})]})]}),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:h("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:T,onChange:X=>be(Number(X.target.value)),children:[t.jsx("option",{value:0,children:h("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:h("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:h("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:h("plannerForm.priorityCritical")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:h("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:P,onChange:X=>Re(X.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:h("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:H,onChange:X=>ct(X.target.value),children:[t.jsx("option",{value:"pending",children:h("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:h("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:h("plannerStatus.done")})]})]})]})]})}),G&&t.jsx(Xp,{src:G,onClose:()=>J(null)})]})}let lB=0;function cB({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:u,onUpdateTag:f}){const{t:m}=xt(),[o,l]=y.useState(""),[h,p]=y.useState(""),[d,g]=y.useState([]),[v,C]=y.useState(""),[k,x]=y.useState(i??""),[S,_]=y.useState(0),[w,j]=y.useState("pending"),[R,E]=y.useState(!1),[D,N]=y.useState(!1),[T,z]=y.useState([]),[P,O]=y.useState([]),[H,U]=y.useState(null),F=y.useRef(null),q=y.useRef(null),$=y.useRef(null),[K,B]=y.useState(new Map),A=new Map([...e.map(ue=>[ue.name,ue.color]),...K]),I=["blue","green","orange","purple","pink","red","yellow","brown"];y.useEffect(()=>{var ue;if(s){l(s.title),p(s.description??""),g(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),_(s.priority),j(s.status);try{O(s.images?JSON.parse(s.images):[])}catch{O([])}}(ue=F.current)==null||ue.focus()},[s]);const Y=e.filter(ue=>!d.includes(ue.name)&&(!v||ue.name.toLowerCase().includes(v.toLowerCase()))),G=ue=>{var We;const Ve=ue.trim();Ve&&!d.includes(Ve)&&g(De=>{const be=[...De,Ve];if(!A.has(Ve)){const Re=I[A.size%I.length];B(ct=>new Map([...ct,[Ve,Re]]))}return be}),C(""),N(!0),(We=q.current)==null||We.focus()},J=ue=>g(d.filter(Ve=>Ve!==ue)),re=y.useCallback(ue=>{const Ve=Array.from(ue).filter(We=>We.type.startsWith("image/"));for(const We of Ve){const De=new FileReader;De.onload=()=>{const be=De.result,Re=`pending-${++lB}`;z(ct=>[...ct,{id:Re,name:We.name,data:be,preview:be}])},De.readAsDataURL(We)}},[]),Z=y.useCallback(ue=>{var De;const Ve=(De=ue.clipboardData)==null?void 0:De.items;if(!Ve)return;const We=[];for(let be=0;be<Ve.length;be++)if(Ve[be].type.startsWith("image/")){const Re=Ve[be].getAsFile();Re&&We.push(Re)}We.length!==0&&(ue.preventDefault(),re(We))},[re]),Q=y.useCallback(ue=>{var Ve;ue.preventDefault(),ue.stopPropagation(),(Ve=ue.dataTransfer)!=null&&Ve.files&&re(ue.dataTransfer.files)},[re]),W=ue=>z(Ve=>Ve.filter(We=>We.id!==ue)),oe=ue=>{s&&V1(s.id,ue),O(Ve=>Ve.filter(We=>We.id!==ue))},le=P.length+T.length,ge=async()=>{if(o.trim()){E(!0);try{const ue=await a({title:o.trim(),description:h.trim()||void 0,tags:d.length>0?JSON.stringify(d):void 0,due_date:k||void 0,priority:S,...s?{status:w}:{}});if(f&&K.size>0&&await Promise.all([...K.entries()].map(([Ve,We])=>f(Ve,{color:We}))),T.length>0){const Ve=(s==null?void 0:s.id)??(ue==null?void 0:ue.id);Ve&&await K1(Ve,T.map(We=>({name:We.name,data:We.data})))}}finally{E(!1)}}};return t.jsxs("div",{className:"card p-5",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[t.jsx("input",{ref:F,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:ue=>l(ue.target.value),onKeyDown:ue=>{ue.key==="Enter"&&ue.preventDefault()}}),t.jsx("textarea",{className:"input-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:m("plannerForm.descPlaceholder"),value:h,onChange:ue=>p(ue.target.value),onPaste:Z,onDrop:Q,onDragOver:ue=>{ue.preventDefault(),ue.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var ue;return(ue=$.current)==null?void 0:ue.click()},className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium text-warm-400 hover:text-warm-600 hover:bg-warm-100 transition-colors",children:[t.jsx(Xa,{size:14}),m("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),t.jsx("input",{ref:$,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:ue=>{ue.target.files&&re(ue.target.files),ue.target.value=""}}),le>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:["(",le,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[P.map(ue=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?Tu(s.id,ue.id):"",alt:ue.originalName,onClick:()=>s&&U(Tu(s.id,ue.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>oe(ue.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(Jt,{size:12})}),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:ue.originalName})})]},ue.id)),T.map(ue=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:ue.preview,alt:ue.name,onClick:()=>U(ue.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>W(ue.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(Jt,{size:12})}),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:ue.name})})]},ue.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:[d.map(ue=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Va(A.get(ue)||"default")}`,children:[ue,t.jsx("button",{onClick:()=>J(ue),className:"opacity-60 hover:opacity-100",children:t.jsx(Jt,{size:12})})]},ue)),t.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[t.jsx("input",{ref:q,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:d.length===0?m("plannerForm.tagsPlaceholder"):"",value:v,onChange:ue=>{C(ue.target.value),N(!0)},onKeyDown:ue=>{(ue.key==="Enter"||ue.key===",")&&v.trim()&&(ue.preventDefault(),G(v.replace(",",""))),ue.key==="Backspace"&&!v&&d.length>0&&J(d[d.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),D&&(Y.length>0||v.trim())&&t.jsxs(Xm,{anchorRef:q,width:208,onClose:()=>N(!1),className:"rounded-lg shadow-elevated z-tooltip py-1.5 max-h-48 overflow-y-auto",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[Y.slice(0,10).map(ue=>t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>G(ue.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Va(ue.color)}`,children:ue.name})},ue.name)),v.trim()&&!e.some(ue=>ue.name===v.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:()=>G(v),children:t.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',v.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:k,onChange:ue=>x(ue.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:S,onChange:ue=>_(Number(ue.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:w,onChange:ue=>j(ue.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:u,children:m("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:ge,disabled:!o.trim()||R,children:m("plannerForm.save")})]}),H&&t.jsx(Xp,{src:H,onClose:()=>U(null)})]})}function VS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:u}){const{t:f}=xt(),[m,o]=y.useState(i||"claude"),[l,h]=y.useState(""),[p,d]=y.useState(!1),[g,v]=y.useState("once"),[C,k]=y.useState("0 0 * * *"),[x,S]=y.useState(""),[_,w]=y.useState(!1),j=async()=>{w(!0);try{s==="todo"?await a({cli_tool:m,max_turns:l?Number(l):void 0}):s==="session"?await a({cli_tool:m,use_worktree:p}):await a({cli_tool:m,schedule_type:g,cron_expression:g==="recurring"?C:void 0,run_at:g==="once"?x:void 0})}finally{w(!1)}};return t.jsx(Dn,{open:!0,onClose:u,size:"md",position:"top",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:R=>o(R.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:l,onChange:R=>h(R.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:R=>d(R.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 ${g==="once"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>v("once"),children:f("plannerConvert.once")}),t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${g==="recurring"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>v("recurring"),children:f("plannerConvert.recurring")})]})]}),g==="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:R=>S(R.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:R=>k(R.target.value),placeholder:"0 0 * * *"})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:u,children:f("plannerConvert.cancel")}),t.jsx("button",{className:"btn-primary btn-sm",onClick:j,disabled:_||s==="schedule"&&g==="once"&&!x,children:f("plannerConvert.convert")})]})]})})}function yn(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 uw(e){return yn(new Date(e))}function dw(e){return new Date(e.getFullYear(),e.getMonth(),1)}function YS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function rr(e,s){const i=YS(e);return i.setDate(i.getDate()+s),i}function XS(e){return rr(e,-e.getDay())}function uB(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function dB(e,s,i,a){if(e==="resize-end")return{startKey:s.startKey,endKey:i<s.startKey?s.startKey:i};if(e==="resize-start")return{startKey:i>s.endKey?s.endKey:i,endKey:s.endKey};const u=uB(a,i),f=m=>yn(rr(new Date(m+"T00:00"),u));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function hB(e,s){if(e==="day"){const f=YS(s);return{rangeStart:yn(f),rangeEnd:yn(rr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=XS(s),m=Array.from({length:7},(o,l)=>rr(f,l));return{rangeStart:yn(f),rangeEnd:yn(rr(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=dw(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:yn(f),rangeEnd:yn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=dw(s),a=rr(i,-i.getDay()),u=Array.from({length:42},(f,m)=>rr(a,m));return{rangeStart:yn(a),rangeEnd:yn(rr(a,42)),gridDays:u,cols:7,dimOutOfMonth:!0}}function JS(e,s){return y.useMemo(()=>hB(e,s),[e,s])}function QS(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 ZS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=XS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${rr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function ek(){const{lang:e}=xt();return y.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>rr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const fB=420,mB=140,pB=220,gB=26,nm=16,hw=2;function xB(e,s){if(!s.length)return{placed:[],laneCount:0};const i=yn(e[0]),a=yn(e[e.length-1]),u=s.filter(o=>o.startKey<=a&&o.endKey>=i).map(o=>{const l=o.startKey<i?i:o.startKey,h=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(p=>yn(p)===l),endCol:e.findIndex(p=>yn(p)===h),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,l)=>o.startCol-l.startCol||l.endCol-l.startCol-(o.endCol-o.startCol)),f=[];return{placed:u.map(o=>{let l=0;for(;l<f.length&&f[l]>=o.startCol;)l++;return f[l]=o.endCol,{...o,lane:l}}),laneCount:f.length}}function tk({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:u,todayKey:f,selectedDate:m,chipsByDay:o,maxChips:l,weekdayLabels:h,addItemLabel:p,bars:d,onBarClick:g,onSelectDate:v,onQuickAdd:C,onChipClick:k,onCellContextMenu:x,onChipContextMenu:S,onBarContextMenu:_,onBarDrag:w,onChipDrag:j,monthCellHeight:R=92}){const{lang:E}=xt(),[D,N]=y.useState(null),[T,z]=y.useState(!1),P=y.useRef(null),O=y.useRef(null),H=()=>{O.current&&(clearTimeout(O.current),O.current=null)},U=(Z,Q)=>{H(),P.current&&clearTimeout(P.current);const W=Q.getBoundingClientRect();P.current=window.setTimeout(()=>N({key:Z,rect:W}),fB)},F=()=>{P.current&&(clearTimeout(P.current),P.current=null),O.current=window.setTimeout(()=>N(null),mB)};y.useEffect(()=>{if(!D){z(!1);return}const Z=requestAnimationFrame(()=>z(!0));return()=>cancelAnimationFrame(Z)},[D]),y.useEffect(()=>()=>{P.current&&clearTimeout(P.current),O.current&&clearTimeout(O.current)},[]),y.useEffect(()=>{if(!D)return;const Z=()=>N(null);return window.addEventListener("scroll",Z,!0),window.addEventListener("resize",Z),()=>{window.removeEventListener("scroll",Z,!0),window.removeEventListener("resize",Z)}},[D]);const q=D?o.get(D.key)??[]:[],[$,K]=y.useState(null),B=y.useRef(!1),A=4,I=(Z,Q)=>{var W,oe;return((oe=(W=document.elementFromPoint(Z,Q))==null?void 0:W.closest("[data-daykey]"))==null?void 0:oe.getAttribute("data-daykey"))??null},Y=(Z,Q,W)=>{Z.preventDefault(),Z.stopPropagation();const oe=I(Z.clientX,Z.clientY)??W.origStart,le=Z.clientX,ge=Z.clientY,ue=Q!=="move";let Ve=ue,We={startKey:W.origStart,endKey:W.origEnd};const De=()=>K({kind:W.kind,entryKey:W.entryKey,curStart:We.startKey,curEnd:We.endKey,title:W.title,bg:W.bg,fg:W.fg,done:W.done}),be=()=>{document.body.style.cursor=ue?"ew-resize":"grabbing",document.body.style.userSelect="none"};ue&&(be(),De());const Re=tt=>{if(!Ve){if(Math.abs(tt.clientX-le)<A&&Math.abs(tt.clientY-ge)<A)return;Ve=!0,be()}const Ke=I(tt.clientX,tt.clientY);Ke&&(We=dB(Q,{startKey:W.origStart,endKey:W.origEnd},Ke,oe),De())},ct=()=>{window.removeEventListener("pointermove",Re),window.removeEventListener("pointerup",ct),document.body.style.cursor="",document.body.style.userSelect="",K(null),Ve&&(B.current=!0,setTimeout(()=>{B.current=!1},0),!(We.startKey===W.origStart&&We.endKey===W.origEnd)&&(W.kind==="bar"&&W.bar?w==null||w(W.bar,We.startKey,We.endKey):W.kind==="chip"&&W.chip&&(j==null||j(W.chip,We.startKey,We.endKey))))};window.addEventListener("pointermove",Re),window.addEventListener("pointerup",ct)},G=(()=>{const Z=d??[];return $?$.kind==="bar"?Z.map(Q=>Q.key===$.entryKey?{...Q,startKey:$.curStart,endKey:$.curEnd}:Q):[...Z,{key:`__drag__${$.entryKey}`,title:$.title,startKey:$.curStart,endKey:$.curEnd,bg:$.bg,fg:$.fg,done:$.done}]:Z})(),J=(Z,Q)=>{const W=yn(Z),oe=o.get(W)??[],le=!a||Z.getMonth()===u,ge=W===f,ue=W===m,Ve=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",We=e==="month"&&oe.length>l;return t.jsxs("div",{"data-daykey":W,onClick:()=>{B.current||v(W)},onContextMenu:x?De=>x(W,De):void 0,onMouseEnter:We?De=>U(W,De.currentTarget):void 0,onMouseLeave:We?F:void 0,className:`group relative ${Ve} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?R+Q:void 0,backgroundColor:ue?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:le?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:Z.toLocaleDateString(E,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:ge?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:Z.getDate()})]}),t.jsx("button",{onClick:De=>{De.stopPropagation(),C(W)},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(wn,{size:14})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:Q||void 0},children:[oe.slice(0,l).map(De=>{if(($==null?void 0:$.kind)==="chip"&&$.entryKey===De.key)return null;const be=e==="month"&&!!(De.draggable&&j),Re={kind:"chip",entryKey:De.key,origStart:W,origEnd:W,title:De.title,bg:De.bg,fg:De.fg,done:De.done,chip:De};return t.jsxs("span",{onClick:ct=>{ct.stopPropagation(),!B.current&&k(De)},onPointerDown:be?ct=>Y(ct,"move",Re):void 0,onContextMenu:S?ct=>S(De,ct):void 0,className:`text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity ${be?"relative group/chip":""}`,style:{backgroundColor:De.bg,color:De.fg,textDecoration:De.done?"line-through":"none"},title:De.title,children:[De.prefix??"",De.time?`${De.time} `:"",De.title,be&&t.jsx("span",{onPointerDown:ct=>{ct.stopPropagation(),Y(ct,"resize-end",Re)},onClick:ct=>ct.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 group-hover/chip:opacity-100 cursor-ew-resize rounded-r-md",style:{backgroundColor:"rgba(127,127,127,0.5)"}})]},De.key)}),oe.length>l&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",oe.length-l]})]})]},W)},re=[];if(e==="month")for(let Z=0;Z<s.length;Z+=i)re.push(s.slice(Z,Z+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:h.map(Z=>t.jsx("div",{className:"px-2 py-1",children:Z},Z))}),e==="month"?t.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:re.map((Z,Q)=>{const{placed:W,laneCount:oe}=xB(Z,G),le=oe*(nm+hw);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[Z.map(ge=>J(ge,le)),W.map(({bar:ge,startCol:ue,endCol:Ve,lane:We,contStart:De,contEnd:be})=>{const Re=!!w&&!ge.key.startsWith("__drag__"),ct={kind:"bar",entryKey:ge.key,origStart:ge.startKey,origEnd:ge.endKey,title:ge.title,bg:ge.bg,fg:ge.fg,done:ge.done,bar:ge};return t.jsxs("div",{onClick:tt=>{tt.stopPropagation(),!B.current&&(g==null||g(ge))},onPointerDown:Re?tt=>Y(tt,"move",ct):void 0,onContextMenu:_?tt=>_(ge,tt):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{pointerEvents:$?"none":void 0,left:`calc(${ue} / ${i} * 100% + 2px)`,width:`calc(${Ve-ue+1} / ${i} * 100% - 4px)`,top:gB+We*(nm+hw),height:nm,backgroundColor:ge.bg,color:ge.fg,textDecoration:ge.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:De?0:4,borderBottomLeftRadius:De?0:4,borderTopRightRadius:be?0:4,borderBottomRightRadius:be?0:4},title:ge.title,children:[De?"◀ ":"",ge.title,be?" ▶":"",Re&&!De&&t.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),Y(tt,"resize-start",ct)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 left-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}}),Re&&!be&&t.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),Y(tt,"resize-end",ct)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 hover:opacity-100 cursor-ew-resize",style:{backgroundColor:"rgba(0,0,0,0.25)"}})]},ge.key)})]},Q)})}):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(Z=>J(Z,0))}),D&&(()=>{const Z=Math.max(D.rect.width,pB),Q=Math.min(Math.max(8,D.rect.left),window.innerWidth-Z-8),W=Math.max(8,Math.min(D.rect.top,window.innerHeight-120)),oe=window.innerHeight-W-16,le=Number(D.key.slice(8,10));return cn.createPortal(t.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:H,onMouseLeave:()=>N(null),style:{position:"fixed",left:Q,top:W,width:Z,maxHeight:oe,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:T?"scale(1)":"scale(0.96)",opacity:T?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:le}),t.jsx("div",{className:"flex flex-col gap-0.5",children:q.map(ge=>t.jsxs("span",{onClick:ue=>{ue.stopPropagation(),k(ge),N(null)},onContextMenu:S?ue=>S(ge,ue):void 0,className:"text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:ge.bg,color:ge.fg,textDecoration:ge.done?"line-through":"none"},title:ge.title,children:[ge.prefix??"",ge.time?`${ge.time} `:"",ge.title]},ge.key))})]}),document.body)})()]})}function vB(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function bB({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:u,onConvert:f,onDeleteItem:m,onUpdateRange:o}){const{t:l,lang:h}=xt(),[p,d]=y.useState(()=>new Date),[g,v]=y.useState(()=>yn(new Date)),[C,k]=y.useState(null),x=ek(),{gridDays:S,cols:_,dimOutOfMonth:w}=JS(e,p),j=yn(new Date),R=p.getMonth(),E=e==="month"?3:99,D=re=>d(Z=>QS(Z,e,re)),N=()=>{d(new Date),v(yn(new Date))},T=ZS(p,e,h);y.useEffect(()=>{e==="day"&&v(yn(p))},[e,p]);const z=260,P=760,O=y.useRef(null),[H,U]=y.useState(()=>{const re=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(re)&&re>=z&&re<=P?re:320});y.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(H))}catch{}},[H]);const F=re=>{re.preventDefault();const Z=W=>{var le;const oe=(le=O.current)==null?void 0:le.getBoundingClientRect();oe&&U(Math.min(P,Math.max(z,oe.right-W.clientX)))},Q=()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",Q),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",Z),window.addEventListener("pointerup",Q)},[q,$]=y.useState(new Map);y.useEffect(()=>{$(new Map)},[s]);const K=y.useMemo(()=>q.size===0?s:s.map(re=>{const Z=q.get(re.id);return Z?{...re,due_date:Z.due_date,end_date:Z.end_date}:re}),[s,q]),B=y.useCallback((re,Z,Q)=>{$(W=>new Map(W).set(re,{due_date:Z,end_date:Q})),o(re,Z,Q)},[o]),A=re=>!!(re.due_date&&re.end_date&&re.end_date.slice(0,10)>re.due_date.slice(0,10)),I=y.useMemo(()=>{const re=new Map;for(const Z of K){if(!Z.due_date||e==="month"&&A(Z))continue;const Q=Z.due_date.slice(0,10),W=Z.status==="done",oe=re.get(Q)??[];oe.push({key:Z.id,title:Z.title,bg:"var(--color-bg-secondary)",fg:W?"var(--color-text-muted)":"var(--color-text-secondary)",done:W,payload:Z,draggable:!0}),re.set(Q,oe)}return re},[K,e]),Y=y.useMemo(()=>e!=="month"?[]:K.filter(A).map(re=>{const Z=re.status==="done";return{key:re.id,title:re.title,startKey:re.due_date.slice(0,10),endKey:re.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:Z?"var(--color-text-muted)":"var(--color-text-secondary)",done:Z,payload:re}}),[K,e]),G=y.useMemo(()=>s.filter(re=>re.due_date&&re.due_date.slice(0,10)===g),[s,g]),J=y.useMemo(()=>s.filter(re=>!re.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:()=>D(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(op,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:T}),t.jsx("button",{onClick:()=>D(1),className:"btn-ghost p-1.5","aria-label":"next",children:t.jsx(ws,{size:16})}),t.jsx("button",{onClick:N,className:"btn-ghost text-xs px-2.5 py-1.5",children:l("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(tk,{view:e,gridDays:S,cols:_,dimOutOfMonth:w,monthIdx:R,todayKey:j,selectedDate:g,chipsByDay:I,maxChips:E,weekdayLabels:x,addItemLabel:l("agenda.addItem"),onSelectDate:v,onQuickAdd:a,onChipClick:re=>u(re.payload),onCellContextMenu:(re,Z)=>{Z.preventDefault(),k({x:Z.clientX,y:Z.clientY,dateKey:re})},bars:Y,onBarClick:re=>u(re.payload),onBarDrag:(re,Z,Q)=>B(re.payload.id,Z,Q),onChipDrag:(re,Z,Q)=>B(re.payload.id,Z,Q)})})]}),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:l("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:H},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(g+"T00:00").toLocaleDateString(h,{month:"long",day:"numeric",weekday:"short"})}),t.jsxs("button",{onClick:()=>a(g),className:"btn-ghost text-xs px-2 py-1 flex items-center gap-1",children:[t.jsx(wn,{size:14}),l("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:[G.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:l("agenda.dayEmpty")}),G.map(re=>t.jsx(fw,{item:re,tagColors:i,onEdit:u,onConvert:f,onDelete:m},re.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:l("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[J.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:l("agenda.backlogEmpty")}),J.map(re=>t.jsx(fw,{item:re,tagColors:i,onEdit:u,onConvert:f,onDelete:m},re.id))]})]})]})]}),C&&t.jsx(Gs,{x:C.x,y:C.y,onClose:()=>k(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>a(C.dateKey),children:[t.jsx(wn,{size:14}),l("planner.add")]})})]})}function fw({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:u}){const{t:f}=xt(),{confirm:m}=Yn(),[o,l]=y.useState(!1),[h,p]=y.useState(!1),[d,g]=y.useState({top:0,left:0}),v=y.useRef(null),C=y.useRef(null),k=vB(e.tags),x=e.status==="moved",S=y.useCallback(()=>{if(!v.current)return;const _=v.current.getBoundingClientRect(),w=window.innerWidth,j=window.innerHeight;let R=_.bottom+4;const E=C.current;if(E){const D=E.offsetWidth,N=E.offsetHeight;let T=_.right-D;T<8&&(T=8),T+D>w-8&&(T=w-8-D),R+N>j-8&&(R=_.top-N-4),g({top:R,left:T}),p(!0)}else g({top:R,left:Math.max(8,_.right-180)})},[]);return y.useEffect(()=>{if(!o){p(!1);return}S();const _=requestAnimationFrame(S),w=j=>{var E,D;const R=j.target;(E=v.current)!=null&&E.contains(R)||(D=C.current)!=null&&D.contains(R)||l(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",S,!0),window.addEventListener("resize",S),()=>{cancelAnimationFrame(_),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",S)}},[o,S]),t.jsxs("div",{className:`group flex items-start gap-2 rounded-lg px-2.5 py-2 ${x?"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 ${$u[e.status]||$u.pending}`,children:f(`plannerStatus.${e.status}`)}),k.map(_=>t.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Va(s.get(_)||"default")}`,children:_},_))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:v,onClick:_=>{_.stopPropagation(),l(!o)},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(cp,{size:14})}),o&&cn.createPortal(t.jsxs("div",{ref:C,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:d.top,left:d.left,opacity:h?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>l(!1),children:[!x&&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(n1,{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(Vi,{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(bi,{size:12})," ",f("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await m({message:f("planner.deleteConfirm"),danger:!0})&&u(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(Pn,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const mw={pending:0,in_progress:1,done:2,moved:3};function yB({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:u,onDeleteItem:f,onConvertToTodo:m,onConvertToSchedule:o,onConvertToSession:l,onUpdateTag:h,onDeleteTag:p,onExport:d,onImport:g,view:v,onChangeView:C}){const{t:k}=xt(),{warning:x}=Rs(),[S,_]=y.useState(!1),[w,j]=y.useState(null),[R,E]=y.useState(void 0),[D,N]=y.useState(""),[T,z]=y.useState(""),[P,O]=y.useState("created_at"),[H,U]=y.useState("desc"),[F,q]=y.useState(null),[$,K]=y.useState("todo"),[B,A]=y.useState(!1),[I,Y]=y.useState(!1),[G,J]=y.useState(null),re=y.useRef(null),Z=y.useRef(0),Q=async()=>{if(!(!d||B)){A(!0);try{await d()}finally{A(!1)}}},W=()=>{var Le;!g||B||(Le=re.current)==null||Le.click()},oe=async Le=>{var Ie;const $e=(Ie=Le.target.files)==null?void 0:Ie[0];if(Le.target.value="",!(!$e||!g)){A(!0);try{await g($e)}finally{A(!1)}}},le=Le=>!!(/\.(md|markdown)$/i.test(Le.name)||Le.type==="text/markdown"),ge=Le=>Array.from(Le.dataTransfer.types).includes("Files"),ue=Le=>{!g||B||ge(Le)&&(Le.preventDefault(),Z.current++,Y(!0))},Ve=Le=>{!g||B||ge(Le)&&(Le.preventDefault(),Le.dataTransfer.dropEffect="copy")},We=Le=>{g&&(Le.preventDefault(),Z.current=Math.max(0,Z.current-1),Z.current===0&&Y(!1))},De=async Le=>{var Ie;if(!g||(Le.preventDefault(),Z.current=0,Y(!1),B))return;const $e=(Ie=Le.dataTransfer.files)==null?void 0:Ie[0];if($e){if(!le($e)){x(k("planner.dropInvalidFile"));return}A(!0);try{await g($e)}finally{A(!1)}}},be=y.useMemo(()=>s.map(Le=>Le.name),[s]),Re=y.useMemo(()=>new Map(s.map(Le=>[Le.name,Le.color])),[s]),ct=y.useMemo(()=>{let Le=e.filter($e=>!(T&&$e.status!==T||D&&!($e.tags?(()=>{try{return JSON.parse($e.tags)}catch{return[]}})():[]).includes(D)));return Le=[...Le].sort(($e,Ie)=>{let it=0;switch(P){case"title":it=$e.title.localeCompare(Ie.title);break;case"tags":{const vt=$e.tags?(()=>{try{return JSON.parse($e.tags).join(",")}catch{return""}})():"",Ce=Ie.tags?(()=>{try{return JSON.parse(Ie.tags).join(",")}catch{return""}})():"";it=(vt||"zzz").localeCompare(Ce||"zzz");break}case"priority":it=$e.priority-Ie.priority;break;case"due_date":{const vt=$e.due_date||"9999",Ce=Ie.due_date||"9999";it=vt.localeCompare(Ce);break}case"status":it=(mw[$e.status]??9)-(mw[Ie.status]??9);break;case"created_at":it=$e.created_at.localeCompare(Ie.created_at);break}return H==="asc"?it:-it}),Le},[e,D,T,P,H]),tt=Le=>{P===Le?U($e=>$e==="asc"?"desc":"asc"):(O(Le),U(Le==="priority"?"desc":"asc"))},Ke=({field:Le})=>P!==Le?null:H==="asc"?t.jsx(_5,{size:12,className:"inline ml-0.5"}):t.jsx(x5,{size:12,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:[k("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:[v!=="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(Le=>t.jsx("button",{onClick:()=>C(Le),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:v===Le?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:k(`agenda.view.${Le}`)},Le))}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:D,onChange:Le=>N(Le.target.value),children:[t.jsx("option",{value:"",children:k("planner.filterTag")}),be.map(Le=>t.jsx("option",{value:Le,children:Le},Le))]}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:T,onChange:Le=>z(Le.target.value),children:[t.jsx("option",{value:"",children:k("planner.filterStatus")}),t.jsx("option",{value:"pending",children:k("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:k("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:k("plannerStatus.done")}),t.jsx("option",{value:"moved",children:k("plannerStatus.moved")})]}),d&&t.jsxs("button",{onClick:Q,disabled:B||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.exportTooltip"),children:[t.jsx(fm,{size:14,className:"inline-block shrink-0"}),k("planner.export")]}),g&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:W,disabled:B,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.importTooltip"),children:[t.jsx(ob,{size:14,className:"inline-block shrink-0"}),k("planner.import")]}),t.jsx("input",{ref:re,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:oe})]}),!S&&!w&&t.jsxs("button",{onClick:()=>_(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(wn,{size:14,className:"inline-block shrink-0"}),k("planner.add")]})]})]}),(S||w)&&t.jsx("div",{className:"mb-5",children:t.jsx(cB,{existingTags:s,editItem:w,initialDueDate:R,onSave:async Le=>{if(w){await u(w.id,Le),j(null);return}else{const $e=await a(Le);return _(!1),E(void 0),$e}},onCancel:()=>{_(!1),j(null),E(void 0)},onUpdateTag:h})}),v==="table"?t.jsxs("div",{className:"card relative",onDragEnter:g?ue:void 0,onDragOver:g?Ve:void 0,onDragLeave:g?We:void 0,onDrop:g?De:void 0,onContextMenu:Le=>{yi(Le)||(Le.preventDefault(),J({x:Le.clientX,y:Le.clientY}))},children:[I&&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(ob,{size:32,className:"inline-block mb-2",style:{color:"var(--color-accent, #3b82f6)"}}),t.jsx("div",{className:"text-sm font-semibold",children:k("planner.dropHint")}),t.jsx("div",{className:"text-xs text-warm-500 mt-1",children:k("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 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("title"),children:[k("planner.col.title"),t.jsx(Ke,{field:"title"})]}),t.jsxs("div",{className:"w-[160px] section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("tags"),children:[k("planner.col.tags"),t.jsx(Ke,{field:"tags"})]}),t.jsxs("div",{className:"w-12 text-center section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("priority"),children:[k("plannerForm.priority"),t.jsx(Ke,{field:"priority"})]}),t.jsxs("div",{className:"hidden md:block w-20 text-right section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("due_date"),children:[k("planner.col.dueDate"),t.jsx(Ke,{field:"due_date"})]}),t.jsxs("div",{className:"w-16 section-label cursor-pointer hover:text-warm-700 transition-colors",onClick:()=>tt("status"),children:[k("planner.col.status"),t.jsx(Ke,{field:"status"})]}),t.jsx("div",{className:"w-8"})]}),ct.length===0?t.jsx(Zi,{icon:GE,title:k("planner.empty"),description:k("planner.emptyHint")}):ct.map((Le,$e)=>t.jsx("div",{children:t.jsx(oB,{item:Le,tagColors:Re,existingTags:be,onSave:async(Ie,it)=>{await u(Ie,it)},onDelete:()=>f(Le.id),onConvertToTodo:()=>{q(Le),K("todo")},onConvertToSchedule:()=>{q(Le),K("schedule")},onConvertToSession:()=>{q(Le),K("session")},onUpdateTag:h})},Le.id))]}):t.jsx(bB,{view:v,items:ct,tagColors:Re,onQuickAdd:Le=>{j(null),E(Le),_(!0)},onEditItem:Le=>{_(!1),j(Le)},onConvert:(Le,$e)=>{q(Le),K($e)},onDeleteItem:f,onUpdateRange:(Le,$e,Ie)=>{u(Le,{due_date:$e,end_date:Ie})}}),F&&t.jsx(VS,{item:F,mode:$,projectCliTool:i,onConvert:async Le=>{$==="todo"?await m(F.id,Le):$==="session"?await l(F.id,Le):await o(F.id,Le),q(null)},onClose:()=>q(null)}),G&&t.jsx(Gs,{x:G.x,y:G.y,onClose:()=>J(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>{j(null),E(void 0),_(!0)},children:[t.jsx(wn,{size:14}),k("planner.add")]})})]})}const nk=y.createContext(null),wB=nk.Provider;function XP(){const e=y.useContext(nk);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const _B=y.lazy(()=>Xu(()=>import("./PlannerPageEditor-BO6Tm17g.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),SB=800;function kB({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:l}=xt(),[h,p]=y.useState(null),[d,g]=y.useState("idle"),[v,C]=y.useState(null),k=y.useRef({title:"",content:null}),x=y.useRef(null);y.useEffect(()=>{let E=!1;return xL(e).then(D=>{E||(p(D),k.current={title:D.title,content:D.content??null})}),()=>{E=!0}},[e]);const S=y.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:E,content:D}=k.current;return g("saving"),vL(e,{title:E,content:D??void 0}).then(()=>g("saved"))},[e]);y.useEffect(()=>()=>{x.current&&S()},[S]);const _=y.useCallback(()=>{x.current&&clearTimeout(x.current),g("saving"),x.current=setTimeout(()=>{S()},SB)},[S]),w=E=>{k.current.title=E,p(D=>D&&{...D,title:E}),u(e,E),_()},j=E=>{k.current.content=E,_()},R=y.useCallback((E,D,N)=>{C({item:E,mode:D,onDone:N})},[]);return h?t.jsxs(wB,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:R},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:h.title,onChange:E=>w(E.target.value),placeholder:l("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:d==="saving"?l("planner.pages.saving"):d==="saved"?l("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(y.Suspense,{fallback:null,children:t.jsx(_B,{pageId:e,initialContent:h.content??null,onChange:j})})})]}),v&&t.jsx(VS,{item:v.item,mode:v.mode,projectCliTool:i,onConvert:async E=>{const{item:D,mode:N,onDone:T}=v;N==="todo"?await f(D.id,E):N==="session"?await o(D.id,E):await m(D.id,E),T==null||T(),C(null)},onClose:()=>C(null)})]}):null}const On=(e,s)=>({type:"heading",props:{level:e},content:s}),il=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},pw=e=>({type:"bulletListItem"}),Wi=e=>({type:"checkListItem"}),gw=()=>({type:"tasklist"}),xw=()=>({type:"calendar"}),CB=[{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:[On(1,"회의 노트"),il("날짜: "),il("참석자: "),On(2,"안건"),pw(),On(2,"논의"),il(),On(2,"액션 아이템"),gw()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[On(1,"프로젝트 플랜"),On(2,"개요"),il(),On(2,"마일스톤"),gw(),On(2,"일정"),xw(),On(2,"리스크 / 메모"),il()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[On(1,"위클리 플래너"),On(2,"이번 주 목표"),pw(),On(2,"요일별 할 일"),On(3,"월요일"),Wi(),On(3,"화요일"),Wi(),On(3,"수요일"),Wi(),On(3,"목요일"),Wi(),On(3,"금요일"),Wi(),On(3,"토요일"),Wi(),On(3,"일요일"),Wi(),On(2,"주간 일정"),xw()]}];function jB({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,u=null;const f=()=>{if(a=null,u===null)return;const l=u;u=null,e(l)},m=l=>{u=l.clientX,a===null&&(a=requestAnimationFrame(f))},o=l=>{a!==null&&cancelAnimationFrame(a),a=null,l.type==="pointerup"&&u!==null&&f(),u=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 vw=160,bw=480,yw="plannerSidebarWidth",ww="plannerSidebarCollapsed";function EB({projectId:e,...s}){const{t:i}=xt(),{confirm:a}=Yn(),[u,f]=y.useState([]),[m,o]=y.useState({kind:"work"}),[l,h]=y.useState("table"),[p,d]=y.useState(!1),[g,v]=y.useState({top:0,left:0}),C=y.useRef(null),k=y.useRef(null),x=y.useRef(!1),[S,_]=y.useState(()=>{const K=Number(localStorage.getItem(yw));return K>=vw&&K<=bw?K:208}),w=y.useCallback(K=>{var I;const B=((I=k.current)==null?void 0:I.getBoundingClientRect().left)??0,A=Math.round(Math.max(vw,Math.min(bw,K-B)));_(A),localStorage.setItem(yw,String(A))},[]),[j,R]=y.useState(()=>localStorage.getItem(ww)==="1"),E=()=>R(K=>(localStorage.setItem(ww,K?"0":"1"),!K)),D=240,N=()=>{var B;const K=(B=C.current)==null?void 0:B.getBoundingClientRect();if(K){const A=Math.min(K.left,window.innerWidth-D-8);v({top:K.bottom+4,left:Math.max(8,A)})}d(!0)};y.useEffect(()=>{if(!p)return;const K=()=>d(!1),B=A=>{var I;(I=C.current)!=null&&I.contains(A.target)||A.target.closest("[data-template-picker]")||d(!1)};return document.addEventListener("mousedown",B),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{document.removeEventListener("mousedown",B),window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[p]),y.useEffect(()=>{pL(e).then(K=>{f(K),x.current||(x.current=!0,K.length>0&&o({kind:"page",id:K[0].id}))})},[e]);const T=async K=>{d(!1);const B=await gL(e,K.title||i("planner.pages.untitled"),K.blocks?JSON.stringify(K.blocks):void 0);f(A=>[...A,B]),o({kind:"page",id:B.id})},z=async K=>{await a({message:i("planner.pages.deleteConfirm"),danger:!0})&&(await bL(K),f(B=>B.filter(A=>A.id!==K)),o(B=>B.kind==="page"&&B.id===K?{kind:"work"}:B))},P=y.useCallback((K,B)=>{f(A=>A.map(I=>I.id===K?{...I,title:B}:I))},[]),O=()=>{o({kind:"work"}),h(K=>K==="table"?"month":K)},H=()=>{o({kind:"work"}),h("table")},U=m.kind==="work",F=U&&l!=="table",q=U&&l==="table",$=(K,B,A,I,Y)=>t.jsxs("div",{onClick:B,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${K?"":"hover:bg-warm-50"}`,style:K?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[A,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:I}),Y]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[j?t.jsx("div",{className:"flex-shrink-0 flex flex-col items-center card p-1.5",children:t.jsx("button",{onClick:E,className:"p-1 text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.expand"),children:t.jsx(f1,{size:14})})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:k,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:S},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.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{ref:C,onClick:()=>p?d(!1):N(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(wn,{size:14})}),t.jsx("button",{onClick:E,className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.collapse"),children:t.jsx(h1,{size:14})})]})]}),u.map(K=>$(m.kind==="page"&&m.id===K.id,()=>o({kind:"page",id:K.id}),t.jsx(ll,{size:14,className:"text-warm-400 flex-shrink-0"}),K.title||i("planner.pages.untitled"),t.jsx("button",{onClick:B=>{B.stopPropagation(),z(K.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-status-error transition-all flex-shrink-0",children:t.jsx(Pn,{size:14})}))),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")}),$(F,O,t.jsx(hm,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),$(q,H,t.jsx(Eu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(jB,{onResize:w})]}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:m.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(kB,{pageId:m.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:P,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},m.id)}):t.jsx(yB,{...s,view:l,onChangeView:h})}),p&&cn.createPortal(t.jsx("div",{"data-template-picker":!0,className:"fixed z-tooltip rounded-xl py-1 shadow-elevated",style:{top:g.top,left:g.left,width:D,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:CB.map(K=>t.jsxs("button",{onClick:()=>T(K),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(K.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(K.descKey)})]},K.id))}),document.body)]})}const sk="webPanelTabs",NB="plannerWebPanelUrl",Jp="https://www.notion.so",LB="electronAPI"in window;function DB(e){const s=e.trim();return s?/^https?:\/\//i.test(s)?s:`https://${s}`:Jp}function Jm(e=""){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,8),src:e,url:e,title:""}}function TB(){var s;try{const i=JSON.parse(localStorage.getItem(sk)||"");if((s=i.tabs)!=null&&s.length){const a=i.tabs.map(({id:f,url:m})=>({id:f,src:m,url:m,title:""})),u=a.some(f=>f.id===i.activeId)?i.activeId:a[0].id;return{tabs:a,activeId:u}}}catch{}const e=Jm(localStorage.getItem(NB)||Jp);return{tabs:[e],activeId:e.id}}function RB(){const{t:e}=xt(),[{tabs:s,activeId:i},a]=y.useState(TB),u=s.find(j=>j.id===i)??s[0],[f,m]=y.useState(u.url),[o,l]=y.useState(!1),[h,p]=y.useState(!1),d=o&&h,g=y.useRef(null),v=y.useRef(null);y.useEffect(()=>{localStorage.setItem(sk,JSON.stringify({tabs:s.map(({id:j,url:R})=>({id:j,url:R})),activeId:i}))},[s,i]),y.useEffect(()=>{m(u.url)},[u.id,u.url]);const C=y.useCallback((j,R)=>{a(E=>({...E,tabs:E.tabs.map(D=>D.id===j?{...D,...R}:D)}))},[]),k=y.useCallback((j="")=>{var E;const R=Jm(j);a(D=>({tabs:[...D.tabs,R],activeId:R.id})),j||(E=g.current)==null||E.focus()},[]),x=j=>{a(R=>{const E=R.tabs.findIndex(N=>N.id===j),D=R.tabs.filter(N=>N.id!==j);if(D.length===0){const N=Jm();return{tabs:[N],activeId:N.id}}return R.activeId!==j?{...R,tabs:D}:{tabs:D,activeId:D[Math.min(E,D.length-1)].id}})},S=()=>{const j=DB(f);m(j),C(u.id,{src:j,url:j})};y.useEffect(()=>{var R;const j=window.electronAPI;return(R=j==null?void 0:j.onWebPanelOpenUrl)==null?void 0:R.call(j,E=>k(E))},[k]),y.useEffect(()=>{const j=v.current;if(!j)return;const R=()=>{j.style.pointerEvents="none"},E=()=>{j.style.pointerEvents=""};return window.addEventListener("mousedown",R,!0),window.addEventListener("mouseup",E,!0),window.addEventListener("blur",E),()=>{window.removeEventListener("mousedown",R,!0),window.removeEventListener("mouseup",E,!0),window.removeEventListener("blur",E)}},[]);const _=y.useCallback(j=>{if(!j)return;const R=j.dataset.tabId,E=N=>C(R,{title:N.title}),D=N=>{const{url:T,isMainFrame:z}=N;z!==!1&&C(R,{url:T})};return j.addEventListener("page-title-updated",E),j.addEventListener("did-navigate",D),j.addEventListener("did-navigate-in-page",D),()=>{j.removeEventListener("page-title-updated",E),j.removeEventListener("did-navigate",D),j.removeEventListener("did-navigate-in-page",D)}},[C]),w=j=>{if(j.title)return j.title;try{return new URL(j.url).hostname}catch{return e("web.newTab")}};return t.jsxs("div",{className:o?"fixed inset-0 z-modal flex flex-col":"flex flex-col flex-1 min-h-0",style:o?{backgroundColor:"var(--color-bg-card)"}:void 0,onKeyDown:j=>{(j.ctrlKey||j.metaKey)&&!j.altKey&&!j.shiftKey&&j.key.toLowerCase()==="t"&&(j.preventDefault(),k())},children:[t.jsxs("div",{role:"tablist",className:`${d?"hidden":"flex"} items-end gap-0.5 px-2 border-b border-theme-border overflow-x-auto`,children:[s.map(j=>t.jsxs("div",{role:"tab","aria-selected":j.id===i,onClick:()=>a(R=>({...R,activeId:j.id})),onMouseDown:R=>{R.button===1&&R.preventDefault()},onAuxClick:R=>{R.button===1&&(R.preventDefault(),x(j.id))},className:`flex items-center gap-1 px-3 py-1.5 text-xs whitespace-nowrap cursor-pointer transition-colors ${j.id===i?"border-b-2 border-accent text-accent font-medium":"text-theme-text-secondary hover:text-theme-text"}`,children:[t.jsx("span",{className:"truncate max-w-[160px]",children:w(j)}),t.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),x(j.id)},className:"p-0.5 rounded hover:bg-theme-hover",title:e("web.closeTab"),"aria-label":e("web.closeTab"),children:t.jsx(Jt,{size:12})})]},j.id)),t.jsx("button",{type:"button",onClick:()=>k(),className:"p-1 mb-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e("web.newTab"),"aria-label":e("web.newTab"),children:t.jsx(wn,{size:14})})]}),t.jsxs("form",{onSubmit:j=>{j.preventDefault(),S()},className:`${d?"hidden":"flex"} items-center gap-2 p-2 border-b border-theme-border`,children:[t.jsx("input",{ref:g,value:f,onChange:j=>m(j.target.value),placeholder:e("web.urlPlaceholder"),className:"input-field flex-1",spellCheck:!1}),t.jsx($t,{type:"submit",size:"sm",children:e("web.go")}),o&&t.jsx("button",{type:"button",onClick:()=>p(!0),className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e("web.hideBar"),"aria-label":e("web.hideBar"),children:t.jsx(lp,{size:14})}),t.jsx("button",{type:"button",onClick:()=>{l(j=>!j),p(!1)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e(o?"web.exitFullscreen":"web.fullscreen"),children:o?t.jsx(Tl,{size:14}):t.jsx(gi,{size:14})})]}),d&&t.jsx("button",{type:"button",onClick:()=>p(!1),className:"absolute top-0 left-1/2 -translate-x-1/2 z-10 px-3 py-0.5 rounded-b-md bg-theme-card border border-t-0 border-theme-border shadow-card text-warm-400 hover:text-warm-600 transition-colors",title:e("web.showBar"),"aria-label":e("web.showBar"),children:t.jsx(_i,{size:14})}),t.jsx("div",{ref:v,className:"flex-1 min-h-0 flex flex-col",children:LB?s.map(j=>j.src?y.createElement("webview",{key:j.id,ref:_,"data-tab-id":j.id,src:j.src,partition:"persist:webpanel",allowpopups:"",className:j.id===i?"flex-1 min-h-0":"hidden"}):j.id===i&&t.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-theme-text-secondary",children:e("web.emptyTab")},j.id)):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-sm text-theme-text-secondary",children:[t.jsx("span",{children:e("web.desktopOnly")}),t.jsxs($t,{size:"sm",className:"flex items-center gap-1.5",onClick:()=>window.open(u.url||Jp,"_blank","noopener"),children:[t.jsx(qs,{size:14}),e("web.openExternal")]})]})})]})}const MB=y.lazy(()=>Xu(()=>import("./AnalyticsPanel-DtuQq2KX.js"),__vite__mapDeps([9,7,3,2]))),AB=y.lazy(()=>Xu(()=>import("./VaultLayout-DH6m6VLs.js"),__vite__mapDeps([10,6,1,2,3,4])));function zB({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:u}=tp(),[f,m]=y.useState(null),[o,l]=y.useState([]),[h,p]=y.useState([]),[d,g]=y.useState(null),[v,C]=y.useState([]),[k,x]=y.useState([]),[S,_]=y.useState([]),[w,j]=y.useState([]),[R,E]=Qw(),D=["tasks","discussions","schedules","analytics"],N=R.get("tab")||"tasks",[T,z]=y.useState(D.includes(N)?"automation":N),[P,O]=y.useState(D.includes(N)?N:"tasks"),H=y.useCallback(ae=>{if(ae==="automation"){z("automation"),E(P==="tasks"?{}:{tab:P},{replace:!0});return}z(ae),E(ae==="tasks"?{}:{tab:ae},{replace:!0})},[E,P]),U=y.useCallback(ae=>{z("automation"),O(ae),E(ae==="tasks"?{}:{tab:ae},{replace:!0})},[E]),F=y.useMemo(()=>{if(!f)return[];let ae=[];try{ae=JSON.parse(f.hidden_tabs||"[]")}catch{}return f.is_git_repo||ae.push("git"),f.svn_enabled||ae.push("svn"),ae},[f]);y.useEffect(()=>{F.includes(T)&&H("automation")},[F,T,H]);const[q,$]=y.useState(!0),[K,B]=y.useState(!1),[A,I]=y.useState(new Set),[Y,G]=y.useState(0),{t:J}=xt(),{success:re,error:Z,info:Q}=Rs(),{sendNotification:W}=ro(),oe=y.useRef([]);y.useEffect(()=>{oe.current=v},[v]),y.useEffect(()=>{u&&Promise.all([e4(u),_f(u),kb(u),Cb(u),z3(),W1(u),Xc(u),Jc(u)]).then(([ae,ve,ye,me,nt,pt,jt,Bt])=>{m(ae),l(ve),p(ye),C(me),x(pt),_(jt),j(Bt),nt.resetsAt&&g(nt.resetsAt);const ze=ve.filter(ut=>ut.status==="running"&&ut.execution_mode==="interactive").map(ut=>ut.id);ze.length>0&&I(new Set(ze))}).catch(()=>B(!0)).finally(()=>$(!1))},[u]);const le=y.useRef(o);le.current=o,y.useEffect(()=>{if(!u)return;const ae=setInterval(()=>{le.current.some(ye=>ye.status==="running")&&_f(u).then(ye=>{l(me=>me.map(nt=>{const pt=ye.find(jt=>jt.id===nt.id);return pt&&pt.status!==nt.status?pt:nt}))}).catch(()=>{})},5e3);return()=>clearInterval(ae)},[u]);const ge=y.useRef(s);y.useEffect(()=>{s&&!ge.current&&u&&Promise.all([_f(u),kb(u),Cb(u)]).then(([ae,ve,ye])=>{l(ae),p(ve),C(ye)}).catch(()=>{}),ge.current=s},[s,u]),y.useEffect(()=>e(ae=>{if(ae.type==="todo:status-changed"&&ae.todoId&&ae.status){if(l(ve=>ve.map(ye=>{if(ye.id!==ae.todoId)return ye;const me={status:ae.status,updated_at:new Date().toISOString()};return ae.worktree_path!==void 0&&(me.worktree_path=ae.worktree_path??null),ae.branch_name!==void 0&&(me.branch_name=ae.branch_name??null),{...ye,...me}})),(ae.status==="completed"||ae.status==="merged"||ae.status==="failed")&&G(ve=>ve+1),ae.status==="completed"||ae.status==="failed"){const ve=le.current.find(ye=>ye.id===ae.todoId);ve&&W(ae.status==="completed"?J("notification.taskCompleted"):J("notification.taskFailed"),ve.title)}ae.status==="running"&&ae.mode==="interactive"?I(ve=>new Set(ve).add(ae.todoId)):ae.status!=="running"&&I(ve=>{const ye=new Set(ve);return ye.delete(ae.todoId),ye})}if(ae.type==="todo:created"&&ae.todo&&ae.todo.project_id===u){const ve=ae.todo;l(ye=>ye.some(me=>me.id===ve.id)?ye:[...ye,ve])}if(ae.type==="schedule:status-changed"&&ae.scheduleId&&p(ve=>ve.map(ye=>ye.id===ae.scheduleId?{...ye,is_active:ae.isActive?1:0,updated_at:new Date().toISOString()}:ye)),ae.type==="rate-limit:updated"&&ae.resetsAt&&g(ae.resetsAt),ae.type==="discussion:status-changed"&&ae.discussionId&&(C(ve=>ve.map(ye=>ye.id===ae.discussionId?{...ye,status:ae.status,current_round:ae.currentRound??ye.current_round,updated_at:new Date().toISOString()}:ye)),ae.status==="completed"||ae.status==="failed")){const ve=oe.current.find(ye=>ye.id===ae.discussionId);ve&&W(ae.status==="completed"?J("notification.discussionCompleted"):J("notification.discussionFailed"),ve.title)}ae.type==="session:status-changed"&&ae.sessionId&&x(ve=>ve.map(ye=>{if(ye.id!==ae.sessionId)return ye;const me={status:ae.status,updated_at:new Date().toISOString()};return ae.worktree_path!==void 0&&(me.worktree_path=ae.worktree_path),ae.branch_name!==void 0&&(me.branch_name=ae.branch_name),ae.cli_session_id!==void 0&&(me.cli_session_id=ae.cli_session_id),ae.resumable!==void 0&&(me.resumable=ae.resumable),{...ye,...me}}))}),[e,W,J]);const ue=y.useCallback(async(ae,ve,ye,me,nt,pt,jt,Bt,ze,ut)=>{if(!u)return;const _t=await _b(u,{title:ae,description:ve,cli_tool:ye,depends_on:nt,max_turns:pt??null,use_worktree:jt??null,...Bt?{memory_inject_mode:Bt}:{},...ze?{memory_node_ids:ze}:{},...ut?{memory_raw_file_paths:ut}:{}});if(me&&me.length>0){const Mt=await F1(_t.id,me.map(At=>({name:At.name,data:At.data})));_t.images=JSON.stringify(Mt.images)}l(Mt=>[...Mt,_t])},[u]),Ve=y.useCallback((ae,ve=[])=>{const ye=ae.split("/").filter(Boolean).pop()??ae,me=[ae,...ve].map(nt=>`@${nt}`).join(`
683
683
  `);return ue(ye,`다음 파일을 참고하세요:
684
684
  ${me}`)},[ue]),We=y.useCallback(async(ae,ve)=>{const ye=ve==="interactive";ye&&I(me=>new Set(me).add(ae));try{const me=await Sb(ae,ve);l(nt=>nt.map(pt=>pt.id===ae?me:pt))}catch(me){throw ye&&I(nt=>{const pt=new Set(nt);return pt.delete(ae),pt}),me}},[]),De=y.useCallback(async ae=>{const ve=await _3(ae);l(ye=>ye.map(me=>me.id===ae?ve:me))},[]),be=y.useCallback(async ae=>{await z1(ae),l(ve=>ve.filter(ye=>ye.id!==ae))},[]),Re=y.useCallback(async(ae,ve,ye,me,nt,pt,jt,Bt,ze,ut)=>{const _t=await Yc(ae,{title:ve,description:ye,cli_tool:me,depends_on:nt??null,max_turns:pt??null,use_worktree:jt===void 0?null:jt,...Bt?{memory_inject_mode:Bt}:{},...ze?{memory_node_ids:ze}:{},...ut?{memory_raw_file_paths:ut}:{}});l(Mt=>Mt.map(At=>At.id===ae?_t:At))},[]),ct=y.useCallback(async ae=>{await B1(ae),l(ve=>ve.map(ye=>ye.id===ae?{...ye,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:ye))},[]),tt=y.useCallback(async ae=>{const ve=await C3(ae),ye=new Set(ve.mergedIds);l(me=>me.map(nt=>ye.has(nt.id)?{...nt,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:nt))},[]),Ke=y.useCallback(async(ae,ve=!1)=>{await P1(ae,ve),l(ye=>ye.map(me=>me.id===ae?{...me,worktree_path:null,...ve?{branch_name:null}:{},updated_at:new Date().toISOString()}:me))},[]),Le=y.useCallback(async(ae,ve)=>{const ye=ve==="interactive";ye&&I(me=>new Set(me).add(ae));try{const me=await j3(ae,ve);l(nt=>nt.map(pt=>pt.id===ae?me:pt))}catch(me){throw ye&&I(nt=>{const pt=new Set(nt);return pt.delete(ae),pt}),me}},[]),$e=y.useCallback(async(ae,ve,ye)=>{const me=ye==="interactive";me&&I(nt=>new Set(nt).add(ae));try{const nt=await I1(ae,ve,ye);l(pt=>pt.map(jt=>jt.id===ae?nt:jt))}catch(nt){throw me&&I(pt=>{const jt=new Set(pt);return jt.delete(ae),jt}),nt}},[]),Ie=y.useCallback(async(ae,ve,ye)=>{const me=await D3(ae,ve,ye);me.original_deleted&&l(nt=>nt.filter(pt=>pt.id!==ae)),p(nt=>[me.schedule,...nt])},[]),it=y.useCallback(async(ae,ve)=>{const ye=await O3(ae,ve);p(me=>[ye.schedule,...me])},[]),vt=y.useCallback((ae,ve)=>{i({type:"todo:stdin",todoId:ae,input:ve})},[i]),Ce=y.useCallback(async(ae,ve)=>{const ye=await Yc(ae,{depends_on:ve});l(me=>me.map(nt=>nt.id===ae?ye:nt))},[]),Ue=y.useCallback(async ae=>{const ve=ae.map((ye,me)=>({id:ye,priority:me}));l(ye=>ye.map(me=>{const nt=ve.find(pt=>pt.id===me.id);return nt?{...me,priority:nt.priority}:me})),await Promise.all(ve.map(ye=>Yc(ye.id,{priority:ye.priority})))},[]),we=y.useCallback(async(ae,ve,ye)=>{await Yc(ae,{position_x:ve,position_y:ye}),l(me=>me.map(nt=>nt.id===ae?{...nt,position_x:ve,position_y:ye}:nt))},[]),Pe=y.useCallback(async(ae,ve)=>{if(!u)return;const ye=ve.map(jt=>jt.message).join(`
685
685
  `),me=`The previous task "${ae.title}" failed with the following errors: